Mercurial > MadButterfly
comparison src/shape_stext.c @ 822:586e50f82c1f
Unify coding style tag for emacs and vim.
author | Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com> |
---|---|
date | Tue, 14 Sep 2010 01:08:39 +0800 |
parents | 5781b2485e38 |
children | a8d20bc8ce40 |
comparison
equal
deleted
inserted
replaced
821:bfdc82bbd6e4 | 822:586e50f82c1f |
---|---|
1 // -*- indent-tabs-mode: t; tab-width: 8; c-basic-offset: 4; -*- | |
2 // vim: sw=4:ts=8:sts=4 | |
1 #include <stdio.h> | 3 #include <stdio.h> |
2 #include <string.h> | 4 #include <string.h> |
3 #include "mb_graph_engine.h" | 5 #include "mb_graph_engine.h" |
4 #include "mb_shapes.h" | 6 #include "mb_shapes.h" |
5 #include "mb_tools.h" | 7 #include "mb_tools.h" |
98 | 100 |
99 /*! \brief Stakeholder of scaled font. | 101 /*! \brief Stakeholder of scaled font. |
100 * | 102 * |
101 * Although, mb_text_extents_t is defined as a mbe_scaled_font_t, but | 103 * Although, mb_text_extents_t is defined as a mbe_scaled_font_t, but |
102 * programmers should assume it is opague. | 104 * programmers should assume it is opague. |
103 * | 105 * |
104 * An extents is the span of showing a fragement of text on the output device. | 106 * An extents is the span of showing a fragement of text on the output device. |
105 * It includes x and y advance of cursor after showinng the text. | 107 * It includes x and y advance of cursor after showinng the text. |
106 * The cursor maybe not really existed. But, the advance is computed as | 108 * The cursor maybe not really existed. But, the advance is computed as |
107 * the cursor existed. It also includes width and height of the text. | 109 * the cursor existed. It also includes width and height of the text. |
108 * The bearing of a styled block is the left-top corner of the bounding box. | 110 * The bearing of a styled block is the left-top corner of the bounding box. |
149 mb_scaled_font_t *make_scaled_font_face_matrix(mb_font_face_t *face, | 151 mb_scaled_font_t *make_scaled_font_face_matrix(mb_font_face_t *face, |
150 co_aix *matrix) { | 152 co_aix *matrix) { |
151 mbe_scaled_font_t *scaled_font; | 153 mbe_scaled_font_t *scaled_font; |
152 static co_aix id[6] = { 1, 0, 0, | 154 static co_aix id[6] = { 1, 0, 0, |
153 0, 1, 0 }; | 155 0, 1, 0 }; |
154 | 156 |
155 ASSERT(matrix != NULL); | 157 ASSERT(matrix != NULL); |
156 | 158 |
157 scaled_font = mbe_scaled_font_create((mbe_font_face_t *)face, | 159 scaled_font = mbe_scaled_font_create((mbe_font_face_t *)face, |
158 matrix, &id); | 160 matrix, &id); |
159 | 161 |
160 return (mb_scaled_font_t *)scaled_font; | 162 return (mb_scaled_font_t *)scaled_font; |
161 } | 163 } |
196 total_tlen = strlen(txt); | 198 total_tlen = strlen(txt); |
197 if(total_tlen > tlen) | 199 if(total_tlen > tlen) |
198 buf = strndup(txt, tlen); | 200 buf = strndup(txt, tlen); |
199 else | 201 else |
200 buf = txt; | 202 buf = txt; |
201 | 203 |
202 saved_scaled = mbe_get_scaled_font(cr); | 204 saved_scaled = mbe_get_scaled_font(cr); |
203 mbe_scaled_font_reference(saved_scaled); | 205 mbe_scaled_font_reference(saved_scaled); |
204 mbe_set_scaled_font(cr, (mbe_scaled_font_t *)scaled); | 206 mbe_set_scaled_font(cr, (mbe_scaled_font_t *)scaled); |
205 | 207 |
206 mbe_move_to(cr, x, y); | 208 mbe_move_to(cr, x, y); |
207 mbe_text_path(cr, buf); | 209 mbe_text_path(cr, buf); |
208 | 210 |
209 mbe_set_scaled_font(cr, saved_scaled); | 211 mbe_set_scaled_font(cr, saved_scaled); |
210 mbe_scaled_font_destroy(saved_scaled); | 212 mbe_scaled_font_destroy(saved_scaled); |
211 | 213 |
212 if(total_tlen > tlen) | 214 if(total_tlen > tlen) |
213 free((char *)buf); | 215 free((char *)buf); |
263 void _rdman_shape_stext_free(shape_t *shape) { | 265 void _rdman_shape_stext_free(shape_t *shape) { |
264 sh_stext_t *txt_o = (sh_stext_t *)shape; | 266 sh_stext_t *txt_o = (sh_stext_t *)shape; |
265 int i; | 267 int i; |
266 | 268 |
267 DARRAY_DESTROY(&txt_o->style_blks); | 269 DARRAY_DESTROY(&txt_o->style_blks); |
268 | 270 |
269 for(i = 0; i < txt_o->scaled_fonts.num; i++) | 271 for(i = 0; i < txt_o->scaled_fonts.num; i++) |
270 scaled_font_free(txt_o->scaled_fonts.ds[i]); | 272 scaled_font_free(txt_o->scaled_fonts.ds[i]); |
271 DARRAY_DESTROY(&txt_o->scaled_fonts); | 273 DARRAY_DESTROY(&txt_o->scaled_fonts); |
272 DARRAY_DESTROY(&txt_o->sub_exts); | 274 DARRAY_DESTROY(&txt_o->sub_exts); |
273 | 275 |
274 if(txt_o->txt) | 276 if(txt_o->txt) |
275 free((void *)txt_o->txt); | 277 free((void *)txt_o->txt); |
276 | 278 |
277 free(txt_o); | 279 free(txt_o); |
278 } | 280 } |
280 shape_t *rdman_shape_stext_new(redraw_man_t *rdman, const char *txt, | 282 shape_t *rdman_shape_stext_new(redraw_man_t *rdman, const char *txt, |
281 co_aix x, co_aix y) { | 283 co_aix x, co_aix y) { |
282 sh_stext_t *txt_o; | 284 sh_stext_t *txt_o; |
283 | 285 |
284 ASSERT(txt != NULL); | 286 ASSERT(txt != NULL); |
285 | 287 |
286 txt_o = (sh_stext_t *)malloc(sizeof(sh_stext_t)); | 288 txt_o = (sh_stext_t *)malloc(sizeof(sh_stext_t)); |
287 if(txt_o == NULL) | 289 if(txt_o == NULL) |
288 return NULL; | 290 return NULL; |
289 | 291 |
290 memset(&txt_o->shape, 0, sizeof(shape_t)); | 292 memset(&txt_o->shape, 0, sizeof(shape_t)); |
291 mb_obj_init(txt_o, MBO_STEXT); | 293 mb_obj_init(txt_o, MBO_STEXT); |
292 | 294 |
293 txt_o->txt = strdup(txt); | 295 txt_o->txt = strdup(txt); |
294 DARRAY_INIT(&txt_o->style_blks); | 296 DARRAY_INIT(&txt_o->style_blks); |
295 txt_o->x = x; | 297 txt_o->x = x; |
296 txt_o->y = y; | 298 txt_o->y = y; |
297 DARRAY_INIT(&txt_o->scaled_fonts); | 299 DARRAY_INIT(&txt_o->scaled_fonts); |
301 free(txt_o); | 303 free(txt_o); |
302 txt_o = NULL; | 304 txt_o = NULL; |
303 } | 305 } |
304 | 306 |
305 txt_o->shape.free = _rdman_shape_stext_free; | 307 txt_o->shape.free = _rdman_shape_stext_free; |
306 | 308 |
307 rdman_shape_man(rdman, (shape_t *)txt_o); | 309 rdman_shape_man(rdman, (shape_t *)txt_o); |
308 | 310 |
309 return (shape_t *)txt_o; | 311 return (shape_t *)txt_o; |
310 } | 312 } |
311 | 313 |
312 static | 314 static |
313 int compute_utf8_chars_sz(const char *txt, int n_chars) { | 315 int compute_utf8_chars_sz(const char *txt, int n_chars) { |
314 int i; | 316 int i; |
315 const char *p = txt; | 317 const char *p = txt; |
316 const char *v; | 318 const char *v; |
317 | 319 |
318 for(i = 0; i < n_chars && *p; i++) { | 320 for(i = 0; i < n_chars && *p; i++) { |
319 if(!(*p & 0x80)) /* single byte */ | 321 if(!(*p & 0x80)) /* single byte */ |
320 p++; | 322 p++; |
321 else if((*p & 0xe0) == 0xc0) /* 2 bytes */ | 323 else if((*p & 0xe0) == 0xc0) /* 2 bytes */ |
322 p += 2; | 324 p += 2; |
331 return ERR; | 333 return ERR; |
332 | 334 |
333 for(v = txt; v != p; v++) | 335 for(v = txt; v != p; v++) |
334 if(*v == '\x0') | 336 if(*v == '\x0') |
335 return ERR; | 337 return ERR; |
336 | 338 |
337 return p - txt; | 339 return p - txt; |
338 } | 340 } |
339 | 341 |
340 static | 342 static |
341 mb_scaled_font_t *make_scaled_font_face(sh_stext_t *txt_o, | 343 mb_scaled_font_t *make_scaled_font_face(sh_stext_t *txt_o, |
349 | 351 |
350 aggr = sh_get_aggr_matrix((shape_t *)txt_o); | 352 aggr = sh_get_aggr_matrix((shape_t *)txt_o); |
351 memcpy(noshift_aggr, aggr, sizeof(co_aix) * 6); | 353 memcpy(noshift_aggr, aggr, sizeof(co_aix) * 6); |
352 noshift_aggr[2] = 0; | 354 noshift_aggr[2] = 0; |
353 noshift_aggr[5] = 0; | 355 noshift_aggr[5] = 0; |
354 | 356 |
355 matrix[0] = font_sz; | 357 matrix[0] = font_sz; |
356 matrix[1] = 0; | 358 matrix[1] = 0; |
357 matrix[2] = shift_x; | 359 matrix[2] = shift_x; |
358 matrix[3] = 0; | 360 matrix[3] = 0; |
359 matrix[4] = font_sz; | 361 matrix[4] = font_sz; |
360 matrix[5] = shift_y; | 362 matrix[5] = shift_y; |
361 matrix_mul(noshift_aggr, matrix, scaled_matrix); | 363 matrix_mul(noshift_aggr, matrix, scaled_matrix); |
362 | 364 |
363 scaled = make_scaled_font_face_matrix(face, scaled_matrix); | 365 scaled = make_scaled_font_face_matrix(face, scaled_matrix); |
364 | 366 |
365 return scaled; | 367 return scaled; |
366 } | 368 } |
367 | 369 |
382 f_rby = MBE_GET_Y_BEARING(full) + MBE_GET_HEIGHT(full); | 384 f_rby = MBE_GET_Y_BEARING(full) + MBE_GET_HEIGHT(full); |
383 s_xbr = MBE_GET_X_BEARING(sub) + MBE_GET_X_ADV(full); | 385 s_xbr = MBE_GET_X_BEARING(sub) + MBE_GET_X_ADV(full); |
384 s_ybr = MBE_GET_Y_BEARING(sub) + MBE_GET_Y_ADV(full); | 386 s_ybr = MBE_GET_Y_BEARING(sub) + MBE_GET_Y_ADV(full); |
385 s_rbx = s_xbr + MBE_GET_WIDTH(sub); | 387 s_rbx = s_xbr + MBE_GET_WIDTH(sub); |
386 s_rby = s_ybr + MBE_GET_HEIGHT(sub); | 388 s_rby = s_ybr + MBE_GET_HEIGHT(sub); |
387 | 389 |
388 /* set bearing */ | 390 /* set bearing */ |
389 if(MBE_GET_X_BEARING(full) > s_xbr) | 391 if(MBE_GET_X_BEARING(full) > s_xbr) |
390 MBE_SET_X_BEARING(full, s_xbr); | 392 MBE_SET_X_BEARING(full, s_xbr); |
391 if(MBE_GET_Y_BEARING(full) > s_ybr) | 393 if(MBE_GET_Y_BEARING(full) > s_ybr) |
392 MBE_SET_Y_BEARING(full, s_ybr); | 394 MBE_SET_Y_BEARING(full, s_ybr); |
393 | 395 |
394 /* set width/height */ | 396 /* set width/height */ |
395 if(f_rbx < s_rbx) | 397 if(f_rbx < s_rbx) |
396 MBE_SET_WIDTH(full, s_rbx - MBE_GET_X_BEARING(full)); | 398 MBE_SET_WIDTH(full, s_rbx - MBE_GET_X_BEARING(full)); |
397 else | 399 else |
398 MBE_SET_WIDTH(full, f_rbx - MBE_GET_X_BEARING(full)); | 400 MBE_SET_WIDTH(full, f_rbx - MBE_GET_X_BEARING(full)); |
433 scaled_fonts_lst_t *scaled_fonts; | 435 scaled_fonts_lst_t *scaled_fonts; |
434 extents_lst_t *sub_exts; | 436 extents_lst_t *sub_exts; |
435 mb_text_extents_t *sub; | 437 mb_text_extents_t *sub; |
436 char *txt, saved; | 438 char *txt, saved; |
437 int i, nscaled; | 439 int i, nscaled; |
438 | 440 |
439 scaled_fonts = &txt_o->scaled_fonts; | 441 scaled_fonts = &txt_o->scaled_fonts; |
440 for(i = 0; i < scaled_fonts->num; i++) | 442 for(i = 0; i < scaled_fonts->num; i++) |
441 scaled_font_free(scaled_fonts->ds[i]); | 443 scaled_font_free(scaled_fonts->ds[i]); |
442 DARRAY_CLEAN(scaled_fonts); | 444 DARRAY_CLEAN(scaled_fonts); |
443 | 445 |
444 style_blks = &txt_o->style_blks; | 446 style_blks = &txt_o->style_blks; |
445 blk = style_blks->ds; | 447 blk = style_blks->ds; |
446 | 448 |
447 sub_exts = &txt_o->sub_exts; | 449 sub_exts = &txt_o->sub_exts; |
448 DARRAY_CLEAN(sub_exts); | 450 DARRAY_CLEAN(sub_exts); |
449 extents_lst_adv(sub_exts, style_blks->num); | 451 extents_lst_adv(sub_exts, style_blks->num); |
450 | 452 |
451 txt = (char *)txt_o->txt; | 453 txt = (char *)txt_o->txt; |
452 for(i = 0; i < style_blks->num; i++) { | 454 for(i = 0; i < style_blks->num; i++) { |
453 scaled = make_scaled_font_face(txt_o, blk->face, | 455 scaled = make_scaled_font_face(txt_o, blk->face, |
454 0, 0, blk->font_sz); | 456 0, 0, blk->font_sz); |
455 ASSERT(scaled != NULL); | 457 ASSERT(scaled != NULL); |
456 scaled_fonts_lst_add(scaled_fonts, scaled); | 458 scaled_fonts_lst_add(scaled_fonts, scaled); |
457 sub = sub_exts->ds + i; | 459 sub = sub_exts->ds + i; |
458 | 460 |
459 blk_txt_len = compute_utf8_chars_sz(txt, blk->n_chars); | 461 blk_txt_len = compute_utf8_chars_sz(txt, blk->n_chars); |
460 ASSERT(blk_txt_len != ERR); | 462 ASSERT(blk_txt_len != ERR); |
461 | 463 |
462 saved = txt[blk_txt_len]; | 464 saved = txt[blk_txt_len]; |
463 txt[blk_txt_len] = 0; | 465 txt[blk_txt_len] = 0; |
464 compute_text_extents(scaled, txt, sub); | 466 compute_text_extents(scaled, txt, sub); |
465 txt[blk_txt_len] = saved; | 467 txt[blk_txt_len] = saved; |
466 | 468 |
467 blk++; | 469 blk++; |
468 txt += blk_txt_len; | 470 txt += blk_txt_len; |
469 } | 471 } |
470 | 472 |
471 if(style_blks->num > 0) { | 473 if(style_blks->num > 0) { |
472 sub = sub_exts->ds; | 474 sub = sub_exts->ds; |
473 memcpy(&txt_o->extents, sub, sizeof(mb_text_extents_t)); | 475 memcpy(&txt_o->extents, sub, sizeof(mb_text_extents_t)); |
474 for(i = 1; i < style_blks->num; i++) { | 476 for(i = 1; i < style_blks->num; i++) { |
475 sub = sub_exts->ds + i; | 477 sub = sub_exts->ds + i; |
476 extent_extents(&txt_o->extents, sub); | 478 extent_extents(&txt_o->extents, sub); |
477 } | 479 } |
478 } else | 480 } else |
479 memset(&txt_o->extents, sizeof(mb_text_extents_t), 0); | 481 memset(&txt_o->extents, sizeof(mb_text_extents_t), 0); |
480 } | 482 } |
481 | 483 |
482 /* | 484 /* |
483 * What we have to do in sh_stext_transform() is | 485 * What we have to do in sh_stext_transform() is |
484 * - computing bounding box for the text, | 486 * - computing bounding box for the text, |
497 co_aix *aggr; | 499 co_aix *aggr; |
498 | 500 |
499 ASSERT(txt_o != NULL); | 501 ASSERT(txt_o != NULL); |
500 | 502 |
501 aggr = sh_get_aggr_matrix(shape); | 503 aggr = sh_get_aggr_matrix(shape); |
502 | 504 |
503 txt_o->dx = txt_o->x; | 505 txt_o->dx = txt_o->x; |
504 txt_o->dy = txt_o->y; | 506 txt_o->dy = txt_o->y; |
505 matrix_trans_pos(aggr, &txt_o->dx, &txt_o->dy); | 507 matrix_trans_pos(aggr, &txt_o->dx, &txt_o->dy); |
506 | 508 |
507 compute_styled_extents_n_scaled_font(txt_o); | 509 compute_styled_extents_n_scaled_font(txt_o); |
508 ext = &txt_o->extents; | 510 ext = &txt_o->extents; |
509 | 511 |
510 area = sh_get_area(shape); | 512 area = sh_get_area(shape); |
511 area->x = MBE_GET_X_BEARING(ext) + txt_o->dx; | 513 area->x = MBE_GET_X_BEARING(ext) + txt_o->dx; |
512 area->y = MBE_GET_Y_BEARING(ext) + txt_o->dy; | 514 area->y = MBE_GET_Y_BEARING(ext) + txt_o->dy; |
513 area->w = MBE_GET_WIDTH(ext); | 515 area->w = MBE_GET_WIDTH(ext); |
514 area->h = MBE_GET_HEIGHT(ext); | 516 area->h = MBE_GET_HEIGHT(ext); |
525 mb_text_extents_t *ext; | 527 mb_text_extents_t *ext; |
526 int blk_txt_len; | 528 int blk_txt_len; |
527 int i; | 529 int i; |
528 | 530 |
529 ASSERT(txt_o != NULL); | 531 ASSERT(txt_o != NULL); |
530 | 532 |
531 x = txt_o->dx; | 533 x = txt_o->dx; |
532 y = txt_o->dy; | 534 y = txt_o->dy; |
533 txt = txt_o->txt; | 535 txt = txt_o->txt; |
534 scaled_fonts = &txt_o->scaled_fonts; | 536 scaled_fonts = &txt_o->scaled_fonts; |
535 style_blks = &txt_o->style_blks; | 537 style_blks = &txt_o->style_blks; |
536 ext = txt_o->sub_exts.ds; | 538 ext = txt_o->sub_exts.ds; |
537 | 539 |
538 for(i = 0; i < scaled_fonts->num; i++) { | 540 for(i = 0; i < scaled_fonts->num; i++) { |
539 scaled = scaled_fonts->ds[i]; | 541 scaled = scaled_fonts->ds[i]; |
540 blk = style_blks->ds + i; | 542 blk = style_blks->ds + i; |
541 blk_txt_len = compute_utf8_chars_sz(txt, blk->n_chars); | 543 blk_txt_len = compute_utf8_chars_sz(txt, blk->n_chars); |
542 draw_text_scaled(cr, txt, blk_txt_len, scaled, x, y); | 544 draw_text_scaled(cr, txt, blk_txt_len, scaled, x, y); |
543 | 545 |
544 x += MBE_GET_X_ADV(ext); | 546 x += MBE_GET_X_ADV(ext); |
545 y += MBE_GET_Y_ADV(ext); | 547 y += MBE_GET_Y_ADV(ext); |
546 txt += blk_txt_len; | 548 txt += blk_txt_len; |
547 } | 549 } |
548 } | 550 } |
552 char *new_txt; | 554 char *new_txt; |
553 int sz; | 555 int sz; |
554 | 556 |
555 ASSERT(txt_o != NULL); | 557 ASSERT(txt_o != NULL); |
556 ASSERT(txt != NULL); | 558 ASSERT(txt != NULL); |
557 | 559 |
558 sz = strlen(txt) + 1; | 560 sz = strlen(txt) + 1; |
559 new_txt = (char *)realloc((void *)txt_o->txt, sz); | 561 new_txt = (char *)realloc((void *)txt_o->txt, sz); |
560 if(new_txt == NULL) | 562 if(new_txt == NULL) |
561 return ERR; | 563 return ERR; |
562 | 564 |
563 memcpy(new_txt, txt, sz); | 565 memcpy(new_txt, txt, sz); |
564 txt_o->txt = new_txt; | 566 txt_o->txt = new_txt; |
565 | 567 |
566 return OK; | 568 return OK; |
567 } | 569 } |
568 | 570 |
569 int sh_stext_set_style(shape_t *shape, | 571 int sh_stext_set_style(shape_t *shape, |
570 const mb_style_blk_t *blks, | 572 const mb_style_blk_t *blks, |
574 mb_style_blk_t *new_blks; | 576 mb_style_blk_t *new_blks; |
575 int sz; | 577 int sz; |
576 | 578 |
577 ASSERT(txt_o != NULL); | 579 ASSERT(txt_o != NULL); |
578 ASSERT(nblks >= 0); | 580 ASSERT(nblks >= 0); |
579 | 581 |
580 style_blks = &txt_o->style_blks; | 582 style_blks = &txt_o->style_blks; |
581 DARRAY_CLEAN(style_blks); | 583 DARRAY_CLEAN(style_blks); |
582 style_blks_lst_adv(style_blks, nblks); | 584 style_blks_lst_adv(style_blks, nblks); |
583 | 585 |
584 memcpy(style_blks->ds, | 586 memcpy(style_blks->ds, |
585 blks, nblks * sizeof(mb_style_blk_t)); | 587 blks, nblks * sizeof(mb_style_blk_t)); |
586 | 588 |
587 return OK; | 589 return OK; |
588 } | 590 } |
589 | 591 |
590 #ifdef UNITTEST | 592 #ifdef UNITTEST |
591 | 593 |
595 void test_query_font_face(void) { | 597 void test_query_font_face(void) { |
596 mb_font_face_t *face; | 598 mb_font_face_t *face; |
597 | 599 |
598 face = query_font_face("serif", MB_FONT_SLANT_ROMAN, 100); | 600 face = query_font_face("serif", MB_FONT_SLANT_ROMAN, 100); |
599 CU_ASSERT(face != NULL); | 601 CU_ASSERT(face != NULL); |
600 | 602 |
601 free_font_face(face); | 603 free_font_face(face); |
602 } | 604 } |
603 | 605 |
604 static | 606 static |
605 void test_make_scaled_font_face_matrix(void) { | 607 void test_make_scaled_font_face_matrix(void) { |
607 mb_font_face_t *face; | 609 mb_font_face_t *face; |
608 mb_scaled_font_t *scaled; | 610 mb_scaled_font_t *scaled; |
609 | 611 |
610 face = query_font_face("serif", MB_FONT_SLANT_ROMAN, 100); | 612 face = query_font_face("serif", MB_FONT_SLANT_ROMAN, 100); |
611 CU_ASSERT(face != NULL); | 613 CU_ASSERT(face != NULL); |
612 | 614 |
613 scaled = make_scaled_font_face_matrix(face, matrix); | 615 scaled = make_scaled_font_face_matrix(face, matrix); |
614 CU_ASSERT(scaled != NULL); | 616 CU_ASSERT(scaled != NULL); |
615 | 617 |
616 scaled_font_free(scaled); | 618 scaled_font_free(scaled); |
617 free_font_face(face); | 619 free_font_face(face); |
618 } | 620 } |
619 | 621 |
620 static | 622 static |
663 MBE_SET_HEIGHT(&ext1, 10); | 665 MBE_SET_HEIGHT(&ext1, 10); |
664 MBE_SET_X_BEARING(&ext1, 1); | 666 MBE_SET_X_BEARING(&ext1, 1); |
665 MBE_SET_Y_BEARING(&ext1, -8); | 667 MBE_SET_Y_BEARING(&ext1, -8); |
666 MBE_SET_X_ADV(&ext1, 21); | 668 MBE_SET_X_ADV(&ext1, 21); |
667 MBE_SET_Y_ADV(&ext1, -3); | 669 MBE_SET_Y_ADV(&ext1, -3); |
668 | 670 |
669 MBE_SET_WIDTH(&ext2, 30); | 671 MBE_SET_WIDTH(&ext2, 30); |
670 MBE_SET_HEIGHT(&ext2, 11); | 672 MBE_SET_HEIGHT(&ext2, 11); |
671 MBE_SET_X_BEARING(&ext2, 2); | 673 MBE_SET_X_BEARING(&ext2, 2); |
672 MBE_SET_Y_BEARING(&ext2, -11); | 674 MBE_SET_Y_BEARING(&ext2, -11); |
673 MBE_SET_X_ADV(&ext2, 32); | 675 MBE_SET_X_ADV(&ext2, 32); |
674 MBE_SET_Y_ADV(&ext2, -5); | 676 MBE_SET_Y_ADV(&ext2, -5); |
675 | 677 |
676 extent_extents(&ext1, &ext2); | 678 extent_extents(&ext1, &ext2); |
677 | 679 |
678 CU_ASSERT(MBE_GET_WIDTH(&ext1) == 52); | 680 CU_ASSERT(MBE_GET_WIDTH(&ext1) == 52); |
679 CU_ASSERT(MBE_GET_HEIGHT(&ext1) == 16); | 681 CU_ASSERT(MBE_GET_HEIGHT(&ext1) == 16); |
680 CU_ASSERT(MBE_GET_X_BEARING(&ext1) == 1); | 682 CU_ASSERT(MBE_GET_X_BEARING(&ext1) == 1); |
685 | 687 |
686 static | 688 static |
687 void test_compute_utf8_chars_sz(void) { | 689 void test_compute_utf8_chars_sz(void) { |
688 const char *str = "\xe4\xb8\xad\xe6\x96\x87test\xe6\xb8\xac\xe8\xa9\xa6"; | 690 const char *str = "\xe4\xb8\xad\xe6\x96\x87test\xe6\xb8\xac\xe8\xa9\xa6"; |
689 int sz; | 691 int sz; |
690 | 692 |
691 sz = compute_utf8_chars_sz(str, 4); | 693 sz = compute_utf8_chars_sz(str, 4); |
692 CU_ASSERT(sz == 8); | 694 CU_ASSERT(sz == 8); |
693 | 695 |
694 sz = compute_utf8_chars_sz(str, 9); | 696 sz = compute_utf8_chars_sz(str, 9); |
695 CU_ASSERT(sz == ERR); | 697 CU_ASSERT(sz == ERR); |
716 aggr[4] = 1; | 718 aggr[4] = 1; |
717 aggr[5] = 0; | 719 aggr[5] = 0; |
718 | 720 |
719 face = query_font_face("serif", MB_FONT_SLANT_ROMAN, 100); | 721 face = query_font_face("serif", MB_FONT_SLANT_ROMAN, 100); |
720 CU_ASSERT(face != NULL); | 722 CU_ASSERT(face != NULL); |
721 | 723 |
722 blks[0].n_chars = 5; | 724 blks[0].n_chars = 5; |
723 blks[0].face = face; | 725 blks[0].face = face; |
724 blks[0].font_sz = 10; | 726 blks[0].font_sz = 10; |
725 | 727 |
726 blks[1].n_chars = 4; | 728 blks[1].n_chars = 4; |
727 blks[1].face = face; | 729 blks[1].face = face; |
728 blks[1].font_sz = 15.5; | 730 blks[1].font_sz = 15.5; |
729 | 731 |
730 r = sh_stext_set_style((shape_t *)txt_o, blks, 2); | 732 r = sh_stext_set_style((shape_t *)txt_o, blks, 2); |
731 CU_ASSERT(r == OK); | 733 CU_ASSERT(r == OK); |
732 | 734 |
733 compute_styled_extents_n_scaled_font(txt_o); | 735 compute_styled_extents_n_scaled_font(txt_o); |
734 | 736 |
738 CU_ASSERT(MBE_GET_WIDTH(ext) > 36); | 740 CU_ASSERT(MBE_GET_WIDTH(ext) > 36); |
739 CU_ASSERT(MBE_GET_WIDTH(ext) < 72); | 741 CU_ASSERT(MBE_GET_WIDTH(ext) < 72); |
740 CU_ASSERT(MBE_GET_X_ADV(ext) > 36); | 742 CU_ASSERT(MBE_GET_X_ADV(ext) > 36); |
741 CU_ASSERT(MBE_GET_X_ADV(ext) < 72); | 743 CU_ASSERT(MBE_GET_X_ADV(ext) < 72); |
742 CU_ASSERT(MBE_GET_Y_ADV(ext) == 0); | 744 CU_ASSERT(MBE_GET_Y_ADV(ext) == 0); |
743 | 745 |
744 _rdman_shape_stext_free((shape_t *)txt_o); | 746 _rdman_shape_stext_free((shape_t *)txt_o); |
745 free_font_face(face); | 747 free_font_face(face); |
746 } | 748 } |
747 | 749 |
748 static | 750 static |
766 aggr[4] = 1; | 768 aggr[4] = 1; |
767 aggr[5] = 0; | 769 aggr[5] = 0; |
768 | 770 |
769 face = query_font_face("serif", MB_FONT_SLANT_ROMAN, 100); | 771 face = query_font_face("serif", MB_FONT_SLANT_ROMAN, 100); |
770 CU_ASSERT(face != NULL); | 772 CU_ASSERT(face != NULL); |
771 | 773 |
772 blks[0].n_chars = 5; | 774 blks[0].n_chars = 5; |
773 blks[0].face = face; | 775 blks[0].face = face; |
774 blks[0].font_sz = 10; | 776 blks[0].font_sz = 10; |
775 | 777 |
776 blks[1].n_chars = 4; | 778 blks[1].n_chars = 4; |
777 blks[1].face = face; | 779 blks[1].face = face; |
778 blks[1].font_sz = 15.5; | 780 blks[1].font_sz = 15.5; |
779 | 781 |
780 r = sh_stext_set_style((shape_t *)txt_o, blks, 2); | 782 r = sh_stext_set_style((shape_t *)txt_o, blks, 2); |
781 CU_ASSERT(r == OK); | 783 CU_ASSERT(r == OK); |
782 | 784 |
783 compute_styled_extents_n_scaled_font(txt_o); | 785 compute_styled_extents_n_scaled_font(txt_o); |
784 | 786 |
789 CU_ASSERT(MBE_GET_WIDTH(ext) < 72); | 791 CU_ASSERT(MBE_GET_WIDTH(ext) < 72); |
790 CU_ASSERT(MBE_GET_X_ADV(ext) > 36); | 792 CU_ASSERT(MBE_GET_X_ADV(ext) > 36); |
791 CU_ASSERT(MBE_GET_X_ADV(ext) < 72); | 793 CU_ASSERT(MBE_GET_X_ADV(ext) < 72); |
792 CU_ASSERT(MBE_GET_Y_ADV(ext) > 36); | 794 CU_ASSERT(MBE_GET_Y_ADV(ext) > 36); |
793 CU_ASSERT(MBE_GET_Y_ADV(ext) < 72); | 795 CU_ASSERT(MBE_GET_Y_ADV(ext) < 72); |
794 | 796 |
795 _rdman_shape_stext_free((shape_t *)txt_o); | 797 _rdman_shape_stext_free((shape_t *)txt_o); |
796 free_font_face(face); | 798 free_font_face(face); |
797 } | 799 } |
798 | 800 |
799 static | 801 static |
816 aggr[4] = 1; | 818 aggr[4] = 1; |
817 aggr[5] = 0; | 819 aggr[5] = 0; |
818 | 820 |
819 face = query_font_face("serif", MB_FONT_SLANT_ROMAN, 100); | 821 face = query_font_face("serif", MB_FONT_SLANT_ROMAN, 100); |
820 CU_ASSERT(face != NULL); | 822 CU_ASSERT(face != NULL); |
821 | 823 |
822 blks[0].n_chars = 5; | 824 blks[0].n_chars = 5; |
823 blks[0].face = face; | 825 blks[0].face = face; |
824 blks[0].font_sz = 10; | 826 blks[0].font_sz = 10; |
825 | 827 |
826 blks[1].n_chars = 4; | 828 blks[1].n_chars = 4; |
827 blks[1].face = face; | 829 blks[1].face = face; |
828 blks[1].font_sz = 15.5; | 830 blks[1].font_sz = 15.5; |
829 | 831 |
830 r = sh_stext_set_style((shape_t *)txt_o, blks, 2); | 832 r = sh_stext_set_style((shape_t *)txt_o, blks, 2); |
831 CU_ASSERT(r == OK); | 833 CU_ASSERT(r == OK); |
832 | 834 |
833 sh_stext_transform((shape_t *)txt_o); | 835 sh_stext_transform((shape_t *)txt_o); |
834 | 836 |
835 area = sh_get_area((shape_t *)txt_o); | 837 area = sh_get_area((shape_t *)txt_o); |
836 CU_ASSERT(area->x >= 200 && area->x < 220); | 838 CU_ASSERT(area->x >= 200 && area->x < 220); |
837 CU_ASSERT(area->y >= 40 && area->y < 50); | 839 CU_ASSERT(area->y >= 40 && area->y < 50); |
838 CU_ASSERT(area->w >= 80 && area->w < 120); | 840 CU_ASSERT(area->w >= 80 && area->w < 120); |
839 CU_ASSERT(area->h >= 8 && area->h < 12); | 841 CU_ASSERT(area->h >= 8 && area->h < 12); |
840 | 842 |
841 _rdman_shape_stext_free((shape_t *)txt_o); | 843 _rdman_shape_stext_free((shape_t *)txt_o); |
842 free_font_face(face); | 844 free_font_face(face); |
843 } | 845 } |
844 | 846 |
845 static | 847 static |
851 area_t *area; | 853 area_t *area; |
852 int r; | 854 int r; |
853 | 855 |
854 txt_o = (sh_stext_t *)rdman_shape_stext_new(NULL, "hello world", 100, 50); | 856 txt_o = (sh_stext_t *)rdman_shape_stext_new(NULL, "hello world", 100, 50); |
855 CU_ASSERT(txt_o != NULL); | 857 CU_ASSERT(txt_o != NULL); |
856 | 858 |
857 aggr = txt_o->shape.aggr; | 859 aggr = txt_o->shape.aggr; |
858 aggr[0] = 2; | 860 aggr[0] = 2; |
859 aggr[1] = 0; | 861 aggr[1] = 0; |
860 aggr[2] = 0; | 862 aggr[2] = 0; |
861 aggr[3] = 0; | 863 aggr[3] = 0; |
862 aggr[4] = 1; | 864 aggr[4] = 1; |
863 aggr[5] = 0; | 865 aggr[5] = 0; |
864 | 866 |
865 face = query_font_face("serif", MB_FONT_SLANT_ROMAN, 100); | 867 face = query_font_face("serif", MB_FONT_SLANT_ROMAN, 100); |
866 CU_ASSERT(face != NULL); | 868 CU_ASSERT(face != NULL); |
867 | 869 |
868 blks[0].n_chars = 5; | 870 blks[0].n_chars = 5; |
869 blks[0].face = face; | 871 blks[0].face = face; |
870 blks[0].font_sz = 10; | 872 blks[0].font_sz = 10; |
871 | 873 |
872 blks[1].n_chars = 6; | 874 blks[1].n_chars = 6; |
873 blks[1].face = face; | 875 blks[1].face = face; |
874 blks[1].font_sz = 15.5; | 876 blks[1].font_sz = 15.5; |
875 | 877 |
876 r = sh_stext_set_style((shape_t *)txt_o, blks, 2); | 878 r = sh_stext_set_style((shape_t *)txt_o, blks, 2); |
877 CU_ASSERT(r == OK); | 879 CU_ASSERT(r == OK); |
878 | 880 |
879 sh_stext_transform((shape_t *)txt_o); | 881 sh_stext_transform((shape_t *)txt_o); |
880 | 882 |
899 area_t *area; | 901 area_t *area; |
900 int r; | 902 int r; |
901 | 903 |
902 txt_o = (sh_stext_t *)rdman_shape_stext_new(NULL, "hello world", 100, 50); | 904 txt_o = (sh_stext_t *)rdman_shape_stext_new(NULL, "hello world", 100, 50); |
903 CU_ASSERT(txt_o != NULL); | 905 CU_ASSERT(txt_o != NULL); |
904 | 906 |
905 aggr = txt_o->shape.aggr; | 907 aggr = txt_o->shape.aggr; |
906 aggr[0] = 2; | 908 aggr[0] = 2; |
907 aggr[1] = 0; | 909 aggr[1] = 0; |
908 aggr[2] = 0; | 910 aggr[2] = 0; |
909 aggr[3] = 1; | 911 aggr[3] = 1; |
910 aggr[4] = 1; | 912 aggr[4] = 1; |
911 aggr[5] = 0; | 913 aggr[5] = 0; |
912 | 914 |
913 face = query_font_face("serif", MB_FONT_SLANT_ROMAN, 100); | 915 face = query_font_face("serif", MB_FONT_SLANT_ROMAN, 100); |
914 CU_ASSERT(face != NULL); | 916 CU_ASSERT(face != NULL); |
915 | 917 |
916 blks[0].n_chars = 5; | 918 blks[0].n_chars = 5; |
917 blks[0].face = face; | 919 blks[0].face = face; |
918 blks[0].font_sz = 10; | 920 blks[0].font_sz = 10; |
919 | 921 |
920 blks[1].n_chars = 6; | 922 blks[1].n_chars = 6; |
921 blks[1].face = face; | 923 blks[1].face = face; |
922 blks[1].font_sz = 15.5; | 924 blks[1].font_sz = 15.5; |
923 | 925 |
924 r = sh_stext_set_style((shape_t *)txt_o, blks, 2); | 926 r = sh_stext_set_style((shape_t *)txt_o, blks, 2); |
925 CU_ASSERT(r == OK); | 927 CU_ASSERT(r == OK); |
926 | 928 |
927 sh_stext_transform((shape_t *)txt_o); | 929 sh_stext_transform((shape_t *)txt_o); |
928 | 930 |