From a28b0fbe07ccdfc691b7aeaa127425a2ab4a5eb2 Mon Sep 17 00:00:00 2001 From: John Mark Bell Date: Mon, 2 Jan 2006 21:24:43 +0000 Subject: [project @ 2006-01-02 21:24:42 by jmb] Finish font configuration. svn path=/import/netsurf/; revision=1953 --- !NetSurf/Resources/de/Messages | 1 + !NetSurf/Resources/de/Templates,fec | Bin 10951 -> 10951 bytes !NetSurf/Resources/en/Messages | 1 + !NetSurf/Resources/en/Templates,fec | Bin 10894 -> 10894 bytes !NetSurf/Resources/fr/Messages | 1 + !NetSurf/Resources/fr/Templates,fec | Bin 11078 -> 11078 bytes !NetSurf/Resources/nl/Messages | 1 + !NetSurf/Resources/nl/Templates,fec | Bin 10980 -> 10980 bytes riscos/configure/con_fonts.c | 110 ++++++++++++++++++++++++++++++++---- riscos/font.c | 16 +++++- riscos/gui.h | 2 + 11 files changed, 119 insertions(+), 13 deletions(-) diff --git a/!NetSurf/Resources/de/Messages b/!NetSurf/Resources/de/Messages index f5829941f..f2dd0607b 100644 --- a/!NetSurf/Resources/de/Messages +++ b/!NetSurf/Resources/de/Messages @@ -199,6 +199,7 @@ ProxyNTLM:NTLM # # Fonts pane Fonts:Schriften +DefaultFonts:Font Families # # Images pane Display:Ausgabe diff --git a/!NetSurf/Resources/de/Templates,fec b/!NetSurf/Resources/de/Templates,fec index 7631a9380..0db119de9 100755 Binary files a/!NetSurf/Resources/de/Templates,fec and b/!NetSurf/Resources/de/Templates,fec differ diff --git a/!NetSurf/Resources/en/Messages b/!NetSurf/Resources/en/Messages index 20f208930..e8cb21377 100644 --- a/!NetSurf/Resources/en/Messages +++ b/!NetSurf/Resources/en/Messages @@ -199,6 +199,7 @@ ProxyNTLM:NTLM # # Fonts pane Fonts:Fonts +DefaultFonts:Font Families # # Images pane Display:Display diff --git a/!NetSurf/Resources/en/Templates,fec b/!NetSurf/Resources/en/Templates,fec index 09775d94e..56858968d 100644 Binary files a/!NetSurf/Resources/en/Templates,fec and b/!NetSurf/Resources/en/Templates,fec differ diff --git a/!NetSurf/Resources/fr/Messages b/!NetSurf/Resources/fr/Messages index 5a4adf87e..2b3273ffd 100644 --- a/!NetSurf/Resources/fr/Messages +++ b/!NetSurf/Resources/fr/Messages @@ -199,6 +199,7 @@ ProxyNTLM:NTLM # # Fonts pane Fonts:Fontes +DefaultFonts:Font Families # # Images pane Display:Affichage diff --git a/!NetSurf/Resources/fr/Templates,fec b/!NetSurf/Resources/fr/Templates,fec index bb23d5256..cf759e280 100644 Binary files a/!NetSurf/Resources/fr/Templates,fec and b/!NetSurf/Resources/fr/Templates,fec differ diff --git a/!NetSurf/Resources/nl/Messages b/!NetSurf/Resources/nl/Messages index f86541ecd..af82472ac 100644 --- a/!NetSurf/Resources/nl/Messages +++ b/!NetSurf/Resources/nl/Messages @@ -200,6 +200,7 @@ ProxyNTLM:NTLM # # Fonts pane Fonts:Lettertypen +DefaultFonts:Font Families # # Images pane Display:Weergave diff --git a/!NetSurf/Resources/nl/Templates,fec b/!NetSurf/Resources/nl/Templates,fec index e3a1a49fb..cae89caf1 100644 Binary files a/!NetSurf/Resources/nl/Templates,fec and b/!NetSurf/Resources/nl/Templates,fec differ diff --git a/riscos/configure/con_fonts.c b/riscos/configure/con_fonts.c index 410d7db89..b9bbdc64e 100644 --- a/riscos/configure/con_fonts.c +++ b/riscos/configure/con_fonts.c @@ -7,12 +7,15 @@ #include "netsurf/desktop/options.h" #include "netsurf/riscos/dialog.h" +#include "netsurf/riscos/gui.h" #include "netsurf/riscos/menus.h" #include "netsurf/riscos/options.h" #include "netsurf/riscos/wimp.h" #include "netsurf/riscos/wimp_event.h" #include "netsurf/riscos/configure.h" #include "netsurf/riscos/configure/configure.h" +#include "netsurf/utils/messages.h" +#include "netsurf/utils/utils.h" #define FONT_SANS_FIELD 3 @@ -37,10 +40,17 @@ #define FONT_CANCEL_BUTTON 33 #define FONT_OK_BUTTON 34 +/* This menu only ever gets created once */ +/** \todo The memory claimed for this menu should + * probably be released at some point */ +static wimp_menu *default_menu; + static void ro_gui_options_fonts_default(wimp_pointer *pointer); static bool ro_gui_options_fonts_ok(wimp_w w); +static bool ro_gui_options_fonts_init_menu(void); -bool ro_gui_options_fonts_initialise(wimp_w w) { +bool ro_gui_options_fonts_initialise(wimp_w w) +{ /* set the current values */ ro_gui_set_icon_decimal(w, FONT_DEFAULT_SIZE, option_font_size, 1); ro_gui_set_icon_decimal(w, FONT_MINIMUM_SIZE, option_font_min_size, 1); @@ -52,7 +62,10 @@ bool ro_gui_options_fonts_initialise(wimp_w w) { ro_gui_set_icon_string(w, FONT_DEFAULT_FIELD, css_font_family_name[option_font_default]); - /* initialise all functions for a newly created window */ + if (!ro_gui_options_fonts_init_menu()) + return false; + + /* initialise all functions for a newly created window */ ro_gui_wimp_event_register_menu_gright(w, FONT_SANS_FIELD, FONT_SANS_MENU, font_menu); ro_gui_wimp_event_register_menu_gright(w, FONT_SERIF_FIELD, @@ -63,7 +76,8 @@ bool ro_gui_options_fonts_initialise(wimp_w w) { FONT_CURSIVE_MENU, font_menu); ro_gui_wimp_event_register_menu_gright(w, FONT_FANTASY_FIELD, FONT_FANTASY_MENU, font_menu); - /* todo: default family menu */ + ro_gui_wimp_event_register_menu_gright(w, FONT_DEFAULT_FIELD, + FONT_DEFAULT_MENU, default_menu); ro_gui_wimp_event_register_numeric_field(w, FONT_DEFAULT_SIZE, FONT_DEFAULT_INC, FONT_DEFAULT_DEC, 50, 1000, 1, 1); ro_gui_wimp_event_register_numeric_field(w, FONT_MINIMUM_SIZE, @@ -79,20 +93,37 @@ bool ro_gui_options_fonts_initialise(wimp_w w) { } -void ro_gui_options_fonts_default(wimp_pointer *pointer) { +void ro_gui_options_fonts_default(wimp_pointer *pointer) +{ + const char *fallback = nsfont_fallback_font(); + /* set the default values */ ro_gui_set_icon_decimal(pointer->w, FONT_DEFAULT_SIZE, 100, 1); ro_gui_set_icon_decimal(pointer->w, FONT_MINIMUM_SIZE, 70, 1); - /* todo: default font families */ + ro_gui_set_icon_string(pointer->w, FONT_SANS_FIELD, + nsfont_exists("Homerton") ? "Homerton" : fallback); + ro_gui_set_icon_string(pointer->w, FONT_SERIF_FIELD, + nsfont_exists("Trinity") ? "Trinity" : fallback); + ro_gui_set_icon_string(pointer->w, FONT_MONOSPACE_FIELD, + nsfont_exists("Corpus") ? "Corpus" : fallback); + ro_gui_set_icon_string(pointer->w, FONT_CURSIVE_FIELD, + nsfont_exists("Churchill") ? "Churchill" : fallback); + ro_gui_set_icon_string(pointer->w, FONT_FANTASY_FIELD, + nsfont_exists("Sassoon") ? "Sassoon" : fallback); + ro_gui_set_icon_string(pointer->w, FONT_DEFAULT_FIELD, + css_font_family_name[1]); } -bool ro_gui_options_fonts_ok(wimp_w w) { - option_font_size = ro_gui_get_icon_decimal(w, FONT_DEFAULT_SIZE, 1); - option_font_min_size = ro_gui_get_icon_decimal(w, FONT_MINIMUM_SIZE, 1); - if (option_font_size < option_font_min_size) { - option_font_size = option_font_min_size; +bool ro_gui_options_fonts_ok(wimp_w w) +{ + unsigned int i; + + option_font_size = ro_gui_get_icon_decimal(w, FONT_DEFAULT_SIZE, 1); + option_font_min_size = ro_gui_get_icon_decimal(w, FONT_MINIMUM_SIZE, 1); + if (option_font_size < option_font_min_size) { + option_font_size = option_font_min_size; ro_gui_set_icon_decimal(w, FONT_DEFAULT_SIZE, option_font_size, 1); - } + } free(option_font_sans); option_font_sans = strdup(ro_gui_get_icon_string(w, FONT_SANS_FIELD)); free(option_font_serif); @@ -103,7 +134,62 @@ bool ro_gui_options_fonts_ok(wimp_w w) { option_font_cursive = strdup(ro_gui_get_icon_string(w, FONT_CURSIVE_FIELD)); free(option_font_fantasy); option_font_fantasy = strdup(ro_gui_get_icon_string(w, FONT_FANTASY_FIELD)); - /* todo: default family */ + + for (i = 0; i != 5; i++) { + if (!strcmp(css_font_family_name[i+1], + ro_gui_get_icon_string(w, + FONT_DEFAULT_FIELD))) + break; + } + if (i == 5) + /* this should never happen, but still */ + i = 0; + + option_font_default = i + 1; + ro_gui_save_options(); return true; } + +bool ro_gui_options_fonts_init_menu(void) +{ + unsigned int i; + + if (default_menu) + /* Already exists */ + return true; + + default_menu = malloc(wimp_SIZEOF_MENU(5)); + if (!default_menu) { + warn_user("NoMemory", 0); + return false; + } + default_menu->title_data.indirected_text.text = + messages_get("DefaultFonts"); + default_menu->title_fg = wimp_COLOUR_BLACK; + default_menu->title_bg = wimp_COLOUR_LIGHT_GREY; + default_menu->work_fg = wimp_COLOUR_BLACK; + default_menu->work_bg = wimp_COLOUR_WHITE; + default_menu->width = 200; + default_menu->height = wimp_MENU_ITEM_HEIGHT; + default_menu->gap = wimp_MENU_ITEM_GAP; + + for (i = 0; i != 5; i++) { + default_menu->entries[i].menu_flags = 0; + default_menu->entries[i].sub_menu = wimp_NO_SUB_MENU; + default_menu->entries[i].icon_flags = wimp_ICON_TEXT | + wimp_ICON_INDIRECTED | + (wimp_COLOUR_BLACK << wimp_ICON_FG_COLOUR_SHIFT) | + (wimp_COLOUR_WHITE << wimp_ICON_BG_COLOUR_SHIFT); + default_menu->entries[i].data.indirected_text.text = + css_font_family_name[i+1]; + default_menu->entries[i].data.indirected_text.validation = + (char *)-1; + default_menu->entries[i].data.indirected_text.size = + strlen(css_font_family_name[i+1]); + } + default_menu->entries[0].menu_flags = wimp_MENU_TITLE_INDIRECTED; + default_menu->entries[i-1].menu_flags |= wimp_MENU_LAST; + + return true; +} diff --git a/riscos/font.c b/riscos/font.c index e0f8b03e6..4bbfcc8b0 100644 --- a/riscos/font.c +++ b/riscos/font.c @@ -29,7 +29,6 @@ wimp_menu *font_menu; static void nsfont_check_option(char **option, const char *family, const char *fallback); -static bool nsfont_exists(const char *font_family); static int nsfont_list_cmp(const void *keyval, const void *datum); static void nsfont_check_fonts(void); static void nsfont_init_menu(void); @@ -84,6 +83,21 @@ void nsfont_init(void) } +/** + * Retrieve the fallback font name + * + * \return Fallback font name + */ +const char *nsfont_fallback_font(void) +{ + const char *fallback = "Homerton"; + + if (!nsfont_exists(fallback)) + fallback = rufl_family_list[0]; + + return fallback; +} + /** * Check that a font option is valid, and fix it if not. * diff --git a/riscos/gui.h b/riscos/gui.h index 0c566a700..e8adbb565 100644 --- a/riscos/gui.h +++ b/riscos/gui.h @@ -216,6 +216,8 @@ void ro_gui_print_prepare(struct gui_window *g); /* in font.c */ void nsfont_init(void); +bool nsfont_exists(const char *font_family); +const char *nsfont_fallback_font(void); bool nsfont_paint(struct css_style *style, const char *string, size_t length, int x, int y, float scale); void nsfont_read_style(const struct css_style *style, -- cgit v1.2.3