Advantages of using SVG over other image formats (like JPEG and GIF) are:
- SVG images can be created and edited with any text editor
- SVG images can be searched, indexed, scripted, and compressed
- SVG images are scalable
- SVG images can be printed with high quality at any resolution
- SVG images are zoomable (and the image can be zoomed without degradation)
- SVG is an open standard
- SVG files are pure XML
NOTE: Before running the following program, plz make sure that you have already installed cairo library. (sudo apt-get install libcairo2-dev)
To Know How to create PDF files in C programming Click HERE.
// File Name: SVGCreate.c
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <cairo/cairo.h>
#include <cairo/cairo-svg.h>
void main() {
// Declaring Variables
cairo_t *cr;
cairo_surface_t *surface;
double x=25.6, y=128.0;
double x1=102.4, y1=230.4, x2=153.6, y2=25.6, x3=230.4, y3=128.0;
surface = (cairo_surface_t *)cairo_svg_surface_create("R.E.N.I.svg", 250.0, 250.0);
cr = cairo_create(surface);
// Creating required graphics in SVG file
cairo_move_to (cr, x, y);
cairo_curve_to (cr, x1, y1, x2, y2, x3, y3);
cairo_set_line_width (cr, 10.0);
cairo_stroke (cr);
cairo_set_source_rgba (cr, 1, 0.2, 0.2, 0.6);
cairo_set_line_width (cr, 6.0);
cairo_move_to (cr,x,y); cairo_line_to (cr,x1,y1);
cairo_move_to (cr,x2,y2); cairo_line_to (cr,x3,y3);
cairo_stroke (cr);
// Typing text in SVG file
cairo_set_font_size (cr, 15);
cairo_select_font_face (cr, "Georgia", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_BOLD);
cairo_set_source_rgb (cr, 0, 0, 0);
cairo_move_to(cr, 140, 150);
cairo_show_text(cr, "R.E.N.I");
// Destroying context and surface
cairo_destroy (cr);
cairo_surface_destroy (surface);
}
To Run: gcc -lcairo SVGCreate.c
./a.out
Out Put: It will create R.E.N.I.svg file in your current directory
No comments:
Post a Comment