Re: Image scaling driving me crazy. Can this be scripted?
Radu Coravu <[email protected]> Wed, 31 Mar 2021 07:41:11 +0300
| Newsgroups | gmane.text.docbook.apps |
|---|---|
| Message-ID | <[email protected]> |
Hi Philo,
I do not understand, in the last discussion you had with me and Bob
Stayton, Bob suggested some XSLT changes to convert the @width attribute
set on the image to a @style attribute:
> I'm coming to the conclusion that the EPUB3 standard changed after the
> Docbook epub3 stylesheet was created. The EPUB3 standard is based on
> XHTML5, and XHTML5 does permit @width on <img> elements. Further
> evidence of the change is that in the DocBook template that converts
> banned attributes to style attributes, there is a specific exception
> carved out for @width on img elements to pass it through to the epub3
> output. The comment in the XSL says it is permitted, and I know I've
> produced epub3 output that passed previous versions of epubcheck
> without complaining about @width.
>
> So this needs to be updated in the DocBook stylesheet. Could you
> please file an issue on the Github site for the stylesheets:
>
> https://github.com/docbook/xslt10-stylesheets
>
> In the meantime, I'll describe the source of the problem in case you
> want to fix it in your stylesheets. In the
> xhtml5/html5-element-mods.xsl files there is a template that starts
> with <xsl:template match="*" mode="convert.to.style"> that handles the
> conversion of hard attributes to styles. The culprit is this line in
> that template:
>
> <xsl:when test="local-name() = 'width' and $element != 'img'">
>
> that needs to be changed to:
>
> <xsl:when test="local-name() = 'width'">
>
> to remove the exception for img elements.
and from your answer I understood that this worked for you.
Regards,
Radu
Radu Coravu
Oxygen XML Editor
On 3/30/21 22:16, Philo Calhoun wrote:
> I tried the various suggestions given and still have to do extensive
> editing of OxygenXML docbook to ePub conversions if image scaling is
> used.
>
> To demonstrate the issue, here is a simple docbook XML file:
>
> <?xml version="1.0" encoding="UTF-8"?>
> <?xml-model href="http://docbook.org/xml/5.1/rng/docbook.rng
> <http://docbook.org/xml/5.1/rng/docbook.rng>"
> schematypens="http://relaxng.org/ns/structure/1.0
> <http://relaxng.org/ns/structure/1.0>"?>
> <?xml-model href="http://docbook.org/xml/5.1/sch/docbook.sch
> <http://docbook.org/xml/5.1/sch/docbook.sch>" type="application/xml"
> schematypens="http://purl.oclc.org/dsdl/schematron
> <http://purl.oclc.org/dsdl/schematron>"?>
> <articlexmlns="http://docbook.org/ns/docbook
> <http://docbook.org/ns/docbook>"xmlns:xlink="http://www.w3.org/1999/xlink
> <http://www.w3.org/1999/xlink>"version="5.1">
> <info>
> <title>Figure Scaling</title>
> <author>
> <personname>John Doe</personname>
> </author>
> <author>
> <orgname>ABC Publishing</orgname>
> </author>
> </info>
> <sect1>
> <title>The problem</title>
> <para>Image scaled 25%:</para>
> <para><inlinemediaobject>
> <imageobject>
> <imagedata
>
> fileref="../../../../../Applications/Oxygen%20XML%20Editor/samples/personal-images/michelle.taylor.jpg"width="25%"
> />
> </imageobject>
> </inlinemediaobject></para>
> <para>Image scaled 50%:</para>
> <para><inlinemediaobject>
> <imageobject>
> <imagedata
>
> fileref="../../../../../Applications/Oxygen%20XML%20Editor/samples/personal-images/michelle.taylor.jpg"width="50%"
> />
> </imageobject>
> </inlinemediaobject></para>
> <para>Image scaled 75%:</para>
> <para><inlinemediaobject>
> <imageobject>
> <imagedata
>
> fileref="../../../../../Applications/Oxygen%20XML%20Editor/samples/personal-images/michelle.taylor.jpg"width="75%"
> />
> </imageobject>
> </inlinemediaobject></para>
> </sect1>
> </article>
>
> __________________
>
> When this is exported, it looks fine on Apple Books but generates
> errors on Epubchecker, since width designation is not allowed in the
> ePub except as a image.style
>
> The OxygenXML generated ebook looks like this:
>
> <?xml version="1.0"
> encoding="utf-8"?><htmlxmlns="http://www.w3.org/1999/xhtml
> <http://www.w3.org/1999/xhtml>"
> xmlns:epub="http://www.idpf.org/2007/ops <http://www.idpf.org/2007/ops>"
> xmlns:m="http://www.w3.org/1998/Math/MathML
> <http://www.w3.org/1998/Math/MathML>"xmlns:pls="http://www.w3.org/2005/01/pronunciation-lexicon
> <http://www.w3.org/2005/01/pronunciation-lexicon>"
> xmlns:ssml="http://www.w3.org/2001/10/synthesis
> <http://www.w3.org/2001/10/synthesis>"
> xmlns:svg="http://www.w3.org/2000/svg
> <http://www.w3.org/2000/svg>"><head><title>Figure Scaling</title>
> <linkrel="stylesheet"type="text/css"href="docbook-epub.css"/>
> <metaname="generator"content="DocBook XSL Stylesheets V1.79.2"/></head>
> <body><header/>
> <sectionclass="article"title="Figure
> Scaling"id="d0e3"><divclass="titlepage"><div><div>
> <h1class="title">Figure Scaling</h1></div><div><divclass="author">
> <h3class="author">John Doe</h3></div></div><div><divclass="author">
> <h3class="author"><spanclass="orgname">ABC
> Publishing</span></h3></div></div></div><hr/></div>
> <sectionclass="sect1"title="The
> problem"epub:type="subchapter"id="d0e13"><divclass="titlepage"><div><div>
> <h2class="title"style="clear:both">The problem</h2></div></div></div>
> <p>Image scaled 25%:</p>
> <p><spanclass="inlinemediaobject"><imgsrc="images/michelle.taylor_987157347.jpg"width="25%"/></span></p>
> <p>Image scaled 50%:</p>
> <p><spanclass="inlinemediaobject"><imgsrc="images/michelle.taylor_987157347.jpg"width="50%"/></span></p>
> <p>Image scaled
> 75%:</p><p><spanclass="inlinemediaobject"><imgsrc="images/michelle.taylor_987157347.jpg"width="75%"/></span></p>
> </section>
> </section>
> <footer/>
> </body>
> </html>
> ______________________
>
> This generates errors for each width designation:
>
> E [EPUBCHeck 4.2.4] Error while parsing file: value of attribute
> “width” is invalid; must be an integer
>
> ________________________
>
> To fix this I need to add image styles to the CSS:
>
> img.A{width: 25%;}
>
> img.B{width: 50%;}
>
> img.B{width: 75%;}
>
> I can correct the code, but it requires manually changing each image
> entry, which is a real issue if one has 100 or so images. The
> corrected ePub code looks like this:
>
> <?xml version="1.0"
> encoding="utf-8"?><htmlxmlns="http://www.w3.org/1999/xhtml
> <http://www.w3.org/1999/xhtml>"
> xmlns:epub="http://www.idpf.org/2007/ops
> <http://www.idpf.org/2007/ops>"xmlns:m="http://www.w3.org/1998/Math/MathML
> <http://www.w3.org/1998/Math/MathML>"
> xmlns:pls="http://www.w3.org/2005/01/pronunciation-lexicon
> <http://www.w3.org/2005/01/pronunciation-lexicon>"
> xmlns:ssml="http://www.w3.org/2001/10/synthesis
> <http://www.w3.org/2001/10/synthesis>"
> xmlns:svg="http://www.w3.org/2000/svg <http://www.w3.org/2000/svg>">
> <head>
> <title>Figure Scaling</title>
> <linkrel="stylesheet"type="text/css"href="docbook-epub.css"/><metaname="generator"content="DocBook
> XSL Stylesheets V1.79.2"/></head><body><header/>
> <sectionclass="article"title="Figure
> Scaling"id="d0e3"><divclass="titlepage"><div><div>
> <h1class="title">Figure Scaling</h1></div><div><divclass="author">
> <h3class="author">John Doe</h3></div></div><div><divclass="author">
> <h3class="author"><spanclass="orgname">ABC
> Publishing</span></h3></div></div></div><hr/></div>
> <sectionclass="sect1"title="The
> problem"epub:type="subchapter"id="d0e13"><divclass="titlepage"><div><div>
> <h2class="title"style="clear:both">The problem</h2></div></div></div>
> <p>Image scaled 25%:</p>
> <p><spanclass="inlinemediaobject"><imgclass="A"src="images/michelle.taylor_987157347.jpg"/></span></p>
> <p>Image scaled 50%:</p>
> <p><spanclass="inlinemediaobject"><imgclass="B"src="images/michelle.taylor_987157347.jpg"/></span></p>
> <p>Image scaled 75%:</p>
> <p><spanclass="inlinemediaobject"><imgclass="C"src="images/michelle.taylor_987157347.jpg"/></span></p>
> </section>
> </section>
> <footer/>
> </body>
> </html>
>
> Is there a way of scripting this?