[gdi32 3/3] Support adding font resources files (.fot) created with CreateScalableFontResource
Jeremy White
jwhite at winehq.org
Wed Apr 9 22:37:55 CDT 2008
---
dlls/gdi32/font.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 52 insertions(+), 0 deletions(-)
diff --git a/dlls/gdi32/font.c b/dlls/gdi32/font.c
index 1d0b08a..5c4f46b 100644
--- a/dlls/gdi32/font.c
+++ b/dlls/gdi32/font.c
@@ -2590,6 +2590,46 @@ static int FONT_WriteScalableFont(LPCWSTR output_name, FONTDIR16 *fontdir, LPCST
return rc;
}
+/*----------------------------------------------------------------------------
+** FONT_ReadScaledFontFile
+** If the input file is an NE format binary and clearly a .fot file,
+** return the name of the .ttf file originally passed when creating the
+** scalable font resource
+**--------------------------------------------------------------------------*/
+static LPSTR FONT_ReadScaledFontFile(LPCWSTR nefile)
+{
+ HANDLE h;
+ char buffer[2048];
+ DWORD bytes_read;
+ LPSTR ret = NULL;
+ TRACE("(%s)\n", debugstr_w(nefile));
+
+ h = CreateFileW(nefile, FILE_SHARE_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
+ if (h == INVALID_HANDLE_VALUE)
+ {
+ TRACE("Error: could not open %s for writing\n", debugstr_w(nefile));
+ return NULL;
+ }
+
+ if(ReadFile(h, buffer, sizeof(buffer), &bytes_read, NULL))
+ {
+ if (bytes_read > 0x480)
+ {
+ WORD dos_magic = * ((WORD *)buffer);
+ WORD ne_magic = * ((WORD *)buffer + 0x40);
+ if (dos_magic == IMAGE_DOS_SIGNATURE && ne_magic == IMAGE_OS2_SIGNATURE)
+ {
+ ret = HeapAlloc(GetProcessHeap(), 0, strlen(buffer + 0x400) + 1);
+ strcpy(ret, buffer + 0x400);
+ }
+ }
+ }
+
+ CloseHandle(h);
+ return ret;
+}
+
+
/***********************************************************************
* CreateScalableFontResourceA (GDI32.@)
*/
@@ -3304,6 +3344,18 @@ INT WINAPI AddFontResourceExW( LPCWSTR str, DWORD fl, PVOID pdv )
ret = num_resources;
FreeLibrary(hModule);
}
+
+ /* If it's an unknown type, see if it is a .FOT file created with CreateScalableFontResource */
+ if (ret == 0)
+ {
+ LPSTR scaled_font;
+ scaled_font = FONT_ReadScaledFontFile(str);
+ if (scaled_font)
+ {
+ ret = AddFontResourceExA(scaled_font, fl, pdv);
+ HeapFree( GetProcessHeap(), 0, scaled_font);
+ }
+ }
}
return ret;
}
--
1.5.3.7
More information about the wine-patches
mailing list