Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 
 
 

188 linhas
6.4 KiB

  1. unit ultsContext;
  2. {$mode objfpc}{$H+}
  3. interface
  4. uses
  5. Classes, SysUtils,
  6. utsTextSuite, utsUtils,
  7. ultsTypes;
  8. type
  9. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  10. TltsContext = class(TtsContext)
  11. public
  12. procedure DelSlave(const aSlave: TtsRefManager); override;
  13. end;
  14. function ltsContextCreate (): TltsContextHandle; stdcall;
  15. function ltsContextGetCodePage (const aHandle: TltsContextHandle; out aCodePage: TtsCodePage): TltsErrorCode; stdcall;
  16. function ltsContextGetDefaultChar (const aHandle: TltsContextHandle; out aValue: WideChar): TltsErrorCode; stdcall;
  17. function ltsContextSetCodePage (const aHandle: TltsContextHandle; aCodePage: TtsCodePage): TltsErrorCode; stdcall;
  18. function ltsContextSetDefaultChar (const aHandle: TltsContextHandle; aValue: WideChar): TltsErrorCode; stdcall;
  19. function ltsContextAnsiToWide (const aHandle: TltsContextHandle; aText: PAnsiChar): PWideChar; stdcall;
  20. function ltsContextDestroy (const aHandle: TltsContextHandle): TltsErrorCode; stdcall;
  21. implementation
  22. uses
  23. ultsUtils;
  24. var
  25. WideStringBuffer: WideString;
  26. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  27. //TltsContext///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  28. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  29. procedure TltsContext.DelSlave(const aSlave: TtsRefManager);
  30. begin
  31. DelReference(aSlave);
  32. inherited DelSlave(aSlave);
  33. end;
  34. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  35. //Context///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  36. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  37. function ltsContextCreate: TltsContextHandle; stdcall;
  38. var
  39. c: TltsContext;
  40. begin
  41. try
  42. result := nil;
  43. if not CheckIfInitialized then
  44. exit;
  45. c := TltsContext.Create;
  46. AddReference(ltsObjTypeContext, c);
  47. result := c;
  48. except
  49. on ex: Exception do begin
  50. SetLastError(ex);
  51. result := nil;
  52. end;
  53. end;
  54. end;
  55. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  56. function ltsContextGetCodePage(const aHandle: TltsContextHandle; out aCodePage: TtsCodePage): TltsErrorCode; stdcall;
  57. var
  58. c: TtsContext;
  59. begin
  60. try
  61. result := ltsErrNone;
  62. if CheckContextHandle(aHandle, c)
  63. then aCodePage := c.CodePage
  64. else result := LastErrorCode;
  65. except
  66. on ex: Exception do begin
  67. SetLastError(ex);
  68. result := LastErrorCode;
  69. end;
  70. end;
  71. end;
  72. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  73. function ltsContextGetDefaultChar(const aHandle: TltsContextHandle; out aValue: WideChar): TltsErrorCode; stdcall;
  74. var
  75. c: TtsContext;
  76. begin
  77. try
  78. result := ltsErrNone;
  79. if CheckContextHandle(aHandle, c)
  80. then aValue := c.DefaultChar
  81. else result := LastErrorCode;
  82. except
  83. on ex: Exception do begin
  84. SetLastError(ex);
  85. result := LastErrorCode;
  86. end;
  87. end;
  88. end;
  89. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  90. function ltsContextSetCodePage(const aHandle: TltsContextHandle; aCodePage: TtsCodePage): TltsErrorCode; stdcall;
  91. var
  92. c: TtsContext;
  93. begin
  94. try
  95. result := ltsErrNone;
  96. if CheckContextHandle(aHandle, c) then begin
  97. if not ValidateCodePage(aCodePage) then begin
  98. SetLastError(ltsErrInvalidEnum, Format('%d is not a valid enum value for CodePage', [aCodePage]));
  99. result := LastErrorCode;
  100. end else
  101. c.CodePage := aCodePage;
  102. end else
  103. result := LastErrorCode;
  104. except
  105. on ex: Exception do begin
  106. SetLastError(ex);
  107. result := LastErrorCode;
  108. end;
  109. end;
  110. end;
  111. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  112. function ltsContextSetDefaultChar(const aHandle: TltsContextHandle; aValue: WideChar): TltsErrorCode; stdcall;
  113. var
  114. c: TtsContext;
  115. begin
  116. try
  117. result := ltsErrNone;
  118. if CheckContextHandle(aHandle, c)
  119. then c.DefaultChar := aValue
  120. else result := LastErrorCode;
  121. except
  122. on ex: Exception do begin
  123. SetLastError(ex);
  124. result := LastErrorCode;
  125. end;
  126. end;
  127. end;
  128. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  129. function ltsContextAnsiToWide(const aHandle: TltsContextHandle; aText: PAnsiChar): PWideChar; stdcall;
  130. var
  131. c: TtsContext;
  132. w: PWideChar;
  133. begin
  134. try
  135. result := nil;
  136. if CheckContextHandle(aHandle, c) then begin
  137. w := c.AnsiToWide(aText);
  138. if not Assigned(w) then
  139. exit;
  140. WideStringBuffer := w;
  141. tsStrDispose(w);
  142. result := PWideChar(WideStringBuffer);
  143. end else
  144. result := nil;
  145. except
  146. on ex: Exception do begin
  147. SetLastError(ex);
  148. result := nil;
  149. end;
  150. end;
  151. end;
  152. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  153. function ltsContextDestroy(const aHandle: TltsContextHandle): TltsErrorCode; stdcall;
  154. var
  155. c: TtsContext;
  156. begin
  157. try
  158. result := ltsErrNone;
  159. if CheckContextHandle(aHandle, c)
  160. then DelReference(ltsObjTypeContext, c)
  161. else result := LastErrorCode;
  162. except
  163. on ex: Exception do begin
  164. SetLastError(ex);
  165. result := LastErrorCode;
  166. end;
  167. end;
  168. end;
  169. end.