function convert ($format, $attr) {
		if ($this->isRemote() || $format != 'png') // @@
			return false;
		$name = file_strip_extension($this->fname);  // remove file extension
		$mo = MediaObjectFactory::createMediaObject($this->pagename, "$name.$format");
		if (!$mo->exists() || $mo->olderThan($this)) {
			@unlink($mo->path());
			RunTool('ffmpeg', sprintf("IN=%s OUT=%s TARGETFORMAT=%s TIME=2", $this->path(), $mo->path(), $format), 'pipe');
			return $mo->exists() ? $mo : false;
		}
		return $mo;
	}
	function createMO ($format, $attr, $showMessages=false) {
		$fname = file_strip_extension($this->fname).".$format";
		$mo = MediaObjectFactory::createMediaObject($this->pagename, $fname);
		if ($this->mustReconvert($mo)) {
			$in  = $this->path();
			$out = $mo->path();
			RunTool('pec2img', "IN=$in OUT=$out");
			if ($format != 'eps' && $format != 'pdf' && isset($attr['scale'])) 
				RunTool('mogrify', "SCALE=$attr[scale] FILE=".$mo->path());
//			$mo->scale($this->attribs->getAttrib('scale'));
		}
		return $mo;
	}
	function createMO ($format, $attr, $showMessages=false) {
		//      Example:
		//      set terminal gif
		//      set output "test.gif"
		//      plot x**2

		$fname = file_strip_extension($this->fname).".$format";
		$mo = MediaObjectFactory::createMediaObject($this->pagename, $fname);
		if ($this->mustReconvert($mo)) {
			if ($showMessages)
				message("creating gnuplot image in ".strtoupper($format)." format", 'start');
			$scripthead = "cd '".$mo->dir()."'\nset output '$fname'\n";
			switch ($format) {
				case "gif":	$scripthead .= "set term gif transparent crop";	break;
				case "png":	$scripthead .= "set term png truecolor crop";	break;
				case 'eps': $scripthead .= "set term postscript eps color"; break;
				case 'pdf': $scripthead .= "set term pdf color"; break;
			}
			$script = file_get_contents($this->path());
			$script = preg_replace('/^\s*set?\s+((o)|(ou\w*))/', '', $script); // remove "set output" statements
			$script = preg_replace('/^\s*set?\s+t\w/', '', $script);           // remove "set terminal" statements
			$script = "$scripthead\n$script";
			$tmpfile = $this->path().".tmp";
			$f = fopen($tmpfile, "w");
			fputs($f, $script);
			fclose($f);
			RunTool('gnuplot', "SCRIPT=$tmpfile");
//			unlink($tmpfile);
			if ($format == 'pdf') {
				// the gnuplot generated bounding box is too wide, so we
				// compute and assign a minimal box
				if ($showMessages)
					message("adapting bounding box");
//				assignMinimalBoundingBoxToPDF($mo->path());
			}
			// @@ the current gnuplot version doesn't handle transparency correctly, so we apply it seperately
			// @@ can hopefully be removed again
			elseif ($format == 'png')
				RunTool('convert', "IN=".$mo->path()." OUT=".$mo->path()." TRANSPARENT=white");

			if ($format != 'eps' && $format != 'pdf' && isset($attr['scale'])) 
				RunTool('mogrify', "SCALE=$attr[scale] FILE=".$mo->path());
			if ($showMessages)
				message("", 'end');
		}
		return $mo;
	}
	function convert ($format, $attr) {
		$currentFormat = $this->format();
		$format = strtolower(trim($format));
		if ($format == '')
			return false;
		if ($currentFormat == $format)
			return $this;
			
		$name = file_strip_extension($this->fname);  // remove file extension
		$newMO = MediaObjectFactory::createMediaObject($this->pagename, "$name.$format");
		if (!$newMO->exists() || $newMO->olderThan($this)) {
			if ($showMessages)
				message("creating FIG image in ".strtoupper($format)." format", 'start');
			RunTool('fig2dev', "IN=".$this->path()." OUT=".$mo->path()." FORMAT=$format");
		}
		return $newMO;
	}
	function getHTML ($attr) {
		if ($this->fname == '')
			return '';
		$ext = strtolower(file_extension($this->fname));
		$appletdir = $this->dir()."/".file_strip_extension($this->fname);
		$appleturl = dirname($this->url())."/".file_strip_extension($this->fname);
		recursive_mkdir($appletdir);
		if ($ext == 'jar' || $ext == 'zip') {
			$cwd = getcwd();
			chdir($appletdir);
			if ($ext == 'zip')
				RunTool('unzip', "IN=".$this->path(), 'pipe');
			else
				RunTool('unzip', "IN=".$this->path()." FILE=index.html", 'pipe');
			$ok = $this->readHTMLFile('index.html');
			chdir($cwd);
			if (!$ok)
				return '';
		}
		if (!isset($this->attribs['archive']))
			return '';

		// generate html file containing the applet
		$ret = "<html><body>\n";
		$ret.= '<div style="margin:0;padding:0"><applet';
		foreach ($this->attribs as $k=>$v)
			$ret .= " $k=\"$v\"";
		$ret .= ">\n";
		foreach ($this->params as $k=>$v)
			$ret .= "<param name=\"$k\" value=\"$v\"/>\n";
		$ret .= "</applet></div>";
		$ret .= "</body></html>";
		$f = fopen("$appletdir/applet.html", "w");
		fputs($f, $ret);
		fclose($f);

		// return iframe with above applet page
		$ret = "<iframe src='$appleturl/applet.html'";
		$ret.= " scrolling='no' frameborder='0' marginwidth='0' marginheight='0'";
		$ret.= "	width='{$this->attribs['width']}' height='{$this->attribs['height']}'>\n";
		$ret.= "<p>Your browser doesn't support embedded frames</p>\n";
		$ret.= "</iframe>";
		return $ret;
	}
Ejemplo n.º 6
0
function file_replace_extension ($fname, $ext) {
	return file_strip_extension($fname) . ".$ext";
}
	function svg2format ($svgfile, $targetfile, $format) {
		$pdffile = file_strip_extension($targetfile).'.pdf';
		if ($this->svg2eps($svgfile, $epsfile)) {			
			RunTool('convert', "IN=$epsfile OUT=$targetfile");
			return file_exists($targetfile);
		}
		return false;
	}
	function tex2format ($texfile, $format) {
		if ($format == 'eps')
			return $this->tex2eps($texfile);
		if ($format == 'pdf')
			return $this->tex2pdf($texfile);

		$resfile = file_strip_extension($texfile).".$format";
		if (file_exists($resfile))
			return $resfile;

		$epsfile = $this->tex2eps($texfile);
		if ($epsfile) {
			RunTool('convert', "DENSITY=110x110 TRANSPARENT=white IN=$epsfile OUT=$resfile");
			return file_exists($resfile) ? $resfile : false;
		}
		return false;
	}
	function convertFO ($fofile, $foproc) {		
		if (is_object($foproc)) {
			message("converting FO to PDF");
			$fname = file_strip_extension($fofile);
			@unlink("$fname.pdf");
			$ok = $foproc->process($fofile, "$fname.pdf");
			message("done", 'end');
			if ($ok && file_exists("$fname.pdf"))
				return "$fname.pdf";
			return false;
		}
		error_message("no FO processor specified", false);
		return false;
	}