Exemplo 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);
        }
Exemplo n.º 2
0
 public int CompareTo(object rhs)
 {
     FontResolver.FontMatch fontMatch = (FontResolver.FontMatch)rhs;
     if (this.exactMatches != fontMatch.exactMatches)
     {
         return(this.exactMatches - fontMatch.exactMatches);
     }
     return(-(this.fontWeightDifference - fontMatch.fontWeightDifference));
 }