AttributeTranslator
in package
Translates HTML 4.0 attributes into CSS rules
Table of Contents
- $_style_attr : mixed
- $_font_size_lookup : mixed
- $_last_basefont_size : mixed
- $__ATTRIBUTE_LOOKUP : mixed
- append_style() : mixed
- translate_attributes() : mixed
- _get_valid_color() : string
- _resolve_target() : string
- _set_background_color() : string
- _set_basefont_size() : null
- _set_body_link() : null
- _set_color() : string
- _set_font_size() : string
- _set_hr_align() : null|string
- _set_hr_size() : string
- _set_input_width() : null|string
- _set_table_border() : string
- _set_table_cellpadding() : null
- _set_table_cellspacing() : string
- _set_table_row_align() : null
- _set_table_row_bgcolor() : null
- _set_table_row_valign() : null
- _set_table_rules() : null|string
- get_cell_list() : DOMNodeList|array<string|int, DOMElement>
Properties
$_style_attr
public
static mixed
$_style_attr
= "_html_style_attribute"
$_font_size_lookup
protected
static mixed
$_font_size_lookup
= [
// For basefont support
-3 => "4pt",
-2 => "5pt",
-1 => "6pt",
0 => "7pt",
1 => "8pt",
2 => "10pt",
3 => "12pt",
4 => "14pt",
5 => "18pt",
6 => "24pt",
7 => "34pt",
// For basefont support
8 => "48pt",
9 => "44pt",
10 => "52pt",
11 => "60pt",
]
$_last_basefont_size
protected
static mixed
$_last_basefont_size
= 3
$__ATTRIBUTE_LOOKUP
private
static mixed
$__ATTRIBUTE_LOOKUP
= [
//'caption' => array ( 'align' => '', ),
'img' => ['align' => ['bottom' => 'vertical-align: baseline;', 'middle' => 'vertical-align: middle;', 'top' => 'vertical-align: top;', 'left' => 'float: left;', 'right' => 'float: right;'], 'border' => 'border: %0.2Fpx solid;', 'height' => 'height: %spx;', 'hspace' => 'padding-left: %1$0.2Fpx; padding-right: %1$0.2Fpx;', 'vspace' => 'padding-top: %1$0.2Fpx; padding-bottom: %1$0.2Fpx;', 'width' => 'width: %spx;'],
'table' => [
'align' => ['left' => 'margin-left: 0; margin-right: auto;', 'center' => 'margin-left: auto; margin-right: auto;', 'right' => 'margin-left: auto; margin-right: 0;'],
'bgcolor' => 'background-color: %s;',
'border' => '!set_table_border',
'cellpadding' => '!set_table_cellpadding',
//'border-spacing: %0.2F; border-collapse: separate;',
'cellspacing' => '!set_table_cellspacing',
'frame' => ['void' => 'border-style: none;', 'above' => 'border-top-style: solid;', 'below' => 'border-bottom-style: solid;', 'hsides' => 'border-left-style: solid; border-right-style: solid;', 'vsides' => 'border-top-style: solid; border-bottom-style: solid;', 'lhs' => 'border-left-style: solid;', 'rhs' => 'border-right-style: solid;', 'box' => 'border-style: solid;', 'border' => 'border-style: solid;'],
'rules' => '!set_table_rules',
'width' => 'width: %s;',
],
'hr' => [
'align' => '!set_hr_align',
// Need to grab width to set 'left' & 'right' correctly
'noshade' => 'border-style: solid;',
'size' => '!set_hr_size',
//'border-width: %0.2F px;',
'width' => 'width: %s;',
],
'div' => ['align' => 'text-align: %s;'],
'h1' => ['align' => 'text-align: %s;'],
'h2' => ['align' => 'text-align: %s;'],
'h3' => ['align' => 'text-align: %s;'],
'h4' => ['align' => 'text-align: %s;'],
'h5' => ['align' => 'text-align: %s;'],
'h6' => ['align' => 'text-align: %s;'],
//TODO: translate more form element attributes
'input' => ['size' => '!set_input_width'],
'p' => ['align' => 'text-align: %s;'],
// 'col' => array(
// 'align' => '',
// 'valign' => '',
// ),
// 'colgroup' => array(
// 'align' => '',
// 'valign' => '',
// ),
'tbody' => ['align' => '!set_table_row_align', 'valign' => '!set_table_row_valign'],
'td' => ['align' => 'text-align: %s;', 'bgcolor' => '!set_background_color', 'height' => 'height: %s;', 'nowrap' => 'white-space: nowrap;', 'valign' => 'vertical-align: %s;', 'width' => 'width: %s;'],
'tfoot' => ['align' => '!set_table_row_align', 'valign' => '!set_table_row_valign'],
'th' => ['align' => 'text-align: %s;', 'bgcolor' => '!set_background_color', 'height' => 'height: %s;', 'nowrap' => 'white-space: nowrap;', 'valign' => 'vertical-align: %s;', 'width' => 'width: %s;'],
'thead' => ['align' => '!set_table_row_align', 'valign' => '!set_table_row_valign'],
'tr' => ['align' => '!set_table_row_align', 'bgcolor' => '!set_table_row_bgcolor', 'valign' => '!set_table_row_valign'],
'body' => ['background' => 'background-image: url(%s);', 'bgcolor' => '!set_background_color', 'link' => '!set_body_link', 'text' => '!set_color'],
'br' => ['clear' => 'clear: %s;'],
'basefont' => ['color' => '!set_color', 'face' => 'font-family: %s;', 'size' => '!set_basefont_size'],
'font' => ['color' => '!set_color', 'face' => 'font-family: %s;', 'size' => '!set_font_size'],
'dir' => ['compact' => 'margin: 0.5em 0;'],
'dl' => ['compact' => 'margin: 0.5em 0;'],
'menu' => ['compact' => 'margin: 0.5em 0;'],
'ol' => ['compact' => 'margin: 0.5em 0;', 'start' => 'counter-reset: -dompdf-default-counter %d;', 'type' => 'list-style-type: %s;'],
'ul' => ['compact' => 'margin: 0.5em 0;', 'type' => 'list-style-type: %s;'],
'li' => ['type' => 'list-style-type: %s;', 'value' => 'counter-reset: -dompdf-default-counter %d;'],
'pre' => ['width' => 'width: %s;'],
]
Methods
append_style()
public
static append_style(DOMElement $node, string $new_style) : mixed
Parameters
- $node : DOMElement
- $new_style : string
Return values
mixed —translate_attributes()
public
static translate_attributes(Frame $frame) : mixed
Parameters
- $frame : Frame
Return values
mixed —_get_valid_color()
protected
static _get_valid_color(string $value) : string
Parameters
- $value : string
Return values
string —_resolve_target()
protected
static _resolve_target(DOMNode $node, string $target, string $value) : string
Parameters
- $node : DOMNode
- $target : string
- $value : string
Return values
string —_set_background_color()
protected
static _set_background_color(DOMElement $node, string $value) : string
Parameters
- $node : DOMElement
- $value : string
Return values
string —_set_basefont_size()
protected
static _set_basefont_size(DOMElement $node, string $value) : null
Parameters
- $node : DOMElement
- $value : string
Return values
null —_set_body_link()
protected
static _set_body_link(DOMElement $node, string $value) : null
Parameters
- $node : DOMElement
- $value : string
Return values
null —_set_color()
protected
static _set_color(DOMElement $node, string $value) : string
Parameters
- $node : DOMElement
- $value : string
Return values
string —_set_font_size()
protected
static _set_font_size(DOMElement $node, string $value) : string
Parameters
- $node : DOMElement
- $value : string
Return values
string —_set_hr_align()
protected
static _set_hr_align(DOMElement $node, string $value) : null|string
Parameters
- $node : DOMElement
- $value : string
Return values
null|string —_set_hr_size()
protected
static _set_hr_size(DOMElement $node, string $value) : string
Parameters
- $node : DOMElement
- $value : string
Return values
string —_set_input_width()
protected
static _set_input_width(DOMElement $node, string $value) : null|string
Parameters
- $node : DOMElement
- $value : string
Return values
null|string —_set_table_border()
protected
static _set_table_border(DOMElement $node, string $value) : string
Parameters
- $node : DOMElement
- $value : string
Return values
string —_set_table_cellpadding()
protected
static _set_table_cellpadding(DOMElement $node, string $value) : null
Parameters
- $node : DOMElement
- $value : string
Return values
null —_set_table_cellspacing()
protected
static _set_table_cellspacing(DOMElement $node, string $value) : string
Parameters
- $node : DOMElement
- $value : string
Return values
string —_set_table_row_align()
protected
static _set_table_row_align(DOMElement $node, string $value) : null
Parameters
- $node : DOMElement
- $value : string
Return values
null —_set_table_row_bgcolor()
protected
static _set_table_row_bgcolor(DOMElement $node, string $value) : null
Parameters
- $node : DOMElement
- $value : string
Return values
null —_set_table_row_valign()
protected
static _set_table_row_valign(DOMElement $node, string $value) : null
Parameters
- $node : DOMElement
- $value : string
Return values
null —_set_table_rules()
protected
static _set_table_rules(DOMElement $node, string $value) : null|string
Parameters
- $node : DOMElement
- $value : string
Return values
null|string —get_cell_list()
protected
static get_cell_list(DOMNode $node) : DOMNodeList|array<string|int, DOMElement>
Parameters
- $node : DOMNode