/// <summary> /// Draws an <see cref="InvariantTextPrimitive"/>. /// </summary> protected override void DrawTextPrimitive(InvariantTextPrimitive textPrimitive) { textPrimitive.CoordinateSystem = CoordinateSystem.Destination; // We adjust the font size depending on the scale so that it's the same size // irrespective of the zoom var fontSize = CalculateScaledFontPoints(textPrimitive.SizeInPoints, Dpi); Font font = _fontFactory.CreateFont(textPrimitive.Font, fontSize, FontStyle.Regular, GraphicsUnit.Point, _defaultFont); // Calculate how big the text will be so we can set the bounding box textPrimitive.Dimensions = Surface.FinalBuffer.Graphics.MeasureString(textPrimitive.Text, font); // Draw drop shadow _brush.Color = Color.Black; SizeF dropShadowOffset = new SizeF(1, 1); PointF boundingBoxTopLeft = new PointF(textPrimitive.BoundingBox.Left, textPrimitive.BoundingBox.Top); Surface.FinalBuffer.Graphics.DrawString( textPrimitive.Text, font, _brush, boundingBoxTopLeft + dropShadowOffset); // Draw text _brush.Color = textPrimitive.Color; Surface.FinalBuffer.Graphics.DrawString( textPrimitive.Text, font, _brush, boundingBoxTopLeft); textPrimitive.ResetCoordinateSystem(); }
public ReferenceLineGraphic() { base.Graphics.Add(_text = new InvariantTextPrimitive()); base.Graphics.Add(_line = new LinePrimitive()); _text.BoundingBoxChanged += OnTextBoundingBoxChanged; }
public KeyObjectPlaceholderImage(string reason) : base(5, 5) { InvariantTextPrimitive textGraphic = new InvariantTextPrimitive(_reason = reason); textGraphic.Color = Color.WhiteSmoke; base.ApplicationGraphics.Add(textGraphic); }
public SliceControlGraphic(IGraphic subject, ResliceToolGraphic topParent) : base(subject) { _topParent = topParent; _textGraphic = new InvariantTextPrimitive(); _textGraphic.BoundingBoxChanged += TextGraphic_BoundingBoxChanged; base.Graphics.Add(_textGraphic); base.DecoratedGraphic.VisualStateChanged += DecoratedGraphic_VisualStateChanged; }
public KeyObjectPlaceholderImage(KeyImageReference keyImageReference, PresentationStateReference presentationStateReference, string reason) : base(5, 5) { _keyImageReference = keyImageReference; _presentationStateReference = presentationStateReference; InvariantTextPrimitive textGraphic = new InvariantTextPrimitive(_reason = reason); textGraphic.Color = Color.WhiteSmoke; base.ApplicationGraphics.Add(textGraphic); }
protected override void OnDrawing() { // upon drawing, re-centre the text RectangleF bounds = base.ClientRectangle; PointF anchor = new PointF(bounds.Left + bounds.Width / 2, bounds.Top + bounds.Height / 2); InvariantTextPrimitive textGraphic = (InvariantTextPrimitive)base.ApplicationGraphics.FirstOrDefault(IsType <InvariantTextPrimitive>); textGraphic.CoordinateSystem = CoordinateSystem.Destination; textGraphic.Location = anchor; textGraphic.ResetCoordinateSystem(); base.OnDrawing(); }
protected override void Dispose(bool disposing) { base.DecoratedGraphic.VisualStateChanged -= DecoratedGraphic_VisualStateChanged; if (_textGraphic != null) { _textGraphic.BoundingBoxChanged -= TextGraphic_BoundingBoxChanged; _textGraphic = null; } _topParent = null; base.Dispose(disposing); }
private static IControlGraphic CreateTextAreaGraphic() { InvariantTextPrimitive textArea = new InvariantTextPrimitive(); TextEditControlGraphic controlGraphic = new TextEditControlGraphic(new MoveControlGraphic(textArea)); controlGraphic.DeleteOnEmpty = true; StandardStatefulGraphic statefulGraphic = new StandardStatefulGraphic(controlGraphic); statefulGraphic.State = statefulGraphic.CreateInactiveState(); ContextMenuControlGraphic contextGraphic = new ContextMenuControlGraphic(typeof(TextCalloutTool).FullName, "basicgraphic-menu", null, statefulGraphic); contextGraphic.Actions = new ToolSet(new GraphicToolExtensionPoint(), new GraphicToolContext(contextGraphic)).Actions; return(contextGraphic); }
public static bool IsImageMarkupPresent(IPresentationImage image) { IOverlayGraphicsProvider currentOverlayGraphics = image as IOverlayGraphicsProvider; if (currentOverlayGraphics != null) { foreach (IGraphic graphic in currentOverlayGraphics.OverlayGraphics) { if (graphic is RoiGraphic) { return(true); } ContextMenuControlGraphic contextMenuControlGraphic = graphic as ContextMenuControlGraphic; if (contextMenuControlGraphic != null && contextMenuControlGraphic.Subject != null) { UserCalloutGraphic userCalloutGraphic = contextMenuControlGraphic.Subject as UserCalloutGraphic; if (userCalloutGraphic != null) { return(true); } InvariantTextPrimitive invariantTextPrimitive = contextMenuControlGraphic.Subject as InvariantTextPrimitive; if (invariantTextPrimitive != null) { return(true); } UserCrosshairCalloutGraphic crosshairGraphic = contextMenuControlGraphic.Subject as UserCrosshairCalloutGraphic; if (crosshairGraphic != null) { return(true); } } } } return(false); }
public void Toggle() { if (this.SelectedOverlayGraphicsProvider == null) { return; } if (this.SelectedPresentationImage == null) { return; } try { var selectPresentationImage = this.SelectedPresentationImage; IPrintViewImageViewer printViewImageViewer = this.ImageViewer as IPrintViewImageViewer; if (printViewImageViewer.ReferenceLines.ContainsKey(selectPresentationImage)) { foreach (var referenceLine in printViewImageViewer.ReferenceLines[selectPresentationImage]) { this.SelectedOverlayGraphicsProvider.OverlayGraphics.Remove(referenceLine); } } else { printViewImageViewer.ReferenceLines.Add(selectPresentationImage, new List <IGraphic>()); } DicomImagePlane targetImagePlane = DicomImagePlane.FromImage(selectPresentationImage); if (targetImagePlane == null) { return; } IDisplaySet displaySet = this.Context.Viewer.SelectedImageBox.DisplaySet; List <ReferenceLine> lines = new List <ReferenceLine>(); int index = 0; foreach (var referenceImage in displaySet.PresentationImages) { index++; if (referenceImage == selectPresentationImage) { continue; } if (jgCount != 0 && index % jgCount != 0) { continue; } DicomImagePlane referenceImagePlane = DicomImagePlane.FromImage(referenceImage); if (referenceImagePlane == null) { continue; } if (referenceImagePlane.StudyInstanceUid == targetImagePlane.StudyInstanceUid) { ReferenceLine line = GetReferenceLine(referenceImagePlane, targetImagePlane); // CompositeGraphic lineGraphic = new CompositeGraphic(); LinePrimitive linePrimitive = new LinePrimitive(); linePrimitive.LineStyle = LineStyle.Dash; linePrimitive.Point1 = line.StartPoint; linePrimitive.Point2 = line.EndPoint; InvariantTextPrimitive text = new InvariantTextPrimitive(line.Label); text.Location = new PointF(line.EndPoint.X + 10, line.EndPoint.Y); //lineGraphic.Graphics.Add(linePrimitive); //lineGraphic.Graphics.Add(text); bool isHaveSameLine = false; foreach (var referenceLine in lines) { if (line.StartPoint == referenceLine.StartPoint && line.EndPoint == referenceLine.EndPoint) { isHaveSameLine = true; break; } } if (!isHaveSameLine) { lines.Add(line); this.SelectedOverlayGraphicsProvider.OverlayGraphics.Add(linePrimitive); this.SelectedOverlayGraphicsProvider.OverlayGraphics.Add(text); printViewImageViewer.ReferenceLines[selectPresentationImage].Add(linePrimitive); printViewImageViewer.ReferenceLines[selectPresentationImage].Add(text); } } } selectPresentationImage.Tile.Draw(); } catch (Exception) { IPrintViewImageViewer printViewImageViewer = this.ImageViewer as IPrintViewImageViewer; if (printViewImageViewer.ReferenceLines.ContainsKey(this.SelectedPresentationImage)) { printViewImageViewer.ReferenceLines.Remove(this.SelectedPresentationImage); } } }
/// <summary> /// Draws an <see cref="InvariantTextPrimitive"/>. Must be overridden and implemented. /// </summary> protected abstract void DrawTextPrimitive(InvariantTextPrimitive textPrimitive);
/// <summary> /// Draws an <see cref="InvariantTextPrimitive"/>. /// </summary> protected override void DrawTextPrimitive(InvariantTextPrimitive textPrimitive) { DrawTextPrimitive(Surface.FinalBuffer, _brush, _fontFactory, textPrimitive, Dpi); }
/// <summary> /// Draws a text primitive to the specified destination buffer. /// </summary> /// <param name="buffer">The destination buffer.</param> /// <param name="brush">A GDI brush to use for drawing.</param> /// <param name="fontFactory">A GDI font factory to use for drawing.</param> /// <param name="text">The text primitive to be drawn.</param> /// <param name="dpi">The intended output DPI.</param> public static void DrawTextPrimitive(IGdiBuffer buffer, SolidBrush brush, FontFactory fontFactory, InvariantTextPrimitive text, float dpi = _nominalScreenDpi) { text.CoordinateSystem = CoordinateSystem.Destination; try { // We adjust the font size depending on the scale so that it's the same size // irrespective of the zoom var fontSize = CalculateScaledFontPoints(text.SizeInPoints, dpi); var font = fontFactory.GetFont(text.Font, fontSize, FontStyle.Regular, GraphicsUnit.Point, FontFactory.GenericSansSerif); // Calculate how big the text will be so we can set the bounding box text.Dimensions = buffer.Graphics.MeasureString(text.Text, font); // Draw drop shadow brush.Color = Color.Black; var dropShadowOffset = new SizeF(1, 1); var boundingBoxTopLeft = new PointF(text.BoundingBox.Left, text.BoundingBox.Top); buffer.Graphics.DrawString( text.Text, font, brush, boundingBoxTopLeft + dropShadowOffset); // Draw text brush.Color = text.Color; buffer.Graphics.DrawString( text.Text, font, brush, boundingBoxTopLeft); } finally { text.ResetCoordinateSystem(); } }
protected virtual void DrawTextPrimitive(InvariantTextPrimitive textPrimitive) { GdiRenderer.DrawTextPrimitive(Surface.OverlayBuffer, _gdiObjectFactory, textPrimitive, Dpi); }
public ExceptionGraphic() : base() { base.Graphics.Add(_textGraphic = new InvariantTextPrimitive()); _textGraphic.Color = Color.WhiteSmoke; }
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."); } }
public static void DrawTextPrimitive(IGdiBuffer buffer, SolidBrush brush, IFontFactory fontFactory, InvariantTextPrimitive text, float dpi = _nominalScreenDpi) { var fakeFactory = new LegacyGdiObjectFactory(fontFactory, brush); DrawTextPrimitive(buffer, fakeFactory, text, dpi); }
private void OnCloneComplete() { _textGraphic = (InvariantTextPrimitive)base.Graphics.FirstOrDefault(IsType <InvariantTextPrimitive>); }