예제 #1
0
파일: Slide.php 프로젝트: sensorsix/app
 /**
  * Write txt
  *
  * @param	PHPPowerPoint_Shared_XMLWriter		$objWriter		XML Writer
  * @param	PHPPowerPoint_Shape_RichText		$shape
  * @param	int									$shapeId
  * @throws	Exception
  */
 private function _writeTxt(PHPPowerPoint_Shared_XMLWriter $objWriter = null, PHPPowerPoint_Shape_RichText $shape = null, $shapeId)
 {
     // p:sp
     $objWriter->startElement('p:sp');
     // p:nvSpPr
     $objWriter->startElement('p:nvSpPr');
     // p:cNvPr
     $objWriter->startElement('p:cNvPr');
     $objWriter->writeAttribute('id', $shapeId);
     $objWriter->writeAttribute('name', '');
     $objWriter->endElement();
     // p:cNvSpPr
     $objWriter->startElement('p:cNvSpPr');
     $objWriter->writeAttribute('txBox', '1');
     $objWriter->endElement();
     // p:nvPr
     $objWriter->writeElement('p:nvPr', null);
     $objWriter->endElement();
     // p:spPr
     $objWriter->startElement('p:spPr');
     // a:xfrm
     $objWriter->startElement('a:xfrm');
     $objWriter->writeAttribute('rot', PHPPowerPoint_Shared_Drawing::degreesToAngle($shape->getRotation()));
     // a:off
     $objWriter->startElement('a:off');
     $objWriter->writeAttribute('x', PHPPowerPoint_Shared_Drawing::pixelsToEMU($shape->getOffsetX()));
     $objWriter->writeAttribute('y', PHPPowerPoint_Shared_Drawing::pixelsToEMU($shape->getOffsetY()));
     $objWriter->endElement();
     // a:ext
     $objWriter->startElement('a:ext');
     $objWriter->writeAttribute('cx', PHPPowerPoint_Shared_Drawing::pixelsToEMU($shape->getWidth()));
     $objWriter->writeAttribute('cy', PHPPowerPoint_Shared_Drawing::pixelsToEMU($shape->getHeight()));
     $objWriter->endElement();
     $objWriter->endElement();
     // a:prstGeom
     $objWriter->startElement('a:prstGeom');
     $objWriter->writeAttribute('prst', 'rect');
     $objWriter->endElement();
     // a:noFill
     $objWriter->writeElement('a:noFill', null);
     if ($shape->getShadow()->getVisible()) {
         // a:effectLst
         $objWriter->startElement('a:effectLst');
         // a:outerShdw
         $objWriter->startElement('a:outerShdw');
         $objWriter->writeAttribute('blurRad', PHPPowerPoint_Shared_Drawing::pixelsToEMU($shape->getShadow()->getBlurRadius()));
         $objWriter->writeAttribute('dist', PHPPowerPoint_Shared_Drawing::pixelsToEMU($shape->getShadow()->getDistance()));
         $objWriter->writeAttribute('dir', PHPPowerPoint_Shared_Drawing::degreesToAngle($shape->getShadow()->getDirection()));
         $objWriter->writeAttribute('algn', $shape->getShadow()->getAlignment());
         $objWriter->writeAttribute('rotWithShape', '0');
         // a:srgbClr
         $objWriter->startElement('a:srgbClr');
         $objWriter->writeAttribute('val', $shape->getShadow()->getColor()->getRGB());
         // a:alpha
         $objWriter->startElement('a:alpha');
         $objWriter->writeAttribute('val', $shape->getShadow()->getAlpha() * 1000);
         $objWriter->endElement();
         $objWriter->endElement();
         $objWriter->endElement();
         $objWriter->endElement();
     }
     $objWriter->endElement();
     // p:txBody
     $objWriter->startElement('p:txBody');
     // a:bodyPr
     $objWriter->startElement('a:bodyPr');
     $objWriter->writeAttribute('wrap', 'square');
     $objWriter->writeAttribute('rtlCol', '0');
     // a:spAutoFit
     $objWriter->writeElement('a:spAutoFit', null);
     $objWriter->endElement();
     // a:lstStyle
     $objWriter->writeElement('a:lstStyle', null);
     // a:p
     $objWriter->startElement('a:p');
     // a:pPr
     $objWriter->startElement('a:pPr');
     $objWriter->writeAttribute('algn', $shape->getAlignment()->getHorizontal());
     $objWriter->writeAttribute('fontAlgn', $shape->getAlignment()->getVertical());
     $objWriter->writeAttribute('indent', $shape->getAlignment()->getIndent());
     $objWriter->writeAttribute('lvl', $shape->getAlignment()->getLevel());
     $objWriter->endElement();
     // Loop trough rich text elements
     $elements = $shape->getRichTextElements();
     foreach ($elements as $element) {
         if ($element instanceof PHPPowerPoint_Shape_RichText_Break) {
             // a:br
             $objWriter->writeElement('a:br', null);
         } elseif ($element instanceof PHPPowerPoint_Shape_RichText_Run || $element instanceof PHPPowerPoint_Shape_RichText_TextElement) {
             // a:r
             $objWriter->startElement('a:r');
             // a:rPr
             if ($element instanceof PHPPowerPoint_Shape_RichText_Run) {
                 // a:rPr
                 $objWriter->startElement('a:rPr');
                 // Bold
                 $objWriter->writeAttribute('b', $element->getFont()->getBold() ? 'true' : 'false');
                 // Italic
                 $objWriter->writeAttribute('i', $element->getFont()->getItalic() ? 'true' : 'false');
                 // Strikethrough
                 $objWriter->writeAttribute('strike', $element->getFont()->getStrikethrough() ? 'sngStrike' : 'noStrike');
                 // Size
                 $objWriter->writeAttribute('sz', $element->getFont()->getSize() * 100);
                 // Underline
                 $objWriter->writeAttribute('u', $element->getFont()->getUnderline());
                 // Superscript / subscript
                 if ($element->getFont()->getSuperScript() || $element->getFont()->getSubScript()) {
                     if ($element->getFont()->getSuperScript()) {
                         $objWriter->writeAttribute('baseline', '30000');
                     } else {
                         if ($element->getFont()->getSubScript()) {
                             $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();
                 $objWriter->endElement();
             }
             // t
             $objWriter->startElement('a:t');
             $objWriter->writeRaw(PHPPowerPoint_Shared_String::ControlCharacterPHP2OOXML(htmlspecialchars($element->getText())));
             $objWriter->endElement();
             $objWriter->endElement();
         }
     }
     $objWriter->endElement();
     $objWriter->endElement();
     /*
     					<a:r>
     							<a:rPr lang="en-US" dirty="0" err="1" smtClean="0" />
     						</a:r>
     */
     $objWriter->endElement();
 }
예제 #2
0
 /**
  * Write txt
  *
  * @param	PHPPowerPoint_Shared_XMLWriter		$objWriter		XML Writer
  * @param	PHPPowerPoint_Shape_RichText		$shape
  * @param	int									$shapeId
  * @throws	Exception
  */
 private function _writeTxt(PHPPowerPoint_Shared_XMLWriter $objWriter = null, PHPPowerPoint_Shape_RichText $shape = null, $shapeId)
 {
     // p:sp
     $objWriter->startElement('p:sp');
     // p:nvSpPr
     $objWriter->startElement('p:nvSpPr');
     // p:cNvPr
     $objWriter->startElement('p:cNvPr');
     $objWriter->writeAttribute('id', $shapeId);
     $objWriter->writeAttribute('name', '');
     // a:hlinkClick
     if ($shape->hasHyperlink()) {
         $this->_writeHyperlink($objWriter, $shape);
     }
     $objWriter->endElement();
     // p:cNvSpPr
     $objWriter->startElement('p:cNvSpPr');
     $objWriter->writeAttribute('txBox', '1');
     $objWriter->endElement();
     // p:nvPr
     $objWriter->writeElement('p:nvPr', null);
     $objWriter->endElement();
     // p:spPr
     $objWriter->startElement('p:spPr');
     // a:xfrm
     $objWriter->startElement('a:xfrm');
     $objWriter->writeAttribute('rot', PHPPowerPoint_Shared_Drawing::degreesToAngle($shape->getRotation()));
     // a:off
     $objWriter->startElement('a:off');
     $objWriter->writeAttribute('x', PHPPowerPoint_Shared_Drawing::pixelsToEMU($shape->getOffsetX()));
     $objWriter->writeAttribute('y', PHPPowerPoint_Shared_Drawing::pixelsToEMU($shape->getOffsetY()));
     $objWriter->endElement();
     // a:ext
     $objWriter->startElement('a:ext');
     $objWriter->writeAttribute('cx', PHPPowerPoint_Shared_Drawing::pixelsToEMU($shape->getWidth()));
     $objWriter->writeAttribute('cy', PHPPowerPoint_Shared_Drawing::pixelsToEMU($shape->getHeight()));
     $objWriter->endElement();
     $objWriter->endElement();
     // a:prstGeom
     $objWriter->startElement('a:prstGeom');
     $objWriter->writeAttribute('prst', 'rect');
     $objWriter->endElement();
     $this->_writeFill($objWriter, $shape->getFill());
     if ($shape->getBorder()->getLineStyle() != PHPPowerPoint_Style_Border::LINE_NONE) {
         $this->_writeBorder($objWriter, $shape->getBorder(), '');
     }
     if ($shape->getShadow()->getVisible()) {
         // a:effectLst
         $objWriter->startElement('a:effectLst');
         // a:outerShdw
         $objWriter->startElement('a:outerShdw');
         $objWriter->writeAttribute('blurRad', PHPPowerPoint_Shared_Drawing::pixelsToEMU($shape->getShadow()->getBlurRadius()));
         $objWriter->writeAttribute('dist', PHPPowerPoint_Shared_Drawing::pixelsToEMU($shape->getShadow()->getDistance()));
         $objWriter->writeAttribute('dir', PHPPowerPoint_Shared_Drawing::degreesToAngle($shape->getShadow()->getDirection()));
         $objWriter->writeAttribute('algn', $shape->getShadow()->getAlignment());
         $objWriter->writeAttribute('rotWithShape', '0');
         // a:srgbClr
         $objWriter->startElement('a:srgbClr');
         $objWriter->writeAttribute('val', $shape->getShadow()->getColor()->getRGB());
         // a:alpha
         $objWriter->startElement('a:alpha');
         $objWriter->writeAttribute('val', $shape->getShadow()->getAlpha() * 1000);
         $objWriter->endElement();
         $objWriter->endElement();
         $objWriter->endElement();
         $objWriter->endElement();
     }
     $objWriter->endElement();
     // p:txBody
     $objWriter->startElement('p:txBody');
     // a:bodyPr
     $objWriter->startElement('a:bodyPr');
     $objWriter->writeAttribute('wrap', $shape->getWrap());
     $objWriter->writeAttribute('rtlCol', '0');
     $objWriter->writeAttribute('horzOverflow', $shape->getHorizontalOverflow());
     $objWriter->writeAttribute('vertOverflow', $shape->getVerticalOverflow());
     if ($shape->getUpright()) {
         $objWriter->writeAttribute('upright', '1');
     }
     if ($shape->getVertical()) {
         $objWriter->writeAttribute('vert', 'vert');
     }
     $objWriter->writeAttribute('bIns', PHPPowerPoint_Shared_Drawing::pixelsToEMU($shape->getInsetBottom()));
     $objWriter->writeAttribute('lIns', PHPPowerPoint_Shared_Drawing::pixelsToEMU($shape->getInsetLeft()));
     $objWriter->writeAttribute('rIns', PHPPowerPoint_Shared_Drawing::pixelsToEMU($shape->getInsetRight()));
     $objWriter->writeAttribute('tIns', PHPPowerPoint_Shared_Drawing::pixelsToEMU($shape->getInsetTop()));
     $objWriter->writeAttribute('numCol', $shape->getColumns());
     // a:spAutoFit
     $objWriter->writeElement('a:' . $shape->getAutoFit(), null);
     $objWriter->endElement();
     // a:lstStyle
     $objWriter->writeElement('a:lstStyle', null);
     // Write paragraphs
     $this->_writeParagraphs($objWriter, $shape->getParagraphs());
     $objWriter->endElement();
     $objWriter->endElement();
 }
예제 #3
0
 function _writeTxt(PHPPowerPoint_Shared_XMLWriter $objWriter = null, PHPPowerPoint_Shape_RichText $shape = null, $shapeId)
 {
     // draw:custom-shape
     $objWriter->startElement('draw:custom-shape');
     $objWriter->writeAttribute('draw:style-name', 'gr' . $shapeId);
     $objWriter->writeAttribute('svg:width', number_format(PHPPowerPoint_Shared_Drawing::pixelsToCentimeters($shape->getWidth()), 3) . 'cm');
     $objWriter->writeAttribute('svg:height', number_format(PHPPowerPoint_Shared_Drawing::pixelsToCentimeters($shape->getHeight()), 3) . 'cm');
     $objWriter->writeAttribute('svg:x', number_format(PHPPowerPoint_Shared_Drawing::pixelsToCentimeters($shape->getOffsetX()), 3) . 'cm');
     $objWriter->writeAttribute('svg:y', number_format(PHPPowerPoint_Shared_Drawing::pixelsToCentimeters($shape->getOffsetY()), 3) . 'cm');
     $paragraphs = $shape->getParagraphs();
     $paragraphId = 0;
     $sCustomShapeLastBullet = '';
     $iCustomShapeLastBulletLevel = 0;
     $bCustomShapeHasBullet = false;
     foreach ($paragraphs as $paragraph) {
         // Close the bullet list
         if ($sCustomShapeLastBullet != 'bullet' && $bCustomShapeHasBullet == true) {
             for ($iInc = $iCustomShapeLastBulletLevel; $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 PHPPowerPoint_Shape_RichText_TextElement || $richtext instanceof PHPPowerPoint_Shape_RichText_Run) {
                     // text:span
                     $objWriter->startElement('text:span');
                     if ($richtext instanceof PHPPowerPoint_Shape_RichText_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 PHPPowerPoint_Shape_RichText_Break) {
                     // 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();
         } elseif ($paragraph->getBulletStyle()->getBulletType() == 'bullet') {
             $bCustomShapeHasBullet = true;
             // Open the bullet list
             if ($sCustomShapeLastBullet != 'bullet' || $sCustomShapeLastBullet == $paragraph->getBulletStyle()->getBulletType() && $iCustomShapeLastBulletLevel < $paragraph->getAlignment()->getLevel()) {
                 // text:list
                 $objWriter->startElement('text:list');
                 $objWriter->writeAttribute('text:style-name', 'L_' . $paragraph->getBulletStyle()->getHashCode());
             }
             if ($sCustomShapeLastBullet == 'bullet') {
                 if ($iCustomShapeLastBulletLevel == $paragraph->getAlignment()->getLevel()) {
                     // text:list-item
                     $objWriter->endElement();
                 } elseif ($iCustomShapeLastBulletLevel > $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 PHPPowerPoint_Shape_RichText_TextElement || $richtext instanceof PHPPowerPoint_Shape_RichText_Run) {
                     // text:span
                     $objWriter->startElement('text:span');
                     if ($richtext instanceof PHPPowerPoint_Shape_RichText_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 PHPPowerPoint_Shape_RichText_Break) {
                     // 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();
         }
         $sCustomShapeLastBullet = $paragraph->getBulletStyle()->getBulletType();
         $iCustomShapeLastBulletLevel = $paragraph->getAlignment()->getLevel();
     }
     // Close the bullet list
     if ($sCustomShapeLastBullet == 'bullet' && $bCustomShapeHasBullet == true) {
         for ($iInc = $iCustomShapeLastBulletLevel; $iInc >= 0; $iInc--) {
             // text:list-item
             $objWriter->endElement();
             // text:list
             $objWriter->endElement();
         }
     }
     $objWriter->endElement();
 }