Comment 6 for bug 826441

Revision history for this message
gue5t gue5t (gue5t) wrote :

If we want to have a GUI setting for forcing the font, I'm not against using the user-stylesheet-uri to do so, as it would definitely be the most effective solution here--no flashing, no extensions, and no javascript required. That said, I do think that user-stylesheet-uri should not be used directly, exactly because it's the most effective way to set global styles, and multiple components (including the end user) may want access to that ability. A midori component which multiplexed the property by keeping track of registered portions of the property and summed them into an actual value to use seems like it would work to make user-stylesheet-uri a reusable method of setting global style properties.

API could look something like

guint midori_settings_add_style_rule(MidoriWebSettings *settings, gchar *rule); //returns rule id, which is used to remove the rule later
midori_settings_remove_style_rule(MidoriWebSettings *settings, guint id); //removes the rule set with the given id

each of which would update the set of style rules and recalculate a resultant value for user-stylesheet-uri.

_midori_browser_forced_font could then be implemented as follows:

static void
_midori_browser_forced_font (MidoriBrowser* browser, const gchar* family, gint size, gboolean enabled)
{
    MidoriWebSettings* midori_settings = browser->settings;
    static guint rule_id = 0;

    if (enabled)
    {
        GString* css_str = g_string_new ("* { font: ");
        g_string_append_printf (css_str, "%dpt ", size);
        g_string_append_printf (css_str, "%s !important; }", family);

        rule_id = midori_settings_add_style_rule (css_str->str);

        g_string_free (css_str, TRUE);
    }
    else if (rule_id)
    {
     midori_settings_remove_style_rule (settings, rule_id);
    }
}