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

Skip to content

Commit 485af83

Browse files
committed
added vertical mathtext for agg
svn path=/trunk/matplotlib/; revision=406
1 parent 385e498 commit 485af83

7 files changed

Lines changed: 85 additions & 69 deletions

File tree

CHANGELOG

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
New entries should be added at the top
22

3+
2004-07-19 Added vertical mathtext - thanks Jim Benson! - JDH
4+
35
2004-07-16 Added ps/eps/svg savefig options to wx and gtk JDH
46

57
2004-07-15 Fixed python framework tk finder in setupext.py - JDH

TODO

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -469,3 +469,8 @@
469469

470470
-- font dict in wx is broken w/ respect to new font names
471471

472+
-- update nav section of tutorial
473+
474+
-- track down transforms memleak
475+
476+
-- make sure you handle cacheing of rotated mathtext properly

examples/mathtext_demo.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,13 @@
1616
#plot(x, sin(2*pi*x))
1717
grid(True)
1818
xlabel(r'$\Delta_i^j$', fontsize=20)
19-
ylabel(r'$\Delta_{i+1}^j$', fontsize=20, # no rotation yet for mathtext
20-
verticalalignment='center',
21-
horizontalalignment='right',
22-
rotation='horizontal')
19+
ylabel(r'$\Delta_{i+1}^j$', fontsize=20)
2320
tex = r'$\cal{R}\prod_{i=\alpha_{i+1}}^\infty a_i\rm{sin}(2 \pi f x_i)$'
2421
#tex = r'$\cal{R}\prod^\infty a_i\rm{sin}(2 \pi f x_i)$'
2522

2623
#tex = r'$\alpha\beta\gamma$'
2724
text(1, 2.6, tex, fontsize=20)
2825
title(r'$\Delta_i^j \hspace{0.4} \rm{versus} \hspace{0.4} \Delta_{i+1}^j$', fontsize=20)
29-
#savefig('mathtext_demo_small', dpi=100)
30-
savefig('mathtext_demo_large', dpi=300)
26+
savefig('mathtext_demo')
3127

3228
show()

examples/scatter_demo2.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,11 @@
1313
set(p, 'alpha', 0.75)
1414
set(gca(), 'xticks', arange(-0.06, 0.061, 0.02))
1515
set(gca(), 'yticks', arange(-0.06, 0.061, 0.02))
16-
xlabel(r'$\Delta_i$', fontsize='x-large')
17-
ylabel(r'$\Delta_{i+1}$', fontsize='x-large',
18-
verticalalignment='center',
19-
horizontalalignment='right',
20-
rotation='horizontal'
21-
)
16+
xlabel(r'$\Delta_i$', size='x-large')
17+
ylabel(r'$\Delta_{i+1}$', size='x-large')
2218
title(r'Volume and percent change')
2319
grid(True)
24-
savefig('scatter_demo2')
20+
#savefig('scatter_demo2')
2521

2622
show()
2723

setupext.py

Lines changed: 10 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
'linux2' : ['/usr/local', '/usr',],
3737
'linux' : ['/usr/local', '/usr',],
3838
'darwin' : [os.getenv('MPLIB_BASE') or '/usr/local', '/usr', '/sw'],
39-
'freebsd4' : [os.getenv('MPLIB_BASE') or '/usr/local', '/usr'],
39+
'freebsd4' : [os.getenv('MBLIB_BASE') or '/usr/local', '/usr'],
4040
'sunos5' : [os.getenv('MPLIB_BASE') or '/usr/local',],
4141
}
4242

@@ -212,59 +212,15 @@ def add_tk_flags(module):
212212
module.include_dirs.extend(['win32_static/include/tcl'])
213213
module.library_dirs.extend(['C:/Python23/dlls'])
214214
module.libraries.extend(['tk84', 'tcl84'])
215-
return
216-
217-
elif sys.platform == 'darwin' :
218-
# this config section lifted directly from Imaging - thanks to
219-
# the effbot!
220-
221-
# First test for a MacOSX/darwin framework install
222-
from os.path import join, exists
223-
framework_dirs = [
224-
'/System/Library/Frameworks/',
225-
'/Library/Frameworks',
226-
join(os.getenv('HOME'), '/Library/Frameworks')
227-
]
228-
229-
# Find the directory that contains the Tcl.framwork and Tk.framework
230-
# bundles.
231-
# XXX distutils should support -F!
232-
for F in framework_dirs:
233-
# both Tcl.framework and Tk.framework should be present
234-
for fw in 'Tcl', 'Tk':
235-
if not exists(join(F, fw + '.framework')):
236-
break
237-
else:
238-
# ok, F is now directory with both frameworks. Continure
239-
# building
240-
tk_framework_found = 1
241-
break
242-
if tk_framework_found:
243-
# For 8.4a2, we must add -I options that point inside the Tcl and Tk
244-
# frameworks. In later release we should hopefully be able to pass
245-
# the -F option to gcc, which specifies a framework lookup path.
246-
#
247-
tk_include_dirs = [
248-
join(F, fw + '.framework', H)
249-
for fw in 'Tcl', 'Tk'
250-
for H in 'Headers', 'Versions/Current/PrivateHeaders'
251-
]
252-
253-
# For 8.4a2, the X11 headers are not included. Rather than include a
254-
# complicated search, this is a hard-coded path. It could bail out
255-
# if X11 libs are not found...
256-
# tk_include_dirs.append('/usr/X11R6/include')
257-
frameworks = ['-framework', 'Tcl', '-framework', 'Tk']
258-
module.include_dirs.extend(tk_include_dirs)
259-
module.extra_link_args.extend(frameworks)
260-
module.extra_compile_args.extend(frameworks)
261-
return
262-
263-
# you're still here? ok we'll try it this way
264-
o = find_tcltk()
265-
module.include_dirs.extend([o.tcl_inc, o.tk_inc])
266-
module.library_dirs.extend([o.tcl_lib, o.tk_lib])
267-
module.libraries.extend(['tk'+o.tkv, 'tcl'+o.tkv])
215+
else:
216+
o = find_tcltk()
217+
if sys.platform == 'darwin' and '/Library/Framework' in o.tk_lib:
218+
module.extra_link_args.extend(['-framework','Tcl'])
219+
module.extra_link_args.extend(['-framework','Tk'])
220+
else:
221+
module.include_dirs.extend([o.tcl_inc, o.tk_inc])
222+
module.library_dirs.extend([o.tcl_lib, o.tk_lib])
223+
module.libraries.extend(['tk'+o.tkv, 'tcl'+o.tkv])
268224

269225

270226
def add_windowing_flags(module):

src/ft2font.cpp

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
FT_Library _ft2Library;
99

10-
FT2Image::FT2Image() : buffer(NULL) {}
10+
FT2Image::FT2Image() : bRotated(false), buffer(NULL) {}
1111
FT2Image::~FT2Image() {delete [] buffer; buffer=NULL;}
1212

1313
Glyph::Glyph( const FT_Face& face, const FT_Glyph& glyph, size_t ind) :
@@ -147,6 +147,62 @@ FT2Font::~FT2Font()
147147
}
148148
}
149149

150+
151+
char FT2Font::horiz_image_to_vert_image__doc__[] =
152+
"horiz_image_to_vert_image()\n"
153+
"\n"
154+
"Copies the horizontal image (w, h) into a\n"
155+
"new image of size (h,w)\n"
156+
"This is equivalent to rotating the original image\n"
157+
"by 90 degrees ccw\n"
158+
;
159+
160+
Py::Object
161+
FT2Font::horiz_image_to_vert_image(const Py::Tuple & args) {
162+
163+
// If we have already rotated, just return.
164+
165+
if (image.bRotated)
166+
return Py::Object();
167+
168+
169+
long width = image.width, height = image.height;
170+
171+
long newWidth = image.height;
172+
long newHeight = image.width;
173+
174+
long numBytes = image.width * image.height;
175+
176+
unsigned char * buffer = new unsigned char [numBytes];
177+
178+
long i, j, k, offset, nhMinusOne;
179+
180+
nhMinusOne = newHeight-1;
181+
182+
for (i=0; i<height; i++) {
183+
184+
offset = i*width;
185+
186+
for (j=0; j<width; j++) {
187+
188+
k = nhMinusOne - j;
189+
190+
buffer[i + k*newWidth] = image.buffer[j + offset];
191+
192+
}
193+
194+
}
195+
196+
delete [] image.buffer;
197+
image.buffer = buffer;
198+
image.width = newWidth;
199+
image.height = newHeight;
200+
image.bRotated = true;
201+
202+
return Py::Object();
203+
204+
}
205+
150206
int
151207
FT2Font::setattr( const char *name, const Py::Object &value ) {
152208
_VERBOSE("FT2Font::setattr");
@@ -1104,6 +1160,9 @@ FT2Font::init_type() {
11041160
FT2Font::get_ps_font_info__doc__);
11051161
add_varargs_method("get_sfnt_table", &FT2Font::get_sfnt_table,
11061162
FT2Font::get_sfnt_table__doc__);
1163+
add_varargs_method("horiz_image_to_vert_image",
1164+
&FT2Font::horiz_image_to_vert_image,
1165+
FT2Font::horiz_image_to_vert_image__doc__);
11071166

11081167
behaviors().supportGetattr();
11091168
behaviors().supportSetattr();

src/ft2font.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ class FT2Image {
2323
public:
2424
FT2Image();
2525
~FT2Image();
26+
bool bRotated;
2627
unsigned char *buffer;
2728
unsigned long width;
2829
unsigned long height;
@@ -67,6 +68,7 @@ class FT2Font : public Py::PythonExtension<FT2Font> {
6768
Py::Object get_name_index(const Py::Tuple & args);
6869
Py::Object get_ps_font_info(const Py::Tuple & args);
6970
Py::Object get_sfnt_table(const Py::Tuple & args);
71+
Py::Object horiz_image_to_vert_image(const Py::Tuple & args);
7072
int setattr( const char *_name, const Py::Object &value );
7173
Py::Object getattr( const char *_name );
7274
FT2Image image;
@@ -108,7 +110,7 @@ class FT2Font : public Py::PythonExtension<FT2Font> {
108110
static char get_name_index__doc__[];
109111
static char get_ps_font_info__doc__[];
110112
static char get_sfnt_table__doc__[];
111-
113+
static char horiz_image_to_vert_image__doc__[];
112114
};
113115

114116
// the extension module

0 commit comments

Comments
 (0)