Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 55497bc

Browse files
committed
mathtext prototype
svn path=/trunk/matplotlib/; revision=158
1 parent 0d03c2a commit 55497bc

2 files changed

Lines changed: 56 additions & 0 deletions

File tree

examples/mathtext_demo.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from matplotlib.matlab import *
2+
3+
plot([1,2,3])
4+
xlabel(r'$\Delta_i$')
5+
ylabel(r'$\Delta_{i+1}$')
6+
tex = r'$\cal{R}\prod_{i=\alpha_{i+1}}^\infty a_i\rm{sin}(2 \pi f x_i)$'
7+
text(0.4, 2.6, tex, fontsize=20)
8+
title(r'$\Delta_i \rm{versus} \Delta_{i+1}$', fontsize=15)
9+
savefig('mathtext_demo', dpi=100)
10+
show()

src/ft2font.c

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -592,6 +592,51 @@ FT2Font_write_bitmap(FT2FontObject *self, PyObject *args)
592592

593593
}
594594

595+
596+
char FT2Font_draw_rect__doc__[] =
597+
"draw_bbox(x0, y0, x1, y1)\n"
598+
"\n"
599+
"Draw a rect to the image. It is you responsibility to set the dimensions\n"
600+
"of the image, eg, with set_bitmap_size\n"
601+
"\n"
602+
;
603+
static PyObject *
604+
FT2Font_draw_rect(FT2FontObject *self, PyObject *args)
605+
{
606+
607+
long x0, y0, x1, y1, i=0, j=0;
608+
long width, height;
609+
if (!PyArg_ParseTuple(args, "llll:draw_glyphs_to_bitmap",
610+
&x0, &y0, &x1, &y1))
611+
return NULL;
612+
613+
width = abs(x1-x0);
614+
height = abs(y1-y0);
615+
616+
if ( x0<0 || y0<0 || x1<0 || y1<0 ||
617+
x0>self->image.width || x1>self->image.width ||
618+
y0>self->image.height || y1>self->image.height ) {
619+
PyErr_SetString(PyExc_ValueError,
620+
"rect coords outside image bounds");
621+
return NULL;
622+
}
623+
624+
625+
printf("%ld, %ld, %ld, %ld\n", x0, x1, y0, y1);
626+
for (i=x0; i<x1; ++i) {
627+
self->image.buffer[i + y0*self->image.width] = 255;
628+
self->image.buffer[i + y1*self->image.width] = 255;
629+
}
630+
631+
for (j=y0; j<y1; ++j) {
632+
self->image.buffer[x0 + j*self->image.width] = 255;
633+
self->image.buffer[x1 + j*self->image.width] = 255;
634+
}
635+
636+
Py_INCREF(Py_None);
637+
return Py_None;
638+
}
639+
595640
char FT2Font_draw_glyphs_to_bitmap__doc__[] =
596641
"draw_glyphs_to_bitmap()\n"
597642
"\n"
@@ -736,6 +781,7 @@ FT2Font_draw_glyph_to_bitmap(FT2FontObject *self, PyObject *args)
736781
static PyMethodDef FT2Font_methods[] = {
737782
{"write_bitmap", (PyCFunction)FT2Font_write_bitmap, METH_VARARGS, FT2Font_write_bitmap__doc__},
738783
{"set_bitmap_size", (PyCFunction)FT2Font_set_bitmap_size, METH_VARARGS, FT2Font_load_char__doc__},
784+
{"draw_rect", (PyCFunction)FT2Font_draw_rect, METH_VARARGS, FT2Font_draw_rect__doc__},
739785
{"draw_glyph_to_bitmap", (PyCFunction)FT2Font_draw_glyph_to_bitmap, METH_VARARGS, FT2Font_draw_glyph_to_bitmap__doc__},
740786
{"draw_glyphs_to_bitmap", (PyCFunction)FT2Font_draw_glyphs_to_bitmap, METH_VARARGS, FT2Font_draw_glyphs_to_bitmap__doc__},
741787
{"load_char", (PyCFunction)FT2Font_load_char, METH_VARARGS, FT2Font_load_char__doc__},

0 commit comments

Comments
 (0)