Tuesday, February 27, 2007

Cleaned up nikud (UPDATED)

Just a quick post to note that I cleaned up the nikud processing. On to figure out why the dynamic text block is getting truncated.

UPDATE: I also just fixed that bug. I was calculating the size of each block by subtracting the position of the previous block from the position of the current block. That does give the size, but the size of the previous block, not the current. Also, it can't work for the last block. Now the size is calculated when encountering the text block ending marker. Next up is to start actually parsing the text on the reading side, which may lead to some refactoring. Stay tuned.

Sunday, February 25, 2007

New plan for removing nikud

I have a new plan for implementing the option to remove nikud. I realize I've never even explained why this is necessary, so in the way of introduction, the tefilla text as I have them include nikud. Once I have other areas in better shape, I'd like to add nikud to the image-based fonts in ASiddur. I'm putting this off until later since many people are able to daaven without nikud, and trying to add nikud without making the text hard to read and also without cutting down too much on the amount of text visible on screen will be somewhat challenging.

As I've mention in the previous post, the existing code filters nikud out when reading it from a file. Since the whole tefilla is read into a buffer initially and just referenced, that works well. This limits the size of the buffer needed and means that filtering can be done just once (as opposed to every time text is shown). That also means that the text can be drawn all at once, especially when using native fonts.

However, that doesn't work very well with the dynamic text because the many features presume that they know the length of the text. For example, when printing out retzei, it is important to know how long ya'aleh v'yavo is. And if the code that reads it in removes nikud, that length will be incorrect.

Instead, my new plan is to handle all of the nikud removal right when the text is drawn. That really is cleaner if I ever switch to more of a Model-View-Controller or related pattern. The main drawback is that less of the tefilla will be buffered at a time, and that native fonts will take a performance hit, since the string will have to be drawn a letter at a time, rather than just passing the whole string to the drawString() function.

The implementation is pretty easy for the Image-based fonts. All that's needed is to create a small empty (or transparent) image, and to manually set the sizes to 0. For native fonts, the easiest is to deprecate the MidpFontAdapterStrategy and instead use the ImageFontStrategy, but let it fall through to the native font in all cases except for nikud, which would be set up as above. Now to get it coded...