def setUp(self): self.effect = Effect() self.document = self.effect.parse("TestFiles/unit_test_svg_ellipse.svg") root = self.effect.document.getroot() self.node = self.findTag(root, "ellipse") self.canvas = Canvas(0, 0) self.ellipse = Ellipse(None, self.node, self.canvas, None)
def __init__(self): Effect.__init__(self) # Two ways to get debug info: # OR just use inkex.debug(string) instead... try: self.tty = open("/dev/tty", 'w') except: self.tty = open(os.devnull, 'w') # '/dev/null' for POSIX, 'nul' for Windows. # print >>self.tty, "gears-dev " + __version__ self.OptionParser.add_option("--input_filename") self.OptionParser.add_option("--overwrite", default=False, **boolParams) self.OptionParser.add_option("--change_fill", default=False, **boolParams) self.OptionParser.add_option("--change_lines", default=False, **boolParams) self.OptionParser.add_option("--change_opacity", default=False, **boolParams) self.OptionParser.add_option("--color_space", default="rgb") self.OptionParser.add_option("--grayscale", default=False, **boolParams) self.OptionParser.add_option("--tones", default=False, **boolParams) self.OptionParser.add_option("--randomness", type="int", default=15, help=u"Procentní vyjádření jak moc může barva ustřelit do jakéhokoli směru (0 => plynulé přechody; 100 => kompletně random)") self.OptionParser.add_option("--colors", type="str", help=u"list barev (formát rrggbb (hexa)) jejichž variace mají být použité") self.OptionParser.add_option("--lines_width", type="float", default=0.0) self.OptionParser.add_option("--lines_color", default="#ffffff") self.OptionParser.add_option("--remove_opacity", default=False, **boolParams) self.OptionParser.add_option("--opacity_start", type="float", default=1.0) self.OptionParser.add_option("--opacity_end", type="float", default=0.0) self.OptionParser.add_option("--opacity_formula", default="1/x") self.OptionParser.add_option("--active-tab", help="no use in CLI")
def setUp(self): self.canvas = Canvas(0, 0) self.effect = Effect() self.document = self.effect.parse( "TestFiles/unit_test_svg_abstractShape.svg") self.root = self.effect.document.getroot() self.node = self.returnsGnode(self.root, "path") self.abstractShape = AbstractShape(None, self.node, self.canvas, None)
def setUp(self): self.effect = Effect() self.document = self.effect.parse("TestFiles/unit_test_image2.svg") root = self.effect.document.getroot() self.node = self.findTag(root, "g") self.node = self.findTag(self.node, "image") self.canvas = Canvas(0, 0) self.image = Image(None, self.node, self.canvas, None)
def __init__(self): Effect.__init__(self) addFn, typeFloat, typeInt, typeString, typeBool = getAddFnTypes(self) addFn( '--tab', action = 'store', type = typeString, dest = 'tab', \ default = 'splash', help = 'The active tab when Apply was pressed') addFn( '--action', action = 'store', type = typeString, dest = 'action', \ default = 'render', help = 'The active option when Apply was pressed' ) addFn( '--text', action = 'store', type = typeString, dest = 'text', \ default = 'Hello World', help = 'The input text to render') addFn( '--filePath', action = 'store', type = typeString, dest = 'filePath', \ default = '', help = 'Complete path of the text file') addFn( '--fontName', action = 'store', type = typeString, dest = 'fontName', \ default = 'Script', help = 'The custom font to be used for rendering') addFn( '--fontName2', action = 'store', type = typeString, dest = 'fontName2', \ default = 'Script', help = 'The custom font to be used for rendering 2') addFn( '--fontName3', action = 'store', type = typeString, dest = 'fontName3', \ default = 'Script', help = 'The custom font to be used for rendering 3') addFn( '--fontName4', action = 'store', type = typeString, dest = 'fontName4', \ default = 'Script', help = 'The custom font to be used for rendering 4') addFn('--fontSize', action = 'store', type = typeFloat, dest = 'fontSize', \ default = '100', help = 'Size of the font') addFn('--charSpacing', action = 'store', type = typeFloat, dest = 'charSpacing', \ default = '1', help = 'Spacing between characters') addFn('--wordSpacing', action = 'store', type = typeFloat, dest = 'wordSpacing', \ default = '1', help = 'Spacing between words') addFn('--lineSpacing', action = 'store', type = typeFloat, dest = 'lineSpacing', \ default = '1.5', help = 'Spacing between the lines') addFn('--flowInBox', action = 'store', type = typeBool, dest = 'flowInBox', \ default = False, help = 'Fit the text in the selected rectangle objects') addFn('--margin', action = 'store', type = typeFloat, dest = 'margin', default = '.1', \ help = 'Inside margin of text within the box') addFn( '--hAlignment', action='store', type = typeString, dest = 'hAlignment', \ default = 'left', help='Horizontal text alignment within the box') addFn( '--vAlignment', action='store', type = typeString, dest = 'vAlignment', \ default = 'none', help='Vertical text alignment within the box') addFn( '--expandDir', action='store', type = typeString, dest = 'expandDir', \ default = 'x', help='Create new rectangles if text doesn\'t fit the selected ones') addFn('--expandDist', action = 'store', type = typeFloat, dest = 'expandDist', \ default = True, help = 'Offset distance between the newly created rectangles')
def getoptions(self): """ inkex loads the sys.argv in the default parameter of it getoptions method. for the unittests where the same extension is loaded multiple time with different parameters, it causes some problems because args keeps the old sys.argv values. as a consequence, we have to give it sys.argv as a parameter """ Effect.getoptions(self, args=sys.argv[1:])
def setUp(self): self.circle = Circle(12, 12, 12, None) self.effect = Effect() self.document = self.effect.parse("TestFiles/unit_test_svg_circle.svg") root = self.effect.document.getroot() for node in root: tag = node.tag.split("}")[1] if (tag == 'circle'): self.node = node break
def parse(self): file = self.args[-1] Effect.parse(self, file) # we don't want to record the output of the enableTrace extension self.recording = False if Conf()['enableRecording'] == True: # create in svg file TestsCreator().addInSvg(file) TestsCreator().addTestArgvModule(self.options, self) self.recording = True
def setUp(self): self.effect = Effect() self.document = self.effect.parse("TestFiles/unit_test_svg_path.svg") root = self.effect.document.getroot() self.node = self.findTag(root, "g") self.node = self.findTag(self.node, "path") self.canvas = Canvas(0, 0) '''Fictional data used in methods such as pathlineto, pathcurveto, pathmoveto, patharcto. we made it so that the 5th parameters (600) is larger then the others, guaranteeing this way that the sqrt value is not a negative value in patharcto.''' self.data = [1.0, 2.0, 3.0, 4.0, 5.0, 600.0, 7.0] self.path = Path(None, self.node, self.canvas, None)
def __init__(self): Effect.__init__(self) self.arg_parser.add_argument("--tab") self.arg_parser.add_argument("--endpoints", dest="endpoints", action="store", type=Bool, default="true") self.arg_parser.add_argument("--controlpoints", dest="controlpoints", action="store", type=Bool, default="false")
def output(self): Effect.output(self) if self.recording == True and Conf()['enableRecording'] == True: testsCreator = TestsCreator() # create out svg file testsCreator.addOutSvg(self.document) testsCreator.writeTestValues() # increment test number conf = Conf() conf['currentTest'] += 1 conf.write()
def setUp(self): self.canvas = Canvas(0,0) self.effect = Effect() self.document = self.effect.parse("TestFiles/unit_test_svg_abstractShape.svg") self.root = self.effect.document.getroot() self.node = self.returnsGnode(self.root,"path") self.abstractShape = AbstractShape( None,self.node,self.canvas, None)
class TestSvgEllipse(unittest.TestCase): def setUp(self): self.effect = Effect() self.document = self.effect.parse("TestFiles/unit_test_svg_ellipse.svg") root = self.effect.document.getroot() self.node = self.findTag(root, "ellipse") self.canvas = Canvas(0, 0) self.ellipse = Ellipse(None, self.node, self.canvas, None) def findTag(self, root, no): for node in root: tag = node.tag.split("}")[1] if tag == no: return node return "" def testGetData(self): x, y, z, w = self.ellipse.getData() self.assertEqual(x, 60) self.assertEqual(y, 70) self.assertEqual(z, 250) self.assertEqual(w, 100) def testDraw(self): self.ellipse.draw(False) self.assertEqual(self.ellipse.canvasContext.code, ["\tctx.fillStyle = 'rgb(255, 0, 0)';\n", '\tctx.beginPath();\n', '\tctx.transform(0.866025, -0.500000, 0.500000, 0.866025, 900.000000, 200.000000);\n', '\tctx.moveTo(60.000000, -30.000000);\n', '\tctx.bezierCurveTo(198.071187, -30.000000, 310.000000, 14.771525, 310.000000, 70.000000);\n', '\tctx.bezierCurveTo(310.000000, 125.228475, 198.071187, 170.000000, 60.000000, 170.000000);\n', '\tctx.bezierCurveTo(-78.071187, 170.000000, -190.000000, 125.228475, -190.000000, 70.000000);\n', '\tctx.bezierCurveTo(-190.000000, 14.771525, -78.071187, -30.000000, 60.000000, -30.000000);\n', '\tctx.fill();\n'])
def testDraw(self): canvas = Canvas(0, 1) canvas.effect = Effect() canvas.document = canvas.effect.parse( "TestFiles/unit_test_svg_abstractShape_transformado.svg") canvas.root = canvas.effect.document.getroot() canvas.node = self.returnsGnode(canvas.root, "rect") rect = Rect("rect", canvas.node, canvas, None) rect.draw() self.assertEqual(rect.canvasContext.code, [ '\tctx.transform(1.000000, 0.000000, 0.380253, 0.924882, 0.000000, 0.000000);\n', "\tctx.lineJoin = 'miter';\n", "\tctx.strokeStyle = 'rgb(0, 0, 0)';\n", "\tctx.lineCap = 'butt';\n", '\tctx.lineWidth = 1.012632;\n', "\tctx.fillStyle = 'rgb(0, 0, 255)';\n", '\tctx.beginPath();\n', '\tctx.moveTo(-60.184902, 299.915122);\n', '\tctx.lineTo(-60.184902, 677.860048);\n', '\tctx.quadraticCurveTo(-60.184902, 683.719660, -60.184902, 683.719660);\n', '\tctx.lineTo(431.239998, 683.719660);\n', '\tctx.quadraticCurveTo(431.239998, 683.719660, 431.239998, 677.860048);\n', '\tctx.lineTo(431.239998, 299.915122);\n', '\tctx.quadraticCurveTo(431.239998, 294.055510, 431.239998, 294.055510);\n', '\tctx.lineTo(-60.184902, 294.055510);\n', '\tctx.quadraticCurveTo(-60.184902, 294.055510, -60.184902, 299.915122);\n', '\tctx.fill();\n', '\tctx.stroke();\n' ])
class TestSvg_image_unit_test(unittest.TestCase): def setUp(self): self.effect = Effect() self.document = self.effect.parse("TestFiles/unit_test_image2.svg") root = self.effect.document.getroot() self.node = self.findTag(root, "g") self.node = self.findTag(self.node, "image") self.canvas = Canvas(0, 0) self.image = Image(None, self.node, self.canvas, None); def findTag(self, root, no): for node in root: tag = node.tag.split("}")[1] if tag == no: return node return "" def testGetData(self): x, y, weight, height, href = self.image.get_data() href = href[-12:] array = [x ,y, weight, height, href] imageArray = [97.285713, 255.6479, 554, 422, "5_images.jpg"] self.assertEqual(array, imageArray)
def __init__(self): Effect.__init__(self) addFn, typeFloat, typeInt, typeString, typeBool = getAddFnTypes(self) addFn( "--fontName", action = "store", type = typeString, dest = "fontName", \ default = 'Script', help = "The custom font to edit") addFn('--rowCnt', action = 'store', type = typeInt, dest = 'rowCnt', \ default = '5', help = 'Number of rows (horizontal guides) in the template') addFn('--fontSize', action = 'store', type = typeInt, dest = 'fontSize', \ default = '100', help = 'Size of the source glyphs to be rendered') addFn("--tab", action = "store", type = typeString, dest = "tab", \ default = "sampling", help = "Tab")
class TestSvgCircle(unittest.TestCase): def setUp(self): self.circle = Circle(12, 12, 12, None) self.effect = Effect() self.document = self.effect.parse("TestFiles/unit_test_svg_circle.svg") root = self.effect.document.getroot() for node in root: tag = node.tag.split("}")[1] if (tag == 'circle'): self.node = node break def testGetDataCx(self): self.circle.node = self.node data = self.circle.getData() self.assertEqual(data[0], 600) def testGetDataCy(self): self.circle.node = self.node data = self.circle.getData() self.assertEqual(data[1], 200) def testGetDataR(self): self.circle.node = self.node data = self.circle.getData() self.assertEqual(data[2], 100)
class TestSvgCircle(unittest.TestCase): def setUp(self): self.circle = Circle(12, 12, 12, None) self.effect = Effect() self.document = self.effect.parse("TestFiles/unit_test_svg_circle.svg") root = self.effect.document.getroot() for node in root: tag = node.tag.split("}")[1] if(tag == 'circle'): self.node = node break def testGetDataCx(self): self.circle.node = self.node data = self.circle.getData() self.assertEqual(data[0], 600) def testGetDataCy(self): self.circle.node = self.node data = self.circle.getData() self.assertEqual(data[1], 200) def testGetDataR(self): self.circle.node = self.node data = self.circle.getData() self.assertEqual(data[2], 100)
def testHasGradient(self): canvas = Canvas(0, 1) canvas.effect = Effect() canvas.document = canvas.effect.parse( "TestFiles/unit_test_svg_abstractShape_transformado_GradienteLinear.svg" ) canvas.root = canvas.effect.document.getroot() canvas.node = self.returnsGnode(canvas.root, "path") canvas.abstractShape = AbstractShape(None, canvas.node, self.canvas, None) self.assertEqual( canvas.abstractShape.gradientHelper.hasGradient("fill"), "linear") canvas.document = canvas.effect.parse( "TestFiles/unit_test_svg_abstractShape_transformado_GradienteRadial.svg" ) canvas.root = canvas.effect.document.getroot() canvas.node = self.returnsGnode(canvas.root, "path") canvas.abstractShape = AbstractShape(None, canvas.node, self.canvas, None) self.assertEqual( canvas.abstractShape.gradientHelper.hasGradient("fill"), "radial") self.assertNotEqual( self.abstractShape.gradientHelper.hasGradient("fill"), "linear")
def setUp(self): self.effect = Effect() self.document = self.effect.parse("TestFiles/unit_test_svg_text.svg") self.root = self.effect.document.getroot() self.canvas = Canvas(0,0) self.node = self.findNodeInG(self.root,"text") self.text = Text( None,self.node,self.canvas, None)
def __init__(self): Effect.__init__(self) self.arg_parser.add_argument("--tab") self.arg_parser.add_argument("--csv_file", dest="csv_file", action="store", type=str, default="") self.arg_parser.add_argument("--csv_encoding", dest="csv_encoding", action="store", type=str, default="utf-8") self.arg_parser.add_argument("--csv_delimiter", dest="csv_delimiter", action="store", type=str, default=";") self.arg_parser.add_argument("--csv_columnx", dest="xidx", action="store", type=int, default=0) self.arg_parser.add_argument("--csv_columny", dest="yidxs", action="store", type=str, default="1") self.arg_parser.add_argument("--csv_ignorefirst", dest="ignorefirst", action="store", type=int, default=0) self.arg_parser.add_argument("--csv_storedata", dest="storedata", action="store", type=Bool, default="false") self.arg_parser.add_argument("--xaxis_format" , dest="xformat" , action="store", type=str, default="") self.arg_parser.add_argument("--xaxis_min" , dest="xmin" , action="store", type=float, default=0) self.arg_parser.add_argument("--xaxis_max" , dest="xmax" , action="store", type=float, default=100) self.arg_parser.add_argument("--xaxis_min_autodetect", dest="xmin_autodetect" , action="store", type=Bool, default="true") self.arg_parser.add_argument("--xaxis_max_autodetect", dest="xmax_autodetect" , action="store", type=Bool, default="true") self.arg_parser.add_argument("--xaxis_tick_n" , dest="xtickn" , action="store", type=int, default=10) self.arg_parser.add_argument("--xaxis_subtick_n", dest="xsubtickn" , action="store", type=int, default=0) self.arg_parser.add_argument("--xaxis_ticksin" , dest="xticksin" , action="store", type=Bool, default="true") self.arg_parser.add_argument("--xaxis_ticksout" , dest="xticksout" , action="store", type=Bool, default="false") self.arg_parser.add_argument("--xaxis_grid" , dest="xgrid" , action="store", type=Bool, default="false") self.arg_parser.add_argument("--yaxis_format" , dest="yformat" , action="store", type=str, default="") self.arg_parser.add_argument("--yaxis_min" , dest="ymin" , action="store", type=float, default=0) self.arg_parser.add_argument("--yaxis_max" , dest="ymax" , action="store", type=float, default=100) self.arg_parser.add_argument("--yaxis_min_autodetect", dest="ymin_autodetect" , action="store", type=Bool, default="true") self.arg_parser.add_argument("--yaxis_max_autodetect", dest="ymax_autodetect" , action="store", type=Bool, default="true") self.arg_parser.add_argument("--yaxis_tick_n" , dest="ytickn" , action="store", type=int, default=10) self.arg_parser.add_argument("--yaxis_subtick_n", dest="ysubtickn" , action="store", type=int, default=0) self.arg_parser.add_argument("--yaxis_ticksin" , dest="yticksin" , action="store", type=Bool, default="true") self.arg_parser.add_argument("--yaxis_ticksout" , dest="yticksout" , action="store", type=Bool, default="false") self.arg_parser.add_argument("--yaxis_grid" , dest="ygrid" , action="store", type=Bool, default="false") self.arg_parser.add_argument("--border_create_left" , dest="border_left" , action="store", type=Bool, default="true") self.arg_parser.add_argument("--border_create_bottom", dest="border_bottom", action="store", type=Bool, default="true") self.arg_parser.add_argument("--border_create_right" , dest="border_right" , action="store", type=Bool, default="true") self.arg_parser.add_argument("--border_create_top" , dest="border_top" , action="store", type=Bool, default="true") self.arg_parser.add_argument("--label_title", dest="label_title", type=str, action="store", default="") self.arg_parser.add_argument("--label_xaxis", dest="label_xaxis", type=str, action="store", default="") self.arg_parser.add_argument("--label_yaxis", dest="label_yaxis", type=str, action="store", default="") self.arg_parser.add_argument("--font_family", dest="font_family", type=str, action="store", default="sans") self.arg_parser.add_argument("--stroke_width" , dest="stroke_width" , type=float, action="store", default="1") self.arg_parser.add_argument("--stroke_width_unit", dest="stroke_width_unit", type=str , action="store", default="px") self.arg_parser.add_argument("--shape_remove_old" , dest="remove", action="store", type=Bool, default="false")
def __init__(self): InkscapeEffect.__init__(self) self.parser = argparse.ArgumentParser() self.parser.add_argument("--id", action='append', type=str, dest='ids', default=[], help='id attribute of object to manipulate') self.parser.add_argument('filename', help='temporary file on which extension will operate') self.parser.add_argument('-f', '--csv_file', type=str, default = '/home', help = 'CSV file to read names from') self.parser.add_argument('-n', '--csv_field_num', type=int, default = 1, help = 'Number of the field number that contains strings we want to vectorize, starts at 1') self.parser.add_argument('-l', '--separate_sizes', type=str_to_bool, default = False, help = 'Separate names for different sized graments onto different layers') self.parser.add_argument('-s', '--size_field_num', type=int, default = 1, help = 'Field number containing size for a given name') self.filename = sys.argv[-1]
class TestRect(unittest.TestCase): def setUp(self): self.effect = Effect() self.document = None self.effect.parse("TestFiles/unit_test_svg_Rect_WithRxRy.svg") self.node = None self.canvas = Canvas(0, 0) def findNodeInG(self, root, tag): for node in root: nodeTag = node.tag.split("}")[1] if (nodeTag == 'g'): root = node break for node in root: nodeTag = node.tag.split("}")[1] if (nodeTag == tag): return node def testExitWithoutRxRy(self): self.document = self.effect.parse( "TestFiles/unit_test_svg_Rect_WithoutRxRy.svg") root = self.effect.document.getroot() self.rect = Rect(None, self.node, self.canvas, None) self.rect.node = self.findNodeInG(root, 'rect') x, y, w, h, rx, ry = self.rect.getData() self.assertEqual(x, 40.0) self.assertEqual(y, 30.0) self.assertEqual(w, 100.0) self.assertEqual(h, 150.0) self.assertEqual(rx, 0) self.assertEqual(ry, 0) def testExitWithRxRy(self): self.document = self.effect.parse( "TestFiles/unit_test_svg_Rect_WithRxRy.svg") root = self.effect.document.getroot() self.rect = Rect(None, self.node, self.canvas, None) self.rect.node = self.findNodeInG(root, 'rect') x, y, w, h, rx, ry = self.rect.getData() self.assertEqual(x, 40.0) self.assertEqual(y, 30.0) self.assertEqual(w, 100.0) self.assertEqual(h, 150.0) self.assertEqual(rx, 5.0) self.assertEqual(ry, 10.0)
def setUp(self): self.effect = Effect() self.document = self.effect.parse("TestFiles/unit_test_image2.svg") root = self.effect.document.getroot() self.node = self.findTag(root, "g") self.node = self.findTag(self.node, "image") self.canvas = Canvas(0, 0) self.image = Image(None, self.node, self.canvas, None);
class TestRect(unittest.TestCase): def setUp(self): self.effect = Effect() self.document = None self.effect.parse("TestFiles/unit_test_svg_Rect_WithRxRy.svg") self.node = None self.canvas = Canvas(0, 0) def findNodeInG(self, root, tag): for node in root: nodeTag = node.tag.split("}")[1] if(nodeTag == 'g'): root = node break for node in root: nodeTag = node.tag.split("}")[1] if(nodeTag == tag): return node def testExitWithoutRxRy(self): self.document = self.effect.parse("TestFiles/unit_test_svg_Rect_WithoutRxRy.svg") root = self.effect.document.getroot() self.rect = Rect(None, self.node, self.canvas, None) self.rect.node = self.findNodeInG(root, 'rect') x, y, w, h, rx, ry = self.rect.getData() self.assertEqual(x, 40.0) self.assertEqual(y, 30.0) self.assertEqual(w, 100.0) self.assertEqual(h, 150.0) self.assertEqual(rx, 0) self.assertEqual(ry, 0) def testExitWithRxRy(self): self.document = self.effect.parse("TestFiles/unit_test_svg_Rect_WithRxRy.svg") root = self.effect.document.getroot() self.rect = Rect(None, self.node, self.canvas, None) self.rect.node = self.findNodeInG(root, 'rect') x, y, w, h, rx, ry = self.rect.getData() self.assertEqual(x, 40.0) self.assertEqual(y, 30.0) self.assertEqual(w, 100.0) self.assertEqual(h, 150.0) self.assertEqual(rx, 5.0) self.assertEqual(ry, 10.0)
def __init__(self): Effect.__init__(self) NSS[u'xmoto'] = u'http://xmoto.tuxfamily.org/' # in the svgs created by inkscape 0.46, in the cc:Work node, # the cc refers to the creativecommons namespace, not the # web.resource one put in inkex NSS[u'cc'] = u'http://creativecommons.org/ns#' # todo::get perfect values for width and height SPRITES['PlayerStart'] = { 'file': '__biker__.png', 'width': '2.10', 'height': '2.43', 'centerX': '1.05', 'centerY': '0.0' } # default values to populate windows self.svg = SvgDoc() # always the same seed to always generate the same random numbers # so that generated unittests works random.seed(1234567890)
def setUp(self): self.circle = Circle(12, 12, 12, None) self.effect = Effect() self.document = self.effect.parse("TestFiles/unit_test_svg_circle.svg") root = self.effect.document.getroot() for node in root: tag = node.tag.split("}")[1] if(tag == 'circle'): self.node = node break
def __init__(self): Effect.__init__(self) addFn, typeFloat, typeInt, typeString, typeBool = getAddFnTypes(self) addFn('--rowCnt', action = 'store', type = typeInt, dest = 'rowCnt', default = '5', \ help = 'Number of rows (horizontal guides) in the template') addFn("--createGlyphs", action="store", type=typeBool, dest="createGlyphs", \ default=True, help = 'Render glyphs of the source font family for tracing ') addFn('--srcFontFamily', action = 'store', type = typeString, dest = 'srcFontFamily', \ help = 'Exact name of the source font family') addFn('--fontSize', action = 'store', type = typeInt, dest = 'fontSize', default = '100', \ help = 'Size of the source glyphs to be rendered') addFn('--spaceWidth', action = 'store', \ type = typeInt, dest = 'spaceWidth', default = '50', \ help = 'Width of the space character (generally 1/3 to 1/2 times the font size') addFn('--fontType', action = 'store', type = typeString, dest = 'fontType', \ default = 'normal', help = 'Font Style') addFn('--startGlyph', action = 'store', type = typeString, dest = 'startGlyph', \ default = '0', help = 'Starting glyph to be rendered') addFn('--glyphCnt', action = 'store', type = typeInt, dest = 'glyphCnt', \ default = '75', help = 'Number of template glyphs') addFn("--rvGuides", action = "store", type = typeBool, dest = "rvGuides", \ default = False, help = 'Render vertical guide at the right of each glyph') addFn("--fillOpacity", action = "store", type = typeFloat, dest = "fillOpacity", \ default = False, help = 'Fill opacity of source glyph') addFn("--strokeOpacity", action = "store", type = typeFloat, dest = "strokeOpacity", \ default = False, help = 'Stroke opacity of source glyph') addFn("--tab", action = "store", type = typeString, dest = "tab", \ default = "sampling", help="Tab")
def testHasClip(self): canvas = Canvas(0, 1) canvas.effect = Effect() canvas.document = canvas.effect.parse( "TestFiles/unit_test_svg_abstractShape_transformado_Clip.svg") canvas.root = canvas.effect.document.getroot() canvas.node = self.returnsGnode(canvas.root, "path") canvas.abstractShape = AbstractShape(None, canvas.node, self.canvas, None) self.assertTrue(canvas.abstractShape.hasClip()) self.assertFalse(self.abstractShape.hasClip())
def setUp(self): self.effect = Effect() self.document = self.effect.parse("TestFiles/unit_test_svg_path.svg") root = self.effect.document.getroot() self.node = self.findTag(root, "g") self.node = self.findTag(self.node, "path") self.canvas = Canvas(0, 0) '''Fictional data used in methods such as pathlineto, pathcurveto, pathmoveto, patharcto. we made it so that the 5th parameters (600) is larger then the others, guaranteeing this way that the sqrt value is not a negative value in patharcto.''' self.data =[1.0, 2.0, 3.0, 4.0, 5.0, 600.0, 7.0] self.path = Path(None, self.node, self.canvas, None)
def testGetClipHref(self): returnValue = "clipPath3191" canvas = Canvas(0, 1) canvas.effect = Effect() canvas.document = canvas.effect.parse( "TestFiles/unit_test_svg_abstractShape_transformado_Clip.svg") canvas.root = canvas.effect.document.getroot() canvas.node = self.returnsGnode(canvas.root, "path") canvas.abstractShape = AbstractShape(None, canvas.node, self.canvas, None) self.assertEqual(canvas.abstractShape.getClipId(), returnValue)
def __init__(self): InkscapeEffect.__init__(self) self.parser = argparse.ArgumentParser() self.parser.add_argument("--id", action='append', type=str, dest='ids', default=[], help='id attribute of object to manipulate') self.parser.add_argument( 'filename', help='temporary file on which extension will operate') self.parser.add_argument('-f', '--csv_file', type=str, default='/home', help='CSV file to read names from') self.parser.add_argument( '-n', '--csv_field_num', type=int, default=1, help= 'Number of the field number that contains strings we want to vectorize, starts at 1' ) self.parser.add_argument( '-l', '--separate_sizes', type=str_to_bool, default=False, help= 'Separate names for different sized graments onto different layers' ) self.parser.add_argument( '-s', '--size_field_num', type=int, default=1, help='Field number containing size for a given name') self.filename = sys.argv[-1]
def testHasTransform(self): self.assertNotEqual(True, self.abstractShape.hasTransform()) canvas = Canvas(0, 1) canvas.effect = Effect() canvas.document = canvas.effect.parse( "TestFiles/unit_test_svg_abstractShape_transformado.svg") canvas.root = canvas.effect.document.getroot() canvas.node = self.returnsGnode(canvas.root, "rect") canvas.abstractShape = AbstractShape(None, canvas.node, self.canvas, None) self.assertEqual(True, canvas.abstractShape.hasTransform())
class TestSvgPath(unittest.TestCase): def setUp(self): self.effect = Effect() self.document = self.effect.parse("TestFiles/unit_test_svg_path.svg") root = self.effect.document.getroot() self.node = self.findTag(root, "g") self.node = self.findTag(self.node, "path") self.canvas = Canvas(0, 0) '''Fictional data used in methods such as pathlineto, pathcurveto, pathmoveto, patharcto. we made it so that the 5th parameters (600) is larger then the others, guaranteeing this way that the sqrt value is not a negative value in patharcto.''' self.data =[1.0, 2.0, 3.0, 4.0, 5.0, 600.0, 7.0] self.path = Path(None, self.node, self.canvas, None) def findTag(self, root, no): for node in root: tag = node.tag.split("}")[1] if tag == no: return node return "" def testGetData(self): vetor = self.path.getData() vetorDaElipse = [['M', [447.49757, 166.4584]], ['A', [197.48482, 67.680222, 0.0, 1, 1, 52.527939, 166.4584]], ['A', [197.48482, 67.680222, 0.0, 1, 1, 447.49757, 166.4584]], ['Z', []]] self.assertEqual(vetor, vetorDaElipse) def testPathMoveTo(self): self.path.pathMoveTo(self.data) self.assertEqual(self.path.canvasContext.code, ['\tctx.moveTo(1.000000, 2.000000);\n']) def testPathLineTo(self): self.path.pathLineTo(self.data) self.assertEqual(self.path.canvasContext.code, ['\tctx.lineTo(1.000000, 2.000000);\n']) def testPathCurveTo(self): self.path.pathCurveTo(self.data) self.assertEqual(self.path.canvasContext.code, ['\tctx.bezierCurveTo(1.000000, 2.000000, 3.000000, 4.000000, 5.000000, 600.000000);\n']) def testPathArcTo(self): self.path.currentPosition = [600.0, 7.0] self.path.pathArcTo(self.data) self.assertEqual(self.path.canvasContext.code, []) self.path.currentPosition = [0.25, 0.25] self.path.pathArcTo(self.data) self.assertEqual(self.path.canvasContext.code, ['\tctx.translate(300.125000, 3.625000);\n', '\tctx.rotate(0.052360);\n', '\tctx.scale(0.500000, 1.000000);\n', '\tctx.arc(0.000000, 0.000000, 599.408034, 3.121031, 6.26262379, -4);\n', '\tctx.scale(2.000000, 1.000000);\n', '\tctx.rotate(-0.052360);\n', '\tctx.translate(-300.125000, -3.625000);\n']) def testDraw(self): self.maxDiff = None self.path.draw(False) self.assertEqual(self.path.canvasContext.code, ["\tctx.lineJoin = 'miter';\n", "\tctx.strokeStyle = 'rgb(0, 0, 0)';\n", "\tctx.lineCap = 'butt';\n", '\tctx.lineWidth = 1.000000;\n', "\tctx.fillStyle = 'rgb(255, 0, 0)';\n", '\tctx.beginPath();\n', '\tctx.transform(0.707107, -0.707107, 0.707107, 0.707107, -44.476826, 225.540250);\n', '\tctx.moveTo(447.497570, 166.458400);\n', '\tctx.translate(250.012754, 166.472848);\n', '\tctx.rotate(0.000000);\n', '\tctx.scale(1.000000, 0.342711);\n', '\tctx.arc(0.000000, 0.000000, 197.484820, -0.000213, 3.14180613, 0);\n', '\tctx.scale(1.000000, 2.917910);\n', '\tctx.rotate(-0.000000);\n', '\tctx.translate(-250.012754, -166.472848);\n', '\tctx.translate(250.012754, 166.443952);\n', '\tctx.rotate(0.000000);\n', '\tctx.scale(1.000000, 0.342711);\n', '\tctx.arc(0.000000, 0.000000, 197.484820, 3.141379, 6.28339879, 0);\n', '\tctx.scale(1.000000, 2.917910);\n', '\tctx.rotate(-0.000000);\n', '\tctx.translate(-250.012754, -166.443952);\n', '\tctx.closePath();\n', '\tctx.fill();\n', '\tctx.stroke();\n'])
class TestSvgElement(unittest.TestCase): def setUp(self): self.element = Element() self.effect = Effect() self.document = self.effect.parse( "TestFiles/unit_test_svg_element.svg") self.node = self.effect.document.getroot() def testAttrWithNs(self): self.element.node = self.node returnValue = self.element.attr("width", "ns") self.assertEqual(returnValue, "12cm") def testAttrWithoutNs(self): self.element.node = self.node returnValue = self.element.attr("width") self.assertEqual(returnValue, "12cm")
class TestSvgElement(unittest.TestCase): def setUp(self): self.element = Element() self.effect = Effect() self.document = self.effect.parse("TestFiles/unit_test_svg_element.svg") self.node = self.effect.document.getroot() def testAttrWithNs(self): self.element.node = self.node returnValue = self.element.attr("width", "ns") self.assertEqual(returnValue, "12cm") def testAttrWithoutNs(self): self.element.node = self.node returnValue = self.element.attr("width") self.assertEqual(returnValue, "12cm")
def testGetTransform(self): m11 = (float(1), float(0), float(0.3802532), float(0.92488243), 0.0, 0.0) canvas = Canvas(0, 1) canvas.effect = Effect() canvas.document = canvas.effect.parse( "TestFiles/unit_test_svg_abstractShape_transformado.svg") canvas.root = canvas.effect.document.getroot() canvas.node = self.returnsGnode(canvas.root, "rect") canvas.abstractShape = AbstractShape(None, canvas.node, self.canvas, None) vetor = canvas.abstractShape.getTransform() self.assertEqual(m11, vetor)
def testEnd(self): self.abstractShape.endDraw() self.assertEqual(self.abstractShape.canvasContext.code, []) canvas1 = Canvas(0, 3) canvas1.effect = Effect() canvas1.document = canvas1.effect.parse( "TestFiles/unit_test_svg_abstractShape_transformado.svg") canvas1.root = canvas1.effect.document.getroot() canvas1.node = self.returnsGnode(canvas1.root, "rect") canvas1.abstractShape = AbstractShape(None, canvas1.node, canvas1, None) canvas1.abstractShape.endDraw() canvas2 = Canvas(0, 2) canvas2.restore() self.assertEqual(canvas1.abstractShape.canvasContext.code, canvas2.code)
def testGetGradientHref(self): returnValue = "linearGradient3022" canvas = Canvas(0, 1) canvas.effect = Effect() canvas.document = canvas.effect.parse( "TestFiles/unit_test_svg_abstractShape_transformado_GradienteLinear.svg" ) canvas.root = canvas.effect.document.getroot() canvas.node = self.returnsGnode(canvas.root, "path") canvas.abstractShape = AbstractShape(None, canvas.node, self.canvas, None) self.assertEqual( returnValue, canvas.abstractShape.gradientHelper.getGradientHref("fill")) returnValue = "ovalGradient3022" self.assertNotEqual( returnValue, canvas.abstractShape.gradientHelper.getGradientHref("fill"))
class TestSvgLine(unittest.TestCase): def setUp(self): self.effect = Effect() self.document = self.effect.parse("TestFiles/unit_test_svg_line.svg") root = self.effect.document.getroot() self.node = self.findTag(root, "line") self.canvas = Canvas(0, 0) self.line = Line(None, self.node, self.canvas, None) def findTag(self, root, no): for node in root: tag = node.tag.split("}")[1] if tag == no: return node return "" def testGetData(self): x, y = self.line.getData() self.assertEqual(x, ('M', (100.0, 300.0)) ) self.assertEqual(y, ('L', (300.0, 100.0)) )
class TestSvgG(unittest.TestCase): def setUp(self): self.effect = Effect() self.document = self.effect.parse("TestFiles/unit_test_svg_g.svg") root = self.effect.document.getroot() self.node = self.findTag(root, "g") self.canvas = Canvas(0, 0) self.g = G(None, self.node, self.canvas, None) def findTag(self, root, no): for node in root: tag = node.tag.split("}")[1] if tag == no: return node return "" def testDraw(self): self.g.draw(False); self.assertEqual(self.g.canvasContext.code, ['\tctx.transform(-0.866025, 0.500000, -0.500000, -0.866025, 0.000000, 0.000000);\n'])
class TestText(unittest.TestCase): def setUp(self): self.effect = Effect() self.document = self.effect.parse("TestFiles/unit_test_svg_text.svg") self.root = self.effect.document.getroot() self.canvas = Canvas(0,0) self.node = self.findNodeInG(self.root,"text") self.text = Text( None,self.node,self.canvas, None) def findNodeInG(self, root, tag): for node in root: nodeTag = node.tag.split("}")[1] if(nodeTag == 'g'): root = node break for node in root: nodeTag = node.tag.split("}")[1] if(nodeTag == tag): return node def testGetData(self): x, y = self.text.getData() self.assertEqual(x, 188.89853) self.assertEqual(y, 117.97108) def testTextHelper(self): stringRetornada = self.text.textHelper(self.node) self.assertEqual(stringRetornada, "TESTE\n ") def testSetTextStyle(self): self.text.setTextStyle(self.text.getStyle()) self.assertEqual(self.text.canvasContext.code, ['\tctx.font = "normal normal 40px Sans";\n']) def testDraw(self): self.text.draw(False) self.assertEqual(self.text.canvasContext.code, ['\tctx.transform(0.707107, -0.707107, 0.707107, 0.707107, -44.476826, 225.540250);\n', "\tctx.fillStyle = 'rgb(0, 0, 0)';\n", '\tctx.font = "normal normal 40px Sans";\n', '\tctx.fillText("TESTE", 188.898530, 117.971080);\n'])
def __init__(self): InkscapeEffect.__init__(self) self.filename = sys.argv[-1]
def setUp(self): self.element = Element() self.effect = Effect() self.document = self.effect.parse("TestFiles/unit_test_svg_element.svg") self.node = self.effect.document.getroot()
class TestSvgAbstractShape(unittest.TestCase): def returnsGnode(self, root, tag): for node in root: nodeTag = node.tag.split("}")[1] if(nodeTag == 'g'): root = node break for node in root: nodeTag = node.tag.split("}")[1] if(nodeTag == tag): return node def setUp(self): self.canvas = Canvas(0,0) self.effect = Effect() self.document = self.effect.parse("TestFiles/unit_test_svg_abstractShape.svg") self.root = self.effect.document.getroot() self.node = self.returnsGnode(self.root,"path") self.abstractShape = AbstractShape( None,self.node,self.canvas, None) def testGetStyle(self): style = self.abstractShape.getStyle() strStyle = "fill:#ff0000;fill-rule:evenodd;stroke:#000000;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" hashStyle = dict([i.split(":") for i in strStyle.split(";") if len(i)]) self.assertEqual(hashStyle,style) strStyle = "fill:ff0000;fill-rule:evenodd;stroke:#000000;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" hashStyle = dict([i.split(":") for i in strStyle.split(";") if len(i)]) self.assertNotEqual(hashStyle,style) def testSetStyle(self): canvas = Canvas(0,0) canvas.setStrokeLinejoin("miter") canvas.setStroke("#000000") canvas.setStrokeLinecap("butt") canvas.setStrokeWidth("1px") canvas.setFill("#ff0000") stringStyle =self.abstractShape.getStyle() self.abstractShape.setStyle(stringStyle) self.assertEqual(canvas.code, self.abstractShape.canvasContext.code) self.assertEqual(self.abstractShape.canvasContext.style,stringStyle) def testHasTransform(self): self.assertNotEqual(True, self.abstractShape.hasTransform()) canvas = Canvas(0,1) canvas.effect = Effect() canvas.document = canvas.effect.parse("TestFiles/unit_test_svg_abstractShape_transformado.svg") canvas.root = canvas.effect.document.getroot() canvas.node = self.returnsGnode(canvas.root,"rect") canvas.abstractShape = AbstractShape( None,canvas.node,self.canvas, None) self.assertEqual(True, canvas.abstractShape.hasTransform()) def testGetTransform(self): m11 = (float(1),float(0),float(0.3802532),float(0.92488243),0.0,0.0) canvas = Canvas(0,1) canvas.effect = Effect() canvas.document = canvas.effect.parse("TestFiles/unit_test_svg_abstractShape_transformado.svg") canvas.root = canvas.effect.document.getroot() canvas.node = self.returnsGnode(canvas.root,"rect") canvas.abstractShape = AbstractShape( None,canvas.node,self.canvas, None) vetor = canvas.abstractShape.getTransform() self.assertEqual(m11, vetor) def testHasGradient(self): canvas = Canvas(0,1) canvas.effect = Effect() canvas.document = canvas.effect.parse("TestFiles/unit_test_svg_abstractShape_transformado_GradienteLinear.svg") canvas.root = canvas.effect.document.getroot() canvas.node = self.returnsGnode(canvas.root,"path") canvas.abstractShape = AbstractShape( None,canvas.node,self.canvas, None) self.assertEqual(canvas.abstractShape.gradientHelper.hasGradient("fill"), "linear") canvas.document = canvas.effect.parse("TestFiles/unit_test_svg_abstractShape_transformado_GradienteRadial.svg") canvas.root = canvas.effect.document.getroot() canvas.node = self.returnsGnode(canvas.root,"path") canvas.abstractShape = AbstractShape( None,canvas.node,self.canvas, None) self.assertEqual(canvas.abstractShape.gradientHelper.hasGradient("fill"), "radial") self.assertNotEqual(self.abstractShape.gradientHelper.hasGradient("fill"),"linear") def testGetGradientHref(self): returnValue ="linearGradient3022" canvas = Canvas(0,1) canvas.effect = Effect() canvas.document = canvas.effect.parse("TestFiles/unit_test_svg_abstractShape_transformado_GradienteLinear.svg") canvas.root = canvas.effect.document.getroot() canvas.node = self.returnsGnode(canvas.root,"path") canvas.abstractShape = AbstractShape( None,canvas.node,self.canvas, None) self.assertEqual(returnValue,canvas.abstractShape.gradientHelper.getGradientHref("fill")) returnValue ="ovalGradient3022" self.assertNotEqual(returnValue,canvas.abstractShape.gradientHelper.getGradientHref("fill")) def testHasClip(self): canvas = Canvas(0,1) canvas.effect = Effect() canvas.document = canvas.effect.parse("TestFiles/unit_test_svg_abstractShape_transformado_Clip.svg") canvas.root = canvas.effect.document.getroot() canvas.node = self.returnsGnode(canvas.root,"path") canvas.abstractShape = AbstractShape( None,canvas.node,self.canvas, None) self.assertTrue(canvas.abstractShape.hasClip()) self.assertFalse(self.abstractShape.hasClip()) def testGetClipHref(self): returnValue = "clipPath3191" canvas = Canvas(0,1) canvas.effect = Effect() canvas.document = canvas.effect.parse("TestFiles/unit_test_svg_abstractShape_transformado_Clip.svg") canvas.root = canvas.effect.document.getroot() canvas.node = self.returnsGnode(canvas.root,"path") canvas.abstractShape = AbstractShape( None,canvas.node,self.canvas, None) self.assertEqual(canvas.abstractShape.getClipId(),returnValue) def testStart(self): canvas2 = Canvas(0,2) canvas2.write("\n// #path3033") self.abstractShape.initDraw() self.assertEqual(self.abstractShape.canvasContext.code,canvas2.code) canvas3 = Canvas(0,3) canvas3.effect = Effect() canvas3.document = canvas3.effect.parse("TestFiles/unit_test_svg_abstractShape_transformado_Clip.svg") canvas3.root = canvas3.effect.document.getroot() canvas3.node = self.returnsGnode(canvas3.root,"path") canvas3.abstractShape = AbstractShape( None,canvas3.node,canvas3, None) canvas4 = Canvas(0,4) canvas4.write("\n// #path2987") canvas4.save() canvas3.abstractShape.initDraw() self.assertEqual(canvas3.abstractShape.canvasContext.code,canvas4.code) def testDraw(self): canvas = Canvas(0,1) canvas.effect = Effect() canvas.document = canvas.effect.parse("TestFiles/unit_test_svg_abstractShape_transformado.svg") canvas.root = canvas.effect.document.getroot() canvas.node = self.returnsGnode(canvas.root,"rect") rect = Rect("rect",canvas.node,canvas, None) rect.draw() self.assertEqual(rect.canvasContext.code,['\tctx.transform(1.000000, 0.000000, 0.380253, 0.924882, 0.000000, 0.000000);\n', "\tctx.lineJoin = 'miter';\n", "\tctx.strokeStyle = 'rgb(0, 0, 0)';\n", "\tctx.lineCap = 'butt';\n", '\tctx.lineWidth = 1.012632;\n', "\tctx.fillStyle = 'rgb(0, 0, 255)';\n", '\tctx.beginPath();\n', '\tctx.moveTo(-60.184902, 299.915122);\n', '\tctx.lineTo(-60.184902, 677.860048);\n', '\tctx.quadraticCurveTo(-60.184902, 683.719660, -60.184902, 683.719660);\n', '\tctx.lineTo(431.239998, 683.719660);\n', '\tctx.quadraticCurveTo(431.239998, 683.719660, 431.239998, 677.860048);\n', '\tctx.lineTo(431.239998, 299.915122);\n', '\tctx.quadraticCurveTo(431.239998, 294.055510, 431.239998, 294.055510);\n', '\tctx.lineTo(-60.184902, 294.055510);\n', '\tctx.quadraticCurveTo(-60.184902, 294.055510, -60.184902, 299.915122);\n', '\tctx.fill();\n', '\tctx.stroke();\n']) def testEnd(self): self.abstractShape.endDraw() self.assertEqual(self.abstractShape.canvasContext.code, []) canvas1 = Canvas(0,3) canvas1.effect = Effect() canvas1.document = canvas1.effect.parse("TestFiles/unit_test_svg_abstractShape_transformado.svg") canvas1.root = canvas1.effect.document.getroot() canvas1.node = self.returnsGnode(canvas1.root,"rect") canvas1.abstractShape = AbstractShape( None,canvas1.node,canvas1, None) canvas1.abstractShape.endDraw() canvas2 = Canvas(0,2) canvas2.restore() self.assertEqual(canvas1.abstractShape.canvasContext.code, canvas2.code)
def setUp(self): self.effect = Effect() self.document = None self.effect.parse("TestFiles/unit_test_svg_Rect_WithRxRy.svg") self.node = None self.canvas = Canvas(0, 0)