View Issue Details

IDProjectCategoryView StatusLast Update
0035699LazarusPatchpublic2019-06-11 14:57
ReporterAnton KavalenkaAssigned To 
PrioritynormalSeverityminorReproducibilityalways
Status newResolutionopen 
Product Version2.0.3 (SVN)Product Build 
Target VersionFixed in Version 
Summary0035699: gtk3: Implement proper LogFont getting from pango layount
DescriptionPatch introduces TGtk3Font.UpdateFont which gets information from pango descriptor.
TagsNo tags attached.
Fixed in Revision
LazTarget
WidgetsetGTK 3
Attached Files
  • logfont.diff (3,463 bytes)
    Index: gtk3objects.pas
    ===================================================================
    --- gtk3objects.pas	(revision 61352)
    +++ gtk3objects.pas	(working copy)
    @@ -64,6 +64,7 @@
         constructor Create(ACairo: Pcairo_t; AWidget: PGtkWidget = nil);
         constructor Create(ALogFont: TLogFont; const ALongFontName: String);
         destructor Destroy; override;
    +    procedure UpdateLogFont;
         property FontName: String read FFontName write SetFontName;
         property Handle: PPangoFontDescription read FHandle;
         property Layout: PPangoLayout read FLayout;
    @@ -425,6 +426,56 @@
       FFontName:=AValue;
     end;
     
    +procedure TGtk3Font.UpdateLogFont;
    +var
    +  sz:integer;
    +  members:TPangoFontMask;
    +begin
    +  if not Assigned(fHandle) then exit;
    +  fillchar(fLogFont,sizeof(fLogFont),0);
    +  members:=fHandle^.get_set_fields;
    +  if (PANGO_FONT_MASK_FAMILY and members<>0) then
    +  begin
    +    fLogFont.lfFaceName:=PChar(fHandle^.get_family);
    +  end;
    +  if (PANGO_FONT_MASK_STYLE and members<>0) then
    +  begin
    +    case fHandle^.get_style() of
    +    PANGO_STYLE_NORMAL:;//  fLogFont.
    +    PANGO_STYLE_OBLIQUE:;// flogFont.
    +    PANGO_STYLE_ITALIC: fLogFont.lfItalic:=1;
    +    end;
    +  end;
    +  if (PANGO_FONT_MASK_WEIGHT and members<>0) then
    +  begin
    +    fLogFont.lfWeight:=fHandle^.get_weight();
    +  end;
    +  if (PANGO_FONT_MASK_GRAVITY and members<>0) then
    +  begin
    +    case fHandle^.get_gravity() of
    +    PANGO_GRAVITY_SOUTH: fLogFont.lfOrientation := 0;
    +    PANGO_GRAVITY_EAST: fLogFont.lfOrientation := 900;
    +    PANGO_GRAVITY_NORTH: fLogFont.lfOrientation := 1800;
    +    PANGO_GRAVITY_WEST: fLogFont.lfOrientation := 2700;
    +    //PANGO_GRAVITY_AUTO: get from matrix;
    +    end;
    +  end;
    +  if (PANGO_FONT_MASK_SIZE and members<>0) then
    +  begin
    +    sz:=fHandle^.get_size;
    +    if fHandle^.get_size_is_absolute then
    +    begin
    +      sz:=12;// sz div PANGO_SCALE;
    +    end else
    +    begin
    +      { in points }
    +      sz:=round(96*sz/PANGO_SCALE/72);//round(2.03*sz/PANGO_SCALE);
    +    end;
    +
    +    fLogFont.lfHeight:=sz;//round(sz/PANGO_SCALE);
    +  end;
    +end;
    +
     constructor TGtk3Font.Create(ACairo: Pcairo_t; AWidget: PGtkWidget);
     var
       AContext: PPangoContext;
    @@ -451,6 +502,7 @@
         // writeln('**TGtk3Font.Create size is absolute ',FFontName,' size ',FHandle^.get_size);
       end else
       begin
    +    FHandle^.set_size(FHandle^.get_size);
         // writeln('*TGtk3Font.Create size is not absolute ',FFontName,' size ',FHandle^.get_size);
       end;
     
    Index: gtk3winapi.inc
    ===================================================================
    --- gtk3winapi.inc	(revision 61352)
    +++ gtk3winapi.inc	(working copy)
    @@ -2279,7 +2279,23 @@
           ALogBrush^ := TGtk3Brush(AObject).LogBrush;
           // DebugLn('TGtk3WidgetSet.GetObject ',dbgsName(aObject),' ALogBrush ',dbgHex(PtrUInt(ALogBrush)));
         end;
    -  end
    +  end else
    +  if aObject is TGtk3Font then
    +  begin
    +    if Buf = nil then
    +    begin
    +      // DebugLn('TGtk3WidgetSet.GetObject ',dbgsName(aObject),' Buffer is empty ',dbgHex(PtrUInt(ALogBrush)));
    +      Result := SizeOf(TLogFont);
    +    end else
    +    if BufSize >= SizeOf(TLogFont) then
    +    begin
    +      Result := SizeOf(TLogFont);
    +      // ALogBrush^ := TGtk3Brush(aObject).Color;
    +       TGtk3Font(AObject).UpdateLogFont;
    +      ALogFont^ := TGtk3Font(AObject).LogFont;
    +      // DebugLn('TGtk3WidgetSet.GetObject ',dbgsName(aObject),' ALogBrush ',dbgHex(PtrUInt(ALogBrush)));
    +    end;
    +  end;
     end;
     
     function TGtk3WidgetSet.GetParent(Handle: HWND): HWND;
    
    logfont.diff (3,463 bytes)

Activities

Anton Kavalenka

2019-06-10 22:07

reporter  

logfont.diff (3,463 bytes)
Index: gtk3objects.pas
===================================================================
--- gtk3objects.pas	(revision 61352)
+++ gtk3objects.pas	(working copy)
@@ -64,6 +64,7 @@
     constructor Create(ACairo: Pcairo_t; AWidget: PGtkWidget = nil);
     constructor Create(ALogFont: TLogFont; const ALongFontName: String);
     destructor Destroy; override;
+    procedure UpdateLogFont;
     property FontName: String read FFontName write SetFontName;
     property Handle: PPangoFontDescription read FHandle;
     property Layout: PPangoLayout read FLayout;
@@ -425,6 +426,56 @@
   FFontName:=AValue;
 end;
 
+procedure TGtk3Font.UpdateLogFont;
+var
+  sz:integer;
+  members:TPangoFontMask;
+begin
+  if not Assigned(fHandle) then exit;
+  fillchar(fLogFont,sizeof(fLogFont),0);
+  members:=fHandle^.get_set_fields;
+  if (PANGO_FONT_MASK_FAMILY and members<>0) then
+  begin
+    fLogFont.lfFaceName:=PChar(fHandle^.get_family);
+  end;
+  if (PANGO_FONT_MASK_STYLE and members<>0) then
+  begin
+    case fHandle^.get_style() of
+    PANGO_STYLE_NORMAL:;//  fLogFont.
+    PANGO_STYLE_OBLIQUE:;// flogFont.
+    PANGO_STYLE_ITALIC: fLogFont.lfItalic:=1;
+    end;
+  end;
+  if (PANGO_FONT_MASK_WEIGHT and members<>0) then
+  begin
+    fLogFont.lfWeight:=fHandle^.get_weight();
+  end;
+  if (PANGO_FONT_MASK_GRAVITY and members<>0) then
+  begin
+    case fHandle^.get_gravity() of
+    PANGO_GRAVITY_SOUTH: fLogFont.lfOrientation := 0;
+    PANGO_GRAVITY_EAST: fLogFont.lfOrientation := 900;
+    PANGO_GRAVITY_NORTH: fLogFont.lfOrientation := 1800;
+    PANGO_GRAVITY_WEST: fLogFont.lfOrientation := 2700;
+    //PANGO_GRAVITY_AUTO: get from matrix;
+    end;
+  end;
+  if (PANGO_FONT_MASK_SIZE and members<>0) then
+  begin
+    sz:=fHandle^.get_size;
+    if fHandle^.get_size_is_absolute then
+    begin
+      sz:=12;// sz div PANGO_SCALE;
+    end else
+    begin
+      { in points }
+      sz:=round(96*sz/PANGO_SCALE/72);//round(2.03*sz/PANGO_SCALE);
+    end;
+
+    fLogFont.lfHeight:=sz;//round(sz/PANGO_SCALE);
+  end;
+end;
+
 constructor TGtk3Font.Create(ACairo: Pcairo_t; AWidget: PGtkWidget);
 var
   AContext: PPangoContext;
@@ -451,6 +502,7 @@
     // writeln('**TGtk3Font.Create size is absolute ',FFontName,' size ',FHandle^.get_size);
   end else
   begin
+    FHandle^.set_size(FHandle^.get_size);
     // writeln('*TGtk3Font.Create size is not absolute ',FFontName,' size ',FHandle^.get_size);
   end;
 
Index: gtk3winapi.inc
===================================================================
--- gtk3winapi.inc	(revision 61352)
+++ gtk3winapi.inc	(working copy)
@@ -2279,7 +2279,23 @@
       ALogBrush^ := TGtk3Brush(AObject).LogBrush;
       // DebugLn('TGtk3WidgetSet.GetObject ',dbgsName(aObject),' ALogBrush ',dbgHex(PtrUInt(ALogBrush)));
     end;
-  end
+  end else
+  if aObject is TGtk3Font then
+  begin
+    if Buf = nil then
+    begin
+      // DebugLn('TGtk3WidgetSet.GetObject ',dbgsName(aObject),' Buffer is empty ',dbgHex(PtrUInt(ALogBrush)));
+      Result := SizeOf(TLogFont);
+    end else
+    if BufSize >= SizeOf(TLogFont) then
+    begin
+      Result := SizeOf(TLogFont);
+      // ALogBrush^ := TGtk3Brush(aObject).Color;
+       TGtk3Font(AObject).UpdateLogFont;
+      ALogFont^ := TGtk3Font(AObject).LogFont;
+      // DebugLn('TGtk3WidgetSet.GetObject ',dbgsName(aObject),' ALogBrush ',dbgHex(PtrUInt(ALogBrush)));
+    end;
+  end;
 end;
 
 function TGtk3WidgetSet.GetParent(Handle: HWND): HWND;
logfont.diff (3,463 bytes)

Alexey Tor.

2019-06-11 14:57

reporter   ~0116676

Last edited: 2019-06-11 14:57

View 2 revisions

Anton,
thanks for this patch.

Can you see why GTK3 cannot show icons from TImageList on BitBtn (i see one pixel) and SpeedButtons (16x16 icon is truncated)?

Issue History

Date Modified Username Field Change
2019-06-10 22:07 Anton Kavalenka New Issue
2019-06-10 22:07 Anton Kavalenka File Added: logfont.diff
2019-06-11 14:57 Alexey Tor. Note Added: 0116676
2019-06-11 14:57 Alexey Tor. Note Edited: 0116676 View Revisions