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 "../../../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_pageobj.h" | 9 #include "../../../include/fpdfapi/fpdf_pageobj.h" |
10 #include "../../../include/fpdfapi/fpdf_resource.h" | 10 #include "../../../include/fpdfapi/fpdf_resource.h" |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 } | 112 } |
113 CPDF_Font::~CPDF_Font() { | 113 CPDF_Font::~CPDF_Font() { |
114 delete m_pCharMap; | 114 delete m_pCharMap; |
115 m_pCharMap = NULL; | 115 m_pCharMap = NULL; |
116 | 116 |
117 delete m_pToUnicodeMap; | 117 delete m_pToUnicodeMap; |
118 m_pToUnicodeMap = NULL; | 118 m_pToUnicodeMap = NULL; |
119 | 119 |
120 if (m_pFontFile) { | 120 if (m_pFontFile) { |
121 m_pDocument->GetPageData()->ReleaseFontFileStreamAcc( | 121 m_pDocument->GetPageData()->ReleaseFontFileStreamAcc( |
122 (CPDF_Stream*)m_pFontFile->GetStream()); | 122 const_cast<CPDF_Stream*>(m_pFontFile->GetStream()->AsStream())); |
123 } | 123 } |
124 } | 124 } |
125 FX_BOOL CPDF_Font::IsVertWriting() const { | 125 FX_BOOL CPDF_Font::IsVertWriting() const { |
126 FX_BOOL bVertWriting = FALSE; | 126 FX_BOOL bVertWriting = FALSE; |
127 CPDF_CIDFont* pCIDFont = GetCIDFont(); | 127 CPDF_CIDFont* pCIDFont = GetCIDFont(); |
128 if (pCIDFont) { | 128 if (pCIDFont) { |
129 bVertWriting = pCIDFont->IsVertWriting(); | 129 bVertWriting = pCIDFont->IsVertWriting(); |
130 } else { | 130 } else { |
131 bVertWriting = m_Font.IsVertical(); | 131 bVertWriting = m_Font.IsVertical(); |
132 } | 132 } |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
268 return; | 268 return; |
269 | 269 |
270 m_pFontFile = m_pDocument->LoadFontFile(pFontFile); | 270 m_pFontFile = m_pDocument->LoadFontFile(pFontFile); |
271 if (!m_pFontFile) | 271 if (!m_pFontFile) |
272 return; | 272 return; |
273 | 273 |
274 const uint8_t* pFontData = m_pFontFile->GetData(); | 274 const uint8_t* pFontData = m_pFontFile->GetData(); |
275 FX_DWORD dwFontSize = m_pFontFile->GetSize(); | 275 FX_DWORD dwFontSize = m_pFontFile->GetSize(); |
276 if (!m_Font.LoadEmbedded(pFontData, dwFontSize)) { | 276 if (!m_Font.LoadEmbedded(pFontData, dwFontSize)) { |
277 m_pDocument->GetPageData()->ReleaseFontFileStreamAcc( | 277 m_pDocument->GetPageData()->ReleaseFontFileStreamAcc( |
278 (CPDF_Stream*)m_pFontFile->GetStream()); | 278 const_cast<CPDF_Stream*>(m_pFontFile->GetStream()->AsStream())); |
279 m_pFontFile = nullptr; | 279 m_pFontFile = nullptr; |
280 } | 280 } |
281 } | 281 } |
282 | 282 |
283 short TT2PDF(int m, FXFT_Face face) { | 283 short TT2PDF(int m, FXFT_Face face) { |
284 int upm = FXFT_Get_Face_UnitsPerEM(face); | 284 int upm = FXFT_Get_Face_UnitsPerEM(face); |
285 if (upm == 0) { | 285 if (upm == 0) { |
286 return (short)m; | 286 return (short)m; |
287 } | 287 } |
288 return (m * 1000 + upm / 2) / upm; | 288 return (m * 1000 + upm / 2) / upm; |
(...skipping 1413 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1702 } | 1702 } |
1703 } | 1703 } |
1704 } | 1704 } |
1705 } | 1705 } |
1706 return TRUE; | 1706 return TRUE; |
1707 } | 1707 } |
1708 void CPDF_Type3Font::CheckType3FontMetrics() { | 1708 void CPDF_Type3Font::CheckType3FontMetrics() { |
1709 CheckFontMetrics(); | 1709 CheckFontMetrics(); |
1710 } | 1710 } |
1711 CPDF_Type3Char* CPDF_Type3Font::LoadChar(FX_DWORD charcode, int level) { | 1711 CPDF_Type3Char* CPDF_Type3Font::LoadChar(FX_DWORD charcode, int level) { |
1712 if (level >= _FPDF_MAX_TYPE3_FORM_LEVEL_) { | 1712 if (level >= _FPDF_MAX_TYPE3_FORM_LEVEL_) |
1713 return NULL; | 1713 return nullptr; |
1714 } | 1714 |
1715 CPDF_Type3Char* pChar = NULL; | 1715 CPDF_Type3Char* pChar = nullptr; |
1716 if (m_CacheMap.Lookup((void*)(uintptr_t)charcode, (void*&)pChar)) { | 1716 if (m_CacheMap.Lookup((void*)(uintptr_t)charcode, (void*&)pChar)) { |
1717 if (pChar->m_bPageRequired && m_pPageResources) { | 1717 if (pChar->m_bPageRequired && m_pPageResources) { |
1718 delete pChar; | 1718 delete pChar; |
1719 m_CacheMap.RemoveKey((void*)(uintptr_t)charcode); | 1719 m_CacheMap.RemoveKey((void*)(uintptr_t)charcode); |
1720 return LoadChar(charcode, level + 1); | 1720 return LoadChar(charcode, level + 1); |
1721 } | 1721 } |
1722 return pChar; | 1722 return pChar; |
1723 } | 1723 } |
1724 const FX_CHAR* name = | 1724 const FX_CHAR* name = |
1725 GetAdobeCharName(m_BaseEncoding, m_pCharNames, charcode); | 1725 GetAdobeCharName(m_BaseEncoding, m_pCharNames, charcode); |
1726 if (name == NULL) { | 1726 if (!name) |
1727 return NULL; | 1727 return nullptr; |
1728 } | 1728 |
1729 CPDF_Stream* pStream = | 1729 CPDF_Stream* pStream = |
1730 (CPDF_Stream*)(m_pCharProcs ? m_pCharProcs->GetElementValue(name) : NULL); | 1730 ToStream(m_pCharProcs ? m_pCharProcs->GetElementValue(name) : nullptr); |
1731 if (pStream == NULL || pStream->GetType() != PDFOBJ_STREAM) { | 1731 if (!pStream) |
1732 return NULL; | 1732 return nullptr; |
1733 } | 1733 |
1734 pChar = new CPDF_Type3Char; | 1734 pChar = new CPDF_Type3Char; |
1735 pChar->m_pForm = new CPDF_Form( | 1735 pChar->m_pForm = new CPDF_Form( |
1736 m_pDocument, m_pFontResources ? m_pFontResources : m_pPageResources, | 1736 m_pDocument, m_pFontResources ? m_pFontResources : m_pPageResources, |
1737 pStream, NULL); | 1737 pStream, nullptr); |
1738 pChar->m_pForm->ParseContent(NULL, NULL, pChar, NULL, level + 1); | 1738 pChar->m_pForm->ParseContent(nullptr, nullptr, pChar, nullptr, level + 1); |
1739 FX_FLOAT scale = m_FontMatrix.GetXUnit(); | 1739 FX_FLOAT scale = m_FontMatrix.GetXUnit(); |
1740 pChar->m_Width = (int32_t)(pChar->m_Width * scale + 0.5f); | 1740 pChar->m_Width = (int32_t)(pChar->m_Width * scale + 0.5f); |
1741 FX_RECT& rcBBox = pChar->m_BBox; | 1741 FX_RECT& rcBBox = pChar->m_BBox; |
1742 CFX_FloatRect char_rect( | 1742 CFX_FloatRect char_rect( |
1743 (FX_FLOAT)rcBBox.left / 1000.0f, (FX_FLOAT)rcBBox.bottom / 1000.0f, | 1743 (FX_FLOAT)rcBBox.left / 1000.0f, (FX_FLOAT)rcBBox.bottom / 1000.0f, |
1744 (FX_FLOAT)rcBBox.right / 1000.0f, (FX_FLOAT)rcBBox.top / 1000.0f); | 1744 (FX_FLOAT)rcBBox.right / 1000.0f, (FX_FLOAT)rcBBox.top / 1000.0f); |
1745 if (rcBBox.right <= rcBBox.left || rcBBox.bottom >= rcBBox.top) { | 1745 if (rcBBox.right <= rcBBox.left || rcBBox.bottom >= rcBBox.top) { |
1746 char_rect = pChar->m_pForm->CalcBoundingBox(); | 1746 char_rect = pChar->m_pForm->CalcBoundingBox(); |
1747 } | 1747 } |
1748 char_rect.Transform(&m_FontMatrix); | 1748 char_rect.Transform(&m_FontMatrix); |
1749 rcBBox.left = FXSYS_round(char_rect.left * 1000); | 1749 rcBBox.left = FXSYS_round(char_rect.left * 1000); |
1750 rcBBox.right = FXSYS_round(char_rect.right * 1000); | 1750 rcBBox.right = FXSYS_round(char_rect.right * 1000); |
1751 rcBBox.top = FXSYS_round(char_rect.top * 1000); | 1751 rcBBox.top = FXSYS_round(char_rect.top * 1000); |
1752 rcBBox.bottom = FXSYS_round(char_rect.bottom * 1000); | 1752 rcBBox.bottom = FXSYS_round(char_rect.bottom * 1000); |
1753 m_CacheMap.SetAt((void*)(uintptr_t)charcode, pChar); | 1753 m_CacheMap.SetAt((void*)(uintptr_t)charcode, pChar); |
1754 if (pChar->m_pForm->CountObjects() == 0) { | 1754 if (pChar->m_pForm->CountObjects() == 0) { |
1755 delete pChar->m_pForm; | 1755 delete pChar->m_pForm; |
1756 pChar->m_pForm = NULL; | 1756 pChar->m_pForm = nullptr; |
1757 } | 1757 } |
1758 return pChar; | 1758 return pChar; |
1759 } | 1759 } |
1760 int CPDF_Type3Font::GetCharWidthF(FX_DWORD charcode, int level) { | 1760 int CPDF_Type3Font::GetCharWidthF(FX_DWORD charcode, int level) { |
1761 if (charcode > 0xff) { | 1761 if (charcode > 0xff) { |
1762 charcode = 0; | 1762 charcode = 0; |
1763 } | 1763 } |
1764 if (m_CharWidthL[charcode]) { | 1764 if (m_CharWidthL[charcode]) { |
1765 return m_CharWidthL[charcode]; | 1765 return m_CharWidthL[charcode]; |
1766 } | 1766 } |
(...skipping 14 matching lines...) Expand all Loading... |
1781 CPDF_Type3Char::CPDF_Type3Char() { | 1781 CPDF_Type3Char::CPDF_Type3Char() { |
1782 m_pForm = NULL; | 1782 m_pForm = NULL; |
1783 m_pBitmap = NULL; | 1783 m_pBitmap = NULL; |
1784 m_bPageRequired = FALSE; | 1784 m_bPageRequired = FALSE; |
1785 m_bColored = FALSE; | 1785 m_bColored = FALSE; |
1786 } | 1786 } |
1787 CPDF_Type3Char::~CPDF_Type3Char() { | 1787 CPDF_Type3Char::~CPDF_Type3Char() { |
1788 delete m_pForm; | 1788 delete m_pForm; |
1789 delete m_pBitmap; | 1789 delete m_pBitmap; |
1790 } | 1790 } |
OLD | NEW |