Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
3 / 3
CRAP
100.00% covered (success)
100.00%
1 / 1
AbstractStandard
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
3 / 3
5
100.00% covered (success)
100.00%
1 / 1
 getUnitsPerEm
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getGlyphWidth
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
3
 hasGlyph
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2declare(strict_types=1);
3/**
4 * Pop PHP Framework (https://www.popphp.org/)
5 *
6 * @link       https://github.com/popphp/popphp-framework
7 * @author     Nick Sagona, III <nick@popphp.org>
8 * @copyright  Copyright (c) 2009-2026 Nick Sagona, III
9 * @license    https://www.popphp.org/license     New BSD License
10 */
11
12/**
13 * @namespace
14 */
15namespace Pop\Pdf\Build\Font\Standard;
16
17/**
18 * Pdf abstract standard font class
19 *
20 * @category   Pop
21 * @package    Pop\Pdf
22 * @author     Nick Sagona, III <nick@popphp.org>
23 * @copyright  Copyright (c) 2009-2026 Nick Sagona, III
24 * @license    https://www.popphp.org/license     New BSD License
25 * @version    6.0.0
26 */
27abstract class AbstractStandard
28{
29
30    /**
31     * Font units per em
32     * @var int
33     */
34    protected int $unitsPerEm = 1000;
35
36    /**
37     * Font glyph widths
38     * @var array
39     */
40    protected array $glyphWidths = [];
41
42    /**
43     * Font character map
44     * @var array
45     */
46    protected array $cmap = [];
47
48    /**
49     * Get units per em
50     *
51     * @return int
52     */
53    public function getUnitsPerEm(): int
54    {
55        return $this->unitsPerEm;
56    }
57
58    /**
59     * Get character glyph width
60     *
61     * @param  int $code
62     * @return mixed
63     */
64    public function getGlyphWidth(int $code): mixed
65    {
66        if (isset($this->cmap[$code]) && isset($this->glyphWidths[$this->cmap[$code]])) {
67            return $this->glyphWidths[$this->cmap[$code]];
68        } else {
69            return 0;
70        }
71    }
72
73    /**
74     * Determine if this font's character map has a glyph for the given codepoint
75     *
76     * @param  int $code
77     * @return bool
78     */
79    public function hasGlyph(int $code): bool
80    {
81        return isset($this->cmap[$code]);
82    }
83
84}