Code Coverage
 
Classes and Traits
Functions and Methods
Lines
Total
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 22
CRAP
0.00% covered (danger)
0.00%
0 / 101
PdfPageHelper
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 22
812.00
0.00% covered (danger)
0.00%
0 / 100
 arc
0.00% covered (danger)
0.00%
0 / 1
2.00
0.00% covered (danger)
0.00%
0 / 3
 circle
0.00% covered (danger)
0.00%
0 / 1
2.00
0.00% covered (danger)
0.00%
0 / 3
 concat
0.00% covered (danger)
0.00%
0 / 1
2.00
0.00% covered (danger)
0.00%
0 / 3
 createLinkAnnotation
0.00% covered (danger)
0.00%
0 / 1
2.00
0.00% covered (danger)
0.00%
0 / 3
 createTextAnnotation
0.00% covered (danger)
0.00%
0 / 1
2.00
0.00% covered (danger)
0.00%
0 / 3
 createURLAnnotation
0.00% covered (danger)
0.00%
0 / 1
2.00
0.00% covered (danger)
0.00%
0 / 3
 curveTo2
0.00% covered (danger)
0.00%
0 / 1
2.00
0.00% covered (danger)
0.00%
0 / 3
 curveTo3
0.00% covered (danger)
0.00%
0 / 1
2.00
0.00% covered (danger)
0.00%
0 / 3
 curveTo
0.00% covered (danger)
0.00%
0 / 1
2.00
0.00% covered (danger)
0.00%
0 / 3
 drawImage
0.00% covered (danger)
0.00%
0 / 1
2.00
0.00% covered (danger)
0.00%
0 / 3
 ellipse
0.00% covered (danger)
0.00%
0 / 1
2.00
0.00% covered (danger)
0.00%
0 / 3
 getHeight
0.00% covered (danger)
0.00%
0 / 1
2.00
0.00% covered (danger)
0.00%
0 / 3
 getWidth
0.00% covered (danger)
0.00%
0 / 1
2.00
0.00% covered (danger)
0.00%
0 / 3
 lineTo
0.00% covered (danger)
0.00%
0 / 1
2.00
0.00% covered (danger)
0.00%
0 / 4
 moveTextPos
0.00% covered (danger)
0.00%
0 / 1
2.00
0.00% covered (danger)
0.00%
0 / 3
 moveTo
0.00% covered (danger)
0.00%
0 / 1
2.00
0.00% covered (danger)
0.00%
0 / 4
 rectangle
0.00% covered (danger)
0.00%
0 / 1
2.00
0.00% covered (danger)
0.00%
0 / 3
 textOut
0.00% covered (danger)
0.00%
0 / 1
6.00
0.00% covered (danger)
0.00%
0 / 8
 textRect
0.00% covered (danger)
0.00%
0 / 1
2.00
0.00% covered (danger)
0.00%
0 / 3
 horizontalLine
0.00% covered (danger)
0.00%
0 / 1
12.00
0.00% covered (danger)
0.00%
0 / 9
 printText
0.00% covered (danger)
0.00%
0 / 1
12.00
0.00% covered (danger)
0.00%
0 / 21
 saveTextPos
0.00% covered (danger)
0.00%
0 / 1
6.00
0.00% covered (danger)
0.00%
0 / 6
<?php
namespace common\helpers;
use HaruDoc;
use HaruPage;
class PdfPageHelper extends \yii\base\BaseObject
{
    public static $marginTop = 15;
    public static $marginRight = 15;
    public static $marginBottom = 15;
    public static $marginLeft = 15;
    public static function arc($page, $x, $y, $ray, $ang1, $ang2)
    {
        return $page->arc($x + static::$marginRight, $y, $ray, $ang1, $ang2);
    }
    public static function circle($page, $x, $y, $ray)
    {
        return $page->circle($x + static::$marginRight, $y, $ray);
    }
    public static function concat($page, $a, $b, $c, $d, $x, $y)
    {
        return $page->concat($a, $b, $c, $d, $x + static::$marginRight, $y);
    }
    public static function createLinkAnnotation($page, $rectangle, $destination)
    {
        return $page->createLinkAnnotation($rectangle, $destination);
    }
    public static function createTextAnnotation($page, $rectangle, $text, $encoder = null)
    {
        return $page->createTextAnnotation($rectangle, $text, $encoder);
    }
    public static function createURLAnnotation($page, $rectangle, $url)
    {
        return $page->createURLAnnotation($rectangle, $url);
    }
    public static function curveTo2($page, $x2, $y2, $x3, $y3)
    {
        return $page->curveTo2($x2, $y2, $x3, $y3);
    }
    
    public static function curveTo3($page, $x1, $y1, $x3, $y3)
    {
        return $page->curveTo3($x1, $y1, $x3, $y3);
    }
    
    public static function curveTo($page, $x1, $y1, $x2, $y2, $x3, $y3)
    {
        return $page->curveTo($x1, $y1, $x2, $y2, $x3, $y3);
    }
    
    public static function drawImage($page, $image, $x, $y, $width, $height)
    {
        return $page->drawImage($image, $x + static::$marginRight, $y, $width, $height);
    }
    
    public static function ellipse($page, $x, $y, $xray, $yray)
    {
        return $page->ellipse($x + static::$marginRight, $y, $xray, $yray);
    }
    public static function getHeight($page)
    {
        return $page->getHeight() - static::$marginTop - static::$marginBottom;
    }
    public static function getWidth($page)
    {
        return $page->getWidth() - static::$marginRight - static::$marginLeft;
    }
    public static function lineTo($page, $x, $y)
    {
        $heigth = $page->getHeight() - static::$marginTop;
        return $page->lineTo($x + static::$marginRight, $heigth - $y);
    }
    
    public static function moveTextPos($page, $x, $y, $set_leading = false)
    {
        return $page->moveTextPos($x + static::$marginRight, $y, $set_leading);
    }
    
    public static function moveTo($page, $x, $y)
    {
        $heigth = $page->getHeight() - static::$marginTop;
        return $page->moveTo($x + static::$marginRight, $heigth - $y);
    }
    
    public static function rectangle($page, $x, $y, $width, $height)
    {
        return $page->rectangle($x + static::$marginRight, $y, $width, $height);
    }
    
    public static function textOut($page, $x, $y, $text)
    {
        if($y < 0){
            $heigth = $page->getHeight() - static::$marginTop - static::$marginBottom;
            $y = $heigth + $y;
        }
        $heigth = $page->getHeight() - static::$marginTop;
        return $page->textOut($x + static::$marginRight, $y + static::$marginBottom, $text);
    }
    
    public static function textRect($page, $left, $top, $right, $bottom, $text, $align = HaruPage::TALIGN_LEFT)
    {
        return $page->textRect($left, $top, $right, $bottom, $text, $align);
    }
    public static function horizontalLine($page, $y, $width = null)
    {
        if($width <= 0)
            $width = $page->getWidth() - static::$marginLeft;
        if($y < 0)
            $y = $page->getHeight() - static::$marginLeft;
        $page->moveTo(static::$marginLeft, $y);
        $page->lineTo($width, $y);
        $page->stroke();
    }
    public static function printText($page, $text, $font, $initPage)
    {
        $margin = 30;
        $left = $margin;
        $top = $page->getHeight() -$margin;
        $right = $page->getWidth() -$margin;
        $bottom = $margin;
        $page->showTextNextLine("");
        for($i = 0, $c = strlen($text); $i < $c;){
            $cc = $page->measureText(substr($text, $i), $right - $left, true);
            $page->showTextNextLine(substr($text, $i, $cc));
            if($page->getCurrentTextPos()['y'] < ($page->getTextLeading() + $bottom)){
                $page->endText();
                $page = $initPage();
                $page->beginText();
                $page->setFontAndSize($font, 10.5); /* set font and size */
                $page->moveTextPos(0, -$page->getCurrentFontSize() *1.25, true);
                $page->moveTextPos($left, $top, false);
            }
            $i += $cc;
        }
    }
    private static $savedTextPos = null;
    public static function saveTextPos($textPos = null)
    {
        if($textPos === null)
            return static::$savedTextPos;
        else
            return static::$savedTextPos = $textPos;
    }
}