public void OnWait(WaitEventArgs args)
 {
     if (Wait != null)
     {
         Wait(this, args);
     }
 }
Beispiel #2
0
        public override void Load(Stream fs, CharacterDocument doc, CharacterHandler handler)
        {
            Page page = doc.Pages [0];

            BinaryReader br     = new BinaryReader(fs);
            Canvas       canvas = page.Canvas;
            Rectangle    rClip  = new Rectangle(0, 0, canvas.Width, canvas.Height);

            ResizeCanvasWidth(fs, doc, canvas);

            Point p = rClip.Location;

            try {
                br.ReadByte();                  // read version byte (unused)
                Palette pal = new Palette();
                pal.Load(br, 64, 0);

                /*
                 * TextWriter tw = new StreamWriter("c:\\blah.txt");
                 * for (int i=0; i<pal.Size; i++)
                 * tw.WriteLine("{0}, {1}, {2}", pal[i].R, pal[i].G, pal[i].B);
                 * tw.Close();
                 */

                page.Palette = Palette.FromEGA(pal);
                page.Font    = new BitFont(256, 8, 16, BitFont.StandardCodePage);
                page.Font.Load(br);

                WaitEventArgs args = new WaitEventArgs();
                while (true)
                {
                    p.X = rClip.Left;
                    for (int x = 0; x < 80; x++)
                    {
                        byte ch   = br.ReadByte();
                        byte attr = br.ReadByte();
                        doc.OnWait(args);
                        if (args.Exit)
                        {
                            break;
                        }
                        if (p.X <= rClip.InnerRight)
                        {
                            canvas [p.X - rClip.Left, p.Y] = new CanvasElement(ch, attr);
                        }
                        p.X++;
                    }
                    p.Y++;
                    if (p.Y > rClip.InnerBottom)
                    {
                        break;
                    }
                }
            } catch (EndOfStreamException) {
            }
            ResizeCanvasHeight(doc, canvas, p.Y + 1);
        }
Beispiel #3
0
            public void Load(Stream fs, Canvas canvas, Palette palette, WaitEventHandler onWait = null)
            {
                ansiLineWrap = null;
                var br = new BinaryReader(fs);

                this.canvas  = canvas;
                this.palette = palette;
                rClip        = new Rectangle(0, 0, canvas.Width, canvas.Height);
                attribute    = rgbAttribute = new Attribute(7, 0);
                ptCur        = rClip.Location;
                try
                {
                    var  args    = new WaitEventArgs();
                    byte curByte = br.ReadByte();
                    while (true)
                    {
                        if (onWait != null)
                        {
                            onWait(this, args);
                        }
                        if (args.Exit)
                        {
                            break;
                        }
                        if (curByte == 27)
                        {
                            curByte = br.ReadByte();
                            if (curByte == 91)
                            {
                                // Escape sequence found!  scan for parameter
                                ReadEscapeSequence(ref br);
                            }
                            else
                            {
                                ReadCurByte(27);
                                continue;
                            }
                        }
                        else
                        {
                            ReadCurByte(curByte);
                        }
                        curByte = br.ReadByte();
                    }
                }
                catch (EndOfStreamException)
                {
                    // end of stream, so we're finished
                }
                catch (CanvasOverflowException)
                {
                    // everything's still okay, just went over the limits of the canvas
                }
                // Console.WriteLine("Finished Loading!");
                br.Close();
            }
Beispiel #4
0
        public override void Load(Stream fs, CharacterDocument doc, CharacterHandler handler)
        {
            Page page = doc.Pages[0];

            BinaryReader br     = new BinaryReader(fs);
            Canvas       canvas = page.Canvas;

            ResizeCanvasWidth(fs, doc, canvas);
            Rectangle rClip = new Rectangle(0, 0, canvas.Width, canvas.Height);

            Point p = rClip.Location;

            try
            {
                //page.Palette = Palette.GetDefaultPalette ();
                //page.Font = BitFont.GetStandard8x16 ();

                CanvasElement ce = new CanvasElement(32, 7);
                p = rClip.Location;
                WaitEventArgs args = new WaitEventArgs();
                while (true)
                {
                    doc.OnWait(args);
                    if (args.Exit)
                    {
                        break;
                    }

                    ce.Character = br.ReadByte();
                    ce.Attribute = br.ReadByte();
                    if (p.X < canvas.Size.Width && p.Y < canvas.Size.Height)
                    {
                        canvas[p] = ce;
                    }
                    p.X++;
                    if (p.X > rClip.InnerRight)
                    {
                        p.X = rClip.Left;
                        p.Y++;
                        if (p.Y > rClip.InnerBottom)
                        {
                            canvas.ShiftUp();
                            p.Y = rClip.InnerBottom;
                        }
                    }
                }
            }
            catch (EndOfStreamException)
            {
            }
            ResizeCanvasHeight(doc, canvas, p.Y + 1);
        }
            public void OnWait(object sender, WaitEventArgs args)
            {
                if (quitThreadEvent.WaitOne(0, false))
                {
                    args.Exit = true;
                    //Console.WriteLine ("Quitting!");
                    //Thread.CurrentThread.Abort ();
                }

                //lock (this) if (stop) args.Exit = true;
                if (bs != null)
                {
                    bs.Wait();
                }
            }
Beispiel #6
0
 void f_WaitEvent(object sender, WaitEventArgs e)
 {
     if (e.Is_err)
     {
         MessageBox.Show("Ошибка.\n" + e.Message);
     }
     else
     {
         if (e.Message != "")
         {
             label2.Text = e.Message;
         }
         else
         {
             label2.Text = "Обработка...";
         }
         Application.DoEvents();
     }
 }
Beispiel #7
0
        public override void Load(Stream fs, CharacterDocument document, CharacterHandler handler)
        {
            var page = document.Pages[0];

            var br = new BinaryReader(fs);

            try
            {
                var header = new XBinHeader(br);
                if (header.XBinID != XBinHeader.XBIN_ID)
                {
                    throw new FileLoadException("not a valid XBIN file");
                }
                var loadSize = new Size(0, 0);
                var canvas   = page.Canvas;
                document.ICEColours = header.NonBlink;
                ResizeCanvasWidth(fs, document, canvas, header);

                loadSize.Width  = (document.EditMode && header.Width > canvas.Size.Width) ? canvas.Size.Width : header.Width;
                loadSize.Height = (document.EditMode && header.Height > canvas.Size.Height) ? canvas.Size.Height : header.Height;

                if (header.Palette)
                {
                    page.Palette.Load(br, 16, 2);
                }

                if (header.Font)
                {
                    var f = new BitFont(header.Font512 ? 512 : 256, 8, header.FontSize, BitFont.StandardCodePage);
                    f.Load(br);
#if DEBUG
                    /* Used to save an XBIN font for use in PabloDraw
                     *
                     * Stream s = new FileStream("c:\\font.fnt", FileMode.Create);
                     * BinaryWriter bw = new BinaryWriter(s);
                     * f.Save(bw);
                     * bw.Close();
                     * s.Close();
                     * /*
                     */
#endif
                    page.Font = f;
                }

                ResizeCanvasHeight(document, canvas, loadSize.Height);

                var ce   = new CanvasElement(32, 7);
                var args = new WaitEventArgs();
                if (header.Compress)
                {
                    for (int y = 0; y < loadSize.Height; y++)
                    {
                        int x = 0;
                        while (x < header.Width)
                        {
                            document.OnWait(args);
                            if (args.Exit)
                            {
                                break;
                            }
                            int countbyte = br.ReadByte();
                            if (countbyte == -1)
                            {
                                break;
                            }
                            int runlength = (countbyte & 0x3F) + 1;
                            switch ((CompressionType)(countbyte & 0xc0))
                            {
                            case CompressionType.NoCompression:
                                while (runlength > 0)
                                {
                                    ce.Character = br.ReadByte();
                                    ce.Attribute = br.ReadByte();
                                    if (x < canvas.Size.Width)
                                    {
                                        canvas[x, y] = ce;
                                    }
                                    x++;
                                    runlength--;
                                }
                                break;

                            case CompressionType.Character:
                                ce.Character = br.ReadByte();
                                while (runlength > 0)
                                {
                                    ce.Attribute = br.ReadByte();
                                    if (x < canvas.Size.Width)
                                    {
                                        canvas[x, y] = ce;
                                    }
                                    x++;
                                    runlength--;
                                }
                                break;

                            case CompressionType.Attribute:
                                ce.Attribute = br.ReadByte();
                                while (runlength > 0)
                                {
                                    ce.Character = br.ReadByte();
                                    if (x < canvas.Size.Width)
                                    {
                                        canvas[x, y] = ce;
                                    }
                                    x++;
                                    runlength--;
                                }
                                break;

                            case CompressionType.Both:
                                ce.Character = br.ReadByte();
                                ce.Attribute = br.ReadByte();
                                while (runlength > 0)
                                {
                                    if (x < canvas.Size.Width)
                                    {
                                        canvas[x, y] = ce;
                                    }
                                    x++;
                                    runlength--;
                                }
                                break;
                            }
                        }
                    }
                }
                else
                {
                    for (int y = 0; y < loadSize.Height; y++)
                    {
                        for (int x = 0; x < header.Width; x++)
                        {
                            document.OnWait(args);
                            if (args.Exit)
                            {
                                break;
                            }
                            ce.Character = br.ReadByte();
                            ce.Attribute = br.ReadByte();
                            if (x < canvas.Size.Width)
                            {
                                canvas[x, y] = ce;
                            }
                        }
                    }
                }
            }
            catch (EndOfStreamException)
            {
                // reached end of file, so we're okay
            }
        }
Beispiel #8
0
        public override void Load(Stream fs, CharacterDocument document, CharacterHandler handler)
        {
            Page page = document.Pages[0];

            var br     = new BinaryReader(fs);
            var canvas = page.Canvas;

            ResizeCanvasWidth(fs, document, canvas);
            var rClip = new Rectangle(0, 0, canvas.Width, canvas.Height);

            Point p = rClip.Location;

            try
            {
                page.Palette = GetCGPalette();
                page.Font    = GetCGLowerFont();
                bool rvson = false;

                var ce = new CanvasElement(32, 7);
                p = rClip.Location;
                var args = new WaitEventArgs();
                while (true)
                {
                    document.OnWait(args);
                    if (args.Exit)
                    {
                        break;
                    }
                    byte b = br.ReadByte();
                    switch (b)
                    {
                    case 0:
                        break;

                    case 1:
                        break;

                    case 2:
                        break;

                    case 3:
                        break;

                    case 4:
                        break;

                    case 5:
                        ce.Attribute = 1;
                        break;

                    case 6:
                        break;

                    case 7:
                        break;

                    case 8:
                        break;

                    case 9:
                        break;

                    case 10:
                        break;

                    case 11:
                        break;

                    case 12:
                        break;

                    case 14:                             // shift out
                        page.Font = GetCGLowerFont();
                        break;

                    case 15:
                        break;

                    case 16:
                        break;

                    case 17:
                        p.Y++;
                        break;

                    case 18:
                        rvson = true;
                        break;                                 //inv

                    case 19:
                        p.X = rClip.Left;                                    //home
                        p.Y = rClip.Top;
                        break;

                    case 20:
                        if (p.X > rClip.Left)
                        {
                            p.X--;
                            ce.Character = 32;
                            canvas.DeleteCharacter(p.X, p.Y, ce);
                        }
                        else if (p.Y > rClip.Top)
                        {
                            p.X = rClip.InnerRight;
                            p.Y--;
                            ce.Character = 32;
                            canvas[p]    = ce;
                        }
                        break;

                    case 21:
                        break;

                    case 22:
                        break;

                    case 23:
                        break;

                    case 24:
                        break;

                    case 25:
                        break;

                    case 26:
                        break;

                    case 27:
                        break;

                    case 28:
                        ce.Attribute = 2;
                        break;

                    case 29:
                        p.X++;
                        if (p.X > rClip.InnerRight)
                        {
                            p.X = rClip.Left;
                            p.Y++;
                        }
                        break;

                    case 30:
                        ce.Attribute = 5;
                        break;

                    case 31:
                        ce.Attribute = 6;
                        break;

                    case 128:
                        break;

                    case 130:
                        break;

                    case 131:
                        break;

                    case 132:
                        break;

                    case 133:
                        break;

                    case 134:
                        break;

                    case 135:
                        break;

                    case 136:
                        break;

                    case 137:
                        break;

                    case 138:
                        break;

                    case 139:
                        break;

                    case 140:
                        break;

                    case 13:
                    case 141:
                        p.Y++;
                        rvson = false;
                        p.X   = rClip.Left;
                        break;

                    case 142:                             // shift in
                        page.Font = GetCGUpperFont();
                        break;

                    case 143:
                        break;

                    case 144:                              // black
                        ce.Attribute = 0;
                        break;

                    case 145:                              // cursor up
                        if (p.Y > rClip.Top)
                        {
                            p.Y--;
                        }
                        break;

                    case 146:                                 //rvs off
                        rvson = false;
                        break;

                    case 147:                                 //clear home
                        p.X = rClip.Left;
                        p.Y = rClip.Top;
                        canvas.Fill(rClip, new CanvasElement(32, 7));
                        break;

                    case 148:                                 //shift delete
                        ce.Character = 32;
                        canvas.InsertCharacter(p.X, p.Y, ce);
                        break;

                    case 158:
                        ce.Attribute = 7;
                        break;

                    case 159:
                        ce.Attribute = 3;
                        break;

                    case 156:
                        ce.Attribute = 4;
                        break;

                    case 129:
                        ce.Attribute = 8;
                        break;

                    case 149:
                        ce.Attribute = 9;
                        break;

                    case 150:
                        ce.Attribute = 10;
                        break;

                    case 151:
                        ce.Attribute = 11;
                        break;

                    case 152:
                        ce.Attribute = 12;
                        break;

                    case 153:
                        ce.Attribute = 13;
                        break;

                    case 154:
                        ce.Attribute = 14;
                        break;

                    case 155:
                        ce.Attribute = 15;
                        break;

                    case 157:
                        if (p.X > rClip.Left)
                        {
                            p.X--;
                        }
                        else if (p.Y > rClip.Top)
                        {
                            p.X = rClip.InnerRight;
                            p.Y--;
                        }
                        break;

                    default:
                        byte pcode = Pet2Screen[b];
                        if (rvson)
                        {
                            pcode += 128;
                        }
                        ce.Character = pcode;
                        if (p.X < canvas.Size.Width && p.Y < canvas.Size.Height)
                        {
                            canvas[p] = ce;
                        }
                        p.X++;
                        if (p.X > rClip.InnerRight)
                        {
                            p.X = rClip.Left;
                            p.Y++;
                        }
                        break;
                    }

                    while (p.Y > rClip.InnerBottom)
                    {
                        p.Y--;
                        canvas.ShiftUp();
                    }
                }
            }
            catch (EndOfStreamException)
            {
            }
            ResizeCanvasHeight(document, canvas, p.Y + 1);
        }
        /// <summary>
        /// Runner of the dispatch thread.
        /// </summary>
        private void Run()
        {
            var fireWait = true;

            while (!stop)
            {
                var           now           = DateTime.Now;
                Action        action        = null;
                WaitEventArgs waitEventArgs = null;
                lock (actionsLock)
                {
                    // Any delayed actions that should be run?
                    var firstDelayedAction = (delayedActions.Count > 0) ? delayedActions[0] : null;
                    if ((firstDelayedAction != null) && (firstDelayedAction.Time <= now))
                    {
                        action = delayedActions[0].Action;
                        delayedActions.RemoveAt(0);
                        fireWait = true;
                    }
                    else if (actions.Count > 0)
                    {
                        action = actions[0];
                        actions.RemoveAt(0);
                        fireWait = true;
                    }
                    else if (fireWait)
                    {
                        // Prepare to fire Wait event handler.
                        waitEventArgs = new WaitEventArgs()
                        {
                            DelayedActionCount = delayedActions.Count
                        };
                        fireWait = false;
                    }
                    else
                    {
                        // Wait a while.
                        var timeout = (firstDelayedAction != null)
                                          ? firstDelayedAction.Time.Subtract(now)
                                          : new TimeSpan(0, 1, 0, 0);
                        Monitor.Wait(actionsLock, timeout);
                    }
                }
                if (action != null)
                {
                    // Perform action
                    try
                    {
                        action();
                    }
                    catch (Exception ex)
                    {
                        log.LogException(LogLevel.Error, Strings.FailedToPerformAction, ex);
                    }
                }
                if (waitEventArgs != null)
                {
                    Wait.Fire(this, waitEventArgs);
                    waitEventArgs = null;
                }
            }
            thread = null;
        }
Beispiel #10
0
        public override void Load(Stream fs, CharacterDocument doc, CharacterHandler handler)
        {
            BinaryReader br   = new BinaryReader(fs);
            Page         page = doc.Pages[0];

            canvas = page.Canvas;
            ResizeCanvasWidth(fs, doc, canvas);
            rClip = new Rectangle(0, 0, canvas.Width, canvas.Height);
            attribute.Foreground = 7;
            attribute.Background = 0;
            ptCur = rClip.Location;
            try
            {
                WaitEventArgs args = new WaitEventArgs();
                while (true)
                {
                    doc.OnWait(args);
                    if (args.Exit)
                    {
                        break;
                    }
                    byte curByte = br.ReadByte();
                    switch (curByte)
                    {
                    case 10:
                        ptCur.Y++;
                        if (ptCur.Y > rClip.InnerBottom)
                        {
                            canvas.ShiftUp();
                            ptCur.Y = rClip.InnerBottom;
                            //throw new CanvasOverflowException();
                        }
                        ptCur.X = rClip.Left;
                        break;

                    case 13:
                        // supposed to move X to 0, but for unix file types, it is omitted
                        break;

                    case 12:
                        canvas.Fill(new CanvasElement(32, 7));
                        attribute.Foreground = 7;
                        attribute.Background = 0;
                        ptCur = rClip.Location;
                        break;

                    case 25:
                    {
                        byte ch    = br.ReadByte();
                        int  count = br.ReadByte();
                        for (int i = 0; i < count; i++)
                        {
                            ReadChar(ch);
                        }
                        break;
                    }

                    case 22:
                    {
                        switch (br.ReadByte())
                        {
                        case 1:
                            attribute = (byte)(br.ReadByte() & 0x7f);
                            break;

                        case 2:
                            attribute.Blink = true;
                            break;

                        case 3:
                            ptCur.Y--;
                            if (ptCur.Y < rClip.Top)
                            {
                                ptCur.Y = rClip.Top;
                            }
                            break;

                        case 4:
                            ptCur.Y++;
                            if (ptCur.Y > rClip.InnerBottom)
                            {
                                ptCur.Y = rClip.InnerBottom;
                            }
                            break;

                        case 5:
                            ptCur.X--;
                            if (ptCur.X < rClip.Left)
                            {
                                ptCur.X = rClip.Left;
                            }
                            break;

                        case 6:
                            ptCur.X++;
                            if (ptCur.X > rClip.InnerRight)
                            {
                                ptCur.X = rClip.InnerRight;
                            }
                            break;

                        case 7:
                            canvas.Fill(new Rectangle(ptCur, new Size(rClip.Width - ptCur.X, 1)), new CanvasElement(32, attribute));
                            break;

                        case 8:
                            ptCur.X = br.ReadByte() - 1;
                            ptCur.Y = br.ReadByte() - 1;
                            break;
                        }
                        break;
                    }

                    default:
                        ReadChar(curByte);
                        break;
                    }
                }
            }
            catch (EndOfStreamException)
            {
                // reached end of file, so we're okay
            }
            catch (CanvasOverflowException)
            {
                // everything's still okay, just went over the limits of the canvas
            }

            ResizeCanvasHeight(doc, canvas, ptCur.Y + 1);
        }
Beispiel #11
0
        public void Load(Stream stream, RipDocument document, RipHandler handler)
        {
            var reader   = new BinaryReader(stream);
            var commands = document.Commands;

            commands.Clear();
            bool lastEnableZoom = true;

            /*
             */
            if (document.AnimateView && Application.Instance != null)
            {
                document.BGI.DelayDraw = true;                 // for faster animation
                Application.Instance.Invoke(delegate {
                    //lastEnableZoom = handler.EnableZoom;
#if DESKTOP
                    handler.EnableZoom = false;
#endif
                });
            }

            try {
                var args = new WaitEventArgs();
                while (true)
                {
                    if (document.AnimateView)
                    {
                        document.OnWait(args);
                        if (args.Exit)
                        {
                            break;
                        }
                    }
                    byte b = reader.ReadRipByte();

                    /*
                     */
                    if (b == (byte)'|')
                    {
                        string op = ((char)reader.ReadRipByte()).ToString();
                        if (op == "1")
                        {
                            op += ((char)reader.ReadRipByte());
                        }
                        else if (op == "#")
                        {
                            break;                             // done reading rip!
                        }
                        var command = RipCommands.Create(op, document);
                        if (command != null)
                        {
                            command.Read(reader);
                            command.Apply();
                            if (command.Store)
                            {
                                commands.Add(command);
                            }
                        }
                    }

                    /*
                     */
                }
            } catch (EndOfStreamException) {
            } finally {
                if (document.AnimateView && Application.Instance != null)
                {
                    Application.Instance.Invoke(delegate {
                        if (document.AnimateView)
                        {
                            handler.EnableZoom = lastEnableZoom;
                        }
                    });
                }
            }
        }