Exemplo n.º 1
0
        public bool UnembedProjectFont(IProjectFont projectFont)
        {
            List <IProjectItem> list = new List <IProjectItem>();

            foreach (DocumentReference documentReference in ((ProjectFont)projectFont).FontDocuments)
            {
                IProjectItem projectItem = this.viewModel.DesignerContext.ActiveProject.FindItem(documentReference);
                if (projectItem != null)
                {
                    switch (((IMSBuildItem)projectItem).GetMetadata("IsSystemFont"))
                    {
                    case "True":
                        list.Add(projectItem);
                        continue;

                    default:
                        projectItem.Properties["BuildAction"] = "Resource";
                        continue;
                    }
                }
            }
            if (list.Count > 0)
            {
                this.ChangeFontReferenceToUnembeddedFont(projectFont);
            }
            else
            {
                this.ChangeFontReferenceToUnzippedFont(projectFont);
            }
            foreach (IProjectItem projectItem in list)
            {
                this.viewModel.DesignerContext.ActiveProject.RemoveItems(1 != 0, projectItem);
            }
            return(list.Count > 0);
        }
Exemplo n.º 2
0
        private void ChangeFontReference(FontChangeType fontChange, IProjectFont projectFont)
        {
            FontFamily oldFontFamily;
            FontFamily newFontFamily;

            FontEmbedder.CreateFontFamilyChange(fontChange, projectFont, this.viewModel.Document.DocumentContext, out oldFontFamily, out newFontFamily);
            if (!(oldFontFamily.Source != newFontFamily.Source))
            {
                return;
            }
            SceneElement sceneElement = this.viewModel.RootNode as SceneElement;

            if (sceneElement == null)
            {
                return;
            }
            FontFamilyRepairProcessor familyRepairProcessor = new FontFamilyRepairProcessor(this.viewModel.DesignerContext, new FontFamilyChangeModel(oldFontFamily.Source, newFontFamily.Source, fontChange, projectFont, sceneElement.DocumentNode.DocumentRoot, this.viewModel.ProjectContext));

            using (SceneEditTransaction editTransaction = this.viewModel.CreateEditTransaction(StringTable.EmbedFontUndoUnit))
            {
                familyRepairProcessor.Begin();
                if (familyRepairProcessor.Cancelled)
                {
                    editTransaction.Cancel();
                }
                else
                {
                    editTransaction.Commit();
                }
            }
        }
Exemplo n.º 3
0
        public static void CreateFontFamilyChange(FontChangeType fontChange, IProjectFont projectFont, IDocumentContext documentContext, out FontFamily oldFontFamily, out FontFamily newFontFamily)
        {
            switch (fontChange)
            {
            case FontChangeType.SystemToEmbedded:
                newFontFamily = FontEmbedder.MakeRelativeFontFamily(projectFont, documentContext, true);
                oldFontFamily = FontEmbedder.MakeSystemFont(newFontFamily);
                break;

            case FontChangeType.EmbeddedToSystem:
                oldFontFamily = FontEmbedder.MakeRelativeFontFamily(projectFont, documentContext, true);
                newFontFamily = FontEmbedder.MakeSystemFont(oldFontFamily);
                break;

            case FontChangeType.ProjectToEmbedded:
                oldFontFamily = FontEmbedder.MakeRelativeFontFamily(projectFont, documentContext, false);
                newFontFamily = FontEmbedder.MakeRelativeFontFamily(projectFont, documentContext, true);
                break;

            case FontChangeType.EmbeddedToProject:
                oldFontFamily = FontEmbedder.MakeRelativeFontFamily(projectFont, documentContext, true);
                newFontFamily = FontEmbedder.MakeRelativeFontFamily(projectFont, documentContext, false);
                break;

            default:
                oldFontFamily = newFontFamily = (FontFamily)null;
                break;
            }
        }
Exemplo n.º 4
0
 public FontFamilyChangeModel(string oldFontFamilyName, string newFontFamilyName, FontChangeType fontChangeType, IProjectFont projectFont, IDocumentRoot documentRoot, IProjectContext projectContext)
     : base(oldFontFamilyName, newFontFamilyName, documentRoot, projectContext)
 {
     this.fontFamilyRepairers = new List <ReferenceRepairer>();
     this.fontFamilyRepairers.Add((ReferenceRepairer) new FontFamilyReferenceRepairer(this));
     this.FontChangeType = fontChangeType;
     this.ProjectFont    = projectFont;
 }
Exemplo n.º 5
0
        public override bool HasFont(string fontFamilyName)
        {
            IProjectFont projectFont = (IProjectFont)null;

            if (this.viewModel != null)
            {
                Enumerable.FirstOrDefault <IProjectFont>((IEnumerable <IProjectFont>) this.viewModel.ProjectContext.ProjectFonts, (Func <IProjectFont, bool>)(font => font.FontFamilyName == fontFamilyName));
            }
            return(projectFont != null);
        }
Exemplo n.º 6
0
        private string FindFontFromProject(string fontNameToken, string modifierToken)
        {
            ObservableCollection <IProjectFont> projectFonts = this.SceneViewModel.ProjectContext.ProjectFonts;
            IFontResolver fontResolver        = this.SceneViewModel.ProjectContext.FontResolver;
            IEnumerable <IProjectFont> source = Enumerable.Where <IProjectFont>((IEnumerable <IProjectFont>)projectFonts, (Func <IProjectFont, bool>)(fontFamily =>
            {
                if (!ImportManager.TokenizeFontName(fontResolver.ConvertToGdiFontName(fontFamily.FontFamilyName)).StartsWith(fontNameToken, StringComparison.OrdinalIgnoreCase))
                {
                    return(ImportManager.TokenizeFontName(fontResolver.ConvertToWpfFontName(fontFamily.FontFamilyName)).StartsWith(fontNameToken, StringComparison.OrdinalIgnoreCase));
                }
                return(true);
            }));
            string       fontMatching = modifierToken == null ? fontNameToken : fontNameToken + modifierToken;
            IProjectFont projectFont1 = (IProjectFont)null;

            foreach (IProjectFont projectFont2 in source)
            {
                string strA1 = ImportManager.TokenizeFontName(fontResolver.ConvertToGdiFontName(projectFont2.FontFamilyName));
                string strA2 = ImportManager.TokenizeFontName(fontResolver.ConvertToWpfFontName(projectFont2.FontFamilyName));
                if (string.Compare(strA1, fontMatching, StringComparison.OrdinalIgnoreCase) == 0 || string.Compare(strA2, fontMatching, StringComparison.OrdinalIgnoreCase) == 0)
                {
                    return(FontEmbedder.MakeProjectFontReference(projectFont2, this.SceneViewModel.Document.DocumentContext).Source);
                }
                if (projectFont1 == null || projectFont1.FontFamilyName.Length > projectFont2.FontFamilyName.Length)
                {
                    projectFont1 = projectFont2;
                }
            }
            if (projectFont1 == null)
            {
                Enumerable.Where <IProjectFont>((IEnumerable <IProjectFont>)projectFonts, (Func <IProjectFont, bool>)(fontFamily =>
                {
                    if (!ImportManager.TokenizeFontName(fontResolver.ConvertToGdiFontName(fontFamily.FontFamilyName)).StartsWith(fontMatching, StringComparison.OrdinalIgnoreCase))
                    {
                        return(ImportManager.TokenizeFontName(fontResolver.ConvertToWpfFontName(fontFamily.FontFamilyName)).StartsWith(fontMatching, StringComparison.OrdinalIgnoreCase));
                    }
                    return(true);
                }));
                if (Enumerable.Count <IProjectFont>(source) > 0)
                {
                    projectFont1 = Enumerable.First <IProjectFont>(source);
                }
            }
            if (projectFont1 != null)
            {
                return(FontEmbedder.MakeProjectFontReference(projectFont1, this.SceneViewModel.Document.DocumentContext).Source);
            }
            return((string)null);
        }
Exemplo n.º 7
0
        private static FontFamily MakeRelativeFontFamily(IProjectFont projectFont, IDocumentContext documentContext, bool useZipForSilverlight)
        {
            string path  = documentContext.MakeResourceReference(projectFont.FontDocumentPath);
            string path1 = (!string.IsNullOrEmpty(path) ? Path.GetDirectoryName(path) : (string)null) ?? string.Empty;
            string path2 = "#" + projectFont.FontFamilyName;

            if (!documentContext.TypeResolver.IsCapabilitySet(PlatformCapability.IsWpf))
            {
                path2 = !useZipForSilverlight?Path.GetFileName(projectFont.FontDocumentPath) + path2 : "Fonts.zip" + path2;
            }
            else if (string.IsNullOrEmpty(path1))
            {
                path2 = "./" + path2;
            }
            return(new FontFamily((Uri)null, FontFamilyHelper.EnsureFamilyName(FontEmbedder.MakeSilverlightFontReference(Path.Combine(path1, path2)))));
        }
Exemplo n.º 8
0
 private void ChangeFontReferenceToUnembeddedFont(IProjectFont projectFont)
 {
     this.ChangeFontReference(FontChangeType.EmbeddedToSystem, projectFont);
 }
Exemplo n.º 9
0
 private void ChangeFontReferenceToUnzippedFont(IProjectFont projectFont)
 {
     this.ChangeFontReference(FontChangeType.EmbeddedToProject, projectFont);
 }
Exemplo n.º 10
0
 private void ChangeFontReferenceToZippedFont(IProjectFont projectFont)
 {
     this.ChangeFontReference(FontChangeType.ProjectToEmbedded, projectFont);
     this.ChangeFontReference(FontChangeType.SystemToEmbedded, projectFont);
 }
Exemplo n.º 11
0
 public static FontFamily MakeProjectFontReference(IProjectFont projectFont, IDocumentContext documentContext)
 {
     return(FontEmbedder.MakeRelativeFontFamily(projectFont, documentContext, projectFont.IsEmbedded));
 }