unit ultsPostProcessor; {$mode objfpc}{$H+} interface uses Classes, SysUtils, ultsTypes, utsTextSuite; function ltsPostProcessorAddRange (const aHandle: TltsPostProcessorHandle; const aUsage: TtsCharRangeUsage; const aStart, aStop: WideChar): TltsErrorCode; stdcall; function ltsPostProcessorAddChars (const aHandle: TltsPostProcessorHandle; const aUsage: TtsCharRangeUsage; const aChars: PWideChar): TltsErrorCode; stdcall; function ltsPostProcessorClearRanges (const aHandle: TltsPostProcessorHandle): TltsErrorCode; stdcall; function ltsPostProcessorFillColorCreate (const aContext: TltsContextHandle; const aColor: TtsColor4f; const aModes: TtsImageModes; const aChannels: TtsColorChannels): TltsPostProcessorHandle; stdcall; function ltsPostProcessorFillPatterCreate (const aContext: TltsContextHandle; const aPattern: TltsImageHandle; const aOwnsPatter: Boolean; const aPosition: TtsPosition; const aModes: TtsImageModes; const aChannels: TtsColorChannels): TltsPostProcessorHandle; stdcall; function ltsPostProcessorBorderCreate (const aContext: TltsContextHandle; const aWidth, aStrength: Single; const aColor: TtsColor4f; const aKeepSize: Boolean): TltsPostProcessorHandle; stdcall; function ltsPostProcessorShadowCreate (const aContext: TltsContextHandle; const aRadius, aStrength: Single; const aOffset: TtsPosition; const aColor: TtsColor4f): TltsPostProcessorHandle; stdcall; function ltsPostProcessorListCreate (const aContext: TltsContextHandle): TltsPostProcessorHandle; stdcall; function ltsPostProcessorListGetCount (const aHandle: TltsPostProcessorHandle): Integer; stdcall; function ltsPostProcessorListGetItem (const aHandle: TltsPostProcessorHandle; const aIndex: Integer): TltsPostProcessorHandle; stdcall; function ltsPostProcessorListGetOwnsObjects (const aHandle: TltsPostProcessorHandle; var aValue: Boolean): TltsErrorCode; stdcall; function ltsPostProcessorListSetOwnsObjects (const aHandle: TltsPostProcessorHandle; const aValue: Boolean): TltsErrorCode; stdcall; function ltsPostProcessorListAdd (const aHandle, aItem: TltsPostProcessorHandle): TltsErrorCode; stdcall; function ltsPostProcessorListDel (const aHandle: TltsPostProcessorHandle; const aIndex: Integer): TltsErrorCode; stdcall; function ltsPostProcessorListClear (const aHandle: TltsPostProcessorHandle): TltsErrorCode; stdcall; function ltsPostProcessorListRem (const aHandle, aItem: TltsPostProcessorHandle): Integer; stdcall; function ltsPostProcessorListIndexOf (const aHandle, aItem: TltsPostProcessorHandle): Integer; stdcall; implementation uses ultsUtils; //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //ltsPostProcessor////////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// function ltsPostProcessorAddRange(const aHandle: TltsPostProcessorHandle; const aUsage: TtsCharRangeUsage; const aStart, aStop: WideChar): TltsErrorCode; stdcall; var pp: TtsPostProcessor; begin try result := ltsErrNone; if ValidateCharRangeUsage(aUsage) and CheckPostProcessorHandle(aHandle, TtsPostProcessor, pp) then pp.AddRange(aUsage, aStart, aStop) else result := LastErrorCode; except on ex: Exception do begin SetLastError(ex); result := LastErrorCode; end; end; end; //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// function ltsPostProcessorAddChars(const aHandle: TltsPostProcessorHandle; const aUsage: TtsCharRangeUsage; const aChars: PWideChar): TltsErrorCode; stdcall; var pp: TtsPostProcessor; begin try result := ltsErrNone; if ValidateCharRangeUsage(aUsage) and CheckPostProcessorHandle(aHandle, TtsPostProcessor, pp) then pp.AddChars(aUsage, aChars) else result := LastErrorCode; except on ex: Exception do begin SetLastError(ex); result := LastErrorCode; end; end; end; //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// function ltsPostProcessorClearRanges(const aHandle: TltsPostProcessorHandle): TltsErrorCode; stdcall; var pp: TtsPostProcessor; begin try result := ltsErrNone; if CheckPostProcessorHandle(aHandle, TtsPostProcessor, pp) then pp.ClearRanges else result := LastErrorCode; except on ex: Exception do begin SetLastError(ex); result := LastErrorCode; end; end; end; //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// function ltsPostProcessorFillColorCreate(const aContext: TltsContextHandle; const aColor: TtsColor4f; const aModes: TtsImageModes; const aChannels: TtsColorChannels): TltsPostProcessorHandle; stdcall; var c: TtsContext; pp: TtsPostProcessor; begin try result := nil; if CheckContextHandle(aContext, c) then begin pp := TtsPostProcessorFillColor.Create(c, aColor, aModes, aChannels); AddReference(ltsObjTypePostProcessor, pp); result := pp; end; except on ex: Exception do begin SetLastError(ex); result := nil; end; end; end; //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// function ltsPostProcessorFillPatterCreate(const aContext: TltsContextHandle; const aPattern: TltsImageHandle; const aOwnsPatter: Boolean; const aPosition: TtsPosition; const aModes: TtsImageModes; const aChannels: TtsColorChannels): TltsPostProcessorHandle; stdcall; var c: TtsContext; img: TtsImage; pp: TtsPostProcessor; begin try result := nil; img := nil; if CheckContextHandle(aContext, c) and CheckImageHandle(aPattern, img) then begin pp := TtsPostProcessorFillPattern.Create(c, img, aOwnsPatter, aPosition, aModes, aChannels); AddReference(ltsObjTypePostProcessor, pp); if aOwnsPatter then DelReference(ltsObjTypeImage, img); result := pp; end; except on ex: Exception do begin SetLastError(ex); result := nil; end; end; end; //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// function ltsPostProcessorBorderCreate(const aContext: TltsContextHandle; const aWidth, aStrength: Single; const aColor: TtsColor4f; const aKeepSize: Boolean): TltsPostProcessorHandle; stdcall; var c: TtsContext; pp: TtsPostProcessor; begin try result := nil; if CheckContextHandle(aContext, c) then begin pp := TtsPostProcessorBorder.Create(c, aWidth, aStrength, aColor, aKeepSize); AddReference(ltsObjTypePostProcessor, pp); result := pp; end; except on ex: Exception do begin SetLastError(ex); result := nil; end; end; end; //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// function ltsPostProcessorShadowCreate(const aContext: TltsContextHandle; const aRadius, aStrength: Single; const aOffset: TtsPosition; const aColor: TtsColor4f): TltsPostProcessorHandle; stdcall; var c: TtsContext; pp: TtsPostProcessor; begin try result := nil; if CheckContextHandle(aContext, c) then begin pp := TtsPostProcessorShadow.Create(c, aRadius, aStrength, aOffset, aColor); AddReference(ltsObjTypePostProcessor, pp); result := pp; end; except on ex: Exception do begin SetLastError(ex); result := nil; end; end; end; //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// function ltsPostProcessorListCreate(const aContext: TltsContextHandle): TltsPostProcessorHandle; stdcall; var c: TtsContext; pp: TtsPostProcessor; begin try result := nil; if CheckContextHandle(aContext, c) then begin pp := TtsPostProcessorList.Create(c, false); AddReference(ltsObjTypePostProcessor, pp); result := pp; end; except on ex: Exception do begin SetLastError(ex); result := nil; end; end; end; //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// function ltsPostProcessorListGetCount(const aHandle: TltsPostProcessorHandle): Integer; stdcall; var pp: TtsPostProcessorList; begin try if CheckPostProcessorHandle(aHandle, TtsPostProcessorList, pp) then result := pp.Count else result := -1; except on ex: Exception do begin SetLastError(ex); result := -1; end; end; end; //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// function ltsPostProcessorListGetItem(const aHandle: TltsPostProcessorHandle; const aIndex: Integer): TltsPostProcessorHandle; stdcall; var pp: TtsPostProcessorList; begin try result := nil; if CheckPostProcessorHandle(aHandle, TtsPostProcessorList, pp) then begin if (aIndex < 0) or (aIndex >= pp.Count) then SetLastError(ltsErrInvalidValue, 'index is out of range') else result := pp.Items[aIndex]; end else result := nil; except on ex: Exception do begin SetLastError(ex); result := nil; end; end; end; //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// function ltsPostProcessorListGetOwnsObjects(const aHandle: TltsPostProcessorHandle; var aValue: Boolean): TltsErrorCode; stdcall; var pp: TtsPostProcessorList; begin try result := ltsErrNone; if CheckPostProcessorHandle(aHandle, TtsPostProcessorList, pp) then aValue := pp.OwnsObjects else result := LastErrorCode; except on ex: Exception do begin SetLastError(ex); result := LastErrorCode; end; end; end; //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// function ltsPostProcessorListSetOwnsObjects(const aHandle: TltsPostProcessorHandle; const aValue: Boolean): TltsErrorCode; stdcall; var pp: TtsPostProcessorList; begin try result := ltsErrNone; if CheckPostProcessorHandle(aHandle, TtsPostProcessorList, pp) then pp.OwnsObjects := aValue else result := LastErrorCode; except on ex: Exception do begin SetLastError(ex); result := LastErrorCode; end; end; end; //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// function ltsPostProcessorListAdd(const aHandle, aItem: TltsPostProcessorHandle): TltsErrorCode; stdcall; var pp, itm: TtsPostProcessorList; begin try result := ltsErrNone; if CheckPostProcessorHandle(aHandle, TtsPostProcessorList, pp) and CheckPostProcessorHandle(aItem, TtsPostProcessor, itm) then pp.Add(itm) else result := LastErrorCode; except on ex: Exception do begin SetLastError(ex); result := LastErrorCode; end; end; end; //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// function ltsPostProcessorListDel(const aHandle: TltsPostProcessorHandle; const aIndex: Integer): TltsErrorCode; stdcall; var pp: TtsPostProcessorList; begin try result := ltsErrNone; if CheckPostProcessorHandle(aHandle, TtsPostProcessorList, pp) then begin if (aIndex < 0) or (aIndex >= pp.Count) then begin SetLastError(ltsErrInvalidValue, 'index is out of range'); result := LastErrorCode end else pp.Delete(aIndex); end else result := LastErrorCode; except on ex: Exception do begin SetLastError(ex); result := LastErrorCode; end; end; end; //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// function ltsPostProcessorListClear(const aHandle: TltsPostProcessorHandle): TltsErrorCode; stdcall; var pp: TtsPostProcessorList; begin try result := ltsErrNone; if CheckPostProcessorHandle(aHandle, TtsPostProcessorList, pp) then pp.ClearRanges else result := LastErrorCode; except on ex: Exception do begin SetLastError(ex); result := LastErrorCode; end; end; end; //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// function ltsPostProcessorListRem(const aHandle, aItem: TltsPostProcessorHandle): Integer; stdcall; var pp, itm: TtsPostProcessorList; begin try result := -1; if CheckPostProcessorHandle(aHandle, TtsPostProcessorList, pp) and CheckPostProcessorHandle(aItem, TtsPostProcessor, itm) then result := pp.Remove(itm) else result := -1; except on ex: Exception do begin SetLastError(ex); result := -1; end; end; end; //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// function ltsPostProcessorListIndexOf(const aHandle, aItem: TltsPostProcessorHandle): Integer; stdcall; var pp, itm: TtsPostProcessorList; begin try result := -1; if CheckPostProcessorHandle(aHandle, TtsPostProcessorList, pp) and CheckPostProcessorHandle(aItem, TtsPostProcessor, itm) then result := pp.IndexOf(itm) else result := -1; except on ex: Exception do begin SetLastError(ex); result := -1; end; end; end; end.