diff options
author | tsepez <tsepez@chromium.org> | 2016-08-30 10:32:36 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-08-30 10:32:36 -0700 |
commit | fbda17d61de1e02799f5d77dceb23df3688b764e (patch) | |
tree | ad15940f6c9bf31ca390a711636981ecd0e52ff6 /core/fpdfapi/fpdf_page | |
parent | f7252a074ed013e2ad3cc11e08eba90502262ce0 (diff) | |
download | pdfium-fbda17d61de1e02799f5d77dceb23df3688b764e.tar.xz |
Make CPDF_TextState have a CPDF_TextStateData rather than inheriting one.
Review-Url: https://codereview.chromium.org/2287313004
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_graphicstates.cpp | 2 | ||||
-rw-r--r-- | core/fpdfapi/fpdf_page/cpdf_textobject.cpp | 6 | ||||
-rw-r--r-- | core/fpdfapi/fpdf_page/cpdf_textstate.cpp | 90 | ||||
-rw-r--r-- | core/fpdfapi/fpdf_page/cpdf_textstate.h | 33 | ||||
-rw-r--r-- | core/fpdfapi/fpdf_page/cpdf_textstatedata.cpp | 26 | ||||
-rw-r--r-- | core/fpdfapi/fpdf_page/fpdf_page_parser.cpp | 39 | ||||
-rw-r--r-- | core/fpdfapi/fpdf_page/fpdf_page_parser_old.cpp | 2 | ||||
-rw-r--r-- | core/fpdfapi/fpdf_page/include/cpdf_textstatedata.h | 6 |
9 files changed, 151 insertions, 55 deletions
diff --git a/core/fpdfapi/fpdf_page/cpdf_allstates.cpp b/core/fpdfapi/fpdf_page/cpdf_allstates.cpp index e4b6e328b9..e01b379bed 100644 --- a/core/fpdfapi/fpdf_page/cpdf_allstates.cpp +++ b/core/fpdfapi/fpdf_page/cpdf_allstates.cpp @@ -98,7 +98,7 @@ void CPDF_AllStates::ProcessExtGS(CPDF_Dictionary* pGS, if (!pFont) break; - m_TextState.GetPrivateCopy()->m_FontSize = pFont->GetNumberAt(1); + m_TextState.SetFontSize(pFont->GetNumberAt(1)); m_TextState.SetFont(pParser->FindFont(pFont->GetStringAt(0))); break; } diff --git a/core/fpdfapi/fpdf_page/cpdf_graphicstates.cpp b/core/fpdfapi/fpdf_page/cpdf_graphicstates.cpp index fc054caf21..e411b53a51 100644 --- a/core/fpdfapi/fpdf_page/cpdf_graphicstates.cpp +++ b/core/fpdfapi/fpdf_page/cpdf_graphicstates.cpp @@ -11,7 +11,7 @@ CPDF_GraphicStates::CPDF_GraphicStates() {} CPDF_GraphicStates::~CPDF_GraphicStates() {} void CPDF_GraphicStates::DefaultStates() { - m_ColorState.New()->Default(); + m_ColorState.Emplace()->Default(); } void CPDF_GraphicStates::CopyStates(const CPDF_GraphicStates& src) { diff --git a/core/fpdfapi/fpdf_page/cpdf_textobject.cpp b/core/fpdfapi/fpdf_page/cpdf_textobject.cpp index af6ae06741..f9e6bdaa76 100644 --- a/core/fpdfapi/fpdf_page/cpdf_textobject.cpp +++ b/core/fpdfapi/fpdf_page/cpdf_textobject.cpp @@ -334,9 +334,9 @@ void CPDF_TextObject::CalcPositionData(FX_FLOAT* pTextAdvanceX, } curpos += charwidth; if (charcode == ' ' && (!pCIDFont || pCIDFont->GetCharSize(32) == 1)) { - curpos += m_TextState.GetObject()->m_WordSpace; + curpos += m_TextState.GetWordSpace(); } - curpos += m_TextState.GetObject()->m_CharSpace; + curpos += m_TextState.GetCharSpace(); } if (bVertWriting) { if (pTextAdvanceX) { @@ -364,7 +364,7 @@ void CPDF_TextObject::CalcPositionData(FX_FLOAT* pTextAdvanceX, m_Bottom = min_y; m_Top = max_y; matrix.TransformRect(m_Left, m_Right, m_Top, m_Bottom); - if (TextRenderingModeIsStrokeMode(m_TextState.GetObject()->m_TextMode)) { + if (TextRenderingModeIsStrokeMode(m_TextState.GetTextMode())) { FX_FLOAT half_width = m_GraphState.GetObject()->m_LineWidth / 2; m_Left -= half_width; m_Right += half_width; diff --git a/core/fpdfapi/fpdf_page/cpdf_textstate.cpp b/core/fpdfapi/fpdf_page/cpdf_textstate.cpp index ae75876664..feb70aeecc 100644 --- a/core/fpdfapi/fpdf_page/cpdf_textstate.cpp +++ b/core/fpdfapi/fpdf_page/cpdf_textstate.cpp @@ -4,45 +4,87 @@ // 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_font/include/cpdf_font.h" #include "core/fpdfapi/fpdf_page/pageint.h" #include "core/fpdfapi/fpdf_parser/include/cpdf_document.h" +CPDF_TextState::CPDF_TextState() {} +CPDF_TextState::~CPDF_TextState() {} + +void CPDF_TextState::Emplace() { + m_Ref.Emplace(); +} + +CPDF_Font* CPDF_TextState::GetFont() const { + return m_Ref.GetObject()->m_pFont; +} + void CPDF_TextState::SetFont(CPDF_Font* pFont) { - CPDF_TextStateData* pStateData = GetPrivateCopy(); - if (pStateData) { - 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; - } + m_Ref.GetPrivateCopy()->SetFont(pFont); +} + +FX_FLOAT CPDF_TextState::GetFontSize() const { + return m_Ref.GetObject()->m_FontSize; +} + +void CPDF_TextState::SetFontSize(FX_FLOAT size) { + m_Ref.GetPrivateCopy()->m_FontSize = size; +} + +const FX_FLOAT* CPDF_TextState::GetMatrix() const { + return m_Ref.GetObject()->m_Matrix; +} + +FX_FLOAT* CPDF_TextState::GetMutableMatrix() { + return m_Ref.GetPrivateCopy()->m_Matrix; +} + +FX_FLOAT CPDF_TextState::GetCharSpace() const { + return m_Ref.GetObject()->m_CharSpace; +} + +void CPDF_TextState::SetCharSpace(FX_FLOAT sp) { + m_Ref.GetPrivateCopy()->m_CharSpace = sp; +} + +FX_FLOAT CPDF_TextState::GetWordSpace() const { + return m_Ref.GetObject()->m_WordSpace; +} + +void CPDF_TextState::SetWordSpace(FX_FLOAT sp) { + m_Ref.GetPrivateCopy()->m_WordSpace = sp; } 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); + return m_Ref.GetObject()->GetFontSizeV(); } 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); + return m_Ref.GetObject()->GetFontSizeH(); } FX_FLOAT CPDF_TextState::GetBaselineAngle() const { - const FX_FLOAT* m_Matrix = GetMatrix(); - return FXSYS_atan2(m_Matrix[2], m_Matrix[0]); + return m_Ref.GetObject()->GetBaselineAngle(); } 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; + return m_Ref.GetObject()->GetShearAngle(); +} + +TextRenderingMode CPDF_TextState::GetTextMode() const { + return m_Ref.GetObject()->m_TextMode; +} + +void CPDF_TextState::SetTextMode(TextRenderingMode mode) { + m_Ref.GetPrivateCopy()->m_TextMode = mode; +} + +const FX_FLOAT* CPDF_TextState::GetCTM() const { + return m_Ref.GetObject()->m_CTM; +} + +FX_FLOAT* CPDF_TextState::GetMutableCTM() { + return m_Ref.GetPrivateCopy()->m_CTM; } diff --git a/core/fpdfapi/fpdf_page/cpdf_textstate.h b/core/fpdfapi/fpdf_page/cpdf_textstate.h index 235bdf1aa1..87f0b5cef4 100644 --- a/core/fpdfapi/fpdf_page/cpdf_textstate.h +++ b/core/fpdfapi/fpdf_page/cpdf_textstate.h @@ -8,23 +8,46 @@ #define CORE_FPDFAPI_FPDF_PAGE_CPDF_TEXTSTATE_H_ #include "core/fpdfapi/fpdf_page/include/cpdf_textstatedata.h" +#include "core/fxcrt/include/cfx_count_ref.h" #include "core/fxcrt/include/fx_basic.h" class CPDF_Font; -class CPDF_TextState : public CFX_CountRef<CPDF_TextStateData> { +class CPDF_TextState { public: - CPDF_Font* GetFont() const { return GetObject()->m_pFont; } + CPDF_TextState(); + ~CPDF_TextState(); + + void Emplace(); + + CPDF_Font* GetFont() const; void SetFont(CPDF_Font* pFont); - FX_FLOAT GetFontSize() const { return GetObject()->m_FontSize; } - const FX_FLOAT* GetMatrix() const { return GetObject()->m_Matrix; } - FX_FLOAT* GetMutableMatrix() { return GetPrivateCopy()->m_Matrix; } + FX_FLOAT GetFontSize() const; + void SetFontSize(FX_FLOAT size); + + const FX_FLOAT* GetMatrix() const; + FX_FLOAT* GetMutableMatrix(); + + FX_FLOAT GetCharSpace() const; + void SetCharSpace(FX_FLOAT sp); + + FX_FLOAT GetWordSpace() const; + void SetWordSpace(FX_FLOAT sp); FX_FLOAT GetFontSizeV() const; FX_FLOAT GetFontSizeH() const; FX_FLOAT GetBaselineAngle() const; FX_FLOAT GetShearAngle() const; + + TextRenderingMode GetTextMode() const; + void SetTextMode(TextRenderingMode mode); + + const FX_FLOAT* GetCTM() const; + FX_FLOAT* GetMutableCTM(); + + private: + CFX_CountRef<CPDF_TextStateData> m_Ref; }; #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..17c33a012c 100644 --- a/core/fpdfapi/fpdf_page/cpdf_textstatedata.cpp +++ b/core/fpdfapi/fpdf_page/cpdf_textstatedata.cpp @@ -72,3 +72,29 @@ CPDF_TextStateData::~CPDF_TextStateData() { pPageData->ReleaseFont(m_pFont->GetFontDict()); } } + +void CPDF_TextStateData::SetFont(CPDF_Font* pFont) { + CPDF_Document* pDoc = m_pDocument; + CPDF_DocPageData* pPageData = pDoc ? pDoc->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 { + return FXSYS_fabs(FXSYS_sqrt2(m_Matrix[1], m_Matrix[3]) * m_FontSize); +} + +FX_FLOAT CPDF_TextStateData::GetFontSizeH() const { + return FXSYS_fabs(FXSYS_sqrt2(m_Matrix[0], m_Matrix[2]) * m_FontSize); +} + +FX_FLOAT CPDF_TextStateData::GetBaselineAngle() const { + return FXSYS_atan2(m_Matrix[2], m_Matrix[0]); +} + +FX_FLOAT CPDF_TextStateData::GetShearAngle() const { + return GetBaselineAngle() + FXSYS_atan2(m_Matrix[1], m_Matrix[3]); +} diff --git a/core/fpdfapi/fpdf_page/fpdf_page_parser.cpp b/core/fpdfapi/fpdf_page/fpdf_page_parser.cpp index f1101034ae..5560b9c20f 100644 --- a/core/fpdfapi/fpdf_page/fpdf_page_parser.cpp +++ b/core/fpdfapi/fpdf_page/fpdf_page_parser.cpp @@ -235,10 +235,10 @@ CPDF_StreamContentParser::CPDF_StreamContentParser( if (pStates) { m_pCurStates->Copy(*pStates); } else { - m_pCurStates->m_GeneralState.New(); - m_pCurStates->m_GraphState.New(); - m_pCurStates->m_TextState.New(); - m_pCurStates->m_ColorState.New(); + m_pCurStates->m_GeneralState.Emplace(); + m_pCurStates->m_GraphState.Emplace(); + m_pCurStates->m_TextState.Emplace(); + m_pCurStates->m_ColorState.Emplace(); } for (size_t i = 0; i < FX_ArraySize(m_Type3Data); ++i) { m_Type3Data[i] = 0.0; @@ -823,10 +823,9 @@ void CPDF_StreamContentParser::Handle_EndText() { if (m_ClipTextList.empty()) return; - if (TextRenderingModeIsClipMode( - m_pCurStates->m_TextState.GetObject()->m_TextMode)) { + if (TextRenderingModeIsClipMode(m_pCurStates->m_TextState.GetTextMode())) m_pCurStates->m_ClipPath.AppendTexts(&m_ClipTextList); - } + m_ClipTextList.clear(); } @@ -1114,7 +1113,7 @@ void CPDF_StreamContentParser::Handle_ShadeFill() { } void CPDF_StreamContentParser::Handle_SetCharSpace() { - m_pCurStates->m_TextState.GetPrivateCopy()->m_CharSpace = GetNumber(0); + m_pCurStates->m_TextState.SetCharSpace(GetNumber(0)); } void CPDF_StreamContentParser::Handle_MoveTextPoint() { @@ -1134,7 +1133,7 @@ void CPDF_StreamContentParser::Handle_SetFont() { if (fs == 0) { fs = m_DefFontSize; } - m_pCurStates->m_TextState.GetPrivateCopy()->m_FontSize = fs; + m_pCurStates->m_TextState.SetFontSize(fs); CPDF_Font* pFont = FindFont(GetString(1)); if (pFont) { m_pCurStates->m_TextState.SetFont(pFont); @@ -1243,13 +1242,13 @@ void CPDF_StreamContentParser::AddTextObject(CFX_ByteString* pStrs, } const TextRenderingMode text_mode = pFont->IsType3Font() ? TextRenderingMode::MODE_FILL - : m_pCurStates->m_TextState.GetObject()->m_TextMode; + : m_pCurStates->m_TextState.GetTextMode(); { std::unique_ptr<CPDF_TextObject> pText(new CPDF_TextObject); m_pLastTextObject = pText.get(); SetGraphicStates(m_pLastTextObject, TRUE, TRUE, TRUE); if (TextRenderingModeIsStrokeMode(text_mode)) { - FX_FLOAT* pCTM = pText->m_TextState.GetPrivateCopy()->m_CTM; + FX_FLOAT* pCTM = pText->m_TextState.GetMutableCTM(); pCTM[0] = m_pCurStates->m_CTM.a; pCTM[1] = m_pCurStates->m_CTM.c; pCTM[2] = m_pCurStates->m_CTM.b; @@ -1358,7 +1357,7 @@ void CPDF_StreamContentParser::OnChangeTextMatrix() { text_matrix.Concat(m_pCurStates->m_TextMatrix); text_matrix.Concat(m_pCurStates->m_CTM); text_matrix.Concat(m_mtContentToUser); - FX_FLOAT* pTextMatrix = m_pCurStates->m_TextState.GetPrivateCopy()->m_Matrix; + FX_FLOAT* pTextMatrix = m_pCurStates->m_TextState.GetMutableMatrix(); pTextMatrix[0] = text_matrix.a; pTextMatrix[1] = text_matrix.c; pTextMatrix[2] = text_matrix.b; @@ -1366,9 +1365,9 @@ void CPDF_StreamContentParser::OnChangeTextMatrix() { } void CPDF_StreamContentParser::Handle_SetTextRenderMode() { - int mode = GetInteger(0); - SetTextRenderingModeFromInt( - mode, &m_pCurStates->m_TextState.GetPrivateCopy()->m_TextMode); + TextRenderingMode mode; + if (SetTextRenderingModeFromInt(GetInteger(0), &mode)) + m_pCurStates->m_TextState.SetTextMode(mode); } void CPDF_StreamContentParser::Handle_SetTextRise() { @@ -1376,7 +1375,7 @@ void CPDF_StreamContentParser::Handle_SetTextRise() { } void CPDF_StreamContentParser::Handle_SetWordSpace() { - m_pCurStates->m_TextState.GetPrivateCopy()->m_WordSpace = GetNumber(0); + m_pCurStates->m_TextState.SetWordSpace(GetNumber(0)); } void CPDF_StreamContentParser::Handle_SetHorzScale() { @@ -1424,8 +1423,8 @@ void CPDF_StreamContentParser::Handle_NextLineShowText() { } void CPDF_StreamContentParser::Handle_NextLineShowText_Space() { - m_pCurStates->m_TextState.GetPrivateCopy()->m_WordSpace = GetNumber(2); - m_pCurStates->m_TextState.GetPrivateCopy()->m_CharSpace = GetNumber(1); + m_pCurStates->m_TextState.SetWordSpace(GetNumber(2)); + m_pCurStates->m_TextState.SetCharSpace(GetNumber(1)); Handle_NextLineShowText(); } @@ -1471,7 +1470,7 @@ void CPDF_StreamContentParser::AddPathObject(int FillType, FX_BOOL bStroke) { if (PathPointCount <= 1) { if (PathPointCount && PathClipType) { CPDF_Path path; - path.New()->AppendRect(0, 0, 0, 0); + path.Emplace()->AppendRect(0, 0, 0, 0); m_pCurStates->m_ClipPath.AppendPath(path, FXFILL_WINDING, TRUE); } return; @@ -1481,7 +1480,7 @@ void CPDF_StreamContentParser::AddPathObject(int FillType, FX_BOOL bStroke) { PathPointCount--; } CPDF_Path Path; - CFX_PathData* pPathData = Path.New(); + CFX_PathData* pPathData = Path.Emplace(); pPathData->SetPointCount(PathPointCount); FXSYS_memcpy(pPathData->GetPoints(), m_pPathPoints, sizeof(FX_PATHPOINT) * PathPointCount); diff --git a/core/fpdfapi/fpdf_page/fpdf_page_parser_old.cpp b/core/fpdfapi/fpdf_page/fpdf_page_parser_old.cpp index 6fa1df26cd..e261ce5bb5 100644 --- a/core/fpdfapi/fpdf_page/fpdf_page_parser_old.cpp +++ b/core/fpdfapi/fpdf_page/fpdf_page_parser_old.cpp @@ -688,7 +688,7 @@ void CPDF_ContentParser::Start(CPDF_Form* pForm, CPDF_Path ClipPath; if (pBBox) { form_bbox = pBBox->GetRect(); - ClipPath.New(); + ClipPath.Emplace(); ClipPath.AppendRect(form_bbox.left, form_bbox.bottom, form_bbox.right, form_bbox.top); ClipPath.Transform(&form_matrix); diff --git a/core/fpdfapi/fpdf_page/include/cpdf_textstatedata.h b/core/fpdfapi/fpdf_page/include/cpdf_textstatedata.h index 4e33d5f170..f3d669690c 100644 --- a/core/fpdfapi/fpdf_page/include/cpdf_textstatedata.h +++ b/core/fpdfapi/fpdf_page/include/cpdf_textstatedata.h @@ -34,6 +34,12 @@ class CPDF_TextStateData { CPDF_TextStateData(const CPDF_TextStateData& src); ~CPDF_TextStateData(); + void SetFont(CPDF_Font* pFont); + 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; |