public function testNumberFormat() { $this->assertEquals('2.1', Text::numberFormat('2.06', 1)); $this->assertEquals('2.1', Text::numberFormat('2.12', 1)); $this->assertEquals('1234', Text::numberFormat(1234, 1)); }
/** * @param Title $oTitle */ private function writeTitle(Title $oTitle) { if ($oTitle->isVisible()) { // chart:title $this->xmlContent->startElement('chart:title'); $this->xmlContent->writeAttribute('svg:x', Text::numberFormat(CommonDrawing::pixelsToCentimeters($oTitle->getOffsetX()), 3) . 'cm'); $this->xmlContent->writeAttribute('svg:y', Text::numberFormat(CommonDrawing::pixelsToCentimeters($oTitle->getOffsetY()), 3) . 'cm'); $this->xmlContent->writeAttribute('chart:style-name', 'styleTitle'); // > text:p $this->xmlContent->startElement('text:p'); $this->xmlContent->text($oTitle->getText()); // > text:p $this->xmlContent->endElement(); // > chart:title $this->xmlContent->endElement(); } }
public function testMedia() { $expectedName = 'MyName'; $expectedWidth = rand(1, 100); $expectedHeight = rand(1, 100); $expectedX = rand(1, 100); $expectedY = rand(1, 100); $oMedia = new Media(); $oMedia->setPath(PHPPRESENTATION_TESTS_BASE_DIR . '/resources/videos/sintel_trailer-480p.ogv')->setName($expectedName)->setResizeProportional(false)->setHeight($expectedHeight)->setWidth($expectedWidth)->setOffsetX($expectedX)->setOffsetY($expectedY); $expectedWidth = Text::numberFormat(CommonDrawing::pixelsToCentimeters($expectedWidth), 3) . 'cm'; $expectedHeight = Text::numberFormat(CommonDrawing::pixelsToCentimeters($expectedHeight), 3) . 'cm'; $expectedX = Text::numberFormat(CommonDrawing::pixelsToCentimeters($expectedX), 3) . 'cm'; $expectedY = Text::numberFormat(CommonDrawing::pixelsToCentimeters($expectedY), 3) . 'cm'; $oPhpPresentation = new PhpPresentation(); $oSlide = $oPhpPresentation->getActiveSlide(); $oSlide->addShape($oMedia); $xmlObject = TestHelperDOCX::getDocument($oPhpPresentation, 'ODPresentation'); $element = '/office:document-content/office:body/office:presentation/draw:page/draw:frame'; $this->assertTrue($xmlObject->elementExists($element, 'content.xml')); $this->assertEquals($expectedName, $xmlObject->getElementAttribute($element, 'draw:name', 'content.xml')); $this->assertEquals($expectedWidth, $xmlObject->getElementAttribute($element, 'svg:width', 'content.xml')); $this->assertEquals($expectedHeight, $xmlObject->getElementAttribute($element, 'svg:height', 'content.xml')); $this->assertEquals($expectedX, $xmlObject->getElementAttribute($element, 'svg:x', 'content.xml')); $this->assertEquals($expectedY, $xmlObject->getElementAttribute($element, 'svg:y', 'content.xml')); $element = '/office:document-content/office:body/office:presentation/draw:page/draw:frame/draw:plugin'; $this->assertTrue($xmlObject->elementExists($element, 'content.xml')); $this->assertEquals('application/vnd.sun.star.media', $xmlObject->getElementAttribute($element, 'draw:mime-type', 'content.xml')); $this->assertStringStartsWith('Pictures/', $xmlObject->getElementAttribute($element, 'xlink:href', 'content.xml')); $this->assertStringEndsWith('ogv', $xmlObject->getElementAttribute($element, 'xlink:href', 'content.xml')); }
/** * Write Meta file to XML format * * @return string XML Output * @throws \Exception */ protected function writePart() { // Create XML writer $objWriter = new XMLWriter(XMLWriter::STORAGE_MEMORY); $objWriter->startDocument('1.0', 'UTF-8'); // office:document-meta $objWriter->startElement('office:document-styles'); $objWriter->writeAttribute('xmlns:office', 'urn:oasis:names:tc:opendocument:xmlns:office:1.0'); $objWriter->writeAttribute('xmlns:style', 'urn:oasis:names:tc:opendocument:xmlns:style:1.0'); $objWriter->writeAttribute('xmlns:text', 'urn:oasis:names:tc:opendocument:xmlns:text:1.0'); $objWriter->writeAttribute('xmlns:table', 'urn:oasis:names:tc:opendocument:xmlns:table:1.0'); $objWriter->writeAttribute('xmlns:draw', 'urn:oasis:names:tc:opendocument:xmlns:drawing:1.0'); $objWriter->writeAttribute('xmlns:fo', 'urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0'); $objWriter->writeAttribute('xmlns:xlink', 'http://www.w3.org/1999/xlink'); $objWriter->writeAttribute('xmlns:dc', 'http://purl.org/dc/elements/1.1/'); $objWriter->writeAttribute('xmlns:meta', 'urn:oasis:names:tc:opendocument:xmlns:meta:1.0'); $objWriter->writeAttribute('xmlns:number', 'urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0'); $objWriter->writeAttribute('xmlns:presentation', 'urn:oasis:names:tc:opendocument:xmlns:presentation:1.0'); $objWriter->writeAttribute('xmlns:svg', 'urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0'); $objWriter->writeAttribute('xmlns:chart', 'urn:oasis:names:tc:opendocument:xmlns:chart:1.0'); $objWriter->writeAttribute('xmlns:dr3d', 'urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0'); $objWriter->writeAttribute('xmlns:math', 'http://www.w3.org/1998/Math/MathML'); $objWriter->writeAttribute('xmlns:form', 'urn:oasis:names:tc:opendocument:xmlns:form:1.0'); $objWriter->writeAttribute('xmlns:script', 'urn:oasis:names:tc:opendocument:xmlns:script:1.0'); $objWriter->writeAttribute('xmlns:ooo', 'http://openoffice.org/2004/office'); $objWriter->writeAttribute('xmlns:ooow', 'http://openoffice.org/2004/writer'); $objWriter->writeAttribute('xmlns:oooc', 'http://openoffice.org/2004/calc'); $objWriter->writeAttribute('xmlns:dom', 'http://www.w3.org/2001/xml-events'); $objWriter->writeAttribute('xmlns:smil', 'urn:oasis:names:tc:opendocument:xmlns:smil-compatible:1.0'); $objWriter->writeAttribute('xmlns:anim', 'urn:oasis:names:tc:opendocument:xmlns:animation:1.0'); $objWriter->writeAttribute('xmlns:rpt', 'http://openoffice.org/2005/report'); $objWriter->writeAttribute('xmlns:of', 'urn:oasis:names:tc:opendocument:xmlns:of:1.2'); $objWriter->writeAttribute('xmlns:xhtml', 'http://www.w3.org/1999/xhtml'); $objWriter->writeAttribute('xmlns:grddl', 'http://www.w3.org/2003/g/data-view#'); $objWriter->writeAttribute('xmlns:officeooo', 'http://openoffice.org/2009/office'); $objWriter->writeAttribute('xmlns:tableooo', 'http://openoffice.org/2009/table'); $objWriter->writeAttribute('xmlns:drawooo', 'http://openoffice.org/2010/draw'); $objWriter->writeAttribute('xmlns:css3t', 'http://www.w3.org/TR/css3-text/'); $objWriter->writeAttribute('office:version', '1.2'); // Variables $stylePageLayout = $this->getPresentation()->getLayout()->getDocumentLayout(); if (empty($stylePageLayout)) { $stylePageLayout = 'sPL0'; } // office:styles $objWriter->startElement('office:styles'); // style:style $objWriter->startElement('style:style'); $objWriter->writeAttribute('style:name', 'sPres0'); $objWriter->writeAttribute('style:display-name', 'sPres0'); $objWriter->writeAttribute('style:family', 'presentation'); // style:graphic-properties $objWriter->startElement('style:graphic-properties'); $objWriter->writeAttribute('draw:fill-color', '#ffffff'); // > style:graphic-properties $objWriter->endElement(); // > style:style $objWriter->endElement(); foreach ($this->getPresentation()->getAllSlides() as $keySlide => $oSlide) { foreach ($oSlide->getShapeCollection() as $shape) { if ($shape instanceof Table) { $this->writeTableStyle($objWriter, $shape); } elseif ($shape instanceof Group) { $this->writeGroupStyle($objWriter, $shape); } elseif ($shape instanceof RichText) { $this->writeRichTextStyle($objWriter, $shape); } } $oBkgImage = $oSlide->getBackground(); if ($oBkgImage instanceof Image) { $this->writeBackgroundStyle($objWriter, $oBkgImage, $keySlide); } } // > office:styles $objWriter->endElement(); // office:automatic-styles $objWriter->startElement('office:automatic-styles'); // style:page-layout $objWriter->startElement('style:page-layout'); $objWriter->writeAttribute('style:name', $stylePageLayout); // style:page-layout-properties $objWriter->startElement('style:page-layout-properties'); $objWriter->writeAttribute('fo:margin-top', '0cm'); $objWriter->writeAttribute('fo:margin-bottom', '0cm'); $objWriter->writeAttribute('fo:margin-left', '0cm'); $objWriter->writeAttribute('fo:margin-right', '0cm'); $objWriter->writeAttribute('fo:page-width', Text::numberFormat(CommonDrawing::pixelsToCentimeters(CommonDrawing::emuToPixels($this->getPresentation()->getLayout()->getCX())), 1) . 'cm'); $objWriter->writeAttribute('fo:page-height', Text::numberFormat(CommonDrawing::pixelsToCentimeters(CommonDrawing::emuToPixels($this->getPresentation()->getLayout()->getCY())), 1) . 'cm'); $printOrientation = 'portrait'; if ($this->getPresentation()->getLayout()->getCX() > $this->getPresentation()->getLayout()->getCY()) { $printOrientation = 'landscape'; } $objWriter->writeAttribute('style:print-orientation', $printOrientation); $objWriter->endElement(); $objWriter->endElement(); $objWriter->endElement(); // office:master-styles $objWriter->startElement('office:master-styles'); // style:master-page $objWriter->startElement('style:master-page'); $objWriter->writeAttribute('style:name', 'Standard'); $objWriter->writeAttribute('style:display-name', 'Standard'); $objWriter->writeAttribute('style:page-layout-name', $stylePageLayout); $objWriter->writeAttribute('draw:style-name', 'sPres0'); $objWriter->endElement(); $objWriter->endElement(); $objWriter->endElement(); // Return return $objWriter->getData(); }
/** * Write the default style information for a Table shape * * @param XMLWriter $objWriter * @param Table $shape */ public function writeTableStyle(XMLWriter $objWriter, Table $shape) { foreach ($shape->getRows() as $keyRow => $shapeRow) { // style:style $objWriter->startElement('style:style'); $objWriter->writeAttribute('style:name', 'gr' . $this->shapeId . 'r' . $keyRow); $objWriter->writeAttribute('style:family', 'table-row'); // style:table-row-properties $objWriter->startElement('style:table-row-properties'); $objWriter->writeAttribute('style:row-height', Text::numberFormat(CommonDrawing::pixelsToCentimeters(CommonDrawing::pointsToPixels($shapeRow->getHeight())), 3) . 'cm'); $objWriter->endElement(); $objWriter->endElement(); foreach ($shapeRow->getCells() as $keyCell => $shapeCell) { // style:style $objWriter->startElement('style:style'); $objWriter->writeAttribute('style:name', 'gr' . $this->shapeId . 'r' . $keyRow . 'c' . $keyCell); $objWriter->writeAttribute('style:family', 'table-cell'); // style:graphic-properties $objWriter->startElement('style:graphic-properties'); if ($shapeCell->getFill()->getFillType() == Fill::FILL_SOLID) { $objWriter->writeAttribute('draw:fill', 'solid'); $objWriter->writeAttribute('draw:fill-color', '#' . $shapeCell->getFill()->getStartColor()->getRGB()); } if ($shapeCell->getFill()->getFillType() == Fill::FILL_GRADIENT_LINEAR) { $objWriter->writeAttribute('draw:fill', 'gradient'); $objWriter->writeAttribute('draw:fill-gradient-name', 'gradient_' . $shapeCell->getFill()->getHashCode()); } $objWriter->endElement(); // <style:graphic-properties // style:paragraph-properties $objWriter->startElement('style:paragraph-properties'); if ($shapeCell->getBorders()->getBottom()->getHashCode() == $shapeCell->getBorders()->getTop()->getHashCode() && $shapeCell->getBorders()->getBottom()->getHashCode() == $shapeCell->getBorders()->getLeft()->getHashCode() && $shapeCell->getBorders()->getBottom()->getHashCode() == $shapeCell->getBorders()->getRight()->getHashCode()) { $lineStyle = 'none'; $lineWidth = Text::numberFormat($shapeCell->getBorders()->getBottom()->getLineWidth() / 1.75, 2); $lineColor = $shapeCell->getBorders()->getBottom()->getColor()->getRGB(); switch ($shapeCell->getBorders()->getBottom()->getLineStyle()) { case Border::LINE_SINGLE: $lineStyle = 'solid'; } $objWriter->writeAttribute('fo:border', $lineWidth . 'pt ' . $lineStyle . ' #' . $lineColor); } else { $lineStyle = 'none'; $lineWidth = Text::numberFormat($shapeCell->getBorders()->getBottom()->getLineWidth() / 1.75, 2); $lineColor = $shapeCell->getBorders()->getBottom()->getColor()->getRGB(); switch ($shapeCell->getBorders()->getBottom()->getLineStyle()) { case Border::LINE_SINGLE: $lineStyle = 'solid'; } $objWriter->writeAttribute('fo:border-bottom', $lineWidth . 'pt ' . $lineStyle . ' #' . $lineColor); // TOP $lineStyle = 'none'; $lineWidth = Text::numberFormat($shapeCell->getBorders()->getTop()->getLineWidth() / 1.75, 2); $lineColor = $shapeCell->getBorders()->getTop()->getColor()->getRGB(); switch ($shapeCell->getBorders()->getTop()->getLineStyle()) { case Border::LINE_SINGLE: $lineStyle = 'solid'; } $objWriter->writeAttribute('fo:border-top', $lineWidth . 'pt ' . $lineStyle . ' #' . $lineColor); // RIGHT $lineStyle = 'none'; $lineWidth = Text::numberFormat($shapeCell->getBorders()->getRight()->getLineWidth() / 1.75, 2); $lineColor = $shapeCell->getBorders()->getRight()->getColor()->getRGB(); switch ($shapeCell->getBorders()->getRight()->getLineStyle()) { case Border::LINE_SINGLE: $lineStyle = 'solid'; } $objWriter->writeAttribute('fo:border-right', $lineWidth . 'pt ' . $lineStyle . ' #' . $lineColor); // LEFT $lineStyle = 'none'; $lineWidth = Text::numberFormat($shapeCell->getBorders()->getLeft()->getLineWidth() / 1.75, 2); $lineColor = $shapeCell->getBorders()->getLeft()->getColor()->getRGB(); switch ($shapeCell->getBorders()->getLeft()->getLineStyle()) { case Border::LINE_SINGLE: $lineStyle = 'solid'; } $objWriter->writeAttribute('fo:border-left', $lineWidth . 'pt ' . $lineStyle . ' #' . $lineColor); } $objWriter->endElement(); $objWriter->endElement(); foreach ($shapeCell->getParagraphs() as $shapeParagraph) { foreach ($shapeParagraph->getRichTextElements() as $shapeRichText) { if ($shapeRichText instanceof Run) { // Style des font text if (!isset($this->arrStyleTextFont[$shapeRichText->getFont()->getHashCode()])) { $this->arrStyleTextFont[$shapeRichText->getFont()->getHashCode()] = $shapeRichText->getFont(); } } } } } } }