Jump to content

Font Smoothing for Rich text field on transparent background


Go to solution Solved by MacScript,

Recommended Posts

Hi all -

I have read on the forums about font smoothing when using text with a transparent background. None of the examples I have found seem to include having the text being displayed in a Rich Edit control.  I need to use the Rich edit control so that different lines of text can have color text and potentially different font/size.

Best way to describe this application is a Console to monitor scroll text. Every time a new line of text is added to the end of the file it is read and then evaluated for specific keywords. Depending on the keywords, the text color, font and size will be adjusted prior to the line of text being outputted to the Rich Edit control.

The problem that I am currently having is that the outside of the font seems to be fuzzy or I almost say white-ish. Which is making almost impossible to read.

I made a very quick example snippet of script to share

Any help would be appreciated. Thanks ahead of time.

#include <GuiRichEdit.au3>
#include <WindowsConstants.au3>
    $style1 = BitXOr($WS_POPUP, $WS_EX_LAYERED)
    $style2 = BitOR($WS_EX_LAYERED,$WS_EX_TOOLWINDOW,$WS_EX_TOPMOST,$WS_EX_LAYERED)
    $hGUI = GUICreate("RichEdit Transparent field", 500, 500, -1, -1, $style1, $style2)
        Global $Input2 = GUICtrlCreateEdit("", 20, 40, 450, 350)
        GUICtrlSetBkColor($Input2, 0xABCDEF)
        GUICtrlSetResizing(-1, 802)

        $hRichEdit = _GUICtrlRichEdit_Create($hGui, "", 20,40,460,400, BitOR($ES_MULTILINE, $WS_VSCROLL, $ES_AUTOVSCROLL), $WS_EX_TRANSPARENT)

    _WinAPI_SetLayeredWindowAttributes($hGUI, 0xABCDEF, 255)

    GUISetState(@SW_SHOW, $hGUI) ; Makes GUI Visible

    _GUICtrlRichEdit_SetFont($hRichEdit, 12, "Verdana")
    _GUICtrlRichEdit_WriteLine($hRichEdit, "This is a test" , +0, "", 0x008000)
    sleep(2000)

    _GUICtrlRichEdit_SetFont($hRichEdit, 12, "Arial")
    _GUICtrlRichEdit_WriteLine($hRichEdit, "This is a test" , +0, "", 0x3C0FF0)
    sleep(2000)

    _GUICtrlRichEdit_SetFont($hRichEdit, 12, "Arial")
    _GUICtrlRichEdit_WriteLine($hRichEdit, "This is a test" , +0, "", 0x00FF00)
    sleep(2000)

    Sleep(5000)

Func _GUICtrlRichEdit_WriteLine($hWnd, $sText, $iIncrement = 0, $sAttrib = "", $iColor = -1)

    ; Count the @CRLFs
    StringReplace(_GUICtrlRichEdit_GetText($hWnd, True), @CRLF, "")
    Local $iLines = @extended
    ; Adjust the text char count to account for the @CRLFs
    Local $iEndPoint = _GUICtrlRichEdit_GetTextLength($hWnd, True, True) - $iLines
    ; Add new text
    _GUICtrlRichEdit_AppendText($hWnd, $sText & @CRLF)
    ; Select text between old and new end points
    _GuiCtrlRichEdit_SetSel($hWnd, $iEndPoint, -1)
    ; Convert colour from RGB to BGR
    $iColor = Hex($iColor, 6)
    $iColor = '0x' & StringMid($iColor, 5, 2) & StringMid($iColor, 3, 2) & StringMid($iColor, 1, 2)
    ; Set colour
    If $iColor <> -1 Then _GuiCtrlRichEdit_SetCharColor($hWnd, $iColor)
    ; Set size
    If $iIncrement <> 0 Then _GUICtrlRichEdit_ChangeFontSize($hWnd, $iIncrement)
    ; Set weight
    If $sAttrib <> "" Then _GUICtrlRichEdit_SetCharAttributes($hWnd, $sAttrib)
    ; Clear selection
    _GUICtrlRichEdit_Deselect($hWnd)

EndFunc
Link to comment
Share on other sites

the only line that seems somewhat *fuzzy* is the last one, but that might be due to the brightness of the colour, the first two look fine.

CeWk.png

 

it looks even better on black background. so I would say it might be the contrast issue between the chosen background colour and the font colours.

ZfAYl.png

If you are not getting similar view to above then perhaps you need to check your windows settings to see if font smoothing is turned on etc..

Link to comment
Share on other sites

Modify the transparent color (0xABCDEF) to see the differencies. Further it depends on the background how anti aliasing (smoothing) looks.

 

Br,

UEZ

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

Modify the transparent color (0xABCDEF) to see the differencies. Further it depends on the background how anti aliasing (smoothing) looks.

 

Br,

UEZ

I am new to using transparent colors. I thought the only transparent color one can use is  (0xABCDEF). What other ones can I use? How do I code my program to do anti aliasing?

the only line that seems somewhat *fuzzy* is the last one, but that might be due to the brightness of the colour, the first two look fine.

CeWk.png

 

 

it looks even better on black background. so I would say it might be the contrast issue between the chosen background colour and the font colours.

ZfAYl.png

If you are not getting similar view to above then perhaps you need to check your windows settings to see if font smoothing is turned on etc..

Your screen shot is against a solid background. Here is a screen shot with the types of backgrounds I need to deal with ->

post-86306-0-90550200-1403692493.png

So thought on how to fix this issue?

Thanks ahead of time for all those who have contributed to this thread to help.

Link to comment
Share on other sites

Tried it at work & I had the same issue as your screen shot. I turned font smoothing off & the problem went away.

http://www.thewindowsclub.com/disable-font-smoothing-windows

This option will not work, I can't ask 20 + people to disable font-smoothing on their computers for all applications. I need a way to make this occur for my application. I have seen comments on the forums about font smoothing for edit fields. just cant seem to find a solution for a rich edit.

Thank you for your reply and suggestions.

Link to comment
Share on other sites

  • Solution

I would like to thank UEZ for his help. it looks like by changing out the transparent background colors to one of these has helped the situation ([["Bright", 0xFEFEFE], ["Normal", 0xABCDEF], ["Dark", 0x2F2F2F]])..,  Further testing is required to see if this has completely resolved the issue.

Link to comment
Share on other sites

I found that setting it the background transparent colour to absolute black ( 0x000000 ) produced the best results when the underlying background image had mostly black/dark colours, similarly setting it to absolute white ( 0xFFFFFF) produced the best result when the background image had mostly white/light colours.

Perhaps there is a way you can analyse the underlying background and achieve an average pixel colour or similar and then set the appropriate transparency colour?

Just a thought.

EDIT: This might help: '?do=embed' frameborder='0' data-embedContent>>

Edited by mpower
Link to comment
Share on other sites

I found that setting it the background transparent colour to absolute black ( 0x000000 ) produced the best results when the underlying background image had mostly black/dark colours, similarly setting it to absolute white ( 0xFFFFFF) produced the best result when the background image had mostly white/light colours.

Perhaps there is a way you can analyse the underlying background and achieve an average pixel colour or similar and then set the appropriate transparency colour?

Just a thought.

EDIT: This might help: '?do=embed' frameborder='0' data-embedContent>>

 

Is there a specific list of colors for the background when using a transparent gui or can any color background be used?  UEZ gave me 3 colors, and mpower gave 2 more.

Thanks for information

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...