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

Skip to content

Commit 0ff67f7

Browse files
committed
fixed mathtest bounding problem
svn path=/trunk/matplotlib/; revision=168
1 parent cbd0d5e commit 0ff67f7

4 files changed

Lines changed: 61 additions & 15 deletions

File tree

examples/mathtext_demo.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
from matplotlib.matlab import *
22
subplot(111, axisbg='y')
33
plot([1,2,3])
4+
x = arange(0.0, 3.0, 0.1)
5+
#plot(x, sin(2*pi*x))
6+
grid(True)
47
xlabel(r'$\Delta_i$')
58
ylabel(r'$\Delta_{i+1}$')
69
tex = r'$\cal{R}\prod_{i=\alpha_{i+1}}^\infty a_i\rm{sin}(2 \pi f x_i)$'
7-
text(1, 2.6, tex, fontsize=20, color='r')
10+
#tex = r'$\alpha\beta\gamma$'
11+
text(1, 2.6, tex, fontsize=20)
812
title(r'$\Delta_i \rm{versus} \Delta_{i+1}$', fontsize=15)
913
savefig('mathtext_demo', dpi=100)
1014
show()

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
be built by setting the appropriate flag below.
44
"""
55

6-
# build the freetype2 interface - this is required for mathtext and
7-
# the agg backends. Requires freetype2, and libz
6+
# build the freetype2 interface - this is required for mathtext
7+
# Requires freetype2, and libz
88
BUILD_FT2FONT = 1
99

1010
# Build the fonttools and TTFQuery packages, required by the Paint,

src/ft2font.c

Lines changed: 46 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,41 @@ FT2Font_set_text(FT2FontObject *self, PyObject *args)
434434

435435
}
436436

437+
char FT2Font_get_glyph__doc__[] =
438+
"get_glyph(num)\n"
439+
"\n"
440+
"Return the glyph object with num num\n"
441+
;
442+
GlyphObject * FT2Font_get_glyph(FT2FontObject *self, PyObject *args){
443+
int num;
444+
if (!PyArg_ParseTuple(args, "i:get_glyph", &num))
445+
return NULL;
446+
447+
if ( num >= self->num_glyphs) {
448+
PyErr_SetString(PyExc_ValueError,
449+
"Glyph index out of range");
450+
return NULL;
451+
452+
}
453+
GlyphObject *gm = self->gms[num];
454+
Py_INCREF(gm);
455+
return gm;
456+
}
457+
458+
char FT2Font_get_num_glyphs__doc__[] =
459+
"get_num_glyphs()\n"
460+
"\n"
461+
"Return the number of loaded glyphs\n"
462+
;
463+
PyObject * FT2Font_get_num_glyphs(FT2FontObject *self, PyObject *args){
464+
465+
if (!PyArg_ParseTuple(args, ":get_num_glyph"))
466+
return NULL;
467+
468+
return Py_BuildValue("l", self->num_glyphs);
469+
470+
}
471+
437472
char FT2Font_load_char__doc__[] =
438473
"load_char(charcode)\n"
439474
"\n"
@@ -453,6 +488,7 @@ static GlyphObject *
453488
FT2Font_load_char(FT2FontObject *self, PyObject *args)
454489
{
455490
//load a char using the unsigned long charcode
491+
GlyphObject *gm;
456492
long charcode;
457493
int error;
458494
if (!PyArg_ParseTuple(args, "l:load_char", &charcode))
@@ -473,10 +509,7 @@ FT2Font_load_char(FT2FontObject *self, PyObject *args)
473509
return NULL;
474510
}
475511

476-
477-
478512

479-
GlyphObject *gm;
480513
gm = PyObject_New(GlyphObject, &Glyph_Type);
481514

482515

@@ -490,8 +523,6 @@ FT2Font_load_char(FT2FontObject *self, PyObject *args)
490523
FT_BBox bbox;
491524
FT_Glyph_Get_CBox( self->glyphs[self->num_glyphs], ft_glyph_bbox_subpixels, &bbox );
492525

493-
gm->glyph_num = self->num_glyphs++;
494-
495526
gm->x_attr = NULL;
496527

497528
SETATTR(gm, Glyph_setattr, "width", PyInt_FromLong, self->face->glyph->metrics.width);
@@ -508,12 +539,18 @@ FT2Font_load_char(FT2FontObject *self, PyObject *args)
508539
("(llll)",
509540
bbox.xMin, bbox.yMin, bbox.xMax, bbox.yMax );
510541
SETATTR_PYOBJ(gm, Glyph_setattr, "bbox", pbbox);
542+
gm->glyph_num = self->num_glyphs;
511543

512-
513-
544+
Py_INCREF(gm); //incref to store in list
545+
self->gms[self->num_glyphs] = gm;
546+
self->num_glyphs++;
514547
return gm;
548+
515549
}
516550

551+
552+
553+
517554
char FT2Font_get_width_height__doc__[] =
518555
"w, h = get_width_height()\n"
519556
"\n"
@@ -801,6 +838,8 @@ static PyMethodDef FT2Font_methods[] = {
801838
{"draw_rect", (PyCFunction)FT2Font_draw_rect, METH_VARARGS, FT2Font_draw_rect__doc__},
802839
{"draw_glyph_to_bitmap", (PyCFunction)FT2Font_draw_glyph_to_bitmap, METH_VARARGS, FT2Font_draw_glyph_to_bitmap__doc__},
803840
{"draw_glyphs_to_bitmap", (PyCFunction)FT2Font_draw_glyphs_to_bitmap, METH_VARARGS, FT2Font_draw_glyphs_to_bitmap__doc__},
841+
{"get_glyph", (PyCFunction)FT2Font_get_glyph, METH_VARARGS, FT2Font_get_glyph__doc__},
842+
{"get_num_glyphs", (PyCFunction)FT2Font_get_num_glyphs, METH_VARARGS, FT2Font_get_num_glyphs__doc__},
804843
{"image_as_str", (PyCFunction)FT2Font_image_as_str, METH_VARARGS, FT2Font_image_as_str__doc__},
805844
{"load_char", (PyCFunction)FT2Font_load_char, METH_VARARGS, FT2Font_load_char__doc__},
806845
{"set_text", (PyCFunction)FT2Font_set_text, METH_VARARGS, FT2Font_set_text__doc__},

src/ft2font.h

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ typedef struct {
1515
unsigned long height;
1616
} FT2_Image;
1717

18+
typedef struct {
19+
PyObject_HEAD
20+
PyObject *x_attr; /* Attributes dictionary */
21+
int glyph_num;
22+
} GlyphObject;
23+
1824

1925
typedef struct {
2026
PyObject_HEAD
@@ -26,18 +32,15 @@ typedef struct {
2632
FT_Error error;
2733
FT_Glyph glyphs[MAXGLYPHS];
2834
FT_Vector pos [MAXGLYPHS];
35+
36+
GlyphObject *gms[MAXGLYPHS];
2937
char *text;
3038
double angle;
3139
int num_chars;
3240
int num_glyphs;
3341
FT2_Image image;
3442
} FT2FontObject;
3543

36-
typedef struct {
37-
PyObject_HEAD
38-
PyObject *x_attr; /* Attributes dictionary */
39-
int glyph_num;
40-
} GlyphObject;
4144

4245

4346
#endif

0 commit comments

Comments
 (0)