Example #1
0
void Painter::DrawLineStroke(int width, Color color)
{
	if(IsNull(width) || IsNull(color))
		return;
	Begin();
	LineCap(LINECAP_ROUND);
	switch(width) {
		case PEN_NULL:
			Stroke(0, color);
			End();
			return;
		case PEN_SOLID:
			Stroke(1, color);
			break;
		case PEN_DASH:
			Dash("18 6");
			break;
		case PEN_DOT:
			Dash("3 3");
			break;
		case PEN_DASHDOT:
			Dash("9 6 3 6");
			break;
		case PEN_DASHDOTDOT:
			Dash("9 3 3 3 3 3");
			break;
	default:
		Stroke(width == 0 ? 1 : width, color);
		End();
		return;
	}
	Stroke(1, color);
	End();
}
Example #2
0
// fontrange shows a range of fonts
void fontrange(int w, int h) {
	int *s, sizes[] = { 6, 7, 8, 9, 10, 11, 12, 14, 16, 18, 21, 24, 36, 48, 60, 72, 96, 0 };
	VGfloat x, y = h / 2, spacing = 50, s2 = spacing / 2, len, lx;
	char num[4];

	Start(w, h);
	Background(255, 255, 255);

	// compute the length so we can center
	for (len = 0, s = sizes; *s; s++) {
		len += *s + spacing;
	}
	len -= spacing;
	lx = (w / 2) - (len / 2);			   // center point

	// for each size, display a character and label
	for (x = lx, s = sizes; *s; s++) {
		Fill(128, 0, 0, 1);
		TextMid(x, y, "a", *s);
		Fill(128, 128, 128, 1);
		snprintf(num, 3, "%d", *s);
		TextMid(x, y - spacing, num, 16);
		x += *s + spacing;
	}
	// draw a line below the characters, a curve above
	x -= spacing;
	Stroke(150, 150, 150, 0.5);
	StrokeWidth(2);
	Line(lx, y - s2, x, y - s2);
	Fill(255, 255, 255, 1);
	Qbezier(lx, y + s2, x, y + s2, x, y + (spacing * 3));
	End();
}
Example #3
0
void Painter::DrawEllipseOp(const Rect& r, Color color, int pen, Color pencolor)
{
	Sizef sz = r.GetSize();
	Ellipse(r.left + sz.cx / 2, r.top + sz.cy / 2, sz.cx / 2, sz.cy / 2);
	Fill(color);
	Stroke(max(pen, 0), pencolor);
}
Example #4
0
void Painter::DrawLineOp(int x1, int y1, int x2, int y2, int width, Color color)
{
	double h = width / 2;
	Move(x1 + h, y1 + h);
	Line(x2 + h, y2 + h);
	Stroke(max(width, 0), color);
}
Example #5
0
void drawLine(int width, int height) {
	VGfloat shapecolor[4];
	RGB(202, 225, 255, shapecolor);
	
	VGfloat dotsize = 20;	
	setfill(shapecolor);

	double angle = getAngle(width, height);

	double hyp1 = height/1.3;	// inner radius
	double hyp2 = height/2;	// outer radius

	VGfloat x1, y1, x2, y2;
	x1 = hyp1 * cos(angle);
	y1 = hyp1 * sin(angle);
	x2 = hyp2 * cos(angle);
	y2 = hyp2 * sin(angle);


	StrokeWidth(5);
	Stroke(43, 43, 43, 1);
	Line(x1, y1, x2, y2);
	coordpoint(x2, y2, dotsize, shapecolor);

}
Example #6
0
// rshapes draws shapes with random colors, strokes, and sizes. 
void rshapes(int width, int height, int n) {
	int i, j, np = 10;
	VGfloat sx, sy, cx, cy, px, py, ex, ey, pox, poy;
	VGfloat polyx[np], polyy[np];
	rseed();
	Start(width, height);
	for (i = 0; i < n; i++) {
		Fill(randcolor(), randcolor(), randcolor(), drand48());
		Ellipse(randf(width), randf(height), randf(200), randf(100));
		Circle(randf(width), randf(height), randf(100));
		Rect(randf(width), randf(height), randf(200), randf(100));
		Arc(randf(width), randf(height), randf(200), randf(200), randf(360), randf(360));

		sx = randf(width);
		sy = randf(height);
		Stroke(randcolor(), randcolor(), randcolor(), 1);
		StrokeWidth(randf(5));
		Line(sx, sy, sx + randf(200), sy + randf(100));
		StrokeWidth(0);

		sx = randf(width);
		sy = randf(height);
		ex = sx + randf(200);
		ey = sy;
		cx = sx + ((ex - sx) / 2.0);
		cy = sy + randf(100);
		Qbezier(sx, sy, cx, cy, ex, ey);

		sx = randf(width);
		sy = randf(height);
		ex = sx + randf(200);
		ey = sy;
		cx = sx + ((ex - sx) / 2.0);
		cy = sy + randf(100);
		px = cx;
		py = sy - randf(100);
		Cbezier(sx, sy, cx, cy, px, py, ex, ey);

		pox = randf(width);
		poy = randf(height);
		for (j = 0; j < np; j++) {
			polyx[j] = pox + randf(200);
			polyy[j] = poy + randf(100);
		}
		Polygon(polyx, polyy, np);

		pox = randf(width);
		poy = randf(height);
		for (j = 0; j < np; j++) {
			polyx[j] = pox + randf(200);
			polyy[j] = poy + randf(100);
		}
		Polyline(polyx, polyy, np);
	}
	Fill(128, 0, 0, 1);
	Text(20, 20, "OpenVG on the Raspberry Pi", 32);
	End();
}
void FindDrawPoints(int y, int x, int ys, int xe, Mat fill_region, ofstream & outputFile, float size, Vec3b rgb, Vec4f cmyk, int lineWidth, StrokeCluster &cluster){
	vector<Point> points;
	bool cross = true;

	//Find draw points
	while (y > ys && x < xe){		// Not touch boundary
		{
			if ((int)fill_region.at<uchar>(y, x) > 128 && !cross){
				points.push_back(Point(x - 1, y + 1));
				cross = true;
			}
			else if ((int)fill_region.at<uchar>(y, x) < 128 && cross){
				points.push_back(Point(x, y));
				cross = false;
			}
		}
		y = y - 1;
		x = x + 1;
	}
	if (points.size() % 2 != 0)  // add the boundary point
		points.push_back(Point(x, y));

	
	//Draw points
	int num = points.size() / 2;
	if (num > 0)
	if (!turn){
		for (int i = 0; i < num; i++)
		{
			cluster.addStroke(Stroke(rgb, cmyk, points[2 * i], points[2 * i + 1], lineWidth));
			outputFile << points[2 * i].x << " " << points[2 * i].y << " " << points[2 * i + 1].x << " " << points[2 * i + 1].y << endl;
			fillLines++;
		}
	}
	else {
		for (int i = num - 1; i >= 0; i--)
		if (norm(points[2 * i] - points[2 * i + 1]) > size*0.05)
		{
			cluster.addStroke(Stroke(rgb, cmyk, points[2 * i + 1], points[2 * i], lineWidth));
			outputFile << points[2 * i + 1].x << " " << points[2 * i + 1].y << " " << points[2 * i].x << " " << points[2 * i].y << endl;
			fillLines++;
		}
	}
	turn = !turn;
}
Example #8
0
// virtual
void Polyline::OnRender(Graphics* pGraphics)
{
	PointCollection* points = get_Points();

	if (points)
	{
		unsigned int count = points->GetCount();
		if (count > 0)
		{
			__release<LDraw::GraphicsPathF> path = new LDraw::GraphicsPathF;

			Point point = points->get_Item(0);
			path->AddMove(point.X, point.Y);

			for (unsigned int i = 1; i < count; i++)
			{
				point = points->get_Item(i);
				path->AddLine(point.X, point.Y);
			}

			Brush* Fill = get_Fill();
			if (Fill)
			{
				__release<LDraw::Brush> brush = Fill->CreateBrush(this, 1, 1);
				if (brush != NULL)
				{
					pGraphics->FillPath(brush, path);
				}
			}

#if 0
			double StrokeThickness;
			if (m_StrokeThickness)
				m_StrokeThickness->get_Value(&StrokeThickness);
			else
				StrokeThickness = 1;

			if (StrokeThickness > 0)
			{
				CComQIPtr<CLXUIElementImplImpl> Stroke(m_Stroke);
				if (Stroke)
				{
					Gdiplus::Brush* pBrush = Stroke->CreateBrush(this, 1, 1);
					if (pBrush)
					{
						Gdiplus::Pen pen(pBrush, StrokeThickness);

						pGraphics->DrawPath(pen, &path);
						delete pBrush;
					}
				}
			}
#endif
		}

	}
}
Example #9
0
// grid draws a grid
void grid(VGfloat x, VGfloat y, int n, int w, int h) {
	VGfloat ix, iy;
	Stroke(128, 128, 128, 0.5);
	StrokeWidth(2);
	for (ix = x; ix <= x + w; ix += n) {
		Line(ix, y, ix, y + h);
	}

	for (iy = y; iy <= y + h; iy += n) {
		Line(x, iy, x + w, iy);
	}
}
Example #10
0
void Leveler::draw_vertical_line( )
{
	Stroke(255, 128, 128, 0.5);
	StrokeWidth(4);

	VGfloat alpha = 1.0;				// start solid
	//VGfloat x_spacing = (width) / 10.0;	
	
	// VERTICAL
	Fill(255, 0, 125, alpha);
	Line(left, bottom+height, left, bottom);
}
Example #11
0
int Leveler::draw() 
{	
	Stroke		(255, 128, 128, 0.5);
	StrokeWidth (2);

	draw_l_title		(  );
	draw_horizontal_tics(  );
	draw_vertical_line  (  );
	draw_x_label	 	(  );
	draw_y_label	 	(  );

	draw_marker(  );
}
Example #12
0
void Leveler::draw_horizontal_tics(  ) 
{
	Stroke(255, 128, 128, 0.5);
	StrokeWidth(2);

	float alpha = 1.0;
	float y_spacing = ((float)(top - bottom)) / 10.0;	
	// HORIZONTAL
	Fill(255, 0, 125, alpha);
	for (VGfloat y = bottom; y <= top; y+=y_spacing) 
	{
		Line(left, y, left+TIC_WIDTH, y);
	}
}
Example #13
0
void Leveler::draw_vertical_line( )
{
	Stroke(255, 128, 128, 0.5);
	StrokeWidth(4);

	int i;
	VGfloat x;
	VGfloat alpha = 1.0;				// start solid
	VGfloat x_spacing = (right-left) / 10.0;	
	
	// VERTICAL
	Fill(255, 0, 125, alpha);
	Line(left, top, left, bottom);
}
Example #14
0
int Leveler::draw() 
{	
	if (!Visible) return 0;
	
	Stroke		(255, 128, 128, 0.5);
	StrokeWidth (2); 
 
	draw_l_title		(  );
	draw_horizontal_tics(  );
	draw_vertical_line  (  );
	draw_x_label	 	(  );
	draw_y_label	 	(  );

	draw_marker			(  );
	return 1;	
}
Example #15
0
void Leveler::draw_marker(  )
{
	Stroke(255, 255, 0, 1.0);
	StrokeWidth(5);

	Fill(255, 0, 0, 1);
	VGfloat x[3];
	VGfloat y[3];

	y[0] = get_level_pixel();
	y[1] = get_level_pixel() + MARKER_HEIGHT/2;
	y[2] = get_level_pixel() - MARKER_HEIGHT/2;

	x[0] = left + TIC_WIDTH;
	x[1] = left + TIC_WIDTH + MARKER_WIDTH;
	x[2] = left + TIC_WIDTH + MARKER_WIDTH;	
	Polygon(x, y, 3);
}
Example #16
0
Painter& Painter::Stroke(double width, const Image& image, const Pointf& p1, const Pointf& p2, dword flags)
{
	return Stroke(width, image, GetLineSzXform(p1, p2, image.GetSize()), flags);
}
Example #17
0
 Polyline(std::vector<Point> const & points,
     Fill const & fill = Fill(), Stroke const & stroke = Stroke())
     : Shape(fill, stroke), points(points) { }
Example #18
0
Painter& Painter::Stroke(double width, const Image& image, double x1, double y1, double x2, double y2, dword flags)
{
	return Stroke(width, image, Pointf(x1, y1), Pointf(x2, y2), flags);
}
Example #19
0
void CairoRenderer::RenderOperator(const Operator *pOp, const Object **pParams, int nParams)
{
	const char *cstr;
	double x, y;
	double v[6];
	int i, n;
	const Object *pObj;
	const Stream *pStream;
	const Dictionary *pDict;
	cairo_matrix_t matrix;
	int nWidth, nHeight;
	cairo_surface_t *pSurface;

	cstr = pOp->GetValue();

	if (strchr("fFbBW", *cstr) != NULL)
		if (cstr[1] == '\0')
			cairo_set_fill_rule(m_pCairo, CAIRO_FILL_RULE_WINDING);
		else if (cstr[1] == '*')
			cairo_set_fill_rule(m_pCairo, CAIRO_FILL_RULE_EVEN_ODD);

	if (*cstr == 'b')  //close, fill, and stroke
	{
		cairo_close_path(m_pCairo);
		cairo_fill(m_pCairo);
		Stroke();
	}
	else if (strcmp(cstr, "B") == 0 || strcmp(cstr, "B*") == 0)  //fill and stroke
	{
		cairo_fill(m_pCairo);
		Stroke();
	}
	else if (strcmp(cstr, "BDC") == 0)
	{
		NOT_IMPLEMENTED;
	}
	else if (strcmp(cstr, "BI") == 0)
	{
		NOT_IMPLEMENTED;
	}
	else if (strcmp(cstr, "BMC") == 0)
	{
		NOT_IMPLEMENTED;
	}
	else if (strcmp(cstr, "BT") == 0)
	{
		cairo_save(m_pCairo);
		cairo_move_to(m_pCairo, 0.0, 0.0);
		m_cairo_face = NULL;
	}
	else if (strcmp(cstr, "BX") == 0)
	{
		NOT_IMPLEMENTED;
	}
	else if (strcmp(cstr, "c") == 0)  //curve to
	{
		ConvertNumeric(pParams, nParams, v);
		cairo_curve_to(m_pCairo, v[0], v[1], v[2], v[3], v[4], v[5]);
	}
	else if (strcmp(cstr, "cm") == 0)  //concat
	{
		ConvertNumeric(pParams, nParams, v);
		cairo_matrix_init(&matrix, v[0], v[1], v[2], v[3], v[4], v[5]);
		cairo_transform(m_pCairo, &matrix);
	}
	else if (strcmp(cstr, "CS") == 0)  //color space
	{
		NOT_IMPLEMENTED;
	}
	else if (strcmp(cstr, "cs") == 0)  //color space
	{
		NOT_IMPLEMENTED;
	}
	else if (strcmp(cstr, "d") == 0)  //line dash
		SetDash(pParams[0], pParams[1]);
	else if (strcmp(cstr, "d0") == 0)
	{
		NOT_IMPLEMENTED;
	}
	else if (strcmp(cstr, "d1") == 0)
	{
		NOT_IMPLEMENTED;
	}
	else if (strcmp(cstr, "Do") == 0)
	{
		pStream = (const Stream *)GetResource(XOBJECT, ((Name *)pParams[0])->GetValue());
		pDict = pStream->GetDictionary();
		pObj = pDict->GetValue("Subtype");
		if (strcmp(((const Name *)pObj)->GetValue(), "Image") == 0)
		{
			nWidth = ((const Numeric *)pDict->GetValue("Width"))->GetValue();
			nHeight = ((const Numeric *)pDict->GetValue("Height"))->GetValue();
			cairo_matrix_init(&matrix, 1.0 / nWidth, 0.0, 0.0, -1.0 / nHeight, 0.0, 1.0);
			cairo_save(m_pCairo);
			cairo_transform(m_pCairo, &matrix);
			cairo_rectangle(m_pCairo, 0.0, 0.0, nWidth, nHeight);
			cairo_clip(m_pCairo);
			pSurface = CreateImageSurface(pStream, nWidth, nHeight);
			cairo_set_source_surface(m_pCairo, pSurface, 0.0, 0.0);
			cairo_paint(m_pCairo);
			cairo_surface_destroy(pSurface);
			cairo_restore(m_pCairo);
		}
	}
	else if (strcmp(cstr, "DP") == 0)
	{
		NOT_IMPLEMENTED;
	}
	else if (strcmp(cstr, "EI") == 0)
	{
		NOT_IMPLEMENTED;
	}
	else if (strcmp(cstr, "EMC") == 0)
	{
		NOT_IMPLEMENTED;
	}
	else if (strcmp(cstr, "ET") == 0)
	{
		cairo_restore(m_pCairo);
		if (m_cairo_face)
		{
			cairo_set_font_face(m_pCairo, NULL);
			cairo_font_face_destroy(m_cairo_face);
		}
	}
	else if (strcmp(cstr, "EX") == 0)
	{
		NOT_IMPLEMENTED;
	}
	else if (*cstr == 'f' || *cstr == 'F')  //fill
		cairo_fill(m_pCairo);
	else if (strcmp(cstr, "G") == 0)
	{
		ConvertNumeric(pParams, nParams, v);
		m_pStrokeColor[0] = v[0];
		m_pStrokeColor[1] = v[0];
		m_pStrokeColor[2] = v[0];
	}
	else if (strcmp(cstr, "g") == 0)
	{
		ConvertNumeric(pParams, nParams, v);
		cairo_set_source_rgba(m_pCairo, v[0], v[0], v[0], 1.0);
	}
	else if (strcmp(cstr, "gs") == 0)  //set graphics state
		SetGraphicsState(((const Name *)pParams[0])->GetValue());
	else if (strcmp(cstr, "h") == 0)  //close subpath
		cairo_close_path(m_pCairo);
	else if (strcmp(cstr, "i") == 0)  //flatness tolerance
	{
		ConvertNumeric(pParams, nParams, v);
		cairo_set_tolerance(m_pCairo, v[0]);
	}
	else if (strcmp(cstr, "ID") == 0)
	{
		NOT_IMPLEMENTED;
	}
	else if (strcmp(cstr, "j") == 0)  //line join
	{
		ConvertNumeric(pParams, nParams, v);
		cairo_set_line_join(m_pCairo, (cairo_line_join_t)v[0]);
	}
	else if (strcmp(cstr, "J") == 0)  //line cap
	{
		ConvertNumeric(pParams, nParams, v);
		cairo_set_line_cap(m_pCairo, (cairo_line_cap_t)v[0]);
	}
	else if (strcmp(cstr, "K") == 0)
	{
		ConvertNumeric(pParams, nParams, v);
		m_pStrokeColor[0] = (1.0 - v[0]) * (1.0 - v[3]);
		m_pStrokeColor[1] = (1.0 - v[1]) * (1.0 - v[3]);
		m_pStrokeColor[2] = (1.0 - v[2]) * (1.0 - v[3]);
	}
	else if (strcmp(cstr, "k") == 0)
	{
		ConvertNumeric(pParams, nParams, v);
		cairo_set_source_rgba(m_pCairo, (1.0 - v[0]) * (1.0 - v[3]), (1.0 - v[1]) * (1.0 - v[3]), (1.0 - v[2]) * (1.0 - v[3]), 1.0);
	}
	else if (strcmp(cstr, "l") == 0)  //line to
	{
		ConvertNumeric(pParams, nParams, v);
		cairo_line_to(m_pCairo, v[0], v[1]);
	}
	else if (strcmp(cstr, "m") == 0)  //new sub path
	{
		ConvertNumeric(pParams, nParams, v);
		cairo_move_to(m_pCairo, v[0], v[1]);
	}
	else if (strcmp(cstr, "M") == 0)  //miter limit
	{
		ConvertNumeric(pParams, nParams, v);
		cairo_set_miter_limit(m_pCairo, v[0]);
	}
	else if (strcmp(cstr, "MP") == 0)
	{
		NOT_IMPLEMENTED;
	}
	else if (strcmp(cstr, "n") == 0)  //end path
		cairo_new_path(m_pCairo);
	else if (strcmp(cstr, "q") == 0)  //save graphics state
		cairo_save(m_pCairo);
	else if (strcmp(cstr, "Q") == 0)  //restore graphics state
		cairo_restore(m_pCairo);
	else if (strcmp(cstr, "re") == 0)  //rectangle
	{
		ConvertNumeric(pParams, nParams, v);
		cairo_rectangle(m_pCairo, v[0], v[1], v[2], v[3]);
	}
	else if (strcmp(cstr, "RG") == 0)
	{
		ConvertNumeric(pParams, nParams, m_pStrokeColor);
	}
	else if (strcmp(cstr, "rg") == 0)
	{
		ConvertNumeric(pParams, nParams, v);
		cairo_set_source_rgba(m_pCairo, v[0], v[1], v[2], 1.0);
	}
	else if (strcmp(cstr, "ri") == 0)  //color rendering intent
		SetIntent(((const Name *)pParams[0])->GetValue());
	else if (strcmp(cstr, "s") == 0)  //close and stroke
	{
		cairo_close_path(m_pCairo);
		Stroke();
	}
	else if (strcmp(cstr, "S") == 0)  //stroke
		Stroke();
	else if (strcmp(cstr, "SC") == 0)
	{
		NOT_IMPLEMENTED;
	}
	else if (strcmp(cstr, "sc") == 0)
	{
		NOT_IMPLEMENTED;
	}
	else if (strcmp(cstr, "SCN") == 0)
	{
		NOT_IMPLEMENTED;
	}
	else if (strcmp(cstr, "scn") == 0)
	{
		NOT_IMPLEMENTED;
	}
	else if (strcmp(cstr, "sh") == 0)
	{
		NOT_IMPLEMENTED;
	}
	else if (strcmp(cstr, "T*") == 0)
	{
		cairo_translate(m_pCairo, 0.0, -m_dTextLead);
		cairo_move_to(m_pCairo, 0.0, 0.0);
	}
	else if (strcmp(cstr, "Tc") == 0)
	{
		NOT_IMPLEMENTED;
	}
	else if (strcmp(cstr, "Td") == 0)
	{
		ConvertNumeric(pParams, nParams, v);
		cairo_translate(m_pCairo, v[0], v[1]);
		cairo_move_to(m_pCairo, 0.0, 0.0);
	}
	else if (strcmp(cstr, "TD") == 0)
	{
		ConvertNumeric(pParams, nParams, v);
		cairo_translate(m_pCairo, v[0], v[1]);
		cairo_move_to(m_pCairo, 0.0, 0.0);
		m_dTextLead = -v[1];
	}
	else if (strcmp(cstr, "Tf") == 0)
	{
		ChangeFont(((const Name *)pParams[0])->GetValue());
		SetFontFace(m_pFontData->GetFontFile());

		ConvertNumeric(pParams + 1, nParams - 1, v);
		cairo_matrix_init_scale(m_pFontMatrix, v[0], -v[0]);
		cairo_set_font_matrix(m_pCairo, m_pFontMatrix);
	}
	else if (strcmp(cstr, "Tj") == 0)
		RenderString((const String *)pParams[0]);
	else if (strcmp(cstr, "TJ") == 0)
	{
		n = ((const Array *)pParams[0])->GetSize();
		for (i = 0; i < n; i++)
		{
			pObj = ((const Array *)pParams[0])->GetValue(i);
			if (pObj->GetType() == Object::OBJ_STRING)
				RenderString((const String *)pObj);
			else if (pObj->GetType() == Object::OBJ_NUMERIC)
				cairo_translate(m_pCairo, -((const Numeric *)pObj)->GetValue() / 1000.0, 0.0);
		}
	}
	else if (strcmp(cstr, "TL") == 0)
	{
		ConvertNumeric(pParams, nParams, v);
		m_dTextLead = v[0];
	}
	else if (strcmp(cstr, "Tm") == 0)
	{
		ConvertNumeric(pParams, nParams, v);
		cairo_matrix_init(&matrix, v[0], v[1], v[2], v[3], v[4], v[5]);
		cairo_matrix_multiply(&matrix, m_pFontMatrix, &matrix);
		cairo_set_font_matrix(m_pCairo, &matrix);
		cairo_move_to(m_pCairo, 0.0, 0.0);
	}
	else if (strcmp(cstr, "Tr") == 0)
	{
		ConvertNumeric(pParams, nParams, v);
		m_nTextMode = v[0];
	}
	else if (strcmp(cstr, "Ts") == 0)
	{
		NOT_IMPLEMENTED;
	}
	else if (strcmp(cstr, "Tw") == 0)
	{
		NOT_IMPLEMENTED;
	}
	else if (strcmp(cstr, "Tz") == 0)
	{
		ConvertNumeric(pParams, nParams, v);
		cairo_scale(m_pCairo, v[0] / 100.0, 1.0);
	}
	else if (strcmp(cstr, "v") == 0)  //curve to
	{
		ConvertNumeric(pParams, nParams, v);
		cairo_get_current_point(m_pCairo, &x, &y);
		cairo_curve_to(m_pCairo, x, y, v[0], v[1], v[2], v[3]);
	}
	else if (strcmp(cstr, "w") == 0)  //line width
	{
		ConvertNumeric(pParams, nParams, v);
		cairo_set_line_width(m_pCairo, v[0] + 0.5);
	}
	else if (*cstr == 'W')  //clipping path
		cairo_clip(m_pCairo);
	else if (strcmp(cstr, "y") == 0)  //curve to
	{
		ConvertNumeric(pParams, nParams, v);
		cairo_curve_to(m_pCairo, v[0], v[1], v[2], v[3], v[2], v[3]);
	}
	else if (strcmp(cstr, "'") == 0)
	{
		cairo_translate(m_pCairo, 0.0, -m_dTextLead);
		cairo_move_to(m_pCairo, 0.0, 0.0);
		RenderString((const String *)pParams[0]);
	}
	else if (strcmp(cstr, "\"") == 0)
	{
		cairo_translate(m_pCairo, 0.0, -m_dTextLead);
		cairo_move_to(m_pCairo, 0.0, 0.0);
		RenderString((const String *)pParams[2]);
	}
	else
	{
		assert(false);
	}
}
Example #20
0
Painter& Painter::Stroke(double width, double fx, double fy, const RGBA& color1, double cx, double cy, double r, const RGBA& color2, int style)
{
	return Stroke(width, Pointf(fx, fy), color1, Pointf(cx, cy), r, color2, style);
}
Example #21
0
Painter& Painter::Stroke(double width, double x1, double y1, const RGBA& color1, double x2, double y2, const RGBA& color2, int style)
{
	return Stroke(width, Pointf(x1, y1), color1, Pointf(x2, y2), color2, style);
}
Example #22
0
inline Painter& Painter::Stroke(double width, double x1, double y1, const RGBA& color1, double r, const RGBA& color2, int style)
{
	return Stroke(width, x1, y1, color1, x1, y1, r, color2, style);
}
Example #23
0
///////////////////////////////////////////////////////////////////////////////
//
//      Run simplified version of Hertzmann's painterly image filter.
//      You probably will want to use the Draw_Stroke funciton and the
//      Stroke class to help.
//      Return success of operation.
//
///////////////////////////////////////////////////////////////////////////////
bool TargaImage::NPR_Paint()
{
	TargaImage ref_image = TargaImage(*this);
	TargaImage canvas = TargaImage(width, height); //Constant color that will get painted on
	
	int x, y, i, j, g, m;
	int r0, g0, b0, r1, g1, b1;
	typedef tuple<int, int, double> error_point;

	double d, area_error;
	int T = 25; //Error threshold
	static const unsigned int arr[] = {7, 3, 1}; //Brush sizes
	vector<int> rs (arr, arr + sizeof(arr) / sizeof(arr[0]) );

	int rad;
	//*****
	//Paint
	//*****
	for(size_t b=0; b < rs.size(); b++) { //For each brush size
		ref_image.Filter_Gaussian_N(2*rs[b]+1); //referenceImage
		g = 2*rs[b]+1; //Could also be 2*rs[b]+1
		rad = 3*rs[b];
		//***Paint a layer***
		vector <Stroke> strokes;
		//Find all of the grid block centers
		vector < tuple<int, int> > centers;
		centers.reserve( (width/g + 1)* (height/g + 1) );
		for( x = g/2; x < g*(width/g); x+=g ) {
			for( y = g/2; y < g*(height/g); y+=g ) {
				centers.push_back( make_tuple(x, y) );
			}
		}
		//Construct overlapping blocks around right and bottom edge, Possibly Unnecessary
		if (width % g) { //Hold x constant equal to width-g/2-1, loop down the column increasing y			
			x = width - g/2 - 1;
			for( y = g/2; y < g*(height/g); y+=g ) {
				centers.push_back( make_tuple(x, y) );
			}
		}
		if (height % g) {
			y = height - g/2 - 1; //Hold y constant equal to height-g/2-1, loop across the row increasing x
			for( x = g/2; x < g*(width/g); x+=g ) {
				centers.push_back( make_tuple(x, y) );
			}
		}
		//if both x_extra and y_extra then need final bottom right corner block, probably unnecessary		
		

		for( size_t c=0; c < centers.size(); c++ ) { //For each grid center
			tie (x, y) = centers[c];
				//Find the error in the area/region/block
				vector < error_point > errors;
				errors.reserve(g*g);
				area_error = 0;
				for (j = -g/2; j<=g/2; ++j) {
					for (i = -g/2; i<=g/2; ++i) {
						m = (width*(y+j) + (x+i))*4; //Location of current pixel
						tie (r0, g0, b0) = make_tuple(ref_image.data[m], ref_image.data[m+1], ref_image.data[m+2]);
						tie (r1, g1, b1) = make_tuple(canvas.data[m], canvas.data[m+1], canvas.data[m+2]);
						//Calculate euclidean distance
						d = sqrt( (double) (r1-r0)*(r1-r0) + (g1-g0)*(g1-g0) + (b1-b0)*(b1-b0) ); 
						//Save the coordinate and its error
						errors.push_back(error_point(x+i, y+j, d));
						area_error += d;
					}//i
				}//j
				if( area_error > T ) {
					//Find largest error point
					sort(errors.begin(), errors.end(), cmp_errors);					
					tie (i, j, d) = errors.front();
					//Build a Stroke at loacation x,y with radius and value of r,g,b,alpha
					m = (width*j + i)*4; //Location of current pixel
					Stroke s = Stroke(rad, i, j, ref_image.data[m], ref_image.data[m+1], ref_image.data[m+2], ref_image.data[m+3]);
					strokes.push_back(s);
				}

		}//c

		//*******
		//Paint all strokes in random order onto canvas
		//*******
		random_shuffle ( strokes.begin(), strokes.end() );
		vector <Stroke>::iterator it;
		for (it = strokes.begin(); it != strokes.end(); it++) {
			canvas.Paint_Stroke(*it);
		}

		//Reset the reference image to the unchanged image data for the next smaller pass
		memcpy(ref_image.data, data, sizeof(unsigned char) * width * height * 4); 
	}//b	

	//Write the canvas data to the displayed image
	memcpy(data, canvas.data, sizeof(unsigned char) * width * height * 4);
	//Overwrite alpha values
	for(i=3; i<width*height*4; i+=4) {
		data[i] = 255;
	}

    return true;
}
Example #24
0
// refcard shows a reference card of shapes
void refcard(int width, int height) {
	char *shapenames[] = {
		"Circle",
		"Ellipse",
		"Rectangle",
		"Rounded Rectangle",
		"Line",
		"Polyline",
		"Polygon",
		"Arc",
		"Quadratic Bezier",
		"Cubic Bezier",
		"Image"
	};
	VGfloat shapecolor[4];
	RGB(202, 225, 255, shapecolor);
	VGfloat top = height * .95, sx = 500, sy = top, sw = width * .05, sh = height * .045, dotsize = 7, spacing = 2.0;

	int i, ns = sizeof(shapenames) / sizeof(char *), fontsize = height * .033;
	Start(width, height);
	sx = width * 0.10;

	Fill(128, 0, 0, 1);
	TextEnd(width - 20, height / 2, "OpenVG on the Raspberry Pi", fontsize + (fontsize / 2));
	Fill(0, 0, 0, 1);
	for (i = 0; i < ns; i++) {
		Text(sx + sw + sw / 2, sy, shapenames[i], fontsize);
		sy -= sh * spacing;
	}
	sy = top;
	VGfloat cx = sx + (sw / 2), ex = sx + sw;
	setfill(shapecolor);
	Circle(cx, sy, sw);
	coordpoint(cx, sy, dotsize, shapecolor);
	sy -= sh * spacing;
	Ellipse(cx, sy, sw, sh);
	coordpoint(cx, sy, dotsize, shapecolor);
	sy -= sh * spacing;
	Rect(sx, sy, sw, sh);
	coordpoint(sx, sy, dotsize, shapecolor);
	sy -= sh * spacing;
	Roundrect(sx, sy, sw, sh, 20, 20);
	coordpoint(sx, sy, dotsize, shapecolor);
	sy -= sh * spacing;

	StrokeWidth(1);
	Stroke(204, 204, 204, 1);
	Line(sx, sy, ex, sy);
	coordpoint(sx, sy, dotsize, shapecolor);
	coordpoint(ex, sy, dotsize, shapecolor);
	sy -= sh;

	VGfloat px[5] = { sx, sx + (sw / 4), sx + (sw / 2), sx + ((sw * 3) / 4), sx + sw };
	VGfloat py[5] = { sy, sy - sh, sy, sy - sh, sy };

	Polyline(px, py, 5);
	coordpoint(px[0], py[0], dotsize, shapecolor);
	coordpoint(px[1], py[1], dotsize, shapecolor);
	coordpoint(px[2], py[2], dotsize, shapecolor);
	coordpoint(px[3], py[3], dotsize, shapecolor);
	coordpoint(px[4], py[4], dotsize, shapecolor);
	sy -= sh * spacing;

	py[0] = sy;
	py[1] = sy - sh;
	py[2] = sy - (sh / 2);
	py[3] = py[1] - (sh / 4);
	py[4] = sy;
	Polygon(px, py, 5);
	sy -= (sh * spacing) + sh;

	Arc(sx + (sw / 2), sy, sw, sh, 0, 180);
	coordpoint(sx + (sw / 2), sy, dotsize, shapecolor);
	sy -= sh * spacing;

	VGfloat cy = sy + (sh / 2), ey = sy;
	Qbezier(sx, sy, cx, cy, ex, ey);
	coordpoint(sx, sy, dotsize, shapecolor);
	coordpoint(cx, cy, dotsize, shapecolor);
	coordpoint(ex, ey, dotsize, shapecolor);
	sy -= sh * spacing;

	ey = sy;
	cy = sy + sh;
	Cbezier(sx, sy, cx, cy, cx, sy, ex, ey);
	coordpoint(sx, sy, dotsize, shapecolor);
	coordpoint(cx, cy, dotsize, shapecolor);
	coordpoint(cx, sy, dotsize, shapecolor);
	coordpoint(ex, ey, dotsize, shapecolor);

	sy -= (sh * spacing * 1.5);
	Image(sx, sy, 100, 100, "starx.jpg");

	End();
}
Example #25
0
Painter& Painter::Stroke(double width, const Pointf& c, const RGBA& color1, double r, const RGBA& color2, int style)
{
	return Stroke(width, c, color1, c, r, color2, style);
}
Example #26
0
 LineChart(Dimensions margin = Dimensions(), double scale = 1,
           Stroke const & axis_stroke = Stroke(.5, Color::Purple))
     : axis_stroke(axis_stroke), margin(margin), scale(scale) { }
Example #27
0
 Polyline(Stroke const & stroke = Stroke()) : Shape(Color::Transparent, stroke) { }
Example #28
0
 Text(Point const & origin, std::string const & content, Fill const & fill = Fill(),
      Font const & font = Font(), Stroke const & stroke = Stroke())
     : Shape(fill, stroke), origin(origin), content(content), font(font) { }
Example #29
0
Painter& Painter::Stroke(double width, double x, double y, const RGBA& color1, double r, const RGBA& color2, int style)
{
	return Stroke(width, Pointf(x, y), color1, r, color2, style);
}
Example #30
0
 	AnimatedPath(Point const & start_point, Point const & end_point, int const & beginn, int const & duration,
 				Stroke const & stroke = Stroke())
 	                : Shape(Color::Transparent, stroke), start_point(start_point), end_point(end_point), beginn(beginn), duration(duration) { }