mirror of
https://github.com/netsurf-browser/netsurf
synced 2024-12-22 04:02:34 +03:00
Plotters: Add plot_style_fixed type, and use for font size.
This commit is contained in:
parent
6cabd4cd62
commit
a58d97a41a
@ -244,7 +244,7 @@ bool box_textarea_create_textarea(html_content *html,
|
||||
textarea_flags ta_flags;
|
||||
plot_font_style_t fstyle = {
|
||||
.family = PLOT_FONT_FAMILY_SANS_SERIF,
|
||||
.size = 10 * FONT_SIZE_SCALE,
|
||||
.size = 10 * PLOT_STYLE_SCALE,
|
||||
.weight = 400,
|
||||
.flags = FONTF_NONE,
|
||||
.background = 0,
|
||||
|
@ -147,11 +147,11 @@ void font_plot_style_from_css(
|
||||
|
||||
css_computed_font_size(css, &length, &unit);
|
||||
fstyle->size = FIXTOINT(FMUL(nscss_len2pt(len_ctx, length, unit),
|
||||
INTTOFIX(FONT_SIZE_SCALE)));
|
||||
INTTOFIX(PLOT_STYLE_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;
|
||||
if (fstyle->size < (nsoption_int(font_min_size) * PLOT_STYLE_SCALE) / 10)
|
||||
fstyle->size = (nsoption_int(font_min_size) * PLOT_STYLE_SCALE) / 10;
|
||||
|
||||
fstyle->weight = plot_font_weight(css_computed_font_weight(css));
|
||||
fstyle->flags = plot_font_flags(css_computed_font_style(css),
|
||||
|
@ -1160,7 +1160,7 @@ bool form_open_select_menu(void *client_data,
|
||||
|
||||
menu->line_height = FIXTOINT(FDIV((FMUL(FLTTOFIX(1.2),
|
||||
FMUL(nscss_screen_dpi,
|
||||
INTTOFIX(fstyle.size / FONT_SIZE_SCALE)))),
|
||||
INTTOFIX(fstyle.size / PLOT_STYLE_SCALE)))),
|
||||
F_72));
|
||||
|
||||
line_height_with_spacing = menu->line_height +
|
||||
|
@ -210,7 +210,7 @@ svg_redraw_internal(struct content *c,
|
||||
|
||||
fstyle.background = 0xffffff;
|
||||
fstyle.foreground = 0x000000;
|
||||
fstyle.size = (8 * FONT_SIZE_SCALE) * scale;
|
||||
fstyle.size = (8 * PLOT_STYLE_SCALE) * scale;
|
||||
|
||||
res = ctx->plot->text(ctx,
|
||||
&fstyle,
|
||||
|
@ -86,7 +86,7 @@ typedef struct textplain_content {
|
||||
#define MARGIN 4
|
||||
|
||||
#define TAB_WIDTH 8 /* must be power of 2 currently */
|
||||
#define TEXT_SIZE 10 * FONT_SIZE_SCALE /* Unscaled text size in pt */
|
||||
#define TEXT_SIZE 10 * PLOT_STYLE_SCALE /* Unscaled text size in pt */
|
||||
|
||||
static plot_font_style_t textplain_style = {
|
||||
.family = PLOT_FONT_FAMILY_MONOSPACE,
|
||||
@ -149,7 +149,7 @@ textplain_create_internal(textplain_content *c, lwc_string *encoding)
|
||||
parserutils_inputstream *stream;
|
||||
parserutils_error error;
|
||||
|
||||
textplain_style.size = (nsoption_int(font_size) * FONT_SIZE_SCALE) / 10;
|
||||
textplain_style.size = (nsoption_int(font_size) * PLOT_STYLE_SCALE) / 10;
|
||||
|
||||
utf8_data = malloc(CHUNK);
|
||||
if (utf8_data == NULL)
|
||||
@ -400,7 +400,7 @@ static 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 FIXTOFLT(FDIV((FMUL(FLTTOFIX(1.2), FMUL(nscss_screen_dpi, INTTOFIX((textplain_style.size / FONT_SIZE_SCALE))))), F_72));
|
||||
return FIXTOFLT(FDIV((FMUL(FLTTOFIX(1.2), FMUL(nscss_screen_dpi, INTTOFIX((textplain_style.size / PLOT_STYLE_SCALE))))), F_72));
|
||||
}
|
||||
|
||||
|
||||
|
@ -352,7 +352,7 @@ bool haru_nsfont_apply_style(const plot_font_style_t *fstyle,
|
||||
if (size <= 0)
|
||||
return true;
|
||||
|
||||
size /= FONT_SIZE_SCALE;
|
||||
size /= PLOT_STYLE_SCALE;
|
||||
|
||||
if (size > HPDF_MAX_FONTSIZE)
|
||||
size = HPDF_MAX_FONTSIZE;
|
||||
|
@ -90,7 +90,7 @@ static plot_style_t pstyle_rect_sel = {
|
||||
*/
|
||||
static plot_font_style_t pfstyle_node = {
|
||||
.family = PLOT_FONT_FAMILY_SANS_SERIF,
|
||||
.size = 8 * FONT_SIZE_SCALE,
|
||||
.size = 8 * PLOT_STYLE_SCALE,
|
||||
.weight = 400,
|
||||
.flags = FONTF_NONE,
|
||||
};
|
||||
@ -101,7 +101,7 @@ static plot_font_style_t pfstyle_node = {
|
||||
*/
|
||||
static plot_font_style_t pfstyle_node_sel = {
|
||||
.family = PLOT_FONT_FAMILY_SANS_SERIF,
|
||||
.size = 8 * FONT_SIZE_SCALE,
|
||||
.size = 8 * PLOT_STYLE_SCALE,
|
||||
.weight = 900,
|
||||
.flags = FONTF_NONE,
|
||||
};
|
||||
|
@ -81,7 +81,7 @@ plot_style_t const * const plot_style_broken_object =
|
||||
|
||||
static const plot_font_style_t plot_fstyle_broken_object_static = {
|
||||
.family = PLOT_FONT_FAMILY_SANS_SERIF,
|
||||
.size = 16 * FONT_SIZE_SCALE,
|
||||
.size = 16 * PLOT_STYLE_SCALE,
|
||||
.weight = 400,
|
||||
.flags = FONTF_NONE,
|
||||
.background = 0x8888ff,
|
||||
@ -156,7 +156,7 @@ plot_style_t *plot_style_stroke_lightwbasec = &plot_style_stroke_lightwbasec_sta
|
||||
/* Generic font style */
|
||||
static const plot_font_style_t plot_style_font_static = {
|
||||
.family = PLOT_FONT_FAMILY_SANS_SERIF,
|
||||
.size = 8 * FONT_SIZE_SCALE,
|
||||
.size = 8 * PLOT_STYLE_SCALE,
|
||||
.weight = 400,
|
||||
.flags = FONTF_NONE,
|
||||
.background = 0xffffff,
|
||||
|
@ -1805,7 +1805,7 @@ static void textarea_setup_text_offsets(struct textarea *ta)
|
||||
|
||||
ta->line_height = FIXTOINT(FMUL(FLTTOFIX(1.3), FDIV(FMUL(
|
||||
nscss_screen_dpi, FDIV(INTTOFIX(ta->fstyle.size),
|
||||
INTTOFIX(FONT_SIZE_SCALE))), F_72)));
|
||||
INTTOFIX(PLOT_STYLE_SCALE))), F_72)));
|
||||
|
||||
text_y_offset = text_y_offset_baseline = ta->border_width;
|
||||
if (ta->flags & TEXTAREA_MULTILINE) {
|
||||
@ -1948,7 +1948,7 @@ struct textarea *textarea_create(const textarea_flags flags,
|
||||
|
||||
ret->line_height = FIXTOINT(FMUL(FLTTOFIX(1.3), FDIV(FMUL(
|
||||
nscss_screen_dpi, FDIV(INTTOFIX(setup->text.size),
|
||||
INTTOFIX(FONT_SIZE_SCALE))), F_72)));
|
||||
INTTOFIX(PLOT_STYLE_SCALE))), F_72)));
|
||||
|
||||
ret->caret_pos.line = ret->caret_pos.byte_off = -1;
|
||||
ret->caret_x = 0;
|
||||
|
@ -5195,7 +5195,7 @@ nserror treeview_init(void)
|
||||
10 + 36) / 72;
|
||||
tree_g.line_height = (font_px_size * 8 + 3) / 6;
|
||||
|
||||
res = treeview_init_plot_styles(font_pt_size * FONT_SIZE_SCALE / 10);
|
||||
res = treeview_init_plot_styles(font_pt_size * PLOT_STYLE_SCALE / 10);
|
||||
if (res != NSERROR_OK) {
|
||||
return res;
|
||||
}
|
||||
|
@ -63,7 +63,7 @@
|
||||
#define NSA_VALUE_SHEARSIN (1 << 14)
|
||||
#define NSA_VALUE_SHEARCOS (1 << 16)
|
||||
|
||||
#define NSA_FONT_EMWIDTH(s) (s / FONT_SIZE_SCALE) * (ami_font_dpi_get_xdpi() / 72.0)
|
||||
#define NSA_FONT_EMWIDTH(s) (s / PLOT_STYLE_SCALE) * (ami_font_dpi_get_xdpi() / 72.0)
|
||||
|
||||
const uint16 sc_table[] = {
|
||||
0x0061, 0x1D00, /* a */
|
||||
@ -512,7 +512,7 @@ static struct OutlineFont *ami_open_outline_font(const plot_font_style_t *fstyle
|
||||
}
|
||||
|
||||
/* Scale to 16.16 fixed point */
|
||||
ysize = fstyle->size * ((1 << 16) / FONT_SIZE_SCALE);
|
||||
ysize = fstyle->size * ((1 << 16) / PLOT_STYLE_SCALE);
|
||||
|
||||
if(designed_node == NULL) {
|
||||
ofont = node->font;
|
||||
|
@ -97,7 +97,7 @@ static struct TextFont *ami_font_bm_open(struct RastPort *rp, const plot_font_st
|
||||
|
||||
snprintf(font, MAX_FONT_NAME_SIZE, "%s.font", fontname);
|
||||
tattr.ta_Name = font;
|
||||
tattr.ta_YSize = fstyle->size / FONT_SIZE_SCALE;
|
||||
tattr.ta_YSize = fstyle->size / PLOT_STYLE_SCALE;
|
||||
NSLOG(netsurf, INFO, "font: %s/%d", tattr.ta_Name, tattr.ta_YSize);
|
||||
|
||||
if(prev_font != NULL) CloseFont(prev_font);
|
||||
|
@ -250,7 +250,7 @@ static void ft_fill_scalar(const plot_font_style_t *fstyle, FTC_Scaler srec)
|
||||
|
||||
srec->face_id = (FTC_FaceID)font_faces[selected_face];
|
||||
|
||||
srec->width = srec->height = (fstyle->size * 64) / FONT_SIZE_SCALE;
|
||||
srec->width = srec->height = (fstyle->size * 64) / PLOT_STYLE_SCALE;
|
||||
srec->pixel = 0;
|
||||
|
||||
/* calculate x/y resolution, when browser_get_dpi() isn't available */
|
||||
|
@ -106,9 +106,9 @@ static int str_width( FONT_PLOTTER self,const plot_font_style_t *fstyle, const c
|
||||
fx |= 1;
|
||||
vst_effects( self->vdi_handle, fx );
|
||||
/* TODO: replace 90 with global dpi setting */
|
||||
//pxsize = ceil( (fstyle->size/FONT_SIZE_SCALE) * 90 / 72 );
|
||||
//pxsize = ceil( (fstyle->size/PLOT_STYLE_SCALE) * 90 / 72 );
|
||||
//vst_height( self->vdi_handle, pxsize ,&cw, &ch, &cellw, &cellh);
|
||||
pxsize = ceil( (fstyle->size/FONT_SIZE_SCALE) * 90 );
|
||||
pxsize = ceil( (fstyle->size/PLOT_STYLE_SCALE) * 90 );
|
||||
vst_point( self->vdi_handle, pxsize, &cw, &ch, &cellw, &cellh);
|
||||
/*
|
||||
if(slen != utf8_bounded_length(str, length)){
|
||||
@ -148,10 +148,10 @@ static int str_split( FONT_PLOTTER self, const plot_font_style_t * fstyle, const
|
||||
if( fstyle->weight > 450 )
|
||||
fx |= 1;
|
||||
vst_effects( self->vdi_handle, fx );
|
||||
//pxsize = ceil( (fstyle->size/FONT_SIZE_SCALE) * 90 / 72 );
|
||||
//pxsize = ceil( (fstyle->size/PLOT_STYLE_SCALE) * 90 / 72 );
|
||||
//vst_height( self->vdi_handle, pxsize ,&cw, &ch, &cellw, &cellh);
|
||||
|
||||
pxsize = ceil( (fstyle->size/FONT_SIZE_SCALE) * 90 );
|
||||
pxsize = ceil( (fstyle->size/PLOT_STYLE_SCALE) * 90 );
|
||||
vst_point( self->vdi_handle, pxsize, &cw, &ch, &cellw, &cellh);
|
||||
*actual_x = 0;
|
||||
//*char_offset = 0;
|
||||
@ -216,7 +216,7 @@ static int pixel_pos( FONT_PLOTTER self, const plot_font_style_t * fstyle,const
|
||||
if( fstyle->weight > 450 )
|
||||
fx |= 1;
|
||||
vst_effects(self->vdi_handle, fx);
|
||||
pxsize = ceil( (fstyle->size/FONT_SIZE_SCALE) * 90 / 72 );
|
||||
pxsize = ceil( (fstyle->size/PLOT_STYLE_SCALE) * 90 / 72 );
|
||||
vst_height( self->vdi_handle, pxsize ,&cw, &ch, &cellw, &cellh);
|
||||
*actual_x = 0;
|
||||
*char_offset = 0;
|
||||
@ -283,8 +283,8 @@ static int text( FONT_PLOTTER self, int x, int y, const char *text, size_t leng
|
||||
|
||||
/* TODO: netsurf uses 90 as default dpi ( somewhere defined in libcss),
|
||||
use that value or pass it as arg, to reduce netsurf dependency */
|
||||
//pxsize = ceil( (fstyle->size/FONT_SIZE_SCALE) * 90 / 72 );
|
||||
pxsize = ceil( (fstyle->size/FONT_SIZE_SCALE) * 90 / 72 );
|
||||
//pxsize = ceil( (fstyle->size/PLOT_STYLE_SCALE) * 90 / 72 );
|
||||
pxsize = ceil( (fstyle->size/PLOT_STYLE_SCALE) * 90 / 72 );
|
||||
|
||||
plot_get_dimensions(&canvas);
|
||||
x += canvas.g_x;
|
||||
|
@ -94,7 +94,7 @@ static float toolbar_url_scale = 1.0;
|
||||
|
||||
static plot_font_style_t font_style_url = {
|
||||
.family = PLOT_FONT_FAMILY_SANS_SERIF,
|
||||
.size = 14*FONT_SIZE_SCALE,
|
||||
.size = 14*PLOT_STYLE_SCALE,
|
||||
.weight = 400,
|
||||
.flags = FONTF_NONE,
|
||||
.background = 0xffffff,
|
||||
@ -302,7 +302,7 @@ struct s_toolbar *toolbar_create(struct s_gui_win_root *owner)
|
||||
|
||||
/* create the url widget: */
|
||||
font_style_url.size =
|
||||
toolbar_styles[t->style].font_height_pt * FONT_SIZE_SCALE;
|
||||
toolbar_styles[t->style].font_height_pt * PLOT_STYLE_SCALE;
|
||||
|
||||
textarea_flags ta_flags = TEXTAREA_INTERNAL_CARET;
|
||||
textarea_setup ta_setup;
|
||||
|
@ -130,7 +130,7 @@ void nsbeos_style_to_font(BFont &font, const struct plot_font_style *fstyle)
|
||||
}
|
||||
|
||||
//fprintf(stderr, "nsbeos_style_to_font: value %f unit %d\n", style->font_size.value.length.value, style->font_size.value.length.unit);
|
||||
size = fstyle->size / FONT_SIZE_SCALE;
|
||||
size = fstyle->size / PLOT_STYLE_SCALE;
|
||||
|
||||
//fprintf(stderr, "nsbeos_style_to_font: %f %d\n", size, style->font_size.value.length.unit);
|
||||
|
||||
|
@ -71,7 +71,7 @@ fb_text_font_style(fbtk_widget_t *widget, int *font_height, int *padding,
|
||||
#endif
|
||||
|
||||
font_style->family = PLOT_FONT_FAMILY_SANS_SERIF;
|
||||
font_style->size = px_to_pt(*font_height * FONT_SIZE_SCALE);
|
||||
font_style->size = px_to_pt(*font_height * PLOT_STYLE_SCALE);
|
||||
font_style->weight = 400;
|
||||
font_style->flags = FONTF_NONE;
|
||||
font_style->background = widget->bg;
|
||||
|
@ -392,7 +392,7 @@ static void fb_fill_scalar(const plot_font_style_t *fstyle, FTC_Scaler srec)
|
||||
|
||||
srec->face_id = (FTC_FaceID)fb_faces[selected_face];
|
||||
|
||||
srec->width = srec->height = (fstyle->size * 64) / FONT_SIZE_SCALE;
|
||||
srec->width = srec->height = (fstyle->size * 64) / PLOT_STYLE_SCALE;
|
||||
srec->pixel = 0;
|
||||
|
||||
srec->x_res = srec->y_res = browser_get_dpi();
|
||||
|
@ -212,7 +212,7 @@ fb_get_font_size(const plot_font_style_t *fstyle)
|
||||
{
|
||||
int size = fstyle->size * 10 /
|
||||
(((nsoption_int(font_min_size) * 3 +
|
||||
nsoption_int(font_size)) / 4) * FONT_SIZE_SCALE);
|
||||
nsoption_int(font_size)) / 4) * PLOT_STYLE_SCALE);
|
||||
if (size > 2)
|
||||
size = 2;
|
||||
else if (size <= 0)
|
||||
|
@ -277,7 +277,7 @@ nsfont_style_to_description(const plot_font_style_t *fstyle)
|
||||
break;
|
||||
}
|
||||
|
||||
size = (fstyle->size * PANGO_SCALE) / FONT_SIZE_SCALE;
|
||||
size = (fstyle->size * PANGO_SCALE) / PLOT_STYLE_SCALE;
|
||||
|
||||
if (fstyle->flags & FONTF_ITALIC)
|
||||
style = PANGO_STYLE_ITALIC;
|
||||
|
@ -33,7 +33,7 @@ static nserror nsfont_width(const plot_font_style_t *fstyle,
|
||||
const char *string, size_t length,
|
||||
int *width)
|
||||
{
|
||||
*width = (fstyle->size * utf8_bounded_length(string, length)) / FONT_SIZE_SCALE;
|
||||
*width = (fstyle->size * utf8_bounded_length(string, length)) / PLOT_STYLE_SCALE;
|
||||
return NSERROR_OK;
|
||||
}
|
||||
|
||||
@ -53,10 +53,10 @@ static nserror 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)
|
||||
{
|
||||
*char_offset = x / (fstyle->size / FONT_SIZE_SCALE);
|
||||
*char_offset = x / (fstyle->size / PLOT_STYLE_SCALE);
|
||||
if (*char_offset > length)
|
||||
*char_offset = length;
|
||||
*actual_x = *char_offset * (fstyle->size / FONT_SIZE_SCALE);
|
||||
*actual_x = *char_offset * (fstyle->size / PLOT_STYLE_SCALE);
|
||||
return NSERROR_OK;
|
||||
}
|
||||
|
||||
@ -88,7 +88,7 @@ static nserror nsfont_split(const plot_font_style_t *fstyle,
|
||||
const char *string, size_t length,
|
||||
int x, size_t *char_offset, int *actual_x)
|
||||
{
|
||||
int c_off = *char_offset = x / (fstyle->size / FONT_SIZE_SCALE);
|
||||
int c_off = *char_offset = x / (fstyle->size / PLOT_STYLE_SCALE);
|
||||
if (*char_offset > length) {
|
||||
*char_offset = length;
|
||||
} else {
|
||||
@ -104,7 +104,7 @@ static nserror nsfont_split(const plot_font_style_t *fstyle,
|
||||
}
|
||||
}
|
||||
}
|
||||
*actual_x = *char_offset * (fstyle->size / FONT_SIZE_SCALE);
|
||||
*actual_x = *char_offset * (fstyle->size / PLOT_STYLE_SCALE);
|
||||
return NSERROR_OK;
|
||||
}
|
||||
|
||||
|
@ -469,7 +469,7 @@ void nsfont_read_style(const plot_font_style_t *fstyle,
|
||||
rufl_WEIGHT_900
|
||||
};
|
||||
|
||||
*font_size = (fstyle->size * 16) / FONT_SIZE_SCALE;
|
||||
*font_size = (fstyle->size * 16) / PLOT_STYLE_SCALE;
|
||||
if (1600 < *font_size)
|
||||
*font_size = 1600;
|
||||
|
||||
|
@ -120,7 +120,7 @@ HFONT get_font(const plot_font_style_t *style)
|
||||
int nHeight = -10;
|
||||
|
||||
HDC hdc = GetDC(font_hwnd);
|
||||
nHeight = -MulDiv(style->size, GetDeviceCaps(hdc, LOGPIXELSY), 72 * FONT_SIZE_SCALE);
|
||||
nHeight = -MulDiv(style->size, GetDeviceCaps(hdc, LOGPIXELSY), 72 * PLOT_STYLE_SCALE);
|
||||
ReleaseDC(font_hwnd, hdc);
|
||||
|
||||
HFONT font = CreateFont(
|
||||
|
@ -36,8 +36,14 @@
|
||||
/** Transparent colour value. */
|
||||
#define NS_TRANSPARENT 0x01000000
|
||||
|
||||
/** Scaling factor for font sizes */
|
||||
#define FONT_SIZE_SCALE 1024
|
||||
/** 22:10 fixed point */
|
||||
#define PLOT_STYLE_RADIX (10)
|
||||
|
||||
/** Scaling factor for plot styles */
|
||||
#define PLOT_STYLE_SCALE (1 << PLOT_STYLE_RADIX)
|
||||
|
||||
/* type for fixed point numbers */
|
||||
typedef int32_t plot_style_fixed;
|
||||
|
||||
/**
|
||||
* Type of plot operation
|
||||
@ -90,7 +96,7 @@ typedef enum {
|
||||
*/
|
||||
typedef struct plot_font_style {
|
||||
plot_font_generic_family_t family; /**< Generic family to plot with */
|
||||
int size; /**< Font size, in points * FONT_SIZE_SCALE */
|
||||
plot_style_fixed size; /**< Font size, in pt */
|
||||
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 */
|
||||
|
Loading…
Reference in New Issue
Block a user