OLD | NEW |
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_page/cpdf_textstate.h" |
| 8 |
7 #include "core/fpdfapi/fpdf_font/include/cpdf_font.h" | 9 #include "core/fpdfapi/fpdf_font/include/cpdf_font.h" |
8 #include "core/fpdfapi/fpdf_page/cpdf_textstate.h" | |
9 #include "core/fpdfapi/fpdf_page/pageint.h" | 10 #include "core/fpdfapi/fpdf_page/pageint.h" |
10 #include "core/fpdfapi/fpdf_parser/include/cpdf_document.h" | 11 #include "core/fpdfapi/fpdf_parser/include/cpdf_document.h" |
11 | 12 |
| 13 CPDF_TextState::CPDF_TextState() {} |
| 14 CPDF_TextState::~CPDF_TextState() {} |
| 15 |
| 16 void CPDF_TextState::Emplace() { |
| 17 m_Ref.Emplace(); |
| 18 } |
| 19 |
| 20 CPDF_Font* CPDF_TextState::GetFont() const { |
| 21 return m_Ref.GetObject()->m_pFont; |
| 22 } |
| 23 |
12 void CPDF_TextState::SetFont(CPDF_Font* pFont) { | 24 void CPDF_TextState::SetFont(CPDF_Font* pFont) { |
13 CPDF_TextStateData* pStateData = GetPrivateCopy(); | 25 m_Ref.GetPrivateCopy()->SetFont(pFont); |
14 if (pStateData) { | 26 } |
15 CPDF_Document* pDoc = pStateData->m_pDocument; | 27 |
16 CPDF_DocPageData* pPageData = pDoc ? pDoc->GetPageData() : nullptr; | 28 FX_FLOAT CPDF_TextState::GetFontSize() const { |
17 if (pPageData && pStateData->m_pFont && !pPageData->IsForceClear()) { | 29 return m_Ref.GetObject()->m_FontSize; |
18 pPageData->ReleaseFont(pStateData->m_pFont->GetFontDict()); | 30 } |
19 } | 31 |
20 pStateData->m_pDocument = pFont ? pFont->m_pDocument : nullptr; | 32 void CPDF_TextState::SetFontSize(FX_FLOAT size) { |
21 pStateData->m_pFont = pFont; | 33 m_Ref.GetPrivateCopy()->m_FontSize = size; |
22 } | 34 } |
| 35 |
| 36 const FX_FLOAT* CPDF_TextState::GetMatrix() const { |
| 37 return m_Ref.GetObject()->m_Matrix; |
| 38 } |
| 39 |
| 40 FX_FLOAT* CPDF_TextState::GetMutableMatrix() { |
| 41 return m_Ref.GetPrivateCopy()->m_Matrix; |
| 42 } |
| 43 |
| 44 FX_FLOAT CPDF_TextState::GetCharSpace() const { |
| 45 return m_Ref.GetObject()->m_CharSpace; |
| 46 } |
| 47 |
| 48 void CPDF_TextState::SetCharSpace(FX_FLOAT sp) { |
| 49 m_Ref.GetPrivateCopy()->m_CharSpace = sp; |
| 50 } |
| 51 |
| 52 FX_FLOAT CPDF_TextState::GetWordSpace() const { |
| 53 return m_Ref.GetObject()->m_WordSpace; |
| 54 } |
| 55 |
| 56 void CPDF_TextState::SetWordSpace(FX_FLOAT sp) { |
| 57 m_Ref.GetPrivateCopy()->m_WordSpace = sp; |
23 } | 58 } |
24 | 59 |
25 FX_FLOAT CPDF_TextState::GetFontSizeV() const { | 60 FX_FLOAT CPDF_TextState::GetFontSizeV() const { |
26 const FX_FLOAT* pMatrix = GetMatrix(); | 61 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 } | 62 } |
31 | 63 |
32 FX_FLOAT CPDF_TextState::GetFontSizeH() const { | 64 FX_FLOAT CPDF_TextState::GetFontSizeH() const { |
33 const FX_FLOAT* pMatrix = GetMatrix(); | 65 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 } | 66 } |
38 | 67 |
39 FX_FLOAT CPDF_TextState::GetBaselineAngle() const { | 68 FX_FLOAT CPDF_TextState::GetBaselineAngle() const { |
40 const FX_FLOAT* m_Matrix = GetMatrix(); | 69 return m_Ref.GetObject()->GetBaselineAngle(); |
41 return FXSYS_atan2(m_Matrix[2], m_Matrix[0]); | |
42 } | 70 } |
43 | 71 |
44 FX_FLOAT CPDF_TextState::GetShearAngle() const { | 72 FX_FLOAT CPDF_TextState::GetShearAngle() const { |
45 const FX_FLOAT* m_Matrix = GetMatrix(); | 73 return m_Ref.GetObject()->GetShearAngle(); |
46 FX_FLOAT shear_angle = FXSYS_atan2(m_Matrix[1], m_Matrix[3]); | |
47 return GetBaselineAngle() + shear_angle; | |
48 } | 74 } |
| 75 |
| 76 TextRenderingMode CPDF_TextState::GetTextMode() const { |
| 77 return m_Ref.GetObject()->m_TextMode; |
| 78 } |
| 79 |
| 80 void CPDF_TextState::SetTextMode(TextRenderingMode mode) { |
| 81 m_Ref.GetPrivateCopy()->m_TextMode = mode; |
| 82 } |
| 83 |
| 84 const FX_FLOAT* CPDF_TextState::GetCTM() const { |
| 85 return m_Ref.GetObject()->m_CTM; |
| 86 } |
| 87 |
| 88 FX_FLOAT* CPDF_TextState::GetMutableCTM() { |
| 89 return m_Ref.GetPrivateCopy()->m_CTM; |
| 90 } |
OLD | NEW |