Page 1 of 1

Border for vector brush

Posted: Sun Aug 10, 2025 11:46 am
by Flinx
I have a function that fits an SVG into a specified area for various purposes. Now I wanted to use it for text on my on-screen keyboard and therefore create a vector brush that is used in the same way as the SVGs loaded by the preprocessor. My SVGs all have a border, so I need one for the vector brush I create to make it look consistent.
But I haven't found a way to set the page size for the paths or the vector brush directly. ExtendBrush doesn't work for vector brushes. So I first create a brush from the text to determine its size, then delete this brush and add a second path that forces the border on the right and bottom. Then I create the resulting brush, with the second path transparent. The border at the top and left is created by specifying the position for the first path.

This works, but it seems cumbersome to me. Have I overlooked a more elegant solution?

Code: Select all

@DISPLAY {Width = 800, Height = 400, Color=$004466, Layers = True}

Function p_MakeTextVectorBrush(text$, font, fontsize, color)
	SetFillStyle(#FILLCOLOR)
	SetFormStyle(#ANTIALIAS)
	SetFont(font, fontsize, {Engine = #FONTENGINE_INBUILT})
	Local pid1=StartPath(Nil)
	MoveTo(pid1, 0, 0)
	AddTextToPath(pid1, text$)
	ClosePath(pid1)
	brushid=PathToBrush(Nil, {{ID=pid1, Color=color, X=0}})
	Local svgW=GetAttribute(#BRUSH,brushid,#ATTRWIDTH)
	Local svgH=GetAttribute(#BRUSH,brushid,#ATTRHEIGHT)
	FreeBrush(brushid)

	Local border=fontsize/6
	Local pid2=StartPath(Nil) ; Path for creating the right and bottom borders
	MoveTo(pid2, border+svgW,0) ; right edge of the text
	LineTo(pid2, border+svgW+border,1) ; border width
	LineTo(pid2, border+svgW+border,border+svgH+border) ; bottom border
	ClosePath(pid2)
	; Path 2 is only used to enlarge the vector object to the right and down
	; and is output transparently (ARGB value for Color):
	brushid=PathToBrush(Nil, {{ID=pid1, Color=color, X=border, Y=border},{ID=pid2, Color=0xffeeeeee, X=border+svgW}})
	FreePath(pid1)
	FreePath(pid2)
	Return(brushid)
EndFunction

brushid=p_MakeTextVectorBrush("Vector text", #SANS, 60, #YELLOW)
DisplayBrush(brushid, 100, 50, {Name="brushlayer"})

SetFillStyle(#FILLNONE)
; Green box to illustrate the size of the vector brush
Box(100, 50, GetAttribute(#BRUSH,brushid,#ATTRWIDTH), GetAttribute(#BRUSH,brushid,#ATTRHEIGHT), #GREEN )
FreeBrush(brushid)

WaitLeftMouse
RemoveLayer("brushlayer")


Re: Border for vector brush

Posted: Sat Aug 23, 2025 10:22 pm
by airsoftsoftwair
Flinx wrote: Sun Aug 10, 2025 11:46 am Have I overlooked a more elegant solution?
Don't think so. All whitespace at the edge of a path is always clipped so it's impossible to add whitespace to the path edges. Using subpaths isn't possible either because it's not possible to have multicolor paths so I think your solution is quite clever at solving the problem ;)