Is it possible to automatically word wrap a title? I have a fairly long one a custom wants on a smaller chart. If it can't, but there is a code-snippet around for inserting the #13s into the text, I would appreciate it.
Thank you,
Ed Dressel
Word Wrap title
-
- Advanced
- Posts: 228
- Joined: Tue Aug 28, 2007 12:00 am
- Location: Oregon, USA
-
- Advanced
- Posts: 228
- Joined: Tue Aug 28, 2007 12:00 am
- Location: Oregon, USA
Re: Word Wrap title
I used the following code, but i my app, had to use 60% of the chart's width to get it t work correctly. (The chart is created just for an image and I had to parent it with a form for it to work).
Maybe someone has a better code snippet that would work better? (BTW, I am using version 8.06 of the chart)
Code: Select all
function GetWrappedText(const aWidth: integer; aCanvas: TCanvas3D; const aText: string): string;
var
lFinished: Boolean;
lPos: Integer;
lText: string;
lUnusable: string;
begin
result := '';
lText := aText;
lUnusable := '';
while Length(lText) > 0 do
begin
lFinished := False;
while (aCanvas.TextWidth(lText) > aWidth) and (not lFinished) do
begin
lPos := ScanB(lText, #32, Length(lText));
if (lPos > 0) then
begin
lUnusable := Trim(Copy(lText, lPos + 1, MaxInt) + ' ' + lUnusable);
Delete(lText, lPos, MaxInt);
end
else
lFinished := True;
end;
result := result + lText;
if Length(lUnusable) > 0 then
result := result + #13;
lText := lUnusable;
lUnusable := '';
end;
end;
Maybe someone has a better code snippet that would work better? (BTW, I am using version 8.06 of the chart)
Re: Word Wrap title
Hello TestAlways,
If you change the way of calculating the position where you want to cut text, using number of characters instead of measuring pixels you can achieve that easily using Delphi’s TextWrap function.
On the other hand, I couldn’t run your code because method ScanB doesn’t compile here. So, you can try to arrange a simple example that we can run as-is to reproduce the problem here?
Thanks,
If you change the way of calculating the position where you want to cut text, using number of characters instead of measuring pixels you can achieve that easily using Delphi’s TextWrap function.
On the other hand, I couldn’t run your code because method ScanB doesn’t compile here. So, you can try to arrange a simple example that we can run as-is to reproduce the problem here?
Thanks,
Best Regards,
Sandra Pazos / Development & Support Steema Software Avinguda Montilivi 33, 17003 Girona, Catalonia Tel: 34 972 218 797 http://www.steema.com |
Instructions - How to post in this forum |
-
- Advanced
- Posts: 228
- Joined: Tue Aug 28, 2007 12:00 am
- Location: Oregon, USA
Re: Word Wrap title
Sorry--ScanB is a Hyper Strings function. Here is a function that works for this scenario (FWIW, it is not from the HyperStr.pas file, I just quickly wrote this):
That will allow the previous code to run.
Ed Dressel
Code: Select all
function ScanB(const aText: string; const aChar: char; const aStartPos: integer): integer;
var
I: Integer;
begin
for I := Min(aStartPos, Length(aText)) downto 0 do
if aText[I] = aChar then
begin
result := I;
exit;
end;
result := 0;
end;
Ed Dressel
Re: Word Wrap title
Hello Dressel,
Sorry for the delay. I have tested your code and it seems work fine for me using last version 8 of TeeChartVCL. Please, could you explain exactly which problem you see when use your code, because we can try to help you solve it?
Thanks,
Sorry for the delay. I have tested your code and it seems work fine for me using last version 8 of TeeChartVCL. Please, could you explain exactly which problem you see when use your code, because we can try to help you solve it?
Thanks,
Best Regards,
Sandra Pazos / Development & Support Steema Software Avinguda Montilivi 33, 17003 Girona, Catalonia Tel: 34 972 218 797 http://www.steema.com |
Instructions - How to post in this forum |