Inheritance: implements PhpOffice\PhpPresentation\ComparableInterface
コード例 #1
0
ファイル: Title.php プロジェクト: hxsam/PHPPresentation
 /**
  * Get hash code
  *
  * @return string Hash code
  */
 public function getHashCode()
 {
     return md5($this->text . $this->offsetX . $this->offsetY . $this->width . $this->height . $this->font->getHashCode() . $this->alignment->getHashCode() . ($this->visible ? 't' : 'f') . __CLASS__);
 }
コード例 #2
0
 /**
  * Extract style
  * @param \DOMElement $nodeStyle
  */
 protected function loadStyle(\DOMElement $nodeStyle)
 {
     $keyStyle = $nodeStyle->getAttribute('style:name');
     $nodeDrawingPageProps = $this->oXMLReader->getElement('style:drawing-page-properties', $nodeStyle);
     if ($nodeDrawingPageProps) {
         // Read Background Color
         if ($nodeDrawingPageProps->hasAttribute('draw:fill-color') && $nodeDrawingPageProps->getAttribute('draw:fill') == 'solid') {
             $oBackground = new \PhpOffice\PhpPresentation\Slide\Background\Color();
             $oColor = new Color();
             $oColor->setRGB(substr($nodeDrawingPageProps->getAttribute('draw:fill-color'), -6));
             $oBackground->setColor($oColor);
         }
         // Read Background Image
         if ($nodeDrawingPageProps->getAttribute('draw:fill') == 'bitmap' && $nodeDrawingPageProps->hasAttribute('draw:fill-image-name')) {
             $nameStyle = $nodeDrawingPageProps->getAttribute('draw:fill-image-name');
             if (!empty($this->arrayCommonStyles[$nameStyle]) && $this->arrayCommonStyles[$nameStyle]['type'] == 'image' && !empty($this->arrayCommonStyles[$nameStyle]['path'])) {
                 $tmpBkgImg = tempnam(sys_get_temp_dir(), 'PhpPresentationReaderODPBkg');
                 $contentImg = $this->oZip->getFromName($this->arrayCommonStyles[$nameStyle]['path']);
                 file_put_contents($tmpBkgImg, $contentImg);
                 $oBackground = new Image();
                 $oBackground->setPath($tmpBkgImg);
             }
         }
     }
     $nodeGraphicProps = $this->oXMLReader->getElement('style:graphic-properties', $nodeStyle);
     if ($nodeGraphicProps) {
         // Read Shadow
         if ($nodeGraphicProps->hasAttribute('draw:shadow') && $nodeGraphicProps->getAttribute('draw:shadow') == 'visible') {
             $oShadow = new Shadow();
             $oShadow->setVisible(true);
             if ($nodeGraphicProps->hasAttribute('draw:shadow-color')) {
                 $oShadow->getColor()->setRGB(substr($nodeGraphicProps->getAttribute('draw:shadow-color'), -6));
             }
             if ($nodeGraphicProps->hasAttribute('draw:shadow-opacity')) {
                 $oShadow->setAlpha(100 - (int) substr($nodeGraphicProps->getAttribute('draw:shadow-opacity'), 0, -1));
             }
             if ($nodeGraphicProps->hasAttribute('draw:shadow-offset-x') && $nodeGraphicProps->hasAttribute('draw:shadow-offset-y')) {
                 $offsetX = substr($nodeGraphicProps->getAttribute('draw:shadow-offset-x'), 0, -2);
                 $offsetY = substr($nodeGraphicProps->getAttribute('draw:shadow-offset-y'), 0, -2);
                 $distance = 0;
                 if ($offsetX != 0) {
                     $distance = $offsetX < 0 ? $offsetX * -1 : $offsetX;
                 } elseif ($offsetY != 0) {
                     $distance = $offsetY < 0 ? $offsetY * -1 : $offsetY;
                 }
                 $oShadow->setDirection(rad2deg(atan2($offsetY, $offsetX)));
                 $oShadow->setDistance(CommonDrawing::centimetersToPixels($distance));
             }
         }
     }
     $nodeTextProperties = $this->oXMLReader->getElement('style:text-properties', $nodeStyle);
     if ($nodeTextProperties) {
         $oFont = new Font();
         if ($nodeTextProperties->hasAttribute('fo:color')) {
             $oFont->getColor()->setRGB(substr($nodeTextProperties->getAttribute('fo:color'), -6));
         }
         if ($nodeTextProperties->hasAttribute('fo:font-family')) {
             $oFont->setName($nodeTextProperties->getAttribute('fo:font-family'));
         }
         if ($nodeTextProperties->hasAttribute('fo:font-weight') && $nodeTextProperties->getAttribute('fo:font-weight') == 'bold') {
             $oFont->setBold(true);
         }
         if ($nodeTextProperties->hasAttribute('fo:font-size')) {
             $oFont->setSize(substr($nodeTextProperties->getAttribute('fo:font-size'), 0, -2));
         }
     }
     $nodeParagraphProps = $this->oXMLReader->getElement('style:paragraph-properties', $nodeStyle);
     if ($nodeParagraphProps) {
         $oAlignment = new Alignment();
         if ($nodeParagraphProps->hasAttribute('fo:text-align')) {
             $oAlignment->setHorizontal($nodeParagraphProps->getAttribute('fo:text-align'));
         }
     }
     if ($nodeStyle->nodeName == 'text:list-style') {
         $arrayListStyle = array();
         foreach ($this->oXMLReader->getElements('text:list-level-style-bullet', $nodeStyle) as $oNodeListLevel) {
             $oAlignment = new Alignment();
             $oBullet = new Bullet();
             $oBullet->setBulletType(Bullet::TYPE_NONE);
             if ($oNodeListLevel->hasAttribute('text:level')) {
                 $oAlignment->setLevel((int) $oNodeListLevel->getAttribute('text:level') - 1);
             }
             if ($oNodeListLevel->hasAttribute('text:bullet-char')) {
                 $oBullet->setBulletChar($oNodeListLevel->getAttribute('text:bullet-char'));
                 $oBullet->setBulletType(Bullet::TYPE_BULLET);
             }
             $oNodeListProperties = $this->oXMLReader->getElement('style:list-level-properties', $oNodeListLevel);
             if ($oNodeListProperties) {
                 if ($oNodeListProperties->hasAttribute('text:min-label-width')) {
                     $oAlignment->setIndent((int) round(CommonDrawing::centimetersToPixels(substr($oNodeListProperties->getAttribute('text:min-label-width'), 0, -2))));
                 }
                 if ($oNodeListProperties->hasAttribute('text:space-before')) {
                     $iSpaceBefore = CommonDrawing::centimetersToPixels(substr($oNodeListProperties->getAttribute('text:space-before'), 0, -2));
                     $iMarginLeft = $iSpaceBefore + $oAlignment->getIndent();
                     $oAlignment->setMarginLeft($iMarginLeft);
                 }
             }
             $oNodeTextProperties = $this->oXMLReader->getElement('style:text-properties', $oNodeListLevel);
             if ($oNodeTextProperties) {
                 if ($oNodeTextProperties->hasAttribute('fo:font-family')) {
                     $oBullet->setBulletFont($oNodeTextProperties->getAttribute('fo:font-family'));
                 }
             }
             $arrayListStyle[$oAlignment->getLevel()] = array('alignment' => $oAlignment, 'bullet' => $oBullet);
         }
     }
     $this->arrayStyles[$keyStyle] = array('alignment' => isset($oAlignment) ? $oAlignment : null, 'background' => isset($oBackground) ? $oBackground : null, 'font' => isset($oFont) ? $oFont : null, 'shadow' => isset($oShadow) ? $oShadow : null, 'listStyle' => isset($arrayListStyle) ? $arrayListStyle : null);
     return true;
 }
コード例 #3
0
 /**
  * Test get/set hash index
  */
 public function testSetGetHashIndex()
 {
     $value = md5(rand(1, 100));
     $object = new Alignment();
     $object->setHashIndex($value);
     $this->assertEquals($value, $object->getHashIndex());
 }
コード例 #4
0
 /**
  * Extract style
  * @param \DOMElement $nodeStyle
  */
 protected function loadStyle(\DOMElement $nodeStyle)
 {
     $keyStyle = $nodeStyle->getAttribute('style:name');
     $nodeGraphicProps = $this->oXMLReader->getElement('style:graphic-properties', $nodeStyle);
     if ($nodeGraphicProps) {
         // Read Shadow
         if ($nodeGraphicProps->hasAttribute('draw:shadow') && $nodeGraphicProps->getAttribute('draw:shadow') == 'visible') {
             $oShadow = new Shadow();
             $oShadow->setVisible(true);
             if ($nodeGraphicProps->hasAttribute('draw:shadow-color')) {
                 $oShadow->getColor()->setRGB(substr($nodeGraphicProps->getAttribute('draw:shadow-color'), -6));
             }
             if ($nodeGraphicProps->hasAttribute('draw:shadow-opacity')) {
                 $oShadow->setAlpha(100 - (int) substr($nodeGraphicProps->getAttribute('draw:shadow-opacity'), 0, -1));
             }
             if ($nodeGraphicProps->hasAttribute('draw:shadow-offset-x') && $nodeGraphicProps->hasAttribute('draw:shadow-offset-y')) {
                 $offsetX = substr($nodeGraphicProps->getAttribute('draw:shadow-offset-x'), 0, -2);
                 $offsetY = substr($nodeGraphicProps->getAttribute('draw:shadow-offset-y'), 0, -2);
                 $distance = 0;
                 if ($offsetX != 0) {
                     $distance = $offsetX < 0 ? $offsetX * -1 : $offsetX;
                 } elseif ($offsetY != 0) {
                     $distance = $offsetY < 0 ? $offsetY * -1 : $offsetY;
                 }
                 $oShadow->setDirection(rad2deg(atan2($offsetY, $offsetX)));
                 $oShadow->setDistance(CommonDrawing::centimetersToPixels($distance));
             }
         }
     }
     $nodeTextProperties = $this->oXMLReader->getElement('style:text-properties', $nodeStyle);
     if ($nodeTextProperties) {
         $oFont = new Font();
         if ($nodeTextProperties->hasAttribute('fo:color')) {
             $oFont->getColor()->setRGB(substr($nodeTextProperties->getAttribute('fo:color'), -6));
         }
         if ($nodeTextProperties->hasAttribute('fo:font-family')) {
             $oFont->setName($nodeTextProperties->getAttribute('fo:font-family'));
         }
         if ($nodeTextProperties->hasAttribute('fo:font-weight') && $nodeTextProperties->getAttribute('fo:font-weight') == 'bold') {
             $oFont->setBold(true);
         }
         if ($nodeTextProperties->hasAttribute('fo:font-size')) {
             $oFont->setSize(substr($nodeTextProperties->getAttribute('fo:font-size'), 0, -2));
         }
     }
     $nodeParagraphProps = $this->oXMLReader->getElement('style:paragraph-properties', $nodeStyle);
     if ($nodeParagraphProps) {
         $oAlignment = new Alignment();
         if ($nodeParagraphProps->hasAttribute('fo:text-align')) {
             $oAlignment->setHorizontal($nodeParagraphProps->getAttribute('fo:text-align'));
         }
     }
     if ($nodeStyle->nodeName == 'text:list-style') {
         $arrayListStyle = array();
         foreach ($this->oXMLReader->getElements('text:list-level-style-bullet', $nodeStyle) as $oNodeListLevel) {
             $oAlignment = new Alignment();
             $oBullet = new Bullet();
             $oBullet->setBulletType(Bullet::TYPE_NONE);
             if ($oNodeListLevel->hasAttribute('text:level')) {
                 $oAlignment->setLevel((int) $oNodeListLevel->getAttribute('text:level') - 1);
             }
             if ($oNodeListLevel->hasAttribute('text:bullet-char')) {
                 $oBullet->setBulletChar($oNodeListLevel->getAttribute('text:bullet-char'));
                 $oBullet->setBulletType(Bullet::TYPE_BULLET);
             }
             $oNodeListProperties = $this->oXMLReader->getElement('style:list-level-properties', $oNodeListLevel);
             if ($oNodeListProperties) {
                 if ($oNodeListProperties->hasAttribute('text:min-label-width')) {
                     $oAlignment->setIndent((int) round(CommonDrawing::centimetersToPixels(substr($oNodeListProperties->getAttribute('text:min-label-width'), 0, -2))));
                 }
                 if ($oNodeListProperties->hasAttribute('text:space-before')) {
                     $iSpaceBefore = CommonDrawing::centimetersToPixels(substr($oNodeListProperties->getAttribute('text:space-before'), 0, -2));
                     $iMarginLeft = $iSpaceBefore + $oAlignment->getIndent();
                     $oAlignment->setMarginLeft($iMarginLeft);
                 }
             }
             $oNodeTextProperties = $this->oXMLReader->getElement('style:text-properties', $oNodeListLevel);
             if ($oNodeTextProperties) {
                 if ($oNodeTextProperties->hasAttribute('fo:font-family')) {
                     $oBullet->setBulletFont($oNodeTextProperties->getAttribute('fo:font-family'));
                 }
             }
             $arrayListStyle[$oAlignment->getLevel()] = array('alignment' => $oAlignment, 'bullet' => $oBullet);
         }
     }
     $this->arrayStyles[$keyStyle] = array('alignment' => isset($oAlignment) ? $oAlignment : null, 'font' => isset($oFont) ? $oFont : null, 'shadow' => isset($oShadow) ? $oShadow : null, 'listStyle' => isset($arrayListStyle) ? $arrayListStyle : null);
     return true;
 }