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

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

Issue 2386423004: Move core/fpdfapi/fpdf_page to core/fpdfapi/page (Closed)
Patch Set: Rebase to master Created 4 years, 2 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
« no previous file with comments | « core/fpdfapi/fpdf_page/cpdf_textstate.h ('k') | core/fpdfapi/fpdf_page/cpdf_tilingpattern.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2016 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6
7 #include "core/fpdfapi/fpdf_page/cpdf_textstate.h"
8
9 #include "core/fpdfapi/font/cpdf_font.h"
10 #include "core/fpdfapi/fpdf_page/pageint.h"
11 #include "core/fpdfapi/fpdf_parser/cpdf_document.h"
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
24 void CPDF_TextState::SetFont(CPDF_Font* pFont) {
25 m_Ref.GetPrivateCopy()->SetFont(pFont);
26 }
27
28 FX_FLOAT CPDF_TextState::GetFontSize() const {
29 return m_Ref.GetObject()->m_FontSize;
30 }
31
32 void CPDF_TextState::SetFontSize(FX_FLOAT size) {
33 m_Ref.GetPrivateCopy()->m_FontSize = size;
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;
58 }
59
60 FX_FLOAT CPDF_TextState::GetFontSizeV() const {
61 return m_Ref.GetObject()->GetFontSizeV();
62 }
63
64 FX_FLOAT CPDF_TextState::GetFontSizeH() const {
65 return m_Ref.GetObject()->GetFontSizeH();
66 }
67
68 FX_FLOAT CPDF_TextState::GetBaselineAngle() const {
69 return m_Ref.GetObject()->GetBaselineAngle();
70 }
71
72 FX_FLOAT CPDF_TextState::GetShearAngle() const {
73 return m_Ref.GetObject()->GetShearAngle();
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 }
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 }
OLDNEW
« no previous file with comments | « core/fpdfapi/fpdf_page/cpdf_textstate.h ('k') | core/fpdfapi/fpdf_page/cpdf_tilingpattern.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698