<commit_before><?php
namespace UAM\Pdf;

$error_reporting = error_reporting(E_ALL & ~E_STRICT & ~E_NOTICE);

use \fpdi\FPDI;

include_once dirname(__FILE__) . '/../../../config/tcpdf_config.php';

class TCPDF extends FPDI
{
    protected $bottom_margin = 25;

    protected $letterhead;
    protected $letterhead_idx;

    protected $watermark = null;
    protected $watermark_font = array('Verdana', 'B', 58);
    protected $watermark_color = array(255, 205, 205);
    protected $watermark_cell_height = 10;

    protected $pagination_in_header = 'p. %page%/%pages%';
    protected $pagination_in_footer = false;
    protected $pagination_font = array('Verdana', '', 8);
    protected $pagination_x;
    protected $pagination_y;

    protected $document_title_font = 'Georgia';
    protected $document_title_size = 16;
    protected $document_title_style = 'B';
    protected $document_title_border = 'B';
    protected $document_title_align = 'C';
    protected $document_title_cell_height = 12;

    protected $title_font = 'Verdana';
    protected $title_size = 11;
    protected $title_style = 'B';
    protected $title_cell_height = 6;
    protected $title_align = 'L';

    protected $subtitle_font = 'Verdana';
    protected $subtitle_size = 11;
    protected $subtitle_style = 'B';
    protected $subtitle_cell_height = 6;


    protected $default_cell_padding = array('L' => 0.3, 'T' => 0.3, 'R' => 0.3, 'B' => 0.3);

    public function __construct($orientation = 'P', $unit = 'mm', $format = 'A4', $unicode = true, $encoding = 'UTF-8', $diskcache = false, $pdfa = false)
    {
        parent::__construct($orientation, $unit, $format, $unicode, $encoding, $diskcache, $pdfa);

        $this->init();
    }

    /**
     * Returns the name to be used by default for this document when output.
     *
     * When the Output method is called with a null $name parameter, this method
     * is invoked to supply a default document name.
     *
     * By default, this method simply returns 'doc'pdf'. Override this method
     * according to your requirements.
     */
    public function getName()
    {
        return 'doc.pdf';
    }

    /**
     * Returns the path to the file to be used as letterhead.
     */
    public function getLetterhead()
    {
        return $this->letterhead;
    }

    /**
     * Sets the path to the file to be used as letterhead.
     */
    public function setLetterhead($letterhead)
    {
        $this->letterhead = $letterhead;
    }

    /**
     * Returns the text to use as watermark.
     *
     * @return string
     */
    public function getWatermark()
    {
        return $this->watermark;
    }

    /**
     * Sets the text of the watermark.
     *
     * @param $watermark
     */
    public function setWatermark($watermark)
    {
        $this->watermark = $watermark;
    }

    public function getWatermarkFont()
    {
        return $this->watermark_font;
    }

    public function setWatermarkFont(array $font)
    {
        $this->watermark_font = $font;
    }

    public function getWatermarkColor()
    {
        return $this->watermark_color;
    }

    public function setWatermarkColor(array $color)
    {
        $this->watermark_color = $color;
    }

    /**
     * If not false or null, returns the format for the pagination in the page header.
     */
    public function getPaginationInHeader()
    {
        return $this->pagination_in_header;
    }

    /**
     * Sets the format for the pagination in the header, or null/false to cancel pagination in the header.
     */
    public function setPaginationInHeader($format = null)
    {
        $this->pagination_in_header = $format;
    }

    /**
     * If not false or null, returns the format for the pagination in the page footer.
     */
    public function getPaginationInFooter()
    {
        return $this->pagination_in_footer;
    }

    /**
     * Sets the format for the pagination in the footer, or null/false to cancel pagination in the footer.
     */
    public function setPaginationInFooter($format = null)
    {
        $this->pagination_in_footer = $format;
    }

    public function getPaginationFont()
    {
        return $this->pagination_font;
    }

    public function setPaginationFont(array $font)
    {
        $this->pagination_font = $font;
    }

    /**
     * Do not override. Override 'generate' method instead.
     *
     */
    public function Output($name = null, $dest = 'D')
    {
        $this->init();

        $this->AddPage();

        $this->generate();

        parent::Output($name ? $name : $this->getName(), $dest);

        header_remove('Content-Length');
    }

    /**
     * Generates the header.
     *
     *
     */
    public function Header()
    {
        $this->addLetterhead();
        $this->addWatermark();

        $this->SetY(max($this->GetY(), $this->getHeaderMargin()));
        $this->printPageHeader();

        if ($this->getPaginationInHeader()) {
            $this->paginate();
        }
    }

    public function Footer()
    {
        $cur_y = $this->y;

        $this->SetTextColorArray($this->footer_text_color);

        $this->printPageFooter();

        if ($this->getPaginationInFooter()) {
            $this->paginate();
        }

        $this->SetY($cur_y);
    }

    public function resetFont()
    {
        $this->SetFont($this->FontFamily, $this->FontStyle, $this->FontSizePt);
    }

    /*
    public function MultiCell($w, $h, $txt, $border=0, $align='J', $fill=false, $ln=1, $x='', $y='', $reseth=true, $stretch=0, $ishtml=false, $autopadding=true, $maxh=0, $valign='T', $fitcell=false)
    {
        $old_cell_padding = $this->GetCellPaddings();
        $this->setCellPaddings($this->default_cell_padding['L'],
                                                     $this->default_cell_padding['T'],
                                                     $this->default_cell_padding['R'],
                                                     $this->default_cell_padding['B']);
        parent::MultiCell($w, $h, $txt, $border, $align, $fill, $ln, $x, $y, $reseth, $stretch, $ishtml, $autopadding, $maxh, $valign, $fitcell);
        $this->SetCellPaddings($old_cell_padding['L'], $old_cell_padding['T'], $old_cell_padding['R'], $old_cell_padding['B']);
    }
    */

    protected function init()
    {
        $this->SetAutoPageBreak(true, $this->bottom_margin);
    }

    protected function generate() {}

    /**
     * Adds the document;s letterhead.
     */
    protected function addLetterhead()
    {
        $letterhead = $this->getLetterhead();

        if (!$letterhead || !file_exists($letterhead) || is_dir($letterhead)) {
            return;
        }

        if (is_null($this->letterhead_idx)) {
            $this->setSourceFile($letterhead);
            $this->letterhead_idx = $this->importPage(1);
        }

        $this->useTemplate($this->letterhead_idx);
    }

    /**
     * Prints the document's watermark.
     * TODO [OP 2013-12-29] Add rtl support
     * TODO [OP 2013-12-29] Use XObject template
     */
    protected function addWatermark()
    {
        $watermark = $this->getWatermark();

        if (!is_array($watermark) || empty($watermark)) {
            return;
        }

        $color = $this->TextColor;
        $x = $this->GetX();
        $y = $this->getY();

        $font = $this->getWatermarkFont();

        $this->SetFont($font[0], $font[1], $font[2]);

        $this->SetTextColorArray($this->getWatermarkColor());

        $this->setXY($this->lMargin, $this->h - $this->bMargin);

        $this->StartTransform();

        if ($this->CurOrientation == 'P') {
            $this->Rotate(60);
            $w = $this->w * 1.5;
        } else {
            $this->Rotate(30);
            $w = $this->h * 1.5;
        }

        $this->MultiCell(
            $w,
            $this->watermark_cell,
            $watermark,
            0, 'C', 0, 0
        );

        $this->StopTransform();

        $this->SetXY($x, $y);
        $this->resetFont();
        $this->TextColor = $color;
    }

    protected function printPageHeader()
    {

    }

    protected function printPageFooter()
    {

    }

    protected function paginate()
    {
        // save current graphic settings
        $gvars = $this->getGraphicVars();

        $font = $this->getPaginationFont();

        $this->SetFont($font[0], $font[1], $font[2]);

        $this->SetX(
            $this->pagination_x
            ? $this->pagination_x
            : ($this->getRTL() ? $this->original_rMargin : $this->original_lMargin)
        );

        if ($this->pagination_y) {

            $this->SetY($this->pagination_y);

        } elseif ($this->InHeader) {

            $this->SetY(max($this->getHeaderMargin(), $this->GetY()));

        } else if ($this->InFooter) {

            $this->SetY($this->h - $this->footer_margin);

        }

        if ($this->getRTL()) {
            $this->Cell(0, 0, $this->getPagination(), 0, 0, 'L');
        } else {
            $this->Cell(0, 0, $this->getAliasRightShift() . $this->getPagination(), 0, 0, 'R');
        }

        // restore graphic settings
        $this->setGraphicVars($gvars);
    }

    protected function getPagination()
    {
        $params = empty($this->pagegroups)
            ? array(
                '%page%' => $this->getAliasNumPage(),
                '%pages%' => $this->getAliasNbPages()
            )
            : array(
                '%page%' => $this->getPageNumGroupAlias(),
                '%pages%' => $this->getPageGroupAlias()
            );

        return strtr(
            $this->InHeader
                ? $this->getPaginationInHeader()
                : $this->getPaginationInFooter(),
            $params
        );
    }

    protected function _cell($s, $link = '')
    {
        $this->Cell($this->getStringWidth($s), 0, $s, 0, 0, 'L', 0, $link);
    }

    //public function getCellPadding() { return $this->cMargin; }

    public function printDocumentTitle()
    {
        if (empty($this->title)) { return; }
        $font = $this->getFontFamily();
        $style = $this->getFontStyle();
        $size = $this->getFontSize();
        $this->SetFont($this->document_title_font, $this->document_title_style, $this->document_title_size);
        $this->MultiCell(0, $this->document_title_cell_height, $this->title, $this->document_title_border, $this->document_title_align, 0, 1);
        $this->SetFont($font, $style, $size);
    }

    public function printTitle($title)
    {
        $this->SetFont($this->title_font, $this->title_style, $this->title_size);
        $this->MultiCell(0, $this->title_cell_height, $title, 0, $this->title_align, 0, 1);
        $this->resetFont();
    }

    public function printText($text, $multiline = false)
    {
        $this->resetFont();
        if (!$multiline) {
            $this->Cell(0, 0, $text, 0, 1, 'L');
        } else {
            $this->MultiCell(0, 0, $text, '', 'L', 0, 1);
        }
    }
<commit_msg>fixed printDocumentTitle method<commit_after><?php
namespace UAM\Pdf;

$error_reporting = error_reporting(E_ALL & ~E_STRICT & ~E_NOTICE);

use \fpdi\FPDI;

include_once dirname(__FILE__) . '/../../../config/tcpdf_config.php';

class TCPDF extends FPDI
{
    protected $bottom_margin = 25;

    protected $letterhead;
    protected $letterhead_idx;

    protected $watermark = null;
    protected $watermark_font = array('Verdana', 'B', 58);
    protected $watermark_color = array(255, 205, 205);
    protected $watermark_cell_height = 10;

    protected $pagination_in_header = 'p. %page%/%pages%';
    protected $pagination_in_footer = false;
    protected $pagination_font = array('Verdana', '', 8);
    protected $pagination_x;
    protected $pagination_y;

    protected $document_title_font = array('Georgia', 'B', 16);
    protected $document_title_border = 'B';
    protected $document_title_align = 'C';
    protected $document_title_cell_height = 12;

    protected $title_font = 'Verdana';
    protected $title_size = 11;
    protected $title_style = 'B';
    protected $title_cell_height = 6;
    protected $title_align = 'L';

    protected $subtitle_font = 'Verdana';
    protected $subtitle_size = 11;
    protected $subtitle_style = 'B';
    protected $subtitle_cell_height = 6;


    protected $default_cell_padding = array('L' => 0.3, 'T' => 0.3, 'R' => 0.3, 'B' => 0.3);

    public function __construct($orientation = 'P', $unit = 'mm', $format = 'A4', $unicode = true, $encoding = 'UTF-8', $diskcache = false, $pdfa = false)
    {
        parent::__construct($orientation, $unit, $format, $unicode, $encoding, $diskcache, $pdfa);

        $this->init();
    }

    /**
     * Returns the name to be used by default for this document when output.
     *
     * When the Output method is called with a null $name parameter, this method
     * is invoked to supply a default document name.
     *
     * By default, this method simply returns 'doc'pdf'. Override this method
     * according to your requirements.
     */
    public function getName()
    {
        return 'doc.pdf';
    }

    /**
     * Returns the path to the file to be used as letterhead.
     */
    public function getLetterhead()
    {
        return $this->letterhead;
    }

    /**
     * Sets the path to the file to be used as letterhead.
     */
    public function setLetterhead($letterhead)
    {
        $this->letterhead = $letterhead;
    }

    /**
     * Returns the text to use as watermark.
     *
     * @return string
     */
    public function getWatermark()
    {
        return $this->watermark;
    }

    /**
     * Sets the text of the watermark.
     *
     * @param $watermark
     */
    public function setWatermark($watermark)
    {
        $this->watermark = $watermark;
    }

    public function getWatermarkFont()
    {
        return $this->watermark_font;
    }

    public function setWatermarkFont(array $font)
    {
        $this->watermark_font = $font;
    }

    public function getWatermarkColor()
    {
        return $this->watermark_color;
    }

    public function setWatermarkColor(array $color)
    {
        $this->watermark_color = $color;
    }

    /**
     * If not false or null, returns the format for the pagination in the page header.
     */
    public function getPaginationInHeader()
    {
        return $this->pagination_in_header;
    }

    /**
     * Sets the format for the pagination in the header, or null/false to cancel pagination in the header.
     */
    public function setPaginationInHeader($format = null)
    {
        $this->pagination_in_header = $format;
    }

    /**
     * If not false or null, returns the format for the pagination in the page footer.
     */
    public function getPaginationInFooter()
    {
        return $this->pagination_in_footer;
    }

    /**
     * Sets the format for the pagination in the footer, or null/false to cancel pagination in the footer.
     */
    public function setPaginationInFooter($format = null)
    {
        $this->pagination_in_footer = $format;
    }

    public function getPaginationFont()
    {
        return $this->pagination_font;
    }

    public function setPaginationFont(array $font)
    {
        $this->pagination_font = $font;
    }

    public function getDocumentTitleFont()
    {
        return $this->document_title_font;
    }

    public function setDocumentTitleFont(array $font)
    {
        $this->document_title_font = $font;
    }

    public function getDocumentTitleBorder()
    {
        return $this->document_title_border;
    }

    public function setDocumentTitleBorder($border)
    {
        $this->document_title_border = $border;
    }

    public function getDocumentTitleAlign()
    {
        return $this->document_title_align;
    }

    public function setDocumentTitleAlign($align)
    {
        $this->document_title_align = $align;
    }

    public function getDocumentTitleCellHeight()
    {
        return $this->document_title_cell_height;
    }

    public function setDocumentTitleCellHeight($height)
    {
        $this->document_title_cell_height = $height;
    }
    /**
     * Do not override. Override 'generate' method instead.
     *
     */
    public function Output($name = null, $dest = 'D')
    {
        $this->init();

        $this->AddPage();

        $this->generate();

        parent::Output($name ? $name : $this->getName(), $dest);

        header_remove('Content-Length');
    }

    /**
     * Generates the header.
     *
     *
     */
    public function Header()
    {
        $this->addLetterhead();
        $this->addWatermark();

        $this->SetY(max($this->GetY(), $this->getHeaderMargin()));
        $this->printPageHeader();

        if ($this->getPaginationInHeader()) {
            $this->paginate();
        }
    }

    public function Footer()
    {
        $cur_y = $this->y;

        $this->SetTextColorArray($this->footer_text_color);

        $this->printPageFooter();

        if ($this->getPaginationInFooter()) {
            $this->paginate();
        }

        $this->SetY($cur_y);
    }

    public function resetFont()
    {
        $this->SetFont($this->FontFamily, $this->FontStyle, $this->FontSizePt);
    }

    /*
    public function MultiCell($w, $h, $txt, $border=0, $align='J', $fill=false, $ln=1, $x='', $y='', $reseth=true, $stretch=0, $ishtml=false, $autopadding=true, $maxh=0, $valign='T', $fitcell=false)
    {
        $old_cell_padding = $this->GetCellPaddings();
        $this->setCellPaddings($this->default_cell_padding['L'],
                                                     $this->default_cell_padding['T'],
                                                     $this->default_cell_padding['R'],
                                                     $this->default_cell_padding['B']);
        parent::MultiCell($w, $h, $txt, $border, $align, $fill, $ln, $x, $y, $reseth, $stretch, $ishtml, $autopadding, $maxh, $valign, $fitcell);
        $this->SetCellPaddings($old_cell_padding['L'], $old_cell_padding['T'], $old_cell_padding['R'], $old_cell_padding['B']);
    }
    */

    protected function init()
    {
        $this->SetAutoPageBreak(true, $this->bottom_margin);
    }

    protected function generate() {}

    /**
     * Adds the document;s letterhead.
     */
    protected function addLetterhead()
    {
        $letterhead = $this->getLetterhead();

        if (!$letterhead || !file_exists($letterhead) || is_dir($letterhead)) {
            return;
        }

        if (is_null($this->letterhead_idx)) {
            $this->setSourceFile($letterhead);
            $this->letterhead_idx = $this->importPage(1);
        }

        $this->useTemplate($this->letterhead_idx);
    }

    /**
     * Prints the document's watermark.
     * TODO [OP 2013-12-29] Add rtl support
     * TODO [OP 2013-12-29] Use XObject template
     */
    protected function addWatermark()
    {
        $watermark = $this->getWatermark();

        if (!is_array($watermark) || empty($watermark)) {
            return;
        }

        $color = $this->TextColor;
        $x = $this->GetX();
        $y = $this->getY();

        $font = $this->getWatermarkFont();

        $this->SetFont($font[0], $font[1], $font[2]);

        $this->SetTextColorArray($this->getWatermarkColor());

        $this->setXY($this->lMargin, $this->h - $this->bMargin);

        $this->StartTransform();

        if ($this->CurOrientation == 'P') {
            $this->Rotate(60);
            $w = $this->w * 1.5;
        } else {
            $this->Rotate(30);
            $w = $this->h * 1.5;
        }

        $this->MultiCell(
            $w,
            $this->watermark_cell,
            $watermark,
            0, 'C', 0, 0
        );

        $this->StopTransform();

        $this->SetXY($x, $y);
        $this->resetFont();
        $this->TextColor = $color;
    }

    protected function printPageHeader()
    {

    }

    protected function printPageFooter()
    {

    }

    protected function paginate()
    {
        // save current graphic settings
        $gvars = $this->getGraphicVars();

        $font = $this->getPaginationFont();

        $this->SetFont($font[0], $font[1], $font[2]);

        $this->SetX(
            $this->pagination_x
            ? $this->pagination_x
            : ($this->getRTL() ? $this->original_rMargin : $this->original_lMargin)
        );

        if ($this->pagination_y) {

            $this->SetY($this->pagination_y);

        } elseif ($this->InHeader) {

            $this->SetY(max($this->getHeaderMargin(), $this->GetY()));

        } else if ($this->InFooter) {

            $this->SetY($this->h - $this->footer_margin);

        }

        if ($this->getRTL()) {
            $this->Cell(0, 0, $this->getPagination(), 0, 0, 'L');
        } else {
            $this->Cell(0, 0, $this->getAliasRightShift() . $this->getPagination(), 0, 0, 'R');
        }

        // restore graphic settings
        $this->setGraphicVars($gvars);
    }

    protected function getPagination()
    {
        $params = empty($this->pagegroups)
            ? array(
                '%page%' => $this->getAliasNumPage(),
                '%pages%' => $this->getAliasNbPages()
            )
            : array(
                '%page%' => $this->getPageNumGroupAlias(),
                '%pages%' => $this->getPageGroupAlias()
            );

        return strtr(
            $this->InHeader
                ? $this->getPaginationInHeader()
                : $this->getPaginationInFooter(),
            $params
        );
    }

    protected function _cell($s, $link = '')
    {
        $this->Cell($this->getStringWidth($s), 0, $s, 0, 0, 'L', 0, $link);
    }

    //public function getCellPadding() { return $this->cMargin; }

    public function printDocumentTitle()
    {
        $title = $this->getDocumentTitle();

        if (empty($title)) {
            return;
        }

        // save current graphic settings
        $gvars = $this->getGraphicVars();

        $font = $this->getDocumentTitleFont();

        $this->SetFont($font[0], $font[1], $font[2]);

        $this->MultiCell(
            0,
            $this->getDocumentTitleCellHeight(),
            $title,
            $this->getDocumentTitleBorder(),
            $this->getDocumentTitleAlign(),
            0,
            1
        );

        // restore graphic settings
        $this->setGraphicVars($gvars);
    }

    public function printTitle($title)
    {
        $this->SetFont($this->title_font, $this->title_style, $this->title_size);
        $this->MultiCell(0, $this->title_cell_height, $title, 0, $this->title_align, 0, 1);
        $this->resetFont();
    }

    public function printText($text, $multiline = false)
    {
        $this->resetFont();
        if (!$multiline) {
            $this->Cell(0, 0, $text, 0, 1, 'L');
        } else {
            $this->MultiCell(0, 0, $text, '', 'L', 0, 1);
        }
    }

{'fraction_non_alphanumeric': 0.1483514090334945, 'fraction_numerical': 0.008928960320571453, 'mean_word_length': 2.152547027323905, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 304, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7620464', 'n_tokens_mistral': 7314, 'n_tokens_neox': 7076, 'n_words': 1467}