Jump to content

how to pad a label text by pixels ?


jennico
 Share

Recommended Posts

i want to pad a label text to the left and to the right with whitespaces, so the text does not start on the first label pixel, and in case of $SS_Right does not end on last pixel. there should be a constant gap to the label borders. (i don't mean center either) :)

if i choose spaces for the padding, the result will not be constant when a bigger font is used, but i need constant spacing no matter of the font.

the best would be to have the possibility to push the text x pixels to the right (and on $ss_right push it x pixel to the left).

does anyone know a trick how to achieve this ?

thank you all.

j.

Spoiler

I actively support Wikileaks | Freedom for Julian Assange ! | Defend freedom of speech ! | Fight censorship ! | I will not silence.OixB7.jpgDon't forget this IP: 213.251.145.96

 

Link to comment
Share on other sites

i am using _WinAPI_GetTextExtentPoint32 already, but it does not leave me "push" the text.

_WinAPI_TwipsPerPixelX : i still wonder what "twips" should be ......... can you explain ?

in helpfile no explanation, no example, no reference.

j.

edit:

MSDN Search No Results Found For: _WinAPI_TwipsPerPixelX

Edited by jennico
Spoiler

I actively support Wikileaks | Freedom for Julian Assange ! | Defend freedom of speech ! | Fight censorship ! | I will not silence.OixB7.jpgDon't forget this IP: 213.251.145.96

 

Link to comment
Share on other sites

i am using _WinAPI_GetTextExtentPoint32 already, but it does not leave me "push" the text.

_WinAPI_TwipsPerPixelX : i still wonder what "twips" should be ......... can you explain ?

in helpfile no explanation, no example, no reference.

j.

Relation Between Inches, Picas, Points, Pitch, and Twips from MS.
Link to comment
Share on other sites

thanks, your link is interesting.

There are several methods typographers can use to measure character spacing (kerning) and line spacing (leading). Listed below are the definitions, and typical conversions you might need to employ.

as far as i understand, so this is about measuring texts for printing purposes.

but i still do not understand how this helps me to add a pica or a twip or a point to my text.

j.

Spoiler

I actively support Wikileaks | Freedom for Julian Assange ! | Defend freedom of speech ! | Fight censorship ! | I will not silence.OixB7.jpgDon't forget this IP: 213.251.145.96

 

Link to comment
Share on other sites

thanks, your link is interesting.

as far as i understand, so this is about measuring texts for printing purposes.

but i still do not understand how this helps me to add a pica or a twip or a point to my text.

j.

What you tried with _WinAPI_GetTextExtentPoint32()?

Some snippet.

Link to comment
Share on other sites

i thought about that:

instead of a label i create a picture control, get the rect for gdiplus and then draw text in the rectangle.

i tried that, but: the picture control does not notify anymore on clicks. and i haven't found an example script in the forum that uses gdiplus elements that are able to send notifications.

j.

Spoiler

I actively support Wikileaks | Freedom for Julian Assange ! | Defend freedom of speech ! | Fight censorship ! | I will not silence.OixB7.jpgDon't forget this IP: 213.251.145.96

 

Link to comment
Share on other sites

_WinAPI_GetTextExtentPoint32() measures the text size and width so you can adapt the label exactly to the text. does it provide more features ?

j.

i cannot paste my script in here, it has >3000 lines, but just the function maybe:

Func __TM_Measure_Item($hRef, $hCnt)
    Local $i = $TM_Itm[$hRef][$hCnt]
    If $TM_Itm_def_w > 0 And $TM_Itm_height[$i] > 0 Then Return $TM_Itm_height[$i]
    Local $hWnd = GUICtrlGetHandle($i), $sText = GUICtrlRead($i), $hDC = DllCall("User32.dll", "hwnd", "GetDC", "hwnd", $hWnd), $hMsg = DllCall("user32.dll", "lparam", "SendMessage", "hwnd", $hWnd, "int", 49, "wparam", 0, "lparam", 0)
    DllCall("GDI32.dll", "hwnd", "SelectObject", "hwnd", $hDC[0], "hwnd", $hMsg[0])
    DllCall("GDI32.dll", "int", "GetTextExtentPoint32", "hwnd", $hDC[0], "str", $sText, "int", StringLen($sText), "ptr", DllStructGetPtr($TM_Size))
    Local $x = DllStructGetData($TM_Size, "X"), $y = DllStructGetData($TM_Size, "Y") + 1; + $TM_pad_ri
    DllCall("User32.dll", "int", "ReleaseDC", "hwnd", $hWnd, "hwnd", $hDC[0])   ;extra function
    If $TM_Itm_def_w > 0 Then $x = $TM_Itm_def_w
    If $x > $TM_Itm_w[$hRef] Then $TM_Itm_w[$hRef] = $x
    If $TM_Itm_height[$i] > 0 Then Return $TM_Itm_height[$i]
    If $TM_Itm_def_h > 0 Then $y = $TM_Itm_def_h;   min. 14 px 2 mehr !
    If $y > $TM_Itm_h[$hRef] Then $TM_Itm_h[$hRef] = $y
    Return $y
EndFunc   ;==>__TM_Measure_Item
Edited by jennico
Spoiler

I actively support Wikileaks | Freedom for Julian Assange ! | Defend freedom of speech ! | Fight censorship ! | I will not silence.OixB7.jpgDon't forget this IP: 213.251.145.96

 

Link to comment
Share on other sites

from msdn:

Windows XP: The calculated string width takes into account the intercharacter spacing set by the SetTextCharacterExtra function and the justification set by SetTextJustification. This is true for both displaying on a screen and for printing. However, if lpDx is set in ExtTextOut, GetTextExtentPoint32 does not take into account either intercharacter spacing or justification.

SetTextCharacterExtra will change the spacing between every word in the text string (this does not help either).

SetTextJustification works with chr(32) as well, not with pixels. so no help so far.

j.

Spoiler

I actively support Wikileaks | Freedom for Julian Assange ! | Defend freedom of speech ! | Fight censorship ! | I will not silence.OixB7.jpgDon't forget this IP: 213.251.145.96

 

Link to comment
Share on other sites

well, okay, i really understand GetTextExtentPoint32 and i use it correctly. let's take the (modified) example by zedna.

the text in the label begins at label x point 0. what i want to achieve, is that the text begins not at 0, but - let's say - 25 pixel from the left side. constantly, no matter what font is used. when i pad it left with spaces, the result will not be constant, because the space character will grow with the font width.

i need some function that allows me to start the text exactly at x position 25 pixel from left side of the label.

#include <GUIConstants.au3>

$WM_GETFONT = 0x31
$text = "ABCDEF"

$hGui = GUICreate("Test Label Size") 
$Label_1 = GUICtrlCreateLabel ($text,  10, 10, 200, 80);, $SS_SIMPLE) 
GUICtrlSetFont(-1, 20, 600, "", "Arial Narrow")
GUICtrlSetBkColor(-1,0xFFFFFF)
GUISetState ()      

$hText = ControlGetHandle($hGui, "", $Label_1)
$hDC = DLLCall("user32.dll","int","GetDC","hwnd",$hText)
$hDC = $hDC[0]
$hFont = DllCall("user32.dll", "ptr", "SendMessage", "hwnd", $hText, "int", $WM_GETFONT, "int", 0, "int", 0)
$hFont = $hFont[0]
$hOld = DllCall("gdi32.dll", "Hwnd", "SelectObject", "int", $hDC, "ptr", $hFont)
$struct_size = DllStructCreate("int;int")
$ret = DllCall("gdi32.dll", "int", "GetTextExtentPoint32", "int", $hDC, "str", $text, "long", StringLen($text), "ptr", DllStructGetPtr($struct_size))
$hOld = DllCall("gdi32.dll", "Hwnd", "SelectObject", "int", $hDC, "ptr", $hOld)

MsgBox(0, "Get Size", "Return Status=" & $ret[0] & " width=" & DllStructGetData($struct_size,1))

DLLCall("user32.dll","int","ReleaseDC","hwnd",$hText,"int",$hDC)
$struct_size = 0

and i can't find a way so far.

thx for your kind efforts.

j.

edited example and typo

Edited by jennico
Spoiler

I actively support Wikileaks | Freedom for Julian Assange ! | Defend freedom of speech ! | Fight censorship ! | I will not silence.OixB7.jpgDon't forget this IP: 213.251.145.96

 

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...