Ejemplo n.º 1
0
        public override FontStyle Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
        {
            var fontStyleString = reader.GetString() ?? "Normal";
            var converter       = new System.Windows.FontStyleConverter();

            return((FontStyle)converter.ConvertFromString(fontStyleString));
        }
Ejemplo n.º 2
0
        //--------------------------------------------------------------
        #region Creation & Cleanup
        //--------------------------------------------------------------

        /// <summary>
        /// Initializes a new instance of the <see cref="TextEditorOptionsPageViewModel"/> class. 
        /// (Do not use this constructor it is only for design-time support!)
        /// </summary>
        public TextEditorOptionsPageViewModel()
            : base("Text Editor")
        {
            Trace.Assert(WindowsHelper.IsInDesignMode, "This TextEditorOptionsPageViewModel constructor must not be used at runtime.");
            Options = new TextEditorOptions();
            _fontStyleConverter = new FontStyleConverter();
            _fontWeightConverter = new FontWeightConverter();
        }
Ejemplo n.º 3
0
        public static FontStyle ParseStyle(string styleString)
        {
            FontStyle style = FontStyles.Normal;
            FontStyleConverter converter = new FontStyleConverter();

            try {
                style = (FontStyle)converter.ConvertFromString(styleString);
            }
            catch {
            }

            return style;
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Convert FontStyle to string for serialization
        /// </summary>
        public static string FontStyleToString(FontStyle value)
        {
            string result;

            try
            {
                result = new FontStyleConverter().ConvertToString(value);
            }
            catch (NotSupportedException)
            {
                result = "";
            }

            return result;
        }
        public FontDefinition ToFontDefinition()
        {
            var styleConverter = new FontStyleConverter();
            var weightConverter = new FontWeightConverter();
            var stretchConverter = new FontStretchConverter();

            var style = (FontStyle?)styleConverter.ConvertFromString(FontStyle) ?? FontStyles.Normal;
            var weight = (FontWeight?)weightConverter.ConvertFromString(FontWeight) ?? FontWeights.Normal;
            var stretch = (FontStretch?)stretchConverter.ConvertFromString(FontStretch) ?? FontStretches.Normal;

            return new FontDefinition
            {
                FontFamily = new FontFamily(FontFamily),
                FontStyle = style,
                FontWeight = weight,
                FontStretch = stretch,
                FontSize = FontSize
            };
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Convert string to FontStyle for serialization
        /// </summary>
        public static FontStyle FontStyleFromString(string value)
        {
            var result = FontStyles.Normal;

            try
            {
                var convertFromString = new FontStyleConverter().ConvertFromString((value));
                if (convertFromString != null)
                {
                    result = (FontStyle)convertFromString;
                }
            }
            catch (NotSupportedException)
            {
            }
            catch (FormatException)
            {
            }

            return result;
        }
Ejemplo n.º 7
0
 // Initialize known object types
 internal static TypeConverter CreateKnownTypeConverter(Int16 converterId)
 { 
     TypeConverter o = null;
     switch (converterId) 
     { 
         case -42: o = new System.Windows.Media.Converters.BoolIListConverter(); break;
         case -46: o = new System.ComponentModel.BooleanConverter(); break; 
         case -53: o = new System.Windows.Media.BrushConverter(); break;
         case -61: o = new System.ComponentModel.ByteConverter(); break;
         case -70: o = new System.ComponentModel.CharConverter(); break;
         case -71: o = new System.Windows.Media.Converters.CharIListConverter(); break; 
         case -87: o = new System.Windows.Media.ColorConverter(); break;
         case -94: o = new System.Windows.Input.CommandConverter(); break; 
         case -96: o = new System.Windows.Markup.ComponentResourceKeyConverter(); break; 
         case -111: o = new System.Windows.CornerRadiusConverter(); break;
         case -114: o = new System.ComponentModel.CultureInfoConverter(); break; 
         case -115: o = new System.Windows.CultureInfoIetfLanguageTagConverter(); break;
         case -117: o = new System.Windows.Input.CursorConverter(); break;
         case -124: o = new System.ComponentModel.DateTimeConverter(); break;
         case -125: o = new System.Windows.Markup.DateTimeConverter2(); break; 
         case -130: o = new System.ComponentModel.DecimalConverter(); break;
         case -137: o = new System.Windows.Markup.DependencyPropertyConverter(); break; 
         case -138: o = new System.Windows.DialogResultConverter(); break; 
         case -174: o = new System.Windows.Media.DoubleCollectionConverter(); break;
         case -175: o = new System.ComponentModel.DoubleConverter(); break; 
         case -176: o = new System.Windows.Media.Converters.DoubleIListConverter(); break;
         case -188: o = new System.Windows.DurationConverter(); break;
         case -190: o = new System.Windows.DynamicResourceExtensionConverter(); break;
         case -201: o = new System.Windows.ExpressionConverter(); break; 
         case -204: o = new System.Windows.FigureLengthConverter(); break;
         case -215: o = new System.Windows.Media.FontFamilyConverter(); break; 
         case -216: o = new System.Windows.FontSizeConverter(); break; 
         case -218: o = new System.Windows.FontStretchConverter(); break;
         case -220: o = new System.Windows.FontStyleConverter(); break; 
         case -222: o = new System.Windows.FontWeightConverter(); break;
         case -240: o = new System.Windows.Media.GeometryConverter(); break;
         case -256: o = new System.Windows.GridLengthConverter(); break;
         case -267: o = new System.ComponentModel.GuidConverter(); break; 
         case -286: o = new System.Windows.Media.ImageSourceConverter(); break;
         case -299: o = new System.Windows.Input.InputScopeConverter(); break; 
         case -301: o = new System.Windows.Input.InputScopeNameConverter(); break; 
         case -306: o = new System.ComponentModel.Int16Converter(); break;
         case -314: o = new System.Windows.Media.Int32CollectionConverter(); break; 
         case -315: o = new System.ComponentModel.Int32Converter(); break;
         case -319: o = new System.Windows.Int32RectConverter(); break;
         case -324: o = new System.ComponentModel.Int64Converter(); break;
         case -338: o = new System.Windows.Input.KeyConverter(); break; 
         case -340: o = new System.Windows.Input.KeyGestureConverter(); break;
         case -342: o = new System.Windows.KeySplineConverter(); break; 
         case -344: o = new System.Windows.KeyTimeConverter(); break; 
         case -348: o = new System.Windows.LengthConverter(); break;
         case -387: o = new System.Windows.Media.Media3D.Matrix3DConverter(); break; 
         case -392: o = new System.Windows.Media.MatrixConverter(); break;
         case -410: o = new System.Windows.Input.ModifierKeysConverter(); break;
         case -411: o = new System.Windows.Input.MouseActionConverter(); break;
         case -415: o = new System.Windows.Input.MouseGestureConverter(); break; 
         case -423: o = new System.Windows.NullableBoolConverter(); break;
         case -445: o = new System.Windows.Media.PathFigureCollectionConverter(); break; 
         case -453: o = new System.Windows.Media.PixelFormatConverter(); break; 
         case -462: o = new System.Windows.Media.Media3D.Point3DCollectionConverter(); break;
         case -463: o = new System.Windows.Media.Media3D.Point3DConverter(); break; 
         case -467: o = new System.Windows.Media.Media3D.Point4DConverter(); break;
         case -473: o = new System.Windows.Media.PointCollectionConverter(); break;
         case -474: o = new System.Windows.PointConverter(); break;
         case -475: o = new System.Windows.Media.Converters.PointIListConverter(); break; 
         case -492: o = new System.Windows.PropertyPathConverter(); break;
         case -498: o = new System.Windows.Media.Media3D.QuaternionConverter(); break; 
         case -507: o = new System.Windows.Media.Media3D.Rect3DConverter(); break; 
         case -511: o = new System.Windows.RectConverter(); break;
         case -521: o = new System.Windows.Media.Animation.RepeatBehaviorConverter(); break; 
         case -538: o = new System.Windows.Markup.RoutedEventConverter(); break;
         case -545: o = new System.ComponentModel.SByteConverter(); break;
         case -563: o = new System.ComponentModel.SingleConverter(); break;
         case -568: o = new System.Windows.Media.Media3D.Size3DConverter(); break; 
         case -572: o = new System.Windows.SizeConverter(); break;
         case -615: o = new System.ComponentModel.StringConverter(); break; 
         case -619: o = new System.Windows.StrokeCollectionConverter(); break; 
         case -633: o = new System.Windows.TemplateBindingExpressionConverter(); break;
         case -635: o = new System.Windows.TemplateBindingExtensionConverter(); break; 
         case -637: o = new System.Windows.Markup.TemplateKeyConverter(); break;
         case -645: o = new System.Windows.TextDecorationCollectionConverter(); break;
         case -655: o = new System.Windows.ThicknessConverter(); break;
         case -664: o = new System.ComponentModel.TimeSpanConverter(); break; 
         case -681: o = new System.Windows.Media.TransformConverter(); break;
         case -692: o = new System.Windows.Markup.TypeTypeConverter(); break; 
         case -696: o = new System.ComponentModel.UInt16Converter(); break; 
         case -698: o = new System.ComponentModel.UInt32Converter(); break;
         case -700: o = new System.ComponentModel.UInt64Converter(); break; 
         case -701: o = new System.Windows.Media.Converters.UShortIListConverter(); break;
         case -705: o = new System.UriTypeConverter(); break;
         case -714: o = new System.Windows.Media.Media3D.Vector3DCollectionConverter(); break;
         case -715: o = new System.Windows.Media.Media3D.Vector3DConverter(); break; 
         case -722: o = new System.Windows.Media.VectorCollectionConverter(); break;
         case -723: o = new System.Windows.VectorConverter(); break; 
         case -757: o = new System.Windows.Markup.XmlLanguageConverter(); break; 
     }
     return o; 
 }
Ejemplo n.º 8
0
        /// <summary>
        /// Helper function that converts the values stored in the settings into the font values
        /// and then sets the tasklist font values.
        /// </summary>
		public void SetFont()
        {
            var family = new FontFamily(User.Default.TaskListFontFamily);

            double size = User.Default.TaskListFontSize;

            var styleConverter = new FontStyleConverter();

            FontStyle style = (FontStyle)styleConverter.ConvertFromString(User.Default.TaskListFontStyle);

            var stretchConverter = new FontStretchConverter();
            FontStretch stretch = (FontStretch)stretchConverter.ConvertFromString(User.Default.TaskListFontStretch);

            var weightConverter = new FontWeightConverter();
            FontWeight weight = (FontWeight)weightConverter.ConvertFromString(User.Default.TaskListFontWeight);

            Color color = (Color)ColorConverter.ConvertFromString(User.Default.TaskListFontBrushColor);

			lbTasks.FontFamily = family;
			lbTasks.FontSize = size;
			lbTasks.FontStyle = style;
			lbTasks.FontStretch = stretch;
			lbTasks.FontWeight = weight;
			lbTasks.Foreground = new SolidColorBrush(color);
        }
Ejemplo n.º 9
0
 public static FontStyle ParseFontStyle(string fontStyleName)
 {
     var converter = new FontStyleConverter();
     return (FontStyle) converter.ConvertFromString(fontStyleName);
 }
Ejemplo n.º 10
0
 public static bool CanParseFontStyle(string fontStyleName)
 {
     try
     {
         var converter = new FontStyleConverter();
         converter.ConvertFromString(fontStyleName);
         return true;
     }
     catch
     {
         return false;
     }
 }
Ejemplo n.º 11
0
        /// <summary>
        /// Read the WordsStyle XML tag with its attributes (if any) and return
        /// a resulting <seealso cref="WordsStyle"/> object.
        /// </summary>
        internal static WordsStyle ReadNode(XmlReader reader)
        {
            WordsStyle ret = null;
              FontWeightConverter FontWeightConverter = new FontWeightConverter();
              FontStyleConverter FontStyleConverter = new FontStyleConverter();

              string name = string.Empty;
              string fgColor = string.Empty;
              string bgColor = string.Empty;
              string fontWeight = string.Empty;
              string FontStyle = string.Empty;

              reader.ReadToNextSibling(ReadWordsStyle.XMLName);
              while (reader.MoveToNextAttribute())
              {
            switch (reader.Name)
            {
              case ReadWordsStyle.attr_name:
            name = reader.Value;
            break;

              case ReadWordsStyle.attr_fgColor:
            fgColor = (reader.Value == null ? string.Empty : reader.Value);
            break;

              case ReadWordsStyle.attr_bgColor:
            bgColor = (reader.Value == null ? string.Empty : reader.Value);
            break;

              case ReadWordsStyle.attr_fontWeight:
            fontWeight = (reader.Value == null ? string.Empty : reader.Value);
            break;

              case ReadWordsStyle.attr_FontStyle:
            FontStyle = (reader.Value == null ? string.Empty : reader.Value);
            break;

              case XMLNameSpace:
            break;

              default:
            if (reader.Name.Trim().Length > 0 && reader.Name != XMLComment)
              logger.Warn("Parsing the XML child:'" + reader.Name + "' of '" + ReadLexerType.XMLName + "' is not implemented.");
              break;
            }
              }

              ret = new WordsStyle(name);

              if (fgColor != string.Empty)
            ret.fgColor = ReadWordsStyle.SetColorFromString(ReadWordsStyle.attr_fgColor, fgColor);

              if (bgColor != string.Empty)
            ret.bgColor = ReadWordsStyle.SetColorFromString(ReadWordsStyle.attr_bgColor, bgColor);

              if (fontWeight != string.Empty)
            ret.fontWeight = ParseFontWeight(ReadWordsStyle.attr_fontWeight, fontWeight, FontWeightConverter);

              if (FontStyle != string.Empty)
            ret.fontStyle = ParseFontStyle(ReadWordsStyle.attr_FontStyle, FontStyle, FontStyleConverter);

              return ret;
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Convert a string representation into a null-able <seealso cref="FontStyle"/> object and return it.
        /// </summary>
        /// <param name="stringAttribName"></param>
        /// <param name="fontStyle"></param>
        /// <param name="converter"></param>
        /// <returns></returns>
        protected static FontStyle? ParseFontStyle(string stringAttribName, string fontStyle, FontStyleConverter converter)
        {
            if (string.IsNullOrEmpty(fontStyle))
            return null;

              try
              {
            return (FontStyle?)converter.ConvertFromInvariantString(fontStyle);
              }
              catch (Exception exp)
              {
            throw new Exception(string.Format(CultureInfo.InvariantCulture, "Invalid FontStyle attribute value '{0}'=\"{1}\"", stringAttribName, fontStyle), exp);
              }
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Initializes a new instance of the <see cref="TextEditorOptionsPageViewModel"/> class.
        /// </summary>
        /// <param name="textExtension">The <see cref="TextExtension"/>.</param>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="textExtension"/> is <see langword="null"/>.
        /// </exception>
        public TextEditorOptionsPageViewModel(TextExtension textExtension)
            : base("Text Editor")
        {
            if (textExtension == null)
                throw new ArgumentNullException(nameof(textExtension));

            _textExtension = textExtension;
            Options = new TextEditorOptions();
            SetDefaultsCommand = new DelegateCommand(SetDefaults);
            SelectFontCommand = new DelegateCommand(SelectFont);

            _fontStretchConverter = new FontStretchConverter();
            _fontStyleConverter = new FontStyleConverter();
            _fontWeightConverter = new FontWeightConverter();
        }
Ejemplo n.º 14
0
      /// <summary/>
      public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) {
         if (value == null) {
            throw new ArgumentNullException("value");
         }
         var fontString = value as string;
         if (fontString.IsEmpty()) {
            return base.ConvertFrom(context, culture, value);
         }

         if (fontString.StartsWith("@") && fontString.IndexOf(",") < 0 && ResourceProvider != null) {
            return ResourceProvider.GetResource<Font>(fontString);
         }

         var fontFamily = Font.DefaultFamily;
         var fontSize = Font.DefaultSize;
         var fontWeight = Font.DefaultWeight;
         var fontStyle = Font.DefaultStyle;
         var fontStretch = Font.DefaultStretch;

         var parts = fontString.Trim().Split(_reComma);
         var nparts = parts.Length;
         if (nparts == 0) return null;
         if (nparts > 5) {
            throw new InvalidCastException();
         }
         for (var i = 0; i < nparts; i++) {
            parts[i] = parts[i].RemoveAll(new Regex(@"\,"));
         }

         if (nparts >= 1 && parts[0].NotEmpty()) {
            fontFamily = _parseFontFamily(context, culture, parts[0]);
         }
         if (nparts >= 2 && parts[1].NotEmpty()) {
            fontSize = Double.Parse(parts[1]);
         }
         if (nparts >= 3 && parts[2].NotEmpty()) {
            var converter = new FontWeightConverter();
            fontWeight = _parseFontWeight(context, culture, parts[2]);
         }
         if (nparts >= 4 && parts[3].NotEmpty()) {
            var converter = new FontStyleConverter();
            fontStyle = _parseFontStyle(context, culture, parts[3]);
         }
         if (nparts >= 5 && parts[4].NotEmpty()) {
            fontStretch = _parseFontStretch(context, culture, parts[4]);
         }

         var face = new Typeface(fontFamily, fontStyle, fontWeight, fontStretch);
         var font = new Font(face, fontSize);
         font.Freeze();
         return font;
      }