Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project!

## matplotlib-checkins

 SF.net SVN: matplotlib: [3612] branches/mathtext_mgd From: - 2007-07-25 15:40:14 Revision: 3612 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=3612&view=rev Author: mdboom Date: 2007-07-25 08:34:52 -0700 (Wed, 25 Jul 2007) Log Message: ----------- Fix for get_xheight/get_underline_thickness. Update examples to use new math syntax. Modified Paths: -------------- branches/mathtext_mgd/examples/mathtext_demo.py branches/mathtext_mgd/lib/matplotlib/mathtext.py Modified: branches/mathtext_mgd/examples/mathtext_demo.py =================================================================== --- branches/mathtext_mgd/examples/mathtext_demo.py 2007-07-25 14:43:13 UTC (rev 3611) +++ branches/mathtext_mgd/examples/mathtext_demo.py 2007-07-25 15:34:52 UTC (rev 3612) @@ -17,8 +17,8 @@ grid(True) 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)$' -text(1, 1.6, tex, fontsize=20) +tex = r'$\mathcal{R}\prod_{i=\alpha_{i+1}}^\infty a_i\sin(2 \pi f x_i)$' +text(1, 1.6, tex, fontsize=20, va='bottom') #title(r'$\Delta_i^j \hspace{0.4} \rm{versus} \hspace{0.4} \Delta_{i+1}^j$', fontsize=20) savefig('mathtext_demo') Modified: branches/mathtext_mgd/lib/matplotlib/mathtext.py =================================================================== --- branches/mathtext_mgd/lib/matplotlib/mathtext.py 2007-07-25 14:43:13 UTC (rev 3611) +++ branches/mathtext_mgd/lib/matplotlib/mathtext.py 2007-07-25 15:34:52 UTC (rev 3612) @@ -699,7 +699,6 @@ basename, font, metrics, symbol_name, num, glyph, offset = \ self._get_info(font, sym, fontsize, dpi) - font.draw_rect(0, 0, self.width - 1, self.height - 1) font.draw_glyph_to_bitmap( int(ox), int(oy - metrics.ymax), glyph) @@ -711,16 +710,16 @@ def get_used_characters(self): return self.used_characters - def get_xheight(self, font, fontsize): + def get_xheight(self, font, fontsize, dpi): basename, cached_font = self._get_font(font) - cached_font.font.set_size(fontsize) + cached_font.font.set_size(fontsize, dpi) pclt = cached_font.font.get_sfnt_table('pclt') xHeight = pclt['xHeight'] / 64.0 return xHeight - def get_underline_thickness(self, font, fontsize): + def get_underline_thickness(self, font, fontsize, dpi): basename, cached_font = self._get_font(font) - cached_font.font.set_size(fontsize) + cached_font.font.set_size(fontsize, dpi) return max(1.0, cached_font.font.underline_thickness / 64.0) def get_kern(self, fontleft, symleft, fontsizeleft, @@ -944,11 +943,11 @@ ps = "%f %f %f %f rectfill" % (x1, self.height - y2, x2 - x1, y2 - y1) self.pswriter.write(ps) - def get_xheight(self, font, fontsize): + def get_xheight(self, font, fontsize, dpi): basename, cached_font = self._get_font(font) return cached_font.get_xheight() * 0.001 * fontsize - def get_underline_thickness(self, font, fontsize): + def get_underline_thickness(self, font, fontsize, dpi): basename, cached_font = self._get_font(font) return cached_font.get_underline_thickness() * 0.001 * fontsize @@ -1367,7 +1366,7 @@ """Convenience class to create a horizontal rule.""" def __init__(self, state): thickness = state.font_output.get_underline_thickness( - state.font, state.fontsize) + state.font, state.fontsize, state.dpi) height = depth = thickness * 0.5 Rule.__init__(self, None, height, depth, state) @@ -1375,7 +1374,7 @@ """Convenience class to create a vertical rule.""" def __init__(self, state): thickness = state.font_output.get_underline_thickness( - state.font, state.fontsize) + state.font, state.fontsize, state.dpi) Rule.__init__(self, thickness, None, None, state) class Glue(Node): @@ -1950,6 +1949,7 @@ return [box] def symbol(self, s, loc, toks): + # print "symbol", toks c = toks[0] if c in self._spaced_symbols: return [Hlist([self._make_space(0.3), @@ -1982,7 +1982,7 @@ assert(len(toks)==1) state = self.get_state() thickness = state.font_output.get_underline_thickness( - state.font, state.fontsize) + state.font, state.fontsize, state.dpi) accent, sym = toks[0] accent = Accent(self._accent_map[accent], self.get_state()) centered = HCentered([accent]) @@ -2067,11 +2067,12 @@ sub = next2 else: raise ParseFatalException("Subscript/superscript string is too long.") - + state = self.get_state() rule_thickness = state.font_output.get_underline_thickness( - state.font, state.fontsize) - xHeight = state.font_output.get_xheight(state.font, state.fontsize) + state.font, state.fontsize, state.dpi) + xHeight = state.font_output.get_xheight( + state.font, state.fontsize, state.dpi) if self.is_overunder(nucleus): vlist = [] @@ -2155,7 +2156,7 @@ cden.hpack(width, 'exactly') state = self.get_state() thickness = state.font_output.get_underline_thickness( - state.font, state.fontsize) + state.font, state.fontsize, state.dpi) space = thickness * 3.0 vlist = Vlist([cnum, FixedGlue(thickness * 2.0), @@ -2243,7 +2244,7 @@ pswriter = list() font_output.set_canvas_size(w, h, pswriter) ship(2, 2, box) - + if self.output == 'SVG': # The empty list at the end is for lines svg_elements = Bunch(svg_glyphs=font_output.svg_glyphs, This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. 
 SF.net SVN: matplotlib: [3614] branches/mathtext_mgd From: - 2007-07-25 20:19:29 Revision: 3614 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=3614&view=rev Author: mdboom Date: 2007-07-25 13:19:25 -0700 (Wed, 25 Jul 2007) Log Message: ----------- Support auto-sized delimiters (e.g. \left(\frac{3}{2}\right)). Commit mathtext_examples.py Modified Paths: -------------- branches/mathtext_mgd/lib/matplotlib/mathtext.py Added Paths: ----------- branches/mathtext_mgd/examples/mathtext_examples.py Added: branches/mathtext_mgd/examples/mathtext_examples.py =================================================================== --- branches/mathtext_mgd/examples/mathtext_examples.py (rev 0) +++ branches/mathtext_mgd/examples/mathtext_examples.py 2007-07-25 20:19:25 UTC (rev 3614) @@ -0,0 +1,64 @@ +#!/usr/bin/env python + +import os, sys + +stests = [ + r'Kerning: AVA $AVA$', + r'$x y$', + r'$x+y\ x=y\ x') - equals = Literal('=') - relation =(langle - | rangle - | equals) - - colon = Literal(':') - comma = Literal(',') - period = Literal('.') - semicolon = Literal(';') - exclamation = Literal('!') - punctuation =(colon - | comma - | period - | semicolon) - - at = Literal('@') - percent = Literal('%') - ampersand = Literal('&') - misc =(exclamation - | at - | percent - | ampersand) - accent = oneOf("hat check dot breve acute ddot grave tilde bar vec " "\"  ' ~ . ^") @@ -1794,7 +1769,7 @@ symbol = Regex("(" + ")|(".join( [ - r"\$a-zA-Z0-9]+(?!{)", + r"\\(?!right)(?!left)[a-zA-Z0-9]+(?!{)", r"[a-zA-Z0-9 ]", r"[+\-*/]", r"[<>=]", @@ -1845,7 +1820,8 @@ simple <<(space | font - | subsuper) + | subsuper + ) subsuperop =(Literal("_") | Literal("^") @@ -1861,8 +1837,22 @@ | placeable ) + ambiDelim = oneOf(r"| \| / \backslash \uparrow \downarrow \updownarrow \Uparrow \Downarrow \Updownarrow") + leftDelim = oneOf(r"( [ { \lfloor \langle \lceil") + rightDelim = oneOf(r") ] } \rfloot \rangle \rceil") + + autoDelim <<(Suppress(Literal(r"\left")) + + (leftDelim | ambiDelim) + + Group( + autoDelim + ^ OneOrMore(simple)) + + Suppress(Literal(r"\right")) + + (rightDelim | ambiDelim) + ) + math = OneOrMore( - simple + autoDelim + | simple ).setParseAction(self.math).setName("math") math_delim =(~bslash @@ -1955,7 +1945,7 @@ return [Hlist([self._make_space(0.3), Char(c, self.get_state()), self._make_space(0.3)])] - elif c in self._delimiter_symbols: + elif c in self._punctuation_symbols: return [Hlist([Char(c, self.get_state()), self._make_space(0.3)])] return [Char(toks[0], self.get_state())] @@ -2173,8 +2163,17 @@ hlist = Hlist([vlist, FixedGlue(thickness * 2.)]) return [hlist] + def auto_sized_delimiter(self, s, loc, toks): + front, middle, back = toks + state = self.get_state() + height = max([x.height for x in middle]) + depth = max([x.depth for x in middle]) + hlist = Hlist( + [AutoSizedDelim(front, height, depth, state)] + + middle.asList() + + [AutoSizedDelim(back, height, depth, state)]) + return hlist - #### ############################################################################## This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.   SF.net SVN: matplotlib: [3615] branches/mathtext_mgd From: - 2007-07-26 13:26:29 Revision: 3615 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=3615&view=rev Author: mdboom Date: 2007-07-26 06:26:26 -0700 (Thu, 26 Jul 2007) Log Message: ----------- Important bugfix (many expressions were silently failing) Modified Paths: -------------- branches/mathtext_mgd/examples/mathtext_examples.py branches/mathtext_mgd/lib/matplotlib/_mathtext_data.py branches/mathtext_mgd/lib/matplotlib/mathtext.py Modified: branches/mathtext_mgd/examples/mathtext_examples.py =================================================================== --- branches/mathtext_mgd/examples/mathtext_examples.py 2007-07-25 20:19:25 UTC (rev 3614) +++ branches/mathtext_mgd/examples/mathtext_examples.py 2007-07-26 13:26:26 UTC (rev 3615) @@ -52,7 +52,7 @@ os.system("pdflatex mathtext_examples.ltx") else: for i, s in enumerate(stests): - print s + print "%02d: %s" % (i, s) plot([1,2,3], 'r') x = arange(0.0, 3.0, 0.1) Modified: branches/mathtext_mgd/lib/matplotlib/_mathtext_data.py =================================================================== --- branches/mathtext_mgd/lib/matplotlib/_mathtext_data.py 2007-07-25 20:19:25 UTC (rev 3614) +++ branches/mathtext_mgd/lib/matplotlib/_mathtext_data.py 2007-07-26 13:26:26 UTC (rev 3615) @@ -38,8 +38,10 @@ r'\SQRT' : ('cmex10', 53), r'\leftbrace' : ('cmex10', 92), r'{' : ('cmex10', 92), + r'\{' : ('cmex10', 92), r'\rightbrace' : ('cmex10', 130), r'}' : ('cmex10', 130), + r'\}' : ('cmex10', 130), r'\leftangle' : ('cmex10', 97), r'\rightangle' : ('cmex10', 64), r'\Leftparen' : ('cmex10', 112), Modified: branches/mathtext_mgd/lib/matplotlib/mathtext.py =================================================================== --- branches/mathtext_mgd/lib/matplotlib/mathtext.py 2007-07-25 20:19:25 UTC (rev 3614) +++ branches/mathtext_mgd/lib/matplotlib/mathtext.py 2007-07-26 13:26:26 UTC (rev 3615) @@ -59,17 +59,10 @@ ^ use raw strings - The symbols must be the first and last symbols in the string. Eg, - you cannot do + Math and non-math can be interpresed in the same string. E.g., r'My label x_i'. - but you can change fonts, as in - - r'\rm{My label} x_i' - - to achieve the same effect. - A large set of the TeX symbols are provided. Subscripting and superscripting are supported, as well as the over/under style of subscripting with \sum, \int, etc. @@ -1714,7 +1707,7 @@ _spaced_symbols = _binary_operators | _relation_symbols | _arrow_symbols - _punctuation_symbols = Set(r', ; . !'.split()) + _punctuation_symbols = Set(r', ; . ! \ldotp \cdotp'.split()) def __init__(self): # All forward declarations are here @@ -1769,15 +1762,14 @@ symbol = Regex("(" + ")|(".join( [ - r"\\(?!right)(?!left)[a-zA-Z0-9]+(?!{)", + r"\\(?!left[^a-z])(?!right[^a-z])[a-zA-Z0-9]+(?!{)", r"[a-zA-Z0-9 ]", r"[+\-*/]", r"[<>=]", r"[:,.;!]", r"[!@%&]", r"[[$()]", - r"\\\$", - r"\\\%" + r"\\[$%{}]", ]) + ")" ).setParseAction(self.symbol).leaveWhitespace() @@ -1828,7 +1820,7 @@ ) subsuper << Group( - ( placeable + ( Optional(placeable) + OneOrMore( subsuperop + placeable @@ -1837,7 +1829,9 @@ | placeable ) - ambiDelim = oneOf(r"| \| / \backslash \uparrow \downarrow \updownarrow \Uparrow \Downarrow \Updownarrow") + ambiDelim = oneOf(r"""| \| / \backslash \uparrow \downarrow + \updownarrow \Uparrow \Downarrow + \Updownarrow""") leftDelim = oneOf(r"( [ { \lfloor \langle \lceil") rightDelim = oneOf(r") ] } \rfloot \rangle \rceil") @@ -1861,9 +1855,9 @@ non_math = Regex(r"(?:[^$]|(?:\\\$))*" ).setParseAction(self.non_math).setName("non_math").leaveWhitespace() - self._expression <<( + self._expression <<( non_math - + ZeroOrMore( + + OneOrMore( Suppress(math_delim) + math + Suppress(math_delim) @@ -1908,6 +1902,7 @@ return [self._expr] def math(self, s, loc, toks): + #~ print "math", toks hlist = Hlist(toks) self.pop_state() return [hlist] @@ -2164,6 +2159,7 @@ return [hlist] def auto_sized_delimiter(self, s, loc, toks): + #~ print "auto_sized_delimiter", toks front, middle, back = toks state = self.get_state() height = max([x.height for x in middle]) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.   SF.net SVN: matplotlib: [3616] branches/mathtext_mgd From: - 2007-07-26 13:46:59 Revision: 3616 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=3616&view=rev Author: mdboom Date: 2007-07-26 06:46:56 -0700 (Thu, 26 Jul 2007) Log Message: ----------- Committing in preparation for merge Modified Paths: -------------- branches/mathtext_mgd/examples/mathtext_examples.py branches/mathtext_mgd/lib/matplotlib/mathtext.py Modified: branches/mathtext_mgd/examples/mathtext_examples.py =================================================================== --- branches/mathtext_mgd/examples/mathtext_examples.py 2007-07-26 13:26:26 UTC (rev 3615) +++ branches/mathtext_mgd/examples/mathtext_examples.py 2007-07-26 13:46:56 UTC (rev 3616) @@ -10,7 +10,7 @@ r'$x\leftarrow y\ x\forall y$', r'$x \sf x \bf x {\cal X} \rm x$', r'$\{ \rm braces \}$', - r'$\left[\left\lfloor\frac{5}{\frac{3}{4}} y\right)\right]$', + r'$\left[\left\lfloor\frac{5}{\frac{\left(3\right)}{4}} y\right)\right]$', r'$\left(x\right)$', r'$\sin(x)$', r'$x_2\$', Modified: branches/mathtext_mgd/lib/matplotlib/mathtext.py =================================================================== --- branches/mathtext_mgd/lib/matplotlib/mathtext.py 2007-07-26 13:26:26 UTC (rev 3615) +++ branches/mathtext_mgd/lib/matplotlib/mathtext.py 2007-07-26 13:46:56 UTC (rev 3616) @@ -1728,24 +1728,16 @@ bslash = Literal('\\') - accent = oneOf("hat check dot breve acute ddot grave tilde bar vec " - "\"  ' ~ . ^") + accent = oneOf("hat check dot breve acute ddot grave tilde bar " + "vec \"  ' ~ . ^") - function = oneOf("arccos csc ker min arcsin deg lg Pr arctan det lim sec " - "arg dim liminf sin cos exp limsup sinh cosh gcd ln sup " - "cot hom log tan coth inf max tanh") + function = oneOf("arccos csc ker min arcsin deg lg Pr arctan det " + "lim sec arg dim liminf sin cos exp limsup sinh " + "cosh gcd ln sup cot hom log tan coth inf max " + "tanh") number = Combine(Word(nums) + Optional(Literal('.')) + Optional( Word(nums) )) - plus = Literal('+') - minus = Literal('-') - times = Literal('*') - div = Literal('/') - binop =(plus - | minus - | times - | div) - fontname = oneOf("rm cal it tt sf bf") latex2efont = oneOf("mathrm mathcal mathit mathtt mathsf mathbf") @@ -1784,7 +1776,9 @@ group = Group( start_group - + OneOrMore(simple) + + OneOrMore( + autoDelim + | simple) + end_group ).setParseAction(self.group).setName("group") @@ -1833,8 +1827,7 @@ \updownarrow \Uparrow \Downarrow \Updownarrow""") leftDelim = oneOf(r"( [ { \lfloor \langle \lceil") - rightDelim = oneOf(r") ] } \rfloot \rangle \rceil") - + rightDelim = oneOf(r") ] } \rfloor \rangle \rceil") autoDelim <<(Suppress(Literal(r"\left")) + (leftDelim | ambiDelim) + Group( This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. `