示例#1
0
 /**
  * Get whether iconv extension is available
  *
  * @return boolean
  */
 public static function getIsIconvEnabled()
 {
     if (isset(self::$_isIconvEnabled)) {
         return self::$_isIconvEnabled;
     }
     self::$_isIconvEnabled = function_exists('iconv') ? true : false;
     return self::$_isIconvEnabled;
 }
示例#2
0
 /**
  * Write paragraphs
  *
  * @param	PHPPowerPoint_Shared_XMLWriter				$objWriter		XML Writer
  * @param	PHPPowerPoint_Shape_RichText_Paragraph[]	$paragraphs
  * @throws	Exception
  */
 private function _writeParagraphs(PHPPowerPoint_Shared_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', PHPPowerPoint_Shared_Drawing::pixelsToEMU($paragraph->getAlignment()->getMarginLeft()));
         $objWriter->writeAttribute('marR', PHPPowerPoint_Shared_Drawing::pixelsToEMU($paragraph->getAlignment()->getMarginRight()));
         $objWriter->writeAttribute('indent', PHPPowerPoint_Shared_Drawing::pixelsToEMU($paragraph->getAlignment()->getIndent()));
         $objWriter->writeAttribute('lvl', $paragraph->getAlignment()->getLevel());
         // Bullet type specified?
         if ($paragraph->getBulletStyle()->getBulletType() != PHPPowerPoint_Style_Bullet::TYPE_NONE) {
             // a:buFont
             $objWriter->startElement('a:buFont');
             $objWriter->writeAttribute('typeface', $paragraph->getBulletStyle()->getBulletFont());
             $objWriter->endElement();
             if ($paragraph->getBulletStyle()->getBulletType() == PHPPowerPoint_Style_Bullet::TYPE_BULLET) {
                 // a:buChar
                 $objWriter->startElement('a:buChar');
                 $objWriter->writeAttribute('char', $paragraph->getBulletStyle()->getBulletChar());
                 $objWriter->endElement();
             } else {
                 if ($paragraph->getBulletStyle()->getBulletType() == PHPPowerPoint_Style_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 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();
                     // a:hlinkClick
                     if ($element->hasHyperlink()) {
                         $this->_writeHyperlink($objWriter, $element);
                     }
                     $objWriter->endElement();
                 }
                 // t
                 $objWriter->startElement('a:t');
                 $objWriter->writeCData(PHPPowerPoint_Shared_String::ControlCharacterPHP2OOXML($element->getText()));
                 $objWriter->endElement();
                 $objWriter->endElement();
             }
         }
         $objWriter->endElement();
     }
 }
示例#3
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();
 }