def put_font_all_glyphs(master, glyph=None, preload=False, force_update=False): gliflist = extract_gliflist_from_ufo(master, glyph=glyph, extract_first=preload) fontpath = op.join(master.get_ufo_path(), 'glyphs') glyphs = [] for ch1 in gliflist: glyphName, ext = buildfname(ch1) if not glyphName or glyphName.startswith('.') or ext not in ["glif"]: continue if force_update: glyph_obj = Glyph.get(name=glyphName, master_id=master.id) if glyph_obj: GlyphPointParam.filter(glyph_id=glyph_obj.id).delete() GlyphPoint.filter(glyph_id=glyph_obj.id).delete() Glyph.delete(glyph_obj) glif = etree.parse(op.join(fontpath, ch1)) newglyph_obj = create_glyph(glif, master) if newglyph_obj: glyphs.append(newglyph_obj.name) try: return glyphs[0] except IndexError: return
def get_glyph_points_from_db(master, glyphid): """ Returns json with information about glyphs' points including coords and point parameters. Example result: ```yaml --- width: 1680 points: - x: 12 y: 123 pointnr: 1 iszpoint: true data: width: 1680 width_new: 1490 # then list of another point parameters ``` """ # todo: move mflist to another common module glyph = Glyph.get(master_id=master.id, name=glyphid) localparam = LocalParam.get(id=master.idlocala) # this is still not fast, but it's 5 times faster than without # .options(joinedload(GlyphPoint.glyphpoint)) option, # FIXME: queries like this belong explicitly into model-land points = (GlyphPoint.filter(glyph_id=glyph.id).join( GlyphPoint.glyphpoint).options(joinedload( GlyphPoint.glyphpoint)).order_by(GlyphPoint.pointnr.asc())).all() _points = [] for point in points: param = point.glyphpoint[ 0] # FIXME: bad naming here, see comment in GlyphPointParam iszpoint = False if re.match('z(\d+)[lr]', param.pointname): iszpoint = True x = point.x if localparam: x += localparam.px params = param.as_dict() params.update({'width': glyph.width}) params.update({'width_new': glyph.width_new}) _points.append({ 'x': x, 'y': point.y, 'pointnr': point.pointnr, 'iszpoint': iszpoint, 'data': params }) return {'width': glyph.width, 'points': _points}
def get_glyph_points_from_db(master, glyphid): """ Returns json with information about glyphs' points including coords and point parameters. Example result: ```yaml --- width: 1680 points: - x: 12 y: 123 pointnr: 1 iszpoint: true data: width: 1680 width_new: 1490 # then list of another point parameters ``` """ # todo: move mflist to another common module glyph = Glyph.get(master_id=master.id, name=glyphid) points = GlyphPoint.filter(glyph_id=glyph.id) localparam = LocalParam.get(id=master.idlocala) _points = [] for point in points.order_by(GlyphPoint.pointnr.asc()): param = GlyphPointParam.get(glyphpoint_id=point.id) iszpoint = False if re.match('z(\d+)[lr]', param.pointname): iszpoint = True x = point.x if localparam: x += localparam.px params = param.as_dict() params.update({'width': glyph.width}) params.update({'width_new': glyph.width_new}) _points.append({ 'x': x, 'y': point.y, 'pointnr': point.pointnr, 'iszpoint': iszpoint, 'data': params }) return {'width': glyph.width, 'points': _points}
def get_glyph_points_from_db(master, glyphid): """ Returns json with information about glyphs' points including coords and point parameters. Example result: ```yaml --- width: 1680 points: - x: 12 y: 123 pointnr: 1 iszpoint: true data: width: 1680 width_new: 1490 # then list of another point parameters ``` """ # todo: move mflist to another common module glyph = Glyph.get(master_id=master.id, name=glyphid) points = GlyphPoint.filter(glyph_id=glyph.id) localparam = LocalParam.get(id=master.idlocala) _points = [] for point in points.order_by(GlyphPoint.pointnr.asc()): param = GlyphPointParam.get(glyphpoint_id=point.id) iszpoint = False if re.match('z(\d+)[lr]', param.pointname): iszpoint = True x = point.x if localparam: x += localparam.px params = param.as_dict() params.update({'width': glyph.width}) params.update({'width_new': glyph.width_new}) _points.append({'x': x, 'y': point.y, 'pointnr': point.pointnr, 'iszpoint': iszpoint, 'data': params}) return {'width': glyph.width, 'points': _points}