silk.text.vertical_text.
Character orientation in vertical text (UAX #50), with data from Unicode 18.0.0.
When to use#
Use orientations to lay out vertical text, such as vertical Japanese: it splits the text
into runs that stand upright and runs that are rotated.
Details#
The orientation belongs to a whole extended grapheme cluster, so combining marks and emoji sequences never split. An enclosing mark makes its cluster upright. The runs are byte ranges of the text, appended to a caller-owned list.
Gotchas#
The result is the fallback orientation, without font data. A character with
Vertical_Orientation Tu or Tr needs its vertical alternate glyph when the font has one.
Read VerticalOrientation.of in silk.text.unicode_properties for that.
Examples#
Find the rotated part of vertical text#
import silk.collections.list { List }
import silk.core.effect { Effect }
import silk.mem.allocator { Allocator, OutOfMemoryError }
import silk.text.vertical_text
import silk.text.vertical_text { Orientation, OrientationRun }
pub effect fn main() -> i32
! OutOfMemoryError {
let mut allocator = Allocator.systemAllocatorProvider()
let mut runs = List<OrientationRun>.make()
// Two kanji, then Latin letters.
run vertical_text.orientations("\u{65e5}\u{672c}abc", &mut runs)
|> Effect.provideMut<Allocator>(&mut allocator)
let items = runs.asSlice()
if items.length != 2 || items[0].orientation != Orientation.Upright || items[1].start != 6
|| items[1].orientation != Orientation.Rotated {
return 1
}
return 0
}Import as vertical_text with import silk.text.vertical_text as vertical_text.
Public declarations: 3.
Orientation#
pub enum OrientationThe fallback orientation of a character in vertical text.
Upright#
UprightThe glyph stands upright, as in the code charts.
Rotated#
RotatedThe glyph is rotated 90 degrees clockwise.
OrientationRun#
pub struct OrientationRunA maximal range of a text with one fallback orientation, as orientations gives it.
Field start#
pub start: usizeThe byte offset where the run starts.
Field end#
pub end: usizeThe byte offset where the run ends.
Field orientation#
pub orientation: OrientationThe fallback orientation of the run.
Implementation Copy for OrientationRun#
impl Copy for OrientationRunorientations#
pub effect fn orientations(text: string, output: &mut List<OrientationRun>) -> ()
! OutOfMemoryError
? &mut AllocatorAppends the runs of fallback orientation of text for vertical layout to output.
Details#
The orientation follows UAX #50 for whole extended grapheme clusters: the first scalar of a
cluster decides, but an enclosing mark (General_Category Me) makes the cluster upright.
Vertical_Orientation U and Tu give Orientation.Upright, and R and Tr give
Orientation.Rotated. The runs are not empty, they cover the text in order without gaps, and
empty text gives none. The function does not clear output, so clear it first to reuse its
storage.
Errors#
OutOfMemoryErrorif theAllocatorcannot growoutput.
Gotchas#
Tu and Tr characters need a vertical alternate glyph when the font has one; the fallback
orientation applies only without it. Read VerticalOrientation.of in
silk.text.unicode_properties to tell them apart from U and R.
Category: Text.
Profiles: aarch64-apple-darwin, aarch64-unknown-linux-gnu, aarch64-unknown-linux-gnu-no-libc, x86_64-unknown-linux-gnu, x86_64-unknown-linux-gnu-no-libc, wasm32-unknown-unknown, wasm32-wasip1, wasm32-wasip2, x86_64-pc-windows-msvc, wasm64-unknown-unknown.