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 _tempdir => ( is => 'rw', );
|
||||||
|
|
||||||
|
has _obj => (is => 'lazy');
|
||||||
|
|
||||||
sub _device($self) {
|
sub _device($self) {
|
||||||
if ( !defined $self->_guts_device ) {
|
if ( !defined $self->_guts_device ) {
|
||||||
$self->_tempdir( Path::Tiny->tempdir );
|
$self->_tempdir( Path::Tiny->tempdir );
|
||||||
@ -59,14 +61,28 @@ sub lf($self) {
|
|||||||
$self->_device->lf;
|
$self->_device->lf;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub _build__obj($self) {
|
||||||
|
my $obj = Net::Bluetooth->newsocket('RFCOMM');
|
||||||
|
$self->_try_to_connect($obj);
|
||||||
|
return $obj;
|
||||||
|
}
|
||||||
|
|
||||||
sub print($self) {
|
sub print($self) {
|
||||||
$self->_device->print;
|
$self->_device->print;
|
||||||
$self->_guts_device(undef);
|
$self->_guts_device(undef);
|
||||||
my $obj = Net::Bluetooth->newsocket('RFCOMM');
|
my $obj = $self->_obj;
|
||||||
if ( 0 != $obj->connect( $self->address, $self->port ) ) {
|
|
||||||
die 'Unable to connect to bluetooth';
|
|
||||||
}
|
|
||||||
my $fh = $obj->perlfh;
|
my $fh = $obj->perlfh;
|
||||||
print $fh path( $self->_tempfile )->slurp_raw;
|
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;
|
1;
|
||||||
|
@ -329,7 +329,6 @@ sub print_text( $self, $text, $font_size ) {
|
|||||||
my $scale_h = $font_size / $ori_height;
|
my $scale_h = $font_size / $ori_height;
|
||||||
$cr->save;
|
$cr->save;
|
||||||
$cr->scale( $scale_w, $scale_h );
|
$cr->scale( $scale_w, $scale_h );
|
||||||
say ((($metrics->get_ascent / 1024 )));
|
|
||||||
$cr->set_source_surface(
|
$cr->set_source_surface(
|
||||||
$image,
|
$image,
|
||||||
$x / $scale_w,
|
$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::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 );
|
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(
|
$printer->print_text(
|
||||||
[ $hoz, 'The best software belongs to everybody', $hoz ], 40 );
|
[
|
||||||
$printer->image('scripts/hoz.jpg');
|
$hoz, ' The best software ' , $hoz , ' belongs to everybody ',
|
||||||
$printer->print_n_lf(4);
|
$hoz
|
||||||
|
],
|
||||||
|
30
|
||||||
|
);
|
||||||
|
$printer->image('scripts/hoz.jpg');
|
||||||
|
$printer->print_n_lf(4);
|
||||||
|
|
||||||
$printer->print;
|
$printer->print;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user