Example #1
0
def excepthook (*args):
    tb = ''.join(traceback.format_exception(*args))
    message = ''.join(traceback.format_exception_only(*args[:2])).strip()

    fontforge.logWarning(tb.replace('%', '%%'))
    fontforge.postError('Unhandled exception',
                        message.replace('%','%%'))
Example #2
0
def OnCollabUpdate(f):
    seq = f.CollabLastSeq()
    basename = "font-" + str(seq)
    fontFileName = basename + ".ttf"
    fontJsonFileName = basename + ".json"
    fontFileOnDisk = webServerOutputDir + fontFileName
    fontJsonOnDisk = webServerOutputDir + fontJsonFileName
    fontFileURL = "http://" + myipaddr + "/" + webOutputDir + fontFileName
    
    fontforge.logWarning("Got an update!")
    fontforge.logWarning("   something about the font... name: " + str(f.fullname))
    fontforge.logWarning(" last seq: " + str(f.CollabLastSeq()))
    fontforge.logWarning("      glyph:" + str(f.CollabLastChangedName()))
    fontforge.logWarning("      code point:" + str(f.CollabLastChangedCodePoint()))
    f.generate(fontFileOnDisk)
    js = json.dumps({
            "seq": str(f.CollabLastSeq()), 
            "glyph": str(f.CollabLastChangedName()), 
            "codepoint": str(f.CollabLastChangedCodePoint()),
            "earl": str(fontFileURL),
            "end": "null" # this is simply so we dont have to manage keeping the last item with no terminating ,
            }, 
            sort_keys=True, indent=4, separators=(',', ': '))
    print js
    fi = open(fontJsonOnDisk, 'w')
    fi.write(js)
Example #3
0
def genAbhayasamp(thisFont):
  """Generate a OTF of this font with points rounded to integers"""
  systemFontsDir = '/Users/Pathum/src/github.com/mooniak/abhaya-libre-font/tests/fonts/'
  thisOTF = thisFont.fontname + ".otf"
  thisSystemFont = systemFontsDir + thisOTF
  thisFont.generate(thisOTF,flags=("round", "dummy-dsig", "PfEd-comments", "PfEd-colors", "PfEd-lookups", "PfEd-guidelines", "PfEd-background"))
  fontforge.logWarning("  Generated " + thisOTF)
  if os.path.exists(systemFontsDir):
    shutil.copy(thisOTF, thisSystemFont)
  if os.path.isfile(thisSystemFont):
    fontforge.logWarning("  Installed " + thisOTF)
Example #4
0
def genFont(thisFont):
  """Generate a TTF of this font with points rounded to integers"""
  systemFontsDir = "/home/crossland-ubuntu/.fonts/"
  thisTTF = thisFont.fontname + ".ttf"
  thisSystemFont = systemFontsDir + thisTTF
  thisFont.generate(thisTTF,flags=("round", "dummy-dsig", "PfEd-comments", "PfEd-colors", "PfEd-lookups", "PfEd-guidelines", "PfEd-background"))
  fontforge.logWarning("  Generated " + thisTTF)
  if os.path.exists(systemFontsDir):
    shutil.copy(thisTTF, thisSystemFont)
  if os.path.isfile(thisSystemFont):
    fontforge.logWarning("  Installed " + thisTTF)
Example #5
0
def nextStep(junk,glyph):
  """Roll a font forward"""
  myFont = fontforge.activeFont()
  snapShot(myFont)
  fontforge.logWarning("All done!")
#!/usr/bin/env fontforge
#
# Join the session and save the current font as /tmp/out.sfd
#
import fontforge

base=fontforge.open("../test.sfd")       
f = base.CollabSessionJoin()
fontforge.logWarning( "joined session" )

f.save("/tmp/out.sfd")

fontforge.logWarning( "script is done. See /tmp/out.sfd " )
#!/usr/bin/env fontforge

import fontforge

f = fontforge.open("../test.sfd")
fontforge.logWarning("font name: " + f.fullname)
Example #8
0
def OnCollabUpdate(f):
    fontforge.logWarning("Got an update!")
    fontforge.logWarning("   something about the font... name: " + f.fullname )
    f.generate("/tmp/out.ttf")
def note(message):
	fontforge.logWarning(str(message))
	print str(message)
Example #10
0
def genAbhaya(junk,glyph):
  """Roll a font forward"""
  myFont = fontforge.activeFont()
  genAbhayasamp(myFont)
  fontforge.logWarning("All done!")
Example #11
0
#!/usr/bin/env fontforge

#
# Start a collab session, move a few points around in the font and then exit.
#
# NOTE: The collab server will remain running after we quit
#
import fontforge

f = fontforge.open("../test.sfd")
f.CollabSessionStart()
fontforge.logWarning("started session")

##
## Create a new glyph 'C' in the test font and create a new contour in that glyph
## ... those changes are sent has updates to the original SFD
##
g = f.createChar(-1, 'C')
l = g.layers[g.activeLayer]
c = fontforge.contour()
c.moveTo(100, 100)
c.lineTo(100, 700)
c.lineTo(800, 700)
c.lineTo(800, 600)
c.lineTo(200, 600)
c.lineTo(200, 200)
c.lineTo(800, 200)
c.lineTo(800, 100)
c.lineTo(100, 100)
l += c
g.layers[g.activeLayer] = l
Example #12
0
    sViewBox = " ".join(map(str, aViewBox))
    tree.set('viewBox', sViewBox)
    treeOuter.write(anInFilename, default_namespace=ns)
    return( ET.tostring(tree) )

### argument handling
#print(argv)
fontname = argv[1].partition('.')[0]
if len(argv) > 2:
    out_path = argv[2]
else: out_path = '.'
save_path = out_path + '/' + fontname

### fontforge magic begins
f=fontforge.open(argv[1])       
fontforge.logWarning( "font name: " + f.fullname )
fontforge.logWarning( "saving..." )

try:
    os.mkdir(save_path)
except OSError: 
    pass

for g in f.glyphs():
    glyphFileName = save_path+"/"+fontname+"_"+g.glyphname
    g.export(glyphFileName+".svg")
    ### this also works for bitmaps!
    #g.export(glyphFileName+".bmp", 256)
    ### fix viewBox problem, that all of the svg's are rendered outside of their viewboxes
    writeEditedSvgXml(glyphFileName+".svg", glyphFileName+".svg")
Example #13
0
    fontforge.logWarning(" last seq: " + str(f.CollabLastSeq()))
    fontforge.logWarning("      glyph:" + str(f.CollabLastChangedName()))
    fontforge.logWarning("      code point:" + str(f.CollabLastChangedCodePoint()))
    f.generate(fontFileOnDisk)
    js = json.dumps({
            "seq": str(f.CollabLastSeq()), 
            "glyph": str(f.CollabLastChangedName()), 
            "codepoint": str(f.CollabLastChangedCodePoint()),
            "earl": str(fontFileURL),
            "end": "null" # this is simply so we dont have to manage keeping the last item with no terminating ,
            }, 
            sort_keys=True, indent=4, separators=(',', ': '))
    print js
    fi = open(fontJsonOnDisk, 'w')
    fi.write(js)

    
newfont=fontforge.font()       
f = newfont.CollabSessionJoin()
fontforge.logWarning( "Joined session, font name: " + f.fullname )

f.CollabSessionSetUpdatedCallback( OnCollabUpdate )
while True:
    f.CollabSessionRunMainLoop()
    # if keyPressed(): 
    #     break;

finalOutput = "/tmp/out-final.ttf"
f.generate(finalOutput)
fontforge.logWarning( "Left collab session, final file is at " + finalOutput )
Example #14
0
#!/usr/bin/env fontforge

#
# Start a collab session, move a few points around in the font and then exit.
#
# NOTE: The collab server will remain running after we quit
#
import fontforge

f=fontforge.open("../test.sfd")       
f.CollabSessionStart()
fontforge.logWarning( "started session" )

##
## Create a new glyph 'C' in the test font and create a new contour in that glyph
## ... those changes are sent has updates to the original SFD
##
g = f.createChar(-1,'C')
l = g.layers[g.activeLayer]
c = fontforge.contour()
c.moveTo(100,100)   
c.lineTo(100,700)   
c.lineTo(800,700)   
c.lineTo(800,600)   
c.lineTo(200,600)   
c.lineTo(200,200)   
c.lineTo(800,200)   
c.lineTo(800,100)   
c.lineTo(100,100)   
l += c
g.layers[g.activeLayer] = l
Example #15
0
#!/usr/bin/env fontforge

#
# Load the test.sfd and expand the 'A' by a magnification factor
#
import fontforge

f = fontforge.open("../test.sfd")
g = f['A']
l = g.layers[g.activeLayer]
c = l[0]

fontforge.logWarning("have glyph  : " + g.glyphname)
fontforge.logWarning("glyph has  layer count: " + str(len(g.layers)))
fontforge.logWarning("glyph has active layer: " + str(g.activeLayer))
fontforge.logWarning("layer has contour count: " + str(len(l)))
fontforge.logWarning("contour.is_quad: " + str(c.is_quadratic))
fontforge.logWarning("contour.len    : " + str(len(c)))

# double the size to make sure the user knows it!
mag = 2

for x in range(0, len(c)):
    p = c[x]
    fontforge.logWarning("old x:" + str(p.x) + " y:" + str(p.y))
    p.x = p.x * mag
    p.y = p.y * mag
    c[x] = p

for x in range(0, len(c)):
    p = c[x]
Example #16
0
def snapShot(myFont):
  fontforge.logWarning("Making a snapshot of " + myFont.fontname + " at " + myDate + "!")
  myFont.save()
  fontforge.logWarning("  Saved master file")
  fontName = myDate
  myFont.fontname = fontName
  myFont.familyname = fontName
  myFont.fullname = fontName
  myFont.appendSFNTName('English (US)', 'SubFamily', 'Medium')
  fontforge.logWarning("  Applied new name")
  mySFD = fontName + ".sfd"
  myFont.save(mySFD)
  fontforge.logWarning("  Saved as " + mySFD)
  # TODO: make sure spiros are all turned off
#  for glyph in myFont.glyphs():
#    glyph.round()
#    glyph.removeOverlap()
#    glyph.addExtrema()
#    glyph.simplify()
#    glyph.correctDirection()
  genFont(myFont)
  fontforge.logWarning("  Generated TTF and installing")
  genLTXlowercase(myFont,testString,lowercaseNonsense)
  fontforge.logWarning("  Generated LTX testdoc + PDF")
  genHTMLlowercase(myFont)
  fontforge.logWarning("  Generated HTML testdoc")
  uploadFont()
  fontforge.logWarning("  Uploaded Anth* to http://dave.lab6.com/a/")
#TODO: new test documents ideally are made by work out what glyphs are in the font, make an adhesion t from those glyphs, and then make inkscape, shoebot or context documents with that dummytext and compile the PDFs and give the option to hit p to print or any other key to finish
  myFont.revert()
  fontforge.logWarning("  Reverted to master file")
Example #17
0
#!/usr/bin/env fontforge

#
# Load the test.sfd and expand the 'A' by a magnification factor
#
import fontforge

f=fontforge.open("../test.sfd")       
g = f['A']
l = g.layers[g.activeLayer]
c = l[0]

fontforge.logWarning( "have glyph  : " + g.glyphname )
fontforge.logWarning( "glyph has  layer count: " + str(len(g.layers)))
fontforge.logWarning( "glyph has active layer: " + str(g.activeLayer) )
fontforge.logWarning( "layer has contour count: " + str(len(l)))
fontforge.logWarning( "contour.is_quad: " + str(c.is_quadratic))
fontforge.logWarning( "contour.len    : " + str(len(c)))

# double the size to make sure the user knows it!
mag = 2

for x in range(0, len(c)):
    p = c[x]
    fontforge.logWarning( "old x:" + str(p.x) + " y:" + str(p.y) )
    p.x = p.x * mag
    p.y = p.y * mag
    c[x] = p

for x in range(0, len(c)):
    p = c[x]
Example #18
0
    js = json.dumps(
        {
            "seq": str(f.CollabLastSeq()),
            "glyph": str(f.CollabLastChangedName()),
            "codepoint": str(f.CollabLastChangedCodePoint()),
            "earl": str(fontFileURL),
            "end":
            "null"  # this is simply so we dont have to manage keeping the last item with no terminating ,
        },
        sort_keys=True,
        indent=4,
        separators=(',', ': '))
    print js
    fi = open(fontJsonOnDisk, 'w')
    fi.write(js)


newfont = fontforge.font()
f = newfont.CollabSessionJoin()
fontforge.logWarning("Joined session, font name: " + f.fullname)

f.CollabSessionSetUpdatedCallback(OnCollabUpdate)
while True:
    f.CollabSessionRunMainLoop()
    # if keyPressed():
    #     break;

finalOutput = "/tmp/out-final.ttf"
f.generate(finalOutput)
fontforge.logWarning("Left collab session, final file is at " + finalOutput)
Example #19
0
    f.generate(fontFileOnDisk)
    js = json.dumps({
            "seq": str(f.CollabLastSeq()), 
            "glyph": str(f.CollabLastChangedName()), 
            "codepoint": str(f.CollabLastChangedCodePoint()),
            "earl": str(fontFileURL),
            "end": "null" # this is simply so we dont have to manage keeping the last item with no terminating ,
            }, 
            sort_keys=True, indent=4, separators=(',', ': '))
    print js
    fi = open(fontJsonOnDisk, 'w')
    fi.write(js)

    
newfont=fontforge.font()       
f = newfont.CollabSessionJoin()
fontforge.logWarning( "Joined session, font name: " + f.fullname )

openURLInBrowser( "http://localhost:8000" )

fontforge.logWarning("web-test-collab: starting up...");
f.CollabSessionSetUpdatedCallback( OnCollabUpdate )
while True:
    f.CollabSessionRunMainLoop()
    # if keyPressed(): 
    #     break;

finalOutput = "/tmp/out-final.ttf"
f.generate(finalOutput)
fontforge.logWarning( "Left collab session, final file is at " + finalOutput )
Example #20
0
#   until a key is pressed.
#
import fontforge
import select


def keyPressed():
    return select.select([sys.stdin], [], [], 0) == ([sys.stdin], [], [])


def OnCollabUpdate(f):
    fontforge.logWarning("Got an update!")
    fontforge.logWarning("   something about the font... name: " + f.fullname)
    f.generate("/tmp/out.ttf")


f = fontforge.open("test.sfd")
fontforge.logWarning("font name: " + f.fullname)
f2 = f.CollabSessionJoin()
fontforge.logWarning("joined session")
fontforge.logWarning("f2 name: " + f2.fullname)

f2.CollabSessionSetUpdatedCallback(OnCollabUpdate)
while True:
    f2.CollabSessionRunMainLoop()
    if keyPressed():
        break

f2.generate("/tmp/out-final.ttf")
fontforge.logWarning("script is done.")
Example #21
0
#!/usr/bin/env fontforge
#
# Join the session and output a TTF of the font as it is updated
#   until a key is pressed.
#
import fontforge
import select

def keyPressed():
    return select.select([sys.stdin], [], [], 0) == ([sys.stdin], [], [])

def OnCollabUpdate(f):
    fontforge.logWarning("Got an update!")
    fontforge.logWarning("   something about the font... name: " + f.fullname )
    f.generate("/tmp/out.ttf")

f=fontforge.open("test.sfd")       
fontforge.logWarning( "font name: " + f.fullname )
f2 = f.CollabSessionJoin()
fontforge.logWarning( "joined session" )
fontforge.logWarning( "f2 name: " + f2.fullname )

f2.CollabSessionSetUpdatedCallback( OnCollabUpdate )
while True:
    f2.CollabSessionRunMainLoop()
    if keyPressed(): 
        break;

f2.generate("/tmp/out-final.ttf")
fontforge.logWarning( "script is done." )
Example #22
0
def OnCollabUpdate(f):
    fontforge.logWarning("Got an update!")
    fontforge.logWarning("   something about the font... name: " + f.fullname)
    f.generate("/tmp/out.ttf")
#!/usr/bin/env fontforge
#
# Join a collab session, move a few points around in the 'C' glyph and then exit.
# NOTE: The collab server will remain running after we quit
#
import fontforge

base=fontforge.open("../test.sfd")       
f = base.CollabSessionJoin()
fontforge.logWarning( "joined session" )
fontforge.logWarning( "font name: " + f.fullname )

g = f['C']
l = g.layers[g.activeLayer]
c = l[0]

# Make the two points at the opening of the C closer together.
p = c[3]
p.y = 500
c[3] = p

p = c[6]
p.y = 300
c[6] = p

l[0] = c
g.layers[g.activeLayer] = l

fontforge.logWarning( "saving..." )
f.save("/tmp/out.sfd")
f.CollabSessionRunMainLoop()
#!/usr/bin/env fontforge

import fontforge

f=fontforge.open("../test.sfd")       
fontforge.logWarning( "font name: " + f.fullname )