Beispiel #1
0
    internal override void VisitDocumentObjectCollection(DocumentObjectCollection elements)
    {
      ArrayList textIndices = new ArrayList();
      if (elements is ParagraphElements)
      {
        for (int idx = 0; idx < elements.Count; ++idx)
        {
          if (elements[idx] is Text)
            textIndices.Add(idx);
        }
      }

      int[] indices = (int[])textIndices.ToArray(typeof(int));
      if (indices != null)
      {
        int insertedObjects = 0;
        foreach (int idx in indices)
        {
          Text text = (Text)elements[idx + insertedObjects];
          string currentString = "";
          foreach (char ch in text.Content)
          {
            switch (ch)
            {
              case ' ':
              case '\r':
              case '\n':
              case '\t':
                if (currentString != "")
                {
                  elements.InsertObject(idx + insertedObjects, new Text(currentString));
                  ++insertedObjects;
                  currentString = "";
                }
                elements.InsertObject(idx + insertedObjects, new Text(" "));
                ++insertedObjects;
                break;

              case '-': //minus
                elements.InsertObject(idx + insertedObjects, new Text(currentString + ch));
                ++insertedObjects;
                currentString = "";
                break;

              case '­': //soft hyphen
                if (currentString != "")
                {
                  elements.InsertObject(idx + insertedObjects, new Text(currentString));
                  ++insertedObjects;
                  currentString = "";
                }
                elements.InsertObject(idx + insertedObjects, new Text("­"));
                ++insertedObjects;
                currentString = "";
                break;

              default:
                currentString += ch;
                break;
            }
          }
          if (currentString != "")
          {
            elements.InsertObject(idx + insertedObjects, new Text(currentString));
            ++insertedObjects;
          }
          elements.RemoveObjectAt(idx + insertedObjects);
          --insertedObjects;
        }
      }
    }
        internal override void VisitDocumentObjectCollection(DocumentObjectCollection elements)
        {
            List <int> textIndices = new List <int>();

            if (elements is ParagraphElements)
            {
                for (int idx = 0; idx < elements.Count; ++idx)
                {
                    if (elements[idx] is Text)
                    {
                        textIndices.Add(idx);
                    }
                }
            }

            int[] indices = (int[])textIndices.ToArray();
            if (indices != null)
            {
                int insertedObjects = 0;
                foreach (int idx in indices)
                {
                    Text   text          = (Text)elements[idx + insertedObjects];
                    string currentString = "";
                    foreach (char ch in text.Content)
                    {
                        // TODO Add support for other breaking spaces (en space, em space, &c.).
                        switch (ch)
                        {
                        case ' ':
                        case '\r':
                        case '\n':
                        case '\t':
                            if (currentString != "")
                            {
                                elements.InsertObject(idx + insertedObjects, new Text(currentString));
                                ++insertedObjects;
                                currentString = "";
                            }
                            elements.InsertObject(idx + insertedObjects, new Text(" "));
                            ++insertedObjects;
                            break;

                        case '-':     // minus.
                            elements.InsertObject(idx + insertedObjects, new Text(currentString + ch));
                            ++insertedObjects;
                            currentString = "";
                            break;

                        // Characters that allow line breaks without indication.
                        case '\u200B':     // zero width space.
                        case '\u200C':     // zero width non-joiner.
                            if (currentString != "")
                            {
                                elements.InsertObject(idx + insertedObjects, new Text(currentString));
                                ++insertedObjects;
                                currentString = "";
                            }
                            break;

                        case '­':     // soft hyphen.
                            if (currentString != "")
                            {
                                elements.InsertObject(idx + insertedObjects, new Text(currentString));
                                ++insertedObjects;
                                currentString = "";
                            }
                            elements.InsertObject(idx + insertedObjects, new Text("­"));
                            ++insertedObjects;
                            //currentString = "";
                            break;

                        default:
                            currentString += ch;
                            break;
                        }
                    }
                    if (currentString != "")
                    {
                        elements.InsertObject(idx + insertedObjects, new Text(currentString));
                        ++insertedObjects;
                    }
                    elements.RemoveObjectAt(idx + insertedObjects);
                    --insertedObjects;
                }
            }
        }
        internal override void VisitDocumentObjectCollection(DocumentObjectCollection elements)
        {
            List <int> textIndices = new List <int>();

            if (elements is ParagraphElements)
            {
                for (int idx = 0; idx < elements.Count; ++idx)
                {
                    if (elements[idx] is Text)
                    {
                        textIndices.Add(idx);
                    }
                }
            }

            int[] indices = (int[])textIndices.ToArray();
            if (indices != null)
            {
                int insertedObjects = 0;
                foreach (int idx in indices)
                {
                    Text   text          = (Text)elements[idx + insertedObjects];
                    string currentString = "";
                    foreach (char ch in text.Content)
                    {
                        switch (ch)
                        {
                        case ' ':
                        case '\r':
                        case '\n':
                        case '\t':
                            if (currentString != "")
                            {
                                elements.InsertObject(idx + insertedObjects, new Text(currentString));
                                ++insertedObjects;
                                currentString = "";
                            }
                            elements.InsertObject(idx + insertedObjects, new Text(" "));
                            ++insertedObjects;
                            break;

                        case '-':     //minus
                            elements.InsertObject(idx + insertedObjects, new Text(currentString + ch));
                            ++insertedObjects;
                            currentString = "";
                            break;

                        case '­':     //soft hyphen
                            if (currentString != "")
                            {
                                elements.InsertObject(idx + insertedObjects, new Text(currentString));
                                ++insertedObjects;
                                currentString = "";
                            }
                            elements.InsertObject(idx + insertedObjects, new Text("­"));
                            ++insertedObjects;
                            currentString = "";
                            break;

                        default:
                            currentString += ch;
                            break;
                        }
                    }
                    if (currentString != "")
                    {
                        elements.InsertObject(idx + insertedObjects, new Text(currentString));
                        ++insertedObjects;
                    }
                    elements.RemoveObjectAt(idx + insertedObjects);
                    --insertedObjects;
                }
            }
        }