List Info

Thread: Dynamically setting font-size and horizontal scale




Dynamically setting font-size and horizontal scale
user name
2006-01-06 03:27:20
 Hi,

I am using a Transcoder to rasterize svg files.

These file are preprocessed to replace some text elements. Depending on the actual length of the text I would like to change its font-size.

In Postscript for example you can retrieve the actual length of a text at some font size, so you can use these length value to calculate dynamically a new font size.

I would like to do this with batik. Is it possible?

I would also like to set an x scale to a font size. I could use the transform=scale(x, y) but if the text is in a path it doesn't work.

I don't see anything in the svg specification that allow this kind of functionality. But is it possible to do it with Batik?

Thanks.

Oscar


Yahoo! DSL Something to write home about. Just $16.99/mo. or less
Dynamically setting font-size and horizontal scale
user name
2006-01-06 08:25:43
Hi Oscar,

I don't if it fits in your project workflow, but SVG has a
number of 
text-related methods that return bounding boxes and computed
text 
length. You could use these methods to adapt font-sizes or
adjust the 
letter spacing.

have a look at the DOM methods and properties of a SVG
textelement:

see http://phr
ogz.net/ObjJob/object.asp?id=146
or
ht
tp://www.w3.org/TR/SVG11/text.html#DOMInterfaces

the following methods might be of interest:
.getComputedTextLength()
.getBBox() - this is a general method of a svg element, not
text related.
.getStartPositionOfChar()
.getEndPositionOfChar()
.getExtentOfChar()

you can read out these values either for the full text,
individual 
characters or words and then adjust letterspacing or
font-sizes.

I don't know if one can actually calculate the new values to
exactly fit 
a given length, but you could certainly iteratively adjust
the values 
until the text-length is good enough if that is quick
enough.

I don't know if there is a more elegant methods.

You could do these adjustments using onload scripts or Java.

Andreas

Oscar Picasso wrote:

>  Hi,
>
> I am using a Transcoder to rasterize svg files.
>
> These file are preprocessed to replace some text
elements. Depending 
> on the actual length of the text I would like to change
its font-size.
>
> In Postscript for example you can retrieve the actual
length of a text 
> at some font size, so you can use these length value to
calculate 
> dynamically a new font size.
>
> I would like to do this with batik. Is it possible?
>
> I would also like to set an x scale to a font size. I
could use the 
> transform=scale(x, y) but if the text is in a path it
doesn't work.
>
> I don't see anything in the svg specification that
allow this kind of 
> functionality. But is it possible to do it with Batik?
>
> Thanks.
>
> Oscar
>
> Yahoo! DSL 
> <http://pa.yahoo.c
om/*http://us.rd.yahoo.com/evt=37474/*http://promo.yahoo.com
/broadband/%20> 
> Something to write home about. Just $16.99/mo. or less 



-- 
----------------------------------------------
Andreas Neumann - Institute of Cartography
Swiss Federal Institute of Technology (ETH)
ETH Hoenggerberg
CH-8093  Zurich, Switzerland
Phone: ++41-1-633 3031, Fax: ++41-1-633 1153
e-mail: neumannkarto.baug.ethz.ch
www: http://www.carto.net/ne
umann/
SVG.Open: http://www.svgopen.org/
Carto.net: http://www.carto.net/


------------------------------------------------------------
---------
To unsubscribe, e-mail: batik-users-unsubscribexmlgraphics.apache.org
For additional commands, e-mail: batik-users-helpxmlgraphics.apache.org

Dynamically setting font-size and horizontal scale
user name
2006-01-06 11:09:13
Hi Oscar, Andreas,

   Oscar, what Andreas says is exactly correct you will need
to use the 
SVG DOM
to query the current text length (probably using
getComputedTextLength), 
so you
can select an appropriate font-size.

   Then to make the text fit the available area the simplest
thing to do 
is to just set 
the 'textLength' property, there is a sister property called

'lengthAdjust' which can
be set to 'spacing' or 'spacingAndGlyphs'.  With the value
'spacing' only 
the
space between glyphs is adjusted, With the value
'spacingAndGlyphs' the
glyphs (as well as the spaces) are stretched to fill the
desired extent 
(which
sounds like what you want to do).

   The easiest place to do this would be in an 'onload'
event handler. You 
will
need to either add this as ECMAScript (javascript) to the
SVG content it's 
self
(usually in a script element) or you could register an
'SVGLoad' DOM event
listener in Java after reading the Document but before
giving it to the 
Transcoder.

   The transcoders have a 'hint' that indicates that the
'onload' event 
should be
fired (normally they aren't).

Andreas Neumann <neumannkarto.baug.ethz.ch>
wrote on 01/06/2006 03:25:43 
AM:

> I don't if it fits in your project workflow, but SVG
has a number of 
> text-related methods that return bounding boxes and
computed text 
> length. You could use these methods to adapt font-sizes
or adjust the 
> letter spacing.
> 
> have a look at the DOM methods and properties of a SVG
textelement:
> 
> see http://phr
ogz.net/ObjJob/object.asp?id=146
> or
> ht
tp://www.w3.org/TR/SVG11/text.html#DOMInterfaces
> 
> the following methods might be of interest:
> .getComputedTextLength()
> .getBBox() - this is a general method of a svg element,
not text 
related.
> .getStartPositionOfChar()
> .getEndPositionOfChar()
> .getExtentOfChar()
> 
> you can read out these values either for the full text,
individual 
> characters or words and then adjust letterspacing or
font-sizes.
> 
> I don't know if one can actually calculate the new
values to exactly fit 

> a given length, but you could certainly iteratively
adjust the values 
> until the text-length is good enough if that is quick
enough.
> 
> I don't know if there is a more elegant methods.
> 
> You could do these adjustments using onload scripts or
Java.
> 
> Andreas
> 
> Oscar Picasso wrote:
> 
> >  Hi,
> >
> > I am using a Transcoder to rasterize svg files.
> >
> > These file are preprocessed to replace some text
elements. Depending 
> > on the actual length of the text I would like to
change its font-size.
> >
> > In Postscript for example you can retrieve the
actual length of a text 

> > at some font size, so you can use these length
value to calculate 
> > dynamically a new font size.
> >
> > I would like to do this with batik. Is it
possible?
> >
> > I would also like to set an x scale to a font
size. I could use the 
> > transform=scale(x, y) but if the text is in a path
it doesn't work.
> >
> > I don't see anything in the svg specification that
allow this kind of 
> > functionality. But is it possible to do it with
Batik?
> >
> > Thanks.
> >
> > Oscar
> >
> > Yahoo! DSL 
> > 
<http://pa.yahoo.com/*http://us.rd.yaho
o.com/evt=37474/*http://promo.yahoo.
> com/broadband/%20> 
> > Something to write home about. Just $16.99/mo. or
less 
> 
> 
> 
> -- 
> ----------------------------------------------
> Andreas Neumann - Institute of Cartography
> Swiss Federal Institute of Technology (ETH)
> ETH Hoenggerberg
> CH-8093  Zurich, Switzerland
> Phone: ++41-1-633 3031, Fax: ++41-1-633 1153
> e-mail: neumannkarto.baug.ethz.ch
> www: http://www.carto.net/ne
umann/
> SVG.Open: http://www.svgopen.org/
> Carto.net: http://www.carto.net/
> 
> 
>
------------------------------------------------------------
---------
> To unsubscribe, e-mail: batik-users-unsubscribexmlgraphics.apache.org
> For additional commands, e-mail: batik-users-helpxmlgraphics.apache.org
> 


------------------------------------------------------------
---------
To unsubscribe, e-mail: batik-users-unsubscribexmlgraphics.apache.org
For additional commands, e-mail: batik-users-helpxmlgraphics.apache.org

[1-3]

about | contact  Other archives ( Real Estate discussion Medical topics )