From 1661041d6a4bce0a6aaab008c010faae214e8781 Mon Sep 17 00:00:00 2001 From: anavaleije Date: Fri, 11 Nov 2011 01:53:39 +0000 Subject: [PATCH] git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@2124 8e941d3f-bd1b-0410-a28a-d453659cc2b4 --- applications/fpbrowser/mod_braille.pas | 244 ++++++++++++++++++++++++- 1 file changed, 238 insertions(+), 6 deletions(-) diff --git a/applications/fpbrowser/mod_braille.pas b/applications/fpbrowser/mod_braille.pas index ba5d6a6cc..0394dc799 100644 --- a/applications/fpbrowser/mod_braille.pas +++ b/applications/fpbrowser/mod_braille.pas @@ -25,12 +25,13 @@ type function HandleOnPageLoad(AInput: string; out AOutput: string): Boolean; override; end; -function ConvertUTF8TextToBraille(Line: string): string; +function ConvertUTF8CharToBraille(Char: string; lCharSize: integer; OrdChar: integer): string; +function ConvertUTF8TextToBraille(Text: string): string; function ConvertUTF8HtmlTextToBraille(AInput: string): string; implementation -type +{type dictionary = array[1..32] of string; const @@ -64,10 +65,10 @@ const {o + circumflex} chr($b9), {o + tilde} chr($aa), {o + diaeresis TODO} chr($80), {division sign TODO} chr($80), {o + stroke TODO} chr($80), {u + grave} chr($b1), {u + acute} chr($be), {u + circumflex TODO} chr($80), {u + diaeresis} chr($b3), - {y + acute TODO} chr($80), {thorn TODO} chr($80), {y + diaeresis TODO} chr($80)); + {y + acute TODO} chr($80), {thorn TODO} chr($80), {y + diaeresis TODO} chr($80)); } -function ConvertUTF8TextToBraille(Line: string): string; -var +{function ConvertUTF8TextToBraille(Line: string): string; +{var lCharSize, count, n, next_n, len: integer; Braille_string: string; Pline: Pchar; @@ -81,7 +82,7 @@ begin if Line = '' then Result := ''; len := length(Line); - Pline := PChar(Line); + Pline := PChar(Line); } while count <= len do begin @@ -209,6 +210,237 @@ begin Inc(Pline, lCharSize); end; Result := Braille_string; +end; } + +const + number_signal = chr($e2) + chr($a0) + chr($bc); + caps_signal = chr($e2) + chr($a0) + chr($a8); + +function ConvertUTF8CharToBraille(Char: string; lCharSize: integer; OrdChar: integer): string; + +const + aux = chr($e2) + chr($a0); + +begin + {If the character can't be found in any of the cases, write a Braille space} + Result := aux + chr($80); + case lCharSize of + 1: + begin + + case OrdChar of + 9: {\t} + Result := #9; + 10: {\n} + Result := #10; + 32: {} + Result := #32; + 33, 43: {!, +} + Result := aux + chr($96); + 34: {"} + Result := aux + chr($a6); + 36: {*$*} + Result := aux + chr($b0); + 37: {%} + Result := aux + chr($b8) + chr($e2) + chr($a0) + chr($b4); + 38: {&} + Result := aux + chr($af); + 39, 46: {', .} + Result := aux + chr($84); + 40: {(} + Result := aux + chr($a3) + chr($e2) + chr($a0) + chr($84); + 41: {)} + Result := aux + chr($a0) + chr($e2) + chr($a0) + chr($9c); + 42: {*} + Result := aux + chr($94); + 44: {,} + Result := aux + chr($82); + 45: {-} + Result := aux + chr($a4); + 47: {/} + Result := aux + chr($90) + chr($e2) + chr($a0) + chr($b2); + 48, 74, 106: {0, J, j} + Result := aux + chr($9a); + 49, 65, 97: {1, A, a} + Result := aux + chr($81); + 50, 66, 98: {2, B, b} + Result := aux + chr($83); + 51, 67, 99: {3, C, c} + Result := aux + chr($89); + 52, 68, 100: {4, D, d} + Result := aux + chr($99); + 53, 69, 101: {5, E, e} + Result := aux + chr($91); + 54, 70, 102: {6, F, f} + Result := aux + chr($8b); + 55, 71, 103: {7, G, g} + Result := aux + chr($9b); + 56, 72, 104: {8, H, h} + Result := aux + chr($93); + 57, 73, 105: {9, I, i} + Result := aux + chr($8a); + 58: {:} + Result := aux + chr($92); + 59: {;} + Result := aux + chr($86); + 60: {<} + Result := aux + chr($aa); + 61: {=} + Result := aux + chr($b6); + 63: {?} + Result := aux + chr($a2); + 75, 107: {K, k} + Result := aux + chr($85); + 76, 108: {L, l} + Result := aux + chr($87); + 77, 109: {M, m} + Result := aux + chr($8d); + 78, 110: {N, n} + Result := aux + chr($9d); + 79, 111, 62: {O, o, >} + Result := aux + chr($95); + 80, 112: {P, p} + Result := aux + chr($8f); + 81, 113: {Q, q} + Result := aux + chr($9f); + 82, 114: {R, r} + Result := aux + chr($97); + 83, 115: {S, s} + Result := aux + chr($8e); + 84, 116: {T, t} + Result := aux + chr($9e); + 85, 117: {U, u} + Result := aux + chr($a5); + 86, 118: {V, v} + Result := aux + chr($a7); + 87, 119: {W, w} + Result := aux + chr($ba); + 88, 120: {X, x} + Result := aux + chr($ad); + 89, 121: {Y, y} + Result := aux + chr($bd); + 90, 122: {Z, z} + Result := aux + chr($b5); + end; + end; + + 2: + begin + case OrdChar of + 195: {accented letter} + begin + OrdChar := Ord(Char[2]); + case OrdChar of + 128, 160: {A + grave, a + grave} + Result := aux + chr($ab); + 129, 161: {A + acute, a + acute} + Result := aux + chr($b7); + 130, 162: {A + circumflex, a + circumflex} + Result := aux + chr($a1); + 131, 163: {A + tilde, a + tilde} + Result := aux + chr($9c); + 135, 167: {C + cedilla, c + cedilla} + Result := aux + chr($af); + 136, 168: {E + grave, e + grave} + Result := aux + chr($ae); + 137, 169: {E + acute, e + acute} + Result := aux + chr($bf); + 138, 170: {E + circumflex, e + circumflex} + Result := aux + chr($a3); + 140, 172: {I + grave, i + grave} + Result := aux + chr($a9); + 141, 173: {I + acute, i + acute} + Result := aux + chr($8c); + 143, 175: {I + diaresis, i + diaresis} + Result := aux + chr($bb); + 146, 178: {O + grave, o + grave} + Result := aux + chr($ba); + 147, 179: {O + acute, o + acute} + Result := aux + chr($ac); + 148, 180: {O + circumflex, o + circumflex} + Result := aux + chr($b9); + 149, 181: {O + tilde, o + tilde} + Result := aux + chr($aa); + 153, 185: {U + grave, u + grave} + Result := aux + chr($b1); + 154, 186: {U + acute, u + acute} + Result := aux + chr($be); + 156, 188: {U + diaeresis, u + diaeresis} + Result := aux + chr($b3); + end; + end; + end; + end; + end; +end; + +function ConvertUTF8TextToBraille(Text:string): string; +var + lCharSize, TextSize, i, OrdChar, nextOrdChar: integer; + Braille_string: string; + PText: Pchar; + IsNum: boolean; + +begin + Braille_string := ''; + IsNum := False; + if Text = '' then Result := ''; + TextSize := Length(Text); + PText := PChar(Text); + + i := 1; + + while i <= TextSize do + begin + + lCharSize := LCLProc.UTF8CharacterLength(PText); + OrdChar := Ord(Text[i]); + case lCharSize of + 1: + begin + case OrdChar of + 48..57: {a number} + begin + if not IsNum then + begin + Braille_string := Braille_string + number_signal; {first algarism of a number, add a number signal} + IsNum := True + end; + + if (i + 1 <= TextSize) then + begin + nextOrdChar := Ord(Text[i + 1]); + if not ((nextOrdChar >= 48) and (nextOrdChar <= 57) or (nextOrdChar = 44) or (nextOrdChar = 46)) then IsNum := False; {the next char is not a number, nor ',', nor '.', then unflag } + end; + + end; + + 65..90: {Upper case letter, add a caps_signal} + Braille_string := Braille_string + caps_signal; + + end; + + Braille_string := Braille_string + ConvertUTF8CharToBraille(Text[i], 1, OrdChar); + i := i + 1; + + end; + 2: + begin + nextOrdChar := Ord(Text[i+1]); + + case nextOrdChar of + {Accented upper case letter, add a caps_signal} + 128..159: + Braille_string := Braille_string + caps_signal; + end; + + Braille_string := Braille_string + ConvertUTF8CharToBraille(copy(Text,i,2), 2, OrdChar); + i := i + 2; + end; + end; + Inc(PText, lCharSize); + end; + Result := Braille_string; end; function ConvertUTF8HtmlTextToBraille(AInput: string): string;