Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
30 / 30 |
|
100.00% |
11 / 11 |
CRAP | |
100.00% |
1 / 1 |
| RubyProperties | |
100.00% |
30 / 30 |
|
100.00% |
11 / 11 |
12 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
1 | |||
| getAlignment | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| setAlignment | |
100.00% |
12 / 12 |
|
100.00% |
1 / 1 |
2 | |||
| getFontFaceSize | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| setFontFaceSize | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| getFontPointsAboveBaseText | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| setFontPointsAboveBaseText | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| getFontSizeForBaseText | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| setFontSizeForBaseText | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| getLanguageId | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| setLanguageId | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * This file is part of PHPWord - A pure PHP library for reading and writing |
| 5 | * word processing documents. |
| 6 | * |
| 7 | * PHPWord is free software distributed under the terms of the GNU Lesser |
| 8 | * General Public License version 3 as published by the Free Software Foundation. |
| 9 | * |
| 10 | * For the full copyright and license information, please read the LICENSE |
| 11 | * file that was distributed with this source code. For the full list of |
| 12 | * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. |
| 13 | * |
| 14 | * @see https://github.com/PHPOffice/PHPWord |
| 15 | * |
| 16 | * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 |
| 17 | */ |
| 18 | |
| 19 | namespace PhpOffice\PhpWord\ComplexType; |
| 20 | |
| 21 | use InvalidArgumentException; |
| 22 | |
| 23 | /** |
| 24 | * Ruby properties. |
| 25 | * |
| 26 | * @see https://learn.microsoft.com/en-us/dotnet/api/documentformat.openxml.wordprocessing.rubyproperties?view=openxml-3.0.1 |
| 27 | */ |
| 28 | class RubyProperties |
| 29 | { |
| 30 | const ALIGNMENT_CENTER = 'center'; |
| 31 | const ALIGNMENT_DISTRIBUTE_LETTER = 'distributeLetter'; |
| 32 | const ALIGNMENT_DISTRIBUTE_SPACE = 'distributeSpace'; |
| 33 | const ALIGNMENT_LEFT = 'left'; |
| 34 | const ALIGNMENT_RIGHT = 'right'; |
| 35 | const ALIGNMENT_RIGHT_VERTICAL = 'rightVertical'; |
| 36 | |
| 37 | /** |
| 38 | * Ruby alignment (w:rubyAlign). |
| 39 | * |
| 40 | * @var string |
| 41 | */ |
| 42 | private $alignment; |
| 43 | |
| 44 | /** |
| 45 | * Ruby font face size (w:hps). |
| 46 | * |
| 47 | * @var float |
| 48 | */ |
| 49 | private $fontFaceSize; |
| 50 | |
| 51 | /** |
| 52 | * Ruby font points above base text (w:hpsRaise). |
| 53 | * |
| 54 | * @var float |
| 55 | */ |
| 56 | private $fontPointsAboveText; |
| 57 | |
| 58 | /** |
| 59 | * Ruby font size for base text (w:hpsBaseText). |
| 60 | * |
| 61 | * @var float |
| 62 | */ |
| 63 | private $baseTextFontSize; |
| 64 | |
| 65 | /** |
| 66 | * Ruby type/language id (w:lid). |
| 67 | * |
| 68 | * @var string |
| 69 | */ |
| 70 | private $languageId; |
| 71 | |
| 72 | /** |
| 73 | * Create a new RubyProperties object. |
| 74 | */ |
| 75 | public function __construct() |
| 76 | { |
| 77 | // these defaults came from opening a new Word doc, adding some ruby text to some |
| 78 | // Japanese text, and copying out the defaults. |
| 79 | $this->alignment = self::ALIGNMENT_DISTRIBUTE_SPACE; |
| 80 | $this->fontFaceSize = 12; |
| 81 | $this->fontPointsAboveText = 22; |
| 82 | $this->languageId = 'ja-JP'; |
| 83 | $this->baseTextFontSize = 24; |
| 84 | } |
| 85 | |
| 86 | /** |
| 87 | * Get the ruby alignment. |
| 88 | */ |
| 89 | public function getAlignment(): string |
| 90 | { |
| 91 | return $this->alignment; |
| 92 | } |
| 93 | |
| 94 | /** |
| 95 | * Set the Ruby Alignment (center, distributeLetter, distributeSpace, left, right, rightVertical). |
| 96 | */ |
| 97 | public function setAlignment(string $alignment): self |
| 98 | { |
| 99 | $alignmentTypes = [ |
| 100 | self::ALIGNMENT_CENTER, |
| 101 | self::ALIGNMENT_DISTRIBUTE_LETTER, |
| 102 | self::ALIGNMENT_DISTRIBUTE_SPACE, |
| 103 | self::ALIGNMENT_LEFT, |
| 104 | self::ALIGNMENT_RIGHT, |
| 105 | self::ALIGNMENT_RIGHT_VERTICAL, |
| 106 | ]; |
| 107 | |
| 108 | if (in_array($alignment, $alignmentTypes)) { |
| 109 | $this->alignment = $alignment; |
| 110 | } else { |
| 111 | throw new InvalidArgumentException('Invalid value, alignments of ' . implode(', ', $alignmentTypes) . ' possible'); |
| 112 | } |
| 113 | |
| 114 | return $this; |
| 115 | } |
| 116 | |
| 117 | /** |
| 118 | * Get the ruby font face size. |
| 119 | */ |
| 120 | public function getFontFaceSize(): float |
| 121 | { |
| 122 | return $this->fontFaceSize; |
| 123 | } |
| 124 | |
| 125 | /** |
| 126 | * Set the ruby font face size. |
| 127 | */ |
| 128 | public function setFontFaceSize(float $size): self |
| 129 | { |
| 130 | $this->fontFaceSize = $size; |
| 131 | |
| 132 | return $this; |
| 133 | } |
| 134 | |
| 135 | /** |
| 136 | * Get the ruby font points above base text. |
| 137 | */ |
| 138 | public function getFontPointsAboveBaseText(): float |
| 139 | { |
| 140 | return $this->fontPointsAboveText; |
| 141 | } |
| 142 | |
| 143 | /** |
| 144 | * Set the ruby font points above base text. |
| 145 | */ |
| 146 | public function setFontPointsAboveBaseText(float $size): self |
| 147 | { |
| 148 | $this->fontPointsAboveText = $size; |
| 149 | |
| 150 | return $this; |
| 151 | } |
| 152 | |
| 153 | /** |
| 154 | * Get the ruby font size for base text. |
| 155 | */ |
| 156 | public function getFontSizeForBaseText(): float |
| 157 | { |
| 158 | return $this->baseTextFontSize; |
| 159 | } |
| 160 | |
| 161 | /** |
| 162 | * Set the ruby font size for base text. |
| 163 | */ |
| 164 | public function setFontSizeForBaseText(float $size): self |
| 165 | { |
| 166 | $this->baseTextFontSize = $size; |
| 167 | |
| 168 | return $this; |
| 169 | } |
| 170 | |
| 171 | /** |
| 172 | * Get the ruby language id. |
| 173 | */ |
| 174 | public function getLanguageId(): string |
| 175 | { |
| 176 | return $this->languageId; |
| 177 | } |
| 178 | |
| 179 | /** |
| 180 | * Set the ruby language id. |
| 181 | */ |
| 182 | public function setLanguageId(string $langId): self |
| 183 | { |
| 184 | $this->languageId = $langId; |
| 185 | |
| 186 | return $this; |
| 187 | } |
| 188 | } |