Exemple #1
0
        private void setTaggedText(TextRange textRange)
        {
            Cache.settings.FontFormatTags.ForEach(a =>
            {
                Regex r = new Regex(@"\<" + a.name + @"\>(?<x0>" + a.regexContent + @")\<\/" + a.name + @"\>", RegexOptions.IgnoreCase | RegexOptions.Singleline);

                MatchCollection mc_r = r.Matches(textRange.Text);
                if (mc_r.Count > 0)
                {
                    foreach (Match m_r in mc_r)
                    {
                        try
                        {
                            switch (a.formatType)
                            {
                            case Structures.Core.FormattedRange.FormatType.Bold: textRange.Characters((m_r.Index + 1), m_r.Length).Font.Bold = Microsoft.Office.Core.MsoTriState.msoTrue; break;

                            case Structures.Core.FormattedRange.FormatType.Italic: textRange.Characters((m_r.Index + 1), m_r.Length).Font.Italic = Microsoft.Office.Core.MsoTriState.msoTrue; break;

                            case Structures.Core.FormattedRange.FormatType.StrikeThrough: textRange.Characters((m_r.Index + 1), m_r.Length).Font.StrikeThrough = Microsoft.Office.Core.MsoTriState.msoTrue; break;

                            case Structures.Core.FormattedRange.FormatType.SuperScript: textRange.Characters((m_r.Index + 1), m_r.Length).Font.SuperScript = Microsoft.Office.Core.MsoTriState.msoTrue; break;

                            case Structures.Core.FormattedRange.FormatType.SubScript: textRange.Characters((m_r.Index + 1), m_r.Length).Font.SubScript = Microsoft.Office.Core.MsoTriState.msoTrue; break;
                            }
                        }
                        catch (Exception ex)
                        {
                            Trace.WriteLine(ex.Message);
                        }
                    }
                }
            });
        }
        public static TextRange setItalic(TextRange textRange)
        {
            string text = textRange.Text;

            if (text.Contains("<i"))
            {
                MsoTriState state = MsoTriState.msoFalse;
                foreach (TextRange tr in textRange.Characters())
                {
                    tr.Font.Italic = state;
                    if (tr.Text == ">")
                    {
                        state = changeState(state);
                    }
                }

                foreach (TextRange trr in textRange.Runs())
                {
                    Console.WriteLine("RUN: " + trr.Text);
                    trr.Text = trr.Text.Replace("<i>", "").Replace("</i>", "");
                }
                return(textRange);
            }

            if (text.Contains("#"))
            {
                MsoTriState state = MsoTriState.msoFalse;
                foreach (TextRange tr in textRange.Characters())
                {
                    tr.Font.Italic = state;
                    if (tr.Text == "#")
                    {
                        state   = changeState(state);
                        tr.Text = "";
                    }
                }
                return(textRange);
            }

            /* int c = 0;
             * for (int e = 0; e < s.Length; e++)
             * {
             *   if (slideText[e] == '#')
             *   {
             *       c++;
             *   }
             * }*/
            return(null);
        }
Exemple #3
0
        /// <summary>
        /// Ajoute un espace entre chaque mot.
        /// </summary>
        /// <remarks>
        /// A priori, la config n'est pas utilisée, mais ça permet de réutiliser le même "pattern"
        /// </remarks>
        /// <param name="conf">La <see cref="Config"/> à utiliser.</param>
        public void AddSpace(Config conf)
        {
            logger.ConditionalDebug("AddSpace");
            bool previousIsSpace = false;

            for (int i = txtRange.Length - 1; i >= 0; i--)
            {
                if (txtRange.Text[i] == ' ')
                {
                    if (!previousIsSpace)
                    {
                        TextRange space = txtRange.Characters(i + 1, 1);
                        space.InsertAfter(" ");
                    }
                    previousIsSpace = true;
                }
                else
                {
                    previousIsSpace = false;
                }
            }
        }
        public static TextRange setItalic(TextRange textRange)
        {
            string text = textRange.Text;
            if (text.Contains("<i"))
            {
               MsoTriState state = MsoTriState.msoFalse;
               foreach (TextRange tr in textRange.Characters()) {
                    tr.Font.Italic = state;
                    if (tr.Text == ">")
                    {
                        state = changeState(state);
                    }
                }

                foreach (TextRange trr in textRange.Runs())
                {
                    Console.WriteLine("RUN: "+trr.Text);
                    trr.Text = trr.Text.Replace("<i>", "").Replace("</i>", "");
                }
                return textRange;
            }

            if (text.Contains("#"))
            {
                MsoTriState state = MsoTriState.msoFalse;
                foreach (TextRange tr in textRange.Characters())
                {
                    tr.Font.Italic = state;
                    if (tr.Text == "#")
                    {
                        state = changeState(state);
                        tr.Text = "";
                    }
                }
                return textRange;
            }
            /* int c = 0;
             for (int e = 0; e < s.Length; e++)
             {
                 if (slideText[e] == '#')
                 {
                     c++;
                 }
             }*/
            return null;
        }
Exemple #5
0
        /// <summary>
        /// Applique le formatage voulu au <see cref="FormattedTextEl"/> sur l'affichage.
        /// </summary>
        /// <param name="fte">Le <see cref="FormattedTextEl"/> qui doit être formaté.</param>
        /// <param name="conf">La <see cref="Config"/> à prendre en compte pour l'application du formatage.</param>
        protected override void SetChars(FormattedTextEl fte, Config conf)
        {
            TextRange theChars = txtRange.Characters(fte.First + 1, fte.Last - fte.First + 1);

            ApplyCFToRange(fte.cf, theChars, conf);
        }
Exemple #6
0
        private string getTextWithFontFormatting(TextRange textRange)
        {
            string rs = string.Empty;


            List <string> tags = new List <string>();

            Structures.Core.FormattedRange fr_previous = null;

            #region  |  get formatted range words  |

            string prefix = string.Empty;
            string suffix = string.Empty;


            if (textRange.Font.Bold == Microsoft.Office.Core.MsoTriState.msoTriStateMixed ||
                textRange.Font.Italic == Microsoft.Office.Core.MsoTriState.msoTriStateMixed ||
                textRange.Font.StrikeThrough == Microsoft.Office.Core.MsoTriState.msoTriStateMixed ||
                textRange.Font.SuperScript == Microsoft.Office.Core.MsoTriState.msoTriStateMixed ||
                textRange.Font.SubScript == Microsoft.Office.Core.MsoTriState.msoTriStateMixed)
            {
                bool continueMixedParse = true;


                if (continueMixedParse)
                {
                    for (int j = 1; j <= textRange.WordsCount; j++)
                    {
                        TextRange tr_j = textRange.Words(j);

                        if (tr_j.Font.Bold == Microsoft.Office.Core.MsoTriState.msoTrue ||
                            tr_j.Font.Bold == Microsoft.Office.Core.MsoTriState.msoTriStateMixed ||
                            tr_j.Font.Italic == Microsoft.Office.Core.MsoTriState.msoTrue ||
                            tr_j.Font.Italic == Microsoft.Office.Core.MsoTriState.msoTriStateMixed ||
                            tr_j.Font.StrikeThrough == Microsoft.Office.Core.MsoTriState.msoTrue ||
                            tr_j.Font.StrikeThrough == Microsoft.Office.Core.MsoTriState.msoTriStateMixed ||
                            tr_j.Font.SuperScript == Microsoft.Office.Core.MsoTriState.msoTrue ||
                            tr_j.Font.SuperScript == Microsoft.Office.Core.MsoTriState.msoTriStateMixed ||
                            tr_j.Font.SubScript == Microsoft.Office.Core.MsoTriState.msoTrue ||
                            tr_j.Font.SubScript == Microsoft.Office.Core.MsoTriState.msoTriStateMixed)
                        {
                            for (int i = 1; i <= tr_j.Text.Length; i++)
                            {
                                TextRange tr_i = tr_j.Characters(i);
                                //Bold = 1,
                                //Italic = 2,
                                //Name = 4,
                                //Size = 8,
                                //StrikeThrough = 16,
                                //SuperScript = 32,
                                //SubScript = 64,
                                //Underline = 128,

                                Structures.Core.FormattedRange fr_current = new Structures.Core.FormattedRange();
                                fr_current.text = (string)tr_i.Text.Clone();

                                prefix = string.Empty;
                                suffix = string.Empty;

                                #region  |  close  |

                                if (fr_previous != null)
                                {
                                    Cache.settings.FontFormatTags.ForEach(a =>
                                    {
                                        if (fr_previous.formatType.HasFlag(a.formatType) &&
                                            (Helpers.getMSFontState(tr_i, a) != Microsoft.Office.Core.MsoTriState.msoTrue ||
                                             tr_j.Text == "\r"))
                                        {
                                            suffix += "</" + a.name + ">" + suffix;
                                            tags.RemoveAt(tags.Count - 1);
                                        }
                                    });
                                }
                                #endregion


                                Cache.settings.FontFormatTags.ForEach(a =>
                                {
                                    if (Helpers.getMSFontState(tr_i, a) == Microsoft.Office.Core.MsoTriState.msoTrue)
                                    {
                                        fr_current.formatType |= a.formatType;
                                        if (fr_previous != null)
                                        {
                                            #region  |  open  |
                                            if (!fr_previous.formatType.HasFlag(a.formatType))
                                            {
                                                if (fr_current.text != "\r" || j != textRange.WordsCount)
                                                {
                                                    prefix += "<" + a.name + ">";
                                                    tags.Add(a.name);
                                                }
                                            }
                                            #endregion
                                        }
                                        else
                                        {
                                            if (fr_current.text != "\r" || j != textRange.WordsCount)
                                            {
                                                prefix += "<" + a.name + ">";
                                                tags.Add(a.name);
                                            }
                                        }
                                    }
                                    ;
                                });


                                if (tr_i.Font.Bold != Microsoft.Office.Core.MsoTriState.msoTrue &&
                                    tr_i.Font.Italic != Microsoft.Office.Core.MsoTriState.msoTrue &&
                                    tr_i.Font.StrikeThrough != Microsoft.Office.Core.MsoTriState.msoTrue &&
                                    tr_i.Font.SuperScript != Microsoft.Office.Core.MsoTriState.msoTrue &&
                                    tr_i.Font.SubScript != Microsoft.Office.Core.MsoTriState.msoTrue)
                                {
                                    fr_current.formatType = Structures.Core.FormattedRange.FormatType.None;
                                }

                                rs += suffix + prefix + fr_current.text;

                                fr_previous = (Structures.Core.FormattedRange)fr_current.Clone();
                            }
                        }
                        else
                        {
                            prefix = string.Empty;
                            suffix = string.Empty;

                            #region  |  close  |

                            if (fr_previous != null)
                            {
                                Cache.settings.FontFormatTags.ForEach(a =>
                                {
                                    if (fr_previous.formatType.HasFlag(a.formatType) &&
                                        (Helpers.getMSFontState(tr_j, a) != Microsoft.Office.Core.MsoTriState.msoTrue ||
                                         tr_j.Text == "\r"))
                                    {
                                        suffix += "</" + a.name + ">" + suffix;
                                        tags.RemoveAt(tags.Count - 1);
                                    }
                                });
                            }
                            #endregion

                            rs += suffix + tr_j.Text;


                            Structures.Core.FormattedRange _fr_current = new Structures.Core.FormattedRange();
                            _fr_current.text = tr_j.Text;
                            fr_previous      = (Structures.Core.FormattedRange)_fr_current.Clone();
                        }
                    }
                }
                else
                {
                    rs = (string)textRange.Text.Clone();
                }
            }
            else
            {
                rs = (string)textRange.Text.Clone();
            }
            #endregion

            if (tags.Count > 0)
            {
                tags.Reverse();
                foreach (string stag in tags)
                {
                    rs += "</" + stag + ">";
                }
            }

            return(rs);
        }