internal int MoveTo_4(IntPtr to, IntPtr user) { var to_0 = Marshal.PtrToStructure <FT_Vector4>(to); var p = Vector2.Zero; if (contours.Count > 0) { contours[contours.Count - 1].end = (uint)points.Count - 1; add_outline_point(p); } Debug.Assert(points.Count % 2 == 0); var range = new fd_ContourRange { begin = (uint)points.Count, end = uint.MaxValue, }; add_outline_contour(range); add_outline_point(convert_point_4(to_0)); return(0); }
static bool try_to_fit_in_cell_count( fd_Outline original, out fd_Outline replacement) { bool ret = true; var cells = new fd_WIPCell[original.cell_count_x * original.cell_count_y]; init_wipcells(original, cells); var temp = new fd_Outline { bbox = original.bbox, cell_count_x = original.cell_count_x, cell_count_y = original.cell_count_y, }; var num_of_contours = original.contours.Count; for (uint contour_index = 0; contour_index < num_of_contours; contour_index++) { uint contour_begin = original.contours[(int)contour_index].begin; uint contour_end = original.contours[(int)contour_index].end; temp.outline_add_odd_point(); var urange = new fd_ContourRange { begin = temp.num_of_points, end = temp.num_of_points + contour_end - contour_begin }; temp.add_outline_contour(urange); for (uint i = contour_begin; i < contour_end; i += 2) { var p0 = original.points[(int)i]; var p1 = original.points[(int)(i + 1)]; //float *p2 = o.points[i + 2]; uint j = temp.num_of_points; temp.add_outline_point(p0); temp.add_outline_point(p1); ret &= for_each_wipcell_add_bezier(original, temp, i, j, contour_index, cells); } uint max_start_len = 0; ret &= for_each_wipcell_finish_contour(original, temp, contour_index, cells, ref max_start_len); uint continuation_end = contour_begin + max_start_len * 2; for (uint i = contour_begin; i < continuation_end; i += 2) { temp.add_outline_point(original.points[(int)i]); temp.add_outline_point(original.points[(int)(i + 1)]); } var plast = original.points[(int)continuation_end]; temp.add_outline_point(plast); } if (!ret) { temp.fd_outline_destroy(); replacement = null; return(ret); } uint filled_line = outline_add_filled_line(temp); uint filled_cell = make_cell_from_single_edge(filled_line); set_filled_cells(temp, cells, filled_cell); copy_wipcell_values(temp, ref cells); original.fd_outline_destroy(); replacement = temp; return(ret); }
internal static fd_Outline fd_outline_fix_thin_lines(fd_Outline src) { var dst = new fd_Outline { bbox = src.bbox, }; for (var contour_index = 0; contour_index < src.contours.Count; contour_index++) { var contour_begin = src.contours[contour_index].begin; var contour_end = src.contours[contour_index].end; dst.outline_add_odd_point(); var urange = new fd_ContourRange { begin = (uint)dst.points.Count, end = uint.MaxValue }; dst.add_outline_contour(urange); for (int i = (int)contour_begin; i < contour_end; i += 2) { var p0 = src.points[i]; var p1 = src.points[i + 1]; var p2 = src.points[i + 2]; Vector2 mid, midp1; mid = Vector2.Lerp(p0, p2, 0.5f); midp1 = p1 - mid; var bezier = new List <Vector2> { p0, p1, p2 }; bezier[1] += midp1; /* * bool subdivide = false; * if (i > 2) * { * uint jbegin = contour_begin; * if (i == contour_end - 2) jbegin += 2; * * for (uint j = jbegin; j < i - 2; j += 2) * { * float *q0 = o.points[j]; * float *q2 = o.points[j + 2]; * * if (fd_bezier2_line_is_intersecting(bezier, q0, q2)) * subdivide = true; * } * } * * uint jend = contour_end; * if (i == contour_begin) jend -= 2; * * for (uint j = i + 2; j < jend; j += 2) * { * float *q0 = o.points[j]; * float *q2 = o.points[j + 2]; * * if (fd_bezier2_line_is_intersecting(bezier, q0, q2)) * subdivide = true; * } */ bool subdivide = false; for (int j = (int)contour_begin; j < contour_end; j += 2) { if (i == contour_begin && j == contour_end - 2) { continue; } if (i == contour_end - 2 && j == contour_begin) { continue; } if (j + 2 >= i && j <= i + 2) { continue; } var q0 = src.points[j]; //float *q1 = o.points[j + 1]; var q2 = src.points[j + 2]; if (Geometry.fd_bezier2_line_is_intersecting(bezier, 0, q0, q2)) { subdivide = true; } } if (subdivide) { var newp = new Vector2[3]; Geometry.fd_bezier2_split_3p(newp, src.points, i, 0.5f); dst.add_outline_point(p0); dst.add_outline_point(newp[0]); dst.add_outline_point(newp[1]); dst.add_outline_point(newp[2]); } else { dst.add_outline_point(p0); dst.add_outline_point(p1); } } var temp = dst.contours[(int)contour_index]; temp.end = (uint)dst.points.Count; dst.contours[(int)contour_index] = temp; dst.add_outline_point(src.points[(int)contour_end]); } src.fd_outline_destroy(); return(dst); }
internal void add_outline_contour(fd_ContourRange range) { contours.Add(range); }