/** * 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); }
protected function setListStyleImage($style, $level, $file) { if ($this->units == NULL) { $this->units = plugin_load('helper', 'odt_units'); } $odt_file = $this->addFileAsPicture($file); if ($odt_file != NULL) { $style->setPropertyForLevel($level, 'list-level-style', 'image'); $style->setPropertyForLevel($level, 'href', $odt_file); $style->setPropertyForLevel($level, 'type', 'simple'); $style->setPropertyForLevel($level, 'show', 'embed'); $style->setPropertyForLevel($level, 'actuate', 'onLoad'); $style->setPropertyForLevel($level, 'vertical-pos', 'middle'); $style->setPropertyForLevel($level, 'vertical-rel', 'line'); list($width, $height) = renderer_plugin_odt_page::_odtGetImageSize($file); if (empty($width) || empty($height)) { $width = '0.5'; $height = $width; } $style->setPropertyForLevel($level, 'width', $width . 'cm'); $style->setPropertyForLevel($level, 'height', $height . 'cm'); // ??? Wie berechnen... $text_indent = $this->units->getDigits($style->getPropertyFromLevel($level, 'text-indent')); $margin_left = $this->units->getDigits($style->getPropertyFromLevel($level, 'margin_left')); $tab_stop_position = $this->units->getDigits($style->getPropertyFromLevel($level, 'list-tab-stop-position')); $minimum = $margin_left + $text_indent + $width; if ($minimum > $tab_stop_position) { $inc = abs($text_indent); if ($inc == 0) { $inc = 0.5; } while ($minimum > $tab_stop_position) { $tab_stop_position += $inc; } } $style->setPropertyForLevel($level, 'list-tab-stop-position', $tab_stop_position . 'cm'); } }
/** * Render a wiki internal link. * In book export mode a local link with a name/test will be inserted if the * referenced page is included in the exported pages. Otherwise an external * link will be created. * * @param string $id page ID to link to. eg. 'wiki:syntax' * @param string|array $name name for the link, array for media file * @param bool $returnonly whether to return odt or write to doc attribute * * @author Andreas Gohr <*****@*****.**>, LarsDW223 */ function internallink($id, $name = NULL, $returnonly = false) { global $ID; // default name is based on $id as given $default = $this->_simpleTitle($id); // now first resolve and clean up the $id resolve_pageid(getNS($ID), $id, $exists); $name = $this->_getLinkTitle($name, $default, $isImage, $id); // build the absolute URL (keeping a hash if any) list($id, $hash) = explode('#', $id, 2); // Is the link a link to a page included in the book? $pages = $this->actioninstance->getExportedPages(); if (in_array($id, $pages)) { // Yes, create a local link with a name parent::locallink_with_name($hash, $id, $name); return; } // No, create an external link $url = wl($id, '', true); if ($hash) { $url .= '#' . $hash; } if ($ID == $id) { if ($returnonly) { return $this->reference($hash, $name); } else { $this->doc .= $this->reference($hash, $name); } } else { if ($returnonly) { return $this->_doLink($url, $name); } else { $this->doc .= $this->_doLink($url, $name); } } }