Hi
patch to bug 996
works both GTK and GTK2,
Darek
Index: interfaces/gtk/gtkwinapi.inc
===================================================================
--- interfaces/gtk/gtkwinapi.inc (wersja 9299)
+++ interfaces/gtk/gtkwinapi.inc (kopia robocza)
@@ -2887,8 +2887,6 @@
theRect.Right := theRect.Left + LineWidth;
theRect.Bottom := theRect.Top + NumLines*TM.tmHeight;
- if NumLines>1 then
- Inc(theRect.Bottom, (NumLines-1)*TM.tmDescent);// space between lines
//debugln('TGtkWidgetSet.DrawText A ',dbgs(theRect),'
TM.tmHeight=',dbgs(TM.tmHeight),' LineWidth=',dbgs(LineWidth),'
NumLines=',dbgs(NumLines));
end;
@@ -3045,9 +3043,6 @@
end
else If (Lines <> nil) and (NumLines <> 0) then begin
For I := 0 to NumLines - 1 do begin
- if I>0 then
- Inc(theRect.Top, TM.tmDescent);// space between lines
-
If (((Flags and DT_EditControl) = DT_EditControl) and
(tm.tmHeight > (theRect.Bottom - theRect.Top))) or
(theRect.Top > theRect.Bottom)
@@ -3918,15 +3913,16 @@
if UseFont<>nil then begin
LineLen := FindChar(#10,Str,Count);
UpdateDCTextMetric(TDeviceContext(DC));
- LineHeight:=GetTextHeight(DCTextMetric);
+ LineHeight:=DCTextMetric.TextMetric.tmHeight;
+// LineHeight:=GetTextHeight(DCTextMetric);
if Buffered then begin
TxtPt.X := 0;
- TxtPt.Y := LineHeight;
+ TxtPt.Y := DCTextMetric.TextMetric.tmAscent;;
end
else begin
TopY := Y;
TxtPt.X := X + DCOrigin.X;
- TxtPt.Y := TopY + LineHeight + DCOrigin.Y;
+ TxtPt.Y := TopY + DCTextMetric.TextMetric.tmAscent + DCOrigin.Y;
end;
SelectGDKTextProps(DC);
LineStart:=Str;
@@ -6504,17 +6500,27 @@
{$ENDIF}
end;
Result := True;
- gdkRect.X := Rect^.Left;
- gdkRect.Y := Rect^.Top;
- gdkRect.Width := (Rect^.Right - Rect^.Left);
- gdkRect.Height := (Rect^.Bottom - Rect^.Top);
-
PaintWidget:=GetFixedWidget(Widget);
if PaintWidget=nil then PaintWidget:=Widget;
+ if Rect = nil then begin
+ gdkRect.X := 0;//PaintWidget^.Allocation.X;
+ gdkRect.Y := 0;//PaintWidget^.Allocation.Y;
+ gdkRect.Width:=PaintWidget^.Allocation.Width;
+ gdkRect.Height:=PaintWidget^.Allocation.Height;
+
+ end else begin
+ gdkRect.X := Rect^.Left;
+ gdkRect.Y := Rect^.Top;
+ gdkRect.Width := (Rect^.Right - Rect^.Left);
+ gdkRect.Height := (Rect^.Bottom - Rect^.Top);
+ end;
+
+
{$IfDef GTK2}
if (PaintWidget<>nil) and GTK_WIDGET_NO_WINDOW(PaintWidget)
and (not GtkWidgetIsA(PGTKWidget(PaintWidget),GTKAPIWidget_GetType))
+ and (Rect<>nil)
then begin
Inc(gdkRect.X, PaintWidget^.Allocation.x);
Inc(gdkRect.Y, PaintWidget^.Allocation.y);
Index: interfaces/gtk/gtkobject.inc
===================================================================
--- interfaces/gtk/gtkobject.inc (wersja 9299)
+++ interfaces/gtk/gtkobject.inc (kopia robocza)
@@ -1446,13 +1446,9 @@
PangoDescStr := AFont.Name;
DescOpts := '';
if FSBold in AFont.Style then
- DescOpts := DescOpts + ' bold';
+ DescOpts := DescOpts + ' Bold';
if FSItalic in AFont.Style then
- DescOpts := DescOpts + ' italic';
- if FSUnderline in AFont.Style then
- DescOpts := DescOpts + ' underline';
- if FSStrikeOut in AFont.Style then
- DescOpts := DescOpts + ' strikethrough';
+ DescOpts := DescOpts + ' Italic';
PangoDescStr := PangoDescStr+DescOpts+' '+IntToStr(AFont.Size);
//DebugLn('TGtkWidgetSet.SetWidgetFont PangoDescStr="',PangoDescStr,'"');
@@ -6530,7 +6526,7 @@
#0'{'#0'A'#0'B'#0'C'#0'D'#0'E'#0'F'#0'G'#0'H'#0'I'#0'J'#0'K'#0'L'#0'M'#0'N'
+#0'O'#0'P'#0'Q'#0'R'#0'S'#0'T'#0'U'#0'V'#0'W'#0'X'#0'Y'#0'Z'#0'X'#0'Y'#0'Z'
+#0'a'#0'b'#0'c'#0'd'#0'e'#0'f'#0'g'#0'h'#0'i'#0'j'#0'k'#0'l'#0'm'#0'n'#0'o'
- +#0'p'#0'q'#0'r'#0's'#0't'#0'u'#0'v'#0'w'#0'x'#0'y'#0'z'#0'|'#0'_'#0'}'
+
+#0'p'#0'q'#0'r'#0#220#0't'#0'u'#195#150#0'w'#0#223#0'y'#195#147#0'|'#0'_'#0'}'
);
var
UseFont : PGDKFont;
@@ -7233,4 +7229,4 @@
{$IFDEF ASSERT_IS_ON}
{$UNDEF ASSERT_IS_ON}
{$C-}
-{$ENDIF}
\ No newline at end of file
+{$ENDIF}
Index: interfaces/gtk2/gtk2winapi.inc
===================================================================
--- interfaces/gtk2/gtk2winapi.inc (wersja 9299)
+++ interfaces/gtk2/gtk2winapi.inc (kopia robocza)
@@ -82,7 +82,7 @@
Exit;
end;
- if CompareText(lfFacename,'default')=0 then begin
+ if (CompareText(lfFacename,'default')=0) and (lfHeight=0) then begin
LoadDefaultFont;
Result := HFONT(GdiObject);
exit;
@@ -112,8 +112,8 @@
else
FullString:=IntToStr(aSize);
FullString := AFamily + ' ' + aStyle + ' ' + FullString;
-
+
GdiObject^.GDIFontObject :=
pango_font_description_from_string(PChar(FullString));
@@ -131,10 +131,10 @@
// which would be great with the given lfheight value, but older gtk2
version
// doesn't have this funtion
if lfHeight<0 then
- aSize:= (abs(lfheight) * 72) div ScreenInfo.PixelsPerInchX
+ aSize:= (abs(lfheight) * 72 * PANGO_SCALE) div
ScreenInfo.PixelsPerInchX
else
- aSize:=lfHeight;
- pango_font_description_set_size( GdiObject^.GDIFontObject,
aSize*PANGO_SCALE);
+ aSize:=lfHeight*PANGO_SCALE;
+ pango_font_description_set_size( GdiObject^.GDIFontObject, aSize);
end;
@@ -499,11 +499,10 @@
Count: Integer) : Boolean;
var
DCOrigin: TPoint;
- aRect : TRect;
-
UnRef,
Underline,
StrikeOut : Boolean;
+ yOffset : integer;
Layout : PPangoLayout;
UseFontDesc : PPangoFontDescription;
@@ -537,6 +536,9 @@
DebugLn('WARNING: [TGtk2WidgetSet.TextOut] Missing Font')
else begin
DCOrigin:=GetDCOffset(TDeviceContext(DC));
+ with DCTextMetric.TextMetric do
+ yOffset:= tmHeight-tmDescent-tmAscent;
+ if yOffset<0 then yOffset:=0;
GetStyle(lgsdefault);
Layout := gtk_widget_create_pango_layout (GetStyleWidget(lgsdefault),
nil);
pango_layout_set_font_description(Layout, UseFontDesc);
@@ -571,15 +573,9 @@
//cross-compatibility with GTK1.2 and win32 interfaces.....
pango_layout_set_text(Layout, Str, Count);
-
- aRect := Rect(0,0,0, 0);
- pango_layout_get_pixel_size(Layout, @arect.Right, @arect.Bottom);
-
- OffsetRect(aRect, X+DCOrigin.X,Y+DCOrigin.Y);
-
EnsureGCColor(DC, dccCurrentTextColor, True, False);
- gdk_draw_layout_with_colors(drawable, GC, aRect.Left, aRect.Top,
Layout, nil, nil);
+ gdk_draw_layout_with_colors(drawable, GC, X+DCOrigin.X,
Y+DCOrigin.Y+yOffset, Layout, nil, nil);
g_object_unref(Layout);
Result := True;
If UnRef then
Index: interfaces/gtk2/gtk2object.inc
===================================================================
--- interfaces/gtk2/gtk2object.inc (wersja 9299)
+++ 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;
+// 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,47 @@
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
+ 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;
Index: include/customlabel.inc
===================================================================
--- include/customlabel.inc (wersja 9299)
+++ include/customlabel.inc (kopia robocza)
@@ -169,7 +169,6 @@
constructor TCustomLabel.Create(TheOwner: TComponent);
begin
inherited Create(TheOwner);
- Font.OnChange := @FontChange;
ControlStyle := [csSetCaption, csClickEvents, csDoubleClicks,
csReplicatable];
setInitialBounds(0,0,65,17);
FShowAccelChar := True;
@@ -408,12 +407,6 @@
end;
end;
-Procedure TCustomLabel.FontChange(Sender : TObject);
-begin
- If Caption <> '' then
- Invalidate;
-end;
-
procedure TCustomLabel.SetOptimalFill(const AValue: Boolean);
begin
if FOptimalFill=AValue then exit;
Index: stdctrls.pp
===================================================================
--- stdctrls.pp (wersja 9299)
+++ stdctrls.pp (kopia robocza)
@@ -1142,7 +1142,6 @@
FShowAccelChar: Boolean;
FWordWrap: Boolean;
FLayout: TTextLayout;
- Procedure FontChange(Sender: TObject);
procedure SetOptimalFill(const AValue: Boolean);
protected
function CanTab: boolean; override;
Index: extctrls.pp
===================================================================
--- extctrls.pp (wersja 9299)
+++ extctrls.pp (kopia robocza)
@@ -33,7 +33,7 @@
{$endif}
uses
- SysUtils, Classes, LCLStrConsts, LCLType, LCLProc, LResources, Controls,
+ SysUtils, Classes, LCLStrConsts, LCLType, LCLProc, LResources, Controls,
InterfaceBase,
Forms, StdCtrls, lMessages, GraphType, Graphics, LCLIntf, CustomTimer;
type