Пример #1
0
    def __init__(self, connection=None, sqlFileName=None, file=None):
        """ Relay from default connection, if provided. Loads a parses SQL script from sqlFileName or file.

        :param connection: database connection, provide in two detabases scenarios only
        :param sqlFileName: SQL file name to be loaded and parsed
        :param file: open file to load and parse script from
        """
        if not connection:
            from pygeotoolbox.database import database
            connection = database

        self.connection = connection
        self.procedures = {}
        self.procedureDecrators = {}
        self.__sqlBuffer = None
        self.setBufferSize(0)
        if file:
            if sqlFileName:
                sqlFileName = os.path.dirname(file) + os.sep + sqlFileName
            else:
                sqlFileName = changeFileExtension(file, '.sql')

        if sqlFileName:
            if os.path.exists(sqlFileName):
                self.load(sqlFileName)
            else:
                log.warning("File <%s> not found." % sqlFileName)
Пример #2
0
    def __init__(self, svgFileName, charsToBeLoaded=None):
        self.name = changeFileExtension(extractFileName(svgFileName), "")

        self.glyphs = {}
        self.defaults = Container({
            "width": 556,
            "height": None,
            "x": None,
            "y": None
        })

        log.openSection("Reading glyphs from %s" % svgFileName, log.DEBUG)
        svgData = open(svgFileName, "r").read().replace('\n', '')

        self.letters = u""
        startPos = 0
        while startPos < len(svgData):
            startPos = svgData.find('<glyph', startPos)
            if startPos >= 0:
                endPos = svgData.find("/>", startPos) + 2
                if endPos >= 0:
                    tag = svgData[startPos:endPos]
                    glyph = Glyph(tag, self)

                    if isinstance(glyph.unicode, list):
                        unicodes = glyph.unicode
                    else:
                        unicodes = [glyph.unicode]
                    for unicode in unicodes:
                        if not charsToBeLoaded or unicode in charsToBeLoaded:
                            self.letters += unicode
                            self.glyphs[unicode] = glyph
                    startPos = endPos
                else:
                    log.error("Unclosed glyph tag at %d" % startPos)
                    break
            else:
                break

        self.letters = "".join(sorted(self.letters))

        if charsToBeLoaded and len(charsToBeLoaded) <> len(self.glyphs.keys()):
            log.openSection("Not all characters found!", log.WARNING)
            log.warning("%d characters to be loaded, %d found" %
                        (len(charsToBeLoaded), len(self.glyphs.keys())))

            log.closeSection(level=log.WARNING)
        log.closeSection("%d glyphs found" % len(self.glyphs.keys()),
                         level=log.DEBUG)
Пример #3
0
def extractSVGIcon(svgFontFileName, glyphName, iconFileName=None):
    global __readers

    if not svgFontFileName in __readers:
        __readers[svgFontFileName] = SVGFontReader(svgFontFileName)

    reader = __readers[svgFontFileName]
    for glyphUnicode, glyph in reader.glyphs.iteritems():
        if glyphName == glyph.name:
            result = '<?xml version="1.0"?>\n<svg>\n\t%s\n</svg>' % glyph.glyphXMLContent.replace(
                "glyph", "path")
            if iconFileName:
                makeDirForFile(iconFileName)
                open(iconFileName, "w").write(result)
                log.debug("Saving icon '%s' --> '%s'." %
                          (glyphName, iconFileName))
            return result

    log.warning("extractSVGIcon('%s', '%s', '%s') - glyph [%s] not found." %
                (svgFontFileName, glyphName, str(iconFileName), glyphName))
    return ""
Пример #4
0
    def __init__(self, paramName, params, penPosition):
        """Reads paramName, creates vertex list and move penPosition."""
        relativePosition = paramName.islower()
        self.params = params
        self.relativePosition = relativePosition
        self.vertexes = []
        pathItemConvertors = {
            'M': self.MoveToPathItem,
            'L': self.LineToPathItem,
            'H': self.HorizontalLineToPathItem,
            'V': self.VerticalLineToPathItem,
            'Q': self.QuadraticBezierCurvePathItem,
            'T': self.SmoothQuadraticBezierCurvePathItem
        }

        if paramName.upper() in pathItemConvertors:
            self.vertexes = pathItemConvertors[paramName.upper()](
                params, relativePosition, penPosition)
        else:
            if not paramName in unknownKeys:
                import pygeotoolbox.sharedtools.log as log
                log.warning("\t\t!!! Warning " + paramName + " not found")
                unknownKeys.append(paramName)
Пример #5
0
    def saveToDatabase(self):
        from pygeotoolbox.sharedtools.fonts.fonts import fonts
        from shapely.affinity import translate
        from pygeotoolbox.database import database

        fonts.schemaNeeded()
        id, tableName = fonts.getFontInfo(self.name)
        fonts.sql.createFontTable(tableName)

        sql = ""
        dx = 0
        for key, glyph in self.glyphs.iteritems():
            shape = glyph.shape
            if shape:
                shape = translate(shape, dx, 0)
                minx, miny, maxx, maxy = shape.bounds
                dx += 1.2 * (maxx - minx)
                sql += "insert into mg_fonts.%s(unicode, name, geom) values('%s', ''%s', st_geometryfromtext('%s', 5514));\n" % (
                    tableName, key.encode('hex'), glyph.name, shape.wkt)
            else:
                log.warning("Letter '%s' has no glyph" % key)

        fonts.schemaNeeded()
        database.execute(sql)