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 "core/src/fpdfapi/fpdf_font/font_int.h" | 7 #include "core/src/fpdfapi/fpdf_font/font_int.h" |
8 | 8 |
9 #include "core/include/fpdfapi/fpdf_module.h" | 9 #include "core/include/fpdfapi/fpdf_module.h" |
10 #include "core/include/fpdfapi/fpdf_page.h" | 10 #include "core/include/fpdfapi/fpdf_page.h" |
(...skipping 1029 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1040 | 1040 |
1041 CPDF_CIDFont::CPDF_CIDFont() | 1041 CPDF_CIDFont::CPDF_CIDFont() |
1042 : m_pCMap(nullptr), | 1042 : m_pCMap(nullptr), |
1043 m_pAllocatedCMap(nullptr), | 1043 m_pAllocatedCMap(nullptr), |
1044 m_pCID2UnicodeMap(nullptr), | 1044 m_pCID2UnicodeMap(nullptr), |
1045 m_pCIDToGIDMap(nullptr), | 1045 m_pCIDToGIDMap(nullptr), |
1046 m_bCIDIsGID(FALSE), | 1046 m_bCIDIsGID(FALSE), |
1047 m_pAnsiWidths(nullptr), | 1047 m_pAnsiWidths(nullptr), |
1048 m_bAdobeCourierStd(FALSE), | 1048 m_bAdobeCourierStd(FALSE), |
1049 m_pTTGSUBTable(nullptr) { | 1049 m_pTTGSUBTable(nullptr) { |
1050 FXSYS_memset(m_CharBBox, 0xff, 256 * sizeof(FX_SMALL_RECT)); | |
1051 } | 1050 } |
1052 | 1051 |
1053 CPDF_CIDFont::~CPDF_CIDFont() { | 1052 CPDF_CIDFont::~CPDF_CIDFont() { |
1054 if (m_pAnsiWidths) { | 1053 if (m_pAnsiWidths) { |
1055 FX_Free(m_pAnsiWidths); | 1054 FX_Free(m_pAnsiWidths); |
1056 } | 1055 } |
1057 delete m_pAllocatedCMap; | 1056 delete m_pAllocatedCMap; |
1058 delete m_pCIDToGIDMap; | 1057 delete m_pCIDToGIDMap; |
1059 delete m_pTTGSUBTable; | 1058 delete m_pTTGSUBTable; |
1060 } | 1059 } |
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1282 m_DefaultVY = pDefaultArray->GetIntegerAt(0); | 1281 m_DefaultVY = pDefaultArray->GetIntegerAt(0); |
1283 m_DefaultW1 = pDefaultArray->GetIntegerAt(1); | 1282 m_DefaultW1 = pDefaultArray->GetIntegerAt(1); |
1284 } else { | 1283 } else { |
1285 m_DefaultVY = 880; | 1284 m_DefaultVY = 880; |
1286 m_DefaultW1 = -1000; | 1285 m_DefaultW1 = -1000; |
1287 } | 1286 } |
1288 } | 1287 } |
1289 return TRUE; | 1288 return TRUE; |
1290 } | 1289 } |
1291 | 1290 |
1292 void CPDF_CIDFont::GetCharBBox(FX_DWORD charcode, FX_RECT& rect, int level) { | 1291 FX_RECT CPDF_CIDFont::GetCharBBox(FX_DWORD charcode, int level) { |
1293 if (charcode < 256 && m_CharBBox[charcode].Right != -1) { | 1292 if (charcode < 256 && m_CharBBox[charcode].Right != -1) |
1294 rect.bottom = m_CharBBox[charcode].Bottom; | 1293 return FX_RECT(m_CharBBox[charcode]); |
1295 rect.left = m_CharBBox[charcode].Left; | 1294 |
1296 rect.right = m_CharBBox[charcode].Right; | 1295 FX_RECT rect; |
1297 rect.top = m_CharBBox[charcode].Top; | |
1298 return; | |
1299 } | |
1300 FX_BOOL bVert = FALSE; | 1296 FX_BOOL bVert = FALSE; |
1301 int glyph_index = GlyphFromCharCode(charcode, &bVert); | 1297 int glyph_index = GlyphFromCharCode(charcode, &bVert); |
1302 FXFT_Face face = m_Font.GetFace(); | 1298 FXFT_Face face = m_Font.GetFace(); |
1303 if (face) { | 1299 if (face) { |
1304 rect.left = rect.bottom = rect.right = rect.top = 0; | |
1305 if (FXFT_Is_Face_Tricky(face)) { | 1300 if (FXFT_Is_Face_Tricky(face)) { |
1306 int err = FXFT_Load_Glyph(face, glyph_index, | 1301 int err = FXFT_Load_Glyph(face, glyph_index, |
1307 FXFT_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH); | 1302 FXFT_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH); |
1308 if (!err) { | 1303 if (!err) { |
1309 FXFT_BBox cbox; | 1304 FXFT_BBox cbox; |
1310 FXFT_Glyph glyph; | 1305 FXFT_Glyph glyph; |
1311 err = FXFT_Get_Glyph(((FXFT_Face)face)->glyph, &glyph); | 1306 err = FXFT_Get_Glyph(((FXFT_Face)face)->glyph, &glyph); |
1312 if (!err) { | 1307 if (!err) { |
1313 FXFT_Glyph_Get_CBox(glyph, FXFT_GLYPH_BBOX_PIXELS, &cbox); | 1308 FXFT_Glyph_Get_CBox(glyph, FXFT_GLYPH_BBOX_PIXELS, &cbox); |
1314 int pixel_size_x = ((FXFT_Face)face)->size->metrics.x_ppem; | 1309 int pixel_size_x = ((FXFT_Face)face)->size->metrics.x_ppem; |
1315 int pixel_size_y = ((FXFT_Face)face)->size->metrics.y_ppem; | 1310 int pixel_size_y = ((FXFT_Face)face)->size->metrics.y_ppem; |
1316 if (pixel_size_x == 0 || pixel_size_y == 0) { | 1311 if (pixel_size_x == 0 || pixel_size_y == 0) { |
1317 rect.left = cbox.xMin; | 1312 rect = FX_RECT(cbox.xMin, cbox.yMax, cbox.xMax, cbox.yMin); |
1318 rect.right = cbox.xMax; | |
1319 rect.top = cbox.yMax; | |
1320 rect.bottom = cbox.yMin; | |
1321 } else { | 1313 } else { |
1322 rect.left = cbox.xMin * 1000 / pixel_size_x; | 1314 rect = FX_RECT(cbox.xMin * 1000 / pixel_size_x, |
1323 rect.right = cbox.xMax * 1000 / pixel_size_x; | 1315 cbox.yMax * 1000 / pixel_size_y, |
1324 rect.top = cbox.yMax * 1000 / pixel_size_y; | 1316 cbox.xMax * 1000 / pixel_size_x, |
1325 rect.bottom = cbox.yMin * 1000 / pixel_size_y; | 1317 cbox.yMin * 1000 / pixel_size_y); |
1326 } | 1318 } |
1327 if (rect.top > FXFT_Get_Face_Ascender(face)) { | 1319 if (rect.top > FXFT_Get_Face_Ascender(face)) { |
1328 rect.top = FXFT_Get_Face_Ascender(face); | 1320 rect.top = FXFT_Get_Face_Ascender(face); |
1329 } | 1321 } |
1330 if (rect.bottom < FXFT_Get_Face_Descender(face)) { | 1322 if (rect.bottom < FXFT_Get_Face_Descender(face)) { |
1331 rect.bottom = FXFT_Get_Face_Descender(face); | 1323 rect.bottom = FXFT_Get_Face_Descender(face); |
1332 } | 1324 } |
1333 FXFT_Done_Glyph(glyph); | 1325 FXFT_Done_Glyph(glyph); |
1334 } | 1326 } |
1335 } | 1327 } |
1336 } else { | 1328 } else { |
1337 int err = FXFT_Load_Glyph(face, glyph_index, FXFT_LOAD_NO_SCALE); | 1329 int err = FXFT_Load_Glyph(face, glyph_index, FXFT_LOAD_NO_SCALE); |
1338 if (err == 0) { | 1330 if (err == 0) { |
1339 rect.left = TT2PDF(FXFT_Get_Glyph_HoriBearingX(face), face); | 1331 rect = FX_RECT(TT2PDF(FXFT_Get_Glyph_HoriBearingX(face), face), |
1340 rect.right = TT2PDF( | 1332 TT2PDF(FXFT_Get_Glyph_HoriBearingY(face), face), |
1341 FXFT_Get_Glyph_HoriBearingX(face) + FXFT_Get_Glyph_Width(face), | 1333 TT2PDF(FXFT_Get_Glyph_HoriBearingX(face) + |
1342 face); | 1334 FXFT_Get_Glyph_Width(face), |
1343 rect.top = TT2PDF(FXFT_Get_Glyph_HoriBearingY(face), face); | 1335 face), |
| 1336 TT2PDF(FXFT_Get_Glyph_HoriBearingY(face) - |
| 1337 FXFT_Get_Glyph_Height(face), |
| 1338 face)); |
1344 rect.top += rect.top / 64; | 1339 rect.top += rect.top / 64; |
1345 rect.bottom = TT2PDF( | |
1346 FXFT_Get_Glyph_HoriBearingY(face) - FXFT_Get_Glyph_Height(face), | |
1347 face); | |
1348 } | 1340 } |
1349 } | 1341 } |
1350 } else { | |
1351 rect = FX_RECT(0, 0, 0, 0); | |
1352 } | 1342 } |
1353 if (!m_pFontFile && m_Charset == CIDSET_JAPAN1) { | 1343 if (!m_pFontFile && m_Charset == CIDSET_JAPAN1) { |
1354 FX_WORD CID = CIDFromCharCode(charcode); | 1344 FX_WORD CID = CIDFromCharCode(charcode); |
1355 const uint8_t* pTransform = GetCIDTransform(CID); | 1345 const uint8_t* pTransform = GetCIDTransform(CID); |
1356 if (pTransform && !bVert) { | 1346 if (pTransform && !bVert) { |
1357 CFX_Matrix matrix(CIDTransformToFloat(pTransform[0]), | 1347 CFX_Matrix matrix(CIDTransformToFloat(pTransform[0]), |
1358 CIDTransformToFloat(pTransform[1]), | 1348 CIDTransformToFloat(pTransform[1]), |
1359 CIDTransformToFloat(pTransform[2]), | 1349 CIDTransformToFloat(pTransform[2]), |
1360 CIDTransformToFloat(pTransform[3]), | 1350 CIDTransformToFloat(pTransform[3]), |
1361 CIDTransformToFloat(pTransform[4]) * 1000, | 1351 CIDTransformToFloat(pTransform[4]) * 1000, |
1362 CIDTransformToFloat(pTransform[5]) * 1000); | 1352 CIDTransformToFloat(pTransform[5]) * 1000); |
1363 CFX_FloatRect rect_f(rect); | 1353 CFX_FloatRect rect_f(rect); |
1364 rect_f.Transform(&matrix); | 1354 rect_f.Transform(&matrix); |
1365 rect = rect_f.GetOutterRect(); | 1355 rect = rect_f.GetOutterRect(); |
1366 } | 1356 } |
1367 } | 1357 } |
1368 if (charcode < 256) { | 1358 if (charcode < 256) |
1369 m_CharBBox[charcode].Bottom = (short)rect.bottom; | 1359 m_CharBBox[charcode] = rect.ToSmallRect(); |
1370 m_CharBBox[charcode].Left = (short)rect.left; | 1360 |
1371 m_CharBBox[charcode].Right = (short)rect.right; | 1361 return rect; |
1372 m_CharBBox[charcode].Top = (short)rect.top; | |
1373 } | |
1374 } | 1362 } |
1375 int CPDF_CIDFont::GetCharWidthF(FX_DWORD charcode, int level) { | 1363 int CPDF_CIDFont::GetCharWidthF(FX_DWORD charcode, int level) { |
1376 if (m_pAnsiWidths && charcode < 0x80) { | 1364 if (m_pAnsiWidths && charcode < 0x80) { |
1377 return m_pAnsiWidths[charcode]; | 1365 return m_pAnsiWidths[charcode]; |
1378 } | 1366 } |
1379 FX_WORD cid = CIDFromCharCode(charcode); | 1367 FX_WORD cid = CIDFromCharCode(charcode); |
1380 int size = m_WidthList.GetSize(); | 1368 int size = m_WidthList.GetSize(); |
1381 FX_DWORD* list = m_WidthList.GetData(); | 1369 FX_DWORD* list = m_WidthList.GetData(); |
1382 for (int i = 0; i < size; i += 3) { | 1370 for (int i = 0; i < size; i += 3) { |
1383 if (cid >= list[i] && cid <= list[i + 1]) { | 1371 if (cid >= list[i] && cid <= list[i + 1]) { |
(...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1733 | 1721 |
1734 const uint8_t* CPDF_CIDFont::GetCIDTransform(FX_WORD CID) const { | 1722 const uint8_t* CPDF_CIDFont::GetCIDTransform(FX_WORD CID) const { |
1735 if (m_Charset != CIDSET_JAPAN1 || m_pFontFile) | 1723 if (m_Charset != CIDSET_JAPAN1 || m_pFontFile) |
1736 return nullptr; | 1724 return nullptr; |
1737 | 1725 |
1738 const struct CIDTransform* found = (const struct CIDTransform*)FXSYS_bsearch( | 1726 const struct CIDTransform* found = (const struct CIDTransform*)FXSYS_bsearch( |
1739 &CID, g_Japan1_VertCIDs, FX_ArraySize(g_Japan1_VertCIDs), | 1727 &CID, g_Japan1_VertCIDs, FX_ArraySize(g_Japan1_VertCIDs), |
1740 sizeof(g_Japan1_VertCIDs[0]), CompareCIDTransform); | 1728 sizeof(g_Japan1_VertCIDs[0]), CompareCIDTransform); |
1741 return found ? &found->a : nullptr; | 1729 return found ? &found->a : nullptr; |
1742 } | 1730 } |
OLD | NEW |