     [ check-ole32-error ] [ |ScriptStringFree void* deref ] bi* ;
 
 : set-dc-colors ( dc font -- )
-    [ background>> color>RGB SetBkColor drop ]
-    [ foreground>> color>RGB SetTextColor drop ] 2bi ;
+    dup background>> >rgba alpha>> 1 number= [
+        ! No transparency needed, set colors from the font.
+        [ background>> color>RGB SetBkColor drop ]
+        [ foreground>> color>RGB SetTextColor drop ] 2bi
+    ] [
+        ! Draw white text on black background. The resulting grayscale
+        ! image will be used as transparency mask for the actual color.
+        drop
+        [ COLOR: black color>RGB SetBkColor drop ]
+        [ COLOR: white color>RGB SetTextColor drop ] bi
+    ] if ;
 
 : selection-start/end ( script-string -- iMinSel iMaxSel )
     string>> dup selection? [ [ start>> ] [ end>> ] bi ] [ drop 0 0 ] if ;

    FALSE ! fDisabled
    ScriptStringOut check-ole32-error ;

:: render-image ( dc ssa script-string -- image )
    script-string size>> :> size
    size dc
    [ ssa size script-string draw-script-string ] make-bitmap-image ;

: set-dc-font ( dc font -- )
    cache-font SelectObject win32-error=0/f ;

! Copyright (C) 2009 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
USING: accessors alien.c-types alien.data arrays assocs cache
classes.struct colors colors.constants combinators destructors
fonts images init io.encodings.string io.encodings.utf16n kernel
literals locals math namespaces sequences windows.errors
windows.fonts windows.gdi32 windows.offscreen windows.ole32
windows.types windows.usp10 ;
IN: windows.uniscribe

TUPLE: script-string < disposable font string metrics ssa size image ;
