コード例 #1
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
        }