From 9fa8fa8cc2ddfd83bc843675a15bce069d4f45d4 Mon Sep 17 00:00:00 2001 From: Dmitry Karasik Date: Sun, 10 Dec 2023 11:56:55 +0100 Subject: [PATCH] hide begin/end font_query from perl --- class/Component.c | 1 + class/Image.cls | 5 +++-- class/Image/text.c | 23 ++++++++++++++++++++--- pod/Prima/Image.pod | 41 ++--------------------------------------- t/Image/Text.t | 5 +---- 5 files changed, 27 insertions(+), 48 deletions(-) diff --git a/class/Component.c b/class/Component.c index a4b853b35..98cb67f29 100644 --- a/class/Component.c +++ b/class/Component.c @@ -50,6 +50,7 @@ Component_init( Handle self, HV * profile) my-> add_notification( self, HeKEY( he), *holder, self, -1); } sv_free( res); + CORE_INIT_TRANSIENT(Component); } void diff --git a/class/Image.cls b/class/Image.cls index f2cdff254..b376dbe61 100644 --- a/class/Image.cls +++ b/class/Image.cls @@ -43,7 +43,7 @@ object Prima::Image( Prima::Drawable) method Bool bar_alpha(int alpha, int x1=-1, int y1=-1, int x2=-1, int y2=-1); method Bool bars(SV * rects); method Handle bitmap(); - method Bool begin_font_query(); + c_only Bool begin_font_query(); method Bool begin_paint(); method Bool begin_paint_info(); method Bool can_draw_alpha(); @@ -55,7 +55,7 @@ object Prima::Image( Prima::Drawable) method void done(); method Handle dup(); method Bool ellipse(double x, double y, double dX, double dY); - method void end_font_query(); + c_only void end_font_query(); method void end_paint(); method void end_paint_info(); method Handle extract( int x, int y, int width, int height); @@ -68,6 +68,7 @@ object Prima::Image( Prima::Drawable) method SV* fonts( char * name = "", char * encoding = ""); method SV* font_encodings( char * encoding = ""); method int get_bpp(); + method Font get_font(); method SV * get_handle(); method Color get_nearest_color( Color color); method Bool graphic_context_push(); diff --git a/class/Image/text.c b/class/Image/text.c index a0d83d57f..e62586b3a 100644 --- a/class/Image/text.c +++ b/class/Image/text.c @@ -46,13 +46,30 @@ Image_font_match( SV * dummy, Font * source, Font * dest, Bool pick) return dest; } +Font +Image_get_font( Handle self) +{ + if ( !is_opt(optInFontQuery)) + my-> begin_font_query(self); + + return var-> font; +} + void Image_set_font( Handle self, Font font) { - if (opt_InPaint || is_opt(optInFontQuery)) - return inherited set_font(self, font); - Drawable_font_add( self, &font, &var->font); + if ( + !is_opt(optInFontQuery) && /* special case during inherited init */ + var->transient_class == CComponent /* to not enter for every image creation */ + ) { /* until at least some font operations are needed */ + Drawable_font_add( self, &font, &var->font); + return; + } + + if ( !is_opt(optInFontQuery)) + my-> begin_font_query(self); + inherited set_font(self, font); } static PTextShapeRec diff --git a/pod/Prima/Image.pod b/pod/Prima/Image.pod index 90c9f8cf5..6bea320fa 100644 --- a/pod/Prima/Image.pod +++ b/pod/Prima/Image.pod @@ -273,9 +273,8 @@ All text API is also supported (on unix if Prima is compiled with freetype and fontconfig) and can be used transparently for the caller. The list of available fonts, and their renderings, may differ from the fonts available in the system. For example, where the system may choose to render glyphs with pixel layout -optimized for LCD screens, the font query subsystem may not. See -C for details. - +optimized for LCD screens, the font query subsystem may not. + See individual methods and properties in L that support standalone usage, and how they differ from system-dependent implementation. @@ -773,38 +772,6 @@ involving the system backend. =over -=item begin_font_query - -Enters a special mode that allows to query font and text information without -requiring C object to be instantiated, and in particular, -no X11 connection on unix. With this mode on, the system reports all the text -and font information that is available inside C/C -brackets (or in modes reported as C and C by -C). The C method returns the -C value when this mode is on. - -The mode can be entered both by explicitly calling on it manually, and implicitly -when performing any font or text related input or output. For example, these are -equivalent: - - $image->text_out(...); - -and - - $image->begin_font_query; - $image->text_out(...); - -When either of the C or C methods is called, the -font query mode is finished automatically. It can also be finished by calling -C. - -In the majority of cases, one shouldn't use this method. The only reason to do -so is to use the difference of how the C method operates in -C and C modes. In the former mode, a calls to -C only stores the new font in the object, while in the latter mode, -the resulting font is also matched towards the system font collection, exactly -as C does, except that the resulting fonts can be different. - =item bitmap Returns a newly created C object @@ -830,10 +797,6 @@ This method can be called without object instance: Returns a copy of the object, a newly created C, with all properties copied. Does not preserve the graphical properties though (color etc). -=item end_font_query - -Ends the font query mode. - =item extract X_OFFSET, Y_OFFSET, WIDTH, HEIGHT Returns a newly created image object with dimensions equal to or less than diff --git a/t/Image/Text.t b/t/Image/Text.t index 9ccdf8a3d..c8e4f219d 100644 --- a/t/Image/Text.t +++ b/t/Image/Text.t @@ -16,13 +16,10 @@ if ( $^O !~ /win32/i && 0 == grep { $_ eq 'freetype' } @{ $Prima::Config::Config my $i = Prima::Image->new( size => [50,50], type => im::BW ); is( $i-> get_paint_state, ps::Disabled, 'get_paint_state == ps::Disabled'); -ok( $i->begin_font_query, 'begin font query'); +$i->get_font; is( $i-> get_paint_state, ps::FontQuery, 'get_paint_state == ps::FontQuery'); -$i->end_font_query; -is( $i-> get_paint_state, ps::Disabled, 'end_font_query == ps::Disabled'); unless ( $noX11 ) { - ok( $i->begin_font_query, 'begin font query again'); ok( $i->begin_paint_info, 'begin paint info'); is( $i-> get_paint_state, ps::Information, 'get_paint_state == ps::Information'); $i->end_paint_info;