You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

75 lines
2.3 KiB

  1. unit utsRenderer;
  2. {$IFDEF FPC}
  3. {$mode objfpc}{$H+}
  4. {$ENDIF}
  5. interface
  6. uses
  7. Classes, SysUtils,
  8. utsTypes, utsFont, utsCharCache, utsTextBlock;
  9. type
  10. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  11. TtsRenderer = class(TtsBlockRenderer)
  12. public
  13. function GetTextWidthA(const aFont: TtsFont; const aText: PAnsiChar): Integer;
  14. function GetTextWidthW(const aFont: TtsFont; const aText: PWideChar): Integer;
  15. function BeginBlock(const aLeft, aTop, aWidth, aHeight: Integer; const aFlags: TtsBlockFlags): TtsTextBlock;
  16. public
  17. class procedure EndBlock(var aBlock: TtsTextBlock);
  18. class procedure AbortBlock(var aBlock: TtsTextBlock);
  19. end;
  20. implementation
  21. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  22. //TtsRenderer///////////////////////////////////////////////////////////////////////////////////////////////////////////
  23. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  24. function TtsRenderer.GetTextWidthA(const aFont: TtsFont; const aText: PAnsiChar): Integer;
  25. var
  26. c: TtsChars;
  27. begin
  28. result := 0;
  29. c := CharCache.Chars[aFont];
  30. if Assigned(c) then
  31. result := c.GetTextWidthA(aText);
  32. end;
  33. function TtsRenderer.GetTextWidthW(const aFont: TtsFont; const aText: PWideChar): Integer;
  34. var
  35. c: TtsChars;
  36. begin
  37. result := 0;
  38. c := CharCache.Chars[aFont];
  39. if Assigned(c) then
  40. result := c.GetTextWidthW(aText);
  41. end;
  42. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  43. function TtsRenderer.BeginBlock(const aLeft, aTop, aWidth, aHeight: Integer; const aFlags: TtsBlockFlags): TtsTextBlock;
  44. begin
  45. result := TtsTextBlock.Create(self, aLeft, aTop, aWidth, aHeight, aFlags);
  46. end;
  47. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  48. class procedure TtsRenderer.EndBlock(var aBlock: TtsTextBlock);
  49. begin
  50. try
  51. aBlock.Render;
  52. finally
  53. FreeAndNil(aBlock);
  54. end;
  55. end;
  56. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  57. class procedure TtsRenderer.AbortBlock(var aBlock: TtsTextBlock);
  58. begin
  59. FreeAndNil(aBlock);
  60. end;
  61. end.