1module TeX 2 module Hyphen 3 module TeXLive 4 module Loader 5 6 def unicode_only? # TODO Spec out 7 ['cu', 'sa','as','bn','gu','hi','hy','kn','lo','mul-ethi','ml','mr','or','pa','ta','te', 'pi', 'rm'].include? @bcp47 8 end 9 10 def string_enc 11 (encoding == nil) ? "" : encoding.upcase + " " 12 end 13 14 def lcchars 15 if isgreek? 16 # some catcodes for XeTeX 17 return { 18 lccode: { 19 0x0027 => '\'', 20 0x2019 => '’', 21 0x02BC => 'ʼ', 22 0x1FBD => '᾽', 23 0x1FBF => '᾿', 24 } 25 } 26 end 27 28 return { } unless unicode_only? 29 30 default = { 31 comment: 'Set \lccode for ZWNJ and ZWJ.', 32 lccode: { 33 0x200C => false, 34 0x200D => false, 35 } 36 } 37 38 { 39 'mul-ethi' => { 40 comment: 'Set \lccode for Ethiopian word space.', 41 lccode: { 42 0x1361 => false, 43 0x1362 => false, 44 } 45 }, 46 'cu' => { 47 comment: 'fix lccodes for some characters (they were recently included in Unicode)', 48 lccode: { 49 0x1C82 => 'sharp o in lowercase "uk"', 50 0x1DF6 => false, 51 0x1DF7 => false, 52 0x1DF8 => false, 53 0x1DF9 => false, 54 0xA69E => false, 55 0x1C86 => false, 56 0xA67E => false, 57 0xFE2E => false, 58 0xFE2F => false, 59 } 60 }, 61 'sa' => { 62 comment: 'Set \lccode for ZWNJ and ZWJ.', 63 lccode: { 64 0x200C => false, 65 0x200D => "\n% Set \\lccode for KANNADA SIGN JIHVAMULIYA and KANNADA SIGN UPADHMANIYA.", 66 0x0CF1 => false, 67 0x0CF2 => false, 68 } 69 }, 70 }[@bcp47] || default 71 end 72 73 def utf8_engine_message 74 if serbian? 75 'UTF-8 Serbian hyphenation patterns' 76 else 77 sprintf('UTF-8 %s', message) 78 end 79 end 80 81 def non_utf8_engine_message 82 if unicode_only? 83 sprintf('No %s - only for Unicode engines', message) 84 else 85 sprintf('%s%s', string_enc, message) 86 end 87 end 88 89 def engine_message(engine) 90 if engine == 'UTF-8' 91 { 92 comment: 'Unicode-aware engine (such as XeTeX or LuaTeX) only sees a single (2-byte) argument', 93 message: utf8_engine_message 94 } 95 else # engine is 8-bit or pTeX 96 { 97 comment: engine + 98 if engine == '8-bit' then " engine (such as TeX or pdfTeX)" else "" end, 99 message: non_utf8_engine_message 100 } 101 end 102 end 103 104 def input_8bit_file 105 if @bcp47 == 'la-x-liturgic' 106 { 107 input: [pTeX_patterns] 108 } 109 elsif use_old_patterns_comment 110 # explain why we are still using the old patterns 111 { 112 comment: use_old_patterns_comment, 113 input: [legacy_patterns] 114 } 115 elsif !italic? 116 { 117 input: [sprintf('conv-utf8-%s.tex', encoding), sprintf('hyph-%s.tex', @bcp47)] 118 } 119 else 120 { 121 input: [sprintf('hyph-%s.tex', @bcp47)] 122 } 123 end 124 end 125 126 def input_utf8_line 127 if serbian? 128 { 129 comment: 'We load both scripts at the same time to simplify usage', 130 input: ['hyph-sh-latn.tex', 'hyph-sh-cyrl.tex'] 131 } 132 else 133 { 134 input: [sprintf('hyph-%s.tex', @bcp47)] 135 } 136 end 137 end 138 139 def format_inputs(specification) 140 if specification.is_a? Array 141 return specification.map do |hash| 142 format_inputs(hash) 143 end 144 end 145 146 comment = specification[:comment] 147 message = specification[:message] 148 if comment then [sprintf('%% %s', comment)] else [] end + 149 if message then [sprintf('\\message{%s}', message)] else [] end + 150 (specification[:lccode] || []).map do |code, comment| 151 sprintf '\\lccode"%04X="%04X%s', code, code, if comment then sprintf ' %% %s', comment else '' end 152 end + 153 (specification[:input] || []).map do |input| 154 sprintf '\\input %s', input 155 end 156 end 157 158 def input_line(engine) 159 if engine == '8-bit' 160 input_8bit_file 161 elsif engine == 'pTeX' 162 { input: [pTeX_patterns] } 163 elsif engine == 'UTF-8' 164 input_utf8_line 165 end 166 end 167 168 def utf8_chunk 169 [ 170 engine_message('UTF-8'), 171 # lccodes 172 lcchars, 173 input_line('UTF-8'), 174 if has_apostrophes? then { input: [sprintf('hyph-quote-%s.tex', bcp47)] } end 175 ].compact 176 end 177 178 def nonutf8_chunk(engine) 179 [engine_message(engine), unless unicode_only? then input_line(engine) end].compact 180 end 181 182 def loadhyph 183 if use_old_loader 184 legacy_patterns 185 else 186 sprintf 'loadhyph-%s.tex', @bcp47.gsub(/^sh-/, 'sr-') 187 end 188 end 189 end 190 end 191 end 192end 193