Get pixel width of a text

Posted:
Fri Jul 22, 2016 8:08 am
by Tim Webstein
Hi,
I'm trying to automatically resize a polyline shape in Fusion 8 depending on the pixel width of a text in another node. As a result I aim to get a custom-designed box around the text.
My idea is to move some points of the polyline depending on the text's pixel width. Unfortunately, I'm unable to find an expression which stores the actual pixel width of the text. Until now, I have only gotten access to the number of letters of a text. But since I don't use a monospace font this doesn't give me a clue on the pixel width of the text.
It seems to me a like a pretty common problem to size a box depending on the length of a text. Nevertheless, I couldn't find a solution for this. Has anybody of you an idea?
Thanks,
Tim
Re: Get pixel width of a text

Posted:
Fri Jul 22, 2016 6:30 pm
by Steve Roberts
The Text+ tool has options for creating a box around text, this will always automatically size to the length of the text.
In this Text+ example Shading element 4 creates a box behind the text. The Extend Horizontal and Vertical will size the box, and Round will control the radius of the corners
- Code: Select all
{
Tools = ordered() {
Text1 = TextPlus {
CtrlWZoom = false,
Inputs = {
GlobalOut = Input { Value = 200, },
Width = Input { Value = 1920, },
Height = Input { Value = 1080, },
["Gamut.SLogVersion"] = Input { Value = FuID { "SLog2" }, },
Font = Input { Value = "Arial", },
StyledText = Input { Value = "Any Length", },
Style = Input { Value = "Bold", },
ManualFontKerningPlacement = Input {
Value = StyledText {
Array = {
},
Value = ""
},
},
SelectElement = Input { Value = 3, },
Select = Input { Value = 3, },
ShadingGradient1 = Input {
Value = Gradient {
Colors = {
[0] = { 0, 0, 0, 1 },
[1] = { 1, 1, 1, 1 }
}
},
},
Enabled3 = Input { Value = 1, },
Enabled4 = Input { Value = 1, },
Level4 = Input { Value = 1, },
ExtendHorizontal4 = Input { Value = 0.147368421052632, },
ExtendVertical4 = Input { Value = 0.0842105263157895, },
Round4 = Input { Value = 0.068421052631579, },
Type4 = Input { Value = 2, },
Green4 = Input { Value = 0.478991596638655, },
ShadingGradient4 = Input {
Value = Gradient {
Colors = {
[0] = { 0.166666666666667, 0.166666666666667, 0.166666666666667, 1 },
[0.503937007874016] = { 1, 1, 1, 1 },
[1] = { 0.306666666666667, 0.306666666666667, 0.306666666666667, 1 }
}
},
},
ShadingMappingAngle4 = Input { Value = -135.9574468, },
Type3 = Input { Value = 2, },
ShadingGradient3 = Input {
Value = Gradient {
Colors = {
[0] = { 0, 0, 0, 1 },
[1] = { 1, 1, 1, 1 }
}
},
},
},
ViewInfo = OperatorInfo { Pos = { 1546, 158 } },
}
},
ActiveTool = "Text1"
}
Re: Get pixel width of a text

Posted:
Sat Jul 23, 2016 12:36 pm
by Tim Webstein
Hi Steve,
Many thanks for your answer.
Unfortunately, my box around the text isn't just an ordinary rectangle. Instead, it's custom-shaped by a polyline. Furthermore, I'd like to animate the stroke in a way that it kind of draws the shape around the text over time. This all works well with the only problem that I have to manually resize the shape when changing the text. That's why I was hoping to find a way to get access to the actual pixel size of a text and connect the position of some points of my PolylineStroke to this value.
Thanks again,
Tim