fix php 5.6 in docker dev env (#1740)
[openemr.git] / vendor / mpdf / mpdf / includes / functions.php
blob3d471f60fa84933a863dd67f5b87c0ba286c7092
1 <?php
4 // mPDF 6
5 // Function only available PHP >=5.5.0
6 if(!function_exists('imagepalettetotruecolor')) {
7 function imagepalettetotruecolor(&$src) {
8 if(imageistruecolor($src)) {
9 return(true);
11 $dst = imagecreatetruecolor(imagesx($src), imagesy($src));
13 imagecopy($dst, $src, 0, 0, 0, 0, imagesx($src), imagesy($src));
14 imagedestroy($src);
16 $src = $dst;
18 return(true);
22 // mPDF 5.7
23 // Replace a section of an array with the elements in reverse
24 function array_splice_reverse(&$arr, $offset, $length) {
25 $tmp = (array_reverse(array_slice($arr, $offset, $length)));
26 array_splice($arr, $offset, $length, $tmp);
30 // mPDF 5.7.4 URLs
31 function urldecode_parts($url) {
32 $file=$url;
33 $query='';
34 if (preg_match('/[?]/',$url)) {
35 $bits = preg_split('/[?]/',$url,2);
36 $file=$bits[0];
37 $query='?'.$bits[1];
39 $file = rawurldecode($file);
40 $query = urldecode($query);
41 return $file.$query;
45 function _strspn($str1, $str2, $start=null, $length=null) {
46 $numargs = func_num_args();
47 if ($numargs == 2) {
48 return strspn($str1, $str2);
50 else if ($numargs == 3) {
51 return strspn($str1, $str2, $start);
53 else {
54 return strspn($str1, $str2, $start, $length);
59 function _strcspn($str1, $str2, $start=null, $length=null) {
60 $numargs = func_num_args();
61 if ($numargs == 2) {
62 return strcspn($str1, $str2);
64 else if ($numargs == 3) {
65 return strcspn($str1, $str2, $start);
67 else {
68 return strcspn($str1, $str2, $start, $length);
72 function _fgets (&$h, $force=false) {
73 $startpos = ftell($h);
74 $s = fgets($h, 1024);
75 if ($force && preg_match("/^([^\r\n]*[\r\n]{1,2})(.)/",trim($s), $ns)) {
76 $s = $ns[1];
77 fseek($h,$startpos+strlen($s));
79 return $s;
83 // For PHP4 compatability
84 if(!function_exists('str_ireplace')) {
85 function str_ireplace($search,$replace,$subject) {
86 $search = preg_quote($search, "/");
87 return preg_replace("/".$search."/i", $replace, $subject);
90 if(!function_exists('htmlspecialchars_decode')) {
91 function htmlspecialchars_decode ($str) {
92 return strtr($str, array_flip(get_html_translation_table(HTML_SPECIALCHARS)));
96 function PreparePreText($text,$ff='//FF//') {
97 $text = htmlspecialchars($text);
98 if ($ff) { $text = str_replace($ff,'</pre><formfeed /><pre>',$text); }
99 return ('<pre>'.$text.'</pre>');
102 if(!function_exists('strcode2utf')){
103 function strcode2utf($str,$lo=true) {
104 //converts all the &#nnn; and &#xhhh; in a string to Unicode
105 // mPDF 5.7
106 if ($lo) {
107 $str = preg_replace_callback('/\&\#([0-9]+)\;/m', 'code2utf_lo_callback', $str);
108 $str = preg_replace_callback('/\&\#x([0-9a-fA-F]+)\;/m', 'codeHex2utf_lo_callback', $str);
110 else {
111 $str = preg_replace_callback('/\&\#([0-9]+)\;/m', 'code2utf_callback', $str);
112 $str = preg_replace_callback('/\&\#x([0-9a-fA-F]+)\;/m', 'codeHex2utf_callback', $str);
114 return $str;
117 function code2utf_callback($matches) {
118 return code2utf($matches[1], 0);
120 function code2utf_lo_callback($matches) {
121 return code2utf($matches[1], 1);
123 function codeHex2utf_callback($matches) {
124 return codeHex2utf($matches[1], 0);
126 function codeHex2utf_lo_callback($matches) {
127 return codeHex2utf($matches[1], 1);
131 if(!function_exists('code2utf')){
132 function code2utf($num,$lo=true){
133 //Returns the utf string corresponding to the unicode value
134 if ($num<128) {
135 if ($lo) return chr($num);
136 else return '&#'.$num.';';
138 if ($num<2048) return chr(($num>>6)+192).chr(($num&63)+128);
139 if ($num<65536) return chr(($num>>12)+224).chr((($num>>6)&63)+128).chr(($num&63)+128);
140 if ($num<2097152) return chr(($num>>18)+240).chr((($num>>12)&63)+128).chr((($num>>6)&63)+128) .chr(($num&63)+128);
141 return '?';
146 if(!function_exists('codeHex2utf')){
147 function codeHex2utf($hex,$lo=true){
148 $num = hexdec($hex);
149 if (($num<128) && !$lo) return '&#x'.$hex.';';
150 return code2utf($num,$lo);