public MainViewModel( IUserInterfaceService userInterfaceService, IOptionsService optionsService, IDialogService dialogService) { _userInterfaceService = userInterfaceService; _optionsService = optionsService; _dialogService = dialogService; _imageService = new BibleTextImage(); InitCommands(); SystemFonts = GetSystemFonts(); _currentTheme = new OnlyVTheme(); _isSampleBackgroundImageUsed = true; BibleEpubFiles = GetBibleEpubFiles(); Messenger.Default.Register <DragOverMessage>(this, OnDragOver); Messenger.Default.Register <DragDropMessage>(this, OnDragDrop); UpdateTextSamples(); SaveSignature(); }
private void CreateThemeFile( string descriptiveName, string imagePath, string backgroundColor, string mainTextColor, string secondaryTextColor, string fontFamily = "Georgia", int bottomMargin = 100) { var file = new ThemeFile(); var currentFolder = Environment.CurrentDirectory; var themePath = Path.Combine(currentFolder, $"{descriptiveName}.onlyv"); var theme = new OnlyVTheme(); theme.Background.Colour = backgroundColor; theme.BodyText.Font.Family = fontFamily; theme.BodyText.Font.Colour = mainTextColor; theme.BodyText.DropShadow.Opacity = 0.3; theme.BodyText.DropShadow.Depth = 7; theme.BodyText.DropShadow.BlurRadius = 15; theme.TitleText.Font.Family = fontFamily; theme.TitleText.Font.Colour = secondaryTextColor; theme.TitleText.DropShadow.Opacity = 0.3; theme.TitleText.DropShadow.Depth = 7; theme.TitleText.DropShadow.BlurRadius = 15; theme.VerseNumbers.Colour = secondaryTextColor; theme.Dimensions.BottomMargin = bottomMargin; file.Create(themePath, theme, imagePath, overwrite: true); var result = file.Read(themePath); Assert.IsNotNull(result); var s1 = JsonConvert.SerializeObject(result.Theme); var s2 = JsonConvert.SerializeObject(theme); Assert.AreEqual(s1, s2); }
private void ApplyFormatting(BibleTextImage bibleTextImage, string themePath) { var cacheEntry = ThemeFile.Read(themePath); OnlyVTheme theme; ImageSource backgroundImage; if (cacheEntry == null) { // must use default... theme = new OnlyVTheme(); backgroundImage = BitmapHelper.ConvertBitmap(Properties.Resources.Blue); } else { theme = cacheEntry.Theme; backgroundImage = cacheEntry.BackgroundImage; } ApplyFormatting(bibleTextImage, theme, backgroundImage); }
public void Create( string themePath, OnlyVTheme theme, BitmapImage backgroundImage, bool overwrite) { string backgroundImagePath = null; if (backgroundImage != null) { backgroundImagePath = Path.GetRandomFileName(); backgroundImagePath = Path.ChangeExtension(backgroundImagePath, ".png"); backgroundImagePath = Path.Combine(Path.GetTempPath(), backgroundImagePath); BitmapWriter.WritePng(backgroundImagePath, backgroundImage); } Create(themePath, theme, backgroundImagePath, overwrite); if (backgroundImagePath != null) { File.Delete(backgroundImagePath); } }
private void ApplyFormatting( BibleTextImage bibleTextImage, OnlyVTheme theme, ImageSource backgroundImage) { // dimensions... bibleTextImage.Width = theme.Dimensions.ImageWidth; bibleTextImage.Height = theme.Dimensions.ImageHeight; bibleTextImage.LeftMargin = theme.Dimensions.LeftMargin; bibleTextImage.TopMargin = theme.Dimensions.TopMargin; bibleTextImage.RightMargin = theme.Dimensions.RightMargin; bibleTextImage.BottomMargin = theme.Dimensions.BottomMargin; // background... bibleTextImage.BackgroundColor = ConvertFromString(theme.Background.Colour, Colors.Blue); bibleTextImage.BackgroundImageSource = _optionsService.UseBackgroundImage ? backgroundImage : null; bibleTextImage.BackgroundImageOpacity = theme.Background.ImageOpacity; // formatting... bibleTextImage.AllowAutoFit = _optionsService.AutoFit; bibleTextImage.ShowBreakInVerses = _optionsService.ShowVerseBreaks; bibleTextImage.UseContinuationEllipses = _optionsService.UseContinuationEllipses; bibleTextImage.UseTildeParaSeparator = _optionsService.UseTildeMarker; bibleTextImage.TrimPunctuation = _optionsService.TrimPunctuation; bibleTextImage.TrimQuotes = _optionsService.TrimQuotes; // body text... bibleTextImage.MainFont.FontFamily = new FontFamily(theme.BodyText.Font.Family); bibleTextImage.MainFont.FontSize = AdaptToScaling(theme.BodyText.Font.Size); bibleTextImage.MainFont.FontColor = ConvertFromString(theme.BodyText.Font.Colour, Colors.White); bibleTextImage.MainFont.FontStyle = theme.BodyText.Font.Style.AsWindowsFontStyle(); bibleTextImage.MainFont.FontWeight = theme.BodyText.Font.Weight.AsWindowsFontWeight(); bibleTextImage.MainFont.Opacity = theme.BodyText.Font.Opacity; bibleTextImage.HorzAlignment = theme.BodyText.HorizontalAlignment.AsWindowsTextAlignment(); bibleTextImage.LineSpacing = theme.BodyText.LineSpacing; bibleTextImage.BodyDropShadow = theme.BodyText.DropShadow.Show; bibleTextImage.BodyDropShadowBlurRadius = theme.BodyText.DropShadow.BlurRadius; bibleTextImage.BodyDropShadowColor = ConvertFromString(theme.BodyText.DropShadow.Colour, Colors.Black); bibleTextImage.BodyDropShadowDepth = theme.BodyText.DropShadow.Depth; bibleTextImage.BodyDropShadowOpacity = theme.BodyText.DropShadow.Opacity; bibleTextImage.BodyVerticalAlignment = theme.BodyText.BodyVerticalAlignment; // title text... bibleTextImage.TitleFont.FontFamily = new FontFamily(theme.TitleText.Font.Family); bibleTextImage.TitleFont.FontSize = AdaptToScaling(theme.TitleText.Font.Size); bibleTextImage.TitleFont.FontColor = ConvertFromString(theme.TitleText.Font.Colour, Colors.White); bibleTextImage.TitleFont.FontStyle = theme.TitleText.Font.Style.AsWindowsFontStyle(); bibleTextImage.TitleFont.FontWeight = theme.TitleText.Font.Weight.AsWindowsFontWeight(); bibleTextImage.TitleFont.Opacity = theme.TitleText.Font.Opacity; bibleTextImage.TitleHorzAlignment = theme.TitleText.HorizontalAlignment.AsWindowsTextAlignment(); bibleTextImage.TitlePosition = theme.TitleText.Position; bibleTextImage.TitleDropShadow = theme.TitleText.DropShadow.Show; bibleTextImage.TitleDropShadowBlurRadius = theme.TitleText.DropShadow.BlurRadius; bibleTextImage.TitleDropShadowColor = ConvertFromString(theme.TitleText.DropShadow.Colour, Colors.Black); bibleTextImage.TitleDropShadowDepth = theme.TitleText.DropShadow.Depth; bibleTextImage.TitleDropShadowOpacity = theme.TitleText.DropShadow.Opacity; bibleTextImage.TitleSpaceBetweenVerseNumbers = _optionsService.SpaceBetweenTitleVerseNumbers; bibleTextImage.UseAbbreviatedBookNames = _optionsService.UseAbbreviatedBookNames; // verse nos... // font family same as body font var verseNosFontFamily = theme.BodyText.Font.Family; bibleTextImage.ShowVerseNumbers = _optionsService.ShowVerseNos; bibleTextImage.VerseFont.FontFamily = new FontFamily(verseNosFontFamily); bibleTextImage.VerseFont.FontColor = ConvertFromString(theme.VerseNumbers.Colour, Colors.White); bibleTextImage.VerseFont.FontStyle = theme.VerseNumbers.Style.AsWindowsFontStyle(); bibleTextImage.VerseFont.FontWeight = theme.VerseNumbers.Weight.AsWindowsFontWeight(); bibleTextImage.VerseFont.Opacity = theme.VerseNumbers.Opacity; }
public void Create(string themePath, OnlyVTheme theme, string backgroundImagePath, bool overwrite) { if (string.IsNullOrEmpty(themePath) || !Path.GetExtension(themePath).Equals(ThemeFileExtension, StringComparison.OrdinalIgnoreCase)) { throw new ArgumentException(nameof(themePath)); } if (theme == null) { throw new ArgumentException(nameof(theme)); } if (File.Exists(themePath) && !overwrite) { throw new Exception("File already exists!"); } var validBackgroundImage = false; if (!string.IsNullOrEmpty(backgroundImagePath)) { var ext = Path.GetExtension(backgroundImagePath); if (string.IsNullOrEmpty(ext) || !ext.Equals(".png", StringComparison.OrdinalIgnoreCase) || !File.Exists(backgroundImagePath)) { throw new ArgumentException(nameof(backgroundImagePath)); } validBackgroundImage = true; } using (var memoryStream = new MemoryStream()) { using (var zip = new ZipArchive(memoryStream, ZipArchiveMode.Create, true)) { var themeEntry = zip.CreateEntry(ThemeEntryName); var serializer = new JsonSerializer { Formatting = Formatting.Indented }; using (var entryStream = themeEntry.Open()) using (var entryStreamWriter = new StreamWriter(entryStream)) using (var jsonTextWriter = new JsonTextWriter(entryStreamWriter)) { serializer.Serialize(jsonTextWriter, theme); } if (validBackgroundImage) { zip.CreateEntryFromFile(backgroundImagePath, ImageEntryName); } } if (overwrite) { File.Delete(themePath); } using (var fileStream = new FileStream(themePath, FileMode.Create)) { memoryStream.Seek(0, SeekOrigin.Begin); memoryStream.CopyTo(fileStream); } } }