From 58e4c5ac24a88f83d1ba8277dee87baf4cba36a0 Mon Sep 17 00:00:00 2001 From: Nicolas Pena Date: Mon, 13 Feb 2017 16:08:51 -0500 Subject: Clean up CPDF_TextObject a bit MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Reviewed-by: Tom Sepez --- core/fpdfapi/render/cpdf_textrenderer.cpp | 51 ++++++++++++------------------- 1 file changed, 19 insertions(+), 32 deletions(-) (limited to 'core/fpdfapi/render/cpdf_textrenderer.cpp') 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 +#include #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& charCodes, + const std::vector& 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 codes; std::vector positions; - if (nChars == 1) { - pCharCodes = reinterpret_cast( - 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& charCodes, + const std::vector& 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; -- cgit v1.2.3