comparison src/shape_stext.c @ 414:bbf036c315be

Fix extent_extents to make it pass the test case.
author Thinker K.F. Li <thinker@branda.to>
date Sun, 26 Jul 2009 15:31:40 +0800
parents 35712e4bad0e
children fef1b8076041
comparison
equal deleted inserted replaced
413:35712e4bad0e 414:bbf036c315be
350 */ 350 */
351 static 351 static
352 void extent_extents(mb_text_extents_t *full, mb_text_extents_t *sub) { 352 void extent_extents(mb_text_extents_t *full, mb_text_extents_t *sub) {
353 co_aix f_rbx, f_rby; /* rb stands for right button */ 353 co_aix f_rbx, f_rby; /* rb stands for right button */
354 co_aix s_rbx, s_rby; 354 co_aix s_rbx, s_rby;
355 co_aix s_xbr, s_ybr;
356 co_aix new_x_adv, new_y_adv;
355 357
356 f_rbx = MBE_GET_X_BEARING(full) + MBE_GET_WIDTH(full); 358 f_rbx = MBE_GET_X_BEARING(full) + MBE_GET_WIDTH(full);
357 f_rby = MBE_GET_Y_BEARING(full) + MBE_GET_HEIGHT(full); 359 f_rby = MBE_GET_Y_BEARING(full) + MBE_GET_HEIGHT(full);
358 s_rbx = MBE_GET_X_BEARING(sub) + MBE_GET_WIDTH(sub); 360 s_xbr = MBE_GET_X_BEARING(sub) + MBE_GET_X_ADV(full);
359 s_rby = MBE_GET_Y_BEARING(sub) + MBE_GET_HEIGHT(sub); 361 s_ybr = MBE_GET_Y_BEARING(sub) + MBE_GET_Y_ADV(full);
362 s_rbx = s_xbr + MBE_GET_WIDTH(sub);
363 s_rby = s_ybr + MBE_GET_HEIGHT(sub);
360 364
361 /* set bearing */ 365 /* set bearing */
362 if(MBE_GET_X_BEARING(full) > MBE_GET_X_BEARING(sub)) 366 if(MBE_GET_X_BEARING(full) > s_xbr)
363 MBE_SET_X_BEARING(full, MBE_GET_X_BEARING(sub)); 367 MBE_SET_X_BEARING(full, s_xbr);
364 if(MBE_GET_Y_BEARING(full) > MBE_GET_Y_BEARING(sub)) 368 if(MBE_GET_Y_BEARING(full) > s_ybr)
365 MBE_SET_Y_BEARING(full, MBE_GET_Y_BEARING(sub)); 369 MBE_SET_Y_BEARING(full, s_ybr);
366 370
367 /* set width/height */ 371 /* set width/height */
368 if(f_rbx < s_rbx) 372 if(f_rbx < s_rbx)
369 MBE_SET_WIDTH(full, s_rbx - MBE_GET_X_BEARING(full)); 373 MBE_SET_WIDTH(full, s_rbx - MBE_GET_X_BEARING(full));
374 else
375 MBE_SET_WIDTH(full, f_rbx - MBE_GET_X_BEARING(full));
370 if(f_rby < s_rby) 376 if(f_rby < s_rby)
371 MBE_SET_HEIGHT(full, s_rby - MBE_GET_Y_BEARING(full)); 377 MBE_SET_HEIGHT(full, s_rby - MBE_GET_Y_BEARING(full));
378 else
379 MBE_SET_HEIGHT(full, f_rby - MBE_GET_Y_BEARING(full));
380
381 /* set x/y advance */
382 new_x_adv = MBE_GET_X_ADV(full) + MBE_GET_X_ADV(sub);
383 new_y_adv = MBE_GET_Y_ADV(full) + MBE_GET_Y_ADV(sub);
384 MBE_SET_X_ADV(full, new_x_adv);
385 MBE_SET_Y_ADV(full, new_y_adv);
372 } 386 }
373 387
374 /*! \brief Compute extents of a stext object according style blocks. 388 /*! \brief Compute extents of a stext object according style blocks.
375 * 389 *
376 * It create scaled fonts for style blocks, compute their extents, 390 * It create scaled fonts for style blocks, compute their extents,
530 CU_ASSERT(face != NULL) 544 CU_ASSERT(face != NULL)
531 scaled = make_scaled_font_face_matrix(face, matrix); 545 scaled = make_scaled_font_face_matrix(face, matrix);
532 CU_ASSERT(scaled != NULL); 546 CU_ASSERT(scaled != NULL);
533 547
534 compute_text_extents(scaled, "test", &ext); 548 compute_text_extents(scaled, "test", &ext);
535 CU_ASSERT(ext.height >= 5 && ext.height <= 12); 549 CU_ASSERT(MBE_GET_HEIGHT(&ext) >= 5 && MBE_GET_HEIGHT(&ext) <= 12);
536 CU_ASSERT(ext.width >= 16 && ext.width <= 48); 550 CU_ASSERT(MBE_GET_WIDTH(&ext) >= 16 && MBE_GET_WIDTH(&ext) <= 48);
537 551
538 scaled_font_free(scaled); 552 scaled_font_free(scaled);
539 free_font_face(face); 553 free_font_face(face);
554 }
555
556 static
557 void test_extent_extents(void) {
558 mb_text_extents_t ext1, ext2;
559
560 MBE_SET_WIDTH(&ext1, 20);
561 MBE_SET_HEIGHT(&ext1, 10);
562 MBE_SET_X_BEARING(&ext1, 1);
563 MBE_SET_Y_BEARING(&ext1, -8);
564 MBE_SET_X_ADV(&ext1, 21);
565 MBE_SET_Y_ADV(&ext1, -3);
566
567 MBE_SET_WIDTH(&ext2, 30);
568 MBE_SET_HEIGHT(&ext2, 11);
569 MBE_SET_X_BEARING(&ext2, 2);
570 MBE_SET_Y_BEARING(&ext2, -11);
571 MBE_SET_X_ADV(&ext2, 32);
572 MBE_SET_Y_ADV(&ext2, -5);
573
574 extent_extents(&ext1, &ext2);
575
576 CU_ASSERT(MBE_GET_WIDTH(&ext1) == 52);
577 CU_ASSERT(MBE_GET_HEIGHT(&ext1) == 16);
578 CU_ASSERT(MBE_GET_X_BEARING(&ext1) == 1);
579 CU_ASSERT(MBE_GET_Y_BEARING(&ext1) == -14);
580 CU_ASSERT(MBE_GET_X_ADV(&ext1) == 53);
581 CU_ASSERT(MBE_GET_Y_ADV(&ext1) == -8);
540 } 582 }
541 583
542 #include <CUnit/Basic.h> 584 #include <CUnit/Basic.h>
543 CU_pSuite get_stext_suite(void) { 585 CU_pSuite get_stext_suite(void) {
544 CU_pSuite suite; 586 CU_pSuite suite;
545 587
546 suite = CU_add_suite("Suite_stext", NULL, NULL); 588 suite = CU_add_suite("Suite_stext", NULL, NULL);
547 CU_ADD_TEST(suite, test_query_font_face); 589 CU_ADD_TEST(suite, test_query_font_face);
548 CU_ADD_TEST(suite, test_make_scaled_font_face_matrix); 590 CU_ADD_TEST(suite, test_make_scaled_font_face_matrix);
549 CU_ADD_TEST(suite, test_compute_text_extents); 591 CU_ADD_TEST(suite, test_compute_text_extents);
550 CU_ADD_TEST(suite, test_compute_text_extents); 592 CU_ADD_TEST(suite, test_extent_extents);
551 593
552 return suite; 594 return suite;
553 } 595 }
554 596
555 #endif /* UNITTEST */ 597 #endif /* UNITTEST */