// Token: 0x06002EF4 RID: 12020 RVA: 0x000D4420 File Offset: 0x000D2620 internal static Rect _GetGlyphRunDesignRect(Glyphs g, int charStart, int charEnd) { GlyphRun glyphRun = g.ToGlyphRun(); if (glyphRun == null) { return(Rect.Empty); } Rect result = glyphRun.ComputeAlignmentBox(); result.Offset(glyphRun.BaselineOrigin.X, glyphRun.BaselineOrigin.Y); int num = 0; if (glyphRun.Characters != null) { num = glyphRun.Characters.Count; } else if (g.UnicodeString != null) { num = g.UnicodeString.Length; } if (charStart > num) { charStart = num; } else if (charStart < 0) { charStart = 0; } if (charEnd > num) { charEnd = num; } else if (charEnd < 0) { charEnd = 0; } double num2 = FixedTextView._GetDistanceToCharacter(glyphRun, charStart); double num3 = FixedTextView._GetDistanceToCharacter(glyphRun, charEnd); double width = num3 - num2; if ((glyphRun.BidiLevel & 1) != 0) { result.X = glyphRun.BaselineOrigin.X - num3; } else { result.X = glyphRun.BaselineOrigin.X + num2; } result.Width = width; return(result); }
internal void RenderFlowNode(DrawingContext dc) { FormattedText ft; FixedNode fixedNode; FixedSOMElement[] somElements; String ouptputString; FixedElement fixedElement; Random random = new Random(); CultureInfo EnglishCulture = System.Windows.Markup.TypeConverterHelper.InvariantEnglishUS; FixedPage fp = _fixedTextBuilder.FixedTextContainer.FixedDocument.GetFixedPage(PageIndex); // //Iterate through flow node to draw Transparent Rect and draw its index // Point prevTextPoint = new Point(0, 0); DpiScale dpi = fp.GetDpi(); for (int i = FlowStart.Fp; i <= FlowEnd.Fp; i++) { FlowNode fn = _fixedTextBuilder.FixedFlowMap[i]; switch (fn.Type) { case FlowNodeType.Boundary: case FlowNodeType.Virtual: // this two cases won't happen. Debug.Assert(false); break; case FlowNodeType.Start: case FlowNodeType.End: { fixedElement = fn.Cookie as FixedElement; String typeString = fixedElement.Type.ToString(); int indexofDot = typeString.LastIndexOf('.'); ouptputString = String.Format("{0}-{1}", fn.ToString(), typeString.Substring(indexofDot + 1)); ft = new FormattedText(ouptputString, EnglishCulture, FlowDirection.LeftToRight, new Typeface("Courier New"), 8, Brushes.DarkGreen, dpi.PixelsPerDip); // Ideally, for FlowNodeType.Start, this should find next FlowNode with physical location, // and draw it around the physical location. prevTextPoint = CreateFromLastTextPoint(prevTextPoint); dc.DrawText(ft, prevTextPoint); break; } case FlowNodeType.Noop: ft = new FormattedText(fn.ToString(), EnglishCulture, FlowDirection.LeftToRight, new Typeface("Courier New"), 8, Brushes.DarkGreen, dpi.PixelsPerDip); prevTextPoint = CreateFromLastTextPoint(prevTextPoint); dc.DrawText(ft, prevTextPoint); break; case FlowNodeType.Run: // // Paint the region. The rect is the union of child glyphs. // Glyphs glyphs; Rect flowRunBox = Rect.Empty; Rect glyphBox; somElements = _fixedTextBuilder.FixedFlowMap.FlowNodes[fn.Fp].FixedSOMElements; foreach (FixedSOMElement currentSomeElement in somElements) { FixedNode currentFixedNode = currentSomeElement.FixedNode; int startIndex = currentSomeElement.StartIndex; int endIndex = currentSomeElement.EndIndex; // same as (_IsBoundaryFixedNode(currentFixedNode)) if (currentFixedNode.Page == FixedFlowMap.FixedOrderStartPage || currentFixedNode.Page == FixedFlowMap.FixedOrderEndPage || currentFixedNode[1] == FixedFlowMap.FixedOrderStartVisual || currentFixedNode[1] == FixedFlowMap.FixedOrderEndVisual) { continue; } glyphs = fp.GetGlyphsElement(currentFixedNode); Debug.Assert(glyphs != null); glyphBox = FixedTextView._GetGlyphRunDesignRect(glyphs, startIndex, endIndex); if (!glyphBox.IsEmpty) { GeneralTransform g = glyphs.TransformToAncestor(fp); glyphBox = g.TransformBounds(glyphBox); } flowRunBox.Union(glyphBox); } if (flowRunBox.IsEmpty) { Debug.Assert(false); } prevTextPoint.X = flowRunBox.Right; prevTextPoint.Y = flowRunBox.Bottom - random.Next(15); // Draw something the upper left corner of region. ft = new FormattedText(fn.ToString() + "-" + Convert.ToString((int)(fn.Cookie)) + "-" + Convert.ToString(somElements.Length), EnglishCulture, FlowDirection.LeftToRight, new Typeface("Courier New"), 8, Brushes.DarkBlue, dpi.PixelsPerDip); dc.DrawText(ft, prevTextPoint); Pen pen = new Pen(Brushes.Blue, 2); flowRunBox.Inflate(random.Next(3), random.Next(3)); DrawRectOutline(dc, pen, flowRunBox); break; case FlowNodeType.Object: // // Find the mapping fixed node // somElements = _fixedTextBuilder.FixedFlowMap.FlowNodes[fn.Fp].FixedSOMElements; foreach (FixedSOMElement currentSomeElement in somElements) { fixedNode = currentSomeElement.FixedNode; DependencyObject dependencyObject = fp.GetElement(fixedNode); Image image = dependencyObject as Image; Path path = dependencyObject as Path; if (image != null || path != null) { Rect imageRect, boundingRect = Rect.Empty; // // Get Image bounding box. // GeneralTransform transform = ((Visual)dependencyObject).TransformToAncestor(fp); // You can't use GetContentBounds inside OnRender if (image != null) { boundingRect = new Rect(0, 0, image.Width, image.Height); } else { boundingRect = path.Data.Bounds; } if (!boundingRect.IsEmpty) { imageRect = transform.TransformBounds(boundingRect); // Image might overlap, inflate the box. imageRect.Inflate(3, 3); dc.DrawRectangle(Brushes.CadetBlue, null, imageRect); prevTextPoint.X = imageRect.Right; prevTextPoint.Y = imageRect.Top; } } else { // // If the object is the Image type(that is not likey). // Use the last Point to infer a comment area! // Debug.Assert(false); } fixedElement = fn.Cookie as FixedElement; ft = new FormattedText(fn.ToString(), EnglishCulture, FlowDirection.LeftToRight, new Typeface("Courier New"), 8, Brushes.DarkGreen, dpi.PixelsPerDip); dc.DrawText(ft, prevTextPoint); } break; default: Debug.Assert(false); break; } } }
// Token: 0x06002EDF RID: 11999 RVA: 0x000D3640 File Offset: 0x000D1840 internal override Rect GetRawRectangleFromTextPosition(ITextPointer position, out Transform transform) { FixedTextPointer fixedTextPointer = this.Container.VerifyPosition(position); Rect result = new Rect(0.0, 0.0, 0.0, 10.0); transform = Transform.Identity; FixedPosition fixedPosition; if (fixedTextPointer.FlowPosition.IsBoundary) { if (!this._GetFirstFixedPosition(fixedTextPointer, out fixedPosition)) { return(result); } } else if (!this._GetFixedPosition(fixedTextPointer, out fixedPosition)) { if (position.GetPointerContext(LogicalDirection.Forward) == TextPointerContext.None) { return(result); } ITextPointer position2 = position.CreatePointer(1); FixedTextPointer ftp = this.Container.VerifyPosition(position2); if (!this._GetFixedPosition(ftp, out fixedPosition)) { return(result); } } if (fixedPosition.Page != this.PageIndex) { return(result); } DependencyObject element = this.FixedPage.GetElement(fixedPosition.Node); if (element is Glyphs) { Glyphs glyphs = (Glyphs)element; result = FixedTextView._GetGlyphRunDesignRect(glyphs, fixedPosition.Offset, fixedPosition.Offset); GeneralTransform transform2 = glyphs.TransformToAncestor(this.FixedPage); result = this._GetTransformedCaretRect(transform2, result.TopLeft, result.Height); } else if (element is Image) { Image image = (Image)element; GeneralTransform transform3 = image.TransformToAncestor(this.FixedPage); Point origin = new Point(0.0, 0.0); if (fixedPosition.Offset > 0) { origin.X += image.ActualWidth; } result = this._GetTransformedCaretRect(transform3, origin, image.ActualHeight); } else if (element is Path) { Path path = (Path)element; GeneralTransform transform4 = path.TransformToAncestor(this.FixedPage); Rect bounds = path.Data.Bounds; Point topLeft = bounds.TopLeft; if (fixedPosition.Offset > 0) { topLeft.X += bounds.Width; } result = this._GetTransformedCaretRect(transform4, topLeft, bounds.Height); } return(result); }