libkate 0.4.1

- Main Page
- Related Pages
- Modules
- Data Structures
- Files
- Examples

- File List
- Globals

kate.h
Go to the documentation of this file.
1 /* Copyright (C) 2008, 2009 Vincent Penquerc'h.
2 This file is part of the Kate codec library.
3 Written by Vincent Penquerc'h.
4
5 Use, distribution and reproduction of this library is governed
6 by a BSD style source license included with this source in the
7 file 'COPYING'. Please read these terms before distributing. */
8
9
10 #ifndef KATE_kate_h_GUARD
11 #define KATE_kate_h_GUARD
12
17 #include "kate/kate_config.h"
18
21 #define KATE_VERSION_MAJOR 0
22 #define KATE_VERSION_MINOR 4
23 #define KATE_VERSION_PATCH 1
28 #define KATE_BITSTREAM_VERSION_MAJOR 0
29 #define KATE_BITSTREAM_VERSION_MINOR 7
33 typedef enum {
34 kate_utf8
35 } kate_text_encoding;
36
38 typedef enum {
39 kate_markup_none,
40 kate_markup_simple
41 } kate_markup_type;
42
44 typedef enum {
45 kate_pixel,
46 kate_percentage,
47 kate_millionths
48 } kate_space_metric;
49
50 struct kate_meta;
51 typedef struct kate_meta kate_meta;
52
54 typedef struct kate_region {
55 kate_space_metric metric;
56 int x;
57 int y;
58 int w;
59 int h;
60 int style;
61 unsigned int clip:1;
62 unsigned int pad0:31;
63 kate_meta *meta;
64 kate_uintptr_t pad1[5];
65 } kate_region;
66
68 typedef struct kate_color {
69 unsigned char r;
70 unsigned char g;
71 unsigned char b;
72 unsigned char a;
73 } kate_color;
74
76 typedef enum {
77 kate_wrap_word,
78 kate_wrap_none
79 } kate_wrap_mode;
80
82 typedef struct kate_style {
83 kate_float halign;
84 kate_float valign;
86 kate_color text_color;
87 kate_color background_color;
88 kate_color draw_color;
90 kate_space_metric font_metric;
91 kate_float font_width;
92 kate_float font_height;
94 kate_space_metric margin_metric;
95 kate_float left_margin;
96 kate_float top_margin;
97 kate_float right_margin;
98 kate_float bottom_margin;
100 unsigned int bold:1;
101 unsigned int italics:1;
102 unsigned int underline:1;
103 unsigned int strike:1;
104 unsigned int justify:1;
105 unsigned int wrap_mode:2;
106 unsigned int pad0:25;
107
108 kate_const char *font;
110 kate_meta *meta;
111
112 kate_uintptr_t pad1[8];
113 } kate_style;
114
116 typedef enum kate_curve_type {
117 kate_curve_none,
118 kate_curve_static,
119 kate_curve_linear,
120 kate_curve_catmull_rom_spline,
121 kate_curve_bezier_cubic_spline,
122 kate_curve_bspline
123 } kate_curve_type;
124
126 typedef struct kate_curve {
127 kate_curve_type type;
128 size_t npts;
129 kate_float *pts;
130 kate_uintptr_t pad[5];
131 } kate_curve;
132
134 typedef enum kate_motion_mapping {
135 /* these can be used for a x/y position mapping */
136 kate_motion_mapping_none,
137 kate_motion_mapping_frame,
138 kate_motion_mapping_window,
139 kate_motion_mapping_region,
140 kate_motion_mapping_event_duration,
141 kate_motion_mapping_bitmap_size,
143 #if 0
144 text is useful, find a way to readd it easily
145 kate_motion_mapping_text,
146 #endif
147
148 /* more mapping may be added in future versions */
149
150 kate_motion_mapping_user=128
151 } kate_motion_mapping;
152
154 typedef enum kate_motion_semantics {
155 kate_motion_semantics_time,
156 kate_motion_semantics_z,
157 kate_motion_semantics_region_position,
158 kate_motion_semantics_region_size,
159 kate_motion_semantics_text_alignment_int,
160 kate_motion_semantics_text_alignment_ext,
161 kate_motion_semantics_text_position,
162 kate_motion_semantics_text_size,
163 kate_motion_semantics_marker1_position,
164 kate_motion_semantics_marker2_position,
165 kate_motion_semantics_marker3_position,
166 kate_motion_semantics_marker4_position,
167 kate_motion_semantics_glyph_pointer_1,
168 kate_motion_semantics_glyph_pointer_2,
169 kate_motion_semantics_glyph_pointer_3,
170 kate_motion_semantics_glyph_pointer_4,
171 kate_motion_semantics_text_color_rg,
172 kate_motion_semantics_text_color_ba,
173 kate_motion_semantics_background_color_rg,
174 kate_motion_semantics_background_color_ba,
175 kate_motion_semantics_draw_color_rg,
176 kate_motion_semantics_draw_color_ba,
177 kate_motion_semantics_style_morph,
178 kate_motion_semantics_text_path,
179 kate_motion_semantics_text_path_section,
180 kate_motion_semantics_draw,
181 kate_motion_semantics_text_visible_section,
182 kate_motion_semantics_horizontal_margins,
183 kate_motion_semantics_vertical_margins,
184 kate_motion_semantics_bitmap_position,
185 kate_motion_semantics_bitmap_size,
186 kate_motion_semantics_marker1_bitmap,
187 kate_motion_semantics_marker2_bitmap,
188 kate_motion_semantics_marker3_bitmap,
189 kate_motion_semantics_marker4_bitmap,
190 kate_motion_semantics_glyph_pointer_1_bitmap,
191 kate_motion_semantics_glyph_pointer_2_bitmap,
192 kate_motion_semantics_glyph_pointer_3_bitmap,
193 kate_motion_semantics_glyph_pointer_4_bitmap,
194 kate_motion_semantics_draw_width,
196 /* more semantics may be added in future versions */
197
198 kate_motion_semantics_user = 128
199 } kate_motion_semantics;
200
202 typedef struct kate_motion {
203 size_t ncurves;
204 kate_curve **curves;
205 kate_float *durations;
206 kate_motion_mapping x_mapping;
207 kate_motion_mapping y_mapping;
208 kate_motion_semantics semantics;
209 unsigned int periodic:1;
210 unsigned int pad0:31;
211 kate_meta *meta;
212 kate_uintptr_t pad1[4];
213 } kate_motion;
214
216 typedef enum kate_text_directionality {
217 kate_l2r_t2b,
218 kate_r2l_t2b,
219 kate_t2b_r2l,
220 kate_t2b_l2r
221 } kate_text_directionality;
222
224 typedef struct kate_palette {
225 size_t ncolors;
226 kate_color *colors;
227 kate_meta *meta;
228 kate_uintptr_t pad[1];
229 } kate_palette;
230
232 typedef enum kate_bitmap_type {
233 kate_bitmap_type_paletted,
234 kate_bitmap_type_png
235 } kate_bitmap_type;
236
238 typedef struct kate_bitmap {
239 size_t width;
240 size_t height;
241 unsigned char bpp;
242 kate_bitmap_type type;
243 unsigned char pad0[1];
244 unsigned char internal;
245 int palette;
246 unsigned char *pixels;
247 size_t size;
248 int x_offset;
249 int y_offset;
250 kate_meta *meta;
251 kate_uintptr_t pad1[14];
252 } kate_bitmap;
253
255 typedef struct kate_font_range {
256 int first_code_point;
257 int last_code_point;
258 int first_bitmap;
259 kate_uintptr_t pad[5];
260 } kate_font_range;
261
263 typedef struct kate_font_mapping {
264 size_t nranges;
265 kate_font_range **ranges;
266 kate_uintptr_t pad[6];
267 } kate_font_mapping;
268
274 typedef struct kate_info {
275 unsigned char bitstream_version_major;
276 unsigned char bitstream_version_minor;
277 unsigned char pad0[2];
278
279 kate_text_encoding text_encoding;
280 kate_text_directionality text_directionality;
282 unsigned char num_headers;
283 unsigned char granule_shift;
284 unsigned char pad1[2];
285
286 kate_uint32_t gps_numerator;
287 kate_uint32_t gps_denominator;
289 kate_const char *language;
291 kate_const char *category;
293 size_t nregions;
294 kate_const kate_region *kate_const *regions;
296 size_t nstyles;
297 kate_const kate_style *kate_const *styles;
299 size_t ncurves;
300 kate_const kate_curve *kate_const *curves;
302 size_t nmotions;
303 kate_const kate_motion *kate_const *motions;
305 size_t npalettes;
306 kate_const kate_palette *kate_const *palettes;
308 size_t nbitmaps;
309 kate_const kate_bitmap *kate_const *bitmaps;
311 size_t nfont_ranges;
312 kate_const kate_font_range *kate_const *font_ranges;
314 size_t nfont_mappings;
315 kate_const kate_font_mapping *kate_const *font_mappings;
317 kate_markup_type text_markup_type;
319 size_t original_canvas_width;
320 size_t original_canvas_height;
322 kate_uintptr_t pad2[11];
323
324 /* internal */
325 int remove_markup;
326 int no_limits;
327 int probe;
328
329 kate_uintptr_t pad3[13];
330 } kate_info;
331
332 struct kate_encode_state; /* internal */
333 struct kate_decode_state; /* internal */
334
336 typedef struct kate_state {
337 kate_const kate_info *ki;
339 /* internal */
340 kate_const struct kate_encode_state *kes;
341 kate_const struct kate_decode_state *kds;
342
343 kate_uintptr_t pad[5];
344 } kate_state;
345
347 typedef struct kate_comment {
348 char **user_comments;
349 int *comment_lengths;
350 int comments;
351 char *vendor;
352 } kate_comment;
353
358 typedef struct kate_event {
359 kate_int64_t start;
360 kate_int64_t duration;
361 kate_int64_t backlink;
363 kate_float start_time;
364 kate_float end_time;
366 kate_int32_t id;
368 kate_text_encoding text_encoding;
369 kate_text_directionality text_directionality;
370 kate_const char *language;
371 kate_const char *text;
372 size_t len;
373 size_t len0;
375 size_t nmotions;
376 kate_const kate_motion *kate_const *motions;
378 kate_const kate_region *region;
379 kate_const kate_style *style;
380 kate_const kate_style *secondary_style;
381 kate_const kate_font_mapping *font_mapping;
382 kate_const kate_palette *palette;
383 kate_const kate_bitmap *bitmap;
385 kate_markup_type text_markup_type;
387 size_t nbitmaps;
388 kate_const kate_bitmap *kate_const *bitmaps;
390 kate_meta *meta;
391
392 kate_uintptr_t pad0[5];
393
394 /* internal */
395 const kate_info *ki;
396 size_t trackers;
397
398 kate_uintptr_t pad1[10];
399 } kate_event;
400
401 struct kate_tracker_internal; /* internal */
402
404 typedef struct kate_tracker {
405 const kate_info *ki;
406 kate_const kate_event *event;
407 kate_float t;
409 struct {
410 unsigned int region:1;
411 unsigned int text_alignment_int:1;
412 unsigned int text_alignment_ext:1;
413 unsigned int text_pos:1;
414 unsigned int text_size:1;
415 unsigned int marker_pos:4;
416 unsigned int text_color:1;
417 unsigned int background_color:1;
418 unsigned int draw_color:1;
419 unsigned int glyph_pointer:4;
420 unsigned int path:1;
421 unsigned int draw:1;
422 unsigned int visible_section:1;
423 unsigned int z:1;
424 unsigned int hmargins:1;
425 unsigned int vmargins:1;
426 unsigned int bitmap_pos:1;
427 unsigned int bitmap_size:1;
428 unsigned int marker_bitmap:4;
429 unsigned int glyph_pointer_bitmap:4;
430 unsigned int draw_width:1;
431 /* 33 bits */
432 unsigned int pad0:31;
433 /* 64 bits */
434 } has;
436 int window_w;
437 int window_h;
438 int frame_x;
439 int frame_y;
440 int frame_w;
441 int frame_h;
443 /* has.region */
444 kate_float region_x;
445 kate_float region_y;
446 kate_float region_w;
447 kate_float region_h;
449 /* has.text_alignment (int/ext) */
450 kate_float text_halign;
451 kate_float text_valign;
453 /* has.text_pos */
454 kate_float text_x;
455 kate_float text_y;
457 /* has.text_size */
458 kate_float text_size_x;
459 kate_float text_size_y;
461 /* has.marker_pos&(1<<n) */
462 kate_float marker_x[4];
463 kate_float marker_y[4];
465 /* has.text_color */
466 kate_color text_color;
468 /* has.background_color */
469 kate_color background_color;
471 /* has.draw_color */
472 kate_color draw_color;
474 /* has.glyph_pointer&(1<<n) */
475 kate_float glyph_pointer[4];
476 kate_float glyph_height[4];
478 /* has.path */
479 kate_float path_start;
480 kate_float path_end;
482 /* has.draw */
483 kate_float draw_x;
484 kate_float draw_y;
486 /* has.visible_section */
487 kate_float visible_x;
488 kate_float visible_y;
490 /* has.z */
491 kate_float z;
493 /* has.hmargins */
494 kate_float left_margin;
495 kate_float right_margin;
497 /* has.vmargins */
498 kate_float top_margin;
499 kate_float bottom_margin;
501 /* has.bitmap_pos */
502 kate_float bitmap_x;
503 kate_float bitmap_y;
505 /* has.bitmap_size */
506 kate_float bitmap_size_x;
507 kate_float bitmap_size_y;
509 /* has.marker_bitmap&(1<<n) */
510 const kate_bitmap *marker_bitmap[4];
512 /* has.glyph_pointer_bitmap&(1<<n) */
513 const kate_bitmap *glyph_pointer_bitmap[4];
515 /* has.draw_width */
516 kate_float draw_width;
518 /* internal */
519 struct kate_tracker_internal *internal;
520
521 kate_uintptr_t pad[19];
522
523 } kate_tracker;
524
526 typedef struct kate_packet {
527 size_t nbytes;
528 void *data;
529 } kate_packet;
530
531 #ifdef __cplusplus
532 extern "C" {
533 #endif
534
536 extern int kate_get_version(void);
537 extern const char *kate_get_version_string(void);
538 extern int kate_get_bitstream_version(void);
539 extern const char *kate_get_bitstream_version_string(void);
540
542 extern int kate_info_init(kate_info *ki);
543 extern int kate_info_set_granule_encoding(kate_info *ki,kate_float resolution,kate_float max_length,kate_float max_event_lifetime);
544 extern int kate_info_set_language(kate_info *ki,const char *language);
545 extern int kate_info_set_text_directionality(kate_info *ki,kate_text_directionality text_directionality);
546 extern int kate_info_set_markup_type(kate_info *ki,kate_markup_type text_markup_type);
547 extern int kate_info_set_category(kate_info *ki,const char *category);
548 extern int kate_info_set_original_canvas_size(kate_info *ki,size_t width,size_t height);
549 extern int kate_info_add_region(kate_info *ki,kate_region *kr);
550 extern int kate_info_add_style(kate_info *ki,kate_style *ks);
551 extern int kate_info_add_curve(kate_info *ki,kate_curve *kc);
552 extern int kate_info_add_motion(kate_info *ki,kate_motion *km);
553 extern int kate_info_add_palette(kate_info *ki,kate_palette *kp);
554 extern int kate_info_add_bitmap(kate_info *ki,kate_bitmap *kb);
555 extern int kate_info_add_font_range(kate_info *ki,kate_font_range *kfr);
556 extern int kate_info_add_font_mapping(kate_info *ki,kate_font_mapping *kfm);
557 extern int kate_info_matches_language(const kate_info *ki,const char *language);
558 extern int kate_info_remove_markup(kate_info *ki,int flag);
559 extern int kate_info_no_limits(kate_info *ki,int flag);
560 extern int kate_info_clear(kate_info *ki);
561
563 extern int kate_granule_shift(const kate_info *ki);
564 extern int kate_granule_split_time(const kate_info *ki,kate_int64_t granulepos,kate_float *base,kate_float *offset);
565 extern kate_float kate_granule_time(const kate_info *ki,kate_int64_t granulepos);
566 extern kate_int64_t kate_duration_granule(const kate_info *ki,kate_float duration);
567 extern kate_float kate_granule_duration(const kate_info *ki,kate_int64_t duration);
568
570 extern int kate_clear(kate_state *k);
571 extern int kate_motion_get_point(const kate_motion *km,kate_float duration,kate_float t,kate_float *x,kate_float *y);
572 extern int kate_curve_get_point(const kate_curve *kc,kate_float t,kate_float *x,kate_float *y);
573 extern int kate_region_init(kate_region *kr);
574 extern int kate_style_init(kate_style *ks);
575 extern int kate_palette_init(kate_palette *kp);
576 extern int kate_bitmap_init(kate_bitmap *kb);
577 extern int kate_bitmap_init_new(kate_bitmap *kb);
578 extern int kate_curve_init(kate_curve *kc);
579 extern int kate_motion_init(kate_motion *km);
580
582 extern int kate_text_get_character(kate_text_encoding text_encoding,const char ** const text,size_t *len0);
583 extern int kate_text_set_character(kate_text_encoding text_encoding,int c,char ** const text,size_t *len0);
584 extern int kate_text_remove_markup(kate_text_encoding text_encoding,char *text,size_t *len0);
585 extern int kate_text_validate(kate_text_encoding text_encoding,const char *text,size_t len0);
586
588 extern int kate_comment_init(kate_comment *kc);
589 extern int kate_comment_clear(kate_comment *kc);
590 extern int kate_comment_add(kate_comment *kc,const char *comment);
591 extern int kate_comment_add_length(kate_comment *kc,const char *comment,size_t len);
592 extern int kate_comment_add_tag(kate_comment *kc,const char *tag,const char *value);
593 extern const char *kate_comment_query(const kate_comment *kc,const char *tag,int count);
594 extern int kate_comment_query_count(const kate_comment *kc,const char *tag);
595
597 extern int kate_encode_init(kate_state *k,kate_info *ki);
598 extern int kate_encode_headers(kate_state *k,kate_comment *kc,kate_packet *kp);
599 extern int kate_encode_text(kate_state *k,kate_float start_time,kate_float stop_time,const char *text,size_t sz,kate_packet *kp); /* text is not null terminated */
600 extern int kate_encode_text_raw_times(kate_state *k,kate_int64_t start_time,kate_int64_t stop_time,const char *text,size_t sz,kate_packet *kp); /* text is not null terminated */
601 extern int kate_encode_keepalive(kate_state *k,kate_float t,kate_packet *kp);
602 extern int kate_encode_keepalive_raw_times(kate_state *k,kate_int64_t t,kate_packet *kp);
603 extern int kate_encode_repeat(kate_state *k,kate_float t,kate_float threshold,kate_packet *kp);
604 extern int kate_encode_repeat_raw_times(kate_state *k,kate_int64_t t,kate_int64_t threshold,kate_packet *kp);
605 extern int kate_encode_finish(kate_state *k,kate_float t,kate_packet *kp); /* t may be negative to use the end granule of the last event */
606 extern int kate_encode_finish_raw_times(kate_state *k,kate_int64_t t,kate_packet *kp); /* t may be negative to use the end granule of the last event */
607 extern int kate_encode_set_id(kate_state *k,kate_int32_t id);
608 extern int kate_encode_set_language(kate_state *k,const char *language); /* language can be NULL */
609 extern int kate_encode_set_text_encoding(kate_state *k,kate_text_encoding text_encoding);
610 extern int kate_encode_set_text_directionality(kate_state *k,kate_text_directionality text_directionality);
611 extern int kate_encode_set_region_index(kate_state *k,size_t region);
612 extern int kate_encode_set_region(kate_state *k,const kate_region *kr);
613 extern int kate_encode_set_style_index(kate_state *k,size_t style);
614 extern int kate_encode_set_style(kate_state *k,const kate_style *ks);
615 extern int kate_encode_set_secondary_style_index(kate_state *k,size_t style);
616 extern int kate_encode_set_secondary_style(kate_state *k,const kate_style *ks);
617 extern int kate_encode_set_font_mapping_index(kate_state *k,size_t font_mapping);
618 extern int kate_encode_add_motion(kate_state *k,kate_motion *km,int destroy);
619 extern int kate_encode_add_motion_index(kate_state *k,size_t motion);
620 extern int kate_encode_set_palette_index(kate_state *k,size_t palette);
621 extern int kate_encode_set_palette(kate_state *k,const kate_palette *kp);
622 extern int kate_encode_set_bitmap_index(kate_state *k,size_t bitmap);
623 extern int kate_encode_set_bitmap(kate_state *k,const kate_bitmap *kb);
624 extern int kate_encode_add_bitmap(kate_state *k,const kate_bitmap *kb);
625 extern int kate_encode_add_bitmap_index(kate_state *k,size_t bitmap);
626 extern int kate_encode_set_markup_type(kate_state *k,int markup_type);
627 extern int kate_encode_merge_meta(kate_state *k,kate_meta *meta);
628 extern int kate_encode_add_meta(kate_state *k,const kate_meta *meta);
629 extern kate_int64_t kate_encode_get_granule(const kate_state *k);
630
632 extern int kate_decode_is_idheader(const kate_packet *kp);
633 extern int kate_decode_init(kate_state *k,kate_info *ki);
634 extern int kate_decode_headerin(kate_info *ki,kate_comment *kc,kate_packet *kp);
635 extern int kate_decode_packetin(kate_state *k,kate_packet *kp);
636 extern int kate_decode_eventout(kate_state *k,kate_const kate_event **ev); /* event can be NULL */
637 extern int kate_decode_seek(kate_state *k);
638
640 extern int kate_tracker_init(kate_tracker *kin,const kate_info *ki,kate_const kate_event *ev);
641 extern int kate_tracker_clear(kate_tracker *kin);
642 extern int kate_tracker_update(kate_tracker *kin,kate_float t,int window_w,int window_h,int frame_x,int frame_y,int frame_w,int frame_h);
643 extern int kate_tracker_morph_styles(kate_style *style,kate_float t,const kate_style *from,const kate_style *to);
644 extern int kate_tracker_get_text_path_position(kate_tracker *kin,size_t glyph,int *x,int *y);
645 extern int kate_tracker_update_property_at_duration(const kate_tracker *kin,kate_float duration,kate_float t,kate_motion_semantics semantics,kate_float *x,kate_float *y);
646 extern int kate_tracker_remap(const kate_tracker *kin,kate_motion_mapping x_mapping,kate_motion_mapping y_mapping,kate_float *x,kate_float *y);
647
649 extern int kate_font_get_index_from_code_point(const kate_font_mapping *kfm,int c);
650
652 extern int kate_high_decode_init(kate_state *k);
653 extern int kate_high_decode_packetin(kate_state *k,kate_packet *kp,kate_const kate_event **ev);
654 extern int kate_high_decode_clear(kate_state *k);
655 extern const kate_comment *kate_high_decode_get_comments(kate_state *k);
656
658 extern int kate_packet_wrap(kate_packet *kp,size_t nbytes,const void *data);
659 extern int kate_packet_init(kate_packet *kp,size_t nbytes,const void *data);
660 extern int kate_packet_clear(kate_packet *kp);
661
663 extern int kate_meta_create(kate_meta **km);
664 extern int kate_meta_destroy(kate_meta *km);
665 extern int kate_meta_add(kate_meta *km,const char *tag,const char *value,size_t len);
666 extern int kate_meta_add_string(kate_meta *km,const char *tag,const char *value);
667 extern int kate_meta_query_tag_count(const kate_meta *km,const char *tag);
668 extern int kate_meta_query_tag(const kate_meta *km,const char *tag,unsigned int idx,const char **value,size_t *len);
669 extern int kate_meta_remove_tag(kate_meta *km,const char *tag,unsigned int idx);
670 extern int kate_meta_query_count(const kate_meta *km);
671 extern int kate_meta_query(const kate_meta *km,unsigned int idx,const char **tag,const char **value,size_t *len);
672 extern int kate_meta_remove(kate_meta *km,unsigned int idx);
673 extern int kate_meta_merge(kate_meta *km,kate_meta *km2);
674
675 #ifdef __cplusplus
676 }
677 #endif
678
681 #define KATE_E_NOT_FOUND (-1)
682 #define KATE_E_INVALID_PARAMETER (-2)
683 #define KATE_E_OUT_OF_MEMORY (-3)
684 #define KATE_E_BAD_GRANULE (-4)
685 #define KATE_E_INIT (-5)
686 #define KATE_E_BAD_PACKET (-6)
687 #define KATE_E_TEXT (-7)
688 #define KATE_E_LIMIT (-8)
689 #define KATE_E_VERSION (-9)
690 #define KATE_E_NOT_KATE (-10)
691 #define KATE_E_BAD_TAG (-11)
692 #define KATE_E_IMPL (-12)
695 #endif
696