Skip to content

Commit

Permalink
Remove duplicated font size
Browse files Browse the repository at this point in the history
  • Loading branch information
janiscw committed Mar 22, 2024
1 parent d47abdc commit 535d5d1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 90 deletions.
2 changes: 1 addition & 1 deletion src/Writers/PdfWriter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
98 changes: 9 additions & 89 deletions src/Writers/PdflibPdfWriter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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)) {
Expand Down Expand Up @@ -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);

Expand All @@ -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;
Expand Down Expand Up @@ -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}
*/
Expand Down Expand Up @@ -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}
*/
Expand Down

0 comments on commit 535d5d1

Please sign in to comment.