| 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/fxge/fx_ge.h" | 7 #include "../../../include/fxge/fx_ge.h" |
| 8 #include "../../../include/fxge/fx_freetype.h" | 8 #include "../../../include/fxge/fx_freetype.h" |
| 9 #include "../../../include/fxcodec/fx_codec.h" | 9 #include "../../../include/fxcodec/fx_codec.h" |
| 10 #include "text_int.h" | 10 #include "text_int.h" |
| 11 #undef FX_GAMMA | 11 #undef FX_GAMMA |
| 12 #undef FX_GAMMA_INVERSE | 12 #undef FX_GAMMA_INVERSE |
| 13 #define FX_GAMMA(value) (value) | 13 #define FX_GAMMA(value) (value) |
| 14 #define FX_GAMMA_INVERSE(value) (value) | 14 #define FX_GAMMA_INVERSE(value) (value) |
| 15 #ifndef PDF_ENABLE_XFA |
| 15 | 16 |
| 16 namespace { | 17 namespace { |
| 17 | 18 |
| 18 void ResetTransform(FT_Face face) { | 19 void ResetTransform(FT_Face face) { |
| 19 FXFT_Matrix matrix; | 20 FXFT_Matrix matrix; |
| 20 matrix.xx = 0x10000L; | 21 matrix.xx = 0x10000L; |
| 21 matrix.xy = 0; | 22 matrix.xy = 0; |
| 22 matrix.yx = 0; | 23 matrix.yx = 0; |
| 23 matrix.yy = 0x10000L; | 24 matrix.yy = 0x10000L; |
| 24 FXFT_Set_Transform(face, &matrix, 0); | 25 FXFT_Set_Transform(face, &matrix, 0); |
| 25 } | 26 } |
| 26 | 27 |
| 27 // Sets the given transform on the font, and resets it to the identity when it | 28 // Sets the given transform on the font, and resets it to the identity when it |
| 28 // goes out of scope. | 29 // goes out of scope. |
| 29 class ScopedFontTransform { | 30 class ScopedFontTransform { |
| 30 public: | 31 public: |
| 31 ScopedFontTransform(FT_Face face, FXFT_Matrix* matrix) : m_Face(face) { | 32 ScopedFontTransform(FT_Face face, FXFT_Matrix* matrix) : m_Face(face) { |
| 32 FXFT_Set_Transform(m_Face, matrix, 0); | 33 FXFT_Set_Transform(m_Face, matrix, 0); |
| 33 } | 34 } |
| 34 | 35 |
| 35 ~ScopedFontTransform() { ResetTransform(m_Face); } | 36 ~ScopedFontTransform() { ResetTransform(m_Face); } |
| 36 | 37 |
| 37 private: | 38 private: |
| 38 FT_Face m_Face; | 39 FT_Face m_Face; |
| 39 }; | 40 }; |
| 40 } | 41 } |
| 41 | 42 |
| 43 #endif |
| 42 FX_RECT FXGE_GetGlyphsBBox(FXTEXT_GLYPHPOS* pGlyphAndPos, | 44 FX_RECT FXGE_GetGlyphsBBox(FXTEXT_GLYPHPOS* pGlyphAndPos, |
| 43 int nChars, | 45 int nChars, |
| 44 int anti_alias, | 46 int anti_alias, |
| 45 FX_FLOAT retinaScaleX, | 47 FX_FLOAT retinaScaleX, |
| 46 FX_FLOAT retinaScaleY) { | 48 FX_FLOAT retinaScaleY) { |
| 47 FX_RECT rect(0, 0, 0, 0); | 49 FX_RECT rect(0, 0, 0, 0); |
| 48 FX_BOOL bStarted = FALSE; | 50 FX_BOOL bStarted = FALSE; |
| 49 for (int iChar = 0; iChar < nChars; iChar++) { | 51 for (int iChar = 0; iChar < nChars; iChar++) { |
| 50 FXTEXT_GLYPHPOS& glyph = pGlyphAndPos[iChar]; | 52 FXTEXT_GLYPHPOS& glyph = pGlyphAndPos[iChar]; |
| 51 const CFX_GlyphBitmap* pGlyph = glyph.m_pGlyph; | 53 const CFX_GlyphBitmap* pGlyph = glyph.m_pGlyph; |
| (...skipping 1121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1173 const FX_BOOL bExternal = internal_face == nullptr; | 1175 const FX_BOOL bExternal = internal_face == nullptr; |
| 1174 FXFT_Face face = | 1176 FXFT_Face face = |
| 1175 bExternal ? (FXFT_Face)pFont->GetSubstFont()->m_ExtHandle : internal_face; | 1177 bExternal ? (FXFT_Face)pFont->GetSubstFont()->m_ExtHandle : internal_face; |
| 1176 CFX_FTCacheMap& map = bExternal ? m_ExtFaceMap : m_FTFaceMap; | 1178 CFX_FTCacheMap& map = bExternal ? m_ExtFaceMap : m_FTFaceMap; |
| 1177 auto it = map.find(face); | 1179 auto it = map.find(face); |
| 1178 if (it != map.end()) { | 1180 if (it != map.end()) { |
| 1179 CFX_CountedFaceCache* counted_face_cache = it->second; | 1181 CFX_CountedFaceCache* counted_face_cache = it->second; |
| 1180 counted_face_cache->m_nCount++; | 1182 counted_face_cache->m_nCount++; |
| 1181 return counted_face_cache->m_Obj; | 1183 return counted_face_cache->m_Obj; |
| 1182 } | 1184 } |
| 1185 #ifndef PDF_ENABLE_XFA |
| 1183 | 1186 |
| 1187 #endif |
| 1184 CFX_FaceCache* face_cache = new CFX_FaceCache(bExternal ? nullptr : face); | 1188 CFX_FaceCache* face_cache = new CFX_FaceCache(bExternal ? nullptr : face); |
| 1185 CFX_CountedFaceCache* counted_face_cache = new CFX_CountedFaceCache; | 1189 CFX_CountedFaceCache* counted_face_cache = new CFX_CountedFaceCache; |
| 1186 counted_face_cache->m_nCount = 2; | 1190 counted_face_cache->m_nCount = 2; |
| 1187 counted_face_cache->m_Obj = face_cache; | 1191 counted_face_cache->m_Obj = face_cache; |
| 1188 map[face] = counted_face_cache; | 1192 map[face] = counted_face_cache; |
| 1189 return face_cache; | 1193 return face_cache; |
| 1190 } | 1194 } |
| 1191 | 1195 |
| 1192 void CFX_FontCache::ReleaseCachedFace(CFX_Font* pFont) { | 1196 void CFX_FontCache::ReleaseCachedFace(CFX_Font* pFont) { |
| 1193 FXFT_Face internal_face = pFont->GetFace(); | 1197 FXFT_Face internal_face = pFont->GetFace(); |
| (...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1543 ft_matrix.yx += ft_matrix.yy * skew / 100; | 1547 ft_matrix.yx += ft_matrix.yy * skew / 100; |
| 1544 } else { | 1548 } else { |
| 1545 ft_matrix.xy += -ft_matrix.xx * skew / 100; | 1549 ft_matrix.xy += -ft_matrix.xx * skew / 100; |
| 1546 } | 1550 } |
| 1547 } | 1551 } |
| 1548 if (pSubstFont->m_SubstFlags & FXFONT_SUBST_MM) { | 1552 if (pSubstFont->m_SubstFlags & FXFONT_SUBST_MM) { |
| 1549 pFont->AdjustMMParams(glyph_index, dest_width, | 1553 pFont->AdjustMMParams(glyph_index, dest_width, |
| 1550 pFont->GetSubstFont()->m_Weight); | 1554 pFont->GetSubstFont()->m_Weight); |
| 1551 } | 1555 } |
| 1552 } | 1556 } |
| 1557 #ifndef PDF_ENABLE_XFA |
| 1553 ScopedFontTransform scoped_transform(m_Face, &ft_matrix); | 1558 ScopedFontTransform scoped_transform(m_Face, &ft_matrix); |
| 1559 #else |
| 1560 FXFT_Set_Transform(m_Face, &ft_matrix, 0); |
| 1561 #endif |
| 1554 int load_flags = (m_Face->face_flags & FT_FACE_FLAG_SFNT) | 1562 int load_flags = (m_Face->face_flags & FT_FACE_FLAG_SFNT) |
| 1555 ? FXFT_LOAD_NO_BITMAP | 1563 ? FXFT_LOAD_NO_BITMAP |
| 1556 : (FXFT_LOAD_NO_BITMAP | FT_LOAD_NO_HINTING); | 1564 : (FXFT_LOAD_NO_BITMAP | FT_LOAD_NO_HINTING); |
| 1557 int error = FXFT_Load_Glyph(m_Face, glyph_index, load_flags); | 1565 int error = FXFT_Load_Glyph(m_Face, glyph_index, load_flags); |
| 1558 if (error) { | 1566 if (error) { |
| 1559 // if an error is returned, try to reload glyphs without hinting. | 1567 // if an error is returned, try to reload glyphs without hinting. |
| 1560 if (load_flags & FT_LOAD_NO_HINTING || load_flags & FT_LOAD_NO_SCALE) { | 1568 if (load_flags & FT_LOAD_NO_HINTING || load_flags & FT_LOAD_NO_SCALE) { |
| 1561 return NULL; | 1569 return NULL; |
| 1562 } | 1570 } |
| 1563 | 1571 |
| (...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1810 if (m_bVertical) { | 1818 if (m_bVertical) { |
| 1811 ft_matrix.yx += ft_matrix.yy * skew / 100; | 1819 ft_matrix.yx += ft_matrix.yy * skew / 100; |
| 1812 } else { | 1820 } else { |
| 1813 ft_matrix.xy += -ft_matrix.xx * skew / 100; | 1821 ft_matrix.xy += -ft_matrix.xx * skew / 100; |
| 1814 } | 1822 } |
| 1815 } | 1823 } |
| 1816 if (m_pSubstFont->m_SubstFlags & FXFONT_SUBST_MM) { | 1824 if (m_pSubstFont->m_SubstFlags & FXFONT_SUBST_MM) { |
| 1817 AdjustMMParams(glyph_index, dest_width, m_pSubstFont->m_Weight); | 1825 AdjustMMParams(glyph_index, dest_width, m_pSubstFont->m_Weight); |
| 1818 } | 1826 } |
| 1819 } | 1827 } |
| 1828 #ifndef PDF_ENABLE_XFA |
| 1820 ScopedFontTransform scoped_transform(m_Face, &ft_matrix); | 1829 ScopedFontTransform scoped_transform(m_Face, &ft_matrix); |
| 1830 #else |
| 1831 FXFT_Set_Transform(m_Face, &ft_matrix, 0); |
| 1832 #endif |
| 1821 int load_flags = FXFT_LOAD_NO_BITMAP; | 1833 int load_flags = FXFT_LOAD_NO_BITMAP; |
| 1822 if (!(m_Face->face_flags & FT_FACE_FLAG_SFNT) || !FT_IS_TRICKY(m_Face)) { | 1834 if (!(m_Face->face_flags & FT_FACE_FLAG_SFNT) || !FT_IS_TRICKY(m_Face)) { |
| 1823 load_flags |= FT_LOAD_NO_HINTING; | 1835 load_flags |= FT_LOAD_NO_HINTING; |
| 1824 } | 1836 } |
| 1825 int error = FXFT_Load_Glyph(m_Face, glyph_index, load_flags); | 1837 int error = FXFT_Load_Glyph(m_Face, glyph_index, load_flags); |
| 1826 if (error) { | 1838 if (error) { |
| 1827 return NULL; | 1839 return NULL; |
| 1828 } | 1840 } |
| 1829 if (m_pSubstFont && !(m_pSubstFont->m_SubstFlags & FXFONT_SUBST_MM) && | 1841 if (m_pSubstFont && !(m_pSubstFont->m_SubstFlags & FXFONT_SUBST_MM) && |
| 1830 m_pSubstFont->m_Weight > 400) { | 1842 m_pSubstFont->m_Weight > 400) { |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1871 void _CFX_UniqueKeyGen::Generate(int count, ...) { | 1883 void _CFX_UniqueKeyGen::Generate(int count, ...) { |
| 1872 va_list argList; | 1884 va_list argList; |
| 1873 va_start(argList, count); | 1885 va_start(argList, count); |
| 1874 for (int i = 0; i < count; i++) { | 1886 for (int i = 0; i < count; i++) { |
| 1875 int p = va_arg(argList, int); | 1887 int p = va_arg(argList, int); |
| 1876 ((FX_DWORD*)m_Key)[i] = p; | 1888 ((FX_DWORD*)m_Key)[i] = p; |
| 1877 } | 1889 } |
| 1878 va_end(argList); | 1890 va_end(argList); |
| 1879 m_KeyLen = count * sizeof(FX_DWORD); | 1891 m_KeyLen = count * sizeof(FX_DWORD); |
| 1880 } | 1892 } |
| OLD | NEW |