public FontFamilyDemoWindowViewModel()
        {
            var tempFontWeights      = new Dictionary <string, FontWeight>();
            var fontWeightProperties =
                typeof(System.Windows.FontWeights).GetProperties(BindingFlags.Public | BindingFlags.Static);

            foreach (var propertyInfo in fontWeightProperties)
            {
                tempFontWeights.Add(propertyInfo.Name, (FontWeight)propertyInfo.GetValue(null));
            }

            FontWeights        = tempFontWeights;
            SelectedFontWeight = FontWeights
                                 .FirstOrDefault(s => s.Key.Equals("Normal", StringComparison.OrdinalIgnoreCase));

            var tempFontStyles       = new Dictionary <string, FontStyle>();
            var fontStylesProperties =
                typeof(System.Windows.FontStyles).GetProperties(BindingFlags.Public | BindingFlags.Static);

            foreach (var propertyInfo in fontStylesProperties)
            {
                tempFontStyles.Add(propertyInfo.Name, (FontStyle)propertyInfo.GetValue(null));
            }

            FontStyles        = tempFontStyles;
            SelectedFontStyle = FontStyles
                                .FirstOrDefault(s => s.Key.Equals("Normal", StringComparison.OrdinalIgnoreCase));

            var tempFontStretches      = new Dictionary <string, FontStretch>();
            var FontStretchsProperties =
                typeof(System.Windows.FontStretches).GetProperties(BindingFlags.Public | BindingFlags.Static);

            foreach (var propertyInfo in FontStretchsProperties)
            {
                tempFontStretches.Add(propertyInfo.Name, (FontStretch)propertyInfo.GetValue(null));
            }

            FontStretches       = tempFontStretches;
            SelectedFontStretch = FontStretches
                                  .FirstOrDefault(s => s.Key.Equals("Normal", StringComparison.OrdinalIgnoreCase));

            var tempSystemFontFamilies = new List <FontFamily>();

            //增加自定义字体
            var aileron = new FontFamily(Path.Combine(AppDomain.CurrentDomain.BaseDirectory,
                                                      @"FontFamilyDemo\FontFiles\#Aileron"));

            var aliFont = new FontFamily(Path.Combine(AppDomain.CurrentDomain.BaseDirectory,
                                                      @"FontFamilyDemo\FontFiles\#阿里巴巴普惠体 R"));

            tempSystemFontFamilies.Add(aileron);
            tempSystemFontFamilies.Add(aliFont);

            foreach (var systemFontFamily in Fonts.SystemFontFamilies)
            {
                tempSystemFontFamilies.Add(systemFontFamily);
            }

            SystemFontFamilies = tempSystemFontFamilies;
        }
        public FontFamilyDemoWindowViewModel()
        {
            var tempFontWeights      = new Dictionary <string, FontWeight>();
            var fontWeightProperties = typeof(System.Windows.FontWeights).GetProperties(BindingFlags.Public | BindingFlags.Static);

            foreach (var propertyInfo in fontWeightProperties)
            {
                tempFontWeights.Add(propertyInfo.Name, (FontWeight)propertyInfo.GetValue(null));
            }

            FontWeights        = tempFontWeights;
            SelectedFontWeight = FontWeights
                                 .FirstOrDefault(s => s.Key.Equals("Normal", StringComparison.OrdinalIgnoreCase));

            var tempFontStyles       = new Dictionary <string, FontStyle>();
            var fontStylesProperties = typeof(System.Windows.FontStyles).GetProperties(BindingFlags.Public | BindingFlags.Static);

            foreach (var propertyInfo in fontStylesProperties)
            {
                tempFontStyles.Add(propertyInfo.Name, (FontStyle)propertyInfo.GetValue(null));
            }

            FontStyles        = tempFontStyles;
            SelectedFontStyle = FontStyles
                                .FirstOrDefault(s => s.Key.Equals("Normal", StringComparison.OrdinalIgnoreCase));

            var tempFontStretches      = new Dictionary <string, FontStretch>();
            var FontStretchsProperties = typeof(System.Windows.FontStretches).GetProperties(BindingFlags.Public | BindingFlags.Static);

            foreach (var propertyInfo in FontStretchsProperties)
            {
                tempFontStretches.Add(propertyInfo.Name, (FontStretch)propertyInfo.GetValue(null));
            }

            FontStretches       = tempFontStretches;
            SelectedFontStretch = FontStretches
                                  .FirstOrDefault(s => s.Key.Equals("Normal", StringComparison.OrdinalIgnoreCase));

            var tempSystemFontFamilies = new List <FontFamily>();

            foreach (var systemFontFamily in Fonts.SystemFontFamilies)
            {
                tempSystemFontFamilies.Add(systemFontFamily);
            }

            SystemFontFamilies = tempSystemFontFamilies;
        }
Beispiel #3
0
        public virtual FontNames GetFontNames()
        {
            FontNames fontNames = new FontNames();

            fontNames.SetAllNames(GetAllNameEntries());
            fontNames.SetFontName(GetPsFontName());
            fontNames.SetFullName(fontNames.GetNames(4));
            String[][] otfFamilyName = fontNames.GetNames(16);
            if (otfFamilyName != null)
            {
                fontNames.SetFamilyName(otfFamilyName);
            }
            else
            {
                fontNames.SetFamilyName(fontNames.GetNames(1));
            }
            String[][] subfamily = fontNames.GetNames(2);
            if (subfamily != null)
            {
                fontNames.SetStyle(subfamily[0][3]);
            }
            String[][] otfSubFamily = fontNames.GetNames(17);
            if (otfFamilyName != null)
            {
                fontNames.SetSubfamily(otfSubFamily);
            }
            else
            {
                fontNames.SetSubfamily(subfamily);
            }
            String[][] cidName = fontNames.GetNames(20);
            if (cidName != null)
            {
                fontNames.SetCidFontName(cidName[0][3]);
            }
            fontNames.SetFontWeight(os_2.usWeightClass);
            fontNames.SetFontStretch(FontStretches.FromOpenTypeWidthClass(os_2.usWidthClass));
            fontNames.SetMacStyle(head.macStyle);
            fontNames.SetAllowEmbedding(os_2.fsType != 2);
            return(fontNames);
        }
Beispiel #4
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();
            }
        }
Beispiel #5
0
        public void Draw(bool bRotateText)
        {
            this.CanvasRoot.get_Children().Clear();
            base.set_Height(this.HEIGHT_ACTUAL);
            base.set_Width(this.WIDTH_ACTUAL);
            this.CanvasRoot.SetValue(FrameworkElement.WidthProperty, this.WIDTH_ACTUAL);
            this.CanvasRoot.SetValue(FrameworkElement.HeightProperty, this.HEIGHT_ACTUAL);
            base.SetValue(FrameworkElement.WidthProperty, this.WIDTH_ACTUAL);
            base.SetValue(FrameworkElement.HeightProperty, this.HEIGHT_ACTUAL);
            Brush     brush     = CreateHatchBrush(this.BodyColorHi, this.BodyColorLo);
            Brush     brush2    = CreateHatchBrush(this.BodyColorLo, this.BodyColorHi);
            Rectangle rectangle = new Rectangle();

            rectangle.set_StrokeThickness(0.0);
            rectangle.set_Fill(brush);
            rectangle.SetValue(Canvas.LeftProperty, this.x0);
            rectangle.SetValue(Canvas.TopProperty, 0.0);
            rectangle.SetValue(FrameworkElement.HeightProperty, this.HEIGHT_ACTUAL / 2.0);
            rectangle.SetValue(FrameworkElement.WidthProperty, this.WIDTH_ACTUAL);
            Rectangle rectangle2 = new Rectangle();

            rectangle2.set_StrokeThickness(0.0);
            rectangle2.set_Fill(brush2);
            rectangle2.SetValue(Canvas.LeftProperty, this.x0);
            rectangle2.SetValue(Canvas.TopProperty, 0.0 + (this.HEIGHT_ACTUAL / 2.0));
            rectangle2.SetValue(FrameworkElement.HeightProperty, this.HEIGHT_ACTUAL / 2.0);
            rectangle2.SetValue(FrameworkElement.WidthProperty, this.WIDTH_ACTUAL);
            this.CanvasRoot.get_Children().Add(rectangle);
            this.CanvasRoot.get_Children().Add(rectangle2);
            if ((this.Direction == 1) || (this.Direction == -1))
            {
                Polygon polygon = new Polygon();
                polygon.set_Fill(brush);
                polygon.set_StrokeThickness(0.0);
                Polygon polygon2 = new Polygon();
                polygon2.set_Fill(brush2);
                polygon2.set_StrokeThickness(0.0);
                if (this.Direction == 1)
                {
                    polygon.get_Points().Add(new Point(this.x0 + this.WIDTH_ACTUAL, 0.0));
                    polygon.get_Points().Add(new Point(this.x0 + this.WIDTH_ACTUAL, 0.0 + (this.HEIGHT_ACTUAL / 2.0)));
                    polygon.get_Points().Add(new Point((this.x0 + this.WIDTH_ACTUAL) + this.NOSE_LEN, 0.0 + (this.HEIGHT_ACTUAL / 2.0)));
                    polygon2.get_Points().Add(new Point(this.x0 + this.WIDTH_ACTUAL, 0.0 + (this.HEIGHT_ACTUAL / 2.0)));
                    polygon2.get_Points().Add(new Point(this.x0 + this.WIDTH_ACTUAL, 0.0 + this.HEIGHT_ACTUAL));
                    polygon2.get_Points().Add(new Point((this.x0 + this.WIDTH_ACTUAL) + this.NOSE_LEN, 0.0 + (this.HEIGHT_ACTUAL / 2.0)));
                }
                else if (this.Direction == -1)
                {
                    polygon.get_Points().Add(new Point(this.x0, 0.0));
                    polygon.get_Points().Add(new Point(this.x0, 0.0 + (this.HEIGHT_ACTUAL / 2.0)));
                    polygon.get_Points().Add(new Point(0.0, 0.0 + (this.HEIGHT_ACTUAL / 2.0)));
                    polygon2.get_Points().Add(new Point(this.x0, 0.0 + this.HEIGHT_ACTUAL));
                    polygon2.get_Points().Add(new Point(0.0, 0.0 + (this.HEIGHT_ACTUAL / 2.0)));
                    polygon2.get_Points().Add(new Point(this.x0, 0.0 + (this.HEIGHT_ACTUAL / 2.0)));
                }
                this.CanvasRoot.get_Children().Add(polygon);
                this.CanvasRoot.get_Children().Add(polygon2);
            }
            if (this.IDToDisplay.Length > 0)
            {
                TextBlock block = new TextBlock();
                block.set_Text(this.IDToDisplay);
                double num = 16.5;
                block.set_FontFamily((this.IDToDisplay != "?") ? this.m_fntTrainBigImpact : this.m_fntTrainBigNormal);
                block.set_FontSize((this.IDToDisplay != "?") ? ((double)this.m_fntTrainBigImpactSize) : ((double)this.m_fntTrainBigNormalSize));
                block.set_FontWeight((this.IDToDisplay != "?") ? this.m_fntTrainBigImpactStyle : this.m_fntTrainBigNormalStyle);
                block.set_FontStretch(FontStretches.get_Normal());
                block.set_FontStyle(FontStyles.get_Normal());
                if (this.m_Small)
                {
                    block.set_FontFamily(this.m_fntTrainSmall);
                    block.set_FontSize((double)this.m_fntTrainSmallSize);
                    block.set_FontWeight(this.m_fntTrainSmallStyle);
                    num = 12.0;
                }
                block.SetValue(Canvas.LeftProperty, this.x0);
                block.SetValue(Canvas.TopProperty, (0.0 + (this.HEIGHT_ACTUAL / 2.0)) - (num / 2.0));
                block.SetValue(FrameworkElement.WidthProperty, this.WIDTH_ACTUAL);
                block.set_Foreground(new SolidColorBrush(Colors.get_Yellow()));
                block.set_TextAlignment(0);
                if (bRotateText)
                {
                    RotateTransform transform = new RotateTransform();
                    transform.set_Angle(180.0);
                    transform.set_CenterX(this.WIDTH_ACTUAL / 2.0);
                    transform.set_CenterY(block.get_ActualHeight() / 2.0);
                    block.set_RenderTransform(transform);
                }
                this.CanvasRoot.get_Children().Add(block);
            }
            foreach (FrameworkElement element in this.CanvasRoot.get_Children())
            {
                double num2 = Convert.ToDouble(element.GetValue(Canvas.LeftProperty));
                double num3 = Convert.ToDouble(element.GetValue(Canvas.TopProperty));
                num2  = (num2 - (this.WIDTH_ACTUAL / 2.0)) - this.NOSE_LEN;
                num3 -= this.HEIGHT_ACTUAL / 2.0;
                element.SetValue(Canvas.LeftProperty, num2);
                element.SetValue(Canvas.TopProperty, num3);
            }
        }