[cairo-commit] svgslides/src svgslides-4suite,1.6,1.7

Keith Packard commit at pdx.freedesktop.org
Tue Apr 19 19:53:43 PDT 2005


Committed by: keithp

Update of /cvs/cairo/svgslides/src
In directory gabe:/tmp/cvs-serv10415/src

Modified Files:
	svgslides-4suite 
Log Message:
2005-04-20  Keith Packard  <keithp at keithp.com>

	* src/svgslides-4suite:
	Add support for user-defined bullets


Index: svgslides-4suite
===================================================================
RCS file: /cvs/cairo/svgslides/src/svgslides-4suite,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- svgslides-4suite	20 Apr 2005 01:58:27 -0000	1.6
+++ svgslides-4suite	20 Apr 2005 02:53:40 -0000	1.7
@@ -3,6 +3,7 @@
 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'
+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
@@ -27,7 +28,8 @@
 NSS = {
 	u'ss': SS,
 	u'ssi': SSI,
-	u'svg': SVG
+	u'svg': SVG,
+        u'xlink': XLINK
 }
 
 def slide_file_name (slide_num, extension='.svg'):
@@ -46,6 +48,14 @@
     else:
         return default
 
+def get_attr_inherited (node, attribute, default=''):
+    try:
+    	return do_xpath (node, 
+			 u'ancestor-or-self::*[@' + attribute + u'][1]/@' + 
+			 attribute)[0].nodeValue
+    except IndexError, exc:
+	return default
+
 def get_attr_float (node, attr, default=1.0):
     value = node.getAttributeNS (None, attr)
     if value:
@@ -122,20 +132,12 @@
     file.close ()
     slide_num += 1
 
-def slide_get_inherited_attribute (slide, attribute):
-    try:
-    	return do_xpath (slide, 
-			 u'ancestor-or-self::*[@' + attribute + u'][1]/@' + 
-			 attribute)[0].nodeValue
-    except IndexError, exc:
-	return ''
-
 def slide_generate_svg_from_template (slide, theme, variant = None):
 
     def substitute_variable (variable):
 	variable_name = variable.getAttributeNS (SS, 'variable')
 #	value = slide.getAttributeNS (None, u''+variable_name)
-	value = slide_get_inherited_attribute (slide, variable_name)
+	value = get_attr_inherited (slide, variable_name)
 	variable.replaceChild (doc.createTextNode (value), variable.firstChild)
 
     def substitute_region (region):
@@ -204,16 +206,24 @@
             # XXX: Theme designer should be able to draw a custom bullet
             bullet_radius = font_size / 6
 
-            bullet = get_attr (li, 'bullet')
+            bullet = get_attr_inherited (li, 'bullet')
             if li.nodeName == 'lc' or bullet == 'off':
                 # no bullet for list continuation or explicitly disabled bullets
                 pass
             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'r',  `bullet_radius`)
+		print bullet
+	    	if bullet:
+		    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`)
+		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'r',  `bullet_radius`)
             
 	    values = do_xpath (li, u'text()')
 	    text = doc.createElementNS (SVG, 'text')
@@ -289,7 +299,7 @@
 	if font_size_string:
 		region.setAttributeNS (None, 'font-size', font_size_string)
 	else:
-		font_size_string = slide_get_inherited_attribute (text_sample, 'font-size')
+		font_size_string = get_attr_inherited (text_sample, 'font-size')
 	font_size = float(font_size_string)
 	font_family = text_sample.getAttributeNS (None, 'font-family')
 	if font_family:




More information about the cairo-commit mailing list