From 5c567d4f2034ac227350b2d72647cd0d37ebee68 Mon Sep 17 00:00:00 2001 From: Vincent Sanders Date: Sun, 24 Apr 2016 20:17:52 +0100 Subject: update beos to use font layout table --- beos/font.cpp | 228 +++++++++++++++++++++++++++++----------------------------- beos/font.h | 4 +- beos/gui.cpp | 7 +- 3 files changed, 120 insertions(+), 119 deletions(-) (limited to 'beos') diff --git a/beos/font.cpp b/beos/font.cpp index cba3e4d4b..cb4d3e6c9 100644 --- a/beos/font.cpp +++ b/beos/font.cpp @@ -30,33 +30,113 @@ #include #include #include + extern "C" { -#include "desktop/font.h" #include "utils/utils.h" #include "utils/log.h" #include "utils/nsoption.h" #include "utils/nsurl.h" + +#include "desktop/gui_layout.h" } #include "beos/gui.h" #include "beos/font.h" #include "beos/plotters.h" -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 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 plot_font_style_t *fstyle, - const char *string, size_t length, - int x, size_t *char_offset, int *actual_x); -const struct font_functions nsfont = { - nsfont_width, - nsfont_position_in_string, - nsfont_split -}; +/** + * Convert a font style to a PangoFontDescription. + * + * \param font Beos font object. + * \param fstyle style for this text + */ +void nsbeos_style_to_font(BFont &font, const struct plot_font_style *fstyle) +{ + float size; + uint16 face = 0; + const char *family; + + switch (fstyle->family) { + case PLOT_FONT_FAMILY_SERIF: + family = nsoption_charp(font_serif); + break; + case PLOT_FONT_FAMILY_MONOSPACE: + family = nsoption_charp(font_mono); + break; + case PLOT_FONT_FAMILY_CURSIVE: + family = nsoption_charp(font_cursive); + break; + case PLOT_FONT_FAMILY_FANTASY: + family = nsoption_charp(font_fantasy); + break; + case PLOT_FONT_FAMILY_SANS_SERIF: + default: + family = nsoption_charp(font_sans); + break; + } + + if ((fstyle->flags & FONTF_ITALIC)) { + face = B_ITALIC_FACE; + } else if ((fstyle->flags & FONTF_OBLIQUE)) { + face = B_ITALIC_FACE; + // XXX: no OBLIQUE flag ?? + // maybe find "Oblique" style + // or use SetShear() ? + } + +#ifndef __HAIKU__XXX + 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; + case CSS_FONT_WEIGHT_200: weight = 200; break; + case CSS_FONT_WEIGHT_300: weight = 300; break; + case CSS_FONT_WEIGHT_400: weight = 400; break; + case CSS_FONT_WEIGHT_500: weight = 500; break; + case CSS_FONT_WEIGHT_600: weight = 600; break; + case CSS_FONT_WEIGHT_700: weight = 700; break; + case CSS_FONT_WEIGHT_800: weight = 800; break; + case CSS_FONT_WEIGHT_900: weight = 900; break; +*/ + + if (!face) + face = B_REGULAR_FACE; + +//fprintf(stderr, "nsbeos_style_to_font: %d, %d, %d -> '%s' %04x\n", style->font_family, style->font_style, style->font_weight, family, face); + + if (family) { + font_family beos_family; + + strncpy(beos_family, family, B_FONT_FAMILY_LENGTH); + // Ensure it's terminated + beos_family[B_FONT_FAMILY_LENGTH] = '\0'; + + font.SetFamilyAndFace(beos_family, face); + } else { + //XXX not used + font = be_plain_font; + font.SetFace(face); + } + +//fprintf(stderr, "nsbeos_style_to_font: value %f unit %d\n", style->font_size.value.length.value, style->font_size.value.length.unit); + size = fstyle->size / FONT_SIZE_SCALE; + +//fprintf(stderr, "nsbeos_style_to_font: %f %d\n", size, style->font_size.value.length.unit); + + font.SetSize(size); +} /** @@ -68,8 +148,7 @@ const struct font_functions nsfont = { * \param width updated to width of string[0..length) * \return true on success, false on error and error reported */ - -bool nsfont_width(const plot_font_style_t *fstyle, +static nserror beos_font_width(const plot_font_style_t *fstyle, const char *string, size_t length, int *width) { @@ -78,12 +157,13 @@ bool nsfont_width(const plot_font_style_t *fstyle, if (length == 0) { *width = 0; - return true; + return NSERROR_OK; } nsbeos_style_to_font(font, fstyle); *width = (int)font.StringWidth(string, length); - return true; + + return NSERROR_OK; } @@ -93,6 +173,7 @@ static int utf8_char_len(const char *c) uint8 m = 0xE0; uint8 v = 0xC0; int i; + if (!*p) return 0; if ((*p & 0x80) == 0) @@ -120,8 +201,7 @@ static int utf8_char_len(const char *c) * \param actual_x updated to x coordinate of character closest to x * \return true on success, false on error and error reported */ - -bool nsfont_position_in_string(const plot_font_style_t *fstyle, +static nserror beos_font_position(const plot_font_style_t *fstyle, const char *string, size_t length, int x, size_t *char_offset, int *actual_x) { @@ -137,6 +217,7 @@ bool nsfont_position_in_string(const plot_font_style_t *fstyle, float esc = 0.0; float current = 0.0; int i; + index = 0; font.GetEscapements(string, len, escapements); // slow but it should work @@ -151,7 +232,7 @@ bool nsfont_position_in_string(const plot_font_style_t *fstyle, *actual_x = (int)current; *char_offset = i; //index; - return true; + return NSERROR_OK; } @@ -177,8 +258,7 @@ bool nsfont_position_in_string(const plot_font_style_t *fstyle, * * Returning char_offset == length means no split possible */ - -bool nsfont_split(const plot_font_style_t *fstyle, +static nserror beos_font_split(const plot_font_style_t *fstyle, const char *string, size_t length, int x, size_t *char_offset, int *actual_x) { @@ -196,6 +276,7 @@ bool nsfont_split(const plot_font_style_t *fstyle, float last_x = 0.0; int i; int last_space = 0; + font.GetEscapements(string, len, escapements); // very slow but it should work for (i = 0; string[index] && i < len; i++) { @@ -215,7 +296,7 @@ bool nsfont_split(const plot_font_style_t *fstyle, *actual_x = MIN(*actual_x, (int)current); *char_offset = index; - return true; + return NSERROR_OK; } @@ -285,95 +366,10 @@ bool nsfont_paint(const plot_font_style_t *fstyle, } -/** - * Convert a font style to a PangoFontDescription. - * - * \param font Beos font object. - * \param fstyle style for this text - */ -void nsbeos_style_to_font(BFont &font, const plot_font_style_t *fstyle) -{ - float size; - uint16 face = 0; - const char *family; - - switch (fstyle->family) { - case PLOT_FONT_FAMILY_SERIF: - family = nsoption_charp(font_serif); - break; - case PLOT_FONT_FAMILY_MONOSPACE: - family = nsoption_charp(font_mono); - break; - case PLOT_FONT_FAMILY_CURSIVE: - family = nsoption_charp(font_cursive); - break; - case PLOT_FONT_FAMILY_FANTASY: - family = nsoption_charp(font_fantasy); - break; - case PLOT_FONT_FAMILY_SANS_SERIF: - default: - family = nsoption_charp(font_sans); - break; - } - - if ((fstyle->flags & FONTF_ITALIC)) { - face = B_ITALIC_FACE; - } else if ((fstyle->flags & FONTF_OBLIQUE)) { - face = B_ITALIC_FACE; - // XXX: no OBLIQUE flag ?? - // maybe find "Oblique" style - // or use SetShear() ? - } - -#ifndef __HAIKU__XXX - 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; - case CSS_FONT_WEIGHT_200: weight = 200; break; - case CSS_FONT_WEIGHT_300: weight = 300; break; - case CSS_FONT_WEIGHT_400: weight = 400; break; - case CSS_FONT_WEIGHT_500: weight = 500; break; - case CSS_FONT_WEIGHT_600: weight = 600; break; - case CSS_FONT_WEIGHT_700: weight = 700; break; - case CSS_FONT_WEIGHT_800: weight = 800; break; - case CSS_FONT_WEIGHT_900: weight = 900; break; -*/ - - if (!face) - face = B_REGULAR_FACE; - -//fprintf(stderr, "nsbeos_style_to_font: %d, %d, %d -> '%s' %04x\n", style->font_family, style->font_style, style->font_weight, family, face); - - if (family) { - font_family beos_family; - - strncpy(beos_family, family, B_FONT_FAMILY_LENGTH); - // Ensure it's terminated - beos_family[B_FONT_FAMILY_LENGTH] = '\0'; - - font.SetFamilyAndFace(beos_family, face); - } else { - //XXX not used - font = be_plain_font; - font.SetFace(face); - } - -//fprintf(stderr, "nsbeos_style_to_font: value %f unit %d\n", style->font_size.value.length.value, style->font_size.value.length.unit); - size = fstyle->size / FONT_SIZE_SCALE; - -//fprintf(stderr, "nsbeos_style_to_font: %f %d\n", size, style->font_size.value.length.unit); +static struct gui_layout_table layout_table = { + .width = beos_font_width, + .position = beos_font_position, + .split = beos_font_split, +}; - font.SetSize(size); -} +struct gui_layout_table *beos_layout_table = &layout_table; diff --git a/beos/font.h b/beos/font.h index aefd898da..ce31929a9 100644 --- a/beos/font.h +++ b/beos/font.h @@ -28,4 +28,6 @@ bool nsfont_paint(const plot_font_style_t *fstyle, const char *string, size_t length, int x, int y); -void nsbeos_style_to_font(BFont &font, const plot_font_style_t *fstyle); +void nsbeos_style_to_font(BFont &font, const struct plot_font_style *fstyle); + +struct gui_layout_table *beos_layout_table; diff --git a/beos/gui.cpp b/beos/gui.cpp index c91cc43db..5171b211a 100644 --- a/beos/gui.cpp +++ b/beos/gui.cpp @@ -82,6 +82,7 @@ extern "C" { #include "beos/fetch_rsrc.h" #include "beos/scaffolding.h" #include "beos/bitmap.h" +#include "beos/font.h" //TODO: use resources // enable using resources instead of files @@ -989,7 +990,8 @@ int main(int argc, char** argv) NULL, /* default search */ NULL, /* default web search */ NULL, /* default low level cache persistant storage */ - beos_bitmap_table + beos_bitmap_table, + beos_layout_table }; ret = netsurf_register(&beos_table); @@ -1069,7 +1071,8 @@ int gui_init_replicant(int argc, char** argv) NULL, /* default search */ NULL, /* default web search */ NULL, /* default low level cache persistant storage */ - beos_bitmap_table + beos_bitmap_table, + beos_layout_table }; ret = netsurf_register(&beos_table); -- cgit v1.2.3