Esempio n. 1
0
        public void usePrivateFont(String fontName)
        {
            FontStyle fontStyle = FontStyle.Regular;

            if (font.Bold)
            {
                fontStyle = FontStyle.Bold;
            }
            if (font.Italic)
            {
                fontStyle |= FontStyle.Italic;
            }
            if (font.Strikeout)
            {
                fontStyle |= FontStyle.Strikeout;
            }
            if (font.Underline)
            {
                fontStyle |= FontStyle.Underline;
            }

            FontFamily fontFamily = FontHandler.getPrivateFontFamily(fontName);

            font = new Font(fontFamily, font.Size, font.Style, font.Unit, font.GdiCharSet, font.GdiVerticalFont);
        }
Esempio n. 2
0
        public List <String> installPrivateFonts(String fontsDir)
        {
            // Install fonts from specified directory
            List <String> fontNames = new List <String>();

            if (Directory.Exists(fontsDir))
            {
                foreach (String fileName in Directory.GetFiles(fontsDir))
                {
                    if (fileName.ToLower().EndsWith(".ttf"))
                    {
                        String name = FontHandler.addPrivateFont(Path.Combine(fontsDir, fileName));
                        fontNames.Add(name);
                    }
                }
            }
            return(fontNames);
        }
Esempio n. 3
0
        public void getFonts(FontAsyncCallback callback)
        {
            Logger.log(Logger.TYPE.DEBUG, "Getting fonts...");

            var root = from item in serverXMLCache.get().Descendants("Server")
                       select new {
                fonts = item.Descendants("Font")
            };

            List <FontPackage> packages = new List <FontPackage>();

            foreach (var data in root)
            {
                foreach (var f in data.fonts)
                {
                    packages.Add(new FontPackage(f));
                }
            }

            List <String> installedFonts = new List <String>();

            String fontCachePath = client.getFontCacheDir();
            String tmpFontPath   = Path.Combine(fontCachePath, "tmpfonts");

            if (!Directory.Exists(fontCachePath))
            {
                Directory.CreateDirectory(fontCachePath);
                Directory.CreateDirectory(tmpFontPath);
            }
            else
            {
                if (!Directory.Exists(tmpFontPath))
                {
                    Directory.CreateDirectory(tmpFontPath);
                }
                // Preload already existing fonts
                installedFonts = installPrivateFonts(fontCachePath);
            }

            if (packages.Count > 0)
            {
                // Download font packages
                foreach (FontPackage package in packages)
                {
                    if (!FontHandler.doesFontExist(package.getName(), true, true))
                    {
                        if (package.canDownload())
                        {
                            Uri packageUrl = new Uri(getUrl() + "/" + package.getPackage());
                            dlHandler.enqueueFile(packageUrl, tmpFontPath,
                                                  package.getArchiveName(), (Boolean cancelled) => {
                                if (!cancelled)
                                {
                                    ArchiveHandler.extractZip(Path.Combine(tmpFontPath,
                                                                           package.getArchiveName()), tmpFontPath, false);
                                }
                            });
                        }
                    }
                    else
                    {
                        package.setInstalled(true);
                    }
                }

                dlHandler.setQueueFileCallback(new QueueCallback(() => {
                    installedFonts.AddRange(installPrivateFonts(tmpFontPath));

                    // Finished installing new fonts, now cache them
                    cacheFonts(tmpFontPath);

                    // Apply new fonts to the packages
                    foreach (FontPackage package in packages)
                    {
                        if (FontHandler.doesPrivateFontExist(package.getName(), true))
                        {
                            package.setInstalled(true); // Ensure package is now installed

                            foreach (KeyValuePair <String, FontApply> pair in package.getApplyMap())
                            {
                                FontApply fontApply = pair.Value;
                                fontApply.usePrivateFont(package.getName());
                            }
                        }
                    }

                    callback.onSuccess(packages);
                }));

                dlHandler.startFileQueue();
            }
            else
            {
                callback.onSuccess(packages);
            }
        }