5 Commits

Author SHA1 Message Date
0c9d50ebcd Remove setter.go 2024-09-10 11:19:31 -04:00
943fc57080 Remove old files from repository root 2024-09-10 11:18:13 -04:00
0592fe32b6 Add .editorconfig because why not 2024-09-10 11:17:52 -04:00
56cf7e3fb8 Update README.md 2024-09-10 11:17:29 -04:00
650ecf0c2e Back up old files 2024-09-10 11:17:10 -04:00
5 changed files with 33 additions and 3 deletions

12
.editorconfig Normal file
View File

@@ -0,0 +1,12 @@
root = true
[*]
end_of_line = lf
insert_final_newline = true
indent_style = tab
indent_size = 8
charset = utf-8
[*.md]
indent_style = space
indent_size = 2

View File

@@ -2,7 +2,20 @@
[![Go Reference](https://pkg.go.dev/badge/git.tebibyte.media/tomo/typeset.svg)](https://pkg.go.dev/git.tebibyte.media/tomo/typeset)
Typeset provides utilities for text layout, wrapping, and rendering.
Typeset provides utilities for text layout, wrapping, and rendering. It is
designed to avoid redundant work and minimize memory allocations wherever
posible in situations where the bounds of a section of text may change
frequently and its content semi-frequently. Text layout is performed by the
TypeSetter struct, which operates in a three-phase process:
The state of a text layout is stored in a TypeSetter, and it can be drawn to any
draw.Image using a Drawer which "extends" TypeSetter.
1. Tokenization
2. Measurement
3. Layout, alignment
The results of these phases are memoized. When the state of the TypeSetter is
queried, it will run through only the required phases before returning a value.
The contents of a TypeSetter can be drawn onto any draw.Image using the Draw
function included within this package, but it is entirely possible to create a
custom draw function that iterates over TypeSetter.Runes that uses some other
method of drawing that's faster than five gazillion virtual method calls.

View File

@@ -149,6 +149,7 @@ func DoLine (text []rune, face font.Face, wrap bool, width fixed.Int26_6) (line
// set the width of the line's content.
line.Width = width
// TODO: just have RecommendedHeight want aligned layout?
if len(line.Words) > 0 {
lastWord := line.Words[len(line.Words) - 1]
line.ContentWidth = x - lastWord.SpaceAfter
@@ -228,6 +229,10 @@ func (line *LineLayout) justify (tabWidth fixed.Int26_6) {
}
}
func tabStop (x, tabWidth fixed.Int26_6, delta int) fixed.Int26_6 {
return fixed.I((tabWidth * 64 / x).Floor() + delta).Mul(tabWidth)
}
func tofuAdvance (face font.Face) fixed.Int26_6 {
if advance, ok := face.GlyphAdvance('M'); ok {
return advance