Ver a proveniência

* implemented example for FPC

* fixed some memleaks and double freed objects
* updated submodule: TextSuite
master
Bergmann89 há 8 anos
ascendente
cometimento
a3fcd76e3c
12 ficheiros alterados com 804 adições e 569 eliminações
  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 Ver ficheiro

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

*.heaptrc
*.heaptrace

+ 1
- 1
TextSuite

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


+ 5
- 0
header/examples/fpc/example.lpi Ver ficheiro

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


+ 13
- 2
header/examples/fpc/example.lpr Ver ficheiro

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


{$R *.res} {$R *.res}


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

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

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


+ 3
- 2
header/examples/fpc/uMainForm.lfm Ver ficheiro

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

+ 78
- 14
header/examples/fpc/uMainForm.pas Ver ficheiro

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


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


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


@@ -29,13 +34,38 @@ implementation
uses uses
dglOpenGL; 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////////////////////////////////////////////////////////////////////////////////////////////////////////////// //MainForm//////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
procedure TMainForm.FormCreate(Sender: TObject); procedure TMainForm.FormCreate(Sender: TObject);
var var
pf: TglcContextPixelFormatSettings; pf: TglcContextPixelFormatSettings;
pp: TltsPostProcessor;
img: TltsImage;
begin begin
ltsInitialize(LibName);

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


glDisable(GL_DEPTH_TEST); glDisable(GL_DEPTH_TEST);
glDisable(GL_CULL_FACE); 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; end;


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


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


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

glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT); 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; fContext.SwapBuffers;
end; end;




+ 656
- 548
header/ulibTextSuite.pas
A apresentação das diferenças no ficheiro foi suprimida por ser demasiado grande
Ver ficheiro


+ 2
- 0
libTextSuite.lpi Ver ficheiro

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


+ 5
- 0
libTextSuite.lpr Ver ficheiro

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


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


ltsCharGetCharCode, ltsCharGetCharCode,
ltsCharGetGlyphMetric, ltsCharGetGlyphMetric,


+ 23
- 1
ultsRenderer.pas Ver ficheiro

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


uses uses
ultsUtils;
ultsUtils, dglOpenGL, dglOpenGLES;


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


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


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


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

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//TltsRendererOpenGLES////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //TltsRendererOpenGLES//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -106,6 +117,17 @@ begin
inherited DelSlave(aSlave); inherited DelSlave(aSlave);
end; 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//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //TltsRendererCustom////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


+ 16
- 0
ultsUtils.pas Ver ficheiro

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


implementation implementation


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

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


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

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


Carregando…
Cancelar
Guardar