dmime/tests: Remove superfluous casts to self.
[wine.git] / dlls / dwrite / freetype.c
blob181b6437f37434b0d7b2a0ad619163b7b56c3a5f
1 /*
2 * FreeType integration
4 * Copyright 2014-2017 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
21 #if 0
22 #pragma makedep unix
23 #endif
25 #include "config.h"
27 #include <sys/types.h>
28 #include <dlfcn.h>
30 #ifdef HAVE_FT2BUILD_H
31 #include <ft2build.h>
32 #include FT_GLYPH_H
33 #include FT_FREETYPE_H
34 #include FT_OUTLINE_H
35 #include FT_TRUETYPE_TABLES_H
36 #include FT_SIZES_H
37 #endif /* HAVE_FT2BUILD_H */
39 #include "ntstatus.h"
40 #define WIN32_NO_STATUS
41 #include "windef.h"
42 #include "wine/debug.h"
43 #include "unixlib.h"
45 #include "dwrite_private.h"
47 #ifdef HAVE_FREETYPE
49 WINE_DEFAULT_DEBUG_CHANNEL(dwrite);
51 static void *ft_handle = NULL;
52 static FT_Library library = 0;
53 typedef struct
55 FT_Int major;
56 FT_Int minor;
57 FT_Int patch;
58 } FT_Version_t;
60 #define MAKE_FUNCPTR(f) static typeof(f) * p##f = NULL
61 MAKE_FUNCPTR(FT_Activate_Size);
62 MAKE_FUNCPTR(FT_Done_Face);
63 MAKE_FUNCPTR(FT_Done_FreeType);
64 MAKE_FUNCPTR(FT_Done_Glyph);
65 MAKE_FUNCPTR(FT_Done_Size);
66 MAKE_FUNCPTR(FT_Get_First_Char);
67 MAKE_FUNCPTR(FT_Get_Glyph);
68 MAKE_FUNCPTR(FT_Get_Kerning);
69 MAKE_FUNCPTR(FT_Get_Sfnt_Table);
70 MAKE_FUNCPTR(FT_Glyph_Copy);
71 MAKE_FUNCPTR(FT_Glyph_Get_CBox);
72 MAKE_FUNCPTR(FT_Glyph_Transform);
73 MAKE_FUNCPTR(FT_Init_FreeType);
74 MAKE_FUNCPTR(FT_Library_Version);
75 MAKE_FUNCPTR(FT_Load_Glyph);
76 MAKE_FUNCPTR(FT_Matrix_Multiply);
77 MAKE_FUNCPTR(FT_MulDiv);
78 MAKE_FUNCPTR(FT_New_Memory_Face);
79 MAKE_FUNCPTR(FT_New_Size);
80 MAKE_FUNCPTR(FT_Outline_Copy);
81 MAKE_FUNCPTR(FT_Outline_Decompose);
82 MAKE_FUNCPTR(FT_Outline_Done);
83 MAKE_FUNCPTR(FT_Outline_Embolden);
84 MAKE_FUNCPTR(FT_Outline_Get_Bitmap);
85 MAKE_FUNCPTR(FT_Outline_New);
86 MAKE_FUNCPTR(FT_Outline_Transform);
87 MAKE_FUNCPTR(FT_Outline_Translate);
88 MAKE_FUNCPTR(FT_Set_Pixel_Sizes);
89 #undef MAKE_FUNCPTR
90 static FT_Error (*pFT_Outline_EmboldenXY)(FT_Outline *, FT_Pos, FT_Pos);
92 #define FaceFromObject(o) ((FT_Face)(ULONG_PTR)(o))
94 static FT_Size freetype_set_face_size(FT_Face face, FT_UInt emsize)
96 FT_Size size;
98 if (pFT_New_Size(face, &size)) return NULL;
100 pFT_Activate_Size(size);
102 if (pFT_Set_Pixel_Sizes(face, emsize, emsize))
104 pFT_Done_Size(size);
105 return NULL;
108 return size;
111 static BOOL freetype_glyph_has_contours(FT_Face face)
113 return face->glyph->format == FT_GLYPH_FORMAT_OUTLINE && face->glyph->outline.n_contours;
116 static NTSTATUS process_attach(void *args)
118 FT_Version_t FT_Version;
120 ft_handle = dlopen(SONAME_LIBFREETYPE, RTLD_NOW);
121 if (!ft_handle)
123 WINE_MESSAGE("Wine cannot find the FreeType font library.\n");
124 return STATUS_DLL_NOT_FOUND;
127 #define LOAD_FUNCPTR(f) if((p##f = dlsym(ft_handle, #f)) == NULL){WARN("Can't find symbol %s\n", #f); goto sym_not_found;}
128 LOAD_FUNCPTR(FT_Activate_Size)
129 LOAD_FUNCPTR(FT_Done_Face)
130 LOAD_FUNCPTR(FT_Done_FreeType)
131 LOAD_FUNCPTR(FT_Done_Glyph)
132 LOAD_FUNCPTR(FT_Done_Size)
133 LOAD_FUNCPTR(FT_Get_First_Char)
134 LOAD_FUNCPTR(FT_Get_Glyph)
135 LOAD_FUNCPTR(FT_Get_Kerning)
136 LOAD_FUNCPTR(FT_Get_Sfnt_Table)
137 LOAD_FUNCPTR(FT_Glyph_Copy)
138 LOAD_FUNCPTR(FT_Glyph_Get_CBox)
139 LOAD_FUNCPTR(FT_Glyph_Transform)
140 LOAD_FUNCPTR(FT_Init_FreeType)
141 LOAD_FUNCPTR(FT_Library_Version)
142 LOAD_FUNCPTR(FT_Load_Glyph)
143 LOAD_FUNCPTR(FT_Matrix_Multiply)
144 LOAD_FUNCPTR(FT_MulDiv)
145 LOAD_FUNCPTR(FT_New_Memory_Face)
146 LOAD_FUNCPTR(FT_New_Size)
147 LOAD_FUNCPTR(FT_Outline_Copy)
148 LOAD_FUNCPTR(FT_Outline_Decompose)
149 LOAD_FUNCPTR(FT_Outline_Done)
150 LOAD_FUNCPTR(FT_Outline_Embolden)
151 LOAD_FUNCPTR(FT_Outline_Get_Bitmap)
152 LOAD_FUNCPTR(FT_Outline_New)
153 LOAD_FUNCPTR(FT_Outline_Transform)
154 LOAD_FUNCPTR(FT_Outline_Translate)
155 LOAD_FUNCPTR(FT_Set_Pixel_Sizes)
156 #undef LOAD_FUNCPTR
157 pFT_Outline_EmboldenXY = dlsym(ft_handle, "FT_Outline_EmboldenXY");
159 if (pFT_Init_FreeType(&library) != 0)
161 ERR("Can't init FreeType library\n");
162 dlclose(ft_handle);
163 ft_handle = NULL;
164 return STATUS_UNSUCCESSFUL;
166 pFT_Library_Version(library, &FT_Version.major, &FT_Version.minor, &FT_Version.patch);
168 TRACE("FreeType version is %d.%d.%d\n", FT_Version.major, FT_Version.minor, FT_Version.patch);
169 return STATUS_SUCCESS;
171 sym_not_found:
172 WINE_MESSAGE("Wine cannot find certain functions that it needs from FreeType library.\n");
173 dlclose(ft_handle);
174 ft_handle = NULL;
175 return STATUS_UNSUCCESSFUL;
178 static NTSTATUS process_detach(void *args)
180 pFT_Done_FreeType(library);
181 return STATUS_SUCCESS;
184 static NTSTATUS create_font_object(void *args)
186 struct create_font_object_params *params = args;
187 FT_Face face = NULL;
188 FT_Error fterror;
190 fterror = pFT_New_Memory_Face(library, params->data, params->size, params->index, &face);
191 if (fterror != FT_Err_Ok)
193 WARN("Failed to create a face object, error %d.\n", fterror);
194 return STATUS_UNSUCCESSFUL;
197 *params->object = (ULONG_PTR)face;
199 return STATUS_SUCCESS;
202 static NTSTATUS release_font_object(void *args)
204 struct release_font_object_params *params = args;
205 pFT_Done_Face(FaceFromObject(params->object));
206 return STATUS_SUCCESS;
209 static NTSTATUS get_design_glyph_metrics(void *args)
211 struct get_design_glyph_metrics_params *params = args;
212 FT_Face face = FaceFromObject(params->object);
213 FT_Size size;
215 if (!(size = freetype_set_face_size(face, params->upem)))
216 return STATUS_UNSUCCESSFUL;
218 if (!pFT_Load_Glyph(face, params->glyph, FT_LOAD_NO_SCALE))
220 FT_Glyph_Metrics *metrics = &face->glyph->metrics;
222 params->metrics->leftSideBearing = metrics->horiBearingX;
223 params->metrics->advanceWidth = metrics->horiAdvance;
224 params->metrics->rightSideBearing = metrics->horiAdvance - metrics->horiBearingX - metrics->width;
226 params->metrics->advanceHeight = metrics->vertAdvance;
227 params->metrics->verticalOriginY = params->ascent;
228 params->metrics->topSideBearing = params->ascent - metrics->horiBearingY;
229 params->metrics->bottomSideBearing = metrics->vertAdvance - metrics->height - params->metrics->topSideBearing;
231 /* Adjust in case of bold simulation, glyphs without contours are ignored. */
232 if (params->simulations & DWRITE_FONT_SIMULATIONS_BOLD && freetype_glyph_has_contours(face))
234 if (params->metrics->advanceWidth)
235 params->metrics->advanceWidth += (params->upem + 49) / 50;
239 pFT_Done_Size(size);
241 return STATUS_SUCCESS;
244 struct decompose_context
246 struct dwrite_outline *outline;
247 BOOL figure_started;
248 BOOL move_to; /* last call was 'move_to' */
249 FT_Vector origin; /* 'pen' position from last call */
252 static inline void ft_vector_to_d2d_point(const FT_Vector *v, D2D1_POINT_2F *p)
254 p->x = v->x / 64.0f;
255 p->y = v->y / 64.0f;
258 static int dwrite_outline_push_tag(struct dwrite_outline *outline, unsigned char tag)
260 if (outline->tags.size < outline->tags.count + 1)
261 return 1;
263 outline->tags.values[outline->tags.count++] = tag;
265 return 0;
268 static int dwrite_outline_push_points(struct dwrite_outline *outline, const D2D1_POINT_2F *points, unsigned int count)
270 if (outline->points.size < outline->points.count + count)
271 return 1;
273 memcpy(&outline->points.values[outline->points.count], points, sizeof(*points) * count);
274 outline->points.count += count;
276 return 0;
279 static int decompose_beginfigure(struct decompose_context *ctxt)
281 D2D1_POINT_2F point;
282 int ret;
284 if (!ctxt->move_to)
285 return 0;
287 ft_vector_to_d2d_point(&ctxt->origin, &point);
288 if ((ret = dwrite_outline_push_tag(ctxt->outline, OUTLINE_BEGIN_FIGURE))) return ret;
289 if ((ret = dwrite_outline_push_points(ctxt->outline, &point, 1))) return ret;
291 ctxt->figure_started = TRUE;
292 ctxt->move_to = FALSE;
294 return 0;
297 static int decompose_move_to(const FT_Vector *to, void *user)
299 struct decompose_context *ctxt = (struct decompose_context *)user;
300 int ret;
302 if (ctxt->figure_started)
304 if ((ret = dwrite_outline_push_tag(ctxt->outline, OUTLINE_END_FIGURE))) return ret;
305 ctxt->figure_started = FALSE;
308 ctxt->move_to = TRUE;
309 ctxt->origin = *to;
310 return 0;
313 static int decompose_line_to(const FT_Vector *to, void *user)
315 struct decompose_context *ctxt = (struct decompose_context *)user;
316 D2D1_POINT_2F point;
317 int ret;
319 /* Special case for empty contours, in a way freetype returns them. */
320 if (ctxt->move_to && !memcmp(to, &ctxt->origin, sizeof(*to)))
321 return 0;
323 ft_vector_to_d2d_point(to, &point);
325 if ((ret = decompose_beginfigure(ctxt))) return ret;
326 if ((ret = dwrite_outline_push_points(ctxt->outline, &point, 1))) return ret;
327 if ((ret = dwrite_outline_push_tag(ctxt->outline, OUTLINE_LINE))) return ret;
329 ctxt->origin = *to;
330 return 0;
333 static int decompose_conic_to(const FT_Vector *control, const FT_Vector *to, void *user)
335 struct decompose_context *ctxt = (struct decompose_context *)user;
336 D2D1_POINT_2F points[3];
337 FT_Vector cubic[3];
338 int ret;
340 if ((ret = decompose_beginfigure(ctxt)))
341 return ret;
343 /* convert from quadratic to cubic */
346 The parametric eqn for a cubic Bezier is, from PLRM:
347 r(t) = at^3 + bt^2 + ct + r0
348 with the control points:
349 r1 = r0 + c/3
350 r2 = r1 + (c + b)/3
351 r3 = r0 + c + b + a
353 A quadratic Bezier has the form:
354 p(t) = (1-t)^2 p0 + 2(1-t)t p1 + t^2 p2
356 So equating powers of t leads to:
357 r1 = 2/3 p1 + 1/3 p0
358 r2 = 2/3 p1 + 1/3 p2
359 and of course r0 = p0, r3 = p2
362 /* r1 = 1/3 p0 + 2/3 p1
363 r2 = 1/3 p2 + 2/3 p1 */
364 cubic[0].x = (2 * control->x + 1) / 3;
365 cubic[0].y = (2 * control->y + 1) / 3;
366 cubic[1] = cubic[0];
367 cubic[0].x += (ctxt->origin.x + 1) / 3;
368 cubic[0].y += (ctxt->origin.y + 1) / 3;
369 cubic[1].x += (to->x + 1) / 3;
370 cubic[1].y += (to->y + 1) / 3;
371 cubic[2] = *to;
373 ft_vector_to_d2d_point(cubic, points);
374 ft_vector_to_d2d_point(cubic + 1, points + 1);
375 ft_vector_to_d2d_point(cubic + 2, points + 2);
376 if ((ret = dwrite_outline_push_points(ctxt->outline, points, 3))) return ret;
377 if ((ret = dwrite_outline_push_tag(ctxt->outline, OUTLINE_BEZIER))) return ret;
378 ctxt->origin = *to;
379 return 0;
382 static int decompose_cubic_to(const FT_Vector *control1, const FT_Vector *control2,
383 const FT_Vector *to, void *user)
385 struct decompose_context *ctxt = (struct decompose_context *)user;
386 D2D1_POINT_2F points[3];
387 int ret;
389 if ((ret = decompose_beginfigure(ctxt)))
390 return ret;
392 ft_vector_to_d2d_point(control1, points);
393 ft_vector_to_d2d_point(control2, points + 1);
394 ft_vector_to_d2d_point(to, points + 2);
395 ctxt->origin = *to;
397 if ((ret = dwrite_outline_push_points(ctxt->outline, points, 3))) return ret;
398 if ((ret = dwrite_outline_push_tag(ctxt->outline, OUTLINE_BEZIER))) return ret;
400 return 0;
403 static int decompose_outline(FT_Outline *ft_outline, struct dwrite_outline *outline)
405 static const FT_Outline_Funcs decompose_funcs =
407 decompose_move_to,
408 decompose_line_to,
409 decompose_conic_to,
410 decompose_cubic_to,
414 struct decompose_context context = { 0 };
415 int ret;
417 context.outline = outline;
419 ret = pFT_Outline_Decompose(ft_outline, &decompose_funcs, &context);
421 if (!ret && context.figure_started)
422 ret = dwrite_outline_push_tag(outline, OUTLINE_END_FIGURE);
424 return ret;
427 static void embolden_glyph_outline(FT_Outline *outline, FLOAT emsize)
429 FT_Pos strength;
431 strength = pFT_MulDiv(emsize, 1 << 6, 24);
432 if (pFT_Outline_EmboldenXY)
433 pFT_Outline_EmboldenXY(outline, strength, 0);
434 else
435 pFT_Outline_Embolden(outline, strength);
438 static void embolden_glyph(FT_Glyph glyph, FLOAT emsize)
440 FT_OutlineGlyph outline_glyph = (FT_OutlineGlyph)glyph;
442 if (glyph->format != FT_GLYPH_FORMAT_OUTLINE)
443 return;
445 embolden_glyph_outline(&outline_glyph->outline, emsize);
448 static NTSTATUS get_glyph_outline(void *args)
450 struct get_glyph_outline_params *params = args;
451 FT_Face face = FaceFromObject(params->object);
452 FT_Size size;
454 if (!(size = freetype_set_face_size(face, params->emsize)))
455 return STATUS_UNSUCCESSFUL;
457 if (!pFT_Load_Glyph(face, params->glyph, FT_LOAD_NO_BITMAP))
459 FT_Outline *ft_outline = &face->glyph->outline;
460 FT_Matrix m;
462 if (params->outline->points.values)
464 if (params->simulations & DWRITE_FONT_SIMULATIONS_BOLD)
465 embolden_glyph_outline(ft_outline, params->emsize);
467 m.xx = 1 << 16;
468 m.xy = params->simulations & DWRITE_FONT_SIMULATIONS_OBLIQUE ? (1 << 16) / 3 : 0;
469 m.yx = 0;
470 m.yy = -(1 << 16); /* flip Y axis */
472 pFT_Outline_Transform(ft_outline, &m);
474 decompose_outline(ft_outline, params->outline);
476 else
478 /* Intentionally overestimate numbers to keep it simple. */
479 params->outline->points.count = ft_outline->n_points * 3;
480 params->outline->tags.count = ft_outline->n_points + ft_outline->n_contours * 2;
484 pFT_Done_Size(size);
486 return STATUS_SUCCESS;
489 static NTSTATUS get_glyph_count(void *args)
491 struct get_glyph_count_params *params = args;
492 FT_Face face = FaceFromObject(params->object);
494 *params->count = face ? face->num_glyphs : 0;
496 return STATUS_SUCCESS;
499 static inline void ft_matrix_from_matrix_2x2(const MATRIX_2X2 *m, FT_Matrix *ft_matrix)
501 ft_matrix->xx = m->m11 * 0x10000;
502 ft_matrix->xy = -m->m21 * 0x10000;
503 ft_matrix->yx = -m->m12 * 0x10000;
504 ft_matrix->yy = m->m22 * 0x10000;
507 static BOOL get_glyph_transform(unsigned int simulations, const MATRIX_2X2 *m, FT_Matrix *ret)
509 FT_Matrix ftm;
511 ret->xx = 1 << 16;
512 ret->xy = 0;
513 ret->yx = 0;
514 ret->yy = 1 << 16;
516 /* Some fonts provide mostly bitmaps and very few outlines, for example for .notdef.
517 Disable transform if that's the case. */
518 if (!memcmp(m, &identity_2x2, sizeof(*m)) && !simulations)
519 return FALSE;
521 if (simulations & DWRITE_FONT_SIMULATIONS_OBLIQUE)
523 ftm.xx = 1 << 16;
524 ftm.xy = (1 << 16) / 3;
525 ftm.yx = 0;
526 ftm.yy = 1 << 16;
527 pFT_Matrix_Multiply(&ftm, ret);
530 ft_matrix_from_matrix_2x2(m, &ftm);
531 pFT_Matrix_Multiply(&ftm, ret);
533 return TRUE;
536 static NTSTATUS get_glyph_bbox(void *args)
538 struct get_glyph_bbox_params *params = args;
539 FT_Face face = FaceFromObject(params->object);
540 FT_Glyph glyph = NULL;
541 FT_BBox bbox = { 0 };
542 BOOL needs_transform;
543 FT_Matrix m;
544 FT_Size size;
546 SetRectEmpty(params->bbox);
548 if (!(size = freetype_set_face_size(face, params->emsize)))
549 return STATUS_UNSUCCESSFUL;
551 needs_transform = FT_IS_SCALABLE(face) && get_glyph_transform(params->simulations, &params->m, &m);
553 if (pFT_Load_Glyph(face, params->glyph, needs_transform ? FT_LOAD_NO_BITMAP : 0))
555 WARN("Failed to load glyph %u.\n", params->glyph);
556 pFT_Done_Size(size);
557 return STATUS_UNSUCCESSFUL;
560 pFT_Get_Glyph(face->glyph, &glyph);
561 if (needs_transform)
563 if (params->simulations & DWRITE_FONT_SIMULATIONS_BOLD)
564 embolden_glyph(glyph, params->emsize);
566 /* Includes oblique and user transform. */
567 pFT_Glyph_Transform(glyph, &m, NULL);
570 pFT_Glyph_Get_CBox(glyph, FT_GLYPH_BBOX_PIXELS, &bbox);
571 pFT_Done_Glyph(glyph);
572 pFT_Done_Size(size);
574 /* flip Y axis */
575 SetRect(params->bbox, bbox.xMin, -bbox.yMax, bbox.xMax, -bbox.yMin);
577 return STATUS_SUCCESS;
580 static NTSTATUS freetype_get_aliased_glyph_bitmap(struct get_glyph_bitmap_params *params, FT_Glyph glyph)
582 const RECT *bbox = &params->bbox;
583 int width = bbox->right - bbox->left;
584 int height = bbox->bottom - bbox->top;
586 *params->is_1bpp = 1;
588 if (glyph->format == FT_GLYPH_FORMAT_OUTLINE) {
589 FT_OutlineGlyph outline = (FT_OutlineGlyph)glyph;
590 const FT_Outline *src = &outline->outline;
591 FT_Bitmap ft_bitmap;
592 FT_Outline copy;
594 ft_bitmap.width = width;
595 ft_bitmap.rows = height;
596 ft_bitmap.pitch = params->pitch;
597 ft_bitmap.pixel_mode = FT_PIXEL_MODE_MONO;
598 ft_bitmap.buffer = params->bitmap;
600 /* Note: FreeType will only set 'black' bits for us. */
601 if (pFT_Outline_New(library, src->n_points, src->n_contours, &copy) == 0) {
602 pFT_Outline_Copy(src, &copy);
603 pFT_Outline_Translate(&copy, -bbox->left << 6, bbox->bottom << 6);
604 pFT_Outline_Get_Bitmap(library, &copy, &ft_bitmap);
605 pFT_Outline_Done(library, &copy);
608 else if (glyph->format == FT_GLYPH_FORMAT_BITMAP) {
609 FT_Bitmap *ft_bitmap = &((FT_BitmapGlyph)glyph)->bitmap;
610 BYTE *src = ft_bitmap->buffer, *dst = params->bitmap;
611 int w = min(params->pitch, (ft_bitmap->width + 7) >> 3);
612 int h = min(height, ft_bitmap->rows);
614 while (h--) {
615 memcpy(dst, src, w);
616 src += ft_bitmap->pitch;
617 dst += params->pitch;
620 else
621 FIXME("format %x not handled\n", glyph->format);
623 return STATUS_SUCCESS;
626 static NTSTATUS freetype_get_aa_glyph_bitmap(struct get_glyph_bitmap_params *params, FT_Glyph glyph)
628 const RECT *bbox = &params->bbox;
629 int width = bbox->right - bbox->left;
630 int height = bbox->bottom - bbox->top;
632 *params->is_1bpp = 0;
634 if (glyph->format == FT_GLYPH_FORMAT_OUTLINE) {
635 FT_OutlineGlyph outline = (FT_OutlineGlyph)glyph;
636 const FT_Outline *src = &outline->outline;
637 FT_Bitmap ft_bitmap;
638 FT_Outline copy;
640 ft_bitmap.width = width;
641 ft_bitmap.rows = height;
642 ft_bitmap.pitch = params->pitch;
643 ft_bitmap.pixel_mode = FT_PIXEL_MODE_GRAY;
644 ft_bitmap.buffer = params->bitmap;
646 /* Note: FreeType will only set 'black' bits for us. */
647 if (pFT_Outline_New(library, src->n_points, src->n_contours, &copy) == 0) {
648 pFT_Outline_Copy(src, &copy);
649 pFT_Outline_Translate(&copy, -bbox->left << 6, bbox->bottom << 6);
650 pFT_Outline_Get_Bitmap(library, &copy, &ft_bitmap);
651 pFT_Outline_Done(library, &copy);
654 else if (glyph->format == FT_GLYPH_FORMAT_BITMAP) {
655 FT_Bitmap *ft_bitmap = &((FT_BitmapGlyph)glyph)->bitmap;
656 BYTE *src = ft_bitmap->buffer, *dst = params->bitmap;
657 int w = min(params->pitch, (ft_bitmap->width + 7) >> 3);
658 int h = min(height, ft_bitmap->rows);
660 while (h--) {
661 memcpy(dst, src, w);
662 src += ft_bitmap->pitch;
663 dst += params->pitch;
666 *params->is_1bpp = 1;
668 else
670 FIXME("format %x not handled\n", glyph->format);
671 return STATUS_NOT_IMPLEMENTED;
674 return STATUS_SUCCESS;
677 static NTSTATUS get_glyph_bitmap(void *args)
679 struct get_glyph_bitmap_params *params = args;
680 FT_Face face = FaceFromObject(params->object);
681 BOOL needs_transform;
682 BOOL ret = FALSE;
683 FT_Glyph glyph;
684 FT_Size size;
685 FT_Matrix m;
687 *params->is_1bpp = 0;
689 if (!(size = freetype_set_face_size(face, params->emsize)))
690 return STATUS_UNSUCCESSFUL;
692 needs_transform = FT_IS_SCALABLE(face) && get_glyph_transform(params->simulations, &params->m, &m);
694 if (!pFT_Load_Glyph(face, params->glyph, needs_transform ? FT_LOAD_NO_BITMAP : 0))
696 pFT_Get_Glyph(face->glyph, &glyph);
698 if (needs_transform)
700 if (params->simulations & DWRITE_FONT_SIMULATIONS_BOLD)
701 embolden_glyph(glyph, params->emsize);
703 /* Includes oblique and user transform. */
704 pFT_Glyph_Transform(glyph, &m, NULL);
707 if (params->mode == DWRITE_RENDERING_MODE1_ALIASED)
708 ret = freetype_get_aliased_glyph_bitmap(params, glyph);
709 else
710 ret = freetype_get_aa_glyph_bitmap(params, glyph);
712 pFT_Done_Glyph(glyph);
715 pFT_Done_Size(size);
717 return ret;
720 static NTSTATUS get_glyph_advance(void *args)
722 struct get_glyph_advance_params *params = args;
723 FT_Face face = FaceFromObject(params->object);
724 FT_Size size;
726 *params->advance = 0;
727 *params->has_contours = FALSE;
729 if (!(size = freetype_set_face_size(face, params->emsize)))
730 return STATUS_UNSUCCESSFUL;
732 if (!pFT_Load_Glyph(face, params->glyph, params->mode == DWRITE_MEASURING_MODE_NATURAL ? FT_LOAD_NO_HINTING : 0))
734 *params->advance = face->glyph->advance.x >> 6;
735 *params->has_contours = freetype_glyph_has_contours(face);
738 pFT_Done_Size(size);
740 return STATUS_SUCCESS;
743 #else /* HAVE_FREETYPE */
745 static NTSTATUS process_attach(void *args)
747 return STATUS_NOT_IMPLEMENTED;
750 static NTSTATUS process_detach(void *args)
752 return STATUS_NOT_IMPLEMENTED;
755 static NTSTATUS create_font_object(void *args)
757 return STATUS_NOT_IMPLEMENTED;
760 static NTSTATUS release_font_object(void *args)
762 return STATUS_NOT_IMPLEMENTED;
765 static NTSTATUS get_glyph_outline(void *args)
767 return STATUS_NOT_IMPLEMENTED;
770 static NTSTATUS get_glyph_count(void *args)
772 return STATUS_NOT_IMPLEMENTED;
775 static NTSTATUS get_glyph_advance(void *args)
777 struct get_glyph_advance_params *params = args;
779 *params->has_contours = 0;
780 *params->advance = 0;
782 return STATUS_NOT_IMPLEMENTED;
785 static NTSTATUS get_glyph_bbox(void *args)
787 struct get_glyph_bbox_params *params = args;
788 SetRectEmpty(params->bbox);
789 return STATUS_NOT_IMPLEMENTED;
792 static NTSTATUS get_glyph_bitmap(void *args)
794 return STATUS_NOT_IMPLEMENTED;
797 static NTSTATUS get_design_glyph_metrics(void *args)
799 return STATUS_NOT_IMPLEMENTED;
802 #endif /* HAVE_FREETYPE */
804 const unixlib_entry_t __wine_unix_call_funcs[] =
806 process_attach,
807 process_detach,
808 create_font_object,
809 release_font_object,
810 get_glyph_outline,
811 get_glyph_count,
812 get_glyph_advance,
813 get_glyph_bbox,
814 get_glyph_bitmap,
815 get_design_glyph_metrics,
818 C_ASSERT( ARRAYSIZE(__wine_unix_call_funcs) == unix_funcs_count );
820 #ifdef _WIN64
822 typedef ULONG PTR32;
824 static NTSTATUS wow64_create_font_object(void *args)
826 struct
828 PTR32 data;
829 UINT64 size;
830 ULONG index;
831 PTR32 object;
832 } const *params32 = args;
833 struct create_font_object_params params =
835 ULongToPtr(params32->data),
836 params32->size,
837 params32->index,
838 ULongToPtr(params32->object),
841 return create_font_object(&params);
844 static NTSTATUS wow64_release_font_object(void *args)
846 struct
848 UINT64 object;
849 } const *params32 = args;
850 struct release_font_object_params params =
852 params32->object
855 return release_font_object(&params);
858 struct dwrite_outline32
860 struct
862 PTR32 values;
863 ULONG count;
864 ULONG size;
865 } tags;
867 struct
869 PTR32 values;
870 ULONG count;
871 ULONG size;
872 } points;
875 static NTSTATUS wow64_get_glyph_outline(void *args)
877 struct
879 UINT64 object;
880 ULONG simulations;
881 ULONG glyph;
882 float emsize;
883 PTR32 outline;
884 } const *params32 = args;
885 struct dwrite_outline32 *outline32 = ULongToPtr(params32->outline);
886 struct dwrite_outline outline =
888 .tags.values = ULongToPtr(outline32->tags.values),
889 .tags.count = outline32->tags.count,
890 .tags.size = outline32->tags.size,
891 .points.values = ULongToPtr(outline32->points.values),
892 .points.count = outline32->points.count,
893 .points.size = outline32->points.size,
896 struct get_glyph_outline_params params =
898 params32->object,
899 params32->simulations,
900 params32->glyph,
901 params32->emsize,
902 &outline,
904 NTSTATUS status;
906 status = get_glyph_outline(&params);
907 outline32->points.count = outline.points.count;
908 outline32->tags.count = outline.tags.count;
909 return status;
912 static NTSTATUS wow64_get_glyph_count(void *args)
914 struct
916 UINT64 object;
917 PTR32 count;
918 } const *params32 = args;
919 struct get_glyph_count_params params =
921 params32->object,
922 ULongToPtr(params32->count),
925 return get_glyph_count(&params);
928 static NTSTATUS wow64_get_glyph_advance(void *args)
930 struct
932 UINT64 object;
933 ULONG glyph;
934 ULONG mode;
935 float emsize;
936 PTR32 advance;
937 PTR32 has_contours;
938 } const *params32 = args;
939 struct get_glyph_advance_params params =
941 params32->object,
942 params32->glyph,
943 params32->mode,
944 params32->emsize,
945 ULongToPtr(params32->advance),
946 ULongToPtr(params32->has_contours),
949 return get_glyph_advance(&params);
952 static NTSTATUS wow64_get_glyph_bbox(void *args)
954 struct
956 UINT64 object;
957 ULONG simulations;
958 ULONG glyph;
959 float emsize;
960 MATRIX_2X2 m;
961 PTR32 bbox;
962 } const *params32 = args;
963 struct get_glyph_bbox_params params =
965 params32->object,
966 params32->simulations,
967 params32->glyph,
968 params32->emsize,
969 params32->m,
970 ULongToPtr(params32->bbox),
973 return get_glyph_bbox(&params);
976 static NTSTATUS wow64_get_glyph_bitmap(void *args)
978 struct
980 UINT64 object;
981 ULONG simulations;
982 ULONG glyph;
983 ULONG mode;
984 float emsize;
985 MATRIX_2X2 m;
986 RECT bbox;
987 int pitch;
988 PTR32 bitmap;
989 PTR32 is_1bpp;
990 } const *params32 = args;
991 struct get_glyph_bitmap_params params =
993 params32->object,
994 params32->simulations,
995 params32->glyph,
996 params32->mode,
997 params32->emsize,
998 params32->m,
999 params32->bbox,
1000 params32->pitch,
1001 ULongToPtr(params32->bitmap),
1002 ULongToPtr(params32->is_1bpp),
1005 return get_glyph_bitmap(&params);
1008 static NTSTATUS wow64_get_design_glyph_metrics(void *args)
1010 struct
1012 UINT64 object;
1013 ULONG simulations;
1014 ULONG glyph;
1015 ULONG upem;
1016 ULONG ascent;
1017 PTR32 metrics;
1018 } const *params32 = args;
1019 struct get_design_glyph_metrics_params params =
1021 params32->object,
1022 params32->simulations,
1023 params32->glyph,
1024 params32->upem,
1025 params32->ascent,
1026 ULongToPtr(params32->metrics),
1029 return get_design_glyph_metrics(&params);
1032 const unixlib_entry_t __wine_unix_call_wow64_funcs[] =
1034 process_attach,
1035 process_detach,
1036 wow64_create_font_object,
1037 wow64_release_font_object,
1038 wow64_get_glyph_outline,
1039 wow64_get_glyph_count,
1040 wow64_get_glyph_advance,
1041 wow64_get_glyph_bbox,
1042 wow64_get_glyph_bitmap,
1043 wow64_get_design_glyph_metrics,
1046 C_ASSERT( ARRAYSIZE(__wine_unix_call_wow64_funcs) == unix_funcs_count );
1048 #endif /* _WIN64 */