Hi, I regularly use matplotlib on lots of systems I don't have root access to. On most of these installation of gs 8.15 is quite problematic (and buggy) and as I result using TeX with matplotlib is impractical. Additionally as all of the printers I have access to are HP made the use of embedded truetype fonts is also problematic. The combination of these two problems has made it difficult to use mpl for anything I need to print and for which I need mathtext. As a solution I've patched the mathtext library and backend_ps in order to support mathtext based upon the standard postscript Symbol font when ps.usetex = True. A function patch to CVS is attached. In addition to the expected limitations from using the standard fonts; the character spacing in my output isn't perfect. As I'm not particularly knowledgeable regarding fonts I'd appreciate some assistance in fixing this problem. Once this problem is fixed I believe that the result would be quite useful for those who want to produce portable and small (in filesize) plots without the overhead of running TeX. Nick
>>>>> "Nicholas" == Nicholas Young <su...@su...> writes: Nicholas> Hi, I regularly use matplotlib on lots of systems I Nicholas> don't have root access to. On most of these Nicholas> installation of gs 8.15 is quite problematic (and buggy) Nicholas> and as I result using TeX with matplotlib is Nicholas> impractical. Additionally as all of the printers I have Nicholas> access to are HP made the use of embedded truetype fonts Nicholas> is also problematic. The combination of these two Nicholas> problems has made it difficult to use mpl for anything I Nicholas> need to print and for which I need mathtext. Hi this looks very nice! I have to run now but I'll give you a quick tip. kerning controls the inter-letter spacing, and your Fonts class has to override "get_kern"; the base class always returns 0 def get_kern(self, font, symleft, symright, fontsize, dpi): """ Get the kerning distance for font between symleft and symright. font is one of tt, it, rm, cal or None sym is a single symbol(alphanum, punct) or a special symbol like \sigma. """ return 0 For an afm class instance, you can call get_kern_distance to get the kerning distance between two characters. >>> from afm import AFM >>> fh = file('ptmr8a.afm') >>> afm = AFM(fh) >>> afm.get_kern_dist('A', 'y') -92.0 and if I recall correctly this has to be corrected by a factor of 1000. JDH
On Wed, 2005年10月19日 at 12:08 -0500, John Hunter wrote: > Hi this looks very nice! I have to run now but I'll give you a quick > tip. kerning controls the inter-letter spacing, and your Fonts class > has to override "get_kern"; the base class always returns 0 I had missed this function - but as far as I can see it isn't actually called in the majority of cases (only where set_font is called on the parent GroupElement - which doesn't always happen in any of the common cases I've tried). Am I missing something? Nick
>>>>> "Nicholas" == Nicholas Young <su...@su...> writes: Nicholas> On Wed, 2005年10月19日 at 12:08 -0500, John Hunter wrote: >> Hi this looks very nice! I have to run now but I'll give you a >> quick tip. kerning controls the inter-letter spacing, and your >> Fonts class has to override "get_kern"; the base class always >> returns 0 Nicholas> I had missed this function - but as far as I can see it Nicholas> isn't actually called in the majority of cases (only Nicholas> where set_font is called on the parent GroupElement - Nicholas> which doesn't always happen in any of the common cases Nicholas> I've tried). Am I missing something? The Group element is the only place kerning is set, but groups are the right place. Eg \rm{hi mom} is a group. I just took a look and noticed I commented out the place where the kern is set def advance(self): 'get the horiz advance' return self.metrics.advance # how to handle cm units?+ self.kern*self.widthm It looks like I was a bit confused about how to best include the kerning information, and was experimenting by treating it as a fraction of the width of an "m". You may want to try some alternatives. But this is where you would start hacking. JDH
On Wed, 2005年10月19日 at 15:28 -0500, John Hunter wrote: > It looks like I was a bit confused about how to best include the > kerning information, and was experimenting by treating it as a > fraction of the width of an "m". You may want to try some > alternatives. But this is where you would start hacking. I've made some improvements and I think the result looks as good as it's going to using the Symbol font and without a suitable font for \cal; a revised patch is attached. In the patch I've refactored the kerning in mathtext.py and removed all kerning information from TrueType the font classes (as it wasn't being used anyway) by renaming the relevant get_kern functions. Nick
>>>>> "Nicholas" == Nicholas Young <su...@su...> writes: Nicholas> Hi, I regularly use matplotlib on lots of systems I Nicholas> don't have root access to. On most of these Nicholas> installation of gs 8.15 is quite problematic (and buggy) Nicholas> and as I result using TeX with matplotlib is Nicholas> impractical. Additionally as all of the printers I have Nicholas> access to are HP made the use of embedded truetype fonts Nicholas> is also problematic. The combination of these two Nicholas> problems has made it difficult to use mpl for anything I Nicholas> need to print and for which I need mathtext. Nicholas> As a solution I've patched the mathtext library and Nicholas> backend_ps in order to support mathtext based upon the Nicholas> standard postscript Symbol font when ps.usetex = True. Nicholas> A function patch to CVS is attached. Thanks Nick -- just committed this to CVS so it will be in the next release Checking in lib/matplotlib/mathtext.py; /cvsroot/matplotlib/matplotlib/lib/matplotlib/mathtext.py,v <-- matht\ ext.py new revision: 1.21; previous revision: 1.20 done Checking in lib/matplotlib/backends/backend_ps.py; /cvsroot/matplotlib/matplotlib/lib/matplotlib/backends/backend_ps.py,v \ <-- backend_ps.py new revision: 1.69; previous revision: 1.68 done JDH
I've made a small alteration to my code for AFM mathtext to show digits and brackets () in the roman rather than the italic font, as is normal in mathtext. The patch is attached. Nicholas
>>>>> "Nicholas" == Nicholas Young <su...@su...> writes: Nicholas> I've made a small alteration to my code for AFM mathtext Nicholas> to show digits and brackets () in the roman rather than Nicholas> the italic font, as is normal in mathtext. The patch is Nicholas> attached. Thanks Nicholas, changes in CVS. JDH