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" |
(...skipping 1208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1219 int max_width = FXFT_Get_Glyph_HoriAdvance(m_Face) * 1000 / FXFT_Get_Fac
e_UnitsPerEM(m_Face); | 1219 int max_width = FXFT_Get_Glyph_HoriAdvance(m_Face) * 1000 / FXFT_Get_Fac
e_UnitsPerEM(m_Face); |
1220 if (max_width == min_width) { | 1220 if (max_width == min_width) { |
1221 return; | 1221 return; |
1222 } | 1222 } |
1223 int param = min_param + (max_param - min_param) * (dest_width - min_widt
h) / (max_width - min_width); | 1223 int param = min_param + (max_param - min_param) * (dest_width - min_widt
h) / (max_width - min_width); |
1224 coords[1] = param; | 1224 coords[1] = param; |
1225 } | 1225 } |
1226 FXFT_Free(m_Face, pMasters); | 1226 FXFT_Free(m_Face, pMasters); |
1227 FXFT_Set_MM_Design_Coordinates(m_Face, 2, coords); | 1227 FXFT_Set_MM_Design_Coordinates(m_Face, 2, coords); |
1228 } | 1228 } |
1229 extern const char g_AngleSkew[30] = { | 1229 static const size_t ANGLESKEW_ARRAY_SIZE = 30; |
| 1230 static const char g_AngleSkew[ANGLESKEW_ARRAY_SIZE] = { |
1230 0, 2, 3, 5, 7, 9, 11, 12, 14, 16, | 1231 0, 2, 3, 5, 7, 9, 11, 12, 14, 16, |
1231 18, 19, 21, 23, 25, 27, 29, 31, 32, 34, | 1232 18, 19, 21, 23, 25, 27, 29, 31, 32, 34, |
1232 36, 38, 40, 42, 45, 47, 49, 51, 53, 55, | 1233 36, 38, 40, 42, 45, 47, 49, 51, 53, 55, |
1233 }; | 1234 }; |
1234 static const FX_BYTE g_WeightPow[100] = { | 1235 static const size_t WEIGHTPOW_ARRAY_SIZE = 100; |
| 1236 static const FX_BYTE g_WeightPow[WEIGHTPOW_ARRAY_SIZE] = { |
1235 0, 3, 6, 7, 8, 9, 11, 12, 14, 15, 16, 17, 18, 19, 20, | 1237 0, 3, 6, 7, 8, 9, 11, 12, 14, 15, 16, 17, 18, 19, 20, |
1236 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 35, 36, 36, | 1238 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 35, 36, 36, |
1237 37, 37, 37, 38, 38, 38, 39, 39, 39, 40, 40, 40, 41, 41, 41, 42, 42, 42, | 1239 37, 37, 37, 38, 38, 38, 39, 39, 39, 40, 40, 40, 41, 41, 41, 42, 42, 42, |
1238 42, 43, 43, 43, 44, 44, 44, 44, 45, 45, 45, 45, 46, 46, 46, 46, 47, 47, | 1240 42, 43, 43, 43, 44, 44, 44, 44, 45, 45, 45, 45, 46, 46, 46, 46, 47, 47, |
1239 47, 47, 48, 48, 48, 48, 48, 49, 49, 49, 49, 50, 50, 50, 50, 50, 51, 51, | 1241 47, 47, 48, 48, 48, 48, 48, 49, 49, 49, 49, 50, 50, 50, 50, 50, 51, 51, |
1240 51, 51, 51, 52, 52, 52, 52, 52, 53, 53, 53, 53, 53, | 1242 51, 51, 51, 52, 52, 52, 52, 52, 53, 53, 53, 53, 53, |
1241 }; | 1243 }; |
1242 extern const FX_BYTE g_WeightPow_11[100] = { | 1244 static const FX_BYTE g_WeightPow_11[WEIGHTPOW_ARRAY_SIZE] = { |
1243 0, 4, 7, 8, 9, 10, 12, 13, 15, 17, 18, 19, 20, 21, 22, | 1245 0, 4, 7, 8, 9, 10, 12, 13, 15, 17, 18, 19, 20, 21, 22, |
1244 23, 24, 25, 26, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 39, 39, 40, 40, | 1246 23, 24, 25, 26, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 39, 39, 40, 40, |
1245 41, 41, 41, 42, 42, 42, 43, 43, 43, 44, 44, 44, 45, 45, 45, 46, 46, 46, | 1247 41, 41, 41, 42, 42, 42, 43, 43, 43, 44, 44, 44, 45, 45, 45, 46, 46, 46, |
1246 46, 43, 47, 47, 48, 48, 48, 48, 45, 50, 50, 50, 46, 51, 51, 51, 52, 52, | 1248 46, 43, 47, 47, 48, 48, 48, 48, 45, 50, 50, 50, 46, 51, 51, 51, 52, 52, |
1247 52, 52, 53, 53, 53, 53, 53, 54, 54, 54, 54, 55, 55, 55, 55, 55, 56, 56, | 1249 52, 52, 53, 53, 53, 53, 53, 54, 54, 54, 54, 55, 55, 55, 55, 55, 56, 56, |
1248 56, 56, 56, 57, 57, 57, 57, 57, 58, 58, 58, 58, 58, | 1250 56, 56, 56, 57, 57, 57, 57, 57, 58, 58, 58, 58, 58, |
1249 }; | 1251 }; |
1250 extern const FX_BYTE g_WeightPow_SHIFTJIS[100] = { | 1252 static const FX_BYTE g_WeightPow_SHIFTJIS[WEIGHTPOW_ARRAY_SIZE] = { |
1251 0, 0, 1, 2, 3, 4, 5, 7, 8, 10, 11, 13, 14, 16, 17, 19, 21, 22, 24, 26, 28, | 1253 0, 0, 1, 2, 3, 4, 5, 7, 8, 10, 11, 13, 14, 16, 17, 19, 21, 22, 24, 26, 28, |
1252 30, 32, 33, 35, 37, 39, 41, 43, 45, 48, 48, 48, 48, 49, 49, 49, 50, 50, 50,
50, | 1254 30, 32, 33, 35, 37, 39, 41, 43, 45, 48, 48, 48, 48, 49, 49, 49, 50, 50, 50,
50, |
1253 51, 51, 51, 51, 52, 52, 52, 52, 52, 53, 53, 53, 53, 53, 54, 54, 54, 54, 54,
55, 55, | 1255 51, 51, 51, 51, 52, 52, 52, 52, 52, 53, 53, 53, 53, 53, 54, 54, 54, 54, 54,
55, 55, |
1254 55, 55, 55, 56, 56, 56, 56, 56 , 56, 57, 57, 57 , 57 , 57, 57, 57, 58, 58, 5
8, 58, 58, | 1256 55, 55, 55, 56, 56, 56, 56, 56 , 56, 57, 57, 57 , 57 , 57, 57, 57, 58, 58, 5
8, 58, 58, |
1255 58, 58, 59, 59, 59, 59, 59, 59, 59, 60, 60, 60, 60, 60, 60, 60, 60, | 1257 58, 58, 59, 59, 59, 59, 59, 59, 59, 60, 60, 60, 60, 60, 60, 60, 60, |
1256 }; | 1258 }; |
1257 static void _GammaAdjust(FX_LPBYTE pData, int nWid, int nHei, int src_pitch, FX_
LPCBYTE gammaTable) | 1259 static void _GammaAdjust(FX_LPBYTE pData, int nWid, int nHei, int src_pitch, FX_
LPCBYTE gammaTable) |
1258 { | 1260 { |
1259 int count = nHei * src_pitch; | 1261 int count = nHei * src_pitch; |
1260 for(int i = 0; i < count; i++) { | 1262 for(int i = 0; i < count; i++) { |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1316 const CFX_SubstFont* pSubstFont = pFont->GetSubstFont(); | 1318 const CFX_SubstFont* pSubstFont = pFont->GetSubstFont(); |
1317 if (pSubstFont) { | 1319 if (pSubstFont) { |
1318 bUseCJKSubFont = pSubstFont->m_bSubstOfCJK && bFontStyle; | 1320 bUseCJKSubFont = pSubstFont->m_bSubstOfCJK && bFontStyle; |
1319 int skew = 0; | 1321 int skew = 0; |
1320 if (bUseCJKSubFont) { | 1322 if (bUseCJKSubFont) { |
1321 skew = pSubstFont->m_bItlicCJK ? -15 : 0; | 1323 skew = pSubstFont->m_bItlicCJK ? -15 : 0; |
1322 } else { | 1324 } else { |
1323 skew = pSubstFont->m_ItalicAngle; | 1325 skew = pSubstFont->m_ItalicAngle; |
1324 } | 1326 } |
1325 if (skew) { | 1327 if (skew) { |
1326 skew = skew <= -30 ? -58 : -g_AngleSkew[-skew]; | 1328 skew = skew <= -ANGLESKEW_ARRAY_SIZE ? -58 : -g_AngleSkew[-skew]; |
1327 if (pFont->IsVertical()) { | 1329 if (pFont->IsVertical()) { |
1328 ft_matrix.yx += ft_matrix.yy * skew / 100; | 1330 ft_matrix.yx += ft_matrix.yy * skew / 100; |
1329 } else { | 1331 } else { |
1330 ft_matrix.xy += -ft_matrix.xx * skew / 100; | 1332 ft_matrix.xy += -ft_matrix.xx * skew / 100; |
1331 } | 1333 } |
1332 } | 1334 } |
1333 if (pSubstFont->m_SubstFlags & FXFONT_SUBST_MM) { | 1335 if (pSubstFont->m_SubstFlags & FXFONT_SUBST_MM) { |
1334 pFont->AdjustMMParams(glyph_index, dest_width, pFont->GetSubstFont()
->m_Weight); | 1336 pFont->AdjustMMParams(glyph_index, dest_width, pFont->GetSubstFont()
->m_Weight); |
1335 } | 1337 } |
1336 } | 1338 } |
1337 int transflag = FXFT_Get_Face_Internal_Flag(m_Face); | 1339 int transflag = FXFT_Get_Face_Internal_Flag(m_Face); |
1338 FXFT_Set_Transform(m_Face, &ft_matrix, 0); | 1340 FXFT_Set_Transform(m_Face, &ft_matrix, 0); |
1339 int load_flags = (m_Face->face_flags & FT_FACE_FLAG_SFNT) ? FXFT_LOAD_NO_BIT
MAP : (FXFT_LOAD_NO_BITMAP | FT_LOAD_NO_HINTING); | 1341 int load_flags = (m_Face->face_flags & FT_FACE_FLAG_SFNT) ? FXFT_LOAD_NO_BIT
MAP : (FXFT_LOAD_NO_BITMAP | FT_LOAD_NO_HINTING); |
1340 int error = FXFT_Load_Glyph(m_Face, glyph_index, load_flags); | 1342 int error = FXFT_Load_Glyph(m_Face, glyph_index, load_flags); |
1341 if (error) { | 1343 if (error) { |
1342 FXFT_Set_Face_Internal_Flag(m_Face, transflag); | 1344 FXFT_Set_Face_Internal_Flag(m_Face, transflag); |
1343 return NULL; | 1345 return NULL; |
1344 } | 1346 } |
1345 int weight = 0; | 1347 int weight = 0; |
1346 if (bUseCJKSubFont) { | 1348 if (bUseCJKSubFont) { |
1347 weight = pSubstFont->m_WeightCJK; | 1349 weight = pSubstFont->m_WeightCJK; |
1348 } else { | 1350 } else { |
1349 weight = pSubstFont ? pSubstFont->m_Weight : 0; | 1351 weight = pSubstFont ? pSubstFont->m_Weight : 0; |
1350 } | 1352 } |
1351 if (pSubstFont && !(pSubstFont->m_SubstFlags & FXFONT_SUBST_MM) && weight >
400) { | 1353 if (pSubstFont && !(pSubstFont->m_SubstFlags & FXFONT_SUBST_MM) && weight >
400) { |
1352 int index = (weight - 400) / 10; | 1354 int index = (weight - 400) / 10; |
1353 if (index >= 100) { | 1355 if (index >= WEIGHTPOW_ARRAY_SIZE) { |
1354 FXFT_Set_Face_Internal_Flag(m_Face, transflag); | 1356 FXFT_Set_Face_Internal_Flag(m_Face, transflag); |
1355 return NULL; | 1357 return NULL; |
1356 } | 1358 } |
1357 int level = 0; | 1359 int level = 0; |
1358 if (pSubstFont->m_Charset == FXFONT_SHIFTJIS_CHARSET) { | 1360 if (pSubstFont->m_Charset == FXFONT_SHIFTJIS_CHARSET) { |
1359 level = g_WeightPow_SHIFTJIS[index] * 2 * (FXSYS_abs((int)(ft_matrix
.xx)) + FXSYS_abs((int)(ft_matrix.xy))) / 36655; | 1361 level = g_WeightPow_SHIFTJIS[index] * 2 * (FXSYS_abs((int)(ft_matrix
.xx)) + FXSYS_abs((int)(ft_matrix.xy))) / 36655; |
1360 } else { | 1362 } else { |
1361 level = g_WeightPow_11[index] * (FXSYS_abs((int)(ft_matrix.xx)) + FX
SYS_abs((int)(ft_matrix.xy))) / 36655; | 1363 level = g_WeightPow_11[index] * (FXSYS_abs((int)(ft_matrix.xx)) + FX
SYS_abs((int)(ft_matrix.xy))) / 36655; |
1362 } | 1364 } |
1363 FXFT_Outline_Embolden(FXFT_Get_Glyph_Outline(m_Face), level); | 1365 FXFT_Outline_Embolden(FXFT_Get_Glyph_Outline(m_Face), level); |
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1628 CFX_PathData* CFX_Font::LoadGlyphPath(FX_DWORD glyph_index, int dest_width) | 1630 CFX_PathData* CFX_Font::LoadGlyphPath(FX_DWORD glyph_index, int dest_width) |
1629 { | 1631 { |
1630 if (m_Face == NULL) { | 1632 if (m_Face == NULL) { |
1631 return NULL; | 1633 return NULL; |
1632 } | 1634 } |
1633 FXFT_Set_Pixel_Sizes(m_Face, 0, 64); | 1635 FXFT_Set_Pixel_Sizes(m_Face, 0, 64); |
1634 FXFT_Matrix ft_matrix = {65536, 0, 0, 65536}; | 1636 FXFT_Matrix ft_matrix = {65536, 0, 0, 65536}; |
1635 if (m_pSubstFont) { | 1637 if (m_pSubstFont) { |
1636 if (m_pSubstFont->m_ItalicAngle) { | 1638 if (m_pSubstFont->m_ItalicAngle) { |
1637 int skew = m_pSubstFont->m_ItalicAngle; | 1639 int skew = m_pSubstFont->m_ItalicAngle; |
1638 skew = skew <= -30 ? -58 : -g_AngleSkew[-skew]; | 1640 skew = skew <= -ANGLESKEW_ARRAY_SIZE ? -58 : -g_AngleSkew[-skew]; |
1639 if (m_bVertical) { | 1641 if (m_bVertical) { |
1640 ft_matrix.yx += ft_matrix.yy * skew / 100; | 1642 ft_matrix.yx += ft_matrix.yy * skew / 100; |
1641 } else { | 1643 } else { |
1642 ft_matrix.xy += -ft_matrix.xx * skew / 100; | 1644 ft_matrix.xy += -ft_matrix.xx * skew / 100; |
1643 } | 1645 } |
1644 } | 1646 } |
1645 if (m_pSubstFont->m_SubstFlags & FXFONT_SUBST_MM) { | 1647 if (m_pSubstFont->m_SubstFlags & FXFONT_SUBST_MM) { |
1646 AdjustMMParams(glyph_index, dest_width, m_pSubstFont->m_Weight); | 1648 AdjustMMParams(glyph_index, dest_width, m_pSubstFont->m_Weight); |
1647 } | 1649 } |
1648 } | 1650 } |
1649 int transflag = FXFT_Get_Face_Internal_Flag(m_Face); | 1651 int transflag = FXFT_Get_Face_Internal_Flag(m_Face); |
1650 FXFT_Set_Transform(m_Face, &ft_matrix, 0); | 1652 FXFT_Set_Transform(m_Face, &ft_matrix, 0); |
1651 int load_flags = (m_Face->face_flags & FT_FACE_FLAG_SFNT) ? FXFT_LOAD_NO_BIT
MAP : FXFT_LOAD_NO_BITMAP | FT_LOAD_NO_HINTING; | 1653 int load_flags = (m_Face->face_flags & FT_FACE_FLAG_SFNT) ? FXFT_LOAD_NO_BIT
MAP : FXFT_LOAD_NO_BITMAP | FT_LOAD_NO_HINTING; |
1652 int error = FXFT_Load_Glyph(m_Face, glyph_index, load_flags); | 1654 int error = FXFT_Load_Glyph(m_Face, glyph_index, load_flags); |
1653 if (error) { | 1655 if (error) { |
1654 FXFT_Set_Face_Internal_Flag(m_Face, transflag); | 1656 FXFT_Set_Face_Internal_Flag(m_Face, transflag); |
1655 return NULL; | 1657 return NULL; |
1656 } | 1658 } |
1657 if (m_pSubstFont && !(m_pSubstFont->m_SubstFlags & FXFONT_SUBST_MM) && m_pSu
bstFont->m_Weight > 400) { | 1659 if (m_pSubstFont && !(m_pSubstFont->m_SubstFlags & FXFONT_SUBST_MM) && m_pSu
bstFont->m_Weight > 400) { |
| 1660 int index = (m_pSubstFont->m_Weight - 400) / 10; |
| 1661 if (index >= WEIGHTPOW_ARRAY_SIZE) |
| 1662 index = WEIGHTPOW_ARRAY_SIZE - 1; |
1658 int level = 0; | 1663 int level = 0; |
1659 if (m_pSubstFont->m_Charset == FXFONT_SHIFTJIS_CHARSET) { | 1664 if (m_pSubstFont->m_Charset == FXFONT_SHIFTJIS_CHARSET) { |
1660 level = g_WeightPow_SHIFTJIS[(m_pSubstFont->m_Weight - 400) / 10] *
2 * 65536 / 36655; | 1665 level = g_WeightPow_SHIFTJIS[index] * 2 * 65536 / 36655; |
1661 } else { | 1666 } else { |
1662 level = g_WeightPow[(m_pSubstFont->m_Weight - 400) / 10] * 2; | 1667 level = g_WeightPow[index] * 2; |
1663 } | 1668 } |
1664 FXFT_Outline_Embolden(FXFT_Get_Glyph_Outline(m_Face), level); | 1669 FXFT_Outline_Embolden(FXFT_Get_Glyph_Outline(m_Face), level); |
1665 } | 1670 } |
1666 FXFT_Outline_Funcs funcs; | 1671 FXFT_Outline_Funcs funcs; |
1667 funcs.move_to = _Outline_MoveTo; | 1672 funcs.move_to = _Outline_MoveTo; |
1668 funcs.line_to = _Outline_LineTo; | 1673 funcs.line_to = _Outline_LineTo; |
1669 funcs.conic_to = _Outline_ConicTo; | 1674 funcs.conic_to = _Outline_ConicTo; |
1670 funcs.cubic_to = _Outline_CubicTo; | 1675 funcs.cubic_to = _Outline_CubicTo; |
1671 funcs.shift = 0; | 1676 funcs.shift = 0; |
1672 funcs.delta = 0; | 1677 funcs.delta = 0; |
(...skipping 28 matching lines...) Expand all Loading... |
1701 { | 1706 { |
1702 va_list argList; | 1707 va_list argList; |
1703 va_start(argList, count); | 1708 va_start(argList, count); |
1704 for (int i = 0; i < count; i ++) { | 1709 for (int i = 0; i < count; i ++) { |
1705 int p = va_arg(argList, int); | 1710 int p = va_arg(argList, int); |
1706 ((FX_DWORD*)m_Key)[i] = p; | 1711 ((FX_DWORD*)m_Key)[i] = p; |
1707 } | 1712 } |
1708 va_end(argList); | 1713 va_end(argList); |
1709 m_KeyLen = count * sizeof(FX_DWORD); | 1714 m_KeyLen = count * sizeof(FX_DWORD); |
1710 } | 1715 } |
OLD | NEW |