例えばGD::Barcode::EAN13の表示方法を少々(ピクセル単位で)調整したいとなると、継承してplot()をほげほげするのが一番ラクなんだが、よーくソースコードを読むと
ぐはあああ。引数1個のbless()だ。自動的にblessするパッケージ名を判別してくれない・・・。
ということで、MyBarcodeサブクラスを作る時は、
ちなみに今回はGD::Font->Tinyを使いたかったのと、その後1ピクセルだけ隙間をあけたかったので、こうなる:
sub new($$) {
my($sClass, $sTxt) = @_;
$errStr ='';
my $oThis = {};
bless $oThis;
return undef if($errStr = $oThis->init($sTxt));
return $oThis;
}
ぐはあああ。引数1個のbless()だ。自動的にblessするパッケージ名を判別してくれない・・・。
ということで、MyBarcodeサブクラスを作る時は、
package MyBarcode;
use strict;
use base qw(GD::Barcode::EAN13);
sub new {
my $class = shift;
my $self = $class->SUPER::new(@_);
bless $self, $class;
return $self;
}
とするのが吉。ちなみに今回はGD::Font->Tinyを使いたかったのと、その後1ピクセルだけ隙間をあけたかったので、こうなる:
sub plot($;%) {
my($oThis, %hParam) = @_;
#Barcode Pattern
my $sPtn = $oThis->barcode();
#Create Image
my $iHeight = ($hParam{Height})? $hParam{Height} : 50;
my($oGd, $cBlack);
if($hParam{NoText}) {
($oGd, $cBlack) = GD::Barcode::plot($sPtn, length($sPtn), $iHeight, 0, 0);
}
else {
my($fW,$fH) = (GD::Font->Tiny->width,GD::Font->Tiny->height);
my $iWidth = length($sPtn)+$fW+1;
($oGd, $cBlack) = GD::Barcode::plot($sPtn, $iWidth, $iHeight, $fH + 1, $fW+1);
$oGd->string(GD::Font->Tiny, 0, $iHeight - $fH, substr($oThis->{text}, 0, 1), $cBlack);
$oGd->string(GD::Font->Tiny, $fW +8 , $iHeight - $fH, substr($oThis->{text}, 1, 6), $cBlack);
$oGd->string(GD::Font->Tiny, $fW +55, $iHeight - $fH, substr($oThis->{text}, 7, 6), $cBlack);
}
return $oGd;
}
コメント