Example #1
0
		//
		// Format includes:
		// Control:
		//   ^    Switch to big endian encoding
		//   _    Switch to little endian encoding
		//   %    Switch to host (native) encoding
		//   !    aligns the next data type to its natural boundary (for strings this is 4).
		//
		// Types:
		//   s    Int16
		//   S    UInt16
		//   i    Int32
		//   I    UInt32
		//   l    Int64
		//   L    UInt64
		//   f    float
		//   d    double
		//   b    byte
                //   c    1-byte signed character
                //   C    1-byte unsigned character
		//   z8   string encoded as UTF8 with 1-byte null terminator
		//   z6   string encoded as UTF16 with 2-byte null terminator
		//   z7   string encoded as UTF7 with 1-byte null terminator
		//   zb   string encoded as BigEndianUnicode with 2-byte null terminator
		//   z3   string encoded as UTF32 with 4-byte null terminator
		//   z4   string encoded as UTF32 big endian with 4-byte null terminator
		//   $8   string encoded as UTF8
		//   $6   string encoded as UTF16
		//   $7   string encoded as UTF7
		//   $b   string encoded as BigEndianUnicode
		//   $3   string encoded as UTF32
		//   $4   string encoded as UTF-32 big endian encoding
		//   x    null byte
		//
		// Repeats, these are prefixes:
		//   N    a number between 1 and 9, indicates a repeat count (process N items
		//        with the following datatype
		//   [N]  For numbers larger than 9, use brackets, for example [20]
		//   *    Repeat the next data type until the arguments are exhausted
		//
		static public byte [] Pack (string description, params object [] args)
		{
			int argn = 0;
			PackContext b = new PackContext ();
			b.conv = CopyConv;
			b.description = description;

			for (b.i = 0; b.i < description.Length; ){
				object oarg;

				if (argn < args.Length)
					oarg = args [argn];
				else {
					if (b.repeat != 0)
						break;
					
					oarg = null;
				}

				int save = b.i;
				
				if (PackOne (b, oarg)){
					argn++;
					if (b.repeat > 0){
						if (--b.repeat > 0)
							b.i = save;
						else
							b.i++;
					} else
						b.i++;
				} else
					b.i++;
			}
			return b.Get ();
		}
Example #2
0
        public static bool PackFontRangesRenderIntoRects(
            PackContext context,
            FontInfo info,
            float pixelFlatness,
            Span <byte> pixels,
            ReadOnlySpan <PackRange> ranges,
            Span <RPRect> rects)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            bool return_value  = true;
            int  old_h_over    = context.oversample.X;
            int  old_v_over    = context.oversample.Y;
            int  k             = 0;
            int  j             = 0;
            int  i             = 0;
            int  missing_glyph = -1;

            for (i = 0; i < ranges.Length; ++i)
            {
                Span <PackedChar> charData = ranges[i].chardata_for_range.Span;
                float             fh       = ranges[i].font_size;
                var scale = new Vector2(fh > 0
                    ? ScaleForPixelHeight(info, fh)
                    : ScaleForMappingEmToPixels(info, -fh));
                float recip_h = 0;
                float recip_v = 0;
                float sub_x   = 0;
                float sub_y   = 0;
                context.oversample.X = ranges[i].oversample_x;
                context.oversample.Y = ranges[i].oversample_y;
                recip_h = 1f / context.oversample.X;
                recip_v = 1f / context.oversample.Y;
                sub_x   = OversampleShift(context.oversample.X);
                sub_y   = OversampleShift(context.oversample.Y);

                for (j = 0; j < charData.Length; ++j)
                {
                    ref RPRect r = ref rects[k];
                    if (r.was_packed && r.w != 0 && r.h != 0)
                    {
                        int[]? codepointArray = ranges[i].array_of_unicode_codepoints;
                        int codepoint = codepointArray != null
                            ? codepointArray[j]
                            : ranges[i].first_unicode_codepoint_in_range + j;

                        int glyph = FindGlyphIndex(info, codepoint);
                        int pad   = context.padding;
                        r.x += pad;
                        r.y += pad;
                        r.w -= pad;
                        r.h -= pad;

                        var pixelSlice = pixels[(r.x + r.y * context.stride_in_bytes)..];
Example #3
0
        public static void PackSetSkipMissingCodepoints(PackContext context, bool skip)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            context.skip_missing = skip;
        }
Example #4
0
        public void Begin(int width, int height)
        {
            bitmapWidth  = width;
            bitmapHeight = height;
            _bitmap      = new byte[width * height];
            _context     = new PackContext();

            _context.stbtt_PackBegin(_bitmap, width, height, width, 1);

            _glyphs = new Dictionary <int, GlyphInfo>();
        }
        public void Test_BakePackedCodepoint()
        {
            #region Init
            string assemblyDir  = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
            string solution_dir = Path.GetDirectoryName(Path.GetDirectoryName(Path.GetDirectoryName(assemblyDir)));
            #endregion

            //Read ttf file into byte array
            byte[] ttfFileContent = File.ReadAllBytes(solution_dir + @"\FontSamples\Windsong.ttf");
            using (var ttf = new PinnedArray <byte>(ttfFileContent))
            {
                //get pointer of the ttf file content
                var ttf_buffer = ttf.Pointer;
                //Initialize fontinfo
                FontInfo font = new FontInfo();
                STBTrueType.InitFont(ref font, ttf_buffer, STBTrueType.GetFontOffsetForIndex(ttf_buffer, 0));
                //set bitmap size
                const int BITMAP_W = 512;
                const int BITMAP_H = 512;
                //allocate bitmap buffer
                byte[] bitmapBuffer = new byte[BITMAP_W * BITMAP_H];
                //Initialize a pack context
                PackContext pc = new PackContext();
                STBTrueType.PackBegin(ref pc, bitmapBuffer, BITMAP_W, BITMAP_H, 0, 1, IntPtr.Zero);
                //allocate packed char buffer
                PackedChar[] pdata = new PackedChar[256 * 2];
                using (var pin_pdata = new PinnedArray <PackedChar>(pdata))
                {
                    //get pointer of the pdata
                    var ptr_pdata = pin_pdata.Pointer;
                    //set pack ranges
                    PackRange[] ranges = new PackRange[2];
                    ranges[0].chardata_for_range          = ptr_pdata;
                    ranges[0].first_unicode_char_in_range = 32;
                    ranges[0].num_chars_in_range          = 95;
                    ranges[0].font_size                   = 20.0f;
                    ranges[1].chardata_for_range          = IntPtr.Add(ptr_pdata, 256 * Marshal.SizeOf(pdata[0]));
                    ranges[1].first_unicode_char_in_range = 0xa0;
                    ranges[1].num_chars_in_range          = 0x100 - 0xa0;
                    ranges[1].font_size                   = 20.0f;
                    //Bake bitmap
                    STBTrueType.PackFontRanges(ref pc, ttf_buffer, 0, ranges, 2);
                    //Clean up
                    STBTrueType.PackEnd(ref pc);
                }
                //output the bitmap to a text file
                WriteBitmapToFileAsText("testOuput.txt", BITMAP_H, BITMAP_W, bitmapBuffer);
                //Open the text file
                OpenFile("testOuput.txt");
            }
        }
Example #6
0
        public ItemController(PackContext context)
        {
            _context = context;

            if (_context.PackItems.Count() == 0)
            {
                // Create a new PackItem if collection is empty,
                // which means you can't delete all PackItem.
                _context.PackItems.Add(new PackItem {
                    Description = "Item1"
                });
                _context.SaveChanges();
            }
        }
        public void BeforeTest()
        {
            var builder = new DbContextOptionsBuilder <PackContext>();

            builder.EnableSensitiveDataLogging();
            builder.UseInMemoryDatabase("testpack");

            var context    = new PackContext(builder.Options);
            var repository = new PackRepository(context);

            this.controller = new(
                Mock.Of <ILogger <PacksController> >(),
                repository);
            Assert.IsNotNull(this.controller);
        }
Example #8
0
        public static void PackSetOversampling(PackContext context, IntPoint oversample)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            if (oversample.X <= 8)
            {
                context.oversample.X = oversample.X;
            }
            if (oversample.Y <= 8)
            {
                context.oversample.Y = oversample.Y;
            }
        }
Example #9
0
        public bool CreatePackedGlyphMap(string charactersToPack, int fontSize, int width, int height)
        {
            width  = 512;
            height = 512;
            var bitmapData = new byte[width * height];

            using (var ttf = new PinnedArray <byte>(_data))
            {
                //get pointer of the ttf file content
                var ttfBuffer = ttf.Pointer;

                //Begin pack
                PackContext pc = new PackContext();
                STBTrueType.PackBegin(ref pc, bitmapData, width, height, 0, 1, IntPtr.Zero);

                //Ref: https://github.com/nothings/stb/blob/bdef693b7cc89efb0c450b96a8ae4aecf27785c8/tests/test_truetype.c
                //allocate packed char buffer
                PackedCharData = new PackedChar[charactersToPack.Length];

                using (var pin_pdata = new PinnedArray <PackedChar>(PackedCharData))
                {
                    //get pointer of the pdata
                    var         ptr_pdata  = pin_pdata.Pointer;
                    PackRange[] vPackRange = new PackRange[charactersToPack.Length];
                    for (var i = 0; i < charactersToPack.Length; ++i)
                    {
                        //create a PackRange of one character
                        PackRange pr = new PackRange
                        {
                            chardata_for_range          = IntPtr.Add(ptr_pdata, i * Marshal.SizeOf(typeof(PackedChar))),
                            first_unicode_char_in_range = charactersToPack[i] & 0xFFFF,
                            num_chars_in_range          = 1,
                            font_size = fontSize
                        };
                        //add it to the range list
                        vPackRange[i] = pr;
                    }
                    //STBTrueType.PackSetOversampling(ref pc, 2, 2);
                    STBTrueType.PackFontRanges(ref pc, ttfBuffer, 0, vPackRange, vPackRange.Length);
                    STBTrueType.PackEnd(ref pc);
                }
            }

            PackedCharBitmap = CreateBitmapFromRawData(bitmapData, width, height);

            return(true);
        }
Example #10
0
        private byte[] CreateGlyph(string charactersToPack, ref int width, ref int height)
        {
            byte[] bitmapData = null;

            //Read ttf file into byte array
            byte[] ttfFileContent = File.ReadAllBytes(ttfSampleDir + '\\' + FontSelectorComboBox.SelectedItem as string);
            using (var ttf = new PinnedArray <byte>(ttfFileContent))
            {
                //get pointer of the ttf file content
                var ttf_buffer = ttf.Pointer;
                //Initialize fontinfo
                FontInfo font = new FontInfo();
                STBTrueType.InitFont(ref font, ttf_buffer, STBTrueType.GetFontOffsetForIndex(ttf_buffer, 0));
                PackContext pc = new PackContext();
                width      = 512;
                height     = 512;
                bitmapData = new byte[width * height];
                STBTrueType.PackBegin(ref pc, bitmapData, width, height, 0, 1, IntPtr.Zero);

                //Ref: https://github.com/nothings/stb/blob/bdef693b7cc89efb0c450b96a8ae4aecf27785c8/tests/test_truetype.c
                //allocate packed char buffer
                PackedChar[] pdata = new PackedChar[charactersToPack.Length];

                using (var pin_pdata = new PinnedArray <PackedChar>(pdata))
                {
                    //get pointer of the pdata
                    var         ptr_pdata  = pin_pdata.Pointer;
                    PackRange[] vPackRange = new PackRange[charactersToPack.Length];
                    for (var i = 0; i < charactersToPack.Length; ++i)
                    {
                        //create a PackRange of one character
                        PackRange pr = new PackRange();
                        pr.chardata_for_range          = IntPtr.Add(ptr_pdata, i * Marshal.SizeOf(typeof(PackedChar)));
                        pr.first_unicode_char_in_range = charactersToPack[i] & 0xFFFF;
                        pr.num_chars_in_range          = 1;
                        pr.font_size = pixelHeight;
                        //add it to the range list
                        vPackRange[i] = pr;
                    }
                    //STBTrueType.PackSetOversampling(ref pc, 2, 2);
                    STBTrueType.PackFontRanges(ref pc, ttf_buffer, 0, vPackRange, vPackRange.Length);
                    STBTrueType.PackEnd(ref pc);
                }
            }
            return(bitmapData);
        }
Example #11
0
        public static int PackPrepare(
            PackContext context, bool skipMissing, int pw, int ph, int byteStride, int padding)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            context.width           = pw;
            context.height          = ph;
            context.pack_info       = new RPContext();
            context.padding         = padding;
            context.stride_in_bytes = byteStride != 0 ? byteStride : pw;
            context.oversample.X    = 1;
            context.oversample.Y    = 1;
            context.skip_missing    = skipMissing;
            context.pack_info.Init(pw - padding, ph - padding);
            return(1);
        }
Example #12
0
        public ListController(PackContext context)
        {
            _context = context;

            if (_context.PackLists.Count() == 0)
            {
                // Create a new PackList if collection is empty,
                // which means you can't delete all PackList.
                PackList packList1 = new PackList {
                    Description = "List1"
                };
                packList1.PackItems.Add(new PackItem {
                    Description = "PackItem1ListItem1", Weight = 25, Volume = 30
                });
                packList1.PackItems.Add(new PackItem {
                    Description = "PackItem1ListItem2", Weight = 5, Volume = 10
                });

                _context.PackLists.Add(packList1);

                _context.SaveChanges();
            }
        }
Example #13
0
		static public byte [] PackEnumerable (string description, IEnumerable args)
		{
			PackContext b = new PackContext ();
			b.conv = CopyConv;
			b.description = description;
			
			IEnumerator enumerator = args.GetEnumerator ();
			bool ok = enumerator.MoveNext ();

			for (b.i = 0; b.i < description.Length; ){
				object oarg;

				if (ok)
					oarg = enumerator.Current;
				else {
					if (b.repeat != 0)
						break;
					oarg = null;
				}
						
				int save = b.i;
				
				if (PackOne (b, oarg)){
					ok = enumerator.MoveNext ();
					if (b.repeat > 0){
						if (--b.repeat > 0)
							b.i = save;
						else
							b.i++;
					} else
						b.i++;
				} else
					b.i++;
			}
			return b.Get ();
		}
Example #14
0
		//
		// Format includes:
		// Control:
		//   ^    Switch to big endian encoding
		//   _    Switch to little endian encoding
		//   %    Switch to host (native) encoding
		//   !    aligns the next data type to its natural boundary (for strings this is 4).
		//
		// Types:
		//   s    Int16
		//   S    UInt16
		//   i    Int32
		//   I    UInt32
		//   l    Int64
		//   L    UInt64
		//   f    float
		//   d    double
		//   b    byte
                //   c    1-byte signed character
                //   C    1-byte unsigned character
		//   z8   string encoded as UTF8 with 1-byte null terminator
		//   z6   string encoded as UTF16 with 2-byte null terminator
		//   z7   string encoded as UTF7 with 1-byte null terminator
		//   zb   string encoded as BigEndianUnicode with 2-byte null terminator
		//   z3   string encoded as UTF32 with 4-byte null terminator
		//   z4   string encoded as UTF32 big endian with 4-byte null terminator
		//   $8   string encoded as UTF8
		//   $6   string encoded as UTF16
		//   $7   string encoded as UTF7
		//   $b   string encoded as BigEndianUnicode
		//   $3   string encoded as UTF32
		//   $4   string encoded as UTF-32 big endian encoding
		//   x    null byte
		//
		// Repeats, these are prefixes:
		//   N    a number between 1 and 9, indicates a repeat count (process N items
		//        with the following datatype
		//   [N]  For numbers larger than 9, use brackets, for example [20]
		//   *    Repeat the next data type until the arguments are exhausted
		//
		static public byte [] Pack (string description, params object [] args)
		{
			int argn = 0;
			PackContext b = new PackContext ();
			b.conv = CopyConv;
			b.description = description;

			for (b.i = 0; b.i < description.Length; ){
				object oarg;

				if (argn < args.Length)
					oarg = args [argn];
				else {
					if (b.repeat != 0)
						break;
					
					oarg = null;
				}

				int save = b.i;
				
				if (PackOne (b, oarg)){
					argn++;
					if (b.repeat > 0){
						if (--b.repeat > 0)
							b.i = save;
						else
							b.i++;
					} else
						b.i++;
				} else
					b.i++;
			}
			return b.Get ();
		}
Example #15
0
 public VoitureRepository(PackContext context)
 {
     _context = context;
 }
Example #16
0
		static public byte [] PackEnumerable (string description, IEnumerable args)
		{
			PackContext b = new PackContext ();
			b.conv = CopyConv;
			b.description = description;
			
			IEnumerator enumerator = args.GetEnumerator ();
			bool ok = enumerator.MoveNext ();

			for (b.i = 0; b.i < description.Length; ){
				object oarg;

				if (ok)
					oarg = enumerator.Current;
				else {
					if (b.repeat != 0)
						break;
					oarg = null;
				}
						
				int save = b.i;
				
				if (PackOne (b, oarg)){
					ok = enumerator.MoveNext ();
					if (b.repeat > 0){
						if (--b.repeat > 0)
							b.i = save;
						else
							b.i++;
					} else
						b.i++;
				} else
					b.i++;
			}
			return b.Get ();
		}
Example #17
0
        //
        // Packs one datum `oarg' into the buffer `b', using the string format
        // in `description' at position `i'
        //
        // Returns: true if we must pick the next object from the list
        //
        private static bool PackOne(PackContext b, object oarg)
        {
            int n;

            switch (b.description[b.i])
            {
            case '^':
                b.conv = BigEndian;
                return(false);

            case '_':
                b.conv = LittleEndian;
                return(false);

            case '%':
                b.conv = Native;
                return(false);

            case '!':
                return(false);

            case 'x':
                b.Add(new byte[] { 0 });
                return(false);

            // Type Conversions
            case 'i':
                b.Add(b.conv.GetBytes(Convert.ToInt32(oarg)));
                break;

            case 'I':
                b.Add(b.conv.GetBytes(Convert.ToUInt32(oarg)));
                break;

            case 's':
                b.Add(b.conv.GetBytes(Convert.ToInt16(oarg)));
                break;

            case 'S':
                b.Add(b.conv.GetBytes(Convert.ToUInt16(oarg)));
                break;

            case 'l':
                b.Add(b.conv.GetBytes(Convert.ToInt64(oarg)));
                break;

            case 'L':
                b.Add(b.conv.GetBytes(Convert.ToUInt64(oarg)));
                break;

            case 'b':
                b.Add(new[] { Convert.ToByte(oarg) });
                break;

            case 'c':
                b.Add(new[] { (byte)(Convert.ToSByte(oarg)) });
                break;

            case 'C':
                b.Add(new[] { Convert.ToByte(oarg) });
                break;

            case 'A':
                b.Add(b.conv.GetBytes((byte[])oarg));
                break;

            // Repeat acount;
            case '1':
            case '2':
            case '3':
            case '4':
            case '5':
            case '6':
            case '7':
            case '8':
            case '9':
                b.repeat = ((short)b.description[b.i]) - ((short)'0');
                return(false);

            case '*':
                b.repeat = Int32.MaxValue;
                return(false);

            case '[':
                int count = -1, j;

                for (j = b.i + 1; j < b.description.Length; j++)
                {
                    if (b.description[j] == ']')
                    {
                        break;
                    }
                    n = ((short)b.description[j]) - ((short)'0');
                    if (n >= 0 && n <= 9)
                    {
                        if (count == -1)
                        {
                            count = n;
                        }
                        else
                        {
                            count = count * 10 + n;
                        }
                    }
                }
                if (count == -1)
                {
                    throw new ArgumentException("invalid size specification");
                }
                b.i      = j;
                b.repeat = count;
                return(false);

            case '$':
            case 'z':
                var add_null = b.description[b.i] == 'z';
                b.i++;
                if (b.i >= b.description.Length)
                {
                    throw new ArgumentException("$ description needs a type specified", "description");
                }
                char d = b.description[b.i];
                System.Text.Encoding e;

                switch (d)
                {
                case '8':
                    e = System.Text.Encoding.UTF8;
                    n = 1;
                    break;

                case '6':
                    e = System.Text.Encoding.Unicode;
                    n = 2;
                    break;

                case '7':
                    e = System.Text.Encoding.UTF7;
                    n = 1;
                    break;

                case 'b':
                    e = System.Text.Encoding.BigEndianUnicode;
                    n = 2;
                    break;

                case '3':
                    e = System.Text.Encoding.GetEncoding(12000);
                    n = 4;
                    break;

                case '4':
                    e = System.Text.Encoding.GetEncoding(12001);
                    n = 4;
                    break;

                default:
                    throw new ArgumentException("Invalid format for $ specifier", "description");
                }
                b.Add(e.GetBytes(Convert.ToString(oarg)));
                if (add_null)
                {
                    b.Add(new byte[n]);
                }
                break;

            default:
                throw new ArgumentException($"invalid format specified '{b.description[b.i]}'", "description");
            }
            return(true);
        }
Example #18
0
        private Bitmap CreateGlyphForText(string text, ref int width, ref int height)
        {
            byte[] bitmapData = null;
            Bitmap bmp        = new Bitmap(512, 512, PixelFormat.Format24bppRgb);

            //Read ttf file into byte array
            byte[] ttfFileContent = File.ReadAllBytes(ttfSampleDir + '\\' + FontSelectorComboBox.SelectedItem as string);
            using (var ttf = new PinnedArray <byte>(ttfFileContent))
            {
                //get pointer of the ttf file content
                var ttf_buffer = ttf.Pointer;
                //Initialize fontinfo
                FontInfo font = new FontInfo();
                STBTrueType.InitFont(ref font, ttf_buffer, STBTrueType.GetFontOffsetForIndex(ttf_buffer, 0));
            }

            //TODO build packed characters' bitmap for ASCII/Chinese/Japanse/Korean characters etc.

            PackContext pc = new PackContext();

            width      = 512;
            height     = 512;
            bitmapData = new byte[width * height];
            STBTrueType.PackBegin(ref pc, bitmapData, width, height, 0, 1, IntPtr.Zero);

            //Ref: https://github.com/nothings/stb/blob/bdef693b7cc89efb0c450b96a8ae4aecf27785c8/tests/test_truetype.c
            //allocate packed char buffer
            PackedChar[] pdata = new PackedChar[text.Length];

            using (var pin_pdata = new PinnedArray <PackedChar>(pdata))
            {
                //get pointer of the pdata
                var         ptr_pdata  = pin_pdata.Pointer;
                PackRange[] vPackRange = new PackRange[text.Length];
                for (var i = 0; i < text.Length; ++i)
                {
                    //create a PackRange of one character
                    PackRange pr = new PackRange();
                    pr.chardata_for_range          = IntPtr.Add(ptr_pdata, i * Marshal.SizeOf(typeof(PackedChar)));
                    pr.first_unicode_char_in_range = text[i] & 0xFFFF;
                    pr.num_chars_in_range          = 1;
                    pr.font_size = pixelHeight;
                    //add it to the range list
                    vPackRange[i] = pr;
                }
                STBTrueType.PackSetOversampling(ref pc, 2, 2);
                using (var ttf = new PinnedArray <byte>(ttfFileContent))
                {
                    //get pointer of the ttf file content
                    var ttf_buffer = ttf.Pointer;
                    STBTrueType.PackFontRanges(ref pc, ttf_buffer, 0, vPackRange, vPackRange.Length);
                }
                STBTrueType.PackEnd(ref pc);
            }
            var bitmapPackedCharacters = CreateBitmapFromRawData(bitmapData, width, height);

            //ref
            //https://github.com/nothings/stb/blob/bdef693b7cc89efb0c450b96a8ae4aecf27785c8/tests/oversample/main.c

            //Draw characters to a bitmap by order
            Graphics g = Graphics.FromImage(bmp);

            g.Clear(Color.White);
            float x = 0, y = 0;

            for (var i = 0; i < text.Length; ++i)
            {
                var         character = text[i];
                AlignedQuad aq;
                //get character bitmaps in packed bitmap
                STBTrueType.GetPackedQuad(pdata, width, height, i, ref x, ref y, out aq, 0);
#if DebugOutput
                Debug.WriteLine(i);
                Debug.WriteLine("x: {0}, y: {1}", x, y);
                Debug.WriteLine("src: left-top: ({0}, {1}), right-bottom: ({2}, {3})", aq.s0 * width, aq.t0 * height, aq.s1 * width, aq.t1 * height);
                Debug.WriteLine("dest: left-top: ({0}, {1}), right-bottom: ({2}, {3})", aq.x0, aq.y0, aq.x1, aq.y1);
#endif
                var rectSrc  = RectangleF.FromLTRB(aq.s0 * width, aq.t0 * height, aq.s1 * width, aq.t1 * height);
                var rectDest = RectangleF.FromLTRB(aq.x0, aq.y0, aq.x1, aq.y1);
                rectDest.Offset(x, y + pixelHeight);//ATTENTION! The offset of lineHeight(pixelHeight here) should be appended.
#if DebugOutput
                Debug.WriteLine("rectSrc {0}", rectSrc);
                Debug.WriteLine("rectDest {0}", rectDest);
#endif
                g.DrawImage(bitmapPackedCharacters, rectDest, rectSrc, GraphicsUnit.Pixel);
            }
            g.Flush();
            return(bmp);
        }
Example #19
0
		//
		// Packs one datum `oarg' into the buffer `b', using the string format
		// in `description' at position `i'
		//
		// Returns: true if we must pick the next object from the list
		//
		static bool PackOne (PackContext b, object oarg)
		{
			int n;
			
			switch (b.description [b.i]){
			case '^':
				b.conv = BigEndian;
				return false;
			case '_':
				b.conv = LittleEndian;
				return false;
			case '%':
				b.conv = Native;
				return false;

			case '!':
				b.align = -1;
				return false;
				
			case 'x':
				b.Add (new byte [] { 0 });
				return false;
				
				// Type Conversions
			case 'i':
				b.Add (b.conv.GetBytes (Convert.ToInt32 (oarg)));
				break;
				
			case 'I':
				b.Add (b.conv.GetBytes (Convert.ToUInt32 (oarg)));
				break;
				
			case 's':
				b.Add (b.conv.GetBytes (Convert.ToInt16 (oarg)));
				break;
				
			case 'S':
				b.Add (b.conv.GetBytes (Convert.ToUInt16 (oarg)));
				break;
				
			case 'l':
				b.Add (b.conv.GetBytes (Convert.ToInt64 (oarg)));
				break;
				
			case 'L':
				b.Add (b.conv.GetBytes (Convert.ToUInt64 (oarg)));
				break;
				
			case 'f':
				b.Add (b.conv.GetBytes (Convert.ToSingle (oarg)));
				break;
				
			case 'd':
				b.Add (b.conv.GetBytes (Convert.ToDouble (oarg)));
				break;
				
			case 'b':
				b.Add (new byte [] { Convert.ToByte (oarg) });
				break;

			case 'c':
				b.Add (new byte [] { (byte) (Convert.ToSByte (oarg)) });
				break;

			case 'C':
				b.Add (new byte [] { Convert.ToByte (oarg) });
				break;

				// Repeat acount;
			case '1': case '2': case '3': case '4': case '5':
			case '6': case '7': case '8': case '9':
				b.repeat = ((short) b.description [b.i]) - ((short) '0');
				return false;

			case '*':
				b.repeat = Int32.MaxValue;
				return false;
				
			case '[':
				int count = -1, j;
				
				for (j = b.i+1; j < b.description.Length; j++){
					if (b.description [j] == ']')
						break;
					n = ((short) b.description [j]) - ((short) '0');
					if (n >= 0 && n <= 9){
						if (count == -1)
							count = n;
						else
							count = count * 10 + n;
					}
				}
				if (count == -1)
					throw new ArgumentException ("invalid size specification");
				b.i = j;
				b.repeat = count;
				return false;
				
			case '$': case 'z':
				bool add_null = b.description [b.i] == 'z';
				b.i++;
				if (b.i >= b.description.Length)
					throw new ArgumentException ("$ description needs a type specified", "description");
				char d = b.description [b.i];
				Encoding e;
				
				switch (d){
				case '8':
					e = Encoding.UTF8;
					n = 1;
					break;
				case '6':
					e = Encoding.Unicode;
					n = 2;
					break;
				case '7':
					e = Encoding.UTF7;
					n = 1;
					break;
				case 'b':
					e = Encoding.BigEndianUnicode;
					n = 2;
					break;
				case '3':
					e = Encoding.GetEncoding (12000);
					n = 4;
					break;
				case '4':
					e = Encoding.GetEncoding (12001);
					n = 4;
					break;
					
				default:
					throw new ArgumentException ("Invalid format for $ specifier", "description");
				}
				if (b.align == -1)
					b.align = 4;
				b.Add (e.GetBytes (Convert.ToString (oarg)));
				if (add_null)
					b.Add (new byte [n]);
				break;
			default:
				throw new ArgumentException (String.Format ("invalid format specified `{0}'",
									    b.description [b.i]));
			}
			return true;
		}
Example #20
0
		//
		// Packs one datum `oarg' into the buffer `b', using the string format
		// in `description' at position `i'
		//
		// Returns: true if we must pick the next object from the list
		//
		static bool PackOne (PackContext b, object oarg)
		{
			int n;
			
			switch (b.description [b.i]){
			case '^':
				b.conv = BigEndian;
				return false;
			case '_':
				b.conv = LittleEndian;
				return false;
			case '%':
				b.conv = Native;
				return false;

			case '!':
				b.align = -1;
				return false;
				
			case 'x':
				b.Add (new byte [] { 0 });
				return false;
				
				// Type Conversions
			case 'i':
				b.Add (b.conv.GetBytes (Convert.ToInt32 (oarg)));
				break;
				
			case 'I':
				b.Add (b.conv.GetBytes (Convert.ToUInt32 (oarg)));
				break;
				
			case 's':
				b.Add (b.conv.GetBytes (Convert.ToInt16 (oarg)));
				break;
				
			case 'S':
				b.Add (b.conv.GetBytes (Convert.ToUInt16 (oarg)));
				break;
				
			case 'l':
				b.Add (b.conv.GetBytes (Convert.ToInt64 (oarg)));
				break;
				
			case 'L':
				b.Add (b.conv.GetBytes (Convert.ToUInt64 (oarg)));
				break;
				
			case 'f':
				b.Add (b.conv.GetBytes (Convert.ToSingle (oarg)));
				break;
				
			case 'd':
				b.Add (b.conv.GetBytes (Convert.ToDouble (oarg)));
				break;
				
			case 'b':
				b.Add (new byte [] { Convert.ToByte (oarg) });
				break;

			case 'c':
				b.Add (new byte [] { (byte) (Convert.ToSByte (oarg)) });
				break;

			case 'C':
				b.Add (new byte [] { Convert.ToByte (oarg) });
				break;

				// Repeat acount;
			case '1': case '2': case '3': case '4': case '5':
			case '6': case '7': case '8': case '9':
				b.repeat = ((short) b.description [b.i]) - ((short) '0');
				return false;

			case '*':
				b.repeat = Int32.MaxValue;
				return false;
				
			case '[':
				int count = -1, j;
				
				for (j = b.i+1; j < b.description.Length; j++){
					if (b.description [j] == ']')
						break;
					n = ((short) b.description [j]) - ((short) '0');
					if (n >= 0 && n <= 9){
						if (count == -1)
							count = n;
						else
							count = count * 10 + n;
					}
				}
				if (count == -1)
					throw new ArgumentException ("invalid size specification");
				b.i = j;
				b.repeat = count;
				return false;
				
			case '$': case 'z':
				bool add_null = b.description [b.i] == 'z';
				b.i++;
				if (b.i >= b.description.Length)
					throw new ArgumentException ("$ description needs a type specified", "description");
				char d = b.description [b.i];
				Encoding e;
				
				switch (d){
				case '8':
					e = Encoding.UTF8;
					n = 1;
					break;
				case '6':
					e = Encoding.Unicode;
					n = 2;
					break;
				case '7':
#if PCL
					e = Encoding.GetEncoding ("utf-7");
#else
					e = Encoding.UTF7;
#endif
					n = 1;
					break;
				case 'b':
					e = Encoding.BigEndianUnicode;
					n = 2;
					break;
				case '3':
#if PCL
					e = Encoding.GetEncoding ("utf-32");
#else
					e = Encoding.GetEncoding (12000);
#endif
					n = 4;
					break;
				case '4':
#if PCL
					e = Encoding.GetEncoding ("utf-32BE");
#else
					e = Encoding.GetEncoding (12001);
#endif
					n = 4;
					break;
					
				default:
					throw new ArgumentException ("Invalid format for $ specifier", "description");
				}
				if (b.align == -1)
					b.align = 4;
				b.Add (e.GetBytes (Convert.ToString (oarg)));
				if (add_null)
					b.Add (new byte [n]);
				break;
			default:
				throw new ArgumentException (String.Format ("invalid format specified `{0}'",
									    b.description [b.i]));
			}
			return true;
		}