2009-07-21 14:59:53 +04:00
|
|
|
/*
|
|
|
|
* Copyright 2009 John-Mark Bell <jmb@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/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2014-10-13 14:56:31 +04:00
|
|
|
* \file
|
2009-07-21 14:59:53 +04:00
|
|
|
*
|
2018-05-10 13:34:26 +03:00
|
|
|
* HTML internal font handling implementation.
|
2009-07-21 14:59:53 +04:00
|
|
|
*/
|
2009-07-24 03:05:34 +04:00
|
|
|
|
2014-10-13 14:56:31 +04:00
|
|
|
#include "utils/nsoption.h"
|
2017-01-13 13:01:25 +03:00
|
|
|
#include "netsurf/plot_style.h"
|
2016-06-06 16:47:27 +03:00
|
|
|
#include "css/utils.h"
|
2009-07-21 14:59:53 +04:00
|
|
|
|
2018-05-10 13:34:26 +03:00
|
|
|
#include "html/font.h"
|
2009-07-21 14:59:53 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Map a generic CSS font family to a generic plot font family
|
|
|
|
*
|
2018-05-10 13:34:26 +03:00
|
|
|
* \param css Generic CSS font family
|
2009-07-21 14:59:53 +04:00
|
|
|
* \return Plot font family
|
|
|
|
*/
|
2018-05-10 13:34:26 +03:00
|
|
|
static plot_font_generic_family_t
|
|
|
|
plot_font_generic_family(enum css_font_family_e css)
|
2009-07-21 14:59:53 +04:00
|
|
|
{
|
|
|
|
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
|
|
|
|
*/
|
2014-10-13 14:56:31 +04:00
|
|
|
static int plot_font_weight(enum css_font_weight_e css)
|
2009-07-21 14:59:53 +04:00
|
|
|
{
|
|
|
|
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
|
2014-10-13 14:56:31 +04:00
|
|
|
*
|
2009-07-21 14:59:53 +04:00
|
|
|
* \param style CSS font style
|
|
|
|
* \param variant CSS font variant
|
|
|
|
* \return Computed plot flags
|
|
|
|
*/
|
2014-10-13 14:56:31 +04:00
|
|
|
static plot_font_flags_t plot_font_flags(enum css_font_style_e style,
|
2009-08-02 23:19:43 +04:00
|
|
|
enum css_font_variant_e variant)
|
2009-07-21 14:59:53 +04:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2014-10-13 14:56:31 +04:00
|
|
|
|
2018-05-10 13:34:26 +03:00
|
|
|
/* exported function documented in html/font.h */
|
2018-01-04 02:58:18 +03:00
|
|
|
void font_plot_style_from_css(
|
2021-03-29 12:45:59 +03:00
|
|
|
const css_unit_ctx *unit_len_ctx,
|
2018-01-04 02:58:18 +03:00
|
|
|
const css_computed_style *css,
|
2014-10-13 14:56:31 +04:00
|
|
|
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));
|
2018-05-23 16:02:53 +03:00
|
|
|
fstyle->families = families;
|
2014-10-13 14:56:31 +04:00
|
|
|
|
|
|
|
css_computed_font_size(css, &length, &unit);
|
2021-03-29 12:45:59 +03:00
|
|
|
fstyle->size = FIXTOINT(FMUL(css_unit_font_size_len2pt(css,
|
|
|
|
unit_len_ctx, length, unit),
|
2018-05-23 13:48:35 +03:00
|
|
|
INTTOFIX(PLOT_STYLE_SCALE)));
|
2014-10-13 14:56:31 +04:00
|
|
|
|
|
|
|
/* Clamp font size to configured minimum */
|
2018-05-23 13:48:35 +03:00
|
|
|
if (fstyle->size < (nsoption_int(font_min_size) * PLOT_STYLE_SCALE) / 10)
|
|
|
|
fstyle->size = (nsoption_int(font_min_size) * PLOT_STYLE_SCALE) / 10;
|
2014-10-13 14:56:31 +04:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|