support different transparencies for fillstroke
This commit is contained in:
parent
3450d01825
commit
fcd849f2e4
1 changed files with 25 additions and 7 deletions
|
@ -190,7 +190,9 @@ func (gc *GraphicContext) StrokeStringAt(text string, x, y float64) (cursor floa
|
||||||
|
|
||||||
// Stroke strokes the paths with the color specified by SetStrokeColor
|
// Stroke strokes the paths with the color specified by SetStrokeColor
|
||||||
func (gc *GraphicContext) Stroke(paths ...*draw2d.PathStorage) {
|
func (gc *GraphicContext) Stroke(paths ...*draw2d.PathStorage) {
|
||||||
gc.draw("D", paths...)
|
_, _, _, alphaS := gc.Current.StrokeColor.RGBA()
|
||||||
|
gc.draw("D", alphaS, paths...)
|
||||||
|
gc.Current.Path = draw2d.NewPathStorage()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fill fills the paths with the color specified by SetFillColor
|
// Fill fills the paths with the color specified by SetFillColor
|
||||||
|
@ -199,27 +201,43 @@ func (gc *GraphicContext) Fill(paths ...*draw2d.PathStorage) {
|
||||||
if !gc.Current.FillRule.UseNonZeroWinding() {
|
if !gc.Current.FillRule.UseNonZeroWinding() {
|
||||||
style += "*"
|
style += "*"
|
||||||
}
|
}
|
||||||
gc.draw(style, paths...)
|
_, _, _, alphaF := gc.Current.FillColor.RGBA()
|
||||||
|
gc.draw(style, alphaF, paths...)
|
||||||
|
gc.Current.Path = draw2d.NewPathStorage()
|
||||||
}
|
}
|
||||||
|
|
||||||
// FillStroke first fills the paths and than strokes them
|
// FillStroke first fills the paths and than strokes them
|
||||||
func (gc *GraphicContext) FillStroke(paths ...*draw2d.PathStorage) {
|
func (gc *GraphicContext) FillStroke(paths ...*draw2d.PathStorage) {
|
||||||
style := "FD"
|
var rule string
|
||||||
if !gc.Current.FillRule.UseNonZeroWinding() {
|
if !gc.Current.FillRule.UseNonZeroWinding() {
|
||||||
style += "*"
|
rule = "*"
|
||||||
}
|
}
|
||||||
gc.draw(style, paths...)
|
_, _, _, alphaS := gc.Current.StrokeColor.RGBA()
|
||||||
|
_, _, _, alphaF := gc.Current.FillColor.RGBA()
|
||||||
|
if alphaS == alphaF {
|
||||||
|
gc.draw("FD"+rule, alphaF, paths...)
|
||||||
|
} else {
|
||||||
|
gc.draw("F"+rule, alphaF, paths...)
|
||||||
|
gc.draw("S", alphaS, paths...)
|
||||||
|
}
|
||||||
|
gc.Current.Path = draw2d.NewPathStorage()
|
||||||
}
|
}
|
||||||
|
|
||||||
var logger = log.New(os.Stdout, "", log.Lshortfile)
|
var logger = log.New(os.Stdout, "", log.Lshortfile)
|
||||||
|
|
||||||
|
const alphaMax = float64(0xFFFF)
|
||||||
|
|
||||||
// draw fills and/or strokes paths
|
// draw fills and/or strokes paths
|
||||||
func (gc *GraphicContext) draw(style string, paths ...*draw2d.PathStorage) {
|
func (gc *GraphicContext) draw(style string, alpha uint32, paths ...*draw2d.PathStorage) {
|
||||||
paths = append(paths, gc.Current.Path)
|
paths = append(paths, gc.Current.Path)
|
||||||
pathConverter := NewPathConverter(gc.pdf)
|
pathConverter := NewPathConverter(gc.pdf)
|
||||||
pathConverter.Convert(paths...)
|
pathConverter.Convert(paths...)
|
||||||
|
a := float64(alpha) / alphaMax
|
||||||
|
current, blendMode := gc.pdf.GetAlpha()
|
||||||
|
if a != current {
|
||||||
|
gc.pdf.SetAlpha(a, blendMode)
|
||||||
|
}
|
||||||
gc.pdf.DrawPath(style)
|
gc.pdf.DrawPath(style)
|
||||||
gc.Current.Path = draw2d.NewPathStorage()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// overwrite StackGraphicContext methods
|
// overwrite StackGraphicContext methods
|
||||||
|
|
Loading…
Reference in a new issue