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

Side by Side Diff: core/src/fxge/ge/fx_ge_fontmap.cpp

Issue 1177483002: Use stdint.h types throughout PDFium. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Created 5 years, 6 months 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
« no previous file with comments | « core/src/fxge/ge/fx_ge_font.cpp ('k') | core/src/fxge/ge/fx_ge_linux.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <limits> 7 #include <limits>
8 8
9 #include "../../../include/fxge/fx_ge.h" 9 #include "../../../include/fxge/fx_ge.h"
10 #include "../../../include/fxge/fx_freetype.h" 10 #include "../../../include/fxge/fx_freetype.h"
(...skipping 547 matching lines...) Expand 10 before | Expand all | Expand 10 after
558 return CFX_ByteString(); 558 return CFX_ByteString();
559 } 559 }
560 CFX_ByteString CFX_FontMapper::GetPSNameFromTT(void* hFont) 560 CFX_ByteString CFX_FontMapper::GetPSNameFromTT(void* hFont)
561 { 561 {
562 if (m_pFontInfo == NULL) { 562 if (m_pFontInfo == NULL) {
563 CFX_ByteString(); 563 CFX_ByteString();
564 } 564 }
565 CFX_ByteString result; 565 CFX_ByteString result;
566 FX_DWORD size = m_pFontInfo->GetFontData(hFont, 0x6e616d65, NULL, 0); 566 FX_DWORD size = m_pFontInfo->GetFontData(hFont, 0x6e616d65, NULL, 0);
567 if (size) { 567 if (size) {
568 FX_LPBYTE buffer = FX_Alloc(FX_BYTE, size); 568 FX_LPBYTE buffer = FX_Alloc(uint8_t, size);
569 m_pFontInfo->GetFontData(hFont, 0x6e616d65, buffer, size); 569 m_pFontInfo->GetFontData(hFont, 0x6e616d65, buffer, size);
570 result = _FPDF_GetNameFromTT(buffer, 6); 570 result = _FPDF_GetNameFromTT(buffer, 6);
571 FX_Free(buffer); 571 FX_Free(buffer);
572 } 572 }
573 return result; 573 return result;
574 } 574 }
575 void CFX_FontMapper::AddInstalledFont(const CFX_ByteString& name, int charset) 575 void CFX_FontMapper::AddInstalledFont(const CFX_ByteString& name, int charset)
576 { 576 {
577 if (m_pFontInfo == NULL) { 577 if (m_pFontInfo == NULL) {
578 return; 578 return;
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
637 if (i < 0) { 637 if (i < 0) {
638 return CFX_ByteString(); 638 return CFX_ByteString();
639 } 639 }
640 CFX_ByteString match = m_InstalledTTFonts[i]; 640 CFX_ByteString match = m_InstalledTTFonts[i];
641 if (match[0] == ' ') { 641 if (match[0] == ' ') {
642 match = m_InstalledTTFonts[i + 1]; 642 match = m_InstalledTTFonts[i + 1];
643 } 643 }
644 return match; 644 return match;
645 } 645 }
646 typedef struct _CHARSET_MAP_ { 646 typedef struct _CHARSET_MAP_ {
647 FX_BYTE charset; 647 uint8_t charset;
648 FX_WORD codepage; 648 FX_WORD codepage;
649 } CHARSET_MAP; 649 } CHARSET_MAP;
650 static const CHARSET_MAP g_Codepage2CharsetTable[] = { 650 static const CHARSET_MAP g_Codepage2CharsetTable[] = {
651 { 1 , 0 }, 651 { 1 , 0 },
652 { 2 , 42 }, 652 { 2 , 42 },
653 { 254, 437 }, 653 { 254, 437 },
654 { 255, 850 }, 654 { 255, 850 },
655 { 222, 874 }, 655 { 222, 874 },
656 { 128, 932 }, 656 { 128, 932 },
657 { 134, 936 }, 657 { 134, 936 },
(...skipping 15 matching lines...) Expand all
673 { 80, 10008 }, 673 { 80, 10008 },
674 { 81, 10002 }, 674 { 81, 10002 },
675 { 83, 10005 }, 675 { 83, 10005 },
676 { 84, 10004 }, 676 { 84, 10004 },
677 { 85, 10006 }, 677 { 85, 10006 },
678 { 86, 10081 }, 678 { 86, 10081 },
679 { 87, 10021 }, 679 { 87, 10021 },
680 { 88, 10029 }, 680 { 88, 10029 },
681 { 89, 10007 }, 681 { 89, 10007 },
682 }; 682 };
683 FX_BYTE _GetCharsetFromCodePage(FX_WORD codepage) 683 uint8_t _GetCharsetFromCodePage(FX_WORD codepage)
684 { 684 {
685 FX_INT32 iEnd = sizeof(g_Codepage2CharsetTable) / sizeof(CHARSET_MAP) - 1; 685 int32_t iEnd = sizeof(g_Codepage2CharsetTable) / sizeof(CHARSET_MAP) - 1;
686 FXSYS_assert(iEnd >= 0); 686 FXSYS_assert(iEnd >= 0);
687 FX_INT32 iStart = 0, iMid; 687 int32_t iStart = 0, iMid;
688 do { 688 do {
689 iMid = (iStart + iEnd) / 2; 689 iMid = (iStart + iEnd) / 2;
690 const CHARSET_MAP & cp = g_Codepage2CharsetTable[iMid]; 690 const CHARSET_MAP & cp = g_Codepage2CharsetTable[iMid];
691 if (codepage == cp.codepage) { 691 if (codepage == cp.codepage) {
692 return cp.charset; 692 return cp.charset;
693 } else if (codepage < cp.codepage) { 693 } else if (codepage < cp.codepage) {
694 iEnd = iMid - 1; 694 iEnd = iMid - 1;
695 } else { 695 } else {
696 iStart = iMid + 1; 696 iStart = iMid + 1;
697 } 697 }
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
817 } 817 }
818 _AltFontFamily* found = (_AltFontFamily*)FXSYS_bsearch(fontName.c_str(), g_A ltFontFamilies, 818 _AltFontFamily* found = (_AltFontFamily*)FXSYS_bsearch(fontName.c_str(), g_A ltFontFamilies,
819 sizeof g_AltFontFamilies / sizeof (_AltFontFamily), sizeof (_AltFontFamily), compareFontFamilyString); 819 sizeof g_AltFontFamilies / sizeof (_AltFontFamily), sizeof (_AltFontFamily), compareFontFamilyString);
820 if (found == NULL) { 820 if (found == NULL) {
821 return fontName; 821 return fontName;
822 } 822 }
823 return found->m_pFontFamily; 823 return found->m_pFontFamily;
824 }; 824 };
825 typedef struct _FX_FontStyle { 825 typedef struct _FX_FontStyle {
826 FX_LPCSTR style; 826 FX_LPCSTR style;
827 FX_INT32 len; 827 int32_t len;
828 } FX_FontStyle; 828 } FX_FontStyle;
829 const FX_FontStyle g_FontStyles[] = { 829 const FX_FontStyle g_FontStyles[] = {
830 { "Bold", 4 }, 830 { "Bold", 4 },
831 { "Italic", 6 }, 831 { "Italic", 6 },
832 { "BoldItalic", 10 }, 832 { "BoldItalic", 10 },
833 { "Reg", 3 }, 833 { "Reg", 3 },
834 { "Regular", 7 }, 834 { "Regular", 7 },
835 }; 835 };
836 CFX_ByteString ParseStyle(FX_LPCSTR pStyle, int iLen, int iIndex) 836 CFX_ByteString ParseStyle(FX_LPCSTR pStyle, int iLen, int iIndex)
837 { 837 {
838 CFX_ByteTextBuf buf; 838 CFX_ByteTextBuf buf;
839 if (!iLen || iLen <= iIndex) { 839 if (!iLen || iLen <= iIndex) {
840 return buf.GetByteString(); 840 return buf.GetByteString();
841 } 841 }
842 while (iIndex < iLen) { 842 while (iIndex < iLen) {
843 if (pStyle[iIndex] == ',') { 843 if (pStyle[iIndex] == ',') {
844 break; 844 break;
845 } 845 }
846 buf.AppendChar(pStyle[iIndex]); 846 buf.AppendChar(pStyle[iIndex]);
847 ++iIndex; 847 ++iIndex;
848 } 848 }
849 return buf.GetByteString(); 849 return buf.GetByteString();
850 } 850 }
851 FX_INT32 GetStyleType(const CFX_ByteString &bsStyle, FX_BOOL bRevert) 851 int32_t GetStyleType(const CFX_ByteString &bsStyle, FX_BOOL bRevert)
852 { 852 {
853 FX_INT32 iLen = bsStyle.GetLength(); 853 int32_t iLen = bsStyle.GetLength();
854 if (!iLen) { 854 if (!iLen) {
855 return -1; 855 return -1;
856 } 856 }
857 int iSize = sizeof(g_FontStyles) / sizeof(FX_FontStyle); 857 int iSize = sizeof(g_FontStyles) / sizeof(FX_FontStyle);
858 const FX_FontStyle *pStyle = NULL; 858 const FX_FontStyle *pStyle = NULL;
859 for (int i = iSize - 1; i >= 0; --i) { 859 for (int i = iSize - 1; i >= 0; --i) {
860 pStyle = g_FontStyles + i; 860 pStyle = g_FontStyles + i;
861 if (!pStyle || pStyle->len > iLen) { 861 if (!pStyle || pStyle->len > iLen) {
862 continue; 862 continue;
863 } 863 }
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
961 if (!bHasComma) { 961 if (!bHasComma) {
962 find = family.ReverseFind('-'); 962 find = family.ReverseFind('-');
963 if (find >= 0) { 963 if (find >= 0) {
964 style = family.Mid(find + 1); 964 style = family.Mid(find + 1);
965 family = family.Left(find); 965 family = family.Left(find);
966 bHasHypen = TRUE; 966 bHasHypen = TRUE;
967 } 967 }
968 } 968 }
969 if (!bHasHypen) { 969 if (!bHasHypen) {
970 int nLen = family.GetLength(); 970 int nLen = family.GetLength();
971 FX_INT32 nRet = GetStyleType(family, TRUE); 971 int32_t nRet = GetStyleType(family, TRUE);
972 if (nRet > -1) { 972 if (nRet > -1) {
973 family = family.Left(nLen - g_FontStyles[nRet].len); 973 family = family.Left(nLen - g_FontStyles[nRet].len);
974 if (nRet == 0) { 974 if (nRet == 0) {
975 nStyle |= FX_FONT_STYLE_Bold; 975 nStyle |= FX_FONT_STYLE_Bold;
976 } 976 }
977 if (nRet == 1) { 977 if (nRet == 1) {
978 nStyle |= FX_FONT_STYLE_Italic; 978 nStyle |= FX_FONT_STYLE_Italic;
979 } 979 }
980 if (nRet == 2) { 980 if (nRet == 2) {
981 nStyle |= (FX_FONT_STYLE_Bold | FX_FONT_STYLE_Italic); 981 nStyle |= (FX_FONT_STYLE_Bold | FX_FONT_STYLE_Italic);
(...skipping 11 matching lines...) Expand all
993 } 993 }
994 } 994 }
995 if (!style.IsEmpty()) { 995 if (!style.IsEmpty()) {
996 int nLen = style.GetLength(); 996 int nLen = style.GetLength();
997 FX_LPCSTR pStyle = style; 997 FX_LPCSTR pStyle = style;
998 int i = 0; 998 int i = 0;
999 FX_BOOL bFirstItem = TRUE; 999 FX_BOOL bFirstItem = TRUE;
1000 CFX_ByteString buf; 1000 CFX_ByteString buf;
1001 while (i < nLen) { 1001 while (i < nLen) {
1002 buf = ParseStyle(pStyle, nLen, i); 1002 buf = ParseStyle(pStyle, nLen, i);
1003 FX_INT32 nRet = GetStyleType(buf, FALSE); 1003 int32_t nRet = GetStyleType(buf, FALSE);
1004 if ((i && !bStyleAvail) || (!i && nRet < 0)) { 1004 if ((i && !bStyleAvail) || (!i && nRet < 0)) {
1005 family = SubstName; 1005 family = SubstName;
1006 iBaseFont = 12; 1006 iBaseFont = 12;
1007 break; 1007 break;
1008 } else if (nRet >= 0) { 1008 } else if (nRet >= 0) {
1009 bStyleAvail = TRUE; 1009 bStyleAvail = TRUE;
1010 } 1010 }
1011 if (nRet == 0) { 1011 if (nRet == 0) {
1012 if (nStyle & FX_FONT_STYLE_Bold) { 1012 if (nStyle & FX_FONT_STYLE_Bold) {
1013 nStyle |= FX_FONT_STYLE_BoldBold; 1013 nStyle |= FX_FONT_STYLE_BoldBold;
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
1191 m_pFontInfo->GetFontCharset(hFont, Charset); 1191 m_pFontInfo->GetFontCharset(hFont, Charset);
1192 } 1192 }
1193 FX_DWORD ttc_size = m_pFontInfo->GetFontData(hFont, 0x74746366, NULL, 0); 1193 FX_DWORD ttc_size = m_pFontInfo->GetFontData(hFont, 0x74746366, NULL, 0);
1194 FX_DWORD font_size = m_pFontInfo->GetFontData(hFont, 0, NULL, 0); 1194 FX_DWORD font_size = m_pFontInfo->GetFontData(hFont, 0, NULL, 0);
1195 if(font_size == 0 && ttc_size == 0) { 1195 if(font_size == 0 && ttc_size == 0) {
1196 m_pFontInfo->DeleteFont(hFont); 1196 m_pFontInfo->DeleteFont(hFont);
1197 return NULL; 1197 return NULL;
1198 } 1198 }
1199 FXFT_Face face = NULL; 1199 FXFT_Face face = NULL;
1200 if (ttc_size) { 1200 if (ttc_size) {
1201 FX_BYTE temp[1024]; 1201 uint8_t temp[1024];
1202 m_pFontInfo->GetFontData(hFont, 0x74746366, temp, 1024); 1202 m_pFontInfo->GetFontData(hFont, 0x74746366, temp, 1024);
1203 FX_DWORD checksum = 0; 1203 FX_DWORD checksum = 0;
1204 for (int i = 0; i < 256; i ++) { 1204 for (int i = 0; i < 256; i ++) {
1205 checksum += ((FX_DWORD*)temp)[i]; 1205 checksum += ((FX_DWORD*)temp)[i];
1206 } 1206 }
1207 FX_LPBYTE pFontData; 1207 FX_LPBYTE pFontData;
1208 face = m_pFontMgr->GetCachedTTCFace(ttc_size, checksum, ttc_size - font_ size, pFontData); 1208 face = m_pFontMgr->GetCachedTTCFace(ttc_size, checksum, ttc_size - font_ size, pFontData);
1209 if (face == NULL) { 1209 if (face == NULL) {
1210 pFontData = FX_Alloc(FX_BYTE, ttc_size); 1210 pFontData = FX_Alloc(uint8_t, ttc_size);
1211 m_pFontInfo->GetFontData(hFont, 0x74746366, pFontData, ttc_size); 1211 m_pFontInfo->GetFontData(hFont, 0x74746366, pFontData, ttc_size);
1212 face = m_pFontMgr->AddCachedTTCFace(ttc_size, checksum, pFontData, t tc_size, 1212 face = m_pFontMgr->AddCachedTTCFace(ttc_size, checksum, pFontData, t tc_size,
1213 ttc_size - font_size); 1213 ttc_size - font_size);
1214 } 1214 }
1215 } else { 1215 } else {
1216 FX_LPBYTE pFontData; 1216 FX_LPBYTE pFontData;
1217 face = m_pFontMgr->GetCachedFace(SubstName, weight, bItalic, pFontData); 1217 face = m_pFontMgr->GetCachedFace(SubstName, weight, bItalic, pFontData);
1218 if (face == NULL) { 1218 if (face == NULL) {
1219 pFontData = FX_Alloc(FX_BYTE, font_size); 1219 pFontData = FX_Alloc(uint8_t, font_size);
1220 m_pFontInfo->GetFontData(hFont, 0, pFontData, font_size); 1220 m_pFontInfo->GetFontData(hFont, 0, pFontData, font_size);
1221 face = m_pFontMgr->AddCachedFace(SubstName, weight, bItalic, pFontDa ta, font_size, m_pFontInfo->GetFaceIndex(hFont)); 1221 face = m_pFontMgr->AddCachedFace(SubstName, weight, bItalic, pFontDa ta, font_size, m_pFontInfo->GetFaceIndex(hFont));
1222 } 1222 }
1223 } 1223 }
1224 if (face == NULL) { 1224 if (face == NULL) {
1225 m_pFontInfo->DeleteFont(hFont); 1225 m_pFontInfo->DeleteFont(hFont);
1226 return NULL; 1226 return NULL;
1227 } 1227 }
1228 pSubstFont->m_Family = SubstName; 1228 pSubstFont->m_Family = SubstName;
1229 pSubstFont->m_Charset = Charset; 1229 pSubstFont->m_Charset = Charset;
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
1350 FX_CloseFolder(handle); 1350 FX_CloseFolder(handle);
1351 } 1351 }
1352 void CFX_FolderFontInfo::ScanFile(CFX_ByteString& path) 1352 void CFX_FolderFontInfo::ScanFile(CFX_ByteString& path)
1353 { 1353 {
1354 FXSYS_FILE* pFile = FXSYS_fopen(path, "rb"); 1354 FXSYS_FILE* pFile = FXSYS_fopen(path, "rb");
1355 if (pFile == NULL) { 1355 if (pFile == NULL) {
1356 return; 1356 return;
1357 } 1357 }
1358 FXSYS_fseek(pFile, 0, FXSYS_SEEK_END); 1358 FXSYS_fseek(pFile, 0, FXSYS_SEEK_END);
1359 FX_DWORD filesize = FXSYS_ftell(pFile); 1359 FX_DWORD filesize = FXSYS_ftell(pFile);
1360 FX_BYTE buffer[16]; 1360 uint8_t buffer[16];
1361 FXSYS_fseek(pFile, 0, FXSYS_SEEK_SET); 1361 FXSYS_fseek(pFile, 0, FXSYS_SEEK_SET);
1362 size_t readCnt = FXSYS_fread(buffer, 12, 1, pFile); 1362 size_t readCnt = FXSYS_fread(buffer, 12, 1, pFile);
1363 if (readCnt != 1) { 1363 if (readCnt != 1) {
1364 FXSYS_fclose(pFile); 1364 FXSYS_fclose(pFile);
1365 return; 1365 return;
1366 } 1366 }
1367 1367
1368 if (GET_TT_LONG(buffer) == 0x74746366) { 1368 if (GET_TT_LONG(buffer) == 0x74746366) {
1369 FX_DWORD nFaces = GET_TT_LONG(buffer + 8); 1369 FX_DWORD nFaces = GET_TT_LONG(buffer + 8);
1370 if (nFaces > std::numeric_limits<FX_DWORD>::max() / 4) { 1370 if (nFaces > std::numeric_limits<FX_DWORD>::max() / 4) {
1371 FXSYS_fclose(pFile); 1371 FXSYS_fclose(pFile);
1372 return; 1372 return;
1373 } 1373 }
1374 FX_DWORD face_bytes = nFaces * 4; 1374 FX_DWORD face_bytes = nFaces * 4;
1375 FX_LPBYTE offsets = FX_Alloc(FX_BYTE, face_bytes); 1375 FX_LPBYTE offsets = FX_Alloc(uint8_t, face_bytes);
1376 readCnt = FXSYS_fread(offsets, face_bytes, 1, pFile); 1376 readCnt = FXSYS_fread(offsets, face_bytes, 1, pFile);
1377 if (readCnt != face_bytes) { 1377 if (readCnt != face_bytes) {
1378 FX_Free(offsets); 1378 FX_Free(offsets);
1379 FXSYS_fclose(pFile); 1379 FXSYS_fclose(pFile);
1380 return; 1380 return;
1381 } 1381 }
1382 for (FX_DWORD i = 0; i < nFaces; i ++) { 1382 for (FX_DWORD i = 0; i < nFaces; i ++) {
1383 FX_LPBYTE p = offsets + i * 4; 1383 FX_LPBYTE p = offsets + i * 4;
1384 ReportFace(path, pFile, filesize, GET_TT_LONG(p)); 1384 ReportFace(path, pFile, filesize, GET_TT_LONG(p));
1385 } 1385 }
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
1518 return FALSE; 1518 return FALSE;
1519 } 1519 }
1520 CFontFaceInfo* pFont = (CFontFaceInfo*)hFont; 1520 CFontFaceInfo* pFont = (CFontFaceInfo*)hFont;
1521 name = pFont->m_FaceName; 1521 name = pFont->m_FaceName;
1522 return TRUE; 1522 return TRUE;
1523 } 1523 }
1524 FX_BOOL CFX_FolderFontInfo::GetFontCharset(void* hFont, int& charset) 1524 FX_BOOL CFX_FolderFontInfo::GetFontCharset(void* hFont, int& charset)
1525 { 1525 {
1526 return FALSE; 1526 return FALSE;
1527 } 1527 }
OLDNEW
« no previous file with comments | « core/src/fxge/ge/fx_ge_font.cpp ('k') | core/src/fxge/ge/fx_ge_linux.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698