コード例 #1
0
ファイル: TFSSvg.py プロジェクト: behnam/typefacet
def parseArgbColor(value):
    result = TFSMap()
    result.alpha = 0xFF & (value >> 24)
    result.red = 0xFF & (value >> 16)
    result.green = 0xFF & (value >> 8)
    result.blue = 0xFF & (value >> 0)
    return result
コード例 #2
0
        def createPoint(segment, t):
            result = TFSMap()
            result.t = t
            result.p, result.tangent, _, _ = segment.evaluateWithTangent(t)
#            result.angle = result.tangent.atan2()
            result.angle = normalizeRadians(result.tangent.atan2())
            return result
コード例 #3
0
 def createPoint(segment, t):
     result = TFSMap()
     result.t = t
     result.p, result.tangent, _, _ = segment.evaluateWithTangent(t)
     #            result.angle = result.tangent.atan2()
     result.angle = normalizeRadians(result.tangent.atan2())
     return result
コード例 #4
0
ファイル: TFSSvg.py プロジェクト: behnam/typefacet
def blendArgbColors(argb0, argb1, factor):
    factor = clamp01(factor)
    color0 = parseArgbColor(argb0)
    color1 = parseArgbColor(argb1)
    color = TFSMap()
    color.alpha = int((color0.alpha * (1.0 - factor)) + (color1.alpha * factor))
    color.red = int((color0.red * (1.0 - factor)) + (color1.red * factor))
    color.green = int((color0.green * (1.0 - factor)) + (color1.green * factor))
    color.blue = int((color0.blue * (1.0 - factor)) + (color1.blue * factor))
    return unparseArgbColor(color)
コード例 #5
0
    def tangentToCircle_base(self, other, tangentFunction):
        centersDiff = other.center.minus(self.center)
        centersAngle = math.atan2(centersDiff.y, centersDiff.x)
        maxAngle = centersAngle + math.pi * 0.5
        minAngle = centersAngle - math.pi * 0.5

        minDiff, _, _ = tangentFunction(minAngle)
        maxDiff, _, _ = tangentFunction(maxAngle)
        #        print 'minAngle', minAngle
        #        print 'maxAngle', maxAngle
        #        print 'minDiff', minDiff
        #        print 'maxDiff', maxDiff

        if maxDiff < minDiff:
            maxDiff, minDiff = minDiff, maxDiff
            maxAngle, minAngle = minAngle, maxAngle
#            print 'minAngle\'', minAngle
#            print 'maxAngle\'', maxAngle
#            print 'minDiff\'', minDiff
#            print 'maxDiff\'', maxDiff

        MAX_ATTEMPTS = 32
        for _ in xrange(MAX_ATTEMPTS):
            tangentAngle = (maxAngle + minAngle) * 0.5
            anglesDiff, p0, p1 = tangentFunction(tangentAngle)

            #            print
            #            print 'tangentAngle', tangentAngle
            #            print 'anglesDiff', anglesDiff

            OVAL_TO_OVAL_TANGENT_PRECISION_RADIANS = getFloatRoundingTolerance(
            )

            #            print
            #            print 'tangentAngle', tangentAngle
            #            print 'centersAngle', centersAngle
            ##            print 'tangentsAngle', tangentsAngle
            #            print 'anglesDiff', anglesDiff

            if abs(anglesDiff) < OVAL_TO_OVAL_TANGENT_PRECISION_RADIANS:
                result = TFSMap()
                result.p0 = p0
                result.p1 = p1
                result.angle = tangentAngle
                return result

            if anglesDiff > 0:
                maxAngle = tangentAngle
            else:
                minAngle = tangentAngle

        raise Exception('Did not converge')
コード例 #6
0
ファイル: TFSPoint.py プロジェクト: behnam/typefacet
def minmaxMerge(minmax0, minmax1):
    if minmax0 is None and minmax1 is None:
        raise Exception('Invalid arguments')
    if minmax0 is None:
        return minmax1
    if minmax1 is None:
        return minmax0
    result = TFSMap()
    result.minX = min(minmax0.minX, minmax1.minX)
    result.maxX = max(minmax0.maxX, minmax1.maxX)
    result.minY = min(minmax0.minY, minmax1.minY)
    result.maxY = max(minmax0.maxY, minmax1.maxY)
    return result
コード例 #7
0
ファイル: TFSOval.py プロジェクト: behnam/typefacet
    def tangentToCircle_base(self, other, tangentFunction):
        centersDiff = other.center.minus(self.center)
        centersAngle = math.atan2(centersDiff.y, centersDiff.x)
        maxAngle = centersAngle + math.pi * 0.5
        minAngle = centersAngle - math.pi * 0.5

        minDiff, _, _ = tangentFunction(minAngle)
        maxDiff, _, _ = tangentFunction(maxAngle)
#        print 'minAngle', minAngle
#        print 'maxAngle', maxAngle
#        print 'minDiff', minDiff
#        print 'maxDiff', maxDiff

        if maxDiff < minDiff:
            maxDiff, minDiff = minDiff, maxDiff
            maxAngle, minAngle = minAngle, maxAngle
#            print 'minAngle\'', minAngle
#            print 'maxAngle\'', maxAngle
#            print 'minDiff\'', minDiff
#            print 'maxDiff\'', maxDiff

        MAX_ATTEMPTS = 32
        for _ in xrange(MAX_ATTEMPTS):
            tangentAngle = (maxAngle + minAngle) * 0.5
            anglesDiff, p0, p1 = tangentFunction(tangentAngle)

#            print
#            print 'tangentAngle', tangentAngle
#            print 'anglesDiff', anglesDiff

            OVAL_TO_OVAL_TANGENT_PRECISION_RADIANS = getFloatRoundingTolerance()

#            print
#            print 'tangentAngle', tangentAngle
#            print 'centersAngle', centersAngle
##            print 'tangentsAngle', tangentsAngle
#            print 'anglesDiff', anglesDiff

            if abs(anglesDiff) < OVAL_TO_OVAL_TANGENT_PRECISION_RADIANS:
                result = TFSMap()
                result.p0 = p0
                result.p1 = p1
                result.angle = tangentAngle
                return result

            if anglesDiff > 0:
                maxAngle = tangentAngle
            else:
                minAngle = tangentAngle

        raise Exception('Did not converge')
コード例 #8
0
def readCodeBlocks():
    import tfs.common.TFSProject as TFSProject

    srcFile = os.path.abspath(os.path.join(TFSProject.findProjectRootFolder(), "data", "UnicodeCodeBlocks.yaml"))
    #    print 'srcFile', srcFile
    if not os.path.exists(srcFile) and os.path.isfile(srcFile):
        raise Exception("Missing srcFile: " + srcFile)

    with open(srcFile, "rt") as f:
        data = f.read()
    maps = yaml.load(data)

    for map in maps:
        unicodeCodeBlock = TFSMap()
        unicodeCodeBlock.blockName = map["blockName"]
        unicodeCodeBlock.blockRangeStart = int(map["blockRangeStart"][2:], 16)
        unicodeCodeBlock.blockRangeEnd = int(map["blockRangeEnd"][2:], 16)
        unicodeCodeBlocks.append(unicodeCodeBlock)
コード例 #9
0
def readCodeBlocks():
    #import tfs.common.TFSProject as TFSProject
    srcFile = os.path.abspath(
        os.path.join(project_root_folder, 'data', 'UnicodeCodeBlocks.yaml'))
    #    print 'srcFile', srcFile
    if not os.path.exists(srcFile) and os.path.isfile(srcFile):
        raise Exception('Missing srcFile: ' + srcFile)

    with open(srcFile, 'rt') as f:
        data = f.read()
    maps = yaml.load(data)

    for map in maps:
        unicodeCodeBlock = TFSMap()
        unicodeCodeBlock.blockName = map['blockName']
        unicodeCodeBlock.blockRangeStart = int(map['blockRangeStart'][2:], 16)
        unicodeCodeBlock.blockRangeEnd = int(map['blockRangeEnd'][2:], 16)
        unicodeCodeBlocks.append(unicodeCodeBlock)
コード例 #10
0
def parseArgbColor(value):
    result = TFSMap()
    result.alpha = 0xff & (value >> 24)
    result.red = 0xff & (value >> 16)
    result.green = 0xff & (value >> 8)
    result.blue = 0xff & (value >> 0)
    return result
コード例 #11
0
def minmaxPoints(points):
    result = TFSMap()
    result.minX = reduce(min, [point.x for point in points])
    result.maxX = reduce(max, [point.x for point in points])
    result.minY = reduce(min, [point.y for point in points])
    result.maxY = reduce(max, [point.y for point in points])
    return result
コード例 #12
0
def blendArgbColors(argb0, argb1, factor):
    factor = clamp01(factor)
    color0 = parseArgbColor(argb0)
    color1 = parseArgbColor(argb1)
    color = TFSMap()
    color.alpha = int((color0.alpha * (1.0 - factor)) + (color1.alpha * factor))
    color.red = int((color0.red * (1.0 - factor)) + (color1.red * factor))
    color.green = int((color0.green * (1.0 - factor)) + (color1.green * factor))
    color.blue = int((color0.blue * (1.0 - factor)) + (color1.blue * factor))
    return unparseArgbColor(color)
コード例 #13
0
def minmaxMerge(minmax0, minmax1):
    if minmax0 is None and minmax1 is None:
        raise Exception('Invalid arguments')
    if minmax0 is None:
        return minmax1
    if minmax1 is None:
        return minmax0
    result = TFSMap()
    result.minX = min(minmax0.minX, minmax1.minX)
    result.maxX = max(minmax0.maxX, minmax1.maxX)
    result.minY = min(minmax0.minY, minmax1.minY)
    result.maxY = max(minmax0.maxY, minmax1.maxY)
    return result
コード例 #14
0
def controlPointsWithSides(_left, _right, _top, _bottom):
    result = TFSMap()
    result.tl = TFSPoint(_left, _top)
    result.bl = TFSPoint(_left, _bottom)
    result.tr = TFSPoint(_right, _top)
    result.br = TFSPoint(_right, _bottom)

    result.tc = result.tl.midpoint(result.tr)
    result.bc = result.bl.midpoint(result.br)
    result.lc = result.tl.midpoint(result.bl)
    result.rc = result.tr.midpoint(result.br)

    result.left = _left
    result.right = _right
    result.top = _top
    result.bottom = _bottom
    return result
コード例 #15
0
    def tangentToCircle(self, other, isLeft, isCross=False):
        def getTangentAngleDiff(tangentAngle):
            #            tangentAngle = (maxAngle + minAngle) * 0.5
            if isLeft:
                sideAngle = tangentAngle + math.pi / 2
            else:
                sideAngle = tangentAngle - math.pi / 2

            p0 = self.evaluate(sideAngle)
            if isCross:
                otherAngle = sideAngle + math.pi * 1.0
            else:
                otherAngle = sideAngle
            p1 = other.evaluate(otherAngle)

            angle01 = p1.minus(p0).atan2()
            pTangent = self.evaluateTangent(sideAngle)
            #            print 'pTangent', pTangent
            if isLeft:
                pTangent = pTangent.invert()
#            print 'pTangent', pTangent
            pTangentAngle = pTangent.atan2()

            anglesDiff = normalizeRadiansDiff(angle01 - pTangentAngle)
            #            print 'tangentAngle', tangentAngle
            #            print 'pTangentAngle', pTangentAngle
            #            print 'angle01', angle01
            #            print 'anglesDiff', anglesDiff
            return anglesDiff, p0, p1

        centersDiff = other.center.minus(self.center)
        centersAngle = math.atan2(centersDiff.y, centersDiff.x)
        maxAngle = centersAngle + math.pi * 0.5
        minAngle = centersAngle - math.pi * 0.5

        minDiff, _, _ = getTangentAngleDiff(minAngle)
        maxDiff, _, _ = getTangentAngleDiff(maxAngle)
        #        print 'minAngle', minAngle
        #        print 'maxAngle', maxAngle
        #        print 'minDiff', minDiff
        #        print 'maxDiff', maxDiff

        if maxDiff < minDiff:
            maxDiff, minDiff = minDiff, maxDiff
            maxAngle, minAngle = minAngle, maxAngle
#            print 'minAngle\'', minAngle
#            print 'maxAngle\'', maxAngle
#            print 'minDiff\'', minDiff
#            print 'maxDiff\'', maxDiff

        MAX_ATTEMPTS = 32
        for _ in xrange(MAX_ATTEMPTS):
            tangentAngle = (maxAngle + minAngle) * 0.5
            anglesDiff, p0, p1 = getTangentAngleDiff(tangentAngle)

            #            print
            #            print 'tangentAngle', tangentAngle
            #            print 'anglesDiff', anglesDiff

            OVAL_TO_OVAL_TANGENT_PRECISION_RADIANS = getFloatRoundingTolerance(
            )
            OVAL_TO_OVAL_TANGENT_APPROXIMATION_FACTOR = 0.65
            OVAL_TO_OVAL_TANGENT_APPROXIMATION_FACTOR = 0.5

            #            print
            #            print 'tangentAngle', tangentAngle
            #            print 'centersAngle', centersAngle
            ##            print 'tangentsAngle', tangentsAngle
            #            print 'anglesDiff', anglesDiff

            if abs(anglesDiff) < OVAL_TO_OVAL_TANGENT_PRECISION_RADIANS:
                result = TFSMap()
                result.p0 = p0
                result.p1 = p1
                result.angle = tangentAngle
                return result

            if anglesDiff > 0:
                maxAngle = tangentAngle
            else:
                minAngle = tangentAngle

        raise Exception('Did not converge')
コード例 #16
0
    def getGlyphInfos(self):
        result = []
        #        glyphIndexToNameMap = {}
        glyphToCharacterMap = self.getGlyphIndexToCharacterMap()
        if self.ftFont.has_glyph_names:
            for glyphIndex in self.getGlyphIndices():
                glyphNameBuffer = ' ' * 256
                error = freetype.FT_Get_Glyph_Name(self.ftFont._FT_Face,
                                                   glyphIndex, glyphNameBuffer,
                                                   len(glyphNameBuffer) - 1)
                if error:
                    raise freetype.FT_Exception(error)

                glyphInfo = TFSMap()
                glyphInfo.glyphIndex = glyphIndex
                glyphInfo.glyphName = glyphNameBuffer.strip()[:-1]
                #                print 'glyphName', glyphIndex, glyphName, len(glyphName)
                glyphInfo.characterCode = None
                if glyphIndex in glyphToCharacterMap:
                    glyphInfo.characterCode = glyphToCharacterMap[glyphIndex]
                result.append(glyphInfo)

        else:
            for glyphIndex, characterCode in glyphToCharacterMap.items():
                glyphInfo = TFSMap()
                glyphInfo.glyphIndex = glyphIndex
                glyphInfo.glyphName = getUnicodeCharacterName(characterCode)
                glyphInfo.characterCode = characterCode
                #                glyphInfoMap[glyphIndex] = glyphInfo
                result.append(glyphInfo)

        return result
コード例 #17
0
ファイル: TFSOval.py プロジェクト: behnam/typefacet
    def tangentToCircle(self, other, isLeft, isCross=False):

        def getTangentAngleDiff(tangentAngle):
#            tangentAngle = (maxAngle + minAngle) * 0.5
            if isLeft:
                sideAngle = tangentAngle + math.pi / 2
            else:
                sideAngle = tangentAngle - math.pi / 2

            p0 = self.evaluate(sideAngle)
            if isCross:
                otherAngle = sideAngle + math.pi * 1.0
            else:
                otherAngle = sideAngle
            p1 = other.evaluate(otherAngle)

            angle01 = p1.minus(p0).atan2()
            pTangent = self.evaluateTangent(sideAngle)
#            print 'pTangent', pTangent
            if isLeft:
                pTangent = pTangent.invert()
#            print 'pTangent', pTangent
            pTangentAngle = pTangent.atan2()

            anglesDiff = normalizeRadiansDiff(angle01 - pTangentAngle)
#            print 'tangentAngle', tangentAngle
#            print 'pTangentAngle', pTangentAngle
#            print 'angle01', angle01
#            print 'anglesDiff', anglesDiff
            return anglesDiff, p0, p1

        centersDiff = other.center.minus(self.center)
        centersAngle = math.atan2(centersDiff.y, centersDiff.x)
        maxAngle = centersAngle + math.pi * 0.5
        minAngle = centersAngle - math.pi * 0.5

        minDiff, _, _ = getTangentAngleDiff(minAngle)
        maxDiff, _, _ = getTangentAngleDiff(maxAngle)
#        print 'minAngle', minAngle
#        print 'maxAngle', maxAngle
#        print 'minDiff', minDiff
#        print 'maxDiff', maxDiff

        if maxDiff < minDiff:
            maxDiff, minDiff = minDiff, maxDiff
            maxAngle, minAngle = minAngle, maxAngle
#            print 'minAngle\'', minAngle
#            print 'maxAngle\'', maxAngle
#            print 'minDiff\'', minDiff
#            print 'maxDiff\'', maxDiff

        MAX_ATTEMPTS = 32
        for _ in xrange(MAX_ATTEMPTS):
            tangentAngle = (maxAngle + minAngle) * 0.5
            anglesDiff, p0, p1 = getTangentAngleDiff(tangentAngle)

#            print
#            print 'tangentAngle', tangentAngle
#            print 'anglesDiff', anglesDiff

            OVAL_TO_OVAL_TANGENT_PRECISION_RADIANS = getFloatRoundingTolerance()
            OVAL_TO_OVAL_TANGENT_APPROXIMATION_FACTOR = 0.65
            OVAL_TO_OVAL_TANGENT_APPROXIMATION_FACTOR = 0.5

#            print
#            print 'tangentAngle', tangentAngle
#            print 'centersAngle', centersAngle
##            print 'tangentsAngle', tangentsAngle
#            print 'anglesDiff', anglesDiff

            if abs(anglesDiff) < OVAL_TO_OVAL_TANGENT_PRECISION_RADIANS:
                result = TFSMap()
                result.p0 = p0
                result.p1 = p1
                result.angle = tangentAngle
                return result

            if anglesDiff > 0:
                maxAngle = tangentAngle
            else:
                minAngle = tangentAngle

        raise Exception('Did not converge')
コード例 #18
0
ファイル: TFSPoint.py プロジェクト: behnam/typefacet
def controlPointsWithSides(_left, _right, _top, _bottom):
    result = TFSMap()
    result.tl = TFSPoint(_left, _top)
    result.bl = TFSPoint(_left, _bottom)
    result.tr = TFSPoint(_right, _top)
    result.br = TFSPoint(_right, _bottom)

    result.tc = result.tl.midpoint(result.tr)
    result.bc = result.bl.midpoint(result.br)
    result.lc = result.tl.midpoint(result.bl)
    result.rc = result.tr.midpoint(result.br)

    result.left = _left
    result.right = _right
    result.top = _top
    result.bottom = _bottom
    return result