summaryrefslogtreecommitdiff
path: root/core/fpdfapi/fpdf_page
diff options
context:
space:
mode:
Diffstat (limited to 'core/fpdfapi/fpdf_page')
-rw-r--r--core/fpdfapi/fpdf_page/cpdf_textobject.cpp3
-rw-r--r--core/fpdfapi/fpdf_page/cpdf_textstatedata.cpp33
-rw-r--r--core/fpdfapi/fpdf_page/fpdf_page_parser.cpp23
-rw-r--r--core/fpdfapi/fpdf_page/include/cpdf_textstatedata.h18
4 files changed, 60 insertions, 17 deletions
diff --git a/core/fpdfapi/fpdf_page/cpdf_textobject.cpp b/core/fpdfapi/fpdf_page/cpdf_textobject.cpp
index a3fbbad8b0..72658c67ba 100644
--- a/core/fpdfapi/fpdf_page/cpdf_textobject.cpp
+++ b/core/fpdfapi/fpdf_page/cpdf_textobject.cpp
@@ -313,8 +313,7 @@ void CPDF_TextObject::CalcPositionData(FX_FLOAT* pTextAdvanceX,
m_Bottom = min_y;
m_Top = max_y;
matrix.TransformRect(m_Left, m_Right, m_Top, m_Bottom);
- int textmode = m_TextState.GetObject()->m_TextMode;
- if (textmode == 1 || textmode == 2 || textmode == 5 || textmode == 6) {
+ if (TextRenderingModeIsStrokeMode(m_TextState.GetObject()->m_TextMode)) {
FX_FLOAT half_width = m_GraphState.GetObject()->m_LineWidth / 2;
m_Left -= half_width;
m_Right += half_width;
diff --git a/core/fpdfapi/fpdf_page/cpdf_textstatedata.cpp b/core/fpdfapi/fpdf_page/cpdf_textstatedata.cpp
index 5cd6061542..e60af0076e 100644
--- a/core/fpdfapi/fpdf_page/cpdf_textstatedata.cpp
+++ b/core/fpdfapi/fpdf_page/cpdf_textstatedata.cpp
@@ -10,13 +10,44 @@
#include "core/fpdfapi/fpdf_page/pageint.h"
#include "core/fpdfapi/fpdf_parser/include/cpdf_document.h"
+bool SetTextRenderingModeFromInt(int iMode, TextRenderingMode* mode) {
+ if (iMode < 0 || iMode > 7)
+ return false;
+ *mode = static_cast<TextRenderingMode>(iMode);
+ return true;
+}
+
+bool TextRenderingModeIsClipMode(const TextRenderingMode& mode) {
+ switch (mode) {
+ case TextRenderingMode::MODE_FILL_CLIP:
+ case TextRenderingMode::MODE_STROKE_CLIP:
+ case TextRenderingMode::MODE_FILL_STROKE_CLIP:
+ case TextRenderingMode::MODE_CLIP:
+ return true;
+ default:
+ return false;
+ }
+}
+
+bool TextRenderingModeIsStrokeMode(const TextRenderingMode& mode) {
+ switch (mode) {
+ case TextRenderingMode::MODE_STROKE:
+ case TextRenderingMode::MODE_FILL_STROKE:
+ case TextRenderingMode::MODE_STROKE_CLIP:
+ case TextRenderingMode::MODE_FILL_STROKE_CLIP:
+ return true;
+ default:
+ return false;
+ }
+}
+
CPDF_TextStateData::CPDF_TextStateData()
: m_pFont(nullptr),
m_pDocument(nullptr),
m_FontSize(1.0f),
m_CharSpace(0),
m_WordSpace(0),
- m_TextMode(0) {
+ m_TextMode(TextRenderingMode::MODE_FILL) {
m_Matrix[0] = m_Matrix[3] = 1.0f;
m_Matrix[1] = m_Matrix[2] = 0;
m_CTM[0] = m_CTM[3] = 1.0f;
diff --git a/core/fpdfapi/fpdf_page/fpdf_page_parser.cpp b/core/fpdfapi/fpdf_page/fpdf_page_parser.cpp
index 0374915af4..4a7b6ad403 100644
--- a/core/fpdfapi/fpdf_page/fpdf_page_parser.cpp
+++ b/core/fpdfapi/fpdf_page/fpdf_page_parser.cpp
@@ -816,8 +816,10 @@ void CPDF_StreamContentParser::Handle_EndText() {
if (m_ClipTextList.empty())
return;
- if (m_pCurStates->m_TextState.GetObject()->m_TextMode >= 4)
+ if (TextRenderingModeIsClipMode(
+ m_pCurStates->m_TextState.GetObject()->m_TextMode)) {
m_pCurStates->m_ClipPath.AppendTexts(&m_ClipTextList);
+ }
m_ClipTextList.clear();
}
@@ -1251,17 +1253,14 @@ void CPDF_StreamContentParser::AddTextObject(CFX_ByteString* pStrs,
if (nsegs == 0) {
return;
}
- int textmode;
- if (pFont->IsType3Font()) {
- textmode = 0;
- } else {
- textmode = m_pCurStates->m_TextState.GetObject()->m_TextMode;
- }
+ const TextRenderingMode text_mode =
+ pFont->IsType3Font() ? TextRenderingMode::MODE_FILL
+ : m_pCurStates->m_TextState.GetObject()->m_TextMode;
{
std::unique_ptr<CPDF_TextObject> pText(new CPDF_TextObject);
m_pLastTextObject = pText.get();
SetGraphicStates(m_pLastTextObject, TRUE, TRUE, TRUE);
- if (textmode && textmode != 3 && textmode != 4 && textmode != 7) {
+ if (TextRenderingModeIsStrokeMode(text_mode)) {
FX_FLOAT* pCTM = pText->m_TextState.GetModify()->m_CTM;
pCTM[0] = m_pCurStates->m_CTM.a;
pCTM[1] = m_pCurStates->m_CTM.c;
@@ -1278,7 +1277,7 @@ void CPDF_StreamContentParser::AddTextObject(CFX_ByteString* pStrs,
m_pCurStates->m_TextHorzScale, m_Level);
m_pCurStates->m_TextX += x_advance;
m_pCurStates->m_TextY += y_advance;
- if (textmode > 3) {
+ if (TextRenderingModeIsClipMode(text_mode)) {
m_ClipTextList.push_back(
std::unique_ptr<CPDF_TextObject>(pText->Clone()));
}
@@ -1380,10 +1379,8 @@ void CPDF_StreamContentParser::OnChangeTextMatrix() {
void CPDF_StreamContentParser::Handle_SetTextRenderMode() {
int mode = GetInteger(0);
- if (mode < 0 || mode > 7) {
- return;
- }
- m_pCurStates->m_TextState.GetModify()->m_TextMode = mode;
+ SetTextRenderingModeFromInt(
+ mode, &m_pCurStates->m_TextState.GetModify()->m_TextMode);
}
void CPDF_StreamContentParser::Handle_SetTextRise() {
diff --git a/core/fpdfapi/fpdf_page/include/cpdf_textstatedata.h b/core/fpdfapi/fpdf_page/include/cpdf_textstatedata.h
index feed1a043f..4e33d5f170 100644
--- a/core/fpdfapi/fpdf_page/include/cpdf_textstatedata.h
+++ b/core/fpdfapi/fpdf_page/include/cpdf_textstatedata.h
@@ -12,6 +12,22 @@
class CPDF_Font;
class CPDF_Document;
+// See PDF Reference 1.7, page 402, table 5.3.
+enum class TextRenderingMode {
+ MODE_FILL = 0,
+ MODE_STROKE = 1,
+ MODE_FILL_STROKE = 2,
+ MODE_INVISIBLE = 3,
+ MODE_FILL_CLIP = 4,
+ MODE_STROKE_CLIP = 5,
+ MODE_FILL_STROKE_CLIP = 6,
+ MODE_CLIP = 7,
+};
+
+bool SetTextRenderingModeFromInt(int iMode, TextRenderingMode* mode);
+bool TextRenderingModeIsClipMode(const TextRenderingMode& mode);
+bool TextRenderingModeIsStrokeMode(const TextRenderingMode& mode);
+
class CPDF_TextStateData {
public:
CPDF_TextStateData();
@@ -23,8 +39,8 @@ class CPDF_TextStateData {
FX_FLOAT m_FontSize;
FX_FLOAT m_CharSpace;
FX_FLOAT m_WordSpace;
+ TextRenderingMode m_TextMode;
FX_FLOAT m_Matrix[4];
- int m_TextMode;
FX_FLOAT m_CTM[4];
};