diff options
author | Johannes Hofmann <Johannes.Hofmann@gmx.de> | 2009-01-26 21:09:52 +0100 |
---|---|---|
committer | Johannes Hofmann <Johannes.Hofmann@gmx.de> | 2009-01-26 21:09:52 +0100 |
commit | 307159fdc7edda9d12a174ebc7d3e0e5480aed4f (patch) | |
tree | 3d58b34d86c042ec916e4bc75d3689387d9b814b | |
parent | 954f1b5dea7b6dbdf8208b0ce6576228d121656c (diff) |
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.
-rw-r--r-- | dillorc | 20 | ||||
-rw-r--r-- | src/css.cc | 2 | ||||
-rw-r--r-- | src/dialog.cc | 2 | ||||
-rw-r--r-- | src/dillo.cc | 2 | ||||
-rw-r--r-- | src/plain.cc | 2 | ||||
-rw-r--r-- | src/prefs.c | 57 | ||||
-rw-r--r-- | src/prefs.h | 7 | ||||
-rw-r--r-- | src/styleengine.cc | 15 | ||||
-rw-r--r-- | src/web.cc | 2 |
9 files changed, 70 insertions, 39 deletions
@@ -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 @@ -356,7 +356,7 @@ void CssContext::addRule (CssRule *rule, CssPrimaryOrder order) { 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}" diff --git a/src/dialog.cc b/src/dialog.cc index e19eede0..38854fb3 100644 --- a/src/dialog.cc +++ b/src/dialog.cc @@ -128,7 +128,7 @@ void *a_Dialog_make_text_window(const char *txt, const char *title) //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); diff --git a/src/dillo.cc b/src/dillo.cc index 86b1ffa1..31eeed99 100644 --- a/src/dillo.cc +++ b/src/dillo.cc @@ -287,7 +287,7 @@ int main(int argc, char **argv) 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); diff --git a/src/plain.cc b/src/plain.cc index 8826dafe..1295f99f 100644 --- a/src/plain.cc +++ b/src/plain.cc @@ -99,7 +99,7 @@ DilloPlain::DilloPlain(BrowserWindow *p_bw, const DilloUrl *p_url) 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; diff --git a/src/prefs.c b/src/prefs.c index f7c286f8..8980d838 100644 --- a/src/prefs.c +++ b/src/prefs.c @@ -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 @@ typedef enum { 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 @@ static const SymNode_t symbols[] = { { "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 @@ static const SymNode_t symbols[] = { { "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 @@ static int Prefs_parse_pair(char *name, char *value) 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 @@ void a_Prefs_init(void) 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 @@ void a_Prefs_freeall(void) 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); diff --git a/src/prefs.h b/src/prefs.h index 767530d2..90bcc0f3 100644 --- a/src/prefs.h +++ b/src/prefs.h @@ -61,8 +61,11 @@ struct _DilloPrefs { 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; diff --git a/src/styleengine.cc b/src/styleengine.cc index d5089d71..015f75be 100644 --- a/src/styleengine.cc +++ b/src/styleengine.cc @@ -30,7 +30,7 @@ StyleEngine::StyleEngine (dw::core::Layout *layout) { 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 @@ void StyleEngine::apply (StyleAttrs *attrs, CssPropertyList *props) { 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; @@ -72,7 +72,7 @@ int a_Web_dispatch_by_type (const char *Type, DilloWeb *Web, 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; |