internal bool CompareFallbackFontFamily(FontFamily fallbackFontFamily) { if (fallbackFontFamily == null || _fallbackFontFamily == null) { return(fallbackFontFamily == _fallbackFontFamily); } return(_fallbackFontFamily.Equals(fallbackFontFamily)); }
/// <summary> /// Equality check /// </summary> public override bool Equals(object o) { Typeface t = o as Typeface; if (t == null) { return(false); } return(_style == t._style && _weight == t._weight && _stretch == t._stretch && _fontFamily.Equals(t._fontFamily) && CompareFallbackFontFamily(t._fallbackFontFamily)); }
/// <summary> /// Sets or changes the font family for the text object /// </summary> /// <param name="fontFamily">Font family</param> /// <param name="startIndex">The start index of initial character to apply the change to.</param> /// <param name="count">The number of characters the change should be applied to.</param> public void SetFontFamily(FontFamily fontFamily, int startIndex, int count) { if (fontFamily == null) throw new ArgumentNullException("fontFamily"); int limit = ValidateRange(startIndex, count); for (int i = startIndex; i < limit;) { SpanRider formatRider = new SpanRider(_formatRuns, _latestPosition, i); i = Math.Min(limit, i + formatRider.Length); #pragma warning disable 6506 // Presharp warns that runProps is not validated, but it can never be null // because the rider is already checked to be in range GenericTextRunProperties runProps = formatRider.CurrentElement as GenericTextRunProperties; Invariant.Assert(runProps != null); Typeface oldTypeface = runProps.Typeface; if (fontFamily.Equals(oldTypeface.FontFamily)) continue; GenericTextRunProperties newProps = new GenericTextRunProperties( new Typeface(fontFamily, oldTypeface.Style, oldTypeface.Weight, oldTypeface.Stretch), runProps.FontRenderingEmSize, runProps.FontHintingEmSize, runProps.TextDecorations, runProps.ForegroundBrush, runProps.BackgroundBrush, runProps.BaselineAlignment, runProps.CultureInfo, runProps.NumberSubstitution ); #pragma warning restore 6506 _latestPosition = _formatRuns.SetValue(formatRider.CurrentPosition, i - formatRider.CurrentPosition, newProps, formatRider.SpanPosition); InvalidateMetrics(); } }
void UpdateSelection() { InternalUpdateSelection(); // update font state Boolean HasFont = false; FontFamily Family = new FontFamily("Arial"); FontStyle Style = FontStyles.Normal; FontWeight Weight = FontWeights.Normal; Double Size = 14; Color Foreground = Colors.Black; Color Background = Colors.Transparent; TextAlign Alignment = TextAlign.Block; TextAttributes Attributes = TextAttributes.None; FontStretch Stretch = FontStretches.Normal; // determine letter before selection... for (int i = SelectionStart - 1; i >= 0; i--) { Letter Item = LineItems[i] as Letter; if (Item == null) continue; Family = Item.Label.FontFamily; Style = Item.Label.FontStyle; Weight = Item.Label.FontWeight; Size = Item.FontSize; Foreground = Item.Foreground; Background = Item.Background; Attributes = Item.TextAttributes; Alignment = Item.Alignment; Stretch = Item.Label.FontStretch; break; } m_FontFamily = Family; m_FontStyle = Style; m_FontWeight = Weight; m_FontSize = Size; m_FontStretch = Stretch; m_FontForeground = Foreground; m_FontBackground = Background; m_TextAlignment = Alignment; m_TextAttributes = Attributes; for (int i = SelectionStart; i < SelectionStart + SelectionLength; i++) { Letter Item = LineItems[i] as Letter; if (Item == null) continue; if (!HasFont) { Family = Item.Label.FontFamily; Style = Item.Label.FontStyle; Weight = Item.Label.FontWeight; Size = Item.FontSize; Foreground = Item.Foreground; Background = Item.Background; Attributes = Item.TextAttributes; Alignment = Item.Alignment; Stretch = Item.Label.FontStretch; HasFont = true; } else { if (!Family.Equals(Item.Label.FontFamily) || !Style.Equals(Item.Label.FontStyle) || !Weight.Equals(Item.Label.FontWeight) || (Size != Item.FontSize) || !Foreground.Equals(Item.Foreground) || !Background.Equals(Item.Background) || (Alignment != Item.Alignment) || (Attributes != Item.TextAttributes) || (Stretch != Item.Label.FontStretch) ) { // only homogenous formatting may be saved... return; } } } m_FontFamily = Family; m_FontStyle = Style; m_FontWeight = Weight; m_FontSize = Size; m_FontForeground = Foreground; m_FontBackground = Background; m_TextAlignment = Alignment; m_TextAttributes = Attributes; m_FontStretch = Stretch; }