vendor: Upgrade dompdf to v2.0.1

This commit is contained in:
Johannes Meyer 2022-12-08 11:28:17 +01:00
parent b4756b19c5
commit f9b48e0651
342 changed files with 44506 additions and 23634 deletions

24
library/vendor/dompdf/AUTHORS.md vendored Normal file
View File

@ -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.

232
library/vendor/dompdf/README.md vendored Normal file
View File

@ -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.)*

View File

@ -1,24 +0,0 @@
#!/bin/bash
set -eux
#GLOBIGNORE=$0; rm -rf *
DOMPDF_VERSION=0.8.3
PHP_FONTLIB_VERSION=0.5.1
PHP_SVGLIB_VERSION=0.3.2
rm -rf lib/ src/
curl -LsS https://github.com/dompdf/dompdf/archive/v"$DOMPDF_VERSION".tar.gz -o /tmp/dompdf.tar.gz
tar xf /tmp/dompdf.tar.gz --strip-components 1 dompdf-"$DOMPDF_VERSION"/{lib,src,LICENSE.LGPL}
rm /tmp/dompdf.tar.gz
mv LICENSE.LGPL LICENSE
curl -LsS https://github.com/PhenX/php-font-lib/archive/"$PHP_FONTLIB_VERSION".tar.gz -o /tmp/php-font-lib.tar.gz
[ -d lib/php-font-lib ] || mkdir -p lib/php-font-lib
tar xf /tmp/php-font-lib.tar.gz --strip-components 1 -C lib/php-font-lib php-font-lib-"$PHP_FONTLIB_VERSION"/{src,LICENSE}
rm /tmp/php-font-lib.tar.gz
curl -LsS https://github.com/PhenX/php-svg-lib/archive/v"$PHP_SVGLIB_VERSION".tar.gz -o /tmp/php-svg-lib.tar.gz
[ -d lib/php-svg-lib ] || mkdir -p lib/php-svg-lib
tar xf /tmp/php-svg-lib.tar.gz --strip-components 1 -C lib/php-svg-lib php-svg-lib-"$PHP_SVGLIB_VERSION"/src
rm /tmp/php-svg-lib.tar.gz

1
library/vendor/dompdf/VERSION vendored Normal file
View File

@ -0,0 +1 @@
2.0.1

View File

@ -0,0 +1 @@
<?php require (__DIR__ . '/vendor/autoload.php');

View File

@ -1,95 +0,0 @@
<?php
$distFontDir = $rootDir . DIRECTORY_SEPARATOR . 'lib' . DIRECTORY_SEPARATOR . 'fonts' . DIRECTORY_SEPARATOR;
return array(
'sans-serif' =>
array(
'normal' => $distFontDir . 'Helvetica',
'bold' => $distFontDir . 'Helvetica-Bold',
'italic' => $distFontDir . 'Helvetica-Oblique',
'bold_italic' => $distFontDir . 'Helvetica-BoldOblique'
),
'times' =>
array(
'normal' => $distFontDir . 'Times-Roman',
'bold' => $distFontDir . 'Times-Bold',
'italic' => $distFontDir . 'Times-Italic',
'bold_italic' => $distFontDir . 'Times-BoldItalic'
),
'times-roman' =>
array(
'normal' => $distFontDir . 'Times-Roman',
'bold' => $distFontDir . 'Times-Bold',
'italic' => $distFontDir . 'Times-Italic',
'bold_italic' => $distFontDir . 'Times-BoldItalic'
),
'courier' =>
array(
'normal' => $distFontDir . 'Courier',
'bold' => $distFontDir . 'Courier-Bold',
'italic' => $distFontDir . 'Courier-Oblique',
'bold_italic' => $distFontDir . 'Courier-BoldOblique'
),
'helvetica' =>
array(
'normal' => $distFontDir . 'Helvetica',
'bold' => $distFontDir . 'Helvetica-Bold',
'italic' => $distFontDir . 'Helvetica-Oblique',
'bold_italic' => $distFontDir . 'Helvetica-BoldOblique'
),
'zapfdingbats' =>
array(
'normal' => $distFontDir . 'ZapfDingbats',
'bold' => $distFontDir . 'ZapfDingbats',
'italic' => $distFontDir . 'ZapfDingbats',
'bold_italic' => $distFontDir . 'ZapfDingbats'
),
'symbol' =>
array(
'normal' => $distFontDir . 'Symbol',
'bold' => $distFontDir . 'Symbol',
'italic' => $distFontDir . 'Symbol',
'bold_italic' => $distFontDir . 'Symbol'
),
'serif' =>
array(
'normal' => $distFontDir . 'Times-Roman',
'bold' => $distFontDir . 'Times-Bold',
'italic' => $distFontDir . 'Times-Italic',
'bold_italic' => $distFontDir . 'Times-BoldItalic'
),
'monospace' =>
array(
'normal' => $distFontDir . 'Courier',
'bold' => $distFontDir . 'Courier-Bold',
'italic' => $distFontDir . 'Courier-Oblique',
'bold_italic' => $distFontDir . 'Courier-BoldOblique'
),
'fixed' =>
array(
'normal' => $distFontDir . 'Courier',
'bold' => $distFontDir . 'Courier-Bold',
'italic' => $distFontDir . 'Courier-Oblique',
'bold_italic' => $distFontDir . 'Courier-BoldOblique'
),
'dejavu sans' =>
array(
'bold' => $distFontDir . 'DejaVuSans-Bold',
'bold_italic' => $distFontDir . 'DejaVuSans-BoldOblique',
'italic' => $distFontDir . 'DejaVuSans-Oblique',
'normal' => $distFontDir . 'DejaVuSans'
),
'dejavu sans mono' =>
array(
'bold' => $distFontDir . 'DejaVuSansMono-Bold',
'bold_italic' => $distFontDir . 'DejaVuSansMono-BoldOblique',
'italic' => $distFontDir . 'DejaVuSansMono-Oblique',
'normal' => $distFontDir . 'DejaVuSansMono'
),
'dejavu serif' =>
array(
'bold' => $distFontDir . 'DejaVuSerif-Bold',
'bold_italic' => $distFontDir . 'DejaVuSerif-BoldItalic',
'italic' => $distFontDir . 'DejaVuSerif-Italic',
'normal' => $distFontDir . 'DejaVuSerif'
)
);

View File

@ -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 = array(
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;
}
}

View File

@ -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 = array();
/**
* @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[] = array(
'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(
array(
"\0",
"\r\n",
"\r"
),
array(
"\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[] = array(
'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--;
}
}
}

View File

@ -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
*/
static public 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
*/
static public 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

View File

@ -1,308 +0,0 @@
<?php
/**
* @package php-svg-lib
* @link http://github.com/PhenX/php-svg-lib
* @author Fabien M<EFBFBD>nager <fabien.menager@gmail.com>
* @license GNU LGPLv3+ http://www.gnu.org/copyleft/lesser.html
*/
namespace Svg\Surface;
use Svg\Style;
class SurfaceGmagick implements SurfaceInterface
{
const DEBUG = false;
/** @var \GmagickDraw */
private $canvas;
private $width;
private $height;
/** @var Style */
private $style;
public function __construct($w, $h)
{
if (self::DEBUG) {
echo __FUNCTION__ . "\n";
}
$this->width = $w;
$this->height = $h;
$canvas = new \GmagickDraw();
$this->canvas = $canvas;
}
function out()
{
if (self::DEBUG) {
echo __FUNCTION__ . "\n";
}
$image = new \Gmagick();
$image->newimage($this->width, $this->height);
$image->drawimage($this->canvas);
$tmp = tempnam("", "gm");
$image->write($tmp);
return file_get_contents($tmp);
}
public function save()
{
if (self::DEBUG) {
echo __FUNCTION__ . "\n";
}
$this->canvas->save();
}
public function restore()
{
if (self::DEBUG) echo __FUNCTION__ . "\n";
$this->canvas->restore();
}
public function scale($x, $y)
{
if (self::DEBUG) echo __FUNCTION__ . "\n";
$this->canvas->scale($x, $y);
}
public function rotate($angle)
{
if (self::DEBUG) echo __FUNCTION__ . "\n";
$this->canvas->rotate($angle);
}
public function translate($x, $y)
{
if (self::DEBUG) echo __FUNCTION__ . "\n";
$this->canvas->translate($x, $y);
}
public function transform($a, $b, $c, $d, $e, $f)
{
if (self::DEBUG) echo __FUNCTION__ . "\n";
$this->canvas->concat($a, $b, $c, $d, $e, $f);
}
public function beginPath()
{
if (self::DEBUG) echo __FUNCTION__ . "\n";
// TODO: Implement beginPath() method.
}
public function closePath()
{
if (self::DEBUG) echo __FUNCTION__ . "\n";
$this->canvas->closepath();
}
public function fillStroke()
{
if (self::DEBUG) echo __FUNCTION__ . "\n";
$this->canvas->fill_stroke();
}
public function clip()
{
if (self::DEBUG) echo __FUNCTION__ . "\n";
$this->canvas->clip();
}
public function fillText($text, $x, $y, $maxWidth = null)
{
if (self::DEBUG) echo __FUNCTION__ . "\n";
$this->canvas->set_text_pos($x, $y);
$this->canvas->show($text);
}
public function strokeText($text, $x, $y, $maxWidth = null)
{
if (self::DEBUG) echo __FUNCTION__ . "\n";
// TODO: Implement drawImage() method.
}
public function drawImage($image, $sx, $sy, $sw = null, $sh = null, $dx = null, $dy = null, $dw = null, $dh = null)
{
if (self::DEBUG) echo __FUNCTION__ . "\n";
if (strpos($image, "data:") === 0) {
$data = substr($image, strpos($image, ";") + 1);
if (strpos($data, "base64") === 0) {
$data = base64_decode(substr($data, 7));
}
$image = tempnam("", "svg");
file_put_contents($image, $data);
}
$img = $this->canvas->load_image("auto", $image, "");
$sy = $sy - $sh;
$this->canvas->fit_image($img, $sx, $sy, 'boxsize={' . "$sw $sh" . '} fitmethod=entire');
}
public function lineTo($x, $y)
{
if (self::DEBUG) echo __FUNCTION__ . "\n";
$this->canvas->lineto($x, $y);
}
public function moveTo($x, $y)
{
if (self::DEBUG) echo __FUNCTION__ . "\n";
$this->canvas->moveto($x, $y);
}
public function quadraticCurveTo($cpx, $cpy, $x, $y)
{
if (self::DEBUG) echo __FUNCTION__ . "\n";
// TODO: Implement quadraticCurveTo() method.
}
public function bezierCurveTo($cp1x, $cp1y, $cp2x, $cp2y, $x, $y)
{
if (self::DEBUG) echo __FUNCTION__ . "\n";
$this->canvas->curveto($cp1x, $cp1y, $cp2x, $cp2y, $x, $y);
}
public function arcTo($x1, $y1, $x2, $y2, $radius)
{
if (self::DEBUG) echo __FUNCTION__ . "\n";
}
public function arc($x, $y, $radius, $startAngle, $endAngle, $anticlockwise = false)
{
if (self::DEBUG) echo __FUNCTION__ . "\n";
$this->canvas->arc($x, $y, $radius, $startAngle, $endAngle);
}
public function circle($x, $y, $radius)
{
if (self::DEBUG) echo __FUNCTION__ . "\n";
$this->canvas->circle($x, $y, $radius);
}
public function ellipse($x, $y, $radiusX, $radiusY, $rotation, $startAngle, $endAngle, $anticlockwise)
{
if (self::DEBUG) echo __FUNCTION__ . "\n";
$this->canvas->ellipse($x, $y, $radiusX, $radiusY);
}
public function fillRect($x, $y, $w, $h)
{
if (self::DEBUG) echo __FUNCTION__ . "\n";
$this->rect($x, $y, $w, $h);
$this->fill();
}
public function rect($x, $y, $w, $h, $rx = 0, $ry = 0)
{
if (self::DEBUG) echo __FUNCTION__ . "\n";
$this->canvas->rect($x, $y, $w, $h);
}
public function fill()
{
if (self::DEBUG) echo __FUNCTION__ . "\n";
$this->canvas->fill();
}
public function strokeRect($x, $y, $w, $h)
{
if (self::DEBUG) echo __FUNCTION__ . "\n";
$this->rect($x, $y, $w, $h);
$this->stroke();
}
public function stroke()
{
if (self::DEBUG) echo __FUNCTION__ . "\n";
$this->canvas->stroke();
}
public function endPath()
{
if (self::DEBUG) echo __FUNCTION__ . "\n";
//$this->canvas->endPath();
}
public function measureText($text)
{
if (self::DEBUG) echo __FUNCTION__ . "\n";
$style = $this->getStyle();
$font = $this->getFont($style->fontFamily, $style->fontStyle);
return $this->canvas->stringwidth($text, $font, $this->getStyle()->fontSize);
}
public function getStyle()
{
if (self::DEBUG) echo __FUNCTION__ . "\n";
return $this->style;
}
public function setStyle(Style $style)
{
if (self::DEBUG) echo __FUNCTION__ . "\n";
$this->style = $style;
$canvas = $this->canvas;
if (is_array($style->stroke) && $stroke = $style->stroke) {
$canvas->setcolor("stroke", "rgb", $stroke[0] / 255, $stroke[1] / 255, $stroke[2] / 255, null);
}
if (is_array($style->fill) && $fill = $style->fill) {
// $canvas->setcolor("fill", "rgb", $fill[0] / 255, $fill[1] / 255, $fill[2] / 255, null);
}
$opts = array();
if ($style->strokeWidth > 0.000001) {
$opts[] = "linewidth=$style->strokeWidth";
}
if (in_array($style->strokeLinecap, array("butt", "round", "projecting"))) {
$opts[] = "linecap=$style->strokeLinecap";
}
if (in_array($style->strokeLinejoin, array("miter", "round", "bevel"))) {
$opts[] = "linejoin=$style->strokeLinejoin";
}
$canvas->set_graphics_option(implode(" ", $opts));
$font = $this->getFont($style->fontFamily, $style->fontStyle);
$canvas->setfont($font, $style->fontSize);
}
private function getFont($family, $style)
{
$map = array(
"serif" => "Times",
"sans-serif" => "Helvetica",
"fantasy" => "Symbol",
"cursive" => "serif",
"monospance" => "Courier",
);
$family = strtolower($family);
if (isset($map[$family])) {
$family = $map[$family];
}
return $this->canvas->load_font($family, "unicode", "fontstyle=$style");
}
public function setFont($family, $style, $weight)
{
// TODO: Implement setFont() method.
}
}

View File

@ -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;
}
}
});

View File

@ -1,8 +0,0 @@
<?xml version="1.0"?>
<svg width="64" height="64" xmlns="http://www.w3.org/2000/svg">
<g>
<rect stroke="#666666" id="svg_1" height="60.499994" width="60.166667" y="1.666669" x="1.999998" stroke-width="1.5" fill="none"/>
<line 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="#999999" fill="none"/>
<line 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="#999999" fill="none"/>
</g>
</svg>

Before

Width:  |  Height:  |  Size: 579 B

File diff suppressed because it is too large Load Diff

View 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(array(new self, 'autoload'));
}
/**
* Autoloader
*
* @param string
*/
public static function autoload($class)
{
if ($class === 'Cpdf') {
require_once __DIR__ . "/../lib/Cpdf.php";
return;
}
$prefixLength = strlen(self::PREFIX);
if (0 === strncmp(self::PREFIX, $class, $prefixLength)) {
$file = str_replace('\\', DIRECTORY_SEPARATOR, substr($class, $prefixLength));
$file = realpath(__DIR__ . (empty($file) ? '' : DIRECTORY_SEPARATOR) . $file . '.php');
if (file_exists($file)) {
require_once $file;
}
}
}
}

View File

@ -1,422 +0,0 @@
<?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
*/
namespace Dompdf;
/**
* Main rendering interface
*
* Currently {@link Dompdf\Adapter\CPDF}, {@link Dompdf\Adapter\PDFLib}, and {@link Dompdf\Adapter\GD}
* implement this interface.
*
* Implementations should measure x and y increasing to the left and down,
* respectively, with the origin in the top left corner. Implementations
* are free to use a unit other than points for length, but I can't
* guarantee that the results will look any good.
*
* @package dompdf
*/
interface Canvas
{
function __construct($paper = "letter", $orientation = "portrait", Dompdf $dompdf);
/**
* @return Dompdf
*/
function get_dompdf();
/**
* Returns the current page number
*
* @return int
*/
function get_page_number();
/**
* Returns the total number of pages
*
* @return int
*/
function get_page_count();
/**
* Sets the total number of pages
*
* @param int $count
*/
function set_page_count($count);
/**
* 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
*/
function line($x1, $y1, $x2, $y2, $color, $width, $style = null);
/**
* 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
*/
function rectangle($x1, $y1, $w, $h, $color, $width, $style = null);
/**
* 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
*/
function filled_rectangle($x1, $y1, $w, $h, $color);
/**
* 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
*/
function clipping_rectangle($x1, $y1, $w, $h);
/**
* Starts a rounded clipping rectangle at x1,y1 with width w and height h
*
* @param float $x1
* @param float $y1
* @param float $w
* @param float $h
* @param float $tl
* @param float $tr
* @param float $br
* @param float $bl
*
* @return
*/
function clipping_roundrectangle($x1, $y1, $w, $h, $tl, $tr, $br, $bl);
/**
* Ends the last clipping shape
*/
function clipping_end();
/**
* Save current state
*/
function save();
/**
* Restore last state
*/
function restore();
/**
* Rotate
*
* @param float $angle angle in degrees for counter-clockwise rotation
* @param float $x Origin abscissa
* @param float $y Origin ordinate
*/
function rotate($angle, $x, $y);
/**
* Skew
*
* @param float $angle_x
* @param float $angle_y
* @param float $x Origin abscissa
* @param float $y Origin ordinate
*/
function skew($angle_x, $angle_y, $x, $y);
/**
* Scale
*
* @param float $s_x scaling factor for width as percent
* @param float $s_y scaling factor for height as percent
* @param float $x Origin abscissa
* @param float $y Origin ordinate
*/
function scale($s_x, $s_y, $x, $y);
/**
* Translate
*
* @param float $t_x movement to the right
* @param float $t_y movement to the bottom
*/
function translate($t_x, $t_y);
/**
* Transform
*
* @param $a
* @param $b
* @param $c
* @param $d
* @param $e
* @param $f
* @return
*/
function transform($a, $b, $c, $d, $e, $f);
/**
* 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
*/
function polygon($points, $color, $width = null, $style = null, $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)
*
* @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
*/
function circle($x, $y, $r, $color, $width = null, $style = null, $fill = false);
/**
* 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 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 = array());
/**
* 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
*/
function text($x, $y, $text, $font, $size, $color = array(0, 0, 0), $word_space = 0.0, $char_space = 0.0, $angle = 0.0);
/**
* Add a named destination (similar to <a name="foo">...</a> in html)
*
* @param string $anchorname The name of the named destination
*/
function add_named_dest($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
*/
function add_link($url, $x, $y, $width, $height);
/**
* Add meta information to the pdf
*
* @param string $name Label of the value (Creator, Producer, etc.)
* @param string $value The text to set
*/
function add_info($name, $value);
/**
* 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
*
* @return float
*/
function get_text_width($text, $font, $size, $word_spacing = 0.0, $char_spacing = 0.0);
/**
* Calculates font height, in points
*
* @param string $font
* @param float $size
*
* @return float
*/
function get_font_height($font, $size);
/**
* Calculates font baseline, in points
*
* @param string $font
* @param float $size
*
* @return float
*/
function get_font_baseline($font, $size);
/**
* Returns the PDF's width in points
*
* @return float
*/
function get_width();
/**
* Return the image's height in pixels
*
* @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 string $mode
*/
function set_opacity($opacity, $mode = "Normal");
/**
* Sets the default view
*
* @param string $view
* 'XYZ' left, top, zoom
* 'Fit'
* 'FitH' top
* 'FitV' left
* 'FitR' left,bottom,right
* 'FitB'
* 'FitBH' top
* 'FitBV' left
* @param array $options
*
* @return void
*/
function set_default_view($view, $options = array());
/**
* @param string $script
*
* @return void
*/
function javascript($script);
/**
* Starts a new page
*
* Subsequent drawing operations will appear on the new page.
*/
function new_page();
/**
* Streams the PDF directly to the browser.
*
* @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).
*/
function stream($filename, $options = array());
/**
* Returns the PDF as a string.
*
* @param array $options Associative array: 'compress' => 1 or 0 (default 1).
* @return string
*/
function output($options = array());
}

File diff suppressed because it is too large Load Diff

View File

@ -1,538 +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;
use FontLib\Font;
/**
* The font metrics class
*
* This class provides information about fonts and text. It can resolve
* font names into actual installed font files, as well as determine the
* size of text in a particular font and size.
*
* @static
* @package dompdf
*/
class FontMetrics
{
/**
* Name of the font cache 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
* with FontMetrics::saveFontFamilies().
* 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";
/**
* @var Canvas
* @deprecated
*/
protected $pdf;
/**
* Underlying {@link Canvas} object to perform text size calculations
*
* @var Canvas
*/
protected $canvas;
/**
* Array of font family names to font files
*
* Usually cached by the {@link load_font.php} script
*
* @var array
*/
protected $fontLookup = array();
/**
* @var Options
*/
private $options;
/**
* Class initialization
*/
public function __construct(Canvas $canvas, Options $options)
{
$this->setCanvas($canvas);
$this->setOptions($options);
$this->loadFontFamilies();
}
/**
* @deprecated
*/
public function save_font_families()
{
$this->saveFontFamilies();
}
/**
* 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
* 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 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->getOptions()->getFontDir() , '$fontDir . \'' , $path);
$path = str_replace('\'' . $this->getOptions()->getRootDir() , '$rootDir . \'' , $path);
$cacheData .= sprintf(" '%s' => %s,%s", $variant, $path, PHP_EOL);
}
$cacheData .= sprintf(" ),%s", PHP_EOL);
}
$cacheData .= ") ?>";
file_put_contents($this->getCacheFile(), $cacheData);
}
/**
* @deprecated
*/
public function load_font_families()
{
$this->loadFontFamilies();
}
/**
* Loads the stored font family cache
*
* @see FontMetrics::saveFontFamilies()
*/
public function loadFontFamilies()
{
$fontDir = $this->getOptions()->getFontDir();
$rootDir = $this->getOptions()->getRootDir();
// 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";
$distFonts = require $file;
if (!is_readable($this->getCacheFile())) {
$this->fontLookup = $distFonts;
return;
}
$cacheData = require $this->getCacheFile();
$this->fontLookup = array();
if (is_array($this->fontLookup)) {
foreach ($cacheData as $key => $value) {
$this->fontLookup[stripslashes($key)] = $value;
}
}
// Merge provided fonts
$this->fontLookup += $distFonts;
}
/**
* @param array $style
* @param string $remote_file
* @param resource $context
* @return bool
* @deprecated
*/
public function register_font($style, $remote_file, $context = null)
{
return $this->registerFont($style, $remote_file);
}
/**
* @param array $style
* @param string $remoteFile
* @param resource $context
* @return bool
*/
public function registerFont($style, $remoteFile, $context = null)
{
$fontname = mb_strtolower($style["family"]);
$families = $this->getFontFamilies();
$entry = array();
if (isset($families[$fontname])) {
$entry = $families[$fontname];
}
$styleString = $this->getType("{$style['weight']} {$style['style']}");
if (isset($entry[$styleString])) {
return true;
}
$fontDir = $this->getOptions()->getFontDir();
$remoteHash = md5($remoteFile);
$localFile = $fontDir . DIRECTORY_SEPARATOR . $remoteHash;
$cacheEntry = $localFile;
$localFile .= ".".strtolower(pathinfo(parse_url($remoteFile, PHP_URL_PATH),PATHINFO_EXTENSION));
$entry[$styleString] = $cacheEntry;
// Download the remote file
list($remoteFileContent, $http_response_header) = @Helpers::getFileContent($remoteFile, $context);
if (false === $remoteFileContent) {
return false;
}
$localTempFile = @tempnam($this->options->get("tempDir"), "dompdf-font-");
file_put_contents($localTempFile, $remoteFileContent);
$font = Font::load($localTempFile);
if (!$font) {
unlink($localTempFile);
return false;
}
$font->parse();
$font->saveAdobeFontMetrics("$cacheEntry.ufm");
$font->close();
unlink($localTempFile);
if ( !file_exists("$cacheEntry.ufm") ) {
return false;
}
// Save the changes
file_put_contents($localFile, $remoteFileContent);
if ( !file_exists($localFile) ) {
unlink("$cacheEntry.ufm");
return false;
}
$this->setFontFamily($fontname, $entry);
$this->saveFontFamilies();
return true;
}
/**
* @param $text
* @param $font
* @param $size
* @param float $word_spacing
* @param float $char_spacing
* @return float
* @deprecated
*/
public function get_text_width($text, $font, $size, $word_spacing = 0.0, $char_spacing = 0.0)
{
//return self::$_pdf->get_text_width($text, $font, $size, $word_spacing, $char_spacing);
return $this->getTextWidth($text, $font, $size, $word_spacing, $char_spacing);
}
/**
* 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
*
* @internal param float $spacing word spacing, if any
* @return float
*/
public function getTextWidth($text, $font, $size, $wordSpacing = 0.0, $charSpacing = 0.0)
{
// @todo Make sure this cache is efficient before enabling it
static $cache = array();
if ($text === "") {
return 0;
}
// Don't cache long strings
$useCache = !isset($text[50]); // Faster than strlen
$key = "$font/$size/$wordSpacing/$charSpacing";
if ($useCache && isset($cache[$key][$text])) {
return $cache[$key]["$text"];
}
$width = $this->getCanvas()->get_text_width($text, $font, $size, $wordSpacing, $charSpacing);
if ($useCache) {
$cache[$key][$text] = $width;
}
return $width;
}
/**
* @param $font
* @param $size
* @return float
* @deprecated
*/
public function get_font_height($font, $size)
{
return $this->getFontHeight($font, $size);
}
/**
* Calculates font height
*
* @param string $font
* @param float $size
*
* @return float
*/
public function getFontHeight($font, $size)
{
return $this->getCanvas()->get_font_height($font, $size);
}
/**
* @param $family_raw
* @param string $subtype_raw
* @return string
* @deprecated
*/
public function get_font($family_raw, $subtype_raw = "normal")
{
return $this->getFont($family_raw, $subtype_raw);
}
/**
* Resolves a font family & subtype into an actual font file
* Subtype can be one of 'normal', 'bold', 'italic' or 'bold_italic'. If
* the particular font family has no suitable font file, the default font
* ({@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
*
* @return string
*/
public function getFont($familyRaw, $subtypeRaw = "normal")
{
static $cache = array();
if (isset($cache[$familyRaw][$subtypeRaw])) {
return $cache[$familyRaw][$subtypeRaw];
}
/* Allow calling for various fonts in search path. Therefore not immediately
* return replacement on non match.
* Only when called with NULL try replacement.
* When this is also missing there is really trouble.
* If only the subtype fails, nevertheless return failure.
* Only on checking the fallback font, check various subtypes on same font.
*/
$subtype = strtolower($subtypeRaw);
if ($familyRaw) {
$family = str_replace(array("'", '"'), "", strtolower($familyRaw));
if (isset($this->fontLookup[$family][$subtype])) {
return $cache[$familyRaw][$subtypeRaw] = $this->fontLookup[$family][$subtype];
}
return null;
}
$family = "serif";
if (isset($this->fontLookup[$family][$subtype])) {
return $cache[$familyRaw][$subtypeRaw] = $this->fontLookup[$family][$subtype];
}
if (!isset($this->fontLookup[$family])) {
return null;
}
$family = $this->fontLookup[$family];
foreach ($family as $sub => $font) {
if (strpos($subtype, $sub) !== false) {
return $cache[$familyRaw][$subtypeRaw] = $font;
}
}
if ($subtype !== "normal") {
foreach ($family as $sub => $font) {
if ($sub !== "normal") {
return $cache[$familyRaw][$subtypeRaw] = $font;
}
}
}
$subtype = "normal";
if (isset($family[$subtype])) {
return $cache[$familyRaw][$subtypeRaw] = $family[$subtype];
}
return null;
}
/**
* @param $family
* @return null|string
* @deprecated
*/
public function get_family($family)
{
return $this->getFamily($family);
}
/**
* @param string $family
* @return null|string
*/
public function getFamily($family)
{
$family = str_replace(array("'", '"'), "", mb_strtolower($family));
if (isset($this->fontLookup[$family])) {
return $this->fontLookup[$family];
}
return null;
}
/**
* @param $type
* @return string
* @deprecated
*/
public function get_type($type)
{
return $this->getType($type);
}
/**
* @param string $type
* @return string
*/
public function getType($type)
{
if (preg_match("/bold/i", $type)) {
if (preg_match("/italic|oblique/i", $type)) {
$type = "bold_italic";
} else {
$type = "bold";
}
} elseif (preg_match("/italic|oblique/i", $type)) {
$type = "italic";
} else {
$type = "normal";
}
return $type;
}
/**
* @return array
* @deprecated
*/
public function get_font_families()
{
return $this->getFontFamilies();
}
/**
* Returns the current font lookup table
*
* @return array
*/
public function getFontFamilies()
{
return $this->fontLookup;
}
/**
* @param string $fontname
* @param mixed $entry
* @deprecated
*/
public function set_font_family($fontname, $entry)
{
$this->setFontFamily($fontname, $entry);
}
/**
* @param string $fontname
* @param mixed $entry
*/
public function setFontFamily($fontname, $entry)
{
$this->fontLookup[mb_strtolower($fontname)] = $entry;
}
/**
* @return string
*/
public function getCacheFile()
{
return $this->getOptions()->getFontDir() . DIRECTORY_SEPARATOR . self::CACHE_FILE;
}
/**
* @param Options $options
* @return $this
*/
public function setOptions(Options $options)
{
$this->options = $options;
return $this;
}
/**
* @return Options
*/
public function getOptions()
{
return $this->options;
}
/**
* @param Canvas $canvas
* @return $this
*/
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;
}
/**
* @return Canvas
*/
public function getCanvas()
{
return $this->canvas;
}
}

View 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()
{
return new FrameListIterator($this->_frame);
}
}

View File

@ -1,91 +0,0 @@
<?php
namespace Dompdf\Frame;
use Iterator;
use Dompdf\Frame;
/**
* Linked-list Iterator
*
* Returns children in order and allows for list to change during iteration,
* provided the changes occur to or after the current element
*
* @access private
* @package dompdf
*/
class FrameListIterator implements Iterator
{
/**
* @var Frame
*/
protected $_parent;
/**
* @var Frame
*/
protected $_cur;
/**
* @var int
*/
protected $_num;
/**
* @param Frame $frame
*/
public function __construct(Frame $frame)
{
$this->_parent = $frame;
$this->_cur = $frame->get_first_child();
$this->_num = 0;
}
/**
*
*/
public function rewind()
{
$this->_cur = $this->_parent->get_first_child();
$this->_num = 0;
}
/**
* @return bool
*/
public function valid()
{
return isset($this->_cur); // && ($this->_cur->get_prev_sibling() === $this->_prev);
}
/**
* @return int
*/
public function key()
{
return $this->_num;
}
/**
* @return Frame
*/
public function current()
{
return $this->_cur;
}
/**
* @return Frame
*/
public function next()
{
$ret = $this->_cur;
if (!$ret) {
return null;
}
$this->_cur = $this->_cur->get_next_sibling();
$this->_num++;
return $ret;
}
}

View File

@ -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 \Dompdf\Frame
*/
protected $_root;
/**
* @param \Dompdf\Frame $root
*/
public function __construct(Frame $root)
{
$this->_root = $root;
}
/**
* @return FrameTreeIterator
*/
public function getIterator()
{
return new FrameTreeIterator($this->_root);
}
}

View File

@ -1,284 +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\LineBox;
/**
* Decorates frames for block layout
*
* @access private
* @package dompdf
*/
class Block extends AbstractFrameDecorator
{
/**
* Current line index
*
* @var int
*/
protected $_cl;
/**
* The block's line boxes
*
* @var LineBox[]
*/
protected $_line_boxes;
/**
* Block constructor.
* @param Frame $frame
* @param Dompdf $dompdf
*/
function __construct(Frame $frame, Dompdf $dompdf)
{
parent::__construct($frame, $dompdf);
$this->_line_boxes = array(new LineBox($this));
$this->_cl = 0;
}
/**
*
*/
function reset()
{
parent::reset();
$this->_line_boxes = array(new LineBox($this));
$this->_cl = 0;
}
/**
* @return LineBox
*/
function get_current_line_box()
{
return $this->_line_boxes[$this->_cl];
}
/**
* @return integer
*/
function get_current_line_number()
{
return $this->_cl;
}
/**
* @return LineBox[]
*/
function get_line_boxes()
{
return $this->_line_boxes;
}
/**
* @param integer $line_number
* @return integer
*/
function set_current_line_number($line_number)
{
$line_boxes_count = count($this->_line_boxes);
$cl = max(min($line_number, $line_boxes_count), 0);
return ($this->_cl = $cl);
}
/**
* @param integer $i
*/
function clear_line($i)
{
if (isset($this->_line_boxes[$i])) {
unset($this->_line_boxes[$i]);
}
}
/**
* @param Frame $frame
*/
function add_frame_to_line(Frame $frame)
{
if (!$frame->is_in_flow()) {
return;
}
$style = $frame->get_style();
$frame->set_containing_line($this->_line_boxes[$this->_cl]);
/*
// Adds a new line after a block, only if certain conditions are met
if ((($frame instanceof Inline && $frame->get_node()->nodeName !== "br") ||
$frame instanceof Text && trim($frame->get_text())) &&
($frame->get_prev_sibling() && $frame->get_prev_sibling()->get_style()->display === "block" &&
$this->_line_boxes[$this->_cl]->w > 0 )) {
$this->maximize_line_height( $style->length_in_pt($style->line_height), $frame );
$this->add_line();
// Add each child of the inline frame to the line individually
foreach ($frame->get_children() as $child)
$this->add_frame_to_line( $child );
}
else*/
// Handle inline frames (which are effectively wrappers)
if ($frame instanceof Inline) {
// Handle line breaks
if ($frame->get_node()->nodeName === "br") {
$this->maximize_line_height($style->length_in_pt($style->line_height), $frame);
$this->add_line(true);
}
return;
}
// Trim leading text if this is an empty line. Kinda a hack to put it here,
// but what can you do...
if ($this->get_current_line_box()->w == 0 &&
$frame->is_text_node() &&
!$frame->is_pre()
) {
$frame->set_text(ltrim($frame->get_text()));
$frame->recalculate_width();
}
$w = $frame->get_margin_width();
// FIXME: Why? Doesn't quite seem to be the correct thing to do,
// but does appear to be necessary. Hack to handle wrapped white space?
if ($w == 0 && $frame->get_node()->nodeName !== "hr") {
return;
}
// Debugging code:
/*
Helpers::pre_r("\n<h3>Adding frame to line:</h3>");
// Helpers::pre_r("Me: " . $this->get_node()->nodeName . " (" . spl_object_hash($this->get_node()) . ")");
// Helpers::pre_r("Node: " . $frame->get_node()->nodeName . " (" . spl_object_hash($frame->get_node()) . ")");
if ( $frame->is_text_node() )
Helpers::pre_r('"'.$frame->get_node()->nodeValue.'"');
Helpers::pre_r("Line width: " . $this->_line_boxes[$this->_cl]->w);
Helpers::pre_r("Frame: " . get_class($frame));
Helpers::pre_r("Frame width: " . $w);
Helpers::pre_r("Frame height: " . $frame->get_margin_height());
Helpers::pre_r("Containing block width: " . $this->get_containing_block("w"));
*/
// End debugging
$line = $this->_line_boxes[$this->_cl];
if ($line->left + $line->w + $line->right + $w > $this->get_containing_block("w")) {
$this->add_line();
}
$frame->position();
$current_line = $this->_line_boxes[$this->_cl];
$current_line->add_frame($frame);
if ($frame->is_text_node()) {
$current_line->wc += count(preg_split("/\s+/", trim($frame->get_text())));
}
$this->increase_line_width($w);
$this->maximize_line_height($frame->get_margin_height(), $frame);
}
/**
* @param Frame $frame
*/
function remove_frames_from_line(Frame $frame)
{
// Search backwards through the lines for $frame
$i = $this->_cl;
$j = null;
while ($i >= 0) {
if (($j = in_array($frame, $this->_line_boxes[$i]->get_frames(), true)) !== false) {
break;
}
$i--;
}
if ($j === false) {
return;
}
// Remove $frame and all frames that follow
while ($j < count($this->_line_boxes[$i]->get_frames())) {
$frames = $this->_line_boxes[$i]->get_frames();
$f = $frames[$j];
$frames[$j] = null;
unset($frames[$j]);
$j++;
$this->_line_boxes[$i]->w -= $f->get_margin_width();
}
// Recalculate the height of the line
$h = 0;
foreach ($this->_line_boxes[$i]->get_frames() as $f) {
$h = max($h, $f->get_margin_height());
}
$this->_line_boxes[$i]->h = $h;
// Remove all lines that follow
while ($this->_cl > $i) {
$this->_line_boxes[$this->_cl] = null;
unset($this->_line_boxes[$this->_cl]);
$this->_cl--;
}
}
/**
* @param float $w
*/
function increase_line_width($w)
{
$this->_line_boxes[$this->_cl]->w += $w;
}
/**
* @param $val
* @param Frame $frame
*/
function maximize_line_height($val, Frame $frame)
{
if ($val > $this->_line_boxes[$this->_cl]->h) {
$this->_line_boxes[$this->_cl]->tallest_frame = $frame;
$this->_line_boxes[$this->_cl]->h = $val;
}
}
/**
* @param bool $br
*/
function add_line($br = false)
{
// if ( $this->_line_boxes[$this->_cl]["h"] == 0 ) //count($this->_line_boxes[$i]["frames"]) == 0 ||
// return;
$this->_line_boxes[$this->_cl]->br = $br;
$y = $this->_line_boxes[$this->_cl]->y + $this->_line_boxes[$this->_cl]->h;
$new_line = new LineBox($this, $y);
$this->_line_boxes[++$this->_cl] = $new_line;
}
//........................................................................
}

View File

@ -1,106 +0,0 @@
<?php
/**
* @package dompdf
* @link http://dompdf.github.com/
* @author Benj Carson <benjcarson@digitaljunkies.ca>
* @author Helmut Tischer <htischer@weihenstephan.org>
* @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
*/
namespace Dompdf\FrameDecorator;
use DOMElement;
use Dompdf\Dompdf;
use Dompdf\Frame;
use Dompdf\Exception;
/**
* Decorates frames for inline layout
*
* @access private
* @package dompdf
*/
class Inline extends AbstractFrameDecorator
{
/**
* Inline constructor.
* @param Frame $frame
* @param Dompdf $dompdf
*/
function __construct(Frame $frame, Dompdf $dompdf)
{
parent::__construct($frame, $dompdf);
}
/**
* @param Frame|null $frame
* @param bool $force_pagebreak
* @throws Exception
*/
function split(Frame $frame = null, $force_pagebreak = false)
{
if (is_null($frame)) {
$this->get_parent()->split($this, $force_pagebreak);
return;
}
if ($frame->get_parent() !== $this) {
throw new Exception("Unable to split: frame is not a child of this one.");
}
$node = $this->_frame->get_node();
if ($node instanceof DOMElement && $node->hasAttribute("id")) {
$node->setAttribute("data-dompdf-original-id", $node->getAttribute("id"));
$node->removeAttribute("id");
}
$split = $this->copy($node->cloneNode());
// if this is a generated node don't propagate the content style
if ($split->get_node()->nodeName == "dompdf_generated") {
$split->get_style()->content = "normal";
}
$this->get_parent()->insert_child_after($split, $this);
// Unset the current node's right style properties
$style = $this->_frame->get_style();
$style->margin_right = 0;
$style->padding_right = 0;
$style->border_right_width = 0;
// Unset the split node's left style properties since we don't want them
// to propagate
$style = $split->get_style();
$style->margin_left = 0;
$style->padding_left = 0;
$style->border_left_width = 0;
//On continuation of inline element on next line,
//don't repeat non-vertically repeatble background images
//See e.g. in testcase image_variants, long desriptions
if (($url = $style->background_image) && $url !== "none"
&& ($repeat = $style->background_repeat) && $repeat !== "repeat" && $repeat !== "repeat-y"
) {
$style->background_image = "none";
}
// Add $frame and all following siblings to the new split node
$iter = $frame;
while ($iter) {
$frame = $iter;
$iter = $iter->get_next_sibling();
$frame->reset();
$split->append_child($frame);
}
$page_breaks = array("always", "left", "right");
$frame_style = $frame->get_style();
if ($force_pagebreak ||
in_array($frame_style->page_break_before, $page_breaks) ||
in_array($frame_style->page_break_after, $page_breaks)
) {
$this->get_parent()->split($split, true);
}
}
}

View File

@ -1,87 +0,0 @@
<?php
/**
* @package dompdf
* @link http://dompdf.github.com/
* @author Benj Carson <benjcarson@digitaljunkies.ca>
* @author Helmut Tischer <htischer@weihenstephan.org>
* @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
*/
namespace Dompdf\FrameDecorator;
use Dompdf\Dompdf;
use Dompdf\Frame;
/**
* Decorates frames for list bullet rendering
*
* @package dompdf
*/
class ListBullet extends AbstractFrameDecorator
{
const BULLET_PADDING = 1; // Distance from bullet to text in pt
// As fraction of font size (including descent). See also DECO_THICKNESS.
const BULLET_THICKNESS = 0.04; // Thickness of bullet outline. Screen: 0.08, print: better less, e.g. 0.04
const BULLET_DESCENT = 0.3; //descent of font below baseline. Todo: Guessed for now.
const BULLET_SIZE = 0.35; // bullet diameter. For now 0.5 of font_size without descent.
static $BULLET_TYPES = array("disc", "circle", "square");
/**
* ListBullet constructor.
* @param Frame $frame
* @param Dompdf $dompdf
*/
function __construct(Frame $frame, Dompdf $dompdf)
{
parent::__construct($frame, $dompdf);
}
/**
* @return float|int
*/
function get_margin_width()
{
$style = $this->_frame->get_style();
if ($style->list_style_type === "none") {
return 0;
}
return $style->font_size * self::BULLET_SIZE + 2 * self::BULLET_PADDING;
}
/**
* hits only on "inset" lists items, to increase height of box
*
* @return float|int
*/
function get_margin_height()
{
$style = $this->_frame->get_style();
if ($style->list_style_type === "none") {
return 0;
}
return $style->font_size * self::BULLET_SIZE + 2 * self::BULLET_PADDING;
}
/**
* @return float|int
*/
function get_width()
{
return $this->get_margin_width();
}
/**
* @return float|int
*/
function get_height()
{
return $this->get_margin_height();
}
//........................................................................
}

View File

@ -1,154 +0,0 @@
<?php
/**
* @package dompdf
* @link http://dompdf.github.com/
* @author Benj Carson <benjcarson@digitaljunkies.ca>
* @author Helmut Tischer <htischer@weihenstephan.org>
* @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
*/
namespace Dompdf\FrameDecorator;
use Dompdf\Dompdf;
use Dompdf\Frame;
use Dompdf\Helpers;
/**
* Decorates frames for list bullets with custom images
*
* @package dompdf
*/
class ListBulletImage extends AbstractFrameDecorator
{
/**
* The underlying image frame
*
* @var Image
*/
protected $_img;
/**
* The image's width in pixels
*
* @var int
*/
protected $_width;
/**
* The image's height in pixels
*
* @var int
*/
protected $_height;
/**
* Class constructor
*
* @param Frame $frame the bullet frame to decorate
* @param Dompdf $dompdf the document's dompdf object
*/
function __construct(Frame $frame, Dompdf $dompdf)
{
$style = $frame->get_style();
$url = $style->list_style_image;
$frame->get_node()->setAttribute("src", $url);
$this->_img = new Image($frame, $dompdf);
parent::__construct($this->_img, $dompdf);
list($width, $height) = Helpers::dompdf_getimagesize($this->_img->get_image_url(), $dompdf->getHttpContext());
// Resample the bullet image to be consistent with 'auto' sized images
// See also Image::get_min_max_width
// Tested php ver: value measured in px, suffix "px" not in value: rtrim unnecessary.
$dpi = $this->_dompdf->getOptions()->getDpi();
$this->_width = ((float)rtrim($width, "px") * 72) / $dpi;
$this->_height = ((float)rtrim($height, "px") * 72) / $dpi;
//If an image is taller as the containing block/box, the box should be extended.
//Neighbour elements are overwriting the overlapping image areas.
//Todo: Where can the box size be extended?
//Code below has no effect.
//See block_frame_reflower _calculate_restricted_height
//See generated_frame_reflower, Dompdf:render() "list-item", "-dompdf-list-bullet"S.
//Leave for now
//if ($style->min_height < $this->_height ) {
// $style->min_height = $this->_height;
//}
//$style->height = "auto";
}
/**
* Return the bullet's width
*
* @return int
*/
function get_width()
{
//ignore image width, use same width as on predefined bullet ListBullet
//for proper alignment of bullet image and text. Allow image to not fitting on left border.
//This controls the distance between bullet image and text
//return $this->_width;
return $this->_frame->get_style()->get_font_size() * ListBullet::BULLET_SIZE +
2 * ListBullet::BULLET_PADDING;
}
/**
* Return the bullet's height
*
* @return int
*/
function get_height()
{
//based on image height
return $this->_height;
}
/**
* Override get_margin_width
*
* @return int
*/
function get_margin_width()
{
//ignore image width, use same width as on predefined bullet ListBullet
//for proper alignment of bullet image and text. Allow image to not fitting on left border.
//This controls the extra indentation of text to make room for the bullet image.
//Here use actual image size, not predefined bullet size
//return $this->_frame->get_style()->get_font_size()*ListBullet::BULLET_SIZE +
// 2 * ListBullet::BULLET_PADDING;
// Small hack to prevent indenting of list text
// Image Might not exist, then position like on list_bullet_frame_decorator fallback to none.
if ($this->_frame->get_style()->list_style_position === "outside" || $this->_width == 0) {
return 0;
}
//This aligns the "inside" image position with the text.
//The text starts to the right of the image.
//Between the image and the text there is an added margin of image width.
//Where this comes from is unknown.
//The corresponding ListBullet sets a smaller margin. bullet size?
return $this->_width + 2 * ListBullet::BULLET_PADDING;
}
/**
* Override get_margin_height()
*
* @return int
*/
function get_margin_height()
{
//Hits only on "inset" lists items, to increase height of box
//based on image height
return $this->_height + 2 * ListBullet::BULLET_PADDING;
}
/**
* Return image url
*
* @return string
*/
function get_image_url()
{
return $this->_img->get_image_url();
}
}

View File

@ -1,398 +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\Cellmap;
use DOMNode;
use Dompdf\Dompdf;
use Dompdf\Frame;
use Dompdf\Frame\Factory;
/**
* Decorates Frames for table layout
*
* @package dompdf
*/
class Table extends AbstractFrameDecorator
{
public static $VALID_CHILDREN = array(
"table-row-group",
"table-row",
"table-header-group",
"table-footer-group",
"table-column",
"table-column-group",
"table-caption",
"table-cell"
);
public static $ROW_GROUPS = array(
'table-row-group',
'table-header-group',
'table-footer-group'
);
/**
* The Cellmap object for this table. The cellmap maps table cells
* to rows and columns, and aids in calculating column widths.
*
* @var \Dompdf\Cellmap
*/
protected $_cellmap;
/**
* The minimum width of the table, in pt
*
* @var float
*/
protected $_min_width;
/**
* The maximum width of the table, in pt
*
* @var float
*/
protected $_max_width;
/**
* Table header rows. Each table header is duplicated when a table
* spans pages.
*
* @var array
*/
protected $_headers;
/**
* Table footer rows. Each table footer is duplicated when a table
* spans pages.
*
* @var array
*/
protected $_footers;
/**
* Class constructor
*
* @param Frame $frame the frame to decorate
* @param Dompdf $dompdf
*/
public function __construct(Frame $frame, Dompdf $dompdf)
{
parent::__construct($frame, $dompdf);
$this->_cellmap = new Cellmap($this);
if ($frame->get_style()->table_layout === "fixed") {
$this->_cellmap->set_layout_fixed(true);
}
$this->_min_width = null;
$this->_max_width = null;
$this->_headers = array();
$this->_footers = array();
}
public function reset()
{
parent::reset();
$this->_cellmap->reset();
$this->_min_width = null;
$this->_max_width = null;
$this->_headers = array();
$this->_footers = array();
$this->_reflower->reset();
}
//........................................................................
/**
* split the table at $row. $row and all subsequent rows will be
* added to the clone. This method is overidden in order to remove
* frames from the cellmap properly.
*
* @param Frame $child
* @param bool $force_pagebreak
*
* @return void
*/
public function split(Frame $child = null, $force_pagebreak = false)
{
if (is_null($child)) {
parent::split();
return;
}
// If $child is a header or if it is the first non-header row, do
// not duplicate headers, simply move the table to the next page.
if (count($this->_headers) && !in_array($child, $this->_headers, true) &&
!in_array($child->get_prev_sibling(), $this->_headers, true)
) {
$first_header = null;
// Insert copies of the table headers before $child
foreach ($this->_headers as $header) {
$new_header = $header->deep_copy();
if (is_null($first_header)) {
$first_header = $new_header;
}
$this->insert_child_before($new_header, $child);
}
parent::split($first_header);
} elseif (in_array($child->get_style()->display, self::$ROW_GROUPS)) {
// Individual rows should have already been handled
parent::split($child);
} else {
$iter = $child;
while ($iter) {
$this->_cellmap->remove_row($iter);
$iter = $iter->get_next_sibling();
}
parent::split($child);
}
}
/**
* Return a copy of this frame with $node as its node
*
* @param DOMNode $node
*
* @return Frame
*/
public function copy(DOMNode $node)
{
$deco = parent::copy($node);
// In order to keep columns' widths through pages
$deco->_cellmap->set_columns($this->_cellmap->get_columns());
$deco->_cellmap->lock_columns();
return $deco;
}
/**
* Static function to locate the parent table of a frame
*
* @param Frame $frame
*
* @return Table the table that is an ancestor of $frame
*/
public static function find_parent_table(Frame $frame)
{
while ($frame = $frame->get_parent()) {
if ($frame->is_table()) {
break;
}
}
return $frame;
}
/**
* Return this table's Cellmap
*
* @return \Dompdf\Cellmap
*/
public function get_cellmap()
{
return $this->_cellmap;
}
/**
* Return the minimum width of this table
*
* @return float
*/
public function get_min_width()
{
return $this->_min_width;
}
/**
* Return the maximum width of this table
*
* @return float
*/
public function get_max_width()
{
return $this->_max_width;
}
/**
* Set the minimum width of the table
*
* @param float $width the new minimum width
*/
public function set_min_width($width)
{
$this->_min_width = $width;
}
/**
* Set the maximum width of the table
*
* @param float $width the new maximum width
*/
public function set_max_width($width)
{
$this->_max_width = $width;
}
/**
* Restructure tree so that the table has the correct structure.
* Invalid children (i.e. all non-table-rows) are moved below the
* table.
*
* @fixme #1363 Method has some bugs. $table_row has not been initialized and lookup most likely could return an
* array of Style instead a Style Object
*/
public function normalise()
{
// Store frames generated by invalid tags and move them outside the table
$erroneous_frames = array();
$anon_row = false;
$iter = $this->get_first_child();
while ($iter) {
$child = $iter;
$iter = $iter->get_next_sibling();
$display = $child->get_style()->display;
if ($anon_row) {
if ($display === "table-row") {
// Add the previous anonymous row
$this->insert_child_before($table_row, $child);
$table_row->normalise();
$child->normalise();
$this->_cellmap->add_row();
$anon_row = false;
continue;
}
// add the child to the anonymous row
$table_row->append_child($child);
continue;
} else {
if ($display === "table-row") {
$child->normalise();
continue;
}
if ($display === "table-cell") {
$css = $this->get_style()->get_stylesheet();
// Create an anonymous table row group
$tbody = $this->get_node()->ownerDocument->createElement("tbody");
$frame = new Frame($tbody);
$style = $css->create_style();
$style->inherit($this->get_style());
// Lookup styles for tbody tags. If the user wants styles to work
// better, they should make the tbody explicit... I'm not going to
// try to guess what they intended.
if ($tbody_style = $css->lookup("tbody")) {
$style->merge($tbody_style);
}
$style->display = 'table-row-group';
// Okay, I have absolutely no idea why I need this clone here, but
// if it's omitted, php (as of 2004-07-28) segfaults.
$frame->set_style($style);
$table_row_group = Factory::decorate_frame($frame, $this->_dompdf, $this->_root);
// Create an anonymous table row
$tr = $this->get_node()->ownerDocument->createElement("tr");
$frame = new Frame($tr);
$style = $css->create_style();
$style->inherit($this->get_style());
// Lookup styles for tr tags. If the user wants styles to work
// better, they should make the tr explicit... I'm not going to
// try to guess what they intended.
if ($tr_style = $css->lookup("tr")) {
$style->merge($tr_style);
}
$style->display = 'table-row';
// Okay, I have absolutely no idea why I need this clone here, but
// if it's omitted, php (as of 2004-07-28) segfaults.
$frame->set_style(clone $style);
$table_row = Factory::decorate_frame($frame, $this->_dompdf, $this->_root);
// Add the cell to the row
$table_row->append_child($child, true);
// Add the tr to the tbody
$table_row_group->append_child($table_row, true);
$anon_row = true;
continue;
}
if (!in_array($display, self::$VALID_CHILDREN)) {
$erroneous_frames[] = $child;
continue;
}
// Normalise other table parts (i.e. row groups)
foreach ($child->get_children() as $grandchild) {
if ($grandchild->get_style()->display === "table-row") {
$grandchild->normalise();
}
}
// Add headers and footers
if ($display === "table-header-group") {
$this->_headers[] = $child;
} elseif ($display === "table-footer-group") {
$this->_footers[] = $child;
}
}
}
if ($anon_row && $table_row_group instanceof AbstractFrameDecorator) {
// Add the row to the table
$this->_frame->append_child($table_row_group->_frame);
$table_row->normalise();
}
foreach ($erroneous_frames as $frame) {
$this->move_after($frame);
}
}
//........................................................................
/**
* Moves the specified frame and it's corresponding node outside of
* the table.
*
* @param Frame $frame the frame to move
*/
public function move_after(Frame $frame)
{
$this->get_parent()->insert_child_after($frame, $this);
}
}

View File

@ -1,68 +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.
*/
function normalise()
{
// Find our table parent
$p = TableFrameDecorator::find_parent_table($this);
$erroneous_frames = array();
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);
}
}
function split(Frame $child = null, $force_pagebreak = false)
{
$this->_already_pushed = true;
if (is_null($child)) {
parent::split();
return;
}
parent::split($child, $force_pagebreak);
}
}

View File

@ -1,529 +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\FrameReflower;
use Dompdf\Adapter\CPDF;
use Dompdf\Css\Style;
use Dompdf\Dompdf;
use Dompdf\Helpers;
use Dompdf\Frame;
use Dompdf\FrameDecorator\Block;
use Dompdf\Frame\Factory;
/**
* Base reflower class
*
* Reflower objects are responsible for determining the width and height of
* individual frames. They also create line and page breaks as necessary.
*
* @package dompdf
*/
abstract class AbstractFrameReflower
{
/**
* Frame for this reflower
*
* @var Frame
*/
protected $_frame;
/**
* Cached min/max size
*
* @var array
*/
protected $_min_max_cache;
/**
* AbstractFrameReflower constructor.
* @param Frame $frame
*/
function __construct(Frame $frame)
{
$this->_frame = $frame;
$this->_min_max_cache = null;
}
function dispose()
{
}
/**
* @return Dompdf
*/
function get_dompdf()
{
return $this->_frame->get_dompdf();
}
/**
* Collapse frames margins
* http://www.w3.org/TR/CSS2/box.html#collapsing-margins
*/
protected function _collapse_margins()
{
$frame = $this->_frame;
$cb = $frame->get_containing_block();
$style = $frame->get_style();
// Margins of float/absolutely positioned/inline-block elements do not collapse.
if (!$frame->is_in_flow() || $frame->is_inline_block()) {
return;
}
$t = $style->length_in_pt($style->margin_top, $cb["h"]);
$b = $style->length_in_pt($style->margin_bottom, $cb["h"]);
// Handle 'auto' values
if ($t === "auto") {
$style->margin_top = "0pt";
$t = 0;
}
if ($b === "auto") {
$style->margin_bottom = "0pt";
$b = 0;
}
// Collapse vertical margins:
$n = $frame->get_next_sibling();
if ( $n && !$n->is_block() & !$n->is_table() ) {
while ($n = $n->get_next_sibling()) {
if ($n->is_block() || $n->is_table()) {
break;
}
if (!$n->get_first_child()) {
$n = null;
break;
}
}
}
if ($n) {
$n_style = $n->get_style();
$n_t = (float)$n_style->length_in_pt($n_style->margin_top, $cb["h"]);
$b = $this->_get_collapsed_margin_length($b, $n_t);
$style->margin_bottom = $b . "pt";
$n_style->margin_top = "0pt";
}
// Collapse our first child's margin, if there is no border or padding
if ($style->border_top_width == 0 && $style->length_in_pt($style->padding_top) == 0) {
$f = $this->_frame->get_first_child();
if ( $f && !$f->is_block() && !$f->is_table() ) {
while ( $f = $f->get_next_sibling() ) {
if ( $f->is_block() || $f->is_table() ) {
break;
}
if ( !$f->get_first_child() ) {
$f = null;
break;
}
}
}
// Margin are collapsed only between block-level boxes
if ($f) {
$f_style = $f->get_style();
$f_t = (float)$f_style->length_in_pt($f_style->margin_top, $cb["h"]);
$t = $this->_get_collapsed_margin_length($t, $f_t);
$style->margin_top = $t."pt";
$f_style->margin_top = "0pt";
}
}
// Collapse our last child's margin, if there is no border or padding
if ($style->border_bottom_width == 0 && $style->length_in_pt($style->padding_bottom) == 0) {
$l = $this->_frame->get_last_child();
if ( $l && !$l->is_block() && !$l->is_table() ) {
while ( $l = $l->get_prev_sibling() ) {
if ( $l->is_block() || $l->is_table() ) {
break;
}
if ( !$l->get_last_child() ) {
$l = null;
break;
}
}
}
// Margin are collapsed only between block-level boxes
if ($l) {
$l_style = $l->get_style();
$l_b = (float)$l_style->length_in_pt($l_style->margin_bottom, $cb["h"]);
$b = $this->_get_collapsed_margin_length($b, $l_b);
$style->margin_bottom = $b."pt";
$l_style->margin_bottom = "0pt";
}
}
}
/**
* Get the combined (collapsed) length of two adjoining margins.
*
* See http://www.w3.org/TR/CSS2/box.html#collapsing-margins.
*
* @param number $length1
* @param number $length2
* @return number
*/
private function _get_collapsed_margin_length($length1, $length2)
{
if ($length1 < 0 && $length2 < 0) {
return min($length1, $length2); // min(x, y) = - max(abs(x), abs(y)), if x < 0 && y < 0
}
if ($length1 < 0 || $length2 < 0) {
return $length1 + $length2; // x + y = x - abs(y), if y < 0
}
return max($length1, $length2);
}
/**
* @param Block|null $block
* @return mixed
*/
abstract function reflow(Block $block = null);
/**
* Required for table layout: Returns an array(0 => min, 1 => max, "min"
* => min, "max" => max) of the minimum and maximum widths of this frame.
* This provides a basic implementation. Child classes should override
* this if necessary.
*
* @return array|null
*/
function get_min_max_width()
{
if (!is_null($this->_min_max_cache)) {
return $this->_min_max_cache;
}
$style = $this->_frame->get_style();
// Account for margins & padding
$dims = array($style->padding_left,
$style->padding_right,
$style->border_left_width,
$style->border_right_width,
$style->margin_left,
$style->margin_right);
$cb_w = $this->_frame->get_containing_block("w");
$delta = (float)$style->length_in_pt($dims, $cb_w);
// Handle degenerate case
if (!$this->_frame->get_first_child()) {
return $this->_min_max_cache = array(
$delta, $delta,
"min" => $delta,
"max" => $delta,
);
}
$low = array();
$high = array();
for ($iter = $this->_frame->get_children()->getIterator(); $iter->valid(); $iter->next()) {
$inline_min = 0;
$inline_max = 0;
// Add all adjacent inline widths together to calculate max width
while ($iter->valid() && in_array($iter->current()->get_style()->display, Style::$INLINE_TYPES)) {
$child = $iter->current();
$minmax = $child->get_min_max_width();
if (in_array($iter->current()->get_style()->white_space, array("pre", "nowrap"))) {
$inline_min += $minmax["min"];
} else {
$low[] = $minmax["min"];
}
$inline_max += $minmax["max"];
$iter->next();
}
if ($inline_max > 0) {
$high[] = $inline_max;
}
if ($inline_min > 0) {
$low[] = $inline_min;
}
if ($iter->valid()) {
list($low[], $high[]) = $iter->current()->get_min_max_width();
continue;
}
}
$min = count($low) ? max($low) : 0;
$max = count($high) ? max($high) : 0;
// Use specified width if it is greater than the minimum defined by the
// content. If the width is a percentage ignore it for now.
$width = $style->width;
if ($width !== "auto" && !Helpers::is_percent($width)) {
$width = (float)$style->length_in_pt($width, $cb_w);
if ($min < $width) {
$min = $width;
}
if ($max < $width) {
$max = $width;
}
}
$min += $delta;
$max += $delta;
return $this->_min_max_cache = array($min, $max, "min" => $min, "max" => $max);
}
/**
* Parses a CSS string containing quotes and escaped hex characters
*
* @param $string string The CSS string to parse
* @param $single_trim
* @return string
*/
protected function _parse_string($string, $single_trim = false)
{
if ($single_trim) {
$string = preg_replace('/^[\"\']/', "", $string);
$string = preg_replace('/[\"\']$/', "", $string);
} else {
$string = trim($string, "'\"");
}
$string = str_replace(array("\\\n", '\\"', "\\'"),
array("", '"', "'"), $string);
// Convert escaped hex characters into ascii characters (e.g. \A => newline)
$string = preg_replace_callback("/\\\\([0-9a-fA-F]{0,6})/",
function ($matches) { return \Dompdf\Helpers::unichr(hexdec($matches[1])); },
$string);
return $string;
}
/**
* Parses a CSS "quotes" property
*
* @return array|null An array of pairs of quotes
*/
protected function _parse_quotes()
{
// Matches quote types
$re = '/(\'[^\']*\')|(\"[^\"]*\")/';
$quotes = $this->_frame->get_style()->quotes;
// split on spaces, except within quotes
if (!preg_match_all($re, "$quotes", $matches, PREG_SET_ORDER)) {
return null;
}
$quotes_array = array();
foreach ($matches as $_quote) {
$quotes_array[] = $this->_parse_string($_quote[0], true);
}
if (empty($quotes_array)) {
$quotes_array = array('"', '"');
}
return array_chunk($quotes_array, 2);
}
/**
* Parses the CSS "content" property
*
* @return string|null The resulting string
*/
protected function _parse_content()
{
// Matches generated content
$re = "/\n" .
"\s(counters?\\([^)]*\\))|\n" .
"\A(counters?\\([^)]*\\))|\n" .
"\s([\"']) ( (?:[^\"']|\\\\[\"'])+ )(?<!\\\\)\\3|\n" .
"\A([\"']) ( (?:[^\"']|\\\\[\"'])+ )(?<!\\\\)\\5|\n" .
"\s([^\s\"']+)|\n" .
"\A([^\s\"']+)\n" .
"/xi";
$content = $this->_frame->get_style()->content;
$quotes = $this->_parse_quotes();
// split on spaces, except within quotes
if (!preg_match_all($re, $content, $matches, PREG_SET_ORDER)) {
return null;
}
$text = "";
foreach ($matches as $match) {
if (isset($match[2]) && $match[2] !== "") {
$match[1] = $match[2];
}
if (isset($match[6]) && $match[6] !== "") {
$match[4] = $match[6];
}
if (isset($match[8]) && $match[8] !== "") {
$match[7] = $match[8];
}
if (isset($match[1]) && $match[1] !== "") {
// counters?(...)
$match[1] = mb_strtolower(trim($match[1]));
// Handle counter() references:
// http://www.w3.org/TR/CSS21/generate.html#content
$i = mb_strpos($match[1], ")");
if ($i === false) {
continue;
}
preg_match('/(counters?)(^\()*?\(\s*([^\s,]+)\s*(,\s*["\']?([^"\'\)]*)["\']?\s*(,\s*([^\s)]+)\s*)?)?\)/i', $match[1], $args);
$counter_id = $args[3];
if (strtolower($args[1]) == 'counter') {
// counter(name [,style])
if (isset($args[5])) {
$type = trim($args[5]);
} else {
$type = null;
}
$p = $this->_frame->lookup_counter_frame($counter_id);
$text .= $p->counter_value($counter_id, $type);
} else if (strtolower($args[1]) == 'counters') {
// counters(name, string [,style])
if (isset($args[5])) {
$string = $this->_parse_string($args[5]);
} else {
$string = "";
}
if (isset($args[7])) {
$type = trim($args[7]);
} else {
$type = null;
}
$p = $this->_frame->lookup_counter_frame($counter_id);
$tmp = array();
while ($p) {
// We only want to use the counter values when they actually increment the counter
if (array_key_exists($counter_id, $p->_counters)) {
array_unshift($tmp, $p->counter_value($counter_id, $type));
}
$p = $p->lookup_counter_frame($counter_id);
}
$text .= implode($string, $tmp);
} else {
// countertops?
continue;
}
} else if (isset($match[4]) && $match[4] !== "") {
// String match
$text .= $this->_parse_string($match[4]);
} else if (isset($match[7]) && $match[7] !== "") {
// Directive match
if ($match[7] === "open-quote") {
// FIXME: do something here
$text .= $quotes[0][0];
} else if ($match[7] === "close-quote") {
// FIXME: do something else here
$text .= $quotes[0][1];
} else if ($match[7] === "no-open-quote") {
// FIXME:
} else if ($match[7] === "no-close-quote") {
// FIXME:
} else if (mb_strpos($match[7], "attr(") === 0) {
$i = mb_strpos($match[7], ")");
if ($i === false) {
continue;
}
$attr = mb_substr($match[7], 5, $i - 5);
if ($attr == "") {
continue;
}
$text .= $this->_frame->get_parent()->get_node()->getAttribute($attr);
} else {
continue;
}
}
}
return $text;
}
/**
* Sets the generated content of a generated frame
*/
protected function _set_content()
{
$frame = $this->_frame;
$style = $frame->get_style();
// if the element was pushed to a new page use the saved counter value, otherwise use the CSS reset value
if ($style->counter_reset && ($reset = $style->counter_reset) !== "none") {
$vars = preg_split('/\s+/', trim($reset), 2);
$frame->reset_counter($vars[0], (isset($frame->_counters['__' . $vars[0]]) ? $frame->_counters['__' . $vars[0]] : (isset($vars[1]) ? $vars[1] : 0)));
}
if ($style->counter_increment && ($increment = $style->counter_increment) !== "none") {
$frame->increment_counters($increment);
}
if ($style->content && $frame->get_node()->nodeName === "dompdf_generated") {
$content = $this->_parse_content();
// add generated content to the font subset
// FIXME: This is currently too late because the font subset has already been generated.
// See notes in issue #750.
if ($frame->get_dompdf()->getOptions()->getIsFontSubsettingEnabled() && $frame->get_dompdf()->get_canvas() instanceof CPDF) {
$frame->get_dompdf()->get_canvas()->register_string_subset($style->font_family, $content);
}
$node = $frame->get_node()->ownerDocument->createTextNode($content);
$new_style = $style->get_stylesheet()->create_style();
$new_style->inherit($style);
$new_frame = new Frame($node);
$new_frame->set_style($new_style);
Factory::decorate_frame($new_frame, $frame->get_dompdf(), $frame->get_root());
$frame->append_child($new_frame);
}
}
/**
* Determine current frame width based on contents
*
* @return float
*/
public function calculate_auto_width()
{
return $this->_frame->get_margin_width();
}
}

View File

@ -1,948 +0,0 @@
<?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
*/
namespace Dompdf\FrameReflower;
use Dompdf\Frame;
use Dompdf\FrameDecorator\Block as BlockFrameDecorator;
use Dompdf\FrameDecorator\TableCell as TableCellFrameDecorator;
use Dompdf\FrameDecorator\Text as TextFrameDecorator;
use Dompdf\Exception;
use Dompdf\Css\Style;
/**
* Reflows block frames
*
* @package dompdf
*/
class Block extends AbstractFrameReflower
{
// Minimum line width to justify, as fraction of available width
const MIN_JUSTIFY_WIDTH = 0.80;
/**
* @var BlockFrameDecorator
*/
protected $_frame;
function __construct(BlockFrameDecorator $frame)
{
parent::__construct($frame);
}
/**
* Calculate the ideal used value for the width property as per:
* http://www.w3.org/TR/CSS21/visudet.html#Computing_widths_and_margins
*
* @param float $width
*
* @return array
*/
protected function _calculate_width($width)
{
$frame = $this->_frame;
$style = $frame->get_style();
$w = $frame->get_containing_block("w");
if ($style->position === "fixed") {
$w = $frame->get_parent()->get_containing_block("w");
}
$rm = $style->length_in_pt($style->margin_right, $w);
$lm = $style->length_in_pt($style->margin_left, $w);
$left = $style->length_in_pt($style->left, $w);
$right = $style->length_in_pt($style->right, $w);
// Handle 'auto' values
$dims = array($style->border_left_width,
$style->border_right_width,
$style->padding_left,
$style->padding_right,
$width !== "auto" ? $width : 0,
$rm !== "auto" ? $rm : 0,
$lm !== "auto" ? $lm : 0);
// absolutely positioned boxes take the 'left' and 'right' properties into account
if ($frame->is_absolute()) {
$absolute = true;
$dims[] = $left !== "auto" ? $left : 0;
$dims[] = $right !== "auto" ? $right : 0;
} else {
$absolute = false;
}
$sum = (float)$style->length_in_pt($dims, $w);
// Compare to the containing block
$diff = $w - $sum;
if ($diff > 0) {
if ($absolute) {
// resolve auto properties: see
// http://www.w3.org/TR/CSS21/visudet.html#abs-non-replaced-width
if ($width === "auto" && $left === "auto" && $right === "auto") {
if ($lm === "auto") {
$lm = 0;
}
if ($rm === "auto") {
$rm = 0;
}
// Technically, the width should be "shrink-to-fit" i.e. based on the
// preferred width of the content... a little too costly here as a
// special case. Just get the width to take up the slack:
$left = 0;
$right = 0;
$width = $diff;
} else if ($width === "auto") {
if ($lm === "auto") {
$lm = 0;
}
if ($rm === "auto") {
$rm = 0;
}
if ($left === "auto") {
$left = 0;
}
if ($right === "auto") {
$right = 0;
}
$width = $diff;
} else if ($left === "auto") {
if ($lm === "auto") {
$lm = 0;
}
if ($rm === "auto") {
$rm = 0;
}
if ($right === "auto") {
$right = 0;
}
$left = $diff;
} else if ($right === "auto") {
if ($lm === "auto") {
$lm = 0;
}
if ($rm === "auto") {
$rm = 0;
}
$right = $diff;
}
} else {
// Find auto properties and get them to take up the slack
if ($width === "auto") {
$width = $diff;
} else if ($lm === "auto" && $rm === "auto") {
$lm = $rm = round($diff / 2);
} else if ($lm === "auto") {
$lm = $diff;
} else if ($rm === "auto") {
$rm = $diff;
}
}
} else if ($diff < 0) {
// We are over constrained--set margin-right to the difference
$rm = $diff;
}
return array(
"width" => $width,
"margin_left" => $lm,
"margin_right" => $rm,
"left" => $left,
"right" => $right,
);
}
/**
* Call the above function, but resolve max/min widths
*
* @throws Exception
* @return array
*/
protected function _calculate_restricted_width()
{
$frame = $this->_frame;
$style = $frame->get_style();
$cb = $frame->get_containing_block();
if ($style->position === "fixed") {
$cb = $frame->get_root()->get_containing_block();
}
//if ( $style->position === "absolute" )
// $cb = $frame->find_positionned_parent()->get_containing_block();
if (!isset($cb["w"])) {
throw new Exception("Box property calculation requires containing block width");
}
// Treat width 100% as auto
if ($style->width === "100%") {
$width = "auto";
} else {
$width = $style->length_in_pt($style->width, $cb["w"]);
}
$calculate_width = $this->_calculate_width($width);
$margin_left = $calculate_width['margin_left'];
$margin_right = $calculate_width['margin_right'];
$width = $calculate_width['width'];
$left = $calculate_width['left'];
$right = $calculate_width['right'];
// Handle min/max width
$min_width = $style->length_in_pt($style->min_width, $cb["w"]);
$max_width = $style->length_in_pt($style->max_width, $cb["w"]);
if ($max_width !== "none" && $min_width > $max_width) {
list($max_width, $min_width) = array($min_width, $max_width);
}
if ($max_width !== "none" && $width > $max_width) {
extract($this->_calculate_width($max_width));
}
if ($width < $min_width) {
$calculate_width = $this->_calculate_width($min_width);
$margin_left = $calculate_width['margin_left'];
$margin_right = $calculate_width['margin_right'];
$width = $calculate_width['width'];
$left = $calculate_width['left'];
$right = $calculate_width['right'];
}
return array($width, $margin_left, $margin_right, $left, $right);
}
/**
* Determine the unrestricted height of content within the block
* not by adding each line's height, but by getting the last line's position.
* This because lines could have been pushed lower by a clearing element.
*
* @return float
*/
protected function _calculate_content_height()
{
$height = 0;
$lines = $this->_frame->get_line_boxes();
if (count($lines) > 0) {
$last_line = end($lines);
$content_box = $this->_frame->get_content_box();
$height = $last_line->y + $last_line->h - $content_box["y"];
}
return $height;
}
/**
* Determine the frame's restricted height
*
* @return array
*/
protected function _calculate_restricted_height()
{
$frame = $this->_frame;
$style = $frame->get_style();
$content_height = $this->_calculate_content_height();
$cb = $frame->get_containing_block();
$height = $style->length_in_pt($style->height, $cb["h"]);
$top = $style->length_in_pt($style->top, $cb["h"]);
$bottom = $style->length_in_pt($style->bottom, $cb["h"]);
$margin_top = $style->length_in_pt($style->margin_top, $cb["h"]);
$margin_bottom = $style->length_in_pt($style->margin_bottom, $cb["h"]);
if ($frame->is_absolute()) {
// see http://www.w3.org/TR/CSS21/visudet.html#abs-non-replaced-height
$dims = array($top !== "auto" ? $top : 0,
$style->margin_top !== "auto" ? $style->margin_top : 0,
$style->padding_top,
$style->border_top_width,
$height !== "auto" ? $height : 0,
$style->border_bottom_width,
$style->padding_bottom,
$style->margin_bottom !== "auto" ? $style->margin_bottom : 0,
$bottom !== "auto" ? $bottom : 0);
$sum = (float)$style->length_in_pt($dims, $cb["h"]);
$diff = $cb["h"] - $sum;
if ($diff > 0) {
if ($height === "auto" && $top === "auto" && $bottom === "auto") {
if ($margin_top === "auto") {
$margin_top = 0;
}
if ($margin_bottom === "auto") {
$margin_bottom = 0;
}
$height = $diff;
} else if ($height === "auto" && $top === "auto") {
if ($margin_top === "auto") {
$margin_top = 0;
}
if ($margin_bottom === "auto") {
$margin_bottom = 0;
}
$height = $content_height;
$top = $diff - $content_height;
} else if ($height === "auto" && $bottom === "auto") {
if ($margin_top === "auto") {
$margin_top = 0;
}
if ($margin_bottom === "auto") {
$margin_bottom = 0;
}
$height = $content_height;
$bottom = $diff - $content_height;
} else if ($top === "auto" && $bottom === "auto") {
if ($margin_top === "auto") {
$margin_top = 0;
}
if ($margin_bottom === "auto") {
$margin_bottom = 0;
}
$bottom = $diff;
} else if ($top === "auto") {
if ($margin_top === "auto") {
$margin_top = 0;
}
if ($margin_bottom === "auto") {
$margin_bottom = 0;
}
$top = $diff;
} else if ($height === "auto") {
if ($margin_top === "auto") {
$margin_top = 0;
}
if ($margin_bottom === "auto") {
$margin_bottom = 0;
}
$height = $diff;
} else if ($bottom === "auto") {
if ($margin_top === "auto") {
$margin_top = 0;
}
if ($margin_bottom === "auto") {
$margin_bottom = 0;
}
$bottom = $diff;
} else {
if ($style->overflow === "visible") {
// set all autos to zero
if ($margin_top === "auto") {
$margin_top = 0;
}
if ($margin_bottom === "auto") {
$margin_bottom = 0;
}
if ($top === "auto") {
$top = 0;
}
if ($bottom === "auto") {
$bottom = 0;
}
if ($height === "auto") {
$height = $content_height;
}
}
// FIXME: overflow hidden
}
}
} else {
// Expand the height if overflow is visible
if ($height === "auto" && $content_height > $height /* && $style->overflow === "visible" */) {
$height = $content_height;
}
// FIXME: this should probably be moved to a seperate function as per
// _calculate_restricted_width
// Only handle min/max height if the height is independent of the frame's content
if (!($style->overflow === "visible" || ($style->overflow === "hidden" && $height === "auto"))) {
$min_height = $style->min_height;
$max_height = $style->max_height;
if (isset($cb["h"])) {
$min_height = $style->length_in_pt($min_height, $cb["h"]);
$max_height = $style->length_in_pt($max_height, $cb["h"]);
} else if (isset($cb["w"])) {
if (mb_strpos($min_height, "%") !== false) {
$min_height = 0;
} else {
$min_height = $style->length_in_pt($min_height, $cb["w"]);
}
if (mb_strpos($max_height, "%") !== false) {
$max_height = "none";
} else {
$max_height = $style->length_in_pt($max_height, $cb["w"]);
}
}
if ($max_height !== "none" && $min_height > $max_height) {
// Swap 'em
list($max_height, $min_height) = array($min_height, $max_height);
}
if ($max_height !== "none" && $height > $max_height) {
$height = $max_height;
}
if ($height < $min_height) {
$height = $min_height;
}
}
}
return array($height, $margin_top, $margin_bottom, $top, $bottom);
}
/**
* Adjust the justification of each of our lines.
* http://www.w3.org/TR/CSS21/text.html#propdef-text-align
*/
protected function _text_align()
{
$style = $this->_frame->get_style();
$w = $this->_frame->get_containing_block("w");
$width = (float)$style->length_in_pt($style->width, $w);
switch ($style->text_align) {
default:
case "left":
foreach ($this->_frame->get_line_boxes() as $line) {
if (!$line->left) {
continue;
}
foreach ($line->get_frames() as $frame) {
if ($frame instanceof BlockFrameDecorator) {
continue;
}
$frame->set_position($frame->get_position("x") + $line->left);
}
}
return;
case "right":
foreach ($this->_frame->get_line_boxes() as $line) {
// Move each child over by $dx
$dx = $width - $line->w - $line->right;
foreach ($line->get_frames() as $frame) {
// Block frames are not aligned by text-align
if ($frame instanceof BlockFrameDecorator) {
continue;
}
$frame->set_position($frame->get_position("x") + $dx);
}
}
break;
case "justify":
// We justify all lines except the last one
$lines = $this->_frame->get_line_boxes(); // needs to be a variable (strict standards)
$last_line = array_pop($lines);
foreach ($lines as $i => $line) {
if ($line->br) {
unset($lines[$i]);
}
}
// One space character's width. Will be used to get a more accurate spacing
$space_width = $this->get_dompdf()->getFontMetrics()->getTextWidth(" ", $style->font_family, $style->font_size);
foreach ($lines as $line) {
if ($line->left) {
foreach ($line->get_frames() as $frame) {
if (!$frame instanceof TextFrameDecorator) {
continue;
}
$frame->set_position($frame->get_position("x") + $line->left);
}
}
// Set the spacing for each child
if ($line->wc > 1) {
$spacing = ($width - ($line->left + $line->w + $line->right) + $space_width) / ($line->wc - 1);
} else {
$spacing = 0;
}
$dx = 0;
foreach ($line->get_frames() as $frame) {
if (!$frame instanceof TextFrameDecorator) {
continue;
}
$text = $frame->get_text();
$spaces = mb_substr_count($text, " ");
$char_spacing = (float)$style->length_in_pt($style->letter_spacing);
$_spacing = $spacing + $char_spacing;
$frame->set_position($frame->get_position("x") + $dx);
$frame->set_text_spacing($_spacing);
$dx += $spaces * $_spacing;
}
// The line (should) now occupy the entire width
$line->w = $width;
}
// Adjust the last line if necessary
if ($last_line->left) {
foreach ($last_line->get_frames() as $frame) {
if ($frame instanceof BlockFrameDecorator) {
continue;
}
$frame->set_position($frame->get_position("x") + $last_line->left);
}
}
break;
case "center":
case "centre":
foreach ($this->_frame->get_line_boxes() as $line) {
// Centre each line by moving each frame in the line by:
$dx = ($width + $line->left - $line->w - $line->right) / 2;
foreach ($line->get_frames() as $frame) {
// Block frames are not aligned by text-align
if ($frame instanceof BlockFrameDecorator) {
continue;
}
$frame->set_position($frame->get_position("x") + $dx);
}
}
break;
}
}
/**
* Align inline children vertically.
* Aligns each child vertically after each line is reflowed
*/
function vertical_align()
{
$canvas = null;
foreach ($this->_frame->get_line_boxes() as $line) {
$height = $line->h;
foreach ($line->get_frames() as $frame) {
$style = $frame->get_style();
$isInlineBlock = (
'-dompdf-image' === $style->display
|| 'inline-block' === $style->display
|| 'inline-table' === $style->display
);
if (!$isInlineBlock && $style->display !== "inline") {
continue;
}
if (!isset($canvas)) {
$canvas = $frame->get_root()->get_dompdf()->get_canvas();
}
$baseline = $canvas->get_font_baseline($style->font_family, $style->font_size);
$y_offset = 0;
//FIXME: The 0.8 ratio applied to the height is arbitrary (used to accommodate descenders?)
if($isInlineBlock) {
$lineFrames = $line->get_frames();
if (count($lineFrames) == 1) {
continue;
}
$frameBox = $frame->get_frame()->get_border_box();
$imageHeightDiff = $height * 0.8 - (float)$frameBox['h'];
$align = $frame->get_style()->vertical_align;
if (in_array($align, Style::$vertical_align_keywords) === true) {
switch ($align) {
case "middle":
$y_offset = $imageHeightDiff / 2;
break;
case "sub":
$y_offset = 0.3 * $height + $imageHeightDiff;
break;
case "super":
$y_offset = -0.2 * $height + $imageHeightDiff;
break;
case "text-top": // FIXME: this should be the height of the frame minus the height of the text
$y_offset = $height - (float)$style->length_in_pt($style->line_height, $style->font_size);
break;
case "top":
break;
case "text-bottom": // FIXME: align bottom of image with the descender?
case "bottom":
$y_offset = 0.3 * $height + $imageHeightDiff;
break;
case "baseline":
default:
$y_offset = $imageHeightDiff;
break;
}
} else {
$y_offset = $baseline - (float)$style->length_in_pt($align, $style->font_size) - (float)$frameBox['h'];
}
} else {
$parent = $frame->get_parent();
if ($parent instanceof TableCellFrameDecorator) {
$align = "baseline";
} else {
$align = $parent->get_style()->vertical_align;
}
if (in_array($align, Style::$vertical_align_keywords) === true) {
switch ($align) {
case "middle":
$y_offset = ($height * 0.8 - $baseline) / 2;
break;
case "sub":
$y_offset = $height * 0.8 - $baseline * 0.5;
break;
case "super":
$y_offset = $height * 0.8 - $baseline * 1.4;
break;
case "text-top":
case "top": // Not strictly accurate, but good enough for now
break;
case "text-bottom":
case "bottom":
$y_offset = $height * 0.8 - $baseline;
break;
case "baseline":
default:
$y_offset = $height * 0.8 - $baseline;
break;
}
} else {
$y_offset = $height * 0.8 - $baseline - (float)$style->length_in_pt($align, $style->font_size);
}
}
if ($y_offset !== 0) {
$frame->move(0, $y_offset);
}
}
}
}
/**
* @param Frame $child
*/
function process_clear(Frame $child)
{
$child_style = $child->get_style();
$root = $this->_frame->get_root();
// Handle "clear"
if ($child_style->clear !== "none") {
//TODO: this is a WIP for handling clear/float frames that are in between inline frames
if ($child->get_prev_sibling() !== null) {
$this->_frame->add_line();
}
if ($child_style->float !== "none" && $child->get_next_sibling()) {
$this->_frame->set_current_line_number($this->_frame->get_current_line_number() - 1);
}
$lowest_y = $root->get_lowest_float_offset($child);
// If a float is still applying, we handle it
if ($lowest_y) {
if ($child->is_in_flow()) {
$line_box = $this->_frame->get_current_line_box();
$line_box->y = $lowest_y + $child->get_margin_height();
$line_box->left = 0;
$line_box->right = 0;
}
$child->move(0, $lowest_y - $child->get_position("y"));
}
}
}
/**
* @param Frame $child
* @param float $cb_x
* @param float $cb_w
*/
function process_float(Frame $child, $cb_x, $cb_w)
{
$child_style = $child->get_style();
$root = $this->_frame->get_root();
// Handle "float"
if ($child_style->float !== "none") {
$root->add_floating_frame($child);
// Remove next frame's beginning whitespace
$next = $child->get_next_sibling();
if ($next && $next instanceof TextFrameDecorator) {
$next->set_text(ltrim($next->get_text()));
}
$line_box = $this->_frame->get_current_line_box();
list($old_x, $old_y) = $child->get_position();
$float_x = $cb_x;
$float_y = $old_y;
$float_w = $child->get_margin_width();
if ($child_style->clear === "none") {
switch ($child_style->float) {
case "left":
$float_x += $line_box->left;
break;
case "right":
$float_x += ($cb_w - $line_box->right - $float_w);
break;
}
} else {
if ($child_style->float === "right") {
$float_x += ($cb_w - $float_w);
}
}
if ($cb_w < $float_x + $float_w - $old_x) {
// TODO handle when floating elements don't fit
}
$line_box->get_float_offsets();
if ($child->_float_next_line) {
$float_y += $line_box->h;
}
$child->set_position($float_x, $float_y);
$child->move($float_x - $old_x, $float_y - $old_y, true);
}
}
/**
* @param BlockFrameDecorator $block
* @return mixed|void
*/
function reflow(BlockFrameDecorator $block = null)
{
// Check if a page break is forced
$page = $this->_frame->get_root();
$page->check_forced_page_break($this->_frame);
// Bail if the page is full
if ($page->is_full()) {
return;
}
// Generated content
$this->_set_content();
// Collapse margins if required
$this->_collapse_margins();
$style = $this->_frame->get_style();
$cb = $this->_frame->get_containing_block();
if ($style->position === "fixed") {
$cb = $this->_frame->get_root()->get_containing_block();
}
// Determine the constraints imposed by this frame: calculate the width
// of the content area:
list($w, $left_margin, $right_margin, $left, $right) = $this->_calculate_restricted_width();
// Store the calculated properties
$style->width = $w;
$style->margin_left = $left_margin;
$style->margin_right = $right_margin;
$style->left = $left;
$style->right = $right;
// Update the position
$this->_frame->position();
list($x, $y) = $this->_frame->get_position();
// Adjust the first line based on the text-indent property
$indent = (float)$style->length_in_pt($style->text_indent, $cb["w"]);
$this->_frame->increase_line_width($indent);
// Determine the content edge
$top = (float)$style->length_in_pt(array($style->margin_top,
$style->padding_top,
$style->border_top_width), $cb["h"]);
$bottom = (float)$style->length_in_pt(array($style->border_bottom_width,
$style->margin_bottom,
$style->padding_bottom), $cb["h"]);
$cb_x = $x + (float)$left_margin + (float)$style->length_in_pt(array($style->border_left_width,
$style->padding_left), $cb["w"]);
$cb_y = $y + $top;
$cb_h = ($cb["h"] + $cb["y"]) - $bottom - $cb_y;
// Set the y position of the first line in this block
$line_box = $this->_frame->get_current_line_box();
$line_box->y = $cb_y;
$line_box->get_float_offsets();
// Set the containing blocks and reflow each child
foreach ($this->_frame->get_children() as $child) {
// Bail out if the page is full
if ($page->is_full()) {
break;
}
$child->set_containing_block($cb_x, $cb_y, $w, $cb_h);
$this->process_clear($child);
$child->reflow($this->_frame);
// Don't add the child to the line if a page break has occurred
if ($page->check_page_break($child)) {
break;
}
$this->process_float($child, $cb_x, $w);
}
// Determine our height
list($height, $margin_top, $margin_bottom, $top, $bottom) = $this->_calculate_restricted_height();
$style->height = $height;
$style->margin_top = $margin_top;
$style->margin_bottom = $margin_bottom;
$style->top = $top;
$style->bottom = $bottom;
$orig_style = $this->_frame->get_original_style();
$needs_reposition = ($style->position === "absolute" && ($style->right !== "auto" || $style->bottom !== "auto"));
// Absolute positioning measurement
if ($needs_reposition) {
if ($orig_style->width === "auto" && ($orig_style->left === "auto" || $orig_style->right === "auto")) {
$width = 0;
foreach ($this->_frame->get_line_boxes() as $line) {
$width = max($line->w, $width);
}
$style->width = $width;
}
$style->left = $orig_style->left;
$style->right = $orig_style->right;
}
// Calculate inline-block / float auto-widths
if (($style->display === "inline-block" || $style->float !== 'none') && $orig_style->width === 'auto') {
$width = 0;
foreach ($this->_frame->get_line_boxes() as $line) {
$line->recalculate_width();
$width = max($line->w, $width);
}
if ($width === 0) {
foreach ($this->_frame->get_children() as $child) {
$width += $child->calculate_auto_width();
}
}
$style->width = $width;
}
$this->_text_align();
$this->vertical_align();
// Absolute positioning
if ($needs_reposition) {
list($x, $y) = $this->_frame->get_position();
$this->_frame->position();
list($new_x, $new_y) = $this->_frame->get_position();
$this->_frame->move($new_x - $x, $new_y - $y, true);
}
if ($block && $this->_frame->is_in_flow()) {
$block->add_frame_to_line($this->_frame);
// May be inline-block
if ($style->display === "block") {
$block->add_line();
}
}
}
/**
* Determine current frame width based on contents
*
* @return float
*/
public function calculate_auto_width()
{
$width = 0;
foreach ($this->_frame->get_line_boxes() as $line) {
$line_width = 0;
foreach ($line->get_frames() as $frame) {
if ($frame->get_original_style()->width == 'auto') {
$line_width += $frame->calculate_auto_width();
} else {
$line_width += $frame->get_margin_width();
}
}
$width = max($line_width, $width);
}
$this->_frame->get_style()->width = $width;
return $this->_frame->get_margin_width();
}
}

View File

@ -1,206 +0,0 @@
<?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
*/
namespace Dompdf\FrameReflower;
use Dompdf\Helpers;
use Dompdf\FrameDecorator\Block as BlockFrameDecorator;
use Dompdf\FrameDecorator\Image as ImageFrameDecorator;
/**
* Image reflower class
*
* @package dompdf
*/
class Image extends AbstractFrameReflower
{
/**
* Image constructor.
* @param ImageFrameDecorator $frame
*/
function __construct(ImageFrameDecorator $frame)
{
parent::__construct($frame);
}
/**
* @param BlockFrameDecorator|null $block
*/
function reflow(BlockFrameDecorator $block = null)
{
$this->_frame->position();
//FLOAT
//$frame = $this->_frame;
//$page = $frame->get_root();
//if ($frame->get_style()->float !== "none" ) {
// $page->add_floating_frame($this);
//}
// Set the frame's width
$this->get_min_max_width();
if ($block) {
$block->add_frame_to_line($this->_frame);
}
}
/**
* @return array
*/
function get_min_max_width()
{
if ($this->get_dompdf()->getOptions()->getDebugPng()) {
// Determine the image's size. Time consuming. Only when really needed?
list($img_width, $img_height) = Helpers::dompdf_getimagesize($this->_frame->get_image_url(), $this->get_dompdf()->getHttpContext());
print "get_min_max_width() " .
$this->_frame->get_style()->width . ' ' .
$this->_frame->get_style()->height . ';' .
$this->_frame->get_parent()->get_style()->width . " " .
$this->_frame->get_parent()->get_style()->height . ";" .
$this->_frame->get_parent()->get_parent()->get_style()->width . ' ' .
$this->_frame->get_parent()->get_parent()->get_style()->height . ';' .
$img_width . ' ' .
$img_height . '|';
}
$style = $this->_frame->get_style();
$width_forced = true;
$height_forced = true;
//own style auto or invalid value: use natural size in px
//own style value: ignore suffix text including unit, use given number as px
//own style %: walk up parent chain until found available space in pt; fill available space
//
//special ignored unit: e.g. 10ex: e treated as exponent; x ignored; 10e completely invalid ->like auto
$width = ($style->width > 0 ? $style->width : 0);
if (Helpers::is_percent($width)) {
$t = 0.0;
for ($f = $this->_frame->get_parent(); $f; $f = $f->get_parent()) {
$f_style = $f->get_style();
$t = $f_style->length_in_pt($f_style->width);
if ($t != 0) {
break;
}
}
$width = ((float)rtrim($width, "%") * $t) / 100; //maybe 0
} else {
// Don't set image original size if "%" branch was 0 or size not given.
// Otherwise aspect changed on %/auto combination for width/height
// Resample according to px per inch
// See also ListBulletImage::__construct
$width = $style->length_in_pt($width);
}
$height = ($style->height > 0 ? $style->height : 0);
if (Helpers::is_percent($height)) {
$t = 0.0;
for ($f = $this->_frame->get_parent(); $f; $f = $f->get_parent()) {
$f_style = $f->get_style();
$t = (float)$f_style->length_in_pt($f_style->height);
if ($t != 0) {
break;
}
}
$height = ((float)rtrim($height, "%") * $t) / 100; //maybe 0
} else {
// Don't set image original size if "%" branch was 0 or size not given.
// Otherwise aspect changed on %/auto combination for width/height
// Resample according to px per inch
// See also ListBulletImage::__construct
$height = $style->length_in_pt($height);
}
if ($width == 0 || $height == 0) {
// Determine the image's size. Time consuming. Only when really needed!
list($img_width, $img_height) = Helpers::dompdf_getimagesize($this->_frame->get_image_url(), $this->get_dompdf()->getHttpContext());
// don't treat 0 as error. Can be downscaled or can be catched elsewhere if image not readable.
// Resample according to px per inch
// See also ListBulletImage::__construct
if ($width == 0 && $height == 0) {
$dpi = $this->_frame->get_dompdf()->getOptions()->getDpi();
$width = (float)($img_width * 72) / $dpi;
$height = (float)($img_height * 72) / $dpi;
$width_forced = false;
$height_forced = false;
} elseif ($height == 0 && $width != 0) {
$height_forced = false;
$height = ($width / $img_width) * $img_height; //keep aspect ratio
} elseif ($width == 0 && $height != 0) {
$width_forced = false;
$width = ($height / $img_height) * $img_width; //keep aspect ratio
}
}
// Handle min/max width/height
if ($style->min_width !== "none" ||
$style->max_width !== "none" ||
$style->min_height !== "none" ||
$style->max_height !== "none"
) {
list( /*$x*/, /*$y*/, $w, $h) = $this->_frame->get_containing_block();
$min_width = $style->length_in_pt($style->min_width, $w);
$max_width = $style->length_in_pt($style->max_width, $w);
$min_height = $style->length_in_pt($style->min_height, $h);
$max_height = $style->length_in_pt($style->max_height, $h);
if ($max_width !== "none" && $width > $max_width) {
if (!$height_forced) {
$height *= $max_width / $width;
}
$width = $max_width;
}
if ($min_width !== "none" && $width < $min_width) {
if (!$height_forced) {
$height *= $min_width / $width;
}
$width = $min_width;
}
if ($max_height !== "none" && $height > $max_height) {
if (!$width_forced) {
$width *= $max_height / $height;
}
$height = $max_height;
}
if ($min_height !== "none" && $height < $min_height) {
if (!$width_forced) {
$width *= $min_height / $height;
}
$height = $min_height;
}
}
if ($this->get_dompdf()->getOptions()->getDebugPng()) {
print $width . ' ' . $height . ';';
}
$style->width = $width . "pt";
$style->height = $height . "pt";
$style->min_width = "none";
$style->max_width = "none";
$style->min_height = "none";
$style->max_height = "none";
return array($width, $width, "min" => $width, "max" => $width);
}
}

View File

@ -1,103 +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\FrameReflower;
use Dompdf\Frame;
use Dompdf\FrameDecorator\Block as BlockFrameDecorator;
use Dompdf\FrameDecorator\Text as TextFrameDecorator;
/**
* Reflows inline frames
*
* @package dompdf
*/
class Inline extends AbstractFrameReflower
{
/**
* Inline constructor.
* @param Frame $frame
*/
function __construct(Frame $frame)
{
parent::__construct($frame);
}
/**
* @param BlockFrameDecorator|null $block
*/
function reflow(BlockFrameDecorator $block = null)
{
$frame = $this->_frame;
// Check if a page break is forced
$page = $frame->get_root();
$page->check_forced_page_break($frame);
if ($page->is_full()) {
return;
}
$style = $frame->get_style();
// Generated content
$this->_set_content();
$frame->position();
$cb = $frame->get_containing_block();
// Add our margin, padding & border to the first and last children
if (($f = $frame->get_first_child()) && $f instanceof TextFrameDecorator) {
$f_style = $f->get_style();
$f_style->margin_left = $style->margin_left;
$f_style->padding_left = $style->padding_left;
$f_style->border_left = $style->border_left;
}
if (($l = $frame->get_last_child()) && $l instanceof TextFrameDecorator) {
$l_style = $l->get_style();
$l_style->margin_right = $style->margin_right;
$l_style->padding_right = $style->padding_right;
$l_style->border_right = $style->border_right;
}
if ($block) {
$block->add_frame_to_line($this->_frame);
}
// Set the containing blocks and reflow each child. The containing
// block is not changed by line boxes.
foreach ($frame->get_children() as $child) {
$child->set_containing_block($cb);
$child->reflow($block);
}
}
/**
* Determine current frame width based on contents
*
* @return float
*/
public function calculate_auto_width()
{
$width = 0;
foreach ($this->_frame->get_children() as $child) {
if ($child->get_original_style()->width == 'auto') {
$width += $child->calculate_auto_width();
} else {
$width += $child->get_margin_width();
}
}
$this->_frame->get_style()->width = $width;
return $this->_frame->get_margin_width();
}
}

View File

@ -1,589 +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\FrameReflower;
use Dompdf\FrameDecorator\Block as BlockFrameDecorator;
use Dompdf\FrameDecorator\Table as TableFrameDecorator;
/**
* Reflows tables
*
* @access private
* @package dompdf
*/
class Table extends AbstractFrameReflower
{
/**
* Frame for this reflower
*
* @var TableFrameDecorator
*/
protected $_frame;
/**
* Cache of results between call to get_min_max_width and assign_widths
*
* @var array
*/
protected $_state;
/**
* Table constructor.
* @param TableFrameDecorator $frame
*/
function __construct(TableFrameDecorator $frame)
{
$this->_state = null;
parent::__construct($frame);
}
/**
* State is held here so it needs to be reset along with the decorator
*/
function reset()
{
$this->_state = null;
$this->_min_max_cache = null;
}
protected function _assign_widths()
{
$style = $this->_frame->get_style();
// Find the min/max width of the table and sort the columns into
// absolute/percent/auto arrays
$min_width = $this->_state["min_width"];
$max_width = $this->_state["max_width"];
$percent_used = $this->_state["percent_used"];
$absolute_used = $this->_state["absolute_used"];
$auto_min = $this->_state["auto_min"];
$absolute =& $this->_state["absolute"];
$percent =& $this->_state["percent"];
$auto =& $this->_state["auto"];
// Determine the actual width of the table
$cb = $this->_frame->get_containing_block();
$columns =& $this->_frame->get_cellmap()->get_columns();
$width = $style->width;
// Calculate padding & border fudge factor
$left = $style->margin_left;
$right = $style->margin_right;
$centered = ($left === "auto" && $right === "auto");
$left = (float)($left === "auto" ? 0 : $style->length_in_pt($left, $cb["w"]));
$right = (float)($right === "auto" ? 0 : $style->length_in_pt($right, $cb["w"]));
$delta = $left + $right;
if (!$centered) {
$delta += (float)$style->length_in_pt(array(
$style->padding_left,
$style->border_left_width,
$style->border_right_width,
$style->padding_right),
$cb["w"]);
}
$min_table_width = (float)$style->length_in_pt($style->min_width, $cb["w"] - $delta);
// min & max widths already include borders & padding
$min_width -= $delta;
$max_width -= $delta;
if ($width !== "auto") {
$preferred_width = (float)$style->length_in_pt($width, $cb["w"]) - $delta;
if ($preferred_width < $min_table_width) {
$preferred_width = $min_table_width;
}
if ($preferred_width > $min_width) {
$width = $preferred_width;
} else {
$width = $min_width;
}
} else {
if ($max_width + $delta < $cb["w"]) {
$width = $max_width;
} else if ($cb["w"] - $delta > $min_width) {
$width = $cb["w"] - $delta;
} else {
$width = $min_width;
}
if ($width < $min_table_width) {
$width = $min_table_width;
}
}
// Store our resolved width
$style->width = $width;
$cellmap = $this->_frame->get_cellmap();
if ($cellmap->is_columns_locked()) {
return;
}
// If the whole table fits on the page, then assign each column it's max width
if ($width == $max_width) {
foreach (array_keys($columns) as $i) {
$cellmap->set_column_width($i, $columns[$i]["max-width"]);
}
return;
}
// Determine leftover and assign it evenly to all columns
if ($width > $min_width) {
// We have four cases to deal with:
//
// 1. All columns are auto--no widths have been specified. In this
// case we distribute extra space across all columns weighted by max-width.
//
// 2. Only absolute widths have been specified. In this case we
// distribute any extra space equally among 'width: auto' columns, or all
// columns if no auto columns have been specified.
//
// 3. Only percentage widths have been specified. In this case we
// normalize the percentage values and distribute any remaining % to
// width: auto columns. We then proceed to assign widths as fractions
// of the table width.
//
// 4. Both absolute and percentage widths have been specified.
$increment = 0;
// Case 1:
if ($absolute_used == 0 && $percent_used == 0) {
$increment = $width - $min_width;
foreach (array_keys($columns) as $i) {
$cellmap->set_column_width($i, $columns[$i]["min-width"] + $increment * ($columns[$i]["max-width"] / $max_width));
}
return;
}
// Case 2
if ($absolute_used > 0 && $percent_used == 0) {
if (count($auto) > 0) {
$increment = ($width - $auto_min - $absolute_used) / count($auto);
}
// Use the absolutely specified width or the increment
foreach (array_keys($columns) as $i) {
if ($columns[$i]["absolute"] > 0 && count($auto)) {
$cellmap->set_column_width($i, $columns[$i]["min-width"]);
} else if (count($auto)) {
$cellmap->set_column_width($i, $columns[$i]["min-width"] + $increment);
} else {
// All absolute columns
$increment = ($width - $absolute_used) * $columns[$i]["absolute"] / $absolute_used;
$cellmap->set_column_width($i, $columns[$i]["min-width"] + $increment);
}
}
return;
}
// Case 3:
if ($absolute_used == 0 && $percent_used > 0) {
$scale = null;
$remaining = null;
// Scale percent values if the total percentage is > 100, or if all
// values are specified as percentages.
if ($percent_used > 100 || count($auto) == 0) {
$scale = 100 / $percent_used;
} else {
$scale = 1;
}
// Account for the minimum space used by the unassigned auto columns
$used_width = $auto_min;
foreach ($percent as $i) {
$columns[$i]["percent"] *= $scale;
$slack = $width - $used_width;
$w = min($columns[$i]["percent"] * $width / 100, $slack);
if ($w < $columns[$i]["min-width"]) {
$w = $columns[$i]["min-width"];
}
$cellmap->set_column_width($i, $w);
$used_width += $w;
}
// This works because $used_width includes the min-width of each
// unassigned column
if (count($auto) > 0) {
$increment = ($width - $used_width) / count($auto);
foreach ($auto as $i) {
$cellmap->set_column_width($i, $columns[$i]["min-width"] + $increment);
}
}
return;
}
// Case 4:
// First-come, first served
if ($absolute_used > 0 && $percent_used > 0) {
$used_width = $auto_min;
foreach ($absolute as $i) {
$cellmap->set_column_width($i, $columns[$i]["min-width"]);
$used_width += $columns[$i]["min-width"];
}
// Scale percent values if the total percentage is > 100 or there
// are no auto values to take up slack
if ($percent_used > 100 || count($auto) == 0) {
$scale = 100 / $percent_used;
} else {
$scale = 1;
}
$remaining_width = $width - $used_width;
foreach ($percent as $i) {
$slack = $remaining_width - $used_width;
$columns[$i]["percent"] *= $scale;
$w = min($columns[$i]["percent"] * $remaining_width / 100, $slack);
if ($w < $columns[$i]["min-width"]) {
$w = $columns[$i]["min-width"];
}
$columns[$i]["used-width"] = $w;
$used_width += $w;
}
if (count($auto) > 0) {
$increment = ($width - $used_width) / count($auto);
foreach ($auto as $i) {
$cellmap->set_column_width($i, $columns[$i]["min-width"] + $increment);
}
}
return;
}
} else { // we are over constrained
// Each column gets its minimum width
foreach (array_keys($columns) as $i) {
$cellmap->set_column_width($i, $columns[$i]["min-width"]);
}
}
}
/**
* Determine the frame's height based on min/max height
*
* @return float|int|mixed|string
*/
protected function _calculate_height()
{
$style = $this->_frame->get_style();
$height = $style->height;
$cellmap = $this->_frame->get_cellmap();
$cellmap->assign_frame_heights();
$rows = $cellmap->get_rows();
// Determine our content height
$content_height = 0;
foreach ($rows as $r) {
$content_height += $r["height"];
}
$cb = $this->_frame->get_containing_block();
if (!($style->overflow === "visible" ||
($style->overflow === "hidden" && $height === "auto"))
) {
// Only handle min/max height if the height is independent of the frame's content
$min_height = $style->min_height;
$max_height = $style->max_height;
if (isset($cb["h"])) {
$min_height = $style->length_in_pt($min_height, $cb["h"]);
$max_height = $style->length_in_pt($max_height, $cb["h"]);
} else if (isset($cb["w"])) {
if (mb_strpos($min_height, "%") !== false) {
$min_height = 0;
} else {
$min_height = $style->length_in_pt($min_height, $cb["w"]);
}
if (mb_strpos($max_height, "%") !== false) {
$max_height = "none";
} else {
$max_height = $style->length_in_pt($max_height, $cb["w"]);
}
}
if ($max_height !== "none" && $min_height > $max_height) {
// Swap 'em
list($max_height, $min_height) = array($min_height, $max_height);
}
if ($max_height !== "none" && $height > $max_height) {
$height = $max_height;
}
if ($height < $min_height) {
$height = $min_height;
}
} else {
// Use the content height or the height value, whichever is greater
if ($height !== "auto") {
$height = $style->length_in_pt($height, $cb["h"]);
if ($height <= $content_height) {
$height = $content_height;
} else {
$cellmap->set_frame_heights($height, $content_height);
}
} else {
$height = $content_height;
}
}
return $height;
}
/**
* @param BlockFrameDecorator $block
*/
function reflow(BlockFrameDecorator $block = null)
{
/** @var TableFrameDecorator */
$frame = $this->_frame;
// Check if a page break is forced
$page = $frame->get_root();
$page->check_forced_page_break($frame);
// Bail if the page is full
if ($page->is_full()) {
return;
}
// Let the page know that we're reflowing a table so that splits
// are suppressed (simply setting page-break-inside: avoid won't
// work because we may have an arbitrary number of block elements
// inside tds.)
$page->table_reflow_start();
// Collapse vertical margins, if required
$this->_collapse_margins();
$frame->position();
// Table layout algorithm:
// http://www.w3.org/TR/CSS21/tables.html#auto-table-layout
if (is_null($this->_state)) {
$this->get_min_max_width();
}
$cb = $frame->get_containing_block();
$style = $frame->get_style();
// This is slightly inexact, but should be okay. Add half the
// border-spacing to the table as padding. The other half is added to
// the cells themselves.
if ($style->border_collapse === "separate") {
list($h, $v) = $style->border_spacing;
$v = (float)$style->length_in_pt($v) / 2;
$h = (float)$style->length_in_pt($h) / 2;
$style->padding_left = (float)$style->length_in_pt($style->padding_left, $cb["w"]) + $h;
$style->padding_right = (float)$style->length_in_pt($style->padding_right, $cb["w"]) + $h;
$style->padding_top = (float)$style->length_in_pt($style->padding_top, $cb["h"]) + $v;
$style->padding_bottom = (float)$style->length_in_pt($style->padding_bottom, $cb["h"]) + $v;
}
$this->_assign_widths();
// Adjust left & right margins, if they are auto
$width = $style->width;
$left = $style->margin_left;
$right = $style->margin_right;
$diff = $cb["w"] - $width;
if ($left === "auto" && $right === "auto") {
if ($diff < 0) {
$left = 0;
$right = $diff;
} else {
$left = $right = $diff / 2;
}
$style->margin_left = sprintf("%Fpt", $left);
$style->margin_right = sprintf("%Fpt", $right);;
} else {
if ($left === "auto") {
$left = (float)$style->length_in_pt($cb["w"], $cb["w"]) - (float)$style->length_in_pt($right, $cb["w"]) - (float)$style->length_in_pt($width, $cb["w"]);
}
if ($right === "auto") {
$left = (float)$style->length_in_pt($left, $cb["w"]);
}
}
list($x, $y) = $frame->get_position();
// Determine the content edge
$content_x = $x + (float)$left + (float)$style->length_in_pt(array($style->padding_left,
$style->border_left_width), $cb["w"]);
$content_y = $y + (float)$style->length_in_pt(array($style->margin_top,
$style->border_top_width,
$style->padding_top), $cb["h"]);
if (isset($cb["h"])) {
$h = $cb["h"];
} else {
$h = null;
}
$cellmap = $frame->get_cellmap();
$col =& $cellmap->get_column(0);
$col["x"] = $content_x;
$row =& $cellmap->get_row(0);
$row["y"] = $content_y;
$cellmap->assign_x_positions();
// Set the containing block of each child & reflow
foreach ($frame->get_children() as $child) {
// Bail if the page is full
if (!$page->in_nested_table() && $page->is_full()) {
break;
}
$child->set_containing_block($content_x, $content_y, $width, $h);
$child->reflow();
if (!$page->in_nested_table()) {
// Check if a split has occured
$page->check_page_break($child);
}
}
// Assign heights to our cells:
$style->height = $this->_calculate_height();
if ($style->border_collapse === "collapse") {
// Unset our borders because our cells are now using them
$style->border_style = "none";
}
$page->table_reflow_end();
// Debugging:
//echo ($this->_frame->get_cellmap());
if ($block && $style->float === "none" && $frame->is_in_flow()) {
$block->add_frame_to_line($frame);
$block->add_line();
}
}
/**
* @return array|null
*/
function get_min_max_width()
{
if (!is_null($this->_min_max_cache)) {
return $this->_min_max_cache;
}
$style = $this->_frame->get_style();
$this->_frame->normalise();
// Add the cells to the cellmap (this will calcluate column widths as
// frames are added)
$this->_frame->get_cellmap()->add_frame($this->_frame);
// Find the min/max width of the table and sort the columns into
// absolute/percent/auto arrays
$this->_state = array();
$this->_state["min_width"] = 0;
$this->_state["max_width"] = 0;
$this->_state["percent_used"] = 0;
$this->_state["absolute_used"] = 0;
$this->_state["auto_min"] = 0;
$this->_state["absolute"] = array();
$this->_state["percent"] = array();
$this->_state["auto"] = array();
$columns =& $this->_frame->get_cellmap()->get_columns();
foreach (array_keys($columns) as $i) {
$this->_state["min_width"] += $columns[$i]["min-width"];
$this->_state["max_width"] += $columns[$i]["max-width"];
if ($columns[$i]["absolute"] > 0) {
$this->_state["absolute"][] = $i;
$this->_state["absolute_used"] += $columns[$i]["absolute"];
} else if ($columns[$i]["percent"] > 0) {
$this->_state["percent"][] = $i;
$this->_state["percent_used"] += $columns[$i]["percent"];
} else {
$this->_state["auto"][] = $i;
$this->_state["auto_min"] += $columns[$i]["min-width"];
}
}
// Account for margins & padding
$dims = array($style->border_left_width,
$style->border_right_width,
$style->padding_left,
$style->padding_right,
$style->margin_left,
$style->margin_right);
if ($style->border_collapse !== "collapse") {
list($dims[]) = $style->border_spacing;
}
$delta = (float)$style->length_in_pt($dims, $this->_frame->get_containing_block("w"));
$this->_state["min_width"] += $delta;
$this->_state["max_width"] += $delta;
return $this->_min_max_cache = array(
$this->_state["min_width"],
$this->_state["max_width"],
"min" => $this->_state["min_width"],
"max" => $this->_state["max_width"],
);
}
}

View File

@ -1,72 +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\FrameReflower;
use Dompdf\FrameDecorator\Block as BlockFrameDecorator;
use Dompdf\FrameDecorator\Table as TableFrameDecorator;
/**
* Reflows table row groups (e.g. tbody tags)
*
* @package dompdf
*/
class TableRowGroup extends AbstractFrameReflower
{
/**
* TableRowGroup constructor.
* @param \Dompdf\Frame $frame
*/
function __construct($frame)
{
parent::__construct($frame);
}
/**
* @param BlockFrameDecorator|null $block
*/
function reflow(BlockFrameDecorator $block = null)
{
$page = $this->_frame->get_root();
$style = $this->_frame->get_style();
// Our width is equal to the width of our parent table
$table = TableFrameDecorator::find_parent_table($this->_frame);
$cb = $this->_frame->get_containing_block();
foreach ($this->_frame->get_children() as $child) {
// Bail if the page is full
if ($page->is_full()) {
return;
}
$child->set_containing_block($cb["x"], $cb["y"], $cb["w"], $cb["h"]);
$child->reflow();
// Check if a split has occured
$page->check_page_break($child);
}
if ($page->is_full()) {
return;
}
$cellmap = $table->get_cellmap();
$style->width = $cellmap->get_frame_width($this->_frame);
$style->height = $cellmap->get_frame_height($this->_frame);
$this->_frame->set_position($cellmap->get_frame_position($this->_frame));
if ($table->get_style()->border_collapse === "collapse") {
// Unset our borders because our cells are now using them
$style->border_style = "none";
}
}
}

View File

@ -1,511 +0,0 @@
<?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
*/
namespace Dompdf\FrameReflower;
use Dompdf\FrameDecorator\Block as BlockFrameDecorator;
use Dompdf\FrameDecorator\Text as TextFrameDecorator;
use Dompdf\FontMetrics;
use Dompdf\Helpers;
/**
* Reflows text frames.
*
* @package dompdf
*/
class Text extends AbstractFrameReflower
{
/**
* @var BlockFrameDecorator
*/
protected $_block_parent; // Nearest block-level ancestor
/**
* @var TextFrameDecorator
*/
protected $_frame;
public static $_whitespace_pattern = "/[ \t\r\n\f]+/u";
/**
* @var FontMetrics
*/
private $fontMetrics;
/**
* @param TextFrameDecorator $frame
* @param FontMetrics $fontMetrics
*/
public function __construct(TextFrameDecorator $frame, FontMetrics $fontMetrics)
{
parent::__construct($frame);
$this->setFontMetrics($fontMetrics);
}
/**
* @param $text
* @return mixed
*/
protected function _collapse_white_space($text)
{
//$text = $this->_frame->get_text();
// if ( $this->_block_parent->get_current_line_box->w == 0 )
// $text = ltrim($text, " \n\r\t");
return preg_replace(self::$_whitespace_pattern, " ", $text);
}
/**
* @param $text
* @return bool|int
*/
protected function _line_break($text)
{
$style = $this->_frame->get_style();
$size = $style->font_size;
$font = $style->font_family;
$current_line = $this->_block_parent->get_current_line_box();
// Determine the available width
$line_width = $this->_frame->get_containing_block("w");
$current_line_width = $current_line->left + $current_line->w + $current_line->right;
$available_width = $line_width - $current_line_width;
// Account for word-spacing
$word_spacing = (float)$style->length_in_pt($style->word_spacing);
$char_spacing = (float)$style->length_in_pt($style->letter_spacing);
// Determine the frame width including margin, padding & border
$text_width = $this->getFontMetrics()->getTextWidth($text, $font, $size, $word_spacing, $char_spacing);
$mbp_width =
(float)$style->length_in_pt(array($style->margin_left,
$style->border_left_width,
$style->padding_left,
$style->padding_right,
$style->border_right_width,
$style->margin_right), $line_width);
$frame_width = $text_width + $mbp_width;
// Debugging:
// Helpers::pre_r("Text: '" . htmlspecialchars($text). "'");
// Helpers::pre_r("width: " .$frame_width);
// Helpers::pre_r("textwidth + delta: $text_width + $mbp_width");
// Helpers::pre_r("font-size: $size");
// Helpers::pre_r("cb[w]: " .$line_width);
// Helpers::pre_r("available width: " . $available_width);
// Helpers::pre_r("current line width: " . $current_line_width);
// Helpers::pre_r($words);
if ($frame_width <= $available_width) {
return false;
}
// split the text into words
$words = preg_split('/([\s-]+)/u', $text, -1, PREG_SPLIT_DELIM_CAPTURE);
$wc = count($words);
// Determine the split point
$width = 0;
$str = "";
reset($words);
// @todo support <shy>, <wbr>
for ($i = 0; $i < $wc; $i += 2) {
$word = $words[$i] . (isset($words[$i + 1]) ? $words[$i + 1] : "");
$word_width = $this->getFontMetrics()->getTextWidth($word, $font, $size, $word_spacing, $char_spacing);
if ($width + $word_width + $mbp_width > $available_width) {
break;
}
$width += $word_width;
$str .= $word;
}
$break_word = ($style->word_wrap === "break-word");
// The first word has overflowed. Force it onto the line
if ($current_line_width == 0 && $width == 0) {
$s = "";
$last_width = 0;
if ($break_word) {
for ($j = 0; $j < strlen($word); $j++) {
$s .= $word[$j];
$_width = $this->getFontMetrics()->getTextWidth($s, $font, $size, $word_spacing, $char_spacing);
if ($_width > $available_width) {
break;
}
$last_width = $_width;
}
}
if ($break_word && $last_width > 0) {
//$width += $last_width;
$str .= substr($s, 0, -1);
} else {
//$width += $word_width;
$str .= $word;
}
}
$offset = mb_strlen($str);
// More debugging:
// var_dump($str);
// print_r("Width: ". $width);
// print_r("Offset: " . $offset);
return $offset;
}
//........................................................................
/**
* @param $text
* @return bool|int
*/
protected function _newline_break($text)
{
if (($i = mb_strpos($text, "\n")) === false) {
return false;
}
return $i + 1;
}
/**
*
*/
protected function _layout_line()
{
$frame = $this->_frame;
$style = $frame->get_style();
$text = $frame->get_text();
$size = $style->font_size;
$font = $style->font_family;
// Determine the text height
$style->height = $this->getFontMetrics()->getFontHeight($font, $size);
$split = false;
$add_line = false;
// Handle text transform:
// http://www.w3.org/TR/CSS21/text.html#propdef-text-transform
switch (strtolower($style->text_transform)) {
default:
break;
case "capitalize":
$text = Helpers::mb_ucwords($text);
break;
case "uppercase":
$text = mb_convert_case($text, MB_CASE_UPPER);
break;
case "lowercase":
$text = mb_convert_case($text, MB_CASE_LOWER);
break;
}
// Handle white-space property:
// http://www.w3.org/TR/CSS21/text.html#propdef-white-space
switch ($style->white_space) {
default:
case "normal":
$frame->set_text($text = $this->_collapse_white_space($text));
if ($text == "") {
break;
}
$split = $this->_line_break($text);
break;
case "pre":
$split = $this->_newline_break($text);
$add_line = $split !== false;
break;
case "nowrap":
$frame->set_text($text = $this->_collapse_white_space($text));
break;
case "pre-wrap":
$split = $this->_newline_break($text);
if (($tmp = $this->_line_break($text)) !== false) {
$add_line = $split < $tmp;
$split = min($tmp, $split);
} else
$add_line = true;
break;
case "pre-line":
// Collapse white-space except for \n
$frame->set_text($text = preg_replace("/[ \t]+/u", " ", $text));
if ($text == "") {
break;
}
$split = $this->_newline_break($text);
if (($tmp = $this->_line_break($text)) !== false) {
$add_line = $split < $tmp;
$split = min($tmp, $split);
} else {
$add_line = true;
}
break;
}
// Handle degenerate case
if ($text === "") {
return;
}
if ($split !== false) {
// Handle edge cases
if ($split == 0 && $text === " ") {
$frame->set_text("");
return;
}
if ($split == 0) {
// Trim newlines from the beginning of the line
//$this->_frame->set_text(ltrim($text, "\n\r"));
$this->_block_parent->maximize_line_height($style->height, $frame);
$this->_block_parent->add_line();
$frame->position();
// Layout the new line
$this->_layout_line();
} else if ($split < mb_strlen($frame->get_text())) {
// split the line if required
$frame->split_text($split);
$t = $frame->get_text();
// Remove any trailing newlines
if ($split > 1 && $t[$split - 1] === "\n" && !$frame->is_pre()) {
$frame->set_text(mb_substr($t, 0, -1));
}
// Do we need to trim spaces on wrapped lines? This might be desired, however, we
// can't trim the lines here or the layout will be affected if trimming the line
// leaves enough space to fit the next word in the text stream (because pdf layout
// is performed elsewhere).
/*if (!$this->_frame->get_prev_sibling() && !$this->_frame->get_next_sibling()) {
$t = $this->_frame->get_text();
$this->_frame->set_text( trim($t) );
}*/
}
if ($add_line) {
$this->_block_parent->add_line();
$frame->position();
}
} else {
// Remove empty space from start and end of line, but only where there isn't an inline sibling
// and the parent node isn't an inline element with siblings
// FIXME: Include non-breaking spaces?
$t = $frame->get_text();
$parent = $frame->get_parent();
$is_inline_frame = ($parent instanceof \Dompdf\FrameDecorator\Inline);
if ((!$is_inline_frame && !$frame->get_next_sibling()) /* ||
( $is_inline_frame && !$parent->get_next_sibling())*/
) { // fails <b>BOLD <u>UNDERLINED</u></b> becomes <b>BOLD<u>UNDERLINED</u></b>
$t = rtrim($t);
}
if ((!$is_inline_frame && !$frame->get_prev_sibling()) /* ||
( $is_inline_frame && !$parent->get_prev_sibling())*/
) { // <span><span>A<span>B</span> C</span></span> fails (the whitespace is removed)
$t = ltrim($t);
}
$frame->set_text($t);
}
// Set our new width
$width = $frame->recalculate_width();
}
/**
* @param BlockFrameDecorator|null $block
*/
function reflow(BlockFrameDecorator $block = null)
{
$frame = $this->_frame;
$page = $frame->get_root();
$page->check_forced_page_break($this->_frame);
if ($page->is_full()) {
return;
}
$this->_block_parent = /*isset($block) ? $block : */
$frame->find_block_parent();
// Left trim the text if this is the first text on the line and we're
// collapsing white space
// if ( $this->_block_parent->get_current_line()->w == 0 &&
// ($frame->get_style()->white_space !== "pre" ||
// $frame->get_style()->white_space !== "pre-wrap") ) {
// $frame->set_text( ltrim( $frame->get_text() ) );
// }
$frame->position();
$this->_layout_line();
if ($block) {
$block->add_frame_to_line($frame);
}
}
//........................................................................
// Returns an array(0 => min, 1 => max, "min" => min, "max" => max) of the
// minimum and maximum widths of this frame
function get_min_max_width()
{
/*if ( !is_null($this->_min_max_cache) )
return $this->_min_max_cache;*/
$frame = $this->_frame;
$style = $frame->get_style();
$this->_block_parent = $frame->find_block_parent();
$line_width = $frame->get_containing_block("w");
$str = $text = $frame->get_text();
$size = $style->font_size;
$font = $style->font_family;
$word_spacing = (float)$style->length_in_pt($style->word_spacing);
$char_spacing = (float)$style->length_in_pt($style->letter_spacing);
switch ($style->white_space) {
default:
case "normal":
$str = preg_replace(self::$_whitespace_pattern, " ", $str);
case "pre-wrap":
case "pre-line":
// Find the longest word (i.e. minimum length)
// This technique (using arrays & an anonymous function) is actually
// faster than doing a single-pass character by character scan. Heh,
// yes I took the time to bench it ;)
$words = array_flip(preg_split("/[\s-]+/u", $str, -1, PREG_SPLIT_DELIM_CAPTURE));
$root = $this;
array_walk($words, function(&$val, $str) use ($font, $size, $word_spacing, $char_spacing, $root) {
$val = $root->getFontMetrics()->getTextWidth($str, $font, $size, $word_spacing, $char_spacing);
});
arsort($words);
$min = reset($words);
break;
case "pre":
$lines = array_flip(preg_split("/\n/u", $str));
$root = $this;
array_walk($lines, function(&$val, $str) use ($font, $size, $word_spacing, $char_spacing, $root) {
$val = $root->getFontMetrics()->getTextWidth($str, $font, $size, $word_spacing, $char_spacing);
});
arsort($lines);
$min = reset($lines);
break;
case "nowrap":
$min = $this->getFontMetrics()->getTextWidth($this->_collapse_white_space($str), $font, $size, $word_spacing, $char_spacing);
break;
}
switch ($style->white_space) {
default:
case "normal":
case "nowrap":
$str = preg_replace(self::$_whitespace_pattern, " ", $text);
break;
case "pre-line":
//XXX: Is this correct?
$str = preg_replace("/[ \t]+/u", " ", $text);
case "pre-wrap":
// Find the longest word (i.e. minimum length)
$lines = array_flip(preg_split("/\n/", $text));
$root = $this;
array_walk($lines, function(&$val, $str) use ($font, $size, $word_spacing, $char_spacing, $root) {
$val = $root->getFontMetrics()->getTextWidth($str, $font, $size, $word_spacing, $char_spacing);
});
arsort($lines);
reset($lines);
$str = key($lines);
break;
}
$max = $this->getFontMetrics()->getTextWidth($str, $font, $size, $word_spacing, $char_spacing);
$delta = (float)$style->length_in_pt(array($style->margin_left,
$style->border_left_width,
$style->padding_left,
$style->padding_right,
$style->border_right_width,
$style->margin_right), $line_width);
$min += $delta;
$min_word = $min;
$max += $delta;
if ($style->word_wrap === 'break-word') {
// If it is allowed to break words, the min width is the widest character.
// But for performance reasons, we only check the first character.
$char = mb_substr($str, 0, 1);
$min_char = $this->getFontMetrics()->getTextWidth($char, $font, $size, $word_spacing, $char_spacing);
$min = $delta + $min_char;
}
return $this->_min_max_cache = array($min, $max, $min_word, "min" => $min, "max" => $max, 'min_word' => $min_word);
}
/**
* @param FontMetrics $fontMetrics
* @return $this
*/
public function setFontMetrics(FontMetrics $fontMetrics)
{
$this->fontMetrics = $fontMetrics;
return $this;
}
/**
* @return FontMetrics
*/
public function getFontMetrics()
{
return $this->fontMetrics;
}
/**
* Determine current frame width based on contents
*
* @return float
*/
public function calculate_auto_width()
{
return $this->_frame->recalculate_width();
}
}

View File

@ -1,186 +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 = array();
/**
* 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();
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
else {
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();
$resolved_url = @tempnam($tmp_dir, "ca_dompdf_img_");
$image = "";
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 (strlen($image) == 0) {
$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
file_put_contents($resolved_url, $image);
}
}
} // Not remote, local image
else {
$resolved_url = Helpers::build_url($protocol, $host, $base_path, $url);
}
}
// 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, array("gif", "png", "jpeg", "bmp", "svg"))) {
//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) {
$resolved_url = self::$broken_image;
$type = "png";
$message = self::$error_message;
Helpers::record_warnings($e->getCode(), $e->getMessage() . " \n $url", $e->getFile(), $e->getLine());
}
return array($resolved_url, $type, $message);
}
/**
* Unlink all cached images (i.e. temporary images either downloaded
* or converted)
*/
static function clear()
{
if (empty(self::$_cache) || self::$_dompdf->getOptions()->getDebugKeepTemp()) {
return;
}
foreach (self::$_cache as $file) {
if (self::$_dompdf->getOptions()->getDebugPng()) {
print "[clear unlink $file]";
}
unlink($file);
}
self::$_cache = array();
}
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");
}

View File

@ -1,118 +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\Positioner;
use Dompdf\FrameDecorator\AbstractFrameDecorator;
/**
* Positions absolutely positioned frames
*/
class Absolute extends AbstractPositioner
{
/**
* @param AbstractFrameDecorator $frame
*/
function position(AbstractFrameDecorator $frame)
{
$style = $frame->get_style();
$p = $frame->find_positionned_parent();
list($x, $y, $w, $h) = $frame->get_containing_block();
$top = $style->length_in_pt($style->top, $h);
$right = $style->length_in_pt($style->right, $w);
$bottom = $style->length_in_pt($style->bottom, $h);
$left = $style->length_in_pt($style->left, $w);
if ($p && !($left === "auto" && $right === "auto")) {
// Get the parent's padding box (see http://www.w3.org/TR/CSS21/visuren.html#propdef-top)
list($x, $y, $w, $h) = $p->get_padding_box();
}
list($width, $height) = array($frame->get_margin_width(), $frame->get_margin_height());
$orig_style = $frame->get_original_style();
$orig_width = $orig_style->width;
$orig_height = $orig_style->height;
/****************************
*
* Width auto:
* ____________| left=auto | left=fixed |
* right=auto | A | B |
* right=fixed | C | D |
*
* Width fixed:
* ____________| left=auto | left=fixed |
* right=auto | E | F |
* right=fixed | G | H |
*****************************/
if ($left === "auto") {
if ($right === "auto") {
// A or E - Keep the frame at the same position
$x = $x + $frame->find_block_parent()->get_current_line_box()->w;
} else {
if ($orig_width === "auto") {
// C
$x += $w - $width - $right;
} else {
// G
$x += $w - $width - $right;
}
}
} else {
if ($right === "auto") {
// B or F
$x += (float)$left;
} else {
if ($orig_width === "auto") {
// D - TODO change width
$x += (float)$left;
} else {
// H - Everything is fixed: left + width win
$x += (float)$left;
}
}
}
// The same vertically
if ($top === "auto") {
if ($bottom === "auto") {
// A or E - Keep the frame at the same position
$y = $frame->find_block_parent()->get_current_line_box()->y;
} else {
if ($orig_height === "auto") {
// C
$y += (float)$h - $height - (float)$bottom;
} else {
// G
$y += (float)$h - $height - (float)$bottom;
}
}
} else {
if ($bottom === "auto") {
// B or F
$y += (float)$top;
} else {
if ($orig_height === "auto") {
// D - TODO change height
$y += (float)$top;
} else {
// H - Everything is fixed: top + height win
$y += (float)$top;
}
}
}
$frame->set_position($x, $y);
}
}

View File

@ -1,89 +0,0 @@
<?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
*/
namespace Dompdf\Positioner;
use Dompdf\FrameDecorator\AbstractFrameDecorator;
/**
* Positions fixely positioned frames
*/
class Fixed extends AbstractPositioner
{
/**
* @param AbstractFrameDecorator $frame
*/
function position(AbstractFrameDecorator $frame)
{
$style = $frame->get_original_style();
$root = $frame->get_root();
$initialcb = $root->get_containing_block();
$initialcb_style = $root->get_style();
$p = $frame->find_block_parent();
if ($p) {
$p->add_line();
}
// Compute the margins of the @page style
$margin_top = (float)$initialcb_style->length_in_pt($initialcb_style->margin_top, $initialcb["h"]);
$margin_right = (float)$initialcb_style->length_in_pt($initialcb_style->margin_right, $initialcb["w"]);
$margin_bottom = (float)$initialcb_style->length_in_pt($initialcb_style->margin_bottom, $initialcb["h"]);
$margin_left = (float)$initialcb_style->length_in_pt($initialcb_style->margin_left, $initialcb["w"]);
// The needed computed style of the element
$height = (float)$style->length_in_pt($style->height, $initialcb["h"]);
$width = (float)$style->length_in_pt($style->width, $initialcb["w"]);
$top = $style->length_in_pt($style->top, $initialcb["h"]);
$right = $style->length_in_pt($style->right, $initialcb["w"]);
$bottom = $style->length_in_pt($style->bottom, $initialcb["h"]);
$left = $style->length_in_pt($style->left, $initialcb["w"]);
$y = $margin_top;
if (isset($top)) {
$y = (float)$top + $margin_top;
if ($top === "auto") {
$y = $margin_top;
if (isset($bottom) && $bottom !== "auto") {
$y = $initialcb["h"] - $bottom - $margin_bottom;
if ($frame->is_auto_height()) {
$y -= $height;
} else {
$y -= $frame->get_margin_height();
}
}
}
}
$x = $margin_left;
if (isset($left)) {
$x = (float)$left + $margin_left;
if ($left === "auto") {
$x = $margin_left;
if (isset($right) && $right !== "auto") {
$x = $initialcb["w"] - $right - $margin_right;
if ($frame->is_auto_width()) {
$x -= $width;
} else {
$x -= $frame->get_margin_width();
}
}
}
}
$frame->set_position($x, $y);
$children = $frame->get_children();
foreach ($children as $child) {
$child->set_position($x, $y);
}
}
}

View File

@ -1,77 +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\Positioner;
use Dompdf\FrameDecorator\AbstractFrameDecorator;
use Dompdf\FrameDecorator\Inline as InlineFrameDecorator;
use Dompdf\Exception;
/**
* Positions inline frames
*
* @package dompdf
*/
class Inline extends AbstractPositioner
{
/**
* @param AbstractFrameDecorator $frame
* @throws Exception
*/
function position(AbstractFrameDecorator $frame)
{
/**
* Find our nearest block level parent and access its lines property.
* @var BlockFrameDecorator
*/
$p = $frame->find_block_parent();
// Debugging code:
// Helpers::pre_r("\nPositioning:");
// Helpers::pre_r("Me: " . $frame->get_node()->nodeName . " (" . spl_object_hash($frame->get_node()) . ")");
// Helpers::pre_r("Parent: " . $p->get_node()->nodeName . " (" . spl_object_hash($p->get_node()) . ")");
// End debugging
if (!$p) {
throw new Exception("No block-level parent found. Not good.");
}
$f = $frame;
$cb = $f->get_containing_block();
$line = $p->get_current_line_box();
// Skip the page break if in a fixed position element
$is_fixed = false;
while ($f = $f->get_parent()) {
if ($f->get_style()->position === "fixed") {
$is_fixed = true;
break;
}
}
$f = $frame;
if (!$is_fixed && $f->get_parent() &&
$f->get_parent() instanceof InlineFrameDecorator &&
$f->is_text_node()
) {
$min_max = $f->get_reflower()->get_min_max_width();
// If the frame doesn't fit in the current line, a line break occurs
if ($min_max["min"] > ($cb["w"] - $line->left - $line->w - $line->right)) {
$p->add_line();
}
}
$f->set_position($cb["x"] + $line->w, $line->y);
}
}

View File

@ -1,76 +0,0 @@
<?php
/**
* @package dompdf
* @link http://dompdf.github.com/
* @author Benj Carson <benjcarson@digitaljunkies.ca>
* @author Helmut Tischer <htischer@weihenstephan.org>
* @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
*/
namespace Dompdf\Positioner;
use Dompdf\FrameDecorator\AbstractFrameDecorator;
/**
* Positions list bullets
*
* @package dompdf
*/
class ListBullet extends AbstractPositioner
{
/**
* @param AbstractFrameDecorator $frame
*/
function position(AbstractFrameDecorator $frame)
{
// Bullets & friends are positioned an absolute distance to the left of
// the content edge of their parent element
$cb = $frame->get_containing_block();
// Note: this differs from most frames in that we must position
// ourselves after determining our width
$x = $cb["x"] - $frame->get_width();
$p = $frame->find_block_parent();
$y = $p->get_current_line_box()->y;
// This is a bit of a hack...
$n = $frame->get_next_sibling();
if ($n) {
$style = $n->get_style();
$line_height = $style->length_in_pt($style->line_height, $style->font_size);
$offset = (float)$style->length_in_pt($line_height, $n->get_containing_block("h")) - $frame->get_height();
$y += $offset / 2;
}
// Now the position is the left top of the block which should be marked with the bullet.
// We tried to find out the y of the start of the first text character within the block.
// But the top margin/padding does not fit, neither from this nor from the next sibling
// The "bit of a hack" above does not work also.
// Instead let's position the bullet vertically centered to the block which should be marked.
// But for get_next_sibling() the get_containing_block is all zero, and for find_block_parent()
// the get_containing_block is paper width and the entire list as height.
// if ($p) {
// //$cb = $n->get_containing_block();
// $cb = $p->get_containing_block();
// $y += $cb["h"]/2;
// print 'cb:'.$cb["x"].':'.$cb["y"].':'.$cb["w"].':'.$cb["h"].':';
// }
// Todo:
// For now give up on the above. Use Guesswork with font y-pos in the middle of the line spacing
/*$style = $p->get_style();
$font_size = $style->font_size;
$line_height = (float)$style->length_in_pt($style->line_height, $font_size);
$y += ($line_height - $font_size) / 2; */
//Position is x-end y-top of character position of the bullet.
$frame->set_position($x, $y);
}
}

View File

@ -1,923 +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\Renderer;
use Dompdf\Adapter\CPDF;
use Dompdf\Css\Color;
use Dompdf\Css\Style;
use Dompdf\Dompdf;
use Dompdf\Helpers;
use Dompdf\Frame;
use Dompdf\Image\Cache;
/**
* Base renderer class
*
* @package dompdf
*/
abstract class AbstractRenderer
{
/**
* Rendering backend
*
* @var \Dompdf\Canvas
*/
protected $_canvas;
/**
* Current dompdf instance
*
* @var Dompdf
*/
protected $_dompdf;
/**
* Class constructor
*
* @param Dompdf $dompdf The current dompdf instance
*/
function __construct(Dompdf $dompdf)
{
$this->_dompdf = $dompdf;
$this->_canvas = $dompdf->getCanvas();
}
/**
* Render a frame.
*
* Specialized in child classes
*
* @param Frame $frame The frame to render
*/
abstract function render(Frame $frame);
/**
* Render a background image over a rectangular area
*
* @param string $url The background image to load
* @param float $x The left edge of the rectangular area
* @param float $y The top edge of the rectangular area
* @param float $width The width of the rectangular area
* @param float $height The height of the rectangular area
* @param Style $style The associated Style object
*
* @throws \Exception
*/
protected function _background_image($url, $x, $y, $width, $height, $style)
{
if (!function_exists("imagecreatetruecolor")) {
throw new \Exception("The PHP GD extension is required, but is not installed.");
}
$sheet = $style->get_stylesheet();
// Skip degenerate cases
if ($width == 0 || $height == 0) {
return;
}
$box_width = $width;
$box_height = $height;
//debugpng
if ($this->_dompdf->getOptions()->getDebugPng()) {
print '[_background_image ' . $url . ']';
}
list($img, $type, /*$msg*/) = Cache::resolve_url(
$url,
$sheet->get_protocol(),
$sheet->get_host(),
$sheet->get_base_path(),
$this->_dompdf
);
// Bail if the image is no good
if (Cache::is_broken($img)) {
return;
}
//Try to optimize away reading and composing of same background multiple times
//Postponing read with imagecreatefrom ...()
//final composition parameters and name not known yet
//Therefore read dimension directly from file, instead of creating gd object first.
//$img_w = imagesx($src); $img_h = imagesy($src);
list($img_w, $img_h) = Helpers::dompdf_getimagesize($img, $this->_dompdf->getHttpContext());
if (!isset($img_w) || $img_w == 0 || !isset($img_h) || $img_h == 0) {
return;
}
$repeat = $style->background_repeat;
$dpi = $this->_dompdf->getOptions()->getDpi();
//Increase background resolution and dependent box size according to image resolution to be placed in
//Then image can be copied in without resize
$bg_width = round((float)($width * $dpi) / 72);
$bg_height = round((float)($height * $dpi) / 72);
//Need %bg_x, $bg_y as background pos, where img starts, converted to pixel
list($bg_x, $bg_y) = $style->background_position;
if (Helpers::is_percent($bg_x)) {
// The point $bg_x % from the left edge of the image is placed
// $bg_x % from the left edge of the background rectangle
$p = ((float)$bg_x) / 100.0;
$x1 = $p * $img_w;
$x2 = $p * $bg_width;
$bg_x = $x2 - $x1;
} else {
$bg_x = (float)($style->length_in_pt($bg_x) * $dpi) / 72;
}
$bg_x = round($bg_x + (float)$style->length_in_pt($style->border_left_width) * $dpi / 72);
if (Helpers::is_percent($bg_y)) {
// The point $bg_y % from the left edge of the image is placed
// $bg_y % from the left edge of the background rectangle
$p = ((float)$bg_y) / 100.0;
$y1 = $p * $img_h;
$y2 = $p * $bg_height;
$bg_y = $y2 - $y1;
} else {
$bg_y = (float)($style->length_in_pt($bg_y) * $dpi) / 72;
}
$bg_y = round($bg_y + (float)$style->length_in_pt($style->border_top_width) * $dpi / 72);
//clip background to the image area on partial repeat. Nothing to do if img off area
//On repeat, normalize start position to the tile at immediate left/top or 0/0 of area
//On no repeat with positive offset: move size/start to have offset==0
//Handle x/y Dimensions separately
if ($repeat !== "repeat" && $repeat !== "repeat-x") {
//No repeat x
if ($bg_x < 0) {
$bg_width = $img_w + $bg_x;
} else {
$x += ($bg_x * 72) / $dpi;
$bg_width = $bg_width - $bg_x;
if ($bg_width > $img_w) {
$bg_width = $img_w;
}
$bg_x = 0;
}
if ($bg_width <= 0) {
return;
}
$width = (float)($bg_width * 72) / $dpi;
} else {
//repeat x
if ($bg_x < 0) {
$bg_x = -((-$bg_x) % $img_w);
} else {
$bg_x = $bg_x % $img_w;
if ($bg_x > 0) {
$bg_x -= $img_w;
}
}
}
if ($repeat !== "repeat" && $repeat !== "repeat-y") {
//no repeat y
if ($bg_y < 0) {
$bg_height = $img_h + $bg_y;
} else {
$y += ($bg_y * 72) / $dpi;
$bg_height = $bg_height - $bg_y;
if ($bg_height > $img_h) {
$bg_height = $img_h;
}
$bg_y = 0;
}
if ($bg_height <= 0) {
return;
}
$height = (float)($bg_height * 72) / $dpi;
} else {
//repeat y
if ($bg_y < 0) {
$bg_y = -((-$bg_y) % $img_h);
} else {
$bg_y = $bg_y % $img_h;
if ($bg_y > 0) {
$bg_y -= $img_h;
}
}
}
//Optimization, if repeat has no effect
if ($repeat === "repeat" && $bg_y <= 0 && $img_h + $bg_y >= $bg_height) {
$repeat = "repeat-x";
}
if ($repeat === "repeat" && $bg_x <= 0 && $img_w + $bg_x >= $bg_width) {
$repeat = "repeat-y";
}
if (($repeat === "repeat-x" && $bg_x <= 0 && $img_w + $bg_x >= $bg_width) ||
($repeat === "repeat-y" && $bg_y <= 0 && $img_h + $bg_y >= $bg_height)
) {
$repeat = "no-repeat";
}
//Use filename as indicator only
//different names for different variants to have different copies in the pdf
//This is not dependent of background color of box! .'_'.(is_array($bg_color) ? $bg_color["hex"] : $bg_color)
//Note: Here, bg_* are the start values, not end values after going through the tile loops!
$filedummy = $img;
$is_png = false;
$filedummy .= '_' . $bg_width . '_' . $bg_height . '_' . $bg_x . '_' . $bg_y . '_' . $repeat;
//Optimization to avoid multiple times rendering the same image.
//If check functions are existing and identical image already cached,
//then skip creation of duplicate, because it is not needed by addImagePng
if ($this->_canvas instanceof CPDF && $this->_canvas->get_cpdf()->image_iscached($filedummy)) {
$bg = null;
} else {
// Create a new image to fit over the background rectangle
$bg = imagecreatetruecolor($bg_width, $bg_height);
switch (strtolower($type)) {
case "png":
$is_png = true;
imagesavealpha($bg, true);
imagealphablending($bg, false);
$src = imagecreatefrompng($img);
break;
case "jpeg":
$src = imagecreatefromjpeg($img);
break;
case "gif":
$src = imagecreatefromgif($img);
break;
case "bmp":
$src = Helpers::imagecreatefrombmp($img);
break;
default:
return; // Unsupported image type
}
if ($src == null) {
return;
}
//Background color if box is not relevant here
//Non transparent image: box clipped to real size. Background non relevant.
//Transparent image: The image controls the transparency and lets shine through whatever background.
//However on transparent image preset the composed image with the transparency color,
//to keep the transparency when copying over the non transparent parts of the tiles.
$ti = imagecolortransparent($src);
if ($ti >= 0) {
$tc = imagecolorsforindex($src, $ti);
$ti = imagecolorallocate($bg, $tc['red'], $tc['green'], $tc['blue']);
imagefill($bg, 0, 0, $ti);
imagecolortransparent($bg, $ti);
}
//This has only an effect for the non repeatable dimension.
//compute start of src and dest coordinates of the single copy
if ($bg_x < 0) {
$dst_x = 0;
$src_x = -$bg_x;
} else {
$src_x = 0;
$dst_x = $bg_x;
}
if ($bg_y < 0) {
$dst_y = 0;
$src_y = -$bg_y;
} else {
$src_y = 0;
$dst_y = $bg_y;
}
//For historical reasons exchange meanings of variables:
//start_* will be the start values, while bg_* will be the temporary start values in the loops
$start_x = $bg_x;
$start_y = $bg_y;
// Copy regions from the source image to the background
if ($repeat === "no-repeat") {
// Simply place the image on the background
imagecopy($bg, $src, $dst_x, $dst_y, $src_x, $src_y, $img_w, $img_h);
} else if ($repeat === "repeat-x") {
for ($bg_x = $start_x; $bg_x < $bg_width; $bg_x += $img_w) {
if ($bg_x < 0) {
$dst_x = 0;
$src_x = -$bg_x;
$w = $img_w + $bg_x;
} else {
$dst_x = $bg_x;
$src_x = 0;
$w = $img_w;
}
imagecopy($bg, $src, $dst_x, $dst_y, $src_x, $src_y, $w, $img_h);
}
} else if ($repeat === "repeat-y") {
for ($bg_y = $start_y; $bg_y < $bg_height; $bg_y += $img_h) {
if ($bg_y < 0) {
$dst_y = 0;
$src_y = -$bg_y;
$h = $img_h + $bg_y;
} else {
$dst_y = $bg_y;
$src_y = 0;
$h = $img_h;
}
imagecopy($bg, $src, $dst_x, $dst_y, $src_x, $src_y, $img_w, $h);
}
} else if ($repeat === "repeat") {
for ($bg_y = $start_y; $bg_y < $bg_height; $bg_y += $img_h) {
for ($bg_x = $start_x; $bg_x < $bg_width; $bg_x += $img_w) {
if ($bg_x < 0) {
$dst_x = 0;
$src_x = -$bg_x;
$w = $img_w + $bg_x;
} else {
$dst_x = $bg_x;
$src_x = 0;
$w = $img_w;
}
if ($bg_y < 0) {
$dst_y = 0;
$src_y = -$bg_y;
$h = $img_h + $bg_y;
} else {
$dst_y = $bg_y;
$src_y = 0;
$h = $img_h;
}
imagecopy($bg, $src, $dst_x, $dst_y, $src_x, $src_y, $w, $h);
}
}
} else {
print 'Unknown repeat!';
}
imagedestroy($src);
} /* End optimize away creation of duplicates */
$this->_canvas->clipping_rectangle($x, $y, $box_width, $box_height);
//img: image url string
//img_w, img_h: original image size in px
//width, height: box size in pt
//bg_width, bg_height: box size in px
//x, y: left/top edge of box on page in pt
//start_x, start_y: placement of image relative to pattern
//$repeat: repeat mode
//$bg: GD object of result image
//$src: GD object of original image
//When using cpdf and optimization to direct png creation from gd object is available,
//don't create temp file, but place gd object directly into the pdf
if (!$is_png && $this->_canvas instanceof CPDF) {
// Note: CPDF_Adapter image converts y position
$this->_canvas->get_cpdf()->addImagePng($filedummy, $x, $this->_canvas->get_height() - $y - $height, $width, $height, $bg);
} else {
$tmp_dir = $this->_dompdf->getOptions()->getTempDir();
$tmp_name = @tempnam($tmp_dir, "bg_dompdf_img_");
@unlink($tmp_name);
$tmp_file = "$tmp_name.png";
//debugpng
if ($this->_dompdf->getOptions()->getDebugPng()) {
print '[_background_image ' . $tmp_file . ']';
}
imagepng($bg, $tmp_file);
$this->_canvas->image($tmp_file, $x, $y, $width, $height);
imagedestroy($bg);
//debugpng
if ($this->_dompdf->getOptions()->getDebugPng()) {
print '[_background_image unlink ' . $tmp_file . ']';
}
if (!$this->_dompdf->getOptions()->getDebugKeepTemp()) {
unlink($tmp_file);
}
}
$this->_canvas->clipping_end();
}
/**
* @param $style
* @param $width
* @return array
*/
protected function _get_dash_pattern($style, $width)
{
$pattern = array();
switch ($style) {
default:
/*case "solid":
case "double":
case "groove":
case "inset":
case "outset":
case "ridge":*/
case "none":
break;
case "dotted":
if ($width <= 1) {
$pattern = array($width, $width * 2);
} else {
$pattern = array($width);
}
break;
case "dashed":
$pattern = array(3 * $width);
break;
}
return $pattern;
}
/**
* @param $x
* @param $y
* @param $length
* @param $color
* @param $widths
* @param $side
* @param string $corner_style
* @param int $r1
* @param int $r2
*/
protected function _border_none($x, $y, $length, $color, $widths, $side, $corner_style = "bevel", $r1 = 0, $r2 = 0)
{
return;
}
/**
* @param $x
* @param $y
* @param $length
* @param $color
* @param $widths
* @param $side
* @param string $corner_style
* @param int $r1
* @param int $r2
*/
protected function _border_hidden($x, $y, $length, $color, $widths, $side, $corner_style = "bevel", $r1 = 0, $r2 = 0)
{
return;
}
// Border rendering functions
/**
* @param $x
* @param $y
* @param $length
* @param $color
* @param $widths
* @param $side
* @param string $corner_style
* @param int $r1
* @param int $r2
*/
protected function _border_dotted($x, $y, $length, $color, $widths, $side, $corner_style = "bevel", $r1 = 0, $r2 = 0)
{
$this->_border_line($x, $y, $length, $color, $widths, $side, $corner_style, "dotted", $r1, $r2);
}
/**
* @param $x
* @param $y
* @param $length
* @param $color
* @param $widths
* @param $side
* @param string $corner_style
* @param int $r1
* @param int $r2
*/
protected function _border_dashed($x, $y, $length, $color, $widths, $side, $corner_style = "bevel", $r1 = 0, $r2 = 0)
{
$this->_border_line($x, $y, $length, $color, $widths, $side, $corner_style, "dashed", $r1, $r2);
}
/**
* @param $x
* @param $y
* @param $length
* @param $color
* @param $widths
* @param $side
* @param string $corner_style
* @param int $r1
* @param int $r2
*/
protected function _border_solid($x, $y, $length, $color, $widths, $side, $corner_style = "bevel", $r1 = 0, $r2 = 0)
{
// TODO: Solve rendering where one corner is beveled (radius == 0), one corner isn't.
if ($corner_style !== "bevel" || $r1 > 0 || $r2 > 0) {
// do it the simple way
$this->_border_line($x, $y, $length, $color, $widths, $side, $corner_style, "solid", $r1, $r2);
return;
}
list($top, $right, $bottom, $left) = $widths;
// All this polygon business is for beveled corners...
switch ($side) {
case "top":
$points = array($x, $y,
$x + $length, $y,
$x + $length - $right, $y + $top,
$x + $left, $y + $top);
$this->_canvas->polygon($points, $color, null, null, true);
break;
case "bottom":
$points = array($x, $y,
$x + $length, $y,
$x + $length - $right, $y - $bottom,
$x + $left, $y - $bottom);
$this->_canvas->polygon($points, $color, null, null, true);
break;
case "left":
$points = array($x, $y,
$x, $y + $length,
$x + $left, $y + $length - $bottom,
$x + $left, $y + $top);
$this->_canvas->polygon($points, $color, null, null, true);
break;
case "right":
$points = array($x, $y,
$x, $y + $length,
$x - $right, $y + $length - $bottom,
$x - $right, $y + $top);
$this->_canvas->polygon($points, $color, null, null, true);
break;
default:
return;
}
}
/**
* @param $side
* @param $ratio
* @param $top
* @param $right
* @param $bottom
* @param $left
* @param $x
* @param $y
* @param $length
* @param $r1
* @param $r2
*/
protected function _apply_ratio($side, $ratio, $top, $right, $bottom, $left, &$x, &$y, &$length, &$r1, &$r2)
{
switch ($side) {
case "top":
$r1 -= $left * $ratio;
$r2 -= $right * $ratio;
$x += $left * $ratio;
$y += $top * $ratio;
$length -= $left * $ratio + $right * $ratio;
break;
case "bottom":
$r1 -= $right * $ratio;
$r2 -= $left * $ratio;
$x += $left * $ratio;
$y -= $bottom * $ratio;
$length -= $left * $ratio + $right * $ratio;
break;
case "left":
$r1 -= $top * $ratio;
$r2 -= $bottom * $ratio;
$x += $left * $ratio;
$y += $top * $ratio;
$length -= $top * $ratio + $bottom * $ratio;
break;
case "right":
$r1 -= $bottom * $ratio;
$r2 -= $top * $ratio;
$x -= $right * $ratio;
$y += $top * $ratio;
$length -= $top * $ratio + $bottom * $ratio;
break;
default:
return;
}
}
/**
* @param $x
* @param $y
* @param $length
* @param $color
* @param $widths
* @param $side
* @param string $corner_style
* @param int $r1
* @param int $r2
*/
protected function _border_double($x, $y, $length, $color, $widths, $side, $corner_style = "bevel", $r1 = 0, $r2 = 0)
{
list($top, $right, $bottom, $left) = $widths;
$third_widths = array($top / 3, $right / 3, $bottom / 3, $left / 3);
// draw the outer border
$this->_border_solid($x, $y, $length, $color, $third_widths, $side, $corner_style, $r1, $r2);
$this->_apply_ratio($side, 2 / 3, $top, $right, $bottom, $left, $x, $y, $length, $r1, $r2);
$this->_border_solid($x, $y, $length, $color, $third_widths, $side, $corner_style, $r1, $r2);
}
/**
* @param $x
* @param $y
* @param $length
* @param $color
* @param $widths
* @param $side
* @param string $corner_style
* @param int $r1
* @param int $r2
*/
protected function _border_groove($x, $y, $length, $color, $widths, $side, $corner_style = "bevel", $r1 = 0, $r2 = 0)
{
list($top, $right, $bottom, $left) = $widths;
$half_widths = array($top / 2, $right / 2, $bottom / 2, $left / 2);
$this->_border_inset($x, $y, $length, $color, $half_widths, $side, $corner_style, $r1, $r2);
$this->_apply_ratio($side, 0.5, $top, $right, $bottom, $left, $x, $y, $length, $r1, $r2);
$this->_border_outset($x, $y, $length, $color, $half_widths, $side, $corner_style, $r1, $r2);
}
/**
* @param $x
* @param $y
* @param $length
* @param $color
* @param $widths
* @param $side
* @param string $corner_style
* @param int $r1
* @param int $r2
*/
protected function _border_ridge($x, $y, $length, $color, $widths, $side, $corner_style = "bevel", $r1 = 0, $r2 = 0)
{
list($top, $right, $bottom, $left) = $widths;
$half_widths = array($top / 2, $right / 2, $bottom / 2, $left / 2);
$this->_border_outset($x, $y, $length, $color, $half_widths, $side, $corner_style, $r1, $r2);
$this->_apply_ratio($side, 0.5, $top, $right, $bottom, $left, $x, $y, $length, $r1, $r2);
$this->_border_inset($x, $y, $length, $color, $half_widths, $side, $corner_style, $r1, $r2);
}
/**
* @param $c
* @return mixed
*/
protected function _tint($c)
{
if (!is_numeric($c)) {
return $c;
}
return min(1, $c + 0.16);
}
/**
* @param $c
* @return mixed
*/
protected function _shade($c)
{
if (!is_numeric($c)) {
return $c;
}
return max(0, $c - 0.33);
}
/**
* @param $x
* @param $y
* @param $length
* @param $color
* @param $widths
* @param $side
* @param string $corner_style
* @param int $r1
* @param int $r2
*/
protected function _border_inset($x, $y, $length, $color, $widths, $side, $corner_style = "bevel", $r1 = 0, $r2 = 0)
{
switch ($side) {
case "top":
case "left":
$shade = array_map(array($this, "_shade"), $color);
$this->_border_solid($x, $y, $length, $shade, $widths, $side, $corner_style, $r1, $r2);
break;
case "bottom":
case "right":
$tint = array_map(array($this, "_tint"), $color);
$this->_border_solid($x, $y, $length, $tint, $widths, $side, $corner_style, $r1, $r2);
break;
default:
return;
}
}
/**
* @param $x
* @param $y
* @param $length
* @param $color
* @param $widths
* @param $side
* @param string $corner_style
* @param int $r1
* @param int $r2
*/
protected function _border_outset($x, $y, $length, $color, $widths, $side, $corner_style = "bevel", $r1 = 0, $r2 = 0)
{
switch ($side) {
case "top":
case "left":
$tint = array_map(array($this, "_tint"), $color);
$this->_border_solid($x, $y, $length, $tint, $widths, $side, $corner_style, $r1, $r2);
break;
case "bottom":
case "right":
$shade = array_map(array($this, "_shade"), $color);
$this->_border_solid($x, $y, $length, $shade, $widths, $side, $corner_style, $r1, $r2);
break;
default:
return;
}
}
/**
* Draws a solid, dotted, or dashed line, observing the border radius
*
* @param $x
* @param $y
* @param $length
* @param $color
* @param $widths
* @param $side
* @param string $corner_style
* @param $pattern_name
* @param int $r1
* @param int $r2
*
* @var $top
*/
protected function _border_line($x, $y, $length, $color, $widths, $side, $corner_style = "bevel", $pattern_name, $r1 = 0, $r2 = 0)
{
/** used by $$side */
list($top, $right, $bottom, $left) = $widths;
$width = $$side;
$pattern = $this->_get_dash_pattern($pattern_name, $width);
$half_width = $width / 2;
$r1 -= $half_width;
$r2 -= $half_width;
$adjust = $r1 / 80;
$length -= $width;
switch ($side) {
case "top":
$x += $half_width;
$y += $half_width;
if ($r1 > 0) {
$this->_canvas->arc($x + $r1, $y + $r1, $r1, $r1, 90 - $adjust, 135 + $adjust, $color, $width, $pattern);
}
$this->_canvas->line($x + $r1, $y, $x + $length - $r2, $y, $color, $width, $pattern);
if ($r2 > 0) {
$this->_canvas->arc($x + $length - $r2, $y + $r2, $r2, $r2, 45 - $adjust, 90 + $adjust, $color, $width, $pattern);
}
break;
case "bottom":
$x += $half_width;
$y -= $half_width;
if ($r1 > 0) {
$this->_canvas->arc($x + $r1, $y - $r1, $r1, $r1, 225 - $adjust, 270 + $adjust, $color, $width, $pattern);
}
$this->_canvas->line($x + $r1, $y, $x + $length - $r2, $y, $color, $width, $pattern);
if ($r2 > 0) {
$this->_canvas->arc($x + $length - $r2, $y - $r2, $r2, $r2, 270 - $adjust, 315 + $adjust, $color, $width, $pattern);
}
break;
case "left":
$y += $half_width;
$x += $half_width;
if ($r1 > 0) {
$this->_canvas->arc($x + $r1, $y + $r1, $r1, $r1, 135 - $adjust, 180 + $adjust, $color, $width, $pattern);
}
$this->_canvas->line($x, $y + $r1, $x, $y + $length - $r2, $color, $width, $pattern);
if ($r2 > 0) {
$this->_canvas->arc($x + $r2, $y + $length - $r2, $r2, $r2, 180 - $adjust, 225 + $adjust, $color, $width, $pattern);
}
break;
case "right":
$y += $half_width;
$x -= $half_width;
if ($r1 > 0) {
$this->_canvas->arc($x - $r1, $y + $r1, $r1, $r1, 0 - $adjust, 45 + $adjust, $color, $width, $pattern);
}
$this->_canvas->line($x, $y + $r1, $x, $y + $length - $r2, $color, $width, $pattern);
if ($r2 > 0) {
$this->_canvas->arc($x - $r2, $y + $length - $r2, $r2, $r2, 315 - $adjust, 360 + $adjust, $color, $width, $pattern);
}
break;
}
}
/**
* @param $opacity
*/
protected function _set_opacity($opacity)
{
if (is_numeric($opacity) && $opacity <= 1.0 && $opacity >= 0.0) {
$this->_canvas->set_opacity($opacity);
}
}
/**
* @param $box
* @param string $color
* @param array $style
*/
protected function _debug_layout($box, $color = "red", $style = array())
{
$this->_canvas->rectangle($box[0], $box[1], $box[2], $box[3], Color::parse($color), 0.1, $style);
}
}

View File

@ -1,262 +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\AbstractFrameDecorator;
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();
list($x, $y, $w, $h) = $frame->get_border_box();
$this->_set_opacity($frame->get_opacity($style->opacity));
if ($node->nodeName === "body") {
$h = $frame->get_containing_block("h") - (float)$style->length_in_pt(array(
$style->margin_top,
$style->border_top_width,
$style->border_bottom_width,
$style->margin_bottom),
(float)$style->length_in_pt($style->width));
}
// Handle anchors & links
if ($node->nodeName === "a" && $href = $node->getAttribute("href")) {
$href = Helpers::build_url($this->_dompdf->getProtocol(), $this->_dompdf->getBaseHost(), $this->_dompdf->getBasePath(), $href);
$this->_canvas->add_link($href, $x, $y, (float)$w, (float)$h);
}
// Draw our background, border and content
list($tl, $tr, $br, $bl) = $style->get_computed_border_radius($w, $h);
if ($tl + $tr + $br + $bl > 0) {
$this->_canvas->clipping_roundrectangle($x, $y, (float)$w, (float)$h, $tl, $tr, $br, $bl);
}
if (($bg = $style->background_color) !== "transparent") {
$this->_canvas->filled_rectangle($x, $y, (float)$w, (float)$h, $bg);
}
if (($url = $style->background_image) && $url !== "none") {
$this->_background_image($url, $x, $y, $w, $h, $style);
}
if ($tl + $tr + $br + $bl > 0) {
$this->_canvas->clipping_end();
}
$border_box = array($x, $y, $w, $h);
$this->_render_border($frame, $border_box);
$this->_render_outline($frame, $border_box);
if ($this->_dompdf->getOptions()->getDebugLayout() && $this->_dompdf->getOptions()->getDebugLayoutBlocks()) {
$this->_debug_layout($frame->get_border_box(), "red");
if ($this->_dompdf->getOptions()->getDebugLayoutPaddingBox()) {
$this->_debug_layout($frame->get_padding_box(), "red", array(0.5, 0.5));
}
}
if ($this->_dompdf->getOptions()->getDebugLayout() && $this->_dompdf->getOptions()->getDebugLayoutLines() && $frame->get_decorator()) {
foreach ($frame->get_decorator()->get_line_boxes() as $line) {
$frame->_debug_layout(array($line->x, $line->y, $line->w, $line->h), "orange");
}
}
$id = $frame->get_node()->getAttribute("id");
if (strlen($id) > 0) {
$this->_canvas->add_named_dest($id);
}
}
/**
* @param AbstractFrameDecorator $frame
* @param null $border_box
* @param string $corner_style
*/
protected function _render_border(AbstractFrameDecorator $frame, $border_box = null, $corner_style = "bevel")
{
$style = $frame->get_style();
$bp = $style->get_border_properties();
if (empty($border_box)) {
$border_box = $frame->get_border_box();
}
// find the radius
$radius = $style->get_computed_border_radius($border_box[2], $border_box[3]); // w, h
// 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"], array("solid", "dashed", "dotted")) &&
$bp["top"] == $bp["right"] &&
$bp["right"] == $bp["bottom"] &&
$bp["bottom"] == $bp["left"] &&
array_sum($radius) == 0
) {
$props = $bp["top"];
if ($props["color"] === "transparent" || $props["width"] <= 0) {
return;
}
list($x, $y, $w, $h) = $border_box;
$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, (float)$w - $width, (float)$h - $width, $props["color"], $width, $pattern);
return;
}
// Do it the long way
$widths = array(
(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 = (float)$w;
$r1 = $radius["top-left"];
$r2 = $radius["top-right"];
break;
case "bottom":
$length = (float)$w;
$y += (float)$h;
$r1 = $radius["bottom-left"];
$r2 = $radius["bottom-right"];
break;
case "left":
$length = (float)$h;
$r1 = $radius["top-left"];
$r2 = $radius["bottom-left"];
break;
case "right":
$length = (float)$h;
$x += (float)$w;
$r1 = $radius["top-right"];
$r2 = $radius["bottom-right"];
break;
default:
break;
}
$method = "_border_" . $props["style"];
// draw rounded corners
$this->$method($x, $y, $length, $props["color"], $widths, $side, $corner_style, $r1, $r2);
}
}
/**
* @param AbstractFrameDecorator $frame
* @param null $border_box
* @param string $corner_style
*/
protected function _render_outline(AbstractFrameDecorator $frame, $border_box = null, $corner_style = "bevel")
{
$style = $frame->get_style();
$props = array(
"width" => $style->outline_width,
"style" => $style->outline_style,
"color" => $style->outline_color,
);
if (!$props["style"] || $props["style"] === "none" || $props["width"] <= 0) {
return;
}
if (empty($border_box)) {
$border_box = $frame->get_border_box();
}
$offset = (float)$style->length_in_pt($props["width"]);
$pattern = $this->_get_dash_pattern($props["style"], $offset);
// If the outline style is "solid" we'd better draw a rectangle
if (in_array($props["style"], array("solid", "dashed", "dotted"))) {
$border_box[0] -= $offset / 2;
$border_box[1] -= $offset / 2;
$border_box[2] += $offset;
$border_box[3] += $offset;
list($x, $y, $w, $h) = $border_box;
$this->_canvas->rectangle($x, $y, (float)$w, (float)$h, $props["color"], $offset, $pattern);
return;
}
$border_box[0] -= $offset;
$border_box[1] -= $offset;
$border_box[2] += $offset * 2;
$border_box[3] += $offset * 2;
$method = "_border_" . $props["style"];
$widths = array_fill(0, 4, (float)$style->length_in_pt($props["width"]));
$sides = array("top", "right", "left", "bottom");
$length = 0;
foreach ($sides as $side) {
list($x, $y, $w, $h) = $border_box;
switch ($side) {
case "top":
$length = (float)$w;
break;
case "bottom":
$length = (float)$w;
$y += (float)$h;
break;
case "left":
$length = (float)$h;
break;
case "right":
$length = (float)$h;
$x += (float)$w;
break;
default:
break;
}
$this->$method($x, $y, $length, $props["color"], $widths, $side, $corner_style);
}
}
}

View File

@ -1,139 +0,0 @@
<?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
*/
namespace Dompdf\Renderer;
use Dompdf\Frame;
use Dompdf\Image\Cache;
/**
* Image renderer
*
* @access private
* @package dompdf
*/
class Image extends Block
{
/**
* @param Frame $frame
*/
function render(Frame $frame)
{
// Render background & borders
$style = $frame->get_style();
$cb = $frame->get_containing_block();
list($x, $y, $w, $h) = $frame->get_border_box();
$this->_set_opacity($frame->get_opacity($style->opacity));
list($tl, $tr, $br, $bl) = $style->get_computed_border_radius($w, $h);
$has_border_radius = $tl + $tr + $br + $bl > 0;
if ($has_border_radius) {
$this->_canvas->clipping_roundrectangle($x, $y, (float)$w, (float)$h, $tl, $tr, $br, $bl);
}
if (($bg = $style->background_color) !== "transparent") {
$this->_canvas->filled_rectangle($x, $y, (float)$w, (float)$h, $bg);
}
if (($url = $style->background_image) && $url !== "none") {
$this->_background_image($url, $x, $y, $w, $h, $style);
}
if ($has_border_radius) {
$this->_canvas->clipping_end();
}
$this->_render_border($frame);
$this->_render_outline($frame);
list($x, $y) = $frame->get_padding_box();
$x += (float)$style->length_in_pt($style->padding_left, $cb["w"]);
$y += (float)$style->length_in_pt($style->padding_top, $cb["h"]);
$w = (float)$style->length_in_pt($style->width, $cb["w"]);
$h = (float)$style->length_in_pt($style->height, $cb["h"]);
if ($has_border_radius) {
list($wt, $wr, $wb, $wl) = array(
$style->border_top_width,
$style->border_right_width,
$style->border_bottom_width,
$style->border_left_width,
);
// we have to get the "inner" radius
if ($tl > 0) {
$tl -= ($wt + $wl) / 2;
}
if ($tr > 0) {
$tr -= ($wt + $wr) / 2;
}
if ($br > 0) {
$br -= ($wb + $wr) / 2;
}
if ($bl > 0) {
$bl -= ($wb + $wl) / 2;
}
$this->_canvas->clipping_roundrectangle($x, $y, $w, $h, $tl, $tr, $br, $bl);
}
$src = $frame->get_image_url();
$alt = null;
if (Cache::is_broken($src) &&
$alt = $frame->get_node()->getAttribute("alt")
) {
$font = $style->font_family;
$size = $style->font_size;
$spacing = $style->word_spacing;
$this->_canvas->text(
$x,
$y,
$alt,
$font,
$size,
$style->color,
$spacing
);
} else {
$this->_canvas->image($src, $x, $y, $w, $h, $style->image_resolution);
}
if ($has_border_radius) {
$this->_canvas->clipping_end();
}
if ($msg = $frame->get_image_msg()) {
$parts = preg_split("/\s*\n\s*/", $msg);
$height = 10;
$_y = $alt ? $y + $h - count($parts) * $height : $y;
foreach ($parts as $i => $_part) {
$this->_canvas->text($x, $_y + $i * $height, $_part, "times", $height * 0.8, array(0.5, 0.5, 0.5));
}
}
if ($this->_dompdf->getOptions()->getDebugLayout() && $this->_dompdf->getOptions()->getDebugLayoutBlocks()) {
$this->_debug_layout($frame->get_border_box(), "blue");
if ($this->_dompdf->getOptions()->getDebugLayoutPaddingBox()) {
$this->_debug_layout($frame->get_padding_box(), "blue", array(0.5, 0.5));
}
}
$id = $frame->get_node()->getAttribute("id");
if (strlen($id) > 0) {
$this->_canvas->add_named_dest($id);
}
}
}

View File

@ -1,211 +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
{
/**
* @param Frame $frame
*/
function render(Frame $frame)
{
$style = $frame->get_style();
if (!$frame->get_first_child()) {
return; // No children, no service
}
// Draw the left border if applicable
$bp = $style->get_border_properties();
$widths = array(
(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();
$w = null;
$h = 0;
// $x += $widths[3];
// $y += $widths[0];
$this->_set_opacity($frame->get_opacity($style->opacity));
$first_row = true;
$DEBUGLAYOUTINLINE = $this->_dompdf->getOptions()->getDebugLayout() && $this->_dompdf->getOptions()->getDebugLayoutInline();
foreach ($frame->get_children() as $child) {
list($child_x, $child_y, $child_w, $child_h) = $child->get_padding_box();
if (!is_null($w) && $child_x < $x + $w) {
//This branch seems to be supposed to being called on the first part
//of an inline html element, and the part after the if clause for the
//parts after a line break.
//But because $w initially mostly is 0, and gets updated only on the next
//round, this seem to be never executed and the common close always.
// The next child is on another line. Draw the background &
// borders on this line.
// Background:
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 this is the first row, draw the left border
if ($first_row) {
if ($bp["left"]["style"] !== "none" && $bp["left"]["color"] !== "transparent" && $bp["left"]["width"] > 0) {
$method = "_border_" . $bp["left"]["style"];
$this->$method($x, $y, $h + $widths[0] + $widths[2], $bp["left"]["color"], $widths, "left");
}
$first_row = false;
}
// Draw the top & bottom borders
if ($bp["top"]["style"] !== "none" && $bp["top"]["color"] !== "transparent" && $bp["top"]["width"] > 0) {
$method = "_border_" . $bp["top"]["style"];
$this->$method($x, $y, $w + $widths[1] + $widths[3], $bp["top"]["color"], $widths, "top");
}
if ($bp["bottom"]["style"] !== "none" && $bp["bottom"]["color"] !== "transparent" && $bp["bottom"]["width"] > 0) {
$method = "_border_" . $bp["bottom"]["style"];
$this->$method($x, $y + $h + $widths[0] + $widths[2], $w + $widths[1] + $widths[3], $bp["bottom"]["color"], $widths, "bottom");
}
// Handle anchors & links
$link_node = null;
if ($frame->get_node()->nodeName === "a") {
$link_node = $frame->get_node();
} else if ($frame->get_parent()->get_node()->nodeName === "a") {
$link_node = $frame->get_parent()->get_node();
}
if ($link_node && $href = $link_node->getAttribute("href")) {
$href = Helpers::build_url($this->_dompdf->getProtocol(), $this->_dompdf->getBaseHost(), $this->_dompdf->getBasePath(), $href);
$this->_canvas->add_link($href, $x, $y, $w, $h);
}
$x = $child_x;
$y = $child_y;
$w = (float)$child_w;
$h = (float)$child_h;
continue;
}
if (is_null($w)) {
$w = (float)$child_w;
}else {
$w += (float)$child_w;
}
$h = max($h, $child_h);
if ($DEBUGLAYOUTINLINE) {
$this->_debug_layout($child->get_border_box(), "blue");
if ($this->_dompdf->getOptions()->getDebugLayoutPaddingBox()) {
$this->_debug_layout($child->get_padding_box(), "blue", array(0.5, 0.5));
}
}
}
// 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];
// make sure the border and background start inside the left margin
$left_margin = (float)$style->length_in_pt($style->margin_left);
$x += $left_margin;
// If this is the first row, draw the left border too
if ($first_row && $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");
}
$id = $frame->get_node()->getAttribute("id");
if (strlen($id) > 0) {
$this->_canvas->add_named_dest($id);
}
// Only two levels of links frames
$link_node = null;
if ($frame->get_node()->nodeName === "a") {
$link_node = $frame->get_node();
if (($name = $link_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 ($link_node) {
if ($href = $link_node->getAttribute("href")) {
$href = Helpers::build_url($this->_dompdf->getProtocol(), $this->_dompdf->getBaseHost(), $this->_dompdf->getBasePath(), $href);
$this->_canvas->add_link($href, $x, $y, $w, $h);
}
}
}
}

View File

@ -1,50 +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;
/**
* Renders block frames
*
* @package dompdf
*/
class TableRowGroup extends Block
{
/**
* @param Frame $frame
*/
function render(Frame $frame)
{
$style = $frame->get_style();
$this->_set_opacity($frame->get_opacity($style->opacity));
$this->_render_border($frame);
$this->_render_outline($frame);
if ($this->_dompdf->getOptions()->getDebugLayout() && $this->_dompdf->getOptions()->getDebugLayoutBlocks()) {
$this->_debug_layout($frame->get_border_box(), "red");
if ($this->_dompdf->getOptions()->getDebugLayoutPaddingBox()) {
$this->_debug_layout($frame->get_padding_box(), "red", array(0.5, 0.5));
}
}
if ($this->_dompdf->getOptions()->getDebugLayout() && $this->_dompdf->getOptions()->getDebugLayoutLines() && $frame->get_decorator()) {
foreach ($frame->get_decorator()->get_line_boxes() as $line) {
$frame->_debug_layout(array($line->x, $line->y, $line->w, $line->h), "orange");
}
}
$id = $frame->get_node()->getAttribute("id");
if (strlen($id) > 0) {
$this->_canvas->add_named_dest($id);
}
}
}

View File

@ -0,0 +1,7 @@
<?php
// autoload.php @generated by Composer
require_once __DIR__ . '/composer/autoload_real.php';
return ComposerAutoloaderInit47dfdbccdbe2c66869f4658d0723ed1a::getLoader();

View File

@ -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;
}

View 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;
}
}

View File

@ -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.

View File

@ -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',
);

View File

@ -0,0 +1,9 @@
<?php
// autoload_namespaces.php @generated by Composer
$vendorDir = dirname(dirname(__FILE__));
$baseDir = dirname($vendorDir);
return array(
);

View File

@ -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'),
);

View File

@ -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;
}
}

View File

@ -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);
}
}

View File

@ -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": []
}

View File

@ -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,
),
),
);

View File

@ -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
);
}

View File

@ -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.

View File

@ -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.

View File

@ -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.)*

View File

@ -0,0 +1 @@
2.0.1

View File

@ -0,0 +1,47 @@
{
"name": "dompdf/dompdf",
"type": "library",
"description": "DOMPDF is a CSS 2.1 compliant HTML to PDF converter",
"homepage": "https://github.com/dompdf/dompdf",
"license": "LGPL-2.1",
"authors": [
{
"name": "The Dompdf Community",
"homepage": "https://github.com/dompdf/dompdf/blob/master/AUTHORS.md"
}
],
"autoload": {
"psr-4": {
"Dompdf\\": "src/"
},
"classmap": [
"lib/"
]
},
"autoload-dev": {
"psr-4": {
"Dompdf\\Tests\\": "tests/"
}
},
"require": {
"php": "^7.1 || ^8.0",
"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"
},
"require-dev": {
"ext-json": "*",
"ext-zip": "*",
"phpunit/phpunit": "^7.5 || ^8 || ^9",
"squizlabs/php_codesniffer": "^3.5",
"mockery/mockery": "^1.3"
},
"suggest": {
"ext-gd": "Needed to process images",
"ext-imagick": "Improves image processing performance",
"ext-gmagick": "Improves image processing performance",
"ext-zlib": "Needed for pdf stream compression"
}
}

Some files were not shown because too many files have changed in this diff Show More