Put the font operations table alongside all the other core API

The netsurf core is driven from numerous operation tables most of
which are now set through a common netsurf_register() interface. The
font and plotting interfaces are currently separate and unlike all the
other operation tables are modified for differing contexts.

This change moves the font operations alongside all the other
operations table and remove unnecessary interaction with the renderers
font internals. Further this also removes the need for css internals
to be visible in frontends.
This commit is contained in:
Vincent Sanders 2014-10-13 11:56:31 +01:00
parent 33c6073dbe
commit 17be8cf216
43 changed files with 273 additions and 239 deletions

View File

@ -26,7 +26,7 @@
#include "amiga/schedule.h" #include "amiga/schedule.h"
#include "utils/nsoption.h" #include "utils/nsoption.h"
#include "desktop/browser.h" #include "desktop/browser.h"
#include "render/font.h" #include "desktop/font.h"
#include "utils/log.h" #include "utils/log.h"
#include "utils/utf8.h" #include "utils/utf8.h"
#include "utils/utils.h" #include "utils/utils.h"

View File

@ -18,7 +18,7 @@
#include "desktop/printer.h" #include "desktop/printer.h"
#include "amiga/plotters.h" #include "amiga/plotters.h"
#include "render/font.h" #include "desktop/font.h"
#include "amiga/gui.h" #include "amiga/gui.h"
#include "utils/nsoption.h" #include "utils/nsoption.h"
#include "amiga/print.h" #include "amiga/print.h"

View File

@ -23,8 +23,6 @@
#include <assert.h> #include <assert.h>
#include <stdbool.h> #include <stdbool.h>
#include "css/css.h"
#include "render/font.h"
#include "utils/utf8.h" #include "utils/utf8.h"
struct gui_utf8_table *atari_utf8_table; struct gui_utf8_table *atari_utf8_table;

View File

@ -39,7 +39,7 @@
#include <stdbool.h> #include <stdbool.h>
#include "css/css.h" #include "css/css.h"
#include "render/font.h" #include "desktop/font.h"
#include "utils/utf8.h" #include "utils/utf8.h"
#include "utils/log.h" #include "utils/log.h"
#include "utils/nsoption.h" #include "utils/nsoption.h"

View File

@ -50,7 +50,7 @@
#include "desktop/browser.h" #include "desktop/browser.h"
#include "desktop/browser_private.h" #include "desktop/browser_private.h"
#include "desktop/mouse.h" #include "desktop/mouse.h"
#include "render/font.h" #include "desktop/font.h"
#include "atari/gemtk/gemtk.h" #include "atari/gemtk/gemtk.h"
#include "atari/gui.h" #include "atari/gui.h"

View File

@ -32,7 +32,7 @@
#include <View.h> #include <View.h>
extern "C" { extern "C" {
#include "css/css.h" #include "css/css.h"
#include "render/font.h" #include "desktop/font.h"
#include "utils/utils.h" #include "utils/utils.h"
#include "utils/log.h" #include "utils/log.h"
#include "utils/nsoption.h" #include "utils/nsoption.h"

View File

@ -32,7 +32,7 @@
#include <Shape.h> #include <Shape.h>
extern "C" { extern "C" {
#include "desktop/plotters.h" #include "desktop/plotters.h"
#include "render/font.h" #include "desktop/font.h"
#include "utils/log.h" #include "utils/log.h"
#include "utils/utils.h" #include "utils/utils.h"
#include "utils/nsoption.h" #include "utils/nsoption.h"

View File

@ -59,7 +59,7 @@ extern "C" {
#include "desktop/plotters.h" #include "desktop/plotters.h"
#include "utils/nsoption.h" #include "utils/nsoption.h"
#include "desktop/textinput.h" #include "desktop/textinput.h"
#include "render/font.h" #include "desktop/font.h"
#include "render/form.h" #include "render/form.h"
#include "utils/messages.h" #include "utils/messages.h"
#include "utils/utils.h" #include "utils/utils.h"

View File

@ -36,7 +36,7 @@ extern "C" {
#include "desktop/browser.h" #include "desktop/browser.h"
#include "desktop/thumbnail.h" #include "desktop/thumbnail.h"
#include "image/bitmap.h" #include "image/bitmap.h"
#include "render/font.h" #include "desktop/font.h"
#include "utils/log.h" #include "utils/log.h"
} }
#include "beos/scaffolding.h" #include "beos/scaffolding.h"

View File

@ -29,7 +29,7 @@ extern "C" {
#include "utils/nsoption.h" #include "utils/nsoption.h"
#include "desktop/netsurf.h" #include "desktop/netsurf.h"
#include "desktop/textinput.h" #include "desktop/textinput.h"
#include "render/font.h" #include "desktop/font.h"
#include "utils/log.h" #include "utils/log.h"
#include "utils/types.h" #include "utils/types.h"
#include "utils/utf8.h" #include "utils/utf8.h"

View File

@ -23,7 +23,7 @@
#import "css/css.h" #import "css/css.h"
#import "utils/nsoption.h" #import "utils/nsoption.h"
#import "render/font.h" #import "desktop/font.h"
#import "desktop/plotters.h" #import "desktop/plotters.h"

View File

@ -18,7 +18,7 @@
*/ */
/** \file /** \file
* Browser history tree (implementation). * Browser history tree implementation.
*/ */
#include <assert.h> #include <assert.h>
@ -27,20 +27,20 @@
#include <string.h> #include <string.h>
#include <time.h> #include <time.h>
#include "utils/log.h"
#include "utils/nsurl.h"
#include "utils/utils.h"
#include "content/content.h" #include "content/content.h"
#include "content/hlcache.h" #include "content/hlcache.h"
#include "content/urldb.h" #include "content/urldb.h"
#include "css/css.h" #include "css/css.h"
#include "image/bitmap.h"
#include "desktop/browser_history.h" #include "desktop/browser_history.h"
#include "desktop/browser_private.h" #include "desktop/browser_private.h"
#include "desktop/plotters.h" #include "desktop/plotters.h"
#include "desktop/thumbnail.h" #include "desktop/thumbnail.h"
#include "image/bitmap.h" #include "desktop/font.h"
#include "render/font.h"
#include "utils/log.h"
#include "utils/nsurl.h"
#include "utils/utils.h"
#define WIDTH 100 #define WIDTH 100
#define HEIGHT 86 #define HEIGHT 86

97
desktop/font.h Normal file
View File

@ -0,0 +1,97 @@
/*
* Copyright 2003 Phil Mellor <monkeyson@users.sourceforge.net>
* Copyright 2005 James Bursa <bursa@users.sourceforge.net>
* Copyright 2004 John Tytgat <joty@netsurf-browser.org>
*
* 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 <http://www.gnu.org/licenses/>.
*/
/** \file
* Font handling interface.
*
* These functions provide font related services. They all work on
* UTF-8 strings with lengths given.
*
* Note that an interface to painting is not defined here. Painting is
* redirected through platform-dependent plotters anyway, so there is
* no gain in abstracting it here.
*/
#ifndef _NETSURF_DESKTOP_FONT_H_
#define _NETSURF_DESKTOP_FONT_H_
#include <stdbool.h>
#include <stddef.h>
#include "desktop/plot_style.h"
struct font_functions
{
/**
* Measure the width of a string.
*
* \param fstyle plot style for this text
* \param string UTF-8 string to measure
* \param length length of string, in bytes
* \param width updated to width of string[0..length)
* \return true on success, false on error and error reported
*/
bool (*font_width)(const plot_font_style_t *fstyle,
const char *string, size_t length,
int *width);
/**
* Find the position in a string where an x coordinate falls.
*
* \param fstyle style for this text
* \param string UTF-8 string to measure
* \param length length of string, in bytes
* \param x x coordinate to search for
* \param char_offset updated to offset in string of actual_x, [0..length]
* \param actual_x updated to x coordinate of character closest to x
* \return true on success, false on error and error reported
*/
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);
/**
* Find where to split a string to make it fit a width.
*
* \param fstyle style for this text
* \param string UTF-8 string to measure
* \param length length of string, in bytes
* \param x width available
* \param char_offset updated to offset in string of actual_x, [1..length]
* \param actual_x updated to x coordinate of character closest to x
* \return true on success, false on error and error reported
*
* On exit, char_offset indicates first character after split point.
*
* Note: char_offset of 0 should never be returned.
*
* Returns:
* char_offset giving split point closest to x, where actual_x <= x
* else
* char_offset giving split point closest to x, where actual_x > x
*
* Returning char_offset == length means no split possible
*/
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;
#endif

View File

@ -41,7 +41,7 @@
#include "utils/nsoption.h" #include "utils/nsoption.h"
#include "desktop/save_pdf/font_haru.h" #include "desktop/save_pdf/font_haru.h"
#include "render/font.h" #include "desktop/font.h"
#include "utils/log.h" #include "utils/log.h"

View File

@ -26,8 +26,8 @@
#include <hpdf.h> #include <hpdf.h>
#include "render/font.h"
#include "desktop/plot_style.h" #include "desktop/plot_style.h"
#include "desktop/font.h"
bool haru_nsfont_apply_style(const plot_font_style_t *fstyle, bool haru_nsfont_apply_style(const plot_font_style_t *fstyle,
HPDF_Doc doc, HPDF_Page page, HPDF_Doc doc, HPDF_Page page,

View File

@ -28,21 +28,21 @@
#include <string.h> #include <string.h>
#include <dom/dom.h> #include <dom/dom.h>
#include "utils/log.h"
#include "utils/utf8.h"
#include "utils/utils.h"
#include "render/box.h"
#include "render/form.h"
#include "render/html_internal.h"
#include "render/font.h"
#include "render/textplain.h"
#include "desktop/browser_private.h" #include "desktop/browser_private.h"
#include "desktop/gui_factory.h" #include "desktop/gui_factory.h"
#include "desktop/mouse.h" #include "desktop/mouse.h"
#include "desktop/plotters.h" #include "desktop/plotters.h"
#include "desktop/save_text.h" #include "desktop/save_text.h"
#include "desktop/selection.h" #include "desktop/selection.h"
#include "render/box.h"
#include "render/font.h"
#include "render/form.h"
#include "render/html_internal.h"
#include "render/textplain.h"
#include "utils/log.h"
#include "utils/utf8.h"
#include "utils/utils.h"
/** /**
* Text selection works by labelling each node in the box tree with its * Text selection works by labelling each node in the box tree with its

View File

@ -23,18 +23,19 @@
#include <stdint.h> #include <stdint.h>
#include <string.h> #include <string.h>
#include "css/utils.h" #include "css/utils.h"
#include "utils/log.h"
#include "utils/utf8.h"
#include "utils/utils.h"
#include "desktop/mouse.h" #include "desktop/mouse.h"
#include "desktop/textarea.h" #include "desktop/textarea.h"
#include "desktop/textinput.h" #include "desktop/textinput.h"
#include "desktop/plotters.h" #include "desktop/plotters.h"
#include "desktop/scrollbar.h" #include "desktop/scrollbar.h"
#include "desktop/font.h"
#include "desktop/gui_factory.h" #include "desktop/gui_factory.h"
#include "render/font.h"
#include "utils/log.h"
#include "utils/utf8.h"
#include "utils/utils.h"
#define CARET_COLOR 0x0000FF #define CARET_COLOR 0x0000FF
#define TA_ALLOC_STEP 512 #define TA_ALLOC_STEP 512

View File

@ -21,7 +21,7 @@
*/ */
/** \file /** \file
* Textual input handling (implementation) * Textual input handling implementation
*/ */
#include <assert.h> #include <assert.h>
@ -29,21 +29,21 @@
#include <string.h> #include <string.h>
#include <dom/dom.h> #include <dom/dom.h>
#include "utils/log.h"
#include "utils/talloc.h"
#include "utils/utf8.h"
#include "utils/utils.h"
#include "render/box.h"
#include "render/form.h"
#include "render/html_internal.h"
#include "render/layout.h"
#include "desktop/browser_private.h" #include "desktop/browser_private.h"
#include "desktop/gui_factory.h" #include "desktop/gui_factory.h"
#include "desktop/mouse.h" #include "desktop/mouse.h"
#include "desktop/scrollbar.h" #include "desktop/scrollbar.h"
#include "desktop/selection.h" #include "desktop/selection.h"
#include "desktop/textinput.h" #include "desktop/textinput.h"
#include "render/box.h"
#include "render/font.h"
#include "render/form.h"
#include "render/html_internal.h"
#include "render/layout.h"
#include "utils/log.h"
#include "utils/talloc.h"
#include "utils/utf8.h"
#include "utils/utils.h"
/* Define to enable textinput debug */ /* Define to enable textinput debug */
#undef TEXTINPUT_DEBUG #undef TEXTINPUT_DEBUG

View File

@ -26,16 +26,17 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include "content/content.h"
#include "content/hlcache.h"
#include "css/utils.h"
#include "desktop/browser.h"
#include "desktop/tree.h"
#include "utils/nsoption.h"
#include "render/font.h"
#include "utils/log.h" #include "utils/log.h"
#include "utils/messages.h" #include "utils/messages.h"
#include "utils/utils.h" #include "utils/utils.h"
#include "content/content.h"
#include "content/hlcache.h"
#include "css/utils.h"
#include "utils/nsoption.h"
#include "desktop/browser.h"
#include "desktop/tree.h"
struct tree { struct tree {
unsigned int flags; /* Tree flags */ unsigned int flags; /* Tree flags */

View File

@ -16,14 +16,15 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
/** \file /**
* Treeview handling (implementation). * \file
*
* Treeview handling implementation.
*/ */
#include "utils/log.h" #include "utils/log.h"
#include "css/utils.h" #include "css/utils.h"
#include "image/bitmap.h" #include "image/bitmap.h"
#include "render/font.h"
#include "content/hlcache.h" #include "content/hlcache.h"
#include "desktop/system_colour.h" #include "desktop/system_colour.h"
@ -31,8 +32,9 @@
#include "desktop/plotters.h" #include "desktop/plotters.h"
#include "desktop/textarea.h" #include "desktop/textarea.h"
#include "desktop/treeview.h" #include "desktop/treeview.h"
#include "desktop/font.h"
/* TODO: get rid of REDRAW_MAX -- need to be able to know window size */ /** @todo get rid of REDRAW_MAX -- need to be able to know window size */
#define REDRAW_MAX 8000 #define REDRAW_MAX 8000
struct treeview_globals { struct treeview_globals {

View File

@ -29,7 +29,7 @@
#include "utils/log.h" #include "utils/log.h"
#include "desktop/browser.h" #include "desktop/browser.h"
#include "render/font.h" #include "desktop/font.h"
#include "framebuffer/gui.h" #include "framebuffer/gui.h"
#include "framebuffer/fbtk.h" #include "framebuffer/fbtk.h"

View File

@ -27,8 +27,8 @@
#include "utils/utf8.h" #include "utils/utf8.h"
#include "utils/log.h" #include "utils/log.h"
#include "utils/nsoption.h" #include "utils/nsoption.h"
#include "render/font.h"
#include "desktop/gui.h" #include "desktop/gui.h"
#include "desktop/font.h"
#include "desktop/browser.h" #include "desktop/browser.h"
#include "framebuffer/gui.h" #include "framebuffer/gui.h"

View File

@ -20,12 +20,12 @@
#include <inttypes.h> #include <inttypes.h>
#include <string.h> #include <string.h>
#include <assert.h> #include <assert.h>
#include <stdlib.h>
#include "utils/nsoption.h" #include "utils/nsoption.h"
#include "utils/utf8.h" #include "utils/utf8.h"
#include "desktop/gui.h" #include "desktop/gui.h"
#include "css/css.h" #include "desktop/font.h"
#include "render/font.h"
#include "framebuffer/gui.h" #include "framebuffer/gui.h"
#include "framebuffer/font.h" #include "framebuffer/font.h"

View File

@ -27,12 +27,13 @@
#include <stdio.h> #include <stdio.h>
#include <gtk/gtk.h> #include <gtk/gtk.h>
#include "gtk/font_pango.h"
#include "gtk/plotters.h"
#include "render/font.h"
#include "utils/utils.h" #include "utils/utils.h"
#include "utils/log.h" #include "utils/log.h"
#include "utils/nsoption.h" #include "utils/nsoption.h"
#include "desktop/font.h"
#include "gtk/font_pango.h"
#include "gtk/plotters.h"
static bool nsfont_width(const plot_font_style_t *fstyle, static bool nsfont_width(const plot_font_style_t *fstyle,
const char *string, size_t length, const char *string, size_t length,

View File

@ -33,7 +33,6 @@
#include "utils/log.h" #include "utils/log.h"
#include "desktop/plotters.h" #include "desktop/plotters.h"
#include "render/font.h"
#include "utils/nsoption.h" #include "utils/nsoption.h"
#include "gtk/font_pango.h" #include "gtk/font_pango.h"

View File

@ -31,19 +31,20 @@
#include <gdk/gdk.h> #include <gdk/gdk.h>
#include <gtk/gtk.h> #include <gtk/gtk.h>
#include "utils/log.h"
#include "utils/utils.h"
#include "content/content.h" #include "content/content.h"
#include "content/hlcache.h" #include "content/hlcache.h"
#include "utils/nsoption.h" #include "utils/nsoption.h"
#include "desktop/plotters.h" #include "desktop/plotters.h"
#include "desktop/print.h" #include "desktop/print.h"
#include "desktop/printer.h" #include "desktop/printer.h"
#include "desktop/font.h"
#include "gtk/font_pango.h" #include "gtk/font_pango.h"
#include "gtk/bitmap.h" #include "gtk/bitmap.h"
#include "gtk/print.h" #include "gtk/print.h"
#include "gtk/scaffolding.h" #include "gtk/scaffolding.h"
#include "render/font.h"
#include "utils/log.h"
#include "utils/utils.h"
/* Globals */ /* Globals */
cairo_t *gtk_print_current_cr; cairo_t *gtk_print_current_cr;

View File

@ -44,7 +44,7 @@
#include "desktop/save_text.h" #include "desktop/save_text.h"
#include "desktop/searchweb.h" #include "desktop/searchweb.h"
#include "desktop/textinput.h" #include "desktop/textinput.h"
#include "render/font.h" #include "desktop/font.h"
#include "render/html.h" #include "render/html.h"
#include "content/hlcache.h" #include "content/hlcache.h"

View File

@ -28,19 +28,19 @@
#include <gtk/gtk.h> #include <gtk/gtk.h>
#include <gdk/gdk.h> #include <gdk/gdk.h>
#include "utils/log.h"
#include "utils/utils.h"
#include "content/content.h" #include "content/content.h"
#include "content/hlcache.h" #include "content/hlcache.h"
#include "content/urldb.h" #include "content/urldb.h"
#include "desktop/plotters.h" #include "desktop/plotters.h"
#include "desktop/browser.h" #include "desktop/browser.h"
#include "desktop/thumbnail.h" #include "desktop/thumbnail.h"
#include "image/bitmap.h"
#include "gtk/scaffolding.h" #include "gtk/scaffolding.h"
#include "gtk/plotters.h" #include "gtk/plotters.h"
#include "gtk/bitmap.h" #include "gtk/bitmap.h"
#include "image/bitmap.h"
#include "render/font.h"
#include "utils/log.h"
#include "utils/utils.h"
/** /**
* Create a thumbnail of a page. * Create a thumbnail of a page.

View File

@ -16,10 +16,9 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "render/font.h"
#include "utils/nsoption.h" #include "utils/nsoption.h"
#include "utils/utf8.h" #include "utils/utf8.h"
#include "desktop/font.h"
static bool nsfont_width(const plot_font_style_t *fstyle, static bool nsfont_width(const plot_font_style_t *fstyle,
const char *string, size_t length, const char *string, size_t length,

View File

@ -25,10 +25,11 @@
#include "desktop/browser.h" #include "desktop/browser.h"
#include "desktop/textarea.h" #include "desktop/textarea.h"
#include "desktop/textinput.h" #include "desktop/textinput.h"
#include "utils/log.h"
#include "render/box_textarea.h" #include "render/box_textarea.h"
#include "render/font.h" #include "render/font.h"
#include "render/form.h" #include "render/form.h"
#include "utils/log.h"
bool box_textarea_keypress(html_content *html, struct box *box, uint32_t key) bool box_textarea_keypress(html_content *html, struct box *box, uint32_t key)

View File

@ -16,62 +16,25 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
/**
* \file
*
* Renderer internal font handling implementation.
*/
#include "css/css.h" #include "css/css.h"
#include "css/utils.h" #include "css/utils.h"
#include "utils/nsoption.h" #include "utils/nsoption.h"
#include "render/font.h" #include "render/font.h"
static plot_font_generic_family_t plot_font_generic_family(
enum css_font_family_e css);
static int plot_font_weight(enum css_font_weight_e css);
static plot_font_flags_t plot_font_flags(enum css_font_style_e style,
enum css_font_variant_e 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 css_computed_style *css,
plot_font_style_t *fstyle)
{
lwc_string **families;
css_fixed length = 0;
css_unit unit = CSS_UNIT_PX;
css_color col;
fstyle->family = plot_font_generic_family(
css_computed_font_family(css, &families));
css_computed_font_size(css, &length, &unit);
fstyle->size = FIXTOINT(FMUL(nscss_len2pt(length, unit),
INTTOFIX(FONT_SIZE_SCALE)));
/* Clamp font size to configured minimum */
if (fstyle->size < (nsoption_int(font_min_size) * FONT_SIZE_SCALE) / 10)
fstyle->size = (nsoption_int(font_min_size) * FONT_SIZE_SCALE) / 10;
fstyle->weight = plot_font_weight(css_computed_font_weight(css));
fstyle->flags = plot_font_flags(css_computed_font_style(css),
css_computed_font_variant(css));
css_computed_color(css, &col);
fstyle->foreground = nscss_color_to_ns(col);
fstyle->background = 0;
}
/******************************************************************************
* Helper functions *
******************************************************************************/
/** /**
* Map a generic CSS font family to a generic plot font family * Map a generic CSS font family to a generic plot font family
* *
* \param css Generic CSS font family * \param css Generic CSS font family
* \return Plot font family * \return Plot font family
*/ */
plot_font_generic_family_t plot_font_generic_family( static plot_font_generic_family_t plot_font_generic_family(
enum css_font_family_e css) enum css_font_family_e css)
{ {
plot_font_generic_family_t plot; plot_font_generic_family_t plot;
@ -104,7 +67,7 @@ plot_font_generic_family_t plot_font_generic_family(
* \param css CSS font weight * \param css CSS font weight
* \return Plot weight * \return Plot weight
*/ */
int plot_font_weight(enum css_font_weight_e css) static int plot_font_weight(enum css_font_weight_e css)
{ {
int weight; int weight;
@ -151,7 +114,7 @@ int plot_font_weight(enum css_font_weight_e css)
* \param variant CSS font variant * \param variant CSS font variant
* \return Computed plot flags * \return Computed plot flags
*/ */
plot_font_flags_t plot_font_flags(enum css_font_style_e style, static plot_font_flags_t plot_font_flags(enum css_font_style_e style,
enum css_font_variant_e variant) enum css_font_variant_e variant)
{ {
plot_font_flags_t flags = FONTF_NONE; plot_font_flags_t flags = FONTF_NONE;
@ -167,3 +130,32 @@ plot_font_flags_t plot_font_flags(enum css_font_style_e style,
return flags; return flags;
} }
/* exported function documented in render/font_internal.h */
void font_plot_style_from_css(const css_computed_style *css,
plot_font_style_t *fstyle)
{
lwc_string **families;
css_fixed length = 0;
css_unit unit = CSS_UNIT_PX;
css_color col;
fstyle->family = plot_font_generic_family(
css_computed_font_family(css, &families));
css_computed_font_size(css, &length, &unit);
fstyle->size = FIXTOINT(FMUL(nscss_len2pt(length, unit),
INTTOFIX(FONT_SIZE_SCALE)));
/* Clamp font size to configured minimum */
if (fstyle->size < (nsoption_int(font_min_size) * FONT_SIZE_SCALE) / 10)
fstyle->size = (nsoption_int(font_min_size) * FONT_SIZE_SCALE) / 10;
fstyle->weight = plot_font_weight(css_computed_font_weight(css));
fstyle->flags = plot_font_flags(css_computed_font_style(css),
css_computed_font_variant(css));
css_computed_color(css, &col);
fstyle->foreground = nscss_color_to_ns(col);
fstyle->background = 0;
}

View File

@ -1,7 +1,5 @@
/* /*
* Copyright 2003 Phil Mellor <monkeyson@users.sourceforge.net> * Copyright 2014 Vincent Sanders <vince@netsurf-browser.org>
* Copyright 2005 James Bursa <bursa@users.sourceforge.net>
* Copyright 2004 John Tytgat <joty@netsurf-browser.org>
* *
* This file is part of NetSurf, http://www.netsurf-browser.org/ * This file is part of NetSurf, http://www.netsurf-browser.org/
* *
@ -19,82 +17,22 @@
*/ */
/** \file /** \file
* Font handling (interface).
* *
* These functions provide font related services. They all work on UTF-8 strings * Internal font handling interfaces.
* with lengths given.
* *
* Note that an interface to painting is not defined here. Painting is * These functions provide font related services. They all work on
* redirected through platform-dependent plotters anyway, so there is no gain in * UTF-8 strings with lengths given.
* abstracting it here.
*/ */
#ifndef _NETSURF_RENDER_FONT_H_ #ifndef _NETSURF_RENDER_FONT_H_
#define _NETSURF_RENDER_FONT_H_ #define _NETSURF_RENDER_FONT_H_
#include <stdbool.h>
#include <stddef.h>
#include "css/css.h"
#include "desktop/plot_style.h"
struct font_functions
{
/** /**
* Measure the width of a string. * Populate a font style using data from a computed CSS style
* *
* \param fstyle plot style for this text * \param css Computed style to consider
* \param string UTF-8 string to measure * \param fstyle Font style to populate
* \param length length of string, in bytes
* \param width updated to width of string[0..length)
* \return true on success, false on error and error reported
*/ */
bool (*font_width)(const plot_font_style_t *fstyle,
const char *string, size_t length,
int *width);
/**
* Find the position in a string where an x coordinate falls.
*
* \param fstyle style for this text
* \param string UTF-8 string to measure
* \param length length of string, in bytes
* \param x x coordinate to search for
* \param char_offset updated to offset in string of actual_x, [0..length]
* \param actual_x updated to x coordinate of character closest to x
* \return true on success, false on error and error reported
*/
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);
/**
* Find where to split a string to make it fit a width.
*
* \param fstyle style for this text
* \param string UTF-8 string to measure
* \param length length of string, in bytes
* \param x width available
* \param char_offset updated to offset in string of actual_x, [1..length]
* \param actual_x updated to x coordinate of character closest to x
* \return true on success, false on error and error reported
*
* On exit, char_offset indicates first character after split point.
*
* Note: char_offset of 0 should never be returned.
*
* Returns:
* char_offset giving split point closest to x, where actual_x <= x
* else
* char_offset giving split point closest to x, where actual_x > x
*
* Returning char_offset == length means no split possible
*/
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 css_computed_style *css, void font_plot_style_from_css(const css_computed_style *css,
plot_font_style_t *fstyle); plot_font_style_t *fstyle);

View File

@ -33,6 +33,13 @@
#include <string.h> #include <string.h>
#include <dom/dom.h> #include <dom/dom.h>
#include "utils/corestrings.h"
#include "utils/log.h"
#include "utils/messages.h"
#include "utils/talloc.h"
#include "utils/url.h"
#include "utils/utf8.h"
#include "utils/utils.h"
#include "content/fetch.h" #include "content/fetch.h"
#include "content/hlcache.h" #include "content/hlcache.h"
#include "css/css.h" #include "css/css.h"
@ -43,19 +50,13 @@
#include "desktop/plotters.h" #include "desktop/plotters.h"
#include "desktop/scrollbar.h" #include "desktop/scrollbar.h"
#include "desktop/textarea.h" #include "desktop/textarea.h"
#include "render/box.h" #include "render/box.h"
#include "render/font.h" #include "render/font.h"
#include "render/form.h" #include "render/form.h"
#include "render/html.h" #include "render/html.h"
#include "render/html_internal.h" #include "render/html_internal.h"
#include "render/layout.h" #include "render/layout.h"
#include "utils/corestrings.h"
#include "utils/log.h"
#include "utils/messages.h"
#include "utils/talloc.h"
#include "utils/url.h"
#include "utils/utf8.h"
#include "utils/utils.h"
#define MAX_SELECT_HEIGHT 210 #define MAX_SELECT_HEIGHT 210
#define SELECT_LINE_SPACING 0.2 #define SELECT_LINE_SPACING 0.2

View File

@ -47,9 +47,9 @@
#include "image/bitmap.h" #include "image/bitmap.h"
#include "javascript/js.h" #include "javascript/js.h"
#include "desktop/gui_factory.h" #include "desktop/gui_factory.h"
#include "desktop/font.h"
#include "render/box.h" #include "render/box.h"
#include "render/font.h"
#include "render/form.h" #include "render/form.h"
#include "render/html_internal.h" #include "render/html_internal.h"
#include "render/imagemap.h" #include "render/imagemap.h"

View File

@ -28,6 +28,10 @@
#include <dom/dom.h> #include <dom/dom.h>
#include "utils/corestrings.h"
#include "utils/messages.h"
#include "utils/utils.h"
#include "utils/log.h"
#include "content/content.h" #include "content/content.h"
#include "content/hlcache.h" #include "content/hlcache.h"
#include "desktop/browser.h" #include "desktop/browser.h"
@ -39,6 +43,9 @@
#include "desktop/selection.h" #include "desktop/selection.h"
#include "desktop/textarea.h" #include "desktop/textarea.h"
#include "desktop/textinput.h" #include "desktop/textinput.h"
#include "desktop/font.h"
#include "javascript/js.h"
#include "render/box.h" #include "render/box.h"
#include "render/box_textarea.h" #include "render/box_textarea.h"
#include "render/font.h" #include "render/font.h"
@ -46,12 +53,6 @@
#include "render/html_internal.h" #include "render/html_internal.h"
#include "render/imagemap.h" #include "render/imagemap.h"
#include "render/search.h" #include "render/search.h"
#include "javascript/js.h"
#include "utils/corestrings.h"
#include "utils/messages.h"
#include "utils/utils.h"
#include "utils/log.h"
/** /**
* Get pointer shape for given box * Get pointer shape for given box

View File

@ -22,8 +22,10 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
/** \file /**
* Redraw of a CONTENT_HTML (implementation). * \file
*
* Redrawing CONTENT_HTML implementation.
*/ */
#include <assert.h> #include <assert.h>
@ -32,7 +34,11 @@
#include <string.h> #include <string.h>
#include <math.h> #include <math.h>
#include <dom/dom.h> #include <dom/dom.h>
#include "utils/config.h" #include "utils/config.h"
#include "utils/log.h"
#include "utils/messages.h"
#include "utils/utils.h"
#include "content/content_protected.h" #include "content/content_protected.h"
#include "css/css.h" #include "css/css.h"
#include "css/utils.h" #include "css/utils.h"
@ -42,18 +48,15 @@
#include "desktop/print.h" #include "desktop/print.h"
#include "desktop/scrollbar.h" #include "desktop/scrollbar.h"
#include "desktop/textarea.h" #include "desktop/textarea.h"
#include "desktop/font.h"
#include "image/bitmap.h" #include "image/bitmap.h"
#include "render/box.h" #include "render/box.h"
#include "render/font.h" #include "render/font.h"
#include "render/form.h" #include "render/form.h"
#include "render/html_internal.h" #include "render/html_internal.h"
#include "render/layout.h" #include "render/layout.h"
#include "render/search.h" #include "render/search.h"
#include "utils/log.h"
#include "utils/messages.h"
#include "utils/utils.h"
bool html_redraw_debug = false; bool html_redraw_debug = false;

View File

@ -41,21 +41,24 @@
#include <string.h> #include <string.h>
#include <math.h> #include <math.h>
#include <dom/dom.h> #include <dom/dom.h>
#include "utils/log.h"
#include "utils/talloc.h"
#include "utils/utils.h"
#include "css/css.h" #include "css/css.h"
#include "css/utils.h" #include "css/utils.h"
#include "content/content_protected.h" #include "content/content_protected.h"
#include "utils/nsoption.h" #include "utils/nsoption.h"
#include "desktop/scrollbar.h" #include "desktop/scrollbar.h"
#include "desktop/textarea.h" #include "desktop/textarea.h"
#include "desktop/font.h"
#include "render/box.h" #include "render/box.h"
#include "render/font.h" #include "render/font.h"
#include "render/form.h" #include "render/form.h"
#include "render/html_internal.h" #include "render/html_internal.h"
#include "render/layout.h" #include "render/layout.h"
#include "render/table.h" #include "render/table.h"
#include "utils/log.h"
#include "utils/talloc.h"
#include "utils/utils.h"
/* Define to enable layout debugging */ /* Define to enable layout debugging */

View File

@ -31,6 +31,12 @@
#include <parserutils/input/inputstream.h> #include <parserutils/input/inputstream.h>
#include <parserutils/charset/utf8.h> #include <parserutils/charset/utf8.h>
#include "utils/corestrings.h"
#include "utils/http.h"
#include "utils/log.h"
#include "utils/messages.h"
#include "utils/utils.h"
#include "utils/utf8.h"
#include "content/content_protected.h" #include "content/content_protected.h"
#include "content/hlcache.h" #include "content/hlcache.h"
#include "css/css.h" #include "css/css.h"
@ -41,17 +47,12 @@
#include "desktop/search.h" #include "desktop/search.h"
#include "desktop/selection.h" #include "desktop/selection.h"
#include "desktop/textinput.h" #include "desktop/textinput.h"
#include "render/font.h" #include "desktop/font.h"
#include "render/search.h" #include "render/search.h"
#include "render/textplain.h" #include "render/textplain.h"
#include "render/html.h" #include "render/html.h"
#include "render/search.h" #include "render/search.h"
#include "utils/corestrings.h"
#include "utils/http.h"
#include "utils/log.h"
#include "utils/messages.h"
#include "utils/utils.h"
#include "utils/utf8.h"
struct textplain_line { struct textplain_line {
size_t start; size_t start;

View File

@ -42,7 +42,6 @@
#include "utils/utils.h" #include "utils/utils.h"
#include "desktop/netsurf.h" #include "desktop/netsurf.h"
#include "desktop/browser.h" #include "desktop/browser.h"
#include "render/font.h"
#include "riscos/configure.h" #include "riscos/configure.h"
#include "riscos/cookies.h" #include "riscos/cookies.h"

View File

@ -29,13 +29,11 @@
#include <oslib/wimp.h> #include <oslib/wimp.h>
#include <oslib/wimpreadsysinfo.h> #include <oslib/wimpreadsysinfo.h>
#include "css/css.h"
#include "css/utils.h"
#include "render/font.h"
#include "utils/nsoption.h" #include "utils/nsoption.h"
#include "utils/log.h" #include "utils/log.h"
#include "utils/messages.h" #include "utils/messages.h"
#include "utils/utils.h" #include "utils/utils.h"
#include "desktop/font.h"
#include "riscos/gui.h" #include "riscos/gui.h"
#include "riscos/font.h" #include "riscos/font.h"

View File

@ -28,7 +28,6 @@
#include "utils/log.h" #include "utils/log.h"
#include "desktop/plotters.h" #include "desktop/plotters.h"
#include "render/font.h"
#include "riscos/bitmap.h" #include "riscos/bitmap.h"
#include "riscos/image.h" #include "riscos/image.h"
@ -36,7 +35,6 @@
#include "riscos/font.h" #include "riscos/font.h"
#include "riscos/oslib_pre7.h" #include "riscos/oslib_pre7.h"
static bool ro_plot_rectangle(int x0, int y0, int x1, int y1, const plot_style_t *style); static bool ro_plot_rectangle(int x0, int y0, int x1, int y1, const plot_style_t *style);
static bool ro_plot_line(int x0, int y0, int x1, int y1, const plot_style_t *style); static bool ro_plot_line(int x0, int y0, int x1, int y1, const plot_style_t *style);
static bool ro_plot_draw_path(const draw_path * const path, int width, static bool ro_plot_draw_path(const draw_path * const path, int width,

View File

@ -31,21 +31,21 @@
#include "oslib/colourtrans.h" #include "oslib/colourtrans.h"
#include "oslib/osfile.h" #include "oslib/osfile.h"
#include "oslib/osspriteop.h" #include "oslib/osspriteop.h"
#include "utils/nsoption.h"
#include "utils/log.h"
#include "content/content.h" #include "content/content.h"
#include "content/hlcache.h" #include "content/hlcache.h"
#include "content/urldb.h" #include "content/urldb.h"
#include "desktop/plotters.h" #include "desktop/plotters.h"
#include "desktop/thumbnail.h" #include "desktop/thumbnail.h"
#include "image/bitmap.h" #include "image/bitmap.h"
#include "render/font.h"
#include "riscos/bitmap.h" #include "riscos/bitmap.h"
#include "riscos/gui.h" #include "riscos/gui.h"
#include "utils/nsoption.h"
#include "riscos/oslib_pre7.h" #include "riscos/oslib_pre7.h"
#include "riscos/thumbnail.h" #include "riscos/thumbnail.h"
#include "riscos/tinct.h" #include "riscos/tinct.h"
#include "utils/log.h"
/* Whether we can use 32bpp sprites /* Whether we can use 32bpp sprites
*/ */

View File

@ -27,7 +27,7 @@
#include <windows.h> #include <windows.h>
#include "css/css.h" #include "css/css.h"
#include "render/font.h" #include "desktop/font.h"
#include "utils/nsoption.h" #include "utils/nsoption.h"
#include "utils/utf8.h" #include "utils/utf8.h"