Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

66 rader
2.5 KiB

  1. unit utsFont;
  2. {$IFDEF FPC}
  3. {$mode objfpc}{$H+}
  4. {$ENDIF}
  5. interface
  6. uses
  7. Classes, SysUtils,
  8. utsUtils, utsTypes, utsPostProcessor, utsImage;
  9. type
  10. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  11. TtsFont = class(TtsMultiMasterRefManager)
  12. private
  13. fNames: TtsFontNames;
  14. fMetric: TtsFontMetric;
  15. fPostProcessor: TtsPostProcessor;
  16. fTabWidth: Integer;
  17. fCharSpacing: Integer;
  18. fLineSpacing: Single;
  19. protected
  20. {%H-}constructor Create(const aCreator: TtsRefManager; const aMetric: TtsFontMetric; const aNames: TtsFontNames);
  21. public
  22. property Names: TtsFontNames read fNames;
  23. property Metric: TtsFontMetric read fMetric;
  24. property PostProcessor: TtsPostProcessor read fPostProcessor write fPostProcessor;
  25. property TabWidth: Integer read fTabWidth write fTabWidth;
  26. property CharSpacing: Integer read fCharSpacing write fCharSpacing;
  27. property LineSpacing: Single read fLineSpacing write fLineSpacing;
  28. procedure GetTextMetric(out aMetric: TtsTextMetric);
  29. procedure GetCharImage(const aCharCode: WideChar; const aCharImage: TtsImage; const aFormat: TtsFormat); virtual; abstract;
  30. function GetGlyphMetrics(const aCharCode: WideChar; out aGlyphOrigin, aGlyphSize: TtsPosition; out aAdvance: Integer): Boolean; virtual; abstract;
  31. end;
  32. implementation
  33. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  34. //TtsFont//////////////////////////////////////////////////////////////////////////////////////////////////////////////
  35. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  36. constructor TtsFont.Create(const aCreator: TtsRefManager; const aMetric: TtsFontMetric; const aNames: TtsFontNames);
  37. begin
  38. inherited Create(aCreator);
  39. fMetric := aMetric;
  40. fNames := aNames;
  41. end;
  42. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  43. procedure TtsFont.GetTextMetric(out aMetric: TtsTextMetric);
  44. begin
  45. aMetric.Ascent := fMetric.Ascent;
  46. aMetric.Descent := fMetric.Descent;
  47. aMetric.ExternalLeading := fMetric.ExternalLeading;
  48. aMetric.BaseLineOffset := fMetric.BaseLineOffset;
  49. aMetric.CharSpacing := CharSpacing;
  50. aMetric.LineHeight := fMetric.Ascent + fMetric.Descent + fMetric.ExternalLeading;
  51. aMetric.LineSpacing := Trunc(fMetric.Size * fLineSpacing);
  52. end;
  53. end.