You can subscribe to this list here.
| 2007 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
(115) |
Aug
(120) |
Sep
(137) |
Oct
(170) |
Nov
(461) |
Dec
(263) |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 2008 |
Jan
(120) |
Feb
(74) |
Mar
(35) |
Apr
(74) |
May
(245) |
Jun
(356) |
Jul
(240) |
Aug
(115) |
Sep
(78) |
Oct
(225) |
Nov
(98) |
Dec
(271) |
| 2009 |
Jan
(132) |
Feb
(84) |
Mar
(74) |
Apr
(56) |
May
(90) |
Jun
(79) |
Jul
(83) |
Aug
(296) |
Sep
(214) |
Oct
(76) |
Nov
(82) |
Dec
(66) |
| 2010 |
Jan
(46) |
Feb
(58) |
Mar
(51) |
Apr
(77) |
May
(58) |
Jun
(126) |
Jul
(128) |
Aug
(64) |
Sep
(50) |
Oct
(44) |
Nov
(48) |
Dec
(54) |
| 2011 |
Jan
(68) |
Feb
(52) |
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
(1) |
| 2018 |
Jan
|
Feb
|
Mar
|
Apr
|
May
(1) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
|
From: <md...@us...> - 2007-08-08 16:59:20
|
Revision: 3686
http://matplotlib.svn.sourceforge.net/matplotlib/?rev=3686&view=rev
Author: mdboom
Date: 2007-08-08 09:52:44 -0700 (Wed, 08 Aug 2007)
Log Message:
-----------
Load characters without hinting for PDF output.
Modified Paths:
--------------
trunk/matplotlib/lib/matplotlib/backends/backend_pdf.py
Modified: trunk/matplotlib/lib/matplotlib/backends/backend_pdf.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/backends/backend_pdf.py 2007-08-08 16:48:48 UTC (rev 3685)
+++ trunk/matplotlib/lib/matplotlib/backends/backend_pdf.py 2007-08-08 16:52:44 UTC (rev 3686)
@@ -28,7 +28,7 @@
from matplotlib.font_manager import fontManager
from matplotlib.afm import AFM
from matplotlib.dviread import Dvi
-from matplotlib.ft2font import FT2Font, FIXED_WIDTH, ITALIC, LOAD_NO_SCALE
+from matplotlib.ft2font import FT2Font, FIXED_WIDTH, ITALIC, LOAD_NO_SCALE, LOAD_NO_HINTING
from matplotlib.mathtext import math_parse_s_pdf
from matplotlib.transforms import Bbox
from matplotlib import ttconv
@@ -530,7 +530,7 @@
def get_char_width(charcode):
unicode = decode_char(charcode)
- width = font.load_char(unicode, flags=LOAD_NO_SCALE).horiAdvance
+ width = font.load_char(unicode, flags=LOAD_NO_SCALE|LOAD_NO_HINTING).horiAdvance
return cvt(width)
widths = [ get_char_width(charcode) for charcode in range(firstchar, lastchar+1) ]
@@ -632,7 +632,7 @@
for c in characters:
ccode = ord(c)
gind = cmap.get(ccode) or 0
- glyph = font.load_char(ccode)
+ glyph = font.load_char(ccode, flags=LOAD_NO_HINTING)
# Why divided by 3.0 ??? Wish I knew... MGD
widths.append((ccode, cvt(glyph.horiAdvance) / 3.0))
cid_to_gid_map[ccode] = unichr(gind)
@@ -1240,7 +1240,7 @@
else:
font = self._get_font_ttf(prop)
self.track_characters(font, s)
- font.set_text(s, 0.0)
+ font.set_text(s, 0.0, flags=LOAD_NO_HINTING)
y += font.get_descent() / 64.0
self.file.output(Op.begin_text,
@@ -1268,7 +1268,7 @@
else:
font = self._get_font_ttf(prop)
- font.set_text(s, 0.0)
+ font.set_text(s, 0.0, flags=LOAD_NO_HINTING)
w, h = font.get_width_height()
w /= 64.0
h /= 64.0
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <md...@us...> - 2007-08-08 16:48:49
|
Revision: 3685
http://matplotlib.svn.sourceforge.net/matplotlib/?rev=3685&view=rev
Author: mdboom
Date: 2007-08-08 09:48:48 -0700 (Wed, 08 Aug 2007)
Log Message:
-----------
Removing accidentally committed debugging output.
Modified Paths:
--------------
trunk/matplotlib/lib/matplotlib/font_manager.py
Modified: trunk/matplotlib/lib/matplotlib/font_manager.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/font_manager.py 2007-08-08 16:46:54 UTC (rev 3684)
+++ trunk/matplotlib/lib/matplotlib/font_manager.py 2007-08-08 16:48:48 UTC (rev 3685)
@@ -850,13 +850,6 @@
break
verbose.report('loaded ttfcache file %s'%ttfcache)
- def flatten(d, path):
- if isinstance(d, dict):
- for key, val in d.items():
- flatten(val, path + [key])
- elif isinstance(d, str):
- print path, os.path.basename(d)
- flatten(self.ttfdict, [])
#self.ttfdict = createFontDict(self.ttffiles)
# Load AFM fonts for PostScript
@@ -935,14 +928,12 @@
fname = None
font = fontdict
- print font.keys()
if font.has_key(name):
font = font[name]
else:
verbose.report('\tfindfont failed %(name)s'%locals(), 'debug')
return None
- print font.keys()
if font.has_key(style):
font = font[style]
elif style == 'italic' and font.has_key('oblique'):
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <md...@us...> - 2007-08-08 16:46:56
|
Revision: 3684
http://matplotlib.svn.sourceforge.net/matplotlib/?rev=3684&view=rev
Author: mdboom
Date: 2007-08-08 09:46:54 -0700 (Wed, 08 Aug 2007)
Log Message:
-----------
Add support for fonts with more than 256 codepoints in PDF backend.
This currently only works when pdf.fonttype == 42. (It doesn't seem
possible to have a CID-keyed Type 3 font in PDF, so some hacky
solution will have to be developed.)
Modified Paths:
--------------
trunk/matplotlib/lib/matplotlib/backends/backend_pdf.py
Modified: trunk/matplotlib/lib/matplotlib/backends/backend_pdf.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/backends/backend_pdf.py 2007-08-08 16:44:38 UTC (rev 3683)
+++ trunk/matplotlib/lib/matplotlib/backends/backend_pdf.py 2007-08-08 16:46:54 UTC (rev 3684)
@@ -28,7 +28,7 @@
from matplotlib.font_manager import fontManager
from matplotlib.afm import AFM
from matplotlib.dviread import Dvi
-from matplotlib.ft2font import FT2Font, FIXED_WIDTH, ITALIC, LOAD_NO_SCALE, LOAD_NO_HINTING
+from matplotlib.ft2font import FT2Font, FIXED_WIDTH, ITALIC, LOAD_NO_SCALE
from matplotlib.mathtext import math_parse_s_pdf
from matplotlib.transforms import Bbox
from matplotlib import ttconv
@@ -491,124 +491,52 @@
# boxes and the like
if value < 0: return floor(value)
else: return ceil(value)
-
- # You are lost in a maze of TrueType tables, all different...
- ps_name = Name(font.get_sfnt()[(1,0,0,6)])
- pclt = font.get_sfnt_table('pclt') \
- or { 'capHeight': 0, 'xHeight': 0 }
- post = font.get_sfnt_table('post') \
- or { 'italicAngle': (0,0) }
- ff = font.face_flags
- sf = font.style_flags
-
- # Get widths for the 256 characters of PDF encoding "WinAnsiEncoding" (similar to
- # Python encoding "cp1252"). According to the PDF Reference, a simple font, based on
- # single-byte characters, can't manage more than 256 characters, contrary to a
- # composite font, based on multi-byte characters.
-
- from encodings import cp1252
- # The "decoding_map" was changed to a "decoding_table" as of Python 2.5.
- if hasattr(cp1252, 'decoding_map'):
- def decode_char(charcode):
- return cp1252.decoding_map[charcode] or 0
- else:
- def decode_char(charcode):
- return ord(cp1252.decoding_table[charcode])
-
- def get_char_width(charcode):
- unicode = decode_char(charcode)
- width = font.load_char(unicode, flags=LOAD_NO_SCALE|LOAD_NO_HINTING).horiAdvance
- return cvt(width)
-
- firstchar, lastchar = 0, 255
- widths = [ get_char_width(charcode) for charcode in range(firstchar, lastchar+1) ]
- font_bbox = [ cvt(x, nearest=False) for x in font.bbox ]
-
- widthsObject = self.reserveObject('font widths')
- fontdescObject = self.reserveObject('font descriptor')
- # TODO: "WinAnsiEncoding" could become a parameter of PdfFile. The PDF encoding
- # "WinAnsiEncoding" matches the Python enconding "cp1252" used in method
- # RendererPdf.draw_text and RendererPdf.get_text_width_height to encode Unicode strings.
- fontdict = { 'Type': Name('Font'),
- 'BaseFont': ps_name,
- 'FirstChar': firstchar,
- 'LastChar': lastchar,
- 'Widths': widthsObject,
- 'FontDescriptor': fontdescObject }
-
- if fonttype == 3:
+
+ def embedTTFType3(font, characters, descriptor):
+ """The Type 3-specific part of embedding a Truetype font"""
+ widthsObject = self.reserveObject('font widths')
+ fontdescObject = self.reserveObject('font descriptor')
+ fontdictObject = self.reserveObject('font dictionary')
charprocsObject = self.reserveObject('character procs')
differencesArray = []
- fontdict['Subtype'] = Name('Type3')
- fontdict['Name'] = ps_name
- fontdict['FontBBox'] = font_bbox
- fontdict['FontMatrix'] = [ .001, 0, 0, .001, 0, 0 ]
- fontdict['CharProcs'] = charprocsObject
- fontdict['Encoding'] = {
- 'Type': Name('Encoding'),
- 'Differences': differencesArray}
- elif fonttype == 42:
- fontdict['Subtype'] = Name('TrueType')
- fontdict['Encoding'] = Name('WinAnsiEncoding')
+ firstchar, lastchar = 0, 255
+
+ fontdict = {
+ 'Type' : Name('Font'),
+ 'BaseFont' : ps_name,
+ 'FirstChar' : firstchar,
+ 'LastChar' : lastchar,
+ 'FontDescriptor' : fontdescObject,
+ 'Subtype' : Name('Type3'),
+ 'Name' : descriptor['FontName'],
+ 'FontBBox' : [cvt(x, nearest=False) for x in font.bbox],
+ 'FontMatrix' : [ .001, 0, 0, .001, 0, 0 ],
+ 'CharProcs' : charprocsObject,
+ 'Encoding' : {
+ 'Type' : Name('Encoding'),
+ 'Differences' : differencesArray},
+ 'Widths' : widthsObject
+ }
+ # Make the "Widths" array
+ from encodings import cp1252
+ # The "decoding_map" was changed to a "decoding_table" as of Python 2.5.
+ if hasattr(cp1252, 'decoding_map'):
+ def decode_char(charcode):
+ return cp1252.decoding_map[charcode] or 0
+ else:
+ def decode_char(charcode):
+ return ord(cp1252.decoding_table[charcode])
- flags = 0
- symbolic = False #ps_name.name in ('Cmsy10', 'Cmmi10', 'Cmex10')
- if ff & FIXED_WIDTH: flags |= 1 << 0
- if 0: flags |= 1 << 1 # TODO: serif
- if symbolic: flags |= 1 << 2
- else: flags |= 1 << 5
- if sf & ITALIC: flags |= 1 << 6
- if 0: flags |= 1 << 16 # TODO: all caps
- if 0: flags |= 1 << 17 # TODO: small caps
- if 0: flags |= 1 << 18 # TODO: force bold
+ def get_char_width(charcode):
+ unicode = decode_char(charcode)
+ width = font.load_char(unicode, flags=LOAD_NO_SCALE).horiAdvance
+ return cvt(width)
- descriptor = {
- 'Type': Name('FontDescriptor'),
- 'FontName': ps_name,
- 'Flags': flags,
- 'FontBBox': [ cvt(x, nearest=False) for x in font.bbox ],
- 'Ascent': cvt(font.ascender, nearest=False),
- 'Descent': cvt(font.descender, nearest=False),
- 'CapHeight': cvt(pclt['capHeight'], nearest=False),
- 'XHeight': cvt(pclt['xHeight']),
- 'ItalicAngle': post['italicAngle'][1], # ???
- 'MaxWidth': max(widths),
- 'StemV': 0 # ???
- }
+ widths = [ get_char_width(charcode) for charcode in range(firstchar, lastchar+1) ]
+ descriptor['MaxWidth'] = max(widths)
- if fonttype == 42:
- descriptor['FontFile2'] = self.reserveObject('font file')
-
- # Other FontDescriptor keys include:
- # /FontFamily /Times (optional)
- # /FontStretch /Normal (optional)
- # /FontFile (stream for type 1 font)
- # /CharSet (used when subsetting type1 fonts)
-
- # Make an Identity-H encoded CID font for CM fonts? (Doesn't quite work)
- if False:
- del fontdict['Widths'], fontdict['FontDescriptor'], \
- fontdict['LastChar'], fontdict['FirstChar']
-
- fontdict['Subtype'] = Name('Type0')
- fontdict['Encoding'] = Name('Identity-H')
- fontdict2Object = self.reserveObject('descendant font')
- fontdict['DescendantFonts'] = [ fontdict2Object ]
- # TODO: fontdict['ToUnicode']
- fontdict2 = { 'Type': Name('Font'),
- 'Subtype': Name('CIDFontType2'),
- 'BaseFont': ps_name,
- 'W': widthsObject,
- 'CIDSystemInfo': { 'Registry': 'Adobe',
- 'Ordering': 'Identity',
- 'Supplement': 0 },
- 'FontDescriptor': fontdescObject }
- self.writeObject(fontdict2Object, fontdict2)
-
- widths = [ firstchar, widths ]
-
- if fonttype == 3:
+ # Make the "Differences" array
cmap = font.get_charmap()
glyph_ids = []
differences = []
@@ -626,6 +554,8 @@
differencesArray.append(Name(name))
last_c = c
+ # Make the charprocs array (using ttconv for the
+ # actual outlines)
rawcharprocs = ttconv.get_pdf_charprocs(filename, glyph_ids)
charprocs = {}
charprocsRef = {}
@@ -637,13 +567,52 @@
self.currentstream.write(stream)
self.endStream()
charprocs[charname] = charprocObject
+
+ # Write everything out
+ self.writeObject(fontdictObject, fontdict)
+ self.writeObject(fontdescObject, descriptor)
+ self.writeObject(widthsObject, widths)
self.writeObject(charprocsObject, charprocs)
- elif fonttype == 42:
+ return fontdictObject
+
+ def embedTTFType42(font, characters, descriptor):
+ """The Type 42-specific part of embedding a Truetype font"""
+ fontdescObject = self.reserveObject('font descriptor')
+ cidFontDictObject = self.reserveObject('CID font dictionary')
+ type0FontDictObject = self.reserveObject('Type 0 font dictionary')
+ cidToGidMapObject = self.reserveObject('CIDToGIDMap stream')
+ fontfileObject = self.reserveObject('font file stream')
+ wObject = self.reserveObject('Type 0 widths')
+
+ cidFontDict = {
+ 'Type' : Name('Font'),
+ 'Subtype' : Name('CIDFontType2'),
+ 'BaseFont' : ps_name,
+ 'CIDSystemInfo' : {
+ 'Registry' : 'Adobe',
+ 'Ordering' : 'Identity',
+ 'Supplement' : 0 },
+ 'FontDescriptor' : fontdescObject,
+ 'W' : wObject,
+ 'CIDToGIDMap' : cidToGidMapObject
+ }
+
+ type0FontDict = {
+ 'Type' : Name('Font'),
+ 'Subtype' : Name('Type0'),
+ 'BaseFont' : ps_name,
+ 'Encoding' : Name('Identity-H'),
+ 'DescendantFonts' : [cidFontDictObject]
+ }
+
+ # Make fontfile stream
+ descriptor['FontFile2'] = fontfileObject
length1Object = self.reserveObject('decoded length of a font')
- self.beginStream(descriptor['FontFile2'].id,
- self.reserveObject('length of font stream'),
- {'Length1': length1Object})
+ self.beginStream(
+ fontfileObject.id,
+ self.reserveObject('length of font stream'),
+ {'Length1': length1Object})
fontfile = open(filename, 'rb')
length1 = 0
while True:
@@ -655,13 +624,92 @@
self.endStream()
self.writeObject(length1Object, length1)
- fontdictObject = self.reserveObject('font dictionary')
- self.writeObject(fontdictObject, fontdict)
- self.writeObject(widthsObject, widths)
- self.writeObject(fontdescObject, descriptor)
+ # Make the 'W' (Widths) array and the CidToGidMap at the same time
+ cid_to_gid_map = [u'\u0000'] * 65536
+ cmap = font.get_charmap()
+ widths = []
+ max_ccode = 0
+ for c in characters:
+ ccode = ord(c)
+ gind = cmap.get(ccode) or 0
+ glyph = font.load_char(ccode)
+ # Why divided by 3.0 ??? Wish I knew... MGD
+ widths.append((ccode, cvt(glyph.horiAdvance) / 3.0))
+ cid_to_gid_map[ccode] = unichr(gind)
+ max_ccode = max(ccode, max_ccode)
+ widths.sort()
+ cid_to_gid_map = cid_to_gid_map[:max_ccode + 1]
+
+ last_ccode = -2
+ w = []
+ max_width = 0
+ for ccode, width in widths:
+ if ccode != last_ccode + 1:
+ w.append(ccode)
+ w.append([width])
+ else:
+ w[-1].append(width)
+ max_width = max(max_width, width)
+ last_ccode = ccode
- return fontdictObject
+ # CIDToGIDMap stream
+ cid_to_gid_map = "".join(cid_to_gid_map).encode("utf-16be")
+ self.beginStream(cidToGidMapObject.id,
+ None,
+ {'Length': len(cid_to_gid_map)})
+ self.currentstream.write(cid_to_gid_map)
+ self.endStream()
+ descriptor['MaxWidth'] = max_width
+
+ # Write everything out
+ self.writeObject(cidFontDictObject, cidFontDict)
+ self.writeObject(type0FontDictObject, type0FontDict)
+ self.writeObject(fontdescObject, descriptor)
+ self.writeObject(wObject, w)
+
+ return type0FontDictObject
+
+ # Beginning of main embedTTF function...
+
+ # You are lost in a maze of TrueType tables, all different...
+ ps_name = Name(font.get_sfnt()[(1,0,0,6)])
+ pclt = font.get_sfnt_table('pclt') \
+ or { 'capHeight': 0, 'xHeight': 0 }
+ post = font.get_sfnt_table('post') \
+ or { 'italicAngle': (0,0) }
+ ff = font.face_flags
+ sf = font.style_flags
+
+ flags = 0
+ symbolic = False #ps_name.name in ('Cmsy10', 'Cmmi10', 'Cmex10')
+ if ff & FIXED_WIDTH: flags |= 1 << 0
+ if 0: flags |= 1 << 1 # TODO: serif
+ if symbolic: flags |= 1 << 2
+ else: flags |= 1 << 5
+ if sf & ITALIC: flags |= 1 << 6
+ if 0: flags |= 1 << 16 # TODO: all caps
+ if 0: flags |= 1 << 17 # TODO: small caps
+ if 0: flags |= 1 << 18 # TODO: force bold
+
+ descriptor = {
+ 'Type' : Name('FontDescriptor'),
+ 'FontName' : ps_name,
+ 'Flags' : flags,
+ 'FontBBox' : [ cvt(x, nearest=False) for x in font.bbox ],
+ 'Ascent' : cvt(font.ascender, nearest=False),
+ 'Descent' : cvt(font.descender, nearest=False),
+ 'CapHeight' : cvt(pclt['capHeight'], nearest=False),
+ 'XHeight' : cvt(pclt['xHeight']),
+ 'ItalicAngle' : post['italicAngle'][1], # ???
+ 'StemV' : 0 # ???
+ }
+
+ if fonttype == 3:
+ return embedTTFType3(font, characters, descriptor)
+ elif fonttype == 42:
+ return embedTTFType42(font, characters, descriptor)
+
def alphaState(self, alpha):
"""Return name of an ExtGState that sets alpha to the given value"""
@@ -1113,12 +1161,7 @@
self.file.output(self.file.fontName(fontname), fontsize,
Op.selectfont)
prev_font = fontname, fontsize
-
- if num < 256:
- string = chr(num)
- else:
- string = "?"
- self.file.output(string, Op.show)
+ self.file.output(self.encode_string(unichr(num)), Op.show)
self.file.output(Op.end_text)
for record in pswriter:
@@ -1178,12 +1221,14 @@
self.draw_polygon(boxgc, gc._rgb,
((x1,y1), (x2,y2), (x3,y3), (x4,y4)))
+ def encode_string(self, s):
+ if rcParams['pdf.fonttype'] == 42:
+ return s.encode('utf-16be', 'replace')
+ return s.encode('cp1252', 'replace')
+
def draw_text(self, gc, x, y, s, prop, angle, ismath=False):
# TODO: combine consecutive texts into one BT/ET delimited section
- if isinstance(s, unicode):
- s = s.encode('cp1252', 'replace')
-
if ismath: return self.draw_mathtext(gc, x, y, s, prop, angle)
self.check_gc(gc, gc._rgb)
@@ -1195,7 +1240,7 @@
else:
font = self._get_font_ttf(prop)
self.track_characters(font, s)
- font.set_text(s, 0.0, flags=LOAD_NO_HINTING)
+ font.set_text(s, 0.0)
y += font.get_descent() / 64.0
self.file.output(Op.begin_text,
@@ -1204,7 +1249,8 @@
Op.selectfont)
self._setup_textpos(x, y, angle)
- self.file.output(s, Op.show, Op.end_text)
+
+ self.file.output(self.encode_string(s), Op.show, Op.end_text)
def get_text_width_height(self, s, prop, ismath):
if isinstance(s, unicode):
@@ -1222,7 +1268,7 @@
else:
font = self._get_font_ttf(prop)
- font.set_text(s, 0.0, flags=LOAD_NO_HINTING)
+ font.set_text(s, 0.0)
w, h = font.get_width_height()
w /= 64.0
h /= 64.0
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <md...@us...> - 2007-08-08 16:44:52
|
Revision: 3683
http://matplotlib.svn.sourceforge.net/matplotlib/?rev=3683&view=rev
Author: mdboom
Date: 2007-08-08 09:44:38 -0700 (Wed, 08 Aug 2007)
Log Message:
-----------
Improve font manager so default font names like "serif", "sans-serif"
etc. are looked for across all fonts in that mapping, not just a
single hard-coded one.
Add DejaVu fonts as an alternative to Vera fonts if present.
Fix how mathtext non-Computer Modern fonts are specified.
Modified Paths:
--------------
trunk/matplotlib/lib/matplotlib/font_manager.py
trunk/matplotlib/lib/matplotlib/rcsetup.py
Modified: trunk/matplotlib/lib/matplotlib/font_manager.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/font_manager.py 2007-08-07 17:47:30 UTC (rev 3682)
+++ trunk/matplotlib/lib/matplotlib/font_manager.py 2007-08-08 16:44:38 UTC (rev 3683)
@@ -477,24 +477,6 @@
except: continue
add_filename(fontdict, prop, fpath)
-
- # !!!! Default font algorithm needs improvement
- if prop.name.lower() in ['bitstream vera serif', 'times']:
- prop.name = 'serif'
- add_filename(fontdict, prop, fpath)
- elif prop.name.lower() in ['bitstream vera sans', 'helvetica']:
- prop.name = 'sans-serif'
- add_filename(fontdict, prop, fpath)
- elif prop.name.lower() in ['zapf chancery', 'itc zapf chancery']:
- prop.name = 'cursive'
- add_filename(fontdict, prop, fpath)
- elif prop.name.lower() in ['western', 'itc avant garde gothic']:
- prop.name = 'fantasy'
- add_filename(fontdict, prop, fpath)
- elif prop.name.lower() in ['bitstream vera sans mono', 'courier']:
- prop.name = 'monospace'
- add_filename(fontdict, prop, fpath)
-
return fontdict
def setWeights(font):
@@ -868,6 +850,13 @@
break
verbose.report('loaded ttfcache file %s'%ttfcache)
+ def flatten(d, path):
+ if isinstance(d, dict):
+ for key, val in d.items():
+ flatten(val, path + [key])
+ elif isinstance(d, str):
+ print path, os.path.basename(d)
+ flatten(self.ttfdict, [])
#self.ttfdict = createFontDict(self.ttffiles)
# Load AFM fonts for PostScript
@@ -928,74 +917,99 @@
else:
fontdict = self.ttfdict
- name = prop.get_family()[0]
- style = prop.get_style()
- variant = prop.get_variant()
- weight = weight_as_number(prop.get_weight())
- stretch = prop.get_stretch()
- size = str(prop.get_size_in_points())
+ original_name = prop.get_family()[0]
+ style = prop.get_style()
+ variant = prop.get_variant()
+ weight = weight_as_number(prop.get_weight())
+ stretch = prop.get_stretch()
+ size = str(prop.get_size_in_points())
- try:
- fname = fontdict[name][style][variant][weight][stretch][size]
- verbose.report('\tfindfont cached %(name)s, %(style)s, %(variant)s, %(weight)s, %(stretch)s, %(size)s'%locals(), 'debug')
- verbose.report('findfont returning %s'%fname, 'debug')
- return fname
- except KeyError:
- pass
+ def lookup_name(name):
+ try:
+ fname = fontdict[name][style][variant][weight][stretch][size]
+ verbose.report('\tfindfont cached %(name)s, %(style)s, %(variant)s, %(weight)s, %(stretch)s, %(size)s'%locals(), 'debug')
+ verbose.report('findfont returning %s'%fname, 'debug')
+ return fname
+ except KeyError:
+ pass
- for name in prop.get_family():
+ fname = None
font = fontdict
+ print font.keys()
if font.has_key(name):
font = font[name]
else:
verbose.report('\tfindfont failed %(name)s'%locals(), 'debug')
- continue
+ return None
+ print font.keys()
if font.has_key(style):
font = font[style]
- elif style == 'italics' and font.has_key('oblique'):
+ elif style == 'italic' and font.has_key('oblique'):
font = font['oblique']
+ elif style == 'oblique' and font.has_key('italic'):
+ font = font['italic']
else:
verbose.report('\tfindfont failed %(name)s, %(style)s'%locals(), 'debug')
- continue
+ return None
if font.has_key(variant):
font = font[variant]
else:
verbose.report('\tfindfont failed %(name)s, %(style)s, %(variant)s'%locals(), 'debug')
- continue
+ return None
if not font.has_key(weight):
setWeights(font)
font = font[weight]
- # !!!! need improvement
if font.has_key(stretch):
- font = font[stretch]
- else:
- verbose.report('\tfindfont failed %(name)s, %(style)s, %(variant)s %(weight)s, %(stretch)s'%locals(), 'debug')
- continue
+ stretch_font = font[stretch]
+ if stretch_font.has_key('scalable'):
+ fname = stretch_font['scalable']
+ elif stretch_font.has_key(size):
+ fname = stretch_font[size]
- if font.has_key('scalable'):
- fname = font['scalable']
- elif font.has_key(size):
- fname = font[size]
- else:
- verbose.report('\tfindfont failed %(name)s, %(style)s, %(variant)s %(weight)s, %(stretch)s, %(size)s'%locals(), 'debug')
- continue
+ if fname is None:
+ for val in font.values():
+ if val.has_key('scalable'):
+ fname = val['scalable']
+ break
- fontkey = FontKey(name, style, variant, weight, stretch, size)
- add_filename(fontdict, fontkey, fname)
- verbose.report('\tfindfont found %(name)s, %(style)s, %(variant)s %(weight)s, %(stretch)s, %(size)s'%locals(), 'debug')
- verbose.report('findfont returning %s'%fname, 'debug')
+ if fname is None:
+ for val in font.values():
+ if val.has_key(size):
+ fname = val[size]
+ break
+ if fname is None:
+ verbose.report('\tfindfont failed %(name)s, %(style)s, %(variant)s %(weight)s, %(stretch)s'%locals(), 'debug')
+ else:
+ fontkey = FontKey(original_name, style, variant, weight, stretch, size)
+ add_filename(fontdict, fontkey, fname)
+ verbose.report('\tfindfont found %(name)s, %(style)s, %(variant)s %(weight)s, %(stretch)s, %(size)s'%locals(), 'debug')
+ verbose.report('findfont returning %s'%fname, 'debug')
return fname
- fontkey = FontKey(name, style, variant, weight, stretch, size)
- add_filename(fontdict, fontkey, self.defaultFont)
- verbose.report('Could not match %s, %s, %s. Returning %s' % (name, style, variant, self.defaultFont))
+ font_family_aliases = ['serif', 'sans-serif', 'cursive', 'fantasy', 'monospace']
+
+ for name in prop.get_family():
+ if name in font_family_aliases:
+ for name2 in rcParams['font.' + name]:
+ fname = lookup_name(name2)
+ if fname:
+ break
+ else:
+ fname = lookup_name(name)
+ if fname:
+ break
- return self.defaultFont
+ if not fname:
+ fontkey = FontKey(original_name, style, variant, weight, stretch, size)
+ add_filename(fontdict, fontkey, self.defaultFont)
+ verbose.report('Could not match %s, %s, %s. Returning %s' % (name, style, variant, self.defaultFont))
+ return self.defaultFont
+ return fname
def _get_afm_font_dict(self):
cache_message = "Saving AFM font cache for PS and PDF backends to %s.\n" \
Modified: trunk/matplotlib/lib/matplotlib/rcsetup.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/rcsetup.py 2007-08-07 17:47:30 UTC (rev 3682)
+++ trunk/matplotlib/lib/matplotlib/rcsetup.py 2007-08-08 16:44:38 UTC (rev 3683)
@@ -334,21 +334,24 @@
'font.stretch' : ['normal', str], #
'font.weight' : ['normal', str], #
'font.size' : [12.0, validate_float], #
- 'font.serif' : [['Bitstream Vera Serif','New Century Schoolbook',
- 'Century Schoolbook L','Utopia','ITC Bookman',
- 'Bookman','Nimbus Roman No9 L','Times New Roman',
- 'Times','Palatino','Charter','serif'],
+ 'font.serif' : [['Bitstream Vera Serif', 'DejaVu Serif',
+ 'New Century Schoolbook', 'Century Schoolbook L',
+ 'Utopia', 'ITC Bookman', 'Bookman',
+ 'Nimbus Roman No9 L','Times New Roman',
+ 'Times','Palatino','Charter','serif'],
validate_stringlist],
- 'font.sans-serif' : [['Bitstream Vera Sans','Lucida Grande','Verdana',
- 'Geneva','Lucid','Arial','Helvetica','Avant Garde',
- 'sans-serif'], validate_stringlist],
+ 'font.sans-serif' : [['Bitstream Vera Sans', 'DejaVu Sans',
+ 'Lucida Grande', 'Verdana', 'Geneva', 'Lucid',
+ 'Arial', 'Helvetica', 'Avant Garde', 'sans-serif'],
+ validate_stringlist],
'font.cursive' : [['Apple Chancery','Textile','Zapf Chancery',
'Sand','cursive'], validate_stringlist],
'font.fantasy' : [['Comic Sans MS','Chicago','Charcoal','Impact'
'Western','fantasy'], validate_stringlist],
- 'font.monospace' : [['Bitstream Vera Sans Mono','Andale Mono'
- 'Nimbus Mono L','Courier New','Courier','Fixed'
- 'Terminal','monospace'], validate_stringlist],
+ 'font.monospace' : [['Bitstream Vera Sans Mono', 'DejaVu Sans Mono',
+ 'Andale Mono', 'Nimbus Mono L', 'Courier New',
+ 'Courier','Fixed', 'Terminal','monospace'],
+ validate_stringlist],
# text props
'text.color' : ['k', validate_color], # black
@@ -363,12 +366,12 @@
'text.fontsize' : ['medium', validate_fontsize],
'text.markup' : ['plain', validate_markup],
- 'mathtext.cal' : [(['cursive'], 'normal', 'normal'), validate_mathtext_font],
- 'mathtext.rm' : [(['serif'], 'normal', 'normal'), validate_mathtext_font],
- 'mathtext.tt' : [(['monospace'], 'normal', 'normal'), validate_mathtext_font],
- 'mathtext.it' : [(['serif'], 'normal', 'oblique'), validate_mathtext_font],
- 'mathtext.bf' : [(['serif'], 'bold', 'normal'), validate_mathtext_font],
- 'mathtext.sf' : [(['sans-serif'], 'normal', 'normal'), validate_mathtext_font],
+ 'mathtext.cal' : [('cursive', 'normal', 'normal'), validate_mathtext_font],
+ 'mathtext.rm' : [('serif', 'normal', 'normal'), validate_mathtext_font],
+ 'mathtext.tt' : [('monospace', 'normal', 'normal'), validate_mathtext_font],
+ 'mathtext.it' : [('serif', 'normal', 'italic'), validate_mathtext_font],
+ 'mathtext.bf' : [('serif', 'bold', 'normal'), validate_mathtext_font],
+ 'mathtext.sf' : [('sans-serif', 'normal', 'normal'), validate_mathtext_font],
'mathtext.use_cm' : [True, validate_bool],
'mathtext.fallback_to_cm' : [True, validate_bool],
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <md...@us...> - 2007-08-07 17:47:31
|
Revision: 3682
http://matplotlib.svn.sourceforge.net/matplotlib/?rev=3682&view=rev
Author: mdboom
Date: 2007-08-07 10:47:30 -0700 (Tue, 07 Aug 2007)
Log Message:
-----------
Fix bug with SVG non-math text
Modified Paths:
--------------
trunk/matplotlib/src/ft2font.cpp
Modified: trunk/matplotlib/src/ft2font.cpp
===================================================================
--- trunk/matplotlib/src/ft2font.cpp 2007-08-07 17:39:57 UTC (rev 3681)
+++ trunk/matplotlib/src/ft2font.cpp 2007-08-07 17:47:30 UTC (rev 3682)
@@ -697,7 +697,7 @@
FT_Vector delta;
if (!FT_Get_Kerning( face, left, right, mode, &delta )) {
- return Py::Int(delta.x);
+ return Py::Int(delta.x / HORIZ_HINTING);
}
else {
return Py::Int(0);
@@ -775,7 +775,7 @@
FT_Vector delta;
FT_Get_Kerning( face, previous, glyph_index,
FT_KERNING_DEFAULT, &delta );
- pen.x += delta.x;
+ pen.x += delta.x / HORIZ_HINTING;
}
error = FT_Load_Glyph( face, glyph_index, flags );
if ( error ) {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <md...@us...> - 2007-08-07 17:40:06
|
Revision: 3681
http://matplotlib.svn.sourceforge.net/matplotlib/?rev=3681&view=rev
Author: mdboom
Date: 2007-08-07 10:39:57 -0700 (Tue, 07 Aug 2007)
Log Message:
-----------
Fix bug with PDF non-math text
Modified Paths:
--------------
trunk/matplotlib/src/ft2font.cpp
Modified: trunk/matplotlib/src/ft2font.cpp
===================================================================
--- trunk/matplotlib/src/ft2font.cpp 2007-08-07 15:29:25 UTC (rev 3680)
+++ trunk/matplotlib/src/ft2font.cpp 2007-08-07 17:39:57 UTC (rev 3681)
@@ -56,7 +56,7 @@
setattr("height", Py::Int( face->glyph->metrics.height) );
setattr("horiBearingX", Py::Int( face->glyph->metrics.horiBearingX / HORIZ_HINTING) );
setattr("horiBearingY", Py::Int( face->glyph->metrics.horiBearingY) );
- setattr("horiAdvance", Py::Int( face->glyph->metrics.horiAdvance / HORIZ_HINTING) );
+ setattr("horiAdvance", Py::Int( face->glyph->metrics.horiAdvance) );
setattr("linearHoriAdvance", Py::Int( face->glyph->linearHoriAdvance / HORIZ_HINTING) );
setattr("vertBearingX", Py::Int( face->glyph->metrics.vertBearingX) );
@@ -697,7 +697,7 @@
FT_Vector delta;
if (!FT_Get_Kerning( face, left, right, mode, &delta )) {
- return Py::Int(delta.x / HORIZ_HINTING);
+ return Py::Int(delta.x);
}
else {
return Py::Int(0);
@@ -775,7 +775,7 @@
FT_Vector delta;
FT_Get_Kerning( face, previous, glyph_index,
FT_KERNING_DEFAULT, &delta );
- pen.x += delta.x / HORIZ_HINTING;
+ pen.x += delta.x;
}
error = FT_Load_Glyph( face, glyph_index, flags );
if ( error ) {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <md...@us...> - 2007-08-07 15:29:29
|
Revision: 3680
http://matplotlib.svn.sourceforge.net/matplotlib/?rev=3680&view=rev
Author: mdboom
Date: 2007-08-07 08:29:25 -0700 (Tue, 07 Aug 2007)
Log Message:
-----------
Improve font rendering considerably using a vertical hinting hack.
Hinting is disabled for all of the "vector" backends, to correct
spacing problems.
Modified Paths:
--------------
trunk/matplotlib/lib/matplotlib/backends/backend_agg.py
trunk/matplotlib/lib/matplotlib/backends/backend_pdf.py
trunk/matplotlib/lib/matplotlib/backends/backend_ps.py
trunk/matplotlib/lib/matplotlib/backends/backend_svg.py
trunk/matplotlib/lib/matplotlib/mathtext.py
trunk/matplotlib/src/ft2font.cpp
trunk/matplotlib/src/ft2font.h
Modified: trunk/matplotlib/lib/matplotlib/backends/backend_agg.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/backends/backend_agg.py 2007-08-07 14:34:24 UTC (rev 3679)
+++ trunk/matplotlib/lib/matplotlib/backends/backend_agg.py 2007-08-07 15:29:25 UTC (rev 3680)
@@ -82,7 +82,7 @@
from matplotlib.cbook import enumerate, is_string_like, exception_to_str
from matplotlib.figure import Figure
from matplotlib.font_manager import fontManager
-from matplotlib.ft2font import FT2Font
+from matplotlib.ft2font import FT2Font, LOAD_DEFAULT
from matplotlib.mathtext import math_parse_s_ft2font
from matplotlib.transforms import lbwh_to_bbox
@@ -203,11 +203,10 @@
font = self._get_agg_font(prop)
if font is None: return None
- if len(s)==1 and ord(s)>127:
-
- font.load_char(ord(s))
+ if len(s) == 1 and ord(s) > 127:
+ font.load_char(ord(s), flags=LOAD_DEFAULT)
else:
- font.set_text(s, angle)
+ font.set_text(s, angle, flags=LOAD_DEFAULT)
font.draw_glyphs_to_bitmap()
#print x, y, int(x), int(y)
@@ -237,7 +236,7 @@
s, self.dpi.get(), prop)
return width, height
font = self._get_agg_font(prop)
- font.set_text(s, 0.0) # the width and height of unrotated string
+ font.set_text(s, 0.0, flags=LOAD_DEFAULT) # the width and height of unrotated string
w, h = font.get_width_height()
w /= 64.0 # convert from subpixels
h /= 64.0
Modified: trunk/matplotlib/lib/matplotlib/backends/backend_pdf.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/backends/backend_pdf.py 2007-08-07 14:34:24 UTC (rev 3679)
+++ trunk/matplotlib/lib/matplotlib/backends/backend_pdf.py 2007-08-07 15:29:25 UTC (rev 3680)
@@ -28,7 +28,7 @@
from matplotlib.font_manager import fontManager
from matplotlib.afm import AFM
from matplotlib.dviread import Dvi
-from matplotlib.ft2font import FT2Font, FIXED_WIDTH, ITALIC, LOAD_NO_SCALE
+from matplotlib.ft2font import FT2Font, FIXED_WIDTH, ITALIC, LOAD_NO_SCALE, LOAD_NO_HINTING
from matplotlib.mathtext import math_parse_s_pdf
from matplotlib.transforms import Bbox
from matplotlib import ttconv
@@ -517,7 +517,7 @@
def get_char_width(charcode):
unicode = decode_char(charcode)
- width = font.load_char(unicode, flags=LOAD_NO_SCALE).horiAdvance
+ width = font.load_char(unicode, flags=LOAD_NO_SCALE|LOAD_NO_HINTING).horiAdvance
return cvt(width)
firstchar, lastchar = 0, 255
@@ -1195,7 +1195,7 @@
else:
font = self._get_font_ttf(prop)
self.track_characters(font, s)
- font.set_text(s, 0.0)
+ font.set_text(s, 0.0, flags=LOAD_NO_HINTING)
y += font.get_descent() / 64.0
self.file.output(Op.begin_text,
@@ -1222,7 +1222,7 @@
else:
font = self._get_font_ttf(prop)
- font.set_text(s, 0.0)
+ font.set_text(s, 0.0, flags=LOAD_NO_HINTING)
w, h = font.get_width_height()
w /= 64.0
h /= 64.0
Modified: trunk/matplotlib/lib/matplotlib/backends/backend_ps.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/backends/backend_ps.py 2007-08-07 14:34:24 UTC (rev 3679)
+++ trunk/matplotlib/lib/matplotlib/backends/backend_ps.py 2007-08-07 15:29:25 UTC (rev 3680)
@@ -19,7 +19,7 @@
from matplotlib.figure import Figure
from matplotlib.font_manager import fontManager
-from matplotlib.ft2font import FT2Font, KERNING_UNFITTED, KERNING_DEFAULT, KERNING_UNSCALED
+from matplotlib.ft2font import FT2Font, KERNING_DEFAULT, LOAD_NO_HINTING
from matplotlib.ttconv import convert_ttf_to_ps
from matplotlib.mathtext import math_parse_s_ps
from matplotlib.text import Text
@@ -292,7 +292,7 @@
return w, h
font = self._get_font_ttf(prop)
- font.set_text(s, 0.0)
+ font.set_text(s, 0.0, flags=LOAD_NO_HINTING)
w, h = font.get_width_height()
w /= 64.0 # convert from subpixels
h /= 64.0
@@ -738,7 +738,7 @@
return self.draw_unicode(gc, x, y, s, prop, angle)
else:
font = self._get_font_ttf(prop)
- font.set_text(s,0)
+ font.set_text(s, 0, flags=LOAD_NO_HINTING)
self.track_characters(font, s)
self.set_color(*gc.get_rgb())
@@ -782,10 +782,10 @@
gind = 0
else:
name = font.get_glyph_name(gind)
- glyph = font.load_char(ccode)
+ glyph = font.load_char(ccode, flags=LOAD_NO_HINTING)
if lastgind is not None:
- kern = font.get_kerning(lastgind, gind, KERNING_UNFITTED)
+ kern = font.get_kerning(lastgind, gind, KERNING_DEFAULT)
else:
kern = 0
lastgind = gind
Modified: trunk/matplotlib/lib/matplotlib/backends/backend_svg.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/backends/backend_svg.py 2007-08-07 14:34:24 UTC (rev 3679)
+++ trunk/matplotlib/lib/matplotlib/backends/backend_svg.py 2007-08-07 15:29:25 UTC (rev 3680)
@@ -8,7 +8,7 @@
from matplotlib.colors import rgb2hex
from matplotlib.figure import Figure
from matplotlib.font_manager import fontManager, FontProperties
-from matplotlib.ft2font import FT2Font, KERNING_UNFITTED, KERNING_DEFAULT, KERNING_UNSCALED
+from matplotlib.ft2font import FT2Font, KERNING_DEFAULT, LOAD_NO_HINTING
from matplotlib.mathtext import math_parse_s_ft2font_svg
from xml.sax.saxutils import escape as escape_xml_text
@@ -266,10 +266,10 @@
if gind is None:
ccode = ord('?')
gind = 0
- glyph = font.load_char(ccode)
+ glyph = font.load_char(ccode, flags=LOAD_NO_HINTING)
if lastgind is not None:
- kern = font.get_kerning(lastgind, gind, KERNING_UNFITTED)
+ kern = font.get_kerning(lastgind, gind, KERNING_DEFAULT)
else:
kern = 0
lastgind = gind
@@ -305,7 +305,7 @@
return char_id
path_data = []
- glyph = font.load_char(ord(char))
+ glyph = font.load_char(ord(char), flags=LOAD_NO_HINTING)
currx, curry = 0.0, 0.0
for step in glyph.path:
if step[0] == 0: # MOVE_TO
@@ -431,7 +431,7 @@
math_parse_s_ft2font_svg(s, 72, prop)
return width, height
font = self._get_font(prop)
- font.set_text(s, 0.0)
+ font.set_text(s, 0.0, flags=LOAD_NO_HINTING)
w, h = font.get_width_height()
w /= 64.0 # convert from subpixels
h /= 64.0
Modified: trunk/matplotlib/lib/matplotlib/mathtext.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/mathtext.py 2007-08-07 14:34:24 UTC (rev 3679)
+++ trunk/matplotlib/lib/matplotlib/mathtext.py 2007-08-07 15:29:25 UTC (rev 3680)
@@ -148,7 +148,7 @@
from matplotlib.afm import AFM
from matplotlib.cbook import enumerate, iterable, Bunch, get_realpath_and_stat, \
is_string_like
-from matplotlib.ft2font import FT2Font, KERNING_UNFITTED
+from matplotlib.ft2font import FT2Font, KERNING_DEFAULT, LOAD_DEFAULT, LOAD_NO_HINTING
from matplotlib.font_manager import fontManager, FontProperties
from matplotlib._mathtext_data import latex_to_bakoma, \
latex_to_standard, tex2uni, type12uni, tex2type1, uni2type1
@@ -237,6 +237,9 @@
"""Return a backend specific tuple of things to return to the
backend after all processing is done."""
raise NotImplementedError()
+
+ def get_hinting_type(self):
+ return LOAD_NO_HINTING
class MathtextBackendAgg(MathtextBackend):
def set_canvas_size(self, w, h):
@@ -261,7 +264,10 @@
self.height,
self.fonts_object.get_fonts(),
self.fonts_object.get_used_characters())
-
+
+ def get_hinting_type(self):
+ return LOAD_DEFAULT
+
class MathtextBackendPs(MathtextBackend):
def __init__(self):
self.pswriter = StringIO()
@@ -487,7 +493,9 @@
font = cached_font.font
font.set_size(fontsize, dpi)
- glyph = font.load_char(num)
+ glyph = font.load_char(
+ num,
+ flags=self.mathtext_backend.get_hinting_type())
xmin, ymin, xmax, ymax = [val/64.0 for val in glyph.bbox]
offset = self._get_offset(cached_font, glyph, fontsize, dpi)
@@ -538,7 +546,7 @@
info1 = self._get_info(font1, sym1, fontsize1, dpi)
info2 = self._get_info(font2, sym2, fontsize2, dpi)
font = info1.font
- return font.get_kerning(info1.num, info2.num, KERNING_UNFITTED) / 64.0
+ return font.get_kerning(info1.num, info2.num, KERNING_DEFAULT) / 64.0
return 0.0
class BakomaFonts(TruetypeFonts):
Modified: trunk/matplotlib/src/ft2font.cpp
===================================================================
--- trunk/matplotlib/src/ft2font.cpp 2007-08-07 14:34:24 UTC (rev 3679)
+++ trunk/matplotlib/src/ft2font.cpp 2007-08-07 15:29:25 UTC (rev 3680)
@@ -5,6 +5,41 @@
#define FIXED_MAJOR(val) (*((short *) &val+1))
#define FIXED_MINOR(val) (*((short *) &val+0))
+/**
+ To improve the hinting of the fonts, this code uses a hack
+ presented here:
+
+ http://antigrain.com/research/font_rasterization/index.html
+
+ The idea is to limit the effect of hinting in the x-direction, while
+ preserving hinting in the y-direction. Since freetype does not
+ support this directly, the dpi in the x-direction is set higher than
+ in the y-direction, which affects the hinting grid. Then, a global
+ transform is placed on the font to shrink it back to the desired
+ size. While it is a bit surprising that the dpi setting affects
+ hinting, whereas the global transform does not, this is documented
+ behavior of freetype, and therefore hopefully unlikely to change.
+ The freetype 2 tutorial says:
+
+ NOTE: The transformation is applied to every glyph that is
+ loaded through FT_Load_Glyph and is completely independent of
+ any hinting process. This means that you won't get the same
+ results if you load a glyph at the size of 24 pixels, or a glyph
+ at the size at 12 pixels scaled by 2 through a transform,
+ because the hints will have been computed differently (except
+ you have disabled hints).
+
+ This hack is enabled only when VERTICAL_HINTING is defined, and will
+ only be effective when load_char and set_text are called with 'flags=
+ LOAD_DEFAULT', which is the default.
+ */
+#define VERTICAL_HINTING
+#ifdef VERTICAL_HINTING
+#define HORIZ_HINTING 8
+#else
+#define HORIZ_HINTING 1
+#endif
+
FT_Library _ft2Library;
FT2Image::FT2Image() : bRotated(false), buffer(NULL) {}
@@ -17,12 +52,12 @@
FT_BBox bbox;
FT_Glyph_Get_CBox( glyph, ft_glyph_bbox_subpixels, &bbox );
- setattr("width", Py::Int( face->glyph->metrics.width) );
+ setattr("width", Py::Int( face->glyph->metrics.width / HORIZ_HINTING) );
setattr("height", Py::Int( face->glyph->metrics.height) );
- setattr("horiBearingX", Py::Int( face->glyph->metrics.horiBearingX) );
+ setattr("horiBearingX", Py::Int( face->glyph->metrics.horiBearingX / HORIZ_HINTING) );
setattr("horiBearingY", Py::Int( face->glyph->metrics.horiBearingY) );
- setattr("horiAdvance", Py::Int( face->glyph->metrics.horiAdvance) );
- setattr("linearHoriAdvance", Py::Int( face->glyph->linearHoriAdvance) );
+ setattr("horiAdvance", Py::Int( face->glyph->metrics.horiAdvance / HORIZ_HINTING) );
+ setattr("linearHoriAdvance", Py::Int( face->glyph->linearHoriAdvance / HORIZ_HINTING) );
setattr("vertBearingX", Py::Int( face->glyph->metrics.vertBearingX) );
setattr("vertBearingY", Py::Int( face->glyph->metrics.vertBearingY) );
@@ -341,7 +376,13 @@
}
// set a default fontsize 12 pt at 72dpi
+#ifdef VERTICAL_HINTING
+ error = FT_Set_Char_Size( face, 12 * 64, 0, 72 * HORIZ_HINTING, 72 );
+ static FT_Matrix transform = { 65536 / HORIZ_HINTING, 0, 0, 65536 };
+ FT_Set_Transform( face, &transform, 0 );
+#else
error = FT_Set_Char_Size( face, 12 * 64, 0, 72, 72 );
+#endif
//error = FT_Set_Char_Size( face, 20 * 64, 0, 80, 80 );
if (error) {
std::ostringstream s;
@@ -572,9 +613,17 @@
double ptsize = Py::Float(args[0]);
double dpi = Py::Float(args[1]);
+#ifdef VERTICAL_HINTING
int error = FT_Set_Char_Size( face, (long)(ptsize * 64), 0,
+ (unsigned int)dpi * HORIZ_HINTING,
+ (unsigned int)dpi );
+ static FT_Matrix transform = { 65536 / HORIZ_HINTING, 0, 0, 65536 };
+ FT_Set_Transform( face, &transform, 0 );
+#else
+ int error = FT_Set_Char_Size( face, (long)(ptsize * 64), 0,
(unsigned int)dpi,
(unsigned int)dpi );
+#endif
if (error)
throw Py::RuntimeError("Could not set the fontsize");
return Py::Object();
@@ -648,7 +697,7 @@
FT_Vector delta;
if (!FT_Get_Kerning( face, left, right, mode, &delta )) {
- return Py::Int(delta.x);
+ return Py::Int(delta.x / HORIZ_HINTING);
}
else {
return Py::Int(0);
@@ -665,7 +714,7 @@
"You must call this before draw_glyphs_to_bitmap\n"
"A sequence of x,y positions is returned";
Py::Object
-FT2Font::set_text(const Py::Tuple & args) {
+FT2Font::set_text(const Py::Tuple & args, const Py::Dict & kwargs) {
_VERBOSE("FT2Font::set_text");
args.verify_length(2);
@@ -687,6 +736,11 @@
angle = Py::Float(args[1]);
angle = angle/360.0*2*3.14159;
+
+ long flags = FT_LOAD_DEFAULT;
+ if (kwargs.hasKey("flags"))
+ flags = Py::Long(kwargs["flags"]);
+
//this computes width and height in subpixels so we have to divide by 64
matrix.xx = (FT_Fixed)( cos( angle ) * 0x10000L );
matrix.xy = (FT_Fixed)(-sin( angle ) * 0x10000L );
@@ -721,9 +775,9 @@
FT_Vector delta;
FT_Get_Kerning( face, previous, glyph_index,
FT_KERNING_DEFAULT, &delta );
- pen.x += delta.x;
+ pen.x += delta.x / HORIZ_HINTING;
}
- error = FT_Load_Glyph( face, glyph_index, FT_LOAD_DEFAULT );
+ error = FT_Load_Glyph( face, glyph_index, flags );
if ( error ) {
std::cerr << "\tcould not load glyph for " << thischar << std::endl;
continue;
@@ -794,7 +848,7 @@
}
char FT2Font::load_char__doc__[] =
-"load_char(charcode, flags=LOAD_DEFAULT)\n"
+"load_char(charcode, flags=LOAD_LOAD_DEFAULT)\n"
"\n"
"Load character with charcode in current fontfile and set glyph.\n"
"The flags argument can be a bitwise-or of the LOAD_XXX constants.\n"
@@ -881,22 +935,25 @@
FT_Int x,
FT_Int y) {
_VERBOSE("FT2Font::draw_bitmap");
- FT_Int i, j, p, q;
- FT_Int width = (FT_Int)image.width;
- FT_Int height = (FT_Int)image.height;
+ FT_Int image_width = (FT_Int)image.width;
+ FT_Int image_height = (FT_Int)image.height;
+ FT_Int char_width = bitmap->width;
+ FT_Int char_height = bitmap->rows;
- FT_Int x1 = CLAMP(x, 0, width);
- FT_Int y1 = CLAMP(y, 0, height);
- FT_Int x2 = CLAMP(x + bitmap->width, 0, width);
- FT_Int y2 = CLAMP(y + bitmap->rows, 0, height);
+ FT_Int x1 = CLAMP(x, 0, image_width);
+ FT_Int y1 = CLAMP(y, 0, image_height);
+ FT_Int x2 = CLAMP(x + char_width, 0, image_width);
+ FT_Int y2 = CLAMP(y + char_height, 0, image_height);
- for ( i = x1, p = MAX(0, -x); i < x2; ++i, ++p )
- {
- for ( j = y1, q = MAX(0, -y); j < y2; ++j, ++q )
- {
- image.buffer[i + j*width] |= bitmap->buffer[p + q*bitmap->pitch];
- }
- }
+ FT_Int x_start = MAX(0, -x);
+ FT_Int y_offset = y1 - MAX(0, -y);
+
+ for ( FT_Int i = y1; i < y2; ++i ) {
+ unsigned char* dst = image.buffer + (i * image_width + x1);
+ unsigned char* src = bitmap->buffer + (((i - y_offset) * bitmap->pitch) + x_start);
+ for ( FT_Int j = x1; j < x2; ++j, ++dst, ++src )
+ *dst |= *src;
+ }
}
char FT2Font::write_bitmap__doc__[] =
@@ -1038,15 +1095,14 @@
FT_BBox string_bbox = compute_string_bbox();
- image.width = (string_bbox.xMax-string_bbox.xMin) / 64+2;
- image.height = (string_bbox.yMax-string_bbox.yMin) / 64+2;
+ image.width = (string_bbox.xMax-string_bbox.xMin) / 64 + 2;
+ image.height = (string_bbox.yMax-string_bbox.yMin) / 64 + 2;
- image.offsetx = (int)(string_bbox.xMin/64.0);
+ image.offsetx = (int)(string_bbox.xMin / 64.0);
if (angle==0)
image.offsety = -image.height;
- else {
+ else
image.offsety = (int)(-string_bbox.yMax/64.0);
- }
size_t numBytes = image.width*image.height;
delete [] image.buffer;
@@ -1054,8 +1110,6 @@
for (size_t n=0; n<numBytes; n++)
image.buffer[n] = 0;
-
-
for ( size_t n = 0; n < glyphs.size(); n++ )
{
FT_BBox bbox;
@@ -1074,11 +1128,8 @@
// now, draw to our target surface (convert position)
//bitmap left and top in pixel, string bbox in subpixel
- FT_Int x = (FT_Int)(bitmap->left-string_bbox.xMin/64.);
- FT_Int y = (FT_Int)(string_bbox.yMax/64.-bitmap->top+1);
- //make sure the index is non-neg
- x = x<0?0:x;
- y = y<0?0:y;
+ FT_Int x = (FT_Int)(bitmap->left - (string_bbox.xMin / 64.));
+ FT_Int y = (FT_Int)((string_bbox.yMax / 64.) - bitmap->top + 1);
draw_bitmap( &bitmap->bitmap, x, y);
}
@@ -1173,12 +1224,7 @@
FT_BitmapGlyph bitmap = (FT_BitmapGlyph)glyphs[glyph->glyphInd];
- draw_bitmap( &bitmap->bitmap,
- //x + bitmap->left,
- x,
- //y+bitmap->top
- y
- );
+ draw_bitmap( &bitmap->bitmap, x, y);
return Py::Object();
}
@@ -1586,9 +1632,8 @@
behaviors().doc("Glyph");
behaviors().supportGetattr();
behaviors().supportSetattr();
+}
-
-}
void
FT2Font::init_type() {
_VERBOSE("FT2Font::init_type");
@@ -1603,7 +1648,7 @@
FT2Font::load_char__doc__);
add_varargs_method("draw_rect",&FT2Font::draw_rect,
FT2Font::draw_rect__doc__);
- add_varargs_method("draw_rect_filled",&FT2Font::draw_rect_filled,
+ add_varargs_method("draw_rect_filled",&FT2Font::draw_rect_filled,
FT2Font::draw_rect_filled__doc__);
add_varargs_method("draw_glyph_to_bitmap", &FT2Font::draw_glyph_to_bitmap,
FT2Font::draw_glyph_to_bitmap__doc__);
@@ -1620,7 +1665,7 @@
FT2Font::image_as_str__doc__);
add_keyword_method("load_char", &FT2Font::load_char,
FT2Font::load_char__doc__);
- add_varargs_method("set_text", &FT2Font::set_text,
+ add_keyword_method("set_text", &FT2Font::set_text,
FT2Font::set_text__doc__);
add_varargs_method("set_size", &FT2Font::set_size,
FT2Font::set_size__doc__);
@@ -1766,6 +1811,5 @@
}
ft2font_module::~ft2font_module() {
-
FT_Done_FreeType( _ft2Library );
}
Modified: trunk/matplotlib/src/ft2font.h
===================================================================
--- trunk/matplotlib/src/ft2font.h 2007-08-07 14:34:24 UTC (rev 3679)
+++ trunk/matplotlib/src/ft2font.h 2007-08-07 15:29:25 UTC (rev 3680)
@@ -56,7 +56,7 @@
Py::Object clear(const Py::Tuple & args);
Py::Object set_size(const Py::Tuple & args);
Py::Object set_charmap(const Py::Tuple & args);
- Py::Object set_text(const Py::Tuple & args);
+ Py::Object set_text(const Py::Tuple & args, const Py::Dict & kwargs);
Py::Object get_glyph(const Py::Tuple & args);
Py::Object get_kerning(const Py::Tuple & args);
Py::Object get_num_glyphs(const Py::Tuple & args);
@@ -91,9 +91,10 @@
std::vector<FT_Vector> pos;
std::vector<Glyph*> gms;
double angle;
+ double ptsize;
+ double dpi;
-
FT_BBox compute_string_bbox();
void draw_bitmap( FT_Bitmap* bitmap, FT_Int x, FT_Int y);
void set_scalable_attributes();
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <md...@us...> - 2007-08-07 14:34:25
|
Revision: 3679
http://matplotlib.svn.sourceforge.net/matplotlib/?rev=3679&view=rev
Author: mdboom
Date: 2007-08-07 07:34:24 -0700 (Tue, 07 Aug 2007)
Log Message:
-----------
Fix character spacing bug in non-mathtext
Modified Paths:
--------------
trunk/matplotlib/lib/matplotlib/backends/backend_svg.py
Modified: trunk/matplotlib/lib/matplotlib/backends/backend_svg.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/backends/backend_svg.py 2007-08-07 00:35:08 UTC (rev 3678)
+++ trunk/matplotlib/lib/matplotlib/backends/backend_svg.py 2007-08-07 14:34:24 UTC (rev 3679)
@@ -276,9 +276,9 @@
currx += kern/64.0
svg.append('<use xlink:href="#%s" transform="translate(%s)"/>\n'
- % (charid, currx / (fontsize / self.FONT_SCALE)))
+ % (charid, currx))
- currx += glyph.linearHoriAdvance / 65536.0
+ currx += (glyph.linearHoriAdvance / 65536.0)
svg.append('</g>\n')
svg = ''.join(svg)
else:
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <cm...@us...> - 2007-08-07 00:35:10
|
Revision: 3678
http://matplotlib.svn.sourceforge.net/matplotlib/?rev=3678&view=rev
Author: cmoad
Date: 2007-08-06 17:35:08 -0700 (Mon, 06 Aug 2007)
Log Message:
-----------
typo in the tcl/tk win32 includes
Modified Paths:
--------------
trunk/matplotlib/setupext.py
Modified: trunk/matplotlib/setupext.py
===================================================================
--- trunk/matplotlib/setupext.py 2007-08-06 20:53:11 UTC (rev 3677)
+++ trunk/matplotlib/setupext.py 2007-08-07 00:35:08 UTC (rev 3678)
@@ -676,10 +676,10 @@
if sys.platform=='win32':
major, minor1, minor2, s, tmp = sys.version_info
if major==2 and minor1 in [3, 4, 5]:
- module.include_dirs.extend(['win32_static/include/tcl84'])
+ module.include_dirs.extend(['win32_static/include/tcl8.4'])
module.libraries.extend(['tk84', 'tcl84'])
elif major==2 and minor1==2:
- module.include_dirs.extend(['win32_static/include/tcl83'])
+ module.include_dirs.extend(['win32_static/include/tcl8.3'])
module.libraries.extend(['tk83', 'tcl83'])
else:
raise RuntimeError('No tk/win32 support for this python version yet')
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <md...@us...> - 2007-08-06 20:53:37
|
Revision: 3677
http://matplotlib.svn.sourceforge.net/matplotlib/?rev=3677&view=rev
Author: mdboom
Date: 2007-08-06 13:53:11 -0700 (Mon, 06 Aug 2007)
Log Message:
-----------
Expose Unicode font functionality for mathtext through rcParams
Modified Paths:
--------------
trunk/matplotlib/lib/matplotlib/_mathtext_data.py
trunk/matplotlib/lib/matplotlib/mathtext.py
trunk/matplotlib/lib/matplotlib/mpl-data/matplotlibrc
trunk/matplotlib/lib/matplotlib/rcsetup.py
trunk/matplotlib/matplotlibrc.template
Modified: trunk/matplotlib/lib/matplotlib/_mathtext_data.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/_mathtext_data.py 2007-08-06 18:52:07 UTC (rev 3676)
+++ trunk/matplotlib/lib/matplotlib/_mathtext_data.py 2007-08-06 20:53:11 UTC (rev 3677)
@@ -2211,7 +2211,7 @@
'$': 36,
'{': 123,
'}': 125,
-'imath': 0xfd,
+'imath': 0x131,
'circumflexaccent' : 770,
'combiningbreve' : 774,
'combiningoverline' : 772,
Modified: trunk/matplotlib/lib/matplotlib/mathtext.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/mathtext.py 2007-08-06 18:52:07 UTC (rev 3676)
+++ trunk/matplotlib/lib/matplotlib/mathtext.py 2007-08-06 20:53:11 UTC (rev 3677)
@@ -133,7 +133,7 @@
from cStringIO import StringIO
from math import floor, ceil
from sets import Set
-from unicodedata import category
+import unicodedata
from warnings import warn
from numpy import inf, isinf
@@ -462,7 +462,7 @@
cached_font = self.fonts.get(basename)
if cached_font is None:
- font = FT2Font(os.path.join(self.basepath, basename + ".ttf"))
+ font = FT2Font(basename)
cached_font = self.CachedFont(font)
self.fonts[basename] = cached_font
self.fonts[font.postscript_name] = cached_font
@@ -545,15 +545,24 @@
"""
Use the Bakoma true type fonts for rendering
"""
- fontmap = { 'cal' : 'cmsy10',
- 'rm' : 'cmr10',
- 'tt' : 'cmtt10',
- 'it' : 'cmmi10',
- 'bf' : 'cmb10',
- 'sf' : 'cmss10',
- 'ex' : 'cmex10'
- }
-
+ _fontmap = { 'cal' : 'cmsy10',
+ 'rm' : 'cmr10',
+ 'tt' : 'cmtt10',
+ 'it' : 'cmmi10',
+ 'bf' : 'cmb10',
+ 'sf' : 'cmss10',
+ 'ex' : 'cmex10'
+ }
+ fontmap = {}
+
+ def __init__(self, *args, **kwargs):
+ TruetypeFonts.__init__(self, *args, **kwargs)
+ if not len(self.fontmap):
+ for key, val in self._fontmap.items():
+ fullpath = os.path.join(self.basepath, val + ".ttf")
+ self.fontmap[key] = fullpath
+ self.fontmap[val] = fullpath
+
def _get_offset(self, cached_font, glyph, fontsize, dpi):
if cached_font.font.postscript_name == 'Cmex10':
return glyph.height/64.0/2.0 + 256.0/64.0 * dpi/72.0
@@ -564,7 +573,7 @@
def _get_glyph(self, fontname, sym, fontsize):
if fontname in self.fontmap and latex_to_bakoma.has_key(sym):
basename, num = latex_to_bakoma[sym]
- slanted = basename == "cmmi10" or sym in self._slanted_symbols
+ slanted = (basename == "cmmi10") or sym in self._slanted_symbols
cached_font = self._get_font(basename)
symbol_name = cached_font.font.get_glyph_name(num)
num = cached_font.glyphmap[num]
@@ -638,15 +647,24 @@
class UnicodeFonts(TruetypeFonts):
"""An abstract base class for handling Unicode fonts.
"""
- fontmap = { 'cal' : 'cmsy10',
- 'rm' : 'DejaVuSerif',
- 'tt' : 'DejaVuSansMono',
- 'it' : 'DejaVuSerif-Italic',
- 'bf' : 'DejaVuSerif-Bold',
- 'sf' : 'DejaVuSans',
- None : 'DejaVuSerif-Italic'
- }
+ fontmap = {}
+
+ def __init__(self, *args, **kwargs):
+ # This must come first so the backend's owner is set correctly
+ if rcParams['mathtext.fallback_to_cm']:
+ self.cm_fallback = BakomaFonts(*args, **kwargs)
+ else:
+ self.cm_fallback = None
+ TruetypeFonts.__init__(self, *args, **kwargs)
+ if not len(self.fontmap):
+ for texfont in "cal rm tt it bf sf".split():
+ setting = rcParams['mathtext.' + texfont]
+ family, weight, style = setting
+ prop = FontProperties(family=family, weight=weight, style=style)
+ font = fontManager.findfont(prop)
+ self.fontmap[texfont] = font
+
def _get_offset(self, cached_font, glyph, fontsize, dpi):
return 0.
@@ -662,34 +680,66 @@
uniindex = get_unicode_index(sym[4:])
fontsize *= GROW_FACTOR
else:
- warn("No TeX to unicode mapping for '%s'" % sym,
+ uniindex = ord('?')
+ warn("No TeX to unicode mapping for '%s'" % sym.encode('ascii', 'replace'),
MathTextWarning)
# Only characters in the "Letter" class should be italicized in 'it'
- # mode. This class includes greek letters, of course.
- if (fontname == 'it'
- and not category(unichr(uniindex)).startswith("L")):
- fontname = 'rm'
+ # mode. Greek capital letters should be Roman.
+ if found_symbol:
+ new_fontname = fontname
- slanted = (fontname == 'it')
-
- cached_font = self._get_font(fontname)
- if found_symbol:
+ if fontname == 'it':
+ unistring = unichr(uniindex)
+ if (not unicodedata.category(unistring).startswith("L")
+ or unicodedata.name(unistring).startswith("GREEK CAPITAL")):
+ new_fontname = 'rm'
+
+ slanted = (new_fontname == 'it')
+ cached_font = self._get_font(new_fontname)
try:
glyphindex = cached_font.charmap[uniindex]
except KeyError:
warn("Font '%s' does not have a glyph for '%s'" %
- (cached_font.font.postscript_name, sym),
+ (cached_font.font.postscript_name, sym.encode('ascii', 'replace')),
MathTextWarning)
found_symbol = False
if not found_symbol:
- uniindex = 0xA4 # currency character, for lack of anything better
- glyphindex = cached_font.charmap[uniindex]
+ if self.cm_fallback:
+ warn("Substituting with a symbol from the Computer Modern family.",
+ MathTextWarning)
+ return self.cm_fallback._get_glyph(fontname, sym, fontsize)
+ else:
+ new_fontname = fontname
+ cached_font = self._get_font(fontname)
+ uniindex = 0xA4 # currency character, for lack of anything better
+ glyphindex = cached_font.charmap[uniindex]
+ slanted = False
symbol_name = cached_font.font.get_glyph_name(glyphindex)
return cached_font, uniindex, symbol_name, fontsize, slanted
+
+ def set_canvas_size(self, w, h):
+ 'Dimension the drawing canvas; may be a noop'
+ TruetypeFonts.set_canvas_size(self, w, h)
+ if self.cm_fallback:
+ self.cm_fallback.set_canvas_size(w, h)
+ def get_used_characters(self):
+ used_characters = dict(self.used_characters)
+ if self.cm_fallback:
+ fallback_characters = self.cm_fallback.get_used_characters()
+ for key, val in fallback_characters:
+ used_characters.setdefault(key, Set()).update(val)
+ return used_characters
+
+ def get_fonts(self):
+ fonts = [x.font for x in self.fonts.values()]
+ if self.cm_fallback:
+ fonts.extend(self.cm_fallback.get_fonts())
+ return list(set(fonts))
+
class StandardPsFonts(Fonts):
"""
Use the standard postscript fonts for rendering to backend_ps
@@ -750,7 +800,7 @@
# This class includes greek letters, so we're ok
if (fontname == 'it' and
(len(sym) > 1 or
- not category(unicode(sym)).startswith("L"))):
+ not unicodedata.category(unicode(sym)).startswith("L"))):
fontname = 'rm'
found_symbol = False
@@ -2302,10 +2352,10 @@
font_output = StandardPsFonts(prop)
else:
backend = self._backend_mapping[self.output]()
- font_output = BakomaFonts(prop, backend)
- # When we have a decent Unicode font, we should test and
- # then make this available as an option
- #~ font_output = UnicodeFonts(prop, backend)
+ if rcParams['mathtext.use_cm']:
+ font_output = BakomaFonts(prop, backend)
+ else:
+ font_output = UnicodeFonts(prop, backend)
fontsize = prop.get_size_in_points()
if self._parser is None:
Modified: trunk/matplotlib/lib/matplotlib/mpl-data/matplotlibrc
===================================================================
--- trunk/matplotlib/lib/matplotlib/mpl-data/matplotlibrc 2007-08-06 18:52:07 UTC (rev 3676)
+++ trunk/matplotlib/lib/matplotlib/mpl-data/matplotlibrc 2007-08-06 20:53:11 UTC (rev 3677)
@@ -159,6 +159,22 @@
# In that case, all text will be sent to TeX for
# processing.
+# The following settings allow you to select the fonts in math mode.
+# They map from a TeX font name to a 3-tuple of the form:
+# (family, weight, style)
+# These settings are only used if mathtext.use_cm is False, otherwise, the
+# Bakoma TeX Computer Modern fonts are used.
+#mathtext.cal : (['cursive'], 'normal', 'normal')
+#mathtext.rm : (['serif'], 'normal', 'normal')
+#mathtext.tt : (['monospace'], 'normal', 'normal')
+#mathtext.it : (['serif'], 'normal', 'oblique')
+#mathtext.bf : (['serif'], 'bold', 'normal')
+#mathtext.sf : (['sans-serif'], 'normal', 'normal')
+#mathtext.use_cm : True
+#mathtext.fallback_to_cm : True # When True, use symbols from the Computer Modern
+ # fonts when a symbol can not be found in one of
+ # the user-specified math fonts.
+
### AXES
# default face and edge color, default tick sizes,
# default fontsizes for ticklabels, and so on. See
Modified: trunk/matplotlib/lib/matplotlib/rcsetup.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/rcsetup.py 2007-08-06 18:52:07 UTC (rev 3676)
+++ trunk/matplotlib/lib/matplotlib/rcsetup.py 2007-08-06 20:53:11 UTC (rev 3677)
@@ -198,6 +198,12 @@
except ValueError:
raise ValueError('not a valid font size')
+def validate_mathtext_font(s):
+ s = eval(s)
+ if type(s) in (list, tuple) and len(s) == 3:
+ return s
+ raise ValueError('Mathtext font specifier must be a 3-tuple of (family, weight, style)')
+
validate_markup = ValidateInStrings(
'markup',
['plain', 'tex'],
@@ -357,6 +363,15 @@
'text.fontsize' : ['medium', validate_fontsize],
'text.markup' : ['plain', validate_markup],
+ 'mathtext.cal' : [(['cursive'], 'normal', 'normal'), validate_mathtext_font],
+ 'mathtext.rm' : [(['serif'], 'normal', 'normal'), validate_mathtext_font],
+ 'mathtext.tt' : [(['monospace'], 'normal', 'normal'), validate_mathtext_font],
+ 'mathtext.it' : [(['serif'], 'normal', 'oblique'), validate_mathtext_font],
+ 'mathtext.bf' : [(['serif'], 'bold', 'normal'), validate_mathtext_font],
+ 'mathtext.sf' : [(['sans-serif'], 'normal', 'normal'), validate_mathtext_font],
+ 'mathtext.use_cm' : [True, validate_bool],
+ 'mathtext.fallback_to_cm' : [True, validate_bool],
+
'image.aspect' : ['equal', validate_aspect], # equal, auto, a number
'image.interpolation' : ['bilinear', str],
'image.cmap' : ['jet', str], # one of gray, jet, etc
Modified: trunk/matplotlib/matplotlibrc.template
===================================================================
--- trunk/matplotlib/matplotlibrc.template 2007-08-06 18:52:07 UTC (rev 3676)
+++ trunk/matplotlib/matplotlibrc.template 2007-08-06 20:53:11 UTC (rev 3677)
@@ -159,6 +159,22 @@
# In that case, all text will be sent to TeX for
# processing.
+# The following settings allow you to select the fonts in math mode.
+# They map from a TeX font name to a 3-tuple of the form:
+# (family, weight, style)
+# These settings are only used if mathtext.use_cm is False, otherwise, the
+# Bakoma TeX Computer Modern fonts are used.
+#mathtext.cal : (['cursive'], 'normal', 'normal')
+#mathtext.rm : (['serif'], 'normal', 'normal')
+#mathtext.tt : (['monospace'], 'normal', 'normal')
+#mathtext.it : (['serif'], 'normal', 'oblique')
+#mathtext.bf : (['serif'], 'bold', 'normal')
+#mathtext.sf : (['sans-serif'], 'normal', 'normal')
+#mathtext.use_cm : True
+#mathtext.fallback_to_cm : True # When True, use symbols from the Computer Modern
+ # fonts when a symbol can not be found in one of
+ # the user-specified math fonts.
+
### AXES
# default face and edge color, default tick sizes,
# default fontsizes for ticklabels, and so on. See
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <md...@us...> - 2007-08-06 18:52:10
|
Revision: 3676
http://matplotlib.svn.sourceforge.net/matplotlib/?rev=3676&view=rev
Author: mdboom
Date: 2007-08-06 11:52:07 -0700 (Mon, 06 Aug 2007)
Log Message:
-----------
Removed mathtext2. Fix horizontal centering in mathtext. Put all
mathtext_examples on one plot.
Modified Paths:
--------------
trunk/matplotlib/CHANGELOG
trunk/matplotlib/examples/mathtext_examples.py
trunk/matplotlib/lib/matplotlib/config/mplconfig.py
trunk/matplotlib/lib/matplotlib/config/rcsetup.py
trunk/matplotlib/lib/matplotlib/mathtext.py
trunk/matplotlib/lib/matplotlib/mpl-data/matplotlibrc
trunk/matplotlib/lib/matplotlib/rcsetup.py
Removed Paths:
-------------
trunk/matplotlib/examples/mathtext2_demo.py
trunk/matplotlib/lib/matplotlib/mathtext2.py
Modified: trunk/matplotlib/CHANGELOG
===================================================================
--- trunk/matplotlib/CHANGELOG 2007-08-06 18:50:00 UTC (rev 3675)
+++ trunk/matplotlib/CHANGELOG 2007-08-06 18:52:07 UTC (rev 3676)
@@ -1,3 +1,17 @@
+2007-08-06 Removed mathtext2
+
+2007-07-31 Refactoring of distutils scripts.
+ - Will not fail on the entire build if an optional Python
+ package (e.g. Tkinter) is installed but its development
+ headers are not (e.g. tk-devel). Instead, it will
+ continue to build all other extensions.
+ - Provide an overview at the top of the output to display
+ what dependencies and their versions were found, and (by
+ extension) what will be built.
+ - Use pkg-config, when available, to find freetype2, since
+ this was broken on Mac OS-X when using MacPorts in a non-
+ standard location.
+
2007-07-30 Reorganized configuration code to work with traited config
objects. The new config system is located in the
matplotlib.config package, but it is disabled by default.
Deleted: trunk/matplotlib/examples/mathtext2_demo.py
===================================================================
--- trunk/matplotlib/examples/mathtext2_demo.py 2007-08-06 18:50:00 UTC (rev 3675)
+++ trunk/matplotlib/examples/mathtext2_demo.py 2007-08-06 18:52:07 UTC (rev 3676)
@@ -1,89 +0,0 @@
-#!/usr/bin/env python
-"""
-
-In order to use mathtext2, you must build matplotlib.ft2font. This is
-built by default in the windows installer.
-
-For other platforms, edit setup.py and set
-
-BUILD_FT2FONT = True
-
-You have to put the following lines in your matplotlibrc file if you want to
-enable mathtext2 globaly (not needed for running this example):
-
-mathtext.mathtext2: True # Needed to enable the new mathtext
-mathtext.rm : FreeSerif.ttf
-mathtext.it : FreeSerifItalic.ttf # Text italic
-mathtext.tt : FreeMono.ttf # Typewriter (monospaced)
-mathtext.mit : FreeSerifItalic.ttf # Math italic
-mathtext.cal : FreeSansOblique.ttf # Caligraphic
-mathtext.nonascii: FreeSerif.ttf # #Used for \sum, \infty etc.
-
-Note that "FreeSerif.ttf" etc. may be replaced by any font. Font files must be
-in your system's font path.
-
-Only the first parameter must be set (mathtext2 uses BaKoMa fonts by
-default, and they come packaged with matplotlib, so the above lines
-override them) because mathtext2 is disabled by default.
-
-This demo assumes that you have FreeSerif.ttf installed.
-You can get FreeSerif.ttf (and other files) from:
-http://download.savannah.gnu.org/releases/freefont/
-if you are on windows. On linux, they are usually shipped by default.
-FreeFonts are distributed under GPL.
-
-"""
-# We override the default params
-from matplotlib import rcParams
-rcParams['mathtext.mathtext2'] = True
-
-# You can put other fonts to override the default ones
-rcParams['mathtext.rm'] = 'FreeSerif.ttf'
-rcParams['mathtext.it'] = 'FreeSerifItalic.ttf'
-rcParams['mathtext.tt'] = 'FreeMono.ttf'
-rcParams['mathtext.mit'] = 'FreeSerifItalic.ttf'
-rcParams['mathtext.cal'] = 'FreeSansOblique.ttf'
-
-# This is used by mathtext2 to find chars with ord > 255 (Unicode characters)
-rcParams['mathtext.nonascii'] = 'FreeSerif.ttf'
-from pylab import *
-subplot(111, axisbg='y')
-plot([1,2,3], 'r')
-x = arange(0.0, 3.0, 0.1)
-grid(True)
-
-tex = r'$1+1\ u_{x^2_1}^{y_{-q_u}}$'
-#text(0.5, 2., tex, fontsize=20)
-#show()
-#xlabel(r'$\Delta_i^j$', fontsize=20)
-#ylabel(r'$\Delta_{i+1}^j$', fontsize=20)
-#tex = r'$\cal{R}\prod_{i=\alpha_{i+1}}^\infty a_i\rm{sin}(2 \pi f x_i)$'
-#tex = ur"$1^j_3$"
-#tex = ur"$Tj_1j_jj_gT$"
-#tex = ur"$F_1^1y_{1_{2_{3_2\sum_1^2{4}^6}}3}1_23$"
-#tex = ur"$x_2{\cal TRALALA}\sum_1^2$"
-#tex = ur"$a = x_2{\cal TRALALA}\sum_1^2$"
-#tex = r'$K_{R osman dsfgs Tralala_{K_4^3}}X_1^1$'
-#tex = ur"$Tutinjac\ fff\sin\exp$"
-#tex = ur"$\sin\exp{\rm sin\ exp}$"
-#tex = ur"$a^{\sin x}\sin b\sin(x/x), {\rm sin}(x/x){\rm sin\ }(x/x)$"
-#tex = ur"$1\frac {\int_{-\infty}^\infty} 22$"
-#tex = ur"$\rm a\vtext{Traktor}b$"
-#tex = ur"$\frac{\int_{-\infty}^\infty} 2$"
-#tex = ur"$1_\frac{\sum^2_{i_{23}=0}} 2678$"
-#tex = ur"$1_{\frac{\sum^2_{i_{23}=0}}{\sum_{i=\frac94}^\infty} 345}678$"
-text(0.5, 2., tex, fontsize=20)
-tex = r'${\cal R}\prod_{i=\alpha_{i+1}}^\infty a_i\sin\exp(2 \pi f x_i)$'
-#text(1, 1.9, tex, fontsize=20)
-tex = ur"$F_1^1y_{1_{2_{3_2\sum_1^2{4}^6}}3}1_23$"
-#text(1, 1.7, tex, fontsize=20)
-tex = ur"$x = \sin(\sum_{i=0}^\infty y_i)$"
-#text(1, 1.5, tex, fontsize=20)
-#title(r'$\Delta_i^j \hspace{0.4} \rm{versus} \hspace{0.4} \Delta_{i+1}^j$', fontsize=20)
-
-savefig('mathtext_demo.png')
-savefig('mathtext_demo.svg')
-savefig('mathtext_demo.ps')
-
-
-show()
Modified: trunk/matplotlib/examples/mathtext_examples.py
===================================================================
--- trunk/matplotlib/examples/mathtext_examples.py 2007-08-06 18:50:00 UTC (rev 3675)
+++ trunk/matplotlib/examples/mathtext_examples.py 2007-08-06 18:52:07 UTC (rev 3676)
@@ -20,8 +20,8 @@
r'$x_y^2$',
r'$\prod_{i=\alpha_{i+1}}^\infty$',
r'$x = \frac{x+\frac{5}{2}}{\frac{y+3}{8}}$',
- r'$dz/dt \/ = \/ \gamma x^2 \/ + \/ {\rm sin}(2\pi y+\phi)$',
- r'Foo: $\alpha_{i+1}^j \/ = \/ {\rm sin}(2\pi f_j t_i) e^{-5 t_i/\tau}$',
+ r'$dz/dt = \gamma x^2 + {\rm sin}(2\pi y+\phi)$',
+ r'Foo: $\alpha_{i+1}^j = {\rm sin}(2\pi f_j t_i) e^{-5 t_i/\tau}$',
r'$\mathcal{R}\prod_{i=\alpha_{i+1}}^\infty a_i \sin(2 \pi f x_i)$',
# r'$\bigodot \bigoplus {\sf R} a_i{\rm sin}(2 \pi f x_i)$',
r'Variable $i$ is good',
@@ -33,7 +33,7 @@
r"$\gamma = \frac{x=\frac{6}{8}}{y} \delta$",
r'$\limsup_{x\to\infty}$',
r'$\oint^\infty_0$',
- r"$f'$",
+ r"$f^'$",
r'$\frac{x_2888}{y}$',
r"$\sqrt[3]{\frac{X_2}{Y}}=5$",
r"$\sqrt[5x\pi]{\prod^\frac{x}{2\pi^2}_\infty}$",
@@ -41,24 +41,29 @@
r'$\frac{X}{\frac{X}{Y}}$',
# From UTR #25
r"$W^{3\beta}_{\delta_1 \rho_1 \sigma_2} = U^{3\beta}_{\delta_1 \rho_1} + \frac{1}{8 \pi 2} \int^{\alpha_2}_{\alpha_2} d \alpha^\prime_2 \left[\frac{ U^{2\beta}_{\delta_1 \rho_1} - \alpha^\prime_2U^{1\beta}_{\rho_1 \sigma_2} }{U^{0\beta}_{\rho_1 \sigma_2}}\right]$",
- r'$\mathcal{H} = \int d \tau (\epsilon E^2 + \mu H^2)$',
- r'$\widehat{abc}\widetilde{def}$'
+ r'$\mathcal{H} = \int d \tau \left(\epsilon E^2 + \mu H^2\right)$',
+ r'$\widehat{abc}\widetilde{def}$',
+ r'$\Gamma \Delta \Theta \Lambda \Xi \Pi \Sigma \Upsilon \Phi \Psi \Omega$',
+ r'$\alpha \beta \gamma \delta \epsilon \zeta \eta \theta \iota \lambda \mu \nu \xi \pi \kappa \rho \sigma \tau \upsilon \phi \chi \psi$'
]
from pylab import *
def doall():
- for i, s in enumerate(stests):
+ tests = stests
+
+ figure(figsize=(8, (len(tests) * 1) + 2))
+ plot([0, 0], 'r')
+ grid(False)
+ axis([0, 3, -len(tests), 0])
+ yticks(arange(len(tests)) * -1)
+ for i, s in enumerate(tests):
print "%02d: %s" % (i, s)
- plot([0,0,3], 'r')
- x = arange(0.0, 3.0, 0.1)
+ text(0.1, -i, s, fontsize=20, markup="tex")
- grid(True)
- text(0.1, 1.6, s, fontsize=20, markup="tex")
+ savefig('mathtext_example')
+ figure()
- savefig('mathtext_example%02d' % i)
- figure()
-
if '--latex' in sys.argv:
fd = open("mathtext_examples.ltx", "w")
fd.write("\\documentclass{article}\n")
Modified: trunk/matplotlib/lib/matplotlib/config/mplconfig.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/config/mplconfig.py 2007-08-06 18:50:00 UTC (rev 3675)
+++ trunk/matplotlib/lib/matplotlib/config/mplconfig.py 2007-08-06 18:52:07 UTC (rev 3676)
@@ -153,21 +153,13 @@
class text(TConfig):
color = T.Trait('black',mplT.ColorHandler())
usetex = T.false
+ markup = T.Trait('plain', 'tex')
class latex(TConfig):
unicode = T.false
preamble = T.ListStr([])
dvipnghack = T.false
- class math(TConfig):
- mathtext2 = T.false
- rm = T.Trait('cmr10.ttf')
- it = T.Trait('cmmi10.ttf')
- tt = T.Trait('cmtt10.ttf')
- mit = T.Trait('cmmi10.ttf')
- cal = T.Trait('cmsy10.ttf')
- nonascii = T.Trait('cmex10.ttf')
-
class axes(TConfig):
hold = T.Trait(True, mplT.BoolHandler())
facecolor = T.Trait('white', mplT.ColorHandler())
@@ -336,6 +328,7 @@
'text.latex.unicode' : (self.tconfig.text.latex, 'unicode'),
'text.latex.preamble' : (self.tconfig.text.latex, 'preamble'),
'text.dvipnghack' : (self.tconfig.text.latex, 'dvipnghack'),
+ 'text.markup' : (self.tconfig.text.markup, 'markup'),
'image.aspect' : (self.tconfig.image, 'aspect'),
'image.interpolation' : (self.tconfig.image, 'interpolation'),
@@ -429,14 +422,6 @@
'svg.image_noscale' : (self.tconfig.backend.svg, 'image_noscale'),
'svg.embed_char_paths' : (self.tconfig.backend.svg, 'embed_chars'),
- # mathtext settings
- 'mathtext.mathtext2' : (self.tconfig.text.math, 'mathtext2'),
- 'mathtext.rm' : (self.tconfig.text.math, 'rm'),
- 'mathtext.it' : (self.tconfig.text.math, 'it'),
- 'mathtext.tt' : (self.tconfig.text.math, 'tt'),
- 'mathtext.mit' : (self.tconfig.text.math, 'mit'),
- 'mathtext.cal' : (self.tconfig.text.math, 'cal'),
- 'mathtext.nonascii' : (self.tconfig.text.math, 'nonascii'),
}
def __setitem__(self, key, val):
Modified: trunk/matplotlib/lib/matplotlib/config/rcsetup.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/config/rcsetup.py 2007-08-06 18:50:00 UTC (rev 3675)
+++ trunk/matplotlib/lib/matplotlib/config/rcsetup.py 2007-08-06 18:52:07 UTC (rev 3676)
@@ -448,16 +448,6 @@
'svg.embed_char_paths' : [False, validate_bool], # True to save
#all characters as paths in the SVG
- # mathtext settings
- 'mathtext.mathtext2' : [False, validate_bool], # Needed to enable Unicode
- # fonts used by mathtext. These ship with matplotlib
- 'mathtext.rm' : ['cmr10.ttf', str], # Roman (normal)
- 'mathtext.it' : ['cmmi10.ttf', str], # Italic
- 'mathtext.tt' : ['cmtt10.ttf', str], # Typewriter (monospaced)
- 'mathtext.mit' : ['cmmi10.ttf', str], # Math italic
- 'mathtext.cal' : ['cmsy10.ttf', str], # Caligraphic
- 'mathtext.nonascii' : ['cmex10.ttf', str], # All other nonascii fonts
-
}
if __name__ == '__main__':
Modified: trunk/matplotlib/lib/matplotlib/mathtext.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/mathtext.py 2007-08-06 18:50:00 UTC (rev 3675)
+++ trunk/matplotlib/lib/matplotlib/mathtext.py 2007-08-06 18:52:07 UTC (rev 3676)
@@ -246,7 +246,7 @@
def render_glyph(self, ox, oy, info):
info.font.draw_glyph_to_bitmap(
- int(ox), int(oy - info.metrics.ymax), info.glyph)
+ ox, oy - info.metrics.ymax, info.glyph)
def render_rect_filled(self, x1, y1, x2, y2):
font = self.fonts_object.get_fonts()[0]
@@ -297,7 +297,7 @@
def render_glyph(self, ox, oy, info):
filename = info.font.fname
oy = self.height - oy + info.offset
-
+
self.pswriter.append(('glyph', ox, oy, filename, info.fontsize, info.num))
def render_rect_filled(self, x1, y1, x2, y2):
@@ -865,7 +865,7 @@
# get any smaller
NUM_SIZE_LEVELS = 4
# Percentage of x-height of additional horiz. space after sub/superscripts
-SCRIPT_SPACE = 0.3
+SCRIPT_SPACE = 0.2
# Percentage of x-height that sub/superscripts drop below the baseline
SUBDROP = 0.3
# Percentage of x-height that superscripts drop below the baseline
@@ -873,7 +873,7 @@
# Percentage of x-height that subscripts drop below the baseline
SUB1 = 0.0
# Percentage of x-height that superscripts are offset relative to the subscript
-DELTA = 0.25
+DELTA = 0.18
class MathTextWarning(Warning):
pass
@@ -1101,19 +1101,20 @@
list in the correct way."""
new_children = []
num_children = len(self.children)
- for i in range(num_children):
- elem = self.children[i]
- if i < num_children - 1:
- next = self.children[i + 1]
- else:
- next = None
+ if num_children:
+ for i in range(num_children):
+ elem = self.children[i]
+ if i < num_children - 1:
+ next = self.children[i + 1]
+ else:
+ next = None
- new_children.append(elem)
- kerning_distance = elem.get_kerning(next)
- if kerning_distance != 0.:
- kern = Kern(kerning_distance)
- new_children.append(kern)
- self.children = new_children
+ new_children.append(elem)
+ kerning_distance = elem.get_kerning(next)
+ if kerning_distance != 0.:
+ kern = Kern(kerning_distance)
+ new_children.append(kern)
+ self.children = new_children
def hpack(self, w=0., m='additional'):
"""The main duty of hpack is to compute the dimensions of the
@@ -1372,9 +1373,15 @@
class HCentered(Hlist):
"""A convenience class to create an Hlist whose contents are centered
within its enclosing box."""
- def __init__(self, elements):
+ def __init__(self, elements, is_accent = False):
+ self.is_accent = is_accent
Hlist.__init__(self, [SsGlue()] + elements + [SsGlue()])
+ def kern(self):
+ Hlist.kern(self)
+ if not self.is_accent and isinstance(self.children[-2], Kern):
+ self.children = self.children[:-2] + [SsGlue()]
+
class VCentered(Hlist):
"""A convenience class to create an Vlist whose contents are centered
within its enclosing box."""
@@ -1982,7 +1989,7 @@
else:
accent = Accent(self._accent_map[accent], state)
shift_amount = accent._metrics.xmin
- centered = HCentered([accent])
+ centered = HCentered([accent], is_accent=True)
centered.hpack(sym.width, 'exactly')
centered.shift_amount = shift_amount
return Vlist([
Deleted: trunk/matplotlib/lib/matplotlib/mathtext2.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/mathtext2.py 2007-08-06 18:50:00 UTC (rev 3675)
+++ trunk/matplotlib/lib/matplotlib/mathtext2.py 2007-08-06 18:52:07 UTC (rev 3676)
@@ -1,1038 +0,0 @@
-r"""
-Supported commands:
--------------------
- * _, ^, to any depth
- * commands for typesetting functions (\sin, \cos etc.),
- * commands for changing the current font (\rm, \cal etc.),
- * Space/kern commands "\ ", \thinspace
- * \frac
-
-Small TO-DO's:
---------------
- * Display braces etc. \} not working (displaying wierd characters) etc.
- * better placing of sub/superscripts. F_1^1y_{1_{2_{3_{4}^3}}3}1_23
- * implement crampedness (or is it smth. else?). y_1 vs. y_1^1
- * add better italic correction. F^1
- * implement other space/kern commands
-
-TO-DO's:
---------
- * \over, \above, \choose etc.
- * Add support for other backends
-
-"""
-import os
-from math import fabs, floor, ceil
-
-from matplotlib import get_data_path, rcParams
-from matplotlib._mathtext_data import tex2uni
-from matplotlib.ft2font import FT2Font, KERNING_DEFAULT
-from matplotlib.font_manager import findSystemFonts
-from copy import deepcopy
-from matplotlib.cbook import Bunch
-
-_path = get_data_path()
-faces = ('mit', 'rm', 'tt', 'cal', 'nonascii')
-
-filenamesd = {}
-fonts = {}
-
-# Filling the above dicts
-for face in faces:
- # The filename without the path
- barefname = rcParams['mathtext.' + face]
- base, ext = os.path.splitext(barefname)
- if not ext:
- ext = '.ttf'
- barefname = base + ext
- # First, we search for the font in the system font dir
- for fname in findSystemFonts(fontext=ext[1:]):
- if fname.endswith(barefname):
- filenamesd[face] = str(fname)
- break
- # We check if the for loop above had success. If it failed, we try to
- # find the font in the mpl-data dir
- if not face in filenamesd:
- fontdirs = [os.path.join(_path,'fonts','afm'),
- os.path.join(_path,'fonts','ttf')]
- for fontdir in fontdirs:
- fname = os.path.join(fontdir, barefname)
- if os.path.exists( fname ):
- filenamesd[face] = fname
- break
- # Display a useful message when the fontfile is not found.
- # TO-DO: Maybe this should just throw a warning to the user?
- try:
- fonts[face] = FT2Font(filenamesd[face])
- except KeyError:
- msg = "Can't find the font file for the '%s' face"%face
- raise KeyError(msg)
-
-svg_elements = Bunch(svg_glyphs=[], svg_lines=[])
-
-esc_char = '\\'
-# Grouping delimiters
-begin_group_char = '{'
-end_group_char = '}'
-dec_delim = '.'
-word_delim = ' '
-mathstyles = ["display", "text", "script", "scriptscript"]
-modes = ["mathmode", "displaymathmode"]
-
-# Commands
-scripts = ("_", "^")
-functions = ("sin", "tan", "cos", "exp", "arctan", "arccos", "arcsin", "cot",
- "lim", "log")
-reserved = ("{", "}", "%", "$", "#", "~")
-# Commands that change the environment (in the current scope)
-setters = faces
-# Maximum number of nestings (groups within groups)
-max_depth = 10
-
-#~ environment = {
-#~ "mode": "mathmode",
-#~ "mathstyle" : "display",
-#~ "cramped" : False,
-#~ # We start with zero scriptdepth (should be incremented by a Scripted
-#~ # instance)
-#~ "scriptdepth" : 0,
-#~ "face" : None,
-#~ "fontsize" : 12,
-#~ "dpi" : 100,
-#~ }
-
-
-# _textclass can be unicode or str.
-_textclass = unicode
-
-
-# Exception classes
-class TexParseError(Exception):
- pass
-
-# Helper classes
-class Scriptfactors(dict):
- """Used for returning the factor with wich you should multiply the
- fontsize to get the font size of the script
-
- """
- _scriptfactors = {
- 0 : 1, # Normal text
- 1: 0.8, # Script
- 2: 0.6, # Scriptscript
- # For keys > 3 returns 0.6
- }
-
- def __getitem__(self, key):
- if not isinstance(key, int):
- raise KeyError("Integer value needed for scriptdepth")
- if key < 0:
- raise KeyError("scriptdepth must be positive")
- if key in self._scriptfactors:
- return self._scriptfactors[key]
- else:
- # Maximum depth of scripts is 2 (scriptscript)
- return self._scriptfactors[2]
-
-scriptfactors = Scriptfactors()
-
-
-class Environment:
- """Class used for representing the TeX environment variables"""
- def __init__(self):
- self.mode = "mathmode"
- self.mathstyle = "display"
- self.cramped = False
- # We start with zero scriptdepth (should be incremented by a Scripted
- # instance)
- self.scriptdepth = 0
- self.face = None
- self.fontsize = 12
- self.dpi = 100
- self.output = "AGG"
-
- def copy(self):
- return deepcopy(self)
-
-# The topmost environment
-environment = Environment()
-
-
-# Helper functions used by the renderer
-def get_frac_bar_height(env):
- # TO-DO: Find a better way to calculate the height of the rule
- c = Char(env, ".")
- return (c.ymax - c.ymin)/2
-
-def get_font(env):
- env = env.copy()
- # TO-DO: Perhaps this should be done somewhere else
- fontsize = env.fontsize * scriptfactors[env.scriptdepth]
- dpi = env.dpi
- if not env.face:
- env.face = "rm"
- font = fonts[env.face]
-
- font.set_size(fontsize, dpi)
- return font
- #~ font = FT2Font(filenamesd[face])
- #~ if fonts:
- #~ fonts[max(fonts.keys()) + 1] = font
- #~ else:
- #~ fonts[1] = font
-
-def infer_face(env, item):
- if item.isalpha():
- if env.mode == "mathmode" and item < "z":
- face = "mit"
- else:
- # TO-DO: Perhaps change to 'rm'
- face = "nonascii"
- elif item.isdigit():
- face = "rm"
- elif ord(item) < 256:
- face = "rm"
- else:
- face = "nonascii"
- return face
-
-def get_space(env):
- _env = env.copy()
- if not _env.face:
- _env.face = "rm"
- space = Char(_env, " ")
- return space
-
-def get_kern(first, second):
- # TO-DO: Something's wrong
- if isinstance(first,Char) and isinstance(second, Char):
- if first.env.__dict__ == second.env.__dict__:
- font = get_font(first.env)
- advance = -font.get_kerning(first.uniindex, second.uniindex,
- KERNING_DEFAULT)/64.0
- #print first.char, second.char, advance
- return Kern(first.env, advance)
- else:
- return Kern(first.env, 0)
- else:
- return Kern(first.env, 0)
-
-
-# Classes used for renderering
-
-# Base rendering class
-class Renderer:
- """Abstract class that implements the rendering methods"""
- def __init__(self, env):
- # We initialize all the values to 0.0
- self.xmin, self.ymin, self.xmax, self.ymax = (0.0,)*4
- self.width, self.height = (0.0,)*2
- (self.hadvance, self.hbearingx, self.hbearingy,
- self.hdescent)= (0.0,)*4
- (self.vadvance, self.vbearingx, self.vbearingy)= (0.0,)*3
- self.env = env
-
- def hrender(self, x, y):
- pass
-
- def vrender(self, x, y):
- # We reuse hrender. This can be used by all subclasses of Renderer
- y += self.vbearingy + self.hbearingy
- x -= -self.vbearingx + self.hbearingx
- self.hrender(x, y)
-
-# Primitive rendering classes
-class Char(Renderer):
- """A class that implements rendering of a single character."""
- def __init__(self, env, char, uniindex=None):
- #Renderer.__init__(self, env)
- self.env = env
- # uniindex is used to override ord(char) (needed on platforms where
- # there is only BMP support for unicode, i.e. windows)
- msg = "A char (string with length == 1) is needed"
- if isinstance(_textclass(char), _textclass) and len(char) == 1:
- self.char = char
- else:
- raise ValueError(msg)
- if not uniindex:
- self.uniindex = ord(char)
- else:
- if isinstance(uniindex, int):
- self.uniindex = uniindex
- else:
- raise ValueError("uniindex must be an int")
- #print self.env.face, filenamesd
- # TO-DO: This code is needed for BaKoMa fonts. To be removed when
- # mathtext migrates to completely unicode fonts
- if self.env.face == "rm" and filenamesd["rm"].endswith("cmr10.ttf"):
- _env = self.env.copy()
- if self.char in ("{", "}"):
- _env.face = "cal"
- font = get_font(_env)
- if self.char == "{":
- index = 118
- elif self.char == "}":
- index = 119
- glyph = font.load_char(index)
- else:
- font = get_font(self.env)
- glyph = font.load_char(self.uniindex)
- else:
- font = get_font(self.env)
- glyph = font.load_char(self.uniindex)
- self.glyph = glyph
- self.xmin, self.ymin, self.xmax, self.ymax = [
- val/64.0 for val in self.glyph.bbox]
-
- self.width = self.xmax - self.xmin#glyph.width/64.0
- self.height = self.ymax - self.ymin#glyph.height/64.0
- # Horizontal values
- self.hadvance = glyph.horiAdvance/64.0
- self.hbearingx = glyph.horiBearingX/64.0
- self.hbearingy = glyph.horiBearingY/64.0
- # Vertical values
- self.vadvance = glyph.vertAdvance/64.0
- self.vbearingx = glyph.vertBearingX/64.0
- self.vbearingy = glyph.vertBearingY/64.0
-
- def hrender(self, x, y):
- #y -= self.ymax
- #y -= (self.height - self.hbearingy)
- #print x, y
- font = get_font(self.env)
- output = self.env.output
- if output == "AGG":
- x += self.hbearingx
- y -= self.hbearingy
- font.draw_glyph_to_bitmap(x, y, self.glyph)
- elif output == "SVG":
- familyname = font.get_sfnt()[(1,0,0,1)]
- thetext = unichr(self.uniindex)
- thetext.encode('utf-8')
- fontsize = self.env.fontsize * scriptfactors[self.env.scriptdepth]
- svg_elements.svg_glyphs.append((familyname, fontsize,thetext, x, y,
- Bunch(advance=self.hadvance))) # last was originaly metrics (in old mathtext)
-
-
-class Kern(Renderer):
- """Class that implements the rendering of a Kern."""
-
- def __init__(self, env, hadvance):
- Renderer.__init__(self, env)
- self.width = hadvance
- self.hadvance = hadvance
-
- def __repr__(self):
- return "Kern(%s, %s)"%(self.env, self.hadvance)
-
-class Line(Renderer):
- """Class that implements the rendering of a line."""
-
- def __init__(self, env, width, height):
- Renderer.__init__(self, env)
- self.ymin = -height/2.
- self.xmax = width
- self.ymax = height/2.
-
- self.width = width
- self.height = height
- self.hadvance = width
- self.hbearingy = self.ymax
- # vertical
- self.vadvance = height
- self.vbearingx = - width/2.0
-
- def hrender(self, x, y):
- font = get_font(self.env)
- coords = (x + self.xmin, y + self.ymin, x + self.xmax,
- y + self.ymax)
- #print coords
- #print "\n".join(repr(self.__dict__).split(","))
- if self.env.output == "AGG":
- coords = (coords[0]+2, coords[1]-1, coords[2]-2,
- coords[3]-1)
- #print coords
- font.draw_rect_filled(*coords)
- elif self.env.output == "SVG":
- svg_elements.svg_lines.append(coords)
- #~ familyname = font.get_sfnt()[(1,0,0,1)]
- #~ svg_elements.svg_glyphs.append((familyname, self.env.fontsize,
- #~ "---", x,y, None))
-
-
-# Complex rendering classes
-class Hbox(Renderer):
- """A class that corresponds to a TeX hbox."""
- def __init__(self, env, texlist=[]):
- Renderer.__init__(self, env)
- self.items = texlist
- if not self.items:
- # empty group
- return
- previous = None
- for item in self.items:
- # Checking for kerning
- if previous:
- kern = get_kern(previous, item)
- item.hadvance += kern.hadvance
- self.hbearingy = max((item.hbearingy, self.hbearingy))
- self.ymax = max((item.ymax, self.ymax))
- if self.ymin == 0:
- self.ymin = item.ymin
- else:
- self.ymin = min((item.ymin, self.ymin))
- self.hadvance += item.hadvance
- # vertical
- self.vadvance = max((item.vadvance, self.vadvance))
- if self.vbearingy == 0:
- self.vbearingy = item.vbearingy
- else:
- self.vbearingy = min(item.vbearingy, self.vbearingy)
- previous = item
- first = self.items[0]
- self.hbearingx = 0#first.hbearingx
- self.xmin = 0#first.xmin
-
- last = self.items[-1]
- self.xmax = self.hadvance# + fabs(last.hadvance - last.xmax)
- self.xmax -= first.hbearingx
- self.width = self.xmax - self.xmin
- self.height = self.ymax - self.ymin
- # vertical
- self.vbearingx = - self.width/2.0
-
- def hrender(self, x, y):
- for item in self.items:
- item.hrender(x, y)
- x += item.hadvance
-
-# TO-DO
-class Vbox(Renderer):
- """A class representing a vertical box. ref is the index of the texlist
- element whose origin will be used as the vbox origin. The default is
- ref=-1. If ref is None, then ref is set to be the middle index (if the
- number of items in the list is even, a new list element is inserted (as
- Kern(0)) to make the list odd).
- The box is rendered top down - the last element of the list is rendered
- at the bottom.
-
- """
- def __init__(self, env, texlist=[], ref=None):
- if ref == None:
- if not len(texlist)%2:
- texlist = texlist.insert(len(texlist)/2,Kern(env, 0))
- ref = len(texlist)/2
- if ref < 0:
- ref = len(texlist) + ref
- Renderer.__init__(self, env)
-
- self.items = texlist
- if not self.items:
- return
-
- for i, item in enumerate(self.items):
- if i == 0:
- self.vbearingy = item.vbearingy
- if i == ref:
- # ymax is determined by the reference item
- if self.vadvance == 0:
- #self.ymax = item.ymax
- self.hbearingy = item.hbearingy
- else:
- #self.ymax = self.vadvance + item.ymax + item.vbearingy
- self.hbearingy = self.vadvance + item.hbearingy +\
- item.vbearingy
- self.width = max(self.width, item.width)
- if self.width < item.width:
- self.width = item.width
- self.hbearingx = item.hbearingx
- self.hadvance = max(self.hadvance, item.hadvance)
- self.vbearingx = min(self.vbearingx, item.vbearingx)
- self.vadvance += item.vadvance
- if i == len(self.items) - 1:
- # last item
- if i == 0:
- self.ymin = item.ymin
- else:
- _overlap = item.vadvance - item.height -item.vbearingy
- self.ymin = -(self.vadvance - _overlap - self.hbearingy)
- self.xmin = self.hbearingx
- self.xmax = self.xmin + self.width
-
- self.ymax = self.hbearingy
- self.height = self.ymax - self.ymin
-
- def hrender(self, x, y):
- # We reuse vrender.
- print "H"
- y -= self.vbearingy + self.hbearingy
- x += -self.vbearingx + self.hbearingx
- self.vrender(x, y)
-
- def vrender(self, x, y):
- print "V"
- #print "\n".join(repr(self.__dict__).split(","))
- for item in self.items:
- for key in item.__dict__:
- try:
- print key, getattr(self, key), getattr(item, key)
- except AttributeError:
- pass
- #print "\n".join(repr(item.__dict__).split(","))
- item.vrender(x, y)
- y += item.vadvance
-
-class Scripted(Renderer):
- """Used for creating elements that have sub/superscripts"""
- def __init__(self, env, nuc=None, type="ord", sub=None,
- sup=None):
- Renderer.__init__(self, env)
- if not nuc:
- nuc = Hbox([])
- if not sub:
- sub = Hbox([])
- if not sup:
- sup = Hbox([])
- self.nuc = nuc
- self.sub = sub
- self.sup = sup
- self.type = type
- # Heuristics for figuring out how much the subscripts origin has to be
- # below the origin of the nucleus (the descent of the letter "j").
- # TO-DO: Change with a better alternative. Not working: F_1^1y_1
- c = Char(env, "j")
- C = Char(env, "M")
-
- self.subpad = c.height - c.hbearingy
- # If subscript is complex (i.e. a large Hbox - fraction etc.)
- # we have to aditionaly lower the subscript
- if sub.ymax > (C.height/2.1 + self.subpad):
- self.subpad = sub.ymax - C.height/2.1
-
- #self.subpad = max(self.subpad)
- #self.subpad = 0.5*sub.height
- # Similar for the superscript
- self.suppad = max(nuc.height/1.9, C.ymax/1.9) - sup.ymin# - C.hbearingy
-
-
- #self.hadvance = nuc.hadvance + max((sub.hadvance, sup.hadvance))
-
- self.xmin = nuc.xmin
-
- self.xmax = max(nuc.hadvance, nuc.hbearingx + nuc.width) +\
- max((sub.hadvance, sub.hbearingx + sub.width,
- sup.hadvance, sup.hbearingx + sup.width))# - corr
-
- self.ymin = min(nuc.ymin, -self.subpad + sub.ymin)
-
- self.ymax = max((nuc.ymax, self.suppad + sup.hbearingy))
-
- # The bearing of the whole element is the bearing of the nucleus
- self.hbearingx = nuc.hbearingx
- self.hadvance = self.xmax
- # Heruistics. Feel free to change
- self.hbearingy = self.ymax
-
- self.width = self.xmax - self.xmin
- self.height = self.ymax - self.ymin
- # vertical
- self.vadvance = self.height
- self.vbearingx = - self.width/2.0
-
- def hrender(self, x, y):
- nuc, sub, sup = self.nuc, self.sub, self.sup
- nx = x
- ny = y
-
- subx = x + max(nuc.hadvance, nuc.hbearingx + nuc.width)# + sub.hbearingx
- suby = y + self.subpad# - subfactor*self.env.fontsize
-
- supx = x + max(nuc.hadvance, nuc.hbearingx + nuc.width)# + sup.hbearingx
- supy = y - self.suppad# + 10#subfactor*self.env.fontsize
-
- self.nuc.hrender(nx, ny)
- self.sub.hrender(subx, suby)
- self.sup.hrender(supx, supy)
-
- def __repr__(self):
- tmp = [repr(i) for i in [self.env, self.nuc, self.type,
- self.sub, self.sup]]
- tmp = tuple(tmp)
- return "Scripted(env=%s,nuc=%s, type=%s, \
-sub=%s, sup=%s)"%tmp
-
-
-class Fraction(Renderer):
- """A class for rendering a fraction."""
-
- def __init__(self, env, num, den):
- Renderer.__init__(self, env)
- self.numer = num
- self.denom = den
-
- # TO-DO: Find a better way to implement the fraction bar
- self.pad = get_frac_bar_height(self.env)
- pad = self.pad
- self.bar = Line(env.copy(), max(num.width, den.width) + 2*pad, pad)
- #~ self.bar.hbearingx = pad
- #~ self.bar.hadvance = self.bar.width + 2*pad
- #~ self.bar.hbearingy = pad + pad
-
- self.xmin = 0
- #self.xmax = self.bar.hadvance
- self.xmax = self.bar.width# + 2*pad
-
- self.ymin = -(2*pad + den.height)
- self.ymax = 2*pad + num.height
- # The amount by which we raise the bar (the whole fraction)
- # of the bottom (origin)
- # TO-DO: Find a better way to implement it
- _env = env.copy()
- _env.face = "rm"
- c = Char(_env, "+")
- self.barpad = 1./2.*(c.ymax-c.ymin) + c.ymin
- self.ymin += self.barpad
- self.ymax += self.barpad
-
- self.width = self.xmax - self.xmin
- self.height = self.ymax - self.ymin
- #print self.width, self.height
-
- #self.hbearingx = pad
- self.hbearingx = 0
- self.hbearingy = self.ymax
- #self.hadvance = self.bar.hadvance
- self.hadvance = self.xmax
- # vertical
- self.vbearingx = - self.width/2.0
- self.vbearingy = num.vbearingy
- self.vadvance = self.height + num.vbearingy + (den.vadvance + den.ymin)
-
- def hrender(self, x, y):
- y -= self.barpad
- pad = self.pad
- #print self.bar.xmax, self.bar.xmin, self.bar.ymin, self.bar.ymax
- self.bar.hrender(x, y)
-
- nx = x - self.numer.hbearingx + (self.width - self.numer.width)/2.
- ny = y - 2*pad - (self.numer.height - self.numer.ymax)
- self.numer.hrender(nx, ny)
-
- dx = x - self.denom.hbearingx+ (self.width - self.denom.width)/2.
- dy = y + 2*pad + self.denom.hbearingy
- self.denom.hrender(dx, dy)
-
-
-
-
-# Helper functions used by the parser
-def parse_tex(texstring):
- texstring = normalize_tex(texstring)
- _parsed = to_list(texstring)
- #_parsed = Hbox(_parsed)
- return _parsed
-
-def remove_comments(texstring):
- # TO-DO
- return texstring
-
-def group_split(texstring):
- """Splits the string into three parts based on the grouping delimiters,
- and returns them as a list.
- """
- if texstring == begin_group_char + end_group_char:
- return '', [], ''
- length = len(texstring)
- i = texstring.find(begin_group_char)
- if i == -1:
- return texstring, '', ''
- pos_begin = i
- count = 1
- num_groups = 0
- while count != 0:
- i = i + 1
- # First we check some things
- if num_groups > max_depth:
- message = "Maximum number of nestings reached. Too many groups"
- raise TexParseError(message)
- if i == length:
- message = "Group not closed properly"
- raise TexParseError(message)
-
- if texstring[i] == end_group_char:
- count -= 1
- elif texstring[i] == begin_group_char:
- num_groups += 1
- count += 1
- before = texstring[:pos_begin]
- if pos_begin + 1 == i:
- grouping = []
- else:
- grouping = texstring[pos_begin + 1:i]
- after = texstring[i + 1:]
- return before, grouping, after
-
-def break_up_commands(texstring):
- """Breaks up a string (mustn't contain any groupings) into a list
- of commands and pure text.
- """
- result = []
- if not texstring:
- return result
- _texstrings = texstring.split(esc_char)
- for i, _texstring in enumerate(_texstrings):
- _command, _puretext = split_command(_texstring)
- if i == 0 and _texstrings[0]:
- # Case when the first command is a not a command but text
- result.extend([c for c in _command])
- result.extend(_puretext)
- continue
- if _command:
- result.append(esc_char + _command)
- if _puretext:
- if _puretext[0] == word_delim:
- _puretext = _puretext[1:]
- result.extend(_puretext)
- return result
-
-def split_command(texstring):
- """Splits a texstring into a command part and a pure text (as a list) part
-
- """
- if not texstring:
- return "", []
- _puretext = []
- _command, _rest = get_first_word(texstring)
- if not _command:
- _command = texstring[0]
- _rest = texstring[1:]
- _puretext = [c for c in _rest]
- #~ while True:
- #~ _word, _rest = get_first_word(_rest)
- #~ if _word:
- #~ _puretext.append(_word)
- #~ if _rest:
- #~ _puretext.extend(_rest[0])
- #~ if len(_rest) == 1:
- #~ break
- #~ _rest = _rest[1:]
- #~ else:
- #~ break
- return _command, _puretext
-
-def get_first_word(texstring):
- _word = ""
- i = 0
- _length = len(texstring)
- if _length == 0:
- return "", ""
- if texstring[0].isalpha():
- while _length > i and texstring[i].isalpha():
- _word += texstring[i]
- i = i + 1
- elif texstring[0].isdigit():
- while _length > i and (texstring[i].isdigit()):
- _word += texstring[i]
- i = i + 1
-
- return _word, texstring[i:]
-
-def to_list(texstring):
- """Parses the normalized tex string and returns a list. Used recursively.
- """
- result = []
- if not texstring:
- return result
- # Checking for groupings: begin_group_char...end_group_char
- before, grouping, after = group_split(texstring)
- #print "Before: ", before, '\n', grouping, '\n', after
-
- if before:
- result.extend(break_up_commands(before))
- if grouping or grouping == []:
- result.append(to_list(grouping))
- if after:
- result.extend(to_list(after))
-
- return result
-
-def normalize_tex(texstring):
- """Normalizes the whole TeX expression (that is: prepares it for
- parsing)"""
- texstring = remove_comments(texstring)
- # Removing the escaped escape character (replacing it)
- texstring = texstring.replace(esc_char + esc_char, esc_char + 'backslash ')
-
- # Removing the escaped scope/grouping characters
- texstring = texstring.replace(esc_char + begin_group_char, esc_char + 'lbrace ')
- texstring = texstring.replace(esc_char + end_group_char, esc_char + 'rbrace ')
-
- # Now we should have a clean expression, so we check if all the groupings
- # are OK (every begin_group_char should have a matching end_group_char)
- # TO-DO
-
- # Replacing all space-like characters with a single space word_delim
- texstring = word_delim.join(texstring.split())
-
- # Removing unnecessary white space
- texstring = word_delim.join(texstring.split())
- return texstring
-
-def is_command(item):
- try:
- return item.startswith(esc_char)
- except AttributeError:
- return False
-
-
-
-
-# Main parser functions
-def handle_tokens(texgroup, env, box=Hbox):
- """Scans the entire (tex)group to handle tokens. Tokens are other groups,
- commands, characters, kerns etc. Used recursively.
-
- """
- result = []
- # So we're sure that nothing changes the outer environment
- env = env.copy()
- while texgroup:
- item = texgroup.pop(0)
- #print texgroup, type(texgroup)
- #print env.face, type(item), repr(item)
- if isinstance(item, list):
- appendix = handle_tokens(item, env.copy())
- elif item in scripts:
- sub, sup, texgroup = handle_scripts(item, texgroup, env.copy())
- try:
- nuc = result.pop()
- except IndexError:
- nuc = Hbox([])
- appendix = Scripted(env.copy(), nuc=nuc, sub=sub, sup=sup)
- elif is_command(item):
- command = item.strip(esc_char)
- texgroup, env = handle_command(command, texgroup, env.copy(),
- allowsetters=True)
- continue
- elif isinstance(item, _textclass):
- if env.mode == "mathmode":
- if item == word_delim:
- # Disregard space in mathmode
- continue
- elif item == "-":
- # load the math minus sign
- item = u"\u2212"
- uniindex = ord(item)
- appendix = handle_char(uniindex, env.copy())
- else:
- appendix = item
- result.append(appendix)
- return box(env.copy(),result)
-
-def handle_command(command, texgroup, env, allowsetters=False):
- """Handles TeX commands that don't have backward propagation, and
- aren't setting anything in the environment.
-
- """
- # First we deal with setters - commands that change the
- # environment of the current group (scope)
- if command in setters:
- if not allowsetters:
- raise TexParseError("Seter not allowed here")
- if command in faces:
- env.face = command
- else:
- raise TexParseError("Unknown setter: %s%s"%(esc_char, command))
- return texgroup, env
- elif command == "frac":
- texgroup, args = get_args(command, texgroup, env.copy(), 2)
- num, den = args
- frac = Fraction(env=env, num=num, den=den)
- appendix = frac
- elif command in functions:
- _tex = "%srm %sthinspace %s"%(esc_char, esc_char, command)
- appendix = handle_tokens(parse_tex(_tex), env.copy())
- elif command in (" "):
- space = get_space(env)
- appendix = Kern(env, space.hadvance)
- elif command == "thinspace":
- #print command
- space = get_space(env)
- appendix = Kern(env, 1/2. * space.hadvance)
- elif command in reserved:
- uniindex = ord(command)
- appendix = handle_char(uniindex, env.copy())
- #elif command == "vtext":
- # _vlist = texgroup.pop(0)
- # appendix = handle_tokens(_vlist, env.copy(), box=Vbox)
- elif command in tex2uni:
- uniindex = tex2uni[command]
- appendix = handle_char(uniindex, env.copy())
- else:
- #appendix = handle_tokens([r"\backslash"] + [
- #~ c for c in command], env.copy())
- #appendix.env = env.copy()
- #print appendix
- raise TexParseError("Unknown command: " + esc_char + command)
- appendix = [appendix]
- appendix.extend(texgroup)
- #print "App",appendix
- return appendix, env
-
-def handle_scripts(firsttype, texgroup, env):
- sub = None
- sup = None
- env = env.copy()
- # The environment for the script elements
- _env = env.copy()
- _env.scriptdepth += 1
- firstscript = texgroup.pop(0)
- if firstscript in scripts:
- # An "_" or "^", immediately folowed by another "_" or "^"
- raise TexParseError("Missing { inserted. " + firsttype + firstscript)
- elif is_command(firstscript):
- command = firstscript.strip(esc_char)
- texgroup, _env = handle_command(command, texgroup, _env)
- firstscript = texgroup.pop(0)
- else:
- _tmp = handle_tokens([firstscript], _env)
- firstscript = _tmp.items.pop(0)
- if firsttype == "_":
- sub = firstscript
- else:
- sup = firstscript
- # Check if the next item is also a command for scripting
- try:
- second = texgroup[0]
- except IndexError:
- second = None
- if second in scripts:
- secondtype = texgroup.pop(0)
- if secondtype == firsttype:
- raise TexParseError("Double script: " + secondtype)
- try:
- secondscript = texgroup.pop(0)
- except IndexError:
- raise TexParseError("Empty script: " + secondtype)
- if secondscript in scripts:
- # An "_" or "^", immediately folowed by another "_" or "^"
- raise TexParseError("Missing { inserted. "\
- + secondtype + secondscript)
- elif is_command(secondscript):
- command = secondscript.strip(esc_char)
- texgroup, _env = handle_command(command, texgroup, _env)
- secondscript = texgroup.pop(0)
- else:
- _tmp = handle_tokens([secondscript], _env)
- secondscript = _tmp.items.pop(0)
- if secondtype == "_":
- sub = secondscript
- else:
- sup = secondscript
- # Check if the next item is also a command for scripting
- try:
- next = texgroup[0]
- except IndexError:
- next = None
- if next in scripts:
- raise TexParseError("Double script: " + next)
- return sub, sup, texgroup
-
-def handle_char(uniindex, env):
- env = env.copy()
- char = unichr(uniindex)
- if not env.face:
- env.face = infer_face(env, char)
- return Char(env, char, uniindex=uniindex)
-
-def get_args(command, texgroup, env, num_args):
- """Returns the arguments needed by a TeX command"""
- args = []
- i = 0
- while i < num_args:
- try:
- arg = texgroup.pop(0)
- except IndexError:
- msg = "%s is missing it's %d argument"%(command, i+1)
- raise TexParseError(msg)
- # We skip space
- if arg == " ":
- continue
- tmp = handle_tokens([arg], env.copy())
- arg = tmp.items.pop()
- args.append(arg)
- i += 1
- return texgroup, args
-
-
-# Functions exported to backends
-def math_parse_s_ft2font(s, dpi, fontsize, angle=0, output="AGG"):
- """This function is called by the backends"""
- # Reseting the variables used for rendering
- for font in fonts.values():
- font.clear()
- svg_elements.svg_glyphs = []
- svg_elements.svg_lines = []
-
- s = s[1:-1]
- parsed = parse_tex(_textclass(s))
- env = environment.copy()
- env.dpi = dpi
- env.fontsize = fontsize
- env.output = output
- parsed = handle_tokens(parsed, env)
- #print "\n".join(str(parsed.__dict__).split(","))
- width, height = parsed.width + 2, parsed.height + 2
- #print width, height
- if output == "AGG":
- for key in fonts:
- fonts[key].set_bitmap_size(width, height)
- parsed.hrender(-parsed.items[0].hbearingx, height + parsed.ymin - 1)
- #~ parsed.hrender(-parsed.hbearingx, height - 1 - (
- #~ parsed.height - parsed.hbearingy))
- if output == "AGG":
- return width, height, fonts.values()
- elif output == "SVG":
- return width, height, svg_elements
-
-def math_parse_s_ft2font_svg(s, dpi, fontsize, angle=0):
- return math_parse_s_ft2font(s, dpi, fontsize, angle, "SVG")
-
-def math_parse_s_ft2font1(s, dpi, fontsize, angle=0):
- "Used only for testing"
- s = s[1:-1]
- parsed = parse_tex(_textclass(s))
- env = environment.copy()
- env.dpi = dpi
- env.fontsize = fontsize
- parsed = handle_tokens(parsed, env)
- #print "\n".join(str(parsed.__dict__).split(","))
- width, height = parsed.width + 10, parsed.height + 10
- width, height = 300, 300
- #print width, height
- for key in fonts:
- fonts[key].set_bitmap_size(width, height)
- parsed.hrender(width/2., height/2.)
- #fonts["mit"].draw_rect(0, 0, 40, 0)
- #fonts["mit"].draw_rect(0, 1, 40, 0)
- #parsed.hrender(20, 20)
- #~ parsed.hrender(-parsed.hbearingx, height - 1 - (
- #~ parsed.height - parsed.hbearingy))
- _fonts = fonts.values()
- return width, height, _fonts
-
-
-if __name__ == '__main__':
- pass
- #texstring = r"\\{ \horse\ Hello\^ ^ a^b_c}"
- #texstring = r" asdf { \horse{}tralala1234\ \zztop{} \ Hello\^^a^{b_c}}"
- #texstring = r"{}{} { }"
- #texstring = r"{{{_ }}}"
- #texstring = r"\horse{}"
- #texstring = r"\horse;,.?)_)(*(*^*%&$$%{} Haha! Kako je frajeru?"
- #texstring = r"a_2\trav 32"
- #texstring = r"a_24{\sum_4^5} _3"
- #texstring = _textclass(r"1_2^{4^5}32 5")
- #parsed = parse_tex(texstring)
- #~ print bool(a)
- #print is_scriptcommand('\\subscript')
Modified: trunk/matplotlib/lib/matplotlib/mpl-data/matplotlibrc
===================================================================
--- trunk/matplotlib/lib/matplotlib/mpl-data/matplotlibrc 2007-08-06 18:50:00 UTC (rev 3675)
+++ trunk/matplotlib/lib/matplotlib/mpl-data/matplotlibrc 2007-08-06 18:52:07 UTC (rev 3676)
@@ -26,7 +26,7 @@
#### CONFIGURATION BEGINS HERE
# the default backend; one of GTK GTKAgg GTKCairo FltkAgg QtAgg TkAgg
# Agg Cairo GD GDK Paint PS PDF SVG Template
-backend : TkAgg
+backend : WXAgg
numerix : numpy # numpy, Numeric or numarray
#maskedarray : False # True to use external maskedarray module
# instead of numpy.ma; this is a temporary
@@ -150,6 +150,14 @@
#text.dvipnghack : False # some versions of dvipng don't handle
# alpha channel properly. Use True to correct and flush
# ~/.matplotlib/tex.cache before testing
+#text.markup : 'plain' # Affects how text, such as titles and lables, are
+ # interpreted by default.
+ # 'plain': As plain, unformatted text
+ # 'tex': As TeX-like text. Text between $'s will be
+ # formatted as a TeX math expression.
+ # This setting has no effect when text.usetex is True.
+ # In that case, all text will be sent to TeX for
+ # processing.
### AXES
# default face and edge color, default tick sizes,
Modified: trunk/matplotlib/lib/matplotlib/rcsetup.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/rcsetup.py 2007-08-06 18:50:00 UTC (rev 3675)
+++ trunk/matplotlib/lib/matplotlib/rcsetup.py 2007-08-06 18:52:07 UTC (rev 3676)
@@ -458,16 +458,6 @@
'svg.embed_char_paths' : [False, validate_bool], # True to save all characters as paths in the SVG
'plugins.directory' : ['.matplotlib_plugins', str], # where plugin directory is locate
- # mathtext settings
- 'mathtext.mathtext2' : [False, validate_bool], # Needed to enable Unicode
- # fonts used by mathtext. These ship with matplotlib
- 'mathtext.rm' : ['cmr10.ttf', str], # Roman (normal)
- 'mathtext.it' : ['cmmi10.ttf', str], # Italic
- 'mathtext.tt' : ['cmtt10.ttf', str], # Typewriter (monospaced)
- 'mathtext.mit' : ['cmmi10.ttf', str], # Math italic
- 'mathtext.cal' : ['cmsy10.ttf', str], # Caligraphic
- 'mathtext.nonascii' : ['cmex10.ttf', str], # All other nonascii fonts
-
}
if __name__ == '__main__':
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <md...@us...> - 2007-08-06 18:50:03
|
Revision: 3675
http://matplotlib.svn.sourceforge.net/matplotlib/?rev=3675&view=rev
Author: mdboom
Date: 2007-08-06 11:50:00 -0700 (Mon, 06 Aug 2007)
Log Message:
-----------
Fix bug when rendering special XML characters (such as < > &) in SVG
Modified Paths:
--------------
trunk/matplotlib/lib/matplotlib/backends/backend_svg.py
Modified: trunk/matplotlib/lib/matplotlib/backends/backend_svg.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/backends/backend_svg.py 2007-08-06 18:49:19 UTC (rev 3674)
+++ trunk/matplotlib/lib/matplotlib/backends/backend_svg.py 2007-08-06 18:50:00 UTC (rev 3675)
@@ -11,6 +11,8 @@
from matplotlib.ft2font import FT2Font, KERNING_UNFITTED, KERNING_DEFAULT, KERNING_UNSCALED
from matplotlib.mathtext import math_parse_s_ft2font_svg
+from xml.sax.saxutils import escape as escape_xml_text
+
backend_version = __version__
def new_figure_manager(num, *args, **kwargs):
@@ -239,7 +241,7 @@
font = self._get_font(prop)
- thetext = '%s' % s
+ thetext = escape_xml_text(s)
fontfamily = font.family_name
fontstyle = font.style_name
fontsize = prop.get_size_in_points()
@@ -369,10 +371,7 @@
curr_x,curr_y = 0.0,0.0
for font, fontsize, thetext, new_x, new_y_mtc, metrics in svg_glyphs:
- if rcParams["mathtext.mathtext2"]:
- new_y = new_y_mtc - height
- else:
- new_y = - new_y_mtc
+ new_y = - new_y_mtc
svg.append('<tspan style="font-size: %f; font-family: %s"' %
(fontsize, font.family_name))
@@ -387,6 +386,8 @@
if dy != 0.0:
svg.append(' dy="%f"' % dy)
+ thetext = escape_xml_text(thetext)
+
svg.append('>%s</tspan>\n' % thetext)
curr_x = new_x + xadvance
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <md...@us...> - 2007-08-06 18:49:20
|
Revision: 3674
http://matplotlib.svn.sourceforge.net/matplotlib/?rev=3674&view=rev
Author: mdboom
Date: 2007-08-06 11:49:19 -0700 (Mon, 06 Aug 2007)
Log Message:
-----------
Fix bug when rendering character codes > 255 in PDF
Modified Paths:
--------------
trunk/matplotlib/lib/matplotlib/backends/backend_pdf.py
Modified: trunk/matplotlib/lib/matplotlib/backends/backend_pdf.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/backends/backend_pdf.py 2007-08-03 19:47:49 UTC (rev 3673)
+++ trunk/matplotlib/lib/matplotlib/backends/backend_pdf.py 2007-08-06 18:49:19 UTC (rev 3674)
@@ -1103,7 +1103,7 @@
oldx, oldy = 0, 0
for record in pswriter:
if record[0] == 'glyph':
- rec_type, ox, oy, fontname, fontsize, glyph = record
+ rec_type, ox, oy, fontname, fontsize, num = record
a = angle / 180.0 * pi
newx = x + cos(a)*ox - sin(a)*oy
newy = y + sin(a)*ox + cos(a)*oy
@@ -1114,7 +1114,10 @@
Op.selectfont)
prev_font = fontname, fontsize
- string = chr(glyph)
+ if num < 256:
+ string = chr(num)
+ else:
+ string = "?"
self.file.output(string, Op.show)
self.file.output(Op.end_text)
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <md...@us...> - 2007-08-03 19:47:51
|
Revision: 3673
http://matplotlib.svn.sourceforge.net/matplotlib/?rev=3673&view=rev
Author: mdboom
Date: 2007-08-03 12:47:49 -0700 (Fri, 03 Aug 2007)
Log Message:
-----------
Fix superscript offset bug (only offset when nucleus is slanted)
Modified Paths:
--------------
trunk/matplotlib/lib/matplotlib/_mathtext_data.py
trunk/matplotlib/lib/matplotlib/mathtext.py
Modified: trunk/matplotlib/lib/matplotlib/_mathtext_data.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/_mathtext_data.py 2007-08-03 18:30:25 UTC (rev 3672)
+++ trunk/matplotlib/lib/matplotlib/_mathtext_data.py 2007-08-03 19:47:49 UTC (rev 3673)
@@ -68,17 +68,6 @@
r'\imath' : ('cmmi10', 8),
r'\jmath' : ('cmmi10', 65),
r'\wp' : ('cmmi10', 14),
- r'\Gamma' : ('cmmi10', 37),
- r'\Delta' : ('cmmi10', 11),
- r'\Theta' : ('cmmi10', 12),
- r'\Lambda' : ('cmmi10', 26),
- r'\Xi' : ('cmmi10', 4),
- r'\Pi' : ('cmmi10', 33),
- r'\Sigma' : ('cmmi10', 16),
- r'\Upsilon' : ('cmmi10', 19),
- r'\Phi' : ('cmmi10', 15),
- r'\Psi' : ('cmmi10', 27),
- r'\Omega' : ('cmmi10', 23),
r'\alpha' : ('cmmi10', 13),
r'\beta' : ('cmmi10', 35),
r'\gamma' : ('cmmi10', 24),
@@ -128,6 +117,17 @@
r'%' : ('cmr10', 48),
r'\$' : ('cmr10', 99),
r'@' : ('cmr10', 111),
+ r'\Gamma' : ('cmr10', 19),
+ r'\Delta' : ('cmr10', 6),
+ r'\Theta' : ('cmr10', 7),
+ r'\Lambda' : ('cmr10', 14),
+ r'\Xi' : ('cmr10', 3),
+ r'\Pi' : ('cmr10', 17),
+ r'\Sigma' : ('cmr10', 10),
+ r'\Upsilon' : ('cmr10', 11),
+ r'\Phi' : ('cmr10', 9),
+ r'\Psi' : ('cmr10', 15),
+ r'\Omega' : ('cmr10', 12),
# these are mathml names, I think. I'm just using them for the
# tex methods noted
Modified: trunk/matplotlib/lib/matplotlib/mathtext.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/mathtext.py 2007-08-03 18:30:25 UTC (rev 3672)
+++ trunk/matplotlib/lib/matplotlib/mathtext.py 2007-08-03 19:47:49 UTC (rev 3673)
@@ -482,7 +482,7 @@
if bunch is not None:
return bunch
- cached_font, num, symbol_name, fontsize = \
+ cached_font, num, symbol_name, fontsize, slanted = \
self._get_glyph(fontname, sym, fontsize)
font = cached_font.font
@@ -500,7 +500,8 @@
ymin = ymin+offset,
ymax = ymax+offset,
# iceberg is the equivalent of TeX's "height"
- iceberg = glyph.horiBearingY/64.0 + offset
+ iceberg = glyph.horiBearingY/64.0 + offset,
+ slanted = slanted
)
self.glyphd[key] = Bunch(
@@ -558,13 +559,17 @@
return glyph.height/64.0/2.0 + 256.0/64.0 * dpi/72.0
return 0.
+ _slanted_symbols = Set(r"\int \oint".split())
+
def _get_glyph(self, fontname, sym, fontsize):
if fontname in self.fontmap and latex_to_bakoma.has_key(sym):
basename, num = latex_to_bakoma[sym]
+ slanted = basename == "cmmi10" or sym in self._slanted_symbols
cached_font = self._get_font(basename)
symbol_name = cached_font.font.get_glyph_name(num)
num = cached_font.glyphmap[num]
elif len(sym) == 1:
+ slanted = (fontname == "it")
cached_font = self._get_font(fontname)
num = ord(sym)
symbol_name = cached_font.font.get_glyph_name(
@@ -572,7 +577,7 @@
else:
raise ValueError('unrecognized symbol "%s"' % sym)
- return cached_font, num, symbol_name, fontsize
+ return cached_font, num, symbol_name, fontsize, slanted
# The Bakoma fonts contain many pre-sized alternatives for the
# delimiters. The AutoSizedChar class will use these alternatives
@@ -666,6 +671,8 @@
and not category(unichr(uniindex)).startswith("L")):
fontname = 'rm'
+ slanted = (fontname == 'it')
+
cached_font = self._get_font(fontname)
if found_symbol:
try:
@@ -681,7 +688,7 @@
glyphindex = cached_font.charmap[uniindex]
symbol_name = cached_font.font.get_glyph_name(glyphindex)
- return cached_font, uniindex, symbol_name, fontsize
+ return cached_font, uniindex, symbol_name, fontsize, slanted
class StandardPsFonts(Fonts):
"""
@@ -759,6 +766,8 @@
else:
warn("No TeX to built-in Postscript mapping for '%s'" % sym,
MathTextWarning)
+
+ slanted = (fontname == 'it')
font = self._get_font(fontname)
if found_symbol:
@@ -772,7 +781,8 @@
if not found_symbol:
glyph = sym = '?'
- symbol_name = font.get_char_name(glyph)
+ num = ord(glyph)
+ symbol_name = font.get_name_char(glyph)
offset = 0
@@ -789,7 +799,8 @@
ymin = ymin+offset,
ymax = ymax+offset,
# iceberg is the equivalent of TeX's "height"
- iceberg = ymax + offset
+ iceberg = ymax + offset,
+ slanted = slanted
)
self.glyphd[key] = Bunch(
@@ -963,6 +974,9 @@
self.width = metrics.width
self.height = metrics.iceberg
self.depth = -(metrics.iceberg - metrics.height)
+
+ def is_slanted(self):
+ return self._metrics.slanted
def get_kerning(self, next):
"""Return the amount of kerning between this and the given
@@ -2019,6 +2033,11 @@
if isinstance(nucleus, Char):
return nucleus.c in self._dropsub_symbols
return False
+
+ def is_slanted(self, nucleus):
+ if isinstance(nucleus, Char):
+ return nucleus.is_slanted()
+ return False
def subsuperscript(self, s, loc, toks):
assert(len(toks)==1)
@@ -2126,7 +2145,8 @@
if clr > 0.:
shift_up += clr
shift_down += clr
- x.shift_amount = DELTA * (shift_up + shift_down)
+ if self.is_slanted(nucleus):
+ x.shift_amount = DELTA * (shift_up + shift_down)
x = Vlist([x,
Kern((shift_up - x.depth) - (y.height - shift_down)),
y])
@@ -2296,11 +2316,7 @@
font_output.mathtext_backend.fonts_object = None
return self.cache[cacheKey]
-if rcParams["mathtext.mathtext2"]:
- from matplotlib.mathtext2 import math_parse_s_ft2font
- from matplotlib.mathtext2 import math_parse_s_ft2font_svg
-else:
- math_parse_s_ft2font = math_parse_s_ft2font_common('Agg')
- math_parse_s_ft2font_svg = math_parse_s_ft2font_common('SVG')
+math_parse_s_ft2font = math_parse_s_ft2font_common('Agg')
+math_parse_s_ft2font_svg = math_parse_s_ft2font_common('SVG')
math_parse_s_ps = math_parse_s_ft2font_common('PS')
math_parse_s_pdf = math_parse_s_ft2font_common('PDF')
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <md...@us...> - 2007-08-03 18:30:31
|
Revision: 3672
http://matplotlib.svn.sourceforge.net/matplotlib/?rev=3672&view=rev
Author: mdboom
Date: 2007-08-03 11:30:25 -0700 (Fri, 03 Aug 2007)
Log Message:
-----------
Make LaTeX preview show things in displaymath mode, since that's what
we're trying to emulate.
Modified Paths:
--------------
trunk/matplotlib/examples/mathtext_examples.py
Modified: trunk/matplotlib/examples/mathtext_examples.py
===================================================================
--- trunk/matplotlib/examples/mathtext_examples.py 2007-08-03 17:58:07 UTC (rev 3671)
+++ trunk/matplotlib/examples/mathtext_examples.py 2007-08-03 18:30:25 UTC (rev 3672)
@@ -1,6 +1,6 @@
#!/usr/bin/env python
-import os, sys
+import os, sys, re
stests = [
r'Kerning: AVA $AVA$',
@@ -66,6 +66,7 @@
fd.write("\\begin{enumerate}\n")
for i, s in enumerate(stests):
+ s = re.sub(r"(?<!\\)\$", "$$", s)
fd.write("\\item %s\n" % s)
fd.write("\\end{enumerate}\n")
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <md...@us...> - 2007-08-03 17:58:08
|
Revision: 3671
http://matplotlib.svn.sourceforge.net/matplotlib/?rev=3671&view=rev
Author: mdboom
Date: 2007-08-03 10:58:07 -0700 (Fri, 03 Aug 2007)
Log Message:
-----------
Change missing header file errors into warnings, since include paths
can be inserted in sneaky ways behind distutils' back ;)
Modified Paths:
--------------
trunk/matplotlib/setupext.py
Modified: trunk/matplotlib/setupext.py
===================================================================
--- trunk/matplotlib/setupext.py 2007-08-03 17:27:20 UTC (rev 3670)
+++ trunk/matplotlib/setupext.py 2007-08-03 17:58:07 UTC (rev 3671)
@@ -240,26 +240,25 @@
for d in basedirs:
module.include_dirs.append(os.path.join(d, 'freetype2'))
+ print_status("freetype2", get_pkgconfig_version('freetype2'))
if not find_include_file(module.include_dirs, 'ft2build.h'):
print_message(
- "Could not find 'freetype2' headers in any of %s" %
+ "WARNING: Could not find 'freetype2' headers in any of %s." %
", ".join(["'%s'" % x for x in module.include_dirs]))
- return False
- print_status("freetype2", get_pkgconfig_version('freetype2'))
return True
def check_for_libpng():
module = Extension("test", [])
get_pkgconfig(module, 'libpng')
add_base_flags(module)
+
+ print_status("libpng", get_pkgconfig_version('libpng'))
if not find_include_file(module.include_dirs, 'png.h'):
print_message(
- ", ".join("Could not find 'libpng' headers in any of %s" %
- ["'%s'" % x for x in module.include_dirs]))
- return False
+ "Could not find 'libpng' headers in any of %s" %
+ ", ".join(["'%s'" % x for x in module.include_dirs]))
- print_status("libpng", get_pkgconfig_version('libpng'))
return True
def add_base_flags(module):
@@ -323,11 +322,10 @@
module = Extension('test', [])
add_numpy_flags(module)
add_base_flags(module)
+
+ print_status("numpy", numpy.__version__)
if not find_include_file(module.include_dirs, os.path.join("numpy", "arrayobject.h")):
- print_status("numpy", "no")
print_message("Could not find the headers for numpy. You may need to install the development package.")
- return False
- print_status("numpy", numpy.__version__)
return True
def add_numpy_flags(module):
@@ -408,7 +406,6 @@
explanation = (
"Could not find Gtk+ headers in any of %s" %
", ".join(["'%s'" % x for x in module.include_dirs]))
- gotit = False
def ver2str(tup):
return ".".join([str(x) for x in tup])
@@ -424,8 +421,10 @@
ver2str(gtk.pygtk_version), pygobject_version))
else:
print_status("Gtk+", "no")
+
+ if explanation is not None:
print_message(explanation)
-
+
return gotit
def add_pygtk_flags(module):
@@ -529,7 +528,6 @@
os.path.join("wx", "wxPython", "wxPython.h")):
explanation = ("Could not find wxPython headers in any of %s" %
", ".join(["'%s'" % x for x in module.include_dirs]))
- gotit = False
if gotit:
print_status("wxPython", wx.__version__)
@@ -663,7 +661,6 @@
gotit = False
if not find_include_file(module.include_dirs, "tk.h"):
explanation = 'Tkinter present, but header files are not installed. You may need to install development packages.'
- gotit = False
if gotit:
print_status("Tkinter", "Tkinter: %s, Tk: %s, Tcl: %s" %
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <md...@us...> - 2007-08-03 17:27:22
|
Revision: 3670
http://matplotlib.svn.sourceforge.net/matplotlib/?rev=3670&view=rev
Author: mdboom
Date: 2007-08-03 10:27:20 -0700 (Fri, 03 Aug 2007)
Log Message:
-----------
Minor speed improvements from profiling. Fix kerning corruption issue when
"shrinking" characters.
Modified Paths:
--------------
trunk/matplotlib/examples/mathtext_examples.py
trunk/matplotlib/lib/matplotlib/mathtext.py
Modified: trunk/matplotlib/examples/mathtext_examples.py
===================================================================
--- trunk/matplotlib/examples/mathtext_examples.py 2007-08-02 22:49:01 UTC (rev 3669)
+++ trunk/matplotlib/examples/mathtext_examples.py 2007-08-03 17:27:20 UTC (rev 3670)
@@ -9,6 +9,7 @@
r'$100\%y\ x*y\ x/y x\$y$',
r'$x\leftarrow y\ x\forall y\ x-y$',
r'$x \sf x \bf x {\cal X} \rm x$',
+ r'$x\ x\,x\;x\quad x\qquad x\!x$',
r'$\{ \rm braces \}$',
r'$\left[\left\lfloor\frac{5}{\frac{\left(3\right)}{4}} y\right)\right]$',
r'$\left(x\right)$',
@@ -35,13 +36,29 @@
r"$f'$",
r'$\frac{x_2888}{y}$',
r"$\sqrt[3]{\frac{X_2}{Y}}=5$",
+ r"$\sqrt[5x\pi]{\prod^\frac{x}{2\pi^2}_\infty}$",
r"$\sqrt[3]{x}=5$",
r'$\frac{X}{\frac{X}{Y}}$',
+ # From UTR #25
+ r"$W^{3\beta}_{\delta_1 \rho_1 \sigma_2} = U^{3\beta}_{\delta_1 \rho_1} + \frac{1}{8 \pi 2} \int^{\alpha_2}_{\alpha_2} d \alpha^\prime_2 \left[\frac{ U^{2\beta}_{\delta_1 \rho_1} - \alpha^\prime_2U^{1\beta}_{\rho_1 \sigma_2} }{U^{0\beta}_{\rho_1 \sigma_2}}\right]$",
+ r'$\mathcal{H} = \int d \tau (\epsilon E^2 + \mu H^2)$',
r'$\widehat{abc}\widetilde{def}$'
]
from pylab import *
+def doall():
+ for i, s in enumerate(stests):
+ print "%02d: %s" % (i, s)
+ plot([0,0,3], 'r')
+ x = arange(0.0, 3.0, 0.1)
+
+ grid(True)
+ text(0.1, 1.6, s, fontsize=20, markup="tex")
+
+ savefig('mathtext_example%02d' % i)
+ figure()
+
if '--latex' in sys.argv:
fd = open("mathtext_examples.ltx", "w")
fd.write("\\documentclass{article}\n")
@@ -57,14 +74,4 @@
os.system("pdflatex mathtext_examples.ltx")
else:
- for i, s in enumerate(stests):
- print "%02d: %s" % (i, s)
- plot([1,2,3], 'r')
- x = arange(0.0, 3.0, 0.1)
-
- grid(True)
- text(1, 1.6, s, fontsize=20, markup="tex")
-
- savefig('mathtext_example%02d' % i)
- figure()
-
+ doall()
Modified: trunk/matplotlib/lib/matplotlib/mathtext.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/mathtext.py 2007-08-02 22:49:01 UTC (rev 3669)
+++ trunk/matplotlib/lib/matplotlib/mathtext.py 2007-08-03 17:27:20 UTC (rev 3670)
@@ -135,8 +135,9 @@
from sets import Set
from unicodedata import category
from warnings import warn
-import numpy
+from numpy import inf, isinf
+
from matplotlib import verbose
from matplotlib.pyparsing import Literal, Word, OneOrMore, ZeroOrMore, \
Combine, Group, Optional, Forward, NotAny, alphas, nums, alphanums, \
@@ -554,7 +555,7 @@
def _get_offset(self, cached_font, glyph, fontsize, dpi):
if cached_font.font.postscript_name == 'Cmex10':
- return glyph.height/64.0/2 + 256.0/64.0 * dpi/72.0
+ return glyph.height/64.0/2.0 + 256.0/64.0 * dpi/72.0
return 0.
def _get_glyph(self, fontname, sym, fontsize):
@@ -654,7 +655,7 @@
# This is a total hack, but it works for now
if sym.startswith('\\big'):
uniindex = get_unicode_index(sym[4:])
- fontsize *= INV_SHRINK_FACTOR
+ fontsize *= GROW_FACTOR
else:
warn("No TeX to unicode mapping for '%s'" % sym,
MathTextWarning)
@@ -848,7 +849,7 @@
# How much text shrinks when going to the next-smallest level
SHRINK_FACTOR = 0.7
-INV_SHRINK_FACTOR = 1.0 / SHRINK_FACTOR
+GROW_FACTOR = 1.0 / SHRINK_FACTOR
# The number of different sizes of chars to use, beyond which they will not
# get any smaller
NUM_SIZE_LEVELS = 4
@@ -900,28 +901,22 @@
@135"""
def __init__(self, width, height, depth):
Node.__init__(self)
- self.width = width
- self.height = height
- self.depth = depth
+ self.width = width
+ self.height = height
+ self.depth = depth
def shrink(self):
Node.shrink(self)
if self.size < NUM_SIZE_LEVELS:
- if self.width is not None:
- self.width *= SHRINK_FACTOR
- if self.height is not None:
- self.height *= SHRINK_FACTOR
- if self.depth is not None:
- self.depth *= SHRINK_FACTOR
+ self.width *= SHRINK_FACTOR
+ self.height *= SHRINK_FACTOR
+ self.depth *= SHRINK_FACTOR
def grow(self):
Node.grow(self)
- if self.width is not None:
- self.width *= INV_SHRINK_FACTOR
- if self.height is not None:
- self.height *= INV_SHRINK_FACTOR
- if self.depth is not None:
- self.depth *= INV_SHRINK_FACTOR
+ self.width *= GROW_FACTOR
+ self.height *= GROW_FACTOR
+ self.depth *= GROW_FACTOR
def render(self, x1, y1, x2, y2):
pass
@@ -992,12 +987,16 @@
Node.shrink(self)
if self.size < NUM_SIZE_LEVELS:
self.fontsize *= SHRINK_FACTOR
- self._update_metrics()
+ self.width *= SHRINK_FACTOR
+ self.height *= SHRINK_FACTOR
+ self.depth *= SHRINK_FACTOR
def grow(self):
Node.grow(self)
- self.fontsize *= INV_SHRINK_FACTOR
- self._update_metrics()
+ self.fontsize *= GROW_FACTOR
+ self.width *= GROW_FACTOR
+ self.height *= GROW_FACTOR
+ self.depth *= GROW_FACTOR
class Accent(Char):
"""The font metrics need to be dealt with differently for accents, since they
@@ -1028,10 +1027,11 @@
self.glue_order = 0 # The order of infinity (0 - 3) for the glue
def __repr__(self):
- return '[%s <%d %d %d %d> %s]' % (self.__internal_repr__(),
- self.width, self.height,
- self.depth, self.shift_amount,
- ' '.join([repr(x) for x in self.children]))
+ return '[%s <%.02f %.02f %.02f %.02f> %s]' % (
+ self.__internal_repr__(),
+ self.width, self.height,
+ self.depth, self.shift_amount,
+ ' '.join([repr(x) for x in self.children]))
def _determine_order(self, totals):
"""A helper function to determine the highest order of glue
@@ -1069,8 +1069,8 @@
for child in self.children:
child.grow()
Box.grow(self)
- self.shift_amount *= INV_SHRINK_FACTOR
- self.glue_set *= INV_SHRINK_FACTOR
+ self.shift_amount *= GROW_FACTOR
+ self.glue_set *= GROW_FACTOR
class Hlist(List):
"""A horizontal list of boxes.
@@ -1131,7 +1131,7 @@
d = max(d, p.depth)
elif isinstance(p, Box):
x += p.width
- if p.height is not None and p.depth is not None:
+ if not isinf(p.height) and not isinf(p.depth):
s = getattr(p, 'shift_amount', 0.)
h = max(h, p.height - s)
d = max(d, p.depth + s)
@@ -1167,7 +1167,7 @@
List.__init__(self, elements)
self.vpack()
- def vpack(self, h=0., m='additional', l=float(numpy.inf)):
+ def vpack(self, h=0., m='additional', l=float(inf)):
"""The main duty of vpack is to compute the dimensions of the
resulting boxes, and to adjust the glue if one of those dimensions is
pre-specified.
@@ -1192,7 +1192,7 @@
if isinstance(p, Box):
x += d + p.height
d = p.depth
- if p.width is not None:
+ if not isinf(p.width):
s = getattr(p, 'shift_amount', 0.)
w = max(w, p.width + s)
elif isinstance(p, Glue):
@@ -1234,7 +1234,7 @@
class Rule(Box):
"""A Rule node stands for a solid black rectangle; it has width,
depth, and height fields just as in an Hlist. However, if any of these
- dimensions is None, the actual value will be determined by running the
+ dimensions is inf, the actual value will be determined by running the
rule up to the boundary of the innermost enclosing box. This is called
a "running dimension." The width is never running in an Hlist; the
height and depth are never running in a Vlist.
@@ -1252,14 +1252,14 @@
thickness = state.font_output.get_underline_thickness(
state.font, state.fontsize, state.dpi)
height = depth = thickness * 0.5
- Rule.__init__(self, None, height, depth, state)
+ Rule.__init__(self, inf, height, depth, state)
class Vrule(Rule):
"""Convenience class to create a vertical rule."""
def __init__(self, state):
thickness = state.font_output.get_underline_thickness(
state.font, state.fontsize, state.dpi)
- Rule.__init__(self, thickness, None, None, state)
+ Rule.__init__(self, thickness, inf, inf, state)
class Glue(Node):
"""Most of the information in this object is stored in the underlying
@@ -1291,7 +1291,7 @@
Node.grow(self)
if self.glue_spec.width != 0.:
self.glue_spec = self.glue_spec.copy()
- self.glue_spec.width *= INV_SHRINK_FACTOR
+ self.glue_spec.width *= GROW_FACTOR
class GlueSpec(object):
"""@150, @151"""
@@ -1379,6 +1379,9 @@
Node.__init__(self)
self.width = width
+ def __repr__(self):
+ return "k%.02f" % self.width
+
def shrink(self):
Node.shrink(self)
if self.size < NUM_SIZE_LEVELS:
@@ -1386,7 +1389,7 @@
def grow(self):
Node.grow(self)
- self.width *= INV_SHRINK_FACTOR
+ self.width *= GROW_FACTOR
class SubSuperCluster(Hlist):
"""This class is a sort of hack to get around that fact that this
@@ -1507,9 +1510,9 @@
rule_height = p.height
rule_depth = p.depth
rule_width = p.width
- if rule_height is None:
+ if isinf(rule_height):
rule_height = box.height
- if rule_depth is None:
+ if isinf(rule_depth):
rule_depth = box.depth
if rule_height > 0 and rule_width > 0:
self.cur_v = baseline + rule_depth
@@ -1566,7 +1569,7 @@
rule_height = p.height
rule_depth = p.depth
rule_width = p.width
- if rule_width is None:
+ if isinf(rule_width):
rule_width = box.width
rule_height += rule_depth
if rule_height > 0 and rule_depth > 0:
@@ -1822,7 +1825,7 @@
self._expression <<(
non_math
- + OneOrMore(
+ + ZeroOrMore(
Suppress(math_delim)
+ math
+ Suppress(math_delim)
@@ -2178,7 +2181,8 @@
else:
if not isinstance(root, ParseResults):
raise ParseFatalException(
- "Can not parse root of radical. Only simple symbols are allowed.")
+ "Can not parse root of radical. "
+ "Only simple symbols are allowed in the root.")
root = Hlist(root.asList())
root.shrink()
root.shrink()
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <md...@us...> - 2007-08-02 22:49:03
|
Revision: 3669
http://matplotlib.svn.sourceforge.net/matplotlib/?rev=3669&view=rev
Author: mdboom
Date: 2007-08-02 15:49:01 -0700 (Thu, 02 Aug 2007)
Log Message:
-----------
Reverting last change since it breaks on gcc-4.2
Modified Paths:
--------------
trunk/matplotlib/src/_ttconv.cpp
trunk/matplotlib/src/ft2font.cpp
trunk/matplotlib/ttconv/pprdrv_tt.cpp
trunk/matplotlib/ttconv/truetype.h
Modified: trunk/matplotlib/src/_ttconv.cpp
===================================================================
--- trunk/matplotlib/src/_ttconv.cpp 2007-08-02 21:32:30 UTC (rev 3668)
+++ trunk/matplotlib/src/_ttconv.cpp 2007-08-02 22:49:01 UTC (rev 3669)
@@ -83,10 +83,10 @@
int fonttype;
std::vector<int> glyph_ids;
- static const char *kwlist[] = { "filename", "output", "fonttype", "glyph_ids", NULL };
+ static char *kwlist[] = { "filename", "output", "fonttype", "glyph_ids", NULL };
if (! PyArg_ParseTupleAndKeywords
(args, kwds,
- "sO&i|O&:convert_ttf_to_ps", (char **)kwlist,
+ "sO&i|O&:convert_ttf_to_ps", kwlist,
&filename,
fileobject_to_PythonFileWriter,
&output,
@@ -140,10 +140,10 @@
std::vector<int> glyph_ids;
PyObject* result;
- static const char *kwlist[] = { "filename", "glyph_ids", NULL };
+ static char *kwlist[] = { "filename", "glyph_ids", NULL };
if (! PyArg_ParseTupleAndKeywords
(args, kwds,
- "s|O&:convert_ttf_to_ps", (char **)kwlist,
+ "s|O&:convert_ttf_to_ps", kwlist,
&filename,
pyiterable_to_vector_int,
&glyph_ids))
Modified: trunk/matplotlib/src/ft2font.cpp
===================================================================
--- trunk/matplotlib/src/ft2font.cpp 2007-08-02 21:32:30 UTC (rev 3668)
+++ trunk/matplotlib/src/ft2font.cpp 2007-08-02 22:49:01 UTC (rev 3669)
@@ -1370,8 +1370,8 @@
std::string tagname = Py::String(args[0]);
int tag;
- static const char *tags[] = {"head", "maxp", "OS/2", "hhea",
- "vhea", "post", "pclt", NULL};
+ char *tags[] = {"head", "maxp", "OS/2", "hhea",
+ "vhea", "post", "pclt", NULL};
for (tag=0; tags[tag] != NULL; tag++)
if (strcmp(tagname.c_str(), tags[tag]) == 0)
Modified: trunk/matplotlib/ttconv/pprdrv_tt.cpp
===================================================================
--- trunk/matplotlib/ttconv/pprdrv_tt.cpp 2007-08-02 21:32:30 UTC (rev 3668)
+++ trunk/matplotlib/ttconv/pprdrv_tt.cpp 2007-08-02 22:49:01 UTC (rev 3669)
@@ -107,7 +107,7 @@
** is always 4 characters, though the last characters may be
** padding spaces.
-----------------------------------------------------------------------*/
-BYTE *GetTable(struct TTFONT *font, const char *name)
+BYTE *GetTable(struct TTFONT *font, char *name)
{
BYTE *ptr;
ULONG x;
@@ -654,7 +654,7 @@
*/
void ttfont_sfnts(TTStreamWriter& stream, struct TTFONT *font)
{
- const char *table_names[]= /* The names of all tables */
+ char *table_names[]= /* The names of all tables */
{ /* which it is worth while */
"cvt ", /* to include in a Type 42 */
"fpgm", /* PostScript font. */
@@ -828,7 +828,7 @@
** this array will instead convert PostScript character names
** to executable proceedures.
--------------------------------------------------------------*/
-const char *Apple_CharStrings[]={
+char *Apple_CharStrings[]={
".notdef",".null","nonmarkingreturn","space","exclam","quotedbl","numbersign",
"dollar","percent","ampersand","quotesingle","parenleft","parenright",
"asterisk","plus", "comma","hyphen","period","slash","zero","one","two",
@@ -871,7 +871,7 @@
** This routine is called by the one below.
** It is also called from pprdrv_tt2.c
*/
-const char *ttfont_CharStrings_getname(struct TTFONT *font, int charindex)
+char *ttfont_CharStrings_getname(struct TTFONT *font, int charindex)
{
int GlyphIndex;
static char temp[80];
@@ -1227,7 +1227,7 @@
i != glyph_ids.end(); ++i) {
StringStreamWriter writer;
tt_type3_charproc(writer, &font, *i);
- const char* name = ttfont_CharStrings_getname(&font, *i);
+ char* name = ttfont_CharStrings_getname(&font, *i);
dict.add_pair(name, writer.str().c_str());
}
}
Modified: trunk/matplotlib/ttconv/truetype.h
===================================================================
--- trunk/matplotlib/ttconv/truetype.h 2007-08-02 21:32:30 UTC (rev 3668)
+++ trunk/matplotlib/ttconv/truetype.h 2007-08-02 22:49:01 UTC (rev 3669)
@@ -51,13 +51,13 @@
font_type_enum target_type; /* 42 or 3 for PS, or -3 for PDF */
ULONG numTables; /* number of tables present */
- const char *PostName; /* Font's PostScript name */
- const char *FullName; /* Font's full name */
- const char *FamilyName; /* Font's family name */
- const char *Style; /* Font's style string */
- const char *Copyright; /* Font's copyright string */
- const char *Version; /* Font's version string */
- const char *Trademark; /* Font's trademark string */
+ char *PostName; /* Font's PostScript name */
+ char *FullName; /* Font's full name */
+ char *FamilyName; /* Font's family name */
+ char *Style; /* Font's style string */
+ char *Copyright; /* Font's copyright string */
+ char *Version; /* Font's version string */
+ char *Trademark; /* Font's trademark string */
int llx,lly,urx,ury; /* bounding box */
Fixed TTVersion; /* Truetype version number from offset table */
@@ -98,7 +98,7 @@
/* This is the one routine in pprdrv_tt.c that is */
/* called from pprdrv_tt.c. */
-const char *ttfont_CharStrings_getname(struct TTFONT *font, int charindex);
+char *ttfont_CharStrings_getname(struct TTFONT *font, int charindex);
void tt_type3_charproc(TTStreamWriter& stream, struct TTFONT *font, int charindex);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <md...@us...> - 2007-08-02 21:32:33
|
Revision: 3668
http://matplotlib.svn.sourceforge.net/matplotlib/?rev=3668&view=rev
Author: mdboom
Date: 2007-08-02 14:32:30 -0700 (Thu, 02 Aug 2007)
Log Message:
-----------
Attempting to reduce compiler warnings for gcc-4.2 (which I don't
have, but Darren Dale has reported some new warnings).
Modified Paths:
--------------
trunk/matplotlib/src/_ttconv.cpp
trunk/matplotlib/src/ft2font.cpp
trunk/matplotlib/ttconv/pprdrv_tt.cpp
trunk/matplotlib/ttconv/truetype.h
Modified: trunk/matplotlib/src/_ttconv.cpp
===================================================================
--- trunk/matplotlib/src/_ttconv.cpp 2007-08-02 19:07:02 UTC (rev 3667)
+++ trunk/matplotlib/src/_ttconv.cpp 2007-08-02 21:32:30 UTC (rev 3668)
@@ -83,10 +83,10 @@
int fonttype;
std::vector<int> glyph_ids;
- static char *kwlist[] = { "filename", "output", "fonttype", "glyph_ids", NULL };
+ static const char *kwlist[] = { "filename", "output", "fonttype", "glyph_ids", NULL };
if (! PyArg_ParseTupleAndKeywords
(args, kwds,
- "sO&i|O&:convert_ttf_to_ps", kwlist,
+ "sO&i|O&:convert_ttf_to_ps", (char **)kwlist,
&filename,
fileobject_to_PythonFileWriter,
&output,
@@ -140,10 +140,10 @@
std::vector<int> glyph_ids;
PyObject* result;
- static char *kwlist[] = { "filename", "glyph_ids", NULL };
+ static const char *kwlist[] = { "filename", "glyph_ids", NULL };
if (! PyArg_ParseTupleAndKeywords
(args, kwds,
- "s|O&:convert_ttf_to_ps", kwlist,
+ "s|O&:convert_ttf_to_ps", (char **)kwlist,
&filename,
pyiterable_to_vector_int,
&glyph_ids))
Modified: trunk/matplotlib/src/ft2font.cpp
===================================================================
--- trunk/matplotlib/src/ft2font.cpp 2007-08-02 19:07:02 UTC (rev 3667)
+++ trunk/matplotlib/src/ft2font.cpp 2007-08-02 21:32:30 UTC (rev 3668)
@@ -1370,8 +1370,8 @@
std::string tagname = Py::String(args[0]);
int tag;
- char *tags[] = {"head", "maxp", "OS/2", "hhea",
- "vhea", "post", "pclt", NULL};
+ static const char *tags[] = {"head", "maxp", "OS/2", "hhea",
+ "vhea", "post", "pclt", NULL};
for (tag=0; tags[tag] != NULL; tag++)
if (strcmp(tagname.c_str(), tags[tag]) == 0)
Modified: trunk/matplotlib/ttconv/pprdrv_tt.cpp
===================================================================
--- trunk/matplotlib/ttconv/pprdrv_tt.cpp 2007-08-02 19:07:02 UTC (rev 3667)
+++ trunk/matplotlib/ttconv/pprdrv_tt.cpp 2007-08-02 21:32:30 UTC (rev 3668)
@@ -107,7 +107,7 @@
** is always 4 characters, though the last characters may be
** padding spaces.
-----------------------------------------------------------------------*/
-BYTE *GetTable(struct TTFONT *font, char *name)
+BYTE *GetTable(struct TTFONT *font, const char *name)
{
BYTE *ptr;
ULONG x;
@@ -654,7 +654,7 @@
*/
void ttfont_sfnts(TTStreamWriter& stream, struct TTFONT *font)
{
- char *table_names[]= /* The names of all tables */
+ const char *table_names[]= /* The names of all tables */
{ /* which it is worth while */
"cvt ", /* to include in a Type 42 */
"fpgm", /* PostScript font. */
@@ -828,7 +828,7 @@
** this array will instead convert PostScript character names
** to executable proceedures.
--------------------------------------------------------------*/
-char *Apple_CharStrings[]={
+const char *Apple_CharStrings[]={
".notdef",".null","nonmarkingreturn","space","exclam","quotedbl","numbersign",
"dollar","percent","ampersand","quotesingle","parenleft","parenright",
"asterisk","plus", "comma","hyphen","period","slash","zero","one","two",
@@ -871,7 +871,7 @@
** This routine is called by the one below.
** It is also called from pprdrv_tt2.c
*/
-char *ttfont_CharStrings_getname(struct TTFONT *font, int charindex)
+const char *ttfont_CharStrings_getname(struct TTFONT *font, int charindex)
{
int GlyphIndex;
static char temp[80];
@@ -1227,7 +1227,7 @@
i != glyph_ids.end(); ++i) {
StringStreamWriter writer;
tt_type3_charproc(writer, &font, *i);
- char* name = ttfont_CharStrings_getname(&font, *i);
+ const char* name = ttfont_CharStrings_getname(&font, *i);
dict.add_pair(name, writer.str().c_str());
}
}
Modified: trunk/matplotlib/ttconv/truetype.h
===================================================================
--- trunk/matplotlib/ttconv/truetype.h 2007-08-02 19:07:02 UTC (rev 3667)
+++ trunk/matplotlib/ttconv/truetype.h 2007-08-02 21:32:30 UTC (rev 3668)
@@ -51,13 +51,13 @@
font_type_enum target_type; /* 42 or 3 for PS, or -3 for PDF */
ULONG numTables; /* number of tables present */
- char *PostName; /* Font's PostScript name */
- char *FullName; /* Font's full name */
- char *FamilyName; /* Font's family name */
- char *Style; /* Font's style string */
- char *Copyright; /* Font's copyright string */
- char *Version; /* Font's version string */
- char *Trademark; /* Font's trademark string */
+ const char *PostName; /* Font's PostScript name */
+ const char *FullName; /* Font's full name */
+ const char *FamilyName; /* Font's family name */
+ const char *Style; /* Font's style string */
+ const char *Copyright; /* Font's copyright string */
+ const char *Version; /* Font's version string */
+ const char *Trademark; /* Font's trademark string */
int llx,lly,urx,ury; /* bounding box */
Fixed TTVersion; /* Truetype version number from offset table */
@@ -98,7 +98,7 @@
/* This is the one routine in pprdrv_tt.c that is */
/* called from pprdrv_tt.c. */
-char *ttfont_CharStrings_getname(struct TTFONT *font, int charindex);
+const char *ttfont_CharStrings_getname(struct TTFONT *font, int charindex);
void tt_type3_charproc(TTStreamWriter& stream, struct TTFONT *font, int charindex);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <md...@us...> - 2007-08-02 19:07:35
|
Revision: 3667
http://matplotlib.svn.sourceforge.net/matplotlib/?rev=3667&view=rev
Author: mdboom
Date: 2007-08-02 12:07:02 -0700 (Thu, 02 Aug 2007)
Log Message:
-----------
Small bugfix with auto-sized delimiters
Modified Paths:
--------------
trunk/matplotlib/lib/matplotlib/mathtext.py
Modified: trunk/matplotlib/lib/matplotlib/mathtext.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/mathtext.py 2007-08-02 18:59:29 UTC (rev 3666)
+++ trunk/matplotlib/lib/matplotlib/mathtext.py 2007-08-02 19:07:02 UTC (rev 3667)
@@ -1412,20 +1412,15 @@
state = state.copy()
target_total = height + depth
- big_enough = False
for fontname, sym in alternatives:
state.font = fontname
char = Char(sym, state)
- if char.height + char.depth > target_total:
- big_enough = True
+ if char.height + char.depth >= target_total:
break
- # If the largest option is still not big enough, just do
- # simple scale on it.
- if not big_enough:
- factor = target_total / (char.height + char.depth)
- state.fontsize *= factor
- char = Char(sym, state)
+ factor = target_total / (char.height + char.depth)
+ state.fontsize *= factor
+ char = Char(sym, state)
shift = (depth - char.depth)
Hlist.__init__(self, [char])
@@ -1442,20 +1437,15 @@
state.font, c)
state = state.copy()
- big_enough = False
for fontname, sym in alternatives:
state.font = fontname
char = char_class(sym, state)
- if char.width > width:
- big_enough = True
+ if char.width >= width:
break
- # If the largest option is still not big enough, just do
- # simple scale on it.
- if not big_enough:
- factor = width / char.width
- state.fontsize *= factor
- char = char_class(sym, state)
+ factor = width / char.width
+ state.fontsize *= factor
+ char = char_class(sym, state)
Hlist.__init__(self, [char])
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <md...@us...> - 2007-08-02 18:59:31
|
Revision: 3666
http://matplotlib.svn.sourceforge.net/matplotlib/?rev=3666&view=rev
Author: mdboom
Date: 2007-08-02 11:59:29 -0700 (Thu, 02 Aug 2007)
Log Message:
-----------
Add support for \widehat and \widetilde
Modified Paths:
--------------
trunk/matplotlib/examples/mathtext_examples.py
trunk/matplotlib/lib/matplotlib/_mathtext_data.py
trunk/matplotlib/lib/matplotlib/mathtext.py
Modified: trunk/matplotlib/examples/mathtext_examples.py
===================================================================
--- trunk/matplotlib/examples/mathtext_examples.py 2007-08-02 18:49:17 UTC (rev 3665)
+++ trunk/matplotlib/examples/mathtext_examples.py 2007-08-02 18:59:29 UTC (rev 3666)
@@ -36,7 +36,8 @@
r'$\frac{x_2888}{y}$',
r"$\sqrt[3]{\frac{X_2}{Y}}=5$",
r"$\sqrt[3]{x}=5$",
- r'$\frac{X}{\frac{X}{Y}}$'
+ r'$\frac{X}{\frac{X}{Y}}$',
+ r'$\widehat{abc}\widetilde{def}$'
]
from pylab import *
Modified: trunk/matplotlib/lib/matplotlib/_mathtext_data.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/_mathtext_data.py 2007-08-02 18:49:17 UTC (rev 3665)
+++ trunk/matplotlib/lib/matplotlib/_mathtext_data.py 2007-08-02 18:59:29 UTC (rev 3666)
@@ -39,6 +39,8 @@
r'\}' : ('cmex10', 130),
r'\leftangle' : ('cmex10', 97),
r'\rightangle' : ('cmex10', 64),
+ r'\widehat' : ('cmex10', 15),
+ r'\widetilde' : ('cmex10', 52),
r'\omega' : ('cmmi10', 29),
r'\varepsilon' : ('cmmi10', 20),
Modified: trunk/matplotlib/lib/matplotlib/mathtext.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/mathtext.py 2007-08-02 18:49:17 UTC (rev 3665)
+++ trunk/matplotlib/lib/matplotlib/mathtext.py 2007-08-02 18:59:29 UTC (rev 3666)
@@ -1437,7 +1437,7 @@
of some characters (such as the BaKoMa fonts), the correct glyph will
be selected, otherwise this will always just return a scaled version
of the glyph."""
- def __init__(self, c, width, state, always=False):
+ def __init__(self, c, width, state, always=False, char_class=Char):
alternatives = state.font_output.get_sized_alternatives_for_symbol(
state.font, c)
@@ -1445,7 +1445,7 @@
big_enough = False
for fontname, sym in alternatives:
state.font = fontname
- char = Char(sym, state)
+ char = char_class(sym, state)
if char.width > width:
big_enough = True
break
@@ -1455,7 +1455,7 @@
if not big_enough:
factor = width / char.width
state.fontsize *= factor
- char = Char(sym, state)
+ char = char_class(sym, state)
Hlist.__init__(self, [char])
@@ -1969,12 +1969,15 @@
raise ParseFatalException("Error parsing accent")
accent, sym = toks[0]
if accent in self._wide_accents:
- accent = AutoWidthChar(accent, sym.width, state)
+ accent = AutoWidthChar(
+ accent, sym.width, state, char_class=Accent)
+ shift_amount = 0.
else:
accent = Accent(self._accent_map[accent], state)
+ shift_amount = accent._metrics.xmin
centered = HCentered([accent])
centered.hpack(sym.width, 'exactly')
- centered.shift_amount = accent._metrics.xmin
+ centered.shift_amount = shift_amount
return Vlist([
centered,
Vbox(0., thickness * 2.0),
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <md...@us...> - 2007-08-02 18:49:21
|
Revision: 3665
http://matplotlib.svn.sourceforge.net/matplotlib/?rev=3665&view=rev
Author: mdboom
Date: 2007-08-02 11:49:17 -0700 (Thu, 02 Aug 2007)
Log Message:
-----------
Improved exception handling. Remove compiler warning.
Modified Paths:
--------------
trunk/matplotlib/src/_ttconv.cpp
Modified: trunk/matplotlib/src/_ttconv.cpp
===================================================================
--- trunk/matplotlib/src/_ttconv.cpp 2007-08-02 18:37:32 UTC (rev 3664)
+++ trunk/matplotlib/src/_ttconv.cpp 2007-08-02 18:49:17 UTC (rev 3665)
@@ -8,6 +8,10 @@
#include "ttconv/pprdrv.h"
#include <vector>
+class PythonExceptionOccurred {
+
+};
+
/**
* An implementation of TTStreamWriter that writes to a Python
* file-like object.
@@ -35,33 +39,40 @@
virtual void write(const char* a) {
if (_write_method)
- PyObject_CallFunction(_write_method, "s", a);
+ if (! PyObject_CallFunction(_write_method, "s", a))
+ throw PythonExceptionOccurred();
}
};
int fileobject_to_PythonFileWriter(PyObject* object, void* address) {
PythonFileWriter* file_writer = (PythonFileWriter*)address;
+
PyObject* write_method = PyObject_GetAttrString(object, "write");
if (write_method == NULL || ! PyCallable_Check(write_method)) {
PyErr_SetString(PyExc_TypeError, "Expected a file-like object with a write method.");
return 0;
}
+
file_writer->set(write_method);
+
return 1;
}
int pyiterable_to_vector_int(PyObject* object, void* address) {
std::vector<int>* result = (std::vector<int>*)address;
+
PyObject* iterator = PyObject_GetIter(object);
if (! iterator)
return 0;
+
PyObject* item;
- while (item = PyIter_Next(iterator)) {
+ while ( (item = PyIter_Next(iterator)) ) {
long value = PyInt_AsLong(item);
if (value == -1 && PyErr_Occurred())
return 0;
result->push_back(value);
}
+
return 1;
}
@@ -96,6 +107,8 @@
} catch (TTException& e) {
PyErr_SetString(PyExc_RuntimeError, e.getMessage());
return NULL;
+ } catch (PythonExceptionOccurred& e) {
+ return NULL;
} catch (...) {
PyErr_SetString(PyExc_RuntimeError, "Unknown C++ exception");
return NULL;
@@ -116,7 +129,8 @@
virtual void add_pair(const char* a, const char* b) {
PyObject* value = PyString_FromString(b);
if (value)
- PyDict_SetItemString(_dict, a, value);
+ if (PyDict_SetItemString(_dict, a, value))
+ throw PythonExceptionOccurred();
}
};
@@ -146,6 +160,8 @@
} catch (TTException& e) {
PyErr_SetString(PyExc_RuntimeError, e.getMessage());
return NULL;
+ } catch (PythonExceptionOccurred& e) {
+ return NULL;
} catch (...) {
PyErr_SetString(PyExc_RuntimeError, "Unknown C++ exception");
return NULL;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <md...@us...> - 2007-08-02 18:37:33
|
Revision: 3664
http://matplotlib.svn.sourceforge.net/matplotlib/?rev=3664&view=rev
Author: mdboom
Date: 2007-08-02 11:37:32 -0700 (Thu, 02 Aug 2007)
Log Message:
-----------
Add kwarg 'markup' for all text that allows the user to choose either
'plain' or 'tex' markup. A default may also be provided in the
rcParam 'text.markup'.
Minor bugfix to mathtext.py
Modified Paths:
--------------
trunk/matplotlib/examples/accented_text.py
trunk/matplotlib/examples/arrow_demo.py
trunk/matplotlib/examples/dannys_example.py
trunk/matplotlib/examples/histogram_demo.py
trunk/matplotlib/examples/histogram_demo_canvasagg.py
trunk/matplotlib/examples/integral_demo.py
trunk/matplotlib/examples/legend_auto.py
trunk/matplotlib/examples/mathtext_demo.py
trunk/matplotlib/examples/mathtext_examples.py
trunk/matplotlib/examples/scatter_demo2.py
trunk/matplotlib/examples/tex_demo.py
trunk/matplotlib/examples/tex_unicode_demo.py
trunk/matplotlib/lib/matplotlib/mathtext.py
trunk/matplotlib/lib/matplotlib/rcsetup.py
trunk/matplotlib/lib/matplotlib/text.py
trunk/matplotlib/matplotlibrc.template
Modified: trunk/matplotlib/examples/accented_text.py
===================================================================
--- trunk/matplotlib/examples/accented_text.py 2007-08-02 15:15:29 UTC (rev 3663)
+++ trunk/matplotlib/examples/accented_text.py 2007-08-02 18:37:32 UTC (rev 3664)
@@ -13,9 +13,9 @@
plot(range(10))
-title(r'$\ddot{o}\acute{e}\grave{e}\hat{O}\breve{i}\bar{A}\tilde{n}\vec{q}$', fontsize=20)
+title(r'$\ddot{o}\acute{e}\grave{e}\hat{O}\breve{i}\bar{A}\tilde{n}\vec{q}$', fontsize=20, markup="tex")
# shorthand is also supported and curly's are optional
-xlabel(r"""$\"o\ddot o \'e\`e\~n\.x\^y$""", fontsize=20)
+xlabel(r"""$\"o\ddot o \'e\`e\~n\.x\^y$""", fontsize=20, markup="tex")
show()
Modified: trunk/matplotlib/examples/arrow_demo.py
===================================================================
--- trunk/matplotlib/examples/arrow_demo.py 2007-08-02 15:15:29 UTC (rev 3663)
+++ trunk/matplotlib/examples/arrow_demo.py 2007-08-02 18:37:32 UTC (rev 3664)
@@ -52,7 +52,7 @@
min_text_size = size
label_text_size = size*2.5
text_params={'ha':'center', 'va':'center', 'family':'sans-serif',\
- 'fontweight':'bold'}
+ 'fontweight':'bold', 'markup': 'tex'}
r2 = sqrt(2)
deltas = {\
@@ -211,7 +211,7 @@
label = '$%s_{_{\mathrm{%s}}}$' % (orig_label[0], orig_label[1:])
text(x, y, label, size=label_text_size, ha='center', va='center', \
- color=labelcolor or fc)
+ color=labelcolor or fc, markup='tex')
for p in positions.keys():
draw_arrow(p)
Modified: trunk/matplotlib/examples/dannys_example.py
===================================================================
--- trunk/matplotlib/examples/dannys_example.py 2007-08-02 15:15:29 UTC (rev 3663)
+++ trunk/matplotlib/examples/dannys_example.py 2007-08-02 18:37:32 UTC (rev 3664)
@@ -29,14 +29,14 @@
pylab.plot((-delta / 2, -delta / 2 + offset * 2), (height, height + offset), 'k', linewidth = 2)
pylab.plot((delta / 2, delta / 2 - offset * 2), (height, height - offset), 'k', linewidth = 2)
pylab.plot((delta / 2, delta / 2 - offset * 2), (height, height + offset), 'k', linewidth = 2)
-pylab.text(-0.06, height - 0.06, r'$\delta$', {'color' : 'k', 'fontsize' : 24})
+pylab.text(-0.06, height - 0.06, r'$\delta$', {'color' : 'k', 'fontsize' : 24}, markup = 'tex')
## X-axis label
pylab.xticks((-1, 0, 1), ('-1', '0', '1'), color = 'k', size = 20)
## Left Y-axis labels
pylab.ylabel(r'\bf{phase field} $\phi$', {'color' : 'b',
- 'fontsize' : 20 })
+ 'fontsize' : 20 }, markup='tex')
pylab.yticks((0, 0.5, 1), ('0', '.5', '1'), color = 'k', size = 20)
## Right Y-axis labels
@@ -44,16 +44,17 @@
horizontalalignment = 'left',
verticalalignment = 'center',
rotation = 90,
- clip_on = False)
+ clip_on = False,
+ markup = 'tex')
pylab.text(1.01, -0.02, "-1", {'color' : 'k', 'fontsize' : 20})
pylab.text(1.01, 0.98, "1", {'color' : 'k', 'fontsize' : 20})
pylab.text(1.01, 0.48, "0", {'color' : 'k', 'fontsize' : 20})
## level set equations
-pylab.text(0.1, 0.85, r'$|\nabla\phi| = 1,$ \newline $ \frac{\partial \phi}{\partial t} + U|\nabla \phi| = 0$', {'color' : 'g', 'fontsize' : 20})
+pylab.text(0.1, 0.85, r'$|\nabla\phi| = 1,$ \newline $ \frac{\partial \phi}{\partial t} + U|\nabla \phi| = 0$', {'color' : 'g', 'fontsize' : 20}, markup='tex')
## phase field equations
-pylab.text(0.2, 0.15, r'$\mathcal{F} = \int f\left( \phi, c \right) dV,$ \newline $ \frac{ \partial \phi } { \partial t } = -M_{ \phi } \frac{ \delta \mathcal{F} } { \delta \phi }$', {'color' : 'b', 'fontsize' : 20})
+pylab.text(0.2, 0.15, r'$\mathcal{F} = \int f\left( \phi, c \right) dV,$ \newline $ \frac{ \partial \phi } { \partial t } = -M_{ \phi } \frac{ \delta \mathcal{F} } { \delta \phi }$', {'color' : 'b', 'fontsize' : 20}, markup='tex')
pylab.savefig('pfm-lsm.png')
pylab.show()
Modified: trunk/matplotlib/examples/histogram_demo.py
===================================================================
--- trunk/matplotlib/examples/histogram_demo.py 2007-08-02 15:15:29 UTC (rev 3663)
+++ trunk/matplotlib/examples/histogram_demo.py 2007-08-02 18:37:32 UTC (rev 3664)
@@ -15,7 +15,7 @@
xlabel('Smarts')
ylabel('Probability')
-title(r'$\rm{Histogram\ of\ IQ:}\ \mu=100,\ \sigma=15$')
+title(r'$\mathrm{Histogram\ of\ IQ:}\ \mu=100,\ \sigma=15$', markup='tex')
axis([40, 160, 0, 0.03])
grid(True)
Modified: trunk/matplotlib/examples/histogram_demo_canvasagg.py
===================================================================
--- trunk/matplotlib/examples/histogram_demo_canvasagg.py 2007-08-02 15:15:29 UTC (rev 3663)
+++ trunk/matplotlib/examples/histogram_demo_canvasagg.py 2007-08-02 18:37:32 UTC (rev 3664)
@@ -33,7 +33,7 @@
ax.set_xlabel('Smarts')
ax.set_ylabel('Probability')
-ax.set_title(r'$\rm{Histogram of IQ: }\mu=100, \sigma=15$')
+ax.set_title(r'$\mathrm{Histogram of IQ: }\mu=100, \sigma=15$', markup='tex')
ax.set_xlim( (40, 160))
ax.set_ylim( (0, 0.03))
Modified: trunk/matplotlib/examples/integral_demo.py
===================================================================
--- trunk/matplotlib/examples/integral_demo.py 2007-08-02 15:15:29 UTC (rev 3663)
+++ trunk/matplotlib/examples/integral_demo.py 2007-08-02 18:37:32 UTC (rev 3664)
@@ -22,8 +22,8 @@
ax.add_patch(poly)
text(0.5 * (a + b), 30,
- r"$\int_a^b f(x)\rm{d}x$", horizontalalignment='center',
- fontsize=20)
+ r"$\int_a^b f(x)\mathrm{d}x$", horizontalalignment='center',
+ fontsize=20, markup='tex')
axis([0,10, 0, 180])
figtext(0.9, 0.05, 'x')
Modified: trunk/matplotlib/examples/legend_auto.py
===================================================================
--- trunk/matplotlib/examples/legend_auto.py 2007-08-02 15:15:29 UTC (rev 3663)
+++ trunk/matplotlib/examples/legend_auto.py 2007-08-02 18:37:32 UTC (rev 3664)
@@ -51,9 +51,9 @@
def fig_7():
figure(7)
xx = x - (N/2.0)
- plot(xx, (xx*xx)-1225, 'bo', label='$y=x^2$')
- plot(xx, 25*xx, 'go', label='$y=25x$')
- plot(xx, -25*xx, 'mo', label='$y=-25x$')
+ plot(xx, (xx*xx)-1225, 'bo', label='$y=x^2$', markup='tex')
+ plot(xx, 25*xx, 'go', label='$y=25x$', markup='tex')
+ plot(xx, -25*xx, 'mo', label='$y=-25x$', markup='tex')
legend()
def fig_8():
Modified: trunk/matplotlib/examples/mathtext_demo.py
===================================================================
--- trunk/matplotlib/examples/mathtext_demo.py 2007-08-02 15:15:29 UTC (rev 3663)
+++ trunk/matplotlib/examples/mathtext_demo.py 2007-08-02 18:37:32 UTC (rev 3664)
@@ -17,7 +17,7 @@
ax.set_ylabel(r'$\Delta_{i+1}^j$', fontsize=20)
tex = r'$\mathcal{R}\prod_{i=\alpha_{i+1}}^\infty a_i\sin(2 \pi f x_i)$'
-ax.text(1, 1.6, tex, fontsize=20, va='bottom')
+ax.text(1, 1.6, tex, fontsize=20, va='bottom', markup="tex")
#title(r'$\Delta_i^j \hspace{0.4} \rm{versus} \hspace{0.4} \Delta_{i+1}^j$', fontsize=20)
fig.savefig('mathtext_demo')
Modified: trunk/matplotlib/examples/mathtext_examples.py
===================================================================
--- trunk/matplotlib/examples/mathtext_examples.py 2007-08-02 15:15:29 UTC (rev 3663)
+++ trunk/matplotlib/examples/mathtext_examples.py 2007-08-02 18:37:32 UTC (rev 3664)
@@ -62,7 +62,7 @@
x = arange(0.0, 3.0, 0.1)
grid(True)
- text(1, 1.6, s, fontsize=20)
+ text(1, 1.6, s, fontsize=20, markup="tex")
savefig('mathtext_example%02d' % i)
figure()
Modified: trunk/matplotlib/examples/scatter_demo2.py
===================================================================
--- trunk/matplotlib/examples/scatter_demo2.py 2007-08-02 15:15:29 UTC (rev 3663)
+++ trunk/matplotlib/examples/scatter_demo2.py 2007-08-02 18:37:32 UTC (rev 3664)
@@ -11,8 +11,8 @@
close = 0.003*intc.close[:-2]/0.003*intc.open[:-2]
p = scatter(delta1[:-1], delta1[1:], c=close, s=volume, alpha=0.75)
-xlabel(r'$\Delta_i$', size='x-large')
-ylabel(r'$\Delta_{i+1}$', size='x-large')
+xlabel(r'$\Delta_i$', size='x-large', markup='tex')
+ylabel(r'$\Delta_{i+1}$', size='x-large', markup='tex')
title(r'Volume and percent change')
grid(True)
#savefig('scatter_demo2')
Modified: trunk/matplotlib/examples/tex_demo.py
===================================================================
--- trunk/matplotlib/examples/tex_demo.py 2007-08-02 15:15:29 UTC (rev 3663)
+++ trunk/matplotlib/examples/tex_demo.py 2007-08-02 18:37:32 UTC (rev 3664)
@@ -23,10 +23,10 @@
s = cos(2*2*pi*t)+2
plot(t, s)
-xlabel(r'\textbf{time (s)}')
-ylabel(r'\textit{voltage (mV)}',fontsize=16)
+xlabel(r'\textbf{time (s)}', markup='tex')
+ylabel(r'\textit{voltage (mV)}',fontsize=16, markup='tex')
title(r"\TeX\ is Number $\displaystyle\sum_{n=1}^\infty\frac{-e^{i\pi}}{2^n}$!",
- fontsize=16, color='r')
+ fontsize=16, color='r', markup='tex')
grid(True)
savefig('tex_demo')
Modified: trunk/matplotlib/examples/tex_unicode_demo.py
===================================================================
--- trunk/matplotlib/examples/tex_unicode_demo.py 2007-08-02 15:15:29 UTC (rev 3663)
+++ trunk/matplotlib/examples/tex_unicode_demo.py 2007-08-02 18:37:32 UTC (rev 3664)
@@ -17,11 +17,11 @@
s = cos(2*2*pi*t)+2
plot(t, s)
-xlabel(r'\textbf{time (s)}')
+xlabel(r'\textbf{time (s)}', markup='tex')
s = unicode(r'\textit{Velocity (\xB0/sec)}','latin-1')
-ylabel(unicode(r'\textit{Velocity (\xB0/sec)}','latin-1'),fontsize=16)
+ylabel(unicode(r'\textit{Velocity (\xB0/sec)}','latin-1'),fontsize=16, markup='tex')
title(r"\TeX\ is Number $\displaystyle\sum_{n=1}^\infty\frac{-e^{i\pi}}{2^n}$!",
- fontsize=16, color='r')
+ fontsize=16, color='r', markup='tex')
grid(True)
savefig('tex_demo')
Modified: trunk/matplotlib/lib/matplotlib/mathtext.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/mathtext.py 2007-08-02 15:15:29 UTC (rev 3663)
+++ trunk/matplotlib/lib/matplotlib/mathtext.py 2007-08-02 18:37:32 UTC (rev 3664)
@@ -1840,6 +1840,8 @@
)
)
+ self.clear()
+
def clear(self):
self._expr = None
self._state_stack = None
Modified: trunk/matplotlib/lib/matplotlib/rcsetup.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/rcsetup.py 2007-08-02 15:15:29 UTC (rev 3663)
+++ trunk/matplotlib/lib/matplotlib/rcsetup.py 2007-08-02 18:37:32 UTC (rev 3664)
@@ -198,6 +198,11 @@
except ValueError:
raise ValueError('not a valid font size')
+validate_markup = ValidateInStrings(
+ 'markup',
+ ['plain', 'tex'],
+ ignorecase=True)
+
validate_verbose = ValidateInStrings('verbose',[
'silent', 'helpful', 'debug', 'debug-annoying',
])
@@ -350,8 +355,8 @@
'text.fontvariant' : ['normal', str],
'text.fontweight' : ['normal', str],
'text.fontsize' : ['medium', validate_fontsize],
+ 'text.markup' : ['plain', validate_markup],
-
'image.aspect' : ['equal', validate_aspect], # equal, auto, a number
'image.interpolation' : ['bilinear', str],
'image.cmap' : ['jet', str], # one of gray, jet, etc
Modified: trunk/matplotlib/lib/matplotlib/text.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/text.py 2007-08-02 15:15:29 UTC (rev 3663)
+++ trunk/matplotlib/lib/matplotlib/text.py 2007-08-02 18:37:32 UTC (rev 3664)
@@ -146,6 +146,7 @@
fontproperties=None, # defaults to FontProperties()
rotation=None,
linespacing=None,
+ markup=None,
**kwargs
):
"""
@@ -174,6 +175,7 @@
if linespacing is None:
linespacing = 1.2 # Maybe use rcParam later.
self._linespacing = linespacing
+ self.set_markup(markup)
self.update(kwargs)
#self.set_bbox(dict(pad=0))
__init__.__doc__ = cbook.dedent(__init__.__doc__) % artist.kwdocd
@@ -222,6 +224,7 @@
self._rotation = other._rotation
self._picker = other._picker
self._linespacing = other._linespacing
+ self._markup = other._markup
def _get_layout(self, renderer):
@@ -752,11 +755,11 @@
self._substrings = [] # ignore embedded mathtext for now
def is_math_text(self):
- if rcParams['text.usetex']: return 'TeX'
- if not matplotlib._havemath: return False
- if len(self._text)<2: return False
- dollar_signs = self._text.count('$') - self._text.count('\\$')
- return dollar_signs > 0 and dollar_signs % 2 == 0
+ if rcParams['text.usetex']: return 'TeX'
+ if self._markup.lower() == 'tex':
+ if not matplotlib._havemath: return False
+ return True
+ return False
def set_fontproperties(self, fp):
"""
@@ -766,9 +769,20 @@
"""
self._fontproperties = fp
+ def set_markup(self, markup):
+ """
+ Set the type of markup used for this text.
+ ACCEPTS: 'plain' for plain text, 'tex' for TeX-like markup
+ None to use the default text.markup value.
+ """
+ if markup is None:
+ self._markup = rcParams['text.markup']
+ elif markup.lower() in ('plain', 'tex'):
+ self._markup = markup.lower()
+ else:
+ raise ValueError("Markup type must be 'plain' or 'tex'")
-
def _get_layout_super(self, renderer, m):
"""
a special case optimization if a log super and angle = 0
Modified: trunk/matplotlib/matplotlibrc.template
===================================================================
--- trunk/matplotlib/matplotlibrc.template 2007-08-02 15:15:29 UTC (rev 3663)
+++ trunk/matplotlib/matplotlibrc.template 2007-08-02 18:37:32 UTC (rev 3664)
@@ -150,6 +150,14 @@
#text.dvipnghack : False # some versions of dvipng don't handle
# alpha channel properly. Use True to correct and flush
# ~/.matplotlib/tex.cache before testing
+#text.markup : 'plain' # Affects how text, such as titles and lables, are
+ # interpreted by default.
+ # 'plain': As plain, unformatted text
+ # 'tex': As TeX-like text. Text between $'s will be
+ # formatted as a TeX math expression.
+ # This setting has no effect when text.usetex is True.
+ # In that case, all text will be sent to TeX for
+ # processing.
### AXES
# default face and edge color, default tick sizes,
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <md...@us...> - 2007-08-02 15:15:37
|
Revision: 3663
http://matplotlib.svn.sourceforge.net/matplotlib/?rev=3663&view=rev
Author: mdboom
Date: 2007-08-02 08:15:29 -0700 (Thu, 02 Aug 2007)
Log Message:
-----------
Minor mathtext bugfixes
Modified Paths:
--------------
trunk/matplotlib/lib/matplotlib/mathtext.py
Modified: trunk/matplotlib/lib/matplotlib/mathtext.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/mathtext.py 2007-08-01 17:28:58 UTC (rev 3662)
+++ trunk/matplotlib/lib/matplotlib/mathtext.py 2007-08-02 15:15:29 UTC (rev 3663)
@@ -1031,7 +1031,7 @@
return '[%s <%d %d %d %d> %s]' % (self.__internal_repr__(),
self.width, self.height,
self.depth, self.shift_amount,
- ' '.join(self.children))
+ ' '.join([repr(x) for x in self.children]))
def _determine_order(self, totals):
"""A helper function to determine the highest order of glue
@@ -2104,7 +2104,7 @@
# @757
sub.shrink()
x = Hlist([sub])
- x.width += SCRIPT_SPACE * xHeight
+ # x.width += SCRIPT_SPACE * xHeight
shift_down = max(shift_down, SUB1)
clr = x.height - (abs(xHeight * 4.0) / 5.0)
shift_down = max(shift_down, clr)
@@ -2122,7 +2122,7 @@
else: # Both sub and superscript
sub.shrink()
y = Hlist([sub])
- y.width += SCRIPT_SPACE * xHeight
+ # y.width += SCRIPT_SPACE * xHeight
shift_down = max(shift_down, SUB1 * xHeight)
clr = 2.0 * rule_thickness - ((shift_up - x.depth) - (y.height - shift_down))
if clr > 0.:
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <md...@us...> - 2007-08-01 17:29:01
|
Revision: 3662
http://matplotlib.svn.sourceforge.net/matplotlib/?rev=3662&view=rev
Author: mdboom
Date: 2007-08-01 10:28:58 -0700 (Wed, 01 Aug 2007)
Log Message:
-----------
Convert _ttconv.cpp to use raw Python/C API, rather than CXX.
Modified Paths:
--------------
trunk/matplotlib/src/_ttconv.cpp
Modified: trunk/matplotlib/src/_ttconv.cpp
===================================================================
--- trunk/matplotlib/src/_ttconv.cpp 2007-08-01 16:21:11 UTC (rev 3661)
+++ trunk/matplotlib/src/_ttconv.cpp 2007-08-01 17:28:58 UTC (rev 3662)
@@ -1,181 +1,204 @@
-#include "CXX/Extensions.hxx"
-#include "CXX/Objects.hxx"
-#include "ttconv/pprdrv.h"
+/*
+ _ttconv.c
-class ttconv_module : public Py::ExtensionModule<ttconv_module>
-{
-public:
- ttconv_module()
- : Py::ExtensionModule<ttconv_module>( "ttconv" )
- {
- add_varargs_method("convert_ttf_to_ps",
- &ttconv_module::convert_ttf_to_ps,
- ttconv_module::convert_ttf_to_ps__doc__);
- add_varargs_method("get_pdf_charprocs",
- &ttconv_module::get_pdf_charprocs,
- ttconv_module::get_pdf_charprocs__doc__);
+ Python wrapper for TrueType conversion library in ../ttconv.
+ */
- initialize( "The ttconv module" );
- }
+#include <Python.h>
+#include "ttconv/pprdrv.h"
+#include <vector>
- Py::Object
- convert_ttf_to_ps(const Py::Tuple& args);
- static char convert_ttf_to_ps__doc__[];
-
- Py::Object
- get_pdf_charprocs(const Py::Tuple& args);
- static char get_pdf_charprocs__doc__[];
-};
-
-char ttconv_module::convert_ttf_to_ps__doc__[] =
-"convert_ttf_to_ps(filename, output, fonttype, glyph_ids)\n"
-"\n"
-"Converts the Truetype font into a Type 3 or Type 42 Postscript font, "
-"optionally subsetting the font to only the desired set of characters.\n"
-"\n"
-"filename is the path to a TTF font file.\n"
-"output is a Python file-like object with a write method that the Postscript "
-"font data will be written to.\n"
-"fonttype may be either 3 or 42. Type 3 is a \"raw Postscript\" font. "
-"Type 42 is an embedded Truetype font. Glyph subsetting is not supported "
-"for Type 42 fonts.\n"
-"glyph_ids (optional) is a list of glyph ids (integers) to keep when "
-"subsetting to a Type 3 font. If glyph_ids is not provided or is None, "
-"then all glyphs will be included. If any of the glyphs specified are "
-"composite glyphs, then the component glyphs will also be included."
-;
-
/**
* An implementation of TTStreamWriter that writes to a Python
* file-like object.
*/
class PythonFileWriter : public TTStreamWriter {
- Py::Callable _write_method;
+ PyObject* _write_method;
public:
- PythonFileWriter(const Py::Object& file_like_object) {
- _write_method = file_like_object.getAttr( "write" );
+ PythonFileWriter() {
+ _write_method = NULL;
}
+ ~PythonFileWriter() {
+ if (_write_method)
+ Py_DECREF(_write_method);
+ }
+
+ void set(PyObject* write_method) {
+ if (_write_method)
+ Py_DECREF(_write_method);
+ _write_method = write_method;
+ if (_write_method)
+ Py_INCREF(_write_method);
+ }
+
virtual void write(const char* a) {
- Py::Tuple args(1);
- args[0] = Py::String(a);
- _write_method.apply(args);
+ if (_write_method)
+ PyObject_CallFunction(_write_method, "s", a);
}
};
-Py::Object
-ttconv_module::convert_ttf_to_ps(const Py::Tuple & args) {
- args.verify_length(3, 4);
+int fileobject_to_PythonFileWriter(PyObject* object, void* address) {
+ PythonFileWriter* file_writer = (PythonFileWriter*)address;
+ PyObject* write_method = PyObject_GetAttrString(object, "write");
+ if (write_method == NULL || ! PyCallable_Check(write_method)) {
+ PyErr_SetString(PyExc_TypeError, "Expected a file-like object with a write method.");
+ return 0;
+ }
+ file_writer->set(write_method);
+ return 1;
+}
- std::string fname = Py::String(args[0]).as_std_string();
+int pyiterable_to_vector_int(PyObject* object, void* address) {
+ std::vector<int>* result = (std::vector<int>*)address;
+ PyObject* iterator = PyObject_GetIter(object);
+ if (! iterator)
+ return 0;
+ PyObject* item;
+ while (item = PyIter_Next(iterator)) {
+ long value = PyInt_AsLong(item);
+ if (value == -1 && PyErr_Occurred())
+ return 0;
+ result->push_back(value);
+ }
+ return 1;
+}
- PythonFileWriter python_file_writer(args[1]);
+static PyObject*
+convert_ttf_to_ps(PyObject* self, PyObject* args, PyObject* kwds) {
+ const char* filename;
+ PythonFileWriter output;
+ int fonttype;
+ std::vector<int> glyph_ids;
- long font_type = (long)Py::Int(args[2]);
- if ( font_type != 3 && font_type != 42 ) {
- throw Py::ValueError("Font type must be either 3 (raw Postscript) or 42 (embedded Truetype)");
+ static char *kwlist[] = { "filename", "output", "fonttype", "glyph_ids", NULL };
+ if (! PyArg_ParseTupleAndKeywords
+ (args, kwds,
+ "sO&i|O&:convert_ttf_to_ps", kwlist,
+ &filename,
+ fileobject_to_PythonFileWriter,
+ &output,
+ &fonttype,
+ pyiterable_to_vector_int,
+ &glyph_ids))
+ return NULL;
+
+ if (fonttype != 3 && fonttype != 42) {
+ PyErr_SetString(PyExc_ValueError,
+ "fonttype must be either 3 (raw Postscript) or 42 "
+ "(embedded Truetype)");
+ return NULL;
}
- std::vector<int> glyph_ids;
- if ( args.size() == 4 ) {
- if ( args[3] != Py::None() ) {
- Py::SeqBase< Py::Int > py_glyph_ids = args[3];
- size_t num_glyphs = py_glyph_ids.size();
- // If there are no included glyphs, just return
- if (num_glyphs == 0) {
- return Py::Object();
- }
- glyph_ids.reserve(num_glyphs);
- for (size_t i = 0; i < num_glyphs; ++i) {
- glyph_ids.push_back( (long) py_glyph_ids.getItem(i) );
- }
- }
- }
-
try {
- insert_ttfont( fname.c_str(), python_file_writer, (font_type_enum) font_type, glyph_ids );
+ insert_ttfont( filename, output, (font_type_enum)fonttype, glyph_ids );
} catch (TTException& e) {
- throw Py::RuntimeError(e.getMessage());
+ PyErr_SetString(PyExc_RuntimeError, e.getMessage());
+ return NULL;
+ } catch (...) {
+ PyErr_SetString(PyExc_RuntimeError, "Unknown C++ exception");
+ return NULL;
}
- return Py::Object();
+ Py_INCREF(Py_None);
+ return Py_None;
}
-char ttconv_module::get_pdf_charprocs__doc__[] =
-"get_pdf_charprocs(filename, glyph_ids)\n"
-"\n"
-"Given a Truetype font file, returns a dictionary containing the PDF Type 3\n"
-"representation of its path. Useful for subsetting a Truetype font inside\n"
-"of a PDF file.\n"
-"\n"
-"filename is the path to a TTF font file.\n"
-"glyph_ids is a list of the numeric glyph ids to include.\n"
-"The return value is a dictionary where the keys are glyph names and \n"
-"the values are the stream content needed to render that glyph. This\n"
-"is useful to generate the CharProcs dictionary in a PDF Type 3 font.\n"
-;
-
-/**
- * An implementation of TTStreamWriter that writes to a Python
- * file-like object.
- */
class PythonDictionaryCallback : public TTDictionaryCallback {
- Py::Dict _dict;
+ PyObject* _dict;
public:
- PythonDictionaryCallback(const Py::Dict& dict) : _dict(dict) {
-
+ PythonDictionaryCallback(PyObject* dict) {
+ _dict = dict;
}
virtual void add_pair(const char* a, const char* b) {
- _dict.setItem(a, Py::String(b));
+ PyObject* value = PyString_FromString(b);
+ if (value)
+ PyDict_SetItemString(_dict, a, value);
}
};
-Py::Object
-ttconv_module::get_pdf_charprocs(const Py::Tuple & args) {
- args.verify_length(1, 2);
+static PyObject*
+py_get_pdf_charprocs(PyObject* self, PyObject* args, PyObject* kwds) {
+ const char* filename;
+ std::vector<int> glyph_ids;
+ PyObject* result;
- Py::Dict result;
+ static char *kwlist[] = { "filename", "glyph_ids", NULL };
+ if (! PyArg_ParseTupleAndKeywords
+ (args, kwds,
+ "s|O&:convert_ttf_to_ps", kwlist,
+ &filename,
+ pyiterable_to_vector_int,
+ &glyph_ids))
+ return NULL;
- std::string fname = Py::String(args[0]).as_std_string();
+ result = PyDict_New();
+ if (!result)
+ return NULL;
- std::vector<int> glyph_ids;
- if ( args.size() == 2 ) {
- if ( args[1] != Py::None() ) {
- Py::SeqBase< Py::Int > py_glyph_ids = args[1];
- size_t num_glyphs = py_glyph_ids.size();
- // If there are no included glyphs, just return
- if (num_glyphs == 0) {
- return result;
- }
- glyph_ids.reserve(num_glyphs);
- for (size_t i = 0; i < num_glyphs; ++i) {
- glyph_ids.push_back( (long) py_glyph_ids.getItem(i) );
- }
- }
- }
+ PythonDictionaryCallback dict(result);
- PythonDictionaryCallback dictCallback(result);
-
try {
- ::get_pdf_charprocs( fname.c_str(), glyph_ids, dictCallback );
+ ::get_pdf_charprocs( filename, glyph_ids, dict );
} catch (TTException& e) {
- throw Py::RuntimeError(e.getMessage());
+ PyErr_SetString(PyExc_RuntimeError, e.getMessage());
+ return NULL;
+ } catch (...) {
+ PyErr_SetString(PyExc_RuntimeError, "Unknown C++ exception");
+ return NULL;
}
return result;
}
-#if defined(_MSC_VER)
-DL_EXPORT(void)
-#elif defined(__cplusplus)
- extern "C" void
-#else
-void
+static PyMethodDef ttconv_methods[] = {
+ {"convert_ttf_to_ps", (PyCFunction)convert_ttf_to_ps, METH_KEYWORDS,
+ "convert_ttf_to_ps(filename, output, fonttype, glyph_ids)\n"
+ "\n"
+ "Converts the Truetype font into a Type 3 or Type 42 Postscript font, "
+ "optionally subsetting the font to only the desired set of characters.\n"
+ "\n"
+ "filename is the path to a TTF font file.\n"
+ "output is a Python file-like object with a write method that the Postscript "
+ "font data will be written to.\n"
+ "fonttype may be either 3 or 42. Type 3 is a \"raw Postscript\" font. "
+ "Type 42 is an embedded Truetype font. Glyph subsetting is not supported "
+ "for Type 42 fonts.\n"
+ "glyph_ids (optional) is a list of glyph ids (integers) to keep when "
+ "subsetting to a Type 3 font. If glyph_ids is not provided or is None, "
+ "then all glyphs will be included. If any of the glyphs specified are "
+ "composite glyphs, then the component glyphs will also be included."
+ },
+ {"get_pdf_charprocs", (PyCFunction)py_get_pdf_charprocs, METH_KEYWORDS,
+ "get_pdf_charprocs(filename, glyph_ids)\n"
+ "\n"
+ "Given a Truetype font file, returns a dictionary containing the PDF Type 3\n"
+ "representation of its path. Useful for subsetting a Truetype font inside\n"
+ "of a PDF file.\n"
+ "\n"
+ "filename is the path to a TTF font file.\n"
+ "glyph_ids is a list of the numeric glyph ids to include.\n"
+ "The return value is a dictionary where the keys are glyph names and \n"
+ "the values are the stream content needed to render that glyph. This\n"
+ "is useful to generate the CharProcs dictionary in a PDF Type 3 font.\n"
+ },
+ {NULL} /* Sentinel */
+};
+
+#ifndef PyMODINIT_FUNC /* declarations for DLL import/export */
+#define PyMODINIT_FUNC void
#endif
-initttconv(void)
+PyMODINIT_FUNC
+initttconv(void)
{
- static ttconv_module* ttconv = new ttconv_module;
+ PyObject* m;
+
+ m = Py_InitModule3("ttconv", ttconv_methods,
+ "Module to handle converting and subsetting TrueType "
+ "fonts to Postscript Type 3, Postscript Type 42 and "
+ "Pdf Type 3 fonts.");
}
+
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|