@@ -88,67 +88,6 @@ export default function AnnotationLayer({
88
88
}
89
89
}
90
90
91
- function render_annotations ( ) {
92
- if ( annotations == null ) return < div /> ;
93
- const v : JSX . Element [ ] = [ ] ;
94
- for ( const annotation0 of annotations ) {
95
- // NOTE: We have to do this ugly cast to any because the @types for pdfjs are
96
- // incomplete/wrong for annotations.
97
- const annotation : any = annotation0 as any ;
98
- if ( annotation . subtype != "Link" ) {
99
- // We only care about link annotations *right now*, for the purposes of the latex editor.
100
- console . log ( "Annotation not implemented" , annotation ) ;
101
- continue ;
102
- }
103
- const [ x1 , y1 , x2 , y2 ] = Util . normalizeRect ( annotation . rect ) ;
104
- const page_height = page . view [ 3 ] ;
105
- const left = x1 - 1 ,
106
- top = page_height - y2 - 1 ,
107
- width = x2 - x1 + 2 ,
108
- height = y2 - y1 + 1 ;
109
-
110
- let border = "" ;
111
- if ( annotation . borderStyle . width ) {
112
- border = `0.5px solid rgb(${ annotation . color [ 0 ] } , ${ annotation . color [ 1 ] } , ${ annotation . color [ 2 ] } )` ;
113
- }
114
-
115
- // Note: this "annotation" in the onClick below is the right one because we use "let"
116
- // *inside* the for loop above -- I'm not making the typical closure/scopying mistake.
117
- const elt = (
118
- < div
119
- onClick = { ( ) => clickAnnotation ( annotation ) }
120
- key = { annotation . id }
121
- style = { {
122
- position : "absolute" ,
123
- left : left * scale ,
124
- top : top * scale ,
125
- width : width * scale ,
126
- height : height * scale ,
127
- border : border ,
128
- cursor : "pointer" ,
129
- zIndex : 1 , // otherwise, the yellow sync highlight is above url links
130
- } }
131
- />
132
- ) ;
133
- v . push ( elt ) ;
134
- }
135
-
136
- // handle highlight which is used for synctex.
137
- if ( sync_highlight !== undefined ) {
138
- v . push ( render_sync_highlight ( scale , page . view [ 2 ] , sync_highlight . y ) ) ;
139
- }
140
-
141
- return (
142
- < div
143
- style = { {
144
- position : "absolute" ,
145
- } }
146
- >
147
- { v }
148
- </ div >
149
- ) ;
150
- }
151
-
152
91
function render_sync_highlight (
153
92
scale : number ,
154
93
width : number ,
@@ -172,5 +111,56 @@ export default function AnnotationLayer({
172
111
) ;
173
112
}
174
113
175
- return render_annotations ( ) ;
114
+ if ( annotations == null ) {
115
+ return < div /> ;
116
+ }
117
+ const v : JSX . Element [ ] = [ ] ;
118
+ for ( const annotation0 of annotations ) {
119
+ // NOTE: We have to do this ugly cast to any because the @types for pdfjs are
120
+ // incomplete/wrong for annotations.
121
+ const annotation : any = annotation0 as any ;
122
+ if ( annotation . subtype != "Link" ) {
123
+ // We only care about link annotations *right now*, for the purposes of the latex editor.
124
+ console . log ( "Annotation not implemented" , annotation ) ;
125
+ continue ;
126
+ }
127
+ const [ x1 , y1 , x2 , y2 ] = Util . normalizeRect ( annotation . rect ) ;
128
+ const page_height = page . view [ 3 ] ;
129
+ const left = x1 - 1 ,
130
+ top = page_height - y2 - 1 ,
131
+ width = x2 - x1 + 2 ,
132
+ height = y2 - y1 + 1 ;
133
+
134
+ let border = "" ;
135
+ if ( annotation . borderStyle . width ) {
136
+ border = `0.5px solid rgb(${ annotation . color [ 0 ] } , ${ annotation . color [ 1 ] } , ${ annotation . color [ 2 ] } )` ;
137
+ }
138
+
139
+ // Note: this "annotation" in the onClick below is the right one because we use "let"
140
+ // *inside* the for loop above -- I'm not making the typical closure/scopying mistake.
141
+ const elt = (
142
+ < div
143
+ onClick = { ( ) => clickAnnotation ( annotation ) }
144
+ key = { annotation . id }
145
+ style = { {
146
+ position : "absolute" ,
147
+ left : left * scale ,
148
+ top : top * scale ,
149
+ width : width * scale ,
150
+ height : height * scale ,
151
+ border : border ,
152
+ cursor : "pointer" ,
153
+ zIndex : 1 , // otherwise, the yellow sync highlight is above url links
154
+ } }
155
+ />
156
+ ) ;
157
+ v . push ( elt ) ;
158
+ }
159
+
160
+ // handle highlight which is used for synctex.
161
+ if ( sync_highlight !== undefined ) {
162
+ v . push ( render_sync_highlight ( scale , page . view [ 2 ] , sync_highlight . y ) ) ;
163
+ }
164
+
165
+ return < div style = { { position : "absolute" } } > { v } </ div > ;
176
166
}
0 commit comments