Skip to content

Commit

Permalink
fix auto page break positioning
Browse files Browse the repository at this point in the history
  • Loading branch information
F-Amaral committed Sep 13, 2023
1 parent 5f00f8c commit d0fc5c1
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 33 deletions.
11 changes: 6 additions & 5 deletions pkg/v2/code/barcode/barcode.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,12 @@ func (b *barcode) Render(fpdf fpdf.Fpdf, ctx context.Context) {
math := internal.NewMath(fpdf)

code := internal.NewCode(fpdf, math)
fmt.Println(fpdf.GetX()-ctx.Margins.Left, fpdf.GetY()-ctx.Margins.Top)
err := code.AddBar(b.code, internal.Cell{fpdf.GetX() - ctx.Margins.Left,
fpdf.GetY() - ctx.Margins.Top,
ctx.Dimensions.Width,
ctx.Dimensions.Height}, b.prop)
x := fpdf.GetX() - ctx.Margins.Left - ctx.Dimensions.Width
y := fpdf.GetY() - ctx.Margins.Top
fmt.Println(x, y)
err := code.AddBar(b.code,
internal.Cell{x, y, ctx.Dimensions.Width, ctx.Dimensions.Height},
b.prop)

if err != nil {
fpdf.ClearError()
Expand Down
9 changes: 5 additions & 4 deletions pkg/v2/code/matrixcode/matrixcode.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,11 @@ func (m *matrixCode) Render(fpdf fpdf.Fpdf, ctx context.Context) {
math := internal.NewMath(fpdf)

code := internal.NewCode(fpdf, math)
code.AddDataMatrix(m.code, internal.Cell{fpdf.GetX() - ctx.Margins.Left,
fpdf.GetY() - ctx.Margins.Top,
ctx.Dimensions.Width,
ctx.Dimensions.Height}, m.prop)
x := fpdf.GetX() - ctx.Margins.Left - ctx.Dimensions.Width
y := fpdf.GetY() - ctx.Margins.Top
code.AddDataMatrix(m.code,
internal.Cell{x, y, ctx.Dimensions.Width, ctx.Dimensions.Height},
m.prop)
}

func (m *matrixCode) GetType() string {
Expand Down
9 changes: 5 additions & 4 deletions pkg/v2/code/qrcode/qrcode.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,11 @@ func (q *qrCode) Render(fpdf fpdf.Fpdf, ctx context.Context) {
math := internal.NewMath(fpdf)

code := internal.NewCode(fpdf, math)
code.AddQr(q.code, internal.Cell{fpdf.GetX() - ctx.Margins.Left,
fpdf.GetY() - ctx.Margins.Top,
ctx.Dimensions.Width,
ctx.Dimensions.Height}, q.prop)
x := fpdf.GetX() - ctx.Margins.Left - ctx.Dimensions.Width
y := fpdf.GetY() - ctx.Margins.Top
code.AddQr(q.code,
internal.Cell{x, y, ctx.Dimensions.Width, ctx.Dimensions.Height},
q.prop)
}

func (q *qrCode) GetType() string {
Expand Down
7 changes: 3 additions & 4 deletions pkg/v2/image/base64image.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,11 @@ func NewFromBase64(path string, extension consts.Extension, imageProps ...props.
func (b *base64Image) Render(fpdf fpdf.Fpdf, ctx context.Context) {
math := internal.NewMath(fpdf)
img := internal.NewImage(fpdf, math)
x := fpdf.GetX() - ctx.Margins.Left - ctx.Dimensions.Width
y := fpdf.GetY() - ctx.Margins.Top
err := img.AddFromBase64(
b.base64,
internal.Cell{fpdf.GetX() - ctx.Margins.Left,
fpdf.GetY() - ctx.Margins.Top,
ctx.Dimensions.Width,
ctx.Dimensions.Height},
internal.Cell{x, y, ctx.Dimensions.Width, ctx.Dimensions.Height},
b.prop,
b.extension,
)
Expand Down
7 changes: 3 additions & 4 deletions pkg/v2/image/fileimage.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,11 @@ func NewFromFile(path string, imageProps ...props.Rect) domain.Component {
func (f *fileImage) Render(fpdf fpdf.Fpdf, ctx context.Context) {
math := internal.NewMath(fpdf)
img := internal.NewImage(fpdf, math)
x := fpdf.GetX() - ctx.Margins.Left - ctx.Dimensions.Width
y := fpdf.GetY() - ctx.Margins.Top
err := img.AddFromFile(
f.path,
internal.Cell{fpdf.GetX() - ctx.Margins.Left,
fpdf.GetY() - ctx.Margins.Top,
ctx.Dimensions.Width,
ctx.Dimensions.Height},
internal.Cell{x, y, ctx.Dimensions.Width, ctx.Dimensions.Height},
f.prop)
if err != nil {
fpdf.ClearError()
Expand Down
3 changes: 1 addition & 2 deletions pkg/v2/row/row.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,13 @@ func (r *row) GetStructure() *tree.Node[domain.Structure] {
func (r *row) Render(fpdf fpdf.Fpdf, ctx context.Context) {
//ctx.Print(r.height)
ctx = ctx.WithDimension(ctx.Dimensions.Width, r.height)

fpdf.SetDrawColor(r.color.Red, r.color.Green, r.color.Blue)

for _, col := range r.cols {
col.Render(fpdf, ctx)
}

r.render(fpdf, ctx)

return
}

Expand Down
8 changes: 3 additions & 5 deletions pkg/v2/signature/signature.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,11 @@ func (s *signature) Render(fpdf fpdf.Fpdf, ctx context.Context) {
math := internal.NewMath(fpdf)
text := internal.NewText(fpdf, math, font)
signature := internal.NewSignature(fpdf, math, text)

x := fpdf.GetX() - ctx.Margins.Left - ctx.Dimensions.Width
y := fpdf.GetY() - ctx.Margins.Top
signature.AddSpaceFor(
s.value,
internal.Cell{fpdf.GetX() - ctx.Margins.Left,
fpdf.GetY() - ctx.Margins.Top,
ctx.Dimensions.Width,
ctx.Dimensions.Height},
internal.Cell{x, y, ctx.Dimensions.Width, ctx.Dimensions.Height},
s.prop)
}

Expand Down
8 changes: 3 additions & 5 deletions pkg/v2/text/text.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,10 @@ func (t *text) render(fpdf fpdf.Fpdf, ctx context.Context) {
font := internal.NewFont(fpdf, 2, consts.Arial, consts.Normal)
math := internal.NewMath(fpdf)
text := internal.NewText(fpdf, math, font)

x := fpdf.GetX() - ctx.Margins.Left - ctx.Dimensions.Width
y := fpdf.GetY() - ctx.Margins.Top
text.Add(
t.value,
internal.Cell{fpdf.GetX() - ctx.Margins.Left,
fpdf.GetY() - ctx.Margins.Top,
ctx.Dimensions.Width,
ctx.Dimensions.Height},
internal.Cell{x, y, ctx.Dimensions.Width, ctx.Dimensions.Height},
t.prop)
}
Binary file modified v2.pdf
Binary file not shown.

0 comments on commit d0fc5c1

Please sign in to comment.