internal static void SetBottomMargin(string style, ParagraphProperties properties) { decimal dxa = DocxUnits.GetDxaFromStyle(style); if (dxa != -1) { SpacingBetweenLines spacing = new SpacingBetweenLines(); spacing.After = dxa.ToString(); properties.Append(spacing); } }
internal void ProcessParagraphMargin(ParagraphProperties properties) { string topMargin = GetTopMargin(); string bottomMargin = GetBottomMargin(); string leftMargin = GetLeftMargin(); string rightMargin = GetRightMargin(); string line = node.ExtractStyleValue(lineHeight); if (!string.IsNullOrEmpty(topMargin) || !string.IsNullOrEmpty(bottomMargin) || !string.IsNullOrEmpty(line)) { SpacingBetweenLines spacing = new SpacingBetweenLines(); if (!string.IsNullOrEmpty(topMargin)) { decimal dxa = DocxUnits.GetDxaFromStyle(topMargin); if (dxa != -1) { spacing.Before = dxa.ToString(); } } if (!string.IsNullOrEmpty(bottomMargin)) { decimal dxa = DocxUnits.GetDxaFromStyle(bottomMargin); if (dxa != -1) { spacing.After = decimal.Round(dxa).ToString(); } } if (!string.IsNullOrEmpty(line) && !line.CompareStringOrdinalIgnoreCase(DocxFontStyle.normal)) { decimal number; decimal dxa = -1; LineSpacingRuleValues lineSpacingRuleValues = LineSpacingRuleValues.AtLeast; if (decimal.TryParse(line, out number)) { dxa = DocxUnits.GetDxaFromNumber(number); dxa = dxa - defaultLineHeight;//Removing the default line height } else if (line.Contains("%")) { line = line.Replace("%", string.Empty); if (decimal.TryParse(line, out number)) { dxa = (number / 100) * DocxFontStyle.defaultFontSizeInPixel; dxa = dxa - defaultLineHeight;//Removing the default line height } } else { dxa = DocxUnits.GetDxaFromStyle(line); //lineSpacingRuleValues = LineSpacingRuleValues.Exact; } dxa = decimal.Round(dxa); if (dxa > 0) { spacing.LineRule = lineSpacingRuleValues; spacing.Line = dxa.ToString(); } } if (spacing.HasAttributes) { properties.Append(spacing); } } if (!string.IsNullOrEmpty(leftMargin) || !string.IsNullOrEmpty(rightMargin)) { Indentation ind = new Indentation(); if (!string.IsNullOrEmpty(leftMargin)) { decimal dxa = DocxUnits.GetDxaFromStyle(leftMargin); if (dxa != -1) { ind.Left = dxa.ToString(); } } if (!string.IsNullOrEmpty(rightMargin)) { decimal dxa = DocxUnits.GetDxaFromStyle(rightMargin); if (dxa != -1) { ind.Right = dxa.ToString(); } } if (ind.HasAttributes) { properties.Append(ind); } } }