private bool HasPaddingValue(string attrName, ReportSize generalPadding, out ReportSize effectivePadding) { if (m_currentHtmlElement.CssStyle.TryGetValue(attrName, out string value)) { if (ReportSize.TryParse(value, out ReportSize reportSize)) { effectivePadding = reportSize; return(true); } m_richTextLogger.RegisterInvalidSizeWarning("padding", value, m_currentHtmlElement.CharacterPosition); } if (generalPadding != null) { effectivePadding = generalPadding; return(true); } effectivePadding = null; return(false); }
private void SetStyleValues(bool isParagraph) { if (m_currentHtmlElement.CssStyle == null) { return; } string value; ReportSize reportSize; if (isParagraph && m_allowMultipleParagraphs) { if (m_currentHtmlElement.CssStyle.TryGetValue("text-align", out value)) { if (RichTextStyleTranslator.TranslateTextAlign(value, out TextAlignments textAlignment)) { m_currentStyle.TextAlign = textAlignment; } else { m_richTextLogger.RegisterInvalidValueWarning("text-align", value, m_currentHtmlElement.CharacterPosition); } } if (m_currentHtmlElement.CssStyle.TryGetValue("text-indent", out value)) { if (ReportSize.TryParse(value, allowNegative: true, out reportSize)) { m_currentParagraph.HangingIndent = reportSize; } else { m_richTextLogger.RegisterInvalidSizeWarning("text-indent", value, m_currentHtmlElement.CharacterPosition); } } ReportSize generalPadding = null; if (m_currentHtmlElement.CssStyle.TryGetValue("padding", out value)) { if (ReportSize.TryParse(value, out reportSize)) { generalPadding = reportSize; } else { m_richTextLogger.RegisterInvalidSizeWarning("padding", value, m_currentHtmlElement.CharacterPosition); } } if (HasPaddingValue("padding-top", generalPadding, out ReportSize effectivePadding)) { m_currentParagraph.AddSpaceBefore(effectivePadding); } if (HasPaddingValue("padding-bottom", generalPadding, out effectivePadding)) { m_currentParagraph.AddSpaceAfter(effectivePadding); } if (HasPaddingValue("padding-left", generalPadding, out effectivePadding)) { m_currentParagraph.AddLeftIndent(effectivePadding); } if (HasPaddingValue("padding-right", generalPadding, out effectivePadding)) { m_currentParagraph.AddRightIndent(effectivePadding); } } if (m_currentHtmlElement.CssStyle.TryGetValue("font-family", out value)) { m_currentStyle.FontFamily = value; } if (m_currentHtmlElement.CssStyle.TryGetValue("font-size", out value)) { if (ReportSize.TryParse(value, out reportSize)) { m_currentStyle.FontSize = reportSize; } else { m_richTextLogger.RegisterInvalidSizeWarning("font-size", value, m_currentHtmlElement.CharacterPosition); } } if (m_currentHtmlElement.CssStyle.TryGetValue("font-weight", out value)) { if (RichTextStyleTranslator.TranslateFontWeight(value, out FontWeights fontWieght)) { m_currentStyle.FontWeight = fontWieght; } else { m_richTextLogger.RegisterInvalidValueWarning("font-weight", value, m_currentHtmlElement.CharacterPosition); } } if (m_currentHtmlElement.CssStyle.TryGetValue("color", out value)) { if (ReportColor.TryParse(RichTextStyleTranslator.TranslateHtmlColor(value), out ReportColor reportColor)) { m_currentStyle.Color = reportColor; } else { m_richTextLogger.RegisterInvalidColorWarning("color", value, m_currentHtmlElement.CharacterPosition); } } }