Ejemplo n.º 1
0
    public static Paragraph SpacingBetweenLines(this Paragraph paragraph,
                                                int Before,
                                                int After = 0,
                                                int Line  = 240,
                                                LineSpacingRuleValues LineRile = LineSpacingRuleValues.Auto)
    {
        var spacing = (paragraph.ParagraphProperties ??= new()).SpacingBetweenLines ??= new();

        // Множитель 20: чтобы установить 18 надо задать 360
        if (Before > 0)
        {
            spacing.Before = Before.ToString();
        }
        if (After > 0)
        {
            spacing.After = After.ToString();
        }
        if (Line > 0)
        {
            spacing.Line = Line.ToString();
        }
        spacing.LineRule = LineRile;

        return(paragraph);
    }
Ejemplo n.º 2
0
        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);
                }
            }
        }