Пример #1
0
        /*-------------------------------------------------------------------------------------------------------
        ** CreateFootnotes method
        *
        * This method returns the page number of a given TextField
        **-----------------------------------------------------------------------------------------------------*/
        private int GetPageOfField(TXTextControl.TextField field)
        {
            foreach (TXTextControl.Page page in textControl1.GetPages())
            {
                if (field.Start >= page.Start && (field.Start + field.Length) <= page.Start + page.Length)
                {
                    return(page.Number);
                }
            }

            return(0);
        }
Пример #2
0
        /*-------------------------------------------------------------------------------------------------------
        ** ShowEditor method
        *
        * This method gets a TextField in the constructor and checks whether it
        * is a footnote field. It opens the footnote editor form that is used to
        * modify the footnote text.
        **-----------------------------------------------------------------------------------------------------*/
        private void ShowEditor(TXTextControl.TextField TextField)
        {
            if (TextField.Name.StartsWith("FN:") == false)
            {
                return;
            }

            footnote_editor frmFootnoteEditor = new footnote_editor(TextField);

            // the size is calculated based on the page size (width)
            frmFootnoteEditor.Size = new Size(
                (textControl1.GetPages()[textControl1.InputPosition.Page].TextBounds.Width / 15)
                , 150);

            // the form should be displayed directly under the footnote field
            Point pntEditorPosition = new Point(
                (int)((textControl1.GetPages()[textControl1.InputPosition.Page].TextBounds.Left / iDpi) -
                      (textControl1.ScrollLocation.X / iDpi)) *
                textControl1.ZoomFactor / 100,

                ((int)(TextField.Bounds.Bottom / 15) -
                 (int)(textControl1.ScrollLocation.Y / 15)) *
                textControl1.ZoomFactor / 100);

            frmFootnoteEditor.Location = textControl1.PointToScreen(pntEditorPosition);

            if (frmFootnoteEditor.ShowDialog() == DialogResult.OK)
            {
                CreateFootnotes();
            }
            else
            {
                textControl1.TextFields.Remove(TextField);
                CreateFootnotes();
            }
        }
 public footnote_editor(TXTextControl.TextField TextField)
 {
     InitializeComponent();
     textControl1.ButtonBar = buttonBar1;
     textField = TextField;
 }
Пример #4
0
        /*-------------------------------------------------------------------------------------------------------
        ** CreateFootnotes method
        *
        * This method loops through all pages in order to check whether there are
        * footnote TextFields on that page. If yes, the footnote text is collected in
        * a temporary TextControl instance.
        * If there are footnotes on that page, a TextFrame is created which contains
        * the collected footnote texts.
        **-----------------------------------------------------------------------------------------------------*/
        public void CreateFootnotes()
        {
            RemoveFootnoteFrames();

            // loop through all pages
            foreach (TXTextControl.Page page in textControl1.GetPages())
            {
                TXTextControl.TextControl tempTX = new TextControl();
                tempTX.CreateControl();
                tempTX.Font     = new Font("Arial", 7F);
                tempTX.ViewMode = ViewMode.Normal;

                TXTextControl.TextFieldCollection.TextFieldEnumerator fieldEnum = textControl1.TextFields.GetEnumerator();
                int fieldCounter = textControl1.TextFields.Count;

                // loop through all TextFields
                for (int i = 0; i <= fieldCounter; i++)
                {
                    fieldEnum.MoveNext();
                    TXTextControl.TextField curField = (TXTextControl.TextField)fieldEnum.Current;

                    // use field only, if it is a footnote field (starts with "FN:")
                    // and if the field contains formatted text
                    if (curField.Name.StartsWith("FN:") == false || curField.Name.Length <= 3)
                    {
                        continue;
                    }

                    // check whether the field is on the current page
                    if (GetPageOfField(curField) == page.Number)
                    {
                        // add the formatted text to the temporary TextControl
                        int startPos = tempTX.Selection.Start;
                        tempTX.Selection.Load(curField.Name.Substring(3, curField.Name.Length - 3), StringStreamType.RichTextFormat);
                        tempTX.Selection.Start = startPos;
                        tempTX.Selection.Text  = curField.Text + ") ";
                        tempTX.Selection.Start = -1;
                    }
                }

                if (tempTX.Text == "")
                {
                    continue;
                }

                // insert a top frame border
                tempTX.Selection.Start = 0;
                tempTX.Selection.Text  = "\r\n";
                tempTX.Selection.Start = 0;
                tempTX.Selection.ParagraphFormat.RightIndent = 5000;
                tempTX.Selection.ParagraphFormat.Frame       = Frame.TopLine;

                // measure the used text height
                int textHeight = tempTX.Lines[tempTX.Lines.Count].Baseline + 200;

                // create a new TextFrame based on the used text height
                TXTextControl.TextFrame frame = new TextFrame(new Size(page.TextBounds.Width, textHeight));
                frame.Sizeable        = false;
                frame.Moveable        = false;
                frame.BorderWidth     = 0;
                frame.Name            = "FN";
                frame.InternalMargins = new int[] { 0, 0, 0, 0 };

                // add the TextFrame at the bottom border of the page
                textControl1.TextFrames.Add(
                    frame,
                    page.Number,
                    new Point((int)(textControl1.Sections[page.Section].Format.PageMargins.Left * iDpi - 55),
                              (int)textControl1.Sections[page.Section].Format.PageSize.Height * iDpi - (int)textControl1.Sections[page.Section].Format.PageMargins.Top * iDpi - 576 - frame.Size.Height),
                    TextFrameInsertionMode.DisplaceCompleteLines);

                byte[] data = null;

                // save the formatted text from the temporary TextControl
                tempTX.Save(out data, BinaryStreamType.InternalUnicodeFormat);
                // and load it into the TextFrame
                frame.Selection.Load(data, BinaryStreamType.InternalUnicodeFormat);
            }
        }