pass viewbox coords in
This commit is contained in:
parent
51d0000e0f
commit
5e2ce123fc
2 changed files with 11 additions and 11 deletions
|
|
@ -8,6 +8,7 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
|
@ -489,7 +490,15 @@ func renderPDF(ctx context.Context, ms *xmain.State, plugin d2plugin.Plugin, ske
|
||||||
}
|
}
|
||||||
|
|
||||||
viewboxSlice := appendix.FindViewboxSlice(svg)
|
viewboxSlice := appendix.FindViewboxSlice(svg)
|
||||||
err = pdf.AddPDFPage(pngImg, currBoardPath, themeID, rootFill, diagram.Shapes, pad, viewboxSlice)
|
viewboxX, err := strconv.ParseFloat(viewboxSlice[0], 64)
|
||||||
|
if err != nil {
|
||||||
|
return svg, err
|
||||||
|
}
|
||||||
|
viewboxY, err := strconv.ParseFloat(viewboxSlice[1], 64)
|
||||||
|
if err != nil {
|
||||||
|
return svg, err
|
||||||
|
}
|
||||||
|
err = pdf.AddPDFPage(pngImg, currBoardPath, themeID, rootFill, diagram.Shapes, pad, viewboxX, viewboxY)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return svg, err
|
return svg, err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,6 @@ package pdf
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"math"
|
"math"
|
||||||
"strconv"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/jung-kurt/gofpdf"
|
"github.com/jung-kurt/gofpdf"
|
||||||
|
|
@ -59,7 +58,7 @@ func (g *GoFPDF) GetFillRGB(themeID int64, fill string) (color.RGB, error) {
|
||||||
return color.Hex2RGB(fill)
|
return color.Hex2RGB(fill)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *GoFPDF) AddPDFPage(png []byte, boardPath []string, themeID int64, fill string, shapes []d2target.Shape, pad int64, viewboxSlice []string) error {
|
func (g *GoFPDF) AddPDFPage(png []byte, boardPath []string, themeID int64, fill string, shapes []d2target.Shape, pad int64, viewboxX, viewboxY float64) error {
|
||||||
var opt gofpdf.ImageOptions
|
var opt gofpdf.ImageOptions
|
||||||
opt.ImageType = "png"
|
opt.ImageType = "png"
|
||||||
imageInfo := g.pdf.RegisterImageOptionsReader(strings.Join(boardPath, "/"), opt, bytes.NewReader(png))
|
imageInfo := g.pdf.RegisterImageOptionsReader(strings.Join(boardPath, "/"), opt, bytes.NewReader(png))
|
||||||
|
|
@ -126,14 +125,6 @@ func (g *GoFPDF) AddPDFPage(png []byte, boardPath []string, themeID int64, fill
|
||||||
// Draw external links
|
// Draw external links
|
||||||
for _, shape := range shapes {
|
for _, shape := range shapes {
|
||||||
if shape.Link != "" {
|
if shape.Link != "" {
|
||||||
viewboxX, err := strconv.ParseFloat(viewboxSlice[0], 64)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
viewboxY, err := strconv.ParseFloat(viewboxSlice[1], 64)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
linkX := imageX + float64(shape.Pos.X) - viewboxX - float64(shape.StrokeWidth)
|
linkX := imageX + float64(shape.Pos.X) - viewboxX - float64(shape.StrokeWidth)
|
||||||
linkY := imageY + float64(shape.Pos.Y) - viewboxY - float64(shape.StrokeWidth)
|
linkY := imageY + float64(shape.Pos.Y) - viewboxY - float64(shape.StrokeWidth)
|
||||||
linkWidth := float64(shape.Width) + float64(shape.StrokeWidth*2)
|
linkWidth := float64(shape.Width) + float64(shape.StrokeWidth*2)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue