Skip to content

Commit 356bbca

Browse files
committed
Fix fontname
1 parent cb27188 commit 356bbca

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

modules/ILL/ILL/Font/Win.moon

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -178,11 +178,17 @@ class WindowsGDI extends Init
178178

179179
-- Convert family from utf8 to utf16
180180
family = utf8_to_utf16 @family
181-
if tonumber(C.wcslen family) > 31
182-
error "family name to long", 2
181+
182+
-- Fix family length
183+
lfFaceName = ffi.new "WCHAR[?]", FONT_LF_FACESIZE
184+
familyLen = C.wcslen family
185+
if familyLen >= FONT_LF_FACESIZE
186+
ffi.copy lfFaceName, family, (FONT_LF_FACESIZE-1) * ffi.sizeof "WCHAR"
187+
else
188+
ffi.copy lfFaceName, family, (familyLen+1) * ffi.sizeof "WCHAR"
183189

184190
-- Create font handle
185-
font = C.CreateFontW @size * FONT_UPSCALE, 0, 0, 0, @bold and C.FW_BOLD_ILL or C.FW_NORMAL_ILL, @italic and 1 or 0, @underline and 1 or 0, @strikeout and 1 or 0, C.DEFAULT_CHARSET_ILL, C.OUT_TT_PRECIS_ILL, C.CLIP_DEFAULT_PRECIS_ILL, C.ANTIALIASED_QUALITY_ILL, C.DEFAULT_PITCH_ILL + C.FF_DONTCARE_ILL, family
191+
font = C.CreateFontW @size * FONT_UPSCALE, 0, 0, 0, @bold and C.FW_BOLD_ILL or C.FW_NORMAL_ILL, @italic and 1 or 0, @underline and 1 or 0, @strikeout and 1 or 0, C.DEFAULT_CHARSET_ILL, C.OUT_TT_PRECIS_ILL, C.CLIP_DEFAULT_PRECIS_ILL, C.ANTIALIASED_QUALITY_ILL, C.DEFAULT_PITCH_ILL + C.FF_DONTCARE_ILL, lfFaceName
186192

187193
-- Set new font to device context
188194
old_font = C.SelectObject @dc, font

0 commit comments

Comments
 (0)