Showing changing fonts.
This commit is contained in:
parent
463f2161cd
commit
00a864d6f0
@ -27,6 +27,8 @@ has _guts_device => ( is => 'rw' );
|
||||
|
||||
has _tempdir => ( is => 'rw', );
|
||||
|
||||
has _obj => (is => 'lazy');
|
||||
|
||||
sub _device($self) {
|
||||
if ( !defined $self->_guts_device ) {
|
||||
$self->_tempdir( Path::Tiny->tempdir );
|
||||
@ -59,14 +61,28 @@ sub lf($self) {
|
||||
$self->_device->lf;
|
||||
}
|
||||
|
||||
sub _build__obj($self) {
|
||||
my $obj = Net::Bluetooth->newsocket('RFCOMM');
|
||||
$self->_try_to_connect($obj);
|
||||
return $obj;
|
||||
}
|
||||
|
||||
sub print($self) {
|
||||
$self->_device->print;
|
||||
$self->_guts_device(undef);
|
||||
my $obj = Net::Bluetooth->newsocket('RFCOMM');
|
||||
if ( 0 != $obj->connect( $self->address, $self->port ) ) {
|
||||
die 'Unable to connect to bluetooth';
|
||||
}
|
||||
my $obj = $self->_obj;
|
||||
my $fh = $obj->perlfh;
|
||||
print $fh path( $self->_tempfile )->slurp_raw;
|
||||
}
|
||||
|
||||
sub _try_to_connect($self, $obj, $retries = 3) {
|
||||
if ( 0 == $obj->connect( $self->address, $self->port ) ) {
|
||||
return;
|
||||
}
|
||||
if ($retries == 0) {
|
||||
die 'Unable to connect to bluetooth';
|
||||
}
|
||||
sleep 1;
|
||||
return $self->_try_to_connect($obj, $retries - 1);
|
||||
}
|
||||
1;
|
||||
|
@ -329,7 +329,6 @@ sub print_text( $self, $text, $font_size ) {
|
||||
my $scale_h = $font_size / $ori_height;
|
||||
$cr->save;
|
||||
$cr->scale( $scale_w, $scale_h );
|
||||
say ((($metrics->get_ascent / 1024 )));
|
||||
$cr->set_source_surface(
|
||||
$image,
|
||||
$x / $scale_w,
|
||||
|
@ -13,17 +13,30 @@ use Exd::Utils;
|
||||
|
||||
{
|
||||
# my $device = Exd::DeviceToBluetooth->new( address => '5A:4A:AE:8C:E9:D2', port => 1 );
|
||||
my $device = Exd::DeviceToImage->new( output_file => 'a.png' );
|
||||
my $device =
|
||||
Exd::DeviceToImage->new( output_file => 'a.png' );
|
||||
my $printer = Exd::Printer->new( device => $device );
|
||||
$printer->font('Z003 Medium Italic');
|
||||
for my $font (
|
||||
'Z003 Medium Italic',
|
||||
'Noto Sans CJK JP',
|
||||
'Shadow Into Light Regular'
|
||||
)
|
||||
{
|
||||
$printer->font($font);
|
||||
|
||||
my $hoz = Exd::Utils::get_gd_image('scripts/hoz.jpg');
|
||||
my $hoz = Exd::Utils::get_gd_image('scripts/hoz.jpg');
|
||||
|
||||
$printer->print_text(
|
||||
[ $hoz, 'The best software belongs to everybody', $hoz ], 40 );
|
||||
$printer->image('scripts/hoz.jpg');
|
||||
$printer->print_n_lf(4);
|
||||
$printer->print_text(
|
||||
[
|
||||
$hoz, ' The best software ' , $hoz , ' belongs to everybody ',
|
||||
$hoz
|
||||
],
|
||||
30
|
||||
);
|
||||
$printer->image('scripts/hoz.jpg');
|
||||
$printer->print_n_lf(4);
|
||||
|
||||
$printer->print;
|
||||
$printer->print;
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user