Qual: Can externalize fonts.

This commit is contained in:
Laurent Destailleur 2011-08-14 18:25:15 +00:00
parent d6bb618dfe
commit 2409c7fbfd
14 changed files with 1224 additions and 1175 deletions

View File

@ -5,9 +5,4 @@ embedded-javascript-library usr/share/dolibarr/htdocs/includes/ckeditor/ckeditor
embedded-javascript-library usr/share/dolibarr/htdocs/includes/fckeditor/fckeditor.js
embedded-php-library usr/share/dolibarr/htdocs/includes/magpierss/extlib/Snoopy.class.inc
embedded-php-library usr/share/dolibarr/htdocs/includes/magpierss/rss_parse.inc
embedded-php-library usr/share/dolibarr/htdocs/includes/nusoap/lib/nusoap.php
# embedded fonts, wich are specific to Dolibarr usage
font-in-non-font-package usr/share/dolibarr/htdocs/includes/artichow/font/Tuffy.ttf
font-in-non-font-package usr/share/dolibarr/htdocs/includes/artichow/font/TuffyBold.ttf
font-in-non-font-package usr/share/dolibarr/htdocs/includes/artichow/font/TuffyBoldItalic.ttf
font-in-non-font-package usr/share/dolibarr/htdocs/includes/artichow/font/TuffyItalic.ttf
embedded-php-library usr/share/dolibarr/htdocs/includes/nusoap/lib/nusoap.php

View File

@ -2,7 +2,7 @@
#----------------------------------------------------------------------------
# \file build/makepack-dolibarr.pl
# \brief Dolibarr package builder (tgz, zip, rpm, deb, exe, aps)
# \version $Id: makepack-dolibarr.pl,v 1.144 2011/08/14 17:17:20 eldy Exp $
# \version $Id: makepack-dolibarr.pl,v 1.145 2011/08/14 18:26:21 eldy Exp $
# \author (c)2004-2011 Laurent Destailleur <eldy@users.sourceforge.net>
#----------------------------------------------------------------------------
@ -45,7 +45,7 @@ if (-d "/usr/src/RPM") { $RPMDIR="/usr/src/RPM"; } # mandrake
use vars qw/ $REVISION $VERSION /;
$REVISION='$Revision: 1.144 $'; $REVISION =~ /\s(.*)\s/; $REVISION=$1;
$REVISION='$Revision: 1.145 $'; $REVISION =~ /\s(.*)\s/; $REVISION=$1;
$VERSION="3.2 (build $REVISION)";
@ -503,6 +503,7 @@ if ($nboftargetok) {
$ret=`rm -fr $BUILDROOT/$FILENAMETGZ2/usr/share/$PROJECT/build/zip`;
$ret=`rm -fr $BUILDROOT/$FILENAMETGZ2/usr/share/$PROJECT/build/perl`;
# We remove embedded libraries or fonts
$ret=`rm -fr $BUILDROOT/$FILENAMETGZ2/usr/share/$PROJECT/htdocs/includes/artichow/font`,
$ret=`rm -fr $BUILDROOT/$FILENAMETGZ2/usr/share/$PROJECT/htdocs/includes/barcode/php-barcode/fonts`,
#$ret=`rm -fr $BUILDROOT/$FILENAMETGZ2/usr/share/$PROJECT/htdocs/includes/odtphp/zip/pclzip`;
$ret=`rm -fr $BUILDROOT/$FILENAMETGZ2/usr/share/$PROJECT/htdocs/includes/odtphp/zip/pclzip/gnu-lgpl.txt`;
@ -703,6 +704,7 @@ if ($nboftargetok) {
$ret=`rm -fr $BUILDROOT/$PROJECT.tmp/usr/share/$PROJECT/build/rpm`;
$ret=`rm -fr $BUILDROOT/$PROJECT.tmp/usr/share/$PROJECT/build/zip`;
# We remove embedded libraries or fonts
$ret=`rm -fr $BUILDROOT/$PROJECT.tmp/usr/share/$PROJECT/htdocs/includes/artichow/font`,
$ret=`rm -fr $BUILDROOT/$PROJECT.tmp/usr/share/$PROJECT/htdocs/includes/barcode/php-barcode/fonts`,
$ret=`rm -fr $BUILDROOT/$PROJECT.tmp/usr/share/$PROJECT/htdocs/includes/nusoap/lib/Mail`;
$ret=`rm -fr $BUILDROOT/$PROJECT.tmp/usr/share/$PROJECT/htdocs/includes/odtphp/zip/pclzip`;

View File

@ -20,7 +20,7 @@
* \file htdocs/core/class/dolgraph.class.php
* \ingroup core
* \brief Fichier de la classe mere de gestion des graph
* \version $Id: dolgraph.class.php,v 1.7 2011/07/31 23:45:15 eldy Exp $
* \version $Id: dolgraph.class.php,v 1.8 2011/08/14 18:26:26 eldy Exp $
*
* Usage:
* $graph_data = array(array('labelA',yA),array('labelB',yB));
@ -415,6 +415,7 @@ class DolGraph
*/
function draw_artichow($file)
{
global $artichow_defaultfont;
dol_syslog("DolGraph.class::draw_artichow this->type=".$this->type);
if (! defined('SHADOW_RIGHT_TOP')) define('SHADOW_RIGHT_TOP',3);
@ -442,7 +443,8 @@ class DolGraph
if (isset($this->title))
{
$graph->title->set($this->title);
$graph->title->setFont(new Tuffy(10));
//print $artichow_defaultfont;exit;
$graph->title->setFont(new $artichow_defaultfont(10));
}
if (is_array($this->bgcolor)) $graph->setBackgroundColor($bgcolor);
@ -555,7 +557,7 @@ class DolGraph
//$plot->reduce(80); // Evite temps d'affichage trop long et nombre de ticks absisce satures
$group->legend->setTextFont(new Tuffy(10)); // This is to force Artichow to use awFileFontDriver to
$group->legend->setTextFont(new $artichow_defaultfont(10)); // This is to force Artichow to use awFileFontDriver to
// solve a bug in Artichow with UTF8
if (sizeof($this->Legend))
{
@ -568,7 +570,7 @@ class DolGraph
}
$group->axis->bottom->setLabelText($legends);
$group->axis->bottom->label->setFont(new Tuffy(7));
$group->axis->bottom->label->setFont(new $artichow_defaultfont(7));
//print $group->axis->bottom->getLabelNumber();
if ($this->labelInterval > 0) $group->axis->bottom->setLabelInterval($this->labelInterval);

View File

@ -18,27 +18,27 @@ define('ARTICHOW', dirname(__FILE__).DIRECTORY_SEPARATOR.'php'.substr(phpversion
* Path to TrueType fonts
*/
if(defined('ARTICHOW_FONT') === FALSE) {
define('ARTICHOW_FONT', ARTICHOW.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'font');
}
/*
* Patterns directory
*/
if(defined('ARTICHOW_PATTERN') === FALSE) {
define('ARTICHOW_PATTERN', ARTICHOW.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'patterns');
}
/*
* Images directory
*/
if(defined('ARTICHOW_IMAGE') === FALSE) {
define('ARTICHOW_IMAGE', ARTICHOW.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'images');
}
/*
@ -50,9 +50,9 @@ define('ARTICHOW_CACHE', TRUE);
* Cache directory
*/
if(defined('ARTICHOW_CACHE') === FALSE) {
define('ARTICHOW_CACHE_DIRECTORY', ARTICHOW.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'cache');
}
/*
@ -69,11 +69,19 @@ define('ARTICHOW_DEPRECATED', TRUE);
/*
* Fonts to use
*/
$fonts = array(
// DOL_CHANGE LDR
if (defined('ARTICHOW_FONT_NAMES')) $fonts=explode(',',constant('ARTICHOW_FONT_NAMES'));
else $fonts = array(
'Tuffy',
'TuffyBold',
'TuffyBoldItalic',
'TuffyItalic'
);
global $artichow_defaultfont;
$artichow_defaultfont=$fonts[0];
//var_dump(ARTICHOW_FONT);
//var_dump($fonts);
//var_dump($artichow_defaultfont);
//exit;
?>

View File

@ -6,7 +6,7 @@
* Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.
*
*/
require_once dirname(__FILE__)."/Graph.class.php";
@ -23,7 +23,7 @@ require_once dirname(__FILE__)."/Graph.class.php";
* @var array
*/
var $components;
/**
* Build the component group
*/
@ -81,7 +81,7 @@ registerClass('ComponentGroup', TRUE);
* @var float
*/
var $y = 0.5;
/**
* Component absolute width (in pixels)
*
@ -89,7 +89,7 @@ registerClass('ComponentGroup', TRUE);
* @var int
*/
var $w;
/**
* Component absolute height (in pixels)
*
@ -111,71 +111,74 @@ registerClass('ComponentGroup', TRUE);
* @var float
*/
var $left;
/**
* Component background color
*
* @var Color
*/
var $background;
/**
* Component padding
*
* @var Side
*/
var $padding;
/**
* Component space
*
* @var Side
*/
var $space;
/**
* Component title
*
* @var Label
*/
var $title;
/**
* Adjust automatically the component ?
*
* @var bool
*/
var $auto = TRUE;
/**
* Legend
*
* @var Legend
*/
var $legend;
/**
* Build the component
*/
function awComponent() {
// DOL_CHANGE LDR Fix to allow usage of other fonts
global $artichow_defaultfont;
$classfontname='aw'.str_replace('-','_',$artichow_defaultfont);
// Component legend
$this->legend = new awLegend();
$this->padding = new awSide(25, 25, 25, 25);
$this->space = new awSide(0, 0, 0, 0);
// Component title
$this->title = new awLabel(
NULL,
new awTuffy(10),
new $classfontname(10),
NULL,
0
);
$this->title->setAlign(LABEL_CENTER, LABEL_TOP);
}
/**
* Adjust automatically the component ?
*
@ -184,7 +187,7 @@ registerClass('ComponentGroup', TRUE);
function auto($auto) {
$this->auto = (bool)$auto;
}
/**
* Change the size of the component
*
@ -192,12 +195,12 @@ registerClass('ComponentGroup', TRUE);
* @param int $height Component height (from 0 to 1)
*/
function setSize($width, $height) {
$this->width = (float)$width;
$this->height = (float)$height;
}
/**
* Change the absolute size of the component
*
@ -205,12 +208,12 @@ registerClass('ComponentGroup', TRUE);
* @param int $h Component height (in pixels)
*/
function setAbsSize($w, $h) {
$this->w = (int)$w;
$this->h = (int)$h;
}
/**
* Change component background color
*
@ -221,7 +224,7 @@ registerClass('ComponentGroup', TRUE);
$this->background = $color;
}
}
/**
* Change component background gradient
*
@ -232,7 +235,7 @@ registerClass('ComponentGroup', TRUE);
$this->background = $gradient;
}
}
/**
* Change component background image
*
@ -243,7 +246,7 @@ registerClass('ComponentGroup', TRUE);
$this->background = $image;
}
}
/**
* Return the component background
*
@ -252,7 +255,7 @@ registerClass('ComponentGroup', TRUE);
function getBackground() {
return $this->background;
}
/**
* Change component padding
*
@ -264,7 +267,7 @@ registerClass('ComponentGroup', TRUE);
function setPadding($left = NULL, $right = NULL, $top = NULL, $bottom = NULL) {
$this->padding->set($left, $right, $top, $bottom);
}
/**
* Change component space
*
@ -276,7 +279,7 @@ registerClass('ComponentGroup', TRUE);
function setSpace($left = NULL, $right = NULL, $bottom = NULL, $top = NULL) {
$this->space->set($left, $right, $bottom, $top);
}
/**
* Change the absolute position of the component on the graph
*
@ -284,12 +287,12 @@ registerClass('ComponentGroup', TRUE);
* @var int $y Left-top corner Y position
*/
function setAbsPosition($left, $top) {
$this->left = (int)$left;
$this->top = (int)$top;
}
/**
* Set the center of the component
*
@ -297,29 +300,29 @@ registerClass('ComponentGroup', TRUE);
* @param int $y Position on Y axis of the center of the component
*/
function setCenter($x, $y) {
$this->x = (float)$x;
$this->y = (float)$y;
}
/**
* Get component coords with its padding
*
* @return array Coords of the component
*/
function getPosition() {
// Get component coords
$x1 = $this->padding->left;
$y1 = $this->padding->top;
$x2 = $this->w - $this->padding->right;
$y2 = $this->h - $this->padding->bottom;
return array($x1, $y1, $x2, $y2);
}
/**
* Init the drawing of the component
*/
@ -327,57 +330,57 @@ registerClass('ComponentGroup', TRUE);
// Set component background
$background = $this->getBackground();
if($background !== NULL) {
$p1 = new awPoint(0, 0);
$p2 = new awPoint($this->w - 1, $this->h - 1);
if(is_a($background, 'awImage')) {
$drawer->copyImage(
$background,
$p1,
$p2
);
} else {
$drawer->filledRectangle(
$background,
new awLine($p1, $p2)
);
}
}
}
/**
* Finalize the drawing of the component
*/
function finalize($drawer) {
// Draw component title
$point = new awPoint(
$this->w / 2,
$this->padding->top - 8
);
$this->title->draw($drawer, $point);
// Draw legend
$this->legend->draw($drawer);
}
/**
* Draw the grid around your component
*
* @param Drawer A drawer
* @return array Coords for the component
*/
/**
* Draw the component on the graph
* Component should be drawed into specified coords
@ -389,8 +392,8 @@ registerClass('ComponentGroup', TRUE);
* @param int $y2
* @param bool $aliasing Use anti-aliasing to draw the component ?
*/
/**
* Get space width in pixels
*
@ -399,16 +402,16 @@ registerClass('ComponentGroup', TRUE);
* @return array
*/
function getSpace($width, $height) {
$left = (int)($width * $this->space->left / 100);
$right = (int)($width * $this->space->right / 100);
$top = (int)($height * $this->space->top / 100);
$bottom = (int)($height * $this->space->bottom / 100);
return array($left, $right, $top, $bottom);
}
}
registerClass('Component', TRUE);

View File

@ -29,7 +29,7 @@ require_once ARTICHOW."/inc/Font.class.php";
require_once ARTICHOW."/inc/Gradient.class.php";
/**
* A graph
* A graph
*
* @package Artichow
*/
@ -48,35 +48,35 @@ class awGraph extends awImage {
* @var int
*/
var $timeout = 0;
/**
* Graph timing ?
*
* @var bool
*/
var $timing;
/**
* Components
*
* @var array
*/
var $components = array();
/**
* Some labels to add to the component
*
* @var array
*/
var $labels = array();
/**
* Graph title
*
* @var Label
*/
var $title;
/**
* Construct a new graph
*
@ -86,29 +86,33 @@ class awGraph extends awImage {
* @param int $timeout Cache timeout (unix timestamp)
*/
function awGraph($width = NULL, $height = NULL, $name = NULL, $timeout = 0) {
// DOL_CHANGE LDR Fix to allow usage of other fonts
global $artichow_defaultfont;
$classfontname='aw'.str_replace('-','_',$artichow_defaultfont);
parent::awImage();
$this->setSize($width, $height);
if(ARTICHOW_CACHE) {
$this->name = $name;
$this->timeout = $timeout;
// Clean sometimes all the cache
if(mt_rand(0, 5000) === 0) {
awGraph::cleanCache();
}
if($this->name !== NULL) {
$file = ARTICHOW_CACHE_DIRECTORY."/".$this->name."-time";
if(is_file($file)) {
$type = awGraph::cleanGraphCache($file);
if($type === NULL) {
awGraph::deleteFromCache($this->name);
} else {
@ -116,23 +120,23 @@ class awGraph extends awImage {
readfile(ARTICHOW_CACHE_DIRECTORY."/".$this->name."");
exit;
}
}
}
}
$this->title = new awLabel(
NULL,
new awTuffy(16),
new $classfontname(16),
NULL,
0
);
$this->title->setAlign(LABEL_CENTER, LABEL_BOTTOM);
}
/**
* Delete a graph from the cache
*
@ -142,59 +146,59 @@ class awGraph extends awImage {
function deleteFromCache($name) {
if(ARTICHOW_CACHE) {
if(is_file(ARTICHOW_CACHE_DIRECTORY."/".$name."-time")) {
unlink(ARTICHOW_CACHE_DIRECTORY."/".$name."");
unlink(ARTICHOW_CACHE_DIRECTORY."/".$name."-time");
}
}
}
/**
* Delete all graphs from the cache
*/
function deleteAllCache() {
if(ARTICHOW_CACHE) {
$dp = opendir(ARTICHOW_CACHE_DIRECTORY);
while($file = readdir($dp)) {
if($file !== '.' and $file != '..') {
unlink(ARTICHOW_CACHE_DIRECTORY."/".$file);
}
}
}
}
/**
* Clean cache
*/
function cleanCache() {
if(ARTICHOW_CACHE) {
$glob = glob(ARTICHOW_CACHE_DIRECTORY."/*-time");
foreach($glob as $file) {
$type = awGraph::cleanGraphCache($file);
if($type === NULL) {
$name = ereg_replace(".*/(.*)\-time", "\\1", $file);
awGraph::deleteFromCache($name);
}
}
}
}
/**
* Enable/Disable Graph timing
*
@ -203,18 +207,18 @@ class awGraph extends awImage {
function setTiming($timing) {
$this->timing = (bool)$timing;
}
/**
* Add a component to the graph
*
* @param &$component
*/
function add(&$component) {
$this->components[] = $component;
}
/**
* Add a label to the component
*
@ -223,13 +227,13 @@ class awGraph extends awImage {
* @param int $y Position on Y axis of the center of the text
*/
function addLabel(&$label, $x, $y) {
$this->labels[] = array(
$label, $x, $y
);
}
/**
* Add a label to the component with aboslute position
*
@ -237,13 +241,13 @@ class awGraph extends awImage {
* @param $point Text position
*/
function addAbsLabel(&$label, $point) {
$this->labels[] = array(
$label, $point
);
}
/**
* Build the graph and draw component on it
* Image is sent to the user browser
@ -251,23 +255,23 @@ class awGraph extends awImage {
* @param string $file Save the image in the specified file. Let it null to print image to screen.
*/
function draw($file = NULL) {
if($this->timing) {
$time = microtimeFloat();
}
$this->create();
foreach($this->components as $component) {
$this->drawComponent($component);
}
$this->drawTitle();
$this->drawShadow();
$this->drawLabels();
if($this->timing) {
$this->drawTiming(microtimeFloat() - $time);
}
@ -275,104 +279,104 @@ class awGraph extends awImage {
if(ARTICHOW_CACHE and $this->name !== NULL) {
ob_start();
}
$this->send($file);
if(ARTICHOW_CACHE and $this->name !== NULL) {
$data = ob_get_contents();
if(is_writable(ARTICHOW_CACHE_DIRECTORY) === FALSE) {
trigger_error("Cache directory is not writable");
}
$file = ARTICHOW_CACHE_DIRECTORY."/".$this->name."";
file_put_contents($file, $data);
$file .= "-time";
file_put_contents($file, $this->timeout."\n".$this->getFormat());
ob_clean();
echo $data;
}
}
function drawLabels() {
$drawer = $this->getDrawer();
foreach($this->labels as $array) {
if(count($array) === 3) {
// Text in relative position
list($label, $x, $y) = $array;
$point = new awPoint(
$x * $this->width,
$y * $this->height
);
} else {
// Text in absolute position
list($label, $point) = $array;
}
$label->draw($drawer, $point);
}
}
function drawTitle() {
$drawer = $this->getDrawer();
$point = new awPoint(
$this->width / 2,
10
);
$this->title->draw($drawer, $point);
}
function drawTiming($time) {
$drawer = $this->getDrawer();
$label = new awLabel;
$label->set("(".sprintf("%.3f", $time)." s)");
$label->setAlign(LABEL_LEFT, LABEL_TOP);
$label->border->show();
$label->setPadding(1, 0, 0, 0);
$label->setBackgroundColor(new awColor(230, 230, 230, 25));
$label->draw($drawer, new awPoint(5, $drawer->height - 5));
}
function cleanGraphCache($file) {
list(
$time,
$type
) = explode("\n", file_get_contents($file));
$time = (int)$time;
if($time !== 0 and $time < time()) {
return NULL;
} else {
return $type;
}
}
}
@ -382,8 +386,8 @@ registerClass('Graph');
/*
* To preserve PHP 4 compatibility
*/
function microtimeFloat() {
list($usec, $sec) = explode(" ", microtime());
return (float)$usec + (float)$sec;
function microtimeFloat() {
list($usec, $sec) = explode(" ", microtime());
return (float)$usec + (float)$sec;
}
?>

View File

@ -22,28 +22,28 @@ class awMathFunction {
* @var Line
*/
var $line;
/**
* Marks for your plot
*
* @var Mark
*/
var $mark;
/**
* Callback function
*
* @var string
*/
var $f;
/**
* Start the drawing from this value
*
* @var float
*/
var $fromX;
/**
* Stop the drawing at this value
*
@ -57,7 +57,7 @@ class awMathFunction {
* @var Color
*/
var $color;
/**
* Construct the function
*
@ -66,17 +66,17 @@ class awMathFunction {
* @param float $toX
*/
function awMathFunction($f, $fromX = NULL, $toX = NULL) {
$this->f = (string)$f;
$this->fromX = is_null($fromX) ? NULL : (float)$fromX;
$this->toX = is_null($toX) ? NULL : (float)$toX;
$this->line = new awLine;
$this->mark = new awMark;
$this->color = new awBlack;
}
/**
* Change line color
*
@ -85,7 +85,7 @@ class awMathFunction {
function setColor($color) {
$this->color = $color;
}
/**
* Get line color
*
@ -142,56 +142,56 @@ class awMathFunction {
}
registerClass('MathFunction');
/**
* For mathematics functions
*
* @package Artichow
*/
class awMathPlot extends awComponent {
/**
* Functions
*
* @var array
*/
var $functions = array();
/**
* Grid properties
*
* @var Grid
*/
var $grid;
/**
* X axis
*
* @var Axis
*/
var $xAxis;
/**
* Y axis
*
* @var Axis
*/
var $yAxis;
/**
* Extremum
*
* @var Side
*/
var $extremum = NULL;
/**
* Interval
*
* @var float
*/
var $interval = 1;
/**
* Build the plot
*
@ -201,44 +201,47 @@ class awMathPlot extends awComponent {
* @param int $yMin Minimum Y value
*/
function awMathPlot($xMin, $xMax, $yMax, $yMin) {
parent::awComponent();
$this->setPadding(8, 8, 8, 8);
$this->grid = new awGrid;
// Hide grid by default
$this->grid->hide(TRUE);
// Set extremum
$this->extremum = new awSide($xMin, $xMax, $yMax, $yMin);
// Create axis
$this->xAxis = new awAxis;
$this->xAxis->setTickStyle(TICK_IN);
$this->xAxis->label->hideValue(0);
$this->initAxis($this->xAxis);
$this->yAxis = new awAxis;
$this->yAxis->setTickStyle(TICK_IN);
$this->yAxis->label->hideValue(0);
$this->initAxis($this->yAxis);
}
function initAxis(&$axis) {
// DOL_CHANGE LDR Fix to allow usage of other fonts
global $artichow_defaultfont;
$classfontname='aw'.str_replace('-','_',$artichow_defaultfont);
$axis->setLabelPrecision(1);
$axis->addTick('major', new awTick(0, 5));
$axis->addTick('minor', new awTick(0, 3));
$axis->addTick('micro', new awTick(0, 1));
$axis->setNumberByTick('minor', 'major', 1);
$axis->setNumberByTick('micro', 'minor', 4);
$axis->label->setFont(new awTuffy(7));
$axis->label->setFont(new $classfontname(7));
}
/**
* Interval to calculate values
*
@ -247,7 +250,7 @@ class awMathPlot extends awComponent {
function setInterval($interval) {
$this->interval = (float)$interval;
}
/**
* Add a formula f(x)
*
@ -256,104 +259,104 @@ class awMathPlot extends awComponent {
* @param int $type Type for the legend
*/
function add(&$function, $name = NULL, $type = LEGEND_LINE) {
$this->functions[] = $function;
if($name !== NULL) {
$this->legend->add($function, $name, $type);
}
}
function init($drawer) {
list($x1, $y1, $x2, $y2) = $this->getPosition();
$this->xAxis->line->setX($x1, $x2);
$this->xAxis->label->setAlign(NULL, LABEL_BOTTOM);
$this->xAxis->label->move(0, 3);
$this->xAxis->setRange($this->extremum->left, $this->extremum->right);
$this->yAxis->line->setY($y2, $y1);
$this->yAxis->label->setAlign(LABEL_RIGHT);
$this->yAxis->label->move(-6, 0);
$this->yAxis->reverseTickStyle();
$this->yAxis->setRange($this->extremum->bottom, $this->extremum->top);
$this->xAxis->setYCenter($this->yAxis, 0);
$this->yAxis->setXCenter($this->xAxis, 0);
if($this->yAxis->getLabelNumber() === NULL) {
$number = $this->extremum->top - $this->extremum->bottom + 1;
$this->yAxis->setLabelNumber($number);
}
if($this->xAxis->getLabelNumber() === NULL) {
$number = $this->extremum->right - $this->extremum->left + 1;
$this->xAxis->setLabelNumber($number);
}
// Set ticks
$this->xAxis->ticks['major']->setNumber($this->xAxis->getLabelNumber());
$this->yAxis->ticks['major']->setNumber($this->yAxis->getLabelNumber());
// Set axis labels
$labels = array();
for($i = 0, $count = $this->xAxis->getLabelNumber(); $i < $count; $i++) {
$labels[] = $i;
}
$this->xAxis->label->set($labels);
$labels = array();
for($i = 0, $count = $this->yAxis->getLabelNumber(); $i < $count; $i++) {
$labels[] = $i;
}
$this->yAxis->label->set($labels);
parent::init($drawer);
// Create the grid
$this->createGrid();
// Draw the grid
$this->grid->draw($drawer, $x1, $y1, $x2, $y2);
}
function drawEnvelope($drawer) {
// Draw axis
$this->xAxis->draw($drawer);
$this->yAxis->draw($drawer);
}
function drawComponent($drawer, $x1, $y1, $x2, $y2, $aliasing) {
foreach($this->functions as $function) {
$f = $function->f;
$fromX = is_null($function->fromX) ? $this->extremum->left : $function->fromX;
$toX = is_null($function->toX) ? $this->extremum->right : $function->toX;
$old = NULL;
for($i = $fromX; $i <= $toX; $i += $this->interval) {
$p = awAxis::toPosition($this->xAxis, $this->yAxis, new awPoint($i, $f($i)));
if($p->y >= $y1 and $p->y <= $y2) {
$function->mark->draw($drawer, $p);
}
if($old !== NULL) {
$line = $function->line;
$line->setLocation($old, $p);
if(
($line->p1->y >= $y1 and $line->p1->y <= $y2) or
($line->p2->y >= $y1 and $line->p2->y <= $y2)
@ -363,26 +366,26 @@ class awMathPlot extends awComponent {
$line
);
}
}
$old = $p;
}
// Draw last point if needed
if($old !== NULL and $i - $this->interval != $toX) {
$p = awAxis::toPosition($this->xAxis, $this->yAxis, new awPoint($toX, $f($toX)));
if($p->y >= $y1 and $p->y <= $y2) {
$function->mark->draw($drawer, $p);
}
$line = $function->line;
$line->setLocation($old, $p);
if(
($line->p1->y >= $y1 and $line->p1->y <= $y2) or
($line->p2->y >= $y1 and $line->p2->y <= $y2)
@ -392,34 +395,34 @@ class awMathPlot extends awComponent {
$line
);
}
}
}
}
function createGrid() {
// Horizontal lines of the grid
$major = $this->yAxis->tick('major');
$interval = $major->getInterval();
$number = $this->yAxis->getLabelNumber() - 1;
$h = array();
if($number > 0) {
for($i = 0; $i <= $number; $i++) {
$h[] = $i / $number;
}
}
// Vertical lines
$major = $this->xAxis->tick('major');
$interval = $major->getInterval();
$number = $this->xAxis->getLabelNumber() - 1;
$w = array();
if($number > 0) {
for($i = 0; $i <= $number; $i++) {
@ -428,9 +431,9 @@ class awMathPlot extends awComponent {
}
}
}
$this->grid->setGrid($w, $h);
}
}

File diff suppressed because it is too large Load Diff

View File

@ -6,7 +6,7 @@
* Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.
*
*/
require_once dirname(__FILE__)."/Graph.class.php";
@ -23,7 +23,7 @@ abstract class awComponentGroup extends awComponent {
* @var array
*/
protected $components;
/**
* Build the component group
*/
@ -81,7 +81,7 @@ abstract class awComponent {
* @var float
*/
public $y = 0.5;
/**
* Component absolute width (in pixels)
*
@ -89,7 +89,7 @@ abstract class awComponent {
* @var int
*/
public $w;
/**
* Component absolute height (in pixels)
*
@ -111,71 +111,75 @@ abstract class awComponent {
* @var float
*/
public $left;
/**
* Component background color
*
* @var Color
*/
protected $background;
/**
* Component padding
*
* @var Side
*/
protected $padding;
/**
* Component space
*
* @var Side
*/
protected $space;
/**
* Component title
*
* @var Label
*/
public $title;
/**
* Adjust automatically the component ?
*
* @var bool
*/
protected $auto = TRUE;
/**
* Legend
*
* @var Legend
*/
public $legend;
/**
* Build the component
*/
public function __construct() {
// DOL_CHANGE LDR Fix to allow usage of other fonts
global $artichow_defaultfont;
$classfontname='aw'.str_replace('-','_',$artichow_defaultfont);
// Component legend
$this->legend = new awLegend();
$this->padding = new awSide(25, 25, 25, 25);
$this->space = new awSide(0, 0, 0, 0);
// Component title
$this->title = new awLabel(
NULL,
new awTuffy(10),
new $classfontname(10),
NULL,
0
);
$this->title->setAlign(awLabel::CENTER, awLabel::TOP);
}
/**
* Adjust automatically the component ?
*
@ -184,7 +188,7 @@ abstract class awComponent {
public function auto($auto) {
$this->auto = (bool)$auto;
}
/**
* Change the size of the component
*
@ -192,12 +196,12 @@ abstract class awComponent {
* @param int $height Component height (from 0 to 1)
*/
public function setSize($width, $height) {
$this->width = (float)$width;
$this->height = (float)$height;
}
/**
* Change the absolute size of the component
*
@ -205,12 +209,12 @@ abstract class awComponent {
* @param int $h Component height (in pixels)
*/
public function setAbsSize($w, $h) {
$this->w = (int)$w;
$this->h = (int)$h;
}
/**
* Change component background color
*
@ -221,7 +225,7 @@ abstract class awComponent {
$this->background = $color;
}
}
/**
* Change component background gradient
*
@ -232,7 +236,7 @@ abstract class awComponent {
$this->background = $gradient;
}
}
/**
* Change component background image
*
@ -243,7 +247,7 @@ abstract class awComponent {
$this->background = $image;
}
}
/**
* Return the component background
*
@ -252,7 +256,7 @@ abstract class awComponent {
public function getBackground() {
return $this->background;
}
/**
* Change component padding
*
@ -264,7 +268,7 @@ abstract class awComponent {
public function setPadding($left = NULL, $right = NULL, $top = NULL, $bottom = NULL) {
$this->padding->set($left, $right, $top, $bottom);
}
/**
* Change component space
*
@ -276,7 +280,7 @@ abstract class awComponent {
public function setSpace($left = NULL, $right = NULL, $bottom = NULL, $top = NULL) {
$this->space->set($left, $right, $bottom, $top);
}
/**
* Change the absolute position of the component on the graph
*
@ -284,12 +288,12 @@ abstract class awComponent {
* @var int $y Left-top corner Y position
*/
public function setAbsPosition($left, $top) {
$this->left = (int)$left;
$this->top = (int)$top;
}
/**
* Set the center of the component
*
@ -297,29 +301,29 @@ abstract class awComponent {
* @param int $y Position on Y axis of the center of the component
*/
public function setCenter($x, $y) {
$this->x = (float)$x;
$this->y = (float)$y;
}
/**
* Get component coords with its padding
*
* @return array Coords of the component
*/
public function getPosition() {
// Get component coords
$x1 = $this->padding->left;
$y1 = $this->padding->top;
$x2 = $this->w - $this->padding->right;
$y2 = $this->h - $this->padding->bottom;
return array($x1, $y1, $x2, $y2);
}
/**
* Init the drawing of the component
*/
@ -327,49 +331,49 @@ abstract class awComponent {
// Set component background
$background = $this->getBackground();
if($background !== NULL) {
$p1 = new awPoint(0, 0);
$p2 = new awPoint($this->w - 1, $this->h - 1);
if($background instanceof awImage) {
$drawer->copyImage(
$background,
$p1,
$p2
);
} else {
$drawer->filledRectangle(
$background,
new awLine($p1, $p2)
);
}
}
}
/**
* Finalize the drawing of the component
*/
public function finalize(awDrawer $drawer) {
// Draw component title
$point = new awPoint(
$this->w / 2,
$this->padding->top - 8
);
$this->title->draw($drawer, $point);
// Draw legend
$this->legend->draw($drawer);
}
/**
* Draw the grid around your component
*
@ -377,7 +381,7 @@ abstract class awComponent {
* @return array Coords for the component
*/
abstract public function drawEnvelope(awDrawer $drawer);
/**
* Draw the component on the graph
* Component should be drawed into specified coords
@ -390,7 +394,7 @@ abstract class awComponent {
* @param bool $aliasing Use anti-aliasing to draw the component ?
*/
abstract public function drawComponent(awDrawer $drawer, $x1, $y1, $x2, $y2, $aliasing);
/**
* Get space width in pixels
*
@ -399,16 +403,16 @@ abstract class awComponent {
* @return array
*/
protected function getSpace($width, $height) {
$left = (int)($width * $this->space->left / 100);
$right = (int)($width * $this->space->right / 100);
$top = (int)($height * $this->space->top / 100);
$bottom = (int)($height * $this->space->bottom / 100);
return array($left, $right, $top, $bottom);
}
}
registerClass('Component', TRUE);

View File

@ -34,7 +34,7 @@ require_once ARTICHOW."/inc/Font.class.php";
require_once ARTICHOW."/inc/Gradient.class.php";
/**
* A graph
* A graph
*
* @package Artichow
*/
@ -53,35 +53,35 @@ class awGraph extends awImage {
* @var int
*/
protected $timeout = 0;
/**
* Graph timing ?
*
* @var bool
*/
protected $timing;
/**
* Components
*
* @var array
*/
private $components = array();
/**
* Some labels to add to the component
*
* @var array
*/
protected $labels = array();
/**
* Graph title
*
* @var Label
*/
public $title;
/**
* Construct a new graph
*
@ -91,29 +91,33 @@ class awGraph extends awImage {
* @param int $timeout Cache timeout (unix timestamp)
*/
public function __construct($width = NULL, $height = NULL, $name = NULL, $timeout = 0) {
// DOL_CHANGE LDR Fix to allow usage of other fonts
global $artichow_defaultfont;
$classfontname='aw'.str_replace('-','_',$artichow_defaultfont);
parent::__construct();
$this->setSize($width, $height);
if(ARTICHOW_CACHE) {
$this->name = $name;
$this->timeout = $timeout;
// Clean sometimes all the cache
if(mt_rand(0, 5000) === 0) {
awGraph::cleanCache();
}
if($this->name !== NULL) {
$file = ARTICHOW_CACHE_DIRECTORY."/".$this->name."-time";
if(is_file($file)) {
$type = awGraph::cleanGraphCache($file);
if($type === NULL) {
awGraph::deleteFromCache($this->name);
} else {
@ -121,23 +125,23 @@ class awGraph extends awImage {
readfile(ARTICHOW_CACHE_DIRECTORY."/".$this->name."");
exit;
}
}
}
}
$this->title = new awLabel(
NULL,
new awTuffy(16),
new $classfontname(16),
NULL,
0
);
$this->title->setAlign(awLabel::CENTER, awLabel::BOTTOM);
}
/**
* Delete a graph from the cache
*
@ -147,59 +151,59 @@ class awGraph extends awImage {
public static function deleteFromCache($name) {
if(ARTICHOW_CACHE) {
if(is_file(ARTICHOW_CACHE_DIRECTORY."/".$name."-time")) {
unlink(ARTICHOW_CACHE_DIRECTORY."/".$name."");
unlink(ARTICHOW_CACHE_DIRECTORY."/".$name."-time");
}
}
}
/**
* Delete all graphs from the cache
*/
public static function deleteAllCache() {
if(ARTICHOW_CACHE) {
$dp = opendir(ARTICHOW_CACHE_DIRECTORY);
while($file = readdir($dp)) {
if($file !== '.' and $file != '..') {
unlink(ARTICHOW_CACHE_DIRECTORY."/".$file);
}
}
}
}
/**
* Clean cache
*/
public static function cleanCache() {
if(ARTICHOW_CACHE) {
$glob = glob(ARTICHOW_CACHE_DIRECTORY."/*-time");
foreach($glob as $file) {
$type = awGraph::cleanGraphCache($file);
if($type === NULL) {
$name = preg_replace("/.*\/(.*)\-time/", "\\1", $file);
awGraph::deleteFromCache($name);
}
}
}
}
/**
* Enable/Disable Graph timing
*
@ -208,18 +212,18 @@ class awGraph extends awImage {
public function setTiming($timing) {
$this->timing = (bool)$timing;
}
/**
* Add a component to the graph
*
* @param awComponent $component
*/
public function add(awComponent $component) {
$this->components[] = $component;
}
/**
* Add a label to the component
*
@ -228,13 +232,13 @@ class awGraph extends awImage {
* @param int $y Position on Y axis of the center of the text
*/
public function addLabel(awLabel $label, $x, $y) {
$this->labels[] = array(
$label, $x, $y
);
}
/**
* Add a label to the component with aboslute position
*
@ -242,13 +246,13 @@ class awGraph extends awImage {
* @param awPoint $point Text position
*/
public function addAbsLabel(awLabel $label, awPoint $point) {
$this->labels[] = array(
$label, $point
);
}
/**
* Build the graph and draw component on it
* Image is sent to the user browser
@ -256,23 +260,23 @@ class awGraph extends awImage {
* @param string $file Save the image in the specified file. Let it null to print image to screen.
*/
public function draw($file = NULL) {
if($this->timing) {
$time = microtimeFloat();
}
$this->create();
foreach($this->components as $component) {
$this->drawComponent($component);
}
$this->drawTitle();
$this->drawShadow();
$this->drawLabels();
if($this->timing) {
$this->drawTiming(microtimeFloat() - $time);
}
@ -280,104 +284,104 @@ class awGraph extends awImage {
if(ARTICHOW_CACHE and $this->name !== NULL) {
ob_start();
}
$this->send($file);
if(ARTICHOW_CACHE and $this->name !== NULL) {
$data = ob_get_contents();
if(is_writable(ARTICHOW_CACHE_DIRECTORY) === FALSE) {
trigger_error("Cache directory is not writable");
}
$file = ARTICHOW_CACHE_DIRECTORY."/".$this->name."";
file_put_contents($file, $data);
$file .= "-time";
file_put_contents($file, $this->timeout."\n".$this->getFormat());
ob_clean();
echo $data;
}
}
private function drawLabels() {
$drawer = $this->getDrawer();
foreach($this->labels as $array) {
if(count($array) === 3) {
// Text in relative position
list($label, $x, $y) = $array;
$point = new awPoint(
$x * $this->width,
$y * $this->height
);
} else {
// Text in absolute position
list($label, $point) = $array;
}
$label->draw($drawer, $point);
}
}
private function drawTitle() {
$drawer = $this->getDrawer();
$point = new awPoint(
$this->width / 2,
10
);
$this->title->draw($drawer, $point);
}
private function drawTiming($time) {
$drawer = $this->getDrawer();
$label = new awLabel;
$label->set("(".sprintf("%.3f", $time)." s)");
$label->setAlign(awLabel::LEFT, awLabel::TOP);
$label->border->show();
$label->setPadding(1, 0, 0, 0);
$label->setBackgroundColor(new awColor(230, 230, 230, 25));
$label->draw($drawer, new awPoint(5, $drawer->height - 5));
}
private static function cleanGraphCache($file) {
list(
$time,
$type
) = explode("\n", file_get_contents($file));
$time = (int)$time;
if($time !== 0 and $time < time()) {
return NULL;
} else {
return $type;
}
}
}
@ -387,8 +391,8 @@ registerClass('Graph');
/*
* To preserve PHP 4 compatibility
*/
function microtimeFloat() {
list($usec, $sec) = explode(" ", microtime());
return (float)$usec + (float)$sec;
function microtimeFloat() {
list($usec, $sec) = explode(" ", microtime());
return (float)$usec + (float)$sec;
}
?>

View File

@ -22,28 +22,28 @@ class awMathFunction implements awLegendable {
* @var Line
*/
public $line;
/**
* Marks for your plot
*
* @var Mark
*/
public $mark;
/**
* Callback function
*
* @var string
*/
public $f;
/**
* Start the drawing from this value
*
* @var float
*/
public $fromX;
/**
* Stop the drawing at this value
*
@ -57,7 +57,7 @@ class awMathFunction implements awLegendable {
* @var Color
*/
protected $color;
/**
* Construct the function
*
@ -66,17 +66,17 @@ class awMathFunction implements awLegendable {
* @param float $toX
*/
public function __construct($f, $fromX = NULL, $toX = NULL) {
$this->f = (string)$f;
$this->fromX = is_null($fromX) ? NULL : (float)$fromX;
$this->toX = is_null($toX) ? NULL : (float)$toX;
$this->line = new awLine;
$this->mark = new awMark;
$this->color = new awBlack;
}
/**
* Change line color
*
@ -85,7 +85,7 @@ class awMathFunction implements awLegendable {
public function setColor(awColor $color) {
$this->color = $color;
}
/**
* Get line color
*
@ -142,56 +142,56 @@ class awMathFunction implements awLegendable {
}
registerClass('MathFunction');
/**
* For mathematics functions
*
* @package Artichow
*/
class awMathPlot extends awComponent {
/**
* Functions
*
* @var array
*/
protected $functions = array();
/**
* Grid properties
*
* @var Grid
*/
public $grid;
/**
* X axis
*
* @var Axis
*/
public $xAxis;
/**
* Y axis
*
* @var Axis
*/
public $yAxis;
/**
* Extremum
*
* @var Side
*/
private $extremum = NULL;
/**
* Interval
*
* @var float
*/
private $interval = 1;
/**
* Build the plot
*
@ -201,44 +201,47 @@ class awMathPlot extends awComponent {
* @param int $yMin Minimum Y value
*/
public function __construct($xMin, $xMax, $yMax, $yMin) {
parent::__construct();
$this->setPadding(8, 8, 8, 8);
$this->grid = new awGrid;
// Hide grid by default
$this->grid->hide(TRUE);
// Set extremum
$this->extremum = new awSide($xMin, $xMax, $yMax, $yMin);
// Create axis
$this->xAxis = new awAxis;
$this->xAxis->setTickStyle(awTick::IN);
$this->xAxis->label->hideValue(0);
$this->initAxis($this->xAxis);
$this->yAxis = new awAxis;
$this->yAxis->setTickStyle(awTick::IN);
$this->yAxis->label->hideValue(0);
$this->initAxis($this->yAxis);
}
protected function initAxis(awAxis $axis) {
// DOL_CHANGE LDR Fix to allow usage of other fonts
global $artichow_defaultfont;
$classfontname='aw'.str_replace('-','_',$artichow_defaultfont);
$axis->setLabelPrecision(1);
$axis->addTick('major', new awTick(0, 5));
$axis->addTick('minor', new awTick(0, 3));
$axis->addTick('micro', new awTick(0, 1));
$axis->setNumberByTick('minor', 'major', 1);
$axis->setNumberByTick('micro', 'minor', 4);
$axis->label->setFont(new awTuffy(7));
$axis->label->setFont(new $classfontname(7));
}
/**
* Interval to calculate values
*
@ -247,7 +250,7 @@ class awMathPlot extends awComponent {
public function setInterval($interval) {
$this->interval = (float)$interval;
}
/**
* Add a formula f(x)
*
@ -256,44 +259,44 @@ class awMathPlot extends awComponent {
* @param int $type Type for the legend
*/
public function add(awMathFunction $function, $name = NULL, $type = awLegend::LINE) {
$this->functions[] = $function;
if($name !== NULL) {
$this->legend->add($function, $name, $type);
}
}
public function init(awDrawer $drawer) {
list($x1, $y1, $x2, $y2) = $this->getPosition();
$this->xAxis->line->setX($x1, $x2);
$this->xAxis->label->setAlign(NULL, awLabel::BOTTOM);
$this->xAxis->label->move(0, 3);
$this->xAxis->setRange($this->extremum->left, $this->extremum->right);
$this->yAxis->line->setY($y2, $y1);
$this->yAxis->label->setAlign(awLabel::RIGHT);
$this->yAxis->label->move(-6, 0);
$this->yAxis->reverseTickStyle();
$this->yAxis->setRange($this->extremum->bottom, $this->extremum->top);
$this->xAxis->setYCenter($this->yAxis, 0);
$this->yAxis->setXCenter($this->xAxis, 0);
if($this->yAxis->getLabelNumber() === NULL) {
$number = $this->extremum->top - $this->extremum->bottom + 1;
$this->yAxis->setLabelNumber($number);
}
if($this->xAxis->getLabelNumber() === NULL) {
$number = $this->extremum->right - $this->extremum->left + 1;
$this->xAxis->setLabelNumber($number);
}
// Set ticks
/* <php5> */
$this->xAxis->tick('major')->setNumber($this->xAxis->getLabelNumber());
@ -303,61 +306,61 @@ class awMathPlot extends awComponent {
$this->xAxis->ticks['major']->setNumber($this->xAxis->getLabelNumber());
$this->yAxis->ticks['major']->setNumber($this->yAxis->getLabelNumber());
-- </php4> */
// Set axis labels
$labels = array();
for($i = 0, $count = $this->xAxis->getLabelNumber(); $i < $count; $i++) {
$labels[] = $i;
}
$this->xAxis->label->set($labels);
$labels = array();
for($i = 0, $count = $this->yAxis->getLabelNumber(); $i < $count; $i++) {
$labels[] = $i;
}
$this->yAxis->label->set($labels);
parent::init($drawer);
// Create the grid
$this->createGrid();
// Draw the grid
$this->grid->draw($drawer, $x1, $y1, $x2, $y2);
}
public function drawEnvelope(awDrawer $drawer) {
// Draw axis
$this->xAxis->draw($drawer);
$this->yAxis->draw($drawer);
}
public function drawComponent(awDrawer $drawer, $x1, $y1, $x2, $y2, $aliasing) {
foreach($this->functions as $function) {
$f = $function->f;
$fromX = is_null($function->fromX) ? $this->extremum->left : $function->fromX;
$toX = is_null($function->toX) ? $this->extremum->right : $function->toX;
$old = NULL;
for($i = $fromX; $i <= $toX; $i += $this->interval) {
$p = awAxis::toPosition($this->xAxis, $this->yAxis, new awPoint($i, $f($i)));
if($p->y >= $y1 and $p->y <= $y2) {
$function->mark->draw($drawer, $p);
}
if($old !== NULL) {
$line = $function->line;
$line->setLocation($old, $p);
if(
($line->p1->y >= $y1 and $line->p1->y <= $y2) or
($line->p2->y >= $y1 and $line->p2->y <= $y2)
@ -367,26 +370,26 @@ class awMathPlot extends awComponent {
$line
);
}
}
$old = $p;
}
// Draw last point if needed
if($old !== NULL and $i - $this->interval != $toX) {
$p = awAxis::toPosition($this->xAxis, $this->yAxis, new awPoint($toX, $f($toX)));
if($p->y >= $y1 and $p->y <= $y2) {
$function->mark->draw($drawer, $p);
}
$line = $function->line;
$line->setLocation($old, $p);
if(
($line->p1->y >= $y1 and $line->p1->y <= $y2) or
($line->p2->y >= $y1 and $line->p2->y <= $y2)
@ -396,34 +399,34 @@ class awMathPlot extends awComponent {
$line
);
}
}
}
}
protected function createGrid() {
// Horizontal lines of the grid
$major = $this->yAxis->tick('major');
$interval = $major->getInterval();
$number = $this->yAxis->getLabelNumber() - 1;
$h = array();
if($number > 0) {
for($i = 0; $i <= $number; $i++) {
$h[] = $i / $number;
}
}
// Vertical lines
$major = $this->xAxis->tick('major');
$interval = $major->getInterval();
$number = $this->xAxis->getLabelNumber() - 1;
$w = array();
if($number > 0) {
for($i = 0; $i <= $number; $i++) {
@ -432,9 +435,9 @@ class awMathPlot extends awComponent {
}
}
}
$this->grid->setGrid($w, $h);
}
}

File diff suppressed because it is too large Load Diff

View File

@ -7,32 +7,32 @@
*
*/
/**
* Built-in PHP fonts
*
* @package Artichow
*/
class awFont {
/**
* Used font
*
*
* @param int $font
*/
public $font;
/**
* Build the font
*
* @param int $font Font identifier
*/
public function __construct($font) {
$this->font = $font;
}
/**
* Draw a text
*
@ -41,28 +41,28 @@ class awFont {
* @param awText $text The text
*/
public function draw(awDrawer $drawer, awPoint $p, awText $text) {
$angle = $text->getAngle();
if($angle !== 90 and $angle !== 0) {
trigger_error("You can only use 0° and 90°", E_USER_ERROR);
}
if($angle === 90) {
$function = 'imagestringup';
} else {
$function = 'imagestring';
}
if($angle === 90) {
$add = $this->getTextHeight($text);
} else {
$add = 0;
}
$color = $text->getColor();
$rgb = $color->getColor($drawer->resource);
$function(
$drawer->resource,
$this->font,
@ -71,55 +71,55 @@ class awFont {
$text->getText(),
$rgb
);
}
/**
* Get the width of a string
*
* @param awText $text A string
*/
public function getTextWidth(awText $text) {
if($text->getAngle() === 90) {
$text->setAngle(45);
return $this->getTextHeight($text);
} else if($text->getAngle() === 45) {
$text->setAngle(90);
}
$font = $text->getFont();
$fontWidth = imagefontwidth($font->font);
if($fontWidth === FALSE) {
trigger_error("Unable to get font size", E_USER_ERROR);
}
return (int)$fontWidth * strlen($text->getText());
}
/**
* Get the height of a string
*
* @param awText $text A string
*/
public function getTextHeight(awText $text) {
if($text->getAngle() === 90) {
$text->setAngle(45);
return $this->getTextWidth($text);
} else if($text->getAngle() === 45) {
$text->setAngle(90);
}
$font = $text->getFont();
$fontHeight = imagefontheight($font->font);
if($fontHeight === FALSE) {
trigger_error("Unable to get font size", E_USER_ERROR);
}
return (int)$fontHeight;
}
@ -149,13 +149,13 @@ class awTTFFont extends awFont {
* @param int $size Font size
*/
public function __construct($font, $size) {
parent::__construct($font);
$this->size = (int)$size;
}
/**
* Draw a text
*
@ -164,23 +164,23 @@ class awTTFFont extends awFont {
* @param awText $text The text
*/
public function draw(awDrawer $drawer, awPoint $p, awText $text) {
// Make easier font positionment
$text->setText($text->getText()." ");
$color = $text->getColor();
$rgb = $color->getColor($drawer->resource);
$box = imagettfbbox($this->size, $text->getAngle(), $this->font, $text->getText());
$height = - $box[5];
$box = imagettfbbox($this->size, 90, $this->font, $text->getText());
$width = abs($box[6] - $box[2]);
// Restore old text
$text->setText(substr($text->getText(), 0, strlen($text->getText()) - 1));
imagettftext(
$drawer->resource,
$this->size,
@ -191,45 +191,45 @@ class awTTFFont extends awFont {
$this->font,
$text->getText()
);
}
/**
* Get the width of a string
*
* @param awText $text A string
*/
public function getTextWidth(awText $text) {
$box = imagettfbbox($this->size, $text->getAngle(), $this->font, $text->getText());
if($box === FALSE) {
trigger_error("Unable to get font size", E_USER_ERROR);
return;
}
list(, , $x2, $y2, , , $x1, $y1) = $box;
return abs($x2 - $x1);
}
/**
* Get the height of a string
*
* @param awText $text A string
*/
public function getTextHeight(awText $text) {
$box = imagettfbbox($this->size, $text->getAngle(), $this->font, $text->getText());
if($box === FALSE) {
trigger_error("Unable to get font size", E_USER_ERROR);
return;
}
list(, , $x2, $y2, , , $x1, $y1) = $box;
return abs($y2 - $y1);
}
@ -246,14 +246,14 @@ for($i = 1; $i <= 5; $i++) {
$php .= '
class awFont'.$i.' extends awFont {
public function __construct() {
parent::__construct('.$i.');
}
}
';
if(ARTICHOW_PREFIX !== 'aw') {
$php .= '
class '.ARTICHOW_PREFIX.'Font'.$i.' extends awFont'.$i.' {
@ -269,19 +269,20 @@ $php = '';
foreach($fonts as $font) {
// DOL_CHANGE LDR Fix to allow - into font names
$php .= '
class aw'.$font.' extends awTTFFont {
class aw'.str_replace('-','_',$font).' extends awTTFFont {
public function __construct($size) {
parent::__construct(\''.(ARTICHOW_FONT.DIRECTORY_SEPARATOR.$font.'.ttf').'\', $size);
}
}
';
if(ARTICHOW_PREFIX !== 'aw') {
$php .= '
class '.ARTICHOW_PREFIX.$font.' extends aw'.$font.' {
class '.ARTICHOW_PREFIX.str_replace('-','_',$font).' extends aw'.str_replace('-','_',$font).' {
}
';
}
@ -299,14 +300,14 @@ for($i = 1; $i <= 5; $i++) {
$php .= '
class awFont'.$i.' extends awFont {
function awFont'.$i.'() {
parent::awFont('.$i.');
}
}
';
if(ARTICHOW_PREFIX !== 'aw') {
$php .= '
class '.ARTICHOW_PREFIX.'Font'.$i.' extends awFont'.$i.' {
@ -324,14 +325,14 @@ foreach($fonts as $font) {
$php .= '
class aw'.$font.' extends awTTFFont {
function aw'.$font.'($size) {
parent::awTTFFont(\''.(ARTICHOW_FONT.DIRECTORY_SEPARATOR.$font.'.ttf').'\', $size);
}
}
';
if(ARTICHOW_PREFIX !== 'aw') {
$php .= '
class '.ARTICHOW_PREFIX.$font.' extends aw'.$font.' {

View File

@ -29,7 +29,7 @@
* \ingroup core
* \brief File that defines environment for all Dolibarr process (pages or scripts)
* This script reads the conf file, init $lang, $db and and empty $user
* \version $Id: master.inc.php,v 1.355 2011/08/14 17:17:20 eldy Exp $
* \version $Id: master.inc.php,v 1.356 2011/08/14 18:26:15 eldy Exp $
*/
@ -301,7 +301,9 @@ if (! defined('NUSOAP_PATH')) { define('NUSOAP_PATH', DOL_DOCUME
if (! defined('PHPEXCEL_PATH')) { define('PHPEXCEL_PATH', DOL_DOCUMENT_ROOT .'/includes/phpexcel/'); }
if (! defined('ODTPHP_PATH')) { define('ODTPHP_PATH', empty($dolibarr_lib_ODTPHP_PATH)?DOL_DOCUMENT_ROOT.'/includes/odtphp/':$dolibarr_lib_ODTPHP_PATH.'/'); }
if (! defined('ODTPHP_PATHTOPCLZIP')) { define('ODTPHP_PATHTOPCLZIP', empty($dolibarr_lib_ODTPHP_PATHTOPCLZIP)?DOL_DOCUMENT_ROOT.'/includes/odtphp/zip/pclzip/':$dolibarr_lib_ODTPHP_PATHTOPCLZIP.'/'); }
if (! defined('ARTICHOW_FONT')) { define('ARTICHOW_FONT', empty($dolibarr_font_DOL_DEFAULT_TTF_BOLD)?DOL_DOCUMENT_ROOT.'/includes/artichow/font':dirname($dolibarr_font_DOL_DEFAULT_TTF_BOLD)); }
// Other required path
if (! defined('ARTICHOW_FONT_NAMES')) { define('ARTICHOW_FONT_NAMES', empty($dolibarr_font_DOL_DEFAULT_TTF_BOLD)?'Tuffy,TuffyBold,TuffyBoldItalic,TuffyItalic':'DejaVuSans,DejaVuSans-Bold,DejaVuSans-BoldOblique,DejaVuSans-Oblique'); }
if (! defined('DOL_DEFAULT_TTF')) { define('DOL_DEFAULT_TTF', empty($dolibarr_font_DOL_DEFAULT_TTF)?DOL_DOCUMENT_ROOT.'/includes/barcode/php-barcode/fonts/Aerial.ttf':$dolibarr_font_DOL_DEFAULT_TTF); }
if (! defined('DOL_DEFAULT_TTF_BOLD')) { define('DOL_DEFAULT_TTF_BOLD', empty($dolibarr_font_DOL_DEFAULT_TTF_BOLD)?DOL_DOCUMENT_ROOT.'/includes/barcode/php-barcode/fonts/AerialBd.ttf':$dolibarr_font_DOL_DEFAULT_TTF_BOLD); }
if (! defined('MAGPIE_DIR')) { define('MAGPIE_DIR', MAGPIERSS_PATH); }