mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-17 04:29:28 +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,35 +32,20 @@ interface
|
|||||||
|
|
||||||
uses
|
uses
|
||||||
glib2, gdk2pixbuf, pango, gdk2, gtk2,
|
glib2, gdk2pixbuf, pango, gdk2, gtk2,
|
||||||
GtkExtra, GtkDef;
|
GtkExtra, GtkDef, SysUtils;
|
||||||
|
|
||||||
//paul: this improvement brings an issue: 0011523
|
|
||||||
{off $define gtk2_improve_TextOut_speed}
|
|
||||||
|
|
||||||
type
|
type
|
||||||
{$ifdef gtk2_improve_TextOut_speed}
|
|
||||||
TSetTextArgs = record
|
|
||||||
Font: PPangoLayout;
|
|
||||||
Len: LongInt;
|
|
||||||
Text: array of char;
|
|
||||||
end;
|
|
||||||
{$endif}
|
|
||||||
|
|
||||||
{ TGtk2DeviceContext }
|
{ TGtk2DeviceContext }
|
||||||
|
|
||||||
TGtk2DeviceContext = class(TGtkDeviceContext)
|
TGtk2DeviceContext = class(TGtkDeviceContext)
|
||||||
private
|
|
||||||
{$ifdef gtk2_improve_TextOut_speed}
|
|
||||||
OldText: TSetTextArgs;
|
|
||||||
{$endif}
|
|
||||||
protected
|
protected
|
||||||
function GetFunction: TGdkFunction; override;
|
function GetFunction: TGdkFunction; override;
|
||||||
public
|
public
|
||||||
constructor Create; override;
|
|
||||||
procedure SetText(AFont: PPangoLayout; AText: PChar; ALength: LongInt);
|
|
||||||
procedure DrawTextWithColors(AText: PChar; ALength: LongInt; X, Y: Integer; FGColor, BGColor: PGdkColor);
|
procedure DrawTextWithColors(AText: PChar; ALength: LongInt; X, Y: Integer; FGColor, BGColor: PGdkColor);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure SetLayoutText(ALayout: PPangoLayout; AText: PChar; ALength: LongInt);
|
||||||
|
|
||||||
implementation
|
implementation
|
||||||
{$i gtk2devicecontext.inc}
|
{$i gtk2devicecontext.inc}
|
||||||
|
|
||||||
|
@ -24,6 +24,23 @@
|
|||||||
// {$DEFINE ASSERT_IS_ON}
|
// {$DEFINE ASSERT_IS_ON}
|
||||||
{$ENDIF}
|
{$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 }
|
{ TGtk2DeviceContext }
|
||||||
|
|
||||||
function TGtk2DeviceContext.GetFunction: TGdkFunction;
|
function TGtk2DeviceContext.GetFunction: TGdkFunction;
|
||||||
@ -31,30 +48,6 @@ begin
|
|||||||
Result := GCValues._function;
|
Result := GCValues._function;
|
||||||
end;
|
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;
|
procedure TGtk2DeviceContext.DrawTextWithColors(AText: PChar; ALength: LongInt;
|
||||||
X, Y: Integer; FGColor, BGColor: PGdkColor);
|
X, Y: Integer; FGColor, BGColor: PGdkColor);
|
||||||
var
|
var
|
||||||
@ -74,7 +67,7 @@ var
|
|||||||
|
|
||||||
begin
|
begin
|
||||||
AFont := GetFont;
|
AFont := GetFont;
|
||||||
SetText(AFont^.GDIFontObject, AText, ALength);
|
SetLayoutText(AFont^.GDIFontObject, AText, ALength);
|
||||||
|
|
||||||
if AFont^.LogFont.lfEscapement <> 0 then
|
if AFont^.LogFont.lfEscapement <> 0 then
|
||||||
begin
|
begin
|
||||||
@ -110,4 +103,8 @@ begin
|
|||||||
gdk_draw_layout_with_colors(drawable, GC, X, Y, AFont^.GDIFontObject, FGColor, BGColor);
|
gdk_draw_layout_with_colors(drawable, GC, X, Y, AFont^.GDIFontObject, FGColor, BGColor);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
initialization
|
||||||
|
TextLengthQuark := g_quark_from_static_string('layouttextlength');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -496,7 +496,7 @@ begin
|
|||||||
|
|
||||||
UpdateDCTextMetric(TGtkDeviceContext(DC));
|
UpdateDCTextMetric(TGtkDeviceContext(DC));
|
||||||
|
|
||||||
TGtk2DeviceContext(DC).SetText(UseFont, Str, Count);
|
SetLayoutText(UseFont, Str, Count);
|
||||||
pango_layout_get_pixel_size(UseFont, @Size.cX, @Size.cY);
|
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]);
|
//DebugLn(['TGtk2WidgetSet.GetTextExtentPoint Str="',copy(Str,1,Count),' Count=',Count,' X=',Size.cx,' Y=',Size.cY]);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user