K-Pad is a multi-featured notepad / organizer for Windows: print-out pages or booklets of photos, tables, and rich text.More...
This is my support blog, featuring help, tutorials, and comment. Welcome. :-)

Wednesday, 27 August 2008

K-Pad v1.1.2 Notes

With each new release version, I'm going to endeavour to detail the changes more fully in my blog. It's a bit techie, and I expect it'll only be of interest to me, so feel free to skip!

Today, v1.1.2 (Beta).


Text boxes

I use two groups of text edit classes in K-Pad: the one used by the Lined Paper module, which supports fancy effects, and the one used by everything else. The first I call "TextBox", and the second "EasyText". The TextBox classes were written a long, long time ago, and have been modified to a great extent. They have a monstrous amount of code behind them. When I realized that I needed text edit for other modules (and the tree), I decided that TextBox was just too bloated and overly-complicated to adapt. My fault, really, because I wasn't the coder I am today when I created them. Today, I'm all about keeping it clean, keeping it very simple.

And so, I created EasyText. EasyText, I hope, will someday have the features of TextBox without the associated complications. But writing a text edit control properly isn't trivial. There's the caret (esp. "keep in view" code and selection), keyboard navigation, horizontal and vertical alignment, word-wrapping, sizing, clipping, single-line mode, display at different zooms etc. Those are my minimum requirements for the control to work properly. After that, there are the "nice to have" features. Importantly: undo/redo and caret-navigation via the mouse. Those two new features are in v1.1.2, and now that they're there in EasyText, the functionality can be applied quickly to the Header, Footer, List title, List items, Clipping caption, Squared textbox obs, and tree item rename. ...The exception being the mouse navigation in the Squared textbox obs, which will require some recoding and rethinking of that interface. Something I can look at for a future version.


Squared paper: TextBox

I was designing a cover using squared paper, and needed to add a title. For some reason, instead of choosing a fancy font for this, I used the default font, but in a larger size. The instant I did, other bits of text on the squared paper, and the header/footer text, and the List text, jumped to the same point size. Nasty bug!

The reason for the bug is that I have a method of my global PaintBox called getFont ( fontName, size, bold, italic), which returns the font from a store (or adds it to the store if it does not exist). However, the store holds fonts as {fontName, bold, italic}, and the class sets the size. When I created that larger font, it returned the default font from store, and set the large point size, but then did not reset the point size for the other times that the font was drawn. To fix the bug, I created a wrapper class to ensure that the font size is properly set before each call to draw or getSize.


When I fix a bug like that, my inclination is to add a new feature alongside the fix. So I added bold and italic support to the Squared paper textboxes. It actually wasn't a lot of work for something that's quite useful: link in the accelerators, modify FontBox, and add to load/save.

A final bugfix: changing the font would result in the text going out of alignment. This was because the EasyText only calculates new sizes after a change of text. The simple fix was to add a method to tell it to resize on next draw.


Squared paper: Object movement (keyboard)

A bug fix for home/end/pgup/pgdn keys. Objects are supposed to keep to the constraints of the page. Each object has a bounding rect, which must be within the constraint rect. The bug was caused by hurried (read: sloppy) coding. For the home key, for example, I would shift the object rect to the left by 1000 squares, and leave the tidying to the constrain () code... which wasn't good enough.


Header/Footer

The unparsed format code is now always shown when the page is not in the main pad, i.e. the page is not going to be printed (or not yet). This is because a page that won't be printed doesn't have a proper page number! In fact, that page number is -1. So formatting code like %O, %E, %P, %F, %L etc becomes meaningless.

No comments: