@@ -4,13 +4,13 @@ const pdfMake = require('pdfmake')
4
4
let database = null
5
5
6
6
pdfMake . fonts = {
7
- Retro : {
7
+ retro : {
8
8
bold : new URL ( 'fonts/Retro.ttf' , document . location . toString ( ) ) . toString ( )
9
9
} ,
10
- RetroCondensed : {
10
+ retrocondensed : {
11
11
bold : new URL ( 'fonts/RetroCondensed.ttf' , document . location . toString ( ) ) . toString ( )
12
12
} ,
13
- ATypewriter : {
13
+ atypewriter : {
14
14
bold : new URL ( 'fonts/ATypewriter.ttf' , document . location . toString ( ) ) . toString ( )
15
15
}
16
16
}
@@ -20,7 +20,6 @@ function shadeColor2(color, percent) {
20
20
return "#" + ( 0x1000000 + ( Math . round ( ( t - R ) * p ) + R ) * 0x10000 + ( Math . round ( ( t - G ) * p ) + G ) * 0x100 + ( Math . round ( ( t - B ) * p ) + B ) ) . toString ( 16 ) . slice ( 1 ) ;
21
21
}
22
22
23
-
24
23
let Printer = {
25
24
init : ( db ) => {
26
25
database = db
@@ -79,9 +78,11 @@ let Printer = {
79
78
dd . jsmeta . rows = 10
80
79
break
81
80
}
82
- for ( let i = 0 ; i < titles . length ; i += dd . jsmeta . columns * dd . jsmeta . rows ) {
81
+ let spliceTitles = JSON . parse ( JSON . stringify ( titles ) )
82
+ while ( spliceTitles . length > 0 ) {
83
+ const pageTitles = spliceTitles . splice ( 0 , dd . jsmeta . columns * dd . jsmeta . rows )
83
84
dd . content . push ( {
84
- jsmeta : { titles : Printer . formatTitles ( titles . slice ( i , i + dd . jsmeta . columns + dd . jsmeta . rows ) , dd . jsmeta ) }
85
+ jsmeta : { titles : Printer . formatTitles ( pageTitles , dd . jsmeta ) }
85
86
} )
86
87
}
87
88
return dd ;
@@ -367,43 +368,40 @@ let Printer = {
367
368
// if we're supposed to have two columns and there's a corresponding title to populate
368
369
const title_col2 = ( dd . jsmeta . columns == 2 && page . jsmeta . titles . length > i + dd . jsmeta . rows ) ? page . jsmeta . titles [ i + dd . jsmeta . rows ] : null
369
370
370
- let columns = [ ]
371
-
372
371
//get asides
373
- columns . push ( this . getTitleASide ( title ) )
374
- if ( title_col2 !== null ) {
375
- columns . push ( this . getTitleASide ( title_col2 ) )
376
- } else {
377
- columns . push ( { text : '' , border : [ false , false , false , false ] } )
378
- }
379
-
380
- body . push ( columns )
372
+ let row = [ this . getTitleASide ( title ) ]
381
373
382
- columns = [ ]
383
-
384
- //get artists
385
- columns . push ( this . getTitleArtist ( title ) )
386
- if ( title_col2 !== null ) {
387
- columns . push ( this . getTitleArtist ( title_col2 ) )
388
- } else {
389
- columns . push ( { text : '' , border : [ false , false , false , false ] } )
374
+ if ( dd . jsmeta . columns == 2 ) {
375
+ if ( title_col2 ) {
376
+ row . push ( this . getTitleASide ( title_col2 ) )
377
+ } else {
378
+ row . push ( { text : '' , border : [ false , false , false , false ] } )
379
+ }
390
380
}
381
+ body . push ( row )
391
382
383
+ //get artists
384
+ row = [ this . getTitleArtist ( title ) ]
392
385
393
- body . push ( columns )
394
-
395
- columns = [ ]
386
+ if ( dd . jsmeta . columns == 2 ) {
387
+ if ( title_col2 !== null ) {
388
+ row . push ( this . getTitleArtist ( title_col2 ) )
389
+ } else {
390
+ row . push ( { text : '' , border : [ false , false , false , false ] } )
391
+ }
392
+ }
393
+ body . push ( row )
396
394
397
395
//get bsides
398
- columns . push ( this . getTitleBSide ( title ) )
399
- if ( title_col2 !== null ) {
400
- columns . push ( this . getTitleBSide ( title_col2 ) )
401
- } else {
402
- columns . push ( { text : '' , border : [ false , false , false , false ] } )
396
+ row = [ this . getTitleBSide ( title ) ]
397
+ if ( dd . jsmeta . columns == 2 ) {
398
+ if ( title_col2 !== null ) {
399
+ row . push ( this . getTitleBSide ( title_col2 ) )
400
+ } else {
401
+ row . push ( { text : '' , border : [ false , false , false , false ] } )
402
+ }
403
403
}
404
-
405
-
406
- body . push ( columns )
404
+ body . push ( row )
407
405
}
408
406
409
407
const spaced = dd . jsmeta . options . spacing
@@ -429,10 +427,10 @@ let Printer = {
429
427
let str = title [ side + 'side' ]
430
428
431
429
let canvas = document . createElement ( 'canvas' )
432
- canvas . width = 225
430
+ canvas . width = "225px"
433
431
434
432
let context = canvas . getContext ( '2d' )
435
- context . font = font . titleSize + 'px ' + font . name
433
+ context . font = Math . ceil ( font . titleSize ) + 'px ' + font . font
436
434
context . textAlign = 'center'
437
435
context . textBaseline = 'middle' ;
438
436
@@ -468,7 +466,7 @@ let Printer = {
468
466
}
469
467
}
470
468
471
- _words . splice ( _splitPoint , 0 , '\n' )
469
+ _words [ _splitPoint - 1 ] = _words [ _splitPoint - 1 ] + '\n'
472
470
str = _words . join ( ' ' )
473
471
474
472
title [ side + 'wrap' ] = true
@@ -491,7 +489,7 @@ let Printer = {
491
489
bwrap : false
492
490
}
493
491
494
- let font = null
492
+ let font = StyleDefines . fonts [ jsmeta . options . font ]
495
493
let style = null
496
494
497
495
if ( jsmeta . options . allCaps ) {
@@ -510,13 +508,11 @@ let Printer = {
510
508
for ( let key of [ 'style' , 'primaryColor' , 'shadeTitle' , 'shadeArtist' ] ) {
511
509
formattedTitle [ key ] = title . styleOverride [ key ]
512
510
}
513
- font = StyleDefines . fonts [ title . styleOverride . font ]
514
511
style = StyleDefines . styles [ title . styleOverride . style ]
515
512
} else {
516
513
for ( let key of [ 'style' , 'primaryColor' , 'shadeTitle' , 'shadeArtist' ] ) {
517
514
formattedTitle [ key ] = jsmeta . options [ key ]
518
515
}
519
- font = StyleDefines . fonts [ jsmeta . options . font ]
520
516
style = StyleDefines . styles [ jsmeta . options . style ]
521
517
}
522
518
@@ -526,19 +522,19 @@ let Printer = {
526
522
formattedTitle . mergeArtist = style . mergeArtist
527
523
528
524
//add font details
529
- formattedTitle . font = font . name
525
+ formattedTitle . font = font . font
530
526
formattedTitle . titleSize = font . titleSize
531
527
formattedTitle . artistSize = font . artistSize
532
528
533
529
//provide the correct shades for fills
534
530
535
- if ( formattedTitle . shadeTitle === true ) {
531
+ if ( formattedTitle . shadeTitle === true && ( jsmeta . options . paperType === 'a4' || jsmeta . options . paperType === 'letter' ) ) {
536
532
formattedTitle . titleTint = shadeColor2 ( StyleDefines . colors [ formattedTitle . primaryColor ] . primary , 0.8 )
537
533
} else {
538
534
formattedTitle . titleTint = '#ffffff'
539
535
}
540
536
541
- if ( formattedTitle . shadeArtist === true ) {
537
+ if ( formattedTitle . shadeArtist === true && ( jsmeta . options . paperType === 'a4' || jsmeta . options . paperType === 'letter' ) ) {
542
538
formattedTitle . artistTint = shadeColor2 ( StyleDefines . colors [ formattedTitle . primaryColor ] . primary , 0.8 )
543
539
} else {
544
540
formattedTitle . artistTint = '#ffffff'
0 commit comments