Ejemplo n.º 1
0
        /// <summary>
        /// Add one character to the List
        /// </summary>
        /// <param name="c">The character</param>
        /// <param name="fo">The FontOptimizer serving character bitmaps</param>
        /// <param name="target">Width target setting</param>
        /// <returns>The maxsize of all added characters</returns>
        public Size Add(Char c, FontOptimizer fo, FontOptimizer.WidthTarget target)
        {
            LetterBase l = m_letterFactory();
            Size       s = l.CreateChar(c, fo, target);

            MaxSize.Width  = Math.Max(MaxSize.Width, s.Width);
            MaxSize.Height = Math.Max(MaxSize.Height, s.Height);


            this.Add(l);
            m_sizeTable.Add(( Byte )s.Width);

            return(s);
        }
Ejemplo n.º 2
0
        private void SaveFontAs( )
        {
            if (FO == null)
            {
                return;
            }
            if (m_TotalChars <= 0)
            {
                return;
            }

            if (comFileFormat.SelectedItem == null)
            {
                return;
            }
            if (!m_FCchooser.ContainsKey(( String )comFileFormat.SelectedItem))
            {
                return;                                                 // ERROR exit
            }
            FC = m_FCchooser[( String )comFileFormat.SelectedItem](FO); // call the selected format instance factory

            String ret = "";

            FontOptimizer.WidthTarget widthTarget = FontOptimizer.WidthTarget.WT_None;
            if (rbTrimMono.Checked)
            {
                widthTarget = FontOptimizer.WidthTarget.WT_Mono;
            }
            else if (rbTrimMinimum.Checked)
            {
                widthTarget = FontOptimizer.WidthTarget.WT_Minimum;
            }

            ret = FC.FontFile(txFirstChar.Text[0], m_TotalChars, widthTarget);
            String fName = "";

            fName = FC.FontNameCreated + ".h";

            sfDlg.FileName         = fName;
            sfDlg.InitialDirectory = appSettings.SaveDirPath;
            if (sfDlg.ShowDialog(this) != DialogResult.Cancel)
            {
                using (TextWriter tw = new StreamWriter(sfDlg.FileName, false)) {
                    tw.Write(ret);
                    FO.MakeThumbnail(sfDlg.FileName);
                    txFontName.Text         = String.Format("File: {0} created, code size is {1} bytes", Path.GetFileName(sfDlg.FileName), FC.CodeSize);
                    appSettings.SaveDirPath = Path.GetDirectoryName(sfDlg.FileName); appSettings.Save( );
                }
            }
        }
Ejemplo n.º 3
0
            /// <summary>
            /// Character Digitizer
            ///   Creates the Byte stream for this character
            /// </summary>
            /// <param name="c">Character to digitize</param>
            /// <param name="fo">The FontOptimzer serving the bitmaps</param>
            /// <param name="target">Width target setting</param>
            /// <returns>The size of the created character</returns>
            public override Size CreateChar(Char c, FontOptimizer fo, FontOptimizer.WidthTarget target)
            {
                m_c = c;

                Bitmap fontImage = fo.GetMapForChar(c, target);

                // GET and ADD BITS...
                // from Top to bottom - then from left to right
                m_bytesPerCol = (fontImage.Height + 7) / 8; // get height in bytes

                for (int b = 0; b < m_bytesPerCol; b++)
                {
                    // per byte row
                    for (int x = 0; x < fontImage.Width; x++)
                    {
                        // left -> right

                        Byte col = 0;
                        Byte bit = 1; // paint bit moves from LSB to MSB in the y -loop

                        for (int y = b * 8; y < (b + 1) * 8; y++)
                        {
                            if (y < fontImage.Height)
                            {
                                // top -> down ??
                                Color pix = fontImage.GetPixel(x, y);
                                if (pix.R > FontOptimizer.BLANKTX) // red on black painting
                                {
                                    col |= bit;
                                }
                                bit <<= 1;
                            }
                            else
                            {
                                // catch overrun - but shift in (supposed bug in original must be retained...)
                                col <<= 1; // shift in
                            }
                        } // for y
                        this.Add(col);
                    } // for x
                }     // for b

                Size nS = fontImage.Size;

                fontImage.Dispose( );
                return(nS);
            }
Ejemplo n.º 4
0
 /// <summary>
 /// Creates a complete font file and returns it as String
 /// </summary>
 /// <param name="firstChar">The character to start with</param>
 /// <param name="charCount">The number of characters to include by inc. the Chars Ordinal (ASCII 7bit only)</param>
 /// <param name="widthTarget">Width target setting</param>
 /// <returns>The created font file as String</returns>
 abstract public String FontFile(Char firstChar, int charCount, FontOptimizer.WidthTarget widthTarget);
Ejemplo n.º 5
0
        /// <summary>
        /// Creates a complete font file and returns it as String
        /// </summary>
        /// <param name="firstChar">The character to start with</param>
        /// <param name="charCount">The number of characters to include by inc. the Chars Ordinal (ASCII 7bit only)</param>
        /// <param name="widthTarget">Width target setting</param>
        /// <returns>The created font file as String</returns>
        public override String FontFile(Char firstChar, int charCount, FontOptimizer.WidthTarget widthTarget)
        {
            String ret = "";

            // store args
            FirstChar = firstChar;
            CharCount = charCount;

            m_letters = new Letters(LetterFactory); // create font machine.. and submit the factory
            // create string
            int lastChar = Convert.ToChar(Convert.ToByte(FirstChar) + CharCount - 1);

            for (Char c = FirstChar; c <= lastChar; c++)
            {
                Size s = m_letters.Add(c, m_fo, widthTarget); // --> this will essentially capture all characters bits via Letter instance

                if (m_firstSize.Height == 0)
                {
                    m_firstSize = s;                        // collect size information - init in 1st round
                }
                Monospace = Monospace & (s == m_firstSize); // gets false if sizes are different
            }
            // final size from collected bit patterns
            Width  = m_letters.MaxSize.Width;
            Height = m_letters.MaxSize.Height;

            UInt16 totalSize = 6; // descriptor code size

            if (!Monospace)
            {
                totalSize += ( UInt16 )m_letters.SizeTable.Count;         // fixed fonts don't have a size table
            }
            totalSize += ( UInt16 )m_letters.CodeSize( );
            CodeSize   = totalSize;

            // start output
            FontNameCreated = ModName( );

            // create the file (collect all in one String)
            ret += Header( );
            // descriptor
            ret += Descriptor( );

            // code portion
            ret += CodeStart(totalSize);
            if (!Monospace)
            {
                ret += m_letters.SizeTable.GetBytes( );         // fixed fonts don't have a size table
            }
            // all font code now
            ret += m_letters.GetBytes( );
            // remove last comma from hex bytes
            int lc = ret.LastIndexOf(',');

            if (lc != -1)
            {
                ret = ret.Remove(lc, 1);
            }

            // write the code trailer
            ret += Trailer( );

            return(ret); // Done
        }
Ejemplo n.º 6
0
        protected Char m_c = '\0';  // the letter handled


        /// <summary>
        /// Character Digitizer
        ///   Creates the Byte stream for this character
        /// </summary>
        /// <param name="c">Character to digitize</param>
        /// <param name="fo">The FontOptimzer serving the bitmaps</param>
        /// <param name="target">Width target setting</param>
        /// <returns>The size of the created character</returns>
        abstract public Size CreateChar(Char c, FontOptimizer fo, FontOptimizer.WidthTarget target);