-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[font] add a cache for glyph extents
- Loading branch information
1 parent
1019675
commit 52836ef
Showing
16 changed files
with
157 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package font | ||
|
||
type glyphExtents struct { | ||
valid bool | ||
extents GlyphExtents | ||
} | ||
|
||
type extentsCache []glyphExtents | ||
|
||
func (ec extentsCache) get(gid GID) (GlyphExtents, bool) { | ||
if int(gid) >= len(ec) { | ||
return GlyphExtents{}, false | ||
} | ||
ge := ec[gid] | ||
return ge.extents, ge.valid | ||
} | ||
|
||
func (ec extentsCache) set(gid GID, extents GlyphExtents) { | ||
ec[gid].valid = true | ||
ec[gid].extents = extents | ||
} | ||
|
||
func (ec extentsCache) reset() { | ||
for i := range ec { | ||
ec[i] = glyphExtents{} | ||
} | ||
} | ||
|
||
func (f *Face) GlyphExtents(glyph GID) (GlyphExtents, bool) { | ||
if e, ok := f.extentsCache.get(glyph); ok { | ||
return e, ok | ||
} | ||
e, ok := f.glyphExtentsRaw(glyph) | ||
if ok { | ||
f.extentsCache.set(glyph, e) | ||
} | ||
return e, ok | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.