1<?php
2/*
3*  Module written/ported by Xavier Noguer <xnoguer@rezebra.com>
4*
5*  The majority of this is _NOT_ my code.  I simply ported it from the
6*  PERL Spreadsheet::WriteExcel module.
7*
8*  The author of the Spreadsheet::WriteExcel module is John McNamara
9*  <jmcnamara@cpan.org>
10*
11*  I _DO_ maintain this code, and John McNamara has nothing to do with the
12*  porting of this code to PHP.  Any questions directly related to this
13*  class library should be directed to me.
14*
15*  License Information:
16*
17*    Spreadsheet_Excel_Writer:  A library for generating Excel Spreadsheets
18*    Copyright (c) 2002-2003 Xavier Noguer xnoguer@rezebra.com
19*
20*    This library is free software; you can redistribute it and/or
21*    modify it under the terms of the GNU Lesser General Public
22*    License as published by the Free Software Foundation; either
23*    version 2.1 of the License, or (at your option) any later version.
24*
25*    This library is distributed in the hope that it will be useful,
26*    but WITHOUT ANY WARRANTY; without even the implied warranty of
27*    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
28*    Lesser General Public License for more details.
29*
30*    You should have received a copy of the GNU Lesser General Public
31*    License along with this library; if not, write to the Free Software
32*    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
33*/
34
35/**
36* Class for generating Excel XF records (formats)
37*
38* @author   Xavier Noguer <xnoguer@rezebra.com>
39* @category FileFormats
40* @package  Spreadsheet_Excel_Writer
41*/
42
43class Spreadsheet_Excel_Writer_Format extends PEAR
44{
45    /**
46    * The index given by the workbook when creating a new format.
47    * @var integer
48    */
49    var $_xf_index;
50
51    /**
52    * Index to the FONT record.
53    * @var integer
54    */
55    var $font_index;
56
57    /**
58    * The font name (ASCII).
59    * @var string
60    */
61    var $_font_name;
62
63    /**
64    * Height of font (1/20 of a point)
65    * @var integer
66    */
67    var $_size;
68
69    /**
70    * Bold style
71    * @var integer
72    */
73    var $_bold;
74
75    /**
76    * Bit specifiying if the font is italic.
77    * @var integer
78    */
79    var $_italic;
80
81    /**
82    * Index to the cell's color
83    * @var integer
84    */
85    var $_color;
86
87    /**
88    * The text underline property
89    * @var integer
90    */
91    var $_underline;
92
93    /**
94    * Bit specifiying if the font has strikeout.
95    * @var integer
96    */
97    var $_font_strikeout;
98
99    /**
100    * Bit specifiying if the font has outline.
101    * @var integer
102    */
103    var $_font_outline;
104
105    /**
106    * Bit specifiying if the font has shadow.
107    * @var integer
108    */
109    var $_font_shadow;
110
111    /**
112    * 2 bytes specifiying the script type for the font.
113    * @var integer
114    */
115    var $_font_script;
116
117    /**
118    * Byte specifiying the font family.
119    * @var integer
120    */
121    var $_font_family;
122
123    /**
124    * Byte specifiying the font charset.
125    * @var integer
126    */
127    var $_font_charset;
128
129    /**
130    * An index (2 bytes) to a FORMAT record (number format).
131    * @var integer
132    */
133    var $_num_format;
134
135    /**
136    * Bit specifying if formulas are hidden.
137    * @var integer
138    */
139    var $_hidden;
140
141    /**
142    * Bit specifying if the cell is locked.
143    * @var integer
144    */
145    var $_locked;
146
147    /**
148    * The three bits specifying the text horizontal alignment.
149    * @var integer
150    */
151    var $_text_h_align;
152
153    /**
154    * Bit specifying if the text is wrapped at the right border.
155    * @var integer
156    */
157    var $_text_wrap;
158
159    /**
160    * The three bits specifying the text vertical alignment.
161    * @var integer
162    */
163    var $_text_v_align;
164
165    /**
166    * 1 bit, apparently not used.
167    * @var integer
168    */
169    var $_text_justlast;
170
171    /**
172    * The two bits specifying the text rotation.
173    * @var integer
174    */
175    var $_rotation;
176
177    /**
178    * The cell's foreground color.
179    * @var integer
180    */
181    var $_fg_color;
182
183    /**
184    * The cell's background color.
185    * @var integer
186    */
187    var $_bg_color;
188
189    /**
190    * The cell's background fill pattern.
191    * @var integer
192    */
193    var $_pattern;
194
195    /**
196    * Style of the bottom border of the cell
197    * @var integer
198    */
199    var $_bottom;
200
201    /**
202    * Color of the bottom border of the cell.
203    * @var integer
204    */
205    var $_bottom_color;
206
207    /**
208    * Style of the top border of the cell
209    * @var integer
210    */
211    var $_top;
212
213    /**
214    * Color of the top border of the cell.
215    * @var integer
216    */
217    var $_top_color;
218
219    /**
220    * Style of the left border of the cell
221    * @var integer
222    */
223    var $_left;
224
225    /**
226    * Color of the left border of the cell.
227    * @var integer
228    */
229    var $_left_color;
230
231    /**
232    * Style of the right border of the cell
233    * @var integer
234    */
235    var $_right;
236
237    /**
238    * Color of the right border of the cell.
239    * @var integer
240    */
241    var $_right_color;
242
243    /**
244    * Constructor
245    *
246    * @access private
247    * @param integer $index the XF index for the format.
248    * @param array   $properties array with properties to be set on initialization.
249    */
250    function __construct($BIFF_version, $index = 0, $properties =  array())
251    {
252        $this->_xf_index       = $index;
253        $this->_BIFF_version   = $BIFF_version;
254        $this->font_index      = 0;
255        $this->_font_name      = 'Arial';
256        $this->_size           = 10;
257        $this->_bold           = 0x0190;
258        $this->_italic         = 0;
259        $this->_color          = 0x7FFF;
260        $this->_underline      = 0;
261        $this->_font_strikeout = 0;
262        $this->_font_outline   = 0;
263        $this->_font_shadow    = 0;
264        $this->_font_script    = 0;
265        $this->_font_family    = 0;
266        $this->_font_charset   = 0;
267
268        $this->_num_format     = 0;
269
270        $this->_hidden         = 0;
271        $this->_locked         = 0;
272
273        $this->_text_h_align   = 0;
274        $this->_text_wrap      = 0;
275        $this->_text_v_align   = 2;
276        $this->_text_justlast  = 0;
277        $this->_rotation       = 0;
278
279        $this->_fg_color       = 0x40;
280        $this->_bg_color       = 0x41;
281
282        $this->_pattern        = 0;
283
284        $this->_bottom         = 0;
285        $this->_top            = 0;
286        $this->_left           = 0;
287        $this->_right          = 0;
288        $this->_diag           = 0;
289
290        $this->_bottom_color   = 0x40;
291        $this->_top_color      = 0x40;
292        $this->_left_color     = 0x40;
293        $this->_right_color    = 0x40;
294        $this->_diag_color     = 0x40;
295
296        // Set properties passed to Spreadsheet_Excel_Writer_Workbook::addFormat()
297        foreach($properties as $property => $value)
298        {
299            if(method_exists($this,'set'.ucwords($property)))
300            {
301                $method_name = 'set'.ucwords($property);
302                $this->$method_name($value);
303            }
304        }
305    }
306
307
308    /**
309    * Generate an Excel BIFF XF record (style or cell).
310    *
311    * @param string $style The type of the XF record ('style' or 'cell').
312    * @return string The XF record
313    */
314    function getXf($style)
315    {
316        // Set the type of the XF record and some of the attributes.
317        if ($style == "style") {
318            $style = 0xFFF5;
319        }
320        else {
321            $style   = $this->_locked;
322            $style  |= $this->_hidden << 1;
323        }
324
325        // Flags to indicate if attributes have been set.
326        $atr_num     = ($this->_num_format != 0)?1:0;
327        $atr_fnt     = ($this->font_index != 0)?1:0;
328        $atr_alc     = ($this->_text_wrap)?1:0;
329        $atr_bdr     = ($this->_bottom   ||
330                        $this->_top      ||
331                        $this->_left     ||
332                        $this->_right)?1:0;
333        $atr_pat     = (($this->_fg_color != 0x40) ||
334                        ($this->_bg_color != 0x41) ||
335                        $this->_pattern)?1:0;
336        $atr_prot    = $this->_locked | $this->_hidden;
337
338        // Zero the default border colour if the border has not been set.
339        if ($this->_bottom == 0) {
340            $this->_bottom_color = 0;
341        }
342        if ($this->_top  == 0) {
343            $this->_top_color = 0;
344        }
345        if ($this->_right == 0) {
346            $this->_right_color = 0;
347        }
348        if ($this->_left == 0) {
349            $this->_left_color = 0;
350        }
351        if ($this->_diag == 0) {
352            $this->_diag_color = 0;
353        }
354
355        $record         = 0x00E0;              // Record identifier
356        if ($this->_BIFF_version == 0x0500) {
357            $length         = 0x0010;              // Number of bytes to follow
358        }
359        if ($this->_BIFF_version == 0x0600) {
360            $length         = 0x0014;
361        }
362
363        $ifnt           = $this->font_index;   // Index to FONT record
364        $ifmt           = $this->_num_format;  // Index to FORMAT record
365        if ($this->_BIFF_version == 0x0500)
366        {
367            $align          = $this->_text_h_align;       // Alignment
368            $align         |= $this->_text_wrap     << 3;
369            $align         |= $this->_text_v_align  << 4;
370            $align         |= $this->_text_justlast << 7;
371            $align         |= $this->_rotation      << 8;
372            $align         |= $atr_num                << 10;
373            $align         |= $atr_fnt                << 11;
374            $align         |= $atr_alc                << 12;
375            $align         |= $atr_bdr                << 13;
376            $align         |= $atr_pat                << 14;
377            $align         |= $atr_prot               << 15;
378
379            $icv            = $this->_fg_color;       // fg and bg pattern colors
380            $icv           |= $this->_bg_color      << 7;
381
382            $fill           = $this->_pattern;        // Fill and border line style
383            $fill          |= $this->_bottom        << 6;
384            $fill          |= $this->_bottom_color  << 9;
385
386            $border1        = $this->_top;            // Border line style and color
387            $border1       |= $this->_left          << 3;
388            $border1       |= $this->_right         << 6;
389            $border1       |= $this->_top_color     << 9;
390
391            $border2        = $this->_left_color;     // Border color
392            $border2       |= $this->_right_color   << 7;
393
394            $header      = pack("vv",       $record, $length);
395            $data        = pack("vvvvvvvv", $ifnt, $ifmt, $style, $align,
396                                            $icv, $fill,
397                                            $border1, $border2);
398        }
399        elseif ($this->_BIFF_version == 0x0600)
400        {
401            $align          = $this->_text_h_align;       // Alignment
402            $align         |= $this->_text_wrap     << 3;
403            $align         |= $this->_text_v_align  << 4;
404            $align         |= $this->_text_justlast << 7;
405
406            $used_attrib    = $atr_num              << 2;
407            $used_attrib   |= $atr_fnt              << 3;
408            $used_attrib   |= $atr_alc              << 4;
409            $used_attrib   |= $atr_bdr              << 5;
410            $used_attrib   |= $atr_pat              << 6;
411            $used_attrib   |= $atr_prot             << 7;
412
413            $icv            = $this->_fg_color;      // fg and bg pattern colors
414            $icv           |= $this->_bg_color      << 7;
415
416            $border1        = $this->_left;          // Border line style and color
417            $border1       |= $this->_right         << 4;
418            $border1       |= $this->_top           << 8;
419            $border1       |= $this->_bottom        << 12;
420            $border1       |= $this->_left_color    << 16;
421            $border1       |= $this->_right_color   << 23;
422            $diag_tl_to_rb = 0; // FIXME: add method
423            $diag_tr_to_lb = 0; // FIXME: add method
424            $border1       |= $diag_tl_to_rb        << 30;
425            $border1       |= $diag_tr_to_lb        << 31;
426
427            $border2        = $this->_top_color;    // Border color
428            $border2       |= $this->_bottom_color   << 7;
429            $border2       |= $this->_diag_color     << 14;
430            $border2       |= $this->_diag           << 21;
431            $border2       |= $this->_pattern        << 26;
432
433            $header      = pack("vv",       $record, $length);
434
435            $rotation      = 0x00;
436            $biff8_options = 0x00;
437            $data  = pack("vvvC", $ifnt, $ifmt, $style, $align);
438            $data .= pack("CCC", $rotation, $biff8_options, $used_attrib);
439            $data .= pack("VVv", $border1, $border2, $icv);
440        }
441
442        return($header.$data);
443    }
444
445    /**
446    * Generate an Excel BIFF FONT record.
447    *
448    * @return string The FONT record
449    */
450    function getFont()
451    {
452        $dyHeight   = $this->_size * 20;    // Height of font (1/20 of a point)
453        $icv        = $this->_color;        // Index to color palette
454        $bls        = $this->_bold;         // Bold style
455        $sss        = $this->_font_script;  // Superscript/subscript
456        $uls        = $this->_underline;    // Underline
457        $bFamily    = $this->_font_family;  // Font family
458        $bCharSet   = $this->_font_charset; // Character set
459        $encoding   = 0;                    // TODO: Unicode support
460
461        $cch        = strlen($this->_font_name); // Length of font name
462        $record     = 0x31;                      // Record identifier
463        if ($this->_BIFF_version == 0x0500) {
464            $length     = 0x0F + $cch;            // Record length
465        }
466        elseif ($this->_BIFF_version == 0x0600) {
467            $length     = 0x10 + $cch;
468        }
469        $reserved   = 0x00;                // Reserved
470        $grbit      = 0x00;                // Font attributes
471        if ($this->_italic) {
472            $grbit     |= 0x02;
473        }
474        if ($this->_font_strikeout) {
475            $grbit     |= 0x08;
476        }
477        if ($this->_font_outline) {
478            $grbit     |= 0x10;
479        }
480        if ($this->_font_shadow) {
481            $grbit     |= 0x20;
482        }
483
484        $header  = pack("vv",         $record, $length);
485        if ($this->_BIFF_version == 0x0500) {
486            $data    = pack("vvvvvCCCCC", $dyHeight, $grbit, $icv, $bls,
487                                          $sss, $uls, $bFamily,
488                                          $bCharSet, $reserved, $cch);
489        }
490        elseif ($this->_BIFF_version == 0x0600) {
491            $data    = pack("vvvvvCCCCCC", $dyHeight, $grbit, $icv, $bls,
492                                           $sss, $uls, $bFamily,
493                                           $bCharSet, $reserved, $cch, $encoding);
494        }
495        return($header . $data. $this->_font_name);
496    }
497
498    /**
499    * Returns a unique hash key for a font.
500    * Used by Spreadsheet_Excel_Writer_Workbook::_storeAllFonts()
501    *
502    * The elements that form the key are arranged to increase the probability of
503    * generating a unique key. Elements that hold a large range of numbers
504    * (eg. _color) are placed between two binary elements such as _italic
505    *
506    * @return string A key for this font
507    */
508    function getFontKey()
509    {
510        $key  = "$this->_font_name$this->_size";
511        $key .= "$this->_font_script$this->_underline";
512        $key .= "$this->_font_strikeout$this->_bold$this->_font_outline";
513        $key .= "$this->_font_family$this->_font_charset";
514        $key .= "$this->_font_shadow$this->_color$this->_italic";
515        $key  = str_replace(" ","_",$key);
516        return ($key);
517    }
518
519    /**
520    * Returns the index used by Spreadsheet_Excel_Writer_Worksheet::_XF()
521    *
522    * @return integer The index for the XF record
523    */
524    function getXfIndex()
525    {
526        return($this->_xf_index);
527    }
528
529    /**
530    * Used in conjunction with the set_xxx_color methods to convert a color
531    * string into a number. Color range is 0..63 but we will restrict it
532    * to 8..63 to comply with Gnumeric. Colors 0..7 are repeated in 8..15.
533    *
534    * @access private
535    * @param string $name_color name of the color (i.e.: 'blue', 'red', etc..). Optional.
536    * @return integer The color index
537    */
538    function _getColor($name_color = '')
539    {
540        $colors = array(
541                        'aqua'    => 0x0F,
542                        'cyan'    => 0x0F,
543                        'black'   => 0x08,
544                        'blue'    => 0x0C,
545                        'brown'   => 0x10,
546                        'magenta' => 0x0E,
547                        'fuchsia' => 0x0E,
548                        'gray'    => 0x17,
549                        'grey'    => 0x17,
550                        'green'   => 0x11,
551                        'lime'    => 0x0B,
552                        'navy'    => 0x12,
553                        'orange'  => 0x35,
554                        'purple'  => 0x14,
555                        'red'     => 0x0A,
556                        'silver'  => 0x16,
557                        'white'   => 0x09,
558                        'yellow'  => 0x0D
559                       );
560
561        // Return the default color, 0x7FFF, if undef,
562        if($name_color == '') {
563            return(0x7FFF);
564        }
565
566        // or the color string converted to an integer,
567        if(isset($colors[$name_color])) {
568            return($colors[$name_color]);
569        }
570
571        // or the default color if string is unrecognised,
572        if(preg_match("/\D/",$name_color)) {
573            return(0x7FFF);
574        }
575
576        // or an index < 8 mapped into the correct range,
577        if($name_color < 8) {
578            return($name_color + 8);
579        }
580
581        // or the default color if arg is outside range,
582        if($name_color > 63) {
583            return(0x7FFF);
584        }
585
586        // or an integer in the valid range
587        return($name_color);
588    }
589
590    /**
591    * Set cell alignment.
592    *
593    * @access public
594    * @param string $location alignment for the cell ('left', 'right', etc...).
595    */
596    function setAlign($location)
597    {
598        if (preg_match("/\d/",$location)) {
599            return;                      // Ignore numbers
600        }
601
602        $location = strtolower($location);
603
604        if ($location == 'left') {
605            $this->_text_h_align = 1;
606        }
607        if ($location == 'centre') {
608            $this->_text_h_align = 2;
609        }
610        if ($location == 'center') {
611            $this->_text_h_align = 2;
612        }
613        if ($location == 'right') {
614            $this->_text_h_align = 3;
615        }
616        if ($location == 'fill') {
617            $this->_text_h_align = 4;
618        }
619        if ($location == 'justify') {
620            $this->_text_h_align = 5;
621        }
622        if ($location == 'merge') {
623            $this->_text_h_align = 6;
624        }
625        if ($location == 'equal_space') { // For T.K.
626            $this->_text_h_align = 7;
627        }
628        if ($location == 'top') {
629            $this->_text_v_align = 0;
630        }
631        if ($location == 'vcentre') {
632            $this->_text_v_align = 1;
633        }
634        if ($location == 'vcenter') {
635            $this->_text_v_align = 1;
636        }
637        if ($location == 'bottom') {
638            $this->_text_v_align = 2;
639        }
640        if ($location == 'vjustify') {
641            $this->_text_v_align = 3;
642        }
643        if ($location == 'vequal_space') { // For T.K.
644            $this->_text_v_align = 4;
645        }
646    }
647
648    /**
649    * This is an alias for the unintuitive setAlign('merge')
650    *
651    * @access public
652    */
653    function setMerge()
654    {
655        $this->setAlign('merge');
656    }
657
658    /**
659    * Sets the boldness of the text.
660    * Bold has a range 100..1000.
661    * 0 (400) is normal. 1 (700) is bold.
662    *
663    * @access public
664    * @param integer $weight Weight for the text, 0 maps to 400 (normal text),
665                             1 maps to 700 (bold text). Valid range is: 100-1000.
666                             It's Optional, default is 1 (bold).
667    */
668    function setBold($weight = 1)
669    {
670        if($weight == 1) {
671            $weight = 0x2BC;  // Bold text
672        }
673        if($weight == 0) {
674            $weight = 0x190;  // Normal text
675        }
676        if($weight <  0x064) {
677            $weight = 0x190;  // Lower bound
678        }
679        if($weight >  0x3E8) {
680            $weight = 0x190;  // Upper bound
681        }
682        $this->_bold = $weight;
683    }
684
685
686    /************************************
687    * FUNCTIONS FOR SETTING CELLS BORDERS
688    */
689
690    /**
691    * Sets the width for the bottom border of the cell
692    *
693    * @access public
694    * @param integer $style style of the cell border. 1 => thin, 2 => thick.
695    */
696    function setBottom($style)
697    {
698        $this->_bottom = $style;
699    }
700
701    /**
702    * Sets the width for the top border of the cell
703    *
704    * @access public
705    * @param integer $style style of the cell top border. 1 => thin, 2 => thick.
706    */
707    function setTop($style)
708    {
709        $this->_top = $style;
710    }
711
712    /**
713    * Sets the width for the left border of the cell
714    *
715    * @access public
716    * @param integer $style style of the cell left border. 1 => thin, 2 => thick.
717    */
718    function setLeft($style)
719    {
720        $this->_left = $style;
721    }
722
723    /**
724    * Sets the width for the right border of the cell
725    *
726    * @access public
727    * @param integer $style style of the cell right border. 1 => thin, 2 => thick.
728    */
729    function setRight($style)
730    {
731        $this->_right = $style;
732    }
733
734
735    /**
736    * Set cells borders to the same style
737    *
738    * @access public
739    * @param integer $style style to apply for all cell borders. 1 => thin, 2 => thick.
740    */
741    function setBorder($style)
742    {
743        $this->setBottom($style);
744        $this->setTop($style);
745        $this->setLeft($style);
746        $this->setRight($style);
747    }
748
749
750    /*******************************************
751    * FUNCTIONS FOR SETTING CELLS BORDERS COLORS
752    */
753
754    /**
755    * Sets all the cell's borders to the same color
756    *
757    * @access public
758    * @param mixed $color The color we are setting. Either a string (like 'blue'),
759    *                     or an integer (range is [8...63]).
760    */
761    function setBorderColor($color)
762    {
763        $this->setBottomColor($color);
764        $this->setTopColor($color);
765        $this->setLeftColor($color);
766        $this->setRightColor($color);
767    }
768
769    /**
770    * Sets the cell's bottom border color
771    *
772    * @access public
773    * @param mixed $color either a string (like 'blue'), or an integer (range is [8...63]).
774    */
775    function setBottomColor($color)
776    {
777        $value = $this->_getColor($color);
778        $this->_bottom_color = $value;
779    }
780
781    /**
782    * Sets the cell's top border color
783    *
784    * @access public
785    * @param mixed $color either a string (like 'blue'), or an integer (range is [8...63]).
786    */
787    function setTopColor($color)
788    {
789        $value = $this->_getColor($color);
790        $this->_top_color = $value;
791    }
792
793    /**
794    * Sets the cell's left border color
795    *
796    * @access public
797    * @param mixed $color either a string (like 'blue'), or an integer (range is [8...63]).
798    */
799    function setLeftColor($color)
800    {
801        $value = $this->_getColor($color);
802        $this->_left_color = $value;
803    }
804
805    /**
806    * Sets the cell's right border color
807    *
808    * @access public
809    * @param mixed $color either a string (like 'blue'), or an integer (range is [8...63]).
810    */
811    function setRightColor($color)
812    {
813        $value = $this->_getColor($color);
814        $this->_right_color = $value;
815    }
816
817
818    /**
819    * Sets the cell's foreground color
820    *
821    * @access public
822    * @param mixed $color either a string (like 'blue'), or an integer (range is [8...63]).
823    */
824    function setFgColor($color)
825    {
826        $value = $this->_getColor($color);
827        $this->_fg_color = $value;
828        if ($this->_pattern == 0) { // force color to be seen
829            $this->_pattern = 1;
830        }
831    }
832
833    /**
834    * Sets the cell's background color
835    *
836    * @access public
837    * @param mixed $color either a string (like 'blue'), or an integer (range is [8...63]).
838    */
839    function setBgColor($color)
840    {
841        $value = $this->_getColor($color);
842        $this->_bg_color = $value;
843        if ($this->_pattern == 0) { // force color to be seen
844            $this->_pattern = 1;
845        }
846    }
847
848    /**
849    * Sets the cell's color
850    *
851    * @access public
852    * @param mixed $color either a string (like 'blue'), or an integer (range is [8...63]).
853    */
854    function setColor($color)
855    {
856        $value = $this->_getColor($color);
857        $this->_color = $value;
858    }
859
860    /**
861    * Sets the fill pattern attribute of a cell
862    *
863    * @access public
864    * @param integer $arg Optional. Defaults to 1. Meaningful values are: 0-18,
865    *                     0 meaning no background.
866    */
867    function setPattern($arg = 1)
868    {
869        $this->_pattern = $arg;
870    }
871
872    /**
873    * Sets the underline of the text
874    *
875    * @access public
876    * @param integer $underline The value for underline. Possible values are:
877    *                          1 => underline, 2 => double underline.
878    */
879    function setUnderline($underline)
880    {
881        $this->_underline = $underline;
882    }
883
884    /**
885    * Sets the font style as italic
886    *
887    * @access public
888    */
889    function setItalic()
890    {
891        $this->_italic = 1;
892    }
893
894    /**
895    * Sets the font size
896    *
897    * @access public
898    * @param integer $size The font size (in pixels I think).
899    */
900    function setSize($size)
901    {
902        $this->_size = $size;
903    }
904
905    /**
906    * Sets text wrapping
907    *
908    * @access public
909    */
910    function setTextWrap()
911    {
912        $this->_text_wrap = 1;
913    }
914
915    /**
916    * Sets the orientation of the text
917    *
918    * @access public
919    * @param integer $angle The rotation angle for the text (clockwise). Possible
920                            values are: 0, 90, 270 and -1 for stacking top-to-bottom.
921    */
922    function setTextRotation($angle)
923    {
924        switch ($angle)
925        {
926            case 0:
927                $this->_rotation = 0;
928                break;
929            case 90:
930                $this->_rotation = 3;
931                break;
932            case 270:
933                $this->_rotation = 2;
934                break;
935            case -1:
936                $this->_rotation = 1;
937                break;
938            default :
939                return $this->raiseError("Invalid value for angle.".
940                                  " Possible values are: 0, 90, 270 and -1 ".
941                                  "for stacking top-to-bottom.");
942                $this->_rotation = 0;
943                break;
944        }
945    }
946
947    /**
948    * Sets the numeric format.
949    * It can be date, time, currency, etc...
950    *
951    * @access public
952    * @param integer $num_format The numeric format.
953    */
954    function setNumFormat($num_format)
955    {
956        $this->_num_format = $num_format;
957    }
958
959    /**
960    * Sets font as strikeout.
961    *
962    * @access public
963    */
964    function setStrikeOut()
965    {
966        $this->_font_strikeout = 1;
967    }
968
969    /**
970    * Sets outlining for a font.
971    *
972    * @access public
973    */
974    function setOutLine()
975    {
976        $this->_font_outline = 1;
977    }
978
979    /**
980    * Sets font as shadow.
981    *
982    * @access public
983    */
984    function setShadow()
985    {
986        $this->_font_shadow = 1;
987    }
988
989    /**
990    * Sets the script type of the text
991    *
992    * @access public
993    * @param integer $script The value for script type. Possible values are:
994    *                        1 => superscript, 2 => subscript.
995    */
996    function setScript($script)
997    {
998        $this->_font_script = $script;
999    }
1000
1001     /**
1002     * Locks a cell.
1003     *
1004     * @access public
1005     */
1006     function setLocked()
1007     {
1008         $this->_locked = 1;
1009     }
1010
1011    /**
1012    * Unlocks a cell. Useful for unprotecting particular cells of a protected sheet.
1013    *
1014    * @access public
1015    */
1016    function setUnLocked()
1017    {
1018        $this->_locked = 0;
1019    }
1020
1021    /**
1022    * Sets the font family name.
1023    *
1024    * @access public
1025    * @param string $fontfamily The font family name. Possible values are:
1026    *                           'Times New Roman', 'Arial', 'Courier'.
1027    */
1028    function setFontFamily($font_family)
1029    {
1030        $this->_font_name = $font_family;
1031    }
1032}
1033