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