vendor: Upgrade dompdf to v2.0.1
This commit is contained in:
parent
a6af690040
commit
bb54956dbb
|
@ -0,0 +1,24 @@
|
|||
Dompdf was designed and developed by Benj Carson.
|
||||
|
||||
### Current Team
|
||||
|
||||
* **Brian Sweeney** (maintainer)
|
||||
* **Till Berger**
|
||||
|
||||
### Alumni
|
||||
|
||||
* **Benj Carson** (creator)
|
||||
* **Fabien Ménager**
|
||||
* **Simon Berger**
|
||||
* **Orion Richardson**
|
||||
|
||||
### Contributors
|
||||
* **Gabriel Bull**
|
||||
* **Barry vd. Heuvel**
|
||||
* **Ryan H. Masten**
|
||||
* **Helmut Tischer**
|
||||
* [and many more...](https://github.com/dompdf/dompdf/graphs/contributors)
|
||||
|
||||
### Thanks
|
||||
|
||||
Dompdf would not have been possible without strong community support.
|
|
@ -214,12 +214,6 @@ Files accessed through the local file system have the following requirement:
|
|||
|
||||
## Limitations (Known Issues)
|
||||
|
||||
* Dompdf is not particularly tolerant to poorly-formed HTML input. To avoid
|
||||
any unexpected rendering issues you should either enable the built-in HTML5
|
||||
parser at runtime (`$options->setIsHtml5ParserEnabled(true);`)
|
||||
or run your HTML through a HTML validator/cleaner (such as
|
||||
[Tidy](http://tidy.sourceforge.net) or the
|
||||
[W3C Markup Validation Service](http://validator.w3.org)).
|
||||
* Table cells are not pageable, meaning a table row must fit on a single page.
|
||||
* Elements are rendered on the active page when they are parsed.
|
||||
* Embedding "raw" SVG's (`<svg><path...></svg>`) isn't working yet, you need to
|
||||
|
@ -228,7 +222,8 @@ Files accessed through the local file system have the following requirement:
|
|||
$html = '<img src="data:image/svg+xml;base64,' . base64_encode($svg) . '" ...>';
|
||||
```
|
||||
Watch https://github.com/dompdf/dompdf/issues/320 for progress
|
||||
|
||||
* Does not support CSS flexbox.
|
||||
* Does not support CSS Grid.
|
||||
---
|
||||
|
||||
[![Donate button](https://www.paypal.com/en_US/i/btn/btn_donate_SM.gif)](http://goo.gl/DSvWf)
|
||||
|
|
|
@ -1 +1 @@
|
|||
1.2.1
|
||||
2.0.1
|
||||
|
|
|
@ -1,40 +1 @@
|
|||
<?php
|
||||
/**
|
||||
* @package dompdf
|
||||
* @link http://dompdf.github.com/
|
||||
* @author Benj Carson <benjcarson@digitaljunkies.ca>
|
||||
* @author Fabien Ménager <fabien.menager@gmail.com>
|
||||
* @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
|
||||
*/
|
||||
|
||||
// HMLT5 Parser
|
||||
//FIXME: replace with masterminds HTML5
|
||||
//require_once __DIR__ . '/lib/html5lib/Parser.php';
|
||||
|
||||
// Sabberworm
|
||||
spl_autoload_register(function($class)
|
||||
{
|
||||
if (strpos($class, 'Sabberworm') !== false) {
|
||||
$file = str_replace('\\', DIRECTORY_SEPARATOR, $class);
|
||||
$file = realpath(__DIR__ . '/lib/php-css-parser/lib/' . (empty($file) ? '' : DIRECTORY_SEPARATOR) . $file . '.php');
|
||||
if (file_exists($file)) {
|
||||
require_once $file;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
});
|
||||
|
||||
// php-font-lib
|
||||
require_once __DIR__ . '/lib/php-font-lib/src/FontLib/Autoloader.php';
|
||||
|
||||
//php-svg-lib
|
||||
require_once __DIR__ . '/lib/php-svg-lib/src/autoload.php';
|
||||
|
||||
|
||||
/*
|
||||
* New PHP 5.3.0 namespaced autoloader
|
||||
*/
|
||||
require_once __DIR__ . '/src/Autoloader.php';
|
||||
|
||||
Dompdf\Autoloader::register();
|
||||
<?php require (__DIR__ . '/vendor/autoload.php');
|
|
@ -1,97 +0,0 @@
|
|||
<?php
|
||||
return function ($rootDir) {
|
||||
$distFontDir = $rootDir . '/lib/fonts';
|
||||
return [
|
||||
'sans-serif' =>
|
||||
[
|
||||
'normal' => $distFontDir . '/Helvetica',
|
||||
'bold' => $distFontDir . '/Helvetica-Bold',
|
||||
'italic' => $distFontDir . '/Helvetica-Oblique',
|
||||
'bold_italic' => $distFontDir . '/Helvetica-BoldOblique'
|
||||
],
|
||||
'times' =>
|
||||
[
|
||||
'normal' => $distFontDir . '/Times-Roman',
|
||||
'bold' => $distFontDir . '/Times-Bold',
|
||||
'italic' => $distFontDir . '/Times-Italic',
|
||||
'bold_italic' => $distFontDir . '/Times-BoldItalic'
|
||||
],
|
||||
'times-roman' =>
|
||||
[
|
||||
'normal' => $distFontDir . '/Times-Roman',
|
||||
'bold' => $distFontDir . '/Times-Bold',
|
||||
'italic' => $distFontDir . '/Times-Italic',
|
||||
'bold_italic' => $distFontDir . '/Times-BoldItalic'
|
||||
],
|
||||
'courier' =>
|
||||
[
|
||||
'normal' => $distFontDir . '/Courier',
|
||||
'bold' => $distFontDir . '/Courier-Bold',
|
||||
'italic' => $distFontDir . '/Courier-Oblique',
|
||||
'bold_italic' => $distFontDir . '/Courier-BoldOblique'
|
||||
],
|
||||
'helvetica' =>
|
||||
[
|
||||
'normal' => $distFontDir . '/Helvetica',
|
||||
'bold' => $distFontDir . '/Helvetica-Bold',
|
||||
'italic' => $distFontDir . '/Helvetica-Oblique',
|
||||
'bold_italic' => $distFontDir . '/Helvetica-BoldOblique'
|
||||
],
|
||||
'zapfdingbats' =>
|
||||
[
|
||||
'normal' => $distFontDir . '/ZapfDingbats',
|
||||
'bold' => $distFontDir . '/ZapfDingbats',
|
||||
'italic' => $distFontDir . '/ZapfDingbats',
|
||||
'bold_italic' => $distFontDir . '/ZapfDingbats'
|
||||
],
|
||||
'symbol' =>
|
||||
[
|
||||
'normal' => $distFontDir . '/Symbol',
|
||||
'bold' => $distFontDir . '/Symbol',
|
||||
'italic' => $distFontDir . '/Symbol',
|
||||
'bold_italic' => $distFontDir . '/Symbol'
|
||||
],
|
||||
'serif' =>
|
||||
[
|
||||
'normal' => $distFontDir . '/Times-Roman',
|
||||
'bold' => $distFontDir . '/Times-Bold',
|
||||
'italic' => $distFontDir . '/Times-Italic',
|
||||
'bold_italic' => $distFontDir . '/Times-BoldItalic'
|
||||
],
|
||||
'monospace' =>
|
||||
[
|
||||
'normal' => $distFontDir . '/Courier',
|
||||
'bold' => $distFontDir . '/Courier-Bold',
|
||||
'italic' => $distFontDir . '/Courier-Oblique',
|
||||
'bold_italic' => $distFontDir . '/Courier-BoldOblique'
|
||||
],
|
||||
'fixed' =>
|
||||
[
|
||||
'normal' => $distFontDir . '/Courier',
|
||||
'bold' => $distFontDir . '/Courier-Bold',
|
||||
'italic' => $distFontDir . '/Courier-Oblique',
|
||||
'bold_italic' => $distFontDir . '/Courier-BoldOblique'
|
||||
],
|
||||
'dejavu sans' =>
|
||||
[
|
||||
'bold' => $distFontDir . '/DejaVuSans-Bold',
|
||||
'bold_italic' => $distFontDir . '/DejaVuSans-BoldOblique',
|
||||
'italic' => $distFontDir . '/DejaVuSans-Oblique',
|
||||
'normal' => $distFontDir . '/DejaVuSans'
|
||||
],
|
||||
'dejavu sans mono' =>
|
||||
[
|
||||
'bold' => $distFontDir . '/DejaVuSansMono-Bold',
|
||||
'bold_italic' => $distFontDir . '/DejaVuSansMono-BoldOblique',
|
||||
'italic' => $distFontDir . '/DejaVuSansMono-Oblique',
|
||||
'normal' => $distFontDir . '/DejaVuSansMono'
|
||||
],
|
||||
'dejavu serif' =>
|
||||
[
|
||||
'bold' => $distFontDir . '/DejaVuSerif-Bold',
|
||||
'bold_italic' => $distFontDir . '/DejaVuSerif-BoldItalic',
|
||||
'italic' => $distFontDir . '/DejaVuSerif-Italic',
|
||||
'normal' => $distFontDir . '/DejaVuSerif'
|
||||
]
|
||||
];
|
||||
};
|
|
@ -1,123 +0,0 @@
|
|||
<?php
|
||||
|
||||
// warning: this file is encoded in UTF-8!
|
||||
|
||||
class HTML5_Data
|
||||
{
|
||||
|
||||
// at some point this should be moved to a .ser file. Another
|
||||
// possible optimization is to give UTF-8 bytes, not Unicode
|
||||
// codepoints
|
||||
// XXX: Not quite sure why it's named this; this is
|
||||
// actually the numeric entity dereference table.
|
||||
protected static $realCodepointTable = [
|
||||
0x00 => 0xFFFD, // REPLACEMENT CHARACTER
|
||||
0x0D => 0x000A, // LINE FEED (LF)
|
||||
0x80 => 0x20AC, // EURO SIGN ('€')
|
||||
0x81 => 0x0081, // <control>
|
||||
0x82 => 0x201A, // SINGLE LOW-9 QUOTATION MARK ('‚')
|
||||
0x83 => 0x0192, // LATIN SMALL LETTER F WITH HOOK ('ƒ')
|
||||
0x84 => 0x201E, // DOUBLE LOW-9 QUOTATION MARK ('„')
|
||||
0x85 => 0x2026, // HORIZONTAL ELLIPSIS ('…')
|
||||
0x86 => 0x2020, // DAGGER ('†')
|
||||
0x87 => 0x2021, // DOUBLE DAGGER ('‡')
|
||||
0x88 => 0x02C6, // MODIFIER LETTER CIRCUMFLEX ACCENT ('ˆ')
|
||||
0x89 => 0x2030, // PER MILLE SIGN ('‰')
|
||||
0x8A => 0x0160, // LATIN CAPITAL LETTER S WITH CARON ('Š')
|
||||
0x8B => 0x2039, // SINGLE LEFT-POINTING ANGLE QUOTATION MARK ('‹')
|
||||
0x8C => 0x0152, // LATIN CAPITAL LIGATURE OE ('Œ')
|
||||
0x8D => 0x008D, // <control>
|
||||
0x8E => 0x017D, // LATIN CAPITAL LETTER Z WITH CARON ('Ž')
|
||||
0x8F => 0x008F, // <control>
|
||||
0x90 => 0x0090, // <control>
|
||||
0x91 => 0x2018, // LEFT SINGLE QUOTATION MARK ('‘')
|
||||
0x92 => 0x2019, // RIGHT SINGLE QUOTATION MARK ('’')
|
||||
0x93 => 0x201C, // LEFT DOUBLE QUOTATION MARK ('“')
|
||||
0x94 => 0x201D, // RIGHT DOUBLE QUOTATION MARK ('”')
|
||||
0x95 => 0x2022, // BULLET ('•')
|
||||
0x96 => 0x2013, // EN DASH ('–')
|
||||
0x97 => 0x2014, // EM DASH ('—')
|
||||
0x98 => 0x02DC, // SMALL TILDE ('˜')
|
||||
0x99 => 0x2122, // TRADE MARK SIGN ('™')
|
||||
0x9A => 0x0161, // LATIN SMALL LETTER S WITH CARON ('š')
|
||||
0x9B => 0x203A, // SINGLE RIGHT-POINTING ANGLE QUOTATION MARK ('›')
|
||||
0x9C => 0x0153, // LATIN SMALL LIGATURE OE ('œ')
|
||||
0x9D => 0x009D, // <control>
|
||||
0x9E => 0x017E, // LATIN SMALL LETTER Z WITH CARON ('ž')
|
||||
0x9F => 0x0178, // LATIN CAPITAL LETTER Y WITH DIAERESIS ('Ÿ')
|
||||
];
|
||||
|
||||
protected static $namedCharacterReferences;
|
||||
|
||||
protected static $namedCharacterReferenceMaxLength;
|
||||
|
||||
/**
|
||||
* Returns the "real" Unicode codepoint of a malformed character
|
||||
* reference.
|
||||
*/
|
||||
public static function getRealCodepoint($ref) {
|
||||
if (!isset(self::$realCodepointTable[$ref])) {
|
||||
return false;
|
||||
} else {
|
||||
return self::$realCodepointTable[$ref];
|
||||
}
|
||||
}
|
||||
|
||||
public static function getNamedCharacterReferences() {
|
||||
if (!self::$namedCharacterReferences) {
|
||||
self::$namedCharacterReferences = unserialize(
|
||||
file_get_contents(dirname(__FILE__) . '/named-character-references.ser'));
|
||||
}
|
||||
return self::$namedCharacterReferences;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a Unicode codepoint to sequence of UTF-8 bytes.
|
||||
* @note Shamelessly stolen from HTML Purifier, which is also
|
||||
* shamelessly stolen from Feyd (which is in public domain).
|
||||
*/
|
||||
public static function utf8chr($code) {
|
||||
/* We don't care: we live dangerously
|
||||
* if($code > 0x10FFFF or $code < 0x0 or
|
||||
($code >= 0xD800 and $code <= 0xDFFF) ) {
|
||||
// bits are set outside the "valid" range as defined
|
||||
// by UNICODE 4.1.0
|
||||
return "\xEF\xBF\xBD";
|
||||
}*/
|
||||
|
||||
$y = $z = $w = 0;
|
||||
if ($code < 0x80) {
|
||||
// regular ASCII character
|
||||
$x = $code;
|
||||
} else {
|
||||
// set up bits for UTF-8
|
||||
$x = ($code & 0x3F) | 0x80;
|
||||
if ($code < 0x800) {
|
||||
$y = (($code & 0x7FF) >> 6) | 0xC0;
|
||||
} else {
|
||||
$y = (($code & 0xFC0) >> 6) | 0x80;
|
||||
if ($code < 0x10000) {
|
||||
$z = (($code >> 12) & 0x0F) | 0xE0;
|
||||
} else {
|
||||
$z = (($code >> 12) & 0x3F) | 0x80;
|
||||
$w = (($code >> 18) & 0x07) | 0xF0;
|
||||
}
|
||||
}
|
||||
}
|
||||
// set up the actual character
|
||||
$ret = '';
|
||||
if ($w) {
|
||||
$ret .= chr($w);
|
||||
}
|
||||
if ($z) {
|
||||
$ret .= chr($z);
|
||||
}
|
||||
if ($y) {
|
||||
$ret .= chr($y);
|
||||
}
|
||||
$ret .= chr($x);
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,299 +0,0 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
|
||||
Copyright 2009 Geoffrey Sneddon <http://gsnedders.com/>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a
|
||||
copy of this software and associated documentation files (the
|
||||
"Software"), to deal in the Software without restriction, including
|
||||
without limitation the rights to use, copy, modify, merge, publish,
|
||||
distribute, sublicense, and/or sell copies of the Software, and to
|
||||
permit persons to whom the Software is furnished to do so, subject to
|
||||
the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included
|
||||
in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
*/
|
||||
|
||||
// Some conventions:
|
||||
// /* */ indicates verbatim text from the HTML 5 specification
|
||||
// // indicates regular comments
|
||||
|
||||
class HTML5_InputStream {
|
||||
/**
|
||||
* The string data we're parsing.
|
||||
*/
|
||||
private $data;
|
||||
|
||||
/**
|
||||
* The current integer byte position we are in $data
|
||||
*/
|
||||
private $char;
|
||||
|
||||
/**
|
||||
* Length of $data; when $char === $data, we are at the end-of-file.
|
||||
*/
|
||||
private $EOF;
|
||||
|
||||
/**
|
||||
* Parse errors.
|
||||
*/
|
||||
public $errors = [];
|
||||
|
||||
/**
|
||||
* @param $data | Data to parse
|
||||
* @throws Exception
|
||||
*/
|
||||
public function __construct($data) {
|
||||
|
||||
/* Given an encoding, the bytes in the input stream must be
|
||||
converted to Unicode characters for the tokeniser, as
|
||||
described by the rules for that encoding, except that the
|
||||
leading U+FEFF BYTE ORDER MARK character, if any, must not
|
||||
be stripped by the encoding layer (it is stripped by the rule below).
|
||||
|
||||
Bytes or sequences of bytes in the original byte stream that
|
||||
could not be converted to Unicode characters must be converted
|
||||
to U+FFFD REPLACEMENT CHARACTER code points. */
|
||||
|
||||
// XXX currently assuming input data is UTF-8; once we
|
||||
// build encoding detection this will no longer be the case
|
||||
//
|
||||
// We previously had an mbstring implementation here, but that
|
||||
// implementation is heavily non-conforming, so it's been
|
||||
// omitted.
|
||||
if (extension_loaded('iconv')) {
|
||||
// non-conforming
|
||||
$data = @iconv('UTF-8', 'UTF-8//IGNORE', $data);
|
||||
} else {
|
||||
// we can make a conforming native implementation
|
||||
throw new Exception('Not implemented, please install iconv');
|
||||
}
|
||||
|
||||
/* One leading U+FEFF BYTE ORDER MARK character must be
|
||||
ignored if any are present. */
|
||||
if (substr($data, 0, 3) === "\xEF\xBB\xBF") {
|
||||
$data = substr($data, 3);
|
||||
}
|
||||
|
||||
/* All U+0000 NULL characters in the input must be replaced
|
||||
by U+FFFD REPLACEMENT CHARACTERs. Any occurrences of such
|
||||
characters is a parse error. */
|
||||
for ($i = 0, $count = substr_count($data, "\0"); $i < $count; $i++) {
|
||||
$this->errors[] = [
|
||||
'type' => HTML5_Tokenizer::PARSEERROR,
|
||||
'data' => 'null-character'
|
||||
];
|
||||
}
|
||||
/* U+000D CARRIAGE RETURN (CR) characters and U+000A LINE FEED
|
||||
(LF) characters are treated specially. Any CR characters
|
||||
that are followed by LF characters must be removed, and any
|
||||
CR characters not followed by LF characters must be converted
|
||||
to LF characters. Thus, newlines in HTML DOMs are represented
|
||||
by LF characters, and there are never any CR characters in the
|
||||
input to the tokenization stage. */
|
||||
$data = str_replace(
|
||||
[
|
||||
"\0",
|
||||
"\r\n",
|
||||
"\r"
|
||||
],
|
||||
[
|
||||
"\xEF\xBF\xBD",
|
||||
"\n",
|
||||
"\n"
|
||||
],
|
||||
$data
|
||||
);
|
||||
|
||||
/* Any occurrences of any characters in the ranges U+0001 to
|
||||
U+0008, U+000B, U+000E to U+001F, U+007F to U+009F,
|
||||
U+D800 to U+DFFF , U+FDD0 to U+FDEF, and
|
||||
characters U+FFFE, U+FFFF, U+1FFFE, U+1FFFF, U+2FFFE, U+2FFFF,
|
||||
U+3FFFE, U+3FFFF, U+4FFFE, U+4FFFF, U+5FFFE, U+5FFFF, U+6FFFE,
|
||||
U+6FFFF, U+7FFFE, U+7FFFF, U+8FFFE, U+8FFFF, U+9FFFE, U+9FFFF,
|
||||
U+AFFFE, U+AFFFF, U+BFFFE, U+BFFFF, U+CFFFE, U+CFFFF, U+DFFFE,
|
||||
U+DFFFF, U+EFFFE, U+EFFFF, U+FFFFE, U+FFFFF, U+10FFFE, and
|
||||
U+10FFFF are parse errors. (These are all control characters
|
||||
or permanently undefined Unicode characters.) */
|
||||
// Check PCRE is loaded.
|
||||
if (extension_loaded('pcre')) {
|
||||
$count = preg_match_all(
|
||||
'/(?:
|
||||
[\x01-\x08\x0B\x0E-\x1F\x7F] # U+0001 to U+0008, U+000B, U+000E to U+001F and U+007F
|
||||
|
|
||||
\xC2[\x80-\x9F] # U+0080 to U+009F
|
||||
|
|
||||
\xED(?:\xA0[\x80-\xFF]|[\xA1-\xBE][\x00-\xFF]|\xBF[\x00-\xBF]) # U+D800 to U+DFFFF
|
||||
|
|
||||
\xEF\xB7[\x90-\xAF] # U+FDD0 to U+FDEF
|
||||
|
|
||||
\xEF\xBF[\xBE\xBF] # U+FFFE and U+FFFF
|
||||
|
|
||||
[\xF0-\xF4][\x8F-\xBF]\xBF[\xBE\xBF] # U+nFFFE and U+nFFFF (1 <= n <= 10_{16})
|
||||
)/x',
|
||||
$data,
|
||||
$matches
|
||||
);
|
||||
for ($i = 0; $i < $count; $i++) {
|
||||
$this->errors[] = [
|
||||
'type' => HTML5_Tokenizer::PARSEERROR,
|
||||
'data' => 'invalid-codepoint'
|
||||
];
|
||||
}
|
||||
} else {
|
||||
// XXX: Need non-PCRE impl, probably using substr_count
|
||||
}
|
||||
|
||||
$this->data = $data;
|
||||
$this->char = 0;
|
||||
$this->EOF = strlen($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current line that the tokenizer is at.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getCurrentLine() {
|
||||
// Check the string isn't empty
|
||||
if ($this->EOF) {
|
||||
// Add one to $this->char because we want the number for the next
|
||||
// byte to be processed.
|
||||
return substr_count($this->data, "\n", 0, min($this->char, $this->EOF)) + 1;
|
||||
} else {
|
||||
// If the string is empty, we are on the first line (sorta).
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current column of the current line that the tokenizer is at.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getColumnOffset() {
|
||||
// strrpos is weird, and the offset needs to be negative for what we
|
||||
// want (i.e., the last \n before $this->char). This needs to not have
|
||||
// one (to make it point to the next character, the one we want the
|
||||
// position of) added to it because strrpos's behaviour includes the
|
||||
// final offset byte.
|
||||
$lastLine = strrpos($this->data, "\n", $this->char - 1 - strlen($this->data));
|
||||
|
||||
// However, for here we want the length up until the next byte to be
|
||||
// processed, so add one to the current byte ($this->char).
|
||||
if ($lastLine !== false) {
|
||||
$findLengthOf = substr($this->data, $lastLine + 1, $this->char - 1 - $lastLine);
|
||||
} else {
|
||||
$findLengthOf = substr($this->data, 0, $this->char);
|
||||
}
|
||||
|
||||
// Get the length for the string we need.
|
||||
if (extension_loaded('iconv')) {
|
||||
return iconv_strlen($findLengthOf, 'utf-8');
|
||||
} elseif (extension_loaded('mbstring')) {
|
||||
return mb_strlen($findLengthOf, 'utf-8');
|
||||
} elseif (extension_loaded('xml')) {
|
||||
return strlen(utf8_decode($findLengthOf));
|
||||
} else {
|
||||
$count = count_chars($findLengthOf);
|
||||
// 0x80 = 0x7F - 0 + 1 (one added to get inclusive range)
|
||||
// 0x33 = 0xF4 - 0x2C + 1 (one added to get inclusive range)
|
||||
return array_sum(array_slice($count, 0, 0x80)) +
|
||||
array_sum(array_slice($count, 0xC2, 0x33));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the currently consume character.
|
||||
* @note This performs bounds checking
|
||||
*
|
||||
* @return bool|string
|
||||
*/
|
||||
public function char() {
|
||||
return ($this->char++ < $this->EOF)
|
||||
? $this->data[$this->char - 1]
|
||||
: false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all characters until EOF.
|
||||
* @note This performs bounds checking
|
||||
*
|
||||
* @return string|bool
|
||||
*/
|
||||
public function remainingChars() {
|
||||
if ($this->char < $this->EOF) {
|
||||
$data = substr($this->data, $this->char);
|
||||
$this->char = $this->EOF;
|
||||
return $data;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Matches as far as possible until we reach a certain set of bytes
|
||||
* and returns the matched substring.
|
||||
*
|
||||
* @param $bytes | Bytes to match.
|
||||
* @param null $max
|
||||
* @return bool|string
|
||||
*/
|
||||
public function charsUntil($bytes, $max = null) {
|
||||
if ($this->char < $this->EOF) {
|
||||
if ($max === 0 || $max) {
|
||||
$len = strcspn($this->data, $bytes, $this->char, $max);
|
||||
} else {
|
||||
$len = strcspn($this->data, $bytes, $this->char);
|
||||
}
|
||||
$string = (string) substr($this->data, $this->char, $len);
|
||||
$this->char += $len;
|
||||
return $string;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Matches as far as possible with a certain set of bytes
|
||||
* and returns the matched substring.
|
||||
*
|
||||
* @param $bytes | Bytes to match.
|
||||
* @param null $max
|
||||
* @return bool|string
|
||||
*/
|
||||
public function charsWhile($bytes, $max = null) {
|
||||
if ($this->char < $this->EOF) {
|
||||
if ($max === 0 || $max) {
|
||||
$len = strspn($this->data, $bytes, $this->char, $max);
|
||||
} else {
|
||||
$len = strspn($this->data, $bytes, $this->char);
|
||||
}
|
||||
$string = (string) substr($this->data, $this->char, $len);
|
||||
$this->char += $len;
|
||||
return $string;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Unconsume one character.
|
||||
*/
|
||||
public function unget() {
|
||||
if ($this->char <= $this->EOF) {
|
||||
$this->char--;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,37 +0,0 @@
|
|||
<?php
|
||||
|
||||
require_once dirname(__FILE__) . '/Data.php';
|
||||
require_once dirname(__FILE__) . '/InputStream.php';
|
||||
require_once dirname(__FILE__) . '/TreeBuilder.php';
|
||||
require_once dirname(__FILE__) . '/Tokenizer.php';
|
||||
|
||||
/**
|
||||
* Outwards facing interface for HTML5.
|
||||
*/
|
||||
class HTML5_Parser
|
||||
{
|
||||
/**
|
||||
* Parses a full HTML document.
|
||||
* @param $text | HTML text to parse
|
||||
* @param $builder | Custom builder implementation
|
||||
* @return DOMDocument|DOMNodeList Parsed HTML as DOMDocument
|
||||
*/
|
||||
public static function parse($text, $builder = null) {
|
||||
$tokenizer = new HTML5_Tokenizer($text, $builder);
|
||||
$tokenizer->parse();
|
||||
return $tokenizer->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses an HTML fragment.
|
||||
* @param $text | HTML text to parse
|
||||
* @param $context String name of context element to pretend parsing is in.
|
||||
* @param $builder | Custom builder implementation
|
||||
* @return DOMDocument|DOMNodeList Parsed HTML as DOMDocument
|
||||
*/
|
||||
public static function parseFragment($text, $context = null, $builder = null) {
|
||||
$tokenizer = new HTML5_Tokenizer($text, $builder);
|
||||
$tokenizer->parseFragment($context);
|
||||
return $tokenizer->save();
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because one or more lines are too long
|
@ -1,674 +0,0 @@
|
|||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 3, 29 June 2007
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The GNU General Public License is a free, copyleft license for
|
||||
software and other kinds of works.
|
||||
|
||||
The licenses for most software and other practical works are designed
|
||||
to take away your freedom to share and change the works. By contrast,
|
||||
the GNU General Public License is intended to guarantee your freedom to
|
||||
share and change all versions of a program--to make sure it remains free
|
||||
software for all its users. We, the Free Software Foundation, use the
|
||||
GNU General Public License for most of our software; it applies also to
|
||||
any other work released this way by its authors. You can apply it to
|
||||
your programs, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
them if you wish), that you receive source code or can get it if you
|
||||
want it, that you can change the software or use pieces of it in new
|
||||
free programs, and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to prevent others from denying you
|
||||
these rights or asking you to surrender the rights. Therefore, you have
|
||||
certain responsibilities if you distribute copies of the software, or if
|
||||
you modify it: responsibilities to respect the freedom of others.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must pass on to the recipients the same
|
||||
freedoms that you received. You must make sure that they, too, receive
|
||||
or can get the source code. And you must show them these terms so they
|
||||
know their rights.
|
||||
|
||||
Developers that use the GNU GPL protect your rights with two steps:
|
||||
(1) assert copyright on the software, and (2) offer you this License
|
||||
giving you legal permission to copy, distribute and/or modify it.
|
||||
|
||||
For the developers' and authors' protection, the GPL clearly explains
|
||||
that there is no warranty for this free software. For both users' and
|
||||
authors' sake, the GPL requires that modified versions be marked as
|
||||
changed, so that their problems will not be attributed erroneously to
|
||||
authors of previous versions.
|
||||
|
||||
Some devices are designed to deny users access to install or run
|
||||
modified versions of the software inside them, although the manufacturer
|
||||
can do so. This is fundamentally incompatible with the aim of
|
||||
protecting users' freedom to change the software. The systematic
|
||||
pattern of such abuse occurs in the area of products for individuals to
|
||||
use, which is precisely where it is most unacceptable. Therefore, we
|
||||
have designed this version of the GPL to prohibit the practice for those
|
||||
products. If such problems arise substantially in other domains, we
|
||||
stand ready to extend this provision to those domains in future versions
|
||||
of the GPL, as needed to protect the freedom of users.
|
||||
|
||||
Finally, every program is threatened constantly by software patents.
|
||||
States should not allow patents to restrict development and use of
|
||||
software on general-purpose computers, but in those that do, we wish to
|
||||
avoid the special danger that patents applied to a free program could
|
||||
make it effectively proprietary. To prevent this, the GPL assures that
|
||||
patents cannot be used to render the program non-free.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
TERMS AND CONDITIONS
|
||||
|
||||
0. Definitions.
|
||||
|
||||
"This License" refers to version 3 of the GNU General Public License.
|
||||
|
||||
"Copyright" also means copyright-like laws that apply to other kinds of
|
||||
works, such as semiconductor masks.
|
||||
|
||||
"The Program" refers to any copyrightable work licensed under this
|
||||
License. Each licensee is addressed as "you". "Licensees" and
|
||||
"recipients" may be individuals or organizations.
|
||||
|
||||
To "modify" a work means to copy from or adapt all or part of the work
|
||||
in a fashion requiring copyright permission, other than the making of an
|
||||
exact copy. The resulting work is called a "modified version" of the
|
||||
earlier work or a work "based on" the earlier work.
|
||||
|
||||
A "covered work" means either the unmodified Program or a work based
|
||||
on the Program.
|
||||
|
||||
To "propagate" a work means to do anything with it that, without
|
||||
permission, would make you directly or secondarily liable for
|
||||
infringement under applicable copyright law, except executing it on a
|
||||
computer or modifying a private copy. Propagation includes copying,
|
||||
distribution (with or without modification), making available to the
|
||||
public, and in some countries other activities as well.
|
||||
|
||||
To "convey" a work means any kind of propagation that enables other
|
||||
parties to make or receive copies. Mere interaction with a user through
|
||||
a computer network, with no transfer of a copy, is not conveying.
|
||||
|
||||
An interactive user interface displays "Appropriate Legal Notices"
|
||||
to the extent that it includes a convenient and prominently visible
|
||||
feature that (1) displays an appropriate copyright notice, and (2)
|
||||
tells the user that there is no warranty for the work (except to the
|
||||
extent that warranties are provided), that licensees may convey the
|
||||
work under this License, and how to view a copy of this License. If
|
||||
the interface presents a list of user commands or options, such as a
|
||||
menu, a prominent item in the list meets this criterion.
|
||||
|
||||
1. Source Code.
|
||||
|
||||
The "source code" for a work means the preferred form of the work
|
||||
for making modifications to it. "Object code" means any non-source
|
||||
form of a work.
|
||||
|
||||
A "Standard Interface" means an interface that either is an official
|
||||
standard defined by a recognized standards body, or, in the case of
|
||||
interfaces specified for a particular programming language, one that
|
||||
is widely used among developers working in that language.
|
||||
|
||||
The "System Libraries" of an executable work include anything, other
|
||||
than the work as a whole, that (a) is included in the normal form of
|
||||
packaging a Major Component, but which is not part of that Major
|
||||
Component, and (b) serves only to enable use of the work with that
|
||||
Major Component, or to implement a Standard Interface for which an
|
||||
implementation is available to the public in source code form. A
|
||||
"Major Component", in this context, means a major essential component
|
||||
(kernel, window system, and so on) of the specific operating system
|
||||
(if any) on which the executable work runs, or a compiler used to
|
||||
produce the work, or an object code interpreter used to run it.
|
||||
|
||||
The "Corresponding Source" for a work in object code form means all
|
||||
the source code needed to generate, install, and (for an executable
|
||||
work) run the object code and to modify the work, including scripts to
|
||||
control those activities. However, it does not include the work's
|
||||
System Libraries, or general-purpose tools or generally available free
|
||||
programs which are used unmodified in performing those activities but
|
||||
which are not part of the work. For example, Corresponding Source
|
||||
includes interface definition files associated with source files for
|
||||
the work, and the source code for shared libraries and dynamically
|
||||
linked subprograms that the work is specifically designed to require,
|
||||
such as by intimate data communication or control flow between those
|
||||
subprograms and other parts of the work.
|
||||
|
||||
The Corresponding Source need not include anything that users
|
||||
can regenerate automatically from other parts of the Corresponding
|
||||
Source.
|
||||
|
||||
The Corresponding Source for a work in source code form is that
|
||||
same work.
|
||||
|
||||
2. Basic Permissions.
|
||||
|
||||
All rights granted under this License are granted for the term of
|
||||
copyright on the Program, and are irrevocable provided the stated
|
||||
conditions are met. This License explicitly affirms your unlimited
|
||||
permission to run the unmodified Program. The output from running a
|
||||
covered work is covered by this License only if the output, given its
|
||||
content, constitutes a covered work. This License acknowledges your
|
||||
rights of fair use or other equivalent, as provided by copyright law.
|
||||
|
||||
You may make, run and propagate covered works that you do not
|
||||
convey, without conditions so long as your license otherwise remains
|
||||
in force. You may convey covered works to others for the sole purpose
|
||||
of having them make modifications exclusively for you, or provide you
|
||||
with facilities for running those works, provided that you comply with
|
||||
the terms of this License in conveying all material for which you do
|
||||
not control copyright. Those thus making or running the covered works
|
||||
for you must do so exclusively on your behalf, under your direction
|
||||
and control, on terms that prohibit them from making any copies of
|
||||
your copyrighted material outside their relationship with you.
|
||||
|
||||
Conveying under any other circumstances is permitted solely under
|
||||
the conditions stated below. Sublicensing is not allowed; section 10
|
||||
makes it unnecessary.
|
||||
|
||||
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||
|
||||
No covered work shall be deemed part of an effective technological
|
||||
measure under any applicable law fulfilling obligations under article
|
||||
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
||||
similar laws prohibiting or restricting circumvention of such
|
||||
measures.
|
||||
|
||||
When you convey a covered work, you waive any legal power to forbid
|
||||
circumvention of technological measures to the extent such circumvention
|
||||
is effected by exercising rights under this License with respect to
|
||||
the covered work, and you disclaim any intention to limit operation or
|
||||
modification of the work as a means of enforcing, against the work's
|
||||
users, your or third parties' legal rights to forbid circumvention of
|
||||
technological measures.
|
||||
|
||||
4. Conveying Verbatim Copies.
|
||||
|
||||
You may convey verbatim copies of the Program's source code as you
|
||||
receive it, in any medium, provided that you conspicuously and
|
||||
appropriately publish on each copy an appropriate copyright notice;
|
||||
keep intact all notices stating that this License and any
|
||||
non-permissive terms added in accord with section 7 apply to the code;
|
||||
keep intact all notices of the absence of any warranty; and give all
|
||||
recipients a copy of this License along with the Program.
|
||||
|
||||
You may charge any price or no price for each copy that you convey,
|
||||
and you may offer support or warranty protection for a fee.
|
||||
|
||||
5. Conveying Modified Source Versions.
|
||||
|
||||
You may convey a work based on the Program, or the modifications to
|
||||
produce it from the Program, in the form of source code under the
|
||||
terms of section 4, provided that you also meet all of these conditions:
|
||||
|
||||
a) The work must carry prominent notices stating that you modified
|
||||
it, and giving a relevant date.
|
||||
|
||||
b) The work must carry prominent notices stating that it is
|
||||
released under this License and any conditions added under section
|
||||
7. This requirement modifies the requirement in section 4 to
|
||||
"keep intact all notices".
|
||||
|
||||
c) You must license the entire work, as a whole, under this
|
||||
License to anyone who comes into possession of a copy. This
|
||||
License will therefore apply, along with any applicable section 7
|
||||
additional terms, to the whole of the work, and all its parts,
|
||||
regardless of how they are packaged. This License gives no
|
||||
permission to license the work in any other way, but it does not
|
||||
invalidate such permission if you have separately received it.
|
||||
|
||||
d) If the work has interactive user interfaces, each must display
|
||||
Appropriate Legal Notices; however, if the Program has interactive
|
||||
interfaces that do not display Appropriate Legal Notices, your
|
||||
work need not make them do so.
|
||||
|
||||
A compilation of a covered work with other separate and independent
|
||||
works, which are not by their nature extensions of the covered work,
|
||||
and which are not combined with it such as to form a larger program,
|
||||
in or on a volume of a storage or distribution medium, is called an
|
||||
"aggregate" if the compilation and its resulting copyright are not
|
||||
used to limit the access or legal rights of the compilation's users
|
||||
beyond what the individual works permit. Inclusion of a covered work
|
||||
in an aggregate does not cause this License to apply to the other
|
||||
parts of the aggregate.
|
||||
|
||||
6. Conveying Non-Source Forms.
|
||||
|
||||
You may convey a covered work in object code form under the terms
|
||||
of sections 4 and 5, provided that you also convey the
|
||||
machine-readable Corresponding Source under the terms of this License,
|
||||
in one of these ways:
|
||||
|
||||
a) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by the
|
||||
Corresponding Source fixed on a durable physical medium
|
||||
customarily used for software interchange.
|
||||
|
||||
b) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by a
|
||||
written offer, valid for at least three years and valid for as
|
||||
long as you offer spare parts or customer support for that product
|
||||
model, to give anyone who possesses the object code either (1) a
|
||||
copy of the Corresponding Source for all the software in the
|
||||
product that is covered by this License, on a durable physical
|
||||
medium customarily used for software interchange, for a price no
|
||||
more than your reasonable cost of physically performing this
|
||||
conveying of source, or (2) access to copy the
|
||||
Corresponding Source from a network server at no charge.
|
||||
|
||||
c) Convey individual copies of the object code with a copy of the
|
||||
written offer to provide the Corresponding Source. This
|
||||
alternative is allowed only occasionally and noncommercially, and
|
||||
only if you received the object code with such an offer, in accord
|
||||
with subsection 6b.
|
||||
|
||||
d) Convey the object code by offering access from a designated
|
||||
place (gratis or for a charge), and offer equivalent access to the
|
||||
Corresponding Source in the same way through the same place at no
|
||||
further charge. You need not require recipients to copy the
|
||||
Corresponding Source along with the object code. If the place to
|
||||
copy the object code is a network server, the Corresponding Source
|
||||
may be on a different server (operated by you or a third party)
|
||||
that supports equivalent copying facilities, provided you maintain
|
||||
clear directions next to the object code saying where to find the
|
||||
Corresponding Source. Regardless of what server hosts the
|
||||
Corresponding Source, you remain obligated to ensure that it is
|
||||
available for as long as needed to satisfy these requirements.
|
||||
|
||||
e) Convey the object code using peer-to-peer transmission, provided
|
||||
you inform other peers where the object code and Corresponding
|
||||
Source of the work are being offered to the general public at no
|
||||
charge under subsection 6d.
|
||||
|
||||
A separable portion of the object code, whose source code is excluded
|
||||
from the Corresponding Source as a System Library, need not be
|
||||
included in conveying the object code work.
|
||||
|
||||
A "User Product" is either (1) a "consumer product", which means any
|
||||
tangible personal property which is normally used for personal, family,
|
||||
or household purposes, or (2) anything designed or sold for incorporation
|
||||
into a dwelling. In determining whether a product is a consumer product,
|
||||
doubtful cases shall be resolved in favor of coverage. For a particular
|
||||
product received by a particular user, "normally used" refers to a
|
||||
typical or common use of that class of product, regardless of the status
|
||||
of the particular user or of the way in which the particular user
|
||||
actually uses, or expects or is expected to use, the product. A product
|
||||
is a consumer product regardless of whether the product has substantial
|
||||
commercial, industrial or non-consumer uses, unless such uses represent
|
||||
the only significant mode of use of the product.
|
||||
|
||||
"Installation Information" for a User Product means any methods,
|
||||
procedures, authorization keys, or other information required to install
|
||||
and execute modified versions of a covered work in that User Product from
|
||||
a modified version of its Corresponding Source. The information must
|
||||
suffice to ensure that the continued functioning of the modified object
|
||||
code is in no case prevented or interfered with solely because
|
||||
modification has been made.
|
||||
|
||||
If you convey an object code work under this section in, or with, or
|
||||
specifically for use in, a User Product, and the conveying occurs as
|
||||
part of a transaction in which the right of possession and use of the
|
||||
User Product is transferred to the recipient in perpetuity or for a
|
||||
fixed term (regardless of how the transaction is characterized), the
|
||||
Corresponding Source conveyed under this section must be accompanied
|
||||
by the Installation Information. But this requirement does not apply
|
||||
if neither you nor any third party retains the ability to install
|
||||
modified object code on the User Product (for example, the work has
|
||||
been installed in ROM).
|
||||
|
||||
The requirement to provide Installation Information does not include a
|
||||
requirement to continue to provide support service, warranty, or updates
|
||||
for a work that has been modified or installed by the recipient, or for
|
||||
the User Product in which it has been modified or installed. Access to a
|
||||
network may be denied when the modification itself materially and
|
||||
adversely affects the operation of the network or violates the rules and
|
||||
protocols for communication across the network.
|
||||
|
||||
Corresponding Source conveyed, and Installation Information provided,
|
||||
in accord with this section must be in a format that is publicly
|
||||
documented (and with an implementation available to the public in
|
||||
source code form), and must require no special password or key for
|
||||
unpacking, reading or copying.
|
||||
|
||||
7. Additional Terms.
|
||||
|
||||
"Additional permissions" are terms that supplement the terms of this
|
||||
License by making exceptions from one or more of its conditions.
|
||||
Additional permissions that are applicable to the entire Program shall
|
||||
be treated as though they were included in this License, to the extent
|
||||
that they are valid under applicable law. If additional permissions
|
||||
apply only to part of the Program, that part may be used separately
|
||||
under those permissions, but the entire Program remains governed by
|
||||
this License without regard to the additional permissions.
|
||||
|
||||
When you convey a copy of a covered work, you may at your option
|
||||
remove any additional permissions from that copy, or from any part of
|
||||
it. (Additional permissions may be written to require their own
|
||||
removal in certain cases when you modify the work.) You may place
|
||||
additional permissions on material, added by you to a covered work,
|
||||
for which you have or can give appropriate copyright permission.
|
||||
|
||||
Notwithstanding any other provision of this License, for material you
|
||||
add to a covered work, you may (if authorized by the copyright holders of
|
||||
that material) supplement the terms of this License with terms:
|
||||
|
||||
a) Disclaiming warranty or limiting liability differently from the
|
||||
terms of sections 15 and 16 of this License; or
|
||||
|
||||
b) Requiring preservation of specified reasonable legal notices or
|
||||
author attributions in that material or in the Appropriate Legal
|
||||
Notices displayed by works containing it; or
|
||||
|
||||
c) Prohibiting misrepresentation of the origin of that material, or
|
||||
requiring that modified versions of such material be marked in
|
||||
reasonable ways as different from the original version; or
|
||||
|
||||
d) Limiting the use for publicity purposes of names of licensors or
|
||||
authors of the material; or
|
||||
|
||||
e) Declining to grant rights under trademark law for use of some
|
||||
trade names, trademarks, or service marks; or
|
||||
|
||||
f) Requiring indemnification of licensors and authors of that
|
||||
material by anyone who conveys the material (or modified versions of
|
||||
it) with contractual assumptions of liability to the recipient, for
|
||||
any liability that these contractual assumptions directly impose on
|
||||
those licensors and authors.
|
||||
|
||||
All other non-permissive additional terms are considered "further
|
||||
restrictions" within the meaning of section 10. If the Program as you
|
||||
received it, or any part of it, contains a notice stating that it is
|
||||
governed by this License along with a term that is a further
|
||||
restriction, you may remove that term. If a license document contains
|
||||
a further restriction but permits relicensing or conveying under this
|
||||
License, you may add to a covered work material governed by the terms
|
||||
of that license document, provided that the further restriction does
|
||||
not survive such relicensing or conveying.
|
||||
|
||||
If you add terms to a covered work in accord with this section, you
|
||||
must place, in the relevant source files, a statement of the
|
||||
additional terms that apply to those files, or a notice indicating
|
||||
where to find the applicable terms.
|
||||
|
||||
Additional terms, permissive or non-permissive, may be stated in the
|
||||
form of a separately written license, or stated as exceptions;
|
||||
the above requirements apply either way.
|
||||
|
||||
8. Termination.
|
||||
|
||||
You may not propagate or modify a covered work except as expressly
|
||||
provided under this License. Any attempt otherwise to propagate or
|
||||
modify it is void, and will automatically terminate your rights under
|
||||
this License (including any patent licenses granted under the third
|
||||
paragraph of section 11).
|
||||
|
||||
However, if you cease all violation of this License, then your
|
||||
license from a particular copyright holder is reinstated (a)
|
||||
provisionally, unless and until the copyright holder explicitly and
|
||||
finally terminates your license, and (b) permanently, if the copyright
|
||||
holder fails to notify you of the violation by some reasonable means
|
||||
prior to 60 days after the cessation.
|
||||
|
||||
Moreover, your license from a particular copyright holder is
|
||||
reinstated permanently if the copyright holder notifies you of the
|
||||
violation by some reasonable means, this is the first time you have
|
||||
received notice of violation of this License (for any work) from that
|
||||
copyright holder, and you cure the violation prior to 30 days after
|
||||
your receipt of the notice.
|
||||
|
||||
Termination of your rights under this section does not terminate the
|
||||
licenses of parties who have received copies or rights from you under
|
||||
this License. If your rights have been terminated and not permanently
|
||||
reinstated, you do not qualify to receive new licenses for the same
|
||||
material under section 10.
|
||||
|
||||
9. Acceptance Not Required for Having Copies.
|
||||
|
||||
You are not required to accept this License in order to receive or
|
||||
run a copy of the Program. Ancillary propagation of a covered work
|
||||
occurring solely as a consequence of using peer-to-peer transmission
|
||||
to receive a copy likewise does not require acceptance. However,
|
||||
nothing other than this License grants you permission to propagate or
|
||||
modify any covered work. These actions infringe copyright if you do
|
||||
not accept this License. Therefore, by modifying or propagating a
|
||||
covered work, you indicate your acceptance of this License to do so.
|
||||
|
||||
10. Automatic Licensing of Downstream Recipients.
|
||||
|
||||
Each time you convey a covered work, the recipient automatically
|
||||
receives a license from the original licensors, to run, modify and
|
||||
propagate that work, subject to this License. You are not responsible
|
||||
for enforcing compliance by third parties with this License.
|
||||
|
||||
An "entity transaction" is a transaction transferring control of an
|
||||
organization, or substantially all assets of one, or subdividing an
|
||||
organization, or merging organizations. If propagation of a covered
|
||||
work results from an entity transaction, each party to that
|
||||
transaction who receives a copy of the work also receives whatever
|
||||
licenses to the work the party's predecessor in interest had or could
|
||||
give under the previous paragraph, plus a right to possession of the
|
||||
Corresponding Source of the work from the predecessor in interest, if
|
||||
the predecessor has it or can get it with reasonable efforts.
|
||||
|
||||
You may not impose any further restrictions on the exercise of the
|
||||
rights granted or affirmed under this License. For example, you may
|
||||
not impose a license fee, royalty, or other charge for exercise of
|
||||
rights granted under this License, and you may not initiate litigation
|
||||
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
||||
any patent claim is infringed by making, using, selling, offering for
|
||||
sale, or importing the Program or any portion of it.
|
||||
|
||||
11. Patents.
|
||||
|
||||
A "contributor" is a copyright holder who authorizes use under this
|
||||
License of the Program or a work on which the Program is based. The
|
||||
work thus licensed is called the contributor's "contributor version".
|
||||
|
||||
A contributor's "essential patent claims" are all patent claims
|
||||
owned or controlled by the contributor, whether already acquired or
|
||||
hereafter acquired, that would be infringed by some manner, permitted
|
||||
by this License, of making, using, or selling its contributor version,
|
||||
but do not include claims that would be infringed only as a
|
||||
consequence of further modification of the contributor version. For
|
||||
purposes of this definition, "control" includes the right to grant
|
||||
patent sublicenses in a manner consistent with the requirements of
|
||||
this License.
|
||||
|
||||
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
||||
patent license under the contributor's essential patent claims, to
|
||||
make, use, sell, offer for sale, import and otherwise run, modify and
|
||||
propagate the contents of its contributor version.
|
||||
|
||||
In the following three paragraphs, a "patent license" is any express
|
||||
agreement or commitment, however denominated, not to enforce a patent
|
||||
(such as an express permission to practice a patent or covenant not to
|
||||
sue for patent infringement). To "grant" such a patent license to a
|
||||
party means to make such an agreement or commitment not to enforce a
|
||||
patent against the party.
|
||||
|
||||
If you convey a covered work, knowingly relying on a patent license,
|
||||
and the Corresponding Source of the work is not available for anyone
|
||||
to copy, free of charge and under the terms of this License, through a
|
||||
publicly available network server or other readily accessible means,
|
||||
then you must either (1) cause the Corresponding Source to be so
|
||||
available, or (2) arrange to deprive yourself of the benefit of the
|
||||
patent license for this particular work, or (3) arrange, in a manner
|
||||
consistent with the requirements of this License, to extend the patent
|
||||
license to downstream recipients. "Knowingly relying" means you have
|
||||
actual knowledge that, but for the patent license, your conveying the
|
||||
covered work in a country, or your recipient's use of the covered work
|
||||
in a country, would infringe one or more identifiable patents in that
|
||||
country that you have reason to believe are valid.
|
||||
|
||||
If, pursuant to or in connection with a single transaction or
|
||||
arrangement, you convey, or propagate by procuring conveyance of, a
|
||||
covered work, and grant a patent license to some of the parties
|
||||
receiving the covered work authorizing them to use, propagate, modify
|
||||
or convey a specific copy of the covered work, then the patent license
|
||||
you grant is automatically extended to all recipients of the covered
|
||||
work and works based on it.
|
||||
|
||||
A patent license is "discriminatory" if it does not include within
|
||||
the scope of its coverage, prohibits the exercise of, or is
|
||||
conditioned on the non-exercise of one or more of the rights that are
|
||||
specifically granted under this License. You may not convey a covered
|
||||
work if you are a party to an arrangement with a third party that is
|
||||
in the business of distributing software, under which you make payment
|
||||
to the third party based on the extent of your activity of conveying
|
||||
the work, and under which the third party grants, to any of the
|
||||
parties who would receive the covered work from you, a discriminatory
|
||||
patent license (a) in connection with copies of the covered work
|
||||
conveyed by you (or copies made from those copies), or (b) primarily
|
||||
for and in connection with specific products or compilations that
|
||||
contain the covered work, unless you entered into that arrangement,
|
||||
or that patent license was granted, prior to 28 March 2007.
|
||||
|
||||
Nothing in this License shall be construed as excluding or limiting
|
||||
any implied license or other defenses to infringement that may
|
||||
otherwise be available to you under applicable patent law.
|
||||
|
||||
12. No Surrender of Others' Freedom.
|
||||
|
||||
If conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot convey a
|
||||
covered work so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you may
|
||||
not convey it at all. For example, if you agree to terms that obligate you
|
||||
to collect a royalty for further conveying from those to whom you convey
|
||||
the Program, the only way you could satisfy both those terms and this
|
||||
License would be to refrain entirely from conveying the Program.
|
||||
|
||||
13. Use with the GNU Affero General Public License.
|
||||
|
||||
Notwithstanding any other provision of this License, you have
|
||||
permission to link or combine any covered work with a work licensed
|
||||
under version 3 of the GNU Affero General Public License into a single
|
||||
combined work, and to convey the resulting work. The terms of this
|
||||
License will continue to apply to the part which is the covered work,
|
||||
but the special requirements of the GNU Affero General Public License,
|
||||
section 13, concerning interaction through a network will apply to the
|
||||
combination as such.
|
||||
|
||||
14. Revised Versions of this License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions of
|
||||
the GNU General Public License from time to time. Such new versions will
|
||||
be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the
|
||||
Program specifies that a certain numbered version of the GNU General
|
||||
Public License "or any later version" applies to it, you have the
|
||||
option of following the terms and conditions either of that numbered
|
||||
version or of any later version published by the Free Software
|
||||
Foundation. If the Program does not specify a version number of the
|
||||
GNU General Public License, you may choose any version ever published
|
||||
by the Free Software Foundation.
|
||||
|
||||
If the Program specifies that a proxy can decide which future
|
||||
versions of the GNU General Public License can be used, that proxy's
|
||||
public statement of acceptance of a version permanently authorizes you
|
||||
to choose that version for the Program.
|
||||
|
||||
Later license versions may give you additional or different
|
||||
permissions. However, no additional obligations are imposed on any
|
||||
author or copyright holder as a result of your choosing to follow a
|
||||
later version.
|
||||
|
||||
15. Disclaimer of Warranty.
|
||||
|
||||
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
||||
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
||||
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
||||
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
||||
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
||||
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
||||
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||
|
||||
16. Limitation of Liability.
|
||||
|
||||
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
||||
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
||||
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
||||
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
||||
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
||||
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
||||
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
||||
SUCH DAMAGES.
|
||||
|
||||
17. Interpretation of Sections 15 and 16.
|
||||
|
||||
If the disclaimer of warranty and limitation of liability provided
|
||||
above cannot be given local legal effect according to their terms,
|
||||
reviewing courts shall apply local law that most closely approximates
|
||||
an absolute waiver of all civil liability in connection with the
|
||||
Program, unless a warranty or assumption of liability accompanies a
|
||||
copy of the Program in return for a fee.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
state the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the program's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program does terminal interaction, make it output a short
|
||||
notice like this when it starts in an interactive mode:
|
||||
|
||||
<program> Copyright (C) <year> <name of author>
|
||||
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||
This is free software, and you are welcome to redistribute it
|
||||
under certain conditions; type `show c' for details.
|
||||
|
||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||
parts of the General Public License. Of course, your program's commands
|
||||
might be different; for a GUI interface, you would use an "about box".
|
||||
|
||||
You should also get your employer (if you work as a programmer) or school,
|
||||
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
||||
For more information on this, and how to apply and follow the GNU GPL, see
|
||||
<https://www.gnu.org/licenses/>.
|
||||
|
||||
The GNU General Public License does not permit incorporating your program
|
||||
into proprietary programs. If your program is a subroutine library, you
|
||||
may consider it more useful to permit linking proprietary applications with
|
||||
the library. If this is what you want to do, use the GNU Lesser General
|
||||
Public License instead of this License. But first, please read
|
||||
<https://www.gnu.org/licenses/why-not-lgpl.html>.
|
|
@ -1,17 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* @package php-svg-lib
|
||||
* @link http://github.com/PhenX/php-svg-lib
|
||||
* @author Fabien Ménager <fabien.menager@gmail.com>
|
||||
* @license GNU LGPLv3+ http://www.gnu.org/copyleft/lesser.html
|
||||
*/
|
||||
|
||||
spl_autoload_register(function($class) {
|
||||
if (0 === strpos($class, "Svg")) {
|
||||
$file = str_replace('\\', DIRECTORY_SEPARATOR, $class);
|
||||
$file = realpath(__DIR__ . DIRECTORY_SEPARATOR . $file . '.php');
|
||||
if (file_exists($file)) {
|
||||
include_once $file;
|
||||
}
|
||||
}
|
||||
});
|
|
@ -1,42 +0,0 @@
|
|||
<?php
|
||||
namespace Dompdf;
|
||||
|
||||
/**
|
||||
* Autoloads Dompdf classes
|
||||
*
|
||||
* @package Dompdf
|
||||
*/
|
||||
class Autoloader
|
||||
{
|
||||
const PREFIX = 'Dompdf';
|
||||
|
||||
/**
|
||||
* Register the autoloader
|
||||
*/
|
||||
public static function register()
|
||||
{
|
||||
spl_autoload_register([new self, 'autoload']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Autoloader
|
||||
*
|
||||
* @param string
|
||||
*/
|
||||
public static function autoload($class)
|
||||
{
|
||||
if ($class === 'Dompdf\Cpdf') {
|
||||
require_once __DIR__ . "/../lib/Cpdf.php";
|
||||
return;
|
||||
}
|
||||
|
||||
$prefixLength = strlen(self::PREFIX);
|
||||
if (0 === strncmp(self::PREFIX, $class, $prefixLength)) {
|
||||
$file = str_replace('\\', '/', substr($class, $prefixLength));
|
||||
$file = realpath(__DIR__ . (empty($file) ? '' : '/') . $file . '.php');
|
||||
if (file_exists($file)) {
|
||||
require_once $file;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,35 +0,0 @@
|
|||
<?php
|
||||
namespace Dompdf\Frame;
|
||||
|
||||
use Dompdf\Frame;
|
||||
use IteratorAggregate;
|
||||
|
||||
/**
|
||||
* Linked-list IteratorAggregate
|
||||
*
|
||||
* @access private
|
||||
* @package dompdf
|
||||
*/
|
||||
class FrameList implements IteratorAggregate
|
||||
{
|
||||
/**
|
||||
* @var Frame
|
||||
*/
|
||||
protected $_frame;
|
||||
|
||||
/**
|
||||
* @param Frame $frame
|
||||
*/
|
||||
function __construct($frame)
|
||||
{
|
||||
$this->_frame = $frame;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return FrameListIterator
|
||||
*/
|
||||
function getIterator(): FrameListIterator
|
||||
{
|
||||
return new FrameListIterator($this->_frame);
|
||||
}
|
||||
}
|
|
@ -1,35 +0,0 @@
|
|||
<?php
|
||||
namespace Dompdf\Frame;
|
||||
|
||||
use IteratorAggregate;
|
||||
use Dompdf\Frame;
|
||||
|
||||
/**
|
||||
* Pre-order IteratorAggregate
|
||||
*
|
||||
* @access private
|
||||
* @package dompdf
|
||||
*/
|
||||
class FrameTreeList implements IteratorAggregate
|
||||
{
|
||||
/**
|
||||
* @var Frame
|
||||
*/
|
||||
protected $_root;
|
||||
|
||||
/**
|
||||
* @param Frame $root
|
||||
*/
|
||||
public function __construct(Frame $root)
|
||||
{
|
||||
$this->_root = $root;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return FrameTreeIterator
|
||||
*/
|
||||
public function getIterator(): FrameTreeIterator
|
||||
{
|
||||
return new FrameTreeIterator($this->_root);
|
||||
}
|
||||
}
|
|
@ -1,58 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* @package dompdf
|
||||
* @link http://dompdf.github.com/
|
||||
* @author Benj Carson <benjcarson@digitaljunkies.ca>
|
||||
* @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
|
||||
*/
|
||||
namespace Dompdf\FrameDecorator;
|
||||
|
||||
use Dompdf\Dompdf;
|
||||
use Dompdf\Frame;
|
||||
use Dompdf\FrameDecorator\Table as TableFrameDecorator;
|
||||
|
||||
/**
|
||||
* Decorates Frames for table row layout
|
||||
*
|
||||
* @package dompdf
|
||||
*/
|
||||
class TableRow extends AbstractFrameDecorator
|
||||
{
|
||||
/**
|
||||
* TableRow constructor.
|
||||
* @param Frame $frame
|
||||
* @param Dompdf $dompdf
|
||||
*/
|
||||
function __construct(Frame $frame, Dompdf $dompdf)
|
||||
{
|
||||
parent::__construct($frame, $dompdf);
|
||||
}
|
||||
|
||||
//........................................................................
|
||||
|
||||
/**
|
||||
* Remove all non table-cell frames from this row and move them after
|
||||
* the table.
|
||||
*
|
||||
* @deprecated
|
||||
*/
|
||||
function normalise()
|
||||
{
|
||||
// Find our table parent
|
||||
$p = TableFrameDecorator::find_parent_table($this);
|
||||
|
||||
$erroneous_frames = [];
|
||||
foreach ($this->get_children() as $child) {
|
||||
$display = $child->get_style()->display;
|
||||
|
||||
if ($display !== "table-cell") {
|
||||
$erroneous_frames[] = $child;
|
||||
}
|
||||
}
|
||||
|
||||
// dump the extra nodes after the table.
|
||||
foreach ($erroneous_frames as $frame) {
|
||||
$p->move_after($frame);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,268 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* @package dompdf
|
||||
* @link http://dompdf.github.com/
|
||||
* @author Benj Carson <benjcarson@digitaljunkies.ca>
|
||||
* @author Helmut Tischer <htischer@weihenstephan.org>
|
||||
* @author Fabien Ménager <fabien.menager@gmail.com>
|
||||
* @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
|
||||
*/
|
||||
namespace Dompdf\Image;
|
||||
|
||||
use Dompdf\Dompdf;
|
||||
use Dompdf\Helpers;
|
||||
use Dompdf\Exception\ImageException;
|
||||
|
||||
/**
|
||||
* Static class that resolves image urls and downloads and caches
|
||||
* remote images if required.
|
||||
*
|
||||
* @package dompdf
|
||||
*/
|
||||
class Cache
|
||||
{
|
||||
/**
|
||||
* Array of downloaded images. Cached so that identical images are
|
||||
* not needlessly downloaded.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected static $_cache = [];
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected static $tempImages = [];
|
||||
|
||||
/**
|
||||
* The url to the "broken image" used when images can't be loaded
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public static $broken_image = "data:image/svg+xml;charset=utf8,%3C?xml version='1.0'?%3E%3Csvg width='64' height='64' xmlns='http://www.w3.org/2000/svg'%3E%3Cg%3E%3Crect stroke='%23666666' id='svg_1' height='60.499994' width='60.166667' y='1.666669' x='1.999998' stroke-width='1.5' fill='none'/%3E%3Cline stroke-linecap='null' stroke-linejoin='null' id='svg_3' y2='59.333253' x2='59.749916' y1='4.333415' x1='4.250079' stroke-width='1.5' stroke='%23999999' fill='none'/%3E%3Cline stroke-linecap='null' stroke-linejoin='null' id='svg_4' y2='59.999665' x2='4.062838' y1='3.750342' x1='60.062164' stroke-width='1.5' stroke='%23999999' fill='none'/%3E%3C/g%3E%3C/svg%3E";
|
||||
|
||||
public static $error_message = "Image not found or type unknown";
|
||||
|
||||
/**
|
||||
* Current dompdf instance
|
||||
*
|
||||
* @var Dompdf
|
||||
*/
|
||||
protected static $_dompdf;
|
||||
|
||||
/**
|
||||
* Resolve and fetch an image for use.
|
||||
*
|
||||
* @param string $url The url of the image
|
||||
* @param string $protocol Default protocol if none specified in $url
|
||||
* @param string $host Default host if none specified in $url
|
||||
* @param string $base_path Default path if none specified in $url
|
||||
* @param Dompdf $dompdf The Dompdf instance
|
||||
*
|
||||
* @throws ImageException
|
||||
* @return array An array with two elements: The local path to the image and the image extension
|
||||
*/
|
||||
static function resolve_url($url, $protocol, $host, $base_path, Dompdf $dompdf)
|
||||
{
|
||||
self::$_dompdf = $dompdf;
|
||||
|
||||
$protocol = mb_strtolower($protocol);
|
||||
$parsed_url = Helpers::explode_url($url);
|
||||
$message = null;
|
||||
|
||||
$remote = ($protocol && $protocol !== "file://") || ($parsed_url['protocol'] !== "");
|
||||
|
||||
$data_uri = strpos($parsed_url['protocol'], "data:") === 0;
|
||||
$full_url = null;
|
||||
$enable_remote = $dompdf->getOptions()->getIsRemoteEnabled();
|
||||
$tempfile = false;
|
||||
|
||||
try {
|
||||
|
||||
// Remote not allowed and is not DataURI
|
||||
if (!$enable_remote && $remote && !$data_uri) {
|
||||
throw new ImageException("Remote file access is disabled.", E_WARNING);
|
||||
}
|
||||
|
||||
// remote allowed or DataURI
|
||||
if (($enable_remote && $remote) || $data_uri) {
|
||||
// Download remote files to a temporary directory
|
||||
$full_url = Helpers::build_url($protocol, $host, $base_path, $url);
|
||||
|
||||
// From cache
|
||||
if (isset(self::$_cache[$full_url])) {
|
||||
$resolved_url = self::$_cache[$full_url];
|
||||
} // From remote
|
||||
else {
|
||||
$tmp_dir = $dompdf->getOptions()->getTempDir();
|
||||
if (($resolved_url = @tempnam($tmp_dir, "ca_dompdf_img_")) === false) {
|
||||
throw new ImageException("Unable to create temporary image in " . $tmp_dir, E_WARNING);
|
||||
}
|
||||
$tempfile = $resolved_url;
|
||||
$image = null;
|
||||
|
||||
if ($data_uri) {
|
||||
if ($parsed_data_uri = Helpers::parse_data_uri($url)) {
|
||||
$image = $parsed_data_uri['data'];
|
||||
}
|
||||
} else {
|
||||
list($image, $http_response_header) = Helpers::getFileContent($full_url, $dompdf->getHttpContext());
|
||||
}
|
||||
|
||||
// Image not found or invalid
|
||||
if ($image === null) {
|
||||
$msg = ($data_uri ? "Data-URI could not be parsed" : "Image not found");
|
||||
throw new ImageException($msg, E_WARNING);
|
||||
} // Image found, put in cache and process
|
||||
else {
|
||||
//e.g. fetch.php?media=url.jpg&cache=1
|
||||
//- Image file name might be one of the dynamic parts of the url, don't strip off!
|
||||
//- a remote url does not need to have a file extension at all
|
||||
//- local cached file does not have a matching file extension
|
||||
//Therefore get image type from the content
|
||||
if (@file_put_contents($resolved_url, $image) === false) {
|
||||
throw new ImageException("Unable to create temporary image in " . $tmp_dir, E_WARNING);
|
||||
}
|
||||
}
|
||||
}
|
||||
} // Not remote, local image
|
||||
else {
|
||||
$resolved_url = Helpers::build_url($protocol, $host, $base_path, $url);
|
||||
|
||||
if ($protocol === "" || $protocol === "file://") {
|
||||
$realfile = realpath($resolved_url);
|
||||
|
||||
$rootDir = realpath($dompdf->getOptions()->getRootDir());
|
||||
if (strpos($realfile, $rootDir) !== 0) {
|
||||
$chroot = $dompdf->getOptions()->getChroot();
|
||||
$chrootValid = false;
|
||||
foreach ($chroot as $chrootPath) {
|
||||
$chrootPath = realpath($chrootPath);
|
||||
if ($chrootPath !== false && strpos($realfile, $chrootPath) === 0) {
|
||||
$chrootValid = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if ($chrootValid !== true) {
|
||||
throw new ImageException("Permission denied on $resolved_url. The file could not be found under the paths specified by Options::chroot.", E_WARNING);
|
||||
}
|
||||
}
|
||||
|
||||
if (!$realfile) {
|
||||
throw new ImageException("File '$realfile' not found.", E_WARNING);
|
||||
}
|
||||
|
||||
$resolved_url = $realfile;
|
||||
}
|
||||
}
|
||||
|
||||
// Check if the local file is readable
|
||||
if (!is_readable($resolved_url) || !filesize($resolved_url)) {
|
||||
throw new ImageException("Image not readable or empty", E_WARNING);
|
||||
} // Check is the file is an image
|
||||
else {
|
||||
list($width, $height, $type) = Helpers::dompdf_getimagesize($resolved_url, $dompdf->getHttpContext());
|
||||
|
||||
// Known image type
|
||||
if ($width && $height && in_array($type, ["gif", "png", "jpeg", "bmp", "svg","webp"], true)) {
|
||||
//Don't put replacement image into cache - otherwise it will be deleted on cache cleanup.
|
||||
//Only execute on successful caching of remote image.
|
||||
if ($enable_remote && $remote || $data_uri) {
|
||||
self::$_cache[$full_url] = $resolved_url;
|
||||
}
|
||||
} // Unknown image type
|
||||
else {
|
||||
throw new ImageException("Image type unknown", E_WARNING);
|
||||
}
|
||||
}
|
||||
} catch (ImageException $e) {
|
||||
if ($tempfile) {
|
||||
unlink($tempfile);
|
||||
}
|
||||
$resolved_url = self::$broken_image;
|
||||
$type = "png";
|
||||
$message = self::$error_message;
|
||||
Helpers::record_warnings($e->getCode(), $e->getMessage() . " \n $url", $e->getFile(), $e->getLine());
|
||||
self::$_cache[$full_url] = $resolved_url;
|
||||
}
|
||||
|
||||
return [$resolved_url, $type, $message];
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a temp file for the given original image file.
|
||||
*
|
||||
* @param string $filePath The path of the original image.
|
||||
* @param string $tempPath The path of the temp file to register.
|
||||
* @param string $key An optional key to register the temp file at.
|
||||
*/
|
||||
static function addTempImage(string $filePath, string $tempPath, string $key = "default"): void
|
||||
{
|
||||
if (!isset(self::$tempImages[$filePath])) {
|
||||
self::$tempImages[$filePath] = [];
|
||||
}
|
||||
|
||||
self::$tempImages[$filePath][$key] = $tempPath;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the path of a temp file registered for the given original image file.
|
||||
*
|
||||
* @param string $filePath The path of the original image.
|
||||
* @param string $key The key the temp file is registered at.
|
||||
*/
|
||||
static function getTempImage(string $filePath, string $key = "default"): ?string
|
||||
{
|
||||
return self::$tempImages[$filePath][$key] ?? null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Unlink all cached images (i.e. temporary images either downloaded
|
||||
* or converted) except for the bundled "broken image"
|
||||
*/
|
||||
static function clear(bool $debugPng = false)
|
||||
{
|
||||
foreach (self::$_cache as $file) {
|
||||
if ($file === self::$broken_image) {
|
||||
continue;
|
||||
}
|
||||
if ($debugPng) {
|
||||
print "[clear unlink $file]";
|
||||
}
|
||||
unlink($file);
|
||||
}
|
||||
|
||||
foreach (self::$tempImages as $versions) {
|
||||
foreach ($versions as $file) {
|
||||
if ($file === self::$broken_image) {
|
||||
continue;
|
||||
}
|
||||
if ($debugPng) {
|
||||
print "[unlink temp image $file]";
|
||||
}
|
||||
if (file_exists($file)) {
|
||||
unlink($file);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
self::$_cache = [];
|
||||
self::$tempImages = [];
|
||||
}
|
||||
|
||||
static function detect_type($file, $context = null)
|
||||
{
|
||||
list(, , $type) = Helpers::dompdf_getimagesize($file, $context);
|
||||
|
||||
return $type;
|
||||
}
|
||||
|
||||
static function is_broken($url)
|
||||
{
|
||||
return $url === self::$broken_image;
|
||||
}
|
||||
}
|
||||
|
||||
if (file_exists(realpath(__DIR__ . "/../../lib/res/broken_image.svg"))) {
|
||||
Cache::$broken_image = realpath(__DIR__ . "/../../lib/res/broken_image.svg");
|
||||
}
|
|
@ -1,301 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* @package dompdf
|
||||
* @link http://dompdf.github.com/
|
||||
* @author Benj Carson <benjcarson@digitaljunkies.ca>
|
||||
* @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
|
||||
*/
|
||||
namespace Dompdf\Renderer;
|
||||
|
||||
use Dompdf\Frame;
|
||||
use Dompdf\FrameDecorator\Block as BlockFrameDecorator;
|
||||
use Dompdf\Helpers;
|
||||
|
||||
/**
|
||||
* Renders block frames
|
||||
*
|
||||
* @package dompdf
|
||||
*/
|
||||
class Block extends AbstractRenderer
|
||||
{
|
||||
|
||||
/**
|
||||
* @param Frame $frame
|
||||
*/
|
||||
function render(Frame $frame)
|
||||
{
|
||||
$style = $frame->get_style();
|
||||
$node = $frame->get_node();
|
||||
$dompdf = $this->_dompdf;
|
||||
|
||||
$this->_set_opacity($frame->get_opacity($style->opacity));
|
||||
|
||||
[$x, $y, $w, $h] = $frame->get_border_box();
|
||||
|
||||
if ($node->nodeName === "body") {
|
||||
$h = $frame->get_containing_block("h") - (float)$style->length_in_pt([
|
||||
$style->margin_top,
|
||||
$style->border_top_width,
|
||||
$style->border_bottom_width,
|
||||
$style->margin_bottom],
|
||||
(float)$style->length_in_pt($style->width));
|
||||
}
|
||||
|
||||
$border_box = [$x, $y, $w, $h];
|
||||
|
||||
// Draw our background, border and content
|
||||
$this->_render_background($frame, $border_box);
|
||||
$this->_render_border($frame, $border_box);
|
||||
$this->_render_outline($frame, $border_box);
|
||||
|
||||
// Handle anchors & links
|
||||
if ($node->nodeName === "a" && $href = $node->getAttribute("href")) {
|
||||
$href = Helpers::build_url($dompdf->getProtocol(), $dompdf->getBaseHost(), $dompdf->getBasePath(), $href);
|
||||
$this->_canvas->add_link($href, $x, $y, $w, $h);
|
||||
}
|
||||
|
||||
$id = $frame->get_node()->getAttribute("id");
|
||||
if (strlen($id) > 0) {
|
||||
$this->_canvas->add_named_dest($id);
|
||||
}
|
||||
|
||||
$this->debugBlockLayout($frame, "red", false);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Frame $frame
|
||||
* @param float[] $border_box
|
||||
*/
|
||||
protected function _render_background(Frame $frame, array $border_box): void
|
||||
{
|
||||
$style = $frame->get_style();
|
||||
[$x, $y, $w, $h] = $border_box;
|
||||
|
||||
if ($style->has_border_radius()) {
|
||||
[$tl, $tr, $br, $bl] = $style->resolve_border_radius($border_box);
|
||||
$this->_canvas->clipping_roundrectangle($x, $y, $w, $h, $tl, $tr, $br, $bl);
|
||||
}
|
||||
|
||||
if (($bg = $style->background_color) !== "transparent") {
|
||||
$this->_canvas->filled_rectangle($x, $y, $w, $h, $bg);
|
||||
}
|
||||
|
||||
if (($url = $style->background_image) && $url !== "none") {
|
||||
$this->_background_image($url, $x, $y, $w, $h, $style);
|
||||
}
|
||||
|
||||
if ($style->has_border_radius()) {
|
||||
$this->_canvas->clipping_end();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Frame $frame
|
||||
* @param float[] $border_box
|
||||
* @param string $corner_style
|
||||
*/
|
||||
protected function _render_border(Frame $frame, array $border_box, string $corner_style = "bevel"): void
|
||||
{
|
||||
$style = $frame->get_style();
|
||||
$bp = $style->get_border_properties();
|
||||
[$x, $y, $w, $h] = $border_box;
|
||||
[$tl, $tr, $br, $bl] = $style->resolve_border_radius($border_box);
|
||||
|
||||
// Short-cut: If all the borders are "solid" with the same color and style, and no radius, we'd better draw a rectangle
|
||||
if (
|
||||
in_array($bp["top"]["style"], ["solid", "dashed", "dotted"]) &&
|
||||
$bp["top"] == $bp["right"] &&
|
||||
$bp["right"] == $bp["bottom"] &&
|
||||
$bp["bottom"] == $bp["left"] &&
|
||||
!$style->has_border_radius()
|
||||
) {
|
||||
$props = $bp["top"];
|
||||
if ($props["color"] === "transparent" || $props["width"] <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
$width = (float)$style->length_in_pt($props["width"]);
|
||||
$pattern = $this->_get_dash_pattern($props["style"], $width);
|
||||
$this->_canvas->rectangle($x + $width / 2, $y + $width / 2, $w - $width, $h - $width, $props["color"], $width, $pattern);
|
||||
return;
|
||||
}
|
||||
|
||||
// Do it the long way
|
||||
$widths = [
|
||||
(float)$style->length_in_pt($bp["top"]["width"]),
|
||||
(float)$style->length_in_pt($bp["right"]["width"]),
|
||||
(float)$style->length_in_pt($bp["bottom"]["width"]),
|
||||
(float)$style->length_in_pt($bp["left"]["width"])
|
||||
];
|
||||
|
||||
foreach ($bp as $side => $props) {
|
||||
list($x, $y, $w, $h) = $border_box;
|
||||
$length = 0;
|
||||
$r1 = 0;
|
||||
$r2 = 0;
|
||||
|
||||
if (!$props["style"] ||
|
||||
$props["style"] === "none" ||
|
||||
$props["width"] <= 0 ||
|
||||
$props["color"] == "transparent"
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
|
||||
switch ($side) {
|
||||
case "top":
|
||||
$length = $w;
|
||||
$r1 = $tl;
|
||||
$r2 = $tr;
|
||||
break;
|
||||
|
||||
case "bottom":
|
||||
$length = $w;
|
||||
$y += $h;
|
||||
$r1 = $bl;
|
||||
$r2 = $br;
|
||||
break;
|
||||
|
||||
case "left":
|
||||
$length = $h;
|
||||
$r1 = $tl;
|
||||
$r2 = $bl;
|
||||
break;
|
||||
|
||||
case "right":
|
||||
$length = $h;
|
||||
$x += $w;
|
||||
$r1 = $tr;
|
||||
$r2 = $br;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
$method = "_border_" . $props["style"];
|
||||
|
||||
// draw rounded corners
|
||||
$this->$method($x, $y, $length, $props["color"], $widths, $side, $corner_style, $r1, $r2);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Frame $frame
|
||||
* @param float[] $border_box
|
||||
* @param string $corner_style
|
||||
*/
|
||||
protected function _render_outline(Frame $frame, array $border_box, string $corner_style = "bevel"): void
|
||||
{
|
||||
$style = $frame->get_style();
|
||||
|
||||
$width = (float) $style->length_in_pt($style->outline_width);
|
||||
$outline_style = $style->outline_style;
|
||||
$color = $style->outline_color;
|
||||
|
||||
if (!$outline_style || $outline_style === "none" || $color === "transparent" || $width <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
$offset = (float) $style->length_in_pt($style->outline_offset);
|
||||
|
||||
[$x, $y, $w, $h] = $border_box;
|
||||
$d = $width + $offset;
|
||||
$outline_box = [$x - $d, $y - $d, $w + $d * 2, $h + $d * 2];
|
||||
[$tl, $tr, $br, $bl] = $style->resolve_border_radius($border_box, $outline_box);
|
||||
|
||||
$x -= $offset;
|
||||
$y -= $offset;
|
||||
$w += $offset * 2;
|
||||
$h += $offset * 2;
|
||||
|
||||
// For a simple outline, we can draw a rectangle
|
||||
if (in_array($outline_style, ["solid", "dashed", "dotted"], true)
|
||||
&& !$style->has_border_radius()
|
||||
) {
|
||||
$x -= $width / 2;
|
||||
$y -= $width / 2;
|
||||
$w += $width;
|
||||
$h += $width;
|
||||
|
||||
$pattern = $this->_get_dash_pattern($outline_style, $width);
|
||||
$this->_canvas->rectangle($x, $y, $w, $h, $color, $width, $pattern);
|
||||
return;
|
||||
}
|
||||
|
||||
$x -= $width;
|
||||
$y -= $width;
|
||||
$w += $width * 2;
|
||||
$h += $width * 2;
|
||||
|
||||
$method = "_border_" . $outline_style;
|
||||
$widths = array_fill(0, 4, $width);
|
||||
$sides = ["top", "right", "left", "bottom"];
|
||||
|
||||
foreach ($sides as $side) {
|
||||
switch ($side) {
|
||||
case "top":
|
||||
$length = $w;
|
||||
$side_x = $x;
|
||||
$side_y = $y;
|
||||
$r1 = $tl;
|
||||
$r2 = $tr;
|
||||
break;
|
||||
|
||||
case "bottom":
|
||||
$length = $w;
|
||||
$side_x = $x;
|
||||
$side_y = $y + $h;
|
||||
$r1 = $bl;
|
||||
$r2 = $br;
|
||||
break;
|
||||
|
||||
case "left":
|
||||
$length = $h;
|
||||
$side_x = $x;
|
||||
$side_y = $y;
|
||||
$r1 = $tl;
|
||||
$r2 = $bl;
|
||||
break;
|
||||
|
||||
case "right":
|
||||
$length = $h;
|
||||
$side_x = $x + $w;
|
||||
$side_y = $y;
|
||||
$r1 = $tr;
|
||||
$r2 = $br;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
$this->$method($side_x, $side_y, $length, $color, $widths, $side, $corner_style, $r1, $r2);
|
||||
}
|
||||
}
|
||||
|
||||
protected function debugBlockLayout(Frame $frame, ?string $color, bool $lines = false): void
|
||||
{
|
||||
$options = $this->_dompdf->getOptions();
|
||||
$debugLayout = $options->getDebugLayout();
|
||||
|
||||
if (!$debugLayout) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($color && $options->getDebugLayoutBlocks()) {
|
||||
$this->_debug_layout($frame->get_border_box(), $color);
|
||||
|
||||
if ($options->getDebugLayoutPaddingBox()) {
|
||||
$this->_debug_layout($frame->get_padding_box(), $color, [0.5, 0.5]);
|
||||
}
|
||||
}
|
||||
|
||||
if ($lines && $options->getDebugLayoutLines() && $frame instanceof BlockFrameDecorator) {
|
||||
[$cx, , $cw] = $frame->get_content_box();
|
||||
|
||||
foreach ($frame->get_line_boxes() as $line) {
|
||||
$lw = $cw - $line->left - $line->right;
|
||||
$this->_debug_layout([$cx + $line->left, $line->y, $lw, $line->h], "orange");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,164 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* @package dompdf
|
||||
* @link http://dompdf.github.com/
|
||||
* @author Benj Carson <benjcarson@digitaljunkies.ca>
|
||||
* @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
|
||||
*/
|
||||
namespace Dompdf\Renderer;
|
||||
|
||||
use Dompdf\Frame;
|
||||
use Dompdf\Helpers;
|
||||
|
||||
/**
|
||||
* Renders inline frames
|
||||
*
|
||||
* @access private
|
||||
* @package dompdf
|
||||
*/
|
||||
class Inline extends AbstractRenderer
|
||||
{
|
||||
function render(Frame $frame)
|
||||
{
|
||||
if (!$frame->get_first_child()) {
|
||||
return; // No children, no service
|
||||
}
|
||||
|
||||
$style = $frame->get_style();
|
||||
$dompdf = $this->_dompdf;
|
||||
|
||||
// Draw the left border if applicable
|
||||
$bp = $style->get_border_properties();
|
||||
$widths = [
|
||||
(float)$style->length_in_pt($bp["top"]["width"]),
|
||||
(float)$style->length_in_pt($bp["right"]["width"]),
|
||||
(float)$style->length_in_pt($bp["bottom"]["width"]),
|
||||
(float)$style->length_in_pt($bp["left"]["width"])
|
||||
];
|
||||
|
||||
// Draw the background & border behind each child. To do this we need
|
||||
// to figure out just how much space each child takes:
|
||||
list($x, $y) = $frame->get_first_child()->get_position();
|
||||
|
||||
$this->_set_opacity($frame->get_opacity($style->opacity));
|
||||
|
||||
$do_debug_layout_line = $dompdf->getOptions()->getDebugLayout()
|
||||
&& $dompdf->getOptions()->getDebugLayoutInline();
|
||||
|
||||
list($w, $h) = $this->get_child_size($frame, $do_debug_layout_line);
|
||||
|
||||
// make sure the border and background start inside the left margin
|
||||
$left_margin = (float)$style->length_in_pt($style->margin_left);
|
||||
$x += $left_margin;
|
||||
|
||||
// Handle the last child
|
||||
if (($bg = $style->background_color) !== "transparent") {
|
||||
$this->_canvas->filled_rectangle($x + $widths[3], $y + $widths[0], $w, $h, $bg);
|
||||
}
|
||||
|
||||
//On continuation lines (after line break) of inline elements, the style got copied.
|
||||
//But a non repeatable background image should not be repeated on the next line.
|
||||
//But removing the background image above has never an effect, and removing it below
|
||||
//removes it always, even on the initial line.
|
||||
//Need to handle it elsewhere, e.g. on certain ...clone()... usages.
|
||||
// Repeat not given: default is Style::__construct
|
||||
// ... && (!($repeat = $style->background_repeat) || $repeat === "repeat" ...
|
||||
//different position? $this->_background_image($url, $x, $y, $w, $h, $style);
|
||||
if (($url = $style->background_image) && $url !== "none") {
|
||||
$this->_background_image($url, $x + $widths[3], $y + $widths[0], $w, $h, $style);
|
||||
}
|
||||
|
||||
// Add the border widths
|
||||
$w += (float)$widths[1] + (float)$widths[3];
|
||||
$h += (float)$widths[0] + (float)$widths[2];
|
||||
|
||||
// If this is the first row, draw the left border too
|
||||
if ($bp["left"]["style"] !== "none" && $bp["left"]["color"] !== "transparent" && $widths[3] > 0) {
|
||||
$method = "_border_" . $bp["left"]["style"];
|
||||
$this->$method($x, $y, $h, $bp["left"]["color"], $widths, "left");
|
||||
}
|
||||
|
||||
// Draw the top & bottom borders
|
||||
if ($bp["top"]["style"] !== "none" && $bp["top"]["color"] !== "transparent" && $widths[0] > 0) {
|
||||
$method = "_border_" . $bp["top"]["style"];
|
||||
$this->$method($x, $y, $w, $bp["top"]["color"], $widths, "top");
|
||||
}
|
||||
|
||||
if ($bp["bottom"]["style"] !== "none" && $bp["bottom"]["color"] !== "transparent" && $widths[2] > 0) {
|
||||
$method = "_border_" . $bp["bottom"]["style"];
|
||||
$this->$method($x, $y + $h, $w, $bp["bottom"]["color"], $widths, "bottom");
|
||||
}
|
||||
|
||||
// Helpers::var_dump(get_class($frame->get_next_sibling()));
|
||||
// $last_row = get_class($frame->get_next_sibling()) !== 'Inline';
|
||||
// Draw the right border if this is the last row
|
||||
if ($bp["right"]["style"] !== "none" && $bp["right"]["color"] !== "transparent" && $widths[1] > 0) {
|
||||
$method = "_border_" . $bp["right"]["style"];
|
||||
$this->$method($x + $w, $y, $h, $bp["right"]["color"], $widths, "right");
|
||||
}
|
||||
|
||||
$node = $frame->get_node();
|
||||
$id = $node->getAttribute("id");
|
||||
if (strlen($id) > 0) {
|
||||
$this->_canvas->add_named_dest($id);
|
||||
}
|
||||
|
||||
// Only two levels of links frames
|
||||
$is_link_node = $node->nodeName === "a";
|
||||
if ($is_link_node) {
|
||||
if (($name = $node->getAttribute("name"))) {
|
||||
$this->_canvas->add_named_dest($name);
|
||||
}
|
||||
}
|
||||
|
||||
if ($frame->get_parent() && $frame->get_parent()->get_node()->nodeName === "a") {
|
||||
$link_node = $frame->get_parent()->get_node();
|
||||
}
|
||||
|
||||
// Handle anchors & links
|
||||
if ($is_link_node) {
|
||||
if ($href = $node->getAttribute("href")) {
|
||||
$href = Helpers::build_url($dompdf->getProtocol(), $dompdf->getBaseHost(), $dompdf->getBasePath(), $href);
|
||||
$this->_canvas->add_link($href, $x, $y, $w, $h);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected function get_child_size(Frame $frame, bool $do_debug_layout_line): array
|
||||
{
|
||||
$w = 0.0;
|
||||
$h = 0.0;
|
||||
|
||||
foreach ($frame->get_children() as $child) {
|
||||
if ($child->get_node()->nodeValue === " " && $child->get_prev_sibling() && !$child->get_next_sibling()) {
|
||||
break;
|
||||
}
|
||||
|
||||
$style = $child->get_style();
|
||||
list(, , $child_w, $child_h) = $child->get_padding_box();
|
||||
|
||||
$child_h2 = 0.0;
|
||||
|
||||
if ($style->width === "auto") {
|
||||
list($child_w, $child_h2) = $this->get_child_size($child, $do_debug_layout_line);
|
||||
}
|
||||
|
||||
if ($style->height === "auto") {
|
||||
list(, $child_h2) = $this->get_child_size($child, $do_debug_layout_line);
|
||||
}
|
||||
|
||||
$w += $child_w;
|
||||
$h = max($h, $child_h, $child_h2);
|
||||
|
||||
if ($do_debug_layout_line) {
|
||||
$this->_debug_layout($child->get_border_box(), "blue");
|
||||
|
||||
if ($this->_dompdf->getOptions()->getDebugLayoutPaddingBox()) {
|
||||
$this->_debug_layout($child->get_padding_box(), "blue", [0.5, 0.5]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return [$w, $h];
|
||||
}
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
<?php
|
||||
|
||||
// autoload.php @generated by Composer
|
||||
|
||||
require_once __DIR__ . '/composer/autoload_real.php';
|
||||
|
||||
return ComposerAutoloaderInit47dfdbccdbe2c66869f4658d0723ed1a::getLoader();
|
|
@ -0,0 +1,572 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Composer.
|
||||
*
|
||||
* (c) Nils Adermann <naderman@naderman.de>
|
||||
* Jordi Boggiano <j.boggiano@seld.be>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Composer\Autoload;
|
||||
|
||||
/**
|
||||
* ClassLoader implements a PSR-0, PSR-4 and classmap class loader.
|
||||
*
|
||||
* $loader = new \Composer\Autoload\ClassLoader();
|
||||
*
|
||||
* // register classes with namespaces
|
||||
* $loader->add('Symfony\Component', __DIR__.'/component');
|
||||
* $loader->add('Symfony', __DIR__.'/framework');
|
||||
*
|
||||
* // activate the autoloader
|
||||
* $loader->register();
|
||||
*
|
||||
* // to enable searching the include path (eg. for PEAR packages)
|
||||
* $loader->setUseIncludePath(true);
|
||||
*
|
||||
* In this example, if you try to use a class in the Symfony\Component
|
||||
* namespace or one of its children (Symfony\Component\Console for instance),
|
||||
* the autoloader will first look for the class under the component/
|
||||
* directory, and it will then fallback to the framework/ directory if not
|
||||
* found before giving up.
|
||||
*
|
||||
* This class is loosely based on the Symfony UniversalClassLoader.
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
* @author Jordi Boggiano <j.boggiano@seld.be>
|
||||
* @see https://www.php-fig.org/psr/psr-0/
|
||||
* @see https://www.php-fig.org/psr/psr-4/
|
||||
*/
|
||||
class ClassLoader
|
||||
{
|
||||
/** @var ?string */
|
||||
private $vendorDir;
|
||||
|
||||
// PSR-4
|
||||
/**
|
||||
* @var array[]
|
||||
* @psalm-var array<string, array<string, int>>
|
||||
*/
|
||||
private $prefixLengthsPsr4 = array();
|
||||
/**
|
||||
* @var array[]
|
||||
* @psalm-var array<string, array<int, string>>
|
||||
*/
|
||||
private $prefixDirsPsr4 = array();
|
||||
/**
|
||||
* @var array[]
|
||||
* @psalm-var array<string, string>
|
||||
*/
|
||||
private $fallbackDirsPsr4 = array();
|
||||
|
||||
// PSR-0
|
||||
/**
|
||||
* @var array[]
|
||||
* @psalm-var array<string, array<string, string[]>>
|
||||
*/
|
||||
private $prefixesPsr0 = array();
|
||||
/**
|
||||
* @var array[]
|
||||
* @psalm-var array<string, string>
|
||||
*/
|
||||
private $fallbackDirsPsr0 = array();
|
||||
|
||||
/** @var bool */
|
||||
private $useIncludePath = false;
|
||||
|
||||
/**
|
||||
* @var string[]
|
||||
* @psalm-var array<string, string>
|
||||
*/
|
||||
private $classMap = array();
|
||||
|
||||
/** @var bool */
|
||||
private $classMapAuthoritative = false;
|
||||
|
||||
/**
|
||||
* @var bool[]
|
||||
* @psalm-var array<string, bool>
|
||||
*/
|
||||
private $missingClasses = array();
|
||||
|
||||
/** @var ?string */
|
||||
private $apcuPrefix;
|
||||
|
||||
/**
|
||||
* @var self[]
|
||||
*/
|
||||
private static $registeredLoaders = array();
|
||||
|
||||
/**
|
||||
* @param ?string $vendorDir
|
||||
*/
|
||||
public function __construct($vendorDir = null)
|
||||
{
|
||||
$this->vendorDir = $vendorDir;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public function getPrefixes()
|
||||
{
|
||||
if (!empty($this->prefixesPsr0)) {
|
||||
return call_user_func_array('array_merge', array_values($this->prefixesPsr0));
|
||||
}
|
||||
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array[]
|
||||
* @psalm-return array<string, array<int, string>>
|
||||
*/
|
||||
public function getPrefixesPsr4()
|
||||
{
|
||||
return $this->prefixDirsPsr4;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array[]
|
||||
* @psalm-return array<string, string>
|
||||
*/
|
||||
public function getFallbackDirs()
|
||||
{
|
||||
return $this->fallbackDirsPsr0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array[]
|
||||
* @psalm-return array<string, string>
|
||||
*/
|
||||
public function getFallbackDirsPsr4()
|
||||
{
|
||||
return $this->fallbackDirsPsr4;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string[] Array of classname => path
|
||||
* @psalm-return array<string, string>
|
||||
*/
|
||||
public function getClassMap()
|
||||
{
|
||||
return $this->classMap;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string[] $classMap Class to filename map
|
||||
* @psalm-param array<string, string> $classMap
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function addClassMap(array $classMap)
|
||||
{
|
||||
if ($this->classMap) {
|
||||
$this->classMap = array_merge($this->classMap, $classMap);
|
||||
} else {
|
||||
$this->classMap = $classMap;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a set of PSR-0 directories for a given prefix, either
|
||||
* appending or prepending to the ones previously set for this prefix.
|
||||
*
|
||||
* @param string $prefix The prefix
|
||||
* @param string[]|string $paths The PSR-0 root directories
|
||||
* @param bool $prepend Whether to prepend the directories
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function add($prefix, $paths, $prepend = false)
|
||||
{
|
||||
if (!$prefix) {
|
||||
if ($prepend) {
|
||||
$this->fallbackDirsPsr0 = array_merge(
|
||||
(array) $paths,
|
||||
$this->fallbackDirsPsr0
|
||||
);
|
||||
} else {
|
||||
$this->fallbackDirsPsr0 = array_merge(
|
||||
$this->fallbackDirsPsr0,
|
||||
(array) $paths
|
||||
);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$first = $prefix[0];
|
||||
if (!isset($this->prefixesPsr0[$first][$prefix])) {
|
||||
$this->prefixesPsr0[$first][$prefix] = (array) $paths;
|
||||
|
||||
return;
|
||||
}
|
||||
if ($prepend) {
|
||||
$this->prefixesPsr0[$first][$prefix] = array_merge(
|
||||
(array) $paths,
|
||||
$this->prefixesPsr0[$first][$prefix]
|
||||
);
|
||||
} else {
|
||||
$this->prefixesPsr0[$first][$prefix] = array_merge(
|
||||
$this->prefixesPsr0[$first][$prefix],
|
||||
(array) $paths
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a set of PSR-4 directories for a given namespace, either
|
||||
* appending or prepending to the ones previously set for this namespace.
|
||||
*
|
||||
* @param string $prefix The prefix/namespace, with trailing '\\'
|
||||
* @param string[]|string $paths The PSR-4 base directories
|
||||
* @param bool $prepend Whether to prepend the directories
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function addPsr4($prefix, $paths, $prepend = false)
|
||||
{
|
||||
if (!$prefix) {
|
||||
// Register directories for the root namespace.
|
||||
if ($prepend) {
|
||||
$this->fallbackDirsPsr4 = array_merge(
|
||||
(array) $paths,
|
||||
$this->fallbackDirsPsr4
|
||||
);
|
||||
} else {
|
||||
$this->fallbackDirsPsr4 = array_merge(
|
||||
$this->fallbackDirsPsr4,
|
||||
(array) $paths
|
||||
);
|
||||
}
|
||||
} elseif (!isset($this->prefixDirsPsr4[$prefix])) {
|
||||
// Register directories for a new namespace.
|
||||
$length = strlen($prefix);
|
||||
if ('\\' !== $prefix[$length - 1]) {
|
||||
throw new \InvalidArgumentException("A non-empty PSR-4 prefix must end with a namespace separator.");
|
||||
}
|
||||
$this->prefixLengthsPsr4[$prefix[0]][$prefix] = $length;
|
||||
$this->prefixDirsPsr4[$prefix] = (array) $paths;
|
||||
} elseif ($prepend) {
|
||||
// Prepend directories for an already registered namespace.
|
||||
$this->prefixDirsPsr4[$prefix] = array_merge(
|
||||
(array) $paths,
|
||||
$this->prefixDirsPsr4[$prefix]
|
||||
);
|
||||
} else {
|
||||
// Append directories for an already registered namespace.
|
||||
$this->prefixDirsPsr4[$prefix] = array_merge(
|
||||
$this->prefixDirsPsr4[$prefix],
|
||||
(array) $paths
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a set of PSR-0 directories for a given prefix,
|
||||
* replacing any others previously set for this prefix.
|
||||
*
|
||||
* @param string $prefix The prefix
|
||||
* @param string[]|string $paths The PSR-0 base directories
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function set($prefix, $paths)
|
||||
{
|
||||
if (!$prefix) {
|
||||
$this->fallbackDirsPsr0 = (array) $paths;
|
||||
} else {
|
||||
$this->prefixesPsr0[$prefix[0]][$prefix] = (array) $paths;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a set of PSR-4 directories for a given namespace,
|
||||
* replacing any others previously set for this namespace.
|
||||
*
|
||||
* @param string $prefix The prefix/namespace, with trailing '\\'
|
||||
* @param string[]|string $paths The PSR-4 base directories
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setPsr4($prefix, $paths)
|
||||
{
|
||||
if (!$prefix) {
|
||||
$this->fallbackDirsPsr4 = (array) $paths;
|
||||
} else {
|
||||
$length = strlen($prefix);
|
||||
if ('\\' !== $prefix[$length - 1]) {
|
||||
throw new \InvalidArgumentException("A non-empty PSR-4 prefix must end with a namespace separator.");
|
||||
}
|
||||
$this->prefixLengthsPsr4[$prefix[0]][$prefix] = $length;
|
||||
$this->prefixDirsPsr4[$prefix] = (array) $paths;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Turns on searching the include path for class files.
|
||||
*
|
||||
* @param bool $useIncludePath
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setUseIncludePath($useIncludePath)
|
||||
{
|
||||
$this->useIncludePath = $useIncludePath;
|
||||
}
|
||||
|
||||
/**
|
||||
* Can be used to check if the autoloader uses the include path to check
|
||||
* for classes.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function getUseIncludePath()
|
||||
{
|
||||
return $this->useIncludePath;
|
||||
}
|
||||
|
||||
/**
|
||||
* Turns off searching the prefix and fallback directories for classes
|
||||
* that have not been registered with the class map.
|
||||
*
|
||||
* @param bool $classMapAuthoritative
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setClassMapAuthoritative($classMapAuthoritative)
|
||||
{
|
||||
$this->classMapAuthoritative = $classMapAuthoritative;
|
||||
}
|
||||
|
||||
/**
|
||||
* Should class lookup fail if not found in the current class map?
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isClassMapAuthoritative()
|
||||
{
|
||||
return $this->classMapAuthoritative;
|
||||
}
|
||||
|
||||
/**
|
||||
* APCu prefix to use to cache found/not-found classes, if the extension is enabled.
|
||||
*
|
||||
* @param string|null $apcuPrefix
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setApcuPrefix($apcuPrefix)
|
||||
{
|
||||
$this->apcuPrefix = function_exists('apcu_fetch') && filter_var(ini_get('apc.enabled'), FILTER_VALIDATE_BOOLEAN) ? $apcuPrefix : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* The APCu prefix in use, or null if APCu caching is not enabled.
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function getApcuPrefix()
|
||||
{
|
||||
return $this->apcuPrefix;
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers this instance as an autoloader.
|
||||
*
|
||||
* @param bool $prepend Whether to prepend the autoloader or not
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function register($prepend = false)
|
||||
{
|
||||
spl_autoload_register(array($this, 'loadClass'), true, $prepend);
|
||||
|
||||
if (null === $this->vendorDir) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($prepend) {
|
||||
self::$registeredLoaders = array($this->vendorDir => $this) + self::$registeredLoaders;
|
||||
} else {
|
||||
unset(self::$registeredLoaders[$this->vendorDir]);
|
||||
self::$registeredLoaders[$this->vendorDir] = $this;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Unregisters this instance as an autoloader.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function unregister()
|
||||
{
|
||||
spl_autoload_unregister(array($this, 'loadClass'));
|
||||
|
||||
if (null !== $this->vendorDir) {
|
||||
unset(self::$registeredLoaders[$this->vendorDir]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads the given class or interface.
|
||||
*
|
||||
* @param string $class The name of the class
|
||||
* @return true|null True if loaded, null otherwise
|
||||
*/
|
||||
public function loadClass($class)
|
||||
{
|
||||
if ($file = $this->findFile($class)) {
|
||||
includeFile($file);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds the path to the file where the class is defined.
|
||||
*
|
||||
* @param string $class The name of the class
|
||||
*
|
||||
* @return string|false The path if found, false otherwise
|
||||
*/
|
||||
public function findFile($class)
|
||||
{
|
||||
// class map lookup
|
||||
if (isset($this->classMap[$class])) {
|
||||
return $this->classMap[$class];
|
||||
}
|
||||
if ($this->classMapAuthoritative || isset($this->missingClasses[$class])) {
|
||||
return false;
|
||||
}
|
||||
if (null !== $this->apcuPrefix) {
|
||||
$file = apcu_fetch($this->apcuPrefix.$class, $hit);
|
||||
if ($hit) {
|
||||
return $file;
|
||||
}
|
||||
}
|
||||
|
||||
$file = $this->findFileWithExtension($class, '.php');
|
||||
|
||||
// Search for Hack files if we are running on HHVM
|
||||
if (false === $file && defined('HHVM_VERSION')) {
|
||||
$file = $this->findFileWithExtension($class, '.hh');
|
||||
}
|
||||
|
||||
if (null !== $this->apcuPrefix) {
|
||||
apcu_add($this->apcuPrefix.$class, $file);
|
||||
}
|
||||
|
||||
if (false === $file) {
|
||||
// Remember that this class does not exist.
|
||||
$this->missingClasses[$class] = true;
|
||||
}
|
||||
|
||||
return $file;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the currently registered loaders indexed by their corresponding vendor directories.
|
||||
*
|
||||
* @return self[]
|
||||
*/
|
||||
public static function getRegisteredLoaders()
|
||||
{
|
||||
return self::$registeredLoaders;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $class
|
||||
* @param string $ext
|
||||
* @return string|false
|
||||
*/
|
||||
private function findFileWithExtension($class, $ext)
|
||||
{
|
||||
// PSR-4 lookup
|
||||
$logicalPathPsr4 = strtr($class, '\\', DIRECTORY_SEPARATOR) . $ext;
|
||||
|
||||
$first = $class[0];
|
||||
if (isset($this->prefixLengthsPsr4[$first])) {
|
||||
$subPath = $class;
|
||||
while (false !== $lastPos = strrpos($subPath, '\\')) {
|
||||
$subPath = substr($subPath, 0, $lastPos);
|
||||
$search = $subPath . '\\';
|
||||
if (isset($this->prefixDirsPsr4[$search])) {
|
||||
$pathEnd = DIRECTORY_SEPARATOR . substr($logicalPathPsr4, $lastPos + 1);
|
||||
foreach ($this->prefixDirsPsr4[$search] as $dir) {
|
||||
if (file_exists($file = $dir . $pathEnd)) {
|
||||
return $file;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// PSR-4 fallback dirs
|
||||
foreach ($this->fallbackDirsPsr4 as $dir) {
|
||||
if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr4)) {
|
||||
return $file;
|
||||
}
|
||||
}
|
||||
|
||||
// PSR-0 lookup
|
||||
if (false !== $pos = strrpos($class, '\\')) {
|
||||
// namespaced class name
|
||||
$logicalPathPsr0 = substr($logicalPathPsr4, 0, $pos + 1)
|
||||
. strtr(substr($logicalPathPsr4, $pos + 1), '_', DIRECTORY_SEPARATOR);
|
||||
} else {
|
||||
// PEAR-like class name
|
||||
$logicalPathPsr0 = strtr($class, '_', DIRECTORY_SEPARATOR) . $ext;
|
||||
}
|
||||
|
||||
if (isset($this->prefixesPsr0[$first])) {
|
||||
foreach ($this->prefixesPsr0[$first] as $prefix => $dirs) {
|
||||
if (0 === strpos($class, $prefix)) {
|
||||
foreach ($dirs as $dir) {
|
||||
if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) {
|
||||
return $file;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// PSR-0 fallback dirs
|
||||
foreach ($this->fallbackDirsPsr0 as $dir) {
|
||||
if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) {
|
||||
return $file;
|
||||
}
|
||||
}
|
||||
|
||||
// PSR-0 include paths.
|
||||
if ($this->useIncludePath && $file = stream_resolve_include_path($logicalPathPsr0)) {
|
||||
return $file;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Scope isolated include.
|
||||
*
|
||||
* Prevents access to $this/self from included files.
|
||||
*
|
||||
* @param string $file
|
||||
* @return void
|
||||
* @private
|
||||
*/
|
||||
function includeFile($file)
|
||||
{
|
||||
include $file;
|
||||
}
|
|
@ -0,0 +1,350 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Composer.
|
||||
*
|
||||
* (c) Nils Adermann <naderman@naderman.de>
|
||||
* Jordi Boggiano <j.boggiano@seld.be>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Composer;
|
||||
|
||||
use Composer\Autoload\ClassLoader;
|
||||
use Composer\Semver\VersionParser;
|
||||
|
||||
/**
|
||||
* This class is copied in every Composer installed project and available to all
|
||||
*
|
||||
* See also https://getcomposer.org/doc/07-runtime.md#installed-versions
|
||||
*
|
||||
* To require its presence, you can require `composer-runtime-api ^2.0`
|
||||
*/
|
||||
class InstalledVersions
|
||||
{
|
||||
/**
|
||||
* @var mixed[]|null
|
||||
* @psalm-var array{root: array{name: string, version: string, reference: string, pretty_version: string, aliases: string[], dev: bool, install_path: string, type: string}, versions: array<string, array{dev_requirement: bool, pretty_version?: string, version?: string, aliases?: string[], reference?: string, replaced?: string[], provided?: string[], install_path?: string, type?: string}>}|array{}|null
|
||||
*/
|
||||
private static $installed;
|
||||
|
||||
/**
|
||||
* @var bool|null
|
||||
*/
|
||||
private static $canGetVendors;
|
||||
|
||||
/**
|
||||
* @var array[]
|
||||
* @psalm-var array<string, array{root: array{name: string, version: string, reference: string, pretty_version: string, aliases: string[], dev: bool, install_path: string, type: string}, versions: array<string, array{dev_requirement: bool, pretty_version?: string, version?: string, aliases?: string[], reference?: string, replaced?: string[], provided?: string[], install_path?: string, type?: string}>}>
|
||||
*/
|
||||
private static $installedByVendor = array();
|
||||
|
||||
/**
|
||||
* Returns a list of all package names which are present, either by being installed, replaced or provided
|
||||
*
|
||||
* @return string[]
|
||||
* @psalm-return list<string>
|
||||
*/
|
||||
public static function getInstalledPackages()
|
||||
{
|
||||
$packages = array();
|
||||
foreach (self::getInstalled() as $installed) {
|
||||
$packages[] = array_keys($installed['versions']);
|
||||
}
|
||||
|
||||
if (1 === \count($packages)) {
|
||||
return $packages[0];
|
||||
}
|
||||
|
||||
return array_keys(array_flip(\call_user_func_array('array_merge', $packages)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list of all package names with a specific type e.g. 'library'
|
||||
*
|
||||
* @param string $type
|
||||
* @return string[]
|
||||
* @psalm-return list<string>
|
||||
*/
|
||||
public static function getInstalledPackagesByType($type)
|
||||
{
|
||||
$packagesByType = array();
|
||||
|
||||
foreach (self::getInstalled() as $installed) {
|
||||
foreach ($installed['versions'] as $name => $package) {
|
||||
if (isset($package['type']) && $package['type'] === $type) {
|
||||
$packagesByType[] = $name;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $packagesByType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether the given package is installed
|
||||
*
|
||||
* This also returns true if the package name is provided or replaced by another package
|
||||
*
|
||||
* @param string $packageName
|
||||
* @param bool $includeDevRequirements
|
||||
* @return bool
|
||||
*/
|
||||
public static function isInstalled($packageName, $includeDevRequirements = true)
|
||||
{
|
||||
foreach (self::getInstalled() as $installed) {
|
||||
if (isset($installed['versions'][$packageName])) {
|
||||
return $includeDevRequirements || empty($installed['versions'][$packageName]['dev_requirement']);
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether the given package satisfies a version constraint
|
||||
*
|
||||
* e.g. If you want to know whether version 2.3+ of package foo/bar is installed, you would call:
|
||||
*
|
||||
* Composer\InstalledVersions::satisfies(new VersionParser, 'foo/bar', '^2.3')
|
||||
*
|
||||
* @param VersionParser $parser Install composer/semver to have access to this class and functionality
|
||||
* @param string $packageName
|
||||
* @param string|null $constraint A version constraint to check for, if you pass one you have to make sure composer/semver is required by your package
|
||||
* @return bool
|
||||
*/
|
||||
public static function satisfies(VersionParser $parser, $packageName, $constraint)
|
||||
{
|
||||
$constraint = $parser->parseConstraints($constraint);
|
||||
$provided = $parser->parseConstraints(self::getVersionRanges($packageName));
|
||||
|
||||
return $provided->matches($constraint);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a version constraint representing all the range(s) which are installed for a given package
|
||||
*
|
||||
* It is easier to use this via isInstalled() with the $constraint argument if you need to check
|
||||
* whether a given version of a package is installed, and not just whether it exists
|
||||
*
|
||||
* @param string $packageName
|
||||
* @return string Version constraint usable with composer/semver
|
||||
*/
|
||||
public static function getVersionRanges($packageName)
|
||||
{
|
||||
foreach (self::getInstalled() as $installed) {
|
||||
if (!isset($installed['versions'][$packageName])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$ranges = array();
|
||||
if (isset($installed['versions'][$packageName]['pretty_version'])) {
|
||||
$ranges[] = $installed['versions'][$packageName]['pretty_version'];
|
||||
}
|
||||
if (array_key_exists('aliases', $installed['versions'][$packageName])) {
|
||||
$ranges = array_merge($ranges, $installed['versions'][$packageName]['aliases']);
|
||||
}
|
||||
if (array_key_exists('replaced', $installed['versions'][$packageName])) {
|
||||
$ranges = array_merge($ranges, $installed['versions'][$packageName]['replaced']);
|
||||
}
|
||||
if (array_key_exists('provided', $installed['versions'][$packageName])) {
|
||||
$ranges = array_merge($ranges, $installed['versions'][$packageName]['provided']);
|
||||
}
|
||||
|
||||
return implode(' || ', $ranges);
|
||||
}
|
||||
|
||||
throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $packageName
|
||||
* @return string|null If the package is being replaced or provided but is not really installed, null will be returned as version, use satisfies or getVersionRanges if you need to know if a given version is present
|
||||
*/
|
||||
public static function getVersion($packageName)
|
||||
{
|
||||
foreach (self::getInstalled() as $installed) {
|
||||
if (!isset($installed['versions'][$packageName])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!isset($installed['versions'][$packageName]['version'])) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $installed['versions'][$packageName]['version'];
|
||||
}
|
||||
|
||||
throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $packageName
|
||||
* @return string|null If the package is being replaced or provided but is not really installed, null will be returned as version, use satisfies or getVersionRanges if you need to know if a given version is present
|
||||
*/
|
||||
public static function getPrettyVersion($packageName)
|
||||
{
|
||||
foreach (self::getInstalled() as $installed) {
|
||||
if (!isset($installed['versions'][$packageName])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!isset($installed['versions'][$packageName]['pretty_version'])) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $installed['versions'][$packageName]['pretty_version'];
|
||||
}
|
||||
|
||||
throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $packageName
|
||||
* @return string|null If the package is being replaced or provided but is not really installed, null will be returned as reference
|
||||
*/
|
||||
public static function getReference($packageName)
|
||||
{
|
||||
foreach (self::getInstalled() as $installed) {
|
||||
if (!isset($installed['versions'][$packageName])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!isset($installed['versions'][$packageName]['reference'])) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $installed['versions'][$packageName]['reference'];
|
||||
}
|
||||
|
||||
throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $packageName
|
||||
* @return string|null If the package is being replaced or provided but is not really installed, null will be returned as install path. Packages of type metapackages also have a null install path.
|
||||
*/
|
||||
public static function getInstallPath($packageName)
|
||||
{
|
||||
foreach (self::getInstalled() as $installed) {
|
||||
if (!isset($installed['versions'][$packageName])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
return isset($installed['versions'][$packageName]['install_path']) ? $installed['versions'][$packageName]['install_path'] : null;
|
||||
}
|
||||
|
||||
throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
* @psalm-return array{name: string, version: string, reference: string, pretty_version: string, aliases: string[], dev: bool, install_path: string, type: string}
|
||||
*/
|
||||
public static function getRootPackage()
|
||||
{
|
||||
$installed = self::getInstalled();
|
||||
|
||||
return $installed[0]['root'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the raw installed.php data for custom implementations
|
||||
*
|
||||
* @deprecated Use getAllRawData() instead which returns all datasets for all autoloaders present in the process. getRawData only returns the first dataset loaded, which may not be what you expect.
|
||||
* @return array[]
|
||||
* @psalm-return array{root: array{name: string, version: string, reference: string, pretty_version: string, aliases: string[], dev: bool, install_path: string, type: string}, versions: array<string, array{dev_requirement: bool, pretty_version?: string, version?: string, aliases?: string[], reference?: string, replaced?: string[], provided?: string[], install_path?: string, type?: string}>}
|
||||
*/
|
||||
public static function getRawData()
|
||||
{
|
||||
@trigger_error('getRawData only returns the first dataset loaded, which may not be what you expect. Use getAllRawData() instead which returns all datasets for all autoloaders present in the process.', E_USER_DEPRECATED);
|
||||
|
||||
if (null === self::$installed) {
|
||||
// only require the installed.php file if this file is loaded from its dumped location,
|
||||
// and not from its source location in the composer/composer package, see https://github.com/composer/composer/issues/9937
|
||||
if (substr(__DIR__, -8, 1) !== 'C') {
|
||||
self::$installed = include __DIR__ . '/installed.php';
|
||||
} else {
|
||||
self::$installed = array();
|
||||
}
|
||||
}
|
||||
|
||||
return self::$installed;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the raw data of all installed.php which are currently loaded for custom implementations
|
||||
*
|
||||
* @return array[]
|
||||
* @psalm-return list<array{root: array{name: string, version: string, reference: string, pretty_version: string, aliases: string[], dev: bool, install_path: string, type: string}, versions: array<string, array{dev_requirement: bool, pretty_version?: string, version?: string, aliases?: string[], reference?: string, replaced?: string[], provided?: string[], install_path?: string, type?: string}>}>
|
||||
*/
|
||||
public static function getAllRawData()
|
||||
{
|
||||
return self::getInstalled();
|
||||
}
|
||||
|
||||
/**
|
||||
* Lets you reload the static array from another file
|
||||
*
|
||||
* This is only useful for complex integrations in which a project needs to use
|
||||
* this class but then also needs to execute another project's autoloader in process,
|
||||
* and wants to ensure both projects have access to their version of installed.php.
|
||||
*
|
||||
* A typical case would be PHPUnit, where it would need to make sure it reads all
|
||||
* the data it needs from this class, then call reload() with
|
||||
* `require $CWD/vendor/composer/installed.php` (or similar) as input to make sure
|
||||
* the project in which it runs can then also use this class safely, without
|
||||
* interference between PHPUnit's dependencies and the project's dependencies.
|
||||
*
|
||||
* @param array[] $data A vendor/composer/installed.php data set
|
||||
* @return void
|
||||
*
|
||||
* @psalm-param array{root: array{name: string, version: string, reference: string, pretty_version: string, aliases: string[], dev: bool, install_path: string, type: string}, versions: array<string, array{dev_requirement: bool, pretty_version?: string, version?: string, aliases?: string[], reference?: string, replaced?: string[], provided?: string[], install_path?: string, type?: string}>} $data
|
||||
*/
|
||||
public static function reload($data)
|
||||
{
|
||||
self::$installed = $data;
|
||||
self::$installedByVendor = array();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array[]
|
||||
* @psalm-return list<array{root: array{name: string, version: string, reference: string, pretty_version: string, aliases: string[], dev: bool, install_path: string, type: string}, versions: array<string, array{dev_requirement: bool, pretty_version?: string, version?: string, aliases?: string[], reference?: string, replaced?: string[], provided?: string[], install_path?: string, type?: string}>}>
|
||||
*/
|
||||
private static function getInstalled()
|
||||
{
|
||||
if (null === self::$canGetVendors) {
|
||||
self::$canGetVendors = method_exists('Composer\Autoload\ClassLoader', 'getRegisteredLoaders');
|
||||
}
|
||||
|
||||
$installed = array();
|
||||
|
||||
if (self::$canGetVendors) {
|
||||
foreach (ClassLoader::getRegisteredLoaders() as $vendorDir => $loader) {
|
||||
if (isset(self::$installedByVendor[$vendorDir])) {
|
||||
$installed[] = self::$installedByVendor[$vendorDir];
|
||||
} elseif (is_file($vendorDir.'/composer/installed.php')) {
|
||||
$installed[] = self::$installedByVendor[$vendorDir] = require $vendorDir.'/composer/installed.php';
|
||||
if (null === self::$installed && strtr($vendorDir.'/composer', '\\', '/') === strtr(__DIR__, '\\', '/')) {
|
||||
self::$installed = $installed[count($installed) - 1];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (null === self::$installed) {
|
||||
// only require the installed.php file if this file is loaded from its dumped location,
|
||||
// and not from its source location in the composer/composer package, see https://github.com/composer/composer/issues/9937
|
||||
if (substr(__DIR__, -8, 1) !== 'C') {
|
||||
self::$installed = require __DIR__ . '/installed.php';
|
||||
} else {
|
||||
self::$installed = array();
|
||||
}
|
||||
}
|
||||
$installed[] = self::$installed;
|
||||
|
||||
return $installed;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
|
||||
Copyright (c) Nils Adermann, Jordi Boggiano
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is furnished
|
||||
to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
<?php
|
||||
|
||||
// autoload_classmap.php @generated by Composer
|
||||
|
||||
$vendorDir = dirname(dirname(__FILE__));
|
||||
$baseDir = dirname($vendorDir);
|
||||
|
||||
return array(
|
||||
'Composer\\InstalledVersions' => $vendorDir . '/composer/InstalledVersions.php',
|
||||
'Dompdf\\Cpdf' => $vendorDir . '/dompdf/dompdf/lib/Cpdf.php',
|
||||
);
|
|
@ -0,0 +1,9 @@
|
|||
<?php
|
||||
|
||||
// autoload_namespaces.php @generated by Composer
|
||||
|
||||
$vendorDir = dirname(dirname(__FILE__));
|
||||
$baseDir = dirname($vendorDir);
|
||||
|
||||
return array(
|
||||
);
|
|
@ -0,0 +1,14 @@
|
|||
<?php
|
||||
|
||||
// autoload_psr4.php @generated by Composer
|
||||
|
||||
$vendorDir = dirname(dirname(__FILE__));
|
||||
$baseDir = dirname($vendorDir);
|
||||
|
||||
return array(
|
||||
'Svg\\' => array($vendorDir . '/phenx/php-svg-lib/src/Svg'),
|
||||
'Sabberworm\\CSS\\' => array($vendorDir . '/sabberworm/php-css-parser/src'),
|
||||
'Masterminds\\' => array($vendorDir . '/masterminds/html5/src'),
|
||||
'FontLib\\' => array($vendorDir . '/phenx/php-font-lib/src/FontLib'),
|
||||
'Dompdf\\' => array($vendorDir . '/dompdf/dompdf/src'),
|
||||
);
|
|
@ -0,0 +1,57 @@
|
|||
<?php
|
||||
|
||||
// autoload_real.php @generated by Composer
|
||||
|
||||
class ComposerAutoloaderInit47dfdbccdbe2c66869f4658d0723ed1a
|
||||
{
|
||||
private static $loader;
|
||||
|
||||
public static function loadClassLoader($class)
|
||||
{
|
||||
if ('Composer\Autoload\ClassLoader' === $class) {
|
||||
require __DIR__ . '/ClassLoader.php';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Composer\Autoload\ClassLoader
|
||||
*/
|
||||
public static function getLoader()
|
||||
{
|
||||
if (null !== self::$loader) {
|
||||
return self::$loader;
|
||||
}
|
||||
|
||||
require __DIR__ . '/platform_check.php';
|
||||
|
||||
spl_autoload_register(array('ComposerAutoloaderInit47dfdbccdbe2c66869f4658d0723ed1a', 'loadClassLoader'), true, true);
|
||||
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(\dirname(__FILE__)));
|
||||
spl_autoload_unregister(array('ComposerAutoloaderInit47dfdbccdbe2c66869f4658d0723ed1a', 'loadClassLoader'));
|
||||
|
||||
$useStaticLoader = PHP_VERSION_ID >= 50600 && !defined('HHVM_VERSION') && (!function_exists('zend_loader_file_encoded') || !zend_loader_file_encoded());
|
||||
if ($useStaticLoader) {
|
||||
require __DIR__ . '/autoload_static.php';
|
||||
|
||||
call_user_func(\Composer\Autoload\ComposerStaticInit47dfdbccdbe2c66869f4658d0723ed1a::getInitializer($loader));
|
||||
} else {
|
||||
$map = require __DIR__ . '/autoload_namespaces.php';
|
||||
foreach ($map as $namespace => $path) {
|
||||
$loader->set($namespace, $path);
|
||||
}
|
||||
|
||||
$map = require __DIR__ . '/autoload_psr4.php';
|
||||
foreach ($map as $namespace => $path) {
|
||||
$loader->setPsr4($namespace, $path);
|
||||
}
|
||||
|
||||
$classMap = require __DIR__ . '/autoload_classmap.php';
|
||||
if ($classMap) {
|
||||
$loader->addClassMap($classMap);
|
||||
}
|
||||
}
|
||||
|
||||
$loader->register(true);
|
||||
|
||||
return $loader;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,66 @@
|
|||
<?php
|
||||
|
||||
// autoload_static.php @generated by Composer
|
||||
|
||||
namespace Composer\Autoload;
|
||||
|
||||
class ComposerStaticInit47dfdbccdbe2c66869f4658d0723ed1a
|
||||
{
|
||||
public static $prefixLengthsPsr4 = array (
|
||||
'S' =>
|
||||
array (
|
||||
'Svg\\' => 4,
|
||||
'Sabberworm\\CSS\\' => 15,
|
||||
),
|
||||
'M' =>
|
||||
array (
|
||||
'Masterminds\\' => 12,
|
||||
),
|
||||
'F' =>
|
||||
array (
|
||||
'FontLib\\' => 8,
|
||||
),
|
||||
'D' =>
|
||||
array (
|
||||
'Dompdf\\' => 7,
|
||||
),
|
||||
);
|
||||
|
||||
public static $prefixDirsPsr4 = array (
|
||||
'Svg\\' =>
|
||||
array (
|
||||
0 => __DIR__ . '/..' . '/phenx/php-svg-lib/src/Svg',
|
||||
),
|
||||
'Sabberworm\\CSS\\' =>
|
||||
array (
|
||||
0 => __DIR__ . '/..' . '/sabberworm/php-css-parser/src',
|
||||
),
|
||||
'Masterminds\\' =>
|
||||
array (
|
||||
0 => __DIR__ . '/..' . '/masterminds/html5/src',
|
||||
),
|
||||
'FontLib\\' =>
|
||||
array (
|
||||
0 => __DIR__ . '/..' . '/phenx/php-font-lib/src/FontLib',
|
||||
),
|
||||
'Dompdf\\' =>
|
||||
array (
|
||||
0 => __DIR__ . '/..' . '/dompdf/dompdf/src',
|
||||
),
|
||||
);
|
||||
|
||||
public static $classMap = array (
|
||||
'Composer\\InstalledVersions' => __DIR__ . '/..' . '/composer/InstalledVersions.php',
|
||||
'Dompdf\\Cpdf' => __DIR__ . '/..' . '/dompdf/dompdf/lib/Cpdf.php',
|
||||
);
|
||||
|
||||
public static function getInitializer(ClassLoader $loader)
|
||||
{
|
||||
return \Closure::bind(function () use ($loader) {
|
||||
$loader->prefixLengthsPsr4 = ComposerStaticInit47dfdbccdbe2c66869f4658d0723ed1a::$prefixLengthsPsr4;
|
||||
$loader->prefixDirsPsr4 = ComposerStaticInit47dfdbccdbe2c66869f4658d0723ed1a::$prefixDirsPsr4;
|
||||
$loader->classMap = ComposerStaticInit47dfdbccdbe2c66869f4658d0723ed1a::$classMap;
|
||||
|
||||
}, null, ClassLoader::class);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,295 @@
|
|||
{
|
||||
"packages": [
|
||||
{
|
||||
"name": "dompdf/dompdf",
|
||||
"version": "v2.0.1",
|
||||
"version_normalized": "2.0.1.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/dompdf/dompdf.git",
|
||||
"reference": "c5310df0e22c758c85ea5288175fc6cd777bc085"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/dompdf/dompdf/zipball/c5310df0e22c758c85ea5288175fc6cd777bc085",
|
||||
"reference": "c5310df0e22c758c85ea5288175fc6cd777bc085",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"ext-dom": "*",
|
||||
"ext-mbstring": "*",
|
||||
"masterminds/html5": "^2.0",
|
||||
"phenx/php-font-lib": ">=0.5.4 <1.0.0",
|
||||
"phenx/php-svg-lib": ">=0.3.3 <1.0.0",
|
||||
"php": "^7.1 || ^8.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"ext-json": "*",
|
||||
"ext-zip": "*",
|
||||
"mockery/mockery": "^1.3",
|
||||
"phpunit/phpunit": "^7.5 || ^8 || ^9",
|
||||
"squizlabs/php_codesniffer": "^3.5"
|
||||
},
|
||||
"suggest": {
|
||||
"ext-gd": "Needed to process images",
|
||||
"ext-gmagick": "Improves image processing performance",
|
||||
"ext-imagick": "Improves image processing performance",
|
||||
"ext-zlib": "Needed for pdf stream compression"
|
||||
},
|
||||
"time": "2022-09-22T13:43:41+00:00",
|
||||
"type": "library",
|
||||
"installation-source": "dist",
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Dompdf\\": "src/"
|
||||
},
|
||||
"classmap": [
|
||||
"lib/"
|
||||
]
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"LGPL-2.1"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "The Dompdf Community",
|
||||
"homepage": "https://github.com/dompdf/dompdf/blob/master/AUTHORS.md"
|
||||
}
|
||||
],
|
||||
"description": "DOMPDF is a CSS 2.1 compliant HTML to PDF converter",
|
||||
"homepage": "https://github.com/dompdf/dompdf",
|
||||
"support": {
|
||||
"issues": "https://github.com/dompdf/dompdf/issues",
|
||||
"source": "https://github.com/dompdf/dompdf/tree/v2.0.1"
|
||||
},
|
||||
"install-path": "../dompdf/dompdf"
|
||||
},
|
||||
{
|
||||
"name": "masterminds/html5",
|
||||
"version": "2.7.6",
|
||||
"version_normalized": "2.7.6.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/Masterminds/html5-php.git",
|
||||
"reference": "897eb517a343a2281f11bc5556d6548db7d93947"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/Masterminds/html5-php/zipball/897eb517a343a2281f11bc5556d6548db7d93947",
|
||||
"reference": "897eb517a343a2281f11bc5556d6548db7d93947",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"ext-ctype": "*",
|
||||
"ext-dom": "*",
|
||||
"ext-libxml": "*",
|
||||
"php": ">=5.3.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "^4.8.35 || ^5.7.21 || ^6 || ^7"
|
||||
},
|
||||
"time": "2022-08-18T16:18:26+00:00",
|
||||
"type": "library",
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "2.7-dev"
|
||||
}
|
||||
},
|
||||
"installation-source": "dist",
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Masterminds\\": "src"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Matt Butcher",
|
||||
"email": "technosophos@gmail.com"
|
||||
},
|
||||
{
|
||||
"name": "Matt Farina",
|
||||
"email": "matt@mattfarina.com"
|
||||
},
|
||||
{
|
||||
"name": "Asmir Mustafic",
|
||||
"email": "goetas@gmail.com"
|
||||
}
|
||||
],
|
||||
"description": "An HTML5 parser and serializer.",
|
||||
"homepage": "http://masterminds.github.io/html5-php",
|
||||
"keywords": [
|
||||
"HTML5",
|
||||
"dom",
|
||||
"html",
|
||||
"parser",
|
||||
"querypath",
|
||||
"serializer",
|
||||
"xml"
|
||||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/Masterminds/html5-php/issues",
|
||||
"source": "https://github.com/Masterminds/html5-php/tree/2.7.6"
|
||||
},
|
||||
"install-path": "../masterminds/html5"
|
||||
},
|
||||
{
|
||||
"name": "phenx/php-font-lib",
|
||||
"version": "0.5.4",
|
||||
"version_normalized": "0.5.4.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/dompdf/php-font-lib.git",
|
||||
"reference": "dd448ad1ce34c63d09baccd05415e361300c35b4"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/dompdf/php-font-lib/zipball/dd448ad1ce34c63d09baccd05415e361300c35b4",
|
||||
"reference": "dd448ad1ce34c63d09baccd05415e361300c35b4",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"ext-mbstring": "*"
|
||||
},
|
||||
"require-dev": {
|
||||
"symfony/phpunit-bridge": "^3 || ^4 || ^5"
|
||||
},
|
||||
"time": "2021-12-17T19:44:54+00:00",
|
||||
"type": "library",
|
||||
"installation-source": "dist",
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"FontLib\\": "src/FontLib"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"LGPL-3.0"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Fabien Ménager",
|
||||
"email": "fabien.menager@gmail.com"
|
||||
}
|
||||
],
|
||||
"description": "A library to read, parse, export and make subsets of different types of font files.",
|
||||
"homepage": "https://github.com/PhenX/php-font-lib",
|
||||
"support": {
|
||||
"issues": "https://github.com/dompdf/php-font-lib/issues",
|
||||
"source": "https://github.com/dompdf/php-font-lib/tree/0.5.4"
|
||||
},
|
||||
"install-path": "../phenx/php-font-lib"
|
||||
},
|
||||
{
|
||||
"name": "phenx/php-svg-lib",
|
||||
"version": "0.5.0",
|
||||
"version_normalized": "0.5.0.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/dompdf/php-svg-lib.git",
|
||||
"reference": "76876c6cf3080bcb6f249d7d59705108166a6685"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/dompdf/php-svg-lib/zipball/76876c6cf3080bcb6f249d7d59705108166a6685",
|
||||
"reference": "76876c6cf3080bcb6f249d7d59705108166a6685",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"ext-mbstring": "*",
|
||||
"php": "^7.1 || ^8.0",
|
||||
"sabberworm/php-css-parser": "^8.4"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "^7.5 || ^8.5 || ^9.5"
|
||||
},
|
||||
"time": "2022-09-06T12:16:56+00:00",
|
||||
"type": "library",
|
||||
"installation-source": "dist",
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Svg\\": "src/Svg"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"LGPL-3.0"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Fabien Ménager",
|
||||
"email": "fabien.menager@gmail.com"
|
||||
}
|
||||
],
|
||||
"description": "A library to read, parse and export to PDF SVG files.",
|
||||
"homepage": "https://github.com/PhenX/php-svg-lib",
|
||||
"support": {
|
||||
"issues": "https://github.com/dompdf/php-svg-lib/issues",
|
||||
"source": "https://github.com/dompdf/php-svg-lib/tree/0.5.0"
|
||||
},
|
||||
"install-path": "../phenx/php-svg-lib"
|
||||
},
|
||||
{
|
||||
"name": "sabberworm/php-css-parser",
|
||||
"version": "8.4.0",
|
||||
"version_normalized": "8.4.0.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/sabberworm/PHP-CSS-Parser.git",
|
||||
"reference": "e41d2140031d533348b2192a83f02d8dd8a71d30"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/sabberworm/PHP-CSS-Parser/zipball/e41d2140031d533348b2192a83f02d8dd8a71d30",
|
||||
"reference": "e41d2140031d533348b2192a83f02d8dd8a71d30",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"ext-iconv": "*",
|
||||
"php": ">=5.6.20"
|
||||
},
|
||||
"require-dev": {
|
||||
"codacy/coverage": "^1.4",
|
||||
"phpunit/phpunit": "^4.8.36"
|
||||
},
|
||||
"suggest": {
|
||||
"ext-mbstring": "for parsing UTF-8 CSS"
|
||||
},
|
||||
"time": "2021-12-11T13:40:54+00:00",
|
||||
"type": "library",
|
||||
"installation-source": "dist",
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Sabberworm\\CSS\\": "src/"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Raphael Schweikert"
|
||||
}
|
||||
],
|
||||
"description": "Parser for CSS Files written in PHP",
|
||||
"homepage": "https://www.sabberworm.com/blog/2010/6/10/php-css-parser",
|
||||
"keywords": [
|
||||
"css",
|
||||
"parser",
|
||||
"stylesheet"
|
||||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/sabberworm/PHP-CSS-Parser/issues",
|
||||
"source": "https://github.com/sabberworm/PHP-CSS-Parser/tree/8.4.0"
|
||||
},
|
||||
"install-path": "../sabberworm/php-css-parser"
|
||||
}
|
||||
],
|
||||
"dev": true,
|
||||
"dev-package-names": []
|
||||
}
|
|
@ -0,0 +1,68 @@
|
|||
<?php return array(
|
||||
'root' => array(
|
||||
'pretty_version' => '1.0.0+no-version-set',
|
||||
'version' => '1.0.0.0',
|
||||
'type' => 'project',
|
||||
'install_path' => __DIR__ . '/../../',
|
||||
'aliases' => array(),
|
||||
'reference' => NULL,
|
||||
'name' => '__root__',
|
||||
'dev' => true,
|
||||
),
|
||||
'versions' => array(
|
||||
'__root__' => array(
|
||||
'pretty_version' => '1.0.0+no-version-set',
|
||||
'version' => '1.0.0.0',
|
||||
'type' => 'project',
|
||||
'install_path' => __DIR__ . '/../../',
|
||||
'aliases' => array(),
|
||||
'reference' => NULL,
|
||||
'dev_requirement' => false,
|
||||
),
|
||||
'dompdf/dompdf' => array(
|
||||
'pretty_version' => 'v2.0.1',
|
||||
'version' => '2.0.1.0',
|
||||
'type' => 'library',
|
||||
'install_path' => __DIR__ . '/../dompdf/dompdf',
|
||||
'aliases' => array(),
|
||||
'reference' => 'c5310df0e22c758c85ea5288175fc6cd777bc085',
|
||||
'dev_requirement' => false,
|
||||
),
|
||||
'masterminds/html5' => array(
|
||||
'pretty_version' => '2.7.6',
|
||||
'version' => '2.7.6.0',
|
||||
'type' => 'library',
|
||||
'install_path' => __DIR__ . '/../masterminds/html5',
|
||||
'aliases' => array(),
|
||||
'reference' => '897eb517a343a2281f11bc5556d6548db7d93947',
|
||||
'dev_requirement' => false,
|
||||
),
|
||||
'phenx/php-font-lib' => array(
|
||||
'pretty_version' => '0.5.4',
|
||||
'version' => '0.5.4.0',
|
||||
'type' => 'library',
|
||||
'install_path' => __DIR__ . '/../phenx/php-font-lib',
|
||||
'aliases' => array(),
|
||||
'reference' => 'dd448ad1ce34c63d09baccd05415e361300c35b4',
|
||||
'dev_requirement' => false,
|
||||
),
|
||||
'phenx/php-svg-lib' => array(
|
||||
'pretty_version' => '0.5.0',
|
||||
'version' => '0.5.0.0',
|
||||
'type' => 'library',
|
||||
'install_path' => __DIR__ . '/../phenx/php-svg-lib',
|
||||
'aliases' => array(),
|
||||
'reference' => '76876c6cf3080bcb6f249d7d59705108166a6685',
|
||||
'dev_requirement' => false,
|
||||
),
|
||||
'sabberworm/php-css-parser' => array(
|
||||
'pretty_version' => '8.4.0',
|
||||
'version' => '8.4.0.0',
|
||||
'type' => 'library',
|
||||
'install_path' => __DIR__ . '/../sabberworm/php-css-parser',
|
||||
'aliases' => array(),
|
||||
'reference' => 'e41d2140031d533348b2192a83f02d8dd8a71d30',
|
||||
'dev_requirement' => false,
|
||||
),
|
||||
),
|
||||
);
|
|
@ -0,0 +1,26 @@
|
|||
<?php
|
||||
|
||||
// platform_check.php @generated by Composer
|
||||
|
||||
$issues = array();
|
||||
|
||||
if (!(PHP_VERSION_ID >= 70100)) {
|
||||
$issues[] = 'Your Composer dependencies require a PHP version ">= 7.1.0". You are running ' . PHP_VERSION . '.';
|
||||
}
|
||||
|
||||
if ($issues) {
|
||||
if (!headers_sent()) {
|
||||
header('HTTP/1.1 500 Internal Server Error');
|
||||
}
|
||||
if (!ini_get('display_errors')) {
|
||||
if (PHP_SAPI === 'cli' || PHP_SAPI === 'phpdbg') {
|
||||
fwrite(STDERR, 'Composer detected issues in your platform:' . PHP_EOL.PHP_EOL . implode(PHP_EOL, $issues) . PHP_EOL.PHP_EOL);
|
||||
} elseif (!headers_sent()) {
|
||||
echo 'Composer detected issues in your platform:' . PHP_EOL.PHP_EOL . str_replace('You are running '.PHP_VERSION.'.', '', implode(PHP_EOL, $issues)) . PHP_EOL.PHP_EOL;
|
||||
}
|
||||
}
|
||||
trigger_error(
|
||||
'Composer detected issues in your platform: ' . implode(' ', $issues),
|
||||
E_USER_ERROR
|
||||
);
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
Dompdf was designed and developed by Benj Carson.
|
||||
|
||||
### Current Team
|
||||
|
||||
* **Brian Sweeney** (maintainer)
|
||||
* **Till Berger**
|
||||
|
||||
### Alumni
|
||||
|
||||
* **Benj Carson** (creator)
|
||||
* **Fabien Ménager**
|
||||
* **Simon Berger**
|
||||
* **Orion Richardson**
|
||||
|
||||
### Contributors
|
||||
* **Gabriel Bull**
|
||||
* **Barry vd. Heuvel**
|
||||
* **Ryan H. Masten**
|
||||
* **Helmut Tischer**
|
||||
* [and many more...](https://github.com/dompdf/dompdf/graphs/contributors)
|
||||
|
||||
### Thanks
|
||||
|
||||
Dompdf would not have been possible without strong community support.
|
|
@ -0,0 +1,456 @@
|
|||
GNU LESSER GENERAL PUBLIC LICENSE
|
||||
Version 2.1, February 1999
|
||||
|
||||
Copyright (C) 1991, 1999 Free Software Foundation, Inc.
|
||||
59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
[This is the first released version of the Lesser GPL. It also counts
|
||||
as the successor of the GNU Library Public License, version 2, hence
|
||||
the version number 2.1.]
|
||||
|
||||
Preamble
|
||||
|
||||
The licenses for most software are designed to take away your
|
||||
freedom to share and change it. By contrast, the GNU General Public
|
||||
Licenses are intended to guarantee your freedom to share and change
|
||||
free software--to make sure the software is free for all its users.
|
||||
|
||||
This license, the Lesser General Public License, applies to some
|
||||
specially designated software packages--typically libraries--of the
|
||||
Free Software Foundation and other authors who decide to use it. You
|
||||
can use it too, but we suggest you first think carefully about whether
|
||||
this license or the ordinary General Public License is the better
|
||||
strategy to use in any particular case, based on the explanations below.
|
||||
|
||||
When we speak of free software, we are referring to freedom of use,
|
||||
not price. Our General Public Licenses are designed to make sure that
|
||||
you have the freedom to distribute copies of free software (and charge
|
||||
for this service if you wish); that you receive source code or can get
|
||||
it if you want it; that you can change the software and use pieces of
|
||||
it in new free programs; and that you are informed that you can do
|
||||
these things.
|
||||
|
||||
To protect your rights, we need to make restrictions that forbid
|
||||
distributors to deny you these rights or to ask you to surrender these
|
||||
rights. These restrictions translate to certain responsibilities for
|
||||
you if you distribute copies of the library or if you modify it.
|
||||
|
||||
For example, if you distribute copies of the library, whether gratis
|
||||
or for a fee, you must give the recipients all the rights that we gave
|
||||
you. You must make sure that they, too, receive or can get the source
|
||||
code. If you link other code with the library, you must provide
|
||||
complete object files to the recipients, so that they can relink them
|
||||
with the library after making changes to the library and recompiling
|
||||
it. And you must show them these terms so they know their rights.
|
||||
|
||||
We protect your rights with a two-step method: (1) we copyright the
|
||||
library, and (2) we offer you this license, which gives you legal
|
||||
permission to copy, distribute and/or modify the library.
|
||||
|
||||
To protect each distributor, we want to make it very clear that
|
||||
there is no warranty for the free library. Also, if the library is
|
||||
modified by someone else and passed on, the recipients should know
|
||||
that what they have is not the original version, so that the original
|
||||
author's reputation will not be affected by problems that might be
|
||||
introduced by others.
|
||||
|
||||
Finally, software patents pose a constant threat to the existence of
|
||||
any free program. We wish to make sure that a company cannot
|
||||
effectively restrict the users of a free program by obtaining a
|
||||
restrictive license from a patent holder. Therefore, we insist that
|
||||
any patent license obtained for a version of the library must be
|
||||
consistent with the full freedom of use specified in this license.
|
||||
|
||||
Most GNU software, including some libraries, is covered by the
|
||||
ordinary GNU General Public License. This license, the GNU Lesser
|
||||
General Public License, applies to certain designated libraries, and
|
||||
is quite different from the ordinary General Public License. We use
|
||||
this license for certain libraries in order to permit linking those
|
||||
libraries into non-free programs.
|
||||
|
||||
When a program is linked with a library, whether statically or using
|
||||
a shared library, the combination of the two is legally speaking a
|
||||
combined work, a derivative of the original library. The ordinary
|
||||
General Public License therefore permits such linking only if the
|
||||
entire combination fits its criteria of freedom. The Lesser General
|
||||
Public License permits more lax criteria for linking other code with
|
||||
the library.
|
||||
|
||||
We call this license the "Lesser" General Public License because it
|
||||
does Less to protect the user's freedom than the ordinary General
|
||||
Public License. It also provides other free software developers Less
|
||||
of an advantage over competing non-free programs. These disadvantages
|
||||
are the reason we use the ordinary General Public License for many
|
||||
libraries. However, the Lesser license provides advantages in certain
|
||||
special circumstances.
|
||||
|
||||
For example, on rare occasions, there may be a special need to
|
||||
encourage the widest possible use of a certain library, so that it becomes
|
||||
a de-facto standard. To achieve this, non-free programs must be
|
||||
allowed to use the library. A more frequent case is that a free
|
||||
library does the same job as widely used non-free libraries. In this
|
||||
case, there is little to gain by limiting the free library to free
|
||||
software only, so we use the Lesser General Public License.
|
||||
|
||||
In other cases, permission to use a particular library in non-free
|
||||
programs enables a greater number of people to use a large body of
|
||||
free software. For example, permission to use the GNU C Library in
|
||||
non-free programs enables many more people to use the whole GNU
|
||||
operating system, as well as its variant, the GNU/Linux operating
|
||||
system.
|
||||
|
||||
Although the Lesser General Public License is Less protective of the
|
||||
users' freedom, it does ensure that the user of a program that is
|
||||
linked with the Library has the freedom and the wherewithal to run
|
||||
that program using a modified version of the Library.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow. Pay close attention to the difference between a
|
||||
"work based on the library" and a "work that uses the library". The
|
||||
former contains code derived from the library, whereas the latter must
|
||||
be combined with the library in order to run.
|
||||
|
||||
GNU LESSER GENERAL PUBLIC LICENSE
|
||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||
|
||||
0. This License Agreement applies to any software library or other
|
||||
program which contains a notice placed by the copyright holder or
|
||||
other authorized party saying it may be distributed under the terms of
|
||||
this Lesser General Public License (also called "this License").
|
||||
Each licensee is addressed as "you".
|
||||
|
||||
A "library" means a collection of software functions and/or data
|
||||
prepared so as to be conveniently linked with application programs
|
||||
(which use some of those functions and data) to form executables.
|
||||
|
||||
The "Library", below, refers to any such software library or work
|
||||
which has been distributed under these terms. A "work based on the
|
||||
Library" means either the Library or any derivative work under
|
||||
copyright law: that is to say, a work containing the Library or a
|
||||
portion of it, either verbatim or with modifications and/or translated
|
||||
straightforwardly into another language. (Hereinafter, translation is
|
||||
included without limitation in the term "modification".)
|
||||
|
||||
"Source code" for a work means the preferred form of the work for
|
||||
making modifications to it. For a library, complete source code means
|
||||
all the source code for all modules it contains, plus any associated
|
||||
interface definition files, plus the scripts used to control compilation
|
||||
and installation of the library.
|
||||
|
||||
Activities other than copying, distribution and modification are not
|
||||
covered by this License; they are outside its scope. The act of
|
||||
running a program using the Library is not restricted, and output from
|
||||
such a program is covered only if its contents constitute a work based
|
||||
on the Library (independent of the use of the Library in a tool for
|
||||
writing it). Whether that is true depends on what the Library does
|
||||
and what the program that uses the Library does.
|
||||
|
||||
1. You may copy and distribute verbatim copies of the Library's
|
||||
complete source code as you receive it, in any medium, provided that
|
||||
you conspicuously and appropriately publish on each copy an
|
||||
appropriate copyright notice and disclaimer of warranty; keep intact
|
||||
all the notices that refer to this License and to the absence of any
|
||||
warranty; and distribute a copy of this License along with the
|
||||
Library.
|
||||
|
||||
You may charge a fee for the physical act of transferring a copy,
|
||||
and you may at your option offer warranty protection in exchange for a
|
||||
fee.
|
||||
|
||||
2. You may modify your copy or copies of the Library or any portion
|
||||
of it, thus forming a work based on the Library, and copy and
|
||||
distribute such modifications or work under the terms of Section 1
|
||||
above, provided that you also meet all of these conditions:
|
||||
|
||||
a) The modified work must itself be a software library.
|
||||
|
||||
b) You must cause the files modified to carry prominent notices
|
||||
stating that you changed the files and the date of any change.
|
||||
|
||||
c) You must cause the whole of the work to be licensed at no
|
||||
charge to all third parties under the terms of this License.
|
||||
|
||||
d) If a facility in the modified Library refers to a function or a
|
||||
table of data to be supplied by an application program that uses
|
||||
the facility, other than as an argument passed when the facility
|
||||
is invoked, then you must make a good faith effort to ensure that,
|
||||
in the event an application does not supply such function or
|
||||
table, the facility still operates, and performs whatever part of
|
||||
its purpose remains meaningful.
|
||||
|
||||
(For example, a function in a library to compute square roots has
|
||||
a purpose that is entirely well-defined independent of the
|
||||
application. Therefore, Subsection 2d requires that any
|
||||
application-supplied function or table used by this function must
|
||||
be optional: if the application does not supply it, the square
|
||||
root function must still compute square roots.)
|
||||
|
||||
These requirements apply to the modified work as a whole. If
|
||||
identifiable sections of that work are not derived from the Library,
|
||||
and can be reasonably considered independent and separate works in
|
||||
themselves, then this License, and its terms, do not apply to those
|
||||
sections when you distribute them as separate works. But when you
|
||||
distribute the same sections as part of a whole which is a work based
|
||||
on the Library, the distribution of the whole must be on the terms of
|
||||
this License, whose permissions for other licensees extend to the
|
||||
entire whole, and thus to each and every part regardless of who wrote
|
||||
it.
|
||||
|
||||
Thus, it is not the intent of this section to claim rights or contest
|
||||
your rights to work written entirely by you; rather, the intent is to
|
||||
exercise the right to control the distribution of derivative or
|
||||
collective works based on the Library.
|
||||
|
||||
In addition, mere aggregation of another work not based on the Library
|
||||
with the Library (or with a work based on the Library) on a volume of
|
||||
a storage or distribution medium does not bring the other work under
|
||||
the scope of this License.
|
||||
|
||||
3. You may opt to apply the terms of the ordinary GNU General Public
|
||||
License instead of this License to a given copy of the Library. To do
|
||||
this, you must alter all the notices that refer to this License, so
|
||||
that they refer to the ordinary GNU General Public License, version 2,
|
||||
instead of to this License. (If a newer version than version 2 of the
|
||||
ordinary GNU General Public License has appeared, then you can specify
|
||||
that version instead if you wish.) Do not make any other change in
|
||||
these notices.
|
||||
|
||||
Once this change is made in a given copy, it is irreversible for
|
||||
that copy, so the ordinary GNU General Public License applies to all
|
||||
subsequent copies and derivative works made from that copy.
|
||||
|
||||
This option is useful when you wish to copy part of the code of
|
||||
the Library into a program that is not a library.
|
||||
|
||||
4. You may copy and distribute the Library (or a portion or
|
||||
derivative of it, under Section 2) in object code or executable form
|
||||
under the terms of Sections 1 and 2 above provided that you accompany
|
||||
it with the complete corresponding machine-readable source code, which
|
||||
must be distributed under the terms of Sections 1 and 2 above on a
|
||||
medium customarily used for software interchange.
|
||||
|
||||
If distribution of object code is made by offering access to copy
|
||||
from a designated place, then offering equivalent access to copy the
|
||||
source code from the same place satisfies the requirement to
|
||||
distribute the source code, even though third parties are not
|
||||
compelled to copy the source along with the object code.
|
||||
|
||||
5. A program that contains no derivative of any portion of the
|
||||
Library, but is designed to work with the Library by being compiled or
|
||||
linked with it, is called a "work that uses the Library". Such a
|
||||
work, in isolation, is not a derivative work of the Library, and
|
||||
therefore falls outside the scope of this License.
|
||||
|
||||
However, linking a "work that uses the Library" with the Library
|
||||
creates an executable that is a derivative of the Library (because it
|
||||
contains portions of the Library), rather than a "work that uses the
|
||||
library". The executable is therefore covered by this License.
|
||||
Section 6 states terms for distribution of such executables.
|
||||
|
||||
When a "work that uses the Library" uses material from a header file
|
||||
that is part of the Library, the object code for the work may be a
|
||||
derivative work of the Library even though the source code is not.
|
||||
Whether this is true is especially significant if the work can be
|
||||
linked without the Library, or if the work is itself a library. The
|
||||
threshold for this to be true is not precisely defined by law.
|
||||
|
||||
If such an object file uses only numerical parameters, data
|
||||
structure layouts and accessors, and small macros and small inline
|
||||
functions (ten lines or less in length), then the use of the object
|
||||
file is unrestricted, regardless of whether it is legally a derivative
|
||||
work. (Executables containing this object code plus portions of the
|
||||
Library will still fall under Section 6.)
|
||||
|
||||
Otherwise, if the work is a derivative of the Library, you may
|
||||
distribute the object code for the work under the terms of Section 6.
|
||||
Any executables containing that work also fall under Section 6,
|
||||
whether or not they are linked directly with the Library itself.
|
||||
|
||||
6. As an exception to the Sections above, you may also combine or
|
||||
link a "work that uses the Library" with the Library to produce a
|
||||
work containing portions of the Library, and distribute that work
|
||||
under terms of your choice, provided that the terms permit
|
||||
modification of the work for the customer's own use and reverse
|
||||
engineering for debugging such modifications.
|
||||
|
||||
You must give prominent notice with each copy of the work that the
|
||||
Library is used in it and that the Library and its use are covered by
|
||||
this License. You must supply a copy of this License. If the work
|
||||
during execution displays copyright notices, you must include the
|
||||
copyright notice for the Library among them, as well as a reference
|
||||
directing the user to the copy of this License. Also, you must do one
|
||||
of these things:
|
||||
|
||||
a) Accompany the work with the complete corresponding
|
||||
machine-readable source code for the Library including whatever
|
||||
changes were used in the work (which must be distributed under
|
||||
Sections 1 and 2 above); and, if the work is an executable linked
|
||||
with the Library, with the complete machine-readable "work that
|
||||
uses the Library", as object code and/or source code, so that the
|
||||
user can modify the Library and then relink to produce a modified
|
||||
executable containing the modified Library. (It is understood
|
||||
that the user who changes the contents of definitions files in the
|
||||
Library will not necessarily be able to recompile the application
|
||||
to use the modified definitions.)
|
||||
|
||||
b) Use a suitable shared library mechanism for linking with the
|
||||
Library. A suitable mechanism is one that (1) uses at run time a
|
||||
copy of the library already present on the user's computer system,
|
||||
rather than copying library functions into the executable, and (2)
|
||||
will operate properly with a modified version of the library, if
|
||||
the user installs one, as long as the modified version is
|
||||
interface-compatible with the version that the work was made with.
|
||||
|
||||
c) Accompany the work with a written offer, valid for at
|
||||
least three years, to give the same user the materials
|
||||
specified in Subsection 6a, above, for a charge no more
|
||||
than the cost of performing this distribution.
|
||||
|
||||
d) If distribution of the work is made by offering access to copy
|
||||
from a designated place, offer equivalent access to copy the above
|
||||
specified materials from the same place.
|
||||
|
||||
e) Verify that the user has already received a copy of these
|
||||
materials or that you have already sent this user a copy.
|
||||
|
||||
For an executable, the required form of the "work that uses the
|
||||
Library" must include any data and utility programs needed for
|
||||
reproducing the executable from it. However, as a special exception,
|
||||
the materials to be distributed need not include anything that is
|
||||
normally distributed (in either source or binary form) with the major
|
||||
components (compiler, kernel, and so on) of the operating system on
|
||||
which the executable runs, unless that component itself accompanies
|
||||
the executable.
|
||||
|
||||
It may happen that this requirement contradicts the license
|
||||
restrictions of other proprietary libraries that do not normally
|
||||
accompany the operating system. Such a contradiction means you cannot
|
||||
use both them and the Library together in an executable that you
|
||||
distribute.
|
||||
|
||||
7. You may place library facilities that are a work based on the
|
||||
Library side-by-side in a single library together with other library
|
||||
facilities not covered by this License, and distribute such a combined
|
||||
library, provided that the separate distribution of the work based on
|
||||
the Library and of the other library facilities is otherwise
|
||||
permitted, and provided that you do these two things:
|
||||
|
||||
a) Accompany the combined library with a copy of the same work
|
||||
based on the Library, uncombined with any other library
|
||||
facilities. This must be distributed under the terms of the
|
||||
Sections above.
|
||||
|
||||
b) Give prominent notice with the combined library of the fact
|
||||
that part of it is a work based on the Library, and explaining
|
||||
where to find the accompanying uncombined form of the same work.
|
||||
|
||||
8. You may not copy, modify, sublicense, link with, or distribute
|
||||
the Library except as expressly provided under this License. Any
|
||||
attempt otherwise to copy, modify, sublicense, link with, or
|
||||
distribute the Library is void, and will automatically terminate your
|
||||
rights under this License. However, parties who have received copies,
|
||||
or rights, from you under this License will not have their licenses
|
||||
terminated so long as such parties remain in full compliance.
|
||||
|
||||
9. You are not required to accept this License, since you have not
|
||||
signed it. However, nothing else grants you permission to modify or
|
||||
distribute the Library or its derivative works. These actions are
|
||||
prohibited by law if you do not accept this License. Therefore, by
|
||||
modifying or distributing the Library (or any work based on the
|
||||
Library), you indicate your acceptance of this License to do so, and
|
||||
all its terms and conditions for copying, distributing or modifying
|
||||
the Library or works based on it.
|
||||
|
||||
10. Each time you redistribute the Library (or any work based on the
|
||||
Library), the recipient automatically receives a license from the
|
||||
original licensor to copy, distribute, link with or modify the Library
|
||||
subject to these terms and conditions. You may not impose any further
|
||||
restrictions on the recipients' exercise of the rights granted herein.
|
||||
You are not responsible for enforcing compliance by third parties with
|
||||
this License.
|
||||
|
||||
11. If, as a consequence of a court judgment or allegation of patent
|
||||
infringement or for any other reason (not limited to patent issues),
|
||||
conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot
|
||||
distribute so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you
|
||||
may not distribute the Library at all. For example, if a patent
|
||||
license would not permit royalty-free redistribution of the Library by
|
||||
all those who receive copies directly or indirectly through you, then
|
||||
the only way you could satisfy both it and this License would be to
|
||||
refrain entirely from distribution of the Library.
|
||||
|
||||
If any portion of this section is held invalid or unenforceable under any
|
||||
particular circumstance, the balance of the section is intended to apply,
|
||||
and the section as a whole is intended to apply in other circumstances.
|
||||
|
||||
It is not the purpose of this section to induce you to infringe any
|
||||
patents or other property right claims or to contest validity of any
|
||||
such claims; this section has the sole purpose of protecting the
|
||||
integrity of the free software distribution system which is
|
||||
implemented by public license practices. Many people have made
|
||||
generous contributions to the wide range of software distributed
|
||||
through that system in reliance on consistent application of that
|
||||
system; it is up to the author/donor to decide if he or she is willing
|
||||
to distribute software through any other system and a licensee cannot
|
||||
impose that choice.
|
||||
|
||||
This section is intended to make thoroughly clear what is believed to
|
||||
be a consequence of the rest of this License.
|
||||
|
||||
12. If the distribution and/or use of the Library is restricted in
|
||||
certain countries either by patents or by copyrighted interfaces, the
|
||||
original copyright holder who places the Library under this License may add
|
||||
an explicit geographical distribution limitation excluding those countries,
|
||||
so that distribution is permitted only in or among countries not thus
|
||||
excluded. In such case, this License incorporates the limitation as if
|
||||
written in the body of this License.
|
||||
|
||||
13. The Free Software Foundation may publish revised and/or new
|
||||
versions of the Lesser General Public License from time to time.
|
||||
Such new versions will be similar in spirit to the present version,
|
||||
but may differ in detail to address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the Library
|
||||
specifies a version number of this License which applies to it and
|
||||
"any later version", you have the option of following the terms and
|
||||
conditions either of that version or of any later version published by
|
||||
the Free Software Foundation. If the Library does not specify a
|
||||
license version number, you may choose any version ever published by
|
||||
the Free Software Foundation.
|
||||
|
||||
14. If you wish to incorporate parts of the Library into other free
|
||||
programs whose distribution conditions are incompatible with these,
|
||||
write to the author to ask for permission. For software which is
|
||||
copyrighted by the Free Software Foundation, write to the Free
|
||||
Software Foundation; we sometimes make exceptions for this. Our
|
||||
decision will be guided by the two goals of preserving the free status
|
||||
of all derivatives of our free software and of promoting the sharing
|
||||
and reuse of software generally.
|
||||
|
||||
NO WARRANTY
|
||||
|
||||
15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO
|
||||
WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
|
||||
EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
|
||||
OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY
|
||||
KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE
|
||||
LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME
|
||||
THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||
|
||||
16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
|
||||
WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY
|
||||
AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU
|
||||
FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR
|
||||
CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE
|
||||
LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
|
||||
RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
|
||||
FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
|
||||
SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
|
||||
DAMAGES.
|
|
@ -0,0 +1,232 @@
|
|||
Dompdf
|
||||
======
|
||||
|
||||
[![Build Status](https://github.com/dompdf/dompdf/actions/workflows/test.yml/badge.svg)](https://github.com/dompdf/dompdf/actions/workflows/test.yml)
|
||||
[![Latest Release](https://poser.pugx.org/dompdf/dompdf/v/stable.png)](https://packagist.org/packages/dompdf/dompdf)
|
||||
[![Total Downloads](https://poser.pugx.org/dompdf/dompdf/downloads.png)](https://packagist.org/packages/dompdf/dompdf)
|
||||
[![License](https://poser.pugx.org/dompdf/dompdf/license.png)](https://packagist.org/packages/dompdf/dompdf)
|
||||
|
||||
**Dompdf is an HTML to PDF converter**
|
||||
|
||||
At its heart, dompdf is (mostly) a [CSS 2.1](http://www.w3.org/TR/CSS2/) compliant
|
||||
HTML layout and rendering engine written in PHP. It is a style-driven renderer:
|
||||
it will download and read external stylesheets, inline style tags, and the style
|
||||
attributes of individual HTML elements. It also supports most presentational
|
||||
HTML attributes.
|
||||
|
||||
*This document applies to the latest stable code which may not reflect the current
|
||||
release. For released code please
|
||||
[navigate to the appropriate tag](https://github.com/dompdf/dompdf/tags).*
|
||||
|
||||
----
|
||||
|
||||
**Check out the [demo](http://eclecticgeek.com/dompdf/debug.php) and ask any
|
||||
question on [StackOverflow](https://stackoverflow.com/questions/tagged/dompdf) or
|
||||
in [Discussions](https://github.com/dompdf/dompdf/discussions).**
|
||||
|
||||
Follow us on [![Twitter](http://twitter-badges.s3.amazonaws.com/twitter-a.png)](http://www.twitter.com/dompdf).
|
||||
|
||||
---
|
||||
|
||||
|
||||
|
||||
## Features
|
||||
|
||||
* Handles most CSS 2.1 and a few CSS3 properties, including @import, @media &
|
||||
@page rules
|
||||
* Supports most presentational HTML 4.0 attributes
|
||||
* Supports external stylesheets, either local or through http/ftp (via
|
||||
fopen-wrappers)
|
||||
* Supports complex tables, including row & column spans, separate & collapsed
|
||||
border models, individual cell styling
|
||||
* Image support (gif, png (8, 24 and 32 bit with alpha channel), bmp & jpeg)
|
||||
* No dependencies on external PDF libraries, thanks to the R&OS PDF class
|
||||
* Inline PHP support
|
||||
* Basic SVG support (see "Limitations" below)
|
||||
|
||||
## Requirements
|
||||
|
||||
* PHP version 7.1 or higher
|
||||
* DOM extension
|
||||
* MBString extension
|
||||
* php-font-lib
|
||||
* php-svg-lib
|
||||
|
||||
Note that some required dependencies may have further dependencies
|
||||
(notably php-svg-lib requires sabberworm/php-css-parser).
|
||||
|
||||
### Recommendations
|
||||
|
||||
* OPcache (OPcache, XCache, APC, etc.): improves performance
|
||||
* GD (for image processing)
|
||||
* IMagick or GMagick extension: improves image processing performance
|
||||
|
||||
Visit the wiki for more information:
|
||||
https://github.com/dompdf/dompdf/wiki/Requirements
|
||||
|
||||
## About Fonts & Character Encoding
|
||||
|
||||
PDF documents internally support the following fonts: Helvetica, Times-Roman,
|
||||
Courier, Zapf-Dingbats, & Symbol. These fonts only support Windows ANSI
|
||||
encoding. In order for a PDF to display characters that are not available in
|
||||
Windows ANSI, you must supply an external font. Dompdf will embed any referenced
|
||||
font in the PDF so long as it has been pre-loaded or is accessible to dompdf and
|
||||
reference in CSS @font-face rules. See the
|
||||
[font overview](https://github.com/dompdf/dompdf/wiki/About-Fonts-and-Character-Encoding)
|
||||
for more information on how to use fonts.
|
||||
|
||||
The [DejaVu TrueType fonts](https://dejavu-fonts.github.io/) have been pre-installed
|
||||
to give dompdf decent Unicode character coverage by default. To use the DejaVu
|
||||
fonts reference the font in your stylesheet, e.g. `body { font-family: DejaVu
|
||||
Sans; }` (for DejaVu Sans). The following DejaVu 2.34 fonts are available:
|
||||
DejaVu Sans, DejaVu Serif, and DejaVu Sans Mono.
|
||||
|
||||
## Easy Installation
|
||||
|
||||
### Install with composer
|
||||
|
||||
To install with [Composer](https://getcomposer.org/), simply require the
|
||||
latest version of this package.
|
||||
|
||||
```bash
|
||||
composer require dompdf/dompdf
|
||||
```
|
||||
|
||||
Make sure that the autoload file from Composer is loaded.
|
||||
|
||||
```php
|
||||
// somewhere early in your project's loading, require the Composer autoloader
|
||||
// see: http://getcomposer.org/doc/00-intro.md
|
||||
require 'vendor/autoload.php';
|
||||
|
||||
```
|
||||
|
||||
### Download and install
|
||||
|
||||
Download a packaged archive of dompdf and extract it into the
|
||||
directory where dompdf will reside
|
||||
|
||||
* You can download stable copies of dompdf from
|
||||
https://github.com/dompdf/dompdf/releases
|
||||
* Or download a nightly (the latest, unreleased code) from
|
||||
http://eclecticgeek.com/dompdf
|
||||
|
||||
Use the packaged release autoloader to load dompdf, libraries,
|
||||
and helper functions in your PHP:
|
||||
|
||||
```php
|
||||
// include autoloader
|
||||
require_once 'dompdf/autoload.inc.php';
|
||||
```
|
||||
|
||||
Note: packaged releases are named according using semantic
|
||||
versioning (_dompdf_MAJOR-MINOR-PATCH.zip_). So the 1.0.0
|
||||
release would be dompdf_1-0-0.zip. This is the only download
|
||||
that includes the autoloader for Dompdf and all its dependencies.
|
||||
|
||||
### Install with git
|
||||
|
||||
From the command line, switch to the directory where dompdf will
|
||||
reside and run the following commands:
|
||||
|
||||
```sh
|
||||
git clone https://github.com/dompdf/dompdf.git
|
||||
cd dompdf/lib
|
||||
|
||||
git clone https://github.com/PhenX/php-font-lib.git php-font-lib
|
||||
cd php-font-lib
|
||||
git checkout 0.5.1
|
||||
cd ..
|
||||
|
||||
git clone https://github.com/PhenX/php-svg-lib.git php-svg-lib
|
||||
cd php-svg-lib
|
||||
git checkout v0.3.2
|
||||
cd ..
|
||||
|
||||
git clone https://github.com/sabberworm/PHP-CSS-Parser.git php-css-parser
|
||||
cd php-css-parser
|
||||
git checkout 8.1.0
|
||||
```
|
||||
|
||||
Require dompdf and it's dependencies in your PHP.
|
||||
For details see the [autoloader in the utils project](https://github.com/dompdf/utils/blob/master/autoload.inc.php).
|
||||
|
||||
## Quick Start
|
||||
|
||||
Just pass your HTML in to dompdf and stream the output:
|
||||
|
||||
```php
|
||||
// reference the Dompdf namespace
|
||||
use Dompdf\Dompdf;
|
||||
|
||||
// instantiate and use the dompdf class
|
||||
$dompdf = new Dompdf();
|
||||
$dompdf->loadHtml('hello world');
|
||||
|
||||
// (Optional) Setup the paper size and orientation
|
||||
$dompdf->setPaper('A4', 'landscape');
|
||||
|
||||
// Render the HTML as PDF
|
||||
$dompdf->render();
|
||||
|
||||
// Output the generated PDF to Browser
|
||||
$dompdf->stream();
|
||||
```
|
||||
|
||||
### Setting Options
|
||||
|
||||
Set options during dompdf instantiation:
|
||||
|
||||
```php
|
||||
use Dompdf\Dompdf;
|
||||
use Dompdf\Options;
|
||||
|
||||
$options = new Options();
|
||||
$options->set('defaultFont', 'Courier');
|
||||
$dompdf = new Dompdf($options);
|
||||
```
|
||||
|
||||
or at run time
|
||||
|
||||
```php
|
||||
use Dompdf\Dompdf;
|
||||
|
||||
$dompdf = new Dompdf();
|
||||
$options = $dompdf->getOptions();
|
||||
$options->setDefaultFont('Courier');
|
||||
$dompdf->setOptions($options);
|
||||
```
|
||||
|
||||
See [Dompdf\Options](src/Options.php) for a list of available options.
|
||||
|
||||
### Resource Reference Requirements
|
||||
|
||||
In order to protect potentially sensitive information Dompdf imposes
|
||||
restrictions on files referenced from the local file system or the web.
|
||||
|
||||
Files accessed through web-based protocols have the following requirements:
|
||||
* The Dompdf option "isRemoteEnabled" must be set to "true"
|
||||
* PHP must either have the curl extension enabled or the
|
||||
allow_url_fopen setting set to true
|
||||
|
||||
Files accessed through the local file system have the following requirement:
|
||||
* The file must fall within the path(s) specified for the Dompdf "chroot" option
|
||||
|
||||
## Limitations (Known Issues)
|
||||
|
||||
* Table cells are not pageable, meaning a table row must fit on a single page.
|
||||
* Elements are rendered on the active page when they are parsed.
|
||||
* Embedding "raw" SVG's (`<svg><path...></svg>`) isn't working yet, you need to
|
||||
either link to an external SVG file, or use a DataURI like this:
|
||||
```php
|
||||
$html = '<img src="data:image/svg+xml;base64,' . base64_encode($svg) . '" ...>';
|
||||
```
|
||||
Watch https://github.com/dompdf/dompdf/issues/320 for progress
|
||||
* Does not support CSS flexbox.
|
||||
* Does not support CSS Grid.
|
||||
---
|
||||
|
||||
[![Donate button](https://www.paypal.com/en_US/i/btn/btn_donate_SM.gif)](http://goo.gl/DSvWf)
|
||||
|
||||
*If you find this project useful, please consider making a donation.
|
||||
Any funds donated will be used to help further development on this project.)*
|
|
@ -0,0 +1 @@
|
|||
2.0.1
|
|
@ -6,16 +6,8 @@
|
|||
"license": "LGPL-2.1",
|
||||
"authors": [
|
||||
{
|
||||
"name": "Fabien Ménager",
|
||||
"email": "fabien.menager@gmail.com"
|
||||
},
|
||||
{
|
||||
"name": "Brian Sweeney",
|
||||
"email": "eclecticgeek@gmail.com"
|
||||
},
|
||||
{
|
||||
"name": "Gabriel Bull",
|
||||
"email": "me@gabrielbull.com"
|
||||
"name": "The Dompdf Community",
|
||||
"homepage": "https://github.com/dompdf/dompdf/blob/master/AUTHORS.md"
|
||||
}
|
||||
],
|
||||
"autoload": {
|
||||
|
@ -35,10 +27,13 @@
|
|||
"php": "^7.1 || ^8.0",
|
||||
"ext-dom": "*",
|
||||
"ext-mbstring": "*",
|
||||
"phenx/php-font-lib": "^0.5.4",
|
||||
"phenx/php-svg-lib": "^0.3.3 || ^0.4.0"
|
||||
"masterminds/html5": "^2.0",
|
||||
"phenx/php-font-lib": ">=0.5.4 <1.0.0",
|
||||
"phenx/php-svg-lib": ">=0.3.3 <1.0.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"ext-json": "*",
|
||||
"ext-zip": "*",
|
||||
"phpunit/phpunit": "^7.5 || ^8 || ^9",
|
||||
"squizlabs/php_codesniffer": "^3.5",
|
||||
"mockery/mockery": "^1.3"
|
|
@ -3,19 +3,10 @@
|
|||
* A PHP class to provide the basic functionality to create a pdf document without
|
||||
* any requirement for additional modules.
|
||||
*
|
||||
* Extended by Orion Richardson to support Unicode / UTF-8 characters using
|
||||
* TCPDF and others as a guide.
|
||||
*
|
||||
* @author Wayne Munro <pdf@ros.co.nz>
|
||||
* @author Orion Richardson <orionr@yahoo.com>
|
||||
* @author Helmut Tischer <htischer@weihenstephan.org>
|
||||
* @author Ryan H. Masten <ryan.masten@gmail.com>
|
||||
* @author Brian Sweeney <eclecticgeek@gmail.com>
|
||||
* @author Fabien Ménager <fabien.menager@gmail.com>
|
||||
* @license Public Domain http://creativecommons.org/licenses/publicdomain/
|
||||
* @author Wayne Munro
|
||||
* @license http://creativecommons.org/licenses/publicdomain/ Public Domain
|
||||
* @package Cpdf
|
||||
*/
|
||||
|
||||
namespace Dompdf;
|
||||
|
||||
use FontLib\Exception\FontNotFoundException;
|
||||
|
@ -1048,7 +1039,7 @@ class Cpdf
|
|||
}
|
||||
}
|
||||
|
||||
return 'SUB' . str_pad($base_26, 3 , 'A', STR_PAD_LEFT);
|
||||
return 'SUB' . str_pad($base_26, 3, 'A', STR_PAD_LEFT);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1381,7 +1372,7 @@ EOT;
|
|||
|
||||
$res = "\n$id 0 obj\n";
|
||||
$res .= "<</Length " . mb_strlen($stream, '8bit') . " >>\n";
|
||||
$res .= "stream\n" . $stream . "\nendstream" . "\nendobj";;
|
||||
$res .= "stream\n" . $stream . "\nendstream" . "\nendobj";
|
||||
|
||||
return $res;
|
||||
}
|
||||
|
@ -2423,8 +2414,7 @@ EOT;
|
|||
$res = "\n$id 0 obj\n<< /Type /XObject\n";
|
||||
|
||||
foreach ($o["info"] as $k => $v) {
|
||||
switch($k)
|
||||
{
|
||||
switch ($k) {
|
||||
case 'Subtype':
|
||||
$res .= "/Subtype /$v\n";
|
||||
break;
|
||||
|
@ -2477,7 +2467,7 @@ EOT;
|
|||
}
|
||||
|
||||
$res .= "/Length " . mb_strlen($tmp, '8bit') . " >>\n";
|
||||
$res .= "stream\n" . $tmp . "\nendstream" . "\nendobj";;
|
||||
$res .= "stream\n" . $tmp . "\nendstream" . "\nendobj";
|
||||
|
||||
return $res;
|
||||
}
|
||||
|
@ -2515,7 +2505,7 @@ EOT;
|
|||
$res = "\n$id 0 obj\n<<";
|
||||
|
||||
foreach ($o["info"] as $k => $v) {
|
||||
switch($k) {
|
||||
switch ($k) {
|
||||
case 'Fields':
|
||||
$res .= " /Fields [";
|
||||
foreach ($v as $i) {
|
||||
|
@ -2619,7 +2609,7 @@ EOT;
|
|||
$res .= ">>\n";
|
||||
break;
|
||||
case 'T':
|
||||
if($encrypted) {
|
||||
if ($encrypted) {
|
||||
$v = $this->filterText($this->ARC4($v), false, false);
|
||||
}
|
||||
$res .= "/T ($v)\n";
|
||||
|
@ -2662,7 +2652,7 @@ EOT;
|
|||
$pos = strpos($content, sprintf("/ByteRange [ %'.010d", $id));
|
||||
$len = strlen('/ByteRange [ ********** ********** ********** ********** ]');
|
||||
$rangeStartPos = $pos + $len + 1 + 10; // before '<'
|
||||
$content = substr_replace($content, str_pad(sprintf('/ByteRange [ 0 %u %u %u ]', $rangeStartPos, $rangeStartPos + $sign_maxlen + 2, $content_len - 2 - $sign_maxlen - $rangeStartPos ), $len, ' ', STR_PAD_RIGHT), $pos, $len);
|
||||
$content = substr_replace($content, str_pad(sprintf('/ByteRange [ 0 %u %u %u ]', $rangeStartPos, $rangeStartPos + $sign_maxlen + 2, $content_len - 2 - $sign_maxlen - $rangeStartPos), $len, ' ', STR_PAD_RIGHT), $pos, $len);
|
||||
|
||||
$fuid = uniqid();
|
||||
$tmpInput = $this->tmp . "/pkcs7.tmp." . $fuid . '.in';
|
||||
|
@ -2726,7 +2716,7 @@ EOT;
|
|||
|
||||
$o = &$this->objects[$id];
|
||||
foreach ($o['info'] as $k => $v) {
|
||||
switch($k) {
|
||||
switch ($k) {
|
||||
case 'Name':
|
||||
case 'Location':
|
||||
case 'Reason':
|
||||
|
@ -2852,7 +2842,7 @@ EOT;
|
|||
case 'out':
|
||||
$res = "\n$id 0 obj << ";
|
||||
|
||||
foreach($this->objects[$id]['info'] as $referenceObjName => $referenceObjId) {
|
||||
foreach ($this->objects[$id]['info'] as $referenceObjName => $referenceObjId) {
|
||||
$res .= "/$referenceObjName $referenceObjId 0 R ";
|
||||
}
|
||||
|
||||
|
@ -3310,11 +3300,11 @@ EOT;
|
|||
{
|
||||
// assume that $font contains the path and file but not the extension
|
||||
$name = basename($font);
|
||||
$dir = dirname($font) . '/';
|
||||
$dir = dirname($font);
|
||||
|
||||
$fontcache = $this->fontcache;
|
||||
if ($fontcache == '') {
|
||||
$fontcache = rtrim($dir, DIRECTORY_SEPARATOR."/\\");
|
||||
$fontcache = $dir;
|
||||
}
|
||||
|
||||
//$name filename without folder and extension of font metrics
|
||||
|
@ -3331,36 +3321,22 @@ EOT;
|
|||
$metrics_name = "$name.ufm";
|
||||
}
|
||||
|
||||
$cache_name = "$metrics_name.php";
|
||||
$cache_name = "$metrics_name.json";
|
||||
$this->addMessage("metrics: $metrics_name, cache: $cache_name");
|
||||
|
||||
|
||||
if (file_exists($fontcache . '/' . $cache_name)) {
|
||||
$this->addMessage("openFont: php file exists $fontcache/$cache_name");
|
||||
$this->fonts[$font] = require($fontcache . '/' . $cache_name);
|
||||
|
||||
if (!isset($this->fonts[$font]['_version_']) || $this->fonts[$font]['_version_'] != $this->fontcacheVersion) {
|
||||
// if the font file is old, then clear it out and prepare for re-creation
|
||||
$this->addMessage('openFont: clear out, make way for new version.');
|
||||
$this->fonts[$font] = null;
|
||||
unset($this->fonts[$font]);
|
||||
}
|
||||
} else {
|
||||
$old_cache_name = "php_$metrics_name";
|
||||
if (file_exists($fontcache . '/' . $old_cache_name)) {
|
||||
$this->addMessage(
|
||||
"openFont: php file doesn't exist $fontcache/$cache_name, creating it from the old format"
|
||||
);
|
||||
$old_cache = file_get_contents($fontcache . '/' . $old_cache_name);
|
||||
file_put_contents($fontcache . '/' . $cache_name, '<?php return ' . $old_cache . ';');
|
||||
|
||||
$this->openFont($font);
|
||||
return;
|
||||
$this->addMessage("openFont: json metrics file exists $fontcache/$cache_name");
|
||||
$cached_font_info = json_decode(file_get_contents($fontcache . '/' . $cache_name), true);
|
||||
if (!isset($cached_font_info['_version_']) || $cached_font_info['_version_'] != $this->fontcacheVersion) {
|
||||
$this->addMessage('openFont: font cache is out of date, regenerating');
|
||||
} else {
|
||||
$this->fonts[$font] = $cached_font_info;
|
||||
}
|
||||
}
|
||||
|
||||
if (!isset($this->fonts[$font]) && file_exists($dir . $metrics_name)) {
|
||||
if (!isset($this->fonts[$font]) && file_exists("$dir/$metrics_name")) {
|
||||
// then rebuild the php_<font>.afm file from the <font>.afm file
|
||||
$this->addMessage("openFont: build php file from $dir$metrics_name");
|
||||
$this->addMessage("openFont: build php file from $dir/$metrics_name");
|
||||
$data = [];
|
||||
|
||||
// 20 => 'space'
|
||||
|
@ -3375,7 +3351,7 @@ EOT;
|
|||
$cidtogid = str_pad('', 256 * 256 * 2, "\x00");
|
||||
}
|
||||
|
||||
$file = file($dir . $metrics_name);
|
||||
$file = file("$dir/$metrics_name");
|
||||
|
||||
foreach ($file as $rowA) {
|
||||
$row = trim($rowA);
|
||||
|
@ -3529,7 +3505,7 @@ EOT;
|
|||
//Because of potential trouble with php safe mode, expect that the folder already exists.
|
||||
//If not existing, this will hit performance because of missing cached results.
|
||||
if (is_dir($fontcache) && is_writable($fontcache)) {
|
||||
file_put_contents($fontcache . '/' . $cache_name, '<?php return ' . var_export($data, true) . ';');
|
||||
file_put_contents("$fontcache/$cache_name", json_encode($data, JSON_PRETTY_PRINT));
|
||||
}
|
||||
$data = null;
|
||||
}
|
||||
|
@ -3537,8 +3513,6 @@ EOT;
|
|||
if (!isset($this->fonts[$font])) {
|
||||
$this->addMessage("openFont: no font file found for $font. Do you need to run load_font.php?");
|
||||
}
|
||||
|
||||
//pre_r($this->messages);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -3548,7 +3522,7 @@ EOT;
|
|||
* note that encoding='none' will need to be used for symbolic fonts
|
||||
* and 'differences' => an array of mappings between numbers 0->255 and character names.
|
||||
*
|
||||
* @param $fontName
|
||||
* @param string $fontName
|
||||
* @param string $encoding
|
||||
* @param bool $set
|
||||
* @param bool $isSubsetting
|
||||
|
@ -3696,8 +3670,8 @@ EOT;
|
|||
/**
|
||||
* sets the color for fill operations
|
||||
*
|
||||
* @param $color
|
||||
* @param bool $force
|
||||
* @param array $color
|
||||
* @param bool $force
|
||||
*/
|
||||
function setColor($color, $force = false)
|
||||
{
|
||||
|
@ -3719,9 +3693,7 @@ EOT;
|
|||
}
|
||||
|
||||
/**
|
||||
* sets the color for fill operations
|
||||
*
|
||||
* @param $fillRule
|
||||
* @param string $fillRule
|
||||
*/
|
||||
function setFillRule($fillRule)
|
||||
{
|
||||
|
@ -3735,8 +3707,8 @@ EOT;
|
|||
/**
|
||||
* sets the color for stroke operations
|
||||
*
|
||||
* @param $color
|
||||
* @param bool $force
|
||||
* @param array $color
|
||||
* @param bool $force
|
||||
*/
|
||||
function setStrokeColor($color, $force = false)
|
||||
{
|
||||
|
@ -3887,11 +3859,11 @@ EOT;
|
|||
/**
|
||||
* draw a line from one set of coordinates to another
|
||||
*
|
||||
* @param $x1
|
||||
* @param $y1
|
||||
* @param $x2
|
||||
* @param $y2
|
||||
* @param bool $stroke
|
||||
* @param float $x1
|
||||
* @param float $y1
|
||||
* @param float $x2
|
||||
* @param float $y2
|
||||
* @param bool $stroke
|
||||
*/
|
||||
function line($x1, $y1, $x2, $y2, $stroke = true)
|
||||
{
|
||||
|
@ -3905,14 +3877,14 @@ EOT;
|
|||
/**
|
||||
* draw a bezier curve based on 4 control points
|
||||
*
|
||||
* @param $x0
|
||||
* @param $y0
|
||||
* @param $x1
|
||||
* @param $y1
|
||||
* @param $x2
|
||||
* @param $y2
|
||||
* @param $x3
|
||||
* @param $y3
|
||||
* @param float $x0
|
||||
* @param float $y0
|
||||
* @param float $x1
|
||||
* @param float $y1
|
||||
* @param float $x2
|
||||
* @param float $y2
|
||||
* @param float $x3
|
||||
* @param float $y3
|
||||
*/
|
||||
function curve($x0, $y0, $x1, $y1, $x2, $y2, $x3, $y3)
|
||||
{
|
||||
|
@ -3926,13 +3898,13 @@ EOT;
|
|||
/**
|
||||
* draw a part of an ellipse
|
||||
*
|
||||
* @param $x0
|
||||
* @param $y0
|
||||
* @param $astart
|
||||
* @param $afinish
|
||||
* @param $r1
|
||||
* @param int $r2
|
||||
* @param int $angle
|
||||
* @param float $x0
|
||||
* @param float $y0
|
||||
* @param float $astart
|
||||
* @param float $afinish
|
||||
* @param float $r1
|
||||
* @param float $r2
|
||||
* @param float $angle
|
||||
* @param int $nSeg
|
||||
*/
|
||||
function partEllipse($x0, $y0, $astart, $afinish, $r1, $r2 = 0, $angle = 0, $nSeg = 8)
|
||||
|
@ -3943,14 +3915,14 @@ EOT;
|
|||
/**
|
||||
* draw a filled ellipse
|
||||
*
|
||||
* @param $x0
|
||||
* @param $y0
|
||||
* @param $r1
|
||||
* @param int $r2
|
||||
* @param int $angle
|
||||
* @param float $x0
|
||||
* @param float $y0
|
||||
* @param float $r1
|
||||
* @param float $r2
|
||||
* @param float $angle
|
||||
* @param int $nSeg
|
||||
* @param int $astart
|
||||
* @param int $afinish
|
||||
* @param float $astart
|
||||
* @param float $afinish
|
||||
*/
|
||||
function filledEllipse($x0, $y0, $r1, $r2 = 0, $angle = 0, $nSeg = 8, $astart = 0, $afinish = 360)
|
||||
{
|
||||
|
@ -3958,8 +3930,8 @@ EOT;
|
|||
}
|
||||
|
||||
/**
|
||||
* @param $x
|
||||
* @param $y
|
||||
* @param float $x
|
||||
* @param float $y
|
||||
*/
|
||||
function lineTo($x, $y)
|
||||
{
|
||||
|
@ -3967,8 +3939,8 @@ EOT;
|
|||
}
|
||||
|
||||
/**
|
||||
* @param $x
|
||||
* @param $y
|
||||
* @param float $x
|
||||
* @param float $y
|
||||
*/
|
||||
function moveTo($x, $y)
|
||||
{
|
||||
|
@ -3978,12 +3950,12 @@ EOT;
|
|||
/**
|
||||
* draw a bezier curve based on 4 control points
|
||||
*
|
||||
* @param $x1
|
||||
* @param $y1
|
||||
* @param $x2
|
||||
* @param $y2
|
||||
* @param $x3
|
||||
* @param $y3
|
||||
* @param float $x1
|
||||
* @param float $y1
|
||||
* @param float $x2
|
||||
* @param float $y2
|
||||
* @param float $x3
|
||||
* @param float $y3
|
||||
*/
|
||||
function curveTo($x1, $y1, $x2, $y2, $x3, $y3)
|
||||
{
|
||||
|
@ -3992,6 +3964,11 @@ EOT;
|
|||
|
||||
/**
|
||||
* draw a bezier curve based on 4 control points
|
||||
*
|
||||
* @param float $cpx
|
||||
* @param float $cpy
|
||||
* @param float $x
|
||||
* @param float $y
|
||||
*/
|
||||
function quadTo($cpx, $cpy, $x, $y)
|
||||
{
|
||||
|
@ -4019,18 +3996,18 @@ EOT;
|
|||
* nSeg is not allowed to be less than 2, as this will simply draw a line (and will even draw a
|
||||
* pretty crappy shape at 2, as we are approximating with bezier curves.
|
||||
*
|
||||
* @param $x0
|
||||
* @param $y0
|
||||
* @param $r1
|
||||
* @param int $r2
|
||||
* @param int $angle
|
||||
* @param int $nSeg
|
||||
* @param int $astart
|
||||
* @param int $afinish
|
||||
* @param bool $close
|
||||
* @param bool $fill
|
||||
* @param bool $stroke
|
||||
* @param bool $incomplete
|
||||
* @param float $x0
|
||||
* @param float $y0
|
||||
* @param float $r1
|
||||
* @param float $r2
|
||||
* @param float $angle
|
||||
* @param int $nSeg
|
||||
* @param float $astart
|
||||
* @param float $afinish
|
||||
* @param bool $close
|
||||
* @param bool $fill
|
||||
* @param bool $stroke
|
||||
* @param bool $incomplete
|
||||
*/
|
||||
function ellipse(
|
||||
$x0,
|
||||
|
@ -4144,11 +4121,11 @@ EOT;
|
|||
* (2,1) is 2 on, 1 off, 2 on, 1 off.. etc
|
||||
* phase is a modifier on the dash pattern which is used to shift the point at which the pattern starts.
|
||||
*
|
||||
* @param int $width
|
||||
* @param float $width
|
||||
* @param string $cap
|
||||
* @param string $join
|
||||
* @param string $dash
|
||||
* @param int $phase
|
||||
* @param array $dash
|
||||
* @param int $phase
|
||||
*/
|
||||
function setLineStyle($width = 1, $cap = '', $join = '', $dash = '', $phase = 0)
|
||||
{
|
||||
|
@ -4182,19 +4159,19 @@ EOT;
|
|||
/**
|
||||
* draw a polygon, the syntax for this is similar to the GD polygon command
|
||||
*
|
||||
* @param $p
|
||||
* @param $np
|
||||
* @param bool $f
|
||||
* @param float[] $p
|
||||
* @param bool $fill
|
||||
*/
|
||||
function polygon($p, $np, $f = false)
|
||||
public function polygon(array $p, bool $fill = false): void
|
||||
{
|
||||
$this->addContent(sprintf("\n%.3F %.3F m ", $p[0], $p[1]));
|
||||
|
||||
for ($i = 2; $i < $np * 2; $i = $i + 2) {
|
||||
$n = count($p);
|
||||
for ($i = 2; $i < $n; $i = $i + 2) {
|
||||
$this->addContent(sprintf("%.3F %.3F l ", $p[$i], $p[$i + 1]));
|
||||
}
|
||||
|
||||
if ($f) {
|
||||
if ($fill) {
|
||||
$this->addContent(' f');
|
||||
} else {
|
||||
$this->addContent(' S');
|
||||
|
@ -4205,10 +4182,10 @@ EOT;
|
|||
* a filled rectangle, note that it is the width and height of the rectangle which are the secondary parameters, not
|
||||
* the coordinates of the upper-right corner
|
||||
*
|
||||
* @param $x1
|
||||
* @param $y1
|
||||
* @param $width
|
||||
* @param $height
|
||||
* @param float $x1
|
||||
* @param float $y1
|
||||
* @param float $width
|
||||
* @param float $height
|
||||
*/
|
||||
function filledRectangle($x1, $y1, $width, $height)
|
||||
{
|
||||
|
@ -4219,10 +4196,10 @@ EOT;
|
|||
* draw a rectangle, note that it is the width and height of the rectangle which are the secondary parameters, not
|
||||
* the coordinates of the upper-right corner
|
||||
*
|
||||
* @param $x1
|
||||
* @param $y1
|
||||
* @param $width
|
||||
* @param $height
|
||||
* @param float $x1
|
||||
* @param float $y1
|
||||
* @param float $width
|
||||
* @param float $height
|
||||
*/
|
||||
function rectangle($x1, $y1, $width, $height)
|
||||
{
|
||||
|
@ -4233,10 +4210,10 @@ EOT;
|
|||
* draw a rectangle, note that it is the width and height of the rectangle which are the secondary parameters, not
|
||||
* the coordinates of the upper-right corner
|
||||
*
|
||||
* @param $x1
|
||||
* @param $y1
|
||||
* @param $width
|
||||
* @param $height
|
||||
* @param float $x1
|
||||
* @param float $y1
|
||||
* @param float $width
|
||||
* @param float $height
|
||||
*/
|
||||
function rect($x1, $y1, $width, $height)
|
||||
{
|
||||
|
@ -4348,8 +4325,10 @@ EOT;
|
|||
$color = implode(' ', $color) . ' rg';
|
||||
|
||||
$currentFontNum = $this->currentFontNum;
|
||||
$font = array_filter($this->objects[$this->currentNode]['info']['fonts'],
|
||||
function($item) use ($currentFontNum) { return $item['fontNum'] == $currentFontNum; });
|
||||
$font = array_filter(
|
||||
$this->objects[$this->currentNode]['info']['fonts'],
|
||||
function ($item) use ($currentFontNum) { return $item['fontNum'] == $currentFontNum; }
|
||||
);
|
||||
|
||||
$this->o_acroform($this->acroFormId, 'font',
|
||||
['objNum' => $font[0]['objNum'], 'fontNum' => $font[0]['fontNum']]);
|
||||
|
@ -4464,10 +4443,10 @@ EOT;
|
|||
/**
|
||||
* draw a clipping rectangle, all the elements added after this will be clipped
|
||||
*
|
||||
* @param $x1
|
||||
* @param $y1
|
||||
* @param $width
|
||||
* @param $height
|
||||
* @param float $x1
|
||||
* @param float $y1
|
||||
* @param float $width
|
||||
* @param float $height
|
||||
*/
|
||||
function clippingRectangle($x1, $y1, $width, $height)
|
||||
{
|
||||
|
@ -4478,14 +4457,14 @@ EOT;
|
|||
/**
|
||||
* draw a clipping rounded rectangle, all the elements added after this will be clipped
|
||||
*
|
||||
* @param $x1
|
||||
* @param $y1
|
||||
* @param $w
|
||||
* @param $h
|
||||
* @param $rTL
|
||||
* @param $rTR
|
||||
* @param $rBR
|
||||
* @param $rBL
|
||||
* @param float $x1
|
||||
* @param float $y1
|
||||
* @param float $w
|
||||
* @param float $h
|
||||
* @param float $rTL
|
||||
* @param float $rTR
|
||||
* @param float $rBR
|
||||
* @param float $rBL
|
||||
*/
|
||||
function clippingRectangleRounded($x1, $y1, $w, $h, $rTL, $rTR, $rBR, $rBL)
|
||||
{
|
||||
|
@ -4525,6 +4504,25 @@ EOT;
|
|||
$this->addContent(" W n");
|
||||
}
|
||||
|
||||
/**
|
||||
* draw a clipping polygon, the syntax for this is similar to the GD polygon command
|
||||
*
|
||||
* @param float[] $p
|
||||
*/
|
||||
public function clippingPolygon(array $p): void
|
||||
{
|
||||
$this->save();
|
||||
|
||||
$this->addContent(sprintf("\n%.3F %.3F m ", $p[0], $p[1]));
|
||||
|
||||
$n = count($p);
|
||||
for ($i = 2; $i < $n; $i = $i + 2) {
|
||||
$this->addContent(sprintf("%.3F %.3F l ", $p[$i], $p[$i + 1]));
|
||||
}
|
||||
|
||||
$this->addContent("W n");
|
||||
}
|
||||
|
||||
/**
|
||||
* ends the last clipping shape
|
||||
*/
|
||||
|
@ -4741,10 +4739,11 @@ EOT;
|
|||
/**
|
||||
* return the height in units of the current font in the given size
|
||||
*
|
||||
* @param $size
|
||||
* @return float|int
|
||||
* @param float $size
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
function getFontHeight($size)
|
||||
public function getFontHeight(float $size): float
|
||||
{
|
||||
if (!$this->numFonts) {
|
||||
$this->selectFont($this->defaultFont);
|
||||
|
@ -4776,10 +4775,11 @@ EOT;
|
|||
}
|
||||
|
||||
/**
|
||||
* @param $size
|
||||
* @return float|int
|
||||
* @param float $size
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
function getFontXHeight($size)
|
||||
public function getFontXHeight(float $size): float
|
||||
{
|
||||
if (!$this->numFonts) {
|
||||
$this->selectFont($this->defaultFont);
|
||||
|
@ -4802,10 +4802,11 @@ EOT;
|
|||
* if you add this number to the baseline, you get the level of the bottom of the font
|
||||
* it is in the pdf user units
|
||||
*
|
||||
* @param $size
|
||||
* @return float|int
|
||||
* @param float $size
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
function getFontDescender($size)
|
||||
public function getFontDescender(float $size): float
|
||||
{
|
||||
// note that this will most likely return a negative value
|
||||
if (!$this->numFonts) {
|
||||
|
@ -4822,8 +4823,6 @@ EOT;
|
|||
* filter the text, this is applied to all text just before being inserted into the pdf document
|
||||
* it escapes the various things that need to be escaped, and so on
|
||||
*
|
||||
* @access private
|
||||
*
|
||||
* @param $text
|
||||
* @param bool $bom
|
||||
* @param bool $convert_encoding
|
||||
|
@ -4843,7 +4842,7 @@ EOT;
|
|||
//$text = html_entity_decode($text, ENT_QUOTES);
|
||||
$text = mb_convert_encoding($text, self::$targetEncoding, 'UTF-8');
|
||||
}
|
||||
} else if ($bom) {
|
||||
} elseif ($bom) {
|
||||
$text = $this->utf8toUtf16BE($text, $bom);
|
||||
}
|
||||
|
||||
|
@ -4858,12 +4857,7 @@ EOT;
|
|||
* based on the excellent TCPDF code by Nicola Asuni and the
|
||||
* RFC for UTF-8 at http://www.faqs.org/rfcs/rfc3629.html
|
||||
*
|
||||
* @access private
|
||||
* @author Orion Richardson
|
||||
* @since January 5, 2008
|
||||
*
|
||||
* @param string $text UTF-8 string to process
|
||||
*
|
||||
* @return array UTF-8 codepoints array for the string
|
||||
*/
|
||||
function utf8toCodePointsArray(&$text)
|
||||
|
@ -4933,13 +4927,8 @@ EOT;
|
|||
* based on the excellent TCPDF code by Nicola Asuni and the
|
||||
* RFC for UTF-8 at http://www.faqs.org/rfcs/rfc3629.html
|
||||
*
|
||||
* @access private
|
||||
* @author Orion Richardson
|
||||
* @since January 5, 2008
|
||||
*
|
||||
* @param string $text UTF-8 string to process
|
||||
* @param boolean $bom whether to add the byte order marker
|
||||
*
|
||||
* @return string UTF-16 result string
|
||||
*/
|
||||
function utf8toUtf16BE(&$text, $bom = true)
|
||||
|
@ -5014,8 +5003,8 @@ EOT;
|
|||
/**
|
||||
* register text for font subsetting
|
||||
*
|
||||
* @param $font
|
||||
* @param $text
|
||||
* @param string $font
|
||||
* @param string $text
|
||||
*/
|
||||
function registerText($font, $text)
|
||||
{
|
||||
|
@ -5024,7 +5013,8 @@ EOT;
|
|||
}
|
||||
|
||||
if (!isset($this->stringSubsets[$font])) {
|
||||
$this->stringSubsets[$font] = [];
|
||||
$base_subset = "\u{fffd}\u{fffe}\u{ffff}";
|
||||
$this->stringSubsets[$font] = $this->utf8toCodePointsArray($base_subset);
|
||||
}
|
||||
|
||||
$this->stringSubsets[$font] = array_unique(
|
||||
|
@ -5035,14 +5025,14 @@ EOT;
|
|||
/**
|
||||
* add text to the document, at a specified location, size and angle on the page
|
||||
*
|
||||
* @param $x
|
||||
* @param $y
|
||||
* @param $size
|
||||
* @param $text
|
||||
* @param int $angle
|
||||
* @param int $wordSpaceAdjust
|
||||
* @param int $charSpaceAdjust
|
||||
* @param bool $smallCaps
|
||||
* @param float $x
|
||||
* @param float $y
|
||||
* @param float $size
|
||||
* @param string $text
|
||||
* @param float $angle
|
||||
* @param float $wordSpaceAdjust
|
||||
* @param float $charSpaceAdjust
|
||||
* @param bool $smallCaps
|
||||
*/
|
||||
function addText($x, $y, $size, $text, $angle = 0, $wordSpaceAdjust = 0, $charSpaceAdjust = 0, $smallCaps = false)
|
||||
{
|
||||
|
@ -5155,13 +5145,14 @@ EOT;
|
|||
* calculate how wide a given text string will be on a page, at a given size.
|
||||
* this can be called externally, but is also used by the other class functions
|
||||
*
|
||||
* @param float $size
|
||||
* @param float $size
|
||||
* @param string $text
|
||||
* @param float $word_spacing
|
||||
* @param float $char_spacing
|
||||
* @param float $wordSpacing
|
||||
* @param float $charSpacing
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
function getTextWidth($size, $text, $word_spacing = 0, $char_spacing = 0)
|
||||
public function getTextWidth(float $size, string $text, float $wordSpacing = 0.0, float $charSpacing = 0.0): float
|
||||
{
|
||||
static $ord_cache = [];
|
||||
|
||||
|
@ -5176,9 +5167,6 @@ EOT;
|
|||
|
||||
$text = str_replace(["\r", "\n"], "", $text);
|
||||
|
||||
// converts a number or a float to a string so it can get the width
|
||||
$text = "$text";
|
||||
|
||||
// hmm, this is where it all starts to get tricky - use the font information to
|
||||
// calculate the width of each character, add them up and convert to user units
|
||||
$w = 0;
|
||||
|
@ -5205,14 +5193,14 @@ EOT;
|
|||
|
||||
// add additional padding for space
|
||||
if (isset($current_font['codeToName'][$char]) && $current_font['codeToName'][$char] === 'space') { // Space
|
||||
$w += $word_spacing * $space_scale;
|
||||
$w += $wordSpacing * $space_scale;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// add additional char spacing
|
||||
if ($char_spacing != 0) {
|
||||
$w += $char_spacing * $space_scale * count($unicode);
|
||||
if ($charSpacing != 0) {
|
||||
$w += $charSpacing * $space_scale * count($unicode);
|
||||
}
|
||||
|
||||
} else {
|
||||
|
@ -5240,14 +5228,14 @@ EOT;
|
|||
|
||||
// add additional padding for space
|
||||
if (isset($current_font['codeToName'][$char]) && $current_font['codeToName'][$char] === 'space') { // Space
|
||||
$w += $word_spacing * $space_scale;
|
||||
$w += $wordSpacing * $space_scale;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// add additional char spacing
|
||||
if ($char_spacing != 0) {
|
||||
$w += $char_spacing * $space_scale * $len;
|
||||
if ($charSpacing != 0) {
|
||||
$w += $charSpacing * $space_scale * $len;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -5487,12 +5475,12 @@ EOT;
|
|||
}
|
||||
|
||||
/**
|
||||
* add content to the documents info object
|
||||
* Add content to the documents info object
|
||||
*
|
||||
* @param $label
|
||||
* @param int $value
|
||||
* @param string|array $label
|
||||
* @param string $value
|
||||
*/
|
||||
function addInfo($label, $value = 0)
|
||||
public function addInfo($label, string $value = ""): void
|
||||
{
|
||||
// this will only work if the label is one of the valid ones.
|
||||
// modify this so that arrays can be passed as well.
|
||||
|
@ -5500,7 +5488,7 @@ EOT;
|
|||
// else assume that they are both scalar, anything else will probably error
|
||||
if (is_array($label)) {
|
||||
foreach ($label as $l => $v) {
|
||||
$this->o_info($this->infoObject, $l, $v);
|
||||
$this->o_info($this->infoObject, $l, (string) $v);
|
||||
}
|
||||
} else {
|
||||
$this->o_info($this->infoObject, $label, $value);
|
80
library/vendor/dompdf/vendor/dompdf/dompdf/lib/fonts/installed-fonts.dist.json
vendored
Normal file
80
library/vendor/dompdf/vendor/dompdf/dompdf/lib/fonts/installed-fonts.dist.json
vendored
Normal file
|
@ -0,0 +1,80 @@
|
|||
{
|
||||
"sans-serif": {
|
||||
"normal": "Helvetica",
|
||||
"bold": "Helvetica-Bold",
|
||||
"italic": "Helvetica-Oblique",
|
||||
"bold_italic": "Helvetica-BoldOblique"
|
||||
},
|
||||
"times": {
|
||||
"normal": "Times-Roman",
|
||||
"bold": "Times-Bold",
|
||||
"italic": "Times-Italic",
|
||||
"bold_italic": "Times-BoldItalic"
|
||||
},
|
||||
"times-roman": {
|
||||
"normal": "Times-Roman",
|
||||
"bold": "Times-Bold",
|
||||
"italic": "Times-Italic",
|
||||
"bold_italic": "Times-BoldItalic"
|
||||
},
|
||||
"courier": {
|
||||
"normal": "Courier",
|
||||
"bold": "Courier-Bold",
|
||||
"italic": "Courier-Oblique",
|
||||
"bold_italic": "Courier-BoldOblique"
|
||||
},
|
||||
"helvetica": {
|
||||
"normal": "Helvetica",
|
||||
"bold": "Helvetica-Bold",
|
||||
"italic": "Helvetica-Oblique",
|
||||
"bold_italic": "Helvetica-BoldOblique"
|
||||
},
|
||||
"zapfdingbats": {
|
||||
"normal": "ZapfDingbats",
|
||||
"bold": "ZapfDingbats",
|
||||
"italic": "ZapfDingbats",
|
||||
"bold_italic": "ZapfDingbats"
|
||||
},
|
||||
"symbol": {
|
||||
"normal": "Symbol",
|
||||
"bold": "Symbol",
|
||||
"italic": "Symbol",
|
||||
"bold_italic": "Symbol"
|
||||
},
|
||||
"serif": {
|
||||
"normal": "Times-Roman",
|
||||
"bold": "Times-Bold",
|
||||
"italic": "Times-Italic",
|
||||
"bold_italic": "Times-BoldItalic"
|
||||
},
|
||||
"monospace": {
|
||||
"normal": "Courier",
|
||||
"bold": "Courier-Bold",
|
||||
"italic": "Courier-Oblique",
|
||||
"bold_italic": "Courier-BoldOblique"
|
||||
},
|
||||
"fixed": {
|
||||
"normal": "Courier",
|
||||
"bold": "Courier-Bold",
|
||||
"italic": "Courier-Oblique",
|
||||
"bold_italic": "Courier-BoldOblique"
|
||||
},
|
||||
"dejavu sans": {
|
||||
"bold": "DejaVuSans-Bold",
|
||||
"bold_italic": "DejaVuSans-BoldOblique",
|
||||
"italic": "DejaVuSans-Oblique",
|
||||
"normal": "DejaVuSans"
|
||||
},
|
||||
"dejavu sans mono": {
|
||||
"bold": "DejaVuSansMono-Bold",
|
||||
"bold_italic": "DejaVuSansMono-BoldOblique",
|
||||
"italic": "DejaVuSansMono-Oblique",
|
||||
"normal": "DejaVuSansMono"
|
||||
},
|
||||
"dejavu serif": {
|
||||
"bold": "DejaVuSerif-Bold",
|
||||
"bold_italic": "DejaVuSerif-BoldItalic",
|
||||
"italic": "DejaVuSerif-Italic",
|
||||
"normal": "DejaVuSerif"
|
||||
}
|
||||
}
|
Before Width: | Height: | Size: 618 B After Width: | Height: | Size: 618 B |
Before Width: | Height: | Size: 581 B After Width: | Height: | Size: 581 B |
|
@ -2,15 +2,12 @@
|
|||
* dompdf default stylesheet.
|
||||
*
|
||||
* @package dompdf
|
||||
* @link http://dompdf.github.com/
|
||||
* @author Benj Carson <benjcarson@digitaljunkies.ca>
|
||||
* @author Blake Ross <BlakeR1234@aol.com>
|
||||
* @author Fabien Ménager <fabien.menager@gmail.com>
|
||||
* @link https://github.com/dompdf/dompdf
|
||||
* @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
|
||||
*
|
||||
* Portions from Mozilla
|
||||
* @link https://dxr.mozilla.org/mozilla-central/source/layout/style/res/html.css
|
||||
* @license http://mozilla.org/MPL/2.0/ Mozilla Public License, v. 2.0
|
||||
* @license http://mozilla.org/MPL/2.0/ Mozilla Public License, v. 2.0
|
||||
*
|
||||
* Portions from W3C
|
||||
* @link https://drafts.csswg.org/css-ui-3/#default-style-sheet
|
|
@ -1,11 +1,7 @@
|
|||
<?php
|
||||
/**
|
||||
* @package dompdf
|
||||
* @link http://dompdf.github.com/
|
||||
* @author Benj Carson <benjcarson@digitaljunkies.ca>
|
||||
* @author Orion Richardson <orionr@yahoo.com>
|
||||
* @author Helmut Tischer <htischer@weihenstephan.org>
|
||||
* @author Fabien Ménager <fabien.menager@gmail.com>
|
||||
* @link https://github.com/dompdf/dompdf
|
||||
* @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
|
||||
*/
|
||||
|
||||
|
@ -14,10 +10,10 @@ namespace Dompdf\Adapter;
|
|||
|
||||
use Dompdf\Canvas;
|
||||
use Dompdf\Dompdf;
|
||||
use Dompdf\Helpers;
|
||||
use Dompdf\Exception;
|
||||
use Dompdf\FontMetrics;
|
||||
use Dompdf\Helpers;
|
||||
use Dompdf\Image\Cache;
|
||||
use Dompdf\PhpEvaluator;
|
||||
use FontLib\Exception\FontNotFoundException;
|
||||
|
||||
/**
|
||||
|
@ -41,66 +37,66 @@ class CPDF implements Canvas
|
|||
/**
|
||||
* Dimensions of paper sizes in points
|
||||
*
|
||||
* @var array;
|
||||
* @var array
|
||||
*/
|
||||
static $PAPER_SIZES = [
|
||||
"4a0" => [0, 0, 4767.87, 6740.79],
|
||||
"2a0" => [0, 0, 3370.39, 4767.87],
|
||||
"a0" => [0, 0, 2383.94, 3370.39],
|
||||
"a1" => [0, 0, 1683.78, 2383.94],
|
||||
"a2" => [0, 0, 1190.55, 1683.78],
|
||||
"a3" => [0, 0, 841.89, 1190.55],
|
||||
"a4" => [0, 0, 595.28, 841.89],
|
||||
"a5" => [0, 0, 419.53, 595.28],
|
||||
"a6" => [0, 0, 297.64, 419.53],
|
||||
"a7" => [0, 0, 209.76, 297.64],
|
||||
"a8" => [0, 0, 147.40, 209.76],
|
||||
"a9" => [0, 0, 104.88, 147.40],
|
||||
"a10" => [0, 0, 73.70, 104.88],
|
||||
"b0" => [0, 0, 2834.65, 4008.19],
|
||||
"b1" => [0, 0, 2004.09, 2834.65],
|
||||
"b2" => [0, 0, 1417.32, 2004.09],
|
||||
"b3" => [0, 0, 1000.63, 1417.32],
|
||||
"b4" => [0, 0, 708.66, 1000.63],
|
||||
"b5" => [0, 0, 498.90, 708.66],
|
||||
"b6" => [0, 0, 354.33, 498.90],
|
||||
"b7" => [0, 0, 249.45, 354.33],
|
||||
"b8" => [0, 0, 175.75, 249.45],
|
||||
"b9" => [0, 0, 124.72, 175.75],
|
||||
"b10" => [0, 0, 87.87, 124.72],
|
||||
"c0" => [0, 0, 2599.37, 3676.54],
|
||||
"c1" => [0, 0, 1836.85, 2599.37],
|
||||
"c2" => [0, 0, 1298.27, 1836.85],
|
||||
"c3" => [0, 0, 918.43, 1298.27],
|
||||
"c4" => [0, 0, 649.13, 918.43],
|
||||
"c5" => [0, 0, 459.21, 649.13],
|
||||
"c6" => [0, 0, 323.15, 459.21],
|
||||
"c7" => [0, 0, 229.61, 323.15],
|
||||
"c8" => [0, 0, 161.57, 229.61],
|
||||
"c9" => [0, 0, 113.39, 161.57],
|
||||
"c10" => [0, 0, 79.37, 113.39],
|
||||
"ra0" => [0, 0, 2437.80, 3458.27],
|
||||
"ra1" => [0, 0, 1729.13, 2437.80],
|
||||
"ra2" => [0, 0, 1218.90, 1729.13],
|
||||
"ra3" => [0, 0, 864.57, 1218.90],
|
||||
"ra4" => [0, 0, 609.45, 864.57],
|
||||
"sra0" => [0, 0, 2551.18, 3628.35],
|
||||
"sra1" => [0, 0, 1814.17, 2551.18],
|
||||
"sra2" => [0, 0, 1275.59, 1814.17],
|
||||
"sra3" => [0, 0, 907.09, 1275.59],
|
||||
"sra4" => [0, 0, 637.80, 907.09],
|
||||
"letter" => [0, 0, 612.00, 792.00],
|
||||
"half-letter" => [0, 0, 396.00, 612.00],
|
||||
"legal" => [0, 0, 612.00, 1008.00],
|
||||
"ledger" => [0, 0, 1224.00, 792.00],
|
||||
"tabloid" => [0, 0, 792.00, 1224.00],
|
||||
"executive" => [0, 0, 521.86, 756.00],
|
||||
"folio" => [0, 0, 612.00, 936.00],
|
||||
"commercial #10 envelope" => [0, 0, 684, 297],
|
||||
"catalog #10 1/2 envelope" => [0, 0, 648, 864],
|
||||
"8.5x11" => [0, 0, 612.00, 792.00],
|
||||
"8.5x14" => [0, 0, 612.00, 1008.0],
|
||||
"11x17" => [0, 0, 792.00, 1224.00],
|
||||
"4a0" => [0.0, 0.0, 4767.87, 6740.79],
|
||||
"2a0" => [0.0, 0.0, 3370.39, 4767.87],
|
||||
"a0" => [0.0, 0.0, 2383.94, 3370.39],
|
||||
"a1" => [0.0, 0.0, 1683.78, 2383.94],
|
||||
"a2" => [0.0, 0.0, 1190.55, 1683.78],
|
||||
"a3" => [0.0, 0.0, 841.89, 1190.55],
|
||||
"a4" => [0.0, 0.0, 595.28, 841.89],
|
||||
"a5" => [0.0, 0.0, 419.53, 595.28],
|
||||
"a6" => [0.0, 0.0, 297.64, 419.53],
|
||||
"a7" => [0.0, 0.0, 209.76, 297.64],
|
||||
"a8" => [0.0, 0.0, 147.40, 209.76],
|
||||
"a9" => [0.0, 0.0, 104.88, 147.40],
|
||||
"a10" => [0.0, 0.0, 73.70, 104.88],
|
||||
"b0" => [0.0, 0.0, 2834.65, 4008.19],
|
||||
"b1" => [0.0, 0.0, 2004.09, 2834.65],
|
||||
"b2" => [0.0, 0.0, 1417.32, 2004.09],
|
||||
"b3" => [0.0, 0.0, 1000.63, 1417.32],
|
||||
"b4" => [0.0, 0.0, 708.66, 1000.63],
|
||||
"b5" => [0.0, 0.0, 498.90, 708.66],
|
||||
"b6" => [0.0, 0.0, 354.33, 498.90],
|
||||
"b7" => [0.0, 0.0, 249.45, 354.33],
|
||||
"b8" => [0.0, 0.0, 175.75, 249.45],
|
||||
"b9" => [0.0, 0.0, 124.72, 175.75],
|
||||
"b10" => [0.0, 0.0, 87.87, 124.72],
|
||||
"c0" => [0.0, 0.0, 2599.37, 3676.54],
|
||||
"c1" => [0.0, 0.0, 1836.85, 2599.37],
|
||||
"c2" => [0.0, 0.0, 1298.27, 1836.85],
|
||||
"c3" => [0.0, 0.0, 918.43, 1298.27],
|
||||
"c4" => [0.0, 0.0, 649.13, 918.43],
|
||||
"c5" => [0.0, 0.0, 459.21, 649.13],
|
||||
"c6" => [0.0, 0.0, 323.15, 459.21],
|
||||
"c7" => [0.0, 0.0, 229.61, 323.15],
|
||||
"c8" => [0.0, 0.0, 161.57, 229.61],
|
||||
"c9" => [0.0, 0.0, 113.39, 161.57],
|
||||
"c10" => [0.0, 0.0, 79.37, 113.39],
|
||||
"ra0" => [0.0, 0.0, 2437.80, 3458.27],
|
||||
"ra1" => [0.0, 0.0, 1729.13, 2437.80],
|
||||
"ra2" => [0.0, 0.0, 1218.90, 1729.13],
|
||||
"ra3" => [0.0, 0.0, 864.57, 1218.90],
|
||||
"ra4" => [0.0, 0.0, 609.45, 864.57],
|
||||
"sra0" => [0.0, 0.0, 2551.18, 3628.35],
|
||||
"sra1" => [0.0, 0.0, 1814.17, 2551.18],
|
||||
"sra2" => [0.0, 0.0, 1275.59, 1814.17],
|
||||
"sra3" => [0.0, 0.0, 907.09, 1275.59],
|
||||
"sra4" => [0.0, 0.0, 637.80, 907.09],
|
||||
"letter" => [0.0, 0.0, 612.00, 792.00],
|
||||
"half-letter" => [0.0, 0.0, 396.00, 612.00],
|
||||
"legal" => [0.0, 0.0, 612.00, 1008.00],
|
||||
"ledger" => [0.0, 0.0, 1224.00, 792.00],
|
||||
"tabloid" => [0.0, 0.0, 792.00, 1224.00],
|
||||
"executive" => [0.0, 0.0, 521.86, 756.00],
|
||||
"folio" => [0.0, 0.0, 612.00, 936.00],
|
||||
"commercial #10 envelope" => [0.0, 0.0, 684.00, 297.00],
|
||||
"catalog #10 1/2 envelope" => [0.0, 0.0, 648.00, 864.00],
|
||||
"8.5x11" => [0.0, 0.0, 612.00, 792.00],
|
||||
"8.5x14" => [0.0, 0.0, 612.00, 1008.00],
|
||||
"11x17" => [0.0, 0.0, 792.00, 1224.00],
|
||||
];
|
||||
|
||||
/**
|
||||
|
@ -145,13 +141,6 @@ class CPDF implements Canvas
|
|||
*/
|
||||
protected $_page_count;
|
||||
|
||||
/**
|
||||
* Text to display on every page
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_page_text;
|
||||
|
||||
/**
|
||||
* Array of pages for accessing after rendering is initially complete
|
||||
*
|
||||
|
@ -166,24 +155,16 @@ class CPDF implements Canvas
|
|||
*/
|
||||
protected $_current_opacity = 1;
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* @param mixed $paper The size of paper to use in this PDF ({@link CPDF::$PAPER_SIZES})
|
||||
* @param string $orientation The orientation of the document (either 'landscape' or 'portrait')
|
||||
* @param Dompdf $dompdf The Dompdf instance
|
||||
*/
|
||||
public function __construct($paper = "letter", $orientation = "portrait", Dompdf $dompdf = null)
|
||||
public function __construct($paper = "letter", $orientation = "portrait", ?Dompdf $dompdf = null)
|
||||
{
|
||||
if (is_array($paper)) {
|
||||
$size = $paper;
|
||||
} else if (isset(self::$PAPER_SIZES[mb_strtolower($paper)])) {
|
||||
$size = self::$PAPER_SIZES[mb_strtolower($paper)];
|
||||
$size = array_map("floatval", $paper);
|
||||
} else {
|
||||
$size = self::$PAPER_SIZES["letter"];
|
||||
$paper = strtolower($paper);
|
||||
$size = self::$PAPER_SIZES[$paper] ?? self::$PAPER_SIZES["letter"];
|
||||
}
|
||||
|
||||
if (mb_strtolower($orientation) === "landscape") {
|
||||
if (strtolower($orientation) === "landscape") {
|
||||
[$size[2], $size[3]] = [$size[3], $size[2]];
|
||||
}
|
||||
|
||||
|
@ -209,14 +190,10 @@ class CPDF implements Canvas
|
|||
$this->_height = $size[3] - $size[1];
|
||||
|
||||
$this->_page_number = $this->_page_count = 1;
|
||||
$this->_page_text = [];
|
||||
|
||||
$this->_pages = [$this->_pdf->getFirstPageId()];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Dompdf
|
||||
*/
|
||||
public function get_dompdf()
|
||||
{
|
||||
return $this->_dompdf;
|
||||
|
@ -232,13 +209,7 @@ class CPDF implements Canvas
|
|||
return $this->_pdf;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add meta information to the PDF
|
||||
*
|
||||
* @param string $label label of the value (Creator, Producer, etc.)
|
||||
* @param string $value the text to set
|
||||
*/
|
||||
public function add_info($label, $value)
|
||||
public function add_info(string $label, string $value): void
|
||||
{
|
||||
$this->_pdf->addInfo($label, $value);
|
||||
}
|
||||
|
@ -324,17 +295,13 @@ class CPDF implements Canvas
|
|||
}
|
||||
|
||||
/**
|
||||
* @access private
|
||||
* Serialize the pdf object's current state for retrieval later
|
||||
*/
|
||||
public function serialize_object($id)
|
||||
{
|
||||
// Serialize the pdf object's current state for retrieval later
|
||||
return $this->_pdf->serializeObject($id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @access private
|
||||
*/
|
||||
public function reopen_serialized_object($obj)
|
||||
{
|
||||
return $this->_pdf->restoreSerializedObject($obj);
|
||||
|
@ -342,37 +309,21 @@ class CPDF implements Canvas
|
|||
|
||||
//........................................................................
|
||||
|
||||
/**
|
||||
* Returns the PDF's width in points
|
||||
* @return float
|
||||
*/
|
||||
public function get_width()
|
||||
{
|
||||
return $this->_width;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the PDF's height in points
|
||||
* @return float
|
||||
*/
|
||||
public function get_height()
|
||||
{
|
||||
return $this->_height;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current page number
|
||||
* @return int
|
||||
*/
|
||||
public function get_page_number()
|
||||
{
|
||||
return $this->_page_number;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the total number of pages in the document
|
||||
* @return int
|
||||
*/
|
||||
public function get_page_count()
|
||||
{
|
||||
return $this->_page_count;
|
||||
|
@ -388,11 +339,6 @@ class CPDF implements Canvas
|
|||
$this->_page_number = $num;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the page count
|
||||
*
|
||||
* @param int $count
|
||||
*/
|
||||
public function set_page_count($count)
|
||||
{
|
||||
$this->_page_count = $count;
|
||||
|
@ -402,15 +348,14 @@ class CPDF implements Canvas
|
|||
* Sets the stroke color
|
||||
*
|
||||
* See {@link Style::set_color()} for the format of the color array.
|
||||
*
|
||||
* @param array $color
|
||||
*/
|
||||
protected function _set_stroke_color($color)
|
||||
{
|
||||
$this->_pdf->setStrokeColor($color);
|
||||
$alpha = isset($color["alpha"]) ? $color["alpha"] : 1;
|
||||
if ($this->_current_opacity != 1) {
|
||||
$alpha *= $this->_current_opacity;
|
||||
}
|
||||
$alpha *= $this->_current_opacity;
|
||||
$this->_set_line_transparency("Normal", $alpha);
|
||||
}
|
||||
|
||||
|
@ -418,15 +363,14 @@ class CPDF implements Canvas
|
|||
* Sets the fill colour
|
||||
*
|
||||
* See {@link Style::set_color()} for the format of the colour array.
|
||||
*
|
||||
* @param array $color
|
||||
*/
|
||||
protected function _set_fill_color($color)
|
||||
{
|
||||
$this->_pdf->setColor($color);
|
||||
$alpha = isset($color["alpha"]) ? $color["alpha"] : 1;
|
||||
if ($this->_current_opacity) {
|
||||
$alpha *= $this->_current_opacity;
|
||||
}
|
||||
$alpha *= $this->_current_opacity;
|
||||
$this->_set_fill_transparency("Normal", $alpha);
|
||||
}
|
||||
|
||||
|
@ -440,8 +384,8 @@ class CPDF implements Canvas
|
|||
* ColorDodge, ColorBurn, HardLight, SoftLight, Difference,
|
||||
* Exclusion
|
||||
*
|
||||
* @param string $mode the blending mode to use
|
||||
* @param float $opacity 0.0 fully transparent, 1.0 fully opaque
|
||||
* @param string $mode the blending mode to use
|
||||
* @param float $opacity 0.0 fully transparent, 1.0 fully opaque
|
||||
*/
|
||||
protected function _set_line_transparency($mode, $opacity)
|
||||
{
|
||||
|
@ -458,8 +402,8 @@ class CPDF implements Canvas
|
|||
* ColorDogde, ColorBurn, HardLight, SoftLight, Difference,
|
||||
* Exclusion
|
||||
*
|
||||
* @param string $mode the blending mode to use
|
||||
* @param float $opacity 0.0 fully transparent, 1.0 fully opaque
|
||||
* @param string $mode the blending mode to use
|
||||
* @param float $opacity 0.0 fully transparent, 1.0 fully opaque
|
||||
*/
|
||||
protected function _set_fill_transparency($mode, $opacity)
|
||||
{
|
||||
|
@ -471,23 +415,17 @@ class CPDF implements Canvas
|
|||
*
|
||||
* @see Cpdf::setLineStyle()
|
||||
*
|
||||
* @param float $width
|
||||
* @param float $width
|
||||
* @param string $cap
|
||||
* @param string $join
|
||||
* @param array $dash
|
||||
* @param array $dash
|
||||
*/
|
||||
protected function _set_line_style($width, $cap, $join, $dash)
|
||||
{
|
||||
$this->_pdf->setLineStyle($width, $cap, $join, $dash);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the opacity
|
||||
*
|
||||
* @param $opacity
|
||||
* @param $mode
|
||||
*/
|
||||
public function set_opacity($opacity, $mode = "Normal")
|
||||
public function set_opacity(float $opacity, string $mode = "Normal"): void
|
||||
{
|
||||
$this->_set_line_transparency($mode, $opacity);
|
||||
$this->_set_fill_transparency($mode, $opacity);
|
||||
|
@ -511,90 +449,33 @@ class CPDF implements Canvas
|
|||
return $this->_height - $y;
|
||||
}
|
||||
|
||||
/**
|
||||
* Canvas implementation
|
||||
*
|
||||
* @param float $x1
|
||||
* @param float $y1
|
||||
* @param float $x2
|
||||
* @param float $y2
|
||||
* @param array $color
|
||||
* @param float $width
|
||||
* @param array $style
|
||||
*/
|
||||
public function line($x1, $y1, $x2, $y2, $color, $width, $style = [])
|
||||
public function line($x1, $y1, $x2, $y2, $color, $width, $style = [], $cap = "butt")
|
||||
{
|
||||
$this->_set_stroke_color($color);
|
||||
$this->_set_line_style($width, "butt", "", $style);
|
||||
$this->_set_line_style($width, $cap, "", $style);
|
||||
|
||||
$this->_pdf->line($x1, $this->y($y1),
|
||||
$x2, $this->y($y2));
|
||||
$this->_set_line_transparency("Normal", $this->_current_opacity);
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw line at the specified coordinates on every page.
|
||||
*
|
||||
* See {@link Style::munge_color()} for the format of the colour array.
|
||||
*
|
||||
* @param float $x1
|
||||
* @param float $y1
|
||||
* @param float $x2
|
||||
* @param float $y2
|
||||
* @param array $color
|
||||
* @param float $width
|
||||
* @param array $style optional
|
||||
*/
|
||||
public function page_line($x1, $y1, $x2, $y2, $color, $width, $style = [])
|
||||
{
|
||||
$_t = 'line';
|
||||
$this->_page_text[] = compact('_t', 'x1', 'y1', 'x2', 'y2', 'color', 'width', 'style');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param float $x
|
||||
* @param float $y
|
||||
* @param float $r1
|
||||
* @param float $r2
|
||||
* @param float $astart
|
||||
* @param float $aend
|
||||
* @param array $color
|
||||
* @param float $width
|
||||
* @param array $style
|
||||
*/
|
||||
public function arc($x, $y, $r1, $r2, $astart, $aend, $color, $width, $style = [])
|
||||
public function arc($x, $y, $r1, $r2, $astart, $aend, $color, $width, $style = [], $cap = "butt")
|
||||
{
|
||||
$this->_set_stroke_color($color);
|
||||
$this->_set_line_style($width, "butt", "", $style);
|
||||
$this->_set_line_style($width, $cap, "", $style);
|
||||
|
||||
$this->_pdf->ellipse($x, $this->y($y), $r1, $r2, 0, 8, $astart, $aend, false, false, true, false);
|
||||
$this->_set_line_transparency("Normal", $this->_current_opacity);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param float $x1
|
||||
* @param float $y1
|
||||
* @param float $w
|
||||
* @param float $h
|
||||
* @param array $color
|
||||
* @param float $width
|
||||
* @param array $style
|
||||
*/
|
||||
public function rectangle($x1, $y1, $w, $h, $color, $width, $style = [])
|
||||
public function rectangle($x1, $y1, $w, $h, $color, $width, $style = [], $cap = "butt")
|
||||
{
|
||||
$this->_set_stroke_color($color);
|
||||
$this->_set_line_style($width, "butt", "", $style);
|
||||
$this->_set_line_style($width, $cap, "", $style);
|
||||
$this->_pdf->rectangle($x1, $this->y($y1) - $h, $w, $h);
|
||||
$this->_set_line_transparency("Normal", $this->_current_opacity);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param float $x1
|
||||
* @param float $y1
|
||||
* @param float $w
|
||||
* @param float $h
|
||||
* @param array $color
|
||||
*/
|
||||
public function filled_rectangle($x1, $y1, $w, $h, $color)
|
||||
{
|
||||
$this->_set_fill_color($color);
|
||||
|
@ -602,143 +483,87 @@ class CPDF implements Canvas
|
|||
$this->_set_fill_transparency("Normal", $this->_current_opacity);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param float $x1
|
||||
* @param float $y1
|
||||
* @param float $w
|
||||
* @param float $h
|
||||
*/
|
||||
public function clipping_rectangle($x1, $y1, $w, $h)
|
||||
{
|
||||
$this->_pdf->clippingRectangle($x1, $this->y($y1) - $h, $w, $h);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param float $x1
|
||||
* @param float $y1
|
||||
* @param float $w
|
||||
* @param float $h
|
||||
* @param float $rTL
|
||||
* @param float $rTR
|
||||
* @param float $rBR
|
||||
* @param float $rBL
|
||||
*/
|
||||
public function clipping_roundrectangle($x1, $y1, $w, $h, $rTL, $rTR, $rBR, $rBL)
|
||||
{
|
||||
$this->_pdf->clippingRectangleRounded($x1, $this->y($y1) - $h, $w, $h, $rTL, $rTR, $rBR, $rBL);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function clipping_polygon(array $points): void
|
||||
{
|
||||
// Adjust y values
|
||||
for ($i = 1; $i < count($points); $i += 2) {
|
||||
$points[$i] = $this->y($points[$i]);
|
||||
}
|
||||
|
||||
$this->_pdf->clippingPolygon($points);
|
||||
}
|
||||
|
||||
public function clipping_end()
|
||||
{
|
||||
$this->_pdf->clippingEnd();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function save()
|
||||
{
|
||||
$this->_pdf->saveState();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function restore()
|
||||
{
|
||||
$this->_pdf->restoreState();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $angle
|
||||
* @param $x
|
||||
* @param $y
|
||||
*/
|
||||
public function rotate($angle, $x, $y)
|
||||
{
|
||||
$this->_pdf->rotate($angle, $x, $y);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $angle_x
|
||||
* @param $angle_y
|
||||
* @param $x
|
||||
* @param $y
|
||||
*/
|
||||
public function skew($angle_x, $angle_y, $x, $y)
|
||||
{
|
||||
$this->_pdf->skew($angle_x, $angle_y, $x, $y);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $s_x
|
||||
* @param $s_y
|
||||
* @param $x
|
||||
* @param $y
|
||||
*/
|
||||
public function scale($s_x, $s_y, $x, $y)
|
||||
{
|
||||
$this->_pdf->scale($s_x, $s_y, $x, $y);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $t_x
|
||||
* @param $t_y
|
||||
*/
|
||||
public function translate($t_x, $t_y)
|
||||
{
|
||||
$this->_pdf->translate($t_x, $t_y);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $a
|
||||
* @param $b
|
||||
* @param $c
|
||||
* @param $d
|
||||
* @param $e
|
||||
* @param $f
|
||||
*/
|
||||
public function transform($a, $b, $c, $d, $e, $f)
|
||||
{
|
||||
$this->_pdf->transform([$a, $b, $c, $d, $e, $f]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $points
|
||||
* @param array $color
|
||||
* @param null $width
|
||||
* @param array $style
|
||||
* @param bool $fill
|
||||
*/
|
||||
public function polygon($points, $color, $width = null, $style = [], $fill = false)
|
||||
{
|
||||
$this->_set_fill_color($color);
|
||||
$this->_set_stroke_color($color);
|
||||
|
||||
if (!$fill && isset($width)) {
|
||||
$this->_set_line_style($width, "square", "miter", $style);
|
||||
}
|
||||
|
||||
// Adjust y values
|
||||
for ($i = 1; $i < count($points); $i += 2) {
|
||||
$points[$i] = $this->y($points[$i]);
|
||||
}
|
||||
|
||||
$this->_pdf->polygon($points, count($points) / 2, $fill);
|
||||
$this->_pdf->polygon($points, $fill);
|
||||
|
||||
$this->_set_fill_transparency("Normal", $this->_current_opacity);
|
||||
$this->_set_line_transparency("Normal", $this->_current_opacity);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param float $x
|
||||
* @param float $y
|
||||
* @param float $r1
|
||||
* @param array $color
|
||||
* @param null $width
|
||||
* @param null $style
|
||||
* @param bool $fill
|
||||
*/
|
||||
public function circle($x, $y, $r1, $color, $width = null, $style = null, $fill = false)
|
||||
public function circle($x, $y, $r, $color, $width = null, $style = [], $fill = false)
|
||||
{
|
||||
$this->_set_fill_color($color);
|
||||
$this->_set_stroke_color($color);
|
||||
|
@ -747,7 +572,7 @@ class CPDF implements Canvas
|
|||
$this->_set_line_style($width, "round", "round", $style);
|
||||
}
|
||||
|
||||
$this->_pdf->ellipse($x, $this->y($y), $r1, 0, 0, 8, 0, 360, 1, $fill);
|
||||
$this->_pdf->ellipse($x, $this->y($y), $r, 0, 0, 8, 0, 360, 1, $fill);
|
||||
|
||||
$this->_set_fill_transparency("Normal", $this->_current_opacity);
|
||||
$this->_set_line_transparency("Normal", $this->_current_opacity);
|
||||
|
@ -759,8 +584,7 @@ class CPDF implements Canvas
|
|||
* @param string $image_url
|
||||
* @param string $type
|
||||
*
|
||||
* @throws Exception
|
||||
* @return string The url of the newly converted image
|
||||
* @return string|null The url of the newly converted image
|
||||
*/
|
||||
protected function _convert_to_png($image_url, $type)
|
||||
{
|
||||
|
@ -772,6 +596,8 @@ class CPDF implements Canvas
|
|||
|
||||
$func_name = "imagecreatefrom$type";
|
||||
|
||||
set_error_handler([Helpers::class, "record_warnings"]);
|
||||
|
||||
if (!function_exists($func_name)) {
|
||||
if (!method_exists(Helpers::class, $func_name)) {
|
||||
throw new Exception("Function $func_name() not found. Cannot convert $type image: $image_url. Please install the image PHP extension.");
|
||||
|
@ -779,8 +605,6 @@ class CPDF implements Canvas
|
|||
$func_name = [Helpers::class, $func_name];
|
||||
}
|
||||
|
||||
set_error_handler([Helpers::class, "record_warnings"]);
|
||||
|
||||
try {
|
||||
$im = call_user_func($func_name, $image_url);
|
||||
|
||||
|
@ -795,25 +619,19 @@ class CPDF implements Canvas
|
|||
imagepng($im, $filename);
|
||||
imagedestroy($im);
|
||||
} else {
|
||||
$filename = Cache::$broken_image;
|
||||
$filename = null;
|
||||
}
|
||||
} finally {
|
||||
restore_error_handler();
|
||||
}
|
||||
|
||||
Cache::addTempImage($image_url, $filename);
|
||||
if ($filename !== null) {
|
||||
Cache::addTempImage($image_url, $filename);
|
||||
}
|
||||
|
||||
return $filename;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $img
|
||||
* @param float $x
|
||||
* @param float $y
|
||||
* @param int $w
|
||||
* @param int $h
|
||||
* @param string $resolution
|
||||
*/
|
||||
public function image($img, $x, $y, $w, $h, $resolution = "normal")
|
||||
{
|
||||
[$width, $height, $type] = Helpers::dompdf_getimagesize($img, $this->get_dompdf()->getHttpContext());
|
||||
|
@ -839,6 +657,11 @@ class CPDF implements Canvas
|
|||
case "bmp":
|
||||
if ($debug_png) print "!!!{$type}!!!";
|
||||
$img = $this->_convert_to_png($img, $type);
|
||||
if ($img === null) {
|
||||
if ($debug_png) print '!!!conversion to PDF failed!!!';
|
||||
$this->image(Cache::$broken_image, $x, $y, $w, $h, $resolution);
|
||||
break;
|
||||
}
|
||||
|
||||
case "png":
|
||||
if ($debug_png) print '!!!png!!!';
|
||||
|
@ -922,17 +745,6 @@ class CPDF implements Canvas
|
|||
$pdf->addFormField($ft, rand(), $x, $this->y($y) - $h, $x + $w, $this->y($y), $ff, $size, $color);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param float $x
|
||||
* @param float $y
|
||||
* @param string $text
|
||||
* @param string $font
|
||||
* @param float $size
|
||||
* @param array $color
|
||||
* @param float $word_space
|
||||
* @param float $char_space
|
||||
* @param float $angle
|
||||
*/
|
||||
public function text($x, $y, $text, $font, $size, $color = [0, 0, 0], $word_space = 0.0, $char_space = 0.0, $angle = 0.0)
|
||||
{
|
||||
$pdf = $this->_pdf;
|
||||
|
@ -947,9 +759,6 @@ class CPDF implements Canvas
|
|||
$this->_set_fill_transparency("Normal", $this->_current_opacity);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $code
|
||||
*/
|
||||
public function javascript($code)
|
||||
{
|
||||
$this->_pdf->addJavascript($code);
|
||||
|
@ -957,25 +766,11 @@ class CPDF implements Canvas
|
|||
|
||||
//........................................................................
|
||||
|
||||
/**
|
||||
* Add a named destination (similar to <a name="foo">...</a> in html)
|
||||
*
|
||||
* @param string $anchorname The name of the named destination
|
||||
*/
|
||||
public function add_named_dest($anchorname)
|
||||
{
|
||||
$this->_pdf->addDestination($anchorname, "Fit");
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a link to the pdf
|
||||
*
|
||||
* @param string $url The url to link to
|
||||
* @param float $x The x position of the link
|
||||
* @param float $y The y position of the link
|
||||
* @param float $width The width of the link
|
||||
* @param float $height The height of the link
|
||||
*/
|
||||
public function add_link($url, $x, $y, $width, $height)
|
||||
{
|
||||
$y = $this->y($y) - $height;
|
||||
|
@ -987,28 +782,20 @@ class CPDF implements Canvas
|
|||
$this->_pdf->addInternalLink($name, $x, $y, $x + $width, $y + $height);
|
||||
}
|
||||
} else {
|
||||
$this->_pdf->addLink(rawurldecode($url), $x, $y, $x + $width, $y + $height);
|
||||
$this->_pdf->addLink($url, $x, $y, $x + $width, $y + $height);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $text
|
||||
* @param string $font
|
||||
* @param float $size
|
||||
* @param float $word_spacing
|
||||
* @param float $char_spacing
|
||||
* @return float
|
||||
* @throws FontNotFoundException
|
||||
*/
|
||||
public function get_text_width($text, $font, $size, $word_spacing = 0, $char_spacing = 0)
|
||||
public function get_text_width($text, $font, $size, $word_spacing = 0.0, $char_spacing = 0.0)
|
||||
{
|
||||
$this->_pdf->selectFont($font, '', true, $this->_dompdf->getOptions()->getIsFontSubsettingEnabled());
|
||||
return $this->_pdf->getTextWidth($size, $text, $word_spacing, $char_spacing);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $font
|
||||
* @param float $size
|
||||
* @return float|int
|
||||
* @throws FontNotFoundException
|
||||
*/
|
||||
public function get_font_height($font, $size)
|
||||
|
@ -1026,9 +813,7 @@ class CPDF implements Canvas
|
|||
}*/
|
||||
|
||||
/**
|
||||
* @param string $font
|
||||
* @param float $size
|
||||
* @return float
|
||||
* @throws FontNotFoundException
|
||||
*/
|
||||
public function get_font_baseline($font, $size)
|
||||
{
|
||||
|
@ -1037,53 +822,53 @@ class CPDF implements Canvas
|
|||
}
|
||||
|
||||
/**
|
||||
* Writes text at the specified x and y coordinates on every page
|
||||
* Processes a callback or script on every page.
|
||||
*
|
||||
* The strings '{PAGE_NUM}' and '{PAGE_COUNT}' are automatically replaced
|
||||
* with their current values.
|
||||
*
|
||||
* See {@link Style::munge_color()} for the format of the colour array.
|
||||
*
|
||||
* @param float $x
|
||||
* @param float $y
|
||||
* @param string $text the text to write
|
||||
* @param string $font the font file to use
|
||||
* @param float $size the font size, in points
|
||||
* @param array $color
|
||||
* @param float $word_space word spacing adjustment
|
||||
* @param float $char_space char spacing adjustment
|
||||
* @param float $angle angle to write the text at, measured CW starting from the x-axis
|
||||
*/
|
||||
public function page_text($x, $y, $text, $font, $size, $color = [0, 0, 0], $word_space = 0.0, $char_space = 0.0, $angle = 0.0)
|
||||
{
|
||||
$_t = "text";
|
||||
$this->_page_text[] = compact("_t", "x", "y", "text", "font", "size", "color", "word_space", "char_space", "angle");
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes a callback or script on every page
|
||||
*
|
||||
* The callback function receives the four parameters `$pageNumber`,
|
||||
* `$pageCount`, `$pdf`, and `$fontMetrics`, in that order. If a script is
|
||||
* passed as string, the variables `$PAGE_NUM`, `$PAGE_COUNT`, `$pdf`, and
|
||||
* `$fontMetrics` are available instead.
|
||||
* The callback function receives the four parameters `int $pageNumber`,
|
||||
* `int $pageCount`, `Canvas $canvas`, and `FontMetrics $fontMetrics`, in
|
||||
* that order. If a script is passed as string, the variables `$PAGE_NUM`,
|
||||
* `$PAGE_COUNT`, `$pdf`, and `$fontMetrics` are available instead. Passing
|
||||
* a script as string is deprecated and will be removed in a future version.
|
||||
*
|
||||
* This function can be used to add page numbers to all pages after the
|
||||
* first one, for example.
|
||||
*
|
||||
* @param callable|string $code The callback function or PHP script to process on every page
|
||||
* @param callable|string $callback The callback function or PHP script to process on every page
|
||||
*/
|
||||
public function page_script($code)
|
||||
public function page_script($callback): void
|
||||
{
|
||||
if (is_callable($code)) {
|
||||
$this->_page_text[] = [
|
||||
"_t" => "callback",
|
||||
"callback" => $code
|
||||
];
|
||||
} else {
|
||||
$_t = "script";
|
||||
$this->_page_text[] = compact("_t", "code");
|
||||
if (is_string($callback)) {
|
||||
$this->processPageScript(function (
|
||||
int $PAGE_NUM,
|
||||
int $PAGE_COUNT,
|
||||
self $pdf,
|
||||
FontMetrics $fontMetrics
|
||||
) use ($callback) {
|
||||
eval($callback);
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
$this->processPageScript($callback);
|
||||
}
|
||||
|
||||
public function page_text($x, $y, $text, $font, $size, $color = [0, 0, 0], $word_space = 0.0, $char_space = 0.0, $angle = 0.0)
|
||||
{
|
||||
$this->processPageScript(function (int $pageNumber, int $pageCount) use ($x, $y, $text, $font, $size, $color, $word_space, $char_space, $angle) {
|
||||
$text = str_replace(
|
||||
["{PAGE_NUM}", "{PAGE_COUNT}"],
|
||||
[$pageNumber, $pageCount],
|
||||
$text
|
||||
);
|
||||
$this->text($x, $y, $text, $font, $size, $color, $word_space, $char_space, $angle);
|
||||
});
|
||||
}
|
||||
|
||||
public function page_line($x1, $y1, $x2, $y2, $color, $width, $style = [])
|
||||
{
|
||||
$this->processPageScript(function () use ($x1, $y1, $x2, $y2, $color, $width, $style) {
|
||||
$this->line($x1, $y1, $x2, $y2, $color, $width, $style);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1099,60 +884,21 @@ class CPDF implements Canvas
|
|||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add text to each page after rendering is complete
|
||||
*/
|
||||
protected function _add_page_text()
|
||||
protected function processPageScript(callable $callback): void
|
||||
{
|
||||
if (!count($this->_page_text)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$page_number = 1;
|
||||
$eval = null;
|
||||
$pageNumber = 1;
|
||||
|
||||
foreach ($this->_pages as $pid) {
|
||||
$this->reopen_object($pid);
|
||||
|
||||
foreach ($this->_page_text as $pt) {
|
||||
extract($pt);
|
||||
|
||||
switch ($_t) {
|
||||
case "text":
|
||||
$text = str_replace(["{PAGE_NUM}", "{PAGE_COUNT}"],
|
||||
[$page_number, $this->_page_count], $text);
|
||||
$this->text($x, $y, $text, $font, $size, $color, $word_space, $char_space, $angle);
|
||||
break;
|
||||
|
||||
case "callback":
|
||||
$fontMetrics = $this->get_dompdf()->getFontMetrics();
|
||||
$callback($page_number, $this->_page_count, $this, $fontMetrics);
|
||||
break;
|
||||
|
||||
case "script":
|
||||
if (!$eval) {
|
||||
$eval = new PhpEvaluator($this);
|
||||
}
|
||||
$eval->evaluate($code, ["PAGE_NUM" => $page_number, "PAGE_COUNT" => $this->_page_count]);
|
||||
break;
|
||||
|
||||
case "line":
|
||||
$this->line($x1, $y1, $x2, $y2, $color, $width, $style);
|
||||
break;
|
||||
}
|
||||
}
|
||||
$fontMetrics = $this->_dompdf->getFontMetrics();
|
||||
$callback($pageNumber, $this->_page_count, $this, $fontMetrics);
|
||||
|
||||
$this->close_object();
|
||||
$page_number++;
|
||||
$pageNumber++;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Streams the PDF to the client.
|
||||
*
|
||||
* @param string $filename The filename to present to the client.
|
||||
* @param array $options Associative array: 'compress' => 1 or 0 (default 1); 'Attachment' => 1 or 0 (default 1).
|
||||
*/
|
||||
public function stream($filename = "document.pdf", $options = [])
|
||||
{
|
||||
if (headers_sent()) {
|
||||
|
@ -1162,8 +908,6 @@ class CPDF implements Canvas
|
|||
if (!isset($options["compress"])) $options["compress"] = true;
|
||||
if (!isset($options["Attachment"])) $options["Attachment"] = true;
|
||||
|
||||
$this->_add_page_text();
|
||||
|
||||
$debug = !$options['compress'];
|
||||
$tmp = ltrim($this->_pdf->output($debug));
|
||||
|
||||
|
@ -1179,18 +923,10 @@ class CPDF implements Canvas
|
|||
flush();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the PDF as a string.
|
||||
*
|
||||
* @param array $options Associative array: 'compress' => 1 or 0 (default 1).
|
||||
* @return string
|
||||
*/
|
||||
public function output($options = [])
|
||||
{
|
||||
if (!isset($options["compress"])) $options["compress"] = true;
|
||||
|
||||
$this->_add_page_text();
|
||||
|
||||
$debug = !$options['compress'];
|
||||
|
||||
return $this->_pdf->output($debug);
|
|
@ -1,17 +1,15 @@
|
|||
<?php
|
||||
/**
|
||||
* @package dompdf
|
||||
* @link http://dompdf.github.com/
|
||||
* @author Benj Carson <benjcarson@digitaljunkies.ca>
|
||||
* @author Fabien Ménager <fabien.menager@gmail.com>
|
||||
* @link https://github.com/dompdf/dompdf
|
||||
* @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
|
||||
*/
|
||||
namespace Dompdf\Adapter;
|
||||
|
||||
use Dompdf\Canvas;
|
||||
use Dompdf\Dompdf;
|
||||
use Dompdf\Image\Cache;
|
||||
use Dompdf\Helpers;
|
||||
use Dompdf\Image\Cache;
|
||||
|
||||
/**
|
||||
* Image rendering interface
|
||||
|
@ -130,29 +128,24 @@ class GD implements Canvas
|
|||
const FONT_SCALE = 0.75;
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* @param mixed $size The size of image to create: array(x1,y1,x2,y2) or "letter", "legal", etc.
|
||||
* @param string $orientation The orientation of the document (either 'landscape' or 'portrait')
|
||||
* @param Dompdf $dompdf
|
||||
* @param float $aa_factor Anti-aliasing factor, 1 for no AA
|
||||
* @param array $bg_color Image background color: array(r,g,b,a), 0 <= r,g,b,a <= 1
|
||||
* @param string|float[] $paper The paper size to use as either a standard paper size (see {@link CPDF::$PAPER_SIZES}) or
|
||||
* an array of the form `[x1, y1, x2, y2]` (typically `[0, 0, width, height]`).
|
||||
* @param string $orientation The paper orientation, either `portrait` or `landscape`.
|
||||
* @param Dompdf $dompdf The Dompdf instance.
|
||||
* @param float $aa_factor Anti-aliasing factor, 1 for no AA
|
||||
* @param array $bg_color Image background color: array(r,g,b,a), 0 <= r,g,b,a <= 1
|
||||
*/
|
||||
public function __construct($size = 'letter', $orientation = "portrait", Dompdf $dompdf = null, $aa_factor = 1.0, $bg_color = [1, 1, 1, 0])
|
||||
public function __construct($paper = "letter", $orientation = "portrait", ?Dompdf $dompdf = null, $aa_factor = 1.0, $bg_color = [1, 1, 1, 0])
|
||||
{
|
||||
|
||||
if (!is_array($size)) {
|
||||
$size = strtolower($size);
|
||||
|
||||
if (isset(CPDF::$PAPER_SIZES[$size])) {
|
||||
$size = CPDF::$PAPER_SIZES[$size];
|
||||
} else {
|
||||
$size = CPDF::$PAPER_SIZES["letter"];
|
||||
}
|
||||
if (is_array($paper)) {
|
||||
$size = array_map("floatval", $paper);
|
||||
} else {
|
||||
$paper = strtolower($paper);
|
||||
$size = CPDF::$PAPER_SIZES[$paper] ?? CPDF::$PAPER_SIZES["letter"];
|
||||
}
|
||||
|
||||
if (strtolower($orientation) === "landscape") {
|
||||
list($size[2], $size[3]) = [$size[3], $size[2]];
|
||||
[$size[2], $size[3]] = [$size[3], $size[2]];
|
||||
}
|
||||
|
||||
if ($dompdf === null) {
|
||||
|
@ -190,9 +183,6 @@ class GD implements Canvas
|
|||
$this->new_page();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Dompdf
|
||||
*/
|
||||
public function get_dompdf()
|
||||
{
|
||||
return $this->_dompdf;
|
||||
|
@ -228,21 +218,11 @@ class GD implements Canvas
|
|||
return round($this->_height / $this->_aa_factor);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current page number
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function get_page_number()
|
||||
{
|
||||
return $this->_page_number;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the total number of pages in the document
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function get_page_count()
|
||||
{
|
||||
return $this->_page_count;
|
||||
|
@ -258,23 +238,12 @@ class GD implements Canvas
|
|||
$this->_page_number = $num;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the page count
|
||||
*
|
||||
* @param int $count
|
||||
*/
|
||||
public function set_page_count($count)
|
||||
{
|
||||
$this->_page_count = $count;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the opacity
|
||||
*
|
||||
* @param $opacity
|
||||
* @param $mode
|
||||
*/
|
||||
public function set_opacity($opacity, $mode = "Normal")
|
||||
public function set_opacity(float $opacity, string $mode = "Normal"): void
|
||||
{
|
||||
// FIXME
|
||||
}
|
||||
|
@ -284,7 +253,7 @@ class GD implements Canvas
|
|||
* previously allocated colors in $this->_colors.
|
||||
*
|
||||
* @param array $color The new current color
|
||||
* @return int The allocated color
|
||||
* @return int The allocated color
|
||||
*/
|
||||
protected function _allocate_color($color)
|
||||
{
|
||||
|
@ -342,30 +311,61 @@ class GD implements Canvas
|
|||
* Scales value down from the current canvas DPI to 72 DPI
|
||||
*
|
||||
* @param float $length
|
||||
* @return int
|
||||
* @return float
|
||||
*/
|
||||
protected function _downscale($length)
|
||||
{
|
||||
return round(($length / $this->dpi * 72) / $this->_aa_factor);
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws a line from x1,y1 to x2,y2
|
||||
*
|
||||
* See {@link Style::munge_color()} for the format of the color array.
|
||||
* See {@link Cpdf::setLineStyle()} for a description of the format of the
|
||||
* $style parameter (aka dash).
|
||||
*
|
||||
* @param float $x1
|
||||
* @param float $y1
|
||||
* @param float $x2
|
||||
* @param float $y2
|
||||
* @param array $color
|
||||
* @param float $width
|
||||
* @param array $style
|
||||
*/
|
||||
public function line($x1, $y1, $x2, $y2, $color, $width, $style = null)
|
||||
protected function convertStyle(array $style, int $color, int $width): array
|
||||
{
|
||||
$gdStyle = [];
|
||||
|
||||
if (count($style) === 1) {
|
||||
$style[] = $style[0];
|
||||
}
|
||||
|
||||
foreach ($style as $index => $s) {
|
||||
$d = $this->_upscale($s);
|
||||
|
||||
for ($i = 0; $i < $d; $i++) {
|
||||
for ($j = 0; $j < $width; $j++) {
|
||||
$gdStyle[] = $index % 2 === 0
|
||||
? $color
|
||||
: IMG_COLOR_TRANSPARENT;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $gdStyle;
|
||||
}
|
||||
|
||||
public function line($x1, $y1, $x2, $y2, $color, $width, $style = [], $cap = "butt")
|
||||
{
|
||||
// Account for the fact that round and square caps are expected to
|
||||
// extend outwards
|
||||
if ($cap === "round" || $cap === "square") {
|
||||
// Shift line by half width
|
||||
$w = $width / 2;
|
||||
$a = $x2 - $x1;
|
||||
$b = $y2 - $y1;
|
||||
$c = sqrt($a ** 2 + $b ** 2);
|
||||
$dx = $a * $w / $c;
|
||||
$dy = $b * $w / $c;
|
||||
|
||||
$x1 -= $dx;
|
||||
$x2 -= $dx;
|
||||
$y1 -= $dy;
|
||||
$y2 -= $dy;
|
||||
|
||||
// Adapt dash pattern
|
||||
if (is_array($style)) {
|
||||
foreach ($style as $index => &$s) {
|
||||
$s = $index % 2 === 0 ? $s + $width : $s - $width;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Scale by the AA factor and DPI
|
||||
$x1 = $this->_upscale($x1);
|
||||
|
@ -378,34 +378,7 @@ class GD implements Canvas
|
|||
|
||||
// Convert the style array if required
|
||||
if (is_array($style) && count($style) > 0) {
|
||||
$gd_style = [];
|
||||
|
||||
if (count($style) == 1) {
|
||||
for ($i = 0; $i < $style[0] * $this->_aa_factor; $i++) {
|
||||
$gd_style[] = $c;
|
||||
}
|
||||
|
||||
for ($i = 0; $i < $style[0] * $this->_aa_factor; $i++) {
|
||||
$gd_style[] = $this->_bg_color;
|
||||
}
|
||||
} else {
|
||||
$i = 0;
|
||||
foreach ($style as $length) {
|
||||
if ($i % 2 == 0) {
|
||||
// 'On' pattern
|
||||
for ($i = 0; $i < $style[0] * $this->_aa_factor; $i++) {
|
||||
$gd_style[] = $c;
|
||||
}
|
||||
|
||||
} else {
|
||||
// Off pattern
|
||||
for ($i = 0; $i < $style[0] * $this->_aa_factor; $i++) {
|
||||
$gd_style[] = $this->_bg_color;
|
||||
}
|
||||
}
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
$gd_style = $this->convertStyle($style, $c, $width);
|
||||
|
||||
if (!empty($gd_style)) {
|
||||
imagesetstyle($this->get_image(), $gd_style);
|
||||
|
@ -418,39 +391,59 @@ class GD implements Canvas
|
|||
imageline($this->get_image(), $x1, $y1, $x2, $y2, $c);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param float $x1
|
||||
* @param float $y1
|
||||
* @param float $r1
|
||||
* @param float $r2
|
||||
* @param float $astart
|
||||
* @param float $aend
|
||||
* @param array $color
|
||||
* @param float $width
|
||||
* @param array $style
|
||||
*/
|
||||
public function arc($x1, $y1, $r1, $r2, $astart, $aend, $color, $width, $style = [])
|
||||
public function arc($x, $y, $r1, $r2, $astart, $aend, $color, $width, $style = [], $cap = "butt")
|
||||
{
|
||||
// @todo
|
||||
// Account for the fact that round and square caps are expected to
|
||||
// extend outwards
|
||||
if ($cap === "round" || $cap === "square") {
|
||||
// Adapt dash pattern
|
||||
if (is_array($style)) {
|
||||
foreach ($style as $index => &$s) {
|
||||
$s = $index % 2 === 0 ? $s + $width : $s - $width;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Scale by the AA factor and DPI
|
||||
$x = $this->_upscale($x);
|
||||
$y = $this->_upscale($y);
|
||||
$w = $this->_upscale($r1 * 2);
|
||||
$h = $this->_upscale($r2 * 2);
|
||||
$width = $this->_upscale($width);
|
||||
|
||||
// Adapt angles as imagearc counts clockwise
|
||||
$start = 360 - $aend;
|
||||
$end = 360 - $astart;
|
||||
|
||||
$c = $this->_allocate_color($color);
|
||||
|
||||
// Convert the style array if required
|
||||
if (is_array($style) && count($style) > 0) {
|
||||
$gd_style = $this->convertStyle($style, $c, $width);
|
||||
|
||||
if (!empty($gd_style)) {
|
||||
imagesetstyle($this->get_image(), $gd_style);
|
||||
$c = IMG_COLOR_STYLED;
|
||||
}
|
||||
}
|
||||
|
||||
imagesetthickness($this->get_image(), $width);
|
||||
|
||||
imagearc($this->get_image(), $x, $y, $w, $h, $start, $end, $c);
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws a rectangle at x1,y1 with width w and height h
|
||||
*
|
||||
* See {@link Style::munge_color()} for the format of the color array.
|
||||
* See {@link Cpdf::setLineStyle()} for a description of the $style
|
||||
* parameter (aka dash)
|
||||
*
|
||||
* @param float $x1
|
||||
* @param float $y1
|
||||
* @param float $w
|
||||
* @param float $h
|
||||
* @param array $color
|
||||
* @param float $width
|
||||
* @param array $style
|
||||
*/
|
||||
public function rectangle($x1, $y1, $w, $h, $color, $width, $style = null)
|
||||
public function rectangle($x1, $y1, $w, $h, $color, $width, $style = [], $cap = "butt")
|
||||
{
|
||||
// Account for the fact that round and square caps are expected to
|
||||
// extend outwards
|
||||
if ($cap === "round" || $cap === "square") {
|
||||
// Adapt dash pattern
|
||||
if (is_array($style)) {
|
||||
foreach ($style as $index => &$s) {
|
||||
$s = $index % 2 === 0 ? $s + $width : $s - $width;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Scale by the AA factor and DPI
|
||||
$x1 = $this->_upscale($x1);
|
||||
|
@ -463,13 +456,7 @@ class GD implements Canvas
|
|||
|
||||
// Convert the style array if required
|
||||
if (is_array($style) && count($style) > 0) {
|
||||
$gd_style = [];
|
||||
|
||||
foreach ($style as $length) {
|
||||
for ($i = 0; $i < $length; $i++) {
|
||||
$gd_style[] = $c;
|
||||
}
|
||||
}
|
||||
$gd_style = $this->convertStyle($style, $c, $width);
|
||||
|
||||
if (!empty($gd_style)) {
|
||||
imagesetstyle($this->get_image(), $gd_style);
|
||||
|
@ -479,20 +466,18 @@ class GD implements Canvas
|
|||
|
||||
imagesetthickness($this->get_image(), $width);
|
||||
|
||||
imagerectangle($this->get_image(), $x1, $y1, $x1 + $w, $y1 + $h, $c);
|
||||
if ($c === IMG_COLOR_STYLED) {
|
||||
imagepolygon($this->get_image(), [
|
||||
$x1, $y1,
|
||||
$x1 + $w, $y1,
|
||||
$x1 + $w, $y1 + $h,
|
||||
$x1, $y1 + $h
|
||||
], $c);
|
||||
} else {
|
||||
imagerectangle($this->get_image(), $x1, $y1, $x1 + $w, $y1 + $h, $c);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws a filled rectangle at x1,y1 with width w and height h
|
||||
*
|
||||
* See {@link Style::munge_color()} for the format of the color array.
|
||||
*
|
||||
* @param float $x1
|
||||
* @param float $y1
|
||||
* @param float $w
|
||||
* @param float $h
|
||||
* @param array $color
|
||||
*/
|
||||
public function filled_rectangle($x1, $y1, $w, $h, $color)
|
||||
{
|
||||
// Scale by the AA factor and DPI
|
||||
|
@ -506,14 +491,6 @@ class GD implements Canvas
|
|||
imagefilledrectangle($this->get_image(), $x1, $y1, $x1 + $w, $y1 + $h, $c);
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts a clipping rectangle at x1,y1 with width w and height h
|
||||
*
|
||||
* @param float $x1
|
||||
* @param float $y1
|
||||
* @param float $w
|
||||
* @param float $h
|
||||
*/
|
||||
public function clipping_rectangle($x1, $y1, $w, $h)
|
||||
{
|
||||
// @todo
|
||||
|
@ -524,127 +501,65 @@ class GD implements Canvas
|
|||
// @todo
|
||||
}
|
||||
|
||||
/**
|
||||
* Ends the last clipping shape
|
||||
*/
|
||||
public function clipping_polygon(array $points): void
|
||||
{
|
||||
// @todo
|
||||
}
|
||||
|
||||
public function clipping_end()
|
||||
{
|
||||
// @todo
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function save()
|
||||
{
|
||||
$this->get_dompdf()->getOptions()->setDpi(72);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function restore()
|
||||
{
|
||||
$this->get_dompdf()->getOptions()->setDpi($this->dpi);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $angle
|
||||
* @param $x
|
||||
* @param $y
|
||||
*/
|
||||
public function rotate($angle, $x, $y)
|
||||
{
|
||||
// @todo
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $angle_x
|
||||
* @param $angle_y
|
||||
* @param $x
|
||||
* @param $y
|
||||
*/
|
||||
public function skew($angle_x, $angle_y, $x, $y)
|
||||
{
|
||||
// @todo
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $s_x
|
||||
* @param $s_y
|
||||
* @param $x
|
||||
* @param $y
|
||||
*/
|
||||
public function scale($s_x, $s_y, $x, $y)
|
||||
{
|
||||
// @todo
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $t_x
|
||||
* @param $t_y
|
||||
*/
|
||||
public function translate($t_x, $t_y)
|
||||
{
|
||||
// @todo
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $a
|
||||
* @param $b
|
||||
* @param $c
|
||||
* @param $d
|
||||
* @param $e
|
||||
* @param $f
|
||||
*/
|
||||
public function transform($a, $b, $c, $d, $e, $f)
|
||||
{
|
||||
// @todo
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws a polygon
|
||||
*
|
||||
* The polygon is formed by joining all the points stored in the $points
|
||||
* array. $points has the following structure:
|
||||
* <code>
|
||||
* array(0 => x1,
|
||||
* 1 => y1,
|
||||
* 2 => x2,
|
||||
* 3 => y2,
|
||||
* ...
|
||||
* );
|
||||
* </code>
|
||||
*
|
||||
* See {@link Style::munge_color()} for the format of the color array.
|
||||
* See {@link Cpdf::setLineStyle()} for a description of the $style
|
||||
* parameter (aka dash)
|
||||
*
|
||||
* @param array $points
|
||||
* @param array $color
|
||||
* @param float $width
|
||||
* @param array $style
|
||||
* @param bool $fill Fills the polygon if true
|
||||
*/
|
||||
public function polygon($points, $color, $width = null, $style = null, $fill = false)
|
||||
public function polygon($points, $color, $width = null, $style = [], $fill = false)
|
||||
{
|
||||
|
||||
// Scale each point by the AA factor and DPI
|
||||
foreach (array_keys($points) as $i) {
|
||||
$points[$i] = $this->_upscale($points[$i]);
|
||||
}
|
||||
|
||||
$width = isset($width) ? $this->_upscale($width) : null;
|
||||
|
||||
$c = $this->_allocate_color($color);
|
||||
|
||||
// Convert the style array if required
|
||||
if (is_array($style) && count($style) > 0 && !$fill) {
|
||||
$gd_style = [];
|
||||
|
||||
foreach ($style as $length) {
|
||||
for ($i = 0; $i < $length; $i++) {
|
||||
$gd_style[] = $c;
|
||||
}
|
||||
}
|
||||
if (is_array($style) && count($style) > 0 && isset($width) && !$fill) {
|
||||
$gd_style = $this->convertStyle($style, $c, $width);
|
||||
|
||||
if (!empty($gd_style)) {
|
||||
imagesetstyle($this->get_image(), $gd_style);
|
||||
|
@ -652,7 +567,7 @@ class GD implements Canvas
|
|||
}
|
||||
}
|
||||
|
||||
imagesetthickness($this->get_image(), isset($width) ? round($width) : 0);
|
||||
imagesetthickness($this->get_image(), isset($width) ? $width : 0);
|
||||
|
||||
if ($fill) {
|
||||
imagefilledpolygon($this->get_image(), $points, $c);
|
||||
|
@ -661,39 +576,19 @@ class GD implements Canvas
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws a circle at $x,$y with radius $r
|
||||
*
|
||||
* See {@link Style::munge_color()} for the format of the color array.
|
||||
* See {@link Cpdf::setLineStyle()} for a description of the $style
|
||||
* parameter (aka dash)
|
||||
*
|
||||
* @param float $x
|
||||
* @param float $y
|
||||
* @param float $r
|
||||
* @param array $color
|
||||
* @param float $width
|
||||
* @param array $style
|
||||
* @param bool $fill Fills the circle if true
|
||||
*/
|
||||
public function circle($x, $y, $r, $color, $width = null, $style = null, $fill = false)
|
||||
public function circle($x, $y, $r, $color, $width = null, $style = [], $fill = false)
|
||||
{
|
||||
// Scale by the AA factor and DPI
|
||||
$x = $this->_upscale($x);
|
||||
$y = $this->_upscale($y);
|
||||
$d = $this->_upscale(2 * $r);
|
||||
$width = isset($width) ? $this->_upscale($width) : null;
|
||||
|
||||
$c = $this->_allocate_color($color);
|
||||
|
||||
// Convert the style array if required
|
||||
if (is_array($style) && count($style) > 0 && !$fill) {
|
||||
$gd_style = [];
|
||||
|
||||
foreach ($style as $length) {
|
||||
for ($i = 0; $i < $length; $i++) {
|
||||
$gd_style[] = $c;
|
||||
}
|
||||
}
|
||||
if (is_array($style) && count($style) > 0 && isset($width) && !$fill) {
|
||||
$gd_style = $this->convertStyle($style, $c, $width);
|
||||
|
||||
if (!empty($gd_style)) {
|
||||
imagesetstyle($this->get_image(), $gd_style);
|
||||
|
@ -701,7 +596,7 @@ class GD implements Canvas
|
|||
}
|
||||
}
|
||||
|
||||
imagesetthickness($this->get_image(), isset($width) ? round($width) : 0);
|
||||
imagesetthickness($this->get_image(), isset($width) ? $width : 0);
|
||||
|
||||
if ($fill) {
|
||||
imagefilledellipse($this->get_image(), $x, $y, $d, $d, $c);
|
||||
|
@ -711,24 +606,11 @@ class GD implements Canvas
|
|||
}
|
||||
|
||||
/**
|
||||
* Add an image to the pdf.
|
||||
* The image is placed at the specified x and y coordinates with the
|
||||
* given width and height.
|
||||
*
|
||||
* @param string $img_url the path to the image
|
||||
* @param float $x x position
|
||||
* @param float $y y position
|
||||
* @param int $w width (in pixels)
|
||||
* @param int $h height (in pixels)
|
||||
* @param string $resolution
|
||||
* @return void
|
||||
*
|
||||
* @throws \Exception
|
||||
* @internal param string $img_type the type (e.g. extension) of the image
|
||||
*/
|
||||
public function image($img_url, $x, $y, $w, $h, $resolution = "normal")
|
||||
public function image($img, $x, $y, $w, $h, $resolution = "normal")
|
||||
{
|
||||
$img_type = Cache::detect_type($img_url, $this->get_dompdf()->getHttpContext());
|
||||
$img_type = Cache::detect_type($img, $this->get_dompdf()->getHttpContext());
|
||||
|
||||
if (!$img_type) {
|
||||
return;
|
||||
|
@ -737,11 +619,11 @@ class GD implements Canvas
|
|||
$func_name = "imagecreatefrom$img_type";
|
||||
if (!function_exists($func_name)) {
|
||||
if (!method_exists(Helpers::class, $func_name)) {
|
||||
throw new \Exception("Function $func_name() not found. Cannot convert $img_type image: $img_url. Please install the image PHP extension.");
|
||||
throw new \Exception("Function $func_name() not found. Cannot convert $img_type image: $img. Please install the image PHP extension.");
|
||||
}
|
||||
$func_name = [Helpers::class, $func_name];
|
||||
}
|
||||
$src = @call_user_func($func_name, $img_url);
|
||||
$src = @call_user_func($func_name, $img);
|
||||
|
||||
if (!$src) {
|
||||
return; // Probably should add to $_dompdf_errors or whatever here
|
||||
|
@ -760,22 +642,6 @@ class GD implements Canvas
|
|||
imagecopyresampled($this->get_image(), $src, $x, $y, 0, 0, $w, $h, $img_w, $img_h);
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes text at the specified x and y coordinates
|
||||
* See {@link Style::munge_color()} for the format of the color array.
|
||||
*
|
||||
* @param float $x
|
||||
* @param float $y
|
||||
* @param string $text the text to write
|
||||
* @param string $font the font file to use
|
||||
* @param float $size the font size, in points
|
||||
* @param array $color
|
||||
* @param float $word_spacing word spacing adjustment
|
||||
* @param float $char_spacing
|
||||
* @param float $angle Text angle
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function text($x, $y, $text, $font, $size, $color = [0, 0, 0], $word_spacing = 0.0, $char_spacing = 0.0, $angle = 0.0)
|
||||
{
|
||||
// Scale by the AA factor and DPI
|
||||
|
@ -805,61 +671,26 @@ class GD implements Canvas
|
|||
// Not implemented
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a named destination (similar to <a name="foo">...</a> in html)
|
||||
*
|
||||
* @param string $anchorname The name of the named destination
|
||||
*/
|
||||
public function add_named_dest($anchorname)
|
||||
{
|
||||
// Not implemented
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a link to the pdf
|
||||
*
|
||||
* @param string $url The url to link to
|
||||
* @param float $x The x position of the link
|
||||
* @param float $y The y position of the link
|
||||
* @param float $width The width of the link
|
||||
* @param float $height The height of the link
|
||||
*/
|
||||
public function add_link($url, $x, $y, $width, $height)
|
||||
{
|
||||
// Not implemented
|
||||
}
|
||||
|
||||
/**
|
||||
* Add meta information to the PDF
|
||||
*
|
||||
* @param string $label label of the value (Creator, Producer, etc.)
|
||||
* @param string $value the text to set
|
||||
*/
|
||||
public function add_info($label, $value)
|
||||
public function add_info(string $label, string $value): void
|
||||
{
|
||||
// N/A
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $view
|
||||
* @param array $options
|
||||
*/
|
||||
public function set_default_view($view, $options = [])
|
||||
{
|
||||
// N/A
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculates text size, in points
|
||||
*
|
||||
* @param string $text the text to be sized
|
||||
* @param string $font the desired font
|
||||
* @param float $size the desired font size
|
||||
* @param float $word_spacing word spacing, if any
|
||||
* @param float $char_spacing char spacing, if any
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
public function get_text_width($text, $font, $size, $word_spacing = 0.0, $char_spacing = 0.0)
|
||||
{
|
||||
$font = $this->get_ttf_file($font);
|
||||
|
@ -913,13 +744,6 @@ class GD implements Canvas
|
|||
return $font;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculates font height, in points
|
||||
*
|
||||
* @param string $font
|
||||
* @param float $size
|
||||
* @return int
|
||||
*/
|
||||
public function get_font_height($font, $size)
|
||||
{
|
||||
$size = $this->_upscale($size) * self::FONT_SCALE;
|
||||
|
@ -929,6 +753,12 @@ class GD implements Canvas
|
|||
return $this->_downscale($height);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $font
|
||||
* @param float $size
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
protected function get_font_height_actual($font, $size)
|
||||
{
|
||||
$font = $this->get_ttf_file($font);
|
||||
|
@ -939,22 +769,12 @@ class GD implements Canvas
|
|||
return ($y2 - $y1) * $ratio;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $font
|
||||
* @param float $size
|
||||
* @return float
|
||||
*/
|
||||
public function get_font_baseline($font, $size)
|
||||
{
|
||||
$ratio = $this->_dompdf->getOptions()->getFontHeightRatio();
|
||||
return $this->get_font_height($font, $size) / $ratio;
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts a new page
|
||||
*
|
||||
* Subsequent drawing operations will appear on the new page.
|
||||
*/
|
||||
public function new_page()
|
||||
{
|
||||
$this->_page_number++;
|
||||
|
@ -985,7 +805,7 @@ class GD implements Canvas
|
|||
// N/A
|
||||
}
|
||||
|
||||
public function page_script($callback)
|
||||
public function page_script($callback): void
|
||||
{
|
||||
// N/A
|
||||
}
|
||||
|
@ -995,7 +815,7 @@ class GD implements Canvas
|
|||
// N/A
|
||||
}
|
||||
|
||||
public function page_line()
|
||||
public function page_line($x1, $y1, $x2, $y2, $color, $width, $style = [])
|
||||
{
|
||||
// N/A
|
||||
}
|
||||
|
@ -1004,7 +824,7 @@ class GD implements Canvas
|
|||
* Streams the image to the client.
|
||||
*
|
||||
* @param string $filename The filename to present to the client.
|
||||
* @param array $options Associative array: 'type' => jpeg|jpg|png; 'quality' => 0 - 100 (JPEG only);
|
||||
* @param array $options Associative array: 'type' => jpeg|jpg|png; 'quality' => 0 - 100 (JPEG only);
|
||||
* 'page' => Number of the page to output (defaults to the first); 'Attachment': 1 or 0 (default 1).
|
||||
*/
|
||||
public function stream($filename, $options = [])
|
|
@ -1,20 +1,17 @@
|
|||
<?php
|
||||
/**
|
||||
* @package dompdf
|
||||
* @link http://dompdf.github.com/
|
||||
* @author Benj Carson <benjcarson@digitaljunkies.ca>
|
||||
* @author Helmut Tischer <htischer@weihenstephan.org>
|
||||
* @link https://github.com/dompdf/dompdf
|
||||
* @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
|
||||
*/
|
||||
|
||||
namespace Dompdf\Adapter;
|
||||
|
||||
use Dompdf\Canvas;
|
||||
use Dompdf\Dompdf;
|
||||
use Dompdf\Helpers;
|
||||
use Dompdf\Exception;
|
||||
use Dompdf\FontMetrics;
|
||||
use Dompdf\Helpers;
|
||||
use Dompdf\Image\Cache;
|
||||
use Dompdf\PhpEvaluator;
|
||||
|
||||
/**
|
||||
* PDF rendering interface
|
||||
|
@ -37,7 +34,7 @@ class PDFLib implements Canvas
|
|||
/**
|
||||
* Dimensions of paper sizes in points
|
||||
*
|
||||
* @var array;
|
||||
* @var array
|
||||
*/
|
||||
public static $PAPER_SIZES = []; // Set to Dompdf\Adapter\CPDF::$PAPER_SIZES below.
|
||||
|
||||
|
@ -130,7 +127,7 @@ class PDFLib implements Canvas
|
|||
/**
|
||||
* The current opacity level
|
||||
*
|
||||
* @var array
|
||||
* @var float|null
|
||||
*/
|
||||
protected $_current_opacity;
|
||||
|
||||
|
@ -184,39 +181,23 @@ class PDFLib implements Canvas
|
|||
protected $_page_count;
|
||||
|
||||
/**
|
||||
* Text to display on every page
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_page_text;
|
||||
|
||||
/**
|
||||
* Array of pages for accesing after rendering is initially complete
|
||||
* Array of pages for accessing after rendering is initially complete
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_pages;
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* @param string|array $paper The size of paper to use either a string (see {@link Dompdf\Adapter\CPDF::$PAPER_SIZES}) or
|
||||
* an array(xmin,ymin,xmax,ymax)
|
||||
* @param string $orientation The orientation of the document (either 'landscape' or 'portrait')
|
||||
* @param Dompdf $dompdf
|
||||
*/
|
||||
public function __construct($paper = "letter", $orientation = "portrait", Dompdf $dompdf = null)
|
||||
public function __construct($paper = "letter", $orientation = "portrait", ?Dompdf $dompdf = null)
|
||||
{
|
||||
if (is_array($paper)) {
|
||||
$size = $paper;
|
||||
} elseif (isset(self::$PAPER_SIZES[mb_strtolower($paper)])) {
|
||||
$size = self::$PAPER_SIZES[mb_strtolower($paper)];
|
||||
$size = array_map("floatval", $paper);
|
||||
} else {
|
||||
$size = self::$PAPER_SIZES["letter"];
|
||||
$paper = strtolower($paper);
|
||||
$size = self::$PAPER_SIZES[$paper] ?? self::$PAPER_SIZES["letter"];
|
||||
}
|
||||
|
||||
if (mb_strtolower($orientation) === "landscape") {
|
||||
list($size[2], $size[3]) = [$size[3], $size[2]];
|
||||
if (strtolower($orientation) === "landscape") {
|
||||
[$size[2], $size[3]] = [$size[3], $size[2]];
|
||||
}
|
||||
|
||||
$this->_width = $size[2] - $size[0];
|
||||
|
@ -235,7 +216,9 @@ class PDFLib implements Canvas
|
|||
$this->setPDFLibParameter("license", $license);
|
||||
}
|
||||
|
||||
$this->setPDFLibParameter("textformat", "utf8");
|
||||
if ($this->getPDFLibMajorVersion() < 10) {
|
||||
$this->setPDFLibParameter("textformat", "utf8");
|
||||
}
|
||||
if ($this->getPDFLibMajorVersion() >= 7) {
|
||||
$this->setPDFLibParameter("errorpolicy", "return");
|
||||
// $this->_pdf->set_option('logging={filename=' . \APP_PATH . '/logs/pdflib.log classes={api=1 warning=2}}');
|
||||
|
@ -271,16 +254,12 @@ class PDFLib implements Canvas
|
|||
$this->_pdf->begin_page_ext($this->_width, $this->_height, "");
|
||||
|
||||
$this->_page_number = $this->_page_count = 1;
|
||||
$this->_page_text = [];
|
||||
|
||||
$this->_imgs = [];
|
||||
$this->_fonts = [];
|
||||
$this->_objs = [];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Dompdf
|
||||
*/
|
||||
function get_dompdf()
|
||||
{
|
||||
return $this->_dompdf;
|
||||
|
@ -314,13 +293,7 @@ class PDFLib implements Canvas
|
|||
return $this->_pdf;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add meta information to the PDF
|
||||
*
|
||||
* @param string $label label of the value (Creator, Producter, etc.)
|
||||
* @param string $value the text to set
|
||||
*/
|
||||
public function add_info($label, $value)
|
||||
public function add_info(string $label, string $value): void
|
||||
{
|
||||
$this->_pdf->set_info($label, $value);
|
||||
}
|
||||
|
@ -464,33 +437,21 @@ class PDFLib implements Canvas
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return float|mixed
|
||||
*/
|
||||
public function get_width()
|
||||
{
|
||||
return $this->_width;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return float|mixed
|
||||
*/
|
||||
public function get_height()
|
||||
{
|
||||
return $this->_height;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function get_page_number()
|
||||
{
|
||||
return $this->_page_number;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function get_page_count()
|
||||
{
|
||||
return $this->_page_count;
|
||||
|
@ -504,9 +465,6 @@ class PDFLib implements Canvas
|
|||
$this->_page_number = (int)$num;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $count
|
||||
*/
|
||||
public function set_page_count($count)
|
||||
{
|
||||
$this->_page_count = (int)$count;
|
||||
|
@ -516,19 +474,25 @@ class PDFLib implements Canvas
|
|||
* Sets the line style
|
||||
*
|
||||
* @param float $width
|
||||
* @param $cap
|
||||
* @param string $cap
|
||||
* @param string $join
|
||||
* @param array $dash
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function _set_line_style($width, $cap, $join, $dash)
|
||||
{
|
||||
if (!is_array($dash)) {
|
||||
$dash = array();
|
||||
$dash = [];
|
||||
}
|
||||
|
||||
if (count($dash) == 1) {
|
||||
// Work around PDFLib limitation with 0 dash length:
|
||||
// Value 0 for option 'dasharray' is too small (minimum 1.5e-05)
|
||||
foreach ($dash as &$d) {
|
||||
if ($d == 0) {
|
||||
$d = 1.5e-5;
|
||||
}
|
||||
}
|
||||
|
||||
if (count($dash) === 1) {
|
||||
$dash[] = $dash[0];
|
||||
}
|
||||
|
||||
|
@ -684,12 +648,12 @@ class PDFLib implements Canvas
|
|||
/**
|
||||
* Sets the fill opacity
|
||||
*
|
||||
* @param $opacity
|
||||
* @param $mode
|
||||
* @param float $opacity
|
||||
* @param string $mode
|
||||
*/
|
||||
public function _set_fill_opacity($opacity, $mode = "Normal")
|
||||
{
|
||||
if ($mode === "Normal" && is_null($opacity) === false) {
|
||||
if ($mode === "Normal" && isset($opacity)) {
|
||||
$this->_set_gstate("opacityfill=$opacity");
|
||||
}
|
||||
}
|
||||
|
@ -697,25 +661,19 @@ class PDFLib implements Canvas
|
|||
/**
|
||||
* Sets the stroke opacity
|
||||
*
|
||||
* @param $opacity
|
||||
* @param $mode
|
||||
* @param float $opacity
|
||||
* @param string $mode
|
||||
*/
|
||||
public function _set_stroke_opacity($opacity, $mode = "Normal")
|
||||
{
|
||||
if ($mode === "Normal" && is_null($opacity) === false) {
|
||||
if ($mode === "Normal" && isset($opacity)) {
|
||||
$this->_set_gstate("opacitystroke=$opacity");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the opacity
|
||||
*
|
||||
* @param $opacity
|
||||
* @param $mode
|
||||
*/
|
||||
public function set_opacity($opacity, $mode = "Normal")
|
||||
public function set_opacity(float $opacity, string $mode = "Normal"): void
|
||||
{
|
||||
if ($mode === "Normal" && is_null($opacity) === false) {
|
||||
if ($mode === "Normal") {
|
||||
$this->_set_gstate("opacityfill=$opacity opacitystroke=$opacity");
|
||||
$this->_current_opacity = $opacity;
|
||||
}
|
||||
|
@ -874,18 +832,9 @@ class PDFLib implements Canvas
|
|||
return $this->_height - $y;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param float $x1
|
||||
* @param float $y1
|
||||
* @param float $x2
|
||||
* @param float $y2
|
||||
* @param array $color
|
||||
* @param float $width
|
||||
* @param array $style
|
||||
*/
|
||||
public function line($x1, $y1, $x2, $y2, $color, $width, $style = null)
|
||||
public function line($x1, $y1, $x2, $y2, $color, $width, $style = [], $cap = "butt")
|
||||
{
|
||||
$this->_set_line_style($width, "butt", "", $style);
|
||||
$this->_set_line_style($width, $cap, "", $style);
|
||||
$this->_set_stroke_color($color);
|
||||
|
||||
$y1 = $this->y($y1);
|
||||
|
@ -898,62 +847,23 @@ class PDFLib implements Canvas
|
|||
$this->_set_stroke_opacity($this->_current_opacity, "Normal");
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw line at the specified coordinates on every page.
|
||||
*
|
||||
* See {@link Style::munge_color()} for the format of the colour array.
|
||||
*
|
||||
* @param float $x1
|
||||
* @param float $y1
|
||||
* @param float $x2
|
||||
* @param float $y2
|
||||
* @param array $color
|
||||
* @param float $width
|
||||
* @param array $style optional
|
||||
*/
|
||||
public function page_line($x1, $y1, $x2, $y2, $color, $width, $style = [])
|
||||
public function arc($x, $y, $r1, $r2, $astart, $aend, $color, $width, $style = [], $cap = "butt")
|
||||
{
|
||||
$_t = 'line';
|
||||
$this->_page_text[] = compact('_t', 'x1', 'y1', 'x2', 'y2', 'color', 'width', 'style');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param float $x1
|
||||
* @param float $y1
|
||||
* @param float $r1
|
||||
* @param float $r2
|
||||
* @param float $astart
|
||||
* @param float $aend
|
||||
* @param array $color
|
||||
* @param float $width
|
||||
* @param array $style
|
||||
*/
|
||||
public function arc($x1, $y1, $r1, $r2, $astart, $aend, $color, $width, $style = [])
|
||||
{
|
||||
$this->_set_line_style($width, "butt", "", $style);
|
||||
$this->_set_line_style($width, $cap, "", $style);
|
||||
$this->_set_stroke_color($color);
|
||||
|
||||
$y1 = $this->y($y1);
|
||||
$y = $this->y($y);
|
||||
|
||||
$this->_pdf->arc($x1, $y1, $r1, $astart, $aend);
|
||||
$this->_pdf->arc($x, $y, $r1, $astart, $aend);
|
||||
$this->_pdf->stroke();
|
||||
|
||||
$this->_set_stroke_opacity($this->_current_opacity, "Normal");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param float $x1
|
||||
* @param float $y1
|
||||
* @param float $w
|
||||
* @param float $h
|
||||
* @param array $color
|
||||
* @param float $width
|
||||
* @param null $style
|
||||
*/
|
||||
public function rectangle($x1, $y1, $w, $h, $color, $width, $style = null)
|
||||
public function rectangle($x1, $y1, $w, $h, $color, $width, $style = [], $cap = "butt")
|
||||
{
|
||||
$this->_set_stroke_color($color);
|
||||
$this->_set_line_style($width, "butt", "", $style);
|
||||
$this->_set_line_style($width, $cap, "", $style);
|
||||
|
||||
$y1 = $this->y($y1) - $h;
|
||||
|
||||
|
@ -963,13 +873,6 @@ class PDFLib implements Canvas
|
|||
$this->_set_stroke_opacity($this->_current_opacity, "Normal");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param float $x1
|
||||
* @param float $y1
|
||||
* @param float $w
|
||||
* @param float $h
|
||||
* @param array $color
|
||||
*/
|
||||
public function filled_rectangle($x1, $y1, $w, $h, $color)
|
||||
{
|
||||
$this->_set_fill_color($color);
|
||||
|
@ -982,12 +885,6 @@ class PDFLib implements Canvas
|
|||
$this->_set_fill_opacity($this->_current_opacity, "Normal");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param float $x1
|
||||
* @param float $y1
|
||||
* @param float $w
|
||||
* @param float $h
|
||||
*/
|
||||
public function clipping_rectangle($x1, $y1, $w, $h)
|
||||
{
|
||||
$this->_pdf->save();
|
||||
|
@ -998,16 +895,6 @@ class PDFLib implements Canvas
|
|||
$this->_pdf->clip();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param float $x1
|
||||
* @param float $y1
|
||||
* @param float $w
|
||||
* @param float $h
|
||||
* @param float $rTL
|
||||
* @param float $rTR
|
||||
* @param float $rBR
|
||||
* @param float $rBL
|
||||
*/
|
||||
public function clipping_roundrectangle($x1, $y1, $w, $h, $rTL, $rTR, $rBR, $rBL)
|
||||
{
|
||||
if ($this->getPDFLibMajorVersion() < 9) {
|
||||
|
@ -1027,33 +914,53 @@ class PDFLib implements Canvas
|
|||
// line: left edge, bottom end
|
||||
$path = $this->_pdf->add_path_point($path, 0, 0 + $rBL, "line", "");
|
||||
// curve: bottom-left corner
|
||||
$path = $this->_pdf->add_path_point($path, 0 + $rBL, 0, "elliptical", "radius=$rBL clockwise=false");
|
||||
if ($rBL > 0) {
|
||||
$path = $this->_pdf->add_path_point($path, 0 + $rBL, 0, "elliptical", "radius=$rBL clockwise=false");
|
||||
}
|
||||
// line: bottom edge, left end
|
||||
$path = $this->_pdf->add_path_point($path, 0 - $rBR + $w, 0, "line", "");
|
||||
// curve: bottom-right corner
|
||||
$path = $this->_pdf->add_path_point($path, 0 + $w, 0 + $rBR, "elliptical", "radius=$rBR clockwise=false");
|
||||
if ($rBR > 0) {
|
||||
$path = $this->_pdf->add_path_point($path, 0 + $w, 0 + $rBR, "elliptical", "radius=$rBR clockwise=false");
|
||||
}
|
||||
// line: right edge, top end
|
||||
$path = $this->_pdf->add_path_point($path, 0 + $w, 0 - $rTR + $h, "line", "");
|
||||
// curve: top-right corner
|
||||
$path = $this->_pdf->add_path_point($path, 0 - $rTR + $w, 0 +$h, "elliptical", "radius=$rTR clockwise=false");
|
||||
if ($rTR > 0) {
|
||||
$path = $this->_pdf->add_path_point($path, 0 - $rTR + $w, 0 + $h, "elliptical", "radius=$rTR clockwise=false");
|
||||
}
|
||||
// line: top edge, left end
|
||||
$path = $this->_pdf->add_path_point($path, 0 + $rTL, 0 + $h, "line", "");
|
||||
// curve: top-left corner
|
||||
$path = $this->_pdf->add_path_point($path, 0, 0 - $rTL + $h, "elliptical", "radius=$rTL clockwise=false");
|
||||
if ($rTL > 0) {
|
||||
$path = $this->_pdf->add_path_point($path, 0, 0 - $rTL + $h, "elliptical", "radius=$rTL clockwise=false");
|
||||
}
|
||||
$this->_pdf->draw_path($path, $x1, $this->_height-$y1-$h, "clip=true");
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function clipping_polygon(array $points): void
|
||||
{
|
||||
$this->_pdf->save();
|
||||
|
||||
$y = $this->y(array_pop($points));
|
||||
$x = array_pop($points);
|
||||
$this->_pdf->moveto($x, $y);
|
||||
|
||||
while (count($points) > 1) {
|
||||
$y = $this->y(array_pop($points));
|
||||
$x = array_pop($points);
|
||||
$this->_pdf->lineto($x, $y);
|
||||
}
|
||||
|
||||
$this->_pdf->closepath();
|
||||
$this->_pdf->clip();
|
||||
}
|
||||
|
||||
public function clipping_end()
|
||||
{
|
||||
$this->_pdf->restore();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function save()
|
||||
{
|
||||
$this->_pdf->save();
|
||||
|
@ -1064,11 +971,6 @@ class PDFLib implements Canvas
|
|||
$this->_pdf->restore();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $angle
|
||||
* @param $x
|
||||
* @param $y
|
||||
*/
|
||||
public function rotate($angle, $x, $y)
|
||||
{
|
||||
$pdf = $this->_pdf;
|
||||
|
@ -1077,12 +979,6 @@ class PDFLib implements Canvas
|
|||
$pdf->translate(-$x, -$this->_height + $y);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $angle_x
|
||||
* @param $angle_y
|
||||
* @param $x
|
||||
* @param $y
|
||||
*/
|
||||
public function skew($angle_x, $angle_y, $x, $y)
|
||||
{
|
||||
$pdf = $this->_pdf;
|
||||
|
@ -1091,12 +987,6 @@ class PDFLib implements Canvas
|
|||
$pdf->translate(-$x, -$this->_height + $y);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $s_x
|
||||
* @param $s_y
|
||||
* @param $x
|
||||
* @param $y
|
||||
*/
|
||||
public function scale($s_x, $s_y, $x, $y)
|
||||
{
|
||||
$pdf = $this->_pdf;
|
||||
|
@ -1105,36 +995,17 @@ class PDFLib implements Canvas
|
|||
$pdf->translate(-$x, -$this->_height + $y);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $t_x
|
||||
* @param $t_y
|
||||
*/
|
||||
public function translate($t_x, $t_y)
|
||||
{
|
||||
$this->_pdf->translate($t_x, -$t_y);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $a
|
||||
* @param $b
|
||||
* @param $c
|
||||
* @param $d
|
||||
* @param $e
|
||||
* @param $f
|
||||
*/
|
||||
public function transform($a, $b, $c, $d, $e, $f)
|
||||
{
|
||||
$this->_pdf->concat($a, $b, $c, $d, $e, $f);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $points
|
||||
* @param array $color
|
||||
* @param null $width
|
||||
* @param null $style
|
||||
* @param bool $fill
|
||||
*/
|
||||
public function polygon($points, $color, $width = null, $style = null, $fill = false)
|
||||
public function polygon($points, $color, $width = null, $style = [], $fill = false)
|
||||
{
|
||||
$this->_set_fill_color($color);
|
||||
$this->_set_stroke_color($color);
|
||||
|
@ -1163,16 +1034,7 @@ class PDFLib implements Canvas
|
|||
$this->_set_stroke_opacity($this->_current_opacity, "Normal");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param float $x
|
||||
* @param float $y
|
||||
* @param float $r
|
||||
* @param array $color
|
||||
* @param null $width
|
||||
* @param null $style
|
||||
* @param bool $fill
|
||||
*/
|
||||
public function circle($x, $y, $r, $color, $width = null, $style = null, $fill = false)
|
||||
public function circle($x, $y, $r, $color, $width = null, $style = [], $fill = false)
|
||||
{
|
||||
$this->_set_fill_color($color);
|
||||
$this->_set_stroke_color($color);
|
||||
|
@ -1195,37 +1057,34 @@ class PDFLib implements Canvas
|
|||
$this->_set_stroke_opacity($this->_current_opacity, "Normal");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $img_url
|
||||
* @param float $x
|
||||
* @param float $y
|
||||
* @param int $w
|
||||
* @param int $h
|
||||
* @param string $resolution
|
||||
*/
|
||||
public function image($img_url, $x, $y, $w, $h, $resolution = "normal")
|
||||
public function image($img, $x, $y, $w, $h, $resolution = "normal")
|
||||
{
|
||||
$w = (int)$w;
|
||||
$h = (int)$h;
|
||||
|
||||
$img_type = Cache::detect_type($img_url, $this->get_dompdf()->getHttpContext());
|
||||
$img_type = Cache::detect_type($img, $this->get_dompdf()->getHttpContext());
|
||||
|
||||
if (!isset($this->_imgs[$img_url])) {
|
||||
// Strip file:// prefix
|
||||
if (substr($img, 0, 7) === "file://") {
|
||||
$img = substr($img, 7);
|
||||
}
|
||||
|
||||
if (!isset($this->_imgs[$img])) {
|
||||
if (strtolower($img_type) === "svg") {
|
||||
//FIXME: PDFLib loads SVG but returns error message "Function must not be called in 'page' scope"
|
||||
$image_load_response = $this->_pdf->load_graphics($img_type, $img_url, "");
|
||||
$image_load_response = $this->_pdf->load_graphics($img_type, $img, "");
|
||||
} else {
|
||||
$image_load_response = $this->_pdf->load_image($img_type, $img_url, "");
|
||||
$image_load_response = $this->_pdf->load_image($img_type, $img, "");
|
||||
}
|
||||
if ($image_load_response === 0) {
|
||||
//TODO: should do something with the error message
|
||||
$error = $this->_pdf->get_errmsg();
|
||||
return;
|
||||
}
|
||||
$this->_imgs[$img_url] = $image_load_response;
|
||||
$this->_imgs[$img] = $image_load_response;
|
||||
}
|
||||
|
||||
$img = $this->_imgs[$img_url];
|
||||
$img = $this->_imgs[$img];
|
||||
|
||||
$y = $this->y($y) - $h;
|
||||
if (strtolower($img_type) === "svg") {
|
||||
|
@ -1235,19 +1094,12 @@ class PDFLib implements Canvas
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param float $x
|
||||
* @param float $y
|
||||
* @param string $text
|
||||
* @param string $font
|
||||
* @param float $size
|
||||
* @param array $color
|
||||
* @param int $word_spacing
|
||||
* @param int $char_spacing
|
||||
* @param int $angle
|
||||
*/
|
||||
public function text($x, $y, $text, $font, $size, $color = [0, 0, 0], $word_spacing = 0, $char_spacing = 0, $angle = 0)
|
||||
{
|
||||
if ($size == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
$fh = $this->_load_font($font);
|
||||
|
||||
$this->_pdf->setfont($fh, $size);
|
||||
|
@ -1264,9 +1116,6 @@ class PDFLib implements Canvas
|
|||
$this->_set_fill_opacity($this->_current_opacity, "Normal");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $code
|
||||
*/
|
||||
public function javascript($code)
|
||||
{
|
||||
if (strlen($this->_dompdf->getOptions()->getPdflibLicense()) > 0) {
|
||||
|
@ -1274,25 +1123,11 @@ class PDFLib implements Canvas
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a named destination (similar to <a name="foo">...</a> in html)
|
||||
*
|
||||
* @param string $anchorname The name of the named destination
|
||||
*/
|
||||
public function add_named_dest($anchorname)
|
||||
{
|
||||
$this->_pdf->add_nameddest($anchorname, "");
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a link to the pdf
|
||||
*
|
||||
* @param string $url The url to link to
|
||||
* @param float $x The x position of the link
|
||||
* @param float $y The y position of the link
|
||||
* @param float $width The width of the link
|
||||
* @param float $height The height of the link
|
||||
*/
|
||||
public function add_link($url, $x, $y, $width, $height)
|
||||
{
|
||||
$y = $this->y($y) - $height;
|
||||
|
@ -1304,29 +1139,21 @@ class PDFLib implements Canvas
|
|||
"contents={$url} destname=" . substr($url, 1) . " linewidth=0");
|
||||
}
|
||||
} else {
|
||||
list($proto, $host, $path, $file) = Helpers::explode_url($url);
|
||||
|
||||
if ($proto === "" || $proto === "file://") {
|
||||
return; // Local links are not allowed
|
||||
//TODO: PDFLib::create_action does not permit non-HTTP links for URI actions
|
||||
$action = $this->_pdf->create_action("URI", "url={{$url}}");
|
||||
// add the annotation only if the action was created
|
||||
if ($action !== 0) {
|
||||
$this->_pdf->create_annotation($x, $y, $x + $width, $y + $height, 'Link', "contents={{$url}} action={activate=$action} linewidth=0");
|
||||
}
|
||||
$url = Helpers::build_url($proto, $host, $path, $file);
|
||||
$url = '{' . rawurldecode($url) . '}';
|
||||
|
||||
$action = $this->_pdf->create_action("URI", "url=" . $url);
|
||||
$this->_pdf->create_annotation($x, $y, $x + $width, $y + $height, 'Link', "contents={$url} action={activate=$action} linewidth=0");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $text
|
||||
* @param string $font
|
||||
* @param float $size
|
||||
* @param float $word_spacing
|
||||
* @param float $letter_spacing
|
||||
* @return mixed
|
||||
*/
|
||||
public function get_text_width($text, $font, $size, $word_spacing = 0, $letter_spacing = 0)
|
||||
public function get_text_width($text, $font, $size, $word_spacing = 0.0, $letter_spacing = 0.0)
|
||||
{
|
||||
if ($size == 0) {
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
$fh = $this->_load_font($font);
|
||||
|
||||
// Determine the additional width due to extra spacing
|
||||
|
@ -1341,13 +1168,12 @@ class PDFLib implements Canvas
|
|||
return $this->_pdf->stringwidth($text, $fh, $size) + $delta;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $font
|
||||
* @param float $size
|
||||
* @return float
|
||||
*/
|
||||
public function get_font_height($font, $size)
|
||||
{
|
||||
if ($size == 0) {
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
$fh = $this->_load_font($font);
|
||||
|
||||
$this->_pdf->setfont($fh, $size);
|
||||
|
@ -1361,11 +1187,6 @@ class PDFLib implements Canvas
|
|||
return (abs($asc) + abs($desc)) * $ratio;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $font
|
||||
* @param float $size
|
||||
* @return float
|
||||
*/
|
||||
public function get_font_baseline($font, $size)
|
||||
{
|
||||
$ratio = $this->_dompdf->getOptions()->getFontHeightRatio();
|
||||
|
@ -1374,60 +1195,55 @@ class PDFLib implements Canvas
|
|||
}
|
||||
|
||||
/**
|
||||
* Writes text at the specified x and y coordinates on every page
|
||||
* Processes a callback or script on every page.
|
||||
*
|
||||
* The strings '{PAGE_NUM}' and '{PAGE_COUNT}' are automatically replaced
|
||||
* with their current values.
|
||||
*
|
||||
* See {@link Style::munge_color()} for the format of the color array.
|
||||
*
|
||||
* @param float $x
|
||||
* @param float $y
|
||||
* @param string $text the text to write
|
||||
* @param string $font the font file to use
|
||||
* @param float $size the font size, in points
|
||||
* @param array $color
|
||||
* @param float $word_space word spacing adjustment
|
||||
* @param float $char_space char spacing adjustment
|
||||
* @param float $angle angle to write the text at, measured CW starting from the x-axis
|
||||
*/
|
||||
public function page_text($x, $y, $text, $font, $size, $color = [0, 0, 0], $word_space = 0.0, $char_space = 0.0, $angle = 0.0)
|
||||
{
|
||||
$_t = "text";
|
||||
$this->_page_text[] = compact("_t", "x", "y", "text", "font", "size", "color", "word_space", "char_space", "angle");
|
||||
}
|
||||
|
||||
//........................................................................
|
||||
|
||||
/**
|
||||
* Processes a callback or script on every page
|
||||
*
|
||||
* The callback function receives the four parameters `$pageNumber`,
|
||||
* `$pageCount`, `$pdf`, and `$fontMetrics`, in that order. If a script is
|
||||
* passed as string, the variables `$PAGE_NUM`, `$PAGE_COUNT`, `$pdf`, and
|
||||
* `$fontMetrics` are available instead.
|
||||
* The callback function receives the four parameters `int $pageNumber`,
|
||||
* `int $pageCount`, `Canvas $canvas`, and `FontMetrics $fontMetrics`, in
|
||||
* that order. If a script is passed as string, the variables `$PAGE_NUM`,
|
||||
* `$PAGE_COUNT`, `$pdf`, and `$fontMetrics` are available instead. Passing
|
||||
* a script as string is deprecated and will be removed in a future version.
|
||||
*
|
||||
* This function can be used to add page numbers to all pages after the
|
||||
* first one, for example.
|
||||
*
|
||||
* @param callable|string $code The callback function or PHP script to process on every page
|
||||
* @param callable|string $callback The callback function or PHP script to process on every page
|
||||
*/
|
||||
public function page_script($code)
|
||||
public function page_script($callback): void
|
||||
{
|
||||
if (is_callable($code)) {
|
||||
$this->_page_text[] = [
|
||||
"_t" => "callback",
|
||||
"callback" => $code
|
||||
];
|
||||
} else {
|
||||
$_t = "script";
|
||||
$this->_page_text[] = compact("_t", "code");
|
||||
if (is_string($callback)) {
|
||||
$this->processPageScript(function (
|
||||
int $PAGE_NUM,
|
||||
int $PAGE_COUNT,
|
||||
self $pdf,
|
||||
FontMetrics $fontMetrics
|
||||
) use ($callback) {
|
||||
eval($callback);
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
$this->processPageScript($callback);
|
||||
}
|
||||
|
||||
public function page_text($x, $y, $text, $font, $size, $color = [0, 0, 0], $word_space = 0.0, $char_space = 0.0, $angle = 0.0)
|
||||
{
|
||||
$this->processPageScript(function (int $pageNumber, int $pageCount) use ($x, $y, $text, $font, $size, $color, $word_space, $char_space, $angle) {
|
||||
$text = str_replace(
|
||||
["{PAGE_NUM}", "{PAGE_COUNT}"],
|
||||
[$pageNumber, $pageCount],
|
||||
$text
|
||||
);
|
||||
$this->text($x, $y, $text, $font, $size, $color, $word_space, $char_space, $angle);
|
||||
});
|
||||
}
|
||||
|
||||
public function page_line($x1, $y1, $x2, $y2, $color, $width, $style = [])
|
||||
{
|
||||
$this->processPageScript(function () use ($x1, $y1, $x2, $y2, $color, $width, $style) {
|
||||
$this->line($x1, $y1, $x2, $y2, $color, $width, $style);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function new_page()
|
||||
{
|
||||
// Add objects to the current page
|
||||
|
@ -1438,49 +1254,15 @@ class PDFLib implements Canvas
|
|||
$this->_page_number = ++$this->_page_count;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add text to each page after rendering is complete
|
||||
*/
|
||||
protected function _add_page_text()
|
||||
protected function processPageScript(callable $callback): void
|
||||
{
|
||||
if (count($this->_page_text) === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
$eval = null;
|
||||
$this->_pdf->suspend_page("");
|
||||
|
||||
for ($p = 1; $p <= $this->_page_count; $p++) {
|
||||
$this->_pdf->resume_page("pagenumber=$p");
|
||||
|
||||
foreach ($this->_page_text as $pt) {
|
||||
extract($pt);
|
||||
|
||||
switch ($_t) {
|
||||
case "text":
|
||||
$text = str_replace(["{PAGE_NUM}", "{PAGE_COUNT}"],
|
||||
[$p, $this->_page_count], $text);
|
||||
$this->text($x, $y, $text, $font, $size, $color, $word_space, $char_space, $angle);
|
||||
break;
|
||||
|
||||
case "callback":
|
||||
$fontMetrics = $this->get_dompdf()->getFontMetrics();
|
||||
$callback($p, $this->_page_count, $this, $fontMetrics);
|
||||
break;
|
||||
|
||||
case "script":
|
||||
if (!$eval) {
|
||||
$eval = new PHPEvaluator($this);
|
||||
}
|
||||
$eval->evaluate($code, ["PAGE_NUM" => $p, "PAGE_COUNT" => $this->_page_count]);
|
||||
break;
|
||||
|
||||
case "line":
|
||||
$this->line($x1, $y1, $x2, $y2, $color, $width, $style);
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
$fontMetrics = $this->_dompdf->getFontMetrics();
|
||||
$callback($p, $this->_page_count, $this, $fontMetrics);
|
||||
|
||||
$this->_pdf->suspend_page("");
|
||||
}
|
||||
|
@ -1489,10 +1271,6 @@ class PDFLib implements Canvas
|
|||
}
|
||||
|
||||
/**
|
||||
* Streams the PDF to the client.
|
||||
*
|
||||
* @param string $filename The filename to present to the client.
|
||||
* @param array $options Associative array: 'compress' => 1 or 0 (default 1); 'Attachment' => 1 or 0 (default 1).
|
||||
* @throws Exception
|
||||
*/
|
||||
public function stream($filename = "document.pdf", $options = [])
|
||||
|
@ -1508,8 +1286,6 @@ class PDFLib implements Canvas
|
|||
$options["Attachment"] = true;
|
||||
}
|
||||
|
||||
$this->_add_page_text();
|
||||
|
||||
if ($options["compress"]) {
|
||||
$this->setPDFLibValue("compress", 6);
|
||||
} else {
|
||||
|
@ -1564,20 +1340,12 @@ class PDFLib implements Canvas
|
|||
flush();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the PDF as a string.
|
||||
*
|
||||
* @param array $options Associative array: 'compress' => 1 or 0 (default 1).
|
||||
* @return string
|
||||
*/
|
||||
public function output($options = [])
|
||||
{
|
||||
if (!isset($options["compress"])) {
|
||||
$options["compress"] = true;
|
||||
}
|
||||
|
||||
$this->_add_page_text();
|
||||
|
||||
if ($options["compress"]) {
|
||||
$this->setPDFLibValue("compress", 6);
|
||||
} else {
|
|
@ -1,12 +1,9 @@
|
|||
<?php
|
||||
/**
|
||||
* @package dompdf
|
||||
* @link http://dompdf.github.com/
|
||||
* @author Benj Carson <benjcarson@digitaljunkies.ca>
|
||||
* @author Fabien Ménager <fabien.menager@gmail.com>
|
||||
* @link https://github.com/dompdf/dompdf
|
||||
* @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
|
||||
*/
|
||||
|
||||
namespace Dompdf;
|
||||
|
||||
/**
|
||||
|
@ -24,7 +21,13 @@ namespace Dompdf;
|
|||
*/
|
||||
interface Canvas
|
||||
{
|
||||
function __construct($paper = "letter", $orientation = "portrait", Dompdf $dompdf = null);
|
||||
/**
|
||||
* @param string|float[] $paper The paper size to use as either a standard paper size (see {@link Dompdf\Adapter\CPDF::$PAPER_SIZES})
|
||||
* or an array of the form `[x1, y1, x2, y2]` (typically `[0, 0, width, height]`).
|
||||
* @param string $orientation The paper orientation, either `portrait` or `landscape`.
|
||||
* @param Dompdf $dompdf The Dompdf instance.
|
||||
*/
|
||||
public function __construct($paper = "letter", $orientation = "portrait", ?Dompdf $dompdf = null);
|
||||
|
||||
/**
|
||||
* @return Dompdf
|
||||
|
@ -39,7 +42,7 @@ interface Canvas
|
|||
function get_page_number();
|
||||
|
||||
/**
|
||||
* Returns the total number of pages
|
||||
* Returns the total number of pages in the document
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
|
@ -55,47 +58,68 @@ interface Canvas
|
|||
/**
|
||||
* Draws a line from x1,y1 to x2,y2
|
||||
*
|
||||
* See {@link Style::munge_color()} for the format of the color array.
|
||||
* See {@link Cpdf::setLineStyle()} for a description of the format of the
|
||||
* $style parameter (aka dash).
|
||||
* $style and $cap parameters (aka dash and cap).
|
||||
*
|
||||
* @param float $x1
|
||||
* @param float $y1
|
||||
* @param float $x2
|
||||
* @param float $y2
|
||||
* @param array $color
|
||||
* @param float $width
|
||||
* @param array $style
|
||||
* @param float $x1
|
||||
* @param float $y1
|
||||
* @param float $x2
|
||||
* @param float $y2
|
||||
* @param array $color Color array in the format `[r, g, b, "alpha" => alpha]`
|
||||
* where r, g, b, and alpha are float values between 0 and 1
|
||||
* @param float $width
|
||||
* @param array $style
|
||||
* @param string $cap `butt`, `round`, or `square`
|
||||
*/
|
||||
function line($x1, $y1, $x2, $y2, $color, $width, $style = null);
|
||||
function line($x1, $y1, $x2, $y2, $color, $width, $style = [], $cap = "butt");
|
||||
|
||||
/**
|
||||
* Draws an arc
|
||||
*
|
||||
* See {@link Cpdf::setLineStyle()} for a description of the format of the
|
||||
* $style and $cap parameters (aka dash and cap).
|
||||
*
|
||||
* @param float $x X coordinate of the arc
|
||||
* @param float $y Y coordinate of the arc
|
||||
* @param float $r1 Radius 1
|
||||
* @param float $r2 Radius 2
|
||||
* @param float $astart Start angle in degrees
|
||||
* @param float $aend End angle in degrees
|
||||
* @param array $color Color array in the format `[r, g, b, "alpha" => alpha]`
|
||||
* where r, g, b, and alpha are float values between 0 and 1
|
||||
* @param float $width
|
||||
* @param array $style
|
||||
* @param string $cap `butt`, `round`, or `square`
|
||||
*/
|
||||
function arc($x, $y, $r1, $r2, $astart, $aend, $color, $width, $style = [], $cap = "butt");
|
||||
|
||||
/**
|
||||
* Draws a rectangle at x1,y1 with width w and height h
|
||||
*
|
||||
* See {@link Style::munge_color()} for the format of the color array.
|
||||
* See {@link Cpdf::setLineStyle()} for a description of the $style
|
||||
* parameter (aka dash)
|
||||
* See {@link Cpdf::setLineStyle()} for a description of the format of the
|
||||
* $style and $cap parameters (aka dash and cap).
|
||||
*
|
||||
* @param float $x1
|
||||
* @param float $y1
|
||||
* @param float $w
|
||||
* @param float $h
|
||||
* @param array $color
|
||||
* @param float $width
|
||||
* @param array $style
|
||||
* @param float $x1
|
||||
* @param float $y1
|
||||
* @param float $w
|
||||
* @param float $h
|
||||
* @param array $color Color array in the format `[r, g, b, "alpha" => alpha]`
|
||||
* where r, g, b, and alpha are float values between 0 and 1
|
||||
* @param float $width
|
||||
* @param array $style
|
||||
* @param string $cap `butt`, `round`, or `square`
|
||||
*/
|
||||
function rectangle($x1, $y1, $w, $h, $color, $width, $style = null);
|
||||
function rectangle($x1, $y1, $w, $h, $color, $width, $style = [], $cap = "butt");
|
||||
|
||||
/**
|
||||
* Draws a filled rectangle at x1,y1 with width w and height h
|
||||
*
|
||||
* See {@link Style::munge_color()} for the format of the color array.
|
||||
*
|
||||
* @param float $x1
|
||||
* @param float $y1
|
||||
* @param float $w
|
||||
* @param float $h
|
||||
* @param array $color
|
||||
* @param array $color Color array in the format `[r, g, b, "alpha" => alpha]`
|
||||
* where r, g, b, and alpha are float values between 0 and 1
|
||||
*/
|
||||
function filled_rectangle($x1, $y1, $w, $h, $color);
|
||||
|
||||
|
@ -120,65 +144,67 @@ interface Canvas
|
|||
* @param float $tr
|
||||
* @param float $br
|
||||
* @param float $bl
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
function clipping_roundrectangle($x1, $y1, $w, $h, $tl, $tr, $br, $bl);
|
||||
|
||||
/**
|
||||
* Starts a clipping polygon
|
||||
*
|
||||
* @param float[] $points
|
||||
*/
|
||||
public function clipping_polygon(array $points): void;
|
||||
|
||||
/**
|
||||
* Ends the last clipping shape
|
||||
*/
|
||||
function clipping_end();
|
||||
|
||||
/**
|
||||
* Processes a callback on every page
|
||||
* Processes a callback on every page.
|
||||
*
|
||||
* The callback function receives the four parameters `$pageNumber`,
|
||||
* `$pageCount`, `$pdf`, and `$fontMetrics`, in that order.
|
||||
* The callback function receives the four parameters `int $pageNumber`,
|
||||
* `int $pageCount`, `Canvas $canvas`, and `FontMetrics $fontMetrics`, in
|
||||
* that order.
|
||||
*
|
||||
* This function can be used to add page numbers to all pages after the
|
||||
* first one, for example.
|
||||
*
|
||||
* @param callable $callback The callback function to process on every page
|
||||
* @todo Enable with next major release
|
||||
*/
|
||||
//public function page_script(callable $callback): void;
|
||||
public function page_script($callback): void;
|
||||
|
||||
/**
|
||||
* Writes text at the specified x and y coordinates on every page
|
||||
* Writes text at the specified x and y coordinates on every page.
|
||||
*
|
||||
* The strings '{PAGE_NUM}' and '{PAGE_COUNT}' are automatically replaced
|
||||
* with their current values.
|
||||
*
|
||||
* See {@link Style::munge_color()} for the format of the color array.
|
||||
*
|
||||
* @param float $x
|
||||
* @param float $y
|
||||
* @param string $text the text to write
|
||||
* @param string $font the font file to use
|
||||
* @param float $size the font size, in points
|
||||
* @param array $color
|
||||
* @param float $word_space word spacing adjustment
|
||||
* @param float $char_space char spacing adjustment
|
||||
* @param float $angle angle to write the text at, measured CW starting from the x-axis
|
||||
* @param string $text The text to write
|
||||
* @param string $font The font file to use
|
||||
* @param float $size The font size, in points
|
||||
* @param array $color Color array in the format `[r, g, b, "alpha" => alpha]`
|
||||
* where r, g, b, and alpha are float values between 0 and 1
|
||||
* @param float $word_space Word spacing adjustment
|
||||
* @param float $char_space Char spacing adjustment
|
||||
* @param float $angle Angle to write the text at, measured clockwise starting from the x-axis
|
||||
*/
|
||||
public function page_text($x, $y, $text, $font, $size, $color = [0, 0, 0], $word_space = 0.0, $char_space = 0.0, $angle = 0.0);
|
||||
|
||||
/**
|
||||
* Draw line at the specified coordinates on every page.
|
||||
*
|
||||
* See {@link Style::munge_color()} for the format of the color array.
|
||||
* Draws a line at the specified coordinates on every page.
|
||||
*
|
||||
* @param float $x1
|
||||
* @param float $y1
|
||||
* @param float $x2
|
||||
* @param float $y2
|
||||
* @param array $color
|
||||
* @param array $color Color array in the format `[r, g, b, "alpha" => alpha]`
|
||||
* where r, g, b, and alpha are float values between 0 and 1
|
||||
* @param float $width
|
||||
* @param array $style optional
|
||||
* @todo Enable with next major release
|
||||
* @param array $style
|
||||
*/
|
||||
//public function page_line($x1, $y1, $x2, $y2, $color, $width, $style = []);
|
||||
public function page_line($x1, $y1, $x2, $y2, $color, $width, $style = []);
|
||||
|
||||
/**
|
||||
* Save current state
|
||||
|
@ -204,8 +230,8 @@ interface Canvas
|
|||
*
|
||||
* @param float $angle_x
|
||||
* @param float $angle_y
|
||||
* @param float $x Origin abscissa
|
||||
* @param float $y Origin ordinate
|
||||
* @param float $x Origin abscissa
|
||||
* @param float $y Origin ordinate
|
||||
*/
|
||||
function skew($angle_x, $angle_y, $x, $y);
|
||||
|
||||
|
@ -230,13 +256,12 @@ interface Canvas
|
|||
/**
|
||||
* Transform
|
||||
*
|
||||
* @param $a
|
||||
* @param $b
|
||||
* @param $c
|
||||
* @param $d
|
||||
* @param $e
|
||||
* @param $f
|
||||
* @return
|
||||
* @param float $a
|
||||
* @param float $b
|
||||
* @param float $c
|
||||
* @param float $d
|
||||
* @param float $e
|
||||
* @param float $f
|
||||
*/
|
||||
function transform($a, $b, $c, $d, $e, $f);
|
||||
|
||||
|
@ -245,43 +270,43 @@ interface Canvas
|
|||
*
|
||||
* The polygon is formed by joining all the points stored in the $points
|
||||
* array. $points has the following structure:
|
||||
* <code>
|
||||
* ```
|
||||
* array(0 => x1,
|
||||
* 1 => y1,
|
||||
* 2 => x2,
|
||||
* 3 => y2,
|
||||
* ...
|
||||
* );
|
||||
* </code>
|
||||
* ```
|
||||
*
|
||||
* See {@link Style::munge_color()} for the format of the color array.
|
||||
* See {@link Cpdf::setLineStyle()} for a description of the $style
|
||||
* parameter (aka dash)
|
||||
* See {@link Cpdf::setLineStyle()} for a description of the format of the
|
||||
* $style parameter (aka dash).
|
||||
*
|
||||
* @param array $points
|
||||
* @param array $color
|
||||
* @param array $color Color array in the format `[r, g, b, "alpha" => alpha]`
|
||||
* where r, g, b, and alpha are float values between 0 and 1
|
||||
* @param float $width
|
||||
* @param array $style
|
||||
* @param bool $fill Fills the polygon if true
|
||||
* @param bool $fill Fills the polygon if true
|
||||
*/
|
||||
function polygon($points, $color, $width = null, $style = null, $fill = false);
|
||||
function polygon($points, $color, $width = null, $style = [], $fill = false);
|
||||
|
||||
/**
|
||||
* Draws a circle at $x,$y with radius $r
|
||||
*
|
||||
* See {@link Style::munge_color()} for the format of the color array.
|
||||
* See {@link Cpdf::setLineStyle()} for a description of the $style
|
||||
* parameter (aka dash)
|
||||
* See {@link Cpdf::setLineStyle()} for a description of the format of the
|
||||
* $style parameter (aka dash).
|
||||
*
|
||||
* @param float $x
|
||||
* @param float $y
|
||||
* @param float $r
|
||||
* @param array $color
|
||||
* @param array $color Color array in the format `[r, g, b, "alpha" => alpha]`
|
||||
* where r, g, b, and alpha are float values between 0 and 1
|
||||
* @param float $width
|
||||
* @param array $style
|
||||
* @param bool $fill Fills the circle if true
|
||||
* @param bool $fill Fills the circle if true
|
||||
*/
|
||||
function circle($x, $y, $r, $color, $width = null, $style = null, $fill = false);
|
||||
function circle($x, $y, $r, $color, $width = null, $style = [], $fill = false);
|
||||
|
||||
/**
|
||||
* Add an image to the pdf.
|
||||
|
@ -289,44 +314,28 @@ interface Canvas
|
|||
* The image is placed at the specified x and y coordinates with the
|
||||
* given width and height.
|
||||
*
|
||||
* @param string $img_url the path to the image
|
||||
* @param float $x x position
|
||||
* @param float $y y position
|
||||
* @param int $w width (in pixels)
|
||||
* @param int $h height (in pixels)
|
||||
* @param string $img The path to the image
|
||||
* @param float $x X position
|
||||
* @param float $y Y position
|
||||
* @param float $w Width
|
||||
* @param float $h Height
|
||||
* @param string $resolution The resolution of the image
|
||||
*/
|
||||
function image($img_url, $x, $y, $w, $h, $resolution = "normal");
|
||||
|
||||
/**
|
||||
* Add an arc to the PDF
|
||||
* See {@link Style::munge_color()} for the format of the color array.
|
||||
*
|
||||
* @param float $x X coordinate of the arc
|
||||
* @param float $y Y coordinate of the arc
|
||||
* @param float $r1 Radius 1
|
||||
* @param float $r2 Radius 2
|
||||
* @param float $astart Start angle in degrees
|
||||
* @param float $aend End angle in degrees
|
||||
* @param array $color Color
|
||||
* @param float $width
|
||||
* @param array $style
|
||||
*/
|
||||
function arc($x, $y, $r1, $r2, $astart, $aend, $color, $width, $style = []);
|
||||
function image($img, $x, $y, $w, $h, $resolution = "normal");
|
||||
|
||||
/**
|
||||
* Writes text at the specified x and y coordinates
|
||||
* See {@link Style::munge_color()} for the format of the color array.
|
||||
*
|
||||
* @param float $x
|
||||
* @param float $y
|
||||
* @param string $text the text to write
|
||||
* @param string $font the font file to use
|
||||
* @param float $size the font size, in points
|
||||
* @param array $color
|
||||
* @param float $word_space word spacing adjustment
|
||||
* @param float $char_space char spacing adjustment
|
||||
* @param float $angle angle
|
||||
* @param float $x
|
||||
* @param float $y
|
||||
* @param string $text The text to write
|
||||
* @param string $font The font file to use
|
||||
* @param float $size The font size, in points
|
||||
* @param array $color Color array in the format `[r, g, b, "alpha" => alpha]`
|
||||
* where r, g, b, and alpha are float values between 0 and 1
|
||||
* @param float $word_space Word spacing adjustment
|
||||
* @param float $char_space Char spacing adjustment
|
||||
* @param float $angle Angle to write the text at, measured clockwise starting from the x-axis
|
||||
*/
|
||||
function text($x, $y, $text, $font, $size, $color = [0, 0, 0], $word_space = 0.0, $char_space = 0.0, $angle = 0.0);
|
||||
|
||||
|
@ -340,30 +349,30 @@ interface Canvas
|
|||
/**
|
||||
* Add a link to the pdf
|
||||
*
|
||||
* @param string $url The url to link to
|
||||
* @param float $x The x position of the link
|
||||
* @param float $y The y position of the link
|
||||
* @param float $width The width of the link
|
||||
* @param float $height The height of the link
|
||||
* @param string $url The url to link to
|
||||
* @param float $x The x position of the link
|
||||
* @param float $y The y position of the link
|
||||
* @param float $width The width of the link
|
||||
* @param float $height The height of the link
|
||||
*/
|
||||
function add_link($url, $x, $y, $width, $height);
|
||||
|
||||
/**
|
||||
* Add meta information to the pdf
|
||||
* Add meta information to the PDF.
|
||||
*
|
||||
* @param string $name Label of the value (Creator, Producer, etc.)
|
||||
* @param string $label Label of the value (Creator, Producer, etc.)
|
||||
* @param string $value The text to set
|
||||
*/
|
||||
function add_info($name, $value);
|
||||
public function add_info(string $label, string $value): void;
|
||||
|
||||
/**
|
||||
* Calculates text size, in points
|
||||
*
|
||||
* @param string $text the text to be sized
|
||||
* @param string $font the desired font
|
||||
* @param float $size the desired font size
|
||||
* @param float $word_spacing word spacing, if any
|
||||
* @param float $char_spacing char spacing, if any
|
||||
* @param string $text The text to be sized
|
||||
* @param string $font The font file to use
|
||||
* @param float $size The font size, in points
|
||||
* @param float $word_spacing Word spacing, if any
|
||||
* @param float $char_spacing Char spacing, if any
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
|
@ -372,18 +381,28 @@ interface Canvas
|
|||
/**
|
||||
* Calculates font height, in points
|
||||
*
|
||||
* @param string $font
|
||||
* @param float $size
|
||||
* @param string $font The font file to use
|
||||
* @param float $size The font size, in points
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
function get_font_height($font, $size);
|
||||
|
||||
/**
|
||||
* Returns the font x-height, in points
|
||||
*
|
||||
* @param string $font The font file to use
|
||||
* @param float $size The font size, in points
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
//function get_font_x_height($font, $size);
|
||||
|
||||
/**
|
||||
* Calculates font baseline, in points
|
||||
*
|
||||
* @param string $font
|
||||
* @param float $size
|
||||
* @param string $font The font file to use
|
||||
* @param float $size The font size, in points
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
|
@ -396,31 +415,20 @@ interface Canvas
|
|||
*/
|
||||
function get_width();
|
||||
|
||||
|
||||
/**
|
||||
* Return the image's height in pixels
|
||||
* Returns the PDF's height in points
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
function get_height();
|
||||
|
||||
/**
|
||||
* Returns the font x-height, in points
|
||||
*
|
||||
* @param string $font
|
||||
* @param float $size
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
//function get_font_x_height($font, $size);
|
||||
|
||||
/**
|
||||
* Sets the opacity
|
||||
*
|
||||
* @param float $opacity
|
||||
* @param float $opacity
|
||||
* @param string $mode
|
||||
*/
|
||||
function set_opacity($opacity, $mode = "Normal");
|
||||
public function set_opacity(float $opacity, string $mode = "Normal"): void;
|
||||
|
||||
/**
|
||||
* Sets the default view
|
||||
|
@ -435,17 +443,13 @@ interface Canvas
|
|||
* 'FitBH' top
|
||||
* 'FitBV' left
|
||||
* @param array $options
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function set_default_view($view, $options = []);
|
||||
|
||||
/**
|
||||
* @param string $script
|
||||
*
|
||||
* @return void
|
||||
* @param string $code
|
||||
*/
|
||||
function javascript($script);
|
||||
function javascript($code);
|
||||
|
||||
/**
|
||||
* Starts a new page
|
||||
|
@ -455,10 +459,10 @@ interface Canvas
|
|||
function new_page();
|
||||
|
||||
/**
|
||||
* Streams the PDF directly to the browser.
|
||||
* Streams the PDF to the client.
|
||||
*
|
||||
* @param string $filename The filename to present to the browser.
|
||||
* @param array $options Associative array: 'compress' => 1 or 0 (default 1); 'Attachment' => 1 or 0 (default 1).
|
||||
* @param string $filename The filename to present to the client.
|
||||
* @param array $options Associative array: 'compress' => 1 or 0 (default 1); 'Attachment' => 1 or 0 (default 1).
|
||||
*/
|
||||
function stream($filename, $options = []);
|
||||
|
||||
|
@ -466,6 +470,7 @@ interface Canvas
|
|||
* Returns the PDF as a string.
|
||||
*
|
||||
* @param array $options Associative array: 'compress' => 1 or 0 (default 1).
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function output($options = []);
|
|
@ -1,8 +1,7 @@
|
|||
<?php
|
||||
/**
|
||||
* @package dompdf
|
||||
* @link http://dompdf.github.com/
|
||||
* @author Benj Carson <benjcarson@digitaljunkies.ca>
|
||||
* @link https://github.com/dompdf/dompdf
|
||||
* @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
|
||||
*/
|
||||
namespace Dompdf;
|
|
@ -1,8 +1,7 @@
|
|||
<?php
|
||||
/**
|
||||
* @package dompdf
|
||||
* @link http://dompdf.github.com/
|
||||
* @author Benj Carson <benjcarson@digitaljunkies.ca>
|
||||
* @link https://github.com/dompdf/dompdf
|
||||
* @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
|
||||
*/
|
||||
namespace Dompdf;
|
||||
|
@ -23,10 +22,8 @@ class Cellmap
|
|||
{
|
||||
/**
|
||||
* Border style weight lookup for collapsed border resolution.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected static $_BORDER_STYLE_SCORE = [
|
||||
protected const BORDER_STYLE_SCORE = [
|
||||
"double" => 8,
|
||||
"solid" => 7,
|
||||
"dashed" => 6,
|
||||
|
@ -131,10 +128,7 @@ class Cellmap
|
|||
$this->reset();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function reset()
|
||||
public function reset(): void
|
||||
{
|
||||
$this->_num_rows = 0;
|
||||
$this->_num_cols = 0;
|
||||
|
@ -153,10 +147,7 @@ class Cellmap
|
|||
$this->__col = $this->__row = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function lock_columns()
|
||||
public function lock_columns(): void
|
||||
{
|
||||
$this->_columns_locked = true;
|
||||
}
|
||||
|
@ -170,9 +161,9 @@ class Cellmap
|
|||
}
|
||||
|
||||
/**
|
||||
* @param $fixed
|
||||
* @param bool $fixed
|
||||
*/
|
||||
public function set_layout_fixed($fixed)
|
||||
public function set_layout_fixed(bool $fixed)
|
||||
{
|
||||
$this->_fixed_layout = $fixed;
|
||||
}
|
||||
|
@ -456,12 +447,12 @@ class Cellmap
|
|||
/**
|
||||
* https://www.w3.org/TR/CSS21/tables.html#border-conflict-resolution
|
||||
*
|
||||
* @param int $i
|
||||
* @param int $j
|
||||
* @param string $h_v
|
||||
* @param array $border_spec
|
||||
* @param int $i
|
||||
* @param int $j
|
||||
* @param string $h_v `horizontal` or `vertical`
|
||||
* @param array $border_spec
|
||||
*/
|
||||
protected function _resolve_border($i, $j, $h_v, $border_spec)
|
||||
protected function resolve_border(int $i, int $j, string $h_v, array $border_spec): void
|
||||
{
|
||||
if (!isset($this->_borders[$i][$j][$h_v])) {
|
||||
$this->_borders[$i][$j][$h_v] = $border_spec;
|
||||
|
@ -483,9 +474,9 @@ class Cellmap
|
|||
// width here, as its resolved width is always 0
|
||||
if ($n_style === "hidden" || $n_width > $o_width
|
||||
|| ($o_width == $n_width
|
||||
&& isset(self::$_BORDER_STYLE_SCORE[$n_style])
|
||||
&& isset(self::$_BORDER_STYLE_SCORE[$o_style])
|
||||
&& self::$_BORDER_STYLE_SCORE[$n_style] > self::$_BORDER_STYLE_SCORE[$o_style])
|
||||
&& isset(self::BORDER_STYLE_SCORE[$n_style])
|
||||
&& isset(self::BORDER_STYLE_SCORE[$o_style])
|
||||
&& self::BORDER_STYLE_SCORE[$n_style] > self::BORDER_STYLE_SCORE[$o_style])
|
||||
) {
|
||||
$this->_borders[$i][$j][$h_v] = $border_spec;
|
||||
}
|
||||
|
@ -554,7 +545,7 @@ class Cellmap
|
|||
// Recursively add the frames within the table, its row groups and rows
|
||||
if ($frame === $this->_table
|
||||
|| $display === "table-row"
|
||||
|| in_array($display, TableFrameDecorator::$ROW_GROUPS, true)
|
||||
|| in_array($display, TableFrameDecorator::ROW_GROUPS, true)
|
||||
) {
|
||||
$start_row = $this->__row;
|
||||
|
||||
|
@ -579,14 +570,14 @@ class Cellmap
|
|||
|
||||
// Resolve vertical borders
|
||||
for ($i = 0; $i < $num_rows + 1; $i++) {
|
||||
$this->_resolve_border($start_row + $i, 0, "vertical", $bp["left"]);
|
||||
$this->_resolve_border($start_row + $i, $this->_num_cols, "vertical", $bp["right"]);
|
||||
$this->resolve_border($start_row + $i, 0, "vertical", $bp["left"]);
|
||||
$this->resolve_border($start_row + $i, $this->_num_cols, "vertical", $bp["right"]);
|
||||
}
|
||||
|
||||
// Resolve horizontal borders
|
||||
for ($j = 0; $j < $this->_num_cols; $j++) {
|
||||
$this->_resolve_border($start_row, $j, "horizontal", $bp["top"]);
|
||||
$this->_resolve_border($this->__row, $j, "horizontal", $bp["bottom"]);
|
||||
$this->resolve_border($start_row, $j, "horizontal", $bp["top"]);
|
||||
$this->resolve_border($this->__row, $j, "horizontal", $bp["bottom"]);
|
||||
}
|
||||
|
||||
if ($frame === $this->_table) {
|
||||
|
@ -644,8 +635,8 @@ class Cellmap
|
|||
|
||||
if ($collapse) {
|
||||
// Resolve vertical borders
|
||||
$this->_resolve_border($row, $this->__col, "vertical", $bp["left"]);
|
||||
$this->_resolve_border($row, $this->__col + $colspan, "vertical", $bp["right"]);
|
||||
$this->resolve_border($row, $this->__col, "vertical", $bp["left"]);
|
||||
$this->resolve_border($row, $this->__col + $colspan, "vertical", $bp["right"]);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -656,8 +647,8 @@ class Cellmap
|
|||
|
||||
if ($collapse) {
|
||||
// Resolve horizontal borders
|
||||
$this->_resolve_border($this->__row, $col, "horizontal", $bp["top"]);
|
||||
$this->_resolve_border($this->__row + $rowspan, $col, "horizontal", $bp["bottom"]);
|
||||
$this->resolve_border($this->__row, $col, "horizontal", $bp["top"]);
|
||||
$this->resolve_border($this->__row + $rowspan, $col, "horizontal", $bp["bottom"]);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -684,11 +675,8 @@ class Cellmap
|
|||
} else {
|
||||
// The additional 1/2 width gets added to the table proper
|
||||
[$h, $v] = $table_style->border_spacing;
|
||||
|
||||
$v = $table_style->length_in_pt($v);
|
||||
$h = $table_style->length_in_pt($h);
|
||||
$v_spacing = is_numeric($v) ? $v / 2 : $v;
|
||||
$h_spacing = is_numeric($v) ? $h / 2 : $h;
|
||||
$v_spacing = $v / 2;
|
||||
$h_spacing = $h / 2;
|
||||
}
|
||||
|
||||
foreach ($this->_frames as $frame_info) {
|
||||
|
@ -790,12 +778,19 @@ class Cellmap
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Adjust absolute columns so that the absolute (and max) width is the
|
||||
// largest minimum width of all cells. This accounts for cells without
|
||||
// absolute width within an absolute column
|
||||
foreach ($this->_columns as &$col) {
|
||||
if ($col["absolute"] > 0) {
|
||||
$col["absolute"] = $col["min-width"];
|
||||
$col["max-width"] = $col["min-width"];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function add_row()
|
||||
protected function add_row(): void
|
||||
{
|
||||
$this->__row++;
|
||||
$this->_num_rows++;
|
||||
|
@ -899,10 +894,7 @@ class Cellmap
|
|||
$this->_frames[$g_key]["rows"] = range($first_index, $last_index);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function assign_x_positions()
|
||||
public function assign_x_positions(): void
|
||||
{
|
||||
// Pre-condition: widths must be resolved and assigned to columns and
|
||||
// column[0]["x"] must be set.
|
||||
|
@ -918,17 +910,14 @@ class Cellmap
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function assign_frame_heights()
|
||||
public function assign_frame_heights(): void
|
||||
{
|
||||
// Pre-condition: widths and heights of each column & row must be
|
||||
// calcluated
|
||||
foreach ($this->_frames as $arr) {
|
||||
$frame = $arr["frame"];
|
||||
|
||||
$h = 0;
|
||||
$h = 0.0;
|
||||
foreach ($arr["rows"] as $row) {
|
||||
if (!isset($this->_rows[$row])) {
|
||||
// The row has been removed because of a page split, so skip it.
|
||||
|
@ -941,7 +930,7 @@ class Cellmap
|
|||
if ($frame instanceof TableCellFrameDecorator) {
|
||||
$frame->set_cell_height($h);
|
||||
} else {
|
||||
$frame->get_style()->height = $h;
|
||||
$frame->get_style()->set_used("height", $h);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -949,13 +938,13 @@ class Cellmap
|
|||
/**
|
||||
* Re-adjust frame height if the table height is larger than its content
|
||||
*/
|
||||
public function set_frame_heights($table_height, $content_height)
|
||||
public function set_frame_heights(float $table_height, float $content_height): void
|
||||
{
|
||||
// Distribute the increased height proportionally amongst each row
|
||||
foreach ($this->_frames as $arr) {
|
||||
$frame = $arr["frame"];
|
||||
|
||||
$h = 0;
|
||||
$h = 0.0;
|
||||
foreach ($arr["rows"] as $row) {
|
||||
if (!isset($this->_rows[$row])) {
|
||||
continue;
|
||||
|
@ -967,13 +956,13 @@ class Cellmap
|
|||
if ($content_height > 0) {
|
||||
$new_height = ($h / $content_height) * $table_height;
|
||||
} else {
|
||||
$new_height = 0;
|
||||
$new_height = 0.0;
|
||||
}
|
||||
|
||||
if ($frame instanceof TableCellFrameDecorator) {
|
||||
$frame->set_cell_height($new_height);
|
||||
} else {
|
||||
$frame->get_style()->height = $new_height;
|
||||
$frame->get_style()->set_used("height", $new_height);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -983,7 +972,7 @@ class Cellmap
|
|||
*
|
||||
* @return string
|
||||
*/
|
||||
public function __toString()
|
||||
public function __toString(): string
|
||||
{
|
||||
$str = "";
|
||||
$str .= "Columns:<br/>";
|
|
@ -1,9 +1,7 @@
|
|||
<?php
|
||||
/**
|
||||
* @package dompdf
|
||||
* @link http://dompdf.github.com/
|
||||
* @author Benj Carson <benjcarson@digitaljunkies.ca>
|
||||
* @author Fabien Ménager <fabien.menager@gmail.com>
|
||||
* @link https://github.com/dompdf/dompdf
|
||||
* @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
|
||||
*/
|
||||
namespace Dompdf\Css;
|
|
@ -2,12 +2,9 @@
|
|||
|
||||
/**
|
||||
* @package dompdf
|
||||
* @link http://dompdf.github.com/
|
||||
* @author Benj Carson <benjcarson@digitaljunkies.ca>
|
||||
* @author Fabien Ménager <fabien.menager@gmail.com>
|
||||
* @link https://github.com/dompdf/dompdf
|
||||
* @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
|
||||
*/
|
||||
|
||||
namespace Dompdf\Css;
|
||||
|
||||
use Dompdf\Helpers;
|
||||
|
@ -165,7 +162,7 @@ class Color
|
|||
];
|
||||
|
||||
/**
|
||||
* @param $color
|
||||
* @param array|string|null $color
|
||||
* @return array|string|null
|
||||
*/
|
||||
static function parse($color)
|
||||
|
@ -261,7 +258,7 @@ class Color
|
|||
|
||||
// Parse alpha value
|
||||
if (Helpers::is_percent($alpha)) {
|
||||
$alpha = round((float) $alpha / 100, 2);
|
||||
$alpha = (float) $alpha / 100;
|
||||
} else {
|
||||
$alpha = (float) $alpha;
|
||||
}
|
||||
|
@ -294,7 +291,7 @@ class Color
|
|||
return null;
|
||||
}
|
||||
|
||||
$values = array_map(function($c) {
|
||||
$values = array_map(function ($c) {
|
||||
return min(1.0, max(0.0, floatval(trim($c))));
|
||||
}, $values);
|
||||
|
||||
|
@ -306,7 +303,7 @@ class Color
|
|||
}
|
||||
|
||||
/**
|
||||
* @param $color
|
||||
* @param array|string $color
|
||||
* @param float $alpha
|
||||
* @return array
|
||||
*/
|
File diff suppressed because it is too large
Load Diff
|
@ -1,10 +1,7 @@
|
|||
<?php
|
||||
/**
|
||||
* @package dompdf
|
||||
* @link http://dompdf.github.com/
|
||||
* @author Benj Carson <benjcarson@digitaljunkies.ca>
|
||||
* @author Helmut Tischer <htischer@weihenstephan.org>
|
||||
* @author Fabien Ménager <fabien.menager@gmail.com>
|
||||
* @link https://github.com/dompdf/dompdf
|
||||
* @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
|
||||
*/
|
||||
namespace Dompdf\Css;
|
||||
|
@ -288,19 +285,6 @@ class Stylesheet
|
|||
$this->_styles[$key][] = $style;
|
||||
}
|
||||
|
||||
/**
|
||||
* Lookup a specific Style collection
|
||||
*
|
||||
* @deprecated
|
||||
* @param string $key the selector of the requested Style collection
|
||||
*
|
||||
* @return Style[]
|
||||
*/
|
||||
function lookup(string $key): array
|
||||
{
|
||||
return $this->_styles[$key] ?? [];
|
||||
}
|
||||
|
||||
/**
|
||||
* load and parse a CSS string
|
||||
*
|
||||
|
@ -338,46 +322,26 @@ class Stylesheet
|
|||
$parsed = Helpers::parse_data_uri($file);
|
||||
$css = $parsed["data"];
|
||||
} else {
|
||||
$parsed_url = Helpers::explode_url($file);
|
||||
|
||||
[$this->_protocol, $this->_base_host, $this->_base_path, $filename] = $parsed_url;
|
||||
|
||||
$file = Helpers::build_url($this->_protocol, $this->_base_host, $this->_base_path, $filename);
|
||||
|
||||
$options = $this->_dompdf->getOptions();
|
||||
// Download the remote file
|
||||
if (!$options->isRemoteEnabled() && ($this->_protocol !== "" && $this->_protocol !== "file://")) {
|
||||
Helpers::record_warnings(E_USER_WARNING, "Remote CSS resource '$file' referenced, but remote file download is disabled.", __FILE__, __LINE__);
|
||||
return;
|
||||
}
|
||||
if ($this->_protocol === "" || $this->_protocol === "file://") {
|
||||
$realfile = realpath($file);
|
||||
|
||||
$rootDir = realpath($options->getRootDir());
|
||||
if (strpos($realfile, $rootDir) !== 0) {
|
||||
$chroot = $options->getChroot();
|
||||
$chrootValid = false;
|
||||
foreach ($chroot as $chrootPath) {
|
||||
$chrootPath = realpath($chrootPath);
|
||||
if ($chrootPath !== false && strpos($realfile, $chrootPath) === 0) {
|
||||
$chrootValid = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if ($chrootValid !== true) {
|
||||
Helpers::record_warnings(E_USER_WARNING, "Permission denied on $file. The file could not be found under the paths specified by Options::chroot.", __FILE__, __LINE__);
|
||||
$parsed_url = Helpers::explode_url($file);
|
||||
$protocol = $parsed_url["protocol"];
|
||||
|
||||
if ($file !== $this->getDefaultStylesheet()) {
|
||||
$allowed_protocols = $options->getAllowedProtocols();
|
||||
if (!array_key_exists($protocol, $allowed_protocols)) {
|
||||
Helpers::record_warnings(E_USER_WARNING, "Permission denied on $file. The communication protocol is not supported.", __FILE__, __LINE__);
|
||||
return;
|
||||
}
|
||||
foreach ($allowed_protocols[$protocol]["rules"] as $rule) {
|
||||
[$result, $message] = $rule($file);
|
||||
if (!$result) {
|
||||
Helpers::record_warnings(E_USER_WARNING, "Error loading $file: $message", __FILE__, __LINE__);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (!$realfile) {
|
||||
Helpers::record_warnings(E_USER_WARNING, "File '$realfile' not found.", __FILE__, __LINE__);
|
||||
return;
|
||||
}
|
||||
|
||||
$file = $realfile;
|
||||
}
|
||||
|
||||
|
||||
[$css, $http_response_header] = Helpers::getFileContent($file, $this->_dompdf->getHttpContext());
|
||||
|
||||
$good_mime_type = true;
|
||||
|
@ -392,11 +356,12 @@ class Stylesheet
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!$good_mime_type || $css === null) {
|
||||
Helpers::record_warnings(E_USER_WARNING, "Unable to load css file $file", __FILE__, __LINE__);
|
||||
return;
|
||||
}
|
||||
|
||||
[$this->_protocol, $this->_base_host, $this->_base_path] = $parsed_url;
|
||||
}
|
||||
|
||||
$this->_parse_css($css);
|
||||
|
@ -577,7 +542,7 @@ class Stylesheet
|
|||
// class=".* $tok .*" and class=".* $tok"
|
||||
|
||||
// This doesn't work because libxml only supports XPath 1.0...
|
||||
//$query .= "[matches(@$attr,\"^${tok}\$|^${tok}[ ]+|[ ]+${tok}\$|[ ]+${tok}[ ]+\")]";
|
||||
//$query .= "[matches(@$attr,\"^{$tok}\$|^{$tok}[ ]+|[ ]+{$tok}\$|[ ]+{$tok}[ ]+\")]";
|
||||
|
||||
$query .= "[contains(concat(' ', normalize-space(@$attr), ' '), concat(' ', '$tok', ' '))]";
|
||||
$tok = "";
|
||||
|
@ -620,7 +585,7 @@ class Stylesheet
|
|||
switch ($tok) {
|
||||
|
||||
case "first-child":
|
||||
$query .= "[1]";
|
||||
$query .= "[not(preceding-sibling::*)]";
|
||||
$tok = "";
|
||||
break;
|
||||
|
||||
|
@ -653,16 +618,17 @@ class Stylesheet
|
|||
$pseudo_classes[$tok] = true;
|
||||
$p = $i + 1;
|
||||
$nth = trim(mb_substr($selector, $p, strpos($selector, ")", $i) - $p));
|
||||
$position = $last ? "(last()-position()+1)" : "position()";
|
||||
|
||||
// 1
|
||||
if (preg_match("/^\d+$/", $nth)) {
|
||||
$condition = "position() = $nth";
|
||||
$condition = "$position = $nth";
|
||||
} // odd
|
||||
elseif ($nth === "odd") {
|
||||
$condition = "(position() mod 2) = 1";
|
||||
$condition = "($position mod 2) = 1";
|
||||
} // even
|
||||
elseif ($nth === "even") {
|
||||
$condition = "(position() mod 2) = 0";
|
||||
$condition = "($position mod 2) = 0";
|
||||
} // an+b
|
||||
else {
|
||||
$condition = $this->_selector_an_plus_b($nth, $last);
|
||||
|
@ -684,16 +650,17 @@ class Stylesheet
|
|||
$pseudo_classes[$tok] = true;
|
||||
$p = $i + 1;
|
||||
$nth = trim(mb_substr($selector, $p, strpos($selector, ")", $i) - $p));
|
||||
$position = $last ? "(last()-position()+1)" : "position()";
|
||||
|
||||
// 1
|
||||
if (preg_match("/^\d+$/", $nth)) {
|
||||
$condition = "position() = $nth";
|
||||
$condition = "$position = $nth";
|
||||
} // odd
|
||||
elseif ($nth === "odd") {
|
||||
$condition = "(position() mod 2) = 1";
|
||||
$condition = "($position mod 2) = 1";
|
||||
} // even
|
||||
elseif ($nth === "even") {
|
||||
$condition = "(position() mod 2) = 0";
|
||||
$condition = "($position mod 2) = 0";
|
||||
} // an+b
|
||||
else {
|
||||
$condition = $this->_selector_an_plus_b($nth, $last);
|
||||
|
@ -920,26 +887,27 @@ class Stylesheet
|
|||
/**
|
||||
* https://github.com/tenderlove/nokogiri/blob/master/lib/nokogiri/css/xpath_visitor.rb
|
||||
*
|
||||
* @param $expr
|
||||
* @param string $expr
|
||||
* @param bool $last
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function _selector_an_plus_b($expr, $last = false)
|
||||
protected function _selector_an_plus_b(string $expr, bool $last = false): string
|
||||
{
|
||||
$expr = preg_replace("/\s/", "", $expr);
|
||||
if (!preg_match("/^(?P<a>-?[0-9]*)?n(?P<b>[-+]?[0-9]+)?$/", $expr, $matches)) {
|
||||
return "false()";
|
||||
}
|
||||
|
||||
$a = ((isset($matches["a"]) && $matches["a"] !== "") ? intval($matches["a"]) : 1);
|
||||
$b = ((isset($matches["b"]) && $matches["b"] !== "") ? intval($matches["b"]) : 0);
|
||||
$a = (isset($matches["a"]) && $matches["a"] !== "") ? ($matches["a"] !== "-" ? intval($matches["a"]) : -1) : 1;
|
||||
$b = (isset($matches["b"]) && $matches["b"] !== "") ? intval($matches["b"]) : 0;
|
||||
|
||||
$position = ($last ? "(last()-position()+1)" : "position()");
|
||||
$position = $last ? "(last()-position()+1)" : "position()";
|
||||
|
||||
if ($b == 0) {
|
||||
return "($position mod $a) = 0";
|
||||
} else {
|
||||
$compare = (($a < 0) ? "<=" : ">=");
|
||||
$compare = ($a < 0) ? "<=" : ">=";
|
||||
$b2 = -$b;
|
||||
if ($b2 >= 0) {
|
||||
$b2 = "+$b2";
|
||||
|
@ -1006,7 +974,7 @@ class Stylesheet
|
|||
continue;
|
||||
}
|
||||
|
||||
$content = $style->get_prop("content");
|
||||
$content = $style->get_specified("content");
|
||||
|
||||
// Do not create non-displayed before/after pseudo elements
|
||||
// https://www.w3.org/TR/CSS21/generate.html#content
|
||||
|
@ -1075,7 +1043,7 @@ class Stylesheet
|
|||
// Now create the styles and assign them to the appropriate frames. (We
|
||||
// iterate over the tree using an implicit FrameTree iterator.)
|
||||
$root_flg = false;
|
||||
foreach ($tree->get_frames() as $frame) {
|
||||
foreach ($tree as $frame) {
|
||||
// Helpers::pre_r($frame->get_node()->nodeName . ":");
|
||||
if (!$root_flg && $this->_page_styles["base"]) {
|
||||
$style = $this->_page_styles["base"];
|
||||
|
@ -1330,7 +1298,7 @@ class Stylesheet
|
|||
$media_query_feature = strtolower($media_query_match[3]);
|
||||
$media_query_value = strtolower($media_query_match[2]);
|
||||
$mq[] = [$media_query_feature, $media_query_value];
|
||||
} else if (empty($media_query_match[4]) === false) {
|
||||
} elseif (empty($media_query_match[4]) === false) {
|
||||
$media_query_feature = strtolower($media_query_match[5]);
|
||||
$media_query_value = (array_key_exists(8, $media_query_match) ? strtolower($media_query_match[8]) : null);
|
||||
$mq[] = [$media_query_feature, $media_query_value];
|
||||
|
@ -1431,20 +1399,16 @@ class Stylesheet
|
|||
$val = preg_replace("/url\(\s*['\"]?([^'\")]+)['\"]?\s*\)/", "\\1", trim($val));
|
||||
|
||||
// Resolve the url now in the context of the current stylesheet
|
||||
$parsed_url = Helpers::explode_url($val);
|
||||
$path = Helpers::build_url($this->_protocol,
|
||||
$this->_base_host,
|
||||
$this->_base_path,
|
||||
$val);
|
||||
if (($parsed_url["protocol"] === "" || $parsed_url["protocol"] === "file://") && ($this->_protocol === "" || $this->_protocol === "file://")) {
|
||||
$path = realpath($path);
|
||||
// If realpath returns FALSE then specifically state that there is no background image
|
||||
if ($path === false) {
|
||||
$path = "none";
|
||||
}
|
||||
if ($path === null) {
|
||||
$path = "none";
|
||||
}
|
||||
}
|
||||
if ($DEBUGCSS) {
|
||||
$parsed_url = Helpers::explode_url($path);
|
||||
print "<pre>[_image\n";
|
||||
print_r($parsed_url);
|
||||
print $this->_protocol . "\n" . $this->_base_path . "\n" . $path . "\n";
|
||||
|
@ -1493,9 +1457,9 @@ class Stylesheet
|
|||
// Above does not work for subfolders and absolute urls.
|
||||
// Todo: As above, do we need to replace php or file to an empty protocol for local files?
|
||||
|
||||
$url = $this->resolve_url($url);
|
||||
|
||||
$this->load_css_file($url);
|
||||
if (($url = $this->resolve_url($url)) !== "none") {
|
||||
$this->load_css_file($url);
|
||||
}
|
||||
|
||||
// Restore the current base url
|
||||
$this->_protocol = $protocol;
|
||||
|
@ -1514,11 +1478,9 @@ class Stylesheet
|
|||
{
|
||||
$descriptors = $this->_parse_properties($str);
|
||||
|
||||
preg_match_all("/(url|local)\s*\([\"\']?([^\"\'\)]+)[\"\']?\)\s*(format\s*\([\"\']?([^\"\'\)]+)[\"\']?\))?/i", $descriptors->src, $src);
|
||||
preg_match_all("/(url|local)\s*\(\s*[\"\']?([^\"\'\)]+)[\"\']?\s*\)\s*(format\s*\(\s*[\"\']?([^\"\'\)]+)[\"\']?\s*\))?/i", $descriptors->src, $src);
|
||||
|
||||
$sources = [];
|
||||
$valid_sources = [];
|
||||
|
||||
foreach ($src[0] as $i => $value) {
|
||||
$source = [
|
||||
"local" => strtolower($src[1][$i]) === "local",
|
||||
|
@ -1527,11 +1489,9 @@ class Stylesheet
|
|||
"path" => Helpers::build_url($this->_protocol, $this->_base_host, $this->_base_path, $src[2][$i]),
|
||||
];
|
||||
|
||||
if (!$source["local"] && in_array($source["format"], ["", "truetype"])) {
|
||||
if (!$source["local"] && in_array($source["format"], ["", "truetype"]) && $source["path"] !== null) {
|
||||
$valid_sources[] = $source;
|
||||
}
|
||||
|
||||
$sources[] = $source;
|
||||
}
|
||||
|
||||
// No valid sources
|
||||
|
@ -1685,7 +1645,7 @@ class Stylesheet
|
|||
{
|
||||
$options = $this->_dompdf->getOptions();
|
||||
$rootDir = realpath($options->getRootDir());
|
||||
return $rootDir . self::DEFAULT_STYLESHEET;
|
||||
return Helpers::build_url("file://", "", $rootDir, $rootDir . self::DEFAULT_STYLESHEET);
|
||||
}
|
||||
|
||||
/**
|
|
@ -1,9 +1,7 @@
|
|||
<?php
|
||||
/**
|
||||
* @package dompdf
|
||||
* @link http://dompdf.github.com/
|
||||
* @author Benj Carson <benjcarson@digitaljunkies.ca>
|
||||
* @author Fabien Ménager <fabien.menager@gmail.com>
|
||||
* @link https://github.com/dompdf/dompdf
|
||||
* @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
|
||||
*/
|
||||
namespace Dompdf;
|
||||
|
@ -14,11 +12,10 @@ use Dompdf\Adapter\CPDF;
|
|||
use DOMXPath;
|
||||
use Dompdf\Frame\Factory;
|
||||
use Dompdf\Frame\FrameTree;
|
||||
use HTML5_Tokenizer;
|
||||
use HTML5_TreeBuilder;
|
||||
use Dompdf\Image\Cache;
|
||||
use Dompdf\Css\Stylesheet;
|
||||
use Dompdf\Helpers;
|
||||
use Masterminds\HTML5;
|
||||
|
||||
/**
|
||||
* Dompdf - PHP5 HTML to PDF renderer
|
||||
|
@ -197,16 +194,6 @@ class Dompdf
|
|||
*/
|
||||
private $quirksmode = false;
|
||||
|
||||
/**
|
||||
* Protocol whitelist
|
||||
*
|
||||
* Protocols and PHP wrappers allowed in URLs. Full support is not
|
||||
* guaranteed for the protocols/wrappers contained in this array.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $allowedProtocols = ["", "file://", "http://", "https://"];
|
||||
|
||||
/**
|
||||
* Local file extension whitelist
|
||||
*
|
||||
|
@ -259,7 +246,7 @@ class Dompdf
|
|||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* @param array|Options $options
|
||||
* @param Options|array|null $options
|
||||
*/
|
||||
public function __construct($options = null)
|
||||
{
|
||||
|
@ -272,8 +259,11 @@ class Dompdf
|
|||
}
|
||||
|
||||
$versionFile = realpath(__DIR__ . '/../VERSION');
|
||||
if (file_exists($versionFile) && ($version = trim(file_get_contents($versionFile))) !== false && $version !== '$Format:<%h>$') {
|
||||
$this->version = sprintf('dompdf %s', $version);
|
||||
if (($version = file_get_contents($versionFile)) !== false) {
|
||||
$version = trim($version);
|
||||
if ($version !== '$Format:<%h>$') {
|
||||
$this->version = sprintf('dompdf %s', $version);
|
||||
}
|
||||
}
|
||||
|
||||
$this->setPhpConfig();
|
||||
|
@ -281,8 +271,8 @@ class Dompdf
|
|||
$this->paperSize = $this->options->getDefaultPaperSize();
|
||||
$this->paperOrientation = $this->options->getDefaultPaperOrientation();
|
||||
|
||||
$this->setCanvas(CanvasFactory::get_instance($this, $this->paperSize, $this->paperOrientation));
|
||||
$this->setFontMetrics(new FontMetrics($this->getCanvas(), $this->getOptions()));
|
||||
$this->canvas = CanvasFactory::get_instance($this, $this->paperSize, $this->paperOrientation);
|
||||
$this->fontMetrics = new FontMetrics($this->canvas, $this->options);
|
||||
$this->css = new Stylesheet($this);
|
||||
|
||||
$this->restorePhpConfig();
|
||||
|
@ -353,43 +343,25 @@ class Dompdf
|
|||
[$this->protocol, $this->baseHost, $this->basePath] = Helpers::explode_url($file);
|
||||
}
|
||||
$protocol = strtolower($this->protocol);
|
||||
|
||||
$uri = Helpers::build_url($this->protocol, $this->baseHost, $this->basePath, $file);
|
||||
|
||||
if (!in_array($protocol, $this->allowedProtocols, true)) {
|
||||
$allowed_protocols = $this->options->getAllowedProtocols();
|
||||
if (!array_key_exists($protocol, $allowed_protocols)) {
|
||||
throw new Exception("Permission denied on $file. The communication protocol is not supported.");
|
||||
}
|
||||
|
||||
if (!$this->options->isRemoteEnabled() && ($protocol !== "" && $protocol !== "file://")) {
|
||||
throw new Exception("Remote file requested, but remote file download is disabled.");
|
||||
if ($protocol === "file://") {
|
||||
$ext = strtolower(pathinfo($uri, PATHINFO_EXTENSION));
|
||||
if (!in_array($ext, $this->allowedLocalFileExtensions)) {
|
||||
throw new Exception("Permission denied on $file: The file extension is forbidden.");
|
||||
}
|
||||
}
|
||||
|
||||
if ($protocol === "" || $protocol === "file://") {
|
||||
$realfile = realpath($uri);
|
||||
|
||||
$chroot = $this->options->getChroot();
|
||||
$chrootValid = false;
|
||||
foreach ($chroot as $chrootPath) {
|
||||
$chrootPath = realpath($chrootPath);
|
||||
if ($chrootPath !== false && strpos($realfile, $chrootPath) === 0) {
|
||||
$chrootValid = true;
|
||||
break;
|
||||
}
|
||||
foreach ($allowed_protocols[$protocol]["rules"] as $rule) {
|
||||
[$result, $message] = $rule($uri);
|
||||
if (!$result) {
|
||||
throw new Exception("Error loading $file: $message");
|
||||
}
|
||||
if ($chrootValid !== true) {
|
||||
throw new Exception("Permission denied on $file. The file could not be found under the paths specified by Options::chroot.");
|
||||
}
|
||||
|
||||
$ext = strtolower(pathinfo($realfile, PATHINFO_EXTENSION));
|
||||
if (!in_array($ext, $this->allowedLocalFileExtensions)) {
|
||||
throw new Exception("Permission denied on $file. This file extension is forbidden");
|
||||
}
|
||||
|
||||
if (!$realfile) {
|
||||
throw new Exception("File '$file' not found.");
|
||||
}
|
||||
|
||||
$uri = $realfile;
|
||||
}
|
||||
|
||||
[$contents, $http_response_header] = Helpers::getFileContent($uri, $this->options->getHttpContext());
|
||||
|
@ -498,43 +470,18 @@ class Dompdf
|
|||
|
||||
try {
|
||||
// @todo Take the quirksmode into account
|
||||
// https://quirks.spec.whatwg.org/
|
||||
// http://hsivonen.iki.fi/doctype/
|
||||
// https://developer.mozilla.org/en/mozilla's_quirks_mode
|
||||
$quirksmode = false;
|
||||
|
||||
if ($this->options->isHtml5ParserEnabled() && class_exists(HTML5_Tokenizer::class)) {
|
||||
$tokenizer = new HTML5_Tokenizer($str);
|
||||
$tokenizer->parse();
|
||||
$doc = $tokenizer->save();
|
||||
$html5 = new HTML5(['encoding' => $encoding, 'disable_html_ns' => true]);
|
||||
$dom = $html5->loadHTML($str);
|
||||
|
||||
$quirksmode = ($tokenizer->getTree()->getQuirksMode() > HTML5_TreeBuilder::NO_QUIRKS);
|
||||
} else {
|
||||
// loadHTML assumes ISO-8859-1 unless otherwise specified on the HTML document header.
|
||||
// http://devzone.zend.com/1538/php-dom-xml-extension-encoding-processing/ (see #4)
|
||||
// http://stackoverflow.com/a/11310258/264628
|
||||
$doc = new DOMDocument("1.0", $encoding);
|
||||
$doc->preserveWhiteSpace = true;
|
||||
$doc->loadHTML($str);
|
||||
$doc->encoding = $encoding;
|
||||
|
||||
// If some text is before the doctype, we are in quirksmode
|
||||
if (preg_match("/^(.+)<!doctype/i", ltrim($str), $matches)) {
|
||||
$quirksmode = true;
|
||||
} // If no doctype is provided, we are in quirksmode
|
||||
elseif (!preg_match("/^<!doctype/i", ltrim($str), $matches)) {
|
||||
$quirksmode = true;
|
||||
} else {
|
||||
// HTML5 <!DOCTYPE html>
|
||||
if (!$doc->doctype->publicId && !$doc->doctype->systemId) {
|
||||
$quirksmode = false;
|
||||
}
|
||||
|
||||
// not XHTML
|
||||
if (!preg_match("/xhtml/i", $doc->doctype->publicId)) {
|
||||
$quirksmode = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
// extra step to normalize the HTML document structure
|
||||
// see Masterminds/html5-php#166
|
||||
$doc = new DOMDocument("1.0", $encoding);
|
||||
$doc->preserveWhiteSpace = true;
|
||||
$doc->loadHTML($html5->saveHTML($dom), LIBXML_NOWARNING | LIBXML_NOERROR);
|
||||
|
||||
$this->loadDOM($doc, $quirksmode);
|
||||
} finally {
|
||||
|
@ -584,9 +531,11 @@ class Dompdf
|
|||
$acceptedmedia[] = $this->options->getDefaultMediaType();
|
||||
|
||||
// <base href="" />
|
||||
$base_nodes = $this->dom->getElementsByTagName("base");
|
||||
if ($base_nodes->length && ($href = $base_nodes->item(0)->getAttribute("href"))) {
|
||||
[$this->protocol, $this->baseHost, $this->basePath] = Helpers::explode_url($href);
|
||||
/** @var \DOMElement|null */
|
||||
$baseNode = $this->dom->getElementsByTagName("base")->item(0);
|
||||
$baseHref = $baseNode ? $baseNode->getAttribute("href") : "";
|
||||
if ($baseHref !== "") {
|
||||
[$this->protocol, $this->baseHost, $this->basePath] = Helpers::explode_url($baseHref);
|
||||
}
|
||||
|
||||
// Set the base path of the Stylesheet to that of the file being processed
|
||||
|
@ -628,7 +577,9 @@ class Dompdf
|
|||
$url = $tag->getAttribute("href");
|
||||
$url = Helpers::build_url($this->protocol, $this->baseHost, $this->basePath, $url);
|
||||
|
||||
$this->css->load_css_file($url, Stylesheet::ORIG_AUTHOR);
|
||||
if ($url !== null) {
|
||||
$this->css->load_css_file($url, Stylesheet::ORIG_AUTHOR);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
|
@ -726,9 +677,8 @@ class Dompdf
|
|||
public function render()
|
||||
{
|
||||
$this->setPhpConfig();
|
||||
$options = $this->options;
|
||||
|
||||
$logOutputFile = $options->getLogOutputFile();
|
||||
$logOutputFile = $this->options->getLogOutputFile();
|
||||
if ($logOutputFile) {
|
||||
if (!file_exists($logOutputFile) && is_writable(dirname($logOutputFile))) {
|
||||
touch($logOutputFile);
|
||||
|
@ -753,36 +703,31 @@ class Dompdf
|
|||
$pageStyle->inherit($basePageStyle);
|
||||
}
|
||||
|
||||
$defaultOptionPaperSize = $this->getPaperSize($options->getDefaultPaperSize());
|
||||
// If there is a CSS defined paper size compare to the paper size used to create the canvas to determine a
|
||||
// recreation need
|
||||
// Set paper size if defined via CSS
|
||||
if (is_array($basePageStyle->size)) {
|
||||
$basePageStyleSize = $basePageStyle->size;
|
||||
$this->setPaper([0, 0, $basePageStyleSize[0], $basePageStyleSize[1]]);
|
||||
[$width, $height] = $basePageStyle->size;
|
||||
$this->setPaper([0, 0, $width, $height]);
|
||||
}
|
||||
|
||||
$paperSize = $this->getPaperSize();
|
||||
if (
|
||||
$defaultOptionPaperSize[2] !== $paperSize[2] ||
|
||||
$defaultOptionPaperSize[3] !== $paperSize[3] ||
|
||||
$options->getDefaultPaperOrientation() !== $this->paperOrientation
|
||||
) {
|
||||
$this->setCanvas(CanvasFactory::get_instance($this, $this->paperSize, $this->paperOrientation));
|
||||
$this->fontMetrics->setCanvas($this->getCanvas());
|
||||
// Create a new canvas instance if the current one does not match the
|
||||
// desired paper size
|
||||
$canvasWidth = $this->canvas->get_width();
|
||||
$canvasHeight = $this->canvas->get_height();
|
||||
$size = $this->getPaperSize();
|
||||
|
||||
if ($canvasWidth !== $size[2] || $canvasHeight !== $size[3]) {
|
||||
$this->canvas = CanvasFactory::get_instance($this, $this->paperSize, $this->paperOrientation);
|
||||
$this->fontMetrics->setCanvas($this->canvas);
|
||||
}
|
||||
|
||||
$canvas = $this->getCanvas();
|
||||
$canvas = $this->canvas;
|
||||
|
||||
$root = null;
|
||||
|
||||
foreach ($this->tree->get_frames() as $frame) {
|
||||
// Set up the root frame
|
||||
if (is_null($root)) {
|
||||
$root = Factory::decorate_root($this->tree->get_root(), $this);
|
||||
$root_frame = $this->tree->get_root();
|
||||
$root = Factory::decorate_root($root_frame, $this);
|
||||
foreach ($this->tree as $frame) {
|
||||
if ($frame === $root_frame) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Create the appropriate decorators, reflowers & positioners.
|
||||
Factory::decorate_frame($frame, $this, $root);
|
||||
}
|
||||
|
||||
|
@ -819,6 +764,14 @@ class Dompdf
|
|||
// This is where the magic happens:
|
||||
$root->reflow();
|
||||
|
||||
if (isset($this->callbacks["end_document"])) {
|
||||
$fs = $this->callbacks["end_document"];
|
||||
|
||||
foreach ($fs as $f) {
|
||||
$canvas->page_script($f);
|
||||
}
|
||||
}
|
||||
|
||||
// Clean up cached images
|
||||
if (!$this->options->getDebugKeepTemp()) {
|
||||
Cache::clear($this->options->getDebugPng());
|
||||
|
@ -846,17 +799,6 @@ class Dompdf
|
|||
$this->restorePhpConfig();
|
||||
}
|
||||
|
||||
/**
|
||||
* Add meta information to the PDF after rendering
|
||||
*/
|
||||
public function add_info($label, $value)
|
||||
{
|
||||
$canvas = $this->getCanvas();
|
||||
if (!is_null($canvas)) {
|
||||
$canvas->add_info($label, $value);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes the output buffer in the log file
|
||||
*
|
||||
|
@ -883,6 +825,27 @@ class Dompdf
|
|||
file_put_contents($logOutputFile, $out);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add meta information to the PDF after rendering.
|
||||
*
|
||||
* @deprecated
|
||||
*/
|
||||
public function add_info($label, $value)
|
||||
{
|
||||
$this->addInfo($label, $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add meta information to the PDF after rendering.
|
||||
*
|
||||
* @param string $label Label of the value (Creator, Producer, etc.)
|
||||
* @param string $value The text to set
|
||||
*/
|
||||
public function addInfo(string $label, string $value): void
|
||||
{
|
||||
$this->canvas->add_info($label, $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Streams the PDF to the client.
|
||||
*
|
||||
|
@ -903,10 +866,7 @@ class Dompdf
|
|||
{
|
||||
$this->setPhpConfig();
|
||||
|
||||
$canvas = $this->getCanvas();
|
||||
if (!is_null($canvas)) {
|
||||
$canvas->stream($filename, $options);
|
||||
}
|
||||
$this->canvas->stream($filename, $options);
|
||||
|
||||
$this->restorePhpConfig();
|
||||
}
|
||||
|
@ -927,12 +887,7 @@ class Dompdf
|
|||
{
|
||||
$this->setPhpConfig();
|
||||
|
||||
$canvas = $this->getCanvas();
|
||||
if (is_null($canvas)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$output = $canvas->output($options);
|
||||
$output = $this->canvas->output($options);
|
||||
|
||||
$this->restorePhpConfig();
|
||||
|
||||
|
@ -1006,7 +961,7 @@ class Dompdf
|
|||
/**
|
||||
* Sets the paper size & orientation
|
||||
*
|
||||
* @param string|array $size 'letter', 'legal', 'A4', etc. {@link Dompdf\Adapter\CPDF::$PAPER_SIZES}
|
||||
* @param string|float[] $size 'letter', 'legal', 'A4', etc. {@link Dompdf\Adapter\CPDF::$PAPER_SIZES}
|
||||
* @param string $orientation 'portrait' or 'landscape'
|
||||
* @return $this
|
||||
*/
|
||||
|
@ -1020,19 +975,25 @@ class Dompdf
|
|||
/**
|
||||
* Gets the paper size
|
||||
*
|
||||
* @param null|string|array $paperSize
|
||||
* @return int[] A four-element integer array
|
||||
* @return float[] A four-element float array
|
||||
*/
|
||||
public function getPaperSize($paperSize = null)
|
||||
public function getPaperSize()
|
||||
{
|
||||
$size = $paperSize !== null ? $paperSize : $this->paperSize;
|
||||
if (is_array($size)) {
|
||||
return $size;
|
||||
} else if (isset(Adapter\CPDF::$PAPER_SIZES[mb_strtolower($size)])) {
|
||||
return Adapter\CPDF::$PAPER_SIZES[mb_strtolower($size)];
|
||||
$paper = $this->paperSize;
|
||||
$orientation = $this->paperOrientation;
|
||||
|
||||
if (is_array($paper)) {
|
||||
$size = array_map("floatval", $paper);
|
||||
} else {
|
||||
return Adapter\CPDF::$PAPER_SIZES["letter"];
|
||||
$paper = strtolower($paper);
|
||||
$size = CPDF::$PAPER_SIZES[$paper] ?? CPDF::$PAPER_SIZES["letter"];
|
||||
}
|
||||
|
||||
if (strtolower($orientation) === "landscape") {
|
||||
[$size[2], $size[3]] = [$size[3], $size[2]];
|
||||
}
|
||||
|
||||
return $size;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1265,6 +1226,11 @@ class Dompdf
|
|||
}
|
||||
|
||||
/**
|
||||
* Set a custom `Canvas` instance to render the document to.
|
||||
*
|
||||
* Be aware that the instance will be replaced on render if the document
|
||||
* defines a paper size different from the canvas.
|
||||
*
|
||||
* @param Canvas $canvas
|
||||
* @return $this
|
||||
*/
|
||||
|
@ -1361,7 +1327,7 @@ class Dompdf
|
|||
}
|
||||
|
||||
$this->options = $options;
|
||||
$fontMetrics = $this->getFontMetrics();
|
||||
$fontMetrics = $this->fontMetrics;
|
||||
if (isset($fontMetrics)) {
|
||||
$fontMetrics->setOptions($options);
|
||||
}
|
||||
|
@ -1397,15 +1363,16 @@ class Dompdf
|
|||
|
||||
/**
|
||||
* @param array $callbacks the set of callbacks to set
|
||||
* @return $this
|
||||
* @deprecated
|
||||
*/
|
||||
public function set_callbacks($callbacks)
|
||||
{
|
||||
$this->setCallbacks($callbacks);
|
||||
return $this->setCallbacks($callbacks);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets callbacks for events like rendering of pages and elements.
|
||||
* Define callbacks that allow modifying the document during render.
|
||||
*
|
||||
* The callbacks array should contain arrays with `event` set to a callback
|
||||
* event name and `f` set to a function or any other callable.
|
||||
|
@ -1416,27 +1383,31 @@ class Dompdf
|
|||
* * `end_frame`: called after frame rendering is complete
|
||||
* * `begin_page_render`: called before a page is rendered
|
||||
* * `end_page_render`: called after page rendering is complete
|
||||
* * `end_document`: called for every page after rendering is complete
|
||||
*
|
||||
* The function `f` must take an array as argument, which contains info
|
||||
* about the event (`[0 => Canvas, 1 => Frame, "canvas" => Canvas,
|
||||
* "frame" => Frame]`).
|
||||
* The function `f` receives three arguments `Frame $frame`, `Canvas $canvas`,
|
||||
* and `FontMetrics $fontMetrics` for all events but `end_document`. For
|
||||
* `end_document`, the function receives four arguments `int $pageNumber`,
|
||||
* `int $pageCount`, `Canvas $canvas`, and `FontMetrics $fontMetrics` instead.
|
||||
*
|
||||
* @param array $callbacks The set of callbacks to set
|
||||
* @param array $callbacks The set of callbacks to set.
|
||||
* @return $this
|
||||
*/
|
||||
public function setCallbacks($callbacks)
|
||||
public function setCallbacks(array $callbacks): self
|
||||
{
|
||||
if (is_array($callbacks)) {
|
||||
$this->callbacks = [];
|
||||
foreach ($callbacks as $c) {
|
||||
if (is_array($c) && isset($c["event"]) && isset($c["f"])) {
|
||||
$event = $c["event"];
|
||||
$f = $c["f"];
|
||||
if (is_string($event) && is_callable($f)) {
|
||||
$this->callbacks[$event][] = $f;
|
||||
}
|
||||
$this->callbacks = [];
|
||||
|
||||
foreach ($callbacks as $c) {
|
||||
if (is_array($c) && isset($c["event"]) && isset($c["f"])) {
|
||||
$event = $c["event"];
|
||||
$f = $c["f"];
|
||||
if (is_string($event) && is_callable($f)) {
|
||||
$this->callbacks[$event][] = $f;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
|
@ -1,11 +1,9 @@
|
|||
<?php
|
||||
/**
|
||||
* @package dompdf
|
||||
* @link http://dompdf.github.com/
|
||||
* @author Benj Carson <benjcarson@digitaljunkies.ca>
|
||||
* @link https://github.com/dompdf/dompdf
|
||||
* @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
|
||||
*/
|
||||
|
||||
namespace Dompdf;
|
||||
|
||||
/**
|
|
@ -1,8 +1,7 @@
|
|||
<?php
|
||||
/**
|
||||
* @package dompdf
|
||||
* @link http://dompdf.github.com/
|
||||
* @author Benj Carson <benjcarson@digitaljunkies.ca>
|
||||
* @link https://github.com/dompdf/dompdf
|
||||
* @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
|
||||
*/
|
||||
namespace Dompdf\Exception;
|
|
@ -1,13 +1,9 @@
|
|||
<?php
|
||||
/**
|
||||
* @package dompdf
|
||||
* @link http://dompdf.github.com/
|
||||
* @author Benj Carson <benjcarson@digitaljunkies.ca>
|
||||
* @author Helmut Tischer <htischer@weihenstephan.org>
|
||||
* @author Fabien Ménager <fabien.menager@gmail.com>
|
||||
* @link https://github.com/dompdf/dompdf
|
||||
* @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
|
||||
*/
|
||||
|
||||
namespace Dompdf;
|
||||
|
||||
use FontLib\Font;
|
||||
|
@ -25,7 +21,7 @@ use FontLib\Font;
|
|||
class FontMetrics
|
||||
{
|
||||
/**
|
||||
* Name of the font cache file
|
||||
* Name of the user font families file
|
||||
*
|
||||
* This file must be writable by the webserver process only to update it
|
||||
* with save_font_families() after adding the .afm file references of a new font family
|
||||
|
@ -33,13 +29,8 @@ class FontMetrics
|
|||
* This is typically done only from command line with load_font.php on converting
|
||||
* ttf fonts to ufm with php-font-lib.
|
||||
*/
|
||||
const CACHE_FILE = "dompdf_font_family_cache.php";
|
||||
const USER_FONTS_FILE = "installed-fonts.json";
|
||||
|
||||
/**
|
||||
* @var Canvas
|
||||
* @deprecated
|
||||
*/
|
||||
protected $pdf;
|
||||
|
||||
/**
|
||||
* Underlying {@link Canvas} object to perform text size calculations
|
||||
|
@ -49,13 +40,25 @@ class FontMetrics
|
|||
protected $canvas;
|
||||
|
||||
/**
|
||||
* Array of font family names to font files
|
||||
*
|
||||
* Usually cached by the {@link load_font.php} script
|
||||
* Array of bundled font family names to variants
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $fontLookup = [];
|
||||
protected $bundledFonts = [];
|
||||
|
||||
/**
|
||||
* Array of user defined font family names to variants
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $userFonts = [];
|
||||
|
||||
/**
|
||||
* combined list of all font families with absolute paths
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $fontFamilies;
|
||||
|
||||
/**
|
||||
* @var Options
|
||||
|
@ -84,29 +87,14 @@ class FontMetrics
|
|||
* Saves the stored font family cache
|
||||
*
|
||||
* The name and location of the cache file are determined by {@link
|
||||
* FontMetrics::CACHE_FILE}. This file should be writable by the
|
||||
* FontMetrics::USER_FONTS_FILE}. This file should be writable by the
|
||||
* webserver process.
|
||||
*
|
||||
* @see FontMetrics::loadFontFamilies()
|
||||
*/
|
||||
public function saveFontFamilies()
|
||||
{
|
||||
// replace the path to the DOMPDF font directories with the corresponding constants (allows for more portability)
|
||||
$cacheData = sprintf("<?php return function (%s, %s) {%s", '$fontDir', '$rootDir', PHP_EOL);
|
||||
$cacheData .= sprintf("return array (%s", PHP_EOL);
|
||||
foreach ($this->fontLookup as $family => $variants) {
|
||||
$cacheData .= sprintf(" '%s' => array(%s", addslashes($family), PHP_EOL);
|
||||
foreach ($variants as $variant => $path) {
|
||||
$path = sprintf("'%s'", $path);
|
||||
$path = str_replace('\'' . $this->options->getFontDir(), '$fontDir . \'', $path);
|
||||
$path = str_replace('\'' . $this->options->getRootDir(), '$rootDir . \'', $path);
|
||||
$cacheData .= sprintf(" '%s' => %s,%s", $variant, $path, PHP_EOL);
|
||||
}
|
||||
$cacheData .= sprintf(" ),%s", PHP_EOL);
|
||||
}
|
||||
$cacheData .= ");" . PHP_EOL;
|
||||
$cacheData .= "}; ?>";
|
||||
file_put_contents($this->getCacheFile(), $cacheData);
|
||||
file_put_contents($this->getUserFontsFilePath(), json_encode($this->userFonts, JSON_PRETTY_PRINT));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -124,33 +112,45 @@ class FontMetrics
|
|||
*/
|
||||
public function loadFontFamilies()
|
||||
{
|
||||
$fontDir = $this->options->getFontDir();
|
||||
$rootDir = $this->options->getRootDir();
|
||||
$file = $this->options->getRootDir() . "/lib/fonts/installed-fonts.dist.json";
|
||||
$this->bundledFonts = json_decode(file_get_contents($file), true);
|
||||
|
||||
// FIXME: temporarily define constants for cache files <= v0.6.2
|
||||
if (!defined("DOMPDF_DIR")) { define("DOMPDF_DIR", $rootDir); }
|
||||
if (!defined("DOMPDF_FONT_DIR")) { define("DOMPDF_FONT_DIR", $fontDir); }
|
||||
|
||||
$file = $rootDir . "/lib/fonts/dompdf_font_family_cache.dist.php";
|
||||
$distFontsClosure = require $file;
|
||||
$distFonts = is_array($distFontsClosure) ? $distFontsClosure : $distFontsClosure($rootDir);
|
||||
if (!is_readable($this->getCacheFile())) {
|
||||
$this->fontLookup = $distFonts;
|
||||
return;
|
||||
if (is_readable($this->getUserFontsFilePath())) {
|
||||
$this->userFonts = json_decode(file_get_contents($this->getUserFontsFilePath()), true);
|
||||
} else {
|
||||
$this->loadFontFamiliesLegacy();
|
||||
}
|
||||
}
|
||||
|
||||
$cacheDataClosure = require $this->getCacheFile();
|
||||
$cacheData = is_array($cacheDataClosure) ? $cacheDataClosure : $cacheDataClosure($fontDir, $rootDir);
|
||||
|
||||
$this->fontLookup = [];
|
||||
if (is_array($this->fontLookup)) {
|
||||
foreach ($cacheData as $key => $value) {
|
||||
$this->fontLookup[stripslashes($key)] = $value;
|
||||
private function loadFontFamiliesLegacy()
|
||||
{
|
||||
$legacyCacheFile = $this->options->getFontDir() . '/dompdf_font_family_cache.php';
|
||||
if (is_readable($legacyCacheFile)) {
|
||||
$fontDir = $this->options->getFontDir();
|
||||
$rootDir = $this->options->getRootDir();
|
||||
|
||||
if (!defined("DOMPDF_DIR")) { define("DOMPDF_DIR", $rootDir); }
|
||||
if (!defined("DOMPDF_FONT_DIR")) { define("DOMPDF_FONT_DIR", $fontDir); }
|
||||
|
||||
$cacheDataClosure = require $legacyCacheFile;
|
||||
$cacheData = is_array($cacheDataClosure) ? $cacheDataClosure : $cacheDataClosure($fontDir, $rootDir);
|
||||
if (is_array($cacheData)) {
|
||||
foreach ($cacheData as $family => $variants) {
|
||||
if (!isset($this->bundledFonts[$family]) && is_array($variants)) {
|
||||
foreach ($variants as $variant => $variantPath) {
|
||||
$variantName = basename($variantPath);
|
||||
$variantDir = dirname($variantPath);
|
||||
if ($variantDir == $fontDir) {
|
||||
$this->userFonts[$family][$variant] = $variantName;
|
||||
} else {
|
||||
$this->userFonts[$family][$variant] = $variantPath;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$this->saveFontFamilies();
|
||||
}
|
||||
}
|
||||
|
||||
// Merge provided fonts
|
||||
$this->fontLookup += $distFonts;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -183,7 +183,6 @@ class FontMetrics
|
|||
|
||||
$styleString = $this->getType("{$style['weight']} {$style['style']}");
|
||||
|
||||
$fontDir = $this->options->getFontDir();
|
||||
$remoteHash = md5($remoteFile);
|
||||
|
||||
$prefix = $fontname . "_" . $styleString;
|
||||
|
@ -199,49 +198,32 @@ class FontMetrics
|
|||
$prefix = preg_replace("[\W]", "_", $prefix);
|
||||
$prefix = preg_replace("/[^-_\w]+/", "", $prefix);
|
||||
|
||||
$localFile = $fontDir . "/" . $prefix . "_" . $remoteHash;
|
||||
$localFile = $prefix . "_" . $remoteHash;
|
||||
$localFilePath = $this->getOptions()->getFontDir() . "/" . $localFile;
|
||||
|
||||
if (isset($entry[$styleString]) && $localFile == $entry[$styleString]) {
|
||||
if (isset($entry[$styleString]) && $localFilePath == $entry[$styleString]) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$cacheEntry = $localFile;
|
||||
|
||||
$entry[$styleString] = $cacheEntry;
|
||||
$entry[$styleString] = $localFile;
|
||||
|
||||
// Download the remote file
|
||||
[$protocol] = Helpers::explode_url($remoteFile);
|
||||
if (!$this->options->isRemoteEnabled() && ($protocol !== "" && $protocol !== "file://")) {
|
||||
Helpers::record_warnings(E_USER_WARNING, "Remote font resource $remoteFile referenced, but remote file download is disabled.", __FILE__, __LINE__);
|
||||
$allowed_protocols = $this->options->getAllowedProtocols();
|
||||
if (!array_key_exists($protocol, $allowed_protocols)) {
|
||||
Helpers::record_warnings(E_USER_WARNING, "Permission denied on $remoteFile. The communication protocol is not supported.", __FILE__, __LINE__);
|
||||
return false;
|
||||
}
|
||||
if ($protocol === "" || $protocol === "file://") {
|
||||
$realfile = realpath($remoteFile);
|
||||
|
||||
$rootDir = realpath($this->options->getRootDir());
|
||||
if (strpos($realfile, $rootDir) !== 0) {
|
||||
$chroot = $this->options->getChroot();
|
||||
$chrootValid = false;
|
||||
foreach ($chroot as $chrootPath) {
|
||||
$chrootPath = realpath($chrootPath);
|
||||
if ($chrootPath !== false && strpos($realfile, $chrootPath) === 0) {
|
||||
$chrootValid = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if ($chrootValid !== true) {
|
||||
Helpers::record_warnings(E_USER_WARNING, "Permission denied on $remoteFile. The file could not be found under the paths specified by Options::chroot.", __FILE__, __LINE__);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (!$realfile) {
|
||||
Helpers::record_warnings(E_USER_WARNING, "File '$realfile' not found.", __FILE__, __LINE__);
|
||||
foreach ($allowed_protocols[$protocol]["rules"] as $rule) {
|
||||
[$result, $message] = $rule($remoteFile);
|
||||
if ($result !== true) {
|
||||
Helpers::record_warnings(E_USER_WARNING, "Error loading $remoteFile: $message", __FILE__, __LINE__);
|
||||
return false;
|
||||
}
|
||||
|
||||
$remoteFile = $realfile;
|
||||
}
|
||||
|
||||
list($remoteFileContent, $http_response_header) = @Helpers::getFileContent($remoteFile, $context);
|
||||
if ($remoteFileContent === null) {
|
||||
return false;
|
||||
|
@ -257,33 +239,33 @@ class FontMetrics
|
|||
return false;
|
||||
}
|
||||
|
||||
switch ($font->getFontType()) {
|
||||
case "TrueType":
|
||||
default:
|
||||
$localFile .= ".ttf";
|
||||
break;
|
||||
}
|
||||
|
||||
$font->parse();
|
||||
$font->saveAdobeFontMetrics("$cacheEntry.ufm");
|
||||
$font->saveAdobeFontMetrics("$localFilePath.ufm");
|
||||
$font->close();
|
||||
|
||||
unlink($localTempFile);
|
||||
|
||||
if ( !file_exists("$cacheEntry.ufm") ) {
|
||||
if ( !file_exists("$localFilePath.ufm") ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Save the changes
|
||||
file_put_contents($localFile, $remoteFileContent);
|
||||
$fontExtension = ".ttf";
|
||||
switch ($font->getFontType()) {
|
||||
case "TrueType":
|
||||
default:
|
||||
$fontExtension = ".ttf";
|
||||
break;
|
||||
}
|
||||
|
||||
if ( !file_exists($localFile) ) {
|
||||
unlink("$cacheEntry.ufm");
|
||||
// Save the changes
|
||||
file_put_contents($localFilePath.$fontExtension, $remoteFileContent);
|
||||
|
||||
if ( !file_exists($localFilePath.$fontExtension) ) {
|
||||
unlink("$localFilePath.ufm");
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->setFontFamily($fontname, $entry);
|
||||
$this->saveFontFamilies();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -306,16 +288,15 @@ class FontMetrics
|
|||
/**
|
||||
* Calculates text size, in points
|
||||
*
|
||||
* @param string $text the text to be sized
|
||||
* @param string $font the desired font
|
||||
* @param float $size the desired font size
|
||||
* @param float $wordSpacing
|
||||
* @param float $charSpacing
|
||||
* @param string $text The text to be sized
|
||||
* @param string $font The font file to use
|
||||
* @param float $size The font size, in points
|
||||
* @param float $wordSpacing Word spacing, if any
|
||||
* @param float $charSpacing Char spacing, if any
|
||||
*
|
||||
* @internal param float $spacing word spacing, if any
|
||||
* @return float
|
||||
*/
|
||||
public function getTextWidth($text, $font, $size, $wordSpacing = 0.0, $charSpacing = 0.0)
|
||||
public function getTextWidth(string $text, $font, float $size, float $wordSpacing = 0.0, float $charSpacing = 0.0): float
|
||||
{
|
||||
// @todo Make sure this cache is efficient before enabling it
|
||||
static $cache = [];
|
||||
|
@ -359,12 +340,12 @@ class FontMetrics
|
|||
/**
|
||||
* Calculates font height, in points
|
||||
*
|
||||
* @param string $font
|
||||
* @param float $size
|
||||
* @param string $font The font file to use
|
||||
* @param float $size The font size, in points
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
public function getFontHeight($font, $size)
|
||||
public function getFontHeight($font, float $size): float
|
||||
{
|
||||
return $this->canvas->get_font_height($font, $size);
|
||||
}
|
||||
|
@ -372,12 +353,12 @@ class FontMetrics
|
|||
/**
|
||||
* Calculates font baseline, in points
|
||||
*
|
||||
* @param string $font
|
||||
* @param float $size
|
||||
* @param string $font The font file to use
|
||||
* @param float $size The font size, in points
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
public function getFontBaseline($font, $size)
|
||||
public function getFontBaseline($font, float $size): float
|
||||
{
|
||||
return $this->canvas->get_font_baseline($font, $size);
|
||||
}
|
||||
|
@ -400,10 +381,10 @@ class FontMetrics
|
|||
* ({@link Options::defaultFont}) is used. The font file returned
|
||||
* is the absolute pathname to the font file on the system.
|
||||
*
|
||||
* @param string $familyRaw
|
||||
* @param string $subtypeRaw
|
||||
* @param string|null $familyRaw
|
||||
* @param string $subtypeRaw
|
||||
*
|
||||
* @return string
|
||||
* @return string|null
|
||||
*/
|
||||
public function getFont($familyRaw, $subtypeRaw = "normal")
|
||||
{
|
||||
|
@ -423,11 +404,12 @@ class FontMetrics
|
|||
|
||||
$subtype = strtolower($subtypeRaw);
|
||||
|
||||
$families = $this->getFontFamilies();
|
||||
if ($familyRaw) {
|
||||
$family = str_replace(["'", '"'], "", strtolower($familyRaw));
|
||||
|
||||
if (isset($this->fontLookup[$family][$subtype])) {
|
||||
return $cache[$familyRaw][$subtypeRaw] = $this->fontLookup[$family][$subtype];
|
||||
if (isset($families[$family][$subtype])) {
|
||||
return $cache[$familyRaw][$subtypeRaw] = $families[$family][$subtype];
|
||||
}
|
||||
|
||||
return null;
|
||||
|
@ -435,15 +417,15 @@ class FontMetrics
|
|||
|
||||
$fallback_families = [strtolower($this->options->getDefaultFont()), "serif"];
|
||||
foreach ($fallback_families as $family) {
|
||||
if (isset($this->fontLookup[$family][$subtype])) {
|
||||
return $cache[$familyRaw][$subtypeRaw] = $this->fontLookup[$family][$subtype];
|
||||
if (isset($families[$family][$subtype])) {
|
||||
return $cache[$familyRaw][$subtypeRaw] = $families[$family][$subtype];
|
||||
}
|
||||
|
||||
if (!isset($this->fontLookup[$family])) {
|
||||
if (!isset($families[$family])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$family = $this->fontLookup[$family];
|
||||
$family = $families[$family];
|
||||
|
||||
foreach ($family as $sub => $font) {
|
||||
if (strpos($subtype, $sub) !== false) {
|
||||
|
@ -486,9 +468,10 @@ class FontMetrics
|
|||
public function getFamily($family)
|
||||
{
|
||||
$family = str_replace(["'", '"'], "", mb_strtolower($family));
|
||||
$families = $this->getFontFamilies();
|
||||
|
||||
if (isset($this->fontLookup[$family])) {
|
||||
return $this->fontLookup[$family];
|
||||
if (isset($families[$family])) {
|
||||
return $families[$family];
|
||||
}
|
||||
|
||||
return null;
|
||||
|
@ -547,7 +530,41 @@ class FontMetrics
|
|||
*/
|
||||
public function getFontFamilies()
|
||||
{
|
||||
return $this->fontLookup;
|
||||
if (!isset($this->fontFamilies)) {
|
||||
$this->setFontFamilies();
|
||||
}
|
||||
return $this->fontFamilies;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert loaded fonts to font lookup table
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function setFontFamilies()
|
||||
{
|
||||
$fontFamilies = [];
|
||||
if (isset($this->bundledFonts) && is_array($this->bundledFonts)) {
|
||||
foreach ($this->bundledFonts as $family => $variants) {
|
||||
if (!isset($fontFamilies[$family])) {
|
||||
$fontFamilies[$family] = array_map(function ($variant) {
|
||||
return $this->getOptions()->getRootDir() . '/lib/fonts/' . $variant;
|
||||
}, $variants);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (isset($this->userFonts) && is_array($this->userFonts)) {
|
||||
foreach ($this->userFonts as $family => $variants) {
|
||||
$fontFamilies[$family] = array_map(function ($variant) {
|
||||
$variantName = basename($variant);
|
||||
if ($variantName === $variant) {
|
||||
return $this->getOptions()->getFontDir() . '/' . $variant;
|
||||
}
|
||||
return $variant;
|
||||
}, $variants);
|
||||
}
|
||||
}
|
||||
$this->fontFamilies = $fontFamilies;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -566,15 +583,17 @@ class FontMetrics
|
|||
*/
|
||||
public function setFontFamily($fontname, $entry)
|
||||
{
|
||||
$this->fontLookup[mb_strtolower($fontname)] = $entry;
|
||||
$this->userFonts[mb_strtolower($fontname)] = $entry;
|
||||
$this->saveFontFamilies();
|
||||
unset($this->fontFamilies);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getCacheFile()
|
||||
public function getUserFontsFilePath()
|
||||
{
|
||||
return $this->options->getFontDir() . '/' . self::CACHE_FILE;
|
||||
return $this->options->getFontDir() . '/' . self::USER_FONTS_FILE;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -584,6 +603,7 @@ class FontMetrics
|
|||
public function setOptions(Options $options)
|
||||
{
|
||||
$this->options = $options;
|
||||
unset($this->fontFamilies);
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
@ -602,8 +622,6 @@ class FontMetrics
|
|||
public function setCanvas(Canvas $canvas)
|
||||
{
|
||||
$this->canvas = $canvas;
|
||||
// Still write deprecated pdf for now. It might be used by a parent class.
|
||||
$this->pdf = $canvas;
|
||||
return $this;
|
||||
}
|
||||
|
|
@ -1,16 +1,13 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @package dompdf
|
||||
* @link https://github.com/dompdf/dompdf
|
||||
* @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
|
||||
*/
|
||||
namespace Dompdf;
|
||||
|
||||
use Dompdf\Css\Style;
|
||||
use Dompdf\Frame\FrameList;
|
||||
|
||||
/**
|
||||
* @package dompdf
|
||||
* @link http://dompdf.github.com/
|
||||
* @author Benj Carson <benjcarson@digitaljunkies.ca>
|
||||
* @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
|
||||
*/
|
||||
use Dompdf\Frame\FrameListIterator;
|
||||
|
||||
/**
|
||||
* The main Frame class
|
||||
|
@ -57,14 +54,6 @@ class Frame
|
|||
*/
|
||||
protected $_style;
|
||||
|
||||
/**
|
||||
* This frame's original style. Needed for cases where frames are
|
||||
* split across pages.
|
||||
*
|
||||
* @var Style
|
||||
*/
|
||||
protected $_original_style;
|
||||
|
||||
/**
|
||||
* This frame's parent in the document tree.
|
||||
*
|
||||
|
@ -72,13 +61,6 @@ class Frame
|
|||
*/
|
||||
protected $_parent;
|
||||
|
||||
/**
|
||||
* This frame's children
|
||||
*
|
||||
* @var Frame[]
|
||||
*/
|
||||
protected $_frame_list;
|
||||
|
||||
/**
|
||||
* This frame's first child. All children are handled as a
|
||||
* doubly-linked list.
|
||||
|
@ -133,7 +115,7 @@ class Frame
|
|||
/**
|
||||
* This frame's decorator
|
||||
*
|
||||
* @var \Dompdf\FrameDecorator\AbstractFrameDecorator
|
||||
* @var FrameDecorator\AbstractFrameDecorator
|
||||
*/
|
||||
protected $_decorator;
|
||||
|
||||
|
@ -161,13 +143,6 @@ class Frame
|
|||
*/
|
||||
public $_float_next_line = false;
|
||||
|
||||
/**
|
||||
* Whether the frame is a split-off frame
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $_splitted;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
|
@ -188,7 +163,6 @@ class Frame
|
|||
$this->_prev_sibling = $this->_next_sibling = null;
|
||||
|
||||
$this->_style = null;
|
||||
$this->_original_style = null;
|
||||
|
||||
$this->_containing_block = [
|
||||
"x" => null,
|
||||
|
@ -301,13 +275,8 @@ class Frame
|
|||
$this->_parent->get_node()->removeChild($this->_node);
|
||||
}
|
||||
|
||||
$this->_style->dispose();
|
||||
$this->_style = null;
|
||||
unset($this->_style);
|
||||
|
||||
$this->_original_style->dispose();
|
||||
$this->_original_style = null;
|
||||
unset($this->_original_style);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -323,9 +292,7 @@ class Frame
|
|||
$this->_containing_block["w"] = null;
|
||||
$this->_containing_block["h"] = null;
|
||||
|
||||
$this->_style = null;
|
||||
unset($this->_style);
|
||||
$this->_style = clone $this->_original_style;
|
||||
$this->_style->reset();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -353,11 +320,12 @@ class Frame
|
|||
}
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
* @return Style
|
||||
*/
|
||||
public function get_original_style()
|
||||
{
|
||||
return $this->_original_style;
|
||||
return $this->_style;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -369,7 +337,7 @@ class Frame
|
|||
}
|
||||
|
||||
/**
|
||||
* @return \Dompdf\FrameDecorator\AbstractFrameDecorator
|
||||
* @return FrameDecorator\AbstractFrameDecorator
|
||||
*/
|
||||
public function get_decorator()
|
||||
{
|
||||
|
@ -409,17 +377,11 @@ class Frame
|
|||
}
|
||||
|
||||
/**
|
||||
* @return FrameList|Frame[]
|
||||
* @return FrameListIterator
|
||||
*/
|
||||
public function get_children()
|
||||
public function get_children(): FrameListIterator
|
||||
{
|
||||
if (isset($this->_frame_list)) {
|
||||
return $this->_frame_list;
|
||||
}
|
||||
|
||||
$this->_frame_list = new FrameList($this);
|
||||
|
||||
return $this->_frame_list;
|
||||
return new FrameListIterator($this);
|
||||
}
|
||||
|
||||
// Layout property accessors
|
||||
|
@ -650,11 +612,11 @@ class Frame
|
|||
}
|
||||
|
||||
/**
|
||||
* @param null $opacity
|
||||
* @param float|null $opacity
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
public function get_opacity($opacity = null)
|
||||
public function get_opacity(?float $opacity = null): float
|
||||
{
|
||||
if ($opacity !== null) {
|
||||
$this->set_opacity($opacity);
|
||||
|
@ -692,18 +654,14 @@ class Frame
|
|||
/**
|
||||
* @param Style $style
|
||||
*/
|
||||
public function set_style(Style $style)
|
||||
public function set_style(Style $style): void
|
||||
{
|
||||
if (is_null($this->_style)) {
|
||||
$this->_original_style = clone $style;
|
||||
}
|
||||
|
||||
//$style->set_frame($this);
|
||||
// $style->set_frame($this);
|
||||
$this->_style = $style;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Dompdf\FrameDecorator\AbstractFrameDecorator $decorator
|
||||
* @param FrameDecorator\AbstractFrameDecorator $decorator
|
||||
*/
|
||||
public function set_decorator(FrameDecorator\AbstractFrameDecorator $decorator)
|
||||
{
|
||||
|
@ -761,12 +719,12 @@ class Frame
|
|||
}
|
||||
|
||||
/**
|
||||
* @param $opacity
|
||||
* @param float $opacity
|
||||
*/
|
||||
public function set_opacity($opacity)
|
||||
public function set_opacity(float $opacity): void
|
||||
{
|
||||
$parent = $this->get_parent();
|
||||
$base_opacity = (($parent && $parent->_opacity !== null) ? $parent->_opacity : 1.0);
|
||||
$base_opacity = $parent && $parent->_opacity !== null ? $parent->_opacity : 1.0;
|
||||
$this->_opacity = $base_opacity * $opacity;
|
||||
}
|
||||
|
||||
|
@ -833,7 +791,7 @@ class Frame
|
|||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function is_text_node()
|
||||
public function is_text_node(): bool
|
||||
{
|
||||
if (isset($this->_is_cache["text_node"])) {
|
||||
return $this->_is_cache["text_node"];
|
||||
|
@ -845,21 +803,21 @@ class Frame
|
|||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function is_positionned()
|
||||
public function is_positioned(): bool
|
||||
{
|
||||
if (isset($this->_is_cache["positionned"])) {
|
||||
return $this->_is_cache["positionned"];
|
||||
if (isset($this->_is_cache["positioned"])) {
|
||||
return $this->_is_cache["positioned"];
|
||||
}
|
||||
|
||||
$position = $this->get_style()->position;
|
||||
|
||||
return $this->_is_cache["positionned"] = in_array($position, Style::$POSITIONNED_TYPES, true);
|
||||
return $this->_is_cache["positioned"] = in_array($position, Style::POSITIONED_TYPES, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function is_absolute()
|
||||
public function is_absolute(): bool
|
||||
{
|
||||
if (isset($this->_is_cache["absolute"])) {
|
||||
return $this->_is_cache["absolute"];
|
||||
|
@ -873,13 +831,13 @@ class Frame
|
|||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function is_block()
|
||||
public function is_block(): bool
|
||||
{
|
||||
if (isset($this->_is_cache["block"])) {
|
||||
return $this->_is_cache["block"];
|
||||
}
|
||||
|
||||
return $this->_is_cache["block"] = in_array($this->get_style()->display, Style::$BLOCK_TYPES, true);
|
||||
return $this->_is_cache["block"] = in_array($this->get_style()->display, Style::BLOCK_TYPES, true);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -915,22 +873,9 @@ class Frame
|
|||
}
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
* @return bool
|
||||
*/
|
||||
public function is_inline_block()
|
||||
{
|
||||
if (isset($this->_is_cache["inline_block"])) {
|
||||
return $this->_is_cache["inline_block"];
|
||||
}
|
||||
|
||||
return $this->_is_cache["inline_block"] = ($this->get_style()->display === "inline-block");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function is_in_flow()
|
||||
public function is_in_flow(): bool
|
||||
{
|
||||
if (isset($this->_is_cache["in_flow"])) {
|
||||
return $this->_is_cache["in_flow"];
|
||||
|
@ -942,7 +887,7 @@ class Frame
|
|||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function is_pre()
|
||||
public function is_pre(): bool
|
||||
{
|
||||
if (isset($this->_is_cache["pre"])) {
|
||||
return $this->_is_cache["pre"];
|
||||
|
@ -956,7 +901,7 @@ class Frame
|
|||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function is_table()
|
||||
public function is_table(): bool
|
||||
{
|
||||
if (isset($this->_is_cache["table"])) {
|
||||
return $this->_is_cache["table"];
|
||||
|
@ -964,7 +909,7 @@ class Frame
|
|||
|
||||
$display = $this->get_style()->display;
|
||||
|
||||
return $this->_is_cache["table"] = in_array($display, Style::$TABLE_TYPES, true);
|
||||
return $this->_is_cache["table"] = in_array($display, Style::TABLE_TYPES, true);
|
||||
}
|
||||
|
||||
|
|
@ -1,8 +1,7 @@
|
|||
<?php
|
||||
/**
|
||||
* @package dompdf
|
||||
* @link http://dompdf.github.com/
|
||||
* @author Benj Carson <benjcarson@digitaljunkies.ca>
|
||||
* @link https://github.com/dompdf/dompdf
|
||||
* @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
|
||||
*/
|
||||
namespace Dompdf\Frame;
|
||||
|
@ -24,7 +23,6 @@ use Dompdf\Positioner\AbstractPositioner;
|
|||
* objects. This is determined primarily by the Frame's display type, but
|
||||
* also by the Frame's node's type (e.g. DomElement vs. #text)
|
||||
*
|
||||
* @access private
|
||||
* @package dompdf
|
||||
*/
|
||||
class Factory
|
||||
|
@ -190,7 +188,7 @@ class Factory
|
|||
|
||||
// Handle nodeName
|
||||
if ($node->nodeName === "img") {
|
||||
$style->display = "-dompdf-image";
|
||||
$style->set_prop("display", "-dompdf-image");
|
||||
$decorator = "Image";
|
||||
$reflower = "Image";
|
||||
}
|
||||
|
@ -216,8 +214,7 @@ class Factory
|
|||
|
||||
$node = $frame->get_node();
|
||||
$parent_node = $node->parentNode;
|
||||
|
||||
if ($parent_node) {
|
||||
if ($parent_node && $parent_node instanceof \DOMElement) {
|
||||
if (!$parent_node->hasAttribute("dompdf-children-count")) {
|
||||
$xpath = new DOMXPath($xml);
|
||||
$count = $xpath->query("li", $parent_node)->length;
|
||||
|
@ -239,7 +236,7 @@ class Factory
|
|||
}
|
||||
|
||||
$new_style = $dompdf->getCss()->create_style();
|
||||
$new_style->display = "-dompdf-list-bullet";
|
||||
$new_style->set_prop("display", "-dompdf-list-bullet");
|
||||
$new_style->inherit($style);
|
||||
$b_f->set_style($new_style);
|
||||
|
|
@ -1,4 +1,9 @@
|
|||
<?php
|
||||
/**
|
||||
* @package dompdf
|
||||
* @link https://github.com/dompdf/dompdf
|
||||
* @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
|
||||
*/
|
||||
namespace Dompdf\Frame;
|
||||
|
||||
use Iterator;
|
||||
|
@ -10,7 +15,6 @@ use Dompdf\Frame;
|
|||
* Returns children in order and allows for the list to change during iteration,
|
||||
* provided the changes occur to or after the current element.
|
||||
*
|
||||
* @access private
|
||||
* @package dompdf
|
||||
*/
|
||||
class FrameListIterator implements Iterator
|
|
@ -1,5 +1,9 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @package dompdf
|
||||
* @link https://github.com/dompdf/dompdf
|
||||
* @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
|
||||
*/
|
||||
namespace Dompdf\Frame;
|
||||
|
||||
use DOMDocument;
|
||||
|
@ -9,13 +13,7 @@ use DOMXPath;
|
|||
|
||||
use Dompdf\Exception;
|
||||
use Dompdf\Frame;
|
||||
|
||||
/**
|
||||
* @package dompdf
|
||||
* @link http://dompdf.github.com/
|
||||
* @author Benj Carson <benjcarson@digitaljunkies.ca>
|
||||
* @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
|
||||
*/
|
||||
use IteratorAggregate;
|
||||
|
||||
/**
|
||||
* Represents an entire document as a tree of frames
|
||||
|
@ -27,7 +25,7 @@ use Dompdf\Frame;
|
|||
*
|
||||
* @package dompdf
|
||||
*/
|
||||
class FrameTree
|
||||
class FrameTree implements IteratorAggregate
|
||||
{
|
||||
/**
|
||||
* Tags to ignore while parsing the tree
|
||||
|
@ -124,11 +122,22 @@ class FrameTree
|
|||
/**
|
||||
* Returns a post-order iterator for all frames in the tree
|
||||
*
|
||||
* @return FrameTreeList|Frame[]
|
||||
* @deprecated Iterate the tree directly instead
|
||||
* @return FrameTreeIterator
|
||||
*/
|
||||
public function get_frames()
|
||||
public function get_frames(): FrameTreeIterator
|
||||
{
|
||||
return new FrameTreeList($this->_root);
|
||||
return new FrameTreeIterator($this->_root);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a post-order iterator for all frames in the tree
|
||||
*
|
||||
* @return FrameTreeIterator
|
||||
*/
|
||||
public function getIterator(): FrameTreeIterator
|
||||
{
|
||||
return new FrameTreeIterator($this->_root);
|
||||
}
|
||||
|
||||
/**
|
|
@ -1,4 +1,9 @@
|
|||
<?php
|
||||
/**
|
||||
* @package dompdf
|
||||
* @link https://github.com/dompdf/dompdf
|
||||
* @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
|
||||
*/
|
||||
namespace Dompdf\Frame;
|
||||
|
||||
use Iterator;
|
||||
|
@ -9,7 +14,6 @@ use Dompdf\Frame;
|
|||
*
|
||||
* Returns frames in preorder traversal order (parent then children)
|
||||
*
|
||||
* @access private
|
||||
* @package dompdf
|
||||
*/
|
||||
class FrameTreeIterator implements Iterator
|
||||
|
@ -70,10 +74,7 @@ class FrameTreeIterator implements Iterator
|
|||
|
||||
public function next(): void
|
||||
{
|
||||
$b = end($this->_stack);
|
||||
|
||||
// Pop last element
|
||||
unset($this->_stack[key($this->_stack)]);
|
||||
$b = array_pop($this->_stack);
|
||||
$this->_num++;
|
||||
|
||||
// Push all children onto the stack in reverse order
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue