Hello all,
I've been researching for a while about Windows Factor's inability to correctly
render texts on
transparent backgrounds. I haven't solved the problem yet, but I've just come
to an idea.
I'd be happy to hear your opinions on that.
For example, labels for button widgets are tentatively drawn with gray
background text because
they cannot draw labels with a transparent background. I disabled this behavior
and tried to make
transparent drawing work correctly, but only on a black background. I kept
trying to figure
out what was behind the black background, but I couldn't find the widget.
That's why I came up with the idea that Uniscribe works to make the background
transparent,
but where the characters are written is black. At first it seemed like a silly
idea, but I wrote
the code to confirm it.
USING: accessors alien.c-types alien.data colors images.viewer
io io.encodings.string io.encodings.utf16n io.styles kernel
literals math sequences ui ui.commands ui.gadgets
ui.gadgets.borders ui.gadgets.panes ui.gadgets.tracks
ui.gestures windows.gdi32 windows.offscreen windows.ole32
windows.types windows.usp10 locals fonts windows.fonts
windows.errors ;
IN: hello-uniscribe
! NOTE: The following declaration is required in gdi32.factor
!
! FUNCTION: int SetBkMode ( HDC hdc, int iBkMode )
TUPLE: hello-gadget < track ;
: <hello-gadget> ( -- gadget )
horizontal hello-gadget new-track
[
{ { font-size 24 } } [
"Hello" print
"Grüß dich" print
"здравствуйте" print
"こんにちは" print
"안녕하세요" print
"שָׁלוֹם " print
] with-style
] make-pane { 10 10 } <border>
f track-add ;
:: com-screen-shot ( gadget -- )
[ :> dc
gadget dim>> dc [ ] make-bitmap-image image-window
] with-memory-dc ;
CONSTANT: ssa-dwFlags flags{ SSA_GLYPHS SSA_FALLBACK SSA_TAB }
:: (com-screen-shot-with-text) ( dim bkMode uOptions -- )
[ :> dc
dim dc [
dc sans-serif-font cache-font SelectObject win32-error=0/f
dc T{ rgba f 0.0 0.0 1.0 0.0 } color>RGB SetBkColor drop
dc T{ rgba f 1.0 1.0 1.0 1.0 } color>RGB SetTextColor drop
dc bkMode SetBkMode drop
dc
"Hello!"
[ utf16n encode ] ! pString
[ length ] bi ! cString
dup 1.5 * 16 + >integer ! cGlyphs -- MSDN says this is "recommended
size"
-1 ! iCharset -- Unicode
ssa-dwFlags
0 ! iReqWidth
f ! psControl
f ! psState
f ! piDx
f ! pTabdef
f ! pbInClass
f void* <ref> ! pssa
[ ScriptStringAnalyse ] keep
[ check-ole32-error ] [ |ScriptStringFree void* deref ] bi*
0 ! iX
0 ! iY
uOptions
{ 0 0 } dim <RECT>
0 ! iMinSel
0 ! iMaxSel
FALSE ! fDisabled
ScriptStringOut check-ole32-error
] make-bitmap-image image-window
] with-memory-dc ;
: com-screen-shot-with-text-opaque ( gadget -- )
dim>> OPAQUE ETO_OPAQUE (com-screen-shot-with-text) ;
: com-screen-shot-with-text-transparent-1 ( gadget -- )
dim>> OPAQUE 0 (com-screen-shot-with-text) ;
: com-screen-shot-with-text-transparent-2 ( gadget -- )
dim>> TRANSPARENT ETO_OPAQUE (com-screen-shot-with-text) ;
: com-screen-shot-with-text-transparent-3 ( gadget -- )
dim>> TRANSPARENT 0 (com-screen-shot-with-text) ;
hello-gadget "gestures" f {
{ T{ key-down { sym "1" } } com-screen-shot }
{ T{ key-down { sym "2" } } com-screen-shot-with-text-opaque }
{ T{ key-down { sym "3" } } com-screen-shot-with-text-transparent-1 }
{ T{ key-down { sym "4" } } com-screen-shot-with-text-transparent-2 }
{ T{ key-down { sym "5" } } com-screen-shot-with-text-transparent-3 }
} define-command-map
MAIN-WINDOW: hello-uniscribe { { title "გამარჯობა, uniscribe" } }
<hello-gadget> >>gadgets ;
My understanding from reading Uniscribe.factor is that it renders characters in
the device context
given by with-memory-dc. However, if you create a bitmap from that dc, its
background is black,
regardless of the drawing on the current window.
My guess is that you won't be able to create an image of a string with a
transparent background
unless you transfer the original window bitmap to the device context created by
with-memory-dc.
--
KUSUMOTO Norio
_______________________________________________
Factor-talk mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/factor-talk