Exemple #1
0
def condenseGlyph(glyph, scale=.8, stemWidth=185):
    ga, subsegments = segmentGlyph(glyph, 25)
    va, e  = glyphToMesh(ga)
    n = len(va)

    normals = edgeNormals(va,e)
    cn = va.dot(np.array([[scale, 0],[0,1]]))
    grad = mapEdges(lambda a,(p,n): normalize(p-a), cn, e)
    # ograd = mapEdges(lambda a,(p,n): normalize(p-a), va, e)

    cn[:,0] -= normals[:,0] * stemWidth * .5 * (1 - scale)
    out = recompose(cn, grad, e, smooth=.5)
    # out = recompose(out, grad, e, smooth=.1)
    out = recompose(out, grad, e, smooth=.01)

    # cornerWeights = mapEdges(lambda a,(p,n): normalize(p-a).dot(normalize(a-n)), grad, e)[:,0].reshape((-1,1))
    #     smooth = np.ones((n,1)) * .1
    #     smooth[cornerWeights < .6] = 10
    #     
    #     grad2 = quantizeGradient(grad).astype(float)
    #     grad2 = copyGradDetails(grad, grad2, e, scale=10)
    #     grad2 = mapEdges(lambda a,e: normalize(a), grad2, e)
    #     out = recompose(out, grad2, e, smooth=smooth)
    out[:,0] += 15
    out[:,1] = va[:,1]
    # out = recompose(out, grad, e, smooth=.5)
    gOut = meshToGlyph(out, ga)
    gOut = fitGlyph(glyph, gOut, subsegments)
    for i,seg in enumerate(gOut):
        gOut[i].points[0].y = glyph[i].points[0].y
    return gOut
Exemple #2
0
def italicize(glyph, angle=12, stemWidth=180, xoffset=-50):
    CURVE_CORRECTION_WEIGHT = .03
    CORNER_WEIGHT = 10
    ga, subsegments = segmentGlyph(glyph,25)
    va, e  = glyphToMesh(ga)
    n = len(va)
    grad = mapEdges(lambda a,(p,n): normalize(p-a), va, e)
    cornerWeights = mapEdges(lambda a,(p,n): normalize(p-a).dot(normalize(a-n)), grad, e)[:,0].reshape((-1,1))
    smooth = np.ones((n,1)) * CURVE_CORRECTION_WEIGHT
    
    controlPoints = findControlPointsInMesh(glyph, va, subsegments)
    smooth[controlPoints > 0] = 1
    smooth[cornerWeights < .6] = CORNER_WEIGHT
    # smooth[cornerWeights >= .9999] = 1
    
    out = va.copy()
    hascurves = False
    for c in glyph.contours:
        for s in c.segments:
            if s.type == "curve":
                hascurves = True
                break
        if hascurves:
            break
    if stemWidth > 100:
        outCorrected = skewMesh(recompose(skewMesh(out, angle * 1.6), grad, e, smooth=smooth), -angle * 1.6)
        # out = copyMeshDetails(va, out, e, 6)
    else:
        outCorrected = out
    normals = edgeNormals(out, e)
    center = va + normals * stemWidth * .4
    if stemWidth > 130:
        center[:, 0] = va[:, 0] * .7 + center[:,0] * .3
    centerSkew = skewMesh(center.dot(np.array([[.97,0],[0,1]])), angle * .9)
    out = outCorrected + (centerSkew - center)
    out[:,1] = outCorrected[:,1]
    
    smooth = np.ones((n,1)) * .1
    out = alignCorners(glyph, out, subsegments)
    out = copyMeshDetails(skewMesh(va, angle), out, e, 7, smooth=smooth)
    # grad = mapEdges(lambda a,(p,n): normalize(p-a), skewMesh(outCorrected, angle*.9), e)
    # out = recompose(out, grad, e, smooth=smooth)
    
    out = skewMesh(out, angle * .1)
    out[:,0] += xoffset
    # out[:,1] = outCorrected[:,1]
    out[va[:,1] == 0, 1] = 0
    gOut = meshToGlyph(out, ga)
    # gOut.width *= .97
    # gOut.width += 10
    # return gOut
    return fitGlyph(glyph, gOut, subsegments)