• R/O
  • SSH
  • HTTPS

bchan: 提交


Commit MetaInfo

修訂578 (tree)
時間2013-11-17 13:41:02
作者ornse01

Log Message

replace datamodel and layout.

Change Summary

差異

--- bchank/trunk/src/main.c (revision 577)
+++ bchank/trunk/src/main.c (revision 578)
@@ -40,6 +40,8 @@
4040 #include <btron/libapp.h>
4141
4242 #include "bchank_hmi.h"
43+#include "bchank_genv.h"
44+#include "bchank_lines.h"
4345
4446 #include <coll/arraybase.h>
4547 #include <tad/taditerator.h>
@@ -50,8 +52,8 @@
5052 # define DP(arg) printf arg
5153 # define DP_ER(msg, err) printf("%s (%d/%x)\n", msg, err>>16, err)
5254 #else
53-# define DP(arg) /**/
54-# define DP_ER(msg, err) /**/
55+# define DP(arg) /* */
56+# define DP_ER(msg, err) /* */
5557 #endif
5658
5759 struct bchank_linearray_t_ {
@@ -118,55 +120,12 @@
118120 cssrendering_blockbox_t root;
119121 cssrendering_anonymousbox_t line_content;
120122 bchank_linearray_t lines;
121- struct {
122- bchank_font_t zen;
123- bchank_font_t han;
124- } fonts;
125123 cssrendering_coordinate_t scroll;
124+ bchank_genv_t *genv;
125+ bchank_linelist_t *text;
126126 };
127127 typedef struct bchank_t_ bchank_t;
128128
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-
170129 #define BCHANK_NODETYPE_HANKAKU 1
171130 #define BCHANK_NODETYPE_ZENKAKU 2
172131
@@ -176,11 +135,10 @@
176135 cssrendering_drawtraversal_result result;
177136 cssmetric_rectangle_t cr;
178137 Bool cont;
179- W x, y, len;
180- TC *str;
181- bchank_font_t *afnt;
138+ W x, y;
139+ bchank_line_t *line;
182140
183- bchank_resetgenvfont(bchank, target, NULL);
141+ bchank_genv_resetfont(bchank->genv, target, NULL);
184142
185143 cr.c.left = r.c.left;
186144 cr.c.top = r.c.top;
@@ -195,15 +153,11 @@
195153 break;
196154 }
197155 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);
201157
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);
207161 }
208162 }
209163 cssrendering_drawtraversal_finalize(&traversal);
@@ -250,100 +204,106 @@
250204 return BCHANK_SEGCHECK_RESULT_OTHER;
251205 }
252206
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)
254208 {
255- cssrendering_linebox_t *box;
209+ bchank_line_t *line;
256210
257- box = bchank_alloclinebox(bchank);
258- if (box == NULL) {
211+ line = bchank_linelist_append(bchank->text);
212+ if (line == NULL) {
259213 return -1;
260214 }
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);
266215
267- return 0;
216+ if (isHankakuStart != False) {
217+ /* */
218+ }
219+
220+ return bchank_line_appendtext(line, start, (end - start));
268221 }
269222
270-LOCAL W bchank_layout(bchank_t *bchank, GID target)
223+LOCAL W bchank_parse(bchank_t *bchank, GID target)
271224 {
272225 taditerator_t iterator;
273226 taditerator_result result;
274227 TC *start = NULL;
275- W len = 0, x = 0, y = 0, w = 0, max_w = 0, max_h = 0;
276- cssmetric_rectangle_t r;
277228 BCHANK_SEGCHECK_RESULT segcheck;
278- bchank_font_t *afnt = &bchank->fonts.zen;
229+ Bool start_state = False, current_state = False;
279230
280- bchank_resetgenvfont(bchank, target, NULL);
281-
282231 taditerator_initialize(&iterator, bchank->data.bin, bchank->data.len);
283232 for (;;) {
284233 taditerator_next2(&iterator, &result);
285234 if (result.type == TADITERATOR_RESULTTYPE_END) {
286235 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);
295237 start = NULL;
296- len = 0;
297238 }
298239 break;
299240 } else if (result.type == TADITERATOR_RESULTTYPE_CHARCTOR) {
300241 if (result.segment == TK_NL) {
301242 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);
310244 start = NULL;
311- len = 0;
312245 }
313- x = 0;
314- y += 18;
315246 } else {
316247 if (start == NULL) {
317248 start = result.pos;
249+ start_state = current_state;
318250 }
319- len++;
320251 }
321252 } 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;
334256 }
335257 segcheck = check_segment(result.segment, result.segsize, result.data);
336258 if (segcheck == BCHANK_SEGCHECK_RESULT_HANKAKU) {
337- afnt = &bchank->fonts.han;
338- gset_fon(target, &afnt->spec);
259+ current_state = True;
339260 } else if (segcheck == BCHANK_SEGCHECK_RESULT_ZENKAKU) {
340- afnt = &bchank->fonts.zen;
341- gset_fon(target, &afnt->spec);
261+ current_state = False;
342262 }
343263 }
344264 }
345265 taditerator_finalize(&iterator);
346266
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+
347307 printf("content height = %d, content width = %d, fragments = %d\n", max_h, max_w, bchank_linarray_length(&bchank->lines));
348308
349309 bchank->root.base.content_edge.c.left = 0;
@@ -410,10 +370,21 @@
410370 {
411371 bchank->data.bin = malloc(sizeof(TC));
412372 if (bchank->data.bin == NULL) {
413- return -1;
373+ goto error_buffer;
414374 }
415375 bchank->data.bin[0] = TNULL;
416376 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+
417388 cssrendering_blockbox_initialize(&bchank->root);
418389 cssrendering_anonymousbox_initialize(&bchank->line_content);
419390 bchank_linearray_initialize(&bchank->lines);
@@ -422,6 +393,13 @@
422393 cssrendering_blockbox_appendanonymouschild(&bchank->root, &bchank->line_content);
423394
424395 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;
425403 }
426404
427405 LOCAL VOID bchank_finalize(bchank_t *bchank)
@@ -437,6 +415,8 @@
437415 bchank_linearray_finalize(&bchank->lines);
438416 cssrendering_anonymousbox_finalize(&bchank->line_content);
439417 cssrendering_blockbox_finalize(&bchank->root);
418+ bchank_linelist_delete(bchank->text);
419+ bchank_genv_delete(bchank->genv);
440420 free(bchank->data.bin);
441421 }
442422
@@ -538,7 +518,7 @@
538518
539519 gid = editorwindow_getGID(window);
540520
541- err = bchank_initfont(bchank, gid);
521+ err = bchank_genv_setGID(bchank->genv, gid);
542522 if (err < 0) {
543523 DP_ER("bchank_initfont error", err);
544524 return;
--- bchank/trunk/src/Makefile (revision 577)
+++ bchank/trunk/src/Makefile (revision 578)
@@ -41,7 +41,7 @@
4141 HEADER := $(S) $(HEADER) ../src/bchanf/src
4242
4343 # ソースファイル
44-SRC = main.c bchank_hmi.c
44+SRC = main.c bchank_hmi.c textcluster.c bchank_lines.c bchank_genv.c
4545
4646 # データボックスソースファイル
4747 DBSRC =
Show on old repository browser