michaelk Posted October 25, 2021 Share Posted October 25, 2021 If I have a string variable who's length I haven't bothered to check and I do BeginText; S1 EndText; SetTextWrap(LNewObj,TRUE); What determines the width of the text object? I know I can set it, but when I don't sometimes it goes as wide as the text no matter how long and sometimes it wraps. Not sure why it does that or how to predict it. Does it matter if the string is formed by concatenating strings and CHR(13)s? Quote Link to comment
Pat Stanford Posted October 25, 2021 Share Posted October 25, 2021 In my quick test, regardless of the length of a DynArray of Char (I did not test specifically with String), it allways wraps the last character unless you have a CHR(13) in the string which forces a wrap. Procedure Test; Const S1='abcdefghijklmnopqrstuwxyz26ABCDEFGHIJKLMNOPQRSTUVWXYZ54abcdefghijklmnopqrstuwxyz82ABCDEFGHIJKLMNOPQRSTUVWXYZ110abcdefghijklmnopqrstuwxyz139ABCDEFGHIJKLMNOPQRSTUVWXYZ168abcdefghijklmnopqrstuwxyz197ABCDEFGHIJKLMNOPQRSTUVWXYZ226abcdefghijklmnopqrstuwxyz255ABCDEFGHIJKLMNOPQRSTUVWXYZ284abcdefghijklmnopqrstuwxyz313ABCDEFGHIJKLMNOPQRSTUVWXYZ352'; VAR S2:DynArray of Char; BEGIN S2:=Concat(SubString(S1,'2',1),CHR(13),SubString(S1,'6',2),CHR(13),S1); Moveto(0,0); BeginText; S2 EndText; SetTextWrap(LNewObj,TRUE); End; Run(Test); If you copy this out, be careful of the wrapping. The entire Const line should be on a single line (or at least it was for me). Quote Link to comment
michaelk Posted October 25, 2021 Author Share Posted October 25, 2021 In a plug-in I'm seeing cases where it will go super long and cases with a CHR(13) where it's maybe 20 characters before the break but it wraps anyway. Need to do more experimenting… Quote Link to comment
Pat Stanford Posted October 25, 2021 Share Posted October 25, 2021 Good luck. Let us know what you find. 1 Quote Link to comment
JBenghiat Posted October 27, 2021 Share Posted October 27, 2021 A few things to consider: - The text is gong to create using the default text settings, so it may or may not wrap before you tell it to. - You also need to set the width of the object, otherwise there's not a universal way of determining the wrap (it's not like text wraps to the page boundary). - You may find that CreateText() is more reliable, both because of the default formatting coming into play and because you have to take into account line breaks and other special characters in the code itself. 1 Quote Link to comment
Jesse Cogswell Posted October 28, 2021 Share Posted October 28, 2021 @michaelk The SetTextWrap procedure basically just checks the "Wrap Text" parameter for a text object. The wrap itself is set using the SetTextWidth procedure. I also agree with @JBenghiat, I always use CreateText to create text objects. Fewer lines of code. Quote Link to comment
MullinRJ Posted October 29, 2021 Share Posted October 29, 2021 @michaelk, At first I thought you exposed a bug, but after several days of visiting this post and rereading your code snippet for the umpteenth time I think your confusion is self inflicted. If you remove the SetTextWrap(LNewObj, TRUE); line, do you still get unpredictable results? I suspect not, but If so then you may have found a bug, but I have not been able to reproduce it in my very limited testing. In the following, I use "Text Object" to refer to the text on the page (blue selection handles et al.), and I use "Text Block" to mean the characters of text in your text variable S1. The Text Block's length can only be changed by changing the Font Face, Size, Style, etc., so you can treat it like a constant until you change any of the text's attributes. Now back to your code snippet, with the SetTextWrap(LNewObj, TRUE); line in place you are telling VW to force the text block to use Wrapping, even though the length of the text block is unchanged from its default value, and VW responds in kind. Please note that the Text Wrap checkbox in the OIP does not control a real text attribute. It does not save a boolean value with the file and there is no way to set it to be ON by default. What is saved is the WIDTH of the text block. When the calculated text width does not equal the text block width, either because it was changed manually or programmatically, the Wrap Text checkbox gets set. If you CLEAR the Wrap Text checkbox, either manually or programmatically, the text object's width is set to be equal to the calculated width of the text block (which is affected by Font Face, Size, Style, etc.) What you see on the screen when the Text Object's width does NOT equal the Text Block's length should be predictable. What you see on the screen, when the Text Block's length exactly equals Text Object's width, is affected by what the text block contains. 1) If the Text Block ends in a printable character, the block will wrap the last word (assuming the block contains a white space and words) to the next line. 2) If the Text Block ends with a Space or a Tab character, no visible word wrapping occurs. 3) If the Text Block ends with a Carriage Return, the text block already has a second line, so the first line's appearance is governed by 1) and 2) above. If you don't care to digest all of the minutiae I've just blathered above, then play with this test code and make you own observations. PROCEDURE xxx; { Script to show how OIP "Wrap Text" affects word wrapping with different string endings. } { Change constant "kWordWrap" from FALSE to TRUE to see effects of wrapping. } { Document settings are INCHES, Layer Scale = 1, Font = Arial, Point Size = 12.} { 28 Oct 2021 - Raymond J Mullin } CONST Tb = chr(9); CR = chr(13); Sp = chr(32); kWordWrap = FALSE; VAR S, S1, S2, S3 :String; procedure PlaceText(TxtBlk :String; X, Y :Real); Begin MoveTo(X, Y); BeginText; TxtBlk EndText; SetTextWrap(LNewObj, kWordWrap); End; { PlaceText } BEGIN S := concat('Abysmal echo duck lamps'); S1 := concat(S, Sp); S2 := concat(S, Tb); S3 := concat(S, CR); PlaceText(S, 0, 0); PlaceText(S1, 0, -0.5); PlaceText(S2, 0, -1.0); PlaceText(S3, 0, -1.5); SysBeep; END; Run(xxx); HTH, Raymond PS - I tried @Pat Stanford's example and was able to get the string to word wrap when using Tabs instead of Carriage Returns, but not with Spaces. No idea why. If you are trying to predict how raw character data will wrap, I leave it to you to investigate further. If you limit yourself to human readable words, you may have better results. 1 Quote Link to comment
michaelk Posted October 29, 2021 Author Share Posted October 29, 2021 That is fantastic!! …and it makes sense :-). Thank you!!! Quote Link to comment
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.