Ejemplo n.º 1
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++;
                }
            }
        }
Ejemplo n.º 2
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();
        }
Ejemplo n.º 3
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();
		}
Ejemplo n.º 4
0
Archivo: RTF.cs Proyecto: 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++;
				}
			}
		}