Represents CSS properties.
The Style class is responsible for handling and storing CSS properties. It includes methods to resolve colors and lengths, as well as getters & setters for many CSS properties.
Access to the different CSS properties is provided by the methods {@link Style::set_prop()} and {@link Style::get_specified()}, and the property overload methods {@link Style::__set()} and {@link Style::__get()}, as well as {@link Style::set_used()}. The latter methods operate on used values and permit access to any (CSS) property using the following syntax:
$style->margin_top = 10.0;
echo $style->margin_top; // Returns `10.0`
To declare a property from a string, use {@link Style::set_prop()}:
$style->set_prop("margin_top", "1em");
echo $style->get_specified("margin_top"); // Returns `1em`
echo $style->margin_top; // Returns `12.0`, assuming the default font size
Actual CSS parsing is performed in the {@link Stylesheet} class.
| Methods | ||
|---|---|---|
public
|
__construct(Stylesheet $stylesheet, int $origin = Stylesheet::ORIG_AUTHOR)
|
# |
public
|
reset(): void
|
# |
public
|
set_media_queries(array $media_queries): void
|
# |
public
|
get_media_queries(): array
|
# |
public
|
set_frame(Frame $frame): void
|
# |
public
|
get_frame(): Frame|null
|
# |
public
|
set_origin(int $origin): void
|
# |
public
|
get_origin(): int
|
# |
public
|
get_stylesheet(): Stylesheet
|
# |
public
|
is_absolute(): bool
|
# |
public
|
is_in_flow(): bool
|
# |
public
|
length_in_pt(float|string|array $length, float|null $ref_size = null): float|string
|
# |
protected
|
single_length_in_pt(string $l, float $ref_size = 0, float|null $font_size = null): float|null
|
# |
public
|
inherit(Style|null $parent = null): void
|
# |
public
|
merge(Style $style): void
|
# |
public
|
clear_important(): void
|
# |
protected
|
clear_cache(string $prop): void
|
# |
public
|
set_prop(string $prop, mixed $val, bool $important = false, bool $clear_dependencies = true): void
|
# |
public
|
get_specified(string $prop): mixed
|
# |
public
|
__set(string $prop, mixed $val)
|
# |
public
|
set_used(string $prop, mixed $val): void
|
# |
public
|
__get(string $prop): mixed
|
# |
protected
|
compute_prop(string $prop, mixed $val): mixed
|
# |
protected
|
computed(string $prop): mixed
|
# |
public
|
computed_bottom_spacing(float $cbw): float|string|null
|
# |
public
|
munge_color(string|null $color): array|string|null
|
# |
public
|
get_font_family_raw(): string
|
# |
protected
|
_get_font_family(string $computed): string
|
# |
protected
|
_get_word_spacing(float|string $computed): float
|
# |
protected
|
_get_letter_spacing(float|string $computed): float
|
# |
protected
|
_get_line_height(float|string $computed): float
|
# |
protected
|
get_color_value(string $computed, bool $current_is_parent = false): array|string
|
# |
protected
|
_get_color(string $computed): array|string
|
# |
protected
|
_get_background_color(string $computed): array|string
|
# |
protected
|
_get_background_image(string $computed): string
|
# |
protected
|
_get_border_top_color(string $computed): array|string
|
# |
protected
|
_get_border_right_color(string $computed): array|string
|
# |
protected
|
_get_border_bottom_color(string $computed): array|string
|
# |
protected
|
_get_border_left_color(string $computed): array|string
|
# |
public
|
get_border_properties(): array
|
# |
protected
|
get_border_side(string $side): string
|
# |
protected
|
_get_border_top(): string
|
# |
protected
|
_get_border_right(): string
|
# |
protected
|
_get_border_bottom(): string
|
# |
protected
|
_get_border_left(): string
|
# |
public
|
has_border_radius(): bool
|
# |
public
|
resolve_border_radius(float[] $border_box, float[]|null $render_box = null): float[]
|
# |
protected
|
_get_outline_color(string $computed): array|string
|
# |
protected
|
_get_outline_style(string $computed): string
|
# |
protected
|
_get_outline(): string
|
# |
protected
|
_get_list_style_image(string $computed): string
|
# |
protected
|
parse_counter_prop(string $value, int $default): array|string
|
# |
protected
|
_get_counter_increment(string $computed): array|string
|
# |
protected
|
_get_counter_reset(string $computed): array|string
|
# |
protected
|
_get_content(string $computed): string[]|string
|
# |
protected
|
parse_property_value(string $value): string[]
|
# |
protected
|
is_color_value(string $val): bool
|
# |
protected
|
compute_color_value(string $val): string|null
|
# |
protected
|
compute_integer(string $val): int|null
|
# |
protected
|
compute_length(string $val): float|null
|
# |
protected
|
compute_length_positive(string $val): float|null
|
# |
protected
|
compute_length_percentage(string $val): float|string|null
|
# |
protected
|
compute_length_percentage_positive(string $val): float|string|null
|
# |
protected
|
compute_line_width(string $val, string $style_prop): float|null
|
# |
protected
|
compute_border_style(string $val): string|null
|
# |
protected
|
set_quad_shorthand(string $prop, string $value): string[]
|
# |
protected
|
_compute_display(string $val)
|
# |
protected
|
_compute_color(string $color)
|
# |
protected
|
_compute_background_color(string $color)
|
# |
protected
|
_compute_background_image(string $val)
|
# |
protected
|
_compute_background_repeat(string $val)
|
# |
protected
|
_compute_background_attachment(string $val)
|
# |
protected
|
_compute_background_position(string $val)
|
# |
protected
|
_compute_background_size(string $val)
|
# |
protected
|
_set_background(string $value): array
|
# |
protected
|
_compute_font_size(string $size)
|
# |
protected
|
_compute_font_weight(string $weight)
|
# |
protected
|
_set_font(string $value): array
|
# |
protected
|
_compute_text_align(string $val)
|
# |
protected
|
_compute_word_spacing(string $val)
|
# |
protected
|
_compute_letter_spacing(string $val)
|
# |
protected
|
_compute_line_height(string $val)
|
# |
protected
|
_compute_text_indent(string $val)
|
# |
protected
|
_compute_page_break_before(string $break)
|
# |
protected
|
_compute_page_break_after(string $break)
|
# |
protected
|
_compute_width(string $val)
|
# |
protected
|
_compute_height(string $val)
|
# |
protected
|
_compute_min_width(string $val)
|
# |
protected
|
_compute_min_height(string $val)
|
# |
protected
|
_compute_max_width(string $val)
|
# |
protected
|
_compute_max_height(string $val)
|
# |
protected
|
_set_inset(string $val): array
|
# |
protected
|
compute_box_inset(string $val): float|string|null
|
# |
protected
|
_compute_top(string $val)
|
# |
protected
|
_compute_right(string $val)
|
# |
protected
|
_compute_bottom(string $val)
|
# |
protected
|
_compute_left(string $val)
|
# |
protected
|
_set_margin(string $val): array
|
# |
protected
|
compute_margin(string $val): float|string|null
|
# |
protected
|
_compute_margin_top(string $val)
|
# |
protected
|
_compute_margin_right(string $val)
|
# |
protected
|
_compute_margin_bottom(string $val)
|
# |
protected
|
_compute_margin_left(string $val)
|
# |
protected
|
_set_padding(string $val): array
|
# |
protected
|
compute_padding(string $val): float|string|null
|
# |
protected
|
_compute_padding_top(string $val)
|
# |
protected
|
_compute_padding_right(string $val)
|
# |
protected
|
_compute_padding_bottom(string $val)
|
# |
protected
|
_compute_padding_left(string $val)
|
# |
protected
|
parse_border_side(string $value, string[] $styles = self::BORDER_STYLES): array
|
# |
protected
|
_set_border(string $value): array
|
# |
protected
|
set_border_side(string $prop, string $value): array
|
# |
protected
|
_set_border_top(string $val): array
|
# |
protected
|
_set_border_right(string $val): array
|
# |
protected
|
_set_border_bottom(string $val): array
|
# |
protected
|
_set_border_left(string $val): array
|
# |
protected
|
_set_border_color(string $val): array
|
# |
protected
|
_compute_border_top_color(string $val)
|
# |
protected
|
_compute_border_right_color(string $val)
|
# |
protected
|
_compute_border_bottom_color(string $val)
|
# |
protected
|
_compute_border_left_color(string $val)
|
# |
protected
|
_set_border_style(string $val): array
|
# |
protected
|
_compute_border_top_style(string $val)
|
# |
protected
|
_compute_border_right_style(string $val)
|
# |
protected
|
_compute_border_bottom_style(string $val)
|
# |
protected
|
_compute_border_left_style(string $val)
|
# |
protected
|
_set_border_width(string $val): array
|
# |
protected
|
_compute_border_top_width(string $val)
|
# |
protected
|
_compute_border_right_width(string $val)
|
# |
protected
|
_compute_border_bottom_width(string $val)
|
# |
protected
|
_compute_border_left_width(string $val)
|
# |
protected
|
_set_border_radius(string $val): array
|
# |
protected
|
_compute_border_top_left_radius(string $val)
|
# |
protected
|
_compute_border_top_right_radius(string $val)
|
# |
protected
|
_compute_border_bottom_right_radius(string $val)
|
# |
protected
|
_compute_border_bottom_left_radius(string $val)
|
# |
protected
|
_set_outline(string $value): array
|
# |
protected
|
_compute_outline_color(string $val)
|
# |
protected
|
_compute_outline_style(string $val)
|
# |
protected
|
_compute_outline_width(string $val)
|
# |
protected
|
_compute_outline_offset(string $val)
|
# |
protected
|
_compute_border_spacing(string $val)
|
# |
protected
|
_compute_list_style_image(string $val)
|
# |
protected
|
_set_list_style(string $value): array
|
# |
protected
|
_compute_size(string $val)
|
# |
protected
|
_get_transform(string $computed): array
|
# |
protected
|
_get_transform_origin(string $computed): array
|
# |
protected
|
parse_image_resolution(string $val): string|null
|
# |
protected
|
_compute_background_image_resolution(string $val)
|
# |
protected
|
_compute_image_resolution(string $val)
|
# |
protected
|
_compute_orphans(string $val)
|
# |
protected
|
_compute_widows(string $val)
|
# |
protected
|
_compute_opacity(string $val)
|
# |
protected
|
_compute_z_index(string $val)
|
# |
public
|
setFontMetrics(FontMetrics $fontMetrics): $this
|
# |
public
|
getFontMetrics(): FontMetrics
|
# |
public
|
__toString(): string
|
# |
public
|
debug_print(): void
|
# |
| Constants | ||
|---|---|---|
protected
|
CSS_IDENTIFIER = "-?[_a-zA-Z]+[_a-zA-Z0-9-]*"
|
# |
protected
|
CSS_INTEGER = "[+-]?\d+"
|
# |
protected
|
CSS_NUMBER = "[+-]?\d*\.?\d+(?:[eE][+-]?\d+)?"
|
# |
public
|
TEXT_ALIGN_KEYWORDS = ["left", "right", "center", "justify"]
|
# |
public
|
VERTICAL_ALIGN_KEYWORDS = ["baseline", "bottom", "middle", "sub", "super", "text-bottom", "text-top", "top"]
|
# |
public
|
BLOCK_LEVEL_TYPES = ["block", "list-item", "table"]
|
# |
public
|
INLINE_LEVEL_TYPES = ["inline", "inline-block", "inline-table"]
|
# |
public
|
TABLE_INTERNAL_TYPES = [
"table-row-group",
"table-header-group",
"table-footer-group",
"table-row",
"table-cell",
"table-column-group",
"table-column",
"table-caption",
]
|
# |
public
|
INLINE_TYPES = ["inline"]
|
# |
public
|
BLOCK_TYPES = ["block", "inline-block", "table-cell", "list-item"]
|
# |
public
|
TABLE_TYPES = ["table", "inline-table"]
|
# |
public
|
POSITIONED_TYPES = ["relative", "absolute", "fixed"]
|
# |
public
|
BORDER_STYLES = ["none", "hidden", "dotted", "dashed", "solid", "double", "groove", "ridge", "inset", "outset"]
|
# |
protected
|
OUTLINE_STYLES = ["auto", "none", "dotted", "dashed", "solid", "double", "groove", "ridge", "inset", "outset"]
|
# |
| Properties | |||
|---|---|---|---|
public
static
|
float
|
$default_font_size = 12
|
# |
public
static
|
float
|
$default_line_height = 1.2
|
# |
public
static
|
array<float>
|
$font_size_keywords = [
"xx-small" => 0.6,
"x-small" => 0.75,
"small" => 0.889,
"medium" => 1,
"large" => 1.2,
"x-large" => 1.5,
"xx-large" => 2.0,
]
|
# |
protected
static
|
array
|
$valid_display_types = []
|
# |
protected
static
|
array
|
$_props_shorthand = [
"background" => [
"background_image",
"background_position",
"background_size",
"background_repeat",
"background_attachment",
"background_color",
],
"border" => [
"border_top_width",
"border_right_width",
"border_bottom_width",
"border_left_width",
"border_top_style",
"border_right_style",
"border_bottom_style",
"border_left_style",
"border_top_color",
"border_right_color",
"border_bottom_color",
"border_left_color",
],
"border_top" => ["border_top_width", "border_top_style", "border_top_color"],
"border_right" => ["border_right_width", "border_right_style", "border_right_color"],
"border_bottom" => ["border_bottom_width", "border_bottom_style", "border_bottom_color"],
"border_left" => ["border_left_width", "border_left_style", "border_left_color"],
"border_width" => ["border_top_width", "border_right_width", "border_bottom_width", "border_left_width"],
"border_style" => ["border_top_style", "border_right_style", "border_bottom_style", "border_left_style"],
"border_color" => ["border_top_color", "border_right_color", "border_bottom_color", "border_left_color"],
"border_radius" => [
"border_top_left_radius",
"border_top_right_radius",
"border_bottom_right_radius",
"border_bottom_left_radius",
],
"font" => ["font_family", "font_size", "font_style", "font_variant", "font_weight", "line_height"],
"inset" => ["top", "right", "bottom", "left"],
"list_style" => ["list_style_image", "list_style_position", "list_style_type"],
"margin" => ["margin_top", "margin_right", "margin_bottom", "margin_left"],
"padding" => ["padding_top", "padding_right", "padding_bottom", "padding_left"],
"outline" => ["outline_width", "outline_style", "outline_color"],
]
|
# |
protected
static
|
array
|
$_props_alias = [
"word_wrap" => "overflow_wrap",
"_dompdf_background_image_resolution" => "background_image_resolution",
"_dompdf_image_resolution" => "image_resolution",
"_webkit_transform" => "transform",
"_webkit_transform_origin" => "transform_origin",
]
|
# |
protected
static
|
array
|
$_defaults = null
|
# |
protected
static
|
array
|
$_inherited = null
|
# |
protected
static
|
array<bool>
|
$_methods_cache = []
|
# |
protected
|
Stylesheet
|
$_stylesheet
|
# |
protected
|
array
|
$_media_queries
|
# |
protected
|
array
|
$_important_props = []
|
# |
protected
|
array
|
$_props = []
|
# |
protected
|
array
|
$_props_computed = []
|
# |
protected
|
array
|
$_props_used = []
|
# |
protected
|
array
|
$non_final_used = []
|
# |
protected
static
|
|
$_dependency_map = [
"border_top_style" => ["border_top_width"],
"border_bottom_style" => ["border_bottom_width"],
"border_left_style" => ["border_left_width"],
"border_right_style" => ["border_right_width"],
"direction" => ["text_align"],
"font_size" => [
"background_position",
"background_size",
"border_top_width",
"border_right_width",
"border_bottom_width",
"border_left_width",
"border_top_left_radius",
"border_top_right_radius",
"border_bottom_right_radius",
"border_bottom_left_radius",
"letter_spacing",
"line_height",
"margin_top",
"margin_right",
"margin_bottom",
"margin_left",
"outline_width",
"outline_offset",
"padding_top",
"padding_right",
"padding_bottom",
"padding_left",
"word_spacing",
"width",
"height",
"min-width",
"min-height",
"max-width",
"max-height",
],
"float" => ["display"],
"position" => ["display"],
"outline_style" => ["outline_width"],
]
|
# |
protected
static
|
array
|
$_dependent_props = []
|
# |
protected
|
Style
|
$parent_style
|
# |
protected
|
Frame|null
|
$_frame
|
# |
protected
|
int
|
$_origin = Stylesheet::ORIG_AUTHOR
|
# |
private
|
float|string|null
|
$_computed_bottom_spacing = null
|
# |
private
|
bool|null
|
$has_border_radius_cache = null
|
# |
private
|
array|null
|
$resolved_border_radius = null
|
# |
private
|
FontMetrics
|
$fontMetrics
|
# |
public
|
string
|
$azimuth
|
# |
public
|
string
|
$background_attachment
|
# |
public
|
array|string
|
$background_color
|
# |
public
|
string
|
$background_image
|
# |
public
|
string
|
$background_image_resolution
|
# |
public
|
array
|
$background_position
|
# |
public
|
string
|
$background_repeat
|
# |
public
|
array|string
|
$background_size
|
# |
public
|
string
|
$border_collapse
|
# |
public
|
string
|
$border_color
|
# |
public
|
float[]
|
$border_spacing
|
# |
public
|
string
|
$border_style
|
# |
public
|
array|string
|
$border_top_color
|
# |
public
|
array|string
|
$border_right_color
|
# |
public
|
array|string
|
$border_bottom_color
|
# |
public
|
array|string
|
$border_left_color
|
# |
public
|
string
|
$border_top_style
|
# |
public
|
string
|
$border_right_style
|
# |
public
|
string
|
$border_bottom_style
|
# |
public
|
string
|
$border_left_style
|
# |
public
|
float
|
$border_top_width
|
# |
public
|
float
|
$border_right_width
|
# |
public
|
float
|
$border_bottom_width
|
# |
public
|
float
|
$border_left_width
|
# |
public
|
string
|
$border_width
|
# |
public
|
float|string
|
$border_bottom_left_radius
|
# |
public
|
float|string
|
$border_bottom_right_radius
|
# |
public
|
float|string
|
$border_top_left_radius
|
# |
public
|
float|string
|
$border_top_right_radius
|
# |
public
|
string
|
$border_radius
|
# |
public
|
float|string
|
$bottom
|
# |
public
|
string
|
$caption_side
|
# |
public
|
string
|
$clear
|
# |
public
|
string
|
$clip
|
# |
public
|
array|string
|
$color
|
# |
public
|
string[]|string
|
$content
|
# |
public
|
array|string
|
$counter_increment
|
# |
public
|
array|string
|
$counter_reset
|
# |
public
|
string
|
$cue_after
|
# |
public
|
string
|
$cue_before
|
# |
public
|
string
|
$cue
|
# |
public
|
string
|
$cursor
|
# |
public
|
string
|
$direction
|
# |
public
|
string
|
$display
|
# |
public
|
string
|
$elevation
|
# |
public
|
string
|
$empty_cells
|
# |
public
|
string
|
$float
|
# |
public
|
string
|
$font_family
|
# |
public
|
float
|
$font_size
|
# |
public
|
string
|
$font_style
|
# |
public
|
string
|
$font_variant
|
# |
public
|
string
|
$font_weight
|
# |
public
|
float|string
|
$height
|
# |
public
|
string
|
$image_resolution
|
# |
public
|
string
|
$inset
|
# |
public
|
float|string
|
$left
|
# |
public
|
float
|
$letter_spacing
|
# |
public
|
float
|
$line_height
|
# |
public
|
string
|
$list_style_image
|
# |
public
|
string
|
$list_style_position
|
# |
public
|
string
|
$list_style_type
|
# |
public
|
float|string
|
$margin_right
|
# |
public
|
float|string
|
$margin_left
|
# |
public
|
float|string
|
$margin_top
|
# |
public
|
float|string
|
$margin_bottom
|
# |
public
|
string
|
$margin
|
# |
public
|
float|string
|
$max_height
|
# |
public
|
float|string
|
$max_width
|
# |
public
|
float|string
|
$min_height
|
# |
public
|
float|string
|
$min_width
|
# |
public
|
float
|
$opacity
|
# |
public
|
int
|
$orphans
|
# |
public
|
array|string
|
$outline_color
|
# |
public
|
string
|
$outline_style
|
# |
public
|
float
|
$outline_width
|
# |
public
|
float
|
$outline_offset
|
# |
public
|
string
|
$overflow
|
# |
public
|
string
|
$overflow_wrap
|
# |
public
|
float|string
|
$padding_top
|
# |
public
|
float|string
|
$padding_right
|
# |
public
|
float|string
|
$padding_bottom
|
# |
public
|
float|string
|
$padding_left
|
# |
public
|
string
|
$padding
|
# |
public
|
string
|
$page_break_after
|
# |
public
|
string
|
$page_break_before
|
# |
public
|
string
|
$page_break_inside
|
# |
public
|
string
|
$pause_after
|
# |
public
|
string
|
$pause_before
|
# |
public
|
string
|
$pause
|
# |
public
|
string
|
$pitch_range
|
# |
public
|
string
|
$pitch
|
# |
public
|
string
|
$play_during
|
# |
public
|
string
|
$position
|
# |
public
|
string
|
$quotes
|
# |
public
|
string
|
$richness
|
# |
public
|
float|string
|
$right
|
# |
public
|
float[]|string
|
$size
|
# |
public
|
string
|
$speak_header
|
# |
public
|
string
|
$speak_numeral
|
# |
public
|
string
|
$speak_punctuation
|
# |
public
|
string
|
$speak
|
# |
public
|
string
|
$speech_rate
|
# |
public
|
string
|
$src
|
# |
public
|
string
|
$stress
|
# |
public
|
string
|
$table_layout
|
# |
public
|
string
|
$text_align
|
# |
public
|
string
|
$text_decoration
|
# |
public
|
float|string
|
$text_indent
|
# |
public
|
string
|
$text_transform
|
# |
public
|
float|string
|
$top
|
# |
public
|
array
|
$transform
|
# |
public
|
array
|
$transform_origin
|
# |
public
|
string
|
$unicode_bidi
|
# |
public
|
string
|
$unicode_range
|
# |
public
|
string
|
$vertical_align
|
# |
public
|
string
|
$visibility
|
# |
public
|
string
|
$voice_family
|
# |
public
|
string
|
$volume
|
# |
public
|
string
|
$white_space
|
# |
public
|
int
|
$widows
|
# |
public
|
float|string
|
$width
|
# |
public
|
string
|
$word_break
|
# |
public
|
float
|
$word_spacing
|
# |
public
|
int|string
|
$z_index
|
# |
public
|
string
|
$_dompdf_keep
|
# |