View this PageEdit this Page (locked)Attachments to this PageHistory of this PageHomeRecent ChangesSearch the SwikiHelp Guide
Hotspots: Admin Pages | Turn-in Site |
Current Links: Cases Final Project Summer 2007

Text Properties Case - Eric Amy

Through the process of creating a Resizing TextMorph, I learned a lot about how squeak stores fonts and other text properties within a TextMorph. And since it is a very convoluted and unintuitive structure, here is everything I know about it:

Starting at the top.
TextMorph has a TextStyle, which is just a wrapper for an array of Fonts. The TextStyle keeps track of the default font and has methods for retrieving a font by size or name, etc..

A method of interest in TextMorph is beAllFont:aFont, which actually reassigns the TextStyle in the TextMorph to only contain the one font that it is given as a parameter. It then declares the TextMorph changed. I have found that this is an unreliable way to change the font if the user has already changed the font by means of the halo.

The TextMorph also keeps references to a TextMorphEditor and a Paragraph. The TextMorphEditor contains methods for changing the attributes of text within TextMorphs. This includes the method changeTextFont which is called when the user changes the font of the selection using the halo.
The Paragraph has it's own TextStyle as well as a ParagraphEditor with similar functions. The TextMorph continuously creates new Paragraphs based on some sort of logic that I haven't found.

Both the TextMorph and the Paragraph have a Text object that represents all the text it contains. Here is where the text properties are actually stored. Much like a Morph has a collection of pluggables properties, a Text has a collection of TextAttributes. The most notable of these are the TextFontReference, TextFontChange, and TextEmphasis. When the user changes the font with the halo, the changeTextFont method in the TextMorphEditor actually adds a TextFontReference to the Text defined by the start and end indexes of the text highlighted at the moment.

TextFontReference contains an absolute reference to a font.
TextFontChange contains a number corresponding to an index in the TextStyle.
TextEmphasis contains a number corresponding to an encoding as follows:

I choose to use the methods addAttribute:att and addAttribute:from:to: directly to the Text, because the higher methods seem to be designed to be called by the UI, not programatically.

Links to this Page