Hi
without this patch tLabel and tSpeedButton not work proper with
caption in UTF8 and Unicode fonts
Darek
Index: interfaces/gtk/gtklclintfh.inc
===================================================================
--- interfaces/gtk/gtklclintfh.inc (wersja 8890)
+++ interfaces/gtk/gtklclintfh.inc (kopia robocza)
@@ -39,6 +39,7 @@
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;
Index: interfaces/gtk/gtkwinapi.inc
===================================================================
--- interfaces/gtk/gtkwinapi.inc (wersja 8890)
+++ interfaces/gtk/gtkwinapi.inc (kopia robocza)
@@ -2862,7 +2862,7 @@
end;
{Draw line of Text}
- TextOut(DC, LeftPos, TopPos, PChar(aStr), Length(aStr));
+ TextUtf8Out(DC, LeftPos, TopPos, PChar(aStr), Length(aStr));
{Draw Prefix}
If pIndex > 0 then begin
@@ -3694,7 +3694,7 @@
with TDeviceContext(DC) do begin
if (Dx=nil) then begin
// no dist array -> write as one block
- //debugln('TGtkWidgetSet.ExtTextOut.DrawTextLine Dx=nil
',dbgs(LineLen),'
DCTextMetric.IsDoubleByteChar=',dbgs(DCTextMetric.IsDoubleByteChar));
+
gdk_draw_text(Buffer, UseFont, GC, TxtPt.X, TxtPt.Y,
LineStart, LineLen);
end else begin
@@ -5908,9 +5908,8 @@
UseFont := CurrentFont^.GDIFontObject;
UnRef := False;
end;
- If UseFont = nil then
- DebugLn('WARNING: [TGtkWidgetSet.GetTextExtentPoint] Missing font')
- else begin
+ assert(usefont<>nil,'WARNING: [TGtkWidgetSet.GetTextExtentPoint] Missing
font');
+
descent:=0;
UpdateDCTextMetric(TDeviceContext(DC));
IsDBCSFont:=TDeviceContext(DC).DCTextMetric.IsDoubleByteChar;
@@ -5937,9 +5936,8 @@
//debugln('TGtkWidgetSet.GetTextExtentPoint END Str="'+DbgStr(Str)+'"
Size=',dbgs(Size.cX),'x',dbgs(Size.cY),' ascent=',dbgs(ascent),'
descent=',dbgs(descent),'
tmDescent=',dbgs(TDeviceContext(DC).DCTextMetric.TextMetric.tmDescent));
If UnRef then
FontCache.Unreference(UseFont);
- end;
+
end;
- Assert(False, 'trace:< [TGtkWidgetSet.GetTextExtentPoint]');
end;
{$EndIf}
@@ -9330,16 +9328,16 @@
TempPen : hPen;
LogP : TLogPen;
Points : array[0..1] of TSize;
+
+ lbearing, rbearing, width, ascent,descent: LongInt;
+
begin
Result := IsValidDC(DC);
if Result and (Count>0)
then with TDeviceContext(DC) do
begin
- if GC = nil
- then begin
- DebugLn('WARNING: [TGtkWidgetSet.TextOut] Uninitialized GC');
- end
- else begin
+
+ assert(GC<>nil,'WARNING: [TGtkWidgetSet.TextOut] Uninitialized GC');
if (CurrentFont = nil) or (CurrentFont^.GDIFontObject = nil)
then begin
UseFont := GetDefaultFont(true);
@@ -9353,11 +9351,20 @@
Underline := LongBool(CurrentFont^.LogFont.lfUnderline);
StrikeOut := LongBool(CurrentFont^.LogFont.lfStrikeOut);
end;
- If UseFont = nil then
- DebugLn('WARNING: [TGtkWidgetSet.TextOut] Missing Font')
- else begin
+ assert(UseFont<>nil,'WARNING: [TGtkWidgetSet.TextOut] Missing Font');
DCOrigin:=GetDCOffset(TDeviceContext(DC));
- GetTextExtentPoint(DC, Str, Count, Sz);
+ descent:=0;
+ gdk_text_extents(UseFont, Str, Count,
+ @lbearing, @rBearing, @width, @ascent, @descent);
+ sz.cx:=width;
+ Sz.cY :={$IFDEF Win32}
+ GDK_String_Height(UseFont, Str)
+ {$ELSE}
+ ascent+descent;
+ {$ENDIF}
+
+
+
aRect := Rect(X+DCOrigin.X,Y+DCOrigin.Y,X + Sz.CX, Sz.CY);
//DebugLn('TGtkWidgetSet.TextOut
',ARect.Left,',',ARect.Top,',',ARect.RIght,',',ARect.Bottom);
FillRect(DC,aRect,hBrush(CurrentBrush));
@@ -9404,8 +9411,6 @@
If UnRef then
FontCache.Unreference(UseFont);
end;
- end;
- end;
end;
{$EndIf}
{------------------------------------------------------------------------------
Index: interfaces/gtk/gtklclintf.inc
===================================================================
--- interfaces/gtk/gtklclintf.inc (wersja 8890)
+++ interfaces/gtk/gtklclintf.inc (kopia robocza)
@@ -232,6 +232,8 @@
Result:=true;
end;
+
+
{------------------------------------------------------------------------------
function TGtkWidgetSet.ExtUTF8Out(DC: HDC; X, Y: Integer; Options: Longint;
Rect: PRect; Str: PChar; Count: Longint; Dx: PInteger): Boolean;
@@ -259,7 +261,27 @@
Result:=ExtTextOut(DC,X,Y,Options,Rect,Str,Count,Dx);
end;
end;
+function TGtkWidgetSet.TextUTF8Out(DC: HDC; X, Y: Integer; Str: PChar; Count:
Longint): Boolean;
+var
+ IsDBCSFont: Boolean;
+ NewCount: Integer;
+begin
+ UpdateDCTextMetric(TDeviceContext(DC));
+ IsDBCSFont:=TDeviceContext(DC).DCTextMetric.IsDoubleByteChar;
+ if IsDBCSFont then begin
+ NewCount:=Count*2;
+ if FExtUTF8OutCacheSize<NewCount then begin
+ ReAllocMem(FExtUTF8OutCache,NewCount);
+ FExtUTF8OutCacheSize:=NewCount;
+ end;
+ NewCount:=UTF8ToDoubleByte(Str,Count,FExtUTF8OutCache)*2;
+ Result:=TextOut(DC,X,Y,FExtUTF8OutCache,NewCount);
+ end else begin
+ Result:=TextOut(DC,X,Y,Str,Count);
+ end;
+end;
+
{------------------------------------------------------------------------------
function TGTKWidgetSet.FontCanUTF8(Font: HFont): boolean;
Index: include/lclintfh.inc
===================================================================
--- include/lclintfh.inc (wersja 8890)
+++ include/lclintfh.inc (kopia robocza)
@@ -63,6 +63,7 @@
procedure DrawArrow(Arrow: TComponent; Canvas: TPersistent); {$IFDEF
IF_BASE_MEMBER}virtual;{$ENDIF}
function ExtUTF8Out(DC: HDC; X, Y: Integer; Options: Longint; Rect: PRect;
Str: PChar; Count: Longint; Dx: PInteger): Boolean; {$IFDEF
IF_BASE_MEMBER}virtual;{$ENDIF}
+function TextUTF8Out(DC: HDC; X, Y: Integer; Str: PChar; Count: Longint):
Boolean; {$IFDEF IF_BASE_MEMBER}virtual;{$ENDIF}
function FontCanUTF8(Font: HFont): boolean; {$IFDEF
IF_BASE_MEMBER}virtual;{$ENDIF}
function Frame(DC: HDC; const ARect: TRect): Integer; {$IFDEF
IF_BASE_MEMBER}virtual;{$ENDIF}
Index: include/intfbaselcl.inc
===================================================================
--- include/intfbaselcl.inc (wersja 8890)
+++ include/intfbaselcl.inc (kopia robocza)
@@ -139,6 +139,12 @@
Result:=ExtTextOut(DC,X,Y,Options,Rect,Str,Count,Dx);
end;
+function TWidgetSet.TextUTF8Out(DC: HDC; X, Y: Integer; Str: PChar; Count:
Longint): Boolean;
+begin
+ Result:=TextOut(DC,X,Y,Str,Count);
+end;
+
+
function TWidgetSet.FontCanUTF8(Font: HFont): boolean;
begin
Result:=false;
Index: include/lclintf.inc
===================================================================
--- include/lclintf.inc (wersja 8890)
+++ include/lclintf.inc (kopia robocza)
@@ -136,6 +136,12 @@
Result := WidgetSet.ExtUTF8Out(DC,X,Y,Options,Rect,Str,Count,Dx);
end;
+
+function TextUTF8Out(DC: HDC; X, Y: Integer; Str: PChar; Count: Longint):
Boolean;
+begin
+ Result := WidgetSet.TextUTF8Out(DC,X,Y,Str,Count);
+end;
+
function FontCanUTF8(Font: HFont): boolean;
begin
Result := WidgetSet.FontCanUTF8(Font);