[cairo-commit] svgslides/src svgslides-4suite,1.9,1.10
Carl Worth
commit at pdx.freedesktop.org
Mon Jul 11 21:40:35 PDT 2005
Committed by: cworth
Update of /cvs/cairo/svgslides/src
In directory gabe:/tmp/cvs-serv28674/src
Modified Files:
svgslides-4suite
Log Message:
* src/svgslides-4suite: Add a nasty hack which provides a hash
table to map nodes to NodeAttribute objects so that we can
annotate new properties with set_mapped_attr and
get_mapped_attr. We used to just use assignment such as node.attr
= value, but that doesn't work with th C implementation of
Domlette, and the python implementation has gone away upstream.
* test/test.xml: Pulled the img tag outside the outside the ul
tag, since otherwise it gets placed incorrectly. This might likely
be a regression, but svgslides has never offered great
stability...
Index: svgslides-4suite
===================================================================
RCS file: /cvs/cairo/svgslides/src/svgslides-4suite,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -d -r1.9 -r1.10
--- svgslides-4suite 26 Apr 2005 18:47:15 -0000 1.9
+++ svgslides-4suite 12 Jul 2005 04:40:33 -0000 1.10
@@ -5,20 +5,8 @@
SVG = u'http://www.w3.org/2000/svg'
XLINK = u'http://www.w3.org/1999/xlink'
-# 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
@@ -63,6 +51,40 @@
else:
return default
+# We use this to workaround the fact that we can't assign new
+# attribute values to cDomlette objects since, being C-implemented
+# python objects, they are crippled compared to actual python
+# objects. Remind me not to use python again in the future.
+
+class NodeAttribute:
+ def __init__(self):
+ pass;
+
+node_attribute_map = {};
+
+# XXX: The set_mapped_attr and get_mapped_attr names are horribly
+# close to the get_attr names and quite confusing. I would come up
+# with better names here if I had a better notion of what makes
+# "these" particular attributes distinct from "those". It may just be
+# time to throw this implementation away and start over again.
+
+def set_mapped_attr (node, attr, value):
+ if node not in node_attribute_map:
+ node_attribute_map[node] = NodeAttribute()
+ node_attribute_map[node].__dict__[attr] = value
+
+def get_mapped_attr (node, attr, default=0.0):
+ if node not in node_attribute_map:
+ return default
+ return node_attribute_map[node].__dict__[attr]
+
+def has_mapped_attr (node, attr):
+ if node not in node_attribute_map:
+ return False
+ if attr not in node_attribute_map[node].__dict__:
+ return False
+ return True
+
###
### Main program
###
@@ -154,17 +176,19 @@
def find_position_content_node (node):
sib = prev_sib (node)
if sib:
- node.y = sib.y + sib.height
+ sib_y = get_mapped_attr (sib, 'y')
+ sib_height = get_mapped_attr (sib, 'height')
+ set_mapped_attr (node, 'y', sib_y + sib_height)
else:
- node.y = 0
+ set_mapped_attr (node, 'y', 0)
if node.nodeName == u'ul':
parent = node.parentNode
if parent.nodeName == u'ul':
- node.x = 50
+ set_mapped_attr (node, 'x', 50)
else:
- node.x = 0
+ set_mapped_attr (node, 'x', 0)
else:
- node.x = 0
+ set_mapped_attr (node, 'x', 0)
def find_position_content_nodes (nodes):
for node in nodes:
@@ -182,7 +206,7 @@
height = 0
if node.hasChildNodes ():
height += find_height_content_nodes (node.childNodes)
- node.height = height
+ set_mapped_attr (node, 'height', height)
return height
def find_height_content_nodes (nodes):
@@ -196,9 +220,11 @@
find_position_content_nodes (content)
def transform_ul (ul, root):
- if ul.x or ul.y:
+ if has_mapped_attr (ul, 'x') or has_mapped_attr (ul, 'y'):
+ ul_x = get_mapped_attr (ul, 'x')
+ ul_y = get_mapped_attr (ul, 'y')
group = doc.createElementNS (SVG, 'g')
- group.setAttributeNS (None, u'transform', 'translate('+`ul.x`+','+`ul.y`+')')
+ group.setAttributeNS (None, u'transform', 'translate('+`ul_x`+','+`ul_y`+')')
root.appendChild (group)
return group
else:
@@ -207,6 +233,8 @@
def transform_li (li, root):
bullet_radius = font_size / 6
+ li_x = get_mapped_attr (li, 'x')
+ li_y = get_mapped_attr (li, 'y')
bullet = get_attr_inherited (li, 'bullet')
if li.nodeName == 'lc' or bullet == 'off':
# no bullet for list continuation or explicitly disabled bullets
@@ -216,13 +244,13 @@
b = doc.createElementNS (SVG, 'use')
root.appendChild(b)
b.setAttributeNS (XLINK, u'xlink:href', u'#' + bullet)
- b.setAttributeNS (None, u'x', `li.x + bullet_radius`)
- b.setAttributeNS (None, u'y', `li.y + font_size / 1.5`)
+ b.setAttributeNS (None, u'x', `li_x + bullet_radius`)
+ b.setAttributeNS (None, u'y', `li_y + font_size / 1.5`)
else:
circle = doc.createElementNS (SVG, 'circle')
root.appendChild (circle)
- circle.setAttributeNS (None, u'cx', `li.x + bullet_radius`)
- circle.setAttributeNS (None, u'cy', `li.y + font_size / 1.5`)
+ circle.setAttributeNS (None, u'cx', `li_x + bullet_radius`)
+ circle.setAttributeNS (None, u'cy', `li_y + font_size / 1.5`)
circle.setAttributeNS (None, u'r', `bullet_radius`)
align = get_attr_inherited (li, 'align')
@@ -233,8 +261,8 @@
for v in values:
text.appendChild (doc.createTextNode (v.nodeValue))
- x = li.x + 3 * bullet_radius
- y = li.y + font_size
+ x = li_x + 3 * bullet_radius
+ y = li_y + font_size
if align == 'center':
x += region_width / 2
text.setAttributeNS (None, u'text-anchor', u'middle')
@@ -258,6 +286,7 @@
img_x = get_attr_float (img, 'x', 0.0)
img_y = get_attr_float (img, 'y', 0.0)
+
# XXX: width/height are currently not working
img_width = get_attr_float (img, 'width', 1.0)
img_height = get_attr_float (img, 'height', 1.0)
More information about the cairo-commit
mailing list