public static string TypefaceToString(FamilyTypeface ttf) { StringBuilder sb = new StringBuilder(ttf.Stretch.ToString()); sb.Append("-"); sb.Append(ttf.Weight.ToString()); sb.Append("-"); sb.Append(ttf.Style.ToString()); return sb.ToString(); }
/// <summary> /// Compares two typefaces for equality; returns true if the specified typeface /// is not null and has the same properties as this typeface. /// </summary> public bool Equals(FamilyTypeface typeface) { if (typeface == null) { return(false); } return( Style == typeface.Style && Weight == typeface.Weight && Stretch == typeface.Stretch ); }
/// <summary> /// Parses a CharacterMetrics element, and advances the current position beyond the /// element. Adds a CharacterMetrics object to the given FamilyTypface. /// </summary> private void ParseCharacterMetricsElement(FamilyTypeface face) { string key = null; string metrics = null; if (_reader.MoveToFirstAttribute()) { do { if (_reader.NamespaceURI == XamlNamespace && _reader.LocalName == KeyAttribute) { key = GetAttributeValue(); } else if (IsCompositeFontAttribute() && _reader.LocalName == MetricsAttribute) { metrics = GetAttributeValue(); } else if (!IsIgnorableAttribute()) { FailUnknownAttribute(); } } while (_reader.MoveToNextAttribute()); _reader.MoveToElement(); } if (key == null) FailMissingAttribute(KeyAttribute); if (metrics == null) FailMissingAttribute(MetricsAttribute); face.DeviceFontCharacterMetrics.Add( CharacterMetricsDictionary.ConvertKey(key), new CharacterMetrics(metrics) ); // There should be no child elements. ParseEmptyElement(); }
/// <summary> /// Parses the attributes of the FamilyTypeface element and sets the corresponding /// properties on the specified FamilyTypeface object. On return, the reader remains /// positioned on the element. /// </summary> private void ParseFamilyTypefaceAttributes(FamilyTypeface face) { // Iterate over the attributes. if (_reader.MoveToFirstAttribute()) { do { // Process attributes in the composite font namespace; ignore any others. if (IsCompositeFontAttribute()) { string name = _reader.LocalName; if (name == StyleAttribute) { FontStyle fontStyle = new FontStyle(); if (!FontStyles.FontStyleStringToKnownStyle(GetAttributeValue(), CultureInfo.InvariantCulture, ref fontStyle)) FailAttributeValue(); face.Style = fontStyle; } else if (name == WeightAttribute) { FontWeight fontWeight = new FontWeight(); if (!FontWeights.FontWeightStringToKnownWeight(GetAttributeValue(), CultureInfo.InvariantCulture, ref fontWeight)) FailAttributeValue(); face.Weight = fontWeight; } else if (name == StretchAttribute) { FontStretch fontStretch = new FontStretch(); if (!FontStretches.FontStretchStringToKnownStretch(GetAttributeValue(), CultureInfo.InvariantCulture, ref fontStretch)) FailAttributeValue(); face.Stretch = fontStretch; } else if (name == UnderlinePositionAttribute) { face.UnderlinePosition = GetAttributeAsDouble(); } else if (name == UnderlineThicknessAttribute) { face.UnderlineThickness = GetAttributeAsDouble(); } else if (name == StrikethroughPositionAttribute) { face.StrikethroughPosition = GetAttributeAsDouble(); } else if (name == StrikethroughThicknessAttribute) { face.StrikethroughThickness = GetAttributeAsDouble(); } else if (name == CapsHeightAttribute) { face.CapsHeight = GetAttributeAsDouble(); } else if (name == XHeightAttribute) { face.XHeight = GetAttributeAsDouble(); } else if (name == DeviceFontNameAttribute) { face.DeviceFontName = GetAttributeValue(); } else { FailUnknownAttribute(); } } else if (!IsIgnorableAttribute()) { FailUnknownAttribute(); } } while (_reader.MoveToNextAttribute()); _reader.MoveToElement(); } }
/// <summary> /// Parses the FamilyTypeface element, including its attributes and children, /// and advances to the next sibling element. /// </summary> private void ParseFamilyTypefaceElement() { FamilyTypeface face = new FamilyTypeface(); ParseFamilyTypefaceAttributes(face); if (_reader.IsEmptyElement) { _reader.Read(); } else { _reader.Read(); while (MoveToContent() != XmlNodeType.EndElement) { if (_reader.NodeType == XmlNodeType.Element && _reader.NamespaceURI == CompositeFontNamespace) { if (_reader.LocalName == DeviceFontCharacterMetricsPropertyElement) { VerifyNoAttributes(); if (_reader.IsEmptyElement) { _reader.Read(); } else { _reader.Read(); // Process all child elements. while (MoveToContent() == XmlNodeType.Element) { if (_reader.LocalName == CharacterMetricsElement) { ParseCharacterMetricsElement(face); } else { // Only CharacterMetricsElement is valid in this context. FailUnknownElement(); } } // Process the end element for the collection. _reader.ReadEndElement(); } } else { FailUnknownElement(); } } else { _reader.Skip(); } } _reader.ReadEndElement(); } // Add the typeface. _compositeFontInfo.GetFamilyTypefaceList().Add(face); }
/// <summary> /// Compares two typefaces for equality; returns true if the specified typeface /// is not null and has the same properties as this typeface. /// </summary> public bool Equals(FamilyTypeface typeface) { if (typeface == null) return false; return ( Style == typeface.Style && Weight == typeface.Weight && Stretch == typeface.Stretch ); }
public FamilyTypefaceWindow(FamilyTypeface familyTypeface) { InitializeComponent(); this.DataContext = familyTypeface; }