Example #1
0
		public Test() {
			MemoryStream	stream;
			RTF		rtf;
			byte[]		buffer;

			text = new TextMap();
			TextMap.SetupStandardTable(text.Table);

			buffer = new byte[rtf_string.Length];
			for (int i = 0; i < buffer.Length; i++) {
				buffer[i] = (byte)rtf_string[i];
			}
			stream = new MemoryStream(buffer);
			rtf = new RTF(stream);

			skip_width = 0;
			skip_count = 0;

			rtf.ClassCallback[TokenClass.Text] = new ClassDelegate(HandleText);
			rtf.ClassCallback[TokenClass.Control] = new ClassDelegate(HandleControl);

			rtf.Read();

			stream.Close();
		}
Example #2
0
			private void HandleControl (RTF rtf)
			{
				switch (rtf.Major) {
				case Major.CharAttr:
					switch (rtf.Minor) {
					case Minor.Bold:
						text_buffer.Append (rtf.Param == RTF.NoParam ? "<b>" : "</b>");
						break;
					case Minor.Italic:
						text_buffer.Append (rtf.Param == RTF.NoParam ? "<i>" : "</i>");
						break;
					case Minor.StrikeThru:
						text_buffer.Append (rtf.Param == RTF.NoParam ? "<s>" : "</s>");
						break;
					}
					break;
			        case Major.SpecialChar:
					switch (rtf.Minor) {
					case Minor.Par:
						text_buffer.Append ("<p>");
						break;
					}
					break;
				}
			}
Example #3
0
        private void HandleOptDest(RTF rtf)
        {
            int group_levels = 1;

            while (true)
            {
                GetToken();

                // Here is where we should handle recognised optional
                // destinations.
                //
                // Handle a picture group
                //
                if (rtf.CheckCMM(TokenClass.Control, Major.Destination, Minor.Pict))
                {
                    ReadPictGroup(rtf);
                    return;
                }

                if (rtf.CheckCM(TokenClass.Group, Major.EndGroup))
                {
                    if ((--group_levels) == 0)
                    {
                        break;
                    }
                }

                if (rtf.CheckCM(TokenClass.Group, Major.BeginGroup))
                {
                    group_levels++;
                }
            }
        }
Example #4
0
			public RtfToHtml (RTF parser)
			{
				this.parser = parser;

				parser.ClassCallback [TokenClass.Text] = new ClassDelegate (HandleText);
				parser.ClassCallback [TokenClass.Control] = new ClassDelegate (HandleControl);

				text_buffer = new StringBuilder ();
			}
Example #5
0
		public void TestEmptyDoc ()
		{
			RTF parser = new RTF (TextStream ("{\\rtf1}"));
			RtfToHtml r = new RtfToHtml (parser);

			r.Run ();

			Assert.AreEqual (String.Empty, r.GetText (), "emptydoc-1");
		}
Example #6
0
		public RTFException(RTF rtf, string error_message) {
			this.pos = rtf.LinePos;
			this.line = rtf.LineNumber;
			this.token_class = rtf.TokenClass;
			this.major = rtf.Major;
			this.minor = rtf.Minor;
			this.param = rtf.Param;
			this.text = rtf.Text;
			this.error_message = error_message;
		}
 public RTFException(RTF rtf, string error_message)
 {
     this.pos           = rtf.LinePos;
     this.line          = rtf.LineNumber;
     this.token_class   = rtf.TokenClass;
     this.major         = rtf.Major;
     this.minor         = rtf.Minor;
     this.param         = rtf.Param;
     this.text          = rtf.Text;
     this.error_message = error_message;
 }
        private void ReadColorTbl(RTF rtf)
        {
            Color color;
            int   num;

            num = 0;

            while (true)
            {
                rtf.GetToken();

                if (rtf.CheckCM(TokenClass.Group, Major.EndGroup))
                {
                    break;
                }

                color     = new Color(rtf);
                color.Num = num++;

                while (rtf.CheckCM(TokenClass.Control, Major.ColorName))
                {
                    switch (rtf.minor)
                    {
                    case Minor.Red:
                    {
                        color.Red = rtf.param;
                        break;
                    }

                    case Minor.Green:
                    {
                        color.Green = rtf.param;
                        break;
                    }

                    case Minor.Blue:
                    {
                        color.Blue = rtf.param;
                        break;
                    }
                    }

                    rtf.GetToken();
                }
                if (!rtf.CheckCM(TokenClass.Text, (Major)';'))
                {
                    throw new RTFException(rtf, "Malformed color entry");
                }
            }
            rtf.RouteToken();
        }
Example #9
0
		void Init ()
		{
			rtf = new RTF (Stream);

			if (text_map == null) {
				text_map = new TextMap ();
				TextMap.SetupStandardTable(text_map.Table);
			}

			sb = new StringBuilder ();
			sb.Length = 0;
			group_stack = new Stack<bool> ();
			current_is_hot = false;

			skip_width = 0;
			skip_count = 0;
		}
Example #10
0
		public Test(string[] args) {
			if (args.Length == 0)
				throw new Exception ("Program needs path to rtf file as argument");

			FileStream	stream;
			RTF		rtf;

			text = new TextMap();
			TextMap.SetupStandardTable(text.Table);

			stream = new FileStream (@"../test.rtf", FileMode.Open);
			rtf = new RTF(stream);

			skip_width = 0;
			skip_count = 0;

			rtf.ClassCallback[TokenClass.Text] = new ClassDelegate(HandleText);
			rtf.ClassCallback[TokenClass.Control] = new ClassDelegate(HandleControl);

			rtf.Read();

			stream.Close();
		}
Example #11
0
        private static String ReadFontName(RTF rtf)
        {
            StringBuilder sb = new StringBuilder();

            while (rtf.rtf_class != TokenClass.EOF && rtf.rtf_class != TokenClass.Text)
            {
                rtf.GetToken();
            }

            while ((rtf.rtf_class != TokenClass.EOF) && (!rtf.CheckCM(TokenClass.Text, (Major)';')) && (!rtf.CheckCM(TokenClass.Group, Major.EndGroup)) &&
                   (!rtf.CheckCM(TokenClass.Group, Major.BeginGroup)))
            {
                sb.Append((char)rtf.major);
                rtf.GetToken();
            }

            if (rtf.CheckCM(TokenClass.Group, Major.EndGroup))
            {
                rtf.UngetToken();
            }

            return(sb.ToString());
        }
Example #12
0
        private void ReadObjGroup(RTF rtf)
        {
            int level;

            level = 1;

            while (GetToken() != TokenClass.EOF && this.minor != Minor.ObjResult)
            {
                if (rtf_class == TokenClass.Group)
                {
                    if (this.major == Major.BeginGroup)
                    {
                        level++;
                    }
                    else if (this.major == Major.EndGroup)
                    {
                        level--;
                        if (level < 1)
                        {
                            break;
                        }
                    }
                }
            }

            if (level >= 1)
            {
                GetToken();

                if (rtf_class == TokenClass.Group)
                {
                    GetToken();
                }
                rtf.RouteToken();
            }
        }
Example #13
0
		private void ReadFontTbl(RTF rtf) {
			int	old;
			Font	font;

			old = -1;
			font = null;

			while (true) {
				rtf.GetToken();

				if (rtf.CheckCM(TokenClass.Group, Major.EndGroup)) {
					break;
				}

				if (old < 0) {
					if (rtf.CheckCMM(TokenClass.Control, Major.CharAttr, Minor.FontNum)) {
						old = 1;
					} else if (rtf.CheckCM(TokenClass.Group, Major.BeginGroup)) {
						old = 0;
					} else {
						throw new RTFException(rtf, "Cannot determine format");
					}
				}

				if (old == 0) {
					if (!rtf.CheckCM(TokenClass.Group, Major.BeginGroup)) {
						throw new RTFException(rtf, "missing \"{\"");
					}
					rtf.GetToken();
				}

				font = new Font(rtf);

				while ((rtf.rtf_class != TokenClass.EOF) && (!rtf.CheckCM(TokenClass.Text, (Major)';')) && (!rtf.CheckCM(TokenClass.Group, Major.EndGroup))) {
					if (rtf.rtf_class == TokenClass.Control) {
						switch(rtf.major) {
							case Major.FontFamily: {
								font.Family = (int)rtf.minor;
								break;
							}

							case Major.CharAttr: {
								switch(rtf.minor) {
									case Minor.FontNum: {
										font.Num = rtf.param;
										break;
									}

									default: {
										#if RTF_DEBUG
											Console.WriteLine("Got unhandled Control.CharAttr.Minor: " + rtf.minor);
										#endif
										break;
									}
								}
								break;
							}

							case Major.FontAttr: {
								switch (rtf.minor) {
									case Minor.FontCharSet: {
										font.Charset = (CharsetType)rtf.param;
										break;
									}

									case Minor.FontPitch: {
										font.Pitch = rtf.param;
										break;
									}

									case Minor.FontCodePage: {
										font.Codepage = rtf.param;
										break;
									}

									case Minor.FTypeNil:
									case Minor.FTypeTrueType: {
										font.Type = rtf.param;
										break;
									}
									default: {
										#if RTF_DEBUG
											Console.WriteLine("Got unhandled Control.FontAttr.Minor: " + rtf.minor);
										#endif
										break;
									}
								}
								break;
							}

							default: {
								#if RTF_DEBUG
									Console.WriteLine("ReadFontTbl: Unknown Control token " + rtf.major);
								#endif
								break;
							}
						}
					} else if (rtf.CheckCM(TokenClass.Group, Major.BeginGroup)) {
						rtf.SkipGroup();
					} else if (rtf.rtf_class == TokenClass.Text) {
						StringBuilder	sb;

						sb = new StringBuilder();

						while ((rtf.rtf_class != TokenClass.EOF) && (!rtf.CheckCM(TokenClass.Text, (Major)';')) && (!rtf.CheckCM(TokenClass.Group, Major.EndGroup)) && (!rtf.CheckCM(TokenClass.Group, Major.BeginGroup))) {
							sb.Append((char)rtf.major);
							rtf.GetToken();
						}

						if (rtf.CheckCM(TokenClass.Group, Major.EndGroup)) {
							rtf.UngetToken();
						}

						font.Name = sb.ToString();
						continue;
#if RTF_DEBUG
					} else {
						Console.WriteLine("ReadFontTbl: Unknown token " + rtf.text_buffer);
#endif
					}

					rtf.GetToken();
				}

				if (old == 0) {
					rtf.GetToken();

					if (!rtf.CheckCM(TokenClass.Group, Major.EndGroup)) {
						throw new RTFException(rtf, "Missing \"}\"");
					}
				}
			}

			if (font == null) {
				throw new RTFException(rtf, "No font created");
			}

			if (font.Num == -1) {
				throw new RTFException(rtf, "Missing font number");
			}

			rtf.RouteToken();
		}
Example #14
0
		private void HandleOptDest (RTF rtf)
		{
			rtf.SkipGroup ();
		}
Example #15
0
		private void ReadColorTbl(RTF rtf) {
			Color	color;
			int	num;

			num = 0;

			while (true) {
				rtf.GetToken();

				if (rtf.CheckCM(TokenClass.Group, Major.EndGroup)) {
					break;
				}

				color = new Color(rtf);
				color.Num = num++;

				while (rtf.CheckCM(TokenClass.Control, Major.ColorName)) {
					switch (rtf.minor) {
						case Minor.Red: {
							color.Red = rtf.param;
							break;
						}

						case Minor.Green: {
							color.Green = rtf.param;
							break;
						}

						case Minor.Blue: {
							color.Blue = rtf.param;
							break;
						}
					}

					rtf.GetToken();
				}
				if (!rtf.CheckCM(TokenClass.Text, (Major)';')) {
					throw new RTFException(rtf, "Malformed color entry");
				}
			}
			rtf.RouteToken();
		}
Example #16
0
		void HandleControl(RTF rtf) {
			switch(rtf.Major) {
				case Major.Unicode: {
					switch(rtf.Minor) {
						case Minor.UnicodeCharBytes: {
							skip_width = rtf.Param;
							break;
						}

						case Minor.UnicodeChar: {
							Console.Write("[Unicode {0:X4}]", rtf.Param);
							skip_count += skip_width;
							break;
						}
					}
					break;
				}

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

				case Major.CharAttr: {
					switch(rtf.Minor) {
						case Minor.ForeColor: {
							System.Windows.Forms.RTF.Color	color;
							int	num;

							color = System.Windows.Forms.RTF.Color.GetColor(rtf, rtf.Param);
							if (color != null) {
								if (color.Red == -1 && color.Green == -1 && color.Blue == -1) {
									Console.Write("[Default Color]");
								} else {
									Console.Write("[Color {0} [{1:X2}{2:X2}{3:X}]]", rtf.Param, color.Red, color.Green, color.Blue);
								}
							}
							break;
						}

						case Minor.FontSize: {
							Console.Write("[Fontsize {0}]", rtf.Param);
							break;
						}

						case Minor.FontNum: {
							System.Windows.Forms.RTF.Font	font;

							font = System.Windows.Forms.RTF.Font.GetFont(rtf, rtf.Param);
							if (font != null) {
								Console.Write("[Font {0} [{1}]]", rtf.Param, font.Name);
							}
							break;
						}

						case Minor.Plain: {
							Console.Write("[Normal]");
							break;
						}

						case Minor.Bold: {
							if (rtf.Param == RTF.NoParam) {
								Console.Write("[Bold]");
							} else {
								Console.Write("[NoBold]");
							}
							break;
						}

						case Minor.Italic: {
							if (rtf.Param == RTF.NoParam) {
								Console.Write("[Italic]");
							} else {
								Console.Write("[NoItalic]");
							}
							break;
						}

						case Minor.StrikeThru: {
							if (rtf.Param == RTF.NoParam) {
								Console.Write("[StrikeThru]");
							} else {
								Console.Write("[NoStrikeThru]");
							}
							break;
						}

						case Minor.Underline: {
							if (rtf.Param == RTF.NoParam) {
								Console.Write("[Underline]");
							} else {
								Console.Write("[NoUnderline]");
							}
							break;
						}

						case Minor.NoUnderline: {
							Console.Write("[NoUnderline]");
							break;
						}
					}
					break;
				}

				case Major.SpecialChar: {
					Console.Write("[Got SpecialChar control {0}]", rtf.Minor);
					SpecialChar(rtf);
					break;
				}
			}
		}
Example #17
0
File: RTF.cs Project: nlhepler/mono
		private void HandleOptDest (RTF rtf)
		{
			int group_levels = 1;

			while (true) {
				GetToken ();

				// Here is where we should handle recognised optional
				// destinations.
				//
				// Handle a picture group 
				//
				if (rtf.CheckCMM (TokenClass.Control, Major.Destination, Minor.Pict)) {
					ReadPictGroup (rtf);
					return;
				}

				if (rtf.CheckCM (TokenClass.Group, Major.EndGroup)) {
					if ((--group_levels) == 0) {
						break;
					}
				}

				if (rtf.CheckCM (TokenClass.Group, Major.BeginGroup)) {
					group_levels++;
				}
			}
		}
Example #18
0
		/////////////////////////////////////////////////////////////////////

		void HandleText(RTF rtf) {
			if (skip_count > 0) {
				skip_count--;
				return;
			}
			if ((StandardCharCode)rtf.Minor != StandardCharCode.nothing) {
				if (debug)
					Console.Write("{0}", text_map [(StandardCharCode) rtf.Minor]);
				AppendTextSmartly (text_map [(StandardCharCode) rtf.Minor]);
			} else {
				if ((int)rtf.Major > 31 && (int)rtf.Major < 128) {
					if (debug)
						Console.Write("[{0}]", (char)rtf.Major);
					AppendTextSmartly ((char)rtf.Major);
				}
			}
		}
Example #19
0
		////////////////////////////////////////////////////////////////////////////

		void AddRTFInfo (RTF rtf, string prop_name, bool is_keyword)
		{
			if (! reading_properties)
				return;

			FlushText ();
			rtf.GetToken ();
			while (rtf.TokenClass == TokenClass.Text) {
				if (debug)
					Console.Write ("{0}", text_map[(StandardCharCode)rtf.Minor]);
				sb.Append (text_map[(StandardCharCode)rtf.Minor]);
				rtf.GetToken ();
			}
			rtf.UngetToken();

			if (! is_keyword)
				AddProperty (Beagle.Property.New (prop_name, sb.ToString ()));
			else {
				foreach (string s in sb.ToString ().Split (' '))
					AddProperty (Beagle.Property.NewKeyword (prop_name, s));
			}

			sb.Length = 0;
		}
Example #20
0
			private void HandleText (RTF rtf)
			{
				text_buffer.Append (rtf.EncodedText);
			}
Example #21
0
        private void ReadFontTbl(RTF rtf)
        {
            int  old;
            Font font;

            old  = -1;
            font = null;

            while (true)
            {
                rtf.GetToken();

                if (rtf.CheckCM(TokenClass.Group, Major.EndGroup))
                {
                    break;
                }

                if (old < 0)
                {
                    if (rtf.CheckCMM(TokenClass.Control, Major.CharAttr, Minor.FontNum))
                    {
                        old = 1;
                    }
                    else if (rtf.CheckCM(TokenClass.Group, Major.BeginGroup))
                    {
                        old = 0;
                    }
                    else
                    {
                        throw new RTFException(rtf, "Cannot determine format");
                    }
                }

                if (old == 0)
                {
                    if (!rtf.CheckCM(TokenClass.Group, Major.BeginGroup))
                    {
                        throw new RTFException(rtf, "missing \"{\"");
                    }
                    rtf.GetToken();
                }

                font = new Font(rtf);

                while ((rtf.rtf_class != TokenClass.EOF) && (!rtf.CheckCM(TokenClass.Text, (Major)';')) && (!rtf.CheckCM(TokenClass.Group, Major.EndGroup)))
                {
                    if (rtf.rtf_class == TokenClass.Control)
                    {
                        switch (rtf.major)
                        {
                        case Major.FontFamily: {
                            font.Family = (int)rtf.minor;
                            break;
                        }

                        case Major.CharAttr: {
                            switch (rtf.minor)
                            {
                            case Minor.FontNum: {
                                font.Num = rtf.param;
                                break;
                            }

                            default: {
                                                                                #if RTF_DEBUG
                                Console.WriteLine("Got unhandled Control.CharAttr.Minor: " + rtf.minor);
                                                                                #endif
                                break;
                            }
                            }
                            break;
                        }

                        case Major.FontAttr: {
                            switch (rtf.minor)
                            {
                            case Minor.FontCharSet: {
                                font.Charset = (CharsetType)rtf.param;
                                break;
                            }

                            case Minor.FontPitch: {
                                font.Pitch = rtf.param;
                                break;
                            }

                            case Minor.FontCodePage: {
                                font.Codepage = rtf.param;
                                break;
                            }

                            case Minor.FTypeNil:
                            case Minor.FTypeTrueType: {
                                font.Type = rtf.param;
                                break;
                            }

                            default: {
                                                                                #if RTF_DEBUG
                                Console.WriteLine("Got unhandled Control.FontAttr.Minor: " + rtf.minor);
                                                                                #endif
                                break;
                            }
                            }
                            break;
                        }

                        default: {
                                                                #if RTF_DEBUG
                            Console.WriteLine("ReadFontTbl: Unknown Control token " + rtf.major);
                                                                #endif
                            break;
                        }
                        }
                    }
                    else if (rtf.CheckCM(TokenClass.Group, Major.BeginGroup))
                    {
                        rtf.SkipGroup();
                    }
                    else if (rtf.rtf_class == TokenClass.Text)
                    {
                        StringBuilder sb;

                        sb = new StringBuilder();

                        while ((rtf.rtf_class != TokenClass.EOF) && (!rtf.CheckCM(TokenClass.Text, (Major)';')) && (!rtf.CheckCM(TokenClass.Group, Major.EndGroup)) && (!rtf.CheckCM(TokenClass.Group, Major.BeginGroup)))
                        {
                            sb.Append((char)rtf.major);
                            rtf.GetToken();
                        }

                        if (rtf.CheckCM(TokenClass.Group, Major.EndGroup))
                        {
                            rtf.UngetToken();
                        }

                        font.Name = sb.ToString();
                        continue;
#if RTF_DEBUG
                    }
                    else
                    {
                        Console.WriteLine("ReadFontTbl: Unknown token " + rtf.text_buffer);
#endif
                    }

                    rtf.GetToken();
                }

                if (old == 0)
                {
                    rtf.GetToken();

                    if (!rtf.CheckCM(TokenClass.Group, Major.EndGroup))
                    {
                        throw new RTFException(rtf, "Missing \"}\"");
                    }
                }
            }

            if (font == null)
            {
                throw new RTFException(rtf, "No font created");
            }

            if (font.Num == -1)
            {
                throw new RTFException(rtf, "Missing font number");
            }

            rtf.RouteToken();
        }
Example #22
0
		private void ReadObjGroup(RTF rtf) {
			rtf.SkipGroup();
			rtf.RouteToken();
		}
Example #23
0
        private void ReadPictGroup(RTF rtf)
        {
            bool read_image_data = false;

            Picture picture = new Picture();

            while (true)
            {
                rtf.GetToken();

                if (rtf.CheckCM(TokenClass.Group, Major.EndGroup))
                {
                    break;
                }

                switch (minor)
                {
                case Minor.PngBlip:
                    picture.ImageType = minor;
                    read_image_data   = true;
                    break;

                case Minor.WinMetafile:
                    picture.ImageType = minor;
                    read_image_data   = true;
                    continue;

                case Minor.PicWid:
                    continue;

                case Minor.PicHt:
                    continue;

                case Minor.PicGoalWid:
                    picture.SetWidthFromTwips(param);
                    continue;

                case Minor.PicGoalHt:
                    picture.SetHeightFromTwips(param);
                    continue;
                }

                if (read_image_data && rtf.rtf_class == TokenClass.Text)
                {
                    picture.Data.Seek(0, SeekOrigin.Begin);

                    //char c = (char) rtf.major;

                    uint digitValue1;
                    uint digitValue2;
                    char hexDigit1 = (char)rtf.major;
                    char hexDigit2;

                    while (true)
                    {
                        while (hexDigit1 == '\n' || hexDigit1 == '\r')
                        {
                            hexDigit1 = (char)source.Peek();
                            if (hexDigit1 == '}')
                            {
                                break;
                            }
                            hexDigit1 = (char)source.Read();
                        }

                        hexDigit2 = (char)source.Peek();
                        if (hexDigit2 == '}')
                        {
                            break;
                        }
                        hexDigit2 = (char)source.Read();
                        while (hexDigit2 == '\n' || hexDigit2 == '\r')
                        {
                            hexDigit2 = (char)source.Peek();
                            if (hexDigit2 == '}')
                            {
                                break;
                            }
                            hexDigit2 = (char)source.Read();
                        }

                        if (Char.IsDigit(hexDigit1))
                        {
                            digitValue1 = (uint)(hexDigit1 - '0');
                        }
                        else if (Char.IsLower(hexDigit1))
                        {
                            digitValue1 = (uint)(hexDigit1 - 'a' + 10);
                        }
                        else if (Char.IsUpper(hexDigit1))
                        {
                            digitValue1 = (uint)(hexDigit1 - 'A' + 10);
                        }
                        else if (hexDigit1 == '\n' || hexDigit1 == '\r')
                        {
                            continue;
                        }
                        else
                        {
                            break;
                        }

                        if (Char.IsDigit(hexDigit2))
                        {
                            digitValue2 = (uint)(hexDigit2 - '0');
                        }
                        else if (Char.IsLower(hexDigit2))
                        {
                            digitValue2 = (uint)(hexDigit2 - 'a' + 10);
                        }
                        else if (Char.IsUpper(hexDigit2))
                        {
                            digitValue2 = (uint)(hexDigit2 - 'A' + 10);
                        }
                        else if (hexDigit2 == '\n' || hexDigit2 == '\r')
                        {
                            continue;
                        }
                        else
                        {
                            break;
                        }

                        picture.Data.WriteByte((byte)checked (digitValue1 * 16 + digitValue2));

                        // We get the first hex digit at the end, since in the very first
                        // iteration we use rtf.major as the first hex digit
                        hexDigit1 = (char)source.Peek();
                        if (hexDigit1 == '}')
                        {
                            break;
                        }
                        hexDigit1 = (char)source.Read();
                    }


                    read_image_data = false;
                    break;
                }
            }

            if (picture.ImageType != Minor.Undefined && !read_image_data)
            {
                this.picture = picture;
                SetToken(TokenClass.Control, Major.PictAttr, picture.ImageType, 0, String.Empty);
            }
        }
Example #24
0
		void HandleInfo (RTF rtf)
		{
			switch (rtf.Minor) {

			case Minor.HeaderLeft:
				SkipGroup (rtf);
				break;
			case Minor.HeaderRight:
				SkipGroup (rtf);
				break;
			case Minor.HeaderFirst:
				SkipGroup (rtf);
				break;
			case Minor.FooterLeft:
				SkipGroup (rtf);
				break;
			case Minor.FooterRight:
				SkipGroup (rtf);
				break;
			case Minor.FooterFirst:
				SkipGroup (rtf);
				break;
			case Minor.FieldInst:
				SkipGroup (rtf);
				break;
			case Minor.Info:
				if (debug)
					Console.WriteLine ("[Info started]");
				info_group = 1;
				break;
			case Minor.ITitle:
				AddRTFInfo (rtf, "dc:title", false);
				break;
			case Minor.ISubject:
				AddRTFInfo (rtf, "dc:subject", false);
				break;
			case Minor.IAuthor:
				AddRTFInfo (rtf, "dc:author", false);
				break;
			case Minor.IOperator:
				AddRTFInfo (rtf, "dc:operator", false);
				break;
			case Minor.IKeywords:
				AddRTFInfo (rtf, "dc:keywords", true);
				break;
			case Minor.IComment:
				AddRTFInfo (rtf, "dc:comment", false);
				break;
			case Minor.IVerscomm:
				SkipGroup(rtf);
				break;
			case Minor.IDoccomm:
				SkipGroup (rtf);
				break;
			}
		}
Example #25
0
		void HandleControl(RTF rtf) {
			switch(rtf.Major) {
				case Major.Unicode: {
					switch(rtf.Minor) {
						case Minor.UnicodeCharBytes: {
							skip_width = rtf.Param;
							break;
						}

						case Minor.UnicodeChar: {
							if (debug)
								Console.Write("[Unicode {0:X4}]", rtf.Param);
							skip_count += skip_width;
							break;
						}
					}
					break;
				}

				case Major.Destination: {
					HandleInfo (rtf);
					break;
				}

				case Major.CharAttr: {
					switch(rtf.Minor) {

					case Minor.Plain:
						if (debug)
							Console.Write("[Normal]");
						GroupIsNotHot ();
						break;

					case Minor.Bold:
						if (rtf.Param == RTF.NoParam) {
							if (debug)
								Console.Write("[Bold]");
							GroupIsHot ();
						} else {
							if (debug)
								Console.Write("[NoBold]");
							GroupIsNotHot ();
						}
						break;

					case Minor.Italic:
						if (rtf.Param == RTF.NoParam) {
							if (debug)
								Console.Write("[Italic]");
							GroupIsHot ();
						} else {
							if (debug)
								Console.Write("[NoItalic]");
							GroupIsNotHot ();
						}
						break;

					case Minor.Underline: {
						if (rtf.Param == RTF.NoParam) {
							if (debug)
								Console.Write("[Underline]");
							GroupIsHot ();
						} else {
							if (debug)
								Console.Write("[NoUnderline]");
							GroupIsNotHot ();
						}
						break;
					}

					default:
						break;
					}
					break;
				}

				case Major.SpecialChar: {
					SpecialChar(rtf);
					break;
				}
			}
		}
Example #26
0
		private string ParsedText (string text)
		{
			RTF parser = new RTF (TextStream (text));
			RtfToHtml r = new RtfToHtml (parser);

			r.Run ();

			return r.GetText ();
		}
Example #27
0
		private void ReadStyleSheet(RTF rtf) {
			Style		style;
			StringBuilder	sb;

			sb = new StringBuilder();

			while (true) {
				rtf.GetToken();

				if (rtf.CheckCM(TokenClass.Group, Major.EndGroup)) {
					break;
				}

				style = new Style(rtf);

				if (!rtf.CheckCM(TokenClass.Group, Major.BeginGroup)) {
					throw new RTFException(rtf, "Missing \"{\"");
				}

				while (true) {
					rtf.GetToken();

					if ((rtf.rtf_class == TokenClass.EOF) || rtf.CheckCM(TokenClass.Text, (Major)';')) {
						break;
					}

					if (rtf.rtf_class == TokenClass.Control) {
						if (rtf.CheckMM(Major.ParAttr, Minor.StyleNum)) {
							style.Num = rtf.param;
							style.Type = StyleType.Paragraph;
							continue;
						}
						if (rtf.CheckMM(Major.CharAttr, Minor.CharStyleNum)) {
							style.Num = rtf.param;
							style.Type = StyleType.Character;
							continue;
						}
						if (rtf.CheckMM(Major.StyleAttr, Minor.SectStyleNum)) {
							style.Num = rtf.param;
							style.Type = StyleType.Section;
							continue;
						}
						if (rtf.CheckMM(Major.StyleAttr, Minor.BasedOn)) {
							style.BasedOn = rtf.param;
							continue;
						}
						if (rtf.CheckMM(Major.StyleAttr, Minor.Additive)) {
							style.Additive = true;
							continue;
						}
						if (rtf.CheckMM(Major.StyleAttr, Minor.Next)) {
							style.NextPar = rtf.param;
							continue;
						}

						new StyleElement(style, rtf.rtf_class, rtf.major, rtf.minor, rtf.param, rtf.text_buffer.ToString());
					} else if (rtf.CheckCM(TokenClass.Group, Major.BeginGroup)) {
						// This passes over "{\*\keycode ... }, among other things
						rtf.SkipGroup();
					} else if (rtf.rtf_class == TokenClass.Text) {
						while (rtf.rtf_class == TokenClass.Text) {
							if (rtf.major == (Major)';') {
								rtf.UngetToken();
								break;
							}

							sb.Append((char)rtf.major);
							rtf.GetToken();
						}

						style.Name = sb.ToString();
#if RTF_DEBUG
					} else {
						Console.WriteLine("ReadStyleSheet: Ignored token " + rtf.text_buffer);
#endif
					}
				}
				rtf.GetToken();

				if (!rtf.CheckCM(TokenClass.Group, Major.EndGroup)) {
					throw new RTFException(rtf, "Missing EndGroup (\"}\"");
				}

				// Sanity checks
				if (style.Name == null) {
					throw new RTFException(rtf, "Style must have name");
				}

				if (style.Num < 0) {
					if (!sb.ToString().StartsWith("Normal") && !sb.ToString().StartsWith("Standard")) {
						throw new RTFException(rtf, "Missing style number");
					}

					style.Num = Style.NormalStyleNum;
				}

				if (style.NextPar == -1) {
					style.NextPar = style.Num;
				}
			}

			rtf.RouteToken();
		}
Example #28
0
 private void HandleOptDest(RTF rtf)
 {
     rtf.SkipGroup();
 }
Example #29
0
		void SpecialChar(RTF rtf) {
			switch(rtf.Minor) {
				case Minor.Page:
				case Minor.Sect:
				case Minor.Row:
				case Minor.Line:
				case Minor.Par: {
					Console.Write("\n");
					break;
				}

				case Minor.Cell: {
					Console.Write(" ");
					break;
				}

				case Minor.NoBrkSpace: {
					Console.Write(" ");
					break;
				}

				case Minor.Tab: {
					Console.Write("\t");
					break;
				}

				case Minor.NoBrkHyphen: {
					Console.Write("-");
					break;
				}

				case Minor.Bullet: {
					Console.Write("*");
					break;
				}

				case Minor.EmDash: {
					Console.Write("—");
					break;
				}

				case Minor.EnDash: {
					Console.Write("–");
					break;
				}

				case Minor.LQuote: {
					Console.Write("‘");
					break;
				}

				case Minor.RQuote: {
					Console.Write("’");
					break;
				}

				case Minor.LDblQuote: {
					Console.Write("“");
					break;
				}

				case Minor.RDblQuote: {
					Console.Write("”");
					break;
				}

				default: {
					rtf.SkipGroup();
					break;
				}
			}
		}
Example #30
0
File: RTF.cs Project: nlhepler/mono
		private void ReadPictGroup(RTF rtf)
		{
			bool read_image_data = false;

			Picture picture = new Picture ();
			while (true) {
				rtf.GetToken ();

				if (rtf.CheckCM (TokenClass.Group, Major.EndGroup))
					break;

				switch (minor) {
				case Minor.PngBlip:
					picture.ImageType = minor;
					read_image_data = true;
					break;
				case Minor.WinMetafile:
					picture.ImageType = minor;
					read_image_data = true;
					continue;
				case Minor.PicWid:
					continue;
				case Minor.PicHt:
					continue;
				case Minor.PicGoalWid:
					picture.SetWidthFromTwips (param);
					continue;
				case Minor.PicGoalHt:
					picture.SetHeightFromTwips (param);
					continue;
				}

				if (read_image_data && rtf.rtf_class == TokenClass.Text) {

					picture.Data.Seek (0, SeekOrigin.Begin);

					//char c = (char) rtf.major;

					uint digitValue1;
					uint digitValue2;
					char hexDigit1 = (char) rtf.major;
					char hexDigit2;

					while (true) {

						while (hexDigit1 == '\n' || hexDigit1 == '\r') {
							hexDigit1 = (char) source.Peek ();
							if (hexDigit1 == '}')
								break;
							hexDigit1 = (char) source.Read ();
						}
						
						hexDigit2 = (char) source.Peek ();
						if (hexDigit2 == '}')
							break;
						hexDigit2 = (char) source.Read ();
						while (hexDigit2 == '\n' || hexDigit2 == '\r') {
							hexDigit2 = (char) source.Peek ();
							if (hexDigit2 == '}')
								break;
							hexDigit2 = (char) source.Read ();
						}

						if (Char.IsDigit (hexDigit1))
							digitValue1 = (uint) (hexDigit1 - '0');
						else if (Char.IsLower (hexDigit1))
							digitValue1 = (uint) (hexDigit1 - 'a' + 10);
						else if (Char.IsUpper (hexDigit1))
							digitValue1 = (uint) (hexDigit1 - 'A' + 10);
						else if (hexDigit1 == '\n' || hexDigit1 == '\r')
							continue;
						else
							break;

						if (Char.IsDigit (hexDigit2))
							digitValue2 = (uint) (hexDigit2 - '0');
						else if (Char.IsLower (hexDigit2))
							digitValue2 = (uint) (hexDigit2 - 'a' + 10);
						else if (Char.IsUpper (hexDigit2))
							digitValue2 = (uint) (hexDigit2 - 'A' + 10);
						else if (hexDigit2 == '\n' || hexDigit2 == '\r')
							continue;
						else 
							break;

						picture.Data.WriteByte ((byte) checked (digitValue1 * 16 + digitValue2));

						// We get the first hex digit at the end, since in the very first
						// iteration we use rtf.major as the first hex digit
						hexDigit1 = (char) source.Peek ();
						if (hexDigit1 == '}')
							break;
						hexDigit1 = (char) source.Read ();
					}

					
					read_image_data = false;
					break;
				}
			}

			if (picture.ImageType != Minor.Undefined && !read_image_data) {
				this.picture = picture;
				SetToken (TokenClass.Control, Major.PictAttr, picture.ImageType, 0, String.Empty);
			}
		}
Example #31
0
		void HandleText(RTF rtf) {
			if (skip_count > 0) {
				skip_count--;
				return;
			}
			if ((StandardCharCode)rtf.Minor != StandardCharCode.nothing) {
				Console.Write("{0}", text[(StandardCharCode)rtf.Minor]);
			} else {
				if ((int)rtf.Major > 31 && (int)rtf.Major < 128) {
					Console.Write("{0}", (char)rtf.Major);
				} else {
					Console.Write("[Literal:0x{0:X2}]", (int)rtf.Major);
				}
			}
		}
Example #32
0
		void SpecialChar(RTF rtf) {
			switch(rtf.Minor) {
				case Minor.Page:
				case Minor.Sect:
				case Minor.Row:
				case Minor.Line:
				case Minor.Par:
					//Console.Write("\n");
					FlushText ();
					AppendStructuralBreak ();
					break;

				case Minor.Cell:
					//Console.Write(" ");
					AppendWhiteSpace ();
					break;

				case Minor.NoBrkSpace:
					//Console.Write(" ");
					AppendWhiteSpace ();
					break;

				case Minor.Tab:
					//Console.Write("\t");
					AppendWhiteSpace ();
					break;

				case Minor.NoBrkHyphen:
					//Console.Write("-");
					AppendTextSmartly ('-');
					break;

				case Minor.Bullet:
					//Console.Write("*");
					AppendTextSmartly ('*');
					break;

				default:
					SkipGroup (rtf);
					break;
			}
		}
Example #33
0
		override protected void DoClose ()
		{
			sb.Length = 0;
			sb = null;

			group_stack.Clear ();
			group_stack = null;

			rtf = null;
		}
Example #34
0
 private void ReadObjGroup(RTF rtf)
 {
     rtf.SkipGroup();
     rtf.RouteToken();
 }
Example #35
0
		void HandleGroup (RTF rtf)
		{
			switch (rtf.Major) {

			case Major.BeginGroup:
				if (reading_properties)
					info_group = (info_group > 0 ? info_group + 1 : info_group);
				if (debug)
					Console.WriteLine ("[new group] {0}", info_group);
				group_stack.Push (current_is_hot);
				current_is_hot = false;
				break;

			case Major.EndGroup:
				FlushText ();

				if (current_is_hot) {
					if (debug)
						Console.WriteLine ("[end hot]");
					HotDown ();
				}

				try {
					current_is_hot = group_stack.Pop ();
				} catch {
					current_is_hot = false;
				}
				if (reading_properties)
					info_group = (info_group > 0 ? info_group - 1 : info_group);
				if (debug)
					Console.WriteLine ("[end new group] {0}", info_group);
				break;
			}
		}
Example #36
0
        private void ReadStyleSheet(RTF rtf)
        {
            Style         style;
            StringBuilder sb;

            sb = new StringBuilder();

            while (true)
            {
                rtf.GetToken();

                if (rtf.CheckCM(TokenClass.Group, Major.EndGroup))
                {
                    break;
                }

                style = new Style(rtf);

                if (!rtf.CheckCM(TokenClass.Group, Major.BeginGroup))
                {
                    throw new RTFException(rtf, "Missing \"{\"");
                }

                while (true)
                {
                    rtf.GetToken();

                    if ((rtf.rtf_class == TokenClass.EOF) || rtf.CheckCM(TokenClass.Text, (Major)';'))
                    {
                        break;
                    }

                    if (rtf.rtf_class == TokenClass.Control)
                    {
                        if (rtf.CheckMM(Major.ParAttr, Minor.StyleNum))
                        {
                            style.Num  = rtf.param;
                            style.Type = StyleType.Paragraph;
                            continue;
                        }
                        if (rtf.CheckMM(Major.CharAttr, Minor.CharStyleNum))
                        {
                            style.Num  = rtf.param;
                            style.Type = StyleType.Character;
                            continue;
                        }
                        if (rtf.CheckMM(Major.StyleAttr, Minor.SectStyleNum))
                        {
                            style.Num  = rtf.param;
                            style.Type = StyleType.Section;
                            continue;
                        }
                        if (rtf.CheckMM(Major.StyleAttr, Minor.BasedOn))
                        {
                            style.BasedOn = rtf.param;
                            continue;
                        }
                        if (rtf.CheckMM(Major.StyleAttr, Minor.Additive))
                        {
                            style.Additive = true;
                            continue;
                        }
                        if (rtf.CheckMM(Major.StyleAttr, Minor.Next))
                        {
                            style.NextPar = rtf.param;
                            continue;
                        }

                        new StyleElement(style, rtf.rtf_class, rtf.major, rtf.minor, rtf.param, rtf.text_buffer.ToString());
                    }
                    else if (rtf.CheckCM(TokenClass.Group, Major.BeginGroup))
                    {
                        // This passes over "{\*\keycode ... }, among other things
                        rtf.SkipGroup();
                    }
                    else if (rtf.rtf_class == TokenClass.Text)
                    {
                        while (rtf.rtf_class == TokenClass.Text)
                        {
                            if (rtf.major == (Major)';')
                            {
                                rtf.UngetToken();
                                break;
                            }

                            sb.Append((char)rtf.major);
                            rtf.GetToken();
                        }

                        style.Name = sb.ToString();
#if RTF_DEBUG
                    }
                    else
                    {
                        Console.WriteLine("ReadStyleSheet: Ignored token " + rtf.text_buffer);
#endif
                    }
                }
                rtf.GetToken();

                if (!rtf.CheckCM(TokenClass.Group, Major.EndGroup))
                {
                    throw new RTFException(rtf, "Missing EndGroup (\"}\"");
                }

                // Sanity checks
                if (style.Name == null)
                {
                    throw new RTFException(rtf, "Style must have name");
                }

                if (style.Num < 0)
                {
                    if (!sb.ToString().StartsWith("Normal") && !sb.ToString().StartsWith("Standard"))
                    {
                        throw new RTFException(rtf, "Missing style number");
                    }

                    style.Num = Style.NormalStyleNum;
                }

                if (style.NextPar == -1)
                {
                    style.NextPar = style.Num;
                }
            }

            rtf.RouteToken();
        }
Example #37
0
		void SkipGroup (RTF rtf)
		{
			rtf.SkipGroup ();
			rtf.RouteToken ();
		}