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
|
S | M | T | W | T | F | S |
---|---|---|---|---|---|---|
|
|
|
1
(16) |
2
(7) |
3
(4) |
4
|
5
|
6
(4) |
7
(5) |
8
(6) |
9
(7) |
10
(4) |
11
|
12
(2) |
13
(5) |
14
(3) |
15
|
16
(5) |
17
(1) |
18
|
19
|
20
(5) |
21
(7) |
22
(3) |
23
(5) |
24
(1) |
25
|
26
|
27
(6) |
28
(7) |
29
(3) |
30
(8) |
31
(6) |
|
From: <md...@us...> - 2007-08-31 19:35:12
|
Revision: 3766 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=3766&view=rev Author: mdboom Date: 2007-08-31 12:35:09 -0700 (Fri, 31 Aug 2007) Log Message: ----------- Fix log expression. Modified Paths: -------------- trunk/matplotlib/examples/mathtext_wx.py Modified: trunk/matplotlib/examples/mathtext_wx.py =================================================================== --- trunk/matplotlib/examples/mathtext_wx.py 2007-08-31 19:25:34 UTC (rev 3765) +++ trunk/matplotlib/examples/mathtext_wx.py 2007-08-31 19:35:09 UTC (rev 3766) @@ -31,7 +31,7 @@ (r'$\sin(2 \pi x)$' , lambda x: sin(2*pi*x)), (r'$\frac{4}{3}\pi x^3$' , lambda x: (4.0 / 3.0) * pi * x**3), (r'$\cos(2 \pi x)$' , lambda x: cos(2*pi*x)), - (r'$\log x$' , lambda x: log(x)) + (r'$\log(x)$' , lambda x: log(x)) ] class CanvasFrame(wx.Frame): This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <md...@us...> - 2007-08-31 19:25:36
|
Revision: 3765 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=3765&view=rev Author: mdboom Date: 2007-08-31 12:25:34 -0700 (Fri, 31 Aug 2007) Log Message: ----------- Render all the fonts in each mathtext expression to a single image buffer (memory and time savings). Add support for getting raw image data for mathtext expressions. Add mathtext_wx.py example showing how to put mathtext expressions into controls. Added Paths: ----------- trunk/matplotlib/examples/mathtext_wx.py Added: trunk/matplotlib/examples/mathtext_wx.py =================================================================== --- trunk/matplotlib/examples/mathtext_wx.py (rev 0) +++ trunk/matplotlib/examples/mathtext_wx.py 2007-08-31 19:25:34 UTC (rev 3765) @@ -0,0 +1,124 @@ +""" +Demonstrates how to convert mathtext to a wx.Bitmap for display in various +controls on wxPython. +""" + +import matplotlib +matplotlib.use("WxAgg") +from matplotlib.numerix import arange, sin, pi, cos, log +from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as FigureCanvas +from matplotlib.backends.backend_wx import NavigationToolbar2Wx +from matplotlib.figure import Figure + +import wx + +IS_GTK = 'wxGTK' in wx.PlatformInfo +IS_WIN = 'wxMSW' in wx.PlatformInfo +IS_MAC = 'wxMac' in wx.PlatformInfo + +############################################################ +# This is where the "magic" happens. +from matplotlib.mathtext import MathTextParser +mathtext_parser = MathTextParser("Bitmap") +def mathtext_to_wxbitmap(s): + ftimage = mathtext_parser.parse(s, 150) + return wx.BitmapFromBufferRGBA( + ftimage.get_width(), ftimage.get_height(), + ftimage.as_rgba_str()) +############################################################ + +functions = [ + (r'$\sin(2 \pi x)$' , lambda x: sin(2*pi*x)), + (r'$\frac{4}{3}\pi x^3$' , lambda x: (4.0 / 3.0) * pi * x**3), + (r'$\cos(2 \pi x)$' , lambda x: cos(2*pi*x)), + (r'$\log x$' , lambda x: log(x)) +] + +class CanvasFrame(wx.Frame): + def __init__(self, parent, title): + wx.Frame.__init__(self, parent, -1, title, size=(550, 350)) + self.SetBackgroundColour(wx.NamedColor("WHITE")) + + self.figure = Figure() + self.axes = self.figure.add_subplot(111) + self.change_plot(0) + + self.canvas = FigureCanvas(self, -1, self.figure) + + self.sizer = wx.BoxSizer(wx.VERTICAL) + self.add_buttonbar() + self.sizer.Add(self.canvas, 1, wx.LEFT | wx.TOP | wx.GROW) + self.add_toolbar() # comment this out for no toolbar + + menuBar = wx.MenuBar() + + # File Menu + menu = wx.Menu() + menu.Append(wx.ID_EXIT, "E&xit\tAlt-X", "Exit this simple sample") + menuBar.Append(menu, "&File") + + if IS_GTK or IS_WIN: + # Equation Menu + menu = wx.Menu() + for i, (mt, func) in enumerate(functions): + bm = mathtext_to_wxbitmap(mt) + item = wx.MenuItem(menu, 1000 + i, "") + item.SetBitmap(bm) + menu.AppendItem(item) + self.Bind(wx.EVT_MENU, self.OnChangePlot, item) + menuBar.Append(menu, "&Functions") + + self.SetMenuBar(menuBar) + + self.SetSizer(self.sizer) + self.Fit() + + def add_buttonbar(self): + self.button_bar = wx.Panel(self) + self.button_bar_sizer = wx.BoxSizer(wx.HORIZONTAL) + self.sizer.Add(self.button_bar, 0, wx.LEFT | wx.TOP | wx.GROW) + + for i, (mt, func) in enumerate(functions): + bm = mathtext_to_wxbitmap(mt) + button = wx.BitmapButton(self.button_bar, 1000 + i, bm) + self.button_bar_sizer.Add(button, 1, wx.GROW) + self.Bind(wx.EVT_BUTTON, self.OnChangePlot, button) + + self.button_bar.SetSizer(self.button_bar_sizer) + + def add_toolbar(self): + """Copied verbatim from embedding_wx2.py""" + self.toolbar = NavigationToolbar2Wx(self.canvas) + self.toolbar.Realize() + if IS_MAC: + self.SetToolBar(self.toolbar) + else: + tw, th = self.toolbar.GetSizeTuple() + fw, fh = self.canvas.GetSizeTuple() + self.toolbar.SetSize(wx.Size(fw, th)) + self.sizer.Add(self.toolbar, 0, wx.LEFT | wx.EXPAND) + self.toolbar.update() + + def OnPaint(self, event): + self.canvas.draw() + + def OnChangePlot(self, event): + self.change_plot(event.GetId() - 1000) + + def change_plot(self, plot_number): + t = arange(1.0,3.0,0.01) + s = functions[plot_number][1](t) + self.axes.clear() + self.axes.plot(t, s) + self.Refresh() + +class MyApp(wx.App): + def OnInit(self): + frame = CanvasFrame(None, "wxPython mathtext demo app") + self.SetTopWindow(frame) + frame.Show(True) + return True + +app = MyApp() +app.MainLoop() + This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <md...@us...> - 2007-08-31 19:25:20
|
Revision: 3764 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=3764&view=rev Author: mdboom Date: 2007-08-31 12:25:17 -0700 (Fri, 31 Aug 2007) Log Message: ----------- Render all the fonts in each mathtext expression to a single image buffer (memory and time savings). Add support for getting raw image data for mathtext expressions. Add mathtext_wx.py example showing how to put mathtext expressions into controls. Modified Paths: -------------- trunk/matplotlib/lib/matplotlib/backends/backend_agg.py trunk/matplotlib/lib/matplotlib/backends/backend_gdk.py trunk/matplotlib/lib/matplotlib/mathtext.py trunk/matplotlib/src/_backend_agg.cpp trunk/matplotlib/src/_backend_agg.h trunk/matplotlib/src/ft2font.cpp trunk/matplotlib/src/ft2font.h trunk/matplotlib/unit/agg_memleak.py Modified: trunk/matplotlib/lib/matplotlib/backends/backend_agg.py =================================================================== --- trunk/matplotlib/lib/matplotlib/backends/backend_agg.py 2007-08-31 17:23:32 UTC (rev 3763) +++ trunk/matplotlib/lib/matplotlib/backends/backend_agg.py 2007-08-31 19:25:17 UTC (rev 3764) @@ -172,7 +172,7 @@ """ if __debug__: verbose.report('RendererAgg.draw_mathtext', 'debug-annoying') - ox, oy, width, height, descent, fonts, used_characters = \ + ox, oy, width, height, descent, font_image, used_characters = \ self.mathtext_parser.parse(s, self.dpi.get(), prop) if angle == 90: @@ -180,13 +180,11 @@ ox, oy = oy, ox x = int(x) - width + ox y = int(y) - height + oy + font_image.rotate() else: x = int(x) + ox y = int(y) - height + oy - for font in fonts: - if angle == 90: - font.horiz_image_to_vert_image() # <-- Rotate - self._renderer.draw_text( font, x, y + 1, gc) + self._renderer.draw_text_image(font_image, x, y + 1, gc) if 0: self._renderer.draw_rectangle(gc, None, int(x), @@ -212,7 +210,7 @@ #print x, y, int(x), int(y) - self._renderer.draw_text(font, int(x), int(y) + 1, gc) + self._renderer.draw_text_image(font.get_image(), int(x), int(y) + 1, gc) def get_text_width_height_descent(self, s, prop, ismath, rgb=(0,0,0)): Modified: trunk/matplotlib/lib/matplotlib/backends/backend_gdk.py =================================================================== --- trunk/matplotlib/lib/matplotlib/backends/backend_gdk.py 2007-08-31 17:23:32 UTC (rev 3763) +++ trunk/matplotlib/lib/matplotlib/backends/backend_gdk.py 2007-08-31 19:25:17 UTC (rev 3764) @@ -215,7 +215,7 @@ for i, font in enumerate(fonts): if angle == 90: - font.horiz_image_to_vert_image() # <-- Rotate + font.get_image().rotate() # <-- Rotate imw, imh, image_str = font.image_as_str() Xall[:,i] = npy.fromstring(image_str, npy.uint8) Modified: trunk/matplotlib/lib/matplotlib/mathtext.py =================================================================== --- trunk/matplotlib/lib/matplotlib/mathtext.py 2007-08-31 17:23:32 UTC (rev 3763) +++ trunk/matplotlib/lib/matplotlib/mathtext.py 2007-08-31 19:25:17 UTC (rev 3764) @@ -143,7 +143,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_DEFAULT, LOAD_DEFAULT, LOAD_NO_HINTING +from matplotlib.ft2font import FT2Font, FT2Image, KERNING_DEFAULT, LOAD_DEFAULT, LOAD_NO_HINTING from matplotlib.font_manager import findfont, FontProperties from matplotlib._mathtext_data import latex_to_bakoma, \ latex_to_standard, tex2uni, type12uni, tex2type1, uni2type1 @@ -288,20 +288,19 @@ def __init__(self): self.ox = 0 self.oy = 0 + self.image = None MathtextBackend.__init__(self) def set_canvas_size(self, w, h, d): MathtextBackend.set_canvas_size(self, w, h, d) - for font in self.fonts_object.get_fonts(): - font.set_bitmap_size(int(w), int(h) + int(d)) + self.image = FT2Image(ceil(w), ceil(h + d)) def render_glyph(self, ox, oy, info): info.font.draw_glyph_to_bitmap( - ox, oy - info.metrics.ymax, info.glyph) + self.image, ox, oy - info.metrics.ymax, info.glyph) def render_rect_filled(self, x1, y1, x2, y2): - font = self.fonts_object.get_fonts()[0] - font.draw_rect_filled(x1, y1, x2, max(y2 - 1, y1)) + self.image.draw_rect_filled(x1, y1, x2, max(y2 - 1, y1)) def get_results(self, box): return (self.ox, @@ -309,7 +308,7 @@ self.width, self.height + self.depth, self.depth, - self.fonts_object.get_fonts(), + self.image, self.fonts_object.get_used_characters()) def get_hinting_type(self): @@ -318,6 +317,13 @@ def MathtextBackendAgg(): return MathtextBackendBbox(MathtextBackendAggRender()) +class MathtextBackendBitmapRender(MathtextBackendAggRender): + def get_results(self, box): + return self.image + +def MathtextBackendBitmap(): + return MathtextBackendBbox(MathtextBackendBitmapRender()) + class MathtextBackendPs(MathtextBackend): def __init__(self): self.pswriter = StringIO() @@ -2443,6 +2449,7 @@ _parser = None _backend_mapping = { + 'Bitmap': MathtextBackendBitmap, 'Agg' : MathtextBackendAgg, 'PS' : MathtextBackendPs, 'Pdf' : MathtextBackendPdf, @@ -2454,7 +2461,10 @@ self._output = output self._cache = {} - def parse(self, s, dpi, prop): + def parse(self, s, dpi = 72, prop = None): + if prop is None: + prop = FontProperties() + cacheKey = (s, dpi, hash(prop)) result = self._cache.get(cacheKey) if result is not None: Modified: trunk/matplotlib/src/_backend_agg.cpp =================================================================== --- trunk/matplotlib/src/_backend_agg.cpp 2007-08-31 17:23:32 UTC (rev 3763) +++ trunk/matplotlib/src/_backend_agg.cpp 2007-08-31 19:25:17 UTC (rev 3764) @@ -2106,14 +2106,15 @@ Py::Object -RendererAgg::draw_text(const Py::Tuple& args) { +RendererAgg::draw_text_image(const Py::Tuple& args) { _VERBOSE("RendererAgg::draw_text"); args.verify_length(4); + FT2Image *image = static_cast<FT2Image*>(args[0].ptr()); + if (!image->get_buffer()) + return Py::Object(); - FT2Font *font = static_cast<FT2Font*>(args[0].ptr()); - int x(0),y(0); try { x = Py::Int( args[1] ); @@ -2151,15 +2152,16 @@ t = b+h; } + const unsigned char* const buffer = image->get_buffer(); - for (size_t i=0; i<font->image.width; i++) { - for (size_t j=0; j<font->image.height; j++) { - thisx = i+x+font->image.offsetx; - thisy = j+y+font->image.offsety; + for (size_t i=0; i< image->get_width(); i++) { + for (size_t j=0; j< image->get_height(); j++) { + thisx = i+x+image->offsetx; + thisy = j+y+image->offsety; if (thisx<l || thisx>=r) continue; if (thisy<height-t || thisy>=height-b) continue; pixFmt->blend_pixel - (thisx, thisy, p, font->image.buffer[i + j*font->image.width]); + (thisx, thisy, p, buffer[i + j*image->get_width()]); } } @@ -2568,8 +2570,8 @@ "draw_markers(gc, path, x, y)\n"); add_varargs_method("draw_path", &RendererAgg::draw_path, "draw_path(gc, rgbFace, path, transform)\n"); - add_varargs_method("draw_text", &RendererAgg::draw_text, - "draw_text(font, x, y, r, g, b, a)\n"); + add_varargs_method("draw_text_image", &RendererAgg::draw_text_image, + "draw_text_image(font_image, x, y, r, g, b, a)\n"); add_varargs_method("draw_image", &RendererAgg::draw_image, "draw_image(x, y, im)"); add_varargs_method("write_rgba", &RendererAgg::write_rgba, Modified: trunk/matplotlib/src/_backend_agg.h =================================================================== --- trunk/matplotlib/src/_backend_agg.h 2007-08-31 17:23:32 UTC (rev 3763) +++ trunk/matplotlib/src/_backend_agg.h 2007-08-31 19:25:17 UTC (rev 3764) @@ -166,7 +166,7 @@ //Py::Object _draw_markers_nocache(const Py::Tuple & args); //Py::Object _draw_markers_cache(const Py::Tuple & args); Py::Object draw_markers(const Py::Tuple & args); - Py::Object draw_text(const Py::Tuple & args); + Py::Object draw_text_image(const Py::Tuple & args); Py::Object draw_image(const Py::Tuple & args); Py::Object write_rgba(const Py::Tuple & args); Modified: trunk/matplotlib/src/ft2font.cpp =================================================================== --- trunk/matplotlib/src/ft2font.cpp 2007-08-31 17:23:32 UTC (rev 3763) +++ trunk/matplotlib/src/ft2font.cpp 2007-08-31 19:25:17 UTC (rev 3764) @@ -42,9 +42,414 @@ FT_Library _ft2Library; -FT2Image::FT2Image() : bRotated(false), buffer(NULL) {} -FT2Image::~FT2Image() {delete [] buffer; buffer=NULL;} +FT2Image::FT2Image() : + offsetx(0), offsety(0), + _bRotated(false), + _isDirty(true), + _buffer(NULL), + _width(0), _height(0), + _rgbCopy(NULL), + _rgbaCopy(NULL) { + _VERBOSE("FT2Image::FT2Image"); +} +FT2Image::FT2Image(unsigned long width, unsigned long height) : + offsetx(0), offsety(0), + _bRotated(false), + _isDirty(true), + _buffer(NULL), + _width(0), _height(0), + _rgbCopy(NULL), + _rgbaCopy(NULL) { + _VERBOSE("FT2Image::FT2Image"); + resize(width, height); +} + +FT2Image::~FT2Image() { + _VERBOSE("FT2Image::~FT2Image"); + delete [] _buffer; + _buffer=NULL; +} + +void FT2Image::resize(unsigned long width, unsigned long height) { + size_t numBytes = width*height; + + if (_width != width || _height != height) { + _width = width; + _height = height; + + delete [] _buffer; + _buffer = new unsigned char [numBytes]; + } + + for (size_t n=0; n<numBytes; n++) + _buffer[n] = 0; + + _bRotated = false; + _isDirty = true; +} + +char FT2Image::resize__doc__[] = +"resize(width, height)\n" +"\n" +"Resize the dimensions of the image (it is cleared in the process).\n" +; +Py::Object +FT2Image::py_resize(const Py::Tuple & args) { + _VERBOSE("FT2Image::resize"); + + args.verify_length(2); + + long x0 = Py::Int(args[0]); + long y0 = Py::Int(args[1]); + + resize(x0, y0); + + return Py::Object(); +} + +void FT2Image::clear() { + _VERBOSE("FT2Image::clear"); + + _width = 0; + _height = 0; + offsetx = 0; + offsety = 0; + _isDirty = true; + _bRotated = false; + delete [] _buffer; + _buffer = NULL; + if (_rgbCopy) { + delete _rgbCopy; + _rgbCopy = NULL; + } + if (_rgbaCopy) { + delete _rgbaCopy; + _rgbaCopy = NULL; + } +} +char FT2Image::clear__doc__[] = +"clear()\n" +"\n" +"Clear the contents of the image.\n" +; +Py::Object +FT2Image::py_clear(const Py::Tuple & args) { + args.verify_length(0); + + clear(); + + return Py::Object(); +} + +void FT2Image::rotate() { + // If we have already rotated, just return. + if (_bRotated) + return; + + unsigned long width = _width; + unsigned long height = _height; + + unsigned long newWidth = _height; + unsigned long newHeight = _width; + + unsigned long numBytes = _width * _height; + + unsigned char * buffer = new unsigned char [numBytes]; + + unsigned long i, j, k, offset, nhMinusOne; + + nhMinusOne = newHeight - 1; + + unsigned char * read_it = _buffer; + + for (i=0; i<height; i++) { + offset = i*width; + for (j=0; j<width; j++) { + k = nhMinusOne - j; + buffer[i + k*newWidth] = *(read_it++); + } + } + + delete [] _buffer; + _buffer = buffer; + _width = newWidth; + _height = newHeight; + _bRotated = true; + _isDirty = true; +} +char FT2Image::rotate__doc__[] = +"rotate()\n" +"\n" +"Rotates the image 90 degrees.\n" +; +Py::Object +FT2Image::py_rotate(const Py::Tuple & args) { + _VERBOSE("FT2Image::rotate"); + + args.verify_length(0); + + rotate(); + + return Py::Object(); +} + +void +FT2Image::draw_bitmap( FT_Bitmap* bitmap, + FT_Int x, + FT_Int y) { + _VERBOSE("FT2Image::draw_bitmap"); + FT_Int image_width = (FT_Int)_width; + FT_Int image_height = (FT_Int)_height; + FT_Int char_width = bitmap->width; + FT_Int char_height = bitmap->rows; + + 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); + + 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 = _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; + } + + _isDirty = true; +} + +void FT2Image::write_bitmap(const char* filename) const { + FILE *fh = fopen(filename, "w"); + + for ( size_t i = 0; i< _height; i++) { + for ( size_t j = 0; j < _width; ++j) { + if (_buffer[j + i*_width]) + fputc('#', fh); + else + fputc(' ', fh); + } + fputc('\n', fh); + } + + fclose(fh); +} + +char FT2Image::write_bitmap__doc__[] = +"write_bitmap(fname)\n" +"\n" +"Write the bitmap to file fname\n" +; +Py::Object +FT2Image::py_write_bitmap(const Py::Tuple & args) { + _VERBOSE("FT2Image::write_bitmap"); + + args.verify_length(1); + + std::string filename = Py::String(args[0]); + + write_bitmap(filename.c_str()); + + return Py::Object(); +} + +void +FT2Image::draw_rect(unsigned long x0, unsigned long y0, + unsigned long x1, unsigned long y1) { + if ( x0<0 || y0<0 || x1<0 || y1<0 || + x0>_width || x1>_width || + y0>_height || y1>_height ) + throw Py::ValueError("Rect coords outside image bounds"); + + size_t top = y0*_width; + size_t bottom = y1*_width; + for (size_t i=x0; i<x1+1; ++i) { + _buffer[i + top] = 255; + _buffer[i + bottom] = 255; + } + + for (size_t j=y0+1; j<y1; ++j) { + _buffer[x0 + j*_width] = 255; + _buffer[x1 + j*_width] = 255; + } + + _isDirty = true; +} + +char FT2Image::draw_rect__doc__[] = +"draw_rect(x0, y0, x1, y1)\n" +"\n" +"Draw a rect to the image.\n" +"\n" +; +Py::Object +FT2Image::py_draw_rect(const Py::Tuple & args) { + _VERBOSE("FT2Image::draw_rect"); + + args.verify_length(4); + + long x0 = Py::Int(args[0]); + long y0 = Py::Int(args[1]); + long x1 = Py::Int(args[2]); + long y1 = Py::Int(args[3]); + + draw_rect(x0, y0, x1, y1); + + return Py::Object(); +} + +void FT2Image::draw_rect_filled(unsigned long x0, unsigned long y0, + unsigned long x1, unsigned long y1) { + x0 = CLAMP(x0, 0, _width); + y0 = CLAMP(y0, 0, _height); + x1 = CLAMP(x1, 0, _width); + y1 = CLAMP(y1, 0, _height); + + for (size_t j=y0; j<y1+1; j++) { + for (size_t i=x0; i<x1+1; i++) { + _buffer[i + j*_width] = 255; + } + } + + _isDirty = true; +} + +char FT2Image::draw_rect_filled__doc__[] = +"draw_rect_filled(x0, y0, x1, y1)\n" +"\n" +"Draw a filled rect to the image.\n" +"\n" +; +Py::Object +FT2Image::py_draw_rect_filled(const Py::Tuple & args) { + _VERBOSE("FT2Image::draw_rect_filled"); + + args.verify_length(4); + + long x0 = Py::Int(args[0]); + long y0 = Py::Int(args[1]); + long x1 = Py::Int(args[2]); + long y1 = Py::Int(args[3]); + + draw_rect_filled(x0, y0, x1, y1); + + return Py::Object(); +} + +char FT2Image::as_str__doc__[] = +"width, height, s = image_as_str()\n" +"\n" +"Return the image buffer as a string\n" +"\n" +; +Py::Object +FT2Image::py_as_str(const Py::Tuple & args) { + _VERBOSE("FT2Image::as_str"); + args.verify_length(0); + + return Py::asObject(PyString_FromStringAndSize((const char *)_buffer, _width*_height)); +} + +void FT2Image::makeRgbCopy() { + if (!_isDirty) + return; + + if (!_rgbCopy) { + _rgbCopy = new FT2Image(_width * 3, _height); + } else { + _rgbCopy->resize(_width * 3, _height); + } + unsigned char *src = _buffer; + unsigned char *src_end = src + (_width * _height); + unsigned char *dst = _rgbCopy->_buffer; + + unsigned char tmp; + while (src != src_end) { + tmp = 255 - *src++; + *dst++ = tmp; + *dst++ = tmp; + *dst++ = tmp; + } +} + +char FT2Image::as_rgb_str__doc__[] = +"width, height, s = image_as_rgb_str()\n" +"\n" +"Return the image buffer as a 24-bit RGB string.\n" +"\n" +; +Py::Object +FT2Image::py_as_rgb_str(const Py::Tuple & args) { + _VERBOSE("FT2Image::as_str_rgb"); + args.verify_length(0); + + makeRgbCopy(); + + return _rgbCopy->py_as_str(args); +} + +void FT2Image::makeRgbaCopy() { + if (!_isDirty) + return; + + if (!_rgbaCopy) { + _rgbaCopy = new FT2Image(_width * 4, _height); + } else { + _rgbaCopy->resize(_width * 4, _height); + } + unsigned char *src = _buffer; + unsigned char *src_end = src + (_width * _height); + unsigned char *dst = _rgbaCopy->_buffer; + + // This pre-multiplies the alpha, which apparently shouldn't + // be necessary for wxGTK, but it sure as heck seems to be. + unsigned int c; + unsigned int tmp; + while (src != src_end) { + c = *src++; + tmp = ((255 - c) * c) >> 8; + *dst++ = tmp; + *dst++ = tmp; + *dst++ = tmp; + *dst++ = c; + } +} + +char FT2Image::as_rgba_str__doc__[] = +"width, height, s = image_as_rgb_str()\n" +"\n" +"Return the image buffer as a 32-bit RGBA string.\n" +"\n" +; +Py::Object +FT2Image::py_as_rgba_str(const Py::Tuple & args) { + _VERBOSE("FT2Image::as_str_rgba"); + args.verify_length(0); + + makeRgbaCopy(); + + return _rgbaCopy->py_as_str(args); +} + +Py::Object +FT2Image::py_get_width(const Py::Tuple & args) { + _VERBOSE("FT2Image::get_width"); + args.verify_length(0); + + return Py::Int((long)get_width()); +} + +Py::Object +FT2Image::py_get_height(const Py::Tuple & args) { + _VERBOSE("FT2Image::get_height"); + args.verify_length(0); + + return Py::Int((long)get_height()); +} + Glyph::Glyph( const FT_Face& face, const FT_Glyph& glyph, size_t ind) : glyphInd(ind) { _VERBOSE("Glyph::Glyph"); @@ -105,7 +510,6 @@ //get the glyph as a path, a list of (COMMAND, *args) as desribed in matplotlib.path // this code is from agg's decompose_ft_outline with minor modifications - enum {MOVETO, LINETO, CURVE3, CURVE4, ENDPOLY}; FT_Outline& outline = face->glyph->outline; Py::List path; @@ -345,12 +749,12 @@ } -FT2Font::FT2Font(std::string facefile) +FT2Font::FT2Font(std::string facefile) : + image(NULL) { _VERBOSE(Printf("FT2Font::FT2Font %s", facefile.c_str()).str()); clear(Py::Tuple(0)); - int error = FT_New_Face( _ft2Library, facefile.c_str(), 0, &face ); @@ -447,75 +851,20 @@ FT2Font::~FT2Font() { _VERBOSE("FT2Font::~FT2Font"); + + if(image) + Py::_XDECREF(image); FT_Done_Face ( face ); - delete [] image.buffer ; - image.buffer = NULL; - for (size_t i=0; i<glyphs.size(); i++) { FT_Done_Glyph( glyphs[i] ); } + for (size_t i=0; i<gms.size(); i++) { Py_DECREF(gms[i]); } } - -char FT2Font::horiz_image_to_vert_image__doc__[] = -"horiz_image_to_vert_image()\n" -"\n" -"Copies the horizontal image (w, h) into a\n" -"new image of size (h,w)\n" -"This is equivalent to rotating the original image\n" -"by 90 degrees ccw\n" -; - -Py::Object -FT2Font::horiz_image_to_vert_image(const Py::Tuple & args) { - - // If we have already rotated, just return. - - if (image.bRotated) - return Py::Object(); - - - long width = image.width, height = image.height; - - long newWidth = image.height; - long newHeight = image.width; - - long numBytes = image.width * image.height; - - unsigned char * buffer = new unsigned char [numBytes]; - - long i, j, k, offset, nhMinusOne; - - nhMinusOne = newHeight-1; - - for (i=0; i<height; i++) { - - offset = i*width; - - for (j=0; j<width; j++) { - - k = nhMinusOne - j; - - buffer[i + k*newWidth] = image.buffer[j + offset]; - - } - - } - - delete [] image.buffer; - image.buffer = buffer; - image.width = newWidth; - image.height = newHeight; - image.bRotated = true; - - return Py::Object(); - -} - int FT2Font::setattr( const char *name, const Py::Object &value ) { _VERBOSE("FT2Font::setattr"); @@ -530,34 +879,6 @@ else return getattr_default( name ); } -char FT2Font::set_bitmap_size__doc__[] = -"set_bitmap_size(w, h)\n" -"\n" -"Manually set the bitmap size to render the glyps to. This is useful" -"in cases where you want to render several different glyphs to the bitmap" -; - -Py::Object -FT2Font::set_bitmap_size(const Py::Tuple & args) { - _VERBOSE("FT2Font::set_bitmap_size"); - args.verify_length(2); - - long width = Py::Int(args[0]); - long height = Py::Int(args[1]); - - image.width = (unsigned)width; - image.height = (unsigned)height; - - long numBytes = image.width * image.height; - - delete [] image.buffer; - image.buffer = new unsigned char [numBytes]; - for (long n=0; n<numBytes; n++) - image.buffer[n] = 0; - - return Py::Object(); -} - char FT2Font::clear__doc__[] = "clear()\n" "\n" @@ -569,13 +890,8 @@ _VERBOSE("FT2Font::clear"); args.verify_length(0); - //todo: move to image method? - delete [] image.buffer ; - image.buffer = NULL; - image.width = 0; - image.height = 0; - image.offsetx = 0; - image.offsety = 0; + if (image) + image->clear(); angle = 0.0; @@ -904,8 +1220,6 @@ _VERBOSE("FT2Font::get_width_height"); args.verify_length(0); - - FT_BBox bbox = compute_string_bbox(); Py::Tuple ret(2); @@ -930,152 +1244,6 @@ return Py::Int(- bbox.yMin);; } -void -FT2Font::draw_bitmap( FT_Bitmap* bitmap, - FT_Int x, - FT_Int y) { - _VERBOSE("FT2Font::draw_bitmap"); - 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, 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); - - 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__[] = -"write_bitmap(fname)\n" -"\n" -"Write the bitmap to file fname\n" -; -Py::Object -FT2Font::write_bitmap(const Py::Tuple & args) { - _VERBOSE("FT2Font::write_bitmap"); - - args.verify_length(1); - - FT_Int i, j; - - std::string filename = Py::String(args[0]); - - FILE *fh = fopen(filename.c_str(), "w"); - FT_Int width = (FT_Int)image.width; - FT_Int height = (FT_Int)image.height; - - for ( i = 0; i< height; i++) - for ( j = 0; j < width; ++j) - fputc(image.buffer[j + i*width], fh); - - fclose(fh); - - return Py::Object(); -} - -char FT2Font::draw_rect__doc__[] = -"draw_rect(x0, y0, x1, y1)\n" -"\n" -"Draw a rect to the image. It is your responsibility to set the dimensions\n" -"of the image, eg, with set_bitmap_size\n" -"\n" -; -Py::Object -FT2Font::draw_rect(const Py::Tuple & args) { - _VERBOSE("FT2Font::draw_rect"); - - args.verify_length(4); - - long x0 = Py::Int(args[0]); - long y0 = Py::Int(args[1]); - long x1 = Py::Int(args[2]); - long y1 = Py::Int(args[3]); - - FT_Int iwidth = (FT_Int)image.width; - FT_Int iheight = (FT_Int)image.height; - - if ( x0<0 || y0<0 || x1<0 || y1<0 || - x0>iwidth || x1>iwidth || - y0>iheight || y1>iheight ) - throw Py::ValueError("Rect coords outside image bounds"); - - for (long i=x0; i<x1+1; ++i) { - image.buffer[i + y0*iwidth] = 255; - image.buffer[i + y1*iwidth] = 255; - } - - for (long j=y0+1; j<y1; ++j) { - image.buffer[x0 + j*iwidth] = 255; - image.buffer[x1 + j*iwidth] = 255; - } - return Py::Object(); -} - -char FT2Font::draw_rect_filled__doc__[] = -"draw_rect_filled(x0, y0, x1, y1)\n" -"\n" -"Draw a filled rect to the image. It is your responsibility to set the\n" -"dimensions of the image, eg, with set_bitmap_size\n" -"\n" -; -Py::Object -FT2Font::draw_rect_filled(const Py::Tuple & args) { - _VERBOSE("FT2Font::draw_rect_filled"); - - args.verify_length(4); - - long x0 = Py::Int(args[0]); - long y0 = Py::Int(args[1]); - long x1 = Py::Int(args[2]); - long y1 = Py::Int(args[3]); - - FT_Int iwidth = (FT_Int)image.width; - FT_Int iheight = (FT_Int)image.height; - - x0 = CLAMP(x0, 0, iwidth); - y0 = CLAMP(y0, 0, iheight); - x1 = CLAMP(x1, 0, iwidth); - y1 = CLAMP(y1, 0, iheight); - - for (long j=y0; j<y1+1; j++) { - for (long i=x0; i<x1+1; i++) { - image.buffer[i + j*iwidth] = 255; - } - } - return Py::Object(); -} - -char FT2Font::image_as_str__doc__[] = -"width, height, s = image_as_str()\n" -"\n" -"Return the image buffer as a string\n" -"\n" -; -Py::Object -FT2Font::image_as_str(const Py::Tuple & args) { - _VERBOSE("FT2Font::image_as_str"); - args.verify_length(0); - - return Py::asObject( - Py_BuildValue("lls#", - image.width, - image.height, - image.buffer, - image.width*image.height) - ); -} - char FT2Font::draw_glyphs_to_bitmap__doc__[] = "draw_glyphs_to_bitmap()\n" "\n" @@ -1089,22 +1257,21 @@ args.verify_length(0); FT_BBox string_bbox = compute_string_bbox(); + size_t width = (string_bbox.xMax-string_bbox.xMin) / 64 + 2; + size_t 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; + if (!image) { + image = new FT2Image(width, height); + } else { + image->resize(width, height); + } - image.offsetx = (int)(string_bbox.xMin / 64.0); + image->offsetx = (int)(string_bbox.xMin / 64.0); if (angle==0) - image.offsety = -image.height; + image->offsety = -image->get_height(); else - image.offsety = (int)(-string_bbox.yMax/64.0); + image->offsety = (int)(-string_bbox.yMax/64.0); - size_t numBytes = image.width*image.height; - delete [] image.buffer; - image.buffer = new unsigned char [numBytes]; - for (size_t n=0; n<numBytes; n++) - image.buffer[n] = 0; - for ( size_t n = 0; n < glyphs.size(); n++ ) { FT_BBox bbox; @@ -1113,8 +1280,7 @@ error = FT_Glyph_To_Bitmap(&glyphs[n], ft_render_mode_normal, 0, - //&pos[n], - 1 //destroy image; + 1 ); if (error) throw Py::RuntimeError("Could not convert glyph to bitmap"); @@ -1126,7 +1292,7 @@ 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); + image->draw_bitmap( &bitmap->bitmap, x, y); } return Py::Object(); @@ -1156,8 +1322,7 @@ error = FT_Glyph_To_Bitmap(&glyphs[n], ft_render_mode_normal, 0, - //&pos[n], - 1 //destroy image; + 1 ); if (error) throw Py::RuntimeError("Could not convert glyph to bitmap"); @@ -1181,7 +1346,7 @@ } char FT2Font::draw_glyph_to_bitmap__doc__[] = -"draw_glyph_to_bitmap(x, y, glyph)\n" +"draw_glyph_to_bitmap(bitmap, x, y, glyph)\n" "\n" "Draw a single glyph to the bitmap at pixel locations x,y\n" "Note it is your responsibility to set up the bitmap manually\n" @@ -1195,16 +1360,17 @@ Py::Object FT2Font::draw_glyph_to_bitmap(const Py::Tuple & args) { _VERBOSE("FT2Font::draw_glyph_to_bitmap"); - args.verify_length(3); + args.verify_length(4); - if (image.width==0 || image.height==0) - throw Py::RuntimeError("You must first set the size of the bitmap with set_bitmap_size"); + if (!FT2Image::check(args[0].ptr())) + throw Py::TypeError("Usage: draw_glyph_to_bitmap(bitmap, x,y,glyph)"); + FT2Image* im = static_cast<FT2Image*>(args[0].ptr()); - long x = Py::Int(args[0]); - long y = Py::Int(args[1]); - if (!Glyph::check(args[2].ptr())) - throw Py::TypeError("Usage: draw_glyph_to_bitmap(x,y,glyph)"); - Glyph* glyph = static_cast<Glyph*>(args[2].ptr()); + long x = Py::Int(args[1]); + long y = Py::Int(args[2]); + if (!Glyph::check(args[3].ptr())) + throw Py::TypeError("Usage: draw_glyph_to_bitmap(bitmap, x,y,glyph)"); + Glyph* glyph = static_cast<Glyph*>(args[3].ptr()); if ((size_t)glyph->glyphInd >= glyphs.size()) throw Py::ValueError("glyph num is out of range"); @@ -1219,7 +1385,7 @@ FT_BitmapGlyph bitmap = (FT_BitmapGlyph)glyphs[glyph->glyphInd]; - draw_bitmap( &bitmap->bitmap, x + bitmap->left, y); + im->draw_bitmap( &bitmap->bitmap, x + bitmap->left, y); return Py::Object(); } @@ -1611,7 +1777,28 @@ } } +char FT2Font::get_image__doc__ [] = + "get_image()\n" + "\n" + "Returns the underlying image buffer for this font object.\n"; Py::Object +FT2Font::get_image (const Py::Tuple &args) { + args.verify_length(0); + Py_INCREF(image); + return Py::asObject(image); +} + +Py::Object +ft2font_module::new_ft2image (const Py::Tuple &args) { + args.verify_length(2); + + int width = Py::Int(args[0]); + int height = Py::Int(args[1]); + + return Py::asObject( new FT2Image(width, height) ); +} + +Py::Object ft2font_module::new_ft2font (const Py::Tuple &args) { _VERBOSE("ft2font_module::new_ft2font "); args.verify_length(1); @@ -1621,6 +1808,36 @@ } void +FT2Image::init_type() { + _VERBOSE("FT2Image::init_type"); + behaviors().name("FT2Image"); + behaviors().doc("FT2Image"); + + add_varargs_method("clear", &FT2Image::py_clear, + FT2Image::clear__doc__); + add_varargs_method("resize", &FT2Image::py_resize, + FT2Image::resize__doc__); + add_varargs_method("rotate", &FT2Image::py_rotate, + FT2Image::rotate__doc__); + add_varargs_method("write_bitmap", &FT2Image::py_write_bitmap, + FT2Image::write_bitmap__doc__); + add_varargs_method("draw_rect", &FT2Image::py_draw_rect, + FT2Image::draw_rect__doc__); + add_varargs_method("draw_rect_filled", &FT2Image::py_draw_rect_filled, + FT2Image::draw_rect_filled__doc__); + add_varargs_method("as_str", &FT2Image::py_as_str, + FT2Image::as_str__doc__); + add_varargs_method("as_rgb_str", &FT2Image::py_as_rgb_str, + FT2Image::as_rgb_str__doc__); + add_varargs_method("as_rgba_str", &FT2Image::py_as_rgba_str, + FT2Image::as_rgba_str__doc__); + add_varargs_method("get_width", &FT2Image::py_get_width, + "Returns the width of the image"); + add_varargs_method("get_height", &FT2Image::py_get_height, + "Returns the height of the image"); +} + +void Glyph::init_type() { _VERBOSE("Glyph::init_type"); behaviors().name("Glyph"); @@ -1637,14 +1854,6 @@ add_varargs_method("clear", &FT2Font::clear, FT2Font::clear__doc__); - add_varargs_method("write_bitmap", &FT2Font::write_bitmap, - FT2Font::write_bitmap__doc__); - add_varargs_method("set_bitmap_size", &FT2Font::set_bitmap_size, - 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, - FT2Font::draw_rect_filled__doc__); add_varargs_method("draw_glyph_to_bitmap", &FT2Font::draw_glyph_to_bitmap, FT2Font::draw_glyph_to_bitmap__doc__); add_varargs_method("draw_glyphs_to_bitmap", &FT2Font::draw_glyphs_to_bitmap, @@ -1656,8 +1865,6 @@ FT2Font::get_glyph__doc__); add_varargs_method("get_num_glyphs", &FT2Font::get_num_glyphs, FT2Font::get_num_glyphs__doc__); - add_varargs_method("image_as_str", &FT2Font::image_as_str, - FT2Font::image_as_str__doc__); add_keyword_method("load_char", &FT2Font::load_char, FT2Font::load_char__doc__); add_keyword_method("set_text", &FT2Font::set_text, @@ -1685,9 +1892,8 @@ FT2Font::get_ps_font_info__doc__); add_varargs_method("get_sfnt_table", &FT2Font::get_sfnt_table, FT2Font::get_sfnt_table__doc__); - add_varargs_method("horiz_image_to_vert_image", - &FT2Font::horiz_image_to_vert_image, - FT2Font::horiz_image_to_vert_image__doc__); + add_varargs_method("get_image", &FT2Font::get_image, + FT2Font::get_image__doc__); behaviors().supportGetattr(); behaviors().supportSetattr(); Modified: trunk/matplotlib/src/ft2font.h =================================================================== --- trunk/matplotlib/src/ft2font.h 2007-08-31 17:23:32 UTC (rev 3763) +++ trunk/matplotlib/src/ft2font.h 2007-08-31 19:25:17 UTC (rev 3764) @@ -20,15 +20,64 @@ // the freetype string rendered into a width, height buffer -class FT2Image { +class FT2Image : public Py::PythonExtension<FT2Image> { public: FT2Image(); + FT2Image(unsigned long width, unsigned long height); ~FT2Image(); - bool bRotated; - unsigned char *buffer; - unsigned long width; - unsigned long height; - int offsetx, offsety; + + static void init_type(); + + void resize(unsigned long width, unsigned long height); + void clear(); + void rotate(); + void draw_bitmap(FT_Bitmap* bitmap, FT_Int x, FT_Int y); + void write_bitmap(const char* filename) const; + void draw_rect(unsigned long x0, unsigned long y0, + unsigned long x1, unsigned long y1); + void draw_rect_filled(unsigned long x0, unsigned long y0, + unsigned long x1, unsigned long y1); + + unsigned int get_width() const { return _width; }; + unsigned int get_height() const { return _height; }; + const unsigned char *const get_buffer() const { return _buffer; }; + + static char clear__doc__ []; + Py::Object py_clear(const Py::Tuple & args); + static char resize__doc__ []; + Py::Object py_resize(const Py::Tuple & args); + static char rotate__doc__ []; + Py::Object py_rotate(const Py::Tuple & args); + static char write_bitmap__doc__ []; + Py::Object py_write_bitmap(const Py::Tuple & args); + static char draw_rect__doc__ []; + Py::Object py_draw_rect(const Py::Tuple & args); + static char draw_rect_filled__doc__ []; + Py::Object py_draw_rect_filled(const Py::Tuple & args); + static char as_str__doc__ []; + Py::Object py_as_str(const Py::Tuple & args); + static char as_rgb_str__doc__ []; + Py::Object py_as_rgb_str(const Py::Tuple & args); + static char as_rgba_str__doc__ []; + Py::Object py_as_rgba_str(const Py::Tuple & args); + + Py::Object py_get_width(const Py::Tuple & args); + Py::Object py_get_height(const Py::Tuple & args); + + unsigned long offsetx; + unsigned long offsety; + + private: + bool _bRotated; + bool _isDirty; + unsigned char *_buffer; + unsigned long _width; + unsigned long _height; + FT2Image* _rgbCopy; + FT2Image* _rgbaCopy; + + void makeRgbCopy(); + void makeRgbaCopy(); }; @@ -52,7 +101,6 @@ FT2Font(std::string); ~FT2Font(); static void init_type(void); - Py::Object set_bitmap_size(const Py::Tuple & args); Py::Object clear(const Py::Tuple & args); Py::Object set_size(const Py::Tuple & args); Py::Object set_charmap(const Py::Tuple & args); @@ -63,10 +111,7 @@ Py::Object load_char(const Py::Tuple & args, const Py::Dict & kws); Py::Object get_width_height(const Py::Tuple & args); Py::Object get_descent(const Py::Tuple & args); - Py::Object write_bitmap(const Py::Tuple & args); - Py::Object draw_rect(const Py::Tuple & args); Py::Object draw_rect_filled(const Py::Tuple & args); - Py::Object image_as_str(const Py::Tuple & args); Py::Object get_xys(const Py::Tuple & args); Py::Object draw_glyphs_to_bitmap(const Py::Tuple & args); Py::Object draw_glyph_to_bitmap(const Py::Tuple & args); @@ -76,10 +121,10 @@ Py::Object get_name_index(const Py::Tuple & args); Py::Object get_ps_font_info(const Py::Tuple & args); Py::Object get_sfnt_table(const Py::Tuple & args); - Py::Object horiz_image_to_vert_image(const Py::Tuple & args); + Py::Object get_image(const Py::Tuple & args); int setattr( const char *_name, const Py::Object &value ); Py::Object getattr( const char *_name ); - FT2Image image; + FT2Image* image; private: Py::Dict __dict__; @@ -96,10 +141,8 @@ FT_BBox compute_string_bbox(); - void draw_bitmap( FT_Bitmap* bitmap, FT_Int x, FT_Int y); void set_scalable_attributes(); - static char set_bitmap_size__doc__ []; static char clear__doc__ []; static char set_size__doc__ []; static char set_charmap__doc__ []; @@ -110,10 +153,6 @@ static char get_width_height__doc__ []; static char get_descent__doc__ []; static char get_kerning__doc__ []; - static char write_bitmap__doc__ []; - static char draw_rect__doc__ []; - static char draw_rect_filled__doc__ []; - static char image_as_str__doc__ []; static char draw_glyphs_to_bitmap__doc__ []; static char get_xys__doc__ []; static char draw_glyph_to_bitmap__doc__ []; @@ -123,7 +162,7 @@ static char get_name_index__doc__[]; static char get_ps_font_info__doc__[]; static char get_sfnt_table__doc__[]; - static char horiz_image_to_vert_image__doc__[]; + static char get_image__doc__[]; }; // the extension module @@ -134,11 +173,14 @@ ft2font_module() : Py::ExtensionModule<ft2font_module>( "ft2font" ) { + FT2Image::init_type(); Glyph::init_type(); FT2Font::init_type(); add_varargs_method("FT2Font", &ft2font_module::new_ft2font, "FT2Font"); + add_varargs_method("FT2Image", &ft2font_module::new_ft2image, + "FT2Image"); initialize( "The ft2font module" ); } @@ -148,6 +190,7 @@ private: Py::Object new_ft2font (const Py::Tuple &args); + Py::Object new_ft2image (const Py::Tuple &args); }; Modified: trunk/matplotlib/unit/agg_memleak.py =================================================================== --- trunk/matplotlib/unit/agg_memleak.py 2007-08-31 17:23:32 UTC (rev 3763) +++ trunk/matplotlib/unit/agg_memleak.py 2007-08-31 19:25:17 UTC (rev 3764) @@ -41,7 +41,7 @@ font.clear() font.set_text('hi mom', 60) font.set_size(12, 72) - o.draw_text( font, 30, 40, gc) + o.draw_text_image(font.get_image(), 30, 40, gc) o.write_png('aggtest%d.png'%i) val = report_memory(i) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <js...@us...> - 2007-08-31 17:23:35
|
Revision: 3763 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=3763&view=rev Author: jswhit Date: 2007-08-31 10:23:32 -0700 (Fri, 31 Aug 2007) Log Message: ----------- regenerate with Cython 0.9.6.5 Modified Paths: -------------- trunk/toolkits/basemap/src/_geod.c trunk/toolkits/basemap/src/_proj.c trunk/toolkits/basemap/src/_pyproj.pxi Modified: trunk/toolkits/basemap/src/_geod.c =================================================================== --- trunk/toolkits/basemap/src/_geod.c 2007-08-31 15:40:42 UTC (rev 3762) +++ trunk/toolkits/basemap/src/_geod.c 2007-08-31 17:23:32 UTC (rev 3763) @@ -1,10 +1,18 @@ -/* Generated by Pyrex 0.9.5.1 on Sun May 20 08:32:09 2007 */ +/* Generated by Pyrex 0.9.6.3 on Fri Aug 31 08:42:50 2007 */ +#define PY_SSIZE_T_CLEAN #include "Python.h" #include "structmember.h" #ifndef PY_LONG_LONG #define PY_LONG_LONG LONG_LONG #endif +#if PY_VERSION_HEX < 0x02050000 + typedef int Py_ssize_t; + #define PY_SSIZE_T_MAX INT_MAX + #define PY_SSIZE_T_MIN INT_MIN + #define PyInt_FromSsize_t(z) PyInt_FromLong(z) + #define PyInt_AsSsize_t(o) PyInt_AsLong(o) +#endif #ifdef __cplusplus #define __PYX_EXTERN_C extern "C" #else @@ -15,12 +23,36 @@ #include "math.h" #include "geodesic.h" #include "proj_api.h" -#include "pycompat.h" +#ifdef __GNUC__ +#define INLINE __inline__ +#elif _WIN32 +#define INLINE __inline +#else +#define INLINE +#endif + +typedef struct {const char *s; const void **p;} __Pyx_CApiTabEntry; /*proto*/ typedef struct {PyObject **p; char *s;} __Pyx_InternTabEntry; /*proto*/ typedef struct {PyObject **p; char *s; long n;} __Pyx_StringTabEntry; /*proto*/ +#define __Pyx_PyBool_FromLong(b) ((b) ? (Py_INCREF(Py_True), Py_True) : (Py_INCREF(Py_False), Py_False)) +static INLINE int __Pyx_PyObject_IsTrue(PyObject* x) { + if (x == Py_True) return 1; + else if (x == Py_False) return 0; + else return PyObject_IsTrue(x); +} + + +#ifdef __GNUC__ +#define likely(x) __builtin_expect(!!(x), 1) +#define unlikely(x) __builtin_expect(!!(x), 0) +#else /* __GNUC__ */ +#define likely(x) (x) +#define unlikely(x) (x) +#endif /* __GNUC__ */ + static PyObject *__pyx_m; static PyObject *__pyx_b; static int __pyx_lineno; @@ -70,13 +102,11 @@ static PyObject *__pyx_n___version__; static PyObject *__pyx_n_radians; static PyObject *__pyx_n_degrees; -static PyObject *__pyx_n_False; static PyObject *__pyx_k2p; static PyObject *__pyx_n_iteritems; static PyObject *__pyx_n_append; -static PyObject *__pyx_n_str; static PyObject *__pyx_n_join; static PyObject *__pyx_n_RuntimeError; @@ -85,6 +115,8 @@ static PyObject *__pyx_k8p; static PyObject *__pyx_k9p; +static PyObject *__pyx_builtin_RuntimeError; + static char (__pyx_k6[]) = "+"; static char (__pyx_k7[]) = "="; static char (__pyx_k8[]) = " "; @@ -99,119 +131,187 @@ PyObject *__pyx_v_value; int __pyx_r; PyObject *__pyx_1 = 0; - PyObject *__pyx_2 = 0; + Py_ssize_t __pyx_2; PyObject *__pyx_3 = 0; PyObject *__pyx_4 = 0; PyObject *__pyx_5 = 0; PyObject *__pyx_6 = 0; int __pyx_7; static char *__pyx_argnames[] = {"geodparams",0}; - if (!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "O", __pyx_argnames, &__pyx_v_geodparams)) return -1; + if (unlikely(!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "O", __pyx_argnames, &__pyx_v_geodparams))) return -1; Py_INCREF(__pyx_v_self); Py_INCREF(__pyx_v_geodparams); __pyx_v_geodargs = Py_None; Py_INCREF(Py_None); __pyx_v_key = Py_None; Py_INCREF(Py_None); __pyx_v_value = Py_None; Py_INCREF(Py_None); - /* "/Users/jsw/python/matplotlib/trunk/toolkits/basemap/src/_geod.pyx":13 */ + /* "/Volumes/User/jwhitaker/python/pyproj/_geod.pyx":13 + * def __new__(self, geodparams): + * cdef GEODESIC_T GEOD_T + * self.geodparams = geodparams # <<<<<<<<<<<<<< + * # setup proj initialization string. + * geodargs = [] + */ Py_INCREF(__pyx_v_geodparams); Py_DECREF(((struct __pyx_obj_5_geod_Geod *)__pyx_v_self)->geodparams); ((struct __pyx_obj_5_geod_Geod *)__pyx_v_self)->geodparams = __pyx_v_geodparams; - /* "/Users/jsw/python/matplotlib/trunk/toolkits/basemap/src/_geod.pyx":15 */ - __pyx_1 = PyList_New(0); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 15; goto __pyx_L1;} + /* "/Volumes/User/jwhitaker/python/pyproj/_geod.pyx":15 + * self.geodparams = geodparams + * # setup proj initialization string. + * geodargs = [] # <<<<<<<<<<<<<< + * for key,value in geodparams.iteritems(): + * geodargs.append('+'+key+"="+str(value)+' ') + */ + __pyx_1 = PyList_New(0); if (unlikely(!__pyx_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 15; goto __pyx_L1;} Py_DECREF(__pyx_v_geodargs); __pyx_v_geodargs = __pyx_1; __pyx_1 = 0; - /* "/Users/jsw/python/matplotlib/trunk/toolkits/basemap/src/_geod.pyx":16 */ - __pyx_1 = PyObject_GetAttr(__pyx_v_geodparams, __pyx_n_iteritems); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 16; goto __pyx_L1;} - __pyx_2 = PyObject_CallObject(__pyx_1, 0); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 16; goto __pyx_L1;} + /* "/Volumes/User/jwhitaker/python/pyproj/_geod.pyx":16 + * # setup proj initialization string. + * geodargs = [] + * for key,value in geodparams.iteritems(): # <<<<<<<<<<<<<< + * geodargs.append('+'+key+"="+str(value)+' ') + * self.geodinitstring = PyString_AsString(''.join(geodargs)) + */ + __pyx_1 = PyObject_GetAttr(__pyx_v_geodparams, __pyx_n_iteritems); if (unlikely(!__pyx_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 16; goto __pyx_L1;} + __pyx_3 = PyObject_CallObject(__pyx_1, 0); if (unlikely(!__pyx_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 16; goto __pyx_L1;} Py_DECREF(__pyx_1); __pyx_1 = 0; - __pyx_1 = PyObject_GetIter(__pyx_2); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 16; goto __pyx_L1;} - Py_DECREF(__pyx_2); __pyx_2 = 0; + if (PyList_CheckExact(__pyx_3)) { __pyx_2 = 0; __pyx_1 = __pyx_3; Py_INCREF(__pyx_1); } + else { __pyx_1 = PyObject_GetIter(__pyx_3); if (unlikely(!__pyx_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 16; goto __pyx_L1;} } + Py_DECREF(__pyx_3); __pyx_3 = 0; for (;;) { - __pyx_2 = PyIter_Next(__pyx_1); - if (!__pyx_2) { - if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 16; goto __pyx_L1;} - break; + if (PyList_CheckExact(__pyx_1)) { if (__pyx_2 >= PyList_GET_SIZE(__pyx_1)) break; __pyx_3 = PyList_GET_ITEM(__pyx_1, __pyx_2++); Py_INCREF(__pyx_3); } + else { + __pyx_3 = PyIter_Next(__pyx_1); + if (!__pyx_3) { + break; + } } - __pyx_3 = PyObject_GetIter(__pyx_2); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 16; goto __pyx_L1;} - Py_DECREF(__pyx_2); __pyx_2 = 0; - __pyx_2 = __Pyx_UnpackItem(__pyx_3); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 16; goto __pyx_L1;} - Py_DECREF(__pyx_v_key); - __pyx_v_key = __pyx_2; - __pyx_2 = 0; - __pyx_2 = __Pyx_UnpackItem(__pyx_3); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 16; goto __pyx_L1;} - Py_DECREF(__pyx_v_value); - __pyx_v_value = __pyx_2; - __pyx_2 = 0; - if (__Pyx_EndUnpack(__pyx_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 16; goto __pyx_L1;} - Py_DECREF(__pyx_3); __pyx_3 = 0; + if (PyTuple_CheckExact(__pyx_3) && PyTuple_GET_SIZE(__pyx_3) == 2) { + __pyx_5 = PyTuple_GET_ITEM(__pyx_3, 0); + Py_INCREF(__pyx_5); + Py_DECREF(__pyx_v_key); + __pyx_v_key = __pyx_5; + __pyx_5 = 0; + __pyx_5 = PyTuple_GET_ITEM(__pyx_3, 1); + Py_INCREF(__pyx_5); + Py_DECREF(__pyx_v_value); + __pyx_v_value = __pyx_5; + __pyx_5 = 0; + Py_DECREF(__pyx_3); __pyx_3 = 0; + } + else { + __pyx_4 = PyObject_GetIter(__pyx_3); if (unlikely(!__pyx_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 16; goto __pyx_L1;} + Py_DECREF(__pyx_3); __pyx_3 = 0; + __pyx_5 = __Pyx_UnpackItem(__pyx_4); if (unlikely(!__pyx_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 16; goto __pyx_L1;} + Py_DECREF(__pyx_v_key); + __pyx_v_key = __pyx_5; + __pyx_5 = 0; + __pyx_5 = __Pyx_UnpackItem(__pyx_4); if (unlikely(!__pyx_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 16; goto __pyx_L1;} + Py_DECREF(__pyx_v_value); + __pyx_v_value = __pyx_5; + __pyx_5 = 0; + if (__Pyx_EndUnpack(__pyx_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 16; goto __pyx_L1;} + Py_DECREF(__pyx_4); __pyx_4 = 0; + } - /* "/Users/jsw/python/matplotlib/trunk/toolkits/basemap/src/_geod.pyx":17 */ - __pyx_2 = PyObject_GetAttr(__pyx_v_geodargs, __pyx_n_append); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 17; goto __pyx_L1;} - __pyx_3 = PyNumber_Add(__pyx_k6p, __pyx_v_key); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 17; goto __pyx_L1;} - __pyx_4 = PyNumber_Add(__pyx_3, __pyx_k7p); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 17; goto __pyx_L1;} + /* "/Volumes/User/jwhitaker/python/pyproj/_geod.pyx":17 + * geodargs = [] + * for key,value in geodparams.iteritems(): + * geodargs.append('+'+key+"="+str(value)+' ') # <<<<<<<<<<<<<< + * self.geodinitstring = PyString_AsString(''.join(geodargs)) + * # initialize projection + */ + __pyx_5 = PyObject_GetAttr(__pyx_v_geodargs, __pyx_n_append); if (unlikely(!__pyx_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 17; goto __pyx_L1;} + __pyx_3 = PyNumber_Add(__pyx_k6p, __pyx_v_key); if (unlikely(!__pyx_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 17; goto __pyx_L1;} + __pyx_4 = PyNumber_Add(__pyx_3, __pyx_k7p); if (unlikely(!__pyx_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 17; goto __pyx_L1;} Py_DECREF(__pyx_3); __pyx_3 = 0; - __pyx_3 = __Pyx_GetName(__pyx_b, __pyx_n_str); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 17; goto __pyx_L1;} - __pyx_5 = PyTuple_New(1); if (!__pyx_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 17; goto __pyx_L1;} + __pyx_3 = PyTuple_New(1); if (unlikely(!__pyx_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 17; goto __pyx_L1;} Py_INCREF(__pyx_v_value); - PyTuple_SET_ITEM(__pyx_5, 0, __pyx_v_value); - __pyx_6 = PyObject_CallObject(__pyx_3, __pyx_5); if (!__pyx_6) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 17; goto __pyx_L1;} + PyTuple_SET_ITEM(__pyx_3, 0, __pyx_v_value); + __pyx_6 = PyObject_CallObject(((PyObject*)&PyString_Type), __pyx_3); if (unlikely(!__pyx_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 17; goto __pyx_L1;} Py_DECREF(__pyx_3); __pyx_3 = 0; - Py_DECREF(__pyx_5); __pyx_5 = 0; - __pyx_3 = PyNumber_Add(__pyx_4, __pyx_6); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 17; goto __pyx_L1;} + __pyx_3 = PyNumber_Add(__pyx_4, __pyx_6); if (unlikely(!__pyx_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 17; goto __pyx_L1;} Py_DECREF(__pyx_4); __pyx_4 = 0; Py_DECREF(__pyx_6); __pyx_6 = 0; - __pyx_5 = PyNumber_Add(__pyx_3, __pyx_k8p); if (!__pyx_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 17; goto __pyx_L1;} + __pyx_4 = PyNumber_Add(__pyx_3, __pyx_k8p); if (unlikely(!__pyx_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 17; goto __pyx_L1;} Py_DECREF(__pyx_3); __pyx_3 = 0; - __pyx_4 = PyTuple_New(1); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 17; goto __pyx_L1;} - PyTuple_SET_ITEM(__pyx_4, 0, __pyx_5); - __pyx_5 = 0; - __pyx_6 = PyObject_CallObject(__pyx_2, __pyx_4); if (!__pyx_6) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 17; goto __pyx_L1;} - Py_DECREF(__pyx_2); __pyx_2 = 0; - Py_DECREF(__pyx_4); __pyx_4 = 0; + __pyx_6 = PyTuple_New(1); if (unlikely(!__pyx_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 17; goto __pyx_L1;} + PyTuple_SET_ITEM(__pyx_6, 0, __pyx_4); + __pyx_4 = 0; + __pyx_3 = PyObject_CallObject(__pyx_5, __pyx_6); if (unlikely(!__pyx_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 17; goto __pyx_L1;} + Py_DECREF(__pyx_5); __pyx_5 = 0; Py_DECREF(__pyx_6); __pyx_6 = 0; + Py_DECREF(__pyx_3); __pyx_3 = 0; } Py_DECREF(__pyx_1); __pyx_1 = 0; - /* "/Users/jsw/python/matplotlib/trunk/toolkits/basemap/src/_geod.pyx":18 */ - __pyx_3 = PyObject_GetAttr(__pyx_k9p, __pyx_n_join); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 18; goto __pyx_L1;} - __pyx_5 = PyTuple_New(1); if (!__pyx_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 18; goto __pyx_L1;} + /* "/Volumes/User/jwhitaker/python/pyproj/_geod.pyx":18 + * for key,value in geodparams.iteritems(): + * geodargs.append('+'+key+"="+str(value)+' ') + * self.geodinitstring = PyString_AsString(''.join(geodargs)) # <<<<<<<<<<<<<< + * # initialize projection + * self.geodesic_t = GEOD_init_plus(self.geodinitstring, &GEOD_T)[0] + */ + __pyx_4 = PyObject_GetAttr(__pyx_k9p, __pyx_n_join); if (unlikely(!__pyx_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 18; goto __pyx_L1;} + __pyx_5 = PyTuple_New(1); if (unlikely(!__pyx_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 18; goto __pyx_L1;} Py_INCREF(__pyx_v_geodargs); PyTuple_SET_ITEM(__pyx_5, 0, __pyx_v_geodargs); - __pyx_2 = PyObject_CallObject(__pyx_3, __pyx_5); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 18; goto __pyx_L1;} - Py_DECREF(__pyx_3); __pyx_3 = 0; + __pyx_6 = PyObject_CallObject(__pyx_4, __pyx_5); if (unlikely(!__pyx_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 18; goto __pyx_L1;} + Py_DECREF(__pyx_4); __pyx_4 = 0; Py_DECREF(__pyx_5); __pyx_5 = 0; - ((struct __pyx_obj_5_geod_Geod *)__pyx_v_self)->geodinitstring = PyString_AsString(__pyx_2); - Py_DECREF(__pyx_2); __pyx_2 = 0; + ((struct __pyx_obj_5_geod_Geod *)__pyx_v_self)->geodinitstring = PyString_AsString(__pyx_6); + Py_DECREF(__pyx_6); __pyx_6 = 0; - /* "/Users/jsw/python/matplotlib/trunk/toolkits/basemap/src/_geod.pyx":20 */ + /* "/Volumes/User/jwhitaker/python/pyproj/_geod.pyx":20 + * self.geodinitstring = PyString_AsString(''.join(geodargs)) + * # initialize projection + * self.geodesic_t = GEOD_init_plus(self.geodinitstring, &GEOD_T)[0] # <<<<<<<<<<<<<< + * if pj_errno != 0: + * raise RuntimeError(pj_strerrno(pj_errno)) + */ ((struct __pyx_obj_5_geod_Geod *)__pyx_v_self)->geodesic_t = (GEOD_init_plus(((struct __pyx_obj_5_geod_Geod *)__pyx_v_self)->geodinitstring,(&__pyx_v_GEOD_T))[0]); - /* "/Users/jsw/python/matplotlib/trunk/toolkits/basemap/src/_geod.pyx":21 */ + /* "/Volumes/User/jwhitaker/python/pyproj/_geod.pyx":21 + * # initialize projection + * self.geodesic_t = GEOD_init_plus(self.geodinitstring, &GEOD_T)[0] + * if pj_errno != 0: # <<<<<<<<<<<<<< + * raise RuntimeError(pj_strerrno(pj_errno)) + * self.proj_version = PJ_VERSION/100. + */ __pyx_7 = (pj_errno != 0); if (__pyx_7) { - /* "/Users/jsw/python/matplotlib/trunk/toolkits/basemap/src/_geod.pyx":22 */ - __pyx_4 = __Pyx_GetName(__pyx_b, __pyx_n_RuntimeError); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 22; goto __pyx_L1;} - __pyx_6 = PyString_FromString(pj_strerrno(pj_errno)); if (!__pyx_6) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 22; goto __pyx_L1;} - __pyx_1 = PyTuple_New(1); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 22; goto __pyx_L1;} - PyTuple_SET_ITEM(__pyx_1, 0, __pyx_6); - __pyx_6 = 0; - __pyx_3 = PyObject_CallObject(__pyx_4, __pyx_1); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 22; goto __pyx_L1;} + /* "/Volumes/User/jwhitaker/python/pyproj/_geod.pyx":22 + * self.geodesic_t = GEOD_init_plus(self.geodinitstring, &GEOD_T)[0] + * if pj_errno != 0: + * raise RuntimeError(pj_strerrno(pj_errno)) # <<<<<<<<<<<<<< + * self.proj_version = PJ_VERSION/100. + * + */ + __pyx_3 = PyString_FromString(pj_strerrno(pj_errno)); if (unlikely(!__pyx_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 22; goto __pyx_L1;} + __pyx_1 = PyTuple_New(1); if (unlikely(!__pyx_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 22; goto __pyx_L1;} + PyTuple_SET_ITEM(__pyx_1, 0, __pyx_3); + __pyx_3 = 0; + __pyx_4 = PyObject_CallObject(__pyx_builtin_RuntimeError, __pyx_1); if (unlikely(!__pyx_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 22; goto __pyx_L1;} + Py_DECREF(__pyx_1); __pyx_1 = 0; + __Pyx_Raise(__pyx_4, 0, 0); Py_DECREF(__pyx_4); __pyx_4 = 0; - Py_DECREF(__pyx_1); __pyx_1 = 0; - __Pyx_Raise(__pyx_3, 0, 0); - Py_DECREF(__pyx_3); __pyx_3 = 0; {__pyx_filename = __pyx_f[0]; __pyx_lineno = 22; goto __pyx_L1;} goto __pyx_L4; } __pyx_L4:; - /* "/Users/jsw/python/matplotlib/trunk/toolkits/basemap/src/_geod.pyx":23 */ - __pyx_5 = PyFloat_FromDouble((PJ_VERSION / 100.)); if (!__pyx_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 23; goto __pyx_L1;} + /* "/Volumes/User/jwhitaker/python/pyproj/_geod.pyx":23 + * if pj_errno != 0: + * raise RuntimeError(pj_strerrno(pj_errno)) + * self.proj_version = PJ_VERSION/100. # <<<<<<<<<<<<<< + * + * def __reduce__(self): + */ + __pyx_5 = PyFloat_FromDouble((PJ_VERSION / 100.)); if (unlikely(!__pyx_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 23; goto __pyx_L1;} Py_DECREF(((struct __pyx_obj_5_geod_Geod *)__pyx_v_self)->proj_version); ((struct __pyx_obj_5_geod_Geod *)__pyx_v_self)->proj_version = __pyx_5; __pyx_5 = 0; @@ -220,7 +320,6 @@ goto __pyx_L0; __pyx_L1:; Py_XDECREF(__pyx_1); - Py_XDECREF(__pyx_2); Py_XDECREF(__pyx_3); Py_XDECREF(__pyx_4); Py_XDECREF(__pyx_5); @@ -246,15 +345,21 @@ PyObject *__pyx_2 = 0; PyObject *__pyx_3 = 0; static char *__pyx_argnames[] = {0}; - if (!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "", __pyx_argnames)) return 0; + if (unlikely(!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "", __pyx_argnames))) return 0; Py_INCREF(__pyx_v_self); - /* "/Users/jsw/python/matplotlib/trunk/toolkits/basemap/src/_geod.pyx":27 */ - __pyx_1 = PyObject_GetAttr(__pyx_v_self, __pyx_n___class__); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 27; goto __pyx_L1;} - __pyx_2 = PyTuple_New(1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 27; goto __pyx_L1;} + /* "/Volumes/User/jwhitaker/python/pyproj/_geod.pyx":27 + * def __reduce__(self): + * """special method that allows pyproj.Geod instance to be pickled""" + * return (self.__class__,(self.geodparams,)) # <<<<<<<<<<<<<< + * + * def _fwd(self, object lons, object lats, object az, object dist, radians=False): + */ + __pyx_1 = PyObject_GetAttr(__pyx_v_self, __pyx_n___class__); if (unlikely(!__pyx_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 27; goto __pyx_L1;} + __pyx_2 = PyTuple_New(1); if (unlikely(!__pyx_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 27; goto __pyx_L1;} Py_INCREF(((struct __pyx_obj_5_geod_Geod *)__pyx_v_self)->geodparams); PyTuple_SET_ITEM(__pyx_2, 0, ((struct __pyx_obj_5_geod_Geod *)__pyx_v_self)->geodparams); - __pyx_3 = PyTuple_New(2); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 27; goto __pyx_L1;} + __pyx_3 = PyTuple_New(2); if (unlikely(!__pyx_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 27; goto __pyx_L1;} PyTuple_SET_ITEM(__pyx_3, 0, __pyx_1); PyTuple_SET_ITEM(__pyx_3, 1, __pyx_2); __pyx_1 = 0; @@ -281,6 +386,8 @@ static PyObject *__pyx_k10p; static PyObject *__pyx_k11p; +static PyObject *__pyx_builtin_ValueError; + static char (__pyx_k10[]) = "Buffer lengths not the same"; static char (__pyx_k11[]) = "undefined forward geodesic (may be an equatorial arc)"; @@ -308,15 +415,15 @@ void (*__pyx_v_distdat); PyObject *__pyx_r; int __pyx_1; - PyObject *__pyx_2 = 0; - int __pyx_3; + int __pyx_2; + PyObject *__pyx_3 = 0; PyObject *__pyx_4 = 0; PyObject *__pyx_5 = 0; Py_ssize_t __pyx_6; double __pyx_7; static char *__pyx_argnames[] = {"lons","lats","az","dist","radians",0}; __pyx_v_radians = __pyx_k3; - if (!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "OOOO|O", __pyx_argnames, &__pyx_v_lons, &__pyx_v_lats, &__pyx_v_az, &__pyx_v_dist, &__pyx_v_radians)) return 0; + if (unlikely(!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "OOOO|O", __pyx_argnames, &__pyx_v_lons, &__pyx_v_lats, &__pyx_v_az, &__pyx_v_dist, &__pyx_v_radians))) return 0; Py_INCREF(__pyx_v_self); Py_INCREF(__pyx_v_lons); Py_INCREF(__pyx_v_lats); @@ -324,59 +431,105 @@ Py_INCREF(__pyx_v_dist); Py_INCREF(__pyx_v_radians); - /* "/Users/jsw/python/matplotlib/trunk/toolkits/basemap/src/_geod.pyx":40 */ + /* "/Volumes/User/jwhitaker/python/pyproj/_geod.pyx":40 + * cdef void *londata, *latdata, *azdat, *distdat + * # if buffer api is supported, get pointer to data buffers. + * if PyObject_AsWriteBuffer(lons, &londata, &buflenlons) <> 0: # <<<<<<<<<<<<<< + * raise RuntimeError + * if PyObject_AsWriteBuffer(lats, &latdata, &buflenlats) <> 0: + */ __pyx_1 = (PyObject_AsWriteBuffer(__pyx_v_lons,(&__pyx_v_londata),(&__pyx_v_buflenlons)) != 0); if (__pyx_1) { - /* "/Users/jsw/python/matplotlib/trunk/toolkits/basemap/src/_geod.pyx":41 */ - __pyx_2 = __Pyx_GetName(__pyx_b, __pyx_n_RuntimeError); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 41; goto __pyx_L1;} - __Pyx_Raise(__pyx_2, 0, 0); - Py_DECREF(__pyx_2); __pyx_2 = 0; + /* "/Volumes/User/jwhitaker/python/pyproj/_geod.pyx":41 + * # if buffer api is supported, get pointer to data buffers. + * if PyObject_AsWriteBuffer(lons, &londata, &buflenlons) <> 0: + * raise RuntimeError # <<<<<<<<<<<<<< + * if PyObject_AsWriteBuffer(lats, &latdata, &buflenlats) <> 0: + * raise RuntimeError + */ + __Pyx_Raise(__pyx_builtin_RuntimeError, 0, 0); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 41; goto __pyx_L1;} goto __pyx_L2; } __pyx_L2:; - /* "/Users/jsw/python/matplotlib/trunk/toolkits/basemap/src/_geod.pyx":42 */ + /* "/Volumes/User/jwhitaker/python/pyproj/_geod.pyx":42 + * if PyObject_AsWriteBuffer(lons, &londata, &buflenlons) <> 0: + * raise RuntimeError + * if PyObject_AsWriteBuffer(lats, &latdata, &buflenlats) <> 0: # <<<<<<<<<<<<<< + * raise RuntimeError + * if PyObject_AsWriteBuffer(az, &azdat, &buflenaz) <> 0: + */ __pyx_1 = (PyObject_AsWriteBuffer(__pyx_v_lats,(&__pyx_v_latdata),(&__pyx_v_buflenlats)) != 0); if (__pyx_1) { - /* "/Users/jsw/python/matplotlib/trunk/toolkits/basemap/src/_geod.pyx":43 */ - __pyx_2 = __Pyx_GetName(__pyx_b, __pyx_n_RuntimeError); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 43; goto __pyx_L1;} - __Pyx_Raise(__pyx_2, 0, 0); - Py_DECREF(__pyx_2); __pyx_2 = 0; + /* "/Volumes/User/jwhitaker/python/pyproj/_geod.pyx":43 + * raise RuntimeError + * if PyObject_AsWriteBuffer(lats, &latdata, &buflenlats) <> 0: + * raise RuntimeError # <<<<<<<<<<<<<< + * if PyObject_AsWriteBuffer(az, &azdat, &buflenaz) <> 0: + * raise RuntimeError + */ + __Pyx_Raise(__pyx_builtin_RuntimeError, 0, 0); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 43; goto __pyx_L1;} goto __pyx_L3; } __pyx_L3:; - /* "/Users/jsw/python/matplotlib/trunk/toolkits/basemap/src/_geod.pyx":44 */ + /* "/Volumes/User/jwhitaker/python/pyproj/_geod.pyx":44 + * if PyObject_AsWriteBuffer(lats, &latdata, &buflenlats) <> 0: + * raise RuntimeError + * if PyObject_AsWriteBuffer(az, &azdat, &buflenaz) <> 0: # <<<<<<<<<<<<<< + * raise RuntimeError + * if PyObject_AsWriteBuffer(dist, &distdat, &buflend) <> 0: + */ __pyx_1 = (PyObject_AsWriteBuffer(__pyx_v_az,(&__pyx_v_azdat),(&__pyx_v_buflenaz)) != 0); if (__pyx_1) { - /* "/Users/jsw/python/matplotlib/trunk/toolkits/basemap/src/_geod.pyx":45 */ - __pyx_2 = __Pyx_GetName(__pyx_b, __pyx_n_RuntimeError); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 45; goto __pyx_L1;} - __Pyx_Raise(__pyx_2, 0, 0); - Py_DECREF(__pyx_2); __pyx_2 = 0; + /* "/Volumes/User/jwhitaker/python/pyproj/_geod.pyx":45 + * raise RuntimeError + * if PyObject_AsWriteBuffer(az, &azdat, &buflenaz) <> 0: + * raise RuntimeError # <<<<<<<<<<<<<< + * if PyObject_AsWriteBuffer(dist, &distdat, &buflend) <> 0: + * raise RuntimeError + */ + __Pyx_Raise(__pyx_builtin_RuntimeError, 0, 0); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 45; goto __pyx_L1;} goto __pyx_L4; } __pyx_L4:; - /* "/Users/jsw/python/matplotlib/trunk/toolkits/basemap/src/_geod.pyx":46 */ + /* "/Volumes/User/jwhitaker/python/pyproj/_geod.pyx":46 + * if PyObject_AsWriteBuffer(az, &azdat, &buflenaz) <> 0: + * raise RuntimeError + * if PyObject_AsWriteBuffer(dist, &distdat, &buflend) <> 0: # <<<<<<<<<<<<<< + * raise RuntimeError + * # process data in buffer + */ __pyx_1 = (PyObject_AsWriteBuffer(__pyx_v_dist,(&__pyx_v_distdat),(&__pyx_v_buflend)) != 0); if (__pyx_1) { - /* "/Users/jsw/python/matplotlib/trunk/toolkits/basemap/src/_geod.pyx":47 */ - __pyx_2 = __Pyx_GetName(__pyx_b, __pyx_n_RuntimeError); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 47; goto __pyx_L1;} - __Pyx_Raise(__pyx_2, 0, 0); - Py_DECREF(__pyx_2); __pyx_2 = 0; + /* "/Volumes/User/jwhitaker/python/pyproj/_geod.pyx":47 + * raise RuntimeError + * if PyObject_AsWriteBuffer(dist, &distdat, &buflend) <> 0: + * raise RuntimeError # <<<<<<<<<<<<<< + * # process data in buffer + * if not buflenlons == buflenlats == buflenaz == buflend: + */ + __Pyx_Raise(__pyx_builtin_RuntimeError, 0, 0); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 47; goto __pyx_L1;} goto __pyx_L5; } __pyx_L5:; - /* "/Users/jsw/python/matplotlib/trunk/toolkits/basemap/src/_geod.pyx":49 */ + /* "/Volumes/User/jwhitaker/python/pyproj/_geod.pyx":49 + * raise RuntimeError + * # process data in buffer + * if not buflenlons == buflenlats == buflenaz == buflend: # <<<<<<<<<<<<<< + * raise RuntimeError("Buffer lengths not the same") + * ndim = buflenlons/_doublesize + */ __pyx_1 = __pyx_v_buflenlons == __pyx_v_buflenlats; if (__pyx_1) { __pyx_1 = __pyx_v_buflenlats == __pyx_v_buflenaz; @@ -384,141 +537,267 @@ __pyx_1 = __pyx_v_buflenaz == __pyx_v_buflend; } } - __pyx_3 = (!__pyx_1); - if (__pyx_3) { + __pyx_2 = (!__pyx_1); + if (__pyx_2) { - /* "/Users/jsw/python/matplotlib/trunk/toolkits/basemap/src/_geod.pyx":50 */ - __pyx_2 = __Pyx_GetName(__pyx_b, __pyx_n_RuntimeError); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 50; goto __pyx_L1;} - __pyx_4 = PyTuple_New(1); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 50; goto __pyx_L1;} + /* "/Volumes/User/jwhitaker/python/pyproj/_geod.pyx":50 + * # process data in buffer + * if not buflenlons == buflenlats == buflenaz == buflend: + * raise RuntimeError("Buffer lengths not the same") # <<<<<<<<<<<<<< + * ndim = buflenlons/_doublesize + * lonsdata = <double *>londata + */ + __pyx_3 = PyTuple_New(1); if (unlikely(!__pyx_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 50; goto __pyx_L1;} Py_INCREF(__pyx_k10p); - PyTuple_SET_ITEM(__pyx_4, 0, __pyx_k10p); - __pyx_5 = PyObject_CallObject(__pyx_2, __pyx_4); if (!__pyx_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 50; goto __pyx_L1;} - Py_DECREF(__pyx_2); __pyx_2 = 0; + PyTuple_SET_ITEM(__pyx_3, 0, __pyx_k10p); + __pyx_4 = PyObject_CallObject(__pyx_builtin_RuntimeError, __pyx_3); if (unlikely(!__pyx_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 50; goto __pyx_L1;} + Py_DECREF(__pyx_3); __pyx_3 = 0; + __Pyx_Raise(__pyx_4, 0, 0); Py_DECREF(__pyx_4); __pyx_4 = 0; - __Pyx_Raise(__pyx_5, 0, 0); - Py_DECREF(__pyx_5); __pyx_5 = 0; {__pyx_filename = __pyx_f[0]; __pyx_lineno = 50; goto __pyx_L1;} goto __pyx_L6; } __pyx_L6:; - /* "/Users/jsw/python/matplotlib/trunk/toolkits/basemap/src/_geod.pyx":51 */ - __pyx_2 = PyInt_FromLong(__pyx_v_buflenlons); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 51; goto __pyx_L1;} - __pyx_4 = __Pyx_GetName(__pyx_m, __pyx_n__doublesize); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 51; goto __pyx_L1;} - __pyx_5 = PyNumber_Divide(__pyx_2, __pyx_4); if (!__pyx_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 51; goto __pyx_L1;} - Py_DECREF(__pyx_2); __pyx_2 = 0; + /* "/Volumes/User/jwhitaker/python/pyproj/_geod.pyx":51 + * if not buflenlons == buflenlats == buflenaz == buflend: + * raise RuntimeError("Buffer lengths not the same") + * ndim = buflenlons/_doublesize # <<<<<<<<<<<<<< + * lonsdata = <double *>londata + * latsdata = <double *>latdata + */ + __pyx_3 = PyInt_FromSsize_t(__pyx_v_buflenlons); if (unlikely(!__pyx_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 51; goto __pyx_L1;} + __pyx_4 = __Pyx_GetName(__pyx_m, __pyx_n__doublesize); if (unlikely(!__pyx_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 51; goto __pyx_L1;} + __pyx_5 = PyNumber_Divide(__pyx_3, __pyx_4); if (unlikely(!__pyx_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 51; goto __pyx_L1;} + Py_DECREF(__pyx_3); __pyx_3 = 0; Py_DECREF(__pyx_4); __pyx_4 = 0; - __pyx_6 = PyInt_AsLong(__pyx_5); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 51; goto __pyx_L1;} + __pyx_6 = PyInt_AsSsize_t(__pyx_5); if (unlikely(PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 51; goto __pyx_L1;} Py_DECREF(__pyx_5); __pyx_5 = 0; __pyx_v_ndim = __pyx_6; - /* "/Users/jsw/python/matplotlib/trunk/toolkits/basemap/src/_geod.pyx":52 */ + /* "/Volumes/User/jwhitaker/python/pyproj/_geod.pyx":52 + * raise RuntimeError("Buffer lengths not the same") + * ndim = buflenlons/_doublesize + * lonsdata = <double *>londata # <<<<<<<<<<<<<< + * latsdata = <double *>latdata + * azdata = <double *>azdat + */ __pyx_v_lonsdata = ((double (*))__pyx_v_londata); - /* "/Users/jsw/python/matplotlib/trunk/toolkits/basemap/src/_geod.pyx":53 */ + /* "/Volumes/User/jwhitaker/python/pyproj/_geod.pyx":53 + * ndim = buflenlons/_doublesize + * lonsdata = <double *>londata + * latsdata = <double *>latdata # <<<<<<<<<<<<<< + * azdata = <double *>azdat + * distdata = <double *>distdat + */ __pyx_v_latsdata = ((double (*))__pyx_v_latdata); - /* "/Users/jsw/python/matplotlib/trunk/toolkits/basemap/src/_geod.pyx":54 */ + /* "/Volumes/User/jwhitaker/python/pyproj/_geod.pyx":54 + * lonsdata = <double *>londata + * latsdata = <double *>latdata + * azdata = <double *>azdat # <<<<<<<<<<<<<< + * distdata = <double *>distdat + * for i from 0 <= i < ndim: + */ __pyx_v_azdata = ((double (*))__pyx_v_azdat); - /* "/Users/jsw/python/matplotlib/trunk/toolkits/basemap/src/_geod.pyx":55 */ + /* "/Volumes/User/jwhitaker/python/pyproj/_geod.pyx":55 + * latsdata = <double *>latdata + * azdata = <double *>azdat + * distdata = <double *>distdat # <<<<<<<<<<<<<< + * for i from 0 <= i < ndim: + * if radians: + */ __pyx_v_distdata = ((double (*))__pyx_v_distdat); - /* "/Users/jsw/python/matplotlib/trunk/toolkits/basemap/src/_geod.pyx":56 */ - for (__pyx_v_i = 0; __pyx_v_i < __pyx_v_ndim; ++__pyx_v_i) { + /* "/Volumes/User/jwhitaker/python/pyproj/_geod.pyx":56 + * azdata = <double *>azdat + * distdata = <double *>distdat + * for i from 0 <= i < ndim: # <<<<<<<<<<<<<< + * if radians: + * self.geodesic_t.p1.v = lonsdata[i] + */ + for (__pyx_v_i = 0; __pyx_v_i < __pyx_v_ndim; __pyx_v_i++) { - /* "/Users/jsw/python/matplotlib/trunk/toolkits/basemap/src/_geod.pyx":57 */ - __pyx_1 = PyObject_IsTrue(__pyx_v_radians); if (__pyx_1 < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 57; goto __pyx_L1;} + /* "/Volumes/User/jwhitaker/python/pyproj/_geod.pyx":57 + * distdata = <double *>distdat + * for i from 0 <= i < ndim: + * if radians: # <<<<<<<<<<<<<< + * self.geodesic_t.p1.v = lonsdata[i] + * self.geodesic_t.p1.u = latsdata[i] + */ + __pyx_1 = PyObject_IsTrue(__pyx_v_radians); if (unlikely(__pyx_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 57; goto __pyx_L1;} if (__pyx_1) { - /* "/Users/jsw/python/matplotlib/trunk/toolkits/basemap/src/_geod.pyx":58 */ + /* "/Volumes/User/jwhitaker/python/pyproj/_geod.pyx":58 + * for i from 0 <= i < ndim: + * if radians: + * self.geodesic_t.p1.v = lonsdata[i] # <<<<<<<<<<<<<< + * self.geodesic_t.p1.u = latsdata[i] + * self.geodesic_t.ALPHA12 = azdata[i] + */ ((struct __pyx_obj_5_geod_Geod *)__pyx_v_self)->geodesic_t.p1.v = (__pyx_v_lonsdata[__pyx_v_i]); - /* "/Users/jsw/python/matplotlib/trunk/toolkits/basemap/src/_geod.pyx":59 */ + /* "/Volumes/User/jwhitaker/python/pyproj/_geod.pyx":59 + * if radians: + * self.geodesic_t.p1.v = lonsdata[i] + * self.geodesic_t.p1.u = latsdata[i] # <<<<<<<<<<<<<< + * self.geodesic_t.ALPHA12 = azdata[i] + * self.geodesic_t.DIST = distdata[i] + */ ((struct __pyx_obj_5_geod_Geod *)__pyx_v_self)->geodesic_t.p1.u = (__pyx_v_latsdata[__pyx_v_i]); - /* "/Users/jsw/python/matplotlib/trunk/toolkits/basemap/src/_geod.pyx":60 */ + /* "/Volumes/User/jwhitaker/python/pyproj/_geod.pyx":60 + * self.geodesic_t.p1.v = lonsdata[i] + * self.geodesic_t.p1.u = latsdata[i] + * self.geodesic_t.ALPHA12 = azdata[i] # <<<<<<<<<<<<<< + * self.geodesic_t.DIST = distdata[i] + * else: + */ ((struct __pyx_obj_5_geod_Geod *)__pyx_v_self)->geodesic_t.ALPHA12 = (__pyx_v_azdata[__pyx_v_i]); - /* "/Users/jsw/python/matplotlib/trunk/toolkits/basemap/src/_geod.pyx":61 */ + /* "/Volumes/User/jwhitaker/python/pyproj/_geod.pyx":61 + * self.geodesic_t.p1.u = latsdata[i] + * self.geodesic_t.ALPHA12 = azdata[i] + * self.geodesic_t.DIST = distdata[i] # <<<<<<<<<<<<<< + * else: + * self.geodesic_t.p1.v = _dg2rad*lonsdata[i] + */ ((struct __pyx_obj_5_geod_Geod *)__pyx_v_self)->geodesic_t.DIST = (__pyx_v_distdata[__pyx_v_i]); goto __pyx_L9; } /*else*/ { - /* "/Users/jsw/python/matplotlib/trunk/toolkits/basemap/src/_geod.pyx":63 */ - __pyx_2 = __Pyx_GetName(__pyx_m, __pyx_n__dg2rad); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 63; goto __pyx_L1;} - __pyx_4 = PyFloat_FromDouble((__pyx_v_lonsdata[__pyx_v_i])); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 63; goto __pyx_L1;} - __pyx_5 = PyNumber_Multiply(__pyx_2, __pyx_4); if (!__pyx_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 63; goto __pyx_L1;} - Py_DECREF(__pyx_2); __pyx_2 = 0; + /* "/Volumes/User/jwhitaker/python/pyproj/_geod.pyx":63 + * self.geodesic_t.DIST = distdata[i] + * else: + * self.geodesic_t.p1.v = _dg2rad*lonsdata[i] # <<<<<<<<<<<<<< + * self.geodesic_t.p1.u = _dg2rad*latsdata[i] + * self.geodesic_t.ALPHA12 = _dg2rad*azdata[i] + */ + __pyx_3 = __Pyx_GetName(__pyx_m, __pyx_n__dg2rad); if (unlikely(!__pyx_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 63; goto __pyx_L1;} + __pyx_4 = PyFloat_FromDouble((__pyx_v_lonsdata[__pyx_v_i])); if (unlikely(!__pyx_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 63; goto __pyx_L1;} + __pyx_5 = PyNumber_Multiply(__pyx_3, __pyx_4); if (unlikely(!__pyx_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 63; goto __pyx_L1;} + Py_DECREF(__pyx_3); __pyx_3 = 0; Py_DECREF(__pyx_4); __pyx_4 = 0; - __pyx_7 = PyFloat_AsDouble(__pyx_5); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 63; goto __pyx_L1;} + __pyx_7 = PyFloat_AsDouble(__pyx_5); if (unlikely(PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 63; goto __pyx_L1;} Py_DECREF(__pyx_5); __pyx_5 = 0; ((struct __pyx_obj_5_geod_Geod *)__pyx_v_self)->geodesic_t.p1.v = __pyx_7; - /* "/Users/jsw/python/matplotlib/trunk/toolkits/basemap/src/_geod.pyx":64 */ - __pyx_2 = __Pyx_GetName(__pyx_m, __pyx_n__dg2rad); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 64; goto __pyx_L1;} - __pyx_4 = PyFloat_FromDouble((__pyx_v_latsdata[__pyx_v_i])); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 64; goto __pyx_L1;} - __pyx_5 = PyNumber_Multiply(__pyx_2, __pyx_4); if (!__pyx_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 64; goto __pyx_L1;} - Py_DECREF(__pyx_2); __pyx_2 = 0; + /* "/Volumes/User/jwhitaker/python/pyproj/_geod.pyx":64 + * else: + * self.geodesic_t.p1.v = _dg2rad*lonsdata[i] + * self.geodesic_t.p1.u = _dg2rad*latsdata[i] # <<<<<<<<<<<<<< + * self.geodesic_t.ALPHA12 = _dg2rad*azdata[i] + * self.geodesic_t.DIST = distdata[i] + */ + __pyx_3 = __Pyx_GetName(__pyx_m, __pyx_n__dg2rad); if (unlikely(!__pyx_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 64; goto __pyx_L1;} + __pyx_4 = PyFloat_FromDouble((__pyx_v_latsdata[__pyx_v_i])); if (unlikely(!__pyx_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 64; goto __pyx_L1;} + __pyx_5 = PyNumber_Multiply(__pyx_3, __pyx_4); if (unlikely(!__pyx_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 64; goto __pyx_L1;} + Py_DECREF(__pyx_3); __pyx_3 = 0; Py_DECREF(__pyx_4); __pyx_4 = 0; - __pyx_7 = PyFloat_AsDouble(__pyx_5); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 64; goto __pyx_L1;} + __pyx_7 = PyFloat_AsDouble(__pyx_5); if (unlikely(PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 64; goto __pyx_L1;} Py_DECREF(__pyx_5); __pyx_5 = 0; ((struct __pyx_obj_5_geod_Geod *)__pyx_v_self)->geodesic_t.p1.u = __pyx_7; - /* "/Users/jsw/python/matplotlib/trunk/toolkits/basemap/src/_geod.pyx":65 */ - __pyx_2 = __Pyx_GetName(__pyx_m, __pyx_n__dg2rad); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 65; goto __pyx_L1;} - __pyx_4 = PyFloat_FromDouble((__pyx_v_azdata[__pyx_v_i])); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 65; goto __pyx_L1;} - __pyx_5 = PyNumber_Multiply(__pyx_2, __pyx_4); if (!__pyx_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 65; goto __pyx_L1;} - Py_DECREF(__pyx_2); __pyx_2 = 0; + /* "/Volumes/User/jwhitaker/python/pyproj/_geod.pyx":65 + * self.geodesic_t.p1.v = _dg2rad*lonsdata[i] + * self.geodesic_t.p1.u = _dg2rad*latsdata[i] + * self.geodesic_t.ALPHA12 = _dg2rad*azdata[i] # <<<<<<<<<<<<<< + * self.geodesic_t.DIST = distdata[i] + * geod_pre(&self.geodesic_t) + */ + __pyx_3 = __Pyx_GetName(__pyx_m, __pyx_n__dg2rad); if (unlikely(!__pyx_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 65; goto __pyx_L1;} + __pyx_4 = PyFloat_FromDouble((__pyx_v_azdata[__pyx_v_i])); if (unlikely(!__pyx_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 65; goto __pyx_L1;} + __pyx_5 = PyNumber_Multiply(__pyx_3, __pyx_4); if (unlikely(!__pyx_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 65; goto __pyx_L1;} + Py_DECREF(__pyx_3); __pyx_3 = 0; Py_DECREF(__pyx_4); __pyx_4 = 0; - __pyx_7 = PyFloat_AsDouble(__pyx_5); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 65; goto __pyx_L1;} + __pyx_7 = PyFloat_AsDouble(__pyx_5); if (unlikely(PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 65; goto __pyx_L1;} Py_DECREF(__pyx_5); __pyx_5 = 0; ((struct __pyx_obj_5_geod_Geod *)__pyx_v_self)->geodesic_t.ALPHA12 = __pyx_7; - /* "/Users/jsw/python/matplotlib/trunk/toolkits/basemap/src/_geod.pyx":66 */ + /* "/Volumes/User/jwhitaker/python/pyproj/_geod.pyx":66 + * self.geodesic_t.p1.u = _dg2rad*latsdata[i] + * self.geodesic_t.ALPHA12 = _dg2rad*azdata[i] + * self.geodesic_t.DIST = distdata[i] # <<<<<<<<<<<<<< + * geod_pre(&self.geodesic_t) + * if pj_errno != 0: + */ ((struct __pyx_obj_5_geod_Geod *)__pyx_v_self)->geodesic_t.DIST = (__pyx_v_distdata[__pyx_v_i]); } __pyx_L9:; - /* "/Users/jsw/python/matplotlib/trunk/toolkits/basemap/src/_geod.pyx":67 */ + /* "/Volumes/User/jwhitaker/python/pyproj/_geod.pyx":67 + * self.geodesic_t.ALPHA12 = _dg2rad*azdata[i] + * self.geodesic_t.DIST = distdata[i] + * geod_pre(&self.geodesic_t) # <<<<<<<<<<<<<< + * if pj_errno != 0: + * raise RuntimeError(pj_strerrno(pj_errno)) + */ geod_pre((&((struct __pyx_obj_5_geod_Geod *)__pyx_v_self)->geodesic_t)); - /* "/Users/jsw/python/matplotlib/trunk/toolkits/basemap/src/_geod.pyx":68 */ - __pyx_3 = (pj_errno != 0); - if (__pyx_3) { + /* "/Volumes/User/jwhitaker/python/pyproj/_geod.pyx":68 + * self.geodesic_t.DIST = distdata[i] + * geod_pre(&self.geodesic_t) + * if pj_errno != 0: # <<<<<<<<<<<<<< + * raise RuntimeError(pj_strerrno(pj_errno)) + * geod_for(&self.geodesic_t) + */ + __pyx_2 = (pj_errno != 0); + if (__pyx_2) { - /* "/Users/jsw/python/matplotlib/trunk/toolkits/basemap/src/_geod.pyx":69 */ - __pyx_2 = __Pyx_GetName(__pyx_b, __pyx_n_RuntimeError); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 69; goto __pyx_L1;} - __pyx_4 = PyString_FromString(pj_strerrno(pj_errno)); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 69; goto __pyx_L1;} - __pyx_5 = PyTuple_New(1); if (!__pyx_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 69; goto __pyx_L1;} - PyTuple_SET_ITEM(__pyx_5, 0, __pyx_4); - __pyx_4 = 0; - __pyx_4 = PyObject_CallObject(__pyx_2, __pyx_5); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 69; goto __pyx_L1;} - Py_DECREF(__pyx_2); __pyx_2 = 0; + /* "/Volumes/User/jwhitaker/python/pyproj/_geod.pyx":69 + * geod_pre(&self.geodesic_t) + * if pj_errno != 0: + * raise RuntimeError(pj_strerrno(pj_errno)) # <<<<<<<<<<<<<< + * geod_for(&self.geodesic_t) + * if pj_errno != 0: + */ + __pyx_3 = PyString_FromString(pj_strerrno(pj_errno)); if (unlikely(!__pyx_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 69; goto __pyx_L1;} + __pyx_4 = PyTuple_New(1); if (unlikely(!__pyx_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 69; goto __pyx_L1;} + PyTuple_SET_ITEM(__pyx_4, 0, __pyx_3); + __pyx_3 = 0; + __pyx_5 = PyObject_CallObject(__pyx_builtin_RuntimeError, __pyx_4); if (unlikely(!__pyx_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 69; goto __pyx_L1;} + Py_DECREF(__pyx_4); __pyx_4 = 0; + __Pyx_Raise(__pyx_5, 0, 0); Py_DECREF(__pyx_5); __pyx_5 = 0; - __Pyx_Raise(__pyx_4, 0, 0); - Py_DECREF(__pyx_4); __pyx_4 = 0; {__pyx_filename = __pyx_f[0]; __pyx_lineno = 69; goto __pyx_L1;} goto __pyx_L10; } __pyx_L10:; - /* "/Users/jsw/python/matplotlib/trunk/toolkits/basemap/src/_geod.pyx":70 */ + /* "/Volumes/User/jwhitaker/python/pyproj/_geod.pyx":70 + * if pj_errno != 0: + * raise RuntimeError(pj_strerrno(pj_errno)) + * geod_for(&self.geodesic_t) # <<<<<<<<<<<<<< + * if pj_errno != 0: + * raise RuntimeError(pj_strerrno(pj_errno)) + */ geod_for((&((struct __pyx_obj_5_geod_Geod *)__pyx_v_self)->geodesic_t)); - /* "/Users/jsw/python/matplotlib/trunk/toolkits/basemap/src/_geod.pyx":71 */ + /* "/Volumes/User/jwhitaker/python/pyproj/_geod.pyx":71 + * raise RuntimeError(pj_strerrno(pj_errno)) + * geod_for(&self.geodesic_t) + * if pj_errno != 0: # <<<<<<<<<<<<<< + * raise RuntimeError(pj_strerrno(pj_errno)) + * if isnan(self.geodesic_t.ALPHA21) == FP_NAN: + */ __pyx_1 = (pj_errno != 0); if (__pyx_1) { - /* "/Users/jsw/python/matplotlib/trunk/toolkits/basemap/src/_geod.pyx":72 */ - __pyx_2 = __Pyx_GetName(__pyx_b, __pyx_n_RuntimeError); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 72; goto __pyx_L1;} - __pyx_5 = PyString_FromString(pj_strerrno(pj_errno)); if (!__pyx_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 72; goto __pyx_L1;} - __pyx_4 = PyTuple_New(1); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 72; goto __pyx_L1;} - PyTuple_SET_ITEM(__pyx_4, 0, __pyx_5); - __pyx_5 = 0; - __pyx_5 = PyObject_CallObject(__pyx_2, __pyx_4); if (!__pyx_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 72; goto __pyx_L1;} - Py_DECREF(__pyx_2); __pyx_2 = 0; + /* "/Volumes/User/jwhitaker/python/pyproj/_geod.pyx":72 + * geod_for(&self.geodesic_t) + * if pj_errno != 0: + * raise RuntimeError(pj_strerrno(pj_errno)) # <<<<<<<<<<<<<< + * if isnan(self.geodesic_t.ALPHA21) == FP_NAN: + * raise ValueError('undefined forward geodesic (may be an equatorial arc)') + */ + __pyx_3 = PyString_FromString(pj_strerrno(pj_errno)); if (unlikely(!__pyx_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 72; goto __pyx_L1;} + __pyx_4 = PyTuple_New(1); if (unlikely(!__pyx_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 72; goto __pyx_L1;} + PyTuple_SET_ITEM(__pyx_4, 0, __pyx_3); + __pyx_3 = 0; + __pyx_5 = PyObject_CallObject(__pyx_builtin_RuntimeError, __pyx_4); if (unlikely(!__pyx_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 72; goto __pyx_L1;} Py_DECREF(__pyx_4); __pyx_4 = 0; __Pyx_Raise(__pyx_5, 0, 0); Py_DECREF(__pyx_5); __pyx_5 = 0; @@ -527,69 +806,121 @@ } __pyx_L11:; - /* "/Users/jsw/python/matplotlib/trunk/toolkits/basemap/src/_geod.pyx":73 */ - __pyx_3 = (isnan(((struct __pyx_obj_5_geod_Geod *)__pyx_v_self)->geodesic_t.ALPHA21) == FP_NAN); - if (__pyx_3) { + /* "/Volumes/User/jwhitaker/python/pyproj/_geod.pyx":73 + * if pj_errno != 0: + * raise RuntimeError(pj_strerrno(pj_errno)) + * if isnan(self.geodesic_t.ALPHA21) == FP_NAN: # <<<<<<<<<<<<<< + * raise ValueError('undefined forward geodesic (may be an equatorial arc)') + * if radians: + */ + __pyx_2 = (isnan(((struct __pyx_obj_5_geod_Geod *)__pyx_v_self)->geodesic_t.ALPHA21) == FP_NAN); + if (__pyx_2) { - /* "/Users/jsw/python/matplotlib/trunk/toolkits/basemap/src/_geod.pyx":74 */ - __pyx_2 = __Pyx_GetName(__pyx_b, __pyx_n_ValueError); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 74; goto __pyx_L1;} - __pyx_4 = PyTuple_New(1); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 74; goto __pyx_L1;} + /* "/Volumes/User/jwhitaker/python/pyproj/_geod.pyx":74 + * raise RuntimeError(pj_strerrno(pj_errno)) + * if isnan(self.geodesic_t.ALPHA21) == FP_NAN: + * raise ValueError('undefined forward geodesic (may be an equatorial arc)') # <<<<<<<<<<<<<< + * if radians: + * lonsdata[i] = self.geodesic_t.p2.v + */ + __pyx_3 = PyTuple_New(1); if (unlikely(!__pyx_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 74; goto __pyx_L1;} Py_INCREF(__pyx_k11p); - PyTuple_SET_ITEM(__pyx_4, 0, __pyx_k11p); - __pyx_5 = PyObject_CallObject(__pyx_2, __pyx_4); if (!__pyx_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 74; goto __pyx_L1;} - Py_DECREF(__pyx_2); __pyx_2 = 0; + PyTuple_SET_ITEM(__pyx_3, 0, __pyx_k11p); + __pyx_4 = PyObject_CallObject(__pyx_builtin_ValueError, __pyx_3); if (unlikely(!__pyx_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 74; goto __pyx_L1;} + Py_DECREF(__pyx_3); __pyx_3 = 0; + __Pyx_Raise(__pyx_4, 0, 0); Py_DECREF(__pyx_4); __pyx_4 = 0; - __Pyx_Raise(__pyx_5, 0, 0); - Py_DECREF(__pyx_5); __pyx_5 = 0; {__pyx_filename = __pyx_f[0]; __pyx_lineno = 74; goto __pyx_L1;} goto __pyx_L12; } __pyx_L12:; - /* "/Users/jsw/python/matplotlib/trunk/toolkits/basemap/src/_geod.pyx":75 */ - __pyx_1 = PyObject_IsTrue(__pyx_v_radians); if (__pyx_1 < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 75; goto __pyx_L1;} + /* "/Volumes/User/jwhitaker/python/pyproj/_geod.pyx":75 + * if isnan(self.geodesic_t.ALPHA21) == FP_NAN: + * raise ValueError('undefined forward geodesic (may be an equatorial arc)') + * if radians: # <<<<<<<<<<<<<< + * lonsdata[i] = self.geodesic_t.p2.v + * latsdata[i] = self.geodesic_t.p2.u + */ + __pyx_1 = PyObject_IsTrue(__pyx_v_radians); if (unlikely(__pyx_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 75; goto __pyx_L1;} if (__pyx_1) { - /* "/Users/jsw/python/matplotlib/trunk/toolkits/basemap/src/_geod.pyx":76 */ + /* "/Volumes/User/jwhitaker/python/pyproj/_geod.pyx":76 + * raise ValueError('undefined forward geodesic (may be an equatorial arc)') + * if radians: + * lonsdata[i] = self.geodesic_t.p2.v # <<<<<<<<<<<<<< + * latsdata[i] = self.geodesic_t.p2.u + * azdata[i] = self.geodesic_t.ALPHA21 + */ (__pyx_v_lonsdata[__pyx_v_i]) = ((struct __pyx_obj_5_geod_Geod *)__pyx_v_self)->geodesic_t.p2.v; - /* "/Users/jsw/python/matplotlib/trunk/toolkits/basemap/src/_geod.pyx":77 */ + /* "/Volumes/User/jwhitaker/python/pyproj/_geod.pyx":77 + * if radians: + * lonsdata[i] = self.geodesic_t.p2.v + * latsdata[i] = self.geodesic_t.p2.u # <<<<<<<<<<<<<< + * azdata[i] = self.geodesic_t.ALPHA21 + * else: + */ (__pyx_v_latsdata[__pyx_v_i]) = ((struct __pyx_obj_5_geod_Geod *)__pyx_v_self)->geodesic_t.p2.u; - /* "/Users/jsw/python/matplotlib/trunk/toolkits/basemap/src/_geod.pyx":78 */ + /* "/Volumes/User/jwhitaker/python/pyproj/_geod.pyx":78 + * lonsdata[i] = self.geodesic_t.p2.v + * latsdata[i] = self.geodesic_t.p2.u + * azdata[i] = self.geodesic_t.ALPHA21 # <<<<<<<<<<<<<< + * else: + * lonsdata[i] = _rad2dg*self.geodesic_t.p2.v + */ (__pyx_v_azdata[__pyx_v_i]) = ((struct __pyx_obj_5_geod_Geod *)__pyx_v_self)->geodesic_t.ALPHA21; goto __pyx_L13; } /*else*/ { - /* "/Users/jsw/python/matplotlib/trunk/toolkits/basemap/src/_geod.pyx":80 */ - __pyx_2 = __Pyx_GetName(__pyx_m, __pyx_n__rad2dg); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 80; goto __pyx_L1;} - __pyx_4 = PyFloat_FromDouble(((struct __pyx_obj_5_geod_Geod *)__pyx_v_self)->geodesic_t.p2.v); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 80; goto __pyx_L1;} - __pyx_5 = PyNumber_Multiply(__pyx_2, __pyx_4); if (!__pyx_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 80; goto __pyx_L1;} - Py_DECREF(__pyx_2); __pyx_2 = 0; + /* "/Volumes/User/jwhitaker/python/pyproj/_geod.pyx":80 + * azdata[i] = self.geodesic_t.ALPHA21 + * else: + * lonsdata[i] = _rad2dg*self.geodesic_t.p2.v # <<<<<<<<<<<<<< + * latsdata[i] = _rad2dg*self.geodesic_t.p2.u + * azdata[i] = _rad2dg*self.geodesic_t.ALPHA21 + */ + __pyx_5 = __Pyx_GetName(__pyx_m, __pyx_n__rad2dg); if (unlikely(!__pyx_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 80; goto __pyx_L1;} + __pyx_3 = PyFloat_FromDouble(((struct __pyx_obj_5_geod_Geod *)__pyx_v_self)->geodesic_t.p2.v); if (unlikely(!__pyx_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 80; goto __pyx_L1;} + __pyx_4 = PyNumber_Multiply(__pyx_5, __pyx_3); if (unlikely(!__pyx_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 80; goto __pyx_L1;} + Py_DECREF(__pyx_5); __pyx_5 = 0; + Py_DECREF(__pyx_3); __pyx_3 = 0; + __pyx_7 = PyFloat_AsDouble(__pyx_4); if (unlikely(PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 80; goto __pyx_L1;} Py_DECREF(__pyx_4); __pyx_4 = 0; - __pyx_7 = PyFloat_AsDouble(__pyx_5); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 80; goto __pyx_L1;} - Py_DECREF(__pyx_5); __pyx_5 = 0; (__pyx_v_lonsdata[__pyx_v_i]) = __pyx_7; - /* "/Users/jsw/python/matplotlib/trunk/toolkits/basemap/src/_geod.pyx":81 */ - __pyx_2 = __Pyx_GetName(__pyx_m, __pyx_n__rad2dg); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 81; goto __pyx_L1;} - __pyx_4 = PyFloat_FromDouble(((struct __pyx_obj_5_geod_Geod *)__pyx_v_self)->geodesic_t.p2.u); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 81; goto __pyx_L1;} - __pyx_5 = PyNumber_Multiply(__pyx_2, __pyx_4); if (!__pyx_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 81; goto __pyx_L1;} - Py_DECREF(__pyx_2); __pyx_2 = 0; + /* "/Volumes/User/jwhitaker/python/pyproj/_geod.pyx":81 + * else: + * lonsdata[i] = _rad2dg*self.geodesic_t.p2.v + * latsdata[i] = _rad2dg*self.geodesic_t.p2.u # <<<<<<<<<<<<<< + * azdata[i] = _rad2dg*self.geodesic_t.ALPHA21 + * + */ + __pyx_5 = __Pyx_GetName(__pyx_m, __pyx_n__rad2dg); if (unlikely(!__pyx_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 81; goto __pyx_L1;} + __pyx_3 = PyFloat_FromDouble(((struct __pyx_obj_5_geod_Geod *)__pyx_v_self)->geodesic_t.p2.u); if (unlikely(!__pyx_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 81; goto __pyx_L1;} + __pyx_4 = PyNumber_Multiply(__pyx_5, __pyx_3); if (unlikely(!__pyx_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 81; goto __pyx_L1;} + Py_DECREF(__pyx_5); __pyx_5 = 0; + Py_DECREF(__pyx_3); __pyx_3 = 0; + __pyx_7 = PyFloat_AsDouble(__pyx_4); if (unlikely(PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 81; goto __pyx_L1;} Py_DECREF(__pyx_4); __pyx_4 = 0; - __pyx_7 = PyFloat_AsDouble(__pyx_5); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 81; goto __pyx_L1;} - Py_DECREF(__pyx_5); __pyx_5 = 0; (__pyx_v_latsdata[__pyx_v_i]) = __pyx_7; - /* "/Users/jsw/python/matplotlib/trunk/toolkits/basemap/src/_geod.pyx":82 */ - __pyx_2 = __Pyx_GetName(__pyx_m, __pyx_n__rad2dg); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 82; goto __pyx_L1;} - __pyx_4 = PyFloat_FromDouble(((struct __pyx_obj_5_geod_Geod *)__pyx_v_self)->geodesic_t.ALPHA21); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 82; goto __pyx_L1;} - __pyx_5 = PyNumber_Multiply(__pyx_2, __pyx_4); if (!__pyx_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 82; goto __pyx_L1;} - Py_DECREF(__pyx_2); __pyx_2 = 0; + /* "/Volumes/User/jwhitaker/python/pyproj/_geod.pyx":82 + * lonsdata[i] = _rad2dg*self.geodesic_t.p2.v + * latsdata[i] = _rad2dg*self.geodesic_t.p2.u + * azdata[i] = _rad2dg*self.geodesic_t.ALPHA21 # <<<<<<<<<<<<<< + * + * def _inv(self, object lons1, object lats1, object lons2, object lats2, radians=False): + */ + __pyx_5 = __Pyx_GetName(__pyx_m, __pyx_n__rad2dg); if (unlikely(!__pyx_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 82; goto __pyx_L1;} + __pyx_3 = PyFloat_FromDouble(((struct __pyx_obj_5_geod_Geod *)__pyx_v_self)->geodesic_t.ALPHA21); if (unlikely(!__pyx_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 82; goto __pyx_L1;} + __pyx_4 = PyNumber_Multiply(__pyx_5, __pyx_3); if (unlikely(!__pyx_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 82; goto __pyx_L1;} + Py_DECREF(__pyx_5); __pyx_5 = 0; + Py_DECREF(__pyx_3); __pyx_3 = 0; + __pyx_7 = PyFloat_AsDouble(__pyx_4); if (unlikely(PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 82; goto __pyx_L1;} Py_DECREF(__pyx_4); __pyx_4 = 0; - __pyx_7 = PyFloat_AsDouble(__pyx_5); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 82; goto __pyx_L1;} - Py_DECREF(__pyx_5); __pyx_5 = 0; (__pyx_v_azdata[__pyx_v_i]) = __pyx_7; } __pyx_L13:; @@ -598,7 +929,7 @@ __pyx_r = Py_None; Py_INCREF(Py_None); goto __pyx_L0; __pyx_L1:; - Py_XDECREF(__pyx_2); + Py_XDECREF(__pyx_3); Py_XDECREF(__pyx_4); Py_XDECREF(__pyx_5); __Pyx_AddTraceback("_geod.Geod._fwd"); @@ -643,15 +974,15 @@ void (*__pyx_v_distdat); PyObject *__pyx_r; int __pyx_1; - PyObject *__pyx_2 = 0; - int __pyx_3; + int __pyx_2; + PyObject *__pyx_3 = 0; PyObject *__pyx_4 = 0; PyObject *__pyx_5 = 0; Py_ssize_t __pyx_6; double __pyx_7; static char *__pyx_argnames[] = {"lons1","lats1","lons2","lats2","radians",0}; __pyx_v_radians = __pyx_k4; - if (!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "OOOO|O", __pyx_argnames, &__pyx_v_lons1, &__pyx_v_lats1, &__pyx_v_lons2, &__pyx_v_lats2, &__pyx_v_radians)) return 0; + if (unlikely(!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "OOOO|O", __pyx_argnames, &__pyx_v_lons1, &__pyx_v_lats1, &__pyx_v_lons2, &__pyx_v_lats2, &__pyx_v_radians))) return 0; Py_INCREF(__pyx_v_self); Py_INCREF(__pyx_v_lons1); Py_INCREF(__pyx_v_lats1); @@ -659,59 +990,105 @@ Py_INCREF(__pyx_v_lats2); Py_INCREF(__pyx_v_radians); - /* "/Users/jsw/python/matplotlib/trunk/toolkits/basemap/src/_geod.pyx":94 */ + /* "/Volumes/User/jwhitaker/python/pyproj/_geod.pyx":94 + * cdef void *londata, *latdata, *azdat, *distdat + * # if buffer api is supported, get pointer to data buffers. + * if PyObject_AsWriteBuffer(lons1, &londata, &buflenlons) <> 0: # <<<<<<<<<<<<<< + * raise RuntimeError + * if PyObject_AsWriteBuffer(lats1, &latdata, &buflenlats) <> 0: + */ __pyx_1 = (PyObject_AsWriteBuffer(__pyx_v_lons1,(&__pyx_v_londata),(&__pyx_v_buflenlons)) != 0); if (__pyx_1) { - /* "/Users/jsw/python/matplotlib/trunk/toolkits/basemap/src/_geod.pyx":95 */ - __pyx_2 = __Pyx_GetName(__pyx_b, __pyx_n_RuntimeError); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 95; goto __pyx_L1;} - __Pyx_Raise(__pyx_2, 0, 0); - Py_DECREF(__pyx_2); __pyx_2 = 0; + /* "/Volumes/User/jwhitaker/python/pyproj/_geod.pyx":95 + * # if buffer api is supported, get pointer to data buffers. + * if PyObject_AsWriteBuffer(lons1, &londata, &buflenlons) <> 0: + * raise RuntimeError # <<<<<<<<<<<<<< + * if PyObject_AsWriteBuffer(lats1, &latdata, &buflenlats) <> 0: + * raise RuntimeError + */ + __Pyx_Raise(__pyx_builtin_RuntimeError, 0, 0); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 95; goto __pyx_L1;} goto __pyx_L2; } __pyx_L2:; - /* "/Users/jsw/python/matplotlib/trunk/toolkits/basemap/src/_geod.pyx":96 */ + /* "/Volumes/User/jwhitaker/python/pyproj/_geod.pyx":96 + * if PyObject_AsWriteBuffer(lons1, &londata, &buflenlons) <> 0: + * raise RuntimeError + * if PyObject_AsWriteBuffer(lats1, &latdata, &buflenlats) <> 0: # <<<<<<<<<<<<<< + * raise RuntimeError + * if PyObject_AsWriteBuffer(lons2, &azdat, &buflenaz) <> 0: + */ __pyx_1 = (PyObject_AsWriteBuffer(__pyx_v_... [truncated message content] |
From: <md...@us...> - 2007-08-31 15:40:46
|
Revision: 3762 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=3762&view=rev Author: mdboom Date: 2007-08-31 08:40:42 -0700 (Fri, 31 Aug 2007) Log Message: ----------- Oops in last commit. Modified Paths: -------------- trunk/matplotlib/lib/matplotlib/backends/backend_agg.py Modified: trunk/matplotlib/lib/matplotlib/backends/backend_agg.py =================================================================== --- trunk/matplotlib/lib/matplotlib/backends/backend_agg.py 2007-08-31 15:09:27 UTC (rev 3761) +++ trunk/matplotlib/lib/matplotlib/backends/backend_agg.py 2007-08-31 15:40:42 UTC (rev 3762) @@ -172,7 +172,7 @@ """ if __debug__: verbose.report('RendererAgg.draw_mathtext', 'debug-annoying') - ox, oy, width, height, descent, font_image, used_characters = \ + ox, oy, width, height, descent, fonts, used_characters = \ self.mathtext_parser.parse(s, self.dpi.get(), prop) if angle == 90: @@ -183,9 +183,10 @@ else: x = int(x) + ox y = int(y) - height + oy - if angle == 90: - font_image.rotate() # <-- Rotate 90 deg - self._renderer.draw_text_image(font_image, x, y + 1, gc) + for font in fonts: + if angle == 90: + font.horiz_image_to_vert_image() # <-- Rotate + self._renderer.draw_text( font, x, y + 1, gc) if 0: self._renderer.draw_rectangle(gc, None, int(x), @@ -211,7 +212,7 @@ #print x, y, int(x), int(y) - self._renderer.draw_text_image(font.get_image(), int(x), int(y) + 1, gc) + self._renderer.draw_text(font, int(x), int(y) + 1, gc) def get_text_width_height_descent(self, s, prop, ismath, rgb=(0,0,0)): @@ -232,7 +233,7 @@ return n,m if ismath: - ox, oy, width, height, descent, font_image, used_characters = \ + ox, oy, width, height, descent, fonts, used_characters = \ self.mathtext_parser.parse(s, self.dpi.get(), prop) return width, height, descent font = self._get_agg_font(prop) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <md...@us...> - 2007-08-31 15:09:38
|
Revision: 3761 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=3761&view=rev Author: mdboom Date: 2007-08-31 08:09:27 -0700 (Fri, 31 Aug 2007) Log Message: ----------- Fix typo. Modified Paths: -------------- trunk/matplotlib/lib/matplotlib/backends/backend_agg.py Modified: trunk/matplotlib/lib/matplotlib/backends/backend_agg.py =================================================================== --- trunk/matplotlib/lib/matplotlib/backends/backend_agg.py 2007-08-30 19:14:55 UTC (rev 3760) +++ trunk/matplotlib/lib/matplotlib/backends/backend_agg.py 2007-08-31 15:09:27 UTC (rev 3761) @@ -172,7 +172,7 @@ """ if __debug__: verbose.report('RendererAgg.draw_mathtext', 'debug-annoying') - ox, oy, width, height, descent, fonts, used_characters = \ + ox, oy, width, height, descent, font_image, used_characters = \ self.mathtext_parser.parse(s, self.dpi.get(), prop) if angle == 90: @@ -183,10 +183,9 @@ else: x = int(x) + ox y = int(y) - height + oy - for font in fonts: - if angle == 90: - font.horiz_image_to_vert_image() # <-- Rotate - self._renderer.draw_text( font, x, y + 1, gc) + if angle == 90: + font_image.rotate() # <-- Rotate 90 deg + self._renderer.draw_text_image(font_image, x, y + 1, gc) if 0: self._renderer.draw_rectangle(gc, None, int(x), @@ -212,7 +211,7 @@ #print x, y, int(x), int(y) - self._renderer.draw_text(font, int(x), int(y) + 1, gc) + self._renderer.draw_text_image(font.get_image(), int(x), int(y) + 1, gc) def get_text_width_height_descent(self, s, prop, ismath, rgb=(0,0,0)): @@ -233,9 +232,9 @@ return n,m if ismath: - ox, oy, width, height, descent, fonts, used_characters = \ + ox, oy, width, height, descent, font_image, used_characters = \ self.mathtext_parser.parse(s, self.dpi.get(), prop) - return width, height, depth + return width, height, descent font = self._get_agg_font(prop) font.set_text(s, 0.0, flags=LOAD_DEFAULT) # the width and height of unrotated string w, h = font.get_width_height() This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <md...@us...> - 2007-08-30 19:15:39
|
Revision: 3760 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=3760&view=rev Author: mdboom Date: 2007-08-30 12:14:55 -0700 (Thu, 30 Aug 2007) Log Message: ----------- Add valignment = 'baseline' feature to align text by its baseline. Modified Paths: -------------- trunk/matplotlib/lib/matplotlib/afm.py trunk/matplotlib/lib/matplotlib/backend_bases.py trunk/matplotlib/lib/matplotlib/backends/backend_agg.py trunk/matplotlib/lib/matplotlib/backends/backend_cairo.py trunk/matplotlib/lib/matplotlib/backends/backend_gd.py trunk/matplotlib/lib/matplotlib/backends/backend_gdk.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/backends/backend_template.py trunk/matplotlib/lib/matplotlib/backends/backend_wx.py trunk/matplotlib/lib/matplotlib/mathtext.py trunk/matplotlib/lib/matplotlib/text.py Modified: trunk/matplotlib/lib/matplotlib/afm.py =================================================================== --- trunk/matplotlib/lib/matplotlib/afm.py 2007-08-30 15:32:25 UTC (rev 3759) +++ trunk/matplotlib/lib/matplotlib/afm.py 2007-08-30 19:14:55 UTC (rev 3760) @@ -334,7 +334,7 @@ return totalw, maxy-miny - def get_str_bbox(self, s): + def get_str_bbox_and_descent(self, s): """ Return the string bounding box """ @@ -369,9 +369,15 @@ thismin = b if thismin<miny: miny = thismin - return left, miny, totalw, maxy-miny + return left, miny, totalw, maxy-miny, -miny + def get_str_bbox(self, s): + """ + Return the string bounding box + """ + return self.get_str_bbox_and_descent(s)[:4] + def get_name_char(self, c): """ Get the name of the character, ie, ';' is 'semicolon' Modified: trunk/matplotlib/lib/matplotlib/backend_bases.py =================================================================== --- trunk/matplotlib/lib/matplotlib/backend_bases.py 2007-08-30 15:32:25 UTC (rev 3759) +++ trunk/matplotlib/lib/matplotlib/backend_bases.py 2007-08-30 19:14:55 UTC (rev 3760) @@ -421,12 +421,13 @@ """ return transforms.lbwh_to_bbox(0,0,1,1) # your values here - def get_text_width_height(self, s, prop, ismath): + def get_text_width_height_descent(self, s, prop, ismath): """ - get the width and height in display coords of the string s - with FontPropertry prop + get the width and height, and the offset from the bottom to the + baseline (descent), in display coords of the string s with + FontPropertry prop """ - return 1,1 + return 1,1,1 def new_gc(self): """ Modified: trunk/matplotlib/lib/matplotlib/backends/backend_agg.py =================================================================== --- trunk/matplotlib/lib/matplotlib/backends/backend_agg.py 2007-08-30 15:32:25 UTC (rev 3759) +++ trunk/matplotlib/lib/matplotlib/backends/backend_agg.py 2007-08-30 19:14:55 UTC (rev 3760) @@ -172,7 +172,7 @@ """ if __debug__: verbose.report('RendererAgg.draw_mathtext', 'debug-annoying') - ox, oy, width, height, fonts, used_characters = \ + ox, oy, width, height, descent, fonts, used_characters = \ self.mathtext_parser.parse(s, self.dpi.get(), prop) if angle == 90: @@ -186,7 +186,7 @@ for font in fonts: if angle == 90: font.horiz_image_to_vert_image() # <-- Rotate - self._renderer.draw_text( font, x, y, gc) + self._renderer.draw_text( font, x, y + 1, gc) if 0: self._renderer.draw_rectangle(gc, None, int(x), @@ -212,10 +212,10 @@ #print x, y, int(x), int(y) - self._renderer.draw_text(font, int(x), int(y), gc) + self._renderer.draw_text(font, int(x), int(y) + 1, gc) - def get_text_width_height(self, s, prop, ismath, rgb=(0,0,0)): + def get_text_width_height_descent(self, s, prop, ismath, rgb=(0,0,0)): """ get the width and height in display coords of the string s with FontPropertry prop @@ -233,15 +233,17 @@ return n,m if ismath: - ox, oy, width, height, fonts, used_characters = \ + ox, oy, width, height, descent, fonts, used_characters = \ self.mathtext_parser.parse(s, self.dpi.get(), prop) - return width, height + return width, height, depth font = self._get_agg_font(prop) font.set_text(s, 0.0, flags=LOAD_DEFAULT) # the width and height of unrotated string w, h = font.get_width_height() + d = font.get_descent() w /= 64.0 # convert from subpixels h /= 64.0 - return w, h + d /= 64.0 + return w, h, d def draw_tex(self, gc, x, y, s, prop, angle): # todo, handle props, angle, origins @@ -250,7 +252,7 @@ dpi = self.dpi.get() flip = angle==90 - w,h = self.get_text_width_height(s, prop, 'TeX', rgb) + w,h,d = self.get_text_width_height_descent(s, prop, 'TeX', rgb) if flip: w,h = h,w x -= w Modified: trunk/matplotlib/lib/matplotlib/backends/backend_cairo.py =================================================================== --- trunk/matplotlib/lib/matplotlib/backends/backend_cairo.py 2007-08-30 15:32:25 UTC (rev 3759) +++ trunk/matplotlib/lib/matplotlib/backends/backend_cairo.py 2007-08-30 19:14:55 UTC (rev 3760) @@ -304,7 +304,7 @@ if _debug: print '%s.%s()' % (self.__class__.__name__, _fn_name()) ctx = gc.ctx - width, height, glyphs, rects = self.mathtext_parser.parse( + width, height, descent, glyphs, rects = self.mathtext_parser.parse( s, self.dpi.get(), prop) ctx.save() @@ -349,12 +349,12 @@ return self.width, self.height - def get_text_width_height(self, s, prop, ismath): + def get_text_width_height_descent(self, s, prop, ismath): if _debug: print '%s.%s()' % (self.__class__.__name__, _fn_name()) if ismath: - width, height, fonts, used_characters = self.mathtext_parser.parse( + width, height, descent, fonts, used_characters = self.mathtext_parser.parse( s, self.dpi.get(), prop) - return width, height + return width, height, descent ctx = self.text_ctx ctx.save() @@ -373,10 +373,10 @@ # save/restore prevents the problem ctx.set_font_size (size) - w, h = ctx.text_extents (s)[2:4] + y_bearing, w, h = ctx.text_extents (s)[1:4] ctx.restore() - return w, h + return w, h, h + y_bearing def new_gc(self): Modified: trunk/matplotlib/lib/matplotlib/backends/backend_gd.py =================================================================== --- trunk/matplotlib/lib/matplotlib/backends/backend_gd.py 2007-08-30 15:32:25 UTC (rev 3759) +++ trunk/matplotlib/lib/matplotlib/backends/backend_gd.py 2007-08-30 19:14:55 UTC (rev 3760) @@ -59,7 +59,7 @@ 'return the canvas width and height in display coords' return self.width, self.height - def get_text_width_height(self, s, prop, ismath): + def get_text_width_height_descent(self, s, prop, ismath): """ get the width and height in display coords of the string s with fontsize in points @@ -78,7 +78,7 @@ w = abs(lrx - llx) h = abs(lly - uly) - return w, h + return w, h, h def flipy(self): Modified: trunk/matplotlib/lib/matplotlib/backends/backend_gdk.py =================================================================== --- trunk/matplotlib/lib/matplotlib/backends/backend_gdk.py 2007-08-30 15:32:25 UTC (rev 3759) +++ trunk/matplotlib/lib/matplotlib/backends/backend_gdk.py 2007-08-30 19:14:55 UTC (rev 3760) @@ -199,7 +199,7 @@ def _draw_mathtext(self, gc, x, y, s, prop, angle): - width, height, fonts, used_characters = self.mathtext_parser.parse( + width, height, descent, fonts, used_characters = self.mathtext_parser.parse( s, self.dpi.get(), prop) if angle==90: @@ -340,15 +340,15 @@ def get_canvas_width_height(self): return self.width, self.height - def get_text_width_height(self, s, prop, ismath): + def get_text_width_height_descent(self, s, prop, ismath): if ismath: - width, height, fonts, used_characters = self.mathtext_parser.parse( + width, height, descent, fonts, used_characters = self.mathtext_parser.parse( s, self.dpi.get(), prop) - return width, height + return width, height, descent layout, inkRect, logicalRect = self._get_pango_layout(s, prop) l, b, w, h = inkRect - return w, h+1 + return w, h+1, h + 1 def new_gc(self): return GraphicsContextGDK(renderer=self) Modified: trunk/matplotlib/lib/matplotlib/backends/backend_pdf.py =================================================================== --- trunk/matplotlib/lib/matplotlib/backends/backend_pdf.py 2007-08-30 15:32:25 UTC (rev 3759) +++ trunk/matplotlib/lib/matplotlib/backends/backend_pdf.py 2007-08-30 19:14:55 UTC (rev 3760) @@ -1224,7 +1224,7 @@ def draw_mathtext(self, gc, x, y, s, prop, angle): # TODO: fix positioning and encoding - width, height, glyphs, rects, used_characters = \ + width, height, descent, glyphs, rects, used_characters = \ self.mathtext_parser.parse(s, 72, prop) self.merge_used_characters(used_characters) @@ -1465,31 +1465,28 @@ else: return draw_text_woven(chunks) - def get_text_width_height(self, s, prop, ismath): - # FT2Font can handle unicode, and so can we - # if isinstance(s, unicode): - # s = s.encode('cp1252', 'replace') - + def get_text_width_height_descent(self, s, prop, ismath): if ismath: - w, h, glyphs, rects, used_characters = \ + w, h, d, glyphs, rects, used_characters = \ self.mathtext_parser.parse(s, 72, prop) elif rcParams['pdf.use14corefonts']: font = self._get_font_afm(prop) - l, b, w, h = font.get_str_bbox(s) - fontsize = prop.get_size_in_points() - w *= fontsize / 1000 - h *= fontsize / 1000 - + l, b, w, h, d = font.get_str_bbox_and_descent(s) + scale = prop.get_size_in_points() / 1000.0 + w *= scale + h *= scale + d *= scale else: font = self._get_font_ttf(prop) font.set_text(s, 0.0, flags=LOAD_NO_HINTING) w, h = font.get_width_height() w /= 64.0 h /= 64.0 + d = font.get_descent() + d /= 64.0 + return w, h, d - return w, h - def _get_font_afm(self, prop): key = hash(prop) font = self.afm_font_cache.get(key) Modified: trunk/matplotlib/lib/matplotlib/backends/backend_ps.py =================================================================== --- trunk/matplotlib/lib/matplotlib/backends/backend_ps.py 2007-08-30 15:32:25 UTC (rev 3759) +++ trunk/matplotlib/lib/matplotlib/backends/backend_ps.py 2007-08-30 19:14:55 UTC (rev 3760) @@ -263,7 +263,7 @@ 'return the canvas width and height in display coords' return self.width, self.height - def get_text_width_height(self, s, prop, ismath): + def get_text_width_height_descent(self, s, prop, ismath): """ get the width and height in display coords of the string s with FontPropertry prop @@ -276,30 +276,36 @@ w = (r-l) h = (t-b) #print s, w, h - return w, h + # TODO: We need a way to get a good baseline from + # text.usetex + return w, h, h if ismath: - width, height, pswriter, used_characters = \ + width, height, descent, pswriter, used_characters = \ self.mathtext_parser.parse(s, 72, prop) - return width, height + return width, height, descent if rcParams['ps.useafm']: if ismath: s = s[1:-1] font = self._get_font_afm(prop) - l,b,w,h = font.get_str_bbox(s) + l,b,w,h,d = font.get_str_bbox_and_descent(s) fontsize = prop.get_size_in_points() - w *= 0.001*fontsize - h *= 0.001*fontsize - return w, h + scale = 0.001*fontsize + w *= scale + h *= scale + d *= scale + return w, h, d font = self._get_font_ttf(prop) 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 + d = font.get_descent() + d /= 64.0 #print s, w, h - return w, h + return w, h, d def flipy(self): 'return true if small y numbers are top for renderer' @@ -661,7 +667,7 @@ """ draw a Text instance """ - w, h = self.get_text_width_height(s, prop, ismath) + w, h, bl = self.get_text_width_height_baseline(s, prop, ismath) fontsize = prop.get_size_in_points() corr = 0#w/2*(fontsize-10)/10 pos = _nums_to_str(x-corr, y) @@ -857,7 +863,7 @@ if debugPS: self._pswriter.write("% mathtext\n") - width, height, pswriter, used_characters = \ + width, height, descent, pswriter, used_characters = \ self.mathtext_parser.parse(s, 72, prop) self.merge_used_characters(used_characters) self.set_color(*gc.get_rgb()) Modified: trunk/matplotlib/lib/matplotlib/backends/backend_svg.py =================================================================== --- trunk/matplotlib/lib/matplotlib/backends/backend_svg.py 2007-08-30 15:32:25 UTC (rev 3759) +++ trunk/matplotlib/lib/matplotlib/backends/backend_svg.py 2007-08-30 19:14:55 UTC (rev 3760) @@ -232,7 +232,7 @@ def draw_rectangle(self, gc, rgbFace, x, y, width, height): details = 'width="%f" height="%f" x="%f" y="%f"' % (width, height, x, - self.height-y-height) + self.height-y-height) self._draw_svg_element('rect', details, gc, rgbFace) def draw_text(self, gc, x, y, s, prop, angle, ismath): @@ -241,7 +241,9 @@ return font = self._get_font(prop) - + font.set_text(s, 0.0, flags=LOAD_NO_HINTING) + y -= font.get_descent() / 64.0 + thetext = escape_xml_text(s) fontfamily = font.family_name fontstyle = font.style_name @@ -277,7 +279,7 @@ currx += kern/64.0 svg.append('<use xlink:href="#%s" transform="translate(%s)"/>\n' - % (charid, currx)) + % (charid, currx * (self.FONT_SCALE / fontsize))) currx += (glyph.linearHoriAdvance / 65536.0) svg.append('</g>\n') @@ -338,7 +340,7 @@ """ Draw math text using matplotlib.mathtext """ - width, height, svg_elements, used_characters = \ + width, height, descent, svg_elements, used_characters = \ self.mathtext_parser.parse(s, 72, prop) svg_glyphs = svg_elements.svg_glyphs svg_rects = svg_elements.svg_rects @@ -426,17 +428,19 @@ def get_canvas_width_height(self): return self.width, self.height - def get_text_width_height(self, s, prop, ismath): + def get_text_width_height_descent(self, s, prop, ismath): if ismath: - width, height, trash, used_characters = \ + width, height, descent, trash, used_characters = \ self.mathtext_parser.parse(s, 72, prop) - return width, height + return width, height, descent font = self._get_font(prop) 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 - return w, h + d = font.get_descent() + d /= 64.0 + return w, h, d class FigureCanvasSVG(FigureCanvasBase): Modified: trunk/matplotlib/lib/matplotlib/backends/backend_template.py =================================================================== --- trunk/matplotlib/lib/matplotlib/backends/backend_template.py 2007-08-30 15:32:25 UTC (rev 3759) +++ trunk/matplotlib/lib/matplotlib/backends/backend_template.py 2007-08-30 19:14:55 UTC (rev 3760) @@ -93,8 +93,8 @@ def get_canvas_width_height(self): return 100, 100 - def get_text_width_height(self, s, prop, ismath): - return 1, 1 + def get_text_width_height_descent(self, s, prop, ismath): + return 1, 1, 1 def new_gc(self): return GraphicsContextTemplate() Modified: trunk/matplotlib/lib/matplotlib/backends/backend_wx.py =================================================================== --- trunk/matplotlib/lib/matplotlib/backends/backend_wx.py 2007-08-30 15:32:25 UTC (rev 3759) +++ trunk/matplotlib/lib/matplotlib/backends/backend_wx.py 2007-08-30 19:14:55 UTC (rev 3760) @@ -253,7 +253,7 @@ def offset_text_height(self): return True - def get_text_width_height(self, s, prop, ismath): + def get_text_width_height_descent(self, s, prop, ismath): """ get the width and height in display coords of the string s with FontPropertry prop @@ -264,9 +264,9 @@ if self.gc is None: gc = self.new_gc() font = self.get_wx_font(s, prop) self.gc.SetFont(font) - w, h = self.gc.GetTextExtent(s) + w, h, descent, leading = self.gc.GetFullTextExtent(s) - return w, h + return w, h, descent def get_canvas_width_height(self): 'return the canvas width and height in display coords' @@ -376,7 +376,7 @@ gc.SetFont(font) assert gc.Ok(), "wxMemoryDC not OK to use" - w, h = self.get_text_width_height(s, prop, ismath) + w, h, d = self.get_text_width_height_descent(s, prop, ismath) x = int(x) y = int(y-h) Modified: trunk/matplotlib/lib/matplotlib/mathtext.py =================================================================== --- trunk/matplotlib/lib/matplotlib/mathtext.py 2007-08-30 15:32:25 UTC (rev 3759) +++ trunk/matplotlib/lib/matplotlib/mathtext.py 2007-08-30 19:14:55 UTC (rev 3760) @@ -217,10 +217,11 @@ def __init__(self): self.fonts_object = None - def set_canvas_size(self, w, h): + def set_canvas_size(self, w, h, d): 'Dimension the drawing canvas; may be a noop' self.width = w self.height = h + self.depth = d def render_glyph(self, ox, oy, info): raise NotImplementedError() @@ -261,12 +262,16 @@ self._update_bbox(x1, y1, x2, y2) def get_results(self, box): + orig_height = box.height + orig_depth = box.depth ship(0, 0, box) bbox = self.bbox - bbox = [bbox[0] - 2, bbox[1] - 2, bbox[2] + 2, bbox[3] + 2] + bbox = [bbox[0] - 1, bbox[1] - 1, bbox[2] + 1, bbox[3] + 1] self._switch_to_real_backend() self.fonts_object.set_canvas_size( - bbox[2] - bbox[0], bbox[3] - bbox[1]) + bbox[2] - bbox[0], + (bbox[3] - bbox[1]) - orig_depth, + (bbox[3] - bbox[1]) - orig_height) ship(-bbox[0], -bbox[1], box) return self.fonts_object.get_results(box) @@ -285,10 +290,10 @@ self.oy = 0 MathtextBackend.__init__(self) - def set_canvas_size(self, w, h): - MathtextBackend.set_canvas_size(self, w, h) + def set_canvas_size(self, w, h, d): + MathtextBackend.set_canvas_size(self, w, h, d) for font in self.fonts_object.get_fonts(): - font.set_bitmap_size(int(w), int(h)) + font.set_bitmap_size(int(w), int(h) + int(d)) def render_glyph(self, ox, oy, info): info.font.draw_glyph_to_bitmap( @@ -302,7 +307,8 @@ return (self.ox, self.oy, self.width, - self.height, + self.height + self.depth, + self.depth, self.fonts_object.get_fonts(), self.fonts_object.get_used_characters()) @@ -341,9 +347,11 @@ self.pswriter.write(ps) def get_results(self, box): - ship(0, 0, box) + ship(0, -self.depth, box) + print self.depth return (self.width, - self.height, + self.height + self.depth, + self.depth, self.pswriter, self.fonts_object.get_used_characters()) @@ -363,9 +371,10 @@ self.rects.append((x1, self.height - y2, x2 - x1, y2 - y1)) def get_results(self, box): - ship(0, 0, box) + ship(0, -self.depth, box) return (self.width, - self.height, + self.height + self.depth, + self.depth, self.glyphs, self.rects, self.fonts_object.get_used_characters()) @@ -386,11 +395,12 @@ (x1, self.height - y1 + 1, x2 - x1, y2 - y1)) def get_results(self, box): - ship(0, 0, box) + ship(0, -self.depth, box) svg_elements = Bunch(svg_glyphs = self.svg_glyphs, svg_rects = self.svg_rects) return (self.width, - self.height, + self.height + self.depth, + self.depth, svg_elements, self.fonts_object.get_used_characters()) @@ -410,9 +420,10 @@ (x1, y1 - self.height, x2 - x1, y2 - y1)) def get_results(self, box): - ship(0, 0, box) + ship(0, -self.depth, box) return (self.width, - self.height, + self.height + self.depth, + self.depth, self.glyphs, self.rects) @@ -477,10 +488,10 @@ info = self._get_info(font, sym, fontsize, dpi) return info.metrics - def set_canvas_size(self, w, h): + def set_canvas_size(self, w, h, d): 'Dimension the drawing canvas; may be a noop' - self.width, self.height = ceil(w), ceil(h) - self.mathtext_backend.set_canvas_size(self.width, self.height) + self.width, self.height, self.depth = ceil(w), ceil(h), ceil(d) + self.mathtext_backend.set_canvas_size(self.width, self.height, self.depth) def render_glyph(self, ox, oy, facename, sym, fontsize, dpi): info = self._get_info(facename, sym, fontsize, dpi) @@ -2447,7 +2458,6 @@ cacheKey = (s, dpi, hash(prop)) result = self._cache.get(cacheKey) if result is not None: - del self._cache[cacheKey] return result if self._output == 'PS' and rcParams['ps.useafm']: @@ -2467,8 +2477,7 @@ self.__class__._parser = Parser() box = self._parser.parse(s, font_output, fontsize, dpi) - w, h = box.width, box.height + box.depth - font_output.set_canvas_size(w, h) + font_output.set_canvas_size(box.width, box.height, box.depth) result = font_output.get_results(box) self._cache[cacheKey] = result # Free up the transient data structures Modified: trunk/matplotlib/lib/matplotlib/text.py =================================================================== --- trunk/matplotlib/lib/matplotlib/text.py 2007-08-30 15:32:25 UTC (rev 3759) +++ trunk/matplotlib/lib/matplotlib/text.py 2007-08-30 19:14:55 UTC (rev 3760) @@ -20,54 +20,6 @@ import matplotlib.nxutils as nxutils -def scanner(s): - """ - Split a string into mathtext and non-mathtext parts. mathtext is - surrounded by $ symbols. quoted \$ are ignored - - All slash quotes dollar signs are ignored - - The number of unquoted dollar signs must be even - - Return value is a list of (substring, inmath) tuples - """ - if not len(s): return [(s, False)] - #print 'testing', s, type(s) - inddollar, = npy.nonzero(npy.asarray(npy.equal(s,'$'))) - quoted = dict([ (ind,1) for ind in npy.nonzero(npy.asarray(npy.equal(s,'\\')))[0]]) - indkeep = [ind for ind in inddollar if not quoted.has_key(ind-1)] - if len(indkeep)==0: - return [(s, False)] - if len(indkeep)%2: - raise ValueError('Illegal string "%s" (must have balanced dollar signs)'%s) - - Ns = len(s) - - indkeep = [ind for ind in indkeep] - # make sure we start with the first element - if indkeep[0]!=0: indkeep.insert(0,0) - # and end with one past the end of the string - indkeep.append(Ns+1) - - Nkeep = len(indkeep) - results = [] - - inmath = s[0] == '$' - for i in range(Nkeep-1): - i0, i1 = indkeep[i], indkeep[i+1] - if not inmath: - if i0>0: i0 +=1 - else: - i1 += 1 - if i0>=Ns: break - - results.append((s[i0:i1], inmath)) - inmath = not inmath - - return results - - - def _process_text_args(override, fontdict=None, **kwargs): "Return an override dict. See 'text' docstring for info" @@ -117,7 +69,7 @@ text: string transform: a matplotlib.transform transformation instance variant: [ 'normal' | 'small-caps' ] - verticalalignment or va: [ 'center' | 'top' | 'bottom' ] + verticalalignment or va: [ 'center' | 'top' | 'bottom' | 'baseline' ] visible: [True | False] weight or fontweight: [ 'normal' | 'bold' | 'heavy' | 'light' | 'ultrabold' | 'ultralight'] x: float @@ -130,9 +82,6 @@ Handle storing and drawing of text in window or data coordinates """ - # special case superscripting to speedup logplots - _rgxsuper = re.compile('\$([\-+0-9]+)\^\{(-?[0-9]+)\}\$') - zorder = 3 def __str__(self): return "Text(%g,%g,%s)"%(self._y,self._y,self._text) @@ -237,21 +186,21 @@ height = 0 xmin, ymin = thisx, thisy - if self.is_math_text(): - lines = [self._text] - else: - lines = self._text.split('\n') + lines = self._text.split('\n') whs = [] # Find full vertical extent of font, # including ascenders and descenders: - tmp, heightt = renderer.get_text_width_height( + tmp, heightt, bl = renderer.get_text_width_height_descent( 'lp', self._fontproperties, ismath=False) offsety = heightt * self._linespacing + baseline = None for line in lines: - w,h = renderer.get_text_width_height( - line, self._fontproperties, ismath=self.is_math_text()) + w, h, d = renderer.get_text_width_height_descent( + line, self._fontproperties, ismath=self.is_math_text(line)) + if baseline is None: + baseline = h - d whs.append( (w,h) ) horizLayout.append((line, thisx, thisy, w, h)) thisy -= offsety @@ -307,6 +256,7 @@ if valign=='center': offsety = ty - (ymin + height/2.0) elif valign=='top': offsety = ty - (ymin + height) + elif valign=='baseline': offsety = ty - (ymin + height) + baseline else: offsety = ty - ymin xmin += offsetx @@ -364,49 +314,9 @@ bbox_artist(self, renderer, self._bbox) angle = self.get_rotation() - ismath = self.is_math_text() - - if angle==0: - #print 'text', self._text - if ismath=='TeX': m = None - else: m = self._rgxsuper.match(self._text) - if m is not None: - bbox, info = self._get_layout_super(self._renderer, m) - base, xt, yt = info[0] - renderer.draw_text(gc, xt, yt, base, - self._fontproperties, angle, - ismath=False) - - exponent, xt, yt, fp = info[1] - renderer.draw_text(gc, xt, yt, exponent, - fp, angle, - ismath=False) - return - - - if len(self._substrings)>1: - # embedded mathtext - thisx, thisy = self._get_xy_display() - - for s,ismath in self._substrings: - w, h = renderer.get_text_width_height( - s, self._fontproperties, ismath) - - renderx, rendery = thisx, thisy - if renderer.flipy(): - canvasw, canvash = renderer.get_canvas_width_height() - rendery = canvash-rendery - - renderer.draw_text(gc, renderx, rendery, s, - self._fontproperties, angle, - ismath) - thisx += w - - - return bbox, info = self._get_layout(renderer) trans = self.get_transform() - if ismath=='TeX': + if rcParams['text.usetex']: canvasw, canvash = renderer.get_canvas_width_height() for line, wh, x, y in info: x, y = trans.xy_tup((x, y)) @@ -426,7 +336,7 @@ renderer.draw_text(gc, x, y, line, self._fontproperties, angle, - ismath=self.is_math_text()) + ismath=self.is_math_text(line)) def get_color(self): "Return the color of the text" @@ -523,13 +433,6 @@ raise RuntimeError('Cannot get window extent w/o renderer') angle = self.get_rotation() - if angle==0: - ismath = self.is_math_text() - if ismath=='TeX': m = None - else: m = self._rgxsuper.match(self._text) - if m is not None: - bbox, tmp = self._get_layout_super(self._renderer, m) - return bbox bbox, info = self._get_layout(self._renderer) return bbox @@ -734,9 +637,9 @@ """ Set the vertical alignment - ACCEPTS: [ 'center' | 'top' | 'bottom' ] + ACCEPTS: [ 'center' | 'top' | 'bottom' | 'baseline' ] """ - legal = ('top', 'bottom', 'center') + legal = ('top', 'bottom', 'center', 'baseline') if align not in legal: raise ValueError('Vertical alignment must be one of %s' % str(legal)) @@ -749,15 +652,12 @@ ACCEPTS: string or anything printable with '%s' conversion """ self._text = '%s' % (s,) - #self._substrings = scanner(s) # support embedded mathtext - self._substrings = [] # ignore embedded mathtext for now - def is_math_text(self): + def is_math_text(self, s): if rcParams['text.usetex']: return 'TeX' # Did we find an even number of non-escaped dollar signs? # If so, treat is as math text. - s = self._text dollar_count = s.count(r'$') - s.count(r'\$') if dollar_count > 0 and dollar_count % 2 == 0: return True @@ -772,56 +672,6 @@ """ self._fontproperties = fp - def _get_layout_super(self, renderer, m): - """ - a special case optimization if a log super and angle = 0 - Basically, mathtext is slow and we can do simple superscript layout "by hand" - """ - - key = self.get_prop_tup() - if self.cached.has_key(key): return self.cached[key] - - base, exponent = m.group(1), m.group(2) - size = self._fontproperties.get_size_in_points() - fpexp = self._fontproperties.copy() - fpexp.set_size(0.7*size) - wb,hb = renderer.get_text_width_height(base, self._fontproperties, False) - we,he = renderer.get_text_width_height(exponent, fpexp, False) - - w = wb+we - - xb, yb = self._get_xy_display() - xe = xb+1.1*wb - ye = yb+0.5*hb - h = ye+he-yb - - - - - if self._horizontalalignment=='center': xo = -w/2. - elif self._horizontalalignment=='right': xo = -w - else: xo = 0 - if self._verticalalignment=='center': yo = -hb/2. - elif self._verticalalignment=='top': yo = -hb - else: yo = 0 - - xb += xo - yb += yo - xe += xo - ye += yo - bbox = lbwh_to_bbox(xb, yb, w, h) - - if renderer.flipy(): - canvasw, canvash = renderer.get_canvas_width_height() - yb = canvash-yb - ye = canvash-ye - - - val = ( bbox, ((base, xb, yb), (exponent, xe, ye, fpexp))) - self.cached[key] = val - - return val - artist.kwdocd['Text'] = artist.kwdoc(Text) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <js...@us...> - 2007-08-30 15:32:27
|
Revision: 3759 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=3759&view=rev Author: jswhit Date: 2007-08-30 08:32:25 -0700 (Thu, 30 Aug 2007) Log Message: ----------- better error message when matplotlib too old Modified Paths: -------------- trunk/toolkits/basemap/lib/matplotlib/toolkits/basemap/basemap.py Modified: trunk/toolkits/basemap/lib/matplotlib/toolkits/basemap/basemap.py =================================================================== --- trunk/toolkits/basemap/lib/matplotlib/toolkits/basemap/basemap.py 2007-08-30 15:12:27 UTC (rev 3758) +++ trunk/toolkits/basemap/lib/matplotlib/toolkits/basemap/basemap.py 2007-08-30 15:32:25 UTC (rev 3759) @@ -4,7 +4,7 @@ mpl_required_version = '0.90' if matplotlib_version < mpl_required_version: raise ImportError('your matplotlib is too old - basemap ' - 'requires at least %s'%mpl_required_version) + 'requires at least %s, you have %s'%(mpl_required_version,matplotlib_version)) from matplotlib.collections import LineCollection from matplotlib.patches import Ellipse, Circle, Polygon from matplotlib.lines import Line2D This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <md...@us...> - 2007-08-30 15:12:29
|
Revision: 3758 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=3758&view=rev Author: mdboom Date: 2007-08-30 08:12:27 -0700 (Thu, 30 Aug 2007) Log Message: ----------- Deal with Unicode and non-ASCII characters correctly when outputting Postscript with ps.useafm == True. Modified Paths: -------------- trunk/matplotlib/lib/matplotlib/afm.py trunk/matplotlib/lib/matplotlib/backends/backend_ps.py Modified: trunk/matplotlib/lib/matplotlib/afm.py =================================================================== --- trunk/matplotlib/lib/matplotlib/afm.py 2007-08-30 15:11:23 UTC (rev 3757) +++ trunk/matplotlib/lib/matplotlib/afm.py 2007-08-30 15:12:27 UTC (rev 3758) @@ -34,8 +34,8 @@ John D. Hunter <jdh...@ac...> """ - import sys, os +from _mathtext_data import uni2type1 #Convert string the a python type _to_int = int @@ -152,12 +152,13 @@ all the sample afm files I have """ - d = {} + ascii_d = {} + name_d = {} while 1: line = fh.readline() if not line: break line = line.rstrip() - if line.startswith('EndCharMetrics'): return d + if line.startswith('EndCharMetrics'): return ascii_d, name_d vals = line.split(';')[:4] if len(vals) !=4 : raise RuntimeError('Bad char metrics line: %s' % line) num = _to_int(vals[0].split()[1]) @@ -169,7 +170,8 @@ if name == 'Euro': num = 128 if num != -1: - d[num] = (wx, name, bbox) + ascii_d[num] = (wx, name, bbox) + name_d[name] = (wx, bbox) raise RuntimeError('Bad parse') def _parse_kern_pairs(fh): @@ -277,9 +279,9 @@ """ _sanity_check(fh) dhead = _parse_header(fh) - dcmetrics = _parse_char_metrics(fh) + dcmetrics_ascii, dcmetrics_name = _parse_char_metrics(fh) doptional = _parse_optional(fh) - return dhead, dcmetrics, doptional[0], doptional[1] + return dhead, dcmetrics_ascii, dcmetrics_name, doptional[0], doptional[1] class AFM: @@ -288,10 +290,12 @@ """ Parse the AFM file in file object fh """ - (dhead, dcmetrics, dkernpairs, dcomposite) = parse_afm(fh) + (dhead, dcmetrics_ascii, dcmetrics_name, dkernpairs, dcomposite) = \ + parse_afm(fh) self._header = dhead self._kern = dkernpairs - self._metrics = dcmetrics + self._metrics = dcmetrics_ascii + self._metrics_by_name = dcmetrics_name self._composite = dcomposite @@ -340,9 +344,16 @@ miny = 1e9 maxy = 0 left = 0 + if not isinstance(s, unicode): + s = s.decode() for c in s: if c == '\n': continue - wx, name, bbox = self._metrics[ord(c)] + name = uni2type1.get(ord(c), 'question') + try: + wx, bbox = self._metrics_by_name[name] + except KeyError: + name = 'question' + wx, bbox = self._metrics_by_name[name] l,b,w,h = bbox if l<left: left = l # find the width with kerning @@ -377,6 +388,13 @@ wx, name, bbox = self._metrics[c] return wx + def get_width_from_char_name(self, name): + """ + Get the width of the character from a type1 character name + """ + wx, bbox = self._metrics_by_name[name] + return wx + def get_height_char(self, c, isord=False): """ Get the height of character c from the bounding box. This is @@ -392,9 +410,16 @@ c2 """ name1, name2 = self.get_name_char(c1), self.get_name_char(c2) + return self.get_kern_dist_from_name(name1, name2) + + def get_kern_dist_from_name(self, name1, name2): + """ + Return the kerning pair distance (possibly 0) for chars c1 and + c2 + """ try: return self._kern[ (name1, name2) ] except: return 0 - + def get_fontname(self): "Return the font name, eg, Times-Roman" return self._header['FontName'] Modified: trunk/matplotlib/lib/matplotlib/backends/backend_ps.py =================================================================== --- trunk/matplotlib/lib/matplotlib/backends/backend_ps.py 2007-08-30 15:11:23 UTC (rev 3757) +++ trunk/matplotlib/lib/matplotlib/backends/backend_ps.py 2007-08-30 15:12:27 UTC (rev 3758) @@ -22,6 +22,7 @@ from matplotlib.ft2font import FT2Font, KERNING_DEFAULT, LOAD_NO_HINTING from matplotlib.ttconv import convert_ttf_to_ps from matplotlib.mathtext import MathTextParser +from matplotlib._mathtext_data import uni2type1 from matplotlib.text import Text from matplotlib.transforms import get_vec6_scales @@ -700,8 +701,10 @@ elif ismath: return self.draw_mathtext(gc, x, y, s, prop, angle) + elif isinstance(s, unicode): + return self.draw_unicode(gc, x, y, s, prop, angle) + elif rcParams['ps.useafm']: - if ismath: s = s[1:-1] font = self._get_font_afm(prop) l,b,w,h = font.get_str_bbox(s) @@ -735,8 +738,6 @@ """ % locals() self._draw_ps(ps, gc, None) - elif isinstance(s, unicode): - return self.draw_unicode(gc, x, y, s, prop, angle) else: font = self._get_font_ttf(prop) font.set_text(s, 0, flags=LOAD_NO_HINTING) @@ -762,50 +763,92 @@ """draw a unicode string. ps doesn't have unicode support, so we have to do this the hard way """ + if rcParams['ps.useafm']: + self.set_color(*gc.get_rgb()) - font = self._get_font_ttf(prop) + font = self._get_font_afm(prop) + fontname = font.get_fontname() + fontsize = prop.get_size_in_points() + scale = 0.001*fontsize - self.set_color(*gc.get_rgb()) - self.set_font(font.get_sfnt()[(1,0,0,6)], prop.get_size_in_points()) - self.track_characters(font, s) + thisx, thisy = 0, 0 + last_name = None + lines = [] + for c in s: + name = uni2type1.get(ord(c), 'question') + try: + width = font.get_width_from_char_name(name) + except KeyError: + name = 'question' + width = font.get_width_char('?') + if last_name is not None: + kern = font.get_kern_dist_from_name(last_name, name) + else: + kern = 0 + last_name = name + thisx += kern * scale + + lines.append('%f %f m /%s glyphshow'%(thisx, thisy, name)) - cmap = font.get_charmap() - lastgind = None - #print 'text', s - lines = [] - thisx, thisy = 0,0 - for c in s: - ccode = ord(c) - gind = cmap.get(ccode) - if gind is None: - ccode = ord('?') - name = '.notdef' - gind = 0 - else: - name = font.get_glyph_name(gind) - glyph = font.load_char(ccode, flags=LOAD_NO_HINTING) + thisx += width * scale - if lastgind is not None: - kern = font.get_kerning(lastgind, gind, KERNING_DEFAULT) - else: - kern = 0 - lastgind = gind - thisx += kern/64.0 - - lines.append('%f %f m /%s glyphshow'%(thisx, thisy, name)) - thisx += glyph.linearHoriAdvance/65536.0 - - - thetext = '\n'.join(lines) - ps = """gsave + thetext = "\n".join(lines) + ps = """\ +gsave +/%(fontname)s findfont +%(fontsize)s scalefont +setfont %(x)f %(y)f translate %(angle)f rotate %(thetext)s grestore -""" % locals() - self._pswriter.write(ps) + """ % locals() + self._pswriter.write(ps) + + else: + font = self._get_font_ttf(prop) + self.set_color(*gc.get_rgb()) + self.set_font(font.get_sfnt()[(1,0,0,6)], prop.get_size_in_points()) + self.track_characters(font, s) + cmap = font.get_charmap() + lastgind = None + #print 'text', s + lines = [] + thisx, thisy = 0,0 + for c in s: + ccode = ord(c) + gind = cmap.get(ccode) + if gind is None: + ccode = ord('?') + name = '.notdef' + gind = 0 + else: + name = font.get_glyph_name(gind) + glyph = font.load_char(ccode, flags=LOAD_NO_HINTING) + + if lastgind is not None: + kern = font.get_kerning(lastgind, gind, KERNING_DEFAULT) + else: + kern = 0 + lastgind = gind + thisx += kern/64.0 + + lines.append('%f %f m /%s glyphshow'%(thisx, thisy, name)) + thisx += glyph.linearHoriAdvance/65536.0 + + + thetext = '\n'.join(lines) + ps = """gsave + %(x)f %(y)f translate + %(angle)f rotate + %(thetext)s + grestore + """ % locals() + self._pswriter.write(ps) + + def draw_mathtext(self, gc, x, y, s, prop, angle): """ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <md...@us...> - 2007-08-30 15:11:26
|
Revision: 3757 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=3757&view=rev Author: mdboom Date: 2007-08-30 08:11:23 -0700 (Thu, 30 Aug 2007) Log Message: ----------- Remove the "markup" kwarg and rcParam everywhere and replace it with an automatic detection of math markup. 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/quiver_demo.py trunk/matplotlib/examples/scatter_demo2.py trunk/matplotlib/examples/tex_demo.py trunk/matplotlib/examples/tex_unicode_demo.py trunk/matplotlib/examples/unicode_demo.py trunk/matplotlib/lib/matplotlib/config/mplconfig.py trunk/matplotlib/lib/matplotlib/config/rcsetup.py trunk/matplotlib/lib/matplotlib/legend.py trunk/matplotlib/lib/matplotlib/mathtext.py trunk/matplotlib/lib/matplotlib/quiver.py trunk/matplotlib/lib/matplotlib/rcsetup.py trunk/matplotlib/lib/matplotlib/table.py trunk/matplotlib/lib/matplotlib/text.py Modified: trunk/matplotlib/examples/accented_text.py =================================================================== --- trunk/matplotlib/examples/accented_text.py 2007-08-30 13:51:10 UTC (rev 3756) +++ trunk/matplotlib/examples/accented_text.py 2007-08-30 15:11:23 UTC (rev 3757) @@ -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, markup="tex") +title(r'$\ddot{o}\acute{e}\grave{e}\hat{O}\breve{i}\bar{A}\tilde{n}\vec{q}$', fontsize=20) # shorthand is also supported and curly's are optional -xlabel(r"""$\"o\ddot o \'e\`e\~n\.x\^y$""", fontsize=20, markup="tex") +xlabel(r"""$\"o\ddot o \'e\`e\~n\.x\^y$""", fontsize=20) show() Modified: trunk/matplotlib/examples/arrow_demo.py =================================================================== --- trunk/matplotlib/examples/arrow_demo.py 2007-08-30 13:51:10 UTC (rev 3756) +++ trunk/matplotlib/examples/arrow_demo.py 2007-08-30 15:11:23 UTC (rev 3757) @@ -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', 'markup': 'tex'} + 'fontweight':'bold'} 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, markup='tex') + color=labelcolor or fc) for p in positions.keys(): draw_arrow(p) Modified: trunk/matplotlib/examples/dannys_example.py =================================================================== --- trunk/matplotlib/examples/dannys_example.py 2007-08-30 13:51:10 UTC (rev 3756) +++ trunk/matplotlib/examples/dannys_example.py 2007-08-30 15:11:23 UTC (rev 3757) @@ -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}, markup = 'tex') +pylab.text(-0.06, height - 0.06, r'$\delta$', {'color' : 'k', 'fontsize' : 24}) ## 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 }, markup='tex') + 'fontsize' : 20 }) pylab.yticks((0, 0.5, 1), ('0', '.5', '1'), color = 'k', size = 20) ## Right Y-axis labels @@ -44,17 +44,16 @@ horizontalalignment = 'left', verticalalignment = 'center', rotation = 90, - clip_on = False, - markup = 'tex') + clip_on = False) 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}, markup='tex') +pylab.text(0.1, 0.85, r'$|\nabla\phi| = 1,$ \newline $ \frac{\partial \phi}{\partial t} + U|\nabla \phi| = 0$', {'color' : 'g', 'fontsize' : 20}) ## 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}, markup='tex') +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.savefig('pfm-lsm.png') pylab.show() Modified: trunk/matplotlib/examples/histogram_demo.py =================================================================== --- trunk/matplotlib/examples/histogram_demo.py 2007-08-30 13:51:10 UTC (rev 3756) +++ trunk/matplotlib/examples/histogram_demo.py 2007-08-30 15:11:23 UTC (rev 3757) @@ -15,7 +15,7 @@ xlabel('Smarts') ylabel('Probability') -title(r'$\mathrm{Histogram\ of\ IQ:}\ \mu=100,\ \sigma=15$', markup='tex') +title(r'$\mathrm{Histogram\ of\ IQ:}\ \mu=100,\ \sigma=15$') 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-30 13:51:10 UTC (rev 3756) +++ trunk/matplotlib/examples/histogram_demo_canvasagg.py 2007-08-30 15:11:23 UTC (rev 3757) @@ -33,7 +33,7 @@ ax.set_xlabel('Smarts') ax.set_ylabel('Probability') -ax.set_title(r'$\mathrm{Histogram of IQ: }\mu=100, \sigma=15$', markup='tex') +ax.set_title(r'$\mathrm{Histogram of IQ: }\mu=100, \sigma=15$') 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-30 13:51:10 UTC (rev 3756) +++ trunk/matplotlib/examples/integral_demo.py 2007-08-30 15:11:23 UTC (rev 3757) @@ -23,7 +23,7 @@ text(0.5 * (a + b), 30, r"$\int_a^b f(x)\mathrm{d}x$", horizontalalignment='center', - fontsize=20, markup='tex') + fontsize=20) 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-30 13:51:10 UTC (rev 3756) +++ trunk/matplotlib/examples/legend_auto.py 2007-08-30 15:11:23 UTC (rev 3757) @@ -51,9 +51,9 @@ def fig_7(): figure(7) xx = x - (N/2.0) - 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') + 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$') legend() def fig_8(): Modified: trunk/matplotlib/examples/mathtext_demo.py =================================================================== --- trunk/matplotlib/examples/mathtext_demo.py 2007-08-30 13:51:10 UTC (rev 3756) +++ trunk/matplotlib/examples/mathtext_demo.py 2007-08-30 15:11:23 UTC (rev 3757) @@ -13,12 +13,14 @@ x = npy.arange(0.0, 3.0, 0.1) ax.grid(True) -ax.set_xlabel(r'$\Delta_i^j$', fontsize=20, markup="tex") -ax.set_ylabel(r'$\Delta_{i+1}^j$', fontsize=20, markup="tex") +ax.set_xlabel(r'$\Delta_i^j$', fontsize=20) +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', markup="tex") +ax.text(1, 1.6, tex, fontsize=20, va='bottom') +ax.legend(("Foo", "Testing $x^2$")) + #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-30 13:51:10 UTC (rev 3756) +++ trunk/matplotlib/examples/mathtext_examples.py 2007-08-30 15:11:23 UTC (rev 3757) @@ -2,14 +2,18 @@ import os, sys, re +import gc + stests = [ r'Kerning: AVA $AVA$', + r'\$100.00 $\alpha$', + r'$\frac{\$100.00}{y}$', r'$x y$', r'$x+y\ x=y\ x<y\ x:y\ x,y\ x@y$', 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\hspace{0.5}y$', + r'$x\ x\,x\;x\quad x\qquad x\!x\hspace{ 0.5 }y$', r'$\{ \rm braces \}$', r'$\left[\left\lfloor\frac{5}{\frac{\left(3\right)}{4}} y\right)\right]$', r'$\left(x\right)$', @@ -59,10 +63,10 @@ yticks(arange(len(tests)) * -1) for i, s in enumerate(tests): print "%02d: %s" % (i, s) - text(0.1, -i, s, fontsize=20, markup="tex") + text(0.1, -i, s, fontsize=20) savefig('mathtext_example') - figure() + close('all') if '--latex' in sys.argv: fd = open("mathtext_examples.ltx", "w") Modified: trunk/matplotlib/examples/quiver_demo.py =================================================================== --- trunk/matplotlib/examples/quiver_demo.py 2007-08-30 13:51:10 UTC (rev 3756) +++ trunk/matplotlib/examples/quiver_demo.py 2007-08-30 15:11:23 UTC (rev 3757) @@ -18,8 +18,7 @@ figure() Q = quiver( U, V) qk = quiverkey(Q, 0.5, 0.92, 2, r'$2 \frac{m}{s}$', labelpos='W', - fontproperties={'weight': 'bold'}, - markup="tex") + fontproperties={'weight': 'bold'}) l,r,b,t = axis() dx, dy = r-l, t-b axis([l-0.05*dx, r+0.05*dx, b-0.05*dy, t+0.05*dy]) @@ -32,8 +31,7 @@ qk = quiverkey(Q, 0.9, 0.95, 2, r'$2 \frac{m}{s}$', labelpos='E', coordinates='figure', - fontproperties={'weight': 'bold'}, - markup="tex") + fontproperties={'weight': 'bold'}) axis([-1, 7, -1, 7]) title('scales with plot width, not view') @@ -41,7 +39,7 @@ figure() Q = quiver( X[::3, ::3], Y[::3, ::3], U[::3, ::3], V[::3, ::3], pivot='mid', color='r', units='inches' ) -qk = quiverkey(Q, 0.5, 0.03, 1, r'$1 \frac{m}{s}$', fontproperties={'weight': 'bold'}, markup="tex") +qk = quiverkey(Q, 0.5, 0.03, 1, r'$1 \frac{m}{s}$', fontproperties={'weight': 'bold'}) plot( X[::3, ::3], Y[::3, ::3], 'k.') axis([-1, 7, -1, 7]) title("pivot='mid'; every third arrow; units='inches'") @@ -52,8 +50,7 @@ Q = quiver( X, Y, U, V, M, units='x', pivot='tip', width=0.022, scale=1/0.15) qk = quiverkey(Q, 0.9, 1.05, 1, r'$1 \frac{m}{s}$', labelpos='E', - fontproperties={'weight': 'bold'}, - markup="tex") + fontproperties={'weight': 'bold'}) plot(X, Y, 'k.') axis([-1, 7, -1, 7]) title("scales with x view; pivot='tip'") @@ -63,7 +60,7 @@ Q = quiver( X[::3, ::3], Y[::3, ::3], U[::3, ::3], V[::3, ::3], color='r', units='x', linewidths=(2,), edgecolors=('k'), headaxislength=5 ) -qk = quiverkey(Q, 0.5, 0.03, 1, r'$1 \frac{m}{s}$', fontproperties={'weight': 'bold'}, markup="tex") +qk = quiverkey(Q, 0.5, 0.03, 1, r'$1 \frac{m}{s}$', fontproperties={'weight': 'bold'}) axis([-1, 7, -1, 7]) title("triangular head; scale with x view; black edges") Modified: trunk/matplotlib/examples/scatter_demo2.py =================================================================== --- trunk/matplotlib/examples/scatter_demo2.py 2007-08-30 13:51:10 UTC (rev 3756) +++ trunk/matplotlib/examples/scatter_demo2.py 2007-08-30 15:11:23 UTC (rev 3757) @@ -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', markup='tex') -ylabel(r'$\Delta_{i+1}$', size='x-large', markup='tex') +xlabel(r'$\Delta_i$', size='x-large') +ylabel(r'$\Delta_{i+1}$', size='x-large') 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-30 13:51:10 UTC (rev 3756) +++ trunk/matplotlib/examples/tex_demo.py 2007-08-30 15:11:23 UTC (rev 3757) @@ -23,10 +23,10 @@ s = cos(2*2*pi*t)+2 plot(t, s) -xlabel(r'\textbf{time (s)}', markup='tex') -ylabel(r'\textit{voltage (mV)}',fontsize=16, markup='tex') +xlabel(r'\textbf{time (s)}') +ylabel(r'\textit{voltage (mV)}',fontsize=16) title(r"\TeX\ is Number $\displaystyle\sum_{n=1}^\infty\frac{-e^{i\pi}}{2^n}$!", - fontsize=16, color='r', markup='tex') + fontsize=16, color='r') grid(True) savefig('tex_demo') Modified: trunk/matplotlib/examples/tex_unicode_demo.py =================================================================== --- trunk/matplotlib/examples/tex_unicode_demo.py 2007-08-30 13:51:10 UTC (rev 3756) +++ trunk/matplotlib/examples/tex_unicode_demo.py 2007-08-30 15:11:23 UTC (rev 3757) @@ -17,11 +17,11 @@ s = cos(2*2*pi*t)+2 plot(t, s) -xlabel(r'\textbf{time (s)}', markup='tex') +xlabel(r'\textbf{time (s)}') s = unicode(r'\textit{Velocity (\xB0/sec)}','latin-1') -ylabel(unicode(r'\textit{Velocity (\xB0/sec)}','latin-1'),fontsize=16, markup='tex') +ylabel(unicode(r'\textit{Velocity (\xB0/sec)}','latin-1'),fontsize=16) title(r"\TeX\ is Number $\displaystyle\sum_{n=1}^\infty\frac{-e^{i\pi}}{2^n}$!", - fontsize=16, color='r', markup='tex') + fontsize=16, color='r') grid(True) savefig('tex_demo') Modified: trunk/matplotlib/examples/unicode_demo.py =================================================================== --- trunk/matplotlib/examples/unicode_demo.py 2007-08-30 13:51:10 UTC (rev 3756) +++ trunk/matplotlib/examples/unicode_demo.py 2007-08-30 15:11:23 UTC (rev 3757) @@ -9,5 +9,5 @@ text( 0.5, 2.5, unicode('Institut f\xFCr Festk\xF6rperphysik', 'latin-1'), rotation=45) text( 1, 1.5, u'AVA (check kerning)') -savefig('test.svg') +savefig('test') show() Modified: trunk/matplotlib/lib/matplotlib/config/mplconfig.py =================================================================== --- trunk/matplotlib/lib/matplotlib/config/mplconfig.py 2007-08-30 13:51:10 UTC (rev 3756) +++ trunk/matplotlib/lib/matplotlib/config/mplconfig.py 2007-08-30 15:11:23 UTC (rev 3757) @@ -153,7 +153,6 @@ class text(TConfig): color = T.Trait('black',mplT.ColorHandler()) usetex = T.false - markup = T.Trait('plain', 'plain', 'tex') class latex(TConfig): unicode = T.false Modified: trunk/matplotlib/lib/matplotlib/config/rcsetup.py =================================================================== --- trunk/matplotlib/lib/matplotlib/config/rcsetup.py 2007-08-30 13:51:10 UTC (rev 3756) +++ trunk/matplotlib/lib/matplotlib/config/rcsetup.py 2007-08-30 15:11:23 UTC (rev 3757) @@ -203,11 +203,6 @@ parse_fontconfig_pattern(s) return s -validate_markup = ValidateInStrings( - 'markup', - ['plain', 'tex'], - ignorecase=True) - validate_verbose = ValidateInStrings('verbose',[ 'silent', 'helpful', 'debug', 'debug-annoying', ]) @@ -363,7 +358,6 @@ 'text.fontvariant' : ['normal', str], 'text.fontweight' : ['normal', str], 'text.fontsize' : ['medium', validate_fontsize], - 'text.markup' : ['plain', validate_markup], 'mathtext.cal' : ['cursive', validate_font_properties], 'mathtext.rm' : ['serif', validate_font_properties], Modified: trunk/matplotlib/lib/matplotlib/legend.py =================================================================== --- trunk/matplotlib/lib/matplotlib/legend.py 2007-08-30 13:51:10 UTC (rev 3756) +++ trunk/matplotlib/lib/matplotlib/legend.py 2007-08-30 15:11:23 UTC (rev 3757) @@ -123,8 +123,7 @@ handletextsep = None, # the space between the legend line and legend text axespad = None, # the border between the axes and legend edge - shadow = None, - markup = None + shadow = None ): """ parent # the artist that contains the legend @@ -204,7 +203,7 @@ else: self._xdata = npy.linspace(left, left + self.handlelen, self.numpoints) textleft = left+ self.handlelen+self.handletextsep - self.texts = self._get_texts(labels, textleft, top, markup) + self.texts = self._get_texts(labels, textleft, top) self.legendHandles = self._get_handles(handles, self.texts) @@ -405,7 +404,7 @@ 'return a list of text.Text instance in the legend' return silent_list('Text', self.texts) - def _get_texts(self, labels, left, upper, markup): + def _get_texts(self, labels, left, upper): # height in axes coords HEIGHT = self._approx_text_height() @@ -419,8 +418,7 @@ text=l, fontproperties=self.prop, verticalalignment='top', - horizontalalignment='left', - markup=markup + horizontalalignment='left' ) self._set_artist_props(text) ret.append(text) Modified: trunk/matplotlib/lib/matplotlib/mathtext.py =================================================================== --- trunk/matplotlib/lib/matplotlib/mathtext.py 2007-08-30 13:51:10 UTC (rev 3756) +++ trunk/matplotlib/lib/matplotlib/mathtext.py 2007-08-30 15:11:23 UTC (rev 3757) @@ -1982,7 +1982,7 @@ math_delim =(~bslash + Literal('$')) - non_math = Regex(r"(?:[^$]|(?:\\\$))*" + non_math = Regex(r"(?:(?:\\[$])|[^$])*" ).setParseAction(self.non_math).setName("non_math").leaveWhitespace() self._expression << ( @@ -2056,7 +2056,8 @@ def non_math(self, s, loc, toks): #~ print "non_math", toks - symbols = [Char(c, self.get_state()) for c in toks[0]] + s = toks[0].replace(r'\$', '$') + symbols = [Char(c, self.get_state()) for c in s] hlist = Hlist(symbols) # We're going into math now, so set font to 'it' self.push_state() Modified: trunk/matplotlib/lib/matplotlib/quiver.py =================================================================== --- trunk/matplotlib/lib/matplotlib/quiver.py 2007-08-30 13:51:10 UTC (rev 3756) +++ trunk/matplotlib/lib/matplotlib/quiver.py 2007-08-30 15:11:23 UTC (rev 3757) @@ -173,14 +173,12 @@ self.labelpos = kw.pop('labelpos', 'N') self.labelcolor = kw.pop('labelcolor', None) self.fontproperties = kw.pop('fontproperties', dict()) - self.markup = kw.pop('markup', None) self.kw = kw _fp = self.fontproperties self.text = text.Text(text=label, horizontalalignment=self.halign[self.labelpos], verticalalignment=self.valign[self.labelpos], - fontproperties=font_manager.FontProperties(**_fp), - markup=self.markup) + fontproperties=font_manager.FontProperties(**_fp)) if self.labelcolor is not None: self.text.set_color(self.labelcolor) self._initialized = False Modified: trunk/matplotlib/lib/matplotlib/rcsetup.py =================================================================== --- trunk/matplotlib/lib/matplotlib/rcsetup.py 2007-08-30 13:51:10 UTC (rev 3756) +++ trunk/matplotlib/lib/matplotlib/rcsetup.py 2007-08-30 15:11:23 UTC (rev 3757) @@ -203,11 +203,6 @@ parse_fontconfig_pattern(s) return s -validate_markup = ValidateInStrings( - 'markup', - ['plain', 'tex'], - ignorecase=True) - validate_verbose = ValidateInStrings('verbose',[ 'silent', 'helpful', 'debug', 'debug-annoying', ]) @@ -363,7 +358,6 @@ 'text.fontvariant' : ['normal', str], 'text.fontweight' : ['normal', str], 'text.fontsize' : ['medium', validate_fontsize], - 'text.markup' : ['plain', validate_markup], 'mathtext.cal' : ['cursive', validate_font_properties], 'mathtext.rm' : ['serif', validate_font_properties], Modified: trunk/matplotlib/lib/matplotlib/table.py =================================================================== --- trunk/matplotlib/lib/matplotlib/table.py 2007-08-30 13:51:10 UTC (rev 3756) +++ trunk/matplotlib/lib/matplotlib/table.py 2007-08-30 15:11:23 UTC (rev 3757) @@ -47,8 +47,7 @@ fill=True, text='', loc=None, - fontproperties=None, - markup=None + fontproperties=None ): # Call base @@ -61,7 +60,7 @@ if loc is None: loc = 'right' self._loc = loc self._text = Text(x=xy[0], y=xy[1], text=text, - fontproperties=fontproperties, markup=markup) + fontproperties=fontproperties) self._text.set_clip_on(False) Modified: trunk/matplotlib/lib/matplotlib/text.py =================================================================== --- trunk/matplotlib/lib/matplotlib/text.py 2007-08-30 13:51:10 UTC (rev 3756) +++ trunk/matplotlib/lib/matplotlib/text.py 2007-08-30 15:11:23 UTC (rev 3757) @@ -146,7 +146,6 @@ fontproperties=None, # defaults to FontProperties() rotation=None, linespacing=None, - markup=None, **kwargs ): """ @@ -176,7 +175,6 @@ 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 @@ -225,7 +223,6 @@ self._rotation = other._rotation self._picker = other._picker self._linespacing = other._linespacing - self._markup = other._markup def _get_layout(self, renderer): @@ -757,9 +754,14 @@ def is_math_text(self): if rcParams['text.usetex']: return 'TeX' - if self._markup.lower() == 'tex': - if not matplotlib._havemath: return False + + # Did we find an even number of non-escaped dollar signs? + # If so, treat is as math text. + s = self._text + dollar_count = s.count(r'$') - s.count(r'\$') + if dollar_count > 0 and dollar_count % 2 == 0: return True + return False def set_fontproperties(self, fp): @@ -770,20 +772,6 @@ """ 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 This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <md...@us...> - 2007-08-30 13:51:12
|
Revision: 3756 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=3756&view=rev Author: mdboom Date: 2007-08-30 06:51:10 -0700 (Thu, 30 Aug 2007) Log Message: ----------- Reduce Ps files sizes when using mathtext Modified Paths: -------------- trunk/matplotlib/lib/matplotlib/mathtext.py Modified: trunk/matplotlib/lib/matplotlib/mathtext.py =================================================================== --- trunk/matplotlib/lib/matplotlib/mathtext.py 2007-08-30 13:41:52 UTC (rev 3755) +++ trunk/matplotlib/lib/matplotlib/mathtext.py 2007-08-30 13:51:10 UTC (rev 3756) @@ -315,6 +315,7 @@ class MathtextBackendPs(MathtextBackend): def __init__(self): self.pswriter = StringIO() + self.lastfont = None def render_glyph(self, ox, oy, info): oy = self.height - oy + info.offset @@ -322,12 +323,15 @@ fontsize = info.fontsize symbol_name = info.symbol_name - # TODO: Optimize out the font changes - - ps = """/%(postscript_name)s findfont + if (postscript_name, fontsize) != self.lastfont: + ps = """/%(postscript_name)s findfont %(fontsize)s scalefont setfont -%(ox)f %(oy)f moveto +""" % locals() + self.lastfont = postscript_name, fontsize + self.pswriter.write(ps) + + ps = """%(ox)f %(oy)f moveto /%(symbol_name)s glyphshow\n """ % locals() self.pswriter.write(ps) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <md...@us...> - 2007-08-30 13:41:54
|
Revision: 3755 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=3755&view=rev Author: mdboom Date: 2007-08-30 06:41:52 -0700 (Thu, 30 Aug 2007) Log Message: ----------- Fixes bounding box bug with Agg backend. Fixes spacing bug when using standard Ps fonts. Reduces memory usage by not caching mathtext expressions for too long. Modified Paths: -------------- trunk/matplotlib/lib/matplotlib/mathtext.py Modified: trunk/matplotlib/lib/matplotlib/mathtext.py =================================================================== --- trunk/matplotlib/lib/matplotlib/mathtext.py 2007-08-30 13:38:22 UTC (rev 3754) +++ trunk/matplotlib/lib/matplotlib/mathtext.py 2007-08-30 13:41:52 UTC (rev 3755) @@ -253,9 +253,9 @@ def render_glyph(self, ox, oy, info): self._update_bbox(ox + info.metrics.xmin, - oy + info.metrics.ymin, + oy - info.metrics.ymax, ox + info.metrics.xmax, - oy + info.metrics.ymax) + oy - info.metrics.ymin) def render_rect_filled(self, x1, y1, x2, y2): self._update_bbox(x1, y1, x2, y2) @@ -265,7 +265,8 @@ bbox = self.bbox bbox = [bbox[0] - 2, bbox[1] - 2, bbox[2] + 2, bbox[3] + 2] self._switch_to_real_backend() - self.fonts_object.set_canvas_size(bbox[2] - bbox[0], bbox[3] - bbox[1]) + self.fonts_object.set_canvas_size( + bbox[2] - bbox[0], bbox[3] - bbox[1]) ship(-bbox[0], -bbox[1], box) return self.fonts_object.get_results(box) @@ -321,6 +322,8 @@ fontsize = info.fontsize symbol_name = info.symbol_name + # TODO: Optimize out the font changes + ps = """/%(postscript_name)s findfont %(fontsize)s scalefont setfont @@ -928,7 +931,7 @@ xmin, ymin, xmax, ymax = [val * scale for val in font.get_bbox_char(glyph)] metrics = Bunch( - advance = (xmax-xmin), + advance = font.get_width_char(glyph) * scale, width = font.get_width_char(glyph) * scale, height = font.get_height_char(glyph) * scale, xmin = xmin, @@ -2439,6 +2442,7 @@ cacheKey = (s, dpi, hash(prop)) result = self._cache.get(cacheKey) if result is not None: + del self._cache[cacheKey] return result if self._output == 'PS' and rcParams['ps.useafm']: This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <md...@us...> - 2007-08-30 13:38:24
|
Revision: 3754 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=3754&view=rev Author: mdboom Date: 2007-08-30 06:38:22 -0700 (Thu, 30 Aug 2007) Log Message: ----------- Make examples match real defaults. Modified Paths: -------------- trunk/matplotlib/lib/matplotlib/mpl-data/matplotlibrc Modified: trunk/matplotlib/lib/matplotlib/mpl-data/matplotlibrc =================================================================== --- trunk/matplotlib/lib/matplotlib/mpl-data/matplotlibrc 2007-08-30 13:04:05 UTC (rev 3753) +++ trunk/matplotlib/lib/matplotlib/mpl-data/matplotlibrc 2007-08-30 13:38:22 UTC (rev 3754) @@ -164,12 +164,12 @@ # (See FontProperties for more details). # These settings are only used if mathtext.use_cm is False, otherwise, the # Bakoma TeX Computer Modern fonts are used. -#mathtext.cal : ['cursive'] -#mathtext.rm : ['serif'] -#mathtext.tt : ['monospace'] -#mathtext.it : ['serif'], style='oblique' -#mathtext.bf : ['serif'], weight='bold' -#mathtext.sf : ['sans-serif'] +#mathtext.cal : cursive +#mathtext.rm : serif +#mathtext.tt : monospace +#mathtext.it : serif:italic +#mathtext.bf : serif:bold +#mathtext.sf : sans #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 This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <md...@us...> - 2007-08-30 13:04:25
|
Revision: 3753 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=3753&view=rev Author: mdboom Date: 2007-08-30 06:04:05 -0700 (Thu, 30 Aug 2007) Log Message: ----------- Fix bug where mathtext colors were not being set properly. 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-29 20:39:07 UTC (rev 3752) +++ trunk/matplotlib/lib/matplotlib/backends/backend_pdf.py 2007-08-30 13:04:05 UTC (rev 3753) @@ -1348,8 +1348,8 @@ # this complication is avoided, but of course, those fonts can # not be subsetted. + self.check_gc(gc, gc._rgb) if ismath: return self.draw_mathtext(gc, x, y, s, prop, angle) - self.check_gc(gc, gc._rgb) fontsize = prop.get_size_in_points() This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <md...@us...> - 2007-08-29 20:39:20
|
Revision: 3752 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=3752&view=rev Author: mdboom Date: 2007-08-29 13:39:07 -0700 (Wed, 29 Aug 2007) Log Message: ----------- Updated to match the real defaults. Modified Paths: -------------- trunk/matplotlib/matplotlibrc.template Modified: trunk/matplotlib/matplotlibrc.template =================================================================== --- trunk/matplotlib/matplotlibrc.template 2007-08-29 20:36:52 UTC (rev 3751) +++ trunk/matplotlib/matplotlibrc.template 2007-08-29 20:39:07 UTC (rev 3752) @@ -164,12 +164,12 @@ # (See FontProperties for more details). # These settings are only used if mathtext.use_cm is False, otherwise, the # Bakoma TeX Computer Modern fonts are used. -#mathtext.cal : "cursive" -#mathtext.rm : "serif" -#mathtext.tt : "monospace" -#mathtext.it : "serif:italic" -#mathtext.bf : "serif:bold" -#mathtext.sf : "sans" +#mathtext.cal : cursive +#mathtext.rm : serif +#mathtext.tt : monospace +#mathtext.it : serif:italic +#mathtext.bf : serif:bold +#mathtext.sf : sans #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 This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <md...@us...> - 2007-08-29 20:36:55
|
Revision: 3751 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=3751&view=rev Author: mdboom Date: 2007-08-29 13:36:52 -0700 (Wed, 29 Aug 2007) Log Message: ----------- Updated to match the real defaults. Modified Paths: -------------- trunk/matplotlib/matplotlibrc.template Modified: trunk/matplotlib/matplotlibrc.template =================================================================== --- trunk/matplotlib/matplotlibrc.template 2007-08-29 17:54:42 UTC (rev 3750) +++ trunk/matplotlib/matplotlibrc.template 2007-08-29 20:36:52 UTC (rev 3751) @@ -164,12 +164,12 @@ # (See FontProperties for more details). # These settings are only used if mathtext.use_cm is False, otherwise, the # Bakoma TeX Computer Modern fonts are used. -#mathtext.cal : ['cursive'] -#mathtext.rm : ['serif'] -#mathtext.tt : ['monospace'] -#mathtext.it : ['serif'], style='oblique' -#mathtext.bf : ['serif'], weight='bold' -#mathtext.sf : ['sans-serif'] +#mathtext.cal : "cursive" +#mathtext.rm : "serif" +#mathtext.tt : "monospace" +#mathtext.it : "serif:italic" +#mathtext.bf : "serif:bold" +#mathtext.sf : "sans" #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 This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <md...@us...> - 2007-08-29 18:10:48
|
Revision: 3750 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=3750&view=rev Author: mdboom Date: 2007-08-29 10:54:42 -0700 (Wed, 29 Aug 2007) Log Message: ----------- Fix leaks of FT2Font objects. Modified Paths: -------------- trunk/matplotlib/lib/matplotlib/backends/backend_agg.py trunk/matplotlib/lib/matplotlib/backends/backend_svg.py trunk/matplotlib/lib/matplotlib/mathtext.py Modified: trunk/matplotlib/lib/matplotlib/backends/backend_agg.py =================================================================== --- trunk/matplotlib/lib/matplotlib/backends/backend_agg.py 2007-08-28 20:29:37 UTC (rev 3749) +++ trunk/matplotlib/lib/matplotlib/backends/backend_agg.py 2007-08-29 17:54:42 UTC (rev 3750) @@ -89,9 +89,7 @@ from _backend_agg import RendererAgg as _RendererAgg backend_version = 'v2.2' -_fontd = {} # a map from fname to font instances - class RendererAgg(RendererBase): """ The renderer handles all the drawing primitives using a graphics @@ -126,7 +124,8 @@ self.copy_from_bbox = self._renderer.copy_from_bbox self.restore_region = self._renderer.restore_region self.mathtext_parser = MathTextParser('Agg') - + self._fontd = {} + self.bbox = lbwh_to_bbox(0,0, self.width, self.height) if __debug__: verbose.report('RendererAgg.__init__ done', 'debug-annoying') @@ -298,12 +297,12 @@ 'debug-annoying') key = hash(prop) - font = _fontd.get(key) + font = self._fontd.get(key) if font is None: fname = findfont(prop) font = FT2Font(str(fname)) - _fontd[key] = font + self._fontd[key] = font font.clear() size = prop.get_size_in_points() Modified: trunk/matplotlib/lib/matplotlib/backends/backend_svg.py =================================================================== --- trunk/matplotlib/lib/matplotlib/backends/backend_svg.py 2007-08-28 20:29:37 UTC (rev 3749) +++ trunk/matplotlib/lib/matplotlib/backends/backend_svg.py 2007-08-29 17:54:42 UTC (rev 3750) @@ -23,7 +23,6 @@ return manager -_fontd = {} _capstyle_d = {'projecting' : 'square', 'butt' : 'butt', 'round': 'round',} class RendererSVG(RendererBase): FONT_SCALE = 1200.0 @@ -41,6 +40,7 @@ self._clipd = {} self._char_defs = {} self.mathtext_parser = MathTextParser('SVG') + self.fontd = {} svgwriter.write(svgProlog%(width,height,width,height)) def _draw_svg_element(self, element, details, gc, rgbFace): @@ -56,11 +56,11 @@ def _get_font(self, prop): key = hash(prop) - font = _fontd.get(key) + font = self.fontd.get(key) if font is None: fname = findfont(prop) font = FT2Font(str(fname)) - _fontd[key] = font + self.fontd[key] = font font.clear() size = prop.get_size_in_points() font.set_size(size, 72.0) Modified: trunk/matplotlib/lib/matplotlib/mathtext.py =================================================================== --- trunk/matplotlib/lib/matplotlib/mathtext.py 2007-08-28 20:29:37 UTC (rev 3749) +++ trunk/matplotlib/lib/matplotlib/mathtext.py 2007-08-29 17:54:42 UTC (rev 3750) @@ -430,6 +430,11 @@ self.mathtext_backend.fonts_object = self self.used_characters = {} + def destroy(self): + """Fix any cyclical references before the object is about + to be destroyed.""" + self.used_characters = None + def get_kern(self, font1, sym1, fontsize1, font2, sym2, fontsize2, dpi): """ @@ -461,7 +466,7 @@ xmin, xmax, ymin, ymax - the ink rectangle of the glyph iceberg - the distance from the baseline to the top of the glyph. horiBearingY in Truetype parlance, height in TeX parlance - """ + """ info = self._get_info(font, sym, fontsize, dpi) return info.metrics @@ -494,8 +499,10 @@ return self.mathtext_backend.get_results(box) def get_sized_alternatives_for_symbol(self, fontname, sym): - """Override if your font provides multiple sizes of the same - symbol.""" + """ + Override if your font provides multiple sizes of the same + symbol. + """ return [(fontname, sym)] class TruetypeFonts(Fonts): @@ -503,10 +510,6 @@ A generic base class for all font setups that use Truetype fonts (through ft2font) """ - """ - Use the Bakoma true type fonts for rendering - """ - # allocate a new set of fonts basepath = os.path.join( get_data_path(), 'fonts', 'ttf' ) class CachedFont: @@ -529,6 +532,14 @@ self.fonts['default'] = default_font + def destroy(self): + self.glyphd = None + for cached_font in self.fonts.values(): + cached_font.charmap = None + cached_font.glyphmap = None + cached_font.font = None + Fonts.destroy(self) + def _get_font(self, font): """Looks up a CachedFont with its charmap and inverse charmap. font may be a TeX font name (cal, rm, it etc.), or postscript name.""" @@ -2401,7 +2412,7 @@ ############################################################################## # MAIN -class MathTextParser: +class MathTextParser(object): """ Parse the math expression s, return the (bbox, fonts) tuple needed to render it. @@ -2453,7 +2464,10 @@ self._cache[cacheKey] = result # Free up the transient data structures self._parser.clear() - # Remove a cyclical reference + + # Fix cyclical references + font_output.destroy() font_output.mathtext_backend.fonts_object = None - + font_output.mathtext_backend = None + return result This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <md...@us...> - 2007-08-28 20:29:39
|
Revision: 3749 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=3749&view=rev Author: mdboom Date: 2007-08-28 13:29:37 -0700 (Tue, 28 Aug 2007) Log Message: ----------- Sped up get_valid_values to improve startup time. Modified Paths: -------------- trunk/matplotlib/lib/matplotlib/artist.py Modified: trunk/matplotlib/lib/matplotlib/artist.py =================================================================== --- trunk/matplotlib/lib/matplotlib/artist.py 2007-08-28 20:28:46 UTC (rev 3748) +++ trunk/matplotlib/lib/matplotlib/artist.py 2007-08-28 20:29:37 UTC (rev 3749) @@ -1,5 +1,5 @@ from __future__ import division -import sys +import sys, re from cbook import iterable, flatten from transforms import identity_transform import matplotlib.units as units @@ -484,6 +484,7 @@ aliases[fullname[4:]] = name[4:] return aliases + _get_valid_values_regex = re.compile(r"\n\s*ACCEPTS:\s*(.*)\n") def get_valid_values(self, attr): """ get the legal arguments for the setter associated with attr @@ -505,10 +506,10 @@ if docstring.startswith('alias for '): return None - for line in docstring.split('\n'): - line = line.lstrip() - if not line.startswith('ACCEPTS:'): continue - return line[8:].strip() + + match = self._get_valid_values_regex.search(docstring) + if match is not None: + return match.group(1) return 'unknown' def get_setters(self): This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <md...@us...> - 2007-08-28 20:28:50
|
Revision: 3748 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=3748&view=rev Author: mdboom Date: 2007-08-28 13:28:46 -0700 (Tue, 28 Aug 2007) Log Message: ----------- Improved speed of revcmap -- a startup time offender. Modified Paths: -------------- trunk/matplotlib/lib/matplotlib/_cm.py Modified: trunk/matplotlib/lib/matplotlib/_cm.py =================================================================== --- trunk/matplotlib/lib/matplotlib/_cm.py 2007-08-28 19:49:53 UTC (rev 3747) +++ trunk/matplotlib/lib/matplotlib/_cm.py 2007-08-28 20:28:46 UTC (rev 3748) @@ -11,6 +11,7 @@ import matplotlib as mpl import matplotlib.colors as colors +from matplotlib.cbook import reversed LUTSIZE = mpl.rcParams['image.lut'] _binary_data = { @@ -5949,13 +5950,9 @@ def revcmap(data): data_r = {} - for key,val in data.iteritems(): - val = list(val) - valrev = val[::-1] - valnew = [] - for a,b,c in valrev: - valnew.append((1.-a,b,c)) - data_r[key]=valnew + for key, val in data.iteritems(): + valnew = [(1.-a, b, c) for a, b, c in reversed(val)] + data_r[key] = valnew return data_r cmapnames = datad.keys() This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <md...@us...> - 2007-08-28 19:50:03
|
Revision: 3747 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=3747&view=rev Author: mdboom Date: 2007-08-28 12:49:53 -0700 (Tue, 28 Aug 2007) Log Message: ----------- A further optimization of the new dedent. Modified Paths: -------------- trunk/matplotlib/lib/matplotlib/cbook.py Modified: trunk/matplotlib/lib/matplotlib/cbook.py =================================================================== --- trunk/matplotlib/lib/matplotlib/cbook.py 2007-08-28 19:49:29 UTC (rev 3746) +++ trunk/matplotlib/lib/matplotlib/cbook.py 2007-08-28 19:49:53 UTC (rev 3747) @@ -577,7 +577,6 @@ _dedent_regex[nshift] = unindent result = unindent.sub("\n", s).strip() - print result return result This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <md...@us...> - 2007-08-28 19:49:33
|
Revision: 3746 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=3746&view=rev Author: mdboom Date: 2007-08-28 12:49:29 -0700 (Tue, 28 Aug 2007) Log Message: ----------- A further optimization of the new dedent. Modified Paths: -------------- trunk/matplotlib/lib/matplotlib/cbook.py Modified: trunk/matplotlib/lib/matplotlib/cbook.py =================================================================== --- trunk/matplotlib/lib/matplotlib/cbook.py 2007-08-28 19:20:08 UTC (rev 3745) +++ trunk/matplotlib/lib/matplotlib/cbook.py 2007-08-28 19:49:29 UTC (rev 3746) @@ -573,10 +573,11 @@ # beginning of each line. If it isn't in the cache, generate it. unindent = _dedent_regex.get(nshift, None) if unindent is None: - unindent = re.compile("\n\r?" + " ?" * nshift) + unindent = re.compile("\n\r? {0,%d}" % nshift) _dedent_regex[nshift] = unindent result = unindent.sub("\n", s).strip() + print result return result This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <md...@us...> - 2007-08-28 19:20:13
|
Revision: 3745 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=3745&view=rev Author: mdboom Date: 2007-08-28 12:20:08 -0700 (Tue, 28 Aug 2007) Log Message: ----------- Oops in last commit. Modified Paths: -------------- trunk/matplotlib/lib/matplotlib/cbook.py Modified: trunk/matplotlib/lib/matplotlib/cbook.py =================================================================== --- trunk/matplotlib/lib/matplotlib/cbook.py 2007-08-28 19:17:21 UTC (rev 3744) +++ trunk/matplotlib/lib/matplotlib/cbook.py 2007-08-28 19:20:08 UTC (rev 3745) @@ -572,7 +572,7 @@ # Get a regex that will remove *up to* nshift spaces from the # beginning of each line. If it isn't in the cache, generate it. unindent = _dedent_regex.get(nshift, None) - if unindent = None + if unindent is None: unindent = re.compile("\n\r?" + " ?" * nshift) _dedent_regex[nshift] = unindent This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <md...@us...> - 2007-08-28 19:17:28
|
Revision: 3744 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=3744&view=rev Author: mdboom Date: 2007-08-28 12:17:21 -0700 (Tue, 28 Aug 2007) Log Message: ----------- Use regular expressions to do dedenting. This is ~15X faster than the old implementation. dedent accounted for around 30% of the time spent in "import pylab", so was probably worthy of optimization, even if this regex approach is less clear. The results are identical to the old implementation, with the exception of a single docstring (in backend_bases.py) that needed to be fixed. Modified Paths: -------------- trunk/matplotlib/lib/matplotlib/backend_bases.py trunk/matplotlib/lib/matplotlib/cbook.py Modified: trunk/matplotlib/lib/matplotlib/backend_bases.py =================================================================== --- trunk/matplotlib/lib/matplotlib/backend_bases.py 2007-08-28 12:27:56 UTC (rev 3743) +++ trunk/matplotlib/lib/matplotlib/backend_bases.py 2007-08-28 19:17:21 UTC (rev 3744) @@ -1100,7 +1100,7 @@ return newCanvas def mpl_connect(self, s, func): - """\ + """ Connect event with string s to func. The signature of func is def func(event) Modified: trunk/matplotlib/lib/matplotlib/cbook.py =================================================================== --- trunk/matplotlib/lib/matplotlib/cbook.py 2007-08-28 12:27:56 UTC (rev 3743) +++ trunk/matplotlib/lib/matplotlib/cbook.py 2007-08-28 19:17:21 UTC (rev 3744) @@ -533,6 +533,12 @@ ret += pad + ' '.join(line) + '\n' return ret +# A regular expression used to determine the amount of space to +# remove. It looks for the first sequence of spaces immediately +# following the first newline, or at the beginning of the string. +_find_dedent_regex = re.compile("(?:(?:\n\r?)|^)( *)\S") +# A cache to hold the regexs that actually remove the indent. +_dedent_regex = {} def dedent(s): """ Remove excess indentation from docstrings. @@ -546,24 +552,34 @@ It is also faster in most cases. """ + # This implementation has a somewhat obtuse use of regular + # expressions. However, this function accounted for almost 30% of + # matplotlib startup time, so it is worthy of optimization at all + # costs. + if not s: # includes case of s is None return '' - lines = s.splitlines(False) - ii = 0 - while lines[ii].strip() == '': - ii += 1 - lines = lines[ii:] - nshift = len(lines[0]) - len(lines[0].lstrip()) - # Don't use first line in case of """blah... - if ii == 0 and len(lines) > 1: - nshift = len(lines[1]) - len(lines[1].lstrip()) - for i, line in enumerate(lines): - nwhite = len(line) - len(line.lstrip()) - lines[i] = line[min(nshift, nwhite):] - return '\n'.join(lines) + match = _find_dedent_regex.match(s) + if match is None: + return s + # This is the number of spaces to remove from the left-hand side. + nshift = match.end(1) - match.start(1) + if nshift == 0: + return s + # Get a regex that will remove *up to* nshift spaces from the + # beginning of each line. If it isn't in the cache, generate it. + unindent = _dedent_regex.get(nshift, None) + if unindent = None + unindent = re.compile("\n\r?" + " ?" * nshift) + _dedent_regex[nshift] = unindent + + result = unindent.sub("\n", s).strip() + return result + + def listFiles(root, patterns='*', recurse=1, return_folders=0): """ Recursively list files This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <md...@us...> - 2007-08-28 15:31:56
|
Revision: 3743 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=3743&view=rev Author: mdboom Date: 2007-08-28 05:27:56 -0700 (Tue, 28 Aug 2007) Log Message: ----------- Fix bug where some the images of some math expressions were truncated at the edges when using Agg backend. Modified Paths: -------------- trunk/matplotlib/lib/matplotlib/backends/backend_agg.py trunk/matplotlib/lib/matplotlib/mathtext.py Modified: trunk/matplotlib/lib/matplotlib/backends/backend_agg.py =================================================================== --- trunk/matplotlib/lib/matplotlib/backends/backend_agg.py 2007-08-27 19:34:23 UTC (rev 3742) +++ trunk/matplotlib/lib/matplotlib/backends/backend_agg.py 2007-08-28 12:27:56 UTC (rev 3743) @@ -173,17 +173,21 @@ """ if __debug__: verbose.report('RendererAgg.draw_mathtext', 'debug-annoying') - width, height, fonts, used_characters = self.mathtext_parser.parse( - s, self.dpi.get(), prop) + ox, oy, width, height, fonts, used_characters = \ + self.mathtext_parser.parse(s, self.dpi.get(), prop) if angle == 90: width, height = height, width + ox, oy = oy, ox + x = int(x) - width + ox + y = int(y) - height + oy + else: + x = int(x) + ox + y = int(y) - height + oy for font in fonts: if angle == 90: font.horiz_image_to_vert_image() # <-- Rotate - self._renderer.draw_text( font, int(x)-width, int(y)-height, gc) - else: - self._renderer.draw_text( font, int(x), int(y)-height, gc) + self._renderer.draw_text( font, x, y, gc) if 0: self._renderer.draw_rectangle(gc, None, int(x), @@ -230,8 +234,8 @@ return n,m if ismath: - width, height, fonts, used_characters = self.mathtext_parser.parse( - s, self.dpi.get(), prop) + ox, oy, width, height, fonts, used_characters = \ + self.mathtext_parser.parse(s, self.dpi.get(), prop) return width, height font = self._get_agg_font(prop) font.set_text(s, 0.0, flags=LOAD_DEFAULT) # the width and height of unrotated string Modified: trunk/matplotlib/lib/matplotlib/mathtext.py =================================================================== --- trunk/matplotlib/lib/matplotlib/mathtext.py 2007-08-27 19:34:23 UTC (rev 3742) +++ trunk/matplotlib/lib/matplotlib/mathtext.py 2007-08-28 12:27:56 UTC (rev 3743) @@ -215,7 +215,7 @@ class MathtextBackend(object): def __init__(self): - fonts_object = None + self.fonts_object = None def set_canvas_size(self, w, h): 'Dimension the drawing canvas; may be a noop' @@ -228,7 +228,7 @@ def render_filled_rect(self, x1, y1, x2, y2): raise NotImplementedError() - def get_results(self): + def get_results(self, box): """Return a backend specific tuple of things to return to the backend after all processing is done.""" raise NotImplementedError() @@ -236,7 +236,54 @@ def get_hinting_type(self): return LOAD_NO_HINTING -class MathtextBackendAgg(MathtextBackend): +class MathtextBackendBbox(MathtextBackend): + """A backend whose only purpose is to get a precise bounding box. + Only required for the Agg backend.""" + + def __init__(self, real_backend): + MathtextBackend.__init__(self) + self.bbox = [0, 0, 0, 0] + self.real_backend = real_backend + + def _update_bbox(self, x1, y1, x2, y2): + self.bbox = [min(self.bbox[0], x1), + min(self.bbox[1], y1), + max(self.bbox[2], x2), + max(self.bbox[3], y2)] + + def render_glyph(self, ox, oy, info): + self._update_bbox(ox + info.metrics.xmin, + oy + info.metrics.ymin, + ox + info.metrics.xmax, + oy + info.metrics.ymax) + + def render_rect_filled(self, x1, y1, x2, y2): + self._update_bbox(x1, y1, x2, y2) + + def get_results(self, box): + ship(0, 0, box) + bbox = self.bbox + bbox = [bbox[0] - 2, bbox[1] - 2, bbox[2] + 2, bbox[3] + 2] + self._switch_to_real_backend() + self.fonts_object.set_canvas_size(bbox[2] - bbox[0], bbox[3] - bbox[1]) + ship(-bbox[0], -bbox[1], box) + return self.fonts_object.get_results(box) + + def get_hinting_type(self): + return self.real_backend.get_hinting_type() + + def _switch_to_real_backend(self): + self.fonts_object.mathtext_backend = self.real_backend + self.real_backend.fonts_object = self.fonts_object + self.real_backend.ox = self.bbox[0] + self.real_backend.oy = self.bbox[1] + +class MathtextBackendAggRender(MathtextBackend): + def __init__(self): + self.ox = 0 + self.oy = 0 + MathtextBackend.__init__(self) + def set_canvas_size(self, w, h): MathtextBackend.set_canvas_size(self, w, h) for font in self.fonts_object.get_fonts(): @@ -248,10 +295,12 @@ def render_rect_filled(self, x1, y1, x2, y2): font = self.fonts_object.get_fonts()[0] - font.draw_rect_filled(x1, y1, x2, y2 - 1) + font.draw_rect_filled(x1, y1, x2, max(y2 - 1, y1)) - def get_results(self): - return (self.width, + def get_results(self, box): + return (self.ox, + self.oy, + self.width, self.height, self.fonts_object.get_fonts(), self.fonts_object.get_used_characters()) @@ -259,6 +308,9 @@ def get_hinting_type(self): return LOAD_DEFAULT +def MathtextBackendAgg(): + return MathtextBackendBbox(MathtextBackendAggRender()) + class MathtextBackendPs(MathtextBackend): def __init__(self): self.pswriter = StringIO() @@ -281,7 +333,8 @@ ps = "%f %f %f %f rectfill\n" % (x1, self.height - y2, x2 - x1, y2 - y1) self.pswriter.write(ps) - def get_results(self): + def get_results(self, box): + ship(0, 0, box) return (self.width, self.height, self.pswriter, @@ -302,7 +355,8 @@ def render_rect_filled(self, x1, y1, x2, y2): self.rects.append((x1, self.height - y2, x2 - x1, y2 - y1)) - def get_results(self): + def get_results(self, box): + ship(0, 0, box) return (self.width, self.height, self.glyphs, @@ -324,7 +378,8 @@ self.svg_rects.append( (x1, self.height - y1 + 1, x2 - x1, y2 - y1)) - def get_results(self): + def get_results(self, box): + ship(0, 0, box) svg_elements = Bunch(svg_glyphs = self.svg_glyphs, svg_rects = self.svg_rects) return (self.width, @@ -347,7 +402,8 @@ self.rects.append( (x1, y1 - self.height, x2 - x1, y2 - y1)) - def get_results(self): + def get_results(self, box): + ship(0, 0, box) return (self.width, self.height, self.glyphs, @@ -434,8 +490,8 @@ def get_used_characters(self): return self.used_characters - def get_results(self): - return self.mathtext_backend.get_results() + def get_results(self, box): + return self.mathtext_backend.get_results(box) def get_sized_alternatives_for_symbol(self, fontname, sym): """Override if your font provides multiple sizes of the same @@ -2384,17 +2440,16 @@ font_output = UnicodeFonts(prop, backend) fontsize = prop.get_size_in_points() + # This is a class variable so we don't rebuild the parser # with each request. if self._parser is None: self.__class__._parser = Parser() + box = self._parser.parse(s, font_output, fontsize, dpi) w, h = box.width, box.height + box.depth - w += 4 - h += 4 font_output.set_canvas_size(w, h) - ship(2, 2, box) - result = font_output.get_results() + result = font_output.get_results(box) self._cache[cacheKey] = result # Free up the transient data structures self._parser.clear() This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <md...@us...> - 2007-08-27 19:34:32
|
Revision: 3742 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=3742&view=rev Author: mdboom Date: 2007-08-27 12:34:23 -0700 (Mon, 27 Aug 2007) Log Message: ----------- Better fontconfig pattern standards compliance. Added experimental (may be removed) fontconfig support. Modified Paths: -------------- trunk/matplotlib/lib/matplotlib/font_manager.py trunk/matplotlib/lib/matplotlib/fontconfig_pattern.py Modified: trunk/matplotlib/lib/matplotlib/font_manager.py =================================================================== --- trunk/matplotlib/lib/matplotlib/font_manager.py 2007-08-27 19:33:45 UTC (rev 3741) +++ trunk/matplotlib/lib/matplotlib/font_manager.py 2007-08-27 19:34:23 UTC (rev 3742) @@ -48,6 +48,8 @@ except ImportError: import pickle +USE_FONTCONFIG = False + verbose = matplotlib.verbose font_scalings = {'xx-small': 0.579, 'x-small': 0.694, 'small': 0.833, @@ -84,13 +86,14 @@ "/System/Library/Fonts/" ] -home = os.environ.get('HOME') -if home is not None: - # user fonts on OSX - path = os.path.join(home, 'Library', 'Fonts') - OSXFontDirectories.append(path) - path = os.path.join(home, '.fonts') - X11FontDirectories.append(path) +if not USE_FONTCONFIG: + home = os.environ.get('HOME') + if home is not None: + # user fonts on OSX + path = os.path.join(home, 'Library', 'Fonts') + OSXFontDirectories.append(path) + path = os.path.join(home, '.fonts') + X11FontDirectories.append(path) def win32FontDirectory(): """Return the user-specified font directory for Win32.""" @@ -609,10 +612,10 @@ family = rcParams['font.' + rcParams['font.family']] if is_string_like(family): family = [family] - slant = rcParams['font.style'] - variant = rcParams['font.variant'] - weight = rcParams['font.weight'] - stretch = rcParams['font.stretch'] + slant = [rcParams['font.style']] + variant = [rcParams['font.variant']] + weight = [rcParams['font.weight']] + stretch = [rcParams['font.stretch']] size = [rcParams['font.size']] file = None @@ -675,32 +678,35 @@ def get_style(self): """Return the font style. Values are: normal, italic or oblique.""" - return self.__props.slant + return self.__props.slant[0] def get_variant(self): """Return the font variant. Values are: normal or small-caps.""" - return self.__props.variant + return self.__props.variant[0] def get_weight(self): """ Return the font weight. See the FontProperties class for a a list of possible values. """ - return self.__props.weight + return self.__props.weight[0] def get_stretch(self): """ Return the font stretch or width. Options are: normal, narrow, condensed, or wide. """ - return self.__props.stretch + return self.__props.stretch[0] def get_size(self): """Return the font size.""" return float(self.__props.size[0]) def get_file(self): - return self.__props.file + if self.__props.file is not None: + return self.__props.file[0] + else: + return None def get_fontconfig_pattern(self): return generate_fontconfig_pattern(self.__props.__dict__) @@ -723,7 +729,7 @@ else: if style not in ('normal', 'italic', 'oblique'): raise ValueError("style must be normal, italic or oblique") - self.__props.slant = style + self.__props.slant = [style] def set_variant(self, variant): """Set the font variant. Values are: normal or small-caps.""" @@ -732,7 +738,7 @@ else: if variant not in ('normal', 'small-caps'): raise ValueError("variant must be normal or small-caps") - self.__props.variant = variant + self.__props.variant = [variant] def set_weight(self, weight): """ @@ -745,7 +751,7 @@ if (weight not in weight_dict and weight not in weight_dict.keys()): raise ValueError("weight is invalid") - self.__props.weight = weight + self.__props.weight = [weight] def set_stretch(self, stretch): """ @@ -755,7 +761,7 @@ if stretch is None: self.__props.__dict__.pop('stretch', None) else: - self.__props.stretch = stretch + self.__props.stretch = [stretch] def set_size(self, size): """Set the font size.""" @@ -774,13 +780,19 @@ self.__props.size = size def set_file(self, file): - self.__props.file = file + if file is None: + self.__props.__dict__.pop('file', None) + else: + self.__props.file = [file] get_size_in_points = get_size def set_fontconfig_pattern(self, pattern): self.__props.__dict__ = self._parse_fontconfig_pattern(pattern) - + + def add_property_pair(self, key, val): + self.__props.setdefault(key, []).append(val) + def copy(self): """Return a deep copy of self""" return FontProperties(_init = self.__props.__dict__) @@ -1026,29 +1038,60 @@ return self.defaultFont return fname +if USE_FONTCONFIG and sys.platform != 'win32': + import re -_fmcache = os.path.join(get_configdir(), 'fontManager.cache') + def fc_match(pattern, fontext): + import commands + ext = "." + fontext + status, output = commands.getstatusoutput('fc-match -sv "%s"' % pattern) + if status == 0: + for match in _fc_match_regex.finditer(output): + file = match.group(1) + if os.path.splitext(file)[1] == ext: + return file + return None -fontManager = None + _fc_match_regex = re.compile(r'\sfile:\s+"(.*)"') + _fc_match_cache = {} + + def findfont(prop, fontext='ttf'): + if not is_string_like(prop): + prop = prop.get_fontconfig_pattern() + cached = _fc_match_cache.get(prop) + if cached is not None: + return cached -def _rebuild(): - global fontManager - fontManager = FontManager() - pickle_dump(fontManager, _fmcache) - verbose.report("generated new fontManager") + result = fc_match(prop, fontext) + if result is None: + result = fc_match(':', fontext) -try: - fontManager = pickle_load(_fmcache) - verbose.report("Using fontManager instance from %s" % _fmcache) -except: - _rebuild() + _fc_match_cache[prop] = result + return result -def findfont(prop, **kw): - global fontManager - font = fontManager.findfont(prop, **kw) - if not os.path.exists(font): - verbose.report("%s returned by pickled fontManager does not exist" % font) +else: + _fmcache = os.path.join(get_configdir(), 'fontManager.cache') + + fontManager = None + + def _rebuild(): + global fontManager + fontManager = FontManager() + pickle_dump(fontManager, _fmcache) + verbose.report("generated new fontManager") + + try: + fontManager = pickle_load(_fmcache) + verbose.report("Using fontManager instance from %s" % _fmcache) + except: _rebuild() - font = fontManager.findfont(prop, **kw) - return font + def findfont(prop, **kw): + global fontManager + font = fontManager.findfont(prop, **kw) + if not os.path.exists(font): + verbose.report("%s returned by pickled fontManager does not exist" % font) + _rebuild() + font = fontManager.findfont(prop, **kw) + return font + Modified: trunk/matplotlib/lib/matplotlib/fontconfig_pattern.py =================================================================== --- trunk/matplotlib/lib/matplotlib/fontconfig_pattern.py 2007-08-27 19:33:45 UTC (rev 3741) +++ trunk/matplotlib/lib/matplotlib/fontconfig_pattern.py 2007-08-27 19:34:23 UTC (rev 3742) @@ -19,7 +19,7 @@ """ import re from matplotlib.pyparsing import Literal, OneOrMore, ZeroOrMore, \ - Optional, Regex, StringEnd, ParseException + Optional, Regex, StringEnd, ParseException, Suppress family_punc = r'\\\-:,' family_unescape = re.compile(r'\\([%s])' % family_punc).sub @@ -89,8 +89,12 @@ ).setParseAction(self._point_sizes) property =( (name - + Literal('=') - + value) + + Suppress(Literal('=')) + + value + + ZeroOrMore( + Suppress(Literal(',')) + + value) + ) | name ).setParseAction(self._property) @@ -142,9 +146,11 @@ if len(tokens) == 1: if tokens[0] in self._constants: key, val = self._constants[tokens[0]] - elif len(tokens) == 3: - key, op, val = tokens - self._properties[key] = val + self._properties.setdefault(key, []).append(val) + else: + key = tokens[0] + val = tokens[1:] + self._properties.setdefault(key, []).extend(val) return [] parse_fontconfig_pattern = FontconfigPatternParser().parse @@ -156,14 +162,9 @@ families = '' size = '' for key, val in d.items(): - if key == 'family': - families = [family_escape(r'\\\1', name) for name in val] - families = ','.join(families) - elif key == 'size': - size = '-' + ','.join([str(x) for x in val]) - elif val is not None: - val = value_escape(r'\\\1', str(val)) - props.append(":%s=%s" % (key, val)) - props = ''.join(props) - - return ''.join([families, size, props]) + if val is not None and val != []: + val = [value_escape(r'\\\1', str(x)) for x in val if x is not None] + if val != []: + val = ','.join(val) + props.append(":%s=%s" % (key, val)) + return ''.join(props) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |