diff --git a/README.md b/README.md index 9af95ec8..e15d3cee 100644 --- a/README.md +++ b/README.md @@ -28,7 +28,7 @@ always when a new page appear, in this case, a header may have many rows, lines * With `go get`: ```bash -go get github.com/johnfercher/maroto/v2/pkg@v2.0.0-alpha.23 +go get github.com/johnfercher/maroto/v2/pkg@v2.0.0-alpha.24 ``` diff --git a/cmd/benchmark/main.go b/cmd/benchmark/main.go index 4b9a2cc0..1b9225bc 100644 --- a/cmd/benchmark/main.go +++ b/cmd/benchmark/main.go @@ -3,13 +3,14 @@ package main import ( "encoding/base64" "fmt" + "log" + "os" + "github.com/johnfercher/maroto/v2/pkg" "github.com/johnfercher/maroto/v2/pkg/components/list" "github.com/johnfercher/maroto/v2/pkg/config" "github.com/johnfercher/maroto/v2/pkg/consts/fontstyle" "github.com/johnfercher/maroto/v2/pkg/metrics" - "log" - "os" "github.com/johnfercher/maroto/v2/pkg/components/code" "github.com/johnfercher/maroto/v2/pkg/components/col" @@ -35,7 +36,7 @@ var background = &props.Color{ func main() { var content string - for i := 0; i < 20; i++ { + for i := 0; i < 100; i++ { fmt.Println(i) content += fmt.Sprintf("%f", run().Value) + "\n" } diff --git a/cmd/seriesanalyzer/main.go b/cmd/seriesanalyzer/main.go index 0bbc50bf..f00e9dd3 100644 --- a/cmd/seriesanalyzer/main.go +++ b/cmd/seriesanalyzer/main.go @@ -35,7 +35,6 @@ func main() { values = MergeFloat64(values) fmt.Printf("min: %f, max: %f, avg: %f", values[0], values[len(values)-1], sum/float64(len(values))) - } func MergeFloat64(arr []float64) []float64 { diff --git a/docs/README.md b/docs/README.md index 117ef217..496a00fb 100644 --- a/docs/README.md +++ b/docs/README.md @@ -2,12 +2,12 @@ [![Mentioned in Awesome Go](https://awesome.re/mentioned-badge.svg)](https://github.com/avelino/awesome-go#template-engines) [![Branch](https://img.shields.io/badge/V2-Branch-pink)](https://github.com/johnfercher/maroto/tree/v2) [![Roadmap](https://img.shields.io/badge/V2-Roadmap-purple)](https://github.com/users/johnfercher/projects/1) [![Discussion](https://img.shields.io/badge/V2-Discussion-blue)](https://github.com/johnfercher/maroto/issues/257) [![Release Notes](https://img.shields.io/badge/Release-Notes-cyan)](https://github.com/johnfercher/maroto/releases) [![Visits Badge](https://badges.pufler.dev/visits/johnfercher/maroto)](https://badges.pufler.dev) -#### Maroto`v2.0.0-alpha.23`is here! Try out: +#### Maroto`v2.0.0-alpha.24`is here! Try out: * Installation with`go get`: ```bash -go get github.com/johnfercher/maroto/v2/pkg@v2.0.0-alpha.23 +go get github.com/johnfercher/maroto/v2/pkg@v2.0.0-alpha.24 ``` The public API was completely redesigned with the aim of enhancing the diff --git a/docs/assets/examples/list/v2/main.go b/docs/assets/examples/list/v2/main.go index 4b9a2cc0..8efb75a6 100644 --- a/docs/assets/examples/list/v2/main.go +++ b/docs/assets/examples/list/v2/main.go @@ -3,13 +3,14 @@ package main import ( "encoding/base64" "fmt" + "log" + "os" + "github.com/johnfercher/maroto/v2/pkg" "github.com/johnfercher/maroto/v2/pkg/components/list" "github.com/johnfercher/maroto/v2/pkg/config" "github.com/johnfercher/maroto/v2/pkg/consts/fontstyle" "github.com/johnfercher/maroto/v2/pkg/metrics" - "log" - "os" "github.com/johnfercher/maroto/v2/pkg/components/code" "github.com/johnfercher/maroto/v2/pkg/components/col" diff --git a/docs/assets/pdf/v2.pdf b/docs/assets/pdf/v2.pdf index 4824e170..1d29789d 100644 Binary files a/docs/assets/pdf/v2.pdf and b/docs/assets/pdf/v2.pdf differ diff --git a/docs/assets/text/benchmark.txt b/docs/assets/text/benchmark.txt index c83c3a17..dfe6b207 100755 --- a/docs/assets/text/benchmark.txt +++ b/docs/assets/text/benchmark.txt @@ -1,20 +1,100 @@ -5713.058155 -5604.562240 -6185.930860 -5831.065336 -5913.167839 -6053.554586 -6034.108635 -5584.093034 -5581.348188 -5893.622080 -5911.445907 -5950.391652 -6102.767394 -5885.246285 -5898.916533 -6214.413742 -5619.153454 -5933.690091 -5934.488651 -5956.515246 +5317.953807 +5315.037820 +5164.163855 +5198.180831 +5237.379406 +5322.056371 +5338.671536 +4837.652953 +4720.954979 +5119.040083 +5298.798362 +5120.403483 +5227.477424 +5162.407316 +5447.440712 +5467.580919 +5313.827204 +5335.735310 +5205.362338 +5374.806570 +5173.248838 +5369.851606 +5331.566468 +5124.031579 +5106.242516 +5218.097750 +5295.609238 +5285.710100 +5253.334516 +5247.828504 +5310.875216 +5255.361052 +5148.246356 +5454.810704 +5347.372197 +5288.712899 +5238.118029 +5236.236376 +5369.347216 +5588.524662 +5389.948522 +5275.753759 +4939.716533 +5206.020321 +5160.954472 +5558.478398 +5316.437244 +5320.318437 +5359.820991 +5295.662023 +5211.191388 +5445.538520 +5403.318623 +5421.800879 +5639.864653 +5325.896143 +5390.202025 +5348.761704 +5078.703688 +5599.018133 +5062.741334 +5424.028018 +5559.508133 +5448.089469 +5201.023734 +5565.419011 +5226.516382 +5235.296242 +5264.377833 +5279.394461 +5490.793322 +5277.064203 +5496.977589 +5363.291172 +5444.443503 +5204.142776 +5427.393976 +5077.196057 +5508.293089 +5312.960908 +5560.476656 +5101.234052 +5150.452483 +5429.566926 +5391.574596 +5246.817435 +5511.685803 +5327.040004 +5144.837634 +5395.723487 +5452.607187 +5413.555648 +5233.978467 +5204.215993 +5277.073030 +5292.669027 +5375.699958 +5297.210985 +5015.364772 +5299.180017 diff --git a/docs/assets/text/v2.txt b/docs/assets/text/v2.txt index a8da870c..e217f4a6 100644 --- a/docs/assets/text/v2.txt +++ b/docs/assets/text/v2.txt @@ -1,4 +1,5 @@ -generate -> avg: 21.90ms, executions: [21.90ms] -header -> avg: 394.00ns, executions: [394.00ns] -footer -> avg: 61.00ns, executions: [61.00ns] -add_row -> avg: 136.89ns, executions: [0.16μs, 0.15μs, 0.06μs, 0.10μs, 0.03μs, 0.03μs, 3.85μs, 0.08μs, 0.03μs, 0.74μs, 0.03μs, 0.02μs, 0.02μs, 0.06μs, 0.02μs, 0.02μs, 0.03μs, 0.36μs, 0.05μs, 0.01μs, 0.05μs, 0.02μs, 0.02μs, 0.02μs, 0.07μs, 0.02μs, 0.02μs, 0.01μs, 0.24μs, 0.05μs, 0.02μs, 0.07μs, 0.02μs, 0.02μs, 0.02μs, 0.06μs, 0.02μs, 0.02μs, 0.02μs, 0.20μs, 0.05μs, 0.01μs, 0.05μs, 0.02μs, 0.02μs, 0.02μs, 0.06μs, 0.02μs, 0.02μs, 0.02μs, 0.23μs, 0.07μs, 0.02μs, 0.12μs, 0.02μs] +generate -> avg: 18.58ms, executions: [18.58ms] +header -> avg: 522.00ns, executions: [522.00ns] +footer -> avg: 64.00ns, executions: [64.00ns] +add_row -> avg: 64.78ns, executions: [121.00ns, 146.00ns, 52.00ns, 107.00ns, 22.00ns, 18.00ns, 683.00ns, 73.00ns, 23.00ns, 66.00ns, 24.00ns, 16.00ns, 15.00ns, 54.00ns, 17.00ns, 16.00ns, 17.00ns, 345.00ns, 50.00ns, 16.00ns, 57.00ns, 15.00ns, 16.00ns, 22.00ns, 64.00ns, 16.00ns, 17.00ns, 17.00ns, 283.00ns, 49.00ns, 15.00ns, 58.00ns, 17.00ns, 19.00ns, 17.00ns, 60.00ns, 16.00ns, 19.00ns, 17.00ns, 209.00ns, 52.00ns, 17.00ns, 54.00ns, 18.00ns, 15.00ns, 15.00ns, 54.00ns, 16.00ns, 30.00ns, 18.00ns, 246.00ns, 52.00ns, 16.00ns, 60.00ns, 16.00ns] +file_size -> 260.96Kb diff --git a/internal/code.go b/internal/code.go index c54fcab0..5f02281a 100644 --- a/internal/code.go +++ b/internal/code.go @@ -4,6 +4,8 @@ import ( "github.com/boombuler/barcode/code128" "github.com/boombuler/barcode/qr" "github.com/johnfercher/maroto/v2/internal/fpdf" + "github.com/johnfercher/maroto/v2/internal/math" + "github.com/johnfercher/maroto/v2/pkg/config" "github.com/johnfercher/maroto/v2/pkg/core" "github.com/johnfercher/maroto/v2/pkg/props" "github.com/jung-kurt/gofpdf/contrib/barcode" @@ -11,18 +13,18 @@ import ( // Code is the abstraction which deals of how to add QrCodes or Barcode in a PDF. type Code interface { - AddQr(code string, cell core.Cell, prop props.Rect) - AddBar(code string, cell core.Cell, prop props.Barcode) (err error) - AddDataMatrix(code string, cell core.Cell, prop props.Rect) + AddQr(code string, cell *core.Cell, margins *config.Margins, prop *props.Rect) + AddBar(code string, cell *core.Cell, margins *config.Margins, prop *props.Barcode) (err error) + AddDataMatrix(code string, cell *core.Cell, margins *config.Margins, prop *props.Rect) } type code struct { pdf fpdf.Fpdf - math Math + math math.Math } // NewCode create a Code. -func NewCode(pdf fpdf.Fpdf, math Math) *code { +func NewCode(pdf fpdf.Fpdf, math math.Math) *code { return &code{ pdf, math, @@ -30,50 +32,53 @@ func NewCode(pdf fpdf.Fpdf, math Math) *code { } // AddDataMatrix creates a DataMatrix code inside a cell. -func (s *code) AddDataMatrix(code string, cell core.Cell, prop props.Rect) { +func (s *code) AddDataMatrix(code string, cell *core.Cell, margins *config.Margins, prop *props.Rect) { key := barcode.RegisterDataMatrix(s.pdf, code) + dimensions := &config.Dimensions{Width: cell.Width, Height: cell.Width} - var x, y, w, h float64 + var rectCell *core.Cell if prop.Center { - x, y, w, h = s.math.GetRectCenterColProperties(cell.Width, cell.Width, cell.Width, cell.Height, cell.X, prop.Percent) + rectCell = s.math.GetRectCenterColProperties(dimensions, cell, margins, prop.Percent) } else { - x, y, w, h = s.math.GetRectNonCenterColProperties(cell.Width, cell.Width, cell.Width, cell.Height, cell.X, prop) + rectCell = s.math.GetRectNonCenterColProperties(dimensions, cell, margins, prop) } - barcode.Barcode(s.pdf, key, x, y+cell.Y, w, h, false) + + barcode.Barcode(s.pdf, key, rectCell.X, rectCell.Y+cell.Y, rectCell.Width, rectCell.Height, false) } // AddQr create a QrCode inside a cell. -func (s *code) AddQr(code string, cell core.Cell, prop props.Rect) { +func (s *code) AddQr(code string, cell *core.Cell, margins *config.Margins, prop *props.Rect) { key := barcode.RegisterQR(s.pdf, code, qr.H, qr.Unicode) + dimensions := &config.Dimensions{Width: cell.Width, Height: cell.Width} - var x, y, w, h float64 + var rectCell *core.Cell if prop.Center { - x, y, w, h = s.math.GetRectCenterColProperties(cell.Width, cell.Width, cell.Width, cell.Height, cell.X, prop.Percent) + rectCell = s.math.GetRectCenterColProperties(dimensions, cell, margins, prop.Percent) } else { - x, y, w, h = s.math.GetRectNonCenterColProperties(cell.Width, cell.Width, cell.Width, cell.Height, cell.X, prop) + rectCell = s.math.GetRectNonCenterColProperties(dimensions, cell, margins, prop) } - barcode.Barcode(s.pdf, key, x, y+cell.Y, w, h, false) + barcode.Barcode(s.pdf, key, rectCell.X, rectCell.Y+cell.Y, rectCell.Width, rectCell.Height, false) } // AddBar create a Barcode inside a cell. -func (s *code) AddBar(code string, cell core.Cell, prop props.Barcode) (err error) { +func (s *code) AddBar(code string, cell *core.Cell, margins *config.Margins, prop *props.Barcode) (err error) { bcode, err := code128.Encode(code) if err != nil { return } heightPercentFromWidth := prop.Proportion.Height / prop.Proportion.Width - var x, y, w, h float64 + dimensions := &config.Dimensions{Width: cell.Width, Height: cell.Width * heightPercentFromWidth} + + var rectCell *core.Cell if prop.Center { - x, y, w, h = s.math.GetRectCenterColProperties(cell.Width, cell.Width*heightPercentFromWidth, cell.Width, - cell.Height, cell.X, prop.Percent) + rectCell = s.math.GetRectCenterColProperties(dimensions, cell, margins, prop.Percent) } else { - rectProps := props.Rect{Left: prop.Left, Top: prop.Top, Center: prop.Center, Percent: prop.Percent} - x, y, w, h = s.math.GetRectNonCenterColProperties(cell.Width, cell.Width*heightPercentFromWidth, cell.Width, - cell.Height, cell.X, rectProps) + rectProps := &props.Rect{Left: prop.Left, Top: prop.Top, Center: prop.Center, Percent: prop.Percent} + rectCell = s.math.GetRectNonCenterColProperties(dimensions, cell, margins, rectProps) } - barcode.Barcode(s.pdf, barcode.Register(bcode), x, y+cell.Y, w, h, false) + barcode.Barcode(s.pdf, barcode.Register(bcode), rectCell.X, rectCell.Y+cell.Y, rectCell.Width, rectCell.Height, false) return } diff --git a/internal/image.go b/internal/image.go index 44f97784..51598cf0 100644 --- a/internal/image.go +++ b/internal/image.go @@ -5,6 +5,9 @@ import ( "encoding/base64" "errors" + "github.com/johnfercher/maroto/v2/internal/math" + "github.com/johnfercher/maroto/v2/pkg/config" + "github.com/johnfercher/maroto/v2/pkg/core" "github.com/google/uuid" @@ -16,17 +19,17 @@ import ( // Image is the abstraction which deals of how to add images in a PDF. type Image interface { - AddFromFile(path string, cell core.Cell, prop props.Rect) (err error) - AddFromBase64(stringBase64 string, cell core.Cell, prop props.Rect, extension extension.Type) (err error) + AddFromFile(path string, cell *core.Cell, margins *config.Margins, prop *props.Rect) (err error) + AddFromBase64(stringBase64 string, cell *core.Cell, margins *config.Margins, prop *props.Rect, extension extension.Type) (err error) } type image struct { pdf fpdf.Fpdf - math Math + math math.Math } // NewImage create an Image. -func NewImage(pdf fpdf.Fpdf, math Math) *image { +func NewImage(pdf fpdf.Fpdf, math math.Math) *image { return &image{ pdf, math, @@ -34,7 +37,7 @@ func NewImage(pdf fpdf.Fpdf, math Math) *image { } // AddFromFile open an image from disk and add to PDF. -func (s *image) AddFromFile(path string, cell core.Cell, prop props.Rect) error { +func (s *image) AddFromFile(path string, cell *core.Cell, margins *config.Margins, prop *props.Rect) error { info := s.pdf.RegisterImageOptions(path, gofpdf.ImageOptions{ ReadDpi: false, ImageType: "", @@ -44,12 +47,14 @@ func (s *image) AddFromFile(path string, cell core.Cell, prop props.Rect) error return errors.New("could not register image options, maybe path/name is wrong") } - s.addImageToPdf(path, info, cell, prop) + s.addImageToPdf(path, info, cell, margins, prop) return nil } // AddFromBase64 use a base64 string to add to PDF. -func (s *image) AddFromBase64(stringBase64 string, cell core.Cell, prop props.Rect, extension extension.Type) error { +func (s *image) AddFromBase64(stringBase64 string, cell *core.Cell, margins *config.Margins, + prop *props.Rect, extension extension.Type, +) error { imageID, _ := uuid.NewRandom() ss, _ := base64.StdEncoding.DecodeString(stringBase64) @@ -67,16 +72,18 @@ func (s *image) AddFromBase64(stringBase64 string, cell core.Cell, prop props.Re return errors.New("could not register image options, maybe path/name is wrong") } - s.addImageToPdf(imageID.String(), info, cell, prop) + s.addImageToPdf(imageID.String(), info, cell, margins, prop) return nil } -func (s *image) addImageToPdf(imageLabel string, info *gofpdf.ImageInfoType, cell core.Cell, prop props.Rect) { - var x, y, w, h float64 +func (s *image) addImageToPdf(imageLabel string, info *gofpdf.ImageInfoType, cell *core.Cell, margins *config.Margins, prop *props.Rect) { + rectCell := &core.Cell{} + dimensions := &config.Dimensions{Width: info.Width(), Height: info.Height()} + if prop.Center { - x, y, w, h = s.math.GetRectCenterColProperties(info.Width(), info.Height(), cell.Width, cell.Height, cell.X, prop.Percent) + rectCell = s.math.GetRectCenterColProperties(dimensions, cell, margins, prop.Percent) } else { - x, y, w, h = s.math.GetRectNonCenterColProperties(info.Width(), info.Height(), cell.Width, cell.Height, cell.X, prop) + rectCell = s.math.GetRectNonCenterColProperties(dimensions, cell, margins, prop) } - s.pdf.Image(imageLabel, x, y+cell.Y+prop.Top, w, h, false, "", 0, "") + s.pdf.Image(imageLabel, rectCell.X, rectCell.Y+cell.Y+prop.Top, rectCell.Width, rectCell.Height, false, "", 0, "") } diff --git a/internal/line.go b/internal/line.go index e199984e..4cabca6e 100644 --- a/internal/line.go +++ b/internal/line.go @@ -9,7 +9,7 @@ import ( ) type Line interface { - Add(cell core.Cell, prop props.Line) + Add(cell *core.Cell, prop *props.Line) } type line struct { @@ -26,7 +26,7 @@ func NewLine(pdf fpdf.Fpdf) *line { } } -func (l *line) Add(cell core.Cell, prop props.Line) { +func (l *line) Add(cell *core.Cell, prop *props.Line) { if prop.Orientation == orientation.Vertical { l.renderVertical(cell, prop) } else { @@ -34,7 +34,7 @@ func (l *line) Add(cell core.Cell, prop props.Line) { } } -func (l *line) renderVertical(cell core.Cell, prop props.Line) { +func (l *line) renderVertical(cell *core.Cell, prop *props.Line) { size := cell.Height * (prop.SizePercent / 100.0) position := cell.Width * (prop.OffsetPercent / 100.0) @@ -59,7 +59,7 @@ func (l *line) renderVertical(cell core.Cell, prop props.Line) { } } -func (l *line) renderHorizontal(cell core.Cell, prop props.Line) { +func (l *line) renderHorizontal(cell *core.Cell, prop *props.Line) { size := cell.Width * (prop.SizePercent / 100.0) position := cell.Height * (prop.OffsetPercent / 100.0) diff --git a/internal/math.go b/internal/math.go deleted file mode 100644 index c57f893b..00000000 --- a/internal/math.go +++ /dev/null @@ -1,106 +0,0 @@ -package internal - -import ( - "github.com/johnfercher/maroto/v2/internal/fpdf" - "github.com/johnfercher/maroto/v2/pkg/props" -) - -const ( - maxPercent = 100.0 -) - -// Math is the abstraction which deals with useful calc. -type Math interface { - GetRectCenterColProperties(imageWidth float64, imageHeight float64, colWidth float64, colHeight float64, - xColOffset float64, percent float64) (x float64, y float64, w float64, h float64) - GetRectNonCenterColProperties(imageWidth float64, imageHeight float64, colWidth float64, colHeight float64, - xColOffset float64, prop props.Rect) (x float64, y float64, w float64, h float64) - GetCenterCorrection(outerSize, innerSize float64) float64 -} - -type math struct { - pdf fpdf.Fpdf -} - -// NewMath create a Math. -func NewMath(pdf fpdf.Fpdf) *math { - return &math{ - pdf, - } -} - -// GetRectCenterColProperties define Width, Height, X Offset and Y Offset -// to and rectangle (QrCode, Barcode, Image) be centralized inside a cell. -func (s *math) GetRectCenterColProperties(imageWidth float64, imageHeight float64, colWidth float64, colHeight float64, - xColOffset float64, percent float64, -) (x float64, y float64, w float64, h float64) { - percent /= 100.0 - left, top, _, _ := s.pdf.GetMargins() - - imageProportion := imageHeight / imageWidth - celProportion := colHeight / colWidth - - if imageProportion > celProportion { - newImageWidth := colHeight / imageProportion * percent - newImageHeight := newImageWidth * imageProportion - - widthCorrection := s.GetCenterCorrection(colWidth, newImageWidth) - heightCorrection := s.GetCenterCorrection(colHeight, newImageHeight) - - x = xColOffset + left + widthCorrection - y = top + heightCorrection - w = newImageWidth - h = newImageHeight - } else { - newImageWidth := colWidth * percent - newImageHeight := newImageWidth * imageProportion - - widthCorrection := s.GetCenterCorrection(colWidth, newImageWidth) - heightCorrection := s.GetCenterCorrection(colHeight, newImageHeight) - - x = xColOffset + left + widthCorrection - y = top + heightCorrection - w = newImageWidth - h = newImageHeight - } - - return x, y, w, h -} - -// GetRectNonCenterColProperties define Width, Height to and rectangle (QrCode, Barcode, Image) inside a cell. -func (s *math) GetRectNonCenterColProperties(imageWidth float64, imageHeight float64, colWidth float64, colHeight float64, - xColOffset float64, prop props.Rect, -) (x float64, y float64, w float64, h float64) { - percent := prop.Percent / maxPercent - left, top, _, _ := s.pdf.GetMargins() - - imageProportion := imageHeight / imageWidth - celProportion := colHeight / colWidth - - if imageProportion > celProportion { - newImageWidth := colHeight / imageProportion * percent - newImageHeight := newImageWidth * imageProportion - - x = xColOffset + left + prop.Left - y = top - w = newImageWidth - h = newImageHeight - } else { - newImageWidth := colWidth * percent - newImageHeight := newImageWidth * imageProportion - - x = xColOffset + left + prop.Left - y = top - w = newImageWidth - h = newImageHeight - } - - return -} - -// GetCenterCorrection return the correction of space in X or Y to -// centralize a line in relation with another line. -func (s *math) GetCenterCorrection(outerSize, innerSize float64) float64 { - const divisorToGetHalf = 2.0 - return (outerSize - innerSize) / divisorToGetHalf -} diff --git a/internal/math/math.go b/internal/math/math.go new file mode 100644 index 00000000..23fb539a --- /dev/null +++ b/internal/math/math.go @@ -0,0 +1,101 @@ +package math + +import ( + "github.com/johnfercher/maroto/v2/pkg/config" + "github.com/johnfercher/maroto/v2/pkg/core" + "github.com/johnfercher/maroto/v2/pkg/props" +) + +const ( + maxPercent = 100.0 +) + +// Math is the abstraction which deals with useful calc. +type Math interface { + GetRectCenterColProperties(rectDimensions *config.Dimensions, cell *core.Cell, margins *config.Margins, percent float64) *core.Cell + GetRectNonCenterColProperties(rectDimensions *config.Dimensions, cell *core.Cell, margins *config.Margins, prop *props.Rect) *core.Cell + GetCenterCorrection(outerSize, innerSize float64) float64 +} + +type math struct{} + +// New create a Math. +func New() *math { + return &math{} +} + +func (s *math) GetRectCenterColProperties(rectDimensions *config.Dimensions, cell *core.Cell, + margins *config.Margins, percent float64, +) *core.Cell { + percent /= 100.0 + left, top := margins.Left, margins.Top + + imageProportion := rectDimensions.Height / rectDimensions.Width + celProportion := cell.Height / cell.Width + + rectCell := &core.Cell{} + if imageProportion > celProportion { + newImageWidth := cell.Height / imageProportion * percent + newImageHeight := newImageWidth * imageProportion + + widthCorrection := s.GetCenterCorrection(cell.Width, newImageWidth) + heightCorrection := s.GetCenterCorrection(cell.Height, newImageHeight) + + rectCell.X = cell.X + left + widthCorrection + rectCell.Y = top + heightCorrection + rectCell.Width = newImageWidth + rectCell.Height = newImageHeight + } else { + newImageWidth := cell.Width * percent + newImageHeight := newImageWidth * imageProportion + + widthCorrection := s.GetCenterCorrection(cell.Width, newImageWidth) + heightCorrection := s.GetCenterCorrection(cell.Height, newImageHeight) + + rectCell.X = cell.X + left + widthCorrection + rectCell.Y = top + heightCorrection + rectCell.Width = newImageWidth + rectCell.Height = newImageHeight + } + + return rectCell +} + +// GetRectNonCenterColProperties define Width, Height to and rectangle (QrCode, Barcode, Image) inside a cell. +func (s *math) GetRectNonCenterColProperties(rectDimensions *config.Dimensions, cell *core.Cell, + margins *config.Margins, prop *props.Rect, +) *core.Cell { + percent := prop.Percent / maxPercent + left, top := margins.Left, margins.Top + + imageProportion := rectDimensions.Height / rectDimensions.Width + celProportion := cell.Height / cell.Width + + rectCell := &core.Cell{} + if imageProportion > celProportion { + newImageWidth := cell.Height / imageProportion * percent + newImageHeight := newImageWidth * imageProportion + + rectCell.X = cell.X + left + prop.Left + rectCell.Y = top + rectCell.Width = newImageWidth + rectCell.Height = newImageHeight + } else { + newImageWidth := cell.Width * percent + newImageHeight := newImageWidth * imageProportion + + rectCell.X = cell.X + left + prop.Left + rectCell.Y = top + rectCell.Width = newImageWidth + rectCell.Height = newImageHeight + } + + return rectCell +} + +// GetCenterCorrection return the correction of space in X or Y to +// centralize a line in relation with another line. +func (s *math) GetCenterCorrection(outerSize, innerSize float64) float64 { + const divisorToGetHalf = 2.0 + return (outerSize - innerSize) / divisorToGetHalf +} diff --git a/internal/math_test.go b/internal/math/math_test.go similarity index 93% rename from internal/math_test.go rename to internal/math/math_test.go index 708ba191..94105365 100644 --- a/internal/math_test.go +++ b/internal/math/math_test.go @@ -1,13 +1,21 @@ -package internal_test +package math_test -/*func TestNewMath(t *testing.T) { - math := internal.NewMath(&mocks.Fpdf{}) +import ( + "fmt" + "testing" - assert.NotNil(t, math) - assert.Equal(t, fmt.Sprintf("%T", math), "*internal.math") + "github.com/johnfercher/maroto/v2/internal/math" + "github.com/stretchr/testify/assert" +) + +func TestNewMath(t *testing.T) { + sut := math.New() + + assert.NotNil(t, sut) + assert.Equal(t, "*math.math", fmt.Sprintf("%T", sut)) } -func TestMath_GetRectCenterColProperties(t *testing.T) { +/*func TestMath_GetRectCenterColProperties(t *testing.T) { cases := []struct { name string width float64 @@ -103,7 +111,7 @@ func TestMath_GetRectCenterColProperties(t *testing.T) { // Arrange pdf := c.pdf() - math := internal.NewMath(pdf) + math := internal.New(pdf) // Act x, y, w, h := math.GetRectCenterColProperties(c.width, c.height, 20, 25.0, 2, c.percent) @@ -230,7 +238,7 @@ func TestMath_GetRectNonCenterColProperties(t *testing.T) { // Arrange pdf := c.pdf() - math := internal.NewMath(pdf) + math := internal.New(pdf) // Act x, y, w, h := math.GetRectNonCenterColProperties(c.width, c.height, 20.0, 25.0, 2, c.prop) @@ -244,7 +252,7 @@ func TestMath_GetRectNonCenterColProperties(t *testing.T) { func TestMath_GetCenterCorrection(t *testing.T) { // Arrange pdf := &mocks.Fpdf{} - math := internal.NewMath(pdf) + math := internal.New(pdf) // Act correction := math.GetCenterCorrection(10, 5) diff --git a/internal/signature.go b/internal/signature.go index aa37c760..f66c5eca 100644 --- a/internal/signature.go +++ b/internal/signature.go @@ -2,23 +2,24 @@ package internal import ( "github.com/johnfercher/maroto/v2/internal/fpdf" + "github.com/johnfercher/maroto/v2/internal/math" "github.com/johnfercher/maroto/v2/pkg/core" "github.com/johnfercher/maroto/v2/pkg/props" ) // Signature is the abstraction which deals of how to add a signature space inside PDF. type Signature interface { - AddSpaceFor(label string, cell core.Cell, textProp props.Text) + AddSpaceFor(label string, cell *core.Cell, textProp *props.Text) } type signature struct { pdf fpdf.Fpdf - math Math + math math.Math text Text } // NewSignature create a Signature. -func NewSignature(pdf fpdf.Fpdf, math Math, text Text) *signature { +func NewSignature(pdf fpdf.Fpdf, math math.Math, text Text) *signature { return &signature{ pdf, math, @@ -27,7 +28,7 @@ func NewSignature(pdf fpdf.Fpdf, math Math, text Text) *signature { } // AddSpaceFor create a space for a signature inside a cell. -func (s *signature) AddSpaceFor(label string, cell core.Cell, textProp props.Text) { +func (s *signature) AddSpaceFor(label string, cell *core.Cell, textProp *props.Text) { lineSpaceProportion := 1.33 left, top, _, _ := s.pdf.GetMargins() space := 4.0 diff --git a/internal/text.go b/internal/text.go index a99359be..24ff9997 100644 --- a/internal/text.go +++ b/internal/text.go @@ -4,6 +4,8 @@ import ( "fmt" "strings" + "github.com/johnfercher/maroto/v2/internal/math" + "github.com/johnfercher/maroto/v2/pkg/consts/breakline" "github.com/johnfercher/maroto/v2/pkg/core" @@ -17,18 +19,18 @@ import ( // Text is the abstraction which deals of how to add text inside PDF. type Text interface { - Add(text string, cell core.Cell, textProp props.Text) + Add(text string, cell *core.Cell, textProp *props.Text) GetLinesQuantity(text string, fontFamily props.Text, colWidth float64) int } type text struct { pdf fpdf.Fpdf - math Math + math math.Math font Font } // NewText create a Text. -func NewText(pdf fpdf.Fpdf, math Math, font Font) *text { +func NewText(pdf fpdf.Fpdf, math math.Math, font Font) *text { return &text{ pdf, math, @@ -37,7 +39,7 @@ func NewText(pdf fpdf.Fpdf, math Math, font Font) *text { } // Add a text inside a cell. -func (s *text) Add(text string, cell core.Cell, textProp props.Text) { +func (s *text) Add(text string, cell *core.Cell, textProp *props.Text) { s.font.SetFont(textProp.Family, textProp.Style, textProp.Size) if textProp.Top > cell.Height { @@ -169,7 +171,7 @@ func (s *text) getLinesBreakingLineWithDash(words string, colWidth float64) []st return lines } -func (s *text) addLine(textProp props.Text, xColOffset, colWidth, yColOffset, textWidth float64, text string) { +func (s *text) addLine(textProp *props.Text, xColOffset, colWidth, yColOffset, textWidth float64, text string) { left, top, _, _ := s.pdf.GetMargins() if textProp.Align == align.Left { @@ -188,7 +190,7 @@ func (s *text) addLine(textProp props.Text, xColOffset, colWidth, yColOffset, te s.pdf.Text(dx+xColOffset+left, yColOffset+top, text) } -func (s *text) textToUnicode(txt string, props props.Text) string { +func (s *text) textToUnicode(txt string, props *props.Text) string { if props.Family == fontfamily.Arial || props.Family == fontfamily.Helvetica || props.Family == fontfamily.Symbol || diff --git a/pkg/components/code/barcode.go b/pkg/components/code/barcode.go index 9764dc07..9c1a4bc8 100644 --- a/pkg/components/code/barcode.go +++ b/pkg/components/code/barcode.go @@ -39,8 +39,8 @@ func NewBarRow(height float64, code string, ps ...props.Barcode) core.Row { return row.New(height).Add(c) } -func (b *barcode) Render(provider core.Provider, cell core.Cell) { - provider.AddBarCode(b.code, cell, b.prop) +func (b *barcode) Render(provider core.Provider, cell *core.Cell) { + provider.AddBarCode(b.code, cell, &b.prop) } func (b *barcode) GetStructure() *tree.Node[core.Structure] { diff --git a/pkg/components/code/matrixcode.go b/pkg/components/code/matrixcode.go index 3420a863..6c40c522 100644 --- a/pkg/components/code/matrixcode.go +++ b/pkg/components/code/matrixcode.go @@ -40,8 +40,8 @@ func NewMatrixRow(height float64, code string, ps ...props.Rect) core.Row { return row.New(height).Add(c) } -func (m *matrixCode) Render(provider core.Provider, cell core.Cell) { - provider.AddMatrixCode(m.code, cell, m.prop) +func (m *matrixCode) Render(provider core.Provider, cell *core.Cell) { + provider.AddMatrixCode(m.code, cell, &m.prop) } func (m *matrixCode) GetStructure() *tree.Node[core.Structure] { diff --git a/pkg/components/code/qrcode.go b/pkg/components/code/qrcode.go index c25a9daa..ea126cda 100644 --- a/pkg/components/code/qrcode.go +++ b/pkg/components/code/qrcode.go @@ -40,8 +40,8 @@ func NewQrRow(height float64, code string, ps ...props.Rect) core.Row { return row.New(height).Add(c) } -func (q *qrCode) Render(provider core.Provider, cell core.Cell) { - provider.AddQrCode(q.code, cell, q.prop) +func (q *qrCode) Render(provider core.Provider, cell *core.Cell) { + provider.AddQrCode(q.code, cell, &q.prop) } func (q *qrCode) GetStructure() *tree.Node[core.Structure] { diff --git a/pkg/components/col/col.go b/pkg/components/col/col.go index c22ca784..2f0f85e2 100644 --- a/pkg/components/col/col.go +++ b/pkg/components/col/col.go @@ -60,7 +60,7 @@ func (c *col) Render(provider core.Provider, cell core.Cell, createCell bool) { } for _, component := range c.components { - component.Render(provider, cell) + component.Render(provider, &cell) } } diff --git a/pkg/components/image/base64image.go b/pkg/components/image/base64image.go index aa82e40b..071d4367 100644 --- a/pkg/components/image/base64image.go +++ b/pkg/components/image/base64image.go @@ -42,8 +42,8 @@ func NewFromBase64Row(height float64, path string, extension extension.Type, ps return row.New(height).Add(c) } -func (b *base64Image) Render(provider core.Provider, cell core.Cell) { - provider.AddImage(b.base64, cell, b.prop, b.extension) +func (b *base64Image) Render(provider core.Provider, cell *core.Cell) { + provider.AddImage(b.base64, cell, &b.prop, b.extension) } func (b *base64Image) GetStructure() *tree.Node[core.Structure] { diff --git a/pkg/components/image/fileimage.go b/pkg/components/image/fileimage.go index 09227b64..94e4d7ab 100644 --- a/pkg/components/image/fileimage.go +++ b/pkg/components/image/fileimage.go @@ -43,9 +43,9 @@ func NewFromFileRow(height float64, path string, ps ...props.Rect) core.Row { return row.New(height).Add(c) } -func (f *fileImage) Render(provider core.Provider, cell core.Cell) { +func (f *fileImage) Render(provider core.Provider, cell *core.Cell) { extensionStr := strings.Split(f.path, ".")[1] - provider.AddImage(f.path, cell, f.prop, extension.Type(extensionStr)) + provider.AddImage(f.path, cell, &f.prop, extension.Type(extensionStr)) } func (f *fileImage) GetStructure() *tree.Node[core.Structure] { diff --git a/pkg/components/line/line.go b/pkg/components/line/line.go index d6a5b721..194eda09 100644 --- a/pkg/components/line/line.go +++ b/pkg/components/line/line.go @@ -49,6 +49,6 @@ func (l *line) SetConfig(config *config.Config) { l.config = config } -func (l *line) Render(provider core.Provider, cell core.Cell) { - provider.AddLine(cell, l.prop) +func (l *line) Render(provider core.Provider, cell *core.Cell) { + provider.AddLine(cell, &l.prop) } diff --git a/pkg/components/page/page.go b/pkg/components/page/page.go index e683ce91..631b0511 100644 --- a/pkg/components/page/page.go +++ b/pkg/components/page/page.go @@ -35,7 +35,7 @@ func (p *page) Render(provider core.Provider, cell core.Cell) { } if p.prop.Pattern != "" { - provider.AddText(p.prop.GetPageString(p.number, p.total), cell, p.prop.GetNumberTextProp(cell.Height)) + provider.AddText(p.prop.GetPageString(p.number, p.total), &cell, p.prop.GetNumberTextProp(cell.Height)) } } diff --git a/pkg/components/signature/signature.go b/pkg/components/signature/signature.go index 4a1225eb..223b33bc 100644 --- a/pkg/components/signature/signature.go +++ b/pkg/components/signature/signature.go @@ -41,7 +41,7 @@ func NewRow(height float64, value string, ps ...props.Font) core.Row { return row.New(height).Add(c) } -func (s *signature) Render(provider core.Provider, cell core.Cell) { +func (s *signature) Render(provider core.Provider, cell *core.Cell) { provider.AddSignature(s.value, cell, s.prop.ToTextProp(align.Center, 0.0, 0)) } diff --git a/pkg/components/text/text.go b/pkg/components/text/text.go index 3639aef7..2381f0f3 100644 --- a/pkg/components/text/text.go +++ b/pkg/components/text/text.go @@ -58,7 +58,7 @@ func (t *text) SetConfig(config *config.Config) { t.config = config } -func (t *text) Render(provider core.Provider, cell core.Cell) { +func (t *text) Render(provider core.Provider, cell *core.Cell) { t.prop.MakeValid(t.config.DefaultFont) - provider.AddText(t.value, cell, t.prop) + provider.AddText(t.value, cell, &t.prop) } diff --git a/pkg/config/margins.go b/pkg/config/margins.go index dcf299d1..ed3d26d3 100644 --- a/pkg/config/margins.go +++ b/pkg/config/margins.go @@ -1,7 +1,18 @@ package config +import "fmt" + type Margins struct { - Left float64 - Right float64 - Top float64 + Left float64 + Right float64 + Top float64 + Bottom float64 +} + +func (m *Margins) Print() { + if m == nil { + return + } + + fmt.Printf("Left: %1.f, Right: %1.f, Top: %1.f, Bottom: %1.f\n", m.Left, m.Right, m.Left, m.Bottom) } diff --git a/pkg/core/cell.go b/pkg/core/cell.go index 18aa5d6b..c4f979f2 100644 --- a/pkg/core/cell.go +++ b/pkg/core/cell.go @@ -1,5 +1,7 @@ package core +import "github.com/johnfercher/maroto/v2/pkg/config" + // Cell represents a cell inside the PDF. type Cell struct { X float64 @@ -17,7 +19,7 @@ func (c Cell) Copy() Cell { } } -func NewRootContext(pageWidth, pageHeight float64, margins Margins) Cell { +func NewRootContext(pageWidth, pageHeight float64, margins config.Margins) Cell { return Cell{ X: 0, Y: 0, diff --git a/pkg/core/core.go b/pkg/core/core.go index f89b8f6e..187911cd 100644 --- a/pkg/core/core.go +++ b/pkg/core/core.go @@ -32,7 +32,7 @@ type Node interface { type Component interface { Node - Render(provider Provider, cell Cell) + Render(provider Provider, cell *Cell) } type Col interface { diff --git a/pkg/core/margins.go b/pkg/core/margins.go deleted file mode 100644 index 57b1c77b..00000000 --- a/pkg/core/margins.go +++ /dev/null @@ -1,18 +0,0 @@ -package core - -import "fmt" - -type Margins struct { - Left float64 - Right float64 - Top float64 - Bottom float64 -} - -func (m *Margins) Print() { - if m == nil { - return - } - - fmt.Printf("Left: %1.f, Right: %1.f, Top: %1.f, Bottom: %1.f\n", m.Left, m.Right, m.Left, m.Bottom) -} diff --git a/pkg/core/provider.go b/pkg/core/provider.go index 33bfe1d8..4b29e030 100644 --- a/pkg/core/provider.go +++ b/pkg/core/provider.go @@ -13,13 +13,13 @@ type Provider interface { CreateCol(width, height float64, config *config.Config, prop *props.Cell) // Features - AddLine(cell Cell, prop props.Line) - AddText(text string, cell Cell, prop props.Text) - AddSignature(text string, cell Cell, prop props.Text) - AddMatrixCode(code string, cell Cell, prop props.Rect) - AddQrCode(code string, cell Cell, rect props.Rect) - AddBarCode(code string, cell Cell, prop props.Barcode) - AddImage(value string, cell Cell, prop props.Rect, extension extension.Type) + AddLine(cell *Cell, prop *props.Line) + AddText(text string, cell *Cell, prop *props.Text) + AddSignature(text string, cell *Cell, prop *props.Text) + AddMatrixCode(code string, cell *Cell, prop *props.Rect) + AddQrCode(code string, cell *Cell, rect *props.Rect) + AddBarCode(code string, cell *Cell, prop *props.Barcode) + AddImage(value string, cell *Cell, prop *props.Rect, extension extension.Type) // General GetDimensions() (width float64, height float64) diff --git a/pkg/maroto.go b/pkg/maroto.go index 624bcc48..92af06f5 100644 --- a/pkg/maroto.go +++ b/pkg/maroto.go @@ -46,9 +46,9 @@ type maroto struct { pool async.Processor[[]core.Page, []byte] } -func NewMaroto(config ...*config.Config) core.Maroto { +func NewMaroto(cfgs ...*config.Config) core.Maroto { cache := cache.New() - cfg := getConfig(config...) + cfg := getConfig(cfgs...) provider := getProvider(cache, cfg) width, height := provider.GetDimensions() @@ -56,7 +56,7 @@ func NewMaroto(config ...*config.Config) core.Maroto { m := &maroto{ provider: provider, - cell: core.NewRootContext(width, height, core.Margins{ + cell: core.NewRootContext(width, height, config.Margins{ Left: left, Top: top, Right: right, diff --git a/pkg/props/font.go b/pkg/props/font.go index 607c7b97..7e0b4e0f 100644 --- a/pkg/props/font.go +++ b/pkg/props/font.go @@ -35,8 +35,8 @@ func (s *Font) MakeValid(defaultFamily string) { } // ToTextProp from Font return a Text based on Font. -func (s *Font) ToTextProp(align align.Type, top float64, verticalPadding float64) Text { - textProp := Text{ +func (s *Font) ToTextProp(align align.Type, top float64, verticalPadding float64) *Text { + textProp := &Text{ Family: s.Family, Style: s.Style, Size: s.Size, diff --git a/pkg/props/page.go b/pkg/props/page.go index 4988dd26..8aa71a41 100644 --- a/pkg/props/page.go +++ b/pkg/props/page.go @@ -33,8 +33,8 @@ type Page struct { Color *Color } -func (p *Page) GetNumberTextProp(height float64) Text { - text := Text{ +func (p *Page) GetNumberTextProp(height float64) *Text { + text := &Text{ Family: p.Family, Style: p.Style, Size: p.Size, diff --git a/pkg/providers/gofpdf/gofpdf.go b/pkg/providers/gofpdf/gofpdf.go index 6b7c2889..97091c17 100644 --- a/pkg/providers/gofpdf/gofpdf.go +++ b/pkg/providers/gofpdf/gofpdf.go @@ -3,6 +3,8 @@ package gofpdf import ( "bytes" + "github.com/johnfercher/maroto/v2/internal/math" + "github.com/johnfercher/maroto/v2/internal" "github.com/johnfercher/maroto/v2/pkg/cache" "github.com/johnfercher/maroto/v2/pkg/config" @@ -30,7 +32,7 @@ var defaultErrorColor = &props.Font{ type gofpdfProvider struct { fpdf *gofpdf.Fpdf - math internal.Math + math math.Math font internal.Font text internal.Text signature internal.Signature @@ -39,6 +41,7 @@ type gofpdfProvider struct { line internal.Line imageCache cache.Cache cellWriter cellwriter.CellWriter + cfg *config.Config } func New(cfg *config.Config, options ...providers.ProviderOption) core.Provider { @@ -60,7 +63,7 @@ func New(cfg *config.Config, options ...providers.ProviderOption) core.Provider fpdf.AddPage() font := internal.NewFont(fpdf, cfg.DefaultFont.Size, cfg.DefaultFont.Family, cfg.DefaultFont.Style) - math := internal.NewMath(fpdf) + math := math.New() text := internal.NewText(fpdf, math, font) signature := internal.NewSignature(fpdf, math, text) code := internal.NewCode(fpdf, math) @@ -78,6 +81,7 @@ func New(cfg *config.Config, options ...providers.ProviderOption) core.Provider image: image, line: line, cellWriter: cellWriter, + cfg: cfg, } for _, option := range options { @@ -95,49 +99,49 @@ func (g *gofpdfProvider) GetMargins() (left float64, top float64, right float64, return g.fpdf.GetMargins() } -func (g *gofpdfProvider) AddText(text string, cell core.Cell, prop props.Text) { +func (g *gofpdfProvider) AddText(text string, cell *core.Cell, prop *props.Text) { g.text.Add(text, cell, prop) } -func (g *gofpdfProvider) AddLine(cell core.Cell, prop props.Line) { +func (g *gofpdfProvider) AddLine(cell *core.Cell, prop *props.Line) { g.line.Add(cell, prop) } -func (g *gofpdfProvider) AddSignature(text string, cell core.Cell, prop props.Text) { +func (g *gofpdfProvider) AddSignature(text string, cell *core.Cell, prop *props.Text) { g.signature.AddSpaceFor(text, cell, prop) } -func (g *gofpdfProvider) AddMatrixCode(code string, cell core.Cell, prop props.Rect) { - g.code.AddDataMatrix(code, cell, prop) +func (g *gofpdfProvider) AddMatrixCode(code string, cell *core.Cell, prop *props.Rect) { + g.code.AddDataMatrix(code, cell, g.cfg.Margins, prop) } -func (g *gofpdfProvider) AddQrCode(code string, cell core.Cell, rect props.Rect) { - g.code.AddQr(code, cell, rect) +func (g *gofpdfProvider) AddQrCode(code string, cell *core.Cell, rect *props.Rect) { + g.code.AddQr(code, cell, g.cfg.Margins, rect) } -func (g *gofpdfProvider) AddBarCode(code string, cell core.Cell, prop props.Barcode) { - err := g.code.AddBar(code, cell, prop) +func (g *gofpdfProvider) AddBarCode(code string, cell *core.Cell, prop *props.Barcode) { + err := g.code.AddBar(code, cell, g.cfg.Margins, prop) if err != nil { - textProp := props.Text{} + textProp := &props.Text{} textProp.MakeValid(defaultErrorColor) g.fpdf.ClearError() g.AddText("Failed to render code", cell, textProp) } } -func (g *gofpdfProvider) AddImage(file string, cell core.Cell, prop props.Rect, extension extension.Type) { +func (g *gofpdfProvider) AddImage(file string, cell *core.Cell, prop *props.Rect, extension extension.Type) { img, err := g.imageCache.Load(file, extension) if err != nil { - textProp := props.Text{} + textProp := &props.Text{} textProp.MakeValid(defaultErrorColor) g.fpdf.ClearError() g.AddText("Failed to load image from file", cell, textProp) return } - err = g.image.AddFromBase64(img.Value, cell, prop, img.Extension) + err = g.image.AddFromBase64(img.Value, cell, g.cfg.Margins, prop, img.Extension) if err != nil { - textProp := props.Text{} + textProp := &props.Text{} textProp.MakeValid(defaultErrorColor) g.fpdf.ClearError() g.AddText("Failed to load image from file", cell, textProp) diff --git a/pkg/providers/html/html.go b/pkg/providers/html/html.go index fcc94af2..247fea5b 100644 --- a/pkg/providers/html/html.go +++ b/pkg/providers/html/html.go @@ -125,7 +125,7 @@ func (h *html) SetProtection(_ *config.Protection) { func (h *html) SetMetadata(_ *config.Metadata) { } -func (h *html) AddLine(_ core.Cell, _ props.Line) { +func (h *html) AddLine(_ *core.Cell, _ *props.Line) { } func (h *html) CreateCol(width, height float64, config *config.Config, prop *props.Cell) { @@ -157,7 +157,7 @@ func (h *html) GetMargins() (left float64, top float64, right float64, bottom fl return h.div.margins.Left, h.div.margins.Top, h.div.margins.Right, h.div.margins.Bottom } -func (h *html) AddText(text string, _ core.Cell, _ props.Text) { +func (h *html) AddText(text string, _ *core.Cell, _ *props.Text) { col := h.getLastCol() textDiv := col.GetData() @@ -168,7 +168,7 @@ func (h *html) AddText(text string, _ core.Cell, _ props.Text) { col.AddNext(textNode) } -func (h *html) AddSignature(text string, _ core.Cell, _ props.Text) { +func (h *html) AddSignature(text string, _ *core.Cell, _ *props.Text) { col := h.getLastCol() textDiv := col.GetData() @@ -179,7 +179,7 @@ func (h *html) AddSignature(text string, _ core.Cell, _ props.Text) { col.AddNext(textNode) } -func (h *html) AddMatrixCode(text string, _ core.Cell, _ props.Rect) { +func (h *html) AddMatrixCode(text string, _ *core.Cell, _ *props.Rect) { col := h.getLastCol() textDiv := col.GetData() @@ -190,7 +190,7 @@ func (h *html) AddMatrixCode(text string, _ core.Cell, _ props.Rect) { col.AddNext(textNode) } -func (h *html) AddQrCode(code string, _ core.Cell, _ props.Rect) { +func (h *html) AddQrCode(code string, _ *core.Cell, _ *props.Rect) { col := h.getLastCol() textDiv := col.GetData() @@ -201,7 +201,7 @@ func (h *html) AddQrCode(code string, _ core.Cell, _ props.Rect) { col.AddNext(textNode) } -func (h *html) AddBarCode(code string, _ core.Cell, _ props.Barcode) { +func (h *html) AddBarCode(code string, _ *core.Cell, _ *props.Barcode) { col := h.getLastCol() textDiv := col.GetData() @@ -212,7 +212,7 @@ func (h *html) AddBarCode(code string, _ core.Cell, _ props.Barcode) { col.AddNext(textNode) } -func (h *html) AddImage(value string, _ core.Cell, _ props.Rect, extension extension.Type) { +func (h *html) AddImage(value string, _ *core.Cell, _ *props.Rect, extension extension.Type) { minSize := 20 if len(value) < minSize { minSize = len(value)