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) 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}
def writeParams(project, filename, masters, label=None, master=None): # TODO: make global parameter to project related and not master globalparam = None unitwidth = get_global_param(globalparam, 'unitwidth') fontsize = get_global_param(globalparam, 'fontsize') mean = get_global_param(globalparam, 'mean') cap = get_global_param(globalparam, 'cap') asc = get_global_param(globalparam, 'asc') des = get_global_param(globalparam, 'des') box = get_global_param(globalparam, 'box') ifile = open(filename, "w") # global parameters ifile.write("% parameter file \n") if label is not None: if label in [0, 1]: metapolationCD = 0 metapolation = 0 if label == 1: metapolation = 1 if label in [2, 3]: metapolation = 0 metapolationCD = 0 if label == 3: metapolationCD = 1 ifile.write("metapolation:=%.2f;\n" % metapolation) ifile.write("metapolationCD:=%.2f;\n" % metapolationCD) else: metap = Metapolation.get(label='AB', project_id=project.id) or 0 if metap: metap = metap.value ifile.write("metapolation:=%.2f;\n" % metap) metap = Metapolation.get(label='CD', project_id=project.id) if metap: metap = metap.value else: metap = 0 ifile.write("metapolationCD:=%.2f;\n" % metap) ifile.write("font_size:=%.3fpt#;\n" % fontsize) ifile.write("mean#:=%.3fpt#;\n" % mean) ifile.write("cap#:=%.3fpt#;\n" % cap) ifile.write("asc#:=%.3fpt#;\n" % asc) ifile.write("desc#:=%.3fpt#;\n" % des) ifile.write("box#:=%.3fpt#;\n" % box) ifile.write("u#:=%.3fpt#;\n" % unitwidth) lmast = masters[:] if len(lmast) < 4: lmast += [None] * (4 - len(masters)) for i, master_obj in enumerate(lmast): imlo = None if master_obj and not master: imlo = LocalParam.get(id=master_obj.idlocala) elif master: imlo = LocalParam.get(id=master.idlocala) uniqletter = chr(ord('A') + i) ifile.write("%s_px#:=%.2fpt#;\n" % (uniqletter, get_local_param(imlo, 'px'))) ifile.write("%s_width:=%.2f;\n" % (uniqletter, get_local_param(imlo, 'width'))) ifile.write("%s_space:=%.2f;\n" % (uniqletter, get_local_param(imlo, 'space'))) ifile.write("%s_spacept:=%.2fpt;\n" % (uniqletter, get_local_param(imlo, 'space'))) ifile.write("%s_xheight:=%.2f;\n" % (uniqletter, get_local_param(imlo, 'xheight'))) ifile.write("%s_capital:=%.2f;\n" % (uniqletter, get_local_param(imlo, 'capital'))) ifile.write("%s_ascender:=%.2f;\n" % (uniqletter, get_local_param(imlo, 'ascender'))) ifile.write("%s_descender:=%.2f;\n" % (uniqletter, get_local_param(imlo, 'descender'))) ifile.write("%s_skeleton#:=%.2fpt#;\n" % (uniqletter, get_local_param(imlo, 'skeleton'))) ifile.write("%s_over:=%.2fpt;\n" % (uniqletter, get_local_param(imlo, 'over'))) ifile.write("%s_jut:=%.2fpt;\n" % (uniqletter, get_local_param(imlo, 'jut'))) ifile.write("%s_slab:=%.2fpt;\n" % (uniqletter, get_local_param(imlo, 'slab'))) ifile.write("%s_bracket:=%.2fpt;\n" % (uniqletter, get_local_param(imlo, 'bracket'))) ifile.write("%s_serif_darkness:=%.2f;\n" % (uniqletter, get_local_param(imlo, 'serif_darkness'))) ifile.write("%s_slant:=%.2f;\n" % (uniqletter, get_local_param(imlo, 'slant'))) ifile.write("\n") ifile.write("input glyphs\n") ifile.write("bye\n") ifile.close()