对ODF作了改进,让其能支持动态图片

This commit is contained in:
wlx 2011-11-04 10:04:41 +00:00
parent 86cdaf39ff
commit 21590fc4d8
1 changed files with 21 additions and 5 deletions

View File

@ -1,6 +1,6 @@
<?php
require 'zip/PclZipProxy.php';
require 'zip/PhpZipProxy.php';
//require 'zip/PclZipProxy.php';
//require 'zip/PhpZipProxy.php';
require 'Segment.php';
class OdfException extends Exception
{}
@ -99,6 +99,19 @@ class Odf
$this->vars[$tag] = str_replace("\n", "<text:line-break/>", $value);
return $this;
}
public function setVarsWithHTMLTable($key, $value, $encode = true, $charset = 'ISO-8859')
{
$tag= $this->config['DELIMITER_LEFT'] . $key . $this->config['DELIMITER_RIGHT'];
if (strpos($this->contentXml, $tag) === false && strpos($this->stylesXml , $tag) === false) {
throw new OdfException("var $key not found in the document");
}
//$value = $encode ? htmlspecialchars($value) : $value;
$value = ($charset == 'ISO-8859') ? utf8_encode($value) : $value;
//$split=preg_split('/\<table(.*?)\>(.*?)\<\/table\>/m', $value);
$this->vars[$tag] = str_replace("\n", "<text:line-break/>", $value);
return $this;
}
/**
* Assign a template variable as a picture
*
@ -109,12 +122,13 @@ class Odf
*/
public function setImage($key, $value)
{
$filename = strtok(strrchr($value, '/'), '/.');
$file = substr(strrchr($value, '/'), 1);
$size = @getimagesize($value);
if ($size === false) {
throw new OdfException("Invalid image");
}
$filename=md5($value);;
$imgext=array('','.gif','.jpg','.png','.swf','.psd','.bmp','.tif','.tif','.jpc','.jp2','.jpx','.jb2','.swc','.iff','.wbmp','.xbm','.ico');
$file=$filename.$imgext[$size[2]];
list ($width, $height) = $size;
$width *= self::PIXEL_TO_CM;
$height *= self::PIXEL_TO_CM;
@ -283,7 +297,9 @@ IMG;
throw new OdfException('Error during manifest file export');
}
foreach ($this->images as $imageKey => $imageValue) {
$this->file->addFile($imageKey, 'Pictures/' . $imageValue);
//$this->file->addFile($imageKey, 'Pictures/' . $imageValue);
$this->file->addFromString('Pictures/' . $imageValue,file_get_contents($imageKey));
}
$this->file->close(); // seems to bug on windows CLI sometimes
}