2014-11-21 09:48:23 +01:00
|
|
|
/*
|
|
|
|
* FreeType integration
|
|
|
|
*
|
2017-03-15 20:35:32 +01:00
|
|
|
* Copyright 2014-2017 Nikolay Sivov for CodeWeavers
|
2014-11-21 09:48:23 +01: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 13:06:18 +02:00
|
|
|
#if 0
|
|
|
|
#pragma makedep unix
|
|
|
|
#endif
|
2014-12-08 11:24:39 +01:00
|
|
|
|
2014-11-21 09:48:23 +01:00
|
|
|
#include "config.h"
|
|
|
|
#include "wine/port.h"
|
|
|
|
|
|
|
|
#ifdef HAVE_FT2BUILD_H
|
|
|
|
#include <ft2build.h>
|
2014-12-08 11:24:39 +01:00
|
|
|
#include FT_CACHE_H
|
2014-11-21 09:48:23 +01:00
|
|
|
#include FT_FREETYPE_H
|
2014-12-15 07:39:26 +01:00
|
|
|
#include FT_OUTLINE_H
|
2015-08-06 17:02:43 +02:00
|
|
|
#include FT_TRUETYPE_TABLES_H
|
2014-11-21 09:48:23 +01:00
|
|
|
#endif /* HAVE_FT2BUILD_H */
|
|
|
|
|
2021-03-29 09:48:51 +02:00
|
|
|
#include "ntstatus.h"
|
|
|
|
#define WIN32_NO_STATUS
|
2014-11-21 09:48:23 +01:00
|
|
|
#include "windef.h"
|
|
|
|
#include "wine/debug.h"
|
|
|
|
|
|
|
|
#include "dwrite_private.h"
|
|
|
|
|
|
|
|
#ifdef HAVE_FREETYPE
|
|
|
|
|
2020-12-23 20:15:15 +01:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(dwrite);
|
|
|
|
|
2021-03-29 09:48:55 +02:00
|
|
|
static RTL_CRITICAL_SECTION freetype_cs;
|
|
|
|
static RTL_CRITICAL_SECTION_DEBUG critsect_debug =
|
2014-12-08 11:24:39 +01:00
|
|
|
{
|
|
|
|
0, 0, &freetype_cs,
|
|
|
|
{ &critsect_debug.ProcessLocksList, &critsect_debug.ProcessLocksList },
|
|
|
|
0, 0, { (DWORD_PTR)(__FILE__ ": freetype_cs") }
|
|
|
|
};
|
2021-03-29 09:48:55 +02:00
|
|
|
static RTL_CRITICAL_SECTION freetype_cs = { &critsect_debug, -1, 0, 0, 0, 0 };
|
2014-12-08 11:24:39 +01:00
|
|
|
|
2014-11-21 09:48:23 +01:00
|
|
|
static void *ft_handle = NULL;
|
|
|
|
static FT_Library library = 0;
|
2014-12-08 11:24:39 +01:00
|
|
|
static FTC_Manager cache_manager = 0;
|
2015-07-29 10:59:02 +02:00
|
|
|
static FTC_ImageCache image_cache = 0;
|
2014-11-21 09:48:23 +01:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
FT_Int major;
|
|
|
|
FT_Int minor;
|
|
|
|
FT_Int patch;
|
|
|
|
} FT_Version_t;
|
|
|
|
|
2021-03-29 09:48:51 +02:00
|
|
|
static const struct font_callback_funcs *callback_funcs;
|
|
|
|
|
2014-11-21 09:48:23 +01:00
|
|
|
#define MAKE_FUNCPTR(f) static typeof(f) * p##f = NULL
|
2014-12-08 11:24:39 +01:00
|
|
|
MAKE_FUNCPTR(FT_Done_FreeType);
|
2015-11-02 14:38:43 +01:00
|
|
|
MAKE_FUNCPTR(FT_Done_Glyph);
|
2015-08-06 17:02:43 +02:00
|
|
|
MAKE_FUNCPTR(FT_Get_First_Char);
|
2015-03-13 21:19:18 +01:00
|
|
|
MAKE_FUNCPTR(FT_Get_Kerning);
|
2015-08-06 17:02:43 +02:00
|
|
|
MAKE_FUNCPTR(FT_Get_Sfnt_Table);
|
2015-11-02 14:38:43 +01:00
|
|
|
MAKE_FUNCPTR(FT_Glyph_Copy);
|
2015-07-29 10:59:02 +02:00
|
|
|
MAKE_FUNCPTR(FT_Glyph_Get_CBox);
|
2015-11-02 14:38:43 +01:00
|
|
|
MAKE_FUNCPTR(FT_Glyph_Transform);
|
2014-11-21 09:48:23 +01:00
|
|
|
MAKE_FUNCPTR(FT_Init_FreeType);
|
|
|
|
MAKE_FUNCPTR(FT_Library_Version);
|
2014-12-08 11:24:39 +01:00
|
|
|
MAKE_FUNCPTR(FT_Load_Glyph);
|
2017-03-13 18:44:09 +01:00
|
|
|
MAKE_FUNCPTR(FT_Matrix_Multiply);
|
2021-03-29 09:48:52 +02:00
|
|
|
MAKE_FUNCPTR(FT_MulDiv);
|
2014-11-21 09:48:23 +01:00
|
|
|
MAKE_FUNCPTR(FT_New_Memory_Face);
|
2015-08-02 22:47:24 +02:00
|
|
|
MAKE_FUNCPTR(FT_Outline_Copy);
|
2016-01-18 22:47:09 +01:00
|
|
|
MAKE_FUNCPTR(FT_Outline_Decompose);
|
2015-08-02 22:47:24 +02:00
|
|
|
MAKE_FUNCPTR(FT_Outline_Done);
|
2017-03-15 20:35:32 +01:00
|
|
|
MAKE_FUNCPTR(FT_Outline_Embolden);
|
2015-07-31 00:30:08 +02:00
|
|
|
MAKE_FUNCPTR(FT_Outline_Get_Bitmap);
|
2015-08-02 22:47:24 +02:00
|
|
|
MAKE_FUNCPTR(FT_Outline_New);
|
2014-12-15 07:39:26 +01:00
|
|
|
MAKE_FUNCPTR(FT_Outline_Transform);
|
2015-07-31 00:30:08 +02:00
|
|
|
MAKE_FUNCPTR(FT_Outline_Translate);
|
2015-07-29 10:59:02 +02:00
|
|
|
MAKE_FUNCPTR(FTC_ImageCache_Lookup);
|
|
|
|
MAKE_FUNCPTR(FTC_ImageCache_New);
|
2014-12-08 11:24:39 +01:00
|
|
|
MAKE_FUNCPTR(FTC_Manager_New);
|
|
|
|
MAKE_FUNCPTR(FTC_Manager_Done);
|
2014-12-09 07:58:14 +01:00
|
|
|
MAKE_FUNCPTR(FTC_Manager_LookupFace);
|
2014-12-08 11:24:39 +01:00
|
|
|
MAKE_FUNCPTR(FTC_Manager_LookupSize);
|
|
|
|
MAKE_FUNCPTR(FTC_Manager_RemoveFaceID);
|
2014-11-21 09:48:23 +01:00
|
|
|
#undef MAKE_FUNCPTR
|
2017-03-15 20:35:32 +01:00
|
|
|
static FT_Error (*pFT_Outline_EmboldenXY)(FT_Outline *, FT_Pos, FT_Pos);
|
2014-11-21 09:48:23 +01:00
|
|
|
|
2017-01-18 21:02:41 +01:00
|
|
|
static void face_finalizer(void *object)
|
|
|
|
{
|
|
|
|
FT_Face face = object;
|
2021-03-29 09:48:51 +02:00
|
|
|
callback_funcs->release_font_data((struct font_data_context *)face->generic.data);
|
2017-01-18 21:02:41 +01:00
|
|
|
}
|
|
|
|
|
2014-12-08 11:24:39 +01:00
|
|
|
static FT_Error face_requester(FTC_FaceID face_id, FT_Library library, FT_Pointer request_data, FT_Face *face)
|
2014-11-21 09:48:23 +01:00
|
|
|
{
|
2021-03-29 09:48:51 +02:00
|
|
|
struct font_data_context *context;
|
2014-12-08 11:24:39 +01:00
|
|
|
const void *data_ptr;
|
|
|
|
FT_Error fterror;
|
|
|
|
UINT64 data_size;
|
2021-03-29 09:48:51 +02:00
|
|
|
UINT32 index;
|
2014-12-08 11:24:39 +01:00
|
|
|
|
|
|
|
*face = NULL;
|
|
|
|
|
2021-03-29 09:48:51 +02:00
|
|
|
if (!face_id)
|
|
|
|
{
|
2016-05-18 09:11:39 +02:00
|
|
|
WARN("NULL fontface requested.\n");
|
|
|
|
return FT_Err_Ok;
|
|
|
|
}
|
|
|
|
|
2021-03-29 09:48:51 +02:00
|
|
|
if (callback_funcs->get_font_data(face_id, &data_ptr, &data_size, &index, &context))
|
2014-12-08 11:24:39 +01:00
|
|
|
return FT_Err_Ok;
|
|
|
|
|
|
|
|
fterror = pFT_New_Memory_Face(library, data_ptr, data_size, index, face);
|
2021-03-29 09:48:51 +02:00
|
|
|
if (fterror == FT_Err_Ok)
|
|
|
|
{
|
|
|
|
(*face)->generic.data = context;
|
2017-01-18 21:02:41 +01:00
|
|
|
(*face)->generic.finalizer = face_finalizer;
|
|
|
|
}
|
|
|
|
else
|
2021-03-29 09:48:51 +02:00
|
|
|
callback_funcs->release_font_data(context);
|
2014-12-08 11:24:39 +01:00
|
|
|
|
|
|
|
return fterror;
|
|
|
|
}
|
2014-11-21 09:48:23 +01:00
|
|
|
|
2021-03-29 09:48:51 +02:00
|
|
|
static BOOL init_freetype(void)
|
2014-11-21 09:48:23 +01:00
|
|
|
{
|
|
|
|
FT_Version_t FT_Version;
|
|
|
|
|
2020-04-06 11:45:32 +02:00
|
|
|
ft_handle = dlopen(SONAME_LIBFREETYPE, RTLD_NOW);
|
2014-11-21 09:48:23 +01:00
|
|
|
if (!ft_handle) {
|
|
|
|
WINE_MESSAGE("Wine cannot find the FreeType font library.\n");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2020-04-06 11:45:32 +02: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;}
|
2014-12-08 11:24:39 +01:00
|
|
|
LOAD_FUNCPTR(FT_Done_FreeType)
|
2015-11-02 14:38:43 +01:00
|
|
|
LOAD_FUNCPTR(FT_Done_Glyph)
|
2015-08-06 17:02:43 +02:00
|
|
|
LOAD_FUNCPTR(FT_Get_First_Char)
|
2015-03-13 21:19:18 +01:00
|
|
|
LOAD_FUNCPTR(FT_Get_Kerning)
|
2015-08-06 17:02:43 +02:00
|
|
|
LOAD_FUNCPTR(FT_Get_Sfnt_Table)
|
2015-11-02 14:38:43 +01:00
|
|
|
LOAD_FUNCPTR(FT_Glyph_Copy)
|
2015-07-29 10:59:02 +02:00
|
|
|
LOAD_FUNCPTR(FT_Glyph_Get_CBox)
|
2015-11-02 14:38:43 +01:00
|
|
|
LOAD_FUNCPTR(FT_Glyph_Transform)
|
2014-11-21 09:48:23 +01:00
|
|
|
LOAD_FUNCPTR(FT_Init_FreeType)
|
|
|
|
LOAD_FUNCPTR(FT_Library_Version)
|
2014-12-08 11:24:39 +01:00
|
|
|
LOAD_FUNCPTR(FT_Load_Glyph)
|
2017-03-13 18:44:09 +01:00
|
|
|
LOAD_FUNCPTR(FT_Matrix_Multiply)
|
2021-03-29 09:48:52 +02:00
|
|
|
LOAD_FUNCPTR(FT_MulDiv)
|
2014-11-21 09:48:23 +01:00
|
|
|
LOAD_FUNCPTR(FT_New_Memory_Face)
|
2015-08-02 22:47:24 +02:00
|
|
|
LOAD_FUNCPTR(FT_Outline_Copy)
|
2016-01-18 22:47:09 +01:00
|
|
|
LOAD_FUNCPTR(FT_Outline_Decompose)
|
2015-08-02 22:47:24 +02:00
|
|
|
LOAD_FUNCPTR(FT_Outline_Done)
|
2017-03-15 20:35:32 +01:00
|
|
|
LOAD_FUNCPTR(FT_Outline_Embolden)
|
2015-07-31 00:30:08 +02:00
|
|
|
LOAD_FUNCPTR(FT_Outline_Get_Bitmap)
|
2015-08-02 22:47:24 +02:00
|
|
|
LOAD_FUNCPTR(FT_Outline_New)
|
2014-12-15 07:39:26 +01:00
|
|
|
LOAD_FUNCPTR(FT_Outline_Transform)
|
2015-07-31 00:30:08 +02:00
|
|
|
LOAD_FUNCPTR(FT_Outline_Translate)
|
2015-07-29 10:59:02 +02:00
|
|
|
LOAD_FUNCPTR(FTC_ImageCache_Lookup)
|
|
|
|
LOAD_FUNCPTR(FTC_ImageCache_New)
|
2014-12-08 11:24:39 +01:00
|
|
|
LOAD_FUNCPTR(FTC_Manager_New)
|
|
|
|
LOAD_FUNCPTR(FTC_Manager_Done)
|
2014-12-09 07:58:14 +01:00
|
|
|
LOAD_FUNCPTR(FTC_Manager_LookupFace)
|
2014-12-08 11:24:39 +01:00
|
|
|
LOAD_FUNCPTR(FTC_Manager_LookupSize)
|
|
|
|
LOAD_FUNCPTR(FTC_Manager_RemoveFaceID)
|
2014-11-21 09:48:23 +01:00
|
|
|
#undef LOAD_FUNCPTR
|
2020-04-06 11:45:32 +02:00
|
|
|
pFT_Outline_EmboldenXY = dlsym(ft_handle, "FT_Outline_EmboldenXY");
|
2014-11-21 09:48:23 +01:00
|
|
|
|
|
|
|
if (pFT_Init_FreeType(&library) != 0) {
|
|
|
|
ERR("Can't init FreeType library\n");
|
2020-04-06 11:45:32 +02:00
|
|
|
dlclose(ft_handle);
|
2014-11-21 09:48:23 +01:00
|
|
|
ft_handle = NULL;
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
pFT_Library_Version(library, &FT_Version.major, &FT_Version.minor, &FT_Version.patch);
|
|
|
|
|
2014-12-08 11:24:39 +01:00
|
|
|
/* init cache manager */
|
2015-02-20 11:47:30 +01:00
|
|
|
if (pFTC_Manager_New(library, 0, 0, 0, &face_requester, NULL, &cache_manager) != 0 ||
|
2015-07-29 10:59:02 +02:00
|
|
|
pFTC_ImageCache_New(cache_manager, &image_cache) != 0) {
|
2015-02-20 11:47:30 +01:00
|
|
|
|
2014-12-08 11:24:39 +01:00
|
|
|
ERR("Failed to init FreeType cache\n");
|
2015-02-20 11:47:30 +01:00
|
|
|
pFTC_Manager_Done(cache_manager);
|
2014-12-08 11:24:39 +01:00
|
|
|
pFT_Done_FreeType(library);
|
2020-04-06 11:45:32 +02:00
|
|
|
dlclose(ft_handle);
|
2014-12-08 11:24:39 +01:00
|
|
|
ft_handle = NULL;
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2014-11-21 09:48:23 +01:00
|
|
|
TRACE("FreeType version is %d.%d.%d\n", FT_Version.major, FT_Version.minor, FT_Version.patch);
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
sym_not_found:
|
|
|
|
WINE_MESSAGE("Wine cannot find certain functions that it needs from FreeType library.\n");
|
2020-04-06 11:45:32 +02:00
|
|
|
dlclose(ft_handle);
|
2014-11-21 09:48:23 +01:00
|
|
|
ft_handle = NULL;
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2021-03-29 09:48:53 +02:00
|
|
|
static void CDECL freetype_notify_release(void *key)
|
2014-12-08 11:24:39 +01:00
|
|
|
{
|
2021-03-29 09:48:55 +02:00
|
|
|
RtlEnterCriticalSection(&freetype_cs);
|
2021-03-29 09:48:53 +02:00
|
|
|
pFTC_Manager_RemoveFaceID(cache_manager, key);
|
2021-03-29 09:48:55 +02:00
|
|
|
RtlLeaveCriticalSection(&freetype_cs);
|
2014-12-08 11:24:39 +01:00
|
|
|
}
|
2014-11-21 09:48:23 +01:00
|
|
|
|
2021-03-29 09:48:53 +02:00
|
|
|
static void CDECL freetype_get_design_glyph_metrics(void *key, UINT16 upem, UINT16 ascent,
|
|
|
|
unsigned int simulations, UINT16 glyph, DWRITE_GLYPH_METRICS *ret)
|
2014-12-08 11:24:39 +01:00
|
|
|
{
|
|
|
|
FTC_ScalerRec scaler;
|
|
|
|
FT_Size size;
|
|
|
|
|
2021-03-29 09:48:53 +02:00
|
|
|
scaler.face_id = key;
|
|
|
|
scaler.width = upem;
|
|
|
|
scaler.height = upem;
|
2014-12-08 11:24:39 +01:00
|
|
|
scaler.pixel = 1;
|
|
|
|
scaler.x_res = 0;
|
|
|
|
scaler.y_res = 0;
|
|
|
|
|
2021-03-29 09:48:55 +02:00
|
|
|
RtlEnterCriticalSection(&freetype_cs);
|
2014-12-08 11:24:39 +01:00
|
|
|
if (pFTC_Manager_LookupSize(cache_manager, &scaler, &size) == 0) {
|
|
|
|
if (pFT_Load_Glyph(size->face, glyph, FT_LOAD_NO_SCALE) == 0) {
|
|
|
|
FT_Glyph_Metrics *metrics = &size->face->glyph->metrics;
|
|
|
|
|
|
|
|
ret->leftSideBearing = metrics->horiBearingX;
|
|
|
|
ret->advanceWidth = metrics->horiAdvance;
|
|
|
|
ret->rightSideBearing = metrics->horiAdvance - metrics->horiBearingX - metrics->width;
|
2019-05-13 13:21:47 +02:00
|
|
|
|
2014-12-08 11:24:39 +01:00
|
|
|
ret->advanceHeight = metrics->vertAdvance;
|
2021-03-29 09:48:53 +02:00
|
|
|
ret->verticalOriginY = ascent;
|
|
|
|
ret->topSideBearing = ascent - metrics->horiBearingY;
|
2019-05-13 13:21:47 +02:00
|
|
|
ret->bottomSideBearing = metrics->vertAdvance - metrics->height - ret->topSideBearing;
|
2017-03-15 20:35:32 +01:00
|
|
|
|
|
|
|
/* Adjust in case of bold simulation, glyphs without contours are ignored. */
|
2021-03-29 09:48:53 +02:00
|
|
|
if (simulations & DWRITE_FONT_SIMULATIONS_BOLD &&
|
2019-05-13 13:21:47 +02:00
|
|
|
size->face->glyph->format == FT_GLYPH_FORMAT_OUTLINE && size->face->glyph->outline.n_contours)
|
|
|
|
{
|
2017-03-15 20:35:32 +01:00
|
|
|
if (ret->advanceWidth)
|
2021-03-29 09:48:53 +02:00
|
|
|
ret->advanceWidth += (upem + 49) / 50;
|
2017-03-15 20:35:32 +01:00
|
|
|
}
|
2014-12-08 11:24:39 +01:00
|
|
|
}
|
2014-11-21 09:48:23 +01:00
|
|
|
}
|
2021-03-29 09:48:55 +02:00
|
|
|
RtlLeaveCriticalSection(&freetype_cs);
|
2014-11-21 09:48:23 +01:00
|
|
|
}
|
|
|
|
|
2021-03-22 08:59:16 +01:00
|
|
|
struct decompose_context
|
|
|
|
{
|
|
|
|
struct dwrite_outline *outline;
|
2016-01-18 22:47:09 +01:00
|
|
|
BOOL figure_started;
|
|
|
|
BOOL move_to; /* last call was 'move_to' */
|
|
|
|
FT_Vector origin; /* 'pen' position from last call */
|
|
|
|
};
|
|
|
|
|
2021-03-22 08:59:16 +01:00
|
|
|
static inline void ft_vector_to_d2d_point(const FT_Vector *v, D2D1_POINT_2F *p)
|
2014-12-15 07:39:26 +01:00
|
|
|
{
|
2021-03-22 08:59:16 +01:00
|
|
|
p->x = v->x / 64.0f;
|
|
|
|
p->y = v->y / 64.0f;
|
2014-12-15 07:39:26 +01:00
|
|
|
}
|
|
|
|
|
2021-03-30 13:06:15 +02:00
|
|
|
static int dwrite_outline_push_tag(struct dwrite_outline *outline, unsigned char tag)
|
|
|
|
{
|
|
|
|
if (!dwrite_array_reserve((void **)&outline->tags.values, &outline->tags.size, outline->tags.count + 1,
|
|
|
|
sizeof(*outline->tags.values)))
|
|
|
|
{
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
if (!dwrite_array_reserve((void **)&outline->points.values, &outline->points.size, outline->points.count + count,
|
|
|
|
sizeof(*outline->points.values)))
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
memcpy(&outline->points.values[outline->points.count], points, sizeof(*points) * count);
|
|
|
|
outline->points.count += count;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-03-22 08:59:16 +01:00
|
|
|
static int decompose_beginfigure(struct decompose_context *ctxt)
|
2017-08-25 07:29:46 +02:00
|
|
|
{
|
|
|
|
D2D1_POINT_2F point;
|
2021-03-22 08:59:16 +01:00
|
|
|
int ret;
|
2017-08-25 07:29:46 +02:00
|
|
|
|
|
|
|
if (!ctxt->move_to)
|
2021-03-22 08:59:16 +01:00
|
|
|
return 0;
|
2017-08-25 07:29:46 +02:00
|
|
|
|
2021-03-22 08:59:16 +01: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 07:29:46 +02:00
|
|
|
|
|
|
|
ctxt->figure_started = TRUE;
|
|
|
|
ctxt->move_to = FALSE;
|
2021-03-22 08:59:16 +01:00
|
|
|
|
|
|
|
return 0;
|
2017-08-25 07:29:46 +02:00
|
|
|
}
|
|
|
|
|
2016-01-18 22:47:09 +01:00
|
|
|
static int decompose_move_to(const FT_Vector *to, void *user)
|
2014-12-15 07:39:26 +01:00
|
|
|
{
|
2021-03-22 08:59:16 +01:00
|
|
|
struct decompose_context *ctxt = (struct decompose_context *)user;
|
|
|
|
int ret;
|
2016-01-18 22:47:09 +01:00
|
|
|
|
2021-03-22 08:59:16 +01:00
|
|
|
if (ctxt->figure_started)
|
|
|
|
{
|
|
|
|
if ((ret = dwrite_outline_push_tag(ctxt->outline, OUTLINE_END_FIGURE))) return ret;
|
2017-08-25 07:29:46 +02:00
|
|
|
ctxt->figure_started = FALSE;
|
2016-01-18 22:47:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
ctxt->move_to = TRUE;
|
|
|
|
ctxt->origin = *to;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int decompose_line_to(const FT_Vector *to, void *user)
|
|
|
|
{
|
2021-03-22 08:59:16 +01:00
|
|
|
struct decompose_context *ctxt = (struct decompose_context *)user;
|
2017-08-25 07:29:46 +02:00
|
|
|
D2D1_POINT_2F point;
|
2021-03-22 08:59:16 +01:00
|
|
|
int ret;
|
2017-08-25 07:29:46 +02: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 08:59:16 +01:00
|
|
|
ft_vector_to_d2d_point(to, &point);
|
2017-08-25 07:29:46 +02:00
|
|
|
|
2021-03-22 08:59:16 +01: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 07:29:46 +02:00
|
|
|
|
2016-01-18 22:47:09 +01:00
|
|
|
ctxt->origin = *to;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int decompose_conic_to(const FT_Vector *control, const FT_Vector *to, void *user)
|
|
|
|
{
|
2021-03-22 08:59:16 +01:00
|
|
|
struct decompose_context *ctxt = (struct decompose_context *)user;
|
2016-01-18 22:47:09 +01:00
|
|
|
D2D1_POINT_2F points[3];
|
|
|
|
FT_Vector cubic[3];
|
2021-03-22 08:59:16 +01:00
|
|
|
int ret;
|
2016-01-18 22:47:09 +01:00
|
|
|
|
2021-03-22 08:59:16 +01:00
|
|
|
if ((ret = decompose_beginfigure(ctxt)))
|
|
|
|
return ret;
|
2017-08-25 07:29:46 +02:00
|
|
|
|
2016-01-18 22:47:09 +01:00
|
|
|
/* convert from quadratic to cubic */
|
|
|
|
|
2015-06-09 23:13:34 +02: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 22:47:09 +01: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 08:59:16 +01: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 22:47:09 +01:00
|
|
|
ctxt->origin = *to;
|
|
|
|
return 0;
|
|
|
|
}
|
2014-12-15 07:39:26 +01:00
|
|
|
|
2016-01-18 22:47:09 +01:00
|
|
|
static int decompose_cubic_to(const FT_Vector *control1, const FT_Vector *control2,
|
|
|
|
const FT_Vector *to, void *user)
|
|
|
|
{
|
2021-03-22 08:59:16 +01:00
|
|
|
struct decompose_context *ctxt = (struct decompose_context *)user;
|
2016-01-18 22:47:09 +01:00
|
|
|
D2D1_POINT_2F points[3];
|
2021-03-22 08:59:16 +01:00
|
|
|
int ret;
|
2014-12-15 07:39:26 +01:00
|
|
|
|
2021-03-22 08:59:16 +01:00
|
|
|
if ((ret = decompose_beginfigure(ctxt)))
|
|
|
|
return ret;
|
2017-08-25 07:29:46 +02:00
|
|
|
|
2021-03-22 08:59:16 +01: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 22:47:09 +01:00
|
|
|
ctxt->origin = *to;
|
2021-03-22 08:59:16 +01: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 22:47:09 +01:00
|
|
|
return 0;
|
|
|
|
}
|
2015-06-09 23:13:34 +02:00
|
|
|
|
2021-03-22 08:59:16 +01:00
|
|
|
static int decompose_outline(FT_Outline *ft_outline, struct dwrite_outline *outline)
|
2016-01-18 22:47:09 +01:00
|
|
|
{
|
2021-03-22 08:59:16 +01:00
|
|
|
static const FT_Outline_Funcs decompose_funcs =
|
|
|
|
{
|
2016-01-18 22:47:09 +01:00
|
|
|
decompose_move_to,
|
|
|
|
decompose_line_to,
|
|
|
|
decompose_conic_to,
|
|
|
|
decompose_cubic_to,
|
|
|
|
0,
|
|
|
|
0
|
|
|
|
};
|
2021-03-22 08:59:16 +01:00
|
|
|
struct decompose_context context = { 0 };
|
|
|
|
int ret;
|
2014-12-15 07:39:26 +01:00
|
|
|
|
2021-03-22 08:59:16 +01:00
|
|
|
context.outline = outline;
|
2015-07-12 22:37:05 +02:00
|
|
|
|
2021-03-22 08:59:16 +01:00
|
|
|
ret = pFT_Outline_Decompose(ft_outline, &decompose_funcs, &context);
|
2016-01-18 22:47:09 +01:00
|
|
|
|
2021-03-22 08:59:16 +01:00
|
|
|
if (!ret && context.figure_started)
|
|
|
|
ret = dwrite_outline_push_tag(outline, OUTLINE_END_FIGURE);
|
|
|
|
|
|
|
|
return ret;
|
2014-12-15 07:39:26 +01:00
|
|
|
}
|
|
|
|
|
2017-03-15 20:35:32 +01:00
|
|
|
static void embolden_glyph_outline(FT_Outline *outline, FLOAT emsize)
|
|
|
|
{
|
|
|
|
FT_Pos strength;
|
|
|
|
|
2021-03-29 09:48:52 +02:00
|
|
|
strength = pFT_MulDiv(emsize, 1 << 6, 24);
|
2017-03-15 20:35:32 +01: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-03-29 09:48:54 +02:00
|
|
|
static int CDECL freetype_get_glyph_outline(void *key, float emSize, unsigned int simulations,
|
|
|
|
UINT16 glyph, struct dwrite_outline *outline)
|
2014-12-15 07:39:26 +01:00
|
|
|
{
|
|
|
|
FTC_ScalerRec scaler;
|
|
|
|
FT_Size size;
|
2021-03-22 08:59:16 +01:00
|
|
|
int ret;
|
2014-12-15 07:39:26 +01:00
|
|
|
|
2021-03-29 09:48:54 +02:00
|
|
|
scaler.face_id = key;
|
2014-12-15 07:39:26 +01:00
|
|
|
scaler.width = emSize;
|
|
|
|
scaler.height = emSize;
|
|
|
|
scaler.pixel = 1;
|
|
|
|
scaler.x_res = 0;
|
|
|
|
scaler.y_res = 0;
|
|
|
|
|
2021-03-29 09:48:55 +02:00
|
|
|
RtlEnterCriticalSection(&freetype_cs);
|
2021-03-22 08:59:16 +01:00
|
|
|
if (!(ret = pFTC_Manager_LookupSize(cache_manager, &scaler, &size)))
|
2021-02-22 19:29:36 +01:00
|
|
|
{
|
2021-03-15 08:36:51 +01:00
|
|
|
if (pFT_Load_Glyph(size->face, glyph, FT_LOAD_NO_BITMAP) == 0)
|
2019-02-08 09:59:14 +01:00
|
|
|
{
|
2021-03-22 08:59:16 +01:00
|
|
|
FT_Outline *ft_outline = &size->face->glyph->outline;
|
2021-03-15 08:36:51 +01:00
|
|
|
FT_Matrix m;
|
|
|
|
|
|
|
|
if (simulations & DWRITE_FONT_SIMULATIONS_BOLD)
|
2021-03-22 08:59:16 +01:00
|
|
|
embolden_glyph_outline(ft_outline, emSize);
|
2021-03-15 08:36:51 +01:00
|
|
|
|
|
|
|
m.xx = 1 << 16;
|
|
|
|
m.xy = simulations & DWRITE_FONT_SIMULATIONS_OBLIQUE ? (1 << 16) / 3 : 0;
|
|
|
|
m.yx = 0;
|
|
|
|
m.yy = -(1 << 16); /* flip Y axis */
|
|
|
|
|
2021-03-22 08:59:16 +01:00
|
|
|
pFT_Outline_Transform(ft_outline, &m);
|
2021-03-15 08:36:51 +01:00
|
|
|
|
2021-03-22 08:59:16 +01:00
|
|
|
ret = decompose_outline(ft_outline, outline);
|
2016-01-18 22:47:09 +01:00
|
|
|
}
|
2014-12-15 07:39:26 +01:00
|
|
|
}
|
2021-03-29 09:48:55 +02:00
|
|
|
RtlLeaveCriticalSection(&freetype_cs);
|
2014-12-15 07:39:26 +01:00
|
|
|
|
2021-03-22 08:59:16 +01:00
|
|
|
return ret;
|
2014-12-15 07:39:26 +01:00
|
|
|
}
|
|
|
|
|
2021-03-29 09:48:53 +02:00
|
|
|
static UINT16 CDECL freetype_get_glyph_count(void *key)
|
2015-02-05 13:54:05 +01:00
|
|
|
{
|
|
|
|
UINT16 count = 0;
|
|
|
|
FT_Face face;
|
|
|
|
|
2021-03-29 09:48:55 +02:00
|
|
|
RtlEnterCriticalSection(&freetype_cs);
|
2021-03-29 09:48:53 +02:00
|
|
|
if (pFTC_Manager_LookupFace(cache_manager, key, &face) == 0)
|
2015-02-05 13:54:05 +01:00
|
|
|
count = face->num_glyphs;
|
2021-03-29 09:48:55 +02:00
|
|
|
RtlLeaveCriticalSection(&freetype_cs);
|
2015-02-05 13:54:05 +01:00
|
|
|
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
2015-11-02 14:38:43 +01:00
|
|
|
static inline void ft_matrix_from_dwrite_matrix(const DWRITE_MATRIX *m, FT_Matrix *ft_matrix)
|
|
|
|
{
|
|
|
|
ft_matrix->xx = m->m11 * 0x10000;
|
|
|
|
ft_matrix->xy = -m->m21 * 0x10000;
|
|
|
|
ft_matrix->yx = -m->m12 * 0x10000;
|
|
|
|
ft_matrix->yy = m->m22 * 0x10000;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Should be used only while holding 'freetype_cs' */
|
2021-03-29 09:48:53 +02:00
|
|
|
static BOOL is_face_scalable(void *key)
|
2015-11-02 14:38:43 +01:00
|
|
|
{
|
|
|
|
FT_Face face;
|
2021-03-29 09:48:53 +02:00
|
|
|
if (pFTC_Manager_LookupFace(cache_manager, key, &face) == 0)
|
2015-11-02 14:38:43 +01:00
|
|
|
return FT_IS_SCALABLE(face);
|
|
|
|
else
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2017-03-13 18:44:09 +01:00
|
|
|
static BOOL get_glyph_transform(struct dwrite_glyphbitmap *bitmap, FT_Matrix *ret)
|
|
|
|
{
|
|
|
|
FT_Matrix m;
|
|
|
|
|
|
|
|
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. */
|
2021-03-29 09:48:53 +02:00
|
|
|
if (!is_face_scalable(bitmap->key) || (!bitmap->m && bitmap->simulations == 0))
|
2017-03-13 18:44:09 +01:00
|
|
|
return FALSE;
|
|
|
|
|
2017-07-11 15:57:40 +02:00
|
|
|
if (bitmap->simulations & DWRITE_FONT_SIMULATIONS_OBLIQUE) {
|
2017-03-13 18:44:09 +01:00
|
|
|
m.xx = 1 << 16;
|
|
|
|
m.xy = (1 << 16) / 3;
|
|
|
|
m.yx = 0;
|
|
|
|
m.yy = 1 << 16;
|
|
|
|
pFT_Matrix_Multiply(&m, ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (bitmap->m) {
|
|
|
|
ft_matrix_from_dwrite_matrix(bitmap->m, &m);
|
|
|
|
pFT_Matrix_Multiply(&m, ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2021-03-29 09:48:53 +02:00
|
|
|
static void CDECL freetype_get_glyph_bbox(struct dwrite_glyphbitmap *bitmap)
|
2015-07-29 10:59:02 +02:00
|
|
|
{
|
|
|
|
FTC_ImageTypeRec imagetype;
|
|
|
|
FT_BBox bbox = { 0 };
|
2017-03-13 18:44:09 +01:00
|
|
|
BOOL needs_transform;
|
2015-07-29 10:59:02 +02:00
|
|
|
FT_Glyph glyph;
|
2017-03-13 18:44:09 +01:00
|
|
|
FT_Matrix m;
|
2015-07-29 10:59:02 +02:00
|
|
|
|
2021-03-29 09:48:55 +02:00
|
|
|
RtlEnterCriticalSection(&freetype_cs);
|
2015-11-02 14:38:43 +01:00
|
|
|
|
2017-03-13 18:44:09 +01:00
|
|
|
needs_transform = get_glyph_transform(bitmap, &m);
|
2015-11-02 14:38:43 +01:00
|
|
|
|
2021-03-29 09:48:53 +02:00
|
|
|
imagetype.face_id = bitmap->key;
|
2015-07-29 10:59:02 +02:00
|
|
|
imagetype.width = 0;
|
2015-08-27 07:38:50 +02:00
|
|
|
imagetype.height = bitmap->emsize;
|
2017-03-13 18:44:09 +01:00
|
|
|
imagetype.flags = needs_transform ? FT_LOAD_NO_BITMAP : FT_LOAD_DEFAULT;
|
2015-11-02 14:38:43 +01:00
|
|
|
|
2019-01-25 12:56:40 +01:00
|
|
|
if (pFTC_ImageCache_Lookup(image_cache, &imagetype, bitmap->glyph, &glyph, NULL) == 0) {
|
2017-03-13 18:44:09 +01:00
|
|
|
if (needs_transform) {
|
2015-11-02 14:38:43 +01:00
|
|
|
FT_Glyph glyph_copy;
|
|
|
|
|
|
|
|
if (pFT_Glyph_Copy(glyph, &glyph_copy) == 0) {
|
2017-07-11 15:57:40 +02:00
|
|
|
if (bitmap->simulations & DWRITE_FONT_SIMULATIONS_BOLD)
|
2017-03-15 20:35:32 +01:00
|
|
|
embolden_glyph(glyph_copy, bitmap->emsize);
|
|
|
|
|
2017-04-04 12:13:19 +02:00
|
|
|
/* Includes oblique and user transform. */
|
|
|
|
pFT_Glyph_Transform(glyph_copy, &m, NULL);
|
2015-11-02 14:38:43 +01:00
|
|
|
pFT_Glyph_Get_CBox(glyph_copy, FT_GLYPH_BBOX_PIXELS, &bbox);
|
|
|
|
pFT_Done_Glyph(glyph_copy);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
pFT_Glyph_Get_CBox(glyph, FT_GLYPH_BBOX_PIXELS, &bbox);
|
|
|
|
}
|
2015-07-29 10:59:02 +02:00
|
|
|
|
2021-03-29 09:48:55 +02:00
|
|
|
RtlLeaveCriticalSection(&freetype_cs);
|
2015-07-29 10:59:02 +02:00
|
|
|
|
|
|
|
/* flip Y axis */
|
2016-05-03 11:32:33 +02:00
|
|
|
SetRect(&bitmap->bbox, bbox.xMin, -bbox.yMax, bbox.xMax, -bbox.yMin);
|
2015-07-29 10:59:02 +02:00
|
|
|
}
|
|
|
|
|
2015-08-27 07:39:45 +02:00
|
|
|
static BOOL freetype_get_aliased_glyph_bitmap(struct dwrite_glyphbitmap *bitmap, FT_Glyph glyph)
|
2015-07-31 00:30:08 +02:00
|
|
|
{
|
2015-08-27 07:38:50 +02:00
|
|
|
const RECT *bbox = &bitmap->bbox;
|
2015-08-27 07:39:45 +02:00
|
|
|
int width = bbox->right - bbox->left;
|
|
|
|
int height = bbox->bottom - bbox->top;
|
|
|
|
|
|
|
|
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;
|
|
|
|
ft_bitmap.pitch = bitmap->pitch;
|
|
|
|
ft_bitmap.pixel_mode = FT_PIXEL_MODE_MONO;
|
|
|
|
ft_bitmap.buffer = bitmap->buf;
|
|
|
|
|
|
|
|
/* 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;
|
|
|
|
BYTE *src = ft_bitmap->buffer, *dst = bitmap->buf;
|
|
|
|
int w = min(bitmap->pitch, (ft_bitmap->width + 7) >> 3);
|
|
|
|
int h = min(height, ft_bitmap->rows);
|
|
|
|
|
|
|
|
while (h--) {
|
|
|
|
memcpy(dst, src, w);
|
|
|
|
src += ft_bitmap->pitch;
|
|
|
|
dst += bitmap->pitch;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
FIXME("format %x not handled\n", glyph->format);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL freetype_get_aa_glyph_bitmap(struct dwrite_glyphbitmap *bitmap, FT_Glyph glyph)
|
|
|
|
{
|
|
|
|
const RECT *bbox = &bitmap->bbox;
|
|
|
|
int width = bbox->right - bbox->left;
|
|
|
|
int height = bbox->bottom - bbox->top;
|
|
|
|
BOOL ret = FALSE;
|
|
|
|
|
|
|
|
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;
|
|
|
|
ft_bitmap.pitch = bitmap->pitch;
|
|
|
|
ft_bitmap.pixel_mode = FT_PIXEL_MODE_GRAY;
|
|
|
|
ft_bitmap.buffer = bitmap->buf;
|
|
|
|
|
|
|
|
/* 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;
|
|
|
|
BYTE *src = ft_bitmap->buffer, *dst = bitmap->buf;
|
|
|
|
int w = min(bitmap->pitch, (ft_bitmap->width + 7) >> 3);
|
|
|
|
int h = min(height, ft_bitmap->rows);
|
|
|
|
|
|
|
|
while (h--) {
|
|
|
|
memcpy(dst, src, w);
|
|
|
|
src += ft_bitmap->pitch;
|
|
|
|
dst += bitmap->pitch;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
FIXME("format %x not handled\n", glyph->format);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2021-03-29 09:48:53 +02:00
|
|
|
static BOOL CDECL freetype_get_glyph_bitmap(struct dwrite_glyphbitmap *bitmap)
|
2015-08-27 07:39:45 +02:00
|
|
|
{
|
2015-07-31 00:30:08 +02:00
|
|
|
FTC_ImageTypeRec imagetype;
|
2017-03-13 18:44:09 +01:00
|
|
|
BOOL needs_transform;
|
2015-08-27 07:39:45 +02:00
|
|
|
BOOL ret = FALSE;
|
2015-07-31 00:30:08 +02:00
|
|
|
FT_Glyph glyph;
|
2017-03-13 18:44:09 +01:00
|
|
|
FT_Matrix m;
|
2015-07-31 00:30:08 +02:00
|
|
|
|
2021-03-29 09:48:55 +02:00
|
|
|
RtlEnterCriticalSection(&freetype_cs);
|
2015-11-02 14:38:43 +01:00
|
|
|
|
2017-03-13 18:44:09 +01:00
|
|
|
needs_transform = get_glyph_transform(bitmap, &m);
|
2015-11-02 14:38:43 +01:00
|
|
|
|
2021-03-29 09:48:53 +02:00
|
|
|
imagetype.face_id = bitmap->key;
|
2015-07-31 00:30:08 +02:00
|
|
|
imagetype.width = 0;
|
2015-08-27 07:38:50 +02:00
|
|
|
imagetype.height = bitmap->emsize;
|
2017-03-13 18:44:09 +01:00
|
|
|
imagetype.flags = needs_transform ? FT_LOAD_NO_BITMAP : FT_LOAD_DEFAULT;
|
2015-07-31 00:30:08 +02:00
|
|
|
|
2019-01-25 12:56:40 +01:00
|
|
|
if (pFTC_ImageCache_Lookup(image_cache, &imagetype, bitmap->glyph, &glyph, NULL) == 0) {
|
2015-11-02 14:38:43 +01:00
|
|
|
FT_Glyph glyph_copy;
|
|
|
|
|
2017-03-13 18:44:09 +01:00
|
|
|
if (needs_transform) {
|
2015-11-02 14:38:43 +01:00
|
|
|
if (pFT_Glyph_Copy(glyph, &glyph_copy) == 0) {
|
2017-07-11 15:57:40 +02:00
|
|
|
if (bitmap->simulations & DWRITE_FONT_SIMULATIONS_BOLD)
|
2017-03-15 20:35:32 +01:00
|
|
|
embolden_glyph(glyph_copy, bitmap->emsize);
|
|
|
|
|
2017-04-04 12:13:19 +02:00
|
|
|
/* Includes oblique and user transform. */
|
|
|
|
pFT_Glyph_Transform(glyph_copy, &m, NULL);
|
2015-11-02 14:38:43 +01:00
|
|
|
glyph = glyph_copy;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
glyph_copy = NULL;
|
|
|
|
|
2017-09-05 12:35:29 +02:00
|
|
|
if (bitmap->aliased)
|
2015-08-27 07:39:45 +02:00
|
|
|
ret = freetype_get_aliased_glyph_bitmap(bitmap, glyph);
|
2017-09-05 12:35:29 +02:00
|
|
|
else
|
|
|
|
ret = freetype_get_aa_glyph_bitmap(bitmap, glyph);
|
2015-11-02 14:38:43 +01:00
|
|
|
|
|
|
|
if (glyph_copy)
|
|
|
|
pFT_Done_Glyph(glyph_copy);
|
2015-07-31 00:30:08 +02:00
|
|
|
}
|
2015-11-02 14:38:43 +01:00
|
|
|
|
2021-03-29 09:48:55 +02:00
|
|
|
RtlLeaveCriticalSection(&freetype_cs);
|
2015-08-27 07:39:45 +02:00
|
|
|
|
|
|
|
return ret;
|
2015-07-31 00:30:08 +02:00
|
|
|
}
|
|
|
|
|
2021-03-29 09:48:53 +02:00
|
|
|
static INT32 CDECL freetype_get_glyph_advance(void *key, float emSize, UINT16 index,
|
|
|
|
DWRITE_MEASURING_MODE mode, BOOL *has_contours)
|
2015-08-24 09:43:19 +02:00
|
|
|
{
|
|
|
|
FTC_ImageTypeRec imagetype;
|
|
|
|
FT_Glyph glyph;
|
|
|
|
INT32 advance;
|
|
|
|
|
2021-03-29 09:48:53 +02:00
|
|
|
imagetype.face_id = key;
|
2015-08-24 09:43:19 +02:00
|
|
|
imagetype.width = 0;
|
|
|
|
imagetype.height = emSize;
|
|
|
|
imagetype.flags = FT_LOAD_DEFAULT;
|
|
|
|
if (mode == DWRITE_MEASURING_MODE_NATURAL)
|
|
|
|
imagetype.flags |= FT_LOAD_NO_HINTING;
|
|
|
|
|
2021-03-29 09:48:55 +02:00
|
|
|
RtlEnterCriticalSection(&freetype_cs);
|
2017-03-15 20:35:32 +01:00
|
|
|
if (pFTC_ImageCache_Lookup(image_cache, &imagetype, index, &glyph, NULL) == 0) {
|
|
|
|
*has_contours = glyph->format == FT_GLYPH_FORMAT_OUTLINE && ((FT_OutlineGlyph)glyph)->outline.n_contours;
|
2015-08-24 09:43:19 +02:00
|
|
|
advance = glyph->advance.x >> 16;
|
2017-03-15 20:35:32 +01:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
*has_contours = FALSE;
|
2015-08-24 09:43:19 +02:00
|
|
|
advance = 0;
|
2017-03-15 20:35:32 +01:00
|
|
|
}
|
2021-03-29 09:48:55 +02:00
|
|
|
RtlLeaveCriticalSection(&freetype_cs);
|
2015-08-24 09:43:19 +02:00
|
|
|
|
|
|
|
return advance;
|
|
|
|
}
|
|
|
|
|
2021-03-29 09:48:53 +02:00
|
|
|
const static struct font_backend_funcs freetype_funcs =
|
|
|
|
{
|
|
|
|
freetype_notify_release,
|
|
|
|
freetype_get_glyph_outline,
|
|
|
|
freetype_get_glyph_count,
|
|
|
|
freetype_get_glyph_advance,
|
|
|
|
freetype_get_glyph_bbox,
|
|
|
|
freetype_get_glyph_bitmap,
|
|
|
|
freetype_get_design_glyph_metrics,
|
|
|
|
};
|
|
|
|
|
2021-03-29 09:48:51 +02:00
|
|
|
static NTSTATUS init_freetype_lib(HMODULE module, DWORD reason, const void *ptr_in, void *ptr_out)
|
2014-11-21 09:48:23 +01:00
|
|
|
{
|
2021-03-29 09:48:51 +02:00
|
|
|
callback_funcs = ptr_in;
|
|
|
|
if (!init_freetype()) return STATUS_DLL_NOT_FOUND;
|
2021-03-29 09:48:53 +02:00
|
|
|
*(const struct font_backend_funcs **)ptr_out = &freetype_funcs;
|
2021-03-29 09:48:51 +02:00
|
|
|
return STATUS_SUCCESS;
|
2014-11-21 09:48:23 +01:00
|
|
|
}
|
|
|
|
|
2021-03-29 09:48:51 +02:00
|
|
|
static NTSTATUS release_freetype_lib(void)
|
2014-12-08 11:24:39 +01:00
|
|
|
{
|
2021-03-29 09:48:51 +02:00
|
|
|
pFTC_Manager_Done(cache_manager);
|
|
|
|
pFT_Done_FreeType(library);
|
|
|
|
return STATUS_SUCCESS;
|
2014-12-08 11:24:39 +01:00
|
|
|
}
|
|
|
|
|
2021-03-29 09:48:51 +02:00
|
|
|
#else /* HAVE_FREETYPE */
|
|
|
|
|
2021-03-29 09:48:53 +02:00
|
|
|
static void CDECL null_notify_release(void *key)
|
2014-11-21 09:48:23 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2021-03-29 09:48:54 +02:00
|
|
|
static int CDECL null_get_glyph_outline(void *key, float emSize, unsigned int simulations,
|
|
|
|
UINT16 glyph, struct dwrite_outline *outline)
|
2014-11-21 09:48:23 +01:00
|
|
|
{
|
2021-03-29 09:48:53 +02:00
|
|
|
return 1;
|
2014-11-21 09:48:23 +01:00
|
|
|
}
|
|
|
|
|
2021-03-29 09:48:53 +02:00
|
|
|
static UINT16 CDECL null_get_glyph_count(void *key)
|
2014-12-15 07:39:26 +01:00
|
|
|
{
|
2021-03-29 09:48:53 +02:00
|
|
|
return 0;
|
2014-12-15 07:39:26 +01:00
|
|
|
}
|
|
|
|
|
2021-03-29 09:48:53 +02:00
|
|
|
static INT32 CDECL null_get_glyph_advance(void *key, float emSize, UINT16 index, DWRITE_MEASURING_MODE mode,
|
|
|
|
BOOL *has_contours)
|
2015-02-05 13:54:05 +01:00
|
|
|
{
|
2021-03-29 09:48:53 +02:00
|
|
|
*has_contours = FALSE;
|
2015-02-05 13:54:05 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-03-29 09:48:53 +02:00
|
|
|
static void CDECL null_get_glyph_bbox(struct dwrite_glyphbitmap *bitmap)
|
2015-07-29 10:59:02 +02:00
|
|
|
{
|
2017-04-12 13:20:29 +02:00
|
|
|
SetRectEmpty(&bitmap->bbox);
|
2015-07-29 10:59:02 +02:00
|
|
|
}
|
|
|
|
|
2021-03-29 09:48:53 +02:00
|
|
|
static BOOL CDECL null_get_glyph_bitmap(struct dwrite_glyphbitmap *bitmap)
|
2015-07-31 00:30:08 +02:00
|
|
|
{
|
2015-08-27 07:39:45 +02:00
|
|
|
return FALSE;
|
2015-07-31 00:30:08 +02:00
|
|
|
}
|
|
|
|
|
2021-03-29 09:48:53 +02:00
|
|
|
static void CDECL null_get_design_glyph_metrics(void *key, UINT16 upem, UINT16 ascent, unsigned int simulations,
|
|
|
|
UINT16 glyph, DWRITE_GLYPH_METRICS *metrics)
|
2015-08-24 09:43:19 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2021-03-29 09:48:53 +02:00
|
|
|
const static struct font_backend_funcs null_funcs =
|
|
|
|
{
|
|
|
|
null_notify_release,
|
|
|
|
null_get_glyph_outline,
|
|
|
|
null_get_glyph_count,
|
|
|
|
null_get_glyph_advance,
|
|
|
|
null_get_glyph_bbox,
|
|
|
|
null_get_glyph_bitmap,
|
|
|
|
null_get_design_glyph_metrics,
|
|
|
|
};
|
|
|
|
|
2021-03-29 09:48:51 +02:00
|
|
|
static NTSTATUS init_freetype_lib(HMODULE module, DWORD reason, const void *ptr_in, void *ptr_out)
|
|
|
|
{
|
2021-03-29 09:48:53 +02:00
|
|
|
*(const struct font_backend_funcs **)ptr_out = &null_funcs;
|
2021-03-29 09:48:51 +02:00
|
|
|
return STATUS_DLL_NOT_FOUND;
|
|
|
|
}
|
|
|
|
|
|
|
|
static NTSTATUS release_freetype_lib(void)
|
|
|
|
{
|
|
|
|
return STATUS_DLL_NOT_FOUND;
|
|
|
|
}
|
|
|
|
|
2014-11-21 09:48:23 +01:00
|
|
|
#endif /* HAVE_FREETYPE */
|
2021-03-29 09:48:51 +02:00
|
|
|
|
2021-03-30 13:06:18 +02:00
|
|
|
NTSTATUS CDECL __wine_init_unix_lib(HMODULE module, DWORD reason, const void *ptr_in, void *ptr_out)
|
2021-03-29 09:48:51 +02:00
|
|
|
{
|
|
|
|
if (reason == DLL_PROCESS_ATTACH)
|
|
|
|
return init_freetype_lib(module, reason, ptr_in, ptr_out);
|
|
|
|
else if (reason == DLL_PROCESS_DETACH)
|
|
|
|
return release_freetype_lib();
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|