Draw: Numerous fixes

git-svn-id: svn://ultimatepp.org/upp/trunk@1473 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
cxl 2009-08-04 11:50:18 +00:00
parent cf0af7d760
commit 90bf24af9c
5 changed files with 51 additions and 60 deletions

View file

@ -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();

View file

@ -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<SystemDraw *>(&w);

View file

@ -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++;
}

View file

@ -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);
*/
}
}
}

View file

@ -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();
}