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 <limits.h> | 7 #include <limits.h> |
8 | 8 |
9 #include "core/fpdfapi/fpdf_font/include/cpdf_font.h" | 9 #include "core/fpdfapi/fpdf_font/include/cpdf_font.h" |
10 #include "core/fpdfapi/fpdf_font/include/cpdf_fontencoding.h" | 10 #include "core/fpdfapi/fpdf_font/include/cpdf_fontencoding.h" |
(...skipping 428 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
439 FXSYS_assert(pStr); | 439 FXSYS_assert(pStr); |
440 int32_t iLength = FXSYS_strlen(pStr); | 440 int32_t iLength = FXSYS_strlen(pStr); |
441 const FX_CHAR* pStrEnd = pStr + iLength; | 441 const FX_CHAR* pStrEnd = pStr + iLength; |
442 uint32_t uHashCode = 0; | 442 uint32_t uHashCode = 0; |
443 while (pStr < pStrEnd) { | 443 while (pStr < pStrEnd) { |
444 uHashCode = 31 * uHashCode + tolower(*pStr++); | 444 uHashCode = 31 * uHashCode + tolower(*pStr++); |
445 } | 445 } |
446 return uHashCode; | 446 return uHashCode; |
447 } | 447 } |
448 struct FX_LANG2CS { | 448 struct FX_LANG2CS { |
449 FX_DWORD uLang; | 449 uint32_t uLang; |
450 int uCharset; | 450 int uCharset; |
451 } * FX_LPLANG2CS; | 451 } * FX_LPLANG2CS; |
452 static const FX_LANG2CS gs_FXLang2CharsetTable[] = { | 452 static const FX_LANG2CS gs_FXLang2CharsetTable[] = { |
453 {3109, 0}, {3121, 178}, {3129, 162}, {3139, 204}, {3141, 204}, | 453 {3109, 0}, {3121, 178}, {3129, 162}, {3139, 204}, {3141, 204}, |
454 {3166, 0}, {3184, 238}, {3197, 0}, {3201, 0}, {3239, 161}, | 454 {3166, 0}, {3184, 238}, {3197, 0}, {3201, 0}, {3239, 161}, |
455 {3241, 0}, {3246, 0}, {3247, 186}, {3248, 0}, {3259, 178}, | 455 {3241, 0}, {3246, 0}, {3247, 186}, {3248, 0}, {3259, 178}, |
456 {3267, 0}, {3273, 0}, {3276, 0}, {3301, 0}, {3310, 1}, | 456 {3267, 0}, {3273, 0}, {3276, 0}, {3301, 0}, {3310, 1}, |
457 {3325, 177}, {3329, 1}, {3338, 238}, {3341, 238}, {3345, 1}, | 457 {3325, 177}, {3329, 1}, {3338, 238}, {3341, 238}, {3345, 1}, |
458 {3355, 0}, {3370, 0}, {3371, 0}, {3383, 128}, {3424, 204}, | 458 {3355, 0}, {3370, 0}, {3371, 0}, {3383, 128}, {3424, 204}, |
459 {3427, 1}, {3428, 129}, {3436, 178}, {3464, 186}, {3466, 186}, | 459 {3427, 1}, {3428, 129}, {3436, 178}, {3464, 186}, {3466, 186}, |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
494 SInt32 len = CFStringGetLength(src); | 494 SInt32 len = CFStringGetLength(src); |
495 CFRange range = CFRangeMake(0, len); | 495 CFRange range = CFRangeMake(0, len); |
496 CFIndex used = 0; | 496 CFIndex used = 0; |
497 UInt8* pBuffer = (UInt8*)calloc(len + 1, sizeof(UInt8)); | 497 UInt8* pBuffer = (UInt8*)calloc(len + 1, sizeof(UInt8)); |
498 CFStringGetBytes(src, range, kCFStringEncodingASCII, 0, false, pBuffer, len, | 498 CFStringGetBytes(src, range, kCFStringEncodingASCII, 0, false, pBuffer, len, |
499 &used); | 499 &used); |
500 dest = (FX_CHAR*)pBuffer; | 500 dest = (FX_CHAR*)pBuffer; |
501 free(pBuffer); | 501 free(pBuffer); |
502 } | 502 } |
503 FX_BOOL IsHasCharSet(CFArrayRef languages, | 503 FX_BOOL IsHasCharSet(CFArrayRef languages, |
504 const CFX_ArrayTemplate<FX_DWORD>& charSets) { | 504 const CFX_ArrayTemplate<uint32_t>& charSets) { |
505 int iCount = charSets.GetSize(); | 505 int iCount = charSets.GetSize(); |
506 for (int i = 0; i < CFArrayGetCount(languages); ++i) { | 506 for (int i = 0; i < CFArrayGetCount(languages); ++i) { |
507 CFStringRef language = (CFStringRef)CFArrayGetValueAtIndex(languages, i); | 507 CFStringRef language = (CFStringRef)CFArrayGetValueAtIndex(languages, i); |
508 FX_DWORD CharSet = FX_GetCharsetFromLang( | 508 uint32_t CharSet = FX_GetCharsetFromLang( |
509 CFStringGetCStringPtr(language, kCFStringEncodingMacRoman), -1); | 509 CFStringGetCStringPtr(language, kCFStringEncodingMacRoman), -1); |
510 for (int j = 0; j < iCount; ++j) { | 510 for (int j = 0; j < iCount; ++j) { |
511 if (CharSet == charSets[j]) { | 511 if (CharSet == charSets[j]) { |
512 return TRUE; | 512 return TRUE; |
513 } | 513 } |
514 } | 514 } |
515 } | 515 } |
516 return FALSE; | 516 return FALSE; |
517 } | 517 } |
518 void FX_GetCharWidth(CTFontRef font, UniChar start, UniChar end, int* width) { | 518 void FX_GetCharWidth(CTFontRef font, UniChar start, UniChar end, int* width) { |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
565 FX_BOOL bCJK = FALSE; | 565 FX_BOOL bCJK = FALSE; |
566 int flags = 0, italicangle = 0, ascend = 0, descend = 0, capheight = 0, | 566 int flags = 0, italicangle = 0, ascend = 0, descend = 0, capheight = 0, |
567 bbox[4]; | 567 bbox[4]; |
568 FXSYS_memset(bbox, 0, sizeof(int) * 4); | 568 FXSYS_memset(bbox, 0, sizeof(int) * 4); |
569 CFArrayRef languages = (CFArrayRef)CTFontDescriptorCopyAttribute( | 569 CFArrayRef languages = (CFArrayRef)CTFontDescriptorCopyAttribute( |
570 descriptor, kCTFontLanguagesAttribute); | 570 descriptor, kCTFontLanguagesAttribute); |
571 if (!languages) { | 571 if (!languages) { |
572 CFRelease(descriptor); | 572 CFRelease(descriptor); |
573 return NULL; | 573 return NULL; |
574 } | 574 } |
575 CFX_ArrayTemplate<FX_DWORD> charSets; | 575 CFX_ArrayTemplate<uint32_t> charSets; |
576 charSets.Add(FXFONT_CHINESEBIG5_CHARSET); | 576 charSets.Add(FXFONT_CHINESEBIG5_CHARSET); |
577 charSets.Add(FXFONT_GB2312_CHARSET); | 577 charSets.Add(FXFONT_GB2312_CHARSET); |
578 charSets.Add(FXFONT_HANGEUL_CHARSET); | 578 charSets.Add(FXFONT_HANGEUL_CHARSET); |
579 charSets.Add(FXFONT_SHIFTJIS_CHARSET); | 579 charSets.Add(FXFONT_SHIFTJIS_CHARSET); |
580 if (IsHasCharSet(languages, charSets)) { | 580 if (IsHasCharSet(languages, charSets)) { |
581 bCJK = TRUE; | 581 bCJK = TRUE; |
582 } | 582 } |
583 CFRelease(descriptor); | 583 CFRelease(descriptor); |
584 CFDictionaryRef traits = (CFDictionaryRef)CTFontCopyTraits(font); | 584 CFDictionaryRef traits = (CFDictionaryRef)CTFontCopyTraits(font); |
585 if (!traits) { | 585 if (!traits) { |
(...skipping 415 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1001 pBBox->AddInteger(bbox.bottom); | 1001 pBBox->AddInteger(bbox.bottom); |
1002 pBBox->AddInteger(bbox.right); | 1002 pBBox->AddInteger(bbox.right); |
1003 pBBox->AddInteger(bbox.top); | 1003 pBBox->AddInteger(bbox.top); |
1004 pFontDesc->SetAt("FontBBox", pBBox); | 1004 pFontDesc->SetAt("FontBBox", pBBox); |
1005 int32_t nStemV = 0; | 1005 int32_t nStemV = 0; |
1006 if (pFont->GetSubstFont()) { | 1006 if (pFont->GetSubstFont()) { |
1007 nStemV = pFont->GetSubstFont()->m_Weight / 5; | 1007 nStemV = pFont->GetSubstFont()->m_Weight / 5; |
1008 } else { | 1008 } else { |
1009 static const FX_CHAR stem_chars[] = {'i', 'I', '!', '1'}; | 1009 static const FX_CHAR stem_chars[] = {'i', 'I', '!', '1'}; |
1010 const size_t count = sizeof(stem_chars) / sizeof(stem_chars[0]); | 1010 const size_t count = sizeof(stem_chars) / sizeof(stem_chars[0]); |
1011 FX_DWORD glyph = pEncoding->GlyphFromCharCode(stem_chars[0]); | 1011 uint32_t glyph = pEncoding->GlyphFromCharCode(stem_chars[0]); |
1012 nStemV = pFont->GetGlyphWidth(glyph); | 1012 nStemV = pFont->GetGlyphWidth(glyph); |
1013 for (size_t i = 1; i < count; i++) { | 1013 for (size_t i = 1; i < count; i++) { |
1014 glyph = pEncoding->GlyphFromCharCode(stem_chars[i]); | 1014 glyph = pEncoding->GlyphFromCharCode(stem_chars[i]); |
1015 int width = pFont->GetGlyphWidth(glyph); | 1015 int width = pFont->GetGlyphWidth(glyph); |
1016 if (width > 0 && width < nStemV) { | 1016 if (width > 0 && width < nStemV) { |
1017 nStemV = width; | 1017 nStemV = width; |
1018 } | 1018 } |
1019 } | 1019 } |
1020 } | 1020 } |
1021 pFontDesc->SetAtInteger("StemV", nStemV); | 1021 pFontDesc->SetAtInteger("StemV", nStemV); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1069 return 1; | 1069 return 1; |
1070 } | 1070 } |
1071 nPagesToGo -= nPages; | 1071 nPagesToGo -= nPages; |
1072 } | 1072 } |
1073 } | 1073 } |
1074 return 0; | 1074 return 0; |
1075 } | 1075 } |
1076 static int InsertNewPage(CPDF_Document* pDoc, | 1076 static int InsertNewPage(CPDF_Document* pDoc, |
1077 int iPage, | 1077 int iPage, |
1078 CPDF_Dictionary* pPageDict, | 1078 CPDF_Dictionary* pPageDict, |
1079 CFX_ArrayTemplate<FX_DWORD>& pageList) { | 1079 CFX_ArrayTemplate<uint32_t>& pageList) { |
1080 CPDF_Dictionary* pRoot = pDoc->GetRoot(); | 1080 CPDF_Dictionary* pRoot = pDoc->GetRoot(); |
1081 if (!pRoot) { | 1081 if (!pRoot) { |
1082 return -1; | 1082 return -1; |
1083 } | 1083 } |
1084 CPDF_Dictionary* pPages = pRoot->GetDictBy("Pages"); | 1084 CPDF_Dictionary* pPages = pRoot->GetDictBy("Pages"); |
1085 if (!pPages) { | 1085 if (!pPages) { |
1086 return -1; | 1086 return -1; |
1087 } | 1087 } |
1088 int nPages = pDoc->GetPageCount(); | 1088 int nPages = pDoc->GetPageCount(); |
1089 if (iPage < 0 || iPage > nPages) { | 1089 if (iPage < 0 || iPage > nPages) { |
(...skipping 14 matching lines...) Expand all Loading... |
1104 if (InsertDeletePDFPage(pDoc, pPages, iPage, pPageDict, TRUE, stack) < 0) { | 1104 if (InsertDeletePDFPage(pDoc, pPages, iPage, pPageDict, TRUE, stack) < 0) { |
1105 return -1; | 1105 return -1; |
1106 } | 1106 } |
1107 } | 1107 } |
1108 pageList.InsertAt(iPage, pPageDict->GetObjNum()); | 1108 pageList.InsertAt(iPage, pPageDict->GetObjNum()); |
1109 return iPage; | 1109 return iPage; |
1110 } | 1110 } |
1111 CPDF_Dictionary* CPDF_Document::CreateNewPage(int iPage) { | 1111 CPDF_Dictionary* CPDF_Document::CreateNewPage(int iPage) { |
1112 CPDF_Dictionary* pDict = new CPDF_Dictionary; | 1112 CPDF_Dictionary* pDict = new CPDF_Dictionary; |
1113 pDict->SetAtName("Type", "Page"); | 1113 pDict->SetAtName("Type", "Page"); |
1114 FX_DWORD dwObjNum = AddIndirectObject(pDict); | 1114 uint32_t dwObjNum = AddIndirectObject(pDict); |
1115 if (InsertNewPage(this, iPage, pDict, m_PageList) < 0) { | 1115 if (InsertNewPage(this, iPage, pDict, m_PageList) < 0) { |
1116 ReleaseIndirectObject(dwObjNum); | 1116 ReleaseIndirectObject(dwObjNum); |
1117 return NULL; | 1117 return NULL; |
1118 } | 1118 } |
1119 return pDict; | 1119 return pDict; |
1120 } | 1120 } |
1121 | 1121 |
1122 CPDF_Font* CPDF_Document::AddStandardFont(const FX_CHAR* font, | 1122 CPDF_Font* CPDF_Document::AddStandardFont(const FX_CHAR* font, |
1123 CPDF_FontEncoding* pEncoding) { | 1123 CPDF_FontEncoding* pEncoding) { |
1124 CFX_ByteString name(font); | 1124 CFX_ByteString name(font); |
(...skipping 26 matching lines...) Expand all Loading... |
1151 void FPDFAPI_FlatPageAttr(CPDF_Dictionary* pPageDict, | 1151 void FPDFAPI_FlatPageAttr(CPDF_Dictionary* pPageDict, |
1152 const CFX_ByteStringC& name) { | 1152 const CFX_ByteStringC& name) { |
1153 if (pPageDict->KeyExist(name)) { | 1153 if (pPageDict->KeyExist(name)) { |
1154 return; | 1154 return; |
1155 } | 1155 } |
1156 CPDF_Object* pObj = FPDFAPI_GetPageAttr(pPageDict, name); | 1156 CPDF_Object* pObj = FPDFAPI_GetPageAttr(pPageDict, name); |
1157 if (pObj) { | 1157 if (pObj) { |
1158 pPageDict->SetAt(name, pObj->Clone()); | 1158 pPageDict->SetAt(name, pObj->Clone()); |
1159 } | 1159 } |
1160 } | 1160 } |
OLD | NEW |