<commit_before>// Package PDF contains functionality to draw data onto a PDF and render said
// PDF to a file or string buffer.
package pdf

import (
	"bytes"
	"io"

	"github.com/jung-kurt/gofpdf"
)

// This is basically an interface to wrap gofpdf.Fpdf in.
type PdfDrawer interface {
	AddPage()
	SetError(err error)
	Output(w io.Writer) error
	Error() error
}

type Pdf interface {
	Bytes(buffer *bytes.Buffer) []byte
	Error() error
	Drawer() *gofpdf.Fpdf
	ParseBlocks(blocks []Block)
}

type EasyPdf struct {
	drawer *gofpdf.Fpdf
	Size   Size
}

func NewPdf(size Size) (pdf *EasyPdf) {
	init := &gofpdf.InitType{
		OrientationStr: size.Orientation(),
		UnitStr:        size.Unit(),
		Size:           gofpdf.SizeType{Wd: size.Width(), Ht: size.Height()},
	}
	f := gofpdf.NewCustom(init)
	f.AddPage()

	pdf = new(EasyPdf)
	pdf.drawer = f
	pdf.Size = size
	return
}

func (f *EasyPdf) Error() error {
	return f.Drawer().Error()
}

func (f *EasyPdf) Drawer() *gofpdf.Fpdf {
	return f.drawer
}

func (f *EasyPdf) ParseBlocks(blocks []Block) {
	blocks[0].Parse(f)
}

func (f *EasyPdf) Bytes(buffer *bytes.Buffer) []byte {
	err := f.Drawer().Output(buffer)

	if err != nil {
		f.Drawer().SetError(err)
		return nil
	}

	return buffer.Bytes()
}<commit_msg>Pdf: go through all blocks.<commit_after>// Package PDF contains functionality to draw data onto a PDF and render said
// PDF to a file or string buffer.
package pdf

import (
	"bytes"
	"io"

	"github.com/jung-kurt/gofpdf"
)

// This is basically an interface to wrap gofpdf.Fpdf in.
type PdfDrawer interface {
	AddPage()
	SetError(err error)
	Output(w io.Writer) error
	Error() error
}

type Pdf interface {
	Bytes(buffer *bytes.Buffer) []byte
	Error() error
	Drawer() *gofpdf.Fpdf
	ParseBlocks(blocks []Block)
}

type EasyPdf struct {
	drawer *gofpdf.Fpdf
	Size   Size
}

func NewPdf(size Size) (pdf *EasyPdf) {
	init := &gofpdf.InitType{
		OrientationStr: size.Orientation(),
		UnitStr:        size.Unit(),
		Size:           gofpdf.SizeType{Wd: size.Width(), Ht: size.Height()},
	}
	f := gofpdf.NewCustom(init)
	f.AddPage()

	pdf = new(EasyPdf)
	pdf.drawer = f
	pdf.Size = size
	return
}

func (f *EasyPdf) Error() error {
	return f.Drawer().Error()
}

func (f *EasyPdf) Drawer() *gofpdf.Fpdf {
	return f.drawer
}

func (f *EasyPdf) ParseBlocks(blocks []Block) {
	for _, block := range blocks {
		block.Parse(f)
	}
}

func (f *EasyPdf) Bytes(buffer *bytes.Buffer) []byte {
	err := f.Drawer().Output(buffer)

	if err != nil {
		f.Drawer().SetError(err)
		return nil
	}

	return buffer.Bytes()
}
{'fraction_non_alphanumeric': 0.1417910447761194, 'fraction_numerical': 0.00039277297721916735, 'mean_word_length': 3.656307129798903, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6360143', 'n_tokens_mistral': 1016, 'n_tokens_neox': 979, 'n_words': 264}