dwrite/tests: Add a font resource and use it for tests.

This commit is contained in:
Aric Stewart 2014-08-20 15:50:21 -05:00 committed by Alexandre Julliard
parent bde260411c
commit 2dec8d6fb2
5 changed files with 447 additions and 0 deletions

View File

@ -5,3 +5,8 @@ C_SRCS = \
analyzer.c \
font.c \
layout.c
FONT_SRCS = \
wine_test.sfd
RC_SRCS = resource.rc

View File

@ -41,6 +41,154 @@ static IDWriteFactory *factory;
static const WCHAR tahomaW[] = {'T','a','h','o','m','a',0};
static const WCHAR blahW[] = {'B','l','a','h','!',0};
/* Here is a functional custom font set of interfaces */
struct test_fontdatastream
{
IDWriteFontFileStream IDWriteFontFileStream_iface;
LONG ref;
LPVOID data;
DWORD size;
};
static inline struct test_fontdatastream *impl_from_IDWriteFontFileStream(IDWriteFontFileStream* iface)
{
return CONTAINING_RECORD(iface, struct test_fontdatastream, IDWriteFontFileStream_iface);
}
static HRESULT WINAPI fontdatastream_QueryInterface(IDWriteFontFileStream *iface, REFIID riid, void **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 fontdatastream_AddRef(IDWriteFontFileStream *iface)
{
struct test_fontdatastream *This = impl_from_IDWriteFontFileStream(iface);
ULONG ref = InterlockedIncrement(&This->ref);
return ref;
}
static ULONG WINAPI fontdatastream_Release(IDWriteFontFileStream *iface)
{
struct test_fontdatastream *This = impl_from_IDWriteFontFileStream(iface);
ULONG ref = InterlockedDecrement(&This->ref);
if (ref == 0)
HeapFree(GetProcessHeap(), 0, This);
return ref;
}
static HRESULT WINAPI fontdatastream_ReadFileFragment(IDWriteFontFileStream *iface, void const **fragment_start, UINT64 offset, UINT64 fragment_size, void **fragment_context)
{
struct test_fontdatastream *This = impl_from_IDWriteFontFileStream(iface);
*fragment_context = NULL;
if (offset+fragment_size > This->size)
{
*fragment_start = NULL;
return E_FAIL;
}
else
{
*fragment_start = (BYTE*)This->data + offset;
return S_OK;
}
}
static void WINAPI fontdatastream_ReleaseFileFragment(IDWriteFontFileStream *iface, void *fragment_context)
{
/* Do Nothing */
}
static HRESULT WINAPI fontdatastream_GetFileSize(IDWriteFontFileStream *iface, UINT64 *size)
{
struct test_fontdatastream *This = impl_from_IDWriteFontFileStream(iface);
*size = This->size;
return S_OK;
}
static HRESULT WINAPI fontdatastream_GetLastWriteTime(IDWriteFontFileStream *iface, UINT64 *last_writetime)
{
return E_NOTIMPL;
}
static const IDWriteFontFileStreamVtbl fontdatastreamvtbl =
{
fontdatastream_QueryInterface,
fontdatastream_AddRef,
fontdatastream_Release,
fontdatastream_ReadFileFragment,
fontdatastream_ReleaseFileFragment,
fontdatastream_GetFileSize,
fontdatastream_GetLastWriteTime
};
static HRESULT create_fontdatastream(LPVOID data, UINT size, IDWriteFontFileStream** iface)
{
struct test_fontdatastream *This = HeapAlloc(GetProcessHeap(), 0, sizeof(struct test_fontdatastream));
if (!This)
return E_OUTOFMEMORY;
This->data = data;
This->size = size;
This->ref = 1;
This->IDWriteFontFileStream_iface.lpVtbl = &fontdatastreamvtbl;
*iface = &This->IDWriteFontFileStream_iface;
return S_OK;
}
static HRESULT WINAPI resourcefontfileloader_QueryInterface(IDWriteFontFileLoader *iface, REFIID riid, void **obj)
{
if (IsEqualIID(riid, &IID_IUnknown) || IsEqualIID(riid, &IID_IDWriteFontFileLoader))
{
*obj = iface;
return S_OK;
}
*obj = NULL;
return E_NOINTERFACE;
}
static ULONG WINAPI resourcefontfileloader_AddRef(IDWriteFontFileLoader *iface)
{
return 2;
}
static ULONG WINAPI resourcefontfileloader_Release(IDWriteFontFileLoader *iface)
{
return 1;
}
static HRESULT WINAPI resourcefontfileloader_CreateStreamFromKey(IDWriteFontFileLoader *iface, const void *fontFileReferenceKey, UINT32 fontFileReferenceKeySize, IDWriteFontFileStream **fontFileStream)
{
LPVOID data;
DWORD size;
HGLOBAL mem;
mem = LoadResource(GetModuleHandleA(NULL), *(HRSRC*)fontFileReferenceKey);
ok(mem != NULL, "Failed to lock font resource\n");
if (mem)
{
size = SizeofResource(GetModuleHandleA(NULL), *(HRSRC*)fontFileReferenceKey);
data = LockResource(mem);
return create_fontdatastream(data, size, fontFileStream);
}
return E_FAIL;
}
static const struct IDWriteFontFileLoaderVtbl resourcefontfileloadervtbl = {
resourcefontfileloader_QueryInterface,
resourcefontfileloader_AddRef,
resourcefontfileloader_Release,
resourcefontfileloader_CreateStreamFromKey
};
static void test_CreateFontFromLOGFONT(void)
{
static const WCHAR tahomaspW[] = {'T','a','h','o','m','a',' ',0};
@ -762,6 +910,7 @@ static void test_FontLoader(void)
IDWriteFontFileLoader floader = { &dwritefontfileloadervtbl };
IDWriteFontFileLoader floader2 = { &dwritefontfileloadervtbl };
IDWriteFontFileLoader floader3 = { &dwritefontfileloadervtbl };
IDWriteFontFileLoader rloader = { &resourcefontfileloadervtbl };
IDWriteFontFile *ffile = NULL;
BOOL support = 1;
DWRITE_FONT_FILE_TYPE type = 1;
@ -769,6 +918,7 @@ static void test_FontLoader(void)
UINT32 count = 1;
IDWriteFontFace *fface = NULL;
HRESULT hr;
HRSRC font;
hr = IDWriteFactory_RegisterFontFileLoader(factory, NULL);
ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
@ -778,6 +928,8 @@ static void test_FontLoader(void)
ok(hr == S_OK, "got 0x%08x\n", hr);
hr = IDWriteFactory_RegisterFontFileLoader(factory, &floader);
ok(hr == DWRITE_E_ALREADYREGISTERED, "got 0x%08x\n", hr);
hr = IDWriteFactory_RegisterFontFileLoader(factory, &rloader);
ok(hr == S_OK, "got 0x%08x\n", hr);
hr = IDWriteFactory_CreateCustomFontFileReference(factory, "test", 4, &floader, &ffile);
ok(hr == S_OK, "got 0x%08x\n", hr);
@ -807,12 +959,34 @@ static void test_FontLoader(void)
ok(hr == 0x8faecafe, "got 0x%08x\n", hr);
IDWriteFontFile_Release(ffile);
font = FindResourceA(GetModuleHandleA(NULL), (LPCSTR)MAKEINTRESOURCE(1), (LPCSTR)RT_RCDATA);
ok(font != NULL, "Failed to find font resource\n");
if (font)
{
hr = IDWriteFactory_CreateCustomFontFileReference(factory, &font, sizeof(HRSRC), &rloader, &ffile);
ok(hr == S_OK, "got 0x%08x\n", hr);
IDWriteFontFile_Analyze(ffile, &support, &type, &face, &count);
ok(hr == S_OK, "got 0x%08x\n", hr);
ok(support == TRUE, "got %i\n", support);
ok(type == DWRITE_FONT_FILE_TYPE_TRUETYPE, "got %i\n", type);
ok(face == DWRITE_FONT_FACE_TYPE_TRUETYPE, "got %i\n", face);
ok(count == 1, "got %i\n", count);
hr = IDWriteFactory_CreateFontFace(factory, face, 1, &ffile, 0, 0, &fface);
ok(hr == S_OK, "got 0x%08x\n",hr);
IDWriteFontFace_Release(fface);
IDWriteFontFile_Release(ffile);
}
hr = IDWriteFactory_UnregisterFontFileLoader(factory, &floader);
ok(hr == S_OK, "got 0x%08x\n", hr);
hr = IDWriteFactory_UnregisterFontFileLoader(factory, &floader);
ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
hr = IDWriteFactory_UnregisterFontFileLoader(factory, &floader2);
ok(hr == S_OK, "got 0x%08x\n", hr);
hr = IDWriteFactory_UnregisterFontFileLoader(factory, &rloader);
ok(hr == S_OK, "got 0x%08x\n", hr);
}
START_TEST(font)

View File

@ -0,0 +1,24 @@
/*
* Resources for dwrite test suite.
*
* Copyright 2010 Dmitry Timoshkov
*
* 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
*/
#include "windef.h"
/* @makedep: wine_test.ttf */
1 RCDATA wine_test.ttf

View File

@ -0,0 +1,244 @@
SplineFontDB: 3.0
FontName: wine_test
FullName: wine_test
FamilyName: wine_test
Weight: Medium
Copyright: Copyright (c) 2010 Dmitry Timoshkov
Version: 001.000
ItalicAngle: 0
UnderlinePosition: -205
UnderlineWidth: 102
Ascent: 1638
Descent: 410
sfntRevision: 0x00010000
LayerCount: 2
Layer: 0 1 "Back" 1
Layer: 1 1 "Fore" 0
XUID: [1021 905 592216984 1247726]
FSType: 0
OS2Version: 2
OS2_WeightWidthSlopeOnly: 0
OS2_UseTypoMetrics: 1
PfmFamily: 17
TTFWeight: 500
TTFWidth: 5
LineGap: 184
VLineGap: 0
Panose: 2 0 6 3 0 0 0 0 0 0
OS2TypoAscent: 0
OS2TypoAOffset: 1
OS2TypoDescent: 0
OS2TypoDOffset: 1
OS2TypoLinegap: 184
OS2WinAscent: 1638
OS2WinAOffset: 0
OS2WinDescent: 410
OS2WinDOffset: 0
HheadAscent: 0
HheadAOffset: 1
HheadDescent: 0
HheadDOffset: 1
OS2SubXSize: 1331
OS2SubYSize: 1433
OS2SubXOff: 0
OS2SubYOff: 286
OS2SupXSize: 1331
OS2SupYSize: 1433
OS2SupXOff: 0
OS2SupYOff: 983
OS2StrikeYSize: 102
OS2StrikeYPos: 530
OS2Vendor: 'Wine'
OS2CodePages: 00000001.00000000
OS2UnicodeRanges: 00000001.00000000.00000000.00000000
MarkAttachClasses: 1
DEI: 91125
ShortTable: cvt 2
68
1297
EndShort
ShortTable: maxp 16
1
0
4
8
2
0
0
2
0
1
1
0
64
46
0
0
EndShort
LangName: 1033 "" "" "" "Wine : wine_test : 4-11-2010"
GaspTable: 1 65535 2 0
Encoding: UnicodeBmp
UnicodeInterp: none
NameList: Adobe Glyph List
DisplaySize: -24
AntiAlias: 1
FitToEm: 1
WinInfo: 48 16 4
BeginPrivate: 0
EndPrivate
BeginChars: 65539 7
StartChar: .notdef
Encoding: 65536 -1 0
AltUni2: 00fffe.ffffffff.0 00fffd.ffffffff.0 00fffc.ffffffff.0 00fffb.ffffffff.0
Width: 748
Flags: W
TtInstrs:
PUSHB_2
1
0
MDAP[rnd]
ALIGNRP
PUSHB_3
7
4
0
MIRP[min,rnd,black]
SHP[rp2]
PUSHB_2
6
5
MDRP[rp0,min,rnd,grey]
ALIGNRP
PUSHB_3
3
2
0
MIRP[min,rnd,black]
SHP[rp2]
SVTCA[y-axis]
PUSHB_2
3
0
MDAP[rnd]
ALIGNRP
PUSHB_3
5
4
0
MIRP[min,rnd,black]
SHP[rp2]
PUSHB_3
7
6
1
MIRP[rp0,min,rnd,grey]
ALIGNRP
PUSHB_3
1
2
0
MIRP[min,rnd,black]
SHP[rp2]
EndTTInstrs
LayerCount: 2
Fore
SplineSet
68 0 m 1,0,-1
68 1365 l 1,1,-1
612 1365 l 1,2,-1
612 0 l 1,3,-1
68 0 l 1,0,-1
136 68 m 1,4,-1
544 68 l 1,5,-1
544 1297 l 1,6,-1
136 1297 l 1,7,-1
136 68 l 1,4,-1
EndSplineSet
EndChar
StartChar: .null
Encoding: 65537 -1 1
Width: 0
Flags: W
LayerCount: 2
EndChar
StartChar: nonmarkingreturn
Encoding: 65538 -1 2
Width: 682
Flags: W
LayerCount: 2
EndChar
StartChar: exclam
Encoding: 33 33 3
Width: 0
Flags: W
LayerCount: 2
EndChar
StartChar: dieresis
Encoding: 168 168 4
Width: 1000
VWidth: 0
Flags: W
LayerCount: 2
Fore
SplineSet
620.215 824.429 m 1,0,1
760.84 777.554 760.84 777.554 713.965 636.929 c 1,2,-1
620.215 824.429 l 1,0,1
154.883 324.971 m 0,3,-1
254.492 773.213 m 1,4,5
310.707 834.805 310.707 834.805 374.609 767.354 c 1,6,7
410.471 728.672 410.471 728.672 374.609 691.182 c 0,8,9
308.375 621.934 308.375 621.934 254.492 688.252 c 0,10,11
216.406 735.127 216.406 735.127 254.492 773.213 c 1,4,5
254.492 773.213 m 1,12,13
216.406 735.127 216.406 735.127 254.492 688.252 c 0,14,15
308.375 621.934 308.375 621.934 374.609 691.182 c 0,16,17
410.471 728.672 410.471 728.672 374.609 767.354 c 1,18,19
310.707 834.805 310.707 834.805 254.492 773.213 c 1,12,13
EndSplineSet
EndChar
StartChar: A
Encoding: 65 65 5
Width: 1000
VWidth: 0
Flags: WO
LayerCount: 2
Fore
SplineSet
459 1258 m 25,0,-1
462 1639 l 1,1,-1
389 1638 l 1,2,-1
492 1815 l 1,3,-1
609 1638.5 l 1,4,-1
531 1637.5 l 1,5,-1
523 1258 l 1,6,-1
459 1258 l 25,0,-1
EndSplineSet
EndChar
StartChar: D
Encoding: 68 68 6
Width: 1000
VWidth: 0
Flags: WO
LayerCount: 2
Fore
SplineSet
461 -30.7998 m 25,0,-1
464 -411.8 l 1,1,-1
391 -410.8 l 1,2,-1
494 -587.8 l 1,3,-1
611 -411.3 l 1,4,-1
533 -410.3 l 1,5,-1
525 -30.7998 l 1,6,-1
461 -30.7998 l 25,0,-1
EndSplineSet
EndChar
EndChars
EndSplineFont

Binary file not shown.