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/fxge/fx_freetype.h" | 10 #include "../../../include/fxge/fx_freetype.h" |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
178 } | 178 } |
179 | 179 |
180 CIDSet CharsetFromOrdering(const CFX_ByteString& ordering) { | 180 CIDSet CharsetFromOrdering(const CFX_ByteString& ordering) { |
181 for (size_t charset = 1; charset < FX_ArraySize(g_CharsetNames); ++charset) { | 181 for (size_t charset = 1; charset < FX_ArraySize(g_CharsetNames); ++charset) { |
182 if (ordering == CFX_ByteStringC(g_CharsetNames[charset])) | 182 if (ordering == CFX_ByteStringC(g_CharsetNames[charset])) |
183 return CIDSetFromSizeT(charset); | 183 return CIDSetFromSizeT(charset); |
184 } | 184 } |
185 return CIDSET_UNKNOWN; | 185 return CIDSET_UNKNOWN; |
186 } | 186 } |
187 | 187 |
188 FX_DWORD CMap_GetCode(const CFX_ByteStringC& word) { | |
189 int num = 0; | |
190 if (word.GetAt(0) == '<') { | |
191 for (int i = 1; i < word.GetLength(); i++) { | |
192 uint8_t digit = word.GetAt(i); | |
193 if (digit >= '0' && digit <= '9') { | |
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 } | |
212 return num; | |
213 } | |
214 | |
215 bool CMap_GetCodeRange(CMap_CodeRange& range, | |
216 const CFX_ByteStringC& first, | |
217 const CFX_ByteStringC& second) { | |
218 if (first.GetLength() == 0 || first.GetAt(0) != '<') | |
219 return false; | |
220 | |
221 int i; | |
222 for (i = 1; i < first.GetLength(); ++i) { | |
223 if (first.GetAt(i) == '>') { | |
224 break; | |
225 } | |
226 } | |
227 range.m_CharSize = (i - 1) / 2; | |
228 if (range.m_CharSize > 4) | |
229 return false; | |
230 | |
231 for (i = 0; i < range.m_CharSize; ++i) { | |
232 uint8_t digit1 = first.GetAt(i * 2 + 1); | |
233 uint8_t digit2 = first.GetAt(i * 2 + 2); | |
234 uint8_t byte = (digit1 >= '0' && digit1 <= '9') | |
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 } | |
242 | |
243 FX_DWORD size = second.GetLength(); | |
244 for (i = 0; i < range.m_CharSize; ++i) { | |
245 uint8_t digit1 = | |
246 ((FX_DWORD)i * 2 + 1 < size) ? second.GetAt((FX_STRSIZE)i * 2 + 1) : 0; | |
247 uint8_t digit2 = | |
248 ((FX_DWORD)i * 2 + 2 < size) ? second.GetAt((FX_STRSIZE)i * 2 + 2) : 0; | |
249 uint8_t byte = (digit1 >= '0' && digit1 <= '9') | |
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 } | |
257 return true; | |
258 } | |
259 | |
260 CFX_ByteString CMap_GetString(const CFX_ByteStringC& word) { | 188 CFX_ByteString CMap_GetString(const CFX_ByteStringC& word) { |
261 return word.Mid(1, word.GetLength() - 2); | 189 return word.Mid(1, word.GetLength() - 2); |
262 } | 190 } |
263 | 191 |
264 int CompareDWORD(const void* data1, const void* data2) { | 192 int CompareDWORD(const void* data1, const void* data2) { |
265 return (*(FX_DWORD*)data1) - (*(FX_DWORD*)data2); | 193 return (*(FX_DWORD*)data1) - (*(FX_DWORD*)data2); |
266 } | 194 } |
267 | 195 |
268 int CompareCID(const void* key, const void* element) { | 196 int CompareCID(const void* key, const void* element) { |
269 if ((*(FX_DWORD*)key) < (*(FX_DWORD*)element)) { | 197 if ((*(FX_DWORD*)key) < (*(FX_DWORD*)element)) { |
(...skipping 492 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
762 CMap_CodeRange range; | 690 CMap_CodeRange range; |
763 if (CMap_GetCodeRange(range, m_LastWord, word)) { | 691 if (CMap_GetCodeRange(range, m_LastWord, word)) { |
764 m_CodeRanges.Add(range); | 692 m_CodeRanges.Add(range); |
765 } | 693 } |
766 } | 694 } |
767 m_CodeSeq++; | 695 m_CodeSeq++; |
768 } | 696 } |
769 } | 697 } |
770 m_LastWord = word; | 698 m_LastWord = word; |
771 } | 699 } |
700 | |
701 FX_DWORD CPDF_CMapParser::CMap_GetCode(const CFX_ByteStringC& word) { | |
702 int num = 0; | |
703 if (word.GetAt(0) == '<') { | |
704 for (int i = 1; i < word.GetLength(); i++) { | |
705 uint8_t digit = word.GetAt(i); | |
706 if (digit >= '0' && digit <= '9') { | |
707 digit = digit - '0'; | |
708 } else if (digit >= 'a' && digit <= 'f') { | |
709 digit = digit - 'a' + 10; | |
710 } else if (digit >= 'A' && digit <= 'F') { | |
711 digit = digit - 'A' + 10; | |
712 } else { | |
713 return num; | |
714 } | |
715 num = num * 16 + digit; | |
716 } | |
717 } else { | |
718 for (int i = 0; i < word.GetLength(); i++) { | |
719 if (word.GetAt(i) < '0' || word.GetAt(i) > '9') { | |
720 return num; | |
721 } | |
722 num = num * 10 + word.GetAt(i) - '0'; | |
723 } | |
724 } | |
725 return num; | |
726 } | |
727 | |
728 // Static. | |
729 bool CPDF_CMapParser::CMap_GetCodeRange(CMap_CodeRange& range, | |
730 const CFX_ByteStringC& first, | |
731 const CFX_ByteStringC& second) { | |
732 if (first.GetLength() == 0 || first.GetAt(0) != '<') | |
733 return false; | |
734 | |
735 int i; | |
736 for (i = 1; i < first.GetLength(); ++i) { | |
737 if (first.GetAt(i) == '>') { | |
738 break; | |
739 } | |
740 } | |
741 range.m_CharSize = (i - 1) / 2; | |
742 if (range.m_CharSize > 4) | |
743 return false; | |
744 | |
745 for (i = 0; i < range.m_CharSize; ++i) { | |
746 uint8_t digit1 = first.GetAt(i * 2 + 1); | |
747 uint8_t digit2 = first.GetAt(i * 2 + 2); | |
748 uint8_t byte = (digit1 >= '0' && digit1 <= '9') | |
749 ? (digit1 - '0') | |
750 : ((digit1 & 0xdf) - 'A' + 10); | |
751 byte = byte * 16 + ((digit2 >= '0' && digit2 <= '9') | |
752 ? (digit2 - '0') | |
753 : ((digit2 & 0xdf) - 'A' + 10)); | |
754 range.m_Lower[i] = byte; | |
755 } | |
756 | |
757 FX_DWORD size = second.GetLength(); | |
758 for (i = 0; i < range.m_CharSize; ++i) { | |
759 uint8_t digit1 = ((FX_DWORD)i * 2 + 1 < size) | |
760 ? second.GetAt((FX_STRSIZE)i * 2 + 1) | |
761 : '0'; | |
762 uint8_t digit2 = ((FX_DWORD)i * 2 + 2 < size) | |
763 ? second.GetAt((FX_STRSIZE)i * 2 + 2) | |
764 : '0'; | |
dsinclair
2015/11/02 19:11:09
I fixed the issue where this was 0 instead of '0'
Tom Sepez
2015/11/02 21:00:54
Acknowledged.
| |
765 uint8_t byte = (digit1 >= '0' && digit1 <= '9') | |
766 ? (digit1 - '0') | |
767 : ((digit1 & 0xdf) - 'A' + 10); | |
768 byte = byte * 16 + ((digit2 >= '0' && digit2 <= '9') | |
769 ? (digit2 - '0') | |
770 : ((digit2 & 0xdf) - 'A' + 10)); | |
771 range.m_Upper[i] = byte; | |
772 } | |
773 return true; | |
774 } | |
775 | |
772 CPDF_CMap::CPDF_CMap() { | 776 CPDF_CMap::CPDF_CMap() { |
773 m_Charset = CIDSET_UNKNOWN; | 777 m_Charset = CIDSET_UNKNOWN; |
774 m_Coding = CIDCODING_UNKNOWN; | 778 m_Coding = CIDCODING_UNKNOWN; |
775 m_CodingScheme = TwoBytes; | 779 m_CodingScheme = TwoBytes; |
776 m_bVertical = 0; | 780 m_bVertical = 0; |
777 m_bLoaded = FALSE; | 781 m_bLoaded = FALSE; |
778 m_pMapping = NULL; | 782 m_pMapping = NULL; |
779 m_pLeadingBytes = NULL; | 783 m_pLeadingBytes = NULL; |
780 m_pAddMapping = NULL; | 784 m_pAddMapping = NULL; |
781 m_pEmbedMap = NULL; | 785 m_pEmbedMap = NULL; |
(...skipping 959 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1741 | 1745 |
1742 const uint8_t* CPDF_CIDFont::GetCIDTransform(FX_WORD CID) const { | 1746 const uint8_t* CPDF_CIDFont::GetCIDTransform(FX_WORD CID) const { |
1743 if (m_Charset != CIDSET_JAPAN1 || m_pFontFile) | 1747 if (m_Charset != CIDSET_JAPAN1 || m_pFontFile) |
1744 return nullptr; | 1748 return nullptr; |
1745 | 1749 |
1746 const struct CIDTransform* found = (const struct CIDTransform*)FXSYS_bsearch( | 1750 const struct CIDTransform* found = (const struct CIDTransform*)FXSYS_bsearch( |
1747 &CID, g_Japan1_VertCIDs, FX_ArraySize(g_Japan1_VertCIDs), | 1751 &CID, g_Japan1_VertCIDs, FX_ArraySize(g_Japan1_VertCIDs), |
1748 sizeof(g_Japan1_VertCIDs[0]), CompareCIDTransform); | 1752 sizeof(g_Japan1_VertCIDs[0]), CompareCIDTransform); |
1749 return found ? &found->a : nullptr; | 1753 return found ? &found->a : nullptr; |
1750 } | 1754 } |
OLD | NEW |