/******************************************************************************/ /* */ /* jdor2svg.cls - JDOR drawing commands to SVG */ /* =========================================== */ /* */ /* This program is part of the Rexx Parser package */ /* [See https://rexx.epbcn.com/rexx-parser/] */ /* */ /* Copyright (c) 2024-2026 Josep Maria Blasco */ /* */ /* License: Apache License 2.0 (https://www.apache.org/licenses/LICENSE-2.0) */ /* */ /* Date Version Details */ /* -------- ------- --------------------------------------------------------- */ /* 20261013 0.7 First version */ /* 20261013 0.7 saveImage keeps a snapshot (~saved) (Rony, 13/10) */ /* 20261013 0.7 gradientPaint without "cyclic"; a clip by a union, exact */ /* 20261103 0.7 state (private), for jdor.cls */ /* 20261103 0.7 GREEN, ORANGE and PINK are java.awt.Color's, as in JDOR */ /* */ /******************************************************************************/ /* */ /* JDOR (Java drawing for ooRexx, Rony G. Flatscher's command handler in */ /* BSF4ooRexx850) draws on a bitmap with commands named after the methods of */ /* java.awt.Graphics2D. With its output redirected (ADDRESS JDOR WITH OUTPUT */ /* USING ...), a program leaves a "macro": every command it ran, one per */ /* line, in canonical form. This class reads such a macro and writes the */ /* drawing as SVG, so that it scales to any size (Rony, 12/10/2026). */ /* */ /* What is translated: the current position (moveTo and its aliases), the */ /* Graphics2D primitives (lines, rectangles, round rectangles, ovals, arcs, */ /* polygons, polylines, strings), colours (named, RGB and RGBA, as integers */ /* or as fractions), gradient paints, strokes (width, cap, join, miter limit, */ /* dashes), fonts, the transform (translate, rotate, scale, shear, */ /* transform), clips, pushGC/popGC, the shapes (Rectangle2D, */ /* RoundRectangle2D, Ellipse2D, Arc2D, Line2D, QuadCurve2D, CubicCurve2D, */ /* Polygon, Path2D and its path* commands) and the areas with their four */ /* operations (add, intersect, subtract, exclusiveOr), and the alpha of a */ /* SRC_OVER composite. */ /* */ /* What is not: bitmaps (loadImage, drawImage, the image stack, copyArea), */ /* the XOR mode and the other composites. They are left out, and said so */ /* (~notes). Commands that do not draw (sleep, the win* commands, the */ /* queries...) are skipped in silence. An animation leaves its last frame: */ /* a newImage, or a clearRect over the whole image, starts again. */ /* */ /* saveImage F, which writes the bitmap drawn so far to the file F, keeps an */ /* SVG of that same drawing: ~saved is an Array of them, in order, each a */ /* Directory with the file name as written (~name) and the lines of the SVG */ /* (~svg). jdor2svg.rex writes each one as F.svg (Rony, 13/10/2026), so that */ /* a program that saves several pictures gets all of them as SVG. */ /* */ /* The areas. SVG has no operations on areas, so an area is drawn with masks, */ /* recursively: its interior is white in a mask (a union is both, an */ /* intersection one inside the other's mask, a difference the second painted */ /* black over the first...), and its outline is the outlines of its parts, */ /* each kept only where the area's edge runs (the edge of A + B is the edge */ /* of A outside B and that of B outside A, and so on). */ /* */ /* Usage: */ /* */ /* conv = .JDOR.SVG~new("j1") -- the prefix of every id it makes */ /* svg = conv~convert(lines) -- an Array of lines, or a string */ /* Do note Over conv~notes; Say note; End */ /* Do snap Over conv~saved; ... snap~name, snap~svg ...; End */ /* */ /* Macros record values, not variables: a command that names a Rexx variable */ /* holding a Java object (a Color, a Shape, an AffineTransform...) cannot be */ /* replayed from the macro, and is taken as JDOR would take an unknown name. */ /* */ /******************************************************************************/ ::Options Digits 16 ::Class JDOR.SVG Public /******************************************************************************/ /* init: the prefix of the ids (masks, clips, gradients), so that several */ /* drawings can live in one HTML page. */ /******************************************************************************/ ::Method init Expose st Use Strict Arg prefix = "jdor" st = .Directory~new st~prefix = prefix st~saved = .Array~new ::Attribute notes Get Expose st out = .Array~new Do name Over st~noteOrder n = st~noteCount[name] out~append(name || (n == 1)~?("", " ("n "times)") || ":" st~noteWhy[name]) End Return out ::Attribute saved Get Expose st Return st~saved~copy /******************************************************************************/ /* state: the converter's state itself (registries and graphic context), for */ /* a subclass that drives the converter command by command (jdor.cls, the */ /* JDOR command handler without Java). */ /******************************************************************************/ ::Method state Private Expose st Return st /******************************************************************************/ /* convert: the macro, as an Array of lines or a string, to an Array of the */ /* lines of an SVG document. */ /******************************************************************************/ ::Method convert Expose st Use Strict Arg source If \source~isA(.Array) Then source = source~makeArray st~noteOrder = .Array~new st~noteCount = .Directory~new st~noteWhy = .Directory~new st~nextId = 0 st~saved = .Array~new self~resetAll st~started = 0 Do line Over source self~command(line) End If \st~started Then self~newImage(500, 500) Return self~document /******************************************************************************/ /* document: the drawing as it stands, as an Array of the lines of an SVG. */ /******************************************************************************/ ::Method document Private Expose st w = st~width; h = st~height out = .Array~new out~append('') If st~defs~items > 0 Then Do out~append("") out~appendAll(st~defs) out~append("") End out~appendAll(st~elements) out~append("") Return out /******************************************************************************/ /* The state: the registries (kept across images, as JDOR keeps them) and */ /* the graphic context (new with every image). */ /******************************************************************************/ ::Method resetAll Private Expose st st~colors = .Directory~new st~strokes = .Directory~new st~fonts = .Directory~new st~shapes = .Directory~new st~transforms = .Directory~new st~gradients = .Directory~new st~fontSize = 12 st~fontStyle = 0 st~stack = .Array~new st~defs = .Array~new st~elements = .Array~new st~width = 500 st~height = 500 st~gc = NewGC() ::Method newImage Private Expose st Use Arg w = 500, h = 500 st~started = 1 st~width = Fmt(w) st~height = Fmt(h) st~elements = .Array~new st~defs = .Array~new st~stack = .Array~new st~gc = NewGC() ::Method newId Private Expose st Use Arg kind st~nextId += 1 Return st~prefix"-"kind || st~nextId ::Method note Private Expose st Use Arg name, why If \st~noteCount~hasIndex(name) Then Do st~noteOrder~append(name) st~noteCount[name] = 0 st~noteWhy[name] = why End st~noteCount[name] += 1 /******************************************************************************/ /* One line of the macro. */ /******************************************************************************/ ::Method command Private Expose st Use Arg line line = line~changeStr("0d"x, "") text = line~strip("L") If text == "" Then Return If "-;/""'.:!?_"~pos(text[1]) > 0 Then Return -- a comment command Parse Var text verb rest cmd = verb~upper args = rest~space~makeArray(" ") n = args~items gc = st~gc -- What draws needs an image: JDOR makes one of 500 x 500 if there is none If \st~started, WordPos(cmd, "NEWIMAGE NEW RESET CLEAR") == 0 Then Do If \IsQuiet(cmd) Then self~newImage(500, 500) gc = st~gc End Select When cmd == "NEWIMAGE" | cmd == "NEW" Then Do w = 500; h = 500 If n >= 1, DataType(args[1], "N") Then w = args[1] If n >= 2, DataType(args[2], "N") Then h = args[2] self~newImage(w, h) End When cmd == "RESET" | cmd == "CLEAR" Then Do started = st~started; w = st~width; h = st~height els = st~elements; defs = st~defs self~resetAll st~started = started; st~width = w; st~height = h st~elements = els; st~defs = defs End When WordPos(cmd, "GOTO LOCATION MOVETO POS POSITION") > 0 Then Do If n == 0 Then Return gc~x = Num(args[1]) gc~y = Num((n >= 2)~?(args[2], args[1])) End -- Colours, paints, strokes, fonts When cmd == "COLOR" | cmd == "COLOUR" Then Do If n == 0 Then Return If n >= 4 Then Do c = MakeColor(args[2], args[3], args[4], (n >= 5)~?(args[5], "")) st~colors[args[1]~upper] = c End Else c = self~colorNamed(args[1]) If c \== .Nil Then Do gc~color = c; gc~paint = c End End When cmd == "BACKGROUND" Then Do If n == 0 Then Return c = self~colorNamed(args[1]) If c \== .Nil Then gc~background = c End When cmd == "GRADIENTPAINT" Then Do If n == 0 Then Return If n >= 7 Then Do c1 = self~colorNamed(args[4]); c2 = self~colorNamed(args[7]) If c1 == .Nil | c2 == .Nil Then Return g = .Directory~new g~kind = "gradient" g~x1 = Num(args[2]); g~y1 = Num(args[3]); g~c1 = c1 g~x2 = Num(args[5]); g~y2 = Num(args[6]); g~c2 = c2 g~cyclic = 0 If n >= 8 Then g~cyclic = IsTrue(args[8]) st~gradients[args[1]~upper] = g End Else g = st~gradients[args[1]~upper] If g \== .Nil Then gc~paint = g End When cmd == "PAINT" Then Do If n == 0 Then Return p = st~gradients[args[1]~upper] If p == .Nil Then p = self~colorNamed(args[1]) If p \== .Nil Then gc~paint = p End When cmd == "STROKE" Then Do If n == 0 Then Return If n >= 2 Then Do s = .Directory~new s~width = Num(args[2]) s~cap = "square"; s~join = "miter"; s~miter = 10 s~dash = ""; s~phase = 0 If n >= 3 Then s~cap = CapOf(args[3]) If n >= 4 Then s~join = JoinOf(args[4]) If n >= 5 Then s~miter = Max(1, Num(args[5])) If n >= 6 Then Do dash = "" Do v Over NumList(args[6]) dash ||= " "Fmt(v) End s~dash = Strip(dash) End If n >= 7 Then s~phase = Num(args[7]) st~strokes[args[1]~upper] = s End Else Do s = st~strokes[args[1]~upper] If s == .Nil Then Do self~note("stroke" args[1], "a stroke the macro never defines") Return End End gc~stroke = s End When cmd == "FONT" Then Do If n == 0 Then Return If n >= 2 Then Do f = DecodeFont(rest~space~subWord(2), st~fontSize, st~fontStyle) st~fonts[args[1]~upper] = f End Else Do f = st~fonts[args[1]~upper] If f == .Nil Then f = DecodeFont(args[1], st~fontSize, st~fontStyle) End gc~font = f End When cmd == "FONTSIZE" Then Do If n > 0, DataType(args[1], "N") Then st~fontSize = args[1] End When cmd == "FONTSTYLE" Then Do If n > 0 Then st~fontStyle = StyleOf(args[1]) End When cmd == "COMPOSITE" Then Do If n == 0 Then Return rule = args[1]~upper If rule == "SRC_OVER" | rule == 3 Then gc~alpha = (n >= 2)~?(Num(args[2]), 1) Else self~note("composite" args[1], "only SRC_OVER (with its alpha) has an SVG equivalent") End -- The transform When cmd == "TRANSLATE" Then Do If n == 0 Then Return tx = Num(args[1]); ty = Num((n >= 2)~?(args[2], args[1])) gc~m = Mul(gc~m, .Array~of(1, 0, 0, 1, tx, ty)) End When cmd == "ROTATE" Then Do If n == 0 Then Return If n >= 3 Then gc~m = Mul(gc~m, .Array~of(1, 0, 0, 1, Num(args[2]), Num(args[3]))) gc~m = Mul(gc~m, RotM(Num(args[1]))) If n >= 3 Then gc~m = Mul(gc~m, .Array~of(1, 0, 0, 1, -Num(args[2]), -Num(args[3]))) End When cmd == "SCALE" Then Do If n == 0 Then Return sx = Num(args[1]); sy = Num((n >= 2)~?(args[2], args[1])) gc~m = Mul(gc~m, .Array~of(sx, 0, 0, sy, 0, 0)) End When cmd == "SHEAR" Then Do If n == 0 Then Return hx = Num(args[1]); hy = Num((n >= 2)~?(args[2], args[1])) gc~m = Mul(gc~m, .Array~of(1, hy, hx, 1, 0, 0)) End When cmd == "TRANSFORM" Then self~transformCommand(args) -- The graphic context's stack, and clips When cmd == "PUSHGC" Then st~stack~append(CopyGC(gc)) When cmd == "POPGC" Then Do If st~stack~items > 0 Then st~gc = st~stack~delete(st~stack~last) End When cmd == "CLIP" Then Do If n < 4 Then Return segs = RectSegs(Num(args[1]), Num(args[2]), Num(args[3]), Num(args[4])) self~addClip(segs, "nonzero") End When cmd == "CLIPSHAPE" | cmd == "SHAPECLIP" Then Do If n == 0 Then Return sh = self~shapeNamed(args[1]) If sh == .Nil Then Return If sh~kind == "area" Then Do leaves = UnionLeaves(sh~expr) If leaves \== .Nil Then self~addClipParts(leaves) -- a union: exact Else Do self~note(cmd~lower args[1], "a clip by an area is taken by its outline") segs = AreaSegs(sh~expr) self~addClip(segs, "evenodd") End End Else self~addClip(sh~segs, sh~rule) End When cmd == "CLIPREMOVE" Then gc~clips = .Array~new -- Drawing When cmd == "DRAWLINE" Then Do If n < 2 Then Return segs = .Array~of(.Array~of("M", gc~x, gc~y), .Array~of("L", Num(args[1]), Num(args[2]))) self~drawSegs(segs, "nonzero", "draw") End When WordPos(cmd, "DRAWRECT FILLRECT DRAW3DRECT FILL3DRECT CLEARRECT") > 0 Then Do If n < 2 Then Return w = Num(args[1]); h = Num(args[2]) If cmd == "CLEARRECT" Then Do self~clearRect(w, h) Return End mode = (cmd[1] == "D")~?("draw", "fill") self~drawSegs(RectSegs(gc~x, gc~y, w, h), "nonzero", mode) End When cmd == "DRAWROUNDRECT" | cmd == "FILLROUNDRECT" Then Do If n < 4 Then Return segs = RoundRectSegs(gc~x, gc~y, Num(args[1]), Num(args[2]), Num(args[3]), Num(args[4])) self~drawSegs(segs, "nonzero", (cmd[1] == "D")~?("draw", "fill")) End When cmd == "DRAWOVAL" | cmd == "FILLOVAL" Then Do If n < 2 Then Return segs = EllipseSegs(gc~x, gc~y, Num(args[1]), Num(args[2])) self~drawSegs(segs, "nonzero", (cmd[1] == "D")~?("draw", "fill")) End When cmd == "DRAWARC" | cmd == "FILLARC" Then Do If n < 4 Then Return type = (cmd[1] == "D")~?("OPEN", "PIE") segs = ArcShapeSegs(gc~x, gc~y, Num(args[1]), Num(args[2]), Num(args[3]), Num(args[4]), type) self~drawSegs(segs, "nonzero", (cmd[1] == "D")~?("draw", "fill")) End When WordPos(cmd, "DRAWPOLYGON FILLPOLYGON DRAWPOLYLINE") > 0 Then Do If n < 3 Then Return segs = PolySegs(NumList(args[1]), NumList(args[2]), Num(args[3]), cmd \== "DRAWPOLYLINE") If segs == .Nil Then Return self~drawSegs(segs, "evenodd", (cmd[1] == "D")~?("draw", "fill")) End When cmd == "DRAWSTRING" Then Do -- only the blank after the command goes: the rest, blanks too, is the text str = line~substr(line~pos(verb) + verb~length + 1) self~drawString(str) End -- Shapes When cmd == "SHAPE" Then self~shapeCommand(args, rest) When cmd == "DRAWSHAPE" | cmd == "SHAPEDRAW" | cmd == "FILLSHAPE" | cmd == "SHAPEFILL" Then Do If n == 0 Then Return sh = self~shapeNamed(args[1]) If sh == .Nil Then Return mode = (cmd~pos("DRAW") > 0)~?("draw", "fill") If sh~kind == "area" Then self~drawArea(sh~expr, mode) Else self~drawSegs(sh~segs, sh~rule, mode) End When cmd~left(4) == "AREA" Then self~areaCommand(cmd, args) When cmd~left(4) == "PATH" Then self~pathCommand(cmd, args) -- What draws, but has no SVG here When WordPos(cmd, "DRAWIMAGE POPIMAGE") > 0 Then self~note(verb, "bitmaps are not translated") When cmd == "COPYAREA" Then self~note(verb, "it copies pixels") When cmd == "SETXORMODE" Then self~note(verb, "the XOR mode has no SVG equivalent") -- A picture written to a file: keep its SVG. As in JDOR, the file name -- is the rest of the line, blanks included When cmd == "SAVEIMAGE" Then Do name = text~substr(verb~length + 1)~strip If name == "" Then Return snap = .Directory~new snap~name = name snap~svg = self~document st~saved~append(snap) End -- What does not draw When IsQuiet(cmd) Then Nop Otherwise -- what a program says goes to the same output as its commands self~note("other lines", "not JDOR commands (what the program said?), such as '"text~left(30)~strip"'") End /******************************************************************************/ /* transform: query, RESET, six numbers (absolute), a name (a transform of */ /* its own, or, when the macro has none by that name, the current one kept */ /* under it: up to JDOR 100.20230718, the output wrote "transform T x y ..." */ /* as "transform T", and "transform T rc" kept the current transform), a */ /* name and six numbers. */ /******************************************************************************/ ::Method transformCommand Private Expose st Use Arg args gc = st~gc n = args~items If n == 0 Then Return If n == 1 Then Do If Abbrev("RESET", args[1]~upper, 1) Then Do gc~m = .Array~of(1, 0, 0, 1, 0, 0) Return End If \st~transforms~hasIndex(args[1]~upper) Then st~transforms[args[1]~upper] = gc~m~copy Return End If n == 6 Then Do gc~m = SixToM(args, 1, gc~m) Return End If n >= 7 Then st~transforms[args[1]~upper] = SixToM(args, 2, .Array~of(1, 0, 0, 1, 0, 0)) /******************************************************************************/ /* Shapes, areas and paths */ /******************************************************************************/ ::Method shapeNamed Private Expose st Use Arg name sh = st~shapes[name~upper] If sh == .Nil Then self~note("shape" name, "a shape the macro never defines") Return sh ::Method shapeCommand Private Expose st Use Arg args, rest n = args~items If n < 2 Then Return name = args[1]~upper type = args[2]~upper v = .Array~new Do i = 3 To n v~append(args[i]) End Select When type == "AREA" Then Do sh = .Directory~new sh~kind = "area" src = .Nil If v~items > 0 Then src = self~shapeNamed(v[1]) If src == .Nil Then sh~expr = .Array~of("leaf", .Array~new, "nonzero") Else If src~kind == "area" Then sh~expr = src~expr Else sh~expr = .Array~of("leaf", CopySegs(src~segs), src~rule) st~shapes[name] = sh Return End When WordPos(type, "ARC ARC2D") > 0 Then Do If v~items == 4 Then Do -- bounds start extent type b = self~shapeNamed(v[1]) If b == .Nil Then Return bb = SegsBox(b~segs) segs = ArcShapeSegs(bb[1], bb[2], bb[3] - bb[1], bb[4] - bb[2], - Num(v[2]), Num(v[3]), ArcType(v[4])) End Else Do If v~items < 7 Then Return segs = ArcShapeSegs(Num(v[1]), Num(v[2]), Num(v[3]), Num(v[4]), - Num(v[5]), Num(v[6]), ArcType(v[7])) End End When WordPos(type, "CUBIC CUBICCURVE CUBICCURVE2D") > 0 Then Do If v~items < 8 Then Return segs = .Array~of(.Array~of("M", Num(v[1]), Num(v[2])), - .Array~of("C", Num(v[3]), Num(v[4]), Num(v[5]), Num(v[6]), Num(v[7]), Num(v[8]))) End When WordPos(type, "ELLI ELLIPSE ELLIPSE2D") > 0 Then Do If v~items < 4 Then Return segs = EllipseSegs(Num(v[1]), Num(v[2]), Num(v[3]), Num(v[4])) End When WordPos(type, "LINE LINE2D") > 0 Then Do If v~items < 4 Then Return segs = .Array~of(.Array~of("M", Num(v[1]), Num(v[2])), .Array~of("L", Num(v[3]), Num(v[4]))) End When WordPos(type, "PATH PATH2D") > 0 Then Do sh = .Directory~new sh~kind = "path"; sh~segs = .Array~new sh~rule = "nonzero" If v~items > 0 Then sh~rule = RuleOf(v[1]) st~shapes[name] = sh Return End When type == "POLYGON" Then Do If v~items < 3 Then Return segs = PolySegs(NumList(v[1]), NumList(v[2]), Num(v[3]), 1) If segs == .Nil Then Return End When WordPos(type, "QUAD QUADCURVE QUADCURVE2D") > 0 Then Do If v~items < 6 Then Return segs = .Array~of(.Array~of("M", Num(v[1]), Num(v[2])), - .Array~of("Q", Num(v[3]), Num(v[4]), Num(v[5]), Num(v[6]))) End When WordPos(type, "RECT RECTANGLE RECTANGLE2D") > 0 Then Do If v~items < 4 Then Return segs = RectSegs(Num(v[1]), Num(v[2]), Num(v[3]), Num(v[4])) End When WordPos(type, "ROUNDRECT ROUNDRECTANGLE ROUNDRECTANGLE2D") > 0 Then Do If v~items < 6 Then Return segs = RoundRectSegs(Num(v[1]), Num(v[2]), Num(v[3]), Num(v[4]), Num(v[5]), Num(v[6])) End Otherwise Do self~note("shape ..." args[2], "an unknown kind of shape") Return End End sh = .Directory~new sh~kind = "path"; sh~segs = segs; sh~rule = "nonzero" st~shapes[name] = sh ::Method areaCommand Private Expose st Use Arg cmd, args If args~items < 2 Then Return a = self~shapeNamed(args[1]) If a == .Nil Then Return If a~kind \== "area" Then Do -- JDOR makes it one a~kind = "area" a~expr = .Array~of("leaf", a~segs, a~rule) End If cmd == "AREATRANSFORM" Then Do m = st~transforms[args[2]~upper] If m == .Nil Then Do self~note("areaTransform ..." args[2], "a transform the macro never defines") Return End a~expr = ExprMap(a~expr, m) Return End b = self~shapeNamed(args[2]) If b == .Nil Then Return If b~kind == "area" Then e = b~expr Else e = .Array~of("leaf", CopySegs(b~segs), b~rule) Select When cmd == "AREAADD" | cmd == "AREAUNION" Then op = "add" When cmd == "AREAINTERSECT" Then op = "intersect" When cmd == "AREASUBTRACT" Then op = "subtract" When cmd == "AREAEXCLUSIVEOR" | cmd == "AREAXOR" Then op = "xor" Otherwise Do self~note(cmd~lower, "not a JDOR command") Return End End a~expr = .Array~of(op, a~expr, e) ::Method pathCommand Private Expose st Use Arg cmd, args If args~items == 0 Then Return If cmd == "PATHITERATOR" | cmd == "PATHCURRENTPOINT" Then Return p = self~shapeNamed(args[1]) If p == .Nil Then Return If p~kind \== "path" Then Do self~note(cmd~lower args[1], "not a path") Return End v = .Array~new Do i = 2 To args~items v~append(args[i]) End segs = p~segs Select When cmd == "PATHMOVETO" Then Do If v~items >= 2 Then segs~append(.Array~of("M", Num(v[1]), Num(v[2]))) End When cmd == "PATHLINETO" Then Do If v~items >= 2 Then segs~append(.Array~of("L", Num(v[1]), Num(v[2]))) End When cmd == "PATHQUADTO" Then Do If v~items >= 4 Then segs~append(.Array~of("Q", Num(v[1]), Num(v[2]), Num(v[3]), Num(v[4]))) End When cmd == "PATHCURVETO" Then Do If v~items >= 6 Then segs~append(.Array~of("C", Num(v[1]), Num(v[2]), Num(v[3]), Num(v[4]), Num(v[5]), Num(v[6]))) End When cmd == "PATHCLOSE" Then segs~append(.Array~of("Z")) When cmd == "PATHRESET" Then p~segs = .Array~new When cmd == "PATHWINDINGRULE" Then Do If v~items >= 1 Then p~rule = RuleOf(v[1]) End When cmd == "PATHCLONE" Then Do If v~items == 0 Then Return c = .Directory~new c~kind = "path"; c~segs = CopySegs(segs); c~rule = p~rule st~shapes[v[1]~upper] = c End When cmd == "PATHTRANSFORM" Then Do If v~items == 0 Then Return m = st~transforms[v[1]~upper] If m == .Nil Then Do self~note("pathTransform ..." v[1], "a transform the macro never defines") Return End p~segs = MapSegs(segs, m) End When cmd == "PATHAPPEND" Then Do If v~items == 0 Then Return s = self~shapeNamed(v[1]) If s == .Nil Then Return If s~kind == "area" Then add = AreaSegs(s~expr) Else add = CopySegs(s~segs) connect = 1 If v~items >= 2 Then connect = IsTrue(v[2]) Do i = 1 To add~items sg = add[i] If i == 1, connect, sg[1] == "M", segs~items > 0 Then sg = .Array~of("L", sg[2], sg[3]) segs~append(sg) End End Otherwise self~note(cmd~lower, "not a JDOR command") End /******************************************************************************/ /* Emitting */ /******************************************************************************/ -- An element on the image: inside the clips and the alpha in force. ::Method emit Private Expose st Use Arg s gc = st~gc If gc~alpha < 1 Then s = ''s'' Do i = gc~clips~items To 1 By -1 s = ''s'' End st~elements~append(s) -- A clip, in the image's own space (the transform in force taken in). ::Method addClip Private Expose st Use Arg segs, rule gc = st~gc id = self~newId("c") st~defs~append('') gc~clips~append(id) -- A clip by a union of shapes: a clipPath with one path for each (SVG -- clips to the union of a clipPath's children). ::Method addClipParts Private Expose st Use Arg leaves gc = st~gc id = self~newId("c") s = '' Do leaf Over leaves s ||= '' End st~defs~append(s'') gc~clips~append(id) -- The fill or the stroke of the paint in force. ::Method paintAttr Private Expose st Use Arg prop p = st~gc~paint If p~kind == "color" Then Do s = ' 'prop'="'p~hex'"' If p~alpha < 1 Then s ||= ' 'prop'-opacity="'Fmt(p~alpha)'"' Return s End If \p~hasIndex("id") Then Do p~id = self~newId("g") st~defs~append('' - '' - '' - '') End Return ' 'prop'="url(#'p~id')"' ::Method strokeAttrs Private Expose st s = st~gc~stroke out = ' fill="none"'self~paintAttr("stroke") If s~width == 0 Then out ||= ' stroke-width="1" vector-effect="non-scaling-stroke"' Else out ||= ' stroke-width="'Fmt(s~width)'"' out ||= ' stroke-linecap="'s~cap'" stroke-linejoin="'s~join'"' If s~join == "miter" Then out ||= ' stroke-miterlimit="'Fmt(s~miter)'"' If s~dash \== "" Then Do out ||= ' stroke-dasharray="'s~dash'"' If s~phase \= 0 Then out ||= ' stroke-dashoffset="'Fmt(s~phase)'"' End Return out ::Method drawSegs Private Expose st Use Arg segs, rule, mode If segs~items == 0 Then Return gc = st~gc If mode == "fill" Then look = self~paintAttr("fill") || (rule \== "nonzero")~?(' fill-rule="'rule'"', "") Else look = self~strokeAttrs self~emit('') ::Method drawString Private Expose st Use Arg str gc = st~gc f = gc~font s = ''XmlEsc(str)'' self~emit(s) /* clearRect: over the whole image, a new frame (what was drawn goes); */ /* elsewhere, the rectangle painted with the background. */ ::Method clearRect Private Expose st Use Arg w, h gc = st~gc box = SegsBox(MapSegs(RectSegs(gc~x, gc~y, w, h), gc~m)) If gc~clips~items == 0, box[1] <= 0, box[2] <= 0, - box[3] >= st~width, box[4] >= st~height Then Do st~elements = .Array~new Return End paint = gc~paint; alpha = gc~alpha gc~paint = gc~background; gc~alpha = 1 self~drawSegs(RectSegs(gc~x, gc~y, w, h), "nonzero", "fill") gc~paint = paint; gc~alpha = alpha /* An area: its interior, white in a mask, filled; its outline, drawn where */ /* the area's edge runs. */ ::Method drawArea Private Expose st Use Arg expr, mode gc = st~gc bb = ExprBox(expr) If bb == .Nil Then Return pad = 10 If mode == "draw" Then pad += st~gc~stroke~width * 2 box = .Array~of(bb[1] - pad, bb[2] - pad, bb[3] - bb[1] + 2 * pad, bb[4] - bb[2] + 2 * pad) If mode == "fill" Then Do If expr[1] == "leaf" Then Do self~drawSegs(expr[2], expr[3], "fill") Return End m = self~areaMask(expr, 0, box) s = '' End Else s = ''self~outline(expr, box)~makeString("L", "")'' self~emit(s) /* The id of a mask that is white where the area is (or, inverse, where it */ /* is not). */ ::Method areaMask Private Expose st Use Arg expr, inverse, box id = self~newId("m") If inverse Then c = ''self~blackOf(expr, box) Else c = self~maskContent(expr, box) st~defs~append(''c'') Return id ::Method maskContent Private Use Arg expr, box Select Case expr[1] When "leaf" Then Return LeafPath(expr, "#fff") When "add" Then Return self~maskContent(expr[2], box) || self~maskContent(expr[3], box) When "intersect" Then Return ''self~maskContent(expr[2], box)'' When "subtract" Then Return self~maskContent(expr[2], box) || self~blackOf(expr[3], box) When "xor" Then Return ''self~maskContent(expr[2], box)'' || - ''self~maskContent(expr[3], box)'' End ::Method blackOf Private Use Arg expr, box If expr[1] == "leaf" Then Return LeafPath(expr, "#000") Return '' -- The outline of an area: the edges of its parts, each where it is edge. ::Method outline Private Use Arg expr, box out = .Array~new If expr[1] == "leaf" Then Do If expr[2]~items > 0 Then out~append('') Return out End a = expr[2]; b = expr[3] Select Case expr[1] When "add" Then Do; ma = self~areaMask(b, 1, box); mb = self~areaMask(a, 1, box); End When "intersect" Then Do; ma = self~areaMask(b, 0, box); mb = self~areaMask(a, 0, box); End When "subtract" Then Do; ma = self~areaMask(b, 1, box); mb = self~areaMask(a, 0, box); End Otherwise Do; ma = ""; mb = ""; End End out~append(MaskedGroup(ma, self~outline(a, box))) out~append(MaskedGroup(mb, self~outline(b, box))) Return out -- A colour by name: the macro's own, or a name JDOR knows. ::Method colorNamed Private Expose st Use Arg name c = st~colors[name~upper] If c \== .Nil Then Return c hex = NamedColor(name) If hex == "" Then Do self~note("color" name, "a colour the macro never defines") Return .Nil End c = .Directory~new c~kind = "color"; c~hex = hex; c~alpha = (name~upper == "TRANSPARENT")~?(0, 1) Return c /******************************************************************************/ /* JDORFences: the ```jdor blocks of a Markdown source, drawn. */ /* */ /* ```jdor {#id .class width=60%} */ /* newImage 200 100 */ /* ... */ /* ``` */ /* */ /* Each block becomes its SVG, inside
, on ONE line, and */ /* the lines it took become blank lines: the lines after it keep their */ /* numbers (what the pipelines say about "line 212", the Markdown of a slide */ /* and d's editor depend on them). Pandoc passes the
on as it is. The */ /* drawing is as wide as its image, never wider than the column; width= sets */ /* the width. Other fenced blocks are skipped whole, so a ```jdor shown */ /* inside a ````markdown block stays as text. What a drawing leaves out is */ /* appended to `notes` ("line 12: ..."). */ /******************************************************************************/ ::Routine JDORFences Public Use Strict Arg source, notes = (.Array~new) out = .Array~new count = 0 i = 0 Loop While i < source~items i += 1 line = source[i] indent = Length(line) - Length(Strip(line, "L")) bare = Strip(line, "L") char = bare[1] If char \== "`", char \== "~" Then Do; out~append(line); Iterate; End ticks = Length(bare) - Length(Strip(bare, "L", char)) If ticks < 3 Then Do; out~append(line); Iterate; End info = Strip(SubStr(bare, ticks + 1)) close = Copies(char, ticks) -- Where the block ends: a line of `close` (or longer), nothing after it j = i Loop j += 1 If j > source~items Then Leave t = Strip(source[j]) If t~startsWith(close), Strip(t, "T", char) == "" Then Leave End isJdor = Lower(info~left(4)) == "jdor" & (Length(info) == 4 | Pos(SubStr(info, 5, 1), " {"||"09"x) > 0) If \isJdor | j > source~items Then Do If isJdor Then notes~append("line" i": a ```jdor block that is never closed is left as it is") Loop k = i To Min(j, source~items) out~append(source[k]) End i = Min(j, source~items) Iterate End -- Its attributes: {#id .class width=...} attrs = Strip(SubStr(info, 5)) attrs = Strip(Strip(attrs, "L", "{"), "T", "}") id = ""; classes = ""; width = "" Loop w Over attrs~space~makeArray(" ") Select When w[1] == "#" Then id = SubStr(w, 2) When w[1] == "." Then classes ||= " "SubStr(w, 2) When Lower(w)~startsWith("width=") Then width = Strip(SubStr(w, 7), "B", '"') Otherwise notes~append("line" i": the ```jdor block does not know '"w"'") End End body = .Array~new Loop k = i + 1 To j - 1 body~append(source[k]) End count += 1 conv = .JDOR.SVG~new("jdor"count) svg = conv~convert(body) Loop n Over conv~notes notes~append("line" i": the JDOR drawing: left out:" n) End style = "display: block; margin: 0 auto; max-width: 100%; height: auto" If width \== "" Then style ||= "; width:" width svg[1] = svg[1]~changeStr("'svg~makeString("L", "")'
') Loop k = i + 1 To j out~append("") End i = j End Return out /******************************************************************************/ /* Routines */ /******************************************************************************/ -- A new graphic context: JDOR's defaults. ::Routine NewGC gc = .Directory~new black = .Directory~new black~kind = "color"; black~hex = "#000000"; black~alpha = 1 white = .Directory~new white~kind = "color"; white~hex = "#ffffff"; white~alpha = 1 s = .Directory~new s~width = 1; s~cap = "square"; s~join = "miter"; s~miter = 10; s~dash = ""; s~phase = 0 f = .Directory~new f~family = "sans-serif"; f~size = 12; f~bold = 0; f~italic = 0 gc~color = black; gc~paint = black; gc~background = white gc~stroke = s; gc~font = f gc~m = .Array~of(1, 0, 0, 1, 0, 0) gc~clips = .Array~new gc~alpha = 1 gc~x = 0; gc~y = 0 Return gc ::Routine CopyGC Use Arg gc c = gc~copy c~m = gc~m~copy c~clips = gc~clips~copy Return c -- Commands that do not change the drawing. ::Routine IsQuiet Use Arg cmd quiet = "SLEEP WINSHOW WINHIDE WINTITLE WINALWAYSONTOP WINALWAYSONTOPSUPPORTED" - "WINCLOSE WINFRAME WINLOCATION WINMOVETO WINRESIZABLE WINSCREENSIZE" - "WINSIZE WINTOBACK WINTOFRONT WINUPDATE WINVISIBLE RENDER" - "PRINTIMAGE PRINTPOS PRINTSCALE PRINTSCALETOPAGE GETSTATE GC ASSIGNRC" - "STRINGBOUNDS IMAGESIZE IMAGETYPE IMAGE PREFERREDIMAGETYPE" - "SETCLIPBOARD CLIPBOARDSET SETCLIPBOARDWITHOUTALPHA" - "CLIPBOARDSETWITHOUTALPHA GETCLIPBOARD CLIPBOARDGET SHAPEBOUNDS" - "SETPAINTMODE LOADIMAGE PUSHIMAGE IMAGECOPY" Return WordPos(cmd, quiet) > 0 ::Routine Num Use Arg v If DataType(v, "N") Then Return v + 0 Return 0 ::Routine IsTrue Use Arg v Return WordPos(v~upper, "1 .TRUE TRUE") > 0 -- A number for SVG: three decimals at most. ::Routine Fmt Use Arg v If \DataType(v, "N") Then Return 0 v = Format(v, , 3, 0) If v~pos(".") > 0 Then v = v~strip("T", "0")~strip("T", ".") If v == "-0" Then v = 0 Return v -- "(1,2,3)" -> an Array of numbers. ::Routine NumList Use Arg s s = s~strip~strip("L", "(")~strip("T", ")") out = .Array~new Do w Over s~makeArray(",") If w~strip \== "" Then out~append(Num(w~strip)) End Return out ::Routine CapOf Use Arg v v = v~upper If v == "CAP_BUTT" | v == 0 Then Return "butt" If v == "CAP_ROUND" | v == 1 Then Return "round" Return "square" ::Routine JoinOf Use Arg v v = v~upper If v == "JOIN_ROUND" | v == 1 Then Return "round" If v == "JOIN_BEVEL" | v == 2 Then Return "bevel" Return "miter" ::Routine RuleOf Use Arg v v = v~upper If v == "WIND_EVEN_ODD" | v == 0 Then Return "evenodd" Return "nonzero" ::Routine ArcType Use Arg v v = v~upper If v == "CHORD" | v == 1 Then Return "CHORD" If v == "PIE" | v == 2 Then Return "PIE" Return "OPEN" ::Routine StyleOf Use Arg v Select Case v~upper When "BOLD", 1 Then Return 1 When "ITALIC", 2 Then Return 2 When "BOLDITALIC", 3 Then Return 3 Otherwise Return 0 End /* A colour from three or four intensities: integers (0-255) or, if any */ /* has a dot, fractions (0.0-1.0). */ ::Routine MakeColor Use Arg r, g, b, a v = .Array~of(r, g, b) If a \== "" Then v~append(a) float = 0 Do x Over v If x~pos(".") > 0 Then float = 1 End Do i = 1 To v~items x = Num(v[i]) If float Then x = x * 255 v[i] = Max(0, Min(255, Format(x, , 0))) End c = .Directory~new c~kind = "color" c~hex = "#"v[1]~d2x(2)~lower || v[2]~d2x(2)~lower || v[3]~d2x(2)~lower c~alpha = 1 If v~items == 4 Then c~alpha = Format(v[4] / 255, , 3) Return c ::Routine StopOpacity Use Arg c If c~alpha < 1 Then Return 'stop-opacity="'Fmt(c~alpha)'"' Return "" -- A font: "Name", "Name STYLE size", "Name-STYLE-size" (Font.decode). ::Routine DecodeFont Use Arg spec, size, style spec = spec~strip Loop 2 p = Max(spec~lastPos(" "), spec~lastPos("-")) If p == 0 Then Leave last = spec~substr(p + 1) If DataType(last, "W") Then Do size = last; spec = spec~left(p - 1)~strip End Else If WordPos(last~upper, "PLAIN BOLD ITALIC BOLDITALIC") > 0 Then Do style = StyleOf(last); spec = spec~left(p - 1)~strip End Else Leave End f = .Directory~new Select Case spec~upper When "DIALOG", "SANSSERIF", "SANS-SERIF", "" Then f~family = "sans-serif" When "SERIF" Then f~family = "serif" When "MONOSPACED", "DIALOGINPUT", "MONOSPACE" Then f~family = "monospace" Otherwise f~family = "'"spec"', sans-serif" End f~size = size f~bold = style == 1 | style == 3 f~italic = style == 2 | style == 3 Return f ::Routine XmlEsc Use Arg s Return s~changeStr("&", "&")~changeStr("<", "<")~changeStr(">", ">") -- Matrices: (a b c d e f), x' = a x + c y + e, y' = b x + d y + f. ::Routine Mul Use Arg t, m Return .Array~of(t[1] * m[1] + t[3] * m[2], t[2] * m[1] + t[4] * m[2], - t[1] * m[3] + t[3] * m[4], t[2] * m[3] + t[4] * m[4], - t[1] * m[5] + t[3] * m[6] + t[5], t[2] * m[5] + t[4] * m[6] + t[6]) ::Routine RotM Use Arg deg c = Cos(deg); s = Sin(deg) Return .Array~of(c, s, -s, c, 0, 0) /* transform's six numbers: translateX translateY scaleX scaleY shearX */ /* shearY; a dot keeps that one as it was. */ ::Routine SixToM Use Arg args, from, old m = old~copy map = .Array~of(5, 6, 1, 4, 3, 2) Do i = 0 To 5 v = args[from + i] If v \== ".", DataType(v, "N") Then m[map[i + 1]] = v + 0 End Return m ::Routine TransformAttr Use Arg m If m[1] = 1, m[2] = 0, m[3] = 0, m[4] = 1, m[5] = 0, m[6] = 0 Then Return "" Return ' transform="matrix('Fmt6(m[1]) Fmt6(m[2]) Fmt6(m[3]) Fmt6(m[4]) Fmt(m[5]) Fmt(m[6])')"' ::Routine Fmt6 Use Arg v v = Format(v, , 6, 0) If v~pos(".") > 0 Then v = v~strip("T", "0")~strip("T", ".") If v == "-0" Then v = 0 Return v ::Routine BoxAttrs Use Arg b Return ' x="'Fmt(b[1])'" y="'Fmt(b[2])'" width="'Fmt(b[3])'" height="'Fmt(b[4])'"' ::Routine MaskedGroup Use Arg id, parts s = parts~makeString("L", "") If id == "" | s == "" Then Return s Return ''s'' -- The leaves of an area made only of unions, or .Nil. ::Routine UnionLeaves Use Arg e If e[1] == "leaf" Then Return .Array~of(e) If e[1] \== "add" Then Return .Nil a = UnionLeaves(e[2]); b = UnionLeaves(e[3]) If a == .Nil | b == .Nil Then Return .Nil a~appendAll(b) Return a ::Routine LeafPath Use Arg expr, colour If expr[2]~items == 0 Then Return "" rule = "" If expr[3] \== "nonzero" Then rule = ' fill-rule="'expr[3]'"' Return '' -- Segments: ("M" x y) ("L" x y) ("Q" cx cy x y) ("C" c1x c1y c2x c2y x y) ("Z"). ::Routine PathD Use Arg segs d = "" Do sg Over segs d ||= sg[1] Do i = 2 To sg~items d ||= (i == 2)~?("", " ")Fmt(sg[i]) End End Return d ::Routine CopySegs Use Arg segs out = .Array~new Do sg Over segs out~append(sg~copy) End Return out ::Routine MapSegs Use Arg segs, m out = .Array~new Do sg Over segs t = .Array~of(sg[1]) Do i = 2 To sg~items By 2 x = sg[i]; y = sg[i + 1] t~append(m[1] * x + m[3] * y + m[5]) t~append(m[2] * x + m[4] * y + m[6]) End out~append(t) End Return out -- The box of every point (control points too): x1 y1 x2 y2, or .Nil. ::Routine SegsBox Use Arg segs b = .Nil Do sg Over segs Do i = 2 To sg~items By 2 x = sg[i]; y = sg[i + 1] If b == .Nil Then b = .Array~of(x, y, x, y) Else Do b[1] = Min(b[1], x); b[2] = Min(b[2], y) b[3] = Max(b[3], x); b[4] = Max(b[4], y) End End End Return b ::Routine ExprBox Use Arg expr If expr[1] == "leaf" Then Return SegsBox(expr[2]) a = ExprBox(expr[2]); b = ExprBox(expr[3]) If a == .Nil Then Return b If b == .Nil Then Return a Return .Array~of(Min(a[1], b[1]), Min(a[2], b[2]), Max(a[3], b[3]), Max(a[4], b[4])) ::Routine ExprMap Use Arg expr, m If expr[1] == "leaf" Then Return .Array~of("leaf", MapSegs(expr[2], m), expr[3]) Return .Array~of(expr[1], ExprMap(expr[2], m), ExprMap(expr[3], m)) -- All the outlines of an area's parts, one path (for a clip or an append). ::Routine AreaSegs Use Arg expr If expr[1] == "leaf" Then Return CopySegs(expr[2]) out = AreaSegs(expr[2]) out~appendAll(AreaSegs(expr[3])) Return out ::Routine RectSegs Use Arg x, y, w, h Return .Array~of(.Array~of("M", x, y), .Array~of("L", x + w, y), .Array~of("L", x + w, y + h), - .Array~of("L", x, y + h), .Array~of("Z")) ::Routine EllipseSegs Use Arg x, y, w, h segs = ArcSegs(x + w / 2, y + h / 2, w / 2, h / 2, 0, 360) segs[1][1] = "M" segs~append(.Array~of("Z")) Return segs ::Routine RoundRectSegs Use Arg x, y, w, h, aw, ah rx = Max(0, Min(aw / 2, w / 2)); ry = Max(0, Min(ah / 2, h / 2)) If rx = 0 | ry = 0 Then Return RectSegs(x, y, w, h) segs = .Array~of(.Array~of("M", x + rx, y), .Array~of("L", x + w - rx, y)) segs~appendAll(Rest(ArcSegs(x + w - rx, y + ry, rx, ry, 90, -90))) segs~append(.Array~of("L", x + w, y + h - ry)) segs~appendAll(Rest(ArcSegs(x + w - rx, y + h - ry, rx, ry, 0, -90))) segs~append(.Array~of("L", x + rx, y + h)) segs~appendAll(Rest(ArcSegs(x + rx, y + h - ry, rx, ry, 270, -90))) segs~append(.Array~of("L", x, y + ry)) segs~appendAll(Rest(ArcSegs(x + rx, y + ry, rx, ry, 180, -90))) segs~append(.Array~of("Z")) Return segs ::Routine Rest Use Arg a Return a~section(2) /* An arc of the ellipse in the box x y w h (Arc2D, drawArc, fillArc): */ /* angles in degrees, 0 at three o'clock, counterclockwise on the screen. */ ::Routine ArcShapeSegs Use Arg x, y, w, h, start, extent, type cx = x + w / 2; cy = y + h / 2 segs = ArcSegs(cx, cy, w / 2, h / 2, start, extent) If type == "PIE" Then Do segs[1][1] = "L" segs~insert(.Array~of("M", cx, cy), .Nil) segs~append(.Array~of("Z")) End Else Do segs[1][1] = "M" If type == "CHORD" Then segs~append(.Array~of("Z")) End Return segs /* The arc as cubics, a quarter turn at most each: the first item is its */ /* start ("P" x y), for the caller to make a move or a line. */ ::Routine ArcSegs Use Arg cx, cy, rx, ry, start, extent If extent > 360 Then extent = 360 If extent < -360 Then extent = -360 n = Max(1, Trunc((Abs(extent) + 89.999) / 90)) step = extent / n pt = .Array~of("P", cx + rx * Cos(start), cy - ry * Sin(start)) segs = .Array~of(pt) Do i = 0 To n - 1 t0 = start + i * step; t1 = t0 + step k = 4 / 3 * Tan(step / 4) x0 = cx + rx * Cos(t0); y0 = cy - ry * Sin(t0) x3 = cx + rx * Cos(t1); y3 = cy - ry * Sin(t1) -- the derivative, per radian: (-rx sin t, -ry cos t) c1x = x0 + k * (-rx * Sin(t0)); c1y = y0 + k * (-ry * Cos(t0)) c2x = x3 - k * (-rx * Sin(t1)); c2y = y3 - k * (-ry * Cos(t1)) segs~append(.Array~of("C", c1x, c1y, c2x, c2y, x3, y3)) End Return segs ::Routine PolySegs Use Arg xs, ys, n, closed n = Min(n, xs~items, ys~items) If n < 1 Then Return .Nil segs = .Array~of(.Array~of("M", xs[1], ys[1])) Do i = 2 To n segs~append(.Array~of("L", xs[i], ys[i])) End If closed Then segs~append(.Array~of("Z")) Return segs ::Routine Sin Use Arg deg Return RxCalcSin(deg, 16, "D") ::Routine Cos Use Arg deg Return RxCalcCos(deg, 16, "D") ::Routine Tan Use Arg deg Return RxCalcTan(deg, 16, "D") /* The colours JDOR knows by name (javafx.scene.paint.Color, the W3C's). The */ /* constants of java.awt.Color go after them in JavaDrawingHandler.java, so */ /* where both have a name, java.awt.Color's wins: GREEN is 0 255 0, not the */ /* W3C's 0 128 0; ORANGE and PINK differ too. DARK_GRAY and LIGHT_GRAY are */ /* only java.awt.Color's. */ ::Routine NamedColor Use Arg name name = name~upper If name == "DARK_GRAY" Then Return "#404040" If name == "LIGHT_GRAY" Then Return "#c0c0c0" If name == "GREEN" Then Return "#00ff00" If name == "ORANGE" Then Return "#ffc800" If name == "PINK" Then Return "#ffafaf" If name == "TRANSPARENT" Then Return "#000000" Do pair Over .Resources~colours Parse Var pair n hex If n~upper == name Then Return hex End Return "" ::Resource colours AliceBlue #f0f8ff AntiqueWhite #faebd7 Aqua #00ffff Aquamarine #7fffd4 Azure #f0ffff Beige #f5f5dc Bisque #ffe4c4 Black #000000 BlanchedAlmond #ffebcd Blue #0000ff BlueViolet #8a2be2 Brown #a52a2a BurlyWood #deb887 CadetBlue #5f9ea0 Chartreuse #7fff00 Chocolate #d2691e Coral #ff7f50 CornflowerBlue #6495ed Cornsilk #fff8dc Crimson #dc143c Cyan #00ffff DarkBlue #00008b DarkCyan #008b8b DarkGoldenRod #b8860b DarkGray #a9a9a9 DarkGrey #a9a9a9 DarkGreen #006400 DarkKhaki #bdb76b DarkMagenta #8b008b DarkOliveGreen #556b2f DarkOrange #ff8c00 DarkOrchid #9932cc DarkRed #8b0000 DarkSalmon #e9967a DarkSeaGreen #8fbc8f DarkSlateBlue #483d8b DarkSlateGray #2f4f4f DarkSlateGrey #2f4f4f DarkTurquoise #00ced1 DarkViolet #9400d3 DeepPink #ff1493 DeepSkyBlue #00bfff DimGray #696969 DimGrey #696969 DodgerBlue #1e90ff FireBrick #b22222 FloralWhite #fffaf0 ForestGreen #228b22 Fuchsia #ff00ff Gainsboro #dcdcdc GhostWhite #f8f8ff Gold #ffd700 GoldenRod #daa520 Gray #808080 Grey #808080 Green #008000 GreenYellow #adff2f HoneyDew #f0fff0 HotPink #ff69b4 IndianRed #cd5c5c Indigo #4b0082 Ivory #fffff0 Khaki #f0e68c Lavender #e6e6fa LavenderBlush #fff0f5 LawnGreen #7cfc00 LemonChiffon #fffacd LightBlue #add8e6 LightCoral #f08080 LightCyan #e0ffff LightGoldenRodYellow #fafad2 LightGray #d3d3d3 LightGrey #d3d3d3 LightGreen #90ee90 LightPink #ffb6c1 LightSalmon #ffa07a LightSeaGreen #20b2aa LightSkyBlue #87cefa LightSlateGray #778899 LightSlateGrey #778899 LightSteelBlue #b0c4de LightYellow #ffffe0 Lime #00ff00 LimeGreen #32cd32 Linen #faf0e6 Magenta #ff00ff Maroon #800000 MediumAquaMarine #66cdaa MediumBlue #0000cd MediumOrchid #ba55d3 MediumPurple #9370db MediumSeaGreen #3cb371 MediumSlateBlue #7b68ee MediumSpringGreen #00fa9a MediumTurquoise #48d1cc MediumVioletRed #c71585 MidnightBlue #191970 MintCream #f5fffa MistyRose #ffe4e1 Moccasin #ffe4b5 NavajoWhite #ffdead Navy #000080 OldLace #fdf5e6 Olive #808000 OliveDrab #6b8e23 Orange #ffa500 OrangeRed #ff4500 Orchid #da70d6 PaleGoldenRod #eee8aa PaleGreen #98fb98 PaleTurquoise #afeeee PaleVioletRed #db7093 PapayaWhip #ffefd5 PeachPuff #ffdab9 Peru #cd853f Pink #ffc0cb Plum #dda0dd PowderBlue #b0e0e6 Purple #800080 RebeccaPurple #663399 Red #ff0000 RosyBrown #bc8f8f RoyalBlue #4169e1 SaddleBrown #8b4513 Salmon #fa8072 SandyBrown #f4a460 SeaGreen #2e8b57 SeaShell #fff5ee Sienna #a0522d Silver #c0c0c0 SkyBlue #87ceeb SlateBlue #6a5acd SlateGray #708090 SlateGrey #708090 Snow #fffafa SpringGreen #00ff7f SteelBlue #4682b4 Tan #d2b48c Teal #008080 Thistle #d8bfd8 Tomato #ff6347 Turquoise #40e0d0 Violet #ee82ee Wheat #f5deb3 White #ffffff WhiteSmoke #f5f5f5 Yellow #ffff00 YellowGreen #9acd32 ::END ::Routine RxCalcSin External "LIBRARY rxmath RxCalcSin" ::Routine RxCalcCos External "LIBRARY rxmath RxCalcCos" ::Routine RxCalcTan External "LIBRARY rxmath RxCalcTan"