summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/fpdfapi/page/cpdf_streamcontentparser.cpp6
-rw-r--r--core/fpdfapi/page/cpdf_textobject.cpp270
-rw-r--r--core/fpdfapi/page/cpdf_textobject.h17
-rw-r--r--core/fpdfapi/render/cpdf_charposlist.cpp18
-rw-r--r--core/fpdfapi/render/cpdf_charposlist.h7
-rw-r--r--core/fpdfapi/render/cpdf_renderstatus.cpp41
-rw-r--r--core/fpdfapi/render/cpdf_textrenderer.cpp51
-rw-r--r--core/fpdfapi/render/cpdf_textrenderer.h12
-rw-r--r--fpdfsdk/javascript/Document.cpp4
9 files changed, 160 insertions, 266 deletions
diff --git a/core/fpdfapi/page/cpdf_streamcontentparser.cpp b/core/fpdfapi/page/cpdf_streamcontentparser.cpp
index af5b88fead..0af43d08b2 100644
--- a/core/fpdfapi/page/cpdf_streamcontentparser.cpp
+++ b/core/fpdfapi/page/cpdf_streamcontentparser.cpp
@@ -1276,9 +1276,9 @@ void CPDF_StreamContentParser::AddTextObject(CFX_ByteString* pStrs,
pCTM[3] = m_pCurStates->m_CTM.d;
}
pText->SetSegments(pStrs, pKerning, nsegs);
- pText->m_PosX = m_pCurStates->m_TextX;
- pText->m_PosY = m_pCurStates->m_TextY + m_pCurStates->m_TextRise;
- ConvertTextSpace(pText->m_PosX, pText->m_PosY);
+ pText->m_Pos = CFX_PointF(m_pCurStates->m_TextX,
+ m_pCurStates->m_TextY + m_pCurStates->m_TextRise);
+ ConvertTextSpace(pText->m_Pos.x, pText->m_Pos.y);
FX_FLOAT x_advance;
FX_FLOAT y_advance;
pText->CalcPositionData(&x_advance, &y_advance,
diff --git a/core/fpdfapi/page/cpdf_textobject.cpp b/core/fpdfapi/page/cpdf_textobject.cpp
index 0404a595bf..74ea6ebc7d 100644
--- a/core/fpdfapi/page/cpdf_textobject.cpp
+++ b/core/fpdfapi/page/cpdf_textobject.cpp
@@ -6,36 +6,29 @@
#include "core/fpdfapi/page/cpdf_textobject.h"
+#include <algorithm>
+
#include "core/fpdfapi/font/cpdf_cidfont.h"
#include "core/fpdfapi/font/cpdf_font.h"
#include "third_party/base/ptr_util.h"
+#include "third_party/base/stl_util.h"
CPDF_TextObjectItem::CPDF_TextObjectItem() : m_CharCode(0) {}
CPDF_TextObjectItem::~CPDF_TextObjectItem() {}
-CPDF_TextObject::CPDF_TextObject()
- : m_PosX(0),
- m_PosY(0),
- m_nChars(0),
- m_pCharCodes(nullptr),
- m_pCharPos(nullptr) {}
+CPDF_TextObject::CPDF_TextObject() {}
CPDF_TextObject::~CPDF_TextObject() {
- if (m_nChars > 1) {
- FX_Free(m_pCharCodes);
- }
- FX_Free(m_pCharPos);
}
int CPDF_TextObject::CountItems() const {
- return m_nChars;
+ return pdfium::CollectionSize<int>(m_CharCodes);
}
void CPDF_TextObject::GetItemInfo(int index, CPDF_TextObjectItem* pInfo) const {
- pInfo->m_CharCode =
- m_nChars == 1 ? (uint32_t)(uintptr_t)m_pCharCodes : m_pCharCodes[index];
- pInfo->m_Origin = CFX_PointF(index ? m_pCharPos[index - 1] : 0, 0);
+ pInfo->m_CharCode = m_CharCodes[index];
+ pInfo->m_Origin = CFX_PointF(index ? m_CharPos[index - 1] : 0, 0);
if (pInfo->m_CharCode == CPDF_Font::kInvalidCharCode)
return;
@@ -58,78 +51,53 @@ void CPDF_TextObject::GetItemInfo(int index, CPDF_TextObjectItem* pInfo) const {
}
int CPDF_TextObject::CountChars() const {
- if (m_nChars == 1) {
- return 1;
- }
int count = 0;
- for (int i = 0; i < m_nChars; ++i)
- if (m_pCharCodes[i] != CPDF_Font::kInvalidCharCode) {
- ++count;
- }
+ for (uint32_t charcode : m_CharCodes) {
+ if (charcode != CPDF_Font::kInvalidCharCode)
+ count++;
+ }
return count;
}
void CPDF_TextObject::GetCharInfo(int index,
- uint32_t& charcode,
- FX_FLOAT& kerning) const {
- if (m_nChars == 1) {
- charcode = (uint32_t)(uintptr_t)m_pCharCodes;
- kerning = 0;
- return;
- }
+ uint32_t* charcode,
+ FX_FLOAT* kerning) const {
int count = 0;
- for (int i = 0; i < m_nChars; ++i) {
- if (m_pCharCodes[i] != CPDF_Font::kInvalidCharCode) {
- if (count == index) {
- charcode = m_pCharCodes[i];
- if (i == m_nChars - 1 ||
- m_pCharCodes[i + 1] != CPDF_Font::kInvalidCharCode) {
- kerning = 0;
- } else {
- kerning = m_pCharPos[i];
- }
- return;
- }
- ++count;
+ for (size_t i = 0; i < m_CharCodes.size(); ++i) {
+ if (m_CharCodes[i] == CPDF_Font::kInvalidCharCode)
+ continue;
+ if (count++ != index)
+ continue;
+ *charcode = m_CharCodes[i];
+ if (i == m_CharCodes.size() - 1 ||
+ m_CharCodes[i + 1] != CPDF_Font::kInvalidCharCode) {
+ *kerning = 0;
+ } else {
+ *kerning = m_CharPos[i];
}
+ return;
}
}
void CPDF_TextObject::GetCharInfo(int index, CPDF_TextObjectItem* pInfo) const {
- if (m_nChars == 1) {
- GetItemInfo(0, pInfo);
- return;
- }
int count = 0;
- for (int i = 0; i < m_nChars; ++i) {
- uint32_t charcode = m_pCharCodes[i];
- if (charcode == CPDF_Font::kInvalidCharCode) {
+ for (int i = 0; i < pdfium::CollectionSize<int>(m_CharCodes); ++i) {
+ uint32_t charcode = m_CharCodes[i];
+ if (charcode == CPDF_Font::kInvalidCharCode)
continue;
- }
- if (count == index) {
- GetItemInfo(i, pInfo);
- break;
- }
- ++count;
+ if (count++ != index)
+ continue;
+ GetItemInfo(i, pInfo);
+ break;
}
}
std::unique_ptr<CPDF_TextObject> CPDF_TextObject::Clone() const {
auto obj = pdfium::MakeUnique<CPDF_TextObject>();
obj->CopyData(this);
-
- obj->m_nChars = m_nChars;
- if (m_nChars > 1) {
- obj->m_pCharCodes = FX_Alloc(uint32_t, m_nChars);
- FXSYS_memcpy(obj->m_pCharCodes, m_pCharCodes, m_nChars * sizeof(uint32_t));
- obj->m_pCharPos = FX_Alloc(FX_FLOAT, m_nChars - 1);
- FXSYS_memcpy(obj->m_pCharPos, m_pCharPos,
- (m_nChars - 1) * sizeof(FX_FLOAT));
- } else {
- obj->m_pCharCodes = m_pCharCodes;
- }
- obj->m_PosX = m_PosX;
- obj->m_PosY = m_PosY;
+ obj->m_CharCodes = m_CharCodes;
+ obj->m_CharPos = m_CharPos;
+ obj->m_Pos = m_Pos;
return obj;
}
@@ -146,8 +114,7 @@ void CPDF_TextObject::Transform(const CFX_Matrix& matrix) {
pTextMatrix[1] = text_matrix.c;
pTextMatrix[2] = text_matrix.b;
pTextMatrix[3] = text_matrix.d;
- m_PosX = text_matrix.e;
- m_PosY = text_matrix.f;
+ m_Pos = CFX_PointF(text_matrix.e, text_matrix.f);
CalcPositionData(nullptr, nullptr, 0);
}
@@ -166,44 +133,32 @@ const CPDF_TextObject* CPDF_TextObject::AsText() const {
CFX_Matrix CPDF_TextObject::GetTextMatrix() const {
const FX_FLOAT* pTextMatrix = m_TextState.GetMatrix();
return CFX_Matrix(pTextMatrix[0], pTextMatrix[2], pTextMatrix[1],
- pTextMatrix[3], m_PosX, m_PosY);
+ pTextMatrix[3], m_Pos.x, m_Pos.y);
}
void CPDF_TextObject::SetSegments(const CFX_ByteString* pStrs,
- FX_FLOAT* pKerning,
+ const FX_FLOAT* pKerning,
int nsegs) {
- if (m_nChars > 1) {
- FX_Free(m_pCharCodes);
- m_pCharCodes = nullptr;
- }
- FX_Free(m_pCharPos);
- m_pCharPos = nullptr;
+ m_CharCodes.clear();
+ m_CharPos.clear();
CPDF_Font* pFont = m_TextState.GetFont();
- m_nChars = 0;
+ int nChars = 0;
+ for (int i = 0; i < nsegs; ++i)
+ nChars += pFont->CountChar(pStrs[i].c_str(), pStrs[i].GetLength());
+ nChars += nsegs - 1;
+ m_CharCodes.resize(nChars);
+ m_CharPos.resize(nChars - 1);
+ int index = 0;
for (int i = 0; i < nsegs; ++i) {
- m_nChars += pFont->CountChar(pStrs[i].c_str(), pStrs[i].GetLength());
- }
- m_nChars += nsegs - 1;
- if (m_nChars > 1) {
- m_pCharCodes = FX_Alloc(uint32_t, m_nChars);
- m_pCharPos = FX_Alloc(FX_FLOAT, m_nChars - 1);
- int index = 0;
- for (int i = 0; i < nsegs; ++i) {
- const FX_CHAR* segment = pStrs[i].c_str();
- int len = pStrs[i].GetLength();
- int offset = 0;
- while (offset < len) {
- m_pCharCodes[index++] = pFont->GetNextChar(segment, len, offset);
- }
- if (i != nsegs - 1) {
- m_pCharPos[index - 1] = pKerning[i];
- m_pCharCodes[index++] = CPDF_Font::kInvalidCharCode;
- }
- }
- } else {
+ const FX_CHAR* segment = pStrs[i].c_str();
+ int len = pStrs[i].GetLength();
int offset = 0;
- m_pCharCodes = (uint32_t*)(uintptr_t)pFont->GetNextChar(
- pStrs[0].c_str(), pStrs[0].GetLength(), offset);
+ while (offset < len)
+ m_CharCodes[index++] = pFont->GetNextChar(segment, len, offset);
+ if (i != nsegs - 1) {
+ m_CharPos[index - 1] = pKerning[i];
+ m_CharCodes[index++] = CPDF_Font::kInvalidCharCode;
+ }
}
}
@@ -217,9 +172,8 @@ FX_FLOAT CPDF_TextObject::GetCharWidth(uint32_t charcode) const {
CPDF_Font* pFont = m_TextState.GetFont();
bool bVertWriting = false;
CPDF_CIDFont* pCIDFont = pFont->AsCIDFont();
- if (pCIDFont) {
+ if (pCIDFont)
bVertWriting = pCIDFont->IsVertWriting();
- }
if (!bVertWriting)
return pFont->GetCharWidthF(charcode) * fontsize;
@@ -232,7 +186,7 @@ CFX_FloatRect CPDF_TextObject::GetRect() const {
}
CFX_PointF CPDF_TextObject::GetPos() const {
- return CFX_PointF(m_PosX, m_PosY);
+ return CFX_PointF(m_Pos.x, m_Pos.y);
}
CPDF_Font* CPDF_TextObject::GetFont() const {
@@ -254,49 +208,29 @@ void CPDF_TextObject::CalcPositionData(FX_FLOAT* pTextAdvanceX,
CPDF_Font* pFont = m_TextState.GetFont();
bool bVertWriting = false;
CPDF_CIDFont* pCIDFont = pFont->AsCIDFont();
- if (pCIDFont) {
+ if (pCIDFont)
bVertWriting = pCIDFont->IsVertWriting();
- }
FX_FLOAT fontsize = m_TextState.GetFontSize();
- for (int i = 0; i < m_nChars; ++i) {
- uint32_t charcode =
- m_nChars == 1 ? (uint32_t)(uintptr_t)m_pCharCodes : m_pCharCodes[i];
+ for (int i = 0; i < pdfium::CollectionSize<int>(m_CharCodes); ++i) {
+ uint32_t charcode = m_CharCodes[i];
if (i > 0) {
if (charcode == CPDF_Font::kInvalidCharCode) {
- curpos -= (m_pCharPos[i - 1] * fontsize) / 1000;
+ curpos -= (m_CharPos[i - 1] * fontsize) / 1000;
continue;
}
- m_pCharPos[i - 1] = curpos;
+ m_CharPos[i - 1] = curpos;
}
FX_RECT char_rect = pFont->GetCharBBox(charcode);
FX_FLOAT charwidth;
if (!bVertWriting) {
- if (min_y > char_rect.top) {
- min_y = (FX_FLOAT)char_rect.top;
- }
- if (max_y < char_rect.top) {
- max_y = (FX_FLOAT)char_rect.top;
- }
- if (min_y > char_rect.bottom) {
- min_y = (FX_FLOAT)char_rect.bottom;
- }
- if (max_y < char_rect.bottom) {
- max_y = (FX_FLOAT)char_rect.bottom;
- }
+ min_y = std::min(min_y, static_cast<FX_FLOAT>(
+ std::min(char_rect.top, char_rect.bottom)));
+ max_y = std::max(max_y, static_cast<FX_FLOAT>(
+ std::max(char_rect.top, char_rect.bottom)));
FX_FLOAT char_left = curpos + char_rect.left * fontsize / 1000;
FX_FLOAT char_right = curpos + char_rect.right * fontsize / 1000;
- if (min_x > char_left) {
- min_x = char_left;
- }
- if (max_x < char_left) {
- max_x = char_left;
- }
- if (min_x > char_right) {
- min_x = char_right;
- }
- if (max_x < char_right) {
- max_x = char_right;
- }
+ min_x = std::min(min_x, std::min(char_left, char_right));
+ max_x = std::max(max_x, std::max(char_left, char_right));
charwidth = pFont->GetCharWidthF(charcode) * fontsize / 1000;
} else {
uint16_t CID = pCIDFont->CIDFromCharCode(charcode);
@@ -307,56 +241,33 @@ void CPDF_TextObject::CalcPositionData(FX_FLOAT* pTextAdvanceX,
char_rect.right -= vx;
char_rect.top -= vy;
char_rect.bottom -= vy;
- if (min_x > char_rect.left) {
- min_x = (FX_FLOAT)char_rect.left;
- }
- if (max_x < char_rect.left) {
- max_x = (FX_FLOAT)char_rect.left;
- }
- if (min_x > char_rect.right) {
- min_x = (FX_FLOAT)char_rect.right;
- }
- if (max_x < char_rect.right) {
- max_x = (FX_FLOAT)char_rect.right;
- }
+ min_x = std::min(min_x, static_cast<FX_FLOAT>(
+ std::min(char_rect.left, char_rect.right)));
+ max_x = std::max(max_x, static_cast<FX_FLOAT>(
+ std::max(char_rect.left, char_rect.right)));
FX_FLOAT char_top = curpos + char_rect.top * fontsize / 1000;
FX_FLOAT char_bottom = curpos + char_rect.bottom * fontsize / 1000;
- if (min_y > char_top) {
- min_y = char_top;
- }
- if (max_y < char_top) {
- max_y = char_top;
- }
- if (min_y > char_bottom) {
- min_y = char_bottom;
- }
- if (max_y < char_bottom) {
- max_y = char_bottom;
- }
+ min_y = std::min(min_y, std::min(char_top, char_bottom));
+ max_y = std::max(max_y, std::max(char_top, char_bottom));
charwidth = pCIDFont->GetVertWidth(CID) * fontsize / 1000;
}
curpos += charwidth;
- if (charcode == ' ' && (!pCIDFont || pCIDFont->GetCharSize(32) == 1)) {
+ if (charcode == ' ' && (!pCIDFont || pCIDFont->GetCharSize(' ') == 1))
curpos += m_TextState.GetWordSpace();
- }
curpos += m_TextState.GetCharSpace();
}
if (bVertWriting) {
- if (pTextAdvanceX) {
+ if (pTextAdvanceX)
*pTextAdvanceX = 0;
- }
- if (pTextAdvanceY) {
+ if (pTextAdvanceY)
*pTextAdvanceY = curpos;
- }
min_x = min_x * fontsize / 1000;
max_x = max_x * fontsize / 1000;
} else {
- if (pTextAdvanceX) {
+ if (pTextAdvanceX)
*pTextAdvanceX = curpos * horz_scale;
- }
- if (pTextAdvanceY) {
+ if (pTextAdvanceY)
*pTextAdvanceY = 0;
- }
min_y = min_y * fontsize / 1000;
max_y = max_y * fontsize / 1000;
}
@@ -366,20 +277,21 @@ 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())) {
- FX_FLOAT half_width = m_GraphState.GetLineWidth() / 2;
- m_Left -= half_width;
- m_Right += half_width;
- m_Top += half_width;
- m_Bottom -= half_width;
- }
+ if (!TextRenderingModeIsStrokeMode(m_TextState.GetTextMode()))
+ return;
+
+ FX_FLOAT half_width = m_GraphState.GetLineWidth() / 2;
+ m_Left -= half_width;
+ m_Right += half_width;
+ m_Top += half_width;
+ m_Bottom -= half_width;
}
void CPDF_TextObject::SetPosition(FX_FLOAT x, FX_FLOAT y) {
- FX_FLOAT dx = x - m_PosX;
- FX_FLOAT dy = y - m_PosY;
- m_PosX = x;
- m_PosY = y;
+ FX_FLOAT dx = x - m_Pos.x;
+ FX_FLOAT dy = y - m_Pos.y;
+ m_Pos.x = x;
+ m_Pos.y = y;
m_Left += dx;
m_Right += dx;
m_Top += dy;
diff --git a/core/fpdfapi/page/cpdf_textobject.h b/core/fpdfapi/page/cpdf_textobject.h
index 7445f0d110..9e763a164e 100644
--- a/core/fpdfapi/page/cpdf_textobject.h
+++ b/core/fpdfapi/page/cpdf_textobject.h
@@ -8,6 +8,7 @@
#define CORE_FPDFAPI_PAGE_CPDF_TEXTOBJECT_H_
#include <memory>
+#include <vector>
#include "core/fpdfapi/page/cpdf_pageobject.h"
#include "core/fxcrt/fx_string.h"
@@ -38,7 +39,7 @@ class CPDF_TextObject : public CPDF_PageObject {
int CountItems() const;
void GetItemInfo(int index, CPDF_TextObjectItem* pInfo) const;
int CountChars() const;
- void GetCharInfo(int index, uint32_t& charcode, FX_FLOAT& kerning) const;
+ void GetCharInfo(int index, uint32_t* charcode, FX_FLOAT* kerning) const;
void GetCharInfo(int index, CPDF_TextObjectItem* pInfo) const;
FX_FLOAT GetCharWidth(uint32_t charcode) const;
@@ -53,22 +54,22 @@ class CPDF_TextObject : public CPDF_PageObject {
void RecalcPositionData();
- protected:
+ private:
friend class CPDF_RenderStatus;
friend class CPDF_StreamContentParser;
friend class CPDF_TextRenderer;
- void SetSegments(const CFX_ByteString* pStrs, FX_FLOAT* pKerning, int nSegs);
+ void SetSegments(const CFX_ByteString* pStrs,
+ const FX_FLOAT* pKerning,
+ int nSegs);
void CalcPositionData(FX_FLOAT* pTextAdvanceX,
FX_FLOAT* pTextAdvanceY,
FX_FLOAT horz_scale);
- FX_FLOAT m_PosX;
- FX_FLOAT m_PosY;
- int m_nChars;
- uint32_t* m_pCharCodes;
- FX_FLOAT* m_pCharPos;
+ CFX_PointF m_Pos;
+ std::vector<uint32_t> m_CharCodes;
+ std::vector<FX_FLOAT> m_CharPos;
};
#endif // CORE_FPDFAPI_PAGE_CPDF_TEXTOBJECT_H_
diff --git a/core/fpdfapi/render/cpdf_charposlist.cpp b/core/fpdfapi/render/cpdf_charposlist.cpp
index bf361e2da1..d7f566d5e7 100644
--- a/core/fpdfapi/render/cpdf_charposlist.cpp
+++ b/core/fpdfapi/render/cpdf_charposlist.cpp
@@ -8,6 +8,7 @@
#include "core/fpdfapi/font/cpdf_cidfont.h"
#include "core/fpdfapi/font/cpdf_font.h"
+#include "third_party/base/stl_util.h"
CPDF_CharPosList::CPDF_CharPosList() {
m_pCharPos = nullptr;
@@ -18,26 +19,23 @@ CPDF_CharPosList::~CPDF_CharPosList() {
FX_Free(m_pCharPos);
}
-void CPDF_CharPosList::Load(int nChars,
- uint32_t* pCharCodes,
- FX_FLOAT* pCharPos,
+void CPDF_CharPosList::Load(const std::vector<uint32_t>& charCodes,
+ const std::vector<FX_FLOAT>& charPos,
CPDF_Font* pFont,
FX_FLOAT FontSize) {
+ int nChars = pdfium::CollectionSize<int>(charCodes);
m_pCharPos = FX_Alloc(FXTEXT_CHARPOS, nChars);
m_nChars = 0;
CPDF_CIDFont* pCIDFont = pFont->AsCIDFont();
bool bVertWriting = pCIDFont && pCIDFont->IsVertWriting();
for (int iChar = 0; iChar < nChars; iChar++) {
- uint32_t CharCode =
- nChars == 1 ? (uint32_t)(uintptr_t)pCharCodes : pCharCodes[iChar];
- if (CharCode == (uint32_t)-1) {
+ uint32_t CharCode = charCodes[iChar];
+ if (CharCode == static_cast<uint32_t>(-1))
continue;
- }
bool bVert = false;
FXTEXT_CHARPOS& charpos = m_pCharPos[m_nChars++];
- if (pCIDFont) {
+ if (pCIDFont)
charpos.m_bFontStyle = true;
- }
charpos.m_GlyphIndex = pFont->GlyphFromCharCode(CharCode, &bVert);
if (charpos.m_GlyphIndex != static_cast<uint32_t>(-1)) {
charpos.m_FallbackFontPosition = -1;
@@ -56,7 +54,7 @@ void CPDF_CharPosList::Load(int nChars,
} else {
charpos.m_FontCharWidth = 0;
}
- charpos.m_Origin = CFX_PointF(iChar ? pCharPos[iChar - 1] : 0, 0);
+ charpos.m_Origin = CFX_PointF(iChar ? charPos[iChar - 1] : 0, 0);
charpos.m_bGlyphAdjust = false;
if (!pCIDFont) {
continue;
diff --git a/core/fpdfapi/render/cpdf_charposlist.h b/core/fpdfapi/render/cpdf_charposlist.h
index 9fa3c2cf51..2f5a44dfa0 100644
--- a/core/fpdfapi/render/cpdf_charposlist.h
+++ b/core/fpdfapi/render/cpdf_charposlist.h
@@ -7,6 +7,8 @@
#ifndef CORE_FPDFAPI_RENDER_CPDF_CHARPOSLIST_H_
#define CORE_FPDFAPI_RENDER_CPDF_CHARPOSLIST_H_
+#include <vector>
+
#include "core/fxcrt/fx_system.h"
#include "core/fxge/cfx_renderdevice.h"
@@ -16,9 +18,8 @@ class CPDF_CharPosList {
public:
CPDF_CharPosList();
~CPDF_CharPosList();
- void Load(int nChars,
- uint32_t* pCharCodes,
- FX_FLOAT* pCharPos,
+ void Load(const std::vector<uint32_t>& charCodes,
+ const std::vector<FX_FLOAT>& charPos,
CPDF_Font* pFont,
FX_FLOAT font_size);
FXTEXT_CHARPOS* m_pCharPos;
diff --git a/core/fpdfapi/render/cpdf_renderstatus.cpp b/core/fpdfapi/render/cpdf_renderstatus.cpp
index 2d3c23994e..05323ed49f 100644
--- a/core/fpdfapi/render/cpdf_renderstatus.cpp
+++ b/core/fpdfapi/render/cpdf_renderstatus.cpp
@@ -1549,10 +1549,10 @@ bool CPDF_RenderStatus::ProcessTransparency(CPDF_PageObject* pPageObj,
CFX_Matrix text_matrix = textobj->GetTextMatrix();
CPDF_TextRenderer::DrawTextPath(
- &text_device, textobj->m_nChars, textobj->m_pCharCodes,
- textobj->m_pCharPos, textobj->m_TextState.GetFont(),
- textobj->m_TextState.GetFontSize(), &text_matrix, &new_matrix,
- textobj->m_GraphState.GetObject(), (FX_ARGB)-1, 0, nullptr, 0);
+ &text_device, textobj->m_CharCodes, textobj->m_CharPos,
+ textobj->m_TextState.GetFont(), textobj->m_TextState.GetFontSize(),
+ &text_matrix, &new_matrix, textobj->m_GraphState.GetObject(),
+ (FX_ARGB)-1, 0, nullptr, 0);
}
}
CPDF_RenderStatus bitmap_render;
@@ -1671,7 +1671,7 @@ void CPDF_RenderStatus::DebugVerifyDeviceIsPreMultiplied() const {
bool CPDF_RenderStatus::ProcessText(CPDF_TextObject* textobj,
const CFX_Matrix* pObj2Device,
CFX_PathData* pClippingPath) {
- if (textobj->m_nChars == 0)
+ if (textobj->m_CharCodes.empty())
return true;
const TextRenderingMode text_render_mode = textobj->m_TextState.GetTextMode();
@@ -1764,15 +1764,14 @@ bool CPDF_RenderStatus::ProcessText(CPDF_TextObject* textobj,
if (m_Options.m_Flags & RENDER_NOTEXTSMOOTH)
flag |= FXFILL_NOPATHSMOOTH;
return CPDF_TextRenderer::DrawTextPath(
- m_pDevice, textobj->m_nChars, textobj->m_pCharCodes,
- textobj->m_pCharPos, pFont, font_size, &text_matrix, pDeviceMatrix,
- textobj->m_GraphState.GetObject(), fill_argb, stroke_argb,
- pClippingPath, flag);
+ m_pDevice, textobj->m_CharCodes, textobj->m_CharPos, pFont, font_size,
+ &text_matrix, pDeviceMatrix, textobj->m_GraphState.GetObject(),
+ fill_argb, stroke_argb, pClippingPath, flag);
}
text_matrix.Concat(*pObj2Device);
- return CPDF_TextRenderer::DrawNormalText(
- m_pDevice, textobj->m_nChars, textobj->m_pCharCodes, textobj->m_pCharPos,
- pFont, font_size, &text_matrix, fill_argb, &m_Options);
+ return CPDF_TextRenderer::DrawNormalText(m_pDevice, textobj->m_CharCodes,
+ textobj->m_CharPos, pFont, font_size,
+ &text_matrix, fill_argb, &m_Options);
}
CPDF_Type3Cache* CPDF_RenderStatus::GetCachedType3(CPDF_Type3Font* pFont) {
@@ -1802,18 +1801,15 @@ bool CPDF_RenderStatus::ProcessType3Text(CPDF_TextObject* textobj,
int device_class = m_pDevice->GetDeviceClass();
std::vector<FXTEXT_GLYPHPOS> glyphs;
if (device_class == FXDC_DISPLAY)
- glyphs.resize(textobj->m_nChars);
+ glyphs.resize(textobj->m_CharCodes.size());
else if (fill_alpha < 255)
return false;
CPDF_RefType3Cache refTypeCache(pType3Font);
- uint32_t* pChars = textobj->m_pCharCodes;
- if (textobj->m_nChars == 1)
- pChars = (uint32_t*)(&textobj->m_pCharCodes);
-
- for (int iChar = 0; iChar < textobj->m_nChars; iChar++) {
- uint32_t charcode = pChars[iChar];
- if (charcode == (uint32_t)-1)
+ for (int iChar = 0; iChar < pdfium::CollectionSize<int>(textobj->m_CharCodes);
+ iChar++) {
+ uint32_t charcode = textobj->m_CharCodes[iChar];
+ if (charcode == static_cast<uint32_t>(-1))
continue;
CPDF_Type3Char* pType3Char = pType3Font->LoadChar(charcode);
@@ -1821,7 +1817,7 @@ bool CPDF_RenderStatus::ProcessType3Text(CPDF_TextObject* textobj,
continue;
CFX_Matrix matrix = char_matrix;
- matrix.e += iChar ? textobj->m_pCharPos[iChar - 1] : 0;
+ matrix.e += iChar ? textobj->m_CharPos[iChar - 1] : 0;
matrix.Concat(text_matrix);
matrix.Concat(*pObj2Device);
if (!pType3Char->LoadBitmap(m_pContext)) {
@@ -1977,8 +1973,7 @@ void CPDF_RenderStatus::DrawTextPathWithPattern(const CPDF_TextObject* textobj,
return;
}
CPDF_CharPosList CharPosList;
- CharPosList.Load(textobj->m_nChars, textobj->m_pCharCodes,
- textobj->m_pCharPos, pFont, font_size);
+ CharPosList.Load(textobj->m_CharCodes, textobj->m_CharPos, pFont, font_size);
for (uint32_t i = 0; i < CharPosList.m_nChars; i++) {
FXTEXT_CHARPOS& charpos = CharPosList.m_pCharPos[i];
auto font =
diff --git a/core/fpdfapi/render/cpdf_textrenderer.cpp b/core/fpdfapi/render/cpdf_textrenderer.cpp
index 9cb8ce933e..28e28f8147 100644
--- a/core/fpdfapi/render/cpdf_textrenderer.cpp
+++ b/core/fpdfapi/render/cpdf_textrenderer.cpp
@@ -6,7 +6,7 @@
#include "core/fpdfapi/render/cpdf_textrenderer.h"
-#include <vector>
+#include <algorithm>
#include "core/fpdfapi/font/cpdf_font.h"
#include "core/fpdfapi/render/cpdf_charposlist.h"
@@ -17,9 +17,8 @@
// static
bool CPDF_TextRenderer::DrawTextPath(CFX_RenderDevice* pDevice,
- int nChars,
- uint32_t* pCharCodes,
- FX_FLOAT* pCharPos,
+ const std::vector<uint32_t>& charCodes,
+ const std::vector<FX_FLOAT>& charPos,
CPDF_Font* pFont,
FX_FLOAT font_size,
const CFX_Matrix* pText2User,
@@ -30,7 +29,7 @@ bool CPDF_TextRenderer::DrawTextPath(CFX_RenderDevice* pDevice,
CFX_PathData* pClippingPath,
int nFlag) {
CPDF_CharPosList CharPosList;
- CharPosList.Load(nChars, pCharCodes, pCharPos, pFont, font_size);
+ CharPosList.Load(charCodes, charPos, pFont, font_size);
if (CharPosList.m_nChars == 0)
return true;
@@ -84,26 +83,16 @@ void CPDF_TextRenderer::DrawTextString(CFX_RenderDevice* pDevice,
return;
int offset = 0;
- uint32_t* pCharCodes;
- FX_FLOAT* pCharPos;
std::vector<uint32_t> codes;
std::vector<FX_FLOAT> positions;
- if (nChars == 1) {
- pCharCodes = reinterpret_cast<uint32_t*>(
- pFont->GetNextChar(str.c_str(), str.GetLength(), offset));
- pCharPos = nullptr;
- } else {
- codes.resize(nChars);
- positions.resize(nChars - 1);
- FX_FLOAT cur_pos = 0;
- for (int i = 0; i < nChars; i++) {
- codes[i] = pFont->GetNextChar(str.c_str(), str.GetLength(), offset);
- if (i)
- positions[i - 1] = cur_pos;
- cur_pos += pFont->GetCharWidthF(codes[i]) * font_size / 1000;
- }
- pCharCodes = codes.data();
- pCharPos = positions.data();
+ codes.resize(nChars);
+ positions.resize(nChars - 1);
+ FX_FLOAT cur_pos = 0;
+ for (int i = 0; i < nChars; i++) {
+ codes[i] = pFont->GetNextChar(str.c_str(), str.GetLength(), offset);
+ if (i)
+ positions[i - 1] = cur_pos;
+ cur_pos += pFont->GetCharWidthF(codes[i]) * font_size / 1000;
}
CFX_Matrix matrix;
if (pMatrix)
@@ -113,27 +102,25 @@ void CPDF_TextRenderer::DrawTextString(CFX_RenderDevice* pDevice,
matrix.f = origin_y;
if (stroke_argb == 0) {
- DrawNormalText(pDevice, nChars, pCharCodes, pCharPos, pFont, font_size,
- &matrix, fill_argb, pOptions);
+ DrawNormalText(pDevice, codes, positions, pFont, font_size, &matrix,
+ fill_argb, pOptions);
} else {
- DrawTextPath(pDevice, nChars, pCharCodes, pCharPos, pFont, font_size,
- &matrix, nullptr, pGraphState, fill_argb, stroke_argb, nullptr,
- 0);
+ DrawTextPath(pDevice, codes, positions, pFont, font_size, &matrix, nullptr,
+ pGraphState, fill_argb, stroke_argb, nullptr, 0);
}
}
// static
bool CPDF_TextRenderer::DrawNormalText(CFX_RenderDevice* pDevice,
- int nChars,
- uint32_t* pCharCodes,
- FX_FLOAT* pCharPos,
+ const std::vector<uint32_t>& charCodes,
+ const std::vector<FX_FLOAT>& charPos,
CPDF_Font* pFont,
FX_FLOAT font_size,
const CFX_Matrix* pText2Device,
FX_ARGB fill_argb,
const CPDF_RenderOptions* pOptions) {
CPDF_CharPosList CharPosList;
- CharPosList.Load(nChars, pCharCodes, pCharPos, pFont, font_size);
+ CharPosList.Load(charCodes, charPos, pFont, font_size);
if (CharPosList.m_nChars == 0)
return true;
int FXGE_flags = 0;
diff --git a/core/fpdfapi/render/cpdf_textrenderer.h b/core/fpdfapi/render/cpdf_textrenderer.h
index 82cc2cf8e6..d3acceeb96 100644
--- a/core/fpdfapi/render/cpdf_textrenderer.h
+++ b/core/fpdfapi/render/cpdf_textrenderer.h
@@ -7,6 +7,8 @@
#ifndef CORE_FPDFAPI_RENDER_CPDF_TEXTRENDERER_H_
#define CORE_FPDFAPI_RENDER_CPDF_TEXTRENDERER_H_
+#include <vector>
+
#include "core/fxcrt/fx_coordinates.h"
#include "core/fxcrt/fx_string.h"
#include "core/fxcrt/fx_system.h"
@@ -33,9 +35,8 @@ class CPDF_TextRenderer {
const CPDF_RenderOptions* pOptions);
static bool DrawTextPath(CFX_RenderDevice* pDevice,
- int nChars,
- uint32_t* pCharCodes,
- FX_FLOAT* pCharPos,
+ const std::vector<uint32_t>& charCodes,
+ const std::vector<FX_FLOAT>& charPos,
CPDF_Font* pFont,
FX_FLOAT font_size,
const CFX_Matrix* pText2User,
@@ -47,9 +48,8 @@ class CPDF_TextRenderer {
int nFlag);
static bool DrawNormalText(CFX_RenderDevice* pDevice,
- int nChars,
- uint32_t* pCharCodes,
- FX_FLOAT* pCharPos,
+ const std::vector<uint32_t>& charCodes,
+ const std::vector<FX_FLOAT>& charPos,
CPDF_Font* pFont,
FX_FLOAT font_size,
const CFX_Matrix* pText2Device,
diff --git a/fpdfsdk/javascript/Document.cpp b/fpdfsdk/javascript/Document.cpp
index 4bf1afd5a3..1a0a53cce2 100644
--- a/fpdfsdk/javascript/Document.cpp
+++ b/fpdfsdk/javascript/Document.cpp
@@ -1543,7 +1543,7 @@ int Document::CountWords(CPDF_TextObject* pTextObj) {
uint32_t charcode = CPDF_Font::kInvalidCharCode;
FX_FLOAT kerning;
- pTextObj->GetCharInfo(i, charcode, kerning);
+ pTextObj->GetCharInfo(i, &charcode, &kerning);
CFX_WideString swUnicode = pFont->UnicodeFromCharCode(charcode);
uint16_t unicode = 0;
@@ -1576,7 +1576,7 @@ CFX_WideString Document::GetObjWordStr(CPDF_TextObject* pTextObj,
uint32_t charcode = CPDF_Font::kInvalidCharCode;
FX_FLOAT kerning;
- pTextObj->GetCharInfo(i, charcode, kerning);
+ pTextObj->GetCharInfo(i, &charcode, &kerning);
CFX_WideString swUnicode = pFont->UnicodeFromCharCode(charcode);
uint16_t unicode = 0;