Esempio n. 1
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();
		}
Esempio n. 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();
        }