public int sceFontGetCharGlyphImage_Clip(Font Font, ushort CharCode, ref GlyphImage GlyphImage, int ClipX,
                                                 int ClipY, int ClipWidth, int ClipHeight)
        {
            try
            {
                var Glyph        = Font.GetGlyph(CharCode);
                var CharInfo     = Font.GetCharInfo(CharCode);
                var Face         = Glyph.Face;
                var PixelFormat  = GlyphImage.PixelFormat;
                var Buffer       = Memory.PspAddressToPointerSafe(GlyphImage.Buffer);
                var BufferHeight = GlyphImage.BufferHeight;
                var BufferWidth  = GlyphImage.BufferWidth;
                var BytesPerLine = GlyphImage.BytesPerLine;
                var Position     = GlyphImage.Position;
                var GlyphBitmap  = Face.GetBitmap();
                var OutputBitmap = new FontBitmap((byte *)Buffer, PixelFormat, (int)BufferWidth, (int)BufferHeight,
                                                  BytesPerLine);

                Console.WriteLine(
                    "sceFontGetCharGlyphImage_Clip({0}, ({1}, {2})-({3}, {4}) : {5}) : {6}",
                    CharCode, ClipX, ClipY, ClipWidth, ClipHeight, PixelFormat, Position
                    );

                ClipWidth  = Math.Min(ClipWidth, BufferWidth - ClipX);
                ClipHeight = Math.Min(ClipHeight, BufferHeight - ClipY);

                ClipWidth  = Math.Min(ClipWidth, GlyphBitmap.Width - ClipX);
                ClipHeight = Math.Min(ClipHeight, GlyphBitmap.Height - ClipY);

                try
                {
                    for (int y = 0; y < ClipHeight; y++)
                    {
                        for (int x = 0; x < ClipWidth; x++)
                        {
                            //Console.WriteLine();
                            var Pixel = GlyphBitmap.GetPixel(x + ClipX, y + ClipY);
                            OutputBitmap.SetPixel(x + (int)Position.X, y + (int)Position.Y, new OutputPixel(Pixel));
                            //Console.Write(Pixel.R > 0x7F ? "X" : ".");
                            //OutputBitmap.SetPixel(x, y, new OutputPixel(Color.Red));
                        }
                        //Console.WriteLine("");
                    }
                }
                catch (Exception Exception)
                {
                    Console.Error.WriteLine(Exception);
                }

                //for (int n = 0; n < )
                //Console.Error.WriteLine("'{0}': {1}", (char)CharCode, Glyph);
                //throw (new NotImplementedException());
                return(0);
            }
            catch (Exception Exception)
            {
                Console.Error.WriteLine(Exception);
                return(-1);
            }
        }
Example #2
0
        public int BakeFontBitmap(float xScale, float yScale, char firstCodepoint,
            BakedChar[] characters, FontBitmap bitmap)
        {
            if (!bitmap.IsValid) { throw new ArgumentException("bitmap"); }
            if (characters == null) { throw new ArgumentNullException("characters"); }

            return stb_truetype.stbtt_BakeFontBitmap(ref _info, xScale, yScale,
                bitmap.StartPointer, bitmap.Width, bitmap.Height, bitmap.Stride,
                (int)firstCodepoint, characters.Length,
                new FakePtr<BakedChar>() { Array = characters });
        }
Example #3
0
        /// <summary>
        /// Gets an instance of <see cref="FontTexture"/>.
        /// </summary>
        /// <param name="fontBitmap"></param>
        /// <returns></returns>
        public static FontTexture GetFontTexture(this FontBitmap fontBitmap)
        {
            var bmp     = fontBitmap.GlyphBitmap;
            var texture = new Texture(
                TextureTarget.Texture2D,
                new TexImage2D(TexImage2D.Target.Texture2D, 0, GL.GL_RGBA, bmp.Width, bmp.Height, 0, GL.GL_BGRA, GL.GL_UNSIGNED_BYTE, new ImageDataProvider(bmp)));

            texture.Initialize();
            var result = new FontTexture();

            result.GlyphFont           = fontBitmap.GlyphFont;
            result.GlyphHeight         = fontBitmap.GlyphHeight;
            result.TextureSize         = fontBitmap.GlyphBitmap.Size;
            result.GlyphInfoDictionary = fontBitmap.GlyphInfoDictionary;
            result.TextureObj          = texture;
            return(result);
        }
Example #4
0
        /// <summary>
        /// Gets an instance of <see cref="FontTexture"/>.
        /// </summary>
        /// <param name="fontBitmap"></param>
        /// <param name="parameters"></param>
        /// <param name="mipmapFiltering"></param>
        /// <returns></returns>
        public static FontTexture GetFontTexture(this FontBitmap fontBitmap,
                                                 SamplerParameters parameters = null,
                                                 MipmapFilter mipmapFiltering = MipmapFilter.LinearMipmapLinear)
        {
            var texture = new Texture(
                TextureTarget.Texture2D,
                fontBitmap.GlyphBitmap,
                parameters, mipmapFiltering);

            texture.Initialize();
            var result = new FontTexture();

            result.GlyphFont           = fontBitmap.GlyphFont;
            result.GlyphHeight         = fontBitmap.GlyphHeight;
            result.TextureSize         = fontBitmap.GlyphBitmap.Size;
            result.GlyphInfoDictionary = fontBitmap.GlyphInfoDictionary;
            result.TextureObj          = texture;
            return(result);
        }
Example #5
0
        private void btnApply_Click(object sender, EventArgs e)
        {
            try
            {
                var font = this.fontBuilder1.GetFont();
                if (font != null)
                {
                    if (this.pictureBox1.Image != null)
                    {
                        this.pictureBox1.Image.Dispose();
                    }

                    string     charSet      = this.txtCharSet.Text;
                    bool       drawBoundary = this.chkDrawBoundary.Checked;
                    FontBitmap fontBitmap   = font.GetFontBitmap(charSet, drawBoundary);
                    fontBitmap.GlyphBitmap.Save("TestFontBitmap.bmp");
                    this.pictureBox1.Image = fontBitmap.GlyphBitmap;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), "Error");
            }
        }
        public void MakeGlyphBitmapSubpixel(int glyphIndex,
            float xScale, float yScale, float xShift, float yShift,
            FontBitmap bitmap)
        {
            if (bitmap.Buffer == null)
            {
                throw new ArgumentNullException("bitmap.Buffer");
            }

            stb_truetype.stbtt_MakeGlyphBitmapSubpixel(ref _info,
                bitmap.StartPointer, bitmap.Width, bitmap.Height, bitmap.Stride,
                xScale, yScale, xShift, yShift, glyphIndex);
        }
 public void MakeGlyphBitmap(int glyphIndex, float xScale, float yScale, FontBitmap bitmap)
 {
     MakeGlyphBitmapSubpixel(glyphIndex, xScale, yScale, 0, 0, bitmap);
 }
Example #8
0
 public void MakeCodepointBitmap(char codepoint, float xScale, float yScale,
                                 FontBitmap bitmap)
 {
     MakeGlyphBitmap(FindGlyphIndex(codepoint), xScale, yScale, bitmap);
 }
 public void MakeCodepointBitmap(char codepoint, float xScale, float yScale,
     FontBitmap bitmap)
 {
     MakeGlyphBitmap(FindGlyphIndex(codepoint), xScale, yScale, bitmap);
 }
Example #10
0
        // generates square textures ... minimalHeight can be used to crop if desired
        public FontBitmap BakeFontBitmap(float pixelHeight, char firstCodepoint,
            BakedChar[] characters, out int minimalHeight)
        {
            int size = 16;
            if (characters.Length == 0) { minimalHeight = 0; return new FontBitmap(0, 0); }

            while (true)
            {
                var bitmap = new FontBitmap(size, size);
                int result = BakeFontBitmap(pixelHeight, firstCodepoint, characters, bitmap);
                if (result > 0) { minimalHeight = result; return bitmap; }

                size *= 2;
            }
        }
Example #11
0
 public int BakeFontBitmap(float pixelHeight, char firstCodepoint,
     BakedChar[] characters, FontBitmap bitmap)
 {
     float scale = GetScaleForPixelHeight(pixelHeight);
     return BakeFontBitmap(scale, scale, firstCodepoint, characters, bitmap);
 }
Example #12
0
        public int sceFontGetCharGlyphImage_Clip(FontHandle FontHandle, ushort CharCode, ref GlyphImage GlyphImage, int ClipX, int ClipY, int ClipWidth, int ClipHeight)
        {
            try
            {
                var Font = Fonts.Get(FontHandle);
                var Glyph = Font.GetGlyph(CharCode);
                var CharInfo = Font.GetCharInfo(CharCode);
                var Face = Glyph.Face;
                var PixelFormat = GlyphImage.PixelFormat;
                var Buffer = PspMemory.PspAddressToPointerSafe(GlyphImage.Buffer);
                var BufferHeight = GlyphImage.BufferHeight;
                var BufferWidth = GlyphImage.BufferWidth;
                var BytesPerLine = GlyphImage.BytesPerLine;
                var Position = GlyphImage.Position;
                var GlyphBitmap = Face.GetBitmap();
                var OutputBitmap = new FontBitmap((byte*)Buffer, PixelFormat, (int)BufferWidth, (int)BufferHeight, BytesPerLine);

                Console.WriteLine(
                    "sceFontGetCharGlyphImage_Clip({0}, ({1}, {2})-({3}, {4}) : {5}) : {6}",
                    CharCode, ClipX, ClipY, ClipWidth, ClipHeight, PixelFormat, Position
                );

                ClipWidth = Math.Min(ClipWidth, BufferWidth - ClipX);
                ClipHeight = Math.Min(ClipHeight, BufferHeight - ClipY);

                ClipWidth = Math.Min(ClipWidth, GlyphBitmap.Width - ClipX);
                ClipHeight = Math.Min(ClipHeight, GlyphBitmap.Height - ClipY);

                try
                {
                    for (int y = 0; y < ClipHeight; y++)
                    {
                        for (int x = 0; x < ClipWidth; x++)
                        {
                            //Console.WriteLine();
                            var Pixel = GlyphBitmap.GetPixel(x + ClipX, y + ClipY);
                            OutputBitmap.SetPixel(x + (int)Position.X, y + (int)Position.Y, new OutputPixel(Pixel));
                            //Console.Write(Pixel.R > 0x7F ? "X" : ".");
                            //OutputBitmap.SetPixel(x, y, new OutputPixel(Color.Red));
                        }
                        //Console.WriteLine("");
                    }
                }
                catch (Exception Exception)
                {
                    Console.Error.WriteLine(Exception);
                }

                //for (int n = 0; n < )
                //Console.Error.WriteLine("'{0}': {1}", (char)CharCode, Glyph);
                //throw (new NotImplementedException());
                return 0;
            }
            catch (Exception Exception)
            {
                Console.Error.WriteLine(Exception);
                return -1;
            }
        }