From 6e13c2fb0a9b386bcca999a5744a655ec3721aad Mon Sep 17 00:00:00 2001 From: John Mark Bell Date: Tue, 21 Jul 2009 16:55:35 +0000 Subject: Scale font sizes, for better accuracy. svn path=/trunk/netsurf/; revision=8657 --- amiga/font.c | 6 +++--- beos/beos_font.cpp | 2 +- desktop/plot_style.h | 7 ++++++- desktop/save_pdf/font_haru.c | 4 +++- framebuffer/font_freetype.c | 2 +- gtk/font_pango.c | 6 +++--- render/font.c | 3 ++- riscos/font.c | 2 +- 8 files changed, 20 insertions(+), 12 deletions(-) diff --git a/amiga/font.c b/amiga/font.c index 6a707e512..cd7d834e2 100644 --- a/amiga/font.c +++ b/amiga/font.c @@ -270,12 +270,12 @@ struct OutlineFont *ami_open_outline_font(const plot_font_style_t *fstyle) ysize = fstyle->size; - if(ysize < (option_font_min_size / 10)) - ysize = option_font_min_size / 10; + if(ysize < (option_font_min_size / 10) * FONT_SIZE_SCALE) + ysize = (option_font_min_size / 10) * FONT_SIZE_SCALE; if(ESetInfo(&ofont->olf_EEngine, OT_DeviceDPI,(72<<16) | 72, - OT_PointHeight,(ysize<<16), + OT_PointHeight,(ysize<<16)/FONT_SIZE_SCALE, TAG_END) == OTERR_Success) { return ofont; diff --git a/beos/beos_font.cpp b/beos/beos_font.cpp index ef2f1dbdb..1d3060cb0 100644 --- a/beos/beos_font.cpp +++ b/beos/beos_font.cpp @@ -365,7 +365,7 @@ void nsbeos_style_to_font(BFont &font, const plot_font_style_t *style) } //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; + size = fstyle->size / FONT_SIZE_SCALE; //XXX: pango stuff ? if (size < abs(option_font_min_size / 10)) diff --git a/desktop/plot_style.h b/desktop/plot_style.h index 3b74a4efd..088f0d275 100644 --- a/desktop/plot_style.h +++ b/desktop/plot_style.h @@ -104,12 +104,17 @@ typedef unsigned long plot_font_flags_t; #define FONTF_OBLIQUE 2 #define FONTF_SMALLCAPS 4 +/** + * Scaling factor for font sizes + */ +#define FONT_SIZE_SCALE 1024 + /** * Font style for plotting */ typedef struct { plot_font_generic_family_t family; /**< Generic family to plot with */ - int size; /**< Font size, in points */ + int size; /**< Font size, in points * FONT_SIZE_SCALE */ 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 */ diff --git a/desktop/save_pdf/font_haru.c b/desktop/save_pdf/font_haru.c index faed7c168..0bf86c340 100644 --- a/desktop/save_pdf/font_haru.c +++ b/desktop/save_pdf/font_haru.c @@ -336,7 +336,7 @@ bool haru_nsfont_apply_style(const plot_font_style_t *fstyle, LOG(("Setting font: %s", font_name)); #endif - size = fstyle->size; + size = fstyle->size; if (font != NULL) size *= pdf_text_scale; @@ -344,6 +344,8 @@ bool haru_nsfont_apply_style(const plot_font_style_t *fstyle, if (size <= 0) return true; + size /= FONT_SIZE_SCALE; + if (size > HPDF_MAX_FONTSIZE) size = HPDF_MAX_FONTSIZE; diff --git a/framebuffer/font_freetype.c b/framebuffer/font_freetype.c index a4ce9ff77..719c0f1ee 100644 --- a/framebuffer/font_freetype.c +++ b/framebuffer/font_freetype.c @@ -262,7 +262,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; + srec->width = srec->height = (fstyle->size * 64) / FONT_SIZE_SCALE; srec->pixel = 0; srec->x_res = srec->y_res = 72; diff --git a/gtk/font_pango.c b/gtk/font_pango.c index e5f561c2f..c0d789344 100644 --- a/gtk/font_pango.c +++ b/gtk/font_pango.c @@ -304,10 +304,10 @@ PangoFontDescription *nsfont_style_to_description( size = fstyle->size; - if (size < (unsigned)abs(option_font_min_size / 10)) - size = option_font_min_size / 10; + if (size < (unsigned)abs(option_font_min_size / 10) * FONT_SIZE_SCALE) + size = (option_font_min_size / 10) * FONT_SIZE_SCALE; - size *= PANGO_SCALE; + size = (size * PANGO_SCALE) / FONT_SIZE_SCALE; if (fstyle->flags & FONTF_ITALIC) style = PANGO_STYLE_ITALIC; diff --git a/render/font.c b/render/font.c index 089fcff5a..11135d959 100644 --- a/render/font.c +++ b/render/font.c @@ -35,7 +35,8 @@ 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->size = + css_len2pt(&css->font_size.value.length, css) * FONT_SIZE_SCALE; fstyle->weight = plot_font_weight(css->font_weight); fstyle->flags = plot_font_flags(css->font_style, css->font_variant); fstyle->foreground = css->color; diff --git a/riscos/font.c b/riscos/font.c index 3aac2cd5e..eef02690f 100644 --- a/riscos/font.c +++ b/riscos/font.c @@ -425,7 +425,7 @@ void nsfont_read_style(const plot_font_style_t *fstyle, rufl_WEIGHT_900 }; - *font_size = fstyle->size * 16.; + *font_size = (fstyle->size * 16) / FONT_SIZE_SCALE; if (*font_size < option_font_min_size * 1.6) *font_size = option_font_min_size * 1.6; if (1600 < *font_size) -- cgit v1.2.3