comparison src/shape_path.c @ 9:6eecdd331fe7

Fix bug in testcase
author Thinker K.F. Li <thinker@branda.to>
date Sat, 26 Jul 2008 04:27:52 +0800
parents 94b4b5bd8810
children 7cfecdce94cc
comparison
equal deleted inserted replaced
8:94b4b5bd8810 9:6eecdd331fe7
315 } 315 }
316 316
317 return OK; 317 return OK;
318 } 318 }
319 319
320 /*! \brief Create a path from value of 'data' of SVG path.
321 */
320 shape_t *sh_path_new(char *data) { 322 shape_t *sh_path_new(char *data) {
321 sh_path_t *path; 323 sh_path_t *path;
322 int cmd_cnt, arg_cnt; 324 int cmd_cnt, arg_cnt;
323 int r; 325 int r;
324 326
360 memcpy(path->dev_data, path->user_data, cmd_cnt); 362 memcpy(path->dev_data, path->user_data, cmd_cnt);
361 363
362 return (shape_t *)path; 364 return (shape_t *)path;
363 } 365 }
364 366
367 /*! \brief Transform a path from user space to device space.
368 *
369 * TODO: associate coord_t with shape objects and transform them
370 * automatically.
371 */
365 void sh_path_transform(shape_t *shape, coord_t *coord) { 372 void sh_path_transform(shape_t *shape, coord_t *coord) {
366 sh_path_t *path; 373 sh_path_t *path;
367 co_aix *user_args, *dev_args; 374 co_aix *user_args, *dev_args;
368 int i; 375 int i;
369 376
512 sh_path_t *path; 519 sh_path_t *path;
513 co_aix *args; 520 co_aix *args;
514 521
515 path = (sh_path_t *)sh_path_new("M 33 25l33 55C 33 87 44 22 55 99L33 77z"); 522 path = (sh_path_t *)sh_path_new("M 33 25l33 55C 33 87 44 22 55 99L33 77z");
516 CU_ASSERT(path != NULL); 523 CU_ASSERT(path != NULL);
517 CU_ASSERT(path->cmd_len == 8); 524 CU_ASSERT(path->cmd_len == ((5 + sizeof(co_aix) * 2 + 3) & ~0x3));
518 CU_ASSERT(path->arg_len == 12); 525 CU_ASSERT(path->arg_len == 12);
519 CU_ASSERT(strcmp(path->user_data, "MlCLz") == 0); 526 CU_ASSERT(strcmp(path->user_data, "MLCLZ") == 0);
520 CU_ASSERT(strcmp(path->dev_data, "MlCLz") == 0); 527 CU_ASSERT(strcmp(path->dev_data, "MLCLZ") == 0);
521 528
522 args = (co_aix *)(path->user_data + path->cmd_len); 529 args = (co_aix *)(path->user_data + path->cmd_len);
523 CU_ASSERT(args[0] == 33); 530 CU_ASSERT(args[0] == 33);
524 CU_ASSERT(args[1] == 25); 531 CU_ASSERT(args[1] == 25);
525 CU_ASSERT(args[2] == 33); 532 CU_ASSERT(args[2] == 66);
526 CU_ASSERT(args[3] == 55); 533 CU_ASSERT(args[3] == 80);
527 CU_ASSERT(args[4] == 33); 534 CU_ASSERT(args[4] == 33);
528 CU_ASSERT(args[5] == 87); 535 CU_ASSERT(args[5] == 87);
529 CU_ASSERT(args[6] == 44); 536 CU_ASSERT(args[6] == 44);
530 CU_ASSERT(args[7] == 22); 537 CU_ASSERT(args[7] == 22);
531 CU_ASSERT(args[8] == 55); 538 CU_ASSERT(args[8] == 55);
540 co_aix *args; 547 co_aix *args;
541 coord_t coord; 548 coord_t coord;
542 549
543 path = (sh_path_t *)sh_path_new("M 33 25l33 55C 33 87 44 22 55 99L33 77z"); 550 path = (sh_path_t *)sh_path_new("M 33 25l33 55C 33 87 44 22 55 99L33 77z");
544 CU_ASSERT(path != NULL); 551 CU_ASSERT(path != NULL);
545 CU_ASSERT(path->cmd_len == 8); 552 CU_ASSERT(path->cmd_len == ((5 + sizeof(co_aix) * 2 + 3) & ~0x3));
546 CU_ASSERT(path->arg_len == 12); 553 CU_ASSERT(path->arg_len == 12);
547 CU_ASSERT(strcmp(path->user_data, "MlCLz") == 0); 554 CU_ASSERT(strcmp(path->user_data, "MLCLZ") == 0);
548 CU_ASSERT(strcmp(path->dev_data, "MlCLz") == 0); 555 CU_ASSERT(strcmp(path->dev_data, "MLCLZ") == 0);
549 556
550 coord.aggr_matrix[0] = 1; 557 coord.aggr_matrix[0] = 1;
551 coord.aggr_matrix[1] = 0; 558 coord.aggr_matrix[1] = 0;
552 coord.aggr_matrix[2] = 1; 559 coord.aggr_matrix[2] = 1;
553 coord.aggr_matrix[3] = 0; 560 coord.aggr_matrix[3] = 0;
556 sh_path_transform((shape_t *)path, &coord); 563 sh_path_transform((shape_t *)path, &coord);
557 564
558 args = (co_aix *)(path->dev_data + path->cmd_len); 565 args = (co_aix *)(path->dev_data + path->cmd_len);
559 CU_ASSERT(args[0] == 34); 566 CU_ASSERT(args[0] == 34);
560 CU_ASSERT(args[1] == 50); 567 CU_ASSERT(args[1] == 50);
561 CU_ASSERT(args[2] == 34); 568 CU_ASSERT(args[2] == 67);
562 CU_ASSERT(args[3] == 110); 569 CU_ASSERT(args[3] == 160);
563 CU_ASSERT(args[4] == 34); 570 CU_ASSERT(args[4] == 34);
564 CU_ASSERT(args[5] == 174); 571 CU_ASSERT(args[5] == 174);
565 CU_ASSERT(args[6] == 45); 572 CU_ASSERT(args[6] == 45);
566 CU_ASSERT(args[7] == 44); 573 CU_ASSERT(args[7] == 44);
567 CU_ASSERT(args[8] == 56); 574 CU_ASSERT(args[8] == 56);