-
Notifications
You must be signed in to change notification settings - Fork 0
/
mdGdocLib.go
4794 lines (4053 loc) · 138 KB
/
mdGdocLib.go
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
// golang library that converts a markdown file into a gdoc file
// author: prr
// created: 25/5/2022
// copyright 2022 prr, Azul Software
//
// for changes see github
//
// start: CvtMdToGdoc
//
package GdocToMd
import (
"fmt"
"os"
"io/ioutil"
"context"
"golang.org/x/oauth2/google"
"google.golang.org/api/option"
gdocAuth "google/gdoc/gdocApiRW"
"google.golang.org/api/docs/v1"
util "google/gdoc/gdocUtil"
)
const (
PtTomm = 0.35277777777778
MmTopt = 2.8346456692913207
)
type GdocDomObj struct {
doc *docs.Document
docName string
docWidth float64
docHeight float64
ImgFoldName string
imgCount int
imgCounter int
tableCount int
tableCounter int
parCount int
title namStylTyp
subtitle namStylTyp
h1 namStylTyp
h2 namStylTyp
h3 namStylTyp
h4 namStylTyp
h5 namStylTyp
h6 namStylTyp
parent string
listStack *[]cList
docLists []docList
headings []headingTyp
sections []secTyp
docPb []pbTyp
docFtnotes []docFtnoteTyp
namStylMap map[string]bool
headCount int
secCount int
pbCount int
elCount int
spanCount int
ftnoteCount int
inImgCount int
posImgCount int
hrCount int
htmlFil *os.File
cssFil *os.File
jsFil *os.File
// folderName string
folderPath string
imgFoldNam string
// imgFoldPath string
Options *util.OptObj
}
type namStylTyp struct {
count int
}
type dispObj struct {
bodyHtml string
bodyCss string
script string
}
type secTyp struct {
sNum int
secElStart int
secElEnd int
}
type pbTyp struct {
el int
parel int
}
type headingTyp struct {
hdElEnd int
hdElStart int
namedStyl string
id string
text string
}
type docFtnoteTyp struct {
el int
parel int
id string
numStr string
}
type cList struct {
cListId string
cListCount int
cOrd bool
}
type docList struct {
listId string
maxNestLev int64
ord bool
}
type nestLevel struct {
GlAl string
GlFmt string
GlSym string
GlTyp string
GlOrd bool
Count int64
FlInd float64
StInd float64
glTxtmap *textMap
}
type tblBorder struct {
color string
dash string
width float64
}
type parMap struct {
halign string
headingId string
direct bool
indEnd float64
indFlin float64
indStart float64
keepLines bool
keepNext bool
linSpac float64
shading string
spaceTop float64
spaceBelow float64
spaceMode bool
tabs []*tabStop
pad [4]float64
margin [4]float64
hasBorders bool
bordTop parBorder
bordLeft parBorder
bordRight parBorder
bordBot parBorder
bordBet parBorder
}
type parBorder struct {
pad float64
width float64
color string
dash string
}
type tabStop struct {
tabAlign string
offset float64
}
type textMap struct {
bckColor string
baseOffset string
bold bool
italic bool
underline bool
strike bool
fontSize float64
txtColor string
link bool
fontType string
fontWeight int64
}
type linkMap struct {
url string
bookmark string
}
type elScriptObj struct {
typ string
txt string
cl1 string
cl2 string
idStr string
href string
parent string
newEl string
comment string
}
type imgScriptObj struct {
cl1 string
cl2 string
idStr string
height int
width int
src string
parent string
title string
desc string
comment string
}
type tableScriptObj struct {
cl1 string
cl2 string
idStr string
rowCount int
colCount int
parent string
newEl string
comment string
tblRows []tblRowScriptObj
}
type tblRowScriptObj struct {
cl1 string
cl2 string
idStr string
parent string
newEl string
tblCells []tblCellScriptObj
}
type tblCellScriptObj struct {
cl1 string
cl2 string
idStr string
parent string
newEl string
}
type tblCell struct {
pad [4] float64
spad float64
vert_align string
bckcolor string
border [4] tblBorder
bwidth float64
bdash string
bcolor string
cspan int
rspan int
}
func InitGdocRWApi() (svc *docs.Service, err error) {
ctx := context.Background()
b, err := ioutil.ReadFile("credGdoc.json")
if err != nil {
return nil, fmt.Errorf("Unable to read client secret file: %v!", err)
}
// If modifying these scopes, delete your previously saved token.json.
config, err := google.ConfigFromJSON(b, "https://www.googleapis.com/auth/documents")
if err != nil {
return nil, fmt.Errorf("Unable to parse client secret file to config: %v", err)
}
client := gdocAuth.GetClient(config)
svc, err = docs.NewService(ctx, option.WithHTTPClient(client))
if err != nil {
return nil, fmt.Errorf("Unable to retrieve Docs client: %v", err)
}
return svc, nil
}
func findDocList(list []docList, listid string) (res int) {
res = -1
for i:=0; i< len(list); i++ {
if list[i].listId == listid {
return i
}
}
return res
}
func pushLiStack(stack *[]cList, item cList)(nstack *[]cList) {
if (stack == nil) {
xx := make([]cList,0)
stack = &xx
}
*stack= append(*stack, item)
return stack
}
func popLiStack(stack *[]cList)(nstack *[]cList) {
if stack == nil {return nil}
n := len(*stack) -1
if n >= 0 {
xx := (*stack)[:n]
nstack = &xx
} else {
nstack = nil
}
return nstack
}
func getLiStack(stack *[]cList) (item cList, nl int) {
if stack == nil {
return item, -1
}
nl = len(*stack) -1
// review n>1 if there is a stack!
if nl >= 0 {
item = (*stack)[nl]
} else {
nl = -1
}
return item, nl
}
func printLiStack(stack *[]cList) {
var item cList
var n int
if stack == nil {
fmt.Println("*** no listStack ***")
return
}
n = len(*stack) -1
if n>=0 {
item = (*stack)[n]
} else {
n = -1
}
fmt.Printf("list stack Nlevel: %d", n)
if n >= 0 {
fmt.Printf(" id: %s ordered: %t", item.cListId, item.cOrd)
}
fmt.Printf("\n")
return
}
func printLiStackItem(listAtt cList, cNest int){
fmt.Printf("list Att Nlevel: %d", cNest)
if cNest >= 0 {
fmt.Printf(" id: %s ordered: %t", listAtt.cListId, listAtt.cOrd)
}
fmt.Printf("\n")
}
func printTxtMap(txtMap *textMap) {
fmt.Println("********* text map ****************")
fmt.Printf("Base Offset: %s\n", txtMap.baseOffset)
fmt.Printf("Bold Text: %t\n", txtMap.bold)
fmt.Printf("Italic Text: %t\n", txtMap.italic)
fmt.Printf("Underline: %t\n", txtMap.underline)
fmt.Printf("Text Strike: %t\n", txtMap.strike)
fmt.Printf("Font: %s\n", txtMap.fontType)
fmt.Printf("Font Weight: %d\n", txtMap.fontWeight)
fmt.Printf("Font Size: %.1f\n", txtMap.fontSize)
fmt.Printf("Font Color: %s\n", txtMap.txtColor)
fmt.Printf("Font BckCol: %s\n", txtMap.bckColor)
return
}
func fillTxtMap (txtStyl *docs.TextStyle)(txtMapRef *textMap) {
var txtMap textMap
if txtStyl == nil { return nil}
txtMap.baseOffset = "NONE"
if len(txtStyl.BaselineOffset) >0 {
if txtStyl.BaselineOffset != "BASELINE_OFFSET_UNSPECIFIED" {
txtMap.baseOffset = txtStyl.BaselineOffset
}
}
txtMap.fontWeight = 400
if txtStyl.Bold {
txtMap.fontWeight = 800
}
txtStyl.Italic = false
if txtStyl.Italic {
txtMap.italic = txtStyl.Italic
}
txtStyl.Underline = false
if txtStyl.Underline {
txtMap.underline = txtStyl.Underline
}
txtMap.strike = false
if txtStyl.Strikethrough {
txtMap.strike = txtStyl.Strikethrough
}
txtMap.fontType = "Calibri"
if txtStyl.WeightedFontFamily != nil {
if txtStyl.WeightedFontFamily.FontFamily != txtMap.fontType {
txtMap.fontType = txtStyl.WeightedFontFamily.FontFamily
}
if txtStyl.WeightedFontFamily.Weight > 0 {
if txtStyl.WeightedFontFamily.Weight != txtMap.fontWeight {
txtMap.fontWeight = txtStyl.WeightedFontFamily.Weight
}
}
}
txtMap.fontSize = 0.0
if txtStyl.FontSize != nil {
if txtStyl.FontSize.Magnitude >0 {
txtMap.fontSize = txtStyl.FontSize.Magnitude
}
}
txtMap.txtColor = "rgb(0,0,0)"
if txtStyl.ForegroundColor != nil {
if txtStyl.ForegroundColor.Color != nil {
color := util.GetColor(txtStyl.ForegroundColor.Color)
if color != txtMap.txtColor {
txtMap.txtColor = color
}
}
}
txtMap.bckColor = ""
if txtStyl.BackgroundColor != nil {
if txtStyl.BackgroundColor.Color != nil {
color := util.GetColor(txtStyl.BackgroundColor.Color)
if color != txtMap.bckColor {
txtMap.bckColor = color
}
}
}
return &txtMap
}
func cvtTxtMapCss(txtMap *textMap)(cssStr string) {
cssStr =""
if len(txtMap.baseOffset) > 0 {
switch txtMap.baseOffset {
case "SUPERSCRIPT":
cssStr += " vertical-align: sub;\n"
case "SUBSCRIPT":
cssStr += " vertical-align: sup;\n"
case "NONE":
cssStr += " vertical-align: baseline;\n"
default:
//error
cssStr += fmt.Sprintf("/* Baseline Offset unknown: %s */\n", txtMap.baseOffset)
}
}
if txtMap.italic {
cssStr += " font-style: italic;\n"
} else {
cssStr += " font-style: normal;\n"
}
textprop := ""
switch {
case txtMap.underline && txtMap.strike:
textprop = "underline line-through"
case txtMap.underline && !txtMap.strike:
textprop = "underline"
case !txtMap.underline && txtMap.strike:
textprop = "line-through"
case !txtMap.underline && !txtMap.strike:
textprop = "none"
}
cssStr += fmt.Sprintf(" text-decoration: %s;\n", textprop)
if len(txtMap.fontType) >0 { cssStr += fmt.Sprintf(" font-family: %s;\n", txtMap.fontType)}
if txtMap.fontWeight > 0 {cssStr += fmt.Sprintf(" font-weight: %d;\n", txtMap.fontWeight)}
if txtMap.fontSize >0 {cssStr += fmt.Sprintf(" font-size: %.2fpt;\n", txtMap.fontSize)}
if len(txtMap.txtColor) >0 {cssStr += fmt.Sprintf(" color: %s;\n", txtMap.txtColor)}
if len(txtMap.bckColor) >0 {cssStr += fmt.Sprintf(" background-color: %s;\n", txtMap.bckColor)}
return cssStr
}
func cvtTxtMapStylCss (txtMap *textMap, txtStyl *docs.TextStyle)(cssStr string) {
if (len(txtStyl.BaselineOffset) > 0) && (txtStyl.BaselineOffset != "BASELINE_OFFSET_UNSPECIFIED") {
if txtStyl.BaselineOffset != txtMap.baseOffset {
txtMap.baseOffset = txtStyl.BaselineOffset
switch txtMap.baseOffset {
case "SUPERSCRIPT":
cssStr += " vertical-align: sub;\n"
case "SUBSCRIPT":
cssStr += " vertical-align: sup;\n"
case "NONE":
cssStr += " vertical-align: baseline;\n"
default:
//error
cssStr += fmt.Sprintf("/* Baseline Offset unknown: %s */\n", txtMap.baseOffset)
}
}
}
switch {
case txtStyl.Bold && (txtMap.fontWeight < 700):
txtMap.fontWeight = 800
cssStr += fmt.Sprintf(" font-weight: %d;\n", txtMap.fontWeight)
case !txtStyl.Bold && (txtMap.fontWeight > 500):
txtMap.fontWeight = 400
cssStr += fmt.Sprintf(" font-weight: %d;\n", txtMap.fontWeight)
default:
}
if txtStyl.Italic != txtMap.italic {
txtMap.italic = txtStyl.Italic
if txtMap.italic {
cssStr += " font-style: italic;\n"
} else {
cssStr += " font-style: normal;\n"
}
}
txtprop := ""
if txtStyl.Underline != txtMap.underline {
txtMap.underline = txtStyl.Underline
if txtMap.underline {
txtprop = "underline"
} else {
txtprop = "none"
}
}
// if txtMap.underline { cssStr += " text-decoration: underline;\n"}
if txtStyl.Strikethrough != txtMap.strike {
txtMap.strike = txtStyl.Strikethrough
if txtMap.strike {
if txtprop == "none" {
txtprop = "line-through"
} else {
txtprop += " line-through"
}
}
}
if len(txtprop) > 0 {cssStr += fmt.Sprintf(" text-decoration: %s;\n", txtprop)}
if txtStyl.WeightedFontFamily != nil {
if txtStyl.WeightedFontFamily.FontFamily != txtMap.fontType {
txtMap.fontType = txtStyl.WeightedFontFamily.FontFamily
cssStr += fmt.Sprintf(" font-family: %s;\n", txtMap.fontType)
}
/*
if txtStyl.WeightedFontFamily.Weight != txtMap.fontWeight {
txtMap.fontWeight = txtStyl.WeightedFontFamily.Weight
alter = true
}
*/
}
if txtStyl.FontSize != nil {
if txtStyl.FontSize.Magnitude != txtMap.fontSize {
txtMap.fontSize = txtStyl.FontSize.Magnitude
cssStr += fmt.Sprintf(" font-size: %.2fpt;\n", txtMap.fontSize)
}
}
if txtStyl.ForegroundColor != nil {
if txtStyl.ForegroundColor.Color != nil {
color := util.GetColor(txtStyl.ForegroundColor.Color)
if color != txtMap.txtColor {
txtMap.txtColor = color
cssStr += fmt.Sprintf(" color: %s;\n", txtMap.txtColor)
}
}
}
if txtStyl.BackgroundColor != nil {
if txtStyl.BackgroundColor.Color != nil {
color := util.GetColor(txtStyl.BackgroundColor.Color)
if color != txtMap.bckColor {
txtMap.bckColor = color
cssStr += fmt.Sprintf(" background-color: %s;\n", txtMap.bckColor)
}
}
}
return cssStr
}
func cvtTxtStylCss (txtStyl *docs.TextStyle)(cssStr string) {
var tcssStr string
if len(txtStyl.BaselineOffset) > 0 {
valStr := "vertical-align: "
switch txtStyl.BaselineOffset {
case "SUPERSCRIPT":
valStr += "sub"
case "SUBSCRIPT":
valStr += "sup"
case "NONE":
valStr += "baseline"
default:
valStr = fmt.Sprintf("/* Baseline Offset unknown: %s */\n", txtStyl.BaselineOffset)
}
tcssStr = valStr + ";\n"
}
if txtStyl.Bold {
tcssStr += " font-weight: 800;\n"
} else {
tcssStr += " font-weight: 400;\n"
}
if txtStyl.Italic { tcssStr += " font-style: italic;\n"}
if txtStyl.Underline { tcssStr += " text-decoration: underline;\n"}
if txtStyl.Strikethrough { tcssStr += " text-decoration: line-through;\n"}
if txtStyl.WeightedFontFamily != nil {
font := txtStyl.WeightedFontFamily.FontFamily
tcssStr += fmt.Sprintf(" font-family: %s;\n", font)
}
if txtStyl.FontSize != nil {
mag := txtStyl.FontSize.Magnitude
tcssStr += fmt.Sprintf(" font-size: %.2fpt;\n", mag)
}
if txtStyl.ForegroundColor != nil {
if txtStyl.ForegroundColor.Color != nil {
//0 to 1
tcssStr += " color: "
tcssStr += util.GetColor(txtStyl.ForegroundColor.Color)
}
}
if txtStyl.BackgroundColor != nil {
if txtStyl.BackgroundColor.Color != nil {
tcssStr += " background-color: "
tcssStr += util.GetColor(txtStyl.BackgroundColor.Color)
}
}
if len(tcssStr) > 0 {
cssStr = tcssStr
}
return cssStr
}
func printParMap(parmap *parMap, parStyl *docs.ParagraphStyle) {
alter := false
fmt.Printf("*** align ***\n")
if parStyl.Alignment != parmap.halign {
fmt.Printf("align: %s %s \n", parmap.halign, parStyl.Alignment)
parmap.halign = parStyl.Alignment
alter = true
}
fmt.Printf("align: %s \n", parmap.halign)
// parmap.direct = true
fmt.Printf("*** indent ***\n")
if (parStyl.IndentStart != nil) {
if parStyl.IndentStart.Magnitude != parmap.indStart {
fmt.Printf("indent start: %.1fpt %.1fpt\n", parmap.indStart, parStyl.IndentStart.Magnitude)
parmap.indStart = parStyl.IndentStart.Magnitude
alter = true
}
}
fmt.Printf("indent start: %.1fpt\n", parmap.indStart)
fmt.Printf("*** indent end***\n")
if (parStyl.IndentEnd != nil) {
if parStyl.IndentEnd.Magnitude != parmap.indEnd {
fmt.Printf("indent end: %.1f %.1f \n", parmap.indEnd, parStyl.IndentEnd.Magnitude)
parmap.indEnd = parStyl.IndentEnd.Magnitude
alter = true
}
}
fmt.Printf("indent end: %.1fpt\n", parmap.indEnd)
fmt.Printf("*** indent first line ***\n")
if (parStyl.IndentFirstLine != nil) {
if parStyl.IndentFirstLine.Magnitude != parmap.indFlin {
fmt.Printf("indent first line: %.1f %.1f \n", parmap.indFlin, parStyl.IndentFirstLine.Magnitude)
parmap.indFlin = parStyl.IndentFirstLine.Magnitude
alter = true
}
}
fmt.Printf("indent first line: %.1fpt\n", parmap.indFlin)
fmt.Printf("*** line spacing ***\n")
if parStyl.LineSpacing/100.0 != parmap.linSpac {
fmt.Printf("line spacing: %.2f %.2f \n", parmap.linSpac, parStyl.LineSpacing/100.0)
parmap.linSpac = parStyl.LineSpacing/100.0; alter = true;
}
fmt.Printf("line spacing: %.2fpt\n", parmap.linSpac)
fmt.Printf("*** keep lines ***\n")
if parStyl.KeepLinesTogether != parmap.keepLines {
fmt.Printf("keep Lines: %t %t\n", parmap.keepLines, parStyl.KeepLinesTogether)
parmap.keepLines = parStyl.KeepLinesTogether; alter = true;
}
fmt.Printf("keep Lines: %t\n", parmap.keepLines)
fmt.Printf("*** keep next ***\n")
if parStyl.KeepWithNext != parmap.keepNext {
fmt.Printf("keep With: %t %t\n", parmap.keepNext, parStyl.KeepWithNext)
parmap.keepNext = parStyl.KeepWithNext; alter = true;
}
fmt.Printf("keep With: %t\n", parmap.keepNext)
fmt.Printf("*** space above ***\n")
if (parStyl.SpaceAbove != nil) {
if parStyl.SpaceAbove.Magnitude != parmap.spaceTop {
fmt.Printf("space above: %.1fpt %.1fpt\n", parmap.spaceTop, parStyl.SpaceAbove.Magnitude)
parmap.spaceTop = parStyl.SpaceAbove.Magnitude
alter = true
}
}
fmt.Printf("space above: %.1fpt\n", parmap.spaceTop)
fmt.Printf("*** space below ***\n")
if (parStyl.SpaceBelow != nil) {
if parStyl.SpaceBelow.Magnitude != parmap.spaceBelow {
fmt.Printf("space below: %.1f %.1f \n", parmap.spaceBelow, parStyl.SpaceBelow.Magnitude)
parmap.spaceBelow = parStyl.SpaceBelow.Magnitude
alter = true
}
}
fmt.Printf("space below: %.1fpt\n", parmap.spaceBelow)
fmt.Printf("*** space mode ***\n")
spaceMode := true
switch parStyl.SpacingMode {
case "NEVER_COLLAPSE":
spaceMode = true
case "COLLAPSE_LISTS":
spaceMode = false
default:
spaceMode = true
}
if spaceMode != parmap.spaceMode {
fmt.Printf("spacing mode: %t %t \n", parmap.spaceMode, spaceMode)
parmap.spaceMode = spaceMode
}
fmt.Printf("spacing mode: %s\n", parmap.spaceMode)
//tabs to do
// parmap.hasBorders = true
bb := true
bb = bb && (parStyl.BorderBetween == nil)
bb = bb && (parStyl.BorderTop == nil)
bb = bb && (parStyl.BorderRight == nil)
bb = bb && (parStyl.BorderBottom == nil)
bb = bb && (parStyl.BorderLeft == nil)
if bb {
fmt.Printf("has no borders: %t %t \n", parmap.hasBorders, !bb)
parmap.hasBorders = false
fmt.Printf("alter 1: %t\n", alter)
return
}
fmt.Println("\n*** has Borders! ***\n")
parmap.hasBorders = true
alter = false
bordalter := false
// fmt.Printf("*** borders between ***\n")
if parStyl.BorderBetween != nil {
if parStyl.BorderBetween.Width != nil {
if parStyl.BorderBetween.Width.Magnitude != parmap.bordBet.width {
parmap.bordBet.width = parStyl.BorderBetween.Width.Magnitude
alter = true
fmt.Printf("width: %.1f\n",parmap.bordBet.width)
}
}
if parStyl.BorderBetween.Padding != nil {
if parStyl.BorderBetween.Padding.Magnitude != parmap.bordBet.pad {
parmap.bordBet.pad = parStyl.BorderBetween.Padding.Magnitude
alter = true
fmt.Printf("padding: %.1f\n",parmap.bordBet.pad)
}
}
if parStyl.BorderBetween.Color != nil {
if parStyl.BorderBetween.Color.Color != nil {
color := util.GetColor(parStyl.BorderBetween.Color.Color)
if color != parmap.bordBet.color {
parmap.bordBet.color = color
alter = true
fmt.Printf("color: %s\n",parmap.bordBet.color)
}
}
}
if parStyl.BorderBetween.DashStyle != parmap.bordBet.dash {
parmap.bordBet.dash = parStyl.BorderBetween.DashStyle;
alter = true;
fmt.Printf("dash: %s\n",parmap.bordBet.dash)
}
}
fmt.Printf("*** border between alter: %t ***\n", alter)
if alter {bordalter = true}
alter = false
// fmt.Printf("*** border top ***\n")
if parStyl.BorderTop != nil {
if parStyl.BorderTop.Width != nil {
if parStyl.BorderTop.Width.Magnitude != parmap.bordTop.width {
parmap.bordTop.width = parStyl.BorderTop.Width.Magnitude
alter = true
fmt.Printf("width: %.1f\n",parmap.bordTop.width)
}
}
if parStyl.BorderTop.Padding != nil {
if parStyl.BorderTop.Padding.Magnitude != parmap.bordTop.pad {
parmap.bordTop.pad = parStyl.BorderTop.Padding.Magnitude
alter = true
}
}
if parStyl.BorderTop.Color != nil {
if parStyl.BorderTop.Color.Color != nil {
color := util.GetColor(parStyl.BorderTop.Color.Color)
if color != parmap.bordTop.color {
parmap.bordTop.color = color
alter = true
}
}
}
if parStyl.BorderTop.DashStyle != parmap.bordTop.dash {parmap.bordTop.dash = parStyl.BorderTop.DashStyle; alter = true;}
}
fmt.Printf("*** border top alter: %t ***\n", alter)
if alter {bordalter = true}
alter = false
// fmt.Printf("*** border right ***\n")
if parStyl.BorderRight != nil {
if parStyl.BorderRight.Width != nil {
if parStyl.BorderRight.Width.Magnitude != parmap.bordRight.width {
parmap.bordRight.width = parStyl.BorderRight.Width.Magnitude
alter = true
}
}
if parStyl.BorderRight.Padding != nil {
if parStyl.BorderRight.Padding.Magnitude != parmap.bordRight.pad {
parmap.bordRight.pad = parStyl.BorderRight.Padding.Magnitude
alter = true
}
}
if parStyl.BorderRight.Color != nil {
if parStyl.BorderRight.Color.Color != nil {
color := util.GetColor(parStyl.BorderRight.Color.Color)
if color != parmap.bordRight.color {
parmap.bordRight.color = color
alter = true
}
}
}
if parStyl.BorderRight.DashStyle != parmap.bordRight.dash {
parmap.bordRight.dash = parStyl.BorderRight.DashStyle
alter = true
}
}
fmt.Printf("*** border right alter: %t ***\n", alter)
if alter {bordalter = true}
alter = false
// fmt.Printf("*** border bottom ***\n")
if parStyl.BorderBottom != nil {
if parStyl.BorderBottom.Width != nil {
if parStyl.BorderBottom.Width.Magnitude != parmap.bordBot.width {
parmap.bordBot.width = parStyl.BorderBottom.Width.Magnitude
alter = true
}
}
if parStyl.BorderBottom.Padding != nil {
if parStyl.BorderBottom.Padding.Magnitude != parmap.bordBot.pad {
parmap.bordBot.pad = parStyl.BorderBottom.Padding.Magnitude
alter = true
}
}
if parStyl.BorderBottom.Color != nil {
if parStyl.BorderBottom.Color.Color != nil {
color := util.GetColor(parStyl.BorderBottom.Color.Color)
if color != parmap.bordBot.color {
parmap.bordBot.color = color
alter = true
}
}
}
if parStyl.BorderBottom.DashStyle != parmap.bordBot.dash {parmap.bordBot.dash = parStyl.BorderBottom.DashStyle; alter = true;}
}
fmt.Printf("*** border bottom alter: %t ***\n", alter)
if alter {bordalter = true}
alter = false
// fmt.Printf("*** border left ***\n")
if parStyl.BorderLeft != nil {
if parStyl.BorderLeft.Width != nil {
if parStyl.BorderLeft.Width.Magnitude != parmap.bordLeft.width {
parmap.bordLeft.width = parStyl.BorderLeft.Width.Magnitude
alter = true
}
}
if parStyl.BorderLeft.Padding != nil {
if parStyl.BorderLeft.Padding.Magnitude != parmap.bordLeft.pad {
parmap.bordLeft.pad = parStyl.BorderLeft.Padding.Magnitude
alter = true
}
}
if parStyl.BorderLeft.Color != nil {
if parStyl.BorderLeft.Color.Color != nil {
color := util.GetColor(parStyl.BorderLeft.Color.Color)
if color != parmap.bordLeft.color {
parmap.bordLeft.color = color
alter = true
}
}
}
if parStyl.BorderLeft.DashStyle != parmap.bordLeft.dash {parmap.bordLeft.dash = parStyl.BorderLeft.DashStyle; alter = true;}
}
fmt.Printf("*** border left alter: %t ***\n", alter)
if alter {bordalter = true}
alter = bordalter
bb2 := true
bb2 = bb2 && (parmap.bordBet.width == 0.0)
bb2 = bb2 && (parmap.bordTop.width == 0.0)
bb2 = bb2 && (parmap.bordRight.width == 0.0)
bb2 = bb2 && (parmap.bordBot.width == 0.0)
bb2 = bb2 && (parmap.bordLeft.width == 0.0)
if bb2 {parmap.hasBorders = false; alter = false;}
fmt.Printf("alter borders: %t\n", alter)
return
}
func fillParMap(parStyl *docs.ParagraphStyle)(parMapRef *parMap) {
// function that converts a parameter style object into a parMap Object
var parmap parMap
if parStyl == nil { return nil}
parmap.halign = "START"
if len(parStyl.Alignment) > 0 {
parmap.halign = parStyl.Alignment
}
parmap.direct = true
parmap.indStart = 0
if (parStyl.IndentStart != nil) {
if parStyl.IndentStart.Magnitude != parmap.indStart {
parmap.indStart = parStyl.IndentStart.Magnitude
}
}
parmap.indEnd = -1
if (parStyl.IndentEnd != nil) {
if parStyl.IndentEnd.Magnitude != parmap.indEnd {
parmap.indEnd = parStyl.IndentEnd.Magnitude
}
}
parmap.indFlin = 0
if (parStyl.IndentFirstLine != nil) {
if parStyl.IndentFirstLine.Magnitude != parmap.indFlin {
parmap.indFlin = parStyl.IndentFirstLine.Magnitude
}
}
parmap.linSpac = 1.0
if parStyl.LineSpacing/100.0 != parmap.linSpac {