Ejemplo n.º 1
0
        /// <summary>
        /// Constructs a FontSurface object from a resource.
        /// </summary>
        /// <param name="resources"></param>
        /// <param name="resourceName"></param>
        public FontSurface(AgateResourceCollection resources, string resourceName)
        {
            AgateResource      res     = resources[resourceName];
            BitmapFontResource bmpFont = res as BitmapFontResource;

            if (res is BitmapFontResource)
            {
                Surface surf = new Surface(bmpFont.Image);

                impl = new BitmapFontImpl(surf, bmpFont.FontMetrics);
            }
            else
            {
                throw new AgateResourceException(string.Format(
                                                     "The resource {0} is of type {1} which cannot be used to construct a font.",
                                                     resourceName, res.GetType().Name));
            }
        }
Ejemplo n.º 2
0
        internal void SaveFont(string resourceFile, string fontName, string imageFile)
        {
            AgateResourceCollection resources;

            if (File.Exists(resourceFile))
            {
                resources = AgateResourceLoader.LoadResources(resourceFile);
            }
            else
            {
                resources = new AgateResourceCollection();
            }

            if (Path.IsPathRooted(resourceFile) == false)
            {
                resourceFile = Path.Combine(Directory.GetCurrentDirectory(), resourceFile);
            }

            string localImagePath;
            string dir = Path.GetDirectoryName(resourceFile);

            if (Path.IsPathRooted(imageFile) == false)
            {
                localImagePath = imageFile;
                imageFile      = Path.Combine(Path.GetDirectoryName(resourceFile), imageFile);
            }
            else
            {
                localImagePath = GetRelativePath(dir, imageFile);
            }

            SaveImage(imageFile);

            localImagePath = localImagePath.Replace(Path.DirectorySeparatorChar.ToString(), "/");

            BitmapFontResource res = new BitmapFontResource(fontName);

            res.Image       = localImagePath;
            res.FontMetrics = ((BitmapFontImpl)Font.Impl).FontMetrics.Clone();

            resources.Add(res);

            AgateResourceLoader.SaveResources(resources, resourceFile);
        }