libsf3
Loading...
Searching...
No Matches
sf3_vector_graphic.h
Go to the documentation of this file.
1#ifndef __SF3_VECTOR_GRAPHIC__
2#define __SF3_VECTOR_GRAPHIC__
3#include "sf3_core.h"
4
6#define SF3_FORMAT_ID_VECTOR_GRAPHIC 0x09
7
28
32 float x;
34 float y;
35};
36
40 float w;
42 float h;
43};
44
48 float r;
50 float g;
52 float b;
54 float a;
55};
56
60 uint16_t count;
62 struct sf3_point edges[];
63};
64
66#define SF3_SKIP_OUTLINE(OUTLINE) ((OUTLINE).edges+(OUTLINE).count)
67
71 float x;
73 float y;
75 float w;
77 float h;
78};
79
83 struct sf3_color fill_color;
85 struct sf3_color outline_color;
88};
89
93 uint8_t type;
95 struct sf3_point point;
97 struct sf3_color color;
99 float font_size;
102};
103
106 uint8_t type;
108 struct sf3_shape_fill fill;
112 struct sf3_shape_outline outline;
113};
114
117 uint8_t type;
119 struct sf3_shape_fill fill;
122 struct sf3_shape_outline outline;
123};
124
127 uint8_t type;
129 struct sf3_shape_fill fill;
131 struct sf3_shape_bounds bounds;
132};
133
136 uint8_t type;
138 struct sf3_shape_fill fill;
140 struct sf3_shape_bounds bounds;
141};
142
145 uint8_t type;
147 struct sf3_color color;
151 struct sf3_shape_outline outline;
152};
153
157 uint8_t type;
160 float elements[6];
161};
162
168
176
181 struct sf3_identifier identifier;
183 uint32_t width;
185 uint32_t height;
187 uint32_t count;
189 struct sf3_vector_instruction instructions[];
190};
191
197 const char *base = (char*)instruction;
198 switch(instruction->type){
200 return (struct sf3_vector_instruction *)(base+sizeof(struct sf3_rectangle_instruction));
202 return (struct sf3_vector_instruction *)(base+sizeof(struct sf3_circle_instruction));
204 return (struct sf3_vector_instruction *)SF3_SKIP_OUTLINE(((struct sf3_line_instruction *)instruction)->outline);
206 return (struct sf3_vector_instruction *)SF3_SKIP_OUTLINE(((struct sf3_polygon_instruction *)instruction)->outline);
208 return (struct sf3_vector_instruction *)SF3_SKIP_OUTLINE(((struct sf3_curve_instruction *)instruction)->outline);
210 const struct sf3_text_instruction *i = (struct sf3_text_instruction *)instruction;
212 }
214 return (struct sf3_vector_instruction *)(base+sizeof(struct sf3_identity_instruction));
216 return (struct sf3_vector_instruction *)(base+sizeof(struct sf3_matrix_instruction));
217 default:
218 return 0;
219 }
220}
221
223SF3_INLINE const char *sf3_text_instruction_string(const struct sf3_text_instruction *instruction){
224 const sf3_str16 *string = (sf3_str16*)SF3_SKIP_STR(instruction->font);
225 return string->str;
226}
227
231 switch(type){
232 case SF3_INSTRUCTION_LINE: return "line";
233 case SF3_INSTRUCTION_RECTANGLE: return "rectangle";
234 case SF3_INSTRUCTION_CIRCLE: return "circle";
235 case SF3_INSTRUCTION_POLYGON: return "polygon";
236 case SF3_INSTRUCTION_CURVE: return "curve";
237 case SF3_INSTRUCTION_TEXT: return "text";
238 case SF3_INSTRUCTION_IDENTITY: return "identity";
239 case SF3_INSTRUCTION_MATRIX: return "matrix";
240 default: return "Unknown";
241 }
242}
243
245SF3_EXPORT size_t sf3_vector_graphic_size(const struct sf3_vector_graphic *vector_graphic){
246 const struct sf3_vector_instruction *inst = &vector_graphic->instructions[0];
247 for(uint32_t i=0; i<vector_graphic->count; ++i){
249 }
250 const void *start = (const void *)vector_graphic;
251 const void *end = (const void *)inst;
252 return (end-start);
253}
254#endif
#define SF3_INLINE
Definition sf3_core.h:16
#define SF3_EXPORT
Definition sf3_core.h:13
#define SF3_PACK
Definition sf3_core.h:9
#define SF3_SKIP_STR(STR)
Macro to retrieve a pointer past the variable size of an SF3 string.
Definition sf3_core.h:59
#define SF3_SKIP_STRP(STR)
Definition sf3_core.h:64
sf3_vector_instruction_type
@ SF3_INSTRUCTION_LINE
The instruction is a sf3_line_instruction.
@ SF3_INSTRUCTION_TEXT
The instruction is a sf3_text_instruction.
@ SF3_INSTRUCTION_POLYGON
The instruction is a sf3_polygon_instruction.
@ SF3_INSTRUCTION_CIRCLE
The instruction is a sf3_circle_instruction.
@ SF3_INSTRUCTION_MATRIX
The instruction is a sf3_matrix_instruction.
@ SF3_INSTRUCTION_CURVE
The instruction is a sf3_curve_instruction.
@ SF3_INSTRUCTION_IDENTITY
The instruction is a sf3_identity_instruction.
@ SF3_INSTRUCTION_RECTANGLE
The instruction is a sf3_rectangle_instruction.
#define SF3_SKIP_OUTLINE(OUTLINE)
Macro to obtain a pointer past the outline structure.
SF3_INLINE const struct sf3_vector_instruction * sf3_vector_graphic_next_instruction(const struct sf3_vector_instruction *instruction)
SF3_EXPORT size_t sf3_vector_graphic_size(const struct sf3_vector_graphic *vector_graphic)
Computes the size of the vector graphic file in bytes.
SF3_INLINE const char * sf3_text_instruction_string(const struct sf3_text_instruction *instruction)
Returns the string to draw of a text instruction.
An instruction to draw a circle.
Description of a colour of a shape.
float b
The blue channel, in the range of [0,1].
float g
The green channel, in the range of [0,1].
float r
The red channel, in the range of [0,1].
float a
The alpha channel, in the range of [0,1].
An instruction to draw a Bezier curve.
The basic header structure of every SF3 file.
Definition sf3_core.h:70
An instruction to draw a segmented line.
float thickness
The thickness of the stroke of the line.
Description of a point on the canvas.
float y
The Y coordinate.
float x
The X coordinate.
An instruction to draw a closed polygon.
An instruction to draw a rectangle.
Description of a shape's bounds or extent on the canvas.
float h
The height in Y of the shape.
float x
The X coordinate of the lower left corner.
float y
The Y coordinate of the lower left corner.
float w
The width in X of the shape.
Description of the fill parameters of a shape.
float outline_thickness
The thickness of the outline stroke of the shape.
Description of a shape's outline.
uint16_t count
The number of edges stored in the outline.
Description of an extent on the canvas.
float w
The width in X.
float h
The height in Y.
char str[]
Definition sf3_core.h:39
sf3_str16 font
The name of the font-family to use for the text.
float font_size
The size of the font in em units.
uint32_t width
The width of the canvas in pixels.
struct sf3_vector_instruction instructions[]
The instructions to execute in order to draw the graphic.
uint32_t count
The number of vector instructions stored.
uint32_t height
The height of the canvas in pixels.