/** * @param string $css * @param boolean $expectedRes * @param array $expectedColor * * @dataProvider convertToColorProvider */ public function testConvertToColor($css, $expectedRes, $expectedColor) { $res = true; $resultColor = $this->cssConverter->convertToColor($css, $res); $this->assertEquals($expectedRes, $res); $this->assertEquals(count($expectedColor), count($resultColor)); for ($i = 0; $i < count($resultColor); $i++) { if (is_null($expectedColor[$i])) { $this->assertNull($resultColor[$i]); } else { $this->assertEquals($expectedColor[$i], $resultColor[$i]); } } }
/** * Parse a background position * * @param string $css * @param boolean &$res flag if convert is ok or not * * @return array (x, y) */ public function convertBackgroundPosition($css, &$res) { // init the res $res = false; // explode the value $css = explode(' ', $css); // we must have 2 values. if 0 or >2 : error. if 1 => put center for 2 if (count($css) < 2) { if (!$css[0]) { return null; } $css[1] = 'center'; } if (count($css) > 2) { return null; } // prepare the values $x = 0; $y = 0; $res = true; // convert the first value if ($css[0] == 'left') { $x = '0%'; } elseif ($css[0] == 'center') { $x = '50%'; } elseif ($css[0] == 'right') { $x = '100%'; } elseif ($css[0] == 'top') { $y = '0%'; } elseif ($css[0] == 'bottom') { $y = '100%'; } elseif (preg_match('/^[-]?[0-9\\.]+%$/isU', $css[0])) { $x = $css[0]; } elseif ($this->cssConverter->convertToMM($css[0])) { $x = $this->cssConverter->convertToMM($css[0]); } else { $res = false; } // convert the second value if ($css[1] == 'left') { $x = '0%'; } elseif ($css[1] == 'right') { $x = '100%'; } elseif ($css[1] == 'top') { $y = '0%'; } elseif ($css[1] == 'center') { $y = '50%'; } elseif ($css[1] == 'bottom') { $y = '100%'; } elseif (preg_match('/^[-]?[0-9\\.]+%$/isU', $css[1])) { $y = $css[1]; } elseif ($this->cssConverter->convertToMM($css[1])) { $y = $this->cssConverter->convertToMM($css[1]); } else { $res = false; } // return the values return array($x, $y); }
/** * tag : END_LAST_PAGE * mode : OPEN * * @param array $param * @return void */ protected function _tag_open_END_LAST_PAGE($param) { $height = $this->cssConverter->ConvertToMM($param['end_height'], $this->pdf->getH() - $this->pdf->gettMargin() - $this->pdf->getbMargin()); if ($height < $this->pdf->getH() - $this->pdf->gettMargin() - $this->pdf->getbMargin() && $this->pdf->getY() + $height >= $this->pdf->getH() - $this->pdf->getbMargin()) { $this->_setNewPage(); } $this->parsingCss->save(); $this->parsingCss->analyse('end_last_page', $param); $this->parsingCss->setPosition(); $this->parsingCss->fontSet(); $this->pdf->setY($this->pdf->getH() - $this->pdf->getbMargin() - $height); }
/** * Analyse a border * * @param string $css css border properties * * @return array border properties */ public function readBorder($css) { // border none $none = array('type' => 'none', 'width' => 0, 'color' => array(0, 0, 0)); // default value $type = 'solid'; $width = $this->cssConverter->convertToMM('1pt'); $color = array(0, 0, 0); // clean up the values $css = explode(' ', $css); foreach ($css as $k => $v) { $v = trim($v); if ($v !== '') { $css[$k] = $v; } else { unset($css[$k]); } } $css = array_values($css); // read the values $res = null; foreach ($css as $value) { // if no border => return none if ($value == 'none' || $value == 'hidden') { return $none; } // try to convert the value as a distance $tmp = $this->cssConverter->convertToMM($value); // if the convert is ok => it is a width if ($tmp !== null) { $width = $tmp; // else, it could be the type } elseif (in_array($value, array('solid', 'dotted', 'dashed', 'double'))) { $type = $value; // else, it could be the color } else { $tmp = $this->cssConverter->convertToColor($value, $res); if ($res) { $color = $tmp; } } } // if no witdh => return none if (!$width) { return $none; } // return the border properties return array('type' => $type, 'width' => $width, 'color' => $color); }