Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 178 } | 179 } |
| 179 | 180 |
| 180 CIDSet CharsetFromOrdering(const CFX_ByteString& ordering) { | 181 CIDSet CharsetFromOrdering(const CFX_ByteString& ordering) { |
| 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) { |
|
Tom Sepez
2015/10/29 19:28:31
test/
dsinclair
2015/11/03 15:59:02
https://codereview.chromium.org/1414013005
| |
| 189 int num = 0; | 190 int num = 0; |
| 190 if (word.GetAt(0) == '<') { | 191 if (word.GetAt(0) == '<') { |
|
Tom Sepez
2015/10/29 19:28:31
nit: can't these two branches of the if be merged?
dsinclair
2015/11/03 15:59:02
No, one is using std::isxdigit to convert hex char
| |
| 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 } 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; | 195 return num; |
| 201 } | 196 num = num * 16 + HexCharToDigit(digit); |
| 202 num = num * 16 + digit; | |
| 203 } | 197 } |
| 204 } else { | 198 } else { |
| 205 for (int i = 0; i < word.GetLength(); i++) { | 199 for (int i = 0; i < word.GetLength(); i++) { |
| 206 if (word.GetAt(i) < '0' || word.GetAt(i) > '9') { | 200 if (!std::isdigit(word.GetAt(i))) |
| 207 return num; | 201 return num; |
| 208 } | 202 |
| 209 num = num * 10 + word.GetAt(i) - '0'; | 203 num = num * 10 + word.GetAt(i) - '0'; |
| 210 } | 204 } |
| 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, |
|
Tom Sepez
2015/10/29 19:28:31
test.
dsinclair
2015/11/03 15:59:02
https://codereview.chromium.org/1414013005
| |
| 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] = HexCharToDigit(digit1) * 16 + HexCharToDigit(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 = |
| 246 ((FX_DWORD)i * 2 + 1 < size) ? second.GetAt((FX_STRSIZE)i * 2 + 1) : 0; | 234 ((FX_DWORD)i * 2 + 1 < size) ? second.GetAt((FX_STRSIZE)i * 2 + 1) : 0; |
| 247 uint8_t digit2 = | 235 uint8_t digit2 = |
| 248 ((FX_DWORD)i * 2 + 2 < size) ? second.GetAt((FX_STRSIZE)i * 2 + 2) : 0; | 236 ((FX_DWORD)i * 2 + 2 < size) ? second.GetAt((FX_STRSIZE)i * 2 + 2) : 0; |
| 249 uint8_t byte = (digit1 >= '0' && digit1 <= '9') | 237 range.m_Upper[i] = HexCharToDigit(digit1) * 16 + HexCharToDigit(digit2); |
| 250 ? (digit1 - '0') | |
| 251 : ((digit1 & 0xdf) - 'A' + 10); | |
| 252 byte = byte * 16 + ((digit2 >= '0' && digit2 <= '9') | |
| 253 ? (digit2 - '0') | |
| 254 : ((digit2 & 0xdf) - 'A' + 10)); | |
| 255 range.m_Upper[i] = byte; | |
| 256 } | 238 } |
| 257 return true; | 239 return true; |
| 258 } | 240 } |
| 259 | 241 |
| 260 CFX_ByteString CMap_GetString(const CFX_ByteStringC& word) { | 242 CFX_ByteString CMap_GetString(const CFX_ByteStringC& word) { |
| 261 return word.Mid(1, word.GetLength() - 2); | 243 return word.Mid(1, word.GetLength() - 2); |
| 262 } | 244 } |
| 263 | 245 |
| 264 int CompareDWORD(const void* data1, const void* data2) { | 246 int CompareDWORD(const void* data1, const void* data2) { |
| 265 return (*(FX_DWORD*)data1) - (*(FX_DWORD*)data2); | 247 return (*(FX_DWORD*)data1) - (*(FX_DWORD*)data2); |
| (...skipping 1475 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1741 | 1723 |
| 1742 const uint8_t* CPDF_CIDFont::GetCIDTransform(FX_WORD CID) const { | 1724 const uint8_t* CPDF_CIDFont::GetCIDTransform(FX_WORD CID) const { |
| 1743 if (m_Charset != CIDSET_JAPAN1 || m_pFontFile) | 1725 if (m_Charset != CIDSET_JAPAN1 || m_pFontFile) |
| 1744 return nullptr; | 1726 return nullptr; |
| 1745 | 1727 |
| 1746 const struct CIDTransform* found = (const struct CIDTransform*)FXSYS_bsearch( | 1728 const struct CIDTransform* found = (const struct CIDTransform*)FXSYS_bsearch( |
| 1747 &CID, g_Japan1_VertCIDs, FX_ArraySize(g_Japan1_VertCIDs), | 1729 &CID, g_Japan1_VertCIDs, FX_ArraySize(g_Japan1_VertCIDs), |
| 1748 sizeof(g_Japan1_VertCIDs[0]), CompareCIDTransform); | 1730 sizeof(g_Japan1_VertCIDs[0]), CompareCIDTransform); |
| 1749 return found ? &found->a : nullptr; | 1731 return found ? &found->a : nullptr; |
| 1750 } | 1732 } |
| OLD | NEW |