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 = dec2roman($n); break; case "lower-greek": $text = unichr($n + 944); break; } if ($uppercase) { $text = strtoupper($text); } return $text . "."; }
function counter_value($id = self::DEFAULT_COUNTER, $type = "decimal") { $type = mb_strtolower($type); if ($id === "page") { $value = $this->get_dompdf()->get_canvas()->get_page_number(); } elseif (!isset($this->_counters[$id])) { $this->_counters[$id] = 0; $value = 0; } else { $value = $this->_counters[$id]; } switch ($type) { default: case "decimal": return $value; case "decimal-leading-zero": return str_pad($value, 2, "0"); case "lower-roman": return dec2roman($value); case "upper-roman": return mb_strtoupper(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 unichr($value + 944); case "upper-greek": return unichr($value + 912); } }
function counter_value($id = self::DEFAULT_COUNTER, $type = "decimal") { $type = mb_strtolower($type); if (!isset($this->_counters[$id])) { $this->_counters[$id] = 0; } switch ($type) { default: case "decimal": return $this->_counters[$id]; case "decimal-leading-zero": return str_pad($this->_counters[$id], 2, "0"); case "lower-roman": return dec2roman($this->_counters[$id]); case "upper-roman": return mb_strtoupper(dec2roman($this->_counters[$id])); case "lower-latin": case "lower-alpha": return chr($this->_counters[$id] % 26 + ord('a') - 1); case "upper-latin": case "upper-alpha": return chr($this->_counters[$id] % 26 + ord('A') - 1); case "lower-greek": return chr($this->_counters[$id] + 944); case "upper-greek": return chr($this->_counters[$id] + 912); } }
function printlistbuffer() { //! @return void //! @desc Prints all list-related buffered info //Save x coordinate $x = $this->oldx; foreach ($this->listitem as $item) { //Set default width & height values $this->divwidth = $this->pgwidth; $this->divheight = $this->lineheight; //Get list's buffered data $lvl = $item[0]; $num = $item[1]; $this->textbuffer = $item[2]; $occur = $item[3]; $type = $this->listlist[$lvl][$occur]['TYPE']; $maxnum = $this->listlist[$lvl][$occur]['MAXNUM']; switch ($type) { case 'A': $num = dec2alpha($num, true); $maxnum = dec2alpha($maxnum, true); $type = str_pad($num, strlen($maxnum), ' ', STR_PAD_LEFT) . "."; break; case 'a': $num = dec2alpha($num, false); $maxnum = dec2alpha($maxnum, false); $type = str_pad($num, strlen($maxnum), ' ', STR_PAD_LEFT) . "."; break; case 'I': $num = dec2roman($num, true); $maxnum = dec2roman($maxnum, true); $type = str_pad($num, strlen($maxnum), ' ', STR_PAD_LEFT) . "."; break; case 'i': $num = dec2roman($num, false); $maxnum = dec2roman($maxnum, false); $type = str_pad($num, strlen($maxnum), ' ', STR_PAD_LEFT) . "."; break; case '1': $type = str_pad($num, strlen($maxnum), ' ', STR_PAD_LEFT) . "."; break; case 'disc': $type = chr(149); break; case 'square': $type = chr(110); //black square on Zapfdingbats font break; case 'circle': $type = chr(186); break; default: break; } $this->x = 5 * $lvl + $x; //Indent list //Get bullet width including margins $oldsize = $this->FontSize * $this->k; if ($type == chr(110)) { $this->SetFont('zapfdingbats', '', 5); } $type .= ' '; $blt_width = $this->GetStringWidth($type) + $this->cMargin * 2; //Output bullet $this->Cell($blt_width, 5, $type, '', '', 'L'); $this->SetFont('arial', '', $oldsize); $this->divwidth = $this->divwidth + $this->lMargin - $this->x; //Print content $this->printbuffer($this->textbuffer); $this->textbuffer = array(); } //Reset all used values $this->listoccur = array(); $this->listitem = array(); $this->listlist = array(); $this->listlvl = 0; $this->listnum = 0; $this->listtype = ''; $this->textbuffer = array(); $this->divwidth = 0; $this->divheight = 0; $this->oldx = -1; //At last, but not least, skip a line $this->Ln($this->lineheight); }
function printdec2roman($n) { echo dec2roman($n); }
} // Calculate the sum of that array: $sum = 0; while ($curr = current($values)) { $next = next($values); $next > $curr ? $sum += $next - $curr + 0 * next($values) : ($sum += $curr); } // Return the value: return $sum; } if (count($argv) > 2) { $ni = $argv[1]; $nj = $argv[2]; $dump = ''; for ($i = 0; $i < $ni; ++$i) { for ($j = 0; $j < $nj; ++$j) { $dump .= dec2roman($j + 0); } } print "Total bytes: " . strlen($dump); } else { if (is_numeric($argv[1])) { print dec2roman($argv[1]); } else { print roman2dec($argv[1]); } } ?>