예제 #1
0
        private void applyCustomFonts(Dictionary <String, FontApply> applyMap)
        {
            Logger.log(Logger.TYPE.DEBUG, "Applying " + applyMap.Count + " custom fonts");

            foreach (KeyValuePair <String, FontApply> pair in applyMap)
            {
                String    to        = pair.Key;
                FontApply fontApply = pair.Value;

                foreach (Control control in ui.getControls())
                {
                    if (control.Name.Equals(to))
                    {
                        control.Font = fontApply.getFont();
                    }
                }
            }
        }
예제 #2
0
 public void addApply(FontApply fontApply)
 {
     applyMap.Remove(fontApply.getTo());
     applyMap.Add(fontApply.getTo(), fontApply);
 }
예제 #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);
            }
        }
예제 #4
0
 public void addApply(FontApply fontApply)
 {
     applyMap.Remove(fontApply.getTo());
     applyMap.Add(fontApply.getTo(), fontApply);
 }