public void CloseContour() { if (curX == latestMoveToX && curY == latestMoveToY) { //we not need to close } else { if (_latestPart != null) { currentCnt.AddPart(_latestPart = new GlyphLine(_latestPart, latestMoveToX, latestMoveToY)); } else { currentCnt.AddPart(_latestPart = new GlyphLine(curX, curY, latestMoveToX, latestMoveToY)); } } this.curX = latestMoveToX; this.curY = latestMoveToY; if (currentCnt != null && currentCnt.parts.Count > 0) { this.contours.Add(currentCnt); currentCnt = null; } // currentCnt = new GlyphContour(); }
public void CloseContour() { if (_curX == _latestMoveToX && _curY == _latestMoveToY) { //we not need to close } else { if (_latestPart != null) { _currentCnt.AddPart(_latestPart = new GlyphLine(_latestPart, _latestMoveToX, _latestMoveToY)); } else { _currentCnt.AddPart(_latestPart = new GlyphLine(_curX, _curY, _latestMoveToX, _latestMoveToY)); } } _curX = _latestMoveToX; _curY = _latestMoveToY; if (_currentCnt != null && _currentCnt.parts.Count > 0) { _contours.Add(_currentCnt); _currentCnt = null; } // _currentCnt = new GlyphContour(); }
public void BeginRead(int contourCount) { //reset all contours = new List <GlyphContour>(); _latestPart = null; this.latestMoveToX = this.curX = this.latestMoveToY = this.curY = 0; // currentCnt = new GlyphContour(); //new contour, but not add }
void GenerateContourOutput(IGlyphTranslator tx, GlyphContour contour) { List <GlyphPoint> points = contour.flattenPoints; int j = points.Count; if (j == 0) { return; } //------------------------------------------------- Bounds controlBounds = this.OriginalGlyphControlBounds; //walk along the edge in the contour to generate new edge output float pxscale = this._pxScale; #if DEBUG // dbugWriteLine("===begin===" + fit_x_offset); // if (!dbugUseHorizontalFitValue) // { // fit_x_offset = 0; // } #endif //------------------------------------------------- //fineSubPixelRenderingOffset = 0.33f; //------------------------------------------------- //TODO: review here float fit_x, fit_y; points[0].GetFitXY(pxscale, out fit_x, out fit_y); // tx.MoveTo(fit_x, fit_y); #if DEBUG // dbugWriteOutput("M", fit_x, fit_x + fit_x_offset, fit_y); #endif //2. others for (int i = 1; i < j; ++i) { //try to fit to grid points[i].GetFitXY(pxscale, out fit_x, out fit_y); tx.LineTo(fit_x, fit_y); #if DEBUG //for debug //dbugWriteOutput("L", fit_x, fit_x + fit_x_offset, fit_y); #endif } //close tx.CloseContour(); #if DEBUG //dbugWriteLine("===end==="); #endif }
void CreateGlyphEdges() { //reset bounds _bounds_minX = _bounds_minY = float.MaxValue; _bounds_maxX = _bounds_maxY = float.MinValue; List <GlyphContour> contours = this._contours; int j = contours.Count; for (int i = 0; i < j; ++i) { GlyphContour cnt = contours[i]; cnt.CreateGlyphEdges(); //this is a new found after fitting process cnt.FindBounds(ref _bounds_minX, ref _bounds_minY, ref _bounds_maxX, ref _bounds_maxY); } }
// public void Walk(GlyphDynamicOutline dynamicOutline) { #if DEBUG _dynamicOutline = dynamicOutline; int triNumber = 0; if (WalkTrianglesAndEdges) { foreach (GlyphTriangle tri in _dynamicOutline.dbugGetGlyphTriangles()) { float centroidX, centriodY; tri.CalculateCentroid(out centroidX, out centriodY); OnTriangle(triNumber++, tri.e0, tri.e1, tri.e2, centroidX, centriodY); } } //--------------- List <GlyphContour> contours = _dynamicOutline._contours; List <CentroidLineHub> centroidLineHubs = _dynamicOutline.dbugGetCentroidLineHubs(); foreach (CentroidLineHub lineHub in centroidLineHubs) { Dictionary <GlyphTriangle, CentroidLine> lines = lineHub.GetAllCentroidLines(); Vector2 hubCenter = lineHub.CalculateAvgHeadPosition(); OnBegingLineHub(hubCenter.X, hubCenter.Y); foreach (CentroidLine line in lines.Values) { List <GlyphBoneJoint> joints = line._joints; int pairCount = joints.Count; for (int i = 0; i < pairCount; ++i) { GlyphBoneJoint joint = joints[i]; if (WalkCentroidBone) { float px, py, qx, qy; joint.dbugGetCentroidBoneCenters(out px, out py, out qx, out qy); OnCentroidLine(px, py, qx, qy); //-------------------------------------------------- if (joint.TipEdgeP != null) { Vector2 pos = joint.TipPointP; OnCentroidLineTip_P(px, py, pos.X, pos.Y); } if (joint.TipEdgeQ != null) { Vector2 pos = joint.TipPointQ; OnCentroidLineTip_Q(qx, qy, pos.X, pos.Y); } } if (WalkGlyphBone) { OnBoneJoint(joint); } } if (WalkGlyphBone) { //draw bone list DrawBoneLinks(line); } } // OnEndLineHub(hubCenter.X, hubCenter.Y, lineHub.GetHeadConnectedJoint()); } //---------------- List <GlyphContour> cnts = _dynamicOutline._contours; int j = cnts.Count; for (int i = 0; i < j; ++i) { GlyphContour cnt = cnts[i]; List <GlyphPoint> points = cnt.flattenPoints; int n = points.Count; for (int m = 0; m < n; ++m) { OnGlyphEdgeN(points[m].E0); } } #endif }
/// <summary> /// create GlyphDynamicOutline from flatten contours /// </summary> /// <param name="flattenContours"></param> /// <returns></returns> GlyphDynamicOutline CreateDynamicOutline(List <GlyphContour> flattenContours) { //-------------------------- //TODO: review here, add hole or not // more than 1 contours, no hole => eg. i, j, ;, etc // more than 1 contours, with hole => eg. a,e , etc //closewise => not hole _waitingHoles.Clear(); int cntCount = flattenContours.Count; Poly2Tri.Polygon mainPolygon = null; // //this version if it is a hole=> we add it to main polygon //TODO: add to more proper polygon *** //eg i //-------------------------- List <Poly2Tri.Polygon> otherPolygons = null; for (int n = 0; n < cntCount; ++n) { GlyphContour cnt = flattenContours[n]; if (cnt.IsClosewise()) { //not a hole if (mainPolygon == null) { //if we don't have mainPolygon before //this is main polygon mainPolygon = CreatePolygon(cnt.flattenPoints); if (_waitingHoles.Count > 0) { //flush all waiting holes to the main polygon int j = _waitingHoles.Count; for (int i = 0; i < j; ++i) { mainPolygon.AddHole(_waitingHoles[i]); } _waitingHoles.Clear(); } } else { //if we already have a main polygon //then this is another sub polygon //IsHole is correct after we Analyze() the glyph contour Poly2Tri.Polygon subPolygon = CreatePolygon(cnt.flattenPoints); if (otherPolygons == null) { otherPolygons = new List <Poly2Tri.Polygon>(); } otherPolygons.Add(subPolygon); } } else { //this is a hole Poly2Tri.Polygon subPolygon = CreatePolygon(cnt.flattenPoints); if (mainPolygon == null) { //add to waiting polygon _waitingHoles.Add(subPolygon); } else { //add to mainPolygon mainPolygon.AddHole(subPolygon); } } } if (_waitingHoles.Count > 0) { throw new NotSupportedException(); } //------------------------------------------ //2. tri angulate Poly2Tri.P2T.Triangulate(mainPolygon); //that poly is triangulated Poly2Tri.Polygon[] subPolygons = (otherPolygons != null) ? otherPolygons.ToArray() : null; if (subPolygons != null) { for (int i = subPolygons.Length - 1; i >= 0; --i) { Poly2Tri.P2T.Triangulate(subPolygons[i]); } } //3. intermediate outline is used inside this lib //and then convert intermediate outline to dynamic outline return(new GlyphDynamicOutline( new GlyphIntermediateOutline(flattenContours, mainPolygon, subPolygons))); }