Skip to content
This repository was archived by the owner on Mar 7, 2025. It is now read-only.

Commit b62fe09

Browse files
hughbeakoeplinger
authored andcommitted
Add FontCollection tests and fix compat bugs (#93)
* Add FontCollection tests and fix compat bugs The font files were created by @hughbe via a tool.
1 parent a7bc3c6 commit b62fe09

File tree

4 files changed

+349
-34
lines changed

4 files changed

+349
-34
lines changed

src/font.c

+14-8
Original file line numberDiff line numberDiff line change
@@ -144,13 +144,15 @@ GdipDeletePrivateFontCollection (GpFontCollection **font_collection)
144144
GdipFree ((void *)*font_collection);
145145
}
146146

147+
*font_collection = NULL;
147148
return Ok;
148149
}
149150

150151
GpStatus WINGDIPAPI
151-
GdipPrivateAddFontFile (GpFontCollection *font_collection, GDIPCONST WCHAR *filename)
152+
GdipPrivateAddFontFile (GpFontCollection *font_collection, GDIPCONST WCHAR *filename)
152153
{
153154
BYTE *file;
155+
FILE *fileHandle;
154156

155157
if (!font_collection || !filename)
156158
return InvalidParameter;
@@ -159,6 +161,13 @@ GdipPrivateAddFontFile (GpFontCollection *font_collection, GDIPCONST WCHAR *fil
159161
if (!file)
160162
return OutOfMemory;
161163

164+
fileHandle = fopen ((char *)file, "r");
165+
if (!fileHandle) {
166+
GdipFree (file);
167+
return FileNotFound;
168+
}
169+
170+
fclose (fileHandle);
162171
FcConfigAppFontAddFile (font_collection->config, file);
163172

164173
GdipFree (file);
@@ -290,13 +299,13 @@ GdipGetFontCollectionFamilyList (GpFontCollection *font_collection, INT num_soug
290299
if (font_collection->config)
291300
gdip_createPrivateFontSet (font_collection);
292301

293-
for (i = 0; i < font_collection->fontset->nfont; i++) {
302+
for (i = 0; i < num_sought && i < font_collection->fontset->nfont; i++) {
294303
gdip_createFontFamily(&gpfamilies[i]);
295304
gpfamilies[i]->pattern = font_collection->fontset->fonts[i];
296305
gpfamilies[i]->allocated = FALSE;
297306
}
298307

299-
*num_found = font_collection->fontset->nfont;
308+
*num_found = i;
300309
return Ok;
301310
}
302311

@@ -1127,7 +1136,6 @@ GdipCreateFontFromLogfontW(void *hdc, GDIPCONST LOGFONTW *logfont, GpFont **font
11271136
GpStatus WINGDIPAPI
11281137
GdipPrivateAddMemoryFont(GpFontCollection *fontCollection, GDIPCONST void *memory, INT length)
11291138
{
1130-
FcBool result;
11311139
FcChar8 fontfile[256];
11321140
int f;
11331141

@@ -1152,14 +1160,12 @@ GdipPrivateAddMemoryFont(GpFontCollection *fontCollection, GDIPCONST void *memor
11521160
}
11531161
close(f);
11541162

1155-
/* FIXME - this doesn't seems to catch "bad" (e.g. invalid) font files */
1156-
result = FcConfigAppFontAddFile (fontCollection->config, fontfile);
1157-
1163+
FcConfigAppFontAddFile (fontCollection->config, fontfile);
11581164
/* FIXME - May we delete our temporary font file or does
11591165
FcConfigAppFontAddFile just reference our file? */
11601166
/* unlink(fontfile); */
11611167

1162-
return result ? Ok : FileNotFound;
1168+
return Ok;
11631169
}
11641170

11651171
GpStatus WINGDIPAPI

tests/test.otf

371 KB
Binary file not shown.

tests/test.ttf

403 KB
Binary file not shown.

0 commit comments

Comments
 (0)