Hopefully fixed color and artifacts problem when printing Images on specific printers...

git-svn-id: svn://ultimatepp.org/upp/trunk@688 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
cxl 2008-12-03 11:10:05 +00:00
parent b46edb7e35
commit 25d0ef2e95
7 changed files with 115 additions and 33 deletions

View file

@ -410,7 +410,11 @@ bool FindFile::Search(const char *name) {
handle = UnicodeWin32().FindFirstFileW(ToSystemCharsetW(name), w);
else
handle = FindFirstFile(ToSystemCharset(name), a);
return handle != INVALID_HANDLE_VALUE;
if(handle == INVALID_HANDLE_VALUE)
return false;
if(!PatternMatch(pattern, GetName()))
return Next();
return true;
}
void FindFile::Close() {

View file

@ -8,6 +8,43 @@ NAMESPACE_UPP
static StaticMutex sDrawLock;
Size Draw::GetNativeDpi() const
{
return nativeDpi;
}
int Draw::GetNativeX(int x) const
{
return inchPixels != nativeDpi ? iscale(x, nativeDpi.cx, 600) : x;
}
int Draw::GetNativeY(int y) const
{
return inchPixels != nativeDpi ? iscale(y, nativeDpi.cy, 600) : y;
}
void Draw::Native(int& x, int& y) const
{
x = GetNativeX(x);
y = GetNativeY(y);
}
void Draw::Native(Point& p) const
{
Native(p.x, p.y);
}
void Draw::Native(Size& sz) const
{
Native(sz.cx, sz.cy);
}
void Draw::Native(Rect& r) const
{
Native(r.left, r.top);
Native(r.right, r.bottom);
}
#ifdef BENCH
static TimingInspector sDrawTiming("DRAW");
#endif
@ -58,11 +95,14 @@ Stream& Draw::PutRect(const Rect& r)
void Draw::DrawImageOp(int x, int y, int cx, int cy, const Image& img, const Rect& src, Color color)
{
DrawLock __;
BeginNative();
Native(x, y);
Native(cx, cy);
LTIMING("DrawImageOp");
if(IsNull(src))
return;
Size sz = Size(cx, cy);
if((cx > 2000 || cy > 2000) && IsNull(color) && (!IsSystem() || IsPrinter())) {
if((cx > 2000 || cy > 1500) && IsNull(color) && IsPrinter()) {
int yy = 0;
ImageRaster ir(img);
RescaleImage rm;
@ -75,14 +115,15 @@ void Draw::DrawImageOp(int x, int y, int cx, int cy, const Image& img, const Rec
DrawImageBandRLE(*this, x, y + yy, ib, 16);
yy += ccy;
}
return;
}
else
if(src.GetSize() == sz)
img.PaintImage(*this, x, y, src, color);
else {
Image h = Rescale(img, Size(cx, cy), src);
h.PaintImage(*this, x, y, h.GetSize(), color);
}
EndNative();
}
// -------------------------------

View file

@ -496,8 +496,10 @@ protected:
Size pagePixels;
Size pageMMs;
Size inchPixels;
Size nativeDpi;
Size sheetPixels;
Point pageOffset;
int native;
Draw();
@ -520,6 +522,7 @@ protected:
FontInfo lastFont;
Point actual_offset;
Point actual_offset_bak;
struct Cloff : Moveable<Cloff> {
Point org;
#ifdef PLATFORM_WIN32
@ -571,6 +574,8 @@ protected:
void Reset();
void SetOrg();
friend HPALETTE GetQlibPalette();
void DotsMode();
static const char *FontScreenSans;
static const char *FontScreenSerif;
@ -640,6 +645,17 @@ public:
bool Pixels() const { return pixels; }
bool Dots() const { return !pixels; }
bool IsNative() const { return native; }
void BeginNative();
void EndNative();
Size GetNativeDpi() const;
int GetNativeX(int x) const;
int GetNativeY(int x) const;
void Native(int& x, int& y) const;
void Native(Point& p) const;
void Native(Size& sz) const;
void Native(Rect& r) const;
bool IsPrinter() const { return printer; }
bool IsAborted() const { return aborted; }

View file

@ -29,16 +29,14 @@ One<DataDrawer> DataDrawer::Create(const String& id)
return NULL;
}
bool IsEqColumn(const Image& m, int x, RGBA c)
bool IsWhiteColumn(const Image& m, int x)
{
LTIMING("IsEqColumn");
Size sz = m.GetSize();
const RGBA *s = ~m + x;
if(c.a != 255)
return false;
while(sz.cy > 1) {
s += sz.cx;
if(*s != c)
if((s->a & s->r & s->g & s->b) != 255)
return false;
sz.cy--;
}
@ -68,14 +66,13 @@ void DrawImageBandRLE(Draw& w, int x, int y, const Image& m, int minp)
#endif
while(xi < cx) {
int xi0 = xi;
RGBA c = m[0][xi0];
while(w.Dots() && IsEqColumn(m, xi, c) && xi < cx)
while(w.Dots() && IsWhiteColumn(m, xi) && xi < cx)
xi++;
if(xi - xi0 >= 16) {
#ifdef BENCHMARK_RLE
sRle += xi - xi0;
#endif
w.DrawRect(x + xi0, y, xi - xi0, ccy, c);
w.DrawRect(x + xi0, y, xi - xi0, ccy, White);
Fill(~todo + xi0, ~todo + xi, false);
}
xi++;
@ -87,7 +84,7 @@ void DrawImageBandRLE(Draw& w, int x, int y, const Image& m, int minp)
int xi0 = xi;
while(xi < cx && todo[xi] && xi - xi0 < 2000)
xi++;
w.DrawImage(x + xi0, y, Crop(m, xi0, 0, xi - xi0, ccy));
m.PaintImage(w, x + xi0, y, RectC(xi0, 0, xi - xi0, ccy), Null);
}
else
xi++;
@ -96,6 +93,9 @@ void DrawImageBandRLE(Draw& w, int x, int y, const Image& m, int minp)
void Draw::DrawDataOp(int x, int y, int cx, int cy, const String& data, const char *id)
{
DrawLock __;
BeginNative();
Native(x, y);
Native(cx, cy);
One<DataDrawer> dd = DataDrawer::Create(id);
if(dd) {
dd->Open(data, cx, cy);
@ -115,6 +115,7 @@ void Draw::DrawDataOp(int x, int y, int cx, int cy, const String& data, const ch
DrawImage(x, y, m);
}
}
EndNative();
}
DataDrawer::~DataDrawer() {}

View file

@ -190,6 +190,34 @@ Size Draw::GetSizeCaps(int i, int j) const {
return Size(GetDeviceCaps(handle, i), GetDeviceCaps(handle, j));
}
void Draw::DotsMode()
{
::SetMapMode(handle, MM_ANISOTROPIC);
::SetViewportExtEx(handle, nativeDpi.cx, nativeDpi.cy, NULL);
::SetViewportOrgEx(handle, 0, 0, NULL);
::SetWindowExtEx(handle, 600, 600, NULL);
::SetWindowOrgEx(handle, 0, 0, NULL);
}
void Draw::BeginNative()
{
if(inchPixels != nativeDpi && ++native == 1) {
::SetMapMode(handle, MM_TEXT);
actual_offset_bak = actual_offset;
Native(actual_offset);
SetOrg();
}
}
void Draw::EndNative()
{
if(inchPixels != nativeDpi && --native == 0) {
DotsMode();
actual_offset = actual_offset_bak;
SetOrg();
}
}
void Draw::LoadCaps() {
DrawLock __;
color16 = false;
@ -198,22 +226,10 @@ void Draw::LoadCaps() {
color16 = GetDeviceCaps(handle, SIZEPALETTE) != 256;
pagePixels = GetSizeCaps(HORZRES, VERTRES);
pageMMs = GetSizeCaps(HORZSIZE, VERTSIZE);
inchPixels = GetSizeCaps(LOGPIXELSX, LOGPIXELSY);
nativeDpi = inchPixels = GetSizeCaps(LOGPIXELSX, LOGPIXELSY);
sheetPixels = GetSizeCaps(PHYSICALWIDTH, PHYSICALHEIGHT);
pageOffset = GetSizeCaps(PHYSICALOFFSETX, PHYSICALOFFSETY);
is_mono = GetDeviceCaps(handle, BITSPIXEL) == 1 && GetDeviceCaps(handle, PLANES) == 1;
/*
if(!is_mono)
{
HBITMAP hbmp = (HBITMAP)GetCurrentObject(handle, OBJ_BITMAP);
if(hbmp)
{
BITMAP bmp;
GetObject(hbmp, sizeof(bmp), &bmp);
is_mono = bmp.bmPlanes == 1 && bmp.bmBitsPixel == 1;
}
}
*/
}
void Draw::SetDevice(const char *s) {
@ -390,16 +406,14 @@ void PrintDraw::InitPrinter()
Init();
printer = true;
pixels = false;
::SetMapMode(handle, MM_ANISOTROPIC);
::SetViewportExtEx(handle, inchPixels.cx, inchPixels.cy, NULL);
::SetViewportOrgEx(handle, 0, 0, NULL);
::SetWindowExtEx(handle, 600, 600, NULL);
::SetWindowOrgEx(handle, 0, 0, NULL);
nativeDpi = inchPixels;
DotsMode();
native = 0;
actual_offset = Point(0, 0);
pagePixels.cx=600*pagePixels.cx/inchPixels.cx;
pagePixels.cy=600*pagePixels.cy/inchPixels.cy;
inchPixels.cx=600;
inchPixels.cy=600;
pagePixels.cx = 600 * pagePixels.cx / inchPixels.cx;
pagePixels.cy = 600 * pagePixels.cy / inchPixels.cy;
inchPixels.cx = 600;
inchPixels.cy = 600;
}
void PrintDraw::StartPage()

View file

@ -378,6 +378,11 @@ Draw::Draw()
Init();
}
void Draw::BeginNative() {}
void Draw::EndNative() {}
#ifdef PLATFORM_XFT
Draw::Draw(Drawable _dw, GC _gc, XftDraw *_xftdraw, const Vector<Rect>& _clip)
#else

View file

@ -175,6 +175,7 @@ private:
void PaintImage(Draw& w, int x, int y, const Rect& src, Color c) const;
friend void SetPaintOnly___(Image& m);
friend void DrawImageBandRLE(Draw& w, int x, int y, const Image& m, int minp);
#ifdef PLATFORM_WIN32
#ifndef PLATFORM_WINCE