I suspect there is a tiny bug in Gdip_TextToGraphics.
If I give an align of 'Center' and an Xpos of say -10 or +10 then my text will be 10 points left or right of centre. However if I do the same with VPos/YPos my text is always centred. This seems to work as a fix
Code:
If vPos
{
StringSplit, ReturnRC, ReturnRC, |
If (vPos = "vCentre") || (vPos = "vCenter")
ypos := ypos + (Height-ReturnRC4)//2
; Else If (vPos = "Top") || (vPos = "Up")
; ypos := 0
Else If (vPos = "Bottom") || (vPos = "Down")
ypos := ypos + Height-ReturnRC4
CreateRectF(RC, xpos, ypos, Width, ReturnRC4)
}
Perhaps TIC can think of including it in any new change he makes ?
Here is my solution for bordered text:
Code:
Gdip_BorderedText(pGraphics, Text, Options, Font="Arial", Width="", Height="")
{
IWidth := Width, IHeight:= Height
RegExMatch(Options, "i)X([\-0-9]+)(p*)", xpos)
RegExMatch(Options, "i)Y([\-0-9]+)(p*)", ypos)
RegExMatch(Options, "i)W([0-9]+)(p*)", Width)
RegExMatch(Options, "i)H([0-9]+)(p*)", Height)
RegExMatch(Options, "i)C(?!(entre|enter))([a-f0-9]{8})", Colour)
RegExMatch(Options, "i)Top|Up|Bottom|Down|vCentre|vCenter", vPos)
RegExMatch(Options, "i)R([0-9])", Rendering)
RegExMatch(Options, "i)S([0-9]+)(p*)", Size)
RegExMatch(Options, "i)T([0-9])", Border_Thickness)
RegExMatch(Options, "i)B([a-f0-9]{8})", Border_Colour)
Style =
Styles := "Regular|Bold|Italic|BoldItalic|Underline|Strikeout"
Loop, Parse, Styles, |
{
If RegExMatch(Options, "\b" A_loopField)
Style := A_LoopField
}
Align =
Alignments := "Near|Left|Centre|Center|Far|Right"
Loop, Parse, Alignments, |
{
If RegExMatch(Options, "\b" A_loopField)
Align := A_loopField
}
if Border_Thickness <>
{
if xpos =
xpos = x0
if ypos =
ypos = y0
Border_Thickness_Array = -1 -1 0 -1 +1 -1 -1 0 +1 0 -1 +1 0 +1 +1 +1
StringSplit, Border_Thickness_Item, Border_Thickness_Array, %A_Space%
Border_Thickness := SubStr(Border_Thickness,2)
Border_Colour := SubStr(Border_Colour,2)
Border_Thickness_Idx=0
Loop, % Border_Thickness_Item0 / 2
{
Border_Thickness_Idx++
xbord = % Border_Thickness_Item%Border_Thickness_Idx%
Border_Thickness_Idx++
ybord = % Border_Thickness_Item%Border_Thickness_Idx%
xbord := SubStr(xpos,2) + (Border_Thickness * xbord)
ybord := SubStr(ypos,2) + (Border_Thickness * ybord)
Options = x%xbord% y%ybord% %Width% %Align% %vPos% %Style% c%Border_Colour% %Rendering% %Size%
Gdip_TextToGraphics(pGraphics, text, Options, Font, iWidth, iHeight)
}
Gdip_SetCompositingMode(pGraphics,1)
Gdip_SetClipRect(pGraphics, 0, 0, %iWidth%, %iWidth%, 3)
Options = %xpos% %ypos% %Width% %Align% %vPos% %Style% cffffffff %Rendering% %Size%
Gdip_TextToGraphics(pGraphics, Text, Options, Font, iWidth, iHeight)
Gdip_SetCompositingMode(pGraphics)
Gdip_ResetClip(pGraphics)
}
Options = %xpos% %ypos% %Width% %Height% %Align% %vPos% %Style% %Colour% %Rendering% %Size%
Gdip_TextToGraphics(pGraphics, Text, Options, Font, iWidth, iHeight)
}
if anyone's interested. Usage as Gdip_TextToGraphics with Bordercolour & Thickness extra in options
Code:
Options = x10p y30p w80p Centre cbbffffff r1 s20 T4 Bbb000000 Underline Italic
Gdip_BorderedText(G, "Tutorial 8`n`nThank you for trying this example", Options, Font, Width, Height)