function setCSS($arrayaux) { //! @return void //! @desc Change some class attributes according to CSS properties if (!is_array($arrayaux)) { return; } //Removes PHP Warning foreach ($arrayaux as $k => $v) { switch ($k) { case 'WIDTH': $this->divwidth = ConvertSize($v, $this->pgwidth); break; case 'HEIGHT': $this->divheight = ConvertSize($v, $this->pgwidth); break; case 'BORDER': // width style color (width not supported correctly - it is always considered as normal) $prop = explode(' ', $v); if (count($prop) != 3) { break; } // Not supported: borders not fully declared //style: dashed dotted none (anything else => solid ) if (strnatcasecmp($prop[1], "dashed") == 0) { $this->dash_on = true; $this->SetDash(2, 2); //2mm on, 2mm off } elseif (strnatcasecmp($prop[1], "dotted") == 0) { $this->dotted_on = true; } elseif (strnatcasecmp($prop[1], "none") == 0) { $this->divborder = 0; } else { $this->divborder = 1; } //color $coul = ConvertColor($prop[2]); $this->SetDrawColor($coul['R'], $coul['G'], $coul['B']); $this->issetcolor = true; break; case 'FONT-FAMILY': // one of the $this->fontlist fonts //If it is a font list, get all font types $aux_fontlist = explode(",", $v); $fontarraysize = count($aux_fontlist); for ($i = 0; $i < $fontarraysize; $i++) { $fonttype = $aux_fontlist[$i]; $fonttype = trim($fonttype); //If font is found, set it, and exit loop if (in_array(strtolower($fonttype), $this->fontlist)) { $this->SetFont(strtolower($fonttype)); break; } //If font = "courier new" for example, try simply looking for "courier" $fonttype = explode(" ", $fonttype); $fonttype = $fonttype[0]; if (in_array(strtolower($fonttype), $this->fontlist)) { $this->SetFont(strtolower($fonttype)); break; } } break; case 'FONT-SIZE': //Does not support: smaller, larger if (is_numeric($v[0])) { $mmsize = ConvertSize($v, $this->pgwidth); $this->SetFontSize($mmsize * (72 / 25.4)); //Get size in points (pt) } else { $v = strtoupper($v); switch ($v) { //Values obtained from http://www.w3schools.com/html/html_reference.asp case 'XX-SMALL': $this->SetFontSize(0.7 * 11); break; case 'X-SMALL': $this->SetFontSize(0.77 * 11); break; case 'SMALL': $this->SetFontSize(0.86 * 11); break; case 'MEDIUM': $this->SetFontSize(11); break; case 'LARGE': $this->SetFontSize(1.2 * 11); break; case 'X-LARGE': $this->SetFontSize(1.5 * 11); break; case 'XX-LARGE': $this->SetFontSize(2 * 11); break; } } break; case 'FONT-STYLE': // italic normal oblique switch (strtoupper($v)) { case 'ITALIC': case 'OBLIQUE': $this->SetStyle('I', true); break; case 'NORMAL': break; } break; case 'FONT-WEIGHT': // normal bold //Does not support: bolder, lighter, 100..900(step value=100) switch (strtoupper($v)) { case 'BOLD': $this->SetStyle('B', true); break; case 'NORMAL': break; } break; case 'TEXT-DECORATION': // none underline //Does not support: overline, blink switch (strtoupper($v)) { case 'LINE-THROUGH': $this->strike = true; break; case 'UNDERLINE': $this->SetStyle('U', true); break; case 'NONE': break; } case 'TEXT-TRANSFORM': // none uppercase lowercase //Does not support: capitalize switch (strtoupper($v)) { case 'UPPERCASE': $this->toupper = true; break; case 'LOWERCASE': $this->tolower = true; break; case 'NONE': break; } case 'TEXT-ALIGN': //left right center justify switch (strtoupper($v)) { case 'LEFT': $this->divalign = "L"; break; case 'CENTER': $this->divalign = "C"; break; case 'RIGHT': $this->divalign = "R"; break; case 'JUSTIFY': $this->divalign = "J"; break; } break; case 'DIRECTION': //ltr(default) rtl if (strtolower($v) == 'rtl') { $this->divrevert = true; } break; case 'BACKGROUND': // bgcolor only $cor = ConvertColor($v); $this->bgcolorarray = $cor; $this->SetFillColor($cor['R'], $cor['G'], $cor['B']); $this->divbgcolor = true; break; case 'COLOR': // font color $cor = ConvertColor($v); $this->colorarray = $cor; $this->SetTextColor($cor['R'], $cor['G'], $cor['B']); $this->issetcolor = true; break; } //end of switch($k) } //end of foreach }
function setCSS($array) { //! @return void foreach ($array as $k => $v) { switch ($k) { case 'WIDTH': $this->divwidth = ConvertSize($v, $this->pgwidth); break; case 'HEIGHT': $this->divheight = ConvertSize($v, $this->pgwidth); break; case 'BORDER': // width style color (width not supported correctly - it is always considered as normal) $prop = explode(' ', $v); if (count($prop) != 3) { break; } // It does not support: borders not fully declared //style: dashed dotted none (anything else => solid ) if (strnatcasecmp($prop[1], "dashed") == 0) { $this->dash_on = true; $this->SetDash(2, 2); //2mm on, 2mm off } elseif (strnatcasecmp($prop[1], "dotted") == 0) { $this->dotted_on = true; } elseif (strnatcasecmp($prop[1], "none") == 0) { $this->divborder = 0; } else { $this->divborder = 1; } //color $coul = ConvertColor($prop[2]); $this->SetDrawColor($coul['R'], $coul['G'], $coul['B']); $this->issetcolor = true; break; case 'FONT-FAMILY': // one of the $this->fontlist fonts if (in_array(strtolower($v), $this->fontlist)) { $this->SetFont(strtolower($v)); } break; case 'FONT-SIZE': $this->SetFontSize(ConvertSize($v, $this->pgwidth)); break; case 'FONT-STYLE': // italic normal oblique switch (strtoupper($v)) { case 'ITALIC': case 'OBLIQUE': $this->SetStyle('I', true); break; case 'NORMAL': break; } break; case 'FONT-WEIGHT': // normal bold switch (strtoupper($v)) { case 'BOLD': $this->SetStyle('B', true); break; case 'NORMAL': break; } break; case 'TEXT-DECORATION': // none underline switch (strtoupper($v)) { case 'UNDERLINE': $this->SetStyle('U', true); break; case 'NONE': break; } case 'TEXT-TRANSFORM': // none uppercase lowercase switch (strtoupper($v)) { case 'UPPERCASE': $this->toupper = true; break; case 'LOWERCASE': $this->tolower = true; break; case 'NONE': break; } case 'TEXT-ALIGN': //left right center justify switch (strtoupper($v)) { case 'LEFT': $this->divalign = "L"; break; case 'CENTER': $this->divalign = "C"; break; case 'RIGHT': $this->divalign = "R"; break; case 'JUSTIFY': $this->divalign = "J"; break; } break; case 'DIRECTION': //ltr(default) rtl if (strtolower($v) == 'rtl') { $this->divrevert = true; } break; case 'BACKGROUND': // bgcolor only $coul = ConvertColor($v); $this->SetFillColor($coul['R'], $coul['G'], $coul['B']); $this->divbgcolor = true; break; case 'COLOR': // font color $coul = ConvertColor($v); $this->colorarray = $coul; $this->SetTextColor($coul['R'], $coul['G'], $coul['B']); $this->issetcolor = true; break; } //end of switch } //end of foreach }