示例#1
0
            async void RemoveFrom_Click(object sender, RoutedEventArgs e)
            {
                if (sender is FrameworkElement f && f.DataContext is InstalledFont fnt)
                {
                    UserFontCollection collection = (main.SelectedCollection == null && main.FontListFilter == BasicFontFilter.SymbolFonts)
                        ? _collections.SymbolCollection
                        : main.SelectedCollection;

                    await _collections.RemoveFromCollectionAsync(fnt, collection);

                    WeakReferenceMessenger.Default.Send(new AppNotificationMessage(true, new CollectionUpdatedArgs(fnt, collection, false)));
                    WeakReferenceMessenger.Default.Send(new CollectionsUpdatedMessage());
                }
            }
示例#2
0
        /// <summary>
        /// 导入字体
        /// </summary>
        /// <param name="multipleSelect"></param>
        /// <returns></returns>
        public static bool ImportFont(bool multipleSelect = false)
        {
            OpenFileDialog f = new OpenFileDialog();

            f.Multiselect = multipleSelect;
            f.Filter      = "(.ttf)字体文件|*.ttf|(.ttc)字体文件|*.ttc|全部文件|*.*";
            f.FilterIndex = 1;
            if (f.ShowDialog() == DialogResult.OK)
            {
                var files = f.FileNames;
                for (int i = 0; i < files.Length; i++)
                {
                    FileInfo fi = new FileInfo(files[i]);
                    if (fi.Extension == ".ttf" || fi.Extension == ".ttc")
                    {
                        File.Copy(fi.FullName, userFontDir + "/" + fi.Name);
                        UserFontCollection.AddFontFile(userFontDir + "/" + fi.Name);
                    }
                }
                return(true);
            }
            return(false);
        }
        internal static Task ExportCollectionAsZipAsync(List <InstalledFont> fontList, UserFontCollection selectedCollection)
        {
            var fonts = fontList.SelectMany(f => f.Variants).ToList();

            return(ExportFontsAsZipAsync(fonts, selectedCollection.Name));
        }
 void SelectCollection(UserFontCollection collection)
 {
     ViewModel.Activate();
     ViewModel.SelectedCollection = collection;
 }
 public AddToCollectionResult(bool success, InstalledFont font, UserFontCollection collection)
 {
     Success    = success;
     Font       = font;
     Collection = collection;
 }
        internal static async Task ExportCollectionToFolderAsync(List <InstalledFont> fontList, UserFontCollection selectedCollection)
        {
            var fonts = fontList.SelectMany(f => f.Variants).ToList();

            FolderPicker picker = new FolderPicker
            {
                SuggestedStartLocation = PickerLocationId.DocumentsLibrary
            };

            picker.FileTypeFilter.Add("*");


            if (await picker.PickSingleFolderAsync() is StorageFolder folder)
            {
                await Task.Run(async() =>
                {
                    var interop = SimpleIoc.Default.GetInstance <Interop>();
                    foreach (var font in fonts)
                    {
                        if (interop.GetFileBuffer(font.FontFace) is FontFileData d)
                        {
                            StorageFile file = await folder.CreateFileAsync(CleanFileName(font, d.FileName), CreationCollisionOption.ReplaceExisting);

                            using var stream = await file.OpenStreamForWriteAsync();
                            stream.SetLength(0);

                            DataWriter w = new DataWriter(stream.AsOutputStream());
                            w.WriteBuffer(d.Buffer);
                            await w.StoreAsync();
                            await w.FlushAsync();

                            d.Dispose();
                        }
                    }
                });

                Messenger.Default.Send(new AppNotificationMessage(true, new ExportFontFileResult(true, folder)));
            }
        }
        internal static async Task ExportCollectionAsZipAsync(List <InstalledFont> fontList, UserFontCollection selectedCollection)
        {
            var fonts = fontList.SelectMany(f => f.Variants).ToList();

            if (await PickFileAsync(selectedCollection.Name, "ZIP", new[] { ".zip" }) is StorageFile file)
            {
                await Task.Run(async() =>
                {
                    var interop = SimpleIoc.Default.GetInstance <Interop>();
                    using var i = await file.OpenStreamForWriteAsync();
                    i.SetLength(0);
                    using ZipArchive z = new ZipArchive(i, ZipArchiveMode.Create);
                    foreach (var font in fonts)
                    {
                        if (interop.GetFileBuffer(font.FontFace) is FontFileData d)
                        {
                            ZipArchiveEntry entry = z.CreateEntry(CleanFileName(font, d.FileName));
                            using (IOutputStream s = entry.Open().AsOutputStream())
                            {
                                DataWriter w = new DataWriter(s);
                                w.WriteBuffer(d.Buffer);
                                await w.StoreAsync();
                                await w.FlushAsync();
                            }

                            d.Dispose();
                        }
                    }
                });

                Messenger.Default.Send(new AppNotificationMessage(true, new ExportFontFileResult(true, file)));
            }
        }