← 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
 
 
Letter spacing
Word spacing
 
 

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

As much as we would like to treat every Chinese and Japanese character as its own thing, both writing systems insist that certain punctuation marks cannot be separated from their preceding character over a line break. Browsers know about this, and make sure it happens in normal HTML. SC, however, makes no effort to guess when this should happen.

For this demo, we have manually added word joiner characters - HTML entity &#x2060; - immediately before these punctuation marks. A more robust code solution to pre-process canvas text would be required to handle this sort of thing in production environments. Building such a solution into the SC code is not in scope for the project.


An even more special note about Thai 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-space spaces - HTML entity &#x200B; - in places where this can be done. Browser engines seem to do this internally, but getting that data from the text string doesn't seem possible. For the two Thai fonts above, this has been done manually by copying the raw string into a <p style='width: 10px; font: 16px "Noto Thai Looped Sans"'> element and then counting the characters. Not recommended for production!

ในแผนเดิมรถไฟฟ้าแอร์พอร์ต เรล ลิงก์ สถานีมักกะสันจะเชื่อมต่อกับสถานีเพชรบุรีของรถไฟฟ้ามหานครที่ชั้น ของตัวอาคาร แต่เนื่องจากเมื่อสำรวจเส้นทางแล้ว พบว่าเส้นทางดังกล่าว มีท่อส่งน้ำมันของปตท. ตามแนวทางรถไฟสายตะวันออก ท่อน้ำประปาของการประปานครหลวง และท่อน้ำทิ้งลงคลองแสนแสบของกรุงเทพมหานคร ที่การรถไฟฟ้าขนส่งมวลชนแห่งประเทศไทยรื้อย้ายจากจุดเดิมเพื่อก่อสร้างสถานีเพชรบุรี ขวางอยู่จึงทำให้การขุดเจาะทางเชื่อมเข้าตัวสถานีรถไฟฟ้ามหานครไม่สามารถทำได้