summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--debug/fontd.c173
1 files changed, 28 insertions, 145 deletions
diff --git a/debug/fontd.c b/debug/fontd.c
index a8974e540..8269a392e 100644
--- a/debug/fontd.c
+++ b/debug/fontd.c
@@ -2,170 +2,53 @@
* This file is part of NetSurf, http://netsurf.sourceforge.net/
* Licensed under the GNU General Public License,
* http://www.opensource.org/licenses/gpl-license
- * Copyright 2003 James Bursa <bursa@users.sourceforge.net>
+ * Copyright 2005 James Bursa <bursa@users.sourceforge.net>
*/
#include <assert.h>
-#include <stdio.h>
#include "netsurf/css/css.h"
#include "netsurf/render/font.h"
-#include "netsurf/utils/utils.h"
-#include "netsurf/utils/log.h"
-#define FONT_FAMILIES 1
-#define FONT_BOLD 2
-#define FONT_SLANTED 1
-/* 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];
-};
-
-
-static void font_close(struct font_data *data);
-
-/**
- * functions
- */
-
-unsigned long nsfont_width(struct font_data *font, const char * text,
- size_t length)
-{
- int width;
-
- assert(font != 0 && text != 0);
-
- if (length == 0)
- return 0;
-
- return length * 10;
-}
-
-bool nsfont_position_in_string(struct font_data* font, const char* text,
- size_t length, unsigned long x, int* char_offset, int* pixel_offset)
+bool nsfont_width(const struct css_style *style,
+ const char *string, size_t length,
+ int *width)
{
- assert(font != 0 && text != 0);
-
- *char_offset = x / 10;
- *pixel_offset = x;
+ assert(style);
+ assert(string);
+ *width = length * 10;
return true;
}
-struct font_set *nsfont_new_set()
-{
- struct font_set *set;
- unsigned int i;
-
- set = calloc(1, sizeof(*set));
- if (!set)
- return NULL;
-
- for (i = 0; i < FONT_FAMILIES * 4; i++)
- set->font[i] = 0;
-
- return set;
-}
-
-
-struct font_data *nsfont_open(struct font_set *set, struct css_style *style)
-{
- struct font_data *data;
- 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 = calloc(1, sizeof(*data));
- if (!data)
- return NULL;
-
- data->size = size;
- data->space_width = nsfont_width(data, " ", sizeof(" ")-1);
-
- data->next = set->font[f];
- set->font[f] = data;
-
- return data;
-}
-
-
-void nsfont_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)
-{
-
- free(data);
-}
-
-
-char *nsfont_split(struct font_data *data, const char * text,
- size_t length, unsigned int width, unsigned int *used_width)
+bool nsfont_position_in_string(const struct css_style *style,
+ const char *string, size_t length,
+ int x, size_t *char_offset, int *actual_x)
{
- int i = width / 10;
+ assert(style);
+ assert(string);
- if (length < i) {
- *used_width = length * 10;
- return text + length;
- }
-
- for (; i != 0 && text[i] != ' '; i--)
- ;
- *used_width = i * 10;
- return text + i;
+ *char_offset = (x + 5) / 10;
+ if (length < *char_offset)
+ *char_offset = length;
+ *actual_x = *char_offset * 10;
+ return true;
}
-bool nsfont_paint(struct font_data *data, const char *text,
- size_t length, int xpos, int ypos, void *trfm)
+bool nsfont_split(const struct css_style *style,
+ const char *string, size_t length,
+ int x, size_t *char_offset, int *actual_x)
{
- assert(data != NULL);
- assert(text != NULL);
+ assert(style);
+ assert(string);
+ *char_offset = x / 10;
+ if (length < *char_offset)
+ *char_offset = length;
+ while (*char_offset && string[*char_offset] != ' ')
+ (*char_offset)--;
+ *actual_x = *char_offset * 10;
return true;
}