![]() | template beta trials |
| A demo area showing the first trials of the templating system that I am working on. The beta code for using these templates is included in the present class, but is not yet finalised, nor documented. |
|
This template produces an origami cd wallet - I know this is a bit unusual, but I'll make things like faxes and business letters next, I am just playing with this at the moment.
I have 'stolen' the idea for this from this guy, and for instructions about how to fold up these creations you are best to have a look at the pdf file from his site. This template make basically the same cd wallet, but allows you to have a title and description on the back, and draws in the lines for you. Note that if you are just here to make cd-wallets then I have made another version which now has more functionality, please visit it at http://ros.co.nz/cdwallet/ |
| The system being developed for templates allows each template to be passed a couple of arrays of information (one for data, one for options). The template is actually PHP code, so is almost like a user defined class function, I am sure that this is not exactly what people had in mind for templates, but seems to me to be the simplest way to give a fully flexible system. |
|
Try it out Use this form to enter your title and description (multi-line allowed), and submit to produce your cd-wallet. |
The file which instances the ezPdf class and calls the template, on response to this form looks like:
<?php
include('class.ezpdf.php');
$pdf =& new Cezpdf($paper);
$tid = $pdf->loadTemplate('cd_cover.tpl');
$pdf->selectFont('fonts/Helvetica');
$pdf->execTemplate($tid,array('title'=>$title,'description'=>$desc));
$pdf->stream();
?>
|
And the template code itself, (cd_cover.tpl) is:
<?php
//============================================================================
// trial ezPdf template.
//
// the template code will effectively be executed within an ezPdf function
// there will be two arrays which should be set, and this is intended way for
// the template to receive information, those arrays are:
// data -> will contain the data
// options -> will contain the various options which control the appearance
// note that the format of these two is completely arbitrary, and will be
// different for each template.
//
// it will be possible to have function within a template, but they will end
// up in global scope, so should be named accordingly, I suggest prefixing them
// all with 'ezPdfTMPL_', though that might be more of a mouthful than most
// people want. (future versions may parse the function names to unique values
// at run time).
//============================================================================
// this is a template to produce an origami plan for an envelope to hold a cd
// it can include the title, and descriptions etc.
// the data array will contain two items:
// 'title'
// 'description'
// nothing is expected in the options array.
// find the size that the page has been set to:
$pw = $this->ez['pageWidth'];
$ph = $this->ez['pageHeight'];
// note that the margins are being ignored for this template.
// cd diameter is 120mm, allow an extra 3 mm each side for the fold, thickness, slop etc
$diam = 120/25.4*72; // convert to points
$slop = 3*2/25.4*72;
// draw the verticals;
$this->setLineStyle(0.5,'','',array(10));
$this->setStrokeColor(0.5,0.5,0.5);
$fh=100;
$x0 = ($pw-$diam-$slop)/2;
$x1 = $x0+$diam+$slop;
$this->line($x0,0,$x0,$ph-$fh);
$this->line($x1,0,$x1,$ph-$fh);
$this->setLineStyle(0.5,'','',array(2));
$this->line($x0,$ph-$fh,$x0,$ph);
$this->line($x1,$ph-$fh,$x1,$ph);
// make the flap 200 points big, so put a line across
$y=$ph-200;
$this->line(0,$y,$x0,$y);
$this->line($x1,$y,$pw,$y);
$this->setLineStyle(0.5,'','',array(10));
$this->line($x0,$y,$x1,$y);
// and the spine 10 points
$y-=10;
$this->setLineStyle(0.5,'','',array(2));
$this->line(0,$y,$x0,$y);
$this->line($x1,$y,$pw,$y);
$this->setLineStyle(0.5,'','',array(10));
$this->line($x0,$y,$x1,$y);
$textPos = $y;
// allow the same cd slop in the vertical direction
$y-= ($diam+$slop);
$this->setLineStyle(0.5,'','',array(2));
$this->line(0,$y,$x0,$y);
$this->line($x1,$y,$pw,$y);
$this->setLineStyle(0.5,'','',array(10));
$this->line($x0,$y,$x1,$y);
// add in the markers for the flap folds
$this->line($x0,$ph-$fh,$x0+$fh,$ph);
$this->line($x0,$ph-$fh,$x0-$fh,$ph);
$this->line($x1,$ph-$fh,$x1+$fh,$ph);
$this->line($x1,$ph-$fh,$x1-$fh,$ph);
// and also the bottom folds
$this->line($x0,$y,0,$y+$x0);
$this->line($x1,$y,$pw,$y-$x1+$pw);
$this->setLineStyle(0.5,'','',array(2));
$this->line($x0,$y,0,$y-$x0);
$this->line($x1,$y,$pw,$y+$x1-$pw);
// then add the title and description text
$this->y = $textPos;
if (isset($data['title'])){
if (is_array($data['title'])){
$title = implode("\n",$data['title']);
} else {
$title=$data['title'];
}
$this->ezSetDy(-10);
$this->ez['leftMargin']=0;
$this->ez['rightMargin']=0;
$this->ezText($title,16,array('left'=>$x0+10,'right'=>($pw-$x1+10),'justification'=>'center'));
}
if (isset($data['description'])){
if (is_array($data['description'])){
$desc = implode("\n",$data['description']);
} else {
$desc=$data['description'];
}
$this->ezSetDy(-10);
$this->ez['leftMargin']=0;
$this->ez['rightMargin']=0;
$this->ezText($desc,10,array('left'=>$x0+10,'right'=>($pw-$x1+10),'justification'=>'left'));
}
?>
|