summaryrefslogtreecommitdiff
path: root/graphics/circuit_macros/svg.m4
diff options
context:
space:
mode:
Diffstat (limited to 'graphics/circuit_macros/svg.m4')
-rw-r--r--graphics/circuit_macros/svg.m497
1 files changed, 73 insertions, 24 deletions
diff --git a/graphics/circuit_macros/svg.m4 b/graphics/circuit_macros/svg.m4
index e270060393..84f7e21e06 100644
--- a/graphics/circuit_macros/svg.m4
+++ b/graphics/circuit_macros/svg.m4
@@ -1,7 +1,7 @@
divert(-1)
svg.m4 Initialization for SVG output.
-* Circuit_macros Version 9.2, copyright (c) 2020 J. D. Aplevich under *
+* Circuit_macros Version 9.3, copyright (c) 2020 J. D. Aplevich under *
* the LaTeX Project Public Licence in file Licence.txt. The files of *
* this distribution may be redistributed or modified provided that this *
* copyright notice is included and provided that modifications are clearly *
@@ -41,24 +41,58 @@ define(`svg_gt',`$1')
',
`define(`svg_tspan',`patsubst(<tspan `$1'
>`$2'</tspan>,",\\")')
-define(`svg_font',`
+divert(-1)
+ `svg_font(fontname,nominal ht:dptextratio,textoffset)
+ or svg_font(fontname,nominal ht:dptextratio,textoffset,
+ text)
+ Note: nominal ht = text height in drawing units,
+ e.g. 12bp__ for 12pt text
+   actual height = nominal ht * dptextratio '
+define(`svg_font',`ifinstr(`$2',:,
+ `stacksplit_(`m4svgf',`$2',:)
+ ifelse(m4svgf,,,dptextratio = m4svgf; )popdef(`m4svgf')dnl
+ ifelse(m4svgf,,,`textht=(m4svgf)*dptextratio; ')undefine(`m4svgf')',
+ `dptextratio=svgfontratio(`$1'); dnl
+ ifelse(`$2',,,textht=(`$2')*dptextratio; )')dnl
+ ifelse(`$3',,,`textoffset=`$3'; ')
command "<g patsubst(ifelse(`$1',,,
index(`$1',font),0,`$1',
index(`$1',style),0,`$1',
style="font-family:`$1'")
,",\\")>"
- ifelse(`$2',,,`textht=(`$2')*dptextratio; ')dnl
- ifelse(`$3',,,`textoffset=`$3'; ')dnl
`$4'
ifelse(`$4',,,`command "</g>"')')
+
`e.g. svg_font(Times)
+ svg_font(Times,12bp__:0.66)
svg_font(Times,11bp__,1bp__,"text" at A)
svg_font(font-family="Times")
svg_font(font-family="Times" font-style="italic")
svg_font(style="font-family:Times; font-style:italic")
+
Some fairly safe choices: Arial, Helvetica, Times, Courier, Verdana, Georgia,
Palatino, Garamond, Bookman, Cursive, Trebuchet MS, Arial Black, Impact.
'
+ `svgfontratio(fontname)
+ reasonable dptextratio values for common fonts'
+define(`svgfontratio',`ifinstr(
+`$1',Times,0.66,
+`$1',sans-serif,0.71,
+`$1',Arial,0.71,
+`$1',Helvetica,0.71,
+`$1',Courier,0.57,
+`$1',Cursive,0.7,
+`$1',Verdana,0.72,
+`$1',Georgia,0.70,
+`$1',Palatino,0.66,
+`$1',Garamond,0.62,
+`$1',Bookman,0.66,
+`$1',Comic Sans MS,0.75,
+`$1',Trebuchet MS,0.71,
+`$1',Arial Black,0.71,
+`$1',Impact,0.79,
+dptextratio)')
+
`see http://www.ascii.cl/htmlcodes.htm
and http://webdesign.about.com/od/localization/l/blhtmlcodes-gr.htm'
define(`svg_symbol',`changecom(,)`$1'changecom(`#',)')
@@ -136,6 +170,7 @@ define(`svg_ensp',`svg_symbol(&`#'8194;)')
define(`svg_emsp',`svg_symbol(&`#'8195;)')
define(`svg_thinsp',`svg_symbol(&`#'8201;)')
define(`svg_backsl',`svg_symbol(&`#'92;)')
+define(`svg_pound',`svg_symbol(&`#'35;)')
')
define(`svgcolor',`sprintf("rgb(%g,%g,%g)",\
@@ -156,35 +191,49 @@ define(`svgLinkString',`"<a xlink:href=\"`$1'\"dnl
`$2' dnl
</a>"')
-# svgrot_init(filename)
+# svg_rot_init(filename)
# filename is the basename of the output
# produced by dpic -v filename.pic > filename.svg
-define(`svgrot_init',`NeedDpicTools
+define(`svg_rot_init',`
+`# svg_rot'_init begin
+ NeedDpicTools
define(`_file_',ifelse(`$1',,patsubst(__file__,.m4),`$1'))
syscmd(touch _file_.svg _file_.cor; cp _file_.svg _file_.tmp)
- sh "grep \"^ x=.*\/text>\" _file_.tmp | sed -e dnl
- \"s/x=\\"\([0-9.]*\)\\" y=\\"\([0-9.]*\)\\".*/\1 \2/\" > _file_.cor"
- svgrot_k = 0; svg_rotz = 0
- define svg_rotcoords { svgrot_k += 1
- if "$`'1" != "" then { x[svgrot_k] = $`'1; y[svgrot_k] = $`'2; svg_rotz = 1 }
- }
+# Extract from the .svg file the x= y= coordinates
+# that appear after each transform="rotate(.." line
+ retcode = ( sh "awk -e \"/transform=\\"rotate/ { r=1 }; dnl
+ /x=\\".*y=\\"/ { if(r==1){ print; r=0 } }\" _file_.tmp dnl
+ | sed -e \"s/x=\\"\([0-9.]*\)\\" y=\\"\([0-9.]*\)\\".*/\1 \2/\" dnl
+ > _file_.cor" )
+ if retcode != 0 then { print "
+ Awk failure
+ Awk and sed are required by svg_rot to rotate svg text.
+ " }
+ svgrot_k = 0
+ define svg_rotcoords { if "$`'1" != "" then { svgrot_k += 1
+ svg_rx[svgrot_k] = $`'1; svg_ry[svgrot_k] = $`'2 }
+ }
copythru(svg_rotcoords, _file_.cor)
sh "rm -f _file_.tmp _file_.cor"
- svg_rotk = 0
+ svgrot_i = 0
ifdef(`svg_rot_',,`
-# `svg_rot(deg clockwise rotation,text or object)
-# Requires svgrot_init(filename)
-# Rotation of svg text is a can of worms because
-# the final coordinates of the text are required;
-# this forward reference has to be extracted from
-# the output file and the source processed twice.'
- define svg_rot { if svg_rotz then { svg_rotk += 1; command \
- sprintf("<g transform=\"rotate(%g %g %g)\">",$`'1,x[svg_rotk],y[svg_rotk]) }\
- else { command sprintf("<g transform=\"rotate(%g)\">",$`'1) }
+# `svg_rot(degrees,"text" [at position])
+# Rotate text degrees ccw
+# Requires svg_rot_init(filename)
+# which uses both awk and sed.
+# The source must be processed twice by m4 and dpic.'
+ define svg_rot { if retcode != 0 then {$`'2} else {
+ if "$`'1" != "" then { svg_rang = -($`'1) } else { svg_rang = -90 }
+ if svgrot_k != 0 then { svgrot_i +=1
+ command sprintf("<g transform=\"rotate(%g %g %g)\">",svg_rang,\
+ svg_rx[svgrot_i],svg_ry[svgrot_i]) }\
+ else { command sprintf("<g transform=\"rotate(%g)\">",svg_rang) }
$`'2
- command "</g>" }
- define(`svg_rot_') ')
+ command "</g>" } }
+ define(`svg_rot_')
+ ')
+`# svg_rot'_init end
')
# ---------------------------------------------------------------------------#