コード例 #1
0
        // Gets a glyph from FntFile as Color32 array
        public static Color32[] GetGlyphColors(FntFile fntFile, int index, Color backColor, Color textColor, out Rect sizeOut)
        {
            // Get actual glyph rect
            sizeOut = new Rect(0, 0, fntFile.GetGlyphWidth(index), fntFile.FixedHeight);

            // Get glyph byte data as color array
            byte[]    data   = fntFile.GetGlyphPixels(index);
            Color32[] colors = new Color32[data.Length];
            for (int y = 0; y < FntFile.GlyphFixedDimension; y++)
            {
                for (int x = 0; x < FntFile.GlyphFixedDimension; x++)
                {
                    int pos = y * FntFile.GlyphFixedDimension + x;
                    if (data[pos] > 0)
                    {
                        colors[pos] = textColor;
                    }
                    else
                    {
                        colors[pos] = backColor;
                    }
                }
            }

            return(colors);
        }
コード例 #2
0
        // Gets proportial-width glyph data from FntFile as Color32 array
        public static Color32[] GetProportionalGlyphColors(FntFile fntFile, int index, Color backColor, Color textColor, bool invertY = false)
        {
            // Get actual glyph dimensions
            int width  = fntFile.GetGlyphWidth(index);
            int height = fntFile.FixedHeight;

            Color32[] colors = new Color32[width * height];

            // Get glyph byte data as color array
            byte[] data = fntFile.GetGlyphPixels(index);
            for (int y = 0; y < height; y++)
            {
                for (int x = 0; x < width; x++)
                {
                    int srcPos = y * FntFile.GlyphFixedDimension + x;
                    int dstPos = (invertY) ? (height - 1 - y) * width + x : y * width + x;
                    colors[dstPos] = (data[srcPos] > 0) ? textColor : backColor;
                }
            }

            return(colors);
        }