|
楼主 |
发表于 2015-4-29 15:56:14
|
显示全部楼层
clxer 发表于 2015-4-29 15:45
用1.2.6没有这个问题
是的,上午有人在群里提醒我了,然后下午装了1.2.6,发现正常,1.2.6下的代码如下:- procedure TfrMemoView.WrapMemo;
- var
- size, size1, maxwidth: Integer;
- b: TWordBreaks;
- WCanvas: TCanvas;
- desc, aword: string;
- procedure OutLine(const str: String);
- var
- n, w: Word;
- begin
- n := Length(str);
- if (n > 0) and (str[n] = #1) then
- w := WCanvas.TextWidth(Copy(str, 1, n - 1)) else
- w := WCanvas.TextWidth(str);
- {$IFDEF DebugLR_detail}
- debugLn('Outline: str="%s" w/=%d w%%=%d',[copy(str,1,12),w div 256, w mod 256]);
- {$ENDIF}
- SMemo.Add(str + Chr(w div 256) + Chr(w mod 256));
- Inc(size, size1);
- end;
- procedure WrapLine(const s: String);
- var
- i, cur, beg, last, len: Integer;
- WasBreak, CRLF, IsCR: Boolean;
- ch: TUTF8char;
- begin
- CRLF := False;
- for i := 1 to Length(s) do
- begin
- if s[i] in [#10, #13] then
- begin
- CRLF := True;
- break;
- end;
- end;
- last := 1; beg := 1;
- if not CRLF and ((Length(s) <= 1) or (WCanvas.TextWidth(s) <= maxwidth)) then
- begin
- OutLine(s + #1)
- end else
- begin
- cur := 1;
- Len := UTF8Desc(S, Desc);
- while cur <= Len do
- begin
- Ch := UTF8Char(s, cur, Desc);
- // check for items with soft-breaks
- IsCR := Ch=#13;
- if IsCR then
- begin
- //handle composite newline
- ch := UTF8Char(s, cur+1, desc);
- //dont increase char index if next char is LF (#10)
- if ch<>#10 then
- Inc(Cur);
- end;
- if Ch=#10 then
- begin
- OutLine(UTF8Range(s, beg, cur - beg, Desc) + #1);
- //increase the char index since it's pointing to CR (#13)
- if IsCR then
- Inc(cur);
- Inc(cur);
- beg := cur;
- last := beg;
- Continue;
- end;
- if ch <> ' ' then
- if WCanvas.TextWidth(UTF8Range(s, beg, cur - beg + 1, Desc)) > maxwidth then
- begin
- WasBreak := False;
- if (Flags and flWordBreak) <> 0 then
- begin
- // in case of breaking in the middle, get the full word
- i := cur;
- while (i <= Len) and not UTF8CharIn(ch, [' ', '.', ',', '-']) do
- begin
- Inc(i);
- if i<=len then
- ch := UTF8Char(s, i, Desc);
- end;
- // find word's break points using some simple hyphenator algorithm
- // TODO: implement interface so users can use their own hyphenator
- // algorithm
- aWord := UTF8Range(s, last, i - last, Desc);
- if (FHyp<>nil) and (FHyp.Loaded) then
- begin
- try
- b := FHyp.BreakWord(UTF8Lowercase(aWord));
- except
- b := '';
- end;
- end else
- b := BreakWord(aWord);
- // if word can be broken in many segments, find the last segment that
- // fits within maxwidth
- if Length(b) > 0 then
- begin
- i := 1;
- while (i <= Length(b)) and
- (WCanvas.TextWidth(UTF8Range(s, beg, last - beg + Ord(b[i]), Desc) + '-') <= maxwidth) do
- begin
- WasBreak := True;
- cur := last + Ord(b[i]); // cur now points to next char after breaking word
- Inc(i);
- end;
- end;
- if (not WasBreak) and (FHyp<>nil) and FHyp.Loaded then
- // if hyphenator was specified and is valid don't break
- // words which hyphenator didn't break
- else
- // last now points to nex char to be processed
- last := cur;
- end
- else
- begin
- if last = beg then
- last := cur;
- end;
- if WasBreak then
- begin
- // if word has been broken, output the partial word plus an hyphen
- OutLine(UTF8Range(s, beg, last - beg, Desc) + '-');
- end else
- begin
- // output the portion of word that fits maxwidth
- OutLine(UTF8Range(s, beg, last - beg, Desc));
- // if space was found, advance to next no space char
- while (UTF8Char(s, last, Desc) = ' ') and (last < Length(s)) do
- Inc(last);
- end;
- beg := last;
- end;
- if UTF8CharIn(Ch, [' ', '.', ',', '-']) then
- last := cur;
- Inc(cur);
- end;
- if beg <> cur then
- OutLine(UTF8Range(s, beg, cur - beg + 1, Desc) + #1);
- end;
- end;
复制代码 |
|