How do I set font spacing and line spacing?

Ask for help, how to use AHK_H, etc.
arcticir
Posts: 694
Joined: 17 Nov 2013, 11:32

How do I set font spacing and line spacing?

14 Aug 2017, 13:29

I try to use "GdipDrawString" to set the font spacing and line spacing,
But its effect is very bad,
I searched for a lot of information and seemed to need to use "GdipDrawDriverString" to set the line spacing
But I did not find an example of it, please tell me how to use "GdipDrawDriverString" instead of "GdipDrawString"...

Code: Select all

GdiplusStartup(getvar(pToken:=0),(si:=Struct("UINT GdiplusVersion;PTR DebugEventCallback;BOOL SuppressBackgroundThread;BOOL SuppressExternalCodecs",{GdiplusVersion:1}))[])
(gui:=GuiCreate("-Caption")).OnEvent("Close","ExitApp")
gui.BackColor:=0x3f627f
k:=GuiCreate("+E0x80000 0x10000000 +Parent" gui.hwnd)
_W:=444,_H:=444
BITMAPINFOHEADER:="DWORD biSize;LONG biWidth;LONG biHeight;WORD biPlanes;WORD biBitCount;DWORD biCompression;DWORD biSizeImage;LONG biXPelsPerMeter;LONG biYPelsPerMeter;DWORD biClrUsed;DWORD biClrImportant;"
bi:=Struct(BITMAPINFOHEADER,{biSize:sizeof(BITMAPINFOHEADER),biWidth:_W,biHeight:_H,biPlanes:1,biBitCount:32})
hbm := CreateDIBSection( hdc:=GetDC(), bi[]),ReleaseDC(0,hdc)
hdc := CreateCompatibleDC(),obm := SelectObject(hdc, hbm)
GdipCreateFromHDC(hdc,getvar(G:=0)),GdipSetInterpolationMode(G, 7)
text(g)
pt:=Struct("x,y")
pt.x:=0,pt.y:=0
UpdateLayeredWindow(k.hwnd,0,pt[],getvar(temp1:=_W|_H<<32),hdc, getvar(temp2:=0),0,getvar(temp3:=255<<16|1<<24),2)
gui.show("w" _W " h" _H+50)
Return

text(pGraphics){
	static FontFamily:=[],Font:=[]
	if !this
		this:={font:"Verdana",s:22}
	this.base:={x:10,y:4,w:820,h:340,c:"0xff000000",s:16,r:4,n:0x4000,Bold:1,Underline:1}

	Align := 0,Style := 0
	Loop Parse, "Regular|Bold|Italic|BoldItalic|Underline|Strikeout", "|"
		if this.haskey(A_LoopField)
			Style |= (A_LoopField = "StrikeOut") ?8:A_Index-1

	Loop Parse, "Near|Left|Centre|Center|Far|Right", "|"
		if this.haskey(A_LoopField)
			Align |= A_Index//2.1      ; 0|0|1|1|2|2



	Colour := "0xff000000"

	Rendering := ((Rendering1 >= 0) && (Rendering1 <= 5)) ? Rendering1 : 4
	Size := (Size1 > 0) ? Size2 ? IHeight*(Size1/100) : Size1 : 12
	hFamily:=font_family(this.Font)
	hFont:=font_handle(hfamily,this.s,style)
	FormatStyle := NoWrap ? 0x4000 | 0x1000 : 0x4000
	GdipCreateStringFormat(FormatStyle,0,getvar(hFormat:=0))
	GdipCreateSolidFill(0xff000000,getvar(pBrush:=0))
	RC:=Struct("float x,float y,float w,float h")
	rc.x:=this.x,rc.y:=this.y,rc.w:=this.w,rc.h:=this.h

	GdipSetStringFormatAlign(hFormat, Align)
	GdipSetTextRenderingHint(pGraphics,4)
	RC:=Struct("float x,float y,float w,float h",{w:400,h:200})	
	f:=[]
	wm:=355
	iw:=0
	f.push({p:p:=[],m:m:=[]})


	Loop Parse,"asdfsdadfsagasdgf234wrasdsagsadfsadgsagasdfsafdsdgsadf"
	{
		r:=Struct("float x,float y,float w,float h,c,l,LPTSTR  t")
		GdipMeasureString(pGraphics,&A_LoopField,-1,hfont,rc[],hFormat,r[],getvar(chars:=0),getvar(lines:=1))
		r.c:=chars,r.l:=lines,r.t:=A_LoopField
		if (iw+r.w)>wm
			f.push({p:p:=[],m:m:=[]}),iw:=0
		else
			iw+=r.w
		m.M.=R.H "|"
		p.push(r)
	}
	zy:=0
	for i,n in f
	{
		s:=Sort(n.m.m,"U N R D|")
		hh:=substr(s,1,instr(s,"|")-1)
		x:=0
		for i,n in n.p
		{
			RC:=Struct("float x,float y,float w,float h",{w:n.w,h:n.h,y:zy})
			s:=n.t
				if x=0
			rc.x:=0
				else
			rc.x:=x-6*A_Index
			GdipDrawString(pGraphics, &s,  -1, hFont, rc[], hFormat, pBrush)
			x+=n.w
		}
		zy+=hh
	}
	GdipDeleteStringFormat(hFormat)   
	GdipDeleteFont(hFont)
	GdipDeleteFontFamily(hFamily)
	return E ? E : ReturnRC

}
font_brush(s){
	local f:=[]
	Return (f.haskey(s)?f[s]:(GdipCreateSolidFill(s,getvar(h:=0)),f[s]:=h))
}

font_family(font){
	local f:=[]
	Return (f.haskey(font)?f[font]:(GdipCreateFontFamilyFromName(&font,0,getvar(h:=0)),f[font]:=h))
}

font_handle(family,size,style){
	local f:=[]
	Return (f.haskey(r:=family " " (i:=Cast("float",size,"int")) " " style)?f[r]:(GdipCreateFont(family,i,style,0,getvar(h:=0)),f[r]:=h))
}
arcticir
Posts: 694
Joined: 17 Nov 2013, 11:32

Re: How do I set font spacing and line spacing?

18 Aug 2017, 21:49

thanks.
Can you fix this WIN7 & V2 BUG?

Code: Select all

GuiCreate("+E0x80000 +Parent" GuiCreate().hwnd)

Return to “Ask for Help”

Who is online

Users browsing this forum: No registered users and 26 guests