📄 class.ezpdf.php
字号:
if ($options['showLines']){
if (!$options['showHeadings']){
$y0=$y1;
}
$this->ezPrvtTableDrawLines($pos,$options['gap'],$x0,$x1,$y0,$y1,$y2,$options['lineCol'],$options['innerLineThickness'],$options['outerLineThickness'],$options['showLines']);
}
// close the object for drawing the text on top
if ($options['shaded']){
$this->closeObject();
$this->restoreState();
}
$this->y=$y;
return $y;
}
// ------------------------------------------------------------------------------
function ezProcessText($text){
// this function will intially be used to implement underlining support, but could be used for a range of other
// purposes
$search = array('<u>','<U>','</u>','</U>');
$replace = array('<c:uline>','<c:uline>','</c:uline>','</c:uline>');
return str_replace($search,$replace,$text);
}
// ------------------------------------------------------------------------------
function ezText($text,$size=0,$options=array(),$test=0){
// this will add a string of text to the document, starting at the current drawing
// position.
// it will wrap to keep within the margins, including optional offsets from the left
// and the right, if $size is not specified, then it will be the last one used, or
// the default value (12 I think).
// the text will go to the start of the next line when a return code "\n" is found.
// possible options are:
// 'left'=> number, gap to leave from the left margin
// 'right'=> number, gap to leave from the right margin
// 'aleft'=> number, absolute left position (overrides 'left')
// 'aright'=> number, absolute right position (overrides 'right')
// 'justification' => 'left','right','center','centre','full'
// only set one of the next two items (leading overrides spacing)
// 'leading' => number, defines the total height taken by the line, independent of the font height.
// 'spacing' => a real number, though usually set to one of 1, 1.5, 2 (line spacing as used in word processing)
// if $test is set then this should just check if the text is going to flow onto a new page or not, returning true or false
// apply the filtering which will make the underlining function.
$text = $this->ezProcessText($text);
$newPage=false;
$store_y = $this->y;
if (is_array($options) && isset($options['aleft'])){
$left=$options['aleft'];
} else {
$left = $this->ez['leftMargin'] + ((is_array($options) && isset($options['left']))?$options['left']:0);
}
if (is_array($options) && isset($options['aright'])){
$right=$options['aright'];
} else {
$right = $this->ez['pageWidth'] - $this->ez['rightMargin'] - ((is_array($options) && isset($options['right']))?$options['right']:0);
}
if ($size<=0){
$size = $this->ez['fontSize'];
} else {
$this->ez['fontSize']=$size;
}
if (is_array($options) && isset($options['justification'])){
$just = $options['justification'];
} else {
$just = 'left';
}
// modifications to give leading and spacing based on those given by Craig Heydenburg 1/1/02
if (is_array($options) && isset($options['leading'])) { ## use leading instead of spacing
$height = $options['leading'];
} else if (is_array($options) && isset($options['spacing'])) {
$height = $this->getFontHeight($size) * $options['spacing'];
} else {
$height = $this->getFontHeight($size);
}
$lines = explode("\n",$text);
foreach ($lines as $line)
{
// for each line of text to print
$start=1;
while (strlen($line) || $start)
{
//while there is still some text to print or if this is the first line
$start=0;
$this->y=$this->y-$height; //make Y position depend on font-size
if ($this->y < $this->ez['bottomMargin'])
{
//if this vertical position (Y) is not out of the page
if ($test)
{
//we are on a new page, nothing to do
$newPage=true;
}
else
{
//else start new page
$this->ezNewPage();
// and then re-calc the left and right, in case they have changed due to columns
}
}
if (is_array($options) && isset($options['aleft'])){
//there are options and they include left position
$left=$options['aleft'];
} else {
//there are no options, or they don't include left position
$left = $this->ez['leftMargin'] + ((is_array($options) && isset($options['left']))?$options['left']:0);
}
if (is_array($options) && isset($options['aright'])){
$right=$options['aright'];
} else {
$right = $this->ez['pageWidth'] - $this->ez['rightMargin'] - ((is_array($options) && isset($options['right']))?$options['right']:0);
}
$line=$this->addTextWrap($left,$this->y,$right-$left,$size,$line,$just,0,$test);
}
}
if ($test){
$this->y=$store_y;
return $newPage;
} else {
return $this->y;
}
}
// ------------------------------------------------------------------------------
function ezImage($image,$pad = 5,$width = 0,$resize = 'full',$just = 'center',$border = ''){
//beta ezimage function
if (stristr($image,'://'))//copy to temp file
{
$fp = @fopen($image,"rb");
while(!feof($fp))
{
$cont.= fread($fp,1024);
}
fclose($fp);
$image = tempnam ("/tmp", "php-pdf");
$fp2 = @fopen($image,"w");
fwrite($fp2,$cont);
fclose($fp2);
$temp = true;
}
if (!(file_exists($image))) return false; //return immediately if image file does not exist
$imageInfo = getimagesize($image);
switch ($imageInfo[2]){
case 2:
$type = "jpeg";
break;
case 3:
$type = "png";
break;
default:
return false; //return if file is not jpg or png
}
if ($width == 0) $width = $imageInfo[0]; //set width
$ratio = $imageInfo[0]/$imageInfo[1];
//get maximum width of image
if (isset($this->ez['columns']) && $this->ez['columns']['on'] == 1)
{
$bigwidth = $this->ez['columns']['width'] - ($pad * 2);
}
else
{
$bigwidth = $this->ez['pageWidth'] - ($pad * 2);
}
//fix width if larger than maximum or if $resize=full
if ($resize == 'full' || $resize == 'width' || $width > $bigwidth)
{
$width = $bigwidth;
}
$height = ($width/$ratio); //set height
//fix size if runs off page
if ($height > ($this->y - $this->ez['bottomMargin'] - ($pad * 2)))
{
if ($resize != 'full')
{
$this->ezNewPage();
}
else
{
$height = ($this->y - $this->ez['bottomMargin'] - ($pad * 2)); //shrink height
$width = ($height*$ratio); //fix width
}
}
//fix x-offset if image smaller than bigwidth
if ($width < $bigwidth)
{
//center if justification=center
if ($just == 'center')
{
$offset = ($bigwidth - $width) / 2;
}
//move to right if justification=right
if ($just == 'right')
{
$offset = ($bigwidth - $width);
}
//leave at left if justification=left
if ($just == 'left')
{
$offset = 0;
}
}
//call appropriate function
if ($type == "jpeg"){
$this->addJpegFromFile($image,$this->ez['leftMargin'] + $pad + $offset, $this->y + $this->getFontHeight($this->ez['fontSize']) - $pad - $height,$width);
}
if ($type == "png"){
$this->addPngFromFile($image,$this->ez['leftMargin'] + $pad + $offset, $this->y + $this->getFontHeight($this->ez['fontSize']) - $pad - $height,$width);
}
//draw border
if ($border != '')
{
if (!(isset($border['color'])))
{
$border['color']['red'] = .5;
$border['color']['blue'] = .5;
$border['color']['green'] = .5;
}
if (!(isset($border['width']))) $border['width'] = 1;
if (!(isset($border['cap']))) $border['cap'] = 'round';
if (!(isset($border['join']))) $border['join'] = 'round';
$this->setStrokeColor($border['color']['red'],$border['color']['green'],$border['color']['blue']);
$this->setLineStyle($border['width'],$border['cap'],$border['join']);
$this->rectangle($this->ez['leftMargin'] + $pad + $offset, $this->y + $this->getFontHeight($this->ez['fontSize']) - $pad - $height,$width,$height);
}
// move y below image
$this->y = $this->y - $pad - $height;
//remove tempfile for remote images
if ($temp == true) unlink($image);
}
// ------------------------------------------------------------------------------
// note that templating code is still considered developmental - have not really figured
// out a good way of doing this yet.
function loadTemplate($templateFile){
// this function will load the requested template ($file includes full or relative pathname)
// the code for the template will be modified to make it name safe, and then stored in
// an array for later use
// The id of the template will be returned for the user to operate on it later
if (!file_exists($templateFile)){
return -1;
}
$code = implode('',file($templateFile));
if (!strlen($code)){
return;
}
$code = trim($code);
if (substr($code,0,5)=='<?php'){
$code = substr($code,5);
}
if (substr($code,-2)=='?>'){
$code = substr($code,0,strlen($code)-2);
}
if (isset($this->ez['numTemplates'])){
$newNum = $this->ez['numTemplates'];
$this->ez['numTemplates']++;
} else {
$newNum=0;
$this->ez['numTemplates']=1;
$this->ez['templates']=array();
}
$this->ez['templates'][$newNum]['code']=$code;
return $newNum;
}
// ------------------------------------------------------------------------------
function execTemplate($id,$data=array(),$options=array()){
// execute the given template on the current document.
if (!isset($this->ez['templates'][$id])){
return;
}
eval($this->ez['templates'][$id]['code']);
}
// ------------------------------------------------------------------------------
function ilink($info){
$this->alink($info,1);
}
function alink($info,$internal=0){
// a callback function to support the formation of clickable links within the document
$lineFactor=0.05; // the thickness of the line as a proportion of the height. also the drop of the line.
switch($info['status']){
case 'start':
case 'sol':
// the beginning of the link
// this should contain the URl for the link as the 'p' entry, and will also contain the value of 'nCallback'
if (!isset($this->ez['links'])){
$this->ez['links']=array();
}
$i = $info['nCallback'];
$this->ez['links'][$i] = array('x'=>$info['x'],'y'=>$info['y'],'angle'=>$info['angle'],'decender'=>$info['decender'],'height'=>$info['height'],'url'=>$info['p']);
if ($internal==0){
$this->saveState();
$this->setColor(0,0,1);
$this->setStrokeColor(0,0,1);
$thick = $info['height']*$lineFactor;
$this->setLineStyle($thick);
}
break;
case 'end':
case 'eol':
// the end of the link
// assume that it is the most recent opening which has closed
$i = $info['nCallback'];
$start = $this->ez['links'][$i];
// add underlining
if ($internal){
$this->addInternalLink($start['url'],$start['x'],$start['y']+$start['decender'],$info['x'],$start['y']+$start['decender']+$start['height']);
} else {
$a = deg2rad((float)$start['angle']-90.0);
$drop = $start['height']*$lineFactor*1.5;
$dropx = cos($a)*$drop;
$dropy = -sin($a)*$drop;
$this->line($start['x']-$dropx,$start['y']-$dropy,$info['x']-$dropx,$info['y']-$dropy);
$this->addLink($start['url'],$start['x'],$start['y']+$start['decender'],$info['x'],$start['y']+$start['decender']+$start['height']);
$this->restoreState();
}
break;
}
}
// ------------------------------------------------------------------------------
function uline($info){
// a callback function to support underlining
$lineFactor=0.05; // the thickness of the line as a proportion of the height. also the drop of the line.
switch($info['status']){
case 'start':
case 'sol':
// the beginning of the underline zone
if (!isset($this->ez['links'])){
$this->ez['links']=array();
}
$i = $info['nCallback'];
$this->ez['links'][$i] = array('x'=>$info['x'],'y'=>$info['y'],'angle'=>$info['angle'],'decender'=>$info['decender'],'height'=>$info['height']);
$this->saveState();
$thick = $info['height']*$lineFactor;
$this->setLineStyle($thick);
break;
case 'end':
case 'eol':
// the end of the link
// assume that it is the most recent opening which has closed
$i = $info['nCallback'];
$start = $this->ez['links'][$i];
// add underlining
$a = deg2rad((float)$start['angle']-90.0);
$drop = $start['height']*$lineFactor*1.5;
$dropx = cos($a)*$drop;
$dropy = -sin($a)*$drop;
$this->line($start['x']-$dropx,$start['y']-$dropy,$info['x']-$dropx,$info['y']-$dropy);
$this->restoreState();
break;
}
}
// ------------------------------------------------------------------------------
}
?>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -