mirror of
git://source.winehq.org/git/wine.git
synced 2024-11-05 18:01:34 +00:00
dwrite: Add the system font collection to the dwrite factory object.
This commit is contained in:
parent
53869e19eb
commit
f49c740907
4 changed files with 69 additions and 66 deletions
|
@ -92,7 +92,6 @@ extern HRESULT get_gdiinterop(IDWriteGdiInterop**) DECLSPEC_HIDDEN;
|
||||||
extern HRESULT create_localizedstrings(IDWriteLocalizedStrings**) DECLSPEC_HIDDEN;
|
extern HRESULT create_localizedstrings(IDWriteLocalizedStrings**) DECLSPEC_HIDDEN;
|
||||||
extern HRESULT add_localizedstring(IDWriteLocalizedStrings*,const WCHAR*,const WCHAR*) DECLSPEC_HIDDEN;
|
extern HRESULT add_localizedstring(IDWriteLocalizedStrings*,const WCHAR*,const WCHAR*) DECLSPEC_HIDDEN;
|
||||||
extern HRESULT get_system_fontcollection(IDWriteFontCollection**) DECLSPEC_HIDDEN;
|
extern HRESULT get_system_fontcollection(IDWriteFontCollection**) DECLSPEC_HIDDEN;
|
||||||
extern void release_system_fontcollection(void) DECLSPEC_HIDDEN;
|
|
||||||
extern HRESULT get_textanalyzer(IDWriteTextAnalyzer**) DECLSPEC_HIDDEN;
|
extern HRESULT get_textanalyzer(IDWriteTextAnalyzer**) DECLSPEC_HIDDEN;
|
||||||
extern HRESULT create_font_file(IDWriteFontFileLoader *loader, const void *reference_key, UINT32 key_size, IDWriteFontFile **font_file) DECLSPEC_HIDDEN;
|
extern HRESULT create_font_file(IDWriteFontFileLoader *loader, const void *reference_key, UINT32 key_size, IDWriteFontFile **font_file) DECLSPEC_HIDDEN;
|
||||||
extern HRESULT create_localfontfileloader(IDWriteLocalFontFileLoader** iface) DECLSPEC_HIDDEN;
|
extern HRESULT create_localfontfileloader(IDWriteLocalFontFileLoader** iface) DECLSPEC_HIDDEN;
|
||||||
|
|
|
@ -127,14 +127,13 @@ typedef struct
|
||||||
|
|
||||||
struct dwrite_fontcollection {
|
struct dwrite_fontcollection {
|
||||||
IDWriteFontCollection IDWriteFontCollection_iface;
|
IDWriteFontCollection IDWriteFontCollection_iface;
|
||||||
|
LONG ref;
|
||||||
|
|
||||||
WCHAR **families;
|
WCHAR **families;
|
||||||
UINT32 count;
|
UINT32 count;
|
||||||
int alloc;
|
int alloc;
|
||||||
};
|
};
|
||||||
|
|
||||||
static IDWriteFontCollection *system_collection;
|
|
||||||
|
|
||||||
struct dwrite_fontfamily {
|
struct dwrite_fontfamily {
|
||||||
IDWriteFontFamily IDWriteFontFamily_iface;
|
IDWriteFontFamily IDWriteFontFamily_iface;
|
||||||
LONG ref;
|
LONG ref;
|
||||||
|
@ -844,14 +843,30 @@ static HRESULT WINAPI dwritefontcollection_QueryInterface(IDWriteFontCollection
|
||||||
return E_NOINTERFACE;
|
return E_NOINTERFACE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static ULONG WINAPI dwritesysfontcollection_AddRef(IDWriteFontCollection *iface)
|
static ULONG WINAPI dwritefontcollection_AddRef(IDWriteFontCollection *iface)
|
||||||
{
|
{
|
||||||
return 2;
|
struct dwrite_fontcollection *This = impl_from_IDWriteFontCollection(iface);
|
||||||
|
ULONG ref = InterlockedIncrement(&This->ref);
|
||||||
|
TRACE("(%p)->(%d)\n", This, ref);
|
||||||
|
return ref;
|
||||||
}
|
}
|
||||||
|
|
||||||
static ULONG WINAPI dwritesysfontcollection_Release(IDWriteFontCollection *iface)
|
static ULONG WINAPI dwritefontcollection_Release(IDWriteFontCollection *iface)
|
||||||
{
|
{
|
||||||
return 1;
|
unsigned int i;
|
||||||
|
struct dwrite_fontcollection *This = impl_from_IDWriteFontCollection(iface);
|
||||||
|
ULONG ref = InterlockedDecrement(&This->ref);
|
||||||
|
TRACE("(%p)->(%d)\n", This, ref);
|
||||||
|
|
||||||
|
if (!ref)
|
||||||
|
{
|
||||||
|
for (i = 0; i < This->count; i++)
|
||||||
|
heap_free(This->families[i]);
|
||||||
|
heap_free(This->families);
|
||||||
|
heap_free(This);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ref;
|
||||||
}
|
}
|
||||||
|
|
||||||
static UINT32 WINAPI dwritefontcollection_GetFontFamilyCount(IDWriteFontCollection *iface)
|
static UINT32 WINAPI dwritefontcollection_GetFontFamilyCount(IDWriteFontCollection *iface)
|
||||||
|
@ -904,10 +919,10 @@ static HRESULT WINAPI dwritefontcollection_GetFontFromFontFace(IDWriteFontCollec
|
||||||
return E_NOTIMPL;
|
return E_NOTIMPL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static const IDWriteFontCollectionVtbl systemfontcollectionvtbl = {
|
static const IDWriteFontCollectionVtbl fontcollectionvtbl = {
|
||||||
dwritefontcollection_QueryInterface,
|
dwritefontcollection_QueryInterface,
|
||||||
dwritesysfontcollection_AddRef,
|
dwritefontcollection_AddRef,
|
||||||
dwritesysfontcollection_Release,
|
dwritefontcollection_Release,
|
||||||
dwritefontcollection_GetFontFamilyCount,
|
dwritefontcollection_GetFontFamilyCount,
|
||||||
dwritefontcollection_GetFontFamily,
|
dwritefontcollection_GetFontFamily,
|
||||||
dwritefontcollection_FindFamilyName,
|
dwritefontcollection_FindFamilyName,
|
||||||
|
@ -938,56 +953,34 @@ static INT CALLBACK enum_font_families(const LOGFONTW *lf, const TEXTMETRICW *tm
|
||||||
return add_family_syscollection(collection, lf->lfFaceName) == S_OK;
|
return add_family_syscollection(collection, lf->lfFaceName) == S_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void release_font_collection(IDWriteFontCollection *iface)
|
|
||||||
{
|
|
||||||
struct dwrite_fontcollection *This = impl_from_IDWriteFontCollection(iface);
|
|
||||||
unsigned int i;
|
|
||||||
|
|
||||||
for (i = 0; i < This->count; i++)
|
|
||||||
heap_free(This->families[i]);
|
|
||||||
heap_free(This->families);
|
|
||||||
heap_free(This);
|
|
||||||
}
|
|
||||||
|
|
||||||
void release_system_fontcollection(void)
|
|
||||||
{
|
|
||||||
if (system_collection)
|
|
||||||
release_font_collection(system_collection);
|
|
||||||
}
|
|
||||||
|
|
||||||
HRESULT get_system_fontcollection(IDWriteFontCollection **collection)
|
HRESULT get_system_fontcollection(IDWriteFontCollection **collection)
|
||||||
{
|
{
|
||||||
if (!system_collection)
|
struct dwrite_fontcollection *This;
|
||||||
{
|
LOGFONTW lf;
|
||||||
struct dwrite_fontcollection *This;
|
HDC hdc;
|
||||||
LOGFONTW lf;
|
|
||||||
HDC hdc;
|
|
||||||
|
|
||||||
*collection = NULL;
|
*collection = NULL;
|
||||||
|
|
||||||
This = heap_alloc(sizeof(struct dwrite_fontcollection));
|
This = heap_alloc(sizeof(struct dwrite_fontcollection));
|
||||||
if (!This) return E_OUTOFMEMORY;
|
if (!This) return E_OUTOFMEMORY;
|
||||||
|
|
||||||
This->IDWriteFontCollection_iface.lpVtbl = &systemfontcollectionvtbl;
|
This->IDWriteFontCollection_iface.lpVtbl = &fontcollectionvtbl;
|
||||||
This->alloc = 50;
|
This->ref = 1;
|
||||||
This->count = 0;
|
This->alloc = 50;
|
||||||
This->families = heap_alloc(This->alloc*sizeof(WCHAR*));
|
This->count = 0;
|
||||||
|
This->families = heap_alloc(This->alloc*sizeof(WCHAR*));
|
||||||
|
|
||||||
TRACE("building system font collection:\n");
|
TRACE("building system font collection:\n");
|
||||||
|
|
||||||
hdc = CreateCompatibleDC(0);
|
hdc = CreateCompatibleDC(0);
|
||||||
memset(&lf, 0, sizeof(lf));
|
memset(&lf, 0, sizeof(lf));
|
||||||
lf.lfCharSet = DEFAULT_CHARSET;
|
lf.lfCharSet = DEFAULT_CHARSET;
|
||||||
lf.lfPitchAndFamily = DEFAULT_PITCH;
|
lf.lfPitchAndFamily = DEFAULT_PITCH;
|
||||||
lf.lfFaceName[0] = 0;
|
lf.lfFaceName[0] = 0;
|
||||||
EnumFontFamiliesExW(hdc, &lf, enum_font_families, (LPARAM)This, 0);
|
EnumFontFamiliesExW(hdc, &lf, enum_font_families, (LPARAM)This, 0);
|
||||||
DeleteDC(hdc);
|
DeleteDC(hdc);
|
||||||
|
|
||||||
if (InterlockedCompareExchangePointer((void**)&system_collection, &This->IDWriteFontCollection_iface, NULL))
|
*collection = &This->IDWriteFontCollection_iface;
|
||||||
release_font_collection(&This->IDWriteFontCollection_iface);
|
|
||||||
}
|
|
||||||
|
|
||||||
*collection = system_collection;
|
|
||||||
|
|
||||||
return S_OK;
|
return S_OK;
|
||||||
}
|
}
|
||||||
|
|
|
@ -229,7 +229,7 @@ static struct layout_range *alloc_layout_range(struct dwrite_textlayout *layout,
|
||||||
range->strikethrough = FALSE;
|
range->strikethrough = FALSE;
|
||||||
range->collection = layout->format.collection;
|
range->collection = layout->format.collection;
|
||||||
if (range->collection)
|
if (range->collection)
|
||||||
IDWriteFontCollection_Release(range->collection);
|
IDWriteFontCollection_AddRef(range->collection);
|
||||||
|
|
||||||
return range;
|
return range;
|
||||||
}
|
}
|
||||||
|
@ -1781,14 +1781,7 @@ HRESULT create_textformat(const WCHAR *family_name, IDWriteFontCollection *colle
|
||||||
IDWriteFontCollection_AddRef(collection);
|
IDWriteFontCollection_AddRef(collection);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
ERR("Collection should always be set\n");
|
||||||
HRESULT hr = get_system_fontcollection(&This->format.collection);
|
|
||||||
if (hr != S_OK)
|
|
||||||
{
|
|
||||||
IDWriteTextFormat_Release(&This->IDWriteTextFormat_iface);
|
|
||||||
return hr;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
*format = &This->IDWriteTextFormat_iface;
|
*format = &This->IDWriteTextFormat_iface;
|
||||||
|
|
||||||
|
|
|
@ -43,10 +43,6 @@ BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD reason, LPVOID reserved)
|
||||||
case DLL_PROCESS_ATTACH:
|
case DLL_PROCESS_ATTACH:
|
||||||
DisableThreadLibraryCalls( hinstDLL );
|
DisableThreadLibraryCalls( hinstDLL );
|
||||||
break;
|
break;
|
||||||
case DLL_PROCESS_DETACH:
|
|
||||||
if (reserved) break;
|
|
||||||
release_system_fontcollection();
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
@ -364,6 +360,7 @@ struct dwritefactory{
|
||||||
LONG ref;
|
LONG ref;
|
||||||
|
|
||||||
IDWriteLocalFontFileLoader* localfontfileloader;
|
IDWriteLocalFontFileLoader* localfontfileloader;
|
||||||
|
IDWriteFontCollection *system_collection;
|
||||||
|
|
||||||
IDWriteFontCollectionLoader **loaders;
|
IDWriteFontCollectionLoader **loaders;
|
||||||
LONG loader_count;
|
LONG loader_count;
|
||||||
|
@ -422,6 +419,8 @@ static ULONG WINAPI dwritefactory_Release(IDWriteFactory *iface)
|
||||||
if (This->file_loaders[i])
|
if (This->file_loaders[i])
|
||||||
IDWriteFontFileLoader_Release(This->file_loaders[i]);
|
IDWriteFontFileLoader_Release(This->file_loaders[i]);
|
||||||
heap_free(This->file_loaders);
|
heap_free(This->file_loaders);
|
||||||
|
if (This->system_collection)
|
||||||
|
IDWriteFontCollection_Release(This->system_collection);
|
||||||
heap_free(This);
|
heap_free(This);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -431,13 +430,22 @@ static ULONG WINAPI dwritefactory_Release(IDWriteFactory *iface)
|
||||||
static HRESULT WINAPI dwritefactory_GetSystemFontCollection(IDWriteFactory *iface,
|
static HRESULT WINAPI dwritefactory_GetSystemFontCollection(IDWriteFactory *iface,
|
||||||
IDWriteFontCollection **collection, BOOL check_for_updates)
|
IDWriteFontCollection **collection, BOOL check_for_updates)
|
||||||
{
|
{
|
||||||
|
HRESULT hr = S_OK;
|
||||||
struct dwritefactory *This = impl_from_IDWriteFactory(iface);
|
struct dwritefactory *This = impl_from_IDWriteFactory(iface);
|
||||||
TRACE("(%p)->(%p %d)\n", This, collection, check_for_updates);
|
TRACE("(%p)->(%p %d)\n", This, collection, check_for_updates);
|
||||||
|
|
||||||
if (check_for_updates)
|
if (check_for_updates)
|
||||||
FIXME("checking for system font updates not implemented\n");
|
FIXME("checking for system font updates not implemented\n");
|
||||||
|
|
||||||
return get_system_fontcollection(collection);
|
if (!This->system_collection)
|
||||||
|
hr = get_system_fontcollection(&This->system_collection);
|
||||||
|
|
||||||
|
if (SUCCEEDED(hr))
|
||||||
|
IDWriteFontCollection_AddRef(This->system_collection);
|
||||||
|
|
||||||
|
*collection = This->system_collection;
|
||||||
|
|
||||||
|
return hr;
|
||||||
}
|
}
|
||||||
|
|
||||||
static HRESULT WINAPI dwritefactory_CreateCustomFontCollection(IDWriteFactory *iface,
|
static HRESULT WINAPI dwritefactory_CreateCustomFontCollection(IDWriteFactory *iface,
|
||||||
|
@ -642,6 +650,15 @@ static HRESULT WINAPI dwritefactory_CreateTextFormat(IDWriteFactory *iface, WCHA
|
||||||
struct dwritefactory *This = impl_from_IDWriteFactory(iface);
|
struct dwritefactory *This = impl_from_IDWriteFactory(iface);
|
||||||
TRACE("(%p)->(%s %p %d %d %d %f %s %p)\n", This, debugstr_w(family_name), collection, weight, style, stretch,
|
TRACE("(%p)->(%s %p %d %d %d %f %s %p)\n", This, debugstr_w(family_name), collection, weight, style, stretch,
|
||||||
size, debugstr_w(locale), format);
|
size, debugstr_w(locale), format);
|
||||||
|
|
||||||
|
if (!collection)
|
||||||
|
{
|
||||||
|
HRESULT hr = IDWriteFactory_GetSystemFontCollection(iface, &collection, FALSE);
|
||||||
|
if (hr != S_OK)
|
||||||
|
return hr;
|
||||||
|
/* Our ref count is 1 too many, since we will add ref in create_textformat */
|
||||||
|
IDWriteFontCollection_Release(This->system_collection);
|
||||||
|
}
|
||||||
return create_textformat(family_name, collection, weight, style, stretch, size, locale, format);
|
return create_textformat(family_name, collection, weight, style, stretch, size, locale, format);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -759,6 +776,7 @@ HRESULT WINAPI DWriteCreateFactory(DWRITE_FACTORY_TYPE type, REFIID riid, IUnkno
|
||||||
This->loaders = heap_alloc_zero(sizeof(*This->loaders) * 2);
|
This->loaders = heap_alloc_zero(sizeof(*This->loaders) * 2);
|
||||||
This->file_loader_count = 2;
|
This->file_loader_count = 2;
|
||||||
This->file_loaders = heap_alloc_zero(sizeof(*This->file_loaders) * 2);
|
This->file_loaders = heap_alloc_zero(sizeof(*This->file_loaders) * 2);
|
||||||
|
This->system_collection = NULL;
|
||||||
|
|
||||||
*factory = (IUnknown*)&This->IDWriteFactory_iface;
|
*factory = (IUnknown*)&This->IDWriteFactory_iface;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue