How to format text with smallcaps

Mar 6, 2012 at 8:43 AM
Edited Mar 6, 2012 at 9:18 AM

I try to format a textrun in smallcaps but I don't succeed. 

The feature doesn't seem to be available in PHPWORD but I'm not certain.

Does anyone know how to create this feature if it's really unavailable in PW ?

Thanks a lot !

Mar 8, 2012 at 7:57 PM
Edited Mar 8, 2012 at 8:25 PM

I have succeeded in developping this feature.

Follow steps below to add this feature to PHPWord library :

  1. Open file : /PHPWord/Shared/Font.php
  2. Add class property : private $_smallcaps;
  3. Initialize class property like this in constructor : $this->_smallcaps = null;
  4. Open file : PHPWord/Writer/Word2007/Base.php
  5. Implement in _writeTextStyle() function before the next line $objWriter->startElement('w:rPr'); this code : $smallcaps = $style->getSmallcaps();
  6. Implement in _writeTextStyle() function after the next line $objWriter->startElement('w:rPr'); the code  below :

        //Smallcaps
       if(!is_null($smallcaps)) {
           $objWriter->startElement('w:smallCaps');
               $objWriter->writeAttribute('w:val', $smallcaps);
           $objWriter->endElement();
       }

Feature is added !

To use it in a textrun you simply have to do like this :
$yourTextrun->addText('your text',array('smallcaps'=>true));

To use it in a section text you simply have to do like this :
$yourSection->addText('your  text',array('smallcaps'=>true));


Enjoy it !
- - - - - - - - - -
By Larry P.