* Check if font can encode the given text. * * CID fonts with Identity-H/V encoding can encode any BMP character. * Simple fonts are limited to their encoding (typically Latin-1).
(text: string)
| 126 | * Simple fonts are limited to their encoding (typically Latin-1). |
| 127 | */ |
| 128 | canEncode(text: string): boolean { |
| 129 | if (this.isCIDFont) { |
| 130 | if (!this.cidFont) { |
| 131 | return false; |
| 132 | } |
| 133 | |
| 134 | if (!this.cidFont.getEmbeddedProgram()) { |
| 135 | return false; |
| 136 | } |
| 137 | |
| 138 | for (const char of text) { |
| 139 | const codePoint = char.codePointAt(0)!; |
| 140 | |
| 141 | if (codePoint > 0xffff) { |
| 142 | return false; |
| 143 | } |
| 144 | |
| 145 | if (this.cidFont.tryGetCharCodeForUnicode(codePoint) === null) { |
| 146 | return false; |
| 147 | } |
| 148 | } |
| 149 | |
| 150 | return true; |
| 151 | } |
| 152 | |
| 153 | if (this.simpleFont) { |
| 154 | return this.simpleFont.canEncode(text); |
| 155 | } |
| 156 | |
| 157 | // Standard 14 fallback: only Latin-1 |
| 158 | for (const char of text) { |
| 159 | if (char.charCodeAt(0) > 255) { |
| 160 | return false; |
| 161 | } |
| 162 | } |
| 163 | |
| 164 | return true; |
| 165 | } |
| 166 | |
| 167 | /** |
| 168 | * Encode text to character codes for this font. |
no test coverage detected