Implement PathFontMode and make it default

This commit is contained in:
Drahoslav 2018-01-10 23:00:32 +01:00
parent 7419075cb6
commit 0b72959009
3 changed files with 31 additions and 11 deletions

View File

@ -87,11 +87,11 @@ func toSvgPathDesc(p *draw2d.Path) string {
// dirty hack to ensure whole arc is drawn
// if start point equals end point
if sweep == 1 {
x += 0.0001 * sinfi
y += 0.0001 * -cosfi
x += 0.01 * sinfi
y += 0.01 * -cosfi
} else {
x += 0.0001 * sinfi
y += 0.0001 * cosfi
x += 0.01 * sinfi
y += 0.01 * cosfi
}
// rx ry x-axis-rotation large-arc-flag sweep-flag x y
@ -153,6 +153,7 @@ func optiSprintf(format string, a ...interface{}) string {
return fmt.Sprintf(format, a...)
}
// TODO needs test, since it is not quiet right
func getPrec(num float64, better bool) int {
max := 3
eps := 0.0005

View File

@ -247,6 +247,16 @@ func (gc *GraphicContext) drawPaths(drawType drawType, paths ...*draw2d.Path) {
// Add text element to svg and returns its expected width
func (gc *GraphicContext) drawString(text string, drawType drawType, x, y float64) float64 {
switch gc.svg.FontMode {
case PathFontMode:
w := gc.CreateStringPath(text, x, y)
gc.drawPaths(drawType)
gc.Current.Path.Clear()
return w
case SvgFontMode:
gc.embedSvgFont(text)
}
// create elements
svgText := Text{}
group := gc.newGroup(drawType)
@ -258,10 +268,6 @@ func (gc *GraphicContext) drawString(text string, drawType drawType, x, y float6
svgText.Y = y
svgText.FontFamily = gc.Current.FontData.Name
if gc.svg.FontMode == SvgFontMode {
gc.embedSvgFont(text)
}
// attach to group
group.Texts = []*Text{&svgText}
left, _, right, _ := gc.GetStringBounds(text)

View File

@ -11,11 +11,24 @@ import (
type FontMode int
// Modes of font handling in svg
const (
// Does nothing special
// Makes sense only for common system fonts
SysFontMode FontMode = 1 << iota
LinkFontMode
// Links font files in css def
// Requires distribution of font files with outputed svg
LinkFontMode // TODO implement
// Embeds glyphs definition in svg file itself in svg font format
// Has poor browser support
SvgFontMode
CssFontMode
// Embeds font definiton in svg file itself in woff format as part of css def
CssFontMode // TODO implement
// Converts texts to paths
PathFontMode
)
@ -33,7 +46,7 @@ func NewSvg() *Svg {
return &Svg{
Xmlns: "http://www.w3.org/2000/svg",
FillStroke: FillStroke{Fill: "none", Stroke: "none"},
FontMode: SvgFontMode,
FontMode: PathFontMode,
}
}