コード例 #1
0
ファイル: Painter.cs プロジェクト: ventor3000/guppy2
        private static GFNFont FindFont(string fontname)
        {
            GFNFont res = null;
            string  filename;

            if (string.IsNullOrEmpty(fontname))
            {
                filename = "ISOCP";
            }
            else if (fontname[0] == '*') //undecorate name that forces use of internal fonts
            {
                filename = fontname.Substring(1).ToUpper();
            }
            else
            {
                filename = fontname.ToUpper();    //seems good as is
            }
            //already loaded?
            if (loadedfonts.TryGetValue(filename, out res))
            {
                return(res);
            }

            //not loaded, try to load it now
            Stream fontstream = StreamUtils.FindResourceStream(filename + ".gfn");

            if (fontstream == null)
            {                            //the font was not found, recursivly use isocp
                if (filename == "ISOCP") //avoid infinite recursion
                {
                    throw new Exception("Fatal error: builtin font 'ISOCP' not found");
                }
                res = FindFont("ISOCP");

                //remember the non-existing name maps to isocp font for future reference
                loadedfonts[filename] = res;

                return(res);
            }

            res = GFNFont.FromStream(fontstream);
            fontstream.Close();
            loadedfonts[filename] = res;    //cache font for later use
            return(res);
        }
コード例 #2
0
ファイル: Painter.cs プロジェクト: ventor3000/guppy2
        public virtual Picture CreatePictureFromResource(string resname, Assembly asm)
        {
            Stream stream = StreamUtils.FindResourceStream(resname, asm);

            if (stream == null)
            {
                return(null);
            }



            /*//try to get resource with the actual name
             * Stream stream = asm.GetManifestResourceStream(resname);
             * if (stream == null)
             * {
             *  //get resource with some random namspace ending with the given name
             *  //this is good for Visual Studio express users, where resources are auto named
             *  string upname = "." + resname.ToUpper();
             *  foreach (string s in asm.GetManifestResourceNames())
             *  {
             *      if (s.ToUpper().EndsWith(upname))
             *      {
             *          stream = asm.GetManifestResourceStream(s);
             *          break;
             *      }
             *  }
             * }
             *
             * if (stream == null)
             *  return null;    //resource not found*/

            Picture res = null;

            try
            {
                res = CreatePictureFromStream(stream);
            }
            finally
            {
                stream.Close();
            }

            return(res);
        }