summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--!NetSurf/Resources/CSS,f793
-rw-r--r--Docs/TODO-CSS4
-rw-r--r--Docs/TODO-General3
-rw-r--r--Docs/TODO-HTML4
-rw-r--r--css/css.c7
-rw-r--r--css/css.h11
-rw-r--r--css/ruleset.c49
-rw-r--r--riscos/font.c84
8 files changed, 147 insertions, 18 deletions
diff --git a/!NetSurf/Resources/CSS,f79 b/!NetSurf/Resources/CSS,f79
index 8f9d4d097..590e45067 100644
--- a/!NetSurf/Resources/CSS,f79
+++ b/!NetSurf/Resources/CSS,f79
@@ -71,3 +71,6 @@ font[size="+1"] { font-size: larger; }
td[nowrap], th[nowrap] { white-space: nowrap; }
pre { white-space: pre; }
+
+cite, dfn, code, samp,
+kbd, var, abbr, acronym { font-family: monospace; text-align: center; }
diff --git a/Docs/TODO-CSS b/Docs/TODO-CSS
index 65b276b7e..285764c1d 100644
--- a/Docs/TODO-CSS
+++ b/Docs/TODO-CSS
@@ -1,4 +1,4 @@
-$Id: TODO-CSS,v 1.4 2003/10/17 23:47:13 jmb Exp $
+$Id: TODO-CSS,v 1.5 2004/01/28 21:48:10 jmb Exp $
TODO-CSS file for NetSurf.
@@ -38,7 +38,7 @@ See TODO-HTML for HTML related TODOs.
- empty-cells
+ float
= font (style, weight, size, line-spacing)
-- font-family
+= font-family
+ font-size
- font-size-adjust
- font-stretch
diff --git a/Docs/TODO-General b/Docs/TODO-General
index 702ba6b9e..ed9397681 100644
--- a/Docs/TODO-General
+++ b/Docs/TODO-General
@@ -1,4 +1,4 @@
-$Id: TODO-General,v 1.5 2003/07/30 13:06:22 jmb Exp $
+$Id: TODO-General,v 1.6 2004/01/28 21:48:10 jmb Exp $
TODO-General for NetSurf.
@@ -11,5 +11,4 @@ Printing
Global Clipboard Support
More Image file formats
JavaScript?
-ANT URL protocol support
#targets in URLS eg: http://www.moo.com/index.html#blah \ No newline at end of file
diff --git a/Docs/TODO-HTML b/Docs/TODO-HTML
index c06e9d9bb..b3b50894c 100644
--- a/Docs/TODO-HTML
+++ b/Docs/TODO-HTML
@@ -1,4 +1,4 @@
-$Id: TODO-HTML,v 1.6 2003/11/02 01:42:54 jmb Exp $
+$Id: TODO-HTML,v 1.7 2004/01/28 21:48:10 jmb Exp $
TODO-HTML file for NetSurf.
@@ -10,8 +10,6 @@ See TODO-CSS for CSS related TODOs.
Text Formatting:
- <CITE>, <DFN>, <CODE>, <SAMP>, <KBD>,
- <VAR>, <ABBR> and <ACRONYM> tags
<Q> tag
Lists:
diff --git a/css/css.c b/css/css.c
index 154a85d6f..97f33934e 100644
--- a/css/css.c
+++ b/css/css.c
@@ -43,6 +43,7 @@ const struct css_style css_base_style = {
CSS_DISPLAY_BLOCK,
CSS_FLOAT_NONE,
{ CSS_FONT_SIZE_LENGTH, { { 10, CSS_UNIT_PT } } },
+ CSS_FONT_FAMILY_SANS_SERIF,
CSS_FONT_WEIGHT_NORMAL,
CSS_FONT_STYLE_NORMAL,
{ CSS_HEIGHT_AUTO, { 1, CSS_UNIT_EM } },
@@ -61,6 +62,7 @@ const struct css_style css_empty_style = {
CSS_DISPLAY_INHERIT,
CSS_FLOAT_INHERIT,
{ CSS_FONT_SIZE_INHERIT, { { 1, CSS_UNIT_EM } } },
+ CSS_FONT_FAMILY_INHERIT,
CSS_FONT_WEIGHT_INHERIT,
CSS_FONT_STYLE_INHERIT,
{ CSS_HEIGHT_INHERIT, { 1, CSS_UNIT_EM } },
@@ -79,6 +81,7 @@ const struct css_style css_blank_style = {
CSS_DISPLAY_INLINE,
CSS_FLOAT_NONE,
{ CSS_FONT_SIZE_INHERIT, { { 1, CSS_UNIT_EM } } },
+ CSS_FONT_FAMILY_INHERIT,
CSS_FONT_WEIGHT_INHERIT,
CSS_FONT_STYLE_INHERIT,
{ CSS_HEIGHT_AUTO, { 1, CSS_UNIT_EM } },
@@ -748,6 +751,8 @@ void css_cascade(struct css_style * const style, const struct css_style * const
style->display = apply->display;
if (apply->float_ != CSS_FLOAT_INHERIT)
style->float_ = apply->float_;
+ if (apply->font_family != CSS_FONT_FAMILY_INHERIT)
+ style->font_family = apply->font_family;
if (apply->font_style != CSS_FONT_STYLE_INHERIT)
style->font_style = apply->font_style;
if (apply->font_weight != CSS_FONT_WEIGHT_INHERIT)
@@ -817,6 +822,8 @@ void css_merge(struct css_style * const style, const struct css_style * const ap
style->display = apply->display;
if (apply->float_ != CSS_FLOAT_INHERIT)
style->float_ = apply->float_;
+ if (apply->font_family != CSS_FONT_FAMILY_INHERIT)
+ style->font_family = apply->font_family;
if (apply->font_size.size != CSS_FONT_SIZE_INHERIT)
style->font_size = apply->font_size;
if (apply->font_style != CSS_FONT_STYLE_INHERIT)
diff --git a/css/css.h b/css/css.h
index 640c0c041..3271ab4bd 100644
--- a/css/css.h
+++ b/css/css.h
@@ -52,6 +52,16 @@ typedef enum {
CSS_TEXT_DECORATION_UNKNOWN = 0x1000
} css_text_decoration;
+typedef enum {
+ CSS_FONT_FAMILY_INHERIT = 0x1,
+ CSS_FONT_FAMILY_SANS_SERIF = 0x2,
+ CSS_FONT_FAMILY_SERIF = 0x4,
+ CSS_FONT_FAMILY_MONOSPACE = 0x8,
+ CSS_FONT_FAMILY_CURSIVE = 0x10,
+ CSS_FONT_FAMILY_FANTASY = 0x20,
+ CSS_FONT_FAMILY_UNKNOWN = 0x1000
+} css_font_family;
+
/** Representation of a complete CSS 2 style. */
struct css_style {
colour background_color;
@@ -72,6 +82,7 @@ struct css_style {
} value;
} font_size;
+ css_font_family font_family;
css_font_weight font_weight;
css_font_style font_style;
diff --git a/css/ruleset.c b/css/ruleset.c
index 0675d0d1e..00b536aba 100644
--- a/css/ruleset.c
+++ b/css/ruleset.c
@@ -44,6 +44,7 @@ static void parse_color(struct css_style * const s, const struct css_node * cons
static void parse_display(struct css_style * const s, const struct css_node * const v);
static void parse_float(struct css_style * const s, const struct css_node * const v);
static void parse_font(struct css_style * const s, const struct css_node * v);
+static void parse_font_family(struct css_style * const s, const struct css_node * const v);
static void parse_font_size(struct css_style * const s, const struct css_node * const v);
static void parse_font_style(struct css_style * const s, const struct css_node * const v);
static void parse_font_weight(struct css_style * const s, const struct css_node * const v);
@@ -55,6 +56,7 @@ static void parse_visibility(struct css_style * const s, const struct css_node *
static void parse_width(struct css_style * const s, const struct css_node * const v);
static void parse_white_space(struct css_style * const s, const struct css_node * const v);
static css_text_decoration css_text_decoration_parse(const char * const s);
+static css_font_family css_font_family_parse(const char * const s);
/* table of property parsers: MUST be sorted by property name */
@@ -66,6 +68,7 @@ static const struct property_entry property_table[] = {
{ "display", parse_display },
{ "float", parse_float },
{ "font", parse_font },
+ { "font-family", parse_font_family },
{ "font-size", parse_font_size },
{ "font-style", parse_font_style },
{ "font-weight", parse_font_weight },
@@ -395,8 +398,10 @@ void parse_float(struct css_style * const s, const struct css_node * const v)
void parse_font(struct css_style * const s, const struct css_node * v)
{
+ css_font_family ff;
css_font_style fs;
css_font_weight fw;
+ s->font_family = CSS_FONT_FAMILY_SANS_SERIF;
s->font_style = CSS_FONT_STYLE_NORMAL;
s->font_weight = CSS_FONT_WEIGHT_NORMAL;
s->line_height.size = CSS_LINE_HEIGHT_ABSOLUTE;
@@ -404,6 +409,13 @@ void parse_font(struct css_style * const s, const struct css_node * v)
for (; v; v = v->next) {
switch (v->type) {
case CSS_NODE_IDENT:
+ /* font-family */
+ ff = css_font_family_parse(v->data);
+ if (ff != CSS_FONT_FAMILY_UNKNOWN) {
+ s->font_family = ff;
+ break;
+ }
+
/* font-style, font-variant, or font-weight */
fs = css_font_style_parse(v->data);
if (fs != CSS_FONT_STYLE_UNKNOWN) {
@@ -432,6 +444,32 @@ void parse_font(struct css_style * const s, const struct css_node * v)
}
}
+void parse_font_family(struct css_style * const s, const struct css_node * const v)
+{
+ /* TODO - font-family values are found in a comma separated list.
+ * Each list element should be considered in turn.
+ * The first match should be used.
+ * White space in a quoted string should be left alone,
+ * other white space should be reduced to a single space.*/
+ struct css_node *temp;
+ css_font_family z;
+ if (v->type != CSS_NODE_IDENT)
+ return;
+ z = css_font_family_parse(v->data);
+ if (z == CSS_FONT_FAMILY_INHERIT) {
+ if (v->next != 0)
+ return;
+ s->font_family = z;
+ }
+ if (z != CSS_FONT_FAMILY_UNKNOWN)
+ s->font_family = z;
+ /* for now, take the first item */
+ /*for (temp = v->next; temp; temp=temp->next) {
+ z = css_font_family_parse(temp->data);
+ s->font_family |= z;
+ }*/
+}
+
void parse_font_size(struct css_style * const s, const struct css_node * const v)
{
struct font_size_entry *fs;
@@ -585,3 +623,14 @@ css_text_decoration css_text_decoration_parse(const char * const s)
if (strcasecmp(s, "underline") == 0) return CSS_TEXT_DECORATION_UNDERLINE;
return CSS_TEXT_DECORATION_UNKNOWN;
}
+
+css_font_family css_font_family_parse(const char * const s)
+{
+ if (strcasecmp(s, "inherit") == 0) return CSS_FONT_FAMILY_INHERIT;
+ if (strcasecmp(s, "sans-serif") == 0) return CSS_FONT_FAMILY_SANS_SERIF;
+ if (strcasecmp(s, "serif") == 0) return CSS_FONT_FAMILY_SERIF;
+ if (strcasecmp(s, "monospace") == 0) return CSS_FONT_FAMILY_MONOSPACE;
+ if (strcasecmp(s, "cursive") == 0) return CSS_FONT_FAMILY_CURSIVE;
+ if (strcasecmp(s, "fantasy") == 0) return CSS_FONT_FAMILY_FANTASY;
+ return CSS_TEXT_DECORATION_UNKNOWN;
+}
diff --git a/riscos/font.c b/riscos/font.c
index 5fb02e3b4..37fc8f7f2 100644
--- a/riscos/font.c
+++ b/riscos/font.c
@@ -22,10 +22,19 @@
#include "netsurf/utils/log.h"
#include "netsurf/utils/utils.h"
-#define FONT_FAMILIES 1
+#define FONT_FAMILIES 5 /* Number of families */
+
+/* Font Styles */
#define FONT_BOLD 2
#define FONT_SLANTED 1
+/* Font families */
+#define FONT_SANS_SERIF 0
+#define FONT_SERIF 4
+#define FONT_MONOSPACE 8
+#define FONT_CURSIVE 12
+#define FONT_FANTASY 16
+
/* a font_set is just a linked list of font_data for each face for now */
struct font_set {
struct font_data *font[FONT_FAMILIES * 4];
@@ -34,16 +43,37 @@ struct font_set {
/** Table of font names.
*
* font id = font family * 4 + bold * 2 + slanted
- *
- * font family: 0 = sans-serif, 1 = serif, ...
+ *
+ * font family: 0 = sans-serif, 1 = serif, 2 = monospace, 3 = cursive
+ * 4 = fantasy
*/
const char * const font_table[FONT_FAMILIES * 4] = {
/* sans-serif */
- "Homerton.Medium\\ELatin1",
- "Homerton.Medium.Oblique\\ELatin1",
- "Homerton.Bold\\ELatin1",
- "Homerton.Bold.Oblique\\ELatin1",
+/*0*/ "Homerton.Medium\\ELatin1",
+/*1*/ "Homerton.Medium.Oblique\\ELatin1",
+/*2*/ "Homerton.Bold\\ELatin1",
+/*3*/ "Homerton.Bold.Oblique\\ELatin1",
+ /* serif */
+/*4*/ "Trinity.Medium\\ELatin1",
+/*5*/ "Trinity.Medium.Italic\\ELatin1",
+/*6*/ "Trinity.Bold\\ELatin1",
+/*7*/ "Trinity.Bold.Italic\\ELatin1",
+ /* monospace */
+/*8*/ "Corpus.Medium\\ELatin1",
+/*9*/ "Corpus.Medium.Oblique\\ELatin1",
+/*10*/ "Corpus.Bold\\ELatin1",
+/*11*/ "Corpus.Bold.Oblique\\ELatin1",
+ /* cursive */
+/*12*/ "Churchill.Medium\\ELatin1",
+/*13*/ "Churchill.Medium\\ELatin1\\M65536 0 13930 65536 0 0",
+/*14*/ "Churchill.Bold\\ELatin1",
+/*15*/ "Churchill.Bold\\ELatin1\\M65536 0 13930 65536 0 0",
+ /* fantasy */
+/*16*/ "Sassoon.Primary\\ELatin1",
+/*17*/ "Sassoon.Primary\\ELatin1\\M65536 0 13930 65536 0 0",
+/*18*/ "Sassoon.Primary.Bold\\ELatin1",
+/*19*/ "Sassoon.Primary.Bold\\ELatin1\\M65536 0 13930 65536 0 0",
};
@@ -82,6 +112,7 @@ struct font_data *font_open(struct font_set *set, struct css_style *style)
unsigned int f = 0;
font_f handle;
os_error *error;
+ bool bold=false, italic=false;
assert(set);
assert(style);
@@ -89,6 +120,26 @@ struct font_data *font_open(struct font_set *set, struct css_style *style)
if (style->font_size.size == CSS_FONT_SIZE_LENGTH)
size = style->font_size.value.length.value * 16;
+ switch (style->font_family) {
+ case CSS_FONT_FAMILY_SANS_SERIF:
+ f += FONT_SANS_SERIF;
+ break;
+ case CSS_FONT_FAMILY_SERIF:
+ f += FONT_SERIF;
+ break;
+ case CSS_FONT_FAMILY_MONOSPACE:
+ f += FONT_MONOSPACE;
+ break;
+ case CSS_FONT_FAMILY_CURSIVE:
+ f += FONT_CURSIVE;
+ break;
+ case CSS_FONT_FAMILY_FANTASY:
+ f += FONT_FANTASY;
+ break;
+ default:
+ break;
+ }
+
switch (style->font_weight) {
case CSS_FONT_WEIGHT_BOLD:
case CSS_FONT_WEIGHT_600:
@@ -96,6 +147,7 @@ struct font_data *font_open(struct font_set *set, struct css_style *style)
case CSS_FONT_WEIGHT_800:
case CSS_FONT_WEIGHT_900:
f += FONT_BOLD;
+ bold = true;
break;
default:
break;
@@ -105,6 +157,7 @@ struct font_data *font_open(struct font_set *set, struct css_style *style)
case CSS_FONT_STYLE_ITALIC:
case CSS_FONT_STYLE_OBLIQUE:
f += FONT_SLANTED;
+ italic = true;
break;
default:
break;
@@ -118,9 +171,17 @@ struct font_data *font_open(struct font_set *set, struct css_style *style)
error = xfont_find_font(font_table[f], (int)size, (int)size,
0, 0, &handle, 0, 0);
- if (error) {
- fprintf(stderr, "%i: %s\n", error->errnum, error->errmess);
- die("font_find_font failed");
+
+ if (error) { /* fall back to Homerton */
+ LOG(("font_find_font failed; falling back to Homerton"));
+ f = 0 + (bold ? FONT_BOLD : 0) + (italic ? FONT_SLANTED: 0);
+
+ error = xfont_find_font(font_table[f], (int)size, (int)size,
+ 0, 0, &handle, 0, 0);
+ if (error) {
+ LOG(("%i: %s\n", error->errnum, error->errmess));
+ die("font_find_font failed");
+ }
}
data->handle = handle;
@@ -196,7 +257,7 @@ unsigned long font_width(struct font_data *font, const char * text, unsigned int
/**
* Find where in a string a x coordinate falls.
*
- * For example, used to find where to position the caret in response to mouse
+ * For example, used to find where to position the caret in response to mouse
* click.
*
* \param text a string
@@ -289,6 +350,7 @@ int main(void)
struct font_set *set;
struct css_style style;
+ style.font_family = CSS_FONT_FAMILY_SANS_SERIF;
style.font_size.size = CSS_FONT_SIZE_LENGTH;
style.font_weight = CSS_FONT_WEIGHT_BOLD;
style.font_style = CSS_FONT_STYLE_ITALIC;