Advertisement
Guest User

Word Wrap procedure

a guest
Jan 31st, 2017
448
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. 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.
  2. https://en.wikipedia.org/wiki/Line_wrap_and_word_wrap#Algorithm
  3.  
  4. procedure WordWrap:
  5.  def input param textToFormat as char no-undo.
  6.  def input param lineLength as int no-undo.
  7.  def input param breakChar as char no-undo.
  8.  
  9.  def output param formattedText as char no-undo.
  10.  
  11.  def var currentWord as char no-undo.
  12.  def var currentWordLength as int no-undo.
  13.  def var ix as int no-undo.
  14.  def var spaceLeft as int no-undo.
  15.  
  16.  spaceLeft = lineLength.
  17.  
  18.  do ix = 1 to num-entries(textToFormat, " "):
  19.    currentWord = entry(ix, textToFormat, " ").
  20.    currentWordLength = length(currentWord).
  21.    if currentWordLength + 1 gt spaceLeft then do:
  22.      entry(ix, textToFormat, " ") = breakChar + entry(ix, textToFormat, " ").
  23.      spaceLeft = lineLength - currentWordLength.
  24.    end.
  25.    else do:
  26.      spaceLeft = spaceLeft - currentWordLength + 1.
  27.    end.
  28.  end.
  29.  
  30.  formattedText = textToFormat.
  31. end procedure.
  32.  
  33. An example from a recent report I worked on:
  34. run WordWrap(SAMedicalDetail.Comments, 70, chr(31), output PrintDetail.details[3]).
  35.  
  36. do ix = 1 to num-entries(PrintDetail.details[3], chr(31)):
  37.  report:PrintText(entry(ix, PrintDetails.details[3], chr(31)), xPosition).
  38. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement