Example #1
0
        /// <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();
            }
        }