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

Side by Side Diff: core/src/fpdfapi/fpdf_font/fpdf_font_cid.cpp

Issue 1405253007: Revert "Revert "Cleanup some numeric code."" (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Created 5 years, 1 month 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
OLDNEW
1 // Copyright 2014 PDFium Authors. All rights reserved. 1 // Copyright 2014 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 "../../../include/fpdfapi/fpdf_module.h" 7 #include "../../../include/fpdfapi/fpdf_module.h"
8 #include "../../../include/fpdfapi/fpdf_page.h" 8 #include "../../../include/fpdfapi/fpdf_page.h"
9 #include "../../../include/fpdfapi/fpdf_resource.h" 9 #include "../../../include/fpdfapi/fpdf_resource.h"
10 #include "../../../include/fxcrt/fx_ext.h"
10 #include "../../../include/fxge/fx_freetype.h" 11 #include "../../../include/fxge/fx_freetype.h"
11 #include "../../../include/fxge/fx_ge.h" 12 #include "../../../include/fxge/fx_ge.h"
12 #include "../fpdf_cmaps/cmap_int.h" 13 #include "../fpdf_cmaps/cmap_int.h"
13 #include "font_int.h" 14 #include "font_int.h"
14 15
15 namespace { 16 namespace {
16 17
17 const FX_CHAR* const g_CharsetNames[CIDSET_NUM_SETS] = 18 const FX_CHAR* const g_CharsetNames[CIDSET_NUM_SETS] =
18 {nullptr, "GB1", "CNS1", "Japan1", "Korea1", "UCS"}; 19 {nullptr, "GB1", "CNS1", "Japan1", "Korea1", "UCS"};
19 20
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 for (size_t charset = 1; charset < FX_ArraySize(g_CharsetNames); ++charset) { 182 for (size_t charset = 1; charset < FX_ArraySize(g_CharsetNames); ++charset) {
182 if (ordering == CFX_ByteStringC(g_CharsetNames[charset])) 183 if (ordering == CFX_ByteStringC(g_CharsetNames[charset]))
183 return CIDSetFromSizeT(charset); 184 return CIDSetFromSizeT(charset);
184 } 185 }
185 return CIDSET_UNKNOWN; 186 return CIDSET_UNKNOWN;
186 } 187 }
187 188
188 FX_DWORD CMap_GetCode(const CFX_ByteStringC& word) { 189 FX_DWORD CMap_GetCode(const CFX_ByteStringC& word) {
189 int num = 0; 190 int num = 0;
190 if (word.GetAt(0) == '<') { 191 if (word.GetAt(0) == '<') {
191 for (int i = 1; i < word.GetLength(); i++) { 192 for (int i = 1; i < word.GetLength() && std::isxdigit(word.GetAt(i)); ++i)
192 uint8_t digit = word.GetAt(i); 193 num = num * 16 + FXSYS_toHexDigit(word.GetAt(i));
193 if (digit >= '0' && digit <= '9') { 194 return num;
194 digit = digit - '0';
195 } else if (digit >= 'a' && digit <= 'f') {
196 digit = digit - 'a' + 10;
197 } else if (digit >= 'A' && digit <= 'F') {
198 digit = digit - 'A' + 10;
199 } else {
200 return num;
201 }
202 num = num * 16 + digit;
203 }
204 } else {
205 for (int i = 0; i < word.GetLength(); i++) {
206 if (word.GetAt(i) < '0' || word.GetAt(i) > '9') {
207 return num;
208 }
209 num = num * 10 + word.GetAt(i) - '0';
210 }
211 } 195 }
196
197 for (int i = 0; i < word.GetLength() && std::isdigit(word.GetAt(i)); ++i)
198 num = num * 10 + FXSYS_toDecimalDigit(word.GetAt(i));
212 return num; 199 return num;
213 } 200 }
214 201
215 bool CMap_GetCodeRange(CMap_CodeRange& range, 202 bool CMap_GetCodeRange(CMap_CodeRange& range,
216 const CFX_ByteStringC& first, 203 const CFX_ByteStringC& first,
217 const CFX_ByteStringC& second) { 204 const CFX_ByteStringC& second) {
218 if (first.GetLength() == 0 || first.GetAt(0) != '<') 205 if (first.GetLength() == 0 || first.GetAt(0) != '<')
219 return false; 206 return false;
220 207
221 int i; 208 int i;
222 for (i = 1; i < first.GetLength(); ++i) { 209 for (i = 1; i < first.GetLength(); ++i) {
223 if (first.GetAt(i) == '>') { 210 if (first.GetAt(i) == '>') {
224 break; 211 break;
225 } 212 }
226 } 213 }
227 range.m_CharSize = (i - 1) / 2; 214 range.m_CharSize = (i - 1) / 2;
228 if (range.m_CharSize > 4) 215 if (range.m_CharSize > 4)
229 return false; 216 return false;
230 217
231 for (i = 0; i < range.m_CharSize; ++i) { 218 for (i = 0; i < range.m_CharSize; ++i) {
232 uint8_t digit1 = first.GetAt(i * 2 + 1); 219 uint8_t digit1 = first.GetAt(i * 2 + 1);
233 uint8_t digit2 = first.GetAt(i * 2 + 2); 220 uint8_t digit2 = first.GetAt(i * 2 + 2);
234 uint8_t byte = (digit1 >= '0' && digit1 <= '9') 221 range.m_Lower[i] = FXSYS_toHexDigit(digit1) * 16 + FXSYS_toHexDigit(digit2);
235 ? (digit1 - '0')
236 : ((digit1 & 0xdf) - 'A' + 10);
237 byte = byte * 16 + ((digit2 >= '0' && digit2 <= '9')
238 ? (digit2 - '0')
239 : ((digit2 & 0xdf) - 'A' + 10));
240 range.m_Lower[i] = byte;
241 } 222 }
242 223
243 FX_DWORD size = second.GetLength(); 224 FX_DWORD size = second.GetLength();
244 for (i = 0; i < range.m_CharSize; ++i) { 225 for (i = 0; i < range.m_CharSize; ++i) {
245 uint8_t digit1 = 226 uint8_t digit1 = ((FX_DWORD)i * 2 + 1 < size)
246 ((FX_DWORD)i * 2 + 1 < size) ? second.GetAt((FX_STRSIZE)i * 2 + 1) : 0; 227 ? second.GetAt((FX_STRSIZE)i * 2 + 1)
247 uint8_t digit2 = 228 : '0';
248 ((FX_DWORD)i * 2 + 2 < size) ? second.GetAt((FX_STRSIZE)i * 2 + 2) : 0; 229 uint8_t digit2 = ((FX_DWORD)i * 2 + 2 < size)
249 uint8_t byte = (digit1 >= '0' && digit1 <= '9') 230 ? second.GetAt((FX_STRSIZE)i * 2 + 2)
250 ? (digit1 - '0') 231 : '0';
251 : ((digit1 & 0xdf) - 'A' + 10); 232 range.m_Upper[i] = FXSYS_toHexDigit(digit1) * 16 + FXSYS_toHexDigit(digit2);
252 byte = byte * 16 + ((digit2 >= '0' && digit2 <= '9')
253 ? (digit2 - '0')
254 : ((digit2 & 0xdf) - 'A' + 10));
255 range.m_Upper[i] = byte;
256 } 233 }
257 return true; 234 return true;
258 } 235 }
259 236
260 CFX_ByteString CMap_GetString(const CFX_ByteStringC& word) { 237 CFX_ByteString CMap_GetString(const CFX_ByteStringC& word) {
261 return word.Mid(1, word.GetLength() - 2); 238 return word.Mid(1, word.GetLength() - 2);
262 } 239 }
263 240
264 int CompareDWORD(const void* data1, const void* data2) { 241 int CompareDWORD(const void* data1, const void* data2) {
265 return (*(FX_DWORD*)data1) - (*(FX_DWORD*)data2); 242 return (*(FX_DWORD*)data1) - (*(FX_DWORD*)data2);
(...skipping 1475 matching lines...) Expand 10 before | Expand all | Expand 10 after
1741 1718
1742 const uint8_t* CPDF_CIDFont::GetCIDTransform(FX_WORD CID) const { 1719 const uint8_t* CPDF_CIDFont::GetCIDTransform(FX_WORD CID) const {
1743 if (m_Charset != CIDSET_JAPAN1 || m_pFontFile) 1720 if (m_Charset != CIDSET_JAPAN1 || m_pFontFile)
1744 return nullptr; 1721 return nullptr;
1745 1722
1746 const struct CIDTransform* found = (const struct CIDTransform*)FXSYS_bsearch( 1723 const struct CIDTransform* found = (const struct CIDTransform*)FXSYS_bsearch(
1747 &CID, g_Japan1_VertCIDs, FX_ArraySize(g_Japan1_VertCIDs), 1724 &CID, g_Japan1_VertCIDs, FX_ArraySize(g_Japan1_VertCIDs),
1748 sizeof(g_Japan1_VertCIDs[0]), CompareCIDTransform); 1725 sizeof(g_Japan1_VertCIDs[0]), CompareCIDTransform);
1749 return found ? &found->a : nullptr; 1726 return found ? &found->a : nullptr;
1750 } 1727 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698