pandoc icon indicating copy to clipboard operation
pandoc copied to clipboard

ICML writer: Image frame sizing can only be set with explicit values

Open Shrinks99 opened this issue 3 years ago • 15 comments

Problem

When converting a file from Markdown → ICML I can't seem to change the size of images in InDesign with graphics frame styles. Setting a value of {width=10cm} within my markdown file produces the expected result in InDesign, however, no graphics frame style is explicitly created to accomplish this unlike how Pandoc handles text styles (which works very nicely!) Instead, Pandoc seems to take the image's hard-coded width and height values and apply it as an override to the default graphics frame style.

When no explicit width value is set Pandoc's fallback is to look at each image's resolution and set width & height values accordingly. This is also set to be applied as an override to the default graphics frame style.

Because these overrides are set with absolute values I cannot modify the graphics frame style to handle images sizing dynamically within InDesign, the only option appears to be to add fixed image frame sizes to each image within Markdown or break the link to my markdown file and handle the layout manually.

Examples

When set to a fixed width size in Markdown that width is carried over and images behave as expected.

When no width value is set Pandoc falls back on the file's dimensions, this can result in overset images. Note the override styling of the default [Basic Graphics Frame]+ in both screenshots which cannot be removed, as such both of these images cannot be effectively styled within InDesign.

ICML Images Issues.zip

All files needed to reproduce the examples above should be included in this zip. Create a fresh 8.5x11" document and place the generated ICML within a text frame.

Proposed Solution

Instead of relying on the absolute sizing fallback for encoding image sizes in ICML, a generalized graphics frame style could be created with some sensible defaults in the same way that paragraph styles are currently handled in the ICML writer? This way image sizing could be dynamic instead of set with fixed default values that cannot be changed without unlinking and manually fixing the sizing issues.

Caveats & other notes

  • I've really tried to make this work but maybe I've just missed something important and I'm doing this wrong. 😬
  • I've also tried to have a solid read through the issues and found no explicit examples of this problem, #6936 is potentially related?
  • Implementing this solution could break some people's existing documents if folks like the existing auto-fixed-sizes and have not set explicit ones?

Shrinks99 avatar May 04 '21 07:05 Shrinks99

Yes, I think #6946 was the last change to how we output images in ICML... and I remember it involved a lot of trial and error :P

Back when I implemented images originally I didn't think there would be much use for images inside the text beyond tiny inline-images. And people would generally place the images in InDesign instead of having them part of the markdown file... but maybe that was a simplistic assumption...

The first step would be to find out exactly what the XML should look like... can we simply wrap the image in an element and keep everything inside as it?

mb21 avatar May 04 '21 09:05 mb21

I've come up with some settings that would work reasonably well as generalized defaults for an Image graphic style. Unfortunately InDesign doesn't seem to let users set the width by percentage of text box so I tried to assume a reasonable default of 12p0x24p0 but this can definitely be up for debate. The image will expand to fill the height and width of the container while keeping its proportions and aligning itself to the right. Further modifications can be made to all images in InDesign by editing the Image graphic style, if users wish to set absolute width & height values they can do so in Pandoc with the method that currently works fine.

Here's the object style I made for images that InDesign spits out when I export this document to an ICML, it's probably longer and more aggressively defined than it needs to be...

<ObjectStyle Self="ObjectStyle/Image" EnableTransformAttributes="true" TopLeftCornerOption="None" TopRightCornerOption="None" BottomLeftCornerOption="None" BottomRightCornerOption="None" TopLeftCornerRadius="12" TopRightCornerRadius="12" BottomLeftCornerRadius="12" BottomRightCornerRadius="12" EmitCss="true" IncludeClass="true" EnableTextFrameAutoSizingOptions="false" ExtendedKeyboardShortcut="0 0 0" EnableTextFrameColumnRuleOptions="false" EnableExportTagging="false" EnableObjectExportAltTextOptions="true" EnableObjectExportTaggedPdfOptions="true" EnableObjectExportEpubOptions="true" Name="Image" AppliedParagraphStyle="ParagraphStyle/$ID/NormalParagraphStyle" ApplyNextParagraphStyle="false" EnableFill="false" EnableStroke="false" EnableParagraphStyle="false" EnableTextFrameGeneralOptions="false" EnableTextFrameBaselineOptions="false" EnableStoryOptions="false" EnableTextWrapAndOthers="false" EnableAnchoredObjectOptions="false" CornerRadius="12" FillColor="Swatch/None" FillTint="-1" StrokeWeight="0" MiterLimit="4" EndCap="ButtEndCap" EndJoin="MiterEndJoin" StrokeType="StrokeStyle/$ID/Solid" LeftLineEnd="None" RightLineEnd="None" StrokeColor="Swatch/None" StrokeTint="-1" GapColor="Swatch/None" GapTint="-1" StrokeAlignment="CenterAlignment" Nonprinting="false" GradientFillAngle="0" GradientStrokeAngle="0" AppliedNamedGrid="n" KeyboardShortcut="0 0" EnableFrameFittingOptions="true" CornerOption="None" EnableStrokeAndCornerOptions="false" ArrowHeadAlignment="InsidePath" LeftArrowHeadScale="100" RightArrowHeadScale="100" EnableTextFrameFootnoteOptions="false">

Example file: Image Example.zip

Shrinks99 avatar May 04 '21 21:05 Shrinks99

Unfortunately InDesign doesn't seem to let users set the width by percentage of text box so I tried to assume a reasonable default of 12p0x24p0

that's unfortunate indeed... maybe @lrosenthol has some input?

mb21 avatar May 05 '21 07:05 mb21

Is there any progress on this matter? I have an otherwise working workflow from latex to icml via pandoc but at the moment, this involves omitting the images in latex because they are not displayed properly in Indesign.

nmueller18 avatar Jun 03 '22 18:06 nmueller18

I would also be curious to know if this feature has progressed since the last time. I find that having linked images from markdown converted to images in a styled image frame in ICML would be extremely convenient, since the original markdown document would contain everything, but the final styling.

ptram avatar Feb 25 '23 21:02 ptram

There hasn't been any progress (or it would be reported here). I don't know enough about ICML to be confident making changes myself. @mb21 what do you think of the proposal above? Is it something that could be made into a PR?

jgm avatar Feb 26 '23 21:02 jgm

Yes, seems like generally a good idea. As always with ICML output, implementing it just requires a lot of trial-and-error to see how the output actually looks and behaves in InCopy and when placed in InDesign. If somebody is willing to put in that work, go for it!

mb21 avatar Feb 27 '23 08:02 mb21

I can test it with InDesign CS6 (and Affinity Publisher), but not InCopy. If there is some new code, I can do some of the tests.

ptram avatar Feb 27 '23 10:02 ptram

Well, I could probably update the code, but I'd need someone to spell out explicitly all the changes needed to the output and/or templates.

jgm avatar Feb 27 '23 16:02 jgm

I'd need someone to spell out explicitly all the changes needed to the output and/or templates.

I don't know if the attached .icml file exported from InDesign CS6 can be of any help. All it contains are two paragraph styles (Body, Image) and an object style (My Image Object Style), this latter applied to the image in the Image-styled paragraph.

span and div styles are already reserved to character and paragraph styles. I frankly don't know how to define object styles in markdown. Are there, maybe, other examples on how to define frame styles? Object styles shouldn't be different from frame styles. image-object-style-test.icml.zip

ptram avatar Feb 28 '23 11:02 ptram

What would be most useful to me would be a diff between this and the current pandoc output.

jgm avatar Feb 28 '23 16:02 jgm

Let's see if there is something useful here. I generated a pandoc-tinged multimarkdown document from Scrivener, and then converted it to .icml via pandoc 3.1 for Mac. It doesn't contain custom styles, since I still don't know how to do it automatically in Scrivener. It doesn't contain custom object styles, since I don't know if this is even feasible.

By the way: my file contains a link to a .tiff image, and pandoc says that it can't fetch it. No need to answer on this, because I've not yet investigated on this issue.

mmd-from-scriv-pandoc.zip

ptram avatar Feb 28 '23 17:02 ptram

If there is some other example I can send, I'll be happy to do it!

ptram avatar Aug 02 '23 23:08 ptram

As I said, what would be most useful to me would be a diff between the desired output and the current pandoc output.

jgm avatar Aug 05 '23 06:08 jgm