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" | 7 #include "core/fpdfapi/fpdf_page/include/cpdf_textstate.h" |
8 | 8 |
9 #include "core/fpdfapi/fpdf_font/include/cpdf_font.h" | 9 #include "core/fpdfapi/fpdf_font/include/cpdf_font.h" |
10 #include "core/fpdfapi/fpdf_page/pageint.h" | 10 #include "core/fpdfapi/fpdf_page/pageint.h" |
11 #include "core/fpdfapi/fpdf_parser/include/cpdf_document.h" | 11 #include "core/fpdfapi/fpdf_parser/include/cpdf_document.h" |
12 | 12 |
13 CPDF_TextState::CPDF_TextState() {} | 13 CPDF_TextState::CPDF_TextState() {} |
14 CPDF_TextState::~CPDF_TextState() {} | 14 CPDF_TextState::~CPDF_TextState() {} |
15 | 15 |
16 void CPDF_TextState::Emplace() { | 16 void CPDF_TextState::Emplace() { |
17 m_Ref.Emplace(); | 17 m_Ref.Emplace(); |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 m_Ref.GetPrivateCopy()->m_TextMode = mode; | 81 m_Ref.GetPrivateCopy()->m_TextMode = mode; |
82 } | 82 } |
83 | 83 |
84 const FX_FLOAT* CPDF_TextState::GetCTM() const { | 84 const FX_FLOAT* CPDF_TextState::GetCTM() const { |
85 return m_Ref.GetObject()->m_CTM; | 85 return m_Ref.GetObject()->m_CTM; |
86 } | 86 } |
87 | 87 |
88 FX_FLOAT* CPDF_TextState::GetMutableCTM() { | 88 FX_FLOAT* CPDF_TextState::GetMutableCTM() { |
89 return m_Ref.GetPrivateCopy()->m_CTM; | 89 return m_Ref.GetPrivateCopy()->m_CTM; |
90 } | 90 } |
| 91 |
| 92 CPDF_TextState::TextData::TextData() |
| 93 : m_pFont(nullptr), |
| 94 m_pDocument(nullptr), |
| 95 m_FontSize(1.0f), |
| 96 m_CharSpace(0), |
| 97 m_WordSpace(0), |
| 98 m_TextMode(TextRenderingMode::MODE_FILL) { |
| 99 m_Matrix[0] = m_Matrix[3] = 1.0f; |
| 100 m_Matrix[1] = m_Matrix[2] = 0; |
| 101 m_CTM[0] = m_CTM[3] = 1.0f; |
| 102 m_CTM[1] = m_CTM[2] = 0; |
| 103 } |
| 104 |
| 105 CPDF_TextState::TextData::TextData(const TextData& that) |
| 106 : m_pFont(that.m_pFont), |
| 107 m_pDocument(that.m_pDocument), |
| 108 m_FontSize(that.m_FontSize), |
| 109 m_CharSpace(that.m_CharSpace), |
| 110 m_WordSpace(that.m_WordSpace), |
| 111 m_TextMode(that.m_TextMode) { |
| 112 for (int i = 0; i < 4; ++i) |
| 113 m_Matrix[i] = that.m_Matrix[i]; |
| 114 |
| 115 for (int i = 0; i < 4; ++i) |
| 116 m_CTM[i] = that.m_CTM[i]; |
| 117 |
| 118 if (m_pDocument && m_pFont) { |
| 119 m_pFont = |
| 120 m_pDocument->GetPageData()->GetFont(m_pFont->GetFontDict(), FALSE); |
| 121 } |
| 122 } |
| 123 |
| 124 CPDF_TextState::TextData::~TextData() { |
| 125 if (m_pDocument && m_pFont) { |
| 126 CPDF_DocPageData* pPageData = m_pDocument->GetPageData(); |
| 127 if (pPageData && !pPageData->IsForceClear()) |
| 128 pPageData->ReleaseFont(m_pFont->GetFontDict()); |
| 129 } |
| 130 } |
| 131 |
| 132 void CPDF_TextState::TextData::SetFont(CPDF_Font* pFont) { |
| 133 CPDF_Document* pDoc = m_pDocument; |
| 134 CPDF_DocPageData* pPageData = pDoc ? pDoc->GetPageData() : nullptr; |
| 135 if (pPageData && m_pFont && !pPageData->IsForceClear()) |
| 136 pPageData->ReleaseFont(m_pFont->GetFontDict()); |
| 137 |
| 138 m_pDocument = pFont ? pFont->m_pDocument : nullptr; |
| 139 m_pFont = pFont; |
| 140 } |
| 141 |
| 142 FX_FLOAT CPDF_TextState::TextData::GetFontSizeV() const { |
| 143 return FXSYS_fabs(FXSYS_sqrt2(m_Matrix[1], m_Matrix[3]) * m_FontSize); |
| 144 } |
| 145 |
| 146 FX_FLOAT CPDF_TextState::TextData::GetFontSizeH() const { |
| 147 return FXSYS_fabs(FXSYS_sqrt2(m_Matrix[0], m_Matrix[2]) * m_FontSize); |
| 148 } |
| 149 |
| 150 FX_FLOAT CPDF_TextState::TextData::GetBaselineAngle() const { |
| 151 return FXSYS_atan2(m_Matrix[2], m_Matrix[0]); |
| 152 } |
| 153 |
| 154 FX_FLOAT CPDF_TextState::TextData::GetShearAngle() const { |
| 155 return GetBaselineAngle() + FXSYS_atan2(m_Matrix[1], m_Matrix[3]); |
| 156 } |
| 157 |
| 158 bool SetTextRenderingModeFromInt(int iMode, TextRenderingMode* mode) { |
| 159 if (iMode < 0 || iMode > 7) |
| 160 return false; |
| 161 *mode = static_cast<TextRenderingMode>(iMode); |
| 162 return true; |
| 163 } |
| 164 |
| 165 bool TextRenderingModeIsClipMode(const TextRenderingMode& mode) { |
| 166 switch (mode) { |
| 167 case TextRenderingMode::MODE_FILL_CLIP: |
| 168 case TextRenderingMode::MODE_STROKE_CLIP: |
| 169 case TextRenderingMode::MODE_FILL_STROKE_CLIP: |
| 170 case TextRenderingMode::MODE_CLIP: |
| 171 return true; |
| 172 default: |
| 173 return false; |
| 174 } |
| 175 } |
| 176 |
| 177 bool TextRenderingModeIsStrokeMode(const TextRenderingMode& mode) { |
| 178 switch (mode) { |
| 179 case TextRenderingMode::MODE_STROKE: |
| 180 case TextRenderingMode::MODE_FILL_STROKE: |
| 181 case TextRenderingMode::MODE_STROKE_CLIP: |
| 182 case TextRenderingMode::MODE_FILL_STROKE_CLIP: |
| 183 return true; |
| 184 default: |
| 185 return false; |
| 186 } |
| 187 } |
OLD | NEW |