2014-11-21 09:48:23 +01:00
|
|
|
/*
|
|
|
|
* FreeType integration
|
|
|
|
*
|
2015-07-29 10:59:02 +02:00
|
|
|
* Copyright 2014-2015 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
|
|
|
|
*/
|
|
|
|
|
2014-12-08 11:24:39 +01:00
|
|
|
#define COBJMACROS
|
|
|
|
|
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 */
|
|
|
|
|
|
|
|
#include "windef.h"
|
|
|
|
#include "wine/library.h"
|
|
|
|
#include "wine/debug.h"
|
|
|
|
|
|
|
|
#include "dwrite_private.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(dwrite);
|
|
|
|
|
|
|
|
#ifdef HAVE_FREETYPE
|
|
|
|
|
2014-12-08 11:24:39 +01:00
|
|
|
static CRITICAL_SECTION freetype_cs;
|
|
|
|
static CRITICAL_SECTION_DEBUG critsect_debug =
|
|
|
|
{
|
|
|
|
0, 0, &freetype_cs,
|
|
|
|
{ &critsect_debug.ProcessLocksList, &critsect_debug.ProcessLocksList },
|
|
|
|
0, 0, { (DWORD_PTR)(__FILE__ ": freetype_cs") }
|
|
|
|
};
|
|
|
|
static CRITICAL_SECTION freetype_cs = { &critsect_debug, -1, 0, 0, 0, 0 };
|
|
|
|
|
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-02-20 11:47:30 +01:00
|
|
|
static FTC_CMapCache cmap_cache = 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;
|
|
|
|
|
|
|
|
#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);
|
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);
|
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-02-20 11:47:30 +01:00
|
|
|
MAKE_FUNCPTR(FTC_CMapCache_Lookup);
|
|
|
|
MAKE_FUNCPTR(FTC_CMapCache_New);
|
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
|
|
|
|
|
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
|
|
|
{
|
2014-12-08 11:24:39 +01:00
|
|
|
IDWriteFontFace *fontface = (IDWriteFontFace*)face_id;
|
|
|
|
IDWriteFontFileStream *stream;
|
|
|
|
IDWriteFontFile *file;
|
|
|
|
const void *data_ptr;
|
|
|
|
UINT32 index, count;
|
|
|
|
FT_Error fterror;
|
|
|
|
UINT64 data_size;
|
|
|
|
void *context;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
*face = NULL;
|
|
|
|
|
2016-05-18 09:11:39 +02:00
|
|
|
if (!fontface) {
|
|
|
|
WARN("NULL fontface requested.\n");
|
|
|
|
return FT_Err_Ok;
|
|
|
|
}
|
|
|
|
|
2014-12-08 11:24:39 +01:00
|
|
|
count = 1;
|
|
|
|
hr = IDWriteFontFace_GetFiles(fontface, &count, &file);
|
|
|
|
if (FAILED(hr))
|
|
|
|
return FT_Err_Ok;
|
|
|
|
|
|
|
|
hr = get_filestream_from_file(file, &stream);
|
|
|
|
IDWriteFontFile_Release(file);
|
|
|
|
if (FAILED(hr))
|
|
|
|
return FT_Err_Ok;
|
|
|
|
|
|
|
|
hr = IDWriteFontFileStream_GetFileSize(stream, &data_size);
|
|
|
|
if (FAILED(hr)) {
|
|
|
|
fterror = FT_Err_Invalid_Stream_Read;
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
hr = IDWriteFontFileStream_ReadFileFragment(stream, &data_ptr, 0, data_size, &context);
|
|
|
|
if (FAILED(hr)) {
|
|
|
|
fterror = FT_Err_Invalid_Stream_Read;
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
index = IDWriteFontFace_GetIndex(fontface);
|
|
|
|
fterror = pFT_New_Memory_Face(library, data_ptr, data_size, index, face);
|
|
|
|
IDWriteFontFileStream_ReleaseFileFragment(stream, context);
|
|
|
|
|
|
|
|
fail:
|
|
|
|
IDWriteFontFileStream_Release(stream);
|
|
|
|
|
|
|
|
return fterror;
|
|
|
|
}
|
2014-11-21 09:48:23 +01:00
|
|
|
|
|
|
|
BOOL init_freetype(void)
|
|
|
|
{
|
|
|
|
FT_Version_t FT_Version;
|
|
|
|
|
|
|
|
ft_handle = wine_dlopen(SONAME_LIBFREETYPE, RTLD_NOW, NULL, 0);
|
|
|
|
if (!ft_handle) {
|
|
|
|
WINE_MESSAGE("Wine cannot find the FreeType font library.\n");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define LOAD_FUNCPTR(f) if((p##f = wine_dlsym(ft_handle, #f, NULL, 0)) == NULL){WARN("Can't find symbol %s\n", #f); goto sym_not_found;}
|
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)
|
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)
|
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-02-20 11:47:30 +01:00
|
|
|
LOAD_FUNCPTR(FTC_CMapCache_Lookup)
|
|
|
|
LOAD_FUNCPTR(FTC_CMapCache_New)
|
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
|
|
|
|
|
|
|
|
if (pFT_Init_FreeType(&library) != 0) {
|
|
|
|
ERR("Can't init FreeType library\n");
|
|
|
|
wine_dlclose(ft_handle, NULL, 0);
|
|
|
|
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_CMapCache_New(cache_manager, &cmap_cache) != 0 ||
|
|
|
|
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);
|
|
|
|
wine_dlclose(ft_handle, NULL, 0);
|
|
|
|
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");
|
|
|
|
wine_dlclose(ft_handle, NULL, 0);
|
|
|
|
ft_handle = NULL;
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2014-12-08 11:24:39 +01:00
|
|
|
void release_freetype(void)
|
2014-11-21 09:48:23 +01:00
|
|
|
{
|
2014-12-08 11:24:39 +01:00
|
|
|
pFTC_Manager_Done(cache_manager);
|
|
|
|
pFT_Done_FreeType(library);
|
|
|
|
}
|
2014-11-21 09:48:23 +01:00
|
|
|
|
2016-03-03 06:16:25 +01:00
|
|
|
void freetype_notify_cacheremove(IDWriteFontFace3 *fontface)
|
2014-12-08 11:24:39 +01:00
|
|
|
{
|
|
|
|
EnterCriticalSection(&freetype_cs);
|
|
|
|
pFTC_Manager_RemoveFaceID(cache_manager, fontface);
|
|
|
|
LeaveCriticalSection(&freetype_cs);
|
|
|
|
}
|
2014-11-21 09:48:23 +01:00
|
|
|
|
2016-03-03 06:16:25 +01:00
|
|
|
HRESULT freetype_get_design_glyph_metrics(IDWriteFontFace3 *fontface, UINT16 unitsperEm, UINT16 glyph, DWRITE_GLYPH_METRICS *ret)
|
2014-12-08 11:24:39 +01:00
|
|
|
{
|
|
|
|
FTC_ScalerRec scaler;
|
|
|
|
FT_Size size;
|
|
|
|
|
|
|
|
scaler.face_id = fontface;
|
|
|
|
scaler.width = unitsperEm;
|
|
|
|
scaler.height = unitsperEm;
|
|
|
|
scaler.pixel = 1;
|
|
|
|
scaler.x_res = 0;
|
|
|
|
scaler.y_res = 0;
|
|
|
|
|
|
|
|
EnterCriticalSection(&freetype_cs);
|
|
|
|
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;
|
|
|
|
ret->topSideBearing = metrics->vertBearingY;
|
|
|
|
ret->advanceHeight = metrics->vertAdvance;
|
|
|
|
ret->bottomSideBearing = metrics->vertAdvance - metrics->vertBearingY - metrics->height;
|
|
|
|
ret->verticalOriginY = metrics->height + metrics->vertBearingY;
|
|
|
|
}
|
2014-11-21 09:48:23 +01:00
|
|
|
}
|
2014-12-08 11:24:39 +01:00
|
|
|
LeaveCriticalSection(&freetype_cs);
|
2014-11-21 09:48:23 +01:00
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2016-03-03 06:16:25 +01:00
|
|
|
BOOL freetype_is_monospaced(IDWriteFontFace3 *fontface)
|
2014-12-09 07:58:14 +01:00
|
|
|
{
|
|
|
|
BOOL is_monospaced = FALSE;
|
|
|
|
FT_Face face;
|
|
|
|
|
|
|
|
EnterCriticalSection(&freetype_cs);
|
|
|
|
if (pFTC_Manager_LookupFace(cache_manager, fontface, &face) == 0)
|
2016-01-21 19:58:40 +01:00
|
|
|
is_monospaced = !!FT_IS_FIXED_WIDTH(face);
|
2014-12-09 07:58:14 +01:00
|
|
|
LeaveCriticalSection(&freetype_cs);
|
|
|
|
|
|
|
|
return is_monospaced;
|
|
|
|
}
|
|
|
|
|
2016-01-18 22:47:09 +01:00
|
|
|
struct decompose_context {
|
|
|
|
IDWriteGeometrySink *sink;
|
|
|
|
FLOAT xoffset;
|
|
|
|
FLOAT yoffset;
|
|
|
|
BOOL figure_started;
|
|
|
|
BOOL figure_closed;
|
|
|
|
BOOL move_to; /* last call was 'move_to' */
|
|
|
|
FT_Vector origin; /* 'pen' position from last call */
|
|
|
|
};
|
|
|
|
|
|
|
|
static inline void ft_vector_to_d2d_point(const FT_Vector *v, FLOAT xoffset, FLOAT yoffset, D2D1_POINT_2F *p)
|
2014-12-15 07:39:26 +01:00
|
|
|
{
|
2016-01-18 22:47:09 +01:00
|
|
|
p->x = (v->x / 64.0f) + xoffset;
|
|
|
|
p->y = (v->y / 64.0f) + yoffset;
|
2014-12-15 07:39:26 +01: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
|
|
|
{
|
2016-01-18 22:47:09 +01:00
|
|
|
struct decompose_context *ctxt = (struct decompose_context*)user;
|
|
|
|
D2D1_POINT_2F point;
|
|
|
|
|
|
|
|
if (ctxt->figure_started) {
|
|
|
|
ID2D1SimplifiedGeometrySink_EndFigure(ctxt->sink, D2D1_FIGURE_END_CLOSED);
|
|
|
|
ctxt->figure_closed = TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
ctxt->figure_closed = FALSE;
|
|
|
|
ctxt->figure_started = TRUE;
|
|
|
|
|
|
|
|
ft_vector_to_d2d_point(to, ctxt->xoffset, ctxt->yoffset, &point);
|
|
|
|
ID2D1SimplifiedGeometrySink_BeginFigure(ctxt->sink, point, D2D1_FIGURE_BEGIN_FILLED);
|
|
|
|
ctxt->move_to = TRUE;
|
|
|
|
ctxt->origin = *to;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int decompose_line_to(const FT_Vector *to, void *user)
|
|
|
|
{
|
|
|
|
struct decompose_context *ctxt = (struct decompose_context*)user;
|
|
|
|
/* special case for empty contours, in a way freetype returns them */
|
|
|
|
if (ctxt->move_to && !memcmp(to, &ctxt->origin, sizeof(*to))) {
|
|
|
|
ID2D1SimplifiedGeometrySink_EndFigure(ctxt->sink, D2D1_FIGURE_END_CLOSED);
|
|
|
|
ctxt->figure_closed = TRUE;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
D2D1_POINT_2F point;
|
|
|
|
ft_vector_to_d2d_point(to, ctxt->xoffset, ctxt->yoffset, &point);
|
|
|
|
ID2D1SimplifiedGeometrySink_AddLines(ctxt->sink, &point, 1);
|
|
|
|
ctxt->figure_closed = FALSE;
|
|
|
|
}
|
|
|
|
ctxt->move_to = FALSE;
|
|
|
|
ctxt->origin = *to;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int decompose_conic_to(const FT_Vector *control, const FT_Vector *to, void *user)
|
|
|
|
{
|
|
|
|
struct decompose_context *ctxt = (struct decompose_context*)user;
|
|
|
|
D2D1_POINT_2F points[3];
|
|
|
|
FT_Vector cubic[3];
|
|
|
|
|
|
|
|
/* 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;
|
|
|
|
|
|
|
|
ft_vector_to_d2d_point(cubic, ctxt->xoffset, ctxt->yoffset, points);
|
|
|
|
ft_vector_to_d2d_point(cubic + 1, ctxt->xoffset, ctxt->yoffset, points + 1);
|
|
|
|
ft_vector_to_d2d_point(cubic + 2, ctxt->xoffset, ctxt->yoffset, points + 2);
|
|
|
|
ID2D1SimplifiedGeometrySink_AddBeziers(ctxt->sink, (D2D1_BEZIER_SEGMENT*)points, 1);
|
|
|
|
ctxt->figure_closed = FALSE;
|
|
|
|
ctxt->move_to = FALSE;
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
struct decompose_context *ctxt = (struct decompose_context*)user;
|
|
|
|
D2D1_POINT_2F points[3];
|
2014-12-15 07:39:26 +01:00
|
|
|
|
2016-01-18 22:47:09 +01:00
|
|
|
ft_vector_to_d2d_point(control1, ctxt->xoffset, ctxt->yoffset, points);
|
|
|
|
ft_vector_to_d2d_point(control2, ctxt->xoffset, ctxt->yoffset, points + 1);
|
|
|
|
ft_vector_to_d2d_point(to, ctxt->xoffset, ctxt->yoffset, points + 2);
|
|
|
|
ID2D1SimplifiedGeometrySink_AddBeziers(ctxt->sink, (D2D1_BEZIER_SEGMENT*)points, 1);
|
|
|
|
ctxt->figure_closed = FALSE;
|
|
|
|
ctxt->move_to = FALSE;
|
|
|
|
ctxt->origin = *to;
|
|
|
|
return 0;
|
|
|
|
}
|
2015-06-09 23:13:34 +02:00
|
|
|
|
2016-01-18 22:47:09 +01:00
|
|
|
static void decompose_outline(FT_Outline *outline, FLOAT xoffset, FLOAT yoffset, IDWriteGeometrySink *sink)
|
|
|
|
{
|
|
|
|
static const FT_Outline_Funcs decompose_funcs = {
|
|
|
|
decompose_move_to,
|
|
|
|
decompose_line_to,
|
|
|
|
decompose_conic_to,
|
|
|
|
decompose_cubic_to,
|
|
|
|
0,
|
|
|
|
0
|
|
|
|
};
|
|
|
|
struct decompose_context context;
|
2014-12-15 07:39:26 +01:00
|
|
|
|
2016-01-18 22:47:09 +01:00
|
|
|
context.sink = sink;
|
|
|
|
context.xoffset = xoffset;
|
|
|
|
context.yoffset = yoffset;
|
|
|
|
context.figure_started = FALSE;
|
|
|
|
context.figure_closed = FALSE;
|
|
|
|
context.move_to = FALSE;
|
|
|
|
context.origin.x = 0;
|
|
|
|
context.origin.y = 0;
|
2015-07-12 22:37:05 +02:00
|
|
|
|
2016-01-18 22:47:09 +01:00
|
|
|
pFT_Outline_Decompose(outline, &decompose_funcs, &context);
|
|
|
|
|
|
|
|
if (!context.figure_closed && outline->n_points)
|
|
|
|
ID2D1SimplifiedGeometrySink_EndFigure(sink, D2D1_FIGURE_END_CLOSED);
|
2014-12-15 07:39:26 +01:00
|
|
|
}
|
|
|
|
|
2016-03-03 06:16:25 +01:00
|
|
|
HRESULT freetype_get_glyphrun_outline(IDWriteFontFace3 *fontface, FLOAT emSize, UINT16 const *glyphs, FLOAT const *advances,
|
2016-01-18 22:47:09 +01:00
|
|
|
DWRITE_GLYPH_OFFSET const *offsets, UINT32 count, BOOL is_rtl, IDWriteGeometrySink *sink)
|
2014-12-15 07:39:26 +01:00
|
|
|
{
|
|
|
|
FTC_ScalerRec scaler;
|
2016-01-18 22:47:09 +01:00
|
|
|
USHORT simulations;
|
2014-12-15 07:39:26 +01:00
|
|
|
HRESULT hr = S_OK;
|
|
|
|
FT_Size size;
|
|
|
|
|
2016-01-18 22:47:09 +01:00
|
|
|
if (!count)
|
|
|
|
return S_OK;
|
|
|
|
|
|
|
|
ID2D1SimplifiedGeometrySink_SetFillMode(sink, D2D1_FILL_MODE_WINDING);
|
|
|
|
|
2016-03-03 06:16:25 +01:00
|
|
|
simulations = IDWriteFontFace3_GetSimulations(fontface);
|
2016-01-18 22:47:09 +01:00
|
|
|
|
2014-12-15 07:39:26 +01:00
|
|
|
scaler.face_id = fontface;
|
|
|
|
scaler.width = emSize;
|
|
|
|
scaler.height = emSize;
|
|
|
|
scaler.pixel = 1;
|
|
|
|
scaler.x_res = 0;
|
|
|
|
scaler.y_res = 0;
|
|
|
|
|
|
|
|
EnterCriticalSection(&freetype_cs);
|
|
|
|
if (pFTC_Manager_LookupSize(cache_manager, &scaler, &size) == 0) {
|
2016-01-18 22:47:09 +01:00
|
|
|
FLOAT advance = 0.0f;
|
|
|
|
UINT32 g;
|
|
|
|
|
|
|
|
for (g = 0; g < count; g++) {
|
|
|
|
if (pFT_Load_Glyph(size->face, glyphs[g], FT_LOAD_NO_BITMAP) == 0) {
|
|
|
|
FLOAT ft_advance = size->face->glyph->metrics.horiAdvance >> 6;
|
|
|
|
FT_Outline *outline = &size->face->glyph->outline;
|
|
|
|
FLOAT xoffset = 0.0f, yoffset = 0.0f;
|
|
|
|
FT_Matrix m;
|
|
|
|
|
|
|
|
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 */
|
|
|
|
|
|
|
|
pFT_Outline_Transform(outline, &m);
|
|
|
|
|
|
|
|
/* glyph offsets act as current glyph adjustment */
|
|
|
|
if (offsets) {
|
|
|
|
xoffset += is_rtl ? -offsets[g].advanceOffset : offsets[g].advanceOffset;
|
|
|
|
yoffset -= offsets[g].ascenderOffset;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (g == 0 && is_rtl)
|
|
|
|
advance = advances ? -advances[g] : -ft_advance;
|
|
|
|
|
|
|
|
xoffset += advance;
|
|
|
|
decompose_outline(outline, xoffset, yoffset, sink);
|
|
|
|
|
|
|
|
/* update advance to next glyph */
|
|
|
|
if (advances)
|
|
|
|
advance += is_rtl ? -advances[g] : advances[g];
|
|
|
|
else
|
|
|
|
advance += is_rtl ? -ft_advance : ft_advance;
|
|
|
|
}
|
|
|
|
}
|
2014-12-15 07:39:26 +01:00
|
|
|
}
|
2016-01-18 22:47:09 +01:00
|
|
|
else
|
|
|
|
hr = E_FAIL;
|
2014-12-15 07:39:26 +01:00
|
|
|
LeaveCriticalSection(&freetype_cs);
|
|
|
|
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2016-03-03 06:16:25 +01:00
|
|
|
UINT16 freetype_get_glyphcount(IDWriteFontFace3 *fontface)
|
2015-02-05 13:54:05 +01:00
|
|
|
{
|
|
|
|
UINT16 count = 0;
|
|
|
|
FT_Face face;
|
|
|
|
|
|
|
|
EnterCriticalSection(&freetype_cs);
|
|
|
|
if (pFTC_Manager_LookupFace(cache_manager, fontface, &face) == 0)
|
|
|
|
count = face->num_glyphs;
|
|
|
|
LeaveCriticalSection(&freetype_cs);
|
|
|
|
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
2016-03-03 06:16:25 +01:00
|
|
|
void freetype_get_glyphs(IDWriteFontFace3 *fontface, INT charmap, UINT32 const *codepoints, UINT32 count,
|
2016-02-09 15:11:20 +01:00
|
|
|
UINT16 *glyphs)
|
2015-02-20 11:47:30 +01:00
|
|
|
{
|
2016-02-09 15:11:20 +01:00
|
|
|
UINT32 i;
|
2015-02-20 11:47:30 +01:00
|
|
|
|
|
|
|
EnterCriticalSection(&freetype_cs);
|
2016-02-09 15:11:20 +01:00
|
|
|
for (i = 0; i < count; i++) {
|
|
|
|
if (charmap == -1)
|
|
|
|
glyphs[i] = pFTC_CMapCache_Lookup(cmap_cache, fontface, charmap, codepoints[i]);
|
|
|
|
else {
|
|
|
|
UINT32 codepoint = codepoints[i];
|
|
|
|
/* special handling for symbol fonts */
|
|
|
|
if (codepoint < 0x100) codepoint += 0xf000;
|
|
|
|
glyphs[i] = pFTC_CMapCache_Lookup(cmap_cache, fontface, charmap, codepoint);
|
|
|
|
if (!glyphs[i])
|
|
|
|
glyphs[i] = pFTC_CMapCache_Lookup(cmap_cache, fontface, charmap, codepoint - 0xf000);
|
|
|
|
}
|
2015-08-06 17:03:12 +02:00
|
|
|
}
|
2015-02-20 11:47:30 +01:00
|
|
|
LeaveCriticalSection(&freetype_cs);
|
|
|
|
}
|
|
|
|
|
2016-03-03 06:16:25 +01:00
|
|
|
BOOL freetype_has_kerning_pairs(IDWriteFontFace3 *fontface)
|
2015-03-13 20:42:30 +01:00
|
|
|
{
|
|
|
|
BOOL has_kerning_pairs = FALSE;
|
|
|
|
FT_Face face;
|
|
|
|
|
|
|
|
EnterCriticalSection(&freetype_cs);
|
|
|
|
if (pFTC_Manager_LookupFace(cache_manager, fontface, &face) == 0)
|
2016-01-21 19:58:40 +01:00
|
|
|
has_kerning_pairs = !!FT_HAS_KERNING(face);
|
2015-03-13 20:42:30 +01:00
|
|
|
LeaveCriticalSection(&freetype_cs);
|
|
|
|
|
|
|
|
return has_kerning_pairs;
|
|
|
|
}
|
|
|
|
|
2016-03-03 06:16:25 +01:00
|
|
|
INT32 freetype_get_kerning_pair_adjustment(IDWriteFontFace3 *fontface, UINT16 left, UINT16 right)
|
2015-03-13 21:19:18 +01:00
|
|
|
{
|
|
|
|
INT32 adjustment = 0;
|
|
|
|
FT_Face face;
|
|
|
|
|
|
|
|
EnterCriticalSection(&freetype_cs);
|
|
|
|
if (pFTC_Manager_LookupFace(cache_manager, fontface, &face) == 0) {
|
|
|
|
FT_Vector kern;
|
|
|
|
if (FT_HAS_KERNING(face)) {
|
|
|
|
pFT_Get_Kerning(face, left, right, FT_KERNING_UNSCALED, &kern);
|
|
|
|
adjustment = kern.x;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
LeaveCriticalSection(&freetype_cs);
|
|
|
|
|
|
|
|
return adjustment;
|
|
|
|
}
|
|
|
|
|
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' */
|
2016-03-03 06:16:25 +01:00
|
|
|
static BOOL is_face_scalable(IDWriteFontFace3 *fontface)
|
2015-11-02 14:38:43 +01:00
|
|
|
{
|
|
|
|
FT_Face face;
|
|
|
|
if (pFTC_Manager_LookupFace(cache_manager, fontface, &face) == 0)
|
|
|
|
return FT_IS_SCALABLE(face);
|
|
|
|
else
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2015-08-27 07:38:50 +02:00
|
|
|
void freetype_get_glyph_bbox(struct dwrite_glyphbitmap *bitmap)
|
2015-07-29 10:59:02 +02:00
|
|
|
{
|
|
|
|
FTC_ImageTypeRec imagetype;
|
|
|
|
FT_BBox bbox = { 0 };
|
|
|
|
FT_Glyph glyph;
|
|
|
|
|
2015-11-02 14:38:43 +01:00
|
|
|
EnterCriticalSection(&freetype_cs);
|
|
|
|
|
|
|
|
/* Some fonts provide mostly bitmaps and very few outlines, for example for .notdef,
|
|
|
|
disable transform if that's the case. */
|
|
|
|
if (bitmap->m) {
|
|
|
|
if (!is_face_scalable(bitmap->fontface))
|
|
|
|
bitmap->m = NULL;
|
|
|
|
}
|
|
|
|
|
2015-08-27 07:38:50 +02:00
|
|
|
imagetype.face_id = bitmap->fontface;
|
2015-07-29 10:59:02 +02:00
|
|
|
imagetype.width = 0;
|
2015-08-27 07:38:50 +02:00
|
|
|
imagetype.height = bitmap->emsize;
|
2015-11-02 14:38:43 +01:00
|
|
|
imagetype.flags = bitmap->m ? FT_LOAD_NO_BITMAP : FT_LOAD_DEFAULT;
|
|
|
|
|
|
|
|
if (pFTC_ImageCache_Lookup(image_cache, &imagetype, bitmap->index, &glyph, NULL) == 0) {
|
|
|
|
if (bitmap->m) {
|
|
|
|
FT_Glyph glyph_copy;
|
|
|
|
|
|
|
|
if (pFT_Glyph_Copy(glyph, &glyph_copy) == 0) {
|
|
|
|
FT_Matrix ft_matrix;
|
|
|
|
|
|
|
|
ft_matrix_from_dwrite_matrix(bitmap->m, &ft_matrix);
|
|
|
|
pFT_Glyph_Transform(glyph_copy, &ft_matrix, NULL);
|
|
|
|
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
|
|
|
|
|
|
|
LeaveCriticalSection(&freetype_cs);
|
|
|
|
|
|
|
|
/* 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;
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOL freetype_get_glyph_bitmap(struct dwrite_glyphbitmap *bitmap)
|
|
|
|
{
|
2015-07-31 00:30:08 +02:00
|
|
|
FTC_ImageTypeRec imagetype;
|
2015-08-27 07:39:45 +02:00
|
|
|
BOOL ret = FALSE;
|
2015-07-31 00:30:08 +02:00
|
|
|
FT_Glyph glyph;
|
|
|
|
|
2015-11-02 14:38:43 +01:00
|
|
|
EnterCriticalSection(&freetype_cs);
|
|
|
|
|
|
|
|
if (bitmap->m) {
|
|
|
|
if (!is_face_scalable(bitmap->fontface))
|
|
|
|
bitmap->m = NULL;
|
|
|
|
}
|
|
|
|
|
2015-08-27 07:38:50 +02:00
|
|
|
imagetype.face_id = bitmap->fontface;
|
2015-07-31 00:30:08 +02:00
|
|
|
imagetype.width = 0;
|
2015-08-27 07:38:50 +02:00
|
|
|
imagetype.height = bitmap->emsize;
|
2015-11-02 14:38:43 +01:00
|
|
|
imagetype.flags = bitmap->m ? FT_LOAD_NO_BITMAP : FT_LOAD_DEFAULT;
|
2015-07-31 00:30:08 +02:00
|
|
|
|
2015-08-27 07:38:50 +02:00
|
|
|
if (pFTC_ImageCache_Lookup(image_cache, &imagetype, bitmap->index, &glyph, NULL) == 0) {
|
2015-11-02 14:38:43 +01:00
|
|
|
FT_Glyph glyph_copy;
|
|
|
|
|
|
|
|
if (bitmap->m) {
|
|
|
|
if (pFT_Glyph_Copy(glyph, &glyph_copy) == 0) {
|
|
|
|
FT_Matrix ft_matrix;
|
|
|
|
|
|
|
|
ft_matrix_from_dwrite_matrix(bitmap->m, &ft_matrix);
|
|
|
|
pFT_Glyph_Transform(glyph_copy, &ft_matrix, NULL);
|
|
|
|
glyph = glyph_copy;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
glyph_copy = NULL;
|
|
|
|
|
2015-08-27 07:39:45 +02:00
|
|
|
if (bitmap->type == DWRITE_TEXTURE_CLEARTYPE_3x1)
|
|
|
|
ret = freetype_get_aa_glyph_bitmap(bitmap, glyph);
|
2015-07-31 00:30:08 +02:00
|
|
|
else
|
2015-08-27 07:39:45 +02:00
|
|
|
ret = freetype_get_aliased_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
|
|
|
|
2015-07-31 00:30:08 +02:00
|
|
|
LeaveCriticalSection(&freetype_cs);
|
2015-08-27 07:39:45 +02:00
|
|
|
|
|
|
|
return ret;
|
2015-07-31 00:30:08 +02:00
|
|
|
}
|
|
|
|
|
2016-03-03 06:16:25 +01:00
|
|
|
INT freetype_get_charmap_index(IDWriteFontFace3 *fontface, BOOL *is_symbol)
|
2015-08-06 17:02:43 +02:00
|
|
|
{
|
|
|
|
INT charmap_index = -1;
|
|
|
|
FT_Face face;
|
|
|
|
|
|
|
|
*is_symbol = FALSE;
|
|
|
|
|
|
|
|
EnterCriticalSection(&freetype_cs);
|
|
|
|
if (pFTC_Manager_LookupFace(cache_manager, fontface, &face) == 0) {
|
|
|
|
TT_OS2 *os2 = pFT_Get_Sfnt_Table(face, ft_sfnt_os2);
|
|
|
|
FT_Int i;
|
|
|
|
|
|
|
|
if (os2) {
|
|
|
|
FT_UInt dummy;
|
|
|
|
if (os2->version == 0)
|
|
|
|
*is_symbol = pFT_Get_First_Char(face, &dummy) >= 0x100;
|
|
|
|
else
|
2015-10-12 22:06:32 +02:00
|
|
|
*is_symbol = !!(os2->ulCodePageRange1 & FS_SYMBOL);
|
2015-08-06 17:02:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < face->num_charmaps; i++)
|
|
|
|
if (face->charmaps[i]->encoding == FT_ENCODING_MS_SYMBOL) {
|
|
|
|
*is_symbol = TRUE;
|
|
|
|
charmap_index = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
LeaveCriticalSection(&freetype_cs);
|
|
|
|
|
|
|
|
return charmap_index;
|
|
|
|
}
|
|
|
|
|
2016-03-03 06:16:25 +01:00
|
|
|
INT32 freetype_get_glyph_advance(IDWriteFontFace3 *fontface, FLOAT emSize, UINT16 index, DWRITE_MEASURING_MODE mode)
|
2015-08-24 09:43:19 +02:00
|
|
|
{
|
|
|
|
FTC_ImageTypeRec imagetype;
|
|
|
|
FT_Glyph glyph;
|
|
|
|
INT32 advance;
|
|
|
|
|
|
|
|
imagetype.face_id = fontface;
|
|
|
|
imagetype.width = 0;
|
|
|
|
imagetype.height = emSize;
|
|
|
|
imagetype.flags = FT_LOAD_DEFAULT;
|
|
|
|
if (mode == DWRITE_MEASURING_MODE_NATURAL)
|
|
|
|
imagetype.flags |= FT_LOAD_NO_HINTING;
|
|
|
|
|
|
|
|
EnterCriticalSection(&freetype_cs);
|
|
|
|
if (pFTC_ImageCache_Lookup(image_cache, &imagetype, index, &glyph, NULL) == 0)
|
|
|
|
advance = glyph->advance.x >> 16;
|
|
|
|
else
|
|
|
|
advance = 0;
|
|
|
|
LeaveCriticalSection(&freetype_cs);
|
|
|
|
|
|
|
|
return advance;
|
|
|
|
}
|
|
|
|
|
2014-11-21 09:48:23 +01:00
|
|
|
#else /* HAVE_FREETYPE */
|
|
|
|
|
|
|
|
BOOL init_freetype(void)
|
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2014-12-08 11:24:39 +01:00
|
|
|
void release_freetype(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-03-03 06:16:25 +01:00
|
|
|
void freetype_notify_cacheremove(IDWriteFontFace3 *fontface)
|
2014-11-21 09:48:23 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-03-03 06:16:25 +01:00
|
|
|
HRESULT freetype_get_design_glyph_metrics(IDWriteFontFace3 *fontface, UINT16 unitsperEm, UINT16 glyph, DWRITE_GLYPH_METRICS *ret)
|
2014-11-21 09:48:23 +01:00
|
|
|
{
|
2014-12-08 11:24:39 +01:00
|
|
|
return E_NOTIMPL;
|
2014-11-21 09:48:23 +01:00
|
|
|
}
|
|
|
|
|
2016-03-03 06:16:25 +01:00
|
|
|
BOOL freetype_is_monospaced(IDWriteFontFace3 *fontface)
|
2014-12-09 07:58:14 +01:00
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2016-03-03 06:16:25 +01:00
|
|
|
HRESULT freetype_get_glyphrun_outline(IDWriteFontFace3 *fontface, FLOAT emSize, UINT16 const *glyphs, FLOAT const *advances,
|
2016-01-18 22:47:09 +01:00
|
|
|
DWRITE_GLYPH_OFFSET const *offsets, UINT32 count, BOOL is_rtl, IDWriteGeometrySink *sink)
|
2014-12-15 07:39:26 +01:00
|
|
|
{
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
2016-03-03 06:16:25 +01:00
|
|
|
UINT16 freetype_get_glyphcount(IDWriteFontFace3 *fontface)
|
2015-02-05 13:54:05 +01:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-03-03 06:16:25 +01:00
|
|
|
void freetype_get_glyphs(IDWriteFontFace3 *fontface, INT charmap, UINT32 const *codepoints, UINT32 count,
|
2016-02-09 15:11:20 +01:00
|
|
|
UINT16 *glyphs)
|
2015-02-20 11:47:30 +01:00
|
|
|
{
|
2016-02-09 15:11:20 +01:00
|
|
|
memset(glyphs, 0, count * sizeof(*glyphs));
|
2015-02-20 11:47:30 +01:00
|
|
|
}
|
|
|
|
|
2016-03-03 06:16:25 +01:00
|
|
|
BOOL freetype_has_kerning_pairs(IDWriteFontFace3 *fontface)
|
2015-03-13 20:42:30 +01:00
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2016-03-03 06:16:25 +01:00
|
|
|
INT32 freetype_get_kerning_pair_adjustment(IDWriteFontFace3 *fontface, UINT16 left, UINT16 right)
|
2015-03-13 21:19:18 +01:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-08-27 07:38:50 +02:00
|
|
|
void freetype_get_glyph_bbox(struct dwrite_glyphbitmap *bitmap)
|
2015-07-29 10:59:02 +02:00
|
|
|
{
|
2015-08-27 07:38:50 +02:00
|
|
|
memset(&bitmap->bbox, 0, sizeof(bitmap->bbox));
|
2015-07-29 10:59:02 +02:00
|
|
|
}
|
|
|
|
|
2015-08-27 07:39:45 +02:00
|
|
|
BOOL freetype_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
|
|
|
}
|
|
|
|
|
2016-03-03 06:16:25 +01:00
|
|
|
INT freetype_get_charmap_index(IDWriteFontFace3 *fontface, BOOL *is_symbol)
|
2015-08-06 17:02:43 +02:00
|
|
|
{
|
|
|
|
*is_symbol = FALSE;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2016-03-03 06:16:25 +01:00
|
|
|
INT32 freetype_get_glyph_advance(IDWriteFontFace3 *fontface, FLOAT emSize, UINT16 index, DWRITE_MEASURING_MODE mode)
|
2015-08-24 09:43:19 +02:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-11-21 09:48:23 +01:00
|
|
|
#endif /* HAVE_FREETYPE */
|