/** * @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 color * * @param string $css * * @return string|null $value */ public function convertBackgroundColor($css) { $res = null; if ($css == 'transparent') { return null; } else { return $this->cssConverter->convertToColor($css, $res); } }
/** * 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); }
/** * tag : PAGE * mode : OPEN * * @param array $param * @return boolean */ protected function _tag_open_PAGE($param) { if ($this->_isForOneLine) { return false; } if (!is_null($this->debug)) { $this->debug->addStep('PAGE ' . ($this->_page + 1), true); } $newPageSet = !isset($param['pageset']) || $param['pageset'] != 'old'; $resetPageNumber = isset($param['pagegroup']) && $param['pagegroup'] == 'new'; if (array_key_exists('hideheader', $param) && $param['hideheader'] != 'false' && !empty($param['hideheader'])) { $this->_hideHeader = (array) array_merge($this->_hideHeader, split(',', $param['hideheader'])); } $this->_maxH = 0; // if new page set asked if ($newPageSet) { $this->_subHEADER = array(); $this->_subFOOTER = array(); // orientation $orientation = ''; if (isset($param['orientation'])) { $param['orientation'] = strtolower($param['orientation']); if ($param['orientation'] == 'p') { $orientation = 'P'; } if ($param['orientation'] == 'portrait') { $orientation = 'P'; } if ($param['orientation'] == 'l') { $orientation = 'L'; } if ($param['orientation'] == 'paysage') { $orientation = 'L'; } if ($param['orientation'] == 'landscape') { $orientation = 'L'; } } // format $format = null; if (isset($param['format'])) { $format = strtolower($param['format']); if (preg_match('/^([0-9]+)x([0-9]+)$/isU', $format, $match)) { $format = array(intval($match[1]), intval($match[2])); } } // background $background = array(); if (isset($param['backimg'])) { $background['img'] = isset($param['backimg']) ? $param['backimg'] : ''; // src of the image $background['posX'] = isset($param['backimgx']) ? $param['backimgx'] : 'center'; // horizontale position of the image $background['posY'] = isset($param['backimgy']) ? $param['backimgy'] : 'middle'; // vertical position of the image $background['width'] = isset($param['backimgw']) ? $param['backimgw'] : '100%'; // width of the image (100% = page width) // convert the src of the image, if parameters $background['img'] = str_replace('&', '&', $background['img']); // convert the positions if ($background['posX'] == 'left') { $background['posX'] = '0%'; } if ($background['posX'] == 'center') { $background['posX'] = '50%'; } if ($background['posX'] == 'right') { $background['posX'] = '100%'; } if ($background['posY'] == 'top') { $background['posY'] = '0%'; } if ($background['posY'] == 'middle') { $background['posY'] = '50%'; } if ($background['posY'] == 'bottom') { $background['posY'] = '100%'; } if ($background['img']) { // get the size of the image // WARNING : if URL, "allow_url_fopen" must turned to "on" in php.ini $infos = @getimagesize($background['img']); if (count($infos) > 1) { $imageWidth = $this->cssConverter->ConvertToMM($background['width'], $this->pdf->getW()); $imageHeight = $imageWidth * $infos[1] / $infos[0]; $background['width'] = $imageWidth; $background['posX'] = $this->cssConverter->ConvertToMM($background['posX'], $this->pdf->getW() - $imageWidth); $background['posY'] = $this->cssConverter->ConvertToMM($background['posY'], $this->pdf->getH() - $imageHeight); } else { $background = array(); } } else { $background = array(); } } // margins of the page $background['top'] = isset($param['backtop']) ? $param['backtop'] : '0'; $background['bottom'] = isset($param['backbottom']) ? $param['backbottom'] : '0'; $background['left'] = isset($param['backleft']) ? $param['backleft'] : '0'; $background['right'] = isset($param['backright']) ? $param['backright'] : '0'; // if no unit => mm if (preg_match('/^([0-9]*)$/isU', $background['top'])) { $background['top'] .= 'mm'; } if (preg_match('/^([0-9]*)$/isU', $background['bottom'])) { $background['bottom'] .= 'mm'; } if (preg_match('/^([0-9]*)$/isU', $background['left'])) { $background['left'] .= 'mm'; } if (preg_match('/^([0-9]*)$/isU', $background['right'])) { $background['right'] .= 'mm'; } // convert to mm $background['top'] = $this->cssConverter->ConvertToMM($background['top'], $this->pdf->getH()); $background['bottom'] = $this->cssConverter->ConvertToMM($background['bottom'], $this->pdf->getH()); $background['left'] = $this->cssConverter->ConvertToMM($background['left'], $this->pdf->getW()); $background['right'] = $this->cssConverter->ConvertToMM($background['right'], $this->pdf->getW()); // get the background color $res = false; $background['color'] = isset($param['backcolor']) ? $this->cssConverter->convertToColor($param['backcolor'], $res) : null; if (!$res) { $background['color'] = null; } $this->parsingCss->save(); $this->parsingCss->analyse('PAGE', $param); $this->parsingCss->setPosition(); $this->parsingCss->fontSet(); // new page $this->_setNewPage($format, $orientation, $background, null, $resetPageNumber); // automatic footer if (isset($param['footer'])) { $lst = explode(';', $param['footer']); foreach ($lst as $key => $val) { $lst[$key] = trim(strtolower($val)); } $page = in_array('page', $lst); $date = in_array('date', $lst); $hour = in_array('heure', $lst); $form = in_array('form', $lst); } else { $page = null; $date = null; $hour = null; $form = null; } $this->pdf->SetMyFooter($page, $date, $hour, $form); // else => we use the last page set used } else { $this->parsingCss->save(); $this->parsingCss->analyse('PAGE', $param); $this->parsingCss->setPosition(); $this->parsingCss->fontSet(); $this->_setNewPage(null, null, null, null, $resetPageNumber); } return true; }