Mailing List Archive


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

Re: [tlug] The wrong kanji



Travis Cardwell writes:

 > While it is not possible to identify (with certainty) the language of
 > plain text, applications that are designed to be multilingual may have
 > more knowledge.

"Don't teach Grandma XEmacs to suck eggs." :-)  Yes, I know something
about designing multilingual apps.

 > What I meant above is that fontconfig is not designed with this
 > level of control: there is no way to tell it the language of the
 > text it is rendering.

No, but you don't really want to (although it is a plausible idea on
the face of it).  Fonts don't easily fit into the category of language
(for example essentially all fonts tag themselves as "designed to
support English" because they provide all ASCII characters, the pound
currency symbol, and the Euro currency symbol).  OTOH language has a
habit of slopping over the edge of fonts' repertoires, so it's hard to
design an API for fonts that "just works".

On the other hand, language as a category *does* fit into the idea of
giving priority to some fonts over others.  Which is what fontconfig
does.  If you have (as Ubuntu apparently does) standard definitions
that give priority to fonts designed to support Japanese scripts, as
well as Chinese, it is reasonably easy to use those in a program:

    /* default_cfg not checked, but if this fails, we're doomed anyway */
    FcConfig default_cfg = FcInitAndLoadConfig ();
    FcConfig ja_cfg = FcCreateConfig ();
    FcConfig zh_cfg = FcCreateConfig ();

    typedef enum { japanese, chinese, dontknow } language;

    language lang = dontknow;

    /* Depending on how the system presents the language-specific
       configuration information, there are alternative ways of doing
       this, but this will do for our purposes. */
    if (! FcConfigParseAndLoad (ja_cfg, "JapaneseFontConfig", 0)) {
        bitch_loudly ("Japanese config less useful than Japanese Diet!");
        ja_cfg = default_cfg;
    }
    if (! FcConfigParseAndLoad (zh_cfg, "ChineseFontConfig", 0))
        bitch_loudly ("Chinese config as obstructive as Chinese government!");
        zh_cfg = default_cfg;
    }

    lang = get_language_of_text_to_display ();
    if (lang == japanese)
        if (! FcConfigSetCurrent (ja_cfg)) {
            bitch_loudly ("Could not build Japanese font set!");
            FcConfigSetCurrent (default_cfg);
        }
    else if (lang == chinese)
        if (! FcConfigSetCurrent (zh_cfg)) {
            bitch_loudly ("Could not build Chinese font set!");
            FcConfigSetCurrent (default_cfg);
        }
    else
        FcConfigSetCurrent (default_cfg);

    /* Make your usual calls to fontconfig and Xft functions to
       configure specific faces and draw text, without need to
       reference language unless you really want to. */

Agreed, that's tedious.  In a real system, the code above should be
encapsulated in a module providing better abstractions and user
configuration, but it would be a pretty thin layer.  There's nothing
at all interesting about that program, it's a mere script.

 > POSIX locale is designed to take care of the common case, and this
 > happens to be at the expense of the special case.

Well, yes, but there's nobody with a good word to say for POSIX
locales.  They just don't win on any grounds, except that they're
universally available on *nix systems.  (OTOH, I was privileged to
read the CDIS version of ISO 10646 a few days ago.  It used to be a
reasonable standalone standard, not as detailed as Unicode but good
enough for the purpose of providing a registry for the universal
character set's repertoire.  Now they've turned it into a partial copy
of the Unicode standard written in really bad English with an emoticon
block (character sources: NTT Docomo, Softbank, and KDDI/Au -- how
friggin' embarrassing!) *sigh*  When will they ever learn?  POSIX is
at least better than that.)

 > I do not know of any applications that change locale settings like
 > this.

I do.  Any application that wants to use XIM in a multilingual fashion
needs to reset locale every time it sets a new language.  There's a
reason why XIM (a) was primarily used for localization rather than
multilingual apps and (b) today is best known as a colleague of the
dodo bird.

 > Applications that make use of multiple languages tend to
 > control the fonts themselves.

Unlike conforming to the XIM protocol, changing fonts is easy to do
any way you like, and fontconfig even makes it reasonably easy to make
language-specific configurations for abstract fonts (like "serif").



Home | Main Index | Thread Index

Home Page Mailing List Linux and Japan TLUG Members Links