From: Doug Coleman Date: Sat, 29 Aug 2009 19:29:46 +0000 (-0500) Subject: new structs in font rendering X-Git-Tag: 0.97~5635^2~11^2~23 X-Git-Url: https://gitweb.factorcode.org/gitweb.cgi?p=factor.git;a=commitdiff_plain;h=6aeb3614ff808a9fd18937b2e5d1503e88d3df4c new structs in font rendering --- diff --git a/basis/windows/fonts/fonts.factor b/basis/windows/fonts/fonts.factor index 269e8f8f48..b8acf5d8d1 100755 --- a/basis/windows/fonts/fonts.factor +++ b/basis/windows/fonts/fonts.factor @@ -1,37 +1,37 @@ -USING: assocs memoize locals kernel accessors init fonts math -combinators windows.errors windows.types windows.gdi32 ; -IN: windows.fonts - -: windows-font-name ( string -- string' ) - H{ - { "sans-serif" "Tahoma" } - { "serif" "Times New Roman" } - { "monospace" "Courier New" } - } ?at drop ; - -MEMO:: (cache-font) ( font -- HFONT ) - font size>> neg ! nHeight - 0 0 0 ! nWidth, nEscapement, nOrientation - font bold?>> FW_BOLD FW_NORMAL ? ! fnWeight - font italic?>> TRUE FALSE ? ! fdwItalic - FALSE ! fdwUnderline - FALSE ! fdWStrikeOut - DEFAULT_CHARSET ! fdwCharSet - OUT_OUTLINE_PRECIS ! fdwOutputPrecision - CLIP_DEFAULT_PRECIS ! fdwClipPrecision - DEFAULT_QUALITY ! fdwQuality - DEFAULT_PITCH ! fdwPitchAndFamily - font name>> windows-font-name - CreateFont - dup win32-error=0/f ; - -: cache-font ( font -- HFONT ) strip-font-colors (cache-font) ; - -[ \ (cache-font) reset-memoized ] "windows.fonts" add-init-hook - -: TEXTMETRIC>metrics ( TEXTMETRIC -- metrics ) - [ metrics new 0 >>width ] dip { - [ TEXTMETRICW-tmHeight >>height ] - [ TEXTMETRICW-tmAscent >>ascent ] - [ TEXTMETRICW-tmDescent >>descent ] - } cleave ; +USING: assocs memoize locals kernel accessors init fonts math +combinators windows.errors windows.types windows.gdi32 ; +IN: windows.fonts + +: windows-font-name ( string -- string' ) + H{ + { "sans-serif" "Tahoma" } + { "serif" "Times New Roman" } + { "monospace" "Courier New" } + } ?at drop ; + +MEMO:: (cache-font) ( font -- HFONT ) + font size>> neg ! nHeight + 0 0 0 ! nWidth, nEscapement, nOrientation + font bold?>> FW_BOLD FW_NORMAL ? ! fnWeight + font italic?>> TRUE FALSE ? ! fdwItalic + FALSE ! fdwUnderline + FALSE ! fdWStrikeOut + DEFAULT_CHARSET ! fdwCharSet + OUT_OUTLINE_PRECIS ! fdwOutputPrecision + CLIP_DEFAULT_PRECIS ! fdwClipPrecision + DEFAULT_QUALITY ! fdwQuality + DEFAULT_PITCH ! fdwPitchAndFamily + font name>> windows-font-name + CreateFont + dup win32-error=0/f ; + +: cache-font ( font -- HFONT ) strip-font-colors (cache-font) ; + +[ \ (cache-font) reset-memoized ] "windows.fonts" add-init-hook + +: TEXTMETRIC>metrics ( TEXTMETRIC -- metrics ) + [ metrics new 0 >>width ] dip { + [ tmHeight>> >>height ] + [ tmAscent>> >>ascent ] + [ tmDescent>> >>descent ] + } cleave ; diff --git a/basis/windows/types/types.factor b/basis/windows/types/types.factor index 59192bb3b6..c62de58bcd 100755 --- a/basis/windows/types/types.factor +++ b/basis/windows/types/types.factor @@ -380,26 +380,26 @@ TYPEDEF: DWORD* LPCOLORREF : color>RGB ( color -- COLORREF ) >rgba-components drop [ 255 * >integer ] tri@ RGB ; -C-STRUCT: TEXTMETRICW - { "LONG" "tmHeight" } - { "LONG" "tmAscent" } - { "LONG" "tmDescent" } - { "LONG" "tmInternalLeading" } - { "LONG" "tmExternalLeading" } - { "LONG" "tmAveCharWidth" } - { "LONG" "tmMaxCharWidth" } - { "LONG" "tmWeight" } - { "LONG" "tmOverhang" } - { "LONG" "tmDigitizedAspectX" } - { "LONG" "tmDigitizedAspectY" } - { "WCHAR" "tmFirstChar" } - { "WCHAR" "tmLastChar" } - { "WCHAR" "tmDefaultChar" } - { "WCHAR" "tmBreakChar" } - { "BYTE" "tmItalic" } - { "BYTE" "tmUnderlined" } - { "BYTE" "tmStruckOut" } - { "BYTE" "tmPitchAndFamily" } - { "BYTE" "tmCharSet" } ; +STRUCT: TEXTMETRICW + { tmHeight LONG } + { tmAscent LONG } + { tmDescent LONG } + { tmInternalLeading LONG } + { tmExternalLeading LONG } + { tmAveCharWidth LONG } + { tmMaxCharWidth LONG } + { tmWeight LONG } + { tmOverhang LONG } + { tmDigitizedAspectX LONG } + { tmDigitizedAspectY LONG } + { tmFirstChar WCHAR } + { tmLastChar WCHAR } + { tmDefaultChar WCHAR } + { tmBreakChar WCHAR } + { tmItalic BYTE } + { tmUnderlined BYTE } + { tmStruckOut BYTE } + { tmPitchAndFamily BYTE } + { tmCharSet BYTE } ; TYPEDEF: TEXTMETRICW* LPTEXTMETRIC diff --git a/basis/windows/uniscribe/uniscribe.factor b/basis/windows/uniscribe/uniscribe.factor index 457f4bc9f0..7dd630ca5b 100755 --- a/basis/windows/uniscribe/uniscribe.factor +++ b/basis/windows/uniscribe/uniscribe.factor @@ -4,7 +4,8 @@ USING: kernel assocs math sequences fry io.encodings.string io.encodings.utf16n accessors arrays combinators destructors cache namespaces init fonts alien.c-types windows.usp10 windows.offscreen windows.gdi32 windows.ole32 windows.types -windows.fonts opengl.textures locals windows.errors ; +windows.fonts opengl.textures locals windows.errors +classes.struct ; IN: windows.uniscribe TUPLE: script-string < disposable font string metrics ssa size image ; @@ -84,7 +85,7 @@ TUPLE: script-string < disposable font string metrics ssa size image ; [ SIZE-cx ] [ SIZE-cy ] bi 2array ; : dc-metrics ( dc -- metrics ) - "TEXTMETRICW" + TEXTMETRICW [ GetTextMetrics drop ] keep TEXTMETRIC>metrics ;