Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update docs #393

Merged
merged 5 commits into from
Jan 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ You can write your PDFs like you are creating a site using Bootstrap. A Row may
Besides that, pages will be added when content may extrapolate the useful area. You can define a header which will be added
always when a new page appear, in this case, a header may have many rows, lines or tablelist.

#### Maroto `v2.0.0-beta.12` is here! Try out:
#### Maroto `v2.0.0-beta.13` is here! Try out:

* Installation with`go get`:

```bash
go get github.com/johnfercher/maroto/v2@v2.0.0-beta.12
go get github.com/johnfercher/maroto/v2@v2.0.0-beta.13
```

* You can see the full `v2` documentation [here](https://maroto.io/).
Expand Down
4 changes: 2 additions & 2 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@

* We are about to create a document processor to generate PDFs by interpreting serialized data as: yml, json or html. Please contribute with your ideas in [this discussion](https://github.com/johnfercher/maroto/discussions/390).

#### 3. Maroto`v2.0.0-beta.12`is here! Try out:
#### 3. Maroto`v2.0.0-beta.13`is here! Try out:

* Installation with`go get`:

```bash
go get github.com/johnfercher/maroto/v2@v2.0.0-beta.12
go get github.com/johnfercher/maroto/v2@v2.0.0-beta.13
```

The public API was completely redesigned with the aim of enhancing the
Expand Down
2 changes: 1 addition & 1 deletion docs/_coverpage.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
![logo](assets/images/logo.png)

# Maroto <small>v2.0.0-beta.12</small>
# Maroto <small>v2.0.0-beta.13</small>

> An open-source golang lib to create PDFs. Fast and Simple.

Expand Down
6 changes: 6 additions & 0 deletions docs/v2/features/customfont.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Custom Font

## GoDoc
* [builder : WithCustomFonts](https://pkg.go.dev/github.com/johnfercher/maroto/v2/pkg/config#CfgBuilder.WithCustomFonts)
* [repository : AddUTF8Font](https://pkg.go.dev/github.com/johnfercher/maroto/v2/pkg/repository#FontRepository.AddUTF8Font)
* [repository : Load](https://pkg.go.dev/github.com/johnfercher/maroto/v2/pkg/repository#FontRepository.Load)
* [entity : CustomFont](https://pkg.go.dev/github.com/johnfercher/maroto/v2/pkg/core/entity#CustomFont)

## Code Example
[filename](../../assets/examples/customfont/v2/main.go ':include :type=code')

Expand Down
36 changes: 18 additions & 18 deletions maroto.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"github.com/johnfercher/maroto/v2/pkg/core"
)

type maroto struct {
type Maroto struct {
config *entity.Config
provider core.Provider
cache cache.Cache
Expand All @@ -51,7 +51,7 @@
cfg := getConfig(cfgs...)
provider := getProvider(cache, cfg)

m := &maroto{
m := &Maroto{
provider: provider,
cell: entity.NewRootCell(cfg.Dimensions.Width, cfg.Dimensions.Height, entity.Margins{
Left: cfg.Margins.Left,
Expand All @@ -76,7 +76,7 @@
// new page will appear as the next. If the page provided have
// more rows than the maximum useful area of a page, maroto will split
// that page in more than one.
func (m *maroto) AddPages(pages ...core.Page) {
func (m *Maroto) AddPages(pages ...core.Page) {
for _, page := range pages {
if m.currentHeight != m.headerHeight {
m.fillPageToAddNew()
Expand All @@ -91,7 +91,7 @@
// maroto will automatically add a new page. Maroto use the information of
// PageSize, PageMargin, FooterSize and HeaderSize to calculate the useful
// area of a page.
func (m *maroto) AddRows(rows ...core.Row) {
func (m *Maroto) AddRows(rows ...core.Row) {
m.addRows(rows...)
}

Expand All @@ -100,7 +100,7 @@
// maroto will automatically add a new page. Maroto use the information of
// PageSize, PageMargin, FooterSize and HeaderSize to calculate the useful
// area of a page.
func (m *maroto) AddRow(rowHeight float64, cols ...core.Col) core.Row {
func (m *Maroto) AddRow(rowHeight float64, cols ...core.Col) core.Row {
r := row.New(rowHeight).Add(cols...)
m.addRow(r)
return r
Expand All @@ -110,7 +110,7 @@
// of the document. The header will appear in every new page of the document.
// The header cannot occupy an area greater than the useful area of the page,
// it this case the method will return an error.
func (m *maroto) RegisterHeader(rows ...core.Row) error {
func (m *Maroto) RegisterHeader(rows ...core.Row) error {

Check warning on line 113 in maroto.go

View check run for this annotation

Codecov / codecov/patch

maroto.go#L113

Added line #L113 was not covered by tests
height := m.getRowsHeight(rows...)
if height+m.footerHeight > m.config.Dimensions.Height {
return errors.New("header height is greater than page useful area")
Expand All @@ -130,7 +130,7 @@
// of the document. The footer will appear in every new page of the document.
// The footer cannot occupy an area greater than the useful area of the page,
// it this case the method will return an error.
func (m *maroto) RegisterFooter(rows ...core.Row) error {
func (m *Maroto) RegisterFooter(rows ...core.Row) error {

Check warning on line 133 in maroto.go

View check run for this annotation

Codecov / codecov/patch

maroto.go#L133

Added line #L133 was not covered by tests
height := m.getRowsHeight(rows...)
if height > m.config.Dimensions.Height {
return errors.New("footer height is greater than page useful area")
Expand All @@ -143,7 +143,7 @@

// Generate is responsible to compute the component tree created by
// the usage of all other Maroto methods, and generate the PDF document.
func (m *maroto) Generate() (core.Document, error) {
func (m *Maroto) Generate() (core.Document, error) {
m.provider.SetProtection(m.config.Protection)
m.provider.SetCompression(m.config.Compression)
m.provider.SetMetadata(m.config.Metadata)
Expand All @@ -160,7 +160,7 @@

// GetStructure is responsible for return the component tree, this is useful
// on unit tests cases.
func (m *maroto) GetStructure() *node.Node[core.Structure] {
func (m *Maroto) GetStructure() *node.Node[core.Structure] {
m.fillPageToAddNew()

str := core.Structure{
Expand All @@ -177,13 +177,13 @@
return node
}

func (m *maroto) addRows(rows ...core.Row) {
func (m *Maroto) addRows(rows ...core.Row) {
for _, row := range rows {
m.addRow(row)
}
}

func (m *maroto) addRow(r core.Row) {
func (m *Maroto) addRow(r core.Row) {
maxHeight := m.cell.Height

rowHeight := r.GetHeight()
Expand All @@ -207,14 +207,14 @@
m.rows = append(m.rows, r)
}

func (m *maroto) addHeader() {
func (m *Maroto) addHeader() {
for _, headerRow := range m.header {
m.currentHeight += headerRow.GetHeight()
m.rows = append(m.rows, headerRow)
}
}

func (m *maroto) fillPageToAddNew() {
func (m *Maroto) fillPageToAddNew() {
space := m.cell.Height - m.currentHeight - m.footerHeight

c := col.New(m.config.MaxGridSize)
Expand All @@ -240,14 +240,14 @@
m.currentHeight = 0
}

func (m *maroto) setConfig() {
func (m *Maroto) setConfig() {
for i, page := range m.pages {
page.SetConfig(m.config)
page.SetNumber(i+1, len(m.pages))
}
}

func (m *maroto) generate() (core.Document, error) {
func (m *Maroto) generate() (core.Document, error) {
innerCtx := m.cell.Copy()

for _, page := range m.pages {
Expand All @@ -262,7 +262,7 @@
return core.NewPDF(documentBytes, nil), nil
}

func (m *maroto) generateConcurrently() (core.Document, error) {
func (m *Maroto) generateConcurrently() (core.Document, error) {
chunks := len(m.pages) / m.config.WorkersQuantity
if chunks == 0 {
chunks = 1
Expand Down Expand Up @@ -297,7 +297,7 @@
return core.NewPDF(mergedBytes, nil), nil
}

func (m *maroto) processPage(pages []core.Page) ([]byte, error) {
func (m *Maroto) processPage(pages []core.Page) ([]byte, error) {
innerCtx := m.cell.Copy()

innerProvider := getProvider(cache.NewMutexDecorator(cache.New()), m.config)
Expand All @@ -308,7 +308,7 @@
return innerProvider.GenerateBytes()
}

func (m *maroto) getRowsHeight(rows ...core.Row) float64 {
func (m *Maroto) getRowsHeight(rows ...core.Row) float64 {

Check warning on line 311 in maroto.go

View check run for this annotation

Codecov / codecov/patch

maroto.go#L311

Added line #L311 was not covered by tests
var height float64
for _, r := range rows {
height += r.GetHeight()
Expand Down
6 changes: 3 additions & 3 deletions maroto_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func TestNew(t *testing.T) {

// Assert
assert.NotNil(t, sut)
assert.Equal(t, "*maroto.maroto", fmt.Sprintf("%T", sut))
assert.Equal(t, "*maroto.Maroto", fmt.Sprintf("%T", sut))
})
t.Run("new with config", func(t *testing.T) {
// Arrange
Expand All @@ -35,7 +35,7 @@ func TestNew(t *testing.T) {

// Assert
assert.NotNil(t, sut)
assert.Equal(t, "*maroto.maroto", fmt.Sprintf("%T", sut))
assert.Equal(t, "*maroto.Maroto", fmt.Sprintf("%T", sut))
})
t.Run("new with config and worker pool size", func(t *testing.T) {
// Arrange
Expand All @@ -48,7 +48,7 @@ func TestNew(t *testing.T) {

// Assert
assert.NotNil(t, sut)
assert.Equal(t, "*maroto.maroto", fmt.Sprintf("%T", sut))
assert.Equal(t, "*maroto.Maroto", fmt.Sprintf("%T", sut))
})
}

Expand Down
22 changes: 11 additions & 11 deletions metricsdecorator.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"github.com/johnfercher/maroto/v2/pkg/metrics"
)

type metricsDecorator struct {
type MetricsDecorator struct {
addRowsTime []*metrics.Time
addRowTime []*metrics.Time
addPageTime []*metrics.Time
Expand All @@ -21,13 +21,13 @@
// NewMetricsDecorator is responsible to create the metrics decorator
// for the maroto instance.
func NewMetricsDecorator(inner core.Maroto) core.Maroto {
return &metricsDecorator{
return &MetricsDecorator{
inner: inner,
}
}

// Generate decorates the Generate method of maroto instance.
func (m *metricsDecorator) Generate() (core.Document, error) {
func (m *MetricsDecorator) Generate() (core.Document, error) {
var document core.Document
var err error

Expand All @@ -48,7 +48,7 @@
}

// AddPages decorates the AddPages method of maroto instance.
func (m *metricsDecorator) AddPages(pages ...core.Page) {
func (m *MetricsDecorator) AddPages(pages ...core.Page) {
timeSpent := time.GetTimeSpent(func() {
m.inner.AddPages(pages...)
})
Expand All @@ -57,7 +57,7 @@
}

// AddRows decorates the AddRows method of maroto instance.
func (m *metricsDecorator) AddRows(rows ...core.Row) {
func (m *MetricsDecorator) AddRows(rows ...core.Row) {
timeSpent := time.GetTimeSpent(func() {
m.inner.AddRows(rows...)
})
Expand All @@ -66,7 +66,7 @@
}

// AddRow decorates the AddRow method of maroto instance.
func (m *metricsDecorator) AddRow(rowHeight float64, cols ...core.Col) core.Row {
func (m *MetricsDecorator) AddRow(rowHeight float64, cols ...core.Col) core.Row {
var r core.Row
timeSpent := time.GetTimeSpent(func() {
r = m.inner.AddRow(rowHeight, cols...)
Expand All @@ -77,7 +77,7 @@
}

// RegisterHeader decorates the RegisterHeader method of maroto instance.
func (m *metricsDecorator) RegisterHeader(rows ...core.Row) error {
func (m *MetricsDecorator) RegisterHeader(rows ...core.Row) error {

Check warning on line 80 in metricsdecorator.go

View check run for this annotation

Codecov / codecov/patch

metricsdecorator.go#L80

Added line #L80 was not covered by tests
var err error
timeSpent := time.GetTimeSpent(func() {
err = m.inner.RegisterHeader(rows...)
Expand All @@ -87,7 +87,7 @@
}

// RegisterFooter decorates the RegisterFooter method of maroto instance.
func (m *metricsDecorator) RegisterFooter(rows ...core.Row) error {
func (m *MetricsDecorator) RegisterFooter(rows ...core.Row) error {

Check warning on line 90 in metricsdecorator.go

View check run for this annotation

Codecov / codecov/patch

metricsdecorator.go#L90

Added line #L90 was not covered by tests
var err error
timeSpent := time.GetTimeSpent(func() {
err = m.inner.RegisterFooter(rows...)
Expand All @@ -97,7 +97,7 @@
}

// GetStructure decorates the GetStructure method of maroto instance.
func (m *metricsDecorator) GetStructure() *node.Node[core.Structure] {
func (m *MetricsDecorator) GetStructure() *node.Node[core.Structure] {
var tree *node.Node[core.Structure]

timeSpent := time.GetTimeSpent(func() {
Expand All @@ -108,7 +108,7 @@
return tree
}

func (m *metricsDecorator) buildMetrics(bytesSize int) *metrics.Report {
func (m *MetricsDecorator) buildMetrics(bytesSize int) *metrics.Report {
var timeMetrics []metrics.TimeMetric

if m.structureTime != nil {
Expand Down Expand Up @@ -179,7 +179,7 @@
}
}

func (m *metricsDecorator) getAVG(times []*metrics.Time) *metrics.Time {
func (m *MetricsDecorator) getAVG(times []*metrics.Time) *metrics.Time {
var sum float64
for _, time := range times {
sum += time.Value
Expand Down
2 changes: 1 addition & 1 deletion metricsdecorator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func TestNewMetricsDecorator(t *testing.T) {

// Assert
assert.NotNil(t, sut)
assert.Equal(t, "*maroto.metricsDecorator", fmt.Sprintf("%T", sut))
assert.Equal(t, "*maroto.MetricsDecorator", fmt.Sprintf("%T", sut))
}

func TestMetricsDecorator_AddPages(t *testing.T) {
Expand Down
Loading