| 1 |
/* Copyright (C) 2008 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 |
#define KATE_INTERNAL |
| 11 |
#include "kate_internal.h" |
| 12 |
|
| 13 |
#ifdef HAVE_STDLIB_H |
| 14 |
#include <stdlib.h> |
| 15 |
#endif |
| 16 |
#ifdef HAVE_STRING_H |
| 17 |
#include <string.h> |
| 18 |
#endif |
| 19 |
#include "kate/kate.h" |
| 20 |
|
| 21 |
typedef struct kate_tracker_internal { |
| 22 |
size_t nglyphs; |
| 23 |
} kate_tracker_internal; |
| 24 |
|
| 25 |
/** |
| 26 |
\ingroup tracker |
| 27 |
Initializes a tracker with the given event. |
| 28 |
When done, it should be cleared using kate_tracker_clear. |
| 29 |
\param kin the tracker to initialize |
| 30 |
\param ki the kate_info structure for the stream |
| 31 |
\param ev the event to track |
| 32 |
\returns 0 success |
| 33 |
\returns KATE_E_INVALID_PARAMETER when kin, ki or ev is NULL. |
| 34 |
\returns KATE_E_OUT_OF_MEMORY when unable to allocate memory. |
| 35 |
*/ |
| 36 |
int kate_tracker_init(kate_tracker *kin,const kate_info *ki,kate_const kate_event *ev) |
| 37 |
{ |
| 38 |
kate_tracker_internal *internal; |
| 39 |
const char *text; |
| 40 |
size_t rlen0; |
| 41 |
|
| 42 |
if (!kin || !ki || !ev) return KATE_E_INVALID_PARAMETER; |
| 43 |
|
| 44 |
internal=(kate_tracker_internal*)kate_malloc(sizeof(kate_tracker_internal)); |
| 45 |
if (!internal) return KATE_E_OUT_OF_MEMORY; |
| 46 |
|
| 47 |
kin->ki=ki; |
| 48 |
kin->event=ev; |
| 49 |
kin->internal=internal; |
| 50 |
kate_event_track(kin->event); |
| 51 |
|
| 52 |
kin->internal->nglyphs=0; |
| 53 |
text=kin->event->text; |
| 54 |
rlen0=kin->event->len0; |
| 55 |
while (kate_text_get_character(kin->event->text_encoding,&text,&rlen0)>0) |
| 56 |
++kin->internal->nglyphs; |
| 57 |
|
| 58 |
return 0; |
| 59 |
} |
| 60 |
|
| 61 |
/** |
| 62 |
\ingroup tracker |
| 63 |
Clears a tracker. |
| 64 |
\param kin the tracker to clear, must have been initialized with kate_tracker_init |
| 65 |
\returns 0 success |
| 66 |
\returns KATE_E_* error |
| 67 |
*/ |
| 68 |
int kate_tracker_clear(kate_tracker *kin) |
| 69 |
{ |
| 70 |
if (!kin) return KATE_E_INVALID_PARAMETER; |
| 71 |
if (!kin->event) return KATE_E_INIT; |
| 72 |
if (!kin->internal) return KATE_E_INIT; |
| 73 |
|
| 74 |
kate_free(kin->internal); |
| 75 |
kate_event_release(kin->event); |
| 76 |
|
| 77 |
return 0; |
| 78 |
} |
| 79 |
|
| 80 |
#define LERP(t,from,to) (((1-(t))*(from))+((t)*(to))) |
| 81 |
|
| 82 |
/** |
| 83 |
\ingroup tracker |
| 84 |
Morphs between two styles. |
| 85 |
t should be between 0 and 1 |
| 86 |
\param style the style that will hold the morphed style |
| 87 |
\param t the amount of morping from the from style (eg, 0 yields from, 1 yields to) |
| 88 |
\param from the style to morph from |
| 89 |
\param to the style to morph to |
| 90 |
\returns 0 success |
| 91 |
\returns KATE_E_* error |
| 92 |
*/ |
| 93 |
int kate_tracker_morph_styles(kate_style *style,kate_float t,const kate_style *from,const kate_style *to) |
| 94 |
{ |
| 95 |
if (!style || !from || !to) return KATE_E_INVALID_PARAMETER; |
| 96 |
if (t<(kate_float)-0.001 || t>(kate_float)1.001) return KATE_E_INVALID_PARAMETER; |
| 97 |
|
| 98 |
/* clamp, just in case */ |
| 99 |
if (t<0) t=0; |
| 100 |
if (t>1) t=1; |
| 101 |
|
| 102 |
#define MORPH(field) style->field=LERP(t,from->field,to->field) |
| 103 |
#define MORPHINT(field) style->field=(int)((kate_float)0.5+LERP(t,from->field,to->field)) |
| 104 |
MORPH(halign); |
| 105 |
MORPH(valign); |
| 106 |
MORPHINT(text_color.r); |
| 107 |
MORPHINT(text_color.g); |
| 108 |
MORPHINT(text_color.b); |
| 109 |
MORPHINT(text_color.a); |
| 110 |
MORPHINT(background_color.r); |
| 111 |
MORPHINT(background_color.g); |
| 112 |
MORPHINT(background_color.b); |
| 113 |
MORPHINT(background_color.a); |
| 114 |
MORPHINT(draw_color.r); |
| 115 |
MORPHINT(draw_color.g); |
| 116 |
MORPHINT(draw_color.b); |
| 117 |
MORPHINT(draw_color.a); |
| 118 |
MORPHINT(font_metric); /* doesn't make much sense, caveat streamor */ |
| 119 |
MORPH(font_width); |
| 120 |
MORPH(font_height); |
| 121 |
MORPHINT(margin_metric); /* doesn't make much sense, caveat streamor */ |
| 122 |
MORPH(left_margin); |
| 123 |
MORPH(top_margin); |
| 124 |
MORPH(right_margin); |
| 125 |
MORPH(bottom_margin); |
| 126 |
MORPHINT(bold); |
| 127 |
MORPHINT(italics); |
| 128 |
MORPHINT(underline); |
| 129 |
MORPHINT(strike); |
| 130 |
MORPHINT(justify); |
| 131 |
MORPHINT(wrap_mode); /* doesn't make much sense, caveat streamor */ |
| 132 |
style->font=(t<(kate_float)0.5)?from->font:to->font; |
| 133 |
#undef MORPHINT |
| 134 |
#undef MORPH |
| 135 |
|
| 136 |
return 0; |
| 137 |
} |
| 138 |
|
| 139 |
/** |
| 140 |
\ingroup tracker |
| 141 |
Remaps a point according to the given mappings |
| 142 |
\param kin the tracker to use for the remapping |
| 143 |
\param x_mapping the mapping for use for the x coordinate |
| 144 |
\param y_mapping the mapping for use for the y coordinate |
| 145 |
\param x a pointer to the x coordinate |
| 146 |
\param y a pointer to the y coordinate |
| 147 |
\returns 0 success |
| 148 |
\returns KATE_E_* error |
| 149 |
*/ |
| 150 |
int kate_tracker_remap(const kate_tracker *kin,kate_motion_mapping x_mapping,kate_motion_mapping y_mapping,kate_float *x,kate_float *y) |
| 151 |
{ |
| 152 |
if (!kin || !x || !y) return KATE_E_INVALID_PARAMETER; |
| 153 |
|
| 154 |
switch (x_mapping) { |
| 155 |
case kate_motion_mapping_none: |
| 156 |
/* nothing to do */ |
| 157 |
break; |
| 158 |
case kate_motion_mapping_frame: |
| 159 |
*x=kin->frame_x+(*x)*kin->frame_w; |
| 160 |
break; |
| 161 |
case kate_motion_mapping_window: |
| 162 |
*x=(*x)*kin->window_w; |
| 163 |
break; |
| 164 |
case kate_motion_mapping_region: |
| 165 |
*x=kin->region_x+(*x)*kin->region_w; |
| 166 |
break; |
| 167 |
case kate_motion_mapping_event_duration: |
| 168 |
*x=(*x)*(kin->event->end_time-kin->event->start_time); |
| 169 |
break; |
| 170 |
case kate_motion_mapping_bitmap_size: |
| 171 |
if (!kin->event->bitmap) return KATE_E_INVALID_PARAMETER; |
| 172 |
*x=(*x)*kin->event->bitmap->width; |
| 173 |
break; |
| 174 |
default: |
| 175 |
/* unknown mapping */ |
| 176 |
return KATE_E_INVALID_PARAMETER; |
| 177 |
} |
| 178 |
|
| 179 |
switch (y_mapping) { |
| 180 |
case kate_motion_mapping_none: |
| 181 |
/* nothing to do */ |
| 182 |
break; |
| 183 |
case kate_motion_mapping_frame: |
| 184 |
*y=kin->frame_y+(*y)*kin->frame_h; |
| 185 |
break; |
| 186 |
case kate_motion_mapping_window: |
| 187 |
*y=(*y)*kin->window_h; |
| 188 |
break; |
| 189 |
case kate_motion_mapping_region: |
| 190 |
*y=kin->region_y+(*y)*kin->region_h; |
| 191 |
break; |
| 192 |
case kate_motion_mapping_event_duration: |
| 193 |
*y=(*y)*(kin->event->end_time-kin->event->start_time); |
| 194 |
break; |
| 195 |
case kate_motion_mapping_bitmap_size: |
| 196 |
if (!kin->event->bitmap) return KATE_E_INVALID_PARAMETER; |
| 197 |
*y=(*y)*kin->event->bitmap->height; |
| 198 |
break; |
| 199 |
default: |
| 200 |
/* unknown mapping */ |
| 201 |
return KATE_E_INVALID_PARAMETER; |
| 202 |
} |
| 203 |
|
| 204 |
return 0; |
| 205 |
} |
| 206 |
|
| 207 |
static const kate_motion *kate_tracker_find_motion(const kate_tracker *kin,kate_motion_semantics semantics) |
| 208 |
{ |
| 209 |
const kate_event *ev; |
| 210 |
const kate_motion *km; |
| 211 |
size_t n; |
| 212 |
|
| 213 |
if (!kin || !kin->event) return NULL; |
| 214 |
|
| 215 |
ev=kin->event; |
| 216 |
for (n=0;n<ev->nmotions;++n) { |
| 217 |
km=ev->motions[n]; |
| 218 |
if (km->semantics==semantics) return km; |
| 219 |
} |
| 220 |
|
| 221 |
return NULL; |
| 222 |
} |
| 223 |
|
| 224 |
/** |
| 225 |
\ingroup tracker |
| 226 |
Returns the value of a particular property at the given time |
| 227 |
\param kin the tracker to update the property for |
| 228 |
\param duration the duration of the event the motion belongs to |
| 229 |
\param t the time, between 0 and duration, at which to compute the point |
| 230 |
\param semantics the semantics of the motion to use |
| 231 |
\param x a pointer to the x coordinate |
| 232 |
\param y a pointer to the y coordinate |
| 233 |
\returns 0 success |
| 234 |
\returns 1 success, and there is no such motion at this time |
| 235 |
\returns KATE_E_* error |
| 236 |
*/ |
| 237 |
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) |
| 238 |
{ |
| 239 |
const kate_motion *km; |
| 240 |
int ret; |
| 241 |
|
| 242 |
if (!kin || !x || !y) return KATE_E_INVALID_PARAMETER; |
| 243 |
|
| 244 |
km=kate_tracker_find_motion(kin,semantics); |
| 245 |
if (km) { |
| 246 |
ret=kate_motion_get_point(km,duration,t,x,y); |
| 247 |
if (ret<0) return ret; |
| 248 |
if (ret==0) { |
| 249 |
ret=kate_tracker_remap(kin,km->x_mapping,km->y_mapping,x,y); |
| 250 |
if (ret<0) return ret; |
| 251 |
return 0; |
| 252 |
} |
| 253 |
return 1; /* positive means no error, but no curve at that point */ |
| 254 |
} |
| 255 |
return 1; /* positive means no error, but nothing found either */ |
| 256 |
} |
| 257 |
|
| 258 |
static int kate_tracker_update_property_at(const kate_tracker *kin,kate_float t,kate_motion_semantics semantics,kate_float *x,kate_float *y) |
| 259 |
{ |
| 260 |
#if 1 |
| 261 |
kate_float duration=kin->event->end_time-kin->event->start_time; |
| 262 |
return kate_tracker_update_property_at_duration(kin,duration,t,semantics,x,y); |
| 263 |
#else |
| 264 |
const kate_motion *km; |
| 265 |
int ret; |
| 266 |
|
| 267 |
if (!kin || !x || !y) return KATE_E_INVALID_PARAMETER; |
| 268 |
|
| 269 |
km=kate_tracker_find_motion(kin,semantics); |
| 270 |
if (km) { |
| 271 |
/* TODO: could be precalculated */ |
| 272 |
kate_float duration=kin->event->end_time-kin->event->start_time; |
| 273 |
ret=kate_motion_get_point(km,duration,t,x,y); |
| 274 |
if (ret<0) return ret; |
| 275 |
if (ret==0) { |
| 276 |
ret=kate_tracker_remap(kin,km->x_mapping,km->y_mapping,x,y); |
| 277 |
if (ret<0) return ret; |
| 278 |
return 0; |
| 279 |
} |
| 280 |
return 1; /* positive means no error, but no curve at that point */ |
| 281 |
} |
| 282 |
return 1; /* positive means no error, but nothing found either */ |
| 283 |
#endif |
| 284 |
} |
| 285 |
|
| 286 |
static int kate_tracker_update_property(const kate_tracker *kin,kate_motion_semantics semantics,kate_float *px,kate_float *py) |
| 287 |
{ |
| 288 |
if (!kin) return KATE_E_INVALID_PARAMETER; |
| 289 |
return kate_tracker_update_property_at(kin,kin->t,semantics,px,py); |
| 290 |
} |
| 291 |
|
| 292 |
static unsigned char kate_float_to_color_component(kate_float c) |
| 293 |
{ |
| 294 |
int v=(int)(c+(kate_float)0.5); |
| 295 |
if (v<0) v=0; |
| 296 |
if (v>255) v=255; |
| 297 |
return v; |
| 298 |
} |
| 299 |
|
| 300 |
static const kate_bitmap *kate_tracker_find_bitmap(const kate_tracker *kin,kate_float frame) |
| 301 |
{ |
| 302 |
size_t idx=(size_t)(frame+(kate_float)0.5); |
| 303 |
if (kin->event->nbitmaps>0) { |
| 304 |
if (idx<kin->event->nbitmaps) { |
| 305 |
return kin->event->bitmaps[idx]; |
| 306 |
} |
| 307 |
} |
| 308 |
else { |
| 309 |
if (idx<kin->ki->nbitmaps) { |
| 310 |
return kin->ki->bitmaps[idx]; |
| 311 |
} |
| 312 |
} |
| 313 |
return NULL; |
| 314 |
} |
| 315 |
|
| 316 |
/** |
| 317 |
\ingroup tracker |
| 318 |
Tracks changes in an event at the given time. |
| 319 |
\param kin the tracker to update |
| 320 |
\param t the time (between 0 and the duration of the motion) to update to |
| 321 |
\param window_w the width of the window |
| 322 |
\param window_h the height of the window |
| 323 |
\param frame_x the horizontal offset of the video frame within the window |
| 324 |
\param frame_y the vertical offset of the video frame within the window |
| 325 |
\param frame_w the width of the video frame |
| 326 |
\param frame_h the height of the video frame |
| 327 |
\returns 0 success |
| 328 |
\returns KATE_E_* error |
| 329 |
*/ |
| 330 |
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) |
| 331 |
{ |
| 332 |
const kate_event *ev; |
| 333 |
const kate_region *kr; |
| 334 |
const kate_style *ks; |
| 335 |
const kate_motion *km; |
| 336 |
size_t n; |
| 337 |
int ret; |
| 338 |
kate_float r,g,b,a; |
| 339 |
kate_float dummy; |
| 340 |
kate_float frame; |
| 341 |
|
| 342 |
if (!kin) return KATE_E_INVALID_PARAMETER; |
| 343 |
if (!kin->event) return KATE_E_INIT; |
| 344 |
if (t<0) return KATE_E_INVALID_PARAMETER; |
| 345 |
if (frame_w<0 || frame_h<0) return KATE_E_INVALID_PARAMETER; |
| 346 |
|
| 347 |
ev=kin->event; |
| 348 |
kin->t=t; |
| 349 |
memset(&kin->has,0,sizeof(kin->has)); |
| 350 |
|
| 351 |
kin->window_w=window_w; |
| 352 |
kin->window_h=window_h; |
| 353 |
kin->frame_x=frame_x; |
| 354 |
kin->frame_y=frame_y; |
| 355 |
kin->frame_w=frame_w; |
| 356 |
kin->frame_h=frame_h; |
| 357 |
|
| 358 |
/* find out which region we're in, if any */ |
| 359 |
kr=ev->region; |
| 360 |
|
| 361 |
/* find out which style we have, if any */ |
| 362 |
ks=ev->style; |
| 363 |
if (!ks && kr && kr->style>=0) ks=kin->ki->styles[kr->style]; /* regions can have a default style */ |
| 364 |
|
| 365 |
/* start off with the event attributes */ |
| 366 |
kin->region_x=kin->region_y=kin->region_w=kin->region_h=0; |
| 367 |
if (kr) { |
| 368 |
switch (kr->metric) { |
| 369 |
case kate_percentage: |
| 370 |
kin->region_x=kr->x*frame_w/(kate_float)100; |
| 371 |
kin->region_y=kr->y*frame_h/(kate_float)100; |
| 372 |
kin->region_w=kr->w*frame_w/(kate_float)100; |
| 373 |
kin->region_h=kr->h*frame_h/(kate_float)100; |
| 374 |
break; |
| 375 |
case kate_millionths: /* use 64 bit arithmetic to avoid overflow */ |
| 376 |
kin->region_x=kr->x*(kate_int64_t)frame_w/(kate_float)1000000; |
| 377 |
kin->region_y=kr->y*(kate_int64_t)frame_h/(kate_float)1000000; |
| 378 |
kin->region_w=kr->w*(kate_int64_t)frame_w/(kate_float)1000000; |
| 379 |
kin->region_h=kr->h*(kate_int64_t)frame_h/(kate_float)1000000; |
| 380 |
break; |
| 381 |
case kate_pixel: |
| 382 |
kin->region_x=kr->x; |
| 383 |
kin->region_y=kr->y; |
| 384 |
kin->region_w=kr->w; |
| 385 |
kin->region_h=kr->h; |
| 386 |
break; |
| 387 |
default: |
| 388 |
return KATE_E_INVALID_PARAMETER; |
| 389 |
break; |
| 390 |
} |
| 391 |
/* we already have a valid region */ |
| 392 |
kin->has.region=1; |
| 393 |
} |
| 394 |
|
| 395 |
if (ks) { |
| 396 |
kin->text_color=ks->text_color; |
| 397 |
kin->background_color=ks->background_color; |
| 398 |
kin->draw_color=ks->draw_color; |
| 399 |
/* we already have valid text/background/draw colors */ |
| 400 |
kin->has.text_color=1; |
| 401 |
kin->has.background_color=1; |
| 402 |
kin->has.draw_color=1; |
| 403 |
|
| 404 |
kin->text_halign=ks->halign; |
| 405 |
kin->text_valign=ks->valign; |
| 406 |
/* we already have internal alignment */ |
| 407 |
kin->has.text_alignment_int=1; |
| 408 |
} |
| 409 |
|
| 410 |
/* if we have no motions, go no further */ |
| 411 |
if (!kin->event->nmotions) return 0; |
| 412 |
|
| 413 |
/* TODO: think about the consequences of this wrt continuations */ |
| 414 |
|
| 415 |
/* alter the flow of time */ |
| 416 |
ret=kate_tracker_update_property(kin,kate_motion_semantics_time,&t,&dummy); |
| 417 |
if (ret==0) { |
| 418 |
/* t should be left within 0-duration */ |
| 419 |
/* clamp, just in case */ |
| 420 |
if (t<0) t=0; |
| 421 |
|
| 422 |
/* jump in time for the remainder of the lookups */ |
| 423 |
kin->t=t; |
| 424 |
} |
| 425 |
|
| 426 |
/* update Z */ |
| 427 |
ret=kate_tracker_update_property(kin,kate_motion_semantics_z,&kin->z,&dummy); |
| 428 |
if (ret==0) kin->has.z=1; |
| 429 |
|
| 430 |
/* update region position */ |
| 431 |
if (kr) { |
| 432 |
ret=kate_tracker_update_property(kin,kate_motion_semantics_region_position,&kin->region_x,&kin->region_y); |
| 433 |
if (ret==0) kin->has.region=1; |
| 434 |
} |
| 435 |
|
| 436 |
/* update region size */ |
| 437 |
if (kr) { |
| 438 |
ret=kate_tracker_update_property(kin,kate_motion_semantics_region_size,&kin->region_w,&kin->region_h); |
| 439 |
if (ret==0) kin->has.region=1; |
| 440 |
} |
| 441 |
|
| 442 |
/* update text visible section */ |
| 443 |
if (kr) { |
| 444 |
ret=kate_tracker_update_property(kin,kate_motion_semantics_text_visible_section,&kin->visible_x,&kin->visible_y); |
| 445 |
if (ret==0) kin->has.visible_section=1; |
| 446 |
} |
| 447 |
|
| 448 |
/* update text path section */ |
| 449 |
km=kate_tracker_find_motion(kin,kate_motion_semantics_text_path); |
| 450 |
if (km) { |
| 451 |
kin->has.path=1; |
| 452 |
kin->path_start=0; |
| 453 |
kin->path_end=1; |
| 454 |
ret=kate_tracker_update_property(kin,kate_motion_semantics_text_path_section,&kin->path_start,&kin->path_end); |
| 455 |
} |
| 456 |
|
| 457 |
/* update style morphing */ |
| 458 |
km=kate_tracker_find_motion(kin,kate_motion_semantics_style_morph); |
| 459 |
if (km) { |
| 460 |
kate_float morphing; |
| 461 |
kate_float duration=kin->event->end_time-kin->event->start_time; |
| 462 |
ret=kate_motion_get_point(km,duration,kin->t,&morphing,&dummy); |
| 463 |
if (ret==0) { |
| 464 |
kate_style style; |
| 465 |
ret=kate_tracker_morph_styles(&style,morphing,ev->style,ev->secondary_style); |
| 466 |
if (ret==0) { |
| 467 |
kin->text_halign=style.halign; |
| 468 |
kin->text_valign=style.valign; |
| 469 |
kin->text_color=style.text_color; |
| 470 |
kin->background_color=style.background_color; |
| 471 |
kin->draw_color=style.draw_color; |
| 472 |
kin->left_margin=style.left_margin; |
| 473 |
kin->top_margin=style.top_margin; |
| 474 |
kin->right_margin=style.right_margin; |
| 475 |
kin->bottom_margin=style.bottom_margin; |
| 476 |
/* we get everything that's in a style here */ |
| 477 |
/* those can be overridden afterwards by an alignment/color/etc motion */ |
| 478 |
kin->has.text_alignment_int=1; |
| 479 |
kin->has.text_color=1; |
| 480 |
kin->has.background_color=1; |
| 481 |
kin->has.draw_color=1; |
| 482 |
kin->has.hmargins=1; |
| 483 |
kin->has.vmargins=1; |
| 484 |
} |
| 485 |
} |
| 486 |
} |
| 487 |
|
| 488 |
/* update margins */ |
| 489 |
ret=kate_tracker_update_property(kin,kate_motion_semantics_horizontal_margins,&kin->left_margin,&kin->right_margin); |
| 490 |
if (ret==0) kin->has.hmargins=1; |
| 491 |
ret=kate_tracker_update_property(kin,kate_motion_semantics_vertical_margins,&kin->top_margin,&kin->bottom_margin); |
| 492 |
if (ret==0) kin->has.vmargins=1; |
| 493 |
|
| 494 |
/* update text alignment */ |
| 495 |
ret=kate_tracker_update_property(kin,kate_motion_semantics_text_alignment_int,&kin->text_halign,&kin->text_valign); |
| 496 |
if (ret==0) kin->has.text_alignment_int=1; |
| 497 |
ret=kate_tracker_update_property(kin,kate_motion_semantics_text_alignment_ext,&kin->text_halign,&kin->text_valign); |
| 498 |
if (ret==0) { |
| 499 |
kin->has.text_alignment_int=0; /* external alignment override internal (the default) */ |
| 500 |
kin->has.text_alignment_ext=1; |
| 501 |
} |
| 502 |
|
| 503 |
/* update bitmap position */ |
| 504 |
ret=kate_tracker_update_property(kin,kate_motion_semantics_bitmap_position,&kin->bitmap_x,&kin->bitmap_y); |
| 505 |
if (ret==0) kin->has.bitmap_pos=1; |
| 506 |
|
| 507 |
/* update bitmap size */ |
| 508 |
ret=kate_tracker_update_property(kin,kate_motion_semantics_bitmap_size,&kin->bitmap_size_x,&kin->bitmap_size_y); |
| 509 |
if (ret==0) kin->has.bitmap_size=1; |
| 510 |
|
| 511 |
/* update text position */ |
| 512 |
ret=kate_tracker_update_property(kin,kate_motion_semantics_text_position,&kin->text_x,&kin->text_y); |
| 513 |
if (ret==0) kin->has.text_pos=1; |
| 514 |
|
| 515 |
/* update text size */ |
| 516 |
ret=kate_tracker_update_property(kin,kate_motion_semantics_text_size,&kin->text_size_x,&kin->text_size_y); |
| 517 |
if (ret==0) kin->has.text_size=1; |
| 518 |
|
| 519 |
/* update glyph pointers */ |
| 520 |
for (n=0;n<4;++n) { |
| 521 |
kate_motion_semantics semantics=(kate_motion_semantics)(kate_motion_semantics_glyph_pointer_1+n); |
| 522 |
ret=kate_tracker_update_property(kin,semantics,&kin->glyph_pointer[n],&kin->glyph_height[n]); |
| 523 |
if (ret==0) { |
| 524 |
kin->has.glyph_pointer|=(1<<n); |
| 525 |
/* we don't have to bother looking for a bitmap frame if there's no glyph pointer */ |
| 526 |
semantics=(kate_motion_semantics)(kate_motion_semantics_glyph_pointer_1_bitmap+n); |
| 527 |
ret=kate_tracker_update_property(kin,semantics,&frame,&dummy); |
| 528 |
if (ret==0) { |
| 529 |
const kate_bitmap *kb=kate_tracker_find_bitmap(kin,frame); |
| 530 |
if (kb) { |
| 531 |
kin->glyph_pointer_bitmap[n]=kb; |
| 532 |
kin->has.glyph_pointer_bitmap|=(1<<n); |
| 533 |
} |
| 534 |
} |
| 535 |
} |
| 536 |
} |
| 537 |
|
| 538 |
/* update marker position */ |
| 539 |
for (n=0;n<4;++n) { |
| 540 |
kate_motion_semantics semantics=(kate_motion_semantics)(kate_motion_semantics_marker1_position+n); |
| 541 |
ret=kate_tracker_update_property(kin,semantics,&kin->marker_x[n],&kin->marker_y[n]); |
| 542 |
if (ret==0) { |
| 543 |
kin->has.marker_pos|=(1<<n); |
| 544 |
/* we don't have to bother looking for a bitmap frame if there's no marker position */ |
| 545 |
semantics=(kate_motion_semantics)(kate_motion_semantics_marker1_bitmap+n); |
| 546 |
ret=kate_tracker_update_property(kin,semantics,&frame,&dummy); |
| 547 |
if (ret==0) { |
| 548 |
const kate_bitmap *kb=kate_tracker_find_bitmap(kin,frame); |
| 549 |
if (kb) { |
| 550 |
kin->marker_bitmap[n]=kb; |
| 551 |
kin->has.marker_bitmap|=(1<<n); |
| 552 |
} |
| 553 |
} |
| 554 |
} |
| 555 |
} |
| 556 |
|
| 557 |
/* update draw position */ |
| 558 |
ret=kate_tracker_update_property(kin,kate_motion_semantics_draw,&kin->draw_x,&kin->draw_y); |
| 559 |
if (ret==0) kin->has.draw=1; |
| 560 |
|
| 561 |
/* update colors */ |
| 562 |
ret=kate_tracker_update_property(kin,kate_motion_semantics_text_color_rg,&r,&g); |
| 563 |
if (ret==0) { |
| 564 |
kin->text_color.r=kate_float_to_color_component(r); |
| 565 |
kin->text_color.g=kate_float_to_color_component(g); |
| 566 |
kin->has.text_color=1; |
| 567 |
} |
| 568 |
ret=kate_tracker_update_property(kin,kate_motion_semantics_text_color_ba,&b,&a); |
| 569 |
if (ret==0) { |
| 570 |
kin->text_color.b=kate_float_to_color_component(b); |
| 571 |
kin->text_color.a=kate_float_to_color_component(a); |
| 572 |
kin->has.text_color=1; |
| 573 |
} |
| 574 |
|
| 575 |
ret=kate_tracker_update_property(kin,kate_motion_semantics_background_color_rg,&r,&g); |
| 576 |
if (ret==0) { |
| 577 |
kin->background_color.r=kate_float_to_color_component(r); |
| 578 |
kin->background_color.g=kate_float_to_color_component(g); |
| 579 |
kin->has.background_color=1; |
| 580 |
} |
| 581 |
ret=kate_tracker_update_property(kin,kate_motion_semantics_background_color_ba,&b,&a); |
| 582 |
if (ret==0) { |
| 583 |
kin->background_color.b=kate_float_to_color_component(b); |
| 584 |
kin->background_color.a=kate_float_to_color_component(a); |
| 585 |
kin->has.background_color=1; |
| 586 |
} |
| 587 |
|
| 588 |
ret=kate_tracker_update_property(kin,kate_motion_semantics_draw_color_rg,&r,&g); |
| 589 |
if (ret==0) { |
| 590 |
kin->draw_color.r=kate_float_to_color_component(r); |
| 591 |
kin->draw_color.g=kate_float_to_color_component(g); |
| 592 |
kin->has.draw_color=1; |
| 593 |
} |
| 594 |
ret=kate_tracker_update_property(kin,kate_motion_semantics_draw_color_ba,&b,&a); |
| 595 |
if (ret==0) { |
| 596 |
kin->draw_color.b=kate_float_to_color_component(b); |
| 597 |
kin->draw_color.a=kate_float_to_color_component(a); |
| 598 |
kin->has.draw_color=1; |
| 599 |
} |
| 600 |
|
| 601 |
/* update draw width */ |
| 602 |
ret=kate_tracker_update_property(kin,kate_motion_semantics_draw_width,&kin->draw_width,&dummy); |
| 603 |
if (ret==0) kin->has.draw_width=1; |
| 604 |
|
| 605 |
return 0; |
| 606 |
} |
| 607 |
|
| 608 |
/** |
| 609 |
\ingroup tracker |
| 610 |
Finds the position of a particular glyph along a path. |
| 611 |
\param kin the tracker to use |
| 612 |
\param glyph the index of the glyph to get the position of |
| 613 |
\param x will return the first coordinate of the position |
| 614 |
\param y will return the second coordinate of the position |
| 615 |
\returns 0 success |
| 616 |
\returns KATE_E_* error |
| 617 |
*/ |
| 618 |
int kate_tracker_get_text_path_position(kate_tracker *kin,size_t glyph,int *x,int *y) |
| 619 |
{ |
| 620 |
kate_float t; |
| 621 |
kate_float dx,dy; |
| 622 |
int ret; |
| 623 |
|
| 624 |
if (!kin || !x || !y) return KATE_E_INVALID_PARAMETER; |
| 625 |
if (glyph>=kin->internal->nglyphs) return KATE_E_INVALID_PARAMETER; |
| 626 |
if (!kin->has.path) return KATE_E_INVALID_PARAMETER; |
| 627 |
|
| 628 |
t=0; |
| 629 |
if (kin->internal->nglyphs>1) { |
| 630 |
t=kin->path_start+glyph*(kin->path_end-kin->path_start)/(kin->internal->nglyphs-1); |
| 631 |
} |
| 632 |
ret=kate_tracker_update_property_at_duration(kin,1,t,kate_motion_semantics_text_path,&dx,&dy); |
| 633 |
if (ret==0) { |
| 634 |
*x=(int)(dx+(kate_float)0.5); |
| 635 |
*y=(int)(dy+(kate_float)0.5); |
| 636 |
} |
| 637 |
|
| 638 |
return ret; |
| 639 |
} |
| 640 |
|