Esempio n. 1
0
        protected virtual void DoSetSection(int sectionNum, SectionOptions options)
        {
            var book = options?.Book?.Document ?? Document;

            Section section;

            if (sectionNum > 0 && sectionNum <= book.Sections.Count)
            {
                section = book.Sections[sectionNum - 1];
            }
            else if (sectionNum < 0 && -sectionNum <= book.Sections.Count)
            {
                section = book.Sections[book.Sections.Count - sectionNum];
            }
            else
            {
                throw new Exception("Invalid SectionNum.");
            }

            SetupSection(section, options);
        }
Esempio n. 2
0
        protected void DoAddSection(SectionOptions options)
        {
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options), "Options are not provided.");
            }

            var book = options.Book?.Document ?? Document;

            var section = book.AppendSection();

            if (options != null)
            {
                SetupSection(section, options);
            }

            if (section?.Range?.End != null)
            {
                book.CaretPosition = section.Range.End;
                ScrollToCaret();
            }
        }
Esempio n. 3
0
 public SCBook AddSection(SectionOptions options = null)
 {
     ExecuteSynchronized(options, () => DoAddSection(options));
     return(this);
 }
        protected static void SetupSection(Section section, SectionOptions options)
        {
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options), "Options are not provided.");
            }

            if (options.DifferentFirstPage.HasValue)
            {
                section.DifferentFirstPage = options.DifferentFirstPage.Value;
            }

            if (options.FirstPageTray.HasValue)
            {
                section.FirstPageTray = options.FirstPageTray.Value;
            }
            if (options.OtherPagesTray.HasValue)
            {
                section.OtherPagesTray = options.OtherPagesTray.Value;
            }

            if (options.LineNumberingCountBy.HasValue)
            {
                section.LineNumbering.CountBy = options.LineNumberingCountBy.Value;
            }
            if (options.LineNumberingDistance.HasValue)
            {
                section.LineNumbering.Distance = options.LineNumberingDistance.Value;
            }
            if (options.LineNumberingRestartType.HasValue)
            {
                section.LineNumbering.RestartType = (DevExpress.XtraRichEdit.API.Native.LineNumberingRestart)options.LineNumberingRestartType.Value;
            }
            if (options.LineNumberingStart.HasValue)
            {
                section.LineNumbering.Start = options.LineNumberingStart.Value;
            }

            switch (options.Margins?.Length ?? 0)
            {
            case 0:
                break;

            case 1:
                section.Margins.Left = section.Margins.Top = section.Margins.Right = section.Margins.Bottom = options.Margins[0];
                break;

            case 4:
                section.Margins.Left   = options.Margins[0];
                section.Margins.Top    = options.Margins[1];
                section.Margins.Right  = options.Margins[2];
                section.Margins.Bottom = options.Margins[3];
                break;

            case 6:
                section.Margins.Left         = options.Margins[0];
                section.Margins.Top          = options.Margins[1];
                section.Margins.Right        = options.Margins[2];
                section.Margins.Bottom       = options.Margins[3];
                section.Margins.HeaderOffset = options.Margins[4];
                section.Margins.FooterOffset = options.Margins[5];
                break;

            default:
                throw new Exception("Invalid count of values in Margins.");
            }

            if (options.PaperKind.HasValue)
            {
                section.Page.PaperKind = options.PaperKind.Value;
            }
            if (options.PageWidth.HasValue)
            {
                section.Page.Width = options.PageWidth.Value;
            }
            if (options.PageHeight.HasValue)
            {
                section.Page.Height = options.PageHeight.Value;
            }
            if (options.Landscape.HasValue)
            {
                section.Page.Landscape = options.Landscape.Value;
            }

            if (options.ContinuePageNumbering.HasValue)
            {
                section.PageNumbering.ContinueNumbering = options.ContinuePageNumbering.Value;
            }
            if (options.FirstPageNumber.HasValue)
            {
                section.PageNumbering.FirstPageNumber = options.FirstPageNumber.Value;
            }
            if (options.PageNumberingFormat.HasValue)
            {
                section.PageNumbering.NumberingFormat = (DevExpress.XtraRichEdit.API.Native.NumberingFormat)options.PageNumberingFormat.Value;
            }

            if (options.RightToLeft.HasValue)
            {
                section.RightToLeft = options.RightToLeft.Value;
            }

            if (options.StartType.HasValue)
            {
                section.StartType = (DevExpress.XtraRichEdit.API.Native.SectionStartType)options.StartType.Value;
            }

            if ((options.ColumnWidths?.Length ?? 0) > 0)
            {
                var columns = section.Columns.CreateUniformColumns(section.Page, (options.ColumnSpacing?.Length ?? 0) > 0 ? options.ColumnSpacing[0] : 0.25f, options.ColumnWidths.Length);
                for (int i = 0; i < options.ColumnWidths.Length; i++)
                {
                    columns[i].Width = options.ColumnWidths[i];
                    if ((options.ColumnSpacing?.Length ?? 0) > i)
                    {
                        columns[i].Spacing = options.ColumnSpacing[i];
                    }
                }
                section.Columns.SetColumns(columns);
            }
            else if (options.ColumnCount.HasValue)
            {
                var columns = section.Columns.CreateUniformColumns(section.Page, (options.ColumnSpacing?.Length ?? 0) > 0 ? options.ColumnSpacing[0] : 0.25f, options.ColumnCount.Value);
                if (options.ColumnSpacing != null)
                {
                    for (int i = 0; i < Math.Min(options.ColumnCount.Value, options.ColumnSpacing.Length); i++)
                    {
                        columns[i].Spacing = options.ColumnSpacing[i];
                    }
                }
                section.Columns.SetColumns(columns);
            }

            if (options.LinkHeaderToPrevious)
            {
                section.LinkHeaderToPrevious();
            }
            if (options.LinkFooterToPrevious)
            {
                section.LinkFooterToPrevious();
            }
        }
Esempio n. 5
0
 public SCBook SetSection(int sectionNum, SectionOptions options)
 {
     ExecuteSynchronized(options, () => DoSetSection(sectionNum, options));
     return(this);
 }