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 "fx_fpf.h" | 7 #include "fx_fpf.h" |
8 #if _FX_OS_ == _FX_ANDROID_ | 8 #if _FX_OS_ == _FX_ANDROID_ |
9 #include "fpf_skiafont.h" | 9 #include "fpf_skiafont.h" |
10 #include "fpf_skiafontmgr.h" | 10 #include "fpf_skiafontmgr.h" |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
46 } | 46 } |
47 return CFX_ByteString(FXFT_Get_Face_Family_Name(m_Face)); | 47 return CFX_ByteString(FXFT_Get_Face_Family_Name(m_Face)); |
48 } | 48 } |
49 CFX_WideString CFPF_SkiaFont::GetPsName() | 49 CFX_WideString CFPF_SkiaFont::GetPsName() |
50 { | 50 { |
51 if (!m_Face) { | 51 if (!m_Face) { |
52 return CFX_WideString(); | 52 return CFX_WideString(); |
53 } | 53 } |
54 return CFX_WideString::FromLocal(FXFT_Get_Postscript_Name(m_Face)); | 54 return CFX_WideString::FromLocal(FXFT_Get_Postscript_Name(m_Face)); |
55 } | 55 } |
56 FX_INT32 CFPF_SkiaFont::GetGlyphIndex(FX_WCHAR wUnicode) | 56 int32_t CFPF_SkiaFont::GetGlyphIndex(FX_WCHAR wUnicode) |
57 { | 57 { |
58 if (!m_Face) { | 58 if (!m_Face) { |
59 return wUnicode; | 59 return wUnicode; |
60 } | 60 } |
61 if (FXFT_Select_Charmap(m_Face, FXFT_ENCODING_UNICODE)) { | 61 if (FXFT_Select_Charmap(m_Face, FXFT_ENCODING_UNICODE)) { |
62 return 0; | 62 return 0; |
63 } | 63 } |
64 return FXFT_Get_Char_Index(m_Face, wUnicode); | 64 return FXFT_Get_Char_Index(m_Face, wUnicode); |
65 } | 65 } |
66 FX_INT32 CFPF_SkiaFont::GetGlyphWidth(FX_INT32 iGlyphIndex) | 66 int32_t CFPF_SkiaFont::GetGlyphWidth(int32_t iGlyphIndex) |
67 { | 67 { |
68 if (!m_Face) { | 68 if (!m_Face) { |
69 return 0; | 69 return 0; |
70 } | 70 } |
71 if (FXFT_Load_Glyph(m_Face, iGlyphIndex, FXFT_LOAD_NO_SCALE | FXFT_LOAD_IGNO
RE_GLOBAL_ADVANCE_WIDTH)) { | 71 if (FXFT_Load_Glyph(m_Face, iGlyphIndex, FXFT_LOAD_NO_SCALE | FXFT_LOAD_IGNO
RE_GLOBAL_ADVANCE_WIDTH)) { |
72 return 0; | 72 return 0; |
73 } | 73 } |
74 return FPF_EM_ADJUST(FXFT_Get_Face_UnitsPerEM(m_Face), FXFT_Get_Glyph_HoriAd
vance(m_Face)); | 74 return FPF_EM_ADJUST(FXFT_Get_Face_UnitsPerEM(m_Face), FXFT_Get_Glyph_HoriAd
vance(m_Face)); |
75 } | 75 } |
76 FX_INT32 CFPF_SkiaFont::GetAscent() const | 76 int32_t CFPF_SkiaFont::GetAscent() const |
77 { | 77 { |
78 if (!m_Face) { | 78 if (!m_Face) { |
79 return 0; | 79 return 0; |
80 } | 80 } |
81 return FPF_EM_ADJUST(FXFT_Get_Face_UnitsPerEM(m_Face), FXFT_Get_Face_Ascende
r(m_Face)); | 81 return FPF_EM_ADJUST(FXFT_Get_Face_UnitsPerEM(m_Face), FXFT_Get_Face_Ascende
r(m_Face)); |
82 } | 82 } |
83 FX_INT32 CFPF_SkiaFont::GetDescent() const | 83 int32_t CFPF_SkiaFont::GetDescent() const |
84 { | 84 { |
85 if (!m_Face) { | 85 if (!m_Face) { |
86 return 0; | 86 return 0; |
87 } | 87 } |
88 return FPF_EM_ADJUST(FXFT_Get_Face_UnitsPerEM(m_Face), FXFT_Get_Face_Descend
er(m_Face)); | 88 return FPF_EM_ADJUST(FXFT_Get_Face_UnitsPerEM(m_Face), FXFT_Get_Face_Descend
er(m_Face)); |
89 } | 89 } |
90 FX_BOOL CFPF_SkiaFont::GetGlyphBBox(FX_INT32 iGlyphIndex, FX_RECT &rtBBox) | 90 FX_BOOL CFPF_SkiaFont::GetGlyphBBox(int32_t iGlyphIndex, FX_RECT &rtBBox) |
91 { | 91 { |
92 if (!m_Face) { | 92 if (!m_Face) { |
93 return FALSE; | 93 return FALSE; |
94 } | 94 } |
95 if (FXFT_Is_Face_Tricky(m_Face)) { | 95 if (FXFT_Is_Face_Tricky(m_Face)) { |
96 if (FXFT_Set_Char_Size(m_Face, 0, 1000 * 64, 72, 72)) { | 96 if (FXFT_Set_Char_Size(m_Face, 0, 1000 * 64, 72, 72)) { |
97 return FALSE; | 97 return FALSE; |
98 } | 98 } |
99 if (FXFT_Load_Glyph(m_Face, iGlyphIndex, FXFT_LOAD_IGNORE_GLOBAL_ADVANCE
_WIDTH)) { | 99 if (FXFT_Load_Glyph(m_Face, iGlyphIndex, FXFT_LOAD_IGNORE_GLOBAL_ADVANCE
_WIDTH)) { |
100 FXFT_Set_Pixel_Sizes(m_Face, 0, 64); | 100 FXFT_Set_Pixel_Sizes(m_Face, 0, 64); |
101 return FALSE; | 101 return FALSE; |
102 } | 102 } |
103 FXFT_Glyph glyph; | 103 FXFT_Glyph glyph; |
104 if (FXFT_Get_Glyph(m_Face->glyph, &glyph)) { | 104 if (FXFT_Get_Glyph(m_Face->glyph, &glyph)) { |
105 FXFT_Set_Pixel_Sizes(m_Face, 0, 64); | 105 FXFT_Set_Pixel_Sizes(m_Face, 0, 64); |
106 return FALSE; | 106 return FALSE; |
107 } | 107 } |
108 FXFT_BBox cbox; | 108 FXFT_BBox cbox; |
109 FXFT_Glyph_Get_CBox(glyph, FXFT_GLYPH_BBOX_PIXELS, &cbox); | 109 FXFT_Glyph_Get_CBox(glyph, FXFT_GLYPH_BBOX_PIXELS, &cbox); |
110 FX_INT32 x_ppem = m_Face->size->metrics.x_ppem; | 110 int32_t x_ppem = m_Face->size->metrics.x_ppem; |
111 FX_INT32 y_ppem = m_Face->size->metrics.y_ppem; | 111 int32_t y_ppem = m_Face->size->metrics.y_ppem; |
112 rtBBox.left = FPF_EM_ADJUST(x_ppem, cbox.xMin); | 112 rtBBox.left = FPF_EM_ADJUST(x_ppem, cbox.xMin); |
113 rtBBox.right = FPF_EM_ADJUST(x_ppem, cbox.xMax); | 113 rtBBox.right = FPF_EM_ADJUST(x_ppem, cbox.xMax); |
114 rtBBox.top = FPF_EM_ADJUST(y_ppem, cbox.yMax); | 114 rtBBox.top = FPF_EM_ADJUST(y_ppem, cbox.yMax); |
115 rtBBox.bottom = FPF_EM_ADJUST(y_ppem, cbox.yMin); | 115 rtBBox.bottom = FPF_EM_ADJUST(y_ppem, cbox.yMin); |
116 rtBBox.top = FX_MIN(rtBBox.top, GetAscent()); | 116 rtBBox.top = FX_MIN(rtBBox.top, GetAscent()); |
117 rtBBox.bottom = FX_MAX(rtBBox.bottom, GetDescent()); | 117 rtBBox.bottom = FX_MAX(rtBBox.bottom, GetDescent()); |
118 FXFT_Done_Glyph(glyph); | 118 FXFT_Done_Glyph(glyph); |
119 return FXFT_Set_Pixel_Sizes(m_Face, 0, 64) == 0; | 119 return FXFT_Set_Pixel_Sizes(m_Face, 0, 64) == 0; |
120 } | 120 } |
121 if (FXFT_Load_Glyph(m_Face, iGlyphIndex, FXFT_LOAD_NO_SCALE | FXFT_LOAD_IGNO
RE_GLOBAL_ADVANCE_WIDTH)) { | 121 if (FXFT_Load_Glyph(m_Face, iGlyphIndex, FXFT_LOAD_NO_SCALE | FXFT_LOAD_IGNO
RE_GLOBAL_ADVANCE_WIDTH)) { |
122 return FALSE; | 122 return FALSE; |
123 } | 123 } |
124 rtBBox.left = FPF_EM_ADJUST(FXFT_Get_Face_UnitsPerEM(m_Face), FXFT_Get_Glyph
_HoriBearingX(m_Face)); | 124 rtBBox.left = FPF_EM_ADJUST(FXFT_Get_Face_UnitsPerEM(m_Face), FXFT_Get_Glyph
_HoriBearingX(m_Face)); |
125 rtBBox.bottom = FPF_EM_ADJUST(FXFT_Get_Face_UnitsPerEM(m_Face), FXFT_Get_Gly
ph_HoriBearingY(m_Face)); | 125 rtBBox.bottom = FPF_EM_ADJUST(FXFT_Get_Face_UnitsPerEM(m_Face), FXFT_Get_Gly
ph_HoriBearingY(m_Face)); |
126 rtBBox.right = FPF_EM_ADJUST(FXFT_Get_Face_UnitsPerEM(m_Face), FXFT_Get_Glyp
h_HoriBearingX(m_Face) + FXFT_Get_Glyph_Width(m_Face)); | 126 rtBBox.right = FPF_EM_ADJUST(FXFT_Get_Face_UnitsPerEM(m_Face), FXFT_Get_Glyp
h_HoriBearingX(m_Face) + FXFT_Get_Glyph_Width(m_Face)); |
127 rtBBox.top = FPF_EM_ADJUST(FXFT_Get_Face_UnitsPerEM(m_Face), FXFT_Get_Glyph_
HoriBearingY(m_Face) - FXFT_Get_Glyph_Height(m_Face)); | 127 rtBBox.top = FPF_EM_ADJUST(FXFT_Get_Face_UnitsPerEM(m_Face), FXFT_Get_Glyph_
HoriBearingY(m_Face) - FXFT_Get_Glyph_Height(m_Face)); |
128 return TRUE; | 128 return TRUE; |
129 } | 129 } |
130 FX_BOOL CFPF_SkiaFont::GetBBox(FX_RECT &rtBBox) | 130 FX_BOOL CFPF_SkiaFont::GetBBox(FX_RECT &rtBBox) |
131 { | 131 { |
132 if (!m_Face) { | 132 if (!m_Face) { |
133 return FALSE; | 133 return FALSE; |
134 } | 134 } |
135 rtBBox.left = FPF_EM_ADJUST(FXFT_Get_Face_UnitsPerEM(m_Face), FXFT_Get_Face_
xMin(m_Face)); | 135 rtBBox.left = FPF_EM_ADJUST(FXFT_Get_Face_UnitsPerEM(m_Face), FXFT_Get_Face_
xMin(m_Face)); |
136 rtBBox.top = FPF_EM_ADJUST(FXFT_Get_Face_UnitsPerEM(m_Face), FXFT_Get_Face_y
Min(m_Face)); | 136 rtBBox.top = FPF_EM_ADJUST(FXFT_Get_Face_UnitsPerEM(m_Face), FXFT_Get_Face_y
Min(m_Face)); |
137 rtBBox.right = FPF_EM_ADJUST(FXFT_Get_Face_UnitsPerEM(m_Face), FXFT_Get_Face
_xMax(m_Face)); | 137 rtBBox.right = FPF_EM_ADJUST(FXFT_Get_Face_UnitsPerEM(m_Face), FXFT_Get_Face
_xMax(m_Face)); |
138 rtBBox.bottom = FPF_EM_ADJUST(FXFT_Get_Face_UnitsPerEM(m_Face), FXFT_Get_Fac
e_yMax(m_Face)); | 138 rtBBox.bottom = FPF_EM_ADJUST(FXFT_Get_Face_UnitsPerEM(m_Face), FXFT_Get_Fac
e_yMax(m_Face)); |
139 return TRUE; | 139 return TRUE; |
140 } | 140 } |
141 FX_INT32 CFPF_SkiaFont::GetHeight() const | 141 int32_t CFPF_SkiaFont::GetHeight() const |
142 { | 142 { |
143 if (!m_Face) { | 143 if (!m_Face) { |
144 return 0; | 144 return 0; |
145 } | 145 } |
146 return FPF_EM_ADJUST(FXFT_Get_Face_UnitsPerEM(m_Face), FXFT_Get_Face_He
ight(m_Face)); | 146 return FPF_EM_ADJUST(FXFT_Get_Face_UnitsPerEM(m_Face), FXFT_Get_Face_He
ight(m_Face)); |
147 } | 147 } |
148 FX_INT32 CFPF_SkiaFont::GetItalicAngle() const | 148 int32_t CFPF_SkiaFont::GetItalicAngle() const |
149 { | 149 { |
150 if (!m_Face) { | 150 if (!m_Face) { |
151 return 0; | 151 return 0; |
152 } | 152 } |
153 TT_Postscript *ttInfo = (TT_Postscript*)FT_Get_Sfnt_Table(m_Face, ft_sfnt_po
st); | 153 TT_Postscript *ttInfo = (TT_Postscript*)FT_Get_Sfnt_Table(m_Face, ft_sfnt_po
st); |
154 if (ttInfo) { | 154 if (ttInfo) { |
155 return ttInfo->italicAngle; | 155 return ttInfo->italicAngle; |
156 } | 156 } |
157 return 0; | 157 return 0; |
158 } | 158 } |
159 FX_DWORD CFPF_SkiaFont::GetFontData(FX_DWORD dwTable, FX_LPBYTE pBuffer, FX_DWOR
D dwSize) | 159 FX_DWORD CFPF_SkiaFont::GetFontData(FX_DWORD dwTable, FX_LPBYTE pBuffer, FX_DWOR
D dwSize) |
160 { | 160 { |
161 if (!m_Face) { | 161 if (!m_Face) { |
162 return FALSE; | 162 return FALSE; |
163 } | 163 } |
164 if (FXFT_Load_Sfnt_Table(m_Face, dwTable, 0, pBuffer, (unsigned long*)&dwSiz
e)) { | 164 if (FXFT_Load_Sfnt_Table(m_Face, dwTable, 0, pBuffer, (unsigned long*)&dwSiz
e)) { |
165 return 0; | 165 return 0; |
166 } | 166 } |
167 return dwSize; | 167 return dwSize; |
168 } | 168 } |
169 FX_BOOL CFPF_SkiaFont::InitFont(CFPF_SkiaFontMgr *pFontMgr, CFPF_SkiaFontDescrip
tor *pFontDes, FX_BSTR bsFamily, FX_DWORD dwStyle, FX_BYTE uCharset) | 169 FX_BOOL CFPF_SkiaFont::InitFont(CFPF_SkiaFontMgr *pFontMgr, CFPF_SkiaFontDescrip
tor *pFontDes, FX_BSTR bsFamily, FX_DWORD dwStyle, uint8_t uCharset) |
170 { | 170 { |
171 if (!pFontMgr || !pFontDes) { | 171 if (!pFontMgr || !pFontDes) { |
172 return FALSE; | 172 return FALSE; |
173 } | 173 } |
174 switch (pFontDes->GetType()) { | 174 switch (pFontDes->GetType()) { |
175 case FPF_SKIAFONTTYPE_Path: { | 175 case FPF_SKIAFONTTYPE_Path: { |
176 CFPF_SkiaPathFont *pFont = (CFPF_SkiaPathFont*)pFontDes; | 176 CFPF_SkiaPathFont *pFont = (CFPF_SkiaPathFont*)pFontDes; |
177 m_Face = pFontMgr->GetFontFace(pFont->m_pPath, pFont->m_iFaceInd
ex); | 177 m_Face = pFontMgr->GetFontFace(pFont->m_pPath, pFont->m_iFaceInd
ex); |
178 } | 178 } |
179 break; | 179 break; |
(...skipping 14 matching lines...) Expand all Loading... |
194 return FALSE; | 194 return FALSE; |
195 } | 195 } |
196 m_dwStyle = dwStyle; | 196 m_dwStyle = dwStyle; |
197 m_uCharset = uCharset; | 197 m_uCharset = uCharset; |
198 m_pFontMgr = pFontMgr; | 198 m_pFontMgr = pFontMgr; |
199 m_pFontDes = pFontDes; | 199 m_pFontDes = pFontDes; |
200 m_dwRefCount = 1; | 200 m_dwRefCount = 1; |
201 return TRUE; | 201 return TRUE; |
202 } | 202 } |
203 #endif | 203 #endif |
OLD | NEW |