public ControlFilePropertyEditForm(ControlFile Control)
        {
            this.Height = 500;
            this.Width = 500;
            if (null == Control) {
                throw new Exception("Must specify a valid control file.");
            }
            this.Icon = LayoutDetails.Instance.MainFormIcon;
            FormUtils.SizeFormsForAccessibility(this, LayoutDetails.Instance.MainFormFontSize);

            Button OK = new Button();
            OK.Text = Loc.Instance.GetString ("OK");
            OK.Dock =  DockStyle.Bottom;
            OK.DialogResult = DialogResult.OK;
            this.Controls.Add (OK);

            PropertyGrid grid = new PropertyGrid();
            grid.Dock = DockStyle.Fill;
            this.Controls.Add (grid);
            grid.BringToFront();

            grid.SelectedObject = Control;
        }
        /// <summary>
        /// before whatever initial operations are required to open the filestream
        /// or whatever (in the case of Word Auto, will require global variables)
        /// </summary>
        protected override int InitializeDocument(ControlFile _controlFile)
        {
            directory_to_sourcefiles = _controlFile.TemplateDirectory;
            ZIP7 = _controlFile.Zipper;

            if (null == ZIP7 || Constants.BLANK == ZIP7 || null == directory_to_sourcefiles || Constants.BLANK == directory_to_sourcefiles) {
                NewMessage.Show (Loc.Instance.GetString ("To generate an epub you need to specificy a valid path to 7Zip and to the template files used to generate the final epub files"));
                return -1;
            }
            // create an output directory based on date
            sDirectory = Path.Combine(_controlFile.OutputDirectory, GetDateDirectory);
            Directory.CreateDirectory(sDirectory);
            File.Copy(Path.Combine(directory_to_sourcefiles, "mimetype"), Path.Combine(sDirectory, "mimetype"), true);

            Directory.CreateDirectory(Path.Combine(sDirectory, "oebps"));
            DirectoryInfo images = Directory.CreateDirectory(Path.Combine(sDirectory, "oebps\\images"));
            Directory.CreateDirectory(Path.Combine(sDirectory, "META-INF"));

            // start with footer as default first file?
            currentFileBeingWritten = Path.Combine(sDirectory,"oebps\\" + "preface.xhtml");

            chapter = 1;
            base.InitializeDocument(_controlFile);

            // copy required files

            // copy image files
            FileUtils.Copy(new DirectoryInfo(Path.Combine(directory_to_sourcefiles,"oebps\\images")), images, "*.*", "*.*", false, 2, new System.Windows.Forms.ProgressBar());

            File.Copy(Path.Combine(directory_to_sourcefiles,"oebps\\copyright.xhtml"), Path.Combine(sDirectory, "oebps\\copyright.xhtml"),true);
            File.Copy(Path.Combine(directory_to_sourcefiles, "oebps\\stylesheet.css"), Path.Combine(sDirectory, "oebps\\stylesheet.css"), true);
            File.Copy(Path.Combine(directory_to_sourcefiles, "oebps\\legal.xhtml"), Path.Combine(sDirectory, "oebps\\legal.xhtml"), true);
            File.Copy(Path.Combine(directory_to_sourcefiles, "oebps\\title_page.xhtml"), Path.Combine(sDirectory, "oebps\\title_page.xhtml"), true);
            File.Copy(Path.Combine(directory_to_sourcefiles, "oebps\\page-template.xpgt"), Path.Combine(sDirectory, "oebps\\page-template.xpgt"), true);

            File.Copy(Path.Combine(directory_to_sourcefiles,"META-INF\\container.xml"), Path.Combine(sDirectory, "META-INF\\container.xml"),true);
            footnotesincurrentsection = new ArrayList();
            FootnoteChapterIAmInHash = new Hashtable();
            ids = new Hashtable();

            return 1;
        }
        protected override int InitializeDocument(ControlFile _controlFile)
        {
            files = new ArrayList();
            base.InitializeDocument(_controlFile);

            // if we have not already setup a filename, we create one now
            if ("" == currentFileBeingWritten)
            {
                currentFileBeingWritten = Path.Combine(_controlFile.OutputDirectory, "textoutput_" + DateTime.Today.ToString("MM yy") + ".txt");
            }

            StartNewFile(currentFileBeingWritten);

            return 1;
        }
Пример #4
0
        /// <summary>
        /// before whatever initial operations are required to open the filestream
        /// or whatever (in the case of Word Auto, will require global variables)
        /// </summary>
        protected override int InitializeDocument(ControlFile _controlFile)
        {
            //create a word object instead of globals, ie., WOrd(ControlFIle)
            base.InitializeDocument(_controlFile);

            oWord = new Word.Application();
            oWord.Visible = true;
            object template = controlFile.Template;
            oDoc = oWord.Documents.Add( template,  oMissing,
                 oMissing,  oMissing);

            oSelection = oWord.Selection;

            // load defaults from tempalte

            try
            {
                oHeader1 = controlFile.Heading1;
                oHeader2 = controlFile.Heading2; // write getmethods?
                oHeader3 = controlFile.Heading3;
                oHeader4 = controlFile.Heading4;
                oHeader5 = controlFile.Heading5;
                oBullet = controlFile.Bullet;
                oTitle = controlFile.ChapterTitle;
                oStyle = controlFile.BodyText;
                oBulletNumber = controlFile.BulletNumber;
                oTableStyle = controlFile.TableStyle;
            }
            catch (Exception ex)
            {
                System.Windows.Forms.MessageBox.Show(ex.ToString());
                return -1;
            }

            // test if style exists before being used
            bool bExists = false;
            foreach (Word.Style style in oDoc.Styles)
            {
                if (style.NameLocal == (oStyle).ToString())
                {
                    bExists = true;
                }
            }
            if (false == bExists)
            {
                NewMessage.Show(oStyle.ToString() + " did not exist");
            }

            oSelection.Style = oStyle;// (March 2013 - this might be reasonable replacement
            // set defaults
             //   oSelection.set_Style(ref oStyle); //this never seemed to happen 12/12/2010 (FIXED! The name was wrong, trying to come up with a better error check system
            Word.Style oSetStyle = (Word.Style)oSelection.Style;

            /* DId not work to test
            if (oSetStyle.NameLocal != (oStyle).ToString())
            {
                NewMessage.Show(oStyle.ToString() + " did not exist");
            }*/

            return 1;
        }
Пример #5
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="sSource"></param>
        /// <param name="oSelection"></param>
        /// <param name="controlFile"></param>
        protected void ApplyAllInlineFormats(string sSource, ControlFile controlFile, bool AddLineFeed)
        {
            string sOriginal = sSource;
            string[] sFormats = new string[10];
            sFormats[0] = "'''''";
            sFormats[1] = "'''";
            sFormats[2] = "''";
            sFormats[3] = "_";
            sFormats[4] = "---";
            sFormats[5] = "|"; // links
            sFormats[6] = "[[";
            sFormats[7] = "^"; // O^2^
            sFormats[8] = "##";
            sFormats[9] = "<<<";
              //  sFormats[9] = "..."; can't be used for non doubled , won't work

            // Ok, regex not working with mulitple matches on a line
            // we do this the old fashioned way

            // we look for starttag matches
            // and then for endtag matches

            // we cycle through each format

            string sFrontTag = "";
            string sEndTag = "";
            int nFormat = 0;

            // we cycle through the formats. Once we find one format, we apply it
            // trimming the substring until all is done
            int nFirstStart = 0;

            sSource = ReplaceFancyCharacters(sSource);

            int nLastStart = -1;
            int nLastPos = 0;

            while (nFirstStart > -1)
            {

                nFormat = 0;
                nFirstStart = -1;
                // find a format
                while (nFormat < sFormats.Length)
                {
                    // we are looking for the closest match to start
                    // our processing at the beginning of the string
                    int nPossible = sSource.IndexOf(sFormats[nFormat]);
                    if ((nPossible < nFirstStart || nFirstStart == -1) && nPossible != -1)
                    {

                        sFrontTag = sFormats[nFormat];
                        sEndTag = sFrontTag;
                        if (nFormat == 6)
                        {
                            // special case, end tag must be end ]]
                            sEndTag = "]]";
                        }
                        nFirstStart = nPossible;
                    }
                    nFormat++;

                    // nFirstStart = nPossible;
                }
                if (nFirstStart == -1)
                {
                    // we found no format matches
                    // this means it is time to exit
                    break;
                }

                // write text from lastpos to now
                string sFirst = sSource.Substring(nLastPos, nFirstStart);

                try
                {
                    nLastStart = sSource.IndexOf(sEndTag, nFirstStart + sFrontTag.Length);
                }
                catch (Exception ex)
                {
                    NewMessage.Show(ex.ToString());
                }

                if (nLastStart > -1)
                {
                    InlineWrite(sFirst);
                }

                if (nLastStart > -1)
                {

                     string sBoldText = "";

                    // We only complete if there is an end tag (this is to give rid of an info loop --
                    if (nLastStart > -1)
                    {
                        sBoldText = sSource.Substring(nFirstStart + sFrontTag.Length,
                             nLastStart - nFirstStart - sFrontTag.Length);

                        //oSelection.TypeText(sBoldText);

                        sSource = sSource.Substring(nLastStart + sEndTag.Length, sSource.Length - nLastStart - sEndTag.Length);
                    }

                    if (sFrontTag == "'''''")
                    {
                        InlineBold(1);
                        InlineItalic(1);

                    }
                    else
                        if (sFrontTag == "'''")
                        {

                            InlineBold(1);
                            //   object oStrong = "Strong, fb";
                            //   oSelection.set_Style(ref oStrong);
                        }
                        else
                            if (sFrontTag == "''")
                            {
                                InlineItalic(1);
                            }
                            else
                                if (sFrontTag == "_")
                                {

                                    if (false == controlFile.UnderscoreKeep)
                                    {
                                        if (true == controlFile.UnderlineShouldBeItalicInstead)
                                        {
                                            InlineItalic(1);
                                        }
                                        else
                                            InlineUnderline(1);
                                    }
                                    else
                                    {
                                        // don't underline, keep underscores
                                        InlineWrite("_");
                                    }
                                }

                                else if (sFrontTag == "^")
                                {
                                    InlineSuper(1);
                                }
                                else if (sFrontTag == "##")
                                {
                                    InlineSub(1);
                                }
                                    else

                                    if (sFrontTag == "<<<")
                                    {
                                        ChatMode(1);
                                    }

                                    else

                                        if (sFrontTag == "---")
                                        {
                                            if (nLastStart > -1)
                                            {
                                                InlineStrikeThrough(1);
                                            }
                                        }
                                        else

                                            if (sFrontTag == "|")
                                            {
                                                /* object oTextToShow = ("me a link");
                                                 object oLink = "http://www.google.com";
                                                 oSelection.Hyperlinks.Add(oSelection.Range, ref oLink, ref  oMissing,
                                                    ref  oMissing, ref oTextToShow, ref oMissing);*/
                                                if (lastLink != "")
                                                {
                                                    AddLink(lastLink, sBoldText);
                                                    lastLink = "";
                                                    sBoldText = "";
                                                }
                                                else
                                                    if (
                                                        // for direct file references
                                                        sBoldText.IndexOf("./") > -1    ||
                                                        // for anchors/bookmarks
                                                        sBoldText.IndexOf("##") > -1    ||
                                                        sBoldText.IndexOf("www.") > -1  ||
                                                        sBoldText.IndexOf("http:") > -1 ||
                                                        sBoldText.IndexOf("https:") > -1)
                                                    {
                                                        // error checking
                                                        // look for broken bookmarks

                                                        if (sBoldText.IndexOf("##") > -1)
                                                        {
                                                            bookmarks.Add(sBoldText.Replace("##", "").Trim());
                                                        }

                                                        lastLink = sBoldText;

                                                        sBoldText = "";
                                                    }

                                                    else
                        {
                            // March 2013 - trying to allow variable replacement within an URL to clean up
                            // image management within a text
                            if (sBoldText.IndexOf("~var") > -1)
                            {
                                // swap in variable

                                sBoldText = VariableSwap(sBoldText);
                            }
                                                        if (CoreUtilities.General.IsGraphicFile(sBoldText) == true)
                                                        {
                                                            AddPicture(sBoldText);
                                                            sBoldText = ""; // blank thte text
                                                        }

                        }
                                            }
                                            else if (sFrontTag == "[[")
                                            {
                                                bool bOptional = false;
                                                bool bAllowWrite = false;

                                                if (sBoldText.IndexOf("~center") > -1)
                                                {
                                                    AlignText(0);
                                                    sBoldText = ""; /// June 2011 process remainderFAILED, GAVE UP (basically I could not have multiple codes on one line)
                                                }
                                                else
                                                    if (sBoldText.IndexOf("~left") > -1)
                                                    {
                                                        AlignText(1);
                                                        sBoldText = ""; /// June 2011 process remainderFAILED, GAVE UP
                                                     //   sBoldText = Environment.NewLine;
                                                    }
                                                    else
                                                        if (sBoldText.IndexOf("~right") > -1)
                                                        {
                                                            AlignText(2);
                                                            sBoldText = ""; /// June 2011 process remainder FAILED, GAVE UP
                                                        }
                                                        else if (sBoldText.IndexOf("~breakcomment") > -1) //21/05/2014
                                                        {
                            InlineWrite ("<!--break-->");
                            sBoldText = "";
                                                        }
                                                        else // failed gave up
                                                // June 2 2011 - intentionally removed the else here
                                                // because these formats should work with others

                                                            if (sBoldText.IndexOf("~pagebreak") > -1)
                                                            {
                                                                AddPageBreak();
                                                                sBoldText = "";
                                                            }
                                                            else
                                                                if (sBoldText.IndexOf("~break") > -1)
                                                                {
                                                                    InAList = false;
                                                                    sBoldText = "";
                                                                }
                                                                else /// failed gave up

                                                            // June 2 2011 - intentionally removed the else here
                                                            // because these formats should work with others

                                                                if (sBoldText.IndexOf("~id") > -1)
                                                                {
                                                                    // id is used by sendePub to parse things like Title information
                                                                    // so that gets output into the generated epub book
                                                                    sBoldText = sBoldText.Replace("~id", "");
                                                                    string[] idparts = sBoldText.Split(new char[1] { '|' });
                                                                    if (idparts != null && idparts.Length == 2)
                                                                    {
                                                                        AddId(idparts[0].Trim(), idparts[1].Trim());
                                                                    }

                                                                    sBoldText = "";
                                                                }
                                                                else
                                                                    // we found a footnote and are adding it to the HashTable (no outputting)
                                                                    if (sBoldText.IndexOf("footnoteadd") > -1)
                                                                    {
                                                                        sBoldText = sBoldText.Replace("footnoteadd", "");
                                                                        string[] footparts = sBoldText.Split(new char[1] { '|' });
                                                                        AddFootnoteText(footparts[0].Trim(), footparts[1].Trim());
                                                                        sBoldText = "";
                                                                    }
                                                                    else //output the LINK (and in some case actual footnote)
                                                                        if (sBoldText.IndexOf("footnotelink") > -1)
                                                                        {
                                                                            /* Implementation
                                                                             * All footnotes in the 'first file' processed, which is not written.
                                                                             * Instead the notes are stored in a HASH (FootnoteHash).
                                                                             * Now as we hit FOOTNOTELINK we lookup the footnote from the hash
                                                                             */

                                                                            InlineWrite(" "); // August 2010 insert a blank space to make footnote work?

                                                                            sBoldText = sBoldText.Replace("footnotelink", "");
                                                                            // the text remaining should be the name of the footnotelink

                                                                            AddFootnote(sBoldText.ToLower());

                                                                            // store the number of footnotes in the current chapter
                                                                            if (Footnotes_in_specific_chapter.ContainsKey(chapter) == true)
                                                                            {
                                                                                Footnotes_in_specific_chapter[chapter] = ((int)Footnotes_in_specific_chapter[chapter]) + 1;

                                                                            }
                                                                            else
                                                                            {
                                                                                Footnotes_in_specific_chapter.Add(chapter, 1);
                                                                            }

                                                                            FootnoteLog = FootnoteLog + "," + sBoldText.ToLower();
                                                                            sBoldText = "";

                                                                        }
                                                                        else
                                                                            if (sBoldText.IndexOf("Anchor") > -1)
                                                                            {
                                                                                sBoldText = sBoldText.Replace("Anchor", "");
                                                                                AddBookmark(sBoldText);
                                                                                sBoldText = "";
                                                                            }
                                                                           // else if (sBoldText.IndexOf("~scene") > -1)
                                                                            else if (YomParse.KeywordMatch(sBoldText, YomParse.KEYWORD_SCENE) == true)
                                                                            {
                                                                                // if we find a break we pull the macro that has been assigned
                                                                                // to the properties ControlFile and put that text here
                                                                                // F 2010 - I use this for typing less text with my scene breaks
                                                                                //.InlineWrite("[[~center]]#[[~left]]");
                                                                                //string sResult = @controlFile.SceneBreak; //[[~center]]\r\n#\r\n[[~left]]
                                                                                //@sResult = @sResult.Replace(@"\\", @"\");
                                                                                //Console.WriteLine(@sResult);
                                                                                //InlineWrite("\r\n");

                                                                                if (controlFile.Overridesectionbreak == Constants.BLANK)
                            {
                                FormatRestOfText("[[~center]]", false);
                                                                                FormatRestOfText(controlFile.SceneBreak, true);
                                FormatRestOfText("[[~left]]", false);
                            }
                            else
                            {
                                OverrideSceneBreak();
                            }

                                                                                if (true == controlFile.SceneBreakHasTab)
                                                                                {
                                                                                    AddTab();
                                                                                    // February 15 2011
                                                                                    // The other fix I made to keep
                                                                                    // from losing NEEDED LINESPACE
                                                                                    // unfortuantely is now adding
                                                                                    // linespace after a scene.
                                                                                    //Trying to remove this.
                                                                                    AddLineFeed = false;
                                                                                }
                                                                                //sBoldText = Environment.NewLine + Environment.NewLine + sBoldText;
                                                                                // FormatRestOfText(@"[[~center]]\r\n#\r\n[[~left]]");
                                                                            }
                                                                            else
                                                                                if (sBoldText.IndexOf("~TOC") > -1)
                                                                                {
                                                                                    AddTableOfContents();
                                                                                    sBoldText = "";
                                                                                }
                                                                                else
                                                                                    if (sBoldText.IndexOf("~var=") > -1)
                                                                                    {
                                                                                        VariableAdd(sBoldText);
                                                                                        sBoldText = "";
                                                                                    }
                                                                                    else
                                                                                        if (sBoldText.IndexOf("~var") > -1)
                                                                                        {
                                                                                            // swap in variable

                                                                                            sBoldText = VariableSwap(sBoldText);

                                                                                            // need to solve linefeed issue

                                                                                            ApplyAllInlineFormats(sBoldText, controlFile, false);
                                                                                            sBoldText = " "; // inteintiona July 2011
                                                                                            if (sBoldText != "")
                                                                                            {
                                                                                                bAllowWrite = true;
                                                                                            }
                                                                                        }
                                                                                        else
                                                                                            if (sBoldText.IndexOf("~Footnotecount") > -1)
                                                                                            {
                                                                                                sBoldText = sBoldText.Replace("~Footnotecount", "").Trim();

                                                                                                if (Footnotes_in_specific_chapter.Count > 0)
                                                                                                {
                                                                                                    ArrayList list = new ArrayList(Footnotes_in_specific_chapter.Keys);

                                                                                                    list.Sort();
                                                                                                    foreach (int key in list)
                                                                                                    {
                                                                                                        AddTable((key - 1) + " " + Footnotes_in_specific_chapter[key]);

                                                                                                    }

                                                                                                }

                                                                                            }
                                                                                            else
                                                                                                if (sBoldText.IndexOf("~Display") > -1)
                                                                                                {
                                                                                                    // System.Windows.Forms.MessageBox.Show(tallyTable.Count.ToString());
                                                                                                    sBoldText = sBoldText.Replace("~Display", "").Trim();
                                                                                                    // get just source like b
                                                                                                    if (tallyTable.ContainsKey(sBoldText) == true)
                                                                                                    {
                                                                                                        //InlineWrite(tallyTable[sBoldText].ToString());
                                                                                                        string[] displayitems = tallyTable[sBoldText].ToString().Split(',');
                                                                                                        if (displayitems != null)
                                                                                                        {
                                                                                                            AddTable("||Reference||\n");
                                                                                                            foreach (string s in displayitems)
                                                                                                            {

                                                                                                                AddTable(String.Format("{0}\n", s));
                                                                                                                //ApplyAllInlineFormats(s, controlFile);
                                                                                                                //InlineWrite( s  + "\n");
                                                                                                            }
                                                                                                        }
                                                                                                    }

                                                                                                }
                                                                                                else
                                                                                                    if (sBoldText.IndexOf("~Tally") > -1)
                                                                                                    {
                                                                                                        sBoldText = sBoldText.Replace("~Tally", "").Trim();
                                                                                                        // get just source like b
                                                                                                        if (tallyTable.ContainsKey(sBoldText) == true)
                                                                                                        {
                                                                                                            InlineWrite(tallyTable[sBoldText].ToString().Split(',').Length.ToString());
                                                                                                        }
                                                                                                    }
                                                                                                    else
                                                                                                    {

                                                                                                        if (sBoldText.IndexOf("optional") > -1)
                                                                                                        {
                                                                                                            bOptional = true;
                                                                                                        }
                                                                                                        //  VariableCheck(sBoldText, sOriginal, sFormats);

                                                                                                        // in this situation we intentional DO NOT take
                                                                                                        // the return value from VariableCheck unlike
                                                                                                        /// the later call which is intended for when
                                                                                                        /// we have code within formatting

                                                                                                        // may 2012
                            //NewMessage.Show ("Variable Checked on line 943");
                                                                                                        VariableCheck(sBoldText, sOriginal, sFormats, false);
                            // OKAY: The logic here is that a few lines down (if bAllowWrite) we set the text to blank.
                            //  so the errors we are are gettings (19/06/2014) may not have anything inherently to do with facts and are
                            // something that just crops up with </p> tag matching. In novel mode. perhaps only.

                                                                                                      //  VariableCheck2(sOriginal, sFormats);
                                                                                                    }
                                                if (bOptional == true)
                                                {
                                                    // optinal is special, we insert formatting expression
                                                    switch (controlFile.OptionalCode)
                                                    {
                                                        case 1: InlineBold(1); break;
                                                        case 2: InlineItalic(1); break;
                                                    }

                                                    sBoldText = " " + controlFile.Optional;
                                                }
                                                else
                                                    if (bAllowWrite == false)
                                                    {
                        //	NewMessage.Show ("Setting boldtext to blank");
                                                        sBoldText = ""; // we don't want to write codes
                                                      //  AddLineFeed = false; // june 2011 to get rid of empyt comments

                                                        //January 2012
                                                        // I am missing some linefeeds, specifically when a [[f]] is
                                                        // anywhere in preceding line.
                                                        // I think I need to test to see if a linefeed is PRESENT
                                                        // in sOriginal
                                                        // DID NOT WORK! So I commented out the June 2011 change
                                                        /*
                                                        if (sOriginal.IndexOf("\\n") > -1 || sOriginal.IndexOf("\\r") > -1)
                                                        {
                                                            AddLineFeed = true;
                                                        }*/
                                                    }
                                            }

                    // june 2010 moving things here so formatted text can be parsed for this
                    if (sBoldText.IndexOf("[[") > -1)
                    {
                        // this applies ONLY when we have code with formatting.
                        //NewMessage.Show ("Variable Check on 982");
                       sBoldText =  VariableCheck(sBoldText, sOriginal, sFormats, true);

                    }

                    //if (TEXT_NULL != sBoldText) // June 2 2011 -- don't write blank lines from Varisble comments
                    {
                        InlineWrite(sBoldText);
                    }
                    /*OVerkill   else
                       {
                           // we had only a start tag and no end, so we write out the offending
                           // text (the FrontTag) and then chop it off.
                           InlineWrite(sFrontTag);
                           char[] trimChars = new char[sFrontTag.Length];
                           for (int i= 0; i < sFrontTag.Length; i++)
                           {
                               char c = sFrontTag[i];
                               trimChars[i] = c;
                           }
                           sSource = sSource.TrimStart(trimChars);
                       }
                       */
                    if (sFrontTag == "'''''")
                    {
                        //NewMessage.Show ("here1");
                        InlineItalic(0);
                        InlineBold(0);

                    }
                    else
                        if (sFrontTag == "'''")
                        {
                        //NewMessage.Show ("here");
                            InlineBold(0);
                            // oSelection.set_Style(ref controlFile.oBodyText);

                        }
                        else
                            if (sFrontTag == "''")
                            {
                                InlineItalic(0);
                            }
                            else

                                if (sFrontTag == "_")
                                {
                                    // November 2012
                                    // We only turn off udnerlining or italics if expressedly ordered to do so
                                    // that is, we no longer stop underlining unless we started underlining (this prevents us from ruining
                                    // a <past> section

                                        if (false == controlFile.UnderscoreKeep)
                                        {
                                            if (true == controlFile.UnderlineShouldBeItalicInstead)
                                            {
                                                InlineItalic(0);
                                            }
                                            else
                                                InlineUnderline(0);
                                        }
                                        else
                                        {
                                            // just leave the underscore alone
                                            InlineWrite("_");
                                        }

                                }
                                else
                                    if (sFrontTag == "---")
                                    {
                                        InlineStrikeThrough(0);
                                    }
                                    else

                                        if (sFrontTag == "<<<")
                                        {
                                            ChatMode(0);
                                        }

                                    else if (sFrontTag == "^")
                                    {
                                        InlineSuper(0);
                                    }
                                    else if (sFrontTag == "##")
                                    {
                                        InlineSub(0);
                                    }
                                    else

                                        if (sFrontTag == "|")
                                        {

                                            // add a | back if this is a link
                                            if (lastLink != "")
                                                sSource = "|" + sSource;
                                        }
                                        else if (sEndTag == "]]")
                                        {
                    //	NewMessage.Show ("huh");
                                            // do nothing
                                            switch (controlFile.OptionalCode)
                                            {
                                                case 1: InlineBold(0); break;
                                                case 2: InlineItalic(0); break;
                                            }
                                        }

                    //     nFirstStart = sSource.IndexOf(sFrontTag);

                }
                else
                {
                    // if not end tag, we just break
                    break;
                }

            }
            string sLast = sSource;
            if ("" != sLast /*&& TEXT_NULL != sLast*/)
            {
                InlineWrite(sLast);
            }

            //TEXT_NULL is to prevent variable comment lines (empty variables) from adding linesapce)

            if (true == AddLineFeed)
            {
                InlineWrite(Environment.NewLine);
            }
        }
Пример #6
0
 protected void ApplyAllInlineFormats(string sSource, ControlFile controlFile)
 {
     ApplyAllInlineFormats(sSource, controlFile, true);
 }
Пример #7
0
        /// <summary>
        /// before whatever initial operations are required to open the filestream
        /// or whatever (in the case of Word Auto, will require global variables)
        /// error code of -1 means to abort the write process
        /// </summary>
        protected virtual int InitializeDocument(ControlFile _controlFile)
        {
            FootnoteHash = new Hashtable();
            Footnotes_in_specific_chapter = new Hashtable();
            controlFile = _controlFile;
            tallyTable = new System.Collections.Hashtable();
            variableTable = new System.Collections.Hashtable();

            return 1;
        }
Пример #8
0
        /// <summary>
        /// This routine will handle the parsing of the file and will call other functions
        /// that will be INHERITED by the child classes to actually handle the creation of the end documentation
        /// </summary>
        /// <param name="sTextFile">The plain text file, in wiki-code format, to parse</param>
        /// <param name="sControlFile">a file containing info on what template should be used and such</param>
        /// <param name="stopat">the chapter -1 to stop at (4 means stop at end of chapter 3)</param>
        public string WriteText(string sTextFile, /*string sControlFile*/ ControlFile zcontrolfile, int stopat)
        {
            bookmarks = new System.Collections.ArrayList();
            _stopat = stopat; // chapter to stop at
            int linecount = 0;
            int newlinecount = 0;
            int blankline = 0;
            if (File.Exists(sTextFile) == false)
            {
                throw new Exception(sTextFile + " does not exist");
            }
            if (null == zcontrolfile)
            {
                throw new Exception("Control file does not exist");
            }
               // try
              //  {
              //  ControlFile zcontrolFile = (ControlFile)CoreUtilities.General.DeSerialize(sControlFile, typeof(ControlFile));
               if ( InitializeDocument(zcontrolfile) == -1) return Constants.BLANK;

                // load template file (ToDo: must do this for real eventually)

                StreamReader reader = new StreamReader(sTextFile);

                string sLine = reader.ReadLine();
                while (sLine != null)
                {
                    linecount++; // may 2012 tracking line count
                    if ("" == sLine)
                    {
                        blankline++;
                    }
                    string sText = sLine;
                    sFulltext = sFulltext + sLine; // fulltext is simply used by some routines for error checking

                   /* if (sText.IndexOf("Motto") > -1)
                    {
                        int ii = 9;
                    }
            */

                    // if we have hit chapter threshold than stop
                    if ((stopat > 0) && chapter == (stopat + 1))
                    {
                        break;
                    }

                if (zcontrolfile.ListOfTags != null && zcontrolfile.ListOfTags.Length > 0)
                {
                    foreach (string tag in zcontrolfile.ListOfTags)
                    {
                        // process each tag
                        string[] tags = tag.Split (new char[1] {'|'});
                        if (tags != null && 2 == tags.Length)
                        {
                            string inner_tag= tags[0];
                            string format = tags[1];
                            string buildtag_front = String.Format ("<{0}>", inner_tag);
                            string buildtag_end = String.Format ("</{0}>", inner_tag);

                            // April 2013
                            // experimenting with inline tagging
                            sText = sText.Replace (buildtag_front, format);
                            sText = sText.Replace (buildtag_end, format);
                        }
                    }
                }

                sText = FixHTMLEncoding(sText);
                // April 2013
                // replace -- with emdash if that's teh setting
                if (controlFile.ConvertToEmDash == true)
                {

                    sText = HandleEmDash(sText);
                }

                    // January 2012
                    // We have an issue when saving as HTML that my fancy heading text
                    // becomes really ugly UNDERLINES
                    // I'm thinking of stripping out long rows of spaces
                    if (controlFile.RemoveExcessSpaces == true)
                    {
                        while (sText.IndexOf("     ") > -1)
                        {
                            sText = sText.Replace("     ", "");
                        }
                    }

            //                    if (sText.IndexOf("---") > -1)
            //                    {
            //                        NewMessage.Show(Loc.Instance.GetString ("You have three hyphens. Probably error. Quitting"));
            //                        return "";
            //                    }

                    if (sText.IndexOf("\"'") > -1)
                    {
                    //    throw new Exception("You have a \" mixed with a ' which is likely an error. Shutting down.");
                    UpdateErrors ("Possible ERrors: " + sText);
                     }
                     if (sText.IndexOf("'\"") > -1)
                     {
                         //throw new Exception("You have a \" mixed with a ' which is likely an error. Shutting down.");
                    UpdateErrors ("Possible ERrors: " + sText);
                     }

                    // log common typos
                    if (sText.IndexOf("\"'") > -1)
                    {
                        UpdateErrors("Possible Errors: " + sText);
                    }

                    // first test for table
                    if (sText.IndexOf("||") == 0)
                    {
                        AddTable(sText);
                    }
                    else
                    FormatRestOfText(sText);

                    sLine = reader.ReadLine();
                }
                //oSelection.ParagraphFormat.LineSpacing = 2F;
                // oSelection.ParagraphFormat.LineSpacingRule = Microsoft.Office.Interop.Word.WdLineSpacing.wdLineSpaceSingle;
                reader.Close();

                newlinecount = this.LineCount();
                Cleanup();
             /*   }
            catch (Exception ex)
            {
                System.Windows.Forms.MessageBox.Show(ex.ToString());
            }*/

            string line = String.Format("LINE COUNT OLD: {0} BLANK: {1} NEW: {2}",linecount.ToString(),
                blankline, newlinecount.ToString());
            sError = sError + Environment.NewLine + line;

            if (newlinecount != (linecount+blankline))
            {
                string sLineError = String.Format("LINES DO NOT MATCH. Original lines {0} + blank lines {1} = {2} but new lines is = {3}. NOTE: Extra blank space at TOP of will throw count off.",
                    linecount, blankline, linecount + blankline, newlinecount);

                if (false == SuppressMessages)
                {
                NewMessage.Show(sLineError);
                }
            }
            if (error_CountInlineBrackets > 0)
            {
                string ExtraBrackets = String.Format("You have extra brackets #{0}", error_CountInlineBrackets);
                NewMessage.Show(ExtraBrackets);
            }

            // also add it to END message
            controlFile.EndMessage = String.Format("{0} {1} {2}", controlFile.EndMessage,
                Environment.NewLine, line);

            OnFinishedTotally();
            return sError;
        }