-
Hi @pgundlach Can't understand how to pass a color through a variable to a metapost object: Let's say:
<DefineColor name="npgray" model="cmyk" c="0" m="0" y="0" k="53"/>
<DefineColor name="darknpgray" model="cmyk" c="0" m="0" y="0" k="21"/>
<DefineColor name="yellow" model="cmyk" c="0" m="10" y="100" k="0"/>
<DefineGraphic name="roundedcorners">
save corner; corner := 10;
filldraw (0, box.height - corner ){down} .. {down}(0,corner) ..
(corner,0) -- (box.width - corner,0) .. {up}(box.width, corner) --
(box.width, box.height - corner) .. {left}(box.width - corner, box.height) --
(corner,box.height){left} .. cycle
withcolor colors.accent; <<< accent is what I need to change
</DefineGraphic>
<section secname="01" accent="yellow" >
<item 1 />
<item 2 />
<item 3/>
</section> You say:
What do you mean with the beginning of the graphics? I am defining these elements on top before the page layouts, should I move the graphics just before the page layout after have recorded ? <!-- OPEN SECTION -->
<Record element="section">
<SetVariable variable="secname" select="@secname"/>
<SetVariable variable="sectiontitleimage" select="img/@file"/>
<!-- ACCENT COLOR -->
<SetVariable variable="accent" select="@accent" />
<PlaceObject allocate="yes" column="4cm" row="10cm" halign="right" frame="solid">
<Textblock width="15cm" fontfamily="opensecname">
<Value select="$secname"/>
</Textblock>
</PlaceObject>
<ProcessNode select="subsection"/>
</Record>
<DefineGraphic name="accent-roundedcorners">
save corner; corner := 10;
filldraw (0, box.height - corner ){down} .. {down}(0,corner) ..
(corner,0) -- (box.width - corner,0) .. {up}(box.width, corner) --
(box.width, box.height - corner) .. {left}(box.width - corner, box.height) --
(corner,box.height){left} .. cycle
withcolor colors.accent;
</DefineGraphic> Useless to say it doesn't compile... 🤔 Thanks! 🙏 |
Beta Was this translation helpful? Give feedback.
Replies: 9 comments 15 replies
-
You can use the metapost macro <Layout xmlns="urn:speedata.de:2009/publisher/en"
xmlns:sd="urn:speedata:2009/publisher/functions/en">
<Pageformat height="8cm" width="10cm" />
<DefineColor name="mygray" model="gray" g="80"/>
<DefineColor name="transparentorange" model="cmyk" c="0" m="45" y="87" k="0" alpha="0.4"/>
<DefineGraphic name="box">
fill box withcolor spcolor("mygray");
</DefineGraphic>
<DefineGraphic name="alphabox">
fill box withcolor spcolor("transparentorange");
</DefineGraphic>
<Record element="data">
<PlaceObject>
<Box height="4" width="4" graphic="box"/>
</PlaceObject>
<PlaceObject>
<Box height="4" width="4" backgroundcolor="blue"/>
</PlaceObject>
<PlaceObject row="3" column="3" allocate="no">
<Box height="4" width="4" graphic="alphabox"/>
</PlaceObject>
</Record>
</Layout> See https://github.com/speedata/publisher/tree/develop/qa/metapost/spcolor and https://doc.speedata.de/publisher/en/advancedtopics/advancedtopics-metapostgraphics/#_metapost_macros Does this help? |
Beta Was this translation helpful? Give feedback.
-
I believe is the latest:
🤔 |
Beta Was this translation helpful? Give feedback.
-
I recompiled it:
Your layout worked out. sp --layout=spcolor.xml --dummy --jobname=spcolor
Run speedata publisher 4.15.14 (Pro)
Loading file sdini.lua ... done
Load file: "publisher.lua" ...
Load file: "commands.lua" ...
Load file: "fonts.lua" ...
Load file: "fontloader.lua" ...
Load file: "fontloader.lua" ... done
Load file: "fonts.lua" ... done
Load file: "tabular.lua" ...
Load file: "tabular.lua" ... done
Load file: "par.lua" ...
Load file: "par.lua" ... done
Load file: "commands.lua" ... done
Load file: "grid.lua" ...
Load file: "grid.lua" ... done
Load file: "box.lua" ...
Load file: "box.lua" ... done
Load file: "layout_functions.lua" ...
Load file: "layout_functions.lua" ... done
Load file: "publisher.lua" ... done
Start processing
Running LuaTeX version 1.16.0 on freebsd
Loading hyphenation patterns "hyph-en-gb.pat.txt".
Language id: 0
Preload font "texgyreheros-regular.otf" at 10pt (id: 1)
Preload font "texgyreheros-regular.otf" at 8pt (id: 2)
Preload font "texgyreheros-bold.otf" at 10pt (id: 3)
Preload font "texgyreheros-bold.otf" at 8pt (id: 4)
Preload font "texgyreheros-italic.otf" at 10pt (id: 5)
Preload font "texgyreheros-italic.otf" at 8pt (id: 6)
Preload font "texgyreheros-bolditalic.otf" at 10pt (id: 7)
Preload font "texgyreheros-bolditalic.otf" at 8pt (id: 8)
DefineFontfamily "text" size 10pt/12pt id: 1
Loading layout instructions "NAG/spcolor.xml"
Defining color "@accent" (147)
Page of type "Default Page" created (1)
Number of rows: 28, number of columns = 19
PlaceObject: Box at (1,1) wd/ht: 4/4 in "_page" (p. 1)
Loading colorprofile ISOcoated_v2_eci.icc
colorprofile found: Git/publisher/src/colorprofiles/ISOcoated_v2_eci.icc
> Shipout page 1
Stop processing data
0 errors occurred
Duration: 0.209358 seconds
Output written on spcolor.pdf (1 page, 1366658 bytes).
Transcript written on spcolor.log.
Total run time: 832.878539ms |
Beta Was this translation helpful? Give feedback.
-
It worked even on my layout! 🎇 🎇 🎇 Besides the spot color, was the issues caused by the standard version? |
Beta Was this translation helpful? Give feedback.
-
Hi Patrick, I was able to pass the variable from I was able to get the color by using two variables: <Layout xmlns="urn:speedata.de:2009/publisher/en"
xmlns:sd="urn:speedata:2009/publisher/functions/en">
<DefineColor name="npyellow" model="RGB" r="255" g="178" b="25" alpha="100"/>
<DefineColor name="npgreen" model="RGB" r="0" g="200" b="25" alpha="100"/>
<DefineGraphic name="r"> fill box withcolor spcolor(accent); </DefineGraphic>
<Record element="data">
<ProcessNode select="*"/>
</Record>
<Record element="box">
<SetVariable variable="color" select="@accent" />
<SetVariable variable="accent" select="$color" type="mp:string" />
<PlaceObject>
<Box height="15" width="15" graphic="r" />
</PlaceObject>
<Message select="$color" />
<PlaceObject>
<Textblock>
<Paragraph color="{$color}">
<Value select="@accent" />
</Paragraph>
</Textblock>
</PlaceObject>
</Record>
</Layout>
<data>
<box accent="npgreen" />
</data> Thanks! 🙏 |
Beta Was this translation helpful? Give feedback.
-
I am stil confused what is working and what is broken. Could you open a new issue for each problem? |
Beta Was this translation helpful? Give feedback.
-
Hi @pgundlach I tried to replicate the issue, and it wasn't working till I copied and pasted one to one each variables.
<data>
<Parent title="SP Color Test" accent="spyellow">
<Child>
<Nephew>
<Baby>This is box: </Baby>
<Baby>1</Baby>
</Nephew>
</Child>
<Child>
<Nephew>
<Baby>This is box: </Baby>
<Baby>2</Baby>
</Nephew>
</Child>
<Child>
<Nephew>
<Baby>This is box: </Baby>
<Baby>3</Baby>
</Nephew>
</Child>
<Child>
<Nephew>
<Baby>This is box: </Baby>
<Baby>4</Baby>
</Nephew>
</Child>
</Parent>
</data>
<Layout xmlns="urn:speedata.de:2009/publisher/en"
xmlns:sd="urn:speedata:2009/publisher/functions/en">
<!-- Basic -->
<Trace grid="yes"/>
<Pageformat width="10cm" height="12cm"/>
<!-- Colors -->
<DefineColor name="spyellow" model="RGB" r="255" g="178" b="25" alpha="70"/>
<DefineColor name="spred" model="RGB" r="250" g="25" b="25" alpha="80"/>
<!-- Metapost -->
<DefineGraphic name="spbox"> fill box withcolor spcolor(accent); </DefineGraphic>
<DefineGraphic name="redbox"> fill box withcolor colors.spred; </DefineGraphic>
<!-- Basic Master -->
<Pagetype name="test" test="true()">
<Margin left="1cm" right="1cm" top="2cm" bottom="1cm" />
<AtPageCreation>
<PlaceObject row="10mm" column="0mm">
<Textblock width="10cm">
<Paragraph textformat="centered">
<Value>Header's name: </Value>
<Color name="{$colortitle}">
<Value select="$title" />
</Color>
</Paragraph>
</Textblock>
</PlaceObject>
<Message select="concat('Header: ',$colortitle)" />
</AtPageCreation>
</Pagetype>
<!-- General Record -->
<Record element="data">
<ProcessNode select="*"/>
</Record>
<!-- Record Parent -->
<Record element="Parent">
<SetVariable variable="title" select="@title" />
<SetVariable variable="colortitle" select="@accent" />
<SetVariable variable="color" select="@accent" />
<SetVariable variable="accent" select="$color" type="mp:string" />
<ProcessNode select="Child" />
<Message select="concat('Process Node Parent:',@accent)" />
</Record>
<!-- Record Child -->
<Record element="Child">
<SetGrid nx="2" ny="2" />
<ForAll select="Nephew">
<Group name="box">
<Grid width="1cm" height="1cm" />
<Contents>
<!-- Box -->
<PlaceObject row="1" column="1.5" >
<Box height="10mm" width="30mm" graphic="spbox" />
</PlaceObject>
<!-- Text -->
<PlaceObject row="1.3" column="1.5">
<Textblock width="3">
<Paragraph textformat="centered">
<ForAll select="Baby">
<Value select="." />
</ForAll>
</Paragraph>
</Textblock>
</PlaceObject>
</Contents>
</Group>
<PlaceObject groupname="box" />
</ForAll>
</Record>
</Layout> Perhaps my issue is likely the same, a typo in some variables... 🤔 |
Beta Was this translation helpful? Give feedback.
-
BTW: when you use something like |
Beta Was this translation helpful? Give feedback.
-
Ok, this has been solved, there was a GIANT PEBCAK and I was trying to recycle the same "metapost" variable for an element that wasn't a metapost graphic. The funky part is that solving this issue revealed another one that I was thinking it was already solved... 🤦 But this is another discussion... |
Beta Was this translation helpful? Give feedback.
Hi @pgundlach
I tried to replicate the issue, and it wasn't working till I copied and pasted one to one each variables.
Now the code, that I suppose replicates my structures, is working:
data.xml