jdor2svg


jdor2svg


JDOR2SVG writes the drawing of a JDOR macro as SVG. JDOR (Java drawing for ooRexx) is Rony G. Flatscher's command handler in BSF4ooRexx850: a Rexx program draws on a bitmap with commands named after the methods of java.awt.Graphics2D (moveTo, drawLine, fillOval, shape, rotate...). With its output redirected, the program leaves a macro: every command it ran, one per line, in canonical form.

address JDOR with output using (.output)      -- in the program, or:
rexx drawing.rxj ? > drawing.jdor              -- from the command line

jdor2svg reads that macro and writes the drawing as SVG, which scales to any size. svg2jdor goes the other way. The same translation draws the ```jdor blocks of a Markdown document in md2html, md2pdf, md2epub, md2slides and the CGI (see JDOR Blocks).

Usage

[rexx] jdor2svg [options] macro.jdor [drawing.svg | -]

The SVG goes beside the macro, with the extension .svg, unless another file is given; - writes it to the standard output. Every saveImage of the macro gives one more SVG (see Saved Pictures). jdor2svg then lists what it left out (see What Is Left Out).

When called without arguments, jdor2svg displays help information and exits.

Options


-h, --help Display help and exit
-q, --quiet Do not list what was left out
--no-saves No SVG for the saveImage commands
--id-prefix ID The prefix of the ids in the SVG (masks, clips,
gradients), for several drawings in one page (jdor)


What Is Translated

  • The image: newImage (or new) gives the size of the SVG; without one, it is 500 by 500, as in JDOR.
  • The current position: moveTo and its aliases (goto, location, pos, position).
  • The primitives: drawLine, drawRect, fillRect, draw3DRect, fill3DRect, drawRoundRect, fillRoundRect, drawOval, fillOval, drawArc, fillArc, drawPolygon, fillPolygon, drawPolyline, drawString (its blanks too), clearRect.
  • Colours: by name (the names JDOR knows), and color NAME r g b [a], as integers (0-255) or as fractions (0.0-1.0); an alpha is an opacity. background, gradientPaint (a linear gradient) and paint.
  • Strokes: width, cap, join, miter limit, dashes and their phase.
  • Fonts: font, fontSize, fontStyle, and names as Font.decode reads them (Arial-BOLD-18). Dialog and SansSerif are a sans-serif face, Serif a serif one, Monospaced and DialogInput a monospaced one.
  • The transform: translate, rotate (with its centre too), scale, shear, and transform (six numbers, RESET, named transforms).
  • pushGC and popGC; clip, clipShape and clipRemove. A clip by an area that is a union of shapes is exact; by any other area, it is taken by its outline.
  • Shapes: shape with Rectangle2D, RoundRectangle2D, Ellipse2D, Arc2D (OPEN, CHORD, PIE), Line2D, QuadCurve2D, CubicCurve2D, Polygon, Path2D and Area; drawShape, fillShape; the path... commands (pathMoveTo, pathLineTo, pathQuadTo, pathCurveTo, pathClose, pathAppend, pathClone, pathTransform, pathReset, pathWindingRule).
  • Areas: areaAdd, areaIntersect, areaSubtract, areaExclusiveOr and areaTransform. SVG has no operations on areas: an area is drawn with masks, its interior and its outline as Java draws them.
  • The alpha of a SRC_OVER composite.

An animation leaves its last frame: a new newImage, or a clearRect over the whole image, starts the drawing again.

Saved Pictures

saveImage F is where the program wrote a picture to the file F. jdor2svg writes the drawing as it stood at that point to F.svg: saveImage 2-110_JDOR_FontSample_2.gif gives 2-110_JDOR_FontSample_2.gif.svg. So a program that saves several pictures (the six pages of a font sample, the frames of an animation) gets all of them as SVG, and the main SVG is the last one.

The saved SVGs go in the folder of the main SVG (of the macro, with -). Only the name of F is taken, not its folder, which was on the machine that ran the program: saveImage C:\Users\me\pic.png gives pic.png.svg. A name that comes twice is written twice, and the last one stays, as in JDOR. --no-saves writes only the main SVG.

What Is Left Out

  • Bitmaps: loadImage, drawImage, the image stack, copyArea.
  • The XOR mode, and composites other than SRC_OVER.
  • Commands that do not draw (sleep, the win... commands, the queries) are skipped without a word.
  • A line that is not a JDOR command is skipped too, and counted: when a program says something to the same output, its words end up in the macro.

A macro records values, not variables. A command can name a Rexx variable that holds a Java object (a Color, a Stroke, a Shape, an AffineTransform...) instead of something JDOR registered: the macro has only the name, and cannot replay it. jdor2svg takes the name as JDOR takes an unknown one.

transform NAME, for a name the macro has not defined, keeps the current transform under that name. Up to JDOR 100.20230718, the redirected output wrote transform NAME tx ty sx sy shx shy (a transform stored under a name) as just transform NAME, and lost the six values; a patch to fix it went to Rony on 13/10/2026. With such a macro, a transform stored from the current one (transform TF rc, as in 1-190_JDOR_shapes) comes out right, and any other does not.

JDOR Blocks

In a Markdown document, a fenced block of JDOR commands is a drawing:

```jdor {#venn width=60%}
newImage 265 260
shape C1 Ellipse2D 10.0 25.0 50.0 50.0
...
```

The block becomes its SVG, in <div class="jdor">, as wide as its image and never wider than the column. width= sets its width; #id and .class go on the <div>. What the drawing leaves out is a warning of the build ("line 12: the JDOR drawing: left out: ..."); in md2slides, d shows it too. The lines after the block keep their numbers. A ```jdor block shown inside another fenced block stays as text. A block draws its last picture: its saveImage commands write nothing.