示例#1
0
文件: Store.cs 项目: kpocza/docx2tex
        private bool KillEmptyStyles(out List <Run> simplifiedRuns, List <Run> originalRuns)
        {
            bool didKill = false;

            simplifiedRuns = new List <Run>(originalRuns);

            simplifiedRuns.RemoveAll(r => (r is TextRun) && string.IsNullOrEmpty((r as TextRun).Text));

            for (int i = 0; i < simplifiedRuns.Count - 1; i++)
            {
                Run run1 = simplifiedRuns[i];
                Run run2 = simplifiedRuns[i + 1];

                if (run1 is StyleStartRun && run2 is StyleEndRun &&
                    (run1 as StyleRun).Style == (run2 as StyleRun).Style)
                {
                    simplifiedRuns[i]     = new NullRun();
                    simplifiedRuns[i + 1] = new NullRun();
                    //simplifiedRuns.RemoveAt(i); //ith
                    //simplifiedRuns.RemoveAt(i); // i+1th
                    i++;
                    didKill = true;
                }
            }
            return(didKill);
        }
示例#2
0
文件: Store.cs 项目: kpocza/docx2tex
 private void MergeTextRuns(List <Run> simplifiedRuns)
 {
     for (int i = 0; i < simplifiedRuns.Count; i++)
     {
         if (simplifiedRuns[i] is TextRun)
         {
             string finalText = (simplifiedRuns[i] as TextRun).Text;
             bool   found     = false;
             int    j         = i + 1;
             while (j < simplifiedRuns.Count && simplifiedRuns[j] is TextRun)
             {
                 finalText        += (simplifiedRuns[j] as TextRun).Text;
                 simplifiedRuns[j] = new NullRun();
                 found             = true;
                 j++;
             }
             if (found)
             {
                 simplifiedRuns[i] = new TextRun(finalText);
             }
         }
     }
 }
示例#3
0
文件: Store.cs 项目: kpocza/docx2tex
        private List <Run> RunStyleKillers(List <Run> originalRuns)
        {
            List <Run> simplifiedRuns  = new List <Run>(originalRuns);
            int        cntActiveStyles = 0;

            for (int i = 0; i < simplifiedRuns.Count; i++)
            {
                Run run = simplifiedRuns[i];

                if (run is StyleStartRun)
                {
                    cntActiveStyles++;
                }
                else if (run is StyleEndRun)
                {
                    cntActiveStyles--;
                }

                if (run is StyleKillerRun && cntActiveStyles > 0)
                {
                    int cnt = cntActiveStyles;

                    int effectiveCnt = 0;
                    int j            = i - 1;
                    while (cnt > 0 && j > 0)
                    {
                        if (simplifiedRuns[j] is StyleStartRun)
                        {
                            effectiveCnt++;
                            if (effectiveCnt > 0)
                            {
                                simplifiedRuns[j] = new NullRun();
                                //simplifiedRuns.RemoveAt(j);
                                effectiveCnt--;
                                cnt--;
                                //i--;
                            }
                        }
                        else if (simplifiedRuns[j] is StyleEndRun)
                        {
                            effectiveCnt--;
                        }
                        j--;
                    }

                    cnt = cntActiveStyles;

                    effectiveCnt = 0;
                    j            = i + 1;

                    while (cnt > 0 && j < simplifiedRuns.Count)
                    {
                        if (simplifiedRuns[j] is StyleEndRun)
                        {
                            effectiveCnt++;
                            if (effectiveCnt > 0)
                            {
                                simplifiedRuns[j] = new NullRun();
                                //simplifiedRuns.RemoveAt(j);
                                effectiveCnt--;
                                cnt--;
                                //j--;
                            }
                        }
                        else if (simplifiedRuns[j] is StyleStartRun)
                        {
                            effectiveCnt--;
                        }
                        j++;
                    }
                }
            }
            return(simplifiedRuns);
        }