How to auto scale a group to stay constrained within a box?

Post questions on how to use or achieve an effect in Inkscape.
scapegoats
Posts: 3
Joined: Sun Jul 19, 2015 1:06 am

How to auto scale a group to stay constrained within a box?

Postby scapegoats » Sun Jul 19, 2015 1:44 am

Hello,

I have some multilingual translated text I want to render in Inkscape and auto-scale to fit inside a box. Sometimes the text will be very long (think German: "der scheudenfrangenbangendunderkaumpfen" or very short (think Chinese: >^|). Ideally, I'd like NOT to have to manually adjust the sizes, but rather to script the whole process and just replace the text inside the SVG and have it all "just work".

Caveat: I suspect this isn't really a text problem, but rather a "auto-scale a group inside a box" problem. I want multiple text border/outline colors, so I have actually have two text elements stacked up with different border colors and border thicknesses to get the effect I want. I suspect that some methods of auto scaling might scale/position those two text boxes differently, whereas I need to scale them as a group to keep them lined up with each other.

Lazur
Posts: 4717
Joined: Tue Jun 14, 2016 10:38 am

Re: How to auto scale a group to stay constrained within a b

Postby Lazur » Sun Jul 19, 2015 2:14 am

Hi there,

As far as I know it's not yet possible with the current tools inside inkscape.
Outside?

Only outside reference is the newly implemented symbol feature -apart linked raster images-, though it doesn't have a relative transformation with it /you don't have the option to define it's size by defining a custom viewbox for it.
Guess it won't make it to the features, would mess up the document structure and the rendering a bit?

Theoretically it is possible to code an svg alike, but I have no idea how to do it.
http://www.w3.org/TR/SVG/coords.html#ViewBoxAttribute

User avatar
Maestral
Posts: 982
Joined: Sat Aug 27, 2011 7:10 am

Re: How to auto scale a group to stay constrained within a b

Postby Maestral » Sun Jul 19, 2015 2:42 am

:tool_zoom: <<< click! - but, those with a cheaper tickets should go this way >>> :!:

scapegoats
Posts: 3
Joined: Sun Jul 19, 2015 1:06 am

Re: How to auto scale a group to stay constrained within a b

Postby scapegoats » Sun Jul 19, 2015 8:29 am

Lazur, are you saying there's a way to do it with linked raster images?

Lazur
Posts: 4717
Joined: Tue Jun 14, 2016 10:38 am

Re: How to auto scale a group to stay constrained within a b

Postby Lazur » Sun Jul 19, 2015 8:43 am

No, probably that wouldn't work either. I'm saying you can use a text editor, to link other svg-s outside your document, through a defined viewbox, but inkscape can not render that right.
Or some similar "hacks", superimposing two svg-s on top of each other.
Not sure if two viewboxes can be defined inside one svg, usual workaround is to have one viewbox/viewport and scale the whole document to be displayed right on screen.
If that's a text element, there should be a more straightforward.html

User avatar
brynn
Posts: 10309
Joined: Wed Sep 26, 2007 4:34 pm
Location: western USA
Contact:

Re: How to auto scale a group to stay constrained within a b

Postby brynn » Sun Jul 19, 2015 12:25 pm

I think you'd have to use SVG and either some javascript and/or possibly with CSS3. There is another recent message about having numbers increment in a similar way that you want the text to change, and the box around it automatically fit. Was that here? Or on LP? Looking.....

Could this help? http://wiki.colivre.net/Aurium/InkscapeGenerator You can search the forum. There are some other topics with similar requests, such as viewtopic.php" onclick="readonly();return false;"postlink-local" href="http://www.inkscapeforum.com/viewtopic.php" onclick="readonly();return false;">viewtopic.php?f=5&t=18387&p=68987&hilit=increment#p68987

scapegoats
Posts: 3
Joined: Sun Jul 19, 2015 1:06 am

Re: How to auto scale a group to stay constrained within a b

Postby scapegoats » Tue Jul 21, 2015 12:46 am

@brynn, replacing values in the file is the easy part, the difficulty is in scaling text to fill a rectangle.

I eventually got this to work via a multi step process:

1. Create an SVG of just the text element(s).
2. Have my script modify the text elements SVG to insert my localized text (translated into another language).
3. Export it to a raster PNG at a "really high" resolution.
4. Edit my main SVG to include an "<image>" tag that specifies scaling behavior, and pulls in the raster PNG by reference.
5. Tweak the coordinate values until it is properly scaled and centered for a variety of aspect ratios.
6. Now you can script the whole process and have text automatically expand to fill an area while staying proportional to its proper aspect ratio.

Here's the image tag included in my main SVG. The xMidYMid part does the magic, but you do have to tweak width, height, x, and y to establish the bounding box.

<image
sodipodi:absref="C:\somepath\TextOnlyExport.png"
xlink:href="TextOnlyExport.png"
y="254.70929"
x="594.25323"
id="image20293"
preserveAspectRatio="xMidYMid meet"
height="200"
width="500" />


Return to “Help with using Inkscape”