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

Side by Side Diff: xfa/fgas/font/fgas_stdfontmgr.cpp

Issue 2083943003: Use FXFONT defines in place of integers. (Closed) Base URL: https://pdfium.googlesource.com/pdfium@master
Patch Set: nits Created 4 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 | « xfa/fgas/font/fgas_stdfontmgr.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 PDFium Authors. All rights reserved. 1 // Copyright 2015 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 "xfa/fgas/font/fgas_stdfontmgr.h" 7 #include "xfa/fgas/font/fgas_stdfontmgr.h"
8 8
9 #include "core/fxcrt/include/fx_stream.h" 9 #include "core/fxcrt/include/fx_stream.h"
10 #include "core/fxge/include/fx_ge.h" 10 #include "core/fxge/include/fx_ge.h"
(...skipping 1145 matching lines...) Expand 10 before | Expand all | Expand 10 after
1156 } 1156 }
1157 } 1157 }
1158 } 1158 }
1159 1159
1160 void CFGAS_FontMgrImp::RegisterFace(FXFT_Face pFace, 1160 void CFGAS_FontMgrImp::RegisterFace(FXFT_Face pFace,
1161 CFX_FontDescriptors& Fonts, 1161 CFX_FontDescriptors& Fonts,
1162 const CFX_WideString* pFaceName) { 1162 const CFX_WideString* pFaceName) {
1163 if ((pFace->face_flags & FT_FACE_FLAG_SCALABLE) == 0) 1163 if ((pFace->face_flags & FT_FACE_FLAG_SCALABLE) == 0)
1164 return; 1164 return;
1165 1165
1166 CFX_FontDescriptor* pFont = new CFX_FontDescriptor; 1166 std::unique_ptr<CFX_FontDescriptor> pFont(new CFX_FontDescriptor);
1167 pFont->m_dwFontStyles |= FXFT_Is_Face_Bold(pFace) ? FX_FONTSTYLE_Bold : 0; 1167 pFont->m_dwFontStyles |= FXFT_Is_Face_Bold(pFace) ? FX_FONTSTYLE_Bold : 0;
1168 pFont->m_dwFontStyles |= FXFT_Is_Face_Italic(pFace) ? FX_FONTSTYLE_Italic : 0; 1168 pFont->m_dwFontStyles |= FXFT_Is_Face_Italic(pFace) ? FX_FONTSTYLE_Italic : 0;
1169 pFont->m_dwFontStyles |= GetFlags(pFace); 1169 pFont->m_dwFontStyles |= GetFlags(pFace);
1170 1170
1171 CFX_ArrayTemplate<uint16_t> Charsets; 1171 std::vector<uint16_t> charsets = GetCharsets(pFace);
1172 GetCharsets(pFace, Charsets);
1173 GetUSBCSB(pFace, pFont->m_dwUsb, pFont->m_dwCsb); 1172 GetUSBCSB(pFace, pFont->m_dwUsb, pFont->m_dwCsb);
1174 1173
1175 FT_ULong dwTag; 1174 FT_ULong dwTag;
1176 uint8_t* pTable = nullptr;
1177 FT_ENC_TAG(dwTag, 'n', 'a', 'm', 'e'); 1175 FT_ENC_TAG(dwTag, 'n', 'a', 'm', 'e');
1178 1176
1177 std::vector<uint8_t> table;
1179 unsigned long nLength = 0; 1178 unsigned long nLength = 0;
1180 unsigned int error = FXFT_Load_Sfnt_Table(pFace, dwTag, 0, nullptr, &nLength); 1179 unsigned int error = FXFT_Load_Sfnt_Table(pFace, dwTag, 0, nullptr, &nLength);
1181 if (error == 0 && nLength != 0) { 1180 if (error == 0 && nLength != 0) {
1182 pTable = FX_Alloc(uint8_t, nLength); 1181 table.resize(nLength);
1183 error = FXFT_Load_Sfnt_Table(pFace, dwTag, 0, pTable, nullptr); 1182 if (FXFT_Load_Sfnt_Table(pFace, dwTag, 0, table.data(), nullptr))
1184 if (0 != error) { 1183 table.clear();
1185 FX_Free(pTable);
1186 pTable = nullptr;
1187 }
1188 } 1184 }
1189 GetNames(pTable, pFont->m_wsFamilyNames); 1185 GetNames(table.empty() ? nullptr : table.data(), pFont->m_wsFamilyNames);
1190 if (pTable)
1191 FX_Free(pTable);
1192 1186
1193 pFont->m_wsFamilyNames.Add(CFX_ByteString(pFace->family_name).UTF8Decode()); 1187 pFont->m_wsFamilyNames.Add(CFX_ByteString(pFace->family_name).UTF8Decode());
1194 pFont->m_wsFaceName = 1188 pFont->m_wsFaceName =
1195 pFaceName ? *pFaceName 1189 pFaceName ? *pFaceName
1196 : CFX_WideString::FromLocal(FXFT_Get_Postscript_Name(pFace)); 1190 : CFX_WideString::FromLocal(FXFT_Get_Postscript_Name(pFace));
1197 pFont->m_nFaceIndex = pFace->face_index; 1191 pFont->m_nFaceIndex = pFace->face_index;
1198 1192
1199 Fonts.Add(pFont); 1193 Fonts.Add(pFont.release());
1200 } 1194 }
1201 1195
1202 void CFGAS_FontMgrImp::RegisterFaces(IFX_FileRead* pFontStream, 1196 void CFGAS_FontMgrImp::RegisterFaces(IFX_FileRead* pFontStream,
1203 const CFX_WideString* pFaceName) { 1197 const CFX_WideString* pFaceName) {
1204 int32_t index = 0; 1198 int32_t index = 0;
1205 int32_t num_faces = 0; 1199 int32_t num_faces = 0;
1206 do { 1200 do {
1207 FXFT_Face pFace = LoadFace(pFontStream, index++); 1201 FXFT_Face pFace = LoadFace(pFontStream, index++);
1208 if (!pFace) 1202 if (!pFace)
1209 continue; 1203 continue;
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
1339 {1 << 0, FX_CHARSET_Default}, {1 << 1, FX_CHARSET_Default}, 1333 {1 << 0, FX_CHARSET_Default}, {1 << 1, FX_CHARSET_Default},
1340 {1 << 2, FX_CHARSET_Default}, {1 << 3, FX_CHARSET_Default}, 1334 {1 << 2, FX_CHARSET_Default}, {1 << 3, FX_CHARSET_Default},
1341 {1 << 4, FX_CHARSET_Default}, {1 << 5, FX_CHARSET_Default}, 1335 {1 << 4, FX_CHARSET_Default}, {1 << 5, FX_CHARSET_Default},
1342 {1 << 6, FX_CHARSET_Default}, {1 << 7, FX_CHARSET_Default}, 1336 {1 << 6, FX_CHARSET_Default}, {1 << 7, FX_CHARSET_Default},
1343 {1 << 8, FX_CHARSET_Default}, {1 << 9, FX_CHARSET_Default}, 1337 {1 << 8, FX_CHARSET_Default}, {1 << 9, FX_CHARSET_Default},
1344 {1 << 10, FX_CHARSET_Default}, {1 << 11, FX_CHARSET_Default}, 1338 {1 << 10, FX_CHARSET_Default}, {1 << 11, FX_CHARSET_Default},
1345 {1 << 12, FX_CHARSET_Default}, {1 << 13, FX_CHARSET_Default}, 1339 {1 << 12, FX_CHARSET_Default}, {1 << 13, FX_CHARSET_Default},
1346 {1 << 14, FX_CHARSET_Default}, {1 << 15, FX_CHARSET_US}, 1340 {1 << 14, FX_CHARSET_Default}, {1 << 15, FX_CHARSET_US},
1347 }; 1341 };
1348 1342
1349 #define CODEPAGERANGE_IMPLEMENT(n) \ 1343 #define CODEPAGERANGE_IMPLEMENT(n) \
1350 for (int32_t i = 0; i < 16; i++) { \ 1344 for (int32_t i = 0; i < 16; i++) { \
1351 if ((a##n & g_FX_Bit2Charset##n[i].wBit) != 0) { \ 1345 if ((a##n & g_FX_Bit2Charset##n[i].wBit) != 0) \
1352 Charsets.Add(g_FX_Bit2Charset##n[i].wCharset); \ 1346 charsets.push_back(g_FX_Bit2Charset##n[i].wCharset); \
1353 } \
1354 } 1347 }
1355 1348
1356 void CFGAS_FontMgrImp::GetCharsets(FXFT_Face pFace, 1349 std::vector<uint16_t> CFGAS_FontMgrImp::GetCharsets(FXFT_Face pFace) const {
1357 CFX_ArrayTemplate<uint16_t>& Charsets) { 1350 std::vector<uint16_t> charsets;
1358 Charsets.RemoveAll();
1359 TT_OS2* pOS2 = (TT_OS2*)FT_Get_Sfnt_Table(pFace, ft_sfnt_os2); 1351 TT_OS2* pOS2 = (TT_OS2*)FT_Get_Sfnt_Table(pFace, ft_sfnt_os2);
1360 if (NULL != pOS2) { 1352 if (pOS2) {
1361 uint16_t a1, a2, a3, a4; 1353 uint16_t a1 = pOS2->ulCodePageRange1 & 0xffff;
1362 a1 = pOS2->ulCodePageRange1 & 0x0000ffff;
1363 CODEPAGERANGE_IMPLEMENT(1); 1354 CODEPAGERANGE_IMPLEMENT(1);
1364 a2 = (pOS2->ulCodePageRange1 >> 16) & 0x0000ffff; 1355 uint16_t a2 = (pOS2->ulCodePageRange1 >> 16) & 0xffff;
1365 CODEPAGERANGE_IMPLEMENT(2); 1356 CODEPAGERANGE_IMPLEMENT(2);
1366 a3 = pOS2->ulCodePageRange2 & 0x0000ffff; 1357 uint16_t a3 = pOS2->ulCodePageRange2 & 0xffff;
1367 CODEPAGERANGE_IMPLEMENT(3); 1358 CODEPAGERANGE_IMPLEMENT(3);
1368 a4 = (pOS2->ulCodePageRange2 >> 16) & 0x0000ffff; 1359 uint16_t a4 = (pOS2->ulCodePageRange2 >> 16) & 0xffff;
1369 CODEPAGERANGE_IMPLEMENT(4); 1360 CODEPAGERANGE_IMPLEMENT(4);
1370 } else { 1361 } else {
1371 Charsets.Add(FX_CHARSET_Default); 1362 charsets.push_back(FX_CHARSET_Default);
1372 } 1363 }
1364 return charsets;
1373 } 1365 }
1374 1366
1375 #undef CODEPAGERANGE_IMPLEMENT 1367 #undef CODEPAGERANGE_IMPLEMENT
1376 void CFGAS_FontMgrImp::GetUSBCSB(FXFT_Face pFace, 1368 void CFGAS_FontMgrImp::GetUSBCSB(FXFT_Face pFace,
1377 uint32_t* USB, 1369 uint32_t* USB,
1378 uint32_t* CSB) { 1370 uint32_t* CSB) {
1379 TT_OS2* pOS2 = (TT_OS2*)FT_Get_Sfnt_Table(pFace, ft_sfnt_os2); 1371 TT_OS2* pOS2 = (TT_OS2*)FT_Get_Sfnt_Table(pFace, ft_sfnt_os2);
1380 if (NULL != pOS2) { 1372 if (NULL != pOS2) {
1381 USB[0] = pOS2->ulUnicodeRange1; 1373 USB[0] = pOS2->ulUnicodeRange1;
1382 USB[1] = pOS2->ulUnicodeRange2; 1374 USB[1] = pOS2->ulUnicodeRange2;
(...skipping 13 matching lines...) Expand all
1396 1388
1397 int32_t CFGAS_FontMgrImp::IsPartName(const CFX_WideString& Name1, 1389 int32_t CFGAS_FontMgrImp::IsPartName(const CFX_WideString& Name1,
1398 const CFX_WideString& Name2) { 1390 const CFX_WideString& Name2) {
1399 if (Name1.Find(Name2.c_str()) != -1) { 1391 if (Name1.Find(Name2.c_str()) != -1) {
1400 return 1; 1392 return 1;
1401 } 1393 }
1402 return 0; 1394 return 0;
1403 } 1395 }
1404 1396
1405 #endif 1397 #endif
OLDNEW
« no previous file with comments | « xfa/fgas/font/fgas_stdfontmgr.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698