* Show a string and extract characters.
(bytes: Uint8Array)
| 238 | * Show a string and extract characters. |
| 239 | */ |
| 240 | private showString(bytes: Uint8Array): void { |
| 241 | const font = this.state.font; |
| 242 | |
| 243 | if (!font) { |
| 244 | // No font set - can't decode text |
| 245 | return; |
| 246 | } |
| 247 | |
| 248 | // Decode bytes to character codes based on font type |
| 249 | const codes = this.decodeStringToCodes(bytes, font); |
| 250 | |
| 251 | for (const code of codes) { |
| 252 | // Get Unicode character from font |
| 253 | const char = font.toUnicode(code); |
| 254 | |
| 255 | // Skip if we can't decode to Unicode |
| 256 | if (!char) { |
| 257 | // Still advance position even if we can't decode |
| 258 | const width = font.getWidth(code); |
| 259 | this.state.advanceChar(width, false); |
| 260 | continue; |
| 261 | } |
| 262 | |
| 263 | // Get glyph width |
| 264 | const width = font.getWidth(code); |
| 265 | |
| 266 | // Calculate bounding box |
| 267 | const bbox = this.state.getCharBbox(width); |
| 268 | |
| 269 | // Create extracted character |
| 270 | this.chars.push({ |
| 271 | char, |
| 272 | bbox: { |
| 273 | x: bbox.x, |
| 274 | y: bbox.y, |
| 275 | width: bbox.width, |
| 276 | height: bbox.height, |
| 277 | }, |
| 278 | fontSize: this.state.effectiveFontSize, |
| 279 | fontName: font.baseFontName, |
| 280 | baseline: bbox.baseline, |
| 281 | sequenceIndex: this.chars.length, |
| 282 | }); |
| 283 | |
| 284 | // Advance text position |
| 285 | const isSpace = char === " " || char === "\u00A0"; // Space or non-breaking space |
| 286 | this.state.advanceChar(width, isSpace); |
| 287 | } |
| 288 | } |
| 289 | |
| 290 | /** |
| 291 | * Decode string bytes to character codes. |
no test coverage detected