gegl_utils.pas 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  1. {
  2. * Copyright (c) 2021 SSW
  3. *
  4. * This software is provided 'as-is', without any express or
  5. * implied warranty. In no event will the authors be held
  6. * liable for any damages arising from the use of this software.
  7. *
  8. * Permission is granted to anyone to use this software for any purpose,
  9. * including commercial applications, and to alter it and redistribute
  10. * it freely, subject to the following restrictions:
  11. *
  12. * 1. The origin of this software must not be misrepresented;
  13. * you must not claim that you wrote the original software.
  14. * If you use this software in a product, an acknowledgment
  15. * in the product documentation would be appreciated but
  16. * is not required.
  17. *
  18. * 2. Altered source versions must be plainly marked as such,
  19. * and must not be misrepresented as being the original software.
  20. *
  21. * 3. This notice may not be removed or altered from any
  22. * source distribution.
  23. }
  24. unit gegl_utils;
  25. {$I zgl_config.cfg}
  26. interface
  27. var
  28. // Rus: глобальная строка, для любого использования. Удобно для использования
  29. // для загрузки разных ресурсов.
  30. // Eng: global string, for any use. Convenient to use to load different
  31. // resources.
  32. LoadText: UTF8String;
  33. // Rus: флаг, показывающий, занята глобальная строка или нет. Вы должны его
  34. // включать если загрузили ресурс и отключать, когда больше этот ресурс
  35. // не нужен. И желательно освобождать строку полностью.
  36. // Eng: a flag indicating whether the global string is occupied or not. You
  37. // must enable it when you have loaded a resource and disable it when
  38. // the resource is no longer needed. And it is desirable to release the
  39. // line completely.
  40. fLoadTextClearing: Boolean = True;
  41. {$IfDef DELPHI7_AND_DOWN}
  42. // Delphi 7 and down - UTF8. Rus only.
  43. function AnsiToUtf8(text: AnsiString): UTF8String;
  44. function ByteToUtf8Rus(myByte: Byte): UTF8String;
  45. {$EndIf}
  46. // Rus: переводим клавиатурные коды в русскую символику. Для других языков, надо
  47. // свою функцию делать. И знать клавиатурную раскладку.
  48. // Eng: we translate keyboard codes into Russian symbols. For other languages,
  49. // you need to do your own function. It is imperative to know the keyboard
  50. // layout for this language.
  51. procedure EngToRus(var symb: LongWord);
  52. // Rus: то же самое что и EngToRus, но только переводим в Unicode.
  53. // Eng: the same as EngToRus, but only translated into Unicode.
  54. procedure EngToRusUnicode(var symb: LongWord);
  55. // Rus: установка значения флага для глобальной загружаемой строки. Указываем
  56. // что строка занята или свободна. Если освобождаем, то строка очистится.
  57. // Eng: setting the flag value for the global load string. Indicate that the
  58. // line is busy or free. If we release, the line will be cleared.
  59. procedure set_FlagForLoadText(flag: Boolean); {$IfDef USE_INLINE}inline;{$EndIf}
  60. // Rus: возвращаем значение флага для глобальной строки. Занята строка или
  61. // свободна?
  62. // Eng: return the value of the flag for the global string. Is the line busy or
  63. // free?
  64. function get_FlagForLoadText: Boolean; {$IfDef USE_INLINE}inline;{$EndIf}
  65. implementation
  66. {$IfDef DELPHI7_AND_DOWN}
  67. function AnsiToUtf8(text: AnsiString): UTF8String;
  68. var
  69. i, len: Integer;
  70. n: Byte;
  71. begin
  72. Result := '';
  73. len := Length(text);
  74. for i := 1 to len do
  75. begin
  76. n := byte(text[i]);
  77. case n of
  78. 0..127: Result := Result + chr(n);
  79. 192..255: Result := Result + chr($D0) + chr(n - $C0 + $90);
  80. 168: Result := Result + chr($D0) + chr($81); // Ё
  81. 184: Result := Result + chr($D1) + chr($91); // ё
  82. 185: Result := Result + chr($E2) + chr($84) + chr($96); // №
  83. end;
  84. end;
  85. end;
  86. function ByteToUtf8Rus(myByte: Byte): UTF8String;
  87. begin
  88. case myByte of
  89. 0..127: Result := chr(myByte);
  90. 192..255: Result := chr($D0) + chr((myByte - $C0 + $90));
  91. 168: Result := chr($D0) + chr($81);
  92. 184: Result := chr($D1) + chr($91);
  93. 185: Result := Result + chr($E2) + chr($84) + chr($96);
  94. end;
  95. end;
  96. {$EndIf}
  97. procedure EngToRus(var symb: LongWord);
  98. begin
  99. case symb of
  100. 102 : symb := 224; // а
  101. 44 : symb := 225; // б
  102. 68 : symb := 194; // в
  103. 85 : symb := 195; // г
  104. 76 : symb := 196; // д
  105. 84 : symb := 197; // е
  106. 96 : symb := 184; // ё
  107. 59 : symb := 230; // ж
  108. 80 : symb := 199; // з
  109. 66 : symb := 200; // и
  110. 81 : symb := 201; // й
  111. 82 : symb := 202; // к
  112. 75 : symb := 203; // л
  113. 86 : symb := 204; // м
  114. 89 : symb := 205; // н
  115. 74 : symb := 206; // о
  116. 71 : symb := 207; // п
  117. 72 : symb := 208; // р
  118. 67 : symb := 209; // с
  119. 78 : symb := 210; // т
  120. 69 : symb := 211; // у
  121. 65 : symb := 212; // ф
  122. 91 : symb := 245; // х
  123. 87 : symb := 214; // ц
  124. 88 : symb := 215; // ч
  125. 73 : symb := 216; // ш
  126. 79 : symb := 217; // щ
  127. 93 : symb := 250; // ъ
  128. 83 : symb := 219; // ы
  129. 77 : symb := 220; // ь
  130. 39 : symb := 253; // э
  131. 46 : symb := 254; // ю
  132. 90 : symb := 223; // я
  133. 70 : symb := 192; // А
  134. 60 : symb := 193; // Б
  135. 100 : symb := 226; // В
  136. 117 : symb := 227; // Г
  137. 108 : symb := 228; // Д
  138. 116 : symb := 229; // Е
  139. 126 : symb := 168; // Ё
  140. 58 : symb := 198; // Ж
  141. 112 : symb := 231; // З
  142. 98 : symb := 232; // И
  143. 113 : symb := 233; // Й
  144. 114 : symb := 234; // К
  145. 107 : symb := 235; // Л
  146. 118 : symb := 236; // М
  147. 121 : symb := 237; // Н
  148. 106 : symb := 238; // О
  149. 103 : symb := 239; // П
  150. 104 : symb := 240; // Р
  151. 99 : symb := 241; // С
  152. 110 : symb := 242; // Т
  153. 101 : symb := 243; // У
  154. 97 : symb := 244; // Ф
  155. 123 : symb := 213; // Х
  156. 119 : symb := 246; // Ц
  157. 120 : symb := 247; // Ч
  158. 105 : symb := 248; // Ш
  159. 111 : symb := 249; // Щ
  160. 125 : symb := 218; // Ъ
  161. 115 : symb := 251; // Ы
  162. 109 : symb := 252; // Ь
  163. 34 : symb := 221; // Э
  164. 62 : symb := 222; // Ю
  165. 122 : symb := 255; // Я
  166. 35: symb := 185; // №
  167. end;
  168. end;
  169. procedure EngToRusUnicode(var symb: LongWord);
  170. begin
  171. case symb of
  172. 102 : symb := 1072; // а !!
  173. 44 : symb := 1073; // б !!
  174. 100 : symb := 1074; // в !!
  175. 117 : symb := 1075; // г !!
  176. 108 : symb := 1076; // д !!
  177. 116 : symb := 1077; // е !!
  178. 96 : symb := 1105; // ё !!
  179. 59 : symb := 1078; // ж !!
  180. 112 : symb := 1079; // з !!
  181. 98 : symb := 1080; // и !!
  182. 113 : symb := 1081; // й !!
  183. 114 : symb := 1082; // к !!
  184. 107 : symb := 1083; // л !!
  185. 118 : symb := 1084; // м !!
  186. 121 : symb := 1085; // н !!
  187. 106 : symb := 1086; // о !!
  188. 103 : symb := 1087; // п !!
  189. 104 : symb := 1088; // р !!
  190. 99 : symb := 1089; // с !!
  191. 110 : symb := 1090; // т !!
  192. 101 : symb := 1091; // у !!
  193. 97 : symb := 1092; // ф !!
  194. 91 : symb := 1093; // х !!
  195. 119 : symb := 1094; // ц !!
  196. 120 : symb := 1095; // ч !!
  197. 105 : symb := 1096; // ш !!
  198. 111 : symb := 1097; // щ !!
  199. 93 : symb := 1098; // ъ !!
  200. 115 : symb := 1099; // ы !!
  201. 109 : symb := 1100; // ь !!
  202. 39 : symb := 1101; // э !!
  203. 46 : symb := 1102; // ю !!
  204. 122 : symb := 1103; // я
  205. 70 : symb := 1040; // А !!
  206. 60 : symb := 1041; // Б !!
  207. 68 : symb := 1042; // В !!
  208. 85 : symb := 1043; // Г !!
  209. 76 : symb := 1044; // Д !!
  210. 84 : symb := 1045; // Е !!
  211. 126 : symb := 1025; // Ё !!
  212. 58 : symb := 1046; // Ж !!
  213. 80 : symb := 1047; // З !!
  214. 66 : symb := 1048; // И !!
  215. 81 : symb := 1049; // Й !!
  216. 82 : symb := 1050; // К !!
  217. 75 : symb := 1051; // Л !!
  218. 86 : symb := 1052; // М !!
  219. 89 : symb := 1053; // Н !!
  220. 74 : symb := 1054; // О !!
  221. 71 : symb := 1055; // П !!
  222. 72 : symb := 1056; // Р !!
  223. 67 : symb := 1057; // С !!
  224. 78 : symb := 1058; // Т !!
  225. 69 : symb := 1059; // У !!
  226. 65 : symb := 1060; // Ф !!
  227. 123 : symb := 1061; // Х !!
  228. 87 : symb := 1062; // Ц !!
  229. 88 : symb := 1063; // Ч !!
  230. 73 : symb := 1064; // Ш !!
  231. 79 : symb := 1065; // Щ !!
  232. 125 : symb := 1066; // Ъ !!
  233. 83 : symb := 1067; // Ы !!
  234. 77 : symb := 1068; // Ь !!
  235. 34 : symb := 1069; // Э
  236. 62 : symb := 1070; // Ю
  237. 90 : symb := 1071; // Я
  238. 35 : symb := 8470; // №
  239. end;
  240. end;
  241. procedure set_FlagForLoadText(flag: Boolean);
  242. begin
  243. if flag = True then
  244. LoadText := '';
  245. fLoadTextClearing := flag;
  246. end;
  247. function get_FlagForLoadText: Boolean;
  248. begin
  249. Result := fLoadTextClearing;
  250. end;
  251. end.