From e7b6d7b266fb8d8a55f8ab5dfc37376feefba293 Mon Sep 17 00:00:00 2001 From: rylek Date: Thu, 5 May 2011 21:41:38 +0000 Subject: [PATCH] .CtrlCore: fixed typo and added implementation of WinMetaFile::Detach .TDraw: minor fixes and enhancements in formula painter git-svn-id: svn://ultimatepp.org/upp/trunk@3406 f0d560ea-af0d-0410-9eb7-867de7ffcac7 --- uppsrc/CtrlCore/DrawWin32.h | 4 ++-- uppsrc/CtrlCore/MetaFile.cpp | 8 ++++++++ uppsrc/TDraw/formula.cpp | 37 +++++++++++++++++++++++------------- 3 files changed, 34 insertions(+), 15 deletions(-) diff --git a/uppsrc/CtrlCore/DrawWin32.h b/uppsrc/CtrlCore/DrawWin32.h index 3ff38bbb2..d69e77b6b 100644 --- a/uppsrc/CtrlCore/DrawWin32.h +++ b/uppsrc/CtrlCore/DrawWin32.h @@ -148,8 +148,8 @@ class WinMetaFile/* : NoCopy */{ // void Copy(const WinMetaFile& src); public: - void Attach(HENHMETAFILE emf); - HENHMETAFILE *Detach(); + void Attach(HENHMETAFILE emf); + HENHMETAFILE Detach(); void Set(const void *data, dword len); void Set(const String& data) { Set(~data, data.GetCount()); } diff --git a/uppsrc/CtrlCore/MetaFile.cpp b/uppsrc/CtrlCore/MetaFile.cpp index e1188d5e9..6c10a468a 100644 --- a/uppsrc/CtrlCore/MetaFile.cpp +++ b/uppsrc/CtrlCore/MetaFile.cpp @@ -81,6 +81,14 @@ void WinMetaFile::Attach(HENHMETAFILE _hemf) { } } +HENHMETAFILE WinMetaFile::Detach() +{ + size = Size(0, 0); + HENHMETAFILE out = hemf; + hemf = NULL; + return out; +} + #pragma pack(push, 1) struct PLACEABLE_METAFILEHEADER { diff --git a/uppsrc/TDraw/formula.cpp b/uppsrc/TDraw/formula.cpp index 05d77d686..6bd0a6d44 100644 --- a/uppsrc/TDraw/formula.cpp +++ b/uppsrc/TDraw/formula.cpp @@ -62,15 +62,15 @@ static void BezierEllipse(Vector& out, Point C, Size radius, int n) int SymbolWidth(FORMSYMBOL symbol, int height, int textheight) { int wd = max(Percent(20, textheight), 4); - int lw = Formula::GetLineWidth(textheight); + int lw = Formula::GetLineWidth(textheight) >> 2; switch(symbol) { default: NEVER(); case FS_EMPTY: return 0; - case FS_LBRACE: - case FS_RBRACE: case FS_LSHARP: case FS_RSHARP: wd = textheight / 4; break; + case FS_LBRACE: + case FS_RBRACE: case FS_LPAREN: case FS_RPAREN: case FS_LBRACKET: @@ -79,7 +79,7 @@ int SymbolWidth(FORMSYMBOL symbol, int height, int textheight) case FS_RTBRACKET: case FS_LBBRACKET: case FS_RBBRACKET: break; - case FS_VBAR: wd = textheight / 6; break; + case FS_VBAR: wd = textheight / 8; break; case FS_SUM: case FS_PRODUCT: case FS_UNION: @@ -94,7 +94,7 @@ int SymbolWidth(FORMSYMBOL symbol, int height, int textheight) case FS_MEMBER: case FS_NOT_MEMBER: case FS_SUBSET: case FS_NOT_SUBSET: case FS_PROPER_SUBSET: case FS_NOT_PROPER_SUBSET: - wd = Percent(60, textheight); + wd = Percent(30, textheight); break; } return wd; @@ -104,7 +104,7 @@ void PaintSymbol(Draw& draw, FORMSYMBOL symbol, const Rect& rc, int textheight, { // draw.DrawRect(rc, LtMagenta); int wd = rc.Width(), ht = rc.Height(); - int thick = Formula::GetLineWidth(textheight); + int thick = Formula::GetLineWidth(textheight) >> 1; int half = thick >> 1; Vector polygon; Vector counts; @@ -144,12 +144,13 @@ void PaintSymbol(Draw& draw, FORMSYMBOL symbol, const Rect& rc, int textheight, xs = xv = thick; yo = 0; yi = yj = ys = ht >> 1; + yw = min(textheight / 3, yi); if(bra) { xv = (xv + xo) >> 1; - yi = max(ht >> 2, ys - textheight / 5); + yi = max(Percent(42, ht), ys - textheight / 5); yj = (yi + ys) >> 1; + yw /= 3; } - yw = min(textheight / 3, yi); yv = yw >> 1; enum { PREC = 6 }; Bezier(polygon, Point(xo, yo), Point(xv, yv), Point(xv, yw), PREC); @@ -235,7 +236,7 @@ void PaintSymbol(Draw& draw, FORMSYMBOL symbol, const Rect& rc, int textheight, << Point(wd - thick, top) << Point(wd2, bot - thick - iscale(thick, bot - top, wd2)) << Point(thick, top); } else if(symbol > FS_SETOP_BEGIN && symbol < FS_SETOP_END) { - int ht2 = ht >> 1, ht4 = Percent(30, ht), wd2 = wd >> 1; + int ht2 = Percent(60, ht), ht4 = Percent(20, ht), wd2 = wd >> 1; polygon << Point(wd, ht2 - ht4); Bezier(polygon, Point(wd2, ht2 - ht4), Point(0, ht2 - ht4), Point(0, ht2), 8); Bezier(polygon, Point(0, ht2), Point(0, ht2 + ht4), Point(wd2, ht2 + ht4), 8); @@ -776,7 +777,7 @@ RefCon FormulaParser::RunTextBin() RefCon body = new FormulaSymbol(sym, ht, ht, state.color); Vector< RefCon > list; list << form << body << right; - return new FormulaMatrix(list, new FormulaSpace(Percent(50, ht))); + return new FormulaMatrix(list, new FormulaSpace(Percent(20, ht))); } return form; } @@ -807,6 +808,16 @@ RefCon FormulaParser::RunComp() item = MakeBinary(item, "\xDE", RunComp(), Null, -13); else if(Check('=', '<')) item = MakeBinary(item, "\xDC", RunComp(), Null, -13); + else if(Skip() == '.' && ptr[1] == '.' && ptr[2] != '.') { + ptr += 2; + RefCon right = RunComp(); + Vector< RefCon > list; + list << item; + list << new FormulaText("..", state.font, state.color); + list << right; + int ht = Formula::GetTextHeight0(item, right); + item = new FormulaMatrix(list, new FormulaSpace(Percent(20, ht))); + } else if(Check('<')) item = MakeBinary(item, "<", RunComp(), gap); else if(Check('>')) @@ -837,8 +848,10 @@ RefCon FormulaParser::RunMul() for(;;) if(Check('*')) item = MakeBinary(item, "*", RunDiv()); - else if(Check('.')) + else if(Skip() == '.' && ptr[1] != '.') { + ptr++; item = MakeBinary(item, ".", RunDiv(), Null, -20); + } else if(Check('~')) item = MakeBinary(item, Null, RunDiv()); else @@ -976,8 +989,6 @@ RefCon FormulaParser::RunTerm() return MakeUnary("+", RunTerm(), 0, true); if(Check('.', '.', '.')) return new FormulaText("...", state.font, state.color); - if(Check('.', '.')) - return new FormulaText("..", state.font, state.color); if(Check('~', '~')) { int blanks = 1;