The Java Drawing with Apache Batik tutorial book I ordered from Amazon arrived, very fast by the way. It seems pretty good. I think it is a must have for anybody starting out with batik. I’m only half way through, but so far I’m glad I bought it. Examples are good. Covers the main parts of Batik: Generator, Transcoder, PrettyPrinter, JSVGCanvas. Also covers DOM, how to save to a file. Doesn’t seem to do much with glyphs though or get into how to use it in specific areas such as GIS. Although I’m not finished yet, so maybe in later chapters. Here’s the table of contents:
Chapter 1 Getting Started with Batik
Batik in Real World Projects
Your First SVG Document
Using SVG Rasterizer
What Else Comes with Batik?
Chapter 2 Creating SVG
Drawing in Java
Using SVG Creator
Other Features of SVG Generator
Chapter 3 Viewing SVG
Displaying Generated SVG Documents
Saving the Generated Document
Displaying an SVG File
Chapter 4 Working with Transcoders
The Transcoder API
Using Transcoders in Applications
Setting the Area of Interest
Using the SVGTranscoder for Pretty Printing
The Enhanced Version of the SVG File Viewer
Chapter 5 Document Object Model
SVG Document as a DOM Tree
Creating Documents with the DOM API
Building an SVG Document
Working with Gradients
Using the DOM API
Chapter 6 Working with Text and Fonts
Using the text Element
Using the Font Converter
Using SVG Fonts in a Document
Text Workbench: SVG Writer
Text Elements, Text Nodes, and Text Content
Using tspan elements
Text on A Path
Chapter 7 Batik on the Server Side
The SVG Graph Web Application
SVG Filter Effects
SVG Filters Web Application
Chapter 8 Batik Interactive
SVG and Scripts
Using Java for Scripting
Adding Animation 205 Summary
Appendix A Introduction to XML
Benefits of XML
Well-Formed XML Documents
Validating XML Documents
Related XML Resources
Your First Script
and a description:
This guide to Apache Batik, the Java library that can be used to read SVG files and translate the instructions in the files into graphics, shows how Batik can also be used to save the graphics as JPEG, TIFF, PNG, GIF, and other formats, so that the graphics can be transferred. Using Batik to create animation similar to Flash movies and its use for creating a drawing program such as Corel DRAW are also covered.
Scalable Vector Graphics (SVG) is an XML-based language for describing two-dimensional vector graphics and vector/raster graphics. The SVG specification describes in great detail how different shapes can be created, manipulated, transformed, and animated. In particular, SVG 1.1 defines:
Basic shape elements such as rectangle, circle, ellipse, line, polyline, and polygon.
Basic data types, such as integer, number, length, and angle.
The structure of an SVG document.
How to apply styles in an SVG document.
How to deal with text and how to use fonts.
How to work with colors, gradients, and patterns.
How and in which order elements should be rendered.
Which filter effects should be available and how to apply them.
How to animate images.
Apache Batik is a free and open-sourced implementation of SVG. It comes with tools and sample applications that demonstrate the power of SVG and Batik. This book is an easy-to-read tutorial on Batik. It teaches you how to use the tools in Batik and gets you started with Batik programming. In addition, it explains the following topics:
Batik implementation of the SVG specification
Transcoder and image format transcoding
Document Object Model API
Text and fonts
Using Batik on the server side
This info was taken from here.
Yes, I was able to get batik to draw a polygon, using an svg as the stroke and to do it correctly, not with the fill setting.
What you do is, first create a skeleton svg which contains a script to get the paths, calculate each path length, get the width of the svg you want to use as stroke. Divide path length by that to get the number of glyphs & then do a loop creating the glyph string.
?xml version=”1.0″ standalone=”no”?>
!DOCTYPE svg PUBLIC “-//W3C//DTD SVG 1.0//EN”
svg onload=”load(evt)” xmlns=”http://www.w3.org/2000/svg”
var svgNS = “http://www.w3.org/2000/svg”;
var doc = evt.target.ownerDocument;
var geometryGroup = doc.getElementById(“geometryGroup”);
var pathList = geometryGroup.getElementsByTagNameNS(svgNS, “path”);
var numPaths = pathList.length;
for (var i = 0; i < numPaths; i++)
var path = pathList.item(i);
var pathLength = path.getTotalLength();
//var pt = path.getPointAtLength(dist);
var glyphDefs = doc.getElementById(“glyphDefs”);
var symbolSVG = glyphDefs.getElementsByTagNameNS(svgNS, “svg”).item(0);
var widthAttribute = symbolSVG.getAttributeNS(null, “width”);
var patternWidth = parseFloat(widthAttribute.substring(0, widthAttribute.length – 2));
var numGlyphs = Math.floor((pathLength / patternWidth) * 2);
var glyphsStr = “”;
for (var j = 0; j <= numGlyphs; j++)
glyphsStr += “A”;
var glyphTextPath = document.getElementById(“glyphTextPath” + i);
Using batik, you create a group for each path, add that info to the skeleton svg using the dom, add the svg you want to use as the stroke to the defs section, fill in units-per-em & horiz-adv-x info & any other missing info. Add that to the canvas & draw. Very cool.
This site is also invaluable.