xmlgraphics-batik-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Vincent Hardy <vincent.ha...@sun.com>
Subject Re: Text size
Date Thu, 04 Oct 2001 06:55:44 GMT
Scott,

Using px units or user-space (same by default) is probably the best 
approach, but it depends on your context and constraints. From your 
comments, it seems to be working fine for you.

An SVG 'pt' is defined as 1/72 'in'. The mapping between an 'in' and
'px' depends on the size of one 'px' which depends on the user agent
(typically different for a screen and a printer).

There should not be any difference between Adobe and us if your are
using their latest version (beta3 I think). If you are using an older
version of their software, then you may see a difference as the
way SVG units are handled changed over the life of the SVG specification
process (there was a major change about a year ago).

About the pt units, 
Scott Moore wrote:
> 
> Vincent,
> 
> Thanks so much for the informative reply.  I've been using text-anchor, but
> didn't know about text-length or filter effects.
> 
> I took a look at moonPhases.svg and I see you are the author.  Most
> impressive!  Being relatively new to SVG (2 weeks), I had no idea you could
> do the things you do in moonPhases.
> 
> I'll learn about filter effects.  It sounds like it might solve some of my
> problems.
> 
> The real problem I have is determining how big to make the legend so the
> words don't flow off the picture.  Because I allow the users to choose the
> font and size, I'm currently using some haphazard calculations based on font
> size to guesstimate the maximum size needed.  After tweaking it, it seems to
> work pretty well for proportional fonts.  It isn't the ideal solution, but
> sounds like that's about the best I can do for now.
> 
> I have one question about font sizes.  When specifying a pt size (say a 10
> point font), what exactly does that mean?  How does it correspond to pixels?
> Or is it even possible to relate to pixels?  Because I'm generating JPEG and
> PNG files from Batik, I tend to base my coordinate system in terms of
> pixels.  I tried using the "viewBox" attribute and specifing a width and
> height in inches, but the picture quality suffered greatly.  Plus, the Adobe
> SVG viewer displayed the resulting SVG much differently than Batik.  Seems
> there are some issues there that need to be ironed out.
> 
> Thanks again,
> Scott
> 
> -----Original Message-----
> From: Vincent Hardy [mailto:vincent.hardy@sun.com]
> Sent: Wednesday, October 03, 2001 3:07 AM
> To: Batik Users
> Subject: Re: Text size
> 
> Scott,
> 
> Unfortunately, there is no good way of doing this in SVG right now.
> There are some round-about ways of using the SVG-DOM which would
> provide some solution, but Batik does not support that part of the
> SVG DOM yet.
> 
> I realize this is a disapointing answer. However, there are some tips
> to position text:
> 
> a. Using text-anchor, you can center a text on a given position.
> b. Using text-length, you can force a string of text to fit in a
>    given length.
> c. Using filter effects, you can create boxes around a text area
>    if you use object bounding box units.
> 
> There are probably other tricks you can use, but these are the ones
> from the top of my head. I use a with c. quite a bit and you can see an
> example in moonPhases.svg:
> 
> <filter id="bgRect" primitiveUnits="objectBoundingBox" x="-.2" y="-.2"
> width="1.4" height="1.4" >
>   <feFlood flood-color="black" flood-opacity=".5" result="bg"/>
>   ...
>   <feMerge>
>     <feMergeNode in="bg" />
>     ...
>     <feMergeNode in="SourceGraphic" />
>   </feMerge>
> </filter>
> 
> I hope this helps.
> Vincent.
> 
> > Scott Moore wrote:
> >
> > I'm using Batik directly in a Java program to create charts and graphs
> > via SVG and transcoding them into PNG files.  However, one of the
> > problems I constantly face is how to determine the exact size of a
> > text string.  For instance, when drawing a legend, I need to know the
> > size of the legend in order to properly size the graph next to it.
> >
> > How do I solve this problem?  Is there a way to do it directly in
> > SVG?  Is there an API in Batik that I can call to get the width of a
> > string in a given font and size?
> >
> > Any help would be much appreciated!
> >
> > Scott
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: batik-users-unsubscribe@xml.apache.org
> For additional commands, e-mail: batik-users-help@xml.apache.org
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: batik-users-unsubscribe@xml.apache.org
> For additional commands, e-mail: batik-users-help@xml.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xml.apache.org
For additional commands, e-mail: batik-users-help@xml.apache.org


Mime
View raw message