summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRemko Tronçon <git@el-tramo.be>2010-03-28 19:43:32 (GMT)
committerRemko Tronçon <git@el-tramo.be>2010-03-28 19:44:49 (GMT)
commit3afa4f741c26360245dc313bc368f508b26a6b96 (patch)
tree4fc9fedac990a099010fed8a4ee09ddc51c21cc5 /3rdParty/DocBook/XSL/extensions
parent7548dabae7d10e48816142e508be651ada9f7bc3 (diff)
downloadswift-3afa4f741c26360245dc313bc368f508b26a6b96.zip
swift-3afa4f741c26360245dc313bc368f508b26a6b96.tar.bz2
Added DocBook infrastructure.
Imported most of "DocBook kit". Added placeholder for Swiften developers guide.
Diffstat (limited to '3rdParty/DocBook/XSL/extensions')
-rw-r--r--3rdParty/DocBook/XSL/extensions/README.LIBXSLT52
-rw-r--r--3rdParty/DocBook/XSL/extensions/docbook.py239
-rw-r--r--3rdParty/DocBook/XSL/extensions/saxon65.jarbin0 -> 80674 bytes
-rw-r--r--3rdParty/DocBook/XSL/extensions/xalan27.jarbin0 -> 57506 bytes
-rw-r--r--3rdParty/DocBook/XSL/extensions/xslt.py84
5 files changed, 375 insertions, 0 deletions
diff --git a/3rdParty/DocBook/XSL/extensions/README.LIBXSLT b/3rdParty/DocBook/XSL/extensions/README.LIBXSLT
new file mode 100644
index 0000000..2c80274
--- /dev/null
+++ b/3rdParty/DocBook/XSL/extensions/README.LIBXSLT
@@ -0,0 +1,52 @@
+----------------------------------------------------------------------
+ README file for the libxslt extensions
+----------------------------------------------------------------------
+$Id: README.LIBXSLT 7877 2008-03-08 04:07:52Z xmldoc $
+
+These are XSLT extensions written in Python for use with the DocBook XML
+stylesheets and the libxslt library[1].
+
+Currently, the only available extension is a function for adjusting column
+widths in tables. For more information, see the section describing the
+equivalent Java extension in "DocBook XSL: The Complete Guide"[2].
+
+----------------------------------------------------------------------
+Preparations
+----------------------------------------------------------------------
+In addition to libxml2 and libxslt, the following software needs to
+be installed before you start using the extensions:
+
+1. Python[3].
+
+2. Python bindings for libxml2/libxslt. Most distributions of
+ libxml2/libxslt for Unix/Linux include these bindings.
+ A native Windows port is provided by Stéphane Bidoul[4].
+
+----------------------------------------------------------------------
+Installation of the extensions
+----------------------------------------------------------------------
+No special installation step is needed.
+
+----------------------------------------------------------------------
+How to use the extensions
+----------------------------------------------------------------------
+Instead of using xsltproc, you run a Python program (xslt.py). The
+command has this general form:
+
+python xslt.py xmlfile xslfile [outputfile] [param1=val1 [param2=val]...]
+
+Modify paths, filenames, and parameters as needed. Make sure to set
+the "use.extensions" and "tablecolumns.extension" parameters to 1.
+
+----------------------------------------------------------------------
+Manifest
+----------------------------------------------------------------------
+README.LIBXSLT This file
+xslt.py Executable script file
+docbook.py Module that implements extensions
+
+----------------------------------------------------------------------
+[1] http://xmlsoft.org/XSLT
+[2] http://www.sagehill.net/docbookxsl/ColumnWidths.html
+[3] http://www.python.org/download
+[4] http://users.skynet.be/sbi/libxml-python
diff --git a/3rdParty/DocBook/XSL/extensions/docbook.py b/3rdParty/DocBook/XSL/extensions/docbook.py
new file mode 100644
index 0000000..c070602
--- /dev/null
+++ b/3rdParty/DocBook/XSL/extensions/docbook.py
@@ -0,0 +1,239 @@
+# docbook.py: extension module
+# $Id: docbook.py 8353 2009-03-17 16:57:50Z mzjn $
+
+import sys
+import string
+import libxml2
+import libxslt
+import re
+import math
+
+# Some globals
+pixelsPerInch = 96.0
+unitHash = { 'in': pixelsPerInch,
+ 'cm': pixelsPerInch / 2.54,
+ 'mm': pixelsPerInch / 25.4,
+ 'pc': (pixelsPerInch / 72.0) * 12,
+ 'pt': pixelsPerInch / 72.0,
+ 'px': 1 }
+
+# ======================================================================
+
+def adjustColumnWidths(ctx, nodeset):
+ #
+ # Small check to verify the context is correcly accessed
+ #
+ try:
+ pctxt = libxslt.xpathParserContext(_obj=ctx)
+ ctxt = pctxt.context()
+ tctxt = ctxt.transformContext()
+ except:
+ pass
+
+ # Get the nominal table width
+ varString = lookupVariable(tctxt, "nominal.table.width", None)
+ if varString == None:
+ nominalWidth = 6 * pixelsPerInch;
+ else:
+ nominalWidth = convertLength(varString);
+
+ # Get the requested table width
+ tableWidth = lookupVariable(tctxt, "table.width", "100%")
+
+ foStylesheet = (tctxt.variableLookup("stylesheet.result.type", None) == "fo")
+
+ relTotal = 0
+ relParts = []
+
+ absTotal = 0
+ absParts = []
+
+ colgroup = libxml2.xmlNode(_obj = nodeset[0])
+ # If this is an foStylesheet, we've been passed a list of fo:table-columns.
+ # Otherwise we've been passed a colgroup that contains a list of cols.
+ if foStylesheet:
+ colChildren = colgroup
+ else:
+ colChildren = colgroup.children
+
+ col = colChildren
+ while col != None:
+ if foStylesheet:
+ width = col.prop("column-width")
+ else:
+ width = col.prop("width")
+
+ if width == None:
+ width = "1*"
+
+ relPart = 0.0
+ absPart = 0.0
+ starPos = string.find(width, "*")
+ if starPos >= 0:
+ relPart, absPart = string.split(width, "*", 2)
+ relPart = float(relPart)
+ relTotal = relTotal + float(relPart)
+ else:
+ absPart = width
+
+ pixels = convertLength(absPart)
+ absTotal = absTotal + pixels
+
+ relParts.append(relPart)
+ absParts.append(pixels)
+
+ col = col.next
+
+ # Ok, now we have the relative widths and absolute widths in
+ # two parallel arrays.
+ #
+ # - If there are no relative widths, output the absolute widths
+ # - If there are no absolute widths, output the relative widths
+ # - If there are a mixture of relative and absolute widths,
+ # - If the table width is absolute, turn these all into absolute
+ # widths.
+ # - If the table width is relative, turn these all into absolute
+ # widths in the nominalWidth and then turn them back into
+ # percentages.
+
+ widths = []
+
+ if relTotal == 0:
+ for absPart in absParts:
+ if foStylesheet:
+ inches = absPart / pixelsPerInch
+ widths.append("%4.2fin" % inches)
+ else:
+ widths.append("%d" % absPart)
+ elif absTotal == 0:
+ for relPart in relParts:
+ rel = relPart / relTotal * 100
+ widths.append(rel)
+ widths = correctRoundingError(widths)
+ else:
+ pixelWidth = nominalWidth
+ if string.find(tableWidth, "%") < 0:
+ pixelWidth = convertLength(tableWidth)
+
+ if pixelWidth <= absTotal:
+ print "Table is wider than table width"
+ else:
+ pixelWidth = pixelWidth - absTotal
+
+ absTotal = 0
+ for count in range(len(relParts)):
+ rel = relParts[count] / relTotal * pixelWidth
+ relParts[count] = rel + absParts[count]
+ absTotal = absTotal + rel + absParts[count]
+
+ if string.find(tableWidth, "%") < 0:
+ for count in range(len(relParts)):
+ if foStylesheet:
+ pixels = relParts[count]
+ inches = pixels / pixelsPerInch
+ widths.append("%4.2fin" % inches)
+ else:
+ widths.append(relParts[count])
+ else:
+ for count in range(len(relParts)):
+ rel = relParts[count] / absTotal * 100
+ widths.append(rel)
+ widths = correctRoundingError(widths)
+
+ # Danger, Will Robinson! In-place modification of the result tree!
+ # Side-effect free? We don' need no steenkin' side-effect free!
+ count = 0
+ col = colChildren
+ while col != None:
+ if foStylesheet:
+ col.setProp("column-width", widths[count])
+ else:
+ col.setProp("width", widths[count])
+
+ count = count+1
+ col = col.next
+
+ return nodeset
+
+def convertLength(length):
+ # Given "3.4in" return the width in pixels
+ global pixelsPerInch
+ global unitHash
+
+ m = re.search('([+-]?[\d\.]+)(\S+)', length)
+ if m != None and m.lastindex > 1:
+ unit = pixelsPerInch
+ if unitHash.has_key(m.group(2)):
+ unit = unitHash[m.group(2)]
+ else:
+ print "Unrecognized length: " + m.group(2)
+
+ pixels = unit * float(m.group(1))
+ else:
+ pixels = 0
+
+ return pixels
+
+def correctRoundingError(floatWidths):
+ # The widths are currently floating point numbers, we have to truncate
+ # them back to integers and then distribute the error so that they sum
+ # to exactly 100%.
+
+ totalWidth = 0
+ widths = []
+ for width in floatWidths:
+ width = math.floor(width)
+ widths.append(width)
+ totalWidth = totalWidth + math.floor(width)
+
+ totalError = 100 - totalWidth
+ columnError = totalError / len(widths)
+ error = 0
+ for count in range(len(widths)):
+ width = widths[count]
+ error = error + columnError
+ if error >= 1.0:
+ adj = math.floor(error)
+ error = error - adj
+ widths[count] = "%d%%" % (width + adj)
+ else:
+ widths[count] = "%d%%" % width
+
+ return widths
+
+def lookupVariable(tctxt, varName, default):
+ varString = tctxt.variableLookup(varName, None)
+ if varString == None:
+ return default
+
+ # If it's a list, get the first element
+ if type(varString) == type([]):
+ varString = varString[0]
+
+ # If it's not a string, it must be a node, get its content
+ if type(varString) != type(""):
+ varString = varString.content
+
+ return varString
+
+# ======================================================================
+# Random notes...
+
+#once you have a node which is a libxml2 python xmlNode wrapper all common
+#operations are possible:
+# .children .last .parent .next .prev .doc for navigation
+# .content .type for introspection
+# .prop("attribute_name") to lookup attribute values
+
+# # Now make a nodeset to return
+# # Danger, Will Robinson! This creates a memory leak!
+# newDoc = libxml2.newDoc("1.0")
+# newColGroup = newDoc.newDocNode(None, "colgroup", None)
+# newDoc.addChild(newColGroup)
+# col = colgroup.children
+# while col != None:
+# newCol = newDoc.newDocNode(None, "col", None)
+# newCol.copyPropList(col);
+# newCol.setProp("width", "4")
+# newColGroup.addChild(newCol)
+# col = col.next
diff --git a/3rdParty/DocBook/XSL/extensions/saxon65.jar b/3rdParty/DocBook/XSL/extensions/saxon65.jar
new file mode 100644
index 0000000..4e0ea47
--- /dev/null
+++ b/3rdParty/DocBook/XSL/extensions/saxon65.jar
Binary files differ
diff --git a/3rdParty/DocBook/XSL/extensions/xalan27.jar b/3rdParty/DocBook/XSL/extensions/xalan27.jar
new file mode 100644
index 0000000..773ebdd
--- /dev/null
+++ b/3rdParty/DocBook/XSL/extensions/xalan27.jar
Binary files differ
diff --git a/3rdParty/DocBook/XSL/extensions/xslt.py b/3rdParty/DocBook/XSL/extensions/xslt.py
new file mode 100644
index 0000000..c712f65
--- /dev/null
+++ b/3rdParty/DocBook/XSL/extensions/xslt.py
@@ -0,0 +1,84 @@
+#!/usr/bin/python -u
+# $Id: xslt.py 8353 2009-03-17 16:57:50Z mzjn $
+
+import sys
+import libxml2
+import libxslt
+from docbook import adjustColumnWidths
+
+# Check the arguments
+usage = "Usage: %s xmlfile.xml xslfile.xsl [outputfile] [param1=val [param2=val]...]" % sys.argv[0]
+
+xmlfile = None
+xslfile = None
+outfile = "-"
+params = {}
+
+try:
+ xmlfile = sys.argv[1]
+ xslfile = sys.argv[2]
+except IndexError:
+ print usage
+ sys.exit(1)
+
+def quote(astring):
+ if astring.find("'") < 0:
+ return "'" + astring + "'"
+ else:
+ return '"' + astring + '"'
+
+try:
+ outfile = sys.argv[3]
+ if outfile.find("=") > 0:
+ name, value = outfile.split("=", 2)
+ params[name] = quote(value)
+ outfile = None
+
+ count = 4
+ while (sys.argv[count]):
+ try:
+ name, value = sys.argv[count].split("=", 2)
+ if params.has_key(name):
+ print "Warning: '%s' re-specified; replacing value" % name
+ params[name] = quote(value)
+ except ValueError:
+ print "Invalid parameter specification: '" + sys.argv[count] + "'"
+ print usage
+ sys.exit(1)
+ count = count+1
+except IndexError:
+ pass
+
+# ======================================================================
+# Memory debug specific
+# libxml2.debugMemory(1)
+
+# Setup environment
+libxml2.lineNumbersDefault(1)
+libxml2.substituteEntitiesDefault(1)
+libxslt.registerExtModuleFunction("adjustColumnWidths",
+ "http://nwalsh.com/xslt/ext/xsltproc/python/Table",
+ adjustColumnWidths)
+
+# Initialize and run
+styledoc = libxml2.parseFile(xslfile)
+style = libxslt.parseStylesheetDoc(styledoc)
+doc = libxml2.parseFile(xmlfile)
+result = style.applyStylesheet(doc, params)
+
+# Save the result
+if outfile:
+ style.saveResultToFilename(outfile, result, 0)
+else:
+ print result
+
+# Free things up
+style.freeStylesheet()
+doc.freeDoc()
+result.freeDoc()
+
+# Memory debug specific
+#libxslt.cleanup()
+#if libxml2.debugMemory(1) != 0:
+# print "Memory leak %d bytes" % (libxml2.debugMemory(1))
+# libxml2.dumpMemory()