2012-07-31 06:12:35 +02:00
|
|
|
/*
|
|
|
|
* GDI Interop
|
|
|
|
*
|
2015-07-31 00:30:50 +02:00
|
|
|
* Copyright 2011 Huw Davies
|
2018-11-22 12:29:14 +01:00
|
|
|
* Copyright 2012, 2014-2018 Nikolay Sivov for CodeWeavers
|
2012-07-31 06:12:35 +02: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
|
|
|
|
*/
|
|
|
|
|
2012-08-13 05:49:19 +02:00
|
|
|
#define COBJMACROS
|
|
|
|
|
2012-07-31 06:12:35 +02:00
|
|
|
#include <stdarg.h>
|
|
|
|
|
|
|
|
#include "windef.h"
|
|
|
|
#include "winbase.h"
|
2012-08-13 05:49:19 +02:00
|
|
|
#include "wingdi.h"
|
2012-08-13 05:44:19 +02:00
|
|
|
#include "dwrite_private.h"
|
2012-07-31 06:12:35 +02:00
|
|
|
|
|
|
|
#include "wine/debug.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(dwrite);
|
|
|
|
|
2015-07-31 00:30:50 +02:00
|
|
|
struct dib_data {
|
|
|
|
DWORD *ptr;
|
|
|
|
int stride;
|
|
|
|
int width;
|
|
|
|
};
|
|
|
|
|
2019-12-05 09:56:05 +01:00
|
|
|
struct rendertarget
|
|
|
|
{
|
2014-11-23 20:22:01 +01:00
|
|
|
IDWriteBitmapRenderTarget1 IDWriteBitmapRenderTarget1_iface;
|
2015-08-13 17:55:52 +02:00
|
|
|
ID2D1SimplifiedGeometrySink ID2D1SimplifiedGeometrySink_iface;
|
2019-12-05 09:56:05 +01:00
|
|
|
LONG refcount;
|
2012-08-13 05:49:19 +02:00
|
|
|
|
2019-12-05 09:56:05 +01:00
|
|
|
IDWriteFactory7 *factory;
|
2014-11-23 20:22:01 +01:00
|
|
|
DWRITE_TEXT_ANTIALIAS_MODE antialiasmode;
|
2020-12-01 13:15:00 +01:00
|
|
|
float ppdip;
|
2014-08-01 21:11:10 +02:00
|
|
|
DWRITE_MATRIX m;
|
2012-08-13 05:51:38 +02:00
|
|
|
SIZE size;
|
2012-08-13 05:49:19 +02:00
|
|
|
HDC hdc;
|
2015-07-31 00:30:50 +02:00
|
|
|
struct dib_data dib;
|
2012-08-13 05:49:19 +02:00
|
|
|
};
|
|
|
|
|
2019-12-05 09:56:05 +01:00
|
|
|
struct gdiinterop
|
|
|
|
{
|
2017-04-11 13:21:32 +02:00
|
|
|
IDWriteGdiInterop1 IDWriteGdiInterop1_iface;
|
2018-11-22 12:29:14 +01:00
|
|
|
IDWriteFontFileLoader IDWriteFontFileLoader_iface;
|
2019-12-05 09:56:05 +01:00
|
|
|
LONG refcount;
|
|
|
|
IDWriteFactory7 *factory;
|
2017-04-11 13:21:32 +02:00
|
|
|
};
|
|
|
|
|
2020-12-02 12:44:05 +01:00
|
|
|
struct memresource_stream
|
|
|
|
{
|
2018-11-22 12:29:14 +01:00
|
|
|
IDWriteFontFileStream IDWriteFontFileStream_iface;
|
2020-12-02 12:44:05 +01:00
|
|
|
LONG refcount;
|
2018-11-22 12:29:14 +01:00
|
|
|
DWORD key;
|
|
|
|
};
|
|
|
|
|
2015-07-31 00:30:50 +02:00
|
|
|
static inline int get_dib_stride(int width, int bpp)
|
|
|
|
{
|
|
|
|
return ((width * bpp + 31) >> 3) & ~3;
|
|
|
|
}
|
|
|
|
|
2015-07-22 10:54:53 +02:00
|
|
|
static HRESULT create_target_dibsection(struct rendertarget *target, UINT32 width, UINT32 height)
|
2014-08-01 19:11:45 +02:00
|
|
|
{
|
|
|
|
char bmibuf[FIELD_OFFSET(BITMAPINFO, bmiColors[256])];
|
|
|
|
BITMAPINFO *bmi = (BITMAPINFO*)bmibuf;
|
|
|
|
HBITMAP hbm;
|
|
|
|
|
2015-07-22 10:54:53 +02:00
|
|
|
target->size.cx = width;
|
|
|
|
target->size.cy = height;
|
|
|
|
|
2014-08-01 19:11:45 +02:00
|
|
|
memset(bmi, 0, sizeof(bmibuf));
|
|
|
|
bmi->bmiHeader.biSize = sizeof(bmi->bmiHeader);
|
2015-07-22 10:54:02 +02:00
|
|
|
bmi->bmiHeader.biHeight = -height;
|
2014-08-01 19:11:45 +02:00
|
|
|
bmi->bmiHeader.biWidth = width;
|
|
|
|
bmi->bmiHeader.biBitCount = 32;
|
|
|
|
bmi->bmiHeader.biPlanes = 1;
|
|
|
|
bmi->bmiHeader.biCompression = BI_RGB;
|
|
|
|
|
2015-07-31 00:30:50 +02:00
|
|
|
hbm = CreateDIBSection(target->hdc, bmi, DIB_RGB_COLORS, (void**)&target->dib.ptr, NULL, 0);
|
|
|
|
if (!hbm) {
|
2014-08-01 19:11:45 +02:00
|
|
|
hbm = CreateBitmap(1, 1, 1, 1, NULL);
|
2015-07-31 00:30:50 +02:00
|
|
|
target->dib.ptr = NULL;
|
|
|
|
target->dib.stride = 0;
|
|
|
|
target->dib.width = 0;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
target->dib.stride = get_dib_stride(width, 32);
|
|
|
|
target->dib.width = width;
|
|
|
|
}
|
2014-08-01 19:11:45 +02:00
|
|
|
|
2015-07-22 10:54:53 +02:00
|
|
|
DeleteObject(SelectObject(target->hdc, hbm));
|
2014-08-01 19:11:45 +02:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2014-11-23 20:22:01 +01:00
|
|
|
static inline struct rendertarget *impl_from_IDWriteBitmapRenderTarget1(IDWriteBitmapRenderTarget1 *iface)
|
2012-08-13 05:49:19 +02:00
|
|
|
{
|
2014-11-23 20:22:01 +01:00
|
|
|
return CONTAINING_RECORD(iface, struct rendertarget, IDWriteBitmapRenderTarget1_iface);
|
2012-08-13 05:49:19 +02:00
|
|
|
}
|
|
|
|
|
2015-08-13 17:55:52 +02:00
|
|
|
static inline struct rendertarget *impl_from_ID2D1SimplifiedGeometrySink(ID2D1SimplifiedGeometrySink *iface)
|
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(iface, struct rendertarget, ID2D1SimplifiedGeometrySink_iface);
|
|
|
|
}
|
|
|
|
|
2016-04-19 08:39:28 +02:00
|
|
|
static inline struct gdiinterop *impl_from_IDWriteGdiInterop1(IDWriteGdiInterop1 *iface)
|
2014-08-13 20:47:13 +02:00
|
|
|
{
|
2016-04-19 08:39:28 +02:00
|
|
|
return CONTAINING_RECORD(iface, struct gdiinterop, IDWriteGdiInterop1_iface);
|
2014-08-13 20:47:13 +02:00
|
|
|
}
|
|
|
|
|
2018-11-22 12:29:14 +01:00
|
|
|
static inline struct memresource_stream *impl_from_IDWriteFontFileStream(IDWriteFontFileStream *iface)
|
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(iface, struct memresource_stream, IDWriteFontFileStream_iface);
|
|
|
|
}
|
|
|
|
|
2015-08-13 17:55:52 +02:00
|
|
|
static HRESULT WINAPI rendertarget_sink_QueryInterface(ID2D1SimplifiedGeometrySink *iface, REFIID riid, void **obj)
|
|
|
|
{
|
|
|
|
if (IsEqualIID(riid, &IID_ID2D1SimplifiedGeometrySink) ||
|
|
|
|
IsEqualIID(riid, &IID_IUnknown))
|
|
|
|
{
|
|
|
|
*obj = iface;
|
|
|
|
ID2D1SimplifiedGeometrySink_AddRef(iface);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2017-09-22 14:34:51 +02:00
|
|
|
WARN("%s not implemented.\n", debugstr_guid(riid));
|
|
|
|
|
2015-08-13 17:55:52 +02:00
|
|
|
*obj = NULL;
|
|
|
|
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI rendertarget_sink_AddRef(ID2D1SimplifiedGeometrySink *iface)
|
|
|
|
{
|
2020-12-01 13:15:00 +01:00
|
|
|
struct rendertarget *target = impl_from_ID2D1SimplifiedGeometrySink(iface);
|
|
|
|
return IDWriteBitmapRenderTarget1_AddRef(&target->IDWriteBitmapRenderTarget1_iface);
|
2015-08-13 17:55:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI rendertarget_sink_Release(ID2D1SimplifiedGeometrySink *iface)
|
|
|
|
{
|
2020-12-01 13:15:00 +01:00
|
|
|
struct rendertarget *target = impl_from_ID2D1SimplifiedGeometrySink(iface);
|
|
|
|
return IDWriteBitmapRenderTarget1_Release(&target->IDWriteBitmapRenderTarget1_iface);
|
2015-08-13 17:55:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void WINAPI rendertarget_sink_SetFillMode(ID2D1SimplifiedGeometrySink *iface, D2D1_FILL_MODE mode)
|
|
|
|
{
|
2020-12-01 13:15:00 +01:00
|
|
|
struct rendertarget *target = impl_from_ID2D1SimplifiedGeometrySink(iface);
|
|
|
|
SetPolyFillMode(target->hdc, mode == D2D1_FILL_MODE_ALTERNATE ? ALTERNATE : WINDING);
|
2015-08-13 17:55:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void WINAPI rendertarget_sink_SetSegmentFlags(ID2D1SimplifiedGeometrySink *iface, D2D1_PATH_SEGMENT vertexFlags)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static void WINAPI rendertarget_sink_BeginFigure(ID2D1SimplifiedGeometrySink *iface, D2D1_POINT_2F startPoint, D2D1_FIGURE_BEGIN figureBegin)
|
|
|
|
{
|
2020-12-01 13:15:00 +01:00
|
|
|
struct rendertarget *target = impl_from_ID2D1SimplifiedGeometrySink(iface);
|
|
|
|
MoveToEx(target->hdc, startPoint.x, startPoint.y, NULL);
|
2015-08-13 17:55:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void WINAPI rendertarget_sink_AddLines(ID2D1SimplifiedGeometrySink *iface, const D2D1_POINT_2F *points, UINT32 count)
|
|
|
|
{
|
2020-12-01 13:15:00 +01:00
|
|
|
struct rendertarget *target = impl_from_ID2D1SimplifiedGeometrySink(iface);
|
2015-08-13 17:55:52 +02:00
|
|
|
|
2020-12-01 13:15:00 +01:00
|
|
|
while (count--)
|
|
|
|
{
|
|
|
|
LineTo(target->hdc, points->x, points->y);
|
2015-08-13 17:55:52 +02:00
|
|
|
points++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void WINAPI rendertarget_sink_AddBeziers(ID2D1SimplifiedGeometrySink *iface, const D2D1_BEZIER_SEGMENT *beziers, UINT32 count)
|
|
|
|
{
|
2020-12-01 13:15:00 +01:00
|
|
|
struct rendertarget *target = impl_from_ID2D1SimplifiedGeometrySink(iface);
|
2015-08-13 17:55:52 +02:00
|
|
|
POINT points[3];
|
|
|
|
|
2020-12-01 13:15:00 +01:00
|
|
|
while (count--)
|
|
|
|
{
|
2015-08-13 17:55:52 +02:00
|
|
|
points[0].x = beziers->point1.x;
|
|
|
|
points[0].y = beziers->point1.y;
|
|
|
|
points[1].x = beziers->point2.x;
|
|
|
|
points[1].y = beziers->point2.y;
|
|
|
|
points[2].x = beziers->point3.x;
|
|
|
|
points[2].y = beziers->point3.y;
|
|
|
|
|
2020-12-01 13:15:00 +01:00
|
|
|
PolyBezierTo(target->hdc, points, 3);
|
2015-08-13 17:55:52 +02:00
|
|
|
beziers++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void WINAPI rendertarget_sink_EndFigure(ID2D1SimplifiedGeometrySink *iface, D2D1_FIGURE_END figureEnd)
|
|
|
|
{
|
2020-12-01 13:15:00 +01:00
|
|
|
struct rendertarget *target = impl_from_ID2D1SimplifiedGeometrySink(iface);
|
|
|
|
CloseFigure(target->hdc);
|
2015-08-13 17:55:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI rendertarget_sink_Close(ID2D1SimplifiedGeometrySink *iface)
|
|
|
|
{
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2020-12-01 13:15:00 +01:00
|
|
|
static const ID2D1SimplifiedGeometrySinkVtbl rendertargetsinkvtbl =
|
|
|
|
{
|
2015-08-13 17:55:52 +02:00
|
|
|
rendertarget_sink_QueryInterface,
|
|
|
|
rendertarget_sink_AddRef,
|
|
|
|
rendertarget_sink_Release,
|
|
|
|
rendertarget_sink_SetFillMode,
|
|
|
|
rendertarget_sink_SetSegmentFlags,
|
|
|
|
rendertarget_sink_BeginFigure,
|
|
|
|
rendertarget_sink_AddLines,
|
|
|
|
rendertarget_sink_AddBeziers,
|
|
|
|
rendertarget_sink_EndFigure,
|
|
|
|
rendertarget_sink_Close
|
|
|
|
};
|
|
|
|
|
2014-11-23 20:22:01 +01:00
|
|
|
static HRESULT WINAPI rendertarget_QueryInterface(IDWriteBitmapRenderTarget1 *iface, REFIID riid, void **obj)
|
2012-08-13 05:49:19 +02:00
|
|
|
{
|
2020-12-01 13:15:00 +01:00
|
|
|
TRACE("%p, %s, %p.\n", iface, debugstr_guid(riid), obj);
|
2012-08-13 05:49:19 +02:00
|
|
|
|
2014-11-23 20:22:01 +01:00
|
|
|
if (IsEqualIID(riid, &IID_IDWriteBitmapRenderTarget1) ||
|
|
|
|
IsEqualIID(riid, &IID_IDWriteBitmapRenderTarget) ||
|
|
|
|
IsEqualIID(riid, &IID_IUnknown))
|
2012-08-13 05:49:19 +02:00
|
|
|
{
|
|
|
|
*obj = iface;
|
2014-11-23 20:22:01 +01:00
|
|
|
IDWriteBitmapRenderTarget1_AddRef(iface);
|
2012-08-13 05:49:19 +02:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2017-09-22 14:34:51 +02:00
|
|
|
WARN("%s not implemented.\n", debugstr_guid(riid));
|
|
|
|
|
2012-08-13 05:49:19 +02:00
|
|
|
*obj = NULL;
|
|
|
|
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
2014-11-23 20:22:01 +01:00
|
|
|
static ULONG WINAPI rendertarget_AddRef(IDWriteBitmapRenderTarget1 *iface)
|
2012-08-13 05:49:19 +02:00
|
|
|
{
|
2019-12-05 09:56:05 +01:00
|
|
|
struct rendertarget *target = impl_from_IDWriteBitmapRenderTarget1(iface);
|
|
|
|
ULONG refcount = InterlockedIncrement(&target->refcount);
|
|
|
|
|
2022-02-10 08:42:08 +01:00
|
|
|
TRACE("%p, refcount %lu.\n", iface, refcount);
|
2019-12-05 09:56:05 +01:00
|
|
|
|
|
|
|
return refcount;
|
2012-08-13 05:49:19 +02:00
|
|
|
}
|
|
|
|
|
2014-11-23 20:22:01 +01:00
|
|
|
static ULONG WINAPI rendertarget_Release(IDWriteBitmapRenderTarget1 *iface)
|
2012-08-13 05:49:19 +02:00
|
|
|
{
|
2019-12-05 09:56:05 +01:00
|
|
|
struct rendertarget *target = impl_from_IDWriteBitmapRenderTarget1(iface);
|
|
|
|
ULONG refcount = InterlockedDecrement(&target->refcount);
|
2012-08-13 05:49:19 +02:00
|
|
|
|
2022-02-10 08:42:08 +01:00
|
|
|
TRACE("%p, refcount %lu.\n", iface, refcount);
|
2012-08-13 05:49:19 +02:00
|
|
|
|
2019-12-05 09:56:05 +01:00
|
|
|
if (!refcount)
|
2012-08-13 05:49:19 +02:00
|
|
|
{
|
2019-12-05 09:56:05 +01:00
|
|
|
IDWriteFactory7_Release(target->factory);
|
|
|
|
DeleteDC(target->hdc);
|
2021-12-02 13:37:19 +01:00
|
|
|
free(target);
|
2012-08-13 05:49:19 +02:00
|
|
|
}
|
|
|
|
|
2019-12-05 09:56:05 +01:00
|
|
|
return refcount;
|
2012-08-13 05:49:19 +02:00
|
|
|
}
|
|
|
|
|
2015-07-31 00:30:50 +02:00
|
|
|
static inline DWORD *get_pixel_ptr_32(struct dib_data *dib, int x, int y)
|
|
|
|
{
|
|
|
|
return (DWORD *)((BYTE*)dib->ptr + y * dib->stride + x * 4);
|
|
|
|
}
|
|
|
|
|
2017-09-05 12:35:27 +02:00
|
|
|
static inline BYTE blend_color(BYTE dst, BYTE src, BYTE alpha)
|
|
|
|
{
|
|
|
|
return (src * alpha + dst * (255 - alpha) + 127) / 255;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline DWORD blend_subpixel(BYTE r, BYTE g, BYTE b, DWORD text, const BYTE *alpha)
|
|
|
|
{
|
|
|
|
return blend_color(r, text >> 16, alpha[0]) << 16 |
|
|
|
|
blend_color(g, text >> 8, alpha[1]) << 8 |
|
|
|
|
blend_color(b, text, alpha[2]);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline DWORD blend_pixel(BYTE r, BYTE g, BYTE b, DWORD text, BYTE alpha)
|
|
|
|
{
|
|
|
|
return blend_color(r, text >> 16, alpha) << 16 |
|
|
|
|
blend_color(g, text >> 8, alpha) << 8 |
|
|
|
|
blend_color(b, text, alpha);
|
|
|
|
}
|
|
|
|
|
2015-07-31 00:30:50 +02:00
|
|
|
static void blit_8(struct dib_data *dib, const BYTE *src, const RECT *rect, DWORD text_pixel)
|
|
|
|
{
|
|
|
|
DWORD *dst_ptr = get_pixel_ptr_32(dib, rect->left, rect->top);
|
|
|
|
int x, y, src_width = rect->right - rect->left;
|
|
|
|
|
|
|
|
for (y = rect->top; y < rect->bottom; y++) {
|
|
|
|
for (x = 0; x < src_width; x++) {
|
2017-09-07 03:15:28 +02:00
|
|
|
if (!src[x]) continue;
|
2017-09-05 12:35:27 +02:00
|
|
|
if (src[x] == DWRITE_ALPHA_MAX)
|
|
|
|
dst_ptr[x] = text_pixel;
|
|
|
|
else
|
|
|
|
dst_ptr[x] = blend_pixel(dst_ptr[x] >> 16, dst_ptr[x] >> 8, dst_ptr[x], text_pixel, src[x]);
|
2015-07-31 00:30:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
src += src_width;
|
|
|
|
dst_ptr += dib->stride / 4;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void blit_subpixel_888(struct dib_data *dib, int dib_width, const BYTE *src,
|
|
|
|
const RECT *rect, DWORD text_pixel)
|
|
|
|
{
|
|
|
|
DWORD *dst_ptr = get_pixel_ptr_32(dib, rect->left, rect->top);
|
|
|
|
int x, y, src_width = rect->right - rect->left;
|
|
|
|
|
|
|
|
for (y = rect->top; y < rect->bottom; y++) {
|
|
|
|
for (x = 0; x < src_width; x++) {
|
|
|
|
if (src[3*x] == 0 && src[3*x+1] == 0 && src[3*x+2] == 0) continue;
|
|
|
|
dst_ptr[x] = blend_subpixel(dst_ptr[x] >> 16, dst_ptr[x] >> 8, dst_ptr[x], text_pixel, &src[3*x]);
|
|
|
|
}
|
|
|
|
dst_ptr += dib->stride / 4;
|
|
|
|
src += src_width * 3;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-24 11:01:06 +02:00
|
|
|
static inline DWORD colorref_to_pixel_888(COLORREF color)
|
|
|
|
{
|
|
|
|
return (((color >> 16) & 0xff) | (color & 0xff00) | ((color << 16) & 0xff0000));
|
|
|
|
}
|
|
|
|
|
2014-11-23 20:22:01 +01:00
|
|
|
static HRESULT WINAPI rendertarget_DrawGlyphRun(IDWriteBitmapRenderTarget1 *iface,
|
2015-07-31 00:30:50 +02:00
|
|
|
FLOAT originX, FLOAT originY, DWRITE_MEASURING_MODE measuring_mode,
|
|
|
|
DWRITE_GLYPH_RUN const *run, IDWriteRenderingParams *params, COLORREF color,
|
|
|
|
RECT *bbox_ret)
|
2012-08-13 05:49:19 +02:00
|
|
|
{
|
2019-12-05 09:56:05 +01:00
|
|
|
struct rendertarget *target = impl_from_IDWriteBitmapRenderTarget1(iface);
|
2015-07-31 00:30:50 +02:00
|
|
|
IDWriteGlyphRunAnalysis *analysis;
|
2017-07-24 16:26:06 +02:00
|
|
|
DWRITE_RENDERING_MODE1 rendermode;
|
2017-07-17 22:18:44 +02:00
|
|
|
DWRITE_GRID_FIT_MODE gridfitmode;
|
2015-07-31 00:30:50 +02:00
|
|
|
DWRITE_TEXTURE_TYPE texturetype;
|
2017-07-17 22:18:44 +02:00
|
|
|
DWRITE_GLYPH_RUN scaled_run;
|
2017-07-24 16:26:06 +02:00
|
|
|
IDWriteFontFace3 *fontface;
|
2019-12-05 09:56:05 +01:00
|
|
|
RECT target_rect, bounds;
|
2015-07-31 00:30:50 +02:00
|
|
|
HRESULT hr;
|
|
|
|
|
2022-02-10 08:42:08 +01:00
|
|
|
TRACE("%p, %.8e, %.8e, %d, %p, %p, 0x%08lx, %p.\n", iface, originX, originY,
|
2015-07-31 00:30:50 +02:00
|
|
|
measuring_mode, run, params, color, bbox_ret);
|
|
|
|
|
2015-08-13 17:55:52 +02:00
|
|
|
SetRectEmpty(bbox_ret);
|
|
|
|
|
2019-12-05 09:56:05 +01:00
|
|
|
if (!target->dib.ptr)
|
2015-07-31 00:30:50 +02:00
|
|
|
return S_OK;
|
|
|
|
|
2017-07-17 22:18:45 +02:00
|
|
|
if (!params)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
2017-07-24 16:26:06 +02:00
|
|
|
if (FAILED(hr = IDWriteFontFace_QueryInterface(run->fontFace, &IID_IDWriteFontFace3, (void **)&fontface))) {
|
2022-02-10 08:42:08 +01:00
|
|
|
WARN("Failed to get IDWriteFontFace2 interface, hr %#lx.\n", hr);
|
2017-07-17 22:18:44 +02:00
|
|
|
return hr;
|
2015-08-13 17:56:38 +02:00
|
|
|
}
|
|
|
|
|
2019-12-05 09:56:05 +01:00
|
|
|
hr = IDWriteFontFace3_GetRecommendedRenderingMode(fontface, run->fontEmSize, target->ppdip * 96.0f,
|
2021-03-15 08:36:50 +01:00
|
|
|
target->ppdip * 96.0f, &target->m, run->isSideways, DWRITE_OUTLINE_THRESHOLD_ALIASED, measuring_mode,
|
2017-07-17 22:18:44 +02:00
|
|
|
params, &rendermode, &gridfitmode);
|
2017-07-24 16:26:06 +02:00
|
|
|
IDWriteFontFace3_Release(fontface);
|
2015-07-31 00:30:50 +02:00
|
|
|
if (FAILED(hr))
|
|
|
|
return hr;
|
|
|
|
|
2019-12-05 09:56:05 +01:00
|
|
|
SetRect(&target_rect, 0, 0, target->size.cx, target->size.cy);
|
2015-08-13 17:55:52 +02:00
|
|
|
|
2019-12-05 09:56:05 +01:00
|
|
|
if (rendermode == DWRITE_RENDERING_MODE1_OUTLINE)
|
|
|
|
{
|
2015-08-13 17:55:52 +02:00
|
|
|
static const XFORM identity = { 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f };
|
2019-12-05 09:56:05 +01:00
|
|
|
const DWRITE_MATRIX *m = &target->m;
|
2015-08-13 17:55:52 +02:00
|
|
|
XFORM xform;
|
|
|
|
|
|
|
|
/* target allows any transform to be set, filter it here */
|
|
|
|
if (m->m11 * m->m22 == m->m12 * m->m21) {
|
|
|
|
xform.eM11 = 1.0f;
|
|
|
|
xform.eM12 = 0.0f;
|
|
|
|
xform.eM21 = 0.0f;
|
|
|
|
xform.eM22 = 1.0f;
|
|
|
|
xform.eDx = originX;
|
|
|
|
xform.eDy = originY;
|
|
|
|
} else {
|
|
|
|
xform.eM11 = m->m11;
|
|
|
|
xform.eM12 = m->m12;
|
|
|
|
xform.eM21 = m->m21;
|
|
|
|
xform.eM22 = m->m22;
|
|
|
|
xform.eDx = m->m11 * originX + m->m21 * originY + m->dx;
|
|
|
|
xform.eDy = m->m12 * originX + m->m22 * originY + m->dy;
|
|
|
|
}
|
2019-12-05 09:56:05 +01:00
|
|
|
SetWorldTransform(target->hdc, &xform);
|
2015-08-13 17:55:52 +02:00
|
|
|
|
2019-12-05 09:56:05 +01:00
|
|
|
BeginPath(target->hdc);
|
2015-08-13 17:55:52 +02:00
|
|
|
|
2019-12-05 09:56:05 +01:00
|
|
|
hr = IDWriteFontFace_GetGlyphRunOutline(run->fontFace, run->fontEmSize * target->ppdip,
|
2015-08-13 17:55:52 +02:00
|
|
|
run->glyphIndices, run->glyphAdvances, run->glyphOffsets, run->glyphCount,
|
2019-12-05 09:56:05 +01:00
|
|
|
run->isSideways, run->bidiLevel & 1, &target->ID2D1SimplifiedGeometrySink_iface);
|
2015-08-13 17:55:52 +02:00
|
|
|
|
2019-12-05 09:56:05 +01:00
|
|
|
EndPath(target->hdc);
|
2015-08-13 17:55:52 +02:00
|
|
|
|
2019-12-05 09:56:05 +01:00
|
|
|
if (hr == S_OK)
|
|
|
|
{
|
2015-08-13 17:55:52 +02:00
|
|
|
HBRUSH brush = CreateSolidBrush(color);
|
|
|
|
|
2019-12-05 09:56:05 +01:00
|
|
|
SelectObject(target->hdc, brush);
|
2015-08-13 17:55:52 +02:00
|
|
|
|
2019-12-05 09:56:05 +01:00
|
|
|
FillPath(target->hdc);
|
2015-08-13 17:55:52 +02:00
|
|
|
|
|
|
|
/* FIXME: one way to get affected rectangle bounds is to use region fill */
|
|
|
|
if (bbox_ret)
|
2019-12-05 09:56:05 +01:00
|
|
|
*bbox_ret = target_rect;
|
2015-08-13 17:55:52 +02:00
|
|
|
|
|
|
|
DeleteObject(brush);
|
|
|
|
}
|
|
|
|
|
2019-12-05 09:56:05 +01:00
|
|
|
SetWorldTransform(target->hdc, &identity);
|
2015-08-13 17:55:52 +02:00
|
|
|
|
|
|
|
return hr;
|
|
|
|
}
|
2015-07-31 00:30:50 +02:00
|
|
|
|
2017-07-17 22:18:44 +02:00
|
|
|
scaled_run = *run;
|
2019-12-05 09:56:05 +01:00
|
|
|
scaled_run.fontEmSize *= target->ppdip;
|
|
|
|
hr = IDWriteFactory7_CreateGlyphRunAnalysis(target->factory, &scaled_run, &target->m, rendermode, measuring_mode,
|
|
|
|
gridfitmode, target->antialiasmode, originX, originY, &analysis);
|
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
2022-02-10 08:42:08 +01:00
|
|
|
WARN("failed to create analysis instance, 0x%08lx\n", hr);
|
2015-07-31 00:30:50 +02:00
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
SetRectEmpty(&bounds);
|
|
|
|
texturetype = DWRITE_TEXTURE_ALIASED_1x1;
|
|
|
|
hr = IDWriteGlyphRunAnalysis_GetAlphaTextureBounds(analysis, DWRITE_TEXTURE_ALIASED_1x1, &bounds);
|
|
|
|
if (FAILED(hr) || IsRectEmpty(&bounds)) {
|
|
|
|
hr = IDWriteGlyphRunAnalysis_GetAlphaTextureBounds(analysis, DWRITE_TEXTURE_CLEARTYPE_3x1, &bounds);
|
2015-08-22 20:06:29 +02:00
|
|
|
if (FAILED(hr)) {
|
2022-02-10 08:42:08 +01:00
|
|
|
WARN("GetAlphaTextureBounds() failed, 0x%08lx\n", hr);
|
2015-10-28 19:00:49 +01:00
|
|
|
IDWriteGlyphRunAnalysis_Release(analysis);
|
2015-08-22 20:06:29 +02:00
|
|
|
return hr;
|
|
|
|
}
|
2015-07-31 00:30:50 +02:00
|
|
|
texturetype = DWRITE_TEXTURE_CLEARTYPE_3x1;
|
|
|
|
}
|
|
|
|
|
2019-12-05 09:56:05 +01:00
|
|
|
if (IntersectRect(&target_rect, &target_rect, &bounds))
|
|
|
|
{
|
|
|
|
UINT32 size = (target_rect.right - target_rect.left) * (target_rect.bottom - target_rect.top);
|
2015-07-31 00:30:50 +02:00
|
|
|
BYTE *bitmap;
|
|
|
|
|
2015-08-24 11:01:06 +02:00
|
|
|
color = colorref_to_pixel_888(color);
|
2015-07-31 00:30:50 +02:00
|
|
|
if (texturetype == DWRITE_TEXTURE_CLEARTYPE_3x1)
|
|
|
|
size *= 3;
|
2021-12-02 13:37:19 +01:00
|
|
|
if (!(bitmap = calloc(1, size)))
|
|
|
|
{
|
2016-01-13 20:41:13 +01:00
|
|
|
IDWriteGlyphRunAnalysis_Release(analysis);
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
}
|
|
|
|
|
2019-12-05 09:56:05 +01:00
|
|
|
hr = IDWriteGlyphRunAnalysis_CreateAlphaTexture(analysis, texturetype, &target_rect, bitmap, size);
|
2015-07-31 00:30:50 +02:00
|
|
|
if (hr == S_OK) {
|
|
|
|
/* blit to target dib */
|
|
|
|
if (texturetype == DWRITE_TEXTURE_ALIASED_1x1)
|
2019-12-05 09:56:05 +01:00
|
|
|
blit_8(&target->dib, bitmap, &target_rect, color);
|
2015-07-31 00:30:50 +02:00
|
|
|
else
|
2019-12-05 09:56:05 +01:00
|
|
|
blit_subpixel_888(&target->dib, target->size.cx, bitmap, &target_rect, color);
|
2015-07-31 00:30:50 +02:00
|
|
|
|
2019-12-05 09:56:05 +01:00
|
|
|
if (bbox_ret) *bbox_ret = target_rect;
|
2015-07-31 00:30:50 +02:00
|
|
|
}
|
|
|
|
|
2021-12-02 13:37:19 +01:00
|
|
|
free(bitmap);
|
2015-07-31 00:30:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
IDWriteGlyphRunAnalysis_Release(analysis);
|
|
|
|
|
|
|
|
return S_OK;
|
2012-08-13 05:49:19 +02:00
|
|
|
}
|
|
|
|
|
2014-11-23 20:22:01 +01:00
|
|
|
static HDC WINAPI rendertarget_GetMemoryDC(IDWriteBitmapRenderTarget1 *iface)
|
2012-08-13 05:49:19 +02:00
|
|
|
{
|
2020-12-01 13:15:00 +01:00
|
|
|
struct rendertarget *target = impl_from_IDWriteBitmapRenderTarget1(iface);
|
|
|
|
|
|
|
|
TRACE("%p.\n", iface);
|
|
|
|
|
|
|
|
return target->hdc;
|
2012-08-13 05:49:19 +02:00
|
|
|
}
|
|
|
|
|
2020-12-01 13:15:00 +01:00
|
|
|
static float WINAPI rendertarget_GetPixelsPerDip(IDWriteBitmapRenderTarget1 *iface)
|
2012-08-13 05:49:19 +02:00
|
|
|
{
|
2020-12-01 13:15:00 +01:00
|
|
|
struct rendertarget *target = impl_from_IDWriteBitmapRenderTarget1(iface);
|
|
|
|
|
|
|
|
TRACE("%p.\n", iface);
|
|
|
|
|
|
|
|
return target->ppdip;
|
2012-08-13 05:49:19 +02:00
|
|
|
}
|
|
|
|
|
2020-12-01 13:15:00 +01:00
|
|
|
static HRESULT WINAPI rendertarget_SetPixelsPerDip(IDWriteBitmapRenderTarget1 *iface, float ppdip)
|
2012-08-13 05:49:19 +02:00
|
|
|
{
|
2020-12-01 13:15:00 +01:00
|
|
|
struct rendertarget *target = impl_from_IDWriteBitmapRenderTarget1(iface);
|
2014-10-29 20:53:42 +01:00
|
|
|
|
2020-12-01 13:15:00 +01:00
|
|
|
TRACE("%p, %.2f.\n", iface, ppdip);
|
2014-10-29 20:53:42 +01:00
|
|
|
|
2016-01-11 14:15:53 +01:00
|
|
|
if (ppdip <= 0.0f)
|
2014-10-29 20:53:42 +01:00
|
|
|
return E_INVALIDARG;
|
|
|
|
|
2020-12-01 13:15:00 +01:00
|
|
|
target->ppdip = ppdip;
|
2014-10-29 20:53:42 +01:00
|
|
|
return S_OK;
|
2012-08-13 05:49:19 +02:00
|
|
|
}
|
|
|
|
|
2014-11-23 20:22:01 +01:00
|
|
|
static HRESULT WINAPI rendertarget_GetCurrentTransform(IDWriteBitmapRenderTarget1 *iface, DWRITE_MATRIX *transform)
|
2012-08-13 05:49:19 +02:00
|
|
|
{
|
2020-12-01 13:15:00 +01:00
|
|
|
struct rendertarget *target = impl_from_IDWriteBitmapRenderTarget1(iface);
|
2014-08-01 21:11:10 +02:00
|
|
|
|
2020-12-01 13:15:00 +01:00
|
|
|
TRACE("%p, %p.\n", iface, transform);
|
2014-08-01 21:11:10 +02:00
|
|
|
|
2020-12-01 13:15:00 +01:00
|
|
|
*transform = target->m;
|
2014-08-01 21:11:10 +02:00
|
|
|
return S_OK;
|
2012-08-13 05:49:19 +02:00
|
|
|
}
|
|
|
|
|
2014-11-23 20:22:01 +01:00
|
|
|
static HRESULT WINAPI rendertarget_SetCurrentTransform(IDWriteBitmapRenderTarget1 *iface, DWRITE_MATRIX const *transform)
|
2012-08-13 05:49:19 +02:00
|
|
|
{
|
2020-12-01 13:15:00 +01:00
|
|
|
struct rendertarget *target = impl_from_IDWriteBitmapRenderTarget1(iface);
|
2014-11-18 13:35:50 +01:00
|
|
|
|
2020-12-01 13:15:00 +01:00
|
|
|
TRACE("%p, %p.\n", iface, transform);
|
2014-11-18 13:35:50 +01:00
|
|
|
|
2020-12-01 13:15:00 +01:00
|
|
|
target->m = transform ? *transform : identity;
|
2014-11-18 13:35:50 +01:00
|
|
|
return S_OK;
|
2012-08-13 05:49:19 +02:00
|
|
|
}
|
|
|
|
|
2014-11-23 20:22:01 +01:00
|
|
|
static HRESULT WINAPI rendertarget_GetSize(IDWriteBitmapRenderTarget1 *iface, SIZE *size)
|
2012-08-13 05:49:19 +02:00
|
|
|
{
|
2020-12-01 13:15:00 +01:00
|
|
|
struct rendertarget *target = impl_from_IDWriteBitmapRenderTarget1(iface);
|
2012-08-13 05:51:38 +02:00
|
|
|
|
2020-12-01 13:15:00 +01:00
|
|
|
TRACE("%p, %p.\n", iface, size);
|
|
|
|
|
|
|
|
*size = target->size;
|
2012-08-13 05:51:38 +02:00
|
|
|
return S_OK;
|
2012-08-13 05:49:19 +02:00
|
|
|
}
|
|
|
|
|
2014-11-23 20:22:01 +01:00
|
|
|
static HRESULT WINAPI rendertarget_Resize(IDWriteBitmapRenderTarget1 *iface, UINT32 width, UINT32 height)
|
2012-08-13 05:49:19 +02:00
|
|
|
{
|
2020-12-01 13:15:00 +01:00
|
|
|
struct rendertarget *target = impl_from_IDWriteBitmapRenderTarget1(iface);
|
2014-08-01 19:11:45 +02:00
|
|
|
|
2020-12-01 13:15:00 +01:00
|
|
|
TRACE("%p, %u, %u.\n", iface, width, height);
|
2014-08-01 19:11:45 +02:00
|
|
|
|
2020-12-01 13:15:00 +01:00
|
|
|
if (target->size.cx == width && target->size.cy == height)
|
2014-08-01 19:11:45 +02:00
|
|
|
return S_OK;
|
|
|
|
|
2020-12-01 13:15:00 +01:00
|
|
|
return create_target_dibsection(target, width, height);
|
2012-08-13 05:49:19 +02:00
|
|
|
}
|
|
|
|
|
2014-11-23 20:22:01 +01:00
|
|
|
static DWRITE_TEXT_ANTIALIAS_MODE WINAPI rendertarget_GetTextAntialiasMode(IDWriteBitmapRenderTarget1 *iface)
|
|
|
|
{
|
2020-12-01 13:15:00 +01:00
|
|
|
struct rendertarget *target = impl_from_IDWriteBitmapRenderTarget1(iface);
|
|
|
|
|
|
|
|
TRACE("%p.\n", iface);
|
|
|
|
|
|
|
|
return target->antialiasmode;
|
2014-11-23 20:22:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI rendertarget_SetTextAntialiasMode(IDWriteBitmapRenderTarget1 *iface, DWRITE_TEXT_ANTIALIAS_MODE mode)
|
|
|
|
{
|
2020-12-01 13:15:00 +01:00
|
|
|
struct rendertarget *target = impl_from_IDWriteBitmapRenderTarget1(iface);
|
2014-11-23 20:22:01 +01:00
|
|
|
|
2020-12-01 13:15:00 +01:00
|
|
|
TRACE("%p, %d.\n", iface, mode);
|
2014-11-23 20:22:01 +01:00
|
|
|
|
|
|
|
if ((DWORD)mode > DWRITE_TEXT_ANTIALIAS_MODE_GRAYSCALE)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
2020-12-01 13:15:00 +01:00
|
|
|
target->antialiasmode = mode;
|
2014-11-23 20:22:01 +01:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2020-12-01 13:15:00 +01:00
|
|
|
static const IDWriteBitmapRenderTarget1Vtbl rendertargetvtbl =
|
|
|
|
{
|
2012-08-13 05:49:19 +02:00
|
|
|
rendertarget_QueryInterface,
|
|
|
|
rendertarget_AddRef,
|
|
|
|
rendertarget_Release,
|
|
|
|
rendertarget_DrawGlyphRun,
|
|
|
|
rendertarget_GetMemoryDC,
|
|
|
|
rendertarget_GetPixelsPerDip,
|
|
|
|
rendertarget_SetPixelsPerDip,
|
|
|
|
rendertarget_GetCurrentTransform,
|
|
|
|
rendertarget_SetCurrentTransform,
|
|
|
|
rendertarget_GetSize,
|
2014-11-23 20:22:01 +01:00
|
|
|
rendertarget_Resize,
|
|
|
|
rendertarget_GetTextAntialiasMode,
|
|
|
|
rendertarget_SetTextAntialiasMode
|
2012-08-13 05:49:19 +02:00
|
|
|
};
|
|
|
|
|
2020-12-01 13:15:00 +01:00
|
|
|
static HRESULT create_rendertarget(IDWriteFactory7 *factory, HDC hdc, UINT32 width, UINT32 height,
|
|
|
|
IDWriteBitmapRenderTarget **ret)
|
2012-08-13 05:49:19 +02:00
|
|
|
{
|
2014-08-01 19:11:45 +02:00
|
|
|
struct rendertarget *target;
|
|
|
|
HRESULT hr;
|
2012-08-13 05:49:19 +02:00
|
|
|
|
2014-08-01 19:11:45 +02:00
|
|
|
*ret = NULL;
|
2012-08-13 05:49:19 +02:00
|
|
|
|
2021-12-02 13:37:19 +01:00
|
|
|
if (!(target = malloc(sizeof(*target))))
|
|
|
|
return E_OUTOFMEMORY;
|
2012-08-13 05:51:38 +02:00
|
|
|
|
2014-11-23 20:22:01 +01:00
|
|
|
target->IDWriteBitmapRenderTarget1_iface.lpVtbl = &rendertargetvtbl;
|
2015-08-13 17:55:52 +02:00
|
|
|
target->ID2D1SimplifiedGeometrySink_iface.lpVtbl = &rendertargetsinkvtbl;
|
2019-12-05 09:56:05 +01:00
|
|
|
target->refcount = 1;
|
2012-08-13 05:49:19 +02:00
|
|
|
|
2014-08-01 19:11:45 +02:00
|
|
|
target->hdc = CreateCompatibleDC(hdc);
|
2015-08-13 17:55:52 +02:00
|
|
|
SetGraphicsMode(target->hdc, GM_ADVANCED);
|
2015-07-22 10:54:53 +02:00
|
|
|
hr = create_target_dibsection(target, width, height);
|
2014-08-01 19:11:45 +02:00
|
|
|
if (FAILED(hr)) {
|
2014-11-23 20:22:01 +01:00
|
|
|
IDWriteBitmapRenderTarget1_Release(&target->IDWriteBitmapRenderTarget1_iface);
|
2014-08-01 19:11:45 +02:00
|
|
|
return hr;
|
|
|
|
}
|
2012-08-13 05:49:19 +02:00
|
|
|
|
2014-11-18 13:35:50 +01:00
|
|
|
target->m = identity;
|
2015-10-19 07:43:04 +02:00
|
|
|
target->ppdip = GetDeviceCaps(target->hdc, LOGPIXELSX) / 96.0f;
|
2014-11-23 20:22:01 +01:00
|
|
|
target->antialiasmode = DWRITE_TEXT_ANTIALIAS_MODE_CLEARTYPE;
|
2015-07-31 00:30:50 +02:00
|
|
|
target->factory = factory;
|
2019-12-05 09:56:05 +01:00
|
|
|
IDWriteFactory7_AddRef(factory);
|
2014-08-01 21:11:10 +02:00
|
|
|
|
2014-11-23 20:22:01 +01:00
|
|
|
*ret = (IDWriteBitmapRenderTarget*)&target->IDWriteBitmapRenderTarget1_iface;
|
2012-08-13 05:49:19 +02:00
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2016-04-19 08:39:28 +02:00
|
|
|
static HRESULT WINAPI gdiinterop_QueryInterface(IDWriteGdiInterop1 *iface, REFIID riid, void **obj)
|
2012-07-31 06:12:35 +02:00
|
|
|
{
|
2020-12-01 13:15:01 +01:00
|
|
|
TRACE("%p, %s, %p.\n", iface, debugstr_guid(riid), obj);
|
2012-07-31 06:12:35 +02:00
|
|
|
|
2016-04-19 08:39:28 +02:00
|
|
|
if (IsEqualIID(riid, &IID_IDWriteGdiInterop1) ||
|
|
|
|
IsEqualIID(riid, &IID_IDWriteGdiInterop) ||
|
2014-10-19 21:57:53 +02:00
|
|
|
IsEqualIID(riid, &IID_IUnknown))
|
2012-07-31 06:12:35 +02:00
|
|
|
{
|
|
|
|
*obj = iface;
|
2016-04-19 08:39:28 +02:00
|
|
|
IDWriteGdiInterop1_AddRef(iface);
|
2012-07-31 06:12:35 +02:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2017-09-22 14:34:51 +02:00
|
|
|
WARN("%s not implemented.\n", debugstr_guid(riid));
|
|
|
|
|
2012-07-31 06:12:35 +02:00
|
|
|
*obj = NULL;
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
2016-04-19 08:39:28 +02:00
|
|
|
static ULONG WINAPI gdiinterop_AddRef(IDWriteGdiInterop1 *iface)
|
2012-07-31 06:12:35 +02:00
|
|
|
{
|
2019-12-05 09:56:05 +01:00
|
|
|
struct gdiinterop *interop = impl_from_IDWriteGdiInterop1(iface);
|
|
|
|
LONG refcount = InterlockedIncrement(&interop->refcount);
|
|
|
|
|
2022-02-10 08:42:08 +01:00
|
|
|
TRACE("%p, refcount %lu.\n", iface, refcount);
|
2019-12-05 09:56:05 +01:00
|
|
|
|
|
|
|
return refcount;
|
2012-07-31 06:12:35 +02:00
|
|
|
}
|
|
|
|
|
2016-04-19 08:39:28 +02:00
|
|
|
static ULONG WINAPI gdiinterop_Release(IDWriteGdiInterop1 *iface)
|
2012-07-31 06:12:35 +02:00
|
|
|
{
|
2019-12-05 09:56:05 +01:00
|
|
|
struct gdiinterop *interop = impl_from_IDWriteGdiInterop1(iface);
|
|
|
|
LONG refcount = InterlockedDecrement(&interop->refcount);
|
2017-04-11 13:21:32 +02:00
|
|
|
|
2022-02-10 08:42:08 +01:00
|
|
|
TRACE("%p, refcount %lu.\n", iface, refcount);
|
2017-04-11 13:21:32 +02:00
|
|
|
|
2019-12-05 09:56:05 +01:00
|
|
|
if (!refcount)
|
|
|
|
{
|
|
|
|
IDWriteFactory7_UnregisterFontFileLoader(interop->factory, &interop->IDWriteFontFileLoader_iface);
|
|
|
|
factory_detach_gdiinterop(interop->factory, iface);
|
2021-12-02 13:37:19 +01:00
|
|
|
free(interop);
|
2017-04-11 13:21:32 +02:00
|
|
|
}
|
|
|
|
|
2019-12-05 09:56:05 +01:00
|
|
|
return refcount;
|
2012-07-31 06:12:35 +02:00
|
|
|
}
|
|
|
|
|
2016-04-19 08:39:28 +02:00
|
|
|
static HRESULT WINAPI gdiinterop_CreateFontFromLOGFONT(IDWriteGdiInterop1 *iface,
|
2012-07-31 06:12:35 +02:00
|
|
|
LOGFONTW const *logfont, IDWriteFont **font)
|
|
|
|
{
|
2020-12-01 13:15:01 +01:00
|
|
|
TRACE("%p, %p, %p.\n", iface, logfont, font);
|
2012-07-31 06:18:02 +02:00
|
|
|
|
2016-04-22 15:15:35 +02:00
|
|
|
return IDWriteGdiInterop1_CreateFontFromLOGFONT(iface, logfont, NULL, font);
|
2012-07-31 06:12:35 +02:00
|
|
|
}
|
|
|
|
|
2016-04-19 08:39:28 +02:00
|
|
|
static HRESULT WINAPI gdiinterop_ConvertFontToLOGFONT(IDWriteGdiInterop1 *iface,
|
2012-07-31 06:12:35 +02:00
|
|
|
IDWriteFont *font, LOGFONTW *logfont, BOOL *is_systemfont)
|
|
|
|
{
|
2014-11-07 11:17:38 +01:00
|
|
|
IDWriteFontCollection *collection;
|
|
|
|
IDWriteFontFamily *family;
|
|
|
|
HRESULT hr;
|
|
|
|
|
2020-12-01 13:15:01 +01:00
|
|
|
TRACE("%p, %p, %p, %p.\n", iface, font, logfont, is_systemfont);
|
2014-11-07 11:17:38 +01:00
|
|
|
|
|
|
|
*is_systemfont = FALSE;
|
|
|
|
|
2015-08-06 16:57:26 +02:00
|
|
|
memset(logfont, 0, sizeof(*logfont));
|
|
|
|
|
2014-11-07 11:17:38 +01:00
|
|
|
if (!font)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
|
|
|
hr = IDWriteFont_GetFontFamily(font, &family);
|
|
|
|
if (FAILED(hr))
|
|
|
|
return hr;
|
|
|
|
|
|
|
|
hr = IDWriteFontFamily_GetFontCollection(family, &collection);
|
|
|
|
IDWriteFontFamily_Release(family);
|
|
|
|
if (FAILED(hr))
|
|
|
|
return hr;
|
|
|
|
|
|
|
|
*is_systemfont = is_system_collection(collection);
|
|
|
|
IDWriteFontCollection_Release(collection);
|
|
|
|
|
2016-12-04 17:22:13 +01:00
|
|
|
get_logfont_from_font(font, logfont);
|
2014-11-07 11:17:38 +01:00
|
|
|
logfont->lfCharSet = DEFAULT_CHARSET;
|
|
|
|
logfont->lfOutPrecision = OUT_OUTLINE_PRECIS;
|
|
|
|
|
2016-02-08 10:31:46 +01:00
|
|
|
return hr;
|
2012-07-31 06:12:35 +02:00
|
|
|
}
|
|
|
|
|
2016-04-19 08:39:28 +02:00
|
|
|
static HRESULT WINAPI gdiinterop_ConvertFontFaceToLOGFONT(IDWriteGdiInterop1 *iface,
|
2014-01-05 22:24:17 +01:00
|
|
|
IDWriteFontFace *fontface, LOGFONTW *logfont)
|
2012-07-31 06:12:35 +02:00
|
|
|
{
|
2020-12-01 13:15:01 +01:00
|
|
|
TRACE("%p, %p, %p.\n", iface, fontface, logfont);
|
2015-02-19 09:43:15 +01:00
|
|
|
|
|
|
|
memset(logfont, 0, sizeof(*logfont));
|
|
|
|
|
2016-12-07 14:46:39 +01:00
|
|
|
if (!fontface)
|
|
|
|
return E_INVALIDARG;
|
2015-02-19 09:43:15 +01:00
|
|
|
|
2016-12-07 14:46:39 +01:00
|
|
|
get_logfont_from_fontface(fontface, logfont);
|
2015-02-19 09:43:15 +01:00
|
|
|
logfont->lfCharSet = DEFAULT_CHARSET;
|
|
|
|
logfont->lfOutPrecision = OUT_OUTLINE_PRECIS;
|
|
|
|
|
2016-12-07 14:46:39 +01:00
|
|
|
return S_OK;
|
2012-07-31 06:12:35 +02:00
|
|
|
}
|
|
|
|
|
2021-08-02 19:46:35 +02:00
|
|
|
struct font_realization_info
|
|
|
|
{
|
2015-10-06 12:46:18 +02:00
|
|
|
DWORD size;
|
|
|
|
DWORD flags;
|
|
|
|
DWORD cache_num;
|
|
|
|
DWORD instance_id;
|
2021-08-02 19:46:35 +02:00
|
|
|
DWORD file_count;
|
2015-10-08 20:13:57 +02:00
|
|
|
WORD face_index;
|
|
|
|
WORD simulations;
|
2015-10-06 12:46:18 +02:00
|
|
|
};
|
|
|
|
|
2021-08-02 19:46:35 +02:00
|
|
|
struct font_fileinfo
|
|
|
|
{
|
2015-10-06 12:46:18 +02:00
|
|
|
FILETIME writetime;
|
|
|
|
LARGE_INTEGER size;
|
|
|
|
WCHAR path[1];
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Undocumented gdi32 exports, used to access actually selected font information */
|
|
|
|
extern BOOL WINAPI GetFontRealizationInfo(HDC hdc, struct font_realization_info *info);
|
2021-08-02 19:46:35 +02:00
|
|
|
extern BOOL WINAPI GetFontFileInfo(DWORD instance_id, DWORD file_index, struct font_fileinfo *info, SIZE_T size, SIZE_T *needed);
|
|
|
|
extern BOOL WINAPI GetFontFileData(DWORD instance_id, DWORD file_index, UINT64 offset, void *buff, DWORD buff_size);
|
2015-10-06 12:46:18 +02:00
|
|
|
|
2016-04-19 08:39:28 +02:00
|
|
|
static HRESULT WINAPI gdiinterop_CreateFontFaceFromHdc(IDWriteGdiInterop1 *iface,
|
2012-07-31 06:12:35 +02:00
|
|
|
HDC hdc, IDWriteFontFace **fontface)
|
|
|
|
{
|
2019-12-05 09:56:05 +01:00
|
|
|
struct gdiinterop *interop = impl_from_IDWriteGdiInterop1(iface);
|
2015-10-06 12:46:18 +02:00
|
|
|
struct font_realization_info info;
|
|
|
|
struct font_fileinfo *fileinfo;
|
|
|
|
DWRITE_FONT_FILE_TYPE filetype;
|
|
|
|
DWRITE_FONT_FACE_TYPE facetype;
|
|
|
|
IDWriteFontFile *file;
|
|
|
|
BOOL is_supported;
|
|
|
|
UINT32 facenum;
|
2018-11-21 13:54:01 +01:00
|
|
|
SIZE_T needed;
|
2014-10-20 06:55:39 +02:00
|
|
|
HRESULT hr;
|
|
|
|
|
2019-12-05 09:56:05 +01:00
|
|
|
TRACE("%p, %p, %p.\n", iface, hdc, fontface);
|
2014-10-20 06:55:39 +02:00
|
|
|
|
|
|
|
*fontface = NULL;
|
|
|
|
|
2015-10-06 12:46:18 +02:00
|
|
|
if (!hdc)
|
2014-10-20 06:55:39 +02:00
|
|
|
return E_INVALIDARG;
|
|
|
|
|
2015-10-06 12:46:18 +02:00
|
|
|
/* get selected font id */
|
|
|
|
info.size = sizeof(info);
|
|
|
|
if (!GetFontRealizationInfo(hdc, &info)) {
|
|
|
|
WARN("failed to get selected font id\n");
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
needed = 0;
|
|
|
|
GetFontFileInfo(info.instance_id, 0, NULL, 0, &needed);
|
|
|
|
if (needed == 0) {
|
|
|
|
WARN("failed to get font file info size\n");
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
|
2021-12-02 13:37:19 +01:00
|
|
|
if (!(fileinfo = malloc(needed)))
|
2015-10-06 12:46:18 +02:00
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
2021-12-02 13:37:19 +01:00
|
|
|
if (!GetFontFileInfo(info.instance_id, 0, fileinfo, needed, &needed))
|
|
|
|
{
|
|
|
|
free(fileinfo);
|
2015-10-06 12:46:18 +02:00
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
|
2018-11-22 12:29:14 +01:00
|
|
|
if (*fileinfo->path)
|
2019-12-05 09:56:05 +01:00
|
|
|
hr = IDWriteFactory7_CreateFontFileReference(interop->factory, fileinfo->path, &fileinfo->writetime, &file);
|
2018-11-22 12:29:14 +01:00
|
|
|
else
|
2019-12-05 09:56:05 +01:00
|
|
|
hr = IDWriteFactory7_CreateCustomFontFileReference(interop->factory, &info.instance_id,
|
|
|
|
sizeof(info.instance_id), &interop->IDWriteFontFileLoader_iface, &file);
|
2018-11-22 12:29:14 +01:00
|
|
|
|
2021-12-02 13:37:19 +01:00
|
|
|
free(fileinfo);
|
2014-10-20 06:55:39 +02:00
|
|
|
if (FAILED(hr))
|
|
|
|
return hr;
|
|
|
|
|
2015-10-06 12:46:18 +02:00
|
|
|
is_supported = FALSE;
|
|
|
|
hr = IDWriteFontFile_Analyze(file, &is_supported, &filetype, &facetype, &facenum);
|
2017-04-19 14:15:29 +02:00
|
|
|
if (SUCCEEDED(hr)) {
|
|
|
|
if (is_supported)
|
|
|
|
/* Simulations flags values match DWRITE_FONT_SIMULATIONS */
|
2019-12-05 09:56:05 +01:00
|
|
|
hr = IDWriteFactory7_CreateFontFace(interop->factory, facetype, 1, &file, info.face_index,
|
2017-04-19 14:15:29 +02:00
|
|
|
info.simulations, fontface);
|
|
|
|
else
|
|
|
|
hr = DWRITE_E_FILEFORMAT;
|
2015-10-06 12:46:18 +02:00
|
|
|
}
|
2014-10-20 06:55:39 +02:00
|
|
|
|
2015-10-06 12:46:18 +02:00
|
|
|
IDWriteFontFile_Release(file);
|
2014-10-20 06:55:39 +02:00
|
|
|
return hr;
|
2012-07-31 06:12:35 +02:00
|
|
|
}
|
|
|
|
|
2016-04-19 08:39:28 +02:00
|
|
|
static HRESULT WINAPI gdiinterop_CreateBitmapRenderTarget(IDWriteGdiInterop1 *iface,
|
2012-07-31 06:12:35 +02:00
|
|
|
HDC hdc, UINT32 width, UINT32 height, IDWriteBitmapRenderTarget **target)
|
|
|
|
{
|
2020-12-01 13:15:01 +01:00
|
|
|
struct gdiinterop *interop = impl_from_IDWriteGdiInterop1(iface);
|
|
|
|
|
|
|
|
TRACE("%p, %p, %u, %u, %p.\n", iface, hdc, width, height, target);
|
|
|
|
|
|
|
|
return create_rendertarget(interop->factory, hdc, width, height, target);
|
2012-07-31 06:12:35 +02:00
|
|
|
}
|
|
|
|
|
2016-04-19 08:39:28 +02:00
|
|
|
static HRESULT WINAPI gdiinterop1_CreateFontFromLOGFONT(IDWriteGdiInterop1 *iface,
|
|
|
|
LOGFONTW const *logfont, IDWriteFontCollection *collection, IDWriteFont **font)
|
|
|
|
{
|
2019-12-05 09:56:05 +01:00
|
|
|
struct gdiinterop *interop = impl_from_IDWriteGdiInterop1(iface);
|
2016-04-22 15:15:35 +02:00
|
|
|
IDWriteFontFamily *family;
|
|
|
|
DWRITE_FONT_STYLE style;
|
|
|
|
BOOL exists = FALSE;
|
|
|
|
UINT32 index;
|
|
|
|
HRESULT hr;
|
2016-04-19 08:39:28 +02:00
|
|
|
|
2019-12-05 09:56:05 +01:00
|
|
|
TRACE("%p, %p, %p, %p.\n", iface, logfont, collection, font);
|
2016-04-19 08:39:28 +02:00
|
|
|
|
2016-04-22 15:15:35 +02:00
|
|
|
*font = NULL;
|
|
|
|
|
|
|
|
if (!logfont) return E_INVALIDARG;
|
|
|
|
|
|
|
|
if (collection)
|
|
|
|
IDWriteFontCollection_AddRef(collection);
|
|
|
|
else {
|
2019-12-05 09:56:05 +01:00
|
|
|
hr = IDWriteFactory5_GetSystemFontCollection((IDWriteFactory5 *)interop->factory, FALSE, (IDWriteFontCollection1 **)&collection, FALSE);
|
2016-04-22 15:15:35 +02:00
|
|
|
if (FAILED(hr)) {
|
2022-02-10 08:42:08 +01:00
|
|
|
ERR("failed to get system font collection: 0x%08lx.\n", hr);
|
2016-04-22 15:15:35 +02:00
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
hr = IDWriteFontCollection_FindFamilyName(collection, logfont->lfFaceName, &index, &exists);
|
|
|
|
if (FAILED(hr))
|
|
|
|
goto done;
|
|
|
|
|
|
|
|
if (!exists) {
|
|
|
|
hr = DWRITE_E_NOFONT;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
hr = IDWriteFontCollection_GetFontFamily(collection, index, &family);
|
|
|
|
if (FAILED(hr))
|
|
|
|
goto done;
|
|
|
|
|
|
|
|
style = logfont->lfItalic ? DWRITE_FONT_STYLE_ITALIC : DWRITE_FONT_STYLE_NORMAL;
|
|
|
|
hr = IDWriteFontFamily_GetFirstMatchingFont(family, logfont->lfWeight, DWRITE_FONT_STRETCH_NORMAL, style, font);
|
|
|
|
IDWriteFontFamily_Release(family);
|
|
|
|
|
|
|
|
done:
|
|
|
|
IDWriteFontCollection_Release(collection);
|
|
|
|
return hr;
|
2016-04-19 08:39:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI gdiinterop1_GetFontSignature_(IDWriteGdiInterop1 *iface, IDWriteFontFace *fontface,
|
|
|
|
FONTSIGNATURE *fontsig)
|
|
|
|
{
|
2020-12-01 13:15:01 +01:00
|
|
|
TRACE("%p, %p, %p.\n", iface, fontface, fontsig);
|
2016-05-03 20:26:47 +02:00
|
|
|
|
2017-08-15 13:40:26 +02:00
|
|
|
return get_fontsig_from_fontface(fontface, fontsig);
|
2016-04-19 08:39:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI gdiinterop1_GetFontSignature(IDWriteGdiInterop1 *iface, IDWriteFont *font, FONTSIGNATURE *fontsig)
|
|
|
|
{
|
2020-12-02 12:44:05 +01:00
|
|
|
TRACE("%p, %p, %p.\n", iface, font, fontsig);
|
2016-05-03 20:26:47 +02:00
|
|
|
|
|
|
|
if (!font)
|
|
|
|
return E_INVALIDARG;
|
2016-04-19 08:39:28 +02:00
|
|
|
|
2017-08-15 13:40:26 +02:00
|
|
|
return get_fontsig_from_font(font, fontsig);
|
2016-04-19 08:39:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI gdiinterop1_GetMatchingFontsByLOGFONT(IDWriteGdiInterop1 *iface, LOGFONTW const *logfont,
|
2022-01-20 11:37:44 +01:00
|
|
|
IDWriteFontSet *fontset, IDWriteFontSet **subset)
|
2016-04-19 08:39:28 +02:00
|
|
|
{
|
2022-01-20 11:37:44 +01:00
|
|
|
DWRITE_FONT_PROPERTY property;
|
2016-04-19 08:39:28 +02:00
|
|
|
|
2022-01-20 11:37:44 +01:00
|
|
|
TRACE("%p, %p, %p, %p.\n", iface, logfont, fontset, subset);
|
|
|
|
|
|
|
|
if (!logfont || !fontset)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
|
|
|
property.propertyId = DWRITE_FONT_PROPERTY_ID_WIN32_FAMILY_NAME;
|
|
|
|
property.propertyValue = logfont->lfFaceName;
|
|
|
|
property.localeName = L"";
|
|
|
|
|
|
|
|
return IDWriteFontSet_GetMatchingFonts(fontset, &property, 1, subset);
|
2016-04-19 08:39:28 +02:00
|
|
|
}
|
|
|
|
|
2021-02-01 12:35:23 +01:00
|
|
|
static const IDWriteGdiInterop1Vtbl gdiinteropvtbl =
|
|
|
|
{
|
2012-07-31 06:12:35 +02:00
|
|
|
gdiinterop_QueryInterface,
|
|
|
|
gdiinterop_AddRef,
|
|
|
|
gdiinterop_Release,
|
|
|
|
gdiinterop_CreateFontFromLOGFONT,
|
|
|
|
gdiinterop_ConvertFontToLOGFONT,
|
|
|
|
gdiinterop_ConvertFontFaceToLOGFONT,
|
|
|
|
gdiinterop_CreateFontFaceFromHdc,
|
2016-04-19 08:39:28 +02:00
|
|
|
gdiinterop_CreateBitmapRenderTarget,
|
|
|
|
gdiinterop1_CreateFontFromLOGFONT,
|
|
|
|
gdiinterop1_GetFontSignature_,
|
|
|
|
gdiinterop1_GetFontSignature,
|
|
|
|
gdiinterop1_GetMatchingFontsByLOGFONT
|
2012-07-31 06:12:35 +02:00
|
|
|
};
|
|
|
|
|
2018-11-22 12:29:14 +01:00
|
|
|
static HRESULT WINAPI memresourcestream_QueryInterface(IDWriteFontFileStream *iface, REFIID riid, void **out)
|
|
|
|
{
|
2020-12-02 12:44:05 +01:00
|
|
|
TRACE("%p, %s, %p.\n", iface, debugstr_guid(riid), out);
|
2018-11-22 12:29:14 +01:00
|
|
|
|
|
|
|
if (IsEqualIID(&IID_IDWriteFontFileStream, riid) || IsEqualIID(&IID_IUnknown, riid)) {
|
|
|
|
*out = iface;
|
|
|
|
IDWriteFontFileStream_AddRef(iface);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
*out = NULL;
|
|
|
|
WARN("Unsupported interface %s.\n", debugstr_guid(riid));
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI memresourcestream_AddRef(IDWriteFontFileStream *iface)
|
|
|
|
{
|
2020-12-02 12:44:05 +01:00
|
|
|
struct memresource_stream *stream = impl_from_IDWriteFontFileStream(iface);
|
|
|
|
ULONG refcount = InterlockedIncrement(&stream->refcount);
|
|
|
|
|
2022-02-10 08:42:08 +01:00
|
|
|
TRACE("%p, refcount %ld.\n", iface, refcount);
|
2020-12-02 12:44:05 +01:00
|
|
|
|
|
|
|
return refcount;
|
2018-11-22 12:29:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI memresourcestream_Release(IDWriteFontFileStream *iface)
|
|
|
|
{
|
2020-12-02 12:44:05 +01:00
|
|
|
struct memresource_stream *stream = impl_from_IDWriteFontFileStream(iface);
|
|
|
|
ULONG refcount = InterlockedDecrement(&stream->refcount);
|
2018-11-22 12:29:14 +01:00
|
|
|
|
2022-02-10 08:42:08 +01:00
|
|
|
TRACE("%p, refcount %ld.\n", iface, refcount);
|
2018-11-22 12:29:14 +01:00
|
|
|
|
2020-12-02 12:44:05 +01:00
|
|
|
if (!refcount)
|
2021-12-02 13:37:19 +01:00
|
|
|
free(stream);
|
2018-11-22 12:29:14 +01:00
|
|
|
|
2020-12-02 12:44:05 +01:00
|
|
|
return refcount;
|
2018-11-22 12:29:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI memresourcestream_ReadFileFragment(IDWriteFontFileStream *iface, void const **fragment_start,
|
|
|
|
UINT64 offset, UINT64 fragment_size, void **fragment_context)
|
|
|
|
{
|
2020-12-02 12:44:05 +01:00
|
|
|
struct memresource_stream *stream = impl_from_IDWriteFontFileStream(iface);
|
2018-11-22 12:29:14 +01:00
|
|
|
struct font_fileinfo fileinfo;
|
|
|
|
void *fragment;
|
|
|
|
|
2020-12-02 12:44:05 +01:00
|
|
|
TRACE("%p, %p, %s, %s, %p.\n", iface, fragment_start, wine_dbgstr_longlong(offset),
|
2018-11-22 12:29:14 +01:00
|
|
|
wine_dbgstr_longlong(fragment_size), fragment_context);
|
|
|
|
|
|
|
|
*fragment_context = NULL;
|
|
|
|
*fragment_start = NULL;
|
|
|
|
|
2020-12-02 12:44:05 +01:00
|
|
|
if (!GetFontFileInfo(stream->key, 0, &fileinfo, sizeof(fileinfo), NULL))
|
2018-11-22 12:29:14 +01:00
|
|
|
return E_INVALIDARG;
|
|
|
|
|
|
|
|
if ((offset >= fileinfo.size.QuadPart - 1) || (fragment_size > fileinfo.size.QuadPart - offset))
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
2021-12-02 13:37:19 +01:00
|
|
|
if (!(fragment = malloc(fragment_size)))
|
2018-11-22 12:29:14 +01:00
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
2020-12-02 12:44:05 +01:00
|
|
|
if (!GetFontFileData(stream->key, 0, offset, fragment, fragment_size))
|
2018-11-22 12:29:14 +01:00
|
|
|
return E_FAIL;
|
|
|
|
|
|
|
|
*fragment_start = *fragment_context = fragment;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void WINAPI memresourcestream_ReleaseFileFragment(IDWriteFontFileStream *iface, void *fragment_context)
|
|
|
|
{
|
2020-12-02 12:44:05 +01:00
|
|
|
TRACE("%p, %p.\n", iface, fragment_context);
|
2018-11-22 12:29:14 +01:00
|
|
|
|
2021-12-02 13:37:19 +01:00
|
|
|
free(fragment_context);
|
2018-11-22 12:29:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI memresourcestream_GetFileSize(IDWriteFontFileStream *iface, UINT64 *size)
|
|
|
|
{
|
2020-12-02 12:44:05 +01:00
|
|
|
struct memresource_stream *stream = impl_from_IDWriteFontFileStream(iface);
|
2018-11-22 12:29:14 +01:00
|
|
|
struct font_fileinfo fileinfo;
|
|
|
|
|
2020-12-02 12:44:05 +01:00
|
|
|
TRACE("%p, %p.\n", iface, size);
|
2018-11-22 12:29:14 +01:00
|
|
|
|
2020-12-02 12:44:05 +01:00
|
|
|
if (!GetFontFileInfo(stream->key, 0, &fileinfo, sizeof(fileinfo), NULL))
|
2018-11-22 12:29:14 +01:00
|
|
|
return E_INVALIDARG;
|
|
|
|
|
|
|
|
*size = fileinfo.size.QuadPart;
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI memresourcestream_GetLastWriteTime(IDWriteFontFileStream *iface, UINT64 *last_writetime)
|
|
|
|
{
|
2020-12-02 12:44:05 +01:00
|
|
|
TRACE("%p, %p.\n", iface, last_writetime);
|
2018-11-22 12:29:14 +01:00
|
|
|
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
2021-02-01 12:35:23 +01:00
|
|
|
static const IDWriteFontFileStreamVtbl memresourcestreamvtbl =
|
2020-12-02 12:44:05 +01:00
|
|
|
{
|
2018-11-22 12:29:14 +01:00
|
|
|
memresourcestream_QueryInterface,
|
|
|
|
memresourcestream_AddRef,
|
|
|
|
memresourcestream_Release,
|
|
|
|
memresourcestream_ReadFileFragment,
|
|
|
|
memresourcestream_ReleaseFileFragment,
|
|
|
|
memresourcestream_GetFileSize,
|
|
|
|
memresourcestream_GetLastWriteTime,
|
|
|
|
};
|
|
|
|
|
|
|
|
static HRESULT WINAPI memresourceloader_QueryInterface(IDWriteFontFileLoader *iface, REFIID riid, void **out)
|
|
|
|
{
|
2020-12-02 12:44:05 +01:00
|
|
|
TRACE("%p, %s, %p.\n", iface, debugstr_guid(riid), out);
|
2018-11-22 12:29:14 +01:00
|
|
|
|
|
|
|
if (IsEqualIID(&IID_IDWriteFontFileLoader, riid) || IsEqualIID(&IID_IUnknown, riid)) {
|
|
|
|
*out = iface;
|
|
|
|
IDWriteFontFileLoader_AddRef(iface);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
*out = NULL;
|
|
|
|
WARN("Unsupported interface %s.\n", debugstr_guid(riid));
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI memresourceloader_AddRef(IDWriteFontFileLoader *iface)
|
|
|
|
{
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI memresourceloader_Release(IDWriteFontFileLoader *iface)
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI memresourceloader_CreateStreamFromKey(IDWriteFontFileLoader *iface, void const *key,
|
|
|
|
UINT32 key_size, IDWriteFontFileStream **ret)
|
|
|
|
{
|
|
|
|
struct memresource_stream *stream;
|
|
|
|
|
2020-12-02 12:44:05 +01:00
|
|
|
TRACE("%p, %p, %u, %p.\n", iface, key, key_size, ret);
|
2018-11-22 12:29:14 +01:00
|
|
|
|
|
|
|
*ret = NULL;
|
|
|
|
|
|
|
|
if (!key || key_size != sizeof(DWORD))
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
2021-12-02 13:37:19 +01:00
|
|
|
if (!(stream = malloc(sizeof(*stream))))
|
2018-11-22 12:29:14 +01:00
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
|
|
|
stream->IDWriteFontFileStream_iface.lpVtbl = &memresourcestreamvtbl;
|
2020-12-02 12:44:05 +01:00
|
|
|
stream->refcount = 1;
|
2018-11-22 12:29:14 +01:00
|
|
|
memcpy(&stream->key, key, sizeof(stream->key));
|
|
|
|
|
|
|
|
*ret = &stream->IDWriteFontFileStream_iface;
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2021-02-01 12:35:23 +01:00
|
|
|
static const IDWriteFontFileLoaderVtbl memresourceloadervtbl =
|
|
|
|
{
|
2018-11-22 12:29:14 +01:00
|
|
|
memresourceloader_QueryInterface,
|
|
|
|
memresourceloader_AddRef,
|
|
|
|
memresourceloader_Release,
|
|
|
|
memresourceloader_CreateStreamFromKey,
|
|
|
|
};
|
|
|
|
|
2019-12-05 09:56:05 +01:00
|
|
|
HRESULT create_gdiinterop(IDWriteFactory7 *factory, IDWriteGdiInterop1 **ret)
|
2014-10-19 21:57:53 +02:00
|
|
|
{
|
2017-04-11 13:21:32 +02:00
|
|
|
struct gdiinterop *interop;
|
|
|
|
|
|
|
|
*ret = NULL;
|
|
|
|
|
2021-12-02 13:37:19 +01:00
|
|
|
if (!(interop = malloc(sizeof(*interop))))
|
2017-04-11 13:21:32 +02:00
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
2016-05-03 11:56:57 +02:00
|
|
|
interop->IDWriteGdiInterop1_iface.lpVtbl = &gdiinteropvtbl;
|
2018-11-22 12:29:14 +01:00
|
|
|
interop->IDWriteFontFileLoader_iface.lpVtbl = &memresourceloadervtbl;
|
2019-12-05 09:56:05 +01:00
|
|
|
interop->refcount = 1;
|
|
|
|
interop->factory = factory;
|
|
|
|
IDWriteFactory7_AddRef(interop->factory);
|
|
|
|
IDWriteFactory7_RegisterFontFileLoader(factory, &interop->IDWriteFontFileLoader_iface);
|
2017-04-11 13:21:32 +02:00
|
|
|
|
|
|
|
*ret = &interop->IDWriteGdiInterop1_iface;
|
|
|
|
return S_OK;
|
2014-10-19 21:57:53 +02:00
|
|
|
}
|