Exemple #1
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();
        }
Exemple #2
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();
        }
Exemple #3
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;
				}
			}
		}
Exemple #4
0
 private void ReadObjGroup(RTF rtf)
 {
     rtf.SkipGroup();
     rtf.RouteToken();
 }
Exemple #5
0
		void SkipGroup (RTF rtf)
		{
			rtf.SkipGroup ();
			rtf.RouteToken ();
		}
Exemple #6
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;
				}
			}
		}
Exemple #7
0
		private void ReadObjGroup(RTF rtf) {
			rtf.SkipGroup();
			rtf.RouteToken();
		}
Exemple #8
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();
		}
Exemple #9
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();
		}
Exemple #10
0
		private void HandleOptDest (RTF rtf)
		{
			rtf.SkipGroup ();
		}
Exemple #11
0
 private void HandleOptDest(RTF rtf)
 {
     rtf.SkipGroup();
 }