Implement PathFontMode and make it default
This commit is contained in:
parent
7419075cb6
commit
0b72959009
3 changed files with 31 additions and 11 deletions
|
@ -87,11 +87,11 @@ func toSvgPathDesc(p *draw2d.Path) string {
|
||||||
// dirty hack to ensure whole arc is drawn
|
// dirty hack to ensure whole arc is drawn
|
||||||
// if start point equals end point
|
// if start point equals end point
|
||||||
if sweep == 1 {
|
if sweep == 1 {
|
||||||
x += 0.0001 * sinfi
|
x += 0.01 * sinfi
|
||||||
y += 0.0001 * -cosfi
|
y += 0.01 * -cosfi
|
||||||
} else {
|
} else {
|
||||||
x += 0.0001 * sinfi
|
x += 0.01 * sinfi
|
||||||
y += 0.0001 * cosfi
|
y += 0.01 * cosfi
|
||||||
}
|
}
|
||||||
|
|
||||||
// rx ry x-axis-rotation large-arc-flag sweep-flag x y
|
// 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...)
|
return fmt.Sprintf(format, a...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO needs test, since it is not quiet right
|
||||||
func getPrec(num float64, better bool) int {
|
func getPrec(num float64, better bool) int {
|
||||||
max := 3
|
max := 3
|
||||||
eps := 0.0005
|
eps := 0.0005
|
||||||
|
|
|
@ -247,6 +247,16 @@ func (gc *GraphicContext) drawPaths(drawType drawType, paths ...*draw2d.Path) {
|
||||||
|
|
||||||
// Add text element to svg and returns its expected width
|
// Add text element to svg and returns its expected width
|
||||||
func (gc *GraphicContext) drawString(text string, drawType drawType, x, y float64) float64 {
|
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
|
// create elements
|
||||||
svgText := Text{}
|
svgText := Text{}
|
||||||
group := gc.newGroup(drawType)
|
group := gc.newGroup(drawType)
|
||||||
|
@ -258,10 +268,6 @@ func (gc *GraphicContext) drawString(text string, drawType drawType, x, y float6
|
||||||
svgText.Y = y
|
svgText.Y = y
|
||||||
svgText.FontFamily = gc.Current.FontData.Name
|
svgText.FontFamily = gc.Current.FontData.Name
|
||||||
|
|
||||||
if gc.svg.FontMode == SvgFontMode {
|
|
||||||
gc.embedSvgFont(text)
|
|
||||||
}
|
|
||||||
|
|
||||||
// attach to group
|
// attach to group
|
||||||
group.Texts = []*Text{&svgText}
|
group.Texts = []*Text{&svgText}
|
||||||
left, _, right, _ := gc.GetStringBounds(text)
|
left, _, right, _ := gc.GetStringBounds(text)
|
||||||
|
|
|
@ -11,11 +11,24 @@ import (
|
||||||
|
|
||||||
type FontMode int
|
type FontMode int
|
||||||
|
|
||||||
|
// Modes of font handling in svg
|
||||||
const (
|
const (
|
||||||
|
// Does nothing special
|
||||||
|
// Makes sense only for common system fonts
|
||||||
SysFontMode FontMode = 1 << iota
|
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
|
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
|
PathFontMode
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -33,7 +46,7 @@ func NewSvg() *Svg {
|
||||||
return &Svg{
|
return &Svg{
|
||||||
Xmlns: "http://www.w3.org/2000/svg",
|
Xmlns: "http://www.w3.org/2000/svg",
|
||||||
FillStroke: FillStroke{Fill: "none", Stroke: "none"},
|
FillStroke: FillStroke{Fill: "none", Stroke: "none"},
|
||||||
FontMode: SvgFontMode,
|
FontMode: PathFontMode,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue