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

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

Issue 2291833002: Revert "Replace wrapper methods in CPDF_Path with -> operator." (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: 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
« no previous file with comments | « core/fpdfapi/fpdf_page/cpdf_pathobject.cpp ('k') | core/fpdfapi/fpdf_page/cpdf_textstate.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_page/include/cpdf_textobject.h" 7 #include "core/fpdfapi/fpdf_page/include/cpdf_textobject.h"
8 8
9 #include "core/fpdfapi/fpdf_font/cpdf_cidfont.h" 9 #include "core/fpdfapi/fpdf_font/cpdf_cidfont.h"
10 #include "core/fpdfapi/fpdf_font/include/cpdf_font.h" 10 #include "core/fpdfapi/fpdf_font/include/cpdf_font.h"
(...skipping 17 matching lines...) Expand all
28 } 28 }
29 29
30 void CPDF_TextObject::GetItemInfo(int index, CPDF_TextObjectItem* pInfo) const { 30 void CPDF_TextObject::GetItemInfo(int index, CPDF_TextObjectItem* pInfo) const {
31 pInfo->m_CharCode = 31 pInfo->m_CharCode =
32 m_nChars == 1 ? (uint32_t)(uintptr_t)m_pCharCodes : m_pCharCodes[index]; 32 m_nChars == 1 ? (uint32_t)(uintptr_t)m_pCharCodes : m_pCharCodes[index];
33 pInfo->m_OriginX = index ? m_pCharPos[index - 1] : 0; 33 pInfo->m_OriginX = index ? m_pCharPos[index - 1] : 0;
34 pInfo->m_OriginY = 0; 34 pInfo->m_OriginY = 0;
35 if (pInfo->m_CharCode == CPDF_Font::kInvalidCharCode) { 35 if (pInfo->m_CharCode == CPDF_Font::kInvalidCharCode) {
36 return; 36 return;
37 } 37 }
38 CPDF_Font* pFont = m_TextState->GetFont(); 38 CPDF_Font* pFont = m_TextState.GetFont();
39 if (!pFont->IsCIDFont()) { 39 if (!pFont->IsCIDFont()) {
40 return; 40 return;
41 } 41 }
42 if (!pFont->AsCIDFont()->IsVertWriting()) { 42 if (!pFont->AsCIDFont()->IsVertWriting()) {
43 return; 43 return;
44 } 44 }
45 uint16_t CID = pFont->AsCIDFont()->CIDFromCharCode(pInfo->m_CharCode); 45 uint16_t CID = pFont->AsCIDFont()->CIDFromCharCode(pInfo->m_CharCode);
46 pInfo->m_OriginY = pInfo->m_OriginX; 46 pInfo->m_OriginY = pInfo->m_OriginX;
47 pInfo->m_OriginX = 0; 47 pInfo->m_OriginX = 0;
48 short vx, vy; 48 short vx, vy;
49 pFont->AsCIDFont()->GetVertOrigin(CID, vx, vy); 49 pFont->AsCIDFont()->GetVertOrigin(CID, vx, vy);
50 FX_FLOAT fontsize = m_TextState->GetFontSize(); 50 FX_FLOAT fontsize = m_TextState.GetFontSize();
51 pInfo->m_OriginX -= fontsize * vx / 1000; 51 pInfo->m_OriginX -= fontsize * vx / 1000;
52 pInfo->m_OriginY -= fontsize * vy / 1000; 52 pInfo->m_OriginY -= fontsize * vy / 1000;
53 } 53 }
54 54
55 int CPDF_TextObject::CountChars() const { 55 int CPDF_TextObject::CountChars() const {
56 if (m_nChars == 1) { 56 if (m_nChars == 1) {
57 return 1; 57 return 1;
58 } 58 }
59 int count = 0; 59 int count = 0;
60 for (int i = 0; i < m_nChars; ++i) 60 for (int i = 0; i < m_nChars; ++i)
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 130
131 CPDF_PageObject::Type CPDF_TextObject::GetType() const { 131 CPDF_PageObject::Type CPDF_TextObject::GetType() const {
132 return TEXT; 132 return TEXT;
133 } 133 }
134 134
135 void CPDF_TextObject::Transform(const CFX_Matrix& matrix) { 135 void CPDF_TextObject::Transform(const CFX_Matrix& matrix) {
136 m_TextState.MakePrivateCopy(); 136 m_TextState.MakePrivateCopy();
137 CFX_Matrix text_matrix; 137 CFX_Matrix text_matrix;
138 GetTextMatrix(&text_matrix); 138 GetTextMatrix(&text_matrix);
139 text_matrix.Concat(matrix); 139 text_matrix.Concat(matrix);
140 FX_FLOAT* pTextMatrix = m_TextState->GetMatrix(); 140 FX_FLOAT* pTextMatrix = m_TextState.GetMatrix();
141 pTextMatrix[0] = text_matrix.GetA(); 141 pTextMatrix[0] = text_matrix.GetA();
142 pTextMatrix[1] = text_matrix.GetC(); 142 pTextMatrix[1] = text_matrix.GetC();
143 pTextMatrix[2] = text_matrix.GetB(); 143 pTextMatrix[2] = text_matrix.GetB();
144 pTextMatrix[3] = text_matrix.GetD(); 144 pTextMatrix[3] = text_matrix.GetD();
145 m_PosX = text_matrix.GetE(); 145 m_PosX = text_matrix.GetE();
146 m_PosY = text_matrix.GetF(); 146 m_PosY = text_matrix.GetF();
147 CalcPositionData(nullptr, nullptr, 0); 147 CalcPositionData(nullptr, nullptr, 0);
148 } 148 }
149 149
150 bool CPDF_TextObject::IsText() const { 150 bool CPDF_TextObject::IsText() const {
151 return true; 151 return true;
152 } 152 }
153 153
154 CPDF_TextObject* CPDF_TextObject::AsText() { 154 CPDF_TextObject* CPDF_TextObject::AsText() {
155 return this; 155 return this;
156 } 156 }
157 157
158 const CPDF_TextObject* CPDF_TextObject::AsText() const { 158 const CPDF_TextObject* CPDF_TextObject::AsText() const {
159 return this; 159 return this;
160 } 160 }
161 161
162 void CPDF_TextObject::GetTextMatrix(CFX_Matrix* pMatrix) const { 162 void CPDF_TextObject::GetTextMatrix(CFX_Matrix* pMatrix) const {
163 const FX_FLOAT* pTextMatrix = m_TextState->GetMatrix(); 163 const FX_FLOAT* pTextMatrix = m_TextState.GetMatrix();
164 pMatrix->Set(pTextMatrix[0], pTextMatrix[2], pTextMatrix[1], pTextMatrix[3], 164 pMatrix->Set(pTextMatrix[0], pTextMatrix[2], pTextMatrix[1], pTextMatrix[3],
165 m_PosX, m_PosY); 165 m_PosX, m_PosY);
166 } 166 }
167 167
168 void CPDF_TextObject::SetSegments(const CFX_ByteString* pStrs, 168 void CPDF_TextObject::SetSegments(const CFX_ByteString* pStrs,
169 FX_FLOAT* pKerning, 169 FX_FLOAT* pKerning,
170 int nsegs) { 170 int nsegs) {
171 if (m_nChars > 1) { 171 if (m_nChars > 1) {
172 FX_Free(m_pCharCodes); 172 FX_Free(m_pCharCodes);
173 m_pCharCodes = nullptr; 173 m_pCharCodes = nullptr;
174 } 174 }
175 FX_Free(m_pCharPos); 175 FX_Free(m_pCharPos);
176 m_pCharPos = nullptr; 176 m_pCharPos = nullptr;
177 CPDF_Font* pFont = m_TextState->GetFont(); 177 CPDF_Font* pFont = m_TextState.GetFont();
178 m_nChars = 0; 178 m_nChars = 0;
179 for (int i = 0; i < nsegs; ++i) { 179 for (int i = 0; i < nsegs; ++i) {
180 m_nChars += pFont->CountChar(pStrs[i].c_str(), pStrs[i].GetLength()); 180 m_nChars += pFont->CountChar(pStrs[i].c_str(), pStrs[i].GetLength());
181 } 181 }
182 m_nChars += nsegs - 1; 182 m_nChars += nsegs - 1;
183 if (m_nChars > 1) { 183 if (m_nChars > 1) {
184 m_pCharCodes = FX_Alloc(uint32_t, m_nChars); 184 m_pCharCodes = FX_Alloc(uint32_t, m_nChars);
185 m_pCharPos = FX_Alloc(FX_FLOAT, m_nChars - 1); 185 m_pCharPos = FX_Alloc(FX_FLOAT, m_nChars - 1);
186 int index = 0; 186 int index = 0;
187 for (int i = 0; i < nsegs; ++i) { 187 for (int i = 0; i < nsegs; ++i) {
(...skipping 14 matching lines...) Expand all
202 pStrs[0].c_str(), pStrs[0].GetLength(), offset); 202 pStrs[0].c_str(), pStrs[0].GetLength(), offset);
203 } 203 }
204 } 204 }
205 205
206 void CPDF_TextObject::SetText(const CFX_ByteString& str) { 206 void CPDF_TextObject::SetText(const CFX_ByteString& str) {
207 SetSegments(&str, nullptr, 1); 207 SetSegments(&str, nullptr, 1);
208 RecalcPositionData(); 208 RecalcPositionData();
209 } 209 }
210 210
211 FX_FLOAT CPDF_TextObject::GetCharWidth(uint32_t charcode) const { 211 FX_FLOAT CPDF_TextObject::GetCharWidth(uint32_t charcode) const {
212 FX_FLOAT fontsize = m_TextState->GetFontSize() / 1000; 212 FX_FLOAT fontsize = m_TextState.GetFontSize() / 1000;
213 CPDF_Font* pFont = m_TextState->GetFont(); 213 CPDF_Font* pFont = m_TextState.GetFont();
214 FX_BOOL bVertWriting = FALSE; 214 FX_BOOL bVertWriting = FALSE;
215 CPDF_CIDFont* pCIDFont = pFont->AsCIDFont(); 215 CPDF_CIDFont* pCIDFont = pFont->AsCIDFont();
216 if (pCIDFont) { 216 if (pCIDFont) {
217 bVertWriting = pCIDFont->IsVertWriting(); 217 bVertWriting = pCIDFont->IsVertWriting();
218 } 218 }
219 if (!bVertWriting) 219 if (!bVertWriting)
220 return pFont->GetCharWidthF(charcode, 0) * fontsize; 220 return pFont->GetCharWidthF(charcode, 0) * fontsize;
221 221
222 uint16_t CID = pCIDFont->CIDFromCharCode(charcode); 222 uint16_t CID = pCIDFont->CIDFromCharCode(charcode);
223 return pCIDFont->GetVertWidth(CID) * fontsize; 223 return pCIDFont->GetVertWidth(CID) * fontsize;
224 } 224 }
225 225
226 FX_FLOAT CPDF_TextObject::GetPosX() const { 226 FX_FLOAT CPDF_TextObject::GetPosX() const {
227 return m_PosX; 227 return m_PosX;
228 } 228 }
229 229
230 FX_FLOAT CPDF_TextObject::GetPosY() const { 230 FX_FLOAT CPDF_TextObject::GetPosY() const {
231 return m_PosY; 231 return m_PosY;
232 } 232 }
233 233
234 CPDF_Font* CPDF_TextObject::GetFont() const { 234 CPDF_Font* CPDF_TextObject::GetFont() const {
235 return m_TextState->GetFont(); 235 return m_TextState.GetFont();
236 } 236 }
237 237
238 FX_FLOAT CPDF_TextObject::GetFontSize() const { 238 FX_FLOAT CPDF_TextObject::GetFontSize() const {
239 return m_TextState->GetFontSize(); 239 return m_TextState.GetFontSize();
240 } 240 }
241 241
242 void CPDF_TextObject::CalcPositionData(FX_FLOAT* pTextAdvanceX, 242 void CPDF_TextObject::CalcPositionData(FX_FLOAT* pTextAdvanceX,
243 FX_FLOAT* pTextAdvanceY, 243 FX_FLOAT* pTextAdvanceY,
244 FX_FLOAT horz_scale, 244 FX_FLOAT horz_scale,
245 int level) { 245 int level) {
246 FX_FLOAT curpos = 0; 246 FX_FLOAT curpos = 0;
247 FX_FLOAT min_x = 10000 * 1.0f; 247 FX_FLOAT min_x = 10000 * 1.0f;
248 FX_FLOAT max_x = -10000 * 1.0f; 248 FX_FLOAT max_x = -10000 * 1.0f;
249 FX_FLOAT min_y = 10000 * 1.0f; 249 FX_FLOAT min_y = 10000 * 1.0f;
250 FX_FLOAT max_y = -10000 * 1.0f; 250 FX_FLOAT max_y = -10000 * 1.0f;
251 CPDF_Font* pFont = m_TextState->GetFont(); 251 CPDF_Font* pFont = m_TextState.GetFont();
252 FX_BOOL bVertWriting = FALSE; 252 FX_BOOL bVertWriting = FALSE;
253 CPDF_CIDFont* pCIDFont = pFont->AsCIDFont(); 253 CPDF_CIDFont* pCIDFont = pFont->AsCIDFont();
254 if (pCIDFont) { 254 if (pCIDFont) {
255 bVertWriting = pCIDFont->IsVertWriting(); 255 bVertWriting = pCIDFont->IsVertWriting();
256 } 256 }
257 FX_FLOAT fontsize = m_TextState->GetFontSize(); 257 FX_FLOAT fontsize = m_TextState.GetFontSize();
258 for (int i = 0; i < m_nChars; ++i) { 258 for (int i = 0; i < m_nChars; ++i) {
259 uint32_t charcode = 259 uint32_t charcode =
260 m_nChars == 1 ? (uint32_t)(uintptr_t)m_pCharCodes : m_pCharCodes[i]; 260 m_nChars == 1 ? (uint32_t)(uintptr_t)m_pCharCodes : m_pCharCodes[i];
261 if (i > 0) { 261 if (i > 0) {
262 if (charcode == CPDF_Font::kInvalidCharCode) { 262 if (charcode == CPDF_Font::kInvalidCharCode) {
263 curpos -= (m_pCharPos[i - 1] * fontsize) / 1000; 263 curpos -= (m_pCharPos[i - 1] * fontsize) / 1000;
264 continue; 264 continue;
265 } 265 }
266 m_pCharPos[i - 1] = curpos; 266 m_pCharPos[i - 1] = curpos;
267 } 267 }
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
380 m_PosY = y; 380 m_PosY = y;
381 m_Left += dx; 381 m_Left += dx;
382 m_Right += dx; 382 m_Right += dx;
383 m_Top += dy; 383 m_Top += dy;
384 m_Bottom += dy; 384 m_Bottom += dy;
385 } 385 }
386 386
387 void CPDF_TextObject::RecalcPositionData() { 387 void CPDF_TextObject::RecalcPositionData() {
388 CalcPositionData(nullptr, nullptr, 1); 388 CalcPositionData(nullptr, nullptr, 1);
389 } 389 }
OLDNEW
« no previous file with comments | « core/fpdfapi/fpdf_page/cpdf_pathobject.cpp ('k') | core/fpdfapi/fpdf_page/cpdf_textstate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698