Exemplo n.º 1
0
void RichPara::UnpackParts(Stream& in, const RichPara::CharFormat& chrstyle,
                           Array<RichPara::Part>& part, const Array<RichObject>& obj,
                           int& oi) {
	part.Add();
	part.Top().format = format;
	int c;
	while((c = in.Term()) >= 0)
		if(c < 31 && c != 9 && c != FIELD) {
			do
				switch(in.Get()) {
				case BOLD0:
					format.NoBold();
					break;
				case BOLD1:
					format.Bold();
					break;
				case BOLDS:
					format.Bold(chrstyle.IsBold());
					break;
				case ITALIC0:
					format.NoItalic();
					break;
				case ITALIC1:
					format.Italic();
					break;
				case ITALICS:
					format.Italic(chrstyle.IsItalic());
					break;
				case UNDERLINE0:
					format.NoUnderline();
					break;
				case UNDERLINE1:
					format.Underline();
					break;
				case UNDERLINES:
					format.Underline(chrstyle.IsUnderline());
					break;
				case STRIKEOUT0:
					format.NoStrikeout();
					break;
				case STRIKEOUT1:
					format.Strikeout();
					break;
				case STRIKEOUTS:
					format.Strikeout(chrstyle.IsStrikeout());
					break;
				case CAPITALS0:
					format.capitals = false;
					break;
				case CAPITALS1:
					format.capitals = true;
					break;
				case CAPITALSS:
					format.capitals = chrstyle.capitals;
					break;
				case DASHED0:
					format.dashed = false;
					break;
				case DASHED1:
					format.dashed = true;
					break;
				case DASHEDS:
					format.dashed = chrstyle.dashed;
					break;
				case SSCRIPT:
					format.sscript = in.Get();
					if(format.sscript == 3)
						format.sscript = chrstyle.sscript;
					break;
				case FACE:
					c = in.Get16();
					format.Face(c == 0xffff ? chrstyle.GetFace() : c);
					break;
				case HEIGHT:
					c = in.Get16();
					format.Height(c == 0xffff ? chrstyle.GetHeight() : c);
					break;
				case LINK:
					in % format.link;
					break;
				case INDEXENTRY:
					in % format.indexentry;
					break;
				case INK:
					in % format.ink;
					break;
				case PAPER:
					in % format.paper;
					break;
				case LANGUAGE:
					format.language = in.Get32();
					break;
				case EXT:
					switch(in.Get()) {
					case NONAA0:
						format.NonAntiAliased(false);
						break;
					case NONAA1:
						format.NonAntiAliased(true);
						break;
					case NONAAS:
						format.NonAntiAliased(chrstyle.IsNonAntiAliased());
						break;
					}
				}
			while((c = in.Term()) < 31 && c != 9 && c != FIELD && c >= 0);
			if(part.Top().text.GetLength())
				part.Add();
			part.Top().format = format;
		}
		else
		if(in.Term() == FIELD) {
			RichPara::Format pformat = format;
			if(part.Top().text.GetLength()) {
				part.Add();
				part.Top().format = pformat;
			}
			in.Get();
			Part& p = part.Top();
			String id;
			in % id;
			p.field = id;
			in % p.fieldparam;
			String s;
			in % s;
			StringStream sn(s);
			UnpackParts(sn, chrstyle, p.fieldpart, obj, oi);
			part.Add();
			part.Top().format = format = pformat;
		}
		else
		if(in.Term() == OBJECT) {
			if(part.Top().text.GetLength()) {
				part.Add();
				part.Top().format = format;
			}
			part.Top().object = obj[oi++];
			part.Top().format = format;
			part.Add();
			part.Top().format = format;
			in.Get();
		}
		else {
			StringBuffer b;
			b.Reserve(512);
			while(in.Term() >= 32 || in.Term() == 9)
				b.Cat(in.Get());
			part.Top().text.Cat(FromUtf8(~b));
		}
	if(part.Top().text.GetLength() == 0 && part.Top().IsText())
		part.Drop();
}
Exemplo n.º 2
0
void RichPara::Charformat(Stream& out, const RichPara::CharFormat& o,
                          const RichPara::CharFormat& n, const RichPara::CharFormat& s)
{
	if(o.IsBold() != n.IsBold())
		out.Put(n.IsBold() == s.IsBold() ? BOLDS : BOLD0 + n.IsBold());
	if(o.IsItalic() != n.IsItalic())
		out.Put(n.IsItalic() == s.IsItalic() ? ITALICS
		                                     : ITALIC0 + n.IsItalic());
	if(o.IsUnderline() != n.IsUnderline())
		out.Put(n.IsUnderline() == s.IsUnderline() ? UNDERLINES
		                                           : UNDERLINE0 + n.IsUnderline());
	if(o.IsStrikeout() != n.IsStrikeout())
		out.Put(n.IsStrikeout() == s.IsStrikeout() ? STRIKEOUTS
		                                           : STRIKEOUT0 + n.IsStrikeout());
	if(o.IsNonAntiAliased() != n.IsNonAntiAliased()) {
		out.Put(EXT);
		out.Put(n.IsNonAntiAliased() == s.IsNonAntiAliased() ? NONAAS
		                                                     : NONAA0 + n.IsNonAntiAliased());
	}
	if(o.capitals != n.capitals)
		out.Put(n.capitals == s.capitals ? CAPITALSS
		                                 : CAPITALS0 + n.capitals);
	if(o.dashed != n.dashed)
		out.Put(n.dashed == s.dashed ? DASHEDS
		                             : DASHED0 + n.dashed);
	if(o.sscript != n.sscript) {
		out.Put(SSCRIPT);
		out.Put(n.sscript);
	}
	if(o.GetFace() != n.GetFace()) {
		out.Put(FACE);
		out.Put16(n.GetFace() == s.GetFace() ? 0xffff : n.GetFace());
	}
	if(o.GetHeight() != n.GetHeight()) {
		out.Put(HEIGHT);
		out.Put16(n.GetHeight() == s.GetHeight() ? 0xffff : n.GetHeight());
	}
	if(o.link != n.link) {
		out.Put(LINK);
		String s = n.link;
		out % s;
	}
	if(o.ink != n.ink) {
		out.Put(INK);
		Color c = n.ink;
		c.Serialize(out);
	}
	if(o.paper != n.paper) {
		out.Put(PAPER);
		Color c = n.paper;
		c.Serialize(out);
	}
	if(o.language != n.language) {
		out.Put(LANGUAGE);
		out.Put32(n.language);
	}
	if(o.indexentry != n.indexentry) {
		out.Put(INDEXENTRY);
		WString s = n.indexentry;
		out % s;
	}
}