forked from seisiuneer/abctools
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
7800 lines (5261 loc) · 184 KB
/
app.js
File metadata and controls
7800 lines (5261 loc) · 184 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
*
* app.js - All code for the ABC Transcription Tools
*
* Project repo at: https://github.com/seisiuneer/abctools
*
*
* MIT License
*
* Copyright (c) 2023 Michael Eskin
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
*
**/
var gShowAdvancedControls = false;
var gStripAnnotations = false;
var gStripTextAnnotations = false;
var gStripChords = false;
var STAFFSPACEMIN = 0;
var STAFFSPACEDEFAULT = 10;
var STAFFSPACEMAX = 200;
var STAFFSPACEOFFSET = 40;
var gStaffSpacing = STAFFSPACEOFFSET + STAFFSPACEDEFAULT;
var gIsIOS = false;
var gIsIPad = false;
var gIsIPhone = false;
var gIsSafari = false;
var gIsAndroid = false;
var gRenderingPDF = false;
var gTheQRCode = null;
// Maximum number of characters that can be encoded in a QR Code
var MAXQRCODEURLLENGTH = 2300;
// Maximum length of an all tune titles string before truncation
var ALLTITLESMAXLENGTH = 70;
// Font size for PDF headers and footers
var HEADERFOOTERFONTSIZE = 12.0;
// Font size for PDF QR code caption
var QRCODECAPTIONPDFFONTSIZE = 12.0;
var gShowShareControls = false;
var gAllowSave = false;
var gAllowURLSave = false;
var gAllowQRCodeSave = false
var gShowAllControls = false;
var gAllowControlToggle = false
var gAllowFilterAnnotations = false;
var gAllowFilterText = false;
var gAllowFilterChords = false;
var gCapo = 0;
var gIsMaximized = false;
var gABCFromFile = false;
var gAllowCopy = false;
var gAllowPDF = false;
var gDisplayedName = "";
var gShowTabNames = true;
var gAllowShowTabNames = false;
// Has the tin whistle font been loaded?
var gWhistleFontPrepared = false;
// Debounce time for text area change render requests
var DEBOUNCEMS = 280;
// Debounce time for tune autoscroll
var AUTOSCROLLDEBOUNCEMS = 250;
// For tune autoscroll state
var gLastAutoScrolledTune = -1;
// Top bar showing?
var gTopBarShowing = true;
// Current tune being rendered
var gCurrentTune = 0;
// Last tune count
var gTotalTunes = 0;
// Current tab display
var gCurrentTab = "noten";
// Did we just do a paste or other operation to programatically change the text area?
var gForceFullRender = false;
// Are we in single or dual column display mode?
var gIsOneColumn = true;
// For handling clicks in notation when maximized
var gGotRenderDivClick = false;
var gRenderDivClickOffset = -1;
// Global reference to the ABC editor
var gTheABC = document.getElementById("abc");
//
// Tune utility functions
//
//
// Get the text area character offset to the start of a specific tune by index
//
function findTuneOffsetByIndex(tuneIndex){
if (tuneIndex == 0){
return 0;
}
var theNotes = gTheABC.value;
// Find the tunes
var theTunes = theNotes.split(/^X:/gm);
var offset = theTunes[0].length;
for (var i = 1; i <= tuneIndex; ++i) {
offset += theTunes[i].length + 2; // For the X:
}
return offset;
}
//
// Get the tune number at a character offset into the ABC
//
function findTuneByOffset(start){
var theNotes = gTheABC.value;
// Now find all the X: items
var theTunes = theNotes.split(/^X:/gm);
var nTunes = theTunes.length;
// First chunk is whatever is before the first X:
var theOffset = 0;
theOffset = theTunes[0].length;
for (i=1;i<nTunes;++i){
// Account for the X: stripped in the length
theOffset += theTunes[i].length+2;
// Is the offset in the last chunk?
if (start < theOffset){
return i-1;
}
}
// Off the end
return nTunes-2;
}
//
// Return the tune ABC at a specific index
//
//
function getTuneByIndex(tuneNumber){
var theNotes = gTheABC.value;
// Now find all the X: items
var theTunes = theNotes.split(/^X:/gm);
return ("X:"+theTunes[tuneNumber+1]);
}
//
// Get the currently selected text in a textbox
//
function getSelectedText(id)
{
// Obtain the object reference for the <textarea>
var txtarea = document.getElementById(id);
// Obtain the index of the first selected character
var start = txtarea.selectionStart;
// Obtain the index of the last selected character
var finish = txtarea.selectionEnd;
// Obtain the selected text
var sel = txtarea.value.substring(start, finish);
return sel;
}
//
// Find the tune around the selection point
//
function findSelectedTune(){
var theNotes = gTheABC.value;
// Obtain the object reference for the <textarea>
var txtarea = gTheABC;
// Obtain the index of the first selected character
var start = txtarea.selectionStart;
if (start == 0) {
// Common case where a set was just loaded and the cursor is at the start, go find the first position after an X:
start = theNotes.indexOf("X:")+2;
}
// Odd case where there isn't an X:, just return nothing to play
if (start == 0){
return "";
}
// Now find all the X: items
var theTunes = theNotes.split(/^X:/gm);
var nTunes = theTunes.length;
// First chunk is whatever is before the first X:
var theOffset = 0;
theOffset = theTunes[0].length;
for (i=1;i<nTunes;++i){
// Account for the X: stripped in the length
theOffset += theTunes[i].length+2;
// Is the offset in the last chunk?
if (start < theOffset){
var finalTune = "X:"+theTunes[i];
// Strip any trailing whitespace
finalTune = finalTune.trimEnd();
return (finalTune);
}
}
return "";
}
//
// Get the title of the first tune
//
function GetFirstTuneTitle() {
var title = "";
var theABC = gTheABC.value;
theABC = escape(theABC);
var theLines = theABC.split("%0A");
for (i = 0; i < theLines.length; ++i) {
theLines[i] = unescape(theLines[i]);
var theChars = theLines[i].split("");
if (theChars[0] == "T" && theChars[1] == ":") {
title = theLines[i].slice(2);
title = title.trim();
// Strip out any naughty HTML tag characters
title = title.replace(/[^a-zA-Z0-9_\-. ]+/ig, '');
// Replace any spaces
title = title.replace(/\s/g, '_');
// Replace any quotes
title = title.replace(/\'/g, '_');
break;
}
}
return title;
}
//
// Count the tunes in the text area
//
function CountTunes() {
// Count the tunes in the text area
var theNotes = gTheABC.value;
var theTunes = theNotes.split(/^X:.*$/gm);
var nTunes = theTunes.length - 1;
// Save the global tune count anytime this is called
gTotalTunes = nTunes;
return nTunes;
}
//
// Get all the tune titles
//
function GetAllTuneTitles() {
var theTitles = [];
// Mit For Schleife Titel für Dateinamen extrahieren und Leerzeichen ersetzen und Apostrophe entfernen.
var verarbeiten = gTheABC.value;
var neu = escape(verarbeiten);
var Reihe = neu.split("%0D%0A");
Reihe = neu.split("%0A");
for (i = 0; i < Reihe.length; ++i) {
Reihe[i] = unescape(Reihe[i]); /* Macht die Steuerzeichen wieder weg */
var Aktuellereihe = Reihe[i].split(""); /* nochmal bei C. Walshaw crosschecken, ob alle mögl. ausser K: erfasst. */
if (Aktuellereihe[0] == "T" && Aktuellereihe[1] == ":") {
var titel = Reihe[i].slice(2);
titel = titel.trim();
theTitles.push(titel);
}
}
var nTitles = theTitles.length;
var allTitles = "";
if (nTitles > 0) {
for (i = 0; i < nTitles; ++i) {
allTitles += theTitles[i];
// Limit the length of the string to some maximum number of characters
if (allTitles.length > ALLTITLESMAXLENGTH){
var nRemaining = (nTitles-i-1);
if (nRemaining > 0){
allTitles = allTitles + " + " + nRemaining + " more";
}
return allTitles;
}
if (i != nTitles - 1) {
allTitles += " / ";
}
}
}
return allTitles;
}
//
// Tranpose the ABC up one semitone
//
//
// Find the tune range for the current select
//
function getTuneRangeForTranspose(){
var theNotes = gTheABC.value;
// Obtain the object reference for the <textarea>
var txtarea = gTheABC;
// Obtain the index of the first selected character
var theStart = txtarea.selectionStart;
if (theStart == 0) {
// Common case where a set was just loaded and the cursor is at the start, go find the first position after an X:
theStart = theNotes.indexOf("X:")+2;
}
var theEnd = txtarea.selectionEnd
if (theEnd == 0) {
// Common case where a set was just loaded and the cursor is at the start, go find the first position after an X:
theEnd = theNotes.indexOf("X:")+2;
}
var startTune = findTuneByOffset(theStart);
var endTune = findTuneByOffset(theEnd);
return {start:startTune,end:endTune};
}
//
// Support function for restoring the selection point after the transpose operation
//
function resetSelectionAfterTranspose(start,end){
// Get the first tune index
var theStartIndex = findTuneOffsetByIndex(start);
// Get the tune
var theTune = getTuneByIndex(end);
// Find the last tune in the tunes
var theEndIndex = findTuneOffsetByIndex(end)+(theTune.length-1);
// Set the select point
gTheABC.selectionStart = theStartIndex;
gTheABC.selectionEnd = theEndIndex;
// And set the focus
gTheABC.focus();
}
//
// General purpose tranposer for the currently selected tunes
//
function Transpose(transposeAmount) {
// If currently rendering PDF, exit immediately
if (gRenderingPDF) {
return;
}
var nTunes = CountTunes();
var theTuneRange = getTuneRangeForTranspose();
//console.log("getTuneRangeForTranspose start = "+theTuneRange.start+" end = "+theTuneRange.end);
document.getElementById("loading-bar-spinner").style.display = "block";
// Need a timeout to allow the spinner to show before processing the ABC,
setTimeout(function(){
var theNotes = gTheABC.value;
// Get the rendering params
var params = GetABCJSParams();
// Find the tunes
var theTunes = theNotes.split(/^X:/gm);
// Create the render div ID array
var renderDivs = [];
var id;
for (var i = 0; i < nTunes; ++i) {
id = "notation" + i;
renderDivs.push(id);
// Flash reduction
var elem = document.getElementById(id);
elem.style.opacity = 0.0;
}
var output = "";
for (var i=1;i<=nTunes;++i){
theTunes[i] = "X:"+theTunes[i];
var visualObj = null;
if (((i-1) >= theTuneRange.start) && ((i-1) <= theTuneRange.end)){
// Wrap this in a try-catch since sometimes the transposer fails catastrophically
try {
//console.log("Transposing tune "+i);
visualObj = ABCJS.renderAbc(renderDivs[i-1], theTunes[i], params);
output += ABCJS.strTranspose(theTunes[i], visualObj, transposeAmount);
}
catch (error){
alert("Unable to tranpose one or more tunes.");
output += theTunes[i];
}
}
else{
output += theTunes[i];
}
}
// Stuff in the transposed output
gTheABC.value = output;
// Reset the selection point to the current tune
resetSelectionAfterTranspose(theTuneRange.start,theTuneRange.end);
// Force a full render
RenderAsync(true, null, function(){
setTimeout(function(){
for (var i = 0; i < nTunes; ++i) {
// Flash reduction
var elem = document.getElementById(id);
elem.style.opacity = 1.0;
}
},100);
});
},100);
}
//
// Tranpose the ABC up one semitone
//
function TransposeUp() {
Transpose(1);
}
//
// Tranpose the ABC down one semitone
//
function TransposeDown() {
Transpose(-1);
}
//
// Sort the tunes in the ABC text area
//
function SortTunes(stripAn){
// Get all the tunes
var theNotes = gTheABC.value;
var theTunes = theNotes.split(/(^X:.*$)/gm);
var nTunes = (theTunes.length - 1)/2;
if (nTunes < 2){
return;
}
var thePrefixABC = theTunes[0];
//console.log("thePrefixABC: "+thePrefixABC);
// Get all the tune titles (uses first T: tag found)
// Global totalTunes needs to be set for GetTunebookIndexTitles to work
totalTunes = nTunes;
var theTitles = GetTunebookIndexTitles();
var i;
var tunesToProcess = [];
var nProcessed = 0;
var thisTitle;
for (i=0;i<nTunes;++i){
if (theTunes[(i*2)+1] != undefined){
thisTitle = theTitles[nProcessed];
if (thisTitle.indexOf("The ")==0){
thisTitle = thisTitle.substring(4,thisTitle.length)+", The";
}
if (stripAn){
if (thisTitle.indexOf("An ")==0){
thisTitle = thisTitle.substring(3,thisTitle.length)+", An";
}
if (thisTitle.indexOf("A ")==0){
thisTitle = thisTitle.substring(2,thisTitle.length)+", A";
}
}
nProcessed++;
//console.log("Tune #"+nProcessed+": "+theTunes[(i*2)+1]+theTunes[(i*2)+2]);
tunesToProcess.push({title:thisTitle,tune:theTunes[(i*2)+1]+theTunes[(i*2)+2]});
}
}
//console.log("Tunes processed: "+nProcessed);
// Sort tunes by name
tunesToProcess.sort((a, b) => {
const nameA = a.title.toUpperCase(); // ignore upper and lowercase
const nameB = b.title.toUpperCase(); // ignore upper and lowercase
if (nameA < nameB) {
return -1;
}
if (nameA > nameB) {
return 1;
}
// names must be equal
return 0;
});
theNotes = "";
theNotes += thePrefixABC;
// Aggregate the results
for (i=0;i<nProcessed;++i){
theNotes += tunesToProcess[i].tune;
}
// Put them back in the ABC area
gTheABC.value = theNotes;
// Reset the selection
gTheABC.selectionStart = 0;
gTheABC.selectionEnd = 0;
// And set the focus
gTheABC.focus();
}
//
// UI SortABC command
//
function SortABC(e) {
// If currently rendering PDF, exit immediately
if (gRenderingPDF) {
return;
}
var stripAn = false;
if (e.shiftKey){
stripAn = true;
}
// Give some feedback
document.getElementById("sortbutton").value = " Sorting ";
setTimeout(function(){
// Sort the tunes
SortTunes(stripAn);
document.getElementById("sortbutton").value = "Rendering";
// Redraw
RenderAsync(true,null,function(){
document.getElementById("sortbutton").value = " Sorted! ";
setTimeout(function(){
document.getElementById("sortbutton").value = "Sort ABC";
},1500);
});
},750);
}
//
// UI Clear command
//
function Clear() {
// If currently rendering PDF, exit immediately
if (gRenderingPDF) {
return;
}
ClearNoRender();
RenderAsync(true,null);
}
//
// Clear the ABC area, but don't re-render
//
function ClearNoRender() {
gTheABC.value = "";
// Save it for the status update display
gDisplayedName = "No ABC file selected";
gABCFromFile = false;
RestoreDefaults();
HideAllControls();
}
//
// PDF conversion shared globals
//
// Rendering offsets based on paper size
var PAGENUMBERTOP = 296;
var PAGENUMBERTOPA4 = 313;
var PAGETOPOFFSET = 32;
var PAGEBOTTOMOFFSET = 0;
var PAGELEFTOFFSET = 37;
var PAGELEFTOFFSETA4 = 29;
var PAGEHEIGHTLETTER = 792;
var PAGEHEIGHTA4 = 842;
var BETWEENTUNESPACE = 20;
// Keeps track of where we are on the page
var running_height = PAGETOPOFFSET;
// For incipits, which column
var column_number = 0;
// Page count
var theCurrentPageNumber = 1;
// True for the first page rendered
var isFirstPage = true;
// How many tunes processed so far
var tunesProcessed = 0;
// Total number of tunes being processed
var totalTunes = 0;
// Page header and footer
var thePageHeader = "";
var thePageFooter = "";
// Need to cache the time, since you don't want it to change during the render from page to page
var theRenderTime = "";
// Don't want to recalc this each time
var theHeaderFooterTuneNames = "";
// Page number vertical offset
var thePageNumberVerticalOffset = 0;
// Did they request a QR code
var QRCodeRequested = false;
// Did they request an tunebook index?
var TunebookIndexRequested = false;
var theTunebookIndexTitle = "";
// Did they request an sorted tunebook index?
var TunebookSortedIndexRequested = false;
var theTunebookSortedIndexTitle = "";
// Did they request an tunebook TOC?
var TunebookTOCRequested = false;
var theTunebookTOCTitle = "";
// Did they request a sorted tunebook TOC?
var TunebookSortedTOCRequested = false;
var theTunebookSortedTOCTitle = "";
// Did they request an tunebook title page?
var TunebookTPRequested = false;
var theTunebookTP = "";
// Did they request an tunebook title page subtitle?
var TunebookTPSTRequested = false;
var theTunebookTPST = "";
// Tune page map
var theTunePageMap = [];
// PDF JPG quality (range is 0 to 1)
var PDFJPGQUALITY = 0.8;
// Internal PDF scale factor
var PDFSCALEFACTOR = 1.55;
// The offscreen render div
var theOffscreen = null;
// PDF generation cancel requested
var gPDFCancelRequested = false;
// Which instrument
var gPDFTabselected = "noten";
// PDF object to render to
var pdf;
//
// Get the tune index titles
//
function GetTunebookIndexTitles(){
var i;
var theTitles = [];
for (i=0;i<totalTunes;++i){
var thisTune = getTuneByIndex(i);
var neu = escape(thisTune);
var Reihe = neu.split("%0D%0A");
Reihe = neu.split("%0A");
for (j = 0; j < Reihe.length; ++j) {
Reihe[j] = unescape(Reihe[j]); /* Macht die Steuerzeichen wieder weg */
var Aktuellereihe = Reihe[j].split(""); /* nochmal bei C. Walshaw crosschecken, ob alle mögl. ausser K: erfasst. */
if (Aktuellereihe[0] == "T" && Aktuellereihe[1] == ":") {
titel = Reihe[j].slice(2);
titel = titel.trim();
// Just grab the first title foiund
theTitles.push(titel);
break
}
}
}
return theTitles;
}
//
// Tune title page font sizes
//
var TPTITLESIZE = 24;
var TPSTTITLESIZE = 16;
var TPTOPOFFSET = 435;
var TPSTOFFSET = 24;
//
// Generate and append a tune index to the current PDF
//
function AppendTuneTitlePage(thePDF,paperStyle,theTitle,theSubtitle){
var a4offset = 0
if (paperStyle == "a4"){
a4offset = 20;
}
// Add a new page
thePDF.addPage(paperStyle);
if (theTitle != ""){
// Set the font size
thePDF.setFont("Times","","normal");
thePDF.setFontSize(TPTITLESIZE);
// Add the title
thePDF.text(theTitle, thePDF.internal.pageSize.getWidth()/3.10, TPTOPOFFSET+a4offset, {align:"center"});
}
if (theSubtitle != ""){
// Set the font size
thePDF.setFont("Times","","normal");
thePDF.setFontSize(TPSTTITLESIZE);
// Add the subtitle
thePDF.text(theSubtitle, thePDF.internal.pageSize.getWidth()/3.10, TPTOPOFFSET+TPSTOFFSET+a4offset, {align:"center"});
}
// We're on a new page
theCurrentPageNumber++;
// Move the page to the top
thePDF.movePage(theCurrentPageNumber,1);
}
//
// Text incipits page layout constants
//
var TEXTINCIPITTOPOFFSET = 330;
var TEXTINCIPITBOTTOMOFFSET = 12;