1<?php 2 3namespace Mpdf\Conversion; 4 5class DecToHebrew 6{ 7 8 public function convert($in, $reverse = false) 9 { 10 // reverse is used when called from Lists, as these do not pass through bidi-algorithm 11 $i = intval($in); // I initially be the counter value 12 $s = ''; // S initially be the empty string 13 14 // and glyph list initially be the list of additive tuples. 15 $additive_nums = [400, 300, 200, 100, 90, 80, 70, 60, 50, 40, 30, 20, 19, 18, 17, 16, 15, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]; 16 $additive_glyphs = [0x05EA, 0x05E9, 0x05E8, 0x05E7, 0x05E6, 0x05E4, 0x05E2, 0x05E1, 0x05E0, 0x05DE, 0x05DC, 0x05DB, 17 [0x05D9, 0x05D8], [0x05D9, 0x05D7], [0x05D9, 0x05D6], [0x05D8, 0x05D6], [0x05D8, 0x05D5], 0x05D9, 18 0x05D8, 0x05D7, 0x05D6, 0x05D5, 0x05D4, 0x05D3, 0x05D2, 0x05D1, 0x05D0]; 19 20 // NB This system manually specifies the values for 19-15 to force the correct display of 15 and 16, which are commonly 21 // rewritten to avoid a close resemblance to the Tetragrammaton. 22 // This function only works up to 1,000 23 if ($i > 999) { 24 return $in; 25 } 26 27 // return as initial numeric string 28 // If I is initially 0, and there is an additive tuple with a weight of 0, append that tuple's counter glyph to S and return S. 29 if ($i == 0) { 30 return '0'; 31 } 32 33 // Otherwise, while I is greater than 0 and there are elements left in the glyph list: 34 for ($t = 0; $t < count($additive_nums); $t++) { 35 // Pop the first additive tuple from the glyph list. This is the current tuple. 36 $ct = $additive_nums[$t]; 37 // Append the current tuple's counter glyph to S x floor( I / current tuple's weight ) times (this may be 0). 38 $n = floor($i / $ct); 39 for ($j = 0; $j < $n; $j++) { 40 if (is_array($additive_glyphs[$t])) { 41 foreach ($additive_glyphs[$t] as $ag) { 42 if ($reverse) { 43 $s = code2utf($ag) . $s; 44 } else { 45 $s .= code2utf($ag); 46 } 47 } 48 } else { 49 if ($reverse) { 50 $s = code2utf($additive_glyphs[$t]) . $s; 51 } else { 52 $s .= code2utf($additive_glyphs[$t]); 53 } 54 } 55 $i -= ($ct * $n); 56 } 57 if ($i == 0) { 58 return $s; 59 } 60 } 61 62 return $in; // return as initial string 63 } 64 65} 66