/* Copyright (C) 2008, 2009 Vincent Penquerc'h. This file is part of the Kate codec library. Written by Vincent Penquerc'h. Use, distribution and reproduction of this library is governed by a BSD style source license included with this source in the file 'COPYING'. Please read these terms before distributing. */ #ifndef KATE_kate_h_GUARD #define KATE_kate_h_GUARD /** \file kate.h The libkate public API. */ #include "kate/kate_config.h" /** \name API version */ /** @{ */ #define KATE_VERSION_MAJOR 0 /**< major version number of the libkate API */ #define KATE_VERSION_MINOR 4 /**< minor version number of the libkate API */ #define KATE_VERSION_PATCH 3 /**< patch version number of the libkate API */ /** @} */ /** \name Bitstream version */ /** @{ */ #define KATE_BITSTREAM_VERSION_MAJOR 0 /**< major version number of the highest bitstream version this version of libkate supports */ #define KATE_BITSTREAM_VERSION_MINOR 7 /**< minor version number of the highest bitstream version this version of libkate supports */ /** @} */ /** defines the character encoding used by text */ typedef enum { kate_utf8 /**< utf-8 variable length byte encoding, see RFC 3629 */ } kate_text_encoding; /** defines the type of markup in a text */ typedef enum { kate_markup_none, /**< the text should not be interpreted for markup */ kate_markup_simple /**< the text should be interpreted for simple markup */ } kate_markup_type; /** defines how to interpret spatial dimension values */ typedef enum { kate_pixel, /**< dimensions are in pixels */ kate_percentage, /**< dimensions are in percentage of total size */ kate_millionths /**< dimensions are in millionths of total size */ } kate_space_metric; struct kate_meta; typedef struct kate_meta kate_meta; /** defines an area where to draw */ typedef struct kate_region { kate_space_metric metric; /**< how to interpret the xywh values */ int x; /**< origin of the region */ int y; /**< origin of the region */ int w; /**< size of the region */ int h; /**< size of the region */ int style; /**< default style to apply to text in this region */ unsigned int clip:1; /**< text/images will be clipped to the region */ unsigned int pad0:31; kate_meta *meta; kate_uintptr_t pad1[5]; } kate_region; /** defines an RGBA color */ typedef struct kate_color { unsigned char r; /**< red component, 0 (black) to 255 (full intensity) */ unsigned char g; /**< green component, 0 (black) to 255 (full intensity) */ unsigned char b; /**< blue component, 0 (black) to 255 (full intensity) */ unsigned char a; /**< alpha component, 0 (fully transparent) to 255 (fully opaque) */ } kate_color; /** defines how to wrap text if necessary */ typedef enum { kate_wrap_word, /**< allow wrapping at word boundaries */ kate_wrap_none /**< forbid wrapping */ } kate_wrap_mode; /** defines a style to display text */ typedef struct kate_style { kate_float halign; /**< horizontal alignment, -1 for left, +1 for right, other values inter/extrapolate */ kate_float valign; /**< horizontal alignment, -1 for top, +1 for bottom, other values inter/extrapolate */ kate_color text_color; /**< RGBA color of the text */ kate_color background_color; /**< background RGBA color of the whole region, regardless of what extent any text has */ kate_color draw_color; /**< RGBA color for drawn shapes */ kate_space_metric font_metric; /**< whether font size are in pixels, percentage, etc */ kate_float font_width; /**< horizontal size of the glyphs */ kate_float font_height; /**< vertical size of the glyphs */ kate_space_metric margin_metric; /**< how to interpret margin values */ kate_float left_margin; /**< size of left margin */ kate_float top_margin; /**< size of top margin */ kate_float right_margin; /**< size of right margin */ kate_float bottom_margin; /**< size of bottom margin */ unsigned int bold:1; /**< display text in bold */ unsigned int italics:1; /**< display text in italics */ unsigned int underline:1; /**< display underlined text */ unsigned int strike:1; /**< display striked text */ unsigned int justify:1; /**< display justified text */ unsigned int wrap_mode:2; /**< how to wrap text if necessary */ unsigned int pad0:25; kate_const char *font; /**< name of the font to use */ kate_meta *meta; kate_uintptr_t pad1[8]; } kate_style; /** defines a type of curve */ typedef enum kate_curve_type { kate_curve_none, /**< no curve */ kate_curve_static, /**< a single point */ kate_curve_linear, /**< linear interpolation of line segments */ kate_curve_catmull_rom_spline, /**< Catmull-Rom spline, goes through each point (even the first and last) */ kate_curve_bezier_cubic_spline, /**< Bezier cubic spline, goes through the first and last points, but not others */ kate_curve_bspline /**< Cubic uniform B-spline with 3-multiplicity end knots (goes through each point) */ } kate_curve_type; /** defines a curve */ typedef struct kate_curve { kate_curve_type type; /**< type of the curve */ size_t npts; /**< number of points in this curve */ kate_float *pts; /**< point coordinates for this curve (2D: npts*2 values) */ kate_uintptr_t pad[5]; } kate_curve; /** defines a way to transform a curve point */ typedef enum kate_motion_mapping { /* these can be used for a x/y position mapping */ kate_motion_mapping_none, /**< motion maps to itself */ kate_motion_mapping_frame, /**< 0x0 at top left of frame, 1x1 at bottom right of frame */ kate_motion_mapping_window, /**< 0x0 at top left of window, 1x1 at bottom right of window */ kate_motion_mapping_region, /**< 0x0 at top left of region, 1x1 at bottom right of region */ kate_motion_mapping_event_duration, /**< 0-1 map to 0 to the duration of the event (to be used with time) */ kate_motion_mapping_bitmap_size, /**< 0x0 at top left of bitmap, 1x1 at bottom right of bitmap */ #if 0 text is useful, find a way to readd it easily kate_motion_mapping_text, /**< 0x0 at top left of text, 1x1 at bottom right of text */ #endif /* more mapping may be added in future versions */ kate_motion_mapping_user=128 /**< 128 to 255 for user specific mappings */ } kate_motion_mapping; /** defines what uses a motion can have */ typedef enum kate_motion_semantics { kate_motion_semantics_time, /**< controls the flow of time - 1D */ kate_motion_semantics_z, /**< controls the "depth" of the plane - 1D */ kate_motion_semantics_region_position, /**< controls the region position */ kate_motion_semantics_region_size, /**< controls the region size */ kate_motion_semantics_text_alignment_int, /**< controls internal text alignment */ kate_motion_semantics_text_alignment_ext, /**< controls external text alignment */ kate_motion_semantics_text_position, /**< controls the text position */ kate_motion_semantics_text_size, /**< controls the text size */ kate_motion_semantics_marker1_position, /**< controls the position of a point */ kate_motion_semantics_marker2_position, /**< controls the position of a point */ kate_motion_semantics_marker3_position, /**< controls the position of a point */ kate_motion_semantics_marker4_position, /**< controls the position of a point */ kate_motion_semantics_glyph_pointer_1, /**< controls a pointer to a particular glyph in the text */ kate_motion_semantics_glyph_pointer_2, /**< controls a pointer to a particular glyph in the text */ kate_motion_semantics_glyph_pointer_3, /**< controls a pointer to a particular glyph in the text */ kate_motion_semantics_glyph_pointer_4, /**< controls a pointer to a particular glyph in the text */ kate_motion_semantics_text_color_rg, /**< controls the red and green components of the text color */ kate_motion_semantics_text_color_ba, /**< controls the blue and alpha components of the text color */ kate_motion_semantics_background_color_rg, /**< controls the red and green components of the background color */ kate_motion_semantics_background_color_ba, /**< controls the blue and alpha components of the background color */ kate_motion_semantics_draw_color_rg, /**< controls the red and green components of the draw color */ kate_motion_semantics_draw_color_ba, /**< controls the blue and alpha components of the draw color */ kate_motion_semantics_style_morph, /**< controls morphing between style and secondary style */ kate_motion_semantics_text_path, /**< controls the path on which text is drawn */ kate_motion_semantics_text_path_section, /**< controls the section of the path on which text is drawn */ kate_motion_semantics_draw, /**< controls drawing */ kate_motion_semantics_text_visible_section, /**< controls the section of the text which is visible */ kate_motion_semantics_horizontal_margins, /**< controls the size of the left and right margins */ kate_motion_semantics_vertical_margins, /**< controls the size of the top and bottom margins */ kate_motion_semantics_bitmap_position, /**< controls the position of the background image */ kate_motion_semantics_bitmap_size, /**< controls the size of the background image */ kate_motion_semantics_marker1_bitmap, /**< controls the bitmap of the image used for marker 1 */ kate_motion_semantics_marker2_bitmap, /**< controls the bitmap of the image used for marker 2 */ kate_motion_semantics_marker3_bitmap, /**< controls the bitmap of the image used for marker 3 */ kate_motion_semantics_marker4_bitmap, /**< controls the bitmap of the image used for marker 4 */ kate_motion_semantics_glyph_pointer_1_bitmap, /**< controls the bitmap of the image used for glyph pointer 1 */ kate_motion_semantics_glyph_pointer_2_bitmap, /**< controls the bitmap of the image used for glyph pointer 2 */ kate_motion_semantics_glyph_pointer_3_bitmap, /**< controls the bitmap of the image used for glyph pointer 3 */ kate_motion_semantics_glyph_pointer_4_bitmap, /**< controls the bitmap of the image used for glyph pointer 4 */ kate_motion_semantics_draw_width, /**< controls the width of the drawn line */ /* more semantics may be added in future versions */ kate_motion_semantics_user = 128 /**< 128 to 255 for user specific semantics */ } kate_motion_semantics; /** defines a motion - well, try to find a better explanation */ typedef struct kate_motion { size_t ncurves; /**< number of curves in this motion */ kate_curve **curves; /**< the list of curves in this motion */ kate_float *durations; /**< the durations of each curve */ kate_motion_mapping x_mapping; /**< how to remap the x coordinate of the points */ kate_motion_mapping y_mapping; /**< how to remap the y coordinate of the points */ kate_motion_semantics semantics; /**< what use this motion has */ unsigned int periodic:1; /**< if true, repeats periodically (loops) */ unsigned int pad0:31; kate_meta *meta; kate_uintptr_t pad1[4]; } kate_motion; /** defines the direction in which glyphs within a text are drawn */ typedef enum kate_text_directionality { kate_l2r_t2b, /**< left to right, top to bottom: eg, English */ kate_r2l_t2b, /**< right to left, top to bottom: eg, Arabic */ kate_t2b_r2l, /**< top to bottom, right to left: eg, Japanese */ kate_t2b_l2r /**< top to bottom, left to right: eg, Sometimes Japanese */ } kate_text_directionality; /** defines colors to correspond to a bitmap's pixels */ typedef struct kate_palette { size_t ncolors; /**< number of colors in this palette */ kate_color *colors; /**< the list of colors in this palette */ kate_meta *meta; kate_uintptr_t pad[1]; } kate_palette; /** defines a particular type of bitmap */ typedef enum kate_bitmap_type { kate_bitmap_type_paletted, /**< paletted bitmap */ kate_bitmap_type_png /**< a PNG bitmap */ } kate_bitmap_type; /** defines a paletted image */ typedef struct kate_bitmap { size_t width; /**< width in pixels */ size_t height; /**< height in pixels */ unsigned char bpp; /**< bits per pixel, from 1 to 8, or 0 for a raw PNG bitmap */ kate_bitmap_type type; /**< the type of this bitmap */ unsigned char pad0[1]; unsigned char internal; int palette; /**< index of the default palette to use */ unsigned char *pixels; /**< pixels, rows first, one byte per pixel regardless of bpp */ size_t size; /**< for raw bitmaps, number of bytes in pixels */ int x_offset; /**< the horizontal offset to the logical origin of the bitmap */ int y_offset; /**< the vertical offset to the logical origin of the bitmap */ kate_meta *meta; kate_uintptr_t pad1[14]; } kate_bitmap; /** defines a set of images to map to a range of Unicode code points */ typedef struct kate_font_range { int first_code_point; /**< first code point in this range */ int last_code_point; /**< last code point in this range */ int first_bitmap; /**< index of the bitmap the first code point maps to */ kate_uintptr_t pad[5]; } kate_font_range; /** defines a set of ranges to define a font mapping */ typedef struct kate_font_mapping { size_t nranges; /**< the number of ranges in this mapping */ kate_font_range **ranges; /**< the list of ranges in this mapping */ kate_uintptr_t pad[6]; } kate_font_mapping; /** Information about a Kate bitstream. On encoding, this information will be filled by the encoder. On decoding, it will be extracted from the stream headers. */ typedef struct kate_info { unsigned char bitstream_version_major; /**< the version of the bitstream being read or written */ unsigned char bitstream_version_minor; /**< the version of the bitstream being read or written */ unsigned char pad0[2]; kate_text_encoding text_encoding; /**< the default text encoding (utf-8 only for now) */ kate_text_directionality text_directionality; /**< the default text directionality (left to right, etc) */ unsigned char num_headers; /**< number of header packets in the bitstream */ unsigned char granule_shift; /**< how many low granpos bits are used for the offset */ unsigned char pad1[2]; kate_uint32_t gps_numerator; /**< granules per second numerator */ kate_uint32_t gps_denominator; /**< granules per second denominator */ kate_const char *language; /**< based on RFC 3066, 15 character + terminating zero max */ kate_const char *category; /**< freeform for now, 15 characters + terminating zero max */ size_t nregions; /**< the number of predefined regions */ kate_const kate_region *kate_const *regions; /**< the list of predefined regions */ size_t nstyles; /**< the number of predefined styles */ kate_const kate_style *kate_const *styles; /**< the list of predefined styles */ size_t ncurves; /**< the number of predefined curves */ kate_const kate_curve *kate_const *curves; /**< the list of predefined curves */ size_t nmotions; /**< the number of predefined motions */ kate_const kate_motion *kate_const *motions; /**< the list of predefined motions */ size_t npalettes; /**< the number of predefined palettes */ kate_const kate_palette *kate_const *palettes; /**< the list of predefined palettes */ size_t nbitmaps; /**< the number of predefined bitmaps */ kate_const kate_bitmap *kate_const *bitmaps; /**< the list of predefined bitmaps */ size_t nfont_ranges; /**< the number of predefined font ranges */ kate_const kate_font_range *kate_const *font_ranges; /**< the list of predefined font ranges */ size_t nfont_mappings; /**< the number of predefined font mappings */ kate_const kate_font_mapping *kate_const *font_mappings; /**< the list of predefined font mappings */ kate_markup_type text_markup_type; /**< how to interpret any markup found in the text */ size_t original_canvas_width; /**< width of the canvas this stream was authored for */ size_t original_canvas_height; /**< height of the canvas this stream was authored for */ kate_uintptr_t pad2[11]; /* internal */ int remove_markup; int no_limits; int probe; kate_uintptr_t pad3[13]; } kate_info; struct kate_encode_state; /* internal */ struct kate_decode_state; /* internal */ /** top level information about a Kate bitstream */ typedef struct kate_state { kate_const kate_info *ki; /**< the kate_info associated with this state */ /* internal */ kate_const struct kate_encode_state *kes; kate_const struct kate_decode_state *kds; kate_uintptr_t pad[5]; } kate_state; /** Vorbis comments - this is the same as Vorbis and Theora comments */ typedef struct kate_comment { char **user_comments; /**< the list of comments, in the form "tag=value" */ int *comment_lengths; /**< the lengths of the comment strings in bytes */ int comments; /**< the number of comments in the list */ char *vendor; /**< vendor string, null terminated */ } kate_comment; /** This is an event passed to the user. A kate_tracker may be used to track animation changes to this event. */ typedef struct kate_event { kate_int64_t start; /**< the time at offset rate at which this event starts */ kate_int64_t duration; /**< the duration in granules */ kate_int64_t backlink; /**< the relative offset in granules since the start of the earliest still active event (positive or zero) */ kate_float start_time; /**< the time at which this event starts */ kate_float end_time; /**< the time at which this event ends */ kate_int32_t id; /**< unique id to identify this event */ kate_text_encoding text_encoding; /**< character encoding for the text in this event */ kate_text_directionality text_directionality; /**< directionality of the text in this event */ kate_const char *language; /**< language of the text in this event (may be NULL if no override) */ kate_const char *text; /**< the event text (may be NULL if none) */ size_t len; /**< length in bytes of the text */ size_t len0; /**< length in bytes of the text, including terminating zero(s) */ size_t nmotions; /**< number of attached motions (may be zero) */ kate_const kate_motion *kate_const *motions; /**< the list of attached motions (may be NULL if none) */ kate_const kate_region *region; /**< region to display in (may be NULL for no particular region) */ kate_const kate_style *style; /**< style to display text (may be NULL for no particular style) */ kate_const kate_style *secondary_style; /**< secondary style to display text (may be NULL for no particular style) */ kate_const kate_font_mapping *font_mapping; /**< font mapping to use for the text (may be NULL for no particular mapping) */ kate_const kate_palette *palette; /**< palette to use as background (may be NULL for none) */ kate_const kate_bitmap *bitmap; /**< bitmap to use as background (may be NULL for none) */ kate_markup_type text_markup_type; /**< how to interpret any markup found in the text */ size_t nbitmaps; /**< number of attached bitmaps (may be zero) */ kate_const kate_bitmap *kate_const *bitmaps; /**< the list of attached bitmaps (may be NULL if none) */ kate_meta *meta; kate_uintptr_t pad0[5]; /* internal */ const kate_info *ki; size_t trackers; kate_uintptr_t pad1[10]; } kate_event; struct kate_tracker_internal; /* internal */ /** this keeps track of changes during an event's lifetime */ typedef struct kate_tracker { const kate_info *ki; /**< the kate_info associated with this tracker */ kate_const kate_event *event; /**< the event being tracked */ kate_float t; /**< the current time at which the tracker interpolates */ struct { unsigned int region:1; /**< if set, the tracker has region information */ unsigned int text_alignment_int:1; /**< if set, the tracker has internal text alignment information */ unsigned int text_alignment_ext:1; /**< if set, the tracker has external text alignment information */ unsigned int text_pos:1; /**< if set, the tracker has text position information */ unsigned int text_size:1; /**< if set, the tracker has text size information */ unsigned int marker_pos:4; /**< if set, the tracker has marker position information */ unsigned int text_color:1; /**< if set, the tracker has text color information */ unsigned int background_color:1; /**< if set, the tracker has background color information */ unsigned int draw_color:1; /**< if set, the tracker has draw color information */ unsigned int glyph_pointer:4; /**< if set, the tracker has glyph pointer information */ unsigned int path:1; /**< if set, the tracker has text path information */ unsigned int draw:1; /**< if set, the tracker has draw information */ unsigned int visible_section:1; /**< if set, the tracker has visible section information */ unsigned int z:1; /**< if set, the tracker has z (depth) information */ unsigned int hmargins:1; /**< if set, the tracker has horizontal margin information */ unsigned int vmargins:1; /**< if set, the tracker has vertical margin information */ unsigned int bitmap_pos:1; /**< if set, the tracker has bitmap position information */ unsigned int bitmap_size:1; /**< if set, the tracker has bitmap size information */ unsigned int marker_bitmap:4; /**< if set, the tracker has bitmap information for the marker bitmap */ unsigned int glyph_pointer_bitmap:4; /**< if set, the tracker has bitmap information for the glyph pointer bitmap */ unsigned int draw_width:1; /**< if set, the tracker has draw line width information */ /* 33 bits */ unsigned int pad0:31; /* 64 bits */ } has; /**< bitfield describing what information the tracker has */ int window_w; /**< the window width */ int window_h; /**< the window height */ int frame_x; /**< the video frame origin in the window */ int frame_y; /**< the video frame origin in the window */ int frame_w; /**< the video frame width */ int frame_h; /**< the video frame height */ /* has.region */ kate_float region_x; /**< the region horizontal position in pixels */ kate_float region_y; /**< the region vertical position in pixels */ kate_float region_w; /**< the region width in pixels */ kate_float region_h; /**< the region height in pixels */ /* has.text_alignment (int/ext) */ kate_float text_halign; /**< the horizontal text alignment (-1 for left, 1 for right, etc) */ kate_float text_valign; /**< the vertical text alignment (-1 for top, 1 for bottom, etc) */ /* has.text_pos */ kate_float text_x; /**< the horizontal text position */ kate_float text_y; /**< the vertical text position */ /* has.text_size */ kate_float text_size_x; /**< the horizontal text size (eg, width) */ kate_float text_size_y; /**< the vertical text size (eg, height) */ /* has.marker_pos&(1<