| 1 |
# SPDX-License-Identifier: Artistic-1.0-Perl |
| 2 |
# Copyright (C) 2011 Simon Cozens |
| 3 |
package Text::Gr2::Font; |
| 4 |
use strict; |
| 5 |
no bytes; |
| 6 |
use Encode qw/_utf8_on/; |
| 7 |
|
| 8 |
=head1 NAME |
| 9 |
|
| 10 |
Text::Gr2::Font - Font handling methods |
| 11 |
|
| 12 |
=head1 METHODS |
| 13 |
|
| 14 |
=head2 segment |
| 15 |
|
| 16 |
my $seg = $font->segment($face, $text, |
| 17 |
# Some optional arguments: |
| 18 |
encoding => $enc, # "utf8" || "utf16" || "utf32" |
| 19 |
features => $features, |
| 20 |
script => $script_tag |
| 21 |
); |
| 22 |
|
| 23 |
Makes a L<Text::Gr2::Segment> object from the given text. This is |
| 24 |
what you'll need to do to set text in this font. |
| 25 |
|
| 26 |
=cut |
| 27 |
|
| 28 |
sub segment { |
| 29 |
my ($self, $face, $text, %options) = @_; |
| 30 |
my $encoding = $options{encoding} || "utf8"; |
| 31 |
if ($encoding eq "utf8") { _utf8_on($text) } # In case it isn't already |
| 32 |
my $a; |
| 33 |
my $enc = $encoding =~ /8/ ? 1 : |
| 34 |
$encoding =~ /16/ ? 2 : |
| 35 |
$encoding =~ /32/ ? 4 : 1; |
| 36 |
my $script = $options{script} ? Text::Gr2->str_to_tag($options{script}) : 0; |
| 37 |
my $pFeats = $options{features} || (bless \($a=0), "Text::Gr2::FeatureVal"); |
| 38 |
$self->make_seg($face, $script, $pFeats, $enc, $text, length($text)/$enc, $options{rtl}); |
| 39 |
} |
| 40 |
|
| 41 |
=head1 INTERNAL METHODS |
| 42 |
|
| 43 |
=head2 make_seg |
| 44 |
|
| 45 |
Underlying C interface to make segments. Use C<segment> instead. |
| 46 |
|
| 47 |
=cut |
| 48 |
|
| 49 |
1; |