From fcbe2cebae28ef623dceb82ce9501027fea91fb5 Mon Sep 17 00:00:00 2001 From: James Bursa Date: Thu, 26 Sep 2002 21:38:33 +0000 Subject: [project @ 2002-09-26 21:38:32 by bursa] New Unicode font handling and rendering code. svn path=/import/netsurf/; revision=39 --- desktop/browser.c | 18 ++++- desktop/browser.h | 4 +- render/box.c | 30 ++++---- render/box.h | 6 +- render/layout.c | 32 ++++---- riscos/font.c | 227 ++++++++++++++++++++++++++++++++++++++++++++---------- riscos/font.h | 35 +++++---- riscos/gui.c | 16 ++-- 8 files changed, 268 insertions(+), 100 deletions(-) diff --git a/desktop/browser.c b/desktop/browser.c index f21008abb..f42d068b6 100644 --- a/desktop/browser.c +++ b/desktop/browser.c @@ -1,5 +1,5 @@ /** - * $Id: browser.c,v 1.1 2002/09/11 14:24:02 monkeyson Exp $ + * $Id: browser.c,v 1.2 2002/09/26 21:38:32 bursa Exp $ */ #include "netsurf/riscos/font.h" @@ -12,6 +12,7 @@ #include #include #include +#include struct box_selection { @@ -40,6 +41,7 @@ void content_destroy(struct content* c) { case CONTENT_HTML: /* free other memory here */ + font_free_set(c->data.html.fonts); break; default: break; @@ -138,8 +140,10 @@ void content_html_reformat(struct content* c, int width) c->data.html.layout->type = BOX_BLOCK; c->data.html.layout->node = c->data.html.markup; + c->data.html.fonts = font_new_set(); + Log("content_html_reformat", "XML to box"); - xml_to_box(c->data.html.markup, c->data.html.style, c->data.html.stylesheet, &selector, 0, c->data.html.layout, 0, 0); + xml_to_box(c->data.html.markup, c->data.html.style, c->data.html.stylesheet, &selector, 0, c->data.html.layout, 0, 0, c->data.html.fonts); Log("content_html_reformat", "Layout document"); layout_document(c->data.html.layout->children, (unsigned long)width); @@ -150,6 +154,9 @@ void content_html_reformat(struct content* c, int width) void browser_window_reformat(struct browser_window* bw) { + char status[100]; + clock_t time0, time1; + Log("browser_window_reformat", "Entering..."); if (bw == NULL) return; @@ -161,7 +168,9 @@ void browser_window_reformat(struct browser_window* bw) case CONTENT_HTML: Log("browser_window_reformat", "HTML content."); browser_window_set_status(bw, "Formatting page..."); + time0 = clock(); content_html_reformat(bw->current_content, bw->format_width); + time1 = clock(); Log("browser_window_reformat", "Content reformatted"); if (bw->current_content->data.html.layout != NULL) { @@ -172,7 +181,8 @@ void browser_window_reformat(struct browser_window* bw) Log("browser_window_reformat", "Redraw window"); gui_window_redraw_window(bw->window); Log("browser_window_reformat", "Complete"); - browser_window_set_status(bw, "Format complete."); + sprintf(status, "Format complete (%gs).", ((float) time1 - time0) / CLOCKS_PER_SEC); + browser_window_set_status(bw, status); } else { @@ -541,7 +551,7 @@ void browser_window_text_selection(struct browser_window* bw, end = &(bw->current_content->data.html.text_selection.end); font_position_in_string(click_boxes[i].box->text, - click_boxes[i].box->style, click_boxes[i].box->length, + click_boxes[i].box->font, click_boxes[i].box->length, click_x - click_boxes[i].actual_x, &click_char_offset, &click_pixel_offset); diff --git a/desktop/browser.h b/desktop/browser.h index 1e158b3a8..9f799d0cb 100644 --- a/desktop/browser.h +++ b/desktop/browser.h @@ -1,5 +1,5 @@ /** - * $Id: browser.h,v 1.1 2002/09/11 14:24:02 monkeyson Exp $ + * $Id: browser.h,v 1.2 2002/09/26 21:38:32 bursa Exp $ */ #ifndef _NETSURF_DESKTOP_BROWSER_H_ @@ -10,6 +10,7 @@ #include "netsurf/render/box.h" #include "netsurf/desktop/gui.h" #include "netsurf/desktop/fetch.h" +#include "netsurf/riscos/font.h" typedef int browser_window_flags; #define browser_TOOLBAR ((browser_window_flags) 1) @@ -58,6 +59,7 @@ struct content enum {alter_UNKNOWN, alter_START, alter_END} altering; int selected; /* 0 = unselected, 1 = selected */ } text_selection; + struct font_set* fonts; } html; } data; struct fetch* main_fetch; diff --git a/render/box.c b/render/box.c index 59c7f0f5a..7ee7e712b 100644 --- a/render/box.c +++ b/render/box.c @@ -1,5 +1,5 @@ /** - * $Id: box.c,v 1.16 2002/09/19 19:54:43 bursa Exp $ + * $Id: box.c,v 1.17 2002/09/26 21:38:32 bursa Exp $ */ #include @@ -10,7 +10,7 @@ #include "libxml/HTMLparser.h" #include "utf-8.h" #include "netsurf/render/css.h" -#include "netsurf/render/font.h" +#include "netsurf/riscos/font.h" #include "netsurf/render/box.h" #include "netsurf/render/utils.h" @@ -25,7 +25,7 @@ struct box * convert_xml_to_box(xmlNode * n, struct css_style * parent_style, struct css_stylesheet * stylesheet, struct css_selector ** selector, unsigned int depth, struct box * parent, struct box * inline_container, - const char *href); + const char *href, struct font_set *fonts); struct css_style * box_get_style(struct css_stylesheet * stylesheet, struct css_style * parent_style, xmlNode * n, struct css_selector * selector, unsigned int depth); void box_normalise_block(struct box *block); @@ -74,6 +74,7 @@ struct box * box_create(xmlNode * node, box_type type, struct css_style * style, box->float_children = 0; box->next_float = 0; box->col = 0; + box->font = 0; return box; } @@ -120,10 +121,10 @@ void xml_to_box(xmlNode * n, struct css_style * parent_style, struct css_stylesheet * stylesheet, struct css_selector ** selector, unsigned int depth, struct box * parent, struct box * inline_container, - const char *href) + const char *href, struct font_set *fonts) { convert_xml_to_box(n, parent_style, stylesheet, - selector, depth, parent, inline_container, href); + selector, depth, parent, inline_container, href, fonts); box_normalise_block(parent->children); } @@ -132,7 +133,7 @@ struct box * convert_xml_to_box(xmlNode * n, struct css_style * parent_style, struct css_stylesheet * stylesheet, struct css_selector ** selector, unsigned int depth, struct box * parent, struct box * inline_container, - const char *href) + const char *href, struct font_set *fonts) { struct box * box; struct box * inline_container_c; @@ -174,8 +175,9 @@ struct box * convert_xml_to_box(xmlNode * n, struct css_style * parent_style, } if (n->type == XML_TEXT_NODE) { box = box_create(n, BOX_INLINE, parent_style, href); - box->text = squash_whitespace(tolat1(n->content)); + box->text = squash_whitespace(n->content); box->length = strlen(box->text); + box->font = font_open(fonts, box->style); box_add_child(inline_container, box); } else { box = box_create(0, BOX_FLOAT_LEFT, 0, href); @@ -197,14 +199,14 @@ struct box * convert_xml_to_box(xmlNode * n, struct css_style * parent_style, for (c = n->children; c != 0; c = c->next) inline_container_c = convert_xml_to_box(c, style, stylesheet, selector, depth + 1, box, inline_container_c, - href); + href, fonts); inline_container = 0; break; case CSS_DISPLAY_INLINE: /* inline elements get no box, but their children do */ for (c = n->children; c != 0; c = c->next) inline_container = convert_xml_to_box(c, style, stylesheet, selector, depth + 1, parent, inline_container, - href); + href, fonts); break; case CSS_DISPLAY_TABLE: box = box_create(n, BOX_TABLE, style, href); @@ -212,7 +214,7 @@ struct box * convert_xml_to_box(xmlNode * n, struct css_style * parent_style, for (c = n->children; c != 0; c = c->next) convert_xml_to_box(c, style, stylesheet, selector, depth + 1, box, 0, - href); + href, fonts); inline_container = 0; break; case CSS_DISPLAY_TABLE_ROW_GROUP: @@ -224,7 +226,7 @@ struct box * convert_xml_to_box(xmlNode * n, struct css_style * parent_style, for (c = n->children; c != 0; c = c->next) inline_container_c = convert_xml_to_box(c, style, stylesheet, selector, depth + 1, box, inline_container_c, - href); + href, fonts); inline_container = 0; break; case CSS_DISPLAY_TABLE_ROW: @@ -233,7 +235,7 @@ struct box * convert_xml_to_box(xmlNode * n, struct css_style * parent_style, for (c = n->children; c != 0; c = c->next) convert_xml_to_box(c, style, stylesheet, selector, depth + 1, box, 0, - href); + href, fonts); inline_container = 0; break; case CSS_DISPLAY_TABLE_CELL: @@ -248,7 +250,7 @@ struct box * convert_xml_to_box(xmlNode * n, struct css_style * parent_style, for (c = n->children; c != 0; c = c->next) inline_container_c = convert_xml_to_box(c, style, stylesheet, selector, depth + 1, box, inline_container_c, - href); + href, fonts); inline_container = 0; break; default: @@ -446,7 +448,7 @@ void box_normalise_table(struct box *table) case BOX_TABLE_ROW: case BOX_TABLE_CELL: /* insert implied table row group */ - fprintf(stderr, "inserting implied table row group\n"); +/* fprintf(stderr, "inserting implied table row group\n"); */ style = xcalloc(1, sizeof(struct css_style)); memcpy(style, table->style, sizeof(struct css_style)); css_cascade(style, &css_blank_style); diff --git a/render/box.h b/render/box.h index 5165945b5..3df758a60 100644 --- a/render/box.h +++ b/render/box.h @@ -1,5 +1,5 @@ /** - * $Id: box.h,v 1.10 2002/09/19 19:54:43 bursa Exp $ + * $Id: box.h,v 1.11 2002/09/26 21:38:33 bursa Exp $ */ #ifndef _NETSURF_RENDER_BOX_H_ @@ -8,6 +8,7 @@ #include #include "libxml/HTMLparser.h" #include "netsurf/render/css.h" +#include "netsurf/riscos/font.h" /** * structures @@ -43,6 +44,7 @@ struct box { struct box * float_children; struct box * next_float; struct column *col; + struct font_data *font; }; #define UNKNOWN_WIDTH ULONG_MAX @@ -55,7 +57,7 @@ struct box { void xml_to_box(xmlNode * n, struct css_style * parent_style, struct css_stylesheet * stylesheet, struct css_selector ** selector, unsigned int depth, struct box * parent, struct box * inline_container, - const char *href); + const char *href, struct font_set *fonts); void box_dump(struct box * box, unsigned int depth); void box_free(struct box *box); diff --git a/render/layout.c b/render/layout.c index f3f25b50b..44baa4cef 100644 --- a/render/layout.c +++ b/render/layout.c @@ -1,5 +1,5 @@ /** - * $Id: layout.c,v 1.18 2002/09/19 19:54:43 bursa Exp $ + * $Id: layout.c,v 1.19 2002/09/26 21:38:33 bursa Exp $ */ #include @@ -9,7 +9,7 @@ #include #include "libxml/HTMLparser.h" #include "netsurf/render/css.h" -#include "netsurf/render/font.h" +#include "netsurf/riscos/font.h" #include "netsurf/render/box.h" #include "netsurf/render/utils.h" #include "netsurf/render/layout.h" @@ -308,7 +308,7 @@ struct box * layout_line(struct box * first, unsigned long width, unsigned long b->height = h; if (h > height) height = h; if (b->width == UNKNOWN_WIDTH) - b->width = font_width(b->style, b->text, b->length); + b->width = font_width(b->font, b->text, b->length); x += b->width; } } @@ -369,7 +369,7 @@ struct box * layout_line(struct box * first, unsigned long width, unsigned long if (space == 0) wp = w = c->width; else - wp = w = font_width(c->style, c->text, space - c->text); + wp = w = font_width(c->font, c->text, space - c->text); if (x1 - x0 < xp + w && left == 0 && right == 0 && c == first) { /* first word doesn't fit, but no floats and first on line so force in */ @@ -385,6 +385,8 @@ struct box * layout_line(struct box * first, unsigned long width, unsigned long c->next = c2; b = c2; } + c->width = wp; + x = xp + wp; /* fprintf(stderr, "layout_line: overflow, forcing\n"); */ } else if (x1 - x0 < xp + w) { /* first word doesn't fit, but full width not available so leave for later */ @@ -393,13 +395,15 @@ struct box * layout_line(struct box * first, unsigned long width, unsigned long } else { /* fit as many words as possible */ assert(space != 0); - while (xp + w < x1 - x0) { + while (xp + w < x1 - x0 && space2 != 0) { /* fprintf(stderr, "%li + %li = %li < %li = %li - %li\n", */ /* xp, w, xp + w, x1 - x0, x1, x0); */ space = space2; wp = w; space2 = strchr(space + 1, ' '); - w = font_width(c->style, c->text, space2 - c->text); + if (space2 == 0) + space2 = c->text + c->length; + w = font_width(c->font, c->text, space2 - c->text); } c2 = memcpy(xcalloc(1, sizeof(struct box)), c, sizeof(struct box)); c2->text = xstrdup(space + 1); @@ -409,10 +413,10 @@ struct box * layout_line(struct box * first, unsigned long width, unsigned long c2->next = c->next; c->next = c2; b = c2; + c->width = wp; + x = xp + wp; /* fprintf(stderr, "layout_line: overflow, fit\n"); */ } - c->width = wp; - x = xp + wp; move_y = 1; } @@ -509,7 +513,7 @@ void layout_table(struct box * table, unsigned long width, struct box * cont, break; } - fprintf(stderr, "table width %lu, min %lu, max %lu\n", table_width, table->min_width, table->max_width); +/* fprintf(stderr, "table width %lu, min %lu, max %lu\n", table_width, table->min_width, table->max_width); */ /* percentage width columns give an upper bound if possible */ for (i = 0; i < table->columns; i++) { @@ -537,7 +541,7 @@ void layout_table(struct box * table, unsigned long width, struct box * cont, /* space between min and max: fill it exactly */ float scale = (float) (table_width - table->min_width) / (float) (max_width - table->min_width); - fprintf(stderr, "filling, scale %f\n", scale); +/* fprintf(stderr, "filling, scale %f\n", scale); */ for (i = 0; i < table->columns; i++) { table->col[i].width = table->col[i].min + (table->col[i].max - table->col[i].min) * scale; @@ -651,7 +655,7 @@ void calculate_inline_container_widths(struct box *box) switch (child->type) { case BOX_INLINE: /* max = all one line */ - child->width = font_width(child->style, + child->width = font_width(child->font, child->text, child->length); max += child->width; @@ -659,10 +663,10 @@ void calculate_inline_container_widths(struct box *box) for (word = child->text, space = strchr(child->text, ' '); space != 0; word = space + 1, space = strchr(word, ' ')) { - width = font_width(child->style, word, space - word); + width = font_width(child->font, word, space - word); if (min < width) min = width; } - width = font_width(child->style, word, strlen(word)); + width = font_width(child->font, word, strlen(word)); if (min < width) min = width; break; @@ -741,7 +745,7 @@ void calculate_table_widths(struct box *table) for (i = 0; i < table->columns; i++) { min_width += col[i].min; max_width += col[i].max; - fprintf(stderr, "col %u, min %lu, max %lu\n", i, col[i].min, col[i].max); +/* fprintf(stderr, "col %u, min %lu, max %lu\n", i, col[i].min, col[i].max); */ } table->min_width = min_width; table->max_width = max_width; diff --git a/riscos/font.c b/riscos/font.c index 05faf50cf..3ee42e8ce 100644 --- a/riscos/font.c +++ b/riscos/font.c @@ -1,45 +1,61 @@ /** - * $Id: font.c,v 1.2 2002/09/11 14:24:02 monkeyson Exp $ + * $Id: font.c,v 1.3 2002/09/26 21:38:33 bursa Exp $ */ +#include #include +#include "utf-8.h" #include "netsurf/render/css.h" -#include "netsurf/render/font.h" +#include "netsurf/riscos/font.h" #include "netsurf/render/utils.h" #include "netsurf/desktop/gui.h" #include "oslib/font.h" /** - * functions + * RISC OS fonts are 8-bit, so Unicode is displayed by combining many + * font manager fonts. Each font manager font must have 128 characters of + * Unicode in order, starting at character 128. */ -/** it is rather inefficient calling this all the time **/ -font_f riscos_font_css_to_handle(struct css_style* style) -{ - int width = 12 * 16; - int height = 12 * 16; - char font_name[255]; +/** + * font id = font family * 4 + bold * 2 + slanted + * font family: 0 = sans-serif, 1 = serif, ... + */ - if (style->font_size.size == CSS_FONT_SIZE_LENGTH) - width = height = style->font_size.value.length.value * 16; +const char * const font_table[FONT_FAMILIES * 4][FONT_CHUNKS] = { + /* sans-serif */ + { "Homerton.Medium\\EU0000", + "Homerton.Medium\\EU0080", + "Homerton.Medium\\EU0100" }, + { "Homerton.Medium.Oblique\\EU0000", + "Homerton.Medium.Oblique\\EU0080", + "Homerton.Medium.Oblique\\EU0100" }, + { "Homerton.Bold\\EU0000", + "Homerton.Bold\\EU0080", + "Homerton.Bold\\EU0100" }, + { "Homerton.Bold.Oblique\\EU0000", + "Homerton.Bold.Oblique\\EU0080", + "Homerton.Bold.Oblique\\EU0100" }, +}; - strcpy(font_name, "Homerton."); - if (style->font_weight == CSS_FONT_WEIGHT_BOLD) - strcat(font_name, "Bold"); - else - strcat(font_name, "Medium"); +/* 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]; +}; - if (style->font_style == CSS_FONT_STYLE_ITALIC || style->font_style == CSS_FONT_STYLE_OBLIQUE) - strcat(font_name, ".Oblique"); +void font_close(struct font_data *data); - return font_find_font(font_name, width, height, 0, 0, 0, 0); -} +/** + * functions + */ -unsigned long font_width(struct css_style * style, const char * text, unsigned int length) +unsigned long font_width(struct font_data *font, const char * text, unsigned int length) { font_scan_block block; os_error * error; - font_f font; + char *text2; + + assert(font != 0 && text != 0); if (length == 0) return 0; @@ -48,20 +64,21 @@ unsigned long font_width(struct css_style * style, const char * text, unsigned i block.letter.x = block.letter.y = 0; block.split_char = -1; - font = riscos_font_css_to_handle(style); - - error = xfont_scan_string(font, (char*) text, - font_GIVEN_BLOCK | font_GIVEN_LENGTH | font_GIVEN_FONT | font_KERN | font_RETURN_BBOX, + text2 = font_utf8_to_string(font, text, length); + error = xfont_scan_string(font->handle[0], text2, + font_GIVEN_BLOCK | font_GIVEN_FONT | font_KERN | font_RETURN_BBOX, 0x7fffffff, 0x7fffffff, &block, - 0, length, + 0, 0, 0, 0, 0, 0); if (error != 0) { fprintf(stderr, "%s\n", error->errmess); die("font_scan_string failed"); } -// fprintf(stderr, "Stated length %d, strlen %d\n", (int)length, strlen(text)); +/* fprintf(stderr, "font_width: '%.*s' => '%s' => %i %i %i %i\n", length, text, text2, */ +/* block.bbox.x0, block.bbox.y0, block.bbox.x1, block.bbox.y1); */ + free(text2); if (length < 0x7fffffff) { @@ -82,33 +99,31 @@ unsigned long font_width(struct css_style * style, const char * text, unsigned i // fprintf(stderr, "No space\n");*/ } - font_lose_font(font); - return block.bbox.x1 / 800; } -void font_position_in_string(const char* text, struct css_style* style, int length, int x, int* char_offset, int* pixel_offset) +void font_position_in_string(const char* text, struct font_data* font, + int length, int x, int* char_offset, int* pixel_offset) { - font_f font; font_scan_block block; char* split_point; int x_out, y_out, length_out; + char *text2; + + assert(font != 0 && text != 0); block.space.x = block.space.y = 0; block.letter.x = block.letter.y = 0; block.split_char = -1; - font = riscos_font_css_to_handle(style); - - xfont_scan_string(font, (char*) text, - font_GIVEN_BLOCK | font_GIVEN_LENGTH | - font_GIVEN_FONT | font_KERN | font_RETURN_CARET_POS, + text2 = font_utf8_to_string(font, text, length); + xfont_scan_string(font, text2, + font_GIVEN_BLOCK | font_GIVEN_FONT | font_KERN | font_RETURN_CARET_POS, ro_x_units(x) * 400, 0x7fffffff, - &block, 0, length, + &block, 0, 0, &split_point, &x_out, &y_out, &length_out); - - font_lose_font(font); + free(text2); *char_offset = (int)(split_point - text); *pixel_offset = browser_x_units(x_out / 400); @@ -116,3 +131,135 @@ void font_position_in_string(const char* text, struct css_style* style, int leng return; } + +struct font_set *font_new_set() +{ + struct font_set *set = xcalloc(1, sizeof(*set)); + unsigned int i; + + for (i = 0; i < FONT_FAMILIES * 4; i++) + set->font[i] = 0; + + return set; +} + + +struct font_data *font_open(struct font_set *set, struct css_style *style) +{ + struct font_data *data; + unsigned int i; + unsigned int size = 16 * 11; + unsigned int f = 0; + + assert(set != 0); + + if (style->font_size.size == CSS_FONT_SIZE_LENGTH) + size = style->font_size.value.length.value * 16; + + switch (style->font_weight) { + case CSS_FONT_WEIGHT_BOLD: + case CSS_FONT_WEIGHT_600: + case CSS_FONT_WEIGHT_700: + case CSS_FONT_WEIGHT_800: + case CSS_FONT_WEIGHT_900: + f += FONT_BOLD; + break; + default: + break; + } + + switch (style->font_style) { + case CSS_FONT_STYLE_ITALIC: + case CSS_FONT_STYLE_OBLIQUE: + f += FONT_SLANTED; + break; + default: + break; + } + + for (data = set->font[f]; data != 0; data = data->next) + if (data->size == size) + return data; + + data = xcalloc(1, sizeof(*data)); + + for (i = 0; i < FONT_CHUNKS; i++) { + font_f handle = font_find_font(font_table[f][i], size, size, 0, 0, 0, 0); + data->handle[i] = handle; + } + data->size = size; + + data->next = set->font[f]; + set->font[f] = data; + + return data; +} + + +void font_free_set(struct font_set *set) +{ + unsigned int i; + struct font_data *data, *next; + + assert(set != 0); + + for (i = 0; i < FONT_FAMILIES * 4; i++) { + for (data = set->font[i]; data != 0; data = next) { + next = data->next; + font_close(data); + } + } + + free(set); +} + + +void font_close(struct font_data *data) +{ + unsigned int i; + + for (i = 0; i < FONT_CHUNKS; i++) + font_lose_font(data->handle[i]); + + free(data); +} + +#define BUFFER_CHUNK 100 + +char *font_utf8_to_string(struct font_data *font, const char *s, unsigned int length) +{ + unsigned long buffer_len = BUFFER_CHUNK; + char *d = xcalloc(buffer_len, sizeof(char)); + unsigned int chunk0 = 0, chunk1; + unsigned int u, chars, i = 0, j = 0; + + assert(font != 0 && s != 0); + +/* fprintf(stderr, "font_utf8_to_string: '%s'", s); */ + + while (j < length && s[j] != 0) { + u = sgetu8(s + j, &chars); + j += chars; + if (buffer_len < i + 5) { + buffer_len += BUFFER_CHUNK; + d = xrealloc(d, buffer_len * sizeof(char)); + } + chunk1 = u / 0x80; + if (FONT_CHUNKS <= chunk1 || (u < 0x20 || (0x80 <= u && u <= 0x9f))) { + d[i++] = '?'; + } else { + if (chunk0 != chunk1) { + d[i++] = font_COMMAND_FONT; + d[i++] = font->handle[chunk1]; + chunk0 = chunk1; + } + d[i++] = 0x80 + (u % 0x80); + } + } + d[i] = 0; + +/* fprintf(stderr, " => '%s'\n", d); */ + + return d; +} + diff --git a/riscos/font.h b/riscos/font.h index ee3e4c2b2..24b5d0f5d 100644 --- a/riscos/font.h +++ b/riscos/font.h @@ -1,5 +1,5 @@ /** - * $Id: font.h,v 1.1 2002/09/11 14:24:02 monkeyson Exp $ + * $Id: font.h,v 1.2 2002/09/26 21:38:33 bursa Exp $ */ #ifndef _NETSURF_RISCOS_FONT_H_ @@ -12,28 +12,31 @@ #include "netsurf/render/css.h" #include "oslib/font.h" -struct font_set; typedef unsigned int font_id; -struct font_split { - unsigned long width; - unsigned long height; - const char * end; + +#define FONT_FAMILIES 1 +#define FONT_CHUNKS 3 +#define FONT_BOLD 2 +#define FONT_SLANTED 1 + +struct font_set; +struct font_data { + font_f handle[FONT_CHUNKS]; + unsigned int size; + struct font_data *next; }; /** * interface */ -struct font_set * font_set_create(void); -font_id font_add(struct font_set * font_set, const char * name, unsigned int weight, - unsigned int size); -void font_set_free(struct font_set * font_set); -struct font_split font_split(struct font_set * font_set, font_id id, const char * text, - unsigned long width, int force); -unsigned long font_width(struct css_style * style, const char * text, unsigned int length); - -font_f riscos_font_css_to_handle(struct css_style* style); +unsigned long font_width(struct font_data *font, const char * text, unsigned int length); +void font_position_in_string(const char* text, struct font_data *font, + int length, int x, int* char_offset, int* pixel_offset); -void font_position_in_string(const char* text, struct css_style* style, int length, int x, int* char_offset, int* pixel_offset); +struct font_set *font_new_set(); +struct font_data *font_open(struct font_set *set, struct css_style *style); +void font_free_set(struct font_set *set); +char *font_utf8_to_string(struct font_data *data, const char *s, unsigned int length); #endif diff --git a/riscos/gui.c b/riscos/gui.c index 15d38b540..b66a3b4a8 100644 --- a/riscos/gui.c +++ b/riscos/gui.c @@ -1,5 +1,5 @@ /** - * $Id: gui.c,v 1.1 2002/09/11 14:24:02 monkeyson Exp $ + * $Id: gui.c,v 1.2 2002/09/26 21:38:33 bursa Exp $ */ #include "netsurf/riscos/font.h" @@ -264,7 +264,7 @@ void ro_gui_window_redraw_box(gui_window* g, struct box * box, signed long x, si struct box * c; const char * const noname = ""; const char * name = noname; - font_f font; + char *text; switch (box->type) { @@ -299,8 +299,6 @@ void ro_gui_window_redraw_box(gui_window* g, struct box * box, signed long x, si if (box->type == BOX_INLINE) { - font = riscos_font_css_to_handle(box->style); - if (g->data.browser.bw->current_content->data.html.text_selection.selected == 1) { struct box_position* start; @@ -359,13 +357,13 @@ if (g->data.browser.bw->current_content->data.html.text_selection.selected == 1) } } - font_paint(font, (char*) box->text, - font_OS_UNITS | font_GIVEN_LENGTH | font_GIVEN_FONT | font_KERN, + text = font_utf8_to_string(box->font, box->text, box->length); + font_paint(box->font->handle[0], text, + font_OS_UNITS | font_GIVEN_FONT | font_KERN, x + box->x * 2, y - box->y * 2 - box->height * 2, NULL, NULL, - box->length); - - font_lose_font(font); + 0); + free(text); } } -- cgit v1.2.3