- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOtl.php
More file actions
6238 lines (5658 loc) · 248 KB
/
Otl.php
File metadata and controls
6238 lines (5658 loc) · 248 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
namespace Mpdf;
use Mpdf\Strict;
use Mpdf\Css\TextVars;
use Mpdf\Fonts\FontCache;
use Mpdf\Shaper\Indic;
use Mpdf\Shaper\Myanmar;
use Mpdf\Shaper\Sea;
use Mpdf\Utils\UtfString;
class Otl
{
use Strict;
const _OTL_OLD_SPEC_COMPAT_1 = true;
const _DICT_NODE_TYPE_SPLIT = 0x01;
const _DICT_NODE_TYPE_LINEAR = 0x02;
const _DICT_INTERMEDIATE_MATCH = 0x03;
const _DICT_FINAL_MATCH = 0x04;
private $mpdf;
private $fontCache;
var $arabLeftJoining;
var $arabRightJoining;
var $arabTransparentJoin;
var $arabTransparent;
var $GSUBdata;
var $GPOSdata;
var $GSUBfont;
var $fontkey;
var $ttfOTLdata;
var $glyphIDtoUni;
var $_pos;
var $GSUB_offset;
var $GPOS_offset;
var $MarkAttachmentType;
var $MarkGlyphSets;
var $GlyphClassMarks;
var $GlyphClassLigatures;
var $GlyphClassBases;
var $GlyphClassComponents;
var $Ignores;
var $LuCoverage;
var $OTLdata;
var $assocLigs;
var $assocMarks;
var $shaper;
var $restrictToSyllable;
var $lbdicts; // Line-breaking dictionaries
var $LuDataCache;
var $arabGlyphs;
var $current_fh;
var $Entry;
var $Exit;
var $GDEFdata;
var $GPOSLookups;
var $GSLuCoverage;
var $GSUB_length;
var $GSUBLookups;
var $schOTLdata;
var $lastBidiStrongType;
var $debugOTL = false;
public function __construct(Mpdf $mpdf, FontCache $fontCache)
{
$this->mpdf = $mpdf;
$this->fontCache = $fontCache;
$this->current_fh = '';
$this->lbdicts = [];
$this->LuDataCache = [];
}
function applyOTL($str, $useOTL)
{
if (!$this->arabLeftJoining) {
$this->arabic_initialise();
}
$this->OTLdata = [];
if (trim($str) == '') {
return $str;
}
if (!$useOTL) {
return $str;
}
// 1. Load GDEF data
//==============================
$this->fontkey = $this->mpdf->CurrentFont['fontkey'];
$this->glyphIDtoUni = $this->mpdf->CurrentFont['glyphIDtoUni'];
$fontCacheFilename = $this->fontkey . '.GDEFdata.json';
if (!isset($this->GDEFdata[$this->fontkey]) && $this->fontCache->jsonHas($fontCacheFilename)) {
$font = $this->fontCache->jsonLoad($fontCacheFilename);
$this->GSUB_offset = $this->GDEFdata[$this->fontkey]['GSUB_offset'] = $font['GSUB_offset'];
$this->GPOS_offset = $this->GDEFdata[$this->fontkey]['GPOS_offset'] = $font['GPOS_offset'];
$this->GSUB_length = $this->GDEFdata[$this->fontkey]['GSUB_length'] = $font['GSUB_length'];
$this->MarkAttachmentType = $this->GDEFdata[$this->fontkey]['MarkAttachmentType'] = $font['MarkAttachmentType'];
$this->MarkGlyphSets = $this->GDEFdata[$this->fontkey]['MarkGlyphSets'] = $font['MarkGlyphSets'];
$this->GlyphClassMarks = $this->GDEFdata[$this->fontkey]['GlyphClassMarks'] = $font['GlyphClassMarks'];
$this->GlyphClassLigatures = $this->GDEFdata[$this->fontkey]['GlyphClassLigatures'] = $font['GlyphClassLigatures'];
$this->GlyphClassComponents = $this->GDEFdata[$this->fontkey]['GlyphClassComponents'] = $font['GlyphClassComponents'];
$this->GlyphClassBases = $this->GDEFdata[$this->fontkey]['GlyphClassBases'] = $font['GlyphClassBases'];
} else {
$this->GSUB_offset = $this->GDEFdata[$this->fontkey]['GSUB_offset'];
$this->GPOS_offset = $this->GDEFdata[$this->fontkey]['GPOS_offset'];
$this->GSUB_length = $this->GDEFdata[$this->fontkey]['GSUB_length'];
$this->MarkAttachmentType = $this->GDEFdata[$this->fontkey]['MarkAttachmentType'];
$this->MarkGlyphSets = $this->GDEFdata[$this->fontkey]['MarkGlyphSets'];
$this->GlyphClassMarks = $this->GDEFdata[$this->fontkey]['GlyphClassMarks'];
$this->GlyphClassLigatures = $this->GDEFdata[$this->fontkey]['GlyphClassLigatures'];
$this->GlyphClassComponents = $this->GDEFdata[$this->fontkey]['GlyphClassComponents'];
$this->GlyphClassBases = $this->GDEFdata[$this->fontkey]['GlyphClassBases'];
}
// 2. Prepare string as HEX string and Analyse character properties
//=================================================================
$earr = $this->mpdf->UTF8StringToArray($str, false);
$scriptblock = 0;
$scriptblocks = [];
$scriptblocks[0] = 0;
$vstr = '';
$OTLdata = [];
$subchunk = 0;
$charctr = 0;
foreach ($earr as $char) {
$ucd_record = Ucdn::get_ucd_record($char);
$sbl = $ucd_record[6];
// Special case - Arabic End of Ayah
if ($char == 1757) {
$sbl = Ucdn::SCRIPT_ARABIC;
}
if ($sbl && $sbl != 40 && $sbl != 102) {
if ($scriptblock == 0) {
$scriptblock = $sbl;
$scriptblocks[$subchunk] = $scriptblock;
} elseif ($scriptblock > 0 && $scriptblock != $sbl) {
// *************************************************
// NEW (non-common) Script encountered in this chunk. Start a new subchunk
$subchunk++;
$scriptblock = $sbl;
$charctr = 0;
$scriptblocks[$subchunk] = $scriptblock;
}
}
$OTLdata[$subchunk][$charctr]['general_category'] = $ucd_record[0];
$OTLdata[$subchunk][$charctr]['bidi_type'] = $ucd_record[2];
//$OTLdata[$subchunk][$charctr]['combining_class'] = $ucd_record[1];
//$OTLdata[$subchunk][$charctr]['bidi_type'] = $ucd_record[2];
//$OTLdata[$subchunk][$charctr]['mirrored'] = $ucd_record[3];
//$OTLdata[$subchunk][$charctr]['east_asian_width'] = $ucd_record[4];
//$OTLdata[$subchunk][$charctr]['normalization_check'] = $ucd_record[5];
//$OTLdata[$subchunk][$charctr]['script'] = $ucd_record[6];
$charasstr = $this->unicode_hex($char);
if (strpos($this->GlyphClassMarks, $charasstr) !== false) {
$OTLdata[$subchunk][$charctr]['group'] = 'M';
} elseif ($char == 32 || $char == 12288) {
$OTLdata[$subchunk][$charctr]['group'] = 'S';
} // 12288 = 0x3000 = CJK space
else {
$OTLdata[$subchunk][$charctr]['group'] = 'C';
}
$OTLdata[$subchunk][$charctr]['uni'] = $char;
$OTLdata[$subchunk][$charctr]['hex'] = $charasstr;
$charctr++;
}
/* PROCESS EACH SUBCHUNK WITH DIFFERENT SCRIPTS */
for ($sch = 0; $sch <= $subchunk; $sch++) {
$this->OTLdata = $OTLdata[$sch];
$scriptblock = $scriptblocks[$sch];
// 3. Get Appropriate Scripts, and Shaper engine from analysing text and list of available scripts/langsys in font
//==============================
// Based on actual script block of text, select shaper (and line-breaking dictionaries)
if (Ucdn::SCRIPT_DEVANAGARI <= $scriptblock && $scriptblock <= Ucdn::SCRIPT_MALAYALAM) {
$this->shaper = "I";
} // INDIC shaper
elseif ($scriptblock == Ucdn::SCRIPT_ARABIC || $scriptblock == Ucdn::SCRIPT_SYRIAC) {
$this->shaper = "A";
} // ARABIC shaper
elseif ($scriptblock == Ucdn::SCRIPT_NKO || $scriptblock == Ucdn::SCRIPT_MANDAIC) {
$this->shaper = "A";
} // ARABIC shaper
elseif ($scriptblock == Ucdn::SCRIPT_KHMER) {
$this->shaper = "K";
} // KHMER shaper
elseif ($scriptblock == Ucdn::SCRIPT_THAI) {
$this->shaper = "T";
} // THAI shaper
elseif ($scriptblock == Ucdn::SCRIPT_LAO) {
$this->shaper = "L";
} // LAO shaper
elseif ($scriptblock == Ucdn::SCRIPT_SINHALA) {
$this->shaper = "S";
} // SINHALA shaper
elseif ($scriptblock == Ucdn::SCRIPT_MYANMAR) {
$this->shaper = "M";
} // MYANMAR shaper
elseif ($scriptblock == Ucdn::SCRIPT_NEW_TAI_LUE) {
$this->shaper = "E";
} // SEA South East Asian shaper
elseif ($scriptblock == Ucdn::SCRIPT_CHAM) {
$this->shaper = "E";
} // SEA South East Asian shaper
elseif ($scriptblock == Ucdn::SCRIPT_TAI_THAM) {
$this->shaper = "E";
} // SEA South East Asian shaper
else {
$this->shaper = "";
}
// Get scripttag based on actual text script
$scripttag = Ucdn::$uni_scriptblock[$scriptblock];
$GSUBscriptTag = '';
$GSUBlangsys = '';
$GPOSscriptTag = '';
$GPOSlangsys = '';
$is_old_spec = false;
$ScriptLang = $this->mpdf->CurrentFont['GSUBScriptLang'];
if (count($ScriptLang)) {
list($GSUBscriptTag, $is_old_spec) = $this->_getOTLscriptTag($ScriptLang, $scripttag, $scriptblock, $this->shaper, $useOTL, 'GSUB');
if ($this->mpdf->fontLanguageOverride && strpos($ScriptLang[$GSUBscriptTag], $this->mpdf->fontLanguageOverride) !== false) {
$GSUBlangsys = str_pad($this->mpdf->fontLanguageOverride, 4);
} elseif ($GSUBscriptTag && isset($ScriptLang[$GSUBscriptTag]) && $ScriptLang[$GSUBscriptTag] != '') {
$GSUBlangsys = $this->_getOTLLangTag($this->mpdf->currentLang, $ScriptLang[$GSUBscriptTag]);
}
}
$ScriptLang = $this->mpdf->CurrentFont['GPOSScriptLang'];
// NB If after GSUB, the same script/lang exist for GPOS, just use these...
if ($GSUBscriptTag && $GSUBlangsys && isset($ScriptLang[$GSUBscriptTag]) && strpos($ScriptLang[$GSUBscriptTag], $GSUBlangsys) !== false) {
$GPOSlangsys = $GSUBlangsys;
$GPOSscriptTag = $GSUBscriptTag;
} // else repeat for GPOS
// [Font XBRiyaz has GSUB tables for latn, but not GPOS for latn]
elseif (count($ScriptLang)) {
list($GPOSscriptTag, $dummy) = $this->_getOTLscriptTag($ScriptLang, $scripttag, $scriptblock, $this->shaper, $useOTL, 'GPOS');
if ($GPOSscriptTag && $this->mpdf->fontLanguageOverride && strpos($ScriptLang[$GPOSscriptTag], $this->mpdf->fontLanguageOverride) !== false) {
$GPOSlangsys = str_pad($this->mpdf->fontLanguageOverride, 4);
} elseif ($GPOSscriptTag && isset($ScriptLang[$GPOSscriptTag]) && $ScriptLang[$GPOSscriptTag] != '') {
$GPOSlangsys = $this->_getOTLLangTag($this->mpdf->currentLang, $ScriptLang[$GPOSscriptTag]);
}
}
// This is just for the font_dump_OTL utility to set script and langsys override
// $mpdf->overrideOTLsettings does not exist, this is never called
/*if (isset($this->mpdf->overrideOTLsettings) && isset($this->mpdf->overrideOTLsettings[$this->fontkey])) {
$GSUBscriptTag = $GPOSscriptTag = $this->mpdf->overrideOTLsettings[$this->fontkey]['script'];
$GSUBlangsys = $GPOSlangsys = $this->mpdf->overrideOTLsettings[$this->fontkey]['lang'];
}*/
if (!$GSUBscriptTag && !$GSUBlangsys && !$GPOSscriptTag && !$GPOSlangsys) {
// Remove ZWJ and ZWNJ
for ($i = 0; $i < count($this->OTLdata); $i++) {
if ($this->OTLdata[$i]['uni'] == 8204 || $this->OTLdata[$i]['uni'] == 8205) {
array_splice($this->OTLdata, $i, 1);
}
}
$this->schOTLdata[$sch] = $this->OTLdata;
$this->OTLdata = [];
continue;
}
// Don't use MYANMAR shaper unless using v2 scripttag
if ($this->shaper == 'M' && $GSUBscriptTag != 'mym2') {
$this->shaper = '';
}
$GSUBFeatures = (isset($this->mpdf->CurrentFont['GSUBFeatures'][$GSUBscriptTag][$GSUBlangsys]) ? $this->mpdf->CurrentFont['GSUBFeatures'][$GSUBscriptTag][$GSUBlangsys] : false);
$GPOSFeatures = (isset($this->mpdf->CurrentFont['GPOSFeatures'][$GPOSscriptTag][$GPOSlangsys]) ? $this->mpdf->CurrentFont['GPOSFeatures'][$GPOSscriptTag][$GPOSlangsys] : false);
$this->assocLigs = []; // Ligatures[$posarr lpos] => nc
$this->assocMarks = []; // assocMarks[$posarr mpos] => array(compID, ligPos)
if (!isset($this->GDEFdata[$this->fontkey]['GSUBGPOStables'])) {
$this->ttfOTLdata = $this->GDEFdata[$this->fontkey]['GSUBGPOStables'] = $this->fontCache->load($this->fontkey . '.GSUBGPOStables.dat', 'rb');
if (!$this->ttfOTLdata) {
throw new \Mpdf\MpdfException('Can\'t open file ' . $this->fontCache->tempFilename($this->fontkey . '.GSUBGPOStables.dat'));
}
} else {
$this->ttfOTLdata = $this->GDEFdata[$this->fontkey]['GSUBGPOStables'];
}
if ($this->debugOTL) {
$this->_dumpproc('BEGIN', '-', '-', '-', '-', -1, '-', 0);
}
////////////////////////////////////////////////////////////////
///////// LINE BREAKING FOR KHMER, THAI + LAO /////////////////
////////////////////////////////////////////////////////////////
// Insert U+200B at word boundaries using dictionaries
if ($this->mpdf->useDictionaryLBR && ($this->shaper == "K" || $this->shaper == "T" || $this->shaper == "L")) {
// Sets $this->OTLdata[$i]['wordend']=true at possible end of word boundaries
$this->seaLineBreaking();
} // Insert U+200B at word boundaries for Tibetan
elseif ($this->mpdf->useTibetanLBR && $scriptblock == Ucdn::SCRIPT_TIBETAN) {
// Sets $this->OTLdata[$i]['wordend']=true at possible end of word boundaries
$this->tibetanLineBreaking();
}
////////////////////////////////////////////////////////////////
////////// GSUB /////////////////////////////////
////////////////////////////////////////////////////////////////
if (($useOTL & 0xFF) && $GSUBscriptTag && $GSUBlangsys && $GSUBFeatures) {
// 4. Load GSUB data, Coverage & Lookups
//=================================================================
$this->GSUBfont = $this->fontkey . '.GSUB.' . $GSUBscriptTag . '.' . $GSUBlangsys;
if (!isset($this->GSUBdata[$this->GSUBfont])) {
$fontCacheFilename = $this->GSUBfont . '.json';
if ($this->fontCache->jsonHas($fontCacheFilename)) {
$font = $this->fontCache->jsonLoad($fontCacheFilename);
$this->GSUBdata[$this->GSUBfont]['rtlSUB'] = $font['rtlSUB'];
$this->GSUBdata[$this->GSUBfont]['finals'] = $font['finals'];
if ($this->shaper == 'I') {
$this->GSUBdata[$this->GSUBfont]['rphf'] = $font['rphf'];
$this->GSUBdata[$this->GSUBfont]['half'] = $font['half'];
$this->GSUBdata[$this->GSUBfont]['pref'] = $font['pref'];
$this->GSUBdata[$this->GSUBfont]['blwf'] = $font['blwf'];
$this->GSUBdata[$this->GSUBfont]['pstf'] = $font['pstf'];
}
} else {
$this->GSUBdata[$this->GSUBfont] = ['rtlSUB' => [], 'rphf' => [], 'rphf' => [],
'pref' => [], 'blwf' => [], 'pstf' => [], 'finals' => ''
];
}
}
$fontCacheFilename = $this->fontkey . '.GSUBdata.json';
if (!isset($this->GSUBdata[$this->fontkey]) && $this->fontCache->jsonHas($fontCacheFilename)) {
$this->GSLuCoverage = $this->GSUBdata[$this->fontkey]['GSLuCoverage'] = $this->fontCache->jsonLoad($fontCacheFilename);
} else {
$this->GSLuCoverage = $this->GSUBdata[$this->fontkey]['GSLuCoverage'];
}
$this->GSUBLookups = $this->mpdf->CurrentFont['GSUBLookups'];
// 5(A). GSUB - Shaper - ARABIC
//==============================
if ($this->shaper == 'A') {
//-----------------------------------------------------------------------------------
// a. Apply initial GSUB Lookups (in order specified in lookup list but only selecting from certain tags)
//-----------------------------------------------------------------------------------
$tags = 'locl ccmp';
$omittags = '';
$usetags = $tags;
if (!empty($this->mpdf->OTLtags)) {
$usetags = $this->_applyTagSettings($tags, $GSUBFeatures, $omittags, true);
}
$this->_applyGSUBrules($usetags, $GSUBscriptTag, $GSUBlangsys);
//-----------------------------------------------------------------------------------
// b. Apply context-specific forms GSUB Lookups (initial, isolated, medial, final)
//-----------------------------------------------------------------------------------
// Arab and Syriac are the only scripts requiring the special joining - which takes the place of
// isol fina medi init rules in GSUB (+ fin2 fin3 med2 in Syriac syrc)
$tags = 'isol fina fin2 fin3 medi med2 init';
$omittags = '';
$usetags = $tags;
if (!empty($this->mpdf->OTLtags)) {
$usetags = $this->_applyTagSettings($tags, $GSUBFeatures, $omittags, true);
}
$this->arabGlyphs = $this->GSUBdata[$this->GSUBfont]['rtlSUB'];
$gcms = explode("| ", $this->GlyphClassMarks);
$gcm = [];
foreach ($gcms as $g) {
$gcm[hexdec($g)] = 1;
}
$this->arabTransparentJoin = $this->arabTransparent + $gcm;
$this->arabic_shaper($usetags, $GSUBscriptTag);
//-----------------------------------------------------------------------------------
// c. Set Kashida points (after joining occurred - medi, fina, init) but before other substitutions
//-----------------------------------------------------------------------------------
//if ($scriptblock == Ucdn::SCRIPT_ARABIC ) {
for ($i = 0; $i < count($this->OTLdata); $i++) {
// Put the kashida marker on the character BEFORE which is inserted the kashida
// Kashida marker is inverse of priority i.e. Priority 1 => 7, Priority 7 => 1.
// Priority 1 User-inserted Kashida 0640 = Tatweel
// The user entered a Kashida in a position
// Position: Before the user-inserted kashida
if ($this->OTLdata[$i]['uni'] == 0x0640) {
$this->OTLdata[$i]['GPOSinfo']['kashida'] = 8; // Put before the next character
} // Priority 2 Seen (0633) FEB3, FEB4; Sad (0635) FEBB, FEBC
// Initial or medial form
// Connecting to the next character
// Position: After the character
elseif ($this->OTLdata[$i]['uni'] == 0xFEB3 || $this->OTLdata[$i]['uni'] == 0xFEB4 || $this->OTLdata[$i]['uni'] == 0xFEBB || $this->OTLdata[$i]['uni'] == 0xFEBC) {
$checkpos = $i + 1;
while (isset($this->OTLdata[$checkpos]) && strpos($this->GlyphClassMarks, $this->OTLdata[$checkpos]['hex']) !== false) {
$checkpos++;
}
if (isset($this->OTLdata[$checkpos])) {
$this->OTLdata[$checkpos]['GPOSinfo']['kashida'] = 7; // Put after marks on next character
}
} // Priority 3 Taa Marbutah (0629) FE94; Haa (062D) FEA2; Dal (062F) FEAA
// Final form
// Connecting to previous character
// Position: Before the character
elseif ($this->OTLdata[$i]['uni'] == 0xFE94 || $this->OTLdata[$i]['uni'] == 0xFEA2 || $this->OTLdata[$i]['uni'] == 0xFEAA) {
$this->OTLdata[$i]['GPOSinfo']['kashida'] = 6;
} // Priority 4 Alef (0627) FE8E; Tah (0637) FEC2; Lam (0644) FEDE; Kaf (0643) FEDA; Gaf (06AF) FB93
// Final form
// Connecting to previous character
// Position: Before the character
elseif ($this->OTLdata[$i]['uni'] == 0xFE8E || $this->OTLdata[$i]['uni'] == 0xFEC2 || $this->OTLdata[$i]['uni'] == 0xFEDE || $this->OTLdata[$i]['uni'] == 0xFEDA || $this->OTLdata[$i]['uni'] == 0xFB93) {
$this->OTLdata[$i]['GPOSinfo']['kashida'] = 5;
} // Priority 5 RA (0631) FEAE; Ya (064A) FEF2 FEF4; Alef Maqsurah (0649) FEF0 FBE9
// Final or Medial form
// Connected to preceding medial BAA (0628) = FE92
// Position: Before preceding medial Baa
// Although not mentioned in spec, added Farsi Yeh (06CC) FBFD FBFF; equivalent to 064A or 0649
elseif ($this->OTLdata[$i]['uni'] == 0xFEAE || $this->OTLdata[$i]['uni'] == 0xFEF2 || $this->OTLdata[$i]['uni'] == 0xFEF0 || $this->OTLdata[$i]['uni'] == 0xFEF4 || $this->OTLdata[$i]['uni'] == 0xFBE9 || $this->OTLdata[$i]['uni'] == 0xFBFD || $this->OTLdata[$i]['uni'] == 0xFBFF
) {
$checkpos = $i - 1;
while (isset($this->OTLdata[$checkpos]) && strpos($this->GlyphClassMarks, $this->OTLdata[$checkpos]['hex']) !== false) {
$checkpos--;
}
if (isset($this->OTLdata[$checkpos]) && $this->OTLdata[$checkpos]['uni'] == 0xFE92) {
$this->OTLdata[$checkpos]['GPOSinfo']['kashida'] = 4; // ******* Before preceding BAA
}
} // Priority 6 WAW (0648) FEEE; Ain (0639) FECA; Qaf (0642) FED6; Fa (0641) FED2
// Final form
// Connecting to previous character
// Position: Before the character
elseif ($this->OTLdata[$i]['uni'] == 0xFEEE || $this->OTLdata[$i]['uni'] == 0xFECA || $this->OTLdata[$i]['uni'] == 0xFED6 || $this->OTLdata[$i]['uni'] == 0xFED2) {
$this->OTLdata[$i]['GPOSinfo']['kashida'] = 3;
}
// Priority 7 Other connecting characters
// Final form
// Connecting to previous character
// Position: Before the character
/* This isn't in the spec, but using MS WORD as a basis, give a lower priority to the 3 characters already checked
in (5) above. Test case:
خْرَىٰ
فَتُذَكِّر
*/
if (!isset($this->OTLdata[$i]['GPOSinfo']['kashida'])) {
if (strpos($this->GSUBdata[$this->GSUBfont]['finals'], $this->OTLdata[$i]['hex']) !== false) { // ANY OTHER FINAL FORM
$this->OTLdata[$i]['GPOSinfo']['kashida'] = 2;
} elseif (strpos('0FEAE 0FEF0 0FEF2', $this->OTLdata[$i]['hex']) !== false) { // not already included in 5 above
$this->OTLdata[$i]['GPOSinfo']['kashida'] = 1;
}
}
}
//-----------------------------------------------------------------------------------
// d. Apply Presentation Forms GSUB Lookups (+ any discretionary) - Apply one at a time in Feature order
//-----------------------------------------------------------------------------------
$tags = 'rlig calt liga clig mset';
$omittags = 'locl ccmp nukt akhn rphf rkrf pref blwf abvf half pstf cfar vatu cjct init medi fina isol med2 fin2 fin3 ljmo vjmo tjmo';
$usetags = $tags;
if (!empty($this->mpdf->OTLtags)) {
$usetags = $this->_applyTagSettings($tags, $GSUBFeatures, $omittags, false);
}
$ts = explode(' ', $usetags);
foreach ($ts as $ut) { // - Apply one at a time in Feature order
$this->_applyGSUBrules($ut, $GSUBscriptTag, $GSUBlangsys);
}
//-----------------------------------------------------------------------------------
// e. NOT IN SPEC
// If space precedes a mark -> substitute a before the Mark, to prevent line breaking Test:
//-----------------------------------------------------------------------------------
for ($ptr = 1; $ptr < count($this->OTLdata); $ptr++) {
if ($this->OTLdata[$ptr]['general_category'] == Ucdn::UNICODE_GENERAL_CATEGORY_NON_SPACING_MARK && $this->OTLdata[$ptr - 1]['uni'] == 32) {
$this->OTLdata[$ptr - 1]['uni'] = 0xa0;
$this->OTLdata[$ptr - 1]['hex'] = '000A0';
}
}
} // 5(I). GSUB - Shaper - INDIC and SINHALA and KHMER
//===================================
elseif ($this->shaper == 'I' || $this->shaper == 'K' || $this->shaper == 'S') {
$this->restrictToSyllable = true;
//-----------------------------------------------------------------------------------
// a. First decompose/compose split mattras
// (normalize) ??????? Nukta/Halant order etc ??????????????????????????????????????????????????????????????????????????
//-----------------------------------------------------------------------------------
for ($ptr = 0; $ptr < count($this->OTLdata); $ptr++) {
$char = $this->OTLdata[$ptr]['uni'];
$sub = Indic::decompose_indic($char);
if ($sub) {
$newinfo = [];
for ($i = 0; $i < count($sub); $i++) {
$newinfo[$i] = [];
$ucd_record = Ucdn::get_ucd_record($sub[$i]);
$newinfo[$i]['general_category'] = $ucd_record[0];
$newinfo[$i]['bidi_type'] = $ucd_record[2];
$charasstr = $this->unicode_hex($sub[$i]);
if (strpos($this->GlyphClassMarks, $charasstr) !== false) {
$newinfo[$i]['group'] = 'M';
} else {
$newinfo[$i]['group'] = 'C';
}
$newinfo[$i]['uni'] = $sub[$i];
$newinfo[$i]['hex'] = $charasstr;
}
array_splice($this->OTLdata, $ptr, 1, $newinfo);
$ptr += count($sub) - 1;
}
/* Only Composition-exclusion exceptions that we want to recompose. */
if ($this->shaper == 'I') {
if ($char == 0x09AF && isset($this->OTLdata[$ptr + 1]) && $this->OTLdata[$ptr + 1]['uni'] == 0x09BC) {
$sub = 0x09DF;
$newinfo = [];
$newinfo[0] = [];
$ucd_record = Ucdn::get_ucd_record($sub);
$newinfo[0]['general_category'] = $ucd_record[0];
$newinfo[0]['bidi_type'] = $ucd_record[2];
$newinfo[0]['group'] = 'C';
$newinfo[0]['uni'] = $sub;
$newinfo[0]['hex'] = $this->unicode_hex($sub);
array_splice($this->OTLdata, $ptr, 2, $newinfo);
}
}
}
//-----------------------------------------------------------------------------------
// b. Analyse characters - group as syllables/clusters (Indic); invalid diacritics; add dotted circle
//-----------------------------------------------------------------------------------
$indic_category_string = '';
foreach ($this->OTLdata as $eid => $c) {
Indic::set_indic_properties($this->OTLdata[$eid], $scriptblock); // sets ['indic_category'] and ['indic_position']
//$c['general_category']
//$c['combining_class']
//$c['uni'] = $char;
$indic_category_string .= Indic::$indic_category_char[$this->OTLdata[$eid]['indic_category']];
}
$broken_syllables = false;
if ($this->shaper == 'I') {
Indic::set_syllables($this->OTLdata, $indic_category_string, $broken_syllables);
} elseif ($this->shaper == 'S') {
Indic::set_syllables_sinhala($this->OTLdata, $indic_category_string, $broken_syllables);
} elseif ($this->shaper == 'K') {
Indic::set_syllables_khmer($this->OTLdata, $indic_category_string, $broken_syllables);
}
$indic_category_string = '';
//-----------------------------------------------------------------------------------
// c. Initial Re-ordering (Indic / Khmer / Sinhala)
//-----------------------------------------------------------------------------------
// Find base consonant
// Decompose/compose and reorder Matras
// Reorder marks to canonical order
$indic_config = Indic::$indic_configs[$scriptblock];
$dottedcircle = false;
if ($broken_syllables) {
if ($this->mpdf->_charDefined($this->mpdf->fonts[$this->fontkey]['cw'], 0x25CC)) {
$dottedcircle = [];
$ucd_record = Ucdn::get_ucd_record(0x25CC);
$dottedcircle[0]['general_category'] = $ucd_record[0];
$dottedcircle[0]['bidi_type'] = $ucd_record[2];
$dottedcircle[0]['group'] = 'C';
$dottedcircle[0]['uni'] = 0x25CC;
$dottedcircle[0]['indic_category'] = Indic::OT_DOTTEDCIRCLE;
$dottedcircle[0]['indic_position'] = Indic::POS_BASE_C;
$dottedcircle[0]['hex'] = '025CC'; // TEMPORARY *****
}
}
Indic::initial_reordering($this->OTLdata, $this->GSUBdata[$this->GSUBfont], $broken_syllables, $indic_config, $scriptblock, $is_old_spec, $dottedcircle);
//-----------------------------------------------------------------------------------
// d. Apply initial and basic shaping forms GSUB Lookups (one at a time)
//-----------------------------------------------------------------------------------
if ($this->shaper == 'I' || $this->shaper == 'S') {
$tags = 'locl ccmp nukt akhn rphf rkrf pref blwf half pstf vatu cjct';
} elseif ($this->shaper == 'K') {
$tags = 'locl ccmp pref blwf abvf pstf cfar';
}
$this->_applyGSUBrulesIndic($tags, $GSUBscriptTag, $GSUBlangsys, $is_old_spec);
//-----------------------------------------------------------------------------------
// e. Final Re-ordering (Indic / Khmer / Sinhala)
//-----------------------------------------------------------------------------------
// Reorder matras
// Reorder reph
// Reorder pre-base reordering consonants:
Indic::final_reordering($this->OTLdata, $this->GSUBdata[$this->GSUBfont], $indic_config, $scriptblock, $is_old_spec);
//-----------------------------------------------------------------------------------
// f. Apply 'init' feature to first syllable in word (indicated by ['mask']) Indic::FLAG(Indic::INIT);
//-----------------------------------------------------------------------------------
if ($this->shaper == 'I' || $this->shaper == 'S') {
$tags = 'init';
$this->_applyGSUBrulesIndic($tags, $GSUBscriptTag, $GSUBlangsys, $is_old_spec);
}
//-----------------------------------------------------------------------------------
// g. Apply Presentation Forms GSUB Lookups (+ any discretionary)
//-----------------------------------------------------------------------------------
$tags = 'pres abvs blws psts haln rlig calt liga clig mset';
$omittags = 'locl ccmp nukt akhn rphf rkrf pref blwf abvf half pstf cfar vatu cjct init medi fina isol med2 fin2 fin3 ljmo vjmo tjmo';
$usetags = $tags;
if (!empty($this->mpdf->OTLtags)) {
$usetags = $this->_applyTagSettings($tags, $GSUBFeatures, $omittags, false);
}
if ($this->shaper == 'K') { // Features are applied one at a time, working through each codepoint
$this->_applyGSUBrulesSingly($usetags, $GSUBscriptTag, $GSUBlangsys);
} else {
$this->_applyGSUBrules($usetags, $GSUBscriptTag, $GSUBlangsys);
}
$this->restrictToSyllable = false;
} // 5(M). GSUB - Shaper - MYANMAR (ONLY mym2)
//==============================
// NB Old style 'mymr' is left to go through the default shaper
elseif ($this->shaper == 'M') {
$this->restrictToSyllable = true;
//-----------------------------------------------------------------------------------
// a. Analyse characters - group as syllables/clusters (Myanmar); invalid diacritics; add dotted circle
//-----------------------------------------------------------------------------------
$myanmar_category_string = '';
foreach ($this->OTLdata as $eid => $c) {
Myanmar::set_myanmar_properties($this->OTLdata[$eid]); // sets ['myanmar_category'] and ['myanmar_position']
$myanmar_category_string .= Myanmar::$myanmar_category_char[$this->OTLdata[$eid]['myanmar_category']];
}
$broken_syllables = false;
Myanmar::set_syllables($this->OTLdata, $myanmar_category_string, $broken_syllables);
$myanmar_category_string = '';
//-----------------------------------------------------------------------------------
// b. Re-ordering (Myanmar mym2)
//-----------------------------------------------------------------------------------
$dottedcircle = false;
if ($broken_syllables) {
if ($this->mpdf->_charDefined($this->mpdf->fonts[$this->fontkey]['cw'], 0x25CC)) {
$dottedcircle = [];
$ucd_record = Ucdn::get_ucd_record(0x25CC);
$dottedcircle[0]['general_category'] = $ucd_record[0];
$dottedcircle[0]['bidi_type'] = $ucd_record[2];
$dottedcircle[0]['group'] = 'C';
$dottedcircle[0]['uni'] = 0x25CC;
$dottedcircle[0]['myanmar_category'] = Myanmar::OT_DOTTEDCIRCLE;
$dottedcircle[0]['myanmar_position'] = Myanmar::POS_BASE_C;
$dottedcircle[0]['hex'] = '025CC';
}
}
Myanmar::reordering($this->OTLdata, $this->GSUBdata[$this->GSUBfont], $broken_syllables, $dottedcircle);
//-----------------------------------------------------------------------------------
// c. Apply initial and basic shaping forms GSUB Lookups (one at a time)
//-----------------------------------------------------------------------------------
$tags = 'locl ccmp rphf pref blwf pstf';
$this->_applyGSUBrulesMyanmar($tags, $GSUBscriptTag, $GSUBlangsys);
//-----------------------------------------------------------------------------------
// d. Apply Presentation Forms GSUB Lookups (+ any discretionary)
//-----------------------------------------------------------------------------------
$tags = 'pres abvs blws psts haln rlig calt liga clig mset';
$omittags = 'locl ccmp nukt akhn rphf rkrf pref blwf abvf half pstf cfar vatu cjct init medi fina isol med2 fin2 fin3 ljmo vjmo tjmo';
$usetags = $tags;
if (!empty($this->mpdf->OTLtags)) {
$usetags = $this->_applyTagSettings($tags, $GSUBFeatures, $omittags, false);
}
$this->_applyGSUBrules($usetags, $GSUBscriptTag, $GSUBlangsys);
$this->restrictToSyllable = false;
} // 5(E). GSUB - Shaper - SEA South East Asian (New Tai Lue, Cham, Tai Tam)
//==============================
elseif ($this->shaper == 'E') {
/* HarfBuzz says: If the designer designed the font for the 'DFLT' script,
* use the default shaper. Otherwise, use the SEA shaper.
* Note that for some simple scripts, there may not be *any*
* GSUB/GPOS needed, so there may be no scripts found! */
$this->restrictToSyllable = true;
//-----------------------------------------------------------------------------------
// a. Analyse characters - group as syllables/clusters (Indic); invalid diacritics; add dotted circle
//-----------------------------------------------------------------------------------
$sea_category_string = '';
foreach ($this->OTLdata as $eid => $c) {
Sea::set_sea_properties($this->OTLdata[$eid], $scriptblock); // sets ['sea_category'] and ['sea_position']
//$c['general_category']
//$c['combining_class']
//$c['uni'] = $char;
$sea_category_string .= Sea::$sea_category_char[$this->OTLdata[$eid]['sea_category']];
}
$broken_syllables = false;
Sea::set_syllables($this->OTLdata, $sea_category_string, $broken_syllables);
$sea_category_string = '';
//-----------------------------------------------------------------------------------
// b. Apply locl and ccmp shaping forms - before initial re-ordering; GSUB Lookups (one at a time)
//-----------------------------------------------------------------------------------
$tags = 'locl ccmp';
$this->_applyGSUBrulesSingly($tags, $GSUBscriptTag, $GSUBlangsys);
//-----------------------------------------------------------------------------------
// c. Initial Re-ordering
//-----------------------------------------------------------------------------------
// Find base consonant
// Decompose/compose and reorder Matras
// Reorder marks to canonical order
$dottedcircle = false;
if ($broken_syllables) {
if ($this->mpdf->_charDefined($this->mpdf->fonts[$this->fontkey]['cw'], 0x25CC)) {
$dottedcircle = [];
$ucd_record = Ucdn::get_ucd_record(0x25CC);
$dottedcircle[0]['general_category'] = $ucd_record[0];
$dottedcircle[0]['bidi_type'] = $ucd_record[2];
$dottedcircle[0]['group'] = 'C';
$dottedcircle[0]['uni'] = 0x25CC;
$dottedcircle[0]['sea_category'] = Sea::OT_GB;
$dottedcircle[0]['sea_position'] = Sea::POS_BASE_C;
$dottedcircle[0]['hex'] = '025CC'; // TEMPORARY *****
}
}
Sea::initial_reordering($this->OTLdata, $this->GSUBdata[$this->GSUBfont], $broken_syllables, $scriptblock, $dottedcircle);
//-----------------------------------------------------------------------------------
// d. Apply basic shaping forms GSUB Lookups (one at a time)
//-----------------------------------------------------------------------------------
$tags = 'pref abvf blwf pstf';
$this->_applyGSUBrulesSingly($tags, $GSUBscriptTag, $GSUBlangsys);
//-----------------------------------------------------------------------------------
// e. Final Re-ordering
//-----------------------------------------------------------------------------------
Sea::final_reordering($this->OTLdata, $this->GSUBdata[$this->GSUBfont], $scriptblock);
//-----------------------------------------------------------------------------------
// f. Apply Presentation Forms GSUB Lookups (+ any discretionary)
//-----------------------------------------------------------------------------------
$tags = 'pres abvs blws psts';
$omittags = 'locl ccmp nukt akhn rphf rkrf pref blwf abvf half pstf cfar vatu cjct init medi fina isol med2 fin2 fin3 ljmo vjmo tjmo';
$usetags = $tags;
if (!empty($this->mpdf->OTLtags)) {
$usetags = $this->_applyTagSettings($tags, $GSUBFeatures, $omittags, false);
}
$this->_applyGSUBrules($usetags, $GSUBscriptTag, $GSUBlangsys);
$this->restrictToSyllable = false;
} // 5(D). GSUB - Shaper - DEFAULT (including THAI and LAO and MYANMAR v1 [mymr] and TIBETAN)
//==============================
else { // DEFAULT
//-----------------------------------------------------------------------------------
// a. First decompose/compose in Thai / Lao - Tibetan
//-----------------------------------------------------------------------------------
// Decomposition for THAI or LAO
/* This function implements the shaping logic documented here:
*
* http://linux.thai.net/~thep/th-otf/shaping.html
*
* The first shaping rule listed there is needed even if the font has Thai
* OpenType tables.
*
*
* The following is NOT specified in the MS OT Thai spec, however, it seems
* to be what Uniscribe and other engines implement. According to Eric Muller:
*
* When you have a SARA AM, decompose it in NIKHAHIT + SARA AA, *and* move the
* NIKHAHIT backwards over any tone mark (0E48-0E4B).
*
* <0E14, 0E4B, 0E33> -> <0E14, 0E4D, 0E4B, 0E32>
*
* This reordering is legit only when the NIKHAHIT comes from a SARA AM, not
* when it's there to start with. The string <0E14, 0E4B, 0E4D> is probably
* not what a user wanted, but the rendering is nevertheless nikhahit above
* chattawa.
*
* Same for Lao.
*
* Thai Lao
* SARA AM: U+0E33 U+0EB3
* SARA AA: U+0E32 U+0EB2
* Nikhahit: U+0E4D U+0ECD
*
* Testing shows that Uniscribe reorder the following marks:
* Thai: <0E31,0E34..0E37,0E47..0E4E>
* Lao: <0EB1,0EB4..0EB7,0EC7..0ECE>
*
* Lao versions are the same as Thai + 0x80.
*/
if ($this->shaper == 'T' || $this->shaper == 'L') {
for ($ptr = 0; $ptr < count($this->OTLdata); $ptr++) {
$char = $this->OTLdata[$ptr]['uni'];
if (($char & ~0x0080) == 0x0E33) { // if SARA_AM (U+0E33 or U+0EB3)
$NIKHAHIT = $char + 0x1A;
$SARA_AA = $char - 1;
$sub = [$SARA_AA, $NIKHAHIT];
$newinfo = [];
$ucd_record = Ucdn::get_ucd_record($sub[0]);
$newinfo[0]['general_category'] = $ucd_record[0];
$newinfo[0]['bidi_type'] = $ucd_record[2];
$charasstr = $this->unicode_hex($sub[0]);
if (strpos($this->GlyphClassMarks, $charasstr) !== false) {
$newinfo[0]['group'] = 'M';
} else {
$newinfo[0]['group'] = 'C';
}
$newinfo[0]['uni'] = $sub[0];
$newinfo[0]['hex'] = $charasstr;
$this->OTLdata[$ptr] = $newinfo[0]; // Substitute SARA_AM => SARA_AA
$ntones = 0; // number of (preceding) tone marks
// IS_TONE_MARK ((x) & ~0x0080, 0x0E34 - 0x0E37, 0x0E47 - 0x0E4E, 0x0E31)
while (isset($this->OTLdata[$ptr - 1 - $ntones]) && (
($this->OTLdata[$ptr - 1 - $ntones]['uni'] & ~0x0080) == 0x0E31 ||
(($this->OTLdata[$ptr - 1 - $ntones]['uni'] & ~0x0080) >= 0x0E34 &&
($this->OTLdata[$ptr - 1 - $ntones]['uni'] & ~0x0080) <= 0x0E37) ||
(($this->OTLdata[$ptr - 1 - $ntones]['uni'] & ~0x0080) >= 0x0E47 &&
($this->OTLdata[$ptr - 1 - $ntones]['uni'] & ~0x0080) <= 0x0E4E)
)
) {
$ntones++;
}
$newinfo = [];
$ucd_record = Ucdn::get_ucd_record($sub[1]);
$newinfo[0]['general_category'] = $ucd_record[0];
$newinfo[0]['bidi_type'] = $ucd_record[2];
$charasstr = $this->unicode_hex($sub[1]);
if (strpos($this->GlyphClassMarks, $charasstr) !== false) {
$newinfo[0]['group'] = 'M';
} else {
$newinfo[0]['group'] = 'C';
}
$newinfo[0]['uni'] = $sub[1];
$newinfo[0]['hex'] = $charasstr;
// Insert NIKAHIT
array_splice($this->OTLdata, $ptr - $ntones, 0, $newinfo);
$ptr++;
}
}
}
if ($scriptblock == Ucdn::SCRIPT_TIBETAN) {
// =========================
// Reordering TIBETAN
// =========================
// Tibetan does not need to need a shaper generally, as long as characters are presented in the correct order
// so we will do one minor change here:
// From ICU: If the present character is a number, and the next character is a pre-number combining mark
// then the two characters are reordered
// From MS OTL spec the following are Digit modifiers (Md): 0F18–0F19, 0F3E–0F3F
// Digits: 0F20–0F33
// On testing only 0x0F3F (pre-based mark) seems to need re-ordering
for ($ptr = 0; $ptr < count($this->OTLdata) - 1; $ptr++) {
if (Indic::in_range($this->OTLdata[$ptr]['uni'], 0x0F20, 0x0F33) && $this->OTLdata[$ptr + 1]['uni'] == 0x0F3F) {
$tmp = $this->OTLdata[$ptr + 1];
$this->OTLdata[$ptr + 1] = $this->OTLdata[$ptr];
$this->OTLdata[$ptr] = $tmp;
}
}
// =========================
// Decomposition for TIBETAN
// =========================
/* Recommended, but does not seem to change anything...
for($ptr=0; $ptr<count($this->OTLdata); $ptr++) {
$char = $this->OTLdata[$ptr]['uni'];
$sub = Indic::decompose_indic($char);
if ($sub) {
$newinfo = array();
for($i=0;$i<count($sub);$i++) {
$newinfo[$i] = array();
$ucd_record = Ucdn::get_ucd_record($sub[$i]);
$newinfo[$i]['general_category'] = $ucd_record[0];
$newinfo[$i]['bidi_type'] = $ucd_record[2];
$charasstr = $this->unicode_hex($sub[$i]);
if (strpos($this->GlyphClassMarks, $charasstr)!==false) { $newinfo[$i]['group'] = 'M'; }
else { $newinfo[$i]['group'] = 'C'; }
$newinfo[$i]['uni'] = $sub[$i];
$newinfo[$i]['hex'] = $charasstr;
}
array_splice($this->OTLdata, $ptr, 1, $newinfo);
$ptr += count($sub)-1;
}
}
*/
}
//-----------------------------------------------------------------------------------
// b. Apply all GSUB Lookups (in order specified in lookup list)
//-----------------------------------------------------------------------------------
$tags = 'locl ccmp pref blwf abvf pstf pres abvs blws psts haln rlig calt liga clig mset RQD';
// pref blwf abvf pstf required for Tibetan
// " RQD" is a non-standard tag in Garuda font - presumably intended to be used by default ? "ReQuireD"
// Being a 3 letter tag is non-standard, and does not allow it to be set by font-feature-settings
/* ?Add these until shapers witten?
Hangul: ljmo vjmo tjmo
*/
$omittags = '';
$useGSUBtags = $tags;
if (!empty($this->mpdf->OTLtags)) {
$useGSUBtags = $this->_applyTagSettings($tags, $GSUBFeatures, $omittags, false);
}
// APPLY GSUB rules (as long as not Latin + SmallCaps - but not OTL smcp)
if (!(($this->mpdf->textvar & TextVars::FC_SMALLCAPS) && $scriptblock == Ucdn::SCRIPT_LATIN && strpos($useGSUBtags, 'smcp') === false)) {
$this->_applyGSUBrules($useGSUBtags, $GSUBscriptTag, $GSUBlangsys);
}
}
}
// Shapers - KHMER & THAI & LAO - Replace Word boundary marker with U+200B
// Also TIBETAN (no shaper)
//=======================================================
if (($this->shaper == "K" || $this->shaper == "T" || $this->shaper == "L") || $scriptblock == Ucdn::SCRIPT_TIBETAN) {
// Set up properties to insert a U+200B character
$newinfo = [];
//$newinfo[0] = array('general_category' => 1, 'bidi_type' => 14, 'group' => 'S', 'uni' => 0x200B, 'hex' => '0200B');
$newinfo[0] = [
'general_category' => Ucdn::UNICODE_GENERAL_CATEGORY_FORMAT,
'bidi_type' => Ucdn::BIDI_CLASS_BN,
'group' => 'S', 'uni' => 0x200B, 'hex' => '0200B'];
// Then insert U+200B at (after) all word end boundaries
for ($i = count($this->OTLdata) - 1; $i > 0; $i--) {
// Make sure after GSUB that wordend has not been moved - check next char is not in the same syllable
if (isset($this->OTLdata[$i]['wordend']) && $this->OTLdata[$i]['wordend'] &&
isset($this->OTLdata[$i + 1]['uni']) && (!isset($this->OTLdata[$i + 1]['syllable']) || !isset($this->OTLdata[$i + 1]['syllable']) || $this->OTLdata[$i + 1]['syllable'] != $this->OTLdata[$i]['syllable'])) {
array_splice($this->OTLdata, $i + 1, 0, $newinfo);
$this->_updateLigatureMarks($i, 1);
} elseif ($this->OTLdata[$i]['uni'] == 0x2e) { // Word end if Full-stop.
array_splice($this->OTLdata, $i + 1, 0, $newinfo);
$this->_updateLigatureMarks($i, 1);
}