/
cbxml.cpp
4213 lines (3611 loc) · 136 KB
/
cbxml.cpp
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
// ---------------------------------------------------------------------------
#pragma hdrstop
#include "cbxml.h"
// ---------------------------------------------------------------------------
#pragma package(smart_init)
// ---------------------------------------------------------------------------
// 建構函式
// 傳入參數為 XML 檔, 呈現的設定
__fastcall CCBXML::CCBXML(String sFile, String sLink, CSetting * cSetting, String sJSFile , bool bShowHighlight, TmyMonster * seSearchEngine)
{
IsDebug = false;
// 初值
XMLFile = sFile;
Setting = cSetting;
HTMLText = "";
HTMLCollation = ""; // HTML 校註
JSFile = sJSFile;
ShowHighlight = bShowHighlight; // 是否塗色
mOrigNote.clear();
SerialPath = u""; // 系列(書)的主要位置
BookVerName = u"";
GetInitialFromFileName(); // 由經名取得一切相關資訊
// 初值
IsAIPunc = false; // 判斷是不是 AI 標點文件
DivCount = 0; // Div 的層次
ListCount = 0; // list 層次
InByline = false; // 用來判斷是否是作譯者
// 偈頌相關
IsFindLg = false; // 一遇到 <lg> 就 true, 第一個 <l> 就會處理並設為 false;
InLg = false; // 判斷是不是在 <lg> 之中, 主要是用來處理偈頌中的標點要不要呈現.
LgNormal = true; // lg 的 type 是不是 normal? 有 normal 及 abnormal 二種
LgInline = false; // lg 的 place 是不是 inline?
LgMarginLeft = ""; // Lg 整段的位移
// L
//LTagNum = 0; // <l> 出現的數字, 用來判斷要在普及版寫幾個空格
LMarginLeft = ""; // L 整段的位移
MarginLeft = ""; // 移位
ListCount = 0; // 計算 list 的數目, 有一些地方需要用到
for(int i=0; i<30; i++) ItemNum[i] = 0; // 用來判斷 item 出現的次數
CellNum = 0; // cell 格式數量歸 0
OtherColspan = 0; // 因本 cell 佔 n 格以上, 所以和後面的 cell 要空 (n-1)*3 的空格, 此即記錄 n-1 的數字
FuWenCount = 0; // 用來判斷是否是附文, 因為有巢狀, 所以用 int
InSutraNum = false; // 用來判斷本行是否是經號
InPinHead = false; // 用來判斷本行是否是品名
InFuWenHead = false; // 用來判斷本行是否是附文標題
InOtherHead = false; // 用來判斷本行是否是其它標題
InHead = false; // 用來判斷本行是否是標題
InNoteOrig = false; // 用來判斷是不是在 Note type=orig
InNoteMod = false; // 用來判斷是不是在 Note type=mod
InNoteAdd = false; // 用來判斷是不是在 Note type=add
InTTNormal = false; // 在 <tt rend="normal"> 中, 這時每一個 <t> 都要換行 , T54n2133A : <lb n="1194c17"/><p><tt rend="normal"><t lang="san-sd">
PreFormatCount = 0; // 判斷是否是要依據原始經文格式切行, 要累加的, 因為可能有巢狀的 pre
NoNormal = 0; // 用來判斷是否可用通用字 , 大於 0 就不用通用字, 這二種就不用通用字 <text cb:behaviour="no-norm"> 及 <term cb:behaviour="no-norm">
// 要判斷品的範圍, 若出現品的 mulu, 則記錄 level, 等到 level 數字再次大於或等於時, 此品才結束
// <mulu level="3" label="3 轉輪聖王品" type="品"/>
MuluLevel = 999; // 目錄的層次, 一開始要設到最小
MuluLabel = u""; // 目錄的名稱
InMulu = false; // 判斷是不是在 <cb:mulu> 之中.
InMuluPin = false; // 判斷是不是在 <cb:mulu> 之中, 且是 "品" 目錄.
NoteAddNum = 0; // 自訂校註 <note type="add" 的流水號, 由 1 開始
NextLine = new CNextLine; // 用來處理隔行 <tt> 的物件
// 處理 XML -----------------------------------------------------------
Document = interface_cast<Xmlintf::IXMLDocument>(new TXMLDocument(NULL));
Document->FileName = XMLFile;
Document->ParseOptions = Document->ParseOptions + (TParseOptions() << poPreserveWhiteSpace);
HTMLText += MakeHTMLHead(); // 先產生 html 的 head
// 是否有塗色? 有就表示有檢索字串
if(bShowHighlight)
{
// 加上搜尋字串的 <div>
// 把搜尋字串中的 ? 換成 ⍰
String s = seSearchEngine->SearchSentence;
s = StringReplace(s, u"?", u"⍰", TReplaceFlags() << rfReplaceAll);
HTMLText += u"<div id='SearchHead'>檢索字串:" + s + u"<hr></div>";
}
HTMLText += ParseXML(); // 處理內文
HTMLText = AddOrigNote(HTMLText); // 原本的 orig 校勘還沒加入, 此時才要加入
HTMLCollation = AddOrigNote(HTMLCollation);
// 塗色否?
if(bShowHighlight)
{
CHighlight * HL = new CHighlight(seSearchEngine);
HTMLText = HL->AddHighlight(&HTMLText);
delete HL;
}
// 版本資訊
String sVerInfo = GetVerInfo();
HTMLText += sVerInfo;
// 記錄校勘
HTMLText += "<div id='CollationList' style='display:none'>\n";
HTMLText += HTMLCollation;
HTMLText += "</div>\n";
if(sLink != "")
{
HTMLText += "<script>\n"
"location.href='#" + sLink + "';\n"
"</script>\n";
// "var gotoline = '#" + sLink + "';"
// "location.href='#" + sLink + "';\n"
}
else if(bShowHighlight)
{
HTMLText += "<script>\n"
"location.href='#Search_0_1';\n"
"</script>\n";
}
HTMLText += "\n</body>\n</html>";
}
// ---------------------------------------------------------------------------
__fastcall CCBXML::~CCBXML(void) // 解構函式
{
// 底下的 delete 在 mac 會當掉, 要找正規方法 ???
// if (Document) delete Document;
}
// 先產生 html 的 head
String __fastcall CCBXML::MakeHTMLHead()
{
// 字型大小說明 : 主要為了用中文和等寬英文畫圖, 中文要 21px, 英文用 17.5px 才能對齊
String sJqueryFile = StringReplace(JSFile, u"cbreader.js", "jquery.min.js", TReplaceFlags() << rfReplaceAll << rfIgnoreCase);
String sSiddamFile = StringReplace(JSFile, u"cbreader.js", "font/Siddam.otf", TReplaceFlags() << rfReplaceAll << rfIgnoreCase);
// 底下一定要用 / 才能使用
sSiddamFile = StringReplace(sSiddamFile, u"\\", "/", TReplaceFlags() << rfReplaceAll << rfIgnoreCase);
String sRanjanaFile = StringReplace(sSiddamFile, u"siddam.otf", "Ranjana.otf", TReplaceFlags() << rfReplaceAll << rfIgnoreCase);
String sHtml = u"<!DOCTYPE html>\n"
"<html>\n"
"<head>\n"
" <meta charset='utf-8'>\n"
" <title>";
sHtml += BookId + SutraId + u" " + SutraName;
sHtml += u"</title>\n";
sHtml += u" <script src='";
sHtml += sJqueryFile;
sHtml += u"'></script>\n"
" <script src='";
sHtml += JSFile;
sHtml += u"'></script>\n"
" <style type=\"text/css\">\n"
" @font-face {\n"
" font-family: CBFont;\n"
u" src: local('Times New Roman'), local(MingLiU), local(細明體), local(PMingLiU), local(新細明體), local(NSimSun), local(SimSun), local('Songti TC');\n"
" }\n"
" @font-face {\n"
" font-family: CBFont;\n"
" unicode-range: U+2500-25ff;\n"
u" src: local(MingLiU), local(細明體), local(NSimSun), local('Songti TC');\n"
" }\n"
" @font-face {\n"
" font-family: siddam;\n"
" src: local(siddam), url('";
sHtml += sSiddamFile;
sHtml += "');\n"
" }\n"
" @font-face {\n"
" font-family: Ranjana;\n"
" src: local(Ranjana), url('";
sHtml += sRanjanaFile;
sHtml += "');\n"
" }\n"
" body { background:#DDF1DC; font-weight: normal; line-height:26px; color:#000000; font-size:21px; font-family:CBFont;}\n"
" #AIPuncRemind {color:#ffffff; background: #d80000;}\n"
" a.SearchWord0 {color:#0000ff; background: #ffff66;}\n"
" a.SearchWord1 {color:#0000ff; background: #a0ffff;}\n"
" a.SearchWord2 {color:#0000ff; background: #99ff99;}\n"
" a.SearchWord3 {color:#0000ff; background: #ff9999;}\n"
" a.SearchWord4 {color:#0000ff; background: #ff66ff;}\n"
" span.guess1 {background: #fff0a0;}\n"
" span.guess2 {background: #ffd080;}\n"
" span.guess3 {background: #ffb060;}\n"
" span.guess4 {background: #ff9040;}\n"
" a.hover {color:#0000ff;}\n"
" a:visited {color:#0000ff;}\n"
" a:link {color:#0000ff;}\n"
" a:active {color:#0000ff;}\n"
" .foreign {font-family:'Times New Roman', 'Gandhari Unicode';}\n"
u" .preformat {font-family:細明體,MingLiU,NSimSun,'Songti TC'; font-size:21px;}\n"
" .preformat .foreign {font-family:'Courier New'; font-size:17.5px;}\n"
" .gaiji {font-family:'Times New Roman','Hanazono Mincho B';}\n"
" .juannum {color:#008000; font-size:21px;}\n"
" .juanname {color:#0000FF; font-weight: bold; font-size:24px;}\n"
" .xu {color:#0000A0; font-size:21px;}\n"
" .w {color:#0000A0; font-size:21px;}\n"
" .div-orig {font-weight: bold;}\n"
" .byline {color:#408080; font-size:21px;}\n"
" .headname {color:#0000A0; font-weight: bold; font-size:24px;}\n"
" .headname2 {color:#0000A0; font-weight: bold; font-size:24px;}\n"
" .headname3 {color:#0000A0; font-weight: bold; font-size:24px;}\n"
" .headname4 {color:#0000A0; font-weight: bold; font-size:24px;}\n"
u" .linehead {color:#0000A0; font-weight: normal; font-size:18px;font-family:MingLiU,細明體,NSimSun,'Songti TC';}\n"
u" .parahead {color:#0000A0; font-weight: normal; font-size:18px;font-family:MingLiU,細明體,NSimSun,'Songti TC';}\n"
u" .pts_head {color:#0000A0; font-weight: normal; font-size:18px;font-family:MingLiU,細明體,NSimSun,'Songti TC';}\n"
" .lg {color:#008040; font-size:21px;}\n"
" .corr {color:#FF0000; }\n"
" .note {color:#9F5000; font-size:18px;}\n"
" table {border-collapse: collapse; margin: 20px;}\n";
if(Setting->VerticalMode)
sHtml += u" body {writing-mode: tb-rl;}\n";
// 行首格式
if(Setting->ShowLineFormat)
// 原書
sHtml += u" div {display:inline;}\n"
" p {display:inline;}\n"
" br.lb_br {display:inline;}\n"
" br.para_br {display:none;}\n"
" p.juannum {display:inline; margin-left:0em;}\n" // 經號
" p.headname2 {display:inline; margin-left:0em;}\n" // head 標題
" p.headname3 {display:inline; margin-left:0em;}\n" // head 標題
" p.headname4 {display:inline; margin-left:0em;}\n" // head 標題
" p.byline {display:inline; margin-left:0em;}\n" // byline
" table {border-style: none;}\n"
" td {padding: 0px;}\n"
" span.line_space {display:inline;}\n" // 行首空格
" span.para_space {display:none;}\n"; // 行首空格
// " table {display: inline; line-height:2px; border-style: none}\n"
// " tbody {display: inline;}\n"
// " tr {display: inline;}\n"
// " td {display: inline; padding: 0px;}\n"
// " ul {display:inline;padding-left:0;}\n" // <ul>
// " li {display:inline;}\n"; // <li>
else
// 段落格式
sHtml += u" div {display:block;}\n"
" p {display:block;}\n"
" br.lb_br {display:none;}\n"
" br.para_br {display:inline;}\n"
" p.juannum {display:block; margin-left:2em;}\n" // 經號
" p.headname2 {display:block; margin-left:2em;}\n" // head 標題
" p.headname3 {display:block; margin-left:3em;}\n" // head 標題
" p.headname4 {display:block; margin-left:4em;}\n" // head 標題
" p.byline {display:block; text-align: right;}\n" // byline
" table {border-style: solid;border-collapse: collapse;}\n"
" td {padding: 0.5em;}\n"
" td.pl-1 {padding-left: 1.5em;}\n"
" td.pl-2 {padding-left: 2.5em;}\n"
" td.pl-3 {padding-left: 3.5em;}\n"
" td.pl-4 {padding-left: 4.5em;}\n"
" td.pl-5 {padding-left: 5.5em;}\n"
" td.pl-6 {padding-left: 6.5em;}\n"
" td.pl-7 {padding-left: 7.5em;}\n"
" td.pl-8 {padding-left: 8.5em;}\n"
" span.line_space {display:none;}\n" // 行首空格
" span.para_space {display:inline;}\n"; // 行首空格
// " table {display: table; line-height:20px; border-style: solid}\n"
// " tbody {display: table-row-group;}\n"
// " tr {display: table-row;}\n"
// " td {display: table-cell; padding: 10px;}\n"
// " ul {display:block;padding-left:40;}\n" // <ul>
// " li {display:list-item;}\n"; // <li>
/*
if(Setting->ShowLineHead)
{
if(Setting->ShowLineFormat)
sHtml += u" .linehead {display:inline;}\n"
" .parahead {display:none;}\n";
else
sHtml += u" .linehead {display:none;}\n"
" .parahead {display:inline;}\n";
sHtml += u" .pts_head {display:inline;}\n";
}
else
{
sHtml += u" .linehead {display:none;}\n"
" .parahead {display:none;}\n"
" .pts_head {display:none;}\n";
}
*/
// 校勘呈現
if(Setting->ShowCollation == false)
sHtml += u" .note_orig {display:none;}\n"
" .note_mod {display:none;}\n"
" .note_add {display:none;}\n"
" .note_star {display:none;}\n"
" .note_star_removed {display:none;}\n";
else if(Setting->CollationType == ctOrigCollation)
sHtml += u" .note_mod {display:none;}\n"
" .note_orig {display:inline;}\n"
" .note_add {display:none;}\n"
" .note_star {display:inline;}\n"
" .note_star_removed {display:inline;}\n";
else if(Setting->CollationType == ctCBETACollation)
sHtml += u" .note_orig {display:none;}\n"
" .note_mod {display:inline;}\n"
" .note_add {display:inline;}\n"
" .note_star {display:inline;}\n"
" .note_star_removed {display:none;}\n";
sHtml += u" </style>\n";
// 自訂 CSS
if(Setting->UseCSSFile)
{
sHtml += u"<link rel=stylesheet type=\"text/css\" href=\"";
sHtml += Setting->CSSFileName;
sHtml += u"\">\n";
}
sHtml += u"</head>\n";
sHtml += u"<body data-sutraname='" + SutraName
+ u"' data-juan='" + JuanNum
+ u"' data-totaljuan='" + TotalJuan + u"'";
// data-notetype 用來判斷目前是呈現何種校註
if(Setting->ShowCollation == false)
sHtml += u" data-notetype='none'";
else if(Setting->CollationType == ctOrigCollation)
sHtml += u" data-notetype='orig'";
else if(Setting->CollationType == ctCBETACollation)
sHtml += u" data-notetype='cbeta'";
sHtml += u">\n";
return sHtml;
}
// ---------------------------------------------------------------------------
// 解析 XML , 儲存到 TreeRoot 中
String __fastcall CCBXML::ParseXML()
{
_di_IXMLNode Node;
Document->Active = true;
String sHtml = u"";
// 讀取缺字
_di_IXMLNode NodeGaijis = Document->DocumentElement->ChildNodes->Nodes["teiHeader"]->ChildNodes->Nodes["encodingDesc"]->ChildNodes->Nodes["charDecl"];
ReadGaiji(NodeGaijis); // 讀取缺字
// 檢查是不是 AI 標點
_di_IXMLNode NodeEdition = Document->DocumentElement->ChildNodes->Nodes["teiHeader"]->ChildNodes->Nodes["encodingDesc"]->ChildNodes->Nodes["editorialDecl"]->ChildNodes->Nodes["punctuation"];
String sEdition = NodeEdition->GetXML();
if(sEdition.Pos0(u"AI 標點")>=0) {
IsAIPunc = true;
sHtml += u"<div><span id='AIPuncRemind'>【案:此資料標點由AI標點引擎提供,可從「設定/經文格式」選擇是否呈現。】</span></div>\n";
}
// 遍歷 XML
Node = Document->DocumentElement->ChildNodes->Nodes["text"];
if (Node->ChildNodes->Count == 0)
TDialogService::ShowMessage(u"錯誤:找不到 text 標記。");
else
sHtml += ParseNode(Node);
return sHtml;
}
// ---------------------------------------------------------------------------
// 解析 XML Node
String __fastcall CCBXML::ParseNode(_di_IXMLNode Node)
{
String sHtml = u"";
#ifdef _Windows
TNodeType nodetype = Node->NodeType;
#else
Xml::Internal::Omnixml::TNodeType nodetype = Node->NodeType;
#endif
/* Node Type
1 ELEMENT_NODE
2 ATTRIBUTE_NODE
3 TEXT_NODE
4 CDATA_SECTION_NODE
5 ENTITY_REFERENCE_NODE
6 ENTITY_NODE
7 PROCESSING_INSTRUCTION_NODE
8 COMMENT_NODE
9 DOCUMENT_NODE
10 DOCUMENT_TYPE_NODE
11 DOCUMENT_FRAGMENT_NODE
12 NOTATION_NODE
*/
if (nodetype == 1)
{
// 一般節點
String sTagName = Node->NodeName;
if (sTagName == u"anchor") sHtml = tag_anchor(Node);
else if (sTagName == u"app") sHtml = tag_app(Node);
else if (sTagName == u"biblScope") sHtml = tag_biblScope(Node);
else if (sTagName == u"byline") sHtml = tag_byline(Node);
else if (sTagName == u"caesura") sHtml = tag_caesura(Node);
else if (sTagName == u"cell") sHtml = tag_cell(Node);
else if (sTagName == u"cb:div") sHtml = tag_div(Node);
else if (sTagName == u"cb:docNumber") sHtml = tag_docNumber(Node);
else if (sTagName == u"entry") sHtml = tag_entry(Node);
else if (sTagName == u"figDesc") sHtml = tag_figdesc(Node);
else if (sTagName == u"foreign") sHtml = tag_foreign(Node);
else if (sTagName == u"form") sHtml = tag_form(Node);
else if (sTagName == u"formula") sHtml = tag_formula(Node);
else if (sTagName == u"g") sHtml = tag_g(Node);
else if (sTagName == u"graphic") sHtml = tag_graphic(Node);
else if (sTagName == u"head") sHtml = tag_head(Node);
else if (sTagName == u"hi") sHtml = tag_formula(Node); // 二標記處理法相同
else if (sTagName == u"item") sHtml = tag_item(Node);
else if (sTagName == u"cb:juan") sHtml = tag_juan(Node);
else if (sTagName == u"l") sHtml = tag_l(Node);
else if (sTagName == u"lb") sHtml = tag_lb(Node);
else if (sTagName == u"lem") sHtml = tag_lem(Node);
else if (sTagName == u"lg") sHtml = tag_lg(Node);
else if (sTagName == u"list") sHtml = tag_list(Node);
else if (sTagName == u"cb:mulu") sHtml = tag_mulu(Node);
else if (sTagName == u"note") sHtml = tag_note(Node);
else if (sTagName == u"p") sHtml = tag_p(Node);
else if (sTagName == u"pb") sHtml = tag_pb(Node);
else if (sTagName == u"rdg") sHtml = tag_rdg(Node);
else if (sTagName == u"ref") sHtml = tag_ref(Node);
else if (sTagName == u"row") sHtml = tag_row(Node);
else if (sTagName == u"seg") sHtml = tag_seg(Node);
else if (sTagName == u"cb:sg") sHtml = tag_sg(Node);
else if (sTagName == u"space") sHtml = tag_space(Node);
else if (sTagName == u"cb:t") sHtml = tag_t(Node);
else if (sTagName == u"table") sHtml = tag_table(Node);
else if (sTagName == u"term") sHtml = tag_term(Node);
else if (sTagName == u"text") sHtml = tag_term(Node); // text 和 term 處理法相同
else if (sTagName == u"trailer") sHtml = tag_trailer(Node);
else if (sTagName == u"cb:tt") sHtml = tag_tt(Node);
else if (sTagName == u"unclear") sHtml = tag_unclear(Node);
else sHtml = tag_default(Node);
}
else if (nodetype == 3)
{
// 文字節點
sHtml = Node->Text;
sHtml = StringReplace(sHtml, "\n", "", TReplaceFlags() << rfReplaceAll);
sHtml = StringReplace(sHtml, "\t", "", TReplaceFlags() << rfReplaceAll);
// xml 有 & <, 轉成 html 預設是 & < , CBR 程式讓 html 依然保持 & <
// 實際呈現會自動轉成 & <, 但引用複製需要處理校註的部份
// 所以只有 note_text 要處理 & < , text 不用處理
sHtml = StringReplace(sHtml, "&", "&", TReplaceFlags() << rfReplaceAll);
sHtml = StringReplace(sHtml, "<", "<", TReplaceFlags() << rfReplaceAll);
// 移除標點
if((Setting->ShowPunc == false) ||
(Setting->NoShowLgPunc == true && InLg == true) ||
(Setting->NoShowAIPunc == true && IsAIPunc == true))
{
// 校勘中不用移除標點
if(!InNoteOrig && !InNoteMod &&!InNoteAdd)
{
sHtml = RemovePunc(sHtml);
}
}
}
return sHtml;
}
// ---------------------------------------------------------------------------
// 移除標點
String __fastcall CCBXML::RemovePunc(String sHtml)
{
sHtml = StringReplace(sHtml, u".", "", TReplaceFlags() << rfReplaceAll);
sHtml = StringReplace(sHtml, u"、", "", TReplaceFlags() << rfReplaceAll);
sHtml = StringReplace(sHtml, u",", "", TReplaceFlags() << rfReplaceAll);
sHtml = StringReplace(sHtml, u":", "", TReplaceFlags() << rfReplaceAll);
sHtml = StringReplace(sHtml, u";", "", TReplaceFlags() << rfReplaceAll);
sHtml = StringReplace(sHtml, u"。", "", TReplaceFlags() << rfReplaceAll);
sHtml = StringReplace(sHtml, u"?", "", TReplaceFlags() << rfReplaceAll);
sHtml = StringReplace(sHtml, u"!", "", TReplaceFlags() << rfReplaceAll);
sHtml = StringReplace(sHtml, u"—", "", TReplaceFlags() << rfReplaceAll);
sHtml = StringReplace(sHtml, u"…", "", TReplaceFlags() << rfReplaceAll);
sHtml = StringReplace(sHtml, u"「", "", TReplaceFlags() << rfReplaceAll);
sHtml = StringReplace(sHtml, u"」", "", TReplaceFlags() << rfReplaceAll);
sHtml = StringReplace(sHtml, u"『", "", TReplaceFlags() << rfReplaceAll);
sHtml = StringReplace(sHtml, u"』", "", TReplaceFlags() << rfReplaceAll);
sHtml = StringReplace(sHtml, u"〈", "", TReplaceFlags() << rfReplaceAll);
sHtml = StringReplace(sHtml, u"〉", "", TReplaceFlags() << rfReplaceAll);
sHtml = StringReplace(sHtml, u"《", "", TReplaceFlags() << rfReplaceAll);
sHtml = StringReplace(sHtml, u"》", "", TReplaceFlags() << rfReplaceAll);
sHtml = StringReplace(sHtml, u"“", "", TReplaceFlags() << rfReplaceAll);
sHtml = StringReplace(sHtml, u"”", "", TReplaceFlags() << rfReplaceAll);
sHtml = StringReplace(sHtml, u"(", "", TReplaceFlags() << rfReplaceAll);
sHtml = StringReplace(sHtml, u")", "", TReplaceFlags() << rfReplaceAll);
sHtml = StringReplace(sHtml, u"【", "", TReplaceFlags() << rfReplaceAll);
sHtml = StringReplace(sHtml, u"】", "", TReplaceFlags() << rfReplaceAll);
sHtml = StringReplace(sHtml, u"〔", "", TReplaceFlags() << rfReplaceAll);
sHtml = StringReplace(sHtml, u"〕", "", TReplaceFlags() << rfReplaceAll);
return sHtml;
}
// ---------------------------------------------------------------------------
// 解析 XML Child
String __fastcall CCBXML::parseChild(_di_IXMLNode Node)
{
String sHtml = u"";
for (int i = 0; i < Node->ChildNodes->Count; i++)
{
_di_IXMLNode node = Node->ChildNodes->Get(i);
sHtml += ParseNode(node);
}
return sHtml;
}
// ---------------------------------------------------------------------------
String __fastcall CCBXML::tag_default(_di_IXMLNode Node)
{
String sHtml = u"";
//String sXXX = GetAttr(Node, u"xxx");
sHtml += parseChild(Node); // 處理內容
return sHtml;
}
// ---------------------------------------------------------------------------
// 舊版 CBReader 有很多種 anchor , 現在剩二種
// 1. 沒有處理的星號
// <anchor xml:id="fxT01p0009a09"/>
// 2. 雙圈 ◎
// <anchor type="circle"/>
String __fastcall CCBXML::tag_anchor(_di_IXMLNode Node)
{
String sHtml = u"";
String sXMLId = GetAttr(Node, u"xml:id");
String sType = GetAttr(Node, u"type");
// 沒有處理的星號 <anchor xml:id="fxT01p0009a09"/>
if(sXMLId.SubString0(0,2) == u"fx")
{
sHtml += u"<span class='note_star'>[*]</span>";
}
// 雙圈 ◎ <anchor type="circle"/>
if(sType == u"circle")
{
sHtml += u"◎";
}
//sHtml = parseChild(Node); // 處理內容
return sHtml;
}
// ---------------------------------------------------------------------------
// 校勘中的校勘 , 這個要處理 ????
// <app from="#beg0101004" to="#end0101004">
// <lem wit="#wit1">得法眼淨。猶如淨潔白
// <app n="0101005">
// <lem wit="#wit1">疊</lem>
// <rdg resp="#resp1" wit="#wit2 #wit3 #wit4"><g ref="#CB00626">?</g></rdg>
// </app>
// </lem>
// <rdg resp="#resp1" wit="#wit5">諸法法眼生譬如新衣</rdg>
// </app>
// tt 中的校勘
// <cb:tt type="app" from="#beg0001026" to="#end0001026">
// <cb:t resp="#resp1" xml:lang="zh"><app n="0001026"><lem wit="#wit1">拘樓孫</lem><rdg resp="#resp1" wit="#wit2 #wit3 #wit4">拘留孫</rdg></app></cb:t>
// <cb:t resp="#resp1" xml:lang="pi" place="foot">Kakusandha.</cb:t>
// </cb:tt>
// 星號
// <app from="#beg_1" to="#end_1" corresp="#0001004"><lem wit="#wit1">辨</lem><rdg resp="#resp1" wit="#wit2">辯</rdg></app>
// ????? lem 裡面要有 note 及 lb 才行. note 是 app 包 app 用的
// 以上是舊版資料, 待研究...
/*
<note n="0001002" resp="Taisho" type="orig" place="foot text">〔長安〕-【宋】</note>
<note n="0001002" resp="CBETA" type="mod">長安【大】,〔-〕【宋】</note>
<app n="0001002">
<lem wit="【大】">長安</lem>
<rdg resp="Taisho" wit="【宋】"><space quantity="0"/></rdg>
</app>
【標準校註】
XML 原始標記 : <app n="0001002">
HTML 經文轉成 : <span id="note_app_0001002" class="note_app">
HTML 校註轉成 : <div id="txt_note_app_0001002"> ... </div>
【CBETA 自訂校註】
XML 原始標記 : <app n="0001b0201">
HTML 經文轉成 : <span id="note_app_A1" class="note_app">
HTML 校註轉成 : <div id="txt_note_app_A1"> ... </div>
【星號】
XML 原始標記 :
<app type="star" corresp="#0001004">
<lem wit="【大】">辨</lem>
<rdg resp="Taisho" wit="【宋】">辯</rdg>
</app>
HTML 經文轉成 :
<a id="note_star_0001004-1" class="note_star" href="" onclick="return false;">[*]</a>
<span id="note_app_0001004-1" class="note_app">....</span>
HTML 校註轉成 :
<div id="txt_note_app_0001004-1">
<div type="orig">辨</div>
<div type="lem" data-wit="【大】">辨</div>
<div type="rdg" data-wit="【宋】">辯</div>
</div>
【移除的星號】
XML 原始標記 : T01n0001_003.xml
<note n="0021b2101" resp="CBETA" type="add">琉璃【CB】【麗-CB】,瑠璃【大】,流離【聖】</note>
<app type="star_removed" corresp="#0021019">
<lem resp="CBETA.say" wit="【CB】【麗-CB】">琉璃...</lem>
<rdg wit="【大】">瑠璃</rdg>
<rdg resp="Taisho" wit="【聖】">流離</rdg>
</app>
HTML 經文轉成 :
<a id="note_add_A1" class="note_add" href="" onclick="return false;">[A1]</a>
<a id="note_star_0021019-1" class="note_star_removed" href="" onclick="return false;">[*]</a>
<span id="note_app_0021019-1" class="note_app">琉璃</span>
HTML 校註轉成 :
<div id="txt_note_add_A1">琉璃【CB】【麗-CB】,瑠璃【大】,流離【聖】</div>
<div id="txt_note_app_0021019-1">
<div type="orig">【大正為趣】</div>
<div type="lem" data-wit="【CB】">【CB為越】</span></div>
<div type="rdg" data-wit="【大】">趣</div>
<div type="rdg" data-wit="【宋】【元】【明】">越</div>
</div>
*/
String __fastcall CCBXML::tag_app(_di_IXMLNode Node)
{
String sHtml = u"";
String sId = GetAttr(Node, u"n");
String sType = GetAttr(Node, u"type");
if(sId != u"" && mpNoteAddNum.count(sId)>0)
{
// 表示是 <note type="add"> 的 CBETA 自訂 <app>
// 取回流水號, 把 Id 改成 Axx
String sIdNum = String(Get_Add_IdNum(sId));
sId = u"A" + sIdNum;
}
if(sType == u"star")
{
// 星號
String sId = GetAttr(Node, u"corresp");
sId.Delete0(0,1); // remove '#'
int iStar = 1;
if(mpNoteStarNum.count(sId)>0)
iStar = mpNoteStarNum[sId] + 1; // 星號加 1
else
iStar = 1; // 第一個星號
mpNoteStarNum[sId] = iStar;
sId += u"-" + String(iStar);
String sDisplay = u""; // 呈現的情況
if(Setting->ShowCollation == false) sDisplay = u"none";
else if(Setting->CollationType == ctOrigCollation) sDisplay = u"inline";
else if(Setting->CollationType == ctCBETACollation) sDisplay = u"inline";
// 底下幾個順序不要錯亂, 尤其二個 HTMLCollation 要夾著 parseChild(Node)
HTMLCollation += u"<div id='txt_note_app_" + sId + u"'>\n";
sHtml += u"<a id='note_star_" + sId + u"' class='note_star' "
+ u"href='' style='display:" + sDisplay
+ u"' onclick='return ShowCollation($(this));'>[*]</a>";
sHtml += u"<span id='note_app_" + sId + u"' class='note_app'>"
+ parseChild(Node) // 處理內容, 裡面的資料也會存在 HTMLCollation 中
+ u"</span>";
HTMLCollation += u"</div>\n";
}
else if(sType == u"star_removed")
{
// 移除的星號
String sId = GetAttr(Node, u"corresp");
sId.Delete0(0,1); // remove '#'
int iStar = 1;
if(mpNoteStarNum.count(sId)>0)
iStar = mpNoteStarNum[sId] + 1; // 星號加 1
else
iStar = 1; // 第一個星號
mpNoteStarNum[sId] = iStar;
sId += u"-" + String(iStar);
String sDisplay = u""; // 呈現的情況
if(Setting->ShowCollation == false) sDisplay = u"none";
else if(Setting->CollationType == ctOrigCollation) sDisplay = u"inline";
else if(Setting->CollationType == ctCBETACollation) sDisplay = u"none";
// 底下幾個順序不要錯亂, 尤其二個 HTMLCollation 要夾著 parseChild(Node)
HTMLCollation += u"<div id='txt_note_app_" + sId + "'>\n";
sHtml += u"<a id='note_star_" + sId + u"' class='note_star_removed' "
+ u"href='' style='display:" + sDisplay
+ u"' onclick='return ShowCollation($(this));'>[*]</a>";
sHtml += u"<span id='note_app_" + sId + u"' class='note_app'>"
+ parseChild(Node) // 處理內容, 裡面的資料也會存在 HTMLCollation 中
+ u"</span>";
HTMLCollation += u"</div>\n";
}
else
{
// 這裡要注意順序
// 1. 先處理校註區的 <div id="txt_note_app_xxxx">
// 2. 進行 parseChild , 這裡面會處理校註區 lem ,rdg 的內容
// 3. 再加上校註區的 </div>
// 底下幾個順序不要錯亂, 尤其二個 HTMLCollation 要夾著 parseChild(Node)
HTMLCollation += u"<div id='txt_note_app_" + sId + "'>\n";
sHtml += u"<span id='note_app_" + sId + "' class='note_app'>"
+ parseChild(Node) // 處理內容, 裡面的資料也會存在 HTMLCollation 中
+ u"</span>";
HTMLCollation += u"</div>\n";
}
return sHtml;
}
// ---------------------------------------------------------------------------
// <biblScope n="41" unit="卷" rend="small">
String __fastcall CCBXML::tag_biblScope(_di_IXMLNode Node)
{
String sHtml = u"";
String sRend = GetAttr(Node, u"rend");
String sStyle = GetAttr(Node, u"style");
CRendAttr * myRend = new CRendAttr(sRend);
CStyleAttr * myStyle = new CStyleAttr(sStyle);
if(myRend->NewStyle != u"" || myStyle->NewStyle != u"" )
{
sHtml += u"<span style='";
sHtml += myRend->NewStyle;
sHtml += myStyle->NewStyle;
sHtml += "'>";
}
sHtml += parseChild(Node); // 處理內容
if(myRend->NewStyle != u"" || myStyle->NewStyle != u"" )
{
sHtml += "</span>";
}
delete myRend;
delete myStyle;
return sHtml;
}
// ---------------------------------------------------------------------------
// <byline cb:type="Translator">
String __fastcall CCBXML::tag_byline(_di_IXMLNode Node)
{
String sHtml = u"";
if(ListCount == 0) InByline = true; // ???? 和底下 InByline 不太一樣
String sRend = GetAttr(Node, u"rend");
String sStyle = GetAttr(Node, u"style");
CRendAttr * myRend = new CRendAttr(sRend);
CStyleAttr * myStyle = new CStyleAttr(sStyle);
String sNewStyle = myRend->NewStyle + myStyle->NewStyle;
sHtml += parseChild(Node); // 處理內容
if(sNewStyle != "")
{
sHtml = u"<span style='" + sNewStyle + "'>" + sHtml + "</span>";
}
if(ListCount)
sHtml = u"<span class='byline'> " + sHtml + u"</span>";
else
{
InByline = false;
if(Setting->ShowLineFormat)
sHtml = u"<span class='line_space'> </span>"
u"<span class='byline' data-tagname='p'>" + sHtml + u"</span>";
else
sHtml = u"<span class='line_space' style='display:none'> </span>"
u"<p class='byline' data-tagname='p'>" + sHtml + u"</p>";
}
delete myRend;
delete myStyle;
return sHtml;
}
// ---------------------------------------------------------------------------
// 2020/06 偈頌改成 <l>...<caesura/>...<caesura/>...</l>
// <caesura/> , <caesura style="text-indent:1em;"/>
// 預設空二格, 有 style 依 style 空格
// 不依原書處理時,<l> 負責換行, <caesura> 為句中間隔
String __fastcall CCBXML::tag_caesura(_di_IXMLNode Node)
{
String sHtml = u"";
String sLTextIndent = ""; // caesura 要空的格
int iTextIndent = 0;
String sStyle = GetAttr(Node, u"style");
CStyleAttr * myStyle = new CStyleAttr(sStyle);
if(myStyle->HasTextIndent)
{
iTextIndent = myStyle->TextIndent;
}
else
{
iTextIndent = 2;
}
sLTextIndent += String::StringOfChar(u' ', iTextIndent);
// l 本身要空的格
sHtml += sLTextIndent;
// -----------------------------------
// sHtml += parseChild(Node); // 處理內容
// -----------------------------------
delete myStyle;
return sHtml;
}
// ---------------------------------------------------------------------------
String __fastcall CCBXML::tag_cell(_di_IXMLNode Node)
{
String sHtml = u"";
String sCols = GetAttr(Node, u"cols");
String sRows = GetAttr(Node, u"rows");
String sRend = GetAttr(Node, u"rend");
String sStyle = GetAttr(Node, u"style");
CRendAttr * myRend = new CRendAttr(sRend);
CStyleAttr * myStyle = new CStyleAttr(sStyle);
String sNewStyle = myRend->NewStyle + myStyle->NewStyle;
String sNewClass = myRend->NewClass + myStyle->NewStyle;
if(sNewStyle != u"")
sNewStyle = " style='" + sNewStyle + "'";
if(sNewClass != u"")
sNewClass = " class='" + sNewClass + "'";
CellNum++; // cell 格式數量累加
String sColspan = u"";
String sRowspan = u"";
int iColspan = 0;
if(sCols != u"")
{
iColspan = sCols.ToIntDef(1)-1;
sColspan = u" colspan = '" + sCols + u"'";
}
if(sRows != u"")
{
sRowspan = u" rowspan = '" + sRows + u"'";
}
if(Setting->ShowLineFormat)
sHtml += u"<span";
else
sHtml += u"<td";
sHtml += sColspan;
sHtml += sRowspan;
sHtml += sNewStyle;
sHtml += sNewClass;
sHtml += u" data-tagname='td'>";
// 第一個空一格, 其它空三格
// 因為第一個 <cell> 之後通常會有 <lb>,所以空格要在 <lb> 之後
// 原本是
// ...<span class='line_space'> </span>...
// ...<span class='linehead'>ZW01na003_p0027a11║</span>...
// 換成
// ...<span class='linehead'>ZW01na003_p0027a11║</span>
// <span class='line_space'> </span>...
String sCellSpace = "";
if(Setting->ShowLineFormat) {
sCellSpace += u"<span class='line_space'>";
} else {
sCellSpace += u"<span class='line_space' style='display:none'>";
}
if(CellNum == 1) {
sCellSpace += u" ";
} else {
sCellSpace += u" ";
}
// 若 class="pl-2",就要加上 2 個空格
int iPos = sNewClass.Pos0("pl-");
if(iPos >= 0) {
String sPlNum = sNewClass.SubString0(iPos+3,2); // 先取二個
if(sPlNum.SubString0(1,1) == u" ") sPlNum = sPlNum.Delete0(1,1);
int iPlNum = sPlNum.ToIntDef(0);
sCellSpace += String::StringOfChar(u' ', iPlNum);
}
for(int i=0; i<OtherColspan; i++)
sCellSpace += u" "; //印出前一個 cell 應有的空格
OtherColspan = iColspan;
sCellSpace += u"</span>";
String sChild = parseChild(Node); // 處理內容
// 第一個 cell 因為會在前一行行尾,所以要把 cell 空格移到行首後面
if(CellNum == 1) {
String sHead = "";
String sTail = sChild;
int iPos = sTail.Pos0(u"║</span>");
while(iPos >= 0) {
// sHead = .....║</span>
sHead += sTail.SubString0(0,iPos+8);
// sTail = 剩下的
sTail = sTail.SubString0(iPos+8,sTail.Length()-iPos-8);
iPos = sTail.Pos0(u"║</span>");
}
sChild = sHead + sCellSpace + sTail;
sCellSpace = "";
}
sHtml += sCellSpace + sChild;
if(Setting->ShowLineFormat)
sHtml += u"</span>";
else
sHtml += u"</td>";
delete myRend;
delete myStyle;
return sHtml;
}
// ---------------------------------------------------------------------------
// 附文: <cb:div type="w"><p xml:id="pT02p0029b2201"><anchor xml:id="nkr_note_orig_0029009" n="0029009"/>
// 序: <cb:div type="xu"><cb:mulu level="1" type="序">序</cb:mulu><anchor xml:id="nkr_note_orig_0001001" n="0001001"/><head><title>長阿含經</title>序</head>
String __fastcall CCBXML::tag_div(_di_IXMLNode Node)
{
String sHtml = u"";
String sType = GetAttr(Node, u"type");
String sRend = GetAttr(Node, u"rend");
String sStyle = GetAttr(Node, u"style");
CRendAttr * myRend = new CRendAttr(sRend);
CStyleAttr * myStyle = new CStyleAttr(sStyle);
String sNewStyle = myRend->NewStyle + myStyle->NewStyle;
if(sNewStyle != u"")
sNewStyle = " style='" + sNewStyle + "'";
DivCount++;
if(sType != u"")
{
DivType[DivCount] = sType.LowerCase(); // 都變成小寫
}
if(DivType[DivCount] == u"w") // 附文
{
FuWenCount++;
if(Setting->ShowLineFormat)
sHtml += u"<span class='w' data-tagname='div'" + sNewStyle + ">";
else
// 要用 div , 才不會有 span 包 p 的困境
sHtml += u"<div class='w' data-tagname='div'" + sNewStyle + ">";
if(FuWenCount == 1)
{
if(Setting->ShowLineFormat)
sHtml += u"<span data-margin-left='1em' data-tagname='div'>"
u"<span class='line_space'> </span>";
else
sHtml += u"<div data-margin-left='1em' style='margin-left: 1em' data-tagname='div'>"
u"<span class='line_space' style='display:none'> </span>";
}
}
else if (DivType[DivCount] == u"xu") // 序文
{
if(Setting->ShowLineFormat)
sHtml += u"<span class='xu' data-tagname='div'" + sNewStyle + ">";
else
// 要用 div , 才不會有 span 包 p 的困境
sHtml += u"<div class='xu' data-tagname='div'" + sNewStyle + ">";
}
else if (DivType[DivCount] == u"orig") // 原書資料
{
if(Setting->ShowLineFormat)
sHtml += u"<span class='div-orig' data-tagname='div'" + sNewStyle + ">";
else
// 要用 div , 才不會有 span 包 p 的困境
sHtml += u"<div class='div-orig' data-tagname='div'" + sNewStyle + ">";
}
else