コード例 #1
0
 def _get_num(self, font, sym):
     'get charcode for sym'
     basename = self.fontmap[font]
     if latex_to_bakoma.has_key(sym):
         basename, num = latex_to_bakoma[sym]
         num = self.charmaps[basename][num]
     elif len(sym) == 1:
         num = ord(sym)
     else:
         num = 0
     return num
コード例 #2
0
 def _get_num(self, font, sym):
     'get charcode for sym'
     basename = self.fontmap[font]
     if latex_to_bakoma.has_key(sym):
         basename, num = latex_to_bakoma[sym]
         num = self.charmaps[basename][num]
     elif len(sym) == 1:
         num = ord(sym)
     else:
         num = 0
     return num
コード例 #3
0
    def render(self, ox, oy, font, sym, fontsize, dpi):
        cmfont, metrics, glyph, offset = self._get_info(font, sym, fontsize, dpi)

        if not self.usingSVG:
            cmfont.draw_glyph_to_bitmap(int(ox), int(self.height - oy - metrics.ymax), glyph)
        else:
            oy += offset - 512 / 2048.0 * 10.0
            basename = self.fontmap[font]
            if latex_to_bakoma.has_key(sym):
                basename, num = latex_to_bakoma[sym]
                num = self.fonts[basename].get_charmap()[num]
            elif len(sym) == 1:
                num = ord(sym)
            else:
                num = 0
                print >> sys.stderr, 'unrecognized symbol "%s"' % sym
            self.svg_glyphs.append((basename, fontsize, num, ox, oy, metrics))
コード例 #4
0
    def _get_info (self, font, sym, fontsize, dpi):
        'load the cmfont, metrics and glyph with caching'
        key = font, sym, fontsize, dpi
        tup = self.glyphd.get(key)

        if tup is not None:
            return tup

        basename = self.fontmap[font]

        if latex_to_bakoma.has_key(sym):
            basename, num = latex_to_bakoma[sym]
            sym = self.fonts[basename].get_glyph_name(num)
            num = self.charmaps[basename][num]
        elif len(sym) == 1:
            num = ord(sym)
        else:
            num = 0
            sym = '.notdef'
            verbose.report_error('unrecognized symbol "%s, %d"' % (sym, num))

        if basename not in bakoma_fonts:
            bakoma_fonts.append(basename)
        cmfont = self.fonts[basename]
        cmfont.set_size(fontsize, dpi)
        head = cmfont.get_sfnt_table('head')
        glyph = cmfont.load_char(num)
        
        xmin, ymin, xmax, ymax = [val/64.0 for val in glyph.bbox]
        if basename == 'cmex10':
            offset = -(head['yMin']+512)/head['unitsPerEm']*10.
        else:
            offset = 0.
        metrics = Bunch(
            advance  = glyph.horiAdvance/64.0,
            height   = glyph.height/64.0,
            width    = glyph.width/64.0,
            xmin = xmin,
            xmax = xmax,
            ymin = ymin+offset,
            ymax = ymax+offset
            )

        self.glyphd[key] = basename, metrics, sym, offset
        return basename, metrics, '/'+sym, offset
コード例 #5
0
ファイル: mathtext.py プロジェクト: jtomase/matplotlib
    def _get_info (self, font, sym, fontsize, dpi):
        'load the cmfont, metrics and glyph with caching'
        key = font, sym, fontsize, dpi
        tup = self.glyphd.get(key)

        if tup is not None:
            return tup

        basename = self.fontmap[font]

        if latex_to_bakoma.has_key(sym):
            basename, num = latex_to_bakoma[sym]
            sym = self.fonts[basename].get_glyph_name(num)
            num = self.fonts[basename].get_charmap()[num]
        elif len(sym) == 1:
            num = ord(sym)
        else:
            num = 0
            sym = '.notdef'
            print >>sys.stderr, 'unrecognized symbol "%s"' % sym, num

        if basename not in bakoma_fonts:
            bakoma_fonts.append(basename)
        cmfont = self.fonts[basename]
        cmfont.set_size(fontsize, dpi)
        head = cmfont.get_sfnt_table('head')
        glyph = cmfont.load_char(num)
        
        xmin, ymin, xmax, ymax = [val/64.0 for val in glyph.bbox]
        if basename == 'cmex10':
            offset = -(head['yMin']+512)/head['unitsPerEm']*10.
        else:
            offset = 0.
        metrics = Bunch(
            advance  = glyph.horiAdvance/64.0,
            height   = glyph.height/64.0,
            width    = glyph.width/64.0,
            xmin = xmin,
            xmax = xmax,
            ymin = ymin+offset,
            ymax = ymax+offset
            )

        self.glyphd[key] = basename, metrics, sym, offset
        return basename, metrics, '/'+sym, offset
コード例 #6
0
    def _get_info(self, font, sym, fontsize, dpi):
        'load the cmfont, metrics and glyph with caching'
        key = font, sym, fontsize, dpi
        tup = self.glyphd.get(key)

        if tup is not None: return tup

        basename = self.fontmap[font]

        if latex_to_bakoma.has_key(sym):
            basename, num = latex_to_bakoma[sym]
            num = self.charmaps[basename][num]
        elif len(sym) == 1:
            num = ord(sym)
        else:
            num = 0
            raise ValueError('unrecognized symbol "%s"' % sym)

        #print sym, basename, num
        cmfont = self.fonts[basename]
        cmfont.set_size(fontsize, dpi)
        head = cmfont.get_sfnt_table('head')
        glyph = cmfont.load_char(num)

        xmin, ymin, xmax, ymax = [val / 64.0 for val in glyph.bbox]
        if basename == 'cmex10':
            offset = glyph.height / 64.0 / 2 + 256.0 / 64.0 * dpi / 72.0
            #offset = -(head['yMin']+512)/head['unitsPerEm']*10.
        else:
            offset = 0.
        metrics = Bunch(
            advance=glyph.linearHoriAdvance / 65536.0,
            height=glyph.height / 64.0,
            width=glyph.width / 64.0,
            xmin=xmin,
            xmax=xmax,
            ymin=ymin + offset,
            ymax=ymax + offset,
        )

        self.glyphd[key] = cmfont, metrics, glyph, offset
        return self.glyphd[key]
コード例 #7
0
    def _get_info(self, font, sym, fontsize, dpi):
        "load the cmfont, metrics and glyph with caching"
        key = font, sym, fontsize, dpi
        tup = self.glyphd.get(key)

        if tup is not None:
            return tup

        basename = self.fontmap[font]

        if latex_to_bakoma.has_key(sym):
            basename, num = latex_to_bakoma[sym]
            num = self.fonts[basename].get_charmap()[num]
        elif len(sym) == 1:
            num = ord(sym)
        else:
            num = 0
            verbose.report_error('unrecognized symbol "%s"' % sym)

        cmfont = self.fonts[basename]
        cmfont.set_size(fontsize, dpi)
        head = cmfont.get_sfnt_table("head")
        glyph = cmfont.load_char(num)

        xmin, ymin, xmax, ymax = [val / 64.0 for val in glyph.bbox]
        if basename == "cmex10":
            offset = glyph.height / 64.0 / 2 + 256.0 / 64.0 * dpi / 72.0
            # offset = -(head['yMin']+512)/head['unitsPerEm']*10.
        else:
            offset = 0.0
        metrics = Bunch(
            advance=glyph.horiAdvance / 64.0,
            height=glyph.height / 64.0,
            width=glyph.width / 64.0,
            xmin=xmin,
            xmax=xmax,
            ymin=ymin + offset,
            ymax=ymax + offset,
        )

        self.glyphd[key] = cmfont, metrics, glyph, offset
        return self.glyphd[key]
コード例 #8
0
    def render(self, ox, oy, font, sym, fontsize, dpi):
        cmfont, metrics, glyph, offset = \
                self._get_info(font, sym, fontsize, dpi)

        if not self.usingSVG:
            cmfont.draw_glyph_to_bitmap(int(ox),
                                        int(self.height - oy - metrics.ymax),
                                        glyph)
        else:
            oy += offset - 512 / 2048. * 10.
            basename = self.fontmap[font]
            if latex_to_bakoma.has_key(sym):
                basename, num = latex_to_bakoma[sym]
                num = self.charmaps[basename][num]
            elif len(sym) == 1:
                num = ord(sym)
            else:
                num = 0
                print >> sys.stderr, 'unrecognized symbol "%s"' % sym
            self.svg_glyphs.append((basename, fontsize, num, ox, oy, metrics))