2017-07-05 23:10:57 +00:00
|
|
|
/*
|
|
|
|
* This file is subject to the terms and conditions defined in
|
|
|
|
* file 'LICENSE.md', which is part of this source code package.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package fonts
|
|
|
|
|
|
|
|
import (
|
2018-07-15 16:28:56 +10:00
|
|
|
"github.com/unidoc/unidoc/pdf/core"
|
2017-07-05 23:10:57 +00:00
|
|
|
"github.com/unidoc/unidoc/pdf/model/textencoding"
|
|
|
|
)
|
|
|
|
|
2018-06-27 12:25:59 +10:00
|
|
|
// Font represents a font which is a series of glyphs. Character codes from PDF strings can be
|
|
|
|
// mapped to and from glyphs. Each glyph has metrics.
|
2017-07-05 23:10:57 +00:00
|
|
|
type Font interface {
|
2017-09-01 13:20:51 +00:00
|
|
|
Encoder() textencoding.TextEncoder
|
2017-07-05 23:10:57 +00:00
|
|
|
SetEncoder(encoder textencoding.TextEncoder)
|
|
|
|
GetGlyphCharMetrics(glyph string) (CharMetrics, bool)
|
2018-09-19 11:12:59 +10:00
|
|
|
GetAverageCharWidth() float64
|
2018-07-15 16:28:56 +10:00
|
|
|
ToPdfObject() core.PdfObject
|
2017-07-05 23:10:57 +00:00
|
|
|
}
|
|
|
|
|
2017-09-01 13:20:51 +00:00
|
|
|
// CharMetrics represents width and height metrics of a glyph.
|
2017-07-05 23:10:57 +00:00
|
|
|
type CharMetrics struct {
|
|
|
|
GlyphName string
|
|
|
|
Wx float64
|
|
|
|
Wy float64
|
|
|
|
}
|
2018-09-19 11:12:59 +10:00
|
|
|
|
|
|
|
func AverageCharWidth(metrics map[string]CharMetrics) float64 {
|
|
|
|
total := 0.0
|
|
|
|
for _, m := range metrics {
|
|
|
|
total += m.Wx
|
|
|
|
}
|
|
|
|
return total / float64(len(metrics))
|
|
|
|
}
|