summaryrefslogtreecommitdiff
path: root/desktop
diff options
context:
space:
mode:
Diffstat (limited to 'desktop')
-rw-r--r--desktop/browser.c30
-rw-r--r--desktop/history_core.c9
-rw-r--r--desktop/knockout.c20
-rw-r--r--desktop/options.c3
-rw-r--r--desktop/plot_style.c11
-rw-r--r--desktop/plot_style.h72
-rw-r--r--desktop/plotters.h4
-rw-r--r--desktop/save_pdf/font_haru.c115
-rw-r--r--desktop/save_pdf/font_haru.h3
-rw-r--r--desktop/save_pdf/pdf_plotters.c13
-rw-r--r--desktop/selection.c5
-rw-r--r--desktop/textarea.c44
-rw-r--r--desktop/textinput.c43
13 files changed, 224 insertions, 148 deletions
diff --git a/desktop/browser.c b/desktop/browser.c
index 9185eff51..b188316ea 100644
--- a/desktop/browser.c
+++ b/desktop/browser.c
@@ -1405,6 +1405,7 @@ void browser_window_mouse_action_html(struct browser_window *bw,
struct form_control *gadget = 0;
struct content *object = NULL;
struct box *next_box;
+ plot_font_style_t fstyle;
bw->drag_type = DRAGGING_NONE;
bw->scrolling_box = NULL;
@@ -1554,7 +1555,10 @@ void browser_window_mouse_action_html(struct browser_window *bw,
int pixel_offset;
size_t idx;
- nsfont.font_position_in_string(text_box->style,
+ font_plot_style_from_css(text_box->style,
+ &fstyle);
+
+ nsfont.font_position_in_string(&fstyle,
text_box->text,
text_box->length,
x - gadget_box_x - text_box->x,
@@ -1596,7 +1600,10 @@ void browser_window_mouse_action_html(struct browser_window *bw,
BROWSER_MOUSE_DRAG_2))
selection_init(bw->sel, gadget_box);
- nsfont.font_position_in_string(text_box->style,
+ font_plot_style_from_css(text_box->style,
+ &fstyle);
+
+ nsfont.font_position_in_string(&fstyle,
text_box->text,
text_box->length,
x - gadget_box_x - text_box->x,
@@ -1694,7 +1701,10 @@ void browser_window_mouse_action_html(struct browser_window *bw,
int pixel_offset;
size_t idx;
- nsfont.font_position_in_string(text_box->style,
+ font_plot_style_from_css(text_box->style,
+ &fstyle);
+
+ nsfont.font_position_in_string(&fstyle,
text_box->text,
text_box->length,
x - text_box_x,
@@ -1972,7 +1982,11 @@ void browser_window_mouse_track_html(struct browser_window *bw,
if (box) {
int pixel_offset;
size_t idx;
- nsfont.font_position_in_string(box->style,
+ plot_font_style_t fstyle;
+
+ font_plot_style_from_css(box->style, &fstyle);
+
+ nsfont.font_position_in_string(&fstyle,
box->text, box->length,
dx, &idx, &pixel_offset);
@@ -2052,8 +2066,14 @@ void browser_window_mouse_drag_end(struct browser_window *bw,
box = browser_window_pick_text_box(bw,
x, y, dir, &dx, &dy);
if (box) {
+ plot_font_style_t fstyle;
+
+ font_plot_style_from_css(
+ box->style,
+ &fstyle);
+
nsfont.font_position_in_string(
- box->style,
+ &fstyle,
box->text,
box->length,
dx,
diff --git a/desktop/history_core.c b/desktop/history_core.c
index a40d746bd..4a30d1783 100644
--- a/desktop/history_core.c
+++ b/desktop/history_core.c
@@ -633,6 +633,7 @@ bool history_redraw_entry(struct history *history,
.stroke_colour = c,
.stroke_width = entry == history->current ? 2 : 1,
};
+ plot_font_style_t fstyle = *plot_style_font;
if (clip) {
if(!plot.clip(x0 + xoffset, y0 + yoffset, x1 + xoffset, y1 + yoffset))
@@ -649,12 +650,16 @@ bool history_redraw_entry(struct history *history,
&pstyle_history_rect))
return false;
- if (!nsfont.font_position_in_string(&css_base_style, entry->page.title,
+ if (!nsfont.font_position_in_string(plot_style_font, entry->page.title,
strlen(entry->page.title), WIDTH,
&char_offset, &actual_x))
return false;
+
+ fstyle.background = 0xffffff;
+ fstyle.foreground = c;
+
if (!plot.text(entry->x + xoffset, entry->y + HEIGHT + 12 + yoffset,
- &css_base_style, entry->page.title, char_offset, 0xffffff, c))
+ entry->page.title, char_offset, &fstyle))
return false;
for (child = entry->forward; child; child = child->next) {
diff --git a/desktop/knockout.c b/desktop/knockout.c
index b9a6862e5..680257b0f 100644
--- a/desktop/knockout.c
+++ b/desktop/knockout.c
@@ -90,8 +90,8 @@ static bool knockout_plot_polygon(const int *p, unsigned int n, const plot_style
static bool knockout_plot_rectangle(int x0, int y0, int x1, int y1, const plot_style_t *plot_style);
static bool knockout_plot_clip(int clip_x0, int clip_y0,
int clip_x1, int clip_y1);
-static bool knockout_plot_text(int x, int y, const struct css_style *style,
- const char *text, size_t length, colour bg, colour c);
+static bool knockout_plot_text(int x, int y, const char *text, size_t length,
+ const plot_font_style_t *fstyle);
static bool knockout_plot_disc(int x, int y, int radius, const plot_style_t *pstyle);
static bool knockout_plot_arc(int x, int y, int radius, int angle1, int angle2, const plot_style_t *pstyle);
static bool knockout_plot_bitmap(int x, int y, int width, int height,
@@ -188,11 +188,9 @@ struct knockout_entry {
struct {
int x;
int y;
- const struct css_style *style;
const char *text;
size_t length;
- colour bg;
- colour c;
+ plot_font_style_t font_style;
} text;
struct {
int x;
@@ -350,11 +348,9 @@ bool knockout_plot_flush(void)
success &= plot.text(
knockout_entries[i].data.text.x,
knockout_entries[i].data.text.y,
- knockout_entries[i].data.text.style,
knockout_entries[i].data.text.text,
knockout_entries[i].data.text.length,
- knockout_entries[i].data.text.bg,
- knockout_entries[i].data.text.c);
+ &knockout_entries[i].data.text.font_style);
break;
case KNOCKOUT_PLOT_DISC:
success &= plot.disc(
@@ -737,16 +733,14 @@ bool knockout_plot_clip(int clip_x0, int clip_y0,
}
-bool knockout_plot_text(int x, int y, const struct css_style *style,
- const char *text, size_t length, colour bg, colour c)
+bool knockout_plot_text(int x, int y, const char *text, size_t length,
+ const plot_font_style_t *fstyle)
{
knockout_entries[knockout_entry_cur].data.text.x = x;
knockout_entries[knockout_entry_cur].data.text.y = y;
- knockout_entries[knockout_entry_cur].data.text.style = style;
knockout_entries[knockout_entry_cur].data.text.text = text;
knockout_entries[knockout_entry_cur].data.text.length = length;
- knockout_entries[knockout_entry_cur].data.text.bg = bg;
- knockout_entries[knockout_entry_cur].data.text.c = c;
+ knockout_entries[knockout_entry_cur].data.text.font_style = *fstyle;
knockout_entries[knockout_entry_cur].type = KNOCKOUT_PLOT_TEXT;
if (++knockout_entry_cur >= KNOCKOUT_ENTRIES)
knockout_plot_flush();
diff --git a/desktop/options.c b/desktop/options.c
index 28cdecf3c..e885174a4 100644
--- a/desktop/options.c
+++ b/desktop/options.c
@@ -36,6 +36,7 @@
#include "content/urldb.h"
#include "css/css.h"
#include "desktop/options.h"
+#include "desktop/plot_style.h"
#include "desktop/tree.h"
#include "utils/log.h"
#include "utils/messages.h"
@@ -103,7 +104,7 @@ bool option_animate_images = true;
/** How many days to retain URL data for */
int option_expire_url = 28;
/** Default font family */
-int option_font_default = CSS_FONT_FAMILY_SANS_SERIF;
+int option_font_default = PLOT_FONT_FAMILY_SANS_SERIF;
/** ca-bundle location */
char *option_ca_bundle = 0;
/** ca-path location */
diff --git a/desktop/plot_style.c b/desktop/plot_style.c
index fa94076e8..54dbd40ce 100644
--- a/desktop/plot_style.c
+++ b/desktop/plot_style.c
@@ -137,3 +137,14 @@ static plot_style_t plot_style_stroke_history_static = {
};
plot_style_t *plot_style_stroke_history = &plot_style_stroke_history_static;
+/* Generic font style */
+static const plot_font_style_t plot_style_font_static = {
+ .family = PLOT_FONT_FAMILY_SANS_SERIF,
+ .size = 10,
+ .weight = 400,
+ .flags = FONTF_NONE,
+ .background = 0xffffff,
+ .foreground = 0x000000,
+};
+plot_font_style_t const * const plot_style_font = &plot_style_font_static;
+
diff --git a/desktop/plot_style.h b/desktop/plot_style.h
index 76843fad4..3b74a4efd 100644
--- a/desktop/plot_style.h
+++ b/desktop/plot_style.h
@@ -17,7 +17,7 @@
*/
/** \file
- * Ploter styles.
+ * Plotter styles.
*/
#ifndef _NETSURF_DESKTOP_PLOT_STYLE_H_
@@ -27,27 +27,27 @@
#define WIDGET_BASEC 0xd9d9d9
#define WIDGET_BLOBC 0x000000
-/* Darken a colour by taking three quaters of each channels intensity */
+/* Darken a colour by taking three quarters of each channel's intensity */
#define darken_colour(c1) \
((((3 * (c1 >> 16)) >> 2) << 16) | \
(((3 * ((c1 >> 8) & 0xff)) >> 2) << 8) | \
(((3 * (c1 & 0xff)) >> 2) << 0))
-/* Darken a colour by taking nine sixteenths of each channels intensity */
+/* Darken a colour by taking nine sixteenths of each channel's intensity */
#define double_darken_colour(c1) \
((((9 * (c1 >> 16)) >> 4) << 16) | \
(((9 * ((c1 >> 8) & 0xff)) >> 4) << 8) | \
(((9 * (c1 & 0xff)) >> 4) << 0))
-/* Lighten a colour by taking three quaters of each channels intensity
- * and adding a full quater
+/* Lighten a colour by taking three quarters of each channel's intensity
+ * and adding a full quarter
*/
#define lighten_colour(c1) \
(((((3 * (c1 >> 16)) >> 2) + 64) << 16) | \
((((3 * ((c1 >> 8) & 0xff)) >> 2) + 64) << 8) | \
((((3 * (c1 & 0xff)) >> 2) + 64) << 0))
-/* Lighten a colour by taking nine sixteenths of each channels intensity and
+/* Lighten a colour by taking nine sixteenths of each channel's intensity and
* adding a full intensity 7/16ths */
#define double_lighten_colour(c1) \
(((((9 * (c1 >> 16)) >> 4) + 112) << 16) | \
@@ -62,21 +62,60 @@
(((((c0 >> 8) & 0xff) + ((c1 >> 8) & 0xff)) >> 1) << 8) | \
((((c0 & 0xff) + (c1 & 0xff)) >> 1) << 0)
+/**
+ * Type of plot operation
+ */
typedef enum {
- PLOT_OP_TYPE_NONE = 0, /**< No operation */
- PLOT_OP_TYPE_SOLID, /**< Solid colour */
- PLOT_OP_TYPE_DOT, /**< Doted plot */
- PLOT_OP_TYPE_DASH, /**< dashed plot */
+ PLOT_OP_TYPE_NONE = 0, /**< No operation */
+ PLOT_OP_TYPE_SOLID, /**< Solid colour */
+ PLOT_OP_TYPE_DOT, /**< Dotted plot */
+ PLOT_OP_TYPE_DASH, /**< Dashed plot */
} plot_operation_type_t;
+/**
+ * Plot style for stroke/fill plotters
+ */
typedef struct {
- plot_operation_type_t stroke_type;
- int stroke_width;
- colour stroke_colour;
- plot_operation_type_t fill_type;
- colour fill_colour;
+ plot_operation_type_t stroke_type; /**< Stroke plot type */
+ int stroke_width; /**< Width of stroke, in pixels */
+ colour stroke_colour; /**< Colour of stroke */
+ plot_operation_type_t fill_type; /**< Fill plot type */
+ colour fill_colour; /**< Colour of fill */
} plot_style_t;
+/**
+ * Generic font family type
+ */
+typedef enum {
+ PLOT_FONT_FAMILY_SANS_SERIF = 0,
+ PLOT_FONT_FAMILY_SERIF,
+ PLOT_FONT_FAMILY_MONOSPACE,
+ PLOT_FONT_FAMILY_CURSIVE,
+ PLOT_FONT_FAMILY_FANTASY,
+ PLOT_FONT_FAMILY_COUNT /**< Number of generic families */
+} plot_font_generic_family_t;
+
+/**
+ * Font plot flags
+ */
+typedef unsigned long plot_font_flags_t;
+#define FONTF_NONE 0
+#define FONTF_ITALIC 1
+#define FONTF_OBLIQUE 2
+#define FONTF_SMALLCAPS 4
+
+/**
+ * Font style for plotting
+ */
+typedef struct {
+ plot_font_generic_family_t family; /**< Generic family to plot with */
+ int size; /**< Font size, in points */
+ 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 */
+ colour foreground; /**< Colour of text */
+} plot_font_style_t;
+
/* global fill styles */
extern plot_style_t *plot_style_fill_white;
extern plot_style_t *plot_style_fill_red;
@@ -98,4 +137,7 @@ extern plot_style_t *plot_style_stroke_wblobc;
extern plot_style_t *plot_style_stroke_darkwbasec;
extern plot_style_t *plot_style_stroke_lightwbasec;
+/* Default font style */
+extern plot_font_style_t const * const plot_style_font;
+
#endif
diff --git a/desktop/plotters.h b/desktop/plotters.h
index 91fbd5188..4edec321b 100644
--- a/desktop/plotters.h
+++ b/desktop/plotters.h
@@ -115,8 +115,8 @@ struct plotter_table {
bitmap_flags_t flags);
/* text */
- bool (*text)(int x, int y, const struct css_style *style,
- const char *text, size_t length, colour bg, colour c);
+ bool (*text)(int x, int y, const char *text, size_t length,
+ const plot_font_style_t *fstyle);
/* optional callbacks */
bool (*group_start)(const char *name); /**< optional, may be NULL */
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
diff --git a/desktop/selection.c b/desktop/selection.c
index 014c44659..623caf414 100644
--- a/desktop/selection.c
+++ b/desktop/selection.c
@@ -609,6 +609,9 @@ bool redraw_handler(const char *text, size_t length, struct box *box,
struct rdw_info *r = (struct rdw_info*)handle;
int width, height, space_width;
int x, y;
+ plot_font_style_t fstyle;
+
+ font_plot_style_from_css(box->style, &fstyle);
/* \todo - it should be possible to reduce the redrawn area by
* considering the 'text', 'length' and 'space' parameters */
@@ -618,7 +621,7 @@ bool redraw_handler(const char *text, size_t length, struct box *box,
height = box->padding[TOP] + box->height + box->padding[BOTTOM];
if (box->type == BOX_TEXT && box->space &&
- nsfont.font_width(box->style, " ", 1, &space_width))
+ nsfont.font_width(&fstyle, " ", 1, &space_width))
width += space_width;
if (r->inited) {
diff --git a/desktop/textarea.c b/desktop/textarea.c
index 4e08ff549..4832e29cf 100644
--- a/desktop/textarea.c
+++ b/desktop/textarea.c
@@ -96,7 +96,7 @@ struct text_area {
int selection_start; /**< Character index of sel start(inclusive) */
int selection_end; /**< Character index of sel end(exclusive) */
- struct css_style *style; /**< Text style */
+ plot_font_style_t fstyle; /**< Text style */
int line_count; /**< Count of lines */
#define LINE_CHUNK_SIZE 16
@@ -182,15 +182,8 @@ struct text_area *textarea_create(int x, int y, int width, int height,
ret->text_alloc = 64;
ret->text_len = 1;
ret->text_utf8_len = 0;
-
- ret->style = malloc(sizeof(struct css_style));
- if (ret->style == NULL) {
- LOG(("malloc failed"));
- free(ret->text);
- free(ret);
- return NULL;
- }
- memcpy(ret->style, style, sizeof(struct css_style));
+
+ font_plot_style_from_css(style, &ret->fstyle);
ret->line_height = css_len2px(&(style->line_height.value.length),
style);
@@ -232,7 +225,6 @@ void textarea_set_position(struct text_area *ta, int x, int y)
void textarea_destroy(struct text_area *ta)
{
free(ta->text);
- free(ta->style);
free(ta->lines);
free(ta);
}
@@ -448,8 +440,8 @@ bool textarea_set_caret(struct text_area *ta, int caret)
if (caret != -1 && (unsigned)caret > c_len)
caret = c_len;
- height = css_len2px(&(ta->style->font_size.value.length),
- ta->style);
+ height = ta->fstyle.size * css_screen_dpi / 72;
+
/* Delete the old caret */
if (ta->caret_pos.char_off != -1) {
index = textarea_get_caret(ta);
@@ -467,7 +459,7 @@ bool textarea_set_caret(struct text_area *ta, int caret)
ta->text_len, b_off))
; /* do nothing */
- nsfont.font_width(ta->style,
+ nsfont.font_width(&ta->fstyle,
ta->text +
ta->lines[ta->caret_pos.line].b_start,
b_off - ta->lines[ta->caret_pos.line].b_start,
@@ -516,7 +508,7 @@ bool textarea_set_caret(struct text_area *ta, int caret)
ta->text_len, b_off))
; /* do nothing */
- nsfont.font_width(ta->style,
+ nsfont.font_width(&ta->fstyle,
ta->text +
ta->lines[ta->caret_pos.line].b_start,
b_off - ta->lines[ta->caret_pos.line].b_start,
@@ -570,7 +562,7 @@ unsigned int textarea_get_xy_offset(struct text_area *ta, int x, int y)
if (ta->line_count - 1 < line)
line = ta->line_count - 1;
- nsfont.font_position_in_string(ta->style,
+ nsfont.font_position_in_string(&ta->fstyle,
ta->text + ta->lines[line].b_start,
ta->lines[line].b_length, x, &b_off, &x);
@@ -679,7 +671,7 @@ bool textarea_reflow(struct text_area *ta, unsigned int line)
for (len = ta->text_len - 1, text = ta->text; len > 0;
len -= b_off, text += b_off) {
- nsfont.font_split(ta->style, text, len,
+ nsfont.font_split(&ta->fstyle, text, len,
ta->vis_width - MARGIN_LEFT - MARGIN_RIGHT,
&b_off, &x);
@@ -757,7 +749,6 @@ void textarea_redraw(struct text_area *ta, int x0, int y0, int x1, int y1)
.fill_colour = BACKGROUND_COL,
};
-
if (x1 < ta->x || x0 > ta->x + ta->vis_width || y1 < ta->y ||
y0 > ta->y + ta->vis_height)
/* Textarea outside the clipping rectangle */
@@ -848,7 +839,7 @@ void textarea_redraw(struct text_area *ta, int x0, int y0, int x1, int y1)
b_start = utf8_next(line_text,
line_len,
b_start);
- nsfont.font_width(ta->style, line_text,
+ nsfont.font_width(&ta->fstyle, line_text,
b_start, &x0);
x0 += ta->x + MARGIN_LEFT;
}
@@ -872,7 +863,7 @@ void textarea_redraw(struct text_area *ta, int x0, int y0, int x1, int y1)
b_end = ta->lines[line].b_length;
b_end -= b_start;
- nsfont.font_width(ta->style,
+ nsfont.font_width(&ta->fstyle,
&(ta->text[ta->lines[line].b_start +
b_start]),
b_end, &x1);
@@ -890,14 +881,15 @@ void textarea_redraw(struct text_area *ta, int x0, int y0, int x1, int y1)
c_pos += c_len;
y0 = ta->y + line * ta->line_height + 0.75 * ta->line_height;
-
+
+ ta->fstyle.background =
+ (ta->flags & TEXTAREA_READONLY) ?
+ READONLY_BG : BACKGROUND_COL,
+
plot.text(ta->x + MARGIN_LEFT - ta->scroll_x, y0 - ta->scroll_y,
- ta->style,
ta->text + ta->lines[line].b_start,
ta->lines[line].b_length,
- (ta->flags & TEXTAREA_READONLY) ?
- READONLY_BG : BACKGROUND_COL,
- ta->style->color);
+ &ta->fstyle);
}
}
@@ -1253,7 +1245,7 @@ bool textarea_scroll_visible(struct text_area *ta)
b_off = utf8_next(ta->text, ta->text_len, b_off))
; /* do nothing */
- nsfont.font_width(ta->style,
+ nsfont.font_width(&ta->fstyle,
ta->text + ta->lines[ta->caret_pos.line].b_start,
b_off - ta->lines[ta->caret_pos.line].b_start,
&x);
diff --git a/desktop/textinput.c b/desktop/textinput.c
index 07af9e991..645c961c4 100644
--- a/desktop/textinput.c
+++ b/desktop/textinput.c
@@ -173,6 +173,7 @@ struct box *textarea_get_position(struct box *textarea, int x, int y,
* lines. */
struct box *inline_container, *text_box;
+ plot_font_style_t fstyle;
inline_container = textarea->children;
@@ -181,8 +182,9 @@ struct box *textarea_get_position(struct box *textarea, int x, int y,
text_box = inline_container->last;
assert(text_box->type == BOX_TEXT);
assert(text_box->text);
+ font_plot_style_from_css(text_box->style, &fstyle);
/** \todo handle errors */
- nsfont.font_position_in_string(text_box->style, text_box->text,
+ nsfont.font_position_in_string(&fstyle, text_box->text,
text_box->length,
(unsigned int)(x - text_box->x),
(size_t *) pchar_offset, ppixel_offset);
@@ -204,7 +206,8 @@ struct box *textarea_get_position(struct box *textarea, int x, int y,
text_box = inline_container->last;
assert(text_box->type == BOX_TEXT);
assert(text_box->text);
- nsfont.font_position_in_string(text_box->style,
+ font_plot_style_from_css(text_box->style, &fstyle);
+ nsfont.font_position_in_string(&fstyle,
text_box->text,
text_box->length,
textarea->width,
@@ -224,7 +227,8 @@ struct box *textarea_get_position(struct box *textarea, int x, int y,
}
assert(text_box->type == BOX_TEXT);
assert(text_box->text);
- nsfont.font_position_in_string(text_box->style,
+ font_plot_style_from_css(text_box->style, &fstyle);
+ nsfont.font_position_in_string(&fstyle,
text_box->text,
text_box->length,
(unsigned int)(x - text_box->x),
@@ -321,6 +325,7 @@ bool browser_window_textarea_callback(struct browser_window *bw,
unsigned int utf8_len;
bool scrolled, reflow = false;
bool selection_exists = bw->sel->defined;
+ plot_font_style_t fstyle;
/* box_dump(textarea, 0); */
LOG(("key %i at %i in '%.*s'", key, char_offset,
@@ -762,8 +767,9 @@ bool browser_window_textarea_callback(struct browser_window *bw,
}
}
- nsfont.font_width(text_box->style, text_box->text,
- char_offset, &pixel_offset);
+ font_plot_style_from_css(text_box->style, &fstyle);
+
+ nsfont.font_width(&fstyle, text_box->text, char_offset, &pixel_offset);
selection_clear(bw->sel, true);
@@ -813,8 +819,11 @@ void browser_window_input_click(struct browser_window* bw,
size_t char_offset = 0;
int pixel_offset = 0, dx = 0;
struct box *text_box = input->children->children;
+ plot_font_style_t fstyle;
- nsfont.font_position_in_string(text_box->style, text_box->text,
+ font_plot_style_from_css(text_box->style, &fstyle);
+
+ nsfont.font_position_in_string(&fstyle, text_box->text,
text_box->length, x - text_box->x,
&char_offset, &pixel_offset);
assert(char_offset <= text_box->length);
@@ -1349,6 +1358,7 @@ bool browser_window_textarea_paste_text(struct browser_window *bw,
if (update) {
int box_x, box_y;
+ plot_font_style_t fstyle;
/* reflow textarea preserving width and height */
textarea_reflow(bw, textarea, inline_container);
@@ -1380,7 +1390,9 @@ bool browser_window_textarea_paste_text(struct browser_window *bw,
textarea->gadget->caret_text_box = text_box;
textarea->gadget->caret_box_offset = char_offset;
- nsfont.font_width(text_box->style, text_box->text,
+ font_plot_style_from_css(text_box->style, &fstyle);
+
+ nsfont.font_width(&fstyle, text_box->text,
char_offset, &pixel_offset);
textarea->gadget->caret_pixel_offset = pixel_offset;
@@ -1501,12 +1513,15 @@ void browser_window_textarea_move_caret(struct browser_window *bw, void *p)
size_t char_offset = textarea->gadget->caret_box_offset;
int pixel_offset;
int box_x, box_y;
+ plot_font_style_t fstyle;
+
+ font_plot_style_from_css(text_box->style, &fstyle);
box_coords(textarea, &box_x, &box_y);
box_x -= textarea->scroll_x;
box_y -= textarea->scroll_y;
- nsfont.font_width(text_box->style, text_box->text,
+ nsfont.font_width(&fstyle, text_box->text,
char_offset, &pixel_offset);
browser_window_place_caret(bw,
@@ -1536,10 +1551,13 @@ void browser_window_input_move_caret(struct browser_window *bw, void *p)
unsigned int box_offset = input->gadget->caret_box_offset;
int pixel_offset;
int box_x, box_y;
+ plot_font_style_t fstyle;
+
+ font_plot_style_from_css(text_box->style, &fstyle);
box_coords(input, &box_x, &box_y);
- nsfont.font_width(text_box->style, text_box->text, box_offset,
+ nsfont.font_width(&fstyle, text_box->text, box_offset,
&pixel_offset);
browser_window_place_caret(bw,
@@ -1572,14 +1590,17 @@ void input_update_display(struct browser_window *bw, struct box *input,
unsigned pixel_offset;
int box_x, box_y;
int dx;
+ plot_font_style_t fstyle;
+
+ font_plot_style_from_css(text_box->style, &fstyle);
if (redraw)
- nsfont.font_width(text_box->style, text_box->text, text_box->length,
+ nsfont.font_width(&fstyle, text_box->text, text_box->length,
&text_box->width);
box_coords(input, &box_x, &box_y);
- nsfont.font_width(text_box->style, text_box->text, box_offset,
+ nsfont.font_width(&fstyle, text_box->text, box_offset,
(int *) &pixel_offset);
/* Shift text box horizontally, so caret is visible */