| @@ -206,7 +206,7 @@ begin | |||||
| (m.Advance <> 0))) then | (m.Advance <> 0))) then | ||||
| exit; | exit; | ||||
| CharImage := TtsImage.Create; | |||||
| CharImage := TtsImage.Create(nil); | |||||
| try | try | ||||
| if (aCharCode = #0) then begin | if (aCharCode = #0) then begin | ||||
| CharImage.CreateEmpty(fRenderRefGenerator.Format, 3, 1); | CharImage.CreateEmpty(fRenderRefGenerator.Format, 3, 1); | ||||
| @@ -8,13 +8,13 @@ interface | |||||
| uses | uses | ||||
| Classes, SysUtils, | Classes, SysUtils, | ||||
| utsUtils, utsFontCreator, utsTypes, utsPostProcessor, utsImage; | |||||
| utsUtils, utsTypes, utsPostProcessor, utsImage; | |||||
| type | type | ||||
| //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||||
| TtsFont = class(TtsMultiMasterRefManager) | TtsFont = class(TtsMultiMasterRefManager) | ||||
| private | private | ||||
| fCreator: TtsFontCreator; | |||||
| fNames: TtsFontNames; | |||||
| fMetric: TtsFontMetric; | fMetric: TtsFontMetric; | ||||
| fPostProcessor: TtsPostProcessor; | fPostProcessor: TtsPostProcessor; | ||||
| @@ -22,9 +22,9 @@ type | |||||
| fCharSpacing: Integer; | fCharSpacing: Integer; | ||||
| fLineSpacing: Single; | fLineSpacing: Single; | ||||
| protected | protected | ||||
| {%H-}constructor Create(const aCreator: TtsFontCreator; const aMetric: TtsFontMetric); | |||||
| {%H-}constructor Create(const aMaster: TtsRefManager; const aMetric: TtsFontMetric; const aNames: TtsFontNames); | |||||
| public | public | ||||
| property Creator: TtsFontCreator read fCreator; | |||||
| property Names: TtsFontNames read fNames; | |||||
| property Metric: TtsFontMetric read fMetric; | property Metric: TtsFontMetric read fMetric; | ||||
| property PostProcessor: TtsPostProcessor read fPostProcessor write fPostProcessor; | property PostProcessor: TtsPostProcessor read fPostProcessor write fPostProcessor; | ||||
| @@ -42,11 +42,11 @@ implementation | |||||
| /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||||
| //TtsFont////////////////////////////////////////////////////////////////////////////////////////////////////////////// | //TtsFont////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||||
| //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||||
| constructor TtsFont.Create(const aCreator: TtsFontCreator; const aMetric: TtsFontMetric); | |||||
| constructor TtsFont.Create(const aMaster: TtsRefManager; const aMetric: TtsFontMetric; const aNames: TtsFontNames); | |||||
| begin | begin | ||||
| inherited Create(aCreator); | |||||
| fCreator := aCreator; | |||||
| fMetric := aMetric; | |||||
| inherited Create(aMaster); | |||||
| fMetric := aMetric; | |||||
| fNames := aNames; | |||||
| end; | end; | ||||
| //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||||
| @@ -8,7 +8,7 @@ interface | |||||
| uses | uses | ||||
| Classes, SysUtils, | Classes, SysUtils, | ||||
| utsUtils, utsContext; | |||||
| utsUtils, utsContext, utsTypes, utsFont; | |||||
| type | type | ||||
| //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||||
| @@ -18,6 +18,10 @@ type | |||||
| public | public | ||||
| property Context: TtsContext read fContext; | property Context: TtsContext read fContext; | ||||
| function GetFontByName(const aFontname: String; const aSize: Integer; const aStyle: TtsFontStyles; const aAntiAliasing: TtsAntiAliasing): TtsFont; overload; virtual; | |||||
| function GetFontByFile(const aFilename: String; const aSize: Integer; const aStyle: TtsFontStyles; const aAntiAliasing: TtsAntiAliasing): TtsFont; overload; virtual; | |||||
| function GetFontByStream(const aStream: TStream; const aSize: Integer; const aStyle: TtsFontStyles; const aAntiAliasing: TtsAntiAliasing): TtsFont; overload; virtual; | |||||
| constructor Create(const aContext: TtsContext); | constructor Create(const aContext: TtsContext); | ||||
| end; | end; | ||||
| @@ -25,6 +29,24 @@ implementation | |||||
| //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||||
| //TtsFontCreator//////////////////////////////////////////////////////////////////////////////////////////////////////// | //TtsFontCreator//////////////////////////////////////////////////////////////////////////////////////////////////////// | ||||
| //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||||
| function TtsFontCreator.GetFontByName(const aFontname: String; const aSize: Integer; const aStyle: TtsFontStyles; const aAntiAliasing: TtsAntiAliasing): TtsFont; | |||||
| begin | |||||
| result := nil; | |||||
| end; | |||||
| //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||||
| function TtsFontCreator.GetFontByFile(const aFilename: String; const aSize: Integer; const aStyle: TtsFontStyles; const aAntiAliasing: TtsAntiAliasing): TtsFont; | |||||
| begin | |||||
| result := nil; | |||||
| end; | |||||
| //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||||
| function TtsFontCreator.GetFontByStream(const aStream: TStream; const aSize: Integer; const aStyle: TtsFontStyles; const aAntiAliasing: TtsAntiAliasing): TtsFont; | |||||
| begin | |||||
| result := nil; | |||||
| end; | |||||
| //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||||
| constructor TtsFontCreator.Create(const aContext: TtsContext); | constructor TtsFontCreator.Create(const aContext: TtsContext); | ||||
| begin | begin | ||||
| @@ -25,7 +25,8 @@ type | |||||
| private | private | ||||
| fHandle: TtsFreeTypeFaceHandle; | fHandle: TtsFreeTypeFaceHandle; | ||||
| protected | protected | ||||
| {%H-}constructor Create(const aHandle: TtsFreeTypeFaceHandle; const aCreator: TtsFontCreator; const aMetric: TtsFontMetric); | |||||
| {%H-}constructor Create(const aHandle: TtsFreeTypeFaceHandle; const aCreator: TtsFontCreator; | |||||
| const aMetric: TtsFontMetric; const aNames: TtsFontNames); | |||||
| public | public | ||||
| procedure GetCharImage(const aCharCode: WideChar; const aCharImage: TtsImage; const aFormat: TtsFormat); override; | procedure GetCharImage(const aCharCode: WideChar; const aCharImage: TtsImage; const aFormat: TtsFormat); override; | ||||
| function GetGlyphMetrics(const aCharCode: WideChar; out aGlyphOrigin, aGlyphSize: TtsPosition; out aAdvance: Integer): Boolean; override; | function GetGlyphMetrics(const aCharCode: WideChar; out aGlyphOrigin, aGlyphSize: TtsPosition; out aAdvance: Integer): Boolean; override; | ||||
| @@ -38,11 +39,11 @@ type | |||||
| private | private | ||||
| fHandle: FT_Library; | fHandle: FT_Library; | ||||
| procedure LoadNames(const aFace: FT_Face; var aMetric: TtsFontMetric); | |||||
| procedure LoadNames(const aFace: FT_Face; var aMetric: TtsFontMetric; var aNames: TtsFontNames); | |||||
| function CreateFont(const aFace: FT_Face; const aSize: Integer; const aStyle: TtsFontStyles; const aAntiAliasing: TtsAntiAliasing): TtsFont; | function CreateFont(const aFace: FT_Face; const aSize: Integer; const aStyle: TtsFontStyles; const aAntiAliasing: TtsAntiAliasing): TtsFont; | ||||
| public | public | ||||
| function GetFontByFile(const aFilename: String; const aSize: Integer; const aStyle: TtsFontStyles; const aAntiAliasing: TtsAntiAliasing): TtsFont; overload; | |||||
| function GetFontByStream(const aStream: TStream; const aSize: Integer; const aStyle: TtsFontStyles; const aAntiAliasing: TtsAntiAliasing): TtsFont; overload; | |||||
| function GetFontByFile(const aFilename: String; const aSize: Integer; const aStyle: TtsFontStyles; const aAntiAliasing: TtsAntiAliasing): TtsFont; overload; override; | |||||
| function GetFontByStream(const aStream: TStream; const aSize: Integer; const aStyle: TtsFontStyles; const aAntiAliasing: TtsAntiAliasing): TtsFont; overload; override; | |||||
| constructor Create(const aContext: TtsContext); | constructor Create(const aContext: TtsContext); | ||||
| destructor Destroy; override; | destructor Destroy; override; | ||||
| @@ -77,9 +78,9 @@ end; | |||||
| //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||||
| //TtsFontFreeType/////////////////////////////////////////////////////////////////////////////////////////////////////// | //TtsFontFreeType/////////////////////////////////////////////////////////////////////////////////////////////////////// | ||||
| //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||||
| constructor TtsFontFreeType.Create(const aHandle: TtsFreeTypeFaceHandle; const aCreator: TtsFontCreator; const aMetric: TtsFontMetric); | |||||
| constructor TtsFontFreeType.Create(const aHandle: TtsFreeTypeFaceHandle; const aCreator: TtsFontCreator; const aMetric: TtsFontMetric; const aNames: TtsFontNames); | |||||
| begin | begin | ||||
| inherited Create(aCreator, aMetric); | |||||
| inherited Create(aCreator, aMetric, aNames); | |||||
| fHandle := aHandle; | fHandle := aHandle; | ||||
| end; | end; | ||||
| @@ -218,9 +219,9 @@ begin | |||||
| end; | end; | ||||
| //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||||
| //TtsFontCreatorFreeType////////////////////////////////////////////////////////////////////////////////////////////// | |||||
| //TtsFontCreatorFreeType//////////////////////////////////////////////////////////////////////////////////////////////// | |||||
| //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||||
| procedure TtsFontCreatorFreeType.LoadNames(const aFace: FT_Face; var aMetric: TtsFontMetric); | |||||
| procedure TtsFontCreatorFreeType.LoadNames(const aFace: FT_Face; var aMetric: TtsFontMetric; var aNames: TtsFontNames); | |||||
| var | var | ||||
| i, cnt: FT_Int; | i, cnt: FT_Int; | ||||
| err: FT_Error; | err: FT_Error; | ||||
| @@ -275,16 +276,16 @@ begin | |||||
| case name.name_id of | case name.name_id of | ||||
| TT_NAME_ID_COPYRIGHT: | TT_NAME_ID_COPYRIGHT: | ||||
| if (aMetric.Copyright = '') then | |||||
| aMetric.Copyright := Decode; | |||||
| if (aNames.Copyright = '') then | |||||
| aNames.Copyright := Decode; | |||||
| TT_NAME_ID_FONT_FAMILY: | TT_NAME_ID_FONT_FAMILY: | ||||
| if (aMetric.Fontname = '') then | |||||
| aMetric.Fontname := Decode; | |||||
| if (aNames.Fontname = '') then | |||||
| aNames.Fontname := Decode; | |||||
| TT_NAME_ID_FULL_NAME: | TT_NAME_ID_FULL_NAME: | ||||
| if (aMetric.FullName = '') then | |||||
| aMetric.FullName := Decode; | |||||
| if (aNames.FullName = '') then | |||||
| aNames.FullName := Decode; | |||||
| end; | end; | ||||
| end; | end; | ||||
| end; | end; | ||||
| @@ -295,6 +296,7 @@ function TtsFontCreatorFreeType.CreateFont(const aFace: FT_Face; const aSize: In | |||||
| var | var | ||||
| err: FT_Error; | err: FT_Error; | ||||
| metric: TtsFontMetric; | metric: TtsFontMetric; | ||||
| names: TtsFontNames; | |||||
| os2: PTT_OS2; | os2: PTT_OS2; | ||||
| hz: PTT_HoriHeader; | hz: PTT_HoriHeader; | ||||
| begin | begin | ||||
| @@ -304,9 +306,9 @@ begin | |||||
| FillChar(metric{%H-}, SizeOf(metric), #0); | FillChar(metric{%H-}, SizeOf(metric), #0); | ||||
| metric.AntiAliasing := tsAANormal; | metric.AntiAliasing := tsAANormal; | ||||
| metric.FaceName := String(aFace^.family_name); | |||||
| metric.StyleName := String(aFace^.style_name); | |||||
| LoadNames(aFace, metric); | |||||
| names.FaceName := String(aFace^.family_name); | |||||
| names.StyleName := String(aFace^.style_name); | |||||
| LoadNames(aFace, metric, names); | |||||
| metric.Size := aSize; | metric.Size := aSize; | ||||
| metric.AntiAliasing := aAntiAliasing; | metric.AntiAliasing := aAntiAliasing; | ||||
| @@ -336,7 +338,7 @@ begin | |||||
| metric.ExternalLeading := hz^.Line_Gap div FT_SIZE_FACTOR; | metric.ExternalLeading := hz^.Line_Gap div FT_SIZE_FACTOR; | ||||
| end; | end; | ||||
| result := TtsFontFreeType.Create(TtsFreeTypeFaceHandle.Create(aFace), self, metric); | |||||
| result := TtsFontFreeType.Create(TtsFreeTypeFaceHandle.Create(aFace), self, metric, names); | |||||
| end; | end; | ||||
| //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||||
| @@ -21,7 +21,7 @@ type | |||||
| procedure GetCharImageAANone(const aDC: HDC; const aCharCode: WideChar; const aImage: TtsImage; const aFormat: TtsFormat); | procedure GetCharImageAANone(const aDC: HDC; const aCharCode: WideChar; const aImage: TtsImage; const aFormat: TtsFormat); | ||||
| procedure GetCharImageAANormal(const aDC: HDC; const aCharCode: WideChar; const aImage: TtsImage; const aFormat: TtsFormat); | procedure GetCharImageAANormal(const aDC: HDC; const aCharCode: WideChar; const aImage: TtsImage; const aFormat: TtsFormat); | ||||
| protected | protected | ||||
| {%H-}constructor Create(const aHandle: THandle; const aCreator: TtsFontCreator; const aMetric: TtsFontMetric); | |||||
| {%H-}constructor Create(const aHandle: THandle; const aCreator: TtsFontCreator; const aMetric: TtsFontMetric; const aNames: TtsFontNames); | |||||
| public | public | ||||
| procedure GetCharImage(const aCharCode: WideChar; const aCharImage: TtsImage; const aFormat: TtsFormat); override; | procedure GetCharImage(const aCharCode: WideChar; const aCharImage: TtsImage; const aFormat: TtsFormat); override; | ||||
| function GetGlyphMetrics(const aCharCode: WideChar; out aGlyphOrigin, aGlyphSize: TtsPosition; out aAdvance: Integer): Boolean; override; | function GetGlyphMetrics(const aCharCode: WideChar; out aGlyphOrigin, aGlyphSize: TtsPosition; out aAdvance: Integer): Boolean; override; | ||||
| @@ -64,7 +64,8 @@ type | |||||
| private | private | ||||
| fRegistration: TtsFontRegistration; | fRegistration: TtsFontRegistration; | ||||
| protected | protected | ||||
| {%H-}constructor Create(const aRegistration: TtsFontRegistration; const aHandle: THandle; const aCreator: TtsFontCreator; const aMetric: TtsFontMetric); | |||||
| {%H-}constructor Create(const aRegistration: TtsFontRegistration; const aHandle: THandle; | |||||
| const aCreator: TtsFontCreator; const aMetric: TtsFontMetric; const aNames: TtsFontNames); | |||||
| public | public | ||||
| destructor Destroy; override; | destructor Destroy; override; | ||||
| end; | end; | ||||
| @@ -72,11 +73,11 @@ type | |||||
| //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||||
| TtsFontCreatorGDI = class(TtsFontCreator) | TtsFontCreatorGDI = class(TtsFontCreator) | ||||
| private | private | ||||
| function CreateFont(const aFontname: String; const aSize: Integer; const aStyle: TtsFontStyles; const aAntiAliasing: TtsAntiAliasing; out aMetric: TtsFontMetric): THandle; | |||||
| function CreateFont(const aFontname: String; const aSize: Integer; const aStyle: TtsFontStyles; const aAntiAliasing: TtsAntiAliasing; out aMetric: TtsFontMetric; out aNames: TtsFontNames): THandle; | |||||
| public | public | ||||
| function GetFontByName(const aFontname: String; const aSize: Integer; const aStyle: TtsFontStyles; const aAntiAliasing: TtsAntiAliasing): TtsFont; overload; | |||||
| function GetFontByFile(const aFilename: String; const aSize: Integer; const aStyle: TtsFontStyles; const aAntiAliasing: TtsAntiAliasing): TtsFont; overload; | |||||
| function GetFontByStream(const aStream: TStream; const aSize: Integer; const aStyle: TtsFontStyles; const aAntiAliasing: TtsAntiAliasing): TtsFont; overload; | |||||
| function GetFontByName(const aFontname: String; const aSize: Integer; const aStyle: TtsFontStyles; const aAntiAliasing: TtsAntiAliasing): TtsFont; overload; override; | |||||
| function GetFontByFile(const aFilename: String; const aSize: Integer; const aStyle: TtsFontStyles; const aAntiAliasing: TtsAntiAliasing): TtsFont; overload; override; | |||||
| function GetFontByStream(const aStream: TStream; const aSize: Integer; const aStyle: TtsFontStyles; const aAntiAliasing: TtsAntiAliasing): TtsFont; overload; override; | |||||
| constructor Create(const aContext: TtsContext); | constructor Create(const aContext: TtsContext); | ||||
| destructor Destroy; override; | destructor Destroy; override; | ||||
| @@ -569,9 +570,9 @@ begin | |||||
| end; | end; | ||||
| //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||||
| constructor TtsFontGDI.Create(const aHandle: THandle; const aCreator: TtsFontCreator; const aMetric: TtsFontMetric); | |||||
| constructor TtsFontGDI.Create(const aHandle: THandle; const aCreator: TtsFontCreator; const aMetric: TtsFontMetric; const aNames: TtsFontNames); | |||||
| begin | begin | ||||
| inherited Create(aCreator, aMetric); | |||||
| inherited Create(aCreator, aMetric, aNames); | |||||
| FillChar(fMat2, SizeOf(fMat2), #0); | FillChar(fMat2, SizeOf(fMat2), #0); | ||||
| fMat2.eM11.value := 1; | fMat2.eM11.value := 1; | ||||
| fMat2.eM22.value := 1; | fMat2.eM22.value := 1; | ||||
| @@ -737,9 +738,10 @@ end; | |||||
| //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||||
| //TtsRegistredFontGDI/////////////////////////////////////////////////////////////////////////////////////////////////// | //TtsRegistredFontGDI/////////////////////////////////////////////////////////////////////////////////////////////////// | ||||
| //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||||
| constructor TtsRegistredFontGDI.Create(const aRegistration: TtsFontRegistration; const aHandle: THandle; const aCreator: TtsFontCreator; const aMetric: TtsFontMetric); | |||||
| constructor TtsRegistredFontGDI.Create(const aRegistration: TtsFontRegistration; const aHandle: THandle; | |||||
| const aCreator: TtsFontCreator; const aMetric: TtsFontMetric; const aNames: TtsFontNames); | |||||
| begin | begin | ||||
| inherited Create(aHandle, aCreator, aMetric); | |||||
| inherited Create(aHandle, aCreator, aMetric, aNames); | |||||
| fRegistration := aRegistration; | fRegistration := aRegistration; | ||||
| end; | end; | ||||
| @@ -753,7 +755,8 @@ end; | |||||
| //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||||
| //TtsFontCreatorGDI///////////////////////////////////////////////////////////////////////////////////////////////////// | //TtsFontCreatorGDI///////////////////////////////////////////////////////////////////////////////////////////////////// | ||||
| //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||||
| function TtsFontCreatorGDI.CreateFont(const aFontname: String; const aSize: Integer; const aStyle: TtsFontStyles; const aAntiAliasing: TtsAntiAliasing; out aMetric: TtsFontMetric): THandle; | |||||
| function TtsFontCreatorGDI.CreateFont(const aFontname: String; const aSize: Integer; const aStyle: TtsFontStyles; | |||||
| const aAntiAliasing: TtsAntiAliasing; out aMetric: TtsFontMetric; out aNames: TtsFontNames): THandle; | |||||
| var | var | ||||
| LogFont: TLogFontA; | LogFont: TLogFontA; | ||||
| i: Integer; | i: Integer; | ||||
| @@ -777,7 +780,7 @@ begin | |||||
| aMetric.Size := aSize; | aMetric.Size := aSize; | ||||
| aMetric.Style := aStyle; | aMetric.Style := aStyle; | ||||
| aMetric.AntiAliasing := aAntiAliasing; | aMetric.AntiAliasing := aAntiAliasing; | ||||
| aMetric.Fontname := aFontname; | |||||
| aNames.Fontname := aFontname; | |||||
| // prepare font attribs | // prepare font attribs | ||||
| FillChar(LogFont{%H-}, SizeOf(LogFont), #0); | FillChar(LogFont{%H-}, SizeOf(LogFont), #0); | ||||
| @@ -804,10 +807,10 @@ begin | |||||
| SetLength(Lang, 4); | SetLength(Lang, 4); | ||||
| GetLocaleInfoA(LOCALE_USER_DEFAULT, LOCALE_ILANGUAGE, @Lang[1], 4); | GetLocaleInfoA(LOCALE_USER_DEFAULT, LOCALE_ILANGUAGE, @Lang[1], 4); | ||||
| GetTTString(Buffer, BufSize, NAME_ID_COPYRIGHT, StrToInt('$' + String(Lang)), aMetric.Copyright); | |||||
| GetTTString(Buffer, BufSize, NAME_ID_FACE_NAME, StrToInt('$' + String(Lang)), aMetric.FaceName); | |||||
| GetTTString(Buffer, BufSize, NAME_ID_STYLE_NAME, StrToInt('$' + String(Lang)), aMetric.StyleName); | |||||
| GetTTString(Buffer, BufSize, NAME_ID_FULL_NAME, StrToInt('$' + String(Lang)), aMetric.FullName); | |||||
| GetTTString(Buffer, BufSize, NAME_ID_COPYRIGHT, StrToInt('$' + String(Lang)), aNames.Copyright); | |||||
| GetTTString(Buffer, BufSize, NAME_ID_FACE_NAME, StrToInt('$' + String(Lang)), aNames.FaceName); | |||||
| GetTTString(Buffer, BufSize, NAME_ID_STYLE_NAME, StrToInt('$' + String(Lang)), aNames.StyleName); | |||||
| GetTTString(Buffer, BufSize, NAME_ID_FULL_NAME, StrToInt('$' + String(Lang)), aNames.FullName); | |||||
| end; | end; | ||||
| finally | finally | ||||
| FreeMem(Buffer); | FreeMem(Buffer); | ||||
| @@ -841,11 +844,12 @@ function TtsFontCreatorGDI.GetFontByName(const aFontname: String; const aSize: I | |||||
| var | var | ||||
| handle: THandle; | handle: THandle; | ||||
| metric: TtsFontMetric; | metric: TtsFontMetric; | ||||
| names: TtsFontNames; | |||||
| begin | begin | ||||
| handle := CreateFont(aFontname, aSize, aStyle, aAntiAliasing, metric); | |||||
| handle := CreateFont(aFontname, aSize, aStyle, aAntiAliasing, metric, names); | |||||
| if (handle = 0) then | if (handle = 0) then | ||||
| raise EtsException.Create('unable to create font from name: ' + aFontname); | raise EtsException.Create('unable to create font from name: ' + aFontname); | ||||
| result := TtsFontGDI.Create(handle, self, metric); | |||||
| result := TtsFontGDI.Create(handle, self, metric, names); | |||||
| end; | end; | ||||
| //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||||
| @@ -854,19 +858,20 @@ var | |||||
| reg: TtsFontRegistrationFile; | reg: TtsFontRegistrationFile; | ||||
| handle: THandle; | handle: THandle; | ||||
| metric: TtsFontMetric; | metric: TtsFontMetric; | ||||
| names: TtsFontNames; | |||||
| begin | begin | ||||
| reg := TtsFontRegistrationFile.Create(aFilename); | reg := TtsFontRegistrationFile.Create(aFilename); | ||||
| try | try | ||||
| if not reg.IsRegistered then | if not reg.IsRegistered then | ||||
| raise EtsException.Create('unable to register font file: ' + aFilename); | raise EtsException.Create('unable to register font file: ' + aFilename); | ||||
| handle := CreateFont(reg.Fontname, aSize, aStyle, aAntiAliasing, metric); | |||||
| handle := CreateFont(reg.Fontname, aSize, aStyle, aAntiAliasing, metric, names); | |||||
| if (handle = 0) then | if (handle = 0) then | ||||
| raise EtsException.Create('unable to create font from file: ' + aFilename); | raise EtsException.Create('unable to create font from file: ' + aFilename); | ||||
| except | except | ||||
| FreeAndNil(reg); | FreeAndNil(reg); | ||||
| raise; | raise; | ||||
| end; | end; | ||||
| result := TtsRegistredFontGDI.Create(reg, handle, self, metric); | |||||
| result := TtsRegistredFontGDI.Create(reg, handle, self, metric, names); | |||||
| end; | end; | ||||
| //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||||
| @@ -875,14 +880,15 @@ var | |||||
| reg: TtsFontRegistrationStream; | reg: TtsFontRegistrationStream; | ||||
| handle: THandle; | handle: THandle; | ||||
| metric: TtsFontMetric; | metric: TtsFontMetric; | ||||
| names: TtsFontNames; | |||||
| begin | begin | ||||
| reg := TtsFontRegistrationStream.Create(aStream); | reg := TtsFontRegistrationStream.Create(aStream); | ||||
| if not reg.IsRegistered then | if not reg.IsRegistered then | ||||
| raise EtsException.Create('unable to register font from stream'); | raise EtsException.Create('unable to register font from stream'); | ||||
| handle := CreateFont(reg.Fontname, aSize, aStyle, aAntiAliasing, metric); | |||||
| handle := CreateFont(reg.Fontname, aSize, aStyle, aAntiAliasing, metric, names); | |||||
| if (handle = 0) then | if (handle = 0) then | ||||
| raise EtsException.Create('unable to create font from stream: ' + reg.Fontname); | raise EtsException.Create('unable to create font from stream: ' + reg.Fontname); | ||||
| result := TtsRegistredFontGDI.Create(reg, handle, self, metric); | |||||
| result := TtsRegistredFontGDI.Create(reg, handle, self, metric, names); | |||||
| end; | end; | ||||
| //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||||
| @@ -8,14 +8,17 @@ interface | |||||
| uses | uses | ||||
| Classes, SysUtils, | Classes, SysUtils, | ||||
| utsTypes, utsUtils; | |||||
| utsTypes, utsUtils, utsContext; | |||||
| type | type | ||||
| //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||||
| TtsImage = class; | TtsImage = class; | ||||
| TtsImageFunc = procedure(const aImage: TtsImage; X, Y: Integer; var aPixel: TtsColor4f; aArgs: Pointer); | |||||
| TtsImage = class(TObject) | |||||
| TtsImageLoadFunc = procedure(const aImage: TtsImage; X, Y: Integer; var aPixel: TtsColor4f; aArgs: Pointer); | |||||
| TtsImageBlendFunc = function (const aSrc, aDst: TtsColor4f; aArgs: Pointer): TtsColor4f; | |||||
| TtsImage = class(TtsRefManager) | |||||
| private | private | ||||
| fContext: TtsContext; | |||||
| fWidth: Integer; | fWidth: Integer; | ||||
| fHeight: Integer; | fHeight: Integer; | ||||
| fDataSize: Integer; | fDataSize: Integer; | ||||
| @@ -37,20 +40,21 @@ type | |||||
| const aLineSize: Integer = 0; | const aLineSize: Integer = 0; | ||||
| const aDataSize: Integer = 0); | const aDataSize: Integer = 0); | ||||
| public | public | ||||
| property IsEmpty: Boolean read GetIsEmpty; | |||||
| property Width: Integer read fWidth; | |||||
| property Height: Integer read fHeight; | |||||
| property LineSize: Integer read fLineSize; | |||||
| property DataSize: Integer read fDataSize; | |||||
| property Format: TtsFormat read fFormat; | |||||
| property Data: Pointer read fData; | |||||
| property Context: TtsContext read fContext; | |||||
| property IsEmpty: Boolean read GetIsEmpty; | |||||
| property Width: Integer read fWidth; | |||||
| property Height: Integer read fHeight; | |||||
| property LineSize: Integer read fLineSize; | |||||
| property DataSize: Integer read fDataSize; | |||||
| property Format: TtsFormat read fFormat; | |||||
| property Data: Pointer read fData; | |||||
| property Scanline[const aIndex: Integer]: Pointer read GetScanline; | property Scanline[const aIndex: Integer]: Pointer read GetScanline; | ||||
| function GetPixelAt(const x, y: Integer; out aColor: TtsColor4f): Boolean; | function GetPixelAt(const x, y: Integer; out aColor: TtsColor4f): Boolean; | ||||
| procedure Assign(const aImage: TtsImage); | procedure Assign(const aImage: TtsImage); | ||||
| procedure CreateEmpty(const aFormat: TtsFormat; const aWidth, aHeight: Integer); | procedure CreateEmpty(const aFormat: TtsFormat; const aWidth, aHeight: Integer); | ||||
| procedure LoadFromFunc(const aFunc: TtsImageFunc; const aArgs: Pointer); | |||||
| procedure LoadFromFunc(const aFunc: TtsImageLoadFunc; const aArgs: Pointer); | |||||
| procedure Resize(const aNewWidth, aNewHeight, X, Y: Integer); | procedure Resize(const aNewWidth, aNewHeight, X, Y: Integer); | ||||
| procedure FindMinMax(out aRect: TtsRect); | procedure FindMinMax(out aRect: TtsRect); | ||||
| @@ -58,9 +62,10 @@ type | |||||
| procedure FillColor(const aColor: TtsColor4f; const aChannelMask: TtsColorChannels; const aModes: TtsImageModes); | procedure FillColor(const aColor: TtsColor4f; const aChannelMask: TtsColorChannels; const aModes: TtsImageModes); | ||||
| procedure FillPattern(const aPattern: TtsImage; X, Y: Integer; const aChannelMask: TtsColorChannels; const aModes: TtsImageModes); | procedure FillPattern(const aPattern: TtsImage; X, Y: Integer; const aChannelMask: TtsColorChannels; const aModes: TtsImageModes); | ||||
| procedure Blend(const aImage: TtsImage; const X, Y: Integer; const aFunc: TtsBlendColorFunc); | procedure Blend(const aImage: TtsImage; const X, Y: Integer; const aFunc: TtsBlendColorFunc); | ||||
| procedure Blend(const aImage: TtsImage; const X, Y: Integer; const aFunc: TtsImageBlendFunc; const aArgs: Pointer); | |||||
| procedure Blur(const aHorzKernel, aVertKernel: TtsKernel1D; const aChannelMask: TtsColorChannels); | procedure Blur(const aHorzKernel, aVertKernel: TtsKernel1D; const aChannelMask: TtsColorChannels); | ||||
| constructor Create; | |||||
| constructor Create(const aContext: TtsContext); | |||||
| destructor Destroy; override; | destructor Destroy; override; | ||||
| end; | end; | ||||
| @@ -70,6 +75,20 @@ uses | |||||
| Math, | Math, | ||||
| utsConstants; | utsConstants; | ||||
| type | |||||
| PBlendProxyArgs = ^TBlendProxyArgs; | |||||
| TBlendProxyArgs = packed record | |||||
| callback: TtsBlendColorFunc; | |||||
| end; | |||||
| function tsImageBlendCallbackProxy(const aSrc, aDst: TtsColor4f; aArgs: Pointer): TtsColor4f; | |||||
| var | |||||
| p: PBlendProxyArgs; | |||||
| begin | |||||
| p := PBlendProxyArgs(aArgs); | |||||
| result := p^.callback(aSrc, aDst); | |||||
| end; | |||||
| //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||||
| //TtsImage////////////////////////////////////////////////////////////////////////////////////////////////////////////// | //TtsImage////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||||
| //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||||
| @@ -169,7 +188,7 @@ begin | |||||
| end; | end; | ||||
| //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||||
| procedure TtsImage.LoadFromFunc(const aFunc: TtsImageFunc; const aArgs: Pointer); | |||||
| procedure TtsImage.LoadFromFunc(const aFunc: TtsImageLoadFunc; const aArgs: Pointer); | |||||
| var | var | ||||
| X, Y: Integer; | X, Y: Integer; | ||||
| c: TtsColor4f; | c: TtsColor4f; | ||||
| @@ -335,6 +354,15 @@ end; | |||||
| //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||||
| procedure TtsImage.Blend(const aImage: TtsImage; const X, Y: Integer; const aFunc: TtsBlendColorFunc); | procedure TtsImage.Blend(const aImage: TtsImage; const X, Y: Integer; const aFunc: TtsBlendColorFunc); | ||||
| var | |||||
| args: TBlendProxyArgs; | |||||
| begin | |||||
| args.callback := aFunc; | |||||
| Blend(aImage, X, Y, @tsImageBlendCallbackProxy, @args); | |||||
| end; | |||||
| //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||||
| procedure TtsImage.Blend(const aImage: TtsImage; const X, Y: Integer; const aFunc: TtsImageBlendFunc; const aArgs: Pointer); | |||||
| var | var | ||||
| _x, _y, x1, x2, y1, y2: Integer; | _x, _y, x1, x2, y1, y2: Integer; | ||||
| src, dst, tmp: PByte; | src, dst, tmp: PByte; | ||||
| @@ -356,7 +384,7 @@ begin | |||||
| for _x := x1 to x2-1 do begin | for _x := x1 to x2-1 do begin | ||||
| tsFormatUnmap(aImage.Format, src, srcColor); | tsFormatUnmap(aImage.Format, src, srcColor); | ||||
| tsFormatUnmap( Format, dst, dstColor); | tsFormatUnmap( Format, dst, dstColor); | ||||
| tsFormatMap(aImage.Format, tmp, aFunc(srcColor, dstColor)); | |||||
| tsFormatMap(aImage.Format, tmp, aFunc(srcColor, dstColor, aArgs)); | |||||
| end; | end; | ||||
| end; | end; | ||||
| end; | end; | ||||
| @@ -406,7 +434,7 @@ var | |||||
| end; | end; | ||||
| begin | begin | ||||
| tmpImage := TtsImage.Create; | |||||
| tmpImage := TtsImage.Create(fContext); | |||||
| try | try | ||||
| tmpImage.CreateEmpty(Format, Width, Height); | tmpImage.CreateEmpty(Format, Width, Height); | ||||
| tmpImage.FillColor(tsColor4f(1, 1, 1, 0), TS_COLOR_CHANNELS_RGBA, TS_IMAGE_MODES_REPLACE_ALL); | tmpImage.FillColor(tsColor4f(1, 1, 1, 0), TS_COLOR_CHANNELS_RGBA, TS_IMAGE_MODES_REPLACE_ALL); | ||||
| @@ -419,9 +447,10 @@ begin | |||||
| end; | end; | ||||
| //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||||
| constructor TtsImage.Create; | |||||
| constructor TtsImage.Create(const aContext: TtsContext); | |||||
| begin | begin | ||||
| inherited Create; | |||||
| inherited Create(aContext); | |||||
| fContext := aContext; | |||||
| SetData(nil); | SetData(nil); | ||||
| end; | end; | ||||
| @@ -71,6 +71,7 @@ type | |||||
| procedure FreeRenderRef(const aRenderRef: TtsRenderRef); override; | procedure FreeRenderRef(const aRenderRef: TtsRenderRef); override; | ||||
| protected | protected | ||||
| procedure BeginRender; override; | procedure BeginRender; override; | ||||
| procedure EndRender; override; | |||||
| procedure SetDrawPos(const aValue: TtsPosition); override; | procedure SetDrawPos(const aValue: TtsPosition); override; | ||||
| function GetDrawPos: TtsPosition; override; | function GetDrawPos: TtsPosition; override; | ||||
| procedure MoveDrawPos(const aOffset: TtsPosition); override; | procedure MoveDrawPos(const aOffset: TtsPosition); override; | ||||
| @@ -346,6 +347,12 @@ begin | |||||
| fRenderPos.y := 0; | fRenderPos.y := 0; | ||||
| end; | end; | ||||
| //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||||
| procedure TtsBaseOpenGL.EndRender; | |||||
| begin | |||||
| // DUMMY | |||||
| end; | |||||
| //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||||
| procedure TtsBaseOpenGL.SetDrawPos(const aValue: TtsPosition); | procedure TtsBaseOpenGL.SetDrawPos(const aValue: TtsPosition); | ||||
| begin | begin | ||||
| @@ -52,12 +52,15 @@ type | |||||
| fItems: TObjectList; | fItems: TObjectList; | ||||
| function GetCount: Integer; | function GetCount: Integer; | ||||
| function GetItem(const aIndex: Integer): TtsPostProcessor; | |||||
| function GetOwnsObjects: Boolean; | function GetOwnsObjects: Boolean; | ||||
| procedure SetOwnsObjects(const aValue: Boolean); | procedure SetOwnsObjects(const aValue: Boolean); | ||||
| public | public | ||||
| property Count: Integer read GetCount; | property Count: Integer read GetCount; | ||||
| property OwnsObjects: Boolean read GetOwnsObjects write SetOwnsObjects; | property OwnsObjects: Boolean read GetOwnsObjects write SetOwnsObjects; | ||||
| property Items[const aIndex: Integer]: TtsPostProcessor read GetItem; | |||||
| procedure Add(const aPostProcessor: TtsPostProcessor); | procedure Add(const aPostProcessor: TtsPostProcessor); | ||||
| procedure Delete(const aIndex: Integer); | procedure Delete(const aIndex: Integer); | ||||
| procedure Clear; | procedure Clear; | ||||
| @@ -279,6 +282,12 @@ begin | |||||
| result := fItems.Count; | result := fItems.Count; | ||||
| end; | end; | ||||
| //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||||
| function TtsPostProcessorList.GetItem(const aIndex: Integer): TtsPostProcessor; | |||||
| begin | |||||
| result := TtsPostProcessor(fItems[aIndex]); | |||||
| end; | |||||
| //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||||
| function TtsPostProcessorList.GetOwnsObjects: Boolean; | function TtsPostProcessorList.GetOwnsObjects: Boolean; | ||||
| begin | begin | ||||
| @@ -480,7 +489,7 @@ begin | |||||
| aImage.Width + 2 * fKernel.SizeX, | aImage.Width + 2 * fKernel.SizeX, | ||||
| aImage.Height + 2 * fKernel.SizeY, | aImage.Height + 2 * fKernel.SizeY, | ||||
| fKernel.SizeX, fKernel.SizeY); | fKernel.SizeX, fKernel.SizeY); | ||||
| orig := TtsImage.Create; | |||||
| orig := TtsImage.Create(fContext); | |||||
| try | try | ||||
| orig.Assign(aImage); | orig.Assign(aImage); | ||||
| aImage.FillColor(fColor, TS_COLOR_CHANNELS_RGBA, TS_IMAGE_MODES_REPLACE_ALL); | aImage.FillColor(fColor, TS_COLOR_CHANNELS_RGBA, TS_IMAGE_MODES_REPLACE_ALL); | ||||
| @@ -554,7 +563,7 @@ begin | |||||
| result := inherited Execute(aChar, aImage); | result := inherited Execute(aChar, aImage); | ||||
| if not result or not Assigned(aImage) then | if not result or not Assigned(aImage) then | ||||
| exit; | exit; | ||||
| orig := TtsImage.Create; | |||||
| orig := TtsImage.Create(fContext); | |||||
| try | try | ||||
| orig.Assign(aImage); | orig.Assign(aImage); | ||||
| aImage.Resize( | aImage.Resize( | ||||
| @@ -13,16 +13,19 @@ uses | |||||
| {$IFDEF TS_ENABLE_OPENGLES_SUPPORT} utsRendererOpenGLES,{$ENDIF} | {$IFDEF TS_ENABLE_OPENGLES_SUPPORT} utsRendererOpenGLES,{$ENDIF} | ||||
| {$IFDEF TS_ENABLE_GDI_SUPPORT} utsFontCreatorGDI,{$ENDIF} | {$IFDEF TS_ENABLE_GDI_SUPPORT} utsFontCreatorGDI,{$ENDIF} | ||||
| {$IFDEF TS_ENABLE_FREETYPE_SUPPORT} utsFontCreatorFreeType,{$ENDIF} | {$IFDEF TS_ENABLE_FREETYPE_SUPPORT} utsFontCreatorFreeType,{$ENDIF} | ||||
| utsContext, utsFont, utsTypes, utsTextBlock, utsChar, utsImage, utsPostProcessor; | |||||
| utsContext, utsFont, utsTypes, utsTextBlock, utsImage, | |||||
| utsPostProcessor, utsRenderer, utsFontCreator; | |||||
| type | type | ||||
| // TextSuite Classes | // TextSuite Classes | ||||
| TtsContext = utsContext.TtsContext; | TtsContext = utsContext.TtsContext; | ||||
| TtsRenderer = utsRenderer.TtsRenderer; | |||||
| TtsFontCreator = utsFontCreator.TtsFontCreator; | |||||
| TtsFont = utsFont.TtsFont; | TtsFont = utsFont.TtsFont; | ||||
| TtsTextBlock = utsTextBlock.TtsTextBlock; | TtsTextBlock = utsTextBlock.TtsTextBlock; | ||||
| TtsChar = utsChar.TtsChar; | |||||
| TtsImage = utsImage.TtsImage; | TtsImage = utsImage.TtsImage; | ||||
| TtsImageFunc = utsImage.TtsImageFunc; | |||||
| TtsImageLoadFunc = utsImage.TtsImageLoadFunc; | |||||
| TtsImageBlendFunc = utsImage.TtsImageBlendFunc; | |||||
| // Post Processor | // Post Processor | ||||
| TtsCharRangeUsage = utsPostProcessor.TtsCharRangeUsage; | TtsCharRangeUsage = utsPostProcessor.TtsCharRangeUsage; | ||||
| @@ -51,6 +54,7 @@ type | |||||
| TtsBlockFlag = utsTypes.TtsBlockFlag; | TtsBlockFlag = utsTypes.TtsBlockFlag; | ||||
| TtsBlockFlags = utsTypes.TtsBlockFlags; | TtsBlockFlags = utsTypes.TtsBlockFlags; | ||||
| TtsFontStyle = utsTypes.TtsFontStyle; | TtsFontStyle = utsTypes.TtsFontStyle; | ||||
| TtsFontStyles = utsTypes.TtsFontStyles; | |||||
| TtsColorChannel = utsTypes.TtsColorChannel; | TtsColorChannel = utsTypes.TtsColorChannel; | ||||
| TtsColorChannels = utsTypes.TtsColorChannels; | TtsColorChannels = utsTypes.TtsColorChannels; | ||||
| TtsImageMode = utsTypes.TtsImageMode; | TtsImageMode = utsTypes.TtsImageMode; | ||||
| @@ -161,13 +161,15 @@ type | |||||
| LineSpacing: Integer; | LineSpacing: Integer; | ||||
| end; | end; | ||||
| TtsFontMetric = packed record | |||||
| TtsFontNames = packed record | |||||
| Fontname: String; | Fontname: String; | ||||
| Copyright: String; | Copyright: String; | ||||
| FaceName: String; | |||||
| StyleName: String; | |||||
| FullName: String; | |||||
| Facename: String; | |||||
| Stylename: String; | |||||
| Fullname: String; | |||||
| end; | |||||
| TtsFontMetric = packed record | |||||
| Size: Integer; | Size: Integer; | ||||
| Style: TtsFontStyles; | Style: TtsFontStyles; | ||||
| AntiAliasing: TtsAntiAliasing; | AntiAliasing: TtsAntiAliasing; | ||||
| @@ -138,6 +138,8 @@ begin | |||||
| inherited Create; | inherited Create; | ||||
| fMasterRef := aMaster; | fMasterRef := aMaster; | ||||
| fSlaveRefs := TObjectList.Create(false); | fSlaveRefs := TObjectList.Create(false); | ||||
| if Assigned(fMasterRef) then | |||||
| fMasterRef.AddSlave(self); | |||||
| end; | end; | ||||
| //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||||