RichText: Painting changed to use RichObject::ToImage (instead of Paint) primarily; this fixes transparency issue

git-svn-id: svn://ultimatepp.org/upp/trunk@1333 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
cxl 2009-06-24 13:03:55 +00:00
parent 6dc99ffef1
commit 08ea67bd13
5 changed files with 79 additions and 17 deletions

View file

@ -112,9 +112,10 @@ Image RichObjectType::ToImage(const Value& data, Size sz) const
Image RichObjectType::ToImage(const Value& data, Size sz, void *context) const
{
ImageDraw w(sz);
Paint(data, w, sz, context);
return w;
ImageDraw iw(sz);
iw.DrawRect(sz, SColorPaper());
Paint(data, iw, sz, context);
return iw;
}
String RichObjectType::GetLink(const Value& data, Point pt, Size sz) const

View file

@ -141,10 +141,12 @@ String RichObjectImageMaker::Key() const
Image RichObjectImageMaker::Make() const
{
ImageDraw iw(sz);
return object.ToImage(sz, context);
/* ImageDraw iw(sz);
iw.DrawRect(sz, SColorPaper());
object.Paint(iw, sz, context);
return iw;
*/
}
void RichPara::Paint(PageDraw& pw, const Rect& page, PageY py, const PaintInfo& pi,

View file

@ -8,8 +8,8 @@ struct RichImage : public RichObjectType {
virtual String GetTypeName(const Value& v) const;
virtual Size GetPhysicalSize(const Value& data) const;
virtual Size GetPixelSize(const Value& data) const;
virtual void Paint(const Value& data, Draw& w, Size sz) const;
virtual Image ToImage(const Value& data, Size sz) const;
virtual void Paint(const Value& data, Draw& w, Size sz, void *) const;
virtual Image ToImage(const Value& data, Size sz, void *) const;
virtual bool Accept(PasteClip& clip);
virtual Value Read(PasteClip& clip);
@ -57,14 +57,14 @@ Size RichImage::GetPhysicalSize(const Value& data) const
return sz;
}
void RichImage::Paint(const Value& data, Draw& w, Size sz) const
void RichImage::Paint(const Value& data, Draw& w, Size sz, void *) const
{
Image x = LoadImageFromString(data);
// Size outsz(min(sz.cx, 4 * x.GetWidth()), min(sz.cy, 4 * x.GetHeight()));
w.DrawImage(0, 0, sz.cx, sz.cy, x);
}
Image RichImage::ToImage(const Value& data, Size sz) const
Image RichImage::ToImage(const Value& data, Size sz, void *) const
{
return Rescale(LoadImageFromString(data), sz);
}
@ -88,7 +88,7 @@ struct RichPNG : public RichObjectType {
virtual Size GetPhysicalSize(const Value& data) const;
virtual Size GetPixelSize(const Value& data) const;
virtual void Paint(const Value& data, Draw& w, Size sz) const;
virtual Image ToImage(const Value& data, Size sz) const;
virtual Image ToImage(const Value& data, Size sz, void *) const;
};
String RichPNG::GetTypeName(const Value& v) const
@ -138,7 +138,7 @@ void RichPNG::Paint(const Value& data, Draw& w, Size sz) const
w.DrawImage(0, 0, outsz.cx, outsz.cy, x);
}
Image RichPNG::ToImage(const Value& data, Size sz) const
Image RichPNG::ToImage(const Value& data, Size sz, void *) const
{
if(IsString(data)) {
ImageDraw iw(sz);
@ -160,8 +160,8 @@ struct RichRawImage : public RichObjectType {
virtual String Write(const Value& v) const;
virtual Size GetPhysicalSize(const Value& data) const;
virtual Size GetPixelSize(const Value& data) const;
virtual void Paint(const Value& data, Draw& w, Size sz) const;
virtual Image ToImage(const Value& data, Size sz) const;
virtual void Paint(const Value& data, Draw& w, Size sz, void *) const;
virtual Image ToImage(const Value& data, Size sz, void *) const;
};
String RichRawImage::GetTypeName(const Value& v) const
@ -199,7 +199,7 @@ Size RichRawImage::GetPixelSize(const Value& data) const
return Size(0, 0);
}
void RichRawImage::Paint(const Value& data, Draw& w, Size sz) const
void RichRawImage::Paint(const Value& data, Draw& w, Size sz, void *) const
{
String s = data;
StringStream ss(s);
@ -211,7 +211,7 @@ void RichRawImage::Paint(const Value& data, Draw& w, Size sz) const
}
}
Image RichRawImage::ToImage(const Value& data, Size sz) const
Image RichRawImage::ToImage(const Value& data, Size sz, void *) const
{
String s = data;
StringStream ss(s);
@ -232,6 +232,56 @@ RichObject CreateRawImageObject(const String& s, int cx, int cy)
return o;
}
struct RichImlImage : public RichObjectType {
virtual String GetTypeName(const Value& v) const;
virtual Size GetPhysicalSize(const Value& data) const;
virtual Size GetPixelSize(const Value& data) const;
virtual void Paint(const Value& data, Draw& w, Size sz) const;
virtual Image ToImage(const Value& data, Size sz, void *) const;
virtual bool IsText() const;
Image Get(const Value& v) const;
};
Image RichImlImage::Get(const Value& v) const
{
return GetImlImage((String)v);
}
String RichImlImage::GetTypeName(const Value& v) const
{
return "IML";
}
bool RichImlImage::IsText() const
{
return true;
}
Size RichImlImage::GetPhysicalSize(const Value& data) const
{
return Get(data).GetSize();
}
Size RichImlImage::GetPixelSize(const Value& data) const
{
return Get(data).GetSize();
}
void RichImlImage::Paint(const Value& data, Draw& w, Size sz) const
{
w.DrawImage(0, 0, sz.cx, sz.cy, Get(data));
}
Image RichImlImage::ToImage(const Value& data, Size sz, void *) const
{
return Rescale(Get(data), sz);
}
INITBLOCK {
RichObject::Register("iml", &Single<RichImlImage>());
};
#endif
END_UPP_NAMESPACE

View file

@ -212,8 +212,7 @@ public:
RichObject CreateDrawingObject(const Drawing& dwg, Size dot_size, Size size);
RichObject CreateDrawingObject(const Drawing& dwg, int cx = 0, int cy = 0);
RichObject CreatePNGObject(const Image& img, Size dot_size, Size size);
RichObject CreatePNGObject(const Image& img, Size dot_size, Size size);
RichObject CreateImageObject(const Image& img, int cx = 0, int cy = 0);
RichObject CreatePNGObject(const Image& img, int cx, int cy);
RichObject CreateRawImageObject(const String& s, int cx = 0, int cy = 0);
struct RichPara;

View file

@ -441,7 +441,8 @@ y]&]
[s0; &]
[ {{1879:8121^ [s0; [@(0.0.255) format]]
:: [s0; Format of objects. This format must be recognized by the application.
By default, RichText recognizes the PNG format.]
By default, RichText recognizes the PNG format and [*/ iml] format
(see bellow).]
:: [s0; [@(0.0.255) cx]]
:: [s0; Width of object in dots.]
:: [s0; [@(0.0.255) cy]]
@ -468,6 +469,15 @@ Data are encoded in 7 byte groups, which corresponds to 8 bytes
of encoded format. First byte of this 8 bytes block always contains
eight bits of following bytes, LSB (that is bit 0) being the
eight bit for first byte in block.&]
[s0; &]
[s0; [*/3 iml][*3 format]&]
[s0;* &]
[s0; [*/ iml][* ]format is text format of rich object where text data
reference existing .iml based Image as pair [@(0.0.255) iml`_class`_name]:[@(0.0.255) i
mage`_name]. Example of full object definition in [*/ iml] format:&]
[s0; &]
[s0; [*C@3 `"`@`@iml:400`*400``CtrlImg:exclamation```"]&]
[s0;@(0.0.255) &]
[s0;@(0.0.255) &]
[s0;@(0.0.255) &]
[s2; Tables&]