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 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;
            }
        }