I was wondering if there is an algorithm for dividing one line into several rows, so that the resultant set of several lines Fit in a squared shape instead of a wide rectangular shape. Give me some examples,
Input: Hello It's actually a long line.
Output:
Hi it is a really long line
Input: abcdef
Output:
abc
def
Input: This is really such looooooooooooooooooooooooong line. This is the end.
Output:
It really is - looooooooooooooooooooooong
line it is the end
If you look in the examples given above, the input line is in a wide rectangle Fits. But the maximum output fits in a squared size.
What exactly needs to be done here, just calculate the number of characters in the line, take the square root of that number. Then put the square root number of the characters in each line. But in the above given examples, splitting is required to wrap words instead of letters. Is there a standard algorithm for this? Any code examples / indicators will be appreciated!
As you have seen, it basically means the minimum and maximum width , Which is the opposite of only one max width, which is usually done. (And your example shows that if you can not hyphenate words, it is not always possible.) TeX can do this (refer to the \ parshape command): its line-breaking algorithm arbitrary shapes (And hyphenation, too), and the state of the art is considered, so if you want to create a class in any serious way, then you must definitely optimize the NIIT / PLUS algorithm ().
Comments
Post a Comment