In my app, I have a requirement to post the ASCII art from my iPhone app onto the Facebook wall post. But the problem I face is that Facebook font (Lucida Console) Changes t
Courier is a monospaced font. That means, that every letter has the same space. That's why it is easy to use for ASCII art and popular for coding — as words with same length will always be at same positions.
From Facebook CSS:
font-family: 'lucida grande', tahoma, verdana, arial, sans-serif;
Lucida Grande is a proportional font. i.e. an i
uses much less space than an m
. Words in different lines won't match very well.
Have a look at this Facebook group. The users compensate the absence of a monospaced font by
.
Monospaced:
`♥♥'''''''''''''''♥♥`
`♥♥'''''''''''''''♥♥`
Proportional:
♥♥'''''''''''''''♥♥
I came up with a Python script, only tested it with simple examples so far.
#!/usr/bin/python
'''
fbformat -- format ASCII for Facebook
'''
import sys, os
PRINTABLE = [' '] + map(chr, range(ord('!'), ord('~') + 1))
FB_ABLE = [u'\u3000'] + map(unichr, range(0xff01, 0xff5f))
TO_FB = dict(zip(PRINTABLE, FB_ABLE))
FROM_FB = dict(zip(FB_ABLE, PRINTABLE))
COMMAND = os.path.splitext(os.path.basename(sys.argv[0]))[0]
TEXT = sys.stdin.read().decode('utf8')
TO = ''.join([TO_FB.get(C, C) for C in TEXT])
FROM = ''.join([FROM_FB.get(C, C) for C in TEXT])
sys.stdout.write([TO, FROM][COMMAND == 'fbunformat'].encode('utf8'))
symlink it as ~/home/bin/fbformat
and ~/home/bin/fbunformat
, and make sure ~/home/bin
is in your PATH
.
enter the following as test.txt:
YES!
\o/
|
/ \
then:
jcomeau@aspire:~/rentacoder/gdavis$ fbformat < /tmp/test.txt
YES!
\o/
|
/ \
jcomeau@aspire:~/rentacoder/gdavis$ fbformat < /tmp/test.txt | fbunformat
YES!
\o/
|
/ \
resources: http://www.cs.tut.fi/~jkorpela/chars/spaces.html and https://en.wikipedia.org/wiki/Halfwidth_and_fullwidth_forms