PageSetup   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 76
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 8
Bugs 0 Features 1
Metric Value
wmc 2
c 8
b 0
f 1
lcom 0
cbo 4
dl 0
loc 76
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
B getData() 0 37 1
A calcGrbit() 0 22 1
1
<?php
2
3
namespace Xls\Record;
4
5
use Xls\Worksheet;
6
7
class PageSetup extends AbstractRecord
8
{
9
    const NAME = 'PAGESETUP';
10
    const ID = 0xA1;
11
12
    /**
13
     * @param Worksheet $sheet
14
     *
15
     * @return string
16
     */
17
    public function getData($sheet)
18
    {
19
        $printSetup = $sheet->getPrintSetup();
20
21
        $iPaperSize = $printSetup->getPaperSize(); // Paper size
22
        $iScale = $printSetup->getPrintScale(); // Print scaling factor
23
        $iPageStart = 0x01; // Starting page number
24
        $iFitWidth = $printSetup->getFitWidth(); // Fit to number of pages wide
25
        $iFitHeight = $printSetup->getFitHeight(); // Fit to number of pages high
26
        $iRes = 0x0258; // Print resolution
27
        $iVRes = 0x0258; // Vertical print resolution
28
29
        $margin = $printSetup->getMargin();
30
        $numHdr = $margin->getHead(); // Header Margin
31
        $numFtr = $margin->getFoot(); // Footer Margin
32
33
        $numHdr = pack("d", $numHdr);
34
        $numFtr = pack("d", $numFtr);
35
36
        $data = pack(
37
            "vvvvvvvv",
38
            $iPaperSize,
39
            $iScale,
40
            $iPageStart,
41
            $iFitWidth,
42
            $iFitHeight,
43
            $this->calcGrbit($sheet),
44
            $iRes,
45
            $iVRes
46
        );
47
        $data .= $numHdr . $numFtr;
48
49
        $iCopies = 0x01; // Number of copies
50
        $data .= pack("v", $iCopies);
51
52
        return $this->getFullRecord($data);
53
    }
54
55
    /**
56
     * @param Worksheet $worksheet
57
     *
58
     * @return int
59
     */
60
    protected function calcGrbit(Worksheet $worksheet)
61
    {
62
        $fLeftToRight = 0x0; // Print over then down
63
        $fLandscape = $worksheet->getPrintSetup()->getOrientation(); // Page orientation
64
        $fNoPls = 0x0; // Setup not read from printer
65
        $fNoColor = 0x0; // Print black and white
66
        $fDraft = 0x0; // Print draft quality
67
        $fNotes = 0x0; // Print notes
68
        $fNoOrient = 0x0; // Orientation not set
69
        $fUsePage = 0x0; // Use custom starting page
70
71
        $grbit = $fLeftToRight;
72
        $grbit |= $fLandscape << 1;
73
        $grbit |= $fNoPls << 2;
74
        $grbit |= $fNoColor << 3;
75
        $grbit |= $fDraft << 4;
76
        $grbit |= $fNotes << 5;
77
        $grbit |= $fNoOrient << 6;
78
        $grbit |= $fUsePage << 7;
79
80
        return $grbit;
81
    }
82
}
83