int IComparable.CompareTo(object obj) { TypefaceListItem item = obj as TypefaceListItem; if (item == null) { return(-1); } // Sort all simulated faces after all non-simulated faces. if (_simulated != item._simulated) { return(_simulated ? 1 : -1); } // If weight differs then sort based on weight (lightest first). int difference = FontWeight.ToOpenTypeWeight() - item.FontWeight.ToOpenTypeWeight(); if (difference != 0) { return(difference > 0 ? 1 : -1); } // If style differs then sort based on style (Normal, Italic, then Oblique). FontStyle thisStyle = FontStyle; FontStyle otherStyle = item.FontStyle; if (thisStyle != otherStyle) { if (thisStyle == FontStyles.Normal) { // This item is normal style and should come first. return(-1); } else if (otherStyle == FontStyles.Normal) { // The other item is normal style and should come first. return(1); } else { // Neither is normal so sort italic before oblique. return((thisStyle == FontStyles.Italic) ? -1 : 1); } } // If stretch differs then sort based on stretch (Normal first, then numerically). FontStretch thisStretch = FontStretch; FontStretch otherStretch = item.FontStretch; if (thisStretch != otherStretch) { if (thisStretch == FontStretches.Normal) { // This item is normal stretch and should come first. return(-1); } else if (otherStretch == FontStretches.Normal) { // The other item is normal stretch and should come first. return(1); } else { // Neither is normal so sort numerically. return(thisStretch.ToOpenTypeStretch() < otherStretch.ToOpenTypeStretch() ? -1 : 0); } } // They're the same. return(0); }
void InitializeTypefaceList() { FontFamily family = SelectedFontFamily; if (family != null) { ICollection<Typeface> faceCollection = family.GetTypefaces(); var items = new TypefaceListItem[faceCollection.Count]; int i = 0; foreach (Typeface face in faceCollection) { items[i++] = new TypefaceListItem(face); } Array.Sort<TypefaceListItem>(items); foreach (TypefaceListItem item in items) { typefaceList.Items.Add(item); } } }
protected override void OnPropertyChanged(DependencyPropertyChangedEventArgs e) { if (e.Property == SelectedFamilyProperty) { Typefaces.Clear(); foreach(Typeface typeface in SelectedFamily.GetTypefaces()) { TypefaceListItem item = new TypefaceListItem(typeface); Typefaces.Add(item); } SelectedTypeface = Typefaces[0].Typeface; } else if (e.Property == IsUnderlineProperty || e.Property == IsBaselineProperty || e.Property == IsOverlineProperty || e.Property == IsStrikethroughProperty) { UpdateSelectedDecorations(); } else if (e.Property == SelectedDecorationsProperty) { UpdateDecorationProperties(); } base.OnPropertyChanged(e); }