Text: hyphenation and direction
The code on this page is React’s. How Vue writes it
| React | Vue | |
|---|---|---|
| Classes | className="p-4" | class="p-4" |
| Props | headerRows={1} | :header-rows="1" or :headerRows="1" |
A prop that is true | hyphenate | hyphenate |
| Content per page | render={({ pageNumber }) => …} | <template #render="{ pageNumber, totalPages }">…</template> |
| The page, deeper down | usePage() | usePage() (it injects the page) |
| What to render | <Invoice invoice={invoice} /> | h(Invoice, { invoice }) |
A template for generate | Template: ComponentType<{ data }> | Template: a component with the prop data |
The rest, and Vue’s own API, is in the Vue guide.
The code on this page is React’s. How Svelte writes it
| React | Svelte | |
|---|---|---|
| Classes | className="p-4" | class="p-4" (a list or an object of flags too) |
| Content per page | render={({ pageNumber }) => …} | {#snippet render(page)}{page.pageNumber}{/snippet} inside the Text or View |
| The page, deeper down | usePage() | usePage(), while the component is created |
| What to render | <Invoice invoice={invoice} /> | { component: Invoice, props: { invoice } } |
A template for generate | Template: ComponentType<{ data }> | Template: a component with the prop data |
The rest, and Svelte’s own API, is in the Svelte guide.
The code on this page is React’s. How Angular writes it
| React | Angular | |
|---|---|---|
| Components | <View>, <Path>, <TextField> | <ink-view>, <ink-path>, <ink-text-field>: ink- and the name in kebab case |
| Classes | className="p-4" | class="p-4", [class]="…" |
| Props | headerRows={1}, size="A4" | [headerRows]="1", size="A4" (an attribute is a string: bind numbers) |
A prop that is true | hyphenate | hyphenate |
| Style | style={{ padding: 20 }} | [style]="{ padding: 20 }"; [inkStyle] for @media blocks and lists of styles |
| Content per page | render={({ pageNumber }) => …} | [render]="footer" with <ng-template #footer let-page>{{ page.pageNumber }}</ng-template> |
| The page, deeper down | usePage() | injectPage() |
| What to render | <Invoice invoice={invoice} /> | { component: Invoice, inputs: { invoice } } |
A template for generate | Template: ComponentType<{ data }> | Template: a component with the input data |
The rest, and Angular’s own API, is in the Angular guide.
<Document lang="en-US">
<Page>
<Text className="text-justify" hyphenate>Long paragraphs break words at syllables.</Text>
</Page>
</Document>
-
Hyphenation is off by default. Turn it on per
Textwithhyphenate(or the classhyphens-auto); it follows thelangof the text or the document. With neither, nothing is hyphenated, and thewarningsofgeneratesay so. US English patterns ship with the package and serve every Englishlang; other languages use the engine's built-in patterns, and Romanian (ro) its syllable rules. A paragraph is hyphenated in one language, so aTextinside aTextwith anotherlangis not hyphenated by patterns: make it a paragraph of its own, or give it ahyphenationCallback. A soft hyphen (\u00AD) in the text is a possible break with or withouthyphenate, unlesshyphenationPenaltyis 10 000 or the text does not wrap (whitespace-nowrap,whitespace-pre). -
Words wider than the line. A word that does not fit its line is broken between any two characters, hyphenated or not, as CSS does with
overflow-wrap: break-word(never inside a grapheme cluster, such as a letter with its accent or an emoji); the word still counts whole when an'auto'table column or a box is sized to its content.[word]from a hyphenation callback keeps a word from being hyphenated, but not from being broken this way. Text withwhitespace-nowraporwhitespace-preis never broken: a long word overflows the line. -
Your own hyphenation.
Font.registerHyphenationCallbacksets a function that splits each word into the parts a line may break between, for everyText;[word]keeps a word from being hyphenated. It replaces the built-in patterns, sohyphenateis not needed with it.import { Font } from '@inkoxide/react'; const whole = new Set(['Inkoxide', 'PostgreSQL']); // syllables(word) is your own rules, or a hyphenation library: 'hyphenation' → ['hy', 'phen', 'ation']. Font.registerHyphenationCallback((word) => (whole.has(word) ? [word] : syllables(word)));A word is a run of letters as displayed, after
uppercaseor another text transform; spaces, digits and punctuation stay as they are, and a word that already has soft hyphens is left alone. AText, or aTextinside one, takes its own function withhyphenationCallback={fn}, and the built-in patterns leave its words alone; it goes back tohyphenateandlangwithhyphenationCallback={null}.hyphenate={false}(orhyphens-none) turns the callback off for that text. Text withwhitespace-nowraporwhitespace-preis not broken. -
Right-to-left text uses
dir="rtl"on aText. Register a font that covers the script first (for example Noto Sans Arabic or Noto Sans Hebrew withFont.register): the bundled fonts cover Latin, Greek and Cyrillic. -
Even lines.
textWrap: 'pretty'(the classtext-pretty) breaks a paragraph's lines over the whole paragraph instead of filling each in turn, as TeX does: lines come out more even, with fewer hyphens, and the spaces of justified lines may also shrink by up to a third. It is inherited, so<Page style={{ textWrap: 'pretty' }}>sets it for a page.'wrap'is the default and fills lines in turn. Text withwhitespace-nowraporwhitespace-pre, and very long paragraphs past the limits in the schema, break first fit.hyphenationPenalty={n}on aText(or in its style, inherited) says how muchprettyavoids hyphens: 50 by default, 0 hyphenates as readily as it breaks at a space, and higher values give fewer hyphens and looser lines; 10 000 never breaks a word at a hyphenation point, whatevertextWrap. -
Balanced headings.
textWrap: 'balance'(the classtext-balance) breaks a heading or a caption into as many lines as it would take anyway, but makes them about as long as each other, instead of a full line and a word or two on the next. Text of one line or more than ten, beside a float, or with a word wider than its line breaks as'wrap'. -
Orphans and widows:
orphans={2}andwidows={2}keep at least two lines of a paragraph together at the foot and the head of a page.
Synced from packages/react/GUIDE.md in the inkoxide repository.