Font   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 63
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 7
Bugs 0 Features 0
Metric Value
wmc 2
c 7
b 0
f 0
lcom 0
cbo 2
dl 0
loc 63
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
B getData() 0 34 1
A calcGrbit() 0 11 1
1
<?php
2
namespace Xls\Record;
3
4
use Xls\Font as XlsFont;
5
6
class Font extends AbstractRecord
7
{
8
    const NAME = 'FONT';
9
    const ID = 0x0031;
10
11
    /**
12
     * Generate an Excel BIFF FONT record.
13
     * @param XlsFont $font
14
     *
15
     * @return string
16
     */
17
    public function getData(XlsFont $font)
18
    {
19
        $dyHeight = $font->getSize() * 20; // Height of font (1/20 of a point)
20
        $icv = $font->getColor(); // Index to color palette
21
        $bls = $font->getBold(); // Bold style
22
        $sss = $font->getScript(); // Superscript/subscript
23
        $uls = $font->getUnderline(); // Underline
24
        $bFamily = 0x00; // Font family
25
        $bCharSet = 0x00; // Character set
26
27
        $cch = strlen($font->getName()); // Length of font name
28
29
        $reserved = 0x00; // Reserved
30
31
        $data = pack(
32
            "vvvvvCCCCC",
33
            $dyHeight,
34
            $this->calcGrbit($font),
35
            $icv,
36
            $bls,
37
            $sss,
38
            $uls,
39
            $bFamily,
40
            $bCharSet,
41
            $reserved,
42
            $cch
43
        );
44
45
        $encoding = 0;
46
        $data .= pack("C", $encoding);
47
        $data .= $font->getName();
48
49
        return $this->getFullRecord($data);
50
    }
51
52
    /**
53
     * @param XlsFont $font
54
     *
55
     * @return int
56
     */
57
    protected function calcGrbit(XlsFont $font)
58
    {
59
        $grbit = 0x00;
60
61
        $grbit |= intval($font->getItalic()) << 1;
62
        $grbit |= intval($font->getStrikeout()) << 3;
63
        $grbit |= intval($font->getOutline()) << 4;
64
        $grbit |= intval($font->getShadow()) << 5;
65
66
        return $grbit;
67
    }
68
}
69