speedata / publisher

speedata Publisher - a professional database Publishing system
https://www.speedata.de/
GNU Affero General Public License v3.0
296 stars 36 forks source link

Something wrong with "mm" unit size #606

Closed Cicorione closed 3 weeks ago

Cicorione commented 3 weeks ago

Hi @pgundlach,

I am experience weird behaviors with millimeters (mm) as unit size, when you pass the value as variable. In my current code simply mm aren't displayed, thus I decided to make a test and it looks like the conversion is totally wrong!

Check this out:

<?xml version="1.0" encoding="UTF-8"?>
<?xml-model href="/usr/share/speedata-publisher/schema/layoutschema-en.rng" type="application/xml" schematypens="http://relaxng.org/ns/structure/1.0"?>

<?xml version="1.0" encoding="UTF-8"?>
<?xml-model href="/usr/share/speedata-publisher/schema/layoutschema-en.rng" type="application/xml" schematypens="http://relaxng.org/ns/structure/1.0"?>

<Layout xmlns="urn:speedata.de:2009/publisher/en"
    xmlns:sd="urn:speedata:2009/publisher/functions/en"
    xmlns:xi="http://www.w3.org/2001/XInclude">

  <Trace grid="yes" objects="yes" />
    <Pageformat width="100mm" height="100mm" />

  <Record element="data">

  <SetVariable variable="sqr1" select="4" />
  <SetVariable variable="sqr2" select="40" />

  <PlaceObject column="1" row="1">
  <Box width="4cm" height="4cm" background-color="limegreen"/>
  </PlaceObject>

  <PlaceObject column="5" row="5">
  <Box width="40mm" height="40mm" background-color="deeppink"/>
  </PlaceObject>

  <ClearPage />

  <PlaceObject column="1" row="1">
  <Box width="{concat($sqr1,cm)}" height="{concat($sqr1,cm)}" background-color="limegreen"/>
  </PlaceObject>

  <PlaceObject column="5" row="5">
  <Box width="{concat($sqr1,mm)}" height="{concat($sqr1,mm)}" background-color="deeppink"/>
  </PlaceObject>

  <ClearPage />

  <PlaceObject column="1" row="1">
  <Box width="{concat($sqr1,cm)}" height="{concat($sqr1,cm)}" background-color="limegreen"/>
  </PlaceObject>

  <PlaceObject column="5" row="5">
  <Box width="{concat($sqr2,mm)}" height="{concat($sqr2,mm)}" background-color="deeppink"/>
  </PlaceObject>

  </Record>  

  </Layout>

mm-bug.pdf

sp --layout=test-mm.xml --jobname=mm-bug --dummy
sp --version
Version: 4.19.20

Thanks! 🙏

pgundlach commented 3 weeks ago

The problem here is that you don't put the mm and cm in quotation marks. They get interpreted as a node selector, selecting nothing and thus evaluate to the empty string. Which results to something like concat($sqr1,cm) -> concat($sqr1,'') which is the same as $sqr1 and gets interpreted as "number of grid cells" which have by coincidence the width of 1cm. So 4cm is the same as 4 if the grid size is 1cm.

<Layout xmlns="urn:speedata.de:2009/publisher/en"
    xmlns:sd="urn:speedata:2009/publisher/functions/en"
    xmlns:xi="http://www.w3.org/2001/XInclude">

    <Trace grid="yes" objects="yes" />
    <Pageformat width="100mm" height="100mm" />

    <Record element="data">

        <SetVariable variable="sqr1" select="4" />
        <SetVariable variable="sqr2" select="40" />

        <PlaceObject column="1" row="1">
            <Box width="4cm" height="4cm" background-color="limegreen" />
        </PlaceObject>

        <PlaceObject column="5" row="5">
            <Box width="40mm" height="40mm" background-color="deeppink" />
        </PlaceObject>

        <ClearPage />

        <PlaceObject column="1" row="1">
            <Box width="{concat($sqr1,'cm')}" height="{concat($sqr1,'cm')}" background-color="limegreen" />
        </PlaceObject>

        <PlaceObject column="5" row="5">
            <Box width="{concat($sqr1,'mm')}" height="{concat($sqr1,'mm')}" background-color="deeppink" />
        </PlaceObject>

        <ClearPage />

        <PlaceObject column="1" row="1">
            <Box width="{concat($sqr1,'cm')}" height="{concat($sqr1,'cm')}" background-color="limegreen" />
        </PlaceObject>

        <PlaceObject column="5" row="5">
            <Box width="{concat($sqr2,'mm')}" height="{concat($sqr2,'mm')}" background-color="deeppink" />
        </PlaceObject>

    </Record>

</Layout>
Cicorione commented 3 weeks ago

Thank you @pgundlach 🙏