@@ -206,8 +206,8 @@ class PageView {
206
206
this . rootNode . appendChild ( this . canvasNode )
207
207
208
208
this . textData = null
209
- this . textNode = document . createElement ( "div ")
210
- this . textNode . className = "text"
209
+ this . textNode = document . createElementNS ( "http://www.w3.org/2000/svg" , "svg ")
210
+ this . textNode . classList . add ( "text" )
211
211
this . rootNode . appendChild ( this . textNode )
212
212
213
213
this . linkData = null
@@ -341,44 +341,29 @@ class PageView {
341
341
}
342
342
343
343
_showText ( ) {
344
- this . textNode . zoom = this . zoom
345
- this . textNode . replaceChildren ( )
346
-
347
- let nodes = [ ]
348
- let pdf_w = [ ]
349
- let html_w = [ ]
350
- let text_len = [ ]
344
+ let frag = document . createDocumentFragment ( )
351
345
let scale = this . zoom / 72
352
346
353
347
for ( let block of this . textData . blocks ) {
354
348
if ( block . type === "text" ) {
355
349
for ( let line of block . lines ) {
356
- let text = document . createElement ( "span" )
357
- text . style . left = line . bbox . x * scale + "px"
358
- text . style . top = ( line . y - line . font . size * 0.8 ) * scale + "px"
359
- text . style . height = line . bbox . h * scale + "px"
350
+ let text = document . createElementNS ( "http://www.w3.org/2000/svg" , "text" )
351
+ text . setAttribute ( "x" , line . bbox . x * scale + "px" )
352
+ text . setAttribute ( "y" , line . y * scale + "px" )
360
353
text . style . fontSize = line . font . size * scale + "px"
361
354
text . style . fontFamily = line . font . family
362
355
text . style . fontWeight = line . font . weight
363
356
text . style . fontStyle = line . font . style
357
+ text . setAttribute ( "textLength" , line . bbox . w * scale + "px" )
358
+ text . setAttribute ( "lengthAdjust" , "spacingAndGlyphs" )
364
359
text . textContent = line . text
365
- this . textNode . appendChild ( text )
366
- nodes . push ( text )
367
- pdf_w . push ( line . bbox . w * scale )
368
- text_len . push ( line . text . length - 1 )
360
+ frag . appendChild ( text )
369
361
}
370
362
}
371
363
}
372
364
373
- for ( let i = 0 ; i < nodes . length ; ++ i ) {
374
- if ( text_len [ i ] > 0 )
375
- html_w [ i ] = nodes [ i ] . clientWidth
376
- }
377
-
378
- for ( let i = 0 ; i < nodes . length ; ++ i ) {
379
- if ( text_len [ i ] > 0 )
380
- nodes [ i ] . style . letterSpacing = ( pdf_w [ i ] - html_w [ i ] ) / text_len [ i ] + "px"
381
- }
365
+ this . textNode . zoom = this . zoom
366
+ this . textNode . replaceChildren ( frag )
382
367
}
383
368
384
369
_showLinks ( ) {
@@ -543,7 +528,12 @@ window.addEventListener("keydown", function (event) {
543
528
case 96 :
544
529
zoom_to ( 100 )
545
530
break
546
-
531
+ // 'A'
532
+ case 65 :
533
+ // Ctrl-A full selection
534
+ document . getSelection ( ) . selectAllChildren ( document . getElementById ( "pages" ) )
535
+ event . preventDefault ( )
536
+ break
547
537
// 'F'
548
538
case 70 :
549
539
show_search_panel ( )
@@ -574,6 +564,17 @@ function toggle_fullscreen() {
574
564
document . documentElement . requestFullscreen ( )
575
565
}
576
566
567
+ // Mark TEXT-SELECTION State
568
+ function remove_selection_state ( e ) {
569
+ document . getElementById ( "pages" ) . classList . remove ( "do-content-select" )
570
+ document . removeEventListener ( "mouseup" , remove_selection_state )
571
+ }
572
+
573
+ document . addEventListener ( "selectstart" , function ( event ) {
574
+ document . getElementById ( "pages" ) . classList . add ( "do-content-select" )
575
+ document . addEventListener ( "mouseup" , remove_selection_state )
576
+ } )
577
+
577
578
// SEARCH
578
579
579
580
let search_panel = document . getElementById ( "search-panel" )
0 commit comments