Наследование: implements PhpOffice\PhpPresentation\ComparableInterface
Пример #1
0
 /**
  * Test get/set hash index
  */
 public function testSetGetHashIndex()
 {
     $object = new Color();
     $value = rand(1, 100);
     $object->setHashIndex($value);
     $this->assertEquals($value, $object->getHashIndex());
 }
Пример #2
0
 public function testColor()
 {
     $object = new Color();
     $oStyleColor = new StyleColor();
     $oStyleColor->setRGB('123456');
     $this->assertNull($object->getColor());
     $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Slide\\Background\\Color', $object->setColor($oStyleColor));
     $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Style\\Color', $object->getColor());
     $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Slide\\Background\\Color', $object->setColor());
     $this->assertNull($object->getColor());
 }
Пример #3
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);
     }
 }
Пример #4
0
 /**
  * Get hash code
  *
  * @return string Hash code
  */
 public function getHashCode()
 {
     return md5($this->lineStyle . $this->lineWidth . $this->dashStyle . $this->color->getHashCode() . __CLASS__);
 }
Пример #5
0
 /**
  * Get hash code
  *
  * @return string Hash code
  */
 public function getHashCode()
 {
     return md5($this->name . $this->size . ($this->bold ? 't' : 'f') . ($this->italic ? 't' : 'f') . ($this->superScript ? 't' : 'f') . ($this->subScript ? 't' : 'f') . $this->underline . ($this->strikethrough ? 't' : 'f') . $this->color->getHashCode() . __CLASS__);
 }
Пример #6
0
 /**
  * Get hash code
  *
  * @return string Hash code
  */
 public function getHashCode()
 {
     return md5(($this->visible ? 't' : 'f') . $this->blurRadius . $this->distance . $this->direction . $this->alignment . $this->color->getHashCode() . $this->alpha . __CLASS__);
 }
 /**
  * @param XMLWriter $objWriter
  * @param Color $color
  * @param int|null $alpha
  */
 protected function writeColor(XMLWriter $objWriter, Color $color, $alpha = null)
 {
     if (is_null($alpha)) {
         $alpha = $color->getAlpha();
     }
     // a:srgbClr
     $objWriter->startElement('a:srgbClr');
     $objWriter->writeAttribute('val', $color->getRGB());
     // a:alpha
     $objWriter->startElement('a:alpha');
     $objWriter->writeAttribute('val', $alpha * 1000);
     $objWriter->endElement();
     $objWriter->endElement();
 }
Пример #8
0
 public function testTableCellFill()
 {
     $oColor = new Color();
     $oColor->setRGB(Color::COLOR_BLUE);
     $oFill = new Fill();
     $oFill->setFillType(Fill::FILL_SOLID)->setStartColor($oColor);
     $phpPresentation = new PhpPresentation();
     $oSlide = $phpPresentation->getActiveSlide();
     $oShape = $oSlide->createTableShape();
     $oRow = $oShape->createRow();
     $oCell = $oRow->getCell();
     $oCell->setFill($oFill);
     $pres = TestHelperDOCX::getDocument($phpPresentation, 'ODPresentation');
     $element = '/office:document-content/office:automatic-styles/style:style[@style:name=\'gr1r0c0\']';
     $this->assertTrue($pres->elementExists($element, 'content.xml'));
     $this->assertEquals('table-cell', $pres->getElementAttribute($element, 'style:family', 'content.xml'));
     $element = '/office:document-content/office:automatic-styles/style:style[@style:name=\'gr1r0c0\']/style:graphic-properties';
     $this->assertTrue($pres->elementExists($element, 'content.xml'));
     $this->assertEquals('solid', $pres->getElementAttribute($element, 'draw:fill', 'content.xml'));
     $this->assertStringStartsWith('#', $pres->getElementAttribute($element, 'draw:fill-color', 'content.xml'));
     $this->assertStringEndsWith($oColor->getRGB(), $pres->getElementAttribute($element, 'draw:fill-color', 'content.xml'));
 }
Пример #9
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;
 }