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

`<Pagetype>` misplacing content? #464

Closed pr-apes closed 1 year ago

pr-apes commented 1 year ago

@pgundlach,

this almost obvious sample (run with sp --dummy --jobname=misplaced):

<Layout xmlns="urn:speedata.de:2009/publisher/en"
    xmlns:sd="urn:speedata:2009/publisher/functions/en">

  <Record element="data">
      <Output>
        <Text>
          <Paragraph>
            <Value select="sd:dummytext()"/>
          </Paragraph>
        </Text>
      </Output>
  </Record>
</Layout>

With this source run with sp --dummy -v pdfdoc=misplaced.pdf:

<Layout xmlns="urn:speedata.de:2009/publisher/en"
  xmlns:sd="urn:speedata:2009/publisher/functions/en">

  <!--<Pageformat-->
    <!--width="{if (not(sd:mode('no-booklet'))) then '297mm' else '210mm'}"-->
    <!--height="{if (not(sd:mode('no-booklet'))) then '210mm' else '297mm'}"/>-->

  <Pagetype test="not(sd:mode('no-booklet'))" width="297mm" height="210mm"/>

  <Record element="data">
      <PlaceObject column="{$_pagewidth * 0.75}" row="{$_pageheight div 2}" hreference="center" vreference="middle">
        <Image file="{$pdfdoc}" width="{$_pagewidth div 2}" page="1"/>
      </PlaceObject>
  </Record>

</Layout>

The page is misplaced with <Pagetype>:

misplaced-a-fs8

A workaround is the commented <Pageformat>:

misplaced-000001-fs8

I don't know what am I or is missing here.

Many thanks for your help.

pgundlach commented 1 year ago

This is a bug and I don't really know how to work around it. This is a more simple test case:

<Layout xmlns="urn:speedata.de:2009/publisher/en"
    xmlns:sd="urn:speedata:2009/publisher/functions/en">

    <Pagetype name="foo" test="true()" width="297mm" height="210mm" />

    <Record element="data">
        <!-- <Message select="sd:current-row()"/> -->
        <Message select="$_pagewidth"/>
        <Message select="$_pageheight"/>
    </Record>

</Layout>

Workaround:

If you uncomment the first Message, the page is initialised by the sd:current-row() and then the page width and height are set correctly.

This should be documented though....

pgundlach commented 1 year ago

Perhaps I should stop using these page-dependent variables and expose them as functions?

pgundlach commented 1 year ago

There are now two xpath functions for page detection (sd:pagewidth() and sd:pageheight()) See https://doc.speedata.de/publisher/en/xpathfunctions/index.html#_sd_layout_functions

pr-apes commented 1 year ago

These functions are great to have.

Many thanks for your help.

pr-apes commented 1 year ago

I have just tested them and I'm afraid that these functions have problems to place content:

<Layout xmlns="urn:speedata.de:2009/publisher/en"
  xmlns:sd="urn:speedata:2009/publisher/functions/en">

  <Record element="data">
    <!--<PlaceObject column="{$_pagewidth * 0.5}" row="{$_pageheight div 2}" hreference="center" vreference="middle">-->
    <!--  <Image file="{$pdfdoc}" width="{$_pagewidth div 2}" page="1"/>-->
    <!--</PlaceObject>-->
    <PlaceObject column="{sd:pagewidth('sp') * 0.5}" row="{sd:pageheight('sp') div 2}" hreference="center" vreference="middle">
      <Image file="{$pdfdoc}" width="{sd:pagewidth('sp') div 2}" page="1"/>
    </PlaceObject>
  </Record>

</Layout>

With the code above (run invoking sp --dummy -v pdfdoc=misplaced.pdf and with the sample from the original comment), there is no visible placement at all (Publisher reports conflict in grid).

pgundlach commented 1 year ago

You need to add the unit sp, otherwise this is without dimension and will be interpreted as grid cells.

    <PlaceObject column="{sd:pagewidth('sp') * 0.5}sp" row="{sd:pageheight('sp') div 2}sp" hreference="center" vreference="middle" frame="solid">
      <Image file="{$pdfdoc}" width="{sd:pagewidth('sp') div 2}sp" page="1"/>
    </PlaceObject>
pr-apes commented 1 year ago

@pgundlach,

I wonder whether it would be possible that sd:pagewidth() could add the dimension in the result and behave similar to $_pagewidth.

This would result in the same behavior from $_pagewidth and sd:pagewidth(). Since the function is brand-new, it won't break backwards-compatibility.

Many thanks for your help.

pgundlach commented 1 year ago

But it makes calculation easier if I leave out the unit and it is closer to the behaviour of the other width/height functions.

pr-apes commented 1 year ago

In that case, it is perfectly fine for me.

Many thanks for your help.