summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Mark Bell <jmb@netsurf-browser.org>2005-03-20 18:57:19 (GMT)
committer John Mark Bell <jmb@netsurf-browser.org>2005-03-20 18:57:19 (GMT)
commit27f948dbb05f37e1705dda8dd253dc3c0f94226a (patch)
tree7ea0d1c1fecd9d2fb70d97ee6eb7aa47a4dae3ee
parent5a03b4dccd89ba5b6bba097655891419670e68fd (diff)
downloadlibrufl-27f948dbb05f37e1705dda8dd253dc3c0f94226a.tar.gz
librufl-27f948dbb05f37e1705dda8dd253dc3c0f94226a.tar.bz2
[project @ 2005-03-20 18:57:19 by jmb]
Add flags word (bit 1 set == background blending support) svn path=/import/rufl/; revision=2457
-rw-r--r--rufl.h6
-rw-r--r--rufl_chars.c3
-rw-r--r--rufl_init.c8
-rw-r--r--rufl_internal.h2
-rw-r--r--rufl_paint.c78
-rw-r--r--rufl_test.c2
6 files changed, 69 insertions, 30 deletions
diff --git a/rufl.h b/rufl.h
index 38f481f..a4b9c72 100644
--- a/rufl.h
+++ b/rufl.h
@@ -37,6 +37,8 @@ typedef enum {
rufl_BOLD_SLANTED = 3,
} rufl_style;
+/** rufl_paint(_transformed) flags */
+#define rufl_BLEND_FONT 0x01
/** Last Font Manager error. */
extern os_error *rufl_fm_error;
@@ -63,7 +65,7 @@ rufl_code rufl_init(void);
rufl_code rufl_paint(const char *font_family, rufl_style font_style,
unsigned int font_size,
const char *string, size_t length,
- int x, int y);
+ int x, int y, unsigned int flags);
/**
@@ -76,7 +78,7 @@ rufl_code rufl_paint(const char *font_family, rufl_style font_style,
rufl_code rufl_paint_transformed(const char *font_family, rufl_style font_style,
unsigned int font_size,
const char *string, size_t length,
- int x, int y, os_trfm *trfm);
+ int x, int y, os_trfm *trfm, unsigned int flags);
/**
diff --git a/rufl_chars.c b/rufl_chars.c
index 25c4edb..ff7013a 100644
--- a/rufl_chars.c
+++ b/rufl_chars.c
@@ -260,7 +260,8 @@ rufl_code redraw(int x, int y, int y0, int y1)
code = rufl_paint(rufl_family_list[font], style, 240, s, l,
x + 10 + 40 * (u % 32),
- y - 40 - 40 * (u / 32));
+ y - 40 - 40 * (u / 32),
+ 0);
if (code != rufl_OK)
return code;
}
diff --git a/rufl_init.c b/rufl_init.c
index d2e21a0..77f17d1 100644
--- a/rufl_init.c
+++ b/rufl_init.c
@@ -75,6 +75,7 @@ rufl_code rufl_init(void)
{
unsigned int changes = 0;
unsigned int i;
+ int fm_version;
rufl_code code;
font_f font;
@@ -101,6 +102,13 @@ rufl_code rufl_init(void)
}
LOG("%s font manager", rufl_old_font_manager ? "old" : "new");
+ /* test if the font manager supports background blending */
+ rufl_fm_error = xfont_cache_addr(&fm_version, 0, 0);
+ if (rufl_fm_error)
+ return rufl_FONT_MANAGER_ERROR;
+ if (fm_version >= 335)
+ rufl_can_background_blend = true;
+
code = rufl_init_font_list();
if (code != rufl_OK) {
rufl_quit();
diff --git a/rufl_internal.h b/rufl_internal.h
index 2d16038..d0c9ed6 100644
--- a/rufl_internal.h
+++ b/rufl_internal.h
@@ -109,6 +109,8 @@ extern int rufl_cache_time;
/** Font manager does not support Unicode. */
extern bool rufl_old_font_manager;
+/** Font manager supports background blending */
+extern bool rufl_can_background_blend;
bool rufl_character_set_test(struct rufl_character_set *charset,
unsigned int c);
diff --git a/rufl_paint.c b/rufl_paint.c
index 412a5bd..c378544 100644
--- a/rufl_paint.c
+++ b/rufl_paint.c
@@ -17,27 +17,32 @@
typedef enum { rufl_PAINT, rufl_WIDTH, rufl_X_TO_OFFSET } rufl_action;
#define rufl_PROCESS_CHUNK 200
+bool rufl_can_background_blend = false;
+
static rufl_code rufl_process(rufl_action action,
const char *font_family, rufl_style font_style,
unsigned int font_size,
const char *string0, size_t length,
- int x, int y, os_trfm *trfm, int *width,
- int click_x, size_t *char_offset, int *actual_x);
+ int x, int y, os_trfm *trfm, unsigned int flags,
+ int *width, int click_x, size_t *char_offset, int *actual_x);
static int rufl_family_list_cmp(const void *keyval, const void *datum);
static rufl_code rufl_process_span(rufl_action action,
unsigned short *s, unsigned int n,
unsigned int font, unsigned int font_size, int *x, int y,
- os_trfm *trfm, int click_x, size_t *offset);
+ os_trfm *trfm, unsigned int flags,
+ int click_x, size_t *offset);
static rufl_code rufl_process_span_old(rufl_action action,
unsigned short *s, unsigned int n,
unsigned int font, unsigned int font_size, int *x, int y,
- os_trfm *trfm, int click_x, size_t *offset);
+ os_trfm *trfm, unsigned int flags,
+ int click_x, size_t *offset);
static int rufl_unicode_map_search_cmp(const void *keyval, const void *datum);
static rufl_code rufl_process_not_available(rufl_action action,
unsigned short *s, unsigned int n,
unsigned int font_size, int *x, int y,
- os_trfm *trfm, int click_x, size_t *offset);
+ os_trfm *trfm, unsigned int flags,
+ int click_x, size_t *offset);
static rufl_code rufl_place_in_cache(unsigned int font, unsigned int font_size,
font_f f);
@@ -49,11 +54,11 @@ static rufl_code rufl_place_in_cache(unsigned int font, unsigned int font_size,
rufl_code rufl_paint(const char *font_family, rufl_style font_style,
unsigned int font_size,
const char *string, size_t length,
- int x, int y)
+ int x, int y, unsigned int flags)
{
return rufl_process(rufl_PAINT,
font_family, font_style, font_size, string,
- length, x, y, 0, 0, 0, 0, 0);
+ length, x, y, 0, flags, 0, 0, 0, 0);
}
@@ -67,11 +72,11 @@ rufl_code rufl_paint(const char *font_family, rufl_style font_style,
rufl_code rufl_paint_transformed(const char *font_family, rufl_style font_style,
unsigned int font_size,
const char *string, size_t length,
- int x, int y, os_trfm *trfm)
+ int x, int y, os_trfm *trfm, unsigned int flags)
{
return rufl_process(rufl_PAINT,
font_family, font_style, font_size, string,
- length, x, y, trfm, 0, 0, 0, 0);
+ length, x, y, trfm, flags, 0, 0, 0, 0);
}
@@ -86,7 +91,7 @@ rufl_code rufl_width(const char *font_family, rufl_style font_style,
{
return rufl_process(rufl_WIDTH,
font_family, font_style, font_size, string,
- length, 0, 0, 0, width, 0, 0, 0);
+ length, 0, 0, 0, 0, width, 0, 0, 0);
}
@@ -103,7 +108,8 @@ rufl_code rufl_x_to_offset(const char *font_family, rufl_style font_style,
{
return rufl_process(rufl_X_TO_OFFSET,
font_family, font_style, font_size, string,
- length, 0, 0, 0, 0, click_x, char_offset, actual_x);
+ length, 0, 0, 0, 0, 0,
+ click_x, char_offset, actual_x);
}
@@ -115,8 +121,8 @@ rufl_code rufl_process(rufl_action action,
const char *font_family, rufl_style font_style,
unsigned int font_size,
const char *string0, size_t length,
- int x, int y, os_trfm *trfm, int *width,
- int click_x, size_t *char_offset, int *actual_x)
+ int x, int y, os_trfm *trfm, unsigned int flags,
+ int *width, int click_x, size_t *char_offset, int *actual_x)
{
unsigned short s[rufl_PROCESS_CHUNK];
unsigned int font;
@@ -136,6 +142,11 @@ rufl_code rufl_process(rufl_action action,
(action == rufl_X_TO_OFFSET && char_offset &&
actual_x));
+ if ((flags & rufl_BLEND_FONT) && !rufl_can_background_blend) {
+ /* unsuitable FM => clear blending bit */
+ flags &= ~rufl_BLEND_FONT;
+ }
+
if (length == 0) {
if (action == rufl_WIDTH)
*width = 0;
@@ -193,16 +204,16 @@ rufl_code rufl_process(rufl_action action,
if (font0 == NOT_AVAILABLE)
code = rufl_process_not_available(action, s, n,
- font_size, &x, y, trfm, click_x,
- &offset);
+ font_size, &x, y, trfm, flags,
+ click_x, &offset);
else if (rufl_old_font_manager)
code = rufl_process_span_old(action, s, n, font0,
- font_size, &x, y, trfm, click_x,
- &offset);
+ font_size, &x, y, trfm, flags,
+ click_x, &offset);
else
code = rufl_process_span(action, s, n, font0,
- font_size, &x, y, trfm, click_x,
- &offset);
+ font_size, &x, y, trfm, flags,
+ click_x, &offset);
if (action == rufl_X_TO_OFFSET && (offset < n || click_x < x))
break;
@@ -237,7 +248,8 @@ int rufl_family_list_cmp(const void *keyval, const void *datum)
rufl_code rufl_process_span(rufl_action action,
unsigned short *s, unsigned int n,
unsigned int font, unsigned int font_size, int *x, int y,
- os_trfm *trfm, int click_x, size_t *offset)
+ os_trfm *trfm, unsigned int flags,
+ int click_x, size_t *offset)
{
char font_name[80];
unsigned short *split_point;
@@ -276,7 +288,10 @@ rufl_code rufl_process_span(rufl_action action,
font_OS_UNITS |
(trfm ? font_GIVEN_TRFM : 0) |
font_GIVEN_LENGTH |
- font_GIVEN_FONT | font_KERN | font_GIVEN16_BIT,
+ font_GIVEN_FONT | font_KERN |
+ font_GIVEN16_BIT |
+ ((flags & rufl_BLEND_FONT) ?
+ font_BLEND_FONT : 0),
*x, y, 0, trfm, n * 2);
if (rufl_fm_error)
return rufl_FONT_MANAGER_ERROR;
@@ -317,7 +332,8 @@ rufl_code rufl_process_span(rufl_action action,
rufl_code rufl_process_span_old(rufl_action action,
unsigned short *s, unsigned int n,
unsigned int font, unsigned int font_size, int *x, int y,
- os_trfm *trfm, int click_x, size_t *offset)
+ os_trfm *trfm, unsigned int flags,
+ int click_x, size_t *offset)
{
char s2[rufl_PROCESS_CHUNK];
char *split_point;
@@ -364,7 +380,10 @@ rufl_code rufl_process_span_old(rufl_action action,
/* paint span */
rufl_fm_error = xfont_paint(f, s2, font_OS_UNITS |
(trfm ? font_GIVEN_TRFM : 0) |
- font_GIVEN_LENGTH | font_GIVEN_FONT | font_KERN,
+ font_GIVEN_LENGTH | font_GIVEN_FONT |
+ font_KERN |
+ ((flags & rufl_BLEND_FONT) ?
+ font_BLEND_FONT : 0),
*x, y, 0, trfm, n);
if (rufl_fm_error)
return rufl_FONT_MANAGER_ERROR;
@@ -413,7 +432,8 @@ int rufl_unicode_map_search_cmp(const void *keyval, const void *datum)
rufl_code rufl_process_not_available(rufl_action action,
unsigned short *s, unsigned int n,
unsigned int font_size, int *x, int y,
- os_trfm *trfm, int click_x, size_t *offset)
+ os_trfm *trfm, unsigned int flags,
+ int click_x, size_t *offset)
{
char missing[] = "0000";
int dx = 7 * font_size *
@@ -466,7 +486,10 @@ rufl_code rufl_process_not_available(rufl_action action,
/* first two characters in top row */
rufl_fm_error = xfont_paint(f, missing, font_OS_UNITS |
(trfm ? font_GIVEN_TRFM : 0) |
- font_GIVEN_LENGTH | font_GIVEN_FONT | font_KERN,
+ font_GIVEN_LENGTH | font_GIVEN_FONT |
+ font_KERN |
+ ((flags & rufl_BLEND_FONT) ?
+ font_BLEND_FONT : 0),
*x, y + (trfm ? trfm->entries[1][1] / 0x10000 :
1) * 5 * font_size / 64,
0, trfm, 2);
@@ -476,7 +499,10 @@ rufl_code rufl_process_not_available(rufl_action action,
/* last two characters underneath */
rufl_fm_error = xfont_paint(f, missing + 2, font_OS_UNITS |
(trfm ? font_GIVEN_TRFM : 0) |
- font_GIVEN_LENGTH | font_GIVEN_FONT | font_KERN,
+ font_GIVEN_LENGTH | font_GIVEN_FONT |
+ font_KERN |
+ ((flags & rufl_BLEND_FONT) ?
+ font_BLEND_FONT : 0),
*x, y, 0, trfm, 2);
if (rufl_fm_error)
return rufl_FONT_MANAGER_ERROR;
diff --git a/rufl_test.c b/rufl_test.c
index 71488d7..6068bc5 100644
--- a/rufl_test.c
+++ b/rufl_test.c
@@ -27,7 +27,7 @@ int main(void)
rufl_dump_state();
try(rufl_paint("NewHall", rufl_REGULAR, 240,
utf8_test, sizeof utf8_test - 1,
- 1200, 1200), "rufl_paint");
+ 1200, 1200, 0), "rufl_paint");
try(rufl_width("NewHall", rufl_REGULAR, 240,
utf8_test, sizeof utf8_test - 1,
&width), "rufl_width");