public StoredAnnotationBoxGroup(string identifier) { Platform.CheckForEmptyString(identifier, "identifier"); _identifier = identifier; _defaultBoxSettings = new AnnotationBox(); _annotationBoxes = new AnnotationBoxList(); }
private static IAnnotationLayout CreateRealLayout(string storedLayoutId) { try { StoredAnnotationLayout storedLayout = GetStoredLayout(storedLayoutId); if (storedLayout != null) { return(storedLayout.Clone()); } //just return an empty layout. return(new AnnotationLayout()); } catch (Exception e) { Platform.Log(LogLevel.Error, e); var layout = new AnnotationLayout(); var item = new BasicTextAnnotationItem("errorbox", "errorbox", @"LabelError", SR.MessageErrorLoadingAnnotationLayout); var box = new AnnotationBox(new RectangleF(0.5F, 0.90F, 0.5F, 0.10F), item) { Bold = true, Color = "Red", Justification = AnnotationBox.JustificationBehaviour.Right, NumberOfLines = 5, VerticalAlignment = AnnotationBox.VerticalAlignmentBehaviour.Bottom }; layout.AnnotationBoxes.Add(box); return(layout); } }
private void DeserializeAnnotationBoxes(StoredAnnotationBoxGroup group, XmlNodeList annotationBoxNodes) { foreach (XmlElement annotationBoxNode in annotationBoxNodes) { string normalizedRectangleString = annotationBoxNode.GetAttribute("normalized-rectangle"); RectangleF normalizedRectangle; if (!DeserializeNormalizedRectangle(normalizedRectangleString, out normalizedRectangle)) { continue; } XmlElement boxSettingsNode = (XmlElement)annotationBoxNode.SelectSingleNode("box-settings"); AnnotationBox newBox = group.DefaultBoxSettings.Clone(); newBox.NormalizedRectangle = normalizedRectangle; if (boxSettingsNode != null) { DeserializeBoxSettings(newBox, boxSettingsNode); } string annotationItemIdentifier = annotationBoxNode.GetAttribute("annotation-item-id"); foreach (IAnnotationItem item in _availableAnnotationItems) { if (item.GetIdentifier() == annotationItemIdentifier) { newBox.AnnotationItem = item; break; } } group.AnnotationBoxes.Add(newBox); } }
private void SerializeAnnotationBoxSettings(AnnotationBox annotationBox, AnnotationBox defaultSettings, XmlElement boxSettingsNode) { //only save values that are different from the defaults. if (annotationBox.Bold != defaultSettings.Bold) { boxSettingsNode.SetAttribute("bold", annotationBox.Bold ? "true" : "false"); } if (annotationBox.Italics != defaultSettings.Italics) { boxSettingsNode.SetAttribute("italics", annotationBox.Italics ? "true" : "false"); } if (annotationBox.Font != defaultSettings.Font) { boxSettingsNode.SetAttribute("font", annotationBox.Font); } if (annotationBox.Color != defaultSettings.Color) { boxSettingsNode.SetAttribute("color", annotationBox.Color); } if (annotationBox.NumberOfLines != defaultSettings.NumberOfLines) { boxSettingsNode.SetAttribute("number-of-lines", annotationBox.NumberOfLines.ToString(System.Globalization.CultureInfo.InvariantCulture)); } if (annotationBox.Truncation != defaultSettings.Truncation) { boxSettingsNode.SetAttribute("truncation", annotationBox.Truncation.ToString()); } if (annotationBox.Justification != defaultSettings.Justification) { boxSettingsNode.SetAttribute("justification", annotationBox.Justification.ToString()); } if (annotationBox.VerticalAlignment != defaultSettings.VerticalAlignment) { boxSettingsNode.SetAttribute("vertical-alignment", annotationBox.VerticalAlignment.ToString()); } if (annotationBox.FitWidth != defaultSettings.FitWidth) { boxSettingsNode.SetAttribute("fit-width", annotationBox.FitWidth ? "true" : "false"); } XmlElement configurationSettingsNode = this.Document.CreateElement("configuration-settings"); if (annotationBox.ConfigurationOptions.ShowLabel != defaultSettings.ConfigurationOptions.ShowLabel) { configurationSettingsNode.SetAttribute("show-label", annotationBox.ConfigurationOptions.ShowLabel ? "true" : "false"); } if (annotationBox.ConfigurationOptions.ShowLabelIfValueEmpty != defaultSettings.ConfigurationOptions.ShowLabelIfValueEmpty) { configurationSettingsNode.SetAttribute("show-label-if-empty", annotationBox.ConfigurationOptions.ShowLabelIfValueEmpty ? "true" : "false"); } if (configurationSettingsNode.Attributes.Count > 0) { boxSettingsNode.AppendChild(configurationSettingsNode); } }
/// <summary> /// Creates a deep clone of this object. /// </summary> public AnnotationBox Clone() { var clone = new AnnotationBox(); clone._alwaysVisible = this._alwaysVisible; // bool clone._annotationItem = this._annotationItem; // clone copy reference if (this._annotationItemConfigurationOptions != null) clone._annotationItemConfigurationOptions = this._annotationItemConfigurationOptions.Clone(); clone._bold = this._bold; // bool clone._color = this._color; // string clone._fitWidth = this._fitWidth; // bool clone._font = this._font; // string clone._italics = this._italics; // bool clone._justification = this._justification; // enum clone._normalizedRectangle = this._normalizedRectangle; // rect clone._numberOfLines = this._numberOfLines; // byte clone._truncation = this._truncation; // enum clone._verticalAlignment = this._verticalAlignment; // enum clone._visible = this._visible; // bool return clone; }
private void SerializeAnnotationBoxSettings(AnnotationBox annotationBox, AnnotationBox defaultSettings, XmlElement boxSettingsNode) { //only save values that are different from the defaults. if (annotationBox.Bold != defaultSettings.Bold) boxSettingsNode.SetAttribute("bold", annotationBox.Bold ? "true" : "false"); if (annotationBox.Italics != defaultSettings.Italics) boxSettingsNode.SetAttribute("italics", annotationBox.Italics ? "true" : "false"); if (annotationBox.Font != defaultSettings.Font) boxSettingsNode.SetAttribute("font", annotationBox.Font); if (annotationBox.Color != defaultSettings.Color) boxSettingsNode.SetAttribute("color", annotationBox.Color); if (annotationBox.NumberOfLines != defaultSettings.NumberOfLines) boxSettingsNode.SetAttribute("number-of-lines", annotationBox.NumberOfLines.ToString(System.Globalization.CultureInfo.InvariantCulture)); if (annotationBox.Truncation != defaultSettings.Truncation) boxSettingsNode.SetAttribute("truncation", annotationBox.Truncation.ToString()); if (annotationBox.Justification != defaultSettings.Justification) boxSettingsNode.SetAttribute("justification", annotationBox.Justification.ToString()); if (annotationBox.VerticalAlignment != defaultSettings.VerticalAlignment) boxSettingsNode.SetAttribute("vertical-alignment", annotationBox.VerticalAlignment.ToString()); if (annotationBox.FitWidth != defaultSettings.FitWidth) boxSettingsNode.SetAttribute("fit-width", annotationBox.FitWidth ? "true" : "false"); XmlElement configurationSettingsNode = this.Document.CreateElement("configuration-settings"); if (annotationBox.ConfigurationOptions.ShowLabel != defaultSettings.ConfigurationOptions.ShowLabel) configurationSettingsNode.SetAttribute("show-label", annotationBox.ConfigurationOptions.ShowLabel ? "true" : "false"); if (annotationBox.ConfigurationOptions.ShowLabelIfValueEmpty != defaultSettings.ConfigurationOptions.ShowLabelIfValueEmpty) configurationSettingsNode.SetAttribute("show-label-if-empty", annotationBox.ConfigurationOptions.ShowLabelIfValueEmpty ? "true" : "false"); if (configurationSettingsNode.Attributes.Count > 0) boxSettingsNode.AppendChild(configurationSettingsNode); }
private void SerializeAnnotationBoxes(IList<AnnotationBox> annotationBoxes, AnnotationBox defaultBoxSettings, XmlElement groupNode) { XmlElement boxesNode = this.Document.CreateElement("annotation-boxes"); groupNode.AppendChild(boxesNode); foreach (AnnotationBox box in annotationBoxes) { XmlElement boxNode = this.Document.CreateElement("annotation-box"); boxesNode.AppendChild(boxNode); string normalizedRectangle = String.Format("{0:F6}\\{1:F6}\\{2:F6}\\{3:F6}", box.NormalizedRectangle.Left, box.NormalizedRectangle.Top, box.NormalizedRectangle.Right, box.NormalizedRectangle.Bottom); boxNode.SetAttribute("normalized-rectangle", normalizedRectangle); boxNode.SetAttribute("annotation-item-id", (box.AnnotationItem == null) ? "" : box.AnnotationItem.GetIdentifier()); XmlElement settingsNode = this.Document.CreateElement("box-settings"); SerializeAnnotationBoxSettings(box, defaultBoxSettings, settingsNode); if (settingsNode.ChildNodes.Count > 0 || settingsNode.Attributes.Count > 0) boxNode.AppendChild(settingsNode); } }
private void DeserializeBoxSettings(AnnotationBox boxSettings, XmlElement boxSettingsNode) { string font = boxSettingsNode.GetAttribute("font"); string color = boxSettingsNode.GetAttribute("color"); string italics = boxSettingsNode.GetAttribute("italics"); string bold = boxSettingsNode.GetAttribute("bold"); string numberOfLines = boxSettingsNode.GetAttribute("number-of-lines"); string truncation = boxSettingsNode.GetAttribute("truncation"); string justification = boxSettingsNode.GetAttribute("justification"); string verticalAlignment = boxSettingsNode.GetAttribute("vertical-alignment"); string fitWidth = boxSettingsNode.GetAttribute("fit-width"); string alwaysVisible = boxSettingsNode.GetAttribute("always-visible"); if (!String.IsNullOrEmpty(font)) boxSettings.Font = font; if (!String.IsNullOrEmpty(color)) boxSettings.Color = color; if (!String.IsNullOrEmpty(italics)) boxSettings.Italics = (String.Compare("true", italics, true) == 0); if (!String.IsNullOrEmpty(bold)) boxSettings.Bold = (String.Compare("true", bold, true) == 0); if (!String.IsNullOrEmpty(numberOfLines)) { byte result; if (!byte.TryParse(numberOfLines, System.Globalization.NumberStyles.Integer, System.Globalization.CultureInfo.InvariantCulture, out result)) result = 1; boxSettings.NumberOfLines = result; } if (!String.IsNullOrEmpty(fitWidth)) boxSettings.FitWidth = (String.Compare("true", fitWidth) == 0); if (!String.IsNullOrEmpty(alwaysVisible)) boxSettings.AlwaysVisible = (String.Compare("true", alwaysVisible, true) == 0); if (!String.IsNullOrEmpty(truncation)) { AnnotationBox.TruncationBehaviour fromString = boxSettings.Truncation; EnumConverter converter = new EnumConverter(typeof(AnnotationBox.TruncationBehaviour)); if (converter.IsValid(truncation)) boxSettings.Truncation = (AnnotationBox.TruncationBehaviour)converter.ConvertFromString(truncation); } if (!String.IsNullOrEmpty(justification)) { AnnotationBox.JustificationBehaviour fromString = boxSettings.Justification; EnumConverter converter = new EnumConverter(typeof(AnnotationBox.JustificationBehaviour)); if (converter.IsValid(justification)) boxSettings.Justification = (AnnotationBox.JustificationBehaviour)converter.ConvertFromString(justification); } if (!String.IsNullOrEmpty(verticalAlignment)) { AnnotationBox.VerticalAlignmentBehaviour fromString = boxSettings.VerticalAlignment; EnumConverter converter = new EnumConverter(typeof(AnnotationBox.VerticalAlignmentBehaviour)); if (converter.IsValid(verticalAlignment)) boxSettings.VerticalAlignment = (AnnotationBox.VerticalAlignmentBehaviour)converter.ConvertFromString(verticalAlignment); } XmlElement configurationSettings = (XmlElement)boxSettingsNode.SelectSingleNode("configuration-settings"); if (configurationSettings != null) { string showLabel = configurationSettings.GetAttribute("show-label"); string showLabelIfEmpty = configurationSettings.GetAttribute("show-label-if-empty"); if (!String.IsNullOrEmpty(showLabel)) boxSettings.ConfigurationOptions.ShowLabel = (String.Compare("true", showLabel, true) == 0); if (!String.IsNullOrEmpty(showLabelIfEmpty)) boxSettings.ConfigurationOptions.ShowLabelIfValueEmpty = (String.Compare("true", showLabelIfEmpty, true) == 0); } }
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 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(); } }
/// <summary> /// Cloning constructor. /// </summary> /// <param name="source">The source object from which to clone.</param> /// <param name="context">This parameter is unused.</param> private StoredAnnotationBoxGroup(StoredAnnotationBoxGroup source, ICloningContext context) { this._identifier = source._identifier; this._defaultBoxSettings = source._defaultBoxSettings.Clone(); this._annotationBoxes = source._annotationBoxes.Clone(); }
private void SerializeAnnotationBoxes(IList <AnnotationBox> annotationBoxes, AnnotationBox defaultBoxSettings, XmlElement groupNode) { XmlElement boxesNode = this.Document.CreateElement("annotation-boxes"); groupNode.AppendChild(boxesNode); foreach (AnnotationBox box in annotationBoxes) { XmlElement boxNode = this.Document.CreateElement("annotation-box"); boxesNode.AppendChild(boxNode); string normalizedRectangle = String.Format("{0:F6}\\{1:F6}\\{2:F6}\\{3:F6}", box.NormalizedRectangle.Left, box.NormalizedRectangle.Top, box.NormalizedRectangle.Right, box.NormalizedRectangle.Bottom); boxNode.SetAttribute("normalized-rectangle", normalizedRectangle); boxNode.SetAttribute("annotation-item-id", (box.AnnotationItem == null) ? "" : box.AnnotationItem.GetIdentifier()); XmlElement settingsNode = this.Document.CreateElement("box-settings"); SerializeAnnotationBoxSettings(box, defaultBoxSettings, settingsNode); if (settingsNode.ChildNodes.Count > 0 || settingsNode.Attributes.Count > 0) { boxNode.AppendChild(settingsNode); } } }
private void DeserializeBoxSettings(AnnotationBox boxSettings, XmlElement boxSettingsNode) { string font = boxSettingsNode.GetAttribute("font"); string color = boxSettingsNode.GetAttribute("color"); string italics = boxSettingsNode.GetAttribute("italics"); string bold = boxSettingsNode.GetAttribute("bold"); string numberOfLines = boxSettingsNode.GetAttribute("number-of-lines"); string truncation = boxSettingsNode.GetAttribute("truncation"); string justification = boxSettingsNode.GetAttribute("justification"); string verticalAlignment = boxSettingsNode.GetAttribute("vertical-alignment"); string fitWidth = boxSettingsNode.GetAttribute("fit-width"); string alwaysVisible = boxSettingsNode.GetAttribute("always-visible"); if (!String.IsNullOrEmpty(font)) { boxSettings.Font = font; } if (!String.IsNullOrEmpty(color)) { boxSettings.Color = color; } if (!String.IsNullOrEmpty(italics)) { boxSettings.Italics = (String.Compare("true", italics, true) == 0); } if (!String.IsNullOrEmpty(bold)) { boxSettings.Bold = (String.Compare("true", bold, true) == 0); } if (!String.IsNullOrEmpty(numberOfLines)) { byte result; if (!byte.TryParse(numberOfLines, System.Globalization.NumberStyles.Integer, System.Globalization.CultureInfo.InvariantCulture, out result)) { result = 1; } boxSettings.NumberOfLines = result; } if (!String.IsNullOrEmpty(fitWidth)) { boxSettings.FitWidth = (String.Compare("true", fitWidth) == 0); } if (!String.IsNullOrEmpty(alwaysVisible)) { boxSettings.AlwaysVisible = (String.Compare("true", alwaysVisible, true) == 0); } if (!String.IsNullOrEmpty(truncation)) { AnnotationBox.TruncationBehaviour fromString = boxSettings.Truncation; EnumConverter converter = new EnumConverter(typeof(AnnotationBox.TruncationBehaviour)); if (converter.IsValid(truncation)) { boxSettings.Truncation = (AnnotationBox.TruncationBehaviour)converter.ConvertFromString(truncation); } } if (!String.IsNullOrEmpty(justification)) { AnnotationBox.JustificationBehaviour fromString = boxSettings.Justification; EnumConverter converter = new EnumConverter(typeof(AnnotationBox.JustificationBehaviour)); if (converter.IsValid(justification)) { boxSettings.Justification = (AnnotationBox.JustificationBehaviour)converter.ConvertFromString(justification); } } if (!String.IsNullOrEmpty(verticalAlignment)) { AnnotationBox.VerticalAlignmentBehaviour fromString = boxSettings.VerticalAlignment; EnumConverter converter = new EnumConverter(typeof(AnnotationBox.VerticalAlignmentBehaviour)); if (converter.IsValid(verticalAlignment)) { boxSettings.VerticalAlignment = (AnnotationBox.VerticalAlignmentBehaviour)converter.ConvertFromString(verticalAlignment); } } XmlElement configurationSettings = (XmlElement)boxSettingsNode.SelectSingleNode("configuration-settings"); if (configurationSettings != null) { string showLabel = configurationSettings.GetAttribute("show-label"); string showLabelIfEmpty = configurationSettings.GetAttribute("show-label-if-empty"); if (!String.IsNullOrEmpty(showLabel)) { boxSettings.ConfigurationOptions.ShowLabel = (String.Compare("true", showLabel, true) == 0); } if (!String.IsNullOrEmpty(showLabelIfEmpty)) { boxSettings.ConfigurationOptions.ShowLabelIfValueEmpty = (String.Compare("true", showLabelIfEmpty, true) == 0); } } }
private static IAnnotationLayout CreateRealLayout(string storedLayoutId) { try { StoredAnnotationLayout storedLayout = GetStoredLayout(storedLayoutId); if (storedLayout != null) return storedLayout.Clone(); //just return an empty layout. return new AnnotationLayout(); } catch (Exception e) { Platform.Log(LogLevel.Error, e); var layout = new AnnotationLayout(); var item = new BasicTextAnnotationItem("errorbox", "errorbox", @"LabelError", SR.MessageErrorLoadingAnnotationLayout); var box = new AnnotationBox(new RectangleF(0.5F, 0.90F, 0.5F, 0.10F), item) { Bold = true, Color = "Red", Justification = AnnotationBox.JustificationBehaviour.Right, NumberOfLines = 5, VerticalAlignment = AnnotationBox.VerticalAlignmentBehaviour.Bottom }; layout.AnnotationBoxes.Add(box); return layout; } }
/// <summary> /// Draws an <see cref="AnnotationBox"/>. /// </summary> protected override void DrawAnnotationBox(string annotationText, AnnotationBox annotationBox) { DrawAnnotationBox(Surface.FinalBuffer, _brush, _fontFactory, 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"/>. Must be overridden and implemented. /// </summary> protected abstract void DrawAnnotationBox(string annotationText, AnnotationBox annotationBox);
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); }