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 <limits> | 7 #include <limits> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "core/fxcodec/include/fx_codec.h" | 10 #include "core/fxcodec/include/fx_codec.h" |
11 #include "core/fxge/ge/fx_text_int.h" | 11 #include "core/fxge/ge/fx_text_int.h" |
12 #include "core/fxge/include/cfx_fontmgr.h" | 12 #include "core/fxge/include/cfx_fontmgr.h" |
13 #include "core/fxge/include/cfx_gemodule.h" | 13 #include "core/fxge/include/cfx_gemodule.h" |
14 #include "core/fxge/include/cfx_pathdata.h" | 14 #include "core/fxge/include/cfx_pathdata.h" |
15 #include "core/fxge/include/fx_freetype.h" | 15 #include "core/fxge/include/fx_freetype.h" |
16 #include "core/fxge/include/fx_ge.h" | |
17 #include "core/fxge/include/ifx_renderdevicedriver.h" | 16 #include "core/fxge/include/ifx_renderdevicedriver.h" |
18 | 17 |
19 #ifdef _SKIA_SUPPORT_ | 18 #ifdef _SKIA_SUPPORT_ |
20 #include "third_party/skia/include/core/SkStream.h" | 19 #include "third_party/skia/include/core/SkStream.h" |
21 #include "third_party/skia/include/core/SkTypeface.h" | 20 #include "third_party/skia/include/core/SkTypeface.h" |
22 #endif | 21 #endif |
23 | 22 |
24 namespace { | 23 namespace { |
25 | 24 |
26 void ResetTransform(FT_Face face) { | 25 void ResetTransform(FT_Face face) { |
(...skipping 12 matching lines...) Expand all Loading... |
39 ScopedFontTransform(FT_Face face, FXFT_Matrix* matrix) : m_Face(face) { | 38 ScopedFontTransform(FT_Face face, FXFT_Matrix* matrix) : m_Face(face) { |
40 FXFT_Set_Transform(m_Face, matrix, 0); | 39 FXFT_Set_Transform(m_Face, matrix, 0); |
41 } | 40 } |
42 | 41 |
43 ~ScopedFontTransform() { ResetTransform(m_Face); } | 42 ~ScopedFontTransform() { ResetTransform(m_Face); } |
44 | 43 |
45 private: | 44 private: |
46 FT_Face m_Face; | 45 FT_Face m_Face; |
47 }; | 46 }; |
48 | 47 |
49 void AdjustGlyphSpace(std::vector<FXTEXT_GLYPHPOS>* pGlyphAndPos) { | |
50 ASSERT(pGlyphAndPos->size() > 1); | |
51 std::vector<FXTEXT_GLYPHPOS>& glyphs = *pGlyphAndPos; | |
52 bool bVertical = glyphs.back().m_OriginX == glyphs.front().m_OriginX; | |
53 if (!bVertical && (glyphs.back().m_OriginY != glyphs.front().m_OriginY)) | |
54 return; | |
55 | |
56 for (size_t i = glyphs.size() - 1; i > 1; --i) { | |
57 FXTEXT_GLYPHPOS& next = glyphs[i]; | |
58 int next_origin = bVertical ? next.m_OriginY : next.m_OriginX; | |
59 FX_FLOAT next_origin_f = bVertical ? next.m_fOriginY : next.m_fOriginX; | |
60 | |
61 FXTEXT_GLYPHPOS& current = glyphs[i - 1]; | |
62 int& current_origin = bVertical ? current.m_OriginY : current.m_OriginX; | |
63 FX_FLOAT current_origin_f = | |
64 bVertical ? current.m_fOriginY : current.m_fOriginX; | |
65 | |
66 int space = next_origin - current_origin; | |
67 FX_FLOAT space_f = next_origin_f - current_origin_f; | |
68 FX_FLOAT error = | |
69 FXSYS_fabs(space_f) - FXSYS_fabs(static_cast<FX_FLOAT>(space)); | |
70 if (error > 0.5f) | |
71 current_origin += space > 0 ? -1 : 1; | |
72 } | |
73 } | |
74 | |
75 const uint8_t g_TextGammaAdjust[256] = { | |
76 0, 2, 3, 4, 6, 7, 8, 10, 11, 12, 13, 15, 16, 17, 18, | |
77 19, 21, 22, 23, 24, 25, 26, 27, 29, 30, 31, 32, 33, 34, 35, | |
78 36, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 51, 52, | |
79 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, | |
80 68, 69, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, | |
81 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, | |
82 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, | |
83 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, | |
84 129, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, | |
85 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 156, | |
86 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, | |
87 172, 173, 174, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, | |
88 186, 187, 188, 189, 190, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, | |
89 200, 201, 202, 203, 204, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, | |
90 214, 215, 216, 217, 217, 218, 219, 220, 221, 222, 223, 224, 225, 226, 227, | |
91 228, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239, 239, 240, | |
92 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 250, 251, 252, 253, 254, | |
93 255, | |
94 }; | |
95 | |
96 int TextGammaAdjust(int value) { | |
97 ASSERT(value >= 0); | |
98 ASSERT(value <= 255); | |
99 return g_TextGammaAdjust[value]; | |
100 } | |
101 | |
102 int CalcAlpha(int src, int alpha) { | |
103 return src * alpha / 255; | |
104 } | |
105 | |
106 void Merge(uint8_t src, int channel, int alpha, uint8_t* dest) { | |
107 *dest = FXDIB_ALPHA_MERGE(*dest, channel, CalcAlpha(src, alpha)); | |
108 } | |
109 | |
110 void MergeGammaAdjust(uint8_t src, int channel, int alpha, uint8_t* dest) { | |
111 *dest = | |
112 FXDIB_ALPHA_MERGE(*dest, channel, CalcAlpha(TextGammaAdjust(src), alpha)); | |
113 } | |
114 | |
115 void MergeGammaAdjustBgr(const uint8_t* src, | |
116 int r, | |
117 int g, | |
118 int b, | |
119 int a, | |
120 uint8_t* dest) { | |
121 MergeGammaAdjust(src[0], b, a, &dest[0]); | |
122 MergeGammaAdjust(src[1], g, a, &dest[1]); | |
123 MergeGammaAdjust(src[2], r, a, &dest[2]); | |
124 } | |
125 | |
126 void MergeGammaAdjustRgb(const uint8_t* src, | |
127 int r, | |
128 int g, | |
129 int b, | |
130 int a, | |
131 uint8_t* dest) { | |
132 MergeGammaAdjust(src[2], b, a, &dest[0]); | |
133 MergeGammaAdjust(src[1], g, a, &dest[1]); | |
134 MergeGammaAdjust(src[0], r, a, &dest[2]); | |
135 } | |
136 | |
137 int AverageRgb(const uint8_t* src) { | |
138 return (src[0] + src[1] + src[2]) / 3; | |
139 } | |
140 | |
141 uint8_t CalculateDestAlpha(uint8_t back_alpha, int src_alpha) { | |
142 return back_alpha + src_alpha - back_alpha * src_alpha / 255; | |
143 } | |
144 | |
145 void ApplyDestAlpha(uint8_t back_alpha, | |
146 int src_alpha, | |
147 int r, | |
148 int g, | |
149 int b, | |
150 uint8_t* dest) { | |
151 uint8_t dest_alpha = CalculateDestAlpha(back_alpha, src_alpha); | |
152 int alpha_ratio = src_alpha * 255 / dest_alpha; | |
153 dest[0] = FXDIB_ALPHA_MERGE(dest[0], b, alpha_ratio); | |
154 dest[1] = FXDIB_ALPHA_MERGE(dest[1], g, alpha_ratio); | |
155 dest[2] = FXDIB_ALPHA_MERGE(dest[2], r, alpha_ratio); | |
156 dest[3] = dest_alpha; | |
157 } | |
158 | |
159 void NormalizeRgbDst(int src_value, int r, int g, int b, int a, uint8_t* dest) { | |
160 int src_alpha = CalcAlpha(TextGammaAdjust(src_value), a); | |
161 dest[0] = FXDIB_ALPHA_MERGE(dest[0], b, src_alpha); | |
162 dest[1] = FXDIB_ALPHA_MERGE(dest[1], g, src_alpha); | |
163 dest[2] = FXDIB_ALPHA_MERGE(dest[2], r, src_alpha); | |
164 } | |
165 | |
166 void NormalizeRgbSrc(int src_value, int r, int g, int b, int a, uint8_t* dest) { | |
167 int src_alpha = CalcAlpha(TextGammaAdjust(src_value), a); | |
168 if (src_alpha == 0) | |
169 return; | |
170 | |
171 dest[0] = FXDIB_ALPHA_MERGE(dest[0], b, src_alpha); | |
172 dest[1] = FXDIB_ALPHA_MERGE(dest[1], g, src_alpha); | |
173 dest[2] = FXDIB_ALPHA_MERGE(dest[2], r, src_alpha); | |
174 } | |
175 | |
176 void NormalizeArgbDest(int src_value, | |
177 int r, | |
178 int g, | |
179 int b, | |
180 int a, | |
181 uint8_t* dest) { | |
182 int src_alpha = CalcAlpha(TextGammaAdjust(src_value), a); | |
183 uint8_t back_alpha = dest[3]; | |
184 if (back_alpha == 0) { | |
185 FXARGB_SETDIB(dest, FXARGB_MAKE(src_alpha, r, g, b)); | |
186 } else if (src_alpha != 0) { | |
187 ApplyDestAlpha(back_alpha, src_alpha, r, g, b, dest); | |
188 } | |
189 } | |
190 | |
191 void NormalizeArgbSrc(int src_value, | |
192 int r, | |
193 int g, | |
194 int b, | |
195 int a, | |
196 uint8_t* dest) { | |
197 int src_alpha = CalcAlpha(TextGammaAdjust(src_value), a); | |
198 if (src_alpha == 0) | |
199 return; | |
200 | |
201 uint8_t back_alpha = dest[3]; | |
202 if (back_alpha == 0) { | |
203 FXARGB_SETDIB(dest, FXARGB_MAKE(src_alpha, r, g, b)); | |
204 } else { | |
205 ApplyDestAlpha(back_alpha, src_alpha, r, g, b, dest); | |
206 } | |
207 } | |
208 | |
209 void NextPixel(uint8_t** src_scan, uint8_t** dst_scan, int bpp) { | |
210 *src_scan += 3; | |
211 *dst_scan += bpp; | |
212 } | |
213 | |
214 void SetAlpha(uint8_t* alpha) { | |
215 alpha[3] = 255; | |
216 } | |
217 | |
218 void SetAlphaDoNothing(uint8_t* alpha) {} | |
219 | |
220 void DrawNormalTextHelper(CFX_DIBitmap* bitmap, | |
221 const CFX_DIBitmap* pGlyph, | |
222 int nrows, | |
223 int left, | |
224 int top, | |
225 int start_col, | |
226 int end_col, | |
227 bool bNormal, | |
228 bool bBGRStripe, | |
229 int x_subpixel, | |
230 int a, | |
231 int r, | |
232 int g, | |
233 int b) { | |
234 const bool has_alpha = bitmap->GetFormat() == FXDIB_Argb; | |
235 uint8_t* src_buf = pGlyph->GetBuffer(); | |
236 int src_pitch = pGlyph->GetPitch(); | |
237 uint8_t* dest_buf = bitmap->GetBuffer(); | |
238 int dest_pitch = bitmap->GetPitch(); | |
239 const int Bpp = has_alpha ? 4 : bitmap->GetBPP() / 8; | |
240 auto* pNormalizeSrcFunc = has_alpha ? &NormalizeArgbSrc : &NormalizeRgbDst; | |
241 auto* pNormalizeDstFunc = has_alpha ? &NormalizeArgbDest : &NormalizeRgbSrc; | |
242 auto* pSetAlpha = has_alpha ? &SetAlpha : &SetAlphaDoNothing; | |
243 | |
244 for (int row = 0; row < nrows; row++) { | |
245 int dest_row = row + top; | |
246 if (dest_row < 0 || dest_row >= bitmap->GetHeight()) | |
247 continue; | |
248 | |
249 uint8_t* src_scan = src_buf + row * src_pitch + (start_col - left) * 3; | |
250 uint8_t* dest_scan = dest_buf + dest_row * dest_pitch + start_col * Bpp; | |
251 if (bBGRStripe) { | |
252 if (x_subpixel == 0) { | |
253 for (int col = start_col; col < end_col; col++) { | |
254 if (has_alpha) { | |
255 Merge(src_scan[2], r, a, &dest_scan[2]); | |
256 Merge(src_scan[1], g, a, &dest_scan[1]); | |
257 Merge(src_scan[0], b, a, &dest_scan[0]); | |
258 } else { | |
259 MergeGammaAdjustBgr(&src_scan[0], r, g, b, a, &dest_scan[0]); | |
260 } | |
261 pSetAlpha(dest_scan); | |
262 NextPixel(&src_scan, &dest_scan, Bpp); | |
263 } | |
264 } else if (x_subpixel == 1) { | |
265 MergeGammaAdjust(src_scan[1], r, a, &dest_scan[2]); | |
266 MergeGammaAdjust(src_scan[0], g, a, &dest_scan[1]); | |
267 if (start_col > left) | |
268 MergeGammaAdjust(src_scan[-1], b, a, &dest_scan[0]); | |
269 pSetAlpha(dest_scan); | |
270 NextPixel(&src_scan, &dest_scan, Bpp); | |
271 for (int col = start_col + 1; col < end_col - 1; col++) { | |
272 MergeGammaAdjustBgr(&src_scan[-1], r, g, b, a, &dest_scan[0]); | |
273 pSetAlpha(dest_scan); | |
274 NextPixel(&src_scan, &dest_scan, Bpp); | |
275 } | |
276 } else { | |
277 MergeGammaAdjust(src_scan[0], r, a, &dest_scan[2]); | |
278 if (start_col > left) { | |
279 MergeGammaAdjust(src_scan[-1], g, a, &dest_scan[1]); | |
280 MergeGammaAdjust(src_scan[-2], b, a, &dest_scan[0]); | |
281 } | |
282 pSetAlpha(dest_scan); | |
283 NextPixel(&src_scan, &dest_scan, Bpp); | |
284 for (int col = start_col + 1; col < end_col - 1; col++) { | |
285 MergeGammaAdjustBgr(&src_scan[-2], r, g, b, a, &dest_scan[0]); | |
286 pSetAlpha(dest_scan); | |
287 NextPixel(&src_scan, &dest_scan, Bpp); | |
288 } | |
289 } | |
290 } else { | |
291 if (x_subpixel == 0) { | |
292 for (int col = start_col; col < end_col; col++) { | |
293 if (bNormal) { | |
294 int src_value = AverageRgb(&src_scan[0]); | |
295 pNormalizeDstFunc(src_value, r, g, b, a, dest_scan); | |
296 } else { | |
297 MergeGammaAdjustRgb(&src_scan[0], r, g, b, a, &dest_scan[0]); | |
298 pSetAlpha(dest_scan); | |
299 } | |
300 NextPixel(&src_scan, &dest_scan, Bpp); | |
301 } | |
302 } else if (x_subpixel == 1) { | |
303 if (bNormal) { | |
304 int src_value = start_col > left ? AverageRgb(&src_scan[-1]) | |
305 : (src_scan[0] + src_scan[1]) / 3; | |
306 pNormalizeSrcFunc(src_value, r, g, b, a, dest_scan); | |
307 } else { | |
308 if (start_col > left) | |
309 MergeGammaAdjust(src_scan[-1], r, a, &dest_scan[2]); | |
310 MergeGammaAdjust(src_scan[0], g, a, &dest_scan[1]); | |
311 MergeGammaAdjust(src_scan[1], b, a, &dest_scan[0]); | |
312 pSetAlpha(dest_scan); | |
313 } | |
314 NextPixel(&src_scan, &dest_scan, Bpp); | |
315 for (int col = start_col + 1; col < end_col; col++) { | |
316 if (bNormal) { | |
317 int src_value = AverageRgb(&src_scan[-1]); | |
318 pNormalizeDstFunc(src_value, r, g, b, a, dest_scan); | |
319 } else { | |
320 MergeGammaAdjustRgb(&src_scan[-1], r, g, b, a, &dest_scan[0]); | |
321 pSetAlpha(dest_scan); | |
322 } | |
323 NextPixel(&src_scan, &dest_scan, Bpp); | |
324 } | |
325 } else { | |
326 if (bNormal) { | |
327 int src_value = | |
328 start_col > left ? AverageRgb(&src_scan[-2]) : src_scan[0] / 3; | |
329 pNormalizeSrcFunc(src_value, r, g, b, a, dest_scan); | |
330 } else { | |
331 if (start_col > left) { | |
332 MergeGammaAdjust(src_scan[-2], r, a, &dest_scan[2]); | |
333 MergeGammaAdjust(src_scan[-1], g, a, &dest_scan[1]); | |
334 } | |
335 MergeGammaAdjust(src_scan[0], b, a, &dest_scan[0]); | |
336 pSetAlpha(dest_scan); | |
337 } | |
338 NextPixel(&src_scan, &dest_scan, Bpp); | |
339 for (int col = start_col + 1; col < end_col; col++) { | |
340 if (bNormal) { | |
341 int src_value = AverageRgb(&src_scan[-2]); | |
342 pNormalizeDstFunc(src_value, r, g, b, a, dest_scan); | |
343 } else { | |
344 MergeGammaAdjustRgb(&src_scan[-2], r, g, b, a, &dest_scan[0]); | |
345 pSetAlpha(dest_scan); | |
346 } | |
347 NextPixel(&src_scan, &dest_scan, Bpp); | |
348 } | |
349 } | |
350 } | |
351 } | |
352 } | |
353 | |
354 bool ShouldDrawDeviceText(const CFX_Font* pFont, uint32_t text_flags) { | |
355 #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ | |
356 if (text_flags & FXFONT_CIDFONT) | |
357 return false; | |
358 | |
359 const CFX_ByteString bsPsName = pFont->GetPsName(); | |
360 if (bsPsName.Find("+ZJHL") != -1) | |
361 return false; | |
362 | |
363 if (bsPsName == "CNAAJI+cmex10") | |
364 return false; | |
365 #endif | |
366 return true; | |
367 } | |
368 | |
369 } // namespace | 48 } // namespace |
370 | 49 |
371 FX_RECT FXGE_GetGlyphsBBox(const std::vector<FXTEXT_GLYPHPOS>& glyphs, | 50 FX_RECT FXGE_GetGlyphsBBox(const std::vector<FXTEXT_GLYPHPOS>& glyphs, |
372 int anti_alias, | 51 int anti_alias, |
373 FX_FLOAT retinaScaleX, | 52 FX_FLOAT retinaScaleX, |
374 FX_FLOAT retinaScaleY) { | 53 FX_FLOAT retinaScaleY) { |
375 FX_RECT rect(0, 0, 0, 0); | 54 FX_RECT rect(0, 0, 0, 0); |
376 bool bStarted = false; | 55 bool bStarted = false; |
377 for (const FXTEXT_GLYPHPOS& glyph : glyphs) { | 56 for (const FXTEXT_GLYPHPOS& glyph : glyphs) { |
378 const CFX_GlyphBitmap* pGlyph = glyph.m_pGlyph; | 57 const CFX_GlyphBitmap* pGlyph = glyph.m_pGlyph; |
(...skipping 18 matching lines...) Expand all Loading... |
397 } else { | 76 } else { |
398 rect.left = std::min(rect.left, char_left); | 77 rect.left = std::min(rect.left, char_left); |
399 rect.right = std::max(rect.right, char_right); | 78 rect.right = std::max(rect.right, char_right); |
400 rect.top = std::min(rect.top, char_top); | 79 rect.top = std::min(rect.top, char_top); |
401 rect.bottom = std::max(rect.bottom, char_bottom); | 80 rect.bottom = std::max(rect.bottom, char_bottom); |
402 } | 81 } |
403 } | 82 } |
404 return rect; | 83 return rect; |
405 } | 84 } |
406 | 85 |
407 FX_BOOL CFX_RenderDevice::DrawNormalText(int nChars, | |
408 const FXTEXT_CHARPOS* pCharPos, | |
409 CFX_Font* pFont, | |
410 CFX_FontCache* pCache, | |
411 FX_FLOAT font_size, | |
412 const CFX_Matrix* pText2Device, | |
413 uint32_t fill_color, | |
414 uint32_t text_flags) { | |
415 int nativetext_flags = text_flags; | |
416 if (m_DeviceClass != FXDC_DISPLAY) { | |
417 if (!(text_flags & FXTEXT_PRINTGRAPHICTEXT)) { | |
418 if (ShouldDrawDeviceText(pFont, text_flags) && | |
419 m_pDeviceDriver->DrawDeviceText(nChars, pCharPos, pFont, pCache, | |
420 pText2Device, font_size, | |
421 fill_color)) { | |
422 return TRUE; | |
423 } | |
424 } | |
425 if (FXARGB_A(fill_color) < 255) | |
426 return FALSE; | |
427 } else if (!(text_flags & FXTEXT_NO_NATIVETEXT)) { | |
428 if (ShouldDrawDeviceText(pFont, text_flags) && | |
429 m_pDeviceDriver->DrawDeviceText(nChars, pCharPos, pFont, pCache, | |
430 pText2Device, font_size, fill_color)) { | |
431 return TRUE; | |
432 } | |
433 } | |
434 CFX_Matrix char2device; | |
435 CFX_Matrix text2Device; | |
436 if (pText2Device) { | |
437 char2device = *pText2Device; | |
438 text2Device = *pText2Device; | |
439 } | |
440 char2device.Scale(font_size, -font_size); | |
441 if (FXSYS_fabs(char2device.a) + FXSYS_fabs(char2device.b) > 50 * 1.0f || | |
442 ((m_DeviceClass == FXDC_PRINTER) && | |
443 !(text_flags & FXTEXT_PRINTIMAGETEXT))) { | |
444 if (pFont->GetFace() || | |
445 (pFont->GetSubstFont()->m_SubstFlags & FXFONT_SUBST_GLYPHPATH)) { | |
446 int nPathFlags = | |
447 (text_flags & FXTEXT_NOSMOOTH) == 0 ? 0 : FXFILL_NOPATHSMOOTH; | |
448 return DrawTextPathWithFlags(nChars, pCharPos, pFont, pCache, font_size, | |
449 pText2Device, nullptr, nullptr, fill_color, | |
450 0, nullptr, nPathFlags); | |
451 } | |
452 } | |
453 int anti_alias = FXFT_RENDER_MODE_MONO; | |
454 bool bNormal = false; | |
455 if ((text_flags & FXTEXT_NOSMOOTH) == 0) { | |
456 if (m_DeviceClass == FXDC_DISPLAY && m_bpp > 1) { | |
457 if (!CFX_GEModule::Get()->GetFontMgr()->FTLibrarySupportsHinting()) { | |
458 // Some Freetype implementations (like the one packaged with Fedora) do | |
459 // not support hinting due to patents 6219025, 6239783, 6307566, | |
460 // 6225973, 6243070, 6393145, 6421054, 6282327, and 6624828; the latest | |
461 // one expires 10/7/19. This makes LCD antialiasing very ugly, so we | |
462 // instead fall back on NORMAL antialiasing. | |
463 anti_alias = FXFT_RENDER_MODE_NORMAL; | |
464 } else if ((m_RenderCaps & (FXRC_ALPHA_OUTPUT | FXRC_CMYK_OUTPUT))) { | |
465 anti_alias = FXFT_RENDER_MODE_LCD; | |
466 bNormal = true; | |
467 } else if (m_bpp < 16) { | |
468 anti_alias = FXFT_RENDER_MODE_NORMAL; | |
469 } else { | |
470 anti_alias = FXFT_RENDER_MODE_LCD; | |
471 | |
472 bool bClearType = false; | |
473 if (pFont->GetFace() || | |
474 (pFont->GetSubstFont()->m_SubstFlags & FXFONT_SUBST_CLEARTYPE)) { | |
475 bClearType = !!(text_flags & FXTEXT_CLEARTYPE); | |
476 } | |
477 bNormal = !bClearType; | |
478 } | |
479 } | |
480 } | |
481 if (!pCache) | |
482 pCache = CFX_GEModule::Get()->GetFontCache(); | |
483 | |
484 CFX_FaceCache* pFaceCache = pCache->GetCachedFace(pFont); | |
485 CFX_AutoFontCache autoFontCache(pCache, pFont); | |
486 std::vector<FXTEXT_GLYPHPOS> glyphs(nChars); | |
487 CFX_Matrix matrixCTM = GetCTM(); | |
488 FX_FLOAT scale_x = FXSYS_fabs(matrixCTM.a); | |
489 FX_FLOAT scale_y = FXSYS_fabs(matrixCTM.d); | |
490 CFX_Matrix deviceCtm = char2device; | |
491 deviceCtm.Concat(scale_x, 0, 0, scale_y, 0, 0); | |
492 text2Device.Concat(scale_x, 0, 0, scale_y, 0, 0); | |
493 for (size_t i = 0; i < glyphs.size(); ++i) { | |
494 FXTEXT_GLYPHPOS& glyph = glyphs[i]; | |
495 const FXTEXT_CHARPOS& charpos = pCharPos[i]; | |
496 glyph.m_fOriginX = charpos.m_OriginX; | |
497 glyph.m_fOriginY = charpos.m_OriginY; | |
498 text2Device.Transform(glyph.m_fOriginX, glyph.m_fOriginY); | |
499 if (anti_alias < FXFT_RENDER_MODE_LCD) { | |
500 glyph.m_OriginX = FXSYS_round(glyph.m_fOriginX); | |
501 } else { | |
502 glyph.m_OriginX = (int)FXSYS_floor(glyph.m_fOriginX); | |
503 } | |
504 glyph.m_OriginY = FXSYS_round(glyph.m_fOriginY); | |
505 if (charpos.m_bGlyphAdjust) { | |
506 CFX_Matrix new_matrix( | |
507 charpos.m_AdjustMatrix[0], charpos.m_AdjustMatrix[1], | |
508 charpos.m_AdjustMatrix[2], charpos.m_AdjustMatrix[3], 0, 0); | |
509 new_matrix.Concat(deviceCtm); | |
510 glyph.m_pGlyph = pFaceCache->LoadGlyphBitmap( | |
511 pFont, charpos.m_GlyphIndex, charpos.m_bFontStyle, &new_matrix, | |
512 charpos.m_FontCharWidth, anti_alias, nativetext_flags); | |
513 } else { | |
514 glyph.m_pGlyph = pFaceCache->LoadGlyphBitmap( | |
515 pFont, charpos.m_GlyphIndex, charpos.m_bFontStyle, &deviceCtm, | |
516 charpos.m_FontCharWidth, anti_alias, nativetext_flags); | |
517 } | |
518 } | |
519 if (anti_alias < FXFT_RENDER_MODE_LCD && glyphs.size() > 1) | |
520 AdjustGlyphSpace(&glyphs); | |
521 | |
522 FX_RECT bmp_rect1 = FXGE_GetGlyphsBBox(glyphs, anti_alias); | |
523 if (scale_x > 1 && scale_y > 1) { | |
524 bmp_rect1.left--; | |
525 bmp_rect1.top--; | |
526 bmp_rect1.right++; | |
527 bmp_rect1.bottom++; | |
528 } | |
529 FX_RECT bmp_rect(FXSYS_round((FX_FLOAT)(bmp_rect1.left) / scale_x), | |
530 FXSYS_round((FX_FLOAT)(bmp_rect1.top) / scale_y), | |
531 FXSYS_round((FX_FLOAT)bmp_rect1.right / scale_x), | |
532 FXSYS_round((FX_FLOAT)bmp_rect1.bottom / scale_y)); | |
533 bmp_rect.Intersect(m_ClipBox); | |
534 if (bmp_rect.IsEmpty()) | |
535 return TRUE; | |
536 | |
537 int pixel_width = FXSYS_round(bmp_rect.Width() * scale_x); | |
538 int pixel_height = FXSYS_round(bmp_rect.Height() * scale_y); | |
539 int pixel_left = FXSYS_round(bmp_rect.left * scale_x); | |
540 int pixel_top = FXSYS_round(bmp_rect.top * scale_y); | |
541 if (anti_alias == FXFT_RENDER_MODE_MONO) { | |
542 CFX_DIBitmap bitmap; | |
543 if (!bitmap.Create(pixel_width, pixel_height, FXDIB_1bppMask)) | |
544 return FALSE; | |
545 | |
546 bitmap.Clear(0); | |
547 for (const FXTEXT_GLYPHPOS& glyph : glyphs) { | |
548 if (!glyph.m_pGlyph) | |
549 continue; | |
550 | |
551 const CFX_DIBitmap* pGlyph = &glyph.m_pGlyph->m_Bitmap; | |
552 bitmap.TransferBitmap( | |
553 glyph.m_OriginX + glyph.m_pGlyph->m_Left - pixel_left, | |
554 glyph.m_OriginY - glyph.m_pGlyph->m_Top - pixel_top, | |
555 pGlyph->GetWidth(), pGlyph->GetHeight(), pGlyph, 0, 0); | |
556 } | |
557 return SetBitMask(&bitmap, bmp_rect.left, bmp_rect.top, fill_color); | |
558 } | |
559 CFX_DIBitmap bitmap; | |
560 if (m_bpp == 8) { | |
561 if (!bitmap.Create(pixel_width, pixel_height, FXDIB_8bppMask)) | |
562 return FALSE; | |
563 } else { | |
564 if (!CreateCompatibleBitmap(&bitmap, pixel_width, pixel_height)) | |
565 return FALSE; | |
566 } | |
567 | |
568 if (!bitmap.HasAlpha() && !bitmap.IsAlphaMask()) { | |
569 bitmap.Clear(0xFFFFFFFF); | |
570 if (!GetDIBits(&bitmap, bmp_rect.left, bmp_rect.top)) | |
571 return FALSE; | |
572 } else { | |
573 bitmap.Clear(0); | |
574 if (bitmap.m_pAlphaMask) { | |
575 bitmap.m_pAlphaMask->Clear(0); | |
576 } | |
577 } | |
578 | |
579 int dest_width = pixel_width; | |
580 int a = 0; | |
581 int r = 0; | |
582 int g = 0; | |
583 int b = 0; | |
584 if (anti_alias == FXFT_RENDER_MODE_LCD) | |
585 ArgbDecode(fill_color, a, r, g, b); | |
586 | |
587 for (const FXTEXT_GLYPHPOS& glyph : glyphs) { | |
588 if (!glyph.m_pGlyph) | |
589 continue; | |
590 | |
591 const CFX_DIBitmap* pGlyph = &glyph.m_pGlyph->m_Bitmap; | |
592 int left = glyph.m_OriginX + glyph.m_pGlyph->m_Left - pixel_left; | |
593 int top = glyph.m_OriginY - glyph.m_pGlyph->m_Top - pixel_top; | |
594 int ncols = pGlyph->GetWidth(); | |
595 int nrows = pGlyph->GetHeight(); | |
596 if (anti_alias == FXFT_RENDER_MODE_NORMAL) { | |
597 if (!bitmap.CompositeMask(left, top, ncols, nrows, pGlyph, fill_color, 0, | |
598 0, FXDIB_BLEND_NORMAL, nullptr, FALSE, 0, | |
599 nullptr)) { | |
600 return FALSE; | |
601 } | |
602 continue; | |
603 } | |
604 | |
605 bool bBGRStripe = !!(text_flags & FXTEXT_BGR_STRIPE); | |
606 ncols /= 3; | |
607 int x_subpixel = (int)(glyph.m_fOriginX * 3) % 3; | |
608 int start_col = std::max(left, 0); | |
609 int end_col = std::min(left + ncols, dest_width); | |
610 if (start_col >= end_col) | |
611 continue; | |
612 | |
613 DrawNormalTextHelper(&bitmap, pGlyph, nrows, left, top, start_col, end_col, | |
614 bNormal, bBGRStripe, x_subpixel, a, r, g, b); | |
615 } | |
616 if (bitmap.IsAlphaMask()) | |
617 SetBitMask(&bitmap, bmp_rect.left, bmp_rect.top, fill_color); | |
618 else | |
619 SetDIBits(&bitmap, bmp_rect.left, bmp_rect.top); | |
620 return TRUE; | |
621 } | |
622 | |
623 FX_BOOL CFX_RenderDevice::DrawTextPathWithFlags( | |
624 int nChars, | |
625 const FXTEXT_CHARPOS* pCharPos, | |
626 CFX_Font* pFont, | |
627 CFX_FontCache* pCache, | |
628 FX_FLOAT font_size, | |
629 const CFX_Matrix* pText2User, | |
630 const CFX_Matrix* pUser2Device, | |
631 const CFX_GraphStateData* pGraphState, | |
632 uint32_t fill_color, | |
633 FX_ARGB stroke_color, | |
634 CFX_PathData* pClippingPath, | |
635 int nFlag) { | |
636 if (!pCache) | |
637 pCache = CFX_GEModule::Get()->GetFontCache(); | |
638 | |
639 CFX_FaceCache* pFaceCache = pCache->GetCachedFace(pFont); | |
640 CFX_AutoFontCache autoFontCache(pCache, pFont); | |
641 for (int iChar = 0; iChar < nChars; iChar++) { | |
642 const FXTEXT_CHARPOS& charpos = pCharPos[iChar]; | |
643 CFX_Matrix matrix; | |
644 if (charpos.m_bGlyphAdjust) | |
645 matrix.Set(charpos.m_AdjustMatrix[0], charpos.m_AdjustMatrix[1], | |
646 charpos.m_AdjustMatrix[2], charpos.m_AdjustMatrix[3], 0, 0); | |
647 matrix.Concat(font_size, 0, 0, font_size, charpos.m_OriginX, | |
648 charpos.m_OriginY); | |
649 const CFX_PathData* pPath = pFaceCache->LoadGlyphPath( | |
650 pFont, charpos.m_GlyphIndex, charpos.m_FontCharWidth); | |
651 if (!pPath) | |
652 continue; | |
653 | |
654 matrix.Concat(*pText2User); | |
655 CFX_PathData TransformedPath(*pPath); | |
656 TransformedPath.Transform(&matrix); | |
657 if (fill_color || stroke_color) { | |
658 int fill_mode = nFlag; | |
659 if (fill_color) | |
660 fill_mode |= FXFILL_WINDING; | |
661 fill_mode |= FX_FILL_TEXT_MODE; | |
662 if (!DrawPathWithBlend(&TransformedPath, pUser2Device, pGraphState, | |
663 fill_color, stroke_color, fill_mode, | |
664 FXDIB_BLEND_NORMAL)) { | |
665 return FALSE; | |
666 } | |
667 } | |
668 if (pClippingPath) | |
669 pClippingPath->Append(&TransformedPath, pUser2Device); | |
670 } | |
671 return TRUE; | |
672 } | |
673 | |
674 CFX_FontCache::CFX_FontCache() {} | 86 CFX_FontCache::CFX_FontCache() {} |
675 | 87 |
676 CFX_FontCache::~CFX_FontCache() { | 88 CFX_FontCache::~CFX_FontCache() { |
677 FreeCache(TRUE); | 89 FreeCache(TRUE); |
678 } | 90 } |
679 | 91 |
680 CFX_FaceCache* CFX_FontCache::GetCachedFace(CFX_Font* pFont) { | 92 CFX_FaceCache* CFX_FontCache::GetCachedFace(CFX_Font* pFont) { |
681 FXFT_Face internal_face = pFont->GetFace(); | 93 FXFT_Face internal_face = pFont->GetFace(); |
682 const bool bExternal = !internal_face; | 94 const bool bExternal = !internal_face; |
683 FXFT_Face face = | 95 FXFT_Face face = |
(...skipping 721 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1405 void _CFX_UniqueKeyGen::Generate(int count, ...) { | 817 void _CFX_UniqueKeyGen::Generate(int count, ...) { |
1406 va_list argList; | 818 va_list argList; |
1407 va_start(argList, count); | 819 va_start(argList, count); |
1408 for (int i = 0; i < count; i++) { | 820 for (int i = 0; i < count; i++) { |
1409 int p = va_arg(argList, int); | 821 int p = va_arg(argList, int); |
1410 ((uint32_t*)m_Key)[i] = p; | 822 ((uint32_t*)m_Key)[i] = p; |
1411 } | 823 } |
1412 va_end(argList); | 824 va_end(argList); |
1413 m_KeyLen = count * sizeof(uint32_t); | 825 m_KeyLen = count * sizeof(uint32_t); |
1414 } | 826 } |
OLD | NEW |