Esempio n. 1
0
        public bool LoadData(string filename)
        {
            using (StreamReader fs = new StreamReader(filename, System.Text.Encoding.Default, false))
            {
                m_filename = filename;
                string content = fs.ReadToEnd();
                int    offset  = content.IndexOf("CHARS ");
                m_header = content.Substring(0, offset);
                string          patten  = @"((FONTBOUNDINGBOX)\s*(?<width>\d+)\s*(?<height>\d+)\s*)";
                Regex           buf     = new Regex(patten, RegexOptions.IgnoreCase);
                MatchCollection matches = buf.Matches(m_header);

                if (matches.Count == 1)
                {
                    m_width  = byte.Parse(matches[0].Groups["width"].Value);
                    m_height = byte.Parse(matches[0].Groups["height"].Value);
                }
                offset = content.IndexOf("STARTCHAR");
                bool loop = (offset != -1)? true: false;
                while (loop)
                {
                    int offset_next = content.IndexOf("STARTCHAR", offset + 16);
                    if (offset_next == -1)
                    {
                        loop        = false;
                        offset_next = content.IndexOf("ENDFONT", offset + 16);
                    }
                    FontBitmap fbmp = new FontBitmap(content.Substring(offset, offset_next - offset));
                    m_FontArray[fbmp.m_ch] = fbmp;
                    offset = offset_next;
                }
                return(true);
            }
        }
Esempio n. 2
0
        public void InsertFont(bool isLeft, FontBitmap fontBmp)
        {
            DataGridView dgv;

            if (isLeft)
            {
                dgv = dgvFontL;
            }
            else
            {
                dgv = dgvFontR;
            }

            {
                Bitmap   bmp     = new Bitmap((int)fontBmp.m_width, (int)fontBmp.m_height);
                Bitmap[] BmpRows = new Bitmap[16] {
                    bmp, bmp, bmp, bmp, bmp, bmp, bmp, bmp, bmp, bmp, bmp, bmp, bmp, bmp, bmp, bmp
                };
                for (int i = 0; i < dgv.Rows.Count; i++)
                {
                    if ((int)dgv.Rows[i].HeaderCell.Tag == fontBmp.m_ch >> 4)
                    {
                        dgv[fontBmp.m_ch % 16, i].Value = fontBmp.ToBitmap();
                        dgv[fontBmp.m_ch % 16, i].Tag   = fontBmp.m_ch;
                        break;
                    }
                    else if ((int)dgv.Rows[i].HeaderCell.Tag > fontBmp.m_ch >> 4 || i == dgv.Rows.Count - 1)
                    {
                        if ((int)dgv.Rows[i].HeaderCell.Tag > fontBmp.m_ch >> 4)
                        {
                            dgv.Rows.Insert(i, BmpRows);
                        }
                        else
                        {
                            dgv.Rows.Add(BmpRows);
                            i++;
                        }

                        for (int j = 0; j < 16; j++)
                        {
                            dgv[fontBmp.m_ch % 16, dgv.Rows.Count - 1].Tag = 0;
                        }
                        dgv.Rows[dgv.Rows.Count - 1].HeaderCell.Tag   = fontBmp.m_ch >> 4;
                        dgv.Rows[dgv.Rows.Count - 1].HeaderCell.Value = ((fontBmp.m_ch >> 4) << 4).ToString("X4");

                        dgv[fontBmp.m_ch % 16, i].Value = fontBmp.ToBitmap();
                        dgv[fontBmp.m_ch % 16, i].Tag   = fontBmp.m_ch;

                        break;
                    }
                }
            }
        }
Esempio n. 3
0
        public bool LoadData(sCustFontData custFontData)
        {
            RangeData rangeData = custFontData.pRangeDetails.pRangeData;

            byte[]   WidthArray   = custFontData.pWidthArray;
            byte[]   DWidthArray  = custFontData.pDWidthArray;
            UInt32[] OffsetArray  = custFontData.pOffsetArray;
            UInt16[] OffsetArrayC = custFontData.pOffsetArrayC;
            byte[]   DataArray    = custFontData.pDataArray;
            int      index        = 0;

            m_width  = custFontData.nWidth;
            m_height = custFontData.nHeight;

            if (DWidthArray == null)
            {
                DWidthArray = WidthArray;
            }
            if (custFontData.nEquiDistant == 0)
            {
                m_header = "STARTFONT 2.1\r\n" +
                           "FONTBOUNDINGBOX " + custFontData.nWidth + " " + custFontData.nHeight + " " + "0" + " " + "0" + "\r\n" +
                           "STARTPROPERTIES " + "2" + "\r\n" +
                           "FONT_ASCENT " + custFontData.nAscent + "\r\n" +
                           "FONT_DESCENT " + custFontData.nDescent + "\r\n" +
                           "ENDPROPERTIES" + "\r\n";   // +
                //"CHARS " + m_rangeData.m_chars + "\r\n";

                for (int i = 0; i < rangeData.m_rangeData.Length; i++)
                {
                    for (UInt16 j = rangeData.m_rangeData[i].nMin; j < rangeData.m_rangeData[i].nMax + 1; j++)
                    {
                        if (custFontData.nEquiDistant == 0)
                        {
                            FontBitmap fbmp = new FontBitmap(j, WidthArray[index], DWidthArray[index], custFontData.nHeight, index, DataArray, (UInt32)(OffsetArrayC[index]));
                            m_FontArray[fbmp.m_ch] = fbmp;
                        }
                        else
                        {
                            FontBitmap fbmp = new FontBitmap(j, custFontData.nWidth, custFontData.nWidth, custFontData.nHeight, index, DataArray, (UInt32)index * custFontData.nCharBytes);
                            m_FontArray[fbmp.m_ch] = fbmp;
                        }
                        index++;
                    }
                }
                return(true);
            }
            return(false);
            //temp += "ENDFONT" + "\r\n";
        }
Esempio n. 4
0
        private void btInsert_Click(object sender, EventArgs e)
        {
            Bitmap bmp = (Bitmap)pbBitmap.Image;

            if (bmp.Height != m_height)
            {
                MessageBox.Show("Different heights!");
                return;
            }
            string[] item = m_filename.Split('\\');
            m_fontBmp         = new FontBitmap(UInt16.Parse(item[item.Length - 1].Substring(0, item[item.Length - 1].IndexOf('.'))), bmp);
            this.DialogResult = System.Windows.Forms.DialogResult.OK;
            this.Close();
        }
Esempio n. 5
0
        private void btInsertR_Click(object sender, EventArgs e)
        {
            Bitmap bmp = (Bitmap)pbBitmap.Image;

            if (bmp.Height != m_bdfr.m_height)
            {
                MessageBox.Show("Different heights!");
                return;
            }

            FontBitmap fontBmp = new FontBitmap(Convert.ToUInt16(tbCode.Text, 16), bmp);

            if (m_bdfr.Insert(fontBmp))
            {
                InsertFont(false, fontBmp);
            }
        }
Esempio n. 6
0
 public bool Insert(FontBitmap bdf)
 {
     m_FontArray[bdf.m_ch] = bdf;
     return(true);
 }
Esempio n. 7
0
        public bool LoadData(string CustFontData, string RangeDataS, string Width, string DWidth, string Offset, string Data)
        {
            sCustFontData custFontData;
            RangeData     rangeData;
            ByteData      s_data;
            ByteData      width;
            ByteData      dWidth;
            UInt32Data    s_offset;
            int           index = 0;

            custFontData = new sCustFontData(CustFontData);
            rangeData    = new RangeData(RangeDataS);
            m_width      = custFontData.nWidth;
            m_height     = custFontData.nHeight;

            if (custFontData.nEquiDistant == 0)
            {
                if (Width == null || Width.Length <= 0)
                {
                    MessageBox.Show("Width can not be empty!");
                    return(false);
                }
                width = new ByteData(Width);
                if (DWidth != null && DWidth.Length > 0)
                {
                    dWidth = new ByteData(DWidth);
                }
                else
                {
                    dWidth = width;
                }
                if (dWidth.m_data.Length != width.m_data.Length)
                {
                    MessageBox.Show("Number of different Width & Dwidth!");
                    return(false);
                }
                s_offset = new UInt32Data(Offset);
                s_data   = new ByteData(Data);

                m_header = "STARTFONT 2.1\r\n" +
                           "FONTBOUNDINGBOX " + custFontData.nWidth + " " + custFontData.nHeight + " " + "0" + " " + "0" + "\r\n" +
                           "STARTPROPERTIES " + "2" + "\r\n" +
                           "FONT_ASCENT " + custFontData.nAscent + "\r\n" +
                           "FONT_DESCENT " + custFontData.nDescent + "\r\n" +
                           "ENDPROPERTIES" + "\r\n";   // +
                //"CHARS " + m_rangeData.m_chars + "\r\n";

                for (int i = 0; i < rangeData.m_rangeData.Length; i++)
                {
                    for (UInt16 j = rangeData.m_rangeData[i].nMin; j < rangeData.m_rangeData[i].nMax + 1; j++)
                    {
                        FontBitmap fbmp = new FontBitmap(j, width.m_data[index], dWidth.m_data[index], custFontData.nHeight, index, s_data.m_data, s_offset.m_data[index]);
                        m_FontArray[fbmp.m_ch] = fbmp;
                        index++;
                    }
                }
                return(true);
            }
            else
            {
                s_offset = new UInt32Data(Offset);
                s_data   = new ByteData(Data);

                m_header = "STARTFONT 2.1\r\n" +
                           "FONTBOUNDINGBOX " + custFontData.nWidth + " " + custFontData.nHeight + " " + "0" + " " + "0" + "\r\n" +
                           "STARTPROPERTIES " + "2" + "\r\n" +
                           "FONT_ASCENT " + custFontData.nAscent + "\r\n" +
                           "FONT_DESCENT " + custFontData.nDescent + "\r\n" +
                           "ENDPROPERTIES" + "\r\n";   // +
                //"CHARS " + m_rangeData.m_chars + "\r\n";

                for (int i = 0; i < rangeData.m_rangeData.Length; i++)
                {
                    for (UInt16 j = rangeData.m_rangeData[i].nMin; j < rangeData.m_rangeData[i].nMax + 1; j++)
                    {
                        FontBitmap fbmp = new FontBitmap(j, custFontData.nWidth, custFontData.nWidth, custFontData.nHeight, index, s_data.m_data, (uint)(s_offset.m_data[i] + (j - rangeData.m_rangeData[i].nMin) * ((custFontData.nWidth * custFontData.nHeight + 7) / 8)));
                        m_FontArray[fbmp.m_ch] = fbmp;
                        index++;
                    }
                }
                return(true);
            }
            return(false);
            //temp += "ENDFONT" + "\r\n";
        }