Hi
Attached patch repair TGtkWidgetSet.DrawText under GTK2 (I receive
crush). Problem was connected with WordWrap.
Darek
Index: interfaces/gtk/gtkobject.inc
===================================================================
--- interfaces/gtk/gtkobject.inc (wersja 10881)
+++ interfaces/gtk/gtkobject.inc (kopia robocza)
@@ -7128,13 +7128,23 @@
var
UseFont : TGtkIntfFont;
- function GetLineWidthInPixel(LineStart, LineLen: integer): integer;
+ function GetLineWidthInPixel(LineStart, LineLen: integer;aAmp:boolean):
integer;
var
- lbearing, rbearing, width, ascent, descent: LongInt;
+ xSize : tSize;
+ NewStr : PChar;
begin
- GetTextExtentIgnoringAmpersands(UseFont, @AText[LineStart], LineLen,
- @lbearing, @rBearing, @width, @ascent, @descent);
- Result:=Width;
+// GetTextExtentIgnoringAmpersands(UseFont, @AText[LineStart], LineLen,
+// @lbearing, @rBearing, @width, @ascent, @descent);
+
+ if aAmp then begin
+ NewStr := RemoveAmpersands(@AText[LineStart], LineLen);
+ LineLen:= StrLen(NewStr);
+ end else
+ NewStr := @AText[LineStart];
+
+ GetTextExtentPoint(DC,NewStr,LineLen,xSize);
+ Result:=xSize.cx;
+ if aAmp then StrDispose(NewStr);
end;
function FindLineEnd(LineStart: integer): integer;
@@ -7142,15 +7152,20 @@
CharLen,
LineStop,
LineWidth, WordWidth, WordEnd, CharWidth: integer;
+ wasAmpersand : boolean;
begin
// first search line break or text break
Result:=LineStart;
- while not (AText[Result] in [#0,#10,#13]) do inc(Result);
+ wasAmpersand:=false;
+ while not (AText[Result] in [#0,#10,#13]) do begin
+ if AText[Result]='&' then wasAmpersand:=true;
+ inc(Result);
+ end;
if Result<=LineStart+1 then exit;
lineStop:=Result;
// get current line width in pixel
- LineWidth:=GetLineWidthInPixel(LineStart,Result-LineStart);
+ LineWidth:=GetLineWidthInPixel(LineStart,Result-LineStart,wasAmpersand);
if LineWidth>MaxWidthInPixel then begin
// line too long
// -> add words till line size reached
@@ -7165,7 +7180,7 @@
// find word end
while not (AText[WordEnd] in [#0,' ',#9,#10,#13]) do inc(WordEnd);
// calculate word width
- WordWidth:=GetLineWidthInPixel(Result,WordEnd-Result);
+ WordWidth:=GetLineWidthInPixel(Result,WordEnd-Result,wasAmpersand);
until LineWidth+WordWidth>MaxWidthInPixel;
if LineWidth=0 then begin
// the first word is longer than the maximum width
@@ -7174,7 +7189,7 @@
LineWidth:=0;
repeat
charLen:=UTF8CharacterLength(@AText[result]);
- CharWidth:=GetLineWidthInPixel(Result,charLen);
+ CharWidth:=GetLineWidthInPixel(Result,charLen,wasAmpersand);
inc(LineWidth,CharWidth);
if LineWidth>MaxWidthInPixel then break;
if result>=lineStop then break;