2026-03-24 20:24:08 +00:00
|
|
|
---
|
|
|
|
|
title: useTypography
|
feat(text): deepen typography controls
- Add case, justification, vertical alignment, truncation, max-lines, and OpenType controls
- Apply visual text case and measured vertical offsets in CanvasKit rendering
- Preserve nullable preview values, shared text styles, font demand, and .fig metadata
- Add panel, engine, and canvas visual coverage
2026-07-17 19:40:52 +00:00
|
|
|
description: Read and update font, alignment, case, truncation, and OpenType features for text nodes.
|
2026-03-24 20:24:08 +00:00
|
|
|
---
|
|
|
|
|
|
|
|
|
|
# useTypography
|
|
|
|
|
|
|
|
|
|
`useTypography()` is the text-property control composable for text editing panels.
|
|
|
|
|
|
|
|
|
|
It exposes:
|
|
|
|
|
|
|
|
|
|
- font family
|
|
|
|
|
- font weight
|
|
|
|
|
- font size
|
|
|
|
|
- formatting state
|
|
|
|
|
- missing-font status
|
feat(text): deepen typography controls
- Add case, justification, vertical alignment, truncation, max-lines, and OpenType controls
- Apply visual text case and measured vertical offsets in CanvasKit rendering
- Preserve nullable preview values, shared text styles, font demand, and .fig metadata
- Add panel, engine, and canvas visual coverage
2026-07-17 19:40:52 +00:00
|
|
|
- horizontal and vertical alignment, including justification
|
|
|
|
|
- text case and direction
|
|
|
|
|
- ending truncation and maximum lines
|
|
|
|
|
- OpenType feature toggles
|
2026-03-24 20:24:08 +00:00
|
|
|
- helpers for changing family, weight, alignment, and decorations
|
|
|
|
|
|
|
|
|
|
## Usage
|
|
|
|
|
|
|
|
|
|
```ts
|
|
|
|
|
import { useTypography } from '@open-pencil/vue'
|
|
|
|
|
|
|
|
|
|
const typography = useTypography()
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
## Basic example
|
|
|
|
|
|
|
|
|
|
```ts
|
|
|
|
|
const {
|
|
|
|
|
fontFamily,
|
|
|
|
|
fontWeight,
|
|
|
|
|
fontSize,
|
|
|
|
|
activeFormatting,
|
|
|
|
|
setFamily,
|
|
|
|
|
setWeight,
|
|
|
|
|
setAlign,
|
feat(text): deepen typography controls
- Add case, justification, vertical alignment, truncation, max-lines, and OpenType controls
- Apply visual text case and measured vertical offsets in CanvasKit rendering
- Preserve nullable preview values, shared text styles, font demand, and .fig metadata
- Add panel, engine, and canvas visual coverage
2026-07-17 19:40:52 +00:00
|
|
|
setVerticalAlign,
|
|
|
|
|
setTextCase,
|
|
|
|
|
setTruncation,
|
|
|
|
|
setFontFeature,
|
2026-03-24 20:24:08 +00:00
|
|
|
} = useTypography()
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
## Practical examples
|
|
|
|
|
|
|
|
|
|
### Load and switch a font family
|
|
|
|
|
|
|
|
|
|
```ts
|
|
|
|
|
const typography = useTypography({
|
feat(text): deepen typography controls
- Add case, justification, vertical alignment, truncation, max-lines, and OpenType controls
- Apply visual text case and measured vertical offsets in CanvasKit rendering
- Preserve nullable preview values, shared text styles, font demand, and .fig metadata
- Add panel, engine, and canvas visual coverage
2026-07-17 19:40:52 +00:00
|
|
|
fontLoader: {
|
|
|
|
|
load: async (family, style) => {
|
|
|
|
|
await myFontLoader(family, style)
|
|
|
|
|
},
|
2026-03-24 20:24:08 +00:00
|
|
|
},
|
|
|
|
|
})
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
### Toggle formatting
|
|
|
|
|
|
|
|
|
|
```ts
|
|
|
|
|
typography.toggleBold()
|
|
|
|
|
typography.toggleItalic()
|
|
|
|
|
typography.toggleDecoration('UNDERLINE')
|
feat(text): deepen typography controls
- Add case, justification, vertical alignment, truncation, max-lines, and OpenType controls
- Apply visual text case and measured vertical offsets in CanvasKit rendering
- Preserve nullable preview values, shared text styles, font demand, and .fig metadata
- Add panel, engine, and canvas visual coverage
2026-07-17 19:40:52 +00:00
|
|
|
typography.setTextCase('UPPER')
|
|
|
|
|
typography.setVerticalAlign('CENTER')
|
|
|
|
|
typography.setTruncation('ENDING')
|
|
|
|
|
typography.setFontFeature('LIGA', false)
|
2026-03-24 20:24:08 +00:00
|
|
|
```
|
|
|
|
|
|
|
|
|
|
## Related APIs
|
|
|
|
|
|
|
|
|
|
- [useTextEdit](./use-text-edit)
|
|
|
|
|
- [useSelectionState](./use-selection-state)
|