Hi Thomas,

Many thanks for such a speedy reply...!

On 28 Aug 2007 at 21:22, [EMAIL PROTECTED] wrote:

> "Matthew Darlison" <[EMAIL PROTECTED]> wrote on 08/28/2007 01:26:46 PM:
> 
> > I'm working on code to generate a Java2D illustration, and output it to 
> a 
> > variety of formats, including SVG via the Batik SVGGraphics2D.
> 
>    What version of Batik are you using?

I've verified and rebuilt, and I'm using JDK 1.6 and the result of the 
all-jar target on a current pull of the SVN repository.

> > I'm getting great output quality, but large files because the default
> > export renders the entire outlines of the text to paths, rather than the
> > text itself. 
> 
>    There are a number of ways that this can happen.  How are you drawing
> the text?  (what method is being used on the Graphics2D?).

An example would be:
... 

private Font CapFont = new Font("Sans Serif", Font.PLAIN, 
this.getTextSize());
...

String slabel = "String of unpredictable length";
      
AttributedString sas = new AttributedString(slabel);
sas.addAttribute(TextAttribute.FONT, getCapFont());
AttributedCharacterIterator saci = sas.getIterator();
FontRenderContext sfrc = g2.getFontRenderContext();
LineBreakMeasurer slbm = new LineBreakMeasurer(saci, sfrc);
float swrappingWidth = (this.getXDimension()/4)-offsetunit;
float sx = offsetunit;
float sy = rowcentre1 -offsetunit;
while (slbm.getPosition() < saci.getEndIndex()) {
  TextLayout stextLayout = slbm.nextLayout(swrappingWidth);
  sy += stextLayout.getAscent();
  stextLayout.draw(g2, sx, sy);
  sy += stextLayout.getDescent() + stextLayout.getLeading();
  sx = offsetunit;
}

which comes basically from the Sun 2D tutorial... 

> > Is there any way of configuring the export to say I'm happy to take the
> > quality hit, and lose the abaility to determine exactly what font gets
> > used, if it means I get a clean SVG with text in it rather than lots of
> > very long outline geometric paths...?
> 
>    The default behavior is to try and render text as text.  There is a
> parameter you can pass to the constructor of the SVGGraphics2D that will
> force it to always convert text to paths. I'm assuming that you haven't
> set that.

I don't think I have... this is how I instantiate it... 

DOMImplementation domImpl = 
GenericDOMImplementation.getDOMImplementation();
               
// Create an instance of org.w3c.dom.Document
String svgNS = "http://www.w3.org/2000/svg";;
 Document document = domImpl.createDocument(svgNS, "svg", null);
               
SVGGeneratorContext ctx = SVGGeneratorContext.createDefault(document);
 ctx.setEmbeddedFontsOn(false);

// Create an instance of the SVG Generator
SVGGraphics2D svgGenerator = new SVGGraphics2D(ctx, false);
// set the precision to avoid a null pointer exception in Batik 1.5
svgGenerator.getGeneratorContext().setPrecision(6);

this.paint(svgGenerator);

...

> > I'd be happy with a CSS-style definition of "sans-serif" and a point 
> size...
> 
>    I think the current versions of the SVGGraphics2D will handle
> almost all text as text except in cases where advanced features are
> used like AttributedCharacterIterators with some of the more complex
> attributes, or all GlyphVectors.

I'm not consciously using any sophisticated attributes... and I'll be 
immensely grateful if anyone can shed any llight on how to control what's 
happening...  

Many thanks!

Yours,

Matthew


-- 
"Mr. Matthew Darlison BA MA" <[EMAIL PROTECTED]>
Senior Research Fellow, Clinical & Applied Bioinformatics
UCL Centre for Health Informatics and Multiprofessional Education (CHIME)
WHO Collaborating Centre for the Community Control of Inherited Disorders
APoGI on the Web at http://www.chime.ucl.ac.uk/APoGI/



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to