diff --git a/README.md b/README.md index 42c5c8f7..5d7adf3e 100644 --- a/README.md +++ b/README.md @@ -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/). diff --git a/docs/README.md b/docs/README.md index 816d3987..f8ec3aaa 100644 --- a/docs/README.md +++ b/docs/README.md @@ -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 diff --git a/docs/_coverpage.md b/docs/_coverpage.md index 44654354..52c5bf69 100644 --- a/docs/_coverpage.md +++ b/docs/_coverpage.md @@ -1,6 +1,6 @@ ![logo](assets/images/logo.png) -# Maroto v2.0.0-beta.12 +# Maroto v2.0.0-beta.13 > An open-source golang lib to create PDFs. Fast and Simple. diff --git a/docs/v2/features/customfont.md b/docs/v2/features/customfont.md index 158379f8..583a9ab1 100644 --- a/docs/v2/features/customfont.md +++ b/docs/v2/features/customfont.md @@ -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') diff --git a/maroto.go b/maroto.go index d58da49a..701f037a 100644 --- a/maroto.go +++ b/maroto.go @@ -24,7 +24,7 @@ import ( "github.com/johnfercher/maroto/v2/pkg/core" ) -type maroto struct { +type Maroto struct { config *entity.Config provider core.Provider cache cache.Cache @@ -51,7 +51,7 @@ func New(cfgs ...*entity.Config) core.Maroto { 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, @@ -76,7 +76,7 @@ func New(cfgs ...*entity.Config) core.Maroto { // 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() @@ -91,7 +91,7 @@ func (m *maroto) AddPages(pages ...core.Page) { // 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...) } @@ -100,7 +100,7 @@ func (m *maroto) AddRows(rows ...core.Row) { // 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 @@ -110,7 +110,7 @@ func (m *maroto) AddRow(rowHeight float64, cols ...core.Col) core.Row { // 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 { height := m.getRowsHeight(rows...) if height+m.footerHeight > m.config.Dimensions.Height { return errors.New("header height is greater than page useful area") @@ -130,7 +130,7 @@ func (m *maroto) RegisterHeader(rows ...core.Row) error { // 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 { height := m.getRowsHeight(rows...) if height > m.config.Dimensions.Height { return errors.New("footer height is greater than page useful area") @@ -143,7 +143,7 @@ func (m *maroto) RegisterFooter(rows ...core.Row) error { // 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) @@ -160,7 +160,7 @@ func (m *maroto) Generate() (core.Document, error) { // 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{ @@ -177,13 +177,13 @@ func (m *maroto) GetStructure() *node.Node[core.Structure] { 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() @@ -207,14 +207,14 @@ func (m *maroto) addRow(r core.Row) { 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) @@ -240,14 +240,14 @@ func (m *maroto) fillPageToAddNew() { 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 { @@ -262,7 +262,7 @@ func (m *maroto) generate() (core.Document, error) { 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 @@ -297,7 +297,7 @@ func (m *maroto) generateConcurrently() (core.Document, error) { 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) @@ -308,7 +308,7 @@ func (m *maroto) processPage(pages []core.Page) ([]byte, error) { return innerProvider.GenerateBytes() } -func (m *maroto) getRowsHeight(rows ...core.Row) float64 { +func (m *Maroto) getRowsHeight(rows ...core.Row) float64 { var height float64 for _, r := range rows { height += r.GetHeight() diff --git a/maroto_test.go b/maroto_test.go index 5a478231..1d41ecf6 100644 --- a/maroto_test.go +++ b/maroto_test.go @@ -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 @@ -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 @@ -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)) }) } diff --git a/metricsdecorator.go b/metricsdecorator.go index 1342f6e2..b4b2ffe0 100644 --- a/metricsdecorator.go +++ b/metricsdecorator.go @@ -7,7 +7,7 @@ import ( "github.com/johnfercher/maroto/v2/pkg/metrics" ) -type metricsDecorator struct { +type MetricsDecorator struct { addRowsTime []*metrics.Time addRowTime []*metrics.Time addPageTime []*metrics.Time @@ -21,13 +21,13 @@ type metricsDecorator struct { // 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 @@ -48,7 +48,7 @@ func (m *metricsDecorator) Generate() (core.Document, error) { } // 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...) }) @@ -57,7 +57,7 @@ func (m *metricsDecorator) AddPages(pages ...core.Page) { } // 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...) }) @@ -66,7 +66,7 @@ func (m *metricsDecorator) AddRows(rows ...core.Row) { } // 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...) @@ -77,7 +77,7 @@ func (m *metricsDecorator) AddRow(rowHeight float64, cols ...core.Col) core.Row } // RegisterHeader decorates the RegisterHeader method of maroto instance. -func (m *metricsDecorator) RegisterHeader(rows ...core.Row) error { +func (m *MetricsDecorator) RegisterHeader(rows ...core.Row) error { var err error timeSpent := time.GetTimeSpent(func() { err = m.inner.RegisterHeader(rows...) @@ -87,7 +87,7 @@ func (m *metricsDecorator) RegisterHeader(rows ...core.Row) error { } // RegisterFooter decorates the RegisterFooter method of maroto instance. -func (m *metricsDecorator) RegisterFooter(rows ...core.Row) error { +func (m *MetricsDecorator) RegisterFooter(rows ...core.Row) error { var err error timeSpent := time.GetTimeSpent(func() { err = m.inner.RegisterFooter(rows...) @@ -97,7 +97,7 @@ func (m *metricsDecorator) RegisterFooter(rows ...core.Row) error { } // 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() { @@ -108,7 +108,7 @@ func (m *metricsDecorator) GetStructure() *node.Node[core.Structure] { 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 { @@ -179,7 +179,7 @@ func (m *metricsDecorator) buildMetrics(bytesSize int) *metrics.Report { } } -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 diff --git a/metricsdecorator_test.go b/metricsdecorator_test.go index c0408293..f8f71f83 100644 --- a/metricsdecorator_test.go +++ b/metricsdecorator_test.go @@ -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) {