def font_bounding_box(self): """ Return the font bounding box as a bounding_box object in regular PostScript units. """ numbers = self.fontbbox numbers = map(lambda n: n / 1000.0, numbers) return bounding_box.from_tuple(numbers)
def __init__(self, fp): """ @param fp: File pointer of the AFM file opened for reading. """ metrics.__init__(self) self.FontMetrics = parse_afm(fp) fp.close() # Create a glyph_metric object for every glyph and put it into self # indexed by its unicode code. char_metrics = self.FontMetrics["Direction"][0]["CharMetrics"] # glyph name to unicode mapping for glyph_name, info in char_metrics.by_glyph_name.items(): if self.gs_uni_re.match(glyph_name): # This may be a Ghostscript specific convention. No word # about this in the standard document. unicode_char_code = int(glyph_name[3:], 16) elif glyph_name != '.notdef': try: unicode = glyph_name_to_unicode[glyph_name] ## if unicode in self: ## warn("'{0}': glyph '{1}' is already stored for unicode " ## "{2:04x}".format(glyph_name, self[unicode].ps_name, ## unicode)) ## continue bb = bounding_box.from_tuple(info["B"]) self[unicode] = glyph_metric(info["C"], info["W0X"], glyph_name, bb) except KeyError: pass # FontEncoding to unicode mapping try: encoding_table = encoding_tables[self.encoding_scheme] try: for char_code, info in char_metrics.items(): unicode_char_code = encoding_table[char_code] self[unicode_char_code] = glyph_metric(char_code, info["W0X"], info.get("N", None), bb) except KeyError: raise KeyError("Character code not in encoding table") except KeyError: pass # Create kerning pair index try: kern_pairs = self.FontMetrics["KernData"]["KernPairs"] for pair, info in kern_pairs.iteritems(): a, b = pair key, info0, info1 = info if key == "KPH": a = char_metrics[a]['N'] b = char_metrics[b]['N'] kerning = info0 self.kerning_pairs[ ( a, b, ) ] = kerning except KeyError: pass