Example #1
0
 public static CodePageTable CopyFromFont(Mfe.Font font)
 {
     CodePageTable ret = new CodePageTable();
     for (int i = 0; i < Font.MaximumCodePoints; i++)
         ret.CodePoints[i] = font[i].Codepoint;
     ret.Name = font["Code Page"] ?? "<unspecified>";
     return ret;
 }
Example #2
0
 public void ApplyToFont(Mfe.Font font)
 {
     for (int i = 0; i < Font.MaximumCodePoints; i++)
     {
         font[i].Codepoint = CodePoints[i];
         font[i].Name = Names[i];
     }
     font["Code Page"] = Name;
 }
Example #3
0
        public static void ExportData(Mfe.Font font, string path)
        {
            StringBuilder data = new StringBuilder(8192);
            int shift, curByte;
            bool Inverted = font["Inverted"] == "true";
            data.Append("; FONT METADATA");
            foreach (KeyValuePair<string, string> s in font.AboutData)
            {
                data.Append("; ");
                data.Append(s.Key);
                data.Append(" = ");
                data.Append(s.Value);
                data.AppendLine();
            }
            data.AppendLine("; ");
            data.AppendLine("; FONT DATA");
            for (int i = 0; i < 256; i++)
            {
                shift = 0;
                curByte = 0;
                data.Append("; Char ");
                data.Append(i.ToString("X2"));
                data.Append(" ");
                if (i > 31)
                    data.Append((char)i);
                data.AppendLine();
                // Produce bytes
                for (int col = 0; col < font[i].Width; col++)
                    for (int row = 0; row < font[i].Height; row++)
                    {
                        if (font[i][row, col] ^ Inverted)
                            curByte |= 1 << shift++;
                        else
                            shift++;
                        if (shift > 7)
                        {
                            data.Append("\x9.db\x9");
                            data.Append(ToBinaryByte(curByte));
                            data.Append("b");
                            data.AppendLine();
                            shift = 0;
                            curByte = 0;
                        }
                    }
                if (shift != 0)
                {
                    data.Append("\x9.db\x9");
                    data.Append(ToBinaryByte(curByte));
                    data.Append("b");
                    data.AppendLine();
                }
            }

            System.IO.File.WriteAllText(path, data.ToString());
        }
Example #4
0
 public static void ExportData(Mfe.Font font, string path)
 {
     // Check to make sure the font even looks approximately compatible
     if (font.VariableWidth)
         throw new ArgumentException("Omnicalc does not support variable width Fonts.");
     if (!(font.Width == 8 || font.Width == 6 || font.Width == 5))
         throw new ArgumentException("Invalid font width for Omnicalc.");
     if (font.Height != 7)
         throw new ArgumentException("Omnicalc fonts must be 7 pixels high.");
     // First, we're going to stuff all the data we want to export into
     // an array.  Then, we'll use the program class to package the data
     // into a valid program file and return it to the caller.
     byte[] data = new byte[256 * 7 + 8];
     // Master pointer
     int i = 0;
     // Create file header
     string headerData = "omnicalc";
     for (int a = 0; a < headerData.Length; a++)
         data[i++] = (byte)headerData[a];
     // Add font glyphs
     // Char: 01234567
     // Omni: 76543210
     int temp;
     for (int ch = 0; ch < 256; ch++)
     {
         for (int row = 0; row < font.Height; row++)
         {
             temp = 0;
             for (int col = 0; col < font.Width; col++)
                 if (font[ch][row, col])
                     temp = temp | (1 << (5 - col));
             data[i++] = (byte)temp;
         }
     }
     // Now package the data into a program variable.
     Program prgm = new Program();
     prgm.Type = VariableType.ProtProgObj;
     prgm.Data = data;
     System.IO.File.WriteAllBytes(path, prgm.Export(archived: true));
 }
Example #5
0
        public static void ExportData(Mfe.Font font, string path)
        {
            // Check to make sure that it is an exportable font.
            if (font.VariableWidth)
                throw new ArgumentException("Font must fixed-width.");
            if (font.Height != 6 || font.Width != 4)
                throw new ArgumentException("Font size must be 4x6.");
            // Strings in C# are immutable, so doing "xxx" + "yyy" + "zzz" will end up creating five strings.
            // StringBuilder solves this problem of excessive string allocation.
            // For best performance, this number should be a little larger than the estimated font size for.
            StringBuilder data = new StringBuilder(65536);
            // I dunno, maybe you want to invert the font?
            bool inverted = font["Inverted"] == "true";
            // Font header
            data.Append("; FONT METADATA");
            foreach (KeyValuePair<string, string> s in font.AboutData)
            {
                data.Append("; ");
                data.Append(s.Key);
                data.Append(" = ");
                data.Append(s.Value);
                data.AppendLine();
            }
            data.AppendLine("; ");
            data.AppendLine("; FONT DATA");
            // Iterate over codepoints
            for (int i = 0; i < 256; i++)
            {
                // Header for each character
                data.Append("; Char ");
                data.Append(i.ToString("X2"));
                data.Append(" ");
                data.Append(font[i].Codepoint.ToString());
                data.Append(" ");
                data.Append(font[i].Name);
                data.Append(" ");
                data.AppendLine();
                // Produce bytes
                for (int row = 0; row < font[i].Height; row += 2)
                {
                    Char ch = font[i];
                    // \x9 creates a tab character
                    data.Append("\x9.db\x9$");
                    // I could have used a loop, but this required less thinking.
                    data.Append((
                        (
                              (ch[row, 0] ? 1 << 7 : 0)
                            | (ch[row, 1] ? 1 << 6 : 0)
                            | (ch[row, 2] ? 1 << 5 : 0)
                            | (ch[row, 3] ? 1 << 4 : 0)
                            | (ch[row + 1, 0] ? 1 << 3 : 0)
                            | (ch[row + 1, 1] ? 1 << 2 : 0)
                            | (ch[row + 1, 2] ? 1 << 1 : 0)
                            | (ch[row + 1, 3] ? 1 : 0)
                        )
                        ^
                        (
                            inverted ? 0xFF : 0
                        )
                    ).ToString("X2")
                    );
                    data.AppendLine();
                }
            }

            System.IO.File.WriteAllText(path, data.ToString());
        }
 private static byte getNextByte(Mfe.Char ch, bool Inverted, ref int row, ref int col, out int remainingBits)
 {
     int b = 0;
     int shift = 0;
     remainingBits = ch.Width * ch.Height - col * ch.Height - row;
     int i;
     if (remainingBits > 8)
         i = 8;
     else
         i = remainingBits;
     while (i-- > 0)
     {
         if (ch[row, col] ^ Inverted)
             b |= 1 << shift++;
         else
             shift++;
         remainingBits--;
         row++;
         if (row >= ch.Height)
         {
             col++;
             row = 0;
         }
     }
     return (byte)b;
 }
        public static void ExportData(Mfe.Font font, string path)
        {
            StringBuilder data = new StringBuilder(65536);
            int row, col, remainder;
            bool Inverted = font["Inverted"] == "true";
            string baseName = font["AsmName"] ?? "font";
            int firstChar;
            int lastChar;
            if (!Int32.TryParse((font["FirstChar"] ?? "0"), out firstChar))
                firstChar = 0;
            if (!Int32.TryParse((font["LastChar"] ?? "255"), out lastChar))
                firstChar = 255;
            if (firstChar < 0)
                firstChar = 0;
            if (lastChar > 255)
                lastChar = 255;
            data.Append(baseName);
            data.AppendLine(":");
            data.AppendLine("; FONT METADATA");
            foreach (KeyValuePair<string, string> s in font.AboutData)
            {
                data.Append("; ");
                data.Append(s.Key);
                data.Append(" = ");
                data.Append(s.Value);
                data.AppendLine();
            }
            data.Append("\x9.db\x9");
            data.Append(font.Height);
            data.Append("\x9; font height");
            data.AppendLine();
            data.AppendLine("; ");
            data.AppendLine("; GLYPH WIDTH TABLE");
            data.Append(baseName);
            data.Append("WidthTable:");
            data.AppendLine();
            for (int i = firstChar; i <= lastChar; i++)
            {
                data.Append("\x9.db\x9");
                data.Append(font[i].Width);
                data.Append("\x9; ");
                data.Append(font[i].Codepoint);
                data.Append(" ");
                data.Append(font[i].Name);
                data.AppendLine();
            }
            data.AppendLine("; ");
            data.AppendLine("; GLYPH DATA TABLE");
            data.Append(baseName);
            data.Append("DataTable:");
            data.AppendLine();

            /*
            byte[] bytes = new byte[65536];
            int[] ptrs = new int[256];
            int ptr = (lastChar - firstChar) * 3 + 3;

            for (int i = firstChar; i <= lastChar; i++)
            {
                // Header
                bytes[(i - firstChar) * 3] = (byte)(ptr & 255);
                bytes[(i - firstChar) * 3 + 1] = (byte)((ptr >> 8) & 255);
                bytes[(i - firstChar) * 3 + 2] = (byte)((ptr >> 16) & 255);
                col = 0;
                row = 0;
                remainder = font[i].Width * font[i].Height;
                // Produce bitmap
                for (row = 0; row < font[i].Height; row++)
                {
                    for (col = 0; col < font[i].Width; col += 8)
                    {
                        int dataByte = 0;
                        for (int j = 0; j < 8; j++)
                            if (j + col < font[i].Width ^ Inverted)
                                if (font[i][row, col + j])
                                    dataByte = (dataByte << 1) | 1;
                                else
                                    dataByte <<= 1;
                        bytes[ptr++] = (byte)dataByte;
                    }
                }
            }

            int blah = 0;
            for (int i = 0; i < ptr; i++)
            {
                if (blah-- <= 1)
                {
                    data.AppendLine();
                    data.Append("\x9.db\x9");
                    blah = 8;
                }
                else
                    data.Append(", ");
                data.Append("0");
                data.Append(bytes[i].ToString("X2"));
                data.Append("h");
            }
            */

                for (int i = firstChar; i <= lastChar; i++)
                {
                    data.Append("\x9.dl\x9");
                    data.Append(baseName);
                    data.Append("Char");
                    data.Append(i.ToString("X2"));
                    data.Append(" - ");
                    data.Append(baseName);
                    data.Append("DataTable");
                    data.Append("\x9; ");
                    data.Append(font[i].Codepoint);
                    data.Append(" ");
                    data.Append(font[i].Name);
                    data.AppendLine();
                }
                data.AppendLine("; ");
                data.AppendLine("; GLYPH DATA");
                for (int i = firstChar; i <= lastChar; i++)
                {
                    // Header
                    data.Append(baseName);
                    data.Append("Char");
                    data.Append(i.ToString("X2"));
                    data.Append(": ; ");
                    data.Append(font[i].Codepoint);
                    data.Append(" ");
                    data.Append(font[i].Name);
                    data.AppendLine();
                    col = 0;
                    row = 0;
                    remainder = font[i].Width * font[i].Height;
                    // Produce bitmap
                    for (row = 0; row < font[i].Height; row++)
                    {
                        data.Append("\x9.db\x9");
                        for (col = 0; col < font[i].Width; col += 8)
                        {
                            if (col != 0)
                                data.Append(", ");
                            for (int j = 0; j < 8; j++)
                                if (j + col >= font[i].Width ^ Inverted)
                                    data.Append("0");
                                else
                                    if (font[i][row, col + j])
                                        data.Append("1");
                                    else
                                        data.Append("0");
                            data.Append("b");
                        }
                        data.AppendLine();
                    }
                }
                System.IO.File.WriteAllText(path, data.ToString());
        }
Example #8
0
        public static void ExportData(Mfe.Font font, string path)
        {
            StringBuilder data = new StringBuilder(65536);
            // I dunno, maybe you want to invert the font?
            bool inverted = font["Inverted"] == "true";
            // Font header
            data.AppendLine("; FONT METADATA");
            foreach (KeyValuePair<string, string> s in font.AboutData)
            {
                data.Append("; ");
                data.Append(s.Key);
                data.Append(" = ");
                data.Append(s.Value);
                data.AppendLine();
            }
            data.AppendLine("; ");
            data.AppendLine("; FONT DATA");
            data.AppendLine("; Height byte");
            data.Append("\x9.db\x9");
            data.Append(font.Height);
            data.AppendLine();
            Mfe.Char ch;
            int bytesPerLine;
            int temp;
            // Iterate over codepoints
            for (int i = 0; i < 256; i++)
            {
                // Header for each character
                ch = font[i];
                data.Append("; Char ");
                data.Append(i.ToString("X2"));
                data.Append(" ");
                data.Append(ch.Codepoint.ToString());
                data.Append(" ");
                data.Append(ch.Name);
                data.Append(" ");
                data.AppendLine();
                bytesPerLine = (ch.Width + 7) / 8;
                data.Append("\x9.db\x9");
                data.Append(ch.LogicalWidth);
                data.Append(" ; width");
                data.AppendLine();
                // Produce bytes
                if (bytesPerLine != 0)
                    for (int row = 0; row < ch.Height; row++)
                    {
                        data.Append("\x9.db\x9");
                        for (int bite = 0; bite < bytesPerLine; bite++)
                        {
                            temp = 0;
                            for (int bit = 0; bit < (bite != bytesPerLine - 1 ? 8 : ch.Width - bite * 8); bit++)
                            {
                                temp |= (ch[row, bite * 8 + bit] ^ inverted ? 1 : 0) << (7 - bit);
                            }
                            data.Append("$");
                            data.Append(temp.ToString("X2"));
                            if (bite != bytesPerLine - 1)
                                data.Append(", ");
                        }
                        data.AppendLine();
                    }
            }

            System.IO.File.WriteAllText(path, data.ToString());
        }
Example #9
0
 public static void ExportData(Mfe.Font font, string path)
 {
     StringBuilder data = new StringBuilder(65536);
     int row, col, remainder;
     bool Inverted = font["Inverted"] == "true";
     string baseName = font["AsmName"] ?? "font";
     int firstChar;
     int lastChar;
     if (!Int32.TryParse((font["FirstChar"] ?? "0"), out firstChar))
         firstChar = 0;
     if (!Int32.TryParse((font["LastChar"] ?? "255"), out lastChar))
         firstChar = 255;
     if (firstChar < 0)
         firstChar = 0;
     if (lastChar > 255)
         lastChar = 255;
     data.Append(baseName);
     data.AppendLine(":");
     data.AppendLine("; FONT METADATA");
     foreach (KeyValuePair<string, string> s in font.AboutData)
     {
         data.Append("; ");
         data.Append(s.Key);
         data.Append(" = ");
         data.Append(s.Value);
         data.AppendLine();
     }
     data.Append("\x9.db\x9");
     data.Append(font.Width);
     data.Append("\x9; font width");
     data.AppendLine();
     data.Append("\x9.db\x9");
     data.Append(font.Height);
     data.Append("\x9; font height");
     data.AppendLine();
     data.Append("\x9.db\x9((");
     data.Append(font.Width);
     data.Append(" + 7) >> 3) * ");
     data.Append(font.Height);
     data.Append("\x9; Bytes per character bitmap");
     data.AppendLine();
     data.AppendLine("; ");
     data.AppendLine("; GLYPH DATA TABLE");
     data.Append(baseName);
     data.Append("DataTable:");
     data.AppendLine();
     for (int i = firstChar; i <= lastChar; i++)
     {
         // Header
         data.Append("\x9; Code point ");
         data.Append(i.ToString("X2"));
         data.Append(" ");
         data.Append(font[i].Codepoint);
         data.Append(" ");
         data.Append(font[i].Name);
         data.AppendLine();
         col = 0;
         row = 0;
         remainder = font[i].Width * font[i].Height;
         // Produce bitmap
         for (row = 0; row < font[i].Height; row++)
         {
             data.Append("\x9.db\x9");
             for (col = 0; col < font[i].Width; col += 8)
             {
                 if (col != 0)
                     data.Append(", ");
                 for (int j = 0; j < 8; j++)
                     if (j + col >= font[i].Width ^ Inverted)
                         data.Append("0");
                     else
                         if (font[i][row, col + j])
                             data.Append("1");
                         else
                             data.Append("0");
                 data.Append("b");
             }
             data.AppendLine();
         }
     }
     System.IO.File.WriteAllText(path, data.ToString());
 }
 public static void ExportData(Mfe.Font font, string path)
 {
     StringBuilder data = new StringBuilder(65536);
     int row, col, remainder;
     bool Inverted = font["Inverted"] == "true";
     string baseName = font["AsmName"] ?? "font";
     data.Append(baseName);
     data.AppendLine(":");
     data.AppendLine("; FONT METADATA");
     foreach (KeyValuePair<string, string> s in font.AboutData)
     {
         data.Append("; ");
         data.Append(s.Key);
         data.Append(" = ");
         data.Append(s.Value);
         data.AppendLine();
     }
     data.Append("\x9.db\x9");
     data.Append(font.Height);
     data.Append("\x9; font height");
     data.AppendLine();
     data.AppendLine("; ");
     data.AppendLine("; GLYPH WIDTH TABLE");
     data.Append(baseName);
     data.Append("WidthTable:");
     data.AppendLine();
     for (int i = 0; i < 256; i++)
     {
         data.Append("\x9.db\x9");
         data.Append(font[i].Width);
         data.Append("\x9; ");
         data.Append(font[i].Codepoint);
         data.Append(" ");
         data.Append(font[i].Name);
         data.AppendLine();
     }
     data.AppendLine("; ");
     data.AppendLine("; GLYPH DATA TABLE");
     data.Append(baseName);
     data.Append("DataTable:");
     data.AppendLine();
     for (int i = 0; i < 256; i++)
     {
         data.Append("\x9.dw\x9");
         data.Append(baseName);
         data.Append("Char");
         data.Append(i.ToString("X2"));
         data.Append("\x9; ");
         data.Append(font[i].Codepoint);
         data.Append(" ");
         data.Append(font[i].Name);
         data.AppendLine();
     }
     data.AppendLine("; ");
     data.AppendLine("; GLYPH DATA");
     for (int i = 0; i < 256; i++)
     {
         // Header
         data.Append(baseName);
         data.Append("Char");
         data.Append(i.ToString("X2"));
         data.Append(": ; ");
         data.Append(font[i].Codepoint);
         data.Append(" ");
         data.Append(font[i].Name);
         data.AppendLine();
         col = 0;
         row = 0;
         remainder = font[i].Width * font[i].Height;
         // Number of bytes in glyph body
         data.Append("\x9.db\x9");
         if (remainder % 8 == 0)
             data.Append(remainder / 8 - 1);
         else
             data.Append(remainder / 8);
         data.Append(" ; body byte count");
         data.AppendLine();
         // Producy body bytes
         while (remainder > 8)
         {
             data.Append("\x9.db\x9");
             data.Append(ToBinaryByte(getNextByte(font[i], Inverted, ref row, ref col, out remainder)));
             data.Append("b");
             data.AppendLine();
         }
         // Number of bits in final byte
         data.Append("\x9.db\x9");
         data.Append(remainder);
         data.Append(" ; remaining bits in final byte");
         data.AppendLine();
         // Final byte
         data.Append("\x9.db\x9");
         data.Append(ToBinaryByte(getNextByte(font[i], Inverted, ref row, ref col, out remainder)));
         data.Append("b");
         data.AppendLine();
         if (remainder != 0)
         {
             //System.IO.File.WriteAllText(path, data.ToString());
             throw new Exception("Internal consistency error: expected remaining bits should have been zero, was " + remainder + " on char #" + i.ToString()
                 + " with col=" + col.ToString() + " and row=" + row.ToString());
         }
     }
     System.IO.File.WriteAllText(path, data.ToString());
 }