Example #1
0
    def set_font(self, font_tuple):
        """Set the current font to that specified by FONT_TUPLE, which
        is of the form (SIZE, ITALIC?, BOLD?, TT?).  Returns the
        PostScript layer name of the font, and the font size in
        points.  """
        # we *said* we wanted a tuple
        if font_tuple is None: font_tuple = (None, None, None, None)
##      utils.debug("set_font(%s)\n" % (font_tuple,))
        set_sz, set_italic, set_bold, set_tt = font_tuple
        # get the current font and break up the tuple
        cur_sz, cur_family, cur_italic, cur_bold = self.font
        # calculate size
        new_sz = self.font_size(font_tuple)
        # calculate variable vs. fixed base name
        if set_tt: new_family = 'FONTF'
        else: new_family = 'FONTV'

        # add modifiers.  Because of the way fonts are named, always
        # add bold modifier before italics modifier, in case both are
        # present
        if set_bold: new_bold = 'B'
        else: new_bold = ''

        if set_italic: new_italic = 'I'
        else: new_italic = ''

        # save the current font specification
        self.font = (new_sz, new_family, new_italic, new_bold)

        # get the font nickname
        fontnickname, new_sz = self.get_font()

        # make sure the font object is instantiated
        if not self.fontobjs.has_key(fontnickname):
            psfontname = self.docfonts[fontnickname]
            self.fontobjs[fontnickname] = fonts.font_from_name(psfontname)
##      print fontnickname, "==>", self.fontobjs[fontnickname]
        self.tw_func = self.fontobjs[fontnickname].text_width

        self._fontsize = new_sz

        # return the PostScript font definition and the size in points
        return (fontnickname, new_sz)
Example #2
0
 def push_font_string(self, s, font):
     if not font:
         self.push_string_flowing(s)
         return
     if self._linestr:
         self.close_string()
     if not self._font.fontobjs.has_key(font):
         self._font.fontobjs[font] = fonts.font_from_name(font)
     fontobj = self._font.fontobjs[font]
     size = self.get_fontsize()
     width = fontobj.text_width(size, s)
     if self._xpos + width > self.get_pagewidth():
         self.close_line()
     if self._baseline is None:
         self._baseline = size
     else:
         self._baseline = max(self._baseline, size)
     self._linefp.write('gsave\n /%s findfont %d scalefont setfont ' %
                        (font, size))
     self._linefp.write('(%s) show\ngrestore %d 0 R\n' % (cook(s), width))
     self._xpos = self._xpos + width
Example #3
0
 def push_font_string(self, s, font):
     if not font:
         self.push_string_flowing(s)
         return
     if self._linestr:
         self.close_string()
     if not self._font.fontobjs.has_key(font):
         self._font.fontobjs[font] = fonts.font_from_name(font)
     fontobj = self._font.fontobjs[font]
     size = self.get_fontsize()
     width = fontobj.text_width(size, s)
     if self._xpos + width > self.get_pagewidth():
         self.close_line()
     if self._baseline is None:
         self._baseline = size
     else:
         self._baseline = max(self._baseline, size)
     self._linefp.write('gsave\n /%s findfont %d scalefont setfont '
                        % (font, size))
     self._linefp.write('(%s) show\ngrestore %d 0 R\n' % (cook(s), width))
     self._xpos = self._xpos + width