static StyleRange ExtractStyle(ICssStyleDeclaration style) { var mappedStyle = new StyleRange(); string cssColor = null; try { cssColor = style?.GetPropertyValue("color"); mappedStyle.Color = ParseColor(cssColor); } catch (NullReferenceException) { } try { string fontWeight = null; fontWeight = style?.GetPropertyValue("font-weight"); mappedStyle.Bold = (!string.IsNullOrEmpty(fontWeight) && fontWeight == "bold"); } catch (NullReferenceException) { } try { string fontStyle = null; fontStyle = style?.GetPropertyValue("font-style"); mappedStyle.Italic = (!string.IsNullOrEmpty(fontStyle) && fontStyle == "italic"); } catch (NullReferenceException) { } return(mappedStyle); }
private static void ApplyStyle(PowerPoint.TextRange selection, StyleRange style) { var range = selection.Characters(style.Begin + 1, style.Length); if (style.Color is Color color) { range.Font.Color.RGB = color.ToOle(); } if (style.Bold is bool bold) { range.Font.Bold = bold.ToTryState(); } if (style.Italic is bool italic) { range.Font.Italic = italic.ToTryState(); } ApplyStyle(selection, style.Children); }
private StyleRange Parse(int begin, IElement element, IWindow browsingWindow) { StyleRange style; try { style = ExtractStyle(browsingWindow.GetComputedStyle(element)); } catch (NullReferenceException) { style = new StyleRange(); } style.Begin = begin; style.Length = element.TextContent.Length; style.Text = element.TextContent; style.Children = Parse(begin, element.ChildNodes, browsingWindow); return(style); }