replace datamodel and layout.
@@ -40,6 +40,8 @@ | ||
40 | 40 | #include <btron/libapp.h> |
41 | 41 | |
42 | 42 | #include "bchank_hmi.h" |
43 | +#include "bchank_genv.h" | |
44 | +#include "bchank_lines.h" | |
43 | 45 | |
44 | 46 | #include <coll/arraybase.h> |
45 | 47 | #include <tad/taditerator.h> |
@@ -50,8 +52,8 @@ | ||
50 | 52 | # define DP(arg) printf arg |
51 | 53 | # define DP_ER(msg, err) printf("%s (%d/%x)\n", msg, err>>16, err) |
52 | 54 | #else |
53 | -# define DP(arg) /**/ | |
54 | -# define DP_ER(msg, err) /**/ | |
55 | +# define DP(arg) /* */ | |
56 | +# define DP_ER(msg, err) /* */ | |
55 | 57 | #endif |
56 | 58 | |
57 | 59 | struct bchank_linearray_t_ { |
@@ -118,55 +120,12 @@ | ||
118 | 120 | cssrendering_blockbox_t root; |
119 | 121 | cssrendering_anonymousbox_t line_content; |
120 | 122 | bchank_linearray_t lines; |
121 | - struct { | |
122 | - bchank_font_t zen; | |
123 | - bchank_font_t han; | |
124 | - } fonts; | |
125 | 123 | cssrendering_coordinate_t scroll; |
124 | + bchank_genv_t *genv; | |
125 | + bchank_linelist_t *text; | |
126 | 126 | }; |
127 | 127 | typedef struct bchank_t_ bchank_t; |
128 | 128 | |
129 | -LOCAL W bchank_initfont(bchank_t *bchank, GID target) | |
130 | -{ | |
131 | - FSSPEC spec; | |
132 | - W err; | |
133 | - | |
134 | - err = gget_fon(target, &spec, NULL); | |
135 | - if (err < 0) { | |
136 | - return err; | |
137 | - } | |
138 | - | |
139 | - spec.attr |= FT_PROP; | |
140 | - spec.attr |= FT_GRAYSCALE; | |
141 | - spec.fclass = 0x000000c0; | |
142 | - spec.size.h = 16; | |
143 | - spec.size.v = 16; | |
144 | - | |
145 | - err = gset_fon(target, &spec); | |
146 | - if (err < 0) { | |
147 | - return err; | |
148 | - } | |
149 | - | |
150 | - err = gget_fon(target, &bchank->fonts.zen.spec, &bchank->fonts.zen.info); | |
151 | - if (err < 0) { | |
152 | - return err; | |
153 | - } | |
154 | - | |
155 | - bchank->fonts.han = bchank->fonts.zen; | |
156 | - bchank->fonts.han.spec.size.h = 8; | |
157 | - | |
158 | - return 0; | |
159 | -} | |
160 | - | |
161 | -LOCAL W bchank_resetgenvfont(bchank_t *bchank, GID target, FSSPEC *result) | |
162 | -{ | |
163 | - if (result != NULL) { | |
164 | - *result = bchank->fonts.zen.spec; | |
165 | - } | |
166 | - | |
167 | - return gset_fon(target, &bchank->fonts.zen.spec); | |
168 | -} | |
169 | - | |
170 | 129 | #define BCHANK_NODETYPE_HANKAKU 1 |
171 | 130 | #define BCHANK_NODETYPE_ZENKAKU 2 |
172 | 131 |
@@ -176,11 +135,10 @@ | ||
176 | 135 | cssrendering_drawtraversal_result result; |
177 | 136 | cssmetric_rectangle_t cr; |
178 | 137 | Bool cont; |
179 | - W x, y, len; | |
180 | - TC *str; | |
181 | - bchank_font_t *afnt; | |
138 | + W x, y; | |
139 | + bchank_line_t *line; | |
182 | 140 | |
183 | - bchank_resetgenvfont(bchank, target, NULL); | |
141 | + bchank_genv_resetfont(bchank->genv, target, NULL); | |
184 | 142 | |
185 | 143 | cr.c.left = r.c.left; |
186 | 144 | cr.c.top = r.c.top; |
@@ -195,15 +153,11 @@ | ||
195 | 153 | break; |
196 | 154 | } |
197 | 155 | if (result.type == CSSRENDERING_DRAWTRAVERSAL_RESULTTYPE_TEXT) { |
198 | - afnt = (bchank_font_t *)(result.data.text.nodedata); | |
199 | - if (afnt != NULL) { | |
200 | - gset_fon(target, &afnt->spec); | |
156 | + line = (bchank_line_t *)(result.data.text.nodedata); | |
201 | 157 | |
202 | - cssrendering_coordinate_getrelativepoint(&bchank->scroll, result.data.text.content_edge.c.left, result.data.text.content_edge.c.top + afnt->info.base, &x, &y); | |
203 | - str = result.data.text.fragment->str; | |
204 | - len = result.data.text.fragment->len; | |
205 | - gdra_stp(target, x, y, str, len, G_STORE); | |
206 | - } | |
158 | + cssrendering_coordinate_getrelativepoint(&bchank->scroll, result.data.text.content_edge.c.left, result.data.text.content_edge.c.top + 16/*TODO*/, &x, &y); | |
159 | + gset_chp(target, x, y, True); | |
160 | + bchank_linelist_drawline(bchank->text, line, target); | |
207 | 161 | } |
208 | 162 | } |
209 | 163 | cssrendering_drawtraversal_finalize(&traversal); |
@@ -250,100 +204,106 @@ | ||
250 | 204 | return BCHANK_SEGCHECK_RESULT_OTHER; |
251 | 205 | } |
252 | 206 | |
253 | -LOCAL W bchank_layout_addline(bchank_t *bchank, TC *str, W len, cssmetric_rectangle_t r, VP data) | |
207 | +LOCAL W bchank_parse_addline(bchank_t *bchank, TC *start, TC *end, Bool isHankakuStart) | |
254 | 208 | { |
255 | - cssrendering_linebox_t *box; | |
209 | + bchank_line_t *line; | |
256 | 210 | |
257 | - box = bchank_alloclinebox(bchank); | |
258 | - if (box == NULL) { | |
211 | + line = bchank_linelist_append(bchank->text); | |
212 | + if (line == NULL) { | |
259 | 213 | return -1; |
260 | 214 | } |
261 | - box->text.str = str; | |
262 | - box->text.len = len; | |
263 | - box->base.content_edge = r; | |
264 | - cssrendering_linebox_setuserdata(box, data); | |
265 | - cssrendering_anonymousbox_appendchild(&bchank->line_content, box); | |
266 | 215 | |
267 | - return 0; | |
216 | + if (isHankakuStart != False) { | |
217 | + /* */ | |
218 | + } | |
219 | + | |
220 | + return bchank_line_appendtext(line, start, (end - start)); | |
268 | 221 | } |
269 | 222 | |
270 | -LOCAL W bchank_layout(bchank_t *bchank, GID target) | |
223 | +LOCAL W bchank_parse(bchank_t *bchank, GID target) | |
271 | 224 | { |
272 | 225 | taditerator_t iterator; |
273 | 226 | taditerator_result result; |
274 | 227 | TC *start = NULL; |
275 | - W len = 0, x = 0, y = 0, w = 0, max_w = 0, max_h = 0; | |
276 | - cssmetric_rectangle_t r; | |
277 | 228 | BCHANK_SEGCHECK_RESULT segcheck; |
278 | - bchank_font_t *afnt = &bchank->fonts.zen; | |
229 | + Bool start_state = False, current_state = False; | |
279 | 230 | |
280 | - bchank_resetgenvfont(bchank, target, NULL); | |
281 | - | |
282 | 231 | taditerator_initialize(&iterator, bchank->data.bin, bchank->data.len); |
283 | 232 | for (;;) { |
284 | 233 | taditerator_next2(&iterator, &result); |
285 | 234 | if (result.type == TADITERATOR_RESULTTYPE_END) { |
286 | 235 | if (start != NULL) { |
287 | - w = gget_stw(target, start, len, NULL, NULL); | |
288 | - r.c.left = x; | |
289 | - r.c.top = y; | |
290 | - r.c.right = x + w; | |
291 | - r.c.bottom = y + 18; | |
292 | - max_w = (r.c.left > max_w) ? r.c.left : max_w; | |
293 | - max_h = (r.c.bottom > max_h) ? r.c.bottom : max_h; | |
294 | - bchank_layout_addline(bchank, start, len, r, (VP)afnt); | |
236 | + bchank_parse_addline(bchank, start, result.pos, start_state); | |
295 | 237 | start = NULL; |
296 | - len = 0; | |
297 | 238 | } |
298 | 239 | break; |
299 | 240 | } else if (result.type == TADITERATOR_RESULTTYPE_CHARCTOR) { |
300 | 241 | if (result.segment == TK_NL) { |
301 | 242 | if (start != NULL) { |
302 | - w = gget_stw(target, start, len, NULL, NULL); | |
303 | - r.c.left = x; | |
304 | - r.c.top = y; | |
305 | - r.c.right = x + w; | |
306 | - r.c.bottom = y + 18; | |
307 | - max_w = (r.c.left > max_w) ? r.c.left : max_w; | |
308 | - max_h = (r.c.bottom > max_h) ? r.c.bottom : max_h; | |
309 | - bchank_layout_addline(bchank, start, len, r, (VP)afnt); | |
243 | + bchank_parse_addline(bchank, start, result.pos, start_state); | |
310 | 244 | start = NULL; |
311 | - len = 0; | |
312 | 245 | } |
313 | - x = 0; | |
314 | - y += 18; | |
315 | 246 | } else { |
316 | 247 | if (start == NULL) { |
317 | 248 | start = result.pos; |
249 | + start_state = current_state; | |
318 | 250 | } |
319 | - len++; | |
320 | 251 | } |
321 | 252 | } else if (result.type == TADITERATOR_RESULTTYPE_SEGMENT) { |
322 | - if (start != NULL) { | |
323 | - w = gget_stw(target, start, len, NULL, NULL); | |
324 | - r.c.left = x; | |
325 | - r.c.top = y; | |
326 | - r.c.right = x + w; | |
327 | - r.c.bottom = y + 18; | |
328 | - max_w = (r.c.left > max_w) ? r.c.left : max_w; | |
329 | - max_h = (r.c.bottom > max_h) ? r.c.bottom : max_h; | |
330 | - bchank_layout_addline(bchank, start, len, r, (VP)afnt); | |
331 | - x += w; | |
332 | - start = NULL; | |
333 | - len = 0; | |
253 | + if (start == NULL) { | |
254 | + start = result.pos; | |
255 | + start_state = current_state; | |
334 | 256 | } |
335 | 257 | segcheck = check_segment(result.segment, result.segsize, result.data); |
336 | 258 | if (segcheck == BCHANK_SEGCHECK_RESULT_HANKAKU) { |
337 | - afnt = &bchank->fonts.han; | |
338 | - gset_fon(target, &afnt->spec); | |
259 | + current_state = True; | |
339 | 260 | } else if (segcheck == BCHANK_SEGCHECK_RESULT_ZENKAKU) { |
340 | - afnt = &bchank->fonts.zen; | |
341 | - gset_fon(target, &afnt->spec); | |
261 | + current_state = False; | |
342 | 262 | } |
343 | 263 | } |
344 | 264 | } |
345 | 265 | taditerator_finalize(&iterator); |
346 | 266 | |
267 | + return 0; | |
268 | +} | |
269 | + | |
270 | +LOCAL W bchank_layout(bchank_t *bchank, GID target) | |
271 | +{ | |
272 | + W i, x = 0, y = 0, w = 0, max_w = 0, max_h = 0; | |
273 | + cssmetric_rectangle_t r; | |
274 | + bchank_line_t *line; | |
275 | + cssrendering_linebox_t *box; | |
276 | + | |
277 | + bchank_parse(bchank, target); | |
278 | + | |
279 | + for (i = 0; ; i++) { | |
280 | + line = bchank_linelist_get(bchank->text, i); | |
281 | + if (line == NULL) { | |
282 | + break; | |
283 | + } | |
284 | + w = bchank_linelist_calclinewidth(bchank->text, line, target); | |
285 | + | |
286 | + r.c.left = x; | |
287 | + r.c.top = y; | |
288 | + r.c.right = x + w; | |
289 | + r.c.bottom = y + 18; | |
290 | + max_w = (w > max_w) ? w : max_w; | |
291 | + max_h = (r.c.bottom > max_h) ? r.c.bottom : max_h; | |
292 | + | |
293 | + box = bchank_alloclinebox(bchank); | |
294 | + if (box == NULL) { | |
295 | + return -1; | |
296 | + } | |
297 | + box->text.str = NULL; | |
298 | + box->text.len = NULL; | |
299 | + box->base.content_edge = r; | |
300 | + cssrendering_linebox_setuserdata(box, (VP)line); | |
301 | + cssrendering_anonymousbox_appendchild(&bchank->line_content, box); | |
302 | + | |
303 | + x = 0; | |
304 | + y += 18; | |
305 | + } | |
306 | + | |
347 | 307 | printf("content height = %d, content width = %d, fragments = %d\n", max_h, max_w, bchank_linarray_length(&bchank->lines)); |
348 | 308 | |
349 | 309 | bchank->root.base.content_edge.c.left = 0; |
@@ -410,10 +370,21 @@ | ||
410 | 370 | { |
411 | 371 | bchank->data.bin = malloc(sizeof(TC)); |
412 | 372 | if (bchank->data.bin == NULL) { |
413 | - return -1; | |
373 | + goto error_buffer; | |
414 | 374 | } |
415 | 375 | bchank->data.bin[0] = TNULL; |
416 | 376 | bchank->data.len = 0; |
377 | + | |
378 | + bchank->genv = bchank_genv_new(); | |
379 | + if (bchank->genv == NULL) { | |
380 | + goto error_genv; | |
381 | + } | |
382 | + | |
383 | + bchank->text = bchank_linelist_new(bchank->genv); | |
384 | + if (bchank->text == NULL) { | |
385 | + goto error_linelist; | |
386 | + } | |
387 | + | |
417 | 388 | cssrendering_blockbox_initialize(&bchank->root); |
418 | 389 | cssrendering_anonymousbox_initialize(&bchank->line_content); |
419 | 390 | bchank_linearray_initialize(&bchank->lines); |
@@ -422,6 +393,13 @@ | ||
422 | 393 | cssrendering_blockbox_appendanonymouschild(&bchank->root, &bchank->line_content); |
423 | 394 | |
424 | 395 | return 0; |
396 | + | |
397 | +error_linelist: | |
398 | + bchank_genv_delete(bchank->genv); | |
399 | +error_genv: | |
400 | + free(bchank->data.bin); | |
401 | +error_buffer: | |
402 | + return -1; | |
425 | 403 | } |
426 | 404 | |
427 | 405 | LOCAL VOID bchank_finalize(bchank_t *bchank) |
@@ -437,6 +415,8 @@ | ||
437 | 415 | bchank_linearray_finalize(&bchank->lines); |
438 | 416 | cssrendering_anonymousbox_finalize(&bchank->line_content); |
439 | 417 | cssrendering_blockbox_finalize(&bchank->root); |
418 | + bchank_linelist_delete(bchank->text); | |
419 | + bchank_genv_delete(bchank->genv); | |
440 | 420 | free(bchank->data.bin); |
441 | 421 | } |
442 | 422 |
@@ -538,7 +518,7 @@ | ||
538 | 518 | |
539 | 519 | gid = editorwindow_getGID(window); |
540 | 520 | |
541 | - err = bchank_initfont(bchank, gid); | |
521 | + err = bchank_genv_setGID(bchank->genv, gid); | |
542 | 522 | if (err < 0) { |
543 | 523 | DP_ER("bchank_initfont error", err); |
544 | 524 | return; |
@@ -41,7 +41,7 @@ | ||
41 | 41 | HEADER := $(S) $(HEADER) ../src/bchanf/src |
42 | 42 | |
43 | 43 | # ソースファイル |
44 | -SRC = main.c bchank_hmi.c | |
44 | +SRC = main.c bchank_hmi.c textcluster.c bchank_lines.c bchank_genv.c | |
45 | 45 | |
46 | 46 | # データボックスソースファイル |
47 | 47 | DBSRC = |