function o_pattern( $id, $action, $options = '' )
    {
        if ( $action != 'new' )
        {
            $o =& $this->objects[$id];
        }

        switch ( $action )
        {
            case 'new':
            {
                $this->objects[$id] = array( 't' => 'shading',
                                             'info' => array() );

                if ( isset( $options['type'] ) ) //Set pattern type
                {
                    $this->objects[$id]['info']['PatternType'] = $options['type'];
                }
                else
                {
                    $this->objects[$id]['info']['PatternType'] = '2';
                }

                if ( isset( $options['matrix'] ) )
                {
                    $this->objects[$id]['info']['Matrix'] = '[ ';
                    foreach ( $options['matrix'] as $coord )
                    {
                        $this->objects[$id]['info']['Matrix'] .= sprintf( ' %.3F ', $coord );
                    }
                    $this->objects[$id]['info']['Matrix'] .= ' ]';
                }

                if ( $this->objects[$id]['info']['PatternType'] == 1 ) // Pattern type 1, tiling pattern
                {
                    $this->objects[$id]['info']['PaintType'] = $options['paintType'];
                    $this->objects[$id]['info']['TilingType'] = $options['tilingType'];

                    $this->objects[$id]['info']['BBox'] = '[ ';
                    foreach ( $options['bbox'] as $coord )
                    {
                        $this->objects[$id]['info']['BBox'] .= sprintf( ' %.3F ', $coord );
                    }
                    $this->objects[$id]['info']['BBox'] .= ']';

                    $this->objects[$id]['info']['XStep'] = $options['xstep'];
                    $this->objects[$id]['info']['YStep'] = $options['ystep'];
                }
                else // Non tiling, smooth pattern.
                {
                    if ( isset( $options['shading'] ) )
                    {
                        $this->objects[$id]['info']['Shading'] = $options['shading'] . ' R';
                    }
                }
            } break;

            case 'out':
            {
                $res = "\n" . $id . " 0 obj\n<< ";
                foreach ( $this->objects[$id]['info'] as $key => $info )
                {
                    $res .= '/' . $key . ' ' . $info[$key] . "\n";
                }
                $res .= ">>\nendobject";
                return $res;
            } break;
        }
    }