Skip to content
Inkoxide

Search covers every page and heading of the docs. Use ↑ ↓ and ↵.

Text: hyphenation and direction

Edit this page

The code on this page is React’s. How Vue writes it
ReactVue
ClassesclassName="p-4"class="p-4"
PropsheaderRows={1}:header-rows="1" or :headerRows="1"
A prop that is truehyphenatehyphenate
Content per pagerender={({ pageNumber }) => …}<template #render="{ pageNumber, totalPages }">…</template>
The page, deeper downusePage()usePage() (it injects the page)
What to render<Invoice invoice={invoice} />h(Invoice, { invoice })
A template for generateTemplate: 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
ReactSvelte
ClassesclassName="p-4"class="p-4" (a list or an object of flags too)
Content per pagerender={({ pageNumber }) => …}{#snippet render(page)}{page.pageNumber}{/snippet} inside the Text or View
The page, deeper downusePage()usePage(), while the component is created
What to render<Invoice invoice={invoice} />{ component: Invoice, props: { invoice } }
A template for generateTemplate: 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
ReactAngular
Components<View>, <Path>, <TextField><ink-view>, <ink-path>, <ink-text-field>: ink- and the name in kebab case
ClassesclassName="p-4"class="p-4", [class]="…"
PropsheaderRows={1}, size="A4"[headerRows]="1", size="A4" (an attribute is a string: bind numbers)
A prop that is truehyphenatehyphenate
Stylestyle={{ padding: 20 }}[style]="{ padding: 20 }"; [inkStyle] for @media blocks and lists of styles
Content per pagerender={({ pageNumber }) => …}[render]="footer" with <ng-template #footer let-page>{{ page.pageNumber }}</ng-template>
The page, deeper downusePage()injectPage()
What to render<Invoice invoice={invoice} />{ component: Invoice, inputs: { invoice } }
A template for generateTemplate: 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 Text with hyphenate (or the class hyphens-auto); it follows the lang of the text or the document. With neither, nothing is hyphenated, and the warnings of generate say so. US English patterns ship with the package and serve every English lang; other languages use the engine's built-in patterns, and Romanian (ro) its syllable rules. A paragraph is hyphenated in one language, so a Text inside a Text with another lang is not hyphenated by patterns: make it a paragraph of its own, or give it a hyphenationCallback. A soft hyphen (\u00AD) in the text is a possible break with or without hyphenate, unless hyphenationPenalty is 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 with whitespace-nowrap or whitespace-pre is never broken: a long word overflows the line.

  • Your own hyphenation. Font.registerHyphenationCallback sets a function that splits each word into the parts a line may break between, for every Text; [word] keeps a word from being hyphenated. It replaces the built-in patterns, so hyphenate is 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 uppercase or another text transform; spaces, digits and punctuation stay as they are, and a word that already has soft hyphens is left alone. A Text, or a Text inside one, takes its own function with hyphenationCallback={fn}, and the built-in patterns leave its words alone; it goes back to hyphenate and lang with hyphenationCallback={null}. hyphenate={false} (or hyphens-none) turns the callback off for that text. Text with whitespace-nowrap or whitespace-pre is not broken.

  • Right-to-left text uses dir="rtl" on a Text. Register a font that covers the script first (for example Noto Sans Arabic or Noto Sans Hebrew with Font.register): the bundled fonts cover Latin, Greek and Cyrillic.

  • Even lines. textWrap: 'pretty' (the class text-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 with whitespace-nowrap or whitespace-pre, and very long paragraphs past the limits in the schema, break first fit. hyphenationPenalty={n} on a Text (or in its style, inherited) says how much pretty avoids 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, whatever textWrap.

  • Balanced headings. textWrap: 'balance' (the class text-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} and widows={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.