Example #1
0
 public LabelElement(UIScreen screen, byte[] palette, Fnt font, ushort x, ushort y)
     : base(screen, x, y)
 {
     this.Palette = palette;
     this.Font = font;
     calc_width = true;
 }
Example #2
0
			public MarkupPage (PageLocation loc, Fnt font, byte[] palette)
			{
				location = loc;
				lines = new List<string> ();
				fnt = font;
				pal = palette;
			}
Example #3
0
		public static Surface RenderGlyph (Fnt font, Glyph g, byte[] palette, int offset)
		{
			byte[] buf = new byte[g.Width * g.Height * 4];
			int i = 0;

			for (int y = g.Height - 1; y >= 0; y--) {
				for (int x = g.Width - 1; x >= 0; x--) {
					if (g.Bitmap[y,x] == 0)
						buf [i + 0] = 0;
					else if (g.Bitmap[y,x] == 1)
						buf [i + 0] = 255;
					else
						buf [i + 0] = 128;

					buf[i + 1] = palette[ (g.Bitmap[y,x] + offset) * 3 + 2];
					buf[i + 2] = palette[ (g.Bitmap[y,x] + offset) * 3 + 1];
					buf[i + 3] = palette[ (g.Bitmap[y,x] + offset) * 3 ];

					if (buf[i+1] == 252 && buf[i+2] == 0 && buf[i+3] == 252)
						buf[i + 0] = 0;

					i += 4;
				}
			}

			return CreateSurfaceFromRGBAData (buf, (ushort)g.Width, (ushort)g.Height, 32, g.Width * 4);
		}
Example #4
0
        public static Surface ComposeText(string text, Fnt font, byte[] palette, int width, int height,
						   int offset)
        {
            if (font == null)
                Console.WriteLine ("aiiiieeee");

            int i;
            /* create a run of text, for now ignoring any control codes in the string */
            StringBuilder run = new StringBuilder ();
            for (i = 0; i < text.Length; i ++)
                if (text[i] == 0x0a /* allow newlines */||
                    !Char.IsControl (text[i]))
                    run.Append (text[i]);

            string rs = run.ToString ();
            byte[] r = Encoding.ASCII.GetBytes (rs);

            int x, y;
            int text_height, text_width;

            /* measure the text first, optionally wrapping at width */
            text_width = text_height = 0;
            x = y = 0;

            for (i = 0; i < r.Length; i ++) {
                int glyph_width = 0;

                if (r[i] != 0x0a) /* newline */ {
                    if (r[i] == 0x20) /* space */
                        glyph_width = font.SpaceSize;
                    else {
                        Glyph g = font[r[i]-1];

                        glyph_width = g.Width + g.XOffset;
                    }
                }

                if (r[i] == 0x0a ||
                    (width != -1 && x + glyph_width > width)) {
                    if (x > text_width)
                        text_width = x;
                    x = 0;
                    text_height += font.LineSize;
                }

                x += glyph_width;
            }

            if (x > text_width)
                text_width = x;
            text_height += font.LineSize;

            Surface surf = new Surface (text_width, text_height);
            surf.TransparentColor = Color.Black;

            /* the draw it */
            x = y = 0;
            for (i = 0; i < r.Length; i ++) {
                int glyph_width = 0;
                Glyph g = null;

                if (r[i] != 0x0a) /* newline */ {
                    if (r[i] == 0x20)  /* space */{
                        glyph_width = font.SpaceSize;
                    }
                    else {
                        g = font[r[i]-1];
                        glyph_width = g.Width + g.XOffset;

                        Surface gs = RenderGlyph (font, g, palette, offset);
                        surf.Blit (gs, new Point (x, y + g.YOffset));
                    }
                }

                if (r[i] == 0x0a ||
                    x + glyph_width > text_width) {
                    x = 0;
                    y += font.LineSize;
                }

                x += glyph_width;
            }

            return surf;
        }
Example #5
0
 public static Surface ComposeText(string text, Fnt font, byte[] palette, int offset)
 {
     return ComposeText (text, font, palette, -1, -1, offset);
 }
        public byte[] Write()
        {
            MemoryStream       m  = new MemoryStream();
            EndianBinaryWriter er = new EndianBinaryWriter(m, Endianness.LittleEndian);

            //Header
            //skip the header, and write it afterwards
            er.BaseStream.Position = 16384;
            Header.HeaderSize      = (uint)er.BaseStream.Position;
            //MainRom
            Header.MainRomOffset = (uint)er.BaseStream.Position;
            Header.MainSize      = (uint)MainRom.Length;
            er.Write(MainRom, 0, MainRom.Length);
            //Static Footer
            if (StaticFooter != null)
            {
                StaticFooter.Write(er);
            }
            if (MainOvt.Length != 0)
            {
                while ((er.BaseStream.Position % 0x200) != 0)
                {
                    er.Write((byte)0);
                }
                //Main Ovt
                Header.MainOvtOffset = (uint)er.BaseStream.Position;
                Header.MainOvtSize   = (uint)MainOvt.Length * 0x20;
                foreach (var v in MainOvt)
                {
                    v.Write(er);
                }
                foreach (var v in MainOvt)
                {
                    while ((er.BaseStream.Position % 0x200) != 0)
                    {
                        er.Write((byte)0);
                    }
                    Fat[v.FileId].fileTop    = (uint)er.BaseStream.Position;
                    Fat[v.FileId].fileBottom = (uint)er.BaseStream.Position + (uint)FileData[v.FileId].Length;
                    er.Write(FileData[v.FileId], 0, FileData[v.FileId].Length);
                }
            }
            else
            {
                Header.MainOvtOffset = 0;
                Header.MainOvtSize   = 0;
            }
            while ((er.BaseStream.Position % 0x200) != 0)
            {
                er.Write((byte)0xFF);
            }
            //SubRom
            Header.SubRomOffset = (uint)er.BaseStream.Position;
            Header.SubSize      = (uint)SubRom.Length;
            er.Write(SubRom, 0, SubRom.Length);
            //I assume this works the same as the main ovt?
            if (SubOvt.Length != 0)
            {
                while ((er.BaseStream.Position % 0x200) != 0)
                {
                    er.Write((byte)0);
                }
                //Sub Ovt
                Header.SubOvtOffset = (uint)er.BaseStream.Position;
                Header.SubOvtSize   = (uint)SubOvt.Length * 0x20;
                foreach (var v in SubOvt)
                {
                    v.Write(er);
                }
                foreach (var v in SubOvt)
                {
                    while ((er.BaseStream.Position % 0x200) != 0)
                    {
                        er.Write((byte)0);
                    }
                    Fat[v.FileId].fileTop    = (uint)er.BaseStream.Position;
                    Fat[v.FileId].fileBottom = (uint)er.BaseStream.Position + (uint)FileData[v.FileId].Length;
                    er.Write(FileData[v.FileId], 0, FileData[v.FileId].Length);
                }
            }
            else
            {
                Header.SubOvtOffset = 0;
                Header.SubOvtSize   = 0;
            }
            while ((er.BaseStream.Position % 0x200) != 0)
            {
                er.Write((byte)0xFF);
            }
            //FNT
            Header.FntOffset = (uint)er.BaseStream.Position;
            Fnt.Write(er);
            Header.FntSize = (uint)er.BaseStream.Position - Header.FntOffset;
            while ((er.BaseStream.Position % 0x200) != 0)
            {
                er.Write((byte)0xFF);
            }
            //FAT
            Header.FatOffset = (uint)er.BaseStream.Position;
            Header.FatSize   = (uint)Fat.Length * 8;
            //Skip the fat, and write it after writing the data itself
            er.BaseStream.Position += Header.FatSize;
            //Banner
            if (Banner != null)
            {
                while ((er.BaseStream.Position % 0x200) != 0)
                {
                    er.Write((byte)0xFF);
                }
                Header.BannerOffset = (uint)er.BaseStream.Position;
                Banner.Write(er);
            }
            else
            {
                Header.BannerOffset = 0;
            }
            //Files
            for (int i = (int)(Header.MainOvtSize / 32 + Header.SubOvtSize / 32); i < FileData.Length; i++)
            {
                while ((er.BaseStream.Position % 0x200) != 0)
                {
                    er.Write((byte)0xFF);
                }
                Fat[i].fileTop    = (uint)er.BaseStream.Position;
                Fat[i].fileBottom = (uint)er.BaseStream.Position + (uint)FileData[i].Length;
                er.Write(FileData[i], 0, FileData[i].Length);
            }
            while ((er.BaseStream.Position % 4 /*0x200*/) != 0)
            {
                er.Write((byte)0);
            }
            long curpos = er.BaseStream.Position;

            Header.RomSize = (uint)er.BaseStream.Position;
            uint CapacitySize = Header.RomSize;

            CapacitySize |= CapacitySize >> 16;
            CapacitySize |= CapacitySize >> 8;
            CapacitySize |= CapacitySize >> 4;
            CapacitySize |= CapacitySize >> 2;
            CapacitySize |= CapacitySize >> 1;
            CapacitySize++;
            if (CapacitySize <= 0x20000)
            {
                CapacitySize = 0x20000;
            }
            int Capacity = -18;

            while (CapacitySize != 0)
            {
                CapacitySize >>= 1; Capacity++;
            }
            Header.DeviceSize = (byte)((Capacity < 0) ? 0 : Capacity);
            //RSA!
            if (RSASignature != null)
            {
                er.Write(RSASignature, 0, 0x88);
            }
            //Fat
            er.BaseStream.Position = Header.FatOffset;
            foreach (var v in Fat)
            {
                v.Write(er);
            }
            //Header
            er.BaseStream.Position = 0;
            Header.Write(er);
            byte[] result = m.ToArray();
            er.Close();
            return(result);
        }
Example #7
0
        public static Surface ComposeText(string text, Fnt font, byte[] palette, int width, int height,
                                          int offset)
        {
            if (font == null)
            {
                Console.WriteLine("aiiiieeee");
            }

            int i;
            /* create a run of text, for now ignoring any control codes in the string */
            StringBuilder run = new StringBuilder();

            for (i = 0; i < text.Length; i++)
            {
                if (text[i] == 0x0a /* allow newlines */ ||
                    !Char.IsControl(text[i]))
                {
                    run.Append(text[i]);
                }
            }

            string rs = run.ToString();

            byte[] r = Encoding.ASCII.GetBytes(rs);

            int x, y;
            int text_height, text_width;

            /* measure the text first, optionally wrapping at width */
            text_width = text_height = 0;
            x          = y = 0;

            for (i = 0; i < r.Length; i++)
            {
                int glyph_width = 0;

                if (r[i] != 0x0a)                 /* newline */
                {
                    if (r[i] == 0x20)             /* space */
                    {
                        glyph_width = font.SpaceSize;
                    }
                    else
                    {
                        Glyph g = font[r[i] - 1];

                        glyph_width = g.Width + g.XOffset;
                    }
                }

                if (r[i] == 0x0a ||
                    (width != -1 && x + glyph_width > width))
                {
                    if (x > text_width)
                    {
                        text_width = x;
                    }
                    x            = 0;
                    text_height += font.LineSize;
                }

                x += glyph_width;
            }

            if (x > text_width)
            {
                text_width = x;
            }
            text_height += font.LineSize;

            Surface surf = new Surface(text_width, text_height);

            surf.TransparentColor = Color.Black;

            /* the draw it */
            x = y = 0;
            for (i = 0; i < r.Length; i++)
            {
                int   glyph_width = 0;
                Glyph g           = null;

                if (r[i] != 0x0a)                 /* newline */
                {
                    if (r[i] == 0x20)             /* space */
                    {
                        glyph_width = font.SpaceSize;
                    }
                    else
                    {
                        g           = font[r[i] - 1];
                        glyph_width = g.Width + g.XOffset;

                        Surface gs = RenderGlyph(font, g, palette, offset);
                        surf.Blit(gs, new Point(x, y + g.YOffset));
                    }
                }

                if (r[i] == 0x0a ||
                    x + glyph_width > text_width)
                {
                    x  = 0;
                    y += font.LineSize;
                }

                x += glyph_width;
            }

            return(surf);
        }
Example #8
0
 public static Surface ComposeText(string text, Fnt font, byte[] palette, int offset)
 {
     return(ComposeText(text, font, palette, -1, -1, offset));
 }
Example #9
0
        public int formatString(RichTextBox rchTxt, String strPreBlanks)
        {
            if (bEnable)
            {
                rchTxt.AppendText("启用\r\n");

                if (!String.IsNullOrWhiteSpace(strCapLabelName))
                {
                    rchTxt.AppendText("题注名:" + strCapLabelName + "\r\n");

                    if (capPos == WdCaptionPosition.wdCaptionPositionBelow)
                    {
                        rchTxt.AppendText("居下\r\n");
                    }
                    else
                    {
                        rchTxt.AppendText("居上\r\n");
                    }

                    switch (align)
                    {
                    case WdParagraphAlignment.wdAlignParagraphLeft:
                        rchTxt.AppendText("左对齐\r\n");
                        break;

                    case WdParagraphAlignment.wdAlignParagraphRight:
                        rchTxt.AppendText("右对齐\r\n");
                        break;

                    case WdParagraphAlignment.wdAlignParagraphCenter:
                        rchTxt.AppendText("居中\r\n");
                        break;

                    default:
                        break;
                    }

                    if (!String.IsNullOrWhiteSpace(strPrefix))
                    {
                        rchTxt.AppendText("前缀文字:" + strPrefix + "\r\n");
                    }

                    if (bGetHeadingText)
                    {
                        rchTxt.AppendText("[取就近标题内容]\r\n");
                    }

                    if (bSnWhileSameHeadingText)
                    {
                        rchTxt.AppendText("[同标题则序号区分]\r\n");
                    }

                    if (!String.IsNullOrWhiteSpace(strPostfix))
                    {
                        rchTxt.AppendText("后缀文字:" + strPostfix + "\r\n");
                    }


                    Fnt.formatString(rchTxt, strPreBlanks);
                    ParaFmt.formatString(rchTxt, strPreBlanks);
                }
            }
            else
            {
                rchTxt.AppendText("停用\r\n");
            }

            return(0);
        }
Example #10
0
        protected override void ResourceLoader()
        {
            Console.WriteLine ("loading font palette");
            Stream palStream = (Stream)mpq.GetResource ("glue\\Palmm\\tFont.pcx");
            Pcx pcx = new Pcx ();
            pcx.ReadFromStream (palStream, -1, -1);

            pal = pcx.RgbData;

            Console.WriteLine ("loading font");
            fnt = GuiUtil.GetFonts(mpq)[3];

            Console.WriteLine ("loading markup");
            LoadMarkup ();

            /* set things up so we're ready to go */
            millisDelay = 4000;
            pageEnumerator = pages.GetEnumerator();
            AdvanceToNextPage ();
        }