Back to index

lightning-sunbird  0.9+nobinonly
Classes | Defines | Typedefs | Functions
mozilla-decoder.h File Reference
#include <pango/pangofc-decoder.h>
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  _MozillaDecoder
struct  _MozillaDecoderClass

Defines

#define MOZILLA_TYPE_DECODER   (mozilla_decoder_get_type())
#define MOZILLA_DECODER(object)   (G_TYPE_CHECK_INSTANCE_CAST ((object), MOZILLA_TYPE_DECODER, MozillaDecoder))
#define MOZILLA_IS_DECODER(object)   (G_TYPE_CHECK_INSTANCE_TYPE ((object), MOZILLA_TYPE_DECODER))
#define MOZILLA_DECODER_CLASS(klass)   (G_TYPE_CHECK_CLASS_CAST ((klass), MOZILLA_TYPE_DECODER, MozillaDecoderClass))
#define MOZILLA_IS_DECODER_CLASS(klass)   (G_TYPE_CHECK_CLASS_TYPE ((klass), MOZILLA_TYPE_DECODER))
#define MOZILLA_DECODER_GET_CLASS(obj)   (G_TYPE_INSTANCE_GET_CLASS ((obj), MOZILLA_TYPE_DECODER, MozillaDecoderClass))

Typedefs

typedef struct _MozillaDecoder
typedef struct _MozillaDecoderClass

Functions

GType mozilla_decoder_get_type (void)
int mozilla_decoders_init (void)
 mozilla_decoders_init:

Class Documentation

struct _MozillaDecoder

Definition at line 57 of file mozilla-decoder.h.

Class Members
PangoFcDecoder parent_instance
struct _MozillaDecoderClass

Definition at line 62 of file mozilla-decoder.h.

Class Members
PangoFcDecoderClass parent_class

Define Documentation

#define MOZILLA_DECODER (   object)    (G_TYPE_CHECK_INSTANCE_CAST ((object), MOZILLA_TYPE_DECODER, MozillaDecoder))

Definition at line 47 of file mozilla-decoder.h.

#define MOZILLA_DECODER_CLASS (   klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), MOZILLA_TYPE_DECODER, MozillaDecoderClass))

Definition at line 53 of file mozilla-decoder.h.

#define MOZILLA_DECODER_GET_CLASS (   obj)    (G_TYPE_INSTANCE_GET_CLASS ((obj), MOZILLA_TYPE_DECODER, MozillaDecoderClass))

Definition at line 55 of file mozilla-decoder.h.

#define MOZILLA_IS_DECODER (   object)    (G_TYPE_CHECK_INSTANCE_TYPE ((object), MOZILLA_TYPE_DECODER))

Definition at line 48 of file mozilla-decoder.h.

#define MOZILLA_IS_DECODER_CLASS (   klass)    (G_TYPE_CHECK_CLASS_TYPE ((klass), MOZILLA_TYPE_DECODER))

Definition at line 54 of file mozilla-decoder.h.

Definition at line 46 of file mozilla-decoder.h.


Typedef Documentation

typedef struct _MozillaDecoder

Definition at line 50 of file mozilla-decoder.h.

typedef struct _MozillaDecoderClass

Definition at line 51 of file mozilla-decoder.h.


Function Documentation

mozilla_decoders_init:

mozilla_decoders_init:

This initializes all of the application-specific custom decoders that Mozilla uses. This should only be called once during the lifetime of the application.

Return value: zero on success, not zero on failure.

Definition at line 141 of file mozilla-decoder.cpp.

{
    static PRBool initialized = PR_FALSE;
    if (initialized)
        return 0;

    PangoContext* context = gdk_pango_context_get ();
    PangoFontMap* fontmap = pango_context_get_font_map (context);
    g_object_unref (context);
    
    if (!PANGO_IS_FC_FONT_MAP (fontmap))
        return -1;

    encoder_hash = g_hash_table_new(g_str_hash, g_str_equal);
    cmap_hash = g_hash_table_new(g_str_hash, g_str_equal);
    wide_hash = g_hash_table_new(g_str_hash, g_str_equal);

    PRBool dumb = PR_FALSE;
    nsCOMPtr<nsIPersistentProperties> props;
    nsCOMPtr<nsISimpleEnumerator> encodeEnum;

    NS_LoadPersistentPropertiesFromURISpec(getter_AddRefs(props),
        NS_LITERAL_CSTRING("resource://gre/res/fonts/pangoFontEncoding.properties"));

    if (!props)
        goto loser;

    // Enumerate the properties in this file and figure out all of the
    // fonts for which we have custom encodings.
    props->Enumerate(getter_AddRefs(encodeEnum));
    if (!encodeEnum)
        goto loser;

    while (encodeEnum->HasMoreElements(&dumb), dumb) {
        nsCOMPtr<nsIPropertyElement> prop;
        encodeEnum->GetNext(getter_AddRefs(prop));
        if (!prop)
            goto loser;

        nsCAutoString name;
        prop->GetKey(name);
        nsAutoString value;
        prop->GetValue(value);

        if (!StringBeginsWith(name, NS_LITERAL_CSTRING("encoding."))) {
            printf("string doesn't begin with encoding?\n");
            continue;
        }

        name = Substring(name, 9);

        if (StringEndsWith(name, NS_LITERAL_CSTRING(".ttf"))) {
            name = Substring(name, 0, name.Length() - 4);

            // Strip off a .wide if it's there.
            if (StringEndsWith(value, NS_LITERAL_STRING(".wide"))) {
                g_hash_table_insert(wide_hash, g_strdup(name.get()),
                                    g_strdup("wide"));
                value = Substring(value, 0, name.Length() - 5);
            }

            g_hash_table_insert(encoder_hash,
                                g_strdup(name.get()),
                                g_strdup(NS_ConvertUTF16toUTF8(value).get()));
        }
        else if (StringEndsWith(name, NS_LITERAL_CSTRING(".ftcmap"))) {
            name = Substring(name, 0, name.Length() - 7);
            g_hash_table_insert(cmap_hash,
                                g_strdup(name.get()),
                                g_strdup(NS_ConvertUTF16toUTF8(value).get()));
        }
        else {
            printf("unknown suffix used for mapping\n");
        }
    }

    pango_fc_font_map_add_decoder_find_func(PANGO_FC_FONT_MAP(fontmap),
                                            mozilla_find_decoder,
                                            NULL,
                                            NULL);

    initialized = PR_TRUE;

#ifdef DEBUG_CUSTOM_ENCODER
    printf("*** encoders\n");
    g_hash_table_foreach(encoder_hash, (GHFunc)dump_hash, NULL);

    printf("*** cmaps\n");
    g_hash_table_foreach(cmap_hash, (GHFunc)dump_hash, NULL);
#endif

    return 0;

 loser:
    return -1;
}

Here is the call graph for this function:

Here is the caller graph for this function: