private void SetDisplayColor() { this.clrDisplay = System.Drawing.Color.FromArgb(255, 0, 0, 0); int index = 0; if (this.Theme != null) { index = (int)this.Theme.Value; if (index >= 0 && index < this.listThemeColors.Count) { this.clrDisplay = System.Drawing.Color.FromArgb(255, this.listThemeColors[index]); if (this.Tint != null) { this.clrDisplay = SLTool.ToColor(this.clrDisplay, this.Tint.Value); } } } else if (this.Rgb != null) { this.clrDisplay = SLTool.ToColor(this.Rgb); } else if (this.Indexed != null) { index = (int)this.Indexed.Value; if (index >= 0 && index < this.listIndexedColors.Count) { this.clrDisplay = System.Drawing.Color.FromArgb(255, this.listIndexedColors[index]); } } }
/// <summary> /// Set a color using a theme color, modifying the theme color with a tint value. /// </summary> /// <param name="ThemeColorIndex">The theme color to be used.</param> /// <param name="Tint">The tint applied to the theme color, ranging from -1.0 to 1.0. Negative tints darken the theme color and positive tints lighten the theme color.</param> public void SetThemeColor(SLThemeColorIndexValues ThemeColorIndex, double Tint) { System.Drawing.Color clrRgb = new System.Drawing.Color(); int index = (int)ThemeColorIndex; if (index >= 0 && index < this.listThemeColors.Count) { clrRgb = this.listThemeColors[index]; } this.Auto = null; this.Indexed = null; this.Rgb = null; this.Theme = (uint)ThemeColorIndex; this.Tint = Tint; this.clrDisplay = SLTool.ToColor(clrRgb, Tint); }
/// <summary> /// Convert a set of HSL color values to a System.Drawing.Color structure. /// </summary> /// <param name="Hue">The hue measured in degrees ranging from 0 to 360 degrees.</param> /// <param name="Saturation">The saturation ranging from 0.0 to 1.0, where 0.0 is grayscale and 1.0 is the most saturated.</param> /// <param name="Luminance">The luminance (sometimes known as brightness) ranging from 0.0 to 1.0, where 0.0 is effectively black and 1.0 is effectively white.</param> /// <returns>A System.Drawing.Color structure.</returns> public static System.Drawing.Color ToColor(double Hue, double Saturation, double Luminance) { return(SLTool.ToColor(Hue, Saturation, Luminance)); }
/// <summary> /// Convert a color in hexadecimal to a System.Drawing.Color structure. /// </summary> /// <param name="HexValue">The color in hexadecimal.</param> /// <returns>A System.Drawing.Color structure.</returns> public static System.Drawing.Color ToColor(string HexValue) { return(SLTool.ToColor(HexValue)); }
internal A.Paragraph ToParagraph() { A.Paragraph para = new A.Paragraph(); para.ParagraphProperties = new A.ParagraphProperties(); para.ParagraphProperties.Append(new A.DefaultRunProperties()); A.Run run; if (this.istrReal.Text != null) { run = new A.Run(); run.RunProperties = new A.RunProperties(); run.Text = new A.Text(this.istrReal.Text.Text); para.Append(run); } Run xrun; RunFont xrunRunFont; Bold xrunBold; Italic xrunItalic; Strike xrunStrike; Color xrunColor; FontSize xrunFontSize; Underline xrunUnderline; VerticalTextAlignment xrunVertical; FontScheme xrunScheme; string sFont; bool? bBold; bool? bItalic; bool? bStrike; double? fFontSize; UnderlineValues? vUnderline; VerticalAlignmentRunValues?vVertical; bool bHasColor; SLA.SLColorTransform clrRun = new SLA.SLColorTransform(new List <System.Drawing.Color>()); FontSchemeValues? vScheme; using (OpenXmlReader oxr = OpenXmlReader.Create(this.istrReal)) { while (oxr.Read()) { if (oxr.ElementType == typeof(Run)) { run = new A.Run(); run.RunProperties = new A.RunProperties(); sFont = string.Empty; bBold = null; bItalic = null; bStrike = null; fFontSize = null; vUnderline = null; vVertical = null; bHasColor = false; vScheme = null; xrun = (Run)oxr.LoadCurrentElement(); if (xrun.RunProperties != null) { using (OpenXmlReader oxrProps = OpenXmlReader.Create(xrun.RunProperties)) { while (oxrProps.Read()) { if (oxrProps.ElementType == typeof(RunFont)) { xrunRunFont = (RunFont)oxrProps.LoadCurrentElement(); if (xrunRunFont.Val != null) { sFont = xrunRunFont.Val.Value; } } else if (oxrProps.ElementType == typeof(Bold)) { xrunBold = (Bold)oxrProps.LoadCurrentElement(); if (xrunBold.Val != null) { bBold = xrunBold.Val.Value; } } else if (oxrProps.ElementType == typeof(Italic)) { xrunItalic = (Italic)oxrProps.LoadCurrentElement(); if (xrunItalic.Val != null) { bItalic = xrunItalic.Val.Value; } } else if (oxrProps.ElementType == typeof(Strike)) { xrunStrike = (Strike)oxrProps.LoadCurrentElement(); if (xrunStrike.Val != null) { bStrike = xrunStrike.Val.Value; } } else if (oxrProps.ElementType == typeof(Color)) { xrunColor = (Color)oxrProps.LoadCurrentElement(); if (xrunColor.Rgb != null) { bHasColor = true; clrRun = new SLA.SLColorTransform(new List <System.Drawing.Color>()); clrRun.SetColor(SLTool.ToColor(xrunColor.Rgb.Value), 0); } else if (xrunColor.Theme != null) { bHasColor = true; clrRun = new SLA.SLColorTransform(new List <System.Drawing.Color>()); if (xrunColor.Tint != null) { clrRun.SetColor((SLThemeColorIndexValues)xrunColor.Theme.Value, xrunColor.Tint.Value, 0); } else { clrRun.SetColor((SLThemeColorIndexValues)xrunColor.Theme.Value, 0, 0); } } } else if (oxrProps.ElementType == typeof(FontSize)) { xrunFontSize = (FontSize)oxrProps.LoadCurrentElement(); if (xrunFontSize.Val != null) { fFontSize = xrunFontSize.Val.Value; } } else if (oxrProps.ElementType == typeof(Underline)) { xrunUnderline = (Underline)oxrProps.LoadCurrentElement(); if (xrunUnderline.Val != null) { vUnderline = xrunUnderline.Val.Value; } } else if (oxrProps.ElementType == typeof(VerticalTextAlignment)) { xrunVertical = (VerticalTextAlignment)oxrProps.LoadCurrentElement(); if (xrunVertical.Val != null) { vVertical = xrunVertical.Val.Value; } } else if (oxrProps.ElementType == typeof(FontScheme)) { xrunScheme = (FontScheme)oxrProps.LoadCurrentElement(); if (xrunScheme.Val != null) { vScheme = xrunScheme.Val.Value; } } } } } if (vScheme != null) { if (vScheme.Value == FontSchemeValues.Major) { sFont = "+mj-lt"; } else if (vScheme.Value == FontSchemeValues.Minor) { sFont = "+mn-lt"; } } if (bHasColor) { if (clrRun.IsRgbColorModelHex) { run.RunProperties.Append(new A.SolidFill() { RgbColorModelHex = clrRun.ToRgbColorModelHex() }); } else { run.RunProperties.Append(new A.SolidFill() { SchemeColor = clrRun.ToSchemeColor() }); } } if (sFont.Length > 0) { run.RunProperties.Append(new A.LatinFont() { Typeface = sFont }); } if (fFontSize != null) { run.RunProperties.FontSize = (int)(fFontSize.Value * 100); } if (bBold != null) { run.RunProperties.Bold = bBold.Value; } if (bItalic != null) { run.RunProperties.Italic = bItalic.Value; } if (vUnderline != null) { if (vUnderline.Value == UnderlineValues.Single || vUnderline.Value == UnderlineValues.SingleAccounting) { run.RunProperties.Underline = A.TextUnderlineValues.Single; } else if (vUnderline.Value == UnderlineValues.Double || vUnderline.Value == UnderlineValues.DoubleAccounting) { run.RunProperties.Underline = A.TextUnderlineValues.Double; } } if (bStrike != null) { run.RunProperties.Strike = bStrike.Value ? A.TextStrikeValues.SingleStrike : A.TextStrikeValues.NoStrike; } if (vVertical != null) { if (vVertical.Value == VerticalAlignmentRunValues.Superscript) { run.RunProperties.Baseline = 30000; } else if (vVertical.Value == VerticalAlignmentRunValues.Subscript) { run.RunProperties.Baseline = -25000; } else { run.RunProperties.Baseline = 0; } } else { run.RunProperties.Baseline = 0; } run.Text = new A.Text(xrun.Text.Text); para.Append(run); } } } return(para); }
// SLFont takes on extra duties so you don't have to learn more classes. Just like SLRstType. internal A.Paragraph ToParagraph() { A.Paragraph para = new A.Paragraph(); para.ParagraphProperties = new A.ParagraphProperties(); A.DefaultRunProperties defrunprops = new A.DefaultRunProperties(); string sFont = string.Empty; if (this.FontName != null && this.FontName.Length > 0) { sFont = this.FontName; } if (this.HasFontScheme) { if (this.FontScheme == FontSchemeValues.Major) { sFont = "+mj-lt"; } else if (this.FontScheme == FontSchemeValues.Minor) { sFont = "+mn-lt"; } } if (this.HasFontColor) { SLA.SLColorTransform clr = new SLA.SLColorTransform(new List <System.Drawing.Color>()); if (this.clrFontColor.Rgb != null && this.clrFontColor.Rgb.Length > 0) { clr.SetColor(SLTool.ToColor(this.clrFontColor.Rgb), 0); defrunprops.Append(new A.SolidFill() { RgbColorModelHex = clr.ToRgbColorModelHex() }); } else if (this.clrFontColor.Theme != null) { // potential casting error? If the SLFont class was set properly, there shouldn't be errors... SLThemeColorIndexValues themeindex = (SLThemeColorIndexValues)this.clrFontColor.Theme.Value; if (this.clrFontColor.Tint != null) { clr.SetColor(themeindex, this.clrFontColor.Tint.Value, 0); } else { clr.SetColor(themeindex, 0, 0); } defrunprops.Append(new A.SolidFill() { SchemeColor = clr.ToSchemeColor() }); } } if (sFont.Length > 0) { defrunprops.Append(new A.LatinFont() { Typeface = sFont }); } if (this.FontSize != null) { defrunprops.FontSize = (int)(this.FontSize.Value * 100); } if (this.Bold != null) { defrunprops.Bold = this.Bold.Value; } if (this.Italic != null) { defrunprops.Italic = this.Italic.Value; } if (this.HasUnderline) { if (this.Underline == UnderlineValues.Single || this.Underline == UnderlineValues.SingleAccounting) { defrunprops.Underline = A.TextUnderlineValues.Single; } else if (this.Underline == UnderlineValues.Double || this.Underline == UnderlineValues.DoubleAccounting) { defrunprops.Underline = A.TextUnderlineValues.Double; } } if (this.Strike != null) { defrunprops.Strike = this.Strike.Value ? A.TextStrikeValues.SingleStrike : A.TextStrikeValues.NoStrike; } if (this.HasVerticalAlignment) { if (this.VerticalAlignment == VerticalAlignmentRunValues.Superscript) { defrunprops.Baseline = 30000; } else if (this.VerticalAlignment == VerticalAlignmentRunValues.Subscript) { defrunprops.Baseline = -25000; } else { defrunprops.Baseline = 0; } } para.ParagraphProperties.Append(defrunprops); return(para); }