<?php
class MFont
{
    /** 
     * A list with style attributes.
     */
    public $style;


    public function __construct()
    {
        $this->style     = new MStringList();
    }

    public function __set( $name, $value )
    {
        switch ( $name )
            {
            case 'family':
                $this->addStyle( 'font-family', $value );
                break;
            case 'size':
                $this->addStyle( 'font-size', $value );
                break;
            case 'style':
                $this->addStyle( 'font-style', $value );
                break;
            case 'weight':
                $this->addStyle( 'font-weight', $value );
                break;
            case 'color':
                $this->addStyle( $name, $value );
                break;
            default:
//                $this->addStyle( $name, $value );
//global $MIOLO; $MIOLO->tracestack(); mdump($name . ' - ' . $value);
                break;
            }
    }


    public function __get( $name )
    {
        switch ( $name )
        {
            case 'family':
                return $this->style->get('font-family');
                break;
            case 'size':
                return $this->style->get( 'font-size' );
                break;
            case 'style':
                return $this->style->get( 'font-style' );
                break;
            case 'weight':
                return $this->style->get( 'font-weight' );
                break;
            case 'color':
                return $this->style->get( $name );
                break;
            default:
//                $this->addStyle( $name, $value );
global $MIOLO; $MIOLO->tracestack(); mdump($name . ' - ' . $value);
                break;
        }        
    }

    /** 
     * The clone method.
     * It is used on clone of controls, avoiding references to same styles.
     */
    public function __clone()
    {
        $this->style      = clone $this->style; 
    }

    /** 
     * The setter method.
     */

    public function set($name, $value)
    {
        if ( $value != '' )
        {
            $this->style->addValue($name, $value);
        }
    }

    public function get($name)
    {
        return ( $name != '' ) ? $this->style->get($name) : '';
    }

    public function addStyle($name, $value)
    {
        if ( $value != '' )
        {
            $this->style->addValue($name, $value);
        }
    }

    public function getStyle()
    {
        return $this->style->hasItems() ? ' style="' . $this->style->getText(':', ';') . '"' : '';
    }

}
?>