groff
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Groff] Diagrams in ASCII but text in UTF-8


From: Jérôme Frgacic
Subject: Re: [Groff] Diagrams in ASCII but text in UTF-8
Date: Mon, 4 Feb 2013 17:45:39 +0000 (GMT)


On Sun 03 Feb 2013 20:36:51 +0100 (CET), Werner LEMBERG wrote:
> This is not possible.  The used characters for box crossings and the
> like are hard‐coded into grotty, and you can only decide globally
> whether to use ‐Tutf8 or ‐Tascii.  However, a small post‐processing
> script to replace the box and line characters with ASCII equivalents
> should work.
>
> You can find the used characters in src/devices/grotty/tty.cpp (look
> for ‘is_unicode’ clauses).

Thanks for your reply. :)
I effectively found the characters used for utf‐8 output (there are
defined in an array called ‘crossings’) and wrote a little post‐
processor in C (yes, I could write it in another language) to do the
translation. If it can help someone, Here is the source code:


#include <locale.h>
#include <stdio.h>
#include <wchar.h>
#include <wctype.h>


int
main(void)
{
        wint_t wc;

        setlocale(LC_CTYPE, "");
        while ((wc = getwchar()) != WEOF) {
                switch (wc) {
                case 0x2577: /* ╷ */
                case 0x2575: /* ╵ */
                case 0x2502: /* │ */
                        putwchar(L’|’);
                        break;
                case 0x2576: /* ╶ */
                case 0x2574: /* ╴ */
                case 0x2500: /* ─ */
                        putwchar(L’‐’);
                        break;
                case 0x250C: /* ┌ */
                case 0x2514: /* └ */
                case 0x251C: /* ├ */
                case 0x2510: /* ┐ */
                case 0x2518: /* ┘ */
                case 0x2524: /* ┤ */
                case 0x252C: /* ┬ */
                case 0x2534: /* ┴ */
                case 0x253C: /* ┼ */
                        putwchar(L’+’);
                        break;
                default:
                        putwchar(wc);
                        break;
                }
        }
        return 0;
}



reply via email to

[Prev in Thread] Current Thread [Next in Thread]