qwert Posted June 15, 2013 Posted June 15, 2013 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.;
Zedna Posted June 15, 2013 Posted June 15, 2013 You will get more help when you add as small as possible reproducing script... Resources UDF ResourcesEx UDF AutoIt Forum Search
qwert Posted June 15, 2013 Author Posted June 15, 2013 I adapted the following simple demonstration from an example on these forums. It uses the same GDI+ calls that my large script uses. expandcollapse popup#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 Main() 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" _GDIPlus_Startup() $_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) GUISetBkColor(0xFFFFFF) 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) GUIRegisterMsg($WM_PAINT, "_WMPAINT") GUISetState(@SW_SHOW, $hGUI) ; Message Loop Do Until GUIGetMsg() == $GUI_EVENT_CLOSE ; Clean up _GDIPlus_FontDispose($hFont) _GDIPlus_FontFamilyDispose($hFamily) _GDIPlus_StringFormatDispose($hFormat) _GDIPlus_BrushDispose($hBrush) _GDIPlus_GraphicsDispose($hGraphic) _GDIPlus_Shutdown() EndFunc ;==>Main Func _WMPAINT() _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")] _GDIPlus_FontDispose($hFont) _GDIPlus_FontFamilyDispose($hFamily) _GDIPlus_StringFormatDispose($hFormat) _GDIPlus_GraphicsDispose($hGraphic) Return $aSize EndFunc
UEZ Posted June 16, 2013 Posted June 16, 2013 This might help you: Br,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!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ
qwert Posted June 16, 2013 Author Posted June 16, 2013 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?
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now