예제 #1
0
 public void FormatInline(FlowDocument doc, Inline inline, StringBuilder buf, int indent)
 {
     // indent
      buf.Append (' ', indent);
      buf.AppendFormat (
     "{0} {1} to {2}",
     inline.GetType ().Name + inline.GetHashCode (),
     inline.ContentStart.CompareTo (doc.ContentStart),
     inline.ContentEnd.CompareTo (doc.ContentStart));
      if (inline is Run)
      {
     buf.Append ("  \"" + ((Run)inline).Text + "\"");
      }
      buf.AppendLine ();
      if (inline is Underline)
      {
     FormatInlines (doc, ((Underline)inline).Inlines,  buf, indent + 3);
      }
      if (inline is Italic)
      {
     FormatInlines (doc, ((Italic)inline).Inlines,  buf, indent + 3);
      }
 }
예제 #2
0
파일: TextPointer.cs 프로젝트: mind0n/hive
        // Inserts an Inline at the current location, adding contextual
        // elements as needed to enforce the schema.
        internal void InsertInline(Inline inline)
        {
            TextPointer position = this;

            // Check for hyperlink schema validity first -- we'll throw on an illegal Hyperlink descendent insert.
            bool isValidChild = TextSchema.ValidateChild(position, /*childType*/inline.GetType(), false /* throwIfIllegalChild */, true /* throwIfIllegalHyperlinkDescendent */);

            // Now, it is safe to assume that !isValidChild will be the case of incomplete content.
            if (!isValidChild)
            {
                if (position.Parent == null)
                {
                    // 
                    throw new InvalidOperationException(SR.Get(SRID.TextSchema_CannotInsertContentInThisPosition));
                }

                // Ensure text content.
                position = TextRangeEditTables.EnsureInsertionPosition(this);
                Invariant.Assert(position.Parent is Run, "EnsureInsertionPosition() must return a position in text content");
                Run run = (Run)position.Parent;

                if (run.IsEmpty)
                {
                    // Remove the implicit (empty) Run, since we are going to insert an inline at this position.
                    run.RepositionWithContent(null);
                }
                else
                {
                    // Position is parented by Run, split formatting elements to prepare for inserting inline at this position.
                    position = TextRangeEdit.SplitFormattingElement(position, /*keepEmptyFormatting:*/false);
                }

                Invariant.Assert(TextSchema.IsValidChild(position, /*childType*/inline.GetType()));
            }

            inline.RepositionWithContent(position);
        }