/// <summary> /// Gets the prefix drawing setting for long text. /// </summary> /// <param name="state">Palette value should be applicable to this state.</param> /// <returns>PaletteTextPrefix value.</returns> public virtual PaletteTextHotkeyPrefix GetContentLongTextPrefix(PaletteState state) { if (Apply) { PaletteTextHotkeyPrefix ret = _primaryContent.GetContentLongTextPrefix(Override ? OverrideState : state); if (ret == PaletteTextHotkeyPrefix.Inherit) { ret = _backupContent.GetContentLongTextPrefix(state); } return(ret); } else { return(_backupContent.GetContentLongTextPrefix(state)); } }
/// <summary> /// Gets the prefix drawing setting for long text. /// </summary> /// <param name="state">Palette value should be applicable to this state.</param> /// <returns>PaletteTextPrefix value.</returns> public override PaletteTextHotkeyPrefix GetContentLongTextPrefix(PaletteState state) { if (_apply) { PaletteTextHotkeyPrefix ret = _primary.GetContentLongTextPrefix(_override ? _state : state); if (ret == PaletteTextHotkeyPrefix.Inherit) { ret = _backup.GetContentLongTextPrefix(state); } return(ret); } else { return(_backup.GetContentLongTextPrefix(state)); } }
/// <summary> /// Initialize a new instance of the InternalStorage structure. /// </summary> public InternalStorage() { // Set to default values ContentTextHint = PaletteTextHint.Inherit; ContentTextTrim = PaletteTextTrim.Inherit; ContentTextPrefix = PaletteTextHotkeyPrefix.Inherit; ContentTextH = PaletteRelativeAlign.Inherit; ContentTextV = PaletteRelativeAlign.Inherit; ContentTextMultiLineH = PaletteRelativeAlign.Inherit; ContentTextMultiLine = InheritBool.Inherit; ContentTextColor1 = Color.Empty; ContentTextColor2 = Color.Empty; ContentTextColorStyle = PaletteColorStyle.Inherit; ContentTextColorAlign = PaletteRectangleAlign.Inherit; ContentTextColorAngle = -1; ContentTextImageStyle = PaletteImageStyle.Inherit; ContentTextImageAlign = PaletteRectangleAlign.Inherit; }
/// <summary> /// Pixel accurate measure of the specified string when drawn with the specified Font object. /// </summary> /// <param name="g">Graphics instance used to measure text.</param> /// <param name="rtl">Right to left setting for control.</param> /// <param name="text">String to measure.</param> /// <param name="font">Font object that defines the text format of the string.</param> /// <param name="trim">How to trim excess text.</param> /// <param name="align">How to align multi-line text.</param> /// <param name="prefix">How to process prefix characters.</param> /// <param name="hint">Rendering hint.</param> /// <param name="composition">Should draw on a composition element.</param> /// <param name="glowing">When on composition draw with glowing.</param> /// <param name="disposeFont">Dispose of font when finished with it.</param> /// <exception cref="ArgumentNullException"></exception> /// <returns>A memento used to draw the text.</returns> public static AccurateTextMemento MeasureString(Graphics g, RightToLeft rtl, string text, Font font, PaletteTextTrim trim, PaletteRelativeAlign align, PaletteTextHotkeyPrefix prefix, TextRenderingHint hint, bool composition, bool glowing, bool disposeFont) { Debug.Assert(g != null); Debug.Assert(text != null); Debug.Assert(font != null); if (g == null) { throw new ArgumentNullException(nameof(g)); } if (text == null) { throw new ArgumentNullException(nameof(text)); } if (font == null) { throw new ArgumentNullException(nameof(font)); } // An empty string cannot be drawn, so uses the empty memento if (text.Length == 0) { return(AccurateTextMemento.Empty); } // Create the format object used when measuring and drawing StringFormat format = new StringFormat { FormatFlags = StringFormatFlags.NoClip }; // Ensure that text reflects reversed RTL setting if (rtl == RightToLeft.Yes) { format.FormatFlags |= StringFormatFlags.DirectionRightToLeft; } // How do we position text horizontally? switch (align) { case PaletteRelativeAlign.Near: format.Alignment = (rtl == RightToLeft.Yes) ? StringAlignment.Far : StringAlignment.Near; break; case PaletteRelativeAlign.Center: format.Alignment = StringAlignment.Center; break; case PaletteRelativeAlign.Far: format.Alignment = (rtl == RightToLeft.Yes) ? StringAlignment.Near : StringAlignment.Far; break; default: // Should never happen! Debug.Assert(false); break; } // Do we need to trim text that is too big? switch (trim) { case PaletteTextTrim.Character: format.Trimming = StringTrimming.Character; break; case PaletteTextTrim.EllipsisCharacter: format.Trimming = StringTrimming.EllipsisCharacter; break; case PaletteTextTrim.EllipsisPath: format.Trimming = StringTrimming.EllipsisPath; break; case PaletteTextTrim.EllipsisWord: format.Trimming = StringTrimming.EllipsisWord; break; case PaletteTextTrim.Word: format.Trimming = StringTrimming.Word; break; case PaletteTextTrim.Hide: format.Trimming = StringTrimming.None; break; default: // Should never happen! Debug.Assert(false); break; } // Setup the correct prefix processing switch (prefix) { case PaletteTextHotkeyPrefix.None: format.HotkeyPrefix = HotkeyPrefix.None; break; case PaletteTextHotkeyPrefix.Hide: format.HotkeyPrefix = HotkeyPrefix.Hide; break; case PaletteTextHotkeyPrefix.Show: format.HotkeyPrefix = HotkeyPrefix.Show; break; default: // Should never happen! Debug.Assert(false); break; } // Replace tab characters with a fixed four spaces text = text.Replace("\t", " "); // Perform actual measure of the text using (GraphicsTextHint graphicsHint = new GraphicsTextHint(g, hint)) { SizeF textSize = Size.Empty; try { textSize = g.MeasureString(text, font, int.MaxValue, format); if (composition && glowing) //Seb { textSize.Width += GLOW_EXTRA_WIDTH; } } catch { // ignored } // Return a memento with drawing details return(new AccurateTextMemento(text, font, textSize, format, hint, disposeFont)); } }
/// <summary> /// Pixel accurate measure of the specified string when drawn with the specified Font object. /// </summary> /// <param name="g">Graphics instance used to measure text.</param> /// <param name="rtl">Right to left setting for control.</param> /// <param name="text">String to measure.</param> /// <param name="font">Font object that defines the text format of the string.</param> /// <param name="trim">How to trim excess text.</param> /// <param name="align">How to align multine text.</param> /// <param name="prefix">How to process prefix characters.</param> /// <param name="hint">Rendering hint.</param> /// <param name="composition">Should draw on a composition element.</param> /// <param name="disposeFont">Dispose of font when finished with it.</param> /// <returns>A memento used to draw the text.</returns> public static AccurateTextMemento MeasureString(Graphics g, RightToLeft rtl, string text, Font font, PaletteTextTrim trim, PaletteRelativeAlign align, PaletteTextHotkeyPrefix prefix, TextRenderingHint hint, bool composition, bool disposeFont) { Debug.Assert(g != null); Debug.Assert(text != null); Debug.Assert(font != null); if (g == null) throw new ArgumentNullException("g"); if (text == null) throw new ArgumentNullException("text"); if (font == null) throw new ArgumentNullException("font"); // An empty string cannot be drawn, so uses the empty memento if (text.Length == 0) return AccurateTextMemento.Empty; // Create the format object used when measuring and drawing StringFormat format = new StringFormat(); format.FormatFlags = StringFormatFlags.NoClip; // Ensure that text reflects reversed RTL setting if (rtl == RightToLeft.Yes) format.FormatFlags = StringFormatFlags.DirectionRightToLeft; // How do we position text horizontally? switch (align) { case PaletteRelativeAlign.Near: format.Alignment = (rtl == RightToLeft.Yes) ? StringAlignment.Far : StringAlignment.Near; break; case PaletteRelativeAlign.Center: format.Alignment = StringAlignment.Center; break; case PaletteRelativeAlign.Far: format.Alignment = (rtl == RightToLeft.Yes) ? StringAlignment.Near : StringAlignment.Far; break; default: // Should never happen! Debug.Assert(false); break; } // Do we need to trim text that is too big? switch (trim) { case PaletteTextTrim.Character: format.Trimming = StringTrimming.Character; break; case PaletteTextTrim.EllipsisCharacter: format.Trimming = StringTrimming.EllipsisCharacter; break; case PaletteTextTrim.EllipsisPath: format.Trimming = StringTrimming.EllipsisPath; break; case PaletteTextTrim.EllipsisWord: format.Trimming = StringTrimming.EllipsisWord; break; case PaletteTextTrim.Word: format.Trimming = StringTrimming.Word; break; case PaletteTextTrim.Hide: format.Trimming = StringTrimming.None; break; default: // Should never happen! Debug.Assert(false); break; } // Setup the correct prefix processing switch (prefix) { case PaletteTextHotkeyPrefix.None: format.HotkeyPrefix = HotkeyPrefix.None; break; case PaletteTextHotkeyPrefix.Hide: format.HotkeyPrefix = HotkeyPrefix.Hide; break; case PaletteTextHotkeyPrefix.Show: format.HotkeyPrefix = HotkeyPrefix.Show; break; default: // Should never happen! Debug.Assert(false); break; } // Replace tab characters with a fixed four spaces text = text.Replace("\t", " "); // Perform actual measure of the text using (GraphicsTextHint graphicsHint = new GraphicsTextHint(g, hint)) { SizeF textSize = Size.Empty; try { textSize = g.MeasureString(text, font, int.MaxValue, format); if (composition) textSize.Width += GLOW_EXTRA_WIDTH; } catch {} // Return a memento with drawing details return new AccurateTextMemento(text, font, textSize, format, hint, disposeFont); } }