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
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
Index: interfaces/gtk/gtklclintf.inc
===================================================================
--- interfaces/gtk/gtklclintf.inc (wersja 9243)
+++ interfaces/gtk/gtklclintf.inc (kopia robocza)
@@ -288,11 +288,7 @@
function TGTKWidgetSet.FontCanUTF8(Font: HFont): boolean;
begin
Result:=IsValidGDIObject(Font) and
-{$IFDEF GTK2}
-
FontIsDoubleByteCharsFont(gdk_font_from_description(PGdiObject(Font)^.GDIFontObject));
-{$ELSE GTK2}
- FontIsDoubleByteCharsFont(PGdiObject(Font)^.GDIFontObject);
-{$ENDIF GTK2}
+ FontIsDoubleByteCharsFont(PGDKFont(PGdiObject(Font)^.GDIFontObject));
end;
{------------------------------------------------------------------------------
Index: interfaces/gtk2/gtk2winapi.inc
===================================================================
--- interfaces/gtk2/gtk2winapi.inc (wersja 9243)
+++ interfaces/gtk2/gtk2winapi.inc (kopia robocza)
@@ -105,33 +133,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;
@@ -208,7 +238,6 @@
//will need to know before hand what the current
//locale is, and if we stored UTF-8 string this would break
//cross-compatibility with GTK1.2 and win32 interfaces.....
-
pango_layout_set_text(Layout, Str, Count);
aRect := Classes.Rect(0,0,0,0);
@@ -301,7 +330,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 +346,14 @@
end;
EnsureGCColor(DC, dccCurrentTextColor, True, False);
- RGBColor := ColorToRGB(CurrentTextColor.ColorRef);
+{ 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 +540,6 @@
StrikeOut : Boolean;
RGBColor : Longint;
- Foreground : PGDKColor;
Layout : PPangoLayout;
UseFontDesc : PPangoFontDescription;
AttrList : PPangoAttrList;
@@ -564,21 +592,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);
@@ -596,8 +611,15 @@
pango_layout_get_pixel_size(Layout, @arect.Right, @arect.Bottom);
OffsetRect(aRect, X+DCOrigin.X,Y+DCOrigin.Y);
+// EnsureGCColor(DC, dccCurrentBackColor, True, False);
- gdk_draw_layout_with_colors(drawable, GC, aRect.Left, aRect.Top,
Layout, Foreground, nil);
+// gdk_draw_layout_with_colors(drawable, GC, aRect.Left, aRect.Top,
Layout, nil, nil);
+// EnsureGCColor(DC, dccCurrentBackColor, True, False);
+// gdk_draw_rectangle(Drawable, GC, 1, aRect.Left, aRect.Top,
arect.right, arect.Bottom);
+
+ 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 9243)
+++ interfaces/gtk2/gtk2lclintf.inc (kopia robocza)
@@ -30,5 +30,28 @@
//##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;
+
+{------------------------------------------------------------------------------
+ function TGTKWidgetSet.FontCanUTF8(Font: HFont): boolean;
+
+ True if font recognizes Unicode.
+
------------------------------------------------------------------------------}
+function TGTK2WidgetSet.FontCanUTF8(Font: HFont): boolean;
+begin
+ Result:=IsValidGDIObject(Font) and
+
FontIsDoubleByteCharsFont(gdk_font_from_description(PGdiObject(Font)^.GDIFontObject));
+end;
+
+
+
//##apiwiz##eps## // Do not remove, no wizard declaration after this line
Index: interfaces/gtk2/gtk2int.pas
===================================================================
--- interfaces/gtk2/gtk2int.pas (wersja 9243)
+++ 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 9243)
+++ interfaces/gtk2/gtk2lclintfh.inc (kopia robocza)
@@ -29,5 +29,10 @@
}
//##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;
+function FontCanUTF8(Font: HFont): boolean; override;
+
//##apiwiz##eps## // Do not remove, no wizard declaration after this line
Index: include/font.inc
===================================================================
--- include/font.inc (wersja 9243)
+++ 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));