Second patch
 repair About form
 and size of font in editor


Fernando Kochhann wrote:

Yeah! It works! Some bugs occurs, but I'm happy with the Lazarus evolution!

Can You give an example.



Darek

Index: interfaces/gtk/gtkobject.inc
===================================================================
--- interfaces/gtk/gtkobject.inc        (wersja 9410)
+++ interfaces/gtk/gtkobject.inc        (kopia robocza)
@@ -1042,6 +1042,7 @@
 
   procedure SendSizeNotificationToLCL(MainWidget: PGtkWidget);
   var
+    ParentWidget : PGtkWidget;
     LCLControl: TWinControl;
     LCLLeft, LCLTop, LCLWidth, LCLHeight: integer;
     GtkLeft, GtkTop, GtkWidth, GtkHeight: integer;
@@ -1080,11 +1081,14 @@
     GtkTop:=MainWidget^.Allocation.Y;
 
     {$Ifdef GTK2}
-    if GTK_WIDGET_NO_WINDOW(MainWidget) and 
GTK_WIDGET_NO_WINDOW(MainWidget^.Parent)
-  //   and (not GtkWidgetIsA(MainWidget,GTKAPIWidget_GetType))
-    then begin
-      Dec(GtkLeft, MainWidget^.parent^.Allocation.X);
-      Dec(GtkTop, MainWidget^.parent^.Allocation.Y);
+    parentWidget:=pGtkWidget(LCLControl.handle);
+    if parentWidget<>nil then begin
+      parentWidget:=parentWidget^.parent;
+      if (parentWidget<>nil) and GTK_WIDGET_NO_WINDOW(parentWidget)
+      then begin
+        Dec(GtkLeft, parentWidget^.Allocation.X);
+        Dec(GtkTop, parentWidget^.Allocation.Y);
+      end;
     end;
     {$EndIf}
     GtkWidth:=MainWidget^.Allocation.Width;
Index: interfaces/gtk2/gtk2object.inc
===================================================================
--- interfaces/gtk2/gtk2object.inc      (wersja 9410)
+++ interfaces/gtk2/gtk2object.inc      (kopia robocza)
@@ -1,3 +1,4 @@
+{%MainUnit gtk2int.pp}
 {******************************************************************************
                                    TGtk2WidgetSet
  ******************************************************************************
@@ -1405,12 +1371,14 @@
  
------------------------------------------------------------------------------}
 procedure TGtk2WidgetSet.UpdateDCTextMetric(DC: TDeviceContext);
 const
-  TestString = '{Am|g_}';
+  TestString = #195#147'{Am|g_}'#195#150;//{#196'A'}
+//  TestString = #195#147'aa'#195#150;
+//  testString='a';
 var
   XT : TSize;
   UseFontDesc : PPangoFontDescription;
   UnRef : Boolean;
-  AVGBuffer: array[#32..#126] of char;
+  testStr  : shortstring;
   AvgLen: integer;
   c: char;
 
@@ -1420,7 +1388,18 @@
   Layout : PPangoLayout;
   AttrList : PPangoAttrList;
   Attr : PPangoAttribute;
+  ex2,
   Extents : TPangoRectangle;
+  
+  function GetStringWidth(str : shortstring): integer;
+  var
+    Size: TSize;
+  begin
+    pango_layout_set_text(Layout, @(str[1]) , length(str));
+    pango_layout_get_pixel_size(Layout, @Size.cX, @Size.cY);
+    result:=size.cx;
+  end;
+        
 begin
   with TDeviceContext(DC) do begin
     if dcfTextMetricsValid in DCFlags then begin
@@ -1469,48 +1448,48 @@
         pango_layout_set_alignment(Layout, PANGO_ALIGN_LEFT);
 
         pango_layout_set_text(Layout,  TestString, length(TestString));
+        ex2.y:=0;
+        ex2.height:=0;
+        pango_layout_get_extents(Layout, @ex2, @Extents);
 
-        pango_layout_get_extents(Layout, nil, @Extents);
-        g_object_unref(Layout);
-
-        If UnRef then
-          pango_font_description_free(UseFontDesc);
-
         FillChar(DCTextMetric, SizeOf(DCTextMetric), 0);
         with DCTextMetric do begin
           IsDoubleByteChar:=False;//FontIsDoubleByteCharsFont(UseFont);
-
-          for c:=Low(AVGBuffer) to High(AVGBuffer) do
-            AVGBuffer[c]:=c;
           lbearing := PANGO_LBEARING(extents) div PANGO_SCALE;
           rBearing := PANGO_RBEARING(extents) div PANGO_SCALE;
-          TextMetric.tmAscent := PANGO_ASCENT(extents) div PANGO_SCALE;
-          TextMetric.tmDescent := PANGO_DESCENT(extents) div PANGO_SCALE;
-          AvgLen:=ord(High(AVGBuffer))-ord(Low(AVGBuffer))+1;
-          GetTextExtentPoint(HDC(DC), @AVGBuffer[Low(AVGBuffer)],
-                             AvgLen, XT);
+          if ex2.y<0 then ex2.y:=0;
+          TextMetric.tmheight := (ex2.height+ex2.y  + PANGO_SCALE div 2) div 
PANGO_SCALE;
+          testSTr:='L';
+          pango_layout_set_text(Layout,  @(TestStr[1]), length(TestStr));
+          pango_layout_get_extents(Layout, @ex2, nil);
+          TextMetric.tmDescent := (extents.height - ex2.height - ex2.y  + 
PANGO_SCALE div 2) div PANGO_SCALE;
+          TextMetric.tmAscent := (ex2.height + ex2.y + PANGO_SCALE div 2) div 
PANGO_SCALE;
+          with TextMetric do
+            if tmAscent+tmDescent>tmHeight then tmAscent:=tmHeight-tmDescent;
+
+          testStr:='';
+//          for c:=#26 to #126 do
+          for c:=#65 to #126 do
+            testStr:=testStr+c;
+          avgLen:=length(testStr);
+          XT.cx:=GetStringWidth(testStr);
           if not IsDoubleByteChar then
             XT.cX := XT.cX div AvgLen
           else
             // Quick hack for double byte char fonts
             XT.cX := XT.cX div (AvgLen div 2);
-          TextMetric.tmHeight := XT.cY;
-          TextMetric.tmAscent := TextMetric.tmHeight - TextMetric.tmDescent;
           TextMetric.tmAveCharWidth :=  XT.cX;
           if TextMetric.tmAveCharWidth<1 then TextMetric.tmAveCharWidth:=1;
-          {temp EVIL hack FIXME -->}
-          AVGBuffer[Low(AVGBuffer)]:='M';
-          GetTextExtentPoint(HDC(DC), @AVGBuffer[Low(AVGBuffer)],
-                             1, XT);
-          TextMetric.tmMaxCharWidth := XT.cX;
-          AVGBuffer[Low(AVGBuffer)]:='W';
-          GetTextExtentPoint(HDC(DC), @AVGBuffer[Low(AVGBuffer)],
-                             1, XT);
+          TextMetric.tmMaxCharWidth := GetStringWidth('M');
+          XT.cx:=GetStringWidth('W');
           TextMetric.tmMaxCharWidth := Max(TextMetric.tmMaxCharWidth,XT.cX);
-          {<--  temp EVIL hack FIXME}
           if TextMetric.tmMaxCharWidth<1 then
             TextMetric.tmMaxCharWidth:=1;
         end;
+        g_object_unref(Layout);
+
+        If UnRef then
+          pango_font_description_free(UseFontDesc);
       end;
       Include(DCFlags,dcfTextMetricsValid);
     end;

Reply via email to