From f038c63718f7066a6e1b43506aa256243c8a488d Mon Sep 17 00:00:00 2001 From: Maddo Date: Fri, 17 Mar 2017 16:23:29 +0100 Subject: [PATCH] Font picker --- CatalogLib/ImgSharpCreator.cs | 27 +++-- CatalogLib/PicSettings.cs | 94 ++++++++++++++--- WPFCatalog/FontFamilyStringConverter.cs | 30 ++++++ WPFCatalog/MainWindow.xaml | 19 ++-- WPFCatalog/MainWindow.xaml.cs | 34 ++++++- WPFCatalog/MainWindowViewModel.cs | 100 +++++++++++++++---- WPFCatalog/Messages/FontData.cs | 17 ++++ WPFCatalog/Messages/OpenFontWindowMessage.cs | 18 ++++ WPFCatalog/WPFCatalog.csproj | 3 + 9 files changed, 290 insertions(+), 52 deletions(-) create mode 100644 WPFCatalog/FontFamilyStringConverter.cs create mode 100644 WPFCatalog/Messages/FontData.cs create mode 100644 WPFCatalog/Messages/OpenFontWindowMessage.cs diff --git a/CatalogLib/ImgSharpCreator.cs b/CatalogLib/ImgSharpCreator.cs index ae8784e..96a59c8 100644 --- a/CatalogLib/ImgSharpCreator.cs +++ b/CatalogLib/ImgSharpCreator.cs @@ -25,26 +25,26 @@ namespace CatalogLib var o = exif.GetValue(ExifTag.Orientation); if (o != null) { - int v = (int) o.Value; + int v = (int)o.Value; switch (v) { -//1 = Horizontal(normal) -//2 = Mirror horizontal -//3 = Rotate 180 -//4 = Mirror vertical -//5 = Mirror horizontal and rotate 270 CW -//6 = Rotate 90 CW -//7 = Mirror horizontal and rotate 90 CW -//8 = Rotate 270 CW + //1 = Horizontal(normal) + //2 = Mirror horizontal + //3 = Rotate 180 + //4 = Mirror vertical + //5 = Mirror horizontal and rotate 270 CW + //6 = Rotate 90 CW + //7 = Mirror horizontal and rotate 90 CW + //8 = Rotate 270 CW case 1: break; case 2: break; case 3: //image.Rotate(180f); - + //image.Rotate(90); image.Rotate(180f); break; @@ -69,10 +69,15 @@ namespace CatalogLib } //JpegDecoder j = new JpegDecoder(); - image.Save(Path.Combine(PicSettings.Instance.DirectoryDestinazione,workFile.Name)); + image.Save(Path.Combine(PicSettings.Instance.DirectoryDestinazione, workFile.Name)); //image.Resize(200, 200).Save(""); } } + + private void SetExtraText(ref Image image) + { + //if () + } } } diff --git a/CatalogLib/PicSettings.cs b/CatalogLib/PicSettings.cs index fd08514..af92f44 100644 --- a/CatalogLib/PicSettings.cs +++ b/CatalogLib/PicSettings.cs @@ -35,11 +35,11 @@ namespace CatalogLib public void DeserializeSettings(string serializedData) { _settingsDict = JsonConvert.DeserializeObject>(serializedData); - - + + } - public void Set(string key, object value) + public void SetBase(string key, object value) { if (_settingsDict.ContainsKey(key)) { @@ -53,20 +53,28 @@ namespace CatalogLib public void SetString(string key, string value) { - Set(key, value); + SetBase(key, value); } public void SetInt(string key, int value) { - Set(key, value); + SetBase(key, value); } public void SetBool(string key, bool value) { - Set(key, value); + SetBase(key, value); } + public void SetDouble(string key, double value) + { + SetBase(key, value); + } + public void Set(string key, T value) + { + SetBase(key, value); + } public bool Exists(string key) { @@ -83,7 +91,7 @@ namespace CatalogLib if (_settingsDict[key] is int) return (int)_settingsDict[key]; Debug.WriteLine($"Error while parsing {key}"); //return defaultValue; - + int r; if (int.TryParse(_settingsDict[key].ToString(), out r)) @@ -95,12 +103,48 @@ namespace CatalogLib { SetInt(key, defaultValue); } - return (int) _settingsDict[key]; + return (int)_settingsDict[key]; //return (int) _settingsDict[key]; //return _settingsDict.ContainsKey(key) ? (int)_settingsDict[key] : defaultValue; } + public double GetDouble(string key, double defaultValue = 0) + { + if (!_settingsDict.ContainsKey(key)) + { + SetDouble(key, defaultValue); + // setdouble default + } + + if (_settingsDict[key] is double) return (double)_settingsDict[key]; + Debug.WriteLine($"Error while parsing {key}"); + + double d; + if (double.TryParse(_settingsDict[key].ToString(), out d)) + { + SetDouble(key, d); + // setdouble key r + } + else + { + SetDouble(key, defaultValue); + //setdouble defaultvalue + } + return (double)_settingsDict[key]; + } + + public T Get(string key, T defaultValue) + { + if (!_settingsDict.ContainsKey(key)) + { + Set(key, defaultValue); + // setdouble default + } + + return (T)_settingsDict[key]; + } + public string GetString(string key, string defaultValue = "") { @@ -108,7 +152,7 @@ namespace CatalogLib { SetString(key, defaultValue); } - return (string) _settingsDict[key]; + return (string)_settingsDict[key]; //return _settingsDict.ContainsKey(key) ? (string)_settingsDict[key] : defaultValue; } @@ -120,7 +164,7 @@ namespace CatalogLib SetBool(key, defaultValue); return defaultValue; } - return (bool) _settingsDict[key]; + return (bool)_settingsDict[key]; @@ -334,11 +378,7 @@ namespace CatalogLib set { SetString("FotoSuffisso", value); } } - public bool EnableText - { - get { return GetBool("EnableText", false); } - set { SetBool("EnableText", value); } - } + public bool EnableThumbnails { get { return GetBool("EnableThumbnails", false); } @@ -349,5 +389,29 @@ namespace CatalogLib get { return GetBool("EnableLogo", false); } set { SetBool("EnableLogo", value); } } + + #region Text + + public bool EnableText + { + get { return GetBool("EnableText", false); } + set { SetBool("EnableText", value); } + } + + public string NomeFont + { + get { return GetString("nomeFont", "Verdana"); } + set { SetString("nomeFont", value); } + } + + public double DimensioneFont + { + get { return Get("dimensioneFont", 1); } + set { SetDouble("dimensioneFont", value); } + } + + #endregion + + } } \ No newline at end of file diff --git a/WPFCatalog/FontFamilyStringConverter.cs b/WPFCatalog/FontFamilyStringConverter.cs new file mode 100644 index 0000000..66a103e --- /dev/null +++ b/WPFCatalog/FontFamilyStringConverter.cs @@ -0,0 +1,30 @@ +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Data; +using System.Windows.Media; + +namespace WPFCatalog +{ + public class FontFamilyStringConverter : IValueConverter + { + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + FontFamily fontfamily = new FontFamily("Verdana"); + if (value != null) + { + fontfamily = new FontFamily(value.ToString()); + } + return fontfamily; + + } + + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + { + throw new NotImplementedException(); + } + } +} diff --git a/WPFCatalog/MainWindow.xaml b/WPFCatalog/MainWindow.xaml index 2bad153..9fdb8ae 100644 --- a/WPFCatalog/MainWindow.xaml +++ b/WPFCatalog/MainWindow.xaml @@ -19,7 +19,7 @@ - + @@ -179,7 +179,7 @@ - + @@ -216,13 +216,20 @@