gigaherz / Guidebook

Minecraft book API and library
https://www.curseforge.com/minecraft/mc-mods/guidebook
Other
31 stars 16 forks source link

[Suggestion] Justification #89

Open Klebestreifen opened 5 years ago

Klebestreifen commented 5 years ago

Justify alignments look very neat. Therefore, I would like to have such a feature.

gigaherz commented 5 years ago

Justified text is very hard, but I will keep the request in mind.

HenryLoenwind commented 5 years ago

Let

W be the list of words for a line l(x) be the length in pixels of a word or list of words x c(x) the number of elements in the list x L be the length of the line X be the draw position, starting at 0

  1. Draw W0 at X
  2. Increment X by l(W0)
  3. Remove W0 from W
  4. Calculate S as round((L - X - l(W)) / C(W))
  5. Increment X by S
  6. Draw W0 X
  7. Increment X by l(W0)
  8. Remove W0 from W
  9. repeat from 4 unless W is empty

Yes, this has a certain bias to one side depending on the rounding function used, the alternative is to calculate the word distance once and then keep a record of the rounding error.