Dompdf\Css\Stylesheet
The master stylesheet class
The Stylesheet class is responsible for parsing stylesheets and style
tags/attributes. It also acts as a registry of the individual Style
objects generated by the current set of loaded CSS files and style
elements.
Synopsis
class Stylesheet
{
- // constants
- const DEFAULT_STYLESHEET = "/lib/res/html.css";
- const ORIG_UA = 1;
- const ORIG_USER = 2;
- const ORIG_AUTHOR = 3;
- const SPEC_NON_CSS = 0x20000000;
- // members
- private static array $_stylesheet_origins = ;
- private Dompdf $_dompdf;
- private $_styles;
- private $_protocol;
- private $_base_host;
- private $_base_path;
- private array<Style> $_page_styles;
- private $_loaded_files;
- private int $_current_origin = self::ORIG_UA;
- public static string $ACCEPTED_DEFAULT_MEDIA_TYPE = "print";
- public static array $ACCEPTED_GENERIC_MEDIA_TYPES = ;
- public static array $VALID_MEDIA_TYPES = ;
- private FontMetrics $fontMetrics;
- // methods
- public void __construct()
- public void set_protocol()
- public void set_host()
- public void set_base_path()
- public Dompdf get_dompdf()
- public string get_protocol()
- public string get_host()
- public string get_base_path()
- public array get_page_styles()
- public void add_style()
- public Style lookup()
- public Style create_style()
- public void load_css()
- public void load_css_file()
- private int _specificity()
- private string _css_selector_to_xpath()
- protected string _selector_an_plus_b()
- public void apply_styles()
- private void _parse_css()
- protected string _image()
- private void _parse_import()
- private void _parse_font_face()
- private Style _parse_properties()
- private void _parse_sections()
- public static string getDefaultStylesheet()
- public $this setFontMetrics()
- public FontMetrics getFontMetrics()
- public string __toString()
Constants
Name | Value |
---|---|
DEFAULT_STYLESHEET | "/lib/res/html.css" |
ORIG_UA | 1 |
ORIG_USER | 2 |
ORIG_AUTHOR | 3 |
SPEC_NON_CSS | 0x20000000 |
Members
private
- $_base_host
—
string
Base hostname of the document being parsed Used to handle relative urls. - $_base_path
—
string
Base path of the document being parsed Used to handle relative urls. - $_current_origin
—
int
Current stylesheet origin - $_dompdf
—
Dompdf\Dompdf
Current dompdf instance - $_loaded_files
—
array
List of loaded files, used to prevent recursion - $_page_styles
—
Dompdf\Css\array<Style>
The styles defined by @page rules - $_protocol
—
string
Base protocol of the document being parsed Used to handle relative urls. - $_styles
—
array
Array of currently defined styles - $_stylesheet_origins
- $fontMetrics — Dompdf\FontMetrics
public
-
$ACCEPTED_DEFAULT_MEDIA_TYPE
Accepted CSS media types List of types and parsing rules for future extensions: http://www.w3.org/TR/REC-html40/types.html screen, tty, tv, projection, handheld, print, braille, aural, all The following are non standard extensions for undocumented specific environments. - $ACCEPTED_GENERIC_MEDIA_TYPES
- $VALID_MEDIA_TYPES
Methods
private
- _css_selector_to_xpath() — Converts a CSS selector to an XPath query.
- _parse_css() — parse a CSS string using a regex parser Called by {@link Stylesheet::parse_css()}
- _parse_font_face() — parse @font-face{} sections http://www.w3.org/TR/css3-fonts/#the-font-face-rule
- _parse_import() — parse @import{} sections
- _parse_properties() — parse regular CSS blocks
- _parse_sections() — parse selector + rulesets
- _specificity()
protected
- _image() — See also style.cls Style::_image(), refactoring?, works also for imported css files
- _selector_an_plus_b() — https://github.com/tenderlove/nokogiri/blob/master/lib/nokogiri/css/xpath_visitor.rb
public
- __construct() — The class constructor.
- __toString() — dumps the entire stylesheet as a string
- add_style() — Add a new Style object to the stylesheet add_style() adds a new Style object to the current stylesheet, or merges a new Style with an existing one.
- apply_styles() — applies all current styles to a particular document tree
- create_style() — create a new Style object associated with this stylesheet
- getDefaultStylesheet()
- getFontMetrics()
- get_base_path() — Return the base path for this stylesheet
- get_dompdf() — Return the Dompdf object
- get_host() — Return the base host for this stylesheet
- get_page_styles() — Return the array of page styles
- get_protocol() — Return the base protocol for this stylesheet
- load_css() — load and parse a CSS string
- load_css_file() — load and parse a CSS file
- lookup() — lookup a specifc Style collection
- setFontMetrics()
- set_base_path() — Set the base path
- set_host() — Set the base host
- set_protocol() — Set the base protocol