summaryrefslogtreecommitdiff
path: root/src/cairo-xcb-screen.c
diff options
context:
space:
mode:
authorLukáš Lalinský <lukas@oxygene.sk>2014-09-03 22:53:55 +0200
committerUli Schlachter <psychon@znc.in>2014-09-12 18:19:44 +0200
commite691d242d592a8556e25659fb091a2031abee4c9 (patch)
tree9959ed9f811921417828d436f1a0fa0dd2a6e763 /src/cairo-xcb-screen.c
parente77d0a5611fedce2bfa0940ff62f003c1f9cfa08 (diff)
downloadcairo-e691d242d592a8556e25659fb091a2031abee4c9.tar.gz
xcb: Initialize font options from Xft resources
There is a similar code in the Xlib backend. The logic here is the same, but XCB doesn't support X resources directly, so there is some custom code to get and parse the resources from the root window. Signed-off-by: Lukáš Lalinský <lukas@oxygene.sk> Reviewed-by: Uli Schlachter <psychon@znc.in>
Diffstat (limited to 'src/cairo-xcb-screen.c')
-rw-r--r--src/cairo-xcb-screen.c108
1 files changed, 108 insertions, 0 deletions
diff --git a/src/cairo-xcb-screen.c b/src/cairo-xcb-screen.c
index 2858d23fb..30295af6c 100644
--- a/src/cairo-xcb-screen.c
+++ b/src/cairo-xcb-screen.c
@@ -35,6 +35,96 @@
#include "cairo-xcb-private.h"
#include "cairo-list-inline.h"
+#include "cairo-fontconfig-private.h"
+
+static void
+_cairo_xcb_init_screen_font_options (cairo_xcb_screen_t *screen)
+{
+ cairo_xcb_resources_t res;
+ cairo_antialias_t antialias;
+ cairo_subpixel_order_t subpixel_order;
+ cairo_lcd_filter_t lcd_filter;
+ cairo_hint_style_t hint_style;
+
+ _cairo_xcb_resources_get (screen, &res);
+
+ /* the rest of the code in this function is copied from
+ _cairo_xlib_init_screen_font_options in cairo-xlib-screen.c */
+
+ if (res.xft_hinting) {
+ switch (res.xft_hintstyle) {
+ case FC_HINT_NONE:
+ hint_style = CAIRO_HINT_STYLE_NONE;
+ break;
+ case FC_HINT_SLIGHT:
+ hint_style = CAIRO_HINT_STYLE_SLIGHT;
+ break;
+ case FC_HINT_MEDIUM:
+ hint_style = CAIRO_HINT_STYLE_MEDIUM;
+ break;
+ case FC_HINT_FULL:
+ hint_style = CAIRO_HINT_STYLE_FULL;
+ break;
+ default:
+ hint_style = CAIRO_HINT_STYLE_DEFAULT;
+ }
+ } else {
+ hint_style = CAIRO_HINT_STYLE_NONE;
+ }
+
+ switch (res.xft_rgba) {
+ case FC_RGBA_RGB:
+ subpixel_order = CAIRO_SUBPIXEL_ORDER_RGB;
+ break;
+ case FC_RGBA_BGR:
+ subpixel_order = CAIRO_SUBPIXEL_ORDER_BGR;
+ break;
+ case FC_RGBA_VRGB:
+ subpixel_order = CAIRO_SUBPIXEL_ORDER_VRGB;
+ break;
+ case FC_RGBA_VBGR:
+ subpixel_order = CAIRO_SUBPIXEL_ORDER_VBGR;
+ break;
+ case FC_RGBA_UNKNOWN:
+ case FC_RGBA_NONE:
+ default:
+ subpixel_order = CAIRO_SUBPIXEL_ORDER_DEFAULT;
+ }
+
+ switch (res.xft_lcdfilter) {
+ case FC_LCD_NONE:
+ lcd_filter = CAIRO_LCD_FILTER_NONE;
+ break;
+ case FC_LCD_DEFAULT:
+ lcd_filter = CAIRO_LCD_FILTER_FIR5;
+ break;
+ case FC_LCD_LIGHT:
+ lcd_filter = CAIRO_LCD_FILTER_FIR3;
+ break;
+ case FC_LCD_LEGACY:
+ lcd_filter = CAIRO_LCD_FILTER_INTRA_PIXEL;
+ break;
+ default:
+ lcd_filter = CAIRO_LCD_FILTER_DEFAULT;
+ break;
+ }
+
+ if (res.xft_antialias) {
+ if (subpixel_order == CAIRO_SUBPIXEL_ORDER_DEFAULT)
+ antialias = CAIRO_ANTIALIAS_GRAY;
+ else
+ antialias = CAIRO_ANTIALIAS_SUBPIXEL;
+ } else {
+ antialias = CAIRO_ANTIALIAS_NONE;
+ }
+
+ cairo_font_options_set_hint_style (&screen->font_options, hint_style);
+ cairo_font_options_set_antialias (&screen->font_options, antialias);
+ cairo_font_options_set_subpixel_order (&screen->font_options, subpixel_order);
+ _cairo_font_options_set_lcd_filter (&screen->font_options, lcd_filter);
+ cairo_font_options_set_hint_metrics (&screen->font_options, CAIRO_HINT_METRICS_ON);
+}
+
struct pattern_cache_entry {
cairo_cache_entry_t key;
cairo_xcb_screen_t *screen;
@@ -362,3 +452,21 @@ _cairo_xcb_screen_lookup_radial_picture (cairo_xcb_screen_t *screen,
return picture;
}
+
+cairo_font_options_t *
+_cairo_xcb_screen_get_font_options (cairo_xcb_screen_t *screen)
+{
+ if (! screen->has_font_options) {
+ _cairo_font_options_init_default (&screen->font_options);
+ _cairo_font_options_set_round_glyph_positions (&screen->font_options, CAIRO_ROUND_GLYPH_POS_ON);
+
+ if (! _cairo_xcb_connection_acquire (screen->connection)) {
+ _cairo_xcb_init_screen_font_options (screen);
+ _cairo_xcb_connection_release (screen->connection);
+ }
+
+ screen->has_font_options = TRUE;
+ }
+
+ return &screen->font_options;
+}