public static void DrawAnnotationBox(IGdiBuffer buffer, SolidBrush brush, IFontFactory fontFactory, string annotationText, AnnotationBox annotationBox, float dpi = _nominalScreenDpi) { var fakeFactory = new LegacyGdiObjectFactory(fontFactory, brush); DrawAnnotationBox(buffer, fakeFactory, annotationText, annotationBox, dpi); }
/// <summary> /// Creates an annotation box and shows it /// </summary> /// <param name="container"></param> public static void Show(AnnotationContainer container) { GameObject instance = (GameObject)GameObject.Instantiate(Resources.Load("AnnotationBox")); AnnotationBox annotationBox = instance.GetComponent <AnnotationBox>(); annotationBox.container = container; container.Select(); currentlyOpenAnnotationBox = annotationBox; }
private IEnumerator MakeAnnotation(int x, int y, int w, int h, AnnotationBox newAnno) { yield return(ButtonControls.current.PopUp()); string anno = ButtonControls.current.getPopupText(); newAnno.contents = anno; if (!anno.Equals("")) { FileStream writter; string toWrite = ",\n"; string filename = LocalAnnotationFile(); if (!File.Exists(filename)) { toWrite = "\n"; File.WriteAllText(filename, "{\n\t\"@context\": \"http://www.shared-canvas.org/ns/context.json\"," + "\n\t\"@id\": \"" + filename + "\"" + ",\n\t\"@type\": \"sc:AnnotationList\",\n\t\"resources\": [\n\t\n\t]\n}\n"); } toWrite += "\t\t{\n"; toWrite += "\t\t\t\"id\": \"_:an" + System.DateTime.UtcNow.ToBinary().ToString() + "\",\n"; toWrite += "\t\t\t\"@type\": \"oa:Annotation\",\n"; toWrite += "\t\t\t\"resource\": {\n"; toWrite += "\t\t\t\t\"id\": \"_:an" + System.DateTime.UtcNow.ToBinary().ToString() + "\",\n"; toWrite += "\t\t\t\t\"@type\": \"cnt:ContentAsText\",\n"; toWrite += "\t\t\t\t\"format\": \"text/plain\",\n"; toWrite += "\t\t\t\t\"chars\": \"" + anno + "\",\n"; toWrite += "\t\t\t\t\"language\": \"en\",\n"; toWrite += "\t\t\t},\n"; toWrite += "\t\t\t\"on\": \"" + webAddress + "#xywh=" + x.ToString() + "," + y.ToString() + "," + w.ToString() + "," + h.ToString() + "\"\n"; toWrite += "\t\t}"; writter = File.Open(filename, FileMode.OpenOrCreate, FileAccess.ReadWrite); writter.Seek(0, SeekOrigin.End); while (writter.ReadByte() != ']') { writter.Seek(-2, SeekOrigin.Current); } writter.Seek(-3, SeekOrigin.Current); byte[] myBytes = System.Text.Encoding.ASCII.GetBytes(toWrite); writter.Write(myBytes, 0, myBytes.Length); myBytes = System.Text.Encoding.ASCII.GetBytes("\n\t]\n}\n"); writter.Write(myBytes, 0, myBytes.Length); writter.Close(); } webdata.AddNewAnnotation(pageNum, newAnno); }
public CreateStringFormatArgs(AnnotationBox annotationBox) { if (annotationBox.Truncation == AnnotationBox.TruncationBehaviour.Truncate) { Trimming = StringTrimming.Character; } else { Trimming = StringTrimming.EllipsisCharacter; } if (annotationBox.FitWidth) { Trimming = StringTrimming.None; } if (annotationBox.Justification == AnnotationBox.JustificationBehaviour.Right) { Alignment = StringAlignment.Far; } else if (annotationBox.Justification == AnnotationBox.JustificationBehaviour.Center) { Alignment = StringAlignment.Center; } else { Alignment = StringAlignment.Near; } if (annotationBox.VerticalAlignment == AnnotationBox.VerticalAlignmentBehaviour.Top) { LineAlignment = StringAlignment.Near; } else if (annotationBox.VerticalAlignment == AnnotationBox.VerticalAlignmentBehaviour.Center) { LineAlignment = StringAlignment.Center; } else { LineAlignment = StringAlignment.Far; } //allow p's and q's, etc to extend slightly beyond the bounding rectangle. Only completely visible lines are shown. Flags = StringFormatFlags.NoClip; if (annotationBox.NumberOfLines == 1) { Flags |= StringFormatFlags.NoWrap; } _hash = ComputeHash(); }
private void HideOverlays() { if (_magnificationImage is IAnnotationLayoutProvider) { string magFactor = String.Format("{0:F1}x", ToolSettings.DefaultInstance.MagnificationFactor); AnnotationLayout layout = new AnnotationLayout(); BasicTextAnnotationItem item = new BasicTextAnnotationItem("mag", "mag", "mag", magFactor); AnnotationBox box = new AnnotationBox(new RectangleF(0.8F, 0F, .2F, .05F), item); box.Justification = AnnotationBox.JustificationBehaviour.Right; box.VerticalAlignment = AnnotationBox.VerticalAlignmentBehaviour.Top; layout.AnnotationBoxes.Add(box); ((BasicPresentationImage)_magnificationImage).AnnotationLayout = layout; } if (_magnificationImage is IOverlayGraphicsProvider) { GraphicCollection graphics = ((IOverlayGraphicsProvider)_magnificationImage).OverlayGraphics; foreach (IGraphic graphic in graphics) { graphic.Visible = false; } } if (_magnificationImage is IApplicationGraphicsProvider) { GraphicCollection graphics = ((IApplicationGraphicsProvider)_magnificationImage).ApplicationGraphics; foreach (IGraphic graphic in graphics) { graphic.Visible = false; } } //we want the Dicom graphics to be visible (e.g. shutter and embedded overlays) //if (_magnificationImage is IDicomPresentationImage) //{ // GraphicCollection graphics = ((IDicomPresentationImage)_magnificationImage).DicomGraphics; // foreach (IGraphic graphic in graphics) // graphic.Visible = false; //} }
/// <summary> /// Draws an <see cref="AnnotationBox"/>. Must be overridden and implemented. /// </summary> protected abstract void DrawAnnotationBox(string annotationText, AnnotationBox annotationBox);
private static void CreateDirectionalMarkerBox(float x, float y, float dx, float dy, AnnotationBox.JustificationBehaviour justification, string identifier, AnnotationBox newBox) { RectangleF normalizedRectangle = new RectangleF(x, y, dx, dy); newBox.NormalizedRectangle = normalizedRectangle; newBox.AnnotationItem = AnnotationLayoutFactory.GetAnnotationItem(identifier); newBox.Justification = justification; }
public AnnotationLayout Create() { AnnotationLayout layout = new AnnotationLayout(); int numberOfBoxesPerQuadrant = 15; float boxheight = 1 / 32.0F; float x = 0F, y = 0F, dx = 0.5F, dy = boxheight; AnnotationBox newBox; AnnotationBox defaultBoxSettings = new AnnotationBox(); defaultBoxSettings.Bold = true; defaultBoxSettings.Font = "Century Gothic"; //TL for (int i = 0; i < numberOfBoxesPerQuadrant; ++i) { dx = (i > 0) ? 0.5F : 0.4F; //make room for directional markers. RectangleF normalizedRectangle = new RectangleF(x, y, dx, dy); newBox = defaultBoxSettings.Clone(); newBox.NormalizedRectangle = normalizedRectangle; newBox.AnnotationItem = AnnotationLayoutFactory.GetAnnotationItem(_AssignmentsTopLeft[i]); layout.AnnotationBoxes.Add(newBox); y += boxheight; } defaultBoxSettings = new AnnotationBox(); defaultBoxSettings.Color = "OrangeRed"; defaultBoxSettings.Font = "Century Gothic"; defaultBoxSettings.Justification = AnnotationBox.JustificationBehaviour.Right; y = 0.0F; //TR for (int i = 0; i < numberOfBoxesPerQuadrant; ++i) { x = (i > 0) ? 0.5F : 0.6F; //make room for directional markers. dx = (i > 0) ? 0.5F : 0.4F; //make room for directional markers. RectangleF normalizedRectangle = new RectangleF(x, y, dx, dy); newBox = defaultBoxSettings.Clone(); newBox.NormalizedRectangle = normalizedRectangle; newBox.AnnotationItem = AnnotationLayoutFactory.GetAnnotationItem(_AssignmentsTopRight[i]); layout.AnnotationBoxes.Add(newBox); y += boxheight; } defaultBoxSettings = new AnnotationBox(); defaultBoxSettings.Color = "Cyan"; defaultBoxSettings.Font = "Century Gothic"; x = 0F; y = 1.0F - boxheight; //BL for (int i = numberOfBoxesPerQuadrant - 1; i >= 0; --i) { dx = (i < (numberOfBoxesPerQuadrant - 1)) ? 0.5F : 0.4F; //make room for directional markers. RectangleF normalizedRectangle = new RectangleF(x, y, dx, dy); newBox = defaultBoxSettings.Clone(); newBox.NormalizedRectangle = normalizedRectangle; newBox.AnnotationItem = AnnotationLayoutFactory.GetAnnotationItem(_AssignmentsBottomLeft[i]); if (i < numberOfBoxesPerQuadrant - 4 && !String.IsNullOrEmpty(_AssignmentsBottomLeft[i])) { newBox.ConfigurationOptions = new AnnotationItemConfigurationOptions(); newBox.ConfigurationOptions.ShowLabel = true; } layout.AnnotationBoxes.Add(newBox); y -= boxheight; } defaultBoxSettings = new AnnotationBox(); defaultBoxSettings.Color = "Yellow"; defaultBoxSettings.Font = "Century Gothic"; defaultBoxSettings.NumberOfLines = 2; defaultBoxSettings.Justification = AnnotationBox.JustificationBehaviour.Right; y = 1.0F - boxheight; //BR for (int i = numberOfBoxesPerQuadrant - 1; i >= 0; --i) { x = (i < (numberOfBoxesPerQuadrant - 1)) ? 0.5F : 0.6F; //make room for directional markers. dx = (i < (numberOfBoxesPerQuadrant - 1)) ? 0.5F : 0.4F; //make room for directional markers. RectangleF normalizedRectangle = new RectangleF(x, y, dx, dy); newBox = defaultBoxSettings.Clone(); newBox.NormalizedRectangle = normalizedRectangle; newBox.AnnotationItem = AnnotationLayoutFactory.GetAnnotationItem(_AssignmentsBottomRight[i]); if (!String.IsNullOrEmpty(_AssignmentsBottomRight[i])) newBox.NumberOfLines = 2; layout.AnnotationBoxes.Add(newBox); y -= boxheight; } defaultBoxSettings = new AnnotationBox(); defaultBoxSettings.Color = "White"; defaultBoxSettings.Bold = true; defaultBoxSettings.Font = "Century Gothic"; defaultBoxSettings.NumberOfLines = 1; newBox = defaultBoxSettings.Clone(); CreateDirectionalMarkerBox(0.00F, (1F - boxheight) / 2F, 0.1F, boxheight, AnnotationBox.JustificationBehaviour.Left, "Presentation.DirectionalMarkers.Left", newBox); layout.AnnotationBoxes.Add(newBox); newBox = defaultBoxSettings.Clone(); CreateDirectionalMarkerBox(0.90F, (1F - boxheight) / 2F, 0.1F, boxheight, AnnotationBox.JustificationBehaviour.Right, "Presentation.DirectionalMarkers.Right", newBox); layout.AnnotationBoxes.Add(newBox); newBox = defaultBoxSettings.Clone(); CreateDirectionalMarkerBox(0.45F, 0F, 0.1F, boxheight, AnnotationBox.JustificationBehaviour.Center, "Presentation.DirectionalMarkers.Top", newBox); layout.AnnotationBoxes.Add(newBox); newBox = defaultBoxSettings.Clone(); CreateDirectionalMarkerBox(0.45F, 1F - boxheight, 0.1F, boxheight, AnnotationBox.JustificationBehaviour.Center, "Presentation.DirectionalMarkers.Bottom", newBox); layout.AnnotationBoxes.Add(newBox); return layout; }
public AnnotationLayout Create() { AnnotationLayout layout = new AnnotationLayout(); int numberOfBoxesPerQuadrant = 15; float boxheight = 1 / 32.0F; float x = 0F, y = 0F, dx = 0.5F, dy = boxheight; AnnotationBox newBox; AnnotationBox defaultBoxSettings = new AnnotationBox(); defaultBoxSettings.Bold = true; defaultBoxSettings.Font = "Century Gothic"; //TL for (int i = 0; i < numberOfBoxesPerQuadrant; ++i) { dx = (i > 0) ? 0.5F : 0.4F; //make room for directional markers. RectangleF normalizedRectangle = new RectangleF(x, y, dx, dy); newBox = defaultBoxSettings.Clone(); newBox.NormalizedRectangle = normalizedRectangle; newBox.AnnotationItem = AnnotationLayoutFactory.GetAnnotationItem(_AssignmentsTopLeft[i]); layout.AnnotationBoxes.Add(newBox); y += boxheight; } defaultBoxSettings = new AnnotationBox(); defaultBoxSettings.Color = "OrangeRed"; defaultBoxSettings.Font = "Century Gothic"; defaultBoxSettings.Justification = AnnotationBox.JustificationBehaviour.Right; y = 0.0F; //TR for (int i = 0; i < numberOfBoxesPerQuadrant; ++i) { x = (i > 0) ? 0.5F : 0.6F; //make room for directional markers. dx = (i > 0) ? 0.5F : 0.4F; //make room for directional markers. RectangleF normalizedRectangle = new RectangleF(x, y, dx, dy); newBox = defaultBoxSettings.Clone(); newBox.NormalizedRectangle = normalizedRectangle; newBox.AnnotationItem = AnnotationLayoutFactory.GetAnnotationItem(_AssignmentsTopRight[i]); layout.AnnotationBoxes.Add(newBox); y += boxheight; } defaultBoxSettings = new AnnotationBox(); defaultBoxSettings.Color = "Cyan"; defaultBoxSettings.Font = "Century Gothic"; x = 0F; y = 1.0F - boxheight; //BL for (int i = numberOfBoxesPerQuadrant - 1; i >= 0; --i) { dx = (i < (numberOfBoxesPerQuadrant - 1)) ? 0.5F : 0.4F; //make room for directional markers. RectangleF normalizedRectangle = new RectangleF(x, y, dx, dy); newBox = defaultBoxSettings.Clone(); newBox.NormalizedRectangle = normalizedRectangle; newBox.AnnotationItem = AnnotationLayoutFactory.GetAnnotationItem(_AssignmentsBottomLeft[i]); if (i < numberOfBoxesPerQuadrant - 4 && !String.IsNullOrEmpty(_AssignmentsBottomLeft[i])) { newBox.ConfigurationOptions = new AnnotationItemConfigurationOptions(); newBox.ConfigurationOptions.ShowLabel = true; } layout.AnnotationBoxes.Add(newBox); y -= boxheight; } defaultBoxSettings = new AnnotationBox(); defaultBoxSettings.Color = "Yellow"; defaultBoxSettings.Font = "Century Gothic"; defaultBoxSettings.NumberOfLines = 2; defaultBoxSettings.Justification = AnnotationBox.JustificationBehaviour.Right; y = 1.0F - boxheight; //BR for (int i = numberOfBoxesPerQuadrant - 1; i >= 0; --i) { x = (i < (numberOfBoxesPerQuadrant - 1)) ? 0.5F : 0.6F; //make room for directional markers. dx = (i < (numberOfBoxesPerQuadrant - 1)) ? 0.5F : 0.4F; //make room for directional markers. RectangleF normalizedRectangle = new RectangleF(x, y, dx, dy); newBox = defaultBoxSettings.Clone(); newBox.NormalizedRectangle = normalizedRectangle; newBox.AnnotationItem = AnnotationLayoutFactory.GetAnnotationItem(_AssignmentsBottomRight[i]); if (!String.IsNullOrEmpty(_AssignmentsBottomRight[i])) { newBox.NumberOfLines = 2; } layout.AnnotationBoxes.Add(newBox); y -= boxheight; } defaultBoxSettings = new AnnotationBox(); defaultBoxSettings.Color = "White"; defaultBoxSettings.Bold = true; defaultBoxSettings.Font = "Century Gothic"; defaultBoxSettings.NumberOfLines = 1; newBox = defaultBoxSettings.Clone(); CreateDirectionalMarkerBox(0.00F, (1F - boxheight) / 2F, 0.1F, boxheight, AnnotationBox.JustificationBehaviour.Left, "Presentation.DirectionalMarkers.Left", newBox); layout.AnnotationBoxes.Add(newBox); newBox = defaultBoxSettings.Clone(); CreateDirectionalMarkerBox(0.90F, (1F - boxheight) / 2F, 0.1F, boxheight, AnnotationBox.JustificationBehaviour.Right, "Presentation.DirectionalMarkers.Right", newBox); layout.AnnotationBoxes.Add(newBox); newBox = defaultBoxSettings.Clone(); CreateDirectionalMarkerBox(0.45F, 0F, 0.1F, boxheight, AnnotationBox.JustificationBehaviour.Center, "Presentation.DirectionalMarkers.Top", newBox); layout.AnnotationBoxes.Add(newBox); newBox = defaultBoxSettings.Clone(); CreateDirectionalMarkerBox(0.45F, 1F - boxheight, 0.1F, boxheight, AnnotationBox.JustificationBehaviour.Center, "Presentation.DirectionalMarkers.Bottom", newBox); layout.AnnotationBoxes.Add(newBox); return(layout); }
/// <summary> /// Draws an annotation box to the specified destination buffer. /// </summary> /// <param name="buffer">The destination buffer.</param> /// <param name="gdiObjectFactory">A factory for GDI objects.</param> /// <param name="annotationText">The annotation text to be drawn.</param> /// <param name="annotationBox">The annotation box to be drawn.</param> /// <param name="dpi">The intended output DPI.</param> public static void DrawAnnotationBox(IGdiBuffer buffer, IGdiObjectFactory gdiObjectFactory, string annotationText, AnnotationBox annotationBox, float dpi = _nominalScreenDpi) { // if there's nothing to draw, there's nothing to do. go figure. if (string.IsNullOrWhiteSpace(annotationText)) { return; } var clientRectangle = RectangleUtilities.CalculateSubRectangle(buffer.Bounds, annotationBox.NormalizedRectangle); //Deflate the client rectangle by 4 pixels to allow some space //between neighbouring rectangles whose borders coincide. Rectangle.Inflate(clientRectangle, -4, -4); var fontSize = (clientRectangle.Height / annotationBox.NumberOfLines) - 1; //don't draw it if it's too small to read, anyway. if (fontSize < MinimumFontSizeInPixels) { return; } var style = FontStyle.Regular; if (annotationBox.Bold) { style |= FontStyle.Bold; } if (annotationBox.Italics) { style |= FontStyle.Italic; } //don't draw it if it's too small to read, anyway. if (fontSize < MinimumFontSizeInPixels) { return; } var fontArgs = new CreateFontArgs(annotationBox.Font, fontSize, style, GraphicsUnit.Pixel) { DefaultFontName = AnnotationBox.DefaultFont }; var font = gdiObjectFactory.CreateFont(fontArgs); var format = gdiObjectFactory.CreateStringFormat(new CreateStringFormatArgs(annotationBox)); var layoutArea = new SizeF(clientRectangle.Width, clientRectangle.Height); var size = buffer.Graphics.MeasureString(annotationText, font, layoutArea, format); if (annotationBox.FitWidth && size.Width > clientRectangle.Width) { fontSize = (int)(Math.Round(fontSize * clientRectangle.Width / (double)size.Width - 0.5)); //don't draw it if it's too small to read, anyway. if (fontSize < MinimumFontSizeInPixels) { return; } font = gdiObjectFactory.CreateFont(fontArgs); } // Draw drop shadow var brush = gdiObjectFactory.CreateBrush(new CreateBrushArgs(Color.Black)); clientRectangle.Offset(1, 1); buffer.Graphics.DrawString( annotationText, font, brush, clientRectangle, format); brush = gdiObjectFactory.CreateBrush(new CreateBrushArgs(annotationBox.Color)); clientRectangle.Offset(-1, -1); buffer.Graphics.DrawString( annotationText, font, brush, clientRectangle, format); }
/// <summary> /// Draws an <see cref="AnnotationBox"/>. /// </summary> protected override void DrawAnnotationBox(string annotationText, AnnotationBox annotationBox) { // if there's nothing to draw, there's nothing to do. go figure. if (string.IsNullOrEmpty(annotationText)) { return; } Rectangle clientRectangle = ClearCanvas.ImageViewer.Mathematics.RectangleUtilities.CalculateSubRectangle(Surface.ClientRectangle, annotationBox.NormalizedRectangle); //Deflate the client rectangle by 4 pixels to allow some space //between neighbouring rectangles whose borders coincide. Rectangle.Inflate(clientRectangle, -4, -4); int fontSize = (clientRectangle.Height / annotationBox.NumberOfLines) - 1; //don't draw it if it's too small to read, anyway. if (fontSize < MinimumFontSizeInPixels) { return; } StringFormat format = new StringFormat(); if (annotationBox.Truncation == AnnotationBox.TruncationBehaviour.Truncate) { format.Trimming = StringTrimming.Character; } else { format.Trimming = StringTrimming.EllipsisCharacter; } if (annotationBox.FitWidth) { format.Trimming = StringTrimming.None; } if (annotationBox.Justification == AnnotationBox.JustificationBehaviour.Right) { format.Alignment = StringAlignment.Far; } else if (annotationBox.Justification == AnnotationBox.JustificationBehaviour.Center) { format.Alignment = StringAlignment.Center; } else { format.Alignment = StringAlignment.Near; } if (annotationBox.VerticalAlignment == AnnotationBox.VerticalAlignmentBehaviour.Top) { format.LineAlignment = StringAlignment.Near; } else if (annotationBox.VerticalAlignment == AnnotationBox.VerticalAlignmentBehaviour.Center) { format.LineAlignment = StringAlignment.Center; } else { format.LineAlignment = StringAlignment.Far; } //allow p's and q's, etc to extend slightly beyond the bounding rectangle. Only completely visible lines are shown. format.FormatFlags = StringFormatFlags.NoClip; if (annotationBox.NumberOfLines == 1) { format.FormatFlags |= StringFormatFlags.NoWrap; } FontStyle style = FontStyle.Regular; if (annotationBox.Bold) { style |= FontStyle.Bold; } if (annotationBox.Italics) { style |= FontStyle.Italic; } //don't draw it if it's too small to read, anyway. if (fontSize < MinimumFontSizeInPixels) { return; } Font font = CreateFont(annotationBox.Font, fontSize, style, GraphicsUnit.Pixel, AnnotationBox.DefaultFont); try { SizeF layoutArea = new SizeF(clientRectangle.Width, clientRectangle.Height); SizeF size = Surface.FinalBuffer.Graphics.MeasureString(annotationText, font, layoutArea, format); if (annotationBox.FitWidth && size.Width > clientRectangle.Width) { fontSize = (int)(Math.Round(fontSize * clientRectangle.Width / (double)size.Width - 0.5)); //don't draw it if it's too small to read, anyway. if (fontSize < MinimumFontSizeInPixels) { return; } font.Dispose(); font = CreateFont(annotationBox.Font, fontSize, style, GraphicsUnit.Pixel, AnnotationBox.DefaultFont); } // Draw drop shadow _brush.Color = Color.Black; clientRectangle.Offset(1, 1); Surface.FinalBuffer.Graphics.DrawString( annotationText, font, _brush, clientRectangle, format); _brush.Color = Color.FromName(annotationBox.Color); clientRectangle.Offset(-1, -1); Surface.FinalBuffer.Graphics.DrawString( annotationText, font, _brush, clientRectangle, format); } finally { font.Dispose(); } }
protected override void DrawAnnotationBox(string annotationText, AnnotationBox annotationBox) { GdiRenderer.DrawAnnotationBox(Surface.OverlayBuffer, _gdiObjectFactory, annotationText, annotationBox, Dpi); }
/// <summary> /// Draws an annotation box 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="annotationText">The annotation text to be drawn.</param> /// <param name="annotationBox">The annotation box to be drawn.</param> /// <param name="dpi">The intended output DPI.</param> public static void DrawAnnotationBox(IGdiBuffer buffer, SolidBrush brush, FontFactory fontFactory, string annotationText, AnnotationBox annotationBox, float dpi = _nominalScreenDpi) { // if there's nothing to draw, there's nothing to do. go figure. if (string.IsNullOrEmpty(annotationText)) { return; } var clientRectangle = RectangleUtilities.CalculateSubRectangle(buffer.Bounds, annotationBox.NormalizedRectangle); //Deflate the client rectangle by 4 pixels to allow some space //between neighbouring rectangles whose borders coincide. Rectangle.Inflate(clientRectangle, -4, -4); var fontSize = (clientRectangle.Height / annotationBox.NumberOfLines) - 1; //don't draw it if it's too small to read, anyway. if (fontSize < MinimumFontSizeInPixels) { return; } using (var format = new StringFormat()) { if (annotationBox.Truncation == AnnotationBox.TruncationBehaviour.Truncate) { format.Trimming = StringTrimming.Character; } else { format.Trimming = StringTrimming.EllipsisCharacter; } if (annotationBox.FitWidth) { format.Trimming = StringTrimming.None; } if (annotationBox.Justification == AnnotationBox.JustificationBehaviour.Right) { format.Alignment = StringAlignment.Far; } else if (annotationBox.Justification == AnnotationBox.JustificationBehaviour.Center) { format.Alignment = StringAlignment.Center; } else { format.Alignment = StringAlignment.Near; } if (annotationBox.VerticalAlignment == AnnotationBox.VerticalAlignmentBehaviour.Top) { format.LineAlignment = StringAlignment.Near; } else if (annotationBox.VerticalAlignment == AnnotationBox.VerticalAlignmentBehaviour.Center) { format.LineAlignment = StringAlignment.Center; } else { format.LineAlignment = StringAlignment.Far; } //allow p's and q's, etc to extend slightly beyond the bounding rectangle. Only completely visible lines are shown. format.FormatFlags = StringFormatFlags.NoClip; if (annotationBox.NumberOfLines == 1) { format.FormatFlags |= StringFormatFlags.NoWrap; } var style = FontStyle.Regular; if (annotationBox.Bold) { style |= FontStyle.Bold; } if (annotationBox.Italics) { style |= FontStyle.Italic; } //don't draw it if it's too small to read, anyway. if (fontSize < MinimumFontSizeInPixels) { return; } var font = fontFactory.GetFont(annotationBox.Font, fontSize, style, GraphicsUnit.Pixel, AnnotationBox.DefaultFont); var layoutArea = new SizeF(clientRectangle.Width, clientRectangle.Height); var size = buffer.Graphics.MeasureString(annotationText, font, layoutArea, format); if (annotationBox.FitWidth && size.Width > clientRectangle.Width) { fontSize = (int)(Math.Round(fontSize * clientRectangle.Width / (double)size.Width - 0.5)); //don't draw it if it's too small to read, anyway. if (fontSize < MinimumFontSizeInPixels) { return; } font = fontFactory.GetFont(annotationBox.Font, fontSize, style, GraphicsUnit.Pixel, AnnotationBox.DefaultFont); } // Draw drop shadow brush.Color = Color.Black; clientRectangle.Offset(1, 1); buffer.Graphics.DrawString( annotationText, font, brush, clientRectangle, format); brush.Color = Color.FromName(annotationBox.Color); clientRectangle.Offset(-1, -1); buffer.Graphics.DrawString( annotationText, font, brush, clientRectangle, format); } }
/// <summary> /// Draws an <see cref="AnnotationBox"/>. /// </summary> protected override void DrawAnnotationBox(string annotationText, AnnotationBox annotationBox) { DrawAnnotationBox(Surface.FinalBuffer, _brush, _fontFactory, annotationText, annotationBox, Dpi); }
private static void DrawAnnotationBox(System.Drawing.Graphics g, Rectangle destination, string annotationText, AnnotationBox annotationBox) { Font font; Rectangle rect = RectangleUtilities.CalculateSubRectangle(destination, annotationBox.NormalizedRectangle); Rectangle.Inflate(rect, -4, -4); int num = (rect.Height / annotationBox.NumberOfLines) - 1; StringFormat stringFormat = new StringFormat(); if (annotationBox.Truncation == AnnotationBox.TruncationBehaviour.Truncate) { stringFormat.Trimming = StringTrimming.Character; } else { stringFormat.Trimming = StringTrimming.EllipsisCharacter; } if (annotationBox.FitWidth) { stringFormat.Trimming = StringTrimming.None; } if (annotationBox.Justification == AnnotationBox.JustificationBehaviour.Right) { stringFormat.Alignment = StringAlignment.Far; } else if (annotationBox.Justification == AnnotationBox.JustificationBehaviour.Center) { stringFormat.Alignment = StringAlignment.Center; } else { stringFormat.Alignment = StringAlignment.Near; } if (annotationBox.VerticalAlignment == AnnotationBox.VerticalAlignmentBehaviour.Top) { stringFormat.LineAlignment = StringAlignment.Near; } else if (annotationBox.VerticalAlignment == AnnotationBox.VerticalAlignmentBehaviour.Center) { stringFormat.LineAlignment = StringAlignment.Center; } else { stringFormat.LineAlignment = StringAlignment.Far; } stringFormat.FormatFlags = StringFormatFlags.NoClip; if (annotationBox.NumberOfLines == 1) { stringFormat.FormatFlags |= StringFormatFlags.NoWrap; } FontStyle regular = FontStyle.Regular; if (annotationBox.Bold) { regular |= FontStyle.Bold; } if (annotationBox.Italics) { regular |= FontStyle.Italic; } try { font = new Font(annotationBox.Font, (float)num, regular, GraphicsUnit.Pixel); } catch (Exception exception) { Platform.Log(LogLevel.Error, exception); font = new Font(AnnotationBox.DefaultFont, (float)num, FontStyle.Regular, GraphicsUnit.Pixel); } SizeF layoutArea = new SizeF((float)rect.Width, (float)rect.Height); SizeF ef2 = g.MeasureString(annotationText, font, layoutArea, stringFormat); if (annotationBox.FitWidth && (ef2.Width > rect.Width)) { num = (int)Math.Round((double)((((double)(num * rect.Width)) / ((double)ef2.Width)) - 0.5)); try { font = new Font(annotationBox.Font, (float)num, regular, GraphicsUnit.Pixel); } catch (Exception exception2) { Platform.Log(LogLevel.Error, exception2); font = new Font(AnnotationBox.DefaultFont, (float)num, FontStyle.Regular, GraphicsUnit.Pixel); } } SolidBrush brush = new SolidBrush(Color.Black); rect.Offset(1, 1); g.DrawString(annotationText, font, brush, rect, stringFormat); brush.Color = Color.FromName(annotationBox.Color); rect.Offset(-1, -1); g.DrawString(annotationText, font, brush, rect, stringFormat); brush.Dispose(); font.Dispose(); }
/// <summary> /// called if the close-button is pressed /// closes the AnnotationBox /// </summary> public void Close() { container.Deselect(); currentlyOpenAnnotationBox = null; Destroy(gameObject); }