From 1b08df18300bbc67dabd12fb35ab6ce1732a1024 Mon Sep 17 00:00:00 2001 From: Dan Sinclair Date: Thu, 9 Feb 2017 09:17:20 -0500 Subject: Convert Get methods to return instead of using out params. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This Cl changes several Get methods to return their values instead of using out parameters. Change-Id: Ie9a930a5c2d0e809f2d7181ca033d801945c1cf9 Reviewed-on: https://pdfium-review.googlesource.com/2556 Commit-Queue: dsinclair Reviewed-by: Nicolás Peña --- core/fpdfapi/page/cpdf_page.cpp | 20 +++++++-------- core/fpdfapi/page/cpdf_page.h | 11 ++++----- core/fpdfapi/page/cpdf_textobject.cpp | 18 +++++--------- core/fpdfapi/page/cpdf_textobject.h | 2 +- core/fpdfapi/render/cpdf_renderstatus.cpp | 13 ++++------ core/fpdftext/cpdf_textpage.cpp | 41 ++++++++++++++----------------- core/fxge/ge/cfx_renderdevice.cpp | 3 +++ 7 files changed, 49 insertions(+), 59 deletions(-) (limited to 'core') diff --git a/core/fpdfapi/page/cpdf_page.cpp b/core/fpdfapi/page/cpdf_page.cpp index 7714369df8..ba30ce57c3 100644 --- a/core/fpdfapi/page/cpdf_page.cpp +++ b/core/fpdfapi/page/cpdf_page.cpp @@ -120,15 +120,14 @@ CPDF_Object* CPDF_Page::GetPageAttr(const CFX_ByteString& name) const { return nullptr; } -void CPDF_Page::GetDisplayMatrix(CFX_Matrix& matrix, - int xPos, - int yPos, - int xSize, - int ySize, - int iRotate) const { - if (m_PageWidth == 0 || m_PageHeight == 0) { - return; - } +CFX_Matrix CPDF_Page::GetDisplayMatrix(int xPos, + int yPos, + int xSize, + int ySize, + int iRotate) const { + if (m_PageWidth == 0 || m_PageHeight == 0) + return CFX_Matrix(); + float x0 = 0; float y0 = 0; float x1 = 0; @@ -170,8 +169,9 @@ void CPDF_Page::GetDisplayMatrix(CFX_Matrix& matrix, y2 = yPos; break; } - matrix = m_PageMatrix; + CFX_Matrix matrix = m_PageMatrix; matrix.Concat(CFX_Matrix((x2 - x0) / m_PageWidth, (y2 - y0) / m_PageWidth, (x1 - x0) / m_PageHeight, (y1 - y0) / m_PageHeight, x0, y0)); + return matrix; } diff --git a/core/fpdfapi/page/cpdf_page.h b/core/fpdfapi/page/cpdf_page.h index 3812d28670..6d29a8f34e 100644 --- a/core/fpdfapi/page/cpdf_page.h +++ b/core/fpdfapi/page/cpdf_page.h @@ -31,12 +31,11 @@ class CPDF_Page : public CPDF_PageObjectHolder { void ParseContent(); - void GetDisplayMatrix(CFX_Matrix& matrix, - int xPos, - int yPos, - int xSize, - int ySize, - int iRotate) const; + CFX_Matrix GetDisplayMatrix(int xPos, + int yPos, + int xSize, + int ySize, + int iRotate) const; FX_FLOAT GetPageWidth() const { return m_PageWidth; } FX_FLOAT GetPageHeight() const { return m_PageHeight; } diff --git a/core/fpdfapi/page/cpdf_textobject.cpp b/core/fpdfapi/page/cpdf_textobject.cpp index fb81a40d0c..503ea78f9e 100644 --- a/core/fpdfapi/page/cpdf_textobject.cpp +++ b/core/fpdfapi/page/cpdf_textobject.cpp @@ -134,8 +134,7 @@ CPDF_PageObject::Type CPDF_TextObject::GetType() const { } void CPDF_TextObject::Transform(const CFX_Matrix& matrix) { - CFX_Matrix text_matrix; - GetTextMatrix(&text_matrix); + CFX_Matrix text_matrix = GetTextMatrix(); text_matrix.Concat(matrix); FX_FLOAT* pTextMatrix = m_TextState.GetMutableMatrix(); @@ -160,14 +159,10 @@ const CPDF_TextObject* CPDF_TextObject::AsText() const { return this; } -void CPDF_TextObject::GetTextMatrix(CFX_Matrix* pMatrix) const { +CFX_Matrix CPDF_TextObject::GetTextMatrix() const { const FX_FLOAT* pTextMatrix = m_TextState.GetMatrix(); - pMatrix->a = pTextMatrix[0]; - pMatrix->b = pTextMatrix[2]; - pMatrix->c = pTextMatrix[1]; - pMatrix->d = pTextMatrix[3]; - pMatrix->e = m_PosX; - pMatrix->f = m_PosY; + return CFX_Matrix(pTextMatrix[0], pTextMatrix[2], pTextMatrix[1], + pTextMatrix[3], m_PosX, m_PosY); } void CPDF_TextObject::SetSegments(const CFX_ByteString* pStrs, @@ -361,13 +356,12 @@ void CPDF_TextObject::CalcPositionData(FX_FLOAT* pTextAdvanceX, min_y = min_y * fontsize / 1000; max_y = max_y * fontsize / 1000; } - CFX_Matrix matrix; - GetTextMatrix(&matrix); + m_Left = min_x; m_Right = max_x; m_Bottom = min_y; m_Top = max_y; - matrix.TransformRect(m_Left, m_Right, m_Top, m_Bottom); + 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; diff --git a/core/fpdfapi/page/cpdf_textobject.h b/core/fpdfapi/page/cpdf_textobject.h index b520e3ee92..2e54f2035e 100644 --- a/core/fpdfapi/page/cpdf_textobject.h +++ b/core/fpdfapi/page/cpdf_textobject.h @@ -40,7 +40,7 @@ class CPDF_TextObject : public CPDF_PageObject { FX_FLOAT GetCharWidth(uint32_t charcode) const; FX_FLOAT GetPosX() const; FX_FLOAT GetPosY() const; - void GetTextMatrix(CFX_Matrix* pMatrix) const; + CFX_Matrix GetTextMatrix() const; CPDF_Font* GetFont() const; FX_FLOAT GetFontSize() const; diff --git a/core/fpdfapi/render/cpdf_renderstatus.cpp b/core/fpdfapi/render/cpdf_renderstatus.cpp index 86b9670cd1..1bdf4a0382 100644 --- a/core/fpdfapi/render/cpdf_renderstatus.cpp +++ b/core/fpdfapi/render/cpdf_renderstatus.cpp @@ -1544,11 +1544,10 @@ bool CPDF_RenderStatus::ProcessTransparency(CPDF_PageObject* pPageObj, text_device.Attach(pTextMask.get(), false, nullptr, false); for (uint32_t i = 0; i < pPageObj->m_ClipPath.GetTextCount(); i++) { CPDF_TextObject* textobj = pPageObj->m_ClipPath.GetText(i); - if (!textobj) { + if (!textobj) break; - } - CFX_Matrix text_matrix; - textobj->GetTextMatrix(&text_matrix); + + CFX_Matrix text_matrix = textobj->GetTextMatrix(); CPDF_TextRenderer::DrawTextPath( &text_device, textobj->m_nChars, textobj->m_pCharCodes, textobj->m_pCharPos, textobj->m_TextState.GetFont(), @@ -1732,8 +1731,7 @@ bool CPDF_RenderStatus::ProcessText(CPDF_TextObject* textobj, fill_argb = GetFillArgb(textobj); } } - CFX_Matrix text_matrix; - textobj->GetTextMatrix(&text_matrix); + CFX_Matrix text_matrix = textobj->GetTextMatrix(); if (!IsAvailableMatrix(text_matrix)) return true; @@ -1795,8 +1793,7 @@ bool CPDF_RenderStatus::ProcessType3Text(CPDF_TextObject* textobj, CFX_Matrix dCTM = m_pDevice->GetCTM(); FX_FLOAT sa = FXSYS_fabs(dCTM.a); FX_FLOAT sd = FXSYS_fabs(dCTM.d); - CFX_Matrix text_matrix; - textobj->GetTextMatrix(&text_matrix); + CFX_Matrix text_matrix = textobj->GetTextMatrix(); CFX_Matrix char_matrix = pType3Font->GetFontMatrix(); FX_FLOAT font_size = textobj->m_TextState.GetFontSize(); char_matrix.Scale(font_size, font_size); diff --git a/core/fpdftext/cpdf_textpage.cpp b/core/fpdftext/cpdf_textpage.cpp index a919aa51ec..e5e00168b9 100644 --- a/core/fpdftext/cpdf_textpage.cpp +++ b/core/fpdftext/cpdf_textpage.cpp @@ -115,8 +115,9 @@ CPDF_TextPage::CPDF_TextPage(const CPDF_Page* pPage, FPDFText_Direction flags) m_bIsParsed(false), m_TextlineDir(TextOrientation::Unknown) { m_TextBuf.EstimateSize(0, 10240); - pPage->GetDisplayMatrix(m_DisplayMatrix, 0, 0, (int)pPage->GetPageWidth(), - (int)pPage->GetPageHeight(), 0); + m_DisplayMatrix = + pPage->GetDisplayMatrix(0, 0, static_cast(pPage->GetPageWidth()), + static_cast(pPage->GetPageHeight()), 0); } CPDF_TextPage::~CPDF_TextPage() {} @@ -239,8 +240,7 @@ std::vector CPDF_TextPage::GetRectArray(int start, } if (bFlagNewRect) { FX_FLOAT orgX = info_curchar.m_OriginX, orgY = info_curchar.m_OriginY; - CFX_Matrix matrix; - info_curchar.m_pTextObj->GetTextMatrix(&matrix); + CFX_Matrix matrix = info_curchar.m_pTextObj->GetTextMatrix(); matrix.Concat(info_curchar.m_Matrix); CFX_Matrix matrix_reverse; @@ -759,8 +759,8 @@ void CPDF_TextPage::ProcessTextObject( FX_FLOAT prev_width = GetCharWidth(item.m_CharCode, prev_Obj.m_pTextObj->GetFont()) * prev_Obj.m_pTextObj->GetFontSize() / 1000; - CFX_Matrix prev_matrix; - prev_Obj.m_pTextObj->GetTextMatrix(&prev_matrix); + + CFX_Matrix prev_matrix = prev_Obj.m_pTextObj->GetTextMatrix(); prev_width = FXSYS_fabs(prev_width); prev_matrix.Concat(prev_Obj.m_formMatrix); prev_width = prev_matrix.TransformDistance(prev_width); @@ -769,11 +769,11 @@ void CPDF_TextPage::ProcessTextObject( pTextObj->GetFontSize() / 1000; this_width = FXSYS_fabs(this_width); - CFX_Matrix this_matrix; - pTextObj->GetTextMatrix(&this_matrix); + CFX_Matrix this_matrix = pTextObj->GetTextMatrix(); this_width = FXSYS_fabs(this_width); this_matrix.Concat(formMatrix); this_width = this_matrix.TransformDistance(this_width); + FX_FLOAT threshold = prev_width > this_width ? prev_width / 4 : this_width / 4; FX_FLOAT prev_x = prev_Obj.m_pTextObj->GetPosX(), @@ -890,10 +890,9 @@ void CPDF_TextPage::ProcessMarkedContent(PDFTEXT_Obj Obj) { return; CPDF_Font* pFont = pTextObj->GetFont(); - CFX_Matrix formMatrix = Obj.m_formMatrix; - CFX_Matrix matrix; - pTextObj->GetTextMatrix(&matrix); - matrix.Concat(formMatrix); + CFX_Matrix matrix = pTextObj->GetTextMatrix(); + matrix.Concat(Obj.m_formMatrix); + FX_FLOAT fPosX = pTextObj->GetPosX(); FX_FLOAT fPosY = pTextObj->GetPosY(); int nCharInfoIndex = m_TextBuf.GetLength(); @@ -908,6 +907,7 @@ void CPDF_TextPage::ProcessMarkedContent(PDFTEXT_Obj Obj) { wChar = 0x20; if (wChar >= 0xFFFD) continue; + PAGECHAR_INFO charinfo; charinfo.m_OriginX = fPosX; charinfo.m_OriginY = fPosY; @@ -977,9 +977,9 @@ void CPDF_TextPage::ProcessTextObject(PDFTEXT_Obj Obj) { return; CFX_Matrix formMatrix = Obj.m_formMatrix; CPDF_Font* pFont = pTextObj->GetFont(); - CFX_Matrix matrix; - pTextObj->GetTextMatrix(&matrix); + CFX_Matrix matrix = pTextObj->GetTextMatrix(); matrix.Concat(formMatrix); + FPDFText_MarkedContent ePreMKC = PreMarkedContent(Obj); if (ePreMKC == FPDFText_MarkedContent::Done) { m_pPreTextObj = pTextObj; @@ -1222,8 +1222,7 @@ CPDF_TextPage::TextOrientation CPDF_TextPage::GetTextObjectWritingMode( pTextObj->GetCharInfo(0, &first); pTextObj->GetCharInfo(nChars - 1, &last); - CFX_Matrix textMatrix; - pTextObj->GetTextMatrix(&textMatrix); + CFX_Matrix textMatrix = pTextObj->GetTextMatrix(); textMatrix.TransformPoint(first.m_OriginX, first.m_OriginY); textMatrix.TransformPoint(last.m_OriginX, last.m_OriginY); FX_FLOAT dX = FXSYS_fabs(last.m_OriginX - first.m_OriginX); @@ -1332,8 +1331,7 @@ CPDF_TextPage::GenerateCharacter CPDF_TextPage::ProcessInsertObject( FX_FLOAT threshold = last_width > this_width ? last_width / 4 : this_width / 4; - CFX_Matrix prev_matrix; - m_pPreTextObj->GetTextMatrix(&prev_matrix); + CFX_Matrix prev_matrix = m_pPreTextObj->GetTextMatrix(); prev_matrix.Concat(m_perMatrix); CFX_Matrix prev_reverse; @@ -1359,8 +1357,7 @@ CPDF_TextPage::GenerateCharacter CPDF_TextPage::ProcessInsertObject( if (nItem > 1) { CPDF_TextObjectItem tempItem; m_pPreTextObj->GetItemInfo(0, &tempItem); - CFX_Matrix m; - m_pPreTextObj->GetTextMatrix(&m); + CFX_Matrix m = m_pPreTextObj->GetTextMatrix(); if (PrevItem.m_OriginX > tempItem.m_OriginX && m_DisplayMatrix.a > 0.9 && m_DisplayMatrix.b < 0.1 && m_DisplayMatrix.c < 0.1 && m_DisplayMatrix.d < -0.9 && m.b < 0.1 && @@ -1393,9 +1390,9 @@ CPDF_TextPage::GenerateCharacter CPDF_TextPage::ProcessInsertObject( CFX_WideString PrevStr = m_pPreTextObj->GetFont()->UnicodeFromCharCode(PrevItem.m_CharCode); FX_WCHAR preChar = PrevStr.GetAt(PrevStr.GetLength() - 1); - CFX_Matrix matrix; - pObj->GetTextMatrix(&matrix); + CFX_Matrix matrix = pObj->GetTextMatrix(); matrix.Concat(formMatrix); + threshold = (FX_FLOAT)(nLastWidth > nThisWidth ? nLastWidth : nThisWidth); threshold = threshold > 400 ? (threshold < 700 diff --git a/core/fxge/ge/cfx_renderdevice.cpp b/core/fxge/ge/cfx_renderdevice.cpp index ba99c87469..15863e7611 100644 --- a/core/fxge/ge/cfx_renderdevice.cpp +++ b/core/fxge/ge/cfx_renderdevice.cpp @@ -860,6 +860,7 @@ bool CFX_RenderDevice::DrawNormalText(int nChars, char2device = *pText2Device; text2Device = *pText2Device; } + char2device.Scale(font_size, -font_size); if (FXSYS_fabs(char2device.a) + FXSYS_fabs(char2device.b) > 50 * 1.0f || ((m_DeviceClass == FXDC_PRINTER) && @@ -1072,7 +1073,9 @@ bool CFX_RenderDevice::DrawTextPath(int nChars, pFont->LoadGlyphPath(charpos.m_GlyphIndex, charpos.m_FontCharWidth); if (!pPath) continue; + matrix.Concat(*pText2User); + CFX_PathData TransformedPath(*pPath); TransformedPath.Transform(&matrix); if (fill_color || stroke_color) { -- cgit v1.2.3