#-index-name: Khmer
#-display-name: Khmer braille
#
#+language: km
#+type: literary
#+contraction: no
#+grade: 1
#+dots: 6
#+direction: both
#+system: cambodia
#
#-copyright: Sao Mai Center for the Blind <www.saomaicenter.org/en>
#-license: LGPLv2.1
#
#  Copyright (C) 2018 by Sao Mai Center for the Blind <www.saomaicenter.org/en>
#
#  This file is part of liblouis.
#
#  liblouis is free software: you can redistribute it and/or modify it
#  under the terms of the GNU Lesser General Public License as
#  published by the Free Software Foundation, either version 2.1 of the
#  License, or (at your option) any later version.
#
#  liblouis is distributed in the hope that it will be useful, but
#  WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
#  Lesser General Public License for more details.
#
#  You should have received a copy of the GNU Lesser General Public
#  License along with liblouis. If not, see
#  <http://www.gnu.org/licenses/>.
#
# Created and maintained by: Dang Hoai Phuc <danghoaiphuc@gmail.com>
# with help from Khemara Ly from Myanmar
#
#-author: Dang Hoai Phúc <danghoaiphuc@gmail.com>
#-maintainer: Dang Hoai Phuc <danghoaiphuc@gmail.com>
#
#-updated: 2020-11-17
#
# Based on <http://liblouis.io/braille-specs/khmer>

space \s 0 blank
space \t 9 tab
space \x000a 0 newline
space \x000c 0
space \x000d 0 carriage return
space \x001b 1b escape character for html back-translation
space \x00A0 a NO-BREAK SPACE <noBreak> 0020 NON-BREAKING SPACE 
#space \x200b 0

# latin letters
lowercase a 1
lowercase b 12
lowercase c 14
lowercase d 145
lowercase e 15
lowercase f 124
lowercase g 1245
lowercase h 125
lowercase i 24
lowercase j 245
lowercase k 13
lowercase l 123
lowercase m 134
lowercase n 1345
lowercase o 135
lowercase p 1234
lowercase q 12345
lowercase r 1235
lowercase s 234
lowercase t 2345
lowercase u 136
lowercase v 1236
lowercase w 2456
lowercase x 1346
lowercase y 13456
lowercase z 1356

base uppercase A a
base uppercase B b
base uppercase C c
base uppercase D d
base uppercase E e
base uppercase F f
base uppercase G g
base uppercase H h
base uppercase I i
base uppercase J j
base uppercase K k
base uppercase L l
base uppercase M m
base uppercase N n
base uppercase O o
base uppercase P p
base uppercase Q q
base uppercase R r
base uppercase S s
base uppercase T t
base uppercase U u
base uppercase V v
base uppercase W w
base uppercase X x
base uppercase Y y
base uppercase Z z

# numbers definition
display 0 356
display 1 2
display 2 23
display 3 25
display 4 256
display 5 26
display 6 235
display 7 2356
display 8 236
display 9 35
digit 0 245
digit 1 1
digit 2 12
digit 3 14
digit 4 145
digit 5 15
digit 6 124
digit 7 1245
digit 8 125
digit 9 24
digit \x17e0 245
digit \x17e1 1
digit \x17e2 12
digit \x17e3 14
digit \x17e4 145
digit \x17e5 15
digit \x17e6 124
digit \x17e7 1245
digit \x17e8 125
digit \x17e9 24

litdigit 0 245
litdigit 1 1
litdigit 2 12
litdigit 3 14
litdigit 4 145
litdigit 5 15
litdigit 6 124
litdigit 7 1245
litdigit 8 125
litdigit 9 24
litdigit \x17e0 245
litdigit \x17e1 1
litdigit \x17e2 12
litdigit \x17e3 14
litdigit \x17e4 145
litdigit \x17e5 15
litdigit \x17e6 124
litdigit \x17e7 1245
litdigit \x17e8 125
litdigit \x17e9 24
# signs and punctuations definition
display ! 2346
punctuation ! 235
display " 5
punctuation " 236
#prepunc " 236
#postpunc " 356
display ? 1456
punctuation ? 236
match %[^_~]%<* " %[_.$]*%[a#] 236
match %[a#]%[_.$]* " %>*%[^_~] 356

display # 3456
sign # 3456
display $ 1246
sign $ 4-234
display % 146
sign % 4-356
math % 3456-245-356
display & 12346
sign & 4-12346
punctuation ' 3
display ( 12356
punctuation ( 2356
display ) 23456
punctuation ) 2356
display * 16
sign * 5-236
display + 346
math + 5-235
display , 6
punctuation , 6
punctuation - 36
math - 5-36
hyphen - 36
display . 46
punctuation . 256
#decpoint . 3
display / 34
sign / 34
math / 5-34
punctuation / 34
#display : 156
#punctuation : 45
display ; 56
punctuation ; 23
display < 126
math < 5-246
display = 123456
math = 5-2356
display > 345
punctuation > 5-135
display @ 47
sign @ 4

display [ 2467
punctuation [ 46-126
display \\ 12567
sign \\ 4-16
display ] 124567
punctuation ] 46-345
display ^ 45
sign ^ 4-26
display : 156
punctuation : 45
display _ 456
sign _ 4-456
display ` 4
sign ` 4-4 grave accent

display } 12456
punctuation } 456-345
display | 1256
sign | 456-1256
display { 246
punctuation { 456-126
display ~ 45
math ~ 4-35
punctuation \x17D4 123456
punctuation \x201C 236
punctuation \x201D 356

include braille-patterns.cti



# two special cases, not put v infront of subscript consonants
#match - \x17D2\x178B - 36-23456
#match - \x17D2\x178D - 356-23456
# letters with two character codes for each, all are from dependent vowels
match - \x17BB\x17C6 - 1246
match - \x17B6\x17C6 - 1356
match - \x17BB\x17C7 - 1346
match - \x17C1\x17C7 - 136
match - \x17C4\x17C7 - 2346	
# add v subscript for consonants
letter \x17D2 1236
# if o in print before 4 vowels below, should be placed after these 4 vowels
match - \x17A2\x17BE - 146-135
#match - \x17A2\x17C1 - 124-135
noback pass2 @135-124 @124-135
match - \x17A2\x17C2 - 126-135
match - \x17A2\x17C3 - 24-135
# regular consonants Dot pattern for regular consonants
letter \x1780 1245
letter \x1781 13
#letter \x1782 6-1245
letter គ 6-1245
letter \x1783 6-13
letter \x1784 12456
letter \x1785 245
letter \x1786 346
letter \x1787 6-245
letter \x1788 6-346
letter \x1789 6-1456
letter \x178A 145
letter \x178B 36-23456
letter \x178C 6-145
letter \x178D 356-23456
letter \x178E 1345
letter \x178F 2345
letter \x1790 23456
letter \x1791 6-2345
letter \x1792 6-23456
letter \x1793 6-1345
letter \x1794 12
letter \x1795 1234
letter \x1796 12346
letter \x1797 6-1234
letter \x1798 134
letter \x1799 6-13456
letter \x179A 1235
letter \x179B 6-123
letter \x179C 2456
letter \x179F 234
letter \x17A0 125
letter \x17A1 123
letter \x17A2 135
# independent vowels #Dot patern for independent vowels
letter \x17A5 6-34
letter \x17A6 15-1
letter \x17A7 14-1
#letter \x17A8 
letter \x17A9 6-25
letter \x17AA 1256
letter \x17B3 456-14
letter \x17AB 6-1346
letter \x17AC 1346-1
letter \x17AD 1456
letter \x17AE 1456-1
letter \x17AF 5
letter \x17B0 124-1
letter \x17B1 156-1
letter \x17B2 156-1
#dependent vowels	# Dot paterns for dependent vowels
letter	\x17B6	16
letter	\x17B7	34
letter	\x17B8	15
letter	\x17B9	246
letter	\x17BA	26
letter	\x17BB	14
letter	\x17BC	25
letter	\x17BD	23
letter	\x17BE	146
letter	\x17BF	12345
letter	\x17C0	12356
letter	\x17C1	124
letter	\x17C2	126
letter	\x17C3	24
letter	\x17C4	156
letter	\x17C5	456
#letter	\x17BB\x17C6	1246
letter	\x17C6	13456
#letter	\x17B6\x17C6	1356
letter	\x17C7	1
#letter	\x17BB\x17C7	1346
#letter	\x17C1\x17C7	136
#letter	\x17C4\x17C7	2346
#additional letters not found on wiki page
letter \x17CB 35
letter \x17d0 345
letter \x17c8 45
letter \x17c9 4
letter \x17cf 3
letter \x17cd 356
letter \x17ca 36
letter \x17d7 2
letter \x17cc 2356
letter \x200c 16-5-13		

numsign 3456
letsign 56
capsletter 6
begcapsword 6-6
endcapsword 6-3
lencapsphrase 3
begcapsphrase 6-6-6
begcaps 6-6-6
endcaps 6-3

# time processing with : as saperator sign
noback match %# :0 %# 45-245
noback match %# :1 %# 45-1
noback match %# :2 %# 45-12
noback match %# :3 %# 45-14
noback match %# :4 %# 45-145
noback match %# :5 %# 45-15
noback match %# '0 %# 3-245
noback match %# '1 %# 3-1
noback match %# '2 %# 3-12
noback match %# '3 %# 3-14
noback match %# '4 %# 3-145
noback match %# '5 %# 3-15
# unknown character
replace \x200b
# add space between digits and letters
#noback correct $d$l "\s"
#noback context $d[$l] @0*
noback pass2 @245-56 @245-0
noback pass2 @1-56 @1-0
noback pass2 @12-56 @12-0
noback pass2 @14-56 @14-0
noback pass2 @145-56 @145-0
noback pass2 @15-56 @15-0
noback pass2 @124-56 @124-0
noback pass2 @1245-56 @1245-0
noback pass2 @125-56 @125-0
noback pass2 @24-56 @24-0

# moving vowels and subscript consonants to before dependent consonants
attribute consonant \x1780\x1781\x1782\x1783\x1784\x1785\x1786\x1787\x1788\x1789\x178A\x178B\x178C\x178D\x178E\x178F\x1790\x1791\x1792\x1793\x1794\x1795\x1796\x1797\x1798\x1799\x179A\x179B\x179C\x179F\x17A0\x17A1\x17A2
# place vowels before subscripted and dependent consonants
noback correct [%consonant]"\x17D2\x179A\x17BE" "\x17BE\x17D2\x179A"*
noback correct [%consonant]"\x17D2\x179A\x17C1" "\x17C1\x17D2\x179A"*
noback correct [%consonant]"\x17D2\x179A\x17C2" "\x17C2\x17D2\x179A"*
noback correct [%consonant]"\x17D2\x179A\x17C3" "\x17C3\x17D2\x179A"*
# place vowels before consonants
noback correct [%consonant]"\x17BE" "\x17BE"*
noback correct [%consonant]"\x17C1" "\x17C1"*
noback correct [%consonant]"\x17C2" "\x17C2"*
noback correct [%consonant]"\x17C3" "\x17C3"*

noback correct [%consonant"\x17d2"%consonant]"\x17BE" "\x17BE"*
noback correct [%consonant"\x17d2"%consonant]"\x17C1" "\x17C1"*
noback correct [%consonant"\x17d2"%consonant]"\x17C2" "\x17C2"*
noback correct [%consonant"\x17d2"%consonant]"\x17C3" "\x17C3"*



noback correct [%consonant]"\x17D2\x179A" "\x17D2\x179A"*

#class vowelbefore \x17C1\x17C2\x17C3\x17BE
#noback context "\x17D2\x179A"[%consonant]"\x17BE" ?
#"\x17BE\x17D2\x179A"*
