Exemple #1
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);
        }
Exemple #2
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)));
        }
Exemple #3
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);
        }
        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));
        }
Exemple #5
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);
        }
Exemple #6
0
 public static FontFamily MakeSystemFont(FontFamily fontFamily)
 {
     return(new FontFamily(fontFamily.BaseUri, FontEmbedder.GetFontNameFromSource(fontFamily)));
 }
 protected SourcedFontFamilyItem(FontFamily fontFamily, string category, SceneNodeObjectSet sceneNodeObjectSet)
     : base(FontFamilyItem.EnsureFamilyName(FontEmbedder.GetFontNameFromSource(fontFamily)), category, SourcedFontFamilyItem.DefaultPreviewFontFamilyName, SourcedFontFamilyItem.ConvertToWpfFontFamily(fontFamily, sceneNodeObjectSet.DocumentContext))
 {
     this.sceneNodeObjectSet = sceneNodeObjectSet;
 }
 protected SourcedFontFamilyItem(FontFamily fontFamily, string category, IDocumentContext documentContext)
     : base(FontFamilyItem.EnsureFamilyName(FontEmbedder.GetFontNameFromSource(fontFamily)), category, SourcedFontFamilyItem.DefaultPreviewFontFamilyName, SourcedFontFamilyItem.ConvertToWpfFontFamily(fontFamily, documentContext))
 {
     this.documentContext = documentContext;
 }