Skip to content

Commit

Permalink
Adding several feature updates & a preliminary fix for frames (to be …
Browse files Browse the repository at this point in the history
…tested with spec)
  • Loading branch information
svanteschubert committed Apr 26, 2023
1 parent 8587f1e commit 2a76ccd
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 29 deletions.
Expand Up @@ -81,7 +81,7 @@
<!-- *************** -->

<!-- ID / NAME of text-box -->
<xsl:template match="@draw:name">
<xsl:template match="@draw:name | @text:id | @xml:id">
<xsl:attribute name="id">
<xsl:choose>
<xsl:when test="number(substring(.,1,1))">
Expand Down
Expand Up @@ -23,7 +23,7 @@


<!-- *** Properties with a 'fo:' prefix *** -->
<xsl:template match="@fo:background-color">
<xsl:template match="@fo:background-color | @draw:fill-color">
<xsl:text>background-color:</xsl:text>
<xsl:value-of select="."/>
<xsl:text>; </xsl:text>
Expand Down
85 changes: 58 additions & 27 deletions src/test/resources/odf1.4/tools/odf2html/export/xhtml/body.xsl
Expand Up @@ -139,15 +139,21 @@
</xsl:choose>
<!-- adapt page size -->
<xsl:variable name="pageWidth" select="$pageProperties/style:page-layout-properties/@fo:page-width"/>
<xsl:variable name="pageHeight" select="$pageProperties/style:page-layout-properties/@fo:height"/>

<!-- multiple backgroundimages for different page styles (never used in html) -->
<xsl:variable name="backgroundImage" select="$pageProperties/style:page-layout-properties/style:background-image"/>
<!-- page margins & background image -->
<xsl:if test="$pageWidth or $pageProperties/style:page-layout-properties/@fo:* or $backgroundImage/@xlink:href">
<xsl:if test="$pageWidth or $pageHeight or $pageProperties/style:page-layout-properties/@fo:* or $backgroundImage/@xlink:href">
<xsl:attribute name="style">
<xsl:if test="$pageWidth">
<xsl:text>max-width:</xsl:text>
<xsl:value-of select="$pageWidth"/>
<xsl:value-of select="$pageWidth" />
<xsl:text>;</xsl:text>
</xsl:if>
<xsl:if test="$pageHeight">
<xsl:text>max-height:</xsl:text>
<xsl:value-of select="$pageHeight" />
<xsl:text>;</xsl:text>
</xsl:if>
<xsl:if test="$pageProperties/style:page-layout-properties/@fo:* or $backgroundImage/@xlink:href">
Expand Down Expand Up @@ -254,20 +260,20 @@
<xsl:comment>Next 'div' was a 'draw:text-box'.</xsl:comment>
<xsl:element name="div">
<xsl:variable name="dimension">
<xsl:apply-templates select="@fo:min-width"/>
<xsl:apply-templates select="@fo:max-width"/>
<xsl:apply-templates select="@fo:min-height"/>
<xsl:apply-templates select="@fo:max-height"/>
<xsl:apply-templates select="@fo:min-width" />
<xsl:apply-templates select="@fo:max-width" />
<xsl:apply-templates select="@fo:min-height" />
<xsl:apply-templates select="@fo:max-height" />
</xsl:variable>
<xsl:if test="$dimension">
<xsl:if test="normalize-space($dimension)!=''">
<xsl:attribute name="style">
<xsl:value-of select="$dimension"/>
<xsl:value-of select="$dimension" />
</xsl:attribute>
</xsl:if>
<xsl:apply-templates select="@draw:name">
<xsl:with-param name="globalData" select="$globalData"/>
</xsl:apply-templates>

<xsl:apply-templates select="@*">
<xsl:with-param name="globalData" select="$globalData" />
</xsl:apply-templates>
<xsl:apply-templates select="node()">
<xsl:with-param name="globalData" select="$globalData"/>
</xsl:apply-templates>
Expand Down Expand Up @@ -366,7 +372,7 @@
</xsl:if>

</xsl:when>
<xsl:when test="draw:frame and ((normalize-space($childText) != '') or (((count(*) - count(text:soft-page-break)) &gt; 1)))">
<xsl:when test="name() = 'draw:frame' and ((normalize-space($childText) != '') or (((count(*) - count(text:soft-page-break)) &gt; 1)))">
<!-- If there is a 'draw:frame' child with text (not being whitespace alone) and more than the draw:frame alone and
not the draw:frame and a soft-page-break alone (which is quite often) -->

Expand Down Expand Up @@ -437,7 +443,7 @@
<xsl:variable name="paragraphName" select="@text:style-name" />
<xsl:variable name="imageParagraphStyle" select="$globalData/all-styles/style[@style:name = $paragraphName]/final-properties"/>
<!-- Only the left margin of the first paragraph of a list item will be added to the margin of the complete list (all levels)-->
<!-- TODO: left-margin in order with bidirectional -->
<!-- TODO: left-margin in order with bidirectional -->
<xsl:choose>
<xsl:when test="contains($imageParagraphStyle, 'margin-left:')">
<xsl:call-template name="convert2cm">
Expand Down Expand Up @@ -795,7 +801,7 @@
<xsl:text>;</xsl:text>
</xsl:template>

<!-- As soon a frame is within a paragraph (text:p) or page:frame, every child element is floating (CSS) and worked out in sequence.
<!-- As soon a frame is within a paragraph (text:p) or page:frame, every child element is floating (CSS) and worked out in sequence.
Accumulating prior frame width and adding parent's left margin -->
<!-- Matching all elements and text beyond a paragraph/text:page which are sibling of a draw:frame -->
<xsl:template match="* | text()" mode="frameFloating">
Expand All @@ -808,7 +814,6 @@

<xsl:choose>
<xsl:when test="name() = 'draw:frame' and not($stopAtFirstFrame)">

<!-- if the first node is a draw:frame create a div -->
<xsl:call-template name="createDrawFrame">
<xsl:with-param name="globalData" select="$globalData"/>
Expand Down Expand Up @@ -953,7 +958,6 @@
<xsl:param name="previousFrameHeights" select="0" />
<xsl:param name="parentMarginLeft"/>
<xsl:param name="stopAtFirstFrame" select="false()" />

<xsl:variable name="parentMarginLeftNew">
<xsl:choose>
<xsl:when test="string-length(normalize-space($parentMarginLeft)) &lt; 1">
Expand Down Expand Up @@ -1031,13 +1035,15 @@
<xsl:with-param name="leftPosition" select="$leftPosition"/>
<xsl:with-param name="svgY" select="$svgY"/>
</xsl:call-template>
<!--
<xsl:apply-templates select="following-sibling::node()[1]" mode="frameFloating">
<xsl:with-param name="globalData" select="$globalData"/>
<xsl:with-param name="previousFrameWidths" select="$previousFrameWidths + $svgWidth"/>
<xsl:with-param name="parentMarginLeft" select="$parentMarginLeftNew"/>
<xsl:with-param name="leftPosition" select="$leftPosition"/>
<xsl:with-param name="stopAtFirstFrame" select="$stopAtFirstFrame" />
</xsl:apply-templates>
-->
</xsl:template>

<xsl:template name="createDrawFrame2">
Expand Down Expand Up @@ -1071,18 +1077,28 @@
<xsl:attribute name="style">
<xsl:call-template name="widthAndHeight"/>
<xsl:text> padding:0; </xsl:text>
<xsl:if test="@text:anchor-type!='as-char'">
<!-- all images float (CSS float relative) with a left position calculated by svg:x - parentMarginLeft - previousFrameWidths -->
<xsl:text> float:left; position:relative; left:</xsl:text>
<xsl:value-of select="$leftPosition"/>
<xsl:text>cm; </xsl:text>
<!-- if the frame is anchored on a char -->
<xsl:if test="@text:anchor-type='char'">
<xsl:choose>
<xsl:when test="@text:anchor-type!='as-char'">
<!-- all images float (CSS float relative) with a left position calculated by svg:x - parentMarginLeft - previousFrameWidths -->
<xsl:text> float:left; position:relative; left:</xsl:text>
<xsl:value-of select="$leftPosition" />
<xsl:text>cm; </xsl:text>
<!-- if the frame is anchored on a char -->
<xsl:if test="@text:anchor-type='char'">
<xsl:text>top:</xsl:text>
<xsl:value-of select="$svgY" />
<xsl:text>cm; </xsl:text>
</xsl:if>
</xsl:when>
<xsl:otherwise>
<xsl:text> position:absolute; left:</xsl:text>
<xsl:value-of select="$leftPosition" />
<xsl:text>cm; </xsl:text>
<xsl:text>top:</xsl:text>
<xsl:value-of select="$svgY"/>
<xsl:value-of select="$svgY" />
<xsl:text>cm; </xsl:text>
</xsl:if>
</xsl:if>
</xsl:otherwise>
</xsl:choose>
</xsl:attribute>
<xsl:apply-templates select="@*">
<xsl:with-param name="globalData" select="$globalData"/>
Expand Down Expand Up @@ -2816,7 +2832,22 @@
<xsl:param name="globalData"/>

<xsl:attribute name="class">
<xsl:value-of select="translate(., '.,;: %()[]/\+', '_____________')"/>
<xsl:choose>
<xsl:when test="name() = 'draw:text-style-name' or name() = 'draw:style-name'">
<xsl:choose>
<xsl:when test="parent::*/@draw:text-style-name and parent::*/@draw:style-name">
<xsl:value-of select="translate(parent::*/@draw:style-name, '.,;: %()[]/\+', '_____________')" /><xsl:text> </xsl:text>
<xsl:value-of select="translate(parent::*/@draw:text-style-name, '.,;: %()[]/\+', '_____________')" />
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="translate(., '.,;: %()[]/\+', '_____________')" />
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="translate(., '.,;: %()[]/\+', '_____________')"/>
</xsl:otherwise>
</xsl:choose>
</xsl:attribute>
</xsl:template>

Expand Down

0 comments on commit 2a76ccd

Please sign in to comment.