Skip to content

developers rendering formattedtext

Tim Stair edited this page Aug 22, 2015 · 1 revision

Developers - Rendering - FormattedText

Introduction

What are you doing looking at this section? Are you mad?

FormattedText is one of the more complex components of CardMaker. Essentially it is a font and graphic renderer very loosely based on HTML.

Functionality

Markups and FormattedTextProcessData

To support various interesting pieces of functionality CardMaker uses HTML like markup tags (optionally requiring closing tags depending on the need). Markups are stacked and have logic for applying and unapplying themselves to the current state. The state of the FormattedText is maintained in the FormattedTextProcessData object.

The following example shows the bold tag in use. The font is reconfigured to be bold when the b open tag is found. The font is then reconfigured again when the b closing tag is found.

<b>bold</b>not bold

FormattedTextProcessData also manages the current x and y values in addition to x and y draw offsets.

Processing Markups

DrawFormattedText.GetMarkups has the distinguished honor of reading the Definition string from the Element and creating the Markup list for processing. As of this writing this is done character by character.

Rendering Markups

FormattedTextDataCache is a cached object that is responsible for the rendering order of the markups. See the class for the current rendering order. This object is cached to avoid having to reprocess the entire markup string each time the Layout is rendered.

After the Markup list is created there are four steps required for markup processing before rendering.

Setup / Rectangle Creation

Each Markup is processed in order to stack on effectsd generate a render rectangle, or other setup tasks.

Any markups that require further processing are kept in a collection, while others are dropped. PushMarkup is an example of a Markup that is only processed in this first step.

End of Line Space Cleanup

There is no reason to render markups that don't actually display anything. If a markup is deemed unnecessary it is removed. This is critical for the next step which uses the total width of all the markups on a line to align.

Align the Markups

Based on the setting of the Element all of the markups have to be aligned vertically or horizontally as specified.

Final Processing

Some markups may require post processing after alignment. In most cases this is used to remove a Markup from the list of those to be rendered. CloseTagMarkup is an example of a Markup that is not needed for rendering.