Exemplo n.º 1
0
        /// <summary>
        /// Find the face closest to the specified style, weight and stretch.
        /// Returns null if there is no matching face.
        /// </summary>
        private FamilyTypeface FindNearestFamilyTypeface(
            FontStyle style,
            FontWeight weight,
            FontStretch stretch
            )
        {
            if (_fontInfo.FamilyTypefaces == null || _fontInfo.FamilyTypefaces.Count == 0)
            {
                return(null);
            }

            FamilyTypeface bestFace  = (FamilyTypeface)_fontInfo.FamilyTypefaces[0];
            MatchingStyle  bestMatch = new MatchingStyle(bestFace.Style, bestFace.Weight, bestFace.Stretch);
            MatchingStyle  target    = new MatchingStyle(style, weight, stretch);

            for (int i = 1; i < _fontInfo.FamilyTypefaces.Count; i++)
            {
                FamilyTypeface currentFace  = (FamilyTypeface)_fontInfo.FamilyTypefaces[i];
                MatchingStyle  currentMatch = new MatchingStyle(currentFace.Style, currentFace.Weight, currentFace.Stretch);
                if (MatchingStyle.IsBetterMatch(target, bestMatch, ref currentMatch))
                {
                    bestFace  = currentFace;
                    bestMatch = currentMatch;
                }
            }

            return(bestFace);
        }
Exemplo n.º 2
0
        private void CbQueryBoxFontFaces_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (!settingsLoaded)
            {
                return;
            }
            FamilyTypeface typeface = (FamilyTypeface)cbQueryBoxFontFaces.SelectedItem;

            if (typeface == null)
            {
                if (cbQueryBoxFontFaces.Items.Count > 0)
                {
                    cbQueryBoxFontFaces.SelectedIndex = 0;
                }

                return;
            }
            else
            {
                UserSettingStorage.Instance.QueryBoxFontStretch = typeface.Stretch.ToString();
                UserSettingStorage.Instance.QueryBoxFontWeight  = typeface.Weight.ToString();
                UserSettingStorage.Instance.QueryBoxFontStyle   = typeface.Style.ToString();
                UserSettingStorage.Instance.Save();
                ThemeManager.Theme.ChangeTheme(UserSettingStorage.Instance.Theme);
            }
        }
Exemplo n.º 3
0
        private Typeface Convert(FontInfo fontInfo)
        {
            FamilyTypeface familyTypeface = fontInfo.Typeface;
            FontFamily     family         = new FontFamily(fontInfo.Family.ToString());

            return(new Typeface(family, familyTypeface.Style, familyTypeface.Weight, familyTypeface.Stretch));
        }
Exemplo n.º 4
0
        private void btnOK_Click(object sender, RoutedEventArgs e)
        {
            ResultFontFamily = new FontFamily(listFont[lboxFont.SelectedIndex]);
            ResultFontSize   = double.Parse(textFontSize.Text);
            ResultTypeFace   = listFontTypeface[lboxFontStyle.SelectedIndex];

            DialogResult = true;
        }
Exemplo n.º 5
0
        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());
        }
Exemplo n.º 6
0
 /// <summary>
 /// フォントスタイル
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void fontStyleListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
 {
     if (fontStyleListBox.SelectedItem != null)
     {
         // フォントファミリー変更時のスタイルリセットでnullになるため
         FamilyTypeface ft = (FamilyTypeface)fontStyleListBox.SelectedItem;
         settings.FontStyle = ft.Style;
         settings.Save();
     }
 }
 private void typefaceSelector_SelectionChanged(object sender, SelectionChangedEventArgs e)
 {
     try
     {
         FamilyTypeface f = typefaceSelector.SelectedItem as FamilyTypeface;
         sample.FontStretch = f.Stretch;
         sample.FontStyle   = f.Style;
         sample.FontWeight  = f.Weight;
     }
     catch
     {
     }
 }
Exemplo n.º 8
0
        /// <summary>
        /// Look up device font for the typeface.
        /// </summary>
        IDeviceFont IFontFamily.GetDeviceFont(FontStyle style, FontWeight weight, FontStretch stretch)
        {
            FamilyTypeface bestFace = FindExactFamilyTypeface(style, weight, stretch);

            if (bestFace != null && bestFace.DeviceFontName != null)
            {
                return(bestFace);
            }
            else
            {
                return(null);
            }
        }
Exemplo n.º 9
0
 /// <summary>
 /// フォントファミリー
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void fontFamilyListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
 {
     if (fontFamilyListBox.SelectedItem != null)
     {
         // フォントファミリーが変更されたらスタイルを1番目に設定
         settings.FontFamily          = (FontFamily)fontFamilyListBox.SelectedItem;
         fontStyleListBox.ItemsSource = settings.FontFamily.FamilyTypefaces;
         FamilyTypeface ft = (FamilyTypeface)fontStyleListBox.Items[1];
         fontStyleListBox.SelectedItem = ft.Style;
         settings.FontStyle            = ft.Style;
         settings.Save();
     }
 }
Exemplo n.º 10
0
        private void SyncFontTypeface()
        {
            string fontTypeFaceSb = FontInfo.TypefaceToString(this.selectedFont.Typeface);
            int    idx            = 0;

            foreach (var item in this.ColorFontChooser.lstTypefaces.Items)
            {
                FamilyTypeface face = item as FamilyTypeface;
                if (fontTypeFaceSb == FontInfo.TypefaceToString(face))
                {
                    break;
                }
                idx++;
            }
            this.ColorFontChooser.lstTypefaces.SelectedIndex = idx;
        }
Exemplo n.º 11
0
        private void ApplyFontTypeFace()
        {
            string fontTypeFaceName = FontInfo.TypefaceToString(this.selectedFont.TypeFace);
            int    idx = 0;

            foreach (var item in this.FontControl.fontTypeList.Items)
            {
                FamilyTypeface face = item as FamilyTypeface;
                if (fontTypeFaceName == FontInfo.TypefaceToString(face))
                {
                    break;
                }
                idx++;
            }
            this.FontControl.fontTypeList.SelectedIndex = idx;
        }
Exemplo n.º 12
0
        private ITypefaceMetrics FindTypefaceMetrics(
            FontStyle style,
            FontWeight weight,
            FontStretch stretch
            )
        {
            FamilyTypeface bestFace = FindNearestFamilyTypeface(style, weight, stretch);

            if (bestFace == null)
            {
                return(new CompositeTypefaceMetrics());
            }
            else
            {
                return(bestFace);
            }
        }
Exemplo n.º 13
0
        /// <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();
        }
Exemplo n.º 14
0
        public FontDialog()
        {
            InitializeComponent();

            Control control = this;

            ResultFontFamily       = control.FontFamily;
            ResultFontSize         = control.FontSize;
            ResultTypeFace         = new FamilyTypeface();
            ResultTypeFace.Stretch = control.FontStretch;
            ResultTypeFace.Style   = control.FontStyle;
            ResultTypeFace.Weight  = control.FontWeight;

            var cond = System.Windows.Markup.XmlLanguage.GetLanguage(System.Globalization.CultureInfo.CurrentUICulture.Name);

            foreach (FontFamily item in Fonts.SystemFontFamilies)
            {
                if (item.FamilyNames.ContainsKey(cond))
                {
                    listFont.Add(item.FamilyNames[cond]);
                }
                else
                {
                    listFont.Add(item.ToString());
                }
            }
            listFont.Sort();
            lboxFont.ItemsSource = listFont;

            lboxFont.SelectedItem = control.FontFamily.ToString();
            lboxFont.ScrollIntoView(lboxFont.SelectedItem);
            textFont.Text = control.FontFamily.ToString();

            double[] listSize = { 8, 9, 10, 10.5, 11, 12, 14, 16, 18, 20, 24, 28, 32, 36, 40, 44, 48, 54, 60, 66, 72, 80, 88, 96 };
            lboxFontSize.ItemsSource = listSize;

            lboxFontSize.SelectedItem = FontSize;
            textFontSize.Text         = control.FontSize.ToString();
        }
Exemplo n.º 15
0
        private void OnResultFontFacesSelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (!settingsLoaded)
            {
                return;
            }
            FamilyTypeface typeface = (FamilyTypeface)ResultFontFacesComboBox.SelectedItem;

            if (typeface == null)
            {
                if (ResultFontFacesComboBox.Items.Count > 0)
                {
                    ResultFontFacesComboBox.SelectedIndex = 0;
                }
            }
            else
            {
                _settings.ResultFontStretch = typeface.Stretch.ToString();
                _settings.ResultFontWeight  = typeface.Weight.ToString();
                _settings.ResultFontStyle   = typeface.Style.ToString();
                ThemeManager.Instance.ChangeTheme(_settings.Theme);
            }
        }
Exemplo n.º 16
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();
            }
        }
Exemplo n.º 17
0
        /// <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);
        }