You are viewing a plain text version of this content. The canonical link for it is here.
Posted to batik-users@xmlgraphics.apache.org by "Michael E. Smoot" <me...@cs.virginia.edu> on 2003/03/06 23:22:03 UTC

newbie font question

Hello,

I can't seem to get SVGGraphics2D to generate fonts.  When I do a simple
drawString, the result is a path element in the output.  I _think_ I've
done what I'm supposed to according to
http://xml.apache.org/batik/svggen.html. Example code and output are
below.  My system is Mandrake 8.2 and I'm using Sun's jdk 1.4.1_01.

Eventually I'd like to be able to get SVGGraphics2D to generate font
elements for a drawGlyphVector call, but I figure I should start small.


many thanks!

Mike





import java.awt.Rectangle;
import java.awt.Graphics2D;
import java.awt.*;
import java.awt.Color;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.io.IOException;
import org.apache.batik.svggen.*;
import org.apache.batik.dom.*;
import org.apache.batik.dom.svg.*;
import org.w3c.dom.*;

public class TestSVGGen {


    public void paint(Graphics2D g2d) {
        g2d.setPaint(Color.red);
		g2d.fill(new Rectangle(10, 10, 100, 100));
		g2d.drawString("hello world", 10, 130);
    }

    public static void main(String [] args) throws IOException {
        // Get a DOMImplementation
        DOMImplementation domImpl =
            GenericDOMImplementation.getDOMImplementation();

        // Create an instance of org.w3c.dom.Document
        Document document = domImpl.createDocument(null, "svg", null);

        // Create an instance of the SVG Generator
        SVGGeneratorContext ctx = SVGGeneratorContext.createDefault(document);
        ctx.setEmbeddedFontsOn(true);
        SVGGraphics2D svgGenerator = new SVGGraphics2D(ctx,true);

        // Ask the test to render into the SVG Graphics2D implementation
        TestSVGGen test = new TestSVGGen();
        test.paint(svgGenerator);

        // Finally, stream out SVG to the standard output using UTF-8
        // character to byte encoding
        boolean useCSS = true; // we want to use CSS style attribute
        Writer out = new OutputStreamWriter(System.out, "UTF-8");
        svgGenerator.stream(out, useCSS);
    }
}







<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE svg PUBLIC '-//W3C//DTD SVG 1.0//EN' 'http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd'>
<svg xmlns:xlink="http://www.w3.org/1999/xlink" style="fill-opacity:1; color-rendering:auto; color-interpolation:auto; stroke:black; text-rendering:auto; stroke-linecap:square; stroke-miterlimit:10; shape-rendering:auto; stroke-opacity:1; fill:black; stroke-dasharray:none; font-weight:normal; stroke-width:1; font-family:&apos;sansserif&apos;; font-style:normal; stroke-linejoin:miter; font-size:12; stroke-dashoffset:0; image-rendering:auto;" xmlns="http://www.w3.org/2000/svg">
  <!--Generated by the Batik Graphics2D SVG Generator-->
  <defs id="genericDefs" />
  <g>
    <g style="fill:red; stroke:red;">
      <rect x="10" y="10" width="100" style="stroke:none;" height="100" />
      <path d="M11.15625 130 L11.15625 120.75 L12.3125 120.75 L12.3125 124.828125 Q13.21875 123.5 14.546875 123.5 Q15.375 123.5 15.8671875 124.0234375 Q16.359375 124.546875 16.359375 125.421875 L16.359375 130 L15.203125 130 L15.203125 125.796875 Q15.203125 125.09375 14.9921875 124.7890625 Q14.78125 124.484375 14.3125 124.484375 Q13.25 124.484375 12.3125 125.875 L12.3125 130 L11.15625 130 ZM23.259765625 129.796875 Q22.103515625 130.140625 21.275390625 130.140625 Q19.869140625 130.140625 18.986328125 129.2109375 Q18.103515625 128.28125 18.103515625 126.78125 Q18.103515625 125.34375 18.884765625 124.4140625 Q19.666015625 123.484375 20.884765625 123.484375 Q22.041015625 123.484375 22.666015625 124.3046875 Q23.291015625 125.125 23.291015625 126.640625 L23.291015625 127 L19.275390625 127 Q19.525390625 129.265625 21.494140625 129.265625 Q22.212890625 129.265625 23.259765625 128.875 L23.259765625 129.796875 ZM19.322265625 126.125 L22.134765625 126.125 Q22.134765625 124.359375 20.806640625 124.359375 Q19.478515625 124.359375 19.322265625 126.125 ZM25.2890625 130 L25.2890625 120.75 L26.4453125 120.75 L26.4453125 130 L25.2890625 130 ZM28.7578125 130 L28.7578125 120.75 L29.9140625 120.75 L29.9140625 130 L28.7578125 130 ZM34.7109375 130.140625 Q33.3515625 130.140625 32.5390625 129.234375 Q31.7265625 128.328125 31.7265625 126.8125 Q31.7265625 125.28125 32.5390625 124.390625 Q33.3515625 123.5 34.7578125 123.5 Q36.1640625 123.5 36.9765625 124.390625 Q37.7890625 125.28125 37.7890625 126.8125 Q37.7890625 128.359375 36.96875 129.25 Q36.1484375 130.140625 34.7109375 130.140625 ZM34.7265625 129.28125 Q36.5703125 129.28125 36.5703125 126.8125 Q36.5703125 124.359375 34.7578125 124.359375 Q32.9453125 124.359375 32.9453125 126.8125 Q32.9453125 129.28125 34.7265625 129.28125 ZM44.12890625 130 L42.31640625 123.640625 L43.44140625 123.640625 L44.83203125 128.5625 L46.34765625 123.640625 L47.48828125 123.640625 L48.81640625 128.5625 L50.41015625 123.640625 L51.41015625 123.640625 L49.33203125 130 L48.17578125 130 L46.81640625 125.078125 L45.30078125 130 L44.12890625 130 ZM55.125 130.140625 Q53.765625 130.140625 52.953125 129.234375 Q52.140625 128.328125 52.140625 126.8125 Q52.140625 125.28125 52.953125 124.390625 Q53.765625 123.5 55.171875 123.5 Q56.578125 123.5 57.390625 124.390625 Q58.203125 125.28125 58.203125 126.8125 Q58.203125 128.359375 57.3828125 129.25 Q56.5625 130.140625 55.125 130.140625 ZM55.140625 129.28125 Q56.984375 129.28125 56.984375 126.8125 Q56.984375 124.359375 55.171875 124.359375 Q53.359375 124.359375 53.359375 126.8125 Q53.359375 129.28125 55.140625 129.28125 ZM60.01171875 130 L60.01171875 123.640625 L61.16796875 123.640625 L61.16796875 124.828125 Q61.85546875 123.5 63.15234375 123.5 Q63.33984375 123.5 63.52734375 123.53125 L63.52734375 124.609375 Q63.23046875 124.5 62.99609375 124.5 Q61.90234375 124.5 61.16796875 125.796875 L61.16796875 130 L60.01171875 130 ZM64.921875 130 L64.921875 120.75 L66.078125 120.75 L66.078125 130 L64.921875 130 ZM72.46875 130 L72.46875 128.796875 Q71.765625 130.140625 70.359375 130.140625 Q69.203125 130.140625 68.546875 129.3046875 Q67.890625 128.46875 67.890625 127.015625 Q67.890625 125.421875 68.6328125 124.4609375 Q69.375 123.5 70.59375 123.5 Q71.734375 123.5 72.46875 124.359375 L72.46875 120.75 L73.640625 120.75 L73.640625 130 L72.46875 130 ZM72.46875 125.15625 Q71.578125 124.359375 70.78125 124.359375 Q69.109375 124.359375 69.109375 126.90625 Q69.109375 129.125 70.59375 129.125 Q71.546875 129.125 72.46875 128.078125 L72.46875 125.15625 Z" style="stroke:none;" />
    </g>
  </g>
</svg>



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