Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <jansson.h>
- #include <cairo/cairo.h>
- #include <math.h>
- #include <string.h>
- #include "projeto.h"
- int main(){
- json_t *root;
- json_error_t error;
- root = json_load_file("test.json", 0, &error);
- if(!root){
- fprintf(stderr, "error: on line %d: %s\n", error.line, error.text);
- return 1;
- }
- json_t * jfilename = json_object_get(root, "file_name"); //Obtendo o nome do arquivo
- const char * filename = json_string_value(jfilename);
- json_t * jtype = json_object_get(root, "file_type"); //Obtendo o tipo de arquivo
- const char * filetype = json_string_value(jtype);
- char * fn = (char *)malloc (strlen (filename) + strlen (filetype) + 2);
- sprintf(fn, "%s.%s", filename, filetype);
- printf("Filename: %s\n", fn);
- json_t * jwidth = json_object_get(root, "width"); //Obtendo a largura
- int width = json_number_value(jwidth);
- printf("Width: %d\n", width);
- json_t * jheight = json_object_get(root, "height"); //Obtendo a altura
- int height = json_number_value(jheight);
- printf("Height: %d\n", height);
- cairo_surface_t *surface;
- cairo_t *cr;
- surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, width, height);
- cr = cairo_create(surface);
- json_t * jcontent = json_object_get(root, "content"); //Obtendo as definições
- for(int i = 0; i < json_array_size(jcontent); ++i){
- json_t * jdados = json_array_get(jcontent, i);
- int type = json_number_value(json_object_get(jdados, "type")); //Identificando a saida
- switch(type){
- case 0:{
- int x = json_number_value(json_object_get(jdados, "x"));
- int y = json_number_value(json_object_get(jdados, "y"));
- int width = json_number_value(json_object_get(jdados, "width"));
- int height = json_number_value(json_object_get(jdados, "height"));
- int linewidth = json_number_value(json_object_get(jdados, "line_width"));
- json_t * bgcolor = json_object_get(jdados, "background_color");
- float red = json_number_value(json_object_get(bgcolor, "r"));
- float green = json_number_value(json_object_get(bgcolor, "g"));
- float blue = json_number_value(json_object_get(bgcolor, "b"));
- //float alpha = json_number_value(json_object_get(bgcolor, "a"));
- json_t * stcolor = json_object_get(jdados, "stroke_color");
- float sred = json_number_value(json_object_get(stcolor, "r"));
- float sgreen = json_number_value(json_object_get(stcolor, "g"));
- float sblue = json_number_value(json_object_get(stcolor, "b"));
- //float salpha = json_number_value(json_object_get(stcolor, "a"));
- makeRectangle(cr, x, y, width, height, linewidth, red, green, blue, sred, sgreen, sblue);
- break;
- }
- default:
- break;
- }
- }
- cairo_surface_write_to_png(surface, fn);
- cairo_destroy(cr);
- cairo_surface_destroy(surface);
- free (fn);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement