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
* Why not using GetTextExtent 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)

>    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.
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.

Marc

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

Reply via email to