File: ConvPara.java

package info (click to toggle)
h2orestart 0.7.9-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,168 kB
  • sloc: java: 21,845; makefile: 36; xml: 19
file content (1004 lines) | stat: -rw-r--r-- 58,006 bytes parent folder | download
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
1001
1002
1003
1004
/* Copyright (C) 2023 ebandal
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>
 */
/* 본 제품은 한글과컴퓨터의 ᄒᆞᆫ글 문서 파일(.hwp) 공개 문서를 참고하여 개발하였습니다.
 * 개방형 워드프로세서 마크업 언어(OWPML) 문서 구조 KS X 6101:2018 문서를 참고하였습니다.
 * 작성자 : 반희수 ebandal@gmail.com  
 * 작성일 : 2022.10
 */
package soffice;

import java.util.HashMap;
import java.util.Map;
import java.util.logging.Logger;

import com.sun.star.awt.FontRelief;
import com.sun.star.awt.FontSlant;
import com.sun.star.awt.FontStrikeout;
import com.sun.star.awt.FontUnderline;
import com.sun.star.awt.FontWeight;
import com.sun.star.beans.XPropertySet;
import com.sun.star.container.XNameAccess;
import com.sun.star.container.XNameContainer;
import com.sun.star.style.LineSpacing;
import com.sun.star.style.LineSpacingMode;
import com.sun.star.style.ParagraphAdjust;
import com.sun.star.style.TabAlign;
import com.sun.star.style.TabStop;
import com.sun.star.style.XStyle;
import com.sun.star.style.XStyleFamiliesSupplier;
import com.sun.star.table.ShadowFormat;
import com.sun.star.table.ShadowLocation;
import com.sun.star.text.FontEmphasis;
import com.sun.star.text.ParagraphVertAlign;
import com.sun.star.text.XParagraphCursor;
import com.sun.star.uno.Exception;
import com.sun.star.uno.UnoRuntime;

import HwpDoc.HwpDocInfo.CompatDoc;
import HwpDoc.HwpElement.HwpRecord_BorderFill;
import HwpDoc.HwpElement.HwpRecord_CharShape;
import HwpDoc.HwpElement.HwpRecord_ParaShape;
import HwpDoc.HwpElement.HwpRecord_Style;
import HwpDoc.HwpElement.HwpRecord_TabDef;
import HwpDoc.HwpElement.HwpRecord_CharShape.Outline;
import HwpDoc.HwpElement.HwpRecord_CharShape.Shadow;
import HwpDoc.HwpElement.HwpRecord_TabDef.Tab;

public class ConvPara {
    private static final Logger log = Logger.getLogger(ConvPara.class.getName());
    private static Map<Integer, String> paragraphStyleNameMap = new HashMap<Integer, String>();
    private static Map<Integer, String> characterStyleNameMap = new HashMap<Integer, String>();
    private static final String PARAGRAPH_STYLE_PREFIX = "HWP ";

    static final double PARA_SPACING = 0.85; // 0.75;
    
    public static void reset(WriterContext wContext) {
        deleteCustomStyles(wContext);
    }
	
    private static void deleteCustomStyles(WriterContext wContext) {
        if (wContext.mMyDocument!=null) {
            try {
                XStyleFamiliesSupplier xSupplier = (XStyleFamiliesSupplier)UnoRuntime.queryInterface(XStyleFamiliesSupplier.class, wContext.mMyDocument);
                XNameAccess xFamilies = (XNameAccess) UnoRuntime.queryInterface (XNameAccess.class, xSupplier.getStyleFamilies());
                
                XNameContainer xParagraphFamily = (XNameContainer) UnoRuntime.queryInterface(XNameContainer.class, xFamilies.getByName("ParagraphStyles"));
                for (Integer custIndex: paragraphStyleNameMap.keySet()) {
                    log.info("Deleting "+paragraphStyleNameMap.get(custIndex));
                    if (xParagraphFamily.hasByName(paragraphStyleNameMap.get(custIndex))) {
                        try {
                            xParagraphFamily.removeByName(paragraphStyleNameMap.get(custIndex));
                        } catch (com.sun.star.lang.DisposedException e) {
                            e.printStackTrace();
                        }
                    }
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        paragraphStyleNameMap.clear();
    }

    public static void makeCustomParagraphStyle(WriterContext wContext, int id, HwpRecord_Style hwpStyle) {
        
        HwpRecord_ParaShape paraShape = wContext.getParaShape(hwpStyle.paraShape);
        HwpRecord_CharShape charShape = wContext.getCharShape(hwpStyle.charShape);
        
        try {
            XStyle xListStyle = UnoRuntime.queryInterface(XStyle.class, wContext.mMSF.createInstance("com.sun.star.style.ParagraphStyle"));
            XStyleFamiliesSupplier xSupplier = (XStyleFamiliesSupplier)UnoRuntime.queryInterface(XStyleFamiliesSupplier.class, wContext.mMyDocument);
            XNameAccess xFamilies = (XNameAccess) UnoRuntime.queryInterface (XNameAccess.class, xSupplier.getStyleFamilies());
            XNameContainer xFamily = (XNameContainer) UnoRuntime.queryInterface(XNameContainer.class, xFamilies.getByName("ParagraphStyles"));
            
            String hwpStyleName = PARAGRAPH_STYLE_PREFIX +" "+id+" "+ hwpStyle.name;
            if (xFamily.hasByName(hwpStyleName)==false) {
                xFamily.insertByName (hwpStyleName, xListStyle);
            }
            paragraphStyleNameMap.put(id, hwpStyleName);
            
            XPropertySet xStyleProps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xFamily.getByName(hwpStyleName));
            
            if (paraShape!=null) {
                setParagraphProperties(xStyleProps, paraShape, wContext.getDocInfo().compatibleDoc, charShape.lineSpaceAlpha);
            }
            if (charShape!=null) {
                HwpRecord_BorderFill borderFill = wContext.getBorderFill(charShape.borderFillIDRef);
                setCharacterProperties(xStyleProps, charShape, borderFill, -1);
            }
            
            // NumberingRules 속성을 설정해야  Style이 변경된다. 
            XPropertySet xCursorProps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, wContext.mTextCursor);
            xCursorProps.setPropertyValue("ParaStyleName", "Standard");
            
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    
    public static void makeCustomCharacterStyle(WriterContext wContext, int id, HwpRecord_CharShape charShape) {
        try {
            XStyle xListStyle = UnoRuntime.queryInterface(XStyle.class, wContext.mMSF.createInstance("com.sun.star.style.CharacterStyle"));
            XStyleFamiliesSupplier xSupplier = (XStyleFamiliesSupplier)UnoRuntime.queryInterface(XStyleFamiliesSupplier.class, wContext.mMyDocument);
            XNameAccess xFamilies = (XNameAccess) UnoRuntime.queryInterface (XNameAccess.class, xSupplier.getStyleFamilies());
            XNameContainer xFamily = (XNameContainer) UnoRuntime.queryInterface(XNameContainer.class, xFamilies.getByName("CharacterStyles"));
            
            String hwpStyleName = PARAGRAPH_STYLE_PREFIX +" "+id;
            if (xFamily.hasByName(hwpStyleName)==false) {
                xFamily.insertByName (hwpStyleName, xListStyle);
            }
            characterStyleNameMap.put(id, hwpStyleName);
            
            XPropertySet xStyleProps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xFamily.getByName(hwpStyleName));
            
            if (charShape!=null) {
                HwpRecord_BorderFill borderFill = wContext.getBorderFill(charShape.borderFillIDRef);
                setCharacterProperties(xStyleProps, charShape, borderFill, -1);
            }
            
            // NumberingRules 속성을 설정해야  Style이 변경된다. 
            XPropertySet xCursorProps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, wContext.mTextCursor);
            xCursorProps.setPropertyValue("CharStyleName", "Standard");
            
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    static void setNumberingProperties(XPropertySet xStyleProps, HwpRecord_ParaShape paraShape) {
        String numberingStyleName = "";
        try {
            switch(paraShape.headingType) {
            case NONE:
                xStyleProps.setPropertyValue("NumberingStyleName", "default");
                xStyleProps.setPropertyValue("NumberingLevel", (short) 0);
                break;
            case OUTLINE:
                numberingStyleName = ConvNumbering.getOutlineStyleName();
                xStyleProps.setPropertyValue("NumberingStyleName", numberingStyleName);
                xStyleProps.setPropertyValue("NumberingLevel", (short) (paraShape.headingLevel));
                break;
            case NUMBER:
                log.finest("번호문단ID="+paraShape.headingIdRef + ",문단수준="+paraShape.headingLevel);
                numberingStyleName = ConvNumbering.numberingStyleNameMap.get((int)paraShape.headingIdRef);
                xStyleProps.setPropertyValue("NumberingStyleName", numberingStyleName);
                xStyleProps.setPropertyValue("NumberingLevel", (short) paraShape.headingLevel);
                break;
            case BULLET:
                log.finest("글머리표문단ID="+paraShape.headingIdRef + ",문단수준="+paraShape.headingLevel);
                numberingStyleName = ConvNumbering.bulletStyleNameMap.get((int)paraShape.headingIdRef);
                xStyleProps.setPropertyValue("NumberingStyleName", numberingStyleName);
                xStyleProps.setPropertyValue("NumberingLevel", (short) 0);
                break;
            }
            
            // 문단번호를 설정하면  들여쓰기가 엉망이된다. redundancy 같지만, 들여쓰기를 위해  Margin 설정값을 넣는다.
            xStyleProps.setPropertyValue("ParaLeftMargin", Transform.translateHwp2Office(paraShape.marginLeft/2));
            xStyleProps.setPropertyValue("ParaRightMargin", Transform.translateHwp2Office(paraShape.marginRight/2));
            xStyleProps.setPropertyValue("ParaTopMargin", Transform.translateHwp2Office(paraShape.marginPrev/2));
            xStyleProps.setPropertyValue("ParaBottomMargin", Transform.translateHwp2Office(paraShape.marginNext/2));
            
        } catch (Exception e) {
            e.printStackTrace();
        }
        
    }

    static void setParagraphProperties(XPropertySet xStyleProps, HwpRecord_ParaShape paraShape, CompatDoc compat, double preferSpace) {
        try {
            ParagraphAdjust align = ParagraphAdjust.BLOCK;
            switch(paraShape.align) {
            case LEFT:
                xStyleProps.setPropertyValue("ParaAdjust", ParagraphAdjust.LEFT);
                break;
            case RIGHT:
                xStyleProps.setPropertyValue("ParaAdjust", ParagraphAdjust.RIGHT);
                break;
            case CENTER:
                xStyleProps.setPropertyValue("ParaAdjust", ParagraphAdjust.CENTER);
                break;
            case JUSTIFY:
                xStyleProps.setPropertyValue("ParaAdjust", ParagraphAdjust.LEFT);	// 양쪽정렬은 왼쪽정렬과 조금 더 유사하다. 특히 LINE_BREAK 올때 
                break;
            case DISTRIBUTE:
                xStyleProps.setPropertyValue("ParaAdjust", ParagraphAdjust.BLOCK);
                break;
            case DISTRIBUTE_SPACE:
                xStyleProps.setPropertyValue("ParaAdjust", ParagraphAdjust.STRETCH);
                break;
            }
            // breakLatinWord                       // 줄 나눔 기준 영어 단위 (0:단어, 1:하이픈, 2:글자)
            // breakNonLatinWord                    // 줄 나눔 기준 한글 단위 (0:어절, 1:글자)
            // snapToGrid                           // 편집 용지의 줄 격자 사용 여부
            // condense                             // 공백 최소값 (0%~75%)
            // widowOrphan                          // 외톨이줄 보호 여부
            // keepWithNext                         // 다음 문단과 함께 여부
            xStyleProps.setPropertyValue("ParaKeepTogether", paraShape.keepWithNext);
            // pageBreakBefore                      // 문단 앞에서 항상 쪽 나눔 여부
            // verAlign                             // 세로정렬 (0:글꼴기준, 1:위쪽, 2:가운데, 3:아래)
            short vertAlign = ParagraphVertAlign.CENTER;
            switch(paraShape.vertAlign) {
            case BASELINE:
                vertAlign = ParagraphVertAlign.BOTTOM; // 한컴의 글꼴기준은 LibreOffice의 BOTTOM
                break;
            case TOP:
                vertAlign = ParagraphVertAlign.TOP;
                break;
            case CENTER:
                vertAlign = ParagraphVertAlign.CENTER;
                break;
            case BOTTOM:
                vertAlign = ParagraphVertAlign.BOTTOM; // 한컴의 BOTTOM은 LibreOffice의 BOTTOM보다 더 아래, BOTTOM이 그나마 가장 유사
                break;
            }
            xStyleProps.setPropertyValue("ParaVertAlignment", vertAlign);
            // fontLineHeight                       // 글꼴에 어울리는 줄 높이 여부
            // HeadingType	headingType             // 문단 머리 모양 종류 (0:없음, 1:개요, 2:번호, 3:글머리표(bullet))
            // heading;                             // 번호 문단 ID(Numbering ID) 또는 글머리표 문단 모양 ID(Bullet ID)참조 값
            // headingLevel                         // 문단 수준 (1수준~7수준)
            // connect                              // 문단 테두리 연결 여부
            xStyleProps.setPropertyValue("ParaIsConnectBorder", paraShape.connect);
            // ignoreMargin                         // 문단 여백 무시 여부
            // paraTailShape                        // 문단 꼬리 모양
            // indent                               // 들여쓰기/내어쓰기.   
            // 들여쓰기(+)는 첫줄을 오른쪽으로 얼마나 이동할지..  ParaFirstLineIndent 로 조정
            // 내어쓰기(-)는 두번째줄부터 오른쪽으로 얼마나 이동할지..  LeftMargin +조정하고, 첫줄 -조정
            xStyleProps.setPropertyValue("ParaIsAutoFirstLineIndent", false);
            if (paraShape.indent >= 0) {
                xStyleProps.setPropertyValue("ParaFirstLineIndent", Transform.translateHwp2Office(paraShape.indent/2));
                // marginLeft                       // 왼쪽 여백
                xStyleProps.setPropertyValue("ParaLeftMargin", 
                        paraShape.marginLeft<0 ? 0 : Transform.translateHwp2Office(paraShape.marginLeft/2));
            } else {
                xStyleProps.setPropertyValue("ParaFirstLineIndent", Transform.translateHwp2Office(paraShape.indent/2));
                // marginLeft                       // 왼쪽 여백
                xStyleProps.setPropertyValue("ParaLeftMargin", 
                        paraShape.marginLeft<0 ? 0 : Transform.translateHwp2Office(paraShape.marginLeft/2-paraShape.indent/2));
            }
            
            // marginRight                          // 오른쪽 여백
            xStyleProps.setPropertyValue("ParaRightMargin", 
                    paraShape.marginRight<0 ? 0 : Transform.translateHwp2Office(paraShape.marginRight/2));
            // marginPrev                           // 문단 간격 위 (100 mm)   
            xStyleProps.setPropertyValue("ParaTopMargin", 
                    paraShape.marginPrev<0 ? 0 : Transform.translateHwp2Office(paraShape.marginPrev/2));
            // marginNext                           // 문단 간격 아래
            xStyleProps.setPropertyValue("ParaBottomMargin", 
                    paraShape.marginNext<0 ? 0 : Transform.translateHwp2Office(paraShape.marginNext/2));
            // lineSpacing                          // 줄 간격. 한글2007 이하버전(5.0.2.5 버전 미만)에서 사용.
            //                                      // percent일때:0%~500%, fixed일때:hpwunit또는 글자수,betweenline일때:hwpunit또는글자수
            // lineSpacingType;                     // 줄간격 종류(0:Percent,1:Fixed,2:BetweenLines,4:AtLeast)
            LineSpacing lineSpacing = new LineSpacing();
            switch(paraShape.lineSpacingType) {
            case 0x0:
                lineSpacing.Mode = LineSpacingMode.PROP;
                // 일반텍스트에서는 lineSpacing을 줄인다. HWP 24pt=8.5mm, LO 24pt=11mm, so delta=2.5/11=22.7%
                // 텍스트 상자 내, 테이블 내에서는 lineSpacing을 그대로 반영.
                double scale = 1.0;
                switch(compat) {
                case HWP:
                    scale = preferSpace>0.0?preferSpace:PARA_SPACING;
                    break;
                case MS_WORD:
                    scale = 1.21;
                    break;
                case OLD_HWP:
                default:
                    scale = 1.0;
                }
                lineSpacing.Height = (short)(paraShape.lineSpacing*scale);
                break;
            case 0x1:
                lineSpacing.Mode = LineSpacingMode.FIX;
                lineSpacing.Height = (short)(paraShape.lineSpacing/2*0.352778);	//예) 값:4600, 한컴:23pt, LO:8.113894mm. (1pt=0.352778mm)
                break;
            case 0x2:
                lineSpacing.Mode = LineSpacingMode.LEADING;
                lineSpacing.Height = (short)(paraShape.lineSpacing);
                break;
            case 0x3:
                lineSpacing.Mode = LineSpacingMode.MINIMUM; 
                lineSpacing.Height = (short)(paraShape.lineSpacing);
                break;
            }
            log.finest("lineSpacing="+lineSpacing.Height+"("+lineSpacing.Mode+") <= LineSpacing="+paraShape.lineSpacing + "("+paraShape.lineSpacingType+")");
            
            xStyleProps.setPropertyValue("ParaLineSpacing", lineSpacing);
            // tabDef                               // 탭 정의 아이디(TabDef ID) 참조 값
            HwpRecord_TabDef tabDef = WriterContext.getTabDef(paraShape.tabDef);
            TabStop[] tss = new TabStop[tabDef.count];
            if (tabDef.count>0) {
                for (int i=0; i<tabDef.count; i++) {
                    tss[i] = new TabStop();
                    Tab tab = tabDef.tabs.get(i);
                    switch(tab.type) {
                    case LEFT:
                        tss[i].Alignment = TabAlign.LEFT;
                        break;
                    case RIGHT:
                        tss[i].Alignment = TabAlign.RIGHT;
                        break;
                    case CENTER:
                        tss[i].Alignment = TabAlign.CENTER;
                        break;
                    case DECIMAL:
                        tss[i].Alignment = TabAlign.DECIMAL;
                        tss[i].DecimalChar = 46;
                        break;
                    }
                    switch(tab.leader) {
                    case SOLID:
                    case DASH:
                    case DOT:
                    case DASH_DOT:
                    case DASH_DOT_DOT:
                    case LONG_DASH:
                        tss[i].FillChar = 45;
                        break;
                    default:
                        tss[i].FillChar = 45;
                        break;
                    }
                    tss[i].Position = Math.min(Transform.translateHwp2Office(tab.pos/200), 145)*100;	// 14.5cm
                }
            } else {
                if ((tabDef.attr&0x2)==0x2) {       // 문단 오른쪽 끝 자동 탭
                    tss = new TabStop[1];
                    tss[0] = new TabStop();
                    if (ConvPage.getCurrentPage()!=null) {
                        HwpDoc.section.Page page = ConvPage.getCurrentPage().page;
                        tss[0].Position = Transform.translateHwp2Office(page.width-page.marginLeft-page.marginRight); // 150*100;
                    } else {
                        tss[0].Position = 0;
                    }
                    tss[0].Alignment = TabAlign.RIGHT;
                    tss[0].FillChar = 32;
                } else if ((tabDef.attr&0x1)==0x1) {// 내어쓰기용 자동 탭
                    tss = new TabStop[1];
                    tss[0] = new TabStop();
                    tss[0].Position = 0;
                    tss[0].Alignment = TabAlign.LEFT;
                    tss[0].FillChar = 32;
                }
            }
            xStyleProps.setPropertyValue("ParaTabStops", tss);
            // borderFill                           // 테두리/배경 모양 ID(BorderFill ID) 참조 값
            HwpRecord_BorderFill borders = WriterContext.getBorderFill(paraShape.borderFill);
            if (borders!=null) {
                xStyleProps.setPropertyValue("LeftBorder", Transform.toBorderLine(borders.left));
                xStyleProps.setPropertyValue("RightBorder", Transform.toBorderLine(borders.right));
                xStyleProps.setPropertyValue("TopBorder", Transform.toBorderLine(borders.top));
                xStyleProps.setPropertyValue("BottomBorder", Transform.toBorderLine(borders.bottom));
                if (borders.fill!=null && borders.fill.isColorFill()==true && borders.fill.faceColor!=-1) {
                    xStyleProps.setPropertyValue("ParaBackColor", borders.fill.faceColor);
                }
            }
            // offsetLeft                           // 문단 테두리 왼쪽 간격 (borders-padding-left)
            xStyleProps.setPropertyValue("LeftBorderDistance", Transform.translateHwp2Office(paraShape.offsetLeft));
            // offsetRight                          // 문단 테두리 오른쪽 간격 (borders-padding-right)
            xStyleProps.setPropertyValue("RightBorderDistance", Transform.translateHwp2Office(paraShape.offsetRight));
            // Hwp의 offsetTop, offsetBottom은 문단 간격에 영향을 주지 않는다. 다만 문단의 글자와 테두리 간격을 구분한다.
            // 반면, LibreOffice BorderDistance는 문단 간격에 영향을 준다.
            // offsetTop                            // 문단 테두리 위쪽 간격 (borders-padding-top)
            // xStyleProps.setPropertyValue("TopBorderDistance", Transform.translateHwp2Office(paraShape.offsetTop));
            // offsetBottom                         // 문단 테두리 아래쪽 간격 (borders-padding-bottom)
            // xStyleProps.setPropertyValue("BottomBorderDistance", Transform.translateHwp2Office(paraShape.offsetBottom));
            // 속성2 (5.0.1.7 버전 이상)
            // lineWrap;                            //  한줄로 입력
            // autoSpaceEAsianEng;                  //  한글과 영어 간격을 자동 조절
            // autoSpaceEAsianNum;                  //  한글과 숫자 간격을 자동 조절

            // 테이블 이후 첫문단의 테이블과의 간격을 임의로 조정
            if (paraShape.firstAfterTable) {
                xStyleProps.setPropertyValue("ParaTopMargin", Transform.translateHwp2Office(paraShape.marginPrev/2) 
                                                            + Math.max(0, lineSpacing.Height-100)*10);
                log.finest("ParaTopMargin="+ ((lineSpacing.Height-100)*10));
                // xStyleProps.setPropertyValue("ParaContextMargin", true);
            }
            
            //	https://api.libreoffice.org/docs/idl/ref/servicecom_1_1sun_1_1star_1_1style_1_1ParagraphProperties.html
            //	ParaAdjust,ParaLineSpacing,ParaBackColor,ParaBackTransparent,ParaBackGraphicURL,ParaBackGraphicFilter,ParaBackGraphicLocation,
            //	ParaLeftMargin,ParaRightMargin,ParaTopMargin,ParaBottomMargin,ParaContextMargin,ParaLineNumberCount,ParaLineNumberStartValue,
            //	PageDescName,PageNumberOffset,ParaRegisterModeActive,ParaStyleName,PageStyleName,DropCapFormat,DropCapWholeWord,ParaKeepTogether,ParaSplit,
            //	NumberingLevel,NumberingRules,NumberingStartValue,ParaIsNumberingRestart,NumberingStyleName,ParaOrphans,ParaWidows,ParaShadowFormat,LeftBorder,
            //	RightBorder,TopBorder,BottomBorder,BorderDistance,LeftBorderDistance,RightBorderDistance,TopBorderDistance,BottomBorderDistance,BreakType,
            //	DropCapCharStyleName,ParaFirstLineIndent,ParaIsAutoFirstLineIndent,ParaIsHyphenation,ParaHyphenationMaxHyphens,ParaHyphenationMaxLeadingChars,
            //	ParaHyphenationMaxTrailingChars,ParaVertAlignment,ParaUserDefinedAttributes,NumberingIsNumber,ParaIsConnectBorder,ListId,OutlineLevel,
            //	ContinueingPreviousSubTree,ListLabelString,ParaHyphenationNoCaps,
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    static void setDrawingParagraphProperties(XPropertySet xStyleProps, HwpRecord_ParaShape paraShape, CompatDoc compat, double preferSpace) {
        try {
            ParagraphAdjust align = ParagraphAdjust.BLOCK;
            switch(paraShape.align) {
            case LEFT:
                align = ParagraphAdjust.LEFT;
                break;
            case RIGHT:
                align = ParagraphAdjust.RIGHT;
                break;
            case CENTER:
                align = ParagraphAdjust.CENTER;
                break;
            case JUSTIFY:
            	align = ParagraphAdjust.LEFT;  // 양쪽정렬은 LEFT와 유사. 특히 LINE_BREAK가 있을때
            	break;
            case DISTRIBUTE:
            	align = ParagraphAdjust.BLOCK;
            	break;
            case DISTRIBUTE_SPACE:
                align = ParagraphAdjust.STRETCH;
                break;
            }
            xStyleProps.setPropertyValue("ParaAdjust", align);
            
            if (paraShape.indent >= 0) {
                xStyleProps.setPropertyValue("ParaFirstLineIndent", Transform.translateHwp2Office(paraShape.indent/2));
                // marginLeft                       // 왼쪽 여백
                xStyleProps.setPropertyValue("ParaLeftMargin", 
                        paraShape.marginLeft<0 ? 0 : Transform.translateHwp2Office(paraShape.marginLeft/2));
            } else {
                xStyleProps.setPropertyValue("ParaFirstLineIndent", Transform.translateHwp2Office(paraShape.indent/2));
                // marginLeft                       // 왼쪽 여백
                xStyleProps.setPropertyValue("ParaLeftMargin", 
                        paraShape.marginLeft<0 ? 0 : Transform.translateHwp2Office(paraShape.marginLeft/2-paraShape.indent/2));
            }
            
            // marginRight                          // 오른쪽 여백
            xStyleProps.setPropertyValue("ParaRightMargin", 
                    paraShape.marginRight<0 ? 0 : Transform.translateHwp2Office(paraShape.marginRight/2));
            // marginPrev                           // 문단 간격 위 (100 mm)   
            xStyleProps.setPropertyValue("ParaTopMargin", 
                    paraShape.marginPrev<0 ? 0 : Transform.translateHwp2Office(paraShape.marginPrev/2));
            // marginNext                           // 문단 간격 아래
            xStyleProps.setPropertyValue("ParaBottomMargin", 
                    paraShape.marginNext<0 ? 0 : Transform.translateHwp2Office(paraShape.marginNext/2));
            // lineSpacing                          // 줄 간격. 한글2007 이하버전(5.0.2.5 버전 미만)에서 사용.
            //                                      // percent일때:0%~500%, fixed일때:hpwunit또는 글자수,betweenline일때:hwpunit또는글자수
            // lineSpacingType;                     // 줄간격 종류(0:Percent,1:Fixed,2:BetweenLines,4:AtLeast)
            LineSpacing lineSpacing = new LineSpacing();
            switch(paraShape.lineSpacingType) {
            case 0x0:
                lineSpacing.Mode = LineSpacingMode.PROP;
                // 일반텍스트에서는 lineSpacing을 줄인다. HWP 24pt=8.5mm, LO 24pt=11mm, so delta=2.5/11=22.7%
                // 텍스트 상자 내, 테이블 내에서는 lineSpacing을 그대로 반영.
                double scale = 1.0;
                switch(compat) {
                case HWP:
                    scale = preferSpace>0.0?preferSpace:PARA_SPACING;
                    break;
                case MS_WORD:
                    scale = 1.21;
                    break;
                case OLD_HWP:
                default:
                    scale = 1.0;
                }
                lineSpacing.Height = (short)(paraShape.lineSpacing*scale);
                break;
            case 0x1:
                lineSpacing.Mode = LineSpacingMode.FIX;
                lineSpacing.Height = (short)(paraShape.lineSpacing/2*0.352778);	//예) 값:4600, 한컴:23pt, LO:8.113894mm. (1pt=0.352778mm)
                break;
            case 0x2:
                lineSpacing.Mode = LineSpacingMode.LEADING;
                lineSpacing.Height = (short)(paraShape.lineSpacing);
                break;
            case 0x3:
                lineSpacing.Mode = LineSpacingMode.MINIMUM; 
                lineSpacing.Height = (short)(paraShape.lineSpacing);
                break;
            }
            log.finest("lineSpacing="+lineSpacing.Height+"("+lineSpacing.Mode+") <= LineSpacing="+paraShape.lineSpacing + "("+paraShape.lineSpacingType+")");
            
            xStyleProps.setPropertyValue("ParaLineSpacing", lineSpacing);
            // tabDef                   // 탭 정의 아이디(TabDef ID) 참조 값
            HwpRecord_TabDef tabDef = WriterContext.getTabDef(paraShape.tabDef);
            TabStop[] tss = new TabStop[tabDef.count];
            if (tabDef.count>0) {
                for (int i=0; i<tabDef.count; i++) {
                    tss[i] = new TabStop();
                    Tab tab = tabDef.tabs.get(i);
                    switch(tab.type) {
                    case LEFT:
                        tss[i].Alignment = TabAlign.LEFT;
                        break;
                    case RIGHT:
                        tss[i].Alignment = TabAlign.RIGHT;
                        break;
                    case CENTER:
                        tss[i].Alignment = TabAlign.CENTER;
                        break;
                    case DECIMAL:
                        tss[i].Alignment = TabAlign.DECIMAL;
                        tss[i].DecimalChar = 46;
                        break;
                    }
                    switch(tab.leader) {
                    case SOLID:
                    case DASH:
                    case DOT:
                    case DASH_DOT:
                    case DASH_DOT_DOT:
                    case LONG_DASH:
                        tss[i].FillChar = 45;
                        break;
                    default:
                        tss[i].FillChar = 45;
                        break;
                    }
                    tss[i].Position = Math.min(Transform.translateHwp2Office(tab.pos/200), 145)*100;	// 14.5cm
                }
            } else {
                if ((tabDef.attr&0x2)==0x2) {       // 문단 오른쪽 끝 자동 탭
                    tss = new TabStop[1];
                    tss[0] = new TabStop();
                    HwpDoc.section.Page page = ConvPage.getCurrentPage().page;
                    tss[0].Position = Transform.translateHwp2Office(page.width-page.marginLeft-page.marginRight); // 150*100;
                    tss[0].Alignment = TabAlign.RIGHT;
                    tss[0].FillChar = 32;
                } else if ((tabDef.attr&0x1)==0x1) {// 내어쓰기용 자동 탭
                    tss = new TabStop[1];
                    tss[0] = new TabStop();
                    tss[0].Position = 0;
                    tss[0].Alignment = TabAlign.LEFT;
                    tss[0].FillChar = 32;
                }
            }
            xStyleProps.setPropertyValue("ParaTabStops", tss);
            // borderFill                           // 테두리/배경 모양 ID(BorderFill ID) 참조 값
            HwpRecord_BorderFill borders = WriterContext.getBorderFill(paraShape.borderFill);
            if (borders!=null) {
                if (borders.fill!=null && borders.fill.isColorFill()==true && borders.fill.faceColor!=-1) {
                    xStyleProps.setPropertyValue("ParaBackColor", borders.fill.faceColor);
                }
            }
            
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    static void setMinimumParagraphProperties(XPropertySet xStyleProps) {
        try {
            xStyleProps.setPropertyValue("ParaAdjust", ParagraphAdjust.BLOCK);
            xStyleProps.setPropertyValue("ParaVertAlignment", ParagraphVertAlign.CENTER);
            xStyleProps.setPropertyValue("ParaIsAutoFirstLineIndent", false);
            xStyleProps.setPropertyValue("ParaTopMargin", 0);
            xStyleProps.setPropertyValue("ParaBottomMargin", 0);
            LineSpacing lineSpacing = new LineSpacing();
            lineSpacing.Mode = LineSpacingMode.PROP;
            lineSpacing.Height = 100; // 비례 100%
            xStyleProps.setPropertyValue("ParaLineSpacing", lineSpacing);
            xStyleProps.setPropertyValue("LeftBorderDistance", 0);
            xStyleProps.setPropertyValue("RightBorderDistance", 0);
            xStyleProps.setPropertyValue("TopBorderDistance", 0);
            xStyleProps.setPropertyValue("BottomBorderDistance", 0);

        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    static void setCharacterProperties(XPropertySet xStyleProps, HwpRecord_CharShape charShape, 
                                        HwpRecord_BorderFill borderFill, int step) {
        try {
            if (charShape.fontName[1]!=null) {
                xStyleProps.setPropertyValue("CharFontName", charShape.fontName[1]);
            }
            if (charShape.fontName[0]!=null) {
                xStyleProps.setPropertyValue("CharFontNameAsian", charShape.fontName[0]);
            }
            
            // charShape.fontID[0];                 // 언어별 글꼴ID(FaceID)         // f#
            // charShape.ratio[0];                  // 언어별 장평, 50%~200%         // r#
            if (WriterContext.fontNameSet.contains(charShape.fontName[0])) {
                xStyleProps.setPropertyValue("CharScaleWidth", charShape.ratio[0]);
            } else {
                // 일치하는 폰트가 리브레오피스에 없으면, 무조건 100%로 맞춘다. 100% 미만에서 폰트너비가 커지는 버그 존재
                xStyleProps.setPropertyValue("CharScaleWidth", (short)100);
            }
            
            // charShape.spacing[0];                // 언어별 자간, -50%~50%         // s#
            // 리브레오피스 자간거리(pt) = y ; (폰트크기(pt)* 한컴자간(%) = x ; 가중치 a = 0.85 ; 절편 b = 0.5
            double spacing = ((double)charShape.height)/100 * (charShape.spacing[0]/100.0f) * 0.8 + 0.4;
            // 1pt = 0.35278mm = 35.278 (1/100 mm)
            spacing *= 35.278;
            xStyleProps.setPropertyValue("CharKerning", (short)Math.round(spacing));
            // charShape.relSize[0];                // 언어별 상대 크기, 10%~250%	     // e#
            // charShape.charOffset[0];             // 언어별 글자 위치, -100%~100%   // o#
            // charShape.height;                    // 기준 크기, 0pt~4096pt        // he
            xStyleProps.setPropertyValue("CharHeight", (float)charShape.height*(charShape.relSize[1]/100.0f)/100.0f);	// 1000 (10.0pt)
            xStyleProps.setPropertyValue("CharHeightAsian", (float)charShape.height*(charShape.relSize[0]/100.0f)/100.0f);	// 1000 (10.0pt)
            
            // charShape.bold;                      // 진하게 여부                   // bo
            if (charShape.bold) {
                xStyleProps.setPropertyValue("CharWeight", FontWeight.BOLD);
                xStyleProps.setPropertyValue("CharWeightAsian", FontWeight.BOLD);
            } else {
                xStyleProps.setPropertyValue("CharWeight", FontWeight.NORMAL);
                xStyleProps.setPropertyValue("CharWeightAsian", FontWeight.NORMAL);
            }
            // charShape.italic;                    // 기울임 여부                   // it
            if (charShape.italic) {
                xStyleProps.setPropertyValue("CharPosture", FontSlant.ITALIC);
                xStyleProps.setPropertyValue("CharPostureAsian", FontSlant.ITALIC);
            } else {
                xStyleProps.setPropertyValue("CharPosture", FontSlant.NONE);
                xStyleProps.setPropertyValue("CharPostureAsian", FontSlant.NONE);
            }
            
            // charShape.underline;                 // 밑줄 종류                    // ut
            // charShape.underlineShape;            // 밑줄 모양                    // us
            if (charShape.underline!=null) {
                switch(charShape.underline) {
                case NONE:
                    xStyleProps.setPropertyValue("CharUnderline", FontUnderline.NONE);
                    break;
                case BOTTOM:
                case CENTER:
                case TOP:
                    switch (charShape.underlineShape) {
                    case SOLID:
                        xStyleProps.setPropertyValue("CharUnderline", FontUnderline.SINGLE);
                        break;
                    case DASH:
                        xStyleProps.setPropertyValue("CharUnderline", FontUnderline.DASH);
                        break;
                    case DOT:
                        xStyleProps.setPropertyValue("CharUnderline", FontUnderline.DOTTED);
                        break;
                    case DASH_DOT:
                        xStyleProps.setPropertyValue("CharUnderline", FontUnderline.DASHDOT);
                        break;
                    case DASH_DOT_DOT:
                        xStyleProps.setPropertyValue("CharUnderline", FontUnderline.DASHDOTDOT);
                        break;
                    case LONG_DASH:
                        xStyleProps.setPropertyValue("CharUnderline", FontUnderline.LONGDASH);
                        break;
                    case DOUBLE_SLIM:
                        xStyleProps.setPropertyValue("CharUnderline", FontUnderline.DOUBLE);
                        break;
                    case CIRCLE:
                    case SLIM_THICK:
                    case THICK_SLIM:
                    case SLIM_THICK_SLIM:
                        xStyleProps.setPropertyValue("CharUnderline", FontUnderline.SINGLE);
                        break;
                    default:
                        break;
                    }
                    break;
                }
            }
            // charShape.underlineColor;            // 밑줄 색
            xStyleProps.setPropertyValue("CharUnderlineColor", charShape.underlineColor);
            // charShape.outline;                   // 외곽선종류                    //
            if (charShape.outline==Outline.NONE) {
                xStyleProps.setPropertyValue("CharContoured", false);
            } else {
                xStyleProps.setPropertyValue("CharContoured", true);
            }
            
            // charShape.emboss;                    // 양각 여부                    // em?
            // charShape.engrave;                   // 음각 여부                    // en?
            if (charShape.emboss) {
                xStyleProps.setPropertyValue("CharRelief", FontRelief.EMBOSSED);
            } else if (charShape.engrave) {
                xStyleProps.setPropertyValue("CharRelief", FontRelief.ENGRAVED);
            } else {
                xStyleProps.setPropertyValue("CharRelief", FontRelief.NONE);
            }
            // charShape.superScript;               // 위 첨자 여부                  // su?
            // charShape.subScript;                 // 아래 첨자 여부                 // sb?
            
            // charShape.strikeOut;                 // 취소선 여부
            //	charShape.strikeOutShape;           // 취소선 모양
            //	charShape.strikeOutColor;           // 취소선 색
            if (charShape.strikeOut!=0) {
                switch(charShape.strikeOutShape) {
                case SOLID:
                    xStyleProps.setPropertyValue("CharStrikeout", FontStrikeout.SINGLE);
                    break;
                case DASH:
                    xStyleProps.setPropertyValue("CharStrikeout", FontStrikeout.SINGLE);
                    break;
                case DOT:
                case DASH_DOT:
                case DASH_DOT_DOT:
                case LONG_DASH:
                    xStyleProps.setPropertyValue("CharStrikeout", FontStrikeout.SINGLE);
                    break;
                case DOUBLE_SLIM:
                    xStyleProps.setPropertyValue("CharStrikeout", FontStrikeout.DOUBLE);
                    break;
                case CIRCLE:
                case SLIM_THICK:
                case THICK_SLIM:
                case SLIM_THICK_SLIM:
                    xStyleProps.setPropertyValue("CharUnderline", FontUnderline.SINGLE);
                    break;
                default:
                    break;
                }
            }
            
            //charShape.symMark;                    // 강조점 종류
            xStyleProps.setPropertyValue("CharEmphasis", FontEmphasis.NONE);
            
            //charShape.useFontSpace;               // 글꼴에 어울리는 빈칸 사용 여부      // uf?
            //charShape.useKerning;                 // kerning여부                 // uk?
            //charShape.textColor;                  // 글자 색                      //
            xStyleProps.setPropertyValue("CharColor", charShape.textColor);

         // shadeColor보다 fill.faceColor가 우선한다.
            if (borderFill!=null && borderFill.fill.isColorFill()) {
                if (borderFill.fill.faceColor==0xFFFFFFFF) {
                    //charShape.shadeColor;                 // 음영 색
                    if (charShape.shadeColor != 0xFFFFFFFF) {
                        xStyleProps.setPropertyValue("CharBackColor", charShape.shadeColor);
                    }
                } else {
                    xStyleProps.setPropertyValue("CharBackColor", borderFill.fill.faceColor);
                }
            } else {
                if (charShape.shadeColor != 0xFFFFFFFF) {
                    xStyleProps.setPropertyValue("CharBackColor", charShape.shadeColor);
                }
            }
            
            //	charShape.shadow;                   // 그림자 종류                    // 
            //	charShape.shadowSpacing;            // 그림자 간격, -100%~100%
            //	charShape.shadowColor;              // 그림자 색
            if (charShape.shadow!=Shadow.NONE && charShape.shadowColor!=0) {
                ShadowFormat sf = new ShadowFormat();
                sf.Location = ShadowLocation.BOTTOM_RIGHT;
                sf.ShadowWidth = charShape.shadowOffsetX;
                sf.IsTransparent = false;
                sf.Color = charShape.shadowColor;
                xStyleProps.setPropertyValue("CharShadowed", true);
                xStyleProps.setPropertyValue("CharShadowFormat", sf);
            }
            //	charShape.borderFillId;             // 글자 테두리/배경 ID(CharShapeBorderFill ID) 참조 값
            
            if (step>=0) {
                // 위 첨자, 아래 첨자 처리
                if (charShape.superScript) {
                    xStyleProps.setPropertyValue("CharAutoEscapement", true);
                    xStyleProps.setPropertyValue("CharEscapement", (short)14000);
                    xStyleProps.setPropertyValue("CharEscapementHeight", (byte)58);
                } else if (charShape.subScript) {
                    xStyleProps.setPropertyValue("CharAutoEscapement", true);
                    xStyleProps.setPropertyValue("CharEscapement", (short)-14000);
                    xStyleProps.setPropertyValue("CharEscapementHeight", (byte)58);
                } else {
                    xStyleProps.setPropertyValue("CharEscapement", (short)0);
                    xStyleProps.setPropertyValue("CharEscapementHeight", (byte)100);
                }
            }
            
            //	https://api.libreoffice.org/docs/idl/ref/servicecom_1_1sun_1_1star_1_1style_1_1CharacterProperties.html
            //	CharFontName,CharFontStyleName,CharFontFamily,CharFontCharSet,CharFontPitch,CharColor,CharHeight,CharUnderline,CharWeight,CharPosture,
            //	CharAutoKerning,CharBackColor,CharShadingValue,CharBackTransparent,CharCaseMap,CharCrossedOut,CharFlash,CharStrikeout,CharWordMode,CharKerning,CharLocale,
            //	CharKeepTogether,CharNoLineBreak,CharShadowed,CharFontType,CharStyleName,CharContoured,CharCombineIsOn,CharCombinePrefix,CharCombineSuffix,CharEmphasis
            //	CharRelief,RubyText,RubyAdjust,RubyCharStyleName,RubyIsAbove,CharRotation,CharRotationIsFitToLine,CharScaleWidth,HyperLinkURL,HyperLinkTarget,HyperLinkName
            //	VisitedCharStyleName,UnvisitedCharStyleName,CharEscapementHeight,CharNoHyphenation,CharUnderlineColor,CharUnderlineHasColor,CharHidden,TextUserDefinedAttributes
            //	CharLeftBorder,CharRightBorder,CharTopBorder,CharBottomBorder,CharBorderDistance,CharLeftBorderDistance,CharRightBorderDistance,CharTopBorderDistance
            //	CharBottomBorderDistance,CharShadowFormat,CharHighlight,RubyPosition
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    
    static void setDrawingCharacterProperties(XPropertySet xStyleProps, HwpRecord_CharShape charShape, int step) {
        try {
            xStyleProps.setPropertyValue("CharFontName", charShape.fontName[1]);
            // paraProps.setPropertyValue("CharFontStyleName", faceName.faceName);
            xStyleProps.setPropertyValue("CharFontNameAsian", charShape.fontName[0]);
            // paraProps.setPropertyValue("CharFontStyleNameAsian", faceName.faceName);
            
            // charShape.fontID[0];                 // 언어별 글꼴ID(FaceID)         // f#
            // charShape.ratio[0];                  // 언어별 장평, 50%~200%         // r#
            log.finest("CharWidth="+charShape.ratio[0]);
            xStyleProps.setPropertyValue("CharScaleWidth", charShape.ratio[0]);
            // charShape.spacing[0];                // 언어별 자간, -50%~50%         // s#
            // 리브레오피스 자간거리(pt) = y ; (폰트크기(pt)*한컴자간(%) = x ; 가중치 a = 0.85 ; 절편 b = 0.5
            double spacing = ((double)charShape.height)/100 * (charShape.spacing[0] / 100.0f) * 0.8 + 0.4; 
            // 1pt = 0.35278mm = 35.278 (1/100 mm)
            spacing *= 35.278;
            xStyleProps.setPropertyValue("CharKerning", (short)Math.round(spacing));
            // charShape.relSize[0];                // 언어별 상대 크기, 10%~250%	     // e#
            // charShape.charOffset[0];             // 언어별 글자 위치, -100%~100%   // o#
            // charShape.height;                    // 기준 크기, 0pt~4096pt        // he
            xStyleProps.setPropertyValue("CharHeight", (float)charShape.height*(charShape.relSize[1]/100.0f)/100.0f);	// 1000 (10.0pt)
            xStyleProps.setPropertyValue("CharHeightAsian", (float)charShape.height*(charShape.relSize[0]/100.0f)/100.0f);	// 1000 (10.0pt)
            
            // charShape.bold;                      // 진하게 여부                   // bo
            if (charShape.bold) {
                xStyleProps.setPropertyValue("CharWeight", FontWeight.BOLD);
                xStyleProps.setPropertyValue("CharWeightAsian", FontWeight.BOLD);
            } else {
                xStyleProps.setPropertyValue("CharWeight", FontWeight.NORMAL);
                xStyleProps.setPropertyValue("CharWeightAsian", FontWeight.NORMAL);
            }
            // charShape.italic;                    // 기울임 여부                   // it
            if (charShape.italic) {
                xStyleProps.setPropertyValue("CharPosture", FontSlant.ITALIC);
                xStyleProps.setPropertyValue("CharPostureAsian", FontSlant.ITALIC);
            } else {
                xStyleProps.setPropertyValue("CharPosture", FontSlant.NONE);
                xStyleProps.setPropertyValue("CharPostureAsian", FontSlant.NONE);
            }
            
            // charShape.underline;                 // 밑줄 종류                    // ut
            // charShape.underlineShape;            // 밑줄 모양                    // us
            if (charShape.underline!=null) {
                switch(charShape.underline) {
                case NONE:
                    xStyleProps.setPropertyValue("CharUnderline", FontUnderline.NONE);
                    break;
                case BOTTOM:
                case CENTER:
                case TOP:
                    switch (charShape.underlineShape) {
                    case SOLID:
                        xStyleProps.setPropertyValue("CharUnderline", FontUnderline.SINGLE);
                        break;
                    case DASH:
                        xStyleProps.setPropertyValue("CharUnderline", FontUnderline.DASH);
                        break;
                    case DOT:
                        xStyleProps.setPropertyValue("CharUnderline", FontUnderline.DOTTED);
                        break;
                    case DASH_DOT:
                        xStyleProps.setPropertyValue("CharUnderline", FontUnderline.DASHDOT);
                        break;
                    case DASH_DOT_DOT:
                        xStyleProps.setPropertyValue("CharUnderline", FontUnderline.DASHDOTDOT);
                        break;
                    case LONG_DASH:
                        xStyleProps.setPropertyValue("CharUnderline", FontUnderline.LONGDASH);
                        break;
                    case DOUBLE_SLIM:
                        xStyleProps.setPropertyValue("CharUnderline", FontUnderline.DOUBLE);
                        break;
                    case CIRCLE:
                    case SLIM_THICK:
                    case THICK_SLIM:
                    case SLIM_THICK_SLIM:
                        xStyleProps.setPropertyValue("CharUnderline", FontUnderline.SINGLE);
                        break;
                    default:
                        break;
                    }
                    break;
                }
            }
            // charShape.underlineColor;            // 밑줄 색
            xStyleProps.setPropertyValue("CharUnderlineColor", charShape.underlineColor);
            // charShape.outline;                   // 외곽선종류                    //
            if (charShape.outline==Outline.NONE) {
                xStyleProps.setPropertyValue("CharContoured", false);
            } else {
                xStyleProps.setPropertyValue("CharContoured", true);
            }
            
            // charShape.emboss;                    // 양각 여부                    // em?
            // charShape.engrave;                   // 음각 여부                    // en?
            if (charShape.emboss) {
                xStyleProps.setPropertyValue("CharRelief", FontRelief.EMBOSSED);
            } else if (charShape.engrave) {
                xStyleProps.setPropertyValue("CharRelief", FontRelief.ENGRAVED);
            } else {
                xStyleProps.setPropertyValue("CharRelief", FontRelief.NONE);
            }
            // charShape.superScript;               // 위 첨자 여부                  // su?
            // charShape.subScript;                 // 아래 첨자 여부                 // sb?
            
            // charShape.strikeOut;                 // 취소선 여부
            //	charShape.strikeOutShape;           // 취소선 모양
            //	charShape.strikeOutColor;           // 취소선 색
            if (charShape.strikeOut!=0) {
                switch(charShape.strikeOutShape) {
                case SOLID:
                    xStyleProps.setPropertyValue("CharStrikeout", FontStrikeout.SINGLE);
                    break;
                case DASH:
                    xStyleProps.setPropertyValue("CharStrikeout", FontStrikeout.SINGLE);
                    break;
                case DOT:
                case DASH_DOT:
                case DASH_DOT_DOT:
                case LONG_DASH:
                    xStyleProps.setPropertyValue("CharStrikeout", FontStrikeout.SINGLE);
                    break;
                case DOUBLE_SLIM:
                    xStyleProps.setPropertyValue("CharStrikeout", FontStrikeout.DOUBLE);
                    break;
                case CIRCLE:
                case SLIM_THICK:
                case THICK_SLIM:
                case SLIM_THICK_SLIM:
                    xStyleProps.setPropertyValue("CharUnderline", FontUnderline.SINGLE);
                    break;
                default:
                    break;
                }
            }
            
            //charShape.symMark;                    // 강조점 종류
            xStyleProps.setPropertyValue("CharEmphasis", FontEmphasis.NONE);
            
            //charShape.useFontSpace;               // 글꼴에 어울리는 빈칸 사용 여부      // uf?
            //charShape.useKerning;                 // kerning여부                 // uk?
            //charShape.textColor;                  // 글자 색	                     //
            xStyleProps.setPropertyValue("CharColor", charShape.textColor);
            
            //charShape.shadeColor;                 // 음영 색
            if (charShape.shadeColor != 0xFFFFFFFF) {
                xStyleProps.setPropertyValue("CharBackColor", charShape.shadeColor);
            }

            
            //	charShape.shadow;                   // 그림자 종류                   // 
            //	charShape.shadowSpacing;            // 그림자 간격, -100%~100%
            //	charShape.shadowColor;              // 그림자 색
            if (charShape.shadow!=Shadow.NONE) {
                xStyleProps.setPropertyValue("CharShadowed", true);
            }
            //	charShape.borderFillId;             // 글자 테두리/배경 ID(CharShapeBorderFill ID) 참조 값

            //	https://api.libreoffice.org/docs/idl/ref/servicecom_1_1sun_1_1star_1_1style_1_1CharacterProperties.html
            //	CharFontName,CharFontStyleName,CharFontFamily,CharFontCharSet,CharFontPitch,CharColor,CharEscapement,CharHeight,CharUnderline,CharWeight,CharPosture,
            //	CharAutoKerning,CharBackColor,CharShadingValue,CharBackTransparent,CharCaseMap,CharCrossedOut,CharFlash,CharStrikeout,CharWordMode,CharKerning,CharLocale,
            //	CharKeepTogether,CharNoLineBreak,CharShadowed,CharFontType,CharStyleName,CharContoured,CharCombineIsOn,CharCombinePrefix,CharCombineSuffix,CharEmphasis
            //	CharRelief,RubyText,RubyAdjust,RubyCharStyleName,RubyIsAbove,CharRotation,CharRotationIsFitToLine,CharScaleWidth,HyperLinkURL,HyperLinkTarget,HyperLinkName
            //	VisitedCharStyleName,UnvisitedCharStyleName,CharEscapementHeight,CharNoHyphenation,CharUnderlineColor,CharUnderlineHasColor,CharHidden,TextUserDefinedAttributes
            //	CharLeftBorder,CharRightBorder,CharTopBorder,CharBottomBorder,CharBorderDistance,CharLeftBorderDistance,CharRightBorderDistance,CharTopBorderDistance
            //	CharBottomBorderDistance,CharShadowFormat,CharHighlight,RubyPosition
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    
    public static void setDefaultParaStyle(WriterContext wContext) {
        try {
            XParagraphCursor xParaCursor = (XParagraphCursor) UnoRuntime.queryInterface(XParagraphCursor.class, wContext.mTextCursor);
            xParaCursor.gotoEnd(false);
            XPropertySet xParaProps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xParaCursor);
            String styleName = getStyleName(0);
            xParaProps.setPropertyValue ("ParaStyleName", styleName);
            xParaProps.setPropertyValue ("NumberingStyleName", "default");
            xParaProps.setPropertyValue ("NumberingLevel", (short) 0);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    static String getStyleName(int styleID) {
        return paragraphStyleNameMap.get(styleID);
    }

    static String getCharStyleName(int styleID) {
        return characterStyleNameMap.get(styleID);
    }

    
}