From 90bf24af9c95fe23b42da08492a2daee0ef94fda Mon Sep 17 00:00:00 2001 From: cxl Date: Tue, 4 Aug 2009 11:50:18 +0000 Subject: [PATCH] Draw: Numerous fixes git-svn-id: svn://ultimatepp.org/upp/trunk@1473 f0d560ea-af0d-0410-9eb7-867de7ffcac7 --- uppsrc/CtrlCore/DrawWin32.cpp | 2 +- uppsrc/CtrlCore/MetaFile.cpp | 1 + uppsrc/DocTypes/DocTypes.cpp | 5 +- uppsrc/Draw/Drawing.cpp | 98 ++++++++++++++++------------------- uppsrc/Painter/DrawOp.cpp | 5 +- 5 files changed, 51 insertions(+), 60 deletions(-) diff --git a/uppsrc/CtrlCore/DrawWin32.cpp b/uppsrc/CtrlCore/DrawWin32.cpp index a77f3d367..0894bf9f5 100644 --- a/uppsrc/CtrlCore/DrawWin32.cpp +++ b/uppsrc/CtrlCore/DrawWin32.cpp @@ -228,7 +228,7 @@ void SystemDraw::BeginNative() void SystemDraw::EndNative() { - if(GetPixelsPerInch() != nativeDpi && --native == 0) { + if(GetPixelsPerInch() == nativeDpi && --native == 0) { DotsMode(); actual_offset = actual_offset_bak; SetOrg(); diff --git a/uppsrc/CtrlCore/MetaFile.cpp b/uppsrc/CtrlCore/MetaFile.cpp index 75552c706..bdc98f55e 100644 --- a/uppsrc/CtrlCore/MetaFile.cpp +++ b/uppsrc/CtrlCore/MetaFile.cpp @@ -11,6 +11,7 @@ void WinMetaFile::Init() { void WinMetaFile::Paint(Draw& w, const Rect& r) const { ChkP(); + w.DrawRect(r, White()); if(!hemf) return; SystemDraw *h = dynamic_cast(&w); diff --git a/uppsrc/DocTypes/DocTypes.cpp b/uppsrc/DocTypes/DocTypes.cpp index 723494743..12c6e4f2f 100644 --- a/uppsrc/DocTypes/DocTypes.cpp +++ b/uppsrc/DocTypes/DocTypes.cpp @@ -105,7 +105,7 @@ int Paragraph::GetWidth(int zoom) const { const char *s = pptr->text; int n = pptr->text.GetLength(); while(n--) { - cx += pf[*s == 31 ? 32 : (byte) *s]; + cx += pf[*s == 31 ? 32 : ToUnicode((byte) *s, CHARSET_DEFAULT)]; s++; } } @@ -165,11 +165,10 @@ bool Paragraph::Format(ParaTypo& pfmt, int cx, int zoom) const { font.Height(DocZoom(zoom, pptr->font.GetHeight())); FontInfo pf = pp->Set(font, pptr->color); const char *s = pptr->text; -// LOG("Format " << s << " a: " << pf.GetAscent() << " d: " << pf.GetDescent()); int n = pptr->text.GetLength(); while(n--) { *cp++ = *s; - *wp++ = pf[*s == 31 ? 32 : (byte) *s]; + *wp++ = pf[*s == 31 ? 32 : ToUnicode((byte) *s, CHARSET_DEFAULT)]; *ip++ = pp; s++; } diff --git a/uppsrc/Draw/Drawing.cpp b/uppsrc/Draw/Drawing.cpp index ad6cad237..2718d127d 100644 --- a/uppsrc/Draw/Drawing.cpp +++ b/uppsrc/Draw/Drawing.cpp @@ -563,65 +563,55 @@ void Draw::DrawDrawingOp(const Rect& target, const Drawing& w) { DrawText(x, y, angle, text, font, ink); } else { + const wchar *wp = ~text; + double q = Length((Sizef)ps.target) / Length((Sizef)ps.source); + double px = 0; + while(nn--) { + int cx; + if(dxb) + ps / cx; + else + cx = font[*wp++]; + double npx = q * cx + px; + *wd++ = (int)npx - (int)px; + px = npx; + } + int ht = (int)(font.GetHeight() * q); + font.Width((int)q * font.GetWidth()).Height(ht ? ht : 1); + DrawText(ps.GetX(x), ps.GetY(y), angle, text, font, ink, dx); + /* FontInfo fi = font.Info(); const wchar *wp = ~text; int odd = (angle / 900) & 1; - if(angle % 900 == 0) { - int error = 0; - int a, b; - if(odd) { - a = ps.target.cy; - b = ps.source.cy; - int ht = ps.GetCx(fi.GetFontHeight()); - font.Width(ps.GetCy(fi.GetAveWidth())).Height(ht ? ht : 1); - FontInfo nf = font.Info(); - x = angle == 2700 ? ps.GetX(x - fi.GetAscent()) + nf.GetAscent() - : ps.GetX(x + fi.GetAscent()) - nf.GetAscent(); - y = ps.GetY(y); + double ang = (double) (angle % 900) * M_2PI / 3600; + double sx = (double) ps.target.cx / ps.source.cx; + double sy = (double) ps.target.cy / ps.source.cy; + double ang2 = atan((odd ? sx / sy : sy / sx) * tan(ang)); + DDUMP(odd); + DDUMP(cx); + DDUMP(sy); + DDUMP(sin(ang)); + DDUMP(sin(ang2)); + double q = (odd ? sx : sy) * sin(ang) / sin(ang2); + double error = 0; + while(nn--) { + int cx; + if(dxb) { + ps / cx; + DDUMP(cx); } - else { - a = ps.target.cx; - b = ps.source.cx; - int ht = ps.GetCy(fi.GetFontHeight()); - font.Width(ps.GetCx(fi.GetAveWidth())).Height(ht ? ht : 1); - FontInfo nf = font.Info(); - x = ps.GetX(x); - y = angle == 1800 ? ps.GetY(y - fi.GetAscent()) + nf.GetAscent() - : ps.GetY(y + fi.GetAscent()) - nf.GetAscent(); - } - while(nn--) { - int c; - if(dxb) - ps / c; - else - c = fi[*wp++]; - *wd++ = (c * a + error) / b; - error = (c * a + error) % b; - } - DrawText(x, y, angle, text, font, ink, dx); - } - else { - double ang = (double) (angle % 900) * M_2PI / 3600; - double sx = (double) ps.target.cx / ps.source.cx; - double sy = (double) ps.target.cy / ps.source.cy; - double ang2 = atan((odd ? sx / sy : sy / sx) * tan(ang)); - double q = (odd ? sx : sy) * sin(ang) / sin(ang2); - double error = 0; - while(nn--) { - int cx; - if(dxb) - ps / cx; - else - cx = fi[*wp++]; - double ncx = q * cx + error; - *wd++ = cx = (int) ncx; - error = ncx - cx; - } - int ht = (int)(fi.GetFontHeight() * (sx * sin(ang) * sin(ang2) + sy * cos(ang) * cos(ang2))); - font.Width(int(q * fi.GetAveWidth())).Height(ht ? ht : 1); - DrawText(ps.GetX(x), ps.GetY(y), int(ang2 * 3600 / M_2PI) + (angle / 900) * 900, - text, font, ink, dx); + else + cx = fi[*wp++]; + double ncx = q * cx + error; + DDUMP(q * cx); + *wd++ = cx = (int) ncx; + error = ncx - cx; } + int ht = (int)(fi.GetFontHeight() * (sx * sin(ang) * sin(ang2) + sy * cos(ang) * cos(ang2))); + font.Width(int(q * fi.GetAveWidth())).Height(ht ? ht : 1); + DrawText(ps.GetX(x), ps.GetY(y), int(ang2 * 3600 / M_2PI) + (angle / 900) * 900, + text, font, ink, dx); + */ } } } diff --git a/uppsrc/Painter/DrawOp.cpp b/uppsrc/Painter/DrawOp.cpp index e84b4f748..e1242ddb8 100644 --- a/uppsrc/Painter/DrawOp.cpp +++ b/uppsrc/Painter/DrawOp.cpp @@ -183,8 +183,9 @@ void Painter::DrawTextOp(int x, int y, int angle, const wchar *text, Font font, { Begin(); EvenOdd(true); + Translate(x, y); if(angle) - Rotate(angle * M_2PI / 36000); + Rotate(-angle * M_2PI / 3600); if(n < 0) n = wstrlen(text); double *ddx = NULL; @@ -195,7 +196,7 @@ void Painter::DrawTextOp(int x, int y, int angle, const wchar *text, Font font, for(int i = 0; i < n; i++) ddx[i] = dx[i]; } - Text(x, y, text, font, n, ddx); + Text(0, 0, text, font, n, ddx); Fill(ink); End(); }