Skip to content

Commit

Permalink
hide begin/end font_query from perl
Browse files Browse the repository at this point in the history
  • Loading branch information
dk committed Dec 10, 2023
1 parent 7319cdc commit 9fa8fa8
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 48 deletions.
1 change: 1 addition & 0 deletions class/Component.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions class/Image.cls
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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);
Expand All @@ -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();
Expand Down
23 changes: 20 additions & 3 deletions class/Image/text.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
41 changes: 2 additions & 39 deletions pod/Prima/Image.pod
Original file line number Diff line number Diff line change
Expand Up @@ -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<begin_font_query> for details.

optimized for LCD screens, the font query subsystem may not.

See individual methods and properties in L<API> that support standalone usage,
and how they differ from system-dependent implementation.

Expand Down Expand Up @@ -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<Prima::Application> 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<begin_paint>/C<end_paint>
brackets (or in modes reported as C<ps::Information> and C<ps::Enabled> by
C<get_paint_state>). The C<get_paint_state> method returns the
C<ps::FontQuery> 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<begin_paint> or C<begin_paint_info> methods is called, the
font query mode is finished automatically. It can also be finished by calling
C<end_font_query>.

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<set_font> method operates in
C<ps::Disabled> and C<ps::FontQuery> modes. In the former mode, a calls to
C<set_font> 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<Prima::Drawable::set_font> does, except that the resulting fonts can be different.

=item bitmap

Returns a newly created C<Prima::DeviceBitmap> object
Expand All @@ -830,10 +797,6 @@ This method can be called without object instance:
Returns a copy of the object, a newly created C<Prima::Image>, 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
Expand Down
5 changes: 1 addition & 4 deletions t/Image/Text.t
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 9fa8fa8

Please sign in to comment.