コード例 #1
0
        /// <summary>
        /// Load information about all fonts found in the cache's directories.
        /// </summary>
        public void Load()
        {
            _fonts     = new List <Font>();
            _fontFiles = new List <FontInfo>();

            //	Open all *.ttf and *.afm files in each of our font directories
            //	and test whether it's a font file. If it is a font file then read
            //	it and get its info. This doesn't load the font, it just
            //	reads some metadata.
            foreach (string dir in _fontDirectories)
            {
                //	True Type fonts
                string[] filenames = Directory.GetFiles(dir, "*.ttf");
                foreach (string filename in filenames)
                {
                    FontInfo info = TrueTypeFont.GetFontInfo(filename);
                    _fontFiles.Add(info);
                }

                //	Type 1 fonts
                filenames = Directory.GetFiles(dir, "*.afm");
                foreach (string filename in filenames)
                {
                    FontInfo info = Type1Font.GetFontInfo(filename);
                    _fontFiles.Add(info);
                }
            }
        }
コード例 #2
0
        public Type1Font(Demon.Font.Type1Font underlying)
        {
            _underlying = underlying;

            _descriptor = new FontDescriptor(
                _underlying.PostScriptName, _underlying.Flags, null,
                _underlying.ItalicAngle, _underlying.Ascender, _underlying.Descender,
                _underlying.CapHeight, _underlying.XAvgCharWidth, _underlying.AdvanceWidthMax,
                _underlying.WeightClass, _underlying.XHeight, 0,
                _underlying.BoundingBox);

            //	Underlying widths are reloaded during base.Load
            _widths = new FontWidths(_underlying.Widths);
        }
コード例 #3
0
        /// <summary>
        /// Load a named font, ready for use.
        /// </summary>
        public Font GetFont(string familyName, int weight, bool bold, bool italic, bool underline, bool strikeout)
        {
            //	If we already have this font then don't duplicate it
            Font font = null;

            foreach (Font candidate in _fonts)
            {
                if (candidate.FamilyName.ToLower() != familyName.ToLower())
                {
                    continue;
                }
                if (candidate.Bold != bold)
                {
                    continue;
                }
                if (candidate.Italic != italic)
                {
                    continue;
                }

                //	If we get here then we've got a match
                font = candidate;
                break;
            }
            if (font != null)
            {
                return(font);
            }

            //	Search our font directories for a file that implements
            //	the specified font
            FontInfo info = FindFont(familyName, weight, bold, italic, underline, strikeout);

            if (info == null)
            {
                string msg = "Font '" + familyName + "'";
                if (bold)
                {
                    msg += " bold";
                }
                if (italic)
                {
                    msg += " italic";
                }
                if (underline)
                {
                    msg += " underline";
                }
                if (strikeout)
                {
                    msg += " strikeout";
                }
                msg += " not found, and no substitute found either.";
                throw new Exception(msg);
            }

            //	Create the real font
            switch (info.Type)
            {
            case FontType.TrueType:
                font = new TrueTypeFont(info.FileName);
                break;

            case FontType.Type1:
                font = new Type1Font(info.FileName);
                break;
            }
            _fonts.Add(font);
            return(font);
        }