mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-04-18 14:09:26 +02:00
gtk2 intf: implemented optimization for textout with the same text from Luiz
git-svn-id: trunk@15758 -
This commit is contained in:
parent
1a90e139a9
commit
50c3731145
@ -32,34 +32,19 @@ interface
|
||||
|
||||
uses
|
||||
glib2, gdk2pixbuf, pango, gdk2, gtk2,
|
||||
GtkExtra, GtkDef;
|
||||
|
||||
//paul: this improvement brings an issue: 0011523
|
||||
{off $define gtk2_improve_TextOut_speed}
|
||||
GtkExtra, GtkDef, SysUtils;
|
||||
|
||||
type
|
||||
{$ifdef gtk2_improve_TextOut_speed}
|
||||
TSetTextArgs = record
|
||||
Font: PPangoLayout;
|
||||
Len: LongInt;
|
||||
Text: array of char;
|
||||
end;
|
||||
{$endif}
|
||||
|
||||
{ TGtk2DeviceContext }
|
||||
|
||||
TGtk2DeviceContext = class(TGtkDeviceContext)
|
||||
private
|
||||
{$ifdef gtk2_improve_TextOut_speed}
|
||||
OldText: TSetTextArgs;
|
||||
{$endif}
|
||||
protected
|
||||
function GetFunction: TGdkFunction; override;
|
||||
public
|
||||
constructor Create; override;
|
||||
procedure SetText(AFont: PPangoLayout; AText: PChar; ALength: LongInt);
|
||||
procedure DrawTextWithColors(AText: PChar; ALength: LongInt; X, Y: Integer; FGColor, BGColor: PGdkColor);
|
||||
end;
|
||||
|
||||
procedure SetLayoutText(ALayout: PPangoLayout; AText: PChar; ALength: LongInt);
|
||||
|
||||
implementation
|
||||
{$i gtk2devicecontext.inc}
|
||||
|
@ -24,6 +24,23 @@
|
||||
// {$DEFINE ASSERT_IS_ON}
|
||||
{$ENDIF}
|
||||
|
||||
var
|
||||
TextLengthQuark: TGQuark;
|
||||
|
||||
procedure SetLayoutText(ALayout: PPangoLayout; AText: PChar; ALength: LongInt);
|
||||
var
|
||||
OldStr: PChar;
|
||||
OldLength: Integer;
|
||||
begin
|
||||
OldStr := pango_layout_get_text(ALayout);
|
||||
OldLength := PtrInt(g_object_get_qdata(PGObject(ALayout), TextLengthQuark));
|
||||
if (OldLength <> ALength) or (CompareByte(AText^, OldStr^, ALength) <> 0) then
|
||||
begin
|
||||
pango_layout_set_text(ALayout, AText, ALength);
|
||||
g_object_set_qdata(PGObject(ALayout), TextLengthQuark, gpointer(PtrInt(ALength)));
|
||||
end;
|
||||
end;
|
||||
|
||||
{ TGtk2DeviceContext }
|
||||
|
||||
function TGtk2DeviceContext.GetFunction: TGdkFunction;
|
||||
@ -31,30 +48,6 @@ begin
|
||||
Result := GCValues._function;
|
||||
end;
|
||||
|
||||
constructor TGtk2DeviceContext.Create;
|
||||
begin
|
||||
inherited Create;
|
||||
{$ifdef gtk2_improve_TextOut_speed}
|
||||
FillChar(OldText, SizeOf(OldText), 0);
|
||||
{$endif}
|
||||
end;
|
||||
|
||||
procedure TGtk2DeviceContext.SetText(AFont: PPangoLayout; AText: PChar; ALength: LongInt);
|
||||
begin
|
||||
{$ifdef gtk2_improve_TextOut_speed}
|
||||
if (OldText.Font <> AFont) or (OldText.Len <> ALength) or (CompareChar(AText^, PChar(OldText.Text)^, ALength) <> 0) then
|
||||
begin
|
||||
pango_layout_set_text(AFont, AText, ALength);
|
||||
OldText.Font := AFont;
|
||||
OldText.Len := ALength;
|
||||
SetLength(OldText.Text, ALength);
|
||||
Move(AText^, PChar(OldText.Text)^, ALength);
|
||||
end;
|
||||
{$else}
|
||||
pango_layout_set_text(AFont, AText, ALength);
|
||||
{$endif}
|
||||
end;
|
||||
|
||||
procedure TGtk2DeviceContext.DrawTextWithColors(AText: PChar; ALength: LongInt;
|
||||
X, Y: Integer; FGColor, BGColor: PGdkColor);
|
||||
var
|
||||
@ -74,7 +67,7 @@ var
|
||||
|
||||
begin
|
||||
AFont := GetFont;
|
||||
SetText(AFont^.GDIFontObject, AText, ALength);
|
||||
SetLayoutText(AFont^.GDIFontObject, AText, ALength);
|
||||
|
||||
if AFont^.LogFont.lfEscapement <> 0 then
|
||||
begin
|
||||
@ -110,4 +103,8 @@ begin
|
||||
gdk_draw_layout_with_colors(drawable, GC, X, Y, AFont^.GDIFontObject, FGColor, BGColor);
|
||||
end;
|
||||
|
||||
initialization
|
||||
TextLengthQuark := g_quark_from_static_string('layouttextlength');
|
||||
|
||||
|
||||
|
||||
|
@ -496,7 +496,7 @@ begin
|
||||
|
||||
UpdateDCTextMetric(TGtkDeviceContext(DC));
|
||||
|
||||
TGtk2DeviceContext(DC).SetText(UseFont, Str, Count);
|
||||
SetLayoutText(UseFont, Str, Count);
|
||||
pango_layout_get_pixel_size(UseFont, @Size.cX, @Size.cY);
|
||||
//DebugLn(['TGtk2WidgetSet.GetTextExtentPoint Str="',copy(Str,1,Count),' Count=',Count,' X=',Size.cx,' Y=',Size.cY]);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user