コード例 #1
0
ファイル: drawingTest.c プロジェクト: lfelipev/P1Charts
int main() {
	/**********************************
    * 1 - Criar papel e caneta cairo *
 	**********************************/
 	Drawer * cairo = DrawerInit(800, 600, 0, "result.pdf");

	/****************
 	* 2 - Desenhar *
 	****************/
 	Rectangle base = {0, //x
					  0, //y
					  800, //width
					  600, //height
					  0.0, // borderWidth
					  {1.0, 1.0, 1.0, 1.0},// Color Bg
					  {0.0, 0.0, 0.0, 0.0}// Color border (borderless)
	};
	DrawerDrawRectangle(cairo, base);

 	/*cairo_rectangle (cairo->context, 0, 0, 800, 600);
	cairo_set_source_rgb(cairo->context, 1.0, 1.0, 1.0);
	cairo_fill(cairo->context);*/

	Rectangle rect = {400-100, //x - altura/2
					  300-100, //y - largura/2
					  200, //width
					  200, //height
					  10.0, // borderWidth
					  {1.0, 1.0, 1.0, 1.0}, // Color Bg
					  {0.0, 0.0, 1.0, 1.0} // Color border
	};
	DrawerDrawRectangle(cairo, rect);

	/*cairo_rectangle (cairo->context, 400 - 50, 300 - 50, 100, 100);
	cairo_set_source_rgb(cairo->context, 1.0, 0.0, 0.0);
	cairo_fill_preserve(cairo->context);
 	cairo_set_source_rgba(cairo->context, 1.0, 1.0, 0.0, 1.0);
 	cairo_stroke(cairo->context);*/

 	/*cairo_set_source_rgb(cairo->context, 0.0, 0.0, 0.0);
	cairo_arc (cairo->context, 400, 300, 2, 0, 2* M_PI);
	cairo_fill(cairo->context);*/
	Arc arc = {400, //x
              300, //y
              0, //initAngle
              1*2*M_PI, //endAngle
              50,   //radius
              5.0, // borderWidth
              {1.0, 0.0, 1.0, 1.0}, // Color Bg
              {0.5, 1.0, 1.0, 1.0} // Color border
	};
    DrawerDrawArc(cairo, arc);

	/*************************
 	* 3 - Salvar em arquivo *
 	*************************/
	cairo_surface_write_to_png(cairo->surface, "test.png");

	/******************************
 	* 4 - Deletar caneta e papel *
 	******************************/
    DrawerDestroy(cairo);
	cairo = 0;
	return 0;
}
コード例 #2
0
ファイル: main.c プロジェクト: BrunoGeorgevich/P1Charts
int main(int argc, char *argv[]) {
	 		 if(argc == 2) {//Testando se os parâmetros de entradas são do tipo .json
	 		  char kind[8];
	 		  char  s2[] = {".json"};

	 		  type(argv[1],kind);

	 		  int result = compare(kind, s2);

	 		 if(result != 0) {
	 		  printf("Argumento passado não é do tipo .json!\n");	

	 		  return 0;
	  }
}
	 		 else if(argc > 2) {
	 		  printf("Mais argumentos do que o necessário!\nPor favor, insira somente um argumento do tipo .json!\n");

	 		  return 0;
}	
	 		 else if(argc < 2) {
	 		  printf("Menos argumentos do que o necessário!\nPor favor, insira um argumento do tipo .json!\n");

			  return 0;
}
			  Chart * chart = ChartCreate(argv[1]);
			  Drawer * cairo = DrawerInit(800, 600, chart->fileType, chart->filePath);
	
			  int num_elementos = chart->DatumSize;//Declarando o número de elementos do Datum
	
				 float aux[num_elementos];
				 int cont3;
 
				for(cont3 = 0; cont3 < num_elementos; cont3++) {
					aux[cont3] = chart->content[cont3]->percentage;
				}  			  


		Title title = {
		    
		    30.0,//Fonte do Título
		    chart->chartName,//String que provém o título
		    {0.0,0.0,0.0,1.0}//Cor do Título
};
		Rectangle base = {
		    
		    0, //x
		    0, //y
		    800, //width
		    600, //height
		    0.0, // borderWidth
		   {1.0, 1.0, 1.0, 1.0},// Color Bg
		   {0.0, 0.0, 0.0, 0.0}// Color border (borderless)
};
		
		DrawerDrawRectangle(cairo, base);
		Rectangle baseBg = {
		    
		    10, //x
		    10, //y
		    780, //width
		    580, //height
		    1.0, // borderWidth
		   {0.9,0.9, 0.9, 1.0},// Color Bg
		   {0.3, 0.3, 0.3, 1.0}// Color border (borderless)
};
		DrawerDrawRectangle(cairo, baseBg);
		DrawerDrawTextTitle(cairo, title, base);

		    if(strcmp(chart->chartType,"pizza") == 0) {//Se for Pizza
		     
		     pizza(cairo, chart, base);
	
		   }else if(strcmp(chart->chartType,"bars") == 0){//Se for Barras
		    
			  barra(cairo,chart, base, aux);
}
			  DrawerSave(cairo, chart->fileType, chart->filePath);
			  DrawerDestroy(cairo);

		return 0;
}