c# - Word wrap text to fit an rectangle of certain ratio (not size) -


anyone know of algorithm can break text @ word boundaries fit rectangle of approximate ratio - e.g. 60:40 (width:height)?

note not width (e.g. 80 chars or 600px etc) , arbitrary height rules out every word-wrapping algorithms can find.

bonus points javascript more algorithm implementation.

this it:

int lineheight := getheightoftextline() int lines := 0 {   lines += 1   int width = lines * lineheight * ratio   string wrappedtext := break(input, width) } while(getnumberoflines(wrappedtext) != lines) 

starting 1 line test each height (multiples of lineheight) if have rectangle given ration can hold text. if breaking text @ calculated width leads string more lines allowed (for run) continue, otherwise have solution.


Comments

Popular posts from this blog

android - Spacing between the stars of a rating bar? -

html - Instapaper-like algorithm -

c# - How to execute a particular part of code asynchronously in a class -