set root fill as transparent on pdf exports
This commit is contained in:
parent
a14871c81f
commit
66083e2d98
3 changed files with 9 additions and 5 deletions
|
|
@ -6,7 +6,6 @@ import (
|
||||||
"regexp"
|
"regexp"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
"github.com/davecgh/go-spew/spew"
|
|
||||||
"github.com/lucasb-eyer/go-colorful"
|
"github.com/lucasb-eyer/go-colorful"
|
||||||
"github.com/mazznoer/csscolorparser"
|
"github.com/mazznoer/csscolorparser"
|
||||||
)
|
)
|
||||||
|
|
@ -161,7 +160,6 @@ func (c *RGB) IsLight() bool {
|
||||||
|
|
||||||
hsp := math.Sqrt(0.299*math.Pow(r, 2) + 0.587*math.Pow(g, 2) + 0.114*math.Pow(b, 2))
|
hsp := math.Sqrt(0.299*math.Pow(r, 2) + 0.587*math.Pow(g, 2) + 0.114*math.Pow(b, 2))
|
||||||
|
|
||||||
spew.Dump(hsp)
|
|
||||||
return hsp > 130
|
return hsp > 130
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -170,9 +168,10 @@ func Hex2RGB(hex string) (RGB, error) {
|
||||||
var rgb RGB
|
var rgb RGB
|
||||||
if hex[0:1] == "#" {
|
if hex[0:1] == "#" {
|
||||||
hex = hex[1:]
|
hex = hex[1:]
|
||||||
|
} else {
|
||||||
|
return RGB{}, nil
|
||||||
}
|
}
|
||||||
values, err := strconv.ParseUint(hex, 16, 32)
|
values, err := strconv.ParseUint(hex, 16, 32)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return RGB{}, err
|
return RGB{}, err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -34,7 +34,7 @@ func Init() *GoFPDF {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *GoFPDF) GetFillRGB(fill string) (color.RGB, error) {
|
func (g *GoFPDF) GetFillRGB(fill string) (color.RGB, error) {
|
||||||
if fill == "" {
|
if fill == "" || strings.ToLower(fill) == "transparent" {
|
||||||
return color.RGB{
|
return color.RGB{
|
||||||
Red: 255,
|
Red: 255,
|
||||||
Green: 255,
|
Green: 255,
|
||||||
|
|
|
||||||
7
main.go
7
main.go
|
|
@ -458,6 +458,11 @@ func renderPDF(ctx context.Context, ms *xmain.State, plugin d2plugin.Plugin, ske
|
||||||
}
|
}
|
||||||
|
|
||||||
if !diagram.IsFolderOnly {
|
if !diagram.IsFolderOnly {
|
||||||
|
rootFill := diagram.Root.Fill
|
||||||
|
// gofpdf will print the png img with a slight filter
|
||||||
|
// strip out the background fill within the png so that the background is uniform in the exported pdf
|
||||||
|
diagram.Root.Fill = "transparent"
|
||||||
|
|
||||||
svg, err = d2svg.Render(diagram, &d2svg.RenderOpts{
|
svg, err = d2svg.Render(diagram, &d2svg.RenderOpts{
|
||||||
Pad: int(pad),
|
Pad: int(pad),
|
||||||
Sketch: sketch,
|
Sketch: sketch,
|
||||||
|
|
@ -484,7 +489,7 @@ func renderPDF(ctx context.Context, ms *xmain.State, plugin d2plugin.Plugin, ske
|
||||||
return svg, err
|
return svg, err
|
||||||
}
|
}
|
||||||
|
|
||||||
err = pdf.AddPDFPage(pngImg, currBoardPath, diagram.Root.Fill)
|
err = pdf.AddPDFPage(pngImg, currBoardPath, rootFill)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return svg, err
|
return svg, err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue