diff --git a/Makefile.sources b/Makefile.sources index 5164068da..77f97a567 100644 --- a/Makefile.sources +++ b/Makefile.sources @@ -9,7 +9,7 @@ S_CONTENT := content.c fetch.c fetchcache.c urldb.c \ fetchers/fetch_curl.c fetchers/fetch_data.c S_CSS := css.c css_enum.c parser.c ruleset.c scanner.c S_RENDER := box.c box_construct.c box_normalise.c directory.c \ - form.c html.c html_redraw.c hubbub_binding.c imagemap.c \ + font.c form.c html.c html_redraw.c hubbub_binding.c imagemap.c \ layout.c list.c loosen.c table.c textplain.c S_UTILS := base64.c filename.c hashtable.c locale.c messages.c talloc.c \ url.c utf8.c utils.c useragent.c diff --git a/amiga/font.c b/amiga/font.c index 405065dd7..6a707e512 100644 --- a/amiga/font.c +++ b/amiga/font.c @@ -36,22 +36,22 @@ #include #include "utils/utils.h" -static struct OutlineFont *of[CSS_FONT_FAMILY_NOT_SET]; -static struct OutlineFont *ofb[CSS_FONT_FAMILY_NOT_SET]; -static struct OutlineFont *ofi[CSS_FONT_FAMILY_NOT_SET]; -static struct OutlineFont *ofbi[CSS_FONT_FAMILY_NOT_SET]; +static struct OutlineFont *of[PLOT_FONT_FAMILY_COUNT]; +static struct OutlineFont *ofb[PLOT_FONT_FAMILY_COUNT]; +static struct OutlineFont *ofi[PLOT_FONT_FAMILY_COUNT]; +static struct OutlineFont *ofbi[PLOT_FONT_FAMILY_COUNT]; -struct OutlineFont *ami_open_outline_font(const struct css_style *style); +struct OutlineFont *ami_open_outline_font(const plot_font_style_t *fstyle); -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); @@ -61,13 +61,13 @@ const struct font_functions nsfont = { nsfont_split }; -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) { struct TextFont *tfont; - *width = ami_unicode_text(NULL,string,length,style,0,0,0); + *width = ami_unicode_text(NULL,string,length,fstyle,0,0); return true; } @@ -75,8 +75,7 @@ bool nsfont_width(const struct css_style *style, /** * 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 @@ -85,7 +84,7 @@ bool nsfont_width(const struct css_style *style, * \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) { @@ -103,7 +102,7 @@ bool nsfont_position_in_string(const struct css_style *style, if(utf8_to_enc(string,"UTF-16",length,(char **)&utf16) != UTF8_CONVERT_OK) return false; outf16 = utf16; - if(!(ofont = ami_open_outline_font(style))) return false; + if(!(ofont = ami_open_outline_font(fstyle))) return false; *char_offset = length; @@ -154,8 +153,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 @@ -168,7 +166,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) { @@ -185,7 +183,7 @@ bool nsfont_split(const struct css_style *style, len = utf8_bounded_length(string, length); if(utf8_to_enc((char *)string,"UTF-16",length,(char **)&utf16) != UTF8_CONVERT_OK) return false; outf16 = utf16; - if(!(ofont = ami_open_outline_font(style))) return false; + if(!(ofont = ami_open_outline_font(fstyle))) return false; *char_offset = 0; @@ -235,52 +233,42 @@ bool nsfont_split(const struct css_style *style, return true; } -struct OutlineFont *ami_open_outline_font(const struct css_style *style) +struct OutlineFont *ami_open_outline_font(const plot_font_style_t *fstyle) { struct OutlineFont *ofont; char *fontname; WORD ysize; int tstyle = 0; - switch(style->font_style) - { - case CSS_FONT_STYLE_ITALIC: - case CSS_FONT_STYLE_OBLIQUE: - tstyle += NSA_ITALIC; - break; - } + if ((fstyle->flags & FONTF_ITALIC) || (fstyle->flags & FONTF_OBLIQUE)) + tstyle += NSA_ITALIC; - switch(style->font_weight) - { - case CSS_FONT_WEIGHT_BOLD: - case CSS_FONT_WEIGHT_BOLDER: - tstyle += NSA_BOLD; - break; - } + if (fstyle->weight >= 700) + tstyle += NSA_BOLD; switch(tstyle) { case NSA_ITALIC: - if(ofi[style->font_family]) ofont = ofi[style->font_family]; - else ofont = of[style->font_family]; + if(ofi[fstyle->family]) ofont = ofi[fstyle->family]; + else ofont = of[fstyle->family]; break; case NSA_BOLD: - if(ofb[style->font_family]) ofont = ofb[style->font_family]; - else ofont = of[style->font_family]; + if(ofb[fstyle->family]) ofont = ofb[fstyle->family]; + else ofont = of[fstyle->family]; break; case NSA_BOLDITALIC: - if(ofbi[style->font_family]) ofont = ofbi[style->font_family]; - else ofont = of[style->font_family]; + if(ofbi[fstyle->family]) ofont = ofbi[fstyle->family]; + else ofont = of[fstyle->family]; break; default: - ofont = of[style->font_family]; + ofont = of[fstyle->family]; break; } - ysize = css_len2pt(&style->font_size.value.length, style); + ysize = fstyle->size; if(ysize < (option_font_min_size / 10)) ysize = option_font_min_size / 10; @@ -296,7 +284,7 @@ struct OutlineFont *ami_open_outline_font(const struct css_style *style) return NULL; } -ULONG ami_unicode_text(struct RastPort *rp,const char *string,ULONG length,const struct css_style *style,ULONG dx, ULONG dy, ULONG c) +ULONG ami_unicode_text(struct RastPort *rp,const char *string,ULONG length,const plot_font_style_t *fstyle,ULONG dx, ULONG dy) { uint16 *utf16 = NULL, *outf16 = NULL; struct OutlineFont *ofont; @@ -317,9 +305,9 @@ ULONG ami_unicode_text(struct RastPort *rp,const char *string,ULONG length,const len = utf8_bounded_length(string, length); if(utf8_to_enc(string,"UTF-16",length,(char **)&utf16) != UTF8_CONVERT_OK) return 0; outf16 = utf16; - if(!(ofont = ami_open_outline_font(style))) return 0; + if(!(ofont = ami_open_outline_font(fstyle))) return 0; - if(rp) SetRPAttrs(rp,RPTAG_APenColor,p96EncodeColor(RGBFB_A8B8G8R8,c),TAG_DONE); + if(rp) SetRPAttrs(rp,RPTAG_APenColor,p96EncodeColor(RGBFB_A8B8G8R8,fstyle->foreground),TAG_DONE); dy++; @@ -377,19 +365,19 @@ void ami_init_fonts(void) switch(option_font_default) { - case CSS_FONT_FAMILY_SANS_SERIF: + case PLOT_FONT_FAMILY_SANS_SERIF: deffont = strdup(option_font_sans); break; - case CSS_FONT_FAMILY_SERIF: + case PLOT_FONT_FAMILY_SERIF: deffont = strdup(option_font_serif); break; - case CSS_FONT_FAMILY_MONOSPACE: + case PLOT_FONT_FAMILY_MONOSPACE: deffont = strdup(option_font_mono); break; - case CSS_FONT_FAMILY_CURSIVE: + case PLOT_FONT_FAMILY_CURSIVE: deffont = strdup(option_font_cursive); break; - case CSS_FONT_FAMILY_FANTASY: + case PLOT_FONT_FAMILY_FANTASY: deffont = strdup(option_font_fantasy); break; default: @@ -397,15 +385,13 @@ void ami_init_fonts(void) break; } - of[CSS_FONT_FAMILY_SANS_SERIF] = OpenOutlineFont(option_font_sans,NULL,OFF_OPEN); - of[CSS_FONT_FAMILY_SERIF] = OpenOutlineFont(option_font_serif,NULL,OFF_OPEN); - of[CSS_FONT_FAMILY_MONOSPACE] = OpenOutlineFont(option_font_mono,NULL,OFF_OPEN); - of[CSS_FONT_FAMILY_CURSIVE] = OpenOutlineFont(option_font_cursive,NULL,OFF_OPEN); - of[CSS_FONT_FAMILY_FANTASY] = OpenOutlineFont(option_font_fantasy,NULL,OFF_OPEN); - of[CSS_FONT_FAMILY_UNKNOWN] = OpenOutlineFont(deffont,NULL,OFF_OPEN); - of[CSS_FONT_FAMILY_NOT_SET] = OpenOutlineFont(deffont,NULL,OFF_OPEN); + of[PLOT_FONT_FAMILY_SANS_SERIF] = OpenOutlineFont(option_font_sans,NULL,OFF_OPEN); + of[PLOT_FONT_FAMILY_SERIF] = OpenOutlineFont(option_font_serif,NULL,OFF_OPEN); + of[PLOT_FONT_FAMILY_MONOSPACE] = OpenOutlineFont(option_font_mono,NULL,OFF_OPEN); + of[PLOT_FONT_FAMILY_CURSIVE] = OpenOutlineFont(option_font_cursive,NULL,OFF_OPEN); + of[PLOT_FONT_FAMILY_FANTASY] = OpenOutlineFont(option_font_fantasy,NULL,OFF_OPEN); - for(i=CSS_FONT_FAMILY_SANS_SERIF;i<=CSS_FONT_FAMILY_NOT_SET;i++) + for(i=PLOT_FONT_FAMILY_SANS_SERIF;i<=PLOT_FONT_FAMILY_FANTASY;i++) { if(!of[i]) warn_user("FontError",""); // temporary error message @@ -443,7 +429,7 @@ void ami_close_fonts(void) { int i=0; - for(i=CSS_FONT_FAMILY_SANS_SERIF;i<=CSS_FONT_FAMILY_NOT_SET;i++) + for(i=PLOT_FONT_FAMILY_SANS_SERIF;i<=PLOT_FONT_FAMILY_FANTASY;i++) { if(of[i]) CloseOutlineFont(of[i],NULL); if(ofb[i]) CloseOutlineFont(ofb[i],NULL); diff --git a/amiga/font.h b/amiga/font.h index 151d10d91..e62be85a4 100755 --- a/amiga/font.h +++ b/amiga/font.h @@ -19,7 +19,7 @@ #ifndef AMIGA_FONT_H #define AMIGA_FONT_H -#include "css/css.h" +#include "desktop/plotters.h" #include #define NSA_NORMAL 0 @@ -27,9 +27,8 @@ #define NSA_BOLD 2 #define NSA_BOLDITALIC 3 -struct TextFont *ami_open_font(struct css_style *); void ami_close_font(struct TextFont *tfont); -ULONG ami_unicode_text(struct RastPort *rp,const char *string,ULONG length,const struct css_style *style,ULONG x,ULONG y,ULONG c); +ULONG ami_unicode_text(struct RastPort *rp,const char *string,ULONG length,const plot_font_style_t *fstyle,ULONG x,ULONG y); void ami_init_fonts(void); void ami_close_fonts(void); diff --git a/amiga/gui_options.c b/amiga/gui_options.c index 237683b56..26ec05a23 100755 --- a/amiga/gui_options.c +++ b/amiga/gui_options.c @@ -791,7 +791,7 @@ void ami_gui_opts_open(void) GA_RelVerify, TRUE, CHOOSER_PopUp, TRUE, CHOOSER_LabelArray, fontopts, - CHOOSER_Selected, option_font_default - CSS_FONT_FAMILY_SANS_SERIF, + CHOOSER_Selected, option_font_default - PLOT_FONT_FAMILY_SANS_SERIF, ChooserEnd, CHILD_Label, LabelObject, LABEL_Text, gadlab[GID_OPTS_FONT_DEFAULT], @@ -1301,7 +1301,7 @@ void ami_gui_opts_use(void) option_font_fantasy = (char *)strdup((char *)tattr->ta_Name); GetAttr(CHOOSER_Selected,gow->gadgets[GID_OPTS_FONT_DEFAULT],(ULONG *)&option_font_default); - option_font_default += CSS_FONT_FAMILY_SANS_SERIF; + option_font_default += PLOT_FONT_FAMILY_SANS_SERIF; GetAttr(INTEGER_Number,gow->gadgets[GID_OPTS_FONT_SIZE],(ULONG *)&option_font_size); option_font_size *= 10; diff --git a/amiga/plotters.c b/amiga/plotters.c index f2ae1cc4e..adbdf39e2 100755 --- a/amiga/plotters.c +++ b/amiga/plotters.c @@ -400,10 +400,10 @@ bool ami_clip(int x0, int y0, int x1, int y1) return true; } -bool ami_text(int x, int y, const struct css_style *style, - const char *text, size_t length, colour bg, colour c) +bool ami_text(int x, int y, const char *text, size_t length, + const plot_font_style_t *fstyle) { - ami_unicode_text(&glob->rp,text,length,style,x,y,c); + ami_unicode_text(&glob->rp,text,length,fstyle,x,y); return true; } diff --git a/amiga/plotters.h b/amiga/plotters.h index ce5008d86..fb0583e2f 100755 --- a/amiga/plotters.h +++ b/amiga/plotters.h @@ -46,8 +46,8 @@ bool ami_rectangle(int x0, int y0, int x1, int y1, const plot_style_t *style); bool ami_line(int x0, int y0, int x1, int y1, const plot_style_t *style); bool ami_polygon(const int *p, unsigned int n, const plot_style_t *style); bool ami_clip(int x0, int y0, int x1, int y1); -bool ami_text(int x, int y, const struct css_style *style, - const char *text, size_t length, colour bg, colour c); +bool ami_text(int x, int y, const char *text, size_t length, + const plot_font_style_t *fstyle); bool ami_disc(int x, int y, int radius, const plot_style_t *style); bool ami_arc(int x, int y, int radius, int angle1, int angle2, const plot_style_t *style); 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 +#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); } diff --git a/desktop/browser.c b/desktop/browser.c index 9185eff51..b188316ea 100644 --- a/desktop/browser.c +++ b/desktop/browser.c @@ -1405,6 +1405,7 @@ void browser_window_mouse_action_html(struct browser_window *bw, struct form_control *gadget = 0; struct content *object = NULL; struct box *next_box; + plot_font_style_t fstyle; bw->drag_type = DRAGGING_NONE; bw->scrolling_box = NULL; @@ -1554,7 +1555,10 @@ void browser_window_mouse_action_html(struct browser_window *bw, int pixel_offset; size_t idx; - nsfont.font_position_in_string(text_box->style, + font_plot_style_from_css(text_box->style, + &fstyle); + + nsfont.font_position_in_string(&fstyle, text_box->text, text_box->length, x - gadget_box_x - text_box->x, @@ -1596,7 +1600,10 @@ void browser_window_mouse_action_html(struct browser_window *bw, BROWSER_MOUSE_DRAG_2)) selection_init(bw->sel, gadget_box); - nsfont.font_position_in_string(text_box->style, + font_plot_style_from_css(text_box->style, + &fstyle); + + nsfont.font_position_in_string(&fstyle, text_box->text, text_box->length, x - gadget_box_x - text_box->x, @@ -1694,7 +1701,10 @@ void browser_window_mouse_action_html(struct browser_window *bw, int pixel_offset; size_t idx; - nsfont.font_position_in_string(text_box->style, + font_plot_style_from_css(text_box->style, + &fstyle); + + nsfont.font_position_in_string(&fstyle, text_box->text, text_box->length, x - text_box_x, @@ -1972,7 +1982,11 @@ void browser_window_mouse_track_html(struct browser_window *bw, if (box) { int pixel_offset; size_t idx; - nsfont.font_position_in_string(box->style, + plot_font_style_t fstyle; + + font_plot_style_from_css(box->style, &fstyle); + + nsfont.font_position_in_string(&fstyle, box->text, box->length, dx, &idx, &pixel_offset); @@ -2052,8 +2066,14 @@ void browser_window_mouse_drag_end(struct browser_window *bw, box = browser_window_pick_text_box(bw, x, y, dir, &dx, &dy); if (box) { + plot_font_style_t fstyle; + + font_plot_style_from_css( + box->style, + &fstyle); + nsfont.font_position_in_string( - box->style, + &fstyle, box->text, box->length, dx, diff --git a/desktop/history_core.c b/desktop/history_core.c index a40d746bd..4a30d1783 100644 --- a/desktop/history_core.c +++ b/desktop/history_core.c @@ -633,6 +633,7 @@ bool history_redraw_entry(struct history *history, .stroke_colour = c, .stroke_width = entry == history->current ? 2 : 1, }; + plot_font_style_t fstyle = *plot_style_font; if (clip) { if(!plot.clip(x0 + xoffset, y0 + yoffset, x1 + xoffset, y1 + yoffset)) @@ -649,12 +650,16 @@ bool history_redraw_entry(struct history *history, &pstyle_history_rect)) return false; - if (!nsfont.font_position_in_string(&css_base_style, entry->page.title, + if (!nsfont.font_position_in_string(plot_style_font, entry->page.title, strlen(entry->page.title), WIDTH, &char_offset, &actual_x)) return false; + + fstyle.background = 0xffffff; + fstyle.foreground = c; + if (!plot.text(entry->x + xoffset, entry->y + HEIGHT + 12 + yoffset, - &css_base_style, entry->page.title, char_offset, 0xffffff, c)) + entry->page.title, char_offset, &fstyle)) return false; for (child = entry->forward; child; child = child->next) { diff --git a/desktop/knockout.c b/desktop/knockout.c index b9a6862e5..680257b0f 100644 --- a/desktop/knockout.c +++ b/desktop/knockout.c @@ -90,8 +90,8 @@ static bool knockout_plot_polygon(const int *p, unsigned int n, const plot_style static bool knockout_plot_rectangle(int x0, int y0, int x1, int y1, const plot_style_t *plot_style); static bool knockout_plot_clip(int clip_x0, int clip_y0, int clip_x1, int clip_y1); -static bool knockout_plot_text(int x, int y, const struct css_style *style, - const char *text, size_t length, colour bg, colour c); +static bool knockout_plot_text(int x, int y, const char *text, size_t length, + const plot_font_style_t *fstyle); static bool knockout_plot_disc(int x, int y, int radius, const plot_style_t *pstyle); static bool knockout_plot_arc(int x, int y, int radius, int angle1, int angle2, const plot_style_t *pstyle); static bool knockout_plot_bitmap(int x, int y, int width, int height, @@ -188,11 +188,9 @@ struct knockout_entry { struct { int x; int y; - const struct css_style *style; const char *text; size_t length; - colour bg; - colour c; + plot_font_style_t font_style; } text; struct { int x; @@ -350,11 +348,9 @@ bool knockout_plot_flush(void) success &= plot.text( knockout_entries[i].data.text.x, knockout_entries[i].data.text.y, - knockout_entries[i].data.text.style, knockout_entries[i].data.text.text, knockout_entries[i].data.text.length, - knockout_entries[i].data.text.bg, - knockout_entries[i].data.text.c); + &knockout_entries[i].data.text.font_style); break; case KNOCKOUT_PLOT_DISC: success &= plot.disc( @@ -737,16 +733,14 @@ bool knockout_plot_clip(int clip_x0, int clip_y0, } -bool knockout_plot_text(int x, int y, const struct css_style *style, - const char *text, size_t length, colour bg, colour c) +bool knockout_plot_text(int x, int y, const char *text, size_t length, + const plot_font_style_t *fstyle) { knockout_entries[knockout_entry_cur].data.text.x = x; knockout_entries[knockout_entry_cur].data.text.y = y; - knockout_entries[knockout_entry_cur].data.text.style = style; knockout_entries[knockout_entry_cur].data.text.text = text; knockout_entries[knockout_entry_cur].data.text.length = length; - knockout_entries[knockout_entry_cur].data.text.bg = bg; - knockout_entries[knockout_entry_cur].data.text.c = c; + knockout_entries[knockout_entry_cur].data.text.font_style = *fstyle; knockout_entries[knockout_entry_cur].type = KNOCKOUT_PLOT_TEXT; if (++knockout_entry_cur >= KNOCKOUT_ENTRIES) knockout_plot_flush(); diff --git a/desktop/options.c b/desktop/options.c index 28cdecf3c..e885174a4 100644 --- a/desktop/options.c +++ b/desktop/options.c @@ -36,6 +36,7 @@ #include "content/urldb.h" #include "css/css.h" #include "desktop/options.h" +#include "desktop/plot_style.h" #include "desktop/tree.h" #include "utils/log.h" #include "utils/messages.h" @@ -103,7 +104,7 @@ bool option_animate_images = true; /** How many days to retain URL data for */ int option_expire_url = 28; /** Default font family */ -int option_font_default = CSS_FONT_FAMILY_SANS_SERIF; +int option_font_default = PLOT_FONT_FAMILY_SANS_SERIF; /** ca-bundle location */ char *option_ca_bundle = 0; /** ca-path location */ diff --git a/desktop/plot_style.c b/desktop/plot_style.c index fa94076e8..54dbd40ce 100644 --- a/desktop/plot_style.c +++ b/desktop/plot_style.c @@ -137,3 +137,14 @@ static plot_style_t plot_style_stroke_history_static = { }; plot_style_t *plot_style_stroke_history = &plot_style_stroke_history_static; +/* Generic font style */ +static const plot_font_style_t plot_style_font_static = { + .family = PLOT_FONT_FAMILY_SANS_SERIF, + .size = 10, + .weight = 400, + .flags = FONTF_NONE, + .background = 0xffffff, + .foreground = 0x000000, +}; +plot_font_style_t const * const plot_style_font = &plot_style_font_static; + diff --git a/desktop/plot_style.h b/desktop/plot_style.h index 76843fad4..3b74a4efd 100644 --- a/desktop/plot_style.h +++ b/desktop/plot_style.h @@ -17,7 +17,7 @@ */ /** \file - * Ploter styles. + * Plotter styles. */ #ifndef _NETSURF_DESKTOP_PLOT_STYLE_H_ @@ -27,27 +27,27 @@ #define WIDGET_BASEC 0xd9d9d9 #define WIDGET_BLOBC 0x000000 -/* Darken a colour by taking three quaters of each channels intensity */ +/* Darken a colour by taking three quarters of each channel's intensity */ #define darken_colour(c1) \ ((((3 * (c1 >> 16)) >> 2) << 16) | \ (((3 * ((c1 >> 8) & 0xff)) >> 2) << 8) | \ (((3 * (c1 & 0xff)) >> 2) << 0)) -/* Darken a colour by taking nine sixteenths of each channels intensity */ +/* Darken a colour by taking nine sixteenths of each channel's intensity */ #define double_darken_colour(c1) \ ((((9 * (c1 >> 16)) >> 4) << 16) | \ (((9 * ((c1 >> 8) & 0xff)) >> 4) << 8) | \ (((9 * (c1 & 0xff)) >> 4) << 0)) -/* Lighten a colour by taking three quaters of each channels intensity - * and adding a full quater +/* Lighten a colour by taking three quarters of each channel's intensity + * and adding a full quarter */ #define lighten_colour(c1) \ (((((3 * (c1 >> 16)) >> 2) + 64) << 16) | \ ((((3 * ((c1 >> 8) & 0xff)) >> 2) + 64) << 8) | \ ((((3 * (c1 & 0xff)) >> 2) + 64) << 0)) -/* Lighten a colour by taking nine sixteenths of each channels intensity and +/* Lighten a colour by taking nine sixteenths of each channel's intensity and * adding a full intensity 7/16ths */ #define double_lighten_colour(c1) \ (((((9 * (c1 >> 16)) >> 4) + 112) << 16) | \ @@ -62,21 +62,60 @@ (((((c0 >> 8) & 0xff) + ((c1 >> 8) & 0xff)) >> 1) << 8) | \ ((((c0 & 0xff) + (c1 & 0xff)) >> 1) << 0) +/** + * Type of plot operation + */ typedef enum { - PLOT_OP_TYPE_NONE = 0, /**< No operation */ - PLOT_OP_TYPE_SOLID, /**< Solid colour */ - PLOT_OP_TYPE_DOT, /**< Doted plot */ - PLOT_OP_TYPE_DASH, /**< dashed plot */ + PLOT_OP_TYPE_NONE = 0, /**< No operation */ + PLOT_OP_TYPE_SOLID, /**< Solid colour */ + PLOT_OP_TYPE_DOT, /**< Dotted plot */ + PLOT_OP_TYPE_DASH, /**< Dashed plot */ } plot_operation_type_t; +/** + * Plot style for stroke/fill plotters + */ typedef struct { - plot_operation_type_t stroke_type; - int stroke_width; - colour stroke_colour; - plot_operation_type_t fill_type; - colour fill_colour; + plot_operation_type_t stroke_type; /**< Stroke plot type */ + int stroke_width; /**< Width of stroke, in pixels */ + colour stroke_colour; /**< Colour of stroke */ + plot_operation_type_t fill_type; /**< Fill plot type */ + colour fill_colour; /**< Colour of fill */ } plot_style_t; +/** + * Generic font family type + */ +typedef enum { + PLOT_FONT_FAMILY_SANS_SERIF = 0, + PLOT_FONT_FAMILY_SERIF, + PLOT_FONT_FAMILY_MONOSPACE, + PLOT_FONT_FAMILY_CURSIVE, + PLOT_FONT_FAMILY_FANTASY, + PLOT_FONT_FAMILY_COUNT /**< Number of generic families */ +} plot_font_generic_family_t; + +/** + * Font plot flags + */ +typedef unsigned long plot_font_flags_t; +#define FONTF_NONE 0 +#define FONTF_ITALIC 1 +#define FONTF_OBLIQUE 2 +#define FONTF_SMALLCAPS 4 + +/** + * Font style for plotting + */ +typedef struct { + plot_font_generic_family_t family; /**< Generic family to plot with */ + int size; /**< Font size, in points */ + int weight; /**< Font weight: value in range [100,900] as per CSS */ + plot_font_flags_t flags; /**< Font flags */ + colour background; /**< Background colour to blend to, if appropriate */ + colour foreground; /**< Colour of text */ +} plot_font_style_t; + /* global fill styles */ extern plot_style_t *plot_style_fill_white; extern plot_style_t *plot_style_fill_red; @@ -98,4 +137,7 @@ extern plot_style_t *plot_style_stroke_wblobc; extern plot_style_t *plot_style_stroke_darkwbasec; extern plot_style_t *plot_style_stroke_lightwbasec; +/* Default font style */ +extern plot_font_style_t const * const plot_style_font; + #endif diff --git a/desktop/plotters.h b/desktop/plotters.h index 91fbd5188..4edec321b 100644 --- a/desktop/plotters.h +++ b/desktop/plotters.h @@ -115,8 +115,8 @@ struct plotter_table { bitmap_flags_t flags); /* text */ - bool (*text)(int x, int y, const struct css_style *style, - const char *text, size_t length, colour bg, colour c); + bool (*text)(int x, int y, const char *text, size_t length, + const plot_font_style_t *fstyle); /* optional callbacks */ bool (*group_start)(const char *name); /**< optional, may be NULL */ diff --git a/desktop/save_pdf/font_haru.c b/desktop/save_pdf/font_haru.c index 2cab2c909..faed7c168 100644 --- a/desktop/save_pdf/font_haru.c +++ b/desktop/save_pdf/font_haru.c @@ -47,15 +47,15 @@ static bool haru_nsfont_init(HPDF_Doc *pdf, HPDF_Page *page, const char *string, char **string_nt, int length); -static bool haru_nsfont_width(const struct css_style *style, +static bool haru_nsfont_width(const plot_font_style_t *fstyle, const char *string, size_t length, int *width); -static bool haru_nsfont_position_in_string(const struct css_style *style, +static bool haru_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 haru_nsfont_split(const struct css_style *style, +static bool haru_nsfont_split(const plot_font_style_t *fstyle, const char *string, size_t length, int x, size_t *char_offset, int *actual_x); @@ -113,14 +113,13 @@ static bool haru_nsfont_init(HPDF_Doc *pdf, HPDF_Page *page, /** * 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 string to measure (no UTF-8 currently) * \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 haru_nsfont_width(const struct css_style *style, +bool haru_nsfont_width(const plot_font_style_t *fstyle, const char *string, size_t length, int *width) { @@ -137,7 +136,7 @@ bool haru_nsfont_width(const struct css_style *style, if (!haru_nsfont_init(&pdf, &page, string, &string_nt, length)) return false; - if (!haru_nsfont_apply_style(style, pdf, page, NULL, NULL)) { + if (!haru_nsfont_apply_style(fstyle, pdf, page, NULL, NULL)) { free(string_nt); HPDF_Free(pdf); return false; @@ -159,8 +158,7 @@ bool haru_nsfont_width(const struct css_style *style, /** * 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 string to measure (no UTF-8 currently) * \param length length of string * \param x x coordinate to search for @@ -169,7 +167,7 @@ bool haru_nsfont_width(const struct css_style *style, * \return true on success, false on error and error reported */ -bool haru_nsfont_position_in_string(const struct css_style *style, +bool haru_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) { @@ -183,7 +181,7 @@ bool haru_nsfont_position_in_string(const struct css_style *style, return false; if (HPDF_Page_SetWidth(page, x) != HPDF_OK - || !haru_nsfont_apply_style(style, pdf, page, NULL, NULL)) { + || !haru_nsfont_apply_style(fstyle, pdf, page, NULL, NULL)) { free(string_nt); HPDF_Free(pdf); return false; @@ -218,7 +216,7 @@ bool haru_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 == + * \param fstyle css_style for this text, with style->font_size.size == * CSS_FONT_SIZE_LENGTH * \param string string to measure (no UTF-8 currently) * \param length length of string @@ -228,7 +226,7 @@ bool haru_nsfont_position_in_string(const struct css_style *style, * \return true on success, false on error and error reported */ -bool haru_nsfont_split(const struct css_style *style, +bool haru_nsfont_split(const plot_font_style_t *fstyle, const char *string, size_t length, int x, size_t *char_offset, int *actual_x) { @@ -243,7 +241,7 @@ bool haru_nsfont_split(const struct css_style *style, return false; if (HPDF_Page_SetWidth(page, x) != HPDF_OK - || !haru_nsfont_apply_style(style, pdf, page, NULL, NULL)) { + || !haru_nsfont_apply_style(fstyle, pdf, page, NULL, NULL)) { free(string_nt); HPDF_Free(pdf); return false; @@ -268,77 +266,67 @@ bool haru_nsfont_split(const struct css_style *style, } /** - * Apply css_style to a Haru HPDF_Page + * Apply font style to a Haru HPDF_Page * - * \param style css_style for this page, with style->font_size.size == - * CSS_FONT_SIZE_LENGTH + * \param style plot style for this page * \param doc document owning the page * \param page the page to apply the style to * \param font if this is non NULL it is updated to the font based - * on given CSS style style + * on given style * \param font_size if this is non NULL it is updated to the font size - * based on given CSS style + * based on given style * \return true on success, false on error and error reported * * When both font and font_size are NULL, the HPDF_Page is updated for given - * CSS style, otherwise it is left to the called to do this. + * style, otherwise it is left to the called to do this. */ -bool haru_nsfont_apply_style(const struct css_style *style, +bool haru_nsfont_apply_style(const plot_font_style_t *fstyle, HPDF_Doc doc, HPDF_Page page, HPDF_Font *font, HPDF_REAL *font_size) { HPDF_Font pdf_font; HPDF_REAL size; char font_name[50]; - bool roman; - bool bold; - bool styled; - - roman = false; - bold = false; - styled = false; - + bool roman = false; + bool bold = false; + bool styled = false; + /*TODO: style handling, we are mapping the styles on the basic 14 fonts only */ - switch (style->font_family) { - case CSS_FONT_FAMILY_SERIF: - strcpy(font_name, "Times"); - roman = true; - break; - case CSS_FONT_FAMILY_MONOSPACE: - strcpy(font_name, "Courier"); - break; - case CSS_FONT_FAMILY_SANS_SERIF: - strcpy(font_name, "Helvetica"); - break; - case CSS_FONT_FAMILY_CURSIVE: - case CSS_FONT_FAMILY_FANTASY: - default: - strcpy(font_name, "Times"); - roman=true; - break; + switch (fstyle->family) { + case PLOT_FONT_FAMILY_SERIF: + strcpy(font_name, "Times"); + roman = true; + break; + case PLOT_FONT_FAMILY_MONOSPACE: + strcpy(font_name, "Courier"); + break; + case PLOT_FONT_FAMILY_SANS_SERIF: + strcpy(font_name, "Helvetica"); + break; + case PLOT_FONT_FAMILY_CURSIVE: + case PLOT_FONT_FAMILY_FANTASY: + default: + strcpy(font_name, "Times"); + roman=true; + break; } - if (style->font_weight == CSS_FONT_WEIGHT_BOLD) { + if (fstyle->weight == 700) { strcat(font_name, "-Bold"); bold = true; } - switch (style->font_style) { - case CSS_FONT_STYLE_ITALIC: - case CSS_FONT_STYLE_OBLIQUE: - if (!bold) - strcat(font_name,"-"); - if (roman) - strcat(font_name,"Italic"); - else - strcat(font_name,"Oblique"); + if ((fstyle->flags & FONTF_ITALIC) || (fstyle->flags & FONTF_OBLIQUE)) { + if (!bold) + strcat(font_name,"-"); + if (roman) + strcat(font_name,"Italic"); + else + strcat(font_name,"Oblique"); - styled = true; - break; - default: - break; + styled = true; } if (roman && !styled && !bold) @@ -347,11 +335,8 @@ bool haru_nsfont_apply_style(const struct css_style *style, #ifdef FONT_HARU_DEBUG LOG(("Setting font: %s", font_name)); #endif - - if (style->font_size.value.length.unit == CSS_UNIT_PX) - size = style->font_size.value.length.value; - else - size = css_len2pt(&style->font_size.value.length, style); + + size = fstyle->size; if (font != NULL) size *= pdf_text_scale; diff --git a/desktop/save_pdf/font_haru.h b/desktop/save_pdf/font_haru.h index c88da76c2..0dd6dc0c4 100644 --- a/desktop/save_pdf/font_haru.h +++ b/desktop/save_pdf/font_haru.h @@ -27,8 +27,9 @@ #include #include "render/font.h" +#include "desktop/plot_style.h" -bool haru_nsfont_apply_style(const struct css_style *style, +bool haru_nsfont_apply_style(const plot_font_style_t *fstyle, HPDF_Doc doc, HPDF_Page page, HPDF_Font *font, HPDF_REAL *font_size); diff --git a/desktop/save_pdf/pdf_plotters.c b/desktop/save_pdf/pdf_plotters.c index 84e0a5506..a29db2415 100644 --- a/desktop/save_pdf/pdf_plotters.c +++ b/desktop/save_pdf/pdf_plotters.c @@ -50,8 +50,8 @@ static bool pdf_plot_line(int x0, int y0, int x1, int y1, const plot_style_t *ps static bool pdf_plot_polygon(const int *p, unsigned int n, const plot_style_t *style); static bool pdf_plot_clip(int clip_x0, int clip_y0, int clip_x1, int clip_y1); -static bool pdf_plot_text(int x, int y, const struct css_style *style, - const char *text, size_t length, colour bg, colour c); +static bool pdf_plot_text(int x, int y, const char *text, size_t length, + const plot_font_style_t *fstyle); static bool pdf_plot_disc(int x, int y, int radius, const plot_style_t *style); static bool pdf_plot_arc(int x, int y, int radius, int angle1, int angle2, const plot_style_t *style); @@ -285,8 +285,8 @@ bool pdf_plot_clip(int clip_x0, int clip_y0, int clip_x1, int clip_y1) return true; } -bool pdf_plot_text(int x, int y, const struct css_style *style, - const char *text, size_t length, colour bg, colour c) +bool pdf_plot_text(int x, int y, const char *text, size_t length, + const plot_font_style_t *fstyle) { #ifdef PDF_DEBUG LOG((". %d %d %.*s", x, y, (int)length, text)); @@ -298,9 +298,10 @@ bool pdf_plot_text(int x, int y, const struct css_style *style, if (length == 0) return true; - apply_clip_and_mode(true, c, NS_TRANSPARENT, 0., DashPattern_eNone); + apply_clip_and_mode(true, fstyle->foreground, NS_TRANSPARENT, 0., + DashPattern_eNone); - haru_nsfont_apply_style(style, pdf_doc, pdf_page, &pdf_font, &size); + haru_nsfont_apply_style(fstyle, pdf_doc, pdf_page, &pdf_font, &size); pdfw_gs_font(pdf_page, pdf_font, size); /* FIXME: UTF-8 to current font encoding needs to done. Or the font diff --git a/desktop/selection.c b/desktop/selection.c index 014c44659..623caf414 100644 --- a/desktop/selection.c +++ b/desktop/selection.c @@ -609,6 +609,9 @@ bool redraw_handler(const char *text, size_t length, struct box *box, struct rdw_info *r = (struct rdw_info*)handle; int width, height, space_width; int x, y; + plot_font_style_t fstyle; + + font_plot_style_from_css(box->style, &fstyle); /* \todo - it should be possible to reduce the redrawn area by * considering the 'text', 'length' and 'space' parameters */ @@ -618,7 +621,7 @@ bool redraw_handler(const char *text, size_t length, struct box *box, height = box->padding[TOP] + box->height + box->padding[BOTTOM]; if (box->type == BOX_TEXT && box->space && - nsfont.font_width(box->style, " ", 1, &space_width)) + nsfont.font_width(&fstyle, " ", 1, &space_width)) width += space_width; if (r->inited) { diff --git a/desktop/textarea.c b/desktop/textarea.c index 4e08ff549..4832e29cf 100644 --- a/desktop/textarea.c +++ b/desktop/textarea.c @@ -96,7 +96,7 @@ struct text_area { int selection_start; /**< Character index of sel start(inclusive) */ int selection_end; /**< Character index of sel end(exclusive) */ - struct css_style *style; /**< Text style */ + plot_font_style_t fstyle; /**< Text style */ int line_count; /**< Count of lines */ #define LINE_CHUNK_SIZE 16 @@ -182,15 +182,8 @@ struct text_area *textarea_create(int x, int y, int width, int height, ret->text_alloc = 64; ret->text_len = 1; ret->text_utf8_len = 0; - - ret->style = malloc(sizeof(struct css_style)); - if (ret->style == NULL) { - LOG(("malloc failed")); - free(ret->text); - free(ret); - return NULL; - } - memcpy(ret->style, style, sizeof(struct css_style)); + + font_plot_style_from_css(style, &ret->fstyle); ret->line_height = css_len2px(&(style->line_height.value.length), style); @@ -232,7 +225,6 @@ void textarea_set_position(struct text_area *ta, int x, int y) void textarea_destroy(struct text_area *ta) { free(ta->text); - free(ta->style); free(ta->lines); free(ta); } @@ -448,8 +440,8 @@ bool textarea_set_caret(struct text_area *ta, int caret) if (caret != -1 && (unsigned)caret > c_len) caret = c_len; - height = css_len2px(&(ta->style->font_size.value.length), - ta->style); + height = ta->fstyle.size * css_screen_dpi / 72; + /* Delete the old caret */ if (ta->caret_pos.char_off != -1) { index = textarea_get_caret(ta); @@ -467,7 +459,7 @@ bool textarea_set_caret(struct text_area *ta, int caret) ta->text_len, b_off)) ; /* do nothing */ - nsfont.font_width(ta->style, + nsfont.font_width(&ta->fstyle, ta->text + ta->lines[ta->caret_pos.line].b_start, b_off - ta->lines[ta->caret_pos.line].b_start, @@ -516,7 +508,7 @@ bool textarea_set_caret(struct text_area *ta, int caret) ta->text_len, b_off)) ; /* do nothing */ - nsfont.font_width(ta->style, + nsfont.font_width(&ta->fstyle, ta->text + ta->lines[ta->caret_pos.line].b_start, b_off - ta->lines[ta->caret_pos.line].b_start, @@ -570,7 +562,7 @@ unsigned int textarea_get_xy_offset(struct text_area *ta, int x, int y) if (ta->line_count - 1 < line) line = ta->line_count - 1; - nsfont.font_position_in_string(ta->style, + nsfont.font_position_in_string(&ta->fstyle, ta->text + ta->lines[line].b_start, ta->lines[line].b_length, x, &b_off, &x); @@ -679,7 +671,7 @@ bool textarea_reflow(struct text_area *ta, unsigned int line) for (len = ta->text_len - 1, text = ta->text; len > 0; len -= b_off, text += b_off) { - nsfont.font_split(ta->style, text, len, + nsfont.font_split(&ta->fstyle, text, len, ta->vis_width - MARGIN_LEFT - MARGIN_RIGHT, &b_off, &x); @@ -757,7 +749,6 @@ void textarea_redraw(struct text_area *ta, int x0, int y0, int x1, int y1) .fill_colour = BACKGROUND_COL, }; - if (x1 < ta->x || x0 > ta->x + ta->vis_width || y1 < ta->y || y0 > ta->y + ta->vis_height) /* Textarea outside the clipping rectangle */ @@ -848,7 +839,7 @@ void textarea_redraw(struct text_area *ta, int x0, int y0, int x1, int y1) b_start = utf8_next(line_text, line_len, b_start); - nsfont.font_width(ta->style, line_text, + nsfont.font_width(&ta->fstyle, line_text, b_start, &x0); x0 += ta->x + MARGIN_LEFT; } @@ -872,7 +863,7 @@ void textarea_redraw(struct text_area *ta, int x0, int y0, int x1, int y1) b_end = ta->lines[line].b_length; b_end -= b_start; - nsfont.font_width(ta->style, + nsfont.font_width(&ta->fstyle, &(ta->text[ta->lines[line].b_start + b_start]), b_end, &x1); @@ -890,14 +881,15 @@ void textarea_redraw(struct text_area *ta, int x0, int y0, int x1, int y1) c_pos += c_len; y0 = ta->y + line * ta->line_height + 0.75 * ta->line_height; - - plot.text(ta->x + MARGIN_LEFT - ta->scroll_x, y0 - ta->scroll_y, - ta->style, - ta->text + ta->lines[line].b_start, - ta->lines[line].b_length, + + ta->fstyle.background = (ta->flags & TEXTAREA_READONLY) ? READONLY_BG : BACKGROUND_COL, - ta->style->color); + + plot.text(ta->x + MARGIN_LEFT - ta->scroll_x, y0 - ta->scroll_y, + ta->text + ta->lines[line].b_start, + ta->lines[line].b_length, + &ta->fstyle); } } @@ -1253,7 +1245,7 @@ bool textarea_scroll_visible(struct text_area *ta) b_off = utf8_next(ta->text, ta->text_len, b_off)) ; /* do nothing */ - nsfont.font_width(ta->style, + nsfont.font_width(&ta->fstyle, ta->text + ta->lines[ta->caret_pos.line].b_start, b_off - ta->lines[ta->caret_pos.line].b_start, &x); diff --git a/desktop/textinput.c b/desktop/textinput.c index 07af9e991..645c961c4 100644 --- a/desktop/textinput.c +++ b/desktop/textinput.c @@ -173,6 +173,7 @@ struct box *textarea_get_position(struct box *textarea, int x, int y, * lines. */ struct box *inline_container, *text_box; + plot_font_style_t fstyle; inline_container = textarea->children; @@ -181,8 +182,9 @@ struct box *textarea_get_position(struct box *textarea, int x, int y, text_box = inline_container->last; assert(text_box->type == BOX_TEXT); assert(text_box->text); + font_plot_style_from_css(text_box->style, &fstyle); /** \todo handle errors */ - nsfont.font_position_in_string(text_box->style, text_box->text, + nsfont.font_position_in_string(&fstyle, text_box->text, text_box->length, (unsigned int)(x - text_box->x), (size_t *) pchar_offset, ppixel_offset); @@ -204,7 +206,8 @@ struct box *textarea_get_position(struct box *textarea, int x, int y, text_box = inline_container->last; assert(text_box->type == BOX_TEXT); assert(text_box->text); - nsfont.font_position_in_string(text_box->style, + font_plot_style_from_css(text_box->style, &fstyle); + nsfont.font_position_in_string(&fstyle, text_box->text, text_box->length, textarea->width, @@ -224,7 +227,8 @@ struct box *textarea_get_position(struct box *textarea, int x, int y, } assert(text_box->type == BOX_TEXT); assert(text_box->text); - nsfont.font_position_in_string(text_box->style, + font_plot_style_from_css(text_box->style, &fstyle); + nsfont.font_position_in_string(&fstyle, text_box->text, text_box->length, (unsigned int)(x - text_box->x), @@ -321,6 +325,7 @@ bool browser_window_textarea_callback(struct browser_window *bw, unsigned int utf8_len; bool scrolled, reflow = false; bool selection_exists = bw->sel->defined; + plot_font_style_t fstyle; /* box_dump(textarea, 0); */ LOG(("key %i at %i in '%.*s'", key, char_offset, @@ -762,8 +767,9 @@ bool browser_window_textarea_callback(struct browser_window *bw, } } - nsfont.font_width(text_box->style, text_box->text, - char_offset, &pixel_offset); + font_plot_style_from_css(text_box->style, &fstyle); + + nsfont.font_width(&fstyle, text_box->text, char_offset, &pixel_offset); selection_clear(bw->sel, true); @@ -813,8 +819,11 @@ void browser_window_input_click(struct browser_window* bw, size_t char_offset = 0; int pixel_offset = 0, dx = 0; struct box *text_box = input->children->children; + plot_font_style_t fstyle; - nsfont.font_position_in_string(text_box->style, text_box->text, + font_plot_style_from_css(text_box->style, &fstyle); + + nsfont.font_position_in_string(&fstyle, text_box->text, text_box->length, x - text_box->x, &char_offset, &pixel_offset); assert(char_offset <= text_box->length); @@ -1349,6 +1358,7 @@ bool browser_window_textarea_paste_text(struct browser_window *bw, if (update) { int box_x, box_y; + plot_font_style_t fstyle; /* reflow textarea preserving width and height */ textarea_reflow(bw, textarea, inline_container); @@ -1380,7 +1390,9 @@ bool browser_window_textarea_paste_text(struct browser_window *bw, textarea->gadget->caret_text_box = text_box; textarea->gadget->caret_box_offset = char_offset; - nsfont.font_width(text_box->style, text_box->text, + font_plot_style_from_css(text_box->style, &fstyle); + + nsfont.font_width(&fstyle, text_box->text, char_offset, &pixel_offset); textarea->gadget->caret_pixel_offset = pixel_offset; @@ -1501,12 +1513,15 @@ void browser_window_textarea_move_caret(struct browser_window *bw, void *p) size_t char_offset = textarea->gadget->caret_box_offset; int pixel_offset; int box_x, box_y; + plot_font_style_t fstyle; + + font_plot_style_from_css(text_box->style, &fstyle); box_coords(textarea, &box_x, &box_y); box_x -= textarea->scroll_x; box_y -= textarea->scroll_y; - nsfont.font_width(text_box->style, text_box->text, + nsfont.font_width(&fstyle, text_box->text, char_offset, &pixel_offset); browser_window_place_caret(bw, @@ -1536,10 +1551,13 @@ void browser_window_input_move_caret(struct browser_window *bw, void *p) unsigned int box_offset = input->gadget->caret_box_offset; int pixel_offset; int box_x, box_y; + plot_font_style_t fstyle; + + font_plot_style_from_css(text_box->style, &fstyle); box_coords(input, &box_x, &box_y); - nsfont.font_width(text_box->style, text_box->text, box_offset, + nsfont.font_width(&fstyle, text_box->text, box_offset, &pixel_offset); browser_window_place_caret(bw, @@ -1572,14 +1590,17 @@ void input_update_display(struct browser_window *bw, struct box *input, unsigned pixel_offset; int box_x, box_y; int dx; + plot_font_style_t fstyle; + + font_plot_style_from_css(text_box->style, &fstyle); if (redraw) - nsfont.font_width(text_box->style, text_box->text, text_box->length, + nsfont.font_width(&fstyle, text_box->text, text_box->length, &text_box->width); box_coords(input, &box_x, &box_y); - nsfont.font_width(text_box->style, text_box->text, box_offset, + nsfont.font_width(&fstyle, text_box->text, box_offset, (int *) &pixel_offset); /* Shift text box horizontally, so caret is visible */ diff --git a/framebuffer/fbtk.c b/framebuffer/fbtk.c index 0284b19a1..c564a9117 100644 --- a/framebuffer/fbtk.c +++ b/framebuffer/fbtk.c @@ -39,7 +39,12 @@ #include "framebuffer/bitmap.h" #include "framebuffer/image_data.h" -static struct css_style root_style; +static plot_font_style_t root_style = { + .family = PLOT_FONT_FAMILY_SANS_SERIF, + .size = 11, + .weight = 400, + .flags = FONTF_NONE, +}; enum fbtk_widgettype_e { FB_WIDGET_TYPE_ROOT = 0, @@ -601,13 +606,14 @@ fb_redraw_text(fbtk_widget_t *root, fbtk_widget_t *widget, void *pw) } if (widget->u.text.text != NULL) { + root_style.background = widget->bg; + root_style.foreground = widget->fg; + plot.text(bbox.x0 + 3, bbox.y0 + 17, - &root_style, widget->u.text.text, strlen(widget->u.text.text), - widget->bg, - widget->fg); + &root_style); } nsfb_release(root->u.root.fb, &bbox); @@ -1301,9 +1307,6 @@ fbtk_init(nsfb_t *fb) root->y = 0; root->u.root.rootw = fbtk_create_window(root, 0, 0, 0, 0); - root_style.font_size.value.length.unit = CSS_UNIT_PX; - root_style.font_size.value.length.value = 14; - return root; } diff --git a/framebuffer/font_freetype.c b/framebuffer/font_freetype.c index a4bc7868b..a4ce9ff77 100644 --- a/framebuffer/font_freetype.c +++ b/framebuffer/font_freetype.c @@ -221,91 +221,54 @@ bool fb_font_finalise(void) return true; } -static void fb_fill_scalar(const struct css_style *style, FTC_Scaler srec) +static void fb_fill_scalar(const plot_font_style_t *fstyle, FTC_Scaler srec) { int selected_face = FB_FACE_DEFAULT; - switch (style->font_family) { + switch (fstyle->family) { /* - case CSS_FONT_FAMILY_CURSIVE: + case PLOT_FONT_FAMILY_CURSIVE: break; - case CSS_FONT_FAMILY_FANTASY: + case PLOT_FONT_FAMILY_FANTASY: break; */ - case CSS_FONT_FAMILY_SERIF: - switch (style->font_weight) { - case CSS_FONT_WEIGHT_700: - case CSS_FONT_WEIGHT_800: - case CSS_FONT_WEIGHT_900: - case CSS_FONT_WEIGHT_BOLD: + case PLOT_FONT_FAMILY_SERIF: + if (fstyle->weight >= 700) selected_face = FB_FACE_SERIF_BOLD; - break; - - case CSS_FONT_WEIGHT_NORMAL: - default: + else selected_face = FB_FACE_SERIF; - break; - } break; - case CSS_FONT_FAMILY_MONOSPACE: + case PLOT_FONT_FAMILY_MONOSPACE: selected_face = FB_FACE_MONOSPACE; break; - case CSS_FONT_FAMILY_SANS_SERIF: + case PLOT_FONT_FAMILY_SANS_SERIF: default: - switch (style->font_style) { - case CSS_FONT_STYLE_ITALIC: - switch (style->font_weight) { - case CSS_FONT_WEIGHT_700: - case CSS_FONT_WEIGHT_800: - case CSS_FONT_WEIGHT_900: - case CSS_FONT_WEIGHT_BOLD: + if ((fstyle->flags & FONTF_ITALIC) || + (fstyle->flags & FONTF_OBLIQUE)) { + if (fstyle->weight >= 700) selected_face = FB_FACE_SANS_SERIF_ITALIC_BOLD; - break; - - case CSS_FONT_WEIGHT_NORMAL: - default: + else selected_face = FB_FACE_SANS_SERIF_ITALIC; - break; - } - break; - - default: - switch (style->font_weight) { - case CSS_FONT_WEIGHT_700: - case CSS_FONT_WEIGHT_800: - case CSS_FONT_WEIGHT_900: - case CSS_FONT_WEIGHT_BOLD: + } else { + if (fstyle->weight >= 700) selected_face = FB_FACE_SANS_SERIF_BOLD; - break; - - case CSS_FONT_WEIGHT_NORMAL: - default: + else selected_face = FB_FACE_SANS_SERIF; - break; - } - break; } } srec->face_id = (FTC_FaceID)fb_faces[selected_face]; - if (style->font_size.value.length.unit == CSS_UNIT_PX) { - srec->width = srec->height = style->font_size.value.length.value; - srec->pixel = 1; - } else { - srec->width = srec->height = - css_len2pt(&style->font_size.value.length, style) * 64; - srec->pixel = 0; - - srec->x_res = srec->y_res = 72; - } + srec->width = srec->height = fstyle->size * 64; + srec->pixel = 0; + srec->x_res = srec->y_res = 72; } -FT_Glyph fb_getglyph(const struct css_style *style, uint32_t ucs4) +FT_Glyph fb_getglyph(const plot_font_style_t *fstyle, uint32_t ucs4) { FT_UInt glyph_index; FTC_ScalerRec srec; @@ -313,7 +276,7 @@ FT_Glyph fb_getglyph(const struct css_style *style, uint32_t ucs4) FT_Error error; fb_faceid_t *fb_face; - fb_fill_scalar(style, &srec); + fb_fill_scalar(fstyle, &srec); fb_face = (fb_faceid_t *)srec.face_id; @@ -335,14 +298,13 @@ FT_Glyph fb_getglyph(const struct css_style *style, uint32_t ucs4) /** * 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 */ -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) { @@ -355,7 +317,7 @@ static bool nsfont_width(const struct css_style *style, ucs4 = utf8_to_ucs4(string + nxtchr, length - nxtchr); nxtchr = utf8_next(string, length, nxtchr); - glyph = fb_getglyph(style, ucs4); + glyph = fb_getglyph(fstyle, ucs4); if (glyph == NULL) continue; @@ -368,8 +330,7 @@ static bool nsfont_width(const struct css_style *style, /** * 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 @@ -378,7 +339,7 @@ static bool nsfont_width(const struct css_style *style, * \return true on success, false on error and error reported */ -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) { @@ -390,7 +351,7 @@ static bool nsfont_position_in_string(const struct css_style *style, while (nxtchr < length) { ucs4 = utf8_to_ucs4(string + nxtchr, length - nxtchr); - glyph = fb_getglyph(style, ucs4); + glyph = fb_getglyph(fstyle, ucs4); if (glyph == NULL) continue; @@ -409,8 +370,7 @@ static 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 @@ -423,7 +383,7 @@ static bool nsfont_position_in_string(const struct css_style *style, * char_offset == length] */ -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) { @@ -437,7 +397,7 @@ static bool nsfont_split(const struct css_style *style, while (nxtchr < length) { ucs4 = utf8_to_ucs4(string + nxtchr, length - nxtchr); - glyph = fb_getglyph(style, ucs4); + glyph = fb_getglyph(fstyle, ucs4); if (glyph == NULL) continue; diff --git a/framebuffer/font_freetype.h b/framebuffer/font_freetype.h index 68d986b8c..90d8b23e6 100644 --- a/framebuffer/font_freetype.h +++ b/framebuffer/font_freetype.h @@ -25,6 +25,6 @@ extern int ft_load_type; -FT_Glyph fb_getglyph(const struct css_style *style, uint32_t ucs4); +FT_Glyph fb_getglyph(const plot_font_style_t *fstyle, uint32_t ucs4); #endif /* NETSURF_FB_FONT_FREETYPE_H */ diff --git a/framebuffer/font_internal.c b/framebuffer/font_internal.c index ba03ecc08..82ad6b32e 100644 --- a/framebuffer/font_internal.c +++ b/framebuffer/font_internal.c @@ -34,7 +34,7 @@ bool fb_font_init(void) } const struct fb_font_desc* -fb_get_font(const struct css_style *style) +fb_get_font(const plot_font_style_t *fstyle) { return &font_vga_8x16; } @@ -56,11 +56,11 @@ utf8_convert_ret utf8_to_local_encoding(const char *string, } -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) { - const struct fb_font_desc* fb_font = fb_get_font(style); + const struct fb_font_desc* fb_font = fb_get_font(fstyle); *width = fb_font->width * utf8_bounded_length(string, length); return true; } @@ -68,8 +68,7 @@ static bool nsfont_width(const struct css_style *style, /** * 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 @@ -78,11 +77,11 @@ static bool nsfont_width(const struct css_style *style, * \return true on success, false on error and error reported */ -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) { - const struct fb_font_desc* fb_font = fb_get_font(style); + const struct fb_font_desc* fb_font = fb_get_font(fstyle); *char_offset = x / fb_font->width; if (*char_offset > length) *char_offset = length; @@ -94,8 +93,7 @@ static 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 @@ -108,12 +106,12 @@ static bool nsfont_position_in_string(const struct css_style *style, * char_offset == length] */ -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) { - const struct fb_font_desc* fb_font = fb_get_font(style); + const struct fb_font_desc* fb_font = fb_get_font(fstyle); *char_offset = x / fb_font->width; if (*char_offset > length) { *char_offset = length; diff --git a/framebuffer/font_internal.h b/framebuffer/font_internal.h index eaa9dfba8..66beb42d0 100644 --- a/framebuffer/font_internal.h +++ b/framebuffer/font_internal.h @@ -28,7 +28,7 @@ struct fb_font_desc { extern const struct fb_font_desc font_vga_8x16; -extern const struct fb_font_desc* fb_get_font(const struct css_style *style); +extern const struct fb_font_desc* fb_get_font(const plot_font_style_t *fstyle); extern utf8_convert_ret utf8_to_font_encoding(const struct fb_font_desc* font, const char *string, diff --git a/framebuffer/framebuffer.c b/framebuffer/framebuffer.c index 8885d1fe0..fe3fe12e2 100644 --- a/framebuffer/framebuffer.c +++ b/framebuffer/framebuffer.c @@ -42,7 +42,6 @@ /* netsurf framebuffer library handle */ static nsfb_t *nsfb; -#ifdef FB_USE_FREETYPE static bool framebuffer_plot_disc(int x, int y, int radius, const plot_style_t *style) @@ -75,8 +74,9 @@ static bool framebuffer_plot_polygon(const int *p, unsigned int n, const plot_st } -static bool framebuffer_plot_text(int x, int y, const struct css_style *style, - const char *text, size_t length, colour bg, colour c) +#ifdef FB_USE_FREETYPE +static bool framebuffer_plot_text(int x, int y, const char *text, size_t length, + const plot_font_style_t *fstyle) { uint32_t ucs4; size_t nxtchr = 0; @@ -88,7 +88,7 @@ static bool framebuffer_plot_text(int x, int y, const struct css_style *style, ucs4 = utf8_to_ucs4(text + nxtchr, length - nxtchr); nxtchr = utf8_next(text, length, nxtchr); - glyph = fb_getglyph(style, ucs4); + glyph = fb_getglyph(fstyle, ucs4); if (glyph == NULL) continue; @@ -106,13 +106,13 @@ static bool framebuffer_plot_text(int x, int y, const struct css_style *style, &loc, bglyph->bitmap.buffer, bglyph->bitmap.pitch, - c); + fstyle->foreground); } else { nsfb_plot_glyph8(nsfb, &loc, bglyph->bitmap.buffer, bglyph->bitmap.pitch, - c); + fstyle->foreground); } } x += glyph->advance.x >> 16; @@ -122,10 +122,10 @@ static bool framebuffer_plot_text(int x, int y, const struct css_style *style, } #else -static bool framebuffer_plot_text(int x, int y, const struct css_style *style, - const char *text, size_t length, colour bg, colour c) +static bool framebuffer_plot_text(int x, int y, const char *text, size_t length, + const plot_font_style_t *fstyle) { - const struct fb_font_desc* fb_font = fb_get_font(style); + const struct fb_font_desc* fb_font = fb_get_font(fstyle); const uint32_t *chrp; char *buffer = NULL; int chr; @@ -152,7 +152,7 @@ static bool framebuffer_plot_text(int x, int y, const struct css_style *style, loc.y1 = loc.y0 + fb_font->height; chrp = fb_font->data + ((unsigned char)buffer[chr] * fb_font->height); - nsfb_plot_glyph1(nsfb, &loc, (uint8_t *)chrp, 32, c); + nsfb_plot_glyph1(nsfb, &loc, (uint8_t *)chrp, 32, fstyle->foreground); x+=fb_font->width; diff --git a/gtk/font_pango.c b/gtk/font_pango.c index eda2f89c9..e5f561c2f 100644 --- a/gtk/font_pango.c +++ b/gtk/font_pango.c @@ -37,17 +37,17 @@ /* Until we can consider the descenders etc, we need to not render using cairo */ #undef CAIRO_VERSION -static bool nsfont_width(const struct css_style *style, - const char *string, size_t length, - int *width); +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, - const char *string, size_t length, - int x, size_t *char_offset, int *actual_x); +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, - const char *string, size_t length, - int x, size_t *char_offset, int *actual_x); +static bool nsfont_split(const plot_font_style_t *style, + const char *string, size_t length, + int x, size_t *char_offset, int *actual_x); const struct font_functions nsfont = { nsfont_width, @@ -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 plot 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) { @@ -83,7 +82,7 @@ bool nsfont_width(const struct css_style *style, return true; } - desc = nsfont_style_to_description(style); + desc = nsfont_style_to_description(fstyle); context = gdk_pango_context_get(); layout = pango_layout_new(context); pango_layout_set_font_description(layout, desc); @@ -102,8 +101,7 @@ bool nsfont_width(const struct css_style *style, /** * 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 plot style for this text * \param string UTF-8 string to measure * \param length length of string * \param x x coordinate to search for @@ -112,7 +110,7 @@ bool nsfont_width(const struct css_style *style, * \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) { @@ -122,7 +120,7 @@ bool nsfont_position_in_string(const struct css_style *style, PangoLayout *layout; PangoRectangle pos; - desc = nsfont_style_to_description(style); + desc = nsfont_style_to_description(fstyle); context = gdk_pango_context_get(); layout = pango_layout_new(context); pango_layout_set_font_description(layout, desc); @@ -149,8 +147,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 plot style for this text * \param string UTF-8 string to measure * \param length length of string * \param x width available @@ -163,7 +160,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) { @@ -175,7 +172,7 @@ bool nsfont_split(const struct css_style *style, PangoLayoutIter *iter; PangoRectangle rect; - desc = nsfont_style_to_description(style); + desc = nsfont_style_to_description(fstyle); context = gdk_pango_context_get(); layout = pango_layout_new(context); pango_layout_set_font_description(layout, desc); @@ -206,19 +203,16 @@ 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 string UTF-8 string to measure - * \param length length of string * \param x x coordinate * \param y y coordinate - * \param c colour for text + * \param string UTF-8 string to measure + * \param length length of string + * \param style plot style for this text * \return true on success, false on error and error reported */ -bool nsfont_paint(const struct css_style *style, - const char *string, size_t length, - int x, int y, colour c) +bool nsfont_paint(int x, int y, const char *string, size_t length, + const plot_font_style_t *fstyle) { PangoFontDescription *desc; PangoLayout *layout; @@ -229,15 +223,18 @@ bool nsfont_paint(const struct css_style *style, #else PangoContext *context; GdkColor colour = { 0, - ((c & 0xff) << 8) | (c & 0xff), - (c & 0xff00) | (c & 0xff00 >> 8), - ((c & 0xff0000) >> 8) | (c & 0xff0000 >> 16) }; + ((fstyle->foreground & 0xff) << 8) | + (fstyle->foreground & 0xff), + (fstyle->foreground & 0xff00) | + (fstyle->foreground & 0xff00 >> 8), + ((fstyle->foreground & 0xff0000) >> 8) | + (fstyle->foreground & 0xff0000 >> 16) }; #endif if (length == 0) return true; - desc = nsfont_style_to_description(style); + desc = nsfont_style_to_description(fstyle); size = (gint)((double)pango_font_description_get_size(desc) * nsgtk_plot_get_scale()); if (pango_font_description_get_size_is_absolute(desc)) pango_font_description_set_absolute_size(desc, size); @@ -273,96 +270,60 @@ bool nsfont_paint(const struct css_style *style, /** - * Convert a css_style to a PangoFontDescription. + * Convert a plot style to a PangoFontDescription. * - * \param style css_style for this text, with style->font_size.size == - * CSS_FONT_SIZE_LENGTH + * \param style plot style for this text * \return a new Pango font description */ PangoFontDescription *nsfont_style_to_description( - const struct css_style *style) + const plot_font_style_t *fstyle) { unsigned int size; PangoFontDescription *desc; - PangoWeight weight = PANGO_WEIGHT_NORMAL; - PangoStyle styl = PANGO_STYLE_NORMAL; + PangoStyle style = PANGO_STYLE_NORMAL; - 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: desc = pango_font_description_from_string(option_font_serif); break; - case CSS_FONT_FAMILY_MONOSPACE: + case PLOT_FONT_FAMILY_MONOSPACE: desc = pango_font_description_from_string(option_font_mono); break; - case CSS_FONT_FAMILY_CURSIVE: + case PLOT_FONT_FAMILY_CURSIVE: desc = pango_font_description_from_string(option_font_cursive); break; - case CSS_FONT_FAMILY_FANTASY: + case PLOT_FONT_FAMILY_FANTASY: desc = pango_font_description_from_string(option_font_fantasy); break; - case CSS_FONT_FAMILY_SANS_SERIF: + case PLOT_FONT_FAMILY_SANS_SERIF: default: desc = pango_font_description_from_string(option_font_sans); break; } - - if (style->font_size.value.length.unit == CSS_UNIT_PX) - size = style->font_size.value.length.value; - else - size = css_len2pt(&style->font_size.value.length, style); + size = fstyle->size; if (size < (unsigned)abs(option_font_min_size / 10)) size = option_font_min_size / 10; size *= PANGO_SCALE; - switch (style->font_style) { - case CSS_FONT_STYLE_ITALIC: - styl = PANGO_STYLE_ITALIC; - break; - case CSS_FONT_STYLE_OBLIQUE: - styl = PANGO_STYLE_OBLIQUE; - break; - default: - break; - } + if (fstyle->flags & FONTF_ITALIC) + style = PANGO_STYLE_ITALIC; + else if (fstyle->flags & FONTF_OBLIQUE) + style = PANGO_STYLE_OBLIQUE; - pango_font_description_set_style(desc, styl); + pango_font_description_set_style(desc, style); - switch (style->font_weight) { - case CSS_FONT_WEIGHT_NORMAL: - weight = PANGO_WEIGHT_NORMAL; break; - case CSS_FONT_WEIGHT_BOLD: - weight = PANGO_WEIGHT_BOLD; break; - 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; - default: break; - } + pango_font_description_set_weight(desc, (PangoWeight) fstyle->weight); - pango_font_description_set_weight(desc, weight); + pango_font_description_set_size(desc, size); - if (style->font_size.value.length.unit == CSS_UNIT_PX) - pango_font_description_set_absolute_size(desc, size); - else - pango_font_description_set_size(desc, size); - - switch (style->font_variant) { - case CSS_FONT_VARIANT_SMALL_CAPS: - pango_font_description_set_variant(desc, PANGO_VARIANT_SMALL_CAPS); - break; - case CSS_FONT_VARIANT_NORMAL: - default: + if (fstyle->flags & FONTF_SMALLCAPS) { + pango_font_description_set_variant(desc, + PANGO_VARIANT_SMALL_CAPS); + } else { pango_font_description_set_variant(desc, PANGO_VARIANT_NORMAL); } diff --git a/gtk/font_pango.h b/gtk/font_pango.h index cbae6b2a7..edcd19b47 100644 --- a/gtk/font_pango.h +++ b/gtk/font_pango.h @@ -25,15 +25,13 @@ #include +#include "desktop/plot_style.h" -struct css_style; - -bool nsfont_paint(const struct css_style *style, - const char *string, size_t length, - int x, int y, colour c); +bool nsfont_paint(int x, int y, const char *string, size_t length, + const plot_font_style_t *fstyle); PangoFontDescription *nsfont_style_to_description( - const struct css_style *style); + const plot_font_style_t *fstyle); #endif diff --git a/gtk/gtk_plotters.c b/gtk/gtk_plotters.c index 8f906113c..a88e9a8e4 100644 --- a/gtk/gtk_plotters.c +++ b/gtk/gtk_plotters.c @@ -304,10 +304,10 @@ static bool nsgtk_plot_polygon(const int *p, unsigned int n, const plot_style_t -static bool nsgtk_plot_text(int x, int y, const struct css_style *style, - const char *text, size_t length, colour bg, colour c) +static bool nsgtk_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, c); + return nsfont_paint(x, y, text, length, fstyle); } diff --git a/gtk/gtk_print.c b/gtk/gtk_print.c index dfd5a85c3..8daa21df8 100644 --- a/gtk/gtk_print.c +++ b/gtk/gtk_print.c @@ -107,9 +107,9 @@ static bool nsgtk_print_plot_pixbuf(int x, int y, int width, int height, } -static bool gtk_print_font_paint(const struct css_style *style, +static bool gtk_print_font_paint(int x, int y, const char *string, size_t length, - int x, int y, colour c) + const plot_font_style_t *fstyle) { PangoFontDescription *desc; PangoLayout *layout; @@ -119,7 +119,7 @@ static bool gtk_print_font_paint(const struct css_style *style, if (length == 0) return true; - desc = nsfont_style_to_description(style); + desc = nsfont_style_to_description(fstyle); size = (gint) ((double) pango_font_description_get_size(desc) * settings->scale); @@ -136,7 +136,7 @@ static bool gtk_print_font_paint(const struct css_style *style, line = pango_layout_get_line(layout, 0); cairo_move_to(gtk_print_current_cr, x, y); - nsgtk_print_set_colour(c); + nsgtk_print_set_colour(fstyle->foreground); pango_cairo_show_layout_line(gtk_print_current_cr, line); g_object_unref(layout); @@ -429,10 +429,10 @@ static bool nsgtk_print_plot_bitmap(int x, int y, int width, int height, return true; } -static bool nsgtk_print_plot_text(int x, int y, const struct css_style *style, - const char *text, size_t length, colour bg, colour c) +static bool nsgtk_print_plot_text(int x, int y, const char *text, size_t length, + const plot_font_style_t *fstyle) { - return gtk_print_font_paint(style, text, length, x, y, c); + return gtk_print_font_paint(x, y, text, length, fstyle); } /** GTK print plotter table */ diff --git a/image/svg.c b/image/svg.c index ef4671658..b87a8a67d 100644 --- a/image/svg.c +++ b/image/svg.c @@ -98,6 +98,7 @@ bool svg_redraw(struct content *c, int x, int y, bool ok; int px, py; unsigned int i; + plot_font_style_t fstyle = *plot_style_font; assert(diagram); @@ -128,11 +129,14 @@ bool svg_redraw(struct content *c, int x, int y, py = transform[1] * diagram->shape[i].text_x + transform[3] * diagram->shape[i].text_y + transform[5]; + + fstyle.background = 0xffffff; + fstyle.foreground = 0x000000; + ok = plot.text(px, py, - &css_base_style, diagram->shape[i].text, strlen(diagram->shape[i].text), - 0xffffff, 0x000000); + &fstyle); if (!ok) return false; } diff --git a/render/font.c b/render/font.c new file mode 100644 index 000000000..089fcff5a --- /dev/null +++ b/render/font.c @@ -0,0 +1,150 @@ +/* + * Copyright 2009 John-Mark Bell + * + * This file is part of NetSurf, http://www.netsurf-browser.org/ + * + * NetSurf is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License. + * + * NetSurf is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "css/css.h" +#include "render/font.h" + +static plot_font_generic_family_t plot_font_generic_family( + css_font_family css); +static int plot_font_weight(css_font_weight css); +static plot_font_flags_t plot_font_flags(css_font_style style, + css_font_variant variant); + +/** + * Populate a font style using data from a computed CSS style + * + * \param css Computed style to consider + * \param fstyle Font style to populate + */ +void font_plot_style_from_css(const struct css_style *css, + plot_font_style_t *fstyle) +{ + fstyle->family = plot_font_generic_family(css->font_family); + fstyle->size = css_len2pt(&css->font_size.value.length, css); + fstyle->weight = plot_font_weight(css->font_weight); + fstyle->flags = plot_font_flags(css->font_style, css->font_variant); + fstyle->foreground = css->color; + fstyle->background = 0; +} + +/****************************************************************************** + * Helper functions * + ******************************************************************************/ + +/** + * Map a generic CSS font family to a generic plot font family + * + * \param css Generic CSS font family + * \return Plot font family + */ +plot_font_generic_family_t plot_font_generic_family( + css_font_family css) +{ + plot_font_generic_family_t plot; + + switch (css) { + case CSS_FONT_FAMILY_SERIF: + plot = PLOT_FONT_FAMILY_SERIF; + break; + case CSS_FONT_FAMILY_MONOSPACE: + plot = PLOT_FONT_FAMILY_MONOSPACE; + break; + case CSS_FONT_FAMILY_CURSIVE: + plot = PLOT_FONT_FAMILY_CURSIVE; + break; + case CSS_FONT_FAMILY_FANTASY: + plot = PLOT_FONT_FAMILY_FANTASY; + break; + case CSS_FONT_FAMILY_SANS_SERIF: + default: + plot = PLOT_FONT_FAMILY_SANS_SERIF; + break; + } + + return plot; +} + +/** + * Map a CSS font weight to a plot weight value + * + * \param css CSS font weight + * \return Plot weight + */ +int plot_font_weight(css_font_weight css) +{ + int weight; + + switch (css) { + 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: + case CSS_FONT_WEIGHT_NORMAL: + default: + weight = 400; + break; + case CSS_FONT_WEIGHT_500: + weight = 500; + break; + case CSS_FONT_WEIGHT_600: + weight = 600; + break; + case CSS_FONT_WEIGHT_700: + case CSS_FONT_WEIGHT_BOLD: + weight = 700; + break; + case CSS_FONT_WEIGHT_800: + weight = 800; + break; + case CSS_FONT_WEIGHT_900: + weight = 900; + break; + } + + return weight; +} + +/** + * Map a CSS font style and font variant to plot font flags + * + * \param style CSS font style + * \param variant CSS font variant + * \return Computed plot flags + */ +plot_font_flags_t plot_font_flags(css_font_style style, + css_font_variant variant) +{ + plot_font_flags_t flags = FONTF_NONE; + + if (style == CSS_FONT_STYLE_ITALIC) + flags |= FONTF_ITALIC; + else if (style == CSS_FONT_STYLE_OBLIQUE) + flags |= FONTF_OBLIQUE; + + if (variant == CSS_FONT_VARIANT_SMALL_CAPS) + flags |= FONTF_SMALLCAPS; + + return flags; +} + diff --git a/render/font.h b/render/font.h index acfd7c727..9a80af329 100644 --- a/render/font.h +++ b/render/font.h @@ -35,23 +35,25 @@ #include #include - -struct css_style; - +#include "css/css.h" +#include "desktop/plot_style.h" struct font_functions { - bool (*font_width)(const struct css_style *style, + bool (*font_width)(const plot_font_style_t *fstyle, const char *string, size_t length, int *width); - bool (*font_position_in_string)(const struct css_style *style, + bool (*font_position_in_string)(const plot_font_style_t *fstyle, const char *string, size_t length, int x, size_t *char_offset, int *actual_x); - bool (*font_split)(const struct css_style *style, + bool (*font_split)(const plot_font_style_t *fstyle, const char *string, size_t length, int x, size_t *char_offset, int *actual_x); }; extern const struct font_functions nsfont; +void font_plot_style_from_css(const struct css_style *css, + plot_font_style_t *fstyle); + #endif diff --git a/render/html.h b/render/html.h index f1ab9d86d..e6c322e14 100644 --- a/render/html.h +++ b/render/html.h @@ -28,6 +28,7 @@ #include #include "content/content_type.h" #include "css/css.h" +#include "desktop/plot_style.h" #include "render/parser_binding.h" struct box; @@ -197,11 +198,11 @@ bool html_redraw(struct content *c, int x, int y, bool text_redraw(const char *utf8_text, size_t utf8_len, size_t offset, bool space, - struct css_style *style, + const plot_font_style_t *fstyle, int x, int y, struct rect *clip, int height, - float scale, colour current_background_color, + float scale, bool excluded); #endif diff --git a/render/html_redraw.c b/render/html_redraw.c index 0fc10cb6c..64fc6066b 100644 --- a/render/html_redraw.c +++ b/render/html_redraw.c @@ -747,6 +747,10 @@ bool html_redraw_text_box(struct box *box, int x, int y, { bool excluded = (box->object != NULL); struct rect clip; + plot_font_style_t fstyle; + + font_plot_style_from_css(box->style, &fstyle); + fstyle.background = current_background_color; clip.x0 = x0; clip.y0 = y0; @@ -754,9 +758,8 @@ bool html_redraw_text_box(struct box *box, int x, int y, clip.y1 = y1; if (!text_redraw(box->text, box->length, box->byte_offset, - box->space, box->style, x, y, - &clip, box->height, scale, - current_background_color, excluded)) + box->space, &fstyle, x, y, + &clip, box->height, scale, excluded)) return false; /* does this textbox contain the ghost caret? */ @@ -769,7 +772,6 @@ bool html_redraw_text_box(struct box *box, int x, int y, return true; } - /** * Redraw a short text string, complete with highlighting * (for selection/search) and ghost caret @@ -778,22 +780,21 @@ bool html_redraw_text_box(struct box *box, int x, int y, * \param utf8_len length of string, in bytes * \param offset byte offset within textual representation * \param space indicates whether string is followed by a space - * \param style text style to use + * \param fstyle text style to use * \param x x ordinate at which to plot text * \param y y ordinate at which to plot text * \param clip pointer to current clip rectangle * \param height height of text string * \param scale current display scale (1.0 = 100%) - * \param current_background_color * \param excluded exclude this text string from the selection * \return true iff successful and redraw should proceed */ bool text_redraw(const char *utf8_text, size_t utf8_len, - size_t offset, bool space, struct css_style *style, + size_t offset, bool space, const plot_font_style_t *fstyle, int x, int y, struct rect *clip, int height, - float scale, colour current_background_color, + float scale, bool excluded) { bool highlighted = false; @@ -828,6 +829,7 @@ bool text_redraw(const char *utf8_text, size_t utf8_len, bool text_visible = true; int startx, endx; plot_style_t *pstyle_fill_hback = plot_style_fill_white; + plot_font_style_t fstyle_hback = *fstyle; if (end_idx > utf8_len) { /* adjust for trailing space, not present in @@ -836,11 +838,11 @@ bool text_redraw(const char *utf8_text, size_t utf8_len, endtxt_idx = utf8_len; } - if (!nsfont.font_width(style, utf8_text, start_idx, + if (!nsfont.font_width(fstyle, utf8_text, start_idx, &startx)) startx = 0; - if (!nsfont.font_width(style, utf8_text, endtxt_idx, + if (!nsfont.font_width(fstyle, utf8_text, endtxt_idx, &endx)) endx = 0; @@ -850,7 +852,7 @@ bool text_redraw(const char *utf8_text, size_t utf8_len, int spc_width; /* \todo is there a more elegant/efficient * solution? */ - if (nsfont.font_width(style, " ", 1, + if (nsfont.font_width(fstyle, " ", 1, &spc_width)) endx += spc_width; } @@ -863,15 +865,13 @@ bool text_redraw(const char *utf8_text, size_t utf8_len, /* draw any text preceding highlighted portion */ if (start_idx > 0 && !plot.text(x, y + (int) (height * 0.75 * scale), - style, utf8_text, start_idx, - current_background_color, - /*print_text_black ? 0 :*/ - style->color)) + utf8_text, start_idx, + fstyle)) return false; /* decide whether highlighted portion is to be * white-on-black or black-on-white */ - if ((current_background_color & 0x808080) == 0x808080) + if ((fstyle->background & 0x808080) == 0x808080) pstyle_fill_hback = plot_style_fill_black; /* highlighted portion */ @@ -894,11 +894,15 @@ bool text_redraw(const char *utf8_text, size_t utf8_len, } } + fstyle_hback.background = + pstyle_fill_hback->fill_colour ^ 0xffffff; + fstyle_hback.foreground = + pstyle_fill_hback->fill_colour; + if (text_visible && !plot.text(x, y + (int) (height * 0.75 * scale), - style, utf8_text, endtxt_idx, - pstyle_fill_hback->fill_colour, - pstyle_fill_hback->fill_colour ^ 0xffffff)) + utf8_text, endtxt_idx, + &fstyle_hback)) return false; /* draw any text succeeding highlighted portion */ @@ -914,10 +918,8 @@ bool text_redraw(const char *utf8_text, size_t utf8_len, if (!plot.text(x, y + (int) (height * 0.75 * scale), - style, utf8_text, utf8_len, - current_background_color, - /*print_text_black ? 0 :*/ - style->color)) + utf8_text, utf8_len, + fstyle)) return false; } } @@ -931,9 +933,8 @@ bool text_redraw(const char *utf8_text, size_t utf8_len, if (!highlighted) { if (!plot.text(x, y + (int) (height * 0.75 * scale), - style, utf8_text, utf8_len, - current_background_color, - /*print_text_black ? 0 :*/ style->color)) + utf8_text, utf8_len, + fstyle)) return false; } return true; @@ -1396,6 +1397,10 @@ bool html_redraw_file(int x, int y, int width, int height, int text_width; const char *text; size_t length; + plot_font_style_t fstyle; + + font_plot_style_from_css(box->style, &fstyle); + fstyle.background = background_colour; if (box->gadget->value) text = box->gadget->value; @@ -1403,7 +1408,7 @@ bool html_redraw_file(int x, int y, int width, int height, text = messages_get("Form_Drop"); length = strlen(text); - if (!nsfont.font_width(box->style, text, length, &text_width)) + if (!nsfont.font_width(&fstyle, text, length, &text_width)) return false; text_width *= scale; if (width < text_width + 8) @@ -1411,9 +1416,7 @@ bool html_redraw_file(int x, int y, int width, int height, else x = x + 4; - return plot.text(x, y + height * 0.75, box->style, text, length, - background_colour, - /*print_text_black ? 0 :*/ box->style->color); + return plot.text(x, y + height * 0.75, text, length, &fstyle); } diff --git a/render/layout.c b/render/layout.c index 96a9b6168..5bf03a157 100644 --- a/render/layout.c +++ b/render/layout.c @@ -1668,6 +1668,7 @@ bool layout_line(struct box *first, int *width, int *y, unsigned int i; struct css_length gadget_size; /* Checkbox / radio buttons */ const struct font_functions *font_func = content->data.html.font_func; + plot_font_style_t fstyle; gadget_size.unit = CSS_UNIT_EM; gadget_size.value = 1; @@ -1722,6 +1723,9 @@ bool layout_line(struct box *first, int *width, int *y, b->style->position == CSS_POSITION_FIXED)) continue; + assert(b->style != NULL); + font_plot_style_from_css(b->style, &fstyle); + x += space_after; if (b->type == BOX_INLINE_BLOCK) { @@ -1763,7 +1767,7 @@ bool layout_line(struct box *first, int *width, int *y, b->width = 0; if (b->space) { /** \todo optimize out */ - font_func->font_width(b->style, " ", 1, + font_func->font_width(&fstyle, " ", 1, &space_after); } else { space_after = 0; @@ -1801,7 +1805,7 @@ bool layout_line(struct box *first, int *width, int *y, data.select.items; o; o = o->next) { int opt_width; - font_func->font_width(b->style, + font_func->font_width(&fstyle, o->text, strlen(o->text), &opt_width); @@ -1812,7 +1816,7 @@ bool layout_line(struct box *first, int *width, int *y, b->width = opt_maxwidth; } else { - font_func->font_width(b->style, b->text, + font_func->font_width(&fstyle, b->text, b->length, &b->width); } } @@ -1820,7 +1824,7 @@ bool layout_line(struct box *first, int *width, int *y, x += b->width; if (b->space) /** \todo optimize out */ - font_func->font_width(b->style, " ", 1, + font_func->font_width(&fstyle, " ", 1, &space_after); else space_after = 0; @@ -1957,10 +1961,13 @@ bool layout_line(struct box *first, int *width, int *y, space_after = 0; else if (b->text || b->type == BOX_INLINE_END) { space_after = 0; - if (b->space) + if (b->space) { + font_plot_style_from_css(b->style, + &fstyle); /** \todo handle errors, optimize */ - font_func->font_width(b->style, " ", 1, + font_func->font_width(&fstyle, " ", 1, &space_after); + } } else space_after = 0; split_box = b; @@ -2099,10 +2106,12 @@ bool layout_line(struct box *first, int *width, int *y, if (space == 0) w = split_box->width; - else + else { + font_plot_style_from_css(split_box->style, &fstyle); /** \todo handle errors */ - font_func->font_width(split_box->style, split_box->text, + font_func->font_width(&fstyle, split_box->text, space, &w); + } LOG(("splitting: split_box %p \"%.*s\", space %zu, w %i, " "left %p, right %p, inline_count %u", @@ -2171,8 +2180,9 @@ bool layout_line(struct box *first, int *width, int *y, } else { /* fit as many words as possible */ assert(space != 0); + font_plot_style_from_css(split_box->style, &fstyle); /** \todo handle errors */ - font_func->font_split(split_box->style, + font_func->font_split(&fstyle, split_box->text, split_box->length, x1 - x0 - x - space_before, &space, &w); LOG(("'%.*s' %i %zu %i", (int) split_box->length, @@ -2294,6 +2304,8 @@ struct box *layout_minmax_line(struct box *first, size_t i, j; struct box *b; struct css_length gadget_size; /* Checkbox / radio buttons */ + plot_font_style_t fstyle; + gadget_size.unit = CSS_UNIT_EM; gadget_size.value = 1; @@ -2334,6 +2346,9 @@ struct box *layout_minmax_line(struct box *first, continue; } + assert(b->style); + font_plot_style_from_css(b->style, &fstyle); + if (b->type == BOX_INLINE && !b->object) { fixed = frac = 0; calculate_mbp_width(b->style, LEFT, true, true, true, @@ -2353,7 +2368,7 @@ struct box *layout_minmax_line(struct box *first, if (0 < fixed) max += fixed; if (b->next && b->space) { - font_func->font_width(b->style, " ", 1, &width); + font_func->font_width(&fstyle, " ", 1, &width); max += width; } continue; @@ -2379,7 +2394,7 @@ struct box *layout_minmax_line(struct box *first, data.select.items; o; o = o->next) { int opt_width; - font_func->font_width(b->style, + font_func->font_width(&fstyle, o->text, strlen(o->text), &opt_width); @@ -2390,13 +2405,13 @@ struct box *layout_minmax_line(struct box *first, b->width = opt_maxwidth; } else { - font_func->font_width(b->style, b->text, + font_func->font_width(&fstyle, b->text, b->length, &b->width); } } max += b->width; if (b->next && b->space) { - font_func->font_width(b->style, " ", 1, &width); + font_func->font_width(&fstyle, " ", 1, &width); max += width; } @@ -2406,7 +2421,7 @@ struct box *layout_minmax_line(struct box *first, for (j = i; j != b->length && b->text[j] != ' '; j++) ; - font_func->font_width(b->style, b->text + i, + font_func->font_width(&fstyle, b->text + i, j - i, &width); if (min < width) min = width; @@ -3327,6 +3342,7 @@ void layout_lists(struct box *box, { struct box *child; struct box *marker; + plot_font_style_t fstyle; for (child = box->children; child; child = child->next) { if (child->list_marker) { @@ -3338,11 +3354,14 @@ void layout_lists(struct box *box, marker->y = (line_height(marker->style) - marker->height) / 2; } else if (marker->text) { - if (marker->width == UNKNOWN_WIDTH) - font_func->font_width(marker->style, + if (marker->width == UNKNOWN_WIDTH) { + font_plot_style_from_css(marker->style, + &fstyle); + font_func->font_width(&fstyle, marker->text, marker->length, &marker->width); + } marker->x = -marker->width; marker->y = 0; marker->height = line_height(marker->style); diff --git a/render/loosen.c b/render/loosen.c index 80f64bdcb..85136d89b 100644 --- a/render/loosen.c +++ b/render/loosen.c @@ -115,6 +115,10 @@ bool loosen_text(struct box *text, int width, struct content *content) unsigned int position; const struct font_functions *font_func; + plot_font_style_t fstyle; + + font_plot_style_from_css(text->style, &fstyle); + if (content->type == CONTENT_HTML) font_func = content->data.html.font_func; else @@ -134,7 +138,7 @@ bool loosen_text(struct box *text, int width, struct content *content) position = 0; while (position < text->length) { - font_func->font_position_in_string(text->style, + font_func->font_position_in_string(&fstyle, text->text + position, text->length - position, width, &offset, &actual_x); diff --git a/render/textplain.c b/render/textplain.c index c1ee1cf43..dd3d168f9 100644 --- a/render/textplain.c +++ b/render/textplain.c @@ -49,11 +49,20 @@ #define TAB_WIDTH 8 /* must be power of 2 currently */ -static struct css_style textplain_style; +static plot_font_style_t textplain_style = { + .family = PLOT_FONT_FAMILY_MONOSPACE, + .size = 10, + .weight = 400, + .flags = FONTF_NONE, + .background = 0xffffff, + .foreground = 0x000000, +}; + static int textplain_tab_width = 256; /* try for a sensible default */ static int textplain_coord_from_offset(const char *text, size_t offset, size_t length); +static float textplain_line_height(void); /** @@ -68,9 +77,6 @@ bool textplain_create(struct content *c, const char *params[]) iconv_t iconv_cd; union content_msg_data msg_data; - textplain_style = css_base_style; - textplain_style.font_family = CSS_FONT_FAMILY_MONOSPACE; - utf8_data = talloc_array(c, char, CHUNK); if (!utf8_data) goto no_memory; @@ -281,9 +287,7 @@ void textplain_reformat(struct content *c, int width, int height) c->data.textplain.physical_line_count = line_count; c->width = width; - c->height = line_count * - css_len2px(&textplain_style.font_size.value.length, - &textplain_style) * 1.2 + MARGIN + MARGIN; + c->height = line_count * textplain_line_height() + MARGIN + MARGIN; return; @@ -332,8 +336,7 @@ bool textplain_redraw(struct content *c, int x, int y, char *utf8_data = c->data.textplain.utf8_data; long lineno; unsigned long line_count = c->data.textplain.physical_line_count; - float line_height = css_len2px(&textplain_style.font_size.value.length, - &textplain_style) * 1.2; + float line_height = textplain_line_height(); float scaled_line_height = line_height * scale; long line0 = clip_y0 / scaled_line_height - 1; long line1 = clip_y1 / scaled_line_height + 1; @@ -370,6 +373,9 @@ bool textplain_redraw(struct content *c, int x, int y, else plot_style_highlight = plot_style_fill_white; + /* Set background colour to plot with */ + textplain_style.background = background_colour; + x += MARGIN * scale; y += MARGIN * scale; for (lineno = line0; lineno != line1; lineno++) { @@ -396,8 +402,7 @@ bool textplain_redraw(struct content *c, int x, int y, line[lineno].start + offset, false, &textplain_style, tx, y + (lineno * scaled_line_height), - &clip, line_height, scale, - background_colour, false)) + &clip, line_height, scale, false)) return false; if (next_offset >= length) @@ -468,8 +473,7 @@ bool textplain_redraw(struct content *c, int x, int y, size_t textplain_offset_from_coords(struct content *c, int x, int y, int dir) { - float line_height = css_len2px(&textplain_style.font_size.value.length, - &textplain_style) * 1.2; + float line_height = textplain_line_height(); struct textplain_line *line; const char *text; unsigned nlines; @@ -618,8 +622,7 @@ int textplain_coord_from_offset(const char *text, size_t offset, size_t length) void textplain_coords_from_range(struct content *c, unsigned start, unsigned end, struct rect *r) { - float line_height = css_len2px(&textplain_style.font_size.value.length, - &textplain_style) * 1.2; + float line_height = textplain_line_height(); char *utf8_data = c->data.textplain.utf8_data; struct textplain_line *line; unsigned lineno = 0; @@ -719,3 +722,17 @@ char *textplain_get_raw_data(struct content *c, unsigned start, unsigned end, return c->data.textplain.utf8_data + start; } + +/** + * Calculate the line height, in pixels + * + * \return Line height, in pixels + */ +float textplain_line_height(void) +{ + /* Size is in points, so convert to pixels. + * Then use a constant line height of 1.2 x font size. + */ + return (textplain_style.size * css_screen_dpi / 72) * 1.2; +} + diff --git a/riscos/configure/con_fonts.c b/riscos/configure/con_fonts.c index 4ed436871..b420b26e5 100644 --- a/riscos/configure/con_fonts.c +++ b/riscos/configure/con_fonts.c @@ -19,6 +19,7 @@ #include #include "css/css.h" #include "desktop/options.h" +#include "desktop/plot_style.h" #include "riscos/dialog.h" #include "riscos/gui.h" #include "riscos/menus.h" @@ -58,6 +59,14 @@ * probably be released at some point */ static wimp_menu *default_menu; +static const char *font_names[PLOT_FONT_FAMILY_COUNT] = { + "Sans-serif", + "Serif", + "Monospace", + "Cursive", + "Fantasy" +}; + static void ro_gui_options_fonts_default(wimp_pointer *pointer); static bool ro_gui_options_fonts_ok(wimp_w w); static bool ro_gui_options_fonts_init_menu(void); @@ -73,7 +82,7 @@ bool ro_gui_options_fonts_initialise(wimp_w w) ro_gui_set_icon_string(w, FONT_CURSIVE_FIELD, option_font_cursive, true); ro_gui_set_icon_string(w, FONT_FANTASY_FIELD, option_font_fantasy, true); ro_gui_set_icon_string(w, FONT_DEFAULT_FIELD, - css_font_family_name[option_font_default], true); + font_names[option_font_default], true); if (!ro_gui_options_fonts_init_menu()) return false; @@ -124,7 +133,7 @@ void ro_gui_options_fonts_default(wimp_pointer *pointer) ro_gui_set_icon_string(pointer->w, FONT_FANTASY_FIELD, nsfont_exists("Sassoon") ? "Sassoon" : fallback, true); ro_gui_set_icon_string(pointer->w, FONT_DEFAULT_FIELD, - css_font_family_name[1], true); + font_names[0], true); } bool ro_gui_options_fonts_ok(wimp_w w) @@ -149,16 +158,15 @@ bool ro_gui_options_fonts_ok(wimp_w w) option_font_fantasy = strdup(ro_gui_get_icon_string(w, FONT_FANTASY_FIELD)); for (i = 0; i != 5; i++) { - if (!strcmp(css_font_family_name[i+1], - ro_gui_get_icon_string(w, - FONT_DEFAULT_FIELD))) + if (!strcmp(font_names[i], ro_gui_get_icon_string(w, + FONT_DEFAULT_FIELD))) break; } if (i == 5) /* this should never happen, but still */ i = 0; - option_font_default = i + 1; + option_font_default = i; ro_gui_save_options(); return true; @@ -182,9 +190,9 @@ bool ro_gui_options_fonts_init_menu(void) ro_gui_menu_init_structure(default_menu, 5); for (i = 0; i < 5; i++) { default_menu->entries[i].data.indirected_text.text = - (char *) css_font_family_name[i+1]; + (char *) font_names[i]; default_menu->entries[i].data.indirected_text.size = - strlen(css_font_family_name[i+1]); + strlen(font_names[i]); } return true; } diff --git a/riscos/font.c b/riscos/font.c index 5051fa6f3..3aac2cd5e 100644 --- a/riscos/font.c +++ b/riscos/font.c @@ -41,13 +41,13 @@ static int nsfont_list_cmp(const void *keyval, const void *datum); static void nsfont_check_fonts(void); static void ro_gui_wimp_desktop_font(char *family, size_t bufsize, int *psize, rufl_style *pstyle); -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); @@ -99,12 +99,12 @@ void nsfont_init(void) nsfont_check_option(&option_font_cursive, "Churchill", fallback); nsfont_check_option(&option_font_fantasy, "Sassoon", fallback); - if (option_font_default != CSS_FONT_FAMILY_SANS_SERIF && - option_font_default != CSS_FONT_FAMILY_SERIF && - option_font_default != CSS_FONT_FAMILY_MONOSPACE && - option_font_default != CSS_FONT_FAMILY_CURSIVE && - option_font_default != CSS_FONT_FAMILY_FANTASY) - option_font_default = CSS_FONT_FAMILY_SANS_SERIF; + if (option_font_default != PLOT_FONT_FAMILY_SANS_SERIF && + option_font_default != PLOT_FONT_FAMILY_SERIF && + option_font_default != PLOT_FONT_FAMILY_MONOSPACE && + option_font_default != PLOT_FONT_FAMILY_CURSIVE && + option_font_default != PLOT_FONT_FAMILY_FANTASY) + option_font_default = PLOT_FONT_FAMILY_SANS_SERIF; } @@ -218,15 +218,14 @@ void nsfont_check_fonts(void) /** * Measure the width of a string. * - * \param style css_style for this text, with style->font_size.size == - * CSS_FONT_SIZE_LENGTH + * \param fstyle plot 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) { @@ -235,7 +234,7 @@ bool nsfont_width(const struct css_style *style, rufl_style font_style; rufl_code code; - nsfont_read_style(style, &font_family, &font_size, &font_style); + nsfont_read_style(fstyle, &font_family, &font_size, &font_style); code = rufl_width(font_family, font_style, font_size, string, length, @@ -259,8 +258,7 @@ bool nsfont_width(const struct css_style *style, /** * 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 @@ -269,7 +267,7 @@ bool nsfont_width(const struct css_style *style, * \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) { @@ -278,7 +276,7 @@ bool nsfont_position_in_string(const struct css_style *style, rufl_style font_style; rufl_code code; - nsfont_read_style(style, &font_family, &font_size, &font_style); + nsfont_read_style(fstyle, &font_family, &font_size, &font_style); code = rufl_x_to_offset(font_family, font_style, font_size, string, length, @@ -303,8 +301,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 @@ -317,7 +314,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) { @@ -326,7 +323,7 @@ bool nsfont_split(const struct css_style *style, rufl_style font_style; rufl_code code; - nsfont_read_style(style, &font_family, &font_size, &font_style); + nsfont_read_style(fstyle, &font_family, &font_size, &font_style); code = rufl_split(font_family, font_style, font_size, string, length, @@ -368,19 +365,16 @@ bool nsfont_split(const struct css_style *style, /** * Paint a string. * - * \param style css_style for this text, with style->font_size.size == - * CSS_FONT_SIZE_LENGTH + * \param fstyle plot style for this text * \param string UTF-8 string to measure * \param length length of string * \param x x coordinate * \param y y coordinate * \param scale scale to apply to font size - * \param bg background colour - * \param c colour for text * \return true on success, false on error and error reported */ -bool nsfont_paint(const struct css_style *style, const char *string, +bool nsfont_paint(const plot_font_style_t *fstyle, const char *string, size_t length, int x, int y, float scale) { const char *font_family; @@ -388,7 +382,7 @@ bool nsfont_paint(const struct css_style *style, const char *string, rufl_style font_style; rufl_code code; - nsfont_read_style(style, &font_family, &font_size, &font_style); + nsfont_read_style(fstyle, &font_family, &font_size, &font_style); code = rufl_paint(font_family, font_style, font_size * scale, string, length, x, y, @@ -407,40 +401,50 @@ bool nsfont_paint(const struct css_style *style, const char *string, /** - * Convert a css_style to a font family, size and rufl_style. + * Convert a font style to a font family, size and rufl_style. * - * \param style css_style for this text, with style->font_size.size == - * CSS_FONT_SIZE_LENGTH + * \param fstyle plot style for this text * \param font_family updated to font family * \param font_size updated to font size * \param font_style updated to font style */ -void nsfont_read_style(const struct css_style *style, +void nsfont_read_style(const plot_font_style_t *fstyle, const char **font_family, unsigned int *font_size, rufl_style *font_style) { - assert(style->font_size.size == CSS_FONT_SIZE_LENGTH); - *font_size = css_len2pt(&style->font_size.value.length, style) * 16.; + static const rufl_style weight_table[] = { + rufl_WEIGHT_100, + rufl_WEIGHT_200, + rufl_WEIGHT_300, + rufl_WEIGHT_400, + rufl_WEIGHT_500, + rufl_WEIGHT_600, + rufl_WEIGHT_700, + rufl_WEIGHT_800, + rufl_WEIGHT_900 + }; + + *font_size = fstyle->size * 16.; if (*font_size < option_font_min_size * 1.6) *font_size = option_font_min_size * 1.6; if (1600 < *font_size) *font_size = 1600; - switch (style->font_family) { - case CSS_FONT_FAMILY_SANS_SERIF: + switch (fstyle->family) { + case PLOT_FONT_FAMILY_SANS_SERIF: *font_family = option_font_sans; break; - case CSS_FONT_FAMILY_SERIF: + case PLOT_FONT_FAMILY_SERIF: *font_family = option_font_serif; break; - case CSS_FONT_FAMILY_MONOSPACE: + case PLOT_FONT_FAMILY_MONOSPACE: *font_family = option_font_mono; break; - case CSS_FONT_FAMILY_CURSIVE: + case PLOT_FONT_FAMILY_CURSIVE: *font_family = option_font_cursive; break; - case CSS_FONT_FAMILY_FANTASY: + case PLOT_FONT_FAMILY_FANTASY: *font_family = option_font_fantasy; break; default: @@ -448,50 +452,13 @@ void nsfont_read_style(const struct css_style *style, break; } - switch (style->font_style) { - case CSS_FONT_STYLE_ITALIC: - case CSS_FONT_STYLE_OBLIQUE: + if ((fstyle->flags & FONTF_ITALIC) || (fstyle->flags & FONTF_OBLIQUE)) { *font_style = rufl_SLANTED; - break; - default: + } else { *font_style = 0; - break; } - switch (style->font_weight) { - case CSS_FONT_WEIGHT_100: - *font_style |= rufl_WEIGHT_100; - break; - case CSS_FONT_WEIGHT_200: - *font_style |= rufl_WEIGHT_200; - break; - case CSS_FONT_WEIGHT_300: - *font_style |= rufl_WEIGHT_300; - break; - case CSS_FONT_WEIGHT_NORMAL: - case CSS_FONT_WEIGHT_400: - *font_style |= rufl_WEIGHT_400; - break; - case CSS_FONT_WEIGHT_500: - *font_style |= rufl_WEIGHT_500; - break; - case CSS_FONT_WEIGHT_600: - *font_style |= rufl_WEIGHT_600; - break; - case CSS_FONT_WEIGHT_BOLD: - case CSS_FONT_WEIGHT_700: - *font_style |= rufl_WEIGHT_700; - break; - case CSS_FONT_WEIGHT_800: - *font_style |= rufl_WEIGHT_800; - break; - case CSS_FONT_WEIGHT_900: - *font_style |= rufl_WEIGHT_900; - break; - default: - *font_style |= rufl_WEIGHT_400; - break; - } + *font_style |= weight_table[(fstyle->weight / 100) - 1]; } diff --git a/riscos/gui.h b/riscos/gui.h index e9874bddb..2eaf7cb27 100644 --- a/riscos/gui.h +++ b/riscos/gui.h @@ -210,9 +210,9 @@ void ro_gui_print_prepare(struct gui_window *g); void nsfont_init(void); bool nsfont_exists(const char *font_family); const char *nsfont_fallback_font(void); -bool nsfont_paint(const struct css_style *style, const char *string, +bool nsfont_paint(const plot_font_style_t *fstyle, const char *string, size_t length, int x, int y, float scale); -void nsfont_read_style(const struct css_style *style, +void nsfont_read_style(const plot_font_style_t *fstyle, const char **font_family, unsigned int *font_size, rufl_style *font_style); void ro_gui_wimp_get_desktop_font(void); diff --git a/riscos/plotters.c b/riscos/plotters.c index 38971d57c..ed44a2cd6 100644 --- a/riscos/plotters.c +++ b/riscos/plotters.c @@ -43,8 +43,8 @@ static bool ro_plot_path(const float *p, unsigned int n, colour fill, float widt colour c, const float transform[6]); static bool ro_plot_clip(int clip_x0, int clip_y0, int clip_x1, int clip_y1); -static bool ro_plot_text(int x, int y, const struct css_style *style, - const char *text, size_t length, colour bg, colour c); +static bool ro_plot_text(int x, int y, const char *text, size_t length, + const plot_font_style_t *fstyle); static bool ro_plot_disc(int x, int y, int radius, const plot_style_t *style); static bool ro_plot_arc(int x, int y, int radius, int angle1, int angle2, const plot_style_t *style); @@ -394,20 +394,21 @@ bool ro_plot_clip(int clip_x0, int clip_y0, } -bool ro_plot_text(int x, int y, const struct css_style *style, - const char *text, size_t length, colour bg, colour c) +bool ro_plot_text(int x, int y, const char *text, size_t length, + const plot_font_style_t *fstyle) { os_error *error; error = xcolourtrans_set_font_colours(font_CURRENT, - bg << 8, c << 8, 14, 0, 0, 0); + fstyle->background << 8, fstyle->foreground << 8, + 14, 0, 0, 0); if (error) { LOG(("xcolourtrans_set_font_colours: 0x%x: %s", error->errnum, error->errmess)); return false; } - return nsfont_paint(style, text, length, + return nsfont_paint(fstyle, text, length, ro_plot_origin_x + x * 2, ro_plot_origin_y - y * 2, ro_plot_scale); diff --git a/riscos/print.c b/riscos/print.c index 108fe2d7c..37af874b2 100644 --- a/riscos/print.c +++ b/riscos/print.c @@ -102,8 +102,8 @@ static bool print_fonts_plot_line(int x0, int y0, int x1, int y1, const plot_sty static bool print_fonts_plot_polygon(const int *p, unsigned int n, const plot_style_t *style); static bool print_fonts_plot_clip(int clip_x0, int clip_y0, int clip_x1, int clip_y1); -static bool print_fonts_plot_text(int x, int y, const struct css_style *style, - const char *text, size_t length, colour bg, colour c); +static bool print_fonts_plot_text(int x, int y, const char *text, size_t length, + const plot_font_style_t *fstyle); static bool print_fonts_plot_disc(int x, int y, int radius, const plot_style_t *style); static bool print_fonts_plot_arc(int x, int y, int radius, int angle1, int angle2, const plot_style_t *style); static bool print_fonts_plot_bitmap(int x, int y, int width, int height, @@ -852,15 +852,15 @@ bool print_fonts_plot_path(const float *p, unsigned int n, colour fill, float wi * Plotter for text plotting during font listing. */ -bool print_fonts_plot_text(int x, int y, const struct css_style *style, - const char *text, size_t length, colour bg, colour c) +bool print_fonts_plot_text(int x, int y, const char *text, size_t length, + const plot_font_style_t *fstyle) { const char *font_family; unsigned int font_size; rufl_style font_style; rufl_code code; - nsfont_read_style(style, &font_family, &font_size, &font_style); + nsfont_read_style(fstyle, &font_family, &font_size, &font_style); code = rufl_paint_callback(font_family, font_style, font_size, text, length, 0, 0, print_fonts_callback, 0); diff --git a/riscos/save_draw.c b/riscos/save_draw.c index 6dbd50ddb..1a75ee5f0 100644 --- a/riscos/save_draw.c +++ b/riscos/save_draw.c @@ -44,8 +44,8 @@ static bool ro_save_draw_path(const float *p, unsigned int n, colour fill, float width, colour c, const float transform[6]); static bool ro_save_draw_clip(int clip_x0, int clip_y0, int clip_x1, int clip_y1); -static bool ro_save_draw_text(int x, int y, const struct css_style *style, - const char *text, size_t length, colour bg, colour c); +static bool ro_save_draw_text(int x, int y, const char *text, size_t length, + const plot_font_style_t *fstyle); static bool ro_save_draw_disc(int x, int y, int radius, const plot_style_t *style); static bool ro_save_draw_arc(int x, int y, int radius, int angle1, int angle2, const plot_style_t *style); @@ -348,18 +348,19 @@ bool ro_save_draw_clip(int clip_x0, int clip_y0, } -bool ro_save_draw_text(int x, int y, const struct css_style *style, - const char *text, size_t length, colour bg, colour c) +bool ro_save_draw_text(int x, int y, const char *text, size_t length, + const plot_font_style_t *fstyle) { pencil_code code; const char *font_family; unsigned int font_size; rufl_style font_style; - nsfont_read_style(style, &font_family, &font_size, &font_style); + nsfont_read_style(fstyle, &font_family, &font_size, &font_style); code = pencil_text(ro_save_draw_diagram, x * 2, -y * 2, font_family, - font_style, font_size, text, length, c << 8); + font_style, font_size, text, length, + fstyle->foreground << 8); if (code != pencil_OK) return ro_save_draw_error(code);