Bonsoir André and Jörg,

in the CHANGES file, there is a todo entry "SlantFont & Co". The "Co"
are the ExtendFont entry and the PaintType for outline fonts. I have
no idea what "ExtendFont" should mean -- simple scaling?

Regarding the implementation of SlantFont, I am not quite sure if the
eps and the pdf versions here are equal. They might differ if there is
a shift vector in the FontMatrix, which comes directly from the *.pfb
file. Please have a look at it.

Michael.


On 19.04.07, Michael SCHINDLER wrote:
> Revision: 2865
>           http://svn.sourceforge.net/pyx/?rev=2865&view=rev
> Author:   m-schindler
> Date:     2007-04-19 11:53:20 -0700 (Thu, 19 Apr 2007)
> 
> Log Message:
> -----------
> implemented font slanting via psfont.map
> 
> Modified Paths:
> --------------
>     trunk/pyx/pyx/dvifile.py
>     trunk/pyx/pyx/pswriter.py
>     trunk/pyx/pyx/type1font.py
> 
> Modified: trunk/pyx/pyx/dvifile.py
> ===================================================================
> --- trunk/pyx/pyx/dvifile.py  2007-04-19 15:04:38 UTC (rev 2864)
> +++ trunk/pyx/pyx/dvifile.py  2007-04-19 18:53:20 UTC (rev 2865)
> @@ -2,7 +2,7 @@
>  #
>  #
>  # Copyright (C) 2002-2006 J\xF6rg Lehmann <[EMAIL PROTECTED]>
> -# Copyright (C) 2003-2004,2006 Michael Schindler <[EMAIL PROTECTED]>
> +# Copyright (C) 2003-2004,2006,2007 Michael Schindler <[EMAIL PROTECTED]>
>  # Copyright (C) 2002-2006 Andr\xE9 Wobst <[EMAIL PROTECTED]>
>  #
>  # This file is part of PyX (http://pyx.sourceforge.net/).
> @@ -762,10 +762,14 @@
>                          raise RuntimeError("cannot find type 1 font %s" % 
> fontmapinfo.fontfile)
>                  else:
>                      fontfilename = None
> -                
> +
> +                fontslant = fontmapinfo.slantfont
> +                if fontslant is not None:
> +                    fontslant = float(fontslant)
> +
>                  # XXX we currently misuse use self.activefont as metric 
> -                font = type1font.font(fontbasefontname, fontfilename, 
> fontencoding, self.activefont)
> -        
> +                font = type1font.font(fontbasefontname, fontfilename, 
> fontencoding, fontslant, self.activefont)
> +
>                  self.activetext = type1font.text_pt(self.pos[_POS_H] * 
> self.pyxconv, -self.pos[_POS_V] * self.pyxconv, font)
>                  self.actpage.insert(self.activetext)
>              self.activetext.addchar(char)
> 
> Modified: trunk/pyx/pyx/pswriter.py
> ===================================================================
> --- trunk/pyx/pyx/pswriter.py 2007-04-19 15:04:38 UTC (rev 2864)
> +++ trunk/pyx/pyx/pswriter.py 2007-04-19 18:53:20 UTC (rev 2865)
> @@ -21,7 +21,7 @@
>  # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, 
> USA
>  
>  import cStringIO, copy, time, math
> -import bbox, style, version, type1font, unit
> +import bbox, style, version, type1font, unit, trafo
>  
>  try:
>      enumerate([])
> @@ -118,14 +118,35 @@
>                                      font.filename,
>                                      font.encoding,
>                                      chars))
> +        if font.encoding and font.slant:
> +            tmpname = font.name + "tmpunslanted"
> +            # do first the reencoding and then the slanting:
> +            enc_basename, enc_finalname = font.basefontname, tmpname
> +            slt_basename, slt_finalname = tmpname, font.name
> +        elif font.encoding:
> +            enc_basename, enc_finalname = font.basefontname, font.name
> +        elif font.slant:
> +            slt_basename, slt_finalname = font.basefontname, font.name
> +
>          if font.encoding:
>              registry.add(_ReEncodeFont)
>              registry.add(PSfontencoding(font.encoding))
> -            registry.add(PSfontreencoding(font.name,
> -                                          font.basefontname,
> -                                          font.encoding.name))
> +            registry.add(PSfontreencoding(enc_finalname, enc_basename, 
> font.encoding.name))
>  
> +        if font.slant:
> +            # we need the current fontmatrix in order to manipulate it:
> +            # for this we need to re-read the fontfile as below in
> +            # PSfontfile.ouput:
> +            # XXX Is there a better way to do this?
> +            import font.t1font as t1fontmodule
> +            t1font = t1fontmodule.T1pfbfont(font.filename)
> +            m = t1font.fontmatrixpattern.search(t1font.data1)
> +            m11, m12, m21, m22, v1, v2 = map(float, m.groups()[:6])
> +            t = trafo.trafo_pt(matrix=((1, font.slant), (0, 1)))
> +            t *= trafo.trafo_pt(matrix=((m11, m12), (m21, m22)), vector=(v1, 
> v2))
> +            registry.add(PSfontslanting(slt_finalname, slt_basename, 
> t.__str__()))
>  
> +
>  class PSfontfile(PSresource):
>  
>      """ PostScript font definition included in the prolog """
> @@ -200,6 +221,34 @@
>          encodingfile.outputPS(file, writer)
>  
>  
> +class PSfontslanting(PSresource):
> +
> +    """ PostScript font slanting directive included in the prolog """
> +
> +    def __init__(self, fontname, basefontname, matrixstring):
> +        """ include transformed font directive specified by
> +
> +        - fontname:     PostScript FontName of the new slanted font
> +        - basefontname: PostScript FontName of the original font
> +        - slant:        the value of slanting
> +        """
> +
> +        self.type = "fontslanting"
> +        self.id = self.fontname = fontname
> +        self.basefontname = basefontname
> +        self.matrixstring = matrixstring
> +
> +    def output(self, file, writer, registry):
> +        file.write("%%%%BeginProcSet: %s\n" % self.fontname)
> +        file.write("/%s findfont\n" % self.basefontname)
> +        file.write("dup length dict begin\n")
> +        file.write("{ 1 index /FID ne {def} {pop pop} ifelse } forall\n")
> +        file.write("/FontMatrix %s readonly def\n" % self.matrixstring)
> +        file.write("currentdict\n")
> +        file.write("end\n")
> +        file.write("/%s exch definefont pop\n" % self.fontname)
> +        file.write("%%EndProcSet\n")
> +
>  class PSfontreencoding(PSresource):
>  
>      """ PostScript font re-encoding directive included in the prolog """
> @@ -210,7 +259,6 @@
>          - fontname:     PostScript FontName of the new reencoded font
>          - basefontname: PostScript FontName of the original font
>          - encname:      name of the encoding
> -        - font:         a reference to the font instance (temporarily added 
> for pdf support)
>  
>          Before being able to reencode a font, you have to include the
>          encoding via a fontencoding prolog item with name=encname
> 
> Modified: trunk/pyx/pyx/type1font.py
> ===================================================================
> --- trunk/pyx/pyx/type1font.py        2007-04-19 15:04:38 UTC (rev 2864)
> +++ trunk/pyx/pyx/type1font.py        2007-04-19 18:53:20 UTC (rev 2865)
> @@ -3,6 +3,7 @@
>  #
>  # Copyright (C) 2005-2006 J\xF6rg Lehmann <[EMAIL PROTECTED]>
>  # Copyright (C) 2005-2006 Andr\xE9 Wobst <[EMAIL PROTECTED]>
> +# Copyright (C) 2007 Michael Schindler <[EMAIL PROTECTED]>
>  #
>  # This file is part of PyX (http://pyx.sourceforge.net/).
>  #
> @@ -98,10 +99,11 @@
>  
>  class font:
>  
> -    def __init__(self, basefontname, filename, encoding, metric):
> +    def __init__(self, basefontname, filename, encoding, slant, metric):
>          self.basefontname = basefontname
>          self.filename = filename
>          self.encoding = encoding
> +        self.slant = slant
>          self.metric = metric
>  
>          if encoding is None:
> @@ -109,7 +111,12 @@
>          else:
>              self.name = "%s-%s" % (basefontname, encoding.name)
>  
> +        if slant is None:
> +            self.slant = 0.0
> +        else:
> +            self.name = "%s-slanted%f" % (self.name, self.slant)
>  
> +
>  class text_pt(canvas.canvasitem):
>  
>      def __init__(self, x_pt, y_pt, font):
> @@ -141,8 +148,8 @@
>          pswriter.PSfont(self.font, self.chars, registry)
>          bbox += self.bbox()
>  
> -        if ( context.font is None or 
> -             context.font.name != self.font.name or 
> +        if ( context.font is None or
> +             context.font.name != self.font.name or
>               context.font.metric.getsize_pt() !=  
> self.font.metric.getsize_pt() ):
>              file.write("/%s %f selectfont\n" % (self.font.name, 
> self.font.metric.getsize_pt()))
>              context.font = self.font
> @@ -159,8 +166,8 @@
>          registry.add(pdfwriter.PDFfont(self.font, self.chars, writer, 
> registry))
>          bbox += self.bbox()
>  
> -        if ( context.font is None or 
> -             context.font.name != self.font.name or 
> +        if ( context.font is None or
> +             context.font.name != self.font.name or
>               context.font.metric.getsize_pt() !=  
> self.font.metric.getsize_pt() ):
>              file.write("/%s %f Tf\n" % (self.font.name, 
> self.font.metric.getsize_pt()))
>              context.font = self.font
> @@ -171,5 +178,5 @@
>              else:
>                  ascii = "\\%03o" % char
>              outstring += ascii
> -        file.write("1 0 0 1 %f %f Tm (%s) Tj\n" % (self.x_pt, self.y_pt, 
> outstring))
> +        file.write("1 0 %f 1 %f %f Tm (%s) Tj\n" % (self.font.slant, 
> self.x_pt, self.y_pt, outstring))
>  
> 
> 
> This was sent by the SourceForge.net collaborative development platform, the 
> world's largest Open Source development site.
> 
> -------------------------------------------------------------------------
> This SF.net email is sponsored by DB2 Express
> Download DB2 Express C - the FREE version of DB2 express and take
> control of your XML. No limits. Just data. Click to get it now.
> http://sourceforge.net/powerbar/db2/
> _______________________________________________
> PyX-checkins mailing list
> [EMAIL PROTECTED]
> https://lists.sourceforge.net/lists/listinfo/pyx-checkins

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
PyX-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/pyx-devel

Reply via email to