You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

514 lines
13KB

  1. <?php
  2. /*
  3. mPDF recognises IETF language tags as:
  4. - a single primary language subtag composed of a two letter language code from ISO 639-1 (2002), or a three letter code from ISO 639-2 (1998), ISO 639-3 (2007) or ISO 639-5 (2008) (usually written in lower case);
  5. - an optional script subtag, composed of a four letter script code from ISO 15924 (usually written in title case);
  6. - an optional region subtag composed of a two letter country code from ISO 3166-1 alpha-2 (usually written in upper case), or a three digit code from UN M.49 for geographical regions;
  7. Subtags are not case sensitive, but the specification recommends using the same case as in the Language Subtag Registry, where region subtags are uppercase, script subtags are titlecase and all other subtags are lowercase.
  8. Region subtags are often deprecated by the registration of specific primary language subtags from ISO 639-3 which are now "preferred values". For example, "ar-DZ" is deprecated with the preferred value "arq" for Algerian Spoken Arabic;
  9. Example: Serbian written in the Cyrillic (sr-Cyrl) or Latin (sr-Latn) script
  10. und (for undetermined or undefined) is used in situations in which a script must be indicated but the language cannot be identified.
  11. e.g. und-Cyrl is an undefined language written in Cyrillic script.
  12. */
  13. function GetLangOpts($llcc, $adobeCJK, &$fontdata)
  14. {
  15. $tags = preg_split('/-/', $llcc);
  16. $lang = strtolower($tags[0]);
  17. $country = '';
  18. $script = '';
  19. if (isset($tags[1]) && $tags[1]) {
  20. if (strlen($tags[1]) == 4) {
  21. $script = strtolower($tags[1]);
  22. } else {
  23. $country = strtolower($tags[1]);
  24. }
  25. }
  26. if (isset($tags[2]) && $tags[2]) {
  27. $country = strtolower($tags[2]);
  28. }
  29. $unifont = "";
  30. $coreSuitable = false;
  31. switch ($lang) {
  32. /* European */
  33. CASE "en": CASE "eng": // English // LATIN
  34. CASE "eu": CASE "eus": // Basque
  35. CASE "br": CASE "bre": // Breton
  36. CASE "ca": CASE "cat": // Catalan
  37. CASE "co": CASE "cos": // Corsican
  38. CASE "kw": CASE "cor": // Cornish
  39. CASE "cy": CASE "cym": // Welsh
  40. CASE "cs": CASE "ces": // Czech
  41. CASE "da": CASE "dan": // Danish
  42. CASE "nl": CASE "nld": // Dutch
  43. CASE "et": CASE "est": // Estonian
  44. CASE "fo": CASE "fao": // Faroese
  45. CASE "fi": CASE "fin": // Finnish
  46. CASE "fr": CASE "fra": // French
  47. CASE "gl": CASE "glg": // Galician
  48. CASE "de": CASE "deu": // German
  49. CASE "ht": CASE "hat": // Haitian; Haitian Creole
  50. CASE "hu": CASE "hun": // Hungarian
  51. CASE "ga": CASE "gle": // Irish
  52. CASE "is": CASE "isl": // Icelandic
  53. CASE "it": CASE "ita": // Italian
  54. CASE "la": CASE "lat": // Latin
  55. CASE "lb": CASE "ltz": // Luxembourgish
  56. CASE "li": CASE "lim": // Limburgish
  57. CASE "lt": CASE "lit": // Lithuanian
  58. CASE "lv": CASE "lav": // Latvian
  59. CASE "gv": CASE "glv": // Manx
  60. CASE "no": CASE "nor": // Norwegian
  61. CASE "nn": CASE "nno": // Norwegian Nynorsk
  62. CASE "nb": CASE "nob": // Norwegian Bokmål
  63. CASE "pl": CASE "pol": // Polish
  64. CASE "pt": CASE "por": // Portuguese
  65. CASE "ro": CASE "ron": // Romanian
  66. CASE "gd": CASE "gla": // Scottish Gaelic
  67. CASE "es": CASE "spa": // Spanish
  68. CASE "sv": CASE "swe": // Swedish
  69. CASE "sl": CASE "slv": // Slovene
  70. CASE "sk": CASE "slk": // Slovak
  71. $unifont = "dejavusanscondensed";
  72. // Edit this value to define how mPDF behaves when using new mPDF('-x')
  73. // If set to TRUE, mPDF will use Adobe core fonts only when it recognises the languages above
  74. $coreSuitable = true;
  75. break;
  76. CASE "ru": CASE "rus": // Russian // CYRILLIC
  77. CASE "ab": CASE "abk": // Abkhaz
  78. CASE "av": CASE "ava": // Avaric
  79. CASE "ba": CASE "bak": // Bashkir
  80. CASE "be": CASE "bel": // Belarusian
  81. CASE "bg": CASE "bul": // Bulgarian
  82. CASE "ce": CASE "che": // Chechen
  83. CASE "cv": CASE "chv": // Chuvash
  84. CASE "kk": CASE "kaz": // Kazakh
  85. CASE "kv": CASE "kom": // Komi
  86. CASE "ky": CASE "kir": // Kyrgyz
  87. CASE "mk": CASE "mkd": // Macedonian
  88. CASE "cu": CASE "chu": // Old Church Slavonic
  89. CASE "os": CASE "oss": // Ossetian
  90. CASE "sr": CASE "srp": // Serbian
  91. CASE "tg": CASE "tgk": // Tajik
  92. CASE "tt": CASE "tat": // Tatar
  93. CASE "tk": CASE "tuk": // Turkmen
  94. CASE "uk": CASE "ukr": // Ukrainian
  95. $unifont = "dejavusanscondensed"; /* freeserif best coverage for supplements etc. */
  96. break;
  97. CASE "hy": CASE "hye": // ARMENIAN
  98. $unifont = "dejavusans";
  99. break;
  100. CASE "ka": CASE "kat": // GEORGIAN
  101. $unifont = "dejavusans";
  102. break;
  103. CASE "el": CASE "ell": // GREEK
  104. $unifont = "dejavusanscondensed";
  105. break;
  106. CASE "cop": // COPTIC
  107. $unifont = "quivira";
  108. break;
  109. CASE "got": // GOTHIC
  110. $unifont = "freeserif";
  111. break;
  112. /* African */
  113. CASE "nqo": // NKO
  114. $unifont = "dejavusans";
  115. break;
  116. //CASE "bax": // BAMUM
  117. //CASE "ha": CASE "hau": // Hausa
  118. CASE "vai": // VAI
  119. $unifont = "freesans";
  120. break;
  121. CASE "am": CASE "amh": // Amharic ETHIOPIC
  122. CASE "ti": CASE "tir": // Tigrinya ETHIOPIC
  123. $unifont = "abyssinicasil";
  124. break;
  125. /* Middle Eastern */
  126. CASE "ar": CASE "ara": // Arabic NB Arabic text identified by Autofont will be marked as und-Arab
  127. $unifont = "xbriyaz";
  128. break;
  129. CASE "fa": CASE "fas": // Persian (Farsi)
  130. $unifont = "xbriyaz";
  131. break;
  132. CASE "ps": CASE "pus": // Pashto
  133. $unifont = "xbriyaz";
  134. break;
  135. CASE "ku": CASE "kur": // Kurdish
  136. $unifont = "xbriyaz";
  137. break;
  138. CASE "ur": CASE "urd": // Urdu
  139. $unifont = "xbriyaz";
  140. break;
  141. CASE "he": CASE "heb": // HEBREW
  142. CASE "yi": CASE "yid": // Yiddish
  143. $unifont = "taameydavidclm"; // dejavusans,dejavusanscondensed,freeserif are fine if you do not need cantillation marks
  144. break;
  145. CASE "syr": // SYRIAC
  146. $unifont = "estrangeloedessa";
  147. break;
  148. //CASE "arc": // IMPERIAL_ARAMAIC
  149. //CASE ""ae: // AVESTAN
  150. CASE "xcr": // CARIAN
  151. $unifont = "aegean";
  152. break;
  153. CASE "xlc": // LYCIAN
  154. $unifont = "aegean";
  155. break;
  156. CASE "xld": // LYDIAN
  157. $unifont = "aegean";
  158. break;
  159. //CASE "mid": // MANDAIC
  160. //CASE "peo": // OLD_PERSIAN
  161. CASE "phn": // PHOENICIAN
  162. $unifont = "aegean";
  163. break;
  164. //CASE "smp": // SAMARITAN
  165. CASE "uga": // UGARITIC
  166. $unifont = "aegean";
  167. break;
  168. /* Central Asian */
  169. CASE "bo": CASE "bod": // TIBETAN
  170. CASE "dz": CASE "dzo": // Dzongkha
  171. $unifont = "jomolhari";
  172. break;
  173. //CASE "mn": CASE "mon": // MONGOLIAN (Vertical script)
  174. //CASE "ug": CASE "uig": // Uyghur
  175. //CASE "uz": CASE "uzb": // Uzbek
  176. //CASE "az": CASE "azb": // South Azerbaijani
  177. /* South Asian */
  178. CASE "as": CASE "asm": // Assamese
  179. $unifont = "freeserif";
  180. break;
  181. CASE "bn": CASE "ben": // BENGALI; Bangla
  182. $unifont = "freeserif";
  183. break;
  184. CASE "ks": CASE "kas": // Kashmiri
  185. $unifont = "freeserif";
  186. break;
  187. CASE "hi": CASE "hin": // Hindi DEVANAGARI
  188. CASE "bh": CASE "bih": // Bihari (Bhojpuri, Magahi, and Maithili)
  189. CASE "sa": CASE "san": // Sanskrit
  190. $unifont = "freeserif";
  191. break;
  192. CASE "gu": CASE "guj": // Gujarati
  193. $unifont = "freeserif";
  194. break;
  195. CASE "pa": CASE "pan": // Panjabi, Punjabi GURMUKHI
  196. $unifont = "freeserif";
  197. break;
  198. CASE "kn": CASE "kan": // Kannada
  199. $unifont = "lohitkannada";
  200. break;
  201. CASE "mr": CASE "mar": // Marathi
  202. $unifont = "freeserif";
  203. break;
  204. CASE "ml": CASE "mal": // MALAYALAM
  205. $unifont = "freeserif";
  206. break;
  207. CASE "ne": CASE "nep": // Nepali
  208. $unifont = "freeserif";
  209. break;
  210. CASE "or": CASE "ori": // ORIYA
  211. $unifont = "freeserif";
  212. break;
  213. CASE "si": CASE "sin": // SINHALA
  214. $unifont = "kaputaunicode";
  215. break;
  216. CASE "ta": CASE "tam": // TAMIL
  217. $unifont = "freeserif";
  218. break;
  219. CASE "te": CASE "tel": // TELUGU
  220. $unifont = "pothana2000";
  221. break;
  222. // Sindhi (Arabic or Devanagari)
  223. CASE "sd": CASE "snd": // Sindhi
  224. if ($country == "IN") {
  225. $unifont = "freeserif";
  226. } else if ($country == "PK") {
  227. $unifont = "lateef";
  228. } else {
  229. $unifont = "lateef";
  230. }
  231. break;
  232. //CASE "ccp": // CHAKMA
  233. //CASE "lep": // LEPCHA
  234. CASE "lif": // LIMBU
  235. $unifont = "sun-exta";
  236. break;
  237. //CASE "sat": // OL_CHIKI
  238. //CASE "saz": // SAURASHTRA
  239. CASE "syl": // SYLOTI_NAGRI
  240. $unifont = "mph2bdamase";
  241. break;
  242. //CASE "dgo": // TAKRI
  243. CASE "dv": CASE "div": // Divehi; Maldivian THAANA
  244. $unifont = "freeserif";
  245. break;
  246. /* South East Asian */
  247. CASE "km": CASE "khm": // KHMER
  248. $unifont = "khmeros";
  249. break;
  250. CASE "lo": CASE "lao": // LAO
  251. $unifont = "dhyana";
  252. break;
  253. CASE "my": CASE "mya": // MYANMAR Burmese
  254. $unifont = "tharlon"; // zawgyi-one is non-unicode compliant but in wide usage
  255. // ayar is also not strictly compliant
  256. // padaukbook is unicode compliant
  257. break;
  258. CASE "th": CASE "tha": // THAI
  259. $unifont = "garuda";
  260. break;
  261. // VIETNAMESE
  262. CASE "vi": CASE "vie": // Vietnamese
  263. $unifont = "dejavusanscondensed";
  264. break;
  265. //CASE "ms": CASE "msa": // Malay
  266. //CASE "ban": // BALINESE
  267. //CASE "bya": // BATAK
  268. CASE "bug": // BUGINESE
  269. $unifont = "freeserif";
  270. break;
  271. //CASE "cjm": // CHAM
  272. //CASE "jv": // JAVANESE
  273. CASE "su": // SUNDANESE
  274. $unifont = "sundaneseunicode";
  275. break;
  276. CASE "tdd": // TAI_LE
  277. $unifont = "tharlon";
  278. break;
  279. CASE "blt": // TAI_VIET
  280. $unifont = "taiheritagepro";
  281. break;
  282. /* Phillipine */
  283. CASE "bku": // BUHID
  284. $unifont = "quivira";
  285. break;
  286. CASE "hnn": // HANUNOO
  287. $unifont = "quivira";
  288. break;
  289. CASE "tl": // TAGALOG
  290. $unifont = "quivira";
  291. break;
  292. CASE "tbw": // TAGBANWA
  293. $unifont = "quivira";
  294. break;
  295. /* East Asian */
  296. CASE "zh": CASE "zho": // Chinese
  297. if ($country == "HK" || $country == "TW") {
  298. if ($adobeCJK) {
  299. $unifont = "big5";
  300. } else {
  301. $unifont = "sun-exta";
  302. }
  303. } else if ($country == "CN") {
  304. if ($adobeCJK) {
  305. $unifont = "gb";
  306. } else {
  307. $unifont = "sun-exta";
  308. }
  309. } else {
  310. if ($adobeCJK) {
  311. $unifont = "gb";
  312. } else {
  313. $unifont = "sun-exta";
  314. }
  315. }
  316. break;
  317. CASE "ko": CASE "kor": // HANGUL Korean
  318. if ($adobeCJK) {
  319. $unifont = "uhc";
  320. } else {
  321. $unifont = "unbatang";
  322. }
  323. break;
  324. CASE "ja": CASE "jpn": // Japanese HIRAGANA KATAKANA
  325. if ($adobeCJK) {
  326. $unifont = "sjis";
  327. } else {
  328. $unifont = "sun-exta";
  329. }
  330. break;
  331. CASE "ii": CASE "iii": // Nuosu; Yi
  332. if ($adobeCJK) {
  333. $unifont = "gb";
  334. } else {
  335. $unifont = "sun-exta";
  336. }
  337. CASE "lis": // LISU
  338. $unifont = "quivira";
  339. break;
  340. /* American */
  341. CASE "chr": // CHEROKEE
  342. CASE "oj": CASE "oji": // Ojibwe; Chippewa
  343. CASE "cr": CASE "cre": // Cree CANADIAN_ABORIGINAL
  344. CASE "iu": CASE "iku": // Inuktitut
  345. $unifont = "aboriginalsans";
  346. break;
  347. /* Undetermined language - script used */
  348. CASE "und":
  349. switch ($script) {
  350. /* European */
  351. CASE "latn": // LATIN
  352. $unifont = "dejavusanscondensed";
  353. break;
  354. CASE "cyrl": // CYRILLIC
  355. $unifont = "dejavusanscondensed"; /* freeserif best coverage for supplements etc. */
  356. break;
  357. CASE "cprt": // CYPRIOT
  358. $unifont = "aegean";
  359. break;
  360. CASE "glag": // GLAGOLITIC
  361. $unifont = "mph2bdamase";
  362. break;
  363. CASE "linb": // LINEAR_B
  364. $unifont = "aegean";
  365. break;
  366. CASE "ogam": // OGHAM
  367. $unifont = "dejavusans";
  368. break;
  369. CASE "ital": // OLD_ITALIC
  370. $unifont = "aegean";
  371. break;
  372. CASE "runr": // RUNIC
  373. $unifont = "sun-exta";
  374. break;
  375. CASE "shaw": // SHAVIAN
  376. $unifont = "mph2bdamase";
  377. break;
  378. /* African */
  379. CASE "egyp": // EGYPTIAN_HIEROGLYPHS
  380. $unifont = "aegyptus";
  381. break;
  382. CASE "ethi": // ETHIOPIC
  383. $unifont = "abyssinicasil";
  384. break;
  385. //CASE "merc": // MEROITIC_CURSIVE
  386. //CASE "mero": // MEROITIC_HIEROGLYPHS
  387. CASE "osma": // OSMANYA
  388. $unifont = "mph2bdamase";
  389. break;
  390. CASE "tfng": // TIFINAGH
  391. $unifont = "dejavusans";
  392. break;
  393. /* Middle Eastern */
  394. CASE "arab": // ARABIC
  395. $unifont = "xbriyaz";
  396. break;
  397. CASE "xsux": // CUNEIFORM
  398. $unifont = "akkadian";
  399. break;
  400. //CASE "sarb": // OLD_SOUTH_ARABIAN
  401. //CASE "prti": // INSCRIPTIONAL_PARTHIAN
  402. //CASE "phli": // INSCRIPTIONAL_PAHLAVI
  403. /* Central Asian */
  404. //CASE "orkh": // OLD_TURKIC
  405. //CASE "phag": // PHAGS_PA (Vertical script)
  406. /* South Asian */
  407. //CASE "brah": // BRAHMI
  408. //CASE "kthi": // KAITHI
  409. CASE "khar": // KHAROSHTHI
  410. $unifont = "mph2bdamase";
  411. break;
  412. CASE "mtei": // MEETEI_MAYEK
  413. $unifont = "eeyekunicode";
  414. break;
  415. //CASE "shrd": // SHARADA
  416. //CASE "sora": // SORA_SOMPENG
  417. /* South East Asian */
  418. CASE "kali": // KAYAH_LI
  419. $unifont = "freemono";
  420. break;
  421. //CASE "rjng": // REJANG
  422. CASE "lana": // TAI_THAM
  423. $unifont = "lannaalif";
  424. break;
  425. CASE "talu": // NEW_TAI_LUE
  426. $unifont = "daibannasilbook";
  427. break;
  428. /* East Asian */
  429. CASE "hans": // HAN (SIMPLIFIED)
  430. if ($adobeCJK) {
  431. $unifont = "gb";
  432. } else {
  433. $unifont = "sun-exta";
  434. }
  435. break;
  436. CASE "bopo": // BOPOMOFO
  437. $unifont = "sun-exta";
  438. break;
  439. //CASE "plrd": // MIAO
  440. CASE "yiii": // YI
  441. $unifont = "sun-exta";
  442. break;
  443. /* American */
  444. CASE "dsrt": // DESERET
  445. $unifont = "mph2bdamase";
  446. break;
  447. /* Other */
  448. CASE "brai": // BRAILLE
  449. $unifont = "dejavusans";
  450. break;
  451. } // endswitch
  452. break;
  453. } // endswitch
  454. return array($coreSuitable, $unifont);
  455. }