

mean ( line_features )) # Simplify, then put the vertices on rounded coordinate positions. mean ( line_features )) translate_glyph ( c, bbox, baseline = np. line_features = line_stats scale_glyph ( c, bbox, baseline = np. ascent = 600 for line, position, bbox, fname, chars in characters : c = create_char ( font, chars, fname ) # Get the linestats for this character. transform ( t )įont = basic_font () font. width = scaled_width + 2 * space t = psMat. space = 20 scaled_width = glyph_bbox - glyph_bbox c. I choose a number here that looks reasonable, # there are far more sophisticated means of doing this (like looking at the original image, # and calculating how much space there should be). transform ( t ) # Put horizontal padding around the glyph. translate ( - glyph_bbox, - glyph_bbox + (( baseline - char_bbox ) * c. boundingBox () # No matter where it is currently, take the glyph to x=0 and a y based on its positioning in # the original handwriting sample. But it is probably way off in terms of x & y, so we # need to fix up its position. full_glyph_size = - ( cap_height - baseline ) / top_ratio # We know that the scale of the glyph is now good.
#Import svg into fontforge full
descent ) # In the original pixel coordinate space, compute how big a nice full sized glyph # should be.

# Compute the proportion of the full EM that cap_height - baseline should consume. transform ( t ) def translate_glyph ( c, char_bbox, cap_height, baseline ): # Put the glyph in the middle, and move it relative to the baseline. scale ( frac_of_full_size * import_frac_1000 ) c. em frac_of_full_size = ( height / full_glyph_size ) import_frac_1000 = font. em anchor_ratio = ( top + target_baseline ) / height # pixel scale factor px_sf = ( top + target_baseline ) / font. full_glyph_size = - ( cap_height - baseline ) / top_ratio to_canvas_coord_from_px = full_glyph_size / font. NOTE: In pixel space, cap_height is smaller than baseline, so make it positive. scale_factor = ( top + target_baseline ) / ( cap_height - baseline ) glyph_ratio = ( cap_height - baseline ) / height # A nice glyph size, in pixels.

ascent top_ratio = top / ( top + target_baseline ) y_base_delta_baseline = char_bbox - baseline width, height = char_bbox - char_bbox, char_bbox - char_bbox # This is the scale factor that font forge will have used for normal glyphs. boundingBox () import_width, import_height = import_bbox - import_bbox, import_bbox - import_bbox # Note that timportOutlines doesn't guarantee glyphs will be put in any particular location, # so translate to the bottom and middle. font # Get hold of the bounding box information for the imported glyph.
#Import svg into fontforge code
On second thoughts, this function really does # need to be convoluted, so maybe the code isn't *that* bad. # With that magic ratio in hand, I now look at how much space the glyph *currently* # takes, and scale it to the full EM. # Essentially, all this function does is figure out how much # space a normal glyph takes, then looks at how much space *this* glyph takes. \n Ligature: BETTER" ))įrom _future_ import division import numpy as np import psMat def scale_glyph ( char, char_bbox, baseline, cap_height ): # TODO: The code in this function is convoluted - it can be hugely simplified. format ( uid = unique_id, woff_base64 = woff_base64, content = content ) font_preview = HTML ( html ) return font_preview font_fname = 'xkcd.woff' display ( preview_font ( font_fname, content = "Hello world - this is my first attempt. # on my system, so better isolation would be needed to turn this into a proper conda-forge recipe).Ĭonda create -c conda-forge python=2.7 pango glib freetype libxml2 pkg-config -p $ ").addEventListener('input', update_content) update_content() """.
#Import svg into fontforge install
# Install some of font-forge's dependencies (I'm confident that there are others that are already Git clone fontforge & git checkout 20161012 On OSX the build followed a fairly standard pattern:Įxport PREFIX=/Users/pelson/miniconda/envs/fontforge Now that I have all of the glyphs in vector form, I'm going use fontforge to create a font with glyphs imported from the appropriate SVG shapes.įinding a build of fontforge with python bindings that could be used in my environment proved to be a challenge, so I ended up compiling fontforge myself.

Creating a font from SVGs using fontforge ¶
