1cb93a386Sopenharmony_ci--- 2cb93a386Sopenharmony_ci 3cb93a386Sopenharmony_cititle: "SkText public API" 4cb93a386Sopenharmony_cilinkTitle: "SkText public API" 5cb93a386Sopenharmony_ci 6cb93a386Sopenharmony_ci--- 7cb93a386Sopenharmony_ci 8cb93a386Sopenharmony_ciThe main idea behind SkText is to design a flexible API that allows a user from different platforms to shape, manipulate and draw text. 9cb93a386Sopenharmony_ci 10cb93a386Sopenharmony_ciAs text formatting works in stages, SkText presents a set of text objects that keep data from each stage. That staging approach allows a user to stop at any stage and drop all the data from the previous stages. 11cb93a386Sopenharmony_ciCurrently, we support the following stages: 12cb93a386Sopenharmony_ci 13cb93a386Sopenharmony_ci* <u>Parsing the text</u> to extract all the unicode information that may be needed later: graphemes, words, hard/soft line breaks, whitespaces, bidi regions and so on. 14cb93a386Sopenharmony_ciClass <b>UnicodeText</b> contains the initial text in utf16 format, and the mapping of unicode information to codepoints in a form of enum bit flags. 15cb93a386Sopenharmony_ciIt also has a method <b>resolveFonts</b> that creates a FontResolvedText object. 16cb93a386Sopenharmony_ci 17cb93a386Sopenharmony_ci 18cb93a386Sopenharmony_ci* <u>Resolving fonts</u> to break the text into blocks that can be shaped with one single font (selected out of a given list of fonts). 19cb93a386Sopenharmony_ciClass <b>FontResolvedText</b> contains the results in a form of a list of text blocks with a single typeface for each. 20cb93a386Sopenharmony_ciIt also has a method <b>shape</b> that creates a ShapedText object. 21cb93a386Sopenharmony_ci 22cb93a386Sopenharmony_ci 23cb93a386Sopenharmony_ci* <u>Shaping the text</u> into a single line of glyphs according to all given formatting information (fonts, text direction, scripts, languages and so on). 24cb93a386Sopenharmony_ciClass <b>ShapedText</b> contains the results in the form of a list of shaped blocks with all the information that comes from shaping: glyph ids, positioning, and mapping to the initial text and so on. 25cb93a386Sopenharmony_ciIt also has a method <b>wrap</b> that creates a WrappedText object. 26cb93a386Sopenharmony_ci 27cb93a386Sopenharmony_ci 28cb93a386Sopenharmony_ci* <u>Wrapping the text</u> into a list of lines (by a given width) and formatting it on the lines (left, right, center alignment or justification). 29cb93a386Sopenharmony_ciClass <b>WrappedText</b> contains the shaped results from the previous stage only broken by lines and repositioned by lines. 30cb93a386Sopenharmony_ciIt also has a method <b>prepareToDraw</b> that creates a DrawableText object, and a method <b>prepareToNavigate</b> that creates a SelectableText object. 31cb93a386Sopenharmony_ci 32cb93a386Sopenharmony_ci 33cb93a386Sopenharmony_ci* <u>Drawing the text</u> into a canvas. This is more of an example of how to draw the text because it only covers a rather simple case of drawing (limited decorating supported). Based on this example a user can create a custom drawing class as complex as needed. 34cb93a386Sopenharmony_ciClass <b>DrawableText</b> contains a list of SkTextBlob objects ready to be drawn on a canvas. 35cb93a386Sopenharmony_ci 36cb93a386Sopenharmony_ci 37cb93a386Sopenharmony_ci* <u>Navigating the text</u> by grapheme cluster (later, grapheme, glyph cluster or glyph). It has all the functionality for text editing. 38cb93a386Sopenharmony_ciClass <b>SelectableText</b> contains all the methods for that: hit test, move position (left, right, up, down, to the beginning of the text or the line, to the end of the text or the line), select an arbitrary text (aligned to a grapheme cluster) and so on. 39cb93a386Sopenharmony_ci 40cb93a386Sopenharmony_ciAll the objects described above can exist independently of each other, so a user can decide which ones to keep. 41cb93a386Sopenharmony_ci 42cb93a386Sopenharmony_ciLet’s consider few scenarios (flows): 43cb93a386Sopenharmony_ci 44cb93a386Sopenharmony_ci1. A user only needs to get the unicode information. 45cb93a386Sopenharmony_ci<br>Strictly speaking, it’s not a text shaping operation but UnicodeText would allow it. 46cb93a386Sopenharmony_ci1. A user needs to draw the text. 47cb93a386Sopenharmony_ci<br>That requires performing the first 4 stages, but a user only needs to hold on to the DrawableText object afterwards (removing UnicodeText, ShapedText and WrappedText objects). 48cb93a386Sopenharmony_ci1. A user needs to draw and edit the text. 49cb93a386Sopenharmony_ci<br>That requires performing all the 5 stages. A user will have to hold on to DrawableText and SelectableText (removing the first 3 objects). 50cb93a386Sopenharmony_ci1. A user only needs to be wrapped text, implementing a custom drawing procedure. 51cb93a386Sopenharmony_ci<br>That requires performing the first 3 stages. A user will have to hold on to WrappedText (removing the first 2 objects). 52cb93a386Sopenharmony_ci 53cb93a386Sopenharmony_ciAt the moment there is no support for updating the text (which theoretically could be a less expensive operation). Any changes in the initial text will require the full set of operations. 54