0

is there a thing to order words by their pixel width? I know fonts are different but it's for Twitter. What I mean is:

a
iiii
aa
llllll
aaa
aAa
WW
aaaa

Because that, by character number count length, is not like a half pyramid. A way to arrange them from shortest to longest no matter how many letters they have, but how long the entire word is by looking at the last pixel of the font.

Mike 'Pomax' Kamermans
  • 49,297
  • 16
  • 112
  • 153
MySpiders
  • 1
  • 1
  • 1
    When you say *"it's for Twitter"* are you referring to finding a solution using the font used by Twitter? Also, could you perhaps clarify what you're trying to sort? Is this a JavaScript array? – 4castle Feb 11 '17 at 01:31
  • Yes, mainly for Twitter's font, but it works the same with web, iOS, Android... Their font lengths are basically the same. And just any list or words, because when they have the same number of characters it's hard to order them. Example: "nose eyes toes book pink love"... – MySpiders Feb 11 '17 at 01:41
  • Okay, but web, iOS, and Android are very different technologies. I understand the concept of what you're trying to accomplish, but I don't understand where this input is coming from, what programming language you plan on using, and where the output should go. – 4castle Feb 11 '17 at 01:45
  • Welcome to Stack Overflow. When you're posting, you should be as specific as possible with how you want to solve the problem. This SO thread should give you some ideas for how to solve this problem: http://stackoverflow.com/questions/118241/calculate-text-width-with-javascript/21015393#21015393 – cpilko Feb 11 '17 at 01:46

1 Answers1

0

Answering your question, YES, there is a way to achieve what you want. So basically what you need is:

  1. Convert every line of text to an image
  2. Measure widths of all the images and store the results in an array
  3. Order the array
  4. Print the text according to the order in the array

The programming would be easier if it is done on a server-side language but you could do it in Java or C

docliving
  • 111
  • 1
  • 6