diff --git a/src/Writers/PdfWriter.php b/src/Writers/PdfWriter.php index 5e675fe..f98dbea 100644 --- a/src/Writers/PdfWriter.php +++ b/src/Writers/PdfWriter.php @@ -85,7 +85,7 @@ public function fromTemplatePage($pageNumber); public function closeTemplate(); /** - * Load fonts to use it with the writer. + * Load colors to use it with the writer. * * @param string $name * @param array $color diff --git a/src/Writers/PdflibPdfWriter.php b/src/Writers/PdflibPdfWriter.php index 57680ac..251bdf4 100644 --- a/src/Writers/PdflibPdfWriter.php +++ b/src/Writers/PdflibPdfWriter.php @@ -7,7 +7,6 @@ use Contoweb\Pdflib\Exceptions\DocumentException; use Contoweb\Pdflib\Exceptions\FontException; use Contoweb\Pdflib\Exceptions\ImageException; -use Contoweb\Pdflib\Exceptions\MeasureException; use Contoweb\Pdflib\Exceptions\TextException; use Contoweb\Pdflib\Helpers\MeasureCalculator; use Contoweb\Pdflib\WriterComponents\Table; @@ -98,28 +97,21 @@ class PdflibPdfWriter extends PDFlib implements PdfWriter * * @var */ - private $currentFont; + protected $currentFont; /** - * Currently set font size + * Current font size. * * @var integer */ - private $currentFontSize; + protected $fontSize; /** * Currently used text * * @var string */ - private $currentText; - - /** - * Current font size. - * - * @var - */ - private $fontSize; + protected $currentText; /** * Use offsets in positioning. @@ -319,6 +311,7 @@ public function loadFont($name, $encoding = null, $optlist = null) */ public function useFont($name, $size, $color = null) { + $this->currentFont = $this->fonts[$name]; $this->fontSize = $size; if (array_key_exists($name, $this->fonts)) { @@ -347,6 +340,8 @@ public function getFonts() */ public function writeText($text) { + $this->currentText = $text; + $this->set_text_pos($this->xPos, $this->yPos); $this->show($text); @@ -358,6 +353,8 @@ public function writeText($text) */ public function writeTextLine($text, $optlist = null) { + $this->currentText = $text; + $this->fit_textline($text, $this->xPos, $this->yPos, $optlist); return $this; @@ -387,46 +384,6 @@ public function getTextWidth($text, $font, $fontSize, $unit = null) return $textWidth; } - - /** - * Returns text length in pt with currently set font and font size - * - * @param string $text - * @param $font - * @param null $fontSize - * @param string $unit - * @return integer $fontSize - * @throws MeasureException - */ - public function getTextLength($text, $font = null, $fontSize = null, $unit = 'mm') - { - $textLength = $this->stringwidth($text, $font ?: $this->currentFont, $fontSize ?: $this->currentFontSize); - - return MeasureCalculator::calculateToUnit($textLength, $unit); - } - - /** - * Set a limit in length for currently used text and return an error when the limit is hit - * - * @param string $errorMessage - * @param integer $maxMeasure - * @param string $unit - * @return $this - * @throws MeasureException - */ - public function limitTextLength($errorMessage, $maxMeasure, $unit = 'mm') - { - $maxMeasure = MeasureCalculator::calculateToPt($maxMeasure, $unit); - - $textLength = $this->getTextLength($this->currentText, null, null, 'pt'); - - if ($textLength > $maxMeasure) { - abort(403, $errorMessage); - } - - return $this; - } - /** * {@inheritdoc} */ @@ -624,43 +581,6 @@ public function setYOffset($measure, $unit = null) return $this; } - - /** - * @param $measure - * @param string $unit - * @return float - * @throws MeasureException - */ - public function setLineOffset($measure, $unit = null) - { - $measure = MeasureCalculator::calculateToPt($measure, $unit ?: config('pdf.measurement.unit', 'pt')); - - $this->lineOffset = $measure; - - return $measure; - } - - /** - * Get the defined line offset and optionally calculate to pt. - * - * @param string $unit - * @return float - * @throws MeasureException - */ - public function getLineOffset($unit = null) - { - return MeasureCalculator::calculateToUnit($this->lineOffset, $unit ?: config('pdf.measurement.unit', 'pt')); - } - - /** - * Set y position to a new line by incrementing $this->yPos by defined $this->lineOffset - */ - public function addLine() - { - $this->setYPosition($this->yPos - $this->lineOffset, 'pt', true); - } - - /** * {@inheritdoc} */