Пример #1
0
 def rasterize(cls, dom, width):
     """ generated source for method rasterize """
     imagePointer = [None]*1
     #  Rendering hints can't be set programatically, so
     #  we override defaults with a temporary stylesheet.
     css = "svg {" + "shape-rendering: geometricPrecision;" + "text-rendering:  geometricPrecision;" + "color-rendering: optimizeQuality;" + "image-rendering: optimizeQuality;" + "}"
     cssFile = File.createTempFile("batik-default-override-", ".css")
     FileUtils.writeStringToFile(cssFile, css)
     transcoderHints = TranscodingHints()
     transcoderHints.put(ImageTranscoder.KEY_XML_PARSER_VALIDATING, Boolean.FALSE)
     transcoderHints.put(ImageTranscoder.KEY_DOM_IMPLEMENTATION, SVGDOMImplementation.getDOMImplementation())
     transcoderHints.put(ImageTranscoder.KEY_DOCUMENT_ELEMENT_NAMESPACE_URI, SVGConstants.SVG_NAMESPACE_URI)
     transcoderHints.put(ImageTranscoder.KEY_DOCUMENT_ELEMENT, "svg")
     transcoderHints.put(ImageTranscoder.KEY_USER_STYLESHEET_URI, cssFile.toURI().__str__())
     transcoderHints.put(ImageTranscoder.KEY_WIDTH, float(2 * width))
     transcoderHints.put(ImageTranscoder.KEY_HEIGHT, float(2 * width))
     transcoderHints.put(ImageTranscoder.KEY_MAX_HEIGHT, float(2 * width))
     transcoderHints.put(ImageTranscoder.KEY_MAX_WIDTH, float(2 * width))
     try:
         t.setTranscodingHints(transcoderHints)
         t.transcode(input, None)
     except TranscoderException as ex:
         #  Requires Java 6
         ex.printStackTrace()
         raise IOException("Couldn't convert SVG")
     finally:
         cssFile.delete()
     return imagePointer[0]
Пример #2
0
 def main(cls, args):
     """ generated source for method main """
     if not args[0].endsWith(".kif") or len(args):
         print "Please enter the path of a .kif file as an argument."
         return
     filename = args[0]
     theGame = Game.createEphemeralGame(Game.preprocessRulesheet(FileUtils.readFileAsString(File(filename))))
     if theGame.getRules() == None or theGame.getRules().size() == 0:
         System.err.println("Problem reading the file " + filename + " or parsing the GDL.")
         return
     try:
         StaticValidator().checkValidity(theGame)
     except ValidatorException as e:
         System.err.println("GDL validation error: " + e.__str__())
         return
     transformedDescription = DeORer.run(theGame.getRules())
     newFilename = filename.substring(0, filename.lastIndexOf(".kif")) + "_DEORED.kif"
     try:
         for gdl in transformedDescription:
             out.write(gdl.__str__())
             out.newLine()
         out.close()
     except IOException as e:
         System.err.println("There was an error writing the translated GDL file " + newFilename + ".")
         e.printStackTrace()
Пример #3
0
 def getUncachedGame(self, theKey):
     """ generated source for method getUncachedGame """
     try:
         return Game.createEphemeralGame(Game.preprocessRulesheet(FileUtils.readFileAsString(File("games/test/" + theKey + ".kif"))))
     except Exception as e:
         raise RuntimeException(e)