Esempio n. 1
0
    def addText(self, **opts):
        """Add an svg text element"""
        text_tag = self.svg_dom.createElement("text")
        text_tag.setAttribute("id", str(opts.get("id", "")) + "_text")
        text_tag.setAttribute("x", str(opts.get("x", "0")))
        text_tag.setAttribute("y", str(opts.get("y", "0")))
        # text_tag.setAttribute("dominant-baseline","mathematical")
        text_tag.setAttribute("style", self.svg_current_font)
        self.svg_current_layer.appendChild(text_tag)

        # Generator
        lines = extractRTFString(opts["rtftext"])
        font_info = opts.get("fontinfo", None)
        if font_info is not None:
            font_height = int(font_info.get("Size"))
        else:
            font_height = 12
        total_height = 0.0
        for span in lines:
            total_height += float(span["style"].get("font-size", "%.1fpx" %
                                                    font_height)[:-2])
        y_diff = float(opts.get(
            "y", "12.0")) + opts.get("height", 0) / 2 - total_height / 2
        line_id = opts["id"]
        linenb = 0
        for span in lines:
            y_diff += float(span["style"].get("font-size",
                                              "%.1fpx" % font_height)[:-2])
            linenb += 1
            opts["id"] = str(line_id) + "_line" + str(linenb)
            self.addLine(text_tag,text = span["string"], style = span["style"],\
               y_pos=y_diff, line_height =font_height, **opts)
        self.__bb_box(opts.get("x", "0"), opts.get("y", "0"),
                      opts.get("width", "0"), opts.get("height", "0"))
Esempio n. 2
0
def testcomplexunicode(self):
    lines = extractRTFString(
        r""""{\rtf1\ansi\ansicpg1252\cocoartf949\cocoasubrtf540
\fs24 \uc0\u916
\fs10 2}"""
    )
    self.assertEqual(lines[0]["string"], u"\u03942")
Esempio n. 3
0
	def addText(self,**opts):
		"""Add an svg text element"""
		text_tag = self.svg_dom.createElement("text")
		text_tag.setAttribute("id",str(opts.get("id",""))+"_text")
		text_tag.setAttribute("x",str(opts.get("x","0")))
		text_tag.setAttribute("y",str(opts.get("y","0")))
		# text_tag.setAttribute("dominant-baseline","mathematical")
		text_tag.setAttribute("style", self.svg_current_font)
		self.svg_current_layer.appendChild(text_tag)
        
		# Generator
		lines = extractRTFString(opts["rtftext"])
		font_info =  opts.get("fontinfo",None)
		if font_info is not None:
			font_height = int(font_info.get("Size"))
		else:
			font_height = 12
		total_height = 0.0
		for span in lines:
			total_height += float(span["style"].get("font-size","%.1fpx"%font_height)[:-2])
		y_diff = float(opts.get("y", "12.0")) + opts.get("height",0)/2 -total_height/2
		line_id=opts["id"]
		linenb = 0
		for span in lines:
			y_diff+= float(span["style"].get("font-size","%.1fpx"%font_height)[:-2])
			linenb+=1
			opts["id"]=str(line_id)+"_line"+str(linenb)
			self.addLine(text_tag,text = span["string"], style = span["style"],\
						y_pos=y_diff, line_height =font_height, **opts)
		self.__bb_box(opts.get("x", "0"), opts.get("y", "0"), opts.get("width", "0"), opts.get("height", "0"))
Esempio n. 4
0
    def testfont(self):
        lines = extractRTFString(r"""{\rtf1\ansi\ansicpg1252\cocoartf949\cocoasubrtf540
{\fonttbl\f0\fnil\fcharset0 Monaco;}
{\colortbl;\red255\green255\blue255;\red20\green20\blue20;}
\pard\tx560\tx1120\tx1680\tx2240\tx2800\tx3360\tx3920\tx4480\tx5040\tx5600\tx6160\tx6720\ql\qnatural\pardirnatural

\f0\fs16 \cf2 \expnd0\expndtw0\kerning0
== LICENSE:\
\
(The MIT License)\
\
Copyright (c) 2007 Tom Preston-\
\
Permission is hereby granted, f\
ree of charge, to any person ob\
}""")
        self.assertEqual(len(lines),8 )
        self.assertEqual(lines[0]['style']["font-family"],"Monaco")
Esempio n. 5
0
    def testfont(self):
        lines = extractRTFString(
            r"""{\rtf1\ansi\ansicpg1252\cocoartf949\cocoasubrtf540
{\fonttbl\f0\fnil\fcharset0 Monaco;}
{\colortbl;\red255\green255\blue255;\red20\green20\blue20;}
\pard\tx560\tx1120\tx1680\tx2240\tx2800\tx3360\tx3920\tx4480\tx5040\tx5600\tx6160\tx6720\ql\qnatural\pardirnatural

\f0\fs16 \cf2 \expnd0\expndtw0\kerning0
== LICENSE:\
\
(The MIT License)\
\
Copyright (c) 2007 Tom Preston-\
\
Permission is hereby granted, f\
ree of charge, to any person ob\
}"""
        )
        self.assertEqual(len(lines), 8)
        self.assertEqual(lines[0]["style"]["font-family"], "Monaco")
Esempio n. 6
0
 def testSimple(self):
     '''assert extractRTFString(r"{\rtf1\ansi testing}")["string"]=="testing"'''
     lines = extractRTFString(r"{\rtf1\ansi testing}")
     self.assertEqual(len(lines), 1)
     self.assertEqual(lines[0]["string"],"testing")
Esempio n. 7
0
def testcomplexunicode(self):
        lines = extractRTFString(r""""{\rtf1\ansi\ansicpg1252\cocoartf949\cocoasubrtf540
\fs24 \uc0\u916
\fs10 2}""")
        self.assertEqual(lines[0]['string'],u'\u03942')
Esempio n. 8
0
 def testfontweight(self):
     ''' test that font size is correctly applied on spans'''
     lines = extractRTFString(r"{\rtf\ansi\fs10\b testing}")
     self.assertEqual(len(lines), 1)
     self.assertEqual(lines[0]['style'],  {"font-size":"5.0px","font-weight":"bold"})
Esempio n. 9
0
 def testfontweight(self):
     """ test that font size is correctly applied on spans"""
     lines = extractRTFString(r"{\rtf\ansi\fs10\b testing}")
     self.assertEqual(len(lines), 1)
     self.assertEqual(lines[0]["style"], {"font-size": "5.0px", "font-weight": "bold"})
Esempio n. 10
0
 def testSimple(self):
     '''assert extractRTFString(r"{\rtf1\ansi testing}")["string"]=="testing"'''
     lines = extractRTFString(r"{\rtf1\ansi testing}")
     self.assertEqual(len(lines), 1)
     self.assertEqual(lines[0]["string"], "testing")