diff options
author | John Mark Bell <jmb@netsurf-browser.org> | 2009-07-21 10:59:53 +0000 |
---|---|---|
committer | John Mark Bell <jmb@netsurf-browser.org> | 2009-07-21 10:59:53 +0000 |
commit | 2565a37a52a5c714e7c6bbd1808db0d6d37c6ea3 (patch) | |
tree | f3fe5f224c9e0e4089aca2d9012dfe1a74cf9c90 /desktop/save_pdf | |
parent | 1930989f8ccdd574472ed72990b6a82fdcf9d5f4 (diff) | |
download | netsurf-2565a37a52a5c714e7c6bbd1808db0d6d37c6ea3.tar.gz netsurf-2565a37a52a5c714e7c6bbd1808db0d6d37c6ea3.tar.bz2 |
Refactor text plotter and other font functions to remove dependency on CSS.
svn path=/trunk/netsurf/; revision=8641
Diffstat (limited to 'desktop/save_pdf')
-rw-r--r-- | desktop/save_pdf/font_haru.c | 115 | ||||
-rw-r--r-- | desktop/save_pdf/font_haru.h | 3 | ||||
-rw-r--r-- | desktop/save_pdf/pdf_plotters.c | 13 |
3 files changed, 59 insertions, 72 deletions
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 <hpdf.h> #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 |