diff options
author | Nicolas Pena <npm@chromium.org> | 2017-02-13 16:08:51 -0500 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2017-02-13 22:07:02 +0000 |
commit | 58e4c5ac24a88f83d1ba8277dee87baf4cba36a0 (patch) | |
tree | 5c6c05ffb40c1bb2653b415842537f7043bd6407 /core/fpdfapi/render/cpdf_textrenderer.cpp | |
parent | 9787a7441a905e582b10d9ffc425098b3233d36c (diff) | |
download | pdfium-58e4c5ac24a88f83d1ba8277dee87baf4cba36a0.tar.xz |
Clean up CPDF_TextObject a bit
Modernizing CPDF_TextObject a little bit, in preparation for the addition of
APIs for adding text to PDFs. m_pCharCodes, m_pCharPos are now vectors, this
caused some propagation to other classes. Also m_Pos is now a point. Note that
GetItemInfo is being changed in another CL, so did minimal changes there.
Change-Id: I6e5f19b5d45872e3e714a7cb587c81c92e640ea3
Reviewed-on: https://pdfium-review.googlesource.com/2614
Commit-Queue: Nicolás Peña <npm@chromium.org>
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Diffstat (limited to 'core/fpdfapi/render/cpdf_textrenderer.cpp')
-rw-r--r-- | core/fpdfapi/render/cpdf_textrenderer.cpp | 51 |
1 files changed, 19 insertions, 32 deletions
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; |