4 * Copyright 2014-2015 Nikolay Sivov for CodeWeavers
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 #include "wine/port.h"
26 #ifdef HAVE_FT2BUILD_H
29 #include FT_FREETYPE_H
31 #include FT_TRUETYPE_TABLES_H
32 #endif /* HAVE_FT2BUILD_H */
36 #include "wine/library.h"
37 #include "wine/debug.h"
39 #include "dwrite_private.h"
41 WINE_DEFAULT_DEBUG_CHANNEL(dwrite
);
45 static CRITICAL_SECTION freetype_cs
;
46 static CRITICAL_SECTION_DEBUG critsect_debug
=
49 { &critsect_debug
.ProcessLocksList
, &critsect_debug
.ProcessLocksList
},
50 0, 0, { (DWORD_PTR
)(__FILE__
": freetype_cs") }
52 static CRITICAL_SECTION freetype_cs
= { &critsect_debug
, -1, 0, 0, 0, 0 };
54 static void *ft_handle
= NULL
;
55 static FT_Library library
= 0;
56 static FTC_Manager cache_manager
= 0;
57 static FTC_CMapCache cmap_cache
= 0;
58 static FTC_ImageCache image_cache
= 0;
66 #define MAKE_FUNCPTR(f) static typeof(f) * p##f = NULL
67 MAKE_FUNCPTR(FT_Done_FreeType
);
68 MAKE_FUNCPTR(FT_Done_Glyph
);
69 MAKE_FUNCPTR(FT_Get_First_Char
);
70 MAKE_FUNCPTR(FT_Get_Kerning
);
71 MAKE_FUNCPTR(FT_Get_Sfnt_Table
);
72 MAKE_FUNCPTR(FT_Glyph_Copy
);
73 MAKE_FUNCPTR(FT_Glyph_Get_CBox
);
74 MAKE_FUNCPTR(FT_Glyph_Transform
);
75 MAKE_FUNCPTR(FT_Init_FreeType
);
76 MAKE_FUNCPTR(FT_Library_Version
);
77 MAKE_FUNCPTR(FT_Load_Glyph
);
78 MAKE_FUNCPTR(FT_New_Memory_Face
);
79 MAKE_FUNCPTR(FT_Outline_Copy
);
80 MAKE_FUNCPTR(FT_Outline_Done
);
81 MAKE_FUNCPTR(FT_Outline_Get_Bitmap
);
82 MAKE_FUNCPTR(FT_Outline_New
);
83 MAKE_FUNCPTR(FT_Outline_Transform
);
84 MAKE_FUNCPTR(FT_Outline_Translate
);
85 MAKE_FUNCPTR(FTC_CMapCache_Lookup
);
86 MAKE_FUNCPTR(FTC_CMapCache_New
);
87 MAKE_FUNCPTR(FTC_ImageCache_Lookup
);
88 MAKE_FUNCPTR(FTC_ImageCache_New
);
89 MAKE_FUNCPTR(FTC_Manager_New
);
90 MAKE_FUNCPTR(FTC_Manager_Done
);
91 MAKE_FUNCPTR(FTC_Manager_LookupFace
);
92 MAKE_FUNCPTR(FTC_Manager_LookupSize
);
93 MAKE_FUNCPTR(FTC_Manager_RemoveFaceID
);
96 static FT_Error
face_requester(FTC_FaceID face_id
, FT_Library library
, FT_Pointer request_data
, FT_Face
*face
)
98 IDWriteFontFace
*fontface
= (IDWriteFontFace
*)face_id
;
99 IDWriteFontFileStream
*stream
;
100 IDWriteFontFile
*file
;
101 const void *data_ptr
;
111 hr
= IDWriteFontFace_GetFiles(fontface
, &count
, &file
);
115 hr
= get_filestream_from_file(file
, &stream
);
116 IDWriteFontFile_Release(file
);
120 hr
= IDWriteFontFileStream_GetFileSize(stream
, &data_size
);
122 fterror
= FT_Err_Invalid_Stream_Read
;
126 hr
= IDWriteFontFileStream_ReadFileFragment(stream
, &data_ptr
, 0, data_size
, &context
);
128 fterror
= FT_Err_Invalid_Stream_Read
;
132 index
= IDWriteFontFace_GetIndex(fontface
);
133 fterror
= pFT_New_Memory_Face(library
, data_ptr
, data_size
, index
, face
);
134 IDWriteFontFileStream_ReleaseFileFragment(stream
, context
);
137 IDWriteFontFileStream_Release(stream
);
142 BOOL
init_freetype(void)
144 FT_Version_t FT_Version
;
146 ft_handle
= wine_dlopen(SONAME_LIBFREETYPE
, RTLD_NOW
, NULL
, 0);
148 WINE_MESSAGE("Wine cannot find the FreeType font library.\n");
152 #define LOAD_FUNCPTR(f) if((p##f = wine_dlsym(ft_handle, #f, NULL, 0)) == NULL){WARN("Can't find symbol %s\n", #f); goto sym_not_found;}
153 LOAD_FUNCPTR(FT_Done_FreeType
)
154 LOAD_FUNCPTR(FT_Done_Glyph
)
155 LOAD_FUNCPTR(FT_Get_First_Char
)
156 LOAD_FUNCPTR(FT_Get_Kerning
)
157 LOAD_FUNCPTR(FT_Get_Sfnt_Table
)
158 LOAD_FUNCPTR(FT_Glyph_Copy
)
159 LOAD_FUNCPTR(FT_Glyph_Get_CBox
)
160 LOAD_FUNCPTR(FT_Glyph_Transform
)
161 LOAD_FUNCPTR(FT_Init_FreeType
)
162 LOAD_FUNCPTR(FT_Library_Version
)
163 LOAD_FUNCPTR(FT_Load_Glyph
)
164 LOAD_FUNCPTR(FT_New_Memory_Face
)
165 LOAD_FUNCPTR(FT_Outline_Copy
)
166 LOAD_FUNCPTR(FT_Outline_Done
)
167 LOAD_FUNCPTR(FT_Outline_Get_Bitmap
)
168 LOAD_FUNCPTR(FT_Outline_New
)
169 LOAD_FUNCPTR(FT_Outline_Transform
)
170 LOAD_FUNCPTR(FT_Outline_Translate
)
171 LOAD_FUNCPTR(FTC_CMapCache_Lookup
)
172 LOAD_FUNCPTR(FTC_CMapCache_New
)
173 LOAD_FUNCPTR(FTC_ImageCache_Lookup
)
174 LOAD_FUNCPTR(FTC_ImageCache_New
)
175 LOAD_FUNCPTR(FTC_Manager_New
)
176 LOAD_FUNCPTR(FTC_Manager_Done
)
177 LOAD_FUNCPTR(FTC_Manager_LookupFace
)
178 LOAD_FUNCPTR(FTC_Manager_LookupSize
)
179 LOAD_FUNCPTR(FTC_Manager_RemoveFaceID
)
182 if (pFT_Init_FreeType(&library
) != 0) {
183 ERR("Can't init FreeType library\n");
184 wine_dlclose(ft_handle
, NULL
, 0);
188 pFT_Library_Version(library
, &FT_Version
.major
, &FT_Version
.minor
, &FT_Version
.patch
);
190 /* init cache manager */
191 if (pFTC_Manager_New(library
, 0, 0, 0, &face_requester
, NULL
, &cache_manager
) != 0 ||
192 pFTC_CMapCache_New(cache_manager
, &cmap_cache
) != 0 ||
193 pFTC_ImageCache_New(cache_manager
, &image_cache
) != 0) {
195 ERR("Failed to init FreeType cache\n");
196 pFTC_Manager_Done(cache_manager
);
197 pFT_Done_FreeType(library
);
198 wine_dlclose(ft_handle
, NULL
, 0);
203 TRACE("FreeType version is %d.%d.%d\n", FT_Version
.major
, FT_Version
.minor
, FT_Version
.patch
);
207 WINE_MESSAGE("Wine cannot find certain functions that it needs from FreeType library.\n");
208 wine_dlclose(ft_handle
, NULL
, 0);
213 void release_freetype(void)
215 pFTC_Manager_Done(cache_manager
);
216 pFT_Done_FreeType(library
);
219 void freetype_notify_cacheremove(IDWriteFontFace2
*fontface
)
221 EnterCriticalSection(&freetype_cs
);
222 pFTC_Manager_RemoveFaceID(cache_manager
, fontface
);
223 LeaveCriticalSection(&freetype_cs
);
226 HRESULT
freetype_get_design_glyph_metrics(IDWriteFontFace2
*fontface
, UINT16 unitsperEm
, UINT16 glyph
, DWRITE_GLYPH_METRICS
*ret
)
228 FTC_ScalerRec scaler
;
231 scaler
.face_id
= fontface
;
232 scaler
.width
= unitsperEm
;
233 scaler
.height
= unitsperEm
;
238 EnterCriticalSection(&freetype_cs
);
239 if (pFTC_Manager_LookupSize(cache_manager
, &scaler
, &size
) == 0) {
240 if (pFT_Load_Glyph(size
->face
, glyph
, FT_LOAD_NO_SCALE
) == 0) {
241 FT_Glyph_Metrics
*metrics
= &size
->face
->glyph
->metrics
;
243 ret
->leftSideBearing
= metrics
->horiBearingX
;
244 ret
->advanceWidth
= metrics
->horiAdvance
;
245 ret
->rightSideBearing
= metrics
->horiAdvance
- metrics
->horiBearingX
- metrics
->width
;
246 ret
->topSideBearing
= metrics
->vertBearingY
;
247 ret
->advanceHeight
= metrics
->vertAdvance
;
248 ret
->bottomSideBearing
= metrics
->vertAdvance
- metrics
->vertBearingY
- metrics
->height
;
249 ret
->verticalOriginY
= metrics
->height
+ metrics
->vertBearingY
;
252 LeaveCriticalSection(&freetype_cs
);
257 BOOL
freetype_is_monospaced(IDWriteFontFace2
*fontface
)
259 BOOL is_monospaced
= FALSE
;
262 EnterCriticalSection(&freetype_cs
);
263 if (pFTC_Manager_LookupFace(cache_manager
, fontface
, &face
) == 0)
264 is_monospaced
= FT_IS_FIXED_WIDTH(face
);
265 LeaveCriticalSection(&freetype_cs
);
267 return is_monospaced
;
270 static inline void ft_vector_to_d2d_point(const FT_Vector
*v
, D2D1_POINT_2F
*p
)
276 /* Convert the quadratic Beziers to cubic Beziers. */
277 static void get_cubic_glyph_outline(const FT_Outline
*outline
, short point
, short first_pt
,
278 short contour
, FT_Vector
*cubic_control
)
281 The parametric eqn for a cubic Bezier is, from PLRM:
282 r(t) = at^3 + bt^2 + ct + r0
283 with the control points:
288 A quadratic Bezier has the form:
289 p(t) = (1-t)^2 p0 + 2(1-t)t p1 + t^2 p2
291 So equating powers of t leads to:
294 and of course r0 = p0, r3 = p2
297 /* FIXME: Possible optimization in endpoint calculation
298 if there are two consecutive curves */
299 cubic_control
[0] = outline
->points
[point
-1];
300 if (!(outline
->tags
[point
-1] & FT_Curve_Tag_On
)) {
301 cubic_control
[0].x
+= outline
->points
[point
].x
+ 1;
302 cubic_control
[0].y
+= outline
->points
[point
].y
+ 1;
303 cubic_control
[0].x
>>= 1;
304 cubic_control
[0].y
>>= 1;
306 if (point
+1 > outline
->contours
[contour
])
307 cubic_control
[3] = outline
->points
[first_pt
];
309 cubic_control
[3] = outline
->points
[point
+1];
310 if (!(outline
->tags
[point
+1] & FT_Curve_Tag_On
)) {
311 cubic_control
[3].x
+= outline
->points
[point
].x
+ 1;
312 cubic_control
[3].y
+= outline
->points
[point
].y
+ 1;
313 cubic_control
[3].x
>>= 1;
314 cubic_control
[3].y
>>= 1;
318 /* r1 = 1/3 p0 + 2/3 p1
319 r2 = 1/3 p2 + 2/3 p1 */
320 cubic_control
[1].x
= (2 * outline
->points
[point
].x
+ 1) / 3;
321 cubic_control
[1].y
= (2 * outline
->points
[point
].y
+ 1) / 3;
322 cubic_control
[2] = cubic_control
[1];
323 cubic_control
[1].x
+= (cubic_control
[0].x
+ 1) / 3;
324 cubic_control
[1].y
+= (cubic_control
[0].y
+ 1) / 3;
325 cubic_control
[2].x
+= (cubic_control
[3].x
+ 1) / 3;
326 cubic_control
[2].y
+= (cubic_control
[3].y
+ 1) / 3;
329 static short get_outline_data(const FT_Outline
*outline
, struct glyph_outline
*ret
)
331 short contour
, point
= 0, first_pt
, count
;
333 for (contour
= 0, count
= 0; contour
< outline
->n_contours
; contour
++) {
336 ft_vector_to_d2d_point(&outline
->points
[point
], &ret
->points
[count
]);
337 ret
->tags
[count
] = OUTLINE_POINT_START
;
339 ret
->tags
[count
-1] |= OUTLINE_POINT_END
;
345 while (point
<= outline
->contours
[contour
]) {
347 if (outline
->tags
[point
] & FT_Curve_Tag_On
) {
349 ft_vector_to_d2d_point(&outline
->points
[point
], &ret
->points
[count
]);
350 ret
->tags
[count
] |= OUTLINE_POINT_LINE
;
359 FT_Vector cubic_control
[4];
361 get_cubic_glyph_outline(outline
, point
, first_pt
, contour
, cubic_control
);
362 ft_vector_to_d2d_point(&cubic_control
[1], &ret
->points
[count
]);
363 ft_vector_to_d2d_point(&cubic_control
[2], &ret
->points
[count
+1]);
364 ft_vector_to_d2d_point(&cubic_control
[3], &ret
->points
[count
+2]);
365 ret
->tags
[count
] = OUTLINE_POINT_BEZIER
;
366 ret
->tags
[count
+1] = OUTLINE_POINT_BEZIER
;
367 ret
->tags
[count
+2] = OUTLINE_POINT_BEZIER
;
373 } while (point
<= outline
->contours
[contour
] &&
374 (outline
->tags
[point
] & FT_Curve_Tag_On
) ==
375 (outline
->tags
[point
-1] & FT_Curve_Tag_On
));
377 if (point
<= outline
->contours
[contour
] &&
378 outline
->tags
[point
] & FT_Curve_Tag_On
)
380 /* This is the closing pt of a bezier, but we've already
381 added it, so just inc point and carry on */
388 ret
->tags
[count
-1] |= OUTLINE_POINT_END
;
393 HRESULT
freetype_get_glyph_outline(IDWriteFontFace2
*fontface
, FLOAT emSize
, UINT16 index
, USHORT simulations
, struct glyph_outline
**ret
)
395 FTC_ScalerRec scaler
;
399 scaler
.face_id
= fontface
;
400 scaler
.width
= emSize
;
401 scaler
.height
= emSize
;
406 EnterCriticalSection(&freetype_cs
);
407 if (pFTC_Manager_LookupSize(cache_manager
, &scaler
, &size
) == 0) {
408 if (pFT_Load_Glyph(size
->face
, index
, FT_LOAD_NO_BITMAP
) == 0) {
409 FT_Outline
*outline
= &size
->face
->glyph
->outline
;
414 m
.xy
= simulations
& DWRITE_FONT_SIMULATIONS_OBLIQUE
? (1 << 16) / 3 : 0;
416 m
.yy
= -(1 << 16); /* flip Y axis */
418 pFT_Outline_Transform(outline
, &m
);
420 count
= get_outline_data(outline
, NULL
);
421 hr
= new_glyph_outline(count
, ret
);
423 get_outline_data(outline
, *ret
);
424 (*ret
)->advance
= size
->face
->glyph
->metrics
.horiAdvance
>> 6;
428 LeaveCriticalSection(&freetype_cs
);
433 UINT16
freetype_get_glyphcount(IDWriteFontFace2
*fontface
)
438 EnterCriticalSection(&freetype_cs
);
439 if (pFTC_Manager_LookupFace(cache_manager
, fontface
, &face
) == 0)
440 count
= face
->num_glyphs
;
441 LeaveCriticalSection(&freetype_cs
);
446 UINT16
freetype_get_glyphindex(IDWriteFontFace2
*fontface
, UINT32 codepoint
, INT charmap
)
450 EnterCriticalSection(&freetype_cs
);
452 glyph
= pFTC_CMapCache_Lookup(cmap_cache
, fontface
, charmap
, codepoint
);
454 /* special handling for symbol fonts */
455 if (codepoint
< 0x100) codepoint
+= 0xf000;
456 glyph
= pFTC_CMapCache_Lookup(cmap_cache
, fontface
, charmap
, codepoint
);
458 glyph
= pFTC_CMapCache_Lookup(cmap_cache
, fontface
, charmap
, codepoint
- 0xf000);
460 LeaveCriticalSection(&freetype_cs
);
465 BOOL
freetype_has_kerning_pairs(IDWriteFontFace2
*fontface
)
467 BOOL has_kerning_pairs
= FALSE
;
470 EnterCriticalSection(&freetype_cs
);
471 if (pFTC_Manager_LookupFace(cache_manager
, fontface
, &face
) == 0)
472 has_kerning_pairs
= FT_HAS_KERNING(face
);
473 LeaveCriticalSection(&freetype_cs
);
475 return has_kerning_pairs
;
478 INT32
freetype_get_kerning_pair_adjustment(IDWriteFontFace2
*fontface
, UINT16 left
, UINT16 right
)
480 INT32 adjustment
= 0;
483 EnterCriticalSection(&freetype_cs
);
484 if (pFTC_Manager_LookupFace(cache_manager
, fontface
, &face
) == 0) {
486 if (FT_HAS_KERNING(face
)) {
487 pFT_Get_Kerning(face
, left
, right
, FT_KERNING_UNSCALED
, &kern
);
491 LeaveCriticalSection(&freetype_cs
);
496 static inline void ft_matrix_from_dwrite_matrix(const DWRITE_MATRIX
*m
, FT_Matrix
*ft_matrix
)
498 ft_matrix
->xx
= m
->m11
* 0x10000;
499 ft_matrix
->xy
= -m
->m21
* 0x10000;
500 ft_matrix
->yx
= -m
->m12
* 0x10000;
501 ft_matrix
->yy
= m
->m22
* 0x10000;
504 /* Should be used only while holding 'freetype_cs' */
505 static BOOL
is_face_scalable(IDWriteFontFace2
*fontface
)
508 if (pFTC_Manager_LookupFace(cache_manager
, fontface
, &face
) == 0)
509 return FT_IS_SCALABLE(face
);
514 void freetype_get_glyph_bbox(struct dwrite_glyphbitmap
*bitmap
)
516 FTC_ImageTypeRec imagetype
;
517 FT_BBox bbox
= { 0 };
520 EnterCriticalSection(&freetype_cs
);
522 /* Some fonts provide mostly bitmaps and very few outlines, for example for .notdef,
523 disable transform if that's the case. */
525 if (!is_face_scalable(bitmap
->fontface
))
529 imagetype
.face_id
= bitmap
->fontface
;
531 imagetype
.height
= bitmap
->emsize
;
532 imagetype
.flags
= bitmap
->m
? FT_LOAD_NO_BITMAP
: FT_LOAD_DEFAULT
;
534 if (pFTC_ImageCache_Lookup(image_cache
, &imagetype
, bitmap
->index
, &glyph
, NULL
) == 0) {
538 if (pFT_Glyph_Copy(glyph
, &glyph_copy
) == 0) {
541 ft_matrix_from_dwrite_matrix(bitmap
->m
, &ft_matrix
);
542 pFT_Glyph_Transform(glyph_copy
, &ft_matrix
, NULL
);
543 pFT_Glyph_Get_CBox(glyph_copy
, FT_GLYPH_BBOX_PIXELS
, &bbox
);
544 pFT_Done_Glyph(glyph_copy
);
548 pFT_Glyph_Get_CBox(glyph
, FT_GLYPH_BBOX_PIXELS
, &bbox
);
551 LeaveCriticalSection(&freetype_cs
);
554 bitmap
->bbox
.left
= bbox
.xMin
;
555 bitmap
->bbox
.right
= bbox
.xMax
;
556 bitmap
->bbox
.top
= -bbox
.yMax
;
557 bitmap
->bbox
.bottom
= -bbox
.yMin
;
560 static BOOL
freetype_get_aliased_glyph_bitmap(struct dwrite_glyphbitmap
*bitmap
, FT_Glyph glyph
)
562 const RECT
*bbox
= &bitmap
->bbox
;
563 int width
= bbox
->right
- bbox
->left
;
564 int height
= bbox
->bottom
- bbox
->top
;
566 if (glyph
->format
== FT_GLYPH_FORMAT_OUTLINE
) {
567 FT_OutlineGlyph outline
= (FT_OutlineGlyph
)glyph
;
568 const FT_Outline
*src
= &outline
->outline
;
572 ft_bitmap
.width
= width
;
573 ft_bitmap
.rows
= height
;
574 ft_bitmap
.pitch
= bitmap
->pitch
;
575 ft_bitmap
.pixel_mode
= FT_PIXEL_MODE_MONO
;
576 ft_bitmap
.buffer
= bitmap
->buf
;
578 /* Note: FreeType will only set 'black' bits for us. */
579 if (pFT_Outline_New(library
, src
->n_points
, src
->n_contours
, ©
) == 0) {
580 pFT_Outline_Copy(src
, ©
);
581 pFT_Outline_Translate(©
, -bbox
->left
<< 6, bbox
->bottom
<< 6);
582 pFT_Outline_Get_Bitmap(library
, ©
, &ft_bitmap
);
583 pFT_Outline_Done(library
, ©
);
586 else if (glyph
->format
== FT_GLYPH_FORMAT_BITMAP
) {
587 FT_Bitmap
*ft_bitmap
= &((FT_BitmapGlyph
)glyph
)->bitmap
;
588 BYTE
*src
= ft_bitmap
->buffer
, *dst
= bitmap
->buf
;
589 int w
= min(bitmap
->pitch
, (ft_bitmap
->width
+ 7) >> 3);
590 int h
= min(height
, ft_bitmap
->rows
);
594 src
+= ft_bitmap
->pitch
;
595 dst
+= bitmap
->pitch
;
599 FIXME("format %x not handled\n", glyph
->format
);
604 static BOOL
freetype_get_aa_glyph_bitmap(struct dwrite_glyphbitmap
*bitmap
, FT_Glyph glyph
)
606 const RECT
*bbox
= &bitmap
->bbox
;
607 int width
= bbox
->right
- bbox
->left
;
608 int height
= bbox
->bottom
- bbox
->top
;
611 if (glyph
->format
== FT_GLYPH_FORMAT_OUTLINE
) {
612 FT_OutlineGlyph outline
= (FT_OutlineGlyph
)glyph
;
613 const FT_Outline
*src
= &outline
->outline
;
617 ft_bitmap
.width
= width
;
618 ft_bitmap
.rows
= height
;
619 ft_bitmap
.pitch
= bitmap
->pitch
;
620 ft_bitmap
.pixel_mode
= FT_PIXEL_MODE_GRAY
;
621 ft_bitmap
.buffer
= bitmap
->buf
;
623 /* Note: FreeType will only set 'black' bits for us. */
624 if (pFT_Outline_New(library
, src
->n_points
, src
->n_contours
, ©
) == 0) {
625 pFT_Outline_Copy(src
, ©
);
626 pFT_Outline_Translate(©
, -bbox
->left
<< 6, bbox
->bottom
<< 6);
627 pFT_Outline_Get_Bitmap(library
, ©
, &ft_bitmap
);
628 pFT_Outline_Done(library
, ©
);
631 else if (glyph
->format
== FT_GLYPH_FORMAT_BITMAP
) {
632 FT_Bitmap
*ft_bitmap
= &((FT_BitmapGlyph
)glyph
)->bitmap
;
633 BYTE
*src
= ft_bitmap
->buffer
, *dst
= bitmap
->buf
;
634 int w
= min(bitmap
->pitch
, (ft_bitmap
->width
+ 7) >> 3);
635 int h
= min(height
, ft_bitmap
->rows
);
639 src
+= ft_bitmap
->pitch
;
640 dst
+= bitmap
->pitch
;
646 FIXME("format %x not handled\n", glyph
->format
);
651 BOOL
freetype_get_glyph_bitmap(struct dwrite_glyphbitmap
*bitmap
)
653 FTC_ImageTypeRec imagetype
;
657 EnterCriticalSection(&freetype_cs
);
660 if (!is_face_scalable(bitmap
->fontface
))
664 imagetype
.face_id
= bitmap
->fontface
;
666 imagetype
.height
= bitmap
->emsize
;
667 imagetype
.flags
= bitmap
->m
? FT_LOAD_NO_BITMAP
: FT_LOAD_DEFAULT
;
669 if (pFTC_ImageCache_Lookup(image_cache
, &imagetype
, bitmap
->index
, &glyph
, NULL
) == 0) {
673 if (pFT_Glyph_Copy(glyph
, &glyph_copy
) == 0) {
676 ft_matrix_from_dwrite_matrix(bitmap
->m
, &ft_matrix
);
677 pFT_Glyph_Transform(glyph_copy
, &ft_matrix
, NULL
);
684 if (bitmap
->type
== DWRITE_TEXTURE_CLEARTYPE_3x1
)
685 ret
= freetype_get_aa_glyph_bitmap(bitmap
, glyph
);
687 ret
= freetype_get_aliased_glyph_bitmap(bitmap
, glyph
);
690 pFT_Done_Glyph(glyph_copy
);
693 LeaveCriticalSection(&freetype_cs
);
698 INT
freetype_get_charmap_index(IDWriteFontFace2
*fontface
, BOOL
*is_symbol
)
700 INT charmap_index
= -1;
705 EnterCriticalSection(&freetype_cs
);
706 if (pFTC_Manager_LookupFace(cache_manager
, fontface
, &face
) == 0) {
707 TT_OS2
*os2
= pFT_Get_Sfnt_Table(face
, ft_sfnt_os2
);
712 if (os2
->version
== 0)
713 *is_symbol
= pFT_Get_First_Char(face
, &dummy
) >= 0x100;
715 *is_symbol
= !!(os2
->ulCodePageRange1
& FS_SYMBOL
);
718 for (i
= 0; i
< face
->num_charmaps
; i
++)
719 if (face
->charmaps
[i
]->encoding
== FT_ENCODING_MS_SYMBOL
) {
725 LeaveCriticalSection(&freetype_cs
);
727 return charmap_index
;
730 INT32
freetype_get_glyph_advance(IDWriteFontFace2
*fontface
, FLOAT emSize
, UINT16 index
, DWRITE_MEASURING_MODE mode
)
732 FTC_ImageTypeRec imagetype
;
736 imagetype
.face_id
= fontface
;
738 imagetype
.height
= emSize
;
739 imagetype
.flags
= FT_LOAD_DEFAULT
;
740 if (mode
== DWRITE_MEASURING_MODE_NATURAL
)
741 imagetype
.flags
|= FT_LOAD_NO_HINTING
;
743 EnterCriticalSection(&freetype_cs
);
744 if (pFTC_ImageCache_Lookup(image_cache
, &imagetype
, index
, &glyph
, NULL
) == 0)
745 advance
= glyph
->advance
.x
>> 16;
748 LeaveCriticalSection(&freetype_cs
);
753 #else /* HAVE_FREETYPE */
755 BOOL
init_freetype(void)
760 void release_freetype(void)
764 void freetype_notify_cacheremove(IDWriteFontFace2
*fontface
)
768 HRESULT
freetype_get_design_glyph_metrics(IDWriteFontFace2
*fontface
, UINT16 unitsperEm
, UINT16 glyph
, DWRITE_GLYPH_METRICS
*ret
)
773 BOOL
freetype_is_monospaced(IDWriteFontFace2
*fontface
)
778 HRESULT
freetype_get_glyph_outline(IDWriteFontFace2
*fontface
, FLOAT emSize
, UINT16 index
, USHORT simulations
, struct glyph_outline
**ret
)
784 UINT16
freetype_get_glyphcount(IDWriteFontFace2
*fontface
)
789 UINT16
freetype_get_glyphindex(IDWriteFontFace2
*fontface
, UINT32 codepoint
, INT charmap
)
794 BOOL
freetype_has_kerning_pairs(IDWriteFontFace2
*fontface
)
799 INT32
freetype_get_kerning_pair_adjustment(IDWriteFontFace2
*fontface
, UINT16 left
, UINT16 right
)
804 void freetype_get_glyph_bbox(struct dwrite_glyphbitmap
*bitmap
)
806 memset(&bitmap
->bbox
, 0, sizeof(bitmap
->bbox
));
809 BOOL
freetype_get_glyph_bitmap(struct dwrite_glyphbitmap
*bitmap
)
814 INT
freetype_get_charmap_index(IDWriteFontFace2
*fontface
, BOOL
*is_symbol
)
820 INT32
freetype_get_glyph_advance(IDWriteFontFace2
*fontface
, FLOAT emSize
, UINT16 index
, DWRITE_MEASURING_MODE mode
)
825 #endif /* HAVE_FREETYPE */