Stylesheet
in package
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.
Tags
Table of Contents
- DEFAULT_STYLESHEET = "/lib/res/html.css"
- The location of the default built-in CSS file.
- ORIG_AUTHOR = 3
- Author normal stylesheet origin
- ORIG_UA = 1
- User agent stylesheet origin
- ORIG_USER = 2
- User normal stylesheet origin
- SPEC_NON_CSS = 0x20000000
- $ACCEPTED_DEFAULT_MEDIA_TYPE : mixed
- 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 : mixed
- $VALID_MEDIA_TYPES : mixed
- $_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
- Current dompdf instance
- $_loaded_files : array<string|int, mixed>
- List of loaded files, used to prevent recursion
- $_page_styles : array<string|int, Style>
- The styles defined by @page rules
- $_protocol : string
- Base protocol of the document being parsed Used to handle relative urls.
- $_styles : array<string|int, Style>
- Array of currently defined styles
- $_stylesheet_origins : mixed
- $fontMetrics : FontMetrics
- __construct() : mixed
- The class constructor.
- __toString() : string
- dumps the entire stylesheet as a string
- add_style() : mixed
- 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() : mixed
- applies all current styles to a particular document tree
- create_style() : Style
- create a new Style object associated with this stylesheet
- get_base_path() : string
- Return the base path for this stylesheet
- get_dompdf() : Dompdf
- Return the Dompdf object
- get_host() : string
- Return the base host for this stylesheet
- get_page_styles() : array<string|int, Style>
- Return the array of page styles
- get_protocol() : string
- Return the base protocol for this stylesheet
- getDefaultStylesheet() : string
- getFontMetrics() : FontMetrics
- load_css() : mixed
- load and parse a CSS string
- load_css_file() : mixed
- load and parse a CSS file
- lookup() : Style
- lookup a specific Style collection
- set_base_path() : mixed
- Set the base path
- set_host() : mixed
- Set the base host
- set_protocol() : mixed
- Set the base protocol
- setFontMetrics() : $this
- _image() : string
- See also style.cls Style::_image(), refactoring?, works also for imported css files
- _selector_an_plus_b() : string
- https://github.com/tenderlove/nokogiri/blob/master/lib/nokogiri/css/xpath_visitor.rb
- _css_selector_to_xpath() : array<string|int, mixed>
- Converts a CSS selector to an XPath query.
- _parse_css() : mixed
- parse a CSS string using a regex parser Called by {@link Stylesheet::parse_css()}
- _parse_font_face() : mixed
- parse @font-face{} sections http://www.w3.org/TR/css3-fonts/#the-font-face-rule
- _parse_import() : mixed
- parse @import{} sections
- _parse_properties() : Style
- parse regular CSS blocks
- _parse_sections() : mixed
- parse selector + rulesets
- _specificity() : int
Constants
DEFAULT_STYLESHEET
The location of the default built-in CSS file.
public
mixed
DEFAULT_STYLESHEET
= "/lib/res/html.css"
ORIG_AUTHOR
Author normal stylesheet origin
public
int
ORIG_AUTHOR
= 3
ORIG_UA
User agent stylesheet origin
public
int
ORIG_UA
= 1
ORIG_USER
User normal stylesheet origin
public
int
ORIG_USER
= 2
SPEC_NON_CSS
public
mixed
SPEC_NON_CSS
= 0x20000000
Properties
$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.
public
static mixed
$ACCEPTED_DEFAULT_MEDIA_TYPE
= "print"
static, visual, bitmap, paged, dompdf Note, even though the generated pdf file is intended for print output, the desired content might be different (e.g. screen or projection view of html file). Therefore allow specification of content by dompdf setting Options::defaultMediaType. If given, replace media "print" by Options::defaultMediaType. (Previous version $ACCEPTED_MEDIA_TYPES = $ACCEPTED_GENERIC_MEDIA_TYPES + $ACCEPTED_DEFAULT_MEDIA_TYPE)
$ACCEPTED_GENERIC_MEDIA_TYPES
public
static mixed
$ACCEPTED_GENERIC_MEDIA_TYPES
= ["all", "static", "visual", "bitmap", "paged", "dompdf"]
$VALID_MEDIA_TYPES
public
static mixed
$VALID_MEDIA_TYPES
= ["all", "aural", "bitmap", "braille", "dompdf", "embossed", "handheld", "paged", "print", "projection", "screen", "speech", "static", "tty", "tv", "visual"]
$_base_host
Base hostname of the document being parsed Used to handle relative urls.
private
string
$_base_host
$_base_path
Base path of the document being parsed Used to handle relative urls.
private
string
$_base_path
$_current_origin
Current stylesheet origin
private
int
$_current_origin
= self::ORIG_UA
$_dompdf
Current dompdf instance
private
Dompdf
$_dompdf
$_loaded_files
List of loaded files, used to prevent recursion
private
array<string|int, mixed>
$_loaded_files
$_page_styles
The styles defined by @page rules
private
array<string|int, Style>
$_page_styles
$_protocol
Base protocol of the document being parsed Used to handle relative urls.
private
string
$_protocol
$_styles
Array of currently defined styles
private
array<string|int, Style>
$_styles
$_stylesheet_origins
private
static mixed
$_stylesheet_origins
= [
self::ORIG_UA => 0x0,
// user agent declarations
self::ORIG_USER => 0x10000000,
// user normal declarations
self::ORIG_AUTHOR => 0x30000000,
]
$fontMetrics
private
FontMetrics
$fontMetrics
Methods
__construct()
The class constructor.
public
__construct(Dompdf $dompdf) : mixed
The base protocol, host & path are initialized to those of the current script.
Parameters
- $dompdf : Dompdf
Return values
mixed —__toString()
dumps the entire stylesheet as a string
public
__toString() : string
Generates a string of each selector and associated style in the Stylesheet. Useful for debugging.
Return values
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.
public
add_style(string $key, Style $style) : mixed
Parameters
- $key : string
-
the Style's selector
- $style : Style
-
the Style to be added
Tags
Return values
mixed —apply_styles()
applies all current styles to a particular document tree
public
apply_styles(FrameTree $tree) : mixed
apply_styles() applies all currently loaded styles to the provided . Aside from parsing CSS, this is the main purpose of this class.
Parameters
- $tree : FrameTree
Return values
mixed —create_style()
create a new Style object associated with this stylesheet
public
create_style([Style $parent = null ]) : Style
Parameters
- $parent : Style = null
-
The style of this style's parent in the DOM tree
Return values
Style —get_base_path()
Return the base path for this stylesheet
public
get_base_path() : string
Return values
string —get_dompdf()
Return the Dompdf object
public
get_dompdf() : Dompdf
Return values
Dompdf —get_host()
Return the base host for this stylesheet
public
get_host() : string
Return values
string —get_page_styles()
Return the array of page styles
public
get_page_styles() : array<string|int, Style>
Return values
array<string|int, Style> —get_protocol()
Return the base protocol for this stylesheet
public
get_protocol() : string
Return values
string —getDefaultStylesheet()
public
getDefaultStylesheet() : string
Return values
string —getFontMetrics()
public
getFontMetrics() : FontMetrics
Return values
FontMetrics —load_css()
load and parse a CSS string
public
load_css(string &$css[, int $origin = self::ORIG_AUTHOR ]) : mixed
Parameters
- $css : string
- $origin : int = self::ORIG_AUTHOR
Return values
mixed —load_css_file()
load and parse a CSS file
public
load_css_file(string $file[, int $origin = self::ORIG_AUTHOR ]) : mixed
Parameters
- $file : string
- $origin : int = self::ORIG_AUTHOR
Return values
mixed —lookup()
lookup a specific Style collection
public
lookup(string $key) : Style
lookup() returns the Style collection specified by $key, or null if the Style is not found.
Parameters
- $key : string
-
the selector of the requested Style
Tags
Return values
Style —set_base_path()
Set the base path
public
set_base_path(string $path) : mixed
Parameters
- $path : string
Return values
mixed —set_host()
Set the base host
public
set_host(string $host) : mixed
Parameters
- $host : string
Return values
mixed —set_protocol()
Set the base protocol
public
set_protocol(string $protocol) : mixed
Parameters
- $protocol : string
Return values
mixed —setFontMetrics()
public
setFontMetrics(FontMetrics $fontMetrics) : $this
Parameters
- $fontMetrics : FontMetrics
Return values
$this —_image()
See also style.cls Style::_image(), refactoring?, works also for imported css files
protected
_image( $val) : string
Parameters
Return values
string —_selector_an_plus_b()
https://github.com/tenderlove/nokogiri/blob/master/lib/nokogiri/css/xpath_visitor.rb
protected
_selector_an_plus_b( $expr[, bool $last = false ]) : string
Parameters
Return values
string —_css_selector_to_xpath()
Converts a CSS selector to an XPath query.
private
_css_selector_to_xpath(string $selector[, bool $first_pass = false ]) : array<string|int, mixed>
Parameters
- $selector : string
- $first_pass : bool = false
Tags
Return values
array<string|int, mixed> —_parse_css()
parse a CSS string using a regex parser Called by {@link Stylesheet::parse_css()}
private
_parse_css(string $str) : mixed
Parameters
- $str : string
Tags
Return values
mixed —_parse_font_face()
parse @font-face{} sections http://www.w3.org/TR/css3-fonts/#the-font-face-rule
private
_parse_font_face(string $str) : mixed
Parameters
- $str : string
-
CSS @font-face rules
Return values
mixed —_parse_import()
parse @import{} sections
private
_parse_import(string $url) : mixed
Parameters
- $url : string
-
the url of the imported CSS file
Return values
mixed —_parse_properties()
parse regular CSS blocks
private
_parse_properties(string $str) : Style
_parse_properties() creates a new Style object based on the provided CSS rules.
Parameters
- $str : string
-
CSS rules
Return values
Style —_parse_sections()
parse selector + rulesets
private
_parse_sections(string $str[, array<string|int, mixed> $media_queries = [] ]) : mixed
Parameters
- $str : string
-
CSS selectors and rulesets
- $media_queries : array<string|int, mixed> = []
Return values
mixed —_specificity()
private
_specificity(string $selector[, int $origin = self::ORIG_AUTHOR ]) : int
Parameters
- $selector : string
- $origin : int = self::ORIG_AUTHOR
-
:
- Stylesheet::ORIG_UA: user agent style sheet
- Stylesheet::ORIG_USER: user style sheet
- Stylesheet::ORIG_AUTHOR: author style sheet