Skip to content

Commit

Permalink
win32_utf8: Add CreateFontIndirect() and CreateFontIndirectEx().
Browse files Browse the repository at this point in the history
  • Loading branch information
nmlgc committed Jun 1, 2014
1 parent 228c2c8 commit ff4ac97
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 29 deletions.
104 changes: 75 additions & 29 deletions src/gdi32_dll.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,35 +8,8 @@

#include "win32_utf8.h"

HFONT WINAPI CreateFontU(
__in int cHeight,
__in int cWidth,
__in int cEscapement,
__in int cOrientation,
__in int cWeight,
__in DWORD bItalic,
__in DWORD bUnderline,
__in DWORD bStrikeOut,
__in DWORD iCharSet,
__in DWORD iOutPrecision,
__in DWORD iClipPrecision,
__in DWORD iQuality,
__in DWORD iPitchAndFamily,
__in_opt LPCSTR pszFaceName
)
{
HFONT ret;
WCHAR_T_DEC(pszFaceName);
WCHAR_T_CONV_VLA(pszFaceName);
ret = CreateFontW(
cHeight, cWidth, cEscapement, cOrientation, cWeight, bItalic,
bUnderline, bStrikeOut, iCharSet, iOutPrecision, iClipPrecision,
iQuality, iPitchAndFamily, pszFaceName_w
);
WCHAR_T_FREE(pszFaceName);
return ret;
}

/// Font conversion helpers
/// -----------------------
static LOGFONTA* LogfontWToA(LOGFONTA *a, const LOGFONTW *w)
{
if(w) {
Expand Down Expand Up @@ -76,6 +49,24 @@ static ENUMLOGFONTEXDVA* EnumLogfontExDVWToA(ENUMLOGFONTEXDVA *a, const ENUMLOGF
return w ? a : NULL;
}

static ENUMLOGFONTEXDVW* EnumLogfontExDVAToW(ENUMLOGFONTEXDVW *w, const ENUMLOGFONTEXDVA *a)
{
if(w) {
const ENUMLOGFONTEXA *elfe_a = &a->elfEnumLogfontEx;
ENUMLOGFONTEXW *elfe_w = &w->elfEnumLogfontEx;
DWORD dv_sizediff = (
MM_MAX_NUMAXES - min(a->elfDesignVector.dvNumAxes, MM_MAX_NUMAXES)
) * sizeof(LONG);

LogfontAToW(&elfe_w->elfLogFont, &elfe_a->elfLogFont);
StringToUTF16(elfe_w->elfFullName, (char*)elfe_a->elfFullName, LF_FULLFACESIZE);
StringToUTF16(elfe_w->elfStyle, (char*)elfe_a->elfStyle, LF_FACESIZE);
StringToUTF16(elfe_w->elfScript, (char*)elfe_a->elfScript, LF_FACESIZE);
memcpy(&w->elfDesignVector, &a->elfDesignVector, sizeof(DESIGNVECTOR) - dv_sizediff);
}
return a ? w : NULL;
}

static ENUMTEXTMETRICA* EnumTextmetricWToA(ENUMTEXTMETRICA *a, const ENUMTEXTMETRICW *w)
{
if(w) {
Expand All @@ -100,6 +91,61 @@ static ENUMTEXTMETRICA* EnumTextmetricWToA(ENUMTEXTMETRICA *a, const ENUMTEXTMET
}
return w ? a : NULL;
}
/// -----------------------

HFONT WINAPI CreateFontU(
__in int cHeight,
__in int cWidth,
__in int cEscapement,
__in int cOrientation,
__in int cWeight,
__in DWORD bItalic,
__in DWORD bUnderline,
__in DWORD bStrikeOut,
__in DWORD iCharSet,
__in DWORD iOutPrecision,
__in DWORD iClipPrecision,
__in DWORD iQuality,
__in DWORD iPitchAndFamily,
__in_opt LPCSTR pszFaceName
)
{
LOGFONTA lf_a = {
cHeight, cWidth, cEscapement, cOrientation, cWeight, (BYTE)bItalic,
(BYTE)bUnderline, (BYTE)bStrikeOut, (BYTE)iCharSet, (BYTE)iOutPrecision,
(BYTE)iClipPrecision, (BYTE)iQuality, (BYTE)iPitchAndFamily
};
// Yes, Windows does the same internally. CreateFont() is *not* a way
// to pass a face name longer than 32 characters.
if(pszFaceName) {
strncpy(lf_a.lfFaceName, pszFaceName, sizeof(lf_a.lfFaceName));
}
return CreateFontIndirectU(&lf_a);
}

HFONT WINAPI CreateFontIndirectU(
__in CONST LOGFONTA *lplf
)
{
ENUMLOGFONTEXDVA elfedv_a;
const size_t elfedv_lf_diff =
sizeof(ENUMLOGFONTEXDVA) - offsetof(ENUMLOGFONTEXDVA, elfEnumLogfontEx.elfFullName)
;
if(!lplf) {
return NULL;
}
memcpy(&elfedv_a.elfEnumLogfontEx.elfLogFont, lplf, sizeof(LOGFONTA));
ZeroMemory(&elfedv_a.elfEnumLogfontEx.elfFullName, elfedv_lf_diff);
return CreateFontIndirectExU(&elfedv_a);
}

HFONT WINAPI CreateFontIndirectExU(
__in CONST ENUMLOGFONTEXDVA *lpelfe
)
{
ENUMLOGFONTEXDVW elfedv_w;
return CreateFontIndirectExW(EnumLogfontExDVAToW(&elfedv_w, lpelfe));
}

typedef struct {
FONTENUMPROCA lpOrigProc;
Expand Down
12 changes: 12 additions & 0 deletions src/gdi32_dll.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,18 @@ HFONT WINAPI CreateFontU(
#undef CreateFont
#define CreateFont CreateFontU

HFONT WINAPI CreateFontIndirectU(
__in CONST LOGFONTA *lplf
);
#undef CreateFontIndirect
#define CreateFontIndirect CreateFontIndirectU

HFONT WINAPI CreateFontIndirectExU(
__in CONST ENUMLOGFONTEXDVA *lpelfe
);
#undef CreateFontIndirectEx
#define CreateFontIndirectEx CreateFontIndirectExU

int WINAPI EnumFontFamiliesExU(
__in HDC hdc,
__in LPLOGFONTA lpLogfont,
Expand Down
2 changes: 2 additions & 0 deletions win32_utf8.def
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ EXPORTS
; gdi32.dll
; ---------
CreateFontU
CreateFontIndirectU
CreateFontIndirectExU
EnumFontFamiliesExU
GetTextExtentPoint32U
TextOutU
Expand Down

0 comments on commit ff4ac97

Please sign in to comment.