-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathversiculo.pas
More file actions
1758 lines (1547 loc) · 46.2 KB
/
Copy pathversiculo.pas
File metadata and controls
1758 lines (1547 loc) · 46.2 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
unit Versiculo;
{$mode objfpc}{$H+}
{TODO -cObrigatório: Rever algoritmo de associação/desassociação }
{$DEFINE DEBUG}
interface
uses
Classes, SysUtils, StrUtils, ExtCtrls, StdCtrls, Controls, Graphics,
ONTTokenizer, Syntagm, Forms, LCLType, Math, LCLProc, Dialogs, LazUTF8,
ONTParser, dbugintf, Menus, Clipbrd, PCRE;
type
TVersiculo = class;
TOnSintagmaEvent = procedure (Sender: TSyntagm) of object;
TOnAlterarVersiculoEvent = procedure () of object;
TOnExportTextEvent = procedure (Sender: TVersiculo) of object;
TStrongsCountMode = (scNone, scCountWords, scCountStrongs);
{ TVersiculo }
TVersiculo = class
private
FRightToLeft: Boolean;
{ Private declarations }
FMostrarDicas: boolean;
FOnAlterarVersiculo: TOnAlterarVersiculoEvent;
//FStrongMorfoComoChave: boolean;
FVersiculoRef: TVersiculo;
FSintagmas: TSyntagmList;
FStrongCount: TSyntagm;
FSelecao: TSyntagmList;
FModificado: boolean;
FXMLModificado: boolean;
FPanel: TScrollBox;
FEdit: TEdit;
FAtivo: boolean;
FDestruindo: boolean;
FExibirErro: boolean;
FPalavrasComStrongEmNegrito: boolean;
FStrongsCountMode: TStrongsCountMode;
//FFontePadrao: TFont;
FCorAssociado: TColor;
FCorDesassociado: TColor;
FOnSintagmaClick: TOnSintagmaEvent;
FOnSintagmaMouseEnter: TOnSintagmaEvent;
FOnSintagmaMouseLeave: TOnSintagmaEvent;
FOnExportText: TOnExportTextEvent;
FXML: string;
FONTParser: TONTParser;
FSyntagmPopupMenu: TPopupMenu;
FVersePopupMenu: TPopupMenu;
FRTLMenuItem: TMenuItem;
FFixWrongFiTag: IRegex;
FReadOnly: Boolean;
{ determines the auto select behaviour on right-click association }
FNextAutoSelectWordMustHaveStrongMorpho: Boolean;
//FOnNovaAssociacao: TOnAssociacaoEvent;
//FOnRemoverAssociacao: TOnAssociacaoEvent;
function GetAndamentoAssociacao: Single;
function GetAtivo: boolean;
function GetFonte: TFont;
function GetPares: string;
function GetTextoSimples: string;
procedure SetAtivo(const AValue: boolean);
procedure SetFonte(const AValue: TFont);
procedure SetModificado(const AValue: boolean);
procedure SetRightToLeft(AValue: Boolean);
procedure SetStrongsCountMode(AValue: TStrongsCountMode);
procedure SetPalavrasComStrongEmNegrito(AValue: boolean);
procedure SetPares(const AValue: string);
procedure SetTexto(_XML: string);
function GetTexto: string;
procedure SetVersiculoPar(Par: TVersiculo);
procedure SelecionarListaSintagmas(lst: string);
procedure EditKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
procedure EditExit(Sender: TObject);
procedure EditConfirm;
procedure AtualizarXMLInterno;
procedure AtualizarStrongCount;
function GetTokens: string;
procedure OnCopySyntagmTags(Sender: TObject);
procedure OnPasteSyntagmTags(Sender: TObject);
procedure OnSaveTextToFile(Sender: TObject);
procedure OnCopyTokensToClipboard(Sender: TObject);
procedure OnCopyInterlinearVerseToClipboard(Sender: TObject);
procedure OnCopyXMLToClipboard(Sender: TObject);
procedure OnRightToLeft(Sender: TObject);
procedure OnVerseMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
procedure OnResize(Sender: TObject);
procedure OnMouseWheel(Sender: TObject; Shift: TShiftState;
WheelDelta: Integer; MousePos: TPoint; var Handled: Boolean);
procedure InitSyntagmPopupMenu;
procedure InitVersePopupMenu;
procedure OnCopyAssociationsJSONToClipboard(Sender: TObject);
procedure OnCopySintagmasAsJSON(Sender: TObject);
function GetAssociationsJSON: string;
protected
{ Protected declarations }
public
{ Public declarations }
constructor Criar;
constructor Criar(TheOwner: TScrollBox);
destructor Destruir;
procedure LimparSintagmas;
procedure AssociarSintagmas;
procedure LimparSelecao;
procedure DesassociarPares;
procedure LimparAssociacoes;
procedure Renderizar;
procedure RenderizarStrongCount;
procedure ClearStrongCount;
procedure OrganizarSintagmas;
procedure SelecionarSintagmas(list: TSyntagmList);
procedure AlterarTexto(_XML: string);
function GetListaPares(tipo: TPairsListType): TStringList;
procedure OnSintagmaPopupMenu(s: TSyntagm);
procedure MostrarTags;
procedure OcultarTags;
procedure EnableStrongHighlight(strong: string);
procedure DisableStrongHighlight;
function GetTheWordInterlinearLine: string;
function GetMySwordInterlinearLine: string;
function GetLinhaONT: string;
function GetLinhaONT(morfo: boolean; autoitalico: boolean; strongsreutilizados: boolean;
strongsnaotraduzidos: boolean): string;
property VersiculoPar: TVersiculo read FVersiculoRef write SetVersiculoPar;
property XML: string read FXML;
property Texto: string read GetTexto write SetTexto;
property Pares: string read GetPares write SetPares;
property Painel: TScrollBox read FPanel write FPanel;
property Sintagmas: TSyntagmList read FSintagmas;
property Selecao: TSyntagmList read FSelecao write FSelecao;
property Modificado: boolean read FModificado write SetModificado;
property XMLModificado: boolean read FXMLModificado write FXMLModificado;
property OnClick: TOnSintagmaEvent read FOnSintagmaClick write FOnSintagmaClick;
property OnMouseEnter: TOnSintagmaEvent read FOnSintagmaMouseEnter write FOnSintagmaMouseEnter;
property OnMouseLeave: TOnSintagmaEvent read FOnSintagmaMouseLeave write FOnSintagmaMouseLeave;
property OnExportText: TOnExportTextEvent read FOnExportText write FOnExportText;
property OnAlterarVersiculo: TOnAlterarVersiculoEvent read FOnAlterarVersiculo write FOnAlterarVersiculo;
//property OnNovaAssociacao: TOnAssociacaoEvent read FOnNovaAssociacao write FOnNovaAssociacao;
//property OnRemoverAssociacao: TOnAssociacaoEvent read FOnRemoverAssociacao write FOnRemoverAssociacao;
property MostrarDicas: boolean read FMostrarDicas write FMostrarDicas;
property Ativo: boolean read GetAtivo write SetAtivo;
property TextoSimples: string read GetTextoSimples;
//property LinhaONT: string read GetLinhaONT;
//property LinhaInterlinear: string read GetLinhaInterlinear;
property CorAssociado: TColor read FCorAssociado write FCorAssociado;
property CorDesassociado: TColor read FCorDesassociado write FCorDesassociado;
//property StrongMorfoComoChave: boolean read FStrongMorfoComoChave write FStrongMorfoComoChave;
property AndamentoAssociacao: Single read GetAndamentoAssociacao;
property Fonte: TFont read GetFonte write SetFonte;
property Edit: TEdit read FEdit write FEdit;
property PalavrasComStrongEmNegrito: boolean read FPalavrasComStrongEmNegrito write SetPalavrasComStrongEmNegrito;
property StrongsCountMode: TStrongsCountMode read FStrongsCountMode write SetStrongsCountMode;
property DebugTokens: string read GetTokens;
property ReadOnly: Boolean read FReadOnly write FReadOnly default False;
property RightToLeft: Boolean read FRightToLeft write SetRightToLeft default False;
property NextAutoSelectWordMustHaveStrongMorpho: boolean read FNextAutoSelectWordMustHaveStrongMorpho write FNextAutoSelectWordMustHaveStrongMorpho;
published
{ Published declarations }
end;
resourcestring
SCopyTags ='&Copy tags';
SPasteAllTags = 'Paste &all tags';
SPasteStrongTags = '&Paste &Strong''s tags';
SPasteMorphoTags = 'Paste &morphology tags';
SSaveToFile = '&Save text to file...';
SRightToLeft = 'Right to left text';
SCopyTokensToClipboard = 'Copy &tokens to clipboard';
SCopyInterlinearVerseToClipboard = 'Copy &interlinear verse to clipboard';
SCopyXMLToClipboard = 'Copy association &XML to clipboard';
SCopyAssociationsJSONToClipboard = 'Copy association &JSON to clipboard';
implementation
uses
TypInfo; // added TypInfo
const
MarginWidth = 10; // text's distance from the margin
var
SintagmaClipboard: TSyntagm;
function CompareIndexes(List: TStringList; Index1, Index2: Integer): Integer;
begin
result := List[Index1].ToInteger - List[Index2].ToInteger;
end;
{ TVersiculo }
constructor TVersiculo.Criar(TheOwner : TScrollBox);
begin
FPanel := TheOwner;
FAtivo := assigned(FPanel);
if (FAtivo) then
begin
FPanel.Color := clWindow;
FPanel.Caption := '';
InitSyntagmPopupMenu;
InitVersePopupMenu;
FEdit := TEdit.Create(FPanel);
FEdit.Visible := false;
FEdit.AutoSize := false;
FEdit.OnKeyDown := @EditKeyDown;
FEdit.OnExit := @EditExit;
FPanel.InsertControl(FEdit);
FPanel.OnMouseDown := @OnVerseMouseDown;
FPanel.OnResize := @OnResize;
FPanel.OnMouseWheel := @OnMouseWheel;
end;
FStrongCount := nil;
FStrongsCountMode := scNone;
FVersiculoRef := nil;
FOnSintagmaClick := nil;
FOnSintagmaMouseEnter := nil;
FOnSintagmaMouseLeave := nil;
FModificado := false;
FXMLModificado := false;
FSelecao := TSyntagmList.Create;
FMostrarDicas := false;
FNextAutoSelectWordMustHaveStrongMorpho := true;
//FFontePadrao := TFont.Create;
//FFontePadrao.Assign(TheOwner.Font);
FCorAssociado := clWindowText;
FCorDesassociado := $A3A3A3;//clGrayText;
//FStrongMorfoComoChave := false;
FDestruindo := false;
FONTParser := TONTParser.Create;
{ regex to fix cases in which a <Fi> tag ends up misplaced }
FFixWrongFiTag := RegexCreate('((?:<W[THG][^>]+>)+)(<Fi>)', [rcoUTF8]);
end;
destructor TVersiculo.Destruir;
begin
FDestruindo := true;
LimparSintagmas;
FSintagmas.Free;
FSelecao.Destroy;
if assigned(FPanel) then
begin
FEdit.Free;
FSyntagmPopupMenu.Free;
FVersePopupMenu.Free;
FPanel.OnMouseDown := nil;
FPanel.OnResize := nil;
FPanel.OnMouseWheel := nil;
end;
FONTParser.Destroy;
//FFontePadrao.Free;
end;
procedure TVersiculo.LimparSintagmas;
var
s: TSyntagm;
begin
if assigned(FSintagmas) then
begin
if FAtivo then
FPanel.DisableAutoSizing;
for s in FSintagmas do
s.Destroy;
ClearStrongCount;
FSintagmas.Clear;
if FAtivo then
FPanel.EnableAutoSizing;
end;
FSelecao.Clear;
end;
procedure TVersiculo.AssociarSintagmas;
var
s: TSyntagm;
begin
if not Assigned(VersiculoPar) then
exit;
for s in Selecao do
begin
with s do
begin
Pairs.Clear;
Pairs.AddList(VersiculoPar.Selecao);
IsAssociated:=true;
Siblings.Clear;
Siblings.AddList(Selecao);
Siblings.Remove(s);
end;
end;
for s in VersiculoPar.Selecao do
begin
with s do
begin
Pairs.Clear;
Pairs.AddList(Selecao);
IsAssociated:=true;
Siblings.Clear;
Siblings.AddList(VersiculoPar.Selecao);
Siblings.Remove(s);
end;
end;
Modificado := true;
VersiculoPar.Modificado := true;
end;
procedure TVersiculo.LimparSelecao;
begin
while not Selecao.Empty do
TSyntagm(Selecao.First).RemoveFromSelection;
end;
procedure TVersiculo.DesassociarPares;
var
s: TSyntagm;
begin
LimparSelecao;
VersiculoPar.LimparSelecao;
for s in FSintagmas do
s.Disassociate;
for s in VersiculoPar.FSintagmas do
s.Disassociate;
Renderizar;
VersiculoPar.Renderizar;
end;
procedure TVersiculo.LimparAssociacoes;
var
s: TSyntagm;
begin
for s in FSintagmas do
if not s.Pairs.Empty then
begin // desassociar somente se houver associacoes, para evitar falsos 'modificado = true'
DesassociarPares;
Modificado := true;
break;
end;
end;
procedure TVersiculo.SelecionarSintagmas(list: TSyntagmList);
var
s: TSyntagm;
begin
for s in list do
s.AddToSelection;
end;
function TVersiculo.GetListaPares(tipo: TPairsListType): TStringList;
var
src, dst: string;
s, p: TSyntagm;
tmp: TSyntagmList;
begin
result := TStringList.Create;
tmp := TSyntagmList.Create;
for s in FSintagmas do
begin
if not assigned(s.Pairs) or (s.Kind <> tsSintagma) or s.IsItalic or (tmp.IndexOf(s) >= 0) then
continue;
src := s.GetSuggestionKey(tipo);
tmp.Add(s);
for p in s.Siblings do
begin
if p.IsItalic or (p.Kind <> tsSintagma) then
continue;
src := src + ';' + p.GetSuggestionKey(tipo);
tmp.Add(p);
end;
dst := '';
for p in s.Pairs do
begin
if p.IsItalic or (p.Kind <> tsSintagma) then
continue;
dst := dst + p.GetSuggestionKey(tipo) + ';'
end;
if not src.IsEmpty and not dst.IsEmpty then
begin
result.Add(src);
result.Add(dst.TrimRight(';'));
end;
end;
tmp.Destroy;
end;
procedure TVersiculo.OnSintagmaPopupMenu(s: TSyntagm);
var
p: TPoint;
begin
FSyntagmPopupMenu.Tag := PtrInt(s);
p := s.LabelRef.ClientToScreen(s.LabelRef.ClientRect.BottomRight);
FSyntagmPopupMenu.PopUp(p.x, p.y);
end;
procedure TVersiculo.MostrarTags;
var
s: TSyntagm;
p: TPoint;
tags: string;
begin
if not FAtivo then
exit;
for s in FSintagmas do
begin
if not assigned(s.LabelRef) or not s.HasStrongs then
continue;
p := s.LabelRef.ClientToParent(s.LabelRef.ClientRect.TopLeft, FPanel);
tags := s.Strong.CommaText;
with FPanel.Canvas do
begin
// Link para solução overriding Paint: http://forum.lazarus.freepascal.org/index.php?topic=23894.0
Brush.Color := clYellow;
Font.Name := DefFontData.Name;
Font.Height := round(s.LabelRef.Font.Height * 0.6);
Font.Color := clBlack;
Rectangle(p.x, p.y, p.x + TextWidth(tags) + 4, p.y + TextHeight(tags));
Brush.Style := bsClear;
TextOut(p.x+2, p.y, tags);
end;
end;
end;
procedure TVersiculo.OcultarTags;
begin
if FAtivo then
FPanel.Refresh;
end;
procedure TVersiculo.EnableStrongHighlight(strong: string);
var
s: TSyntagm;
begin
for s in FSintagmas do
s.HighlightStrong(strong);
end;
procedure TVersiculo.DisableStrongHighlight;
var
s: TSyntagm;
begin
for s in FSintagmas do
s.ToggleStrongHighlight(false);
end;
procedure TVersiculo.SetTexto(_XML: string);
begin
FXML := _XML;
LimparSintagmas;
FSintagmas := FONTParser.ParseLine(FXML, self);
Renderizar;
Modificado := true;
FXMLModificado := true;
SintagmaClipboard := nil;
end;
{ Replaces the verse text trying to keep existing associations }
procedure TVersiculo.AlterarTexto(_XML: string);
procedure DeleteSyntagm(i: integer; newlist: TSyntagmList);
var
s, s1, pair: TSyntagm;
begin
s := FSintagmas[i];
if assigned(s.Pairs) then
begin
for pair in FVersiculoRef.Sintagmas do
begin
pair.Pairs.Remove(s);
if pair.Pairs.Count = 0 then
pair.IsAssociated := false;
end;
s.Pairs.Clear;
end;
if s.Kind = tsSintagma then
for s1 in newlist do
if assigned(s1.Siblings) then
s1.Siblings.Remove(s);
s.Destroy;
FSintagmas.Delete(i);
end;
var
new, result: TSyntagmList;
s, old: TSyntagm;
found, oldActive: boolean;
begin
if FXML = _XML then
exit;
oldActive := FAtivo;
FAtivo := false; // we're potentially deleting labels
new := FONTParser.ParseLine(_XML, self);
LimparSelecao;
if FSintagmas.Empty then
FSintagmas := new
else
begin
result := TSyntagmList.Create;
while not (new.Empty and FSintagmas.Empty) do
begin
if new.Empty then
DeleteSyntagm(0, result)
else if FSintagmas.Empty then
begin
result.Add(new[0]);
new.Delete(0);
end
else if FSintagmas.First.Kind <> tsSintagma then
DeleteSyntagm(0, result)
else if new.First.Kind <> tsSintagma then
begin
result.Add(new[0]);
new.Delete(0);
end
else if new.First.IsEqualTo(FSintagmas.First) then
begin
with FSintagmas.First do
begin
Strong.Free;
Morph.Free;
Strong := new.First.Strong;
Morph := new.First.Morph;
new.First.Strong := nil;
new.First.Morph := nil;
end;
result.Add(FSintagmas.First);
FSintagmas.Delete(0);
new.First.Destroy;
new.Delete(0);
end
else
begin
{ checking if the old syntagm will be used in the future }
found := false;
old := FSintagmas.First;
if not old.Pairs.Empty then // does it have associations?
begin
for s in new do
if old.IsEqualTo(s) then
begin
result.Add(new[0]);
new.Delete(0);
found := true;
break;
end;
end;
if not found then { nope, wasting it }
DeleteSyntagm(0, result);
end;
end;
if not new.Empty then
raise Exception.Create('Ainda há sintagmas novos que não foram liberados!');
if not FSintagmas.Empty then
raise Exception.Create('Ainda há sintagmas antigos que não foram liberados!');
LimparSintagmas;
FSintagmas.Destroy;
FSintagmas := result;
end;
FXML := _XML;
FXMLModificado := true;
FModificado := true;
if assigned(VersiculoPar) then
VersiculoPar.Modificado := true;
SintagmaClipboard := nil;
FAtivo := oldActive;
Renderizar;
end;
function TVersiculo.GetTexto: string;
var
linha: TStringStream;
s: TSyntagm;
begin
result := '';
try
linha := TStringStream.Create('');
for s in FSintagmas do
linha.WriteString(s.Text);
finally
result := linha.DataString;
linha.Destroy;
end;
end;
procedure TVersiculo.SetPares(const AValue: string);
var
varredorXML: TONTTokenizer;
s: TTagSintagma;
begin
if not assigned(VersiculoPar) or AValue.IsEmpty then
exit;
FExibirErro := true;
VersiculoPar.FExibirErro := true;
varredorXML := TTokenizerFactory.CreatePreferredTokenizer(AValue);
while varredorXML.LerSintagma(s) <> tsNulo do
begin
if AnsiStartsStr('<par ', s.valor) then
begin
//DebugLn('selecionando par: %s', [s.valor]);
SelecionarListaSintagmas(varredorXML.LerPropriedadeTag('a', s));
VersiculoPar.SelecionarListaSintagmas(varredorXML.LerPropriedadeTag('b', s));
AssociarSintagmas;
LimparSelecao;
VersiculoPar.LimparSelecao;
end;
end;
varredorXML.Destroy;
Renderizar;
VersiculoPar.Renderizar;
end;
function TVersiculo.GetPares: string;
var
b: integer;
s, p: TSyntagm;
_xml: TStringStream;
tmp: TSyntagmList;
begin
_xml := TStringStream.Create('');
// gerar tags de Texto <p a="1,2,3" b="1,2,3">
tmp := TSyntagmList.Create;
for s in FSintagmas do
begin
if not s.Pairs.Empty and (tmp.IndexOf(s) < 0) then
begin
_xml.WriteString(Format('<par a="%d', [FSintagmas.IndexOf(s)]));
tmp.Add(s);
for p in s.Siblings do
begin
_xml.WriteString(Format(',%d', [FSintagmas.IndexOf(p)]));
tmp.Add(p);
end;
_xml.WriteString('" b="');
for p in s.Pairs do
begin
b := FVersiculoRef.Sintagmas.IndexOf(p);
if b < 0 then
raise exception.Create('Pair not found in other verse');
_xml.WriteString(Format('%d', [b]));
if s.Pairs.IndexOf(p) <> s.Pairs.Count-1 then
_xml.WriteString(',');
end;
_xml.WriteString('">');
end;
end;
tmp.Destroy;
result := _xml.DataString;
_xml.Destroy;
end;
function TVersiculo.GetTextoSimples: string;
var
linha: TStringStream;
s: TSyntagm;
begin
result := '';
try
linha := TStringStream.Create('');
for s in FSintagmas do
if s.Kind in [tsEspaco, tsSintagma, tsPontuacao] then
linha.WriteString(s.Text);
finally
result := linha.DataString;
linha.Destroy;
end;
end;
function TVersiculo.GetAtivo: boolean;
begin
result := FAtivo;
end;
function TVersiculo.GetFonte: TFont;
begin
if FAtivo then
result := FPanel.Font
else
result := nil;
end;
function TVersiculo.GetAndamentoAssociacao: Single;
var
s: TSyntagm;
t, p: smallint;
begin
t := 0;
p := 0;
result := 0;
for s in FSintagmas do
if s.Kind = tsSintagma then
begin
inc(t);
if s.IsAssociated then
inc(p);
end;
if t > 0 then
result := p/t;
end;
function TVersiculo.GetTheWordInterlinearLine: string;
function GetSpacingBefore(syn, pair: TSyntagm): string;
var
i: integer;
begin
result := '';
if pair = syn.Pairs[0] then exit;
for i:=FVersiculoRef.Sintagmas.IndexOf(pair)-1 downto 0 do
begin
if FVersiculoRef.Sintagmas[i].Kind = tsSintagma then
break;
if FVersiculoRef.Sintagmas[i].Kind = tsEspaco then
begin
result := ' ';
break;
end;
end;
end;
var
linha: TStringStream;
s, p, prox: TSyntagm;
m: string;
n: integer;
begin
result := '';
try
linha := TStringStream.Create('');
for s in FSintagmas do
begin
linha.WriteString(s.Text);
if (assigned(s.Strong) and (s.Strong.Count > 0)) or (assigned(s.Morph) and (s.Morph.Count > 0)) then
begin // se este texto contém strongs
for m in s.Strong do // strongs
linha.WriteString(format('<W%s>', [m]));
for m in s.Morph do // morfologia
linha.WriteString(format('<WT%s>', [m]));
end else
begin // caso contrário, tentemos o texto relacionado
for p in s.Pairs do
begin
for m in p.Strong do // strongs
linha.WriteString(format('<W%s>', [m]));
for m in p.Morph do // morfologia
linha.WriteString(format('<WT%s>', [m]));
end;
end;
if (FSintagmas.IndexOf(s) < (FSintagmas.Count-1)) and // não é o último sintagma e
(s.Siblings.Count > 0) then // tem irmãos
begin
prox := nil;
for n:=FSintagmas.IndexOf(s)+1 to Sintagmas.Count-1 do
begin // procurando o próximo sintagma (saltando espaços, pontuação, etc.)
if Sintagmas[n].Kind = tsSintagma then
begin
prox := Sintagmas[n];
break;
end;
end;
if (prox <> nil) and (s.Siblings.IndexOf(prox) >= 0) then // o próximo sintagma é irmão deste?
continue;
end;
for p in s.Pairs do // pares
linha.WriteString(GetSpacingBefore(s, p) + '<sup>' + IfThen(p.IsItalic, format('<FI>%s<Fi>', [p.Text]), p.Text) + '</sup>');
end;
finally
result := linha.DataString.Replace('</sup> <sup>', ' ')
.Replace(' ', ' ')
.Replace('<sup>', '<font size=+1 color="CC3300"><sup>')
.Replace('</sup>', '</sup></font>')
.Replace('<Fi><FI>', '')
.Replace(' -', '-');
linha.Destroy;
end;
end;
function TVersiculo.GetMySwordInterlinearLine: string;
function GetSpacingBefore(syn, pair: TSyntagm): string;
var
i: integer;
begin
result := '';
if pair = syn.Pairs[0] then exit;
for i:=FVersiculoRef.Sintagmas.IndexOf(pair)-1 downto 0 do
begin
if FVersiculoRef.Sintagmas[i].Kind = tsSintagma then
break;
if FVersiculoRef.Sintagmas[i].Kind = tsEspaco then
begin
result := ' ';
break;
end;
end;
end;
function TestAndUnset(out flag: boolean): Boolean;
begin
result := flag;
if flag then
flag := false;
end;
function CollectConsecutiveSiblings(startSyntagm: TSyntagm; var skipIndices: TList): string;
var
currentIdx, nextIdx, lookAheadIdx: Integer;
currentSyn, nextSyn, lookAheadSyn: TSyntagm;
combinedText: string;
foundSpace: Boolean;
begin
combinedText := startSyntagm.Text;
currentIdx := FSintagmas.IndexOf(startSyntagm);
// If we have siblings, check if any are consecutive
if startSyntagm.Siblings.Count = 0 then
begin
Result := combinedText;
Exit;
end;
// Check next syntagms to find consecutive siblings
nextIdx := currentIdx + 1;
while nextIdx < FSintagmas.Count do
begin
nextSyn := FSintagmas[nextIdx];
// Add any spaces between siblings
if nextSyn.Kind = tsEspaco then
begin
combinedText := combinedText + nextSyn.Text;
skipIndices.Add(Pointer(nextIdx));
Inc(nextIdx);
continue;
end
// Handle '<wt>' tags between siblings - look ahead to see if followed by a sibling
else if (nextSyn.Kind = tsMetaDado) and (nextSyn.Text = '<wt>') then
begin
// Look ahead to find next syntagm after the tag
lookAheadIdx := nextIdx + 1;
lookAheadSyn := nil;
while (lookAheadIdx < FSintagmas.Count) do
begin
if FSintagmas[lookAheadIdx].Kind = tsSintagma then
begin
lookAheadSyn := FSintagmas[lookAheadIdx];
break;
end;
Inc(lookAheadIdx);
end;
// Only add the '<wt>' tag if followed by a sibling
if (lookAheadSyn <> nil) and (startSyntagm.Siblings.IndexOf(lookAheadSyn) >= 0) then
begin
combinedText := combinedText + nextSyn.Text;
skipIndices.Add(Pointer(nextIdx));
end;
Inc(nextIdx);
continue;
end
// If next syntagm is not a sibling or not a syntagm, we're done
else if (nextSyn.Kind <> tsSintagma) or
(startSyntagm.Siblings.IndexOf(nextSyn) < 0) then
break;
// Found consecutive sibling, add it to result
combinedText := combinedText + nextSyn.Text;
skipIndices.Add(Pointer(nextIdx));
Inc(nextIdx);
end;
Result := combinedText;
end;
var
line: TStringStream;
s, p, nextSyntagm: TSyntagm;
m: string;
skip: boolean;
skipIndices: TList;
i, currentIndex: Integer;
combinedText: string;
begin
result := '';
{Sample: <TS>The Creation<Ts><Q><wg>εν<WG1722><E> In<e><q> <Q><wg>αρχή<WG746><E> <FI>the<Fi> beginning<e><q>}
skipIndices := TList.Create;
try
line := TStringStream.Create('');
skip := false;
i := 0;
while i < FSintagmas.Count do
begin
if skipIndices.IndexOf(Pointer(i)) >= 0 then
begin
Inc(i);
continue;
end;
s := FSintagmas[i];
if TestAndUnset(skip) then
begin
Inc(i);
continue;
end;
case s.Kind of
tsSintagma:
begin
// Collect text from consecutive siblings
combinedText := CollectConsecutiveSiblings(s, skipIndices);
line.WriteString('<Q>');
// Use non-breakable spaces in the text
line.WriteString(combinedText);
// Output Strong's numbers and morphology for this syntagm
for m in s.Strong do
line.WriteString(format('<W%s>', [m]));
for m in s.Morph do
line.WriteString(format('<WT%s>', [m]));
if assigned(s.GetNext) and (s.GetNext.Kind = tsPontuacao) then
begin
line.WriteString(s.GetNext.Text);
skip := true;
end;
if s.Pairs.Count > 0 then
begin
line.WriteString('<T>');
if (s.Siblings.Count = 0) or (i < FSintagmas.IndexOf(s.Siblings[0])) then
begin // no siblings or is the first sibling
for p in s.Pairs do
begin
line.WriteString(GetSpacingBefore(s, p));
// Also use non-breakable spaces in the translated text
if p.IsItalic then
line.WriteString(Format('<FI>%s<Fi>', [p.Text]))
else
line.WriteString(p.Text);
end;
end else // not a first sibling
line.WriteString('←');
line.WriteString('<t>');
end
else
line.WriteString('<T>•<t>');