diff options
author | tsepez <tsepez@chromium.org> | 2016-08-29 10:24:19 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-08-29 10:24:19 -0700 |
commit | d09a09751f724ecdb1a0bc307447a3d0c212ebff (patch) | |
tree | 917a2986be9769a6bfaf8ac4cc96a8a4006eed82 /core/fpdfapi/fpdf_page | |
parent | a032f7f79c67ddef4db0f44fca8f0d245bfb8e82 (diff) | |
download | pdfium-d09a09751f724ecdb1a0bc307447a3d0c212ebff.tar.xz |
Replace wrapper methods in CPDF_Path with -> operator.
These just invoked exaclty the same methodes in the underlying
xxxData class, which we can now do with just a ->()
Move some methods to the xxxData class, where they belong.
In doing so, put MakePrivateCopy() calls at each callsite
for those methods that made a copy.
Review-Url: https://codereview.chromium.org/2286983002
Diffstat (limited to 'core/fpdfapi/fpdf_page')
-rw-r--r-- | core/fpdfapi/fpdf_page/cpdf_allstates.cpp | 2 | ||||
-rw-r--r-- | core/fpdfapi/fpdf_page/cpdf_clippath.cpp | 12 | ||||
-rw-r--r-- | core/fpdfapi/fpdf_page/cpdf_pathobject.cpp | 4 | ||||
-rw-r--r-- | core/fpdfapi/fpdf_page/cpdf_textobject.cpp | 22 | ||||
-rw-r--r-- | core/fpdfapi/fpdf_page/cpdf_textstate.cpp | 47 | ||||
-rw-r--r-- | core/fpdfapi/fpdf_page/cpdf_textstate.h | 14 | ||||
-rw-r--r-- | core/fpdfapi/fpdf_page/cpdf_textstatedata.cpp | 35 | ||||
-rw-r--r-- | core/fpdfapi/fpdf_page/fpdf_page_parser.cpp | 14 | ||||
-rw-r--r-- | core/fpdfapi/fpdf_page/fpdf_page_parser_old.cpp | 10 | ||||
-rw-r--r-- | core/fpdfapi/fpdf_page/include/cpdf_path.h | 19 | ||||
-rw-r--r-- | core/fpdfapi/fpdf_page/include/cpdf_textstatedata.h | 12 |
11 files changed, 79 insertions, 112 deletions
diff --git a/core/fpdfapi/fpdf_page/cpdf_allstates.cpp b/core/fpdfapi/fpdf_page/cpdf_allstates.cpp index fb0c2445e7..eb43bd10c4 100644 --- a/core/fpdfapi/fpdf_page/cpdf_allstates.cpp +++ b/core/fpdfapi/fpdf_page/cpdf_allstates.cpp @@ -104,7 +104,7 @@ void CPDF_AllStates::ProcessExtGS(CPDF_Dictionary* pGS, m_TextState.MakePrivateCopy(); m_TextState->m_FontSize = pFont->GetNumberAt(1); - m_TextState.SetFont(pParser->FindFont(pFont->GetStringAt(0))); + m_TextState->SetFont(pParser->FindFont(pFont->GetStringAt(0))); break; } case FXBSTR_ID('T', 'R', 0, 0): diff --git a/core/fpdfapi/fpdf_page/cpdf_clippath.cpp b/core/fpdfapi/fpdf_page/cpdf_clippath.cpp index 2c05df0d19..51f3086c12 100644 --- a/core/fpdfapi/fpdf_page/cpdf_clippath.cpp +++ b/core/fpdfapi/fpdf_page/cpdf_clippath.cpp @@ -38,9 +38,9 @@ CFX_FloatRect CPDF_ClipPath::GetClipBox() const { FX_BOOL bStarted = FALSE; int count = GetPathCount(); if (count) { - rect = GetPath(0).GetBoundingBox(); + rect = GetPath(0)->GetBoundingBox(); for (int i = 1; i < count; i++) { - CFX_FloatRect path_rect = GetPath(i).GetBoundingBox(); + CFX_FloatRect path_rect = GetPath(i)->GetBoundingBox(); rect.Intersect(path_rect); } bStarted = TRUE; @@ -77,10 +77,10 @@ void CPDF_ClipPath::AppendPath(CPDF_Path path, uint8_t type, bool bAutoMerge) { CPDF_ClipPathData* pData = GetObject(); if (!pData->m_PathAndTypeList.empty() && bAutoMerge) { const CPDF_Path& old_path = pData->m_PathAndTypeList.back().first; - if (old_path.IsRect()) { - CFX_FloatRect old_rect(old_path.GetPointX(0), old_path.GetPointY(0), - old_path.GetPointX(2), old_path.GetPointY(2)); - CFX_FloatRect new_rect = path.GetBoundingBox(); + if (old_path->IsRect()) { + CFX_FloatRect old_rect(old_path->GetPointX(0), old_path->GetPointY(0), + old_path->GetPointX(2), old_path->GetPointY(2)); + CFX_FloatRect new_rect = path->GetBoundingBox(); if (old_rect.Contains(new_rect)) pData->m_PathAndTypeList.pop_back(); } diff --git a/core/fpdfapi/fpdf_page/cpdf_pathobject.cpp b/core/fpdfapi/fpdf_page/cpdf_pathobject.cpp index ceb3dd43cc..d48c84bf4a 100644 --- a/core/fpdfapi/fpdf_page/cpdf_pathobject.cpp +++ b/core/fpdfapi/fpdf_page/cpdf_pathobject.cpp @@ -48,9 +48,9 @@ void CPDF_PathObject::CalcBoundingBox() { CFX_FloatRect rect; FX_FLOAT width = m_GraphState->m_LineWidth; if (m_bStroke && width != 0) { - rect = m_Path.GetBoundingBox(width, m_GraphState->m_MiterLimit); + rect = m_Path->GetBoundingBox(width, m_GraphState->m_MiterLimit); } else { - rect = m_Path.GetBoundingBox(); + rect = m_Path->GetBoundingBox(); } rect.Transform(&m_Matrix); if (width == 0 && m_bStroke) { diff --git a/core/fpdfapi/fpdf_page/cpdf_textobject.cpp b/core/fpdfapi/fpdf_page/cpdf_textobject.cpp index a3653359de..7b39dff924 100644 --- a/core/fpdfapi/fpdf_page/cpdf_textobject.cpp +++ b/core/fpdfapi/fpdf_page/cpdf_textobject.cpp @@ -35,7 +35,7 @@ void CPDF_TextObject::GetItemInfo(int index, CPDF_TextObjectItem* pInfo) const { if (pInfo->m_CharCode == CPDF_Font::kInvalidCharCode) { return; } - CPDF_Font* pFont = m_TextState.GetFont(); + CPDF_Font* pFont = m_TextState->GetFont(); if (!pFont->IsCIDFont()) { return; } @@ -47,7 +47,7 @@ void CPDF_TextObject::GetItemInfo(int index, CPDF_TextObjectItem* pInfo) const { pInfo->m_OriginX = 0; short vx, vy; pFont->AsCIDFont()->GetVertOrigin(CID, vx, vy); - FX_FLOAT fontsize = m_TextState.GetFontSize(); + FX_FLOAT fontsize = m_TextState->GetFontSize(); pInfo->m_OriginX -= fontsize * vx / 1000; pInfo->m_OriginY -= fontsize * vy / 1000; } @@ -137,7 +137,7 @@ void CPDF_TextObject::Transform(const CFX_Matrix& matrix) { CFX_Matrix text_matrix; GetTextMatrix(&text_matrix); text_matrix.Concat(matrix); - FX_FLOAT* pTextMatrix = m_TextState.GetMatrix(); + FX_FLOAT* pTextMatrix = m_TextState->GetMatrix(); pTextMatrix[0] = text_matrix.GetA(); pTextMatrix[1] = text_matrix.GetC(); pTextMatrix[2] = text_matrix.GetB(); @@ -160,7 +160,7 @@ const CPDF_TextObject* CPDF_TextObject::AsText() const { } void CPDF_TextObject::GetTextMatrix(CFX_Matrix* pMatrix) const { - const FX_FLOAT* pTextMatrix = m_TextState.GetMatrix(); + const FX_FLOAT* pTextMatrix = m_TextState->GetMatrix(); pMatrix->Set(pTextMatrix[0], pTextMatrix[2], pTextMatrix[1], pTextMatrix[3], m_PosX, m_PosY); } @@ -174,7 +174,7 @@ void CPDF_TextObject::SetSegments(const CFX_ByteString* pStrs, } FX_Free(m_pCharPos); m_pCharPos = nullptr; - CPDF_Font* pFont = m_TextState.GetFont(); + CPDF_Font* pFont = m_TextState->GetFont(); m_nChars = 0; for (int i = 0; i < nsegs; ++i) { m_nChars += pFont->CountChar(pStrs[i].c_str(), pStrs[i].GetLength()); @@ -209,8 +209,8 @@ void CPDF_TextObject::SetText(const CFX_ByteString& str) { } FX_FLOAT CPDF_TextObject::GetCharWidth(uint32_t charcode) const { - FX_FLOAT fontsize = m_TextState.GetFontSize() / 1000; - CPDF_Font* pFont = m_TextState.GetFont(); + FX_FLOAT fontsize = m_TextState->GetFontSize() / 1000; + CPDF_Font* pFont = m_TextState->GetFont(); FX_BOOL bVertWriting = FALSE; CPDF_CIDFont* pCIDFont = pFont->AsCIDFont(); if (pCIDFont) { @@ -232,11 +232,11 @@ FX_FLOAT CPDF_TextObject::GetPosY() const { } CPDF_Font* CPDF_TextObject::GetFont() const { - return m_TextState.GetFont(); + return m_TextState->GetFont(); } FX_FLOAT CPDF_TextObject::GetFontSize() const { - return m_TextState.GetFontSize(); + return m_TextState->GetFontSize(); } void CPDF_TextObject::CalcPositionData(FX_FLOAT* pTextAdvanceX, @@ -248,13 +248,13 @@ void CPDF_TextObject::CalcPositionData(FX_FLOAT* pTextAdvanceX, FX_FLOAT max_x = -10000 * 1.0f; FX_FLOAT min_y = 10000 * 1.0f; FX_FLOAT max_y = -10000 * 1.0f; - CPDF_Font* pFont = m_TextState.GetFont(); + CPDF_Font* pFont = m_TextState->GetFont(); FX_BOOL bVertWriting = FALSE; CPDF_CIDFont* pCIDFont = pFont->AsCIDFont(); if (pCIDFont) { bVertWriting = pCIDFont->IsVertWriting(); } - FX_FLOAT fontsize = m_TextState.GetFontSize(); + FX_FLOAT fontsize = m_TextState->GetFontSize(); for (int i = 0; i < m_nChars; ++i) { uint32_t charcode = m_nChars == 1 ? (uint32_t)(uintptr_t)m_pCharCodes : m_pCharCodes[i]; diff --git a/core/fpdfapi/fpdf_page/cpdf_textstate.cpp b/core/fpdfapi/fpdf_page/cpdf_textstate.cpp deleted file mode 100644 index 47e2116836..0000000000 --- a/core/fpdfapi/fpdf_page/cpdf_textstate.cpp +++ /dev/null @@ -1,47 +0,0 @@ -// Copyright 2016 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#include "core/fpdfapi/fpdf_font/include/cpdf_font.h" -#include "core/fpdfapi/fpdf_page/cpdf_textstate.h" -#include "core/fpdfapi/fpdf_page/pageint.h" -#include "core/fpdfapi/fpdf_parser/include/cpdf_document.h" - -void CPDF_TextState::SetFont(CPDF_Font* pFont) { - MakePrivateCopy(); - CPDF_TextStateData* pStateData = GetObject(); - CPDF_Document* pDoc = pStateData->m_pDocument; - CPDF_DocPageData* pPageData = pDoc ? pDoc->GetPageData() : nullptr; - if (pPageData && pStateData->m_pFont && !pPageData->IsForceClear()) - pPageData->ReleaseFont(pStateData->m_pFont->GetFontDict()); - - pStateData->m_pDocument = pFont ? pFont->m_pDocument : nullptr; - pStateData->m_pFont = pFont; -} - -FX_FLOAT CPDF_TextState::GetFontSizeV() const { - const FX_FLOAT* pMatrix = GetMatrix(); - FX_FLOAT unit = FXSYS_sqrt2(pMatrix[1], pMatrix[3]); - FX_FLOAT size = unit * GetFontSize(); - return (FX_FLOAT)FXSYS_fabs(size); -} - -FX_FLOAT CPDF_TextState::GetFontSizeH() const { - const FX_FLOAT* pMatrix = GetMatrix(); - FX_FLOAT unit = FXSYS_sqrt2(pMatrix[0], pMatrix[2]); - FX_FLOAT size = unit * GetFontSize(); - return (FX_FLOAT)FXSYS_fabs(size); -} - -FX_FLOAT CPDF_TextState::GetBaselineAngle() const { - const FX_FLOAT* m_Matrix = GetMatrix(); - return FXSYS_atan2(m_Matrix[2], m_Matrix[0]); -} - -FX_FLOAT CPDF_TextState::GetShearAngle() const { - const FX_FLOAT* m_Matrix = GetMatrix(); - FX_FLOAT shear_angle = FXSYS_atan2(m_Matrix[1], m_Matrix[3]); - return GetBaselineAngle() + shear_angle; -} diff --git a/core/fpdfapi/fpdf_page/cpdf_textstate.h b/core/fpdfapi/fpdf_page/cpdf_textstate.h index 59c988de06..744739a6ac 100644 --- a/core/fpdfapi/fpdf_page/cpdf_textstate.h +++ b/core/fpdfapi/fpdf_page/cpdf_textstate.h @@ -10,21 +10,7 @@ #include "core/fpdfapi/fpdf_page/include/cpdf_textstatedata.h" #include "core/fxcrt/include/fx_basic.h" -class CPDF_Font; - class CPDF_TextState : public CFX_CountRef<CPDF_TextStateData> { - public: - CPDF_Font* GetFont() const { return GetObject()->m_pFont; } - void SetFont(CPDF_Font* pFont); - - FX_FLOAT GetFontSize() const { return GetObject()->m_FontSize; } - FX_FLOAT* GetMatrix() { return GetObject()->m_Matrix; } - const FX_FLOAT* GetMatrix() const { return GetObject()->m_Matrix; } - - FX_FLOAT GetFontSizeV() const; - FX_FLOAT GetFontSizeH() const; - FX_FLOAT GetBaselineAngle() const; - FX_FLOAT GetShearAngle() const; }; #endif // CORE_FPDFAPI_FPDF_PAGE_CPDF_TEXTSTATE_H_ diff --git a/core/fpdfapi/fpdf_page/cpdf_textstatedata.cpp b/core/fpdfapi/fpdf_page/cpdf_textstatedata.cpp index e60af0076e..9ae99a1cdb 100644 --- a/core/fpdfapi/fpdf_page/cpdf_textstatedata.cpp +++ b/core/fpdfapi/fpdf_page/cpdf_textstatedata.cpp @@ -72,3 +72,38 @@ CPDF_TextStateData::~CPDF_TextStateData() { pPageData->ReleaseFont(m_pFont->GetFontDict()); } } + +void CPDF_TextStateData::SetFont(CPDF_Font* pFont) { + CPDF_DocPageData* pPageData = + m_pDocument ? m_pDocument->GetPageData() : nullptr; + if (pPageData && m_pFont && !pPageData->IsForceClear()) + pPageData->ReleaseFont(m_pFont->GetFontDict()); + + m_pDocument = pFont ? pFont->m_pDocument : nullptr; + m_pFont = pFont; +} + +FX_FLOAT CPDF_TextStateData::GetFontSizeV() const { + const FX_FLOAT* pMatrix = GetMatrix(); + FX_FLOAT unit = FXSYS_sqrt2(pMatrix[1], pMatrix[3]); + FX_FLOAT size = unit * GetFontSize(); + return (FX_FLOAT)FXSYS_fabs(size); +} + +FX_FLOAT CPDF_TextStateData::GetFontSizeH() const { + const FX_FLOAT* pMatrix = GetMatrix(); + FX_FLOAT unit = FXSYS_sqrt2(pMatrix[0], pMatrix[2]); + FX_FLOAT size = unit * GetFontSize(); + return (FX_FLOAT)FXSYS_fabs(size); +} + +FX_FLOAT CPDF_TextStateData::GetBaselineAngle() const { + const FX_FLOAT* pMatrix = GetMatrix(); + return FXSYS_atan2(pMatrix[2], pMatrix[0]); +} + +FX_FLOAT CPDF_TextStateData::GetShearAngle() const { + const FX_FLOAT* pMatrix = GetMatrix(); + FX_FLOAT shear_angle = FXSYS_atan2(pMatrix[1], pMatrix[3]); + return GetBaselineAngle() + shear_angle; +} diff --git a/core/fpdfapi/fpdf_page/fpdf_page_parser.cpp b/core/fpdfapi/fpdf_page/fpdf_page_parser.cpp index 3afcf4b7d1..5d5b75b60e 100644 --- a/core/fpdfapi/fpdf_page/fpdf_page_parser.cpp +++ b/core/fpdfapi/fpdf_page/fpdf_page_parser.cpp @@ -1144,7 +1144,7 @@ void CPDF_StreamContentParser::Handle_SetFont() { m_pCurStates->m_TextState->m_FontSize = fs; CPDF_Font* pFont = FindFont(GetString(1)); if (pFont) - m_pCurStates->m_TextState.SetFont(pFont); + m_pCurStates->m_TextState->SetFont(pFont); } CPDF_Object* CPDF_StreamContentParser::FindResourceObj( @@ -1231,17 +1231,17 @@ void CPDF_StreamContentParser::AddTextObject(CFX_ByteString* pStrs, FX_FLOAT fInitKerning, FX_FLOAT* pKerning, int nsegs) { - CPDF_Font* pFont = m_pCurStates->m_TextState.GetFont(); + CPDF_Font* pFont = m_pCurStates->m_TextState->GetFont(); if (!pFont) { return; } if (fInitKerning != 0) { if (!pFont->IsVertWriting()) { m_pCurStates->m_TextX -= - (fInitKerning * m_pCurStates->m_TextState.GetFontSize()) / 1000; + (fInitKerning * m_pCurStates->m_TextState->GetFontSize()) / 1000; } else { m_pCurStates->m_TextY -= - (fInitKerning * m_pCurStates->m_TextState.GetFontSize()) / 1000; + (fInitKerning * m_pCurStates->m_TextState->GetFontSize()) / 1000; } } if (nsegs == 0) { @@ -1281,11 +1281,11 @@ void CPDF_StreamContentParser::AddTextObject(CFX_ByteString* pStrs, if (pKerning && pKerning[nsegs - 1] != 0) { if (!pFont->IsVertWriting()) { m_pCurStates->m_TextX -= - (pKerning[nsegs - 1] * m_pCurStates->m_TextState.GetFontSize()) / + (pKerning[nsegs - 1] * m_pCurStates->m_TextState->GetFontSize()) / 1000; } else { m_pCurStates->m_TextY -= - (pKerning[nsegs - 1] * m_pCurStates->m_TextState.GetFontSize()) / + (pKerning[nsegs - 1] * m_pCurStates->m_TextState->GetFontSize()) / 1000; } } @@ -1313,7 +1313,7 @@ void CPDF_StreamContentParser::Handle_ShowText_Positioning() { if (nsegs == 0) { for (size_t i = 0; i < n; i++) { m_pCurStates->m_TextX -= - (pArray->GetNumberAt(i) * m_pCurStates->m_TextState.GetFontSize()) / + (pArray->GetNumberAt(i) * m_pCurStates->m_TextState->GetFontSize()) / 1000; } return; diff --git a/core/fpdfapi/fpdf_page/fpdf_page_parser_old.cpp b/core/fpdfapi/fpdf_page/fpdf_page_parser_old.cpp index 1b37862e99..e19c9a4a61 100644 --- a/core/fpdfapi/fpdf_page/fpdf_page_parser_old.cpp +++ b/core/fpdfapi/fpdf_page/fpdf_page_parser_old.cpp @@ -689,8 +689,8 @@ void CPDF_ContentParser::Start(CPDF_Form* pForm, if (pBBox) { form_bbox = pBBox->GetRect(); ClipPath.New(); - ClipPath.AppendRect(form_bbox.left, form_bbox.bottom, form_bbox.right, - form_bbox.top); + ClipPath->AppendRect(form_bbox.left, form_bbox.bottom, form_bbox.right, + form_bbox.top); ClipPath.Transform(&form_matrix); if (pParentMatrix) { ClipPath.Transform(pParentMatrix); @@ -808,10 +808,10 @@ void CPDF_ContentParser::Continue(IFX_Pause* pPause) { if (pObj->m_ClipPath.GetTextCount()) continue; CPDF_Path ClipPath = pObj->m_ClipPath.GetPath(0); - if (!ClipPath.IsRect() || pObj->IsShading()) + if (!ClipPath->IsRect() || pObj->IsShading()) continue; - CFX_FloatRect old_rect(ClipPath.GetPointX(0), ClipPath.GetPointY(0), - ClipPath.GetPointX(2), ClipPath.GetPointY(2)); + CFX_FloatRect old_rect(ClipPath->GetPointX(0), ClipPath->GetPointY(0), + ClipPath->GetPointX(2), ClipPath->GetPointY(2)); CFX_FloatRect obj_rect(pObj->m_Left, pObj->m_Bottom, pObj->m_Right, pObj->m_Top); if (old_rect.Contains(obj_rect)) diff --git a/core/fpdfapi/fpdf_page/include/cpdf_path.h b/core/fpdfapi/fpdf_page/include/cpdf_path.h index 33db4d755a..adc7d86f44 100644 --- a/core/fpdfapi/fpdf_page/include/cpdf_path.h +++ b/core/fpdfapi/fpdf_page/include/cpdf_path.h @@ -14,18 +14,6 @@ class CPDF_Path : public CFX_CountRef<CFX_PathData> { public: - int GetPointCount() const { return GetObject()->GetPointCount(); } - int GetFlag(int index) const { return GetObject()->GetFlag(index); } - FX_FLOAT GetPointX(int index) const { return GetObject()->GetPointX(index); } - FX_FLOAT GetPointY(int index) const { return GetObject()->GetPointY(index); } - FX_PATHPOINT* GetPoints() const { return GetObject()->GetPoints(); } - CFX_FloatRect GetBoundingBox() const { return GetObject()->GetBoundingBox(); } - CFX_FloatRect GetBoundingBox(FX_FLOAT line_width, - FX_FLOAT miter_limit) const { - return GetObject()->GetBoundingBox(line_width, miter_limit); - } - - FX_BOOL IsRect() const { return GetObject()->IsRect(); } void Transform(const CFX_Matrix* pMatrix) { MakePrivateCopy(); GetObject()->Transform(pMatrix); @@ -33,13 +21,6 @@ class CPDF_Path : public CFX_CountRef<CFX_PathData> { void Append(const CPDF_Path& other, const CFX_Matrix* pMatrix) { GetObject()->Append(other.GetObject(), pMatrix); } - - void AppendRect(FX_FLOAT left, - FX_FLOAT bottom, - FX_FLOAT right, - FX_FLOAT top) { - GetObject()->AppendRect(left, bottom, right, top); - } }; #endif // CORE_FPDFAPI_FPDF_PAGE_INCLUDE_CPDF_PATH_H_ diff --git a/core/fpdfapi/fpdf_page/include/cpdf_textstatedata.h b/core/fpdfapi/fpdf_page/include/cpdf_textstatedata.h index 4e33d5f170..40fa1ea8d3 100644 --- a/core/fpdfapi/fpdf_page/include/cpdf_textstatedata.h +++ b/core/fpdfapi/fpdf_page/include/cpdf_textstatedata.h @@ -34,6 +34,18 @@ class CPDF_TextStateData { CPDF_TextStateData(const CPDF_TextStateData& src); ~CPDF_TextStateData(); + void SetFont(CPDF_Font* pFont); + + CPDF_Font* GetFont() const { return m_pFont; } + FX_FLOAT GetFontSize() const { return m_FontSize; } + FX_FLOAT* GetMatrix() { return m_Matrix; } + const FX_FLOAT* GetMatrix() const { return m_Matrix; } + + FX_FLOAT GetFontSizeV() const; + FX_FLOAT GetFontSizeH() const; + FX_FLOAT GetBaselineAngle() const; + FX_FLOAT GetShearAngle() const; + CPDF_Font* m_pFont; CPDF_Document* m_pDocument; FX_FLOAT m_FontSize; |