Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
0
        public static FontFamily MakeDesignTimeFontFamily(FontFamily fontFamily, IDocumentContext documentContext)
        {
            string[]      strArray = fontFamily.Source.Split(',');
            List <string> list     = new List <string>();

            foreach (string str in strArray)
            {
                if (Microsoft.Expression.Framework.Documents.PathHelper.IsPathRelative(str))
                {
                    Uri result = (Uri)null;
                    if (Uri.TryCreate(str, UriKind.Relative, out result))
                    {
                        Uri uri = documentContext.MakeDesignTimeUri(result);
                        if (uri.IsAbsoluteUri)
                        {
                            list.Add(uri.LocalPath);
                        }
                        else
                        {
                            list.Add(uri.ToString());
                        }
                    }
                }
                else
                {
                    list.Add(str);
                }
            }
            for (int index = 0; index < list.Count; ++index)
            {
                list[index] = list[index].Replace("Fonts.zip#", "#");
            }
            if (list.Count <= 0)
            {
                return(fontFamily);
            }
            string familyName = list[0];

            for (int index = 1; index < list.Count; ++index)
            {
                familyName = familyName + (object)"," + (string)(object)familyName[index];
            }
            return(new FontFamily((Uri)null, FontFamilyHelper.EnsureFamilyName(familyName)));
        }