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

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

Issue 1832173003: Remove FX_DWORD from core/ and delete definition (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Created 4 years, 9 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_meshstream.cpp ('k') | core/fpdfapi/fpdf_page/fpdf_page_colors.cpp » ('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"
11 11
12 CPDF_TextObject::CPDF_TextObject() 12 CPDF_TextObject::CPDF_TextObject()
13 : m_PosX(0), 13 : m_PosX(0),
14 m_PosY(0), 14 m_PosY(0),
15 m_nChars(0), 15 m_nChars(0),
16 m_pCharCodes(nullptr), 16 m_pCharCodes(nullptr),
17 m_pCharPos(nullptr) {} 17 m_pCharPos(nullptr) {}
18 18
19 CPDF_TextObject::~CPDF_TextObject() { 19 CPDF_TextObject::~CPDF_TextObject() {
20 if (m_nChars > 1) { 20 if (m_nChars > 1) {
21 FX_Free(m_pCharCodes); 21 FX_Free(m_pCharCodes);
22 } 22 }
23 FX_Free(m_pCharPos); 23 FX_Free(m_pCharPos);
24 } 24 }
25 25
26 void CPDF_TextObject::GetItemInfo(int index, CPDF_TextObjectItem* pInfo) const { 26 void CPDF_TextObject::GetItemInfo(int index, CPDF_TextObjectItem* pInfo) const {
27 pInfo->m_CharCode = 27 pInfo->m_CharCode =
28 m_nChars == 1 ? (FX_DWORD)(uintptr_t)m_pCharCodes : m_pCharCodes[index]; 28 m_nChars == 1 ? (uint32_t)(uintptr_t)m_pCharCodes : m_pCharCodes[index];
29 pInfo->m_OriginX = index ? m_pCharPos[index - 1] : 0; 29 pInfo->m_OriginX = index ? m_pCharPos[index - 1] : 0;
30 pInfo->m_OriginY = 0; 30 pInfo->m_OriginY = 0;
31 if (pInfo->m_CharCode == -1) { 31 if (pInfo->m_CharCode == -1) {
32 return; 32 return;
33 } 33 }
34 CPDF_Font* pFont = m_TextState.GetFont(); 34 CPDF_Font* pFont = m_TextState.GetFont();
35 if (!pFont->IsCIDFont()) { 35 if (!pFont->IsCIDFont()) {
36 return; 36 return;
37 } 37 }
38 if (!pFont->AsCIDFont()->IsVertWriting()) { 38 if (!pFont->AsCIDFont()->IsVertWriting()) {
39 return; 39 return;
40 } 40 }
41 uint16_t CID = pFont->AsCIDFont()->CIDFromCharCode(pInfo->m_CharCode); 41 uint16_t CID = pFont->AsCIDFont()->CIDFromCharCode(pInfo->m_CharCode);
42 pInfo->m_OriginY = pInfo->m_OriginX; 42 pInfo->m_OriginY = pInfo->m_OriginX;
43 pInfo->m_OriginX = 0; 43 pInfo->m_OriginX = 0;
44 short vx, vy; 44 short vx, vy;
45 pFont->AsCIDFont()->GetVertOrigin(CID, vx, vy); 45 pFont->AsCIDFont()->GetVertOrigin(CID, vx, vy);
46 FX_FLOAT fontsize = m_TextState.GetFontSize(); 46 FX_FLOAT fontsize = m_TextState.GetFontSize();
47 pInfo->m_OriginX -= fontsize * vx / 1000; 47 pInfo->m_OriginX -= fontsize * vx / 1000;
48 pInfo->m_OriginY -= fontsize * vy / 1000; 48 pInfo->m_OriginY -= fontsize * vy / 1000;
49 } 49 }
50 50
51 int CPDF_TextObject::CountChars() const { 51 int CPDF_TextObject::CountChars() const {
52 if (m_nChars == 1) { 52 if (m_nChars == 1) {
53 return 1; 53 return 1;
54 } 54 }
55 int count = 0; 55 int count = 0;
56 for (int i = 0; i < m_nChars; ++i) 56 for (int i = 0; i < m_nChars; ++i)
57 if (m_pCharCodes[i] != (FX_DWORD)-1) { 57 if (m_pCharCodes[i] != (uint32_t)-1) {
58 ++count; 58 ++count;
59 } 59 }
60 return count; 60 return count;
61 } 61 }
62 62
63 void CPDF_TextObject::GetCharInfo(int index, 63 void CPDF_TextObject::GetCharInfo(int index,
64 FX_DWORD& charcode, 64 uint32_t& charcode,
65 FX_FLOAT& kerning) const { 65 FX_FLOAT& kerning) const {
66 if (m_nChars == 1) { 66 if (m_nChars == 1) {
67 charcode = (FX_DWORD)(uintptr_t)m_pCharCodes; 67 charcode = (uint32_t)(uintptr_t)m_pCharCodes;
68 kerning = 0; 68 kerning = 0;
69 return; 69 return;
70 } 70 }
71 int count = 0; 71 int count = 0;
72 for (int i = 0; i < m_nChars; ++i) { 72 for (int i = 0; i < m_nChars; ++i) {
73 if (m_pCharCodes[i] != (FX_DWORD)-1) { 73 if (m_pCharCodes[i] != (uint32_t)-1) {
74 if (count == index) { 74 if (count == index) {
75 charcode = m_pCharCodes[i]; 75 charcode = m_pCharCodes[i];
76 if (i == m_nChars - 1 || m_pCharCodes[i + 1] != (FX_DWORD)-1) { 76 if (i == m_nChars - 1 || m_pCharCodes[i + 1] != (uint32_t)-1) {
77 kerning = 0; 77 kerning = 0;
78 } else { 78 } else {
79 kerning = m_pCharPos[i]; 79 kerning = m_pCharPos[i];
80 } 80 }
81 return; 81 return;
82 } 82 }
83 ++count; 83 ++count;
84 } 84 }
85 } 85 }
86 } 86 }
87 87
88 void CPDF_TextObject::GetCharInfo(int index, CPDF_TextObjectItem* pInfo) const { 88 void CPDF_TextObject::GetCharInfo(int index, CPDF_TextObjectItem* pInfo) const {
89 if (m_nChars == 1) { 89 if (m_nChars == 1) {
90 GetItemInfo(0, pInfo); 90 GetItemInfo(0, pInfo);
91 return; 91 return;
92 } 92 }
93 int count = 0; 93 int count = 0;
94 for (int i = 0; i < m_nChars; ++i) { 94 for (int i = 0; i < m_nChars; ++i) {
95 FX_DWORD charcode = m_pCharCodes[i]; 95 uint32_t charcode = m_pCharCodes[i];
96 if (charcode == (FX_DWORD)-1) { 96 if (charcode == (uint32_t)-1) {
97 continue; 97 continue;
98 } 98 }
99 if (count == index) { 99 if (count == index) {
100 GetItemInfo(i, pInfo); 100 GetItemInfo(i, pInfo);
101 break; 101 break;
102 } 102 }
103 ++count; 103 ++count;
104 } 104 }
105 } 105 }
106 106
107 CPDF_TextObject* CPDF_TextObject::Clone() const { 107 CPDF_TextObject* CPDF_TextObject::Clone() const {
108 CPDF_TextObject* obj = new CPDF_TextObject; 108 CPDF_TextObject* obj = new CPDF_TextObject;
109 obj->CopyData(this); 109 obj->CopyData(this);
110 110
111 obj->m_nChars = m_nChars; 111 obj->m_nChars = m_nChars;
112 if (m_nChars > 1) { 112 if (m_nChars > 1) {
113 obj->m_pCharCodes = FX_Alloc(FX_DWORD, m_nChars); 113 obj->m_pCharCodes = FX_Alloc(uint32_t, m_nChars);
114 FXSYS_memcpy(obj->m_pCharCodes, m_pCharCodes, m_nChars * sizeof(FX_DWORD)); 114 FXSYS_memcpy(obj->m_pCharCodes, m_pCharCodes, m_nChars * sizeof(uint32_t));
115 obj->m_pCharPos = FX_Alloc(FX_FLOAT, m_nChars - 1); 115 obj->m_pCharPos = FX_Alloc(FX_FLOAT, m_nChars - 1);
116 FXSYS_memcpy(obj->m_pCharPos, m_pCharPos, 116 FXSYS_memcpy(obj->m_pCharPos, m_pCharPos,
117 (m_nChars - 1) * sizeof(FX_FLOAT)); 117 (m_nChars - 1) * sizeof(FX_FLOAT));
118 } else { 118 } else {
119 obj->m_pCharCodes = m_pCharCodes; 119 obj->m_pCharCodes = m_pCharCodes;
120 } 120 }
121 obj->m_PosX = m_PosX; 121 obj->m_PosX = m_PosX;
122 obj->m_PosY = m_PosY; 122 obj->m_PosY = m_PosY;
123 return obj; 123 return obj;
124 } 124 }
(...skipping 13 matching lines...) Expand all
138 } 138 }
139 FX_Free(m_pCharPos); 139 FX_Free(m_pCharPos);
140 m_pCharPos = nullptr; 140 m_pCharPos = nullptr;
141 CPDF_Font* pFont = m_TextState.GetFont(); 141 CPDF_Font* pFont = m_TextState.GetFont();
142 m_nChars = 0; 142 m_nChars = 0;
143 for (int i = 0; i < nsegs; ++i) { 143 for (int i = 0; i < nsegs; ++i) {
144 m_nChars += pFont->CountChar(pStrs[i], pStrs[i].GetLength()); 144 m_nChars += pFont->CountChar(pStrs[i], pStrs[i].GetLength());
145 } 145 }
146 m_nChars += nsegs - 1; 146 m_nChars += nsegs - 1;
147 if (m_nChars > 1) { 147 if (m_nChars > 1) {
148 m_pCharCodes = FX_Alloc(FX_DWORD, m_nChars); 148 m_pCharCodes = FX_Alloc(uint32_t, m_nChars);
149 m_pCharPos = FX_Alloc(FX_FLOAT, m_nChars - 1); 149 m_pCharPos = FX_Alloc(FX_FLOAT, m_nChars - 1);
150 int index = 0; 150 int index = 0;
151 for (int i = 0; i < nsegs; ++i) { 151 for (int i = 0; i < nsegs; ++i) {
152 const FX_CHAR* segment = pStrs[i]; 152 const FX_CHAR* segment = pStrs[i];
153 int offset = 0, len = pStrs[i].GetLength(); 153 int offset = 0, len = pStrs[i].GetLength();
154 while (offset < len) { 154 while (offset < len) {
155 m_pCharCodes[index++] = pFont->GetNextChar(segment, len, offset); 155 m_pCharCodes[index++] = pFont->GetNextChar(segment, len, offset);
156 } 156 }
157 if (i != nsegs - 1) { 157 if (i != nsegs - 1) {
158 m_pCharPos[index - 1] = pKerning[i]; 158 m_pCharPos[index - 1] = pKerning[i];
159 m_pCharCodes[index++] = (FX_DWORD)-1; 159 m_pCharCodes[index++] = (uint32_t)-1;
160 } 160 }
161 } 161 }
162 } else { 162 } else {
163 int offset = 0; 163 int offset = 0;
164 m_pCharCodes = (FX_DWORD*)(uintptr_t)pFont->GetNextChar( 164 m_pCharCodes = (uint32_t*)(uintptr_t)pFont->GetNextChar(
165 pStrs[0], pStrs[0].GetLength(), offset); 165 pStrs[0], pStrs[0].GetLength(), offset);
166 } 166 }
167 } 167 }
168 168
169 void CPDF_TextObject::SetText(const CFX_ByteString& str) { 169 void CPDF_TextObject::SetText(const CFX_ByteString& str) {
170 SetSegments(&str, nullptr, 1); 170 SetSegments(&str, nullptr, 1);
171 RecalcPositionData(); 171 RecalcPositionData();
172 } 172 }
173 173
174 FX_FLOAT CPDF_TextObject::GetCharWidth(FX_DWORD charcode) const { 174 FX_FLOAT CPDF_TextObject::GetCharWidth(uint32_t charcode) const {
175 FX_FLOAT fontsize = m_TextState.GetFontSize() / 1000; 175 FX_FLOAT fontsize = m_TextState.GetFontSize() / 1000;
176 CPDF_Font* pFont = m_TextState.GetFont(); 176 CPDF_Font* pFont = m_TextState.GetFont();
177 FX_BOOL bVertWriting = FALSE; 177 FX_BOOL bVertWriting = FALSE;
178 CPDF_CIDFont* pCIDFont = pFont->AsCIDFont(); 178 CPDF_CIDFont* pCIDFont = pFont->AsCIDFont();
179 if (pCIDFont) { 179 if (pCIDFont) {
180 bVertWriting = pCIDFont->IsVertWriting(); 180 bVertWriting = pCIDFont->IsVertWriting();
181 } 181 }
182 if (!bVertWriting) 182 if (!bVertWriting)
183 return pFont->GetCharWidthF(charcode, 0) * fontsize; 183 return pFont->GetCharWidthF(charcode, 0) * fontsize;
184 184
(...skipping 11 matching lines...) Expand all
196 FX_FLOAT min_y = 10000 * 1.0f; 196 FX_FLOAT min_y = 10000 * 1.0f;
197 FX_FLOAT max_y = -10000 * 1.0f; 197 FX_FLOAT max_y = -10000 * 1.0f;
198 CPDF_Font* pFont = m_TextState.GetFont(); 198 CPDF_Font* pFont = m_TextState.GetFont();
199 FX_BOOL bVertWriting = FALSE; 199 FX_BOOL bVertWriting = FALSE;
200 CPDF_CIDFont* pCIDFont = pFont->AsCIDFont(); 200 CPDF_CIDFont* pCIDFont = pFont->AsCIDFont();
201 if (pCIDFont) { 201 if (pCIDFont) {
202 bVertWriting = pCIDFont->IsVertWriting(); 202 bVertWriting = pCIDFont->IsVertWriting();
203 } 203 }
204 FX_FLOAT fontsize = m_TextState.GetFontSize(); 204 FX_FLOAT fontsize = m_TextState.GetFontSize();
205 for (int i = 0; i < m_nChars; ++i) { 205 for (int i = 0; i < m_nChars; ++i) {
206 FX_DWORD charcode = 206 uint32_t charcode =
207 m_nChars == 1 ? (FX_DWORD)(uintptr_t)m_pCharCodes : m_pCharCodes[i]; 207 m_nChars == 1 ? (uint32_t)(uintptr_t)m_pCharCodes : m_pCharCodes[i];
208 if (i > 0) { 208 if (i > 0) {
209 if (charcode == (FX_DWORD)-1) { 209 if (charcode == (uint32_t)-1) {
210 curpos -= (m_pCharPos[i - 1] * fontsize) / 1000; 210 curpos -= (m_pCharPos[i - 1] * fontsize) / 1000;
211 continue; 211 continue;
212 } 212 }
213 m_pCharPos[i - 1] = curpos; 213 m_pCharPos[i - 1] = curpos;
214 } 214 }
215 FX_RECT char_rect = pFont->GetCharBBox(charcode, level); 215 FX_RECT char_rect = pFont->GetCharBBox(charcode, level);
216 FX_FLOAT charwidth; 216 FX_FLOAT charwidth;
217 if (!bVertWriting) { 217 if (!bVertWriting) {
218 if (min_y > char_rect.top) { 218 if (min_y > char_rect.top) {
219 min_y = (FX_FLOAT)char_rect.top; 219 min_y = (FX_FLOAT)char_rect.top;
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
339 void CPDF_TextObject::SetPosition(FX_FLOAT x, FX_FLOAT y) { 339 void CPDF_TextObject::SetPosition(FX_FLOAT x, FX_FLOAT y) {
340 FX_FLOAT dx = x - m_PosX; 340 FX_FLOAT dx = x - m_PosX;
341 FX_FLOAT dy = y - m_PosY; 341 FX_FLOAT dy = y - m_PosY;
342 m_PosX = x; 342 m_PosX = x;
343 m_PosY = y; 343 m_PosY = y;
344 m_Left += dx; 344 m_Left += dx;
345 m_Right += dx; 345 m_Right += dx;
346 m_Top += dy; 346 m_Top += dy;
347 m_Bottom += dy; 347 m_Bottom += dy;
348 } 348 }
OLDNEW
« no previous file with comments | « core/fpdfapi/fpdf_page/cpdf_meshstream.cpp ('k') | core/fpdfapi/fpdf_page/fpdf_page_colors.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698