[cairo-commit] svgslides/src svgslides-4suite,1.1,1.2
Carl Worth
commit at pdx.freedesktop.org
Sat Feb 12 13:45:25 PST 2005
Committed by: cworth
Update of /cvs/cairo/svgslides/src
In directory gabe:/tmp/cvs-serv13180/src
Modified Files:
svgslides-4suite
Log Message:
* src/svgslides-4suite: Set USE_MINIDOM=1 internally to guarantee
we won't get the C implementation of Domlette, and so things will
actually work.
(do_xpath): Get input file and basename from command-line
argument.
(line_height, layout_ul, layout_li): Fix layout of single-depth
bulleted lists. Other than missing bullets, I think we know have
parity with the XSLT-based output.
Index: svgslides-4suite
===================================================================
RCS file: /cvs/cairo/svgslides/src/svgslides-4suite,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- svgslides-4suite 12 Feb 2005 18:21:18 -0000 1.1
+++ svgslides-4suite 12 Feb 2005 21:45:23 -0000 1.2
@@ -1,12 +1,24 @@
#! /usr/bin/python
-# XXX: This should be a command-line argument
-basename='test'
-
SS = u'http://www.svgslides.org/svgslides0.1'
SSI = u'http://www.svgslides.org/svgslides-index0.1'
SVG = u'http://www.w3.org/2000/svg'
+# By default Domlette uses a C implementation. Unfortunately, the C
+# implementations of python objects don't behave the same as python
+# implementations, (eg. we can't set new attributes on them). This
+# makes the C stuff pretty useless in my view.
+#
+# Domlette also provides an all-python implementation called
+# MiniDom. In order to get at it, we have to set the environment
+# variable USE_MINIDOM to 1. And we have to do this before importing
+# the Domlette stuff.
+
+import os
+import sys
+import re
+os.environ['USE_MINIDOM'] = '1'
+
from Ft.Xml.XPath.Context import Context
from Ft.Xml import XPath
from Ft.Xml import Domlette as Dom
@@ -29,8 +41,17 @@
### Main program
###
-file_uri = Uri.OsPathToUri ('test.xml', attemptAbsolute=1)
-slides_doc = Dom.NonvalidatingReader.parseUri (file_uri)
+if len (sys.argv) < 2:
+ print "Usage: %s slides.xml" % sys.argv[0]
+ print "Convert slides in a simple XML format to SVG."
+ sys.exit (1)
+
+input_file = sys.argv[1]
+m = re.match(r"(.*)\.xml", input_file)
+basename = m.group(1)
+
+file_uri = Uri.OsPathToUri (input_file, attemptAbsolute=1)
+slides_doc = Dom.NonvalidatingReader.parseUri (file_uri)
slides = do_xpath (slides_doc, u'//ss:slides/ss:slide')
@@ -61,12 +82,23 @@
def substitute_region (region):
+ def line_height ():
+ return font_size * 1.8
+
# XXX: Need to finish the layout functions
def layout_ul (ul):
- pass
+ ul.x = 10
+ ul.y = 10
def layout_li (li):
- pass
+ sibs = do_xpath (li, "preceding-sibling::ss:li[1]")
+ if len(sibs):
+ sib = sibs[0]
+ li.x = sib.x
+ li.y = sib.y + line_height ()
+ else:
+ li.x = 0
+ li.y = line_height ()
def layout_content_node (node):
if node.nodeName == u'ul':
@@ -77,6 +109,8 @@
def layout_content_nodes (nodes):
for node in nodes:
layout_content_node (node)
+ if (node.hasChildNodes ()):
+ layout_content_nodes (node.childNodes)
def transform_ul (ul, root):
group = doc.createElementNS (SVG, 'g')
@@ -89,9 +123,8 @@
root.appendChild (text)
for v in values:
text.appendChild (doc.createTextNode (v.nodeValue))
- # XXX: Need to get x/y from the layout stuff
- text.setAttributeNS (None, u'x', u'0')
- text.setAttributeNS (None, u'y', u'0')
+ text.setAttributeNS (None, u'x', `li.x`)
+ text.setAttributeNS (None, u'y', `li.y`)
return root
def transform_content_node (node, root):
@@ -110,8 +143,9 @@
# Copy text style up from a mandatory text element
text_sample = do_xpath (region, u'svg:text[1]')[0]
+ font_size = float(text_sample.getAttributeNS (None, 'font-size'))
+ region.setAttributeNS (None, 'font-size', `font_size`)
region.setAttributeNS (None, 'font-family', text_sample.getAttributeNS (None, 'font-family'))
- region.setAttributeNS (None, 'font-size', text_sample.getAttributeNS (None, 'font-size'))
region.setAttributeNS (None, 'fill', text_sample.getAttributeNS (None, 'fill'))
# Get bounds information from a mandatory rect within the region
More information about the cairo-commit
mailing list