@@ -26,6 +26,7 @@ This file is part of the iText (R) project.
26
26
import com .itextpdf .kernel .pdf .PdfName ;
27
27
import com .itextpdf .kernel .pdf .PdfUAConformance ;
28
28
import com .itextpdf .kernel .pdf .tagging .IStructureNode ;
29
+ import com .itextpdf .kernel .pdf .tagging .PdfNamespace ;
29
30
import com .itextpdf .kernel .pdf .tagging .PdfStructElem ;
30
31
import com .itextpdf .kernel .pdf .tagutils .IRoleMappingResolver ;
31
32
@@ -61,23 +62,36 @@ public String resolveToStandardRole(IStructureNode node) {
61
62
if (originalRole == null ) {
62
63
return null ;
63
64
}
65
+ PdfNamespace namespace = node instanceof PdfStructElem ? ((PdfStructElem ) node ).getNamespace () : null ;
64
66
65
- return resolveToStandardRole (originalRole .getValue ());
67
+ return resolveToStandardRole (originalRole .getValue (), namespace );
66
68
}
67
69
68
70
/**
69
- * Resolves the role to a standard role
71
+ * Resolves the role to a standard role.
70
72
*
71
- * @param role The role you want to resolve the standard role for.
73
+ * @param role the role you want to resolve the standard role for
72
74
*
73
- * @return The role.
75
+ * @return resolved role
74
76
*/
75
77
public String resolveToStandardRole (String role ) {
78
+ return resolveToStandardRole (role , null );
79
+ }
80
+
81
+ /**
82
+ * Resolves the role to a standard role.
83
+ *
84
+ * @param role the role you want to resolve the standard role for
85
+ * @param namespace namespace where role is defined
86
+ *
87
+ * @return resolved role
88
+ */
89
+ public String resolveToStandardRole (String role , PdfNamespace namespace ) {
76
90
if (role == null ) {
77
91
return null ;
78
92
}
79
93
IRoleMappingResolver resolver = pdfDocument .getTagStructureContext ()
80
- .resolveMappingToStandardOrDomainSpecificRole (role , null );
94
+ .resolveMappingToStandardOrDomainSpecificRole (role , namespace );
81
95
if (resolver == null ) {
82
96
return role ;
83
97
}
@@ -102,8 +116,8 @@ public PdfStructElem getElementIfRoleMatches(PdfName role, IStructureNode struct
102
116
if (!(structureNode instanceof PdfStructElem )) {
103
117
return null ;
104
118
}
105
- //We can get away with the short code without resolving it. Because we have checks in place
106
- //that would catch remapped standard roles and cyclic roles.
119
+ // We can get away with the short code without resolving it. Because we have checks in place
120
+ // that would catch remapped standard roles and cyclic roles.
107
121
if (role .equals (structureNode .getRole ()) || role .getValue ().equals (resolveToStandardRole (structureNode ))) {
108
122
return (PdfStructElem ) structureNode ;
109
123
}
0 commit comments