View Issue Details

IDProjectCategoryView StatusLast Update
0036569PatchesWidgetsetpublic2020-01-16 17:16
ReporterCudaText man Assigned ToJuha Manninen  
PrioritynormalSeverityminorReproducibilityN/A
Status resolvedResolutionfixed 
Product Version2.1 (SVN) 
Summary0036569: gtk3: TextOut with filled background
DescriptionTextOut must fill its back if Brush.Style<>bsNone.
I will make diff after you apply https://bugs.freepascal.org/view.php?id=36568
Dirty code in comments.
TagsNo tags attached.
Fixed in Revisionr62563
LazTarget-
WidgetsetGTK 3
Attached Files

Relationships

related to 0036568 closedJuha Manninen gtk3: TextOut cleanup 

Activities

CudaText man

2020-01-14 17:42

reporter   ~0120441

Patch and demo to test.
bk.diff (5,299 bytes)   
Index: lcl/interfaces/gtk3/gtk3objects.pas
===================================================================
--- lcl/interfaces/gtk3/gtk3objects.pas	(revision 62554)
+++ lcl/interfaces/gtk3/gtk3objects.pas	(working copy)
@@ -1267,33 +1267,50 @@
   RoundRect(x, y, w, h, rx, ry);
 end;
 
-procedure TGtk3DeviceContext.drawText(x, y: Integer; AText: PChar; ALen: Integer);
+procedure TGtk3DeviceContext.drawText(X, Y: Integer; AText: PChar; ALen: Integer);
 var
-  e: cairo_font_extents_t;
-  R: Double;
-  G: Double;
-  B: Double;
+  //e: cairo_font_extents_t;
+  R, G, B: Double;
+  gColor: TGdkColor;
+  Attr: PPangoAttribute;
+  AttrList: PPangoAttrList;
+  UseBack: boolean;
 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('EXTENTS !!!! ',Format('%2.2n',[e.ascent]));
+      // WriteLn('EXTENTS !!!! ',Format('%2.2n',[e.ascent]));
     end;
-    cairo_move_to(Widget, x, y {+ e.ascent});
-    // writeln('DevOffset ',Format('dx %2.2n dy %2.2n x %d y %d text %s',
-    //  [dx, dy, x, y, s]));
-    // pango_renderer_activate();
-    // pango_cairo_show_layout(Widget, Layout);
-    ColorToCairoRGB(TColor(CurrentTextColor), R, G , B);
+    }
+    cairo_move_to(Widget, X, Y {+ e.ascent});
+    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(AText, ALen);
-    // writeln('Family: ',FCurrentFont.Handle^.get_family,' size ',FCurrentFont.Handle^.get_size,' weight ',FCurrentFont.Handle^.get_weight);
+
+    UseBack := FCurrentBrush.Style <> BS_NULL;
+    if UseBack then
+    begin
+      gColor := TColorToTGDKColor(FCurrentBrush.Color);
+      AttrList := pango_attr_list_new;
+      Attr := pango_attr_background_new(gColor.red, gColor.green, gColor.blue);
+      pango_attr_list_insert(AttrList, Attr);
+      FCurrentFont.Layout^.set_attributes(AttrList);
+    end;
+
+    // WriteLn('Family: ',FCurrentFont.Handle^.get_family,' size ',FCurrentFont.Handle^.get_size,' weight ',FCurrentFont.Handle^.get_weight);
     pango_cairo_show_layout(Widget, FCurrentFont.Layout);
+
+    if UseBack then
+    begin
+      FCurrentFont.Layout^.set_attributes(nil);
+      pango_attribute_destroy(Attr);
+    end;
   finally
     cairo_restore(Widget);
   end;
Index: lcl/interfaces/gtk3/gtk3procs.pas
===================================================================
--- lcl/interfaces/gtk3/gtk3procs.pas	(revision 62554)
+++ lcl/interfaces/gtk3/gtk3procs.pas	(working copy)
@@ -279,7 +279,7 @@
 function Gtk3ScrollTypeToScrollCode(ScrollType: TGtkScrollType): LongWord;
 
 function TGDKColorToTColor(const value : TGDKColor) : TColor;
-function TColortoTGDKColor(const value : TColor) : TGDKColor;
+function TColorToTGDKColor(const value : TColor) : TGDKColor;
 function TGdkRGBAToTColor(const value : TGdkRGBA) : TColor;
 function TColortoTGdkRGBA(const value : TColor; IgnoreAlpha: Boolean = True) : TGdkRGBA;
 function ColorToCairoRGB(AColor: TColor; out ARed, AGreen, ABlue: Double): Boolean;
@@ -613,7 +613,7 @@
            + (Value.Red shr 8);
 end;
 
-function TColortoTGDKColor(const value : TColor) : TGDKColor;
+function TColorToTGDKColor(const value : TColor) : TGDKColor;
 begin
   if Value<0 then
   begin
Index: lcl/interfaces/gtk3/gtk3widgets.pas
===================================================================
--- lcl/interfaces/gtk3/gtk3widgets.pas	(revision 62554)
+++ lcl/interfaces/gtk3/gtk3widgets.pas	(working copy)
@@ -3021,7 +3021,7 @@
     StyleContext^.get_background_color(GTK_STATE_FLAG_NORMAL, @AGdkRGBA);
 
     // writeln('ACOLOR R=',AColor.Red,' G=',AColor.green,' B=',AColor.blue);
-    // AColor := TColortoTGDKColor(AValue);
+    // AColor := TColorToTGDKColor(AValue);
     {AGdkRGBA.alpha := 0;
     AGdkRGBA.red := AColor.red / 65535.00;
     AGdkRGBA.blue := AColor.blue / 65535.00;
@@ -3033,7 +3033,7 @@
     FWidget^.override_background_color(GTK_STATE_FLAG_SELECTED, @AGdkRGBA);
   end else
   begin
-    AColor := TColortoTGDKColor(AValue);
+    AColor := TColorToTGDKColor(AValue);
     // writeln('ACOLOR R=',AColor.Red,' G=',AColor.green,' B=',AColor.blue);
     //inherited SetColor(AValue);
   end;
Index: lcl/interfaces/gtk3/gtk3wsdialogs.pp
===================================================================
--- lcl/interfaces/gtk3/gtk3wsdialogs.pp	(revision 62554)
+++ lcl/interfaces/gtk3/gtk3wsdialogs.pp	(working copy)
@@ -1416,7 +1416,7 @@
 begin
   (*
   Color := TColor(ColorToRGB(Color));
-  SelectionColor := TColortoTGDKColor(Color);
+  SelectionColor := TColorToTGDKColor(Color);
   colorSel := PGtkColorSelection(ColorSelection^.colorsel);
   gtk_color_selection_set_current_color(colorSel, @SelectionColor);
   gtk_color_selection_set_previous_color(colorSel, @SelectionColor);
@@ -1443,7 +1443,7 @@
     for i := 0 to Palette.Count - 1 do
       if ExtractColorIndexAndColor(Palette, i, AIndex, AColor) then
         if AIndex < colors_len then
-          colors[AIndex] := TColortoTGDKColor(AColor);
+          colors[AIndex] := TColorToTGDKColor(AColor);
   end;
   *)
 begin
bk.diff (5,299 bytes)   

CudaText man

2020-01-14 17:43

reporter   ~0120443

Demo to test.

Juha Manninen

2020-01-16 17:16

developer   ~0120481

Applied, thanks.

Issue History

Date Modified Username Field Change
2020-01-14 00:37 CudaText man New Issue
2020-01-14 17:42 CudaText man File Added: bk.diff
2020-01-14 17:42 CudaText man Note Added: 0120441
2020-01-14 17:43 CudaText man File Added: Canvas figures tests.zip
2020-01-14 17:43 CudaText man Note Added: 0120443
2020-01-16 16:07 Juha Manninen Assigned To => Juha Manninen
2020-01-16 16:07 Juha Manninen Status new => assigned
2020-01-16 16:11 Juha Manninen Relationship added related to 0036568
2020-01-16 17:16 Juha Manninen Status assigned => resolved
2020-01-16 17:16 Juha Manninen Resolution open => fixed
2020-01-16 17:16 Juha Manninen Fixed in Revision => r62563
2020-01-16 17:16 Juha Manninen LazTarget => -
2020-01-16 17:16 Juha Manninen Widgetset GTK 3 => GTK 3
2020-01-16 17:16 Juha Manninen Note Added: 0120481