/**
  * This function checks if a image is included with the correct size.
  * Therefore an test image with known size is choosen (TestPicture500x256.png).
  */
 public function test_image_size_2()
 {
     $units = new helper_plugin_odt_units();
     $renderer = new renderer_plugin_odt_page();
     $renderer->document_start();
     $renderer->_odtAddImage(TMP_DIR . '/data/TestPicture500x256.png');
     // There should be a frame
     $start = strpos($renderer->doc, '<draw:frame');
     $end = strpos($renderer->doc, '</draw:frame>');
     $frame = substr($renderer->doc, $start, $end + strlen('</draw:frame>') - $start);
     $this->assertFalse(empty($frame));
     // Check that the width has the unit 'cm' and that it is
     // calculated according to the formula ($width/96.0)*2.54
     $result = preg_match('/svg:width="[^"]*"/', $renderer->doc, $widths);
     $this->assertEquals($result, 1);
     $unit = substr($widths[0], strlen('svg:width='));
     $unit = trim($unit, '"');
     $width = $units->getDigits($unit);
     $unit = $units->stripDigits($unit);
     $this->assertEquals($unit, 'cm');
     $this->assertEquals($width, 500 / 96.0 * 2.54);
     // Check that the height has the unit 'cm' and that it is
     // calculated according to the formula ($height/96.0)*2.54
     $result = preg_match('/svg:height="[^"]*"/', $renderer->doc, $heights);
     $this->assertEquals($result, 1);
     $unit = substr($heights[0], strlen('svg:height='));
     $unit = trim($unit, '"');
     $height = $units->getDigits($unit);
     $unit = $units->stripDigits($unit);
     $this->assertEquals($unit, 'cm');
     $this->assertEquals($height, 256 / 96.0 * 2.54);
 }
Пример #2
0
 /**
  * Ensure that stripDigits() strips all digits from the left correctly.
  */
 public function test_stripDigits()
 {
     $units = new helper_plugin_odt_units();
     $this->assertEquals($units->stripDigits('1cm'), 'cm');
     $this->assertEquals($units->stripDigits('12mm'), 'mm');
     $this->assertEquals($units->stripDigits('123in'), 'in');
     $this->assertEquals($units->stripDigits('1234pt'), 'pt');
     $this->assertEquals($units->stripDigits('12345pc'), 'pc');
     $this->assertEquals($units->stripDigits('123456px'), 'px');
     $this->assertEquals($units->stripDigits('1234567em'), 'em');
     $this->assertEquals($units->stripDigits('9m'), 'm');
     $this->assertEquals($units->stripDigits('9km'), 'km');
     $this->assertEquals($units->stripDigits('9mi'), 'mi');
     $this->assertEquals($units->stripDigits('9ft'), 'ft');
     $this->assertEquals($units->stripDigits('9ft23'), 'ft23');
 }