private DemoStyleSheet SetupStyles() { var stylesheet = new DemoStyleSheet(); var nonCharStyled = new DemoStyle { DefaultCharacterStyleInfo = new DemoCharStyleInfo(), Name = "No Character Style" }; var nonParaStyled = new DemoStyle { ParagraphStyleInfo = new DemoParaStyleInfo(), Name = "No Paragraph Style" }; var normal = new DemoStyle { DefaultCharacterStyleInfo = new DemoCharStyleInfo { FontSize = new DemoStyleProp <int> { Value = 10000 } }, Name = "Normal" }; var bold = new DemoStyle { DefaultCharacterStyleInfo = new DemoCharStyleInfo { Bold = new DemoStyleProp <bool> { Value = true } }, Name = "Bold" }; var italic = new DemoStyle { DefaultCharacterStyleInfo = new DemoCharStyleInfo { Italic = new DemoStyleProp <bool> { Value = true } }, Name = "Italic" }; var boldItalic = new DemoStyle { DefaultCharacterStyleInfo = new DemoCharStyleInfo { Bold = new DemoStyleProp <bool> { Value = true }, Italic = new DemoStyleProp <bool> { Value = true } }, Name = "Bold Italic" }; var redOnYellow = new DemoStyle { DefaultCharacterStyleInfo = new DemoCharStyleInfo { FontColor = new DemoStyleProp <Color> { Value = Color.Red }, BackColor = new DemoStyleProp <Color> { Value = Color.Yellow } }, Name = "Red on Yellow" }; var left = new DemoStyle { ParagraphStyleInfo = new DemoParaStyleInfo { Alignment = new DemoStyleProp <FwTextAlign> { Value = FwTextAlign.ktalLeft } }, Name = "Left" }; var right = new DemoStyle { ParagraphStyleInfo = new DemoParaStyleInfo { Alignment = new DemoStyleProp <FwTextAlign> { Value = FwTextAlign.ktalRight } }, Name = "Right" }; var center = new DemoStyle { ParagraphStyleInfo = new DemoParaStyleInfo { Alignment = new DemoStyleProp <FwTextAlign> { Value = FwTextAlign.ktalCenter } }, Name = "Center" }; var justify = new DemoStyle { ParagraphStyleInfo = new DemoParaStyleInfo { Alignment = new DemoStyleProp <FwTextAlign> { Value = FwTextAlign.ktalJustify } }, Name = "Justify" }; var lineHeight = new DemoStyle { ParagraphStyleInfo = new DemoParaStyleInfo { LineHeight = new DemoStyleProp <LineHeightInfo> { Value = new LineHeightInfo(20000, false) } }, Name = "LineHeight" }; var border = new DemoStyle { ParagraphStyleInfo = new DemoParaStyleInfo { BorderBottom = new DemoStyleProp <int> { Value = 5 }, BorderLeading = new DemoStyleProp <int> { Value = 5 }, BorderTop = new DemoStyleProp <int> { Value = 5 }, BorderTrailing = new DemoStyleProp <int> { Value = 5 }, BorderColor = new DemoStyleProp <Color> { Value = Color.Red } }, Name = "Border" }; var margin = new DemoStyle { ParagraphStyleInfo = new DemoParaStyleInfo { MarginBottom = new DemoStyleProp <int> { Value = 10 }, MarginLeading = new DemoStyleProp <int> { Value = 10 }, MarginTop = new DemoStyleProp <int> { Value = 10 }, MarginTrailing = new DemoStyleProp <int> { Value = 10 }, BorderBottom = new DemoStyleProp <int> { Value = 1 }, BorderLeading = new DemoStyleProp <int> { Value = 1 }, BorderTop = new DemoStyleProp <int> { Value = 1 }, BorderTrailing = new DemoStyleProp <int> { Value = 1 }, BorderColor = new DemoStyleProp <Color> { Value = Color.Black } }, Name = "Margin" }; var padding = new DemoStyle { ParagraphStyleInfo = new DemoParaStyleInfo { PadBottom = new DemoStyleProp <int> { Value = 10 }, PadLeading = new DemoStyleProp <int> { Value = 10 }, PadTop = new DemoStyleProp <int> { Value = 10 }, PadTrailing = new DemoStyleProp <int> { Value = 10 }, BorderBottom = new DemoStyleProp <int> { Value = 1 }, BorderLeading = new DemoStyleProp <int> { Value = 1 }, BorderTop = new DemoStyleProp <int> { Value = 1 }, BorderTrailing = new DemoStyleProp <int> { Value = 1 }, BorderColor = new DemoStyleProp <Color> { Value = Color.Black } }, Name = "Padding" }; var firstLineIndent = new DemoStyle { ParagraphStyleInfo = new DemoParaStyleInfo { FirstLineIndent = new DemoStyleProp <int> { Value = -10000 } }, Name = "FirstLineIndent" }; stylesheet.SetStyle("No Character Style", nonCharStyled); stylesheet.SetStyle("No Paragraph Style", nonParaStyled); stylesheet.SetStyle("Normal", normal); stylesheet.SetStyle("Bold", bold); stylesheet.SetStyle("Italic", italic); stylesheet.SetStyle("Bold Italic", boldItalic); stylesheet.SetStyle("Red on Yellow", redOnYellow); stylesheet.SetStyle("Left", left); stylesheet.SetStyle("Right", right); stylesheet.SetStyle("Center", center); stylesheet.SetStyle("Justify", justify); stylesheet.SetStyle("Line Height", lineHeight); stylesheet.SetStyle("Border", border); stylesheet.SetStyle("Margin", margin); stylesheet.SetStyle("Padding", padding); stylesheet.SetStyle("FirstLineIndent", firstLineIndent); styleChooser.Items.Clear(); styleChooser.Items.Add("No Character Style"); styleChooser.Items.Add("No Paragraph Style"); styleChooser.Items.Add("Normal"); styleChooser.Items.Add("Bold"); styleChooser.Items.Add("Italic"); styleChooser.Items.Add("Bold Italic"); styleChooser.Items.Add("Red on Yellow"); styleChooser.Items.Add("Left"); styleChooser.Items.Add("Right"); styleChooser.Items.Add("Center"); styleChooser.Items.Add("Justify"); styleChooser.Items.Add("Line Height"); styleChooser.Items.Add("Border"); styleChooser.Items.Add("Margin"); styleChooser.Items.Add("Padding"); styleChooser.Items.Add("FirstLineIndent"); return(stylesheet); }
public override IStyle CreateStyle(List <string> styleProps, string name, Dictionary <int, Color> colorTable) { IStyle style; DemoStyleProp <FwTextAlign> alignment = null; DemoStyleProp <int> firstLineIndent = null; DemoStyleProp <int> marginLeading = null; DemoStyleProp <int> marginTrailing = null; DemoStyleProp <int> marginTop = null; DemoStyleProp <int> marginBottom = null; DemoStyleProp <LineHeightInfo> lineSpacing = null; DemoStyleProp <int> borderLeading = null; DemoStyleProp <int> borderTrailing = null; DemoStyleProp <int> borderTop = null; DemoStyleProp <int> borderBottom = null; DemoStyleProp <Color> borderColor = null; DemoStyleProp <bool> bold = null; DemoStyleProp <bool> italic = null; DemoStyleProp <string> fontName = null; DemoStyleProp <int> fontSize = null; DemoStyleProp <Color> fontColor = null; DemoStyleProp <Color> underlineColor = null; DemoStyleProp <FwSuperscriptVal> superSub = null; DemoStyleProp <Color> highlight = null; string defaultStyleName = name; string additiveStyleName = ""; foreach (string prop in styleProps) { int placeHolder; if (prop.StartsWith("b")) { bold = new DemoStyleProp <bool> { Value = true }; defaultStyleName += "+Bold"; } else if (prop.StartsWith("i")) { italic = new DemoStyleProp <bool> { Value = true }; defaultStyleName += "+Italic"; } else if (prop.StartsWith("fs")) { if (int.TryParse(prop.Substring(2), out placeHolder)) { fontSize = new DemoStyleProp <int> { Value = placeHolder }; defaultStyleName += "+" + fontSize.Value + "pt"; } } else if (prop.StartsWith("f")) { fontName = new DemoStyleProp <string> { Value = prop.Substring(1) }; defaultStyleName += "+" + fontName.Value; } else if (prop.StartsWith("cf")) { fontColor = new DemoStyleProp <Color> { Value = colorTable[int.Parse(prop.Substring(2))] }; defaultStyleName += "+" + fontColor.Value + "Font"; } else if (prop.StartsWith("ulc")) { underlineColor = new DemoStyleProp <Color> { Value = colorTable[int.Parse(prop.Substring(2))] }; defaultStyleName += "+" + underlineColor.Value + "Underline"; } else if (prop.StartsWith("nosupersub")) { superSub = new DemoStyleProp <FwSuperscriptVal> { Value = FwSuperscriptVal.kssvOff }; defaultStyleName += "+NoSuperSub"; } else if (prop.StartsWith("super")) { superSub = new DemoStyleProp <FwSuperscriptVal> { Value = FwSuperscriptVal.kssvSuper }; defaultStyleName += "+Super"; } else if (prop.StartsWith("sub")) { superSub = new DemoStyleProp <FwSuperscriptVal> { Value = FwSuperscriptVal.kssvSub }; defaultStyleName += "+Sub"; } else if (prop.StartsWith("highlight")) { highlight = new DemoStyleProp <Color> { Value = colorTable[int.Parse(prop.Substring(9, prop.Length - 9))] }; defaultStyleName += "+" + highlight.Value + "Highlight"; } else if (prop == "ql") { alignment = new DemoStyleProp <FwTextAlign> { Value = FwTextAlign.ktalLeft }; defaultStyleName += "+AlignLeft"; } else if (prop == "qr") { alignment = new DemoStyleProp <FwTextAlign> { Value = FwTextAlign.ktalRight }; defaultStyleName += "+AlignRight"; } else if (prop == "qc") { alignment = new DemoStyleProp <FwTextAlign> { Value = FwTextAlign.ktalCenter }; defaultStyleName += "+AlignCenter"; } else if (prop == "qj") { alignment = new DemoStyleProp <FwTextAlign> { Value = FwTextAlign.ktalJustify }; defaultStyleName += "+AlignJustify"; } else if (prop.StartsWith("fi")) { if (int.TryParse(prop.Substring(2), out placeHolder)) { firstLineIndent = new DemoStyleProp <int> { Value = placeHolder * 50 }; defaultStyleName += "+" + firstLineIndent.Value + "FirstLineIndent"; } } else if (prop.StartsWith("lin")) { if (int.TryParse(prop.Substring(3), out placeHolder)) { marginLeading = new DemoStyleProp <int> { Value = placeHolder * 50 }; defaultStyleName += "+" + marginLeading.Value + "MargLead"; } } else if (prop.StartsWith("rin")) { if (int.TryParse(prop.Substring(3), out placeHolder)) { marginTrailing = new DemoStyleProp <int> { Value = placeHolder * 50 }; defaultStyleName += "+" + marginTrailing + "MargTrail"; } } else if (prop.StartsWith("sa")) { if (int.TryParse(prop.Substring(2), out placeHolder)) { marginTop = new DemoStyleProp <int> { Value = placeHolder * 50 }; defaultStyleName += "+" + marginTop + "MargTop"; } } else if (prop.StartsWith("sb")) { if (int.TryParse(prop.Substring(2), out placeHolder)) { marginBottom = new DemoStyleProp <int> { Value = placeHolder * 50 }; defaultStyleName += "+" + marginBottom + "MargBot"; } } else if (prop.StartsWith("sl")) { if (int.TryParse(prop.Substring(2), out placeHolder)) { lineSpacing = new DemoStyleProp <LineHeightInfo> { Value = new LineHeightInfo(placeHolder * 50, false) }; defaultStyleName += "+" + lineSpacing.Value + "LineSpace"; } else if (prop.Substring(0, 6) == "slmult") { if (int.TryParse(prop.Substring(6, prop.Length - 6), out placeHolder)) { placeHolder *= 50; if (placeHolder == 10000 || placeHolder == 15000 || placeHolder == 20000) { lineSpacing = new DemoStyleProp <LineHeightInfo> { Value = new LineHeightInfo(placeHolder, true) }; defaultStyleName += "+" + lineSpacing.Value + "LineSpace"; } } } } else if (prop.StartsWith("brdrlbrdrsbrdrw")) { if (int.TryParse(prop.Substring(15), out placeHolder)) { borderLeading = new DemoStyleProp <int> { Value = placeHolder * 50 }; defaultStyleName += "+" + borderLeading.Value + "BordLead"; } else if (prop.Contains("brsp")) { int index = prop.IndexOf("brsp"); if (int.TryParse(prop.Substring(15, index - 15), out placeHolder)) { borderLeading = new DemoStyleProp <int> { Value = placeHolder * 50 }; defaultStyleName += "+" + borderLeading.Value + "BordLead"; } char c = '0'; index += 3; while (c < 40 && c > 29) { index++; c = prop[index]; } borderColor = new DemoStyleProp <Color> { Value = colorTable[int.Parse(prop.Substring(2))] }; defaultStyleName += "+" + borderColor.Value + "Border"; } } else if (prop.StartsWith("brdrrbrdrsbrdrw")) { if (int.TryParse(prop.Substring(15), out placeHolder)) { borderTrailing = new DemoStyleProp <int> { Value = placeHolder * 50 }; defaultStyleName += "+" + borderTrailing.Value + "BordTrail"; } else if (prop.Contains("brsp")) { int index = prop.IndexOf("brsp"); if (int.TryParse(prop.Substring(15, index - 15), out placeHolder)) { borderTrailing = new DemoStyleProp <int> { Value = placeHolder * 50 }; defaultStyleName += "+" + borderTrailing.Value + "BordTrail"; } char c = '0'; index += 3; while (c < 40 && c > 29) { index++; c = prop[index]; } borderColor = new DemoStyleProp <Color> { Value = colorTable[int.Parse(prop.Substring(2))] }; defaultStyleName += "+" + borderColor.Value + "Border"; } } else if (prop.StartsWith("brdrtbrdrsbrdrw")) { if (int.TryParse(prop.Substring(15), out placeHolder)) { borderTop = new DemoStyleProp <int> { Value = placeHolder * 50 }; defaultStyleName += "+" + borderTop.Value + "BordTop"; } else if (prop.Contains("brsp")) { int index = prop.IndexOf("brsp"); if (int.TryParse(prop.Substring(15, index - 15), out placeHolder)) { borderTop = new DemoStyleProp <int> { Value = placeHolder * 50 }; defaultStyleName += "+" + borderTop.Value + "BordTop"; } char c = '0'; index += 3; while (c < 40 && c > 29) { index++; c = prop[index]; } borderColor = new DemoStyleProp <Color> { Value = colorTable[int.Parse(prop.Substring(2))] }; defaultStyleName += "+" + borderColor.Value + "Border"; } } else if (prop.StartsWith("brdrbbrdrsbrdrw")) { if (int.TryParse(prop.Substring(15), out placeHolder)) { borderBottom = new DemoStyleProp <int> { Value = placeHolder * 50 }; defaultStyleName += "+" + borderBottom.Value + "BordBot"; } else if (prop.Contains("brsp")) { int index = prop.IndexOf("brsp"); if (int.TryParse(prop.Substring(15, index - 15), out placeHolder)) { borderBottom = new DemoStyleProp <int> { Value = placeHolder * 50 }; defaultStyleName += "+" + borderBottom.Value + "BordBot"; } char c = '0'; index += 3; while (c < 58 && c > 47) { index++; c = prop[index]; } borderColor = new DemoStyleProp <Color> { Value = colorTable[int.Parse(prop.Substring(2))] }; defaultStyleName += "+" + borderColor.Value + "Border"; } } else if (prop.StartsWith("additive")) { additiveStyleName = prop.Substring(9); } } if (name.StartsWith("\\s") || name.StartsWith("\\pard")) { style = new DemoStyle { ParagraphStyleInfo = new DemoParaStyleInfo { Alignment = alignment, FirstLineIndent = firstLineIndent, MarginLeading = marginLeading, MarginTrailing = marginTrailing, MarginTop = marginTop, MarginBottom = marginBottom, LineHeight = lineSpacing, BorderLeading = borderLeading, BorderTrailing = borderTrailing, BorderTop = borderTop, BorderBottom = borderBottom, BorderColor = borderColor }, DefaultCharacterStyleInfo = new DemoCharStyleInfo { BackColor = highlight, Bold = bold, FontColor = fontColor, FontName = fontName, FontSize = fontSize, Italic = italic, SuperSub = superSub, UnderlineColor = underlineColor }, Name = additiveStyleName == "" ? defaultStyleName : additiveStyleName } } ; else if (name.StartsWith("cs")) { style = new DemoStyle { DefaultCharacterStyleInfo = new DemoCharStyleInfo { BackColor = highlight, Bold = bold, FontColor = fontColor, FontName = fontName, FontSize = fontSize, Italic = italic, SuperSub = superSub, UnderlineColor = underlineColor }, Name = additiveStyleName == "" ? defaultStyleName : additiveStyleName } } ; else { style = null; } return(style); }