Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Wrote UP a handy bit OF LINE wrapping CODE FOR anyone working WITH PDFs awhile ago so I'm putting it here for easy access. Bit easier to wield than the existing FormattedText program.
- https://en.wikipedia.org/wiki/Line_wrap_and_word_wrap#Algorithm
- procedure WordWrap:
- def input param textToFormat as char no-undo.
- def input param lineLength as int no-undo.
- def input param breakChar as char no-undo.
- def output param formattedText as char no-undo.
- def var currentWord as char no-undo.
- def var currentWordLength as int no-undo.
- def var ix as int no-undo.
- def var spaceLeft as int no-undo.
- spaceLeft = lineLength.
- do ix = 1 to num-entries(textToFormat, " "):
- currentWord = entry(ix, textToFormat, " ").
- currentWordLength = length(currentWord).
- if currentWordLength + 1 gt spaceLeft then do:
- entry(ix, textToFormat, " ") = breakChar + entry(ix, textToFormat, " ").
- spaceLeft = lineLength - currentWordLength.
- end.
- else do:
- spaceLeft = spaceLeft - currentWordLength + 1.
- end.
- end.
- formattedText = textToFormat.
- end procedure.
- An example from a recent report I worked on:
- run WordWrap(SAMedicalDetail.Comments, 70, chr(31), output PrintDetail.details[3]).
- do ix = 1 to num-entries(PrintDetail.details[3], chr(31)):
- report:PrintText(entry(ix, PrintDetails.details[3], chr(31)), xPosition).
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement