2014-11-21 08:48:23 +00:00
|
|
|
/*
|
|
|
|
* FreeType integration
|
|
|
|
*
|
2017-03-15 19:35:32 +00:00
|
|
|
* Copyright 2014-2017 Nikolay Sivov for CodeWeavers
|
2014-11-21 08:48:23 +00:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
2021-03-30 11:06:18 +00:00
|
|
|
#if 0
|
|
|
|
#pragma makedep unix
|
|
|
|
#endif
|
2014-12-08 10:24:39 +00:00
|
|
|
|
2014-11-21 08:48:23 +00:00
|
|
|
#include "config.h"
|
2021-11-03 09:43:50 +00:00
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <dlfcn.h>
|
2014-11-21 08:48:23 +00:00
|
|
|
|
|
|
|
#ifdef HAVE_FT2BUILD_H
|
|
|
|
#include <ft2build.h>
|
2021-12-07 12:59:47 +00:00
|
|
|
#include FT_GLYPH_H
|
2014-11-21 08:48:23 +00:00
|
|
|
#include FT_FREETYPE_H
|
2014-12-15 06:39:26 +00:00
|
|
|
#include FT_OUTLINE_H
|
2015-08-06 15:02:43 +00:00
|
|
|
#include FT_TRUETYPE_TABLES_H
|
2021-12-02 12:37:17 +00:00
|
|
|
#include FT_SIZES_H
|
2014-11-21 08:48:23 +00:00
|
|
|
#endif /* HAVE_FT2BUILD_H */
|
|
|
|
|
2021-03-29 07:48:51 +00:00
|
|
|
#include "ntstatus.h"
|
|
|
|
#define WIN32_NO_STATUS
|
2014-11-21 08:48:23 +00:00
|
|
|
#include "windef.h"
|
|
|
|
#include "wine/debug.h"
|
2021-12-08 11:10:42 +00:00
|
|
|
#include "unixlib.h"
|
2014-11-21 08:48:23 +00:00
|
|
|
|
|
|
|
#include "dwrite_private.h"
|
|
|
|
|
|
|
|
#ifdef HAVE_FREETYPE
|
|
|
|
|
2020-12-23 19:15:15 +00:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(dwrite);
|
|
|
|
|
2014-11-21 08:48:23 +00:00
|
|
|
static void *ft_handle = NULL;
|
|
|
|
static FT_Library library = 0;
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
FT_Int major;
|
|
|
|
FT_Int minor;
|
|
|
|
FT_Int patch;
|
|
|
|
} FT_Version_t;
|
|
|
|
|
|
|
|
#define MAKE_FUNCPTR(f) static typeof(f) * p##f = NULL
|
2021-12-02 12:37:17 +00:00
|
|
|
MAKE_FUNCPTR(FT_Activate_Size);
|
2021-12-02 12:37:15 +00:00
|
|
|
MAKE_FUNCPTR(FT_Done_Face);
|
2014-12-08 10:24:39 +00:00
|
|
|
MAKE_FUNCPTR(FT_Done_FreeType);
|
2015-11-02 13:38:43 +00:00
|
|
|
MAKE_FUNCPTR(FT_Done_Glyph);
|
2021-12-02 12:37:17 +00:00
|
|
|
MAKE_FUNCPTR(FT_Done_Size);
|
2015-08-06 15:02:43 +00:00
|
|
|
MAKE_FUNCPTR(FT_Get_First_Char);
|
2021-12-07 12:59:45 +00:00
|
|
|
MAKE_FUNCPTR(FT_Get_Glyph);
|
2015-03-13 20:19:18 +00:00
|
|
|
MAKE_FUNCPTR(FT_Get_Kerning);
|
2015-08-06 15:02:43 +00:00
|
|
|
MAKE_FUNCPTR(FT_Get_Sfnt_Table);
|
2015-11-02 13:38:43 +00:00
|
|
|
MAKE_FUNCPTR(FT_Glyph_Copy);
|
2015-07-29 08:59:02 +00:00
|
|
|
MAKE_FUNCPTR(FT_Glyph_Get_CBox);
|
2015-11-02 13:38:43 +00:00
|
|
|
MAKE_FUNCPTR(FT_Glyph_Transform);
|
2014-11-21 08:48:23 +00:00
|
|
|
MAKE_FUNCPTR(FT_Init_FreeType);
|
|
|
|
MAKE_FUNCPTR(FT_Library_Version);
|
2014-12-08 10:24:39 +00:00
|
|
|
MAKE_FUNCPTR(FT_Load_Glyph);
|
2017-03-13 17:44:09 +00:00
|
|
|
MAKE_FUNCPTR(FT_Matrix_Multiply);
|
2021-03-29 07:48:52 +00:00
|
|
|
MAKE_FUNCPTR(FT_MulDiv);
|
2014-11-21 08:48:23 +00:00
|
|
|
MAKE_FUNCPTR(FT_New_Memory_Face);
|
2021-12-02 12:37:17 +00:00
|
|
|
MAKE_FUNCPTR(FT_New_Size);
|
2015-08-02 20:47:24 +00:00
|
|
|
MAKE_FUNCPTR(FT_Outline_Copy);
|
2016-01-18 21:47:09 +00:00
|
|
|
MAKE_FUNCPTR(FT_Outline_Decompose);
|
2015-08-02 20:47:24 +00:00
|
|
|
MAKE_FUNCPTR(FT_Outline_Done);
|
2017-03-15 19:35:32 +00:00
|
|
|
MAKE_FUNCPTR(FT_Outline_Embolden);
|
2015-07-30 22:30:08 +00:00
|
|
|
MAKE_FUNCPTR(FT_Outline_Get_Bitmap);
|
2015-08-02 20:47:24 +00:00
|
|
|
MAKE_FUNCPTR(FT_Outline_New);
|
2014-12-15 06:39:26 +00:00
|
|
|
MAKE_FUNCPTR(FT_Outline_Transform);
|
2015-07-30 22:30:08 +00:00
|
|
|
MAKE_FUNCPTR(FT_Outline_Translate);
|
2021-12-02 12:37:17 +00:00
|
|
|
MAKE_FUNCPTR(FT_Set_Pixel_Sizes);
|
2014-11-21 08:48:23 +00:00
|
|
|
#undef MAKE_FUNCPTR
|
2017-03-15 19:35:32 +00:00
|
|
|
static FT_Error (*pFT_Outline_EmboldenXY)(FT_Outline *, FT_Pos, FT_Pos);
|
2014-11-21 08:48:23 +00:00
|
|
|
|
2021-12-08 11:10:42 +00:00
|
|
|
#define FaceFromObject(o) ((FT_Face)(ULONG_PTR)(o))
|
|
|
|
|
2021-12-02 12:37:17 +00:00
|
|
|
static FT_Size freetype_set_face_size(FT_Face face, FT_UInt emsize)
|
|
|
|
{
|
|
|
|
FT_Size size;
|
|
|
|
|
|
|
|
if (pFT_New_Size(face, &size)) return NULL;
|
|
|
|
|
|
|
|
pFT_Activate_Size(size);
|
|
|
|
|
|
|
|
if (pFT_Set_Pixel_Sizes(face, emsize, emsize))
|
|
|
|
{
|
|
|
|
pFT_Done_Size(size);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL freetype_glyph_has_contours(FT_Face face)
|
|
|
|
{
|
|
|
|
return face->glyph->format == FT_GLYPH_FORMAT_OUTLINE && face->glyph->outline.n_contours;
|
|
|
|
}
|
|
|
|
|
2021-12-08 11:10:42 +00:00
|
|
|
static NTSTATUS process_attach(void *args)
|
2014-11-21 08:48:23 +00:00
|
|
|
{
|
|
|
|
FT_Version_t FT_Version;
|
|
|
|
|
2020-04-06 09:45:32 +00:00
|
|
|
ft_handle = dlopen(SONAME_LIBFREETYPE, RTLD_NOW);
|
2021-12-02 12:37:15 +00:00
|
|
|
if (!ft_handle)
|
|
|
|
{
|
2014-11-21 08:48:23 +00:00
|
|
|
WINE_MESSAGE("Wine cannot find the FreeType font library.\n");
|
2021-12-08 11:10:42 +00:00
|
|
|
return STATUS_DLL_NOT_FOUND;
|
2014-11-21 08:48:23 +00:00
|
|
|
}
|
|
|
|
|
2020-04-06 09:45:32 +00:00
|
|
|
#define LOAD_FUNCPTR(f) if((p##f = dlsym(ft_handle, #f)) == NULL){WARN("Can't find symbol %s\n", #f); goto sym_not_found;}
|
2021-12-02 12:37:17 +00:00
|
|
|
LOAD_FUNCPTR(FT_Activate_Size)
|
2021-12-02 12:37:15 +00:00
|
|
|
LOAD_FUNCPTR(FT_Done_Face)
|
2014-12-08 10:24:39 +00:00
|
|
|
LOAD_FUNCPTR(FT_Done_FreeType)
|
2015-11-02 13:38:43 +00:00
|
|
|
LOAD_FUNCPTR(FT_Done_Glyph)
|
2021-12-02 12:37:17 +00:00
|
|
|
LOAD_FUNCPTR(FT_Done_Size)
|
2015-08-06 15:02:43 +00:00
|
|
|
LOAD_FUNCPTR(FT_Get_First_Char)
|
2021-12-07 12:59:45 +00:00
|
|
|
LOAD_FUNCPTR(FT_Get_Glyph)
|
2015-03-13 20:19:18 +00:00
|
|
|
LOAD_FUNCPTR(FT_Get_Kerning)
|
2015-08-06 15:02:43 +00:00
|
|
|
LOAD_FUNCPTR(FT_Get_Sfnt_Table)
|
2015-11-02 13:38:43 +00:00
|
|
|
LOAD_FUNCPTR(FT_Glyph_Copy)
|
2015-07-29 08:59:02 +00:00
|
|
|
LOAD_FUNCPTR(FT_Glyph_Get_CBox)
|
2015-11-02 13:38:43 +00:00
|
|
|
LOAD_FUNCPTR(FT_Glyph_Transform)
|
2014-11-21 08:48:23 +00:00
|
|
|
LOAD_FUNCPTR(FT_Init_FreeType)
|
|
|
|
LOAD_FUNCPTR(FT_Library_Version)
|
2014-12-08 10:24:39 +00:00
|
|
|
LOAD_FUNCPTR(FT_Load_Glyph)
|
2017-03-13 17:44:09 +00:00
|
|
|
LOAD_FUNCPTR(FT_Matrix_Multiply)
|
2021-03-29 07:48:52 +00:00
|
|
|
LOAD_FUNCPTR(FT_MulDiv)
|
2014-11-21 08:48:23 +00:00
|
|
|
LOAD_FUNCPTR(FT_New_Memory_Face)
|
2021-12-02 12:37:17 +00:00
|
|
|
LOAD_FUNCPTR(FT_New_Size)
|
2015-08-02 20:47:24 +00:00
|
|
|
LOAD_FUNCPTR(FT_Outline_Copy)
|
2016-01-18 21:47:09 +00:00
|
|
|
LOAD_FUNCPTR(FT_Outline_Decompose)
|
2015-08-02 20:47:24 +00:00
|
|
|
LOAD_FUNCPTR(FT_Outline_Done)
|
2017-03-15 19:35:32 +00:00
|
|
|
LOAD_FUNCPTR(FT_Outline_Embolden)
|
2015-07-30 22:30:08 +00:00
|
|
|
LOAD_FUNCPTR(FT_Outline_Get_Bitmap)
|
2015-08-02 20:47:24 +00:00
|
|
|
LOAD_FUNCPTR(FT_Outline_New)
|
2014-12-15 06:39:26 +00:00
|
|
|
LOAD_FUNCPTR(FT_Outline_Transform)
|
2015-07-30 22:30:08 +00:00
|
|
|
LOAD_FUNCPTR(FT_Outline_Translate)
|
2021-12-02 12:37:17 +00:00
|
|
|
LOAD_FUNCPTR(FT_Set_Pixel_Sizes)
|
2014-11-21 08:48:23 +00:00
|
|
|
#undef LOAD_FUNCPTR
|
2020-04-06 09:45:32 +00:00
|
|
|
pFT_Outline_EmboldenXY = dlsym(ft_handle, "FT_Outline_EmboldenXY");
|
2014-11-21 08:48:23 +00:00
|
|
|
|
2021-12-08 11:10:42 +00:00
|
|
|
if (pFT_Init_FreeType(&library) != 0)
|
|
|
|
{
|
2014-11-21 08:48:23 +00:00
|
|
|
ERR("Can't init FreeType library\n");
|
2021-12-08 11:10:42 +00:00
|
|
|
dlclose(ft_handle);
|
2014-11-21 08:48:23 +00:00
|
|
|
ft_handle = NULL;
|
2021-12-08 11:10:42 +00:00
|
|
|
return STATUS_UNSUCCESSFUL;
|
2014-11-21 08:48:23 +00:00
|
|
|
}
|
|
|
|
pFT_Library_Version(library, &FT_Version.major, &FT_Version.minor, &FT_Version.patch);
|
|
|
|
|
|
|
|
TRACE("FreeType version is %d.%d.%d\n", FT_Version.major, FT_Version.minor, FT_Version.patch);
|
2021-12-08 11:10:42 +00:00
|
|
|
return STATUS_SUCCESS;
|
2014-11-21 08:48:23 +00:00
|
|
|
|
|
|
|
sym_not_found:
|
|
|
|
WINE_MESSAGE("Wine cannot find certain functions that it needs from FreeType library.\n");
|
2020-04-06 09:45:32 +00:00
|
|
|
dlclose(ft_handle);
|
2014-11-21 08:48:23 +00:00
|
|
|
ft_handle = NULL;
|
2021-12-08 11:10:42 +00:00
|
|
|
return STATUS_UNSUCCESSFUL;
|
2014-11-21 08:48:23 +00:00
|
|
|
}
|
|
|
|
|
2021-12-08 11:10:42 +00:00
|
|
|
static NTSTATUS process_detach(void *args)
|
2021-12-02 12:37:15 +00:00
|
|
|
{
|
2021-12-08 11:10:42 +00:00
|
|
|
pFT_Done_FreeType(library);
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
static NTSTATUS create_font_object(void *args)
|
|
|
|
{
|
|
|
|
struct create_font_object_params *params = args;
|
2021-12-02 12:37:15 +00:00
|
|
|
FT_Face face = NULL;
|
|
|
|
FT_Error fterror;
|
|
|
|
|
2021-12-08 11:10:42 +00:00
|
|
|
fterror = pFT_New_Memory_Face(library, params->data, params->size, params->index, &face);
|
2021-12-02 12:37:15 +00:00
|
|
|
if (fterror != FT_Err_Ok)
|
2021-12-08 11:10:42 +00:00
|
|
|
{
|
2021-12-02 12:37:15 +00:00
|
|
|
WARN("Failed to create a face object, error %d.\n", fterror);
|
2021-12-08 11:10:42 +00:00
|
|
|
return STATUS_UNSUCCESSFUL;
|
|
|
|
}
|
|
|
|
|
|
|
|
*params->object = (ULONG_PTR)face;
|
2021-12-02 12:37:15 +00:00
|
|
|
|
2021-12-08 11:10:42 +00:00
|
|
|
return STATUS_SUCCESS;
|
2021-12-02 12:37:15 +00:00
|
|
|
}
|
|
|
|
|
2021-12-08 11:10:42 +00:00
|
|
|
static NTSTATUS release_font_object(void *args)
|
2021-12-02 12:37:15 +00:00
|
|
|
{
|
2021-12-08 11:10:42 +00:00
|
|
|
struct release_font_object_params *params = args;
|
|
|
|
pFT_Done_Face(FaceFromObject(params->object));
|
|
|
|
return STATUS_SUCCESS;
|
2021-12-02 12:37:15 +00:00
|
|
|
}
|
|
|
|
|
2021-12-08 11:10:42 +00:00
|
|
|
static NTSTATUS get_design_glyph_metrics(void *args)
|
2014-12-08 10:24:39 +00:00
|
|
|
{
|
2021-12-08 11:10:42 +00:00
|
|
|
struct get_design_glyph_metrics_params *params = args;
|
|
|
|
FT_Face face = FaceFromObject(params->object);
|
2014-12-08 10:24:39 +00:00
|
|
|
FT_Size size;
|
|
|
|
|
2021-12-08 11:10:42 +00:00
|
|
|
if (!(size = freetype_set_face_size(face, params->upem)))
|
|
|
|
return STATUS_UNSUCCESSFUL;
|
2014-12-08 10:24:39 +00:00
|
|
|
|
2021-12-08 11:10:42 +00:00
|
|
|
if (!pFT_Load_Glyph(face, params->glyph, FT_LOAD_NO_SCALE))
|
2021-12-02 12:37:17 +00:00
|
|
|
{
|
|
|
|
FT_Glyph_Metrics *metrics = &face->glyph->metrics;
|
|
|
|
|
2021-12-08 11:10:42 +00:00
|
|
|
params->metrics->leftSideBearing = metrics->horiBearingX;
|
|
|
|
params->metrics->advanceWidth = metrics->horiAdvance;
|
|
|
|
params->metrics->rightSideBearing = metrics->horiAdvance - metrics->horiBearingX - metrics->width;
|
2021-12-02 12:37:17 +00:00
|
|
|
|
2021-12-08 11:10:42 +00:00
|
|
|
params->metrics->advanceHeight = metrics->vertAdvance;
|
|
|
|
params->metrics->verticalOriginY = params->ascent;
|
|
|
|
params->metrics->topSideBearing = params->ascent - metrics->horiBearingY;
|
|
|
|
params->metrics->bottomSideBearing = metrics->vertAdvance - metrics->height - params->metrics->topSideBearing;
|
2021-12-02 12:37:17 +00:00
|
|
|
|
|
|
|
/* Adjust in case of bold simulation, glyphs without contours are ignored. */
|
2021-12-08 11:10:42 +00:00
|
|
|
if (params->simulations & DWRITE_FONT_SIMULATIONS_BOLD && freetype_glyph_has_contours(face))
|
2021-12-02 12:37:17 +00:00
|
|
|
{
|
2021-12-08 11:10:42 +00:00
|
|
|
if (params->metrics->advanceWidth)
|
|
|
|
params->metrics->advanceWidth += (params->upem + 49) / 50;
|
2021-12-02 12:37:17 +00:00
|
|
|
}
|
2014-11-21 08:48:23 +00:00
|
|
|
}
|
2021-12-02 12:37:17 +00:00
|
|
|
|
|
|
|
pFT_Done_Size(size);
|
2021-12-08 11:10:42 +00:00
|
|
|
|
|
|
|
return STATUS_SUCCESS;
|
2014-11-21 08:48:23 +00:00
|
|
|
}
|
|
|
|
|
2021-03-22 07:59:16 +00:00
|
|
|
struct decompose_context
|
|
|
|
{
|
|
|
|
struct dwrite_outline *outline;
|
2016-01-18 21:47:09 +00:00
|
|
|
BOOL figure_started;
|
|
|
|
BOOL move_to; /* last call was 'move_to' */
|
|
|
|
FT_Vector origin; /* 'pen' position from last call */
|
|
|
|
};
|
|
|
|
|
2021-03-22 07:59:16 +00:00
|
|
|
static inline void ft_vector_to_d2d_point(const FT_Vector *v, D2D1_POINT_2F *p)
|
2014-12-15 06:39:26 +00:00
|
|
|
{
|
2021-03-22 07:59:16 +00:00
|
|
|
p->x = v->x / 64.0f;
|
|
|
|
p->y = v->y / 64.0f;
|
2014-12-15 06:39:26 +00:00
|
|
|
}
|
|
|
|
|
2021-03-30 11:06:15 +00:00
|
|
|
static int dwrite_outline_push_tag(struct dwrite_outline *outline, unsigned char tag)
|
|
|
|
{
|
2021-12-02 12:37:18 +00:00
|
|
|
if (outline->tags.size < outline->tags.count + 1)
|
2021-03-30 11:06:15 +00:00
|
|
|
return 1;
|
|
|
|
|
|
|
|
outline->tags.values[outline->tags.count++] = tag;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int dwrite_outline_push_points(struct dwrite_outline *outline, const D2D1_POINT_2F *points, unsigned int count)
|
|
|
|
{
|
2021-12-02 12:37:18 +00:00
|
|
|
if (outline->points.size < outline->points.count + count)
|
2021-03-30 11:06:15 +00:00
|
|
|
return 1;
|
|
|
|
|
|
|
|
memcpy(&outline->points.values[outline->points.count], points, sizeof(*points) * count);
|
|
|
|
outline->points.count += count;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-03-22 07:59:16 +00:00
|
|
|
static int decompose_beginfigure(struct decompose_context *ctxt)
|
2017-08-25 05:29:46 +00:00
|
|
|
{
|
|
|
|
D2D1_POINT_2F point;
|
2021-03-22 07:59:16 +00:00
|
|
|
int ret;
|
2017-08-25 05:29:46 +00:00
|
|
|
|
|
|
|
if (!ctxt->move_to)
|
2021-03-22 07:59:16 +00:00
|
|
|
return 0;
|
2017-08-25 05:29:46 +00:00
|
|
|
|
2021-03-22 07:59:16 +00:00
|
|
|
ft_vector_to_d2d_point(&ctxt->origin, &point);
|
|
|
|
if ((ret = dwrite_outline_push_tag(ctxt->outline, OUTLINE_BEGIN_FIGURE))) return ret;
|
|
|
|
if ((ret = dwrite_outline_push_points(ctxt->outline, &point, 1))) return ret;
|
2017-08-25 05:29:46 +00:00
|
|
|
|
|
|
|
ctxt->figure_started = TRUE;
|
|
|
|
ctxt->move_to = FALSE;
|
2021-03-22 07:59:16 +00:00
|
|
|
|
|
|
|
return 0;
|
2017-08-25 05:29:46 +00:00
|
|
|
}
|
|
|
|
|
2016-01-18 21:47:09 +00:00
|
|
|
static int decompose_move_to(const FT_Vector *to, void *user)
|
2014-12-15 06:39:26 +00:00
|
|
|
{
|
2021-03-22 07:59:16 +00:00
|
|
|
struct decompose_context *ctxt = (struct decompose_context *)user;
|
|
|
|
int ret;
|
2016-01-18 21:47:09 +00:00
|
|
|
|
2021-03-22 07:59:16 +00:00
|
|
|
if (ctxt->figure_started)
|
|
|
|
{
|
|
|
|
if ((ret = dwrite_outline_push_tag(ctxt->outline, OUTLINE_END_FIGURE))) return ret;
|
2017-08-25 05:29:46 +00:00
|
|
|
ctxt->figure_started = FALSE;
|
2016-01-18 21:47:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ctxt->move_to = TRUE;
|
|
|
|
ctxt->origin = *to;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int decompose_line_to(const FT_Vector *to, void *user)
|
|
|
|
{
|
2021-03-22 07:59:16 +00:00
|
|
|
struct decompose_context *ctxt = (struct decompose_context *)user;
|
2017-08-25 05:29:46 +00:00
|
|
|
D2D1_POINT_2F point;
|
2021-03-22 07:59:16 +00:00
|
|
|
int ret;
|
2017-08-25 05:29:46 +00:00
|
|
|
|
|
|
|
/* Special case for empty contours, in a way freetype returns them. */
|
|
|
|
if (ctxt->move_to && !memcmp(to, &ctxt->origin, sizeof(*to)))
|
|
|
|
return 0;
|
|
|
|
|
2021-03-22 07:59:16 +00:00
|
|
|
ft_vector_to_d2d_point(to, &point);
|
2017-08-25 05:29:46 +00:00
|
|
|
|
2021-03-22 07:59:16 +00:00
|
|
|
if ((ret = decompose_beginfigure(ctxt))) return ret;
|
|
|
|
if ((ret = dwrite_outline_push_points(ctxt->outline, &point, 1))) return ret;
|
|
|
|
if ((ret = dwrite_outline_push_tag(ctxt->outline, OUTLINE_LINE))) return ret;
|
2017-08-25 05:29:46 +00:00
|
|
|
|
2016-01-18 21:47:09 +00:00
|
|
|
ctxt->origin = *to;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int decompose_conic_to(const FT_Vector *control, const FT_Vector *to, void *user)
|
|
|
|
{
|
2021-03-22 07:59:16 +00:00
|
|
|
struct decompose_context *ctxt = (struct decompose_context *)user;
|
2016-01-18 21:47:09 +00:00
|
|
|
D2D1_POINT_2F points[3];
|
|
|
|
FT_Vector cubic[3];
|
2021-03-22 07:59:16 +00:00
|
|
|
int ret;
|
2016-01-18 21:47:09 +00:00
|
|
|
|
2021-03-22 07:59:16 +00:00
|
|
|
if ((ret = decompose_beginfigure(ctxt)))
|
|
|
|
return ret;
|
2017-08-25 05:29:46 +00:00
|
|
|
|
2016-01-18 21:47:09 +00:00
|
|
|
/* convert from quadratic to cubic */
|
|
|
|
|
2015-06-09 21:13:34 +00:00
|
|
|
/*
|
|
|
|
The parametric eqn for a cubic Bezier is, from PLRM:
|
|
|
|
r(t) = at^3 + bt^2 + ct + r0
|
|
|
|
with the control points:
|
|
|
|
r1 = r0 + c/3
|
|
|
|
r2 = r1 + (c + b)/3
|
|
|
|
r3 = r0 + c + b + a
|
|
|
|
|
|
|
|
A quadratic Bezier has the form:
|
|
|
|
p(t) = (1-t)^2 p0 + 2(1-t)t p1 + t^2 p2
|
|
|
|
|
|
|
|
So equating powers of t leads to:
|
|
|
|
r1 = 2/3 p1 + 1/3 p0
|
|
|
|
r2 = 2/3 p1 + 1/3 p2
|
|
|
|
and of course r0 = p0, r3 = p2
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* r1 = 1/3 p0 + 2/3 p1
|
|
|
|
r2 = 1/3 p2 + 2/3 p1 */
|
2016-01-18 21:47:09 +00:00
|
|
|
cubic[0].x = (2 * control->x + 1) / 3;
|
|
|
|
cubic[0].y = (2 * control->y + 1) / 3;
|
|
|
|
cubic[1] = cubic[0];
|
|
|
|
cubic[0].x += (ctxt->origin.x + 1) / 3;
|
|
|
|
cubic[0].y += (ctxt->origin.y + 1) / 3;
|
|
|
|
cubic[1].x += (to->x + 1) / 3;
|
|
|
|
cubic[1].y += (to->y + 1) / 3;
|
|
|
|
cubic[2] = *to;
|
|
|
|
|
2021-03-22 07:59:16 +00:00
|
|
|
ft_vector_to_d2d_point(cubic, points);
|
|
|
|
ft_vector_to_d2d_point(cubic + 1, points + 1);
|
|
|
|
ft_vector_to_d2d_point(cubic + 2, points + 2);
|
|
|
|
if ((ret = dwrite_outline_push_points(ctxt->outline, points, 3))) return ret;
|
|
|
|
if ((ret = dwrite_outline_push_tag(ctxt->outline, OUTLINE_BEZIER))) return ret;
|
2016-01-18 21:47:09 +00:00
|
|
|
ctxt->origin = *to;
|
|
|
|
return 0;
|
|
|
|
}
|
2014-12-15 06:39:26 +00:00
|
|
|
|
2016-01-18 21:47:09 +00:00
|
|
|
static int decompose_cubic_to(const FT_Vector *control1, const FT_Vector *control2,
|
|
|
|
const FT_Vector *to, void *user)
|
|
|
|
{
|
2021-03-22 07:59:16 +00:00
|
|
|
struct decompose_context *ctxt = (struct decompose_context *)user;
|
2016-01-18 21:47:09 +00:00
|
|
|
D2D1_POINT_2F points[3];
|
2021-03-22 07:59:16 +00:00
|
|
|
int ret;
|
2014-12-15 06:39:26 +00:00
|
|
|
|
2021-03-22 07:59:16 +00:00
|
|
|
if ((ret = decompose_beginfigure(ctxt)))
|
|
|
|
return ret;
|
2017-08-25 05:29:46 +00:00
|
|
|
|
2021-03-22 07:59:16 +00:00
|
|
|
ft_vector_to_d2d_point(control1, points);
|
|
|
|
ft_vector_to_d2d_point(control2, points + 1);
|
|
|
|
ft_vector_to_d2d_point(to, points + 2);
|
2016-01-18 21:47:09 +00:00
|
|
|
ctxt->origin = *to;
|
2021-03-22 07:59:16 +00:00
|
|
|
|
|
|
|
if ((ret = dwrite_outline_push_points(ctxt->outline, points, 3))) return ret;
|
|
|
|
if ((ret = dwrite_outline_push_tag(ctxt->outline, OUTLINE_BEZIER))) return ret;
|
|
|
|
|
2016-01-18 21:47:09 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2015-06-09 21:13:34 +00:00
|
|
|
|
2021-03-22 07:59:16 +00:00
|
|
|
static int decompose_outline(FT_Outline *ft_outline, struct dwrite_outline *outline)
|
2016-01-18 21:47:09 +00:00
|
|
|
{
|
2021-03-22 07:59:16 +00:00
|
|
|
static const FT_Outline_Funcs decompose_funcs =
|
|
|
|
{
|
2016-01-18 21:47:09 +00:00
|
|
|
decompose_move_to,
|
|
|
|
decompose_line_to,
|
|
|
|
decompose_conic_to,
|
|
|
|
decompose_cubic_to,
|
|
|
|
0,
|
|
|
|
0
|
|
|
|
};
|
2021-03-22 07:59:16 +00:00
|
|
|
struct decompose_context context = { 0 };
|
|
|
|
int ret;
|
2014-12-15 06:39:26 +00:00
|
|
|
|
2021-03-22 07:59:16 +00:00
|
|
|
context.outline = outline;
|
2015-07-12 20:37:05 +00:00
|
|
|
|
2021-03-22 07:59:16 +00:00
|
|
|
ret = pFT_Outline_Decompose(ft_outline, &decompose_funcs, &context);
|
2016-01-18 21:47:09 +00:00
|
|
|
|
2021-03-22 07:59:16 +00:00
|
|
|
if (!ret && context.figure_started)
|
|
|
|
ret = dwrite_outline_push_tag(outline, OUTLINE_END_FIGURE);
|
|
|
|
|
|
|
|
return ret;
|
2014-12-15 06:39:26 +00:00
|
|
|
}
|
|
|
|
|
2017-03-15 19:35:32 +00:00
|
|
|
static void embolden_glyph_outline(FT_Outline *outline, FLOAT emsize)
|
|
|
|
{
|
|
|
|
FT_Pos strength;
|
|
|
|
|
2021-03-29 07:48:52 +00:00
|
|
|
strength = pFT_MulDiv(emsize, 1 << 6, 24);
|
2017-03-15 19:35:32 +00:00
|
|
|
if (pFT_Outline_EmboldenXY)
|
|
|
|
pFT_Outline_EmboldenXY(outline, strength, 0);
|
|
|
|
else
|
|
|
|
pFT_Outline_Embolden(outline, strength);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void embolden_glyph(FT_Glyph glyph, FLOAT emsize)
|
|
|
|
{
|
|
|
|
FT_OutlineGlyph outline_glyph = (FT_OutlineGlyph)glyph;
|
|
|
|
|
|
|
|
if (glyph->format != FT_GLYPH_FORMAT_OUTLINE)
|
|
|
|
return;
|
|
|
|
|
|
|
|
embolden_glyph_outline(&outline_glyph->outline, emsize);
|
|
|
|
}
|
|
|
|
|
2021-12-08 11:10:42 +00:00
|
|
|
static NTSTATUS get_glyph_outline(void *args)
|
2014-12-15 06:39:26 +00:00
|
|
|
{
|
2021-12-08 11:10:42 +00:00
|
|
|
struct get_glyph_outline_params *params = args;
|
|
|
|
FT_Face face = FaceFromObject(params->object);
|
2014-12-15 06:39:26 +00:00
|
|
|
FT_Size size;
|
|
|
|
|
2021-12-08 11:10:42 +00:00
|
|
|
if (!(size = freetype_set_face_size(face, params->emsize)))
|
|
|
|
return STATUS_UNSUCCESSFUL;
|
2014-12-15 06:39:26 +00:00
|
|
|
|
2021-12-08 11:10:42 +00:00
|
|
|
if (!pFT_Load_Glyph(face, params->glyph, FT_LOAD_NO_BITMAP))
|
2021-02-22 18:29:36 +00:00
|
|
|
{
|
2021-12-02 12:37:18 +00:00
|
|
|
FT_Outline *ft_outline = &face->glyph->outline;
|
|
|
|
FT_Matrix m;
|
2021-03-15 07:36:51 +00:00
|
|
|
|
2021-12-08 11:10:42 +00:00
|
|
|
if (params->outline->points.values)
|
2021-12-02 12:37:18 +00:00
|
|
|
{
|
2021-12-08 11:10:42 +00:00
|
|
|
if (params->simulations & DWRITE_FONT_SIMULATIONS_BOLD)
|
|
|
|
embolden_glyph_outline(ft_outline, params->emsize);
|
2021-03-15 07:36:51 +00:00
|
|
|
|
|
|
|
m.xx = 1 << 16;
|
2021-12-08 11:10:42 +00:00
|
|
|
m.xy = params->simulations & DWRITE_FONT_SIMULATIONS_OBLIQUE ? (1 << 16) / 3 : 0;
|
2021-03-15 07:36:51 +00:00
|
|
|
m.yx = 0;
|
|
|
|
m.yy = -(1 << 16); /* flip Y axis */
|
|
|
|
|
2021-03-22 07:59:16 +00:00
|
|
|
pFT_Outline_Transform(ft_outline, &m);
|
2021-03-15 07:36:51 +00:00
|
|
|
|
2021-12-08 11:10:42 +00:00
|
|
|
decompose_outline(ft_outline, params->outline);
|
2016-01-18 21:47:09 +00:00
|
|
|
}
|
2021-12-02 12:37:18 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Intentionally overestimate numbers to keep it simple. */
|
2021-12-08 11:10:42 +00:00
|
|
|
params->outline->points.count = ft_outline->n_points * 3;
|
|
|
|
params->outline->tags.count = ft_outline->n_points + ft_outline->n_contours * 2;
|
2021-12-02 12:37:18 +00:00
|
|
|
}
|
2014-12-15 06:39:26 +00:00
|
|
|
}
|
2021-12-02 12:37:18 +00:00
|
|
|
|
|
|
|
pFT_Done_Size(size);
|
2014-12-15 06:39:26 +00:00
|
|
|
|
2021-12-08 11:10:42 +00:00
|
|
|
return STATUS_SUCCESS;
|
2014-12-15 06:39:26 +00:00
|
|
|
}
|
|
|
|
|
2021-12-08 11:10:42 +00:00
|
|
|
static NTSTATUS get_glyph_count(void *args)
|
2015-02-05 12:54:05 +00:00
|
|
|
{
|
2021-12-08 11:10:42 +00:00
|
|
|
struct get_glyph_count_params *params = args;
|
|
|
|
FT_Face face = FaceFromObject(params->object);
|
|
|
|
|
|
|
|
*params->count = face ? face->num_glyphs : 0;
|
|
|
|
|
|
|
|
return STATUS_SUCCESS;
|
2015-02-05 12:54:05 +00:00
|
|
|
}
|
|
|
|
|
2023-03-22 09:14:24 +00:00
|
|
|
static inline void ft_matrix_from_matrix_2x2(const MATRIX_2X2 *m, FT_Matrix *ft_matrix)
|
2015-11-02 13:38:43 +00:00
|
|
|
{
|
|
|
|
ft_matrix->xx = m->m11 * 0x10000;
|
|
|
|
ft_matrix->xy = -m->m21 * 0x10000;
|
|
|
|
ft_matrix->yx = -m->m12 * 0x10000;
|
|
|
|
ft_matrix->yy = m->m22 * 0x10000;
|
|
|
|
}
|
|
|
|
|
2023-03-22 09:14:24 +00:00
|
|
|
static BOOL get_glyph_transform(unsigned int simulations, const MATRIX_2X2 *m, FT_Matrix *ret)
|
2017-03-13 17:44:09 +00:00
|
|
|
{
|
2021-12-08 11:10:42 +00:00
|
|
|
FT_Matrix ftm;
|
2017-03-13 17:44:09 +00:00
|
|
|
|
|
|
|
ret->xx = 1 << 16;
|
|
|
|
ret->xy = 0;
|
|
|
|
ret->yx = 0;
|
|
|
|
ret->yy = 1 << 16;
|
|
|
|
|
|
|
|
/* Some fonts provide mostly bitmaps and very few outlines, for example for .notdef.
|
|
|
|
Disable transform if that's the case. */
|
2023-03-22 09:14:24 +00:00
|
|
|
if (!memcmp(m, &identity_2x2, sizeof(*m)) && !simulations)
|
2017-03-13 17:44:09 +00:00
|
|
|
return FALSE;
|
|
|
|
|
2021-12-08 11:10:42 +00:00
|
|
|
if (simulations & DWRITE_FONT_SIMULATIONS_OBLIQUE)
|
|
|
|
{
|
|
|
|
ftm.xx = 1 << 16;
|
|
|
|
ftm.xy = (1 << 16) / 3;
|
|
|
|
ftm.yx = 0;
|
|
|
|
ftm.yy = 1 << 16;
|
|
|
|
pFT_Matrix_Multiply(&ftm, ret);
|
2017-03-13 17:44:09 +00:00
|
|
|
}
|
|
|
|
|
2023-03-22 09:14:24 +00:00
|
|
|
ft_matrix_from_matrix_2x2(m, &ftm);
|
2021-12-08 11:10:42 +00:00
|
|
|
pFT_Matrix_Multiply(&ftm, ret);
|
2017-03-13 17:44:09 +00:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2021-12-08 11:10:42 +00:00
|
|
|
static NTSTATUS get_glyph_bbox(void *args)
|
2015-07-29 08:59:02 +00:00
|
|
|
{
|
2021-12-08 11:10:42 +00:00
|
|
|
struct get_glyph_bbox_params *params = args;
|
|
|
|
FT_Face face = FaceFromObject(params->object);
|
2021-12-07 12:59:45 +00:00
|
|
|
FT_Glyph glyph = NULL;
|
2015-07-29 08:59:02 +00:00
|
|
|
FT_BBox bbox = { 0 };
|
2017-03-13 17:44:09 +00:00
|
|
|
BOOL needs_transform;
|
|
|
|
FT_Matrix m;
|
2021-12-07 12:59:45 +00:00
|
|
|
FT_Size size;
|
2015-07-29 08:59:02 +00:00
|
|
|
|
2021-12-08 11:10:42 +00:00
|
|
|
SetRectEmpty(params->bbox);
|
2015-11-02 13:38:43 +00:00
|
|
|
|
2021-12-08 11:10:42 +00:00
|
|
|
if (!(size = freetype_set_face_size(face, params->emsize)))
|
|
|
|
return STATUS_UNSUCCESSFUL;
|
2015-11-02 13:38:43 +00:00
|
|
|
|
2021-12-08 11:10:42 +00:00
|
|
|
needs_transform = FT_IS_SCALABLE(face) && get_glyph_transform(params->simulations, ¶ms->m, &m);
|
2015-11-02 13:38:43 +00:00
|
|
|
|
2021-12-08 11:10:42 +00:00
|
|
|
if (pFT_Load_Glyph(face, params->glyph, needs_transform ? FT_LOAD_NO_BITMAP : 0))
|
2021-12-07 12:59:45 +00:00
|
|
|
{
|
2021-12-08 11:10:42 +00:00
|
|
|
WARN("Failed to load glyph %u.\n", params->glyph);
|
2021-12-07 12:59:45 +00:00
|
|
|
pFT_Done_Size(size);
|
2021-12-08 11:10:42 +00:00
|
|
|
return STATUS_UNSUCCESSFUL;
|
2021-12-07 12:59:45 +00:00
|
|
|
}
|
2015-11-02 13:38:43 +00:00
|
|
|
|
2021-12-07 12:59:45 +00:00
|
|
|
pFT_Get_Glyph(face->glyph, &glyph);
|
|
|
|
if (needs_transform)
|
|
|
|
{
|
2021-12-08 11:10:42 +00:00
|
|
|
if (params->simulations & DWRITE_FONT_SIMULATIONS_BOLD)
|
|
|
|
embolden_glyph(glyph, params->emsize);
|
2017-03-15 19:35:32 +00:00
|
|
|
|
2021-12-07 12:59:45 +00:00
|
|
|
/* Includes oblique and user transform. */
|
|
|
|
pFT_Glyph_Transform(glyph, &m, NULL);
|
2015-11-02 13:38:43 +00:00
|
|
|
}
|
2015-07-29 08:59:02 +00:00
|
|
|
|
2021-12-07 12:59:45 +00:00
|
|
|
pFT_Glyph_Get_CBox(glyph, FT_GLYPH_BBOX_PIXELS, &bbox);
|
|
|
|
pFT_Done_Glyph(glyph);
|
|
|
|
pFT_Done_Size(size);
|
2015-07-29 08:59:02 +00:00
|
|
|
|
|
|
|
/* flip Y axis */
|
2021-12-08 11:10:42 +00:00
|
|
|
SetRect(params->bbox, bbox.xMin, -bbox.yMax, bbox.xMax, -bbox.yMin);
|
|
|
|
|
|
|
|
return STATUS_SUCCESS;
|
2015-07-29 08:59:02 +00:00
|
|
|
}
|
|
|
|
|
2021-12-08 11:10:42 +00:00
|
|
|
static NTSTATUS freetype_get_aliased_glyph_bitmap(struct get_glyph_bitmap_params *params, FT_Glyph glyph)
|
2015-07-30 22:30:08 +00:00
|
|
|
{
|
2021-12-08 11:10:42 +00:00
|
|
|
const RECT *bbox = ¶ms->bbox;
|
2015-08-27 05:39:45 +00:00
|
|
|
int width = bbox->right - bbox->left;
|
|
|
|
int height = bbox->bottom - bbox->top;
|
|
|
|
|
2021-12-08 11:10:42 +00:00
|
|
|
*params->is_1bpp = 1;
|
|
|
|
|
2015-08-27 05:39:45 +00:00
|
|
|
if (glyph->format == FT_GLYPH_FORMAT_OUTLINE) {
|
|
|
|
FT_OutlineGlyph outline = (FT_OutlineGlyph)glyph;
|
|
|
|
const FT_Outline *src = &outline->outline;
|
|
|
|
FT_Bitmap ft_bitmap;
|
|
|
|
FT_Outline copy;
|
|
|
|
|
|
|
|
ft_bitmap.width = width;
|
|
|
|
ft_bitmap.rows = height;
|
2021-12-08 11:10:42 +00:00
|
|
|
ft_bitmap.pitch = params->pitch;
|
2015-08-27 05:39:45 +00:00
|
|
|
ft_bitmap.pixel_mode = FT_PIXEL_MODE_MONO;
|
2021-12-08 11:10:42 +00:00
|
|
|
ft_bitmap.buffer = params->bitmap;
|
2015-08-27 05:39:45 +00:00
|
|
|
|
|
|
|
/* Note: FreeType will only set 'black' bits for us. */
|
|
|
|
if (pFT_Outline_New(library, src->n_points, src->n_contours, ©) == 0) {
|
|
|
|
pFT_Outline_Copy(src, ©);
|
|
|
|
pFT_Outline_Translate(©, -bbox->left << 6, bbox->bottom << 6);
|
|
|
|
pFT_Outline_Get_Bitmap(library, ©, &ft_bitmap);
|
|
|
|
pFT_Outline_Done(library, ©);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (glyph->format == FT_GLYPH_FORMAT_BITMAP) {
|
|
|
|
FT_Bitmap *ft_bitmap = &((FT_BitmapGlyph)glyph)->bitmap;
|
2021-12-08 11:10:42 +00:00
|
|
|
BYTE *src = ft_bitmap->buffer, *dst = params->bitmap;
|
|
|
|
int w = min(params->pitch, (ft_bitmap->width + 7) >> 3);
|
2015-08-27 05:39:45 +00:00
|
|
|
int h = min(height, ft_bitmap->rows);
|
|
|
|
|
|
|
|
while (h--) {
|
|
|
|
memcpy(dst, src, w);
|
|
|
|
src += ft_bitmap->pitch;
|
2021-12-08 11:10:42 +00:00
|
|
|
dst += params->pitch;
|
2015-08-27 05:39:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
FIXME("format %x not handled\n", glyph->format);
|
|
|
|
|
2021-12-08 11:10:42 +00:00
|
|
|
return STATUS_SUCCESS;
|
2015-08-27 05:39:45 +00:00
|
|
|
}
|
|
|
|
|
2021-12-08 11:10:42 +00:00
|
|
|
static NTSTATUS freetype_get_aa_glyph_bitmap(struct get_glyph_bitmap_params *params, FT_Glyph glyph)
|
2015-08-27 05:39:45 +00:00
|
|
|
{
|
2021-12-08 11:10:42 +00:00
|
|
|
const RECT *bbox = ¶ms->bbox;
|
2015-08-27 05:39:45 +00:00
|
|
|
int width = bbox->right - bbox->left;
|
|
|
|
int height = bbox->bottom - bbox->top;
|
2021-12-08 11:10:42 +00:00
|
|
|
|
|
|
|
*params->is_1bpp = 0;
|
2015-08-27 05:39:45 +00:00
|
|
|
|
|
|
|
if (glyph->format == FT_GLYPH_FORMAT_OUTLINE) {
|
|
|
|
FT_OutlineGlyph outline = (FT_OutlineGlyph)glyph;
|
|
|
|
const FT_Outline *src = &outline->outline;
|
|
|
|
FT_Bitmap ft_bitmap;
|
|
|
|
FT_Outline copy;
|
|
|
|
|
|
|
|
ft_bitmap.width = width;
|
|
|
|
ft_bitmap.rows = height;
|
2021-12-08 11:10:42 +00:00
|
|
|
ft_bitmap.pitch = params->pitch;
|
2015-08-27 05:39:45 +00:00
|
|
|
ft_bitmap.pixel_mode = FT_PIXEL_MODE_GRAY;
|
2021-12-08 11:10:42 +00:00
|
|
|
ft_bitmap.buffer = params->bitmap;
|
2015-08-27 05:39:45 +00:00
|
|
|
|
|
|
|
/* Note: FreeType will only set 'black' bits for us. */
|
|
|
|
if (pFT_Outline_New(library, src->n_points, src->n_contours, ©) == 0) {
|
|
|
|
pFT_Outline_Copy(src, ©);
|
|
|
|
pFT_Outline_Translate(©, -bbox->left << 6, bbox->bottom << 6);
|
|
|
|
pFT_Outline_Get_Bitmap(library, ©, &ft_bitmap);
|
|
|
|
pFT_Outline_Done(library, ©);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (glyph->format == FT_GLYPH_FORMAT_BITMAP) {
|
|
|
|
FT_Bitmap *ft_bitmap = &((FT_BitmapGlyph)glyph)->bitmap;
|
2021-12-08 11:10:42 +00:00
|
|
|
BYTE *src = ft_bitmap->buffer, *dst = params->bitmap;
|
|
|
|
int w = min(params->pitch, (ft_bitmap->width + 7) >> 3);
|
2015-08-27 05:39:45 +00:00
|
|
|
int h = min(height, ft_bitmap->rows);
|
|
|
|
|
|
|
|
while (h--) {
|
|
|
|
memcpy(dst, src, w);
|
|
|
|
src += ft_bitmap->pitch;
|
2021-12-08 11:10:42 +00:00
|
|
|
dst += params->pitch;
|
2015-08-27 05:39:45 +00:00
|
|
|
}
|
|
|
|
|
2021-12-08 11:10:42 +00:00
|
|
|
*params->is_1bpp = 1;
|
2015-08-27 05:39:45 +00:00
|
|
|
}
|
|
|
|
else
|
2021-12-08 11:10:42 +00:00
|
|
|
{
|
2015-08-27 05:39:45 +00:00
|
|
|
FIXME("format %x not handled\n", glyph->format);
|
2021-12-08 11:10:42 +00:00
|
|
|
return STATUS_NOT_IMPLEMENTED;
|
|
|
|
}
|
2015-08-27 05:39:45 +00:00
|
|
|
|
2021-12-08 11:10:42 +00:00
|
|
|
return STATUS_SUCCESS;
|
2015-08-27 05:39:45 +00:00
|
|
|
}
|
|
|
|
|
2021-12-08 11:10:42 +00:00
|
|
|
static NTSTATUS get_glyph_bitmap(void *args)
|
2015-08-27 05:39:45 +00:00
|
|
|
{
|
2021-12-08 11:10:42 +00:00
|
|
|
struct get_glyph_bitmap_params *params = args;
|
|
|
|
FT_Face face = FaceFromObject(params->object);
|
2017-03-13 17:44:09 +00:00
|
|
|
BOOL needs_transform;
|
2015-08-27 05:39:45 +00:00
|
|
|
BOOL ret = FALSE;
|
2015-07-30 22:30:08 +00:00
|
|
|
FT_Glyph glyph;
|
2021-12-07 12:59:46 +00:00
|
|
|
FT_Size size;
|
2017-03-13 17:44:09 +00:00
|
|
|
FT_Matrix m;
|
2015-07-30 22:30:08 +00:00
|
|
|
|
2021-12-08 11:10:42 +00:00
|
|
|
*params->is_1bpp = 0;
|
2015-11-02 13:38:43 +00:00
|
|
|
|
2021-12-08 11:10:42 +00:00
|
|
|
if (!(size = freetype_set_face_size(face, params->emsize)))
|
|
|
|
return STATUS_UNSUCCESSFUL;
|
2015-07-30 22:30:08 +00:00
|
|
|
|
2021-12-08 11:10:42 +00:00
|
|
|
needs_transform = FT_IS_SCALABLE(face) && get_glyph_transform(params->simulations, ¶ms->m, &m);
|
|
|
|
|
|
|
|
if (!pFT_Load_Glyph(face, params->glyph, needs_transform ? FT_LOAD_NO_BITMAP : 0))
|
2021-12-07 12:59:46 +00:00
|
|
|
{
|
|
|
|
pFT_Get_Glyph(face->glyph, &glyph);
|
2015-11-02 13:38:43 +00:00
|
|
|
|
2021-12-07 12:59:46 +00:00
|
|
|
if (needs_transform)
|
|
|
|
{
|
2021-12-08 11:10:42 +00:00
|
|
|
if (params->simulations & DWRITE_FONT_SIMULATIONS_BOLD)
|
|
|
|
embolden_glyph(glyph, params->emsize);
|
2017-03-15 19:35:32 +00:00
|
|
|
|
2021-12-07 12:59:46 +00:00
|
|
|
/* Includes oblique and user transform. */
|
|
|
|
pFT_Glyph_Transform(glyph, &m, NULL);
|
2015-11-02 13:38:43 +00:00
|
|
|
}
|
|
|
|
|
2021-12-08 11:10:42 +00:00
|
|
|
if (params->mode == DWRITE_RENDERING_MODE1_ALIASED)
|
|
|
|
ret = freetype_get_aliased_glyph_bitmap(params, glyph);
|
2017-09-05 10:35:29 +00:00
|
|
|
else
|
2021-12-08 11:10:42 +00:00
|
|
|
ret = freetype_get_aa_glyph_bitmap(params, glyph);
|
2015-11-02 13:38:43 +00:00
|
|
|
|
2021-12-07 12:59:46 +00:00
|
|
|
pFT_Done_Glyph(glyph);
|
2015-07-30 22:30:08 +00:00
|
|
|
}
|
2015-11-02 13:38:43 +00:00
|
|
|
|
2021-12-07 12:59:46 +00:00
|
|
|
pFT_Done_Size(size);
|
2015-08-27 05:39:45 +00:00
|
|
|
|
|
|
|
return ret;
|
2015-07-30 22:30:08 +00:00
|
|
|
}
|
|
|
|
|
2021-12-08 11:10:42 +00:00
|
|
|
static NTSTATUS get_glyph_advance(void *args)
|
2015-08-24 07:43:19 +00:00
|
|
|
{
|
2021-12-08 11:10:42 +00:00
|
|
|
struct get_glyph_advance_params *params = args;
|
|
|
|
FT_Face face = FaceFromObject(params->object);
|
2021-12-06 13:17:50 +00:00
|
|
|
FT_Size size;
|
2015-08-24 07:43:19 +00:00
|
|
|
|
2021-12-08 11:10:42 +00:00
|
|
|
*params->advance = 0;
|
|
|
|
*params->has_contours = FALSE;
|
2015-08-24 07:43:19 +00:00
|
|
|
|
2021-12-08 11:10:42 +00:00
|
|
|
if (!(size = freetype_set_face_size(face, params->emsize)))
|
|
|
|
return STATUS_UNSUCCESSFUL;
|
2021-12-06 13:17:50 +00:00
|
|
|
|
2021-12-08 11:10:42 +00:00
|
|
|
if (!pFT_Load_Glyph(face, params->glyph, params->mode == DWRITE_MEASURING_MODE_NATURAL ? FT_LOAD_NO_HINTING : 0))
|
2021-12-06 13:17:50 +00:00
|
|
|
{
|
2021-12-08 11:10:42 +00:00
|
|
|
*params->advance = face->glyph->advance.x >> 6;
|
|
|
|
*params->has_contours = freetype_glyph_has_contours(face);
|
2017-03-15 19:35:32 +00:00
|
|
|
}
|
2021-12-06 13:17:50 +00:00
|
|
|
|
|
|
|
pFT_Done_Size(size);
|
2015-08-24 07:43:19 +00:00
|
|
|
|
2021-03-29 07:48:51 +00:00
|
|
|
return STATUS_SUCCESS;
|
2014-12-08 10:24:39 +00:00
|
|
|
}
|
|
|
|
|
2021-03-29 07:48:51 +00:00
|
|
|
#else /* HAVE_FREETYPE */
|
|
|
|
|
2021-12-08 11:10:42 +00:00
|
|
|
static NTSTATUS process_attach(void *args)
|
2021-12-02 12:37:15 +00:00
|
|
|
{
|
2021-12-08 11:10:42 +00:00
|
|
|
return STATUS_NOT_IMPLEMENTED;
|
2021-12-02 12:37:15 +00:00
|
|
|
}
|
|
|
|
|
2021-12-08 11:10:42 +00:00
|
|
|
static NTSTATUS process_detach(void *args)
|
2021-12-02 12:37:15 +00:00
|
|
|
{
|
2021-12-08 11:10:42 +00:00
|
|
|
return STATUS_NOT_IMPLEMENTED;
|
2021-12-02 12:37:15 +00:00
|
|
|
}
|
|
|
|
|
2021-12-08 11:10:42 +00:00
|
|
|
static NTSTATUS create_font_object(void *args)
|
2014-11-21 08:48:23 +00:00
|
|
|
{
|
2021-12-08 11:10:42 +00:00
|
|
|
return STATUS_NOT_IMPLEMENTED;
|
2014-11-21 08:48:23 +00:00
|
|
|
}
|
|
|
|
|
2021-12-08 11:10:42 +00:00
|
|
|
static NTSTATUS release_font_object(void *args)
|
2014-12-15 06:39:26 +00:00
|
|
|
{
|
2021-12-08 11:10:42 +00:00
|
|
|
return STATUS_NOT_IMPLEMENTED;
|
2014-12-15 06:39:26 +00:00
|
|
|
}
|
|
|
|
|
2021-12-08 11:10:42 +00:00
|
|
|
static NTSTATUS get_glyph_outline(void *args)
|
2015-02-05 12:54:05 +00:00
|
|
|
{
|
2021-12-08 11:10:42 +00:00
|
|
|
return STATUS_NOT_IMPLEMENTED;
|
2015-02-05 12:54:05 +00:00
|
|
|
}
|
|
|
|
|
2021-12-08 11:10:42 +00:00
|
|
|
static NTSTATUS get_glyph_count(void *args)
|
2015-07-29 08:59:02 +00:00
|
|
|
{
|
2021-12-08 11:10:42 +00:00
|
|
|
return STATUS_NOT_IMPLEMENTED;
|
2015-07-29 08:59:02 +00:00
|
|
|
}
|
|
|
|
|
2021-12-08 11:10:42 +00:00
|
|
|
static NTSTATUS get_glyph_advance(void *args)
|
2015-07-30 22:30:08 +00:00
|
|
|
{
|
2021-12-08 11:10:42 +00:00
|
|
|
struct get_glyph_advance_params *params = args;
|
2015-07-30 22:30:08 +00:00
|
|
|
|
2021-12-08 11:10:42 +00:00
|
|
|
*params->has_contours = 0;
|
|
|
|
*params->advance = 0;
|
|
|
|
|
|
|
|
return STATUS_NOT_IMPLEMENTED;
|
2015-08-24 07:43:19 +00:00
|
|
|
}
|
|
|
|
|
2021-12-08 11:10:42 +00:00
|
|
|
static NTSTATUS get_glyph_bbox(void *args)
|
2021-03-29 07:48:53 +00:00
|
|
|
{
|
2021-12-08 11:10:42 +00:00
|
|
|
struct get_glyph_bbox_params *params = args;
|
|
|
|
SetRectEmpty(params->bbox);
|
|
|
|
return STATUS_NOT_IMPLEMENTED;
|
|
|
|
}
|
2021-03-29 07:48:53 +00:00
|
|
|
|
2021-12-08 11:10:42 +00:00
|
|
|
static NTSTATUS get_glyph_bitmap(void *args)
|
2021-03-29 07:48:51 +00:00
|
|
|
{
|
2021-12-08 11:10:42 +00:00
|
|
|
return STATUS_NOT_IMPLEMENTED;
|
2021-03-29 07:48:51 +00:00
|
|
|
}
|
|
|
|
|
2021-12-08 11:10:42 +00:00
|
|
|
static NTSTATUS get_design_glyph_metrics(void *args)
|
2021-03-29 07:48:51 +00:00
|
|
|
{
|
2021-12-08 11:10:42 +00:00
|
|
|
return STATUS_NOT_IMPLEMENTED;
|
2021-03-29 07:48:51 +00:00
|
|
|
}
|
|
|
|
|
2014-11-21 08:48:23 +00:00
|
|
|
#endif /* HAVE_FREETYPE */
|
2021-03-29 07:48:51 +00:00
|
|
|
|
2021-12-08 11:10:42 +00:00
|
|
|
const unixlib_entry_t __wine_unix_call_funcs[] =
|
|
|
|
{
|
|
|
|
process_attach,
|
|
|
|
process_detach,
|
|
|
|
create_font_object,
|
|
|
|
release_font_object,
|
|
|
|
get_glyph_outline,
|
|
|
|
get_glyph_count,
|
|
|
|
get_glyph_advance,
|
|
|
|
get_glyph_bbox,
|
|
|
|
get_glyph_bitmap,
|
|
|
|
get_design_glyph_metrics,
|
|
|
|
};
|
2021-12-08 11:10:43 +00:00
|
|
|
|
|
|
|
#ifdef _WIN64
|
|
|
|
|
|
|
|
typedef ULONG PTR32;
|
|
|
|
|
|
|
|
static NTSTATUS wow64_create_font_object(void *args)
|
|
|
|
{
|
|
|
|
struct
|
|
|
|
{
|
|
|
|
PTR32 data;
|
|
|
|
UINT64 size;
|
|
|
|
ULONG index;
|
|
|
|
PTR32 object;
|
|
|
|
} const *params32 = args;
|
|
|
|
struct create_font_object_params params =
|
|
|
|
{
|
|
|
|
ULongToPtr(params32->data),
|
|
|
|
params32->size,
|
|
|
|
params32->index,
|
|
|
|
ULongToPtr(params32->object),
|
|
|
|
};
|
|
|
|
|
|
|
|
return create_font_object(¶ms);
|
|
|
|
}
|
|
|
|
|
|
|
|
static NTSTATUS wow64_release_font_object(void *args)
|
|
|
|
{
|
|
|
|
struct
|
|
|
|
{
|
|
|
|
UINT64 object;
|
|
|
|
} const *params32 = args;
|
|
|
|
struct release_font_object_params params =
|
|
|
|
{
|
|
|
|
params32->object
|
|
|
|
};
|
|
|
|
|
|
|
|
return release_font_object(¶ms);
|
|
|
|
}
|
|
|
|
|
|
|
|
struct dwrite_outline32
|
|
|
|
{
|
|
|
|
struct
|
|
|
|
{
|
|
|
|
PTR32 values;
|
|
|
|
ULONG count;
|
|
|
|
ULONG size;
|
|
|
|
} tags;
|
|
|
|
|
|
|
|
struct
|
|
|
|
{
|
|
|
|
PTR32 values;
|
|
|
|
ULONG count;
|
|
|
|
ULONG size;
|
|
|
|
} points;
|
|
|
|
};
|
|
|
|
|
|
|
|
static NTSTATUS wow64_get_glyph_outline(void *args)
|
|
|
|
{
|
|
|
|
struct
|
|
|
|
{
|
|
|
|
UINT64 object;
|
|
|
|
ULONG simulations;
|
|
|
|
ULONG glyph;
|
|
|
|
float emsize;
|
|
|
|
PTR32 outline;
|
|
|
|
} const *params32 = args;
|
|
|
|
struct dwrite_outline32 *outline32 = ULongToPtr(params32->outline);
|
|
|
|
struct dwrite_outline outline =
|
|
|
|
{
|
|
|
|
.tags.values = ULongToPtr(outline32->tags.values),
|
|
|
|
.tags.count = outline32->tags.count,
|
|
|
|
.tags.size = outline32->tags.size,
|
|
|
|
.points.values = ULongToPtr(outline32->points.values),
|
|
|
|
.points.count = outline32->points.count,
|
|
|
|
.points.size = outline32->points.size,
|
|
|
|
};
|
|
|
|
|
|
|
|
struct get_glyph_outline_params params =
|
|
|
|
{
|
|
|
|
params32->object,
|
|
|
|
params32->simulations,
|
|
|
|
params32->glyph,
|
|
|
|
params32->emsize,
|
|
|
|
&outline,
|
|
|
|
};
|
|
|
|
NTSTATUS status;
|
|
|
|
|
|
|
|
status = get_glyph_outline(¶ms);
|
|
|
|
outline32->points.count = outline.points.count;
|
|
|
|
outline32->tags.count = outline.tags.count;
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
static NTSTATUS wow64_get_glyph_count(void *args)
|
|
|
|
{
|
|
|
|
struct
|
|
|
|
{
|
|
|
|
UINT64 object;
|
|
|
|
PTR32 count;
|
|
|
|
} const *params32 = args;
|
|
|
|
struct get_glyph_count_params params =
|
|
|
|
{
|
|
|
|
params32->object,
|
|
|
|
ULongToPtr(params32->count),
|
|
|
|
};
|
|
|
|
|
|
|
|
return get_glyph_count(¶ms);
|
|
|
|
}
|
|
|
|
|
|
|
|
static NTSTATUS wow64_get_glyph_advance(void *args)
|
|
|
|
{
|
|
|
|
struct
|
|
|
|
{
|
|
|
|
UINT64 object;
|
|
|
|
ULONG glyph;
|
|
|
|
ULONG mode;
|
|
|
|
float emsize;
|
|
|
|
PTR32 advance;
|
|
|
|
PTR32 has_contours;
|
|
|
|
} const *params32 = args;
|
|
|
|
struct get_glyph_advance_params params =
|
|
|
|
{
|
|
|
|
params32->object,
|
|
|
|
params32->glyph,
|
|
|
|
params32->mode,
|
|
|
|
params32->emsize,
|
|
|
|
ULongToPtr(params32->advance),
|
|
|
|
ULongToPtr(params32->has_contours),
|
|
|
|
};
|
|
|
|
|
|
|
|
return get_glyph_advance(¶ms);
|
|
|
|
}
|
|
|
|
|
|
|
|
static NTSTATUS wow64_get_glyph_bbox(void *args)
|
|
|
|
{
|
|
|
|
struct
|
|
|
|
{
|
|
|
|
UINT64 object;
|
|
|
|
ULONG simulations;
|
|
|
|
ULONG glyph;
|
|
|
|
float emsize;
|
2023-03-22 09:14:24 +00:00
|
|
|
MATRIX_2X2 m;
|
2021-12-08 11:10:43 +00:00
|
|
|
PTR32 bbox;
|
|
|
|
} const *params32 = args;
|
|
|
|
struct get_glyph_bbox_params params =
|
|
|
|
{
|
|
|
|
params32->object,
|
|
|
|
params32->simulations,
|
|
|
|
params32->glyph,
|
|
|
|
params32->emsize,
|
|
|
|
params32->m,
|
|
|
|
ULongToPtr(params32->bbox),
|
|
|
|
};
|
|
|
|
|
|
|
|
return get_glyph_bbox(¶ms);
|
|
|
|
}
|
|
|
|
|
|
|
|
static NTSTATUS wow64_get_glyph_bitmap(void *args)
|
|
|
|
{
|
|
|
|
struct
|
|
|
|
{
|
|
|
|
UINT64 object;
|
|
|
|
ULONG simulations;
|
|
|
|
ULONG glyph;
|
|
|
|
ULONG mode;
|
|
|
|
float emsize;
|
2023-03-22 09:14:24 +00:00
|
|
|
MATRIX_2X2 m;
|
2021-12-08 11:10:43 +00:00
|
|
|
RECT bbox;
|
|
|
|
int pitch;
|
|
|
|
PTR32 bitmap;
|
|
|
|
PTR32 is_1bpp;
|
|
|
|
} const *params32 = args;
|
|
|
|
struct get_glyph_bitmap_params params =
|
|
|
|
{
|
|
|
|
params32->object,
|
|
|
|
params32->simulations,
|
|
|
|
params32->glyph,
|
|
|
|
params32->mode,
|
|
|
|
params32->emsize,
|
|
|
|
params32->m,
|
|
|
|
params32->bbox,
|
|
|
|
params32->pitch,
|
|
|
|
ULongToPtr(params32->bitmap),
|
|
|
|
ULongToPtr(params32->is_1bpp),
|
|
|
|
};
|
|
|
|
|
|
|
|
return get_glyph_bitmap(¶ms);
|
|
|
|
}
|
|
|
|
|
|
|
|
static NTSTATUS wow64_get_design_glyph_metrics(void *args)
|
|
|
|
{
|
|
|
|
struct
|
|
|
|
{
|
|
|
|
UINT64 object;
|
|
|
|
ULONG simulations;
|
|
|
|
ULONG glyph;
|
|
|
|
ULONG upem;
|
|
|
|
ULONG ascent;
|
|
|
|
PTR32 metrics;
|
|
|
|
} const *params32 = args;
|
|
|
|
struct get_design_glyph_metrics_params params =
|
|
|
|
{
|
|
|
|
params32->object,
|
|
|
|
params32->simulations,
|
|
|
|
params32->glyph,
|
|
|
|
params32->upem,
|
|
|
|
params32->ascent,
|
|
|
|
ULongToPtr(params32->metrics),
|
|
|
|
};
|
|
|
|
|
|
|
|
return get_design_glyph_metrics(¶ms);
|
|
|
|
};
|
|
|
|
|
|
|
|
const unixlib_entry_t __wine_unix_call_wow64_funcs[] =
|
|
|
|
{
|
|
|
|
process_attach,
|
|
|
|
process_detach,
|
|
|
|
wow64_create_font_object,
|
|
|
|
wow64_release_font_object,
|
|
|
|
wow64_get_glyph_outline,
|
|
|
|
wow64_get_glyph_count,
|
|
|
|
wow64_get_glyph_advance,
|
|
|
|
wow64_get_glyph_bbox,
|
|
|
|
wow64_get_glyph_bitmap,
|
|
|
|
wow64_get_design_glyph_metrics,
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* _WIN64 */
|