protected override void Serialize(ITextGraphic textGraphic, GraphicAnnotationSequenceItem serializationState) { // if the callout is not visible, don't serialize it! if (!textGraphic.Visible) { return; } if (string.IsNullOrEmpty(textGraphic.Text)) { return; } GraphicAnnotationSequenceItem.TextObjectSequenceItem text = new GraphicAnnotationSequenceItem.TextObjectSequenceItem(); textGraphic.CoordinateSystem = CoordinateSystem.Source; try { RectangleF boundingBox = RectangleUtilities.ConvertToPositiveRectangle(textGraphic.BoundingBox); text.BoundingBoxAnnotationUnits = GraphicAnnotationSequenceItem.BoundingBoxAnnotationUnits.Pixel; text.BoundingBoxTextHorizontalJustification = GraphicAnnotationSequenceItem.BoundingBoxTextHorizontalJustification.Left; text.BoundingBoxTopLeftHandCorner = boundingBox.Location; text.BoundingBoxBottomRightHandCorner = boundingBox.Location + boundingBox.Size; text.UnformattedTextValue = textGraphic.Text; } finally { textGraphic.ResetCoordinateSystem(); } serializationState.AppendTextObjectSequence(text); }
private static IGraphic CreateCalloutText(RectangleF annotationBounds, RectangleF displayedArea, GraphicAnnotationSequenceItem.TextObjectSequenceItem textItem) { if (textItem.AnchorPoint.HasValue) { CalloutGraphic callout = new CalloutGraphic(textItem.UnformattedTextValue); PointF anchor = textItem.AnchorPoint.Value; if (textItem.AnchorPointAnnotationUnits == GraphicAnnotationSequenceItem.AnchorPointAnnotationUnits.Display) { anchor = GetPointInSourceCoordinates(displayedArea, anchor); } callout.AnchorPoint = anchor; callout.ShowArrowhead = annotationBounds.IsEmpty; // show arrowhead if graphic annotation bounds are empty if (textItem.BoundingBoxTopLeftHandCorner.HasValue && textItem.BoundingBoxBottomRightHandCorner.HasValue) { PointF topLeft = textItem.BoundingBoxTopLeftHandCorner.Value; PointF bottomRight = textItem.BoundingBoxBottomRightHandCorner.Value; if (textItem.BoundingBoxAnnotationUnits == GraphicAnnotationSequenceItem.BoundingBoxAnnotationUnits.Display) { topLeft = GetPointInSourceCoordinates(displayedArea, topLeft); bottomRight = GetPointInSourceCoordinates(displayedArea, bottomRight); } callout.TextLocation = Vector.Midpoint(topLeft, bottomRight); } else { if (!annotationBounds.IsEmpty) { callout.TextLocation = annotationBounds.Location - new SizeF(30, 30); } else { callout.TextLocation = anchor - new SizeF(30, 30); } } return(callout); } else if (textItem.BoundingBoxTopLeftHandCorner.HasValue && textItem.BoundingBoxBottomRightHandCorner.HasValue) { InvariantTextPrimitive text = new InvariantTextPrimitive(textItem.UnformattedTextValue); PointF topLeft = textItem.BoundingBoxTopLeftHandCorner.Value; PointF bottomRight = textItem.BoundingBoxBottomRightHandCorner.Value; if (textItem.BoundingBoxAnnotationUnits == GraphicAnnotationSequenceItem.BoundingBoxAnnotationUnits.Display) { topLeft = GetPointInSourceCoordinates(displayedArea, topLeft); bottomRight = GetPointInSourceCoordinates(displayedArea, bottomRight); } // TODO: make the text variant - rotated as specified by bounding area - as well as justified as requested // RectangleF boundingBox = RectangleF.FromLTRB(topLeft.X, topLeft.Y, bottomRight.X, bottomRight.Y); // boundingBox = RectangleUtilities.ConvertToPositiveRectangle(boundingBox); // boundingBox.Location = boundingBox.Location - new SizeF(1, 1); text.Location = Vector.Midpoint(topLeft, bottomRight); return(new MoveControlGraphic(text)); } else { throw new InvalidDataException("The GraphicAnnotationSequenceItem must define either an anchor point or a bounding box."); } }