Browse Source

* implemented example for FPC

* fixed some memleaks and double freed objects
* updated submodule: TextSuite
master
Bergmann89 8 years ago
parent
commit
a3fcd76e3c
12 changed files with 804 additions and 569 deletions
  1. +2
    -1
      .gitignore
  2. +1
    -1
      TextSuite
  3. BIN
     
  4. +5
    -0
      header/examples/fpc/example.lpi
  5. +13
    -2
      header/examples/fpc/example.lpr
  6. +3
    -2
      header/examples/fpc/uMainForm.lfm
  7. +78
    -14
      header/examples/fpc/uMainForm.pas
  8. +656
    -548
      header/ulibTextSuite.pas
  9. +2
    -0
      libTextSuite.lpi
  10. +5
    -0
      libTextSuite.lpr
  11. +23
    -1
      ultsRenderer.pas
  12. +16
    -0
      ultsUtils.pas

+ 2
- 1
.gitignore View File

@@ -9,4 +9,5 @@ debug/
*.dbg
*.dll
*.zip

*.heaptrc
*.heaptrace

+ 1
- 1
TextSuite

@@ -1 +1 @@
Subproject commit a5f9cf19e54f765078e9490a6d678b5b3f87a3dc
Subproject commit 9ad90b9f7ca02386ea5ee359638c556ca9f457b4

BIN
View File


+ 5
- 0
header/examples/fpc/example.lpi View File

@@ -65,6 +65,10 @@
<UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/>
</SearchPaths>
<Linking>
<Debugging>
<UseHeaptrc Value="True"/>
<UseExternalDbgSyms Value="True"/>
</Debugging>
<Options>
<Win32>
<GraphicApplication Value="True"/>
@@ -75,6 +79,7 @@
<CompilerMessages>
<IgnoredMessages idx5024="True"/>
</CompilerMessages>
<CustomOptions Value="-dDUMP_HEAPTRACE"/>
</Other>
</CompilerOptions>
<Debugging>


+ 13
- 2
header/examples/fpc/example.lpr View File

@@ -6,12 +6,23 @@ uses
{$IFDEF UNIX}{$IFDEF UseCThreads}
cthreads,
{$ENDIF}{$ENDIF}
Interfaces, // this includes the LCL widgetset
Forms, uMainForm, ulibTextSuite;
Interfaces, SysUtils, Forms, uMainForm, ulibTextSuite;

{$R *.res}

{$IFDEF DUMP_HEAPTRACE}
var
heaptrcFile: String;
{$ENDIF}

begin
{$IFDEF DUMP_HEAPTRACE}
heaptrcFile := ChangeFileExt(Application.ExeName, '.heaptrc');
if (FileExists(heaptrcFile)) then
DeleteFile(heaptrcFile);
SetHeapTraceOutput(heaptrcFile);
{$ENDIF}

RequireDerivedFormResource := True;
Application.Initialize;
Application.CreateForm(TMainForm, MainForm);


+ 3
- 2
header/examples/fpc/uMainForm.lfm View File

@@ -1,12 +1,13 @@
object MainForm: TMainForm
Left = 485
Height = 240
Height = 500
Top = 255
Width = 320
Width = 640
Caption = 'libTextSuite'
OnCreate = FormCreate
OnDestroy = FormDestroy
OnPaint = FormPaint
OnResize = FormResize
Position = poScreenCenter
LCLVersion = '1.3'
end

+ 78
- 14
header/examples/fpc/uMainForm.pas View File

@@ -6,7 +6,7 @@ interface

uses
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs,
uglcContext;
uglcContext, ulibTextSuite;

type
TMainForm = class(TForm)
@@ -16,6 +16,11 @@ type
procedure FormResize(Sender: TObject);
private
fContext: TglcContext;
fltsContext: TltsContext;
fltsRenderer: TltsRendererOpenGL;
fltsCreator: TltsFontCreatorGDI;
fltsFont: TltsFont;
fltsPostProcessorList: TltsPostProcessorList;
procedure Render;
end;

@@ -29,13 +34,38 @@ implementation
uses
dglOpenGL;

const
{$IF DEFINED(WIN32)}
LibName = '..\..\..\libTextSuite-i386-win32.dll';
{$ELSEIF DEFINED(WIN64)}
LibName = '..\..\..\libTextSuite-x86_64-win64.dll';
{$ELSEIF DEFINED(LINUX) AND DEFINED(CPU32)}
LibName = '../../../libTextSuite-i386-linux.so';
{$ELSEIF DEFINED(LINUX) AND DEFINED(CPU64)}
LibName = '../../../libTextSuite-x86_64-linux.so';
{$ELSE}
{$ERROR 'unknown operation system'}
{$IFEND}

TEST_TEXT = 'Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.';

PATTER_DATA: array[0..15] of Byte = (
$FF, $BF, $7F, $BF,
$BF, $FF, $BF, $7F,
$7F, $BF, $FF, $BF,
$BF, $7F, $BF, $FF);

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//MainForm//////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
procedure TMainForm.FormCreate(Sender: TObject);
var
pf: TglcContextPixelFormatSettings;
pp: TltsPostProcessor;
img: TltsImage;
begin
ltsInitialize(LibName);

pf := TglcContext.MakePF();
fContext := TglcContext.GetPlatformClass.Create(self, pf);
fContext.BuildContext;
@@ -43,12 +73,43 @@ begin

glDisable(GL_DEPTH_TEST);
glDisable(GL_CULL_FACE);
glClearColor(1.0, 1.0, 1.0, 1.0);

fltsContext := TltsContext.Create;
fltsRenderer := TltsRendererOpenGL.Create(fltsContext, ltsFormatRGBA8);
fltsCreator := TltsFontCreatorGDI.Create(fltsContext);

fltsPostProcessorList := TltsPostProcessorList.Create(fltsContext, true);

img := TltsImage.Create(fltsContext);
img.CreateEmpty(ltsFormatAlpha8, 4, 4);
Move(PATTER_DATA[0], img.Data^, 16);
pp := TltsPostProcessorFillPattern.Create(fltsContext, img, true, ltsPosition(0, 0), LTS_IMAGE_MODES_MODULATE_ALL, LTS_COLOR_CHANNELS_RGBA);
pp.AddChars(ltsUsageInclude, 'Lorem');
fltsPostProcessorList.Add(pp);

pp := TltsPostProcessorFillColor.Create(fltsContext, ltsColor4f(0, 0, 0.5, 1), LTS_IMAGE_MODES_REPLACE_ALL, LTS_COLOR_CHANNELS_RGB);
pp.AddChars(ltsUsageExclude, 'e');
fltsPostProcessorList.Add(pp);

pp := TltsPostProcessorBorder.Create(fltsContext, 3.0, 0.5, ltsColor4f(0.0, 0.5, 0.0, 1.0), true);
pp.AddChars(ltsUsageInclude, 'e');
fltsPostProcessorList.Add(pp);

fltsFont := fltsCreator.GetFontByFile(ExpandFileName('../Prototype.ttf'), 40, [], ltsAANormal);
fltsFont.PostProcessor := fltsPostProcessorList;
end;

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
procedure TMainForm.FormDestroy(Sender: TObject);
begin
FreeAndNil(fltsFont);
FreeAndNil(fltsPostProcessorList);
FreeAndNil(fltsCreator);
FreeAndNil(fltsRenderer);
FreeAndNil(fltsContext);
FreeAndNil(fContext);
ltsFinalize;
end;

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -72,22 +133,25 @@ end;

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
procedure TMainForm.Render;
const
X = 100;
var
w, h: Integer;
block: TltsTextBlock;
begin
w := ClientWidth;
h := ClientHeight;

glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT);
glColor4f(1.0, 1.0, 1.0, 1.0);
glBegin(GL_QUADS);
glVertex2f(X, X);
glVertex2f(X, h-X);
glVertex2f(w-X, h-X);
glVertex2f(w-X, X);
glEnd;
glLoadIdentity;

glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

block := fltsRenderer.BeginBlock(10, 10, ClientWidth-20, ClientHeight-20, [ltsBlockFlagWordWrap]);
try
block.HorzAlign := ltsHorzAlignJustify;
block.ChangeFont(fltsFont);
block.ChangeColor(ltsColor4f(1.0, 1.0, 1.0, 1.0));
block.TextOutW(TEST_TEXT);
finally
fltsRenderer.EndBlock(block);
end;

fContext.SwapBuffers;
end;



+ 656
- 548
header/ulibTextSuite.pas
File diff suppressed because it is too large
View File


+ 2
- 0
libTextSuite.lpi View File

@@ -392,6 +392,7 @@
<Unit6>
<Filename Value="ultsGeneral.pas"/>
<IsPartOfProject Value="True"/>
<UnitName Value="ultsGeneral"/>
</Unit6>
<Unit7>
<Filename Value="ultsFont.pas"/>
@@ -447,6 +448,7 @@
<CompilerMessages>
<IgnoredMessages idx5024="True"/>
</CompilerMessages>
<CustomOptions Value="-dDUMP_HEAPTRACE"/>
</Other>
</CompilerOptions>
<Debugging>


+ 5
- 0
libTextSuite.lpr View File

@@ -13,9 +13,11 @@ exports
ltsContextGetDefaultChar,
ltsContextSetCodePage,
ltsContextSetDefaultChar,
ltsContextAnsiToWide,
ltsContextDestroy,

ltsRendererCreate,
ltsRendererCustomCreate,
ltsRendererBeginBlock,
ltsRendererEndBlock,
ltsRendererAbortBlock,
@@ -93,10 +95,13 @@ exports
ltsPostProcessorAddRange,
ltsPostProcessorAddChars,
ltsPostProcessorClearRanges,
ltsPostProcessorExecute,
ltsPostProcessorFillColorCreate,
ltsPostProcessorFillPatterCreate,
ltsPostProcessorBorderCreate,
ltsPostProcessorShadowCreate,
ltsPostProcessorCustomCreate,
ltsPostProcessorDestroy,

ltsCharGetCharCode,
ltsCharGetGlyphMetric,


+ 23
- 1
ultsRenderer.pas View File

@@ -49,19 +49,21 @@ function ltsRendererDestroy (const aHandle: TltsRendererHandle):
implementation

uses
ultsUtils;
ultsUtils, dglOpenGL, dglOpenGLES;

type
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
TltsRendererOpenGL = class(TtsRendererOpenGL)
public
procedure DelSlave(const aSlave: TtsRefManager); override;
constructor Create(const aContext: TtsContext; const aFormat: TtsFormat);
end;

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
TltsRendererOpenGLES = class(TtsRendererOpenGLES)
public
procedure DelSlave(const aSlave: TtsRefManager); override;
constructor Create(const aContext: TtsContext; const aFormat: TtsFormat);
end;

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -97,6 +99,15 @@ begin
inherited DelSlave(aSlave);
end;

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
constructor TltsRendererOpenGL.Create(const aContext: TtsContext; const aFormat: TtsFormat);
begin
dglOpenGL.InitOpenGL;
dglOpenGL.ReadExtensions;
dglOpenGL.ReadImplementationProperties;
inherited Create(aContext, aFormat);
end;

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//TltsRendererOpenGLES//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -106,6 +117,17 @@ begin
inherited DelSlave(aSlave);
end;

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
constructor TltsRendererOpenGLES.Create(const aContext: TtsContext; const aFormat: TtsFormat);
begin
dglOpenGLES.InitOpenGLES;
dglOpenGLES.ReadOpenGLCore;
dglOpenGLES.ReadExtensions;
dglOpenGLES.ReadCoreVersion;
dglOpenGLES.ReadImplementationProperties;
inherited Create(aContext, aFormat);
end;

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//TltsRendererCustom////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


+ 16
- 0
ultsUtils.pas View File

@@ -54,6 +54,11 @@ var

implementation

{$IFDEF DUMP_HEAPTRACE}
uses
heaptrc;
{$ENDIF}

type
TtsContextHashSet = specialize TutlHashSet<TtsContext>;
TtsRendererHashSet = specialize TutlHashSet<TtsRenderer>;
@@ -278,7 +283,18 @@ end;

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
procedure Initialize;
{$IFDEF DUMP_HEAPTRACE}
var
heaptrcFile: String;
{$ENDIF}
begin
{$IFDEF DUMP_HEAPTRACE}
heaptrcFile := ChangeFileExt(ParamStr(0), '.libTextSuite.heaptrc');
if (FileExists(heaptrcFile)) then
DeleteFile(heaptrcFile);
SetHeapTraceOutput(heaptrcFile);
{$ENDIF}

Contexts := TtsContextHashSet.Create(true);
Renderers := TtsRendererHashSet.Create(false);
TextBlocks := TtsTextBlockHashSet.Create(false);


Loading…
Cancel
Save