Chromium Code Reviews| 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> | 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 1389 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1400 } | 1400 } |
| 1401 if (style.Find(FX_BSTRC("Italic")) > -1 || | 1401 if (style.Find(FX_BSTRC("Italic")) > -1 || |
| 1402 style.Find(FX_BSTRC("Oblique")) > -1) { | 1402 style.Find(FX_BSTRC("Oblique")) > -1) { |
| 1403 pInfo->m_Styles |= FXFONT_ITALIC; | 1403 pInfo->m_Styles |= FXFONT_ITALIC; |
| 1404 } | 1404 } |
| 1405 if (facename.Find(FX_BSTRC("Serif")) > -1) { | 1405 if (facename.Find(FX_BSTRC("Serif")) > -1) { |
| 1406 pInfo->m_Styles |= FXFONT_SERIF; | 1406 pInfo->m_Styles |= FXFONT_SERIF; |
| 1407 } | 1407 } |
| 1408 m_FontList[facename] = pInfo; | 1408 m_FontList[facename] = pInfo; |
| 1409 } | 1409 } |
| 1410 static const struct { | |
| 1411 const FX_CHAR* m_pName; | |
| 1412 const FX_CHAR* m_pSubstName; | |
| 1413 FX_BOOL m_bBold; | |
| 1414 FX_BOOL m_bItalic; | |
| 1415 } Base14Substs[] = { | |
| 1416 {"Courier", "Courier New", FALSE, FALSE}, | |
| 1417 {"Courier-Bold", "Courier New", TRUE, FALSE}, | |
| 1418 {"Courier-BoldOblique", "Courier New", TRUE, TRUE}, | |
| 1419 {"Courier-Oblique", "Courier New", FALSE, TRUE}, | |
| 1420 {"Helvetica", "Arial", FALSE, FALSE}, | |
| 1421 {"Helvetica-Bold", "Arial", TRUE, FALSE}, | |
| 1422 {"Helvetica-BoldOblique", "Arial", TRUE, TRUE}, | |
| 1423 {"Helvetica-Oblique", "Arial", FALSE, TRUE}, | |
| 1424 {"Times-Roman", "Times New Roman", FALSE, FALSE}, | |
| 1425 {"Times-Bold", "Times New Roman", TRUE, FALSE}, | |
| 1426 {"Times-BoldItalic", "Times New Roman", TRUE, TRUE}, | |
| 1427 {"Times-Italic", "Times New Roman", FALSE, TRUE}, | |
| 1428 }; | |
| 1429 void* CFX_FolderFontInfo::GetSubstFont(const CFX_ByteString& face) { | |
| 1430 for (size_t iBaseFont = 0; iBaseFont < FX_ArraySize(Base14Substs); | |
| 1431 iBaseFont++) { | |
| 1432 if (face == Base14Substs[iBaseFont].m_pName) { | |
| 1433 return GetFont(Base14Substs[iBaseFont].m_pSubstName); | |
| 1434 } | |
| 1435 } | |
| 1436 return NULL; | |
|
Tom Sepez
2015/10/01 15:55:56
nit: prefer nullptr to NULL. We've been changing
| |
| 1437 } | |
| 1438 static FX_DWORD _GetCharset(int charset) { | |
| 1439 switch (charset) { | |
| 1440 case FXFONT_SHIFTJIS_CHARSET: | |
| 1441 return CHARSET_FLAG_SHIFTJIS; | |
| 1442 case FXFONT_GB2312_CHARSET: | |
| 1443 return CHARSET_FLAG_GB; | |
| 1444 case FXFONT_CHINESEBIG5_CHARSET: | |
| 1445 return CHARSET_FLAG_BIG5; | |
| 1446 case FXFONT_HANGEUL_CHARSET: | |
| 1447 return CHARSET_FLAG_KOREAN; | |
| 1448 case FXFONT_SYMBOL_CHARSET: | |
| 1449 return CHARSET_FLAG_SYMBOL; | |
| 1450 case FXFONT_ANSI_CHARSET: | |
| 1451 return CHARSET_FLAG_ANSI; | |
| 1452 default: | |
| 1453 break; | |
| 1454 } | |
| 1455 return 0; | |
| 1456 } | |
| 1457 static int32_t _GetSimilarValue(int weight, | |
| 1458 FX_BOOL bItalic, | |
| 1459 int pitch_family, | |
| 1460 FX_DWORD style) { | |
| 1461 int32_t iSimilarValue = 0; | |
| 1462 if ((style & FXFONT_BOLD) == (weight > 400)) { | |
| 1463 iSimilarValue += 16; | |
| 1464 } | |
| 1465 if ((style & FXFONT_ITALIC) == bItalic) { | |
| 1466 iSimilarValue += 16; | |
| 1467 } | |
| 1468 if ((style & FXFONT_SERIF) == (pitch_family & FXFONT_FF_ROMAN)) { | |
| 1469 iSimilarValue += 16; | |
| 1470 } | |
| 1471 if ((style & FXFONT_SCRIPT) == (pitch_family & FXFONT_FF_SCRIPT)) { | |
| 1472 iSimilarValue += 8; | |
| 1473 } | |
| 1474 if ((style & FXFONT_FIXED_PITCH) == (pitch_family & FXFONT_FF_FIXEDPITCH)) { | |
| 1475 iSimilarValue += 8; | |
| 1476 } | |
| 1477 return iSimilarValue; | |
| 1478 } | |
| 1479 void* CFX_FolderFontInfo::FindFont(int weight, | |
| 1480 FX_BOOL bItalic, | |
| 1481 int charset, | |
| 1482 int pitch_family, | |
| 1483 const FX_CHAR* family, | |
| 1484 FX_BOOL bMatchName) { | |
| 1485 CFX_FontFaceInfo* pFind = NULL; | |
| 1486 if (charset == FXFONT_ANSI_CHARSET && (pitch_family & FXFONT_FF_FIXEDPITCH)) { | |
| 1487 return GetFont("Courier New"); | |
| 1488 } | |
| 1489 FX_DWORD charset_flag = _GetCharset(charset); | |
| 1490 int32_t iBestSimilar = 0; | |
| 1491 for (const auto& it : m_FontList) { | |
| 1492 const CFX_ByteString& bsName = it.first; | |
| 1493 CFX_FontFaceInfo* pFont = it.second; | |
| 1494 if (!(pFont->m_Charsets & charset_flag) && | |
| 1495 charset != FXFONT_DEFAULT_CHARSET) { | |
| 1496 continue; | |
| 1497 } | |
| 1498 int32_t index = bsName.Find(family); | |
| 1499 if (bMatchName && index < 0) { | |
| 1500 continue; | |
| 1501 } | |
| 1502 int32_t iSimilarValue = | |
| 1503 _GetSimilarValue(weight, bItalic, pitch_family, pFont->m_Styles); | |
| 1504 if (iSimilarValue > iBestSimilar) { | |
| 1505 iBestSimilar = iSimilarValue; | |
| 1506 pFind = pFont; | |
| 1507 } | |
| 1508 } | |
| 1509 return pFind; | |
| 1510 } | |
| 1410 void* CFX_FolderFontInfo::MapFont(int weight, | 1511 void* CFX_FolderFontInfo::MapFont(int weight, |
| 1411 FX_BOOL bItalic, | 1512 FX_BOOL bItalic, |
| 1412 int charset, | 1513 int charset, |
| 1413 int pitch_family, | 1514 int pitch_family, |
| 1414 const FX_CHAR* family, | 1515 const FX_CHAR* family, |
| 1415 int& iExact) { | 1516 int& iExact) { |
| 1416 return NULL; | 1517 return NULL; |
| 1417 } | 1518 } |
| 1418 void* CFX_FolderFontInfo::GetFont(const FX_CHAR* face) { | 1519 void* CFX_FolderFontInfo::GetFont(const FX_CHAR* face) { |
| 1419 auto it = m_FontList.find(face); | 1520 auto it = m_FontList.find(face); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1464 if (hFont == NULL) { | 1565 if (hFont == NULL) { |
| 1465 return FALSE; | 1566 return FALSE; |
| 1466 } | 1567 } |
| 1467 CFX_FontFaceInfo* pFont = (CFX_FontFaceInfo*)hFont; | 1568 CFX_FontFaceInfo* pFont = (CFX_FontFaceInfo*)hFont; |
| 1468 name = pFont->m_FaceName; | 1569 name = pFont->m_FaceName; |
| 1469 return TRUE; | 1570 return TRUE; |
| 1470 } | 1571 } |
| 1471 FX_BOOL CFX_FolderFontInfo::GetFontCharset(void* hFont, int& charset) { | 1572 FX_BOOL CFX_FolderFontInfo::GetFontCharset(void* hFont, int& charset) { |
| 1472 return FALSE; | 1573 return FALSE; |
| 1473 } | 1574 } |
| OLD | NEW |