Beispiel #1
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;
         }
     }
 }
Beispiel #2
0
        private static UIFont InternalTryGetFont(nfloat size, FontWeight fontWeight, FontStyle fontStyle, FontFamily requestedFamily, nfloat?basePreferredSize)
        {
            UIFont font = null;

            size = GetScaledFontSize(size, basePreferredSize);

            if (requestedFamily?.Source != null)
            {
                var fontFamilyName = FontFamilyHelper.RemoveUri(requestedFamily.Source);

                // If there's a ".", we assume there's an extension and that it's a font file path.
                font = fontFamilyName.Contains(".") ? GetCustomFont(size, fontFamilyName, fontWeight, fontStyle) : GetSystemFont(size, fontWeight, fontStyle, fontFamilyName);
            }

            return(font ?? GetDefaultFont(size, fontWeight, fontStyle));
        }
Beispiel #3
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)))));
        }
Beispiel #4
0
        private void HandleWordOption(string fontText, int coefficient, ContainerBuilder builder)
        {
            var resultFont = Result
                             .Of(() => FontFamilyHelper.GetFontFamily(fontText))
                             .RefineError($"{ToString()}.HandleWordOption")
                             .OnFail(Console.WriteLine);

            if (!resultFont.IsSuccess)
            {
                Console.WriteLine("The incorrect font has been replaced with the default font (Microsoft Sans Serif)");
                resultFont = new Result <FontFamily>(null, new FontFamily("Microsoft Sans Serif"));
            }

            var wordSettings = new WordSettings(resultFont.Value, coefficient);

            builder.RegisterInstance(wordSettings).As <WordSettings>();
        }
Beispiel #5
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)));
        }
 private bool AppliesToImpl(DocumentNode node)
 {
     if (PlatformTypes.FontFamily.IsAssignableFrom((ITypeId)node.Type))
     {
         DocumentPrimitiveNode documentPrimitiveNode = node as DocumentPrimitiveNode;
         if (documentPrimitiveNode != null)
         {
             DocumentNodeStringValue documentNodeStringValue = documentPrimitiveNode.Value as DocumentNodeStringValue;
             if (documentNodeStringValue != null)
             {
                 FontFamily oldFontFamily;
                 FontFamily newFontFamily;
                 FontEmbedder.CreateFontFamilyChange(this.FontFamilyChangeModel.FontChangeType, this.FontFamilyChangeModel.ProjectFont, node.Context, out oldFontFamily, out newFontFamily);
                 return(FontEmbedder.AreFontsEqual(new FontFamily(FontFamilyHelper.EnsureFamilyName(documentNodeStringValue.Value)), oldFontFamily, node.Context));
             }
         }
     }
     return(false);
 }
Beispiel #7
0
        internal static FontFamilyItem CreateFontFamilyItem(System.Windows.Media.FontFamily fontFamily)
        {
            XmlLanguage language1 = XmlLanguage.GetLanguage(CultureInfo.CurrentCulture.IetfLanguageTag);
            XmlLanguage language2 = XmlLanguage.GetLanguage("en-US");
            string      source;

            try
            {
                if (!fontFamily.FamilyNames.TryGetValue(language1, out source))
                {
                    if (!fontFamily.FamilyNames.TryGetValue(language2, out source))
                    {
                        source = fontFamily.Source;
                    }
                }
            }
            catch (ArgumentException ex)
            {
                source = fontFamily.Source;
            }
            return(new FontFamilyItem(FontFamilyHelper.EnsureFamilyName(source), string.Empty, CodeOptionsControl.defaultPreviewFontFamilyName, fontFamily));
        }
Beispiel #8
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);
             }
         }
     }
 }
Beispiel #9
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));
        }