Exemple #1
0
void drvGCODE::show_path()
{
	Point currentPoint(0.0f, 0.0f);	
	const Point firstPoint = pathElement(0).getPoint(0);

	for (unsigned int n = 0; n < numberOfElementsInPath(); n++) {
		const basedrawingelement & elem = pathElement(n);

		switch (elem.getType()) {
		case moveto:{
				const Point & p = elem.getPoint(0);
				outf << "\nG00 Z#1000\n";
				outf << "G00 X[#1003*" << p.x_ << "] Y[#1004*" << p.y_ << "]\n";
				outf << "G01 Z#1002\n";
				currentPoint = p;
			}
			break;
		case lineto:{
				const Point & p = elem.getPoint(0);
				outf << "G01 X[#1003*" << p.x_ << "] Y[#1004*" << p.y_ << "]\n";
				currentPoint = p;
			}
			break;
		case closepath:
				outf << "G01 X[#1003*" << firstPoint.x_ << "] Y[#1004*" << firstPoint.y_ << "]\n";
			break;

		case curveto:{
			const Point & cp1 = elem.getPoint(0);
			const Point & cp2 = elem.getPoint(1);
			const Point & ep  = elem.getPoint(2);
			// curve is approximated with a variable number or linear segments.
			// fitpoints should be somewhere between 5 and 50 for reasonable page size plots
			// we compute distance between current point and endpoint and use that to help
			// pick the number of segments to use.
			const float dist = (float) pythagoras((float)(ep.x_ - currentPoint.x_),(float)(ep.y_ - currentPoint.y_)); 
			unsigned int fitpoints = (unsigned int)(dist / 10.0);
			if ( fitpoints < 5 ) fitpoints = 5;
			if ( fitpoints > 50 ) fitpoints = 50;

			for (unsigned int s = 1; s < fitpoints; s++) {
				const float t = 1.0f * s / (fitpoints - 1);
				const Point pt = PointOnBezier(t, currentPoint, cp1, cp2, ep);
				outf << " G01 X[#1003*" << pt.x_ << "] Y[#1004*" << pt.y_ << "]\n";
			}
			currentPoint = ep;

			}
			break;
		default:
			errf << "\t\tFatal: unexpected case in drvgcode " << endl;
			abort();
			break;
		}
	}
}
void drvPCBFILL::show_path()
{
  //	outf << "\n#Polyline:\n";
  outf << "\tPolygon(0x00000010)\n\t(\n\t\t";

	for (unsigned int n = 0; n < numberOfElementsInPath(); n++) {
		if (pathElement(n).getType() != closepath) {
			const Point & p = pathElement(n).getPoint(0);
				outf << "[" << (int)(p.x_*SCALE) << " " 
                     << (int)(500000-p.y_*SCALE) << "] ";
		}
	}
  outf << "\n\t)\n";
}
Exemple #3
0
void drvGSCHEM::show_path()
{
  //	outf << "\n#Polyline:\n";


	for (unsigned int n = 1; n < numberOfElementsInPath(); n++) {
	  const Point & p1 = pathElement(n-1).getPoint(0);
		const Point & p = pathElement(n).getPoint(0);
		outf << "L ";
		outf << (int)(p1.x_*SCALE) << " " 
                     << (int)(p1.y_*SCALE) << " " 
                     << (int)(p.x_*SCALE) << " " 
                     << (int)(p.y_*SCALE) << " 3 0 0 0 -1 -1\n";
	}
}
Exemple #4
0
void SkSVGDevice::AutoElement::addClipResources(const SkDraw& draw, Resources* resources) {
    SkASSERT(!draw.fClipStack->isWideOpen());

    SkPath clipPath;
    (void) draw.fClipStack->asPath(&clipPath);

    SkString clipID = fResourceBucket->addClip();
    const char* clipRule = clipPath.getFillType() == SkPath::kEvenOdd_FillType ?
                           "evenodd" : "nonzero";
    {
        // clipPath is in device space, but since we're only pushing transform attributes
        // to the leaf nodes, so are all our elements => SVG userSpaceOnUse == device space.
        AutoElement clipPathElement("clipPath", fWriter);
        clipPathElement.addAttribute("id", clipID);

        SkRect clipRect = SkRect::MakeEmpty();
        if (clipPath.isEmpty() || clipPath.isRect(&clipRect)) {
            AutoElement rectElement("rect", fWriter);
            rectElement.addRectAttributes(clipRect);
            rectElement.addAttribute("clip-rule", clipRule);
        } else {
            AutoElement pathElement("path", fWriter);
            pathElement.addPathAttributes(clipPath);
            pathElement.addAttribute("clip-rule", clipRule);
        }
    }

    resources->fClip.printf("url(#%s)", clipID.c_str());
}
Exemple #5
0
void drvFIG::bbox_path()
{
	for (unsigned int i = 0; i < numberOfElementsInPath(); i++) {
		const basedrawingelement & elem = pathElement(i);
		switch (elem.getType()) {
		case curveto:
			{
				addtobbox(elem.getPoint(0));
				addtobbox(elem.getPoint(1));
				addtobbox(elem.getPoint(2));
				break;
			}
		case moveto:
		case lineto:
			{
				addtobbox(elem.getPoint(0));
				break;
			}
		case closepath:
		default:
			{					// will get caught later
				break;
			}
		}
	}
	new_depth();
}
Exemple #6
0
void drvJAVA::print_coords()
{
	for (unsigned int n = 0; n < numberOfElementsInPath(); n++) {
		const basedrawingelement & elem = pathElement(n);
		switch (elem.getType()) {
		case moveto:{
				const Point & p = elem.getPoint(0);
				outf << "\tp.addPoint(";
				outf << (int) (p.x_ + x_offset) << ","
					<< (int) (currentDeviceHeight - p.y_ + y_offset) << ");";
			}
			break;
		case lineto:{
				const Point & p = elem.getPoint(0);
				outf << "\tp.addPoint(";
				outf << (int) (p.x_ + x_offset) << ","
					<< (int) (currentDeviceHeight - p.y_ + y_offset) << ");";
			}
			break;
		case closepath:
			// outf << "\t\tclosepath ";
			break;
		case curveto:{
				errf << "\t\tFatal: unexpected case in drvjava " << endl;
				abort();
			}
			break;
		default:
			errf << "\t\tFatal: unexpected case in drvjava " << endl;
			abort();
			break;
		}
		outf << endl;
	}
}
Exemple #7
0
            TEST(PathElementTest, isPlaceholder) {
                std::string placeHolder = "{path}";

                PathElement pathElement(placeHolder);

                ASSERT_THAT(pathElement.isPlaceholder(), Eq(true));
                ASSERT_THAT(pathElement.getValue(), Eq("path"));
            }
Exemple #8
0
            TEST(PathElementTest, pathString) {
                std::string path = "path";

                PathElement pathElement(path);

                ASSERT_THAT(pathElement.isPlaceholder(), Eq(false));
                ASSERT_THAT(pathElement.getValue(), Eq(path));
            }
Exemple #9
0
void drvJAVA::show_path()
{
	outf << "\t// Path # " << currentNr() << endl;

// if fill then use a polygon
// else use line-segments.
	switch (currentShowType()) {
	case drvbase::stroke:{
			outf << "\tl = new PSLinesObject(" << endl;
			outf << "\t\t" << currentR() << "F," << currentG() << "F," <<
				currentB() << "F);" << endl;
			for (unsigned int t = 0; t < numberOfElementsInPath(); t++) {
				const Point & p = pathElement(t).getPoint(0);
				outf << "\tl.addPoint(";
				outf << (int) (p.x_ + x_offset) << ","
					<< (int) (currentDeviceHeight - p.y_ + y_offset) << ");\n ";
			}
			outf << "\tcurrentpage.theObjects.addElement(l);" << endl;
		}
		break;
	case drvbase::fill:
	case drvbase::eofill:{
			outf << "\tp = new PSPolygonObject(";
			outf << currentR() << "F," << currentG() << "F," << currentB()
				<< "F);" << endl;
			print_coords();
			if (!isPolygon()) {
				// make closed polygon anyway
				const basedrawingelement & elem = pathElement(0);
				const Point & p = elem.getPoint(0);
				outf << "\tp.addPoint(";
				outf << (int) (p.x_ + x_offset) << ","
					<< (int) (currentDeviceHeight - p.y_ + y_offset) << ");\n ";
			}
			outf << "\tcurrentpage.theObjects.addElement(p);" << endl;
		}
		break;
	default:
		// cannot happen
		outf << "unexpected ShowType " << (int) currentShowType();
		break;
	}
	// outf << "\tcurrentLineWidth: " <<  currentLineWidth() << endl;
}
Exemple #10
0
void drvFIG::print_polyline_coords()
{
	int j = 0;
	//  const Point & p;
	unsigned int last = numberOfElementsInPath() - 1;
	for (unsigned int n = 0; n <= last; n++) {
		const basedrawingelement & elem = pathElement(n);
		if (j == 0) {
			buffer << "\t";
		}
		switch (elem.getType()) {
		case lineto:
		case moveto:
			{
				const Point & p = pathElement(n).getPoint(0);
				prpoint(buffer, p, (n != last));
			}
			break;
		case closepath:
			{
				const Point & p = pathElement(0).getPoint(0);
				prpoint(buffer, p, (n != last));
			}
			break;
		case curveto:
		default:
			errf << "\t\tFatal: unexpected case in drvfig " << endl;
			abort();
			break;

		}

		j++;
		if (j == 5) {
			j = 0;
			buffer << "\n";
		}
	}
	if (j != 0) {
		buffer << "\n";
	}
}
Exemple #11
0
void drvLWO::print_coords()
{
	LWO_POLY *p = new LWO_POLY;
	p->r = (unsigned char) (255.0 * currentR());
	p->g = (unsigned char) (255.0 * currentG());
	p->b = (unsigned char) (255.0 * currentB());
	p->num = 0;					// intial value;
//  p->num = numberOfElementsInPath();
	p->x = new float[numberOfElementsInPath()];	// allocate a conservative amount
	p->y = new float[numberOfElementsInPath()];	// allocate a conservative amount
	p->next = polys;
	polys = p;
	total_polys++;

	for (unsigned int n = 0; n < numberOfElementsInPath(); n++) {
		const basedrawingelement & elem = pathElement(n);
		switch (elem.getType()) {
		case moveto:{
				const Point & pe = elem.getPoint(0);
				// outf << "\t\tmoveto ";
				p->x[p->num] = pe.x_ + x_offset;
				p->y[p->num] = pe.y_ + y_offset;
				p->num++;
			}
			break;
		case lineto:{
				const Point & pe = elem.getPoint(0);
				// outf << "\t\tlineto ";
				p->x[p->num] = pe.x_ + x_offset;
				p->y[p->num] = pe.y_ + y_offset;
				p->num++;
			}
			break;
		case closepath:		// Not supported
			// outf << "\t\tclosepath ";
			break;
		case curveto:{			// Not supported
			}
			break;
		default:
			errf << "\t\tFatal: unexpected case in drvpdf " << endl;
			abort();
			break;
		}
		//    outf << endl;
	}
	total_vertices += p->num;
	// outf << "]" << endl;
}
Exemple #12
0
void drvJAVA2::print_coords()
{
	for (unsigned int n = 0; n < numberOfElementsInPath(); n++) {
		if (numberOfElements > limitNumberOfElements)
			continue_page();
		const basedrawingelement & elem = pathElement(n);
		switch (elem.getType()) {
		case moveto:{
				const Point & p = elem.getPoint(0);
				outf << "    currentPath.moveTo(" << (p.x_ +
													  x_offset) << "f, " <<
					(currentDeviceHeight - p.y_ + y_offset) << "f);";
			}
			break;
		case lineto:{
				const Point & p = elem.getPoint(0);
				outf << "    currentPath.lineTo(" << (p.x_ +
													  x_offset) << "f, " <<
					(currentDeviceHeight - p.y_ + y_offset) << "f);";
			}
			break;
		case closepath:
			outf << "    currentPath.closePath();";
			break;
		case curveto:{
				outf << "    currentPath.curveTo(";
				outf << (elem.getPoint(0).x_ +
						 x_offset) << "f, " << (currentDeviceHeight -
												elem.getPoint(0).y_ + y_offset) << "f, ";
				outf << (elem.getPoint(1).x_ +
						 x_offset) << "f, " << (currentDeviceHeight -
												elem.getPoint(1).y_ + y_offset) << "f, ";
				outf << (elem.getPoint(2).x_ +
						 x_offset) << "f, " << (currentDeviceHeight -
												elem.getPoint(2).y_ + y_offset) << "f);";
			}
			break;
		default:
			errf << "\t\tFatal: unexpected case for elem.getType() in drvjava2" << endl;
			abort();
			break;
		}
		outf << endl;
		numberOfElements++;
	}
}
Exemple #13
0
// Version with multi-segment lines
void drvVTK::print_coords()
{
	int bp = 0;
	colorStream << fillR() << " " << fillG() << " " << fillB() << " 0.5" << endl;

	polyStream << numberOfElementsInPath() << " " ;
	linepoints += numberOfElementsInPath();
	lineCount++;
	for (unsigned int n = 0; n < numberOfElementsInPath(); n++) {
		const basedrawingelement & elem = pathElement(n);
		switch (elem.getType()) {
		case moveto:{
				const Point & p = elem.getPoint(0);
				const int m = add_point(p);
				polyStream << m-1 << " ";
				bp = m; 
			}
			break;
		case lineto:{
				const Point & p = elem.getPoint(0);
				const int l = add_point(p);
				polyStream << l-1 << " ";
			}
			break;
		case closepath:
			polyStream << bp-1 << " ";
			break;
		case curveto:{
			errf << "\t\tFatal: unexpected case in drvVTK - curveto " << endl;
			}
			break;
		default:
			errf << "\t\tFatal: unexpected case in drvVTK : default" << endl;
			abort();
			break;
		}
	}
	polyStream << endl;
}
Exemple #14
0
void drvRIB::print_coords()
{
	outf << "PointsGeneralPolygons[1]" << endl;
	outf << "[" << numberOfElementsInPath() << "]" << endl << "[";
	for (unsigned int i = 0; i < numberOfElementsInPath(); i++) {
		outf << i << " ";
	}
	outf << "]" << endl << "\"P\" [";
	for (unsigned int n = 0; n < numberOfElementsInPath(); n++) {
		const basedrawingelement & elem = pathElement(n);
		switch (elem.getType()) {
		case moveto:{
				const Point & p = elem.getPoint(0);
				// outf << "\t\tmoveto ";
				outf << p.x_ + x_offset << " " << p.y_ + y_offset << " 0 ";
			}
			break;
		case lineto:{
				const Point & p = elem.getPoint(0);
				// outf << "\t\tlineto ";
				outf << p.x_ + x_offset << " " << p.y_ + y_offset << " 0 ";
			}
			break;
		case closepath:		// Not supported
			// outf << "\t\tclosepath ";
			break;
		case curveto:{			// Not supported
			}
			break;
		default:
			errf << "\t\tFatal: unexpected case in drvpdf " << endl;
			abort();
			break;
		}
		outf << endl;
	}
	outf << "]" << endl;
}
Exemple #15
0
void SkSVGDevice::drawTextOnPath(const SkDraw&, const void* text, size_t len, const SkPath& path,
                                 const SkMatrix* matrix, const SkPaint& paint) {
    SkString pathID = fResourceBucket->addPath();

    {
        AutoElement defs("defs", fWriter);
        AutoElement pathElement("path", fWriter);
        pathElement.addAttribute("id", pathID);
        pathElement.addPathAttributes(path);

    }

    {
        AutoElement textElement("text", fWriter);
        textElement.addTextAttributes(paint);

        if (matrix && !matrix->isIdentity()) {
            textElement.addAttribute("transform", svg_transform(*matrix));
        }

        {
            AutoElement textPathElement("textPath", fWriter);
            textPathElement.addAttribute("xlink:href", SkStringPrintf("#%s", pathID.c_str()));

            if (paint.getTextAlign() != SkPaint::kLeft_Align) {
                SkASSERT(paint.getTextAlign() == SkPaint::kCenter_Align ||
                         paint.getTextAlign() == SkPaint::kRight_Align);
                textPathElement.addAttribute("startOffset",
                    paint.getTextAlign() == SkPaint::kCenter_Align ? "50%" : "100%");
            }

            SVGTextBuilder builder(text, len, paint, SkPoint::Make(0, 0), 0);
            textPathElement.addText(builder.text());
        }
    }
}
Exemple #16
0
// print a path via a sequence of fline(), fcont(), fbezier3() operations,
// terminating with a final endpath()
void drvplot::print_coords()
{
	Point lastpoint(0, 0);
	const Point & firstpoint = pathElement(0).getPoint(0);
	bool currently_at_lastpoint = false;
	bool last_was_endpath = false;

	// since libplot/libplotter doesn't (yet) support sub-paths,
	// all paths that we draw will be of the form
	// moveto {lineto,curveto}+  {closepath}
	// where {}+ means one or more repetitions, and {} means optional.

	for (unsigned int n = 0; n < numberOfElementsInPath(); n++) {
		const basedrawingelement & elem = pathElement(n);
		switch (elem.getType()) {
		case moveto:
			{
				const Point & p = elem.getPoint(0);
				lastpoint = p;
				currently_at_lastpoint = false;
				last_was_endpath = false;
			}
			break;
		case lineto:
			{
				const Point & p = elem.getPoint(0);
				if (currently_at_lastpoint)
					(void)plotter->fcont(p.x_ + x_offset, p.y_ + y_offset);
				else
					(void)plotter->fline(lastpoint.x_ + x_offset,
								   lastpoint.y_ + y_offset, p.x_ + x_offset, p.y_ + y_offset);
				lastpoint = p;
				currently_at_lastpoint = true;
				last_was_endpath = false;
			}
			break;
		case curveto:
			{
				const Point & p1 = lastpoint;
				const Point & p2 = elem.getPoint(0);
				const Point & p3 = elem.getPoint(1);
				const Point & p4 = elem.getPoint(2);

				(void)plotter->fbezier3(p1.x_ + x_offset, p1.y_ + y_offset,
								  p2.x_ + x_offset, p2.y_ + y_offset,
								  p3.x_ + x_offset, p3.y_ + y_offset,
								  p4.x_ + x_offset, p4.y_ + y_offset);
				lastpoint = p4;
				currently_at_lastpoint = true;
				last_was_endpath = false;
			}
			break;
		case closepath:
			if (currently_at_lastpoint)
				/* have drawn at least one segment */
			{
				(void)plotter->fcont(firstpoint.x_ + x_offset, firstpoint.y_ + y_offset);
				(void)plotter->endpath();
				currently_at_lastpoint = true;
				last_was_endpath = true;
			}
			break;
		default:
			errf << "\t\tFatal: unexpected case in drvlplot " << endl;
			abort();
			break;
		}
	}
	if (last_was_endpath == false)
		(void)plotter->endpath();
}
Exemple #17
0
// print control points
void drvFIG::print_spline_coords2()
{
	int j = 0;
	Point lastp;
	int maxj = 8;

	unsigned int last = numberOfElementsInPath() - 1;
	for (unsigned int n = 0; n <= last; n++) {
		const basedrawingelement & elem = pathElement(n);
		switch (elem.getType()) {
		case moveto:
			{
				buffer << " 0";
				if (n != last)
					buffer << " ";
				j++;
				if (j == maxj) {
					j = 0;
					buffer << "\n";
					if ((n + 1) != numberOfElementsInPath()) {
						buffer << "\t";
					}
				}
				lastp = elem.getPoint(0);
			}
			break;
		case lineto:
			{
				buffer << " 0";
				if (n != last)
					buffer << " ";
				j++;
				if (j == maxj) {
					j = 0;
					buffer << "\n";
					if ((n + 1) != numberOfElementsInPath()) {
						buffer << "\t";
					}
				}
			}
			break;
		case closepath:
			{
				buffer << " 0";
				if (n != last)
					buffer << " ";
				j++;
				if (j == maxj) {
					j = 0;
					buffer << "\n";
					if ((n + 1) != numberOfElementsInPath()) {
						buffer << "\t";
					}
				}
			}
			break;
		case curveto:
			{
// IJMP - change to quintic spline
				// put all points, middle points will have control value -1
				float kp = 0.0;
				for (unsigned int i = 0; i < 5; i++) {
					if (i == 1) {
						kp = -1.0; //lint !e736
					}
					if (i == 4) {
						kp = 0.0;
					}
					buffer << " " << kp;
					if (!((n == last) && (i == 4)))
						buffer << " ";
					j++;
					if (j == maxj) {
						j = 0;
						buffer << "\n";
						if (!((i == 4)
							  && ((n + 1) == numberOfElementsInPath()))) {
							buffer << "\t";
						}
					}
				}
				lastp = elem.getPoint(2);
			}
			break;
		default:
			errf << "\t\tFatal: unexpected case in drvfig " << endl;
			abort();
			break;
		}
	}
	if (j != 0) {
		buffer << endl;
	}
}
Exemple #18
0
void drvIDRAW::print_coords()
{
	unsigned int pathelts = numberOfElementsInPath();
	bool closed;				// True if shape is closed
	bool curved;				// True if shape is curved
	const Point *firstpoint;	// First and last points in shape
	const Point *lastpoint;
	unsigned int totalpoints;	// Total number of points in shape
	const Point dummypoint(-123.456f, -789.101112f);	// Used to help eliminate duplicates

	unsigned int i, j;

	// First, try to figure out what type of shape we have
	closed = false;
	curved = false;
	for (i = 0; i < pathelts; i++) {
		if (pathElement(i).getType() == curveto)
			curved = true;
		else if (pathElement(i).getType() == closepath)
			closed = true;
	}
	const Point **pointlist = new const Point *[pathelts * 3];	// List of points
	 	// Allocate a conservative amount
	assert(pointlist != NIL);
	firstpoint = NIL;
	lastpoint = &dummypoint;
	totalpoints = 0;
	for (i = 0; i < pathelts; i++) {
		const basedrawingelement & pelt = pathElement(i);

		if ((pelt.getType() == moveto || pelt.getType() == lineto) &&
			!(pelt.getPoint(0) == *lastpoint))
			lastpoint = pointlist[totalpoints++] = &pelt.getPoint(0);
		else if (pelt.getType() == curveto)
			for (j = 0; j < 3; j++)
				lastpoint = pointlist[totalpoints++] = &pelt.getPoint(j);
	}
	if (totalpoints) {
		firstpoint = pointlist[0];
		if (firstpoint->x_ == lastpoint->x_ && firstpoint->y_ == lastpoint->y_)
			closed = true;

		// Find points on the curve for curved lines
		if (curved) {
			const unsigned int pt_per_cp = 5;	// PostScript points per control point
			const unsigned int min_innerpoints = 2;	// Minimum # of points to add
			unsigned int innerpoints;	// Number of points to add
			unsigned int newtotalpoints = 0;	// Number of points in curve

			// ASSUMPTION: Curve is moveto+curveto+curveto+curveto+...
			// List of points on curve
			const Point **newpointlist = new const Point *[pathelts * 3000 / pt_per_cp];	// Allocate a conservative amount
			assert(newpointlist != NIL);
			for (i = 0; i < totalpoints - 3; i += 3) {
				const float x0 = pointlist[i]->x_;
				const float y0 = pointlist[i]->y_;
				const float x1 = pointlist[i + 1]->x_;
				const float y1 = pointlist[i + 1]->y_;
				const float x2 = pointlist[i + 2]->x_;
				const float y2 = pointlist[i + 2]->y_;
				const float x3 = pointlist[i + 3]->x_;
				const float y3 = pointlist[i + 3]->y_;
				const float cx = (x1 - x0) * 3;
				const float cy = (y1 - y0) * 3;
				const float bx = (x2 - x1) * 3 - cx;
				const float by = (y2 - y1) * 3 - cy;
				const float ax = x3 - x0 - cx - bx;
				const float ay = y3 - y0 - cy - by;
				

				// Longer lines get more control points
				innerpoints =(unsigned int) (
							pythagoras((y1 - y0),(x1 - x0) ) + 
							pythagoras((y2 - y1),(x2 - x1) ) + 
							pythagoras((y3 - y2),(x3 - x2) ) ) / pt_per_cp;
				if (innerpoints < min_innerpoints)
					innerpoints = min_innerpoints;

				// Add points to the list
				ADDPOINT(x0, y0);
				for (j = 1; j <= innerpoints; j++) {
					const float t = (float) j / (float) innerpoints;
					const float newx = (((ax * t) + bx) * t + cx) * t + x0;
					const float newy = (((ay * t) + by) * t + cy) * t + y0;
					ADDPOINT(newx, newy);
				}
				ADDPOINT(x3, y3);
			}

			delete[]pointlist;
			pointlist = newpointlist;
			totalpoints = newtotalpoints;
		}
		// Straight lines, not closed
		if (!closed && !curved) {
			if (totalpoints == 2) {	// Special case for single line
				print_header("Line");
				outf << "%I" << endl;
				outf << iscale(firstpoint->x_) << ' ' << iscale(firstpoint->y_) << ' ';
				outf << iscale(lastpoint->x_) << ' ' << iscale(lastpoint->y_) << ' ';
				outf << "Line" << endl;
				outf << "%I 1" << endl;
				outf << "End" << endl << endl;
			} else {			// Otherwise, output a multiline
				print_header("MLine");	// (Should have a special case for Rect)
				outf << "%I " << totalpoints << endl;
				for (i = 0; i < totalpoints; i++) {
					outf << iscale(pointlist[i]->x_) << ' ';
					outf << iscale(pointlist[i]->y_) << endl;
				}
				outf << totalpoints << " MLine" << endl;
				outf << "%I 1" << endl;
				outf << "End" << endl << endl;
			}
		}
		// Straight lines, closed */
		if (closed && !curved) {
			unsigned int numpoints;

			numpoints = totalpoints == 1 ? 1 : totalpoints - 1;
			print_header("Poly");	// Output a polygon
			outf << "%I " << numpoints << endl;
			for (i = 0; i < numpoints; i++) {
				outf << iscale(pointlist[i]->x_) << ' ';
				outf << iscale(pointlist[i]->y_) << endl;
			}
			outf << numpoints << " Poly" << endl;
			outf << "End" << endl << endl;
		}
		// Curved lines, not closed
		if (!closed && curved) {
			print_header("BSpl");	// Output a B-spline
			outf << "%I " << totalpoints << endl;
			for (i = 0; i < totalpoints; i++) {
				outf << iscale(pointlist[i]->x_) << ' ';
				outf << iscale(pointlist[i]->y_) << endl;
			}
			outf << totalpoints << " BSpl" << endl;
			outf << "%I 1" << endl;
			outf << "End" << endl << endl;
		}
		// Curved lines, closed
		if (closed && curved) {
			unsigned int numpoints;

			numpoints = totalpoints == 1 ? 1 : totalpoints - 1;
			print_header("CBSpl");	// Output a closed B-spline
			outf << "%I " << numpoints << endl;
			for (i = 0; i < numpoints; i++) {
				outf << iscale(pointlist[i]->x_) << ' ';
				outf << iscale(pointlist[i]->y_) << endl;
			}
			outf << numpoints << " CBSpl" << endl;
			outf << "End" << endl << endl;
		}
		if (curved) {
			//
			// in this case we have created the pointlist newly with Points on the heap
			//
			if (pointlist)
				for (unsigned int pindex = 0; pindex < totalpoints; pindex++) {
					//cout << "pindex / totalpoints " << pindex  << " " << totalpoints << " " << pointlist[pindex]->x_ << " " << pointlist[pindex]->y_ << " " << pointlist[pindex]<< endl;
#if defined (_MSC_VER) && (_MSC_VER < 1100)
					// MSVC < 6 needs cast here
					delete (Point *)	(pointlist[pindex]);	
#else
					delete				(pointlist[pindex]);	
#endif
				}

		}
	}
	delete[]pointlist;
}
Exemple #19
0
// print edge points
void drvFIG::print_spline_coords1()
{
// IJMP - need curr_point
	Point P1;
	int j = 0;
	unsigned int last = numberOfElementsInPath() - 1;
	for (unsigned int n = 0; n <= last; n++) {
		if (j == 0) {
			buffer << "\t";
		}
		const basedrawingelement & elem = pathElement(n);
		switch (elem.getType()) {
		case moveto:
		case lineto:
			{
				const Point & p = elem.getPoint(0);
				prpoint(buffer, p, (n != last));
				P1 = p;
			}
			j++;
			if (j == 5) {
				j = 0;
				buffer << "\n";
			}
			break;
		case curveto:
			{
// IJMP - change to quintic spline
				// put all points, middle points will have control value 1
// IJMP = do bezier fit
				
				const Point & P2 = elem.getPoint(0);
				const Point & P3 = elem.getPoint(1);
				const Point & P4 = elem.getPoint(2);

				for (int cp = 1; cp <= 5; cp++) {
					const Point p = PointOnBezier((cp * 0.2f), P1, P2, P3, P4);
					// p.x_ = bezpnt((cp * 0.2f), P1.x_, P2.x_, P3.x_, P4.x_);
					// p.y_ = bezpnt((cp * 0.2f), P1.y_, P2.y_, P3.y_, P4.y_);
					prpoint(buffer, p, !((n == last) && (cp == 5)));
					j++;
					if (j == 5) {
						j = 0;
						buffer << "\n";
					}
//                      if ((j == 0) && (cp != 5) && ( n+1 != (numberOfElementsInPath()))) { buffer << "\t"; }
					if ((j == 0) && (n != (numberOfElementsInPath()))) {
						buffer << "\t";
					}
				}
				P1 = P4;
			}
			break;
		case closepath:
			{
				const Point & p = pathElement(0).getPoint(0);
				P1 = p;
				prpoint(buffer, p, (n != last));
			}
			j++;
			if (j == 5) {
				j = 0;
				buffer << "\n";
			}
			break;
		default:
			errf << "\t\tFatal: unexpected case in drvfig " << endl;
			abort();
			break;
		}
	}
	if (j != 0) {
		buffer << "\n";
	}
	buffer << "\t";
}