Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(420)

Side by Side Diff: core/fpdfapi/fpdf_page/cpdf_textstate.cpp

Issue 2287313004: Make CPDF_TextState have a CPDF_TextStateData rather than inheriting one. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@moar_better_constness
Patch Set: Move impl to .cpp file Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2016 PDFium Authors. All rights reserved. 1 // Copyright 2016 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 6
7 #include "core/fpdfapi/fpdf_font/include/cpdf_font.h" 7 #include "core/fpdfapi/fpdf_font/include/cpdf_font.h"
8 #include "core/fpdfapi/fpdf_page/cpdf_textstate.h" 8 #include "core/fpdfapi/fpdf_page/cpdf_textstate.h"
9 #include "core/fpdfapi/fpdf_page/pageint.h" 9 #include "core/fpdfapi/fpdf_page/pageint.h"
10 #include "core/fpdfapi/fpdf_parser/include/cpdf_document.h" 10 #include "core/fpdfapi/fpdf_parser/include/cpdf_document.h"
11 11
12 CPDF_TextState::CPDF_TextState() {}
13 CPDF_TextState::~CPDF_TextState() {}
14
15 void CPDF_TextState::New() {
dsinclair 2016/08/30 13:36:10 Can we call this Initialize()? Or, something other
Tom Sepez 2016/08/30 16:59:48 The way I'm thinking about these is that they are
16 m_Ref.New();
17 }
18
19 CPDF_Font* CPDF_TextState::GetFont() const {
20 return m_Ref.GetObject()->m_pFont;
21 }
22
12 void CPDF_TextState::SetFont(CPDF_Font* pFont) { 23 void CPDF_TextState::SetFont(CPDF_Font* pFont) {
13 CPDF_TextStateData* pStateData = GetPrivateCopy(); 24 m_Ref.GetPrivateCopy()->SetFont(pFont);
14 if (pStateData) { 25 }
15 CPDF_Document* pDoc = pStateData->m_pDocument; 26
16 CPDF_DocPageData* pPageData = pDoc ? pDoc->GetPageData() : nullptr; 27 FX_FLOAT CPDF_TextState::GetFontSize() const {
17 if (pPageData && pStateData->m_pFont && !pPageData->IsForceClear()) { 28 return m_Ref.GetObject()->m_FontSize;
18 pPageData->ReleaseFont(pStateData->m_pFont->GetFontDict()); 29 }
19 } 30
20 pStateData->m_pDocument = pFont ? pFont->m_pDocument : nullptr; 31 void CPDF_TextState::SetFontSize(FX_FLOAT size) {
21 pStateData->m_pFont = pFont; 32 m_Ref.GetPrivateCopy()->m_FontSize = size;
22 } 33 }
34
35 const FX_FLOAT* CPDF_TextState::GetMatrix() const {
36 return m_Ref.GetObject()->m_Matrix;
37 }
38
39 FX_FLOAT* CPDF_TextState::GetMutableMatrix() {
40 return m_Ref.GetPrivateCopy()->m_Matrix;
41 }
42
43 FX_FLOAT CPDF_TextState::GetCharSpace() const {
44 return m_Ref.GetObject()->m_CharSpace;
45 }
46
47 void CPDF_TextState::SetCharSpace(FX_FLOAT sp) {
48 m_Ref.GetPrivateCopy()->m_CharSpace = sp;
49 }
50
51 FX_FLOAT CPDF_TextState::GetWordSpace() const {
52 return m_Ref.GetObject()->m_WordSpace;
53 }
54
55 void CPDF_TextState::SetWordSpace(FX_FLOAT sp) {
56 m_Ref.GetPrivateCopy()->m_WordSpace = sp;
23 } 57 }
24 58
25 FX_FLOAT CPDF_TextState::GetFontSizeV() const { 59 FX_FLOAT CPDF_TextState::GetFontSizeV() const {
26 const FX_FLOAT* pMatrix = GetMatrix(); 60 return m_Ref.GetObject()->GetFontSizeV();
27 FX_FLOAT unit = FXSYS_sqrt2(pMatrix[1], pMatrix[3]);
28 FX_FLOAT size = unit * GetFontSize();
29 return (FX_FLOAT)FXSYS_fabs(size);
30 } 61 }
31 62
32 FX_FLOAT CPDF_TextState::GetFontSizeH() const { 63 FX_FLOAT CPDF_TextState::GetFontSizeH() const {
33 const FX_FLOAT* pMatrix = GetMatrix(); 64 return m_Ref.GetObject()->GetFontSizeH();
34 FX_FLOAT unit = FXSYS_sqrt2(pMatrix[0], pMatrix[2]);
35 FX_FLOAT size = unit * GetFontSize();
36 return (FX_FLOAT)FXSYS_fabs(size);
37 } 65 }
38 66
39 FX_FLOAT CPDF_TextState::GetBaselineAngle() const { 67 FX_FLOAT CPDF_TextState::GetBaselineAngle() const {
40 const FX_FLOAT* m_Matrix = GetMatrix(); 68 return m_Ref.GetObject()->GetBaselineAngle();
41 return FXSYS_atan2(m_Matrix[2], m_Matrix[0]);
42 } 69 }
43 70
44 FX_FLOAT CPDF_TextState::GetShearAngle() const { 71 FX_FLOAT CPDF_TextState::GetShearAngle() const {
45 const FX_FLOAT* m_Matrix = GetMatrix(); 72 return m_Ref.GetObject()->GetShearAngle();
46 FX_FLOAT shear_angle = FXSYS_atan2(m_Matrix[1], m_Matrix[3]);
47 return GetBaselineAngle() + shear_angle;
48 } 73 }
74
75 TextRenderingMode CPDF_TextState::GetTextMode() const {
76 return m_Ref.GetObject()->m_TextMode;
77 }
78
79 void CPDF_TextState::SetTextMode(TextRenderingMode mode) {
80 m_Ref.GetPrivateCopy()->m_TextMode = mode;
81 }
82
83 const FX_FLOAT* CPDF_TextState::GetCTM() const {
84 return m_Ref.GetObject()->m_CTM;
85 }
86
87 FX_FLOAT* CPDF_TextState::GetMutableCTM() {
88 return m_Ref.GetPrivateCopy()->m_CTM;
89 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698