summaryrefslogtreecommitdiff
path: root/core/fpdfapi/render
diff options
context:
space:
mode:
Diffstat (limited to 'core/fpdfapi/render')
-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
5 files changed, 55 insertions, 74 deletions
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,