text/shaper: lookup closest font by weight

Signed-off-by: Walter Werner SCHNEIDER <contact@schnwalter.eu>
This commit is contained in:
Walter Werner SCHNEIDER
2021-09-02 22:20:38 +03:00
committed by Elias Naur
parent 23f6dcb868
commit 49a7b2e6f4
3 changed files with 163 additions and 15 deletions
+12
View File
@@ -114,3 +114,15 @@ func (s Style) String() string {
panic("invalid Style")
}
}
// weightDistance returns the distance value between two font weights.
func weightDistance(wa Weight, wb Weight) int {
// Avoid dealing with negative Weight values.
a := int(wa) + 400
b := int(wb) + 400
diff := a - b
if diff < 0 {
return -diff
}
return diff
}