2012-08-13 05:44:19 +02:00
|
|
|
/*
|
|
|
|
* Font and collections
|
|
|
|
*
|
|
|
|
* Copyright 2012 Nikolay Sivov for CodeWeavers
|
|
|
|
*
|
|
|
|
* 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.h"
|
|
|
|
#include "dwrite_private.h"
|
|
|
|
|
|
|
|
#include "wine/debug.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(dwrite);
|
|
|
|
|
2012-10-10 14:37:55 +02:00
|
|
|
/* PANOSE is 10 bytes in size, need to pack the structure properly */
|
|
|
|
#include "pshpack2.h"
|
2012-10-16 18:56:23 +02:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
ULONG version;
|
|
|
|
ULONG revision;
|
|
|
|
ULONG checksumadj;
|
|
|
|
ULONG magic;
|
|
|
|
USHORT flags;
|
|
|
|
USHORT unitsPerEm;
|
|
|
|
ULONGLONG created;
|
|
|
|
ULONGLONG modified;
|
|
|
|
SHORT xMin;
|
|
|
|
SHORT yMin;
|
|
|
|
SHORT xMax;
|
|
|
|
SHORT yMax;
|
|
|
|
USHORT macStyle;
|
|
|
|
USHORT lowestRecPPEM;
|
|
|
|
SHORT direction_hint;
|
|
|
|
SHORT index_format;
|
|
|
|
SHORT glyphdata_format;
|
|
|
|
} TT_HEAD;
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
ULONG Version;
|
|
|
|
ULONG italicAngle;
|
|
|
|
SHORT underlinePosition;
|
|
|
|
SHORT underlineThickness;
|
|
|
|
ULONG fixed_pitch;
|
|
|
|
ULONG minmemType42;
|
|
|
|
ULONG maxmemType42;
|
|
|
|
ULONG minmemType1;
|
|
|
|
ULONG maxmemType1;
|
|
|
|
} TT_POST;
|
|
|
|
|
2012-10-10 14:37:55 +02:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
USHORT version;
|
|
|
|
SHORT xAvgCharWidth;
|
|
|
|
USHORT usWeightClass;
|
|
|
|
USHORT usWidthClass;
|
|
|
|
SHORT fsType;
|
|
|
|
SHORT ySubscriptXSize;
|
|
|
|
SHORT ySubscriptYSize;
|
|
|
|
SHORT ySubscriptXOffset;
|
|
|
|
SHORT ySubscriptYOffset;
|
|
|
|
SHORT ySuperscriptXSize;
|
|
|
|
SHORT ySuperscriptYSize;
|
|
|
|
SHORT ySuperscriptXOffset;
|
|
|
|
SHORT ySuperscriptYOffset;
|
|
|
|
SHORT yStrikeoutSize;
|
|
|
|
SHORT yStrikeoutPosition;
|
|
|
|
SHORT sFamilyClass;
|
|
|
|
PANOSE panose;
|
|
|
|
ULONG ulUnicodeRange1;
|
|
|
|
ULONG ulUnicodeRange2;
|
|
|
|
ULONG ulUnicodeRange3;
|
|
|
|
ULONG ulUnicodeRange4;
|
|
|
|
CHAR achVendID[4];
|
|
|
|
USHORT fsSelection;
|
|
|
|
USHORT usFirstCharIndex;
|
|
|
|
USHORT usLastCharIndex;
|
|
|
|
/* According to the Apple spec, original version didn't have the below fields,
|
|
|
|
* version numbers were taken from the OpenType spec.
|
|
|
|
*/
|
|
|
|
/* version 0 (TrueType 1.5) */
|
|
|
|
USHORT sTypoAscender;
|
|
|
|
USHORT sTypoDescender;
|
|
|
|
USHORT sTypoLineGap;
|
|
|
|
USHORT usWinAscent;
|
|
|
|
USHORT usWinDescent;
|
|
|
|
/* version 1 (TrueType 1.66) */
|
|
|
|
ULONG ulCodePageRange1;
|
|
|
|
ULONG ulCodePageRange2;
|
|
|
|
/* version 2 (OpenType 1.2) */
|
|
|
|
SHORT sxHeight;
|
|
|
|
SHORT sCapHeight;
|
|
|
|
USHORT usDefaultChar;
|
|
|
|
USHORT usBreakChar;
|
|
|
|
USHORT usMaxContext;
|
|
|
|
} TT_OS2_V2;
|
|
|
|
#include "poppack.h"
|
|
|
|
|
|
|
|
#ifdef WORDS_BIGENDIAN
|
|
|
|
#define GET_BE_WORD(x) (x)
|
|
|
|
#define GET_BE_DWORD(x) (x)
|
|
|
|
#else
|
|
|
|
#define GET_BE_WORD(x) MAKEWORD(HIBYTE(x), LOBYTE(x))
|
|
|
|
#define GET_BE_DWORD(x) MAKELONG(GET_BE_WORD(HIWORD(x)), GET_BE_WORD(LOWORD(x)));
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define MS_MAKE_TAG(ch0, ch1, ch2, ch3) \
|
|
|
|
((DWORD)(BYTE)(ch0) | ((DWORD)(BYTE)(ch1) << 8) | \
|
|
|
|
((DWORD)(BYTE)(ch2) << 16) | ((DWORD)(BYTE)(ch3) << 24))
|
2012-10-16 18:56:23 +02:00
|
|
|
|
|
|
|
#define MS_HEAD_TAG MS_MAKE_TAG('h','e','a','d')
|
|
|
|
#define MS_OS2_TAG MS_MAKE_TAG('O','S','/','2')
|
|
|
|
#define MS_POST_TAG MS_MAKE_TAG('p','o','s','t')
|
2012-10-10 14:37:55 +02:00
|
|
|
|
2012-10-21 03:43:01 +02:00
|
|
|
struct dwrite_fontcollection {
|
|
|
|
IDWriteFontCollection IDWriteFontCollection_iface;
|
2012-10-21 06:24:35 +02:00
|
|
|
|
|
|
|
WCHAR **families;
|
|
|
|
UINT32 count;
|
|
|
|
int alloc;
|
2012-10-21 03:43:01 +02:00
|
|
|
};
|
|
|
|
|
2012-10-22 05:20:42 +02:00
|
|
|
static IDWriteFontCollection *system_collection;
|
|
|
|
|
2012-08-25 11:11:31 +02:00
|
|
|
struct dwrite_fontfamily {
|
|
|
|
IDWriteFontFamily IDWriteFontFamily_iface;
|
|
|
|
LONG ref;
|
2012-10-07 18:29:39 +02:00
|
|
|
|
|
|
|
WCHAR *familyname;
|
2012-08-25 11:11:31 +02:00
|
|
|
};
|
|
|
|
|
2012-08-13 05:44:19 +02:00
|
|
|
struct dwrite_font {
|
|
|
|
IDWriteFont IDWriteFont_iface;
|
|
|
|
LONG ref;
|
2012-08-13 05:46:43 +02:00
|
|
|
|
2012-08-25 11:11:31 +02:00
|
|
|
IDWriteFontFamily *family;
|
2012-10-07 21:03:52 +02:00
|
|
|
IDWriteFontFace *face;
|
2012-08-13 05:46:43 +02:00
|
|
|
DWRITE_FONT_STYLE style;
|
2012-10-10 14:37:55 +02:00
|
|
|
DWRITE_FONT_STRETCH stretch;
|
2012-10-12 14:43:57 +02:00
|
|
|
DWRITE_FONT_WEIGHT weight;
|
2012-10-16 18:56:23 +02:00
|
|
|
DWRITE_FONT_METRICS metrics;
|
2012-10-24 22:05:01 +02:00
|
|
|
WCHAR *facename;
|
2012-08-13 05:44:19 +02:00
|
|
|
};
|
|
|
|
|
2012-10-07 21:03:52 +02:00
|
|
|
struct dwrite_fontface {
|
|
|
|
IDWriteFontFace IDWriteFontFace_iface;
|
|
|
|
LONG ref;
|
2012-10-24 22:05:01 +02:00
|
|
|
|
|
|
|
LOGFONTW logfont;
|
2012-10-07 21:03:52 +02:00
|
|
|
};
|
|
|
|
|
2012-10-22 06:06:03 +02:00
|
|
|
static HRESULT create_fontfamily(const WCHAR *familyname, IDWriteFontFamily **family);
|
|
|
|
|
2012-10-07 21:03:52 +02:00
|
|
|
static inline struct dwrite_fontface *impl_from_IDWriteFontFace(IDWriteFontFace *iface)
|
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(iface, struct dwrite_fontface, IDWriteFontFace_iface);
|
|
|
|
}
|
|
|
|
|
2012-08-13 05:44:19 +02:00
|
|
|
static inline struct dwrite_font *impl_from_IDWriteFont(IDWriteFont *iface)
|
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(iface, struct dwrite_font, IDWriteFont_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);
|
|
|
|
}
|
|
|
|
|
2012-10-07 21:03:52 +02:00
|
|
|
static HRESULT WINAPI dwritefontface_QueryInterface(IDWriteFontFace *iface, REFIID riid, void **obj)
|
|
|
|
{
|
|
|
|
struct dwrite_fontface *This = impl_from_IDWriteFontFace(iface);
|
|
|
|
|
|
|
|
TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), obj);
|
|
|
|
|
|
|
|
if (IsEqualIID(riid, &IID_IUnknown) || IsEqualIID(riid, &IID_IDWriteFontFace))
|
|
|
|
{
|
|
|
|
*obj = iface;
|
|
|
|
IDWriteFontFace_AddRef(iface);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
*obj = NULL;
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI dwritefontface_AddRef(IDWriteFontFace *iface)
|
|
|
|
{
|
|
|
|
struct dwrite_fontface *This = impl_from_IDWriteFontFace(iface);
|
|
|
|
ULONG ref = InterlockedIncrement(&This->ref);
|
|
|
|
TRACE("(%p)->(%d)\n", This, ref);
|
|
|
|
return ref;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI dwritefontface_Release(IDWriteFontFace *iface)
|
|
|
|
{
|
|
|
|
struct dwrite_fontface *This = impl_from_IDWriteFontFace(iface);
|
|
|
|
ULONG ref = InterlockedDecrement(&This->ref);
|
|
|
|
|
|
|
|
TRACE("(%p)->(%d)\n", This, ref);
|
|
|
|
|
|
|
|
if (!ref)
|
|
|
|
heap_free(This);
|
|
|
|
|
2012-10-21 03:47:22 +02:00
|
|
|
return ref;
|
2012-10-07 21:03:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static DWRITE_FONT_FACE_TYPE WINAPI dwritefontface_GetType(IDWriteFontFace *iface)
|
|
|
|
{
|
|
|
|
struct dwrite_fontface *This = impl_from_IDWriteFontFace(iface);
|
|
|
|
FIXME("(%p): stub\n", This);
|
|
|
|
return DWRITE_FONT_FACE_TYPE_UNKNOWN;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI dwritefontface_GetFiles(IDWriteFontFace *iface, UINT32 *number_of_files,
|
|
|
|
IDWriteFontFile **fontfiles)
|
|
|
|
{
|
|
|
|
struct dwrite_fontface *This = impl_from_IDWriteFontFace(iface);
|
|
|
|
FIXME("(%p)->(%p %p): stub\n", This, number_of_files, fontfiles);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static UINT32 WINAPI dwritefontface_GetIndex(IDWriteFontFace *iface)
|
|
|
|
{
|
|
|
|
struct dwrite_fontface *This = impl_from_IDWriteFontFace(iface);
|
|
|
|
FIXME("(%p): stub\n", This);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static DWRITE_FONT_SIMULATIONS WINAPI dwritefontface_GetSimulations(IDWriteFontFace *iface)
|
|
|
|
{
|
|
|
|
struct dwrite_fontface *This = impl_from_IDWriteFontFace(iface);
|
|
|
|
FIXME("(%p): stub\n", This);
|
|
|
|
return DWRITE_FONT_SIMULATIONS_NONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL WINAPI dwritefontface_IsSymbolFont(IDWriteFontFace *iface)
|
|
|
|
{
|
|
|
|
struct dwrite_fontface *This = impl_from_IDWriteFontFace(iface);
|
|
|
|
FIXME("(%p): stub\n", This);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void WINAPI dwritefontface_GetMetrics(IDWriteFontFace *iface, DWRITE_FONT_METRICS *metrics)
|
|
|
|
{
|
|
|
|
struct dwrite_fontface *This = impl_from_IDWriteFontFace(iface);
|
|
|
|
FIXME("(%p)->(%p): stub\n", This, metrics);
|
|
|
|
}
|
|
|
|
|
|
|
|
static UINT16 WINAPI dwritefontface_GetGlyphCount(IDWriteFontFace *iface)
|
|
|
|
{
|
|
|
|
struct dwrite_fontface *This = impl_from_IDWriteFontFace(iface);
|
|
|
|
FIXME("(%p): stub\n", This);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI dwritefontface_GetDesignGlyphMetrics(IDWriteFontFace *iface,
|
|
|
|
UINT16 const *glyph_indices, UINT32 glyph_count, DWRITE_GLYPH_METRICS *metrics, BOOL is_sideways)
|
|
|
|
{
|
|
|
|
struct dwrite_fontface *This = impl_from_IDWriteFontFace(iface);
|
|
|
|
FIXME("(%p)->(%p %u %p %d): stub\n", This, glyph_indices, glyph_count, metrics, is_sideways);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI dwritefontface_GetGlyphIndices(IDWriteFontFace *iface, UINT32 const *codepoints,
|
|
|
|
UINT32 count, UINT16 *glyph_indices)
|
|
|
|
{
|
|
|
|
struct dwrite_fontface *This = impl_from_IDWriteFontFace(iface);
|
2012-10-24 22:05:01 +02:00
|
|
|
HFONT hfont;
|
|
|
|
WCHAR *str;
|
|
|
|
HDC hdc;
|
2013-03-09 22:48:49 +01:00
|
|
|
unsigned int i;
|
2012-10-24 22:05:01 +02:00
|
|
|
|
|
|
|
TRACE("(%p)->(%p %u %p)\n", This, codepoints, count, glyph_indices);
|
|
|
|
|
|
|
|
str = heap_alloc(count*sizeof(WCHAR));
|
|
|
|
if (!str) return E_OUTOFMEMORY;
|
|
|
|
|
|
|
|
for (i = 0; i < count; i++)
|
|
|
|
str[i] = codepoints[i] < 0x10000 ? codepoints[i] : '?';
|
|
|
|
|
|
|
|
hdc = CreateCompatibleDC(0);
|
|
|
|
hfont = CreateFontIndirectW(&This->logfont);
|
|
|
|
SelectObject(hdc, hfont);
|
|
|
|
|
|
|
|
GetGlyphIndicesW(hdc, str, count, glyph_indices, 0);
|
|
|
|
heap_free(str);
|
|
|
|
|
|
|
|
DeleteDC(hdc);
|
|
|
|
DeleteObject(hfont);
|
|
|
|
|
|
|
|
return S_OK;
|
2012-10-07 21:03:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI dwritefontface_TryGetFontTable(IDWriteFontFace *iface, UINT32 table_tag,
|
|
|
|
const void **table_data, UINT32 *table_size, void **context, BOOL *exists)
|
|
|
|
{
|
|
|
|
struct dwrite_fontface *This = impl_from_IDWriteFontFace(iface);
|
|
|
|
FIXME("(%p)->(%u %p %p %p %p): stub\n", This, table_tag, table_data, table_size, context, exists);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void WINAPI dwritefontface_ReleaseFontTable(IDWriteFontFace *iface, void *table_context)
|
|
|
|
{
|
|
|
|
struct dwrite_fontface *This = impl_from_IDWriteFontFace(iface);
|
|
|
|
FIXME("(%p)->(%p): stub\n", This, table_context);
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI dwritefontface_GetGlyphRunOutline(IDWriteFontFace *iface, FLOAT emSize,
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
struct dwrite_fontface *This = impl_from_IDWriteFontFace(iface);
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI dwritefontface_GetRecommendedRenderingMode(IDWriteFontFace *iface, FLOAT emSize,
|
|
|
|
FLOAT pixels_per_dip, DWRITE_MEASURING_MODE mode, IDWriteRenderingParams* params, DWRITE_RENDERING_MODE* rendering_mode)
|
|
|
|
{
|
|
|
|
struct dwrite_fontface *This = impl_from_IDWriteFontFace(iface);
|
|
|
|
FIXME("(%p)->(%f %f %d %p %p): stub\n", This, emSize, pixels_per_dip, mode, params, rendering_mode);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI dwritefontface_GetGdiCompatibleMetrics(IDWriteFontFace *iface, FLOAT emSize, FLOAT pixels_per_dip,
|
|
|
|
DWRITE_MATRIX const *transform, DWRITE_FONT_METRICS *metrics)
|
|
|
|
{
|
|
|
|
struct dwrite_fontface *This = impl_from_IDWriteFontFace(iface);
|
|
|
|
FIXME("(%p)->(%f %f %p %p): stub\n", This, emSize, pixels_per_dip, transform, metrics);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI dwritefontface_GetGdiCompatibleGlyphMetrics(IDWriteFontFace *iface, FLOAT emSize, FLOAT pixels_per_dip,
|
|
|
|
DWRITE_MATRIX const *transform, BOOL use_gdi_natural, UINT16 const *glyph_indices, UINT32 glyph_count,
|
|
|
|
DWRITE_GLYPH_METRICS *metrics, BOOL is_sideways)
|
|
|
|
{
|
|
|
|
struct dwrite_fontface *This = impl_from_IDWriteFontFace(iface);
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const IDWriteFontFaceVtbl dwritefontfacevtbl = {
|
|
|
|
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,
|
|
|
|
dwritefontface_GetGdiCompatibleGlyphMetrics
|
|
|
|
};
|
|
|
|
|
2012-10-24 22:05:01 +02:00
|
|
|
static HRESULT create_fontface(struct dwrite_font *font, IDWriteFontFace **face)
|
2012-10-07 21:03:52 +02:00
|
|
|
{
|
|
|
|
struct dwrite_fontface *This;
|
|
|
|
|
|
|
|
*face = NULL;
|
|
|
|
|
|
|
|
This = heap_alloc(sizeof(struct dwrite_fontface));
|
|
|
|
if (!This) return E_OUTOFMEMORY;
|
|
|
|
|
|
|
|
This->IDWriteFontFace_iface.lpVtbl = &dwritefontfacevtbl;
|
|
|
|
This->ref = 1;
|
2012-10-24 22:05:01 +02:00
|
|
|
|
|
|
|
memset(&This->logfont, 0, sizeof(This->logfont));
|
|
|
|
This->logfont.lfItalic = font->style == DWRITE_FONT_STYLE_ITALIC;
|
2014-01-05 22:24:17 +01:00
|
|
|
/* weight values from DWRITE_FONT_WEIGHT match values used for LOGFONT */
|
|
|
|
This->logfont.lfWeight = font->weight;
|
2012-10-24 22:05:01 +02:00
|
|
|
strcpyW(This->logfont.lfFaceName, font->facename);
|
|
|
|
|
2012-10-07 21:03:52 +02:00
|
|
|
*face = &This->IDWriteFontFace_iface;
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2014-01-05 22:24:17 +01:00
|
|
|
HRESULT convert_fontface_to_logfont(IDWriteFontFace *face, LOGFONTW *logfont)
|
|
|
|
{
|
|
|
|
struct dwrite_fontface *fontface = impl_from_IDWriteFontFace(face);
|
|
|
|
|
|
|
|
*logfont = fontface->logfont;
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2012-08-13 05:44:19 +02:00
|
|
|
static HRESULT WINAPI dwritefont_QueryInterface(IDWriteFont *iface, REFIID riid, void **obj)
|
|
|
|
{
|
|
|
|
struct dwrite_font *This = impl_from_IDWriteFont(iface);
|
|
|
|
|
|
|
|
TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), obj);
|
|
|
|
|
|
|
|
if (IsEqualIID(riid, &IID_IUnknown) || IsEqualIID(riid, &IID_IDWriteFont))
|
|
|
|
{
|
|
|
|
*obj = iface;
|
|
|
|
IDWriteFont_AddRef(iface);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
*obj = NULL;
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI dwritefont_AddRef(IDWriteFont *iface)
|
|
|
|
{
|
|
|
|
struct dwrite_font *This = impl_from_IDWriteFont(iface);
|
|
|
|
ULONG ref = InterlockedIncrement(&This->ref);
|
|
|
|
TRACE("(%p)->(%d)\n", This, ref);
|
|
|
|
return ref;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI dwritefont_Release(IDWriteFont *iface)
|
|
|
|
{
|
|
|
|
struct dwrite_font *This = impl_from_IDWriteFont(iface);
|
|
|
|
ULONG ref = InterlockedDecrement(&This->ref);
|
|
|
|
|
|
|
|
TRACE("(%p)->(%d)\n", This, ref);
|
|
|
|
|
|
|
|
if (!ref)
|
2012-08-25 11:11:31 +02:00
|
|
|
{
|
2012-10-13 07:22:05 +02:00
|
|
|
if (This->face) IDWriteFontFace_Release(This->face);
|
2012-08-25 11:11:31 +02:00
|
|
|
IDWriteFontFamily_Release(This->family);
|
2012-10-24 22:05:01 +02:00
|
|
|
heap_free(This->facename);
|
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
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI dwritefont_GetFontFamily(IDWriteFont *iface, IDWriteFontFamily **family)
|
|
|
|
{
|
|
|
|
struct dwrite_font *This = impl_from_IDWriteFont(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
|
|
|
}
|
|
|
|
|
|
|
|
static DWRITE_FONT_WEIGHT WINAPI dwritefont_GetWeight(IDWriteFont *iface)
|
|
|
|
{
|
|
|
|
struct dwrite_font *This = impl_from_IDWriteFont(iface);
|
2012-10-12 14:43:57 +02:00
|
|
|
TRACE("(%p)\n", This);
|
|
|
|
return This->weight;
|
2012-08-13 05:44:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static DWRITE_FONT_STRETCH WINAPI dwritefont_GetStretch(IDWriteFont *iface)
|
|
|
|
{
|
|
|
|
struct dwrite_font *This = impl_from_IDWriteFont(iface);
|
2012-10-10 14:37:55 +02:00
|
|
|
TRACE("(%p)\n", This);
|
|
|
|
return This->stretch;
|
2012-08-13 05:44:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static DWRITE_FONT_STYLE WINAPI dwritefont_GetStyle(IDWriteFont *iface)
|
|
|
|
{
|
|
|
|
struct dwrite_font *This = impl_from_IDWriteFont(iface);
|
2012-08-13 05:46:43 +02:00
|
|
|
TRACE("(%p)\n", This);
|
|
|
|
return This->style;
|
2012-08-13 05:44:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL WINAPI dwritefont_IsSymbolFont(IDWriteFont *iface)
|
|
|
|
{
|
|
|
|
struct dwrite_font *This = impl_from_IDWriteFont(iface);
|
|
|
|
FIXME("(%p): stub\n", This);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI dwritefont_GetFaceNames(IDWriteFont *iface, IDWriteLocalizedStrings **names)
|
|
|
|
{
|
|
|
|
struct dwrite_font *This = impl_from_IDWriteFont(iface);
|
|
|
|
FIXME("(%p)->(%p): stub\n", This, names);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI dwritefont_GetInformationalStrings(IDWriteFont *iface,
|
|
|
|
DWRITE_INFORMATIONAL_STRING_ID stringid, IDWriteLocalizedStrings **strings, BOOL *exists)
|
|
|
|
{
|
|
|
|
struct dwrite_font *This = impl_from_IDWriteFont(iface);
|
|
|
|
FIXME("(%p)->(%d %p %p): stub\n", This, stringid, strings, exists);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static DWRITE_FONT_SIMULATIONS WINAPI dwritefont_GetSimulations(IDWriteFont *iface)
|
|
|
|
{
|
|
|
|
struct dwrite_font *This = impl_from_IDWriteFont(iface);
|
|
|
|
FIXME("(%p): stub\n", This);
|
|
|
|
return DWRITE_FONT_SIMULATIONS_NONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void WINAPI dwritefont_GetMetrics(IDWriteFont *iface, DWRITE_FONT_METRICS *metrics)
|
|
|
|
{
|
|
|
|
struct dwrite_font *This = impl_from_IDWriteFont(iface);
|
2012-10-16 18:56:23 +02:00
|
|
|
|
|
|
|
TRACE("(%p)->(%p)\n", This, metrics);
|
|
|
|
*metrics = This->metrics;
|
2012-08-13 05:44:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI dwritefont_HasCharacter(IDWriteFont *iface, UINT32 value, BOOL *exists)
|
|
|
|
{
|
|
|
|
struct dwrite_font *This = impl_from_IDWriteFont(iface);
|
|
|
|
FIXME("(%p)->(0x%08x %p): stub\n", This, value, exists);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI dwritefont_CreateFontFace(IDWriteFont *iface, IDWriteFontFace **face)
|
|
|
|
{
|
|
|
|
struct dwrite_font *This = impl_from_IDWriteFont(iface);
|
2012-10-07 21:03:52 +02:00
|
|
|
|
|
|
|
TRACE("(%p)->(%p)\n", This, face);
|
|
|
|
|
|
|
|
if (!This->face)
|
|
|
|
{
|
2012-10-24 22:05:01 +02:00
|
|
|
HRESULT hr = create_fontface(This, &This->face);
|
2012-10-07 21:03:52 +02:00
|
|
|
if (FAILED(hr)) return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
*face = This->face;
|
|
|
|
IDWriteFontFace_AddRef(*face);
|
|
|
|
|
|
|
|
return S_OK;
|
2012-08-13 05:44:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static const IDWriteFontVtbl dwritefontvtbl = {
|
|
|
|
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,
|
|
|
|
dwritefont_CreateFontFace
|
|
|
|
};
|
|
|
|
|
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
|
|
|
{
|
|
|
|
heap_free(This->familyname);
|
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);
|
|
|
|
FIXME("(%p)->(%p): stub\n", This, collection);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static UINT32 WINAPI dwritefontfamily_GetFontCount(IDWriteFontFamily *iface)
|
|
|
|
{
|
|
|
|
struct dwrite_fontfamily *This = impl_from_IDWriteFontFamily(iface);
|
|
|
|
FIXME("(%p): stub\n", This);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI dwritefontfamily_GetFont(IDWriteFontFamily *iface, UINT32 index, IDWriteFont **font)
|
|
|
|
{
|
|
|
|
struct dwrite_fontfamily *This = impl_from_IDWriteFontFamily(iface);
|
|
|
|
FIXME("(%p)->(%u %p): stub\n", This, index, font);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI dwritefontfamily_GetFamilyNames(IDWriteFontFamily *iface, IDWriteLocalizedStrings **names)
|
|
|
|
{
|
|
|
|
struct dwrite_fontfamily *This = impl_from_IDWriteFontFamily(iface);
|
2012-10-07 23:13:29 +02:00
|
|
|
static const WCHAR enusW[] = {'e','n','-','u','s',0};
|
|
|
|
HRESULT hr;
|
2012-10-07 19:11:04 +02:00
|
|
|
|
2012-10-07 23:13:29 +02:00
|
|
|
TRACE("(%p)->(%p)\n", This, names);
|
|
|
|
|
|
|
|
hr = create_localizedstrings(names);
|
|
|
|
if (FAILED(hr)) return hr;
|
|
|
|
|
|
|
|
return add_localizedstring(*names, enusW, This->familyname);
|
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);
|
2012-10-23 14:18:32 +02:00
|
|
|
LOGFONTW lf;
|
|
|
|
|
|
|
|
TRACE("(%p)->(%d %d %d %p)\n", This, weight, stretch, style, font);
|
|
|
|
|
|
|
|
memset(&lf, 0, sizeof(lf));
|
|
|
|
lf.lfWeight = weight;
|
|
|
|
lf.lfItalic = style == DWRITE_FONT_STYLE_ITALIC;
|
|
|
|
strcpyW(lf.lfFaceName, This->familyname);
|
|
|
|
|
|
|
|
return create_font_from_logfont(&lf, font);
|
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
|
|
|
|
};
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2012-10-22 05:20:42 +02:00
|
|
|
static ULONG WINAPI dwritesysfontcollection_AddRef(IDWriteFontCollection *iface)
|
2012-10-21 03:43:01 +02:00
|
|
|
{
|
2012-10-22 05:20:42 +02:00
|
|
|
return 2;
|
2012-10-21 03:43:01 +02:00
|
|
|
}
|
|
|
|
|
2012-10-22 05:20:42 +02:00
|
|
|
static ULONG WINAPI dwritesysfontcollection_Release(IDWriteFontCollection *iface)
|
2012-10-21 03:43:01 +02:00
|
|
|
{
|
2012-10-22 05:20:42 +02:00
|
|
|
return 1;
|
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);
|
|
|
|
return This->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);
|
|
|
|
|
|
|
|
if (index >= This->count)
|
|
|
|
{
|
|
|
|
*family = NULL;
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return create_fontfamily(This->families[index], family);
|
2012-10-21 03:43:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI dwritefontcollection_FindFamilyName(IDWriteFontCollection *iface, const WCHAR *name, UINT32 *index, BOOL *exists)
|
|
|
|
{
|
|
|
|
struct dwrite_fontcollection *This = impl_from_IDWriteFontCollection(iface);
|
2012-10-21 06:31:11 +02:00
|
|
|
UINT32 i;
|
|
|
|
|
|
|
|
TRACE("(%p)->(%s %p %p)\n", This, debugstr_w(name), index, exists);
|
|
|
|
|
|
|
|
for (i = 0; i < This->count; i++)
|
|
|
|
if (!strcmpW(This->families[i], name))
|
|
|
|
{
|
|
|
|
*index = i;
|
|
|
|
*exists = TRUE;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
*index = (UINT32)-1;
|
|
|
|
*exists = FALSE;
|
|
|
|
|
|
|
|
return S_OK;
|
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);
|
|
|
|
FIXME("(%p)->(%p %p): stub\n", This, face, font);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
2012-10-22 05:20:42 +02:00
|
|
|
static const IDWriteFontCollectionVtbl systemfontcollectionvtbl = {
|
2012-10-21 03:43:01 +02:00
|
|
|
dwritefontcollection_QueryInterface,
|
2012-10-22 05:20:42 +02:00
|
|
|
dwritesysfontcollection_AddRef,
|
|
|
|
dwritesysfontcollection_Release,
|
2012-10-21 03:43:01 +02:00
|
|
|
dwritefontcollection_GetFontFamilyCount,
|
|
|
|
dwritefontcollection_GetFontFamily,
|
|
|
|
dwritefontcollection_FindFamilyName,
|
|
|
|
dwritefontcollection_GetFontFromFontFace
|
|
|
|
};
|
|
|
|
|
2012-10-21 06:24:35 +02:00
|
|
|
static HRESULT add_family_syscollection(struct dwrite_fontcollection *collection, const WCHAR *family)
|
|
|
|
{
|
|
|
|
/* check for duplicate family name */
|
|
|
|
if (collection->count && !strcmpW(collection->families[collection->count-1], family)) return S_OK;
|
|
|
|
|
|
|
|
/* double array length */
|
|
|
|
if (collection->count == collection->alloc)
|
|
|
|
{
|
|
|
|
collection->alloc *= 2;
|
|
|
|
collection->families = heap_realloc(collection->families, collection->alloc*sizeof(WCHAR*));
|
|
|
|
}
|
|
|
|
|
|
|
|
collection->families[collection->count++] = heap_strdupW(family);
|
|
|
|
TRACE("family name %s\n", debugstr_w(family));
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static INT CALLBACK enum_font_families(const LOGFONTW *lf, const TEXTMETRICW *tm, DWORD type, LPARAM lParam)
|
|
|
|
{
|
|
|
|
struct dwrite_fontcollection *collection = (struct dwrite_fontcollection*)lParam;
|
|
|
|
return add_family_syscollection(collection, lf->lfFaceName) == S_OK;
|
|
|
|
}
|
|
|
|
|
2012-10-22 05:20:42 +02:00
|
|
|
static void release_font_collection(IDWriteFontCollection *iface)
|
2012-10-21 03:43:01 +02:00
|
|
|
{
|
2012-10-22 05:20:42 +02:00
|
|
|
struct dwrite_fontcollection *This = impl_from_IDWriteFontCollection(iface);
|
2013-03-09 22:48:49 +01:00
|
|
|
unsigned int i;
|
2012-10-21 03:43:01 +02:00
|
|
|
|
2012-10-22 05:20:42 +02:00
|
|
|
for (i = 0; i < This->count; i++)
|
|
|
|
heap_free(This->families[i]);
|
|
|
|
heap_free(This->families);
|
|
|
|
heap_free(This);
|
|
|
|
}
|
2012-10-21 03:43:01 +02:00
|
|
|
|
2012-10-22 05:20:42 +02:00
|
|
|
void release_system_fontcollection(void)
|
|
|
|
{
|
2013-01-28 07:37:36 +01:00
|
|
|
if (system_collection)
|
|
|
|
release_font_collection(system_collection);
|
2012-10-22 05:20:42 +02:00
|
|
|
}
|
2012-10-21 03:43:01 +02:00
|
|
|
|
2012-10-22 05:20:42 +02:00
|
|
|
HRESULT get_system_fontcollection(IDWriteFontCollection **collection)
|
|
|
|
{
|
|
|
|
if (!system_collection)
|
|
|
|
{
|
|
|
|
struct dwrite_fontcollection *This;
|
|
|
|
LOGFONTW lf;
|
|
|
|
HDC hdc;
|
|
|
|
|
|
|
|
*collection = NULL;
|
2012-10-21 03:43:01 +02:00
|
|
|
|
2012-10-22 05:20:42 +02:00
|
|
|
This = heap_alloc(sizeof(struct dwrite_fontcollection));
|
|
|
|
if (!This) return E_OUTOFMEMORY;
|
2012-10-21 06:24:35 +02:00
|
|
|
|
2012-10-22 05:20:42 +02:00
|
|
|
This->IDWriteFontCollection_iface.lpVtbl = &systemfontcollectionvtbl;
|
|
|
|
This->alloc = 50;
|
|
|
|
This->count = 0;
|
|
|
|
This->families = heap_alloc(This->alloc*sizeof(WCHAR*));
|
2012-10-21 06:24:35 +02:00
|
|
|
|
2012-10-22 05:20:42 +02:00
|
|
|
TRACE("building system font collection:\n");
|
|
|
|
|
|
|
|
hdc = CreateCompatibleDC(0);
|
|
|
|
memset(&lf, 0, sizeof(lf));
|
|
|
|
lf.lfCharSet = DEFAULT_CHARSET;
|
|
|
|
lf.lfPitchAndFamily = DEFAULT_PITCH;
|
|
|
|
lf.lfFaceName[0] = 0;
|
|
|
|
EnumFontFamiliesExW(hdc, &lf, enum_font_families, (LPARAM)This, 0);
|
|
|
|
DeleteDC(hdc);
|
|
|
|
|
|
|
|
if (InterlockedCompareExchangePointer((void**)&system_collection, &This->IDWriteFontCollection_iface, NULL))
|
|
|
|
release_font_collection(&This->IDWriteFontCollection_iface);
|
|
|
|
}
|
2012-10-21 06:24:35 +02:00
|
|
|
|
2012-10-22 05:20:42 +02:00
|
|
|
*collection = system_collection;
|
2012-10-21 03:43:01 +02:00
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2012-10-07 18:29:39 +02:00
|
|
|
static HRESULT create_fontfamily(const WCHAR *familyname, IDWriteFontFamily **family)
|
2012-08-25 11:11:31 +02:00
|
|
|
{
|
|
|
|
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;
|
2012-10-07 18:29:39 +02:00
|
|
|
This->familyname = heap_strdupW(familyname);
|
2012-08-25 11:11:31 +02:00
|
|
|
|
|
|
|
*family = &This->IDWriteFontFamily_iface;
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2012-10-12 14:43:57 +02:00
|
|
|
static void get_font_properties(struct dwrite_font *font, HDC hdc)
|
2012-10-10 14:37:55 +02:00
|
|
|
{
|
|
|
|
TT_OS2_V2 tt_os2;
|
2012-10-16 18:56:23 +02:00
|
|
|
TT_HEAD tt_head;
|
|
|
|
TT_POST tt_post;
|
2012-10-10 14:37:55 +02:00
|
|
|
LONG size;
|
|
|
|
|
2012-10-12 14:43:57 +02:00
|
|
|
/* default stretch and weight to normal */
|
|
|
|
font->stretch = DWRITE_FONT_STRETCH_NORMAL;
|
|
|
|
font->weight = DWRITE_FONT_WEIGHT_NORMAL;
|
2012-10-10 14:37:55 +02:00
|
|
|
|
2012-10-16 18:56:23 +02:00
|
|
|
memset(&font->metrics, 0, sizeof(font->metrics));
|
|
|
|
|
2012-10-10 14:37:55 +02:00
|
|
|
size = GetFontData(hdc, MS_OS2_TAG, 0, NULL, 0);
|
2012-10-12 14:43:57 +02:00
|
|
|
if (size != GDI_ERROR)
|
|
|
|
{
|
|
|
|
if (size > sizeof(tt_os2)) size = sizeof(tt_os2);
|
2012-10-10 14:37:55 +02:00
|
|
|
|
2012-10-12 14:43:57 +02:00
|
|
|
memset(&tt_os2, 0, sizeof(tt_os2));
|
|
|
|
if (GetFontData(hdc, MS_OS2_TAG, 0, &tt_os2, size) != size) return;
|
2012-10-10 14:37:55 +02:00
|
|
|
|
2012-10-12 14:43:57 +02:00
|
|
|
/* DWRITE_FONT_STRETCH enumeration values directly match font data values */
|
|
|
|
if (GET_BE_WORD(tt_os2.usWidthClass) <= DWRITE_FONT_STRETCH_ULTRA_EXPANDED)
|
|
|
|
font->stretch = GET_BE_WORD(tt_os2.usWidthClass);
|
2012-10-10 14:37:55 +02:00
|
|
|
|
2012-10-12 14:43:57 +02:00
|
|
|
font->weight = GET_BE_WORD(tt_os2.usWeightClass);
|
|
|
|
TRACE("stretch=%d, weight=%d\n", font->stretch, font->weight);
|
2012-10-16 18:56:23 +02:00
|
|
|
|
|
|
|
font->metrics.ascent = GET_BE_WORD(tt_os2.sTypoAscender);
|
|
|
|
font->metrics.descent = GET_BE_WORD(tt_os2.sTypoDescender);
|
|
|
|
font->metrics.lineGap = GET_BE_WORD(tt_os2.sTypoLineGap);
|
|
|
|
font->metrics.capHeight = GET_BE_WORD(tt_os2.sCapHeight);
|
|
|
|
font->metrics.xHeight = GET_BE_WORD(tt_os2.sxHeight);
|
|
|
|
font->metrics.strikethroughPosition = GET_BE_WORD(tt_os2.yStrikeoutPosition);
|
|
|
|
font->metrics.strikethroughThickness = GET_BE_WORD(tt_os2.yStrikeoutSize);
|
|
|
|
}
|
|
|
|
|
|
|
|
memset(&tt_head, 0, sizeof(tt_head));
|
|
|
|
if (GetFontData(hdc, MS_HEAD_TAG, 0, &tt_head, sizeof(tt_head)) != GDI_ERROR)
|
|
|
|
{
|
|
|
|
font->metrics.designUnitsPerEm = GET_BE_WORD(tt_head.unitsPerEm);
|
|
|
|
}
|
|
|
|
|
|
|
|
memset(&tt_post, 0, sizeof(tt_post));
|
|
|
|
if (GetFontData(hdc, MS_POST_TAG, 0, &tt_post, sizeof(tt_post)) != GDI_ERROR)
|
|
|
|
{
|
|
|
|
font->metrics.underlinePosition = GET_BE_WORD(tt_post.underlinePosition);
|
|
|
|
font->metrics.underlineThickness = GET_BE_WORD(tt_post.underlineThickness);
|
2012-10-12 14:43:57 +02:00
|
|
|
}
|
2012-10-10 14:37:55 +02:00
|
|
|
}
|
|
|
|
|
2012-08-13 05:46:43 +02:00
|
|
|
HRESULT create_font_from_logfont(const LOGFONTW *logfont, IDWriteFont **font)
|
2012-08-13 05:44:19 +02:00
|
|
|
{
|
2012-10-07 18:29:39 +02:00
|
|
|
const WCHAR* facename, *familyname;
|
2012-08-13 05:44:19 +02:00
|
|
|
struct dwrite_font *This;
|
2012-08-25 11:11:31 +02:00
|
|
|
IDWriteFontFamily *family;
|
2012-10-07 18:29:39 +02:00
|
|
|
OUTLINETEXTMETRICW *otm;
|
2012-08-25 11:11:31 +02:00
|
|
|
HRESULT hr;
|
2012-10-07 18:29:39 +02:00
|
|
|
HFONT hfont;
|
|
|
|
HDC hdc;
|
|
|
|
int ret;
|
2012-08-13 05:44:19 +02:00
|
|
|
|
2012-08-13 05:46:43 +02:00
|
|
|
*font = NULL;
|
|
|
|
|
2012-10-12 14:43:57 +02:00
|
|
|
This = heap_alloc(sizeof(struct dwrite_font));
|
|
|
|
if (!This) return E_OUTOFMEMORY;
|
|
|
|
|
2012-10-07 18:29:39 +02:00
|
|
|
hfont = CreateFontIndirectW(logfont);
|
2012-10-12 14:43:57 +02:00
|
|
|
if (!hfont)
|
|
|
|
{
|
|
|
|
heap_free(This);
|
|
|
|
return DWRITE_E_NOFONT;
|
|
|
|
}
|
2012-10-07 18:29:39 +02:00
|
|
|
|
|
|
|
hdc = CreateCompatibleDC(0);
|
|
|
|
SelectObject(hdc, hfont);
|
|
|
|
|
|
|
|
ret = GetOutlineTextMetricsW(hdc, 0, NULL);
|
|
|
|
otm = heap_alloc(ret);
|
2012-11-29 13:38:21 +01:00
|
|
|
if (!otm)
|
|
|
|
{
|
|
|
|
heap_free(This);
|
|
|
|
DeleteDC(hdc);
|
|
|
|
DeleteObject(hfont);
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
}
|
2012-10-07 18:29:39 +02:00
|
|
|
otm->otmSize = ret;
|
|
|
|
ret = GetOutlineTextMetricsW(hdc, otm->otmSize, otm);
|
|
|
|
|
2012-10-12 14:43:57 +02:00
|
|
|
get_font_properties(This, hdc);
|
2012-10-10 14:37:55 +02:00
|
|
|
|
2012-10-07 18:29:39 +02:00
|
|
|
DeleteDC(hdc);
|
|
|
|
DeleteObject(hfont);
|
|
|
|
|
|
|
|
facename = (WCHAR*)((char*)otm + (ptrdiff_t)otm->otmpFaceName);
|
|
|
|
familyname = (WCHAR*)((char*)otm + (ptrdiff_t)otm->otmpFamilyName);
|
|
|
|
TRACE("facename=%s, familyname=%s\n", debugstr_w(facename), debugstr_w(familyname));
|
|
|
|
|
|
|
|
hr = create_fontfamily(familyname, &family);
|
|
|
|
heap_free(otm);
|
2012-10-12 14:43:57 +02:00
|
|
|
if (hr != S_OK)
|
2012-08-25 11:11:31 +02:00
|
|
|
{
|
2012-10-12 14:43:57 +02:00
|
|
|
heap_free(This);
|
|
|
|
return hr;
|
2012-08-25 11:11:31 +02:00
|
|
|
}
|
2012-08-13 05:44:19 +02:00
|
|
|
|
|
|
|
This->IDWriteFont_iface.lpVtbl = &dwritefontvtbl;
|
|
|
|
This->ref = 1;
|
2012-10-07 21:03:52 +02:00
|
|
|
This->face = NULL;
|
2012-08-25 11:11:31 +02:00
|
|
|
This->family = family;
|
2012-08-13 05:46:43 +02:00
|
|
|
This->style = logfont->lfItalic ? DWRITE_FONT_STYLE_ITALIC : DWRITE_FONT_STYLE_NORMAL;
|
2012-10-24 22:05:01 +02:00
|
|
|
This->facename = heap_strdupW(logfont->lfFaceName);
|
2012-08-13 05:46:43 +02:00
|
|
|
|
2012-08-13 05:44:19 +02:00
|
|
|
*font = &This->IDWriteFont_iface;
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|