Skip to content

Commit

Permalink
add support of PHP 8.1 and PHP 8.2
Browse files Browse the repository at this point in the history
  • Loading branch information
spipu committed Jan 27, 2023
1 parent c002749 commit e258a36
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 67 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ php:
- 7.4
- 8.0
- 8.1
- 8.2

before_script:
- composer selfupdate
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

All notable changes to this project will be documented in this file.

## [5.2.6](https://github.com/spipu/html2pdf/compare/v5.2.5...v5.2.6) - 2023-01-28

* add support of PHP 8.1 and PHP 8.2
* remove useless files

## [5.2.5](https://github.com/spipu/html2pdf/compare/v5.2.4...v5.2.5) - 2022-04-04

* fix security on scheme of css and image paths for windows paths
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Html2Pdf

Html2Pdf is a HTML to PDF converter written in PHP, and compatible with PHP **5.6** to **8.0**.
Html2Pdf is a HTML to PDF converter written in PHP, and compatible with PHP **5.6** to **8.2**.

It allows the conversion of valid HTML in PDF format, to generate documents like invoices, documentation, ...

Expand Down
13 changes: 9 additions & 4 deletions src/Html2Pdf.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ class Html2Pdf
protected $_encoding = ''; // charset encoding
protected $_unicode = true; // means that the input text is unicode (default = true)

/**
* @var bool
*/
protected $_pdfa;

protected $_testTdInOnepage = true; // test of TD that can not take more than one page
protected $_testIsImage = true; // test if the images exist or not
protected $_fallbackImage = null; // fallback image to use in img tags
Expand Down Expand Up @@ -242,7 +247,7 @@ public function getVersionAsArray()
return array(
'major' => 5,
'minor' => 2,
'revision' => 4
'revision' => 6
);
}

Expand Down Expand Up @@ -1021,7 +1026,7 @@ protected function _setNewPositionForNewLine($curr = null)

// if subPart => return because align left
if ($this->_subPart || $this->_isSubPart || $this->_isForOneLine) {
$this->pdf->setWordSpacing(0);
$this->pdf->setWordSpacing(0.);
return null;
}

Expand Down Expand Up @@ -1073,9 +1078,9 @@ protected function _setNewPositionForNewLine($curr = null)

// if justify => set the word spacing
if ($this->parsingCss->value['text-align'] === 'justify' && $e>1) {
$this->pdf->setWordSpacing(($wMax-$w)/($e-1));
$this->pdf->setWordSpacing((float) ($wMax - $w) / (float) ($e - 1.));
} else {
$this->pdf->setWordSpacing(0);
$this->pdf->setWordSpacing(0.);
}
}

Expand Down
37 changes: 21 additions & 16 deletions src/MyPdf.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@
namespace Spipu\Html2Pdf;

use Spipu\Html2Pdf\Exception\HtmlParsingException;
use TCPDF;

class MyPdf extends \TCPDF
class MyPdf extends TCPDF
{
protected $_footerParam = array();
protected $_transf = array();
Expand All @@ -24,9 +25,14 @@ class MyPdf extends \TCPDF
// used to make a radius with bezier : (4/3 * (sqrt(2) - 1))
const MY_ARC = 0.5522847498;

// nb of segment to build a arc with bezier curv
// nb of segment to build an arc with bezier curv
const ARC_NB_SEGMENT = 8;

/**
* @var float
*/
protected $ws = 0.;

/**
* class constructor
*
Expand Down Expand Up @@ -132,8 +138,8 @@ public function Footer()
}

/**
* after cloning a object, we does not want to clone all the front informations
* because it take a lot a time and a lot of memory => we use reference
* after cloning an object, we do not want to clone all the front information
* because it takes a lot a time and a lot of memory => we use reference
*
* @param myPdf &$pdf
* @access public
Expand All @@ -155,7 +161,7 @@ public function cloneFontFrom(&$pdf)
* multiple public accessor for some private attributs
* used only by cloneFontFrom
*
* @return &array
* @return array
* @access public
*/
public function &getFonts()
Expand Down Expand Up @@ -198,7 +204,7 @@ public function &getN()
/**
* Verify that a Font is already loaded
*
* @param string Font Key
* @param string $fontKey Font Key
* @return boolean
* @access public
*/
Expand Down Expand Up @@ -229,7 +235,7 @@ public function getWordSpacing()
/**
* set the Word Spacing
*
* @param float word spacing
* @param float $ws word spacing
* @access public
*/
public function setWordSpacing($ws = 0.)
Expand Down Expand Up @@ -534,8 +540,8 @@ public function stopTransform()
/**
* add a Translate transformation
*
* @param float $Tx
* @param float $Ty
* @param $xT
* @param $yT
* @access public
*/
public function setTranslate($xT, $yT)
Expand All @@ -556,8 +562,8 @@ public function setTranslate($xT, $yT)
* add a Rotate transformation
*
* @param float $angle
* @param float $Cx
* @param float $Cy
* @param float|null $xC
* @param float|null $yC
* @access public
*/
public function setRotation($angle, $xC = null, $yC = null)
Expand Down Expand Up @@ -653,7 +659,6 @@ public function SetXY($x, $y, $rtloff = false)
/**
* multiple public accessor because Html2Pdf need to use TCPDF without being a extend of it
*
* @param mixed
* @return mixed
* @access public
*/
Expand Down Expand Up @@ -1065,7 +1070,7 @@ protected function _Curve($x1, $y1, $x2, $y2, $xf, $yf, $trans = false)
* @param float $rx
* @param float $ry
* @param float $angleBegin in radians
* @param float $angleEng in radians
* @param float $angleEnd in radians
* @param boolean $direction
* @param boolean $drawFirst, true => add the first point
* @param boolean $trans apply transformation
Expand Down Expand Up @@ -1182,7 +1187,7 @@ protected function _Arc2($x1, $y1, $x2, $y2, $rx, $ry, $angle = 0., $l = 0, $s =
// if |vector| is Null, or if |vector| > 2 : impossible to make a arc => Line
if ($v['D'] == 0 || $v['D']>4) {
$this->_Line($x2, $y2, $trans);
return false;
return;
}

// convert paramters for make a arc with Center, Radius, from angleBegin to angleEnd
Expand Down Expand Up @@ -1432,7 +1437,7 @@ public function createIndex(

//Filling dots
$w=$this->w-$this->lMargin-$this->rMargin-$pageCellSize-($level*8)-($strsize+2);
$nb=$w/$this->GetStringWidth('.');
$nb = (int) ($w/$this->GetStringWidth('.'));
$dots=str_repeat('.', $nb);
$this->Cell($w, $this->FontSize+2, $dots, 0, 0, 'R');

Expand Down Expand Up @@ -1490,7 +1495,7 @@ public function getMyNumPage($page = null)
* Start a new group of pages
*
* @access public
* @return integer;
* @return void
* @see tcpdf::startPageGroup
*/
public function myStartPageGroup()
Expand Down
23 changes: 19 additions & 4 deletions src/Tests/Html2PdfTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,16 @@

namespace Spipu\Html2Pdf\Tests;

use Spipu\Html2Pdf\Tag\AbstractTag;

/**
* Class Html2PdfTest
*/
class Html2PdfTest extends AbstractTest
{
public function testExtensionTag()
{
$tag = $this->createMock('Spipu\Html2Pdf\Tag\TagInterface');
$tag->expects($this->any())->method('getName')->willReturn('test_tag');
$tag->expects($this->exactly(4))->method('open');
$tag->expects($this->exactly(2))->method('close');
$tag = new testTag();

$extension = $this->createMock('Spipu\Html2Pdf\Extension\ExtensionInterface');
$extension->expects($this->any())->method('getName')->willReturn('test');
Expand Down Expand Up @@ -43,3 +42,19 @@ public function testSecurityKo()
$object->writeHTML('<div><img src="phar://test.com/php.phar" alt="" /></div>');
}
}

class testTag extends AbstractTag
{
public function getName()
{
return 'test_tag';
}

public function open($properties)
{
}

public function close($properties)
{
}
}
26 changes: 0 additions & 26 deletions test/generate.ps1

This file was deleted.

16 changes: 0 additions & 16 deletions test/generate.sh

This file was deleted.

0 comments on commit e258a36

Please sign in to comment.