示例#1
0
 /**
  */
 public function testDegreesAngle()
 {
     $value = rand(1, 100);
     $this->assertEquals(0, Drawing::degreesToAngle());
     $this->assertEquals((int) round($value * 60000), Drawing::degreesToAngle($value));
     $this->assertEquals(0, Drawing::angleToDegrees());
     $this->assertEquals(round($value / 60000), Drawing::angleToDegrees($value));
 }
示例#2
0
 protected function loadShapeRichText(XMLReader $document, \DOMElement $node, $baseFile)
 {
     // Core
     $oShape = $this->oPhpPresentation->getActiveSlide()->createRichTextShape();
     $oShape->setParagraphs(array());
     // Variables
     $fileRels = 'ppt/slides/_rels/' . $baseFile . '.rels';
     $oElement = $document->getElement('p:spPr/a:xfrm', $node);
     if ($oElement && $oElement->hasAttribute('rot')) {
         $oShape->setRotation(CommonDrawing::angleToDegrees($oElement->getAttribute('rot')));
     }
     $oElement = $document->getElement('p:spPr/a:xfrm/a:off', $node);
     if ($oElement) {
         if ($oElement->hasAttribute('x')) {
             $oShape->setOffsetX(CommonDrawing::emuToPixels($oElement->getAttribute('x')));
         }
         if ($oElement->hasAttribute('y')) {
             $oShape->setOffsetY(CommonDrawing::emuToPixels($oElement->getAttribute('y')));
         }
     }
     $oElement = $document->getElement('p:spPr/a:xfrm/a:ext', $node);
     if ($oElement) {
         if ($oElement->hasAttribute('cx')) {
             $oShape->setWidth(CommonDrawing::emuToPixels($oElement->getAttribute('cx')));
         }
         if ($oElement->hasAttribute('cy')) {
             $oShape->setHeight(CommonDrawing::emuToPixels($oElement->getAttribute('cy')));
         }
     }
     $arrayElements = $document->getElements('p:txBody/a:p', $node);
     foreach ($arrayElements as $oElement) {
         // Core
         $oParagraph = $oShape->createParagraph();
         $oParagraph->setRichTextElements(array());
         $oSubElement = $document->getElement('a:pPr', $oElement);
         if ($oSubElement) {
             if ($oSubElement->hasAttribute('algn')) {
                 $oParagraph->getAlignment()->setHorizontal($oSubElement->getAttribute('algn'));
             }
             if ($oSubElement->hasAttribute('fontAlgn')) {
                 $oParagraph->getAlignment()->setVertical($oSubElement->getAttribute('fontAlgn'));
             }
             if ($oSubElement->hasAttribute('marL')) {
                 $oParagraph->getAlignment()->setMarginLeft(CommonDrawing::emuToPixels($oSubElement->getAttribute('marL')));
             }
             if ($oSubElement->hasAttribute('marR')) {
                 $oParagraph->getAlignment()->setMarginRight(CommonDrawing::emuToPixels($oSubElement->getAttribute('marR')));
             }
             if ($oSubElement->hasAttribute('indent')) {
                 $oParagraph->getAlignment()->setIndent(CommonDrawing::emuToPixels($oSubElement->getAttribute('indent')));
             }
             if ($oSubElement->hasAttribute('lvl')) {
                 $oParagraph->getAlignment()->setLevel($oSubElement->getAttribute('lvl'));
             }
             $oElementBuFont = $document->getElement('a:buFont', $oSubElement);
             $oParagraph->getBulletStyle()->setBulletType(Bullet::TYPE_NONE);
             if ($oElementBuFont) {
                 if ($oElementBuFont->hasAttribute('typeface')) {
                     $oParagraph->getBulletStyle()->setBulletFont($oElementBuFont->getAttribute('typeface'));
                 }
             }
             $oElementBuChar = $document->getElement('a:buChar', $oSubElement);
             if ($oElementBuChar) {
                 $oParagraph->getBulletStyle()->setBulletType(Bullet::TYPE_BULLET);
                 if ($oElementBuChar->hasAttribute('char')) {
                     $oParagraph->getBulletStyle()->setBulletChar($oElementBuChar->getAttribute('char'));
                 }
             }
             /*$oElementBuAutoNum = $document->getElement('a:buAutoNum', $oSubElement);
               if ($oElementBuAutoNum) {
                   $oParagraph->getBulletStyle()->setBulletType(Bullet::TYPE_NUMERIC);
                   if ($oElementBuAutoNum->hasAttribute('type')) {
                       $oParagraph->getBulletStyle()->setBulletNumericStyle($oElementBuAutoNum->getAttribute('type'));
                   }
                   if ($oElementBuAutoNum->hasAttribute('startAt') && $oElementBuAutoNum->getAttribute('startAt') != 1) {
                       $oParagraph->getBulletStyle()->setBulletNumericStartAt($oElementBuAutoNum->getAttribute('startAt'));
                   }
               }*/
         }
         $arraySubElements = $document->getElements('(a:r|a:br)', $oElement);
         foreach ($arraySubElements as $oSubElement) {
             if ($oSubElement->tagName == 'a:br') {
                 $oParagraph->createBreak();
             }
             if ($oSubElement->tagName == 'a:r') {
                 $oElementrPr = $document->getElement('a:rPr', $oSubElement);
                 if (is_object($oElementrPr)) {
                     $oText = $oParagraph->createTextRun();
                     if ($oElementrPr->hasAttribute('b')) {
                         $oText->getFont()->setBold($oElementrPr->getAttribute('b') == 'true' ? true : false);
                     }
                     if ($oElementrPr->hasAttribute('i')) {
                         $oText->getFont()->setItalic($oElementrPr->getAttribute('i') == 'true' ? true : false);
                     }
                     if ($oElementrPr->hasAttribute('strike')) {
                         $oText->getFont()->setStrikethrough($oElementrPr->getAttribute('strike') == 'noStrike' ? false : true);
                     }
                     if ($oElementrPr->hasAttribute('sz')) {
                         $oText->getFont()->setSize((int) ($oElementrPr->getAttribute('sz') / 100));
                     }
                     if ($oElementrPr->hasAttribute('u')) {
                         $oText->getFont()->setUnderline($oElementrPr->getAttribute('u'));
                     }
                     // Color
                     $oElementSrgbClr = $document->getElement('a:solidFill/a:srgbClr', $oElementrPr);
                     if (is_object($oElementSrgbClr) && $oElementSrgbClr->hasAttribute('val')) {
                         $oColor = new Color();
                         $oColor->setRGB($oElementSrgbClr->getAttribute('val'));
                         $oText->getFont()->setColor($oColor);
                     }
                     // Hyperlink
                     $oElementHlinkClick = $document->getElement('a:hlinkClick', $oElementrPr);
                     if (is_object($oElementHlinkClick)) {
                         if ($oElementHlinkClick->hasAttribute('tooltip')) {
                             $oText->getHyperlink()->setTooltip($oElementHlinkClick->getAttribute('tooltip'));
                         }
                         if ($oElementHlinkClick->hasAttribute('r:id') && isset($this->arrayRels[$fileRels][$oElementHlinkClick->getAttribute('r:id')])) {
                             $oText->getHyperlink()->setUrl($this->arrayRels[$fileRels][$oElementHlinkClick->getAttribute('r:id')]);
                         }
                     }
                     //} else {
                     // $oText = $oParagraph->createText();
                 }
                 $oSubSubElement = $document->getElement('a:t', $oSubElement);
                 $oText->setText($oSubSubElement->nodeValue);
             }
         }
     }
     if (count($oShape->getParagraphs()) > 0) {
         $oShape->setActiveParagraph(0);
     }
 }