speedata / publisher

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

horizontal and vertical clipping #394

Closed pr-apes closed 2 years ago

pr-apes commented 2 years ago

@pgundlach,

with the following sample image (the cow from the ConTeXt distribution), I invoke sp --dummy --autoopen -v external_pdfdoc=cow.pdf with the following layout.xml contents:

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

<Trace gridallocation="yes"/>

    <SetVariable variable="myfile" select="$external_pdfdoc"/>
  <Record element="data">
    <PlaceObject>
    <Image width="2cm" file="{$myfile}" clip="yes"/>
  </PlaceObject>
    <PlaceObject>
    <Image height="1cm" file="{$myfile}" clip="yes"/>
  </PlaceObject>
    <PlaceObject>
    <Image width="2cm" height="1cm" file="{$myfile}" clip="yes"/>
  </PlaceObject>
    <PlaceObject>
    <Image file="{$myfile}"/>
  </PlaceObject>
  </Record>
</Layout>

I can get horizontal or vertical clipping, but both seems to be impossible (with version 4.11.1).

Am I doing something wrong or missing something?

Many thanks for your help.

pgundlach commented 2 years ago

There is only one (either horizontal or vertical) clipping. clip="no" means (when width and height are given) distortion, with clip="yes" there is no distortion, but the image is scaled so that the whole area (width and height) is filled with portions of the image.

pr-apes commented 2 years ago

Just to confirm (I barely understand this), would both clippings achievable with transformations such as the ones you describe in https://github.com/speedata/publisher/discussions/395#discussioncomment-3106364?

pgundlach commented 2 years ago

Just to confirm (I barely understand this), would both clippings achievable with transformations such as the ones you describe in #395 (comment)?

Yes, but this is probably tedious calculation (works with DTP points and scale calculations).

pr-apes commented 2 years ago

I wonder whether it would be possible to implement custom clipping with clipping="both" and origin-x and origin-y (with units as in width and height)

I originally intended to translate a rather simple ConTeXt command:

\clip[hoffset=62.5mm, voffset=0.5mm, width=87.5mm, height=54mm]

But I ignore how hard would be to implement such feature in Publisher.

pr-apes commented 2 years ago

I close the issue for now (not a requirement until just before production).

pgundlach commented 2 years ago

I'll re-open it because I am thinking of adding a few attributes to the transform command to make it easier to use (I know that the transformation matrix is hard to use).

pgundlach commented 2 years ago

I think I'll add a new command Clip to be used something like this:

<Clip left="3mm" right="2mm" top="5mm" bottom="3mm">
    <Image width="5cm" file="_sampleb.pdf" />
</Clip>

to clip any kind of contents. Do you think this interface (left/right/top/bottom) is suitable or do you prefer something like the ConTeXt hoffset/voffset/width/height)?

pr-apes commented 2 years ago

@pgundlach,

many thanks for this element.

The ConTeXt values are more familiar to me. But this should not be a reason to decide.

Your approach is clearer (once I got what it meant đŸ˜…), but also requires to do the math,

I wonder whether having left, right, top, bottom and also width and height is an option.

I think it really makes sense, but I may be missing something.

Many thanks for your excellent work.

pr-apes commented 2 years ago

Many thanks for the new implementation, @pgundlach.

pgundlach commented 2 years ago

It is part of version 4.11.3 (available for download now)

pr-apes commented 2 years ago

I had already downloaded it (although I am testing other things).

I really appreciate this huge step in ease of use for image clipping.

Many thanks again.