Marc Weustink wrote:

darekm wrote:
Hi
Attached patch repair TGtkWidgetSet.DrawText under GTK2  (I receive
crush). Problem was connected with WordWrap.

Thanks, some inline conmments.

------------------------------------------------------------------------

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;


* AIgnoreAmpersant would be a better descriptive name than aApm
OK

* Why not using GetTextExtent

tis may broke existing code or make default: AIgnoreAmpersant:boolean=false)

or GetTextExtentIgnoringAmpersands based
on the boolean (note to ourself: why do we have such long name for it
and isn't is added as option to GetTextExtent)
it`s only need change name and results of GetLineWidthInPixel

  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);

Is this correct ? Should all ampersants get removed ? IIRC on windows
imly the first is shown as underscore.
I don't change any of behavior of this function.I only check that is ampersand in string. RemoveAmpersands run as usually
current GetTextExtentIgnoringAmpersands crush
and without patch WordWrap work slowly (more string allocations)

Second, You first check it has an ampersant and based on this
GetLineWidthInPixel is called which you changed in a normal
GetTextExtend when there is no ampersant.
I think fixing GetTextExtentIgnoringAmpersands when there are no
ampersants would be a better solution, than to work around this.
GetTextExtendIgnoringAmpersands exist only in Gtk 1 (its internal and its no any in Win not gtk2),
no other places which use them
for me is better make WordWrap based on primitives function
like getTextExtens and RemoveApmpersands (easer to move to other widget sets)




But maybe I don't understand everything, what I should prepare.


Darek

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

Reply via email to