diff --git a/class/Drawable.c b/class/Drawable.c index e0d9b780..42d5cd3f 100644 --- a/class/Drawable.c +++ b/class/Drawable.c @@ -680,7 +680,7 @@ Drawable_rop2( Handle self, Bool set, int rop2) Bool Drawable_is_font_colored( Handle self ) { - return apc_gp_is_font_colored(self); + return apc_font_is_colored(self); } Bool diff --git a/include/apricot.h b/include/apricot.h index a358595a..962c1f65 100644 --- a/include/apricot.h +++ b/include/apricot.h @@ -3975,9 +3975,6 @@ apc_gp_bars( Handle self, int nr, Rect *rr); extern Bool apc_gp_can_draw_alpha( Handle self); -extern Bool -apc_gp_is_font_colored( Handle self); - extern Bool apc_gp_clear( Handle self, int x1, int y1, int x2, int y2); @@ -4332,6 +4329,9 @@ apc_font_get_text_shaper( Handle self, int *type); extern Byte* apc_font_get_glyph_bitmap( Handle self, uint16_t index, unsigned int flags, PPoint offset, PPoint size, int *advance); +extern Bool +apc_font_is_colored( Handle self); + extern PFont apc_fonts( Handle self, const char *facename, const char *encoding, int *retCount); diff --git a/include/unix/guts.h b/include/unix/guts.h index fd0ad985..46a5a865 100644 --- a/include/unix/guts.h +++ b/include/unix/guts.h @@ -251,6 +251,7 @@ typedef struct CachedFont { XFont id; PRotatedFont rotated; + int8_t has_colors; #ifdef USE_FONTQUERY FT_Face ft_face; FcCharSet *fc_charset; @@ -1650,6 +1651,9 @@ prima_xft_mapper_query_ranges(PFont font, int * count, unsigned int * flags); extern Byte* prima_xft_get_glyph_bitmap( Handle self, uint16_t index, unsigned int flags, PPoint offset, PPoint size, int *advance); +extern Bool +prima_xft_is_font_colored(Handle self); + #endif extern Bool @@ -1939,6 +1943,9 @@ prima_ft_get_glyph_outline( FT_Face face, FT_UInt ft_index, FT_Int32 ft_flags, i extern Byte* prima_ft_get_glyph_bitmap( FT_Face face, FT_UInt index, FT_Int32 flags, PPoint offset, PPoint size, int *advance); +extern Bool +prima_ft_is_font_colored( FT_Face face); + extern Bool prima_ft_text_shaper_harfbuzz( FT_Face face, PTextShapeRec r); diff --git a/unix/font.c b/unix/font.c index 3bcab219..2be3e190 100644 --- a/unix/font.c +++ b/unix/font.c @@ -821,11 +821,50 @@ apc_font_get_glyph_bitmap( Handle self, uint16_t index, unsigned int flags, PPoi return prima_corefont_get_glyph_bitmap(self, index, flags & ggoMonochrome, offset, size, advance); } +Bool +apc_font_is_colored( Handle self) +{ + DEFXX; + PCachedFont f = XX->font; + warn("%d\n", __LINE__); + if ( + f->has_colors < 0 || + ( XT_IS_DBM(XX) && XT_IS_BITMAP(XX)) || + ( XT_IS_IMAGE(XX) && ((PImage)self)-> type == imBW ) + ) + return false; + else if ( f->has_colors > 0 ) + return true; + warn("%d\n", __LINE__); + +#ifdef USE_FONTQUERY + if ( is_opt(optInFontQuery) ) { + return false; /* XXX because colored bitmaps are not supported */ + } +#endif + +#ifdef USE_XFT + warn("%d\n", __LINE__); + if ( f->xft ) { + warn("%d\n", __LINE__); + warn("%d\n", __LINE__); + Bool ok = prima_xft_is_font_colored(self); + warn("%d\n", __LINE__); + f->has_colors = ok ? 1 : -1; + warn("%d\n", __LINE__); + return ok; + } +#endif + warn("%d\n", __LINE__); + + return false; +} + Bool apc_gp_set_text_matrix( Handle self, Matrix matrix) { PFont f = & PDrawable(self)->font; - if (f->undef.height &&f->undef.size) /* too early */ + if (f->undef.height && f->undef.size) /* too early */ return true; return apc_gp_set_font( self, f); } diff --git a/unix/freetype.c b/unix/freetype.c index 3a631c77..097dee1b 100644 --- a/unix/freetype.c +++ b/unix/freetype.c @@ -382,5 +382,23 @@ prima_ft_detail_tt_font( FT_Face face, PFont font, float mul) font->width = 1; } +Bool +prima_ft_is_font_colored( FT_Face face) +{ +#if defined(TTAG_COLR) && defined(TTAG_CPAL) + FT_Int a,b,c; + FT_ULong l = 0; + + if ( a < 2 || ( a == 2 && b < 10 )) /* CPAL/COLR only supported in 2.10 */ + return false; + return + FT_Load_Sfnt_Table(face, TTAG_COLR, 0, NULL, &l) && + FT_Load_Sfnt_Table(face, TTAG_CPAL, 0, NULL, &l) + ; +#else + return false; +#endif +} + #endif diff --git a/unix/graphics.c b/unix/graphics.c index 7167769c..df9361bc 100644 --- a/unix/graphics.c +++ b/unix/graphics.c @@ -1510,12 +1510,6 @@ apc_gp_get_text_opaque( Handle self) return X(self)-> flags. opaque ? true : false; } -Bool -apc_gp_is_font_colored( Handle self) -{ - return false; -} - Bool apc_gp_get_text_out_baseline( Handle self) { diff --git a/unix/xft.c b/unix/xft.c index 0d1a74b3..2ad70479 100644 --- a/unix/xft.c +++ b/unix/xft.c @@ -1427,6 +1427,19 @@ prima_xft_get_glyph_bitmap( Handle self, uint16_t index, unsigned int flags, PPo return ret; } +Bool +prima_xft_is_font_colored( Handle self ) +{ + DEFXX; + Bool ret; + FT_Face face; + if ( !( face = XftLockFace( XX->font->xft))) + return false; + ret = prima_ft_is_font_colored(face); + XftUnlockFace(XX->font->xft); + return ret; +} + unsigned long * prima_xft_mapper_query_ranges(PFont font, int * count, unsigned int * flags) { diff --git a/win32/text.c b/win32/text.c index 4f973b53..a9a418a8 100644 --- a/win32/text.c +++ b/win32/text.c @@ -513,7 +513,7 @@ apc_gp_text_out( Handle self, const char * text, int x, int y, int len, int flag their geometrical limits. */ if ( len > div) len = div; - if ( sys alpha < 255 || apc_gp_is_font_colored(self)) + if ( sys alpha < 255 || apc_font_is_colored(self)) return shaped_text_out( self, text, x, y, len, flags); if ( flags & toUTF8 ) { @@ -677,7 +677,7 @@ apc_gp_glyphs_out( Handle self, PGlyphsOutRec t, int x, int y) if ( t->len > 8192 ) t->len = 8192; use_path = GetROP2( sys ps) != R2_COPYPEN; use_alpha = sys alpha < 255; - want_color = t->fonts ? true : apc_gp_is_font_colored(self); + want_color = t->fonts ? true : apc_font_is_colored(self); if ( use_path ) { STYLUS_USE_BRUSH; BeginPath(ps); @@ -2148,7 +2148,7 @@ apc_gp_get_text_out_baseline( Handle self) } Bool -apc_gp_is_font_colored( Handle self) +apc_font_is_colored( Handle self) { objCheck false; return dwrite_is_font_colored(self, sys dc_font);