From bb8e7dcab87bec14717d8ecd2a2d18411fd3787d Mon Sep 17 00:00:00 2001 From: Dmitry Karasik Date: Sun, 24 Nov 2024 09:41:51 +0100 Subject: [PATCH] update missing merge from write --- class/Drawable.c | 2 +- include/apricot.h | 6 +++--- include/unix/guts.h | 7 +++++++ unix/app.c | 11 ++++++++--- unix/font.c | 33 ++++++++++++++++++++++++++++++++- unix/freetype.c | 19 +++++++++++++++++++ unix/graphics.c | 6 ------ unix/render.c | 4 ++-- unix/xft.c | 13 +++++++++++++ win32/text.c | 8 ++++---- 10 files changed, 89 insertions(+), 20 deletions(-) diff --git a/class/Drawable.c b/class/Drawable.c index e0d9b7807..42d5cd3fc 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 f66c08f81..5395b5809 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); @@ -4333,6 +4330,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, int *type); +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 fd0ad985d..46a5a8653 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/app.c b/unix/app.c index 433d87221..ce12ba51d 100644 --- a/unix/app.c +++ b/unix/app.c @@ -64,12 +64,17 @@ x_error_handler( Display *d, XErrorEvent *ev) return 0; } -#ifdef NEED_X11_EXTENSIONS_XRENDER_H +#ifdef HAVE_X11_EXTENSIONS_XRENDER_H if ( ev-> request_code == guts. xft_xrender_major_opcode && ev-> request_code > 127 && - ev-> error_code == BadLength) - /* Xrender large polygon request failed */ + ev-> error_code == BadLength) { + /* Xrender large polygon request failed, + or colored glyphs over an older X11 server + */ + if ( guts. xft_disable_large_fonts ) + return 1; guts. xft_disable_large_fonts = 1; + } #endif #ifdef HAVE_X11_EXTENSIONS_XCOMPOSITE_H diff --git a/unix/font.c b/unix/font.c index cd9138020..2337aea51 100644 --- a/unix/font.c +++ b/unix/font.c @@ -821,11 +821,42 @@ 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; + 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; + +#ifdef USE_FONTQUERY + if ( is_opt(optInFontQuery) ) { + return false; /* XXX because colored bitmaps are not supported */ + } +#endif + +#ifdef USE_XFT + if ( f->xft ) { + Bool ok = prima_xft_is_font_colored(self); + f->has_colors = ok ? 1 : -1; + return ok; + } +#endif + + 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 3a631c772..8ce953cb9 100644 --- a/unix/freetype.c +++ b/unix/freetype.c @@ -382,5 +382,24 @@ 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 l1 = 0, l2 = 0; + + FT_Library_Version(ft_library,&a,&b,&c); + 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, &l1) == 0) && + (FT_Load_Sfnt_Table(face, TTAG_CPAL, 0, NULL, &l2) == 0) + ; +#else + return false; +#endif +} + #endif diff --git a/unix/graphics.c b/unix/graphics.c index d543b6f6c..df9361bc6 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_get_text_colored( Handle self) -{ - return false; -} - Bool apc_gp_get_text_out_baseline( Handle self) { diff --git a/unix/render.c b/unix/render.c index d7a08ec93..d6646a391 100644 --- a/unix/render.c +++ b/unix/render.c @@ -32,7 +32,7 @@ typedef struct { static Pen pen; -#ifdef NEED_X11_EXTENSIONS_XRENDER_H +#ifdef HAVE_X11_EXTENSIONS_XRENDER_H /* piece of Xrender guts */ typedef struct _XExtDisplayInfo { struct _XExtDisplayInfo *next; @@ -62,7 +62,7 @@ prima_init_xrender_subsystem(char * error_buf, Bool disable_argb32) if ( !guts. render_extension ) return true; -#ifdef NEED_X11_EXTENSIONS_XRENDER_H +#ifdef HAVE_X11_EXTENSIONS_XRENDER_H { /* snatch error code from xrender guts */ XExtDisplayInfo *info = XRenderFindDisplay( DISP); if ( info && info-> codes) diff --git a/unix/xft.c b/unix/xft.c index 0d1a74b3e..2ad70479a 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 e112950b8..5bc562f79 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); @@ -2217,7 +2217,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); @@ -2301,7 +2301,7 @@ apc_font_get_glyph_bitmap( Handle self, uint16_t index, unsigned int flags, PPoi if ( !(flags & ggoMonochrome) && (flags & ggoARGB) && - apc_gp_is_font_colored + apc_font_is_colored ) { //dwrite_draw_bitmap( self, index, *size, *offset); }