提交 6c0ebd02 编写于 作者: B Behdad Esfahbod

[util] If font has color, generate PNG with color

上级 e95eb23a
...@@ -128,6 +128,22 @@ helper_cairo_create_scaled_font (const font_options_t *font_opts) ...@@ -128,6 +128,22 @@ helper_cairo_create_scaled_font (const font_options_t *font_opts)
return scaled_font; return scaled_font;
} }
bool
helper_cairo_scaled_font_has_color (cairo_scaled_font_t *scaled_font)
{
bool ret = false;
#ifdef FT_HAS_COLOR
FT_Face ft_face = cairo_ft_scaled_font_lock_face (scaled_font);
if (ft_face)
{
if (FT_HAS_COLOR (ft_face))
ret = true;
cairo_ft_scaled_font_unlock_face (scaled_font);
}
#endif
return ret;
}
struct finalize_closure_t { struct finalize_closure_t {
void (*callback)(finalize_closure_t *); void (*callback)(finalize_closure_t *);
...@@ -295,7 +311,8 @@ const char *helper_cairo_supported_formats[] = ...@@ -295,7 +311,8 @@ const char *helper_cairo_supported_formats[] =
cairo_t * cairo_t *
helper_cairo_create_context (double w, double h, helper_cairo_create_context (double w, double h,
view_options_t *view_opts, view_options_t *view_opts,
output_options_t *out_opts) output_options_t *out_opts,
cairo_content_t content)
{ {
cairo_surface_t *(*constructor) (cairo_write_func_t write_func, cairo_surface_t *(*constructor) (cairo_write_func_t write_func,
void *closure, void *closure,
...@@ -357,12 +374,14 @@ helper_cairo_create_context (double w, double h, ...@@ -357,12 +374,14 @@ helper_cairo_create_context (double w, double h,
color = view_opts->fore ? view_opts->fore : DEFAULT_FORE; color = view_opts->fore ? view_opts->fore : DEFAULT_FORE;
sscanf (color + (*color=='#'), "%2x%2x%2x%2x", &fr, &fg, &fb, &fa); sscanf (color + (*color=='#'), "%2x%2x%2x%2x", &fr, &fg, &fb, &fa);
cairo_content_t content; if (content == CAIRO_CONTENT_ALPHA)
if (!view_opts->annotate && ba == 255 && br == bg && bg == bb && fr == fg && fg == fb) {
content = CAIRO_CONTENT_ALPHA; if (view_opts->annotate ||
else if (ba == 255) br != bg || bg != bb ||
content = CAIRO_CONTENT_COLOR; fr != fg || fg != fb)
else content = CAIRO_CONTENT_COLOR;
}
if (ba != 255)
content = CAIRO_CONTENT_COLOR_ALPHA; content = CAIRO_CONTENT_COLOR_ALPHA;
cairo_surface_t *surface; cairo_surface_t *surface;
......
...@@ -35,12 +35,16 @@ ...@@ -35,12 +35,16 @@
cairo_scaled_font_t * cairo_scaled_font_t *
helper_cairo_create_scaled_font (const font_options_t *font_opts); helper_cairo_create_scaled_font (const font_options_t *font_opts);
bool
helper_cairo_scaled_font_has_color (cairo_scaled_font_t *scaled_font);
extern const char *helper_cairo_supported_formats[]; extern const char *helper_cairo_supported_formats[];
cairo_t * cairo_t *
helper_cairo_create_context (double w, double h, helper_cairo_create_context (double w, double h,
view_options_t *view_opts, view_options_t *view_opts,
output_options_t *out_opts); output_options_t *out_opts,
cairo_content_t content);
void void
helper_cairo_destroy_context (cairo_t *cr); helper_cairo_destroy_context (cairo_t *cr);
......
...@@ -64,10 +64,15 @@ view_cairo_t::render (const font_options_t *font_opts) ...@@ -64,10 +64,15 @@ view_cairo_t::render (const font_options_t *font_opts)
w = MAX (w, x_sign * x_advance); w = MAX (w, x_sign * x_advance);
} }
/* See if font needs color. */
cairo_content_t content = CAIRO_CONTENT_ALPHA;
if (helper_cairo_scaled_font_has_color (scaled_font))
content = CAIRO_CONTENT_COLOR;
/* Create surface. */ /* Create surface. */
cairo_t *cr = helper_cairo_create_context (w + view_options.margin.l + view_options.margin.r, cairo_t *cr = helper_cairo_create_context (w + view_options.margin.l + view_options.margin.r,
h + view_options.margin.t + view_options.margin.b, h + view_options.margin.t + view_options.margin.b,
&view_options, &output_options); &view_options, &output_options, content);
cairo_set_scaled_font (cr, scaled_font); cairo_set_scaled_font (cr, scaled_font);
/* Setup coordinate system. */ /* Setup coordinate system. */
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册