summaryrefslogtreecommitdiff
path: root/core/fpdfapi
diff options
context:
space:
mode:
Diffstat (limited to 'core/fpdfapi')
-rw-r--r--core/fpdfapi/page/cpdf_allstates.cpp14
-rw-r--r--core/fpdfapi/page/cpdf_allstates.h6
-rw-r--r--core/fpdfapi/page/cpdf_streamcontentparser.cpp47
-rw-r--r--core/fpdfapi/page/cpdf_textobject.cpp28
-rw-r--r--core/fpdfapi/page/cpdf_textobject.h4
5 files changed, 39 insertions, 60 deletions
diff --git a/core/fpdfapi/page/cpdf_allstates.cpp b/core/fpdfapi/page/cpdf_allstates.cpp
index 94bc7b466f..282a47fe29 100644
--- a/core/fpdfapi/page/cpdf_allstates.cpp
+++ b/core/fpdfapi/page/cpdf_allstates.cpp
@@ -23,12 +23,8 @@ FX_FLOAT ClipFloat(FX_FLOAT f) {
} // namespace
-CPDF_AllStates::CPDF_AllStates() {
- m_TextX = m_TextY = m_TextLineX = m_TextLineY = 0;
- m_TextLeading = 0;
- m_TextRise = 0;
- m_TextHorzScale = 1.0f;
-}
+CPDF_AllStates::CPDF_AllStates()
+ : m_TextLeading(0), m_TextRise(0), m_TextHorzScale(1.0f) {}
CPDF_AllStates::~CPDF_AllStates() {}
@@ -37,10 +33,8 @@ void CPDF_AllStates::Copy(const CPDF_AllStates& src) {
m_TextMatrix = src.m_TextMatrix;
m_ParentMatrix = src.m_ParentMatrix;
m_CTM = src.m_CTM;
- m_TextX = src.m_TextX;
- m_TextY = src.m_TextY;
- m_TextLineX = src.m_TextLineX;
- m_TextLineY = src.m_TextLineY;
+ m_TextPos = src.m_TextPos;
+ m_TextLinePos = src.m_TextLinePos;
m_TextLeading = src.m_TextLeading;
m_TextRise = src.m_TextRise;
m_TextHorzScale = src.m_TextHorzScale;
diff --git a/core/fpdfapi/page/cpdf_allstates.h b/core/fpdfapi/page/cpdf_allstates.h
index 1aa680a2ce..dad1b8502b 100644
--- a/core/fpdfapi/page/cpdf_allstates.h
+++ b/core/fpdfapi/page/cpdf_allstates.h
@@ -27,10 +27,8 @@ class CPDF_AllStates : public CPDF_GraphicStates {
CFX_Matrix m_TextMatrix;
CFX_Matrix m_CTM;
CFX_Matrix m_ParentMatrix;
- FX_FLOAT m_TextX;
- FX_FLOAT m_TextY;
- FX_FLOAT m_TextLineX;
- FX_FLOAT m_TextLineY;
+ CFX_PointF m_TextPos;
+ CFX_PointF m_TextLinePos;
FX_FLOAT m_TextLeading;
FX_FLOAT m_TextRise;
FX_FLOAT m_TextHorzScale;
diff --git a/core/fpdfapi/page/cpdf_streamcontentparser.cpp b/core/fpdfapi/page/cpdf_streamcontentparser.cpp
index 8015a8df45..b8c9c4c6af 100644
--- a/core/fpdfapi/page/cpdf_streamcontentparser.cpp
+++ b/core/fpdfapi/page/cpdf_streamcontentparser.cpp
@@ -675,10 +675,8 @@ void CPDF_StreamContentParser::Handle_BeginMarkedContent() {
void CPDF_StreamContentParser::Handle_BeginText() {
m_pCurStates->m_TextMatrix = CFX_Matrix();
OnChangeTextMatrix();
- m_pCurStates->m_TextX = 0;
- m_pCurStates->m_TextY = 0;
- m_pCurStates->m_TextLineX = 0;
- m_pCurStates->m_TextLineY = 0;
+ m_pCurStates->m_TextPos = CFX_PointF();
+ m_pCurStates->m_TextLinePos = CFX_PointF();
}
void CPDF_StreamContentParser::Handle_CurveTo_123() {
@@ -1136,10 +1134,8 @@ void CPDF_StreamContentParser::Handle_SetCharSpace() {
}
void CPDF_StreamContentParser::Handle_MoveTextPoint() {
- m_pCurStates->m_TextLineX += GetNumber(1);
- m_pCurStates->m_TextLineY += GetNumber(0);
- m_pCurStates->m_TextX = m_pCurStates->m_TextLineX;
- m_pCurStates->m_TextY = m_pCurStates->m_TextLineY;
+ m_pCurStates->m_TextLinePos += CFX_PointF(GetNumber(1), GetNumber(0));
+ m_pCurStates->m_TextPos = m_pCurStates->m_TextLinePos;
}
void CPDF_StreamContentParser::Handle_MoveTextPoint_SetLeading() {
@@ -1239,12 +1235,12 @@ void CPDF_StreamContentParser::AddTextObject(CFX_ByteString* pStrs,
}
if (fInitKerning != 0) {
if (!pFont->IsVertWriting()) {
- m_pCurStates->m_TextX -=
+ m_pCurStates->m_TextPos.x -=
(fInitKerning * m_pCurStates->m_TextState.GetFontSize() *
m_pCurStates->m_TextHorzScale) /
1000;
} else {
- m_pCurStates->m_TextY -=
+ m_pCurStates->m_TextPos.y -=
(fInitKerning * m_pCurStates->m_TextState.GetFontSize()) / 1000;
}
}
@@ -1268,15 +1264,11 @@ void CPDF_StreamContentParser::AddTextObject(CFX_ByteString* pStrs,
pText->SetSegments(pStrs, pKerning, nsegs);
pText->m_Pos = m_mtContentToUser.Transform(
m_pCurStates->m_CTM.Transform(m_pCurStates->m_TextMatrix.Transform(
- CFX_PointF(m_pCurStates->m_TextX,
- m_pCurStates->m_TextY + m_pCurStates->m_TextRise))));
-
- FX_FLOAT x_advance;
- FX_FLOAT y_advance;
- pText->CalcPositionData(&x_advance, &y_advance,
- m_pCurStates->m_TextHorzScale);
- m_pCurStates->m_TextX += x_advance;
- m_pCurStates->m_TextY += y_advance;
+ CFX_PointF(m_pCurStates->m_TextPos.x,
+ m_pCurStates->m_TextPos.y + m_pCurStates->m_TextRise))));
+
+ m_pCurStates->m_TextPos +=
+ pText->CalcPositionData(m_pCurStates->m_TextHorzScale);
if (TextRenderingModeIsClipMode(text_mode)) {
m_ClipTextList.push_back(
std::unique_ptr<CPDF_TextObject>(pText->Clone()));
@@ -1285,12 +1277,12 @@ void CPDF_StreamContentParser::AddTextObject(CFX_ByteString* pStrs,
}
if (pKerning && pKerning[nsegs - 1] != 0) {
if (!pFont->IsVertWriting()) {
- m_pCurStates->m_TextX -=
+ m_pCurStates->m_TextPos.x -=
(pKerning[nsegs - 1] * m_pCurStates->m_TextState.GetFontSize() *
m_pCurStates->m_TextHorzScale) /
1000;
} else {
- m_pCurStates->m_TextY -=
+ m_pCurStates->m_TextPos.y -=
(pKerning[nsegs - 1] * m_pCurStates->m_TextState.GetFontSize()) /
1000;
}
@@ -1318,7 +1310,7 @@ void CPDF_StreamContentParser::Handle_ShowText_Positioning() {
}
if (nsegs == 0) {
for (size_t i = 0; i < n; i++) {
- m_pCurStates->m_TextX -=
+ m_pCurStates->m_TextPos.x -=
(pArray->GetNumberAt(i) * m_pCurStates->m_TextState.GetFontSize() *
m_pCurStates->m_TextHorzScale) /
1000;
@@ -1361,10 +1353,8 @@ void CPDF_StreamContentParser::Handle_SetTextMatrix() {
CFX_Matrix(GetNumber(5), GetNumber(4), GetNumber(3), GetNumber(2),
GetNumber(1), GetNumber(0));
OnChangeTextMatrix();
- m_pCurStates->m_TextX = 0;
- m_pCurStates->m_TextY = 0;
- m_pCurStates->m_TextLineX = 0;
- m_pCurStates->m_TextLineY = 0;
+ m_pCurStates->m_TextPos = CFX_PointF();
+ m_pCurStates->m_TextLinePos = CFX_PointF();
}
void CPDF_StreamContentParser::OnChangeTextMatrix() {
@@ -1403,9 +1393,8 @@ void CPDF_StreamContentParser::Handle_SetHorzScale() {
}
void CPDF_StreamContentParser::Handle_MoveToNextLine() {
- m_pCurStates->m_TextLineY -= m_pCurStates->m_TextLeading;
- m_pCurStates->m_TextX = m_pCurStates->m_TextLineX;
- m_pCurStates->m_TextY = m_pCurStates->m_TextLineY;
+ m_pCurStates->m_TextLinePos.y -= m_pCurStates->m_TextLeading;
+ m_pCurStates->m_TextPos = m_pCurStates->m_TextLinePos;
}
void CPDF_StreamContentParser::Handle_CurveTo_23() {
diff --git a/core/fpdfapi/page/cpdf_textobject.cpp b/core/fpdfapi/page/cpdf_textobject.cpp
index a84deb27c7..da69de8ce1 100644
--- a/core/fpdfapi/page/cpdf_textobject.cpp
+++ b/core/fpdfapi/page/cpdf_textobject.cpp
@@ -114,7 +114,7 @@ void CPDF_TextObject::Transform(const CFX_Matrix& matrix) {
pTextMatrix[2] = text_matrix.b;
pTextMatrix[3] = text_matrix.d;
m_Pos = CFX_PointF(text_matrix.e, text_matrix.f);
- CalcPositionData(nullptr, nullptr, 0);
+ CalcPositionData(0);
}
bool CPDF_TextObject::IsText() const {
@@ -188,9 +188,7 @@ FX_FLOAT CPDF_TextObject::GetFontSize() const {
return m_TextState.GetFontSize();
}
-void CPDF_TextObject::CalcPositionData(FX_FLOAT* pTextAdvanceX,
- FX_FLOAT* pTextAdvanceY,
- FX_FLOAT horz_scale) {
+CFX_PointF CPDF_TextObject::CalcPositionData(FX_FLOAT horz_scale) {
FX_FLOAT curpos = 0;
FX_FLOAT min_x = 10000 * 1.0f;
FX_FLOAT max_x = -10000 * 1.0f;
@@ -201,6 +199,7 @@ void CPDF_TextObject::CalcPositionData(FX_FLOAT* pTextAdvanceX,
CPDF_CIDFont* pCIDFont = pFont->AsCIDFont();
if (pCIDFont)
bVertWriting = pCIDFont->IsVertWriting();
+
FX_FLOAT fontsize = m_TextState.GetFontSize();
for (int i = 0; i < pdfium::CollectionSize<int>(m_CharCodes); ++i) {
uint32_t charcode = m_CharCodes[i];
@@ -211,6 +210,7 @@ void CPDF_TextObject::CalcPositionData(FX_FLOAT* pTextAdvanceX,
}
m_CharPos[i - 1] = curpos;
}
+
FX_RECT char_rect = pFont->GetCharBBox(charcode);
FX_FLOAT charwidth;
if (!bVertWriting) {
@@ -245,20 +245,17 @@ void CPDF_TextObject::CalcPositionData(FX_FLOAT* pTextAdvanceX,
curpos += charwidth;
if (charcode == ' ' && (!pCIDFont || pCIDFont->GetCharSize(' ') == 1))
curpos += m_TextState.GetWordSpace();
+
curpos += m_TextState.GetCharSpace();
}
+
+ CFX_PointF ret;
if (bVertWriting) {
- if (pTextAdvanceX)
- *pTextAdvanceX = 0;
- if (pTextAdvanceY)
- *pTextAdvanceY = curpos;
+ ret.y = curpos;
min_x = min_x * fontsize / 1000;
max_x = max_x * fontsize / 1000;
} else {
- if (pTextAdvanceX)
- *pTextAdvanceX = curpos * horz_scale;
- if (pTextAdvanceY)
- *pTextAdvanceY = 0;
+ ret.x = curpos * horz_scale;
min_y = min_y * fontsize / 1000;
max_y = max_y * fontsize / 1000;
}
@@ -268,14 +265,17 @@ void CPDF_TextObject::CalcPositionData(FX_FLOAT* pTextAdvanceX,
m_Bottom = min_y;
m_Top = max_y;
GetTextMatrix().TransformRect(m_Left, m_Right, m_Top, m_Bottom);
+
if (!TextRenderingModeIsStrokeMode(m_TextState.GetTextMode()))
- return;
+ return ret;
FX_FLOAT half_width = m_GraphState.GetLineWidth() / 2;
m_Left -= half_width;
m_Right += half_width;
m_Top += half_width;
m_Bottom -= half_width;
+
+ return ret;
}
void CPDF_TextObject::SetPosition(FX_FLOAT x, FX_FLOAT y) {
@@ -290,5 +290,5 @@ void CPDF_TextObject::SetPosition(FX_FLOAT x, FX_FLOAT y) {
}
void CPDF_TextObject::RecalcPositionData() {
- CalcPositionData(nullptr, nullptr, 1);
+ CalcPositionData(1);
}
diff --git a/core/fpdfapi/page/cpdf_textobject.h b/core/fpdfapi/page/cpdf_textobject.h
index 756187046b..59da718f62 100644
--- a/core/fpdfapi/page/cpdf_textobject.h
+++ b/core/fpdfapi/page/cpdf_textobject.h
@@ -62,9 +62,7 @@ class CPDF_TextObject : public CPDF_PageObject {
const FX_FLOAT* pKerning,
int nSegs);
- void CalcPositionData(FX_FLOAT* pTextAdvanceX,
- FX_FLOAT* pTextAdvanceY,
- FX_FLOAT horz_scale);
+ CFX_PointF CalcPositionData(FX_FLOAT horz_scale);
CFX_PointF m_Pos;
std::vector<uint32_t> m_CharCodes;