8000 finished agg backend · matplotlib/matplotlib@29dfcd2 · GitHub
[go: up one dir, main page]

Skip to content

Commit 29dfcd2

Browse files
committed
finished agg backend
svn path=/trunk/matplotlib/; revision=141
1 parent abaedf1 commit 29dfcd2

File tree

12 files changed

+1086
-24
lines changed

12 files changed

+1086
-24
lines changed

LICENSE_PAINT

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/******************************************************************
2+
Copyright 2000 by Object Craft P/L, Melbourne, Australia.
3+
4+
All Rights Reserved
5+
6+
Permission to use, copy, modify, and distribute this software and its
7+
documentation for any purpose and without fee is hereby granted,
8+
provided that the above copyright notice appear in all copies and that
9+
both that copyright notice and this permission notice appear in
10+
supporting documentation, and that the name of Object Craft
11+
is not be used in advertising or publicity pertaining to
12+
distribution of the software without specific, written prior
13+
permission.
14+
15+
OBJECT CRAFT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
16+
INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
17+
EVENT SHALL OBJECT CRAFT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
18+
CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
19+
USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
20+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
21+
PERFORMANCE OF THIS SOFTWARE.
22+
23+
******************************************************************/

MANIFEST.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
include LICENSE API_CHANGES CHANGELOG KNOWN_BUGS GOALS INSTALL
1+
include LICENSE LICENSE_PAINT API_CHANGES CHANGELOG KNOWN_BUGS GOALS INSTALL
22
include INTERACTIVE TODO
33
include Makefile MANIFEST.in MANIFEST
44
include __init__.py setupext.py setup.py

TODO

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,12 @@
188188

189189
-- DONE 2004-02-11 lost backend_gtk rotate_text fix - find it!
190190

191-
-- GTK clipping broken?
191+
-- DONE GTK clipping broken?
192192

193-
-- GTK facecolor reversed for line markers
193+
-- DONE GTK facecolor reversed for line markers
194194

195+
-- figure clear
196+
197+
-- gd filling is not working like I think - see arctest
198+
199+
-- gd edge clipping is whacked - see arc test

examples/alignment_test.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@
3030
transx=ax.xaxis.transAxis,
3131
transy=ax.yaxis.transAxis)
3232

33+
ax.text(left, bottom, 'left bottom',
34+
horizontalalignment='left',
35+
verticalalignment='bottom',
36+
transx=ax.xaxis.transAxis,
37+
transy=ax.yaxis.transAxis)
38+
3339
ax.text(right, top, 'right bottom',
3440
horizontalalignment='right',
3541
verticalalignment='bottom',
@@ -55,6 +61,13 @@
5561
transx=ax.xaxis.transAxis,
5662
transy=ax.yaxis.transAxis)
5763

64+
ax.text 9E81 (left, 0.5*(bottom+top), 'leftcenter',
65+
horizontalalignment='left',
66+
verticalalignment='center',
67+
rotation='vertical',
68+
transx=ax.xaxis.transAxis,
69+
transy=ax.yaxis.transAxis)
70+
5871
ax.text(0.5*(left+right), 0.5*(bottom+top), 'middle',
5972
horizontalalignment='center',
6073
verticalalignment='center',

examples/line_styles.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,5 @@
2121
if not gca().is_last_row():
2222
set(gca(), 'xticklabels', [])
2323

24+
savefig('line_styles', dpi=300)
2425
show()

examples/scatter_demo2.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
volume = 0.003*intc.volume[:-2]/intc.volume[0]
1010
close = 0.003*intc.close[:-2]/0.003*intc.open[:-2]
1111
p = scatter(delta1[:-1], delta1[1:], c=close, s=volume)
12-
set(p, 'alpha', 0.5)
12+
set(p, 'alpha', 0.75)
1313
set(gca(), 'xticks', arange(-0.06, 0.061, 0.02))
1414
set(gca(), 'yticks', arange(-0.06, 0.061, 0.02))
1515
xlabel('Delta day i')

examples/simple_plot.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
s = sin(2*2*pi*t)
66
plot(t, s, 'x')
77

8-
98
xlabel('time (s)')
109
ylabel('voltage (mV)')
1110
title('About as simple as it gets, folks')

setup.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@
1515
if 0: # how do I add '--with-gtkgd' flag checking?
1616
build_gtkgd(ext_modules)
1717

18-
if 1:
19-
build_agg(ext_modules)
18+
if 1:
19+
aggsrc = '/home/jdhunter/c/src/agg2'
20+
build_agg(ext_modules, aggsrc)
2021

2122
setup(name="matplotlib",
2223
version= '0.50k',

setupext.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
"""
32
Some helper functions for building the C extensions
43
"""
@@ -49,24 +48,24 @@ def build_gtkgd(ext_modules):
4948
ext_modules.append(module)
5049

5150

52-
def add_agg_flags(module):
51+
def add_agg_flags(module, aggpath):
5352
'Add the module flags to build extensions which use gtk'
5453
include_dirs = [
55-
'src', '/usr/X11R6/include', '/home/jdhunter/c/src/agg2/include',
54+
'src', '/usr/X11R6/include', os.path.join(aggpath, 'include'),
5655
'/usr/include/freetype1']
57-
library_dirs = ['/usr/X11R6/lib', '/home/jdhunter/c/src/agg2/src']
56+
library_dirs = ['/usr/X11R6/lib', os.path.join(aggpath, 'src')]
5857
libraries = ['agg', 'X11', 'm', 'ttf', 'png', 'z']
5958
extra_link_args = []
6059
module.include_dirs.extend(include_dirs)
6160
module.libraries.extend(libraries)
6261
module.library_dirs.extend(library_dirs)
6362
module.extra_link_args.extend(extra_link_args)
6463

65-
def build_agg(ext_modules):
64+
def build_agg(ext_modules, aggsrc):
6665
module = Extension(
6766
'matplotlib.backends._backend_agg',
6867
['src/_backend_agg.cpp', 'src/font.cpp'],
6968
)
70-
add_agg_flags(module)
69+
add_agg_flags(module, aggsrc)
7170
ext_modules.append(module)
7271

src/_backend_agg.cpp

Lines changed: 122 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
#include "_backend_agg.h"
1+
// font and text handling was lifted almost verbatim from module
2+
// paint. The paint license is in LICENSE_PAINT that accompanies the
3+
// matplotlib src distribution
24

35
#include <cstring>
4-
5-
6-
// font stuff from paint
6+
#include "_backend_agg.h"
77

88
static char agg_font__doc__[] =
99
"Font(filename, size = 12, rotate = 0)\n"
@@ -299,20 +299,18 @@ extern "C" staticforward PyTypeObject RendererAgg_Type;
299299
static RendererAggObject *
300300
newRendererAggObject(PyObject *args)
301301
{
302-
printf("newRendererAggObject start\n");
302+
//printf("newRendererAggObject start\n");
303303
RendererAggObject *self;
304304
int width, height;
305305
double dpi;
306306
if (!PyArg_ParseTuple(args, "iid:RendererAgg", &width, &height, &dpi))
307307
return NULL;
308308

309-
printf("newRendererAggObject 1\n");
310309

311310
self = PyObject_New(RendererAggObject, &RendererAgg_Type);
312311
if (self == NULL)
313312
return NULL;
314313

315-
printf("newRendererAggObject 2\n");
316314

317315
unsigned stride(width*4); //TODO, pixfmt call to make rgba type independet
318316
size_t NUMBYTES(width*height*4);
@@ -333,9 +331,6 @@ newRendererAggObject(PyObject *args)
333331
self->NUMBYTES = NUMBYTES;
334332
self->x_attr = NULL;
335333

336-
//draw(self);
337-
//print(self); //calling this makes agg.raw work ok. Is is path? Something
338-
printf("newRendererAggObject end\n");
339334
return self;
340335
}
341336

@@ -411,6 +406,121 @@ RendererAgg_draw_ellipse(RendererAggObject *renderer, PyObject* args) {
411406

412407
}
413408

409+
char RendererAgg_draw_polygon__doc__[] =
410+
"draw_polygon(gcEdge, gdFace, points)\n"
411+
"\n"
412+
"Draw a polygon using the gd edge and face. point is a sequence of x,y tuples";
413+
414+
static PyObject *
415+
RendererAgg_draw_polygon(RendererAggObject *renderer, PyObject* args) {
416+
417+
PyObject *gcEdge, *gcFace, *points;
418+
419+
if (!PyArg_ParseTuple(args, "OOO", &gcEdge, &gcFace, &points))
420+
return NULL;
421+
if (! _gc_set_clip_rect(gcEdge, renderer)) return NULL;
422+
double* plw = _gc_get_linewidth(gcEdge);
423+
if (plw==NULL) return NULL;
424+
double lw = _points_to_pixels(renderer, *plw);
425+
delete plw;
426+
//printf("draw_rectangle inited\n");
427+
agg::path_storage path;
428+
429+
PyObject *tup; // the x,y tup
430+
PyObject *xo, *yo; // xi, yi in tup
431+
PyObject *xf, *yf; // xi, yi in tup as Py_Float
432+
double x, y; // finally, the damned numbers
433+
434+
int Npoints = PySequence_Length(points);
435+
436+
if (Npoints==-1) {
437+
PyErr_SetString(PyExc_ValueError,
438+
"points must be a sequence type");
439+
return NULL;
440+
}
441+
442+
tup = PySequence_GetItem( points, 0);
443+
int N = PySequence_Length(tup);
444+
445+
if (N!=2) {
446+
PyErr_SetString(PyExc_ValueError,
447+
"seq must be a sequence of length 2 tuples");
448+
Py_XDECREF(tup);
449+
return NULL;
450+
}
451+
452+
xo = PySequence_GetItem( tup, 0);
453+
yo = PySequence_GetItem( tup, 1);
454+
Py_XDECREF(tup);
455+
456+
xf = PyNumber_Float( xo );
457+
yf = PyNumber_Float( yo );
458+
Py_XDECREF(xo); Py_XDECREF(yo);
459+
460+
461+
x = PyFloat_AsDouble(xf);
462+
y = PyFloat_AsDouble(yf);
463+
Py_XDECREF(xf); Py_XDECREF(yf);
464+
465+
y = renderer->rbase->height() - y;
466+
path.move_to(x, y);
467+
468+
for (int i=1; i<Npoints; ++i) {
469+
470+
tup = PySequence_GetItem(points, i);
471+
int N = PySequence_Length(tup);
472+
473+
if (N!=2) {
474+
PyErr_SetString(PyExc_ValueError,
475+
"points must be a sequence of length 2 tuples");
476+
Py_XDECREF(tup);
477+
return NULL;
478+
}
479+
480+
xo = PySequence_GetItem( tup, 0);
481+
yo = PySequence_GetItem( tup, 1);
482+
Py_XDECREF(tup);
483+
484+
xf = PyNumber_Float( xo );
485+
yf = PyNumber_Float( yo );
486+
Py_XDECREF(xo); Py_XDECREF(yo);
487+
488+
x = PyFloat_AsDouble(xf);
489+
y = PyFloat_AsDouble(yf);
490+
Py_XDECREF(xf); Py_XDECREF(yf);
491+
492+
y = renderer->rbase->height() - y;
493+
path.line_to(x, y);
494+
495+
}
496+
path.close_polygon();
497+
498+
499+
if (gcFace != Py_None) {
500+
//fill the face
501+
agg::rgba* color = _gc_get_color(gcFace);
502+
if (color==NULL) return NULL;
503+
renderer->ren->color(*color);
504+
renderer->ras->add_path(path);
505+
renderer->ras->render(*renderer->sline, *renderer->ren);
506+
delete color;
507+
}
508+
509+
//now fill the edge
510+
agg::conv_stroke<agg::path_storage> stroke(path);
511+
stroke.width(lw);
512+
//printf("setting edge wid %1.2f\n", lw);
513+
agg::rgba* color = _gc_get_color(gcEdge);
514+
if (color==NULL) return NULL;
515+
renderer->ren->color(*color);
516+
//self->ras->gamma(agg::gamma_power(gamma));
517+
renderer->ras->add_path(stroke);
518+
renderer->ras->render(*renderer->sline, *renderer->ren);
519+
delete color;
520+
Py_INCREF(Py_None);
521+
return Py_None;
522+
523+
}
414524

415525
static PyObject *
416526
RendererAgg_draw_rectangle(RendererAggObject *renderer, PyObject* args) {
@@ -450,7 +560,7 @@ RendererAgg_draw_rectangle(RendererAggObject *renderer, PyObject* args) {
450560
//now fill the edge
451561
agg::conv_stroke<agg::path_storage> stroke(path);
452562
stroke.width(lw);
453-
printf("setting edge wid %1.2f\n", lw);
563+
//printf("setting edge wid %1.2f\n", lw);
454564
agg::rgba* color = _gc_get_color(gcEdge);
455565
if (color==NULL) return NULL;
456566
renderer->ren->color(*color);
@@ -760,6 +870,7 @@ static PyMethodDef RendererAgg_methods[] = {
760870

761871
{ "draw_ellipse", (PyCFunction)RendererAgg_draw_ellipse, METH_VARARGS},
762872
{ "draw_rectangle", (PyCFunction)RendererAgg_draw_rectangle, METH_VARARGS},
873+
{ "draw_polygon", (PyCFunction)RendererAgg_draw_polygon, METH_VARARGS},
763874
{ "draw_lines", (PyCFunction)RendererAgg_draw_lines, METH_VARARGS},
764875
{ "draw_text", (PyCFunction)RendererAgg_draw_text, METH_VARARGS, RendererAgg_draw_text__doc__},
765876
{ "write_rgba", (PyCFunction)RendererAgg_write_rgba, METH_VARARGS},

0 commit comments

Comments
 (0)
0