Mercurial > MadButterfly
annotate src/shape_stext.c @ 1399:9cebe429508c
Override the clone_from_subtree to setup the parent and children for the coord object. However, the current children is incorrect since we can not copy it from the origin tree. Instead, we need to get coord_t from the cloned group and then modify all coord objects to include correct parent, children, add_shape and clone_from_subtree.
author | wycc |
---|---|
date | Sun, 03 Apr 2011 11:51:39 +0800 |
parents | bae104d8d247 |
children |
rev | line source |
---|---|
822
586e50f82c1f
Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents:
760
diff
changeset
|
1 // -*- indent-tabs-mode: t; tab-width: 8; c-basic-offset: 4; -*- |
586e50f82c1f
Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents:
760
diff
changeset
|
2 // vim: sw=4:ts=8:sts=4 |
393
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
3 #include <stdio.h> |
475
744c64eb3182
Since cairo-ft.h is not used, removes it.
Thinker K.F. Li <thinker@branda.to>
parents:
473
diff
changeset
|
4 #include <string.h> |
448
16116d84bc5e
Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents:
447
diff
changeset
|
5 #include "mb_graph_engine.h" |
393
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
6 #include "mb_shapes.h" |
422
c6c0d017dc8e
Use DARRAY to manage variable length list
Thinker K.F. Li <thinker@branda.to>
parents:
421
diff
changeset
|
7 #include "mb_tools.h" |
393
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
8 |
421
1e48453bb282
Make compute_styled_extents_n_scaled_font() pass the test.
Thinker K.F. Li <thinker@branda.to>
parents:
420
diff
changeset
|
9 #ifdef UNITTEST |
425
09a66063b25d
Fix issue of missed function for unittest.
Thinker K.F. Li <thinker@branda.to>
parents:
424
diff
changeset
|
10 |
427
8f900da42eed
Make sh_text_draw() passes first test case.
Thinker K.F. Li <thinker@branda.to>
parents:
426
diff
changeset
|
11 #define NO_DOX(x) x |
425
09a66063b25d
Fix issue of missed function for unittest.
Thinker K.F. Li <thinker@branda.to>
parents:
424
diff
changeset
|
12 #define UT_FAKE(r, x, param) \ |
09a66063b25d
Fix issue of missed function for unittest.
Thinker K.F. Li <thinker@branda.to>
parents:
424
diff
changeset
|
13 r x param {} |
09a66063b25d
Fix issue of missed function for unittest.
Thinker K.F. Li <thinker@branda.to>
parents:
424
diff
changeset
|
14 |
09a66063b25d
Fix issue of missed function for unittest.
Thinker K.F. Li <thinker@branda.to>
parents:
424
diff
changeset
|
15 UT_FAKE(void, sh_stext_transform, (shape_t *shape)); |
448
16116d84bc5e
Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents:
447
diff
changeset
|
16 UT_FAKE(void, sh_stext_draw, (shape_t *shape, mbe_t *cr)); |
425
09a66063b25d
Fix issue of missed function for unittest.
Thinker K.F. Li <thinker@branda.to>
parents:
424
diff
changeset
|
17 |
424
585baa462778
Make sh_stext_transform() pass first test case for him.
Thinker K.F. Li <thinker@branda.to>
parents:
423
diff
changeset
|
18 typedef struct _ut_area { |
585baa462778
Make sh_stext_transform() pass first test case for him.
Thinker K.F. Li <thinker@branda.to>
parents:
423
diff
changeset
|
19 co_aix x, y; |
585baa462778
Make sh_stext_transform() pass first test case for him.
Thinker K.F. Li <thinker@branda.to>
parents:
423
diff
changeset
|
20 co_aix w, h; |
585baa462778
Make sh_stext_transform() pass first test case for him.
Thinker K.F. Li <thinker@branda.to>
parents:
423
diff
changeset
|
21 } ut_area_t; |
585baa462778
Make sh_stext_transform() pass first test case for him.
Thinker K.F. Li <thinker@branda.to>
parents:
423
diff
changeset
|
22 #define area_t ut_area_t |
585baa462778
Make sh_stext_transform() pass first test case for him.
Thinker K.F. Li <thinker@branda.to>
parents:
423
diff
changeset
|
23 |
421
1e48453bb282
Make compute_styled_extents_n_scaled_font() pass the test.
Thinker K.F. Li <thinker@branda.to>
parents:
420
diff
changeset
|
24 typedef struct _ut_shape { |
1e48453bb282
Make compute_styled_extents_n_scaled_font() pass the test.
Thinker K.F. Li <thinker@branda.to>
parents:
420
diff
changeset
|
25 co_aix aggr[6]; |
1e48453bb282
Make compute_styled_extents_n_scaled_font() pass the test.
Thinker K.F. Li <thinker@branda.to>
parents:
420
diff
changeset
|
26 void (*free)(struct _ut_shape *); |
424
585baa462778
Make sh_stext_transform() pass first test case for him.
Thinker K.F. Li <thinker@branda.to>
parents:
423
diff
changeset
|
27 ut_area_t area; |
421
1e48453bb282
Make compute_styled_extents_n_scaled_font() pass the test.
Thinker K.F. Li <thinker@branda.to>
parents:
420
diff
changeset
|
28 } ut_shape_t; |
1e48453bb282
Make compute_styled_extents_n_scaled_font() pass the test.
Thinker K.F. Li <thinker@branda.to>
parents:
420
diff
changeset
|
29 #define shape_t ut_shape_t |
1e48453bb282
Make compute_styled_extents_n_scaled_font() pass the test.
Thinker K.F. Li <thinker@branda.to>
parents:
420
diff
changeset
|
30 |
1e48453bb282
Make compute_styled_extents_n_scaled_font() pass the test.
Thinker K.F. Li <thinker@branda.to>
parents:
420
diff
changeset
|
31 #undef sh_get_aggr_matrix |
1e48453bb282
Make compute_styled_extents_n_scaled_font() pass the test.
Thinker K.F. Li <thinker@branda.to>
parents:
420
diff
changeset
|
32 #define sh_get_aggr_matrix(sh) (sh)->aggr |
1e48453bb282
Make compute_styled_extents_n_scaled_font() pass the test.
Thinker K.F. Li <thinker@branda.to>
parents:
420
diff
changeset
|
33 |
424
585baa462778
Make sh_stext_transform() pass first test case for him.
Thinker K.F. Li <thinker@branda.to>
parents:
423
diff
changeset
|
34 #undef sh_get_area |
585baa462778
Make sh_stext_transform() pass first test case for him.
Thinker K.F. Li <thinker@branda.to>
parents:
423
diff
changeset
|
35 #define sh_get_area(sh) (&(sh)->area) |
585baa462778
Make sh_stext_transform() pass first test case for him.
Thinker K.F. Li <thinker@branda.to>
parents:
423
diff
changeset
|
36 |
421
1e48453bb282
Make compute_styled_extents_n_scaled_font() pass the test.
Thinker K.F. Li <thinker@branda.to>
parents:
420
diff
changeset
|
37 #undef mb_obj_init |
1e48453bb282
Make compute_styled_extents_n_scaled_font() pass the test.
Thinker K.F. Li <thinker@branda.to>
parents:
420
diff
changeset
|
38 #define mb_obj_init(o, t) |
1062
a8d20bc8ce40
Rename rdman_shape_man() to rdman_man_shape() to mean managing a shape
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
39 #undef rdman_man_shape |
a8d20bc8ce40
Rename rdman_shape_man() to rdman_man_shape() to mean managing a shape
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
40 #define rdman_man_shape(rdman, sh) |
421
1e48453bb282
Make compute_styled_extents_n_scaled_font() pass the test.
Thinker K.F. Li <thinker@branda.to>
parents:
420
diff
changeset
|
41 |
1e48453bb282
Make compute_styled_extents_n_scaled_font() pass the test.
Thinker K.F. Li <thinker@branda.to>
parents:
420
diff
changeset
|
42 #define rdman_shape_stext_new ut_rdman_shape_stext_new |
1e48453bb282
Make compute_styled_extents_n_scaled_font() pass the test.
Thinker K.F. Li <thinker@branda.to>
parents:
420
diff
changeset
|
43 #define sh_stext_transform ut_sh_stext_transform |
1e48453bb282
Make compute_styled_extents_n_scaled_font() pass the test.
Thinker K.F. Li <thinker@branda.to>
parents:
420
diff
changeset
|
44 #define sh_stext_draw ut_sh_stext_draw |
1e48453bb282
Make compute_styled_extents_n_scaled_font() pass the test.
Thinker K.F. Li <thinker@branda.to>
parents:
420
diff
changeset
|
45 #define sh_stext_set_text ut_sh_stext_set_text |
1e48453bb282
Make compute_styled_extents_n_scaled_font() pass the test.
Thinker K.F. Li <thinker@branda.to>
parents:
420
diff
changeset
|
46 #define sh_stext_set_style ut_sh_stext_set_style |
1e48453bb282
Make compute_styled_extents_n_scaled_font() pass the test.
Thinker K.F. Li <thinker@branda.to>
parents:
420
diff
changeset
|
47 |
448
16116d84bc5e
Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents:
447
diff
changeset
|
48 #undef mbe_get_scaled_font |
16116d84bc5e
Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents:
447
diff
changeset
|
49 #define mbe_get_scaled_font(cr) ((mbe_scaled_font_t *)NULL) |
16116d84bc5e
Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents:
447
diff
changeset
|
50 #undef mbe_set_scaled_font |
16116d84bc5e
Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents:
447
diff
changeset
|
51 #define mbe_set_scaled_font(cr, scaled) ((mbe_scaled_font_t *)NULL) |
16116d84bc5e
Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents:
447
diff
changeset
|
52 #undef mbe_scaled_font_reference |
16116d84bc5e
Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents:
447
diff
changeset
|
53 #define mbe_scaled_font_reference(x) |
427
8f900da42eed
Make sh_text_draw() passes first test case.
Thinker K.F. Li <thinker@branda.to>
parents:
426
diff
changeset
|
54 #define MAX_MOVE 32 |
8f900da42eed
Make sh_text_draw() passes first test case.
Thinker K.F. Li <thinker@branda.to>
parents:
426
diff
changeset
|
55 NO_DOX(static co_aix move_xys[MAX_MOVE][2]); |
8f900da42eed
Make sh_text_draw() passes first test case.
Thinker K.F. Li <thinker@branda.to>
parents:
426
diff
changeset
|
56 NO_DOX(static int move_cnt = 0); |
448
16116d84bc5e
Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents:
447
diff
changeset
|
57 #undef mbe_move_to |
16116d84bc5e
Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents:
447
diff
changeset
|
58 #define mbe_move_to(cr, x, y) \ |
427
8f900da42eed
Make sh_text_draw() passes first test case.
Thinker K.F. Li <thinker@branda.to>
parents:
426
diff
changeset
|
59 do { \ |
8f900da42eed
Make sh_text_draw() passes first test case.
Thinker K.F. Li <thinker@branda.to>
parents:
426
diff
changeset
|
60 move_xys[move_cnt][0] = x; \ |
8f900da42eed
Make sh_text_draw() passes first test case.
Thinker K.F. Li <thinker@branda.to>
parents:
426
diff
changeset
|
61 move_xys[move_cnt++][1] = y; \ |
8f900da42eed
Make sh_text_draw() passes first test case.
Thinker K.F. Li <thinker@branda.to>
parents:
426
diff
changeset
|
62 } while(0) |
448
16116d84bc5e
Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents:
447
diff
changeset
|
63 #undef mbe_scaled_font_destroy |
16116d84bc5e
Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents:
447
diff
changeset
|
64 #define mbe_scaled_font_destroy(scaled) |
16116d84bc5e
Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents:
447
diff
changeset
|
65 #undef mbe_text_path |
16116d84bc5e
Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents:
447
diff
changeset
|
66 #define mbe_text_path(cr, buf) |
427
8f900da42eed
Make sh_text_draw() passes first test case.
Thinker K.F. Li <thinker@branda.to>
parents:
426
diff
changeset
|
67 |
421
1e48453bb282
Make compute_styled_extents_n_scaled_font() pass the test.
Thinker K.F. Li <thinker@branda.to>
parents:
420
diff
changeset
|
68 #endif /* UNITTEST */ |
1e48453bb282
Make compute_styled_extents_n_scaled_font() pass the test.
Thinker K.F. Li <thinker@branda.to>
parents:
420
diff
changeset
|
69 |
393
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
70 #ifndef ASSERT |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
71 #define ASSERT(x) |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
72 #endif |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
73 #define OK 0 |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
74 #define ERR -1 |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
75 |
407 | 76 /*! \page stext Simple Text |
77 * | |
78 * A sh_stext_t is broken into fragments. Each fragment comprises the text | |
79 * and the styles applied on the fragement. The styles determines font face | |
80 * used to show the text. The fragment of text with styles is called | |
81 * styled block. | |
82 */ | |
83 | |
396
7fe0b1ee92b6
Add extents supporting into Fontconfig and FreeType Layer
Thinker K.F. Li <thinker@branda.to>
parents:
395
diff
changeset
|
84 /*! \defgroup fontconfig_freetype Fontconfig and FreeType Layer. |
7fe0b1ee92b6
Add extents supporting into Fontconfig and FreeType Layer
Thinker K.F. Li <thinker@branda.to>
parents:
395
diff
changeset
|
85 * |
411 | 86 * This layer implements a font provider to rest of the system. |
396
7fe0b1ee92b6
Add extents supporting into Fontconfig and FreeType Layer
Thinker K.F. Li <thinker@branda.to>
parents:
395
diff
changeset
|
87 * It bases on fontconfig and FreeType supporting of Cairo. |
411 | 88 * If you want to provide stext with technologies other than fontconfig and |
89 * FreeType, just replace this layer with the implmenetation that you want. | |
396
7fe0b1ee92b6
Add extents supporting into Fontconfig and FreeType Layer
Thinker K.F. Li <thinker@branda.to>
parents:
395
diff
changeset
|
90 * |
7fe0b1ee92b6
Add extents supporting into Fontconfig and FreeType Layer
Thinker K.F. Li <thinker@branda.to>
parents:
395
diff
changeset
|
91 * @{ |
7fe0b1ee92b6
Add extents supporting into Fontconfig and FreeType Layer
Thinker K.F. Li <thinker@branda.to>
parents:
395
diff
changeset
|
92 */ |
7fe0b1ee92b6
Add extents supporting into Fontconfig and FreeType Layer
Thinker K.F. Li <thinker@branda.to>
parents:
395
diff
changeset
|
93 /*! \brief Stakeholder of scaled font. |
7fe0b1ee92b6
Add extents supporting into Fontconfig and FreeType Layer
Thinker K.F. Li <thinker@branda.to>
parents:
395
diff
changeset
|
94 * |
448
16116d84bc5e
Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents:
447
diff
changeset
|
95 * It is actually a mbe_scaled_font_t, now. But, it should not be |
396
7fe0b1ee92b6
Add extents supporting into Fontconfig and FreeType Layer
Thinker K.F. Li <thinker@branda.to>
parents:
395
diff
changeset
|
96 * noticed by out-siders. Only \ref fontconfig_freetype |
7fe0b1ee92b6
Add extents supporting into Fontconfig and FreeType Layer
Thinker K.F. Li <thinker@branda.to>
parents:
395
diff
changeset
|
97 * should known it. |
7fe0b1ee92b6
Add extents supporting into Fontconfig and FreeType Layer
Thinker K.F. Li <thinker@branda.to>
parents:
395
diff
changeset
|
98 */ |
7fe0b1ee92b6
Add extents supporting into Fontconfig and FreeType Layer
Thinker K.F. Li <thinker@branda.to>
parents:
395
diff
changeset
|
99 typedef struct _mb_scaled_font mb_scaled_font_t; |
7fe0b1ee92b6
Add extents supporting into Fontconfig and FreeType Layer
Thinker K.F. Li <thinker@branda.to>
parents:
395
diff
changeset
|
100 |
7fe0b1ee92b6
Add extents supporting into Fontconfig and FreeType Layer
Thinker K.F. Li <thinker@branda.to>
parents:
395
diff
changeset
|
101 /*! \brief Stakeholder of scaled font. |
7fe0b1ee92b6
Add extents supporting into Fontconfig and FreeType Layer
Thinker K.F. Li <thinker@branda.to>
parents:
395
diff
changeset
|
102 * |
448
16116d84bc5e
Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents:
447
diff
changeset
|
103 * Although, mb_text_extents_t is defined as a mbe_scaled_font_t, but |
396
7fe0b1ee92b6
Add extents supporting into Fontconfig and FreeType Layer
Thinker K.F. Li <thinker@branda.to>
parents:
395
diff
changeset
|
104 * programmers should assume it is opague. |
822
586e50f82c1f
Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents:
760
diff
changeset
|
105 * |
407 | 106 * An extents is the span of showing a fragement of text on the output device. |
107 * It includes x and y advance of cursor after showinng the text. | |
108 * The cursor maybe not really existed. But, the advance is computed as | |
109 * the cursor existed. It also includes width and height of the text. | |
110 * The bearing of a styled block is the left-top corner of the bounding box. | |
111 * The bounding box of a styled block is the minimal rectangle, on the | |
112 * output device, that can contain the text. The bearing is related to | |
113 * the base line for an extents. | |
396
7fe0b1ee92b6
Add extents supporting into Fontconfig and FreeType Layer
Thinker K.F. Li <thinker@branda.to>
parents:
395
diff
changeset
|
114 */ |
448
16116d84bc5e
Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents:
447
diff
changeset
|
115 typedef mbe_text_extents_t mb_text_extents_t; |
396
7fe0b1ee92b6
Add extents supporting into Fontconfig and FreeType Layer
Thinker K.F. Li <thinker@branda.to>
parents:
395
diff
changeset
|
116 |
7fe0b1ee92b6
Add extents supporting into Fontconfig and FreeType Layer
Thinker K.F. Li <thinker@branda.to>
parents:
395
diff
changeset
|
117 #define MBE_GET_X_ADV(ext) ((ext)->x_advance) |
7fe0b1ee92b6
Add extents supporting into Fontconfig and FreeType Layer
Thinker K.F. Li <thinker@branda.to>
parents:
395
diff
changeset
|
118 #define MBE_GET_Y_ADV(ext) ((ext)->y_advance) |
397
55f38c2cdb8f
Refactor function of computing text extents
Thinker K.F. Li <thinker@branda.to>
parents:
396
diff
changeset
|
119 #define MBE_GET_X_BEARING(ext) ((ext)->x_bearing) |
55f38c2cdb8f
Refactor function of computing text extents
Thinker K.F. Li <thinker@branda.to>
parents:
396
diff
changeset
|
120 #define MBE_GET_Y_BEARING(ext) ((ext)->y_bearing) |
396
7fe0b1ee92b6
Add extents supporting into Fontconfig and FreeType Layer
Thinker K.F. Li <thinker@branda.to>
parents:
395
diff
changeset
|
121 #define MBE_GET_WIDTH(ext) ((ext)->width) |
7fe0b1ee92b6
Add extents supporting into Fontconfig and FreeType Layer
Thinker K.F. Li <thinker@branda.to>
parents:
395
diff
changeset
|
122 #define MBE_GET_HEIGHT(ext) ((ext)->height) |
403
aee0f66b1154
Compute extents of a styled text
Thinker K.F. Li <thinker@branda.to>
parents:
397
diff
changeset
|
123 #define MBE_SET_X_ADV(ext, v) do { ((ext)->x_advance) = v; } while(0) |
aee0f66b1154
Compute extents of a styled text
Thinker K.F. Li <thinker@branda.to>
parents:
397
diff
changeset
|
124 #define MBE_SET_Y_ADV(ext, v) do { ((ext)->y_advance) = v; } while(0) |
aee0f66b1154
Compute extents of a styled text
Thinker K.F. Li <thinker@branda.to>
parents:
397
diff
changeset
|
125 #define MBE_SET_X_BEARING(ext, v) do { ((ext)->x_bearing) = v; } while(0) |
aee0f66b1154
Compute extents of a styled text
Thinker K.F. Li <thinker@branda.to>
parents:
397
diff
changeset
|
126 #define MBE_SET_Y_BEARING(ext, v) do { ((ext)->y_bearing) = v; } while(0) |
aee0f66b1154
Compute extents of a styled text
Thinker K.F. Li <thinker@branda.to>
parents:
397
diff
changeset
|
127 #define MBE_SET_WIDTH(ext, v) do { ((ext)->width) = v; } while(0) |
aee0f66b1154
Compute extents of a styled text
Thinker K.F. Li <thinker@branda.to>
parents:
397
diff
changeset
|
128 #define MBE_SET_HEIGHT(ext, v) do { ((ext)->height) = v; } while(0) |
396
7fe0b1ee92b6
Add extents supporting into Fontconfig and FreeType Layer
Thinker K.F. Li <thinker@branda.to>
parents:
395
diff
changeset
|
129 |
465
d8181696b689
Move functions into graphic engine layers.
Thinker K.F. Li <thinker@branda.to>
parents:
450
diff
changeset
|
130 static mb_font_face_t * |
d8181696b689
Move functions into graphic engine layers.
Thinker K.F. Li <thinker@branda.to>
parents:
450
diff
changeset
|
131 query_font_face(const char *family, int slant, int weight) { |
d8181696b689
Move functions into graphic engine layers.
Thinker K.F. Li <thinker@branda.to>
parents:
450
diff
changeset
|
132 return (mb_font_face_t *)mbe_query_font_face(family, slant, weight); |
394
b3d5ce48670a
Use fontconfig to find out a font for a family/slant/weight pattern
Thinker K.F. Li <thinker@branda.to>
parents:
393
diff
changeset
|
133 } |
b3d5ce48670a
Use fontconfig to find out a font for a family/slant/weight pattern
Thinker K.F. Li <thinker@branda.to>
parents:
393
diff
changeset
|
134 |
465
d8181696b689
Move functions into graphic engine layers.
Thinker K.F. Li <thinker@branda.to>
parents:
450
diff
changeset
|
135 static void |
d8181696b689
Move functions into graphic engine layers.
Thinker K.F. Li <thinker@branda.to>
parents:
450
diff
changeset
|
136 free_font_face(mb_font_face_t *face) { |
396
7fe0b1ee92b6
Add extents supporting into Fontconfig and FreeType Layer
Thinker K.F. Li <thinker@branda.to>
parents:
395
diff
changeset
|
137 ASSERT(face == NULL); |
395 | 138 |
465
d8181696b689
Move functions into graphic engine layers.
Thinker K.F. Li <thinker@branda.to>
parents:
450
diff
changeset
|
139 mbe_free_font_face((mbe_font_face_t *)face); |
395 | 140 } |
141 | |
142 /*! \brief This is scaled font for specified size and extent. | |
143 * | |
144 * Font face only specified which font would be used to draw text | |
145 * message. But, it also need to scale glyphs to specified size and | |
146 * rotation. This function return a scaled font specified by a | |
147 * matrix that transform glyph from design space of the font to | |
148 * user space of cairo surface. | |
149 */ | |
150 static | |
397
55f38c2cdb8f
Refactor function of computing text extents
Thinker K.F. Li <thinker@branda.to>
parents:
396
diff
changeset
|
151 mb_scaled_font_t *make_scaled_font_face_matrix(mb_font_face_t *face, |
55f38c2cdb8f
Refactor function of computing text extents
Thinker K.F. Li <thinker@branda.to>
parents:
396
diff
changeset
|
152 co_aix *matrix) { |
448
16116d84bc5e
Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents:
447
diff
changeset
|
153 mbe_scaled_font_t *scaled_font; |
473
ba64f928542b
Remove mbe_matrix_t type.
Thinker K.F. Li <thinker@branda.to>
parents:
470
diff
changeset
|
154 static co_aix id[6] = { 1, 0, 0, |
ba64f928542b
Remove mbe_matrix_t type.
Thinker K.F. Li <thinker@branda.to>
parents:
470
diff
changeset
|
155 0, 1, 0 }; |
822
586e50f82c1f
Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents:
760
diff
changeset
|
156 |
395 | 157 ASSERT(matrix != NULL); |
822
586e50f82c1f
Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents:
760
diff
changeset
|
158 |
448
16116d84bc5e
Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents:
447
diff
changeset
|
159 scaled_font = mbe_scaled_font_create((mbe_font_face_t *)face, |
1370
bae104d8d247
Add clone functions for shape types
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
160 matrix, id); |
395 | 161 |
396
7fe0b1ee92b6
Add extents supporting into Fontconfig and FreeType Layer
Thinker K.F. Li <thinker@branda.to>
parents:
395
diff
changeset
|
162 return (mb_scaled_font_t *)scaled_font; |
7fe0b1ee92b6
Add extents supporting into Fontconfig and FreeType Layer
Thinker K.F. Li <thinker@branda.to>
parents:
395
diff
changeset
|
163 } |
7fe0b1ee92b6
Add extents supporting into Fontconfig and FreeType Layer
Thinker K.F. Li <thinker@branda.to>
parents:
395
diff
changeset
|
164 |
7fe0b1ee92b6
Add extents supporting into Fontconfig and FreeType Layer
Thinker K.F. Li <thinker@branda.to>
parents:
395
diff
changeset
|
165 static |
397
55f38c2cdb8f
Refactor function of computing text extents
Thinker K.F. Li <thinker@branda.to>
parents:
396
diff
changeset
|
166 void scaled_font_free(mb_scaled_font_t *scaled_font) { |
448
16116d84bc5e
Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents:
447
diff
changeset
|
167 mbe_scaled_font_destroy((mbe_scaled_font_t *)scaled_font); |
395 | 168 } |
169 | |
170 static | |
397
55f38c2cdb8f
Refactor function of computing text extents
Thinker K.F. Li <thinker@branda.to>
parents:
396
diff
changeset
|
171 void compute_text_extents(mb_scaled_font_t *scaled_font, const char *txt, |
55f38c2cdb8f
Refactor function of computing text extents
Thinker K.F. Li <thinker@branda.to>
parents:
396
diff
changeset
|
172 mb_text_extents_t *extents) { |
448
16116d84bc5e
Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents:
447
diff
changeset
|
173 mbe_scaled_font_text_extents((mbe_scaled_font_t *)scaled_font, |
396
7fe0b1ee92b6
Add extents supporting into Fontconfig and FreeType Layer
Thinker K.F. Li <thinker@branda.to>
parents:
395
diff
changeset
|
174 txt, |
448
16116d84bc5e
Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents:
447
diff
changeset
|
175 (mbe_text_extents_t *)extents); |
395 | 176 } |
177 | |
396
7fe0b1ee92b6
Add extents supporting into Fontconfig and FreeType Layer
Thinker K.F. Li <thinker@branda.to>
parents:
395
diff
changeset
|
178 static |
7fe0b1ee92b6
Add extents supporting into Fontconfig and FreeType Layer
Thinker K.F. Li <thinker@branda.to>
parents:
395
diff
changeset
|
179 mb_text_extents_t *mb_text_extents_new(void) { |
448
16116d84bc5e
Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents:
447
diff
changeset
|
180 mbe_text_extents_t *extents; |
396
7fe0b1ee92b6
Add extents supporting into Fontconfig and FreeType Layer
Thinker K.F. Li <thinker@branda.to>
parents:
395
diff
changeset
|
181 |
448
16116d84bc5e
Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents:
447
diff
changeset
|
182 extents = (mbe_text_extents_t *)malloc(sizeof(mbe_text_extents_t)); |
396
7fe0b1ee92b6
Add extents supporting into Fontconfig and FreeType Layer
Thinker K.F. Li <thinker@branda.to>
parents:
395
diff
changeset
|
183 return extents; |
7fe0b1ee92b6
Add extents supporting into Fontconfig and FreeType Layer
Thinker K.F. Li <thinker@branda.to>
parents:
395
diff
changeset
|
184 } |
7fe0b1ee92b6
Add extents supporting into Fontconfig and FreeType Layer
Thinker K.F. Li <thinker@branda.to>
parents:
395
diff
changeset
|
185 |
7fe0b1ee92b6
Add extents supporting into Fontconfig and FreeType Layer
Thinker K.F. Li <thinker@branda.to>
parents:
395
diff
changeset
|
186 static |
7fe0b1ee92b6
Add extents supporting into Fontconfig and FreeType Layer
Thinker K.F. Li <thinker@branda.to>
parents:
395
diff
changeset
|
187 void mb_text_extents_free(mb_text_extents_t *extents) { |
7fe0b1ee92b6
Add extents supporting into Fontconfig and FreeType Layer
Thinker K.F. Li <thinker@branda.to>
parents:
395
diff
changeset
|
188 free(extents); |
7fe0b1ee92b6
Add extents supporting into Fontconfig and FreeType Layer
Thinker K.F. Li <thinker@branda.to>
parents:
395
diff
changeset
|
189 } |
7fe0b1ee92b6
Add extents supporting into Fontconfig and FreeType Layer
Thinker K.F. Li <thinker@branda.to>
parents:
395
diff
changeset
|
190 |
427
8f900da42eed
Make sh_text_draw() passes first test case.
Thinker K.F. Li <thinker@branda.to>
parents:
426
diff
changeset
|
191 static |
448
16116d84bc5e
Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents:
447
diff
changeset
|
192 void draw_text_scaled(mbe_t *cr, const char *txt, int tlen, |
427
8f900da42eed
Make sh_text_draw() passes first test case.
Thinker K.F. Li <thinker@branda.to>
parents:
426
diff
changeset
|
193 mb_scaled_font_t *scaled, co_aix x, co_aix y) { |
448
16116d84bc5e
Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents:
447
diff
changeset
|
194 mbe_scaled_font_t *saved_scaled; |
427
8f900da42eed
Make sh_text_draw() passes first test case.
Thinker K.F. Li <thinker@branda.to>
parents:
426
diff
changeset
|
195 int total_tlen; |
8f900da42eed
Make sh_text_draw() passes first test case.
Thinker K.F. Li <thinker@branda.to>
parents:
426
diff
changeset
|
196 const char *buf; |
8f900da42eed
Make sh_text_draw() passes first test case.
Thinker K.F. Li <thinker@branda.to>
parents:
426
diff
changeset
|
197 |
8f900da42eed
Make sh_text_draw() passes first test case.
Thinker K.F. Li <thinker@branda.to>
parents:
426
diff
changeset
|
198 total_tlen = strlen(txt); |
8f900da42eed
Make sh_text_draw() passes first test case.
Thinker K.F. Li <thinker@branda.to>
parents:
426
diff
changeset
|
199 if(total_tlen > tlen) |
8f900da42eed
Make sh_text_draw() passes first test case.
Thinker K.F. Li <thinker@branda.to>
parents:
426
diff
changeset
|
200 buf = strndup(txt, tlen); |
8f900da42eed
Make sh_text_draw() passes first test case.
Thinker K.F. Li <thinker@branda.to>
parents:
426
diff
changeset
|
201 else |
8f900da42eed
Make sh_text_draw() passes first test case.
Thinker K.F. Li <thinker@branda.to>
parents:
426
diff
changeset
|
202 buf = txt; |
822
586e50f82c1f
Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents:
760
diff
changeset
|
203 |
448
16116d84bc5e
Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents:
447
diff
changeset
|
204 saved_scaled = mbe_get_scaled_font(cr); |
16116d84bc5e
Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents:
447
diff
changeset
|
205 mbe_scaled_font_reference(saved_scaled); |
16116d84bc5e
Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents:
447
diff
changeset
|
206 mbe_set_scaled_font(cr, (mbe_scaled_font_t *)scaled); |
822
586e50f82c1f
Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents:
760
diff
changeset
|
207 |
448
16116d84bc5e
Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents:
447
diff
changeset
|
208 mbe_move_to(cr, x, y); |
16116d84bc5e
Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents:
447
diff
changeset
|
209 mbe_text_path(cr, buf); |
822
586e50f82c1f
Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents:
760
diff
changeset
|
210 |
448
16116d84bc5e
Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents:
447
diff
changeset
|
211 mbe_set_scaled_font(cr, saved_scaled); |
16116d84bc5e
Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents:
447
diff
changeset
|
212 mbe_scaled_font_destroy(saved_scaled); |
427
8f900da42eed
Make sh_text_draw() passes first test case.
Thinker K.F. Li <thinker@branda.to>
parents:
426
diff
changeset
|
213 |
8f900da42eed
Make sh_text_draw() passes first test case.
Thinker K.F. Li <thinker@branda.to>
parents:
426
diff
changeset
|
214 if(total_tlen > tlen) |
8f900da42eed
Make sh_text_draw() passes first test case.
Thinker K.F. Li <thinker@branda.to>
parents:
426
diff
changeset
|
215 free((char *)buf); |
8f900da42eed
Make sh_text_draw() passes first test case.
Thinker K.F. Li <thinker@branda.to>
parents:
426
diff
changeset
|
216 } |
8f900da42eed
Make sh_text_draw() passes first test case.
Thinker K.F. Li <thinker@branda.to>
parents:
426
diff
changeset
|
217 |
396
7fe0b1ee92b6
Add extents supporting into Fontconfig and FreeType Layer
Thinker K.F. Li <thinker@branda.to>
parents:
395
diff
changeset
|
218 /* @} */ |
395 | 219 |
393
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
220 /*! \brief Query and return a font face for a specified attribute vector. |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
221 * |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
222 * Programmers use mb_font_face_t to specify fonts used to show a |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
223 * block of text on the output device. They can get mb_font_face_t with |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
224 * this function. The objects return by mb_font_face_query() should be |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
225 * freed with mb_font_face_free() when they are not more used. |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
226 * |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
227 * \param family is the name of a font family (times). |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
228 * \param slant is one of \ref MB_FONT_SLANTS. |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
229 * \param weight decides if a font is thin or heavy. |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
230 */ |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
231 mb_font_face_t *mb_font_face_query(redraw_man_t *rdman, |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
232 const char *family, |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
233 int slant, |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
234 int weight) { |
396
7fe0b1ee92b6
Add extents supporting into Fontconfig and FreeType Layer
Thinker K.F. Li <thinker@branda.to>
parents:
395
diff
changeset
|
235 return query_font_face(family, slant, weight); |
393
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
236 } |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
237 |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
238 void mb_font_face_free(mb_font_face_t *face) { |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
239 ASSERT(face != NULL); |
396
7fe0b1ee92b6
Add extents supporting into Fontconfig and FreeType Layer
Thinker K.F. Li <thinker@branda.to>
parents:
395
diff
changeset
|
240 free_font_face(face); |
393
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
241 } |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
242 |
422
c6c0d017dc8e
Use DARRAY to manage variable length list
Thinker K.F. Li <thinker@branda.to>
parents:
421
diff
changeset
|
243 DARRAY(scaled_fonts_lst, mb_scaled_font_t *); |
c6c0d017dc8e
Use DARRAY to manage variable length list
Thinker K.F. Li <thinker@branda.to>
parents:
421
diff
changeset
|
244 DARRAY_DEFINE(scaled_fonts_lst, mb_scaled_font_t *); |
c6c0d017dc8e
Use DARRAY to manage variable length list
Thinker K.F. Li <thinker@branda.to>
parents:
421
diff
changeset
|
245 DARRAY(style_blks_lst, mb_style_blk_t); |
c6c0d017dc8e
Use DARRAY to manage variable length list
Thinker K.F. Li <thinker@branda.to>
parents:
421
diff
changeset
|
246 DARRAY_DEFINE_ADV(style_blks_lst, mb_style_blk_t); |
426
aa320386072c
Keep sub-extents for style blocks.
Thinker K.F. Li <thinker@branda.to>
parents:
425
diff
changeset
|
247 DARRAY(extents_lst, mb_text_extents_t); |
aa320386072c
Keep sub-extents for style blocks.
Thinker K.F. Li <thinker@branda.to>
parents:
425
diff
changeset
|
248 DARRAY_DEFINE_ADV(extents_lst, mb_text_extents_t); |
422
c6c0d017dc8e
Use DARRAY to manage variable length list
Thinker K.F. Li <thinker@branda.to>
parents:
421
diff
changeset
|
249 |
393
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
250 /*! \brief A simple implementation of text shape. |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
251 * |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
252 */ |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
253 typedef struct _sh_stext { |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
254 shape_t shape; |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
255 const char *txt; /*!< \brief Text to be showed */ |
422
c6c0d017dc8e
Use DARRAY to manage variable length list
Thinker K.F. Li <thinker@branda.to>
parents:
421
diff
changeset
|
256 style_blks_lst_t style_blks; |
393
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
257 co_aix x, y; |
424
585baa462778
Make sh_stext_transform() pass first test case for him.
Thinker K.F. Li <thinker@branda.to>
parents:
423
diff
changeset
|
258 co_aix dx, dy; |
422
c6c0d017dc8e
Use DARRAY to manage variable length list
Thinker K.F. Li <thinker@branda.to>
parents:
421
diff
changeset
|
259 scaled_fonts_lst_t scaled_fonts; |
403
aee0f66b1154
Compute extents of a styled text
Thinker K.F. Li <thinker@branda.to>
parents:
397
diff
changeset
|
260 mb_text_extents_t extents; |
426
aa320386072c
Keep sub-extents for style blocks.
Thinker K.F. Li <thinker@branda.to>
parents:
425
diff
changeset
|
261 extents_lst_t sub_exts; |
393
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
262 } sh_stext_t; |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
263 |
419
7c921fda21be
Set free function for sh_stext.
Thinker K.F. Li <thinker@branda.to>
parents:
418
diff
changeset
|
264 static |
7c921fda21be
Set free function for sh_stext.
Thinker K.F. Li <thinker@branda.to>
parents:
418
diff
changeset
|
265 void _rdman_shape_stext_free(shape_t *shape) { |
7c921fda21be
Set free function for sh_stext.
Thinker K.F. Li <thinker@branda.to>
parents:
418
diff
changeset
|
266 sh_stext_t *txt_o = (sh_stext_t *)shape; |
7c921fda21be
Set free function for sh_stext.
Thinker K.F. Li <thinker@branda.to>
parents:
418
diff
changeset
|
267 int i; |
7c921fda21be
Set free function for sh_stext.
Thinker K.F. Li <thinker@branda.to>
parents:
418
diff
changeset
|
268 |
422
c6c0d017dc8e
Use DARRAY to manage variable length list
Thinker K.F. Li <thinker@branda.to>
parents:
421
diff
changeset
|
269 DARRAY_DESTROY(&txt_o->style_blks); |
822
586e50f82c1f
Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents:
760
diff
changeset
|
270 |
422
c6c0d017dc8e
Use DARRAY to manage variable length list
Thinker K.F. Li <thinker@branda.to>
parents:
421
diff
changeset
|
271 for(i = 0; i < txt_o->scaled_fonts.num; i++) |
c6c0d017dc8e
Use DARRAY to manage variable length list
Thinker K.F. Li <thinker@branda.to>
parents:
421
diff
changeset
|
272 scaled_font_free(txt_o->scaled_fonts.ds[i]); |
c6c0d017dc8e
Use DARRAY to manage variable length list
Thinker K.F. Li <thinker@branda.to>
parents:
421
diff
changeset
|
273 DARRAY_DESTROY(&txt_o->scaled_fonts); |
426
aa320386072c
Keep sub-extents for style blocks.
Thinker K.F. Li <thinker@branda.to>
parents:
425
diff
changeset
|
274 DARRAY_DESTROY(&txt_o->sub_exts); |
822
586e50f82c1f
Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents:
760
diff
changeset
|
275 |
419
7c921fda21be
Set free function for sh_stext.
Thinker K.F. Li <thinker@branda.to>
parents:
418
diff
changeset
|
276 if(txt_o->txt) |
7c921fda21be
Set free function for sh_stext.
Thinker K.F. Li <thinker@branda.to>
parents:
418
diff
changeset
|
277 free((void *)txt_o->txt); |
7c921fda21be
Set free function for sh_stext.
Thinker K.F. Li <thinker@branda.to>
parents:
418
diff
changeset
|
278 |
7c921fda21be
Set free function for sh_stext.
Thinker K.F. Li <thinker@branda.to>
parents:
418
diff
changeset
|
279 free(txt_o); |
7c921fda21be
Set free function for sh_stext.
Thinker K.F. Li <thinker@branda.to>
parents:
418
diff
changeset
|
280 } |
7c921fda21be
Set free function for sh_stext.
Thinker K.F. Li <thinker@branda.to>
parents:
418
diff
changeset
|
281 |
429
9d5506968efb
Change the interface of rdman_shape_stext_new().
Thinker K.F. Li <thinker@branda.to>
parents:
427
diff
changeset
|
282 shape_t *rdman_shape_stext_new(redraw_man_t *rdman, const char *txt, |
9d5506968efb
Change the interface of rdman_shape_stext_new().
Thinker K.F. Li <thinker@branda.to>
parents:
427
diff
changeset
|
283 co_aix x, co_aix y) { |
393
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
284 sh_stext_t *txt_o; |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
285 |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
286 ASSERT(txt != NULL); |
822
586e50f82c1f
Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents:
760
diff
changeset
|
287 |
393
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
288 txt_o = (sh_stext_t *)malloc(sizeof(sh_stext_t)); |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
289 if(txt_o == NULL) |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
290 return NULL; |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
291 |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
292 memset(&txt_o->shape, 0, sizeof(shape_t)); |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
293 mb_obj_init(txt_o, MBO_STEXT); |
822
586e50f82c1f
Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents:
760
diff
changeset
|
294 |
393
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
295 txt_o->txt = strdup(txt); |
422
c6c0d017dc8e
Use DARRAY to manage variable length list
Thinker K.F. Li <thinker@branda.to>
parents:
421
diff
changeset
|
296 DARRAY_INIT(&txt_o->style_blks); |
393
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
297 txt_o->x = x; |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
298 txt_o->y = y; |
422
c6c0d017dc8e
Use DARRAY to manage variable length list
Thinker K.F. Li <thinker@branda.to>
parents:
421
diff
changeset
|
299 DARRAY_INIT(&txt_o->scaled_fonts); |
426
aa320386072c
Keep sub-extents for style blocks.
Thinker K.F. Li <thinker@branda.to>
parents:
425
diff
changeset
|
300 DARRAY_INIT(&txt_o->sub_exts); |
393
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
301 |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
302 if(txt_o->txt == NULL) { |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
303 free(txt_o); |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
304 txt_o = NULL; |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
305 } |
419
7c921fda21be
Set free function for sh_stext.
Thinker K.F. Li <thinker@branda.to>
parents:
418
diff
changeset
|
306 |
7c921fda21be
Set free function for sh_stext.
Thinker K.F. Li <thinker@branda.to>
parents:
418
diff
changeset
|
307 txt_o->shape.free = _rdman_shape_stext_free; |
822
586e50f82c1f
Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents:
760
diff
changeset
|
308 |
1062
a8d20bc8ce40
Rename rdman_shape_man() to rdman_man_shape() to mean managing a shape
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
309 rdman_man_shape(rdman, (shape_t *)txt_o); |
822
586e50f82c1f
Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents:
760
diff
changeset
|
310 |
393
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
311 return (shape_t *)txt_o; |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
312 } |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
313 |
1370
bae104d8d247
Add clone functions for shape types
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
314 #ifndef UNITTEST |
bae104d8d247
Add clone functions for shape types
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
315 shape_t * |
bae104d8d247
Add clone functions for shape types
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
316 rdman_shape_stext_clone(redraw_man_t *rdman, const shape_t *_src_txt) { |
bae104d8d247
Add clone functions for shape types
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
317 sh_stext_t *src_txt = (const sh_stext_t *)_src_txt; |
bae104d8d247
Add clone functions for shape types
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
318 sh_stext_t *new_txt; |
bae104d8d247
Add clone functions for shape types
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
319 style_blks_lst_t *style_blks; |
bae104d8d247
Add clone functions for shape types
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
320 int r; |
bae104d8d247
Add clone functions for shape types
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
321 |
bae104d8d247
Add clone functions for shape types
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
322 new_txt = (sh_stext_t *)rdman_shape_stext_new(rdman, src_txt->txt, |
bae104d8d247
Add clone functions for shape types
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
323 src_txt->x, src_txt->y); |
bae104d8d247
Add clone functions for shape types
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
324 if(new_txt == NULL) |
bae104d8d247
Add clone functions for shape types
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
325 return NULL; |
bae104d8d247
Add clone functions for shape types
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
326 |
bae104d8d247
Add clone functions for shape types
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
327 style_blks = &src_txt->style_blks; |
bae104d8d247
Add clone functions for shape types
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
328 if(style_blks->num > 0) { |
bae104d8d247
Add clone functions for shape types
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
329 r = sh_stext_set_style(new_txt, style_blks->ds, style_blks->num); |
bae104d8d247
Add clone functions for shape types
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
330 if(r != OK) { |
bae104d8d247
Add clone functions for shape types
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
331 _rdman_shape_stext_free((shape_t *)new_txt); |
bae104d8d247
Add clone functions for shape types
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
332 return NULL; |
bae104d8d247
Add clone functions for shape types
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
333 } |
bae104d8d247
Add clone functions for shape types
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
334 } |
bae104d8d247
Add clone functions for shape types
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
335 |
bae104d8d247
Add clone functions for shape types
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
336 sh_copy_style(rdman, (shape_t *)src_txt, (shape_t *)new_txt); |
bae104d8d247
Add clone functions for shape types
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
337 |
bae104d8d247
Add clone functions for shape types
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
338 return (shape_t *)new_txt; |
bae104d8d247
Add clone functions for shape types
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
339 } |
bae104d8d247
Add clone functions for shape types
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
340 #endif /* UNITTEST */ |
bae104d8d247
Add clone functions for shape types
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
341 |
393
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
342 static |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
343 int compute_utf8_chars_sz(const char *txt, int n_chars) { |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
344 int i; |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
345 const char *p = txt; |
415
fef1b8076041
Make compute_utf8_chars_sz to compute length of n UTF 8 characters correctly.
Thinker K.F. Li <thinker@branda.to>
parents:
414
diff
changeset
|
346 const char *v; |
822
586e50f82c1f
Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents:
760
diff
changeset
|
347 |
410
1a923ea699c1
shape_stext.c, now, is unittested.
Thinker K.F. Li <thinker@branda.to>
parents:
407
diff
changeset
|
348 for(i = 0; i < n_chars && *p; i++) { |
415
fef1b8076041
Make compute_utf8_chars_sz to compute length of n UTF 8 characters correctly.
Thinker K.F. Li <thinker@branda.to>
parents:
414
diff
changeset
|
349 if(!(*p & 0x80)) /* single byte */ |
393
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
350 p++; |
415
fef1b8076041
Make compute_utf8_chars_sz to compute length of n UTF 8 characters correctly.
Thinker K.F. Li <thinker@branda.to>
parents:
414
diff
changeset
|
351 else if((*p & 0xe0) == 0xc0) /* 2 bytes */ |
fef1b8076041
Make compute_utf8_chars_sz to compute length of n UTF 8 characters correctly.
Thinker K.F. Li <thinker@branda.to>
parents:
414
diff
changeset
|
352 p += 2; |
fef1b8076041
Make compute_utf8_chars_sz to compute length of n UTF 8 characters correctly.
Thinker K.F. Li <thinker@branda.to>
parents:
414
diff
changeset
|
353 else if((*p & 0xf0) == 0xe0) /* 3 bytes */ |
fef1b8076041
Make compute_utf8_chars_sz to compute length of n UTF 8 characters correctly.
Thinker K.F. Li <thinker@branda.to>
parents:
414
diff
changeset
|
354 p += 3; |
fef1b8076041
Make compute_utf8_chars_sz to compute length of n UTF 8 characters correctly.
Thinker K.F. Li <thinker@branda.to>
parents:
414
diff
changeset
|
355 else if((*p & 0xf8) == 0xf0) /* 4 bytes */ |
fef1b8076041
Make compute_utf8_chars_sz to compute length of n UTF 8 characters correctly.
Thinker K.F. Li <thinker@branda.to>
parents:
414
diff
changeset
|
356 p += 4; |
fef1b8076041
Make compute_utf8_chars_sz to compute length of n UTF 8 characters correctly.
Thinker K.F. Li <thinker@branda.to>
parents:
414
diff
changeset
|
357 else |
fef1b8076041
Make compute_utf8_chars_sz to compute length of n UTF 8 characters correctly.
Thinker K.F. Li <thinker@branda.to>
parents:
414
diff
changeset
|
358 return ERR; |
393
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
359 } |
410
1a923ea699c1
shape_stext.c, now, is unittested.
Thinker K.F. Li <thinker@branda.to>
parents:
407
diff
changeset
|
360 if(i < n_chars) |
393
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
361 return ERR; |
415
fef1b8076041
Make compute_utf8_chars_sz to compute length of n UTF 8 characters correctly.
Thinker K.F. Li <thinker@branda.to>
parents:
414
diff
changeset
|
362 |
fef1b8076041
Make compute_utf8_chars_sz to compute length of n UTF 8 characters correctly.
Thinker K.F. Li <thinker@branda.to>
parents:
414
diff
changeset
|
363 for(v = txt; v != p; v++) |
fef1b8076041
Make compute_utf8_chars_sz to compute length of n UTF 8 characters correctly.
Thinker K.F. Li <thinker@branda.to>
parents:
414
diff
changeset
|
364 if(*v == '\x0') |
fef1b8076041
Make compute_utf8_chars_sz to compute length of n UTF 8 characters correctly.
Thinker K.F. Li <thinker@branda.to>
parents:
414
diff
changeset
|
365 return ERR; |
822
586e50f82c1f
Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents:
760
diff
changeset
|
366 |
393
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
367 return p - txt; |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
368 } |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
369 |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
370 static |
397
55f38c2cdb8f
Refactor function of computing text extents
Thinker K.F. Li <thinker@branda.to>
parents:
396
diff
changeset
|
371 mb_scaled_font_t *make_scaled_font_face(sh_stext_t *txt_o, |
410
1a923ea699c1
shape_stext.c, now, is unittested.
Thinker K.F. Li <thinker@branda.to>
parents:
407
diff
changeset
|
372 mb_font_face_t *face, |
393
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
373 co_aix shift_x, co_aix shift_y, |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
374 co_aix font_sz) { |
397
55f38c2cdb8f
Refactor function of computing text extents
Thinker K.F. Li <thinker@branda.to>
parents:
396
diff
changeset
|
375 co_aix matrix[6], scaled_matrix[6]; |
55f38c2cdb8f
Refactor function of computing text extents
Thinker K.F. Li <thinker@branda.to>
parents:
396
diff
changeset
|
376 co_aix *aggr; |
446
2437047b8bb8
Fix bug of propertional shifting of sh_stext_t.
Thinker K.F. Li <thinker@branda.to>
parents:
437
diff
changeset
|
377 co_aix noshift_aggr[6]; |
397
55f38c2cdb8f
Refactor function of computing text extents
Thinker K.F. Li <thinker@branda.to>
parents:
396
diff
changeset
|
378 mb_scaled_font_t *scaled; |
393
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
379 |
397
55f38c2cdb8f
Refactor function of computing text extents
Thinker K.F. Li <thinker@branda.to>
parents:
396
diff
changeset
|
380 aggr = sh_get_aggr_matrix((shape_t *)txt_o); |
446
2437047b8bb8
Fix bug of propertional shifting of sh_stext_t.
Thinker K.F. Li <thinker@branda.to>
parents:
437
diff
changeset
|
381 memcpy(noshift_aggr, aggr, sizeof(co_aix) * 6); |
2437047b8bb8
Fix bug of propertional shifting of sh_stext_t.
Thinker K.F. Li <thinker@branda.to>
parents:
437
diff
changeset
|
382 noshift_aggr[2] = 0; |
2437047b8bb8
Fix bug of propertional shifting of sh_stext_t.
Thinker K.F. Li <thinker@branda.to>
parents:
437
diff
changeset
|
383 noshift_aggr[5] = 0; |
822
586e50f82c1f
Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents:
760
diff
changeset
|
384 |
397
55f38c2cdb8f
Refactor function of computing text extents
Thinker K.F. Li <thinker@branda.to>
parents:
396
diff
changeset
|
385 matrix[0] = font_sz; |
55f38c2cdb8f
Refactor function of computing text extents
Thinker K.F. Li <thinker@branda.to>
parents:
396
diff
changeset
|
386 matrix[1] = 0; |
55f38c2cdb8f
Refactor function of computing text extents
Thinker K.F. Li <thinker@branda.to>
parents:
396
diff
changeset
|
387 matrix[2] = shift_x; |
55f38c2cdb8f
Refactor function of computing text extents
Thinker K.F. Li <thinker@branda.to>
parents:
396
diff
changeset
|
388 matrix[3] = 0; |
55f38c2cdb8f
Refactor function of computing text extents
Thinker K.F. Li <thinker@branda.to>
parents:
396
diff
changeset
|
389 matrix[4] = font_sz; |
760
5781b2485e38
Fix position issue of stext.
Thinker K.F. Li <thinker@codemud.net>
parents:
475
diff
changeset
|
390 matrix[5] = shift_y; |
446
2437047b8bb8
Fix bug of propertional shifting of sh_stext_t.
Thinker K.F. Li <thinker@branda.to>
parents:
437
diff
changeset
|
391 matrix_mul(noshift_aggr, matrix, scaled_matrix); |
822
586e50f82c1f
Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents:
760
diff
changeset
|
392 |
397
55f38c2cdb8f
Refactor function of computing text extents
Thinker K.F. Li <thinker@branda.to>
parents:
396
diff
changeset
|
393 scaled = make_scaled_font_face_matrix(face, scaled_matrix); |
393
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
394 |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
395 return scaled; |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
396 } |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
397 |
403
aee0f66b1154
Compute extents of a styled text
Thinker K.F. Li <thinker@branda.to>
parents:
397
diff
changeset
|
398 /*! \brief Extend an extents from another sub-extents. |
aee0f66b1154
Compute extents of a styled text
Thinker K.F. Li <thinker@branda.to>
parents:
397
diff
changeset
|
399 * |
aee0f66b1154
Compute extents of a styled text
Thinker K.F. Li <thinker@branda.to>
parents:
397
diff
changeset
|
400 * A styled text is styled by several styled blocks, so extents of |
aee0f66b1154
Compute extents of a styled text
Thinker K.F. Li <thinker@branda.to>
parents:
397
diff
changeset
|
401 * blocks should be computed separated, collected, and aggreagated |
aee0f66b1154
Compute extents of a styled text
Thinker K.F. Li <thinker@branda.to>
parents:
397
diff
changeset
|
402 * into a full extents. |
aee0f66b1154
Compute extents of a styled text
Thinker K.F. Li <thinker@branda.to>
parents:
397
diff
changeset
|
403 */ |
393
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
404 static |
403
aee0f66b1154
Compute extents of a styled text
Thinker K.F. Li <thinker@branda.to>
parents:
397
diff
changeset
|
405 void extent_extents(mb_text_extents_t *full, mb_text_extents_t *sub) { |
437
e73b3644d802
Fix bug of compute extents of sh_stext.
Thinker K.F. Li <thinker@branda.to>
parents:
436
diff
changeset
|
406 co_aix f_rbx, f_rby; /* rb stands for right bottom */ |
403
aee0f66b1154
Compute extents of a styled text
Thinker K.F. Li <thinker@branda.to>
parents:
397
diff
changeset
|
407 co_aix s_rbx, s_rby; |
414
bbf036c315be
Fix extent_extents to make it pass the test case.
Thinker K.F. Li <thinker@branda.to>
parents:
413
diff
changeset
|
408 co_aix s_xbr, s_ybr; |
bbf036c315be
Fix extent_extents to make it pass the test case.
Thinker K.F. Li <thinker@branda.to>
parents:
413
diff
changeset
|
409 co_aix new_x_adv, new_y_adv; |
403
aee0f66b1154
Compute extents of a styled text
Thinker K.F. Li <thinker@branda.to>
parents:
397
diff
changeset
|
410 |
aee0f66b1154
Compute extents of a styled text
Thinker K.F. Li <thinker@branda.to>
parents:
397
diff
changeset
|
411 f_rbx = MBE_GET_X_BEARING(full) + MBE_GET_WIDTH(full); |
aee0f66b1154
Compute extents of a styled text
Thinker K.F. Li <thinker@branda.to>
parents:
397
diff
changeset
|
412 f_rby = MBE_GET_Y_BEARING(full) + MBE_GET_HEIGHT(full); |
414
bbf036c315be
Fix extent_extents to make it pass the test case.
Thinker K.F. Li <thinker@branda.to>
parents:
413
diff
changeset
|
413 s_xbr = MBE_GET_X_BEARING(sub) + MBE_GET_X_ADV(full); |
bbf036c315be
Fix extent_extents to make it pass the test case.
Thinker K.F. Li <thinker@branda.to>
parents:
413
diff
changeset
|
414 s_ybr = MBE_GET_Y_BEARING(sub) + MBE_GET_Y_ADV(full); |
bbf036c315be
Fix extent_extents to make it pass the test case.
Thinker K.F. Li <thinker@branda.to>
parents:
413
diff
changeset
|
415 s_rbx = s_xbr + MBE_GET_WIDTH(sub); |
bbf036c315be
Fix extent_extents to make it pass the test case.
Thinker K.F. Li <thinker@branda.to>
parents:
413
diff
changeset
|
416 s_rby = s_ybr + MBE_GET_HEIGHT(sub); |
822
586e50f82c1f
Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents:
760
diff
changeset
|
417 |
403
aee0f66b1154
Compute extents of a styled text
Thinker K.F. Li <thinker@branda.to>
parents:
397
diff
changeset
|
418 /* set bearing */ |
414
bbf036c315be
Fix extent_extents to make it pass the test case.
Thinker K.F. Li <thinker@branda.to>
parents:
413
diff
changeset
|
419 if(MBE_GET_X_BEARING(full) > s_xbr) |
bbf036c315be
Fix extent_extents to make it pass the test case.
Thinker K.F. Li <thinker@branda.to>
parents:
413
diff
changeset
|
420 MBE_SET_X_BEARING(full, s_xbr); |
bbf036c315be
Fix extent_extents to make it pass the test case.
Thinker K.F. Li <thinker@branda.to>
parents:
413
diff
changeset
|
421 if(MBE_GET_Y_BEARING(full) > s_ybr) |
bbf036c315be
Fix extent_extents to make it pass the test case.
Thinker K.F. Li <thinker@branda.to>
parents:
413
diff
changeset
|
422 MBE_SET_Y_BEARING(full, s_ybr); |
822
586e50f82c1f
Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents:
760
diff
changeset
|
423 |
403
aee0f66b1154
Compute extents of a styled text
Thinker K.F. Li <thinker@branda.to>
parents:
397
diff
changeset
|
424 /* set width/height */ |
aee0f66b1154
Compute extents of a styled text
Thinker K.F. Li <thinker@branda.to>
parents:
397
diff
changeset
|
425 if(f_rbx < s_rbx) |
aee0f66b1154
Compute extents of a styled text
Thinker K.F. Li <thinker@branda.to>
parents:
397
diff
changeset
|
426 MBE_SET_WIDTH(full, s_rbx - MBE_GET_X_BEARING(full)); |
414
bbf036c315be
Fix extent_extents to make it pass the test case.
Thinker K.F. Li <thinker@branda.to>
parents:
413
diff
changeset
|
427 else |
bbf036c315be
Fix extent_extents to make it pass the test case.
Thinker K.F. Li <thinker@branda.to>
parents:
413
diff
changeset
|
428 MBE_SET_WIDTH(full, f_rbx - MBE_GET_X_BEARING(full)); |
403
aee0f66b1154
Compute extents of a styled text
Thinker K.F. Li <thinker@branda.to>
parents:
397
diff
changeset
|
429 if(f_rby < s_rby) |
aee0f66b1154
Compute extents of a styled text
Thinker K.F. Li <thinker@branda.to>
parents:
397
diff
changeset
|
430 MBE_SET_HEIGHT(full, s_rby - MBE_GET_Y_BEARING(full)); |
414
bbf036c315be
Fix extent_extents to make it pass the test case.
Thinker K.F. Li <thinker@branda.to>
parents:
413
diff
changeset
|
431 else |
bbf036c315be
Fix extent_extents to make it pass the test case.
Thinker K.F. Li <thinker@branda.to>
parents:
413
diff
changeset
|
432 MBE_SET_HEIGHT(full, f_rby - MBE_GET_Y_BEARING(full)); |
bbf036c315be
Fix extent_extents to make it pass the test case.
Thinker K.F. Li <thinker@branda.to>
parents:
413
diff
changeset
|
433 |
bbf036c315be
Fix extent_extents to make it pass the test case.
Thinker K.F. Li <thinker@branda.to>
parents:
413
diff
changeset
|
434 /* set x/y advance */ |
bbf036c315be
Fix extent_extents to make it pass the test case.
Thinker K.F. Li <thinker@branda.to>
parents:
413
diff
changeset
|
435 new_x_adv = MBE_GET_X_ADV(full) + MBE_GET_X_ADV(sub); |
bbf036c315be
Fix extent_extents to make it pass the test case.
Thinker K.F. Li <thinker@branda.to>
parents:
413
diff
changeset
|
436 new_y_adv = MBE_GET_Y_ADV(full) + MBE_GET_Y_ADV(sub); |
bbf036c315be
Fix extent_extents to make it pass the test case.
Thinker K.F. Li <thinker@branda.to>
parents:
413
diff
changeset
|
437 MBE_SET_X_ADV(full, new_x_adv); |
bbf036c315be
Fix extent_extents to make it pass the test case.
Thinker K.F. Li <thinker@branda.to>
parents:
413
diff
changeset
|
438 MBE_SET_Y_ADV(full, new_y_adv); |
403
aee0f66b1154
Compute extents of a styled text
Thinker K.F. Li <thinker@branda.to>
parents:
397
diff
changeset
|
439 } |
aee0f66b1154
Compute extents of a styled text
Thinker K.F. Li <thinker@branda.to>
parents:
397
diff
changeset
|
440 |
aee0f66b1154
Compute extents of a styled text
Thinker K.F. Li <thinker@branda.to>
parents:
397
diff
changeset
|
441 /*! \brief Compute extents of a stext object according style blocks. |
aee0f66b1154
Compute extents of a styled text
Thinker K.F. Li <thinker@branda.to>
parents:
397
diff
changeset
|
442 * |
aee0f66b1154
Compute extents of a styled text
Thinker K.F. Li <thinker@branda.to>
parents:
397
diff
changeset
|
443 * It create scaled fonts for style blocks, compute their extents, |
aee0f66b1154
Compute extents of a styled text
Thinker K.F. Li <thinker@branda.to>
parents:
397
diff
changeset
|
444 * and compute where they should be draw acoording advance of style |
aee0f66b1154
Compute extents of a styled text
Thinker K.F. Li <thinker@branda.to>
parents:
397
diff
changeset
|
445 * blocks before a style block. |
421
1e48453bb282
Make compute_styled_extents_n_scaled_font() pass the test.
Thinker K.F. Li <thinker@branda.to>
parents:
420
diff
changeset
|
446 * |
1e48453bb282
Make compute_styled_extents_n_scaled_font() pass the test.
Thinker K.F. Li <thinker@branda.to>
parents:
420
diff
changeset
|
447 * The scaled font that is created by this function for style blocks |
1e48453bb282
Make compute_styled_extents_n_scaled_font() pass the test.
Thinker K.F. Li <thinker@branda.to>
parents:
420
diff
changeset
|
448 * are drawed at origin. So, extents of these blocks are also based |
1e48453bb282
Make compute_styled_extents_n_scaled_font() pass the test.
Thinker K.F. Li <thinker@branda.to>
parents:
420
diff
changeset
|
449 * on that the text are drawed at origin of user space. But, |
1e48453bb282
Make compute_styled_extents_n_scaled_font() pass the test.
Thinker K.F. Li <thinker@branda.to>
parents:
420
diff
changeset
|
450 * aggreagated extents (sh_stext_t::extents) accounts x/y advances |
1e48453bb282
Make compute_styled_extents_n_scaled_font() pass the test.
Thinker K.F. Li <thinker@branda.to>
parents:
420
diff
changeset
|
451 * to create correct extents for full text string with style blocks. |
424
585baa462778
Make sh_stext_transform() pass first test case for him.
Thinker K.F. Li <thinker@branda.to>
parents:
423
diff
changeset
|
452 * |
585baa462778
Make sh_stext_transform() pass first test case for him.
Thinker K.F. Li <thinker@branda.to>
parents:
423
diff
changeset
|
453 * This function assumes texts are always drawed at 0, 0. So, |
585baa462778
Make sh_stext_transform() pass first test case for him.
Thinker K.F. Li <thinker@branda.to>
parents:
423
diff
changeset
|
454 * transform function should adjust x and y bearing corresponding |
585baa462778
Make sh_stext_transform() pass first test case for him.
Thinker K.F. Li <thinker@branda.to>
parents:
423
diff
changeset
|
455 * x, y of text to compute area. |
403
aee0f66b1154
Compute extents of a styled text
Thinker K.F. Li <thinker@branda.to>
parents:
397
diff
changeset
|
456 */ |
aee0f66b1154
Compute extents of a styled text
Thinker K.F. Li <thinker@branda.to>
parents:
397
diff
changeset
|
457 static |
aee0f66b1154
Compute extents of a styled text
Thinker K.F. Li <thinker@branda.to>
parents:
397
diff
changeset
|
458 void compute_styled_extents_n_scaled_font(sh_stext_t *txt_o) { |
422
c6c0d017dc8e
Use DARRAY to manage variable length list
Thinker K.F. Li <thinker@branda.to>
parents:
421
diff
changeset
|
459 mb_style_blk_t *blk; |
c6c0d017dc8e
Use DARRAY to manage variable length list
Thinker K.F. Li <thinker@branda.to>
parents:
421
diff
changeset
|
460 style_blks_lst_t *style_blks; |
397
55f38c2cdb8f
Refactor function of computing text extents
Thinker K.F. Li <thinker@branda.to>
parents:
396
diff
changeset
|
461 int blk_txt_len; |
422
c6c0d017dc8e
Use DARRAY to manage variable length list
Thinker K.F. Li <thinker@branda.to>
parents:
421
diff
changeset
|
462 mb_scaled_font_t *scaled; |
c6c0d017dc8e
Use DARRAY to manage variable length list
Thinker K.F. Li <thinker@branda.to>
parents:
421
diff
changeset
|
463 scaled_fonts_lst_t *scaled_fonts; |
426
aa320386072c
Keep sub-extents for style blocks.
Thinker K.F. Li <thinker@branda.to>
parents:
425
diff
changeset
|
464 extents_lst_t *sub_exts; |
aa320386072c
Keep sub-extents for style blocks.
Thinker K.F. Li <thinker@branda.to>
parents:
425
diff
changeset
|
465 mb_text_extents_t *sub; |
397
55f38c2cdb8f
Refactor function of computing text extents
Thinker K.F. Li <thinker@branda.to>
parents:
396
diff
changeset
|
466 char *txt, saved; |
421
1e48453bb282
Make compute_styled_extents_n_scaled_font() pass the test.
Thinker K.F. Li <thinker@branda.to>
parents:
420
diff
changeset
|
467 int i, nscaled; |
822
586e50f82c1f
Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents:
760
diff
changeset
|
468 |
422
c6c0d017dc8e
Use DARRAY to manage variable length list
Thinker K.F. Li <thinker@branda.to>
parents:
421
diff
changeset
|
469 scaled_fonts = &txt_o->scaled_fonts; |
c6c0d017dc8e
Use DARRAY to manage variable length list
Thinker K.F. Li <thinker@branda.to>
parents:
421
diff
changeset
|
470 for(i = 0; i < scaled_fonts->num; i++) |
c6c0d017dc8e
Use DARRAY to manage variable length list
Thinker K.F. Li <thinker@branda.to>
parents:
421
diff
changeset
|
471 scaled_font_free(scaled_fonts->ds[i]); |
c6c0d017dc8e
Use DARRAY to manage variable length list
Thinker K.F. Li <thinker@branda.to>
parents:
421
diff
changeset
|
472 DARRAY_CLEAN(scaled_fonts); |
822
586e50f82c1f
Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents:
760
diff
changeset
|
473 |
422
c6c0d017dc8e
Use DARRAY to manage variable length list
Thinker K.F. Li <thinker@branda.to>
parents:
421
diff
changeset
|
474 style_blks = &txt_o->style_blks; |
c6c0d017dc8e
Use DARRAY to manage variable length list
Thinker K.F. Li <thinker@branda.to>
parents:
421
diff
changeset
|
475 blk = style_blks->ds; |
426
aa320386072c
Keep sub-extents for style blocks.
Thinker K.F. Li <thinker@branda.to>
parents:
425
diff
changeset
|
476 |
aa320386072c
Keep sub-extents for style blocks.
Thinker K.F. Li <thinker@branda.to>
parents:
425
diff
changeset
|
477 sub_exts = &txt_o->sub_exts; |
aa320386072c
Keep sub-extents for style blocks.
Thinker K.F. Li <thinker@branda.to>
parents:
425
diff
changeset
|
478 DARRAY_CLEAN(sub_exts); |
aa320386072c
Keep sub-extents for style blocks.
Thinker K.F. Li <thinker@branda.to>
parents:
425
diff
changeset
|
479 extents_lst_adv(sub_exts, style_blks->num); |
822
586e50f82c1f
Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents:
760
diff
changeset
|
480 |
393
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
481 txt = (char *)txt_o->txt; |
422
c6c0d017dc8e
Use DARRAY to manage variable length list
Thinker K.F. Li <thinker@branda.to>
parents:
421
diff
changeset
|
482 for(i = 0; i < style_blks->num; i++) { |
c6c0d017dc8e
Use DARRAY to manage variable length list
Thinker K.F. Li <thinker@branda.to>
parents:
421
diff
changeset
|
483 scaled = make_scaled_font_face(txt_o, blk->face, |
c6c0d017dc8e
Use DARRAY to manage variable length list
Thinker K.F. Li <thinker@branda.to>
parents:
421
diff
changeset
|
484 0, 0, blk->font_sz); |
c6c0d017dc8e
Use DARRAY to manage variable length list
Thinker K.F. Li <thinker@branda.to>
parents:
421
diff
changeset
|
485 ASSERT(scaled != NULL); |
c6c0d017dc8e
Use DARRAY to manage variable length list
Thinker K.F. Li <thinker@branda.to>
parents:
421
diff
changeset
|
486 scaled_fonts_lst_add(scaled_fonts, scaled); |
426
aa320386072c
Keep sub-extents for style blocks.
Thinker K.F. Li <thinker@branda.to>
parents:
425
diff
changeset
|
487 sub = sub_exts->ds + i; |
822
586e50f82c1f
Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents:
760
diff
changeset
|
488 |
393
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
489 blk_txt_len = compute_utf8_chars_sz(txt, blk->n_chars); |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
490 ASSERT(blk_txt_len != ERR); |
822
586e50f82c1f
Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents:
760
diff
changeset
|
491 |
397
55f38c2cdb8f
Refactor function of computing text extents
Thinker K.F. Li <thinker@branda.to>
parents:
396
diff
changeset
|
492 saved = txt[blk_txt_len]; |
55f38c2cdb8f
Refactor function of computing text extents
Thinker K.F. Li <thinker@branda.to>
parents:
396
diff
changeset
|
493 txt[blk_txt_len] = 0; |
426
aa320386072c
Keep sub-extents for style blocks.
Thinker K.F. Li <thinker@branda.to>
parents:
425
diff
changeset
|
494 compute_text_extents(scaled, txt, sub); |
397
55f38c2cdb8f
Refactor function of computing text extents
Thinker K.F. Li <thinker@branda.to>
parents:
396
diff
changeset
|
495 txt[blk_txt_len] = saved; |
55f38c2cdb8f
Refactor function of computing text extents
Thinker K.F. Li <thinker@branda.to>
parents:
396
diff
changeset
|
496 |
393
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
497 blk++; |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
498 txt += blk_txt_len; |
437
e73b3644d802
Fix bug of compute extents of sh_stext.
Thinker K.F. Li <thinker@branda.to>
parents:
436
diff
changeset
|
499 } |
822
586e50f82c1f
Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents:
760
diff
changeset
|
500 |
437
e73b3644d802
Fix bug of compute extents of sh_stext.
Thinker K.F. Li <thinker@branda.to>
parents:
436
diff
changeset
|
501 if(style_blks->num > 0) { |
e73b3644d802
Fix bug of compute extents of sh_stext.
Thinker K.F. Li <thinker@branda.to>
parents:
436
diff
changeset
|
502 sub = sub_exts->ds; |
e73b3644d802
Fix bug of compute extents of sh_stext.
Thinker K.F. Li <thinker@branda.to>
parents:
436
diff
changeset
|
503 memcpy(&txt_o->extents, sub, sizeof(mb_text_extents_t)); |
e73b3644d802
Fix bug of compute extents of sh_stext.
Thinker K.F. Li <thinker@branda.to>
parents:
436
diff
changeset
|
504 for(i = 1; i < style_blks->num; i++) { |
e73b3644d802
Fix bug of compute extents of sh_stext.
Thinker K.F. Li <thinker@branda.to>
parents:
436
diff
changeset
|
505 sub = sub_exts->ds + i; |
e73b3644d802
Fix bug of compute extents of sh_stext.
Thinker K.F. Li <thinker@branda.to>
parents:
436
diff
changeset
|
506 extent_extents(&txt_o->extents, sub); |
e73b3644d802
Fix bug of compute extents of sh_stext.
Thinker K.F. Li <thinker@branda.to>
parents:
436
diff
changeset
|
507 } |
e73b3644d802
Fix bug of compute extents of sh_stext.
Thinker K.F. Li <thinker@branda.to>
parents:
436
diff
changeset
|
508 } else |
822
586e50f82c1f
Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents:
760
diff
changeset
|
509 memset(&txt_o->extents, sizeof(mb_text_extents_t), 0); |
393
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
510 } |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
511 |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
512 /* |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
513 * What we have to do in sh_stext_transform() is |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
514 * - computing bounding box for the text, |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
515 * - computing offset x,y for the text of style blocks, |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
516 * - free old scaled fonts, and |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
517 * - making scaled fonts for style blocks. |
424
585baa462778
Make sh_stext_transform() pass first test case for him.
Thinker K.F. Li <thinker@branda.to>
parents:
423
diff
changeset
|
518 * |
585baa462778
Make sh_stext_transform() pass first test case for him.
Thinker K.F. Li <thinker@branda.to>
parents:
423
diff
changeset
|
519 * Extents of style blocks are computed with x,y at 0,0. |
585baa462778
Make sh_stext_transform() pass first test case for him.
Thinker K.F. Li <thinker@branda.to>
parents:
423
diff
changeset
|
520 * So, we should add x,y, after transforming by the aggreagated matrix, |
585baa462778
Make sh_stext_transform() pass first test case for him.
Thinker K.F. Li <thinker@branda.to>
parents:
423
diff
changeset
|
521 * to output area. |
393
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
522 */ |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
523 void sh_stext_transform(shape_t *shape) { |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
524 sh_stext_t *txt_o = (sh_stext_t *)shape; |
424
585baa462778
Make sh_stext_transform() pass first test case for him.
Thinker K.F. Li <thinker@branda.to>
parents:
423
diff
changeset
|
525 area_t *area; |
585baa462778
Make sh_stext_transform() pass first test case for him.
Thinker K.F. Li <thinker@branda.to>
parents:
423
diff
changeset
|
526 mb_text_extents_t *ext; |
585baa462778
Make sh_stext_transform() pass first test case for him.
Thinker K.F. Li <thinker@branda.to>
parents:
423
diff
changeset
|
527 co_aix *aggr; |
393
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
528 |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
529 ASSERT(txt_o != NULL); |
424
585baa462778
Make sh_stext_transform() pass first test case for him.
Thinker K.F. Li <thinker@branda.to>
parents:
423
diff
changeset
|
530 |
585baa462778
Make sh_stext_transform() pass first test case for him.
Thinker K.F. Li <thinker@branda.to>
parents:
423
diff
changeset
|
531 aggr = sh_get_aggr_matrix(shape); |
822
586e50f82c1f
Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents:
760
diff
changeset
|
532 |
424
585baa462778
Make sh_stext_transform() pass first test case for him.
Thinker K.F. Li <thinker@branda.to>
parents:
423
diff
changeset
|
533 txt_o->dx = txt_o->x; |
585baa462778
Make sh_stext_transform() pass first test case for him.
Thinker K.F. Li <thinker@branda.to>
parents:
423
diff
changeset
|
534 txt_o->dy = txt_o->y; |
585baa462778
Make sh_stext_transform() pass first test case for him.
Thinker K.F. Li <thinker@branda.to>
parents:
423
diff
changeset
|
535 matrix_trans_pos(aggr, &txt_o->dx, &txt_o->dy); |
822
586e50f82c1f
Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents:
760
diff
changeset
|
536 |
403
aee0f66b1154
Compute extents of a styled text
Thinker K.F. Li <thinker@branda.to>
parents:
397
diff
changeset
|
537 compute_styled_extents_n_scaled_font(txt_o); |
424
585baa462778
Make sh_stext_transform() pass first test case for him.
Thinker K.F. Li <thinker@branda.to>
parents:
423
diff
changeset
|
538 ext = &txt_o->extents; |
822
586e50f82c1f
Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents:
760
diff
changeset
|
539 |
424
585baa462778
Make sh_stext_transform() pass first test case for him.
Thinker K.F. Li <thinker@branda.to>
parents:
423
diff
changeset
|
540 area = sh_get_area(shape); |
585baa462778
Make sh_stext_transform() pass first test case for him.
Thinker K.F. Li <thinker@branda.to>
parents:
423
diff
changeset
|
541 area->x = MBE_GET_X_BEARING(ext) + txt_o->dx; |
585baa462778
Make sh_stext_transform() pass first test case for him.
Thinker K.F. Li <thinker@branda.to>
parents:
423
diff
changeset
|
542 area->y = MBE_GET_Y_BEARING(ext) + txt_o->dy; |
585baa462778
Make sh_stext_transform() pass first test case for him.
Thinker K.F. Li <thinker@branda.to>
parents:
423
diff
changeset
|
543 area->w = MBE_GET_WIDTH(ext); |
585baa462778
Make sh_stext_transform() pass first test case for him.
Thinker K.F. Li <thinker@branda.to>
parents:
423
diff
changeset
|
544 area->h = MBE_GET_HEIGHT(ext); |
393
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
545 } |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
546 |
448
16116d84bc5e
Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents:
447
diff
changeset
|
547 void sh_stext_draw(shape_t *shape, mbe_t *cr) { |
393
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
548 sh_stext_t *txt_o = (sh_stext_t *)shape; |
427
8f900da42eed
Make sh_text_draw() passes first test case.
Thinker K.F. Li <thinker@branda.to>
parents:
426
diff
changeset
|
549 co_aix x, y; |
8f900da42eed
Make sh_text_draw() passes first test case.
Thinker K.F. Li <thinker@branda.to>
parents:
426
diff
changeset
|
550 const char *txt; |
8f900da42eed
Make sh_text_draw() passes first test case.
Thinker K.F. Li <thinker@branda.to>
parents:
426
diff
changeset
|
551 scaled_fonts_lst_t *scaled_fonts; |
8f900da42eed
Make sh_text_draw() passes first test case.
Thinker K.F. Li <thinker@branda.to>
parents:
426
diff
changeset
|
552 mb_scaled_font_t *scaled; |
8f900da42eed
Make sh_text_draw() passes first test case.
Thinker K.F. Li <thinker@branda.to>
parents:
426
diff
changeset
|
553 style_blks_lst_t *style_blks; |
8f900da42eed
Make sh_text_draw() passes first test case.
Thinker K.F. Li <thinker@branda.to>
parents:
426
diff
changeset
|
554 mb_style_blk_t *blk; |
8f900da42eed
Make sh_text_draw() passes first test case.
Thinker K.F. Li <thinker@branda.to>
parents:
426
diff
changeset
|
555 mb_text_extents_t *ext; |
8f900da42eed
Make sh_text_draw() passes first test case.
Thinker K.F. Li <thinker@branda.to>
parents:
426
diff
changeset
|
556 int blk_txt_len; |
8f900da42eed
Make sh_text_draw() passes first test case.
Thinker K.F. Li <thinker@branda.to>
parents:
426
diff
changeset
|
557 int i; |
393
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
558 |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
559 ASSERT(txt_o != NULL); |
822
586e50f82c1f
Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents:
760
diff
changeset
|
560 |
427
8f900da42eed
Make sh_text_draw() passes first test case.
Thinker K.F. Li <thinker@branda.to>
parents:
426
diff
changeset
|
561 x = txt_o->dx; |
8f900da42eed
Make sh_text_draw() passes first test case.
Thinker K.F. Li <thinker@branda.to>
parents:
426
diff
changeset
|
562 y = txt_o->dy; |
8f900da42eed
Make sh_text_draw() passes first test case.
Thinker K.F. Li <thinker@branda.to>
parents:
426
diff
changeset
|
563 txt = txt_o->txt; |
8f900da42eed
Make sh_text_draw() passes first test case.
Thinker K.F. Li <thinker@branda.to>
parents:
426
diff
changeset
|
564 scaled_fonts = &txt_o->scaled_fonts; |
8f900da42eed
Make sh_text_draw() passes first test case.
Thinker K.F. Li <thinker@branda.to>
parents:
426
diff
changeset
|
565 style_blks = &txt_o->style_blks; |
8f900da42eed
Make sh_text_draw() passes first test case.
Thinker K.F. Li <thinker@branda.to>
parents:
426
diff
changeset
|
566 ext = txt_o->sub_exts.ds; |
822
586e50f82c1f
Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents:
760
diff
changeset
|
567 |
427
8f900da42eed
Make sh_text_draw() passes first test case.
Thinker K.F. Li <thinker@branda.to>
parents:
426
diff
changeset
|
568 for(i = 0; i < scaled_fonts->num; i++) { |
8f900da42eed
Make sh_text_draw() passes first test case.
Thinker K.F. Li <thinker@branda.to>
parents:
426
diff
changeset
|
569 scaled = scaled_fonts->ds[i]; |
8f900da42eed
Make sh_text_draw() passes first test case.
Thinker K.F. Li <thinker@branda.to>
parents:
426
diff
changeset
|
570 blk = style_blks->ds + i; |
8f900da42eed
Make sh_text_draw() passes first test case.
Thinker K.F. Li <thinker@branda.to>
parents:
426
diff
changeset
|
571 blk_txt_len = compute_utf8_chars_sz(txt, blk->n_chars); |
8f900da42eed
Make sh_text_draw() passes first test case.
Thinker K.F. Li <thinker@branda.to>
parents:
426
diff
changeset
|
572 draw_text_scaled(cr, txt, blk_txt_len, scaled, x, y); |
822
586e50f82c1f
Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents:
760
diff
changeset
|
573 |
427
8f900da42eed
Make sh_text_draw() passes first test case.
Thinker K.F. Li <thinker@branda.to>
parents:
426
diff
changeset
|
574 x += MBE_GET_X_ADV(ext); |
8f900da42eed
Make sh_text_draw() passes first test case.
Thinker K.F. Li <thinker@branda.to>
parents:
426
diff
changeset
|
575 y += MBE_GET_Y_ADV(ext); |
8f900da42eed
Make sh_text_draw() passes first test case.
Thinker K.F. Li <thinker@branda.to>
parents:
426
diff
changeset
|
576 txt += blk_txt_len; |
8f900da42eed
Make sh_text_draw() passes first test case.
Thinker K.F. Li <thinker@branda.to>
parents:
426
diff
changeset
|
577 } |
393
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
578 } |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
579 |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
580 int sh_stext_set_text(shape_t *shape, const char *txt) { |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
581 sh_stext_t *txt_o = (sh_stext_t *)shape; |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
582 char *new_txt; |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
583 int sz; |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
584 |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
585 ASSERT(txt_o != NULL); |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
586 ASSERT(txt != NULL); |
822
586e50f82c1f
Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents:
760
diff
changeset
|
587 |
393
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
588 sz = strlen(txt) + 1; |
410
1a923ea699c1
shape_stext.c, now, is unittested.
Thinker K.F. Li <thinker@branda.to>
parents:
407
diff
changeset
|
589 new_txt = (char *)realloc((void *)txt_o->txt, sz); |
393
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
590 if(new_txt == NULL) |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
591 return ERR; |
822
586e50f82c1f
Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents:
760
diff
changeset
|
592 |
393
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
593 memcpy(new_txt, txt, sz); |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
594 txt_o->txt = new_txt; |
822
586e50f82c1f
Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents:
760
diff
changeset
|
595 |
393
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
596 return OK; |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
597 } |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
598 |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
599 int sh_stext_set_style(shape_t *shape, |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
600 const mb_style_blk_t *blks, |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
601 int nblks) { |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
602 sh_stext_t *txt_o = (sh_stext_t *)shape; |
422
c6c0d017dc8e
Use DARRAY to manage variable length list
Thinker K.F. Li <thinker@branda.to>
parents:
421
diff
changeset
|
603 style_blks_lst_t *style_blks; |
393
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
604 mb_style_blk_t *new_blks; |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
605 int sz; |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
606 |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
607 ASSERT(txt_o != NULL); |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
608 ASSERT(nblks >= 0); |
822
586e50f82c1f
Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents:
760
diff
changeset
|
609 |
422
c6c0d017dc8e
Use DARRAY to manage variable length list
Thinker K.F. Li <thinker@branda.to>
parents:
421
diff
changeset
|
610 style_blks = &txt_o->style_blks; |
c6c0d017dc8e
Use DARRAY to manage variable length list
Thinker K.F. Li <thinker@branda.to>
parents:
421
diff
changeset
|
611 DARRAY_CLEAN(style_blks); |
c6c0d017dc8e
Use DARRAY to manage variable length list
Thinker K.F. Li <thinker@branda.to>
parents:
421
diff
changeset
|
612 style_blks_lst_adv(style_blks, nblks); |
822
586e50f82c1f
Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents:
760
diff
changeset
|
613 |
422
c6c0d017dc8e
Use DARRAY to manage variable length list
Thinker K.F. Li <thinker@branda.to>
parents:
421
diff
changeset
|
614 memcpy(style_blks->ds, |
421
1e48453bb282
Make compute_styled_extents_n_scaled_font() pass the test.
Thinker K.F. Li <thinker@branda.to>
parents:
420
diff
changeset
|
615 blks, nblks * sizeof(mb_style_blk_t)); |
822
586e50f82c1f
Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents:
760
diff
changeset
|
616 |
393
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
617 return OK; |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
618 } |
27774b93521e
Add sh_stext_t to implement a simple version of text shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
619 |
410
1a923ea699c1
shape_stext.c, now, is unittested.
Thinker K.F. Li <thinker@branda.to>
parents:
407
diff
changeset
|
620 #ifdef UNITTEST |
1a923ea699c1
shape_stext.c, now, is unittested.
Thinker K.F. Li <thinker@branda.to>
parents:
407
diff
changeset
|
621 |
412
a456e267279a
Test cases for shape_stext.
Thinker K.F. Li <thinker@branda.to>
parents:
411
diff
changeset
|
622 #include <CUnit/Basic.h> |
a456e267279a
Test cases for shape_stext.
Thinker K.F. Li <thinker@branda.to>
parents:
411
diff
changeset
|
623 |
a456e267279a
Test cases for shape_stext.
Thinker K.F. Li <thinker@branda.to>
parents:
411
diff
changeset
|
624 static |
a456e267279a
Test cases for shape_stext.
Thinker K.F. Li <thinker@branda.to>
parents:
411
diff
changeset
|
625 void test_query_font_face(void) { |
a456e267279a
Test cases for shape_stext.
Thinker K.F. Li <thinker@branda.to>
parents:
411
diff
changeset
|
626 mb_font_face_t *face; |
a456e267279a
Test cases for shape_stext.
Thinker K.F. Li <thinker@branda.to>
parents:
411
diff
changeset
|
627 |
413
35712e4bad0e
Make shape_stext.c pass test cases.
Thinker K.F. Li <thinker@branda.to>
parents:
412
diff
changeset
|
628 face = query_font_face("serif", MB_FONT_SLANT_ROMAN, 100); |
412
a456e267279a
Test cases for shape_stext.
Thinker K.F. Li <thinker@branda.to>
parents:
411
diff
changeset
|
629 CU_ASSERT(face != NULL); |
822
586e50f82c1f
Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents:
760
diff
changeset
|
630 |
413
35712e4bad0e
Make shape_stext.c pass test cases.
Thinker K.F. Li <thinker@branda.to>
parents:
412
diff
changeset
|
631 free_font_face(face); |
412
a456e267279a
Test cases for shape_stext.
Thinker K.F. Li <thinker@branda.to>
parents:
411
diff
changeset
|
632 } |
a456e267279a
Test cases for shape_stext.
Thinker K.F. Li <thinker@branda.to>
parents:
411
diff
changeset
|
633 |
a456e267279a
Test cases for shape_stext.
Thinker K.F. Li <thinker@branda.to>
parents:
411
diff
changeset
|
634 static |
a456e267279a
Test cases for shape_stext.
Thinker K.F. Li <thinker@branda.to>
parents:
411
diff
changeset
|
635 void test_make_scaled_font_face_matrix(void) { |
413
35712e4bad0e
Make shape_stext.c pass test cases.
Thinker K.F. Li <thinker@branda.to>
parents:
412
diff
changeset
|
636 co_aix matrix[6] = {5, 0, 0, 0, 5, 0}; |
412
a456e267279a
Test cases for shape_stext.
Thinker K.F. Li <thinker@branda.to>
parents:
411
diff
changeset
|
637 mb_font_face_t *face; |
a456e267279a
Test cases for shape_stext.
Thinker K.F. Li <thinker@branda.to>
parents:
411
diff
changeset
|
638 mb_scaled_font_t *scaled; |
a456e267279a
Test cases for shape_stext.
Thinker K.F. Li <thinker@branda.to>
parents:
411
diff
changeset
|
639 |
413
35712e4bad0e
Make shape_stext.c pass test cases.
Thinker K.F. Li <thinker@branda.to>
parents:
412
diff
changeset
|
640 face = query_font_face("serif", MB_FONT_SLANT_ROMAN, 100); |
35712e4bad0e
Make shape_stext.c pass test cases.
Thinker K.F. Li <thinker@branda.to>
parents:
412
diff
changeset
|
641 CU_ASSERT(face != NULL); |
822
586e50f82c1f
Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents:
760
diff
changeset
|
642 |
412
a456e267279a
Test cases for shape_stext.
Thinker K.F. Li <thinker@branda.to>
parents:
411
diff
changeset
|
643 scaled = make_scaled_font_face_matrix(face, matrix); |
a456e267279a
Test cases for shape_stext.
Thinker K.F. Li <thinker@branda.to>
parents:
411
diff
changeset
|
644 CU_ASSERT(scaled != NULL); |
822
586e50f82c1f
Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents:
760
diff
changeset
|
645 |
412
a456e267279a
Test cases for shape_stext.
Thinker K.F. Li <thinker@branda.to>
parents:
411
diff
changeset
|
646 scaled_font_free(scaled); |
413
35712e4bad0e
Make shape_stext.c pass test cases.
Thinker K.F. Li <thinker@branda.to>
parents:
412
diff
changeset
|
647 free_font_face(face); |
412
a456e267279a
Test cases for shape_stext.
Thinker K.F. Li <thinker@branda.to>
parents:
411
diff
changeset
|
648 } |
a456e267279a
Test cases for shape_stext.
Thinker K.F. Li <thinker@branda.to>
parents:
411
diff
changeset
|
649 |
410
1a923ea699c1
shape_stext.c, now, is unittested.
Thinker K.F. Li <thinker@branda.to>
parents:
407
diff
changeset
|
650 static |
1a923ea699c1
shape_stext.c, now, is unittested.
Thinker K.F. Li <thinker@branda.to>
parents:
407
diff
changeset
|
651 void test_compute_text_extents(void) { |
413
35712e4bad0e
Make shape_stext.c pass test cases.
Thinker K.F. Li <thinker@branda.to>
parents:
412
diff
changeset
|
652 co_aix matrix[6] = {10, 0, 0, 0, 10, 0}; |
423
3ba48126c49c
Check bearing and advance of text_extents.
Thinker K.F. Li <thinker@branda.to>
parents:
422
diff
changeset
|
653 co_aix x_adv1, x_adv2; |
3ba48126c49c
Check bearing and advance of text_extents.
Thinker K.F. Li <thinker@branda.to>
parents:
422
diff
changeset
|
654 co_aix x_bearing1, x_bearing2; |
412
a456e267279a
Test cases for shape_stext.
Thinker K.F. Li <thinker@branda.to>
parents:
411
diff
changeset
|
655 mb_font_face_t *face; |
a456e267279a
Test cases for shape_stext.
Thinker K.F. Li <thinker@branda.to>
parents:
411
diff
changeset
|
656 mb_scaled_font_t *scaled; |
a456e267279a
Test cases for shape_stext.
Thinker K.F. Li <thinker@branda.to>
parents:
411
diff
changeset
|
657 mb_text_extents_t ext; |
a456e267279a
Test cases for shape_stext.
Thinker K.F. Li <thinker@branda.to>
parents:
411
diff
changeset
|
658 |
413
35712e4bad0e
Make shape_stext.c pass test cases.
Thinker K.F. Li <thinker@branda.to>
parents:
412
diff
changeset
|
659 face = query_font_face("serif", MB_FONT_SLANT_ROMAN, 100); |
35712e4bad0e
Make shape_stext.c pass test cases.
Thinker K.F. Li <thinker@branda.to>
parents:
412
diff
changeset
|
660 CU_ASSERT(face != NULL) |
412
a456e267279a
Test cases for shape_stext.
Thinker K.F. Li <thinker@branda.to>
parents:
411
diff
changeset
|
661 scaled = make_scaled_font_face_matrix(face, matrix); |
a456e267279a
Test cases for shape_stext.
Thinker K.F. Li <thinker@branda.to>
parents:
411
diff
changeset
|
662 CU_ASSERT(scaled != NULL); |
a456e267279a
Test cases for shape_stext.
Thinker K.F. Li <thinker@branda.to>
parents:
411
diff
changeset
|
663 |
a456e267279a
Test cases for shape_stext.
Thinker K.F. Li <thinker@branda.to>
parents:
411
diff
changeset
|
664 compute_text_extents(scaled, "test", &ext); |
414
bbf036c315be
Fix extent_extents to make it pass the test case.
Thinker K.F. Li <thinker@branda.to>
parents:
413
diff
changeset
|
665 CU_ASSERT(MBE_GET_HEIGHT(&ext) >= 5 && MBE_GET_HEIGHT(&ext) <= 12); |
bbf036c315be
Fix extent_extents to make it pass the test case.
Thinker K.F. Li <thinker@branda.to>
parents:
413
diff
changeset
|
666 CU_ASSERT(MBE_GET_WIDTH(&ext) >= 16 && MBE_GET_WIDTH(&ext) <= 48); |
423
3ba48126c49c
Check bearing and advance of text_extents.
Thinker K.F. Li <thinker@branda.to>
parents:
422
diff
changeset
|
667 x_adv1 = MBE_GET_X_ADV(&ext); |
3ba48126c49c
Check bearing and advance of text_extents.
Thinker K.F. Li <thinker@branda.to>
parents:
422
diff
changeset
|
668 x_bearing1 = MBE_GET_X_BEARING(&ext); |
3ba48126c49c
Check bearing and advance of text_extents.
Thinker K.F. Li <thinker@branda.to>
parents:
422
diff
changeset
|
669 scaled_font_free(scaled); |
412
a456e267279a
Test cases for shape_stext.
Thinker K.F. Li <thinker@branda.to>
parents:
411
diff
changeset
|
670 |
423
3ba48126c49c
Check bearing and advance of text_extents.
Thinker K.F. Li <thinker@branda.to>
parents:
422
diff
changeset
|
671 matrix[2] = 5; |
3ba48126c49c
Check bearing and advance of text_extents.
Thinker K.F. Li <thinker@branda.to>
parents:
422
diff
changeset
|
672 scaled = make_scaled_font_face_matrix(face, matrix); |
3ba48126c49c
Check bearing and advance of text_extents.
Thinker K.F. Li <thinker@branda.to>
parents:
422
diff
changeset
|
673 CU_ASSERT(scaled != NULL); |
3ba48126c49c
Check bearing and advance of text_extents.
Thinker K.F. Li <thinker@branda.to>
parents:
422
diff
changeset
|
674 |
3ba48126c49c
Check bearing and advance of text_extents.
Thinker K.F. Li <thinker@branda.to>
parents:
422
diff
changeset
|
675 compute_text_extents(scaled, "test", &ext); |
3ba48126c49c
Check bearing and advance of text_extents.
Thinker K.F. Li <thinker@branda.to>
parents:
422
diff
changeset
|
676 CU_ASSERT(MBE_GET_HEIGHT(&ext) >= 5 && MBE_GET_HEIGHT(&ext) <= 12); |
3ba48126c49c
Check bearing and advance of text_extents.
Thinker K.F. Li <thinker@branda.to>
parents:
422
diff
changeset
|
677 CU_ASSERT(MBE_GET_WIDTH(&ext) >= 16 && MBE_GET_WIDTH(&ext) <= 48); |
3ba48126c49c
Check bearing and advance of text_extents.
Thinker K.F. Li <thinker@branda.to>
parents:
422
diff
changeset
|
678 x_adv2 = MBE_GET_X_ADV(&ext); |
3ba48126c49c
Check bearing and advance of text_extents.
Thinker K.F. Li <thinker@branda.to>
parents:
422
diff
changeset
|
679 x_bearing2 = MBE_GET_X_BEARING(&ext); |
412
a456e267279a
Test cases for shape_stext.
Thinker K.F. Li <thinker@branda.to>
parents:
411
diff
changeset
|
680 scaled_font_free(scaled); |
423
3ba48126c49c
Check bearing and advance of text_extents.
Thinker K.F. Li <thinker@branda.to>
parents:
422
diff
changeset
|
681 |
3ba48126c49c
Check bearing and advance of text_extents.
Thinker K.F. Li <thinker@branda.to>
parents:
422
diff
changeset
|
682 CU_ASSERT(x_adv1 == x_adv2); |
3ba48126c49c
Check bearing and advance of text_extents.
Thinker K.F. Li <thinker@branda.to>
parents:
422
diff
changeset
|
683 CU_ASSERT((x_bearing1 + 5) == x_bearing2); |
3ba48126c49c
Check bearing and advance of text_extents.
Thinker K.F. Li <thinker@branda.to>
parents:
422
diff
changeset
|
684 |
413
35712e4bad0e
Make shape_stext.c pass test cases.
Thinker K.F. Li <thinker@branda.to>
parents:
412
diff
changeset
|
685 free_font_face(face); |
410
1a923ea699c1
shape_stext.c, now, is unittested.
Thinker K.F. Li <thinker@branda.to>
parents:
407
diff
changeset
|
686 } |
1a923ea699c1
shape_stext.c, now, is unittested.
Thinker K.F. Li <thinker@branda.to>
parents:
407
diff
changeset
|
687 |
414
bbf036c315be
Fix extent_extents to make it pass the test case.
Thinker K.F. Li <thinker@branda.to>
parents:
413
diff
changeset
|
688 static |
bbf036c315be
Fix extent_extents to make it pass the test case.
Thinker K.F. Li <thinker@branda.to>
parents:
413
diff
changeset
|
689 void test_extent_extents(void) { |
bbf036c315be
Fix extent_extents to make it pass the test case.
Thinker K.F. Li <thinker@branda.to>
parents:
413
diff
changeset
|
690 mb_text_extents_t ext1, ext2; |
bbf036c315be
Fix extent_extents to make it pass the test case.
Thinker K.F. Li <thinker@branda.to>
parents:
413
diff
changeset
|
691 |
bbf036c315be
Fix extent_extents to make it pass the test case.
Thinker K.F. Li <thinker@branda.to>
parents:
413
diff
changeset
|
692 MBE_SET_WIDTH(&ext1, 20); |
bbf036c315be
Fix extent_extents to make it pass the test case.
Thinker K.F. Li <thinker@branda.to>
parents:
413
diff
changeset
|
693 MBE_SET_HEIGHT(&ext1, 10); |
bbf036c315be
Fix extent_extents to make it pass the test case.
Thinker K.F. Li <thinker@branda.to>
parents:
413
diff
changeset
|
694 MBE_SET_X_BEARING(&ext1, 1); |
bbf036c315be
Fix extent_extents to make it pass the test case.
Thinker K.F. Li <thinker@branda.to>
parents:
413
diff
changeset
|
695 MBE_SET_Y_BEARING(&ext1, -8); |
bbf036c315be
Fix extent_extents to make it pass the test case.
Thinker K.F. Li <thinker@branda.to>
parents:
413
diff
changeset
|
696 MBE_SET_X_ADV(&ext1, 21); |
bbf036c315be
Fix extent_extents to make it pass the test case.
Thinker K.F. Li <thinker@branda.to>
parents:
413
diff
changeset
|
697 MBE_SET_Y_ADV(&ext1, -3); |
822
586e50f82c1f
Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents:
760
diff
changeset
|
698 |
414
bbf036c315be
Fix extent_extents to make it pass the test case.
Thinker K.F. Li <thinker@branda.to>
parents:
413
diff
changeset
|
699 MBE_SET_WIDTH(&ext2, 30); |
bbf036c315be
Fix extent_extents to make it pass the test case.
Thinker K.F. Li <thinker@branda.to>
parents:
413
diff
changeset
|
700 MBE_SET_HEIGHT(&ext2, 11); |
bbf036c315be
Fix extent_extents to make it pass the test case.
Thinker K.F. Li <thinker@branda.to>
parents:
413
diff
changeset
|
701 MBE_SET_X_BEARING(&ext2, 2); |
bbf036c315be
Fix extent_extents to make it pass the test case.
Thinker K.F. Li <thinker@branda.to>
parents:
413
diff
changeset
|
702 MBE_SET_Y_BEARING(&ext2, -11); |
bbf036c315be
Fix extent_extents to make it pass the test case.
Thinker K.F. Li <thinker@branda.to>
parents:
413
diff
changeset
|
703 MBE_SET_X_ADV(&ext2, 32); |
bbf036c315be
Fix extent_extents to make it pass the test case.
Thinker K.F. Li <thinker@branda.to>
parents:
413
diff
changeset
|
704 MBE_SET_Y_ADV(&ext2, -5); |
822
586e50f82c1f
Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents:
760
diff
changeset
|
705 |
414
bbf036c315be
Fix extent_extents to make it pass the test case.
Thinker K.F. Li <thinker@branda.to>
parents:
413
diff
changeset
|
706 extent_extents(&ext1, &ext2); |
bbf036c315be
Fix extent_extents to make it pass the test case.
Thinker K.F. Li <thinker@branda.to>
parents:
413
diff
changeset
|
707 |
bbf036c315be
Fix extent_extents to make it pass the test case.
Thinker K.F. Li <thinker@branda.to>
parents:
413
diff
changeset
|
708 CU_ASSERT(MBE_GET_WIDTH(&ext1) == 52); |
bbf036c315be
Fix extent_extents to make it pass the test case.
Thinker K.F. Li <thinker@branda.to>
parents:
413
diff
changeset
|
709 CU_ASSERT(MBE_GET_HEIGHT(&ext1) == 16); |
bbf036c315be
Fix extent_extents to make it pass the test case.
Thinker K.F. Li <thinker@branda.to>
parents:
413
diff
changeset
|
710 CU_ASSERT(MBE_GET_X_BEARING(&ext1) == 1); |
bbf036c315be
Fix extent_extents to make it pass the test case.
Thinker K.F. Li <thinker@branda.to>
parents:
413
diff
changeset
|
711 CU_ASSERT(MBE_GET_Y_BEARING(&ext1) == -14); |
bbf036c315be
Fix extent_extents to make it pass the test case.
Thinker K.F. Li <thinker@branda.to>
parents:
413
diff
changeset
|
712 CU_ASSERT(MBE_GET_X_ADV(&ext1) == 53); |
bbf036c315be
Fix extent_extents to make it pass the test case.
Thinker K.F. Li <thinker@branda.to>
parents:
413
diff
changeset
|
713 CU_ASSERT(MBE_GET_Y_ADV(&ext1) == -8); |
bbf036c315be
Fix extent_extents to make it pass the test case.
Thinker K.F. Li <thinker@branda.to>
parents:
413
diff
changeset
|
714 } |
bbf036c315be
Fix extent_extents to make it pass the test case.
Thinker K.F. Li <thinker@branda.to>
parents:
413
diff
changeset
|
715 |
415
fef1b8076041
Make compute_utf8_chars_sz to compute length of n UTF 8 characters correctly.
Thinker K.F. Li <thinker@branda.to>
parents:
414
diff
changeset
|
716 static |
fef1b8076041
Make compute_utf8_chars_sz to compute length of n UTF 8 characters correctly.
Thinker K.F. Li <thinker@branda.to>
parents:
414
diff
changeset
|
717 void test_compute_utf8_chars_sz(void) { |
fef1b8076041
Make compute_utf8_chars_sz to compute length of n UTF 8 characters correctly.
Thinker K.F. Li <thinker@branda.to>
parents:
414
diff
changeset
|
718 const char *str = "\xe4\xb8\xad\xe6\x96\x87test\xe6\xb8\xac\xe8\xa9\xa6"; |
fef1b8076041
Make compute_utf8_chars_sz to compute length of n UTF 8 characters correctly.
Thinker K.F. Li <thinker@branda.to>
parents:
414
diff
changeset
|
719 int sz; |
822
586e50f82c1f
Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents:
760
diff
changeset
|
720 |
415
fef1b8076041
Make compute_utf8_chars_sz to compute length of n UTF 8 characters correctly.
Thinker K.F. Li <thinker@branda.to>
parents:
414
diff
changeset
|
721 sz = compute_utf8_chars_sz(str, 4); |
fef1b8076041
Make compute_utf8_chars_sz to compute length of n UTF 8 characters correctly.
Thinker K.F. Li <thinker@branda.to>
parents:
414
diff
changeset
|
722 CU_ASSERT(sz == 8); |
fef1b8076041
Make compute_utf8_chars_sz to compute length of n UTF 8 characters correctly.
Thinker K.F. Li <thinker@branda.to>
parents:
414
diff
changeset
|
723 |
fef1b8076041
Make compute_utf8_chars_sz to compute length of n UTF 8 characters correctly.
Thinker K.F. Li <thinker@branda.to>
parents:
414
diff
changeset
|
724 sz = compute_utf8_chars_sz(str, 9); |
fef1b8076041
Make compute_utf8_chars_sz to compute length of n UTF 8 characters correctly.
Thinker K.F. Li <thinker@branda.to>
parents:
414
diff
changeset
|
725 CU_ASSERT(sz == ERR); |
fef1b8076041
Make compute_utf8_chars_sz to compute length of n UTF 8 characters correctly.
Thinker K.F. Li <thinker@branda.to>
parents:
414
diff
changeset
|
726 } |
fef1b8076041
Make compute_utf8_chars_sz to compute length of n UTF 8 characters correctly.
Thinker K.F. Li <thinker@branda.to>
parents:
414
diff
changeset
|
727 |
421
1e48453bb282
Make compute_styled_extents_n_scaled_font() pass the test.
Thinker K.F. Li <thinker@branda.to>
parents:
420
diff
changeset
|
728 static |
1e48453bb282
Make compute_styled_extents_n_scaled_font() pass the test.
Thinker K.F. Li <thinker@branda.to>
parents:
420
diff
changeset
|
729 void test_compute_styled_extents_n_scaled_font(void) { |
1e48453bb282
Make compute_styled_extents_n_scaled_font() pass the test.
Thinker K.F. Li <thinker@branda.to>
parents:
420
diff
changeset
|
730 sh_stext_t *txt_o; |
1e48453bb282
Make compute_styled_extents_n_scaled_font() pass the test.
Thinker K.F. Li <thinker@branda.to>
parents:
420
diff
changeset
|
731 co_aix *aggr; |
1e48453bb282
Make compute_styled_extents_n_scaled_font() pass the test.
Thinker K.F. Li <thinker@branda.to>
parents:
420
diff
changeset
|
732 mb_style_blk_t blks[2]; |
1e48453bb282
Make compute_styled_extents_n_scaled_font() pass the test.
Thinker K.F. Li <thinker@branda.to>
parents:
420
diff
changeset
|
733 mb_font_face_t *face; |
1e48453bb282
Make compute_styled_extents_n_scaled_font() pass the test.
Thinker K.F. Li <thinker@branda.to>
parents:
420
diff
changeset
|
734 mb_text_extents_t *ext; |
1e48453bb282
Make compute_styled_extents_n_scaled_font() pass the test.
Thinker K.F. Li <thinker@branda.to>
parents:
420
diff
changeset
|
735 int r; |
1e48453bb282
Make compute_styled_extents_n_scaled_font() pass the test.
Thinker K.F. Li <thinker@branda.to>
parents:
420
diff
changeset
|
736 |
1e48453bb282
Make compute_styled_extents_n_scaled_font() pass the test.
Thinker K.F. Li <thinker@branda.to>
parents:
420
diff
changeset
|
737 txt_o = (sh_stext_t *)rdman_shape_stext_new((redraw_man_t *)NULL, |
429
9d5506968efb
Change the interface of rdman_shape_stext_new().
Thinker K.F. Li <thinker@branda.to>
parents:
427
diff
changeset
|
738 "Hello World", 10, 15); |
421
1e48453bb282
Make compute_styled_extents_n_scaled_font() pass the test.
Thinker K.F. Li <thinker@branda.to>
parents:
420
diff
changeset
|
739 CU_ASSERT(txt_o != NULL); |
1e48453bb282
Make compute_styled_extents_n_scaled_font() pass the test.
Thinker K.F. Li <thinker@branda.to>
parents:
420
diff
changeset
|
740 |
1e48453bb282
Make compute_styled_extents_n_scaled_font() pass the test.
Thinker K.F. Li <thinker@branda.to>
parents:
420
diff
changeset
|
741 aggr = txt_o->shape.aggr; |
1e48453bb282
Make compute_styled_extents_n_scaled_font() pass the test.
Thinker K.F. Li <thinker@branda.to>
parents:
420
diff
changeset
|
742 aggr[0] = 1; |
1e48453bb282
Make compute_styled_extents_n_scaled_font() pass the test.
Thinker K.F. Li <thinker@branda.to>
parents:
420
diff
changeset
|
743 aggr[1] = 0; |
1e48453bb282
Make compute_styled_extents_n_scaled_font() pass the test.
Thinker K.F. Li <thinker@branda.to>
parents:
420
diff
changeset
|
744 aggr[2] = 0; |
1e48453bb282
Make compute_styled_extents_n_scaled_font() pass the test.
Thinker K.F. Li <thinker@branda.to>
parents:
420
diff
changeset
|
745 aggr[3] = 0; |
1e48453bb282
Make compute_styled_extents_n_scaled_font() pass the test.
Thinker K.F. Li <thinker@branda.to>
parents:
420
diff
changeset
|
746 aggr[4] = 1; |
1e48453bb282
Make compute_styled_extents_n_scaled_font() pass the test.
Thinker K.F. Li <thinker@branda.to>
parents:
420
diff
changeset
|
747 aggr[5] = 0; |
1e48453bb282
Make compute_styled_extents_n_scaled_font() pass the test.
Thinker K.F. Li <thinker@branda.to>
parents:
420
diff
changeset
|
748 |
1e48453bb282
Make compute_styled_extents_n_scaled_font() pass the test.
Thinker K.F. Li <thinker@branda.to>
parents:
420
diff
changeset
|
749 face = query_font_face("serif", MB_FONT_SLANT_ROMAN, 100); |
1e48453bb282
Make compute_styled_extents_n_scaled_font() pass the test.
Thinker K.F. Li <thinker@branda.to>
parents:
420
diff
changeset
|
750 CU_ASSERT(face != NULL); |
822
586e50f82c1f
Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents:
760
diff
changeset
|
751 |
421
1e48453bb282
Make compute_styled_extents_n_scaled_font() pass the test.
Thinker K.F. Li <thinker@branda.to>
parents:
420
diff
changeset
|
752 blks[0].n_chars = 5; |
1e48453bb282
Make compute_styled_extents_n_scaled_font() pass the test.
Thinker K.F. Li <thinker@branda.to>
parents:
420
diff
changeset
|
753 blks[0].face = face; |
1e48453bb282
Make compute_styled_extents_n_scaled_font() pass the test.
Thinker K.F. Li <thinker@branda.to>
parents:
420
diff
changeset
|
754 blks[0].font_sz = 10; |
822
586e50f82c1f
Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents:
760
diff
changeset
|
755 |
421
1e48453bb282
Make compute_styled_extents_n_scaled_font() pass the test.
Thinker K.F. Li <thinker@branda.to>
parents:
420
diff
changeset
|
756 blks[1].n_chars = 4; |
1e48453bb282
Make compute_styled_extents_n_scaled_font() pass the test.
Thinker K.F. Li <thinker@branda.to>
parents:
420
diff
changeset
|
757 blks[1].face = face; |
1e48453bb282
Make compute_styled_extents_n_scaled_font() pass the test.
Thinker K.F. Li <thinker@branda.to>
parents:
420
diff
changeset
|
758 blks[1].font_sz = 15.5; |
822
586e50f82c1f
Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents:
760
diff
changeset
|
759 |
421
1e48453bb282
Make compute_styled_extents_n_scaled_font() pass the test.
Thinker K.F. Li <thinker@branda.to>
parents:
420
diff
changeset
|
760 r = sh_stext_set_style((shape_t *)txt_o, blks, 2); |
1e48453bb282
Make compute_styled_extents_n_scaled_font() pass the test.
Thinker K.F. Li <thinker@branda.to>
parents:
420
diff
changeset
|
761 CU_ASSERT(r == OK); |
1e48453bb282
Make compute_styled_extents_n_scaled_font() pass the test.
Thinker K.F. Li <thinker@branda.to>
parents:
420
diff
changeset
|
762 |
1e48453bb282
Make compute_styled_extents_n_scaled_font() pass the test.
Thinker K.F. Li <thinker@branda.to>
parents:
420
diff
changeset
|
763 compute_styled_extents_n_scaled_font(txt_o); |
1e48453bb282
Make compute_styled_extents_n_scaled_font() pass the test.
Thinker K.F. Li <thinker@branda.to>
parents:
420
diff
changeset
|
764 |
1e48453bb282
Make compute_styled_extents_n_scaled_font() pass the test.
Thinker K.F. Li <thinker@branda.to>
parents:
420
diff
changeset
|
765 ext = &txt_o->extents; |
1e48453bb282
Make compute_styled_extents_n_scaled_font() pass the test.
Thinker K.F. Li <thinker@branda.to>
parents:
420
diff
changeset
|
766 CU_ASSERT(MBE_GET_HEIGHT(ext) > 11); |
1e48453bb282
Make compute_styled_extents_n_scaled_font() pass the test.
Thinker K.F. Li <thinker@branda.to>
parents:
420
diff
changeset
|
767 CU_ASSERT(MBE_GET_HEIGHT(ext) < 20); |
1e48453bb282
Make compute_styled_extents_n_scaled_font() pass the test.
Thinker K.F. Li <thinker@branda.to>
parents:
420
diff
changeset
|
768 CU_ASSERT(MBE_GET_WIDTH(ext) > 36); |
1e48453bb282
Make compute_styled_extents_n_scaled_font() pass the test.
Thinker K.F. Li <thinker@branda.to>
parents:
420
diff
changeset
|
769 CU_ASSERT(MBE_GET_WIDTH(ext) < 72); |
1e48453bb282
Make compute_styled_extents_n_scaled_font() pass the test.
Thinker K.F. Li <thinker@branda.to>
parents:
420
diff
changeset
|
770 CU_ASSERT(MBE_GET_X_ADV(ext) > 36); |
1e48453bb282
Make compute_styled_extents_n_scaled_font() pass the test.
Thinker K.F. Li <thinker@branda.to>
parents:
420
diff
changeset
|
771 CU_ASSERT(MBE_GET_X_ADV(ext) < 72); |
1e48453bb282
Make compute_styled_extents_n_scaled_font() pass the test.
Thinker K.F. Li <thinker@branda.to>
parents:
420
diff
changeset
|
772 CU_ASSERT(MBE_GET_Y_ADV(ext) == 0); |
822
586e50f82c1f
Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents:
760
diff
changeset
|
773 |
421
1e48453bb282
Make compute_styled_extents_n_scaled_font() pass the test.
Thinker K.F. Li <thinker@branda.to>
parents:
420
diff
changeset
|
774 _rdman_shape_stext_free((shape_t *)txt_o); |
1e48453bb282
Make compute_styled_extents_n_scaled_font() pass the test.
Thinker K.F. Li <thinker@branda.to>
parents:
420
diff
changeset
|
775 free_font_face(face); |
1e48453bb282
Make compute_styled_extents_n_scaled_font() pass the test.
Thinker K.F. Li <thinker@branda.to>
parents:
420
diff
changeset
|
776 } |
1e48453bb282
Make compute_styled_extents_n_scaled_font() pass the test.
Thinker K.F. Li <thinker@branda.to>
parents:
420
diff
changeset
|
777 |
424
585baa462778
Make sh_stext_transform() pass first test case for him.
Thinker K.F. Li <thinker@branda.to>
parents:
423
diff
changeset
|
778 static |
433
099941c3becf
Test cases for ratation on sh_stext
Thinker K.F. Li <thinker@branda.to>
parents:
429
diff
changeset
|
779 void test_compute_styled_extents_n_scaled_font_rotate(void) { |
099941c3becf
Test cases for ratation on sh_stext
Thinker K.F. Li <thinker@branda.to>
parents:
429
diff
changeset
|
780 sh_stext_t *txt_o; |
099941c3becf
Test cases for ratation on sh_stext
Thinker K.F. Li <thinker@branda.to>
parents:
429
diff
changeset
|
781 co_aix *aggr; |
099941c3becf
Test cases for ratation on sh_stext
Thinker K.F. Li <thinker@branda.to>
parents:
429
diff
changeset
|
782 mb_style_blk_t blks[2]; |
099941c3becf
Test cases for ratation on sh_stext
Thinker K.F. Li <thinker@branda.to>
parents:
429
diff
changeset
|
783 mb_font_face_t *face; |
099941c3becf
Test cases for ratation on sh_stext
Thinker K.F. Li <thinker@branda.to>
parents:
429
diff
changeset
|
784 mb_text_extents_t *ext; |
099941c3becf
Test cases for ratation on sh_stext
Thinker K.F. Li <thinker@branda.to>
parents:
429
diff
changeset
|
785 int r; |
099941c3becf
Test cases for ratation on sh_stext
Thinker K.F. Li <thinker@branda.to>
parents:
429
diff
changeset
|
786 |
099941c3becf
Test cases for ratation on sh_stext
Thinker K.F. Li <thinker@branda.to>
parents:
429
diff
changeset
|
787 txt_o = (sh_stext_t *)rdman_shape_stext_new((redraw_man_t *)NULL, |
099941c3becf
Test cases for ratation on sh_stext
Thinker K.F. Li <thinker@branda.to>
parents:
429
diff
changeset
|
788 "Hello World", 10, 15); |
099941c3becf
Test cases for ratation on sh_stext
Thinker K.F. Li <thinker@branda.to>
parents:
429
diff
changeset
|
789 CU_ASSERT(txt_o != NULL); |
099941c3becf
Test cases for ratation on sh_stext
Thinker K.F. Li <thinker@branda.to>
parents:
429
diff
changeset
|
790 |
099941c3becf
Test cases for ratation on sh_stext
Thinker K.F. Li <thinker@branda.to>
parents:
429
diff
changeset
|
791 aggr = txt_o->shape.aggr; |
099941c3becf
Test cases for ratation on sh_stext
Thinker K.F. Li <thinker@branda.to>
parents:
429
diff
changeset
|
792 aggr[0] = 1; |
099941c3becf
Test cases for ratation on sh_stext
Thinker K.F. Li <thinker@branda.to>
parents:
429
diff
changeset
|
793 aggr[1] = 0; |
099941c3becf
Test cases for ratation on sh_stext
Thinker K.F. Li <thinker@branda.to>
parents:
429
diff
changeset
|
794 aggr[2] = 0; |
099941c3becf
Test cases for ratation on sh_stext
Thinker K.F. Li <thinker@branda.to>
parents:
429
diff
changeset
|
795 aggr[3] = 1; |
099941c3becf
Test cases for ratation on sh_stext
Thinker K.F. Li <thinker@branda.to>
parents:
429
diff
changeset
|
796 aggr[4] = 1; |
099941c3becf
Test cases for ratation on sh_stext
Thinker K.F. Li <thinker@branda.to>
parents:
429
diff
changeset
|
797 aggr[5] = 0; |
099941c3becf
Test cases for ratation on sh_stext
Thinker K.F. Li <thinker@branda.to>
parents:
429
diff
changeset
|
798 |
099941c3becf
Test cases for ratation on sh_stext
Thinker K.F. Li <thinker@branda.to>
parents:
429
diff
changeset
|
799 face = query_font_face("serif", MB_FONT_SLANT_ROMAN, 100); |
099941c3becf
Test cases for ratation on sh_stext
Thinker K.F. Li <thinker@branda.to>
parents:
429
diff
changeset
|
800 CU_ASSERT(face != NULL); |
822
586e50f82c1f
Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents:
760
diff
changeset
|
801 |
433
099941c3becf
Test cases for ratation on sh_stext
Thinker K.F. Li <thinker@branda.to>
parents:
429
diff
changeset
|
802 blks[0].n_chars = 5; |
099941c3becf
Test cases for ratation on sh_stext
Thinker K.F. Li <thinker@branda.to>
parents:
429
diff
changeset
|
803 blks[0].face = face; |
099941c3becf
Test cases for ratation on sh_stext
Thinker K.F. Li <thinker@branda.to>
parents:
429
diff
changeset
|
804 blks[0].font_sz = 10; |
822
586e50f82c1f
Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents:
760
diff
changeset
|
805 |
433
099941c3becf
Test cases for ratation on sh_stext
Thinker K.F. Li <thinker@branda.to>
parents:
429
diff
changeset
|
806 blks[1].n_chars = 4; |
099941c3becf
Test cases for ratation on sh_stext
Thinker K.F. Li <thinker@branda.to>
parents:
429
diff
changeset
|
807 blks[1].face = face; |
099941c3becf
Test cases for ratation on sh_stext
Thinker K.F. Li <thinker@branda.to>
parents:
429
diff
changeset
|
808 blks[1].font_sz = 15.5; |
822
586e50f82c1f
Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents:
760
diff
changeset
|
809 |
433
099941c3becf
Test cases for ratation on sh_stext
Thinker K.F. Li <thinker@branda.to>
parents:
429
diff
changeset
|
810 r = sh_stext_set_style((shape_t *)txt_o, blks, 2); |
099941c3becf
Test cases for ratation on sh_stext
Thinker K.F. Li <thinker@branda.to>
parents:
429
diff
changeset
|
811 CU_ASSERT(r == OK); |
099941c3becf
Test cases for ratation on sh_stext
Thinker K.F. Li <thinker@branda.to>
parents:
429
diff
changeset
|
812 |
099941c3becf
Test cases for ratation on sh_stext
Thinker K.F. Li <thinker@branda.to>
parents:
429
diff
changeset
|
813 compute_styled_extents_n_scaled_font(txt_o); |
099941c3becf
Test cases for ratation on sh_stext
Thinker K.F. Li <thinker@branda.to>
parents:
429
diff
changeset
|
814 |
099941c3becf
Test cases for ratation on sh_stext
Thinker K.F. Li <thinker@branda.to>
parents:
429
diff
changeset
|
815 ext = &txt_o->extents; |
099941c3becf
Test cases for ratation on sh_stext
Thinker K.F. Li <thinker@branda.to>
parents:
429
diff
changeset
|
816 CU_ASSERT(MBE_GET_HEIGHT(ext) > 47); |
099941c3becf
Test cases for ratation on sh_stext
Thinker K.F. Li <thinker@branda.to>
parents:
429
diff
changeset
|
817 CU_ASSERT(MBE_GET_HEIGHT(ext) < 92); |
099941c3becf
Test cases for ratation on sh_stext
Thinker K.F. Li <thinker@branda.to>
parents:
429
diff
changeset
|
818 CU_ASSERT(MBE_GET_WIDTH(ext) > 36); |
099941c3becf
Test cases for ratation on sh_stext
Thinker K.F. Li <thinker@branda.to>
parents:
429
diff
changeset
|
819 CU_ASSERT(MBE_GET_WIDTH(ext) < 72); |
099941c3becf
Test cases for ratation on sh_stext
Thinker K.F. Li <thinker@branda.to>
parents:
429
diff
changeset
|
820 CU_ASSERT(MBE_GET_X_ADV(ext) > 36); |
099941c3becf
Test cases for ratation on sh_stext
Thinker K.F. Li <thinker@branda.to>
parents:
429
diff
changeset
|
821 CU_ASSERT(MBE_GET_X_ADV(ext) < 72); |
099941c3becf
Test cases for ratation on sh_stext
Thinker K.F. Li <thinker@branda.to>
parents:
429
diff
changeset
|
822 CU_ASSERT(MBE_GET_Y_ADV(ext) > 36); |
099941c3becf
Test cases for ratation on sh_stext
Thinker K.F. Li <thinker@branda.to>
parents:
429
diff
changeset
|
823 CU_ASSERT(MBE_GET_Y_ADV(ext) < 72); |
822
586e50f82c1f
Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents:
760
diff
changeset
|
824 |
433
099941c3becf
Test cases for ratation on sh_stext
Thinker K.F. Li <thinker@branda.to>
parents:
429
diff
changeset
|
825 _rdman_shape_stext_free((shape_t *)txt_o); |
099941c3becf
Test cases for ratation on sh_stext
Thinker K.F. Li <thinker@branda.to>
parents:
429
diff
changeset
|
826 free_font_face(face); |
099941c3becf
Test cases for ratation on sh_stext
Thinker K.F. Li <thinker@branda.to>
parents:
429
diff
changeset
|
827 } |
099941c3becf
Test cases for ratation on sh_stext
Thinker K.F. Li <thinker@branda.to>
parents:
429
diff
changeset
|
828 |
099941c3becf
Test cases for ratation on sh_stext
Thinker K.F. Li <thinker@branda.to>
parents:
429
diff
changeset
|
829 static |
424
585baa462778
Make sh_stext_transform() pass first test case for him.
Thinker K.F. Li <thinker@branda.to>
parents:
423
diff
changeset
|
830 void test_sh_stext_transform(void) { |
585baa462778
Make sh_stext_transform() pass first test case for him.
Thinker K.F. Li <thinker@branda.to>
parents:
423
diff
changeset
|
831 sh_stext_t *txt_o; |
585baa462778
Make sh_stext_transform() pass first test case for him.
Thinker K.F. Li <thinker@branda.to>
parents:
423
diff
changeset
|
832 mb_style_blk_t blks[2]; |
585baa462778
Make sh_stext_transform() pass first test case for him.
Thinker K.F. Li <thinker@branda.to>
parents:
423
diff
changeset
|
833 co_aix *aggr; |
585baa462778
Make sh_stext_transform() pass first test case for him.
Thinker K.F. Li <thinker@branda.to>
parents:
423
diff
changeset
|
834 mb_font_face_t *face; |
585baa462778
Make sh_stext_transform() pass first test case for him.
Thinker K.F. Li <thinker@branda.to>
parents:
423
diff
changeset
|
835 area_t *area; |
585baa462778
Make sh_stext_transform() pass first test case for him.
Thinker K.F. Li <thinker@branda.to>
parents:
423
diff
changeset
|
836 int r; |
585baa462778
Make sh_stext_transform() pass first test case for him.
Thinker K.F. Li <thinker@branda.to>
parents:
423
diff
changeset
|
837 |
429
9d5506968efb
Change the interface of rdman_shape_stext_new().
Thinker K.F. Li <thinker@branda.to>
parents:
427
diff
changeset
|
838 txt_o = (sh_stext_t *)rdman_shape_stext_new(NULL, "hello world", 100, 50); |
424
585baa462778
Make sh_stext_transform() pass first test case for him.
Thinker K.F. Li <thinker@branda.to>
parents:
423
diff
changeset
|
839 CU_ASSERT(txt_o != NULL); |
585baa462778
Make sh_stext_transform() pass first test case for him.
Thinker K.F. Li <thinker@branda.to>
parents:
423
diff
changeset
|
840 |
585baa462778
Make sh_stext_transform() pass first test case for him.
Thinker K.F. Li <thinker@branda.to>
parents:
423
diff
changeset
|
841 aggr = txt_o->shape.aggr; |
585baa462778
Make sh_stext_transform() pass first test case for him.
Thinker K.F. Li <thinker@branda.to>
parents:
423
diff
changeset
|
842 aggr[0] = 2; |
585baa462778
Make sh_stext_transform() pass first test case for him.
Thinker K.F. Li <thinker@branda.to>
parents:
423
diff
changeset
|
843 aggr[1] = 0; |
585baa462778
Make sh_stext_transform() pass first test case for him.
Thinker K.F. Li <thinker@branda.to>
parents:
423
diff
changeset
|
844 aggr[2] = 0; |
585baa462778
Make sh_stext_transform() pass first test case for him.
Thinker K.F. Li <thinker@branda.to>
parents:
423
diff
changeset
|
845 aggr[3] = 0; |
585baa462778
Make sh_stext_transform() pass first test case for him.
Thinker K.F. Li <thinker@branda.to>
parents:
423
diff
changeset
|
846 aggr[4] = 1; |
585baa462778
Make sh_stext_transform() pass first test case for him.
Thinker K.F. Li <thinker@branda.to>
parents:
423
diff
changeset
|
847 aggr[5] = 0; |
585baa462778
Make sh_stext_transform() pass first test case for him.
Thinker K.F. Li <thinker@branda.to>
parents:
423
diff
changeset
|
848 |
585baa462778
Make sh_stext_transform() pass first test case for him.
Thinker K.F. Li <thinker@branda.to>
parents:
423
diff
changeset
|
849 face = query_font_face("serif", MB_FONT_SLANT_ROMAN, 100); |
585baa462778
Make sh_stext_transform() pass first test case for him.
Thinker K.F. Li <thinker@branda.to>
parents:
423
diff
changeset
|
850 CU_ASSERT(face != NULL); |
822
586e50f82c1f
Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents:
760
diff
changeset
|
851 |
424
585baa462778
Make sh_stext_transform() pass first test case for him.
Thinker K.F. Li <thinker@branda.to>
parents:
423
diff
changeset
|
852 blks[0].n_chars = 5; |
585baa462778
Make sh_stext_transform() pass first test case for him.
Thinker K.F. Li <thinker@branda.to>
parents:
423
diff
changeset
|
853 blks[0].face = face; |
585baa462778
Make sh_stext_transform() pass first test case for him.
Thinker K.F. Li <thinker@branda.to>
parents:
423
diff
changeset
|
854 blks[0].font_sz = 10; |
822
586e50f82c1f
Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents:
760
diff
changeset
|
855 |
424
585baa462778
Make sh_stext_transform() pass first test case for him.
Thinker K.F. Li <thinker@branda.to>
parents:
423
diff
changeset
|
856 blks[1].n_chars = 4; |
585baa462778
Make sh_stext_transform() pass first test case for him.
Thinker K.F. Li <thinker@branda.to>
parents:
423
diff
changeset
|
857 blks[1].face = face; |
585baa462778
Make sh_stext_transform() pass first test case for him.
Thinker K.F. Li <thinker@branda.to>
parents:
423
diff
changeset
|
858 blks[1].font_sz = 15.5; |
822
586e50f82c1f
Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents:
760
diff
changeset
|
859 |
424
585baa462778
Make sh_stext_transform() pass first test case for him.
Thinker K.F. Li <thinker@branda.to>
parents:
423
diff
changeset
|
860 r = sh_stext_set_style((shape_t *)txt_o, blks, 2); |
585baa462778
Make sh_stext_transform() pass first test case for him.
Thinker K.F. Li <thinker@branda.to>
parents:
423
diff
changeset
|
861 CU_ASSERT(r == OK); |
585baa462778
Make sh_stext_transform() pass first test case for him.
Thinker K.F. Li <thinker@branda.to>
parents:
423
diff
changeset
|
862 |
585baa462778
Make sh_stext_transform() pass first test case for him.
Thinker K.F. Li <thinker@branda.to>
parents:
423
diff
changeset
|
863 sh_stext_transform((shape_t *)txt_o); |
585baa462778
Make sh_stext_transform() pass first test case for him.
Thinker K.F. Li <thinker@branda.to>
parents:
423
diff
changeset
|
864 |
585baa462778
Make sh_stext_transform() pass first test case for him.
Thinker K.F. Li <thinker@branda.to>
parents:
423
diff
changeset
|
865 area = sh_get_area((shape_t *)txt_o); |
585baa462778
Make sh_stext_transform() pass first test case for him.
Thinker K.F. Li <thinker@branda.to>
parents:
423
diff
changeset
|
866 CU_ASSERT(area->x >= 200 && area->x < 220); |
585baa462778
Make sh_stext_transform() pass first test case for him.
Thinker K.F. Li <thinker@branda.to>
parents:
423
diff
changeset
|
867 CU_ASSERT(area->y >= 40 && area->y < 50); |
585baa462778
Make sh_stext_transform() pass first test case for him.
Thinker K.F. Li <thinker@branda.to>
parents:
423
diff
changeset
|
868 CU_ASSERT(area->w >= 80 && area->w < 120); |
585baa462778
Make sh_stext_transform() pass first test case for him.
Thinker K.F. Li <thinker@branda.to>
parents:
423
diff
changeset
|
869 CU_ASSERT(area->h >= 8 && area->h < 12); |
822
586e50f82c1f
Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents:
760
diff
changeset
|
870 |
424
585baa462778
Make sh_stext_transform() pass first test case for him.
Thinker K.F. Li <thinker@branda.to>
parents:
423
diff
changeset
|
871 _rdman_shape_stext_free((shape_t *)txt_o); |
585baa462778
Make sh_stext_transform() pass first test case for him.
Thinker K.F. Li <thinker@branda.to>
parents:
423
diff
changeset
|
872 free_font_face(face); |
585baa462778
Make sh_stext_transform() pass first test case for him.
Thinker K.F. Li <thinker@branda.to>
parents:
423
diff
changeset
|
873 } |
585baa462778
Make sh_stext_transform() pass first test case for him.
Thinker K.F. Li <thinker@branda.to>
parents:
423
diff
changeset
|
874 |
427
8f900da42eed
Make sh_text_draw() passes first test case.
Thinker K.F. Li <thinker@branda.to>
parents:
426
diff
changeset
|
875 static |
8f900da42eed
Make sh_text_draw() passes first test case.
Thinker K.F. Li <thinker@branda.to>
parents:
426
diff
changeset
|
876 void test_sh_stext_draw(void) { |
8f900da42eed
Make sh_text_draw() passes first test case.
Thinker K.F. Li <thinker@branda.to>
parents:
426
diff
changeset
|
877 sh_stext_t *txt_o; |
8f900da42eed
Make sh_text_draw() passes first test case.
Thinker K.F. Li <thinker@branda.to>
parents:
426
diff
changeset
|
878 mb_style_blk_t blks[2]; |
8f900da42eed
Make sh_text_draw() passes first test case.
Thinker K.F. Li <thinker@branda.to>
parents:
426
diff
changeset
|
879 co_aix *aggr; |
8f900da42eed
Make sh_text_draw() passes first test case.
Thinker K.F. Li <thinker@branda.to>
parents:
426
diff
changeset
|
880 mb_font_face_t *face; |
8f900da42eed
Make sh_text_draw() passes first test case.
Thinker K.F. Li <thinker@branda.to>
parents:
426
diff
changeset
|
881 area_t *area; |
8f900da42eed
Make sh_text_draw() passes first test case.
Thinker K.F. Li <thinker@branda.to>
parents:
426
diff
changeset
|
882 int r; |
8f900da42eed
Make sh_text_draw() passes first test case.
Thinker K.F. Li <thinker@branda.to>
parents:
426
diff
changeset
|
883 |
429
9d5506968efb
Change the interface of rdman_shape_stext_new().
Thinker K.F. Li <thinker@branda.to>
parents:
427
diff
changeset
|
884 txt_o = (sh_stext_t *)rdman_shape_stext_new(NULL, "hello world", 100, 50); |
427
8f900da42eed
Make sh_text_draw() passes first test case.
Thinker K.F. Li <thinker@branda.to>
parents:
426
diff
changeset
|
885 CU_ASSERT(txt_o != NULL); |
822
586e50f82c1f
Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents:
760
diff
changeset
|
886 |
427
8f900da42eed
Make sh_text_draw() passes first test case.
Thinker K.F. Li <thinker@branda.to>
parents:
426
diff
changeset
|
887 aggr = txt_o->shape.aggr; |
8f900da42eed
Make sh_text_draw() passes first test case.
Thinker K.F. Li <thinker@branda.to>
parents:
426
diff
changeset
|
888 aggr[0] = 2; |
8f900da42eed
Make sh_text_draw() passes first test case.
Thinker K.F. Li <thinker@branda.to>
parents:
426
diff
changeset
|
889 aggr[1] = 0; |
8f900da42eed
Make sh_text_draw() passes first test case.
Thinker K.F. Li <thinker@branda.to>
parents:
426
diff
changeset
|
890 aggr[2] = 0; |
8f900da42eed
Make sh_text_draw() passes first test case.
Thinker K.F. Li <thinker@branda.to>
parents:
426
diff
changeset
|
891 aggr[3] = 0; |
8f900da42eed
Make sh_text_draw() passes first test case.
Thinker K.F. Li <thinker@branda.to>
parents:
426
diff
changeset
|
892 aggr[4] = 1; |
8f900da42eed
Make sh_text_draw() passes first test case.
Thinker K.F. Li <thinker@branda.to>
parents:
426
diff
changeset
|
893 aggr[5] = 0; |
8f900da42eed
Make sh_text_draw() passes first test case.
Thinker K.F. Li <thinker@branda.to>
parents:
426
diff
changeset
|
894 |
8f900da42eed
Make sh_text_draw() passes first test case.
Thinker K.F. Li <thinker@branda.to>
parents:
426
diff
changeset
|
895 face = query_font_face("serif", MB_FONT_SLANT_ROMAN, 100); |
8f900da42eed
Make sh_text_draw() passes first test case.
Thinker K.F. Li <thinker@branda.to>
parents:
426
diff
changeset
|
896 CU_ASSERT(face != NULL); |
822
586e50f82c1f
Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents:
760
diff
changeset
|
897 |
427
8f900da42eed
Make sh_text_draw() passes first test case.
Thinker K.F. Li <thinker@branda.to>
parents:
426
diff
changeset
|
898 blks[0].n_chars = 5; |
8f900da42eed
Make sh_text_draw() passes first test case.
Thinker K.F. Li <thinker@branda.to>
parents:
426
diff
changeset
|
899 blks[0].face = face; |
8f900da42eed
Make sh_text_draw() passes first test case.
Thinker K.F. Li <thinker@branda.to>
parents:
426
diff
changeset
|
900 blks[0].font_sz = 10; |
822
586e50f82c1f
Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents:
760
diff
changeset
|
901 |
427
8f900da42eed
Make sh_text_draw() passes first test case.
Thinker K.F. Li <thinker@branda.to>
parents:
426
diff
changeset
|
902 blks[1].n_chars = 6; |
8f900da42eed
Make sh_text_draw() passes first test case.
Thinker K.F. Li <thinker@branda.to>
parents:
426
diff
changeset
|
903 blks[1].face = face; |
8f900da42eed
Make sh_text_draw() passes first test case.
Thinker K.F. Li <thinker@branda.to>
parents:
426
diff
changeset
|
904 blks[1].font_sz = 15.5; |
822
586e50f82c1f
Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents:
760
diff
changeset
|
905 |
427
8f900da42eed
Make sh_text_draw() passes first test case.
Thinker K.F. Li <thinker@branda.to>
parents:
426
diff
changeset
|
906 r = sh_stext_set_style((shape_t *)txt_o, blks, 2); |
8f900da42eed
Make sh_text_draw() passes first test case.
Thinker K.F. Li <thinker@branda.to>
parents:
426
diff
changeset
|
907 CU_ASSERT(r == OK); |
8f900da42eed
Make sh_text_draw() passes first test case.
Thinker K.F. Li <thinker@branda.to>
parents:
426
diff
changeset
|
908 |
8f900da42eed
Make sh_text_draw() passes first test case.
Thinker K.F. Li <thinker@branda.to>
parents:
426
diff
changeset
|
909 sh_stext_transform((shape_t *)txt_o); |
8f900da42eed
Make sh_text_draw() passes first test case.
Thinker K.F. Li <thinker@branda.to>
parents:
426
diff
changeset
|
910 |
433
099941c3becf
Test cases for ratation on sh_stext
Thinker K.F. Li <thinker@branda.to>
parents:
429
diff
changeset
|
911 move_cnt = 0; |
427
8f900da42eed
Make sh_text_draw() passes first test case.
Thinker K.F. Li <thinker@branda.to>
parents:
426
diff
changeset
|
912 sh_stext_draw((shape_t *)txt_o, NULL); |
8f900da42eed
Make sh_text_draw() passes first test case.
Thinker K.F. Li <thinker@branda.to>
parents:
426
diff
changeset
|
913 CU_ASSERT(move_cnt == 2); |
8f900da42eed
Make sh_text_draw() passes first test case.
Thinker K.F. Li <thinker@branda.to>
parents:
426
diff
changeset
|
914 CU_ASSERT(move_xys[0][0] == 200); |
8f900da42eed
Make sh_text_draw() passes first test case.
Thinker K.F. Li <thinker@branda.to>
parents:
426
diff
changeset
|
915 CU_ASSERT(move_xys[0][1] == 50); |
8f900da42eed
Make sh_text_draw() passes first test case.
Thinker K.F. Li <thinker@branda.to>
parents:
426
diff
changeset
|
916 CU_ASSERT(move_xys[1][0] >= 240 && move_xys[1][0] < 270); |
8f900da42eed
Make sh_text_draw() passes first test case.
Thinker K.F. Li <thinker@branda.to>
parents:
426
diff
changeset
|
917 CU_ASSERT(move_xys[1][1] == 50); |
8f900da42eed
Make sh_text_draw() passes first test case.
Thinker K.F. Li <thinker@branda.to>
parents:
426
diff
changeset
|
918 |
8f900da42eed
Make sh_text_draw() passes first test case.
Thinker K.F. Li <thinker@branda.to>
parents:
426
diff
changeset
|
919 _rdman_shape_stext_free((shape_t *)txt_o); |
8f900da42eed
Make sh_text_draw() passes first test case.
Thinker K.F. Li <thinker@branda.to>
parents:
426
diff
changeset
|
920 free_font_face(face); |
8f900da42eed
Make sh_text_draw() passes first test case.
Thinker K.F. Li <thinker@branda.to>
parents:
426
diff
changeset
|
921 } |
8f900da42eed
Make sh_text_draw() passes first test case.
Thinker K.F. Li <thinker@branda.to>
parents:
426
diff
changeset
|
922 |
433
099941c3becf
Test cases for ratation on sh_stext
Thinker K.F. Li <thinker@branda.to>
parents:
429
diff
changeset
|
923 static |
099941c3becf
Test cases for ratation on sh_stext
Thinker K.F. Li <thinker@branda.to>
parents:
429
diff
changeset
|
924 void test_sh_stext_draw_rotate(void) { |
099941c3becf
Test cases for ratation on sh_stext
Thinker K.F. Li <thinker@branda.to>
parents:
429
diff
changeset
|
925 sh_stext_t *txt_o; |
099941c3becf
Test cases for ratation on sh_stext
Thinker K.F. Li <thinker@branda.to>
parents:
429
diff
changeset
|
926 mb_style_blk_t blks[2]; |
099941c3becf
Test cases for ratation on sh_stext
Thinker K.F. Li <thinker@branda.to>
parents:
429
diff
changeset
|
927 co_aix *aggr; |
099941c3becf
Test cases for ratation on sh_stext
Thinker K.F. Li <thinker@branda.to>
parents:
429
diff
changeset
|
928 mb_font_face_t *face; |
099941c3becf
Test cases for ratation on sh_stext
Thinker K.F. Li <thinker@branda.to>
parents:
429
diff
changeset
|
929 area_t *area; |
099941c3becf
Test cases for ratation on sh_stext
Thinker K.F. Li <thinker@branda.to>
parents:
429
diff
changeset
|
930 int r; |
099941c3becf
Test cases for ratation on sh_stext
Thinker K.F. Li <thinker@branda.to>
parents:
429
diff
changeset
|
931 |
099941c3becf
Test cases for ratation on sh_stext
Thinker K.F. Li <thinker@branda.to>
parents:
429
diff
changeset
|
932 txt_o = (sh_stext_t *)rdman_shape_stext_new(NULL, "hello world", 100, 50); |
099941c3becf
Test cases for ratation on sh_stext
Thinker K.F. Li <thinker@branda.to>
parents:
429
diff
changeset
|
933 CU_ASSERT(txt_o != NULL); |
822
586e50f82c1f
Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents:
760
diff
changeset
|
934 |
433
099941c3becf
Test cases for ratation on sh_stext
Thinker K.F. Li <thinker@branda.to>
parents:
429
diff
changeset
|
935 aggr = txt_o->shape.aggr; |
099941c3becf
Test cases for ratation on sh_stext
Thinker K.F. Li <thinker@branda.to>
parents:
429
diff
changeset
|
936 aggr[0] = 2; |
099941c3becf
Test cases for ratation on sh_stext
Thinker K.F. Li <thinker@branda.to>
parents:
429
diff
changeset
|
937 aggr[1] = 0; |
099941c3becf
Test cases for ratation on sh_stext
Thinker K.F. Li <thinker@branda.to>
parents:
429
diff
changeset
|
938 aggr[2] = 0; |
099941c3becf
Test cases for ratation on sh_stext
Thinker K.F. Li <thinker@branda.to>
parents:
429
diff
changeset
|
939 aggr[3] = 1; |
099941c3becf
Test cases for ratation on sh_stext
Thinker K.F. Li <thinker@branda.to>
parents:
429
diff
changeset
|
940 aggr[4] = 1; |
099941c3becf
Test cases for ratation on sh_stext
Thinker K.F. Li <thinker@branda.to>
parents:
429
diff
changeset
|
941 aggr[5] = 0; |
099941c3becf
Test cases for ratation on sh_stext
Thinker K.F. Li <thinker@branda.to>
parents:
429
diff
changeset
|
942 |
099941c3becf
Test cases for ratation on sh_stext
Thinker K.F. Li <thinker@branda.to>
parents:
429
diff
changeset
|
943 face = query_font_face("serif", MB_FONT_SLANT_ROMAN, 100); |
099941c3becf
Test cases for ratation on sh_stext
Thinker K.F. Li <thinker@branda.to>
parents:
429
diff
changeset
|
944 CU_ASSERT(face != NULL); |
822
586e50f82c1f
Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents:
760
diff
changeset
|
945 |
433
099941c3becf
Test cases for ratation on sh_stext
Thinker K.F. Li <thinker@branda.to>
parents:
429
diff
changeset
|
946 blks[0].n_chars = 5; |
099941c3becf
Test cases for ratation on sh_stext
Thinker K.F. Li <thinker@branda.to>
parents:
429
diff
changeset
|
947 blks[0].face = face; |
099941c3becf
Test cases for ratation on sh_stext
Thinker K.F. Li <thinker@branda.to>
parents:
429
diff
changeset
|
948 blks[0].font_sz = 10; |
822
586e50f82c1f
Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents:
760
diff
changeset
|
949 |
433
099941c3becf
Test cases for ratation on sh_stext
Thinker K.F. Li <thinker@branda.to>
parents:
429
diff
changeset
|
950 blks[1].n_chars = 6; |
099941c3becf
Test cases for ratation on sh_stext
Thinker K.F. Li <thinker@branda.to>
parents:
429
diff
changeset
|
951 blks[1].face = face; |
099941c3becf
Test cases for ratation on sh_stext
Thinker K.F. Li <thinker@branda.to>
parents:
429
diff
changeset
|
952 blks[1].font_sz = 15.5; |
822
586e50f82c1f
Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents:
760
diff
changeset
|
953 |
433
099941c3becf
Test cases for ratation on sh_stext
Thinker K.F. Li <thinker@branda.to>
parents:
429
diff
changeset
|
954 r = sh_stext_set_style((shape_t *)txt_o, blks, 2); |
099941c3becf
Test cases for ratation on sh_stext
Thinker K.F. Li <thinker@branda.to>
parents:
429
diff
changeset
|
955 CU_ASSERT(r == OK); |
099941c3becf
Test cases for ratation on sh_stext
Thinker K.F. Li <thinker@branda.to>
parents:
429
diff
changeset
|
956 |
099941c3becf
Test cases for ratation on sh_stext
Thinker K.F. Li <thinker@branda.to>
parents:
429
diff
changeset
|
957 sh_stext_transform((shape_t *)txt_o); |
099941c3becf
Test cases for ratation on sh_stext
Thinker K.F. Li <thinker@branda.to>
parents:
429
diff
changeset
|
958 |
099941c3becf
Test cases for ratation on sh_stext
Thinker K.F. Li <thinker@branda.to>
parents:
429
diff
changeset
|
959 move_cnt = 0; |
099941c3becf
Test cases for ratation on sh_stext
Thinker K.F. Li <thinker@branda.to>
parents:
429
diff
changeset
|
960 sh_stext_draw((shape_t *)txt_o, NULL); |
099941c3becf
Test cases for ratation on sh_stext
Thinker K.F. Li <thinker@branda.to>
parents:
429
diff
changeset
|
961 CU_ASSERT(move_cnt == 2); |
099941c3becf
Test cases for ratation on sh_stext
Thinker K.F. Li <thinker@branda.to>
parents:
429
diff
changeset
|
962 CU_ASSERT(move_xys[0][0] == 200); |
099941c3becf
Test cases for ratation on sh_stext
Thinker K.F. Li <thinker@branda.to>
parents:
429
diff
changeset
|
963 CU_ASSERT(move_xys[0][1] == 150); |
099941c3becf
Test cases for ratation on sh_stext
Thinker K.F. Li <thinker@branda.to>
parents:
429
diff
changeset
|
964 CU_ASSERT(move_xys[1][0] >= 240 && move_xys[1][0] < 270); |
099941c3becf
Test cases for ratation on sh_stext
Thinker K.F. Li <thinker@branda.to>
parents:
429
diff
changeset
|
965 CU_ASSERT(move_xys[1][1] >= 170 && move_xys[1][1] < 185); |
099941c3becf
Test cases for ratation on sh_stext
Thinker K.F. Li <thinker@branda.to>
parents:
429
diff
changeset
|
966 |
099941c3becf
Test cases for ratation on sh_stext
Thinker K.F. Li <thinker@branda.to>
parents:
429
diff
changeset
|
967 _rdman_shape_stext_free((shape_t *)txt_o); |
099941c3becf
Test cases for ratation on sh_stext
Thinker K.F. Li <thinker@branda.to>
parents:
429
diff
changeset
|
968 free_font_face(face); |
099941c3becf
Test cases for ratation on sh_stext
Thinker K.F. Li <thinker@branda.to>
parents:
429
diff
changeset
|
969 } |
099941c3becf
Test cases for ratation on sh_stext
Thinker K.F. Li <thinker@branda.to>
parents:
429
diff
changeset
|
970 |
410
1a923ea699c1
shape_stext.c, now, is unittested.
Thinker K.F. Li <thinker@branda.to>
parents:
407
diff
changeset
|
971 #include <CUnit/Basic.h> |
1a923ea699c1
shape_stext.c, now, is unittested.
Thinker K.F. Li <thinker@branda.to>
parents:
407
diff
changeset
|
972 CU_pSuite get_stext_suite(void) { |
1a923ea699c1
shape_stext.c, now, is unittested.
Thinker K.F. Li <thinker@branda.to>
parents:
407
diff
changeset
|
973 CU_pSuite suite; |
1a923ea699c1
shape_stext.c, now, is unittested.
Thinker K.F. Li <thinker@branda.to>
parents:
407
diff
changeset
|
974 |
1a923ea699c1
shape_stext.c, now, is unittested.
Thinker K.F. Li <thinker@branda.to>
parents:
407
diff
changeset
|
975 suite = CU_add_suite("Suite_stext", NULL, NULL); |
412
a456e267279a
Test cases for shape_stext.
Thinker K.F. Li <thinker@branda.to>
parents:
411
diff
changeset
|
976 CU_ADD_TEST(suite, test_query_font_face); |
a456e267279a
Test cases for shape_stext.
Thinker K.F. Li <thinker@branda.to>
parents:
411
diff
changeset
|
977 CU_ADD_TEST(suite, test_make_scaled_font_face_matrix); |
a456e267279a
Test cases for shape_stext.
Thinker K.F. Li <thinker@branda.to>
parents:
411
diff
changeset
|
978 CU_ADD_TEST(suite, test_compute_text_extents); |
414
bbf036c315be
Fix extent_extents to make it pass the test case.
Thinker K.F. Li <thinker@branda.to>
parents:
413
diff
changeset
|
979 CU_ADD_TEST(suite, test_extent_extents); |
415
fef1b8076041
Make compute_utf8_chars_sz to compute length of n UTF 8 characters correctly.
Thinker K.F. Li <thinker@branda.to>
parents:
414
diff
changeset
|
980 CU_ADD_TEST(suite, test_compute_utf8_chars_sz); |
421
1e48453bb282
Make compute_styled_extents_n_scaled_font() pass the test.
Thinker K.F. Li <thinker@branda.to>
parents:
420
diff
changeset
|
981 CU_ADD_TEST(suite, test_compute_styled_extents_n_scaled_font); |
433
099941c3becf
Test cases for ratation on sh_stext
Thinker K.F. Li <thinker@branda.to>
parents:
429
diff
changeset
|
982 CU_ADD_TEST(suite, test_compute_styled_extents_n_scaled_font_rotate); |
424
585baa462778
Make sh_stext_transform() pass first test case for him.
Thinker K.F. Li <thinker@branda.to>
parents:
423
diff
changeset
|
983 CU_ADD_TEST(suite, test_sh_stext_transform); |
427
8f900da42eed
Make sh_text_draw() passes first test case.
Thinker K.F. Li <thinker@branda.to>
parents:
426
diff
changeset
|
984 CU_ADD_TEST(suite, test_sh_stext_draw); |
433
099941c3becf
Test cases for ratation on sh_stext
Thinker K.F. Li <thinker@branda.to>
parents:
429
diff
changeset
|
985 CU_ADD_TEST(suite, test_sh_stext_draw_rotate); |
410
1a923ea699c1
shape_stext.c, now, is unittested.
Thinker K.F. Li <thinker@branda.to>
parents:
407
diff
changeset
|
986 |
1a923ea699c1
shape_stext.c, now, is unittested.
Thinker K.F. Li <thinker@branda.to>
parents:
407
diff
changeset
|
987 return suite; |
1a923ea699c1
shape_stext.c, now, is unittested.
Thinker K.F. Li <thinker@branda.to>
parents:
407
diff
changeset
|
988 } |
1a923ea699c1
shape_stext.c, now, is unittested.
Thinker K.F. Li <thinker@branda.to>
parents:
407
diff
changeset
|
989 |
1a923ea699c1
shape_stext.c, now, is unittested.
Thinker K.F. Li <thinker@branda.to>
parents:
407
diff
changeset
|
990 #endif /* UNITTEST */ |