/// <summary> /// 사용자가 입력한 폰트 파일을 저장한다. /// </summary> /// <param name="fontFile"></param> /// <returns></returns> public static async Task InstallFont(StorageFile fontFile, ObservableCollection <KeyName> fontListSource, TappedEventHandler tapped) { var folder = await Windows.Storage.ApplicationData.Current.LocalFolder.CreateFolderAsync("Fonts", CreationCollisionOption.OpenIfExists); try { //폰트 복사(설치) var copy = await fontFile.CopyAsync(folder, Path.GetFileName(fontFile.Name), NameCollisionOption.FailIfExists); List <KeyName> addedFontList = new List <KeyName>(); foreach (var fontItem in await GetFontItems(copy)) { fontItem.ItemTapped = tapped; if (fontListSource != null) { if (!fontListSource.Any(x => x.Key == fontItem.Key)) { var index = fontListSource.IndexOf(fontListSource.LastOrDefault(x => x.Name.CompareTo(fontItem.Name) < 0)); fontListSource.Insert(index + 1, fontItem); } } if (FontList != null) { if (!FontList.Any(x => x.Key == fontItem.Key)) { var index = FontList.IndexOf(FontList.Where(x => x.Type == FontTypes.App.ToString()).LastOrDefault(x => x.Name.CompareTo(fontItem.Name) < 0)); FontList.Insert(index + 1, fontItem); } } if (!addedFontList.Contains(fontItem)) { addedFontList.Add(fontItem); } if (fontItem.Payload is StorageFile) { var path = (fontItem.Payload as StorageFile).Path; FontDAO.DeleteTempFont(new string[] { path }); } } //이벤트 처리 if (FontFamilyListChanged != null) { FontFamilyListChanged(FontList, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, addedFontList)); } } catch (Exception) { } }
public static void RemoveFont(ObservableCollection <KeyName> fontListSource, KeyName pickerItem) { List <KeyName> removedFontList = new List <KeyName>(); if (pickerItem.Payload is StorageFile) { var file = pickerItem.Payload as StorageFile; FontDAO.InsertTempFont(file.Path); } if (fontListSource != null) { //공유되는 폰트를 모두 삭제 foreach (var font in fontListSource.Where(x => x.Payload == pickerItem.Payload).ToList()) { fontListSource.Remove(font); if (!removedFontList.Contains(font)) { removedFontList.Add(font); } } } if (FontList != null) { foreach (var font in FontList.Where(x => x.Payload == pickerItem.Payload).ToList()) { FontList.Remove(font); if (!removedFontList.Contains(font)) { removedFontList.Add(font); } } } //이벤트 처리 if (FontFamilyListChanged != null) { FontFamilyListChanged(FontList, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove, removedFontList)); } }