repaired patch


On Sun, 07 May 2006 00:28:23 +0200
darekm <[EMAIL PROTECTED]> wrote:

Hi
My patch
works better with size of font and font with XLFD name (see Tony Maro mail)
  distinguish GTK1 from GTK2 on utf8 draw text
  better works with color

About:
+      if (aSize=0)  then FullString:='10'
+                    else FullString:=IntToStr(aSize);

The 10 is not the default size. Please add always a comment that it is a
ToDo to fetch the default font size.
I don't understand what I should done, please modify it


About:
+function TGTK2WidgetSet.FontCanUTF8(Font: HFont): boolean;
+begin
+  Result:=IsValidGDIObject(Font) and
+
FontIsDoubleByteCharsFont(gdk_font_from_description(PGdiObject(Font)^.GDIFo
ntObject));
+end;

This is a mem leak. see gdk_font_from_description.
removed



About:
-    aSize := StrToIntDef(ExtractXLFDItem(LongFontName, XLFD_POINTSIZE),12);
+    aSize := StrToIntDef(ExtractXLFDItem(LongFontName, XLFD_POINTSIZE),0)
div 10;

Why is the size now ten times as big?


Mattias



Darek

Jesús Reyes A. wrote:

----- Original Message ----- From: "darekm" <[EMAIL PROTECTED]>
To: <[email protected]>
Sent: Friday, April 28, 2006 10:23 AM
Subject: Re: [lazarus] [patch] textOut on gtk2


Jesus Reyes wrote:

--- darekm <[EMAIL PROTECTED]> escribió:


Hi
textOut once more

and
clipping (sometimes buttons are not refresh after tHint disappear


Darek



[snip]

I also have a patch for GTK2 CreateFontIndirectEx, I simplified the
function a little and added support for font names like "helvetica
12" in addition to XLFD and single font names. Comments?

FontNameToPangoDescription should not be part of LCL (graphics), its only part of GTK2 widgetSet

Just like the other XLFD auxiliary methods around there, one may argue that they are specific to gtk*, however, is not the location of the function that is interesting but the functionality.

One observation for Darek's patch, it seems that to convert font's
pixel size to point size a fixed 96 ppi was used, why not to use
ScreenInfo.PixelsPerInchX (or Y)?

We can write not only to screen.
We need new function of pango, that use pixel size (as I write, I think that when we start use GTK2 in production application it will be standard)
it can be done by conditional

I made the question because I thought that there might be a reason for using a fixed value. I'm sure that if necesary we will find the way to handle other devices properly, at the moment ScreenInfo.PixelsPerInchX seems to me like a more appropiated value.

and what for FHeightFloat

I was planning to not include that, the patch was not intended to apply as is.

If nobody oppose, I will apply the patch tomorrow when I will have access to the linux pc, then if you like to make some changes, as always, patches are welcome :)

Darek


Jesus Reyes A.

__________________________________________________
Correo Yahoo!
Espacio para todos tus mensajes, antivirus y antispam __gratis! Regístrate ya - http://correo.yahoo.com.mx/
_________________________________________________________________
   To unsubscribe: mail [EMAIL PROTECTED] with
              "unsubscribe" as the Subject
 archives at http://www.lazarus.freepascal.org/mailarchives


_________________________________________________________________
    To unsubscribe: mail [EMAIL PROTECTED] with
               "unsubscribe" as the Subject
  archives at http://www.lazarus.freepascal.org/mailarchives


Index: interfaces/gtk/gtkproc.pp
===================================================================
--- interfaces/gtk/gtkproc.pp   (wersja 9253)
+++ interfaces/gtk/gtkproc.pp   (kopia robocza)
@@ -46,7 +46,7 @@
   {$IFDEF gtk2}
     glib2, gdk2pixbuf, gdk2, gtk2, Pango,
     {$IFDEF UNIX}
-    X, XLib, XUtil, //Keyboard handling
+    X, XLib, XUtil,Xatom, //Keyboard handling
     {$ENDIF}
   {$ELSE}
     glib, gdk, gtk, {$Ifndef NoGdkPixbufLib}gdkpixbuf,{$EndIf} GtkFontCache,
Index: interfaces/gtk2/gtk2winapi.inc
===================================================================
--- interfaces/gtk2/gtk2winapi.inc      (wersja 9253)
+++ interfaces/gtk2/gtk2winapi.inc      (kopia robocza)
@@ -87,6 +87,8 @@
         Result := HFONT(GdiObject);
         exit;
       end;
+
+
       
       FontNameToPangoFontDescStr(LongFontname, aFamily, aStyle, aSize);
       
@@ -105,33 +107,35 @@
       // size information, and later modify font size
       
       // using method 2
-      FullString := AFamily + ' ' + aStyle;
+      if (aSize=0)  then FullString:='10'
+                    else FullString:=IntToStr(aSize);
+      FullString := AFamily + ' ' + aStyle + ' ' + FullString;
       
+
       GdiObject^.GDIFontObject :=
         pango_font_description_from_string(PChar(FullString));
 
       If lfWeight <> FW_DONTCARE then
         pango_font_description_set_weight(GdiObject^.GDIFontObject, lfWeight);
 
-      if lfItalic = 0 then
+      if lfItalic <> 0 then
         pango_font_description_set_style(GdiObject^.GDIFontObject,
-                                         PANGO_STYLE_NORMAL)
-      else
-        pango_font_description_set_style(GdiObject^.GDIFontObject,
                                          PANGO_STYLE_ITALIC);
-                                         
-      if aSize=0 then begin
+
+      if (aSize=0) and (lfHeight<>0) then begin
         // a size is not specified, try to calculate one based on lfHeight
         // and use this value not in the font name but set this value appart
         // NOTE: in gtk2.8 is possible to use 
pango_font_description_set_absolute_size
         // which would be great with the given lfheight value, but older gtk2 
version
         // doesn't have this funtion
-        aSize:= (abs(lfheight) * 72) div ScreenInfo.PixelsPerInchX;
-        if aSize=0 then
-          aSize := 12;
+        if lfHeight<0 then
+          aSize:= (abs(lfheight) * 72) div ScreenInfo.PixelsPerInchX
+        else
+          aSize:=lfHeight;
+        pango_font_description_set_size( GdiObject^.GDIFontObject, 
aSize*PANGO_SCALE);
       end;
-      pango_font_description_set_size( GdiObject^.GDIFontObject, 
aSize*PANGO_SCALE);
 
+
       GdiObject^.StrikeOut := lfStrikeOut <> 0;
       GdiObject^.Underline := lfUnderline <> 0;
 
@@ -301,7 +305,7 @@
           TopY := Y;
           UpdateDCTextMetric(TDeviceContext(DC));
           TxtPt.X := X + DCOrigin.X;
-          LineHeight := DCTextMetric.TextMetric.tmAscent;
+          LineHeight := DCTextMetric.TextMetric.tmHeight;
           TxtPt.Y := TopY + LineHeight + DCOrigin.Y;
 
           SelectedColors := dcscCustom;
@@ -317,14 +321,6 @@
           end;
 
           EnsureGCColor(DC, dccCurrentTextColor, True, False);
-          RGBColor := ColorToRGB(CurrentTextColor.ColorRef);
-
-          Attr := pango_attr_foreground_new(gushort(GetRValue(RGBColor)) shl 8,
-                                            gushort(GetGValue(RGBColor)) shl 8,
-                                            gushort(GetBValue(RGBColor)) shl 
8);
-
-          pango_attr_list_change(AttrList,Attr);
-
           pango_layout_set_attributes(Layout, AttrList);
 
           Foreground := StyleForegroundColor(CurrentTextColor.ColorRef, nil);
@@ -511,7 +507,6 @@
   StrikeOut : Boolean;
 
   RGBColor : Longint;
-  Foreground : PGDKColor;
   Layout : PPangoLayout;
   UseFontDesc : PPangoFontDescription;
   AttrList : PPangoAttrList;
@@ -564,21 +559,8 @@
         pango_attr_list_change(AttrList,Attr);
 
         SelectedColors := dcscCustom;
-        EnsureGCColor(DC, dccCurrentBackColor, True, False);
         EnsureGCColor(DC, dccCurrentTextColor, True, False);
-
-        RGBColor := ColorToRGB(CurrentTextColor.ColorRef);
-
-        Attr := pango_attr_foreground_new(gushort(GetRValue(RGBColor)) shl 8,
-                                        gushort(GetGValue(RGBColor)) shl 8,
-                                        gushort(GetBValue(RGBColor)) shl 8);
-
-        pango_attr_list_change(AttrList,Attr);
-        
         pango_layout_set_attributes(Layout, AttrList);
-
-        Foreground := StyleForegroundColor(CurrentTextColor.ColorRef, nil);
-
         pango_layout_set_single_paragraph_mode(Layout, TRUE);
         pango_layout_set_width(Layout, -1);
 
@@ -597,7 +579,9 @@
 
         OffsetRect(aRect, X+DCOrigin.X,Y+DCOrigin.Y);
 
-        gdk_draw_layout_with_colors(drawable, GC, aRect.Left, aRect.Top, 
Layout, Foreground, nil);
+        EnsureGCColor(DC, dccCurrentTextColor, True, False);
+
+        gdk_draw_layout_with_colors(drawable, GC, aRect.Left, aRect.Top, 
Layout, nil, nil);
         g_object_unref(Layout);
         Result := True;
         If UnRef then
Index: interfaces/gtk2/gtk2lclintf.inc
===================================================================
--- interfaces/gtk2/gtk2lclintf.inc     (wersja 9253)
+++ interfaces/gtk2/gtk2lclintf.inc     (kopia robocza)
@@ -30,5 +30,16 @@
 
 //##apiwiz##sps##   // Do not remove
 
+function TGtk2WidgetSet.ExtUTF8Out(DC: HDC; X, Y: Integer; Options: Longint;
+  Rect: PRect; Str: PChar; Count: Longint; Dx: PInteger): Boolean;
+begin
+    Result:=ExtTextOut(DC,X,Y,Options,Rect,Str,Count,Dx);
+end;
+function TGtk2WidgetSet.TextUTF8Out(DC: HDC; X, Y: Integer; Str: PChar; Count: 
Longint): Boolean;
+begin
+    Result:=TextOut(DC,X,Y,Str,Count);
+end;
 
+
+
 //##apiwiz##eps##   // Do not remove, no wizard declaration after this line
Index: interfaces/gtk2/gtk2int.pas
===================================================================
--- interfaces/gtk2/gtk2int.pas (wersja 9253)
+++ interfaces/gtk2/gtk2int.pas (kopia robocza)
@@ -177,6 +177,7 @@
 
 {$include gtk2object.inc}
 {$include gtk2winapi.inc}
+{$include gtk2lclintf.inc}
 
 const
   GtkListStoreItemGtkListTag = 'GtkList';
Index: interfaces/gtk2/gtk2lclintfh.inc
===================================================================
--- interfaces/gtk2/gtk2lclintfh.inc    (wersja 9253)
+++ interfaces/gtk2/gtk2lclintfh.inc    (kopia robocza)
@@ -29,5 +29,9 @@
 }
 
 //##apiwiz##sps##   // Do not remove
+function ExtUTF8Out(DC: HDC; X, Y: Integer; Options: Longint; Rect: PRect;
+  Str: PChar; Count: Longint; Dx: PInteger): Boolean; override;
+function TextUTF8Out(DC: HDC; X, Y: Integer; Str: PChar; Count: Longint): 
Boolean; override;
 
+
 //##apiwiz##eps##   // Do not remove, no wizard declaration after this line
Index: include/font.inc
===================================================================
--- include/font.inc    (wersja 9253)
+++ include/font.inc    (kopia robocza)
@@ -526,7 +526,7 @@
   
   procedure addStyle(const s: string);
   begin
-    if (s<>'') and (s<>'*') then begin
+    if (s<>'') and (s<>'*') and (s<>'r') then begin
       if aStyle<>'' then
         aStyle := aStyle + ' ' + s
       else
@@ -575,7 +575,7 @@
     aFamily := ExtractXLFDItem(LongFontName, XLFD_FAMILY);
     if aFamily='*' then
       aFamily:='';
-    aSize := StrToIntDef(ExtractXLFDItem(LongFontName, XLFD_POINTSIZE),12);
+    aSize := StrToIntDef(ExtractXLFDItem(LongFontName, XLFD_POINTSIZE),0) div 
10;
     addStyle( ExtractXLFDItem(LongFontName, XLFD_STYLENAME ));
     addStyle( ExtractXLFDItem(LongFontname, XLFD_WEIGHTNAME));
     addStyle( ExtractXLFDItem(LongFontname, XLFD_SLANT));

Reply via email to