"); //remove all unsupported tags
//replace carriage returns, newlines and tabs
$repTable = array("\t" => " ", "\n" => "
", "\r" => " ", "\0" => " ", "\x0B" => " ");
$html = strtr($html, $repTable);
$pattern = '/(<[^>]+>)/Uu';
$a = preg_split($pattern, $html, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY); //explodes the string
if (empty($this->lasth)) {
//set row height
$this->lasth = $this->FontSize * K_CELL_HEIGHT_RATIO;
}
foreach($a as $key=>$element) {
$element = str_replace('–','-',$element); //remplace les – par un tiret
$element = str_replace('’','\'',$element); //remplace les ’ par un apostrophe
$element = str_replace('"','"',$element); //remplace les " par une guillemet
$element = str_replace('€',chr(128),$element); //remplace les € par le signe euro
$element = str_replace('œ',chr(156),$element); //remplace les œ par le signe e dans l'o
if (!preg_match($pattern, $element)) {
//Text
if($this->HREF) {
$this->addHtmlLink($this->HREF, $element, $fill);
}
elseif($this->tdbegin) {
if((strlen(trim($element)) > 0) AND ($element != " ")) {
// Cette version ne g�re pas UTF8
//$this->Cell($this->tdwidth, $this->tdheight, $this->unhtmlentities($element), $this->tableborder, '', $this->tdalign, $this->tdbgcolor);
$this->Cell($this->tdwidth, $this->tdheight, utf8_decode($this->unhtmlentities($element)), $this->tableborder, '', $this->tdalign, $this->tdbgcolor);
}
elseif($element == " ") {
$this->Cell($this->tdwidth, $this->tdheight, '', $this->tableborder, '', $this->tdalign, $this->tdbgcolor);
}
}
else {
// cette version ne g�re pas UTF8
//$this->Write($this->lasth, stripslashes($this->unhtmlentities($element)), '', $fill);
$this->Write($this->lasth, stripslashes(utf8_decode($this->unhtmlentities($element))), '', $fill);
}
}
else {
$element = substr($element, 1, -1);
//Tag
if($element{0}=='/') {
$this->closedHTMLTagHandler(strtolower(substr($element, 1)));
}
else {
//Extract attributes
// get tag name
preg_match('/([a-zA-Z0-9]*)/', $element, $tag);
$tag = strtolower($tag[0]);
// get attributes
preg_match_all('/([^=\s]*)=["\']?([^"\']*)["\']?/', $element, $attr_array, PREG_PATTERN_ORDER);
$attr = array(); // reset attribute array
while(list($id,$name)=each($attr_array[1])) {
$attr[strtolower($name)] = $attr_array[2][$id];
}
$this->openHTMLTagHandler($tag, $attr, $fill);
}
}
}
if ($ln) {
$this->Ln($this->lasth);
}
}
/**
* Prints a cell (rectangular area) with optional borders, background color and html text string. The upper-left corner of the cell corresponds to the current position. After the call, the current position moves to the right or to the next line.
* If automatic page breaking is enabled and the cell goes beyond the limit, a page break is done before outputting.
* @param float $w Cell width. If 0, the cell extends up to the right margin.
* @param float $h Cell minimum height. The cell extends automatically if needed.
* @param float $x upper-left corner X coordinate
* @param float $y upper-left corner Y coordinate
* @param string $html html text to print. Default value: empty string.
* @param mixed $border Indicates if borders must be drawn around the cell. The value can be either a number:
or a string containing some or all of the following characters (in any order):
* @param int $ln Indicates where the current position should go after the call. Possible values are:
Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: 0.
* @param int $fill Indicates if the cell background must be painted (1) or transparent (0). Default value: 0.
* @see Cell()
*/
function writeHTMLCell($w, $h, $x, $y, $html='', $border=0, $ln=0, $fill=0) {
if (empty($this->lasth)) {
//set row height
$this->lasth = $this->FontSize * K_CELL_HEIGHT_RATIO;
}
if (empty($x)) {
$x = $this->GetX();
}
if (empty($y)) {
$y = $this->GetY();
}
// get current page number
$pagenum = $this->page;
$this->SetX($x);
$this->SetY($y);
if(empty($w)) {
$w = $this->w - $x - $this->rMargin;
}
// store original margin values
$lMargin = $this->lMargin;
$rMargin = $this->rMargin;
// set new margin values
$this->SetLeftMargin($x);
$this->SetRightMargin($this->w - $x - $w);
// calculate remaining vertical space on page
$restspace = $this->getPageHeight() - $this->GetY() - $this->getBreakMargin();
$this->writeHTML($html, true, $fill); // write html text
$currentY = $this->GetY();
// check if a new page has been created
if ($this->page > $pagenum) {
// design a cell around the text on first page
$currentpage = $this->page;
$this->page = $pagenum;
$this->SetY($this->getPageHeight() - $restspace - $this->getBreakMargin());
$h = $restspace - 1;
$this->Cell($w, $h, "", $border, $ln, 'L', 0);
// design a cell around the text on last page
$this->page = $currentpage;
$h = $currentY - $this->tMargin;
$this->SetY($this->tMargin); // put cursor at the beginning of text
$this->Cell($w, $h, "", $border, $ln, 'L', 0);
} else {
$h = max($h, ($currentY - $y));
$this->SetY($y); // put cursor at the beginning of text
// design a cell around the text
$this->Cell($w, $h, "", $border, $ln, 'L', 0);
}
// restore original margin values
$this->SetLeftMargin($lMargin);
$this->SetRightMargin($rMargin);
if ($ln) {
$this->Ln(0);
}
}
/**
* Process opening tags.
* @param string $tag tag name (in uppercase)
* @param string $attr tag attribute (in uppercase)
* @param int $fill Indicates if the cell background must be painted (1) or transparent (0). Default value: 0.
* @access private
*/
function openHTMLTagHandler($tag, $attr, $fill=0) {
//Opening tag
switch($tag) {
case 'table': {
if ((isset($attr['border'])) AND ($attr['border'] != '')) {
$this->tableborder = $attr['border'];
}
else {
$this->tableborder = 0;
}
break;
}
case 'tr': {
break;
}
case 'td':
case 'th': {
if ((isset($attr['width'])) AND ($attr['width'] != '')) {
$this->tdwidth = ($attr['width']/4);
}
else {
$this->tdwidth = (($this->w - $this->lMargin - $this->rMargin) / $this->default_table_columns);
}
if ((isset($attr['height'])) AND ($attr['height'] != '')) {
$this->tdheight=($attr['height'] / $this->k);
}
else {
$this->tdheight = $this->lasth;
}
if ((isset($attr['align'])) AND ($attr['align'] != '')) {
switch ($attr['align']) {
case 'center': {
$this->tdalign = "C";
break;
}
case 'right': {
$this->tdalign = "R";
break;
}
default:
case 'left': {
$this->tdalign = "L";
break;
}
}
}
if ((isset($attr['bgcolor'])) AND ($attr['bgcolor'] != '')) {
$coul = $this->convertColorHexToDec($attr['bgcolor']);
$this->SetFillColor($coul['R'], $coul['G'], $coul['B']);
$this->tdbgcolor=true;
}
$this->tdbegin=true;
break;
}
case 'hr': {
$this->Ln();
if ((isset($attr['width'])) AND ($attr['width'] != '')) {
$hrWidth = $attr['width'];
}
else {
$hrWidth = $this->w - $this->lMargin - $this->rMargin;
}
$x = $this->GetX();
$y = $this->GetY();
$this->SetLineWidth(0.2);
$this->Line($x, $y, $x + $hrWidth, $y);
$this->SetLineWidth(0.2);
$this->Ln();
break;
}
case 'strong': {
$this->setStyle('b', true);
break;
}
case 'em': {
$this->setStyle('i', true);
break;
}
case 'b':
case 'i':
case 'u': {
$this->setStyle($tag, true);
break;
}
case 'a': {
$this->HREF = $attr['href'];
break;
}
case 'img': {
if(isset($attr['src'])) {
// replace relative path with real server path
$attr['src'] = str_replace(K_PATH_URL_CACHE, K_PATH_CACHE, $attr['src']);
if(!isset($attr['width'])) {
$attr['width'] = 0;
}
if(!isset($attr['height'])) {
$attr['height'] = 0;
}
$this->Image($attr['src'], $this->GetX(),$this->GetY(), $this->pixelsToMillimeters($attr['width']), $this->pixelsToMillimeters($attr['height']));
//$this->SetX($this->img_rb_x);
$this->SetY($this->img_rb_y);
}
break;
}
case 'ul': {
$this->listordered = false;
$this->listcount = 0;
break;
}
case 'ol': {
$this->listordered = true;
$this->listcount = 0;
break;
}
case 'li': {
$this->Ln();
if ($this->listordered) {
$this->lispacer = " ".(++$this->listcount).". ";
}
else {
//unordered list simbol
$this->lispacer = " - ";
}
$this->Write($this->lasth, $this->lispacer, '', $fill);
break;
}
case 'tr':
case 'blockquote':
case 'br': {
$this->Ln();
if(strlen($this->lispacer) > 0) {
$this->x += $this->GetStringWidth($this->lispacer);
}
break;
}
case 'p': {
$this->Ln();
$this->Ln();
break;
}
case 'sup': {
$currentFontSize = $this->FontSize;
$this->tempfontsize = $this->FontSizePt;
$this->SetFontSize($this->FontSizePt * K_SMALL_RATIO);
$this->SetXY($this->GetX(), $this->GetY() - (($currentFontSize - $this->FontSize)*(K_SMALL_RATIO)));
break;
}
case 'sub': {
$currentFontSize = $this->FontSize;
$this->tempfontsize = $this->FontSizePt;
$this->SetFontSize($this->FontSizePt * K_SMALL_RATIO);
$this->SetXY($this->GetX(), $this->GetY() + (($currentFontSize - $this->FontSize)*(K_SMALL_RATIO)));
break;
}
case 'small': {
$currentFontSize = $this->FontSize;
$this->tempfontsize = $this->FontSizePt;
$this->SetFontSize($this->FontSizePt * K_SMALL_RATIO);
$this->SetXY($this->GetX(), $this->GetY() + (($currentFontSize - $this->FontSize)/3));
break;
}
case 'font': {
if (isset($attr['color']) AND $attr['color']!='') {
$coul = $this->convertColorHexToDec($attr['color']);
$this->SetTextColor($coul['R'],$coul['G'],$coul['B']);
$this->issetcolor=true;
}
// convertir les noms des polices de FckEditor
$attr['face'] = $this->convertNameFont($attr['face']);
if (isset($attr['face']) and in_array(strtolower($attr['face']), $this->fontlist)) {
$this->SetFont(strtolower($attr['face']));
$this->issetfont=true;
}
if (isset($attr['size'])) {
$headsize = intval($attr['size']);
} else {
$headsize = 0;
}
$currentFontSize = $this->FontSize;
$this->tempfontsize = $this->FontSizePt;
//$this->SetFontSize($this->FontSizePt + $headsize);
$this->SetFontSize($this->FontSizePt + $headsize - 3); // Todo: correction pour xx-small
$this->lasth = $this->FontSize * K_CELL_HEIGHT_RATIO;
break;
}
case 'span': {
if (isset($attr['style']) && $attr['style']!='') {
if (preg_match("/color/i",$attr['style'])){
if (preg_match("/rgb/i",$attr['style'])){
//print 'style rgb '.$attr['style'].'
';
$coul = substr($attr['style'],11,-2);
list($R, $G, $B) = explode(', ', $coul);
}
else if (preg_match("/#/",$attr['style'])){
//print 'style hexa '.$attr['style'].'
';
$R = hexdec(substr($attr['style'],8,2));
$G = hexdec(substr($attr['style'],10,2));
$B = hexdec(substr($attr['style'],12,2));
}
//print 'color '.$R.' '.$G.' '.$B;
$this->SetTextColor($R,$G,$B);
$this->issetcolor=true;
}
if (preg_match("/font-family/i",$attr['style'])){
$fontName = substr($attr['style'],13,-1);
$fontName = $this->convertNameFont($fontName);
if (isset($fontName) && in_array(strtolower($fontName), $this->fontlist)) {
$this->SetFont(strtolower($fontName));
$this->issetfont=true;
//print 'fontfamily: '.$this->FontFamily.'
';
}
}
if (preg_match("/font-size/i",$attr['style'])){
$headsize = substr($attr['style'],11);
$headsize = preg_replace('/[;-]/','',$headsize);
//print 'headsize1: '.$headsize.'
';
//print 'recupheadsize: '.$this->$headsize.'
';
$headsize = intval($this->$headsize);
//print 'headsize2: '.$headsize.'
';
}
} else {
$headsize = 1;
}
$currentFontSize = $this->FontSize;
$this->tempfontsize = $this->FontSizePt;
//$this->SetFontSize($this->FontSizePt + $headsize);
//print 'fontsizept: '.$this->FontSizePt.'
';
$this->SetFontSize($this->FontSizePt + $headsize - 3); // Todo: correction pour xx-small
$this->lasth = $this->FontSize * K_CELL_HEIGHT_RATIO;
//print 'fontsizeptafter: '.$this->FontSizePt.'
';
//print 'fontsize:'.$this->FontSize.'
';
//$this->closedHTMLTagHandler('span');
break;
}
case 'h1':
case 'h2':
case 'h3':
case 'h4':
case 'h5':
case 'h6': {
$headsize = (4 - substr($tag, 1)) * 2;
$currentFontSize = $this->FontSize;
$this->tempfontsize = $this->FontSizePt;
$this->SetFontSize($this->FontSizePt + $headsize);
$this->setStyle('b', true);
$this->lasth = $this->FontSize * K_CELL_HEIGHT_RATIO;
break;
}
}
}
/**
* Process closing tags.
* @param string $tag tag name (in uppercase)
* @access private
*/
function closedHTMLTagHandler($tag) {
//Closing tag
switch($tag) {
case 'td':
case 'th': {
$this->tdbegin = false;
$this->tdwidth = 0;
$this->tdheight = 0;
$this->tdalign = "L";
$this->tdbgcolor = false;
$this->SetFillColor($this->prevFillColor[0], $this->prevFillColor[1], $this->prevFillColor[2]);
break;
}
case 'tr': {
$this->Ln();
break;
}
case 'table': {
$this->tableborder=0;
break;
}
case 'strong': {
$this->setStyle('b', false);
break;
}
case 'em': {
$this->setStyle('i', false);
break;
}
case 'b':
case 'i':
case 'u': {
$this->setStyle($tag, false);
break;
}
case 'a': {
$this->HREF = '';
break;
}
case 'sup': {
$currentFontSize = $this->FontSize;
$this->SetFontSize($this->tempfontsize);
$this->tempfontsize = $this->FontSizePt;
$this->SetXY($this->GetX(), $this->GetY() - (($currentFontSize - $this->FontSize)*(K_SMALL_RATIO)));
break;
}
case 'sub': {
$currentFontSize = $this->FontSize;
$this->SetFontSize($this->tempfontsize);
$this->tempfontsize = $this->FontSizePt;
$this->SetXY($this->GetX(), $this->GetY() + (($currentFontSize - $this->FontSize)*(K_SMALL_RATIO)));
break;
}
case 'small': {
$currentFontSize = $this->FontSize;
$this->SetFontSize($this->tempfontsize);
$this->tempfontsize = $this->FontSizePt;
$this->SetXY($this->GetX(), $this->GetY() - (($this->FontSize - $currentFontSize)/3));
break;
}
case 'span':
case 'font': {
if ($this->issetcolor == true) {
$this->SetTextColor($this->prevTextColor[0], $this->prevTextColor[1], $this->prevTextColor[2]);
}
if ($this->issetfont) {
$this->FontFamily = $this->prevFontFamily;
$this->FontStyle = $this->prevFontStyle;
$this->SetFont($this->FontFamily);
$this->issetfont = false;
}
$currentFontSize = $this->FontSize;
$this->SetFontSize($this->tempfontsize);
$this->tempfontsize = $this->FontSizePt;
//$this->TextColor = $this->prevTextColor;
$this->lasth = $this->FontSize * K_CELL_HEIGHT_RATIO;
break;
}
case 'ul': {
$this->Ln();
break;
}
case 'ol': {
$this->Ln();
break;
}
case 'li': {
$this->lispacer = "";
break;
}
case 'h1':
case 'h2':
case 'h3':
case 'h4':
case 'h5':
case 'h6': {
$currentFontSize = $this->FontSize;
$this->SetFontSize($this->tempfontsize);
$this->tempfontsize = $this->FontSizePt;
$this->setStyle('b', false);
$this->Ln();
$this->lasth = $this->FontSize * K_CELL_HEIGHT_RATIO;
break;
}
default : {
break;
}
}
}
/**
* Sets font style.
* @param string $tag tag name (in lowercase)
* @param boolean $enable
* @access private
*/
function setStyle($tag, $enable) {
//Modify style and select corresponding font
$this->$tag += ($enable ? 1 : -1);
$style='';
foreach(array('b', 'i', 'u') as $s) {
if($this->$s > 0) {
$style .= $s;
}
}
$this->SetFont('', $style);
}
/**
* Output anchor link.
* @param string $url link URL
* @param string $name link name
* @param int $fill Indicates if the cell background must be painted (1) or transparent (0). Default value: 0.
* @access public
*/
function addHtmlLink($url, $name, $fill=0) {
//Put a hyperlink
$this->SetTextColor(0, 0, 255);
$this->setStyle('u', true);
$this->Write($this->lasth, $name, $url, $fill);
$this->setStyle('u', false);
$this->SetTextColor(0);
}
/**
* Returns an associative array (keys: R,G,B) from
* a hex html code (e.g. #3FE5AA).
* @param string $color hexadecimal html color [#rrggbb]
* @return array
* @access private
*/
function convertColorHexToDec($color = "#000000"){
$tbl_color = array();
$tbl_color['R'] = hexdec(substr($color, 1, 2));
$tbl_color['G'] = hexdec(substr($color, 3, 2));
$tbl_color['B'] = hexdec(substr($color, 5, 2));
return $tbl_color;
}
/**
* Converts pixels to millimeters in 72 dpi.
* @param int $px pixels
* @return float millimeters
* @access private
*/
function pixelsToMillimeters($px){
return $px * 25.4 / 72;
}
/**
* Reverse function for htmlentities.
* Convert entities in UTF-8.
*
* @param $text_to_convert Text to convert.
* @return string converted
*/
function unhtmlentities($text_to_convert) {
require_once(dirname(__FILE__).'/html_entity_decode_php4.php');
return html_entity_decode_php4($text_to_convert);
}
/**
* Set the image scale.
* @param float $scale image scale.
* @author Nicola Asuni
* @since 1.5.2
*/
function setImageScale($scale) {
$this->imgscale=$scale;
}
/**
* Returns the image scale.
* @return float image scale.
* @author Nicola Asuni
* @since 1.5.2
*/
function getImageScale() {
return $this->imgscale;
}
/**
* Returns the page width in units.
* @return int page width.
* @author Nicola Asuni
* @since 1.5.2
*/
function getPageWidth() {
return $this->w;
}
/**
* Returns the page height in units.
* @return int page height.
* @author Nicola Asuni
* @since 1.5.2
*/
function getPageHeight() {
return $this->fh;
}
/**
* Returns the page break margin.
* @return int page break margin.
* @author Nicola Asuni
* @since 1.5.2
*/
function getBreakMargin() {
return $this->bMargin;
}
/**
* Returns the scale factor (number of points in user unit).
* @return int scale factor.
* @author Nicola Asuni
* @since 1.5.2
*/
function getScaleFactor() {
return $this->k;
}
/**
* Converti les noms des polices FckEditor.
* @string string chaine � convertir
* @return string chaine convertie.
* @author Regis Houssin
*/
function convertNameFont($namefont)
{
if ($namefont == "Times New Roman")
{
$name = "times";
}
else if ($namefont == "Arial")
{
$name = "helvetica";
}
else if ($namefont == "Verdana")
{
$name = "helvetica";
}
else if ($namefont == "Comic Sans MS")
{
$name = "helvetica";
}
else if ($namefont == "Courier New")
{
$name = "courier";
}
else if ($namefont == "Tahoma")
{
$name = "helvetica";
}
return $name;
}
/**
* Param�trage des pr�f�rences d'affichage.
* @string preference liste des pr�f�rences d'affichage (voir la fonction _putcatalog)
* @ex: $pdf->DisplayPreferences('HideMenubar,HideToolbar,HideWindowUI')
* @author Michel Poulain
*/
function DisplayPreferences($preferences)
{
$this->DisplayPreferences.=$preferences;
}
/* End DOLCHANGE Added by Regis */
//End of class
}
//Handle special IE contype request
if(isset($_SERVER['HTTP_USER_AGENT']) && $_SERVER['HTTP_USER_AGENT']=='contype')
{
header('Content-Type: application/pdf');
exit;
}
?>