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

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

Issue 1821043003: Remove FX_WORD in favor of uint16_t. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Use stdint.h directly, bitfield minefield. Created 4 years, 9 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/fpdfapi/fpdf_font/font_int.h ('k') | core/fpdfapi/fpdf_font/fpdf_font_charset.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 "core/fpdfapi/fpdf_font/font_int.h" 7 #include "core/fpdfapi/fpdf_font/font_int.h"
8 8
9 #include "core/fpdfapi/fpdf_page/include/cpdf_form.h" 9 #include "core/fpdfapi/fpdf_page/include/cpdf_form.h"
10 #include "core/fpdfapi/fpdf_page/pageint.h" 10 #include "core/fpdfapi/fpdf_page/pageint.h"
(...skipping 513 matching lines...) Expand 10 before | Expand all | Expand 10 after
524 if (index >= buf_len) { 524 if (index >= buf_len) {
525 return CFX_WideString(); 525 return CFX_WideString();
526 } 526 }
527 FX_DWORD len = buf[index]; 527 FX_DWORD len = buf[index];
528 if (index + len < index || index + len >= buf_len) { 528 if (index + len < index || index + len >= buf_len) {
529 return CFX_WideString(); 529 return CFX_WideString();
530 } 530 }
531 return CFX_WideString(buf + index + 1, len); 531 return CFX_WideString(buf + index + 1, len);
532 } 532 }
533 if (m_pBaseMap) { 533 if (m_pBaseMap) {
534 return m_pBaseMap->UnicodeFromCID((FX_WORD)charcode); 534 return m_pBaseMap->UnicodeFromCID((uint16_t)charcode);
535 } 535 }
536 return CFX_WideString(); 536 return CFX_WideString();
537 } 537 }
538 538
539 FX_DWORD CPDF_ToUnicodeMap::ReverseLookup(FX_WCHAR unicode) { 539 FX_DWORD CPDF_ToUnicodeMap::ReverseLookup(FX_WCHAR unicode) {
540 for (const auto& pair : m_Map) { 540 for (const auto& pair : m_Map) {
541 if (pair.second == unicode) 541 if (pair.second == unicode)
542 return pair.first; 542 return pair.first;
543 } 543 }
544 return 0; 544 return 0;
(...skipping 554 matching lines...) Expand 10 before | Expand all | Expand 10 after
1099 bCoreText = FALSE; 1099 bCoreText = FALSE;
1100 } 1100 }
1101 } 1101 }
1102 #endif 1102 #endif
1103 if (!IsEmbedded() && (m_Base14Font < 12) && m_Font.IsTTFont()) { 1103 if (!IsEmbedded() && (m_Base14Font < 12) && m_Font.IsTTFont()) {
1104 if (FT_UseTTCharmap(m_Font.GetFace(), 3, 0)) { 1104 if (FT_UseTTCharmap(m_Font.GetFace(), 3, 0)) {
1105 FX_BOOL bGotOne = FALSE; 1105 FX_BOOL bGotOne = FALSE;
1106 for (int charcode = 0; charcode < 256; charcode++) { 1106 for (int charcode = 0; charcode < 256; charcode++) {
1107 const uint8_t prefix[4] = {0x00, 0xf0, 0xf1, 0xf2}; 1107 const uint8_t prefix[4] = {0x00, 0xf0, 0xf1, 0xf2};
1108 for (int j = 0; j < 4; j++) { 1108 for (int j = 0; j < 4; j++) {
1109 FX_WORD unicode = prefix[j] * 256 + charcode; 1109 uint16_t unicode = prefix[j] * 256 + charcode;
1110 m_GlyphIndex[charcode] = 1110 m_GlyphIndex[charcode] =
1111 FXFT_Get_Char_Index(m_Font.GetFace(), unicode); 1111 FXFT_Get_Char_Index(m_Font.GetFace(), unicode);
1112 #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ 1112 #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_
1113 FX_CHAR name_glyph[256]; 1113 FX_CHAR name_glyph[256];
1114 FXFT_Get_Glyph_Name(m_Font.GetFace(), m_GlyphIndex[charcode], 1114 FXFT_Get_Glyph_Name(m_Font.GetFace(), m_GlyphIndex[charcode],
1115 name_glyph, 256); 1115 name_glyph, 256);
1116 name_glyph[255] = 0; 1116 name_glyph[255] = 0;
1117 CFStringRef name_ct = CFStringCreateWithCStringNoCopy( 1117 CFStringRef name_ct = CFStringCreateWithCStringNoCopy(
1118 kCFAllocatorDefault, name_glyph, kCFStringEncodingASCII, 1118 kCFAllocatorDefault, name_glyph, kCFStringEncodingASCII,
1119 kCFAllocatorNull); 1119 kCFAllocatorNull);
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after
1376 1376
1377 int CPDF_FontEncoding::CharCodeFromUnicode(FX_WCHAR unicode) const { 1377 int CPDF_FontEncoding::CharCodeFromUnicode(FX_WCHAR unicode) const {
1378 for (int i = 0; i < 256; i++) 1378 for (int i = 0; i < 256; i++)
1379 if (m_Unicodes[i] == unicode) { 1379 if (m_Unicodes[i] == unicode) {
1380 return i; 1380 return i;
1381 } 1381 }
1382 return -1; 1382 return -1;
1383 } 1383 }
1384 1384
1385 CPDF_FontEncoding::CPDF_FontEncoding(int PredefinedEncoding) { 1385 CPDF_FontEncoding::CPDF_FontEncoding(int PredefinedEncoding) {
1386 const FX_WORD* pSrc = PDF_UnicodesForPredefinedCharSet(PredefinedEncoding); 1386 const uint16_t* pSrc = PDF_UnicodesForPredefinedCharSet(PredefinedEncoding);
1387 if (!pSrc) { 1387 if (!pSrc) {
1388 FXSYS_memset(m_Unicodes, 0, sizeof(m_Unicodes)); 1388 FXSYS_memset(m_Unicodes, 0, sizeof(m_Unicodes));
1389 } else { 1389 } else {
1390 for (int i = 0; i < 256; i++) 1390 for (int i = 0; i < 256; i++)
1391 m_Unicodes[i] = pSrc[i]; 1391 m_Unicodes[i] = pSrc[i];
1392 } 1392 }
1393 } 1393 }
1394 1394
1395 FX_BOOL CPDF_FontEncoding::IsIdentical(CPDF_FontEncoding* pAnother) const { 1395 FX_BOOL CPDF_FontEncoding::IsIdentical(CPDF_FontEncoding* pAnother) const {
1396 return FXSYS_memcmp(m_Unicodes, pAnother->m_Unicodes, sizeof(m_Unicodes)) == 1396 return FXSYS_memcmp(m_Unicodes, pAnother->m_Unicodes, sizeof(m_Unicodes)) ==
1397 0; 1397 0;
1398 } 1398 }
1399 1399
1400 CPDF_Object* CPDF_FontEncoding::Realize() { 1400 CPDF_Object* CPDF_FontEncoding::Realize() {
1401 int predefined = 0; 1401 int predefined = 0;
1402 for (int cs = PDFFONT_ENCODING_WINANSI; cs < PDFFONT_ENCODING_ZAPFDINGBATS; 1402 for (int cs = PDFFONT_ENCODING_WINANSI; cs < PDFFONT_ENCODING_ZAPFDINGBATS;
1403 cs++) { 1403 cs++) {
1404 const FX_WORD* pSrc = PDF_UnicodesForPredefinedCharSet(cs); 1404 const uint16_t* pSrc = PDF_UnicodesForPredefinedCharSet(cs);
1405 FX_BOOL match = TRUE; 1405 FX_BOOL match = TRUE;
1406 for (int i = 0; i < 256; ++i) { 1406 for (int i = 0; i < 256; ++i) {
1407 if (m_Unicodes[i] != pSrc[i]) { 1407 if (m_Unicodes[i] != pSrc[i]) {
1408 match = FALSE; 1408 match = FALSE;
1409 break; 1409 break;
1410 } 1410 }
1411 } 1411 }
1412 if (match) { 1412 if (match) {
1413 predefined = cs; 1413 predefined = cs;
1414 break; 1414 break;
1415 } 1415 }
1416 } 1416 }
1417 if (predefined) { 1417 if (predefined) {
1418 if (predefined == PDFFONT_ENCODING_WINANSI) { 1418 if (predefined == PDFFONT_ENCODING_WINANSI) {
1419 return new CPDF_Name("WinAnsiEncoding"); 1419 return new CPDF_Name("WinAnsiEncoding");
1420 } 1420 }
1421 if (predefined == PDFFONT_ENCODING_MACROMAN) { 1421 if (predefined == PDFFONT_ENCODING_MACROMAN) {
1422 return new CPDF_Name("MacRomanEncoding"); 1422 return new CPDF_Name("MacRomanEncoding");
1423 } 1423 }
1424 if (predefined == PDFFONT_ENCODING_MACEXPERT) { 1424 if (predefined == PDFFONT_ENCODING_MACEXPERT) {
1425 return new CPDF_Name("MacExpertEncoding"); 1425 return new CPDF_Name("MacExpertEncoding");
1426 } 1426 }
1427 return NULL; 1427 return NULL;
1428 } 1428 }
1429 const FX_WORD* pStandard = 1429 const uint16_t* pStandard =
1430 PDF_UnicodesForPredefinedCharSet(PDFFONT_ENCODING_WINANSI); 1430 PDF_UnicodesForPredefinedCharSet(PDFFONT_ENCODING_WINANSI);
1431 CPDF_Array* pDiff = new CPDF_Array; 1431 CPDF_Array* pDiff = new CPDF_Array;
1432 for (int i = 0; i < 256; i++) { 1432 for (int i = 0; i < 256; i++) {
1433 if (pStandard[i] == m_Unicodes[i]) { 1433 if (pStandard[i] == m_Unicodes[i]) {
1434 continue; 1434 continue;
1435 } 1435 }
1436 pDiff->Add(new CPDF_Number(i)); 1436 pDiff->Add(new CPDF_Number(i));
1437 pDiff->Add(new CPDF_Name(PDF_AdobeNameFromUnicode(m_Unicodes[i]))); 1437 pDiff->Add(new CPDF_Name(PDF_AdobeNameFromUnicode(m_Unicodes[i])));
1438 } 1438 }
1439 1439
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
1496 if (!FXFT_Has_Glyph_Names(m_Font.GetFace()) && 1496 if (!FXFT_Has_Glyph_Names(m_Font.GetFace()) &&
1497 (!m_Font.GetFace()->num_charmaps || !m_Font.GetFace()->charmaps)) { 1497 (!m_Font.GetFace()->num_charmaps || !m_Font.GetFace()->charmaps)) {
1498 int nStartChar = m_pFontDict->GetIntegerBy("FirstChar"); 1498 int nStartChar = m_pFontDict->GetIntegerBy("FirstChar");
1499 if (nStartChar < 0 || nStartChar > 255) 1499 if (nStartChar < 0 || nStartChar > 255)
1500 return; 1500 return;
1501 1501
1502 int charcode = 0; 1502 int charcode = 0;
1503 for (; charcode < nStartChar; charcode++) { 1503 for (; charcode < nStartChar; charcode++) {
1504 m_GlyphIndex[charcode] = 0; 1504 m_GlyphIndex[charcode] = 0;
1505 } 1505 }
1506 FX_WORD nGlyph = charcode - nStartChar + 3; 1506 uint16_t nGlyph = charcode - nStartChar + 3;
1507 for (; charcode < 256; charcode++, nGlyph++) { 1507 for (; charcode < 256; charcode++, nGlyph++) {
1508 m_GlyphIndex[charcode] = nGlyph; 1508 m_GlyphIndex[charcode] = nGlyph;
1509 } 1509 }
1510 return; 1510 return;
1511 } 1511 }
1512 FX_BOOL bMSUnicode = FT_UseTTCharmap(m_Font.GetFace(), 3, 1); 1512 FX_BOOL bMSUnicode = FT_UseTTCharmap(m_Font.GetFace(), 3, 1);
1513 FX_BOOL bMacRoman = FALSE, bMSSymbol = FALSE; 1513 FX_BOOL bMacRoman = FALSE, bMSSymbol = FALSE;
1514 if (!bMSUnicode) { 1514 if (!bMSUnicode) {
1515 if (m_Flags & PDFFONT_NONSYMBOLIC) { 1515 if (m_Flags & PDFFONT_NONSYMBOLIC) {
1516 bMacRoman = FT_UseTTCharmap(m_Font.GetFace(), 1, 0); 1516 bMacRoman = FT_UseTTCharmap(m_Font.GetFace(), 1, 0);
1517 bMSSymbol = !bMacRoman && FT_UseTTCharmap(m_Font.GetFace(), 3, 0); 1517 bMSSymbol = !bMacRoman && FT_UseTTCharmap(m_Font.GetFace(), 3, 0);
1518 } else { 1518 } else {
1519 bMSSymbol = FT_UseTTCharmap(m_Font.GetFace(), 3, 0); 1519 bMSSymbol = FT_UseTTCharmap(m_Font.GetFace(), 3, 0);
1520 bMacRoman = !bMSSymbol && FT_UseTTCharmap(m_Font.GetFace(), 1, 0); 1520 bMacRoman = !bMSSymbol && FT_UseTTCharmap(m_Font.GetFace(), 1, 0);
1521 } 1521 }
1522 } 1522 }
1523 FX_BOOL bToUnicode = m_pFontDict->KeyExist("ToUnicode"); 1523 FX_BOOL bToUnicode = m_pFontDict->KeyExist("ToUnicode");
1524 for (int charcode = 0; charcode < 256; charcode++) { 1524 for (int charcode = 0; charcode < 256; charcode++) {
1525 const FX_CHAR* name = 1525 const FX_CHAR* name =
1526 GetAdobeCharName(baseEncoding, m_pCharNames, charcode); 1526 GetAdobeCharName(baseEncoding, m_pCharNames, charcode);
1527 if (!name) { 1527 if (!name) {
1528 m_GlyphIndex[charcode] = 1528 m_GlyphIndex[charcode] =
1529 m_pFontFile ? FXFT_Get_Char_Index(m_Font.GetFace(), charcode) : -1; 1529 m_pFontFile ? FXFT_Get_Char_Index(m_Font.GetFace(), charcode) : -1;
1530 continue; 1530 continue;
1531 } 1531 }
1532 m_Encoding.m_Unicodes[charcode] = PDF_UnicodeFromAdobeName(name); 1532 m_Encoding.m_Unicodes[charcode] = PDF_UnicodeFromAdobeName(name);
1533 if (bMSSymbol) { 1533 if (bMSSymbol) {
1534 const uint8_t prefix[4] = {0x00, 0xf0, 0xf1, 0xf2}; 1534 const uint8_t prefix[4] = {0x00, 0xf0, 0xf1, 0xf2};
1535 for (int j = 0; j < 4; j++) { 1535 for (int j = 0; j < 4; j++) {
1536 FX_WORD unicode = prefix[j] * 256 + charcode; 1536 uint16_t unicode = prefix[j] * 256 + charcode;
1537 m_GlyphIndex[charcode] = 1537 m_GlyphIndex[charcode] =
1538 FXFT_Get_Char_Index(m_Font.GetFace(), unicode); 1538 FXFT_Get_Char_Index(m_Font.GetFace(), unicode);
1539 if (m_GlyphIndex[charcode]) { 1539 if (m_GlyphIndex[charcode]) {
1540 break; 1540 break;
1541 } 1541 }
1542 } 1542 }
1543 } else if (m_Encoding.m_Unicodes[charcode]) { 1543 } else if (m_Encoding.m_Unicodes[charcode]) {
1544 if (bMSUnicode) { 1544 if (bMSUnicode) {
1545 m_GlyphIndex[charcode] = FXFT_Get_Char_Index( 1545 m_GlyphIndex[charcode] = FXFT_Get_Char_Index(
1546 m_Font.GetFace(), m_Encoding.m_Unicodes[charcode]); 1546 m_Font.GetFace(), m_Encoding.m_Unicodes[charcode]);
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
1580 } 1580 }
1581 } 1581 }
1582 } 1582 }
1583 return; 1583 return;
1584 } 1584 }
1585 if (FT_UseTTCharmap(m_Font.GetFace(), 3, 0)) { 1585 if (FT_UseTTCharmap(m_Font.GetFace(), 3, 0)) {
1586 const uint8_t prefix[4] = {0x00, 0xf0, 0xf1, 0xf2}; 1586 const uint8_t prefix[4] = {0x00, 0xf0, 0xf1, 0xf2};
1587 FX_BOOL bGotOne = FALSE; 1587 FX_BOOL bGotOne = FALSE;
1588 for (int charcode = 0; charcode < 256; charcode++) { 1588 for (int charcode = 0; charcode < 256; charcode++) {
1589 for (int j = 0; j < 4; j++) { 1589 for (int j = 0; j < 4; j++) {
1590 FX_WORD unicode = prefix[j] * 256 + charcode; 1590 uint16_t unicode = prefix[j] * 256 + charcode;
1591 m_GlyphIndex[charcode] = FXFT_Get_Char_Index(m_Font.GetFace(), unicode); 1591 m_GlyphIndex[charcode] = FXFT_Get_Char_Index(m_Font.GetFace(), unicode);
1592 if (m_GlyphIndex[charcode]) { 1592 if (m_GlyphIndex[charcode]) {
1593 bGotOne = TRUE; 1593 bGotOne = TRUE;
1594 break; 1594 break;
1595 } 1595 }
1596 } 1596 }
1597 } 1597 }
1598 if (bGotOne) { 1598 if (bGotOne) {
1599 if (baseEncoding != PDFFONT_ENCODING_BUILTIN) { 1599 if (baseEncoding != PDFFONT_ENCODING_BUILTIN) {
1600 for (int charcode = 0; charcode < 256; charcode++) { 1600 for (int charcode = 0; charcode < 256; charcode++) {
(...skipping 22 matching lines...) Expand all
1623 if (m_GlyphIndex[charcode]) { 1623 if (m_GlyphIndex[charcode]) {
1624 bGotOne = TRUE; 1624 bGotOne = TRUE;
1625 } 1625 }
1626 } 1626 }
1627 if (m_pFontFile || bGotOne) { 1627 if (m_pFontFile || bGotOne) {
1628 return; 1628 return;
1629 } 1629 }
1630 } 1630 }
1631 if (FXFT_Select_Charmap(m_Font.GetFace(), FXFT_ENCODING_UNICODE) == 0) { 1631 if (FXFT_Select_Charmap(m_Font.GetFace(), FXFT_ENCODING_UNICODE) == 0) {
1632 FX_BOOL bGotOne = FALSE; 1632 FX_BOOL bGotOne = FALSE;
1633 const FX_WORD* pUnicodes = PDF_UnicodesForPredefinedCharSet(baseEncoding); 1633 const uint16_t* pUnicodes = PDF_UnicodesForPredefinedCharSet(baseEncoding);
1634 for (int charcode = 0; charcode < 256; charcode++) { 1634 for (int charcode = 0; charcode < 256; charcode++) {
1635 if (m_pFontFile) { 1635 if (m_pFontFile) {
1636 m_Encoding.m_Unicodes[charcode] = charcode; 1636 m_Encoding.m_Unicodes[charcode] = charcode;
1637 } else { 1637 } else {
1638 const FX_CHAR* name = GetAdobeCharName(0, m_pCharNames, charcode); 1638 const FX_CHAR* name = GetAdobeCharName(0, m_pCharNames, charcode);
1639 if (name) { 1639 if (name) {
1640 m_Encoding.m_Unicodes[charcode] = PDF_UnicodeFromAdobeName(name); 1640 m_Encoding.m_Unicodes[charcode] = PDF_UnicodeFromAdobeName(name);
1641 } else if (pUnicodes) { 1641 } else if (pUnicodes) {
1642 m_Encoding.m_Unicodes[charcode] = pUnicodes[charcode]; 1642 m_Encoding.m_Unicodes[charcode] = pUnicodes[charcode];
1643 } 1643 }
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
1804 return pChar ? pChar->m_BBox : FX_RECT(); 1804 return pChar ? pChar->m_BBox : FX_RECT();
1805 } 1805 }
1806 1806
1807 CPDF_Type3Char::CPDF_Type3Char(CPDF_Form* pForm) 1807 CPDF_Type3Char::CPDF_Type3Char(CPDF_Form* pForm)
1808 : m_pForm(pForm), m_pBitmap(nullptr), m_bColored(FALSE) {} 1808 : m_pForm(pForm), m_pBitmap(nullptr), m_bColored(FALSE) {}
1809 1809
1810 CPDF_Type3Char::~CPDF_Type3Char() { 1810 CPDF_Type3Char::~CPDF_Type3Char() {
1811 delete m_pForm; 1811 delete m_pForm;
1812 delete m_pBitmap; 1812 delete m_pBitmap;
1813 } 1813 }
OLDNEW
« no previous file with comments | « core/fpdfapi/fpdf_font/font_int.h ('k') | core/fpdfapi/fpdf_font/fpdf_font_charset.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698