-
-
Notifications
You must be signed in to change notification settings - Fork 209
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
0dd544c
commit 5cc7521
Showing
9 changed files
with
144 additions
and
66 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
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 |
---|---|---|
@@ -1,7 +1,9 @@ | ||
package v2 | ||
|
||
import "github.com/johnfercher/maroto/internal/fpdf" | ||
|
||
type Component interface { | ||
Render() | ||
Render(fpdf fpdf.Fpdf, ctx Context) | ||
GetType() string | ||
Add(component ...Component) | ||
} |
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,47 @@ | ||
package v2 | ||
|
||
import "fmt" | ||
|
||
type Context struct { | ||
Coordinate *Coordinate | ||
Dimensions *Dimensions | ||
Margins *Margins | ||
} | ||
|
||
func (c *Context) Print(label interface{}) { | ||
fmt.Println(label) | ||
c.Margins.Print() | ||
} | ||
|
||
type Dimensions struct { | ||
Width float64 | ||
Height float64 | ||
} | ||
|
||
func (c *Dimensions) Print() { | ||
|
||
} | ||
|
||
type Coordinate struct { | ||
X float64 | ||
Y float64 | ||
} | ||
|
||
func (c *Coordinate) Print() { | ||
|
||
} | ||
|
||
type Margins struct { | ||
Left float64 | ||
Right float64 | ||
Top float64 | ||
Bottom float64 | ||
} | ||
|
||
func (c *Margins) Print() { | ||
if c == nil { | ||
return | ||
} | ||
|
||
fmt.Printf("Left: %1.f, Right: %1.f, Top: %1.f, Bottom: %1.f\n", c.Left, c.Right, c.Left, c.Bottom) | ||
} |
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 |
---|---|---|
@@ -1,39 +1,57 @@ | ||
package v2 | ||
|
||
import "fmt" | ||
import ( | ||
"github.com/johnfercher/maroto/internal/fpdf" | ||
"github.com/jung-kurt/gofpdf" | ||
) | ||
|
||
type Maroto interface { | ||
Add(component ...Component) | ||
Generate(file string) error | ||
} | ||
|
||
type document struct { | ||
value string | ||
ctx Context | ||
_type DocumentType | ||
fpdf fpdf.Fpdf | ||
components []Component | ||
} | ||
|
||
func NewDocument(value string) *document { | ||
func NewDocument() *document { | ||
fpdf := gofpdf.NewCustom(&gofpdf.InitType{ | ||
OrientationStr: "P", | ||
UnitStr: "mm", | ||
SizeStr: "A4", | ||
FontDirStr: "", | ||
}) | ||
|
||
width, height := fpdf.GetPageSize() | ||
left, top, right, bottom := fpdf.GetMargins() | ||
|
||
return &document{ | ||
fpdf: fpdf, | ||
_type: Document, | ||
value: value, | ||
ctx: Context{ | ||
Coordinate: &Coordinate{0, 0}, | ||
Dimensions: &Dimensions{width, height}, | ||
Margins: &Margins{left, right, top, bottom}, | ||
}, | ||
} | ||
} | ||
|
||
func (d *document) Render() { | ||
fmt.Println(d.value) | ||
for _, component := range d.components { | ||
component.Render() | ||
} | ||
} | ||
|
||
func (d *document) IsDrawable() bool { | ||
return false | ||
} | ||
|
||
func (d *document) GetType() string { | ||
return d._type.String() | ||
} | ||
|
||
func (d *document) Add(components ...Component) { | ||
for _, component := range components { | ||
if d._type.Accept(component.GetType()) { | ||
d.components = append(d.components, component) | ||
} | ||
} | ||
} | ||
|
||
func (d *document) Generate(file string) error { | ||
d.ctx.Print(d._type) | ||
for _, component := range d.components { | ||
component.Render(d.fpdf, d.ctx) | ||
} | ||
|
||
return d.fpdf.OutputFileAndClose(file) | ||
} |
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 |
---|---|---|
@@ -1,38 +1,45 @@ | ||
package row | ||
|
||
import ( | ||
"fmt" | ||
"github.com/johnfercher/maroto/internal/fpdf" | ||
"github.com/johnfercher/maroto/pkg/v2" | ||
) | ||
|
||
type row struct { | ||
height int | ||
height float64 | ||
_type v2.DocumentType | ||
components []v2.Component | ||
} | ||
|
||
func New(height int) *row { | ||
func New(height float64) *row { | ||
return &row{ | ||
_type: v2.Row, | ||
height: height, | ||
} | ||
} | ||
|
||
func (d *row) Render() { | ||
fmt.Println(d.height) | ||
for _, component := range d.components { | ||
component.Render() | ||
} | ||
} | ||
|
||
func (d *row) GetType() string { | ||
return d._type.String() | ||
func (r *row) GetType() string { | ||
return r._type.String() | ||
} | ||
|
||
func (d *row) Add(components ...v2.Component) { | ||
func (r *row) Add(components ...v2.Component) { | ||
for _, component := range components { | ||
if d._type.Accept(component.GetType()) { | ||
d.components = append(d.components, component) | ||
if r._type.Accept(component.GetType()) { | ||
r.components = append(r.components, component) | ||
} | ||
} | ||
} | ||
|
||
func (r *row) Render(fpdf fpdf.Fpdf, ctx v2.Context) { | ||
ctx.Print(r.height) | ||
r.render(fpdf, ctx) | ||
for _, component := range r.components { | ||
component.Render(fpdf, ctx) | ||
} | ||
} | ||
|
||
func (r *row) render(fpdf fpdf.Fpdf, ctx v2.Context) { | ||
fpdf.AddPage() | ||
fpdf.SetFont("Arial", "B", 16) | ||
fpdf.CellFormat(ctx.Dimensions.Width-ctx.Margins.Left-ctx.Margins.Right, r.height, "", "1", 0, "C", false, 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