/******************************************************************************/ /* */ /* jdor2svg.rex - A JDOR macro 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 An SVG for every saveImage (Rony, 13/10) */ /* */ /******************************************************************************/ /* */ /* [rexx] jdor2svg [options] macro.jdor [drawing.svg] */ /* */ /* A JDOR macro is what a program that draws with JDOR (BSF4ooRexx850) */ /* leaves when its output is redirected: the commands it ran, one per line: */ /* */ /* address JDOR with output using (.output) -- or rexx prog.rxj ? > x.jdor */ /* */ /* jdor2svg writes the drawing as SVG (by default beside the macro, with the */ /* extension .svg; "-" writes it to the standard output), and says what it */ /* left out: bitmaps, the XOR mode, composites other than SRC_OVER. See */ /* jdor2svg.cls. */ /* */ /* Every "saveImage F" of the macro, where the program wrote a picture, also */ /* gives an SVG of that picture: F.svg (saveImage pic_2.gif gives */ /* pic_2.gif.svg), in the folder of the main SVG (of the macro, with "-"). */ /* Only the name of F is taken, not its folder: the program wrote it on its */ /* own machine. */ /* */ /* Options: */ /* */ /* -h, --help this help */ /* -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) */ /* */ /******************************************************************************/ CLIhelper = InitCLI() myName = CLIhelper~name myHelp = CLIhelper~help args = CLIhelper~args quiet = 0 saves = 1 prefix = "jdor" files = .Array~new Loop i = 1 To args~items a = args[i] Select Case Lower(a) When "-h", "--help", "-?" Then Signal Help When "-q", "--quiet" Then quiet = 1 When "--no-saves" Then saves = 0 When "--id-prefix" Then Do i += 1 If i > args~items Then Call Fail "--id-prefix needs a value" prefix = args[i] End Otherwise Do If a~left(1) == "-", a \== "-" Then Call Fail "unknown option '"a"'" files~append(a) End End End If files~items == 0 | files~items > 2 Then Signal Help in = files[1] If \SysFileExists(in) Then Call Fail "'"in"' does not exist" s = .Stream~new(in) lines = s~arrayIn s~close If files~items == 2 Then out = files[2] Else Do out = in dot = out~lastPos(".") If dot > out~lastPos("/"), dot > out~lastPos("\") Then out = out~left(dot - 1) out ||= ".svg" End conv = .JDOR.SVG~new(prefix) svg = conv~convert(lines) If out == "-" Then Do line Over svg; Say line; End Else Do Call SysFileDelete out o = .Stream~new(out) o~open("Write Replace") o~arrayOut(svg) o~close If \quiet Then Say myName": wrote" out End -- An SVG for every saveImage, beside the main one If saves Then Do dir = (out == "-")~?(in, out) dir = dir~left(Max(dir~lastPos("/"), dir~lastPos("\"))) Do snap Over conv~saved name = snap~name name = name~substr(Max(name~lastPos("/"), name~lastPos("\")) + 1) file = dir || name".svg" Call SysFileDelete file o = .Stream~new(file) o~open("Write Replace") o~arrayOut(snap~svg) o~close msg = myName": wrote" file "(saveImage" snap~name")" If quiet Then Nop Else If out == "-" Then .Error~lineOut(msg) -- the standard output is the SVG Else Say msg End End If \quiet Then Do note Over conv~notes .Error~lineOut(myName": left out:" note) End Exit 0 Help: Say myName "[-q] [--no-saves] [--id-prefix ID] macro.jdor [drawing.svg | -]" Say "Writes the drawing of a JDOR macro as SVG, and one more for every" Say "saveImage. Documentation:" myHelp Exit 1 Fail: .Error~lineOut(myName":" Arg(1)) Exit 1 ::Requires "parser/CLISupport.cls" ::Requires "jdor2svg.cls"