Painter - fixes, printing fixes, NOAA (for better printing output)

git-svn-id: svn://ultimatepp.org/upp/trunk@779 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
cxl 2009-01-17 11:58:41 +00:00
parent 9ee7e1d00d
commit 82b316980d
19 changed files with 621 additions and 537 deletions

View file

@ -1,155 +1,156 @@
#include "Painter.h"
NAMESPACE_UPP
#define LTIMING(x) RTIMING(x)
void BufferPainter::ClearOp(const RGBA& color)
{
Upp::Fill(~buffer, color, buffer.GetLength());
}
inline void BufferPainter::PathPoint0(double x, double y)
{
pathrect.left = min(pathrect.left, x);
pathrect.top = min(pathrect.top, y);
pathrect.right = max(pathrect.right, x);
pathrect.bottom = max(pathrect.bottom, y);
}
inline void BufferPainter::PathPoint(double& x, double& y, bool rel)
{
x = IsNull(x) ? current.x : rel ? x + current.x : x;
y = IsNull(y) ? current.y : rel ? y + current.y : y;
if(inpath)
PathPoint0(x, y);
else {
path.remove_all();
pathrect.left = pathrect.right = x;
pathrect.top = pathrect.bottom = y;
pathattr = attr;
}
inpath = true;
}
inline void BufferPainter::EndPoint(double& x, double& y, bool rel)
{
PathPoint(x, y, rel);
current = Pointf(x, y);
}
void BufferPainter::MoveOp(double x, double y, bool rel)
{
EndPoint(x, y, rel);
ccontrol = qcontrol = current;
path.move_to(x, y);
inpath = true;
}
void BufferPainter::LineOp(double x, double y, bool rel)
{
EndPoint(x, y, rel);
ccontrol = qcontrol = current;
path.line_to(x, y);
inpath = true;
}
void BufferPainter::QuadraticOp(double x1, double y1, double x, double y, bool rel)
{
PathPoint(x1, y1, rel);
qcontrol = Pointf(x1, y1);
EndPoint(x, y, rel);
ccontrol = current;
path.curve3(x1, y1, x, y);
}
void BufferPainter::QuadraticOp(double x, double y, bool rel)
{
qcontrol = current + current - qcontrol;
PathPoint0(qcontrol.x, qcontrol.y);
EndPoint(x, y, rel);
ccontrol = current;
path.curve3(qcontrol.x, qcontrol.y, x, y);
}
void BufferPainter::CubicOp(double x1, double y1, double x2, double y2, double x, double y, bool rel)
{
PathPoint(x1, y1, rel);
PathPoint(x2, y2, rel);
ccontrol = Pointf(x2, y2);
EndPoint(x, y, rel);
qcontrol = current;
path.curve4(x1, y1, x2, y2, x, y);
}
void BufferPainter::CubicOp(double x2, double y2, double x, double y, bool rel)
{
Pointf c = current + current - ccontrol;
PathPoint0(c.x, c.y);
PathPoint(x2, y2, rel);
ccontrol = Pointf(x2, y2);
EndPoint(x, y, rel);
qcontrol = current;
path.curve4(c.x, c.y, x2, y2, x, y);
}
void BufferPainter::CloseOp()
{
path.close_polygon();
}
inline void BufferPainter::MinMax(Pointf& minv, Pointf& maxv, Pointf p) const
{
p = pathattr.mtx.Transformed(p);
minv.x = min(minv.x, p.x);
minv.y = min(minv.y, p.y);
maxv.x = max(maxv.x, p.x);
maxv.y = max(maxv.y, p.y);
}
bool BufferPainter::PathVisible(double w) const
{
Pointf h = pathattr.mtx.Transformed(w, w);
w = max(fabs(h.x), fabs(h.y));
Pointf min;
Pointf max;
min = max = pathattr.mtx.Transformed(pathrect.TopLeft());
MinMax(min, max, pathrect.TopRight());
MinMax(min, max, pathrect.BottomLeft());
MinMax(min, max, pathrect.BottomRight());
return max.x + w >= 0 && max.y + w >= 0 && min.x - w <= sizef.cx && min.y - w <= sizef.cy;
}
void BufferPainter::SetRbuf()
{
pixf.attach(buffer);
renb.attach(pixf);
renderer.attach(renb);
}
BufferPainter::BufferPainter(ImageBuffer& ib)
: buffer(ib),
curved(path),
curved_trans(curved, attr.mtx)
{
size = ib.GetSize();
sizef = size;
inpath = false;
pathrect = Null;
ccontrol = qcontrol = current = Point(0, 0);
attr.cap = LINECAP_BUTT;
attr.join = LINEJOIN_MITER;
attr.miter_limit = 4;
attr.evenodd = false;
attr.hasclip = false;
attr.cliplevel = 0;
attr.dash_start = 0.0;
attr.opacity = 1.0;
attr.mask = false;
pathattr = attr;
SetRbuf();
}
END_UPP_NAMESPACE
#include "Painter.h"
NAMESPACE_UPP
#define LTIMING(x) RTIMING(x)
void BufferPainter::ClearOp(const RGBA& color)
{
Upp::Fill(~buffer, color, buffer.GetLength());
}
inline void BufferPainter::PathPoint0(double x, double y)
{
pathrect.left = min(pathrect.left, x);
pathrect.top = min(pathrect.top, y);
pathrect.right = max(pathrect.right, x);
pathrect.bottom = max(pathrect.bottom, y);
}
inline void BufferPainter::PathPoint(double& x, double& y, bool rel)
{
x = IsNull(x) ? current.x : rel ? x + current.x : x;
y = IsNull(y) ? current.y : rel ? y + current.y : y;
if(inpath)
PathPoint0(x, y);
else {
path.remove_all();
pathrect.left = pathrect.right = x;
pathrect.top = pathrect.bottom = y;
pathattr = attr;
}
inpath = true;
}
inline void BufferPainter::EndPoint(double& x, double& y, bool rel)
{
PathPoint(x, y, rel);
current = Pointf(x, y);
}
void BufferPainter::MoveOp(double x, double y, bool rel)
{
EndPoint(x, y, rel);
ccontrol = qcontrol = current;
path.move_to(x, y);
inpath = true;
}
void BufferPainter::LineOp(double x, double y, bool rel)
{
EndPoint(x, y, rel);
ccontrol = qcontrol = current;
path.line_to(x, y);
inpath = true;
}
void BufferPainter::QuadraticOp(double x1, double y1, double x, double y, bool rel)
{
PathPoint(x1, y1, rel);
qcontrol = Pointf(x1, y1);
EndPoint(x, y, rel);
ccontrol = current;
path.curve3(x1, y1, x, y);
}
void BufferPainter::QuadraticOp(double x, double y, bool rel)
{
qcontrol = current + current - qcontrol;
PathPoint0(qcontrol.x, qcontrol.y);
EndPoint(x, y, rel);
ccontrol = current;
path.curve3(qcontrol.x, qcontrol.y, x, y);
}
void BufferPainter::CubicOp(double x1, double y1, double x2, double y2, double x, double y, bool rel)
{
PathPoint(x1, y1, rel);
PathPoint(x2, y2, rel);
ccontrol = Pointf(x2, y2);
EndPoint(x, y, rel);
qcontrol = current;
path.curve4(x1, y1, x2, y2, x, y);
}
void BufferPainter::CubicOp(double x2, double y2, double x, double y, bool rel)
{
Pointf c = current + current - ccontrol;
PathPoint0(c.x, c.y);
PathPoint(x2, y2, rel);
ccontrol = Pointf(x2, y2);
EndPoint(x, y, rel);
qcontrol = current;
path.curve4(c.x, c.y, x2, y2, x, y);
}
void BufferPainter::CloseOp()
{
path.close_polygon();
}
inline void BufferPainter::MinMax(Pointf& minv, Pointf& maxv, Pointf p) const
{
p = pathattr.mtx.Transformed(p);
minv.x = min(minv.x, p.x);
minv.y = min(minv.y, p.y);
maxv.x = max(maxv.x, p.x);
maxv.y = max(maxv.y, p.y);
}
bool BufferPainter::PathVisible(double w) const
{
Pointf h = pathattr.mtx.Transformed(w, w);
w = max(fabs(h.x), fabs(h.y));
Pointf min;
Pointf max;
min = max = pathattr.mtx.Transformed(pathrect.TopLeft());
MinMax(min, max, pathrect.TopRight());
MinMax(min, max, pathrect.BottomLeft());
MinMax(min, max, pathrect.BottomRight());
return max.x + w >= 0 && max.y + w >= 0 && min.x - w <= sizef.cx && min.y - w <= sizef.cy;
}
void BufferPainter::SetRbuf()
{
pixf.attach(buffer);
renb.attach(pixf);
renderer.attach(renb);
}
BufferPainter::BufferPainter(ImageBuffer& ib)
: buffer(ib),
curved(path),
curved_trans(curved, attr.mtx)
{
size = ib.GetSize();
sizef = size;
inpath = false;
pathrect = Null;
ccontrol = qcontrol = current = Point(0, 0);
attr.cap = LINECAP_BUTT;
attr.join = LINEJOIN_MITER;
attr.miter_limit = 4;
attr.evenodd = false;
attr.hasclip = false;
attr.cliplevel = 0;
attr.dash_start = 0.0;
attr.opacity = 1.0;
attr.mask = false;
attr.noaa = false;
pathattr = attr;
SetRbuf();
}
END_UPP_NAMESPACE

View file

@ -65,6 +65,8 @@ protected:
virtual void MiterLimitOp(double l);
virtual void EvenOddOp(bool evenodd);
virtual void DashOp(const Vector<double>& dash, double start);
virtual void NoAAOp(bool noaa);
virtual void TransformOp(const Matrix2D& m);
@ -122,7 +124,9 @@ private:
typedef byte value_type;
typedef int calc_type;
typedef agg::const_row_info<RGBA> row_data;
bool noaa;
void attach(ImageBuffer& ib) { buffer = ib; sz = ib.GetSize(); }
int width() const { return sz.cx; }
@ -195,6 +199,7 @@ private:
int cliplevel;
bool hasclip;
bool mask;
bool noaa;
};
Attr attr;

View file

@ -23,9 +23,8 @@ void BufferPainter::EndOp()
void BufferPainter::TransformOp(const Matrix2D& m)
{
ASSERT_(!inpath, "Cannot change transformation during path definition");
pathattr.mtx = m * attr.mtx;
if(!inpath)
attr.mtx = m * attr.mtx;
attr.mtx = m * attr.mtx;
pathattr.mtx = attr.mtx;
}
void BufferPainter::OpacityOp(double o)
@ -73,4 +72,11 @@ void BufferPainter::DashOp(const Vector<double>& dash, double start)
}
}
void BufferPainter::NoAAOp(bool noaa)
{
pathattr.noaa = noaa;
if(!inpath)
attr.noaa = noaa;
}
END_UPP_NAMESPACE

View file

@ -6,6 +6,7 @@ void BufferPainter::FillOp(const RGBA& c)
{
if(inpath)
path.close_polygon();
pixf.noaa = pathattr.noaa;
RGBA color = c;
if(PathVisible(0) && color.a) {
if(pathattr.opacity != 1.0) {
@ -177,6 +178,7 @@ void BufferPainter::FillOp(const Image& image, const Matrix2D& transsrc, dword f
path.close_polygon();
span_alloc sa;
pixf.noaa = pathattr.noaa;
Matrix2D m = transsrc * pathattr.mtx;
m.invert();
UppImageAggSpan sg;

View file

@ -96,7 +96,6 @@ struct sMakeCharOutline : LRUCache<String, FontChar>::Maker {
void Painter::CharacterOp(double x, double y, int ch, Font fnt)
{
RTIMING("Character");
String s;
INTERLOCKED {
static LRUCache<String, FontChar> cache;
@ -106,7 +105,7 @@ void Painter::CharacterOp(double x, double y, int ch, Font fnt)
h.fc.chr = ch;
s = cache.Get(h);
}
RenderCharPath(s, s.GetLength(), *this, x, y);
RenderCharPath(s, s.GetLength(), *this, x, y + fnt.Info().GetAscent());
EvenOdd(true);
}

View file

@ -1,151 +1,151 @@
//----------------------------------------------------------------------------
// Anti-Grain Geometry - Version 2.4
// Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com)
//
// Permission to copy, use, modify, sell and distribute this software
// is granted provided this copyright notice appears in all coM_PIes.
// This software is provided "as is" without express or implied
// warranty, and with no claim as to its suitability for any purpose.
//
//----------------------------------------------------------------------------
// Contact: mcseem@antigrain.com
// mcseemagg@yahoo.com
// http://www.antigrain.com
//----------------------------------------------------------------------------
// Recycled for U++ by Miroslav Fidler 2008
#include "Painter.h"
NAMESPACE_UPP
#ifdef PLATFORM_X11
static inline double ft_dbl(int p)
{
return double(p) / 64.0;
}
bool RenderOutline(const FT_Outline& outline, Painter& path, double xx, double yy)
{
FT_Vector v_last;
FT_Vector v_control;
FT_Vector v_start;
double x1, y1, x2, y2, x3, y3;
FT_Vector* point;
FT_Vector* limit;
char* tags;
int n; // index of contour in outline
char tag; // current point's state
int first = 0; // index of first point in contour
for(n = 0; n < outline.n_contours; n++) {
int last = outline.contours[n];
limit = outline.points + last;
v_start = outline.points[first];
v_last = outline.points[last];
v_control = v_start;
point = outline.points + first;
tags = outline.tags + first;
tag = FT_CURVE_TAG(tags[0]);
if(tag == FT_CURVE_TAG_CUBIC) return false;
if(tag == FT_CURVE_TAG_CONIC) {
if(FT_CURVE_TAG(outline.tags[last]) == FT_CURVE_TAG_ON) {
// start at last point if it is on the curve
v_start = v_last;
limit--;
}
else {
// if both first and last points are conic,
// start at their middle and record its position
// for closure
v_start.x = (v_start.x + v_last.x) / 2;
v_start.y = (v_start.y + v_last.y) / 2;
v_last = v_start;
}
point--;
tags--;
}
path.Move(ft_dbl(v_start.x) + xx, -ft_dbl(v_start.y) + yy);
while(point < limit) {
point++;
tags++;
tag = FT_CURVE_TAG(tags[0]);
switch(tag) {
case FT_CURVE_TAG_ON:
path.Line(ft_dbl(point->x) + xx, -ft_dbl(point->y) + yy);
continue;
case FT_CURVE_TAG_CONIC:
v_control.x = point->x;
v_control.y = point->y;
Do_Conic:
if(point < limit) {
FT_Vector vec;
FT_Vector v_middle;
point++;
tags++;
tag = FT_CURVE_TAG(tags[0]);
vec.x = point->x;
vec.y = point->y;
if(tag == FT_CURVE_TAG_ON) {
path.Quadratic(ft_dbl(v_control.x) + xx, -ft_dbl(v_control.y) + yy,
ft_dbl(vec.x) + xx, -ft_dbl(vec.y) + yy);
continue;
}
if(tag != FT_CURVE_TAG_CONIC) return false;
v_middle.x = (v_control.x + vec.x) / 2;
v_middle.y = (v_control.y + vec.y) / 2;
path.Quadratic(ft_dbl(v_control.x) + xx, -ft_dbl(v_control.y) + yy,
ft_dbl(v_middle.x) + xx, -ft_dbl(v_middle.y) + yy);
v_control = vec;
goto Do_Conic;
}
path.Quadratic(ft_dbl(v_control.x) + xx, -ft_dbl(v_control.y) + yy,
ft_dbl(v_start.x) + xx, -ft_dbl(v_start.y) + yy);
goto Close;
default:
FT_Vector vec1, vec2;
if(point + 1 > limit || FT_CURVE_TAG(tags[1]) != FT_CURVE_TAG_CUBIC)
return false;
vec1.x = point[0].x;
vec1.y = point[0].y;
vec2.x = point[1].x;
vec2.y = point[1].y;
point += 2;
tags += 2;
if(point <= limit) {
FT_Vector vec;
vec.x = point->x;
vec.y = point->y;
path.Cubic(ft_dbl(vec1.x) + xx, -ft_dbl(vec1.y) + yy,
ft_dbl(vec2.x) + xx, -ft_dbl(vec2.y) + yy,
ft_dbl(vec.x) + xx, -ft_dbl(vec.y) + yy);
continue;
}
path.Cubic(ft_dbl(vec1.x) + xx, -ft_dbl(vec1.y) + yy,
ft_dbl(vec2.x) + xx, -ft_dbl(vec2.y) + yy,
ft_dbl(v_start.x) + xx, -ft_dbl(v_start.y) + yy);
goto Close;
}
}
Close:
path.Close();
first = last + 1;
}
return true;
}
void Painter::CharacterOp(double x, double y, int ch, Font fnt)
{
FontInfo fi = fnt.Info();
FT_Face face = XftLockFace(fi.GetXftFont());
int glyph_index = FT_Get_Char_Index(face, ch);
if(FT_Load_Glyph(face, glyph_index, FT_LOAD_DEFAULT) == 0)
RenderOutline(face->glyph->outline, *this, x, y);
XftUnlockFace(fi.GetXftFont());
}
#endif
END_UPP_NAMESPACE
//----------------------------------------------------------------------------
// Anti-Grain Geometry - Version 2.4
// Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com)
//
// Permission to copy, use, modify, sell and distribute this software
// is granted provided this copyright notice appears in all coM_PIes.
// This software is provided "as is" without express or implied
// warranty, and with no claim as to its suitability for any purpose.
//
//----------------------------------------------------------------------------
// Contact: mcseem@antigrain.com
// mcseemagg@yahoo.com
// http://www.antigrain.com
//----------------------------------------------------------------------------
// Recycled for U++ by Miroslav Fidler 2008
#include "Painter.h"
NAMESPACE_UPP
#ifdef PLATFORM_X11
static inline double ft_dbl(int p)
{
return double(p) / 64.0;
}
bool RenderOutline(const FT_Outline& outline, Painter& path, double xx, double yy)
{
FT_Vector v_last;
FT_Vector v_control;
FT_Vector v_start;
double x1, y1, x2, y2, x3, y3;
FT_Vector* point;
FT_Vector* limit;
char* tags;
int n; // index of contour in outline
char tag; // current point's state
int first = 0; // index of first point in contour
for(n = 0; n < outline.n_contours; n++) {
int last = outline.contours[n];
limit = outline.points + last;
v_start = outline.points[first];
v_last = outline.points[last];
v_control = v_start;
point = outline.points + first;
tags = outline.tags + first;
tag = FT_CURVE_TAG(tags[0]);
if(tag == FT_CURVE_TAG_CUBIC) return false;
if(tag == FT_CURVE_TAG_CONIC) {
if(FT_CURVE_TAG(outline.tags[last]) == FT_CURVE_TAG_ON) {
// start at last point if it is on the curve
v_start = v_last;
limit--;
}
else {
// if both first and last points are conic,
// start at their middle and record its position
// for closure
v_start.x = (v_start.x + v_last.x) / 2;
v_start.y = (v_start.y + v_last.y) / 2;
v_last = v_start;
}
point--;
tags--;
}
path.Move(ft_dbl(v_start.x) + xx, -ft_dbl(v_start.y) + yy);
while(point < limit) {
point++;
tags++;
tag = FT_CURVE_TAG(tags[0]);
switch(tag) {
case FT_CURVE_TAG_ON:
path.Line(ft_dbl(point->x) + xx, -ft_dbl(point->y) + yy);
continue;
case FT_CURVE_TAG_CONIC:
v_control.x = point->x;
v_control.y = point->y;
Do_Conic:
if(point < limit) {
FT_Vector vec;
FT_Vector v_middle;
point++;
tags++;
tag = FT_CURVE_TAG(tags[0]);
vec.x = point->x;
vec.y = point->y;
if(tag == FT_CURVE_TAG_ON) {
path.Quadratic(ft_dbl(v_control.x) + xx, -ft_dbl(v_control.y) + yy,
ft_dbl(vec.x) + xx, -ft_dbl(vec.y) + yy);
continue;
}
if(tag != FT_CURVE_TAG_CONIC) return false;
v_middle.x = (v_control.x + vec.x) / 2;
v_middle.y = (v_control.y + vec.y) / 2;
path.Quadratic(ft_dbl(v_control.x) + xx, -ft_dbl(v_control.y) + yy,
ft_dbl(v_middle.x) + xx, -ft_dbl(v_middle.y) + yy);
v_control = vec;
goto Do_Conic;
}
path.Quadratic(ft_dbl(v_control.x) + xx, -ft_dbl(v_control.y) + yy,
ft_dbl(v_start.x) + xx, -ft_dbl(v_start.y) + yy);
goto Close;
default:
FT_Vector vec1, vec2;
if(point + 1 > limit || FT_CURVE_TAG(tags[1]) != FT_CURVE_TAG_CUBIC)
return false;
vec1.x = point[0].x;
vec1.y = point[0].y;
vec2.x = point[1].x;
vec2.y = point[1].y;
point += 2;
tags += 2;
if(point <= limit) {
FT_Vector vec;
vec.x = point->x;
vec.y = point->y;
path.Cubic(ft_dbl(vec1.x) + xx, -ft_dbl(vec1.y) + yy,
ft_dbl(vec2.x) + xx, -ft_dbl(vec2.y) + yy,
ft_dbl(vec.x) + xx, -ft_dbl(vec.y) + yy);
continue;
}
path.Cubic(ft_dbl(vec1.x) + xx, -ft_dbl(vec1.y) + yy,
ft_dbl(vec2.x) + xx, -ft_dbl(vec2.y) + yy,
ft_dbl(v_start.x) + xx, -ft_dbl(v_start.y) + yy);
goto Close;
}
}
Close:
path.Close();
first = last + 1;
}
return true;
}
void Painter::CharacterOp(double x, double y, int ch, Font fnt)
{
FontInfo fi = fnt.Info();
FT_Face face = XftLockFace(fi.GetXftFont());
int glyph_index = FT_Get_Char_Index(face, ch);
if(FT_Load_Glyph(face, glyph_index, FT_LOAD_DEFAULT) == 0)
RenderOutline(face->glyph->outline, *this, x, y + fnt.Info().GetAscent());
XftUnlockFace(fi.GetXftFont());
}
#endif
END_UPP_NAMESPACE

View file

@ -30,7 +30,7 @@ void Painter::Paint(const Painting& pic)
{
StringStream ss(pic.cmd);
Pointf p, p1, p2;
Color c, c1;
RGBA c, c1;
Value v;
int f, ch, n, hasdx;
Matrix2D m;
@ -117,6 +117,7 @@ void Painter::Paint(const Painting& pic)
sGet(w, ss);
sGet(c, ss);
Stroke(w, c);
DDUMP((Color)c);
break;
case PAINTING_STROKE_IMAGE:
sGet(w, ss);
@ -206,6 +207,9 @@ void Painter::Paint(const Painting& pic)
Dash(dash, r);
}
break;
case PAINTING_NOAA:
NoAA(ss.Get());
break;
case PAINTING_TRANSFORM:
sGet(m, ss);
Transform(m);
@ -223,26 +227,28 @@ void Painter::Paint(const Painting& pic)
}
}
void PaintImageBufferPaintingFn(ImageBuffer& ib, const Painting& p, Size sz, Point pos)
void PaintImageBufferPaintingFn(ImageBuffer& ib, const Painting& p, Size sz, Point pos, bool noaa)
{
BufferPainter sw(ib);
sw.NoAA(noaa);
Sizef psz = p.GetSize();
sw.Translate(-pos.x, -pos.y);
sw.Scale(sz.cx / psz.cx, sz.cy / psz.cy);
sw.Paint(p);
}
void PaintImageBufferDrawingFn(ImageBuffer& ib, const Drawing& iw)
void PaintImageBufferDrawingFn(ImageBuffer& ib, const Drawing& iw, bool noaa)
{
BufferPainter sw(ib);
sw.NoAA(noaa);
Sizef sz = ib.GetSize();
Size isz = iw.GetSize();
sw.Scale(sz.cx / isz.cx, sz.cy / isz.cy);
sw.DrawDrawing(0, 0, isz.cx, isz.cy, iw);
}
void RegisterPaintingFns__(void (*ig)(ImageBuffer& ib, const Painting& pw, Size sz, Point pos),
void (*iw)(ImageBuffer& ib, const Drawing& p));
void RegisterPaintingFns__(void (*ig)(ImageBuffer& ib, const Painting& pw, Size sz, Point pos, bool noaa),
void (*iw)(ImageBuffer& ib, const Drawing& p, bool noaa));
INITBLOCK

View file

@ -42,6 +42,7 @@ bool Painter::ExcludeClipOp(const Rect& r)
bool Painter::IntersectClipOp(const Rect& r)
{
return true;
RectPath(r);
Clip();
return true;
@ -123,6 +124,17 @@ void Painter::DrawTextOp(int x, int y, int angle, const wchar *text, Font font,
End();
}
void Painter::DrawPaintingOp(const Rect& target, const Painting& p)
{
Size sz = target.GetSize();
Sizef psz = p.GetSize();
Begin();
Translate(target.left, target.top);
Scale(sz.cx / psz.cx, sz.cy / psz.cy);
Paint(p);
End();
}
Painter& Painter::Move(double x, double y)
{
return Move(x, y, false);

View file

@ -99,6 +99,7 @@ protected:
virtual void DrawEllipseOp(const Rect& r, Color color, int pen, Color pencolor);
virtual void DrawTextOp(int x, int y, int angle, const wchar *text, Font font,
Color ink, int n, const int *dx);
virtual void DrawPaintingOp(const Rect& target, const Painting& w);
protected:
virtual void ClearOp(const RGBA& color) = 0;
@ -144,6 +145,7 @@ protected:
virtual void MiterLimitOp(double l) = 0;
virtual void EvenOddOp(bool evenodd) = 0;
virtual void DashOp(const Vector<double>& dash, double start = 0) = 0;
virtual void NoAAOp(bool noaa) = 0;
virtual void TransformOp(const Matrix2D& m) = 0;
@ -229,6 +231,7 @@ public:
Painter& EvenOdd(bool evenodd);
Painter& Dash(const Vector<double>& dash, double start = 0);
Painter& Dash(const char *dash, double start = 0);
Painter& NoAA(bool noaa = true);
void Transform(const Matrix2D& m);

View file

@ -1,185 +1,191 @@
NAMESPACE_UPP
inline void Painter::Clear(const RGBA& color)
{
ClearOp(color);
}
inline Painter& Painter::Move(double x, double y, bool rel)
{
MoveOp(x, y, rel);
return *this;
}
inline Painter& Painter::Line(double x, double y, bool rel)
{
LineOp(x, y, rel);
return *this;
}
inline Painter& Painter::Quadratic(double x1, double y1, double x, double y, bool rel)
{
QuadraticOp(x1, y1, x, y, rel);
return *this;
}
inline Painter& Painter::Quadratic(double x, double y, bool rel)
{
QuadraticOp(x, y, rel);
return *this;
}
inline Painter& Painter::Cubic(double x1, double y1, double x2, double y2, double x, double y, bool rel)
{
CubicOp(x1, y1, x2, y2, x, y, rel);
return *this;
}
inline Painter& Painter::Cubic(double x2, double y2, double x, double y, bool rel)
{
CubicOp(x2, y2, x, y, rel);
return *this;
}
inline Painter& Painter::Close()
{
CloseOp();
return *this;
}
inline Painter& Painter::Fill(const RGBA& color)
{
FillOp(color);
return *this;
}
inline Painter& Painter::Fill(const Image& image, const Matrix2D& transsrc, dword flags)
{
FillOp(image, transsrc, flags);
return *this;
}
inline Painter& Painter::Fill(double x1, double y1, const RGBA& color1,
double x2, double y2, const RGBA& color2, int style)
{
FillOp(x1, y1, color1, x2, y2, color2, style);
return *this;
}
inline Painter& Painter::Fill(double fx, double fy, const RGBA& color1, double x1, double y1, double r, const RGBA& color2, int style)
{
FillOp(fx, fy, color1, x1, y1, r, color2, style);
return *this;
}
inline Painter& Painter::Fill(double x1, double y1, const RGBA& color1, double r, const RGBA& color2, int style)
{
return Fill(x1, y1, color1, x1, y1, r, color2, style);
}
inline Painter& Painter::Stroke(double width, const RGBA& color)
{
StrokeOp(width, color);
return *this;
}
inline Painter& Painter::Stroke(double width, const Image& image, const Matrix2D& transsrc, dword flags)
{
StrokeOp(width, image, transsrc, flags);
return *this;
}
inline Painter& Painter::Stroke(double width, double x1, double y1, const RGBA& color1,
double x2, double y2, const RGBA& color2, int style)
{
StrokeOp(width, x1, y1, color1, x2, y2, color2, style);
return *this;
}
inline Painter& Painter::Stroke(double width, double fx, double fy, const RGBA& color1,
double x1, double y1, double r, const RGBA& color2, int style)
{
StrokeOp(width, fx, fy, color1, x1, y1, r, color2, style);
return *this;
}
inline Painter& Painter::Stroke(double width, double x1, double y1, const RGBA& color1, double r, const RGBA& color2, int style)
{
return Stroke(width, x1, y1, color1, x1, y1, r, color2, style);
}
inline Painter& Painter::Clip()
{
ClipOp();
return *this;
}
inline Painter& Painter::ColorStop(double pos, const RGBA& color)
{
ColorStopOp(pos, color);
return *this;
}
inline Painter& Painter::ClearStops()
{
ClearStopsOp();
return *this;
}
inline Painter& Painter::Opacity(double o)
{
OpacityOp(o);
return *this;
}
inline Painter& Painter::LineCap(int linecap)
{
LineCapOp(linecap);
return *this;
}
inline Painter& Painter::LineJoin(int linejoin)
{
LineJoinOp(linejoin);
return *this;
}
inline Painter& Painter::MiterLimit(double l)
{
MiterLimitOp(l);
return *this;
}
inline Painter& Painter::EvenOdd(bool evenodd)
{
EvenOddOp(evenodd);
return *this;
}
inline Painter& Painter::Dash(const Vector<double>& dash, double start)
{
DashOp(dash, start);
return *this;
}
inline void Painter::Transform(const Matrix2D& m)
{
TransformOp(m);
}
inline void Painter::Begin()
{
BeginOp();
}
inline void Painter::End()
{
EndOp();
}
inline void Painter::BeginMask()
{
BeginMaskOp();
}
END_UPP_NAMESPACE
NAMESPACE_UPP
inline void Painter::Clear(const RGBA& color)
{
ClearOp(color);
}
inline Painter& Painter::Move(double x, double y, bool rel)
{
MoveOp(x, y, rel);
return *this;
}
inline Painter& Painter::Line(double x, double y, bool rel)
{
LineOp(x, y, rel);
return *this;
}
inline Painter& Painter::Quadratic(double x1, double y1, double x, double y, bool rel)
{
QuadraticOp(x1, y1, x, y, rel);
return *this;
}
inline Painter& Painter::Quadratic(double x, double y, bool rel)
{
QuadraticOp(x, y, rel);
return *this;
}
inline Painter& Painter::Cubic(double x1, double y1, double x2, double y2, double x, double y, bool rel)
{
CubicOp(x1, y1, x2, y2, x, y, rel);
return *this;
}
inline Painter& Painter::Cubic(double x2, double y2, double x, double y, bool rel)
{
CubicOp(x2, y2, x, y, rel);
return *this;
}
inline Painter& Painter::Close()
{
CloseOp();
return *this;
}
inline Painter& Painter::Fill(const RGBA& color)
{
FillOp(color);
return *this;
}
inline Painter& Painter::Fill(const Image& image, const Matrix2D& transsrc, dword flags)
{
FillOp(image, transsrc, flags);
return *this;
}
inline Painter& Painter::Fill(double x1, double y1, const RGBA& color1,
double x2, double y2, const RGBA& color2, int style)
{
FillOp(x1, y1, color1, x2, y2, color2, style);
return *this;
}
inline Painter& Painter::Fill(double fx, double fy, const RGBA& color1, double x1, double y1, double r, const RGBA& color2, int style)
{
FillOp(fx, fy, color1, x1, y1, r, color2, style);
return *this;
}
inline Painter& Painter::Fill(double x1, double y1, const RGBA& color1, double r, const RGBA& color2, int style)
{
return Fill(x1, y1, color1, x1, y1, r, color2, style);
}
inline Painter& Painter::Stroke(double width, const RGBA& color)
{
StrokeOp(width, color);
return *this;
}
inline Painter& Painter::Stroke(double width, const Image& image, const Matrix2D& transsrc, dword flags)
{
StrokeOp(width, image, transsrc, flags);
return *this;
}
inline Painter& Painter::Stroke(double width, double x1, double y1, const RGBA& color1,
double x2, double y2, const RGBA& color2, int style)
{
StrokeOp(width, x1, y1, color1, x2, y2, color2, style);
return *this;
}
inline Painter& Painter::Stroke(double width, double fx, double fy, const RGBA& color1,
double x1, double y1, double r, const RGBA& color2, int style)
{
StrokeOp(width, fx, fy, color1, x1, y1, r, color2, style);
return *this;
}
inline Painter& Painter::Stroke(double width, double x1, double y1, const RGBA& color1, double r, const RGBA& color2, int style)
{
return Stroke(width, x1, y1, color1, x1, y1, r, color2, style);
}
inline Painter& Painter::Clip()
{
ClipOp();
return *this;
}
inline Painter& Painter::ColorStop(double pos, const RGBA& color)
{
ColorStopOp(pos, color);
return *this;
}
inline Painter& Painter::ClearStops()
{
ClearStopsOp();
return *this;
}
inline Painter& Painter::Opacity(double o)
{
OpacityOp(o);
return *this;
}
inline Painter& Painter::LineCap(int linecap)
{
LineCapOp(linecap);
return *this;
}
inline Painter& Painter::LineJoin(int linejoin)
{
LineJoinOp(linejoin);
return *this;
}
inline Painter& Painter::MiterLimit(double l)
{
MiterLimitOp(l);
return *this;
}
inline Painter& Painter::EvenOdd(bool evenodd)
{
EvenOddOp(evenodd);
return *this;
}
inline Painter& Painter::Dash(const Vector<double>& dash, double start)
{
DashOp(dash, start);
return *this;
}
inline Painter& Painter::NoAA(bool noaa)
{
NoAAOp(noaa);
return *this;
}
inline void Painter::Transform(const Matrix2D& m)
{
TransformOp(m);
}
inline void Painter::Begin()
{
BeginOp();
}
inline void Painter::End()
{
EndOp();
}
inline void Painter::BeginMask()
{
BeginMaskOp();
}
END_UPP_NAMESPACE

View file

@ -93,6 +93,7 @@ void PaintingPainter::StrokeOp(double width, const RGBA& color)
Put(PAINTING_STROKE_SOLID);
Putf(width);
Put(color);
DDUMP(Color(color));
}
void PaintingPainter::StrokeOp(double width, const Image& image, const Matrix2D& transsrc, dword flags)
@ -135,6 +136,7 @@ void PaintingPainter::ClipOp()
void PaintingPainter::CharacterOp(double x, double y, int ch, Font fnt)
{
Put(PAINTING_CHARACTER);
Putf(x, y);
Put32(ch);
Put(fnt);
}
@ -204,6 +206,12 @@ void PaintingPainter::DashOp(const Vector<double>& dash, double start)
Putf(start);
}
void PaintingPainter::NoAAOp(bool noaa)
{
Put(PAINTING_NOAA);
Put(noaa);
}
void PaintingPainter::TransformOp(const Matrix2D& m)
{
Put(PAINTING_TRANSFORM);

View file

@ -1,15 +1,3 @@
class Painting {
String cmd;
ValueArray data;
Sizef size;
friend class PaintingPainter;
friend class Painter;
public:
Sizef GetSize() const { return size; }
};
enum {
PAINTING_EOF,
PAINTING_CLEAR,
@ -51,6 +39,7 @@ enum {
PAINTING_MITERLIMIT,
PAINTING_EVENODD,
PAINTING_DASH,
PAINTING_NOAA,
PAINTING_TRANSFORM,
PAINTING_BEGIN,
@ -115,6 +104,7 @@ protected:
virtual void MiterLimitOp(double l);
virtual void EvenOddOp(bool evenodd);
virtual void DashOp(const Vector<double>& dash, double start);
virtual void NoAAOp(bool noaa);
virtual void TransformOp(const Matrix2D& m);
@ -136,6 +126,3 @@ public:
PaintingPainter(double cx, double cy) { Create(cx, cy); }
PaintingPainter(Sizef sz) { Create(sz); }
};
void PaintImageBuffer(ImageBuffer& ib, const Painting& p, Size sz, Point pos);
void PaintImageBuffer(ImageBuffer& ib, const Drawing& p);

View file

@ -6,6 +6,8 @@ void BufferPainter::upp_pixfmt::blend_hline(int x, int y, int len, RGBA c, byte
{
if(c.a == 0) return;
RGBA *t = ptr(x, y);
if(noaa)
cover = cover > 127 ? 255 : 0;
if((c.a & cover) == 255) {
#if 1
while(len >= 16) {
@ -57,6 +59,8 @@ void BufferPainter::upp_pixfmt::blend_solid_hspan(int x, int y, int len,
RGBA *e = t + len;
while(t < e) {
byte cover = *covers++;
if(noaa)
cover = cover > 127 ? 255 : 0;
if((cover & c.a) == 255) // is it worth it?
*t++ = c;
else
@ -69,9 +73,14 @@ void BufferPainter::upp_pixfmt::blend_color_hspan(int x, int y, int len, const R
{
RGBA *t = ptr(x, y);
RGBA *e = t + len;
if(noaa)
cover = cover > 127 ? 255 : 0;
while(t < e) {
if(covers)
if(covers) {
cover = *covers++;
if(noaa)
cover = cover > 127 ? 255 : 0;
}
if((cover & colors->a) == 255)
*t = *colors;
else

View file

@ -213,6 +213,7 @@ void BufferPainter::FillOp(double fx, double fy, const RGBA& color1,
{
if(inpath)
path.close_polygon();
pixf.noaa = pathattr.noaa;
span_alloc sa;
Matrix2D m = pathattr.mtx;
m.invert();

View file

@ -8,7 +8,6 @@ void Painter::TextOp(double x, double y, const wchar *text, Font fnt, int n, dou
FontInfo fi = fnt.Info();
if(n < 0)
n = wstrlen(text);
y += fi.GetAscent();
while(n) {
int ch = *text++;
Character(x, y, ch, fnt);