public function testOffsetX() { $object = new RichText(); $value = rand(1, 100); $this->assertInstanceOf('PhpOffice\\PhpPresentation\\AbstractShape', $object->setOffsetX()); $this->assertEquals(0, $object->getOffsetX()); $this->assertInstanceOf('PhpOffice\\PhpPresentation\\AbstractShape', $object->setOffsetX($value)); $this->assertEquals($value, $object->getOffsetX()); }
/** * Write text * * @param \PhpOffice\Common\XMLWriter $objWriter * @param \PhpOffice\PhpPresentation\Shape\RichText $shape */ public function writeShapeTxt(XMLWriter $objWriter, RichText $shape) { // draw:frame $objWriter->startElement('draw:frame'); $objWriter->writeAttribute('draw:style-name', 'gr' . $this->shapeId); $objWriter->writeAttribute('svg:width', Text::numberFormat(CommonDrawing::pixelsToCentimeters($shape->getWidth()), 3) . 'cm'); $objWriter->writeAttribute('svg:height', Text::numberFormat(CommonDrawing::pixelsToCentimeters($shape->getHeight()), 3) . 'cm'); $objWriter->writeAttribute('svg:x', Text::numberFormat(CommonDrawing::pixelsToCentimeters($shape->getOffsetX()), 3) . 'cm'); $objWriter->writeAttribute('svg:y', Text::numberFormat(CommonDrawing::pixelsToCentimeters($shape->getOffsetY()), 3) . 'cm'); // draw:text-box $objWriter->startElement('draw:text-box'); $paragraphs = $shape->getParagraphs(); $paragraphId = 0; $sCstShpLastBullet = ''; $iCstShpLastBulletLvl = 0; $bCstShpHasBullet = false; foreach ($paragraphs as $paragraph) { // Close the bullet list if ($sCstShpLastBullet != 'bullet' && $bCstShpHasBullet === true) { for ($iInc = $iCstShpLastBulletLvl; $iInc >= 0; $iInc--) { // text:list-item $objWriter->endElement(); // text:list $objWriter->endElement(); } } //=============================================== // Paragraph //=============================================== if ($paragraph->getBulletStyle()->getBulletType() == 'none') { ++$paragraphId; // text:p $objWriter->startElement('text:p'); $objWriter->writeAttribute('text:style-name', 'P_' . $paragraph->getHashCode()); // Loop trough rich text elements $richtexts = $paragraph->getRichTextElements(); $richtextId = 0; foreach ($richtexts as $richtext) { ++$richtextId; if ($richtext instanceof TextElement || $richtext instanceof Run) { // text:span $objWriter->startElement('text:span'); if ($richtext instanceof Run) { $objWriter->writeAttribute('text:style-name', 'T_' . $richtext->getFont()->getHashCode()); } if ($richtext->hasHyperlink() === true && $richtext->getHyperlink()->getUrl() != '') { // text:a $objWriter->startElement('text:a'); $objWriter->writeAttribute('xlink:href', $richtext->getHyperlink()->getUrl()); $objWriter->text($richtext->getText()); $objWriter->endElement(); } else { $objWriter->text($richtext->getText()); } $objWriter->endElement(); } elseif ($richtext instanceof BreakElement) { // text:span $objWriter->startElement('text:span'); // text:line-break $objWriter->startElement('text:line-break'); $objWriter->endElement(); $objWriter->endElement(); } else { //echo '<pre>'.print_r($richtext, true).'</pre>'; } } $objWriter->endElement(); //=============================================== // Bullet list //=============================================== } elseif ($paragraph->getBulletStyle()->getBulletType() == 'bullet') { $bCstShpHasBullet = true; // Open the bullet list if ($sCstShpLastBullet != 'bullet' || $sCstShpLastBullet == $paragraph->getBulletStyle()->getBulletType() && $iCstShpLastBulletLvl < $paragraph->getAlignment()->getLevel()) { // text:list $objWriter->startElement('text:list'); $objWriter->writeAttribute('text:style-name', 'L_' . $paragraph->getBulletStyle()->getHashCode()); } if ($sCstShpLastBullet == 'bullet') { if ($iCstShpLastBulletLvl == $paragraph->getAlignment()->getLevel()) { // text:list-item $objWriter->endElement(); } elseif ($iCstShpLastBulletLvl > $paragraph->getAlignment()->getLevel()) { // text:list-item $objWriter->endElement(); // text:list $objWriter->endElement(); // text:list-item $objWriter->endElement(); } } // text:list-item $objWriter->startElement('text:list-item'); ++$paragraphId; // text:p $objWriter->startElement('text:p'); $objWriter->writeAttribute('text:style-name', 'P_' . $paragraph->getHashCode()); // Loop trough rich text elements $richtexts = $paragraph->getRichTextElements(); $richtextId = 0; foreach ($richtexts as $richtext) { ++$richtextId; if ($richtext instanceof TextElement || $richtext instanceof Run) { // text:span $objWriter->startElement('text:span'); if ($richtext instanceof Run) { $objWriter->writeAttribute('text:style-name', 'T_' . $richtext->getFont()->getHashCode()); } if ($richtext->hasHyperlink() === true && $richtext->getHyperlink()->getUrl() != '') { // text:a $objWriter->startElement('text:a'); $objWriter->writeAttribute('xlink:href', $richtext->getHyperlink()->getUrl()); $objWriter->text($richtext->getText()); $objWriter->endElement(); } else { $objWriter->text($richtext->getText()); } $objWriter->endElement(); } elseif ($richtext instanceof BreakElement) { // text:span $objWriter->startElement('text:span'); // text:line-break $objWriter->startElement('text:line-break'); $objWriter->endElement(); $objWriter->endElement(); } else { //echo '<pre>'.print_r($richtext, true).'</pre>'; } } $objWriter->endElement(); } $sCstShpLastBullet = $paragraph->getBulletStyle()->getBulletType(); $iCstShpLastBulletLvl = $paragraph->getAlignment()->getLevel(); } // Close the bullet list if ($sCstShpLastBullet == 'bullet' && $bCstShpHasBullet === true) { for ($iInc = $iCstShpLastBulletLvl; $iInc >= 0; $iInc--) { // text:list-item $objWriter->endElement(); // text:list $objWriter->endElement(); } } // > draw:text-box $objWriter->endElement(); // > draw:frame $objWriter->endElement(); }