| 1 |
.PS |
| 2 |
# InclepsDPV.m4 : Illustrating one way to import and overwrite jpg in svg |
| 3 |
# A bit messy, but it works. This file has to be processed |
| 4 |
# by m4 in the usual way and then twice by dpic, eg |
| 5 |
# m4 svg.m4 DPVconfig.m4 InclepsDPV.m4 > InclepsDPV.pic |
| 6 |
# dpic -v InclepsDPV.pic > InclepsDPV.svg |
| 7 |
# dpic -v InclepsDPV.pic > InclepsDPV.svg |
| 8 |
# The second requirement is that the result has to be inserted |
| 9 |
# into the html document using the object class, e.g., |
| 10 |
# <object data="file.svg" type="image/svg+xml" class="img"> </object> |
| 11 |
# This is handled by the cfig macro in examples.htmx |
| 12 |
|
| 13 |
# The double processing is needed because svg coordinates are to the right |
| 14 |
# and down. We have to store the coordinates of the nw corner and use them |
| 15 |
# on the second pass. |
| 16 |
|
| 17 |
divert(-1) |
| 18 |
###################################################################### |
| 19 |
# Macros to simplify inclusion and positioning of raster image files such |
| 20 |
# as png or jpg or files with mime type of "image/svg+xml" |
| 21 |
|
| 22 |
`svg_init_include([Unique_name]) |
| 23 |
Put this (once) before all drawing commands |
| 24 |
in the diagram. It opens a [] block for the |
| 25 |
total diagram and creates the file |
| 26 |
Unique_name.dim (default DPVinsertTemp.dim).' |
| 27 |
define(`svg_init_include', |
| 28 |
`define(`M4IP_uniq',`ifelse(`$1',,DPVinsertTemp,`$1')')dnl |
| 29 |
M4IP_NW: (0,0); m4IP_nw = 0; m4IP_lth = lthick |
| 30 |
sh "touch M4IP_uniq.dim" |
| 31 |
copy "M4IP_uniq.dim" |
| 32 |
[ M4IP_NW: M4IP_NW; { move to M4IP_NW } ') |
| 33 |
|
| 34 |
`svg_include(filename, wid, ht, [position],[attrib]) |
| 35 |
Insert bitmap at specified position; also create |
| 36 |
an invis box of the same size and location. |
| 37 |
arg1= path to image file |
| 38 |
arg2= picture width in drawing units |
| 39 |
arg3= picture height in drawing units |
| 40 |
arg4= position attribute e.g. |
| 41 |
Pic: svg_include(Incl.jpg,2,3, with .sw at (1,4)) |
| 42 |
arg5= additional svg image attributes in the sprintf |
| 43 |
string, e.g. |
| 44 |
clip-path=\"polygon(5%% 0%%, 100%% 0%%, 100%% 100%%, 5%% 100%%)\" (distances |
| 45 |
in percent to top-left, top-right, bottom-right, bottom-left clip corners, |
| 46 |
or in pixels) ' |
| 47 |
define(`svg_include',`box invis wid `$2' ht `$3' `$4' |
| 48 |
define(`m4xpx',`(last box.w.x-M4IP_NW.x+m4IP_lth/2)/(1px__)')dnl |
| 49 |
define(`m4ypx',`(M4IP_NW.y-last box.n.y+m4IP_lth/2)/(1px__)')dnl |
| 50 |
define(`m4wdpx',`(`$2')/(1px__)')dnl |
| 51 |
define(`m4htpx',`(`$3')/(1px__)')dnl |
| 52 |
if m4IP_nw then { command sprintf(\ |
| 53 |
"<image x=\"%g\" y=\"%g\" width=\"%g\" height=\"%g\"dnl |
| 54 |
xlink:href=\"`$1'\" `$5' />", m4xpx,m4ypx,m4wdpx,m4htpx) } ') |
| 55 |
|
| 56 |
`svg_end_include |
| 57 |
Put this before .PE after all drawing commands. |
| 58 |
It closes the [] block and writes to Unique_name.dim' |
| 59 |
define(`svg_end_include',`] with .M4IP_NW at M4IP_NW |
| 60 |
print sprintf("m4IP_nw=1; m4IP_lth=%g; M4IP_NW:(%g,%g)",lthick,\ |
| 61 |
last [].w.x+3*m4IP_lth/2, last [].n.y+3*m4IP_lth/2) > "M4IP_uniq.dim" |
| 62 |
undefine(`M4IP_uniq') ') |
| 63 |
|
| 64 |
###################################################################### |
| 65 |
divert(0)dnl |
| 66 |
|
| 67 |
darrow_init |
| 68 |
svg_init_include |
| 69 |
|
| 70 |
|
| 71 |
# This jpg is 242 px x 321 px |
| 72 |
Picture: svg_include(Incl.jpg, 242px__, 321px__, with .w at (1,0)) |
| 73 |
|
| 74 |
define(`backarrow',`darrow(`$1',,,2pt__,6pt__,6pt__,<-|)') |
| 75 |
thinlines_ |
| 76 |
backarrow( from boxcoord(Picture,0.4,0.95) up 0.4 right 0.7 ) |
| 77 |
"Basket" wid 0.45 with .w at Here+(2bp__,0) |
| 78 |
backarrow( from boxcoord(Picture,0.9,0.41) up 0.2 right 0.5 ) |
| 79 |
"Ball" wid 0.3 with .w at Here+(2bp__,0) |
| 80 |
backarrow( from boxcoord(Picture,0.85,0.32) up 0.2 right 0.5 ) |
| 81 |
"Star" wid 0.3 with .w at Here+(2bp__,0) |
| 82 |
"Player" wid 0.43 with .w at last "".w+(0,-0.15) |
| 83 |
|
| 84 |
#for i=3 to 1 by -1 do { |
| 85 |
# Picture: svg_include(Incl.jpg, i/4*242px__, i/4*321px__, |
| 86 |
# with .nw at last box.nw+(0.125,-0.25)) } |
| 87 |
|
| 88 |
# P2: svg_include(Incl.jpg, 242px__, 321px__, |
| 89 |
# with .w at Picture.e+(1.25,0), |
| 90 |
# clip-path=\"polygon(30 0, 100%% 0%%, 100%% 100%%, 30 321)\" ) |
| 91 |
|
| 92 |
svg_end_include |
| 93 |
|
| 94 |
.PE |