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

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: Leftover comments from original CL. 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 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
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(); i++) {
192 uint8_t digit = word.GetAt(i); 193 uint8_t digit = word.GetAt(i);
193 if (digit >= '0' && digit <= '9') { 194 if (!std::isxdigit(digit))
194 digit = digit - '0'; 195 break;
195 } else if (digit >= 'a' && digit <= 'f') { 196 num = num * 16 + FXSYS_toHexDigit(digit);
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 } 197 }
204 } else { 198 return num;
205 for (int i = 0; i < word.GetLength(); i++) { 199 }
206 if (word.GetAt(i) < '0' || word.GetAt(i) > '9') { 200
207 return num; 201 for (int i = 0; i < word.GetLength(); i++) {
208 } 202 if (!std::isdigit(word.GetAt(i)))
209 num = num * 10 + word.GetAt(i) - '0'; 203 break;
210 } 204 num = num * 10 + FXSYS_toDecimalDigit(word.GetAt(i));
211 } 205 }
212 return num; 206 return num;
213 } 207 }
214 208
215 bool CMap_GetCodeRange(CMap_CodeRange& range, 209 bool CMap_GetCodeRange(CMap_CodeRange& range,
216 const CFX_ByteStringC& first, 210 const CFX_ByteStringC& first,
217 const CFX_ByteStringC& second) { 211 const CFX_ByteStringC& second) {
218 if (first.GetLength() == 0 || first.GetAt(0) != '<') 212 if (first.GetLength() == 0 || first.GetAt(0) != '<')
219 return false; 213 return false;
220 214
221 int i; 215 int i;
222 for (i = 1; i < first.GetLength(); ++i) { 216 for (i = 1; i < first.GetLength(); ++i) {
223 if (first.GetAt(i) == '>') { 217 if (first.GetAt(i) == '>') {
224 break; 218 break;
225 } 219 }
226 } 220 }
227 range.m_CharSize = (i - 1) / 2; 221 range.m_CharSize = (i - 1) / 2;
228 if (range.m_CharSize > 4) 222 if (range.m_CharSize > 4)
229 return false; 223 return false;
230 224
231 for (i = 0; i < range.m_CharSize; ++i) { 225 for (i = 0; i < range.m_CharSize; ++i) {
232 uint8_t digit1 = first.GetAt(i * 2 + 1); 226 uint8_t digit1 = first.GetAt(i * 2 + 1);
233 uint8_t digit2 = first.GetAt(i * 2 + 2); 227 uint8_t digit2 = first.GetAt(i * 2 + 2);
234 uint8_t byte = (digit1 >= '0' && digit1 <= '9') 228 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 } 229 }
242 230
243 FX_DWORD size = second.GetLength(); 231 FX_DWORD size = second.GetLength();
244 for (i = 0; i < range.m_CharSize; ++i) { 232 for (i = 0; i < range.m_CharSize; ++i) {
245 uint8_t digit1 = 233 uint8_t digit1 = ((FX_DWORD)i * 2 + 1 < size)
246 ((FX_DWORD)i * 2 + 1 < size) ? second.GetAt((FX_STRSIZE)i * 2 + 1) : 0; 234 ? second.GetAt((FX_STRSIZE)i * 2 + 1)
247 uint8_t digit2 = 235 : '0';
248 ((FX_DWORD)i * 2 + 2 < size) ? second.GetAt((FX_STRSIZE)i * 2 + 2) : 0; 236 uint8_t digit2 = ((FX_DWORD)i * 2 + 2 < size)
249 uint8_t byte = (digit1 >= '0' && digit1 <= '9') 237 ? second.GetAt((FX_STRSIZE)i * 2 + 2)
250 ? (digit1 - '0') 238 : '0';
251 : ((digit1 & 0xdf) - 'A' + 10); 239 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 } 240 }
257 return true; 241 return true;
258 } 242 }
259 243
260 CFX_ByteString CMap_GetString(const CFX_ByteStringC& word) { 244 CFX_ByteString CMap_GetString(const CFX_ByteStringC& word) {
261 return word.Mid(1, word.GetLength() - 2); 245 return word.Mid(1, word.GetLength() - 2);
262 } 246 }
263 247
264 int CompareDWORD(const void* data1, const void* data2) { 248 int CompareDWORD(const void* data1, const void* data2) {
265 return (*(FX_DWORD*)data1) - (*(FX_DWORD*)data2); 249 return (*(FX_DWORD*)data1) - (*(FX_DWORD*)data2);
(...skipping 1475 matching lines...) Expand 10 before | Expand all | Expand 10 after
1741 1725
1742 const uint8_t* CPDF_CIDFont::GetCIDTransform(FX_WORD CID) const { 1726 const uint8_t* CPDF_CIDFont::GetCIDTransform(FX_WORD CID) const {
1743 if (m_Charset != CIDSET_JAPAN1 || m_pFontFile) 1727 if (m_Charset != CIDSET_JAPAN1 || m_pFontFile)
1744 return nullptr; 1728 return nullptr;
1745 1729
1746 const struct CIDTransform* found = (const struct CIDTransform*)FXSYS_bsearch( 1730 const struct CIDTransform* found = (const struct CIDTransform*)FXSYS_bsearch(
1747 &CID, g_Japan1_VertCIDs, FX_ArraySize(g_Japan1_VertCIDs), 1731 &CID, g_Japan1_VertCIDs, FX_ArraySize(g_Japan1_VertCIDs),
1748 sizeof(g_Japan1_VertCIDs[0]), CompareCIDTransform); 1732 sizeof(g_Japan1_VertCIDs[0]), CompareCIDTransform);
1749 return found ? &found->a : nullptr; 1733 return found ? &found->a : nullptr;
1750 } 1734 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698