Documentation
¶
Index ¶
- func CreateSolidColor(c color.Color) *image.Uniform
- type AlignmentBaseline
- type FontMetrics
- type FontStyle
- type FontWeight
- type SVGTextRenderer
- func (r *SVGTextRenderer) AddFontPath(fontPath string)
- func (r *SVGTextRenderer) ClearFontCache()
- func (r *SVGTextRenderer) GetFontMetrics(style *TextStyle) (*FontMetrics, error)
- func (r *SVGTextRenderer) GetLoadedFonts() []string
- func (r *SVGTextRenderer) LoadFontFromFile(fontPath, fontFamily string, fontSize float64) error
- func (r *SVGTextRenderer) MeasureText(text string, style *TextStyle) (*FontMetrics, error)
- func (r *SVGTextRenderer) RegisterFontFamily(familyName string, fontFiles []string)
- func (r *SVGTextRenderer) RenderText(img draw.Image, text string, x, y float64, style *TextStyle) error
- type TextAnchor
- type TextRenderer
- type TextStyle
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type AlignmentBaseline ¶
type AlignmentBaseline string
AlignmentBaseline 定义基线对齐类型
const ( AlignmentBaselineAlphabetic AlignmentBaseline = "alphabetic" AlignmentBaselineMiddle AlignmentBaseline = "middle" AlignmentBaselineHanging AlignmentBaseline = "hanging" AlignmentBaselineTop AlignmentBaseline = "top" AlignmentBaselineBottom AlignmentBaseline = "bottom" )
type FontMetrics ¶
type FontMetrics struct { Ascent float64 // 上升高度 Descent float64 // 下降高度 Height float64 // 总高度 Advance float64 // 字符前进宽度 }
FontMetrics 字体度量信息
type FontWeight ¶
type FontWeight string
FontWeight 定义字体粗细类型 / Font weight type definition
const ( FontWeightNormal FontWeight = "normal" // 400 FontWeightBold FontWeight = "bold" // 700 FontWeightBolder FontWeight = "bolder" // 相对于父元素更粗 / Bolder than parent FontWeightLighter FontWeight = "lighter" // 相对于父元素更细 / Lighter than parent FontWeight100 FontWeight = "100" // 最细 / Thinnest FontWeight200 FontWeight = "200" // 很细 / Extra light FontWeight300 FontWeight = "300" // 细 / Light FontWeight400 FontWeight = "400" // 正常 / Normal FontWeight500 FontWeight = "500" // 中等 / Medium FontWeight600 FontWeight = "600" // 半粗 / Semi bold FontWeight700 FontWeight = "700" // 粗 / Bold FontWeight800 FontWeight = "800" // 很粗 / Extra bold FontWeight900 FontWeight = "900" // 最粗 / Black FontWeightLight FontWeight = "light" // 轻量 / Light FontWeightMedium FontWeight = "medium" // 中等 / Medium FontWeightSemibold FontWeight = "semibold" // 半粗 / Semi bold FontWeightBlack FontWeight = "black" // 超粗 / Black )
type SVGTextRenderer ¶
type SVGTextRenderer struct {
// contains filtered or unexported fields
}
SVGTextRenderer 是符合SVG标准的文本渲染器实现
func NewSVGTextRenderer ¶
func NewSVGTextRenderer() *SVGTextRenderer
NewSVGTextRenderer 创建新的SVG文本渲染器 / Create a new SVG text renderer
func NewSVGTextRendererWithFonts ¶
func NewSVGTextRendererWithFonts(customFontPaths []string) *SVGTextRenderer
NewSVGTextRendererWithFonts 创建带自定义字体路径的SVG文本渲染器 / Create SVG text renderer with custom font paths
func (*SVGTextRenderer) AddFontPath ¶
func (r *SVGTextRenderer) AddFontPath(fontPath string)
AddFontPath 添加自定义字体路径 / Add custom font path
func (*SVGTextRenderer) ClearFontCache ¶
func (r *SVGTextRenderer) ClearFontCache()
ClearFontCache 清空字体缓存 / Clear font cache
func (*SVGTextRenderer) GetFontMetrics ¶
func (r *SVGTextRenderer) GetFontMetrics(style *TextStyle) (*FontMetrics, error)
GetFontMetrics 获取字体度量信息
func (*SVGTextRenderer) GetLoadedFonts ¶
func (r *SVGTextRenderer) GetLoadedFonts() []string
GetLoadedFonts 获取已加载的字体列表 / Get list of loaded fonts
func (*SVGTextRenderer) LoadFontFromFile ¶
func (r *SVGTextRenderer) LoadFontFromFile(fontPath, fontFamily string, fontSize float64) error
LoadFontFromFile 直接从文件加载字体 / Load font directly from file
func (*SVGTextRenderer) MeasureText ¶
func (r *SVGTextRenderer) MeasureText(text string, style *TextStyle) (*FontMetrics, error)
MeasureText 测量文本尺寸
func (*SVGTextRenderer) RegisterFontFamily ¶
func (r *SVGTextRenderer) RegisterFontFamily(familyName string, fontFiles []string)
RegisterFontFamily 注册字体族映射 / Register font family mapping
func (*SVGTextRenderer) RenderText ¶
func (r *SVGTextRenderer) RenderText(img draw.Image, text string, x, y float64, style *TextStyle) error
RenderText 在图像上渲染文本 / Render text on image
type TextAnchor ¶
type TextAnchor string
TextAnchor 定义文本锚点类型
const ( TextAnchorStart TextAnchor = "start" TextAnchorMiddle TextAnchor = "middle" TextAnchorEnd TextAnchor = "end" )
type TextRenderer ¶
type TextRenderer interface { // RenderText 在图像上渲染文本 RenderText(img draw.Image, text string, x, y float64, style *TextStyle) error // MeasureText 测量文本尺寸 MeasureText(text string, style *TextStyle) (*FontMetrics, error) // GetFontMetrics 获取字体度量信息 GetFontMetrics(style *TextStyle) (*FontMetrics, error) }
TextRenderer 是文本渲染器接口
var DefaultTextRenderer TextRenderer = NewSVGTextRenderer()
DefaultTextRenderer 是默认的文本渲染器
type TextStyle ¶
type TextStyle struct { FontFamily string // 字体族 / Font family FontSize float64 // 字体大小 / Font size FontWeight FontWeight // 字体粗细 / Font weight (supports numeric and keyword values) FontStyle FontStyle // 字体样式 / Font style TextAnchor TextAnchor // 文本锚点 / Text anchor AlignmentBaseline AlignmentBaseline // 基线对齐 / Alignment baseline Fill image.Image // 填充颜色 / Fill color Stroke image.Image // 描边颜色 / Stroke color StrokeWidth float64 // 描边宽度 / Stroke width LetterSpacing float64 // 字符间距 / Letter spacing WordSpacing float64 // 单词间距 / Word spacing TextDecoration string // 文本装饰 / Text decoration (underline, overline, line-through) }
TextStyle 文本样式 / Text style definition