static void CreateFitShape(IGlyphPathBuilder reader, GlyphContour contour, float pixelScale, bool x_axis, bool y_axis) { List <GlyphPoint2D> mergePoints = contour.mergedPoints; int j = mergePoints.Count; //merge 0 = start double prev_px = 0; double prev_py = 0; double p_x = 0; double p_y = 0; double first_px = 0; double first_py = 0; { GlyphPoint2D p = mergePoints[0]; p_x = p.x * pixelScale; p_y = p.y * pixelScale; if (y_axis && p.isPartOfHorizontalEdge && p.isUpperSide && p_y > 3) { //vertical fitting //fit p_y to grid p_y = RoundToNearestVerticalSide((float)p_y); } if (x_axis && p.IsPartOfVerticalEdge && p.IsLeftSide) { float new_x = RoundToNearestHorizontalSide((float)p_x); //adjust right-side vertical edge EdgeLine rightside = p.GetMatchingVerticalEdge(); if (rightside != null) { } p_x = new_x; } reader.MoveTo((float)p_x, (float)p_y); //------------- first_px = prev_px = p_x; first_py = prev_py = p_y; } for (int i = 1; i < j; ++i) { //all merge point is polygon point GlyphPoint2D p = mergePoints[i]; p_x = p.x * pixelScale; p_y = p.y * pixelScale; if (y_axis && p.isPartOfHorizontalEdge && p.isUpperSide && p_y > 3) { //vertical fitting //fit p_y to grid p_y = RoundToNearestVerticalSide((float)p_y); } if (x_axis && p.IsPartOfVerticalEdge && p.IsLeftSide) { //horizontal fitting //fix p_x to grid float new_x = RoundToNearestHorizontalSide((float)p_x); ////adjust right-side vertical edge //PixelFarm.Agg.Typography.EdgeLine rightside = p.GetMatchingVerticalEdge(); //if (rightside != null && !rightside.IsLeftSide && rightside.IsOutside) //{ // var rightSideP = rightside.p.userData as GlyphPoint2D; // var rightSideQ = rightside.q.userData as GlyphPoint2D; // //find move diff // float movediff = (float)p_x - new_x; // //adjust right side edge // rightSideP.x = rightSideP.x + movediff; // rightSideQ.x = rightSideQ.x + movediff; //} p_x = new_x; } // reader.LineTo((float)p_x, (float)p_y); // prev_px = p_x; prev_py = p_y; } reader.LineTo((float)first_px, (float)first_py); }
public static void Read(this IGlyphPathBuilder r, GlyphPointF[] glyphPoints, ushort[] contourEndPoints) { //2. start build path int startContour = 0; int cpoint_index = 0; int todoContourCount = contourEndPoints.Length; //----------------------------------- r.BeginRead(todoContourCount); //----------------------------------- float lastMoveX = 0; float lastMoveY = 0; int controlPointCount = 0; while (todoContourCount > 0) { int nextContour = contourEndPoints[startContour] + 1; bool isFirstPoint = true; Vector2 secondControlPoint = new Vector2(); Vector2 thirdControlPoint = new Vector2(); bool justFromCurveMode = false; for (; cpoint_index < nextContour; ++cpoint_index) { GlyphPointF vpoint = glyphPoints[cpoint_index]; float vpoint_x = vpoint.P.X; float vpoint_y = vpoint.P.Y; //int vtag = (int)flags[cpoint_index] & 0x1; //bool has_dropout = (((vtag >> 2) & 0x1) != 0); //int dropoutMode = vtag >> 3; if (vpoint.onCurve) { //on curve if (justFromCurveMode) { switch (controlPointCount) { case 1: { r.Curve3(secondControlPoint.X, secondControlPoint.Y, vpoint_x, vpoint_y); } break; case 2: { r.Curve4(secondControlPoint.X, secondControlPoint.Y, thirdControlPoint.X, thirdControlPoint.Y, vpoint_x, vpoint_y); } break; default: { throw new NotSupportedException(); } } controlPointCount = 0; justFromCurveMode = false; } else { if (isFirstPoint) { isFirstPoint = false; r.MoveTo(lastMoveX = (vpoint_x), lastMoveY = (vpoint_y)); } else { r.LineTo(vpoint_x, vpoint_y); } //if (has_dropout) //{ // //printf("[%d] on,dropoutMode=%d: %d,y:%d \n", mm, dropoutMode, vpoint.x, vpoint.y); //} //else //{ // //printf("[%d] on,x: %d,y:%d \n", mm, vpoint.x, vpoint.y); //} } } else { switch (controlPointCount) { case 0: { secondControlPoint = new Vector2(vpoint_x, vpoint_y); } break; case 1: { //we already have prev second control point //so auto calculate line to //between 2 point Vector2 mid = GetMid(secondControlPoint, vpoint_x, vpoint_y); //---------- //generate curve3 r.Curve3(secondControlPoint.X, secondControlPoint.Y, mid.X, mid.Y); //------------------------ controlPointCount--; //------------------------ //printf("[%d] bzc2nd, x: %d,y:%d \n", mm, vpoint.x, vpoint.y); secondControlPoint = new Vector2(vpoint_x, vpoint_y); } break; default: { throw new NotSupportedException(); } break; } controlPointCount++; justFromCurveMode = true; } } //-------- //close figure //if in curve mode if (justFromCurveMode) { switch (controlPointCount) { case 0: break; case 1: { r.Curve3(secondControlPoint.X, secondControlPoint.Y, lastMoveX, lastMoveY); } break; case 2: { r.Curve4(secondControlPoint.X, secondControlPoint.Y, thirdControlPoint.X, thirdControlPoint.Y, lastMoveX, lastMoveY); } break; default: { throw new NotSupportedException(); } } justFromCurveMode = false; controlPointCount = 0; } r.CloseFigure(); //-------- startContour++; todoContourCount--; } r.EndRead(); }