// $Header: /cvsroot/html2ps/css.visibility.inc.php,v 1.3 2006/04/16 16:54:57 Konstantin Exp $
define('VISIBILITY_VISIBLE', 0);
define('VISIBILITY_HIDDEN', 1);
define('VISIBILITY_COLLAPSE', 2);
// TODO: currently treated is hidden
class CSSVisibility extends CSSProperty
{
    function CSSVisibility()
    {
        $this->CSSProperty(false, false);
    }
    function default_value()
    {
        return VISIBILITY_VISIBLE;
    }
    function parse($value)
    {
        if ($value === 'visible') {
            return VISIBILITY_VISIBLE;
        }
        if ($value === 'hidden') {
            return VISIBILITY_HIDDEN;
        }
        if ($value === 'collapse') {
            return VISIBILITY_COLLAPSE;
        }
        return VISIBILITY_VISIBLE;
    }
}
register_css_property('visibility', new CSSVisibility());
// $Header: /cvsroot/html2ps/css.white-space.inc.php,v 1.5 2006/04/16 16:54:57 Konstantin Exp $
define('WHITESPACE_NORMAL', 0);
define('WHITESPACE_PRE', 1);
define('WHITESPACE_NOWRAP', 2);
class CSSWhiteSpace extends CSSProperty
{
    function CSSWhiteSpace()
    {
        $this->CSSProperty(true, true);
    }
    function default_value()
    {
        return WHITESPACE_NORMAL;
    }
    function parse($value)
    {
        switch ($value) {
            case "normal":
                return WHITESPACE_NORMAL;
            case "pre":
                return WHITESPACE_PRE;
            case "nowrap":
                return WHITESPACE_NOWRAP;
            default:
                return WHITESPACE_NORMAL;
        }
    }
}
register_css_property('white-space', new CSSWhiteSpace());
<?php

class CSSPseudoLinkDestination extends CSSProperty
{
    function CSSPseudoLinkDestination()
    {
        $this->CSSProperty(false, false);
    }
    function default_value()
    {
        return "";
    }
    function parse($value)
    {
        return $value;
    }
}
register_css_property('-html2ps-link-destination', new CSSPseudoLinkDestination());
<?php

// $Header: /cvsroot/html2ps/css.border.collapse.inc.php,v 1.6 2006/04/16 16:54:56 Konstantin Exp $
define('BORDER_COLLAPSE', 1);
define('BORDER_SEPARATE', 2);
class CSSBorderCollapse extends CSSProperty
{
    function CSSBorderCollapse()
    {
        $this->CSSProperty(true, true);
    }
    function default_value()
    {
        return BORDER_SEPARATE;
    }
    function parse($value)
    {
        if ($value === 'collapse') {
            return BORDER_COLLAPSE;
        }
        if ($value === 'separate') {
            return BORDER_SEPARATE;
        }
        return $this->default_value();
    }
}
register_css_property('border-collapse', new CSSBorderCollapse());
<?php

// $Header: /cvsroot/html2ps/css.right.inc.php,v 1.3 2006/03/19 09:25:36 Konstantin Exp $
class CSSRight extends CSSProperty
{
    function CSSRight()
    {
        $this->CSSProperty(false, false);
    }
    function default_value()
    {
        return null;
    }
    function parse($value)
    {
        return $value;
    }
    function pdf()
    {
        return $this->get() === null ? null : units2pt($this->get());
    }
}
register_css_property('right', new CSSRight());
            return PA_LEFT;
        }
        if ($value === 'right') {
            return PA_RIGHT;
        }
        if ($value === 'center') {
            return PA_CENTER;
        }
        // For compatibility with non-valid HTML
        //
        if ($value === 'middle') {
            return PA_CENTER;
        }
        return $this->default_value();
    }
    function value2pdf($value)
    {
        switch ($value) {
            case PA_LEFT:
                return "ta_left";
            case PA_RIGHT:
                return "ta_right";
            case PA_CENTER:
                return "ta_center";
            default:
                return "ta_left";
        }
    }
}
register_css_property('-align', new CSSPseudoAlign());
    {
        $this->CSSProperty(true, true);
    }
    function default_value()
    {
        return "";
    }
    function is_external_link($value)
    {
        return strlen($value) > 0 && $value[0] != "#";
    }
    function is_local_link($value)
    {
        return strlen($value) > 0 && $value[0] == "#";
    }
    function parse($value, &$pipeline)
    {
        // Keep local links (starting with sharp sign) as-is
        if (CSSPseudoLinkTarget::is_local_link($value)) {
            return $value;
        }
        $data = @parse_url($value);
        if (!isset($data['scheme']) || $data['scheme'] == "" || $data['scheme'] == "http") {
            return $pipeline->guess_url($value);
        } else {
            return $value;
        }
    }
}
register_css_property('-html2ps-link-target', new CSSPseudoLinkTarget());
            return new VerticalAlignSub();
        }
        if ($value === VA_TOP) {
            return new VerticalAlignTop();
        }
        if ($value === VA_MIDDLE) {
            return new VerticalAlignMiddle();
        }
        if ($value === VA_BOTTOM) {
            return new VerticalAlignBottom();
        }
        if ($value === VA_BASELINE) {
            return new VerticalAlignBaseline();
        }
        if ($value === VA_TEXT_TOP) {
            return new VerticalAlignTextTop();
        }
        if ($value === VA_TEXT_BOTTOM) {
            return new VerticalAlignTextBottom();
        }
        return new VerticalAlignBaseline();
    }
    function applicable()
    {
        $handler =& get_css_handler('display');
        $display = $handler->get();
        return $display === 'table-cell' || $display === 'table-row' || is_inline_element($display);
    }
}
register_css_property('vertical-align', new CSSVerticalAlign());
    }
    function TextIndentValuePDF($value)
    {
        $this->raw_value = $value;
    }
    function units2pt($base)
    {
        $this->raw_value[0] = units2pt($this->raw_value[0], $base);
    }
}
class CSSTextIndent extends CSSProperty
{
    function CSSTextIndent()
    {
        $this->CSSProperty(true, true);
    }
    function default_value()
    {
        return new TextIndentValuePDF(array(0, false));
    }
    function parse($value)
    {
        if (is_percentage($value)) {
            return new TextIndentValuePDF(array((int) $value, true));
        } else {
            return new TextIndentValuePDF(array($value, false));
        }
    }
}
register_css_property('text-indent', new CSSTextIndent());
    {
        $this->CSSProperty(false, false);
    }
    function default_value()
    {
        return new WCNone();
    }
    function parse($value)
    {
        // Check if user specified empty value
        if ($value === "") {
            return new WCNone();
        }
        // Check if this value is 'auto' - default value of this property
        if ($value === 'auto') {
            return new WCNone();
        }
        if ($value === 'inherit') {
            return new WCFraction(1);
        }
        if (substr($value, strlen($value) - 1, 1) == "%") {
            // Percentage
            return new WCFraction((double) $value / 100);
        } else {
            // Constant
            return new WCConstant(trim($value));
        }
    }
}
register_css_property('width', new CSSWidth());
// $Header: /cvsroot/html2ps/css.clear.inc.php,v 1.7 2006/04/16 16:54:56 Konstantin Exp $
define('CLEAR_NONE', 0);
define('CLEAR_LEFT', 1);
define('CLEAR_RIGHT', 2);
define('CLEAR_BOTH', 3);
class CSSClear extends CSSProperty
{
    function CSSClear()
    {
        $this->CSSProperty(false, false);
    }
    function default_value()
    {
        return CLEAR_NONE;
    }
    function parse($value)
    {
        if ($value === 'left') {
            return CLEAR_LEFT;
        }
        if ($value === 'right') {
            return CLEAR_RIGHT;
        }
        if ($value === 'both') {
            return CLEAR_BOTH;
        }
        return CLEAR_NONE;
    }
}
register_css_property('clear', new CSSClear());
<?php

class CSSPseudoFormRadioGroup extends CSSProperty
{
    function CSSPseudoFormRadioGroup()
    {
        $this->CSSProperty(true, true);
    }
    function default_value()
    {
        return null;
    }
    function parse($value)
    {
        return $value;
    }
}
register_css_property('-html2ps-form-radiogroup', new CSSPseudoFormRadioGroup());
define('OVERFLOW_VISIBLE', 0);
define('OVERFLOW_HIDDEN', 1);
class CSSOverflow extends CSSProperty
{
    function CSSOverflow()
    {
        $this->CSSProperty(false, false);
    }
    function default_value()
    {
        return OVERFLOW_VISIBLE;
    }
    function parse($value)
    {
        switch ($value) {
            case 'hidden':
            case 'scroll':
            case 'auto':
                return OVERFLOW_HIDDEN;
            case 'visible':
            default:
                return OVERFLOW_VISIBLE;
        }
    }
    function pdf()
    {
        return $this->get();
    }
}
register_css_property('overflow', new CSSOverflow());
<?php

// $Header: /cvsroot/html2ps/css.color.inc.php,v 1.10 2006/04/16 16:54:56 Konstantin Exp $
class CSSColor extends CSSProperty
{
    function CSSColor()
    {
        $this->CSSProperty(true, true);
    }
    function default_value()
    {
        return new Color(array(0, 0, 0), false);
    }
    function parse($value)
    {
        $old_color = $this->get();
        $color = parse_color_declaration($value, array($old_color->r, $old_color->g, $old_color->b));
        return new Color($color, is_transparent($color));
    }
}
register_css_property('color', new CSSColor());
<?php

class CSSPseudoFormAction extends CSSProperty
{
    function CSSPseudoFormAction()
    {
        $this->CSSProperty(true, true);
    }
    function default_value()
    {
        return null;
    }
    function parse($value)
    {
        return $value;
    }
}
register_css_property('-html2ps-form-action', new CSSPseudoFormAction());
        $this->CSSProperty(false, false);
    }
    // this pseudo value should be inherited only by the table cells/rows; nested tables
    // should get a default value
    //
    function inherit()
    {
        // Determine parent 'display' value
        $handler =& get_css_handler('display');
        // 'display' CSS property processed AFTER this; so parent display value will be
        // on the top of the stack
        //
        $parent_display = $handler->get();
        // Inherit vertical-align from table-rows
        if ($parent_display === "table-row" || $parent_display === "table") {
            $this->push($this->get());
            return;
        }
        $this->push(is_inline_element($parent_display) ? $this->get() : $this->default_value());
    }
    function default_value()
    {
        return "1px";
    }
    function parse($value)
    {
        return $value;
    }
}
register_css_property('-cellspacing', new CSSCellSpacing());
    {
        $this->CSSProperty(false, true);
    }
    // Inherit text-decoration from inline element (so that <a><i>TEXT</i></a> constructs have TEXT underlined)
    function inherit()
    {
        $handler =& get_css_handler('display');
        $parent_display = $handler->get_parent();
        $this->push(is_inline_element($parent_display) ? $this->get() : $this->default_value());
    }
    function default_value()
    {
        return array("U" => false, "O" => false, "T" => false);
    }
    function parse($value)
    {
        $parsed = $this->default_value();
        if (strstr($value, "overline") !== false) {
            $parsed['O'] = true;
        }
        if (strstr($value, "underline") !== false) {
            $parsed['U'] = true;
        }
        if (strstr($value, "line-through") !== false) {
            $parsed['T'] = true;
        }
        return $parsed;
    }
}
register_css_property("text-decoration", new CSSTextDecoration());
<?php

// $Header: /cvsroot/html2ps/css.content.inc.php,v 1.2 2006/04/16 16:54:57 Konstantin Exp $
class CSSContent extends CSSProperty
{
    function CSSContent()
    {
        $this->CSSProperty(false, false);
    }
    function default_value()
    {
        return "";
    }
    // CSS 2.1 p 12.2:
    // Value: [ <string> | <uri> | <counter> | attr(X) | open-quote | close-quote | no-open-quote | no-close-quote ]+ | inherit
    //
    // TODO: process values other than <string>
    //
    function parse($value)
    {
        return css_remove_value_quotes($value);
    }
}
register_css_property('content', new CSSContent());
<?php

// $Header: /cvsroot/html2ps/css.pseudo.listcounter.inc.php,v 1.2 2005/08/02 15:11:47 Konstantin Exp $
class CSSPseudoListCounter extends CSSProperty
{
    function CSSPseudoListCounter()
    {
        $this->CSSProperty(true, false);
    }
    function default_value()
    {
        return 1;
    }
}
register_css_property('-list-counter', new CSSPseudoListCounter());
<?php

// $Header: /cvsroot/html2ps/css.pseudo.nowrap.inc.php,v 1.4 2006/04/16 16:54:57 Konstantin Exp $
define('NOWRAP_NORMAL', 0);
define('NOWRAP_NOWRAP', 1);
class CSSPseudoNoWrap extends CSSProperty
{
    function CSSPseudoNoWrap()
    {
        $this->CSSProperty(false, false);
    }
    function default_value()
    {
        return NOWRAP_NORMAL;
    }
    function pdf()
    {
        return $this->get();
    }
}
register_css_property('-nowrap', new CSSPseudoNoWrap());
<?php

// $Header: /cvsroot/html2ps/css.bottom.inc.php,v 1.3 2005/12/13 18:24:11 Konstantin Exp $
class CSSBottom extends CSSProperty
{
    function CSSBottom()
    {
        $this->CSSProperty(false, false);
    }
    function default_value()
    {
        return null;
    }
    function parse($value)
    {
        return $value;
    }
}
register_css_property('bottom', new CSSBottom());
        $this->CSSProperty(false, false);
    }
    function inherit()
    {
        // Determine parent 'display' value
        $handler =& get_css_handler('display');
        $parent_display = $handler->get_parent();
        // Inherit vertical-align from table-rows
        if ($parent_display === "table-row") {
            $this->push($this->get());
            return;
        }
        $this->push(is_inline_element($parent_display) ? $this->get() : $this->default_value());
    }
    function default_value()
    {
        return false;
    }
    function parse($value)
    {
        if ($value[strlen($value) - 1] == "%") {
            return array((int) $value, true);
        } else {
            return array($value, false);
        }
    }
}
register_css_property("height", new CSSHeight());
register_css_property("min-height", new CSSMinHeight());
register_css_property("max-height", new CSSMaxHeight());
        if ($value === 'center') {
            return TA_CENTER;
        }
        // For compatibility with non-valid HTML
        //
        if ($value === 'middle') {
            return TA_CENTER;
        }
        if ($value === 'justify') {
            return TA_JUSTIFY;
        }
        return $this->default_value();
    }
    function value2pdf($value)
    {
        switch ($value) {
            case TA_LEFT:
                return "ta_left";
            case TA_RIGHT:
                return "ta_right";
            case TA_CENTER:
                return "ta_center";
            case TA_JUSTIFY:
                return "ta_justify";
            default:
                return "ta_left";
        }
    }
}
register_css_property('text-align', new CSSTextAlign());
<?php

class CSSZIndex extends CSSProperty
{
    function CSSZIndex()
    {
        $this->CSSProperty(false, false);
    }
    function default_value()
    {
        return 0;
    }
    function parse($value)
    {
        return (int) $value;
    }
}
register_css_property('z-index', new CSSZIndex());
class CSSPosition extends CSSProperty
{
    function CSSPosition()
    {
        $this->CSSProperty(false, false);
    }
    function default_value()
    {
        return POSITION_STATIC;
    }
    function parse($value)
    {
        // As usual, though standards say that CSS properties should be lowercase,
        // some people make them uppercase. As we're pretending to be tolerant,
        // we need to convert it to lower case
        switch (strtolower($value)) {
            case "absolute":
                return POSITION_ABSOLUTE;
            case "relative":
                return POSITION_RELATIVE;
            case "fixed":
                return POSITION_FIXED;
            case "static":
                return POSITION_STATIC;
            default:
                return POSITION_STATIC;
        }
    }
}
register_css_property('position', new CSSPosition());
        $this->CSSProperty(false, false);
    }
    // this pseudo value should be inherited only by the table cells/rows; nested tables
    // should get a default value
    //
    function inherit()
    {
        // Determine parent 'display' value
        $handler =& get_css_handler('display');
        // 'display' CSS property processed AFTER this; so parent display value will be
        // on the top of the stack
        //
        $parent_display = $handler->get();
        // Inherit vertical-align from table-rows
        if ($parent_display === "table-row" || $parent_display === "table") {
            $this->push($this->get());
            return;
        }
        $this->push(is_inline_element($parent_display) ? $this->get() : $this->default_value());
    }
    function default_value()
    {
        return "1px";
    }
    function parse($value)
    {
        return $value;
    }
}
register_css_property('-cellpadding', new CSSCellPadding());
        return PaddingSideValue::init($value);
    }
}
class CSSPaddingRight extends CSSSubProperty
{
    function parse($value)
    {
        return PaddingSideValue::init($value);
    }
}
class CSSPaddingLeft extends CSSSubProperty
{
    function parse($value)
    {
        return PaddingSideValue::init($value);
    }
}
class CSSPaddingBottom extends CSSSubProperty
{
    function parse($value)
    {
        return PaddingSideValue::init($value);
    }
}
$ph = new CSSPadding();
register_css_property('padding', $ph);
register_css_property('padding-left', new CSSPaddingLeft($ph, 'left'));
register_css_property('padding-right', new CSSPaddingRight($ph, 'right'));
register_css_property('padding-top', new CSSPaddingTop($ph, 'top'));
register_css_property('padding-bottom', new CSSPaddingBottom($ph, 'bottom'));
Esempio n. 28
0
<?php

// $Header: /cvsroot/html2ps/css.left.inc.php,v 1.4 2006/02/18 13:28:52 Konstantin Exp $
class CSSLeft extends CSSProperty
{
    function CSSLeft()
    {
        $this->CSSProperty(false, false);
    }
    function default_value()
    {
        return null;
    }
    function parse($value)
    {
        $value = trim($value);
        // Check if current value is percentage
        if (substr($value, strlen($value) - 1, 1) === "%") {
            return array((double) $value, true);
        } else {
            return array(units2pt($value), false);
        }
    }
}
register_css_property('left', new CSSLeft());
    function CSSBackground()
    {
        $this->default_value = new Background(CSSBackgroundColor::default_value(), CSSBackgroundImage::default_value(), CSSBackgroundRepeat::default_value(), CSSBackgroundPosition::default_value());
        $this->CSSProperty(false, false);
    }
    function inherit()
    {
        // Determine parent 'display' value
        $handler =& get_css_handler('display');
        // note that as css handlers are evaluated in alphabetic order, parent display value still will be on the top of the stack
        $parent_display = $handler->get();
        // If parent is a table row, inherit the background settings
        $this->push($parent_display == 'table-row' ? $this->get() : $this->default_value());
    }
    function default_value()
    {
        return $this->default_value->copy();
    }
    function parse($value, &$pipeline)
    {
        $background = new Background(CSSBackgroundColor::parse($value), CSSBackgroundImage::parse($value, $pipeline), CSSBackgroundRepeat::parse($value), CSSBackgroundPosition::parse($value));
        return $background;
    }
}
$bg = new CSSBackground();
register_css_property('background', $bg);
register_css_property('background-color', new CSSBackgroundColor($bg, '_color'));
register_css_property('background-image', new CSSBackgroundImage($bg, '_image'));
register_css_property('background-repeat', new CSSBackgroundRepeat($bg, '_repeat'));
register_css_property('background-position', new CSSBackgroundPosition($bg, '_position'));
}
class CSSListStyle extends CSSProperty
{
    // CSS 2.1: list-style is inherited
    function CSSListStyle()
    {
        $this->default_value = new ListStyleValue();
        $this->default_value->image = CSSListStyleImage::default_value();
        $this->default_value->position = CSSListStylePosition::default_value();
        $this->default_value->type = CSSListStyleType::default_value();
        $this->CSSProperty(true, true);
    }
    function parse($value, &$pipeline)
    {
        $style = new ListStyleValue();
        $style->image = CSSListStyleImage::parse($value, $pipeline);
        $style->position = CSSListStylePosition::parse($value);
        $style->type = CSSListStyleType::parse($value);
        return $style;
    }
    function default_value()
    {
        return $this->default_value;
    }
}
$ls = new CSSListStyle();
register_css_property('list-style', $ls);
register_css_property('list-style-image', new CSSListStyleImage($ls, 'image'));
register_css_property('list-style-position', new CSSListStylePosition($ls, 'position'));
register_css_property('list-style-type', new CSSListStyleType($ls, 'type'));