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/include/fxge/fx_ge.h" | 7 #include "core/include/fxge/fx_ge.h" |
8 #include "core/include/fxge/fx_freetype.h" | 8 #include "core/include/fxge/fx_freetype.h" |
9 #include "core/include/fxcodec/fx_codec.h" | 9 #include "core/include/fxcodec/fx_codec.h" |
10 #include "text_int.h" | 10 #include "text_int.h" |
11 | 11 |
12 #undef FX_GAMMA | 12 #undef FX_GAMMA |
13 #undef FX_GAMMA_INVERSE | 13 #undef FX_GAMMA_INVERSE |
14 #define FX_GAMMA(value) (value) | 14 #define FX_GAMMA(value) (value) |
15 #define FX_GAMMA_INVERSE(value) (value) | 15 #define FX_GAMMA_INVERSE(value) (value) |
16 | 16 |
| 17 namespace { |
| 18 |
| 19 void ResetTransform(FT_Face face) { |
| 20 FXFT_Matrix matrix; |
| 21 matrix.xx = 0x10000L; |
| 22 matrix.xy = 0; |
| 23 matrix.yx = 0; |
| 24 matrix.yy = 0x10000L; |
| 25 FXFT_Set_Transform(face, &matrix, 0); |
| 26 } |
| 27 |
| 28 // Sets the given transform on the font, and resets it to the identity when it |
| 29 // goes out of scope. |
| 30 class ScopedFontTransform { |
| 31 public: |
| 32 ScopedFontTransform(FT_Face face, FXFT_Matrix* matrix) : m_Face(face) { |
| 33 FXFT_Set_Transform(m_Face, matrix, 0); |
| 34 } |
| 35 |
| 36 ~ScopedFontTransform() { ResetTransform(m_Face); } |
| 37 |
| 38 private: |
| 39 FT_Face m_Face; |
| 40 }; |
| 41 |
| 42 } // namespace |
| 43 |
17 FX_RECT FXGE_GetGlyphsBBox(FXTEXT_GLYPHPOS* pGlyphAndPos, | 44 FX_RECT FXGE_GetGlyphsBBox(FXTEXT_GLYPHPOS* pGlyphAndPos, |
18 int nChars, | 45 int nChars, |
19 int anti_alias, | 46 int anti_alias, |
20 FX_FLOAT retinaScaleX, | 47 FX_FLOAT retinaScaleX, |
21 FX_FLOAT retinaScaleY) { | 48 FX_FLOAT retinaScaleY) { |
22 FX_RECT rect(0, 0, 0, 0); | 49 FX_RECT rect(0, 0, 0, 0); |
23 FX_BOOL bStarted = FALSE; | 50 FX_BOOL bStarted = FALSE; |
24 for (int iChar = 0; iChar < nChars; iChar++) { | 51 for (int iChar = 0; iChar < nChars; iChar++) { |
25 FXTEXT_GLYPHPOS& glyph = pGlyphAndPos[iChar]; | 52 FXTEXT_GLYPHPOS& glyph = pGlyphAndPos[iChar]; |
26 const CFX_GlyphBitmap* pGlyph = glyph.m_pGlyph; | 53 const CFX_GlyphBitmap* pGlyph = glyph.m_pGlyph; |
(...skipping 1122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1149 const FX_BOOL bExternal = internal_face == nullptr; | 1176 const FX_BOOL bExternal = internal_face == nullptr; |
1150 FXFT_Face face = | 1177 FXFT_Face face = |
1151 bExternal ? (FXFT_Face)pFont->GetSubstFont()->m_ExtHandle : internal_face; | 1178 bExternal ? (FXFT_Face)pFont->GetSubstFont()->m_ExtHandle : internal_face; |
1152 CFX_FTCacheMap& map = bExternal ? m_ExtFaceMap : m_FTFaceMap; | 1179 CFX_FTCacheMap& map = bExternal ? m_ExtFaceMap : m_FTFaceMap; |
1153 auto it = map.find(face); | 1180 auto it = map.find(face); |
1154 if (it != map.end()) { | 1181 if (it != map.end()) { |
1155 CFX_CountedFaceCache* counted_face_cache = it->second; | 1182 CFX_CountedFaceCache* counted_face_cache = it->second; |
1156 counted_face_cache->m_nCount++; | 1183 counted_face_cache->m_nCount++; |
1157 return counted_face_cache->m_Obj; | 1184 return counted_face_cache->m_Obj; |
1158 } | 1185 } |
| 1186 |
1159 CFX_FaceCache* face_cache = new CFX_FaceCache(bExternal ? nullptr : face); | 1187 CFX_FaceCache* face_cache = new CFX_FaceCache(bExternal ? nullptr : face); |
1160 CFX_CountedFaceCache* counted_face_cache = new CFX_CountedFaceCache; | 1188 CFX_CountedFaceCache* counted_face_cache = new CFX_CountedFaceCache; |
1161 counted_face_cache->m_nCount = 2; | 1189 counted_face_cache->m_nCount = 2; |
1162 counted_face_cache->m_Obj = face_cache; | 1190 counted_face_cache->m_Obj = face_cache; |
1163 map[face] = counted_face_cache; | 1191 map[face] = counted_face_cache; |
1164 return face_cache; | 1192 return face_cache; |
1165 } | 1193 } |
1166 | 1194 |
1167 void CFX_FontCache::ReleaseCachedFace(CFX_Font* pFont) { | 1195 void CFX_FontCache::ReleaseCachedFace(CFX_Font* pFont) { |
1168 FXFT_Face internal_face = pFont->GetFace(); | 1196 FXFT_Face internal_face = pFont->GetFace(); |
(...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1517 ft_matrix.yx += ft_matrix.yy * skew / 100; | 1545 ft_matrix.yx += ft_matrix.yy * skew / 100; |
1518 } else { | 1546 } else { |
1519 ft_matrix.xy += -ft_matrix.xx * skew / 100; | 1547 ft_matrix.xy += -ft_matrix.xx * skew / 100; |
1520 } | 1548 } |
1521 } | 1549 } |
1522 if (pSubstFont->m_SubstFlags & FXFONT_SUBST_MM) { | 1550 if (pSubstFont->m_SubstFlags & FXFONT_SUBST_MM) { |
1523 pFont->AdjustMMParams(glyph_index, dest_width, | 1551 pFont->AdjustMMParams(glyph_index, dest_width, |
1524 pFont->GetSubstFont()->m_Weight); | 1552 pFont->GetSubstFont()->m_Weight); |
1525 } | 1553 } |
1526 } | 1554 } |
1527 FXFT_Set_Transform(m_Face, &ft_matrix, 0); | 1555 ScopedFontTransform scoped_transform(m_Face, &ft_matrix); |
1528 int load_flags = (m_Face->face_flags & FT_FACE_FLAG_SFNT) | 1556 int load_flags = (m_Face->face_flags & FT_FACE_FLAG_SFNT) |
1529 ? FXFT_LOAD_NO_BITMAP | 1557 ? FXFT_LOAD_NO_BITMAP |
1530 : (FXFT_LOAD_NO_BITMAP | FT_LOAD_NO_HINTING); | 1558 : (FXFT_LOAD_NO_BITMAP | FT_LOAD_NO_HINTING); |
1531 int error = FXFT_Load_Glyph(m_Face, glyph_index, load_flags); | 1559 int error = FXFT_Load_Glyph(m_Face, glyph_index, load_flags); |
1532 if (error) { | 1560 if (error) { |
1533 // if an error is returned, try to reload glyphs without hinting. | 1561 // if an error is returned, try to reload glyphs without hinting. |
1534 if (load_flags & FT_LOAD_NO_HINTING || load_flags & FT_LOAD_NO_SCALE) { | 1562 if (load_flags & FT_LOAD_NO_HINTING || load_flags & FT_LOAD_NO_SCALE) { |
1535 return NULL; | 1563 return NULL; |
1536 } | 1564 } |
1537 | 1565 |
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1784 if (m_bVertical) { | 1812 if (m_bVertical) { |
1785 ft_matrix.yx += ft_matrix.yy * skew / 100; | 1813 ft_matrix.yx += ft_matrix.yy * skew / 100; |
1786 } else { | 1814 } else { |
1787 ft_matrix.xy += -ft_matrix.xx * skew / 100; | 1815 ft_matrix.xy += -ft_matrix.xx * skew / 100; |
1788 } | 1816 } |
1789 } | 1817 } |
1790 if (m_pSubstFont->m_SubstFlags & FXFONT_SUBST_MM) { | 1818 if (m_pSubstFont->m_SubstFlags & FXFONT_SUBST_MM) { |
1791 AdjustMMParams(glyph_index, dest_width, m_pSubstFont->m_Weight); | 1819 AdjustMMParams(glyph_index, dest_width, m_pSubstFont->m_Weight); |
1792 } | 1820 } |
1793 } | 1821 } |
1794 FXFT_Set_Transform(m_Face, &ft_matrix, 0); | 1822 ScopedFontTransform scoped_transform(m_Face, &ft_matrix); |
1795 int load_flags = FXFT_LOAD_NO_BITMAP; | 1823 int load_flags = FXFT_LOAD_NO_BITMAP; |
1796 if (!(m_Face->face_flags & FT_FACE_FLAG_SFNT) || !FT_IS_TRICKY(m_Face)) { | 1824 if (!(m_Face->face_flags & FT_FACE_FLAG_SFNT) || !FT_IS_TRICKY(m_Face)) { |
1797 load_flags |= FT_LOAD_NO_HINTING; | 1825 load_flags |= FT_LOAD_NO_HINTING; |
1798 } | 1826 } |
1799 int error = FXFT_Load_Glyph(m_Face, glyph_index, load_flags); | 1827 int error = FXFT_Load_Glyph(m_Face, glyph_index, load_flags); |
1800 if (error) { | 1828 if (error) { |
1801 return NULL; | 1829 return NULL; |
1802 } | 1830 } |
1803 if (m_pSubstFont && !(m_pSubstFont->m_SubstFlags & FXFONT_SUBST_MM) && | 1831 if (m_pSubstFont && !(m_pSubstFont->m_SubstFlags & FXFONT_SUBST_MM) && |
1804 m_pSubstFont->m_Weight > 400) { | 1832 m_pSubstFont->m_Weight > 400) { |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1845 void _CFX_UniqueKeyGen::Generate(int count, ...) { | 1873 void _CFX_UniqueKeyGen::Generate(int count, ...) { |
1846 va_list argList; | 1874 va_list argList; |
1847 va_start(argList, count); | 1875 va_start(argList, count); |
1848 for (int i = 0; i < count; i++) { | 1876 for (int i = 0; i < count; i++) { |
1849 int p = va_arg(argList, int); | 1877 int p = va_arg(argList, int); |
1850 ((FX_DWORD*)m_Key)[i] = p; | 1878 ((FX_DWORD*)m_Key)[i] = p; |
1851 } | 1879 } |
1852 va_end(argList); | 1880 va_end(argList); |
1853 m_KeyLen = count * sizeof(FX_DWORD); | 1881 m_KeyLen = count * sizeof(FX_DWORD); |
1854 } | 1882 } |
OLD | NEW |