private void UpdateChecks(FontXStyle style) { _guiBold.IsChecked = style.HasFlag(FontXStyle.Bold); _guiItalic.IsChecked = style.HasFlag(FontXStyle.Italic); _guiUnderline.IsChecked = style.HasFlag(FontXStyle.Underline); _guiStrikeout.IsChecked = style.HasFlag(FontXStyle.Strikeout); }
private void EhCheckChanged(object sender, RoutedEventArgs e) { if (!_eventDisabler.IsSuspended) { FontXStyle newStyle = FontXStyle.Regular; if (true == _guiBold.IsChecked) { newStyle |= FontXStyle.Bold; } if (true == _guiItalic.IsChecked) { newStyle |= FontXStyle.Italic; } if (true == _guiUnderline.IsChecked) { newStyle |= FontXStyle.Underline; } if (true == _guiStrikeout.IsChecked) { newStyle |= FontXStyle.Strikeout; } SetValue(SelectedFontStyleProperty, newStyle); } }
private void _guiFontStyle_SelectedFontStyleChanged(object sender, DependencyPropertyChangedEventArgs e) { var oldFontStyle = _fontStyle; _fontStyle = _guiFontStyle.SelectedFontStyle; if (oldFontStyle != _fontStyle) { OnFontChanged(); } }
/// <summary> /// Gets a font like the existing font, but with a new font style. /// </summary> /// <param name="newStyle">The new font style.</param> /// <returns>Font with the same font family andsize as the existing font, but with the provided style.</returns> public FontX WithStyle(FontXStyle newStyle) { if (Style == newStyle) { return(this); } else { return(new FontX(_fontFamilyName, _size, newStyle)); } }
private FontX(string fontFamilyName, double size, FontXStyle style) { if (string.IsNullOrEmpty(fontFamilyName)) { throw new ArgumentNullException("fontFamilyName"); } _fontFamilyName = fontFamilyName; _size = size; _style = style; _invariantDescriptionString = GetInvariantDescriptionString(fontFamilyName, size, style); var creationEv = FontConstructed; if (null != creationEv) { creationEv(_invariantDescriptionString); } }
/// <summary> /// Converts a <see cref="FontXStyle"/> instance to a <see cref="FontStylePresence"/> instance. /// The styles 'Underline' and 'Strikeout' will not be considered for the conversion. /// </summary> /// <param name="style">The style to convert..</param> /// <returns> /// The converted <see cref="FontStylePresence"/> instance. /// </returns> protected static FontStylePresence ConvertFontXStyleToFontStylePresence(FontXStyle style) { FontStylePresence result; if (style.HasFlag(FontXStyle.Bold) && style.HasFlag(FontXStyle.Italic)) { result = FontStylePresence.BoldAndItalicStyleAvailable; } else if (style.HasFlag(FontXStyle.Bold)) { result = FontStylePresence.BoldStyleAvailable; } else if (style.HasFlag(FontXStyle.Italic)) { result = FontStylePresence.ItalicStyleAvailable; } else { result = FontStylePresence.RegularStyleAvailable; } return(result); }
/// <summary> /// Gets a <see cref="FontX"/> instance of a generic sans serif font with the provided size and style. /// </summary> /// <param name="fontSize">Size of the font.</param> /// <param name="style">The style.</param> /// <returns>A <see cref="FontX"/> instance of a generic sans serif font with the provided size and style.</returns> public static FontX GetFontXGenericSansSerif(double fontSize, FontXStyle style) { return(GetFontX(GenericSansSerifFontFamilyName, fontSize, style)); }
/// <summary> /// Determines whether a font with the given font family name and font style is available. /// </summary> /// <param name="fontFamilyName">Name of the font family.</param> /// <param name="style">The font style to test for (underline and strikeout are always available, thus they are not tested).</param> /// <returns> /// <c>true</c> if a font with the provided family name and style is available; otherwise, <c>false</c>. /// </returns> protected virtual bool InternalIsFontFamilyAndStyleAvailable(string fontFamilyName, FontXStyle style) { FontStylePresence pres; return _gdiFontFamilies.TryGetValue(fontFamilyName, out pres) && pres.HasFlag(ConvertFontXStyleToFontStylePresence(style)); }
public void SetFontStyle(FontXStyle style) { FontId = FontId.WithStyle(style); }
/// <summary> /// Gets an invariant description string, providing the font family, the size and the style of a font. /// </summary> /// <param name="family">The font family name.</param> /// <param name="style">The font style.</param> /// <returns>An invariant description string that can be used to describe the font.</returns> public static string GetInvariantDescriptionStringWithoutSizeInformation(string family, FontXStyle style) { if (style == FontXStyle.Regular) { return(string.Format(System.Globalization.CultureInfo.InvariantCulture, "{0}", family)); } else { return(string.Format(System.Globalization.CultureInfo.InvariantCulture, "{0}, style={1}", family, style)); } }
/// <summary> /// Gets an invariant description string, providing the font family, the size and the style of a font. /// </summary> /// <param name="family">The font family name.</param> /// <param name="size">The font size.</param> /// <param name="style">The font style.</param> /// <returns>An invariant description string that can be used to describe the font.</returns> public static string GetInvariantDescriptionString(string family, double size, FontXStyle style) { if (style == FontXStyle.Regular) { return string.Format(System.Globalization.CultureInfo.InvariantCulture, "{0}, {1}world", family, size); } else { return string.Format(System.Globalization.CultureInfo.InvariantCulture, "{0}, {1}world, style={2}", family, size, style); } }
/// <summary> /// Gets a font like the existing font, but with a new font style. /// </summary> /// <param name="newStyle">The new font style.</param> /// <returns>Font with the same font family andsize as the existing font, but with the provided style.</returns> public FontX WithStyle(FontXStyle newStyle) { if (Style == newStyle) return this; else return new FontX(this._fontFamilyName, this._size, newStyle); }
public static FontX InternalCreateFromNameSizeStyle(string fontFamilyName, double size, FontXStyle style) { return new FontX(fontFamilyName, size, style); }
private FontX(string fontFamilyName, double size, FontXStyle style) { if (string.IsNullOrEmpty(fontFamilyName)) throw new ArgumentNullException("fontFamilyName"); _fontFamilyName = fontFamilyName; _size = size; _style = style; _invariantDescriptionString = GetInvariantDescriptionString(fontFamilyName, size, style); var creationEv = FontConstructed; if (null != creationEv) creationEv(this._invariantDescriptionString); }
public FontX3D WithStyle(FontXStyle style) { return new FontX3D(_font.WithStyle(style), _depth); }
/// <summary> /// Determines whether a font with the given font family name and font style is available. /// </summary> /// <param name="fontFamilyName">Name of the font family.</param> /// <param name="style">The font style to test for (underline and strikeout are always available, thus they are not tested).</param> /// <returns> /// <c>true</c> if a font with the provided family name and style is available; otherwise, <c>false</c>. /// </returns> protected virtual bool InternalIsFontFamilyAndStyleAvailable(string fontFamilyName, FontXStyle style) { return(_dictWin32FamilyNameToGdiFontFamilyAndPresence.TryGetValue(fontFamilyName, out var val) && FontFamilyArrayToFontStylePresence(val).HasFlag(ConvertFontXStyleToFontStylePresence(style))); }
/// <summary> /// Merges the providedstyle into the present style. Example: if the present style is Bold, and the style parameter is Italic, then the merged style is 'Bold Italic'. /// </summary> /// <param name="style">The style to merge with the present style.</param> public void MergeFontStyle(FontXStyle style) { var newStyle = FontId.Style | style; FontId = FontId.WithStyle(newStyle); }
/// <summary> /// Gets an invariant description string, providing the font family, the size and the style of a font. /// </summary> /// <param name="family">The font family name.</param> /// <param name="style">The font style.</param> /// <returns>An invariant description string that can be used to describe the font.</returns> public static string GetInvariantDescriptionStringWithoutSizeInformation(string family, FontXStyle style) { if (style == FontXStyle.Regular) { return string.Format(System.Globalization.CultureInfo.InvariantCulture, "{0}", family); } else { return string.Format(System.Globalization.CultureInfo.InvariantCulture, "{0}, style={1}", family, style); } }
public static FontX InternalCreateFromNameSizeStyle(string fontFamilyName, double size, FontXStyle style) { return(new FontX(fontFamilyName, size, style)); }
/// <summary> /// Extracts font family name, size and style from the invariant description string. /// </summary> /// <param name="fontID">Invariant description string.</param> /// <param name="familyName">On return, contains the font family name.</param> /// <param name="size">On return, contains the font size.</param> /// <param name="style">On return, contains the font style.</param> public static void GetFamilyNameSizeStyleFromInvariantDescriptionString(string fontID, out string familyName, out double size, out FontXStyle style) { if (null == fontID) throw new ArgumentNullException("fontID"); int idx1 = fontID.IndexOf(','); // first comma after the font name if (idx1 <= 0) throw new ArgumentException("String fontID is not well formed. The string is: " + fontID); familyName = fontID.Substring(0, idx1); int idx2 = fontID.IndexOf(worldPostfix, idx1); if (idx2 < 0) throw new ArgumentException("String fontID is not well formed. Unit 'world' is missing. The string is: " + fontID); if (!double.TryParse(fontID.Substring(idx1 + 1, idx2 - idx1 - 1), System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture, out size)) throw new ArgumentException("String fontID is not well formed. The string is: " + fontID); int idx3 = fontID.IndexOf(stylePrefix, idx2 + worldPostfix.Length); style = FontXStyle.Regular; if (idx3 > 0) { idx3 += stylePrefix.Length; if (fontID.IndexOf("Bold", idx3) > 0) style |= FontXStyle.Bold; if (fontID.IndexOf("Italic", idx3) > 0) style |= FontXStyle.Italic; if (fontID.IndexOf("Underline", idx3) > 0) style |= FontXStyle.Underline; if (fontID.IndexOf("Strikeout", idx3) > 0) style |= FontXStyle.Strikeout; } }
/// <summary> /// Gets an invariant description string, providing the font family, the size and the style of a font. /// </summary> /// <param name="family">The font family name.</param> /// <param name="size">The font size.</param> /// <param name="style">The font style.</param> /// <returns>An invariant description string that can be used to describe the font.</returns> public static string GetInvariantDescriptionString(string family, double size, FontXStyle style) { if (style == FontXStyle.Regular) { return(string.Format(System.Globalization.CultureInfo.InvariantCulture, "{0}, {1}world", family, size)); } else { return(string.Format(System.Globalization.CultureInfo.InvariantCulture, "{0}, {1}world, style={2}", family, size, style)); } }
public FontX3D WithStyle(FontXStyle style) { return(new FontX3D(_font.WithStyle(style), _depth)); }
/// <summary> /// Extracts font family name, size and style from the invariant description string. /// </summary> /// <param name="fontID">Invariant description string.</param> /// <param name="familyName">On return, contains the font family name.</param> /// <param name="size">On return, contains the font size.</param> /// <param name="style">On return, contains the font style.</param> public static void GetFamilyNameSizeStyleFromInvariantDescriptionString(string fontID, out string familyName, out double size, out FontXStyle style) { if (null == fontID) { throw new ArgumentNullException("fontID"); } int idx1 = fontID.IndexOf(','); // first comma after the font name if (idx1 <= 0) { throw new ArgumentException("String fontID is not well formed. The string is: " + fontID); } familyName = fontID.Substring(0, idx1); int idx2 = fontID.IndexOf(worldPostfix, idx1); if (idx2 < 0) { throw new ArgumentException("String fontID is not well formed. Unit 'world' is missing. The string is: " + fontID); } if (!double.TryParse(fontID.Substring(idx1 + 1, idx2 - idx1 - 1), System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture, out size)) { throw new ArgumentException("String fontID is not well formed. The string is: " + fontID); } int idx3 = fontID.IndexOf(stylePrefix, idx2 + worldPostfix.Length); style = FontXStyle.Regular; if (idx3 > 0) { idx3 += stylePrefix.Length; if (fontID.IndexOf("Bold", idx3) > 0) { style |= FontXStyle.Bold; } if (fontID.IndexOf("Italic", idx3) > 0) { style |= FontXStyle.Italic; } if (fontID.IndexOf("Underline", idx3) > 0) { style |= FontXStyle.Underline; } if (fontID.IndexOf("Strikeout", idx3) > 0) { style |= FontXStyle.Strikeout; } } }
public FontX3D GetFont(string fontFamilyName, double size, double depth, FontXStyle style) { return(new FontX3D(Altaxo.Graph.Gdi.GdiFontManager.GetFontX(fontFamilyName, size, style), depth)); }
/// <summary> /// Converts a <see cref="FontXStyle"/> instance to a <see cref="FontStylePresence"/> instance. /// The styles 'Underline' and 'Strikeout' will not be considered for the conversion. /// </summary> /// <param name="style">The style to convert..</param> /// <returns> /// The converted <see cref="FontStylePresence"/> instance. /// </returns> private static FontStylePresence ConvertFontXStyleToFontStylePresence(FontXStyle style) { FontStylePresence result; if (style.HasFlag(FontXStyle.Bold) && style.HasFlag(FontXStyle.Italic)) result = FontStylePresence.BoldAndItalicStyleAvailable; else if (style.HasFlag(FontXStyle.Bold)) result = FontStylePresence.BoldStyleAvailable; else if (style.HasFlag(FontXStyle.Italic)) result = FontStylePresence.ItalicStyleAvailable; else result = FontStylePresence.RegularStyleAvailable; return result; }
public FontX3D GetFont(string fontFamilyName, double size, double depth, FontXStyle style) { return new FontX3D(Altaxo.Graph.Gdi.GdiFontManager.GetFont(fontFamilyName, size, style), depth); }
/// <summary> /// Determines whether a font with the given font family name and font style is available. /// </summary> /// <param name="fontFamilyName">Name of the font family.</param> /// <param name="style">The font style to test for (underline and strikeout are always available, thus they are not tested).</param> /// <returns> /// <c>true</c> if a font with the provided family name and style is available; otherwise, <c>false</c>. /// </returns> public static bool IsFontFamilyAndStyleAvailable(string fontFamilyName, FontXStyle style) { return(_instance.InternalIsFontFamilyAndStyleAvailable(fontFamilyName, style)); }
/// <summary> /// Determines whether a font with the given font family name and font style is available. /// </summary> /// <param name="fontFamilyName">Name of the font family.</param> /// <param name="style">The font style to test for (underline and strikeout are always available, thus they are not tested).</param> /// <returns> /// <c>true</c> if a font with the provided family name and style is available; otherwise, <c>false</c>. /// </returns> public static bool IsFontFamilyAndStyleAvailable(string fontFamilyName, FontXStyle style) { return _instance.InternalIsFontFamilyAndStyleAvailable(fontFamilyName, style); }
/// <summary> /// Constructs a font from a font family name, the size and font style. /// </summary> /// <param name="fontFamilyName">Name of the font family.</param> /// <param name="fontSize">Size of the font.</param> /// <param name="fontStyle">The font style.</param> /// <returns>A <see cref="FontX"/> instance describing the font. It can then be used with the FontManager to get a Gdi+ font instance.</returns> public static FontX GetFontX(string fontFamilyName, double fontSize, FontXStyle fontStyle) { return(FontX.InternalCreateFromNameSizeStyle(fontFamilyName, fontSize, fontStyle)); }
/// <summary> /// Constructs a font from a font family name, the size and font style. /// </summary> /// <param name="fontFamilyName">Name of the font family.</param> /// <param name="fontSize">Size of the font.</param> /// <param name="fontStyle">The font style.</param> /// <returns>A <see cref="FontX"/> instance describing the font. It can then be used with the FontManager to get a Gdi+ font instance.</returns> public static FontX GetFont(string fontFamilyName, double fontSize, FontXStyle fontStyle) { return FontX.InternalCreateFromNameSizeStyle(fontFamilyName, fontSize, fontStyle); }
private void _guiFontStyle_SelectedFontStyleChanged(object sender, DependencyPropertyChangedEventArgs e) { var oldFontStyle = _fontStyle; _fontStyle = _guiFontStyle.SelectedFontStyle; if (oldFontStyle != _fontStyle) OnFontChanged(); }