function counter_value($id = self::DEFAULT_COUNTER, $type = "decimal")
 {
     $type = mb_strtolower($type);
     if (!isset($this->_counters[$id])) {
         $this->_counters[$id] = 0;
     }
     $value = $this->_counters[$id];
     switch ($type) {
         default:
         case "decimal":
             return $value;
         case "decimal-leading-zero":
             return str_pad($value, 2, "0", STR_PAD_LEFT);
         case "lower-roman":
             return Helpers::dec2roman($value);
         case "upper-roman":
             return mb_strtoupper(Helpers::dec2roman($value));
         case "lower-latin":
         case "lower-alpha":
             return chr($value % 26 + ord('a') - 1);
         case "upper-latin":
         case "upper-alpha":
             return chr($value % 26 + ord('A') - 1);
         case "lower-greek":
             return Helpers::unichr($value + 944);
         case "upper-greek":
             return Helpers::unichr($value + 912);
     }
 }
Ejemplo n.º 2
0
 /**
  * @param integer $n
  * @param string $type
  * @param integer $pad
  *
  * @return string
  */
 private function make_counter($n, $type, $pad = null)
 {
     $n = intval($n);
     $text = "";
     $uppercase = false;
     switch ($type) {
         case "decimal-leading-zero":
         case "decimal":
         case "1":
             if ($pad) {
                 $text = str_pad($n, $pad, "0", STR_PAD_LEFT);
             } else {
                 $text = $n;
             }
             break;
         case "upper-alpha":
         case "upper-latin":
         case "A":
             $uppercase = true;
         case "lower-alpha":
         case "lower-latin":
         case "a":
             $text = chr($n % 26 + ord('a') - 1);
             break;
         case "upper-roman":
         case "I":
             $uppercase = true;
         case "lower-roman":
         case "i":
             $text = Helpers::dec2roman($n);
             break;
         case "lower-greek":
             $text = Helpers::unichr($n + 944);
             break;
     }
     if ($uppercase) {
         $text = strtoupper($text);
     }
     return "{$text}.";
 }
Ejemplo n.º 3
0
 /**
  * Parses a CSS string containing quotes and escaped hex characters
  *
  * @param $string string The CSS string to parse
  * @param $single_trim
  * @return string
  */
 protected function _parse_string($string, $single_trim = false)
 {
     if ($single_trim) {
         $string = preg_replace('/^[\\"\']/', "", $string);
         $string = preg_replace('/[\\"\']$/', "", $string);
     } else {
         $string = trim($string, "'\"");
     }
     $string = str_replace(array("\\\n", '\\"', "\\'"), array("", '"', "'"), $string);
     // Convert escaped hex characters into ascii characters (e.g. \A => newline)
     $string = preg_replace_callback("/\\\\([0-9a-fA-F]{0,6})/", function ($matches) {
         return \Dompdf\Helpers::unichr(hexdec($matches[1]));
     }, $string);
     return $string;
 }