示例#1
0
文件: Image.php 项目: Senasum/PHPWord
 /**
  * Write element
  */
 public function write()
 {
     $xmlWriter = $this->getXmlWriter();
     $element = $this->getElement();
     if (!$element instanceof \PhpOffice\PhpWord\Element\Image) {
         return;
     }
     $mediaIndex = $element->getMediaIndex();
     $target = 'Pictures/' . $element->getTarget();
     $style = $element->getStyle();
     $width = Converter::pixelToCm($style->getWidth());
     $height = Converter::pixelToCm($style->getHeight());
     $xmlWriter->startElement('text:p');
     $xmlWriter->writeAttribute('text:style-name', 'Standard');
     $xmlWriter->startElement('draw:frame');
     $xmlWriter->writeAttribute('draw:style-name', 'fr' . $mediaIndex);
     $xmlWriter->writeAttribute('draw:name', $element->getElementId());
     $xmlWriter->writeAttribute('text:anchor-type', 'as-char');
     $xmlWriter->writeAttribute('svg:width', $width . 'cm');
     $xmlWriter->writeAttribute('svg:height', $height . 'cm');
     $xmlWriter->writeAttribute('draw:z-index', $mediaIndex);
     $xmlWriter->startElement('draw:image');
     $xmlWriter->writeAttribute('xlink:href', $target);
     $xmlWriter->writeAttribute('xlink:type', 'simple');
     $xmlWriter->writeAttribute('xlink:show', 'embed');
     $xmlWriter->writeAttribute('xlink:actuate', 'onLoad');
     $xmlWriter->endElement();
     // draw:image
     $xmlWriter->endElement();
     // draw:frame
     $xmlWriter->endElement();
     // text:p
 }
示例#2
0
 /**
  * Test unit conversion functions with various numbers
  */
 public function testUnitConversions()
 {
     $values[] = 0;
     // zero value
     $values[] = rand(1, 100) / 100;
     // fraction number
     $values[] = rand(1, 100);
     // integer
     foreach ($values as $value) {
         $result = Converter::cmToTwip($value);
         $this->assertEquals($value / 2.54 * 1440, $result);
         $result = Converter::cmToInch($value);
         $this->assertEquals($value / 2.54, $result);
         $result = Converter::cmToPixel($value);
         $this->assertEquals($value / 2.54 * 96, $result);
         $result = Converter::cmToPoint($value);
         $this->assertEquals($value / 2.54 * 72, $result);
         $result = Converter::cmToEmu($value);
         $this->assertEquals(round($value / 2.54 * 96 * 9525), $result);
         $result = Converter::inchToTwip($value);
         $this->assertEquals($value * 1440, $result);
         $result = Converter::inchToCm($value);
         $this->assertEquals($value * 2.54, $result);
         $result = Converter::inchToPixel($value);
         $this->assertEquals($value * 96, $result);
         $result = Converter::inchToPoint($value);
         $this->assertEquals($value * 72, $result);
         $result = Converter::inchToEmu($value);
         $this->assertEquals(round($value * 96 * 9525), $result);
         $result = Converter::pixelToTwip($value);
         $this->assertEquals($value / 96 * 1440, $result);
         $result = Converter::pixelToCm($value);
         $this->assertEquals($value / 96 * 2.54, $result);
         $result = Converter::pixelToPoint($value);
         $this->assertEquals($value / 96 * 72, $result);
         $result = Converter::pixelToEMU($value);
         $this->assertEquals(round($value * 9525), $result);
         $result = Converter::pointToTwip($value);
         $this->assertEquals($value * 20, $result);
         $result = Converter::pointToPixel($value);
         $this->assertEquals($value / 72 * 96, $result);
         $result = Converter::pointToEMU($value);
         $this->assertEquals(round($value / 72 * 96 * 9525), $result);
         $result = Converter::emuToPixel($value);
         $this->assertEquals(round($value / 9525), $result);
         $result = Converter::degreeToAngle($value);
         $this->assertEquals((int) round($value * 60000), $result);
         $result = Converter::angleToDegree($value);
         $this->assertEquals(round($value / 60000), $result);
     }
 }