Font picker

This commit is contained in:
Maddo 2017-03-17 16:23:29 +01:00
commit f038c63718
9 changed files with 289 additions and 51 deletions

View file

@ -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 ()
}
}
}

View file

@ -35,11 +35,11 @@ namespace CatalogLib
public void DeserializeSettings(string serializedData)
{
_settingsDict = JsonConvert.DeserializeObject<Dictionary<string, object>>(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<T>(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<T>(string key, T defaultValue)
{
if (!_settingsDict.ContainsKey(key))
{
Set<T>(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<double>("dimensioneFont", 1); }
set { SetDouble("dimensioneFont", value); }
}
#endregion
}
}

View file

@ -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();
}
}
}

View file

@ -19,7 +19,7 @@
<Setter Property="Margin" Value="2,2,5,5" />
</Style>
<Style TargetType="ComboBox" BasedOn="{StaticResource CommonStyle}"></Style>
<wpfCatalog:FontFamilyStringConverter x:Key="FontFamilyConverter"></wpfCatalog:FontFamilyStringConverter>
</Window.Resources>
<DockPanel LastChildFill="True">
<Menu DockPanel.Dock="Top" Height="auto">
@ -179,7 +179,7 @@
<Slider Grid.Column="0" Orientation="Horizontal" Maximum="100" Minimum="0" Value="{Binding CompressioneJpeg}"></Slider>
<TextBlock Grid.Column="1" Text="{Binding CompressioneJpeg}"></TextBlock>
</Grid>
<CheckBox Grid.Row="3" Grid.Column="1" HorizontalAlignment="Right" VerticalAlignment="Center" Margin="0,16,0,17.88" IsChecked="{Binding FotoMantieniDimensioni}"/>
<TextBlock Grid.Row="3" Grid.Column="2" Text="Mantieni Dimensioni Originali" TextWrapping="WrapWithOverflow" Width="80" Margin="4,0,4,25.88" Grid.RowSpan="2" />
@ -216,13 +216,20 @@
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<Label Grid.Row="0" Grid.Column="0" Content="Font"/>
<ComboBox Grid.Row="0" Grid.Column="1" Grid.ColumnSpan="2" Width="100" HorizontalAlignment="Right" SelectedItem="{Binding CarattereFont}" />
<!--todo-->
<!--<ComboBox Grid.Row="0" Grid.Column="1" Grid.ColumnSpan="2" Width="100" HorizontalAlignment="Right" SelectedItem="{Binding CarattereFont}" x:Name="cmbFont" />-->
<TextBox Grid.Row="0" Grid.Column="2"
Width="100"
IsReadOnly="True"
FontFamily="{Binding FontName, Converter={StaticResource FontFamilyConverter}, Mode=OneWay}"
Text="{Binding FontName}"
></TextBox>
<!---->
<CheckBox Grid.Row="0" Grid.Column="3" Content="Grassetto" VerticalAlignment="Center" IsChecked="{Binding CarattereGrassetto}" />
<!--<CheckBox Grid.Row="0" Grid.Column="3" Content="Grassetto" VerticalAlignment="Center" IsChecked="{Binding CarattereGrassetto}" />-->
<Button Grid.Row="0" Grid.Column="3" Content="Scegli" Command="{Binding PickFontCommand}"></Button>
<Label Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2" Content="Dimensione"/>
<TextBox Grid.Row="1" Grid.Column="2" Text="{Binding CarattereDimensione}"/>
<TextBox Grid.Row="1" Grid.Column="2" Text="{Binding FontSize}"/>
<Label Grid.Row="2" Grid.Column="0" Grid.ColumnSpan="2" Content="Dimensione Miniatura"/>
<TextBox Grid.Row="2" Grid.Column="2" Text="{Binding CarattereDimensioneMiniatura}"/>

View file

@ -7,12 +7,16 @@ using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Forms;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using CatalogLib;
using GalaSoft.MvvmLight.Messaging;
using MaddoLibrary.Helpers;
using WPFCatalog.Messages;
namespace WPFCatalog
{
@ -29,12 +33,38 @@ namespace WPFCatalog
DataContext = new MainWindowViewModel();
SetDefaults();
//((MainWindowViewModel) DataContext).
Messenger.Default.Register<OpenFontWindowMessage>(this, OpenFonts);
}
private void SetDefaults()
{
}
private void OpenFonts(OpenFontWindowMessage message)
{
FontDialog fd = new FontDialog();
System.Windows.Forms.DialogResult dr = fd.ShowDialog();
if (dr != System.Windows.Forms.DialogResult.Cancel)
{
//DialogHelper.PopUpMessage(fd.Font.Name);
//cmbFont.Text = fd.Font.Name;
//tbSomeText.FontFamily = new System.Windows.Media.FontFamily(fd.Font.Name);
//tbSomeText.FontSize = fd.Font.Size * 96.0 / 72.0;
//tbSomeText.FontWeight = fd.Font.Bold ? FontWeights.Bold : FontWeights.Regular;
//tbSomeText.FontStyle = fd.Font.Italic ? FontStyles.Italic : FontStyles.Normal;
message.Callback(new FontData()
{
Name = fd.Font.Name,
Size = Math.Round(fd.Font.Size) /* 96.0 / 72.0*/,
Bold = fd.Font.Bold,
Italic = fd.Font.Italic
});
}
}
}
}

View file

@ -8,6 +8,7 @@ using System.Threading.Tasks;
using CatalogLib;
using GalaSoft.MvvmLight.Command;
using MaddoLibrary.Helpers;
using WPFCatalog.Messages;
namespace WPFCatalog
{
@ -39,7 +40,8 @@ namespace WPFCatalog
public RelayCommand OpenDestinationFolderCommand { get; private set; }
public RelayCommand StartCommand { get; private set; }
public RelayCommand PickFontCommand { get; private set; }
private void RegisterCommands()
{
@ -53,16 +55,36 @@ namespace WPFCatalog
OpenDestinationFolderCommand = new RelayCommand(OpenDestinationFolder);
StartCommand = new RelayCommand(Start);
PickFontCommand = new RelayCommand(PickFont);
}
private void PickFont()
{
//FontData d = null;
MessengerInstance.Send<OpenFontWindowMessage>(new OpenFontWindowMessage((ayy) =>
{
this.FontName = ayy.Name;
this.FontSize = ayy.Size;
//d = ayy;
}));
//if (d != null)
//{
// FontName = d.Name;
//}
//string s = d.Name;
}
private void Start()
{
//var files = Directory.GetFiles(PicSettings.DirectorySorgente);
// todo folder mode
foreach (var file in Directory.EnumerateFiles(PicSettings.DirectorySorgente))
{
IImageProcessor i = new ImgSharpCreator();
//ImageCreator2 i = new ImageCreator2();
i.Start(new FileInfo(file));
}
@ -649,6 +671,21 @@ namespace WPFCatalog
}
}
#endregion
#region Testo
public bool EnableText
{
get { return PicSettings.EnableText; }
set { PicSettings.EnableText = value; RaisePropertyChanged("EnableText"); }
}
public string ColoreTestoRGB
{
get { return PicSettings.GetString("coloreTestoRGB"); }
@ -659,23 +696,39 @@ namespace WPFCatalog
}
}
public string FontName
{
get { return PicSettings.NomeFont; }
set
{
PicSettings.NomeFont = value;
RaisePropertyChanged("FontName");
}
}
public double FontSize
{
get
{
{
return PicSettings.DimensioneFont;
}
}
set
{
PicSettings.DimensioneFont = value;
RaisePropertyChanged("FontSize");
}
}
//todo: bold
//todo: italic
#endregion
#region Testo
#region Logo
public bool EnableText
{
get { return PicSettings.EnableText; }
set { PicSettings.EnableText = value; RaisePropertyChanged("EnableText");}
}
public bool EnableThumbnails
{
get { return PicSettings.EnableThumbnails; }
set { PicSettings.EnableThumbnails = value; RaisePropertyChanged("EnableThumbnails"); }
}
public bool EnableLogo
{
@ -686,6 +739,17 @@ namespace WPFCatalog
#endregion
#region Thumbnail
public bool EnableThumbnails
{
get { return PicSettings.EnableThumbnails; }
set { PicSettings.EnableThumbnails = value; RaisePropertyChanged("EnableThumbnails"); }
}
#endregion

View file

@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace WPFCatalog.Messages
{
public class FontData
{
public string Name { get; set; }
public double Size { get; set; }
public bool Bold { get; set; }
public bool Italic { get; set; }
}
}

View file

@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace WPFCatalog.Messages
{
public class OpenFontWindowMessage
{
public Action<FontData> Callback { get; set; }
public OpenFontWindowMessage(Action<FontData> calllback)
{
Callback = calllback;
}
}
}

View file

@ -99,6 +99,9 @@
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</ApplicationDefinition>
<Compile Include="FontFamilyStringConverter.cs" />
<Compile Include="Messages\FontData.cs" />
<Compile Include="Messages\OpenFontWindowMessage.cs" />
<Compile Include="ViewModelBase.cs" />
<Compile Include="ViewModel\MainViewModel.cs" />
<Compile Include="ViewModel\ViewModelLocator.cs" />