[Libreoffice-commits] .: 3 commits - filter/source
Michael Meeks
mmeeks at kemper.freedesktop.org
Thu Nov 25 04:47:38 PST 2010
filter/source/odfflatxml/odfflatxmlexport.xsl | 2
filter/source/odfflatxml/split-long-lines.xsl | 98 ++++++++++++++++++++++++++
2 files changed, 100 insertions(+)
New commits:
commit 5dffb230c70e3518f45e77d6f666aa2a2286ad3b
Author: Gioele Barabucci <gioele at svario.it>
Date: Thu Nov 18 11:23:29 2010 +0100
Unification of `<text:p>` and `<text:span>` code paths
diff --git a/filter/source/odfflatxml/split-long-lines.xsl b/filter/source/odfflatxml/split-long-lines.xsl
index 87ecdf4..0e9d310 100644
--- a/filter/source/odfflatxml/split-long-lines.xsl
+++ b/filter/source/odfflatxml/split-long-lines.xsl
@@ -33,13 +33,14 @@ instead of those above.
<xsl:param name="newline"><xsl:text xml:space="preserve"> </xsl:text></xsl:param>
<xsl:template match="text:p/text()">
- <xsl:call-template name="split-text">
- <xsl:with-param name="num-prec-spaces">0</xsl:with-param>
- <xsl:with-param name="text" select="."/>
- </xsl:call-template>
+ <xsl:call-template name="split-current-text-node"/>
</xsl:template>
<xsl:template match="text:p/text:span/text()">
+ <xsl:call-template name="split-current-text-node"/>
+ </xsl:template>
+
+ <xsl:template name="split-current-text-node">
<xsl:call-template name="split-text">
<xsl:with-param name="num-prec-spaces">0</xsl:with-param>
<xsl:with-param name="text" select="."/>
commit dee8c93bc040556c9326052711868e8027755ef3
Author: Gioele Barabucci <gioele at svario.it>
Date: Thu Nov 18 11:22:20 2010 +0100
Also split `<text:span>` elements
diff --git a/filter/source/odfflatxml/split-long-lines.xsl b/filter/source/odfflatxml/split-long-lines.xsl
index 92adb3f..87ecdf4 100644
--- a/filter/source/odfflatxml/split-long-lines.xsl
+++ b/filter/source/odfflatxml/split-long-lines.xsl
@@ -39,6 +39,13 @@ instead of those above.
</xsl:call-template>
</xsl:template>
+ <xsl:template match="text:p/text:span/text()">
+ <xsl:call-template name="split-text">
+ <xsl:with-param name="num-prec-spaces">0</xsl:with-param>
+ <xsl:with-param name="text" select="."/>
+ </xsl:call-template>
+ </xsl:template>
+
<xsl:template name="split-text">
<xsl:param name="num-prec-spaces"/>
<xsl:param name="text"/>
commit ea39bdf1870fff30a8175ceef3238b2e286df56d
Author: Gioele Barabucci <gioele at svario.it>
Date: Thu Nov 18 11:06:37 2010 +0100
Split long paragraphs inside flat ODT files
Flat ODT files usually contain very long paragraphs. As each `<text:p>`
is put on its own line, these `.fodt` files end up containing very
long lines. Long lines in XML files cause problems when using flat ODT
files in text-oriented SCM systems like git or when opening these files
in XML editors.
A very simple yet XML-compliant approach to make these lines shorter is
to, during the XML serialization, output a newline instead of a space
every N spaces (only inside paragraphs, if you want to be conservative).
Files created using this method are, from an XML point of view,
equivalent to the currently created `.fodt` files. Their files size
is also identical.
diff --git a/filter/source/odfflatxml/odfflatxmlexport.xsl b/filter/source/odfflatxml/odfflatxmlexport.xsl
index e08afd7..2c1ea97 100644
--- a/filter/source/odfflatxml/odfflatxmlexport.xsl
+++ b/filter/source/odfflatxml/odfflatxmlexport.xsl
@@ -11,4 +11,6 @@
<xsl:template match="@office:mimetype[string(.)='application/vnd.oasis.opendocument.drawing']">
<xsl:attribute name="office:mimetype">application/vnd.oasis.opendocument.graphics</xsl:attribute>
</xsl:template>
+
+ <xsl:include href="split-long-lines.xsl"/>
</xsl:stylesheet>
diff --git a/filter/source/odfflatxml/split-long-lines.xsl b/filter/source/odfflatxml/split-long-lines.xsl
new file mode 100644
index 0000000..92adb3f
--- /dev/null
+++ b/filter/source/odfflatxml/split-long-lines.xsl
@@ -0,0 +1,90 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+Version: MPL 1.1 / GPLv3+ / LGPLv3+
+
+The contents of this file are subject to the Mozilla Public License Version
+1.1 (the "License"); you may not use this file except in compliance with
+the License. You may obtain a copy of the License at
+http://www.mozilla.org/MPL/
+
+Software distributed under the License is distributed on an "AS IS" basis,
+WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+for the specific language governing rights and limitations under the
+License.
+
+The Initial Developer of the Original Code is
+ Gioele Barabucci <gioele at svario.it>
+Portions created by the Initial Developer are Copyright (C) 2010 the
+Initial Developer. All Rights Reserved.
+
+Contributor(s): Gioele Barabucci <gioele at svario.it>
+
+Alternatively, the contents of this file may be used under the terms of
+either the GNU General Public License Version 3 or later (the "GPLv3+"), or
+the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"),
+in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable
+instead of those above.
+-->
+<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+ xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0"
+ version="1.0">
+ <xsl:param name="num-max-spaces">5</xsl:param>
+ <xsl:param name="sep"><xsl:text xml:space="preserve"> </xsl:text></xsl:param>
+ <xsl:param name="newline"><xsl:text xml:space="preserve"> </xsl:text></xsl:param>
+
+ <xsl:template match="text:p/text()">
+ <xsl:call-template name="split-text">
+ <xsl:with-param name="num-prec-spaces">0</xsl:with-param>
+ <xsl:with-param name="text" select="."/>
+ </xsl:call-template>
+ </xsl:template>
+
+ <xsl:template name="split-text">
+ <xsl:param name="num-prec-spaces"/>
+ <xsl:param name="text"/>
+
+ <xsl:variable name="contains-space" select="contains($text, $sep)"/>
+ <xsl:variable name="text-before">
+ <xsl:choose>
+ <xsl:when test="$contains-space"><xsl:value-of select="substring-before($text, $sep)"/></xsl:when>
+ <xsl:when test="$text = $sep"><xsl:value-of select="$text"/></xsl:when>
+ <xsl:otherwise><xsl:value-of select="$text"/></xsl:otherwise>
+ </xsl:choose>
+ </xsl:variable>
+ <xsl:variable name="text-after">
+ <xsl:choose>
+ <xsl:when test="$contains-space"><xsl:value-of select="substring-after($text, $sep)"/></xsl:when>
+ <xsl:otherwise></xsl:otherwise>
+ </xsl:choose>
+ </xsl:variable>
+ <xsl:variable name="finished" select="string-length($text-after) = 0"/>
+ <xsl:variable name="is-empty" select="string-length($text-before) = 0"/>
+
+ <xsl:value-of select="$text-before"/>
+
+ <xsl:choose>
+ <xsl:when test="$num-prec-spaces = $num-max-spaces">
+ <xsl:value-of select="$newline"/>
+ <xsl:call-template name="split-text">
+ <xsl:with-param name="text" select="$text-after"/>
+ <xsl:with-param name="num-prec-spaces">0</xsl:with-param>
+ </xsl:call-template>
+ </xsl:when>
+
+ <xsl:otherwise>
+ <xsl:if test="$contains-space">
+ <xsl:value-of select="$sep"/>
+ </xsl:if>
+
+ <xsl:if test="not($finished)">
+ <xsl:variable name="incr" select="number(not($is-empty))"/>
+
+ <xsl:call-template name="split-text">
+ <xsl:with-param name="text" select="$text-after"/>
+ <xsl:with-param name="num-prec-spaces" select="$num-prec-spaces + $incr"/>
+ </xsl:call-template>
+ </xsl:if>
+ </xsl:otherwise>
+ </xsl:choose>
+ </xsl:template>
+</xsl:stylesheet>
More information about the Libreoffice-commits
mailing list