View Issue Details

IDProjectCategoryView StatusLast Update
0036568PatchesWidgetsetpublic2020-01-16 16:11
ReporterCudaText manAssigned ToJuha Manninen 
PrioritynormalSeverityminorReproducibilityN/A
Status closedResolutionfixed 
Product Version2.1 (SVN)Product Build 
Target VersionFixed in Version 
Summary0036568: gtk3: TextOut cleanup
Description- optimized internal func DrawText to use AText/ALen instead of string
- removed 2nd internal func DrawText(x,y,w,h,flags...) which did NOT use w/h/flags params and duplicated 1st DrawText
TagsNo tags attached.
Fixed in Revisionr62552
LazTarget-
WidgetsetGTK 3
Attached Files
  • opt.diff (4,017 bytes)
    Index: lcl/interfaces/gtk3/gtk3objects.pas
    ===================================================================
    --- lcl/interfaces/gtk3/gtk3objects.pas	(revision 62533)
    +++ lcl/interfaces/gtk3/gtk3objects.pas	(working copy)
    @@ -220,8 +220,7 @@
         function getPixel(x, y: Integer): TColor;
         procedure drawRect(x1, y1, w, h: Integer; const AFill, ABorder: Boolean);
         procedure drawRoundRect(x, y, w, h, rx, ry: Integer);
    -    procedure drawText(x: Integer; y: Integer; const s: String); overload;
    -    procedure drawText(x,y,w,h,flags: Integer; const s: String); overload;
    +    procedure drawText(x, y: Integer; AText: PChar; ALen: Integer);
         procedure drawEllipse(x, y, w, h: Integer; AFill, ABorder: Boolean);
         procedure drawSurface(targetRect: PRect; Surface: Pcairo_surface_t; sourceRect: PRect;
           mask: PGdkPixBuf; maskRect: PRect);
    @@ -1268,7 +1267,7 @@
       RoundRect(x, y, w, h, rx, ry);
     end;
     
    -procedure TGtk3DeviceContext.drawText(x: Integer; y: Integer; const s: String);
    +procedure TGtk3DeviceContext.drawText(x, y: Integer; AText: PChar; ALen: Integer);
     var
       e: cairo_font_extents_t;
       R: Double;
    @@ -1292,7 +1291,7 @@
         ColorToCairoRGB(TColor(CurrentTextColor), R, G , B);
         cairo_set_source_rgb(Widget, R, G, B);
         // writeln('DRAWINGTEXT ',S,' WITH R=',dbgs(R),' G=',dbgs(G),' B=',dbgs(B));
    -    FCurrentFont.Layout^.set_text(PChar(S), length(S));
    +    FCurrentFont.Layout^.set_text(AText, ALen);
         // writeln('Family: ',FCurrentFont.Handle^.get_family,' size ',FCurrentFont.Handle^.get_size,' weight ',FCurrentFont.Handle^.get_weight);
         pango_cairo_show_layout(Widget, FCurrentFont.Layout);
       finally
    @@ -1300,35 +1299,6 @@
       end;
     end;
     
    -procedure TGtk3DeviceContext.drawText(x, y, w, h, flags: Integer; const s: String
    -  );
    -var
    -  e: cairo_font_extents_t;
    -  R: Double;
    -  G: Double;
    -  B: Double;
    -  // dx, dy: Double;
    -begin
    -  cairo_save(Widget);
    -  try
    -    // TranslateCairoToDevice;
    -    // cairo_surface_get_device_offset(CairoSurface, @dx, @dy);
    -    cairo_font_extents(Widget, @e);
    -    if e.ascent <> 0 then
    -    begin
    -      // writeln('2.EXTENTS !!!! ',Format('%2.2n',[e.ascent]));
    -    end;
    -    cairo_move_to(Widget, x, y + e.ascent);
    -    ColorToCairoRGB(CurrentTextColor, R, G , B);
    -    cairo_set_source_rgb(Widget, R, G, B);
    -    // cairo_show_text(Widget, PChar(s));
    -    FCurrentFont.Layout^.set_text(PChar(S), length(S));
    -    pango_cairo_show_layout(Widget, FCurrentFont.Layout);
    -  finally
    -    cairo_restore(Widget);
    -  end;
    -end;
    -
     procedure TGtk3DeviceContext.drawEllipse(x, y, w, h: Integer; AFill, ABorder: Boolean);
     var
       save_matrix:cairo_matrix_t;
    Index: lcl/interfaces/gtk3/gtk3winapi.inc
    ===================================================================
    --- lcl/interfaces/gtk3/gtk3winapi.inc	(revision 62533)
    +++ lcl/interfaces/gtk3/gtk3winapi.inc	(working copy)
    @@ -1560,7 +1560,7 @@
       if IsValidDC(DC) then
       begin
         Result := True;
    -    TGtk3DeviceContext(DC).drawText(X, Y , Str);
    +    TGtk3DeviceContext(DC).drawText(X, Y, Str, Count);
       end;
     end;
     
    @@ -4098,23 +4098,18 @@
       Result:=inherited SystemParametersInfo(uiAction, uiParam, pvParam, fWinIni);
     end;
     
    -function TGtk3WidgetSet.TextOut(DC: HDC; X, Y: Integer; Str: Pchar;
    -  Count: Integer): Boolean;
    -var
    -  S: String;
    +function TGtk3WidgetSet.TextOut(DC: HDC; X, Y: Integer; Str: PChar; Count: Integer): Boolean;
     begin
    -  // Result:=inherited TextOut(DC, X, Y, Str, Count);
       {$IFDEF VerboseGtk3DeviceContext}
    -  DebugLn('TGtk3WidgetSet.TextOut x=',dbgs(x),' y=',dbgs(y),' Text ',dbgs(Str),' count ',dbgs(Count));
    +  DebugLn('TGtk3WidgetSet.TextOut X=',dbgs(x),' Y=',dbgs(y),' Text=',dbgs(Str),' Count=',dbgs(Count));
       {$ENDIF}
       Result := False;
    +  if Count <= 0 then
    +    Exit;
       if IsValidDC(DC) then
       begin
         Result := True;
    -    S := StrPas(Str);
    -    if Count > 0 then
    -      S := UTF8Copy(S, 1, Count);
    -    TGtk3DeviceContext(DC).drawText(X, Y , S);
    +    TGtk3DeviceContext(DC).drawText(X, Y, Str, Count);
       end;
     end;
     
    
    opt.diff (4,017 bytes)

Relationships

related to 0036569 resolvedJuha Manninen gtk3: TextOut with filled background 

Activities

CudaText man

2020-01-13 23:38

reporter  

opt.diff (4,017 bytes)
Index: lcl/interfaces/gtk3/gtk3objects.pas
===================================================================
--- lcl/interfaces/gtk3/gtk3objects.pas	(revision 62533)
+++ lcl/interfaces/gtk3/gtk3objects.pas	(working copy)
@@ -220,8 +220,7 @@
     function getPixel(x, y: Integer): TColor;
     procedure drawRect(x1, y1, w, h: Integer; const AFill, ABorder: Boolean);
     procedure drawRoundRect(x, y, w, h, rx, ry: Integer);
-    procedure drawText(x: Integer; y: Integer; const s: String); overload;
-    procedure drawText(x,y,w,h,flags: Integer; const s: String); overload;
+    procedure drawText(x, y: Integer; AText: PChar; ALen: Integer);
     procedure drawEllipse(x, y, w, h: Integer; AFill, ABorder: Boolean);
     procedure drawSurface(targetRect: PRect; Surface: Pcairo_surface_t; sourceRect: PRect;
       mask: PGdkPixBuf; maskRect: PRect);
@@ -1268,7 +1267,7 @@
   RoundRect(x, y, w, h, rx, ry);
 end;
 
-procedure TGtk3DeviceContext.drawText(x: Integer; y: Integer; const s: String);
+procedure TGtk3DeviceContext.drawText(x, y: Integer; AText: PChar; ALen: Integer);
 var
   e: cairo_font_extents_t;
   R: Double;
@@ -1292,7 +1291,7 @@
     ColorToCairoRGB(TColor(CurrentTextColor), R, G , B);
     cairo_set_source_rgb(Widget, R, G, B);
     // writeln('DRAWINGTEXT ',S,' WITH R=',dbgs(R),' G=',dbgs(G),' B=',dbgs(B));
-    FCurrentFont.Layout^.set_text(PChar(S), length(S));
+    FCurrentFont.Layout^.set_text(AText, ALen);
     // writeln('Family: ',FCurrentFont.Handle^.get_family,' size ',FCurrentFont.Handle^.get_size,' weight ',FCurrentFont.Handle^.get_weight);
     pango_cairo_show_layout(Widget, FCurrentFont.Layout);
   finally
@@ -1300,35 +1299,6 @@
   end;
 end;
 
-procedure TGtk3DeviceContext.drawText(x, y, w, h, flags: Integer; const s: String
-  );
-var
-  e: cairo_font_extents_t;
-  R: Double;
-  G: Double;
-  B: Double;
-  // dx, dy: Double;
-begin
-  cairo_save(Widget);
-  try
-    // TranslateCairoToDevice;
-    // cairo_surface_get_device_offset(CairoSurface, @dx, @dy);
-    cairo_font_extents(Widget, @e);
-    if e.ascent <> 0 then
-    begin
-      // writeln('2.EXTENTS !!!! ',Format('%2.2n',[e.ascent]));
-    end;
-    cairo_move_to(Widget, x, y + e.ascent);
-    ColorToCairoRGB(CurrentTextColor, R, G , B);
-    cairo_set_source_rgb(Widget, R, G, B);
-    // cairo_show_text(Widget, PChar(s));
-    FCurrentFont.Layout^.set_text(PChar(S), length(S));
-    pango_cairo_show_layout(Widget, FCurrentFont.Layout);
-  finally
-    cairo_restore(Widget);
-  end;
-end;
-
 procedure TGtk3DeviceContext.drawEllipse(x, y, w, h: Integer; AFill, ABorder: Boolean);
 var
   save_matrix:cairo_matrix_t;
Index: lcl/interfaces/gtk3/gtk3winapi.inc
===================================================================
--- lcl/interfaces/gtk3/gtk3winapi.inc	(revision 62533)
+++ lcl/interfaces/gtk3/gtk3winapi.inc	(working copy)
@@ -1560,7 +1560,7 @@
   if IsValidDC(DC) then
   begin
     Result := True;
-    TGtk3DeviceContext(DC).drawText(X, Y , Str);
+    TGtk3DeviceContext(DC).drawText(X, Y, Str, Count);
   end;
 end;
 
@@ -4098,23 +4098,18 @@
   Result:=inherited SystemParametersInfo(uiAction, uiParam, pvParam, fWinIni);
 end;
 
-function TGtk3WidgetSet.TextOut(DC: HDC; X, Y: Integer; Str: Pchar;
-  Count: Integer): Boolean;
-var
-  S: String;
+function TGtk3WidgetSet.TextOut(DC: HDC; X, Y: Integer; Str: PChar; Count: Integer): Boolean;
 begin
-  // Result:=inherited TextOut(DC, X, Y, Str, Count);
   {$IFDEF VerboseGtk3DeviceContext}
-  DebugLn('TGtk3WidgetSet.TextOut x=',dbgs(x),' y=',dbgs(y),' Text ',dbgs(Str),' count ',dbgs(Count));
+  DebugLn('TGtk3WidgetSet.TextOut X=',dbgs(x),' Y=',dbgs(y),' Text=',dbgs(Str),' Count=',dbgs(Count));
   {$ENDIF}
   Result := False;
+  if Count <= 0 then
+    Exit;
   if IsValidDC(DC) then
   begin
     Result := True;
-    S := StrPas(Str);
-    if Count > 0 then
-      S := UTF8Copy(S, 1, Count);
-    TGtk3DeviceContext(DC).drawText(X, Y , S);
+    TGtk3DeviceContext(DC).drawText(X, Y, Str, Count);
   end;
 end;
 
opt.diff (4,017 bytes)

Juha Manninen

2020-01-14 17:28

developer   ~0120440

Applied, thanks.

This indeed looked less than ideal:
  S := StrPas(Str);
  if Count > 0 then
    S := UTF8Copy(S, 1, Count);
  TGtk3DeviceContext(DC).drawText(X, Y , S);

Issue History

Date Modified Username Field Change
2020-01-13 23:38 CudaText man New Issue
2020-01-13 23:38 CudaText man File Added: opt.diff
2020-01-14 17:28 Juha Manninen Assigned To => Juha Manninen
2020-01-14 17:28 Juha Manninen Status new => resolved
2020-01-14 17:28 Juha Manninen Resolution open => fixed
2020-01-14 17:28 Juha Manninen Fixed in Revision => r62552
2020-01-14 17:28 Juha Manninen LazTarget => -
2020-01-14 17:28 Juha Manninen Widgetset GTK 3 => GTK 3
2020-01-14 17:28 Juha Manninen Note Added: 0120440
2020-01-14 17:37 CudaText man Status resolved => closed
2020-01-16 16:11 Juha Manninen Relationship added related to 0036569