示例#1
0
        private async Task GenerateFont_Impl()
        {
            FontFamily fontFamily = DefaultFontFamily;

            if (SelectedFont != null)
            {
                fontFamily = SelectedFont;
            }

            //FontGenerator.ReverseColors = (bool)reverseColorsCheckBox.IsChecked;

            // Validate font sizes
            int fontSize   = RS2014FontGenerator.GetValidFontSize(SelectedFontSize);
            int jpFontSize = RS2014FontGenerator.GetValidFontSize(SelectedKanjiFontSize);

            FontGenerator.GlyphHorizontalMargin = GlyphHorizontalMargin;
            FontGenerator.UseAccurateInnerRects = UseAccurateInnerRects;
            FontGenerator.SpacingAdjustment     = SpacingAdjustment;

            FontGenerator.SetFont(fontFamily, SelectedFontWeight.Weight, fontSize, jpFontSize);

            // Generating the font will block the thread
            // But invoke it anyway so that the UI has time to update (change mouse cursor etc)
            GenerationResult result = await Application.Current.Dispatcher.InvokeAsync(
                () => FontGenerator.TryGenerateFont(),
                DispatcherPriority.Background);

            CanSave = false;

            switch (result)
            {
            case GenerationResult.Success:
                CanSave       = true;
                TextureHeight = FontGenerator.TextureHeight;
                TextureWidth  = FontGenerator.TextureWidth;
                break;

            case GenerationResult.DidNotFitIntoMaxSize:
                MessageBox.Show($"{Properties.Resources.Error_Generation_TooManyGlyphs} (1024x1024)");
                break;

            case GenerationResult.UserCanceled:
                break;

            default:
                Debug.Print("Unexpected generation result!");
                break;
            }
        }
示例#2
0
        public MainWindowViewModel(Canvas fontCanvas, Canvas rectCanvas, FontFamily defaultFontFamily)
        {
            CultureResources.EnumerateAvailableCultures();
            Languages = CultureResources.AvailableCultures.Select(culture => new Language(culture)).ToList();

            var currentLanguage = Languages.Find(l => l.Culture.TwoLetterISOLanguageName == Thread.CurrentThread.CurrentUICulture.TwoLetterISOLanguageName);

            if (currentLanguage == null)
            {
                currentLanguage = Languages.Find(l => l.Culture == CultureResources.AvailableCultures[0]);
            }

            SelectedLanguage = currentLanguage;
            FontWeightList   = LocalizedFontWeights.All;

            this.ObservableForProperty(x => x.SelectedLanguage)
            .Subscribe(lang => CultureResources.ChangeCulture(lang.Value.Culture));

            FontGenerator     = new RS2014FontGenerator(fontCanvas, rectCanvas);
            FontCanvas        = fontCanvas;
            DefaultFontFamily = defaultFontFamily;

            FontList = Fonts.SystemFontFamilies.OrderBy(x => x.Source).ToList();

            LoadProgramState();

            WindowTitle = ProgramName;

            var thisAsm = Assembly.GetExecutingAssembly();

            ProgramVersion = thisAsm.GetName().Version.ToString();

            CreateReactiveCommands();

            this.WhenAnyValue(x => x.UseDarkTheme)
            .Subscribe(dt =>
            {
                string theme = dt ? "Dark" : "Light";

                ThemeManager.Current.ChangeTheme(Application.Current, theme + ".Steel");
            });

            // Generate font after a delay when font size, glyph margin or spacing is changed
            this.WhenAnyValue(
                x => x.SelectedFontSize,
                x => x.SelectedKanjiFontSize,
                x => x.GlyphHorizontalMargin,
                x => x.SpacingAdjustment)
            .Where(_ => CanGenerate)       // Don't do anything if generation is currently disabled
            .Throttle(TimeSpan.FromMilliseconds(650), RxApp.MainThreadScheduler)
            .DistinctUntilChanged()
            .Select(_ => Unit.Default)
            .InvokeCommand(GenerateFont);

            // Generate font immediately when font family or weight or "accurate inner rects" is changed
            this.WhenAnyValue(
                x => x.UseAccurateInnerRects,
                x => x.SelectedFont,
                x => x.SelectedFontWeight)
            .DistinctUntilChanged()
            .Select(_ => Unit.Default)
            .InvokeCommand(GenerateFont);
        }