Example #1
0
String PackImlData(const Vector<Image>& image)
{
    StringBuffer block;
    for(int i = 0; i < image.GetCount(); i++) {
        const Image& img = image[i];
        StringStream ss;
        ss.Put(img.GetResolution() << 6);
        Size sz = img.GetSize();
        ss.Put16le(sz.cx);
        ss.Put16le(sz.cy);
        Point p = img.GetHotSpot();
        ss.Put16le(p.x);
        ss.Put16le(p.y);
        p = img.Get2ndSpot();
        ss.Put16le(p.x);
        ss.Put16le(p.y);
        block.Cat(ss.GetResult());
        const RGBA *s = img;
        const RGBA *e = s + img.GetLength();
        while(s < e) {
            block.Cat(s->r);
            block.Cat(s->g);
            block.Cat(s->b);
            block.Cat(s->a);
            s++;
        }
    }
    return ZCompress(block);
}
Example #2
0
String RichPara::Pack(const RichPara::Format& style, Array<RichObject>& obj) const
{
	StringStream out;
	dword pattr = 0;
	if(format.align != style.align)             pattr |= 1;
	if(format.before != style.before)           pattr |= 2;
	if(format.lm != style.lm)                   pattr |= 4;
	if(format.indent != style.indent)           pattr |= 8;
	if(format.rm != style.rm)                   pattr |= 0x10;
	if(format.after != style.after)             pattr |= 0x20;
	if(format.bullet != style.bullet)           pattr |= 0x40;
	if(format.keep != style.keep)               pattr |= 0x80;
	if(format.newpage != style.newpage)         pattr |= 0x100;
	if(format.tabsize != style.tabsize)         pattr |= 0x200;
	if(!IsNull(format.label))                   pattr |= 0x400;
	if(format.keepnext != style.keepnext)       pattr |= 0x800;
	if(format.orphan != style.orphan)           pattr |= 0x1000;
	if(NumberingDiffers(format, style))         pattr |= 0x2000;
	if(format.linespacing != style.linespacing) pattr |= 0x4000;
	if(format.tab != style.tab)                 pattr |= 0x8000;
	if(format.ruler != style.ruler)             pattr |= 0x10000;
	if(format.rulerink != style.rulerink)       pattr |= 0x20000;
	out.Put32(pattr);
	if(pattr & 1)      out.Put16(format.align);
	if(pattr & 2)      out.Put16(format.before);
	if(pattr & 4)      out.Put16(format.lm);
	if(pattr & 8)      out.Put16(format.indent);
	if(pattr & 0x10)   out.Put16(format.rm);
	if(pattr & 0x20)   out.Put16(format.after);
	if(pattr & 0x40)   out.Put16(format.bullet);
	if(pattr & 0x80)   out.Put(format.keep);
	if(pattr & 0x100)  out.Put(format.newpage);
	if(pattr & 0x200)  out.Put16(format.tabsize);
	if(pattr & 0x400)  { String t = format.label; out % t; }
	if(pattr & 0x800)  out.Put(format.keepnext);
	if(pattr & 0x1000) out.Put(format.orphan);
	if(pattr & 0x2000) {
		String b = format.before_number, a = format.after_number;
		out % b % a;
		out.Put(format.reset_number);
		out.Put(format.number, 8);
	}
	if(pattr & 0x4000)
		out.Put(format.linespacing);
	if(pattr & 0x8000) {
		int c = 0;
		int i;
		for(i = 0; i < format.tab.GetCount(); i++) {
			if(!IsNull(format.tab[i].pos))
				c++;
		}
		out.Put16(c);
		for(i = 0; i < format.tab.GetCount(); i++) {
			const RichPara::Tab& w = format.tab[i];
			if(!IsNull(w.pos)) {
				out.Put32(w.pos);
				out.Put(w.align);
				out.Put(w.fillchar);
			}
		}
	}
	if(pattr & 0x10000)
		out.Put16(format.ruler);
	if(pattr & 0x20000) {
		Color c = format.rulerink;
		c.Serialize(out);
	}
	obj.Clear();
	CharFormat cf = style;
	if(part.GetCount())
		PackParts(out, style, part, cf, obj);
	else
		Charformat(out, style, format, cf);
	String r = out;
	r.Shrink();
	return r;
}
Example #3
0
String SaveIml(const Array<ImlImage>& iml, int format) {
	StringStream out;
	if(format == 1) {
		for(int i = 0; i < iml.GetCount(); i++) {
			const ImlImage& c = iml[i];
			if(c.exp)
				out << "IMAGE_META(\"exp\", \"\")\r\n";
			String name = c.name;
			Image buffer = c.image;
			if(IsNull(name))
				name = "im__" + IntStr(i);
			out.PutLine(NFormat("IMAGE_BEGIN(%s)", name));
			int last = 0;
			for(int i = 0; i < buffer.GetHeight(); i++) {
				String scan = PackRLE(buffer[i], buffer.GetWidth());
				if(!scan.IsEmpty() || i == 0) // force at least 1 scan
				{
					for(; last < i; last++)
						out.PutLine("\tIMAGE_SCAN(\"\")");
					out.Put("\tIMAGE_SCAN(");
					PutOctalString(out, scan.Begin(), scan.End(), true);
					out.Put(")\r\n");
					last = i + 1;
				}
			}
			out.Put("IMAGE_PACKED(");
			out.Put(name);
			out.Put(", ");
			StringStream datastrm;
			Size size = buffer.GetSize();
			Point hotspot = buffer.GetHotSpot();
			int encoding = AlphaImageInfo::COLOR_RLE;
			int version = 1;
			datastrm / version;
			datastrm % size % hotspot % encoding;
			ASSERT(!datastrm.IsError());
			String s = datastrm.GetResult();
			PutOctalString(out, s.Begin(), s.End());
			out.Put(")\r\n");
		}
	}
	else {
		out << "PREMULTIPLIED\r\n";
		for(int i = 0; i < iml.GetCount(); i++) {
			const ImlImage& c = iml[i];
			out << "IMAGE_ID(" << c.name << ")";
			if(c.exp)
				out << " IMAGE_META(\"exp\", \"\")\r\n";
			out << "\r\n";
		}
		int ii = 0;
		while(ii < iml.GetCount()) {
			int bl = 0;
			int bn = 0;
			Vector<Image> bimg;
			while(bl < 4096 && ii < iml.GetCount()) {
				const ImlImage& c = iml[ii++];
				bimg.Add(c.image);
				bl += c.image.GetLength();
				bn++;
			}
			String bs = PackImlData(bimg);
			out << "\r\nIMAGE_BEGIN_DATA\r\n";
			bs.Cat(0, ((bs.GetCount() + 31) & ~31) - bs.GetCount());
			const byte *s = bs;
			for(int n = bs.GetCount() / 32; n--;) {
				out << "IMAGE_DATA(";
				for(int j = 0; j < 32; j++) {
					if(j) out << ',';
					out << (int)*s++;
				}
				out << ")\r\n";
			}
			out << "IMAGE_END_DATA(" << bs.GetCount() << ", " << bn << ")\r\n";
		}
	}
	return out.GetResult();
}