mirror of
https://github.com/xiaoqidun/ofdgo.git
synced 2026-08-30 12:12:40 +08:00
feat(字体绘制): 优化字体绘制
This commit is contained in:
+16
-1
@@ -480,6 +480,14 @@ func (r *Renderer) renderText(ctx *canvas.Context, obj TextObject, pageH float64
|
|||||||
if obj.Italic {
|
if obj.Italic {
|
||||||
fontStyle |= canvas.FontItalic
|
fontStyle |= canvas.FontItalic
|
||||||
}
|
}
|
||||||
|
if of, ok := r.Reader.fontCache[obj.Font]; ok {
|
||||||
|
if of.Bold {
|
||||||
|
fontStyle |= canvas.FontBold
|
||||||
|
}
|
||||||
|
if of.Italic {
|
||||||
|
fontStyle |= canvas.FontItalic
|
||||||
|
}
|
||||||
|
}
|
||||||
ff := r.loadFont(obj.Font)
|
ff := r.loadFont(obj.Font)
|
||||||
face := ff.Face(sizePt, textColor, fontStyle, canvas.FontNormal)
|
face := ff.Face(sizePt, textColor, fontStyle, canvas.FontNormal)
|
||||||
for _, tc := range obj.TextCode {
|
for _, tc := range obj.TextCode {
|
||||||
@@ -534,7 +542,14 @@ func (r *Renderer) loadFont(fontID string) *canvas.FontFamily {
|
|||||||
ff := canvas.NewFontFamily(of.FontName)
|
ff := canvas.NewFontFamily(of.FontName)
|
||||||
if of.FontFile != "" {
|
if of.FontFile != "" {
|
||||||
if fontData, err := r.Reader.ResData(of.FontFile); err == nil {
|
if fontData, err := r.Reader.ResData(of.FontFile); err == nil {
|
||||||
if err := ff.LoadFont(fontData, 0, canvas.FontRegular); err == nil {
|
fontStyle := canvas.FontRegular
|
||||||
|
if of.Bold {
|
||||||
|
fontStyle |= canvas.FontBold
|
||||||
|
}
|
||||||
|
if of.Italic {
|
||||||
|
fontStyle |= canvas.FontItalic
|
||||||
|
}
|
||||||
|
if err := ff.LoadFont(fontData, 0, fontStyle); err == nil {
|
||||||
r.FontMap[fontID] = ff
|
r.FontMap[fontID] = ff
|
||||||
return ff
|
return ff
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user