/**
  */
 public function testControlCharacters()
 {
     $this->assertEquals('', Text::controlCharacterPHP2OOXML());
     $this->assertEquals('aeiou', Text::controlCharacterPHP2OOXML('aeiou'));
     $this->assertEquals('àéîöù', Text::controlCharacterPHP2OOXML('àéîöù'));
     $value = rand(0, 8);
     $this->assertEquals('_x' . sprintf('%04s', strtoupper(dechex($value))) . '_', Text::controlCharacterPHP2OOXML(chr($value)));
     $this->assertEquals('', Text::controlCharacterOOXML2PHP(''));
     $this->assertEquals(chr(0x8), Text::controlCharacterOOXML2PHP('_x0008_'));
 }
Beispiel #2
0
 /**
  * Write paragraphs
  *
  * @param  \PhpOffice\Common\XMLWriter           $objWriter  XML Writer
  * @param  \PhpOffice\PhpPresentation\Shape\RichText\Paragraph[] $paragraphs
  * @throws \Exception
  */
 private function writeParagraphs(XMLWriter $objWriter, $paragraphs)
 {
     // Loop trough paragraphs
     foreach ($paragraphs as $paragraph) {
         // a:p
         $objWriter->startElement('a:p');
         // a:pPr
         $objWriter->startElement('a:pPr');
         $objWriter->writeAttribute('algn', $paragraph->getAlignment()->getHorizontal());
         $objWriter->writeAttribute('fontAlgn', $paragraph->getAlignment()->getVertical());
         $objWriter->writeAttribute('marL', CommonDrawing::pixelsToEmu($paragraph->getAlignment()->getMarginLeft()));
         $objWriter->writeAttribute('marR', CommonDrawing::pixelsToEmu($paragraph->getAlignment()->getMarginRight()));
         $objWriter->writeAttribute('indent', CommonDrawing::pixelsToEmu($paragraph->getAlignment()->getIndent()));
         $objWriter->writeAttribute('lvl', $paragraph->getAlignment()->getLevel());
         // Bullet type specified?
         if ($paragraph->getBulletStyle()->getBulletType() != Bullet::TYPE_NONE) {
             // a:buFont
             $objWriter->startElement('a:buFont');
             $objWriter->writeAttribute('typeface', $paragraph->getBulletStyle()->getBulletFont());
             $objWriter->endElement();
             if ($paragraph->getBulletStyle()->getBulletType() == Bullet::TYPE_BULLET) {
                 // a:buChar
                 $objWriter->startElement('a:buChar');
                 $objWriter->writeAttribute('char', $paragraph->getBulletStyle()->getBulletChar());
                 $objWriter->endElement();
             } elseif ($paragraph->getBulletStyle()->getBulletType() == Bullet::TYPE_NUMERIC) {
                 // a:buAutoNum
                 $objWriter->startElement('a:buAutoNum');
                 $objWriter->writeAttribute('type', $paragraph->getBulletStyle()->getBulletNumericStyle());
                 if ($paragraph->getBulletStyle()->getBulletNumericStartAt() != 1) {
                     $objWriter->writeAttribute('startAt', $paragraph->getBulletStyle()->getBulletNumericStartAt());
                 }
                 $objWriter->endElement();
             }
         }
         $objWriter->endElement();
         // Loop trough rich text elements
         $elements = $paragraph->getRichTextElements();
         foreach ($elements as $element) {
             if ($element instanceof BreakElement) {
                 // a:br
                 $objWriter->writeElement('a:br', null);
             } elseif ($element instanceof Run || $element instanceof TextElement) {
                 // a:r
                 $objWriter->startElement('a:r');
                 // a:rPr
                 if ($element instanceof Run) {
                     // a:rPr
                     $objWriter->startElement('a:rPr');
                     // Bold
                     $objWriter->writeAttribute('b', $element->getFont()->isBold() ? '1' : '0');
                     // Italic
                     $objWriter->writeAttribute('i', $element->getFont()->isItalic() ? '1' : '0');
                     // Strikethrough
                     $objWriter->writeAttribute('strike', $element->getFont()->isStrikethrough() ? 'sngStrike' : 'noStrike');
                     // Size
                     $objWriter->writeAttribute('sz', $element->getFont()->getSize() * 100);
                     // Underline
                     $objWriter->writeAttribute('u', $element->getFont()->getUnderline());
                     // Superscript / subscript
                     if ($element->getFont()->isSuperScript() || $element->getFont()->isSubScript()) {
                         if ($element->getFont()->isSuperScript()) {
                             $objWriter->writeAttribute('baseline', '30000');
                         } elseif ($element->getFont()->isSubScript()) {
                             $objWriter->writeAttribute('baseline', '-25000');
                         }
                     }
                     // Color - a:solidFill
                     $objWriter->startElement('a:solidFill');
                     // a:srgbClr
                     $objWriter->startElement('a:srgbClr');
                     $objWriter->writeAttribute('val', $element->getFont()->getColor()->getRGB());
                     $objWriter->endElement();
                     $objWriter->endElement();
                     // Font - a:latin
                     $objWriter->startElement('a:latin');
                     $objWriter->writeAttribute('typeface', $element->getFont()->getName());
                     $objWriter->endElement();
                     // a:hlinkClick
                     if ($element->hasHyperlink()) {
                         $this->writeHyperlink($objWriter, $element);
                     }
                     $objWriter->endElement();
                 }
                 // t
                 $objWriter->startElement('a:t');
                 $objWriter->writeCData(Text::controlCharacterPHP2OOXML($element->getText()));
                 $objWriter->endElement();
                 $objWriter->endElement();
             }
         }
         $objWriter->endElement();
     }
 }
 /**
  * Convert text to valid format
  *
  * @param string $text
  * @return string
  */
 protected function getText($text)
 {
     return CommonText::controlCharacterPHP2OOXML($text);
 }