diff options
author | John Mark Bell <jmb@netsurf-browser.org> | 2009-07-21 10:59:53 +0000 |
---|---|---|
committer | John Mark Bell <jmb@netsurf-browser.org> | 2009-07-21 10:59:53 +0000 |
commit | 2565a37a52a5c714e7c6bbd1808db0d6d37c6ea3 (patch) | |
tree | f3fe5f224c9e0e4089aca2d9012dfe1a74cf9c90 /beos | |
parent | 1930989f8ccdd574472ed72990b6a82fdcf9d5f4 (diff) | |
download | netsurf-2565a37a52a5c714e7c6bbd1808db0d6d37c6ea3.tar.gz netsurf-2565a37a52a5c714e7c6bbd1808db0d6d37c6ea3.tar.bz2 |
Refactor text plotter and other font functions to remove dependency on CSS.
svn path=/trunk/netsurf/; revision=8641
Diffstat (limited to 'beos')
-rw-r--r-- | beos/beos_font.cpp | 104 | ||||
-rw-r--r-- | beos/beos_font.h | 10 | ||||
-rw-r--r-- | beos/beos_plotters.cpp | 10 |
3 files changed, 48 insertions, 76 deletions
diff --git a/beos/beos_font.cpp b/beos/beos_font.cpp index 9f7ed34f9..ef2f1dbdb 100644 --- a/beos/beos_font.cpp +++ b/beos/beos_font.cpp @@ -42,13 +42,13 @@ extern "C" { #include "beos/beos_font.h" #include "beos/beos_plotters.h" -static bool nsfont_width(const struct css_style *style, +static bool nsfont_width(const plot_font_style_t *fstyle, const char *string, size_t length, int *width); -static bool nsfont_position_in_string(const struct css_style *style, +static bool nsfont_position_in_string(const plot_font_style_t *fstyle, const char *string, size_t length, int x, size_t *char_offset, int *actual_x); -static bool nsfont_split(const struct css_style *style, +static bool nsfont_split(const plot_font_style_t *fstyle, const char *string, size_t length, int x, size_t *char_offset, int *actual_x); @@ -62,15 +62,14 @@ const struct font_functions nsfont = { /** * Measure the width of a string. * - * \param style css_style for this text, with style->font_size.size == - * CSS_FONT_SIZE_LENGTH + * \param fstyle style for this text * \param string UTF-8 string to measure * \param length length of string * \param width updated to width of string[0..length) * \return true on success, false on error and error reported */ -bool nsfont_width(const struct css_style *style, +bool nsfont_width(const plot_font_style_t *fstyle, const char *string, size_t length, int *width) { @@ -82,7 +81,7 @@ bool nsfont_width(const struct css_style *style, return true; } - nsbeos_style_to_font(font, style); + nsbeos_style_to_font(font, fstyle); *width = (int)font.StringWidth(string, length); return true; } @@ -113,8 +112,7 @@ static int utf8_char_len(const char *c) /** * Find the position in a string where an x coordinate falls. * - * \param style css_style for this text, with style->font_size.size == - * CSS_FONT_SIZE_LENGTH + * \param fstyle style for this text * \param string UTF-8 string to measure * \param length length of string * \param x x coordinate to search for @@ -123,7 +121,7 @@ static int utf8_char_len(const char *c) * \return true on success, false on error and error reported */ -bool nsfont_position_in_string(const struct css_style *style, +bool nsfont_position_in_string(const plot_font_style_t *fstyle, const char *string, size_t length, int x, size_t *char_offset, int *actual_x) { @@ -132,7 +130,7 @@ bool nsfont_position_in_string(const struct css_style *style, int index; BFont font; - nsbeos_style_to_font(font, style); + nsbeos_style_to_font(font, fstyle); BString str(string); int32 len = str.CountChars(); float escapements[len]; @@ -159,8 +157,7 @@ bool nsfont_position_in_string(const struct css_style *style, /** * Find where to split a string to make it fit a width. * - * \param style css_style for this text, with style->font_size.size == - * CSS_FONT_SIZE_LENGTH + * \param fstyle style for this text * \param string UTF-8 string to measure * \param length length of string * \param x width available @@ -173,7 +170,7 @@ bool nsfont_position_in_string(const struct css_style *style, * char_offset == length] */ -bool nsfont_split(const struct css_style *style, +bool nsfont_split(const plot_font_style_t *fstyle, const char *string, size_t length, int x, size_t *char_offset, int *actual_x) { @@ -182,7 +179,7 @@ bool nsfont_split(const struct css_style *style, int index = 0; BFont font; - nsbeos_style_to_font(font, style); + nsbeos_style_to_font(font, fstyle); BString str(string); int32 len = str.CountChars(); float escapements[len]; @@ -217,8 +214,7 @@ bool nsfont_split(const struct css_style *style, /** * Render a string. * - * \param style css_style for this text, with style->font_size.size == - * CSS_FONT_SIZE_LENGTH + * \param fstyle style for this text * \param string UTF-8 string to measure * \param length length of string * \param x x coordinate @@ -227,7 +223,7 @@ bool nsfont_split(const struct css_style *style, * \return true on success, false on error and error reported */ -bool nsfont_paint(const struct css_style *style, +bool nsfont_paint(const plot_font_style_t *fstyle, const char *string, size_t length, int x, int y, colour bg, colour c) { @@ -243,7 +239,7 @@ bool nsfont_paint(const struct css_style *style, if (length == 0) return true; - nsbeos_style_to_font(font, style); + nsbeos_style_to_font(font, fstyle); background = nsbeos_rgb_colour(bg); foreground = nsbeos_rgb_colour(c); @@ -287,77 +283,59 @@ bool nsfont_paint(const struct css_style *style, /** - * Convert a css_style to a PangoFontDescription. + * Convert a font style to a PangoFontDescription. * - * \param style css_style for this text, with style->font_size.size == - * CSS_FONT_SIZE_LENGTH + * \param fstyle style for this text * \return a new Pango font description */ -void nsbeos_style_to_font(BFont &font, - const struct css_style *style) +void nsbeos_style_to_font(BFont &font, const plot_font_style_t *style) { float size; uint16 face = 0; const char *family; - assert(style->font_size.size == CSS_FONT_SIZE_LENGTH); - - switch (style->font_family) { - case CSS_FONT_FAMILY_SERIF: + switch (fstyle->family) { + case PLOT_FONT_FAMILY_SERIF: family = option_font_serif; break; - case CSS_FONT_FAMILY_MONOSPACE: + case PLOT_FONT_FAMILY_MONOSPACE: family = option_font_mono; break; - case CSS_FONT_FAMILY_CURSIVE: + case PLOT_FONT_FAMILY_CURSIVE: family = option_font_cursive; break; - case CSS_FONT_FAMILY_FANTASY: + case PLOT_FONT_FAMILY_FANTASY: family = option_font_fantasy; break; - case CSS_FONT_FAMILY_SANS_SERIF: + case PLOT_FONT_FAMILY_SANS_SERIF: default: family = option_font_sans; break; } - - switch (style->font_style) { - case CSS_FONT_STYLE_ITALIC: + if ((fstyle->flags & FONTF_ITALIC)) { face = B_ITALIC_FACE; - break; - case CSS_FONT_STYLE_OBLIQUE: + } else if ((fstyle->flags & FONTF_OBLIQUE)) { face = B_ITALIC_FACE; // XXX: no OBLIQUE flag ?? // maybe find "Oblique" style // or use SetShear() ? - break; - default: - break; } - switch (style->font_weight) { - case CSS_FONT_WEIGHT_NORMAL: - break; - case CSS_FONT_WEIGHT_BOLD: - case CSS_FONT_WEIGHT_600: - case CSS_FONT_WEIGHT_700: #ifndef __HAIKU__XXX - case CSS_FONT_WEIGHT_800: - case CSS_FONT_WEIGHT_900: -#endif - face |= B_BOLD_FACE; break; -#ifdef __HAIKU__XXX - case CSS_FONT_WEIGHT_BOLDER: - case CSS_FONT_WEIGHT_800: - case CSS_FONT_WEIGHT_900: - face |= B_HEAVY_FACE; break; - case CSS_FONT_WEIGHT_100: - case CSS_FONT_WEIGHT_200: - case CSS_FONT_WEIGHT_300: - case CSS_FONT_WEIGHT_LIGHTER: - face |= B_LIGHT_FACE; break; + if (fstyle->weight >= 600) { + face |= B_BOLD_FACE; + } +#else + if (fstyle->weight >= 600) { + if (fstyle->weight >= 800) + face |= B_HEAVY_FACE; + else + face |= B_BOLD_FACE; + } else if (fstyle->weight <= 300) { + face |= B_LIGHT_FACE; + } #endif /* case CSS_FONT_WEIGHT_100: weight = 100; break; @@ -387,11 +365,7 @@ void nsbeos_style_to_font(BFont &font, } //fprintf(stderr, "nsbeos_style_to_font: value %f unit %d\n", style->font_size.value.length.value, style->font_size.value.length.unit); - if (style->font_size.value.length.unit == CSS_UNIT_PT) - size = style->font_size.value.length.value; - else - size = css_len2pt(&style->font_size.value.length, style); - // * 72.0 / 90.0; + size = fstyle->size; //XXX: pango stuff ? if (size < abs(option_font_min_size / 10)) diff --git a/beos/beos_font.h b/beos/beos_font.h index 2dab57e3d..aefd898da 100644 --- a/beos/beos_font.h +++ b/beos/beos_font.h @@ -22,12 +22,10 @@ #include <stdbool.h> +#include "desktop/plotters.h" -struct css_style; - -bool nsfont_paint(const struct css_style *style, +bool nsfont_paint(const plot_font_style_t *fstyle, const char *string, size_t length, - int x, int y, colour bg, colour c); + int x, int y); -void nsbeos_style_to_font(BFont &font, - const struct css_style *style); +void nsbeos_style_to_font(BFont &font, const plot_font_style_t *fstyle); diff --git a/beos/beos_plotters.cpp b/beos/beos_plotters.cpp index 17534dc31..d7e971528 100644 --- a/beos/beos_plotters.cpp +++ b/beos/beos_plotters.cpp @@ -68,8 +68,8 @@ static bool nsbeos_plot_path(const float *p, unsigned int n, colour fill, float colour c, const float transform[6]); static bool nsbeos_plot_clip(int clip_x0, int clip_y0, int clip_x1, int clip_y1); -static bool nsbeos_plot_text(int x, int y, const struct css_style *style, - const char *text, size_t length, colour bg, colour c); +static bool nsbeos_plot_text(int x, int y, const char *text, size_t length, + const plot_font_style_t *fstyle); static bool nsbeos_plot_disc(int x, int y, int radius, const plot_style_t *style); static bool nsbeos_plot_arc(int x, int y, int radius, int angle1, int angle2, const plot_style_t *style); @@ -394,10 +394,10 @@ bool nsbeos_plot_clip(int clip_x0, int clip_y0, } -bool nsbeos_plot_text(int x, int y, const struct css_style *style, - const char *text, size_t length, colour bg, colour c) +bool nsbeos_plot_text(int x, int y, const char *text, size_t length, + const plot_font_style_t *fstyle) { - return nsfont_paint(style, text, length, x, y, bg, c); + return nsfont_paint(fstyle, text, length, x, y, bg); } |