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

Side by Side Diff: core/src/fpdfapi/fpdf_font/fpdf_font_cid.cpp

Issue 1293973002: Cleanup CFX_Font a bit. (Closed) Base URL: https://pdfium.googlesource.com/pdfium@master
Patch Set: rebase Created 5 years, 4 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/fpdfapi/fpdf_font/fpdf_font.cpp ('k') | core/src/fpdfapi/fpdf_font/ttgsubtable.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 "../../../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 1101 matching lines...) Expand 10 before | Expand all | Expand 10 after
1112 void CPDF_CIDFont::GetCharBBox(FX_DWORD charcode, FX_RECT& rect, int level) { 1112 void CPDF_CIDFont::GetCharBBox(FX_DWORD charcode, FX_RECT& rect, int level) {
1113 if (charcode < 256 && m_CharBBox[charcode].Right != -1) { 1113 if (charcode < 256 && m_CharBBox[charcode].Right != -1) {
1114 rect.bottom = m_CharBBox[charcode].Bottom; 1114 rect.bottom = m_CharBBox[charcode].Bottom;
1115 rect.left = m_CharBBox[charcode].Left; 1115 rect.left = m_CharBBox[charcode].Left;
1116 rect.right = m_CharBBox[charcode].Right; 1116 rect.right = m_CharBBox[charcode].Right;
1117 rect.top = m_CharBBox[charcode].Top; 1117 rect.top = m_CharBBox[charcode].Top;
1118 return; 1118 return;
1119 } 1119 }
1120 FX_BOOL bVert = FALSE; 1120 FX_BOOL bVert = FALSE;
1121 int glyph_index = GlyphFromCharCode(charcode, &bVert); 1121 int glyph_index = GlyphFromCharCode(charcode, &bVert);
1122 if (m_Font.m_Face == NULL) { 1122 FXFT_Face face = m_Font.GetFace();
1123 rect = FX_RECT(0, 0, 0, 0); 1123 if (face) {
1124 } else {
1125 rect.left = rect.bottom = rect.right = rect.top = 0; 1124 rect.left = rect.bottom = rect.right = rect.top = 0;
1126 FXFT_Face face = m_Font.m_Face;
1127 if (FXFT_Is_Face_Tricky(face)) { 1125 if (FXFT_Is_Face_Tricky(face)) {
1128 int err = FXFT_Load_Glyph(face, glyph_index, 1126 int err = FXFT_Load_Glyph(face, glyph_index,
1129 FXFT_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH); 1127 FXFT_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH);
1130 if (!err) { 1128 if (!err) {
1131 FXFT_BBox cbox; 1129 FXFT_BBox cbox;
1132 FXFT_Glyph glyph; 1130 FXFT_Glyph glyph;
1133 err = FXFT_Get_Glyph(((FXFT_Face)face)->glyph, &glyph); 1131 err = FXFT_Get_Glyph(((FXFT_Face)face)->glyph, &glyph);
1134 if (!err) { 1132 if (!err) {
1135 FXFT_Glyph_Get_CBox(glyph, FXFT_GLYPH_BBOX_PIXELS, &cbox); 1133 FXFT_Glyph_Get_CBox(glyph, FXFT_GLYPH_BBOX_PIXELS, &cbox);
1136 int pixel_size_x = ((FXFT_Face)face)->size->metrics.x_ppem; 1134 int pixel_size_x = ((FXFT_Face)face)->size->metrics.x_ppem;
(...skipping 25 matching lines...) Expand all
1162 rect.right = TT2PDF( 1160 rect.right = TT2PDF(
1163 FXFT_Get_Glyph_HoriBearingX(face) + FXFT_Get_Glyph_Width(face), 1161 FXFT_Get_Glyph_HoriBearingX(face) + FXFT_Get_Glyph_Width(face),
1164 face); 1162 face);
1165 rect.top = TT2PDF(FXFT_Get_Glyph_HoriBearingY(face), face); 1163 rect.top = TT2PDF(FXFT_Get_Glyph_HoriBearingY(face), face);
1166 rect.top += rect.top / 64; 1164 rect.top += rect.top / 64;
1167 rect.bottom = TT2PDF( 1165 rect.bottom = TT2PDF(
1168 FXFT_Get_Glyph_HoriBearingY(face) - FXFT_Get_Glyph_Height(face), 1166 FXFT_Get_Glyph_HoriBearingY(face) - FXFT_Get_Glyph_Height(face),
1169 face); 1167 face);
1170 } 1168 }
1171 } 1169 }
1170 } else {
1171 rect = FX_RECT(0, 0, 0, 0);
1172 } 1172 }
1173 if (m_pFontFile == NULL && m_Charset == CIDSET_JAPAN1) { 1173 if (m_pFontFile == NULL && m_Charset == CIDSET_JAPAN1) {
1174 FX_WORD CID = CIDFromCharCode(charcode); 1174 FX_WORD CID = CIDFromCharCode(charcode);
1175 const uint8_t* pTransform = GetCIDTransform(CID); 1175 const uint8_t* pTransform = GetCIDTransform(CID);
1176 if (pTransform && !bVert) { 1176 if (pTransform && !bVert) {
1177 CFX_AffineMatrix matrix(_CIDTransformToFloat(pTransform[0]), 1177 CFX_AffineMatrix matrix(_CIDTransformToFloat(pTransform[0]),
1178 _CIDTransformToFloat(pTransform[1]), 1178 _CIDTransformToFloat(pTransform[1]),
1179 _CIDTransformToFloat(pTransform[2]), 1179 _CIDTransformToFloat(pTransform[2]),
1180 _CIDTransformToFloat(pTransform[3]), 1180 _CIDTransformToFloat(pTransform[3]),
1181 _CIDTransformToFloat(pTransform[4]) * 1000, 1181 _CIDTransformToFloat(pTransform[4]) * 1000,
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
1238 break; 1238 break;
1239 } 1239 }
1240 } 1240 }
1241 vx = (short)dwWidth / 2; 1241 vx = (short)dwWidth / 2;
1242 vy = (short)m_DefaultVY; 1242 vy = (short)m_DefaultVY;
1243 } 1243 }
1244 int CPDF_CIDFont::GetGlyphIndex(FX_DWORD unicode, FX_BOOL* pVertGlyph) { 1244 int CPDF_CIDFont::GetGlyphIndex(FX_DWORD unicode, FX_BOOL* pVertGlyph) {
1245 if (pVertGlyph) { 1245 if (pVertGlyph) {
1246 *pVertGlyph = FALSE; 1246 *pVertGlyph = FALSE;
1247 } 1247 }
1248 int index = FXFT_Get_Char_Index(m_Font.m_Face, unicode); 1248 FXFT_Face face = m_Font.GetFace();
1249 int index = FXFT_Get_Char_Index(face, unicode);
1249 if (unicode == 0x2502) { 1250 if (unicode == 0x2502) {
1250 return index; 1251 return index;
1251 } 1252 }
1252 if (index && IsVertWriting()) { 1253 if (index && IsVertWriting()) {
1253 if (m_pTTGSUBTable) { 1254 if (m_pTTGSUBTable) {
1254 TT_uint32_t vindex = 0; 1255 TT_uint32_t vindex = 0;
1255 m_pTTGSUBTable->GetVerticalGlyph(index, &vindex); 1256 m_pTTGSUBTable->GetVerticalGlyph(index, &vindex);
1256 if (vindex) { 1257 if (vindex) {
1257 index = vindex; 1258 index = vindex;
1258 if (pVertGlyph) { 1259 if (pVertGlyph) {
1259 *pVertGlyph = TRUE; 1260 *pVertGlyph = TRUE;
1260 } 1261 }
1261 } 1262 }
1262 return index; 1263 return index;
1263 } 1264 }
1264 if (NULL == m_Font.m_pGsubData) { 1265 if (!m_Font.GetSubData()) {
1265 unsigned long length = 0; 1266 unsigned long length = 0;
1266 int error = FXFT_Load_Sfnt_Table( 1267 int error = FXFT_Load_Sfnt_Table(face, FT_MAKE_TAG('G', 'S', 'U', 'B'), 0,
1267 m_Font.m_Face, FT_MAKE_TAG('G', 'S', 'U', 'B'), 0, NULL, &length); 1268 NULL, &length);
1268 if (!error) { 1269 if (!error) {
1269 m_Font.m_pGsubData = (unsigned char*)FX_Alloc(uint8_t, length); 1270 m_Font.SetSubData((uint8_t*)FX_Alloc(uint8_t, length));
1270 } 1271 }
1271 } 1272 }
1272 int error = 1273 int error = FXFT_Load_Sfnt_Table(face, FT_MAKE_TAG('G', 'S', 'U', 'B'), 0,
1273 FXFT_Load_Sfnt_Table(m_Font.m_Face, FT_MAKE_TAG('G', 'S', 'U', 'B'), 0, 1274 m_Font.GetSubData(), NULL);
1274 m_Font.m_pGsubData, NULL); 1275 if (!error && m_Font.GetSubData()) {
1275 if (!error && m_Font.m_pGsubData) {
1276 m_pTTGSUBTable = new CFX_CTTGSUBTable; 1276 m_pTTGSUBTable = new CFX_CTTGSUBTable;
1277 m_pTTGSUBTable->LoadGSUBTable((FT_Bytes)m_Font.m_pGsubData); 1277 m_pTTGSUBTable->LoadGSUBTable((FT_Bytes)m_Font.GetSubData());
1278 TT_uint32_t vindex = 0; 1278 TT_uint32_t vindex = 0;
1279 m_pTTGSUBTable->GetVerticalGlyph(index, &vindex); 1279 m_pTTGSUBTable->GetVerticalGlyph(index, &vindex);
1280 if (vindex) { 1280 if (vindex) {
1281 index = vindex; 1281 index = vindex;
1282 if (pVertGlyph) { 1282 if (pVertGlyph) {
1283 *pVertGlyph = TRUE; 1283 *pVertGlyph = TRUE;
1284 } 1284 }
1285 } 1285 }
1286 } 1286 }
1287 return index; 1287 return index;
(...skipping 27 matching lines...) Expand all
1315 if (cid && m_pCID2UnicodeMap && m_pCID2UnicodeMap->IsLoaded()) { 1315 if (cid && m_pCID2UnicodeMap && m_pCID2UnicodeMap->IsLoaded()) {
1316 unicode = m_pCID2UnicodeMap->UnicodeFromCID(cid); 1316 unicode = m_pCID2UnicodeMap->UnicodeFromCID(cid);
1317 } 1317 }
1318 if (unicode == 0) { 1318 if (unicode == 0) {
1319 unicode = _UnicodeFromCharCode(charcode); 1319 unicode = _UnicodeFromCharCode(charcode);
1320 } 1320 }
1321 if (unicode == 0 && !(m_Flags & PDFFONT_SYMBOLIC)) { 1321 if (unicode == 0 && !(m_Flags & PDFFONT_SYMBOLIC)) {
1322 unicode = UnicodeFromCharCode(charcode).GetAt(0); 1322 unicode = UnicodeFromCharCode(charcode).GetAt(0);
1323 } 1323 }
1324 } 1324 }
1325 FXFT_Face face = m_Font.GetFace();
1325 if (unicode == 0) { 1326 if (unicode == 0) {
1326 if (!m_bAdobeCourierStd) { 1327 if (!m_bAdobeCourierStd) {
1327 return charcode == 0 ? -1 : (int)charcode; 1328 return charcode == 0 ? -1 : (int)charcode;
1328 } 1329 }
1329 charcode += 31; 1330 charcode += 31;
1330 int index = 0, iBaseEncoding; 1331 int index = 0, iBaseEncoding;
1331 FX_BOOL bMSUnicode = FT_UseTTCharmap(m_Font.m_Face, 3, 1); 1332 FX_BOOL bMSUnicode = FT_UseTTCharmap(face, 3, 1);
1332 FX_BOOL bMacRoman = FALSE; 1333 FX_BOOL bMacRoman = FALSE;
1333 if (!bMSUnicode) { 1334 if (!bMSUnicode) {
1334 bMacRoman = FT_UseTTCharmap(m_Font.m_Face, 1, 0); 1335 bMacRoman = FT_UseTTCharmap(face, 1, 0);
1335 } 1336 }
1336 iBaseEncoding = PDFFONT_ENCODING_STANDARD; 1337 iBaseEncoding = PDFFONT_ENCODING_STANDARD;
1337 if (bMSUnicode) { 1338 if (bMSUnicode) {
1338 iBaseEncoding = PDFFONT_ENCODING_WINANSI; 1339 iBaseEncoding = PDFFONT_ENCODING_WINANSI;
1339 } else if (bMacRoman) { 1340 } else if (bMacRoman) {
1340 iBaseEncoding = PDFFONT_ENCODING_MACROMAN; 1341 iBaseEncoding = PDFFONT_ENCODING_MACROMAN;
1341 } 1342 }
1342 const FX_CHAR* name = GetAdobeCharName(iBaseEncoding, NULL, charcode); 1343 const FX_CHAR* name = GetAdobeCharName(iBaseEncoding, NULL, charcode);
1343 if (name == NULL) { 1344 if (name == NULL) {
1344 return charcode == 0 ? -1 : (int)charcode; 1345 return charcode == 0 ? -1 : (int)charcode;
1345 } 1346 }
1346 FX_WORD unicode = PDF_UnicodeFromAdobeName(name); 1347 FX_WORD unicode = PDF_UnicodeFromAdobeName(name);
1347 if (unicode) { 1348 if (unicode) {
1348 if (bMSUnicode) { 1349 if (bMSUnicode) {
1349 index = FXFT_Get_Char_Index(m_Font.m_Face, unicode); 1350 index = FXFT_Get_Char_Index(face, unicode);
1350 } else if (bMacRoman) { 1351 } else if (bMacRoman) {
1351 FX_DWORD maccode = 1352 FX_DWORD maccode =
1352 FT_CharCodeFromUnicode(FXFT_ENCODING_APPLE_ROMAN, unicode); 1353 FT_CharCodeFromUnicode(FXFT_ENCODING_APPLE_ROMAN, unicode);
1353 index = !maccode ? FXFT_Get_Name_Index(m_Font.m_Face, (char*)name) 1354 index = !maccode ? FXFT_Get_Name_Index(face, (char*)name)
1354 : FXFT_Get_Char_Index(m_Font.m_Face, maccode); 1355 : FXFT_Get_Char_Index(face, maccode);
1355 } else { 1356 } else {
1356 return FXFT_Get_Char_Index(m_Font.m_Face, unicode); 1357 return FXFT_Get_Char_Index(face, unicode);
1357 } 1358 }
1358 } else { 1359 } else {
1359 return charcode == 0 ? -1 : (int)charcode; 1360 return charcode == 0 ? -1 : (int)charcode;
1360 } 1361 }
1361 if (index == 0 || index == 0xffff) { 1362 if (index == 0 || index == 0xffff) {
1362 return charcode == 0 ? -1 : (int)charcode; 1363 return charcode == 0 ? -1 : (int)charcode;
1363 } 1364 }
1364 return index; 1365 return index;
1365 } 1366 }
1366 if (m_Charset == CIDSET_JAPAN1) { 1367 if (m_Charset == CIDSET_JAPAN1) {
1367 if (unicode == '\\') { 1368 if (unicode == '\\') {
1368 unicode = '/'; 1369 unicode = '/';
1369 } 1370 }
1370 #if _FXM_PLATFORM_ != _FXM_PLATFORM_APPLE_ 1371 #if _FXM_PLATFORM_ != _FXM_PLATFORM_APPLE_
1371 else if (unicode == 0xa5) { 1372 else if (unicode == 0xa5) {
1372 unicode = 0x5c; 1373 unicode = 0x5c;
1373 } 1374 }
1374 #endif 1375 #endif
1375 } 1376 }
1376 if (m_Font.m_Face == NULL) { 1377 if (!face)
1377 return unicode; 1378 return unicode;
1378 } 1379
1379 int err = FXFT_Select_Charmap(m_Font.m_Face, FXFT_ENCODING_UNICODE); 1380 int err = FXFT_Select_Charmap(face, FXFT_ENCODING_UNICODE);
1380 if (err != 0) { 1381 if (err != 0) {
1381 int i; 1382 int i;
1382 for (i = 0; i < FXFT_Get_Face_CharmapCount(m_Font.m_Face); i++) { 1383 for (i = 0; i < FXFT_Get_Face_CharmapCount(face); i++) {
1383 FX_DWORD ret = FT_CharCodeFromUnicode( 1384 FX_DWORD ret = FT_CharCodeFromUnicode(
1384 FXFT_Get_Charmap_Encoding(FXFT_Get_Face_Charmaps(m_Font.m_Face)[i]), 1385 FXFT_Get_Charmap_Encoding(FXFT_Get_Face_Charmaps(face)[i]),
1385 (FX_WCHAR)charcode); 1386 (FX_WCHAR)charcode);
1386 if (ret == 0) { 1387 if (ret == 0) {
1387 continue; 1388 continue;
1388 } 1389 }
1389 FXFT_Set_Charmap(m_Font.m_Face, 1390 FXFT_Set_Charmap(face, FXFT_Get_Face_Charmaps(face)[i]);
1390 FXFT_Get_Face_Charmaps(m_Font.m_Face)[i]);
1391 unicode = (FX_WCHAR)ret; 1391 unicode = (FX_WCHAR)ret;
1392 break; 1392 break;
1393 } 1393 }
1394 if (i == FXFT_Get_Face_CharmapCount(m_Font.m_Face) && i) { 1394 if (i == FXFT_Get_Face_CharmapCount(face) && i) {
1395 FXFT_Set_Charmap(m_Font.m_Face, 1395 FXFT_Set_Charmap(face, FXFT_Get_Face_Charmaps(face)[0]);
1396 FXFT_Get_Face_Charmaps(m_Font.m_Face)[0]);
1397 unicode = (FX_WCHAR)charcode; 1396 unicode = (FX_WCHAR)charcode;
1398 } 1397 }
1399 } 1398 }
1400 if (FXFT_Get_Face_Charmap(m_Font.m_Face)) { 1399 if (FXFT_Get_Face_Charmap(face)) {
1401 int index = GetGlyphIndex(unicode, pVertGlyph); 1400 int index = GetGlyphIndex(unicode, pVertGlyph);
1402 if (index == 0) { 1401 if (index == 0)
1403 return -1; 1402 return -1;
1404 }
1405 return index; 1403 return index;
1406 } 1404 }
1407 return unicode; 1405 return unicode;
1408 } 1406 }
1409 if (m_Font.m_Face == NULL) { 1407 if (!m_Font.GetFace())
1410 return -1; 1408 return -1;
1411 } 1409
1412 FX_WORD cid = CIDFromCharCode(charcode); 1410 FX_WORD cid = CIDFromCharCode(charcode);
1413 if (m_bType1) { 1411 if (m_bType1) {
1414 if (NULL == m_pCIDToGIDMap) { 1412 if (!m_pCIDToGIDMap) {
1415 return cid; 1413 return cid;
1416 } 1414 }
1417 } else { 1415 } else {
1418 if (m_pCIDToGIDMap == NULL) { 1416 if (!m_pCIDToGIDMap) {
1419 if (m_pFontFile && m_pCMap->m_pMapping == NULL) { 1417 if (m_pFontFile && !m_pCMap->m_pMapping)
1418 return cid;
1419 if (m_pCMap->m_Coding == CIDCODING_UNKNOWN ||
1420 !FXFT_Get_Face_Charmap(m_Font.GetFace())) {
1420 return cid; 1421 return cid;
1421 } 1422 }
1422 if (m_pCMap->m_Coding == CIDCODING_UNKNOWN || 1423 if (FXFT_Get_Charmap_Encoding(FXFT_Get_Face_Charmap(m_Font.GetFace())) ==
1423 FXFT_Get_Face_Charmap(m_Font.m_Face) == NULL) {
1424 return cid;
1425 }
1426 if (FXFT_Get_Charmap_Encoding(FXFT_Get_Face_Charmap(m_Font.m_Face)) ==
1427 FXFT_ENCODING_UNICODE) { 1424 FXFT_ENCODING_UNICODE) {
1428 CFX_WideString unicode_str = UnicodeFromCharCode(charcode); 1425 CFX_WideString unicode_str = UnicodeFromCharCode(charcode);
1429 if (unicode_str.IsEmpty()) { 1426 if (unicode_str.IsEmpty()) {
1430 return -1; 1427 return -1;
1431 } 1428 }
1432 charcode = unicode_str.GetAt(0); 1429 charcode = unicode_str.GetAt(0);
1433 } 1430 }
1434 return GetGlyphIndex(charcode, pVertGlyph); 1431 return GetGlyphIndex(charcode, pVertGlyph);
1435 } 1432 }
1436 } 1433 }
1437 FX_DWORD byte_pos = cid * 2; 1434 FX_DWORD byte_pos = cid * 2;
1438 if (byte_pos + 2 > m_pCIDToGIDMap->GetSize()) { 1435 if (byte_pos + 2 > m_pCIDToGIDMap->GetSize())
1439 return -1; 1436 return -1;
1440 } 1437
1441 const uint8_t* pdata = m_pCIDToGIDMap->GetData() + byte_pos; 1438 const uint8_t* pdata = m_pCIDToGIDMap->GetData() + byte_pos;
1442 return pdata[0] * 256 + pdata[1]; 1439 return pdata[0] * 256 + pdata[1];
1443 } 1440 }
1444 FX_DWORD CPDF_CIDFont::GetNextChar(const FX_CHAR* pString, 1441 FX_DWORD CPDF_CIDFont::GetNextChar(const FX_CHAR* pString,
1445 int nStrLen, 1442 int nStrLen,
1446 int& offset) const { 1443 int& offset) const {
1447 return m_pCMap->GetNextChar(pString, nStrLen, offset); 1444 return m_pCMap->GetNextChar(pString, nStrLen, offset);
1448 } 1445 }
1449 int CPDF_CIDFont::GetCharSize(FX_DWORD charcode) const { 1446 int CPDF_CIDFont::GetCharSize(FX_DWORD charcode) const {
1450 return m_pCMap->GetCharSize(charcode); 1447 return m_pCMap->GetCharSize(charcode);
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
1639 if (middlecode > CID) { 1636 if (middlecode > CID) {
1640 end = middle - 1; 1637 end = middle - 1;
1641 } else if (middlecode < CID) { 1638 } else if (middlecode < CID) {
1642 begin = middle + 1; 1639 begin = middle + 1;
1643 } else { 1640 } else {
1644 return &Japan1_VertCIDs[middle].a; 1641 return &Japan1_VertCIDs[middle].a;
1645 } 1642 }
1646 } 1643 }
1647 return NULL; 1644 return NULL;
1648 } 1645 }
OLDNEW
« no previous file with comments | « core/src/fpdfapi/fpdf_font/fpdf_font.cpp ('k') | core/src/fpdfapi/fpdf_font/ttgsubtable.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698