Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ text streaming in at hundreds of characters a second doesn't make scrolling stut
marker) are built in, and you can draw shapes of your own, and animate a tag's letters and shapes when it
finishes arriving.
- **Fade-in.** Optionally, text fades in as it streams in. Core Animation plays the fades.
- **Right-to-left text.** Paragraphs in Arabic, Hebrew and other right-to-left scripts start at the right edge, and
selection follows the glyphs in text of mixed direction.
- **SwiftUI and UIKit.** `TranscriptText` for SwiftUI, `TranscriptTextView` for UIKit.

## Requirements
Expand Down Expand Up @@ -435,6 +437,26 @@ TranscriptText(document)
The same values are `lineLimit` and `textAlignment` on `TranscriptStyle`. The alignment moves paragraphs and headings;
lists, quotes, code and tables stay at the leading edge. A table is shown whole or not at all.

### Right-to-left text

Each block takes its direction from its first strong character, such as a letter. Digits, punctuation and spaces do
not count. So a paragraph that starts with a word in Arabic or Hebrew is right to left, and a paragraph that starts with
an English word is left to right, also when it holds words in other scripts.

In a right-to-left block, the leading edge is on the right. Lines start there, and `textAlignment` counts from there:
`.trailing` puts the lines at the left. The indents of lists and quotes, list markers and quote bars are on the right,
and a table puts its first column on the right. A table column with no colon in its delimiter cell (`---`) starts at
the leading edge. A colon on one side (`:---` or `---:`) puts the column's text at the left or at the right, in both
directions. Code blocks are always left to right.

A custom tag takes the direction of its first strong character. A right-to-left tag starts at the right: its padding
and its image before the text are on the right, and the built-in shapes are open on the correct side where the tag
wraps. `TranscriptFragment.isRightToLeft` tells a shape of your own the same.

A selection follows the glyphs. In text of mixed direction, one line can have several selection rects. In a line with
right-to-left text, the left and right arrow keys move the caret to the next caret on that side of the screen. Copy
gives the text in the order it was written.

### Styling

`TranscriptStyle` sets the body size, line, block and list spacing, indents, padding and the maximum image height.
Expand Down
10 changes: 7 additions & 3 deletions Sources/TranscriptKit/Layout/AccessibilityContent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ extension DocumentLayout {
definitions: definitions)
words?.keep(made, for: key, layout: entry.layout)
if let model = block.kind.table, let grid = entry.layout.table {
let table = Self.accessibilityTable(model, grid: grid, of: block, at: entry.y, words: made.cells,
let table = Self.accessibilityTable(model, grid: grid, of: block, at: entry.y,
rightToLeft: entry.layout.isRightToLeft, words: made.cells,
position: positions[index].map(AccessibilityText.position))
guard !table.cells.isEmpty else { continue }
items.append(AccessibilityItem(key: key, frame: entry.frame, label: "", value: nil, isHeading: false,
Expand Down Expand Up @@ -142,12 +143,15 @@ extension DocumentLayout {
}

private static func accessibilityTable(_ model: TranscriptTable, grid: BlockLayout.Table, of block: TranscriptBlock, at y: CGFloat,
words: [AccessibilityWords.Words], position: String?) -> AccessibilityItem.Table {
rightToLeft: Bool, words: [AccessibilityWords.Words],
position: String?) -> AccessibilityItem.Table {
var cells: [AccessibilityItem.Table.Cell] = []
let (rowCount, columnCount) = accessibilityGridSize(model, grid: grid)
for row in 0..<rowCount {
for column in 0..<min(model.rows[row].count, columnCount) where cells.count < words.count {
let frame = CGRect(x: grid.columnX[column], y: y + grid.rowY[row], width: grid.columnX[column + 1] - grid.columnX[column],
// The column edges go from left to right, and a right-to-left table starts on the right.
let edge = rightToLeft ? grid.columnX.count - 2 - column : column
let frame = CGRect(x: grid.columnX[edge], y: y + grid.rowY[row], width: grid.columnX[edge + 1] - grid.columnX[edge],
height: grid.rowY[row + 1] - grid.rowY[row])
let cell = words[cells.count]
let isFirst = cells.isEmpty
Expand Down
Loading
Loading