public void Serialize(XmlElement node) { Exceptions.CheckArgumentNull(node, "node").RemoveAll(); if (IsDefault) { node.SetBoolean("IsDefault", IsDefault); return; } node.SetString("Family", FontFamily.Source); node.SetInt32("Weight", FontWeight.ToOpenTypeWeight()); node.SetInt32("Style", (FontStyleConverter)FontStyle); node.SetInt32("Stretch", FontStretch.ToOpenTypeStretch()); node.SetDouble("Size", FontSize); if (!TextDecorations.IsNullOrEmpty()) { XmlElement textDecorationsNode = node.CreateChildElement("TextDecorations"); foreach (TextDecoration decoration in TextDecorations) { textDecorationsNode.CreateChildElement("Decoration").SetInt32("Location", (int)decoration.Location); } } }
internal MatchingStyle( FontStyle style, FontWeight weight, FontStretch stretch ) { _vector = new Vector( (stretch.ToOpenTypeStretch() - FontStretches.Normal.ToOpenTypeStretch()) * FontStretchScale, style.GetStyleForInternalConstruction() * FontStyleScale, (weight.ToOpenTypeWeight() - FontWeights.Normal.ToOpenTypeWeight()) / 100.0 * FontWeightScale ); }
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); }
internal GlyphTypeface GetGlyphTypeface( FontStyle style, FontWeight weight, FontStretch stretch ) { Text.TextInterface.Font bestMatch = _family.GetFirstMatchingFont((Text.TextInterface.FontWeight)weight.ToOpenTypeWeight(), (Text.TextInterface.FontStretch)stretch.ToOpenTypeStretch(), (Text.TextInterface.FontStyle)style.GetStyleForInternalConstruction()); Debug.Assert(bestMatch != null); return(new GlyphTypeface(bestMatch)); }