1313 * limitations under the License.
1414 */
1515
16+ import { warn } from "../shared/util.js" ;
1617import { XfaText } from "./xfa_text.js" ;
1718
1819class XfaLayer {
@@ -84,8 +85,10 @@ class XfaLayer {
8485 }
8586 }
8687
87- static setAttributes ( html , element , storage , intent ) {
88+ static setAttributes ( { html, element, storage = null , intent, linkService } ) {
8889 const { attributes } = element ;
90+ const isHTMLAnchorElement = html instanceof HTMLAnchorElement ;
91+
8992 if ( attributes . type === "radio" ) {
9093 // Avoid to have a radio group when printing with the same as one
9194 // already displayed.
@@ -105,13 +108,32 @@ class XfaLayer {
105108 } else if ( key === "class" ) {
106109 html . setAttribute ( key , value . join ( " " ) ) ;
107110 } else {
111+ if ( isHTMLAnchorElement && ( key === "href" || key === "newWindow" ) ) {
112+ continue ; // Handled below.
113+ }
108114 html . setAttribute ( key , value ) ;
109115 }
110116 } else {
111117 Object . assign ( html . style , value ) ;
112118 }
113119 }
114120
121+ if ( isHTMLAnchorElement ) {
122+ if (
123+ ( typeof PDFJSDev === "undefined" || PDFJSDev . test ( "GENERIC" ) ) &&
124+ ! linkService . addLinkAttributes
125+ ) {
126+ warn (
127+ "XfaLayer.setAttribute - missing `addLinkAttributes`-method on the `linkService`-instance."
128+ ) ;
129+ }
130+ linkService . addLinkAttributes ?. (
131+ html ,
132+ attributes . href ,
133+ attributes . newWindow
134+ ) ;
135+ }
136+
115137 // Set the value after the others to be sure overwrite
116138 // any other values.
117139 if ( storage && attributes . dataId ) {
@@ -121,11 +143,17 @@ class XfaLayer {
121143
122144 static render ( parameters ) {
123145 const storage = parameters . annotationStorage ;
146+ const linkService = parameters . linkService ;
124147 const root = parameters . xfa ;
125148 const intent = parameters . intent || "display" ;
126149 const rootHtml = document . createElement ( root . name ) ;
127150 if ( root . attributes ) {
128- this . setAttributes ( rootHtml , root ) ;
151+ this . setAttributes ( {
152+ html : rootHtml ,
153+ element : root ,
154+ intent,
155+ linkService,
156+ } ) ;
129157 }
130158 const stack = [ [ root , - 1 , rootHtml ] ] ;
131159
@@ -169,7 +197,13 @@ class XfaLayer {
169197
170198 html . appendChild ( childHtml ) ;
171199 if ( child . attributes ) {
172- this . setAttributes ( childHtml , child , storage , intent ) ;
200+ this . setAttributes ( {
201+ html : childHtml ,
202+ element : child ,
203+ storage,
204+ intent,
205+ linkService,
206+ } ) ;
173207 }
174208
175209 if ( child . children && child . children . length > 0 ) {
0 commit comments