Monday, May 7, 2007

Archimedes on going & TrueType fonts

Keeping the speed is now critical. I am trying to make it a habit to write down every problem or achievement I have here so that people can benefit from those and I can get used to post more frequently on this blog.

Last week end I worked a lot on Archimedes to have the text problem solved. Mainly the thing is Archimedes needed to have a text feature so that users could write things on the drawing and the dimension feature could write the dimensions too. Last time we solved this problem, we had no idea about how to draw fonts on OpenGL and therefore the team chose to implement its own font system and fonts. This was heavily critized by the clients and users and by the developers too. So this time, we decided to implement it right. This means that we focused on reading existing fonts and what our clients asked was Arial which is a TrueType font. So we tried to learn how to parse ttf files and then find out how to render those.

After some research on the internet about java ttf parsers we found an interesting Apache project called Batik. This project focuses on SVG support to a lot of things and, especially, having truetype fonts ported in svg paths. Thanks to the Apache Software license (thanks free and open source movements) we were allowed to read the source code, modify it and use it in Archimedes. So after a couple hours studying the code, we grabbed the packages that were in our interest and brought them into an RCP plugin and used them in Archimedes.

Now a few comments about truetype fonts. The Font class in batik that encapsulates a TTF font is mainly formed of 10 or 15 tables that contain infos about the glyph (characters), platform and several other details I don't understand decently. What we needed to use the font was just the cmapTable and the cmapFormats. Those classes contained mapping between several encodings to the glyph number in the font. Also each point of the glyph contains information about whether it is a normal point or an "endContour" point which means it is the last point of a circle and should be connected to the first point non "endContour" found. We also learned (although we didn't implement it) that interpolation between those points should be done with a bezier curve of second degree but this having this on Archimedes is probably an overkill at the moment.

Dropping a bit the technological part (all the code can be found in the br.org.archimedes.batik package and br.org.archimedes.gui.opengl.OpenGlWrapper class), all this information means that the software is now loading a truetype font and rendering it with OpenGL. There are still a few problems to fix like mapping weird characters and having this working perfectly on all platforms but all the rest is working fine. And here is a small screenshot just to prove I'm not lying:

6 comments:

gtroza said...

i am jealous!!!

nice work hugo !

Hugo "NighT" Corbucci said...

Jealous?
About what? :) The only reason I haven't release an unstable version of archimedes is because it is giving me too much work to do. As soon as I get an automated trustable build easy to generate, I will restart posting weekly unstables.
For now, you will have those new feature in about 20 days.

Thanks for the support :)

gtroza said...

because you are young !!!
(scale your age x 2.6)

look at my blog, and try gtroza cad, and you will understand !!!

i wish you the best !!!

ps:i can not run archimedes yet.

Anonymous said...

x2.3
gt

Hugo "NighT" Corbucci said...

Ok! Got the age argument (though your profile says nothing about it) but still never understood why you are jealous.
I saw your screenshots about gtroza-cad that look a lot more complete than Archimedes and much more powerfull. I couldn't download it because I never found a link and all I could find with google are some greek pages.
I know I should be ashamed of this but... I can't read greek. :( So I couldn't read anything else about it. Could you help me out with that?
Now, please mail me (you can find my contact in my profile page) about not running Archimedes and I will be glad to help you as I can.

Anonymous said...

thanks hugo
more about cad tomorrow !

gt