This is an adaption from the default using Private Fonts.You have to have the "real" name of the font and its filename.
Code: Select all
Gdip_PrivateFontToGraphics(pGraphics, Text, Options, Fontfile,FontName, Width="", Height="", Measure=0)
{
IWidth := Width, IHeight:= Height
RegExMatch(Options, "i)X([\-\d\.]+)(p*)", xpos)
RegExMatch(Options, "i)Y([\-\d\.]+)(p*)", ypos)
RegExMatch(Options, "i)W([\-\d\.]+)(p*)", Width)
RegExMatch(Options, "i)H([\-\d\.]+)(p*)", Height)
RegExMatch(Options, "i)C(?!(entre|Enter))([a-f\d]+)", Colour)
RegExMatch(Options, "i)Top|Up|Bottom|Down|vCentre|vCenter", vPos)
RegExMatch(Options, "i)NoWrap", NoWrap)
RegExMatch(Options, "i)R(\d)", Rendering)
RegExMatch(Options, "i)S(\d+)(p*)", Size)
If !Gdip_DeleteBrush(Gdip_CloneBrush(Colour2))
PassBrush := 1, pBrush := Colour2
If !(IWidth && IHeight) && (xpos2 || ypos2 || Width2 || Height2 || Size2)
Return -1
Style := 0, Styles := "Regular|Bold|italic|Bolditalic|underline|strikeout"
Loop, Parse, Styles, |
{
If RegExMatch(Options, "\b" A_loopField)
Style |= (A_LoopField != "strikeOut") ? (A_Index-1) : 8
}
Align := 0, Alignments := "Near|Left|Centre|Center|Far|Right"
Loop, Parse, Alignments, |
{
If RegExMatch(Options, "\b" A_loopField)
Align |= A_Index//2.1 ; 0|0|1|1|2|2
}
xpos := (xpos1 != "") ? xpos2 ? IWidth*(xpos1/100) : xpos1 : 0
ypos := (ypos1 != "") ? ypos2 ? IHeight*(ypos1/100) : ypos1 : 0
Width := Width1 ? Width2 ? IWidth*(Width1/100) : Width1 : IWidth
Height := Height1 ? Height2 ? IHeight*(Height1/100) : Height1 : IHeight
If !PassBrush
Colour := "0x" (Colour2 ? Colour2 : "ff000000")
Rendering := ((Rendering1 >= 0) && (Rendering1 <= 5)) ? Rendering1 : 4
Size := (Size1 > 0) ? Size2 ? IHeight*(Size1/100) : Size1 : 12
If !A_IsUnicode
{
nSize:=DllCall("kernel32\MultiByteToWideChar", "Uint", 0, "Uint", 0, "Uint", &Fontfile, "int", -1, "Uint", 0, "int", 0)
VarSetCapacity(wFontfile, nSize * 2 + 1)
DllCall("kernel32\MultiByteToWideChar", "Uint", 0, "Uint", 0, "Uint", &Fontfile, "int", -1, "Uint", &wFontfile, "int", nSize + 1)
nSize:=DllCall("kernel32\MultiByteToWideChar", "Uint", 0, "Uint", 0, "Uint", &FontName, "int", -1, "Uint", 0, "int", 0)
VarSetCapacity(wFontName, nSize * 2 + 1)
DllCall("kernel32\MultiByteToWideChar", "Uint", 0, "Uint", 0, "Uint", &FontName, "int", -1, "Uint", &wFontName, "int", nSize + 1)
DllCall("gdiplus\GdipNewPrivateFontCollection", "uint*", hcollection)
DllCall("gdiplus\GdipPrivateAddFontFile", "uint", hcollection, "uint", &wFontfile)
DllCall("gdiplus\GdipCreateFontFamilyFromName", "uint", &wFontName, "uint", hcollection, "uint*", hFamily)
}
Else
{
DllCall("gdiplus\GdipNewPrivateFontCollection", "uint*", hcollection)
DllCall("gdiplus\GdipPrivateAddFontFile", "uint", hcollection, "uint", &FontFile)
DllCall("gdiplus\GdipCreateFontFamilyFromName", "uint", &FontName, "uint", hcollection, "uint*", hFamily)
}
hFont := Gdip_FontCreate(hFamily, Size, Style)
FormatStyle := NoWrap ? 0x4000 | 0x1000 : 0x4000
hFormat := Gdip_StringFormatCreate(FormatStyle)
pBrush := PassBrush ? pBrush : Gdip_BrushCreateSolid(Colour)
If !(hFamily && hFont && hFormat && pBrush && pGraphics)
Return !pGraphics ? -2 : !hFamily ? -3 : !hFont ? -4 : !hFormat ? -5 : !pBrush ? -6 : 0
CreateRectF(RC, xpos, ypos, Width, Height)
Gdip_SetStringFormatAlign(hFormat, Align)
Gdip_SetTextRenderingHint(pGraphics, Rendering)
ReturnRC := Gdip_MeasureString(pGraphics, Text, hFont, hFormat, RC)
If vPos
{
StringSplit, ReturnRC, ReturnRC, |
If (vPos = "vCentre") || (vPos = "vCenter")
ypos += (Height-ReturnRC4)//2
Else If (vPos = "Top") || (vPos = "Up")
ypos := 0
Else If (vPos = "Bottom") || (vPos = "Down")
ypos := Height-ReturnRC4
CreateRectF(RC, xpos, ypos, Width, ReturnRC4)
ReturnRC := Gdip_MeasureString(pGraphics, Text, hFont, hFormat, RC)
}
If !Measure
E := Gdip_DrawString(pGraphics, Text, hFont, hFormat, pBrush, RC)
If !PassBrush
Gdip_DeleteBrush(pBrush)
Gdip_DeleteStringFormat(hFormat)
Gdip_DeleteFont(hFont)
Gdip_DeleteFontFamily(hFamily)
DllCall("gdiplus\GdipDeletePrivateFontCollection", "uint*", hcollection)
Return E ? E : ReturnRC
}