[matplotlib-devel] First SVN commit (for me and mathtext2.py :)

2006-08-20 Thread Edin Salković

The SoC deadline (for code) is tommorow (Aug 21st.), so I decided to commit
what I have done till now to the repository.

JDH is going on a vacation and will not be able to review it for at
least a week,
but I had to commit it before 21st. Aug - that's the SoC rules. Hopefully,
I'll be adding new stuff the next week (and after), but that doesn't
count as part of SoC anymore...

Since this is my first commit, can anyone please test it. I tested it
only on my windows box.

I changed
__init__.py,
mathtext.py
CHANGELOG

I added
mathtext2.py
mathtext2_demo.py

Anyone who wants to test the new mathtext2 has to add the following line(s)
to the matplotlibrc (mathtext2 is disabled by default):

mathtext2:   True# Needed to enable the new mathtext

# Font lines, feel free to change or uncomment (BaKoMa is used by default)
mathtext.rm :   FreeSerif.ttf
mathtext.it :   FreeSerifItalic.ttf # Text italic
mathtext.tt :   FreeMono.ttf# Typewriter (monospaced)
mathtext.mit:   FreeSerifItalic.ttf # Math italic
mathtext.cal:   FreeSansOblique.ttf # Caligraphic
mathtext.nonascii:  FreeSerif.ttf # Used for \sum, \infty etc.

The FreeFont fonts (or any other for that matter) have to be downloaded and put
into the mpl-data dir. The default settingsuse the current bakoma
fonts, and they play pretty well with FreeSerif.ttf as the nonascii
(unicode) font.

so I recommend you just put the line
mathtext.nonascii:  FreeSerif.ttf

and comment out the rest (experiment a little with fonts).

Tonight I plan to add support for fractions. Beware that the only
supported backend for now is Agg.

mathtext2_demo.py is attached


mathtext2_demo.py
Description: Binary data
-
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642___
Matplotlib-devel mailing list
Matplotlib-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-devel


Re: [matplotlib-devel] Mathtext questions, continued...

2006-08-20 Thread Edin Salković
Here are the reasons for rewriting mathtext2 that I can come up with:

 * One of the reasons I started the complete rewrite of the parser is that
I'm a newbie at parsing, and I wanted to try it out a bit. I didn't understand
why was it so difficult to parse TeX (or anything a little bit complicated
for that matter). Well, now I know ;)

 * The other reason was that I didn't understand fully the current parsing
code, or more precisely, the part when what's interpreted get's rendered.
And I'm not talking about glyphs, but about the complex constructs (scripts,
frac's etc.)

 * The third reason was that I can now try out in pararel the new and the old
code. Also, because I'm not touching the PS and SVG backends for now we can
have the following code in the current mathtext:

if rcParams[some_parameter]:
   from matplotlib.mathtext2 import math_parse_s_ft2font
else:
   math_parse_s_ft2font = math_parse_s_ft2font_common('BMP')
math_parse_s_ft2font_svg = math_parse_s_ft2font_common('SVG')
math_parse_s_ps = math_parse_s_ft2font_common('PS')
math_parse_s_pdf = math_parse_s_ft2font_common('PDF')

Also, I thought that the author of the current code base did some design
mistakes at the begining. And, being a developer newbie, it's a lot easier
to start things from scratch, than make fixes to old stuff you don't
understand well.

As for the mathtext_demo.py part, even real TeX can't handle it :). The point
is that, i.e. \cal sets the current fontface to "cal", and the change is
propagated till the end of the current scope (or untill it hits \rm, for
example). Old mathtext applies it only to the first item after the command.

I promise that I'll post more about the implementation in a day or two.
I'll also post screenshots (TeX/mathtext/mathtext2 shootout).

Cheers,
Edin

On 8/18/06, John Hunter <[EMAIL PROTECTED]> wrote:
> > "Edin" == Edin Salkovi§ <[EMAIL PROTECTED]> writes:
>
> Edin> Hi all, Please John, take some time before SciPy conf to
> Edin> answer at least some of this questions, because the SoC
> Edin> deadline (21st August) is *very* near.
>
> Alas, I am already here and have been a little out of email contact
> while traveling.  Sorry for the delay.
>
> Edin> 1) I'm having some problems regarding FT2Font.  The problem
> Edin> is when I instantiate FT2Font like: font = FT2Font(filename)
> Edin> and when I call it's method font.set_text("Some text"), and
> Edin> afterwards, font.draw_glyphs_to_bitmap(), the latter simply
> Edin> deletes every glyph that was drawn before it, and just
> Edin> paints in the internal image buffer the text that was passed
> Edin> on last invocation of set_text (or load_char).
>
> This is a feature, not a bug :-)  You can clear the image buffer if
> you want with the clear method, as we do in the mathtexy code
>
> for fontface in self.fonts.values():
> fontface.clear()
>
> Edin> This is a pain, because draw_glyphs_to_bitmap implements the
> Edin> layout (with kerning etc.), but if one wants to paint
> Edin> several words in different x,y positions in the same image
> Edin> buffer, he has to do the layout for every character in every
> Edin> word manually via draw_glyph_to_bitmap(x, y, glyph) (like
> Edin> you did with the BaKoMa fonts in mathtext).
>
> Edin> Why hasn't draw_glyphs_to_bitmap been implemented so that it
> Edin> takes x, y as arguments (draw_glyphs_to_bitmap(x, y)) and
> Edin> leaves the image buffer intact (as does
> Edin> draw_glyph_to_bitmap)?
>
> You can add optional x and y args to draw_glyphs_to_bitmap if you need
> them.  Just make sure any changes you make pass
> examples/backend_driver.py and unit/memleak_hawaii3.py
>
> Edin> 2) As I have said before, I have started the complete
> Edin> rewrite of mathtext (the parsing stuff etc.). I have
> Edin> completely removed the dependency on pyparsing (please don't
> Edin> yell at me :), and I was wondering about how much of TeX
>
> OK, I won't yell.  Quietly scold maybe :-)
>
> I am skeptical of your -- or anyone's except Robert's -- ability to
> parse TeX mathematical expressions w/o a true recursive descent
> parser.  I took a look at your code but w/o any running examples I
> could not test it.  From reading it, I do not think it will be able to
> handle the deeply recursive structures that are currently supported by
> the existing, working parser.  Can you handle recursively nested
> super/sub scripts?  Can it parse this
>
>   tex = r'$\cal{R}\prod_{i=\alpha_{i+1}}^\infty a_i\rm{sin}(2 \pi f x_i)$'
>
>
> If so, I apologize for my skepticism, but my working assumption is you
> will need a proper parser to parse tex and string methods aren't going
> to get you there.  What I really need to see before even considering a
> system that replaces the working system is an argument about why it
> needs to be replaced, and more importantly, code that can do
> everything the old code can do, such as rende

Re: [matplotlib-devel] First SVN commit (for me and mathtext2.py :)

2006-08-20 Thread Darren Dale
Hi Edin,

On Sunday 20 August 2006 10:21 am, Edin Salković wrote:
> The SoC deadline (for code) is tommorow (Aug 21st.), so I decided to commit
> what I have done till now to the repository.
>
> JDH is going on a vacation and will not be able to review it for at
> least a week,
> but I had to commit it before 21st. Aug - that's the SoC rules. Hopefully,
> I'll be adding new stuff the next week (and after), but that doesn't
> count as part of SoC anymore...
>
> Since this is my first commit, can anyone please test it. I tested it
> only on my windows box.
>
> I changed
> __init__.py,
> mathtext.py
> CHANGELOG
>
> I added
> mathtext2.py
> mathtext2_demo.py
>
> Anyone who wants to test the new mathtext2 has to add the following line(s)
> to the matplotlibrc (mathtext2 is disabled by default):
>
> mathtext2:   True# Needed to enable the new mathtext
>
> # Font lines, feel free to change or uncomment (BaKoMa is used by default)
> mathtext.rm :   FreeSerif.ttf
> mathtext.it :   FreeSerifItalic.ttf # Text italic
> mathtext.tt :   FreeMono.ttf# Typewriter (monospaced)
> mathtext.mit:   FreeSerifItalic.ttf # Math italic
> mathtext.cal:   FreeSansOblique.ttf # Caligraphic
> mathtext.nonascii:  FreeSerif.ttf # Used for \sum, \infty etc.
>
> The FreeFont fonts (or any other for that matter) have to be downloaded and
> put into the mpl-data dir. The default settingsuse the current bakoma
> fonts, and they play pretty well with FreeSerif.ttf as the nonascii
> (unicode) font.
>
> so I recommend you just put the line
> mathtext.nonascii:  FreeSerif.ttf
>
> and comment out the rest (experiment a little with fonts).
>
> Tonight I plan to add support for fractions. Beware that the only
> supported backend for now is Agg.
>
> mathtext2_demo.py is attached

I just updated my svn repository, added the lines you indicated to my rc file, 
but when I run the example, mpl can't find the freefonts that I already have 
installed on my system. The freefonts I have installed are not ttf, but pfb. 
Where should we download from? ftp://ftp.cs.umn.edu/pub/gimp/pub/gimp/fonts, 
for example? I dont think those are what I am looking for. Do they really 
need to go in mpl-dir? It would be more appropriate if they could be 
installed somewhere like /usr/share/fonts.


-
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
___
Matplotlib-devel mailing list
Matplotlib-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-devel


Re: [matplotlib-devel] Mathtext questions, continued...

2006-08-20 Thread Darren Dale
On Sunday 20 August 2006 10:25 am, Edin Salković wrote:
> Here are the reasons for rewriting mathtext2 that I can come up with:
>
>  * One of the reasons I started the complete rewrite of the parser is that
> I'm a newbie at parsing, and I wanted to try it out a bit. I didn't
> understand why was it so difficult to parse TeX (or anything a little bit
> complicated for that matter). Well, now I know ;)
>
>  * The other reason was that I didn't understand fully the current parsing
> code, or more precisely, the part when what's interpreted get's rendered.
> And I'm not talking about glyphs, but about the complex constructs
> (scripts, frac's etc.)
>
>  * The third reason was that I can now try out in pararel the new and the
> old code. Also, because I'm not touching the PS and SVG backends for now we
> can have the following code in the current mathtext:
>
> if rcParams[some_parameter]:
>from matplotlib.mathtext2 import math_parse_s_ft2font
> else:
>math_parse_s_ft2font = math_parse_s_ft2font_common('BMP')
> math_parse_s_ft2font_svg = math_parse_s_ft2font_common('SVG')
> math_parse_s_ps = math_parse_s_ft2font_common('PS')
> math_parse_s_pdf = math_parse_s_ft2font_common('PDF')
>
> Also, I thought that the author of the current code base did some design
> mistakes at the begining. And, being a developer newbie, it's a lot easier
> to start things from scratch, than make fixes to old stuff you don't
> understand well.

Just a general comment. Eric Raymond observed in The Cathedral and the Bazaar 
that "Good programmers know what to write. Great ones know what to rewrite 
(and reuse)." In the future, I suggest you consider that it may be in your 
own long term interest to try to understand and extend existing code instead 
of rewriting it from scratch. You'll learn quickly by being exposed to other 
people's ideas and techniques, and you will get faster results since you 
won't be reinventing the wheel.

> As for the mathtext_demo.py part, even real TeX can't handle it :). 

If TeX isn't yielding the result you expect, then you were expecting the wrong 
result.

> The point is that, i.e. \cal sets the current fontface to "cal", and the 
> change is propagated till the end of the current scope (or untill it hits 
> \rm, for example). Old mathtext applies it only to the first item after the 
> command. 

What does this have to do with real TeX? Maybe you could post an example. It 
is possibly just an mpl bug that needs to be addressed.

Darren

-
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
___
Matplotlib-devel mailing list
Matplotlib-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-devel


Re: [matplotlib-devel] Mathtext questions, continued...

2006-08-20 Thread Jouni K Seppanen
Darren Dale <[EMAIL PROTECTED]> writes:

> On Sunday 20 August 2006 10:25 am, Edin Salković wrote:
>> Also, I thought that the author of the current code base did some
>> design mistakes at the begining. And, being a developer newbie,
>> it's a lot easier to start things from scratch, than make fixes to
>> old stuff you don't understand well.
>
> Just a general comment. Eric Raymond observed in The Cathedral and
> the Bazaar that "Good programmers know what to write. Great ones
> know what to rewrite (and reuse)."

See also: http://www.joelonsoftware.com/articles/fog69.html

>> The point is that, i.e. \cal sets the current fontface to "cal",
>> and the change is propagated till the end of the current scope (or
>> untill it hits \rm, for example). Old mathtext applies it only to
>> the first item after the command.
>
> What does this have to do with real TeX? Maybe you could post an
> example. It is possibly just an mpl bug that needs to be addressed.

Run the attached file through LaTeX to see what he means. Does
Matplotlib attempt to replicate some subset of (La)TeX syntax exactly,
or is it just a "TeX-like" syntax?

-- 
Jouni

\documentclass[12pt]{article}
\begin{document}

Using the traditional Plain \TeX\ declarations,
this is in roman, {\it this is in italics, \bf this is in boldface, 
\rm back to roman, \bf some boldface again.}
This is outside the \{~\} pair and thus in roman.

Using the recommended \LaTeX\ commands,
\textit{this is in italics, \textrm{this is STILL in italics,}
\textbf{this is in both italics and boldface,}} 
THIS is in roman, \textbf{and this is in boldface.}
(If you forget the braces, the command only applies
to the following character:
\textit italics, \textbf boldface.)

\end{document}


-
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642___
Matplotlib-devel mailing list
Matplotlib-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-devel