2012-08-13 05:44:19 +02:00
|
|
|
/*
|
|
|
|
* Font and collections
|
|
|
|
*
|
2014-10-20 19:45:57 +02:00
|
|
|
* Copyright 2012, 2014 Nikolay Sivov for CodeWeavers
|
|
|
|
* Copyright 2014 Aric Stewart for CodeWeavers
|
2012-08-13 05:44:19 +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
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define COBJMACROS
|
|
|
|
|
|
|
|
#include "dwrite_private.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(dwrite);
|
|
|
|
|
2014-10-07 07:23:26 +02:00
|
|
|
#define MS_HEAD_TAG DWRITE_MAKE_OPENTYPE_TAG('h','e','a','d')
|
|
|
|
#define MS_OS2_TAG DWRITE_MAKE_OPENTYPE_TAG('O','S','/','2')
|
|
|
|
#define MS_POST_TAG DWRITE_MAKE_OPENTYPE_TAG('p','o','s','t')
|
|
|
|
#define MS_CMAP_TAG DWRITE_MAKE_OPENTYPE_TAG('c','m','a','p')
|
2014-10-24 09:42:35 +02:00
|
|
|
#define MS_NAME_TAG DWRITE_MAKE_OPENTYPE_TAG('n','a','m','e')
|
2012-10-10 14:37:55 +02:00
|
|
|
|
2014-09-02 17:19:25 +02:00
|
|
|
struct dwrite_font_data {
|
2014-09-03 20:11:35 +02:00
|
|
|
LONG ref;
|
|
|
|
|
2014-09-02 17:19:25 +02:00
|
|
|
DWRITE_FONT_STYLE style;
|
|
|
|
DWRITE_FONT_STRETCH stretch;
|
|
|
|
DWRITE_FONT_WEIGHT weight;
|
|
|
|
DWRITE_FONT_METRICS metrics;
|
2014-10-20 19:45:57 +02:00
|
|
|
IDWriteLocalizedStrings *info_strings[DWRITE_INFORMATIONAL_STRING_POSTSCRIPT_CID_NAME+1];
|
2014-09-02 17:19:25 +02:00
|
|
|
|
2014-10-24 09:43:21 +02:00
|
|
|
/* data needed to create fontface instance */
|
|
|
|
IDWriteFactory *factory;
|
|
|
|
DWRITE_FONT_FACE_TYPE face_type;
|
|
|
|
IDWriteFontFile *file;
|
|
|
|
UINT32 face_index;
|
2014-09-02 17:19:36 +02:00
|
|
|
|
2014-09-02 17:19:25 +02:00
|
|
|
WCHAR *facename;
|
|
|
|
};
|
|
|
|
|
2014-09-09 02:10:48 +02:00
|
|
|
struct dwrite_fontfamily_data {
|
2014-10-08 16:52:07 +02:00
|
|
|
LONG ref;
|
|
|
|
|
2014-09-09 02:10:48 +02:00
|
|
|
IDWriteLocalizedStrings *familyname;
|
|
|
|
|
|
|
|
struct dwrite_font_data **fonts;
|
2014-10-27 09:25:19 +01:00
|
|
|
UINT32 font_count;
|
|
|
|
UINT32 font_alloc;
|
2014-09-09 02:10:48 +02:00
|
|
|
};
|
|
|
|
|
2012-10-21 03:43:01 +02:00
|
|
|
struct dwrite_fontcollection {
|
|
|
|
IDWriteFontCollection IDWriteFontCollection_iface;
|
2014-09-02 14:17:57 +02:00
|
|
|
LONG ref;
|
2012-10-21 06:24:35 +02:00
|
|
|
|
2014-10-08 16:52:07 +02:00
|
|
|
struct dwrite_fontfamily_data **family_data;
|
2014-10-27 12:48:46 +01:00
|
|
|
UINT32 family_count;
|
|
|
|
UINT32 family_alloc;
|
2012-10-21 03:43:01 +02:00
|
|
|
};
|
|
|
|
|
2012-08-25 11:11:31 +02:00
|
|
|
struct dwrite_fontfamily {
|
|
|
|
IDWriteFontFamily IDWriteFontFamily_iface;
|
|
|
|
LONG ref;
|
2012-10-07 18:29:39 +02:00
|
|
|
|
2014-09-09 02:10:48 +02:00
|
|
|
struct dwrite_fontfamily_data *data;
|
2014-09-03 20:11:35 +02:00
|
|
|
|
2014-09-03 14:27:17 +02:00
|
|
|
IDWriteFontCollection* collection;
|
2012-08-25 11:11:31 +02:00
|
|
|
};
|
|
|
|
|
2012-08-13 05:44:19 +02:00
|
|
|
struct dwrite_font {
|
2014-10-10 07:28:58 +02:00
|
|
|
IDWriteFont2 IDWriteFont2_iface;
|
2012-08-13 05:44:19 +02:00
|
|
|
LONG ref;
|
2012-08-13 05:46:43 +02:00
|
|
|
|
2012-08-25 11:11:31 +02:00
|
|
|
IDWriteFontFamily *family;
|
2014-09-02 17:19:25 +02:00
|
|
|
|
2014-11-04 20:53:19 +01:00
|
|
|
USHORT simulations;
|
2014-09-02 17:19:25 +02:00
|
|
|
struct dwrite_font_data *data;
|
2012-08-13 05:44:19 +02:00
|
|
|
};
|
|
|
|
|
2014-08-17 03:42:24 +02:00
|
|
|
#define DWRITE_FONTTABLE_MAGIC 0xededfafa
|
|
|
|
|
2014-10-06 14:26:31 +02:00
|
|
|
struct dwrite_fonttablecontext {
|
2014-08-17 03:42:24 +02:00
|
|
|
UINT32 magic;
|
2014-10-06 14:26:31 +02:00
|
|
|
void *context;
|
2014-08-17 03:42:24 +02:00
|
|
|
UINT32 file_index;
|
|
|
|
};
|
|
|
|
|
2014-10-06 14:26:31 +02:00
|
|
|
struct dwrite_fonttable {
|
|
|
|
void *data;
|
|
|
|
void *context;
|
|
|
|
UINT32 size;
|
|
|
|
};
|
|
|
|
|
2012-10-07 21:03:52 +02:00
|
|
|
struct dwrite_fontface {
|
2014-10-10 08:01:24 +02:00
|
|
|
IDWriteFontFace2 IDWriteFontFace2_iface;
|
2012-10-07 21:03:52 +02:00
|
|
|
LONG ref;
|
2012-10-24 22:05:01 +02:00
|
|
|
|
2014-11-05 21:30:32 +01:00
|
|
|
IDWriteFontFileStream **streams;
|
2014-10-24 09:40:06 +02:00
|
|
|
IDWriteFontFile **files;
|
|
|
|
UINT32 file_count;
|
|
|
|
UINT32 index;
|
|
|
|
|
2014-11-04 20:53:19 +01:00
|
|
|
USHORT simulations;
|
2014-10-24 09:40:06 +02:00
|
|
|
DWRITE_FONT_FACE_TYPE type;
|
|
|
|
|
2014-10-06 14:26:31 +02:00
|
|
|
struct dwrite_fonttable cmap;
|
2012-10-07 21:03:52 +02:00
|
|
|
};
|
|
|
|
|
2014-08-12 21:11:34 +02:00
|
|
|
struct dwrite_fontfile {
|
|
|
|
IDWriteFontFile IDWriteFontFile_iface;
|
|
|
|
LONG ref;
|
|
|
|
|
|
|
|
IDWriteFontFileLoader *loader;
|
|
|
|
void *reference_key;
|
|
|
|
UINT32 key_size;
|
2014-08-17 03:40:48 +02:00
|
|
|
IDWriteFontFileStream *stream;
|
2014-08-12 21:11:34 +02:00
|
|
|
};
|
|
|
|
|
2014-10-28 06:13:51 +01:00
|
|
|
static HRESULT get_filestream_from_file(IDWriteFontFile*,IDWriteFontFileStream**);
|
2012-10-22 06:06:03 +02:00
|
|
|
|
2014-10-10 08:01:24 +02:00
|
|
|
static inline struct dwrite_fontface *impl_from_IDWriteFontFace2(IDWriteFontFace2 *iface)
|
2012-10-07 21:03:52 +02:00
|
|
|
{
|
2014-10-10 08:01:24 +02:00
|
|
|
return CONTAINING_RECORD(iface, struct dwrite_fontface, IDWriteFontFace2_iface);
|
2012-10-07 21:03:52 +02:00
|
|
|
}
|
|
|
|
|
2014-10-10 07:28:58 +02:00
|
|
|
static inline struct dwrite_font *impl_from_IDWriteFont2(IDWriteFont2 *iface)
|
2012-08-13 05:44:19 +02:00
|
|
|
{
|
2014-10-10 07:28:58 +02:00
|
|
|
return CONTAINING_RECORD(iface, struct dwrite_font, IDWriteFont2_iface);
|
2012-08-13 05:44:19 +02:00
|
|
|
}
|
|
|
|
|
2014-08-12 21:11:34 +02:00
|
|
|
static inline struct dwrite_fontfile *impl_from_IDWriteFontFile(IDWriteFontFile *iface)
|
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(iface, struct dwrite_fontfile, IDWriteFontFile_iface);
|
|
|
|
}
|
|
|
|
|
2012-08-25 11:11:31 +02:00
|
|
|
static inline struct dwrite_fontfamily *impl_from_IDWriteFontFamily(IDWriteFontFamily *iface)
|
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(iface, struct dwrite_fontfamily, IDWriteFontFamily_iface);
|
|
|
|
}
|
|
|
|
|
2012-10-21 03:43:01 +02:00
|
|
|
static inline struct dwrite_fontcollection *impl_from_IDWriteFontCollection(IDWriteFontCollection *iface)
|
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(iface, struct dwrite_fontcollection, IDWriteFontCollection_iface);
|
|
|
|
}
|
|
|
|
|
2014-10-16 05:33:51 +02:00
|
|
|
static inline void* get_fontface_cmap(struct dwrite_fontface *fontface)
|
|
|
|
{
|
|
|
|
BOOL exists = FALSE;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
if (fontface->cmap.data)
|
|
|
|
return fontface->cmap.data;
|
|
|
|
|
|
|
|
hr = IDWriteFontFace2_TryGetFontTable(&fontface->IDWriteFontFace2_iface, MS_CMAP_TAG, (const void**)&fontface->cmap.data,
|
|
|
|
&fontface->cmap.size, &fontface->cmap.context, &exists);
|
|
|
|
if (FAILED(hr) || !exists) {
|
|
|
|
ERR("Font does not have a CMAP table\n");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return fontface->cmap.data;
|
|
|
|
}
|
|
|
|
|
2014-10-24 09:43:21 +02:00
|
|
|
static void release_font_data(struct dwrite_font_data *data)
|
2014-09-03 20:11:35 +02:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
if (!data)
|
|
|
|
return;
|
|
|
|
i = InterlockedDecrement(&data->ref);
|
|
|
|
if (i > 0)
|
|
|
|
return;
|
2014-10-20 19:45:57 +02:00
|
|
|
|
|
|
|
for (i = DWRITE_INFORMATIONAL_STRING_NONE; i < sizeof(data->info_strings)/sizeof(data->info_strings[0]); i++) {
|
|
|
|
if (data->info_strings[i])
|
|
|
|
IDWriteLocalizedStrings_Release(data->info_strings[i]);
|
|
|
|
}
|
2014-10-24 09:43:21 +02:00
|
|
|
|
2014-11-05 10:51:52 +01:00
|
|
|
IDWriteFontFile_Release(data->file);
|
|
|
|
IDWriteFactory_Release(data->factory);
|
2014-09-03 20:11:35 +02:00
|
|
|
heap_free(data->facename);
|
|
|
|
heap_free(data);
|
|
|
|
}
|
|
|
|
|
2014-10-08 16:52:07 +02:00
|
|
|
static VOID _free_fontfamily_data(struct dwrite_fontfamily_data *data)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
if (!data)
|
|
|
|
return;
|
|
|
|
i = InterlockedDecrement(&data->ref);
|
|
|
|
if (i > 0)
|
|
|
|
return;
|
|
|
|
for (i = 0; i < data->font_count; i++)
|
2014-10-24 09:43:21 +02:00
|
|
|
release_font_data(data->fonts[i]);
|
2014-10-08 16:52:07 +02:00
|
|
|
heap_free(data->fonts);
|
|
|
|
IDWriteLocalizedStrings_Release(data->familyname);
|
|
|
|
heap_free(data);
|
|
|
|
}
|
|
|
|
|
2014-10-10 08:01:24 +02:00
|
|
|
static HRESULT WINAPI dwritefontface_QueryInterface(IDWriteFontFace2 *iface, REFIID riid, void **obj)
|
2012-10-07 21:03:52 +02:00
|
|
|
{
|
2014-10-10 08:01:24 +02:00
|
|
|
struct dwrite_fontface *This = impl_from_IDWriteFontFace2(iface);
|
2012-10-07 21:03:52 +02:00
|
|
|
|
|
|
|
TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), obj);
|
|
|
|
|
2014-10-10 08:01:24 +02:00
|
|
|
if (IsEqualIID(riid, &IID_IDWriteFontFace2) ||
|
|
|
|
IsEqualIID(riid, &IID_IDWriteFontFace1) ||
|
|
|
|
IsEqualIID(riid, &IID_IDWriteFontFace) ||
|
|
|
|
IsEqualIID(riid, &IID_IUnknown))
|
2012-10-07 21:03:52 +02:00
|
|
|
{
|
|
|
|
*obj = iface;
|
2014-10-10 08:01:24 +02:00
|
|
|
IDWriteFontFace2_AddRef(iface);
|
2012-10-07 21:03:52 +02:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
*obj = NULL;
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
2014-10-10 08:01:24 +02:00
|
|
|
static ULONG WINAPI dwritefontface_AddRef(IDWriteFontFace2 *iface)
|
2012-10-07 21:03:52 +02:00
|
|
|
{
|
2014-10-10 08:01:24 +02:00
|
|
|
struct dwrite_fontface *This = impl_from_IDWriteFontFace2(iface);
|
2012-10-07 21:03:52 +02:00
|
|
|
ULONG ref = InterlockedIncrement(&This->ref);
|
|
|
|
TRACE("(%p)->(%d)\n", This, ref);
|
|
|
|
return ref;
|
|
|
|
}
|
|
|
|
|
2014-10-10 08:01:24 +02:00
|
|
|
static ULONG WINAPI dwritefontface_Release(IDWriteFontFace2 *iface)
|
2012-10-07 21:03:52 +02:00
|
|
|
{
|
2014-10-10 08:01:24 +02:00
|
|
|
struct dwrite_fontface *This = impl_from_IDWriteFontFace2(iface);
|
2012-10-07 21:03:52 +02:00
|
|
|
ULONG ref = InterlockedDecrement(&This->ref);
|
|
|
|
|
|
|
|
TRACE("(%p)->(%d)\n", This, ref);
|
|
|
|
|
2014-10-24 09:40:06 +02:00
|
|
|
if (!ref) {
|
|
|
|
UINT32 i;
|
|
|
|
|
2014-10-06 14:26:31 +02:00
|
|
|
if (This->cmap.context)
|
2014-10-10 08:01:24 +02:00
|
|
|
IDWriteFontFace2_ReleaseFontTable(iface, This->cmap.context);
|
2014-11-05 21:30:32 +01:00
|
|
|
for (i = 0; i < This->file_count; i++) {
|
|
|
|
if (This->streams[i])
|
|
|
|
IDWriteFontFileStream_Release(This->streams[i]);
|
|
|
|
if (This->files[i])
|
|
|
|
IDWriteFontFile_Release(This->files[i]);
|
|
|
|
}
|
2012-10-07 21:03:52 +02:00
|
|
|
heap_free(This);
|
2014-08-17 03:40:48 +02:00
|
|
|
}
|
2012-10-07 21:03:52 +02:00
|
|
|
|
2012-10-21 03:47:22 +02:00
|
|
|
return ref;
|
2012-10-07 21:03:52 +02:00
|
|
|
}
|
|
|
|
|
2014-10-10 08:01:24 +02:00
|
|
|
static DWRITE_FONT_FACE_TYPE WINAPI dwritefontface_GetType(IDWriteFontFace2 *iface)
|
2012-10-07 21:03:52 +02:00
|
|
|
{
|
2014-10-10 08:01:24 +02:00
|
|
|
struct dwrite_fontface *This = impl_from_IDWriteFontFace2(iface);
|
2014-08-17 03:40:48 +02:00
|
|
|
TRACE("(%p)\n", This);
|
2014-10-24 09:40:06 +02:00
|
|
|
return This->type;
|
2012-10-07 21:03:52 +02:00
|
|
|
}
|
|
|
|
|
2014-10-10 08:01:24 +02:00
|
|
|
static HRESULT WINAPI dwritefontface_GetFiles(IDWriteFontFace2 *iface, UINT32 *number_of_files,
|
2012-10-07 21:03:52 +02:00
|
|
|
IDWriteFontFile **fontfiles)
|
|
|
|
{
|
2014-10-10 08:01:24 +02:00
|
|
|
struct dwrite_fontface *This = impl_from_IDWriteFontFace2(iface);
|
2014-08-17 03:40:48 +02:00
|
|
|
int i;
|
2014-10-10 08:01:24 +02:00
|
|
|
|
2014-08-17 03:40:48 +02:00
|
|
|
TRACE("(%p)->(%p %p)\n", This, number_of_files, fontfiles);
|
|
|
|
if (fontfiles == NULL)
|
|
|
|
{
|
2014-10-24 09:40:06 +02:00
|
|
|
*number_of_files = This->file_count;
|
2014-08-17 03:40:48 +02:00
|
|
|
return S_OK;
|
|
|
|
}
|
2014-10-24 09:40:06 +02:00
|
|
|
if (*number_of_files < This->file_count)
|
2014-08-17 03:40:48 +02:00
|
|
|
return E_INVALIDARG;
|
|
|
|
|
2014-10-24 09:40:06 +02:00
|
|
|
for (i = 0; i < This->file_count; i++)
|
2014-08-17 03:40:48 +02:00
|
|
|
{
|
2014-10-24 09:40:06 +02:00
|
|
|
IDWriteFontFile_AddRef(This->files[i]);
|
|
|
|
fontfiles[i] = This->files[i];
|
2014-08-17 03:40:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return S_OK;
|
2012-10-07 21:03:52 +02:00
|
|
|
}
|
|
|
|
|
2014-10-10 08:01:24 +02:00
|
|
|
static UINT32 WINAPI dwritefontface_GetIndex(IDWriteFontFace2 *iface)
|
2012-10-07 21:03:52 +02:00
|
|
|
{
|
2014-10-10 08:01:24 +02:00
|
|
|
struct dwrite_fontface *This = impl_from_IDWriteFontFace2(iface);
|
2014-08-17 03:40:48 +02:00
|
|
|
TRACE("(%p)\n", This);
|
2014-10-24 09:40:06 +02:00
|
|
|
return This->index;
|
2012-10-07 21:03:52 +02:00
|
|
|
}
|
|
|
|
|
2014-10-10 08:01:24 +02:00
|
|
|
static DWRITE_FONT_SIMULATIONS WINAPI dwritefontface_GetSimulations(IDWriteFontFace2 *iface)
|
2012-10-07 21:03:52 +02:00
|
|
|
{
|
2014-10-10 08:01:24 +02:00
|
|
|
struct dwrite_fontface *This = impl_from_IDWriteFontFace2(iface);
|
2014-08-17 03:40:48 +02:00
|
|
|
TRACE("(%p)\n", This);
|
2014-10-24 09:40:06 +02:00
|
|
|
return This->simulations;
|
2012-10-07 21:03:52 +02:00
|
|
|
}
|
|
|
|
|
2014-10-10 08:01:24 +02:00
|
|
|
static BOOL WINAPI dwritefontface_IsSymbolFont(IDWriteFontFace2 *iface)
|
2012-10-07 21:03:52 +02:00
|
|
|
{
|
2014-10-10 08:01:24 +02:00
|
|
|
struct dwrite_fontface *This = impl_from_IDWriteFontFace2(iface);
|
2012-10-07 21:03:52 +02:00
|
|
|
FIXME("(%p): stub\n", This);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2014-10-10 08:01:24 +02:00
|
|
|
static void WINAPI dwritefontface_GetMetrics(IDWriteFontFace2 *iface, DWRITE_FONT_METRICS *metrics)
|
2012-10-07 21:03:52 +02:00
|
|
|
{
|
2014-10-10 08:01:24 +02:00
|
|
|
struct dwrite_fontface *This = impl_from_IDWriteFontFace2(iface);
|
2012-10-07 21:03:52 +02:00
|
|
|
FIXME("(%p)->(%p): stub\n", This, metrics);
|
|
|
|
}
|
|
|
|
|
2014-10-10 08:01:24 +02:00
|
|
|
static UINT16 WINAPI dwritefontface_GetGlyphCount(IDWriteFontFace2 *iface)
|
2012-10-07 21:03:52 +02:00
|
|
|
{
|
2014-10-10 08:01:24 +02:00
|
|
|
struct dwrite_fontface *This = impl_from_IDWriteFontFace2(iface);
|
2012-10-07 21:03:52 +02:00
|
|
|
FIXME("(%p): stub\n", This);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-10-10 08:01:24 +02:00
|
|
|
static HRESULT WINAPI dwritefontface_GetDesignGlyphMetrics(IDWriteFontFace2 *iface,
|
2012-10-07 21:03:52 +02:00
|
|
|
UINT16 const *glyph_indices, UINT32 glyph_count, DWRITE_GLYPH_METRICS *metrics, BOOL is_sideways)
|
|
|
|
{
|
2014-10-10 08:01:24 +02:00
|
|
|
struct dwrite_fontface *This = impl_from_IDWriteFontFace2(iface);
|
2012-10-07 21:03:52 +02:00
|
|
|
FIXME("(%p)->(%p %u %p %d): stub\n", This, glyph_indices, glyph_count, metrics, is_sideways);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
2014-10-10 08:01:24 +02:00
|
|
|
static HRESULT WINAPI dwritefontface_GetGlyphIndices(IDWriteFontFace2 *iface, UINT32 const *codepoints,
|
2012-10-07 21:03:52 +02:00
|
|
|
UINT32 count, UINT16 *glyph_indices)
|
|
|
|
{
|
2014-10-10 08:01:24 +02:00
|
|
|
struct dwrite_fontface *This = impl_from_IDWriteFontFace2(iface);
|
2014-09-03 14:26:43 +02:00
|
|
|
unsigned int i;
|
2014-10-29 20:41:47 +01:00
|
|
|
void *data;
|
2014-09-03 14:26:43 +02:00
|
|
|
|
2014-10-29 20:41:47 +01:00
|
|
|
TRACE("(%p)->(%p %u %p)\n", This, codepoints, count, glyph_indices);
|
2012-10-24 22:05:01 +02:00
|
|
|
|
2014-10-29 20:41:47 +01:00
|
|
|
data = get_fontface_cmap(This);
|
|
|
|
if (!data)
|
|
|
|
return E_FAIL;
|
2014-09-03 14:26:43 +02:00
|
|
|
|
2014-10-29 20:41:47 +01:00
|
|
|
for (i = 0; i < count; i++)
|
|
|
|
opentype_cmap_get_glyphindex(data, codepoints[i], &glyph_indices[i]);
|
2014-10-16 05:32:27 +02:00
|
|
|
|
2014-10-29 20:41:47 +01:00
|
|
|
return S_OK;
|
2012-10-07 21:03:52 +02:00
|
|
|
}
|
|
|
|
|
2014-10-10 08:01:24 +02:00
|
|
|
static HRESULT WINAPI dwritefontface_TryGetFontTable(IDWriteFontFace2 *iface, UINT32 table_tag,
|
2012-10-07 21:03:52 +02:00
|
|
|
const void **table_data, UINT32 *table_size, void **context, BOOL *exists)
|
|
|
|
{
|
2014-10-10 08:01:24 +02:00
|
|
|
struct dwrite_fontface *This = impl_from_IDWriteFontFace2(iface);
|
2014-10-29 20:41:47 +01:00
|
|
|
struct dwrite_fonttablecontext *tablecontext;
|
|
|
|
HRESULT hr = S_OK;
|
|
|
|
int i;
|
2014-08-17 03:42:24 +02:00
|
|
|
|
2014-10-29 20:41:47 +01:00
|
|
|
TRACE("(%p)->(%u %p %p %p %p)\n", This, table_tag, table_data, table_size, context, exists);
|
2014-08-17 03:42:24 +02:00
|
|
|
|
2014-10-29 20:41:47 +01:00
|
|
|
tablecontext = heap_alloc(sizeof(struct dwrite_fonttablecontext));
|
|
|
|
if (!tablecontext)
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
tablecontext->magic = DWRITE_FONTTABLE_MAGIC;
|
2014-08-17 03:42:24 +02:00
|
|
|
|
2014-10-29 20:41:47 +01:00
|
|
|
*exists = FALSE;
|
|
|
|
for (i = 0; i < This->file_count && !(*exists); i++) {
|
2014-11-05 21:30:32 +01:00
|
|
|
hr = opentype_get_font_table(This->streams[i], This->type, This->index, table_tag, table_data, &tablecontext->context, table_size, exists);
|
2014-10-29 20:41:47 +01:00
|
|
|
tablecontext->file_index = i;
|
2014-08-17 03:42:24 +02:00
|
|
|
}
|
2014-10-29 20:41:47 +01:00
|
|
|
if (FAILED(hr) && !*exists)
|
|
|
|
heap_free(tablecontext);
|
|
|
|
else
|
|
|
|
*context = (void*)tablecontext;
|
|
|
|
|
|
|
|
return hr;
|
2012-10-07 21:03:52 +02:00
|
|
|
}
|
|
|
|
|
2014-10-10 08:01:24 +02:00
|
|
|
static void WINAPI dwritefontface_ReleaseFontTable(IDWriteFontFace2 *iface, void *table_context)
|
2012-10-07 21:03:52 +02:00
|
|
|
{
|
2014-10-10 08:01:24 +02:00
|
|
|
struct dwrite_fontface *This = impl_from_IDWriteFontFace2(iface);
|
2014-10-06 14:26:31 +02:00
|
|
|
struct dwrite_fonttablecontext *tablecontext = (struct dwrite_fonttablecontext*)table_context;
|
2014-11-05 21:30:32 +01:00
|
|
|
|
2014-08-17 03:42:24 +02:00
|
|
|
TRACE("(%p)->(%p)\n", This, table_context);
|
|
|
|
|
2014-10-06 14:26:31 +02:00
|
|
|
if (tablecontext->magic != DWRITE_FONTTABLE_MAGIC)
|
2014-08-17 03:42:24 +02:00
|
|
|
{
|
|
|
|
TRACE("Invalid table magic\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-11-05 21:30:32 +01:00
|
|
|
IDWriteFontFileStream_ReleaseFileFragment(This->streams[tablecontext->file_index], tablecontext->context);
|
2014-10-06 14:26:31 +02:00
|
|
|
heap_free(tablecontext);
|
2012-10-07 21:03:52 +02:00
|
|
|
}
|
|
|
|
|
2014-10-10 08:01:24 +02:00
|
|
|
static HRESULT WINAPI dwritefontface_GetGlyphRunOutline(IDWriteFontFace2 *iface, FLOAT emSize,
|
2012-10-07 21:03:52 +02:00
|
|
|
UINT16 const *glyph_indices, FLOAT const* glyph_advances, DWRITE_GLYPH_OFFSET const *glyph_offsets,
|
|
|
|
UINT32 glyph_count, BOOL is_sideways, BOOL is_rtl, IDWriteGeometrySink *geometrysink)
|
|
|
|
{
|
2014-10-10 08:01:24 +02:00
|
|
|
struct dwrite_fontface *This = impl_from_IDWriteFontFace2(iface);
|
2012-10-07 21:03:52 +02:00
|
|
|
FIXME("(%p)->(%f %p %p %p %u %d %d %p): stub\n", This, emSize, glyph_indices, glyph_advances, glyph_offsets,
|
|
|
|
glyph_count, is_sideways, is_rtl, geometrysink);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
2014-10-10 08:01:24 +02:00
|
|
|
static HRESULT WINAPI dwritefontface_GetRecommendedRenderingMode(IDWriteFontFace2 *iface, FLOAT emSize,
|
2012-10-07 21:03:52 +02:00
|
|
|
FLOAT pixels_per_dip, DWRITE_MEASURING_MODE mode, IDWriteRenderingParams* params, DWRITE_RENDERING_MODE* rendering_mode)
|
|
|
|
{
|
2014-10-10 08:01:24 +02:00
|
|
|
struct dwrite_fontface *This = impl_from_IDWriteFontFace2(iface);
|
2012-10-07 21:03:52 +02:00
|
|
|
FIXME("(%p)->(%f %f %d %p %p): stub\n", This, emSize, pixels_per_dip, mode, params, rendering_mode);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
2014-10-10 08:01:24 +02:00
|
|
|
static HRESULT WINAPI dwritefontface_GetGdiCompatibleMetrics(IDWriteFontFace2 *iface, FLOAT emSize, FLOAT pixels_per_dip,
|
2012-10-07 21:03:52 +02:00
|
|
|
DWRITE_MATRIX const *transform, DWRITE_FONT_METRICS *metrics)
|
|
|
|
{
|
2014-10-10 08:01:24 +02:00
|
|
|
struct dwrite_fontface *This = impl_from_IDWriteFontFace2(iface);
|
2012-10-07 21:03:52 +02:00
|
|
|
FIXME("(%p)->(%f %f %p %p): stub\n", This, emSize, pixels_per_dip, transform, metrics);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
2014-10-10 08:01:24 +02:00
|
|
|
static HRESULT WINAPI dwritefontface_GetGdiCompatibleGlyphMetrics(IDWriteFontFace2 *iface, FLOAT emSize, FLOAT pixels_per_dip,
|
2012-10-07 21:03:52 +02:00
|
|
|
DWRITE_MATRIX const *transform, BOOL use_gdi_natural, UINT16 const *glyph_indices, UINT32 glyph_count,
|
|
|
|
DWRITE_GLYPH_METRICS *metrics, BOOL is_sideways)
|
|
|
|
{
|
2014-10-10 08:01:24 +02:00
|
|
|
struct dwrite_fontface *This = impl_from_IDWriteFontFace2(iface);
|
2012-10-07 21:03:52 +02:00
|
|
|
FIXME("(%p)->(%f %f %p %d %p %u %p %d): stub\n", This, emSize, pixels_per_dip, transform, use_gdi_natural, glyph_indices,
|
|
|
|
glyph_count, metrics, is_sideways);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
2014-10-10 08:01:24 +02:00
|
|
|
static HRESULT WINAPI dwritefontface1_GetMetrics(IDWriteFontFace2 *iface, DWRITE_FONT_METRICS1 *metrics)
|
|
|
|
{
|
|
|
|
struct dwrite_fontface *This = impl_from_IDWriteFontFace2(iface);
|
|
|
|
FIXME("(%p)->(%p): stub\n", This, metrics);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI dwritefontface1_GetGdiCompatibleMetrics(IDWriteFontFace2 *iface, FLOAT em_size, FLOAT pixels_per_dip,
|
|
|
|
const DWRITE_MATRIX *transform, DWRITE_FONT_METRICS1 *metrics)
|
|
|
|
{
|
|
|
|
struct dwrite_fontface *This = impl_from_IDWriteFontFace2(iface);
|
|
|
|
FIXME("(%p)->(%f %f %p %p): stub\n", This, em_size, pixels_per_dip, transform, metrics);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void WINAPI dwritefontface1_GetCaretMetrics(IDWriteFontFace2 *iface, DWRITE_CARET_METRICS *metrics)
|
|
|
|
{
|
|
|
|
struct dwrite_fontface *This = impl_from_IDWriteFontFace2(iface);
|
|
|
|
FIXME("(%p)->(%p): stub\n", This, metrics);
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI dwritefontface1_GetUnicodeRanges(IDWriteFontFace2 *iface, UINT32 max_count,
|
|
|
|
DWRITE_UNICODE_RANGE *ranges, UINT32 *count)
|
|
|
|
{
|
|
|
|
struct dwrite_fontface *This = impl_from_IDWriteFontFace2(iface);
|
2014-10-16 05:33:51 +02:00
|
|
|
|
|
|
|
TRACE("(%p)->(%u %p %p)\n", This, max_count, ranges, count);
|
|
|
|
|
|
|
|
*count = 0;
|
|
|
|
if (max_count && !ranges)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
|
|
|
return opentype_cmap_get_unicode_ranges(get_fontface_cmap(This), max_count, ranges, count);
|
2014-10-10 08:01:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL WINAPI dwritefontface1_IsMonospacedFont(IDWriteFontFace2 *iface)
|
|
|
|
{
|
|
|
|
struct dwrite_fontface *This = impl_from_IDWriteFontFace2(iface);
|
|
|
|
FIXME("(%p): stub\n", This);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI dwritefontface1_GetDesignGlyphAdvances(IDWriteFontFace2 *iface,
|
|
|
|
UINT32 glyph_count, UINT16 const *indices, INT32 *advances, BOOL is_sideways)
|
|
|
|
{
|
|
|
|
struct dwrite_fontface *This = impl_from_IDWriteFontFace2(iface);
|
|
|
|
FIXME("(%p)->(%u %p %p %d): stub\n", This, glyph_count, indices, advances, is_sideways);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI dwritefontface1_GetGdiCompatibleGlyphAdvances(IDWriteFontFace2 *iface,
|
|
|
|
FLOAT em_size, FLOAT pixels_per_dip, const DWRITE_MATRIX *transform, BOOL use_gdi_natural,
|
|
|
|
BOOL is_sideways, UINT32 glyph_count, UINT16 const *indices, INT32 *advances)
|
|
|
|
{
|
|
|
|
struct dwrite_fontface *This = impl_from_IDWriteFontFace2(iface);
|
|
|
|
FIXME("(%p)->(%f %f %p %d %d %u %p %p): stub\n", This, em_size, pixels_per_dip, transform,
|
|
|
|
use_gdi_natural, is_sideways, glyph_count, indices, advances);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI dwritefontface1_GetKerningPairAdjustments(IDWriteFontFace2 *iface, UINT32 glyph_count,
|
|
|
|
const UINT16 *indices, INT32 *adjustments)
|
|
|
|
{
|
|
|
|
struct dwrite_fontface *This = impl_from_IDWriteFontFace2(iface);
|
|
|
|
FIXME("(%p)->(%u %p %p): stub\n", This, glyph_count, indices, adjustments);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL WINAPI dwritefontface1_HasKerningPairs(IDWriteFontFace2 *iface)
|
|
|
|
{
|
|
|
|
struct dwrite_fontface *This = impl_from_IDWriteFontFace2(iface);
|
|
|
|
FIXME("(%p): stub\n", This);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI dwritefontface1_GetRecommendedRenderingMode(IDWriteFontFace2 *iface,
|
|
|
|
FLOAT font_emsize, FLOAT dpiX, FLOAT dpiY, const DWRITE_MATRIX *transform, BOOL is_sideways,
|
|
|
|
DWRITE_OUTLINE_THRESHOLD threshold, DWRITE_MEASURING_MODE measuring_mode, DWRITE_RENDERING_MODE *rendering_mode)
|
|
|
|
{
|
|
|
|
struct dwrite_fontface *This = impl_from_IDWriteFontFace2(iface);
|
|
|
|
FIXME("(%p)->(%f %f %f %p %d %d %d %p): stub\n", This, font_emsize, dpiX, dpiY, transform, is_sideways,
|
|
|
|
threshold, measuring_mode, rendering_mode);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI dwritefontface1_GetVerticalGlyphVariants(IDWriteFontFace2 *iface, UINT32 glyph_count,
|
|
|
|
const UINT16 *nominal_indices, UINT16 *vertical_indices)
|
|
|
|
{
|
|
|
|
struct dwrite_fontface *This = impl_from_IDWriteFontFace2(iface);
|
|
|
|
FIXME("(%p)->(%u %p %p): stub\n", This, glyph_count, nominal_indices, vertical_indices);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL WINAPI dwritefontface1_HasVerticalGlyphVariants(IDWriteFontFace2 *iface)
|
|
|
|
{
|
|
|
|
struct dwrite_fontface *This = impl_from_IDWriteFontFace2(iface);
|
|
|
|
FIXME("(%p): stub\n", This);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL WINAPI dwritefontface2_IsColorFont(IDWriteFontFace2 *iface)
|
|
|
|
{
|
|
|
|
struct dwrite_fontface *This = impl_from_IDWriteFontFace2(iface);
|
|
|
|
FIXME("(%p): stub\n", This);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static UINT32 WINAPI dwritefontface2_GetColorPaletteCount(IDWriteFontFace2 *iface)
|
|
|
|
{
|
|
|
|
struct dwrite_fontface *This = impl_from_IDWriteFontFace2(iface);
|
|
|
|
FIXME("(%p): stub\n", This);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static UINT32 WINAPI dwritefontface2_GetPaletteEntryCount(IDWriteFontFace2 *iface)
|
|
|
|
{
|
|
|
|
struct dwrite_fontface *This = impl_from_IDWriteFontFace2(iface);
|
|
|
|
FIXME("(%p): stub\n", This);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI dwritefontface2_GetPaletteEntries(IDWriteFontFace2 *iface, UINT32 palette_index,
|
|
|
|
UINT32 first_entry_index, UINT32 entry_count, DWRITE_COLOR_F *entries)
|
|
|
|
{
|
|
|
|
struct dwrite_fontface *This = impl_from_IDWriteFontFace2(iface);
|
|
|
|
FIXME("(%p)->(%u %u %u %p): stub\n", This, palette_index, first_entry_index, entry_count, entries);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI dwritefontface2_GetRecommendedRenderingMode(IDWriteFontFace2 *iface, FLOAT fontEmSize,
|
|
|
|
FLOAT dpiX, FLOAT dpiY, DWRITE_MATRIX const *transform, BOOL is_sideways, DWRITE_OUTLINE_THRESHOLD threshold,
|
|
|
|
DWRITE_MEASURING_MODE measuringmode, IDWriteRenderingParams *params, DWRITE_RENDERING_MODE *renderingmode,
|
|
|
|
DWRITE_GRID_FIT_MODE *gridfitmode)
|
|
|
|
{
|
|
|
|
struct dwrite_fontface *This = impl_from_IDWriteFontFace2(iface);
|
|
|
|
FIXME("(%p)->(%f %f %f %p %d %d %d %p %p %p): stub\n", This, fontEmSize, dpiX, dpiY, transform, is_sideways, threshold,
|
|
|
|
measuringmode, params, renderingmode, gridfitmode);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const IDWriteFontFace2Vtbl dwritefontfacevtbl = {
|
2012-10-07 21:03:52 +02:00
|
|
|
dwritefontface_QueryInterface,
|
|
|
|
dwritefontface_AddRef,
|
|
|
|
dwritefontface_Release,
|
|
|
|
dwritefontface_GetType,
|
|
|
|
dwritefontface_GetFiles,
|
|
|
|
dwritefontface_GetIndex,
|
|
|
|
dwritefontface_GetSimulations,
|
|
|
|
dwritefontface_IsSymbolFont,
|
|
|
|
dwritefontface_GetMetrics,
|
|
|
|
dwritefontface_GetGlyphCount,
|
|
|
|
dwritefontface_GetDesignGlyphMetrics,
|
|
|
|
dwritefontface_GetGlyphIndices,
|
|
|
|
dwritefontface_TryGetFontTable,
|
|
|
|
dwritefontface_ReleaseFontTable,
|
|
|
|
dwritefontface_GetGlyphRunOutline,
|
|
|
|
dwritefontface_GetRecommendedRenderingMode,
|
|
|
|
dwritefontface_GetGdiCompatibleMetrics,
|
2014-10-10 08:01:24 +02:00
|
|
|
dwritefontface_GetGdiCompatibleGlyphMetrics,
|
|
|
|
dwritefontface1_GetMetrics,
|
|
|
|
dwritefontface1_GetGdiCompatibleMetrics,
|
|
|
|
dwritefontface1_GetCaretMetrics,
|
|
|
|
dwritefontface1_GetUnicodeRanges,
|
|
|
|
dwritefontface1_IsMonospacedFont,
|
|
|
|
dwritefontface1_GetDesignGlyphAdvances,
|
|
|
|
dwritefontface1_GetGdiCompatibleGlyphAdvances,
|
|
|
|
dwritefontface1_GetKerningPairAdjustments,
|
|
|
|
dwritefontface1_HasKerningPairs,
|
|
|
|
dwritefontface1_GetRecommendedRenderingMode,
|
|
|
|
dwritefontface1_GetVerticalGlyphVariants,
|
|
|
|
dwritefontface1_HasVerticalGlyphVariants,
|
|
|
|
dwritefontface2_IsColorFont,
|
|
|
|
dwritefontface2_GetColorPaletteCount,
|
|
|
|
dwritefontface2_GetPaletteEntryCount,
|
|
|
|
dwritefontface2_GetPaletteEntries,
|
|
|
|
dwritefontface2_GetRecommendedRenderingMode
|
2012-10-07 21:03:52 +02:00
|
|
|
};
|
|
|
|
|
2014-10-28 06:13:51 +01:00
|
|
|
static void get_font_properties_from_stream(IDWriteFontFileStream *stream, DWRITE_FONT_FACE_TYPE face_type,
|
|
|
|
UINT32 face_index, DWRITE_FONT_METRICS *metrics, DWRITE_FONT_STRETCH *stretch, DWRITE_FONT_WEIGHT *weight,
|
|
|
|
DWRITE_FONT_STYLE *style)
|
|
|
|
{
|
|
|
|
const void *tt_os2 = NULL, *tt_head = NULL, *tt_post = NULL;
|
|
|
|
void *os2_context, *head_context, *post_context;
|
|
|
|
|
|
|
|
opentype_get_font_table(stream, face_type, face_index, MS_OS2_TAG, &tt_os2, &os2_context, NULL, NULL);
|
|
|
|
opentype_get_font_table(stream, face_type, face_index, MS_HEAD_TAG, &tt_head, &head_context, NULL, NULL);
|
|
|
|
opentype_get_font_table(stream, face_type, face_index, MS_POST_TAG, &tt_post, &post_context, NULL, NULL);
|
|
|
|
|
2014-11-05 21:03:32 +01:00
|
|
|
opentype_get_font_properties(tt_os2, tt_head, stretch, weight, style);
|
|
|
|
opentype_get_font_metrics(tt_os2, tt_head, tt_post, metrics);
|
2014-10-28 06:13:51 +01:00
|
|
|
|
|
|
|
if (tt_os2)
|
|
|
|
IDWriteFontFileStream_ReleaseFileFragment(stream, os2_context);
|
|
|
|
if (tt_head)
|
|
|
|
IDWriteFontFileStream_ReleaseFileFragment(stream, head_context);
|
|
|
|
if (tt_post)
|
|
|
|
IDWriteFontFileStream_ReleaseFileFragment(stream, post_context);
|
|
|
|
}
|
|
|
|
|
2014-01-05 22:24:17 +01:00
|
|
|
HRESULT convert_fontface_to_logfont(IDWriteFontFace *face, LOGFONTW *logfont)
|
|
|
|
{
|
2014-10-28 06:13:51 +01:00
|
|
|
DWRITE_FONT_SIMULATIONS simulations;
|
|
|
|
DWRITE_FONT_FACE_TYPE face_type;
|
|
|
|
IDWriteFontFileStream *stream;
|
|
|
|
DWRITE_FONT_METRICS metrics;
|
|
|
|
DWRITE_FONT_STRETCH stretch;
|
|
|
|
DWRITE_FONT_STYLE style;
|
|
|
|
DWRITE_FONT_WEIGHT weight;
|
|
|
|
IDWriteFontFile *file = NULL;
|
|
|
|
UINT32 index;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
memset(logfont, 0, sizeof(*logfont));
|
|
|
|
|
|
|
|
index = 1;
|
|
|
|
hr = IDWriteFontFace_GetFiles(face, &index, &file);
|
|
|
|
if (FAILED(hr) || !file)
|
|
|
|
return hr;
|
|
|
|
|
|
|
|
hr = get_filestream_from_file(file, &stream);
|
|
|
|
if (FAILED(hr)) {
|
|
|
|
IDWriteFontFile_Release(file);
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
index = IDWriteFontFace_GetIndex(face);
|
|
|
|
face_type = IDWriteFontFace_GetType(face);
|
|
|
|
get_font_properties_from_stream(stream, face_type, index, &metrics, &stretch, &weight, &style);
|
|
|
|
IDWriteFontFileStream_Release(stream);
|
|
|
|
|
|
|
|
simulations = IDWriteFontFace_GetSimulations(face);
|
2014-01-05 22:24:17 +01:00
|
|
|
|
2014-10-28 06:13:51 +01:00
|
|
|
logfont->lfCharSet = DEFAULT_CHARSET;
|
|
|
|
logfont->lfWeight = weight;
|
2014-11-04 16:31:31 +01:00
|
|
|
logfont->lfItalic = style == DWRITE_FONT_STYLE_ITALIC || (simulations & DWRITE_FONT_SIMULATIONS_OBLIQUE);
|
2014-10-28 06:13:51 +01:00
|
|
|
logfont->lfOutPrecision = OUT_OUTLINE_PRECIS;
|
|
|
|
/* TODO: set facename */
|
2014-01-05 22:24:17 +01:00
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2014-10-16 07:47:43 +02:00
|
|
|
static HRESULT get_fontface_from_font(struct dwrite_font *font, IDWriteFontFace2 **fontface)
|
2014-10-16 07:36:13 +02:00
|
|
|
{
|
2014-11-05 10:48:45 +01:00
|
|
|
struct dwrite_font_data *data = font->data;
|
|
|
|
IDWriteFontFace *face;
|
|
|
|
HRESULT hr;
|
2014-10-24 09:43:21 +02:00
|
|
|
|
2014-10-16 07:36:13 +02:00
|
|
|
*fontface = NULL;
|
|
|
|
|
2014-11-05 10:48:45 +01:00
|
|
|
hr = IDWriteFactory_CreateFontFace(data->factory, data->face_type, 1, &data->file,
|
|
|
|
data->face_index, font->simulations, &face);
|
|
|
|
if (FAILED(hr))
|
|
|
|
return hr;
|
2014-10-24 09:43:21 +02:00
|
|
|
|
2014-11-05 10:48:45 +01:00
|
|
|
hr = IDWriteFontFace_QueryInterface(face, &IID_IDWriteFontFace2, (void**)fontface);
|
|
|
|
IDWriteFontFace_Release(face);
|
2014-10-16 07:36:13 +02:00
|
|
|
|
2014-10-24 09:43:21 +02:00
|
|
|
return hr;
|
2014-10-16 07:36:13 +02:00
|
|
|
}
|
|
|
|
|
2014-10-10 07:28:58 +02:00
|
|
|
static HRESULT WINAPI dwritefont_QueryInterface(IDWriteFont2 *iface, REFIID riid, void **obj)
|
2012-08-13 05:44:19 +02:00
|
|
|
{
|
2014-10-10 07:28:58 +02:00
|
|
|
struct dwrite_font *This = impl_from_IDWriteFont2(iface);
|
2012-08-13 05:44:19 +02:00
|
|
|
|
|
|
|
TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), obj);
|
|
|
|
|
2014-10-10 07:28:58 +02:00
|
|
|
if (IsEqualIID(riid, &IID_IDWriteFont2) ||
|
|
|
|
IsEqualIID(riid, &IID_IDWriteFont1) ||
|
|
|
|
IsEqualIID(riid, &IID_IDWriteFont) ||
|
|
|
|
IsEqualIID(riid, &IID_IUnknown))
|
2012-08-13 05:44:19 +02:00
|
|
|
{
|
|
|
|
*obj = iface;
|
2014-10-10 07:28:58 +02:00
|
|
|
IDWriteFont2_AddRef(iface);
|
2012-08-13 05:44:19 +02:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
*obj = NULL;
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
2014-10-10 07:28:58 +02:00
|
|
|
static ULONG WINAPI dwritefont_AddRef(IDWriteFont2 *iface)
|
2012-08-13 05:44:19 +02:00
|
|
|
{
|
2014-10-10 07:28:58 +02:00
|
|
|
struct dwrite_font *This = impl_from_IDWriteFont2(iface);
|
2012-08-13 05:44:19 +02:00
|
|
|
ULONG ref = InterlockedIncrement(&This->ref);
|
|
|
|
TRACE("(%p)->(%d)\n", This, ref);
|
|
|
|
return ref;
|
|
|
|
}
|
|
|
|
|
2014-10-10 07:28:58 +02:00
|
|
|
static ULONG WINAPI dwritefont_Release(IDWriteFont2 *iface)
|
2012-08-13 05:44:19 +02:00
|
|
|
{
|
2014-10-10 07:28:58 +02:00
|
|
|
struct dwrite_font *This = impl_from_IDWriteFont2(iface);
|
2012-08-13 05:44:19 +02:00
|
|
|
ULONG ref = InterlockedDecrement(&This->ref);
|
|
|
|
|
|
|
|
TRACE("(%p)->(%d)\n", This, ref);
|
|
|
|
|
2014-10-24 09:43:21 +02:00
|
|
|
if (!ref) {
|
2014-11-04 14:37:10 +01:00
|
|
|
IDWriteFontFamily_Release(This->family);
|
2014-10-24 09:43:21 +02:00
|
|
|
release_font_data(This->data);
|
2012-08-13 05:44:19 +02:00
|
|
|
heap_free(This);
|
2012-08-25 11:11:31 +02:00
|
|
|
}
|
2012-08-13 05:44:19 +02:00
|
|
|
|
2012-10-21 03:47:22 +02:00
|
|
|
return ref;
|
2012-08-13 05:44:19 +02:00
|
|
|
}
|
|
|
|
|
2014-10-10 07:28:58 +02:00
|
|
|
static HRESULT WINAPI dwritefont_GetFontFamily(IDWriteFont2 *iface, IDWriteFontFamily **family)
|
2012-08-13 05:44:19 +02:00
|
|
|
{
|
2014-10-10 07:28:58 +02:00
|
|
|
struct dwrite_font *This = impl_from_IDWriteFont2(iface);
|
2012-08-25 11:11:31 +02:00
|
|
|
TRACE("(%p)->(%p)\n", This, family);
|
|
|
|
|
|
|
|
*family = This->family;
|
|
|
|
IDWriteFontFamily_AddRef(*family);
|
|
|
|
return S_OK;
|
2012-08-13 05:44:19 +02:00
|
|
|
}
|
|
|
|
|
2014-10-10 07:28:58 +02:00
|
|
|
static DWRITE_FONT_WEIGHT WINAPI dwritefont_GetWeight(IDWriteFont2 *iface)
|
2012-08-13 05:44:19 +02:00
|
|
|
{
|
2014-10-10 07:28:58 +02:00
|
|
|
struct dwrite_font *This = impl_from_IDWriteFont2(iface);
|
2012-10-12 14:43:57 +02:00
|
|
|
TRACE("(%p)\n", This);
|
2014-09-02 17:19:25 +02:00
|
|
|
return This->data->weight;
|
2012-08-13 05:44:19 +02:00
|
|
|
}
|
|
|
|
|
2014-10-10 07:28:58 +02:00
|
|
|
static DWRITE_FONT_STRETCH WINAPI dwritefont_GetStretch(IDWriteFont2 *iface)
|
2012-08-13 05:44:19 +02:00
|
|
|
{
|
2014-10-10 07:28:58 +02:00
|
|
|
struct dwrite_font *This = impl_from_IDWriteFont2(iface);
|
2012-10-10 14:37:55 +02:00
|
|
|
TRACE("(%p)\n", This);
|
2014-09-02 17:19:25 +02:00
|
|
|
return This->data->stretch;
|
2012-08-13 05:44:19 +02:00
|
|
|
}
|
|
|
|
|
2014-10-10 07:28:58 +02:00
|
|
|
static DWRITE_FONT_STYLE WINAPI dwritefont_GetStyle(IDWriteFont2 *iface)
|
2012-08-13 05:44:19 +02:00
|
|
|
{
|
2014-10-10 07:28:58 +02:00
|
|
|
struct dwrite_font *This = impl_from_IDWriteFont2(iface);
|
2012-08-13 05:46:43 +02:00
|
|
|
TRACE("(%p)\n", This);
|
2014-09-02 17:19:25 +02:00
|
|
|
return This->data->style;
|
2012-08-13 05:44:19 +02:00
|
|
|
}
|
|
|
|
|
2014-10-10 07:28:58 +02:00
|
|
|
static BOOL WINAPI dwritefont_IsSymbolFont(IDWriteFont2 *iface)
|
2012-08-13 05:44:19 +02:00
|
|
|
{
|
2014-10-10 07:28:58 +02:00
|
|
|
struct dwrite_font *This = impl_from_IDWriteFont2(iface);
|
2012-08-13 05:44:19 +02:00
|
|
|
FIXME("(%p): stub\n", This);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2014-10-10 07:28:58 +02:00
|
|
|
static HRESULT WINAPI dwritefont_GetFaceNames(IDWriteFont2 *iface, IDWriteLocalizedStrings **names)
|
2012-08-13 05:44:19 +02:00
|
|
|
{
|
2014-11-04 20:53:19 +01:00
|
|
|
static const WCHAR boldobliqueW[] = {'B','o','l','d',' ','O','b','l','i','q','u','e',0};
|
|
|
|
static const WCHAR obliqueW[] = {'O','b','l','i','q','u','e',0};
|
|
|
|
static const WCHAR boldW[] = {'B','o','l','d',0};
|
|
|
|
static const WCHAR enusW[] = {'e','n','-','u','s',0};
|
|
|
|
|
2014-10-10 07:28:58 +02:00
|
|
|
struct dwrite_font *This = impl_from_IDWriteFont2(iface);
|
2014-11-04 20:53:19 +01:00
|
|
|
IDWriteLocalizedStrings *strings;
|
|
|
|
const WCHAR *name;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
TRACE("(%p)->(%p)\n", This, names);
|
|
|
|
|
|
|
|
*names = NULL;
|
|
|
|
|
|
|
|
if (This->simulations == DWRITE_FONT_SIMULATIONS_NONE) {
|
|
|
|
BOOL exists;
|
|
|
|
return IDWriteFont2_GetInformationalStrings(iface, DWRITE_INFORMATIONAL_STRING_WIN32_SUBFAMILY_NAMES,
|
|
|
|
names, &exists);
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (This->simulations) {
|
|
|
|
case DWRITE_FONT_SIMULATIONS_BOLD|DWRITE_FONT_SIMULATIONS_OBLIQUE:
|
|
|
|
name = boldobliqueW;
|
|
|
|
break;
|
|
|
|
case DWRITE_FONT_SIMULATIONS_BOLD:
|
|
|
|
name = boldW;
|
|
|
|
break;
|
|
|
|
case DWRITE_FONT_SIMULATIONS_OBLIQUE:
|
|
|
|
name = obliqueW;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
ERR("unknown simulations %d\n", This->simulations);
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
hr = create_localizedstrings(&strings);
|
|
|
|
if (FAILED(hr)) return hr;
|
|
|
|
|
|
|
|
hr = add_localizedstring(strings, enusW, name);
|
|
|
|
if (FAILED(hr)) {
|
|
|
|
IDWriteLocalizedStrings_Release(strings);
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
*names = strings;
|
|
|
|
|
|
|
|
return S_OK;
|
2012-08-13 05:44:19 +02:00
|
|
|
}
|
|
|
|
|
2014-10-10 07:28:58 +02:00
|
|
|
static HRESULT WINAPI dwritefont_GetInformationalStrings(IDWriteFont2 *iface,
|
2012-08-13 05:44:19 +02:00
|
|
|
DWRITE_INFORMATIONAL_STRING_ID stringid, IDWriteLocalizedStrings **strings, BOOL *exists)
|
|
|
|
{
|
2014-10-10 07:28:58 +02:00
|
|
|
struct dwrite_font *This = impl_from_IDWriteFont2(iface);
|
2014-10-20 19:45:57 +02:00
|
|
|
struct dwrite_font_data *data = This->data;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
TRACE("(%p)->(%d %p %p)\n", This, stringid, strings, exists);
|
|
|
|
|
|
|
|
*exists = FALSE;
|
|
|
|
*strings = NULL;
|
|
|
|
|
|
|
|
if (stringid > DWRITE_INFORMATIONAL_STRING_POSTSCRIPT_CID_NAME || stringid == DWRITE_INFORMATIONAL_STRING_NONE)
|
|
|
|
return S_OK;
|
|
|
|
|
|
|
|
if (!data->info_strings[stringid]) {
|
|
|
|
IDWriteFontFace2 *fontface;
|
2014-10-24 09:42:35 +02:00
|
|
|
const void *table_data;
|
|
|
|
BOOL table_exists;
|
|
|
|
void *context;
|
|
|
|
UINT32 size;
|
2014-10-20 19:45:57 +02:00
|
|
|
|
|
|
|
hr = get_fontface_from_font(This, &fontface);
|
|
|
|
if (FAILED(hr))
|
|
|
|
return hr;
|
|
|
|
|
2014-10-24 09:42:35 +02:00
|
|
|
table_exists = FALSE;
|
|
|
|
hr = IDWriteFontFace2_TryGetFontTable(fontface, MS_NAME_TAG, &table_data, &size, &context, &table_exists);
|
|
|
|
if (FAILED(hr) || !table_exists)
|
|
|
|
WARN("no NAME table found.\n");
|
|
|
|
|
|
|
|
if (table_exists) {
|
|
|
|
hr = opentype_get_font_strings_from_id(table_data, stringid, &data->info_strings[stringid]);
|
|
|
|
if (FAILED(hr) || !data->info_strings[stringid])
|
|
|
|
return hr;
|
|
|
|
IDWriteFontFace2_ReleaseFontTable(fontface, context);
|
|
|
|
}
|
2014-10-20 19:45:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
hr = clone_localizedstring(data->info_strings[stringid], strings);
|
|
|
|
if (FAILED(hr))
|
|
|
|
return hr;
|
|
|
|
|
|
|
|
*exists = TRUE;
|
2014-10-24 09:42:35 +02:00
|
|
|
return S_OK;
|
2012-08-13 05:44:19 +02:00
|
|
|
}
|
|
|
|
|
2014-10-10 07:28:58 +02:00
|
|
|
static DWRITE_FONT_SIMULATIONS WINAPI dwritefont_GetSimulations(IDWriteFont2 *iface)
|
2012-08-13 05:44:19 +02:00
|
|
|
{
|
2014-10-10 07:28:58 +02:00
|
|
|
struct dwrite_font *This = impl_from_IDWriteFont2(iface);
|
2014-09-02 17:19:25 +02:00
|
|
|
TRACE("(%p)\n", This);
|
2014-10-27 15:37:49 +01:00
|
|
|
return This->simulations;
|
2012-08-13 05:44:19 +02:00
|
|
|
}
|
|
|
|
|
2014-10-10 07:28:58 +02:00
|
|
|
static void WINAPI dwritefont_GetMetrics(IDWriteFont2 *iface, DWRITE_FONT_METRICS *metrics)
|
2012-08-13 05:44:19 +02:00
|
|
|
{
|
2014-10-10 07:28:58 +02:00
|
|
|
struct dwrite_font *This = impl_from_IDWriteFont2(iface);
|
2012-10-16 18:56:23 +02:00
|
|
|
|
|
|
|
TRACE("(%p)->(%p)\n", This, metrics);
|
2014-09-02 17:19:25 +02:00
|
|
|
*metrics = This->data->metrics;
|
2012-08-13 05:44:19 +02:00
|
|
|
}
|
|
|
|
|
2014-10-10 07:28:58 +02:00
|
|
|
static HRESULT WINAPI dwritefont_HasCharacter(IDWriteFont2 *iface, UINT32 value, BOOL *exists)
|
2012-08-13 05:44:19 +02:00
|
|
|
{
|
2014-10-10 07:28:58 +02:00
|
|
|
struct dwrite_font *This = impl_from_IDWriteFont2(iface);
|
2014-10-16 07:47:43 +02:00
|
|
|
IDWriteFontFace2 *fontface;
|
2014-10-16 05:30:40 +02:00
|
|
|
UINT16 index;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
TRACE("(%p)->(0x%08x %p)\n", This, value, exists);
|
|
|
|
|
|
|
|
*exists = FALSE;
|
|
|
|
|
2014-10-16 07:36:13 +02:00
|
|
|
hr = get_fontface_from_font(This, &fontface);
|
2014-10-16 05:30:40 +02:00
|
|
|
if (FAILED(hr))
|
|
|
|
return hr;
|
|
|
|
|
|
|
|
index = 0;
|
2014-10-16 07:47:43 +02:00
|
|
|
hr = IDWriteFontFace2_GetGlyphIndices(fontface, &value, 1, &index);
|
2014-10-16 05:30:40 +02:00
|
|
|
if (FAILED(hr))
|
|
|
|
return hr;
|
|
|
|
|
|
|
|
*exists = index != 0;
|
|
|
|
return S_OK;
|
2012-08-13 05:44:19 +02:00
|
|
|
}
|
|
|
|
|
2014-10-10 07:28:58 +02:00
|
|
|
static HRESULT WINAPI dwritefont_CreateFontFace(IDWriteFont2 *iface, IDWriteFontFace **face)
|
2012-08-13 05:44:19 +02:00
|
|
|
{
|
2014-10-10 07:28:58 +02:00
|
|
|
struct dwrite_font *This = impl_from_IDWriteFont2(iface);
|
2014-10-16 07:36:13 +02:00
|
|
|
HRESULT hr;
|
2012-10-07 21:03:52 +02:00
|
|
|
|
2014-10-16 07:36:13 +02:00
|
|
|
TRACE("(%p)->(%p)\n", This, face);
|
2014-09-02 17:19:36 +02:00
|
|
|
|
2014-10-16 07:47:43 +02:00
|
|
|
hr = get_fontface_from_font(This, (IDWriteFontFace2**)face);
|
2014-10-16 07:36:13 +02:00
|
|
|
if (hr == S_OK)
|
2014-09-02 17:19:36 +02:00
|
|
|
IDWriteFontFace_AddRef(*face);
|
|
|
|
|
2014-10-16 07:36:13 +02:00
|
|
|
return hr;
|
2012-08-13 05:44:19 +02:00
|
|
|
}
|
|
|
|
|
2014-10-10 07:28:58 +02:00
|
|
|
static void WINAPI dwritefont1_GetMetrics(IDWriteFont2 *iface, DWRITE_FONT_METRICS1 *metrics)
|
|
|
|
{
|
|
|
|
struct dwrite_font *This = impl_from_IDWriteFont2(iface);
|
|
|
|
FIXME("(%p)->(%p): stub\n", This, metrics);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void WINAPI dwritefont1_GetPanose(IDWriteFont2 *iface, DWRITE_PANOSE *panose)
|
|
|
|
{
|
|
|
|
struct dwrite_font *This = impl_from_IDWriteFont2(iface);
|
|
|
|
FIXME("(%p)->(%p): stub\n", This, panose);
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI dwritefont1_GetUnicodeRanges(IDWriteFont2 *iface, UINT32 max_count, DWRITE_UNICODE_RANGE *ranges, UINT32 *count)
|
|
|
|
{
|
|
|
|
struct dwrite_font *This = impl_from_IDWriteFont2(iface);
|
2014-10-16 07:47:43 +02:00
|
|
|
IDWriteFontFace2 *fontface;
|
2014-10-16 05:33:51 +02:00
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
TRACE("(%p)->(%u %p %p)\n", This, max_count, ranges, count);
|
|
|
|
|
2014-10-16 07:36:13 +02:00
|
|
|
hr = get_fontface_from_font(This, &fontface);
|
2014-10-16 05:33:51 +02:00
|
|
|
if (FAILED(hr))
|
|
|
|
return hr;
|
|
|
|
|
2014-10-16 07:47:43 +02:00
|
|
|
return IDWriteFontFace2_GetUnicodeRanges(fontface, max_count, ranges, count);
|
2014-10-10 07:28:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI dwritefont1_IsMonospacedFont(IDWriteFont2 *iface)
|
|
|
|
{
|
|
|
|
struct dwrite_font *This = impl_from_IDWriteFont2(iface);
|
|
|
|
FIXME("(%p): stub\n", This);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI dwritefont2_IsColorFont(IDWriteFont2 *iface)
|
|
|
|
{
|
|
|
|
struct dwrite_font *This = impl_from_IDWriteFont2(iface);
|
|
|
|
FIXME("(%p): stub\n", This);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const IDWriteFont2Vtbl dwritefontvtbl = {
|
2012-08-13 05:44:19 +02:00
|
|
|
dwritefont_QueryInterface,
|
|
|
|
dwritefont_AddRef,
|
|
|
|
dwritefont_Release,
|
|
|
|
dwritefont_GetFontFamily,
|
|
|
|
dwritefont_GetWeight,
|
|
|
|
dwritefont_GetStretch,
|
|
|
|
dwritefont_GetStyle,
|
|
|
|
dwritefont_IsSymbolFont,
|
|
|
|
dwritefont_GetFaceNames,
|
|
|
|
dwritefont_GetInformationalStrings,
|
|
|
|
dwritefont_GetSimulations,
|
|
|
|
dwritefont_GetMetrics,
|
|
|
|
dwritefont_HasCharacter,
|
2014-10-10 07:28:58 +02:00
|
|
|
dwritefont_CreateFontFace,
|
|
|
|
dwritefont1_GetMetrics,
|
|
|
|
dwritefont1_GetPanose,
|
|
|
|
dwritefont1_GetUnicodeRanges,
|
|
|
|
dwritefont1_IsMonospacedFont,
|
|
|
|
dwritefont2_IsColorFont
|
2012-08-13 05:44:19 +02:00
|
|
|
};
|
|
|
|
|
2014-11-04 14:37:10 +01:00
|
|
|
static HRESULT create_font(struct dwrite_font_data *data, IDWriteFontFamily *family, DWRITE_FONT_SIMULATIONS simulations,
|
|
|
|
IDWriteFont **font)
|
|
|
|
{
|
|
|
|
struct dwrite_font *This;
|
|
|
|
*font = NULL;
|
|
|
|
|
|
|
|
This = heap_alloc(sizeof(struct dwrite_font));
|
|
|
|
if (!This) return E_OUTOFMEMORY;
|
|
|
|
|
|
|
|
This->IDWriteFont2_iface.lpVtbl = &dwritefontvtbl;
|
|
|
|
This->ref = 1;
|
|
|
|
This->family = family;
|
|
|
|
IDWriteFontFamily_AddRef(family);
|
|
|
|
This->simulations = simulations;
|
|
|
|
This->data = data;
|
|
|
|
InterlockedIncrement(&This->data->ref);
|
|
|
|
|
|
|
|
*font = (IDWriteFont*)&This->IDWriteFont2_iface;
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2012-08-25 11:11:31 +02:00
|
|
|
static HRESULT WINAPI dwritefontfamily_QueryInterface(IDWriteFontFamily *iface, REFIID riid, void **obj)
|
|
|
|
{
|
|
|
|
struct dwrite_fontfamily *This = impl_from_IDWriteFontFamily(iface);
|
|
|
|
TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), obj);
|
|
|
|
|
|
|
|
if (IsEqualIID(riid, &IID_IUnknown) ||
|
|
|
|
IsEqualIID(riid, &IID_IDWriteFontList) ||
|
|
|
|
IsEqualIID(riid, &IID_IDWriteFontFamily))
|
|
|
|
{
|
|
|
|
*obj = iface;
|
|
|
|
IDWriteFontFamily_AddRef(iface);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
*obj = NULL;
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI dwritefontfamily_AddRef(IDWriteFontFamily *iface)
|
|
|
|
{
|
|
|
|
struct dwrite_fontfamily *This = impl_from_IDWriteFontFamily(iface);
|
|
|
|
ULONG ref = InterlockedIncrement(&This->ref);
|
|
|
|
TRACE("(%p)->(%d)\n", This, ref);
|
|
|
|
return ref;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI dwritefontfamily_Release(IDWriteFontFamily *iface)
|
|
|
|
{
|
|
|
|
struct dwrite_fontfamily *This = impl_from_IDWriteFontFamily(iface);
|
|
|
|
ULONG ref = InterlockedDecrement(&This->ref);
|
|
|
|
|
|
|
|
TRACE("(%p)->(%d)\n", This, ref);
|
|
|
|
|
|
|
|
if (!ref)
|
2012-10-07 18:29:39 +02:00
|
|
|
{
|
2014-11-04 14:37:10 +01:00
|
|
|
IDWriteFontCollection_Release(This->collection);
|
2014-10-08 16:52:07 +02:00
|
|
|
_free_fontfamily_data(This->data);
|
2012-08-25 11:11:31 +02:00
|
|
|
heap_free(This);
|
2012-10-07 18:29:39 +02:00
|
|
|
}
|
2012-08-25 11:11:31 +02:00
|
|
|
|
2012-10-21 03:47:22 +02:00
|
|
|
return ref;
|
2012-08-25 11:11:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI dwritefontfamily_GetFontCollection(IDWriteFontFamily *iface, IDWriteFontCollection **collection)
|
|
|
|
{
|
|
|
|
struct dwrite_fontfamily *This = impl_from_IDWriteFontFamily(iface);
|
2014-09-03 14:27:17 +02:00
|
|
|
TRACE("(%p)->(%p)\n", This, collection);
|
2014-10-29 20:41:47 +01:00
|
|
|
|
|
|
|
*collection = This->collection;
|
|
|
|
IDWriteFontCollection_AddRef(This->collection);
|
|
|
|
return S_OK;
|
2012-08-25 11:11:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static UINT32 WINAPI dwritefontfamily_GetFontCount(IDWriteFontFamily *iface)
|
|
|
|
{
|
|
|
|
struct dwrite_fontfamily *This = impl_from_IDWriteFontFamily(iface);
|
2014-09-03 20:11:35 +02:00
|
|
|
TRACE("(%p)\n", This);
|
2014-09-09 02:10:48 +02:00
|
|
|
return This->data->font_count;
|
2012-08-25 11:11:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI dwritefontfamily_GetFont(IDWriteFontFamily *iface, UINT32 index, IDWriteFont **font)
|
|
|
|
{
|
|
|
|
struct dwrite_fontfamily *This = impl_from_IDWriteFontFamily(iface);
|
2014-10-29 20:41:47 +01:00
|
|
|
|
2014-09-03 20:11:35 +02:00
|
|
|
TRACE("(%p)->(%u %p)\n", This, index, font);
|
2014-10-29 20:41:47 +01:00
|
|
|
|
|
|
|
*font = NULL;
|
|
|
|
|
|
|
|
if (This->data->font_count == 0)
|
|
|
|
return S_FALSE;
|
|
|
|
|
|
|
|
if (index >= This->data->font_count)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
2014-11-04 14:37:10 +01:00
|
|
|
return create_font(This->data->fonts[index], iface, DWRITE_FONT_SIMULATIONS_NONE, font);
|
2012-08-25 11:11:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI dwritefontfamily_GetFamilyNames(IDWriteFontFamily *iface, IDWriteLocalizedStrings **names)
|
|
|
|
{
|
|
|
|
struct dwrite_fontfamily *This = impl_from_IDWriteFontFamily(iface);
|
2014-09-09 02:10:48 +02:00
|
|
|
return clone_localizedstring(This->data->familyname, names);
|
2012-08-25 11:11:31 +02:00
|
|
|
}
|
|
|
|
|
2014-10-27 17:01:48 +01:00
|
|
|
static inline BOOL is_matching_font_style(DWRITE_FONT_STYLE style, DWRITE_FONT_STYLE font_style)
|
|
|
|
{
|
|
|
|
if (style == font_style)
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
if (((style == DWRITE_FONT_STYLE_ITALIC) || (style == DWRITE_FONT_STYLE_OBLIQUE)) && font_style == DWRITE_FONT_STYLE_NORMAL)
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2012-08-25 11:11:31 +02:00
|
|
|
static HRESULT WINAPI dwritefontfamily_GetFirstMatchingFont(IDWriteFontFamily *iface, DWRITE_FONT_WEIGHT weight,
|
|
|
|
DWRITE_FONT_STRETCH stretch, DWRITE_FONT_STYLE style, IDWriteFont **font)
|
|
|
|
{
|
|
|
|
struct dwrite_fontfamily *This = impl_from_IDWriteFontFamily(iface);
|
2014-10-29 20:41:47 +01:00
|
|
|
UINT32 min_weight_diff = ~0u;
|
|
|
|
int found = -1, i;
|
2012-10-23 14:18:32 +02:00
|
|
|
|
|
|
|
TRACE("(%p)->(%d %d %d %p)\n", This, weight, stretch, style, font);
|
|
|
|
|
2014-10-29 20:41:47 +01:00
|
|
|
for (i = 0; i < This->data->font_count; i++) {
|
|
|
|
if (is_matching_font_style(style, This->data->fonts[i]->style) && stretch == This->data->fonts[i]->stretch) {
|
|
|
|
DWRITE_FONT_WEIGHT font_weight = This->data->fonts[i]->weight;
|
|
|
|
UINT32 weight_diff = abs(font_weight - weight);
|
|
|
|
if (weight_diff < min_weight_diff) {
|
|
|
|
min_weight_diff = weight_diff;
|
|
|
|
found = i;
|
2014-09-03 20:11:35 +02:00
|
|
|
}
|
|
|
|
}
|
2014-10-29 20:41:47 +01:00
|
|
|
}
|
2014-10-27 12:53:59 +01:00
|
|
|
|
2014-10-29 20:41:47 +01:00
|
|
|
if (found != -1) {
|
|
|
|
DWRITE_FONT_SIMULATIONS simulations = DWRITE_FONT_SIMULATIONS_NONE;
|
2014-10-27 17:01:48 +01:00
|
|
|
|
2014-10-29 20:41:47 +01:00
|
|
|
if (((style == DWRITE_FONT_STYLE_ITALIC) || (style == DWRITE_FONT_STYLE_OBLIQUE)) &&
|
2014-11-04 16:31:31 +01:00
|
|
|
This->data->fonts[found]->style == DWRITE_FONT_STYLE_NORMAL) {
|
2014-10-29 20:41:47 +01:00
|
|
|
simulations = DWRITE_FONT_SIMULATIONS_OBLIQUE;
|
2014-10-27 17:01:48 +01:00
|
|
|
}
|
2014-11-04 14:37:10 +01:00
|
|
|
return create_font(This->data->fonts[found], iface, simulations, font);
|
2014-10-29 20:41:47 +01:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
*font = NULL;
|
|
|
|
return DWRITE_E_NOFONT;
|
2014-09-03 20:11:35 +02:00
|
|
|
}
|
2012-08-25 11:11:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI dwritefontfamily_GetMatchingFonts(IDWriteFontFamily *iface, DWRITE_FONT_WEIGHT weight,
|
|
|
|
DWRITE_FONT_STRETCH stretch, DWRITE_FONT_STYLE style, IDWriteFontList **fonts)
|
|
|
|
{
|
|
|
|
struct dwrite_fontfamily *This = impl_from_IDWriteFontFamily(iface);
|
|
|
|
FIXME("(%p)->(%d %d %d %p): stub\n", This, weight, stretch, style, fonts);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const IDWriteFontFamilyVtbl fontfamilyvtbl = {
|
|
|
|
dwritefontfamily_QueryInterface,
|
|
|
|
dwritefontfamily_AddRef,
|
|
|
|
dwritefontfamily_Release,
|
|
|
|
dwritefontfamily_GetFontCollection,
|
|
|
|
dwritefontfamily_GetFontCount,
|
|
|
|
dwritefontfamily_GetFont,
|
|
|
|
dwritefontfamily_GetFamilyNames,
|
|
|
|
dwritefontfamily_GetFirstMatchingFont,
|
|
|
|
dwritefontfamily_GetMatchingFonts
|
|
|
|
};
|
|
|
|
|
2014-11-04 14:37:10 +01:00
|
|
|
static HRESULT create_fontfamily(struct dwrite_fontfamily_data *data, IDWriteFontCollection *collection, IDWriteFontFamily **family)
|
|
|
|
{
|
|
|
|
struct dwrite_fontfamily *This;
|
|
|
|
|
|
|
|
*family = NULL;
|
|
|
|
|
|
|
|
This = heap_alloc(sizeof(struct dwrite_fontfamily));
|
|
|
|
if (!This) return E_OUTOFMEMORY;
|
|
|
|
|
|
|
|
This->IDWriteFontFamily_iface.lpVtbl = &fontfamilyvtbl;
|
|
|
|
This->ref = 1;
|
|
|
|
This->collection = collection;
|
|
|
|
IDWriteFontCollection_AddRef(collection);
|
|
|
|
This->data = data;
|
|
|
|
InterlockedIncrement(&This->data->ref);
|
|
|
|
|
|
|
|
*family = &This->IDWriteFontFamily_iface;
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2012-10-21 03:43:01 +02:00
|
|
|
static HRESULT WINAPI dwritefontcollection_QueryInterface(IDWriteFontCollection *iface, REFIID riid, void **obj)
|
|
|
|
{
|
|
|
|
struct dwrite_fontcollection *This = impl_from_IDWriteFontCollection(iface);
|
|
|
|
TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), obj);
|
|
|
|
|
|
|
|
if (IsEqualIID(riid, &IID_IUnknown) ||
|
|
|
|
IsEqualIID(riid, &IID_IDWriteFontCollection))
|
|
|
|
{
|
|
|
|
*obj = iface;
|
|
|
|
IDWriteFontCollection_AddRef(iface);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
*obj = NULL;
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
2014-09-02 14:17:57 +02:00
|
|
|
static ULONG WINAPI dwritefontcollection_AddRef(IDWriteFontCollection *iface)
|
2012-10-21 03:43:01 +02:00
|
|
|
{
|
2014-09-02 14:17:57 +02:00
|
|
|
struct dwrite_fontcollection *This = impl_from_IDWriteFontCollection(iface);
|
|
|
|
ULONG ref = InterlockedIncrement(&This->ref);
|
|
|
|
TRACE("(%p)->(%d)\n", This, ref);
|
|
|
|
return ref;
|
2012-10-21 03:43:01 +02:00
|
|
|
}
|
|
|
|
|
2014-09-02 14:17:57 +02:00
|
|
|
static ULONG WINAPI dwritefontcollection_Release(IDWriteFontCollection *iface)
|
2012-10-21 03:43:01 +02:00
|
|
|
{
|
2014-09-02 14:17:57 +02:00
|
|
|
unsigned int i;
|
|
|
|
struct dwrite_fontcollection *This = impl_from_IDWriteFontCollection(iface);
|
|
|
|
ULONG ref = InterlockedDecrement(&This->ref);
|
|
|
|
TRACE("(%p)->(%d)\n", This, ref);
|
|
|
|
|
2014-10-29 20:41:47 +01:00
|
|
|
if (!ref) {
|
2014-10-27 12:48:46 +01:00
|
|
|
for (i = 0; i < This->family_count; i++)
|
2014-10-08 16:52:07 +02:00
|
|
|
_free_fontfamily_data(This->family_data[i]);
|
|
|
|
heap_free(This->family_data);
|
2014-09-02 14:17:57 +02:00
|
|
|
heap_free(This);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ref;
|
2012-10-21 03:43:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static UINT32 WINAPI dwritefontcollection_GetFontFamilyCount(IDWriteFontCollection *iface)
|
|
|
|
{
|
|
|
|
struct dwrite_fontcollection *This = impl_from_IDWriteFontCollection(iface);
|
2012-10-21 06:24:35 +02:00
|
|
|
TRACE("(%p)\n", This);
|
2014-10-29 20:41:47 +01:00
|
|
|
return This->family_count;
|
2012-10-21 03:43:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI dwritefontcollection_GetFontFamily(IDWriteFontCollection *iface, UINT32 index, IDWriteFontFamily **family)
|
|
|
|
{
|
|
|
|
struct dwrite_fontcollection *This = impl_from_IDWriteFontCollection(iface);
|
2012-10-22 06:06:03 +02:00
|
|
|
|
|
|
|
TRACE("(%p)->(%u %p)\n", This, index, family);
|
|
|
|
|
2014-10-29 20:41:47 +01:00
|
|
|
if (index >= This->family_count) {
|
|
|
|
*family = NULL;
|
|
|
|
return E_FAIL;
|
2012-10-22 06:06:03 +02:00
|
|
|
}
|
|
|
|
|
2014-11-04 14:37:10 +01:00
|
|
|
return create_fontfamily(This->family_data[index], iface, family);
|
2012-10-21 03:43:01 +02:00
|
|
|
}
|
|
|
|
|
2014-10-24 09:43:21 +02:00
|
|
|
static HRESULT collection_find_family(struct dwrite_fontcollection *collection, const WCHAR *name, UINT32 *index, BOOL *exists)
|
2012-10-21 03:43:01 +02:00
|
|
|
{
|
2012-10-21 06:31:11 +02:00
|
|
|
UINT32 i;
|
|
|
|
|
2014-10-27 12:48:46 +01:00
|
|
|
if (collection->family_count) {
|
|
|
|
for (i = 0; i < collection->family_count; i++) {
|
2014-10-24 09:43:21 +02:00
|
|
|
IDWriteLocalizedStrings *family_name = collection->family_data[i]->familyname;
|
2014-10-08 16:52:07 +02:00
|
|
|
HRESULT hr;
|
|
|
|
int j;
|
2014-10-24 09:43:21 +02:00
|
|
|
|
|
|
|
for (j = 0; j < IDWriteLocalizedStrings_GetCount(family_name); j++) {
|
2014-10-08 16:52:07 +02:00
|
|
|
WCHAR buffer[255];
|
|
|
|
hr = IDWriteLocalizedStrings_GetString(family_name, j, buffer, 255);
|
2014-10-24 09:43:21 +02:00
|
|
|
if (SUCCEEDED(hr)) {
|
|
|
|
if (!strcmpW(buffer, name)) {
|
2014-10-08 16:52:07 +02:00
|
|
|
*index = i;
|
|
|
|
*exists = TRUE;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-10-21 06:31:11 +02:00
|
|
|
}
|
2014-10-08 16:52:07 +02:00
|
|
|
*index = (UINT32)-1;
|
|
|
|
*exists = FALSE;
|
|
|
|
}
|
2012-10-21 06:31:11 +02:00
|
|
|
|
|
|
|
return S_OK;
|
2012-10-21 03:43:01 +02:00
|
|
|
}
|
|
|
|
|
2014-10-24 09:43:21 +02:00
|
|
|
static HRESULT WINAPI dwritefontcollection_FindFamilyName(IDWriteFontCollection *iface, const WCHAR *name, UINT32 *index, BOOL *exists)
|
|
|
|
{
|
|
|
|
struct dwrite_fontcollection *This = impl_from_IDWriteFontCollection(iface);
|
|
|
|
TRACE("(%p)->(%s %p %p)\n", This, debugstr_w(name), index, exists);
|
|
|
|
return collection_find_family(This, name, index, exists);
|
|
|
|
}
|
|
|
|
|
2014-11-05 10:48:45 +01:00
|
|
|
static BOOL is_same_fontfile(IDWriteFontFile *left, IDWriteFontFile *right)
|
|
|
|
{
|
|
|
|
UINT32 left_key_size, right_key_size;
|
|
|
|
const void *left_key, *right_key;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
if (left == right)
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
hr = IDWriteFontFile_GetReferenceKey(left, &left_key, &left_key_size);
|
|
|
|
if (FAILED(hr))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
hr = IDWriteFontFile_GetReferenceKey(right, &right_key, &right_key_size);
|
|
|
|
if (FAILED(hr))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (left_key_size != right_key_size)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return !memcmp(left_key, right_key, left_key_size);
|
|
|
|
}
|
|
|
|
|
2012-10-21 03:43:01 +02:00
|
|
|
static HRESULT WINAPI dwritefontcollection_GetFontFromFontFace(IDWriteFontCollection *iface, IDWriteFontFace *face, IDWriteFont **font)
|
|
|
|
{
|
|
|
|
struct dwrite_fontcollection *This = impl_from_IDWriteFontCollection(iface);
|
2014-10-27 09:25:43 +01:00
|
|
|
struct dwrite_fontfamily_data *found_family = NULL;
|
|
|
|
struct dwrite_font_data *found_font = NULL;
|
2014-10-27 15:37:49 +01:00
|
|
|
DWRITE_FONT_SIMULATIONS simulations;
|
2014-10-27 09:25:43 +01:00
|
|
|
IDWriteFontFamily *family;
|
2014-11-05 10:48:45 +01:00
|
|
|
UINT32 i, j, face_index;
|
|
|
|
IDWriteFontFile *file;
|
2014-10-27 09:25:43 +01:00
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
TRACE("(%p)->(%p %p)\n", This, face, font);
|
|
|
|
|
|
|
|
*font = NULL;
|
|
|
|
|
|
|
|
if (!face)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
2014-11-05 10:48:45 +01:00
|
|
|
i = 1;
|
|
|
|
hr = IDWriteFontFace_GetFiles(face, &i, &file);
|
|
|
|
if (FAILED(hr))
|
|
|
|
return hr;
|
|
|
|
face_index = IDWriteFontFace_GetIndex(face);
|
|
|
|
|
2014-10-27 12:48:46 +01:00
|
|
|
for (i = 0; i < This->family_count; i++) {
|
2014-10-27 09:25:43 +01:00
|
|
|
struct dwrite_fontfamily_data *family_data = This->family_data[i];
|
|
|
|
for (j = 0; j < family_data->font_count; j++) {
|
2014-11-05 10:48:45 +01:00
|
|
|
struct dwrite_font_data *font_data = family_data->fonts[j];
|
|
|
|
|
|
|
|
if (face_index == font_data->face_index && is_same_fontfile(file, font_data->file)) {
|
|
|
|
found_font = font_data;
|
2014-10-27 09:25:43 +01:00
|
|
|
found_family = family_data;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!found_font)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
2014-11-04 14:37:10 +01:00
|
|
|
hr = create_fontfamily(found_family, iface, &family);
|
2014-10-27 09:25:43 +01:00
|
|
|
if (FAILED(hr))
|
|
|
|
return hr;
|
|
|
|
|
2014-10-27 15:37:49 +01:00
|
|
|
simulations = IDWriteFontFace_GetSimulations(face);
|
2014-11-04 14:37:10 +01:00
|
|
|
hr = create_font(found_font, family, simulations, font);
|
2014-10-27 09:25:43 +01:00
|
|
|
IDWriteFontFamily_Release(family);
|
|
|
|
return hr;
|
2012-10-21 03:43:01 +02:00
|
|
|
}
|
|
|
|
|
2014-09-02 14:17:57 +02:00
|
|
|
static const IDWriteFontCollectionVtbl fontcollectionvtbl = {
|
2012-10-21 03:43:01 +02:00
|
|
|
dwritefontcollection_QueryInterface,
|
2014-09-02 14:17:57 +02:00
|
|
|
dwritefontcollection_AddRef,
|
|
|
|
dwritefontcollection_Release,
|
2012-10-21 03:43:01 +02:00
|
|
|
dwritefontcollection_GetFontFamilyCount,
|
|
|
|
dwritefontcollection_GetFontFamily,
|
|
|
|
dwritefontcollection_FindFamilyName,
|
|
|
|
dwritefontcollection_GetFontFromFontFace
|
|
|
|
};
|
|
|
|
|
2014-10-24 09:43:21 +02:00
|
|
|
static HRESULT fontfamily_add_font(struct dwrite_fontfamily_data *family_data, struct dwrite_font_data *font_data)
|
|
|
|
{
|
2014-10-27 09:25:19 +01:00
|
|
|
if (family_data->font_count + 1 >= family_data->font_alloc) {
|
2014-10-24 09:43:21 +02:00
|
|
|
struct dwrite_font_data **new_list;
|
|
|
|
UINT32 new_alloc;
|
|
|
|
|
2014-10-27 09:25:19 +01:00
|
|
|
new_alloc = family_data->font_alloc * 2;
|
2014-10-24 09:43:21 +02:00
|
|
|
new_list = heap_realloc(family_data->fonts, sizeof(*family_data->fonts) * new_alloc);
|
|
|
|
if (!new_list)
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
family_data->fonts = new_list;
|
2014-10-27 09:25:19 +01:00
|
|
|
family_data->font_alloc = new_alloc;
|
2014-10-24 09:43:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
family_data->fonts[family_data->font_count] = font_data;
|
|
|
|
InterlockedIncrement(&font_data->ref);
|
|
|
|
family_data->font_count++;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT fontcollection_add_family(struct dwrite_fontcollection *collection, struct dwrite_fontfamily_data *family)
|
|
|
|
{
|
2014-10-27 12:48:46 +01:00
|
|
|
if (collection->family_alloc < collection->family_count + 1) {
|
2014-10-24 09:43:21 +02:00
|
|
|
struct dwrite_fontfamily_data **new_list;
|
|
|
|
UINT32 new_alloc;
|
|
|
|
|
2014-10-27 12:48:46 +01:00
|
|
|
new_alloc = collection->family_alloc * 2;
|
2014-10-24 09:43:21 +02:00
|
|
|
new_list = heap_realloc(collection->family_data, sizeof(*new_list) * new_alloc);
|
|
|
|
if (!new_list)
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
2014-10-27 12:48:46 +01:00
|
|
|
collection->family_alloc = new_alloc;
|
2014-10-24 09:43:21 +02:00
|
|
|
collection->family_data = new_list;
|
|
|
|
}
|
|
|
|
|
2014-10-27 12:48:46 +01:00
|
|
|
collection->family_data[collection->family_count] = family;
|
|
|
|
collection->family_count++;
|
2014-10-24 09:43:21 +02:00
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT init_font_collection(struct dwrite_fontcollection *collection)
|
|
|
|
{
|
|
|
|
collection->IDWriteFontCollection_iface.lpVtbl = &fontcollectionvtbl;
|
|
|
|
collection->ref = 1;
|
2014-10-27 12:48:46 +01:00
|
|
|
collection->family_count = 0;
|
|
|
|
collection->family_alloc = 2;
|
2014-10-24 09:43:21 +02:00
|
|
|
|
|
|
|
collection->family_data = heap_alloc(sizeof(*collection->family_data)*2);
|
|
|
|
if (!collection->family_data)
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT get_filestream_from_file(IDWriteFontFile *file, IDWriteFontFileStream **stream)
|
|
|
|
{
|
|
|
|
IDWriteFontFileLoader *loader;
|
|
|
|
const void *key;
|
|
|
|
UINT32 key_size;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
*stream = NULL;
|
|
|
|
|
|
|
|
hr = IDWriteFontFile_GetReferenceKey(file, &key, &key_size);
|
|
|
|
if (FAILED(hr))
|
|
|
|
return hr;
|
|
|
|
|
|
|
|
hr = IDWriteFontFile_GetLoader(file, &loader);
|
|
|
|
if (FAILED(hr))
|
|
|
|
return hr;
|
|
|
|
|
|
|
|
hr = IDWriteFontFileLoader_CreateStreamFromKey(loader, key, key_size, stream);
|
|
|
|
IDWriteFontFileLoader_Release(loader);
|
|
|
|
if (FAILED(hr))
|
|
|
|
return hr;
|
|
|
|
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT init_font_data(IDWriteFactory *factory, IDWriteFontFile *file, UINT32 face_index, DWRITE_FONT_FACE_TYPE face_type, struct dwrite_font_data *data)
|
|
|
|
{
|
|
|
|
void *os2_context, *head_context, *post_context;
|
|
|
|
const void *tt_os2 = NULL, *tt_head = NULL, *tt_post = NULL;
|
|
|
|
IDWriteFontFileStream *stream;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
hr = get_filestream_from_file(file, &stream);
|
|
|
|
if (FAILED(hr))
|
|
|
|
return hr;
|
|
|
|
|
|
|
|
data->factory = factory;
|
|
|
|
data->file = file;
|
|
|
|
data->face_index = face_index;
|
|
|
|
data->face_type = face_type;
|
|
|
|
IDWriteFontFile_AddRef(file);
|
|
|
|
IDWriteFactory_AddRef(factory);
|
|
|
|
|
|
|
|
opentype_get_font_table(stream, face_type, face_index, MS_OS2_TAG, &tt_os2, &os2_context, NULL, NULL);
|
|
|
|
opentype_get_font_table(stream, face_type, face_index, MS_HEAD_TAG, &tt_head, &head_context, NULL, NULL);
|
|
|
|
opentype_get_font_table(stream, face_type, face_index, MS_POST_TAG, &tt_post, &post_context, NULL, NULL);
|
|
|
|
|
2014-11-05 21:03:32 +01:00
|
|
|
opentype_get_font_properties(tt_os2, tt_head, &data->stretch, &data->weight, &data->style);
|
|
|
|
opentype_get_font_metrics(tt_os2, tt_head, tt_post, &data->metrics);
|
2014-10-24 09:43:21 +02:00
|
|
|
|
|
|
|
if (tt_os2)
|
|
|
|
IDWriteFontFileStream_ReleaseFileFragment(stream, os2_context);
|
|
|
|
if (tt_head)
|
|
|
|
IDWriteFontFileStream_ReleaseFileFragment(stream, head_context);
|
|
|
|
if (tt_post)
|
|
|
|
IDWriteFontFileStream_ReleaseFileFragment(stream, post_context);
|
|
|
|
IDWriteFontFileStream_Release(stream);
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT init_fontfamily_data(IDWriteLocalizedStrings *familyname, struct dwrite_fontfamily_data *data)
|
|
|
|
{
|
2014-10-27 09:25:19 +01:00
|
|
|
data->ref = 1;
|
|
|
|
data->font_count = 0;
|
|
|
|
data->font_alloc = 2;
|
|
|
|
|
|
|
|
data->fonts = heap_alloc(sizeof(*data->fonts)*data->font_alloc);
|
2014-10-24 09:43:21 +02:00
|
|
|
if (!data->fonts) {
|
|
|
|
heap_free(data);
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
data->familyname = familyname;
|
|
|
|
IDWriteLocalizedStrings_AddRef(familyname);
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT create_font_collection(IDWriteFactory* factory, IDWriteFontFileEnumerator *enumerator, IDWriteFontCollection **ret)
|
|
|
|
{
|
|
|
|
struct dwrite_fontcollection *collection;
|
|
|
|
BOOL current = FALSE;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
*ret = NULL;
|
|
|
|
|
|
|
|
collection = heap_alloc(sizeof(struct dwrite_fontcollection));
|
|
|
|
if (!collection) return E_OUTOFMEMORY;
|
|
|
|
|
|
|
|
hr = init_font_collection(collection);
|
|
|
|
if (FAILED(hr)) {
|
|
|
|
heap_free(collection);
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
*ret = &collection->IDWriteFontCollection_iface;
|
|
|
|
|
|
|
|
TRACE("building font collection:\n");
|
|
|
|
|
|
|
|
while (1) {
|
|
|
|
DWRITE_FONT_FACE_TYPE face_type;
|
|
|
|
DWRITE_FONT_FILE_TYPE file_type;
|
|
|
|
IDWriteFontFile *file;
|
|
|
|
UINT32 face_count;
|
|
|
|
BOOL supported;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
current = FALSE;
|
|
|
|
hr = IDWriteFontFileEnumerator_MoveNext(enumerator, ¤t);
|
|
|
|
if (FAILED(hr) || !current)
|
|
|
|
break;
|
|
|
|
|
|
|
|
hr = IDWriteFontFileEnumerator_GetCurrentFontFile(enumerator, &file);
|
|
|
|
if (FAILED(hr))
|
|
|
|
break;
|
|
|
|
|
|
|
|
hr = IDWriteFontFile_Analyze(file, &supported, &file_type, &face_type, &face_count);
|
|
|
|
if (FAILED(hr) || !supported || face_count == 0) {
|
|
|
|
TRACE("unsupported font (0x%08x, %d, %u)\n", hr, supported, face_count);
|
|
|
|
IDWriteFontFile_Release(file);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < face_count; i++) {
|
|
|
|
IDWriteLocalizedStrings *family_name = NULL;
|
|
|
|
struct dwrite_font_data *font_data;
|
|
|
|
const void *name_table;
|
|
|
|
void *name_context;
|
|
|
|
IDWriteFontFileStream *stream;
|
|
|
|
WCHAR buffer[255];
|
|
|
|
UINT32 index;
|
|
|
|
BOOL exists;
|
|
|
|
|
|
|
|
/* alloc and init new font data structure */
|
|
|
|
font_data = heap_alloc_zero(sizeof(struct dwrite_font_data));
|
|
|
|
init_font_data(factory, file, i, face_type, font_data);
|
|
|
|
|
|
|
|
hr = get_filestream_from_file(file, &stream);
|
2014-11-02 11:10:22 +01:00
|
|
|
if (FAILED(hr)) {
|
|
|
|
heap_free (font_data);
|
2014-10-24 09:43:21 +02:00
|
|
|
return hr;
|
2014-11-02 11:10:22 +01:00
|
|
|
}
|
2014-10-24 09:43:21 +02:00
|
|
|
|
|
|
|
/* get family name from font file */
|
|
|
|
name_table = NULL;
|
|
|
|
opentype_get_font_table(stream, face_type, i, MS_NAME_TAG, &name_table, &name_context, NULL, NULL);
|
|
|
|
if (name_table)
|
|
|
|
hr = opentype_get_font_strings_from_id(name_table, DWRITE_INFORMATIONAL_STRING_WIN32_FAMILY_NAMES, &family_name);
|
|
|
|
IDWriteFontFileStream_Release(stream);
|
|
|
|
|
|
|
|
if (FAILED(hr) || !family_name) {
|
|
|
|
WARN("unable to get family name from font\n");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
buffer[0] = 0;
|
|
|
|
IDWriteLocalizedStrings_GetString(family_name, 0, buffer, sizeof(buffer)/sizeof(WCHAR));
|
|
|
|
|
|
|
|
exists = FALSE;
|
|
|
|
hr = collection_find_family(collection, buffer, &index, &exists);
|
|
|
|
if (exists)
|
|
|
|
hr = fontfamily_add_font(collection->family_data[index], font_data);
|
|
|
|
else {
|
|
|
|
struct dwrite_fontfamily_data *family_data;
|
|
|
|
|
|
|
|
/* create and init new family */
|
|
|
|
family_data = heap_alloc(sizeof(*family_data));
|
|
|
|
init_fontfamily_data(family_name, family_data);
|
|
|
|
|
|
|
|
/* add font to family, family - to collection */
|
|
|
|
fontfamily_add_font(family_data, font_data);
|
|
|
|
fontcollection_add_family(collection, family_data);
|
|
|
|
}
|
|
|
|
|
|
|
|
IDWriteLocalizedStrings_Release(family_name);
|
|
|
|
}
|
|
|
|
|
|
|
|
IDWriteFontFile_Release(file);
|
|
|
|
};
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2014-10-29 20:41:47 +01:00
|
|
|
struct system_fontfile_enumerator
|
|
|
|
{
|
|
|
|
IDWriteFontFileEnumerator IDWriteFontFileEnumerator_iface;
|
|
|
|
LONG ref;
|
|
|
|
|
|
|
|
IDWriteFactory *factory;
|
|
|
|
HKEY hkey;
|
|
|
|
int index;
|
|
|
|
};
|
|
|
|
|
|
|
|
static inline struct system_fontfile_enumerator *impl_from_IDWriteFontFileEnumerator(IDWriteFontFileEnumerator* iface)
|
2012-10-21 06:24:35 +02:00
|
|
|
{
|
2014-10-29 20:41:47 +01:00
|
|
|
return CONTAINING_RECORD(iface, struct system_fontfile_enumerator, IDWriteFontFileEnumerator_iface);
|
2012-10-21 06:24:35 +02:00
|
|
|
}
|
|
|
|
|
2014-10-29 20:41:47 +01:00
|
|
|
static HRESULT WINAPI systemfontfileenumerator_QueryInterface(IDWriteFontFileEnumerator *iface, REFIID riid, void **obj)
|
2012-10-22 05:20:42 +02:00
|
|
|
{
|
2014-10-29 20:41:47 +01:00
|
|
|
*obj = NULL;
|
2012-10-22 05:20:42 +02:00
|
|
|
|
2014-10-29 20:41:47 +01:00
|
|
|
if (IsEqualIID(riid, &IID_IDWriteFontFileEnumerator) || IsEqualIID(riid, &IID_IUnknown)) {
|
|
|
|
IDWriteFontFileEnumerator_AddRef(iface);
|
|
|
|
*obj = iface;
|
|
|
|
return S_OK;
|
|
|
|
}
|
2012-10-21 03:43:01 +02:00
|
|
|
|
2014-10-29 20:41:47 +01:00
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
2012-10-21 06:24:35 +02:00
|
|
|
|
2014-10-29 20:41:47 +01:00
|
|
|
static ULONG WINAPI systemfontfileenumerator_AddRef(IDWriteFontFileEnumerator *iface)
|
|
|
|
{
|
|
|
|
struct system_fontfile_enumerator *enumerator = impl_from_IDWriteFontFileEnumerator(iface);
|
|
|
|
return InterlockedIncrement(&enumerator->ref);
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI systemfontfileenumerator_Release(IDWriteFontFileEnumerator *iface)
|
|
|
|
{
|
|
|
|
struct system_fontfile_enumerator *enumerator = impl_from_IDWriteFontFileEnumerator(iface);
|
|
|
|
ULONG ref = InterlockedDecrement(&enumerator->ref);
|
|
|
|
|
|
|
|
if (!ref) {
|
|
|
|
IDWriteFactory_Release(enumerator->factory);
|
|
|
|
RegCloseKey(enumerator->hkey);
|
|
|
|
heap_free(enumerator);
|
2014-10-08 16:52:07 +02:00
|
|
|
}
|
2014-10-29 20:41:47 +01:00
|
|
|
|
|
|
|
return ref;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI systemfontfileenumerator_GetCurrentFontFile(IDWriteFontFileEnumerator *iface, IDWriteFontFile **file)
|
|
|
|
{
|
|
|
|
struct system_fontfile_enumerator *enumerator = impl_from_IDWriteFontFileEnumerator(iface);
|
|
|
|
DWORD ret, type, count;
|
|
|
|
HRESULT hr;
|
|
|
|
BYTE *data;
|
|
|
|
|
|
|
|
*file = NULL;
|
|
|
|
|
|
|
|
if (enumerator->index < 0)
|
|
|
|
return E_FAIL;
|
|
|
|
|
|
|
|
if (RegEnumValueW(enumerator->hkey, enumerator->index, NULL, NULL, NULL, &type, NULL, &count))
|
|
|
|
return E_FAIL;
|
|
|
|
|
|
|
|
if (!(data = heap_alloc(count)))
|
2014-10-08 16:52:07 +02:00
|
|
|
return E_OUTOFMEMORY;
|
2014-10-29 20:41:47 +01:00
|
|
|
|
|
|
|
ret = RegEnumValueW(enumerator->hkey, enumerator->index, NULL, NULL, NULL, &type, data, &count);
|
|
|
|
if (ret) {
|
|
|
|
heap_free(data);
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
hr = IDWriteFactory_CreateFontFileReference(enumerator->factory, (WCHAR*)data, NULL, file);
|
|
|
|
heap_free(data);
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI systemfontfileenumerator_MoveNext(IDWriteFontFileEnumerator *iface, BOOL *current)
|
|
|
|
{
|
|
|
|
struct system_fontfile_enumerator *enumerator = impl_from_IDWriteFontFileEnumerator(iface);
|
|
|
|
|
|
|
|
*current = FALSE;
|
|
|
|
enumerator->index++;
|
|
|
|
|
|
|
|
/* iterate until we find next string value */
|
|
|
|
while (1) {
|
|
|
|
DWORD type = 0, count;
|
|
|
|
if (RegEnumValueW(enumerator->hkey, enumerator->index, NULL, NULL, NULL, &type, NULL, &count))
|
|
|
|
break;
|
|
|
|
if (type == REG_SZ) {
|
|
|
|
*current = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
enumerator->index++;
|
2014-10-08 16:52:07 +02:00
|
|
|
}
|
2012-10-21 06:24:35 +02:00
|
|
|
|
2014-10-29 20:41:47 +01:00
|
|
|
TRACE("index = %d, current = %d\n", enumerator->index, *current);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct IDWriteFontFileEnumeratorVtbl systemfontfileenumeratorvtbl =
|
|
|
|
{
|
|
|
|
systemfontfileenumerator_QueryInterface,
|
|
|
|
systemfontfileenumerator_AddRef,
|
|
|
|
systemfontfileenumerator_Release,
|
|
|
|
systemfontfileenumerator_MoveNext,
|
|
|
|
systemfontfileenumerator_GetCurrentFontFile
|
|
|
|
};
|
|
|
|
|
|
|
|
static HRESULT create_system_fontfile_enumerator(IDWriteFactory *factory, IDWriteFontFileEnumerator **ret)
|
|
|
|
{
|
|
|
|
struct system_fontfile_enumerator *enumerator;
|
|
|
|
static const WCHAR fontslistW[] = {
|
|
|
|
'S','o','f','t','w','a','r','e','\\','M','i','c','r','o','s','o','f','t','\\',
|
|
|
|
'W','i','n','d','o','w','s',' ','N','T','\\','C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
|
|
|
|
'F','o','n','t','s',0
|
|
|
|
};
|
|
|
|
|
|
|
|
*ret = NULL;
|
|
|
|
|
|
|
|
enumerator = heap_alloc(sizeof(*enumerator));
|
|
|
|
if (!enumerator)
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
|
|
|
enumerator->IDWriteFontFileEnumerator_iface.lpVtbl = &systemfontfileenumeratorvtbl;
|
|
|
|
enumerator->ref = 1;
|
|
|
|
enumerator->factory = factory;
|
|
|
|
enumerator->index = -1;
|
|
|
|
IDWriteFactory_AddRef(factory);
|
2012-10-22 05:20:42 +02:00
|
|
|
|
2014-10-29 20:41:47 +01:00
|
|
|
if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, fontslistW, 0, GENERIC_READ, &enumerator->hkey)) {
|
|
|
|
ERR("failed to open fonts list key\n");
|
|
|
|
IDWriteFactory_Release(factory);
|
|
|
|
heap_free(enumerator);
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
2012-10-21 06:24:35 +02:00
|
|
|
|
2014-10-29 20:41:47 +01:00
|
|
|
*ret = &enumerator->IDWriteFontFileEnumerator_iface;
|
2012-10-21 03:43:01 +02:00
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2014-10-29 20:41:47 +01:00
|
|
|
HRESULT get_system_fontcollection(IDWriteFactory *factory, IDWriteFontCollection **collection)
|
|
|
|
{
|
|
|
|
IDWriteFontFileEnumerator *enumerator;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
*collection = NULL;
|
|
|
|
|
|
|
|
hr = create_system_fontfile_enumerator(factory, &enumerator);
|
|
|
|
if (FAILED(hr))
|
|
|
|
return hr;
|
|
|
|
|
|
|
|
TRACE("building system font collection for factory %p\n", factory);
|
|
|
|
hr = create_font_collection(factory, enumerator, collection);
|
|
|
|
IDWriteFontFileEnumerator_Release(enumerator);
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2014-08-12 21:11:34 +02:00
|
|
|
static HRESULT WINAPI dwritefontfile_QueryInterface(IDWriteFontFile *iface, REFIID riid, void **obj)
|
|
|
|
{
|
|
|
|
struct dwrite_fontfile *This = impl_from_IDWriteFontFile(iface);
|
|
|
|
|
|
|
|
TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), obj);
|
|
|
|
|
|
|
|
if (IsEqualIID(riid, &IID_IUnknown) || IsEqualIID(riid, &IID_IDWriteFontFile))
|
|
|
|
{
|
|
|
|
*obj = iface;
|
|
|
|
IDWriteFontFile_AddRef(iface);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
*obj = NULL;
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI dwritefontfile_AddRef(IDWriteFontFile *iface)
|
|
|
|
{
|
|
|
|
struct dwrite_fontfile *This = impl_from_IDWriteFontFile(iface);
|
|
|
|
ULONG ref = InterlockedIncrement(&This->ref);
|
|
|
|
TRACE("(%p)->(%d)\n", This, ref);
|
|
|
|
return ref;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI dwritefontfile_Release(IDWriteFontFile *iface)
|
|
|
|
{
|
|
|
|
struct dwrite_fontfile *This = impl_from_IDWriteFontFile(iface);
|
|
|
|
ULONG ref = InterlockedDecrement(&This->ref);
|
|
|
|
|
|
|
|
TRACE("(%p)->(%d)\n", This, ref);
|
|
|
|
|
|
|
|
if (!ref)
|
|
|
|
{
|
|
|
|
IDWriteFontFileLoader_Release(This->loader);
|
2014-08-17 03:40:48 +02:00
|
|
|
if (This->stream) IDWriteFontFileStream_Release(This->stream);
|
2014-08-12 21:11:34 +02:00
|
|
|
heap_free(This->reference_key);
|
|
|
|
heap_free(This);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ref;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI dwritefontfile_GetReferenceKey(IDWriteFontFile *iface, const void **fontFileReferenceKey, UINT32 *fontFileReferenceKeySize)
|
|
|
|
{
|
|
|
|
struct dwrite_fontfile *This = impl_from_IDWriteFontFile(iface);
|
|
|
|
TRACE("(%p)->(%p, %p)\n", This, fontFileReferenceKey, fontFileReferenceKeySize);
|
|
|
|
*fontFileReferenceKey = This->reference_key;
|
|
|
|
*fontFileReferenceKeySize = This->key_size;
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI dwritefontfile_GetLoader(IDWriteFontFile *iface, IDWriteFontFileLoader **fontFileLoader)
|
|
|
|
{
|
|
|
|
struct dwrite_fontfile *This = impl_from_IDWriteFontFile(iface);
|
|
|
|
TRACE("(%p)->(%p)\n", This, fontFileLoader);
|
|
|
|
*fontFileLoader = This->loader;
|
|
|
|
IDWriteFontFileLoader_AddRef(This->loader);
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI dwritefontfile_Analyze(IDWriteFontFile *iface, BOOL *isSupportedFontType, DWRITE_FONT_FILE_TYPE *fontFileType, DWRITE_FONT_FACE_TYPE *fontFaceType, UINT32 *numberOfFaces)
|
|
|
|
{
|
2014-10-08 12:14:51 +02:00
|
|
|
struct dwrite_fontfile *This = impl_from_IDWriteFontFile(iface);
|
2014-08-12 21:11:37 +02:00
|
|
|
IDWriteFontFileStream *stream;
|
2014-10-08 12:14:51 +02:00
|
|
|
HRESULT hr;
|
2014-08-12 21:11:37 +02:00
|
|
|
|
2014-10-29 20:43:51 +01:00
|
|
|
TRACE("(%p)->(%p, %p, %p, %p)\n", This, isSupportedFontType, fontFileType, fontFaceType, numberOfFaces);
|
2014-08-12 21:11:37 +02:00
|
|
|
|
|
|
|
*isSupportedFontType = FALSE;
|
|
|
|
*fontFileType = DWRITE_FONT_FILE_TYPE_UNKNOWN;
|
|
|
|
if (fontFaceType)
|
|
|
|
*fontFaceType = DWRITE_FONT_FACE_TYPE_UNKNOWN;
|
|
|
|
*numberOfFaces = 0;
|
|
|
|
|
|
|
|
hr = IDWriteFontFileLoader_CreateStreamFromKey(This->loader, This->reference_key, This->key_size, &stream);
|
|
|
|
if (FAILED(hr))
|
|
|
|
return S_OK;
|
2014-10-08 12:14:51 +02:00
|
|
|
|
|
|
|
hr = opentype_analyze_font(stream, numberOfFaces, fontFileType, fontFaceType, isSupportedFontType);
|
|
|
|
|
2014-08-12 21:11:37 +02:00
|
|
|
/* TODO: Further Analysis */
|
|
|
|
IDWriteFontFileStream_Release(stream);
|
|
|
|
return S_OK;
|
2014-08-12 21:11:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static const IDWriteFontFileVtbl dwritefontfilevtbl = {
|
|
|
|
dwritefontfile_QueryInterface,
|
|
|
|
dwritefontfile_AddRef,
|
|
|
|
dwritefontfile_Release,
|
|
|
|
dwritefontfile_GetReferenceKey,
|
|
|
|
dwritefontfile_GetLoader,
|
|
|
|
dwritefontfile_Analyze,
|
|
|
|
};
|
|
|
|
|
|
|
|
HRESULT create_font_file(IDWriteFontFileLoader *loader, const void *reference_key, UINT32 key_size, IDWriteFontFile **font_file)
|
|
|
|
{
|
|
|
|
struct dwrite_fontfile *This;
|
|
|
|
|
|
|
|
This = heap_alloc(sizeof(struct dwrite_fontfile));
|
|
|
|
if (!This) return E_OUTOFMEMORY;
|
|
|
|
|
|
|
|
This->IDWriteFontFile_iface.lpVtbl = &dwritefontfilevtbl;
|
|
|
|
This->ref = 1;
|
|
|
|
IDWriteFontFileLoader_AddRef(loader);
|
|
|
|
This->loader = loader;
|
2014-08-17 03:40:48 +02:00
|
|
|
This->stream = NULL;
|
2014-08-12 21:11:34 +02:00
|
|
|
This->reference_key = heap_alloc(key_size);
|
|
|
|
memcpy(This->reference_key, reference_key, key_size);
|
|
|
|
This->key_size = key_size;
|
|
|
|
|
|
|
|
*font_file = &This->IDWriteFontFile_iface;
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
2014-08-17 03:40:48 +02:00
|
|
|
|
2014-11-05 21:30:32 +01:00
|
|
|
static HRESULT get_stream_from_file(IDWriteFontFile *file, IDWriteFontFileStream **stream)
|
|
|
|
{
|
|
|
|
IDWriteFontFileLoader *loader;
|
|
|
|
UINT32 key_size;
|
|
|
|
const void *key;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
*stream = NULL;
|
|
|
|
hr = IDWriteFontFile_GetLoader(file, &loader);
|
|
|
|
if (FAILED(hr))
|
|
|
|
return hr;
|
|
|
|
|
|
|
|
hr = IDWriteFontFile_GetReferenceKey(file, &key, &key_size);
|
|
|
|
if (FAILED(hr)) {
|
|
|
|
IDWriteFontFileLoader_Release(loader);
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
hr = IDWriteFontFileLoader_CreateStreamFromKey(loader, key, key_size, stream);
|
|
|
|
IDWriteFontFileLoader_Release(loader);
|
|
|
|
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2014-10-24 09:40:06 +02:00
|
|
|
HRESULT create_fontface(DWRITE_FONT_FACE_TYPE facetype, UINT32 files_number, IDWriteFontFile* const* font_files, UINT32 index,
|
|
|
|
DWRITE_FONT_SIMULATIONS simulations, IDWriteFontFace2 **ret)
|
2014-08-17 03:40:48 +02:00
|
|
|
{
|
2014-10-24 09:40:06 +02:00
|
|
|
struct dwrite_fontface *fontface;
|
2014-08-17 03:40:48 +02:00
|
|
|
HRESULT hr = S_OK;
|
2014-10-24 09:40:06 +02:00
|
|
|
int i;
|
2014-08-17 03:40:48 +02:00
|
|
|
|
2014-10-24 09:40:06 +02:00
|
|
|
fontface = heap_alloc(sizeof(struct dwrite_fontface));
|
|
|
|
if (!fontface)
|
|
|
|
return E_OUTOFMEMORY;
|
2014-10-12 16:18:10 +02:00
|
|
|
|
2014-11-05 21:30:32 +01:00
|
|
|
fontface->files = heap_alloc_zero(sizeof(*fontface->files) * files_number);
|
|
|
|
fontface->streams = heap_alloc_zero(sizeof(*fontface->streams) * files_number);
|
|
|
|
|
|
|
|
if (!fontface->files || !fontface->streams) {
|
|
|
|
heap_free(fontface->files);
|
|
|
|
heap_free(fontface->streams);
|
2014-10-24 09:40:06 +02:00
|
|
|
heap_free(fontface);
|
2014-09-02 17:19:31 +02:00
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
}
|
2014-08-17 03:40:48 +02:00
|
|
|
|
2014-10-24 09:40:06 +02:00
|
|
|
fontface->IDWriteFontFace2_iface.lpVtbl = &dwritefontfacevtbl;
|
|
|
|
fontface->ref = 1;
|
|
|
|
fontface->type = facetype;
|
|
|
|
fontface->file_count = files_number;
|
|
|
|
fontface->cmap.data = NULL;
|
|
|
|
fontface->cmap.context = NULL;
|
|
|
|
fontface->cmap.size = 0;
|
|
|
|
|
|
|
|
for (i = 0; i < fontface->file_count; i++) {
|
2014-11-05 21:30:32 +01:00
|
|
|
hr = get_stream_from_file(font_files[i], &fontface->streams[i]);
|
|
|
|
if (FAILED(hr)) {
|
|
|
|
IDWriteFontFace2_Release(&fontface->IDWriteFontFace2_iface);
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2014-10-24 09:40:06 +02:00
|
|
|
fontface->files[i] = font_files[i];
|
2014-08-17 03:40:48 +02:00
|
|
|
IDWriteFontFile_AddRef(font_files[i]);
|
|
|
|
}
|
|
|
|
|
2014-10-24 09:40:06 +02:00
|
|
|
fontface->index = index;
|
|
|
|
fontface->simulations = simulations;
|
2014-08-17 03:40:48 +02:00
|
|
|
|
2014-10-24 09:40:06 +02:00
|
|
|
*ret = &fontface->IDWriteFontFace2_iface;
|
2014-08-17 03:40:48 +02:00
|
|
|
return S_OK;
|
|
|
|
}
|
2014-08-26 17:11:59 +02:00
|
|
|
|
|
|
|
/* IDWriteLocalFontFileLoader and its required IDWriteFontFileStream */
|
|
|
|
|
|
|
|
struct dwrite_localfontfilestream
|
|
|
|
{
|
|
|
|
IDWriteFontFileStream IDWriteFontFileStream_iface;
|
|
|
|
LONG ref;
|
|
|
|
|
|
|
|
HANDLE handle;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct dwrite_localfontfileloader {
|
|
|
|
IDWriteLocalFontFileLoader IDWriteLocalFontFileLoader_iface;
|
|
|
|
LONG ref;
|
|
|
|
};
|
|
|
|
|
|
|
|
static inline struct dwrite_localfontfileloader *impl_from_IDWriteLocalFontFileLoader(IDWriteLocalFontFileLoader *iface)
|
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(iface, struct dwrite_localfontfileloader, IDWriteLocalFontFileLoader_iface);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline struct dwrite_localfontfilestream *impl_from_IDWriteFontFileStream(IDWriteFontFileStream *iface)
|
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(iface, struct dwrite_localfontfilestream, IDWriteFontFileStream_iface);
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI localfontfilestream_QueryInterface(IDWriteFontFileStream *iface, REFIID riid, void **obj)
|
|
|
|
{
|
|
|
|
struct dwrite_localfontfilestream *This = impl_from_IDWriteFontFileStream(iface);
|
|
|
|
TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), obj);
|
|
|
|
if (IsEqualIID(riid, &IID_IUnknown) || IsEqualIID(riid, &IID_IDWriteFontFileStream))
|
|
|
|
{
|
|
|
|
*obj = iface;
|
|
|
|
IDWriteFontFileStream_AddRef(iface);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
*obj = NULL;
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI localfontfilestream_AddRef(IDWriteFontFileStream *iface)
|
|
|
|
{
|
|
|
|
struct dwrite_localfontfilestream *This = impl_from_IDWriteFontFileStream(iface);
|
|
|
|
ULONG ref = InterlockedIncrement(&This->ref);
|
|
|
|
TRACE("(%p)->(%d)\n", This, ref);
|
|
|
|
return ref;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI localfontfilestream_Release(IDWriteFontFileStream *iface)
|
|
|
|
{
|
|
|
|
struct dwrite_localfontfilestream *This = impl_from_IDWriteFontFileStream(iface);
|
|
|
|
ULONG ref = InterlockedDecrement(&This->ref);
|
|
|
|
|
|
|
|
TRACE("(%p)->(%d)\n", This, ref);
|
|
|
|
|
|
|
|
if (!ref)
|
|
|
|
{
|
|
|
|
if (This->handle != INVALID_HANDLE_VALUE)
|
|
|
|
CloseHandle(This->handle);
|
|
|
|
heap_free(This);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ref;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI localfontfilestream_ReadFileFragment(IDWriteFontFileStream *iface, void const **fragment_start, UINT64 offset, UINT64 fragment_size, void **fragment_context)
|
|
|
|
{
|
|
|
|
struct dwrite_localfontfilestream *This = impl_from_IDWriteFontFileStream(iface);
|
|
|
|
LARGE_INTEGER distance;
|
|
|
|
DWORD bytes = fragment_size;
|
|
|
|
DWORD read;
|
|
|
|
|
|
|
|
TRACE("(%p)->(%p, %s, %s, %p)\n",This, fragment_start,
|
|
|
|
wine_dbgstr_longlong(offset), wine_dbgstr_longlong(fragment_size), fragment_context);
|
|
|
|
|
|
|
|
*fragment_context = NULL;
|
|
|
|
distance.QuadPart = offset;
|
|
|
|
if (!SetFilePointerEx(This->handle, distance, NULL, FILE_BEGIN))
|
|
|
|
return E_FAIL;
|
|
|
|
*fragment_start = *fragment_context = heap_alloc(bytes);
|
|
|
|
if (!*fragment_context)
|
|
|
|
return E_FAIL;
|
|
|
|
if (!ReadFile(This->handle, *fragment_context, bytes, &read, NULL))
|
|
|
|
{
|
|
|
|
heap_free(*fragment_context);
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void WINAPI localfontfilestream_ReleaseFileFragment(IDWriteFontFileStream *iface, void *fragment_context)
|
|
|
|
{
|
|
|
|
struct dwrite_localfontfilestream *This = impl_from_IDWriteFontFileStream(iface);
|
|
|
|
TRACE("(%p)->(%p)\n", This, fragment_context);
|
|
|
|
heap_free(fragment_context);
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI localfontfilestream_GetFileSize(IDWriteFontFileStream *iface, UINT64 *size)
|
|
|
|
{
|
|
|
|
struct dwrite_localfontfilestream *This = impl_from_IDWriteFontFileStream(iface);
|
|
|
|
LARGE_INTEGER li;
|
|
|
|
TRACE("(%p)->(%p)\n",This, size);
|
|
|
|
GetFileSizeEx(This->handle, &li);
|
|
|
|
*size = li.QuadPart;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI localfontfilestream_GetLastWriteTime(IDWriteFontFileStream *iface, UINT64 *last_writetime)
|
|
|
|
{
|
|
|
|
struct dwrite_localfontfilestream *This = impl_from_IDWriteFontFileStream(iface);
|
|
|
|
FIXME("(%p)->(%p): stub\n",This, last_writetime);
|
|
|
|
*last_writetime = 0;
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const IDWriteFontFileStreamVtbl localfontfilestreamvtbl =
|
|
|
|
{
|
|
|
|
localfontfilestream_QueryInterface,
|
|
|
|
localfontfilestream_AddRef,
|
|
|
|
localfontfilestream_Release,
|
|
|
|
localfontfilestream_ReadFileFragment,
|
|
|
|
localfontfilestream_ReleaseFileFragment,
|
|
|
|
localfontfilestream_GetFileSize,
|
|
|
|
localfontfilestream_GetLastWriteTime
|
|
|
|
};
|
|
|
|
|
|
|
|
static HRESULT create_localfontfilestream(HANDLE handle, IDWriteFontFileStream** iface)
|
|
|
|
{
|
|
|
|
struct dwrite_localfontfilestream *This = heap_alloc(sizeof(struct dwrite_localfontfilestream));
|
|
|
|
if (!This)
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
|
|
|
This->ref = 1;
|
|
|
|
This->handle = handle;
|
|
|
|
This->IDWriteFontFileStream_iface.lpVtbl = &localfontfilestreamvtbl;
|
|
|
|
|
|
|
|
*iface = &This->IDWriteFontFileStream_iface;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI localfontfileloader_QueryInterface(IDWriteLocalFontFileLoader *iface, REFIID riid, void **obj)
|
|
|
|
{
|
|
|
|
struct dwrite_localfontfileloader *This = impl_from_IDWriteLocalFontFileLoader(iface);
|
|
|
|
|
|
|
|
TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), obj);
|
|
|
|
|
|
|
|
if (IsEqualIID(riid, &IID_IUnknown) || IsEqualIID(riid, &IID_IDWriteFontFileLoader) || IsEqualIID(riid, &IID_IDWriteLocalFontFileLoader))
|
|
|
|
{
|
|
|
|
*obj = iface;
|
|
|
|
IDWriteLocalFontFileLoader_AddRef(iface);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
*obj = NULL;
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI localfontfileloader_AddRef(IDWriteLocalFontFileLoader *iface)
|
|
|
|
{
|
|
|
|
struct dwrite_localfontfileloader *This = impl_from_IDWriteLocalFontFileLoader(iface);
|
|
|
|
ULONG ref = InterlockedIncrement(&This->ref);
|
|
|
|
TRACE("(%p)->(%d)\n", This, ref);
|
|
|
|
return ref;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI localfontfileloader_Release(IDWriteLocalFontFileLoader *iface)
|
|
|
|
{
|
|
|
|
struct dwrite_localfontfileloader *This = impl_from_IDWriteLocalFontFileLoader(iface);
|
|
|
|
ULONG ref = InterlockedDecrement(&This->ref);
|
|
|
|
|
|
|
|
TRACE("(%p)->(%d)\n", This, ref);
|
|
|
|
|
|
|
|
if (!ref)
|
|
|
|
heap_free(This);
|
|
|
|
|
|
|
|
return ref;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI localfontfileloader_CreateStreamFromKey(IDWriteLocalFontFileLoader *iface, const void *fontFileReferenceKey, UINT32 fontFileReferenceKeySize, IDWriteFontFileStream **fontFileStream)
|
|
|
|
{
|
|
|
|
HANDLE handle;
|
|
|
|
struct dwrite_localfontfileloader *This = impl_from_IDWriteLocalFontFileLoader(iface);
|
|
|
|
const WCHAR *name = (const WCHAR*)fontFileReferenceKey;
|
|
|
|
|
|
|
|
TRACE("(%p)->(%p, %i, %p)\n",This, fontFileReferenceKey, fontFileReferenceKeySize, fontFileStream);
|
|
|
|
|
|
|
|
TRACE("name: %s\n",debugstr_w(name));
|
|
|
|
handle = CreateFileW(name, GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE,
|
|
|
|
NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
|
|
|
|
|
|
|
|
if (handle == INVALID_HANDLE_VALUE)
|
|
|
|
return E_FAIL;
|
|
|
|
|
|
|
|
return create_localfontfilestream(handle, fontFileStream);
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI localfontfileloader_GetFilePathLengthFromKey(IDWriteLocalFontFileLoader *iface, void const *key, UINT32 key_size, UINT32 *length)
|
|
|
|
{
|
|
|
|
struct dwrite_localfontfileloader *This = impl_from_IDWriteLocalFontFileLoader(iface);
|
|
|
|
TRACE("(%p)->(%p, %i, %p)\n",This, key, key_size, length);
|
|
|
|
*length = key_size;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI localfontfileloader_GetFilePathFromKey(IDWriteLocalFontFileLoader *iface, void const *key, UINT32 key_size, WCHAR *path, UINT32 length)
|
|
|
|
{
|
|
|
|
struct dwrite_localfontfileloader *This = impl_from_IDWriteLocalFontFileLoader(iface);
|
|
|
|
TRACE("(%p)->(%p, %i, %p, %i)\n",This, key, key_size, path, length);
|
|
|
|
if (length < key_size)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
lstrcpynW((WCHAR*)key, path, key_size);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI localfontfileloader_GetLastWriteTimeFromKey(IDWriteLocalFontFileLoader *iface, void const *key, UINT32 key_size, FILETIME *writetime)
|
|
|
|
{
|
|
|
|
struct dwrite_localfontfileloader *This = impl_from_IDWriteLocalFontFileLoader(iface);
|
2014-09-01 12:12:35 +02:00
|
|
|
FIXME("(%p)->(%p, %i, %p):stub\n",This, key, key_size, writetime);
|
2014-08-26 17:11:59 +02:00
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct IDWriteLocalFontFileLoaderVtbl localfontfileloadervtbl = {
|
|
|
|
localfontfileloader_QueryInterface,
|
|
|
|
localfontfileloader_AddRef,
|
|
|
|
localfontfileloader_Release,
|
|
|
|
localfontfileloader_CreateStreamFromKey,
|
|
|
|
localfontfileloader_GetFilePathLengthFromKey,
|
|
|
|
localfontfileloader_GetFilePathFromKey,
|
|
|
|
localfontfileloader_GetLastWriteTimeFromKey
|
|
|
|
};
|
|
|
|
|
|
|
|
HRESULT create_localfontfileloader(IDWriteLocalFontFileLoader** iface)
|
|
|
|
{
|
|
|
|
struct dwrite_localfontfileloader *This = heap_alloc(sizeof(struct dwrite_localfontfileloader));
|
|
|
|
if (!This)
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
|
|
|
This->ref = 1;
|
|
|
|
This->IDWriteLocalFontFileLoader_iface.lpVtbl = &localfontfileloadervtbl;
|
|
|
|
|
|
|
|
*iface = &This->IDWriteLocalFontFileLoader_iface;
|
|
|
|
return S_OK;
|
|
|
|
}
|