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 | |
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')
-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 | ||||
-rw-r--r-- | core/fpdfapi/fpdf_render/fpdf_render_text.cpp | 11 | ||||
-rw-r--r-- | core/fpdftext/cpdf_textpage.cpp | 8 | ||||
-rw-r--r-- | core/fxcrt/cfx_count_ref_unittest.cpp | 10 | ||||
-rw-r--r-- | core/fxcrt/include/cfx_count_ref.h | 4 | ||||
-rw-r--r-- | core/fxge/agg/fx_agg_driver.cpp | 5 | ||||
-rw-r--r-- | core/fxge/ge/cfx_cliprgn.cpp | 8 |
15 files changed, 170 insertions, 82 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; diff --git a/core/fpdfapi/fpdf_render/fpdf_render_text.cpp b/core/fpdfapi/fpdf_render/fpdf_render_text.cpp index 16d1235f4d..e5e28b429c 100644 --- a/core/fpdfapi/fpdf_render/fpdf_render_text.cpp +++ b/core/fpdfapi/fpdf_render/fpdf_render_text.cpp @@ -231,8 +231,7 @@ FX_BOOL CPDF_RenderStatus::ProcessText(const CPDF_TextObject* textobj, if (textobj->m_nChars == 0) return TRUE; - const TextRenderingMode& text_render_mode = - textobj->m_TextState.GetObject()->m_TextMode; + const TextRenderingMode text_render_mode = textobj->m_TextState.GetTextMode(); if (text_render_mode == TextRenderingMode::MODE_INVISIBLE) return TRUE; @@ -308,7 +307,7 @@ FX_BOOL CPDF_RenderStatus::ProcessText(const CPDF_TextObject* textobj, const CFX_Matrix* pDeviceMatrix = pObj2Device; CFX_Matrix device_matrix; if (bStroke) { - const FX_FLOAT* pCTM = textobj->m_TextState.GetObject()->m_CTM; + const FX_FLOAT* pCTM = textobj->m_TextState.GetCTM(); if (pCTM[0] != 1.0f || pCTM[3] != 1.0f) { CFX_Matrix ctm(pCTM[0], pCTM[1], pCTM[2], pCTM[3], 0, 0); text_matrix.ConcatInverse(ctm); @@ -817,8 +816,8 @@ void CPDF_RenderStatus::DrawTextPathWithPattern(const CPDF_TextObject* textobj, path.m_FillType = FXFILL_WINDING; path.m_ClipPath.AppendTexts(&pCopy); path.m_ColorState = textobj->m_ColorState; - path.m_Path.New()->AppendRect(textobj->m_Left, textobj->m_Bottom, - textobj->m_Right, textobj->m_Top); + path.m_Path.Emplace()->AppendRect(textobj->m_Left, textobj->m_Bottom, + textobj->m_Right, textobj->m_Top); path.m_Left = textobj->m_Left; path.m_Bottom = textobj->m_Bottom; path.m_Right = textobj->m_Right; @@ -864,7 +863,7 @@ void CPDF_RenderStatus::DrawTextPathWithPattern(const CPDF_TextObject* textobj, charpos.m_AdjustMatrix[2], charpos.m_AdjustMatrix[3], 0, 0); matrix.Concat(font_size, 0, 0, font_size, charpos.m_OriginX, charpos.m_OriginY); - path.m_Path.New()->Append(pPath, &matrix); + path.m_Path.Emplace()->Append(pPath, &matrix); path.m_Matrix = *pTextMatrix; path.m_bStroke = bStroke; path.m_FillType = bFill ? FXFILL_WINDING : 0; diff --git a/core/fpdftext/cpdf_textpage.cpp b/core/fpdftext/cpdf_textpage.cpp index 3981cfee40..909e029262 100644 --- a/core/fpdftext/cpdf_textpage.cpp +++ b/core/fpdftext/cpdf_textpage.cpp @@ -45,10 +45,10 @@ FX_FLOAT CalculateBaseSpace(const CPDF_TextObject* pTextObj, const CFX_Matrix& matrix) { FX_FLOAT baseSpace = 0.0; const int nItems = pTextObj->CountItems(); - if (pTextObj->m_TextState.GetObject()->m_CharSpace && nItems >= 3) { + if (pTextObj->m_TextState.GetCharSpace() && nItems >= 3) { bool bAllChar = true; - FX_FLOAT spacing = matrix.TransformDistance( - pTextObj->m_TextState.GetObject()->m_CharSpace); + FX_FLOAT spacing = + matrix.TransformDistance(pTextObj->m_TextState.GetCharSpace()); baseSpace = spacing; for (int i = 0; i < nItems; i++) { CPDF_TextObjectItem item; @@ -1088,7 +1088,7 @@ void CPDF_TextPage::ProcessTextObject(PDFTEXT_Obj Obj) { spacing = -fontsize_h * item.m_OriginX / 1000; continue; } - FX_FLOAT charSpace = pTextObj->m_TextState.GetObject()->m_CharSpace; + FX_FLOAT charSpace = pTextObj->m_TextState.GetCharSpace(); if (charSpace > 0.001) spacing += matrix.TransformDistance(charSpace); else if (charSpace < -0.001) diff --git a/core/fxcrt/cfx_count_ref_unittest.cpp b/core/fxcrt/cfx_count_ref_unittest.cpp index 7651c93f25..6cb9f4a2fe 100644 --- a/core/fxcrt/cfx_count_ref_unittest.cpp +++ b/core/fxcrt/cfx_count_ref_unittest.cpp @@ -58,7 +58,7 @@ TEST(fxcrt, CountRefCopy) { Observer observer; { CFX_CountRef<Object> ptr1; - ptr1.New(&observer, std::string("one")); + ptr1.Emplace(&observer, std::string("one")); { CFX_CountRef<Object> ptr2 = ptr1; EXPECT_EQ(1, observer.GetConstructionCount("one")); @@ -79,8 +79,8 @@ TEST(fxcrt, CountRefAssignOverOld) { Observer observer; { CFX_CountRef<Object> ptr1; - ptr1.New(&observer, std::string("one")); - ptr1.New(&observer, std::string("two")); + ptr1.Emplace(&observer, std::string("one")); + ptr1.Emplace(&observer, std::string("two")); EXPECT_EQ(1, observer.GetConstructionCount("one")); EXPECT_EQ(1, observer.GetConstructionCount("two")); EXPECT_EQ(1, observer.GetDestructionCount("one")); @@ -93,9 +93,9 @@ TEST(fxcrt, CountRefAssignOverRetained) { Observer observer; { CFX_CountRef<Object> ptr1; - ptr1.New(&observer, std::string("one")); + ptr1.Emplace(&observer, std::string("one")); CFX_CountRef<Object> ptr2(ptr1); - ptr1.New(&observer, std::string("two")); + ptr1.Emplace(&observer, std::string("two")); EXPECT_EQ(1, observer.GetConstructionCount("one")); EXPECT_EQ(1, observer.GetConstructionCount("two")); EXPECT_EQ(0, observer.GetDestructionCount("one")); diff --git a/core/fxcrt/include/cfx_count_ref.h b/core/fxcrt/include/cfx_count_ref.h index 954b72bf88..aac18b166a 100644 --- a/core/fxcrt/include/cfx_count_ref.h +++ b/core/fxcrt/include/cfx_count_ref.h @@ -18,7 +18,7 @@ class CFX_CountRef { ~CFX_CountRef() {} template <typename... Args> - ObjClass* New(Args... params) { + ObjClass* Emplace(Args... params) { m_pObject.Reset(new CountedObj(params...)); return m_pObject.Get(); } @@ -35,7 +35,7 @@ class CFX_CountRef { template <typename... Args> ObjClass* GetPrivateCopy(Args... params) { if (!m_pObject) - return New(params...); + return Emplace(params...); if (!m_pObject->HasOneRef()) m_pObject.Reset(new CountedObj(*m_pObject)); return m_pObject.Get(); diff --git a/core/fxge/agg/fx_agg_driver.cpp b/core/fxge/agg/fx_agg_driver.cpp index cf0fd90917..9db10ac3c6 100644 --- a/core/fxge/agg/fx_agg_driver.cpp +++ b/core/fxge/agg/fx_agg_driver.cpp @@ -528,10 +528,7 @@ void CFX_AggDeviceDriver::SetClipMask(agg::rasterizer_scanline_aa& rasterizer) { rasterizer.max_x() + 1, rasterizer.max_y() + 1); path_rect.Intersect(m_pClipRgn->GetBox()); CFX_DIBitmapRef mask; - CFX_DIBitmap* pThisLayer = mask.New(); - if (!pThisLayer) { - return; - } + CFX_DIBitmap* pThisLayer = mask.Emplace(); pThisLayer->Create(path_rect.Width(), path_rect.Height(), FXDIB_8bppMask); pThisLayer->Clear(0); agg::rendering_buffer raw_buf(pThisLayer->GetBuffer(), pThisLayer->GetWidth(), diff --git a/core/fxge/ge/cfx_cliprgn.cpp b/core/fxge/ge/cfx_cliprgn.cpp index 41975e4b84..ba2605aeca 100644 --- a/core/fxge/ge/cfx_cliprgn.cpp +++ b/core/fxge/ge/cfx_cliprgn.cpp @@ -49,9 +49,7 @@ void CFX_ClipRgn::IntersectMaskRect(FX_RECT rect, m_Mask = Mask; return; } - CFX_DIBitmap* new_dib = m_Mask.New(); - if (!new_dib) - return; + CFX_DIBitmap* new_dib = m_Mask.Emplace(); new_dib->Create(m_Box.Width(), m_Box.Height(), FXDIB_8bppMask); for (int row = m_Box.top; row < m_Box.bottom; row++) { uint8_t* dest_scan = @@ -82,9 +80,7 @@ void CFX_ClipRgn::IntersectMaskF(int left, int top, CFX_DIBitmapRef Mask) { return; } CFX_DIBitmapRef new_mask; - CFX_DIBitmap* new_dib = new_mask.New(); - if (!new_dib) - return; + CFX_DIBitmap* new_dib = new_mask.Emplace(); new_dib->Create(new_box.Width(), new_box.Height(), FXDIB_8bppMask); const CFX_DIBitmap* old_dib = m_Mask.GetObject(); for (int row = new_box.top; row < new_box.bottom; row++) { |