From 3306f00f9b1ea834367a4052138b71a53a78069a Mon Sep 17 00:00:00 2001 From: Joshua Granick Date: Wed, 4 Feb 2015 20:34:38 -0800 Subject: [PATCH] File sync --- legacy/project/include/TextField.h | 4 +- legacy/project/src/common/Font.cpp | 3 +- legacy/project/src/common/FreeType.cpp | 17 +-- legacy/project/src/common/Hardware.cpp | 139 ++++++++++++++++++++++- legacy/project/src/common/TextField.cpp | 1 + legacy/project/src/iPhone/UIStageView.mm | 1 - legacy/project/src/windows/GDIFont.cpp | 2 +- 7 files changed, 153 insertions(+), 14 deletions(-) diff --git a/legacy/project/include/TextField.h b/legacy/project/include/TextField.h index c2e008213..7834eadc3 100644 --- a/legacy/project/include/TextField.h +++ b/legacy/project/include/TextField.h @@ -185,9 +185,9 @@ private: StringState mStringState; WString mUserString; - void SplitGroup(int inGroup,int inPos); + void SplitGroup(int inGroup,int inPos); - void BuildBackground(); + void BuildBackground(); int PointToChar(UserPoint inPoint) const; int LineFromChar(int inChar) const; diff --git a/legacy/project/src/common/Font.cpp b/legacy/project/src/common/Font.cpp index 4201a79f9..638fd299f 100644 --- a/legacy/project/src/common/Font.cpp +++ b/legacy/project/src/common/Font.cpp @@ -332,7 +332,7 @@ Font *Font::Create(TextFormat &inFormat,double inScale,bool inNative,bool inInit } if (bytes != NULL) - face = FontFace::CreateFreeType(inFormat,inScale,bytes); + face = FontFace::CreateFreeType(inFormat,inScale,bytes); if (!face) face = FontFace::CreateCFFIFont(inFormat,inScale); @@ -384,3 +384,4 @@ DEFINE_PRIM(nme_font_register_font,2) } // end namespace nme + diff --git a/legacy/project/src/common/FreeType.cpp b/legacy/project/src/common/FreeType.cpp index 65f838745..9396da444 100644 --- a/legacy/project/src/common/FreeType.cpp +++ b/legacy/project/src/common/FreeType.cpp @@ -56,7 +56,7 @@ public: ~FreeTypeFont() { FT_Done_Face(mFace); - if (mBuffer) free(mBuffer); + if (mBuffer) free(mBuffer); } bool LoadBitmap(int inChar) @@ -405,13 +405,13 @@ bool GetFontFile(const std::string& inName,std::string &outFile) //printf("Try %s\n", outFile.c_str()); - FILE *file = fopen(outFile.c_str(),"rb"); - if (file) - { - //printf("Found sub file %s\n", outFile.c_str()); - fclose(file); - return true; - } + FILE *file = fopen(outFile.c_str(),"rb"); + if (file) + { + //printf("Found sub file %s\n", outFile.c_str()); + fclose(file); + return true; + } test++; } } @@ -1098,3 +1098,4 @@ value nme_font_iterate_device_fonts(value inFunc) DEFINE_PRIM(nme_font_iterate_device_fonts,1) + diff --git a/legacy/project/src/common/Hardware.cpp b/legacy/project/src/common/Hardware.cpp index 67e6221fc..524682d7a 100644 --- a/legacy/project/src/common/Hardware.cpp +++ b/legacy/project/src/common/Hardware.cpp @@ -6,9 +6,13 @@ #define M_PI 3.14159265358979323846 #endif + namespace nme { +enum { DEBUG_KEEP_LOOPS = 0 }; +enum { DEBUG_FAT_LINES = 0 }; + struct CurveEdge { @@ -115,7 +119,7 @@ public: mElement.mWidth = 1.0/mScale; } - if (alphaAA) + if (alphaAA && !DEBUG_FAT_LINES) { mPerpLen += 0.5/mScale; mElement.mWidth += 1.0/mScale; @@ -895,8 +899,101 @@ public: } + + void cleanCurve(Curves &curve,bool inLoop) + { + double perp2 = mPerpLen*mPerpLen*4.0; + + for(int startPoint=0; startPoint perp2 && l0.Dist2(p1) > perp2 ) + break; + + const UserPoint &l1 = curve[testPoint+1].p; + if ( (l0.xmaxX && l1.x>maxX) || + (l0.ymaxY && l1.y>maxY) ) + continue; + + UserPoint dl = l1-l0; + // Solve p0.x + a dp.x = l0.x + b dl.x + // p0.y + a dp.y = l0.y + b dl.y + + // Solve p0.x*dp.y + a dp.x*dp.y = l0.x*dp.y + b dl.x*dp.y + // p0.y*dp.x + a dp.y*dp.x = l0.y*dp.x + b dl.y*dp.x + // p0 x dp - l0 x dp = b dl x dp + // (p0-l0) x dp = b dl x dp + double denom = dl.Cross(dp); + if (denom!=0.0) + { + double b = (p0-l0).Cross(dp)/denom; + if (b>=0 && b<=1.0) + { + double a = (fabs(dp.x) > fabs(dp.y)) ? (l0.x + b*dl.x - p0.x)/dp.x : + (l0.y + b*dl.y - p0.y)/dp.y; + //if (a>=0 && a<=1) equals case? + { + if (a>0 && a<1 && b>0 && b<1) + { + UserPoint p = p0 + dp*a; + // Remove the loop + // c[startPoint] + // p <- new point between c[startPoint] and c[startPoint+1] + // c[startPoint+1] + // c[startPoint+2] + // ... + // c[testPoint] + // p <- new point between c[testPoint] and c[testPoint+1] + // c[testPoint+1] + { + // replace c[startPoint+1] with p, and erase upto and including c[testPoint] + p1 = p; + curve.EraseAt(startPoint+2,testPoint+1); + // Try again... + startPoint--; + break; + } + } + } + } + } + } + } + } + + + + + void removeLoops(QuickVec &curve,int startPoint,float turningPoint,int *inAdjustStart=0) { + if (DEBUG_KEEP_LOOPS!=0) + return; + for(int i=startPoint;i