|
15 | 15 |
|
16 | 16 | import { AnnotationPrefix, stringToPDFString, warn } from "../shared/util.js";
|
17 | 17 | import { Dict, isName, Name, Ref, RefSetCache } from "./primitives.js";
|
| 18 | +import { lookupNormalRect, stringToAsciiOrUTF16BE } from "./core_utils.js"; |
18 | 19 | import { NumberTree } from "./name_number_tree.js";
|
19 |
| -import { stringToAsciiOrUTF16BE } from "./core_utils.js"; |
20 | 20 | import { writeObject } from "./writer.js";
|
21 | 21 |
|
22 | 22 | const MAX_DEPTH = 40;
|
@@ -751,10 +751,38 @@ class StructTreePage {
|
751 | 751 | obj.role = node.role;
|
752 | 752 | obj.children = [];
|
753 | 753 | parent.children.push(obj);
|
754 |
| - const alt = node.dict.get("Alt"); |
| 754 | + let alt = node.dict.get("Alt"); |
| 755 | + if (typeof alt !== "string") { |
| 756 | + alt = node.dict.get("ActualText"); |
| 757 | + } |
755 | 758 | if (typeof alt === "string") {
|
756 | 759 | obj.alt = stringToPDFString(alt);
|
757 | 760 | }
|
| 761 | + |
| 762 | + const a = node.dict.get("A"); |
| 763 | + if (a instanceof Dict) { |
| 764 | + const bbox = lookupNormalRect(a.getArray("BBox"), null); |
| 765 | + if (bbox) { |
| 766 | + obj.bbox = bbox; |
| 767 | + } else { |
| 768 | + const width = a.get("Width"); |
| 769 | + const height = a.get("Height"); |
| 770 | + if ( |
| 771 | + typeof width === "number" && |
| 772 | + width > 0 && |
| 773 | + typeof height === "number" && |
| 774 | + height > 0 |
| 775 | + ) { |
| 776 | + obj.bbox = [0, 0, width, height]; |
| 777 | + } |
| 778 | + } |
| 779 | + // TODO: If the bbox is not available, we should try to get it from |
| 780 | + // the content stream. |
| 781 | + // For example when rendering on the canvas the commands between the |
| 782 | + // beginning and the end of the marked-content sequence, we can |
| 783 | + // compute the overall bbox. |
| 784 | + } |
| 785 | + |
758 | 786 | const lang = node.dict.get("Lang");
|
759 | 787 | if (typeof lang === "string") {
|
760 | 788 | obj.lang = stringToPDFString(lang);
|
|
0 commit comments