#!/usr/bin/perl

# show writing opaque and translucent text by two methods

use strict;
use warnings;

use lib '../lib/';
use PDF::Builder;
use PDF::Builder::Util;
use POSIX;

my $compress = 'none'; # uncompressed streams
#my $compress = 'flate'; # compressed streams

my $pdf = PDF::Builder->new(-compress => $compress);
$pdf->mediabox(595,842);

my $TRANSPARENT = $pdf->egstate(); # Called just once
$TRANSPARENT->transparency(0.4);  # only 60% opaqueness

my $fnt = $pdf->corefont('Verdana-Bold');

my $page = $pdf->page();
my $text = $page->text();

# page 1: opaque red text put down, then almost transparent black partly over.
# both texts bleed off right side of page
$text->textlabel(30,750, $fnt,100, '100% Opaque', -color=>'#F00');

$text->egstate($TRANSPARENT);
$text->textlabel(30,720, $fnt,100, '40% Transparent', -color=>'#000');

# page 2: similar to page 1, but using different methods. bleed off left side.
$page = $pdf->page();
$text = $page->text();

$text->font($fnt, 100);
$text->fillcolor('red');
$text->translate(570,750);
$text->text_right('Opaque 100%');
$text->textend(); # back into graphics state so can do transparency

#$text->save();  # unnecessary, as this is the last segment
$text->egstate($TRANSPARENT);
$text->textstart(); # back into text mode
$text->font($fnt, 100);
$text->fillcolor('black');
$text->translate(570,720);
$text->text_right('Transparent 40%');
$text->textend();
#$text->restore();

$pdf->saveas("$0.pdf");
$pdf->end();

exit;

__END__
