The module text_rendering
The text rendering as a module: each export calls one function of src/library/modus/text_rendering over the bytes and the tables of the caller. The caller gives the font outlines as bytes: the resource font_outlines that its starter mapped, or a copy of it. Each call opens the fonts of those bytes on its stack and measures with them; the module keeps nothing between two calls, so an isolated call gives the same answer as a direct call.
The bytes are hostile input: in an isolated call they are in the call region, which another thread can change during the call. The header and the records of the outlines are copied once and checked (font_outlines.validate); the parser of the fonts checks each read of a font file against its bytes; each advance and each pair is kept in its bound when it is read. A changed byte gives other numbers, never a read out of the bytes and never a sum that wraps.
What it is for. A caller that does not compile the package (a module of a third party, an isolated call) places the glyphs of a text, measures many texts in one call, and breaks a text into the lines of a box, with the numbers of a process that compiles the package in.
The units: each position, width and room is in 1/64 of a pixel. A face is a number of text_rendering.Face (1 Interface, 2 Interface_Bold, 3 Cells, 4 Cells_Without_Grid_Fit, 5 Cells_Bold); a text size is the height of a line in 1/64 of a pixel, from 256 to 16384.
What it does not do: no ligature, no direction other than left to right, no shaping of a complex script.
See: Text rendering: one module for text at any size: The library module in the repository
text_rendering module with no entry
- Hash
ec1ccbd5e20eb5392c352e36e3f44906c36e65d8ffa82f96f0b5bc6adf86079c- Size
45056 bytes- Exports
3- Imports
0- Imported by
0- License
- MIT
The text rendering as a module: each export calls one function of src/library/modus/text_rendering over the bytes and the tables of the caller
| Fact | Value |
|---|---|
| Kind | Modules with no entry |
| Source | src/modules/libraries/text_rendering |
| Boot image | yes: in the boot image, 45056 bytes in this build |
| Build settings | none: the defaults of the source |
| Imports | none |
| Imported by | none |
Neighbours
It imports no module, and no module imports it. The module graph shows it with the other modules that have no edge.
Exports
| Export | What it does |
|---|---|
shape_text(outlines: Bytes(Read), face: Integer, size: Integer, text: Bytes(Read), placed: Table(Placed_Glyph, Append)) -> Integer | appends the placed glyphs of a UTF-8 text in a face at a text size, measured from the font files of the outlines: one for each character, x from the origin of the text and the advance with the pair adjustment of the font, in 1/64 of a pixel, and the first byte of the character as its cluster |
measure_texts(outlines: Bytes(Read), face: Integer, size: Integer, text: Bytes(Read), ranges: Table(Text_Range, Change)) -> Integer | writes the width of each text of a table of ranges into one table of bytes, in a face at a text size, in 1/64 of a pixel: a window measures all its labels in one call |
break_text(outlines: Bytes(Read), face: Integer, size: Integer, text: Bytes(Read), room: Integer, lines: Table(Text_Range, Append)) -> Integer | appends the lines of a UTF-8 text in a box of room, in a face at a text size: each line as a range of the text (its first byte, its bytes with no space at its end, and its width in 1/64 of a pixel) |
shape_text
shape_text(outlines: (Read), face: , size: , text: (Read), placed: (, Append)) ->
shape_text appends the placed glyphs of a UTF-8 text in a face at a text size, measured from the font files of the outlines: one for each character, x from the origin of the text and the advance with the pair adjustment of the font, in 1/64 of a pixel, and the first byte of the character as its cluster. The glyph is the character index for 32 to 126 (0 to 94), U+00A0 to U+00FF (95 to 190) and the euro sign (191); 16777216 plus the code point for another character that a font of the chain of the face has; 4294967295, the replacement glyph, with the advance of "0", for a character that no font of the chain has and each invalid sequence. The outlines are the resource font_outlines, on 8 bytes. The result is the count of placed glyphs of the full answer (larger than the capacity: it did not fit), or -1 with an error record: a face that is not 1 to 5 (argument 2), a size under 256 or over 16384 (argument 3), a text of more than 65536 bytes (argument 4), a table of placed glyphs over 2^40 records (argument 5), outlines that are refused or lack the first font of the face (argument 1). Nothing is written on a refusal.
outlines: (Read)face:size:text: (Read)placed: (, Append)
- When it fails
- a negative result, and the error record
src/modules/libraries/text_rendering/text_rendering.odin:104
measure_texts
measure_texts(outlines: (Read), face: , size: , text: (Read), ranges: (, Change)) ->
measure_texts writes the width of each text of a table of ranges into one table of bytes, in a face at a text size, in 1/64 of a pixel: a window measures all its labels in one call. The width of a text is the sum of the advances of its placed glyphs (shape_text). The result is the count of ranges, or -1 with an error record: a face (argument 2) or a size (argument 3) as for shape_text, a table of bytes (argument 4) or of ranges (argument 5) over 2^40, outlines as for shape_text (argument 1), a range past the end of the bytes (Out_Of_Range: its end, the count of bytes, the number of the range from 1), or a range of more than 65536 bytes (Too_Long: its count, the limit, the number of the range from 1). The ranges before the one that fails have their width; it and the ranges after it are not written.
outlines: (Read)face:size:text: (Read)ranges: (, Change)
- When it fails
- a negative result, and the error record
src/modules/libraries/text_rendering/text_rendering.odin:135
break_text
break_text(outlines: (Read), face: , size: , text: (Read), room: , lines: (, Append)) ->
break_text appends the lines of a UTF-8 text in a box of room, in a face at a text size: each line as a range of the text (its first byte, its bytes with no space at its end, and its width in 1/64 of a pixel). A line ends at the last space that fits; a word wider than the box ends a line after its last "/", ":" or "_" that fits, else after its last character that fits; a line has at least one whole character, also in a room of 0 or below. The lines, joined, are the text with no space at a break. An empty text has no line. The result is the count of lines of the full answer (larger than the capacity: it did not fit), or -1 with an error record: a face (argument 2) or a size (argument 3) as for shape_text, a text of more than 65536 bytes (argument 4), a table of lines over 2^40 records (argument 6), outlines as for shape_text (argument 1). Nothing is written on a refusal.
outlines: (Read)face:size:text: (Read)room:lines: (, Append)
- When it fails
- a negative result, and the error record
src/modules/libraries/text_rendering/text_rendering.odin:165
Read from the source of the module, as the build reads it to describe the exports (tools/modustool/build/describe.odin).
Bytes wire form
A wire form of the module contract: one word of a call. Bytes with no description.
Integer wire form
A wire form of the module contract: one word of a call. A signed integer of 64 bits, in a register.
Table wire form
A wire form of the module contract: one word of a call. Records of one description that follow each other (a table).
Placed_Glyph record of a module
A record of the module text_rendering: 16 bytes, aligned on 4 bytes, 0 bytes of padding.
glyphu3204 bytesxi3244 bytesadvancei3284 bytesclusteru32124 bytes
Error_Record record of a module
A record of the module text_rendering: 56 bytes, aligned on 8 bytes, 0 bytes of padding.
kindi6408 bytesuniti6488 bytesoperationi64168 bytesargumenti64248 bytesvaluei64328 byteslimiti64408 bytesfoundi64488 bytes
Text_Range record of a module
A record of the module text_rendering: 16 bytes, aligned on 8 bytes, 0 bytes of padding.
startu3204 bytescountu3244 byteswidthi6488 bytes
