示例#1
0
        public static BitFont FromResource(string resourceName, int numChars, int codePage, int width, int height)
        {
            var font = new BitFont(numChars, width, height, codePage);

            font.Load(new BinaryReader(Assembly.GetCallingAssembly().GetManifestResourceStream(resourceName)));
            return(font);
        }
示例#2
0
        public void Load(Stream stream, int[] forceCodePage = null, bool isSystemFont = true)
        {
            FallbackCodePages = forceCodePage;
            var br         = new BinaryReader(stream);
            var headerSize = br.ReadInt16();

            /*var nextOffset =*/
            br.ReadInt32();
            var deviceType = br.ReadInt16();

            // must be 1
            FallbackCodePages = forceCodePage;

            /*var deviceName =*/
            br.ReadBytes(8);
            var codePage = br.ReadInt16();

            CodePage = codePage;
            /*var reserved =*/
            br.ReadBytes(6);
            /*var offset =*/
            br.ReadInt32();

            if (headerSize > 0x1C)
            {
                br.ReadBytes(0x1C - headerSize);
            }

            // CodePageInfoHeader
            //stream.Position = offset;
            /*var version =*/
            br.ReadInt16();
            var numFonts = br.ReadInt16();

            /*var size =*/
            br.ReadInt16();
            for (int i = 0; i < numFonts; i++)
            {
                if (deviceType == 1)
                {
                    // screen
                    var height = br.ReadByte();
                    var width  = br.ReadByte();
                    // should be 8
                    /*var yaspect =*/
                    br.ReadByte();
                    /*var xaspect =*/
                    br.ReadByte();
                    var numChars = br.ReadInt16();
                    var font     = new BitFont(numChars, width, height, CodePage);
                    font.ID                = string.Format("{0} {1}x{2}", codePage, width, height);
                    font.Name              = string.Format("CP {0} {1}x{2}", codePage, width, height);
                    font.IsSystemFont      = isSystemFont;
                    font.FallbackCodePages = forceCodePage;
                    font.FontSet           = this;
                    font.Load(br);
                    fonts.Add(font);
                }
                else if (deviceType == 2)
                {
                    // printer
                    throw new NotImplementedException();
                }
            }
            fonts.Sort((x, y) => x.Height.CompareTo(y.Height));
        }