-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathexdesign.satyh
1733 lines (1577 loc) · 74.5 KB
/
exdesign.satyh
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
%UTF-8
%(c) Naoki Kaneko and T. Suwa 2018-2021
%https://github.com/puripuri2100/exdesign
%0.3.1
@require: math
@require: list
@require: gr
@require: color
@require: footnote-scheme
@require: annot
module ExDesign : sig
val document : 'a -> block-text -> document
constraint 'a :: (|
title : inline-text;
author : inline-text;
date : inline-text;
show-title : bool;
show-toc : bool;
style : (|
page-width : length;
page-height : length;
top-space : length;
bottom-space : length;
left-space : length;
right-space : length;
header-left-space : length;
header-right-space : length;
header-height : length;
footer-left-space : length;
footer-right-space : length;
footer-height : length;
titlepage-top-space : length;
titlepage-bottom-space : length;
titlepage-left-space : length;
titlepage-right-space : length;
tocpage-top-space : length;
tocpage-bottom-space : length;
tocpage-left-space : length;
tocpage-right-space : length;
normal-fontsize : length;
language-japanese : bool;
|);
design : (|
oneside : bool;
titlepage : bool;
title-fontsize : length;
author-fontsize : length;
date-fontsize : length;
tocpage : bool;
toc-fontsize : length;
toc-line-text-part : inline-text;
toc-line-text-chapter : inline-text;
toc-line-text-section : inline-text;
toc-line-text-subsection : inline-text;
toc-line-text-subsubsection : inline-text;
toc-line-space-part : length;
toc-line-space-chapter : length;
toc-line-space-section : length;
toc-line-space-subsection : length;
toc-line-space-subsubsection : length;
toc-name-fontsize-part : length;
toc-name-fontsize-chapter : length;
toc-name-fontsize-section : length;
toc-name-fontsize-subsection : length;
toc-name-fontsize-subsubsection : length;
toc-depth : int;
part-fontsize : length;
part-page-break-1 : bool;
part-num-function: (int -> string);
part-top-space : length;
part-bottom-space : length;
part-left-space : length;
part-line-break : bool;
part-right-space : length;
part-page-break-2 : bool;
chapter-fontsize : length;
chapter-page-break-1 : bool;
chapter-num-function: (int -> string);
chapter-top-space : length;
chapter-bottom-space : length;
chapter-left-space : length;
chapter-line-break : bool;
chapter-right-space : length;
chapter-page-break-2 : bool;
section-fontsize : length;
section-num-function: (int -> int -> string);
section-top-space : length;
section-bottom-space : length;
section-left-space : length;
section-line-break : bool;
section-right-space : length;
subsection-fontsize : length;
subsection-num-function: (int -> int -> int -> string);
subsection-top-space : length;
subsection-bottom-space : length;
subsection-left-space : length;
subsection-line-break : bool;
subsection-right-space : length;
subsubsection-fontsize : length;
subsubsection-num-function: (int -> int -> int -> int -> string);
subsubsection-top-space : length;
subsubsection-bottom-space : length;
subsubsection-left-space : length;
subsubsection-line-break : bool;
subsubsection-right-space : length;
figure-caption-fontsize : length;
figure-caption-right-title : inline-text;
figure-caption-left-title : inline-text;
show-figure-caption-num : bool;
table-caption-fontsize : length;
table-caption-right-title : inline-text;
table-caption-left-title : inline-text;
show-table-caption-num : bool;
|);
header-footer : (|
lhead : inline-text;
chead : inline-text;
rhead : inline-text;
header-line : length;
lfoot : inline-text;
cfoot : inline-text;
rfoot : inline-text;
footer-line : length;
tocpage-lhead : inline-text;
tocpage-chead : inline-text;
tocpage-rhead : inline-text;
tocpage-header-line : length;
tocpage-lfoot : inline-text;
tocpage-cfoot : inline-text;
tocpage-rfoot : inline-text;
tocpage-footer-line : length;
|);
fonts : (|
latin-roman : string;
latin-bold : string;
latin-italic : string;
latin-sans : string;
latin-mono : string;
cjk-mincho-l : string;
cjk-mincho-m : string;
cjk-mincho-bx : string;
cjk-gothic-m : string;
cjk-gothic-bx : string;
cjk-gothic-eb : string;
math-font : string;
ratio-latin : float;
ratio-cjk : float;
correction-latin : float;
correction-cjk : float;
|)
|)
% 提供コマンド
direct +part : [string?; string?; inline-text; block-text] block-cmd
direct +chapter : [string?; string?; inline-text; block-text] block-cmd
direct +section : [string?; string?; inline-text; block-text] block-cmd
direct +subsection : [string?; string?; inline-text; block-text] block-cmd
direct +subsubsection : [string?; string?; inline-text; block-text] block-cmd
direct +p-ja : [inline-text] block-cmd
direct +p-en : [inline-text] block-cmd
direct +p : [inline-text] block-cmd
direct +pn : [inline-text] block-cmd
direct \textrm : [inline-text] inline-cmd
direct \textbf : [inline-text] inline-cmd
direct \textit : [inline-text] inline-cmd
direct \textsf : [inline-text] inline-cmd
direct \textmc : [inline-text] inline-cmd
direct \textgt : [inline-text] inline-cmd
direct \footnote : [inline-text] inline-cmd
direct \ref : [string] inline-cmd
direct \ref-page : [string] inline-cmd
direct \figure : [string?; inline-text; block-text] inline-cmd
direct +figure : [string?; inline-text; block-text] block-cmd
direct \table : [string?; inline-text; block-text] inline-cmd
direct +table : [string?; inline-text; block-text] block-cmd
val title-ref : inline-text ref
val author-ref : inline-text ref
val date-ref : inline-text ref
val show-title-ref : bool ref
val show-toc-ref : bool ref
val page-width-ref : length ref
val page-height-ref : length ref
val top-space-ref : length ref
val bottom-space-ref : length ref
val left-space-ref : length ref
val right-space-ref : length ref
val header-left-space-ref : length ref
val header-right-space-ref : length ref
val header-height-ref : length ref
val footer-left-space-ref : length ref
val footer-right-space-ref : length ref
val footer-height-ref : length ref
val titlepage-top-space-ref : length ref
val titlepage-bottom-space-ref : length ref
val titlepage-left-space-ref : length ref
val titlepage-right-space-ref : length ref
val tocpage-top-space-ref : length ref
val tocpage-bottom-space-ref : length ref
val tocpage-left-space-ref : length ref
val tocpage-right-space-ref : length ref
val normal-fontsize-ref : length ref
val language-japanese-ref : bool ref
%% design
val titlepage-ref : bool ref
val title-fontsize-ref : length ref
val author-fontsize-ref : length ref
val date-fontsize-ref : length ref
val tocpage-ref : bool ref
val toc-fontsize-ref : length ref
val part-fontsize-ref : length ref
val part-num-function-ref : (int -> string) ref
val part-top-space-ref : length ref
val part-bottom-space-ref : length ref
val part-left-space-ref : length ref
val part-right-space-ref : length ref
val chapter-fontsize-ref : length ref
val chapter-num-function-ref : (int -> string) ref
val chapter-top-space-ref : length ref
val chapter-bottom-space-ref : length ref
val chapter-left-space-ref : length ref
val chapter-right-space-ref : length ref
val section-fontsize-ref : length ref
val section-num-function-ref : (int -> int -> string) ref
val section-top-space-ref : length ref
val section-bottom-space-ref : length ref
val section-left-space-ref : length ref
val section-right-space-ref : length ref
val subsection-fontsize-ref : length ref
val subsection-num-function-ref : (int -> int -> int -> string) ref
val subsection-top-space-ref : length ref
val subsection-bottom-space-ref : length ref
val subsection-left-space-ref : length ref
val subsection-right-space-ref : length ref
val subsubsection-fontsize-ref : length ref
val subsubsection-num-function-ref : (int -> int -> int -> int -> string) ref
val subsubsection-top-space-ref : length ref
val subsubsection-bottom-space-ref : length ref
val subsubsection-left-space-ref : length ref
val subsubsection-right-space-ref : length ref
%% header-footer
val lhead-ref : inline-text ref
val chead-ref : inline-text ref
val rhead-ref : inline-text ref
val header-line-ref : length ref
val lfoot-ref : inline-text ref
val cfoot-ref : inline-text ref
val rfoot-ref : inline-text ref
val footer-line-ref : length ref
val tocpage-lhead-ref : inline-text ref
val tocpage-chead-ref : inline-text ref
val tocpage-rhead-ref : inline-text ref
val tocpage-header-line-ref : length ref
val tocpage-lfoot-ref : inline-text ref
val tocpage-cfoot-ref : inline-text ref
val tocpage-rfoot-ref : inline-text ref
val tocpage-footer-line-ref : length ref
%% その他
val text-org-ref : (length * length) ref
val text-width-ref : length ref
val text-height-ref : length ref
val hdrorg-ref : (length * length) ref
val ftrorg-ref : (length * length) ref
val hdrwid-ref : length ref
val ftrwid-ref : length ref
val header-thickness-ref : length ref
val footer-thickness-ref : length ref
%%% titlepage用
val titlepage-text-org-ref : (length * length) ref
val titlepage-text-width-ref : length ref
val titlepage-text-height-ref : length ref
val titlepage-hdrorg-ref : (length * length) ref
val titlepage-ftrorg-ref : (length * length) ref
val titlepage-hdrwid-ref : length ref
val titlepage-ftrwid-ref : length ref
%%% tocpage用
val tocpage-text-org-ref : (length * length) ref
val tocpage-text-width-ref : length ref
val tocpage-text-height-ref : length ref
val tocpage-titlepage-hdrorg-ref : (length * length) ref
val tocpage-hdrorg-ref : (length * length) ref
val tocpage-ftrorg-ref : (length * length) ref
val tocpage-hdrwid-ref : length ref
val tocpage-ftrwid-ref : length ref
val tocpage-header-thickness-ref : length ref
val tocpage-footer-thickness-ref : length ref
val page-number : int ref
end = struct
% フォント設定
%% フォント用の可変参照
let-mutable font-latin-roman-ref <- (` ` , 0. , 0.)
let-mutable font-latin-bold-ref <- (` ` , 0. , 0.)
let-mutable font-latin-italic-ref <- (` ` , 0. , 0.)
let-mutable font-latin-sans-ref <- (` ` , 0. , 0.)
let-mutable font-latin-mono-ref <- (` ` , 0. , 0.)
let-mutable font-cjk-mincho-l-ref <- (` ` , 0. , 0.)
let-mutable font-cjk-mincho-m-ref <- (` ` , 0. , 0.)
let-mutable font-cjk-mincho-bx-ref <- (` ` , 0. , 0.)
let-mutable font-cjk-gothic-m-ref <- (` ` , 0. , 0.)
let-mutable font-cjk-gothic-bx-ref <- (` ` , 0. , 0.)
let-mutable font-cjk-gothic-eb-ref <- (` ` , 0. , 0.)
%% フォント設定用の関数
let set-latin-font font ctx =
ctx |> set-font Latin font
let set-cjk-font font ctx =
ctx |> set-font Kana font
|> set-font HanIdeographic font
% 色々な準備
%% 目次の準備
let-mutable toc-acc-ref <- []
type toc-type =
| TocPart of string * inline-text
| TocChapter of string * inline-text
| TocSection of string * inline-text
| TocSubSection of string * inline-text
| TocSubSubSection of string * inline-text
let get-cross-reference-number label =
match get-cross-reference (label ^ `:num`) with
| None -> `?`
| Some(s) -> s
let get-cross-reference-page label =
match get-cross-reference (label ^ `:page`) with
| None -> `?`
| Some(s) -> s
let generate-fresh-label =
let-mutable count <- 0 in
(fun () -> (
let () = count <- !count + 1 in
`generated:` ^ (arabic (!count))
))
let-rec repeat-inline n ib =
if n <= 0 then inline-nil else
ib ++ (repeat-inline (n - 1) ib)
let make-toc-line ctx width s =
let ib = read-inline ctx {#s;} ++ inline-skip 1.5pt in
let wid-text = get-natural-width ib in
let n = round (width /' wid-text) in
inline-fil ++ (repeat-inline n ib) ++ inline-fil
%% PDF outline
let-mutable outline-ref <- []
%% 浮動環境
let-mutable ref-float-boxes <- []
let height-of-float-boxes pageno =
(!ref-float-boxes) |> List.fold-left (fun h (pn, bb) -> (
if pn < pageno then h +' (get-natural-length bb) else h
)) 0pt
let no-pads = (0pt, 0pt, 0pt, 0pt)
% document内の値を入れるための可変参照の設定
let-mutable title-ref <- {}
let-mutable author-ref <- {}
let-mutable date-ref <- {}
let-mutable show-title-ref <- true
let-mutable show-toc-ref <- true
%% style
let-mutable page-width-ref <- 0pt
let-mutable page-height-ref <- 0pt
let-mutable top-space-ref <- 0pt
let-mutable bottom-space-ref <- 0pt
let-mutable left-space-ref <- 0pt
let-mutable right-space-ref <- 0pt
let-mutable header-left-space-ref <- 0pt
let-mutable header-right-space-ref <- 0pt
let-mutable header-height-ref <- 0pt
let-mutable footer-left-space-ref <- 0pt
let-mutable footer-right-space-ref <- 0pt
let-mutable footer-height-ref <- 0pt
let-mutable titlepage-top-space-ref <- 0pt
let-mutable titlepage-bottom-space-ref <- 0pt
let-mutable titlepage-left-space-ref <- 0pt
let-mutable titlepage-right-space-ref <- 0pt
let-mutable tocpage-top-space-ref <- 0pt
let-mutable tocpage-bottom-space-ref <- 0pt
let-mutable tocpage-left-space-ref <- 0pt
let-mutable tocpage-right-space-ref <- 0pt
let-mutable normal-fontsize-ref <- 0pt
let-mutable language-japanese-ref <- true
%% design
let-mutable oneside-ref <- true
let-mutable titlepage-ref <- true
let-mutable title-fontsize-ref <- 0pt
let-mutable author-fontsize-ref <- 0pt
let-mutable date-fontsize-ref <- 0pt
let-mutable tocpage-ref <- true
let-mutable toc-fontsize-ref <- 0pt
let-mutable toc-line-text-part-ref <- {}
let-mutable toc-line-text-chapter-ref <- {}
let-mutable toc-line-text-section-ref <- {}
let-mutable toc-line-text-subsection-ref <- {}
let-mutable toc-line-text-subsubsection-ref <- {}
let-mutable toc-line-space-part-ref <- 0pt
let-mutable toc-line-space-chapter-ref <- 0pt
let-mutable toc-line-space-section-ref <- 0pt
let-mutable toc-line-space-subsection-ref <- 0pt
let-mutable toc-line-space-subsubsection-ref <- 0pt
let-mutable toc-name-fontsize-part-ref <- 0pt
let-mutable toc-name-fontsize-chapter-ref <- 0pt
let-mutable toc-name-fontsize-section-ref <- 0pt
let-mutable toc-name-fontsize-subsection-ref <- 0pt
let-mutable toc-name-fontsize-subsubsection-ref <- 0pt
let-mutable toc-depth-ref <- 0
let-mutable part-fontsize-ref <- 0pt
let-mutable part-page-break-1-ref <- true
let-mutable part-num-function-ref <- (fun _ -> ` `)
let-mutable part-top-space-ref <- 0pt
let-mutable part-bottom-space-ref <- 0pt
let-mutable part-left-space-ref <- 0pt
let-mutable part-line-break-ref <- true
let-mutable part-right-space-ref <- 0pt
let-mutable part-page-break-2-ref <- true
let-mutable chapter-fontsize-ref <- 0pt
let-mutable chapter-page-break-1-ref <- true
let-mutable chapter-num-function-ref <- (fun _ -> ` `)
let-mutable chapter-top-space-ref <- 0pt
let-mutable chapter-bottom-space-ref <- 0pt
let-mutable chapter-left-space-ref <- 0pt
let-mutable chapter-line-break-ref <- true
let-mutable chapter-right-space-ref <- 0pt
let-mutable chapter-page-break-2-ref <- true
let-mutable section-fontsize-ref <- 0pt
let-mutable section-num-function-ref <- (fun _ _ -> ` `)
let-mutable section-top-space-ref <- 0pt
let-mutable section-bottom-space-ref <- 0pt
let-mutable section-left-space-ref <- 0pt
let-mutable section-line-break-ref <- true
let-mutable section-right-space-ref <- 0pt
let-mutable subsection-fontsize-ref <- 0pt
let-mutable subsection-num-function-ref <- (fun _ _ _ -> ` `)
let-mutable subsection-top-space-ref <- 0pt
let-mutable subsection-bottom-space-ref <- 0pt
let-mutable subsection-left-space-ref <- 0pt
let-mutable subsection-line-break-ref <- true
let-mutable subsection-right-space-ref <- 0pt
let-mutable subsubsection-fontsize-ref <- 0pt
let-mutable subsubsection-num-function-ref <- (fun _ _ _ _ -> ` `)
let-mutable subsubsection-top-space-ref <- 0pt
let-mutable subsubsection-bottom-space-ref <- 0pt
let-mutable subsubsection-left-space-ref <- 0pt
let-mutable subsubsection-line-break-ref <- true
let-mutable subsubsection-right-space-ref <- 0pt
let-mutable figure-caption-fontsize-ref <- 0pt
let-mutable figure-caption-right-title-ref <- {}
let-mutable figure-caption-left-title-ref <- {}
let-mutable show-figure-caption-num-ref <- true
let-mutable table-caption-fontsize-ref <- 0pt
let-mutable table-caption-right-title-ref <- {}
let-mutable table-caption-left-title-ref <- {}
let-mutable show-table-caption-num-ref <- true
%% header-footer
let-mutable lhead-ref <- {}
let-mutable chead-ref <- {}
let-mutable rhead-ref <- {}
let-mutable header-line-ref <- 0pt
let-mutable lfoot-ref <- {}
let-mutable cfoot-ref <- {}
let-mutable rfoot-ref <- {}
let-mutable footer-line-ref <- 0pt
let-mutable tocpage-lhead-ref <- {}
let-mutable tocpage-chead-ref <- {}
let-mutable tocpage-rhead-ref <- {}
let-mutable tocpage-header-line-ref <- 0pt
let-mutable tocpage-lfoot-ref <- {}
let-mutable tocpage-cfoot-ref <- {}
let-mutable tocpage-rfoot-ref <- {}
let-mutable tocpage-footer-line-ref <- 0pt
%% fonts
let-mutable latin-roman-ref <- ` `
let-mutable latin-bold-ref <- ` `
let-mutable latin-italic-ref <- ` `
let-mutable latin-sans-ref <- ` `
let-mutable latin-mono-ref <- ` `
let-mutable cjk-mincho-l-ref <- ` `
let-mutable cjk-mincho-m-ref <- ` `
let-mutable cjk-mincho-bx-ref <- ` `
let-mutable cjk-gothic-ref <- ` `
let-mutable cjk-gothic-m-ref <- ` `
let-mutable cjk-gothic-bx-ref <- ` `
let-mutable cjk-gothic-eb-ref <- ` `
let-mutable ratio-latin-ref <- 0.
let-mutable ratio-cjk-ref <- 0.88
let-mutable correction-latin-ref <- 0.
let-mutable correction-cjk-ref <- 0.
%% その他
let-mutable text-org-ref <- (0pt, 0pt)
let-mutable text-org-odd-ref <- (0pt, 0pt)
let-mutable text-width-ref <- 0pt
let-mutable text-height-ref <- 0pt
let-mutable hdrorg-ref <- (0pt, 0pt)
let-mutable hdrorg-odd-ref <- (0pt, 0pt)
let-mutable ftrorg-ref <- (0pt, 0pt)
let-mutable ftrorg-odd-ref <- (0pt, 0pt)
let-mutable hdrwid-ref <- 0pt
let-mutable ftrwid-ref <- 0pt
let-mutable header-thickness-ref <- 0pt
let-mutable footer-thickness-ref <- 0pt
%%% titlepage用
let-mutable titlepage-text-org-ref <- (0pt, 0pt)
let-mutable titlepage-text-width-ref <- 0pt
let-mutable titlepage-text-height-ref <- 0pt
let-mutable titlepage-hdrorg-ref <- (0pt, 0pt)
let-mutable titlepage-ftrorg-ref <- (0pt, 0pt)
let-mutable titlepage-hdrwid-ref <- 0pt
let-mutable titlepage-ftrwid-ref <- 0pt
%%% tocpage用
let-mutable tocpage-text-org-ref <- (0pt, 0pt)
let-mutable tocpage-text-width-ref <- 0pt
let-mutable tocpage-text-height-ref <- 0pt
let-mutable tocpage-titlepage-hdrorg-ref <- (0pt, 0pt)
let-mutable tocpage-hdrorg-ref <- (0pt, 0pt)
let-mutable tocpage-ftrorg-ref <- (0pt, 0pt)
let-mutable tocpage-hdrwid-ref <- 0pt
let-mutable tocpage-ftrwid-ref <- 0pt
let-mutable tocpage-header-thickness-ref <- 0pt
let-mutable tocpage-footer-thickness-ref <- 0pt
let-mutable page-number <- 0
let-mutable toc-page-number <- 0
% -----------------------------------------------------------------------
% documentの設定
let document record inner =
%% 可変参照に値を入れる
let () = title-ref <- record#title in
let () = author-ref <- record#author in
let () = date-ref <- record#date in
let () = show-title-ref <- record#show-title in
let () = show-toc-ref <- record#show-toc in
%%% style
let () = page-width-ref <- record#style#page-width in
let () = page-height-ref <- record#style#page-height in
let () = top-space-ref <- record#style#top-space in
let () = bottom-space-ref <- record#style#bottom-space in
let () = left-space-ref <- record#style#left-space in
let () = right-space-ref <- record#style#right-space in
let () = header-left-space-ref <- record#style#header-left-space in
let () = header-right-space-ref <- record#style#header-right-space in
let () = header-height-ref <- record#style#header-height in
let () = footer-left-space-ref <- record#style#footer-left-space in
let () = footer-right-space-ref <- record#style#footer-right-space in
let () = footer-height-ref <- record#style#footer-height in
let () = titlepage-top-space-ref <- record#style#titlepage-top-space in
let () = titlepage-bottom-space-ref <- record#style#titlepage-bottom-space in
let () = titlepage-left-space-ref <- record#style#titlepage-left-space in
let () = titlepage-right-space-ref <- record#style#titlepage-right-space in
let () = tocpage-top-space-ref <- record#style#tocpage-top-space in
let () = tocpage-bottom-space-ref <- record#style#tocpage-bottom-space in
let () = tocpage-left-space-ref <- record#style#tocpage-left-space in
let () = tocpage-right-space-ref <- record#style#tocpage-right-space in
let () = normal-fontsize-ref <- record#style#normal-fontsize in
let () = language-japanese-ref <- record#style#language-japanese in
%%% design
let () = oneside-ref <- record#design#oneside in
let () = titlepage-ref <- record#design#titlepage in
let () = title-fontsize-ref <- record#design#title-fontsize in
let () = author-fontsize-ref <- record#design#author-fontsize in
let () = date-fontsize-ref <- record#design#date-fontsize in
let () = tocpage-ref <- record#design#tocpage in
let () = toc-fontsize-ref <- record#design#toc-fontsize in
let () = toc-line-text-part-ref <- record#design#toc-line-text-part in
let () = toc-line-text-chapter-ref <- record#design#toc-line-text-chapter in
let () = toc-line-text-section-ref <- record#design#toc-line-text-section in
let () = toc-line-text-subsection-ref <- record#design#toc-line-text-subsection in
let () = toc-line-text-subsubsection-ref <- record#design#toc-line-text-subsubsection in
let () = toc-line-space-part-ref <- record#design#toc-line-space-part in
let () = toc-line-space-chapter-ref <- record#design#toc-line-space-chapter in
let () = toc-line-space-section-ref <- record#design#toc-line-space-section in
let () = toc-line-space-subsection-ref <- record#design#toc-line-space-subsection in
let () = toc-line-space-subsubsection-ref <- record#design#toc-line-space-subsubsection in
let () = toc-name-fontsize-part-ref <- record#design#toc-name-fontsize-part in
let () = toc-name-fontsize-chapter-ref <- record#design#toc-name-fontsize-chapter in
let () = toc-name-fontsize-section-ref <- record#design#toc-name-fontsize-section in
let () = toc-name-fontsize-subsection-ref <- record#design#toc-name-fontsize-subsection in
let () = toc-name-fontsize-subsubsection-ref <- record#design#toc-name-fontsize-subsubsection in
let () = toc-depth-ref <- record#design#toc-depth in
let () = part-fontsize-ref <- record#design#part-fontsize in
let () = part-page-break-1-ref <- record#design#part-page-break-1 in
let () = part-num-function-ref <- record#design#part-num-function in
let () = part-top-space-ref <- record#design#part-top-space in
let () = part-bottom-space-ref <- record#design#part-bottom-space in
let () = part-left-space-ref <- record#design#part-left-space in
let () = part-line-break-ref <- record#design#part-line-break in
let () = part-right-space-ref <- record#design#part-right-space in
let () = part-page-break-2-ref <- record#design#part-page-break-2 in
let () = chapter-fontsize-ref <- record#design#chapter-fontsize in
let () = chapter-page-break-1-ref <- record#design#chapter-page-break-1 in
let () = chapter-num-function-ref <- record#design#chapter-num-function in
let () = chapter-top-space-ref <- record#design#chapter-top-space in
let () = chapter-bottom-space-ref <- record#design#chapter-bottom-space in
let () = chapter-left-space-ref <- record#design#chapter-left-space in
let () = chapter-line-break-ref <- record#design#chapter-line-break in
let () = chapter-right-space-ref <- record#design#chapter-right-space in
let () = chapter-page-break-2-ref <- record#design#chapter-page-break-2 in
let () = section-fontsize-ref <- record#design#section-fontsize in
let () = section-num-function-ref <- record#design#section-num-function in
let () = section-top-space-ref <- record#design#section-top-space in
let () = section-bottom-space-ref <- record#design#section-bottom-space in
let () = section-left-space-ref <- record#design#section-left-space in
let () = section-line-break-ref <- record#design#section-line-break in
let () = section-right-space-ref <- record#design#section-right-space in
let () = subsection-fontsize-ref <- record#design#subsection-fontsize in
let () = subsection-num-function-ref <- record#design#subsection-num-function in
let () = subsection-top-space-ref <- record#design#subsection-top-space in
let () = subsection-bottom-space-ref <- record#design#subsection-bottom-space in
let () = subsection-left-space-ref <- record#design#subsection-left-space in
let () = subsection-line-break-ref <- record#design#subsection-line-break in
let () = subsection-right-space-ref <- record#design#subsection-right-space in
let () = subsubsection-fontsize-ref <- record#design#subsubsection-fontsize in
let () = subsubsection-num-function-ref <- record#design#subsubsection-num-function in
let () = subsubsection-top-space-ref <- record#design#subsubsection-top-space in
let () = subsubsection-bottom-space-ref <- record#design#subsubsection-bottom-space in
let () = subsubsection-left-space-ref <- record#design#subsubsection-left-space in
let () = subsubsection-line-break-ref <- record#design#subsubsection-line-break in
let () = subsubsection-right-space-ref <- record#design#subsubsection-right-space in
let () = figure-caption-fontsize-ref <- record#design#figure-caption-fontsize in
let () = figure-caption-right-title-ref <- record#design#figure-caption-right-title in
let () = figure-caption-left-title-ref <- record#design#figure-caption-left-title in
let () = show-figure-caption-num-ref <- record#design#show-figure-caption-num in
let () = table-caption-fontsize-ref <- record#design#table-caption-fontsize in
let () = table-caption-right-title-ref <- record#design#table-caption-right-title in
let () = table-caption-left-title-ref <- record#design#table-caption-left-title in
let () = show-table-caption-num-ref <- record#design#show-table-caption-num in
%%% header-footer
let () = lhead-ref <- record#header-footer#lhead in
let () = chead-ref <- record#header-footer#chead in
let () = rhead-ref <- record#header-footer#rhead in
let () = header-line-ref <- record#header-footer#header-line in
let () = lfoot-ref <- record#header-footer#lfoot in
let () = cfoot-ref <- record#header-footer#cfoot in
let () = rfoot-ref <- record#header-footer#rfoot in
let () = footer-line-ref <- record#header-footer#footer-line in
let () = tocpage-lhead-ref <- record#header-footer#tocpage-lhead in
let () = tocpage-chead-ref <- record#header-footer#tocpage-chead in
let () = tocpage-rhead-ref <- record#header-footer#tocpage-rhead in
let () = tocpage-header-line-ref <- record#header-footer#tocpage-header-line in
let () = tocpage-lfoot-ref <- record#header-footer#tocpage-lfoot in
let () = tocpage-cfoot-ref <- record#header-footer#tocpage-cfoot in
let () = tocpage-rfoot-ref <- record#header-footer#tocpage-rfoot in
let () = tocpage-footer-line-ref <- record#header-footer#tocpage-footer-line in
%%% fonts
let () = latin-roman-ref <- record#fonts#latin-roman in
let () = latin-bold-ref <- record#fonts#latin-bold in
let () = latin-italic-ref <- record#fonts#latin-italic in
let () = latin-sans-ref <- record#fonts#latin-sans in
let () = latin-mono-ref <- record#fonts#latin-mono in
let () = cjk-mincho-l-ref <- record#fonts#cjk-mincho-l in
let () = cjk-mincho-m-ref <- record#fonts#cjk-mincho-m in
let () = cjk-mincho-bx-ref <- record#fonts#cjk-mincho-bx in
let () = cjk-gothic-m-ref <- record#fonts#cjk-gothic-m in
let () = cjk-gothic-bx-ref <- record#fonts#cjk-gothic-bx in
let () = cjk-gothic-eb-ref <- record#fonts#cjk-gothic-eb in
let () = ratio-latin-ref <- record#fonts#ratio-latin in
let () = ratio-cjk-ref <- record#fonts#ratio-cjk in
let () = correction-latin-ref <- record#fonts#correction-latin in
let () = correction-cjk-ref <- record#fonts#correction-cjk in
%% 値計算
let () = text-org-ref <- ( !left-space-ref , (!top-space-ref +' !header-height-ref)) in
let () = text-org-odd-ref <- ( !right-space-ref , (!top-space-ref +' !header-height-ref)) in
let () = text-width-ref <- ((!page-width-ref -' !left-space-ref) -' !right-space-ref) in
let () = text-height-ref <- (!page-height-ref -' !top-space-ref -' !header-height-ref -' !footer-height-ref -' !bottom-space-ref) in
let () = hdrorg-ref <- ( !header-left-space-ref , !top-space-ref) in
let () = hdrorg-odd-ref <- ( !header-right-space-ref , !top-space-ref) in
let () = ftrorg-ref <- (!footer-left-space-ref , ((!page-height-ref -' !bottom-space-ref) -' !footer-height-ref)) in
let () = ftrorg-odd-ref <- (!footer-right-space-ref , ((!page-height-ref -' !bottom-space-ref) -' !footer-height-ref)) in
let () = hdrwid-ref <- ((!page-width-ref -' !header-left-space-ref) -' !header-right-space-ref) in
let () = ftrwid-ref <- ((!page-width-ref -' !footer-left-space-ref) -' !footer-right-space-ref) in
let () = header-thickness-ref <- !header-line-ref in
let () = footer-thickness-ref <- !footer-line-ref in
%%% titlepageでの計算
let () = titlepage-text-org-ref <- ( !titlepage-left-space-ref, (!titlepage-top-space-ref +' !header-height-ref)) in
let () = titlepage-text-width-ref <- ((!page-width-ref -' !titlepage-left-space-ref) -' !titlepage-right-space-ref) in
let () = titlepage-text-height-ref <- (!page-height-ref -' !titlepage-top-space-ref -' !header-height-ref -' !footer-height-ref -' !titlepage-bottom-space-ref) in
let () = titlepage-hdrorg-ref <- ( !header-left-space-ref , !titlepage-top-space-ref) in
let () = titlepage-ftrorg-ref <- (!footer-left-space-ref , ((!page-height-ref -' !titlepage-bottom-space-ref) -' !footer-height-ref)) in
let () = titlepage-hdrwid-ref <- ((!page-width-ref -' !header-left-space-ref) -' !header-right-space-ref) in
let () = titlepage-ftrwid-ref <- ((!page-width-ref -' !footer-left-space-ref) -' !footer-right-space-ref) in
%%% tocpageでの計算
let () = tocpage-text-org-ref <- ( !tocpage-left-space-ref, (!tocpage-top-space-ref +' !header-height-ref)) in
let () = tocpage-text-width-ref <- ((!page-width-ref -' !tocpage-left-space-ref) -' !tocpage-right-space-ref) in
let () = tocpage-text-height-ref <- (!page-height-ref -' !tocpage-top-space-ref -' !header-height-ref -' !footer-height-ref -' !bottom-space-ref) in
let () = tocpage-hdrorg-ref <- ( !header-left-space-ref , !tocpage-top-space-ref) in
let () = tocpage-ftrorg-ref <- (!footer-left-space-ref , ((!page-height-ref -' !tocpage-bottom-space-ref) -' !footer-height-ref)) in
let () = tocpage-hdrwid-ref <- ((!page-width-ref -' !header-left-space-ref) -' !header-right-space-ref) in
let () = tocpage-ftrwid-ref <- ((!page-width-ref -' !footer-left-space-ref) -' !footer-right-space-ref) in
let () = tocpage-header-thickness-ref <- !tocpage-header-line-ref in
let () = tocpage-footer-thickness-ref <- !tocpage-footer-line-ref in
%% 構築のための準備
%% フォント設定
%%% 拡大率
let font-ratio-latin = !ratio-latin-ref in
let font-ratio-cjk = !ratio-cjk-ref in
%%% ベースライン補正
let font-correction-latin = !correction-latin-ref in
let font-correction-cjk = !correction-cjk-ref in
%%% フォント設定
let () = font-latin-roman-ref <- (!latin-roman-ref , font-ratio-latin , font-correction-latin) in
let () = font-latin-bold-ref <- (!latin-bold-ref , font-ratio-latin , font-correction-latin) in
let () = font-latin-italic-ref <- (!latin-italic-ref , font-ratio-latin , font-correction-latin) in
let () = font-latin-sans-ref <- (!latin-sans-ref , font-ratio-latin , font-correction-latin) in
let () = font-latin-mono-ref <- (!latin-mono-ref , font-ratio-latin, font-correction-latin) in
let () = font-cjk-mincho-l-ref <- (!cjk-mincho-l-ref , font-ratio-cjk, font-correction-cjk) in
let () = font-cjk-mincho-m-ref <- (!cjk-mincho-m-ref , font-ratio-cjk, font-correction-cjk) in
let () = font-cjk-mincho-bx-ref <- (!cjk-mincho-bx-ref , font-ratio-cjk, font-correction-cjk) in
let () = font-cjk-gothic-m-ref <- (!cjk-gothic-m-ref , font-ratio-cjk, font-correction-cjk) in
let () = font-cjk-gothic-bx-ref <- (!cjk-gothic-bx-ref , font-ratio-cjk, font-correction-cjk) in
let () = font-cjk-gothic-eb-ref <- (!cjk-gothic-eb-ref , font-ratio-cjk, font-correction-cjk) in
%% ブロック読み込みの準備
let get-standard-context wid =
get-initial-context wid (command \math)
|> set-dominant-wide-script Kana
|> set-language Kana Japanese
|> set-language HanIdeographic Japanese
|> set-dominant-narrow-script Latin
|> set-language Latin English
|> set-font Kana !font-cjk-mincho-m-ref
|> set-font HanIdeographic !font-cjk-mincho-m-ref
|> set-font Latin !font-latin-roman-ref
|> set-math-font record#fonts#math-font
|> set-hyphen-penalty 100
in
let ctx-doc = get-standard-context !text-width-ref in
let ctx-header = get-standard-context !hdrwid-ref in
let ctx-footer = get-standard-context !ftrwid-ref in
let ctx-titlepage = get-standard-context !titlepage-text-width-ref in
let ctx-titlepage-header = get-standard-context !titlepage-hdrwid-ref in
let ctx-titlepage-footer = get-standard-context !titlepage-ftrwid-ref in
let ctx-tocpage = get-standard-context !tocpage-text-width-ref in
let ctx-tocpage-header = get-standard-context !tocpage-hdrwid-ref in
let ctx-tocpage-footer = get-standard-context !tocpage-ftrwid-ref in
%% メイン部分読み込み
let bb-main = read-block ctx-doc inner in
%% タイトル
let bb-title =
if not !show-title-ref then
block-nil
else
if !titlepage-ref then
let bb-title-main =
let ctx =
ctx-doc |> set-font-size !title-fontsize-ref
|> set-latin-font !font-latin-sans-ref
|> set-cjk-font !font-cjk-mincho-bx-ref
in
line-break false false ctx
(inline-fil ++ read-inline ctx !title-ref ++ inline-fil)
in
let bb-author =
let ctx =
ctx-doc |> set-font-size !author-fontsize-ref
|> set-latin-font !font-latin-sans-ref
|> set-cjk-font !font-cjk-mincho-bx-ref
in
line-break false false ctx
(inline-fil ++ read-inline ctx !author-ref ++ inline-fil)
in
let bb-date =
let ctx =
ctx-doc |> set-font-size !date-fontsize-ref
|> set-latin-font !font-latin-sans-ref
|> set-cjk-font !font-cjk-mincho-bx-ref
in
line-break false false ctx
(inline-fil ++ read-inline ctx !date-ref ++ inline-fil)
in
bb-title-main +++ bb-author +++ bb-date +++ clear-page
else
let bb-title-main =
let ctx =
ctx-doc |> set-font-size !title-fontsize-ref
|> set-latin-font !font-latin-sans-ref
|> set-cjk-font !font-cjk-mincho-bx-ref
in
line-break false false ctx
(inline-fil ++ read-inline ctx !title-ref ++ inline-fil)
in
let bb-author =
let ctx =
ctx-doc |> set-font-size !author-fontsize-ref
|> set-latin-font !font-latin-sans-ref
|> set-cjk-font !font-cjk-mincho-bx-ref
in
line-break false false ctx
(inline-fil ++ read-inline ctx !author-ref ++ inline-fil)
in
let bb-date =
let ctx =
ctx-doc |> set-font-size !date-fontsize-ref
|> set-latin-font !font-latin-sans-ref
|> set-cjk-font !font-cjk-mincho-bx-ref
in
line-break false false ctx
(inline-fil ++ read-inline ctx !date-ref ++ inline-fil)
in
bb-title-main +++ bb-author +++ bb-date
in
%% 目次
let make-toc-title ctx =
ctx |> set-font-size !toc-fontsize-ref
|> set-latin-font !font-latin-sans-ref
|> set-cjk-font !font-cjk-gothic-bx-ref
in
let bb-toc =
if not !show-toc-ref then
block-nil
else
let bb-toc-title =
line-break true false ctx-doc (read-inline (make-toc-title ctx-doc) {目次} ++ inline-fil)
in
let bb-toc-main =
(!toc-acc-ref) |> List.reverse |> List.fold-left (fun bbacc tocelem -> (
match tocelem with
| TocPart(label, title) ->
let it-num = embed-string (get-cross-reference-number label) in
let it-page = embed-string (get-cross-reference-page label) in
let ib-title =
let ctx =
ctx-doc |> set-font-size !toc-name-fontsize-part-ref
|> set-latin-font !font-latin-sans-ref
|> set-cjk-font !font-cjk-gothic-bx-ref
in
read-inline ctx {#it-num; #title;} ++ inline-skip 3pt in
let ib-page = inline-skip 3pt ++ read-inline ctx-doc it-page in
let toc-line-part =
let w = (get-text-width ctx-doc) -' !toc-line-space-part-ref -' (get-natural-width ib-title) -' (get-natural-width ib-page) in
if w <' 0pt then inline-fil else
make-toc-line ctx-doc w !toc-line-text-part-ref
in
bbacc +++ line-break true true ctx-doc
(inline-skip !toc-line-space-part-ref ++ ib-title ++ inline-fil ++ toc-line-part ++ inline-fil ++ ib-page)
| TocChapter(label, title) ->
let it-num = embed-string (get-cross-reference-number label) in
let it-page = embed-string (get-cross-reference-page label) in
let ib-title =
let ctx =
ctx-doc |> set-font-size !toc-name-fontsize-chapter-ref
|> set-latin-font !font-latin-sans-ref
|> set-cjk-font !font-cjk-gothic-bx-ref
in
read-inline ctx {#it-num; #title;} ++ inline-skip 3pt in
let ib-page = inline-skip 3pt ++ read-inline ctx-doc it-page in
let toc-line-chapter =
let w = (get-text-width ctx-doc) -' !toc-line-space-chapter-ref -' (get-natural-width ib-title) -' (get-natural-width ib-page) in
if w <' 0pt then inline-fil else
make-toc-line ctx-doc w !toc-line-text-chapter-ref
in
bbacc +++ line-break true true ctx-doc
(inline-skip !toc-line-space-chapter-ref ++ ib-title ++ inline-fil ++ toc-line-chapter ++ inline-fil ++ ib-page)
| TocSection(label, title) ->
let it-num = embed-string (get-cross-reference-number label) in
let it-page = embed-string (get-cross-reference-page label) in
let ib-title =
let ctx =
ctx-doc |> set-font-size !toc-name-fontsize-section-ref
|> set-latin-font !font-latin-roman-ref
|> set-cjk-font !font-cjk-mincho-bx-ref
in
read-inline ctx {#it-num; #title;} ++ inline-skip 3pt in
let ib-page = inline-skip 3pt ++ read-inline ctx-doc it-page in
let toc-line-section =
let w = (get-text-width ctx-doc) -' !toc-line-space-section-ref -' (get-natural-width ib-title) -' (get-natural-width ib-page) in
if w <' 0pt then inline-fil else
make-toc-line ctx-doc w !toc-line-text-section-ref
in
bbacc +++ line-break true true ctx-doc
(inline-skip !toc-line-space-section-ref ++ ib-title ++ inline-fil ++ toc-line-section ++ inline-fil ++ ib-page)
| TocSubSection(label, title) ->
let it-num = embed-string (get-cross-reference-number label) in
let it-page = embed-string (get-cross-reference-page label) in
let ib-title =
let ctx =
ctx-doc |> set-font-size !toc-name-fontsize-subsection-ref
|> set-latin-font !font-latin-roman-ref
|> set-cjk-font !font-cjk-mincho-bx-ref
in
read-inline ctx {#it-num; #title;} ++ inline-skip 3pt in
let ib-page = inline-skip 3pt ++ read-inline ctx-doc it-page in
let toc-line-subsection =
let w = (get-text-width ctx-doc) -' !toc-line-space-subsection-ref -' (get-natural-width ib-title) -' (get-natural-width ib-page) in
if w <' 0pt then inline-fil else
make-toc-line ctx-doc w !toc-line-text-subsection-ref
in
bbacc +++ line-break true true ctx-doc
(inline-skip !toc-line-space-subsection-ref ++ ib-title ++ inline-fil ++ toc-line-subsection ++ inline-fil ++ ib-page)
| TocSubSubSection(label, title) ->
let it-num = embed-string (get-cross-reference-number label) in
let it-page = embed-string (get-cross-reference-page label) in
let ib-title =
let ctx =
ctx-doc |> set-font-size !toc-name-fontsize-subsubsection-ref
|> set-latin-font !font-latin-roman-ref
|> set-cjk-font !font-cjk-mincho-bx-ref
in
read-inline ctx {#it-num; #title;} ++ inline-skip 3pt in
let ib-page = inline-skip 3pt ++ read-inline ctx-doc it-page in
let toc-line-subsubsection =
let w = (get-text-width ctx-doc) -' !toc-line-space-subsubsection-ref -' (get-natural-width ib-title) -' (get-natural-width ib-page) in
if w <' 0pt then inline-fil else
make-toc-line ctx-doc w !toc-line-text-subsubsection-ref
in
bbacc +++ line-break true true ctx-doc
(inline-skip !toc-line-space-subsubsection-ref ++ ib-title ++ inline-fil ++ toc-line-subsubsection ++ inline-fil ++ ib-page)
)) block-nil
in
if !tocpage-ref then
bb-toc-title +++ bb-toc-main +++ clear-page
else
bb-toc-title +++ bb-toc-main