Do you own a Debenu Quick PDF Library version 7, 8, 9, 10, 11, 12, 13 or iSEDQuickPDF license? Upgrade to Debenu Quick PDF Library 14 today!
Word Wrapping |
Post Reply |
Author | |
runfastman
Beginner Joined: 15 Nov 11 Location: Idaho Status: Offline Points: 4 |
Post Options
Thanks(0)
Posted: 15 Nov 11 at 3:51PM |
Word Wrapping seems to only work on spaces. Is there a way to set the characters it can word wrap on? I would like it to also word wrap on "-".
|
|
runfastman
Beginner Joined: 15 Nov 11 Location: Idaho Status: Offline Points: 4 |
Post Options
Thanks(0)
|
I had a picture there but it got removed. If the word is wider than the cell it is in, the text just keeps going out of the cell and keeps going mixing the text of the next cell.
|
|
Ingo
Moderator Group Joined: 29 Oct 05 Status: Offline Points: 3524 |
Post Options
Thanks(0)
|
Hi!
Perhaps in this case you should work on the text before and if you find a '-' in the string you could insert a space behind? Cheers and welcome here, Ingo |
|
runfastman
Beginner Joined: 15 Nov 11 Location: Idaho Status: Offline Points: 4 |
Post Options
Thanks(0)
|
I can't this is auto processing and I don't know what is going to be in it exactly. Most of the time there is a dash but sometimes not. Most word processors like Word, will break on a space and then a - or special characters and if there are none, it just chops the word off at the max size and moves the rest to the next line.
|
|
steave
Beginner Joined: 18 Jan 12 Location: FL, USA Status: Offline Points: 1 |
Post Options
Thanks(0)
|
I hope the following conversions will help as i believe your problem seems like a same
http://stackoverflow.com/questions/8355175/uilabel-word-wrap-character-wrap |
|
edvoigt
Senior Member Joined: 26 Mar 11 Location: Berlin, Germany Status: Offline Points: 111 |
Post Options
Thanks(0)
|
Hi,
here a solutionidea, written in Delphi 7. It uses the old strings with a byte for every character. It shall only be a demonstration for the use of more thean one wrapindicator. There the code of a procedure, which takes a string-var and a startposition. It draws so much lines as possible in an given box and reports, what it has done. procedure WrapTextToBox(QP: TQuickPDF; const text: string; start: integer; BoxTop, BoxWidth, BoxHeight: double; WrapChars: string; var NewStart: integer; var RealHeight: double); const CR = #13; LF = #10; Tab = #9; var h, hb, y: double; pw, p0, p1, len, n: integer; linecomplete: boolean; begin // wrap text, using selected Font // get TextHeight/LineHeight and minimum width for the smallest character h := QP.GetTextHeight; // this or hb for "linefeed" hb := QP.GetTextBound(2); // height over baseline y := BoxTop+h; p0 := start; //QP.DrawText(25, 80, Format('%f %f',[QP.GetTextHeight, swidth])); n := Length(text); linecomplete := false; pw := 0; // position of last wrap-position in text while (y<BoxTop+Boxheight) and (p0<n) do begin p1 := p0; len := 0; repeat // starting a line case text[p1] of CR, LF: begin // force a new line and step over single CR, LF or CRLF combined len := p1-p0; // exclude char on p1 if (text[p1]=CR) and ((p1<n) and (text[p1+1]=LF)) then inc(p1); linecomplete := true; end; '-', '/', ':': if (QP.GetTextWidth(copy(Text, p0, p1-p0+1))<=BoxWidth) then pw := p1; ' ',Tab: if (p1>p0) then pw := p1-1; end; {case} inc(p1); if not linecomplete then inc(len); // not if CR/LF found until linecomplete or (p1=n) or (QP.GetTextWidth(copy(Text, p0, len))>BoxWidth); if linecomplete or (p1=n) then begin QP.DrawText(25, y, copy(text, p0, p1-p0)); linecomplete := false; // ready for the next end else begin // at least one char to much dec(len); // the last char could be a wrapchar = to late if (pw>0) and (pw<p0+len) then begin // but we have a wrappoint before QP.DrawText(25, y, copy(text, p0, pw-p0+1)); p1 := pw+1; pw := 0; // clear it while (p1<n) and (text[p1]in [' ', Tab]) do inc(p1); // no space on start of next line end else begin // here we have a word to long for Boxwidth p1 := p0+len-1; // cut it QP.DrawText(25, y, copy(text, p0, p1-p0+1)); inc(p1); end; end; p0 := p1; // the next linestart y := y + h; // line position in box end; if (p1<n) then NewStart := p1 else NewStart := 0; // all fits in the given box RealHeight := y-BoxTop; end; The idea is to go through the text and to note last position of chars of interest, which fit in the box. There are the different codings for newline. This chars force a new line, but shall not be part of the line. The chars - or / and : shall in this example indicate possible wrapposition follows. A blank or a tab indicate it too, but they are not to show. I hope the comments make it clear enough. My testcase looks so: procedure TPDFtestForm.WrapText; var QP: TQuickPDF; s: string; n: integer; hb, sizey: double; MS: TMemoryStream; BM: TBitmap; newPos: integer; // 0 if ready, else the next start if not all in the box usedheight: double; begin // let text fit in a box QP := TQuickPDF.Create; if QP.UnlockKey({$I PDFkey.inc})<>1 then exit; QP.SetOrigin(1); // topleft! QP.SetMeasurementUnits(1); // millimeters QP.SetPageDimensions(210, 297); // DIN A4 QP.SetLineColorCMYK(0, 0, 0, 0.5); QP.SetLineWidth(0.2); QP.DrawBox(0, 0, 210, 297, 0); QP.AddStandardFont(4); QP.SetTextSize(10); s := 'Senseless testtext only to be wrapped by QuickPDF+Del-phi/Borland QP.Version: 08.14 or Tab to fit in a small textbox. So it works! '; s := s + s + s + s + 'longAndMuchTooBigForOneLineItShouldBeTruncatedOnTheMaximumWidth' + #13#10 + 'Newline because of CRLF. ' + s; QP.DrawBox(25, 25, 100, 50, 2); WrapTextToBox(QP, s, 1, 25, 100, 50, ' -', newPos, usedheight); QP.DrawText(25, 85, Format('usedHeight=%f, goon at pos %d',[usedheight, newPos])); Try it. Cheers, Werner |
|
Thomas Mueller
Beginner Joined: 19 Jul 12 Location: California,US Status: Offline Points: 2 |
Post Options
Thanks(0)
|
Word wrap is a word processing feature that forces all text to be confined within defined margins. When a line of text is filled, the word processor automatically moves the text to the next line, so the user doesn't have to press the return key after every line.
Thanks in advance, Thomas |
|
Post Reply | |
Tweet
|
Forum Jump | Forum Permissions You cannot post new topics in this forum You cannot reply to topics in this forum You cannot delete your posts in this forum You cannot edit your posts in this forum You cannot create polls in this forum You cannot vote in polls in this forum |
Copyright © 2017 Debenu. Debenu Quick PDF Library is a PDF SDK. All rights reserved. About — Contact — Blog — Support — Online Store