Compare commits
5 Commits
main
...
0c9d50ebcd
| Author | SHA1 | Date | |
|---|---|---|---|
| 0c9d50ebcd | |||
| 943fc57080 | |||
| 0592fe32b6 | |||
| 56cf7e3fb8 | |||
| 650ecf0c2e |
12
.editorconfig
Normal file
12
.editorconfig
Normal 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
|
||||
19
README.md
19
README.md
@@ -2,7 +2,20 @@
|
||||
|
||||
[](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.
|
||||
|
||||
@@ -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
|
||||
Reference in New Issue
Block a user