Showing posts with label truetype. Show all posts
Showing posts with label truetype. Show all posts

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: