Jump to content
Sign in to follow this  

How to place semibold text on graphic?

Recommended Posts


I'm using  _GDIPlus_FontCreate to create Arial to write directly on a PNG.  Everything works, but the font's appearance is too light, with narrow lines.  For some reason _GDIPlus_FontCreate only offers 0=normal, 1=bold, 2=italic.  But I've tried Bold and the result is too heavy.  I need half way in between: Semibold, which is listed on the MSDN site as a choice: http://msdn.microsoft.com/en-us/library/windows/desktop/dd183499%28v=vs.85%29.aspx

Both _WinAPI_CreateFont and GUICtrlSetFont offer a setting for $FW_SEMIBOLD (600), which I've used in normal fields with good result.

Is there any way to specify Semibold when using the GDI+ method?  Or is there another way to place text on a PNG?

Thanks in advance for any assistance.;




Share this post

Link to post
Share on other sites

I adapted the following simple demonstration from an example on these forums.  It uses the same GDI+ calls that my large script uses.

#include <GDIPlus.au3>
#include <GUIConstantsEx.au3>
#include <Misc.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>

AutoItSetOption("MustDeclareVars", 1)
Global $_ATTRIB = 1, $_NAME = 2, $_SIZE = 3, $_WEIGHT = 4, $_COLOR = 7 ;  default values
Global Const $_TEXT = 0, $_WIDTH = 2, $_HEIGHT = 3 ; $aStringSize indices
Global $aStringSize, $hGUI, $hGraphic, $hBrush, $hFormat, $hFamily, $hFont, $tLayout, $aInfo, $sText

Func Main()

$sText = @CRLF & " This is sample text.  It is displayed in Arial font." & @CRLF & @CRLF &" The goal is to have this text displayed in SemiBold." & @CRLF & " (Weight = 600) "& @CRLF & @CRLF & " End"

$_ATTRIB = 0
$_SIZE = 12
$_WEIGHT = 600
$_NAME = "Arial"
$aStringSize = _GDIPlus_MeasureString($sText, $_NAME, $_SIZE, $_ATTRIB)
;MsgBox(48, "", $_NAME & " " & $_SIZE & " " & $_WEIGHT & "  " & $_ATTRIB , 0)
If Not IsArray($aStringSize) Then Return -1

; Build GUI
$hGUI = GUICreate("GDI+ Font Test)", 600, 400)
GUICtrlCreateLabel("Font: " & $_NAME & ", Size: " & $_SIZE & ", Attribute: " & $_ATTRIB & ", Weight: " & $_WEIGHT, 10, 10, $aStringSize[0], 20)

$hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI)
$hBrush = _GDIPlus_BrushCreateSolid()
$hFormat = _GDIPlus_StringFormatCreate()
$hFamily = _GDIPlus_FontFamilyCreate($_NAME)
$hFont = _GDIPlus_FontCreate($hFamily, $_SIZE, $_ATTRIB)
$tLayout = _GDIPlus_RectFCreate(10, 30, 560, 360)
GUISetState(@SW_SHOW, $hGUI)

; Message Loop

; Clean up
EndFunc   ;==>Main

_WinAPI_RedrawWindow($hGUI, 0, 0, $RDW_UPDATENOW)
_GDIPlus_GraphicsDrawStringEx($hGraphic, $sText, $hFont, $tLayout, $hFormat, $hBrush)
_GDIPlus_GraphicsDrawRect($hGraphic, 10, 30, 560, 360)
_WinAPI_RedrawWindow($hGUI, 0, 0, $RDW_VALIDATE)
EndFunc   ;==>_WMPAINT

Func _GDIPlus_MeasureString($sString, $sFont = "Arial", $fSize = 12, $iStyle = 0)
    Local Const $hFormat = _GDIPlus_StringFormatCreate()
    Local Const $hFamily = _GDIPlus_FontFamilyCreate($sFont)
    Local Const $hFont = _GDIPlus_FontCreate($hFamily, $fSize, $iStyle)
    Local Const $tLayout = _GDIPlus_RectFCreate(0, 0, 0, 0)
    Local Const $hGraphic = _GDIPlus_GraphicsCreateFromHWND(WinGetHandle(AutoItWinGetTitle()))
    Local $aInfo = _GDIPlus_GraphicsMeasureString($hGraphic, $sString, $hFont, $tLayout, $hFormat)
    Local $aSize[2] = [DllStructGetData($aInfo[0], "Width"), DllStructGetData($aInfo[0], "Height")]
Return $aSize

Share this post

Link to post
Share on other sites

This might help you:



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!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post

Link to post
Share on other sites

Thanks for your response.  Unfortunately, I can't spot any reference to font weight (=400, 600, 800, etc).

What I do see is the same kind of statement:  _GDIPlus_FontCreate($hFamily, $fSize, 1)
But I don't see any mention of the kind of FW_Semibold parameter that MSDN references.

Does it have to do with the _GDIPlus_BrushCreateSolid()?  Could you point out a couple of statements that I should investigate?

Share this post

Link to post
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
Sign in to follow this  


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.