Example #1
0
        public static bool AreFontsEqual(FontFamily lhs, FontFamily rhs, IDocumentContext documentContext)
        {
            if (FontEmbedder.GetFontNameFromSource(lhs) == FontEmbedder.GetFontNameFromSource(rhs))
            {
                return(true);
            }
            bool flag1 = lhs == null || lhs.Source == null;
            bool flag2 = rhs == null || rhs.Source == null;

            if (flag1 && flag2)
            {
                return(true);
            }
            if (flag1 || flag2)
            {
                return(false);
            }
            if (lhs.Source == rhs.Source)
            {
                return(true);
            }
            string fontFamilyPath1 = FontEmbedder.GetFontFamilyPath(lhs.Source);
            string fontFamilyPath2 = FontEmbedder.GetFontFamilyPath(rhs.Source);
            bool   flag3           = !string.IsNullOrEmpty(fontFamilyPath1);
            bool   flag4           = !string.IsNullOrEmpty(fontFamilyPath2);

            if (!flag3 && !flag4 || (!flag3 || !flag4))
            {
                return(false);
            }
            return(FontEmbedder.GetFontNameFromSource(FontEmbedder.MakeDesignTimeFontFamily(lhs, documentContext)) == FontEmbedder.GetFontNameFromSource(FontEmbedder.MakeDesignTimeFontFamily(rhs, documentContext)));
        }
Example #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();
                }
            }
        }
Example #3
0
 public FontEmbedOption(SystemFontFamily systemFont, SceneViewModel viewModel, FontEmbeddingDialogModel embeddingModel)
 {
     this.systemFont              = systemFont;
     this.viewModel               = viewModel;
     this.embeddingModel          = embeddingModel;
     this.IsFontSubsettingAllowed = FontEmbedder.DoesFontFileSupportSubsetting(Enumerable.FirstOrDefault <string>((IEnumerable <string>)systemFont.FontSources) ?? string.Empty);
 }
Example #4
0
 public static IEnumerable <string> GetFontNamesInFile(string fontFile, bool useGdiFontNames)
 {
     foreach (FontFamily fontFamily in (IEnumerable <FontFamily>)FontEmbedder.GetFontFamiliesSafe(fontFile))
     {
         yield return(FontEmbedder.GetSerializeFontFamilyName(fontFamily, useGdiFontNames));
     }
 }
Example #5
0
        public static string GetGdiName(FontFamily family)
        {
            string   str      = string.Empty;
            Typeface typeface = Enumerable.FirstOrDefault <Typeface>((IEnumerable <Typeface>)family.GetTypefaces());

            try
            {
                if (typeface != null)
                {
                    GlyphTypeface glyphTypeface;
                    if (typeface.TryGetGlyphTypeface(out glyphTypeface))
                    {
                        if (!glyphTypeface.Win32FamilyNames.TryGetValue(CultureInfo.GetCultureInfo("en-US"), out str))
                        {
                            str = Enumerable.FirstOrDefault <string>((IEnumerable <string>)glyphTypeface.Win32FamilyNames.Values) ?? string.Empty;
                        }
                    }
                }
            }
            catch
            {
                str = FontEmbedder.GetWpfName(family);
            }
            return(str);
        }
Example #6
0
 private static void EnsureSystemFontCache()
 {
     if (FontResolver.gdiFontFamilyToFontFileMap != null)
     {
         return;
     }
     FontResolver.gdiFontFamilyToFontFileMap = new Dictionary <string, List <string> >();
     FontResolver.wpfFontFamilyToFontFileMap = new Dictionary <string, List <string> >();
     foreach (string str in Directory.GetFiles(FontEmbedder.SystemFontsDirectory))
     {
         foreach (Typeface typeface in (IEnumerable <Typeface>)FontEmbedder.GetTypefacesSafe(str))
         {
             bool   useGdiFontNames1         = true;
             string serializeFontFamilyName1 = FontEmbedder.GetSerializeFontFamilyName(typeface, useGdiFontNames1);
             bool   useGdiFontNames2         = false;
             string serializeFontFamilyName2 = FontEmbedder.GetSerializeFontFamilyName(typeface, useGdiFontNames2);
             FontResolver.StoreSystemFont(FontResolver.gdiFontFamilyToFontFileMap, serializeFontFamilyName1, str);
             FontResolver.StoreSystemFont(FontResolver.wpfFontFamilyToFontFileMap, serializeFontFamilyName2, str);
             if (serializeFontFamilyName1 != serializeFontFamilyName2)
             {
                 FontResolver.gdiToWpfSystemFontNameMap[serializeFontFamilyName1] = serializeFontFamilyName2;
                 FontResolver.wpfToGdiSystemFontNameMap[serializeFontFamilyName2] = serializeFontFamilyName1;
             }
         }
     }
 }
Example #7
0
 private static void AddFontFileToCache(string fontFile, Dictionary <string, List <KeyValuePair <Typeface, string> > > cache, bool useGdiFontNames, Dictionary <string, string> gdiFontNameMap, Dictionary <string, string> wpfFontNameMap)
 {
     foreach (string str in FontEmbedder.GetFontNamesInFile(fontFile, useGdiFontNames))
     {
         string     index      = FontFamilyHelper.EnsureFamilyName(str);
         FontFamily fontFamily = new FontFamily(fontFile + "#" + index);
         List <KeyValuePair <Typeface, string> > list;
         if (!cache.TryGetValue(str, out list))
         {
             list         = new List <KeyValuePair <Typeface, string> >();
             cache[index] = list;
         }
         foreach (Typeface key in (IEnumerable <Typeface>)FontEmbedder.GetTypefacesSafe(fontFile))
         {
             list.Add(new KeyValuePair <Typeface, string>(key, fontFamily.Source));
         }
     }
     if (gdiFontNameMap == null)
     {
         return;
     }
     foreach (Typeface typeface in (IEnumerable <Typeface>)FontEmbedder.GetTypefacesSafe(fontFile))
     {
         bool   useGdiFontNames1         = true;
         string serializeFontFamilyName1 = FontEmbedder.GetSerializeFontFamilyName(typeface, useGdiFontNames1);
         bool   useGdiFontNames2         = false;
         string serializeFontFamilyName2 = FontEmbedder.GetSerializeFontFamilyName(typeface, useGdiFontNames2);
         if (serializeFontFamilyName1 != serializeFontFamilyName2 && !string.IsNullOrEmpty(serializeFontFamilyName1) && !string.IsNullOrEmpty(serializeFontFamilyName2))
         {
             gdiFontNameMap[serializeFontFamilyName1] = serializeFontFamilyName2;
             wpfFontNameMap[serializeFontFamilyName2] = serializeFontFamilyName1;
         }
     }
 }
Example #8
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;
            }
        }
Example #9
0
        public ProjectFont EmbedSystemFont(SystemFontFamily systemFontFamily)
        {
            string fontsDirectory = Path.Combine(this.viewModel.DesignerContext.ActiveProject.ProjectRoot.Path, "Fonts");

            if (!Microsoft.Expression.Framework.Documents.PathHelper.DirectoryExists(fontsDirectory))
            {
                Directory.CreateDirectory(fontsDirectory);
            }
            foreach (IProjectItem projectItem in this.viewModel.DesignerContext.ActiveProject.AddItems(Enumerable.Select <string, DocumentCreationInfo>((IEnumerable <string>)systemFontFamily.FontSources, (Func <string, DocumentCreationInfo>)(fontSource => new DocumentCreationInfo()
            {
                TargetFolder = fontsDirectory,
                SourcePath = fontSource,
                CreationOptions = CreationOptions.DoNotSelectCreatedItems
            }))))
            {
                IMSBuildItem msBuildItem = projectItem as IMSBuildItem;
                if (msBuildItem != null)
                {
                    projectItem.Properties["BuildAction"] = "BlendEmbeddedFont";
                    msBuildItem.SetMetadata("IsSystemFont", "True");
                    msBuildItem.SetMetadata("All", "True");
                    msBuildItem.SetMetadata("AutoFill", "True");
                }
            }
            this.EnsureFontSubsettingTask();
            foreach (ProjectFont projectFont in (Collection <IProjectFont>) this.viewModel.ProjectContext.ProjectFonts)
            {
                if (projectFont.FontFamilyName == FontEmbedder.GetFontNameFromSource(systemFontFamily.FontFamily))
                {
                    this.ChangeFontReferenceToEmbeddedFont((IProjectFont)projectFont);
                    return(projectFont);
                }
            }
            return((ProjectFont)null);
        }
Example #10
0
 public static IEnumerable <SystemFontFamily> GetSystemFonts(ITypeResolver typeResolver)
 {
     if (typeResolver.IsCapabilitySet(PlatformCapability.UsesGdiFontNames))
     {
         return(FontEmbedder.GetGdiFontFamilies());
     }
     return(FontEmbedder.GetWpfFontFamilies());
 }
Example #11
0
 private static IEnumerable <SystemFontFamily> GetGdiFontFamilies()
 {
     if (FontEmbedder.gdiFonts == null)
     {
         FontEmbedder.CreateSystemFontFamiliesCache();
     }
     return(FontEmbedder.gdiFonts);
 }
Example #12
0
 public static FontFamily MakeDesignTimeFontReference(FontFamily fontFamily, IDocumentContext documentContext)
 {
     if (fontFamily.Source != null && fontFamily.Source.IndexOf('#') != -1)
     {
         return(FontEmbedder.MakeDesignTimeFontFamily(fontFamily, documentContext));
     }
     return(fontFamily);
 }
Example #13
0
 public FontEmbedOption(ProjectFont projectFont, IProjectItem projectItem, SceneViewModel viewModel, FontEmbeddingDialogModel embeddingModel)
 {
     this.projectFont = projectFont;
     this.viewModel   = viewModel;
     this.InitializeEmbedOptions(projectItem);
     this.isEmbedded              = this.IsFontItemEmbedded;
     this.embeddingModel          = embeddingModel;
     this.IsFontSubsettingAllowed = FontEmbedder.DoesFontFileSupportSubsetting(projectFont.FontDocumentPath);
 }
Example #14
0
        public string ResolveFont(string fontFamilySource, object fontStretch, object fontStyle, object fontWeight, IDocumentContext documentContext)
        {
            string     fontFamilyPath = FontEmbedder.GetFontFamilyPath(fontFamilySource);
            FontFamily fontFamily     = FontEmbedder.MakeDesignTimeFontReference(new FontFamily(fontFamilySource), documentContext);
            Dictionary <string, List <KeyValuePair <Typeface, string> > > dictionary;

            if (string.IsNullOrEmpty(fontFamilyPath))
            {
                FontResolver.EnsureSystemFontCached(fontFamilySource);
                dictionary = this.useGdiFontNames ? FontResolver.gdiFontFamilyLookup : FontResolver.wpfFontFamilyLookup;
            }
            else
            {
                Uri uri = documentContext.MakeDesignTimeUri(new Uri(fontFamilyPath, UriKind.RelativeOrAbsolute));
                if (!uri.IsAbsoluteUri)
                {
                    return(fontFamilySource);
                }
                string localPath = uri.LocalPath;
                if (Microsoft.Expression.Framework.Documents.PathHelper.FileExists(localPath) && !localPath.EndsWith(".zip", StringComparison.OrdinalIgnoreCase))
                {
                    return(FontEmbedder.MakeSilverlightFontReference(this.GetCachedFont(localPath) + FontEmbedder.GetFontFamilySpecifier(fontFamilySource)));
                }
                if (!this.projectFontFamilyLookup.TryGetValue(Path.GetDirectoryName(uri.LocalPath), out dictionary))
                {
                    int num = fontFamilySource.IndexOf(";component", StringComparison.OrdinalIgnoreCase);
                    if (num != -1 && fontFamilySource.StartsWith("/", StringComparison.OrdinalIgnoreCase))
                    {
                        IFontResolver resolverForComponent = this.GetFontResolverForComponent(fontFamilySource.Substring(1, num - 1));
                        if (resolverForComponent != null && resolverForComponent != this)
                        {
                            return(resolverForComponent.ResolveFont(fontFamilySource, fontStretch, fontStyle, fontWeight, documentContext));
                        }
                    }
                    return(fontFamilySource);
                }
            }
            string fontNameFromSource = FontEmbedder.GetFontNameFromSource(fontFamily);
            List <KeyValuePair <Typeface, string> > list;

            if (dictionary.TryGetValue(fontNameFromSource, out list))
            {
                string path = (string)null;
                FontResolver.FontMatch fontMatch1 = (FontResolver.FontMatch)null;
                foreach (KeyValuePair <Typeface, string> keyValuePair in list)
                {
                    FontResolver.FontMatch fontMatch2 = new FontResolver.FontMatch(keyValuePair.Key, fontStretch, fontStyle, fontWeight);
                    if (fontMatch1 == null || fontMatch2.CompareTo((object)fontMatch1) > 0)
                    {
                        path       = keyValuePair.Value;
                        fontMatch1 = fontMatch2;
                    }
                }
                fontFamilySource = FontEmbedder.MakeSilverlightFontReference(Path.GetFullPath(path));
            }
            return(fontFamilySource);
        }
Example #15
0
        public static string GetSerializeFontFamilyName(FontFamily fontFamily, bool useGdiFontNames)
        {
            Typeface typeface = Enumerable.FirstOrDefault <Typeface>((IEnumerable <Typeface>)fontFamily.GetTypefaces());

            if (typeface != null)
            {
                return(FontEmbedder.GetSerializeFontFamilyName(typeface, useGdiFontNames));
            }
            return(string.Empty);
        }
        public override bool Equals(object obj)
        {
            SourcedFontFamilyItem sourcedFontFamilyItem = obj as SourcedFontFamilyItem;

            if (sourcedFontFamilyItem == null || !(this.FamilyName == sourcedFontFamilyItem.FamilyName))
            {
                return(false);
            }
            return(FontEmbedder.AreFontsEqual(this.FontFamilySource, sourcedFontFamilyItem.FontFamilySource, this.DocumentContext));
        }
        private static FontFamily ConvertToWpfFontFamily(FontFamily fontFamily, IDocumentContext documentContext)
        {
            if (string.IsNullOrEmpty(fontFamily.Source))
            {
                return(fontFamily);
            }
            string fontNameFromSource = FontEmbedder.GetFontNameFromSource(fontFamily);
            string fontFamilyPath     = FontEmbedder.GetFontFamilyPath(fontFamily.Source);
            string str = ((IProjectContext)documentContext.TypeResolver).FontResolver.ConvertToWpfFontName(fontNameFromSource);

            return(new FontFamily(!string.IsNullOrEmpty(fontFamilyPath) ? fontFamilyPath + "#" + str : str));
        }
        public FontEmbeddingDialogModel(SceneViewModel viewModel)
        {
            this.viewModel = viewModel;
            Dictionary <string, FontEmbedOption> dictionary = new Dictionary <string, FontEmbedOption>();

            foreach (ProjectFont projectFont in (Collection <IProjectFont>)viewModel.ProjectContext.ProjectFonts)
            {
                IProjectItem projectItem = viewModel.DesignerContext.ActiveProject.FindItem(projectFont.FontDocumentReference);
                if (projectItem != null)
                {
                    FontEmbedOption fontEmbedOption = new FontEmbedOption(projectFont, projectItem, viewModel, this);
                    this.fonts.Add(fontEmbedOption);
                    dictionary[projectFont.FontFamilyName] = fontEmbedOption;
                    List <FontEmbedOption> list;
                    if (!this.linkedProjectFonts.TryGetValue(projectFont.FontDocumentReference, out list))
                    {
                        list = new List <FontEmbedOption>();
                        this.linkedProjectFonts[projectFont.FontDocumentReference] = list;
                    }
                    list.Add(fontEmbedOption);
                }
            }
            foreach (SystemFontFamily systemFont in FontEmbedder.GetSystemFonts((ITypeResolver)viewModel.ProjectContext))
            {
                FontEmbedOption fontEmbedOption = (FontEmbedOption)null;
                if (dictionary.TryGetValue(systemFont.FontFamilyName, out fontEmbedOption))
                {
                    if (fontEmbedOption.WasSystemFont)
                    {
                        fontEmbedOption.SystemFont = systemFont;
                    }
                }
                else if (!systemFont.IsNativeSilverlightFont || !this.viewModel.ProjectContext.IsCapabilitySet(PlatformCapability.DisallowEmbeddingSilverlightFonts))
                {
                    this.fonts.Add(new FontEmbedOption(systemFont, viewModel, this));
                }
            }
            this.fonts.Sort((Comparison <FontEmbedOption>)((lhs, rhs) =>
            {
                if (lhs.ProjectFont != null && rhs.ProjectFont == null)
                {
                    return(-1);
                }
                if (lhs.ProjectFont == null && rhs.ProjectFont != null)
                {
                    return(1);
                }
                return(lhs.FontFamilyName.CompareTo(rhs.FontFamilyName));
            }));
            this.fontsView = CollectionViewSource.GetDefaultView((object)this.fonts);
            this.fontsView.CurrentChanged += new EventHandler(this.fontsView_CurrentChanged);
        }
Example #19
0
 public object Convert(object o, Type targetType, object parameter, CultureInfo culture)
 {
   IDocumentContext documentContext = this.SceneNodeObjectSet.DocumentContext;
   FontFamily fontFamily1 = this.SceneNodeObjectSet.DesignerContext.PlatformConverter.ConvertToWpf(documentContext, o) as FontFamily;
   if (fontFamily1 == null)
     return o;
   string source = fontFamily1.Source;
   Uri result;
   bool flag = !Uri.TryCreate(source, UriKind.RelativeOrAbsolute, out result) ? !Path.IsPathRooted(source) : !result.IsAbsoluteUri;
   if (string.IsNullOrEmpty(source) || !flag || source.IndexOf('#') == -1)
     return (object) new UnknownSourceFontFamilyItem(fontFamily1, this.SceneNodeObjectSet);
   FontFamily fontFamily2 = fontFamily1;
   return (object) new UnknownSourceFontFamilyItem(FontEmbedder.MakeDesignTimeFontFamily(fontFamily2, documentContext), fontFamily2, this.SceneNodeObjectSet);
 }
Example #20
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)))));
        }
Example #21
0
        private static void StoreFontLookup(Dictionary <string, List <KeyValuePair <Typeface, string> > > fontFamilyLookup, Dictionary <string, List <string> > fontFamilyToFontFileMap, string fontSource, bool useGdiFontNames)
        {
            if (fontFamilyLookup.ContainsKey(fontSource))
            {
                return;
            }
            string        serializeFontFamilyName = FontEmbedder.GetSerializeFontFamilyName(new FontFamily(fontSource), useGdiFontNames);
            List <string> list;

            if (!fontFamilyToFontFileMap.TryGetValue(serializeFontFamilyName, out list))
            {
                return;
            }
            foreach (string fontFile in list)
            {
                FontResolver.AddFontFileToCache(fontFile, fontFamilyLookup, useGdiFontNames, (Dictionary <string, string>)null, (Dictionary <string, string>)null);
            }
        }
Example #22
0
        public static string GetWpfName(FontFamily fontFamily)
        {
            string str = string.Empty;

            try
            {
                if (!fontFamily.FamilyNames.TryGetValue(XmlLanguage.GetLanguage("en-US"), out str))
                {
                    str = Enumerable.FirstOrDefault <string>((IEnumerable <string>)fontFamily.FamilyNames.Values) ?? string.Empty;
                }
            }
            catch (ArgumentException ex)
            {
                if (!string.IsNullOrEmpty(fontFamily.Source))
                {
                    str = FontEmbedder.GetFontNameFromSource(fontFamily);
                }
            }
            return(str);
        }
Example #23
0
        private static void StoreSystemFont(string fontFile, Typeface typeface, Dictionary <string, SystemFontFamily> fontFileMap, bool useGdiFontNames)
        {
            string serializeFontFamilyName = FontEmbedder.GetSerializeFontFamilyName(typeface, useGdiFontNames);

            if (string.IsNullOrEmpty(serializeFontFamilyName))
            {
                return;
            }
            SystemFontFamily systemFontFamily = (SystemFontFamily)null;

            if (!fontFileMap.TryGetValue(serializeFontFamilyName, out systemFontFamily))
            {
                systemFontFamily = new SystemFontFamily(new FontFamily(serializeFontFamilyName));
                fontFileMap[serializeFontFamilyName] = systemFontFamily;
            }
            if (systemFontFamily.FontSources.Contains(fontFile))
            {
                return;
            }
            systemFontFamily.FontSources.Add(fontFile);
        }
Example #24
0
 private static void RemoveFontFileFromCache(string fontFile, Dictionary <string, List <KeyValuePair <Typeface, string> > > cache, bool useGdiFontNames)
 {
     foreach (string familyName in FontEmbedder.GetFontNamesInFile(fontFile, useGdiFontNames))
     {
         string key = FontFamilyHelper.EnsureFamilyName(familyName);
         List <KeyValuePair <Typeface, string> > list;
         if (cache.TryGetValue(key, out list))
         {
             using (IEnumerator <Typeface> enumerator = FontEmbedder.GetTypefacesSafe(fontFile).GetEnumerator())
             {
                 while (enumerator.MoveNext())
                 {
                     Typeface typeface = enumerator.Current;
                     list.RemoveAll((Predicate <KeyValuePair <Typeface, string> >)(putativeTypeface => typeface == putativeTypeface.Key));
                 }
             }
             if (list.Count == 0)
             {
                 cache.Remove(key);
             }
         }
     }
 }
Example #25
0
        public static string GetSerializeFontFamilyName(Typeface typeface, bool useGdiFontNames)
        {
            string str1 = FontFamilyHelper.EnsureFamilyName(FontEmbedder.GetGdiName(typeface.FontFamily));
            string familyName;

            if (useGdiFontNames)
            {
                familyName = str1;
            }
            else
            {
                string str2 = FontEmbedder.GetFontFamilyPath(typeface.FontFamily.Source);
                if (string.IsNullOrEmpty(str2))
                {
                    str2 = Microsoft.Expression.Framework.Documents.PathHelper.EnsurePathEndsInDirectorySeparator(FontEmbedder.SystemFontsDirectory);
                }
                FontFamily fontFamily = new FontFamily(str2 + "#" + str1);
                string     wpfName1   = FontEmbedder.GetWpfName(typeface.FontFamily);
                string     wpfName2   = FontEmbedder.GetWpfName(fontFamily);
                familyName = !(wpfName1 != wpfName2) ? str1 : wpfName1;
            }
            return(FontFamilyHelper.EnsureFamilyName(familyName));
        }
Example #26
0
        public static void CreateSystemFontFamiliesCache()
        {
            PerformanceUtility.StartPerformanceSequence(PerformanceEvent.FontCacheInitialization);
            Dictionary <string, SystemFontFamily> fontFileMap1 = new Dictionary <string, SystemFontFamily>();
            Dictionary <string, SystemFontFamily> fontFileMap2 = new Dictionary <string, SystemFontFamily>();

            foreach (string str in Directory.GetFiles(FontEmbedder.SystemFontsDirectory))
            {
                foreach (Typeface typeface in (IEnumerable <Typeface>)FontEmbedder.GetTypefacesSafe(str))
                {
                    bool useGdiFontNames1 = false;
                    FontEmbedder.StoreSystemFont(str, typeface, fontFileMap1, useGdiFontNames1);
                    bool useGdiFontNames2 = true;
                    FontEmbedder.StoreSystemFont(str, typeface, fontFileMap2, useGdiFontNames2);
                }
            }
            FontEmbedder.wpfFonts = (IEnumerable <SystemFontFamily>)Enumerable.ToList <SystemFontFamily>((IEnumerable <SystemFontFamily>)fontFileMap1.Values);
            SystemFontFamily systemFontFamily = new SystemFontFamily(new FontFamily("Portable User Interface"));

            fontFileMap2["Portable User Interface"] = systemFontFamily;
            FontEmbedder.gdiFonts = (IEnumerable <SystemFontFamily>)Enumerable.ToList <SystemFontFamily>((IEnumerable <SystemFontFamily>)fontFileMap2.Values);
            PerformanceUtility.EndPerformanceSequence(PerformanceEvent.FontCacheInitialization);
        }
Example #27
0
 public static List <SourcedFontFamilyItem> GetFontFamilies(SceneNodeObjectSet sceneNodeObjectSet)
 {
     return(FontFamilyValueEditor.GetFontFamilies(FontEmbedder.GetSystemFonts(sceneNodeObjectSet.DocumentContext.TypeResolver), (ICollection <IProjectFont>)sceneNodeObjectSet.ProjectContext.ProjectFonts, sceneNodeObjectSet));
 }
Example #28
0
 public static FontFamily MakeSystemFont(FontFamily fontFamily)
 {
     return(new FontFamily(fontFamily.BaseUri, FontEmbedder.GetFontNameFromSource(fontFamily)));
 }
Example #29
0
 public void EnsureFontSubsettingTask()
 {
     this.viewModel.DesignerContext.ActiveProject.AddImport(FontEmbedder.GetSubsetFontTargetFileName(this.viewModel.ProjectContext.TargetFramework));
 }
Example #30
0
        public static bool IsSubsetFontTargetInstalled(ITypeResolver context)
        {
            ProjectXamlContext projectXamlContext = (ProjectXamlContext)context;
            FrameworkName      targetFramework    = projectXamlContext.TargetFramework;
            bool flag;

            if (!FontEmbedder.isSubsettingTaskInstalledForPlatform.TryGetValue(targetFramework, out flag))
            {
                string buildExtensionsPath = projectXamlContext.MSBuildExtensionsPath;
                flag = Microsoft.Expression.Framework.Documents.PathHelper.FileExists(FontEmbedder.GetSubsetFontTargetFileName(targetFramework).Replace("$(MSBuildExtensionsPath)", buildExtensionsPath));
                FontEmbedder.isSubsettingTaskInstalledForPlatform.Add(targetFramework, flag);
            }
            return(flag);
        }