include/kate/kate.h

Go to the documentation of this file.
00001 /* Copyright (C) 2008 Vincent Penquerc'h.
00002    This file is part of the Kate codec library.
00003    Written by Vincent Penquerc'h.
00004 
00005    Use, distribution and reproduction of this library is governed
00006    by a BSD style source license included with this source in the
00007    file 'COPYING'. Please read these terms before distributing. */
00008 
00009 
00010 #ifndef _KATE_CODEC_H_
00011 #define _KATE_CODEC_H_
00012 
00017 #include <stddef.h>
00018 #include <stdint.h>
00019 
00020 #ifdef KATE_INTERNAL
00021 #define kate_const
00022 #else
00023 #define kate_const const
00024 #endif
00025 
00026 typedef int32_t kate_int32_t;
00027 typedef int64_t kate_int64_t;
00028 typedef float kate_float;
00029 
00032 #define KATE_VERSION_MAJOR 0             
00033 #define KATE_VERSION_MINOR 1             
00034 #define KATE_VERSION_PATCH 2             
00039 #define KATE_BITSTREAM_VERSION_MAJOR 0   
00040 #define KATE_BITSTREAM_VERSION_MINOR 2   
00043 #ifndef kate_malloc
00044 #define kate_malloc malloc
00045 #endif
00046 #ifndef kate_realloc
00047 #define kate_realloc realloc
00048 #endif
00049 #ifndef kate_free
00050 #define kate_free free
00051 #endif
00052 
00054 typedef enum {
00055   kate_utf8                      
00056 } kate_text_encoding;
00057 
00059 typedef enum {
00060   kate_markup_none,              
00061   kate_markup_simple             
00062 } kate_markup_type;
00063 
00065 typedef enum {
00066   kate_pixel,                    
00067   kate_percentage                
00068 } kate_space_metric;
00069 
00071 typedef struct kate_region {
00072   kate_space_metric metric;      
00073   int x;                         
00074   int y;                         
00075   int w;                         
00076   int h;                         
00077   int style;                     
00078   uint32_t clip:1;               
00079   uint32_t pad0:31;
00080   uintptr_t pad1[6];
00081 } kate_region;
00082 
00084 typedef struct kate_color {
00085   unsigned char r;               
00086   unsigned char g;               
00087   unsigned char b;               
00088   unsigned char a;               
00089 } kate_color;
00090 
00092 typedef struct kate_style {
00093   kate_float halign;                 
00094   kate_float valign;                 
00096   kate_color text_color;             
00097   kate_color background_color;       
00098   kate_color draw_color;             
00100   kate_space_metric font_metric;     
00101   kate_float font_width;             
00102   kate_float font_height;            
00104   kate_space_metric margin_metric;   
00105   kate_float left_margin;            
00106   kate_float top_margin;             
00107   kate_float right_margin;           
00108   kate_float bottom_margin;          
00110   uint32_t bold:1;                   
00111   uint32_t italics:1;                
00112   uint32_t underline:1;              
00113   uint32_t strike:1;                 
00114   uint32_t justify:1;                
00115   uint32_t pad0:27;
00116 
00117   kate_const char *font;             
00119   uintptr_t pad1[9];
00120 } kate_style;
00121 
00123 typedef enum kate_curve_type {
00124   kate_curve_none,                   
00125   kate_curve_static,                 
00126   kate_curve_linear,                 
00127   kate_curve_catmull_rom_spline,     
00128   kate_curve_bezier_cubic_spline,    
00129   kate_curve_bspline                 
00130 } kate_curve_type;
00131 
00133 typedef struct kate_curve {
00134   kate_curve_type type;              
00135   size_t npts;                       
00136   kate_float *pts;                   
00137   uintptr_t pad[5];
00138 } kate_curve;
00139 
00141 typedef enum kate_motion_mapping {
00142   /* these can be used for a x/y position mapping */
00143   kate_motion_mapping_none,                  
00144   kate_motion_mapping_frame,                 
00145   kate_motion_mapping_window,                
00146   kate_motion_mapping_region,                
00147   kate_motion_mapping_event_duration,        
00148   kate_motion_mapping_bitmap_size,           
00150 #if 0
00151   text is useful, find a way to readd it easily
00152   kate_motion_mapping_text,                  
00153 #endif
00154 
00155   /* more mapping may be added in future versions */
00156 
00157   kate_motion_mapping_user=128               
00158 } kate_motion_mapping;
00159 
00161 typedef enum kate_motion_semantics {
00162   kate_motion_semantics_time,                    
00163   kate_motion_semantics_z,                       
00164   kate_motion_semantics_region_position,         
00165   kate_motion_semantics_region_size,             
00166   kate_motion_semantics_text_alignment_int,      
00167   kate_motion_semantics_text_alignment_ext,      
00168   kate_motion_semantics_text_position,           
00169   kate_motion_semantics_text_size,               
00170   kate_motion_semantics_marker1_position,        
00171   kate_motion_semantics_marker2_position,        
00172   kate_motion_semantics_marker3_position,        
00173   kate_motion_semantics_marker4_position,        
00174   kate_motion_semantics_glyph_pointer_1,         
00175   kate_motion_semantics_glyph_pointer_2,         
00176   kate_motion_semantics_glyph_pointer_3,         
00177   kate_motion_semantics_glyph_pointer_4,         
00178   kate_motion_semantics_text_color_rg,           
00179   kate_motion_semantics_text_color_ba,           
00180   kate_motion_semantics_background_color_rg,     
00181   kate_motion_semantics_background_color_ba,     
00182   kate_motion_semantics_draw_color_rg,           
00183   kate_motion_semantics_draw_color_ba,           
00184   kate_motion_semantics_style_morph,             
00185   kate_motion_semantics_text_path,               
00186   kate_motion_semantics_text_path_section,       
00187   kate_motion_semantics_draw,                    
00188   kate_motion_semantics_text_visible_section,    
00189   kate_motion_semantics_horizontal_margins,      
00190   kate_motion_semantics_vertical_margins,        
00191   kate_motion_semantics_bitmap_position,         
00192   kate_motion_semantics_bitmap_size,             
00194   /* more semantics may be added in future versions */
00195 
00196   kate_motion_semantics_user = 128               
00197 } kate_motion_semantics;
00198 
00200 typedef struct kate_motion {
00201   size_t ncurves;                                
00202   kate_curve **curves;                           
00203   kate_float *durations;                         
00204   kate_motion_mapping x_mapping;                 
00205   kate_motion_mapping y_mapping;                 
00206   kate_motion_semantics semantics;               
00207   uint32_t periodic:1;                           
00208   uint32_t pad0:31;
00209   uintptr_t pad1[5];
00210 } kate_motion;
00211 
00213 typedef enum kate_text_directionality {
00214   kate_l2r_t2b,                                  
00215   kate_r2l_t2b,                                  
00216   kate_t2b_r2l,                                  
00217   kate_t2b_l2r                                   
00218 } kate_text_directionality;
00219 
00221 typedef struct kate_palette {
00222   size_t ncolors;                                
00223   kate_color *colors;                            
00224   uintptr_t pad[2];
00225 } kate_palette;
00226 
00228 typedef enum kate_bitmap_type {
00229   kate_bitmap_type_paletted,                     
00230   kate_bitmap_type_png                           
00231 } kate_bitmap_type;
00232 
00234 typedef struct kate_bitmap {
00235   size_t width;                                  
00236   size_t height;                                 
00237   unsigned char bpp;                             
00238   kate_bitmap_type type;                         
00239   unsigned char pad0[2];
00240   int palette;                                   
00241   unsigned char *pixels;                         
00242   size_t size;                                   
00243   uintptr_t pad1[2];
00244 } kate_bitmap;
00245 
00247 typedef struct kate_font_range {
00248   int first_code_point;                          
00249   int last_code_point;                           
00250   int first_bitmap;                              
00251   uintptr_t pad[5];
00252 } kate_font_range;
00253 
00255 typedef struct kate_font_mapping {
00256   size_t nranges;                                
00257   kate_font_range **ranges;                      
00258   uintptr_t pad[6];
00259 } kate_font_mapping;
00260 
00266 typedef struct kate_info {
00267   unsigned char bitstream_version_major;         
00268   unsigned char bitstream_version_minor;         
00269   unsigned char pad0[2];
00270 
00271   kate_text_encoding text_encoding;              
00272   kate_text_directionality text_directionality;  
00274   unsigned char num_headers;                     
00275   unsigned char granule_shift;                   
00276   unsigned char pad1[2];
00277 
00278   kate_int32_t gps_numerator;                    
00279   kate_int32_t gps_denominator;                  
00281   kate_const char *language;                     
00283   kate_const char *category;                     
00285   size_t nregions;                               
00286   kate_const kate_region *kate_const *regions;   
00288   size_t nstyles;                                
00289   kate_const kate_style *kate_const *styles;     
00291   size_t ncurves;                                
00292   kate_const kate_curve *kate_const *curves;     
00294   size_t nmotions;                               
00295   kate_const kate_motion *kate_const *motions;   
00297   size_t npalettes;                              
00298   kate_const kate_palette *kate_const *palettes; 
00300   size_t nbitmaps;                               
00301   kate_const kate_bitmap *kate_const *bitmaps;   
00303   size_t nfont_ranges;                                       
00304   kate_const kate_font_range *kate_const *font_ranges;       
00306   size_t nfont_mappings;                                     
00307   kate_const kate_font_mapping *kate_const *font_mappings;   
00309   kate_markup_type text_markup_type;             
00311   uintptr_t pad2[13];
00312 
00313   /* internal */
00314   int remove_markup;
00315   int no_limits;
00316   int probe;
00317 
00318   uintptr_t pad3[13];
00319 } kate_info;
00320 
00321 struct kate_encode_state; /* internal */
00322 struct kate_decode_state; /* internal */
00323 
00325 typedef struct kate_state {
00326   kate_const kate_info *ki;                      
00328   /* internal */
00329   kate_const struct kate_encode_state *kes;
00330   kate_const struct kate_decode_state *kds;
00331 
00332   uintptr_t pad[5];
00333 } kate_state;
00334 
00336 typedef struct kate_comment {
00337   char **user_comments;                         
00338   int *comment_lengths;                         
00339   int comments;                                 
00340   char *vendor;                                 
00341 } kate_comment;
00342 
00347 typedef struct kate_event {
00348   kate_int64_t start;                           
00349   kate_int64_t duration;                        
00350   kate_int64_t backlink;                        
00352   kate_float start_time;                        
00353   kate_float end_time;                          
00355   kate_int32_t id;                              
00357   kate_text_encoding text_encoding;             
00358   kate_text_directionality text_directionality; 
00359   kate_const char *language;                    
00360   kate_const char *text;                        
00361   size_t len;                                   
00362   size_t len0;                                  
00364   size_t nmotions;                              
00365   kate_const kate_motion *kate_const *motions;  
00367   kate_const kate_region *region;               
00368   kate_const kate_style *style;                 
00369   kate_const kate_style *secondary_style;       
00370   kate_const kate_font_mapping *font_mapping;   
00371   kate_const kate_palette *palette;             
00372   kate_const kate_bitmap *bitmap;               
00374   kate_markup_type text_markup_type;            
00376   uintptr_t pad0[8];
00377 
00378   /* internal */
00379   const kate_info *ki;
00380   size_t trackers;
00381 
00382   uintptr_t pad1[10];
00383 } kate_event;
00384 
00386 typedef struct kate_tracker {
00387   const kate_info *ki;                          
00388   kate_const kate_event *event;                 
00389   kate_float t;                                 
00391   struct {
00392     uint32_t region:1;                          
00393     uint32_t text_alignment_int:1;              
00394     uint32_t text_alignment_ext:1;              
00395     uint32_t text_pos:1;                        
00396     uint32_t text_size:1;                       
00397     uint32_t marker_pos:4;                      
00398     uint32_t text_color:1;                      
00399     uint32_t background_color:1;                
00400     uint32_t draw_color:1;                      
00401     uint32_t glyph_pointer:4;                   
00402     uint32_t path:1;                            
00403     uint32_t draw:1;                            
00404     uint32_t visible_section:1;                 
00405     uint32_t z:1;                               
00406     uint32_t hmargins:1;                        
00407     uint32_t vmargins:1;                        
00408     uint32_t bitmap_pos:1;                      
00409     uint32_t bitmap_size:1;                     
00410     /* 24 bits */
00411     uint32_t pad0:8;
00412     uint32_t pad1:32;
00413     /* 64 bits */
00414   } has;                                        
00416   int window_w;                                 
00417   int window_h;                                 
00418   int frame_x;                                  
00419   int frame_y;                                  
00420   int frame_w;                                  
00421   int frame_h;                                  
00423   /* has.region */
00424   kate_float region_x;                          
00425   kate_float region_y;                          
00426   kate_float region_w;                          
00427   kate_float region_h;                          
00429   /* has.text_alignment (int/ext) */
00430   kate_float text_halign;                       
00431   kate_float text_valign;                       
00433   /* has.text_pos */
00434   kate_float text_x;                            
00435   kate_float text_y;                            
00437   /* has.text_size */
00438   kate_float text_size_x;                       
00439   kate_float text_size_y;                       
00441   /* has.marker_pos&(1<<n) */
00442   kate_float marker_x[4];                       
00443   kate_float marker_y[4];                       
00445   /* has.text_color */
00446   kate_color text_color;                        
00448   /* has.background_color */
00449   kate_color background_color;                  
00451   /* has.draw_color */
00452   kate_color draw_color;                        
00454   /* has.glyph_pointer&(1<<n) */
00455   kate_float glyph_pointer[4];                  
00456   kate_float glyph_height[4];                   
00458   /* has.path */
00459   kate_float path_start;                        
00460   kate_float path_end;                          
00462   /* has.draw */
00463   kate_float draw_x;                            
00464   kate_float draw_y;                            
00466   /* has.visible_section */
00467   kate_float visible_x;                         
00468   kate_float visible_y;                         
00470   /* has.z */
00471   kate_float z;                                 
00473   /* has.hmargins */
00474   kate_float left_margin;                       
00475   kate_float right_margin;                      
00477   /* has.vmargins */
00478   kate_float top_margin;                        
00479   kate_float bottom_margin;                     
00481   /* has.bitmap_pos */
00482   kate_float bitmap_x;                          
00483   kate_float bitmap_y;                          
00485   /* has.bitmap_size */
00486   kate_float bitmap_size_x;                     
00487   kate_float bitmap_size_y;                     
00489   /* internal */
00490   size_t nglyphs;
00491 
00492   uintptr_t pad[28];
00493 
00494 } kate_tracker;
00495 
00497 typedef struct kate_packet {
00498   size_t nbytes;             
00499   void *data;                
00500 } kate_packet;
00501 
00502 #ifdef __cplusplus
00503 extern "C" {
00504 #endif
00505 
00507 extern int kate_get_version(void);
00508 extern const char *kate_get_version_string(void);
00509 extern int kate_get_bitstream_version(void);
00510 extern const char *kate_get_bitstream_version_string(void);
00511 
00513 extern int kate_info_init(kate_info *ki);
00514 extern int kate_info_set_granule_encoding(kate_info *ki,kate_float resolution,kate_float max_length,kate_float max_event_lifetime);
00515 extern int kate_info_set_language(kate_info *ki,const char *language);
00516 extern int kate_info_set_text_directionality(kate_info *ki,kate_text_directionality text_directionality);
00517 extern int kate_info_set_markup_type(kate_info *ki,kate_markup_type text_markup_type);
00518 extern int kate_info_set_category(kate_info *ki,const char *category);
00519 extern int kate_info_add_region(kate_info *ki,kate_region *kr);
00520 extern int kate_info_add_style(kate_info *ki,kate_style *ks);
00521 extern int kate_info_add_curve(kate_info *ki,kate_curve *kc);
00522 extern int kate_info_add_motion(kate_info *ki,kate_motion *km);
00523 extern int kate_info_add_palette(kate_info *ki,kate_palette *kp);
00524 extern int kate_info_add_bitmap(kate_info *ki,kate_bitmap *kb);
00525 extern int kate_info_add_font_range(kate_info *ki,kate_font_range *kfr);
00526 extern int kate_info_add_font_mapping(kate_info *ki,kate_font_mapping *kfm);
00527 extern int kate_info_matches_language(const kate_info *ki,const char *language);
00528 extern int kate_info_remove_markup(kate_info *ki,int flag);
00529 extern int kate_info_no_limits(kate_info *ki,int flag);
00530 extern int kate_info_clear(kate_info *ki);
00531 
00533 extern int kate_granule_shift(const kate_info *ki);
00534 extern kate_float kate_granule_time(const kate_info *ki,kate_int64_t granulepos);
00535 extern kate_int64_t kate_duration_granule(const kate_info *ki,kate_float duration);
00536 extern kate_float kate_granule_duration(const kate_info *ki,kate_int64_t duration);
00537 
00539 extern int kate_clear(kate_state *k);
00540 extern int kate_motion_get_point(const kate_motion *km,kate_float duration,kate_float t,kate_float *x,kate_float *y);
00541 extern int kate_region_init(kate_region *kr);
00542 extern int kate_style_init(kate_style *ks);
00543 extern int kate_palette_init(kate_palette *kp);
00544 extern int kate_bitmap_init(kate_bitmap *kb);
00545 extern int kate_curve_init(kate_curve *kc);
00546 extern int kate_motion_init(kate_motion *km);
00547 
00549 extern int kate_text_get_character(kate_text_encoding text_encoding,const char ** const text,size_t *len0);
00550 extern int kate_text_set_character(kate_text_encoding text_encoding,int c,char ** const text,size_t *len0);
00551 extern int kate_text_remove_markup(kate_text_encoding text_encoding,char *text,size_t *len0);
00552 extern int kate_text_validate(kate_text_encoding text_encoding,const char *text,size_t len0);
00553 
00555 extern int kate_comment_init(kate_comment *kc);
00556 extern int kate_comment_clear(kate_comment *kc);
00557 extern int kate_comment_add(kate_comment *kc,const char *comment);
00558 extern int kate_comment_add_length(kate_comment *kc,const char *comment,size_t len);
00559 extern int kate_comment_add_tag(kate_comment *kc,const char *name,const char *value);
00560 extern const char *kate_comment_query(const kate_comment *kc,const char *tag,int count);
00561 extern int kate_comment_query_count(const kate_comment *kc,const char *tag);
00562 
00564 extern int kate_encode_init(kate_state *k,kate_info *ki);
00565 extern int kate_encode_headers(kate_state *k,kate_comment *kc,kate_packet *kp);
00566 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 */
00567 extern int kate_encode_keepalive(kate_state *k,kate_float t,kate_packet *kp);
00568 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 */
00569 extern int kate_encode_set_id(kate_state *k,kate_int32_t id);
00570 extern int kate_encode_set_language(kate_state *k,const char *language); /* language can be NULL */
00571 extern int kate_encode_set_text_encoding(kate_state *k,kate_text_encoding text_encoding);
00572 extern int kate_encode_set_text_directionality(kate_state *k,kate_text_directionality text_directionality);
00573 extern int kate_encode_set_region_index(kate_state *k,size_t region);
00574 extern int kate_encode_set_region(kate_state *k,const kate_region *kr);
00575 extern int kate_encode_set_style_index(kate_state *k,size_t style);
00576 extern int kate_encode_set_style(kate_state *k,const kate_style *ks);
00577 extern int kate_encode_set_secondary_style_index(kate_state *k,size_t style);
00578 extern int kate_encode_set_secondary_style(kate_state *k,const kate_style *ks);
00579 extern int kate_encode_set_font_mapping_index(kate_state *k,size_t font_mapping);
00580 extern int kate_encode_add_motion(kate_state *k,kate_motion *km,int destroy);
00581 extern int kate_encode_add_motion_index(kate_state *k,size_t motion);
00582 extern int kate_encode_set_palette_index(kate_state *k,size_t palette);
00583 extern int kate_encode_set_palette(kate_state *k,const kate_palette *kp);
00584 extern int kate_encode_set_bitmap_index(kate_state *k,size_t bitmap);
00585 extern int kate_encode_set_bitmap(kate_state *k,const kate_bitmap *kb);
00586 extern int kate_encode_set_markup_type(kate_state *k,int markup_type);
00587 
00589 extern int kate_decode_is_idheader(const kate_packet *kp);
00590 extern int kate_decode_init(kate_state *k,kate_info *ki);
00591 extern int kate_decode_headerin(kate_info *ki,kate_comment *kc,kate_packet *kp);
00592 extern int kate_decode_packetin(kate_state *k,kate_packet *kp);
00593 extern int kate_decode_eventout(kate_state *k,kate_const kate_event **ev); /* event can be NULL */
00594 
00596 extern int kate_tracker_init(kate_tracker *kin,const kate_info *ki,kate_const kate_event *ev);
00597 extern int kate_tracker_clear(kate_tracker *kin);
00598 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);
00599 extern int kate_tracker_morph_styles(kate_style *style,kate_float t,const kate_style *from,const kate_style *to);
00600 extern int kate_tracker_get_text_path_position(kate_tracker *kin,size_t glyph,int *x,int *y);
00601 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);
00602 
00604 extern int kate_font_get_index_from_code_point(const kate_font_mapping *kfm,int c);
00605 
00607 extern int kate_high_decode_init(kate_state *k);
00608 extern int kate_high_decode_packetin(kate_state *k,kate_packet *kp,kate_const kate_event **ev);
00609 extern int kate_high_decode_clear(kate_state *k);
00610 
00612 extern int kate_packet_wrap(kate_packet *kp,size_t nbytes,const void *data);
00613 extern int kate_packet_init(kate_packet *kp,size_t nbytes,const void *data);
00614 extern int kate_packet_clear(kate_packet *kp);
00615 
00616 #ifdef __cplusplus
00617 }
00618 #endif
00619 
00622 #define KATE_E_NOT_FOUND (-1)            
00623 #define KATE_E_INVALID_PARAMETER (-2)    
00624 #define KATE_E_OUT_OF_MEMORY (-3)        
00625 #define KATE_E_BAD_GRANULE (-4)          
00626 #define KATE_E_INIT (-5)                 
00627 #define KATE_E_BAD_PACKET (-6)           
00628 #define KATE_E_TEXT (-7)                 
00629 #define KATE_E_LIMIT (-8)                
00630 #define KATE_E_VERSION (-9)              
00631 #define KATE_E_NOT_KATE (-10)            
00634 #endif
00635 

Generated on Sun Jun 1 22:02:55 2008 for libkate by  doxygen 1.5.4