@@ -302,11 +302,12 @@ class UnicodeFonts(Fonts):
302302 filenamesd should be declared as a class atribute
303303 * glyphdict: a dict used for caching of glyph specific data
304304 * fonts: a dict of facename -> fontface pairs
305- * charmaps: a dict of facename -> charmap pairs
305+ * charmaps: a dict of facename -> charmap pairs. Charmap maps character
306+ codes to glyph indices
306307 * glyphmaps: a dict of facename -> glyphmap pairs. A glyphmap is an
307308 inverted charmap
308309 * output: a string in ['Agg','SVG','PS'], coresponding to the backends
309- * index: Fontfile specific index of a glyph/char. Taken from a charmap .
310+ * index: Fontfile specific index of a glyph.
310311
311312"""
312313
@@ -324,16 +325,16 @@ def __init__(self, output='Agg'):
324325 self .fonts = dict (
325326 [ (facename , font_open (self .filenamesd [facename ])) for
326327 facename in self .facenames ])
327- # a dict of glyphindex -> charcode pairs
328+ # a dict of charcode -> glyphindex pairs
328329 self .charmaps = dict (
329330 [ (facename , self .fonts [facename ].get_charmap ())
330331 for facename in self .facenames ])
331- # a dict of charcode -> glyphindex pairs
332+ # a dict of glyphindex -> charcode pairs
332333 self .glyphmaps = {}
333334 for facename in self .facenames :
334335 charmap = self .charmaps [facename ]
335- self .glyphmaps [facename ] = dict ([(charcode , glyphind )
336- for glyphind , charcode in charmap .items ()])
336+ self .glyphmaps [facename ] = dict ([(glyphind , charcode )
337+ for charcode , glyphind in charmap .items ()])
337338 for fontface in self .fonts .values ():
338339 fontface .clear ()
339340 if self .output == 'SVG' :
@@ -578,11 +579,11 @@ def __init__(self, useSVG=False):
578579
579580 self .charmaps = dict (
580581 [ (name , self .fonts [name ].get_charmap ()) for name in self .fnames ])
581- # glyphmaps is a dict names to a dict of charcode -> glyphindex
582+ # glyphmaps is a dict names to a dict of glyphindex -> charcode
582583 self .glyphmaps = {}
583584 for name in self .fnames :
584585 cmap = self .charmaps [name ]
585- self .glyphmaps [name ] = dict ([(ccode , glyphind ) for glyphind , ccode in cmap .items ()])
586+ self .glyphmaps [name ] = dict ([(glyphind , ccode ) for ccode , glyphind in cmap .items ()])
586587
587588 for font in self .fonts .values ():
588589 font .clear ()
@@ -607,7 +608,7 @@ def _get_info (self, font, sym, fontsize, dpi):
607608
608609 if latex_to_bakoma .has_key (sym ):
609610 basename , num = latex_to_bakoma [sym ]
610- num = self .charmaps [basename ][num ]
611+ num = self .glyphmaps [basename ][num ]
611612 elif len (sym ) == 1 :
612613 num = ord (sym )
613614 else :
@@ -658,7 +659,7 @@ def render(self, ox, oy, font, sym, fontsize, dpi):
658659 basename = self .fontmap [font ]
659660 if latex_to_bakoma .has_key (sym ):
660661 basename , num = latex_to_bakoma [sym ]
661- num = self .charmaps [basename ][num ]
662+ num = self .glyphmaps [basename ][num ]
662663 elif len (sym ) == 1 :
663664 num = ord (sym )
664665 else :
@@ -693,7 +694,7 @@ def _get_num(self, font, sym):
693694 basename = self .fontmap [font ]
694695 if latex_to_bakoma .has_key (sym ):
695696 basename , num = latex_to_bakoma [sym ]
696- num = self .charmaps [basename ][num ]
697+ num = self .glyphmaps [basename ][num ]
697698 elif len (sym ) == 1 :
698699 num = ord (sym )
699700 else :
@@ -705,7 +706,7 @@ class BakomaPSFonts(Fonts):
705706 """
706707 Use the Bakoma postscript fonts for rendering to backend_ps
707708 """
708- fnames = ('cmmi10' , 'cmsy10' , 'cmex10' ,
709+ facenames = ('cmmi10' , 'cmsy10' , 'cmex10' ,
709710 'cmtt10' , 'cmr10' )
710711 # allocate a new set of fonts
711712 basepath = os .path .join ( get_data_path (), 'fonts' , 'ttf' )
@@ -721,10 +722,13 @@ def __init__(self):
721722 self .glyphd = {}
722723 self .fonts = dict (
723724 [ (name , FT2Font (os .path .join (self .basepath , name ) + '.ttf' ))
724- for name in self .fnames ])
725+ for name in self .facenames ])
725726
726- self .charmaps = dict (
727- [ (name , self .fonts [name ].get_charmap ()) for name in self .fnames ])
727+ self .glyphmaps = {}
728+ for facename in self .facenames :
729+ charmap = self .fonts [facename ].get_charmap ()
730+ self .glyphmaps [facename ] = dict ([(glyphind , charcode )
731+ for charcode , glyphind in charmap .items ()])
728732 for font in self .fonts .values ():
729733 font .clear ()
730734
@@ -741,7 +745,7 @@ def _get_info (self, font, sym, fontsize, dpi):
741745 if latex_to_bakoma .has_key (sym ):
742746 basename , num = latex_to_bakoma [sym ]
743747 sym = self .fonts [basename ].get_glyph_name (num )
744- num = self .charmaps [basename ][num ]
748+ num = self .glyphmaps [basename ][num ]
745749 elif len (sym ) == 1 :
746750 num = ord (sym )
747751 else :
@@ -812,7 +816,7 @@ def _get_filename_and_num (self, font, sym, fontsize, dpi):
812816 if latex_to_bakoma .has_key (sym ):
813817 basename , num = latex_to_bakoma [sym ]
814818 sym = self .fonts [basename ].get_glyph_name (num )
815- num = self .charmaps [basename ][num ]
819+ num = self .glyphmaps [basename ][num ]
816820 elif len (sym ) == 1 :
817821 num = ord (sym )
818822 else :
0 commit comments