@@ -12,18 +12,111 @@ public class StyleFactory
1212 {
1313 public Style GenerateStyle ( JObject jObject )
1414 {
15- return new Style
15+ string size ;
16+ if ( int . TryParse ( ( string ) jObject [ "字体大小" ] , out int sz ) )
17+ {
18+ size = sz . ToString ( ) ;
19+ }
20+ else
21+ {
22+ size = fontmap [ ( string ) jObject [ "字体大小" ] ] ;
23+ }
24+ Style style = new Style
1625 {
1726 Type = StyleValues . Paragraph ,
1827 StyleId = ( string ) jObject [ "名称" ] ,
1928 StyleName = new StyleName { Val = ( string ) jObject [ "名称" ] } ,
29+ StyleParagraphProperties = new StyleParagraphProperties
30+ {
31+ Justification = new Justification { Val = justmap [ ( string ) jObject [ "对齐方式" ] ] }
32+ } ,
2033 StyleRunProperties = new StyleRunProperties
2134 {
2235 RunFonts = new RunFonts { Ascii = ( string ) jObject [ "英文字体" ] , HighAnsi = ( string ) jObject [ "英文字体" ] , ComplexScript = ( string ) jObject [ "英文字体" ] , EastAsia = ( string ) jObject [ "中文字体" ] } ,
23- FontSize = new FontSize { Val = ( string ) jObject [ "字体大小" ] } ,
24- FontSizeComplexScript = new FontSizeComplexScript { Val = ( string ) jObject [ "字体大小" ] }
36+ FontSize = new FontSize { Val = size } ,
37+ FontSizeComplexScript = new FontSizeComplexScript { Val = size }
2538 }
2639 } ;
40+ if ( ( bool ) jObject [ "录入大纲" ] )
41+ {
42+ style . StyleParagraphProperties . OutlineLevel = new OutlineLevel { Val = ( int ) jObject [ "大纲等级" ] } ;
43+ }
44+ if ( ( bool ) jObject [ "加粗" ] )
45+ {
46+ style . StyleRunProperties . Bold = new Bold ( ) ;
47+ style . StyleRunProperties . BoldComplexScript = new BoldComplexScript ( ) ;
48+ }
49+ if ( ( bool ) jObject [ "斜体" ] )
50+ {
51+ style . StyleRunProperties . Italic = new Italic ( ) ;
52+ style . StyleRunProperties . ItalicComplexScript = new ItalicComplexScript ( ) ;
53+ }
54+ if ( ( bool ) jObject [ "下划线" ] )
55+ {
56+ style . StyleRunProperties . Underline = new Underline ( ) ;
57+ }
58+ if ( ( bool ) jObject [ "删除线" ] )
59+ {
60+ style . StyleRunProperties . Strike = new Strike ( ) ;
61+ }
62+ if ( ( bool ) jObject [ "段前分页" ] )
63+ {
64+ style . StyleParagraphProperties . PageBreakBefore = new PageBreakBefore ( ) ;
65+ }
66+
67+ if ( ( float ) jObject [ "首行缩进" ] != 0f )
68+ {
69+ style . StyleParagraphProperties . Indentation = new Indentation
70+ {
71+ FirstLineChars = ( int ) ( ( float ) jObject [ "首行缩进" ] * 100 )
72+ } ;
73+ }
74+ if ( ( float ) jObject [ "段前后空行" ] != 0f )
75+ {
76+ style . StyleParagraphProperties . SpacingBetweenLines = new SpacingBetweenLines
77+ {
78+ BeforeLines = ( int ) ( ( float ) jObject [ "段前后空行" ] * 100 ) ,
79+ AfterLines = ( int ) ( ( float ) jObject [ "段前后空行" ] * 100 )
80+ } ;
81+ }
82+ if ( ( float ) jObject [ "行距" ] != 0f )
83+ {
84+ style . StyleParagraphProperties . SpacingBetweenLines = style . StyleParagraphProperties . SpacingBetweenLines ?? new SpacingBetweenLines ( ) ;
85+ style . StyleParagraphProperties . SpacingBetweenLines . Line = ( ( int ) ( ( float ) jObject [ "行距" ] * 240 ) ) . ToString ( ) ;
86+ style . StyleParagraphProperties . SpacingBetweenLines . LineRule = LineSpacingRuleValues . Auto ;
87+ }
88+
89+ return style ;
2790 }
91+ #region Chinese font mapping
92+ static readonly Dictionary < string , string > fontmap = new Dictionary < string , string >
93+ {
94+ { "初号" , "84" } ,
95+ { "小初" , "72" } ,
96+ { "一号" , "52" } ,
97+ { "小一" , "48" } ,
98+ { "二号" , "44" } ,
99+ { "小二" , "36" } ,
100+ { "三号" , "32" } ,
101+ { "小三" , "30" } ,
102+ { "四号" , "28" } ,
103+ { "小四" , "24" } ,
104+ { "五号" , "21" } ,
105+ { "小五" , "18" } ,
106+ { "六号" , "15" } ,
107+ { "小六" , "13" } ,
108+ { "七号" , "11" } ,
109+ { "八号" , "10" }
110+ } ;
111+ #endregion
112+ #region justification mapping
113+ static readonly Dictionary < string , JustificationValues > justmap = new Dictionary < string , JustificationValues >
114+ {
115+ { "左对齐" , JustificationValues . Left } ,
116+ { "居中" , JustificationValues . Center } ,
117+ { "右对齐" , JustificationValues . Right } ,
118+ { "分散对齐" , JustificationValues . Distribute }
119+ } ;
120+ #endregion
28121 }
29122}
0 commit comments