How can we post ASCII art on Facebook wall?

前端 未结 2 844
無奈伤痛
無奈伤痛 2021-01-14 16:52

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

相关标签:
2条回答
  • 2021-01-14 16:57

    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.

    Edit

    Have a look at this Facebook group. The users compensate the absence of a monospaced font by

    1. using just symbols with roughly the same width
    2. filling room with short symbols like .

    Monospaced:

     `♥♥'''''''''''''''♥♥`  
     `♥♥'''''''''''''''♥♥`
    

    Proportional:

    ♥♥'''''''''''''''♥♥

    0 讨论(0)
  • 2021-01-14 17:14

    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

    0 讨论(0)
提交回复
热议问题