Jump to content
Sign in to follow this  
JFee

Font Size Differences

Recommended Posts

JFee

So I am making a graphics editor for TV stuff.... besides the point.

So the user can create text fields, and they choose a font size. They line the text fields up by dragging around a label. When the final graphic is created however, the text is drawn onto an image using GDI+. I am using the same font size, same font, same positioning, but the GDI+ Font shows up much smaller. Does anyone know why this is happening?

If that wasn't clear then feel free to ask for clarification. It's a little tricky to explain.


Regards,Josh

Share this post


Link to post
Share on other sites
dbzfanatic

Maybe GDI+ uses something like 25px when the GUI uses 25? I don't use GDI (as of yet) so I'm not sure but I bet you could do a bit of searching and do a bit of math to even things out.

Share this post


Link to post
Share on other sites
JFee

Thanks for the fast reply.

GDI has options about scale when it comes to text, and I think I've done all of them, and they're all different. I just find it interesting if they're both using the same scale why it would be different.


Regards,Josh

Share this post


Link to post
Share on other sites
JFee

So I just got a great idea... I opened up Photoshop, and GDIPlus is doing it correctly. So now I just need to find out what unit of measurement GUI controls use for text...


Regards,Josh

Share this post


Link to post
Share on other sites
JFee

Bump. Does anyone know how the GUI labels work in regards to font size?


Regards,Josh

Share this post


Link to post
Share on other sites
weaponx

Photoshop type is measure in points by default, you can change it to pixels through preferences. AutoIt is most likely pixels.

Share this post


Link to post
Share on other sites
JFee

In my GDI code that writes the text, I changed the font scale from points (default) to pixels. It was still off a ton. I tried all of the scale options in GDI+ and they are all different than the GUI text.


Regards,Josh

Share this post


Link to post
Share on other sites
weaponx

Well after looking at the help file it seems AutoIt uses the windows standard font unit, which is points.

Share this post


Link to post
Share on other sites
Zinthose

Bump. Does anyone know how the GUI labels work in regards to font size?

Font sizes for controls are are measured in points which amounts to 1/72 inch.

To produce the same font size in GDI use a $iUnit size = to 3, which is also the default.

The following generates matching fonts

GUICtrlSetFont(-1, 9, 400, 0, "Arial")
_GDIPlus_FontCreate("Arial", 9, 0, 3)
Edited by Zinthose

--- TTFN

Share this post


Link to post
Share on other sites
JFee

Change $imagePath to be any image. I am using a 720x486 png that is pure transparency. Compare the window to the image. They are in the same relative position, and should be the same size.

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

$ImagePath = @ScriptDir & "\includes\transTemplate.png"

GUICreate("Text", 200, 100)
GUISetState()
$label = GUICtrlCreateLabel("Test 123", 10, 10, 190, 90)
GUICtrlSetFont(-1, 20, 400, 0, "Arial")

_GDIPlus_Startup()

$hImage = _GDIPlus_ImageLoadFromFile($ImagePath)
$hGraphics = _GDIPlus_ImageGetGraphicsContext($hImage)

;$hFontFamily = _GDIPlus_FontFamilyCreate("Arial")
;$hFont = _GDIPlus_FontCreate($hFontFamily, 20, 0, 3)
;$hFormat = _GDIPlus_StringFormatCreate ()
;$tLayout = _GDIPlus_RectFCreate (10, 10, 0, 0)
;$aInfo = _GDIPlus_GraphicsMeasureString ($hGraphics, "Test 123", $hFont, $tLayout, $hFormat)
;$hBrush = _GDIPlus_BrushCreateSolid ("0xFF000000")
;_GDIPlus_GraphicsDrawStringEx($hGraphics, "Test 123", $hFont, $aInfo[0], $hFormat, $hBrush)
;_GDIPlus_ImageSaveToFile($hImage, "FontSize.bmp")


$gFontFamily = _GDIPlus_FontFamilyCreate("Arial");$tFont)
$gFont = _GDIPlus_FontCreate($gFontFamily, 20, 0, 3)
$gBrush = _GDIPlus_BrushCreateSolid("0xFF000000")
$gFormat = _GDIPlus_StringFormatCreate()
$gLayout = _GDIPlus_RectFCreate(10, 10)
$gInfo = _GDIPlus_GraphicsMeasureString($hGraphics, "Test 123", $gFont, $gLayout, $gFormat)
_GDIPlus_GraphicsDrawStringEx($hGraphics, "Test 123", $gFont, $gInfo[0], $gFormat, $gBrush)
MsgBox(1, "", _GDIPlus_ImageSaveToFile($hImage, "FontSize.png"))

_GDIPlus_Shutdown()

While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

Regards,Josh

Share this post


Link to post
Share on other sites
JFee

Oh no! I figured out what the problem is.... it is the Pixels Per Inch of the original image. If I set the PPI to 1000 the text gets huge. Is there any way to make the PPI of a PNG automatic?


Regards,Josh

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.