summaryrefslogtreecommitdiff
path: root/core/fpdfapi
diff options
context:
space:
mode:
authorthestig <thestig@chromium.org>2016-06-27 07:16:06 -0700
committerCommit bot <commit-bot@chromium.org>2016-06-27 07:16:06 -0700
commitde0022a7005fcaacc260fda9c1c019c2c408fa00 (patch)
treee5773666e99efb2940c87570d72d8a3317738536 /core/fpdfapi
parent160bd0e26f5dfe5fa11322f61b3d156c2214cba8 (diff)
downloadpdfium-de0022a7005fcaacc260fda9c1c019c2c408fa00.tar.xz
Simplify CPDF_TextRenderer::DrawTextString().
Review-Url: https://codereview.chromium.org/2093033004
Diffstat (limited to 'core/fpdfapi')
-rw-r--r--core/fpdfapi/fpdf_render/fpdf_render_text.cpp50
1 files changed, 24 insertions, 26 deletions
diff --git a/core/fpdfapi/fpdf_render/fpdf_render_text.cpp b/core/fpdfapi/fpdf_render/fpdf_render_text.cpp
index 2da51b90d5..d3e70c169e 100644
--- a/core/fpdfapi/fpdf_render/fpdf_render_text.cpp
+++ b/core/fpdfapi/fpdf_render/fpdf_render_text.cpp
@@ -640,29 +640,34 @@ void CPDF_TextRenderer::DrawTextString(CFX_RenderDevice* pDevice,
FX_ARGB stroke_argb,
const CFX_GraphStateData* pGraphState,
const CPDF_RenderOptions* pOptions) {
+ if (pFont->IsType3Font())
+ return;
+
int nChars = pFont->CountChar(str.c_str(), str.GetLength());
- if (nChars == 0) {
+ if (nChars <= 0)
return;
- }
- uint32_t charcode;
+
int offset = 0;
uint32_t* pCharCodes;
FX_FLOAT* pCharPos;
+ std::vector<uint32_t> codes;
+ std::vector<FX_FLOAT> positions;
if (nChars == 1) {
- charcode = pFont->GetNextChar(str.c_str(), str.GetLength(), offset);
- pCharCodes = (uint32_t*)(uintptr_t)charcode;
+ pCharCodes = reinterpret_cast<uint32_t*>(
+ pFont->GetNextChar(str.c_str(), str.GetLength(), offset));
pCharPos = nullptr;
} else {
- pCharCodes = FX_Alloc(uint32_t, nChars);
- pCharPos = FX_Alloc(FX_FLOAT, nChars - 1);
+ codes.resize(nChars);
+ positions.resize(nChars - 1);
FX_FLOAT cur_pos = 0;
for (int i = 0; i < nChars; i++) {
- pCharCodes[i] = pFont->GetNextChar(str.c_str(), str.GetLength(), offset);
- if (i) {
- pCharPos[i - 1] = cur_pos;
- }
- cur_pos += pFont->GetCharWidthF(pCharCodes[i]) * font_size / 1000;
+ 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();
}
CFX_Matrix matrix;
if (pMatrix)
@@ -671,20 +676,13 @@ void CPDF_TextRenderer::DrawTextString(CFX_RenderDevice* pDevice,
matrix.e = origin_x;
matrix.f = origin_y;
- if (!pFont->IsType3Font()) {
- if (stroke_argb == 0) {
- DrawNormalText(pDevice, nChars, pCharCodes, pCharPos, 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);
- }
- }
-
- if (nChars > 1) {
- FX_Free(pCharCodes);
- FX_Free(pCharPos);
+ if (stroke_argb == 0) {
+ DrawNormalText(pDevice, nChars, pCharCodes, pCharPos, 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);
}
}