-
-
Notifications
You must be signed in to change notification settings - Fork 218
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ccaf6de
commit 1228e6a
Showing
26 changed files
with
305 additions
and
108 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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/[email protected].19 | ||
go get github.com/johnfercher/maroto/v2/[email protected].20 | ||
``` | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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.19`is here! Try out: | ||
#### Maroto`v2.0.0-alpha.20`is here! Try out: | ||
|
||
* Installation with`go get`: | ||
|
||
```bash | ||
go get github.com/johnfercher/maroto/v2/[email protected].19 | ||
go get github.com/johnfercher/maroto/v2/[email protected].20 | ||
``` | ||
|
||
The public API was completely redesigned with the aim of enhancing the | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package main | ||
|
||
import ( | ||
"log" | ||
|
||
"github.com/johnfercher/maroto/v2/pkg/components/line" | ||
"github.com/johnfercher/maroto/v2/pkg/consts/linestyle" | ||
"github.com/johnfercher/maroto/v2/pkg/consts/orientation" | ||
"github.com/johnfercher/maroto/v2/pkg/props" | ||
|
||
"github.com/johnfercher/maroto/v2/pkg" | ||
"github.com/johnfercher/maroto/v2/pkg/config" | ||
) | ||
|
||
var redColor = props.Color{ | ||
Red: 255, | ||
Green: 0, | ||
Blue: 0, | ||
} | ||
|
||
func main() { | ||
cfg := config.NewBuilder(). | ||
WithDebug(true). | ||
Build() | ||
|
||
mrt := pkg.NewMaroto(cfg) | ||
m := pkg.NewMetricsDecorator(mrt) | ||
|
||
m.AddRow(40, | ||
line.NewCol(2), | ||
line.NewCol(4), | ||
line.NewCol(6), | ||
) | ||
|
||
m.AddRow(40, | ||
line.NewCol(6), | ||
line.NewCol(4), | ||
line.NewCol(2), | ||
) | ||
|
||
m.AddRow(40, | ||
line.NewCol(2, props.Line{Thickness: 0.5}), | ||
line.NewCol(4, props.Line{Color: redColor}), | ||
line.NewCol(6, props.Line{Orientation: orientation.Vertical}), | ||
) | ||
|
||
m.AddRow(40, | ||
line.NewCol(6, props.Line{OffsetPercent: 50}), | ||
line.NewCol(4, props.Line{OffsetPercent: 50, Orientation: orientation.Vertical}), | ||
line.NewCol(2, props.Line{SizePercent: 50}), | ||
) | ||
|
||
m.AddRow(40, | ||
line.NewCol(2, props.Line{Style: linestyle.Dashed}), | ||
line.NewCol(4, props.Line{Color: redColor, Style: linestyle.Dashed, Thickness: 0.8, Orientation: orientation.Vertical, OffsetPercent: 70, SizePercent: 70}), | ||
line.NewCol(6, props.Line{Color: redColor, Style: linestyle.Dashed, Thickness: 0.8, Orientation: orientation.Horizontal, OffsetPercent: 40, SizePercent: 40}), | ||
) | ||
|
||
document, err := m.Generate() | ||
if err != nil { | ||
log.Fatal(err.Error()) | ||
} | ||
|
||
err = document.Save("docs/assets/pdf/linegridv2.pdf") | ||
if err != nil { | ||
log.Fatal(err.Error()) | ||
} | ||
|
||
err = document.GetReport().Save("docs/assets/text/linegridv2.txt") | ||
if err != nil { | ||
log.Fatal(err.Error()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
generate -> avg: 66.16μs, executions: [66.16μs] | ||
add_cols -> avg: 184.60ns, executions: [498.00ns, 139.00ns, 118.00ns, 68.00ns, 100.00ns] | ||
file_size -> 2.67Kb |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# Line | ||
|
||
## Code Example | ||
[filename](../../assets/examples/line/v2/main.go ':include :type=code') | ||
|
||
## PDF Generated | ||
assets/pdf/linegridv2.pdf | ||
``` | ||
## Time Execution | ||
[filename](../../assets/text/linegridv2.txt ':include :type=code') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
package internal | ||
|
||
import ( | ||
"github.com/johnfercher/maroto/v2/internal/fpdf" | ||
"github.com/johnfercher/maroto/v2/pkg/consts/linestyle" | ||
"github.com/johnfercher/maroto/v2/pkg/consts/orientation" | ||
"github.com/johnfercher/maroto/v2/pkg/core" | ||
"github.com/johnfercher/maroto/v2/pkg/props" | ||
) | ||
|
||
type Line interface { | ||
Add(cell core.Cell, prop props.Line) | ||
} | ||
|
||
type line struct { | ||
pdf fpdf.Fpdf | ||
defaultColor *props.Color | ||
defaultThickness float64 | ||
} | ||
|
||
func NewLine(pdf fpdf.Fpdf) *line { | ||
return &line{ | ||
pdf: pdf, | ||
defaultColor: props.NewBlack(), | ||
defaultThickness: linestyle.DefaultLineThickness, | ||
} | ||
} | ||
|
||
func (l *line) Add(cell core.Cell, prop props.Line) { | ||
if prop.Orientation == orientation.Vertical { | ||
l.renderVertical(cell, prop) | ||
} else { | ||
l.renderHorizontal(cell, prop) | ||
} | ||
} | ||
|
||
func (l *line) renderVertical(cell core.Cell, prop props.Line) { | ||
size := cell.Height * (prop.SizePercent / 100.0) | ||
position := cell.Width * (prop.OffsetPercent / 100.0) | ||
|
||
space := (cell.Height - size) / 2.0 | ||
|
||
left, top, _, _ := l.pdf.GetMargins() | ||
|
||
l.pdf.SetDrawColor(prop.Color.Red, prop.Color.Green, prop.Color.Blue) | ||
l.pdf.SetLineWidth(prop.Thickness) | ||
|
||
if prop.Style != linestyle.Solid { | ||
l.pdf.SetDashPattern([]float64{1, 1}, 0) | ||
} | ||
|
||
l.pdf.Line(left+cell.X+position, top+cell.Y+space, left+cell.X+position, top+cell.Y+cell.Height-space) | ||
|
||
l.pdf.SetDrawColor(l.defaultColor.Red, l.defaultColor.Green, l.defaultColor.Blue) | ||
l.pdf.SetLineWidth(l.defaultThickness) | ||
|
||
if prop.Style != linestyle.Solid { | ||
l.pdf.SetDashPattern([]float64{1, 0}, 0) | ||
} | ||
} | ||
|
||
func (l *line) renderHorizontal(cell core.Cell, prop props.Line) { | ||
size := cell.Width * (prop.SizePercent / 100.0) | ||
position := cell.Height * (prop.OffsetPercent / 100.0) | ||
|
||
space := (cell.Width - size) / 2.0 | ||
|
||
left, top, _, _ := l.pdf.GetMargins() | ||
|
||
l.pdf.SetDrawColor(prop.Color.Red, prop.Color.Green, prop.Color.Blue) | ||
l.pdf.SetLineWidth(prop.Thickness) | ||
|
||
if prop.Style != linestyle.Solid { | ||
l.pdf.SetDashPattern([]float64{1, 1}, 0) | ||
} | ||
|
||
l.pdf.Line(left+cell.X+space, top+cell.Y+position, left+cell.X+cell.Width-space, top+cell.Y+position) | ||
|
||
l.pdf.SetDrawColor(l.defaultColor.Red, l.defaultColor.Green, l.defaultColor.Blue) | ||
l.pdf.SetLineWidth(l.defaultThickness) | ||
|
||
if prop.Style != linestyle.Solid { | ||
l.pdf.SetDashPattern([]float64{1, 0}, 0) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package line | ||
|
||
import ( | ||
"github.com/johnfercher/go-tree/tree" | ||
"github.com/johnfercher/maroto/v2/pkg/components/col" | ||
"github.com/johnfercher/maroto/v2/pkg/components/row" | ||
"github.com/johnfercher/maroto/v2/pkg/config" | ||
"github.com/johnfercher/maroto/v2/pkg/core" | ||
"github.com/johnfercher/maroto/v2/pkg/props" | ||
) | ||
|
||
type line struct { | ||
config *config.Config | ||
prop props.Line | ||
} | ||
|
||
func New(ps ...props.Line) core.Component { | ||
lineProp := props.Line{} | ||
if len(ps) > 0 { | ||
lineProp = ps[0] | ||
} | ||
lineProp.MakeValid() | ||
|
||
return &line{ | ||
prop: lineProp, | ||
} | ||
} | ||
|
||
func NewCol(size int, ps ...props.Line) core.Col { | ||
r := New(ps...) | ||
return col.New(size).Add(r) | ||
} | ||
|
||
func NewRow(height float64, ps ...props.Line) core.Row { | ||
r := New(ps...) | ||
c := col.New().Add(r) | ||
return row.New(height).Add(c) | ||
} | ||
|
||
func (l *line) GetStructure() *tree.Node[core.Structure] { | ||
str := core.Structure{ | ||
Type: "linestyle", | ||
} | ||
|
||
return tree.NewNode(str) | ||
} | ||
|
||
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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package linestyle | ||
|
||
const ( | ||
// DefaultLineThickness represents the default linestyle width in gofpdf. | ||
DefaultLineThickness float64 = 0.2 | ||
) | ||
|
||
// Type is a representation of a linestyle style. | ||
type Type string | ||
|
||
const ( | ||
// Solid represents a solid style. | ||
Solid Type = "solid" | ||
// Dashed represents a dashed style. | ||
Dashed Type = "dashed" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.