Mercurial > dillo_port1.3
changeset 824:556b5972dd18
adapt font-family preferences to match CSS
CSS 2.1 uses the following predefined font names:
'serif', 'sans-serif', 'cursive', 'fantasy', 'monospace'.
Add preferences so that the user can set real font names for these.
Basically the new "font_sans_serif" option is what "vw_fontame"
used to be and "font_monospace" is equivalent to "fw_fontname".
The other two options are new.
author | Johannes Hofmann <Johannes.Hofmann@gmx.de> |
---|---|
date | Mon, 26 Jan 2009 21:09:52 +0100 |
parents | 8fbeea67aa2b |
children | b04673615946 |
files | dillorc src/css.cc src/dialog.cc src/dillo.cc src/plain.cc src/prefs.c src/prefs.h src/styleengine.cc src/web.cc |
diffstat | 9 files changed, 70 insertions(+), 39 deletions(-) [+] |
line wrap: on
line diff
--- a/dillorc Mon Jan 26 21:01:21 2009 +0100 +++ b/dillorc Mon Jan 26 21:09:52 2009 +0100 @@ -37,22 +37,16 @@ # RENDERING SECTION #------------------------------------------------------------------------- -# Fontname for variable width rendering (most of the text). +# Fontnames: # - some fonts may slow down rendering. # - try to tune a fontname/font_factor combination. # Ex. {helvetica, lucida, times, "new century schoolbook", utopia, ...} -# vw_fontname="new century schoolbook" -# vw_fontname="helvetica" -# vw_fontname="times" -# vw_fontname="Bitstream vera Serif" -# vw_fontname="arial" -#vw_fontname="DejaVu Sans" - -# Fontname for fixed width rendering (mainly text quoted with <pre>) -# fw_fontname=courier -# fw_fontname="Bitstream Vera Sans Mono" -# fw_fontname="Andale Mono" -#fw_fontname="DejaVu Sans Mono" +# +# font_serif="DejaVu Serif" +# font_sans_serif="DejaVu Sans" +# font_cursive="DejaVu Sans" +# font_fantasy="DejaVu Sans" +# font_monospace="DejaVu Sans Mono" # All fontsizes are scaled by this value # font_factor=1.5
--- a/src/css.cc Mon Jan 26 21:01:21 2009 +0100 +++ b/src/css.cc Mon Jan 26 21:09:52 2009 +0100 @@ -356,7 +356,7 @@ void CssContext::buildUserAgentStyle () { const char *cssBuf = - "body {background-color: #dcd1ba; font-family: sans; color: black;" + "body {background-color: #dcd1ba; font-family: sans-serif; color: black;" " margin: 5px}" "big {font-size: 1.17em}" "blockquote, dd {margin-left: 40px; margin-right: 40px}"
--- a/src/dialog.cc Mon Jan 26 21:01:21 2009 +0100 +++ b/src/dialog.cc Mon Jan 26 21:09:52 2009 +0100 @@ -128,7 +128,7 @@ //int wh = 600, ww = 650, bh = 30; int wh = prefs.height, ww = prefs.width, bh = 30; int lines, line_num_width; - Font *textfont = font(prefs.fw_fontname, 0); + Font *textfont = font(prefs.font_monospace, 0); Window *window = new Window(ww, wh, title ? title : "Untitled"); window->callback(window_close_cb, window);
--- a/src/dillo.cc Mon Jan 26 21:01:21 2009 +0100 +++ b/src/dillo.cc Mon Jan 26 21:09:52 2009 +0100 @@ -287,7 +287,7 @@ fltk::TabGroup::default_pager(fltk::PAGER_SHRINK); /* use preferred font for UI */ - fltk::Font *dfont = fltk::font(prefs.vw_fontname, 0); + fltk::Font *dfont = fltk::font(prefs.font_sans_serif, 0); if (dfont) { fltk::Widget::default_style->textfont(dfont); fltk::Widget::default_style->labelfont(dfont);
--- a/src/plain.cc Mon Jan 26 21:01:21 2009 +0100 +++ b/src/plain.cc Mon Jan 26 21:09:52 2009 +0100 @@ -99,7 +99,7 @@ state = ST_SeekingEol; /* Create the font and attribute for the page. */ - fontAttrs.name = prefs.fw_fontname; + fontAttrs.name = prefs.font_monospace; fontAttrs.size = (int) rint(14.0 * prefs.font_factor); fontAttrs.weight = 400; fontAttrs.style = style::FONT_STYLE_NORMAL;
--- a/src/prefs.c Mon Jan 26 21:01:21 2009 +0100 +++ b/src/prefs.c Mon Jan 26 21:09:52 2009 +0100 @@ -36,8 +36,11 @@ #define DILLO_START_PAGE "about:splash" #define DILLO_HOME "http://www.dillo.org/" -#define D_VW_FONTNAME "DejaVu Sans" -#define D_FW_FONTNAME "DejaVu Sans Mono" +#define D_FONT_SERIF "DejaVu Serif" +#define D_FONT_SANS_SERIF "DejaVu Sans" +#define D_FONT_CURSIVE "DejaVu Sans" /* \todo find good default */ +#define D_FONT_FANTASY "DejaVu Sans" /* \todo find good default */ +#define D_FONT_MONOSPACE "DejaVu Sans Mono" #define D_SEARCH_URL "http://www.google.com/search?ie=UTF-8&oe=UTF-8&q=%s" #define D_SAVE_DIR "/tmp/" @@ -64,6 +67,11 @@ DRC_TOKEN_ENTERPRESS_FORCES_SUBMIT, DRC_TOKEN_FOCUS_NEW_TAB, DRC_TOKEN_FONT_FACTOR, + DRC_TOKEN_FONT_SERIF, + DRC_TOKEN_FONT_SANS_SERIF, + DRC_TOKEN_FONT_CURSIVE, + DRC_TOKEN_FONT_FANTASY, + DRC_TOKEN_FONT_MONOSPACE, DRC_TOKEN_FORCE_MY_COLORS, DRC_TOKEN_FULLWINDOW_START, DRC_TOKEN_FW_FONT, @@ -128,10 +136,14 @@ { "contrast_visited_color", DRC_TOKEN_CONTRAST_VISITED_COLOR }, { "enterpress_forces_submit", DRC_TOKEN_ENTERPRESS_FORCES_SUBMIT }, { "focus_new_tab", DRC_TOKEN_FOCUS_NEW_TAB }, + { "font_cursive", DRC_TOKEN_FONT_CURSIVE }, { "font_factor", DRC_TOKEN_FONT_FACTOR }, + { "font_fantasy", DRC_TOKEN_FONT_FANTASY }, + { "font_monospace", DRC_TOKEN_FONT_MONOSPACE }, + { "font_sans_serif", DRC_TOKEN_FONT_SANS_SERIF }, + { "font_serif", DRC_TOKEN_FONT_SERIF }, { "force_my_colors", DRC_TOKEN_FORCE_MY_COLORS }, { "fullwindow_start", DRC_TOKEN_FULLWINDOW_START }, - { "fw_fontname", DRC_TOKEN_FW_FONT }, { "generate_submit", DRC_TOKEN_GENERATE_SUBMIT }, { "geometry", DRC_TOKEN_GEOMETRY }, { "home", DRC_TOKEN_HOME }, @@ -170,7 +182,6 @@ { "start_page", DRC_TOKEN_START_PAGE }, { "text_color", DRC_TOKEN_TEXT_COLOR }, { "visited_color", DRC_TOKEN_VISITED_COLOR, }, - { "vw_fontname", DRC_TOKEN_VW_FONT }, { "w3c_plus_heuristics", DRC_TOKEN_W3C_PLUS_HEURISTICS } }; @@ -343,13 +354,25 @@ case DRC_TOKEN_BUFFERED_DRAWING: prefs.buffered_drawing = atoi(value); break; - case DRC_TOKEN_FW_FONT: - dFree(prefs.fw_fontname); - prefs.fw_fontname = dStrdup(value); + case DRC_TOKEN_FONT_SERIF: + dFree(prefs.font_serif); + prefs.font_serif = dStrdup(value); break; - case DRC_TOKEN_VW_FONT: - dFree(prefs.vw_fontname); - prefs.vw_fontname = dStrdup(value); + case DRC_TOKEN_FONT_SANS_SERIF: + dFree(prefs.font_sans_serif); + prefs.font_sans_serif = dStrdup(value); + break; + case DRC_TOKEN_FONT_CURSIVE: + dFree(prefs.font_cursive); + prefs.font_cursive = dStrdup(value); + break; + case DRC_TOKEN_FONT_FANTASY: + dFree(prefs.font_fantasy); + prefs.font_fantasy = dStrdup(value); + break; + case DRC_TOKEN_FONT_MONOSPACE: + dFree(prefs.font_monospace); + prefs.font_monospace = dStrdup(value); break; case DRC_TOKEN_GENERATE_SUBMIT: prefs.generate_submit = (strcmp(value, "YES") == 0); @@ -470,8 +493,11 @@ prefs.load_stylesheets=TRUE; prefs.parse_embedded_css=TRUE; prefs.buffered_drawing=1; - prefs.vw_fontname = dStrdup(D_VW_FONTNAME); - prefs.fw_fontname = dStrdup(D_FW_FONTNAME); + prefs.font_serif = dStrdup(D_FONT_SERIF); + prefs.font_sans_serif = dStrdup(D_FONT_SANS_SERIF); + prefs.font_cursive = dStrdup(D_FONT_CURSIVE); + prefs.font_fantasy = dStrdup(D_FONT_FANTASY); + prefs.font_monospace = dStrdup(D_FONT_MONOSPACE); prefs.generate_submit = FALSE; prefs.enterpress_forces_submit = FALSE; prefs.middle_click_opens_new_tab = TRUE; @@ -503,8 +529,11 @@ dFree(prefs.http_referer); dFree(prefs.no_proxy); a_Url_free(prefs.http_proxy); - dFree(prefs.fw_fontname); - dFree(prefs.vw_fontname); + dFree(prefs.font_serif); + dFree(prefs.font_sans_serif); + dFree(prefs.font_cursive); + dFree(prefs.font_fantasy); + dFree(prefs.font_monospace); a_Url_free(prefs.start_page); a_Url_free(prefs.home); dFree(prefs.search_url);
--- a/src/prefs.h Mon Jan 26 21:01:21 2009 +0100 +++ b/src/prefs.h Mon Jan 26 21:09:52 2009 +0100 @@ -61,8 +61,11 @@ bool_t load_stylesheets; bool_t parse_embedded_css; int32_t buffered_drawing; - char *vw_fontname; - char *fw_fontname; + char *font_serif; + char *font_sans_serif; + char *font_cursive; + char *font_fantasy; + char *font_monospace; bool_t generate_submit; bool_t enterpress_forces_submit; bool_t middle_click_opens_new_tab;
--- a/src/styleengine.cc Mon Jan 26 21:01:21 2009 +0100 +++ b/src/styleengine.cc Mon Jan 26 21:09:52 2009 +0100 @@ -30,7 +30,7 @@ Node *n = stack->getRef (stack->size () - 1); /* Create a dummy font, attribute, and tag for the bottom of the stack. */ - font_attrs.name = prefs.vw_fontname; + font_attrs.name = prefs.font_sans_serif; font_attrs.size = (int) (14 * prefs.font_factor + 0.5); font_attrs.weight = CssProperty::CSS_FONT_WEIGHT_NORMAL; font_attrs.style = FONT_STYLE_NORMAL; @@ -172,11 +172,16 @@ case CssProperty::CSS_PROPERTY_FONT_FAMILY: // \todo memory management of font name strings // \todo handle comma separated lists of font names - // \todo handle sans-serif, cursive, fantasy - if (strcmp (p->value.strVal, "sans") == 0) - fontAttrs.name = prefs.vw_fontname; + if (strcmp (p->value.strVal, "serif") == 0) + fontAttrs.name = prefs.font_serif; + else if (strcmp (p->value.strVal, "sans-serif") == 0) + fontAttrs.name = prefs.font_sans_serif; + else if (strcmp (p->value.strVal, "cursive") == 0) + fontAttrs.name = prefs.font_cursive; + else if (strcmp (p->value.strVal, "fantasy") == 0) + fontAttrs.name = prefs.font_fantasy; else if (strcmp (p->value.strVal, "monospace") == 0) - fontAttrs.name = prefs.fw_fontname; + fontAttrs.name = prefs.font_monospace; else fontAttrs.name = p->value.strVal; break;
--- a/src/web.cc Mon Jan 26 21:01:21 2009 +0100 +++ b/src/web.cc Mon Jan 26 21:09:52 2009 +0100 @@ -72,7 +72,7 @@ return -1; /* Set a style for the widget */ - fontAttrs.name = prefs.vw_fontname; + fontAttrs.name = prefs.font_sans_serif; fontAttrs.size = (int) rint(14.0 * prefs.font_factor); fontAttrs.weight = 400; fontAttrs.style = style::FONT_STYLE_NORMAL;