← Previous Next →

Scrawl-canvas v8 - Canvas test 206

EnhancedLabel entity - basic multiline text

Select font
Layout template
Text unit flow
Justify line
Line spacing
Line adjustment
Break text on spaces
Break word on hyphens
Alignment
Truncate string
Hyphen string
Local alignment
Show guidelines
Guideline style
Guideline dash
Text handle X
Text handle Y
Auto-hyphenate
set to true for Thai scripts
Letter spacing
Word spacing
Start text on line

CANVAS

HTML

Scale
Roll
 
 
Width (Radius)
Height
 
 

To note: Javascript is not running in this browser environment. Our apologies, but this demo has not yet been updated to support progressive enhancement.

Test purpose

There are so, so many things to check here! The following list is not exhaustive:

Known issue: When changing the font, or the layout template, the positioning of the red ball breaks down; however that can be fixed by making a small adjustment to another attribute.

Known issue: letter spacing does not work in Safari browsers.

Touch test: not required.

Annotated code


A special note about fonts

Because fonts load asynchronously, and SC EnhancedLabel entitys currently have a (near-unsolvable) bug where they will measure a font before the font family's various iterations (if specified in CSS @font-family definitions) have downloaded - they only wait for their default font to download, not any additional fonts included (via CSS) in their text string - it makes sense for us to trigger font downloads as soon as possible. And the simplest way to do that is to include text using those fonts in a "hidden" (actually an aria-hidden="true" style="height: 0; overflow: hidden") element in the web page, ahead of the <script> tag that triggers the SC canvas build.

There are, of course, more professional ways for a front-end engineer to manage efficient and timely font downloads ... but this is just a demo and, well, needs must!


Another special note about Chinese and Japanese scripts

SC makes an effort to keep CJK punctuation marks adhered to their neighbouring characters to prevent them separating across lines. Where that functionality fails for a given text, users can manually add word joiner characters - HTML entity &#x2060; - immediately between the punctuation mark and the character it needs to adhere to.

SC also makes an effort to display appropriate punctuation marks in column-stacked (vertical) text. Both functionalities are active by default.


An even more special note about Thai (and related Lao, Khmer, Myanmar) scripts

Breaking Thai "words" across lines is a difficult issue - see the W3C Thai Layout Requirements spec for the latest position.

The Thai script is a complex abugida. Spaces are used, but the tendency is to only insert them at natural breath pauses, which means a Thai "word" (as in: a set of characters not separated by spaces) can get exceptionally long.

To break such words across lines, one recommendation is to insert zero-width spaces - HTML entity &#x200B; - in places where this can be done. SC attempts to handle this automatically using the browser's Intl.Segmenter functionality, and setting the autoHyphenate flag to true.