Skip to content

Commit

Permalink
pass viewbox coords in
Browse files Browse the repository at this point in the history
  • Loading branch information
Bernard Xie committed Feb 28, 2023
1 parent 51d0000 commit 5e2ce12
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
11 changes: 10 additions & 1 deletion d2cli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"os"
"os/exec"
"path/filepath"
"strconv"
"strings"
"time"

Expand Down Expand Up @@ -489,7 +490,15 @@ func renderPDF(ctx context.Context, ms *xmain.State, plugin d2plugin.Plugin, ske
}

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 {
return svg, err
}
Expand Down
11 changes: 1 addition & 10 deletions lib/pdf/pdf.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package pdf
import (
"bytes"
"math"
"strconv"
"strings"

"github.com/jung-kurt/gofpdf"
Expand Down Expand Up @@ -59,7 +58,7 @@ func (g *GoFPDF) GetFillRGB(themeID int64, fill string) (color.RGB, error) {
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
opt.ImageType = "png"
imageInfo := g.pdf.RegisterImageOptionsReader(strings.Join(boardPath, "/"), opt, bytes.NewReader(png))
Expand Down Expand Up @@ -126,14 +125,6 @@ func (g *GoFPDF) AddPDFPage(png []byte, boardPath []string, themeID int64, fill
// Draw external links
for _, shape := range shapes {
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)
linkY := imageY + float64(shape.Pos.Y) - viewboxY - float64(shape.StrokeWidth)
linkWidth := float64(shape.Width) + float64(shape.StrokeWidth*2)
Expand Down

0 comments on commit 5e2ce12

Please sign in to comment.