Ejemplo n.º 1
0
        private void HandleControl(Common.Text.RTF.Parser.RTF rtf)
        {
            switch (rtf.Major)
            {
            case Major.Unicode: {
                switch (rtf.Minor)
                {
                case Minor.UnicodeCharBytes: {
                    _style.SkipWidth = rtf.Param;
                    break;
                }

                case Minor.UnicodeChar: {
                    FlushText(rtf, false);
                    _skipCount += _style.SkipWidth;
                    _line.Append((char)rtf.Param);
                    break;
                }
                }
                break;
            }

            case Major.Destination: {
                //					Console.Write("[Got Destination control {0}]", rtf.Minor);
                rtf.SkipGroup();
                break;
            }

            case Major.PictAttr:
                if (rtf.Picture != null && rtf.Picture.IsValid())
                {
                    //var line = document.GetLine (_cursorY);
                    //document.InsertPicture (line, 0, rtf.Picture);
                    _cursorX++;

                    FlushText(rtf, true);
                    rtf.Picture = null;
                }
                break;

            case Major.CharAttr: {
                FlushText(rtf, false);
                switch (rtf.Minor)
                {
                case Minor.ForeColor: {
                    var color = Color.GetColor(rtf, rtf.Param);
                    if (color != null)
                    {
                        if (color.Red == -1 && color.Green == -1 && color.Blue == -1)
                        {
                            this._style.Color = ForeColor;
                        }
                        else
                        {
                            this._style.Color = XD.Color.FromBytes((byte)color.Red, (byte)color.Green, (byte)color.Blue);
                        }
                    }

                    break;
                }

                case Minor.FontSize: {
                    this._style.FontSize = rtf.Param / 2;
                    break;
                }

                case Minor.FontNum: {
                    var font = Font.GetFont(rtf, rtf.Param);

                    if (font != null)
                    {
                        this._style.FontName = font.Name;
                    }
                    break;
                }

                case Minor.Plain: {
                    _style.SectionAttribute = SectionAttribute.Regular;
                    break;
                }

                case Minor.Bold: {
                    if (rtf.Param == Common.Text.RTF.Parser.RTF.NoParam)
                    {
                        _style.SectionAttribute |= SectionAttribute.Bold;
                    }
                    else
                    {
                        _style.SectionAttribute &= ~SectionAttribute.Bold;
                    }
                    break;
                }

                case Minor.Italic: {
                    if (rtf.Param == Common.Text.RTF.Parser.RTF.NoParam)
                    {
                        _style.SectionAttribute |= SectionAttribute.Italic;
                    }
                    else
                    {
                        _style.SectionAttribute &= ~SectionAttribute.Italic;
                    }
                    break;
                }

                case Minor.StrikeThru: {
                    if (rtf.Param == Common.Text.RTF.Parser.RTF.NoParam)
                    {
                        _style.SectionAttribute |= SectionAttribute.Strikeout;
                    }
                    else
                    {
                        _style.SectionAttribute &= ~SectionAttribute.Strikeout;
                    }
                    break;
                }

                case Minor.Underline: {
                    if (rtf.Param == Common.Text.RTF.Parser.RTF.NoParam)
                    {
                        _style.SectionAttribute |= SectionAttribute.Underline;
                    }
                    else
                    {
                        _style.SectionAttribute &= ~SectionAttribute.Underline;
                    }
                    break;
                }

                case Minor.SubScrShrink: {
                    if (rtf.Param == Common.Text.RTF.Parser.RTF.NoParam)
                    {
                        _style.SectionAttribute |= SectionAttribute.Subscript;
                    }
                    else
                    {
                        _style.SectionAttribute &= ~SectionAttribute.Subscript;
                    }
                    break;
                }

                case Minor.SuperScrShrink: {
                    if (rtf.Param == Common.Text.RTF.Parser.RTF.NoParam)
                    {
                        _style.SectionAttribute |= SectionAttribute.Superscript;
                    }
                    else
                    {
                        _style.SectionAttribute &= ~SectionAttribute.Superscript;
                    }
                    break;
                }

                case Minor.Invisible: {
                    _style.Visible = false;
                    break;
                }

                case Minor.NoUnderline: {
                    _style.SectionAttribute &= ~SectionAttribute.Underline;
                    break;
                }
                }
                break;
            }

            case Major.ParAttr: {
                switch (rtf.Minor)
                {
                case Minor.ParDef:
                    FlushText(rtf, false);
                    _style.ParLineLeftIndent = 0;
                    _style.Align             = Alignment.Start;
                    break;

                case Minor.LeftIndent:
                    _style.ParLineLeftIndent =
                        (int)(((float)rtf.Param / 1440.0F) * DpiX + 0.5F);
                    break;

                case Minor.QuadCenter:
                    FlushText(rtf, false);
                    _style.Align = Alignment.Center;
                    break;

                case Minor.QuadJust:
                    FlushText(rtf, false);
                    _style.Align = Alignment.Center;
                    break;

                case Minor.QuadLeft:
                    FlushText(rtf, false);
                    _style.Align = Alignment.Start;
                    break;

                case Minor.QuadRight:
                    FlushText(rtf, false);
                    _style.Align = Alignment.End;
                    break;
                }
                break;
            }

            case Major.SpecialChar: {
                //Console.Write("[Got SpecialChar control {0}]", rtf.Minor);
                SpecialChar(rtf);
                break;
            }
            }
        }