public int Compare(object x, object y) { if (x is FontWeight lhs && y is FontWeight rhs) { return(FontWeight.Compare(lhs, rhs)); } return(0); }
public void TestCodeSnippet12() { //<SnippetFontSnippet11> // Return the typefaces for the selected font family name and font values. Typeface typeface1 = new Typeface(new FontFamily("Arial"), FontStyles.Normal, FontWeights.Normal, FontStretches.Normal); Typeface typeface2 = new Typeface(new FontFamily("Arial"), FontStyles.Normal, FontWeights.UltraBold, FontStretches.Normal); if (FontWeight.Compare(typeface1.Weight, typeface2.Weight) < 0) { // Code execution follows this path because // the FontWeight of typeface1 (Normal) is less than of typeface2 (UltraBold). } //</SnippetFontSnippet11> }
/// <summary> /// Compares the family, style, weight and stretch of two TypefacesItems. /// </summary> public int Compare(object face1Object, object face2Object) { TypefaceComboBoxItem face1 = face1Object as TypefaceComboBoxItem; TypefaceComboBoxItem face2 = face2Object as TypefaceComboBoxItem; if (face1.FamilyName != face2.FamilyName) { return(string.Compare(face1.FamilyName, face2.FamilyName, true, CultureInfo.InvariantCulture)); } else if ((face1._face.IsBoldSimulated || face1._face.IsObliqueSimulated) != (face2._face.IsBoldSimulated || face2._face.IsObliqueSimulated)) { // Put non-simulated faces first. return((face1._face.IsBoldSimulated || face1._face.IsObliqueSimulated) ? 1 : -1); } else if (face1.Stretch != face2.Stretch) { return(FontStretch.Compare(face1.Stretch, face2.Stretch)); } else if (face1.Weight != face2.Weight) { return(FontWeight.Compare(face1.Weight, face2.Weight)); } else { if (face1.Style == face2.Style) { return(0); } else { if (face1.Style == FontStyles.Normal) { return(-1); } else if (face1.Style == FontStyles.Oblique) { return(1); } else { return((face2.Style == FontStyles.Normal) ? 1 : -1); } } } }