#include #include #include #include "parse.h" void frame_parse_body(Frame *f, Tag *tag) { TagOpt *opt; char *bgcol = NULL; char *bgname = NULL; char *text = NULL; for (opt = tag->opt; opt; opt=opt->next) { switch (opt->oi->id) { case OPT_background: bgname = opt->val; break; case OPT_bgcolor: bgcol = opt->val; break; case OPT_text: text = opt->val; break; case OPT_alink: case OPT_link: case OPT_vlink: default: break; } } #if 0 fprintf(stderr,"body tag: %s %s\n", bgcol, bgname); #endif if (bgname) { ImageData *img; FILE *fp; if ((fp = frame_file_open(f, bgname)) != NULL) { img = image_new(); if (image_read_stream(img, fp) == 0) { image_set_col(img, f->dpy, f->win); image_pixmap(img, NULL); image_free_data(img); f->bg_image = img; } else image_delete(img); } } if (f->bg_image == NULL && bgcol) frame_alloc_color(f, bgcol, &f->background); if (text) frame_alloc_color(f, text, &(f->pinfo->istyle->pixel)); frame_add_body(f); } void frame_parse_heading(Frame *f, Tag *tag) { BlockFormatInfo *bfi = frame_get_blockformatinfo(f); bfi->paragraph = 0; inlinestyleinfo_setsize(f, f->pinfo->istyle, 6 - (tag->ti->id - TAG_h1)); } void frame_parse_p(Frame *f, Tag *tag) { BlockFormatInfo *bfi = frame_get_blockformatinfo(f); bfi->paragraph = 1; } void frame_parse_pre(Frame *f, Tag *tag) { BlockFormatInfo *bfi = frame_get_blockformatinfo(f); bfi->pre = TAG_OPEN; inlinestyleinfo_setfonttype(f, f->pinfo->istyle, FONTTYPE_PRE); } void frame_parse_ul(Frame *f, Tag *tag) { TagOpt *opt; BlockFormatInfo *bfi = frame_get_blockformatinfo(f); int level = bfi->li_level + 1; for (opt = tag->opt; opt; opt=opt->next) { if (!opt->oi) continue; switch (opt->oi->id) { case OPT_type: { OptInfo *i = GetOptInfo(opt->val); if (i != NULL) { switch (i->id) { case OPT_disc: level = 1; break; case OPT_square: level = 3; break; case OPT_circle: level = 2; break; default: break; } } } break; default: break; } } bfi->li_level = level; } void frame_parse_ol(Frame *f, Tag *tag) { TagOpt *opt; BlockFormatInfo *bfi = frame_get_blockformatinfo(f); int level = 0; int cnt = 0; for (opt = tag->opt; opt; opt=opt->next) { if (!opt->oi) continue; switch (opt->oi->id) { case OPT_type: if (opt->val) { switch (*((char*)opt->val)) { case 'I': level = 1; break; case 'i': level = 2; break; case 'A': level = 3; break; case 'a': level = 4; break; default: break; } } break; case OPT_start: if (opt->val) cnt = atoi(opt->val); break; default: break; } } bfi->li_level = level; bfi->li_cnt = cnt; } static char *num_rome[][9] = { {"I", "II", "III", "IV", "V", "VI", "VII", "IIX", "IX" }, {"i", "ii", "iii", "iv", "v", "vi", "vii", "iix", "ix" }, }; void frame_parse_li(Frame *f, Tag *tag) { BlockFormatInfo *pbfi = frame_get_parent_blockformatinfo(f); BlockFormatInfo *bfi = frame_get_blockformatinfo(f); ParseInfo *ppi = f->pinfo->next; pbfi->li_cnt++; switch (ppi->taginfo->id) { case TAG_ul: frame_add_bullet(f, pbfi->li_level); break; case TAG_ol: { int n; char buf[100]; wchar_t wbuf[100]; wchar_t *wbuf2; mbstate_t s; switch (pbfi->li_level) { case 1: case 2: { int n = pbfi->li_cnt; int m, d, c, l, x, i; char *p = buf; m = n / 1000; n -= m * 1000; d = n / 500; n -= d * 500; c = n / 100; n -= c * 100; l = n / 50; n -= l * 50; x = n / 10; n -= x * 10; for (i=0;ili_level == 1)? 'M' : 'm'; for (i=0;ili_level == 1)? 'D' : 'd'; for (i=0;ili_level == 1)? 'C' : 'c'; for (i=0;ili_level == 1)? 'L' : 'l'; for (i=0;ili_level == 1)? 'X' : 'x'; strcpy(p, num_rome[pbfi->li_level-1][n-1]); strcat(p, ". "); } break; case 3: sprintf(buf, "%c. ", 'A' + pbfi->li_cnt - 1); break; case 4: sprintf(buf, "%c. ", 'a' + pbfi->li_cnt - 1); break; default: sprintf(buf, "%d. ", pbfi->li_cnt); } mbrtowc(NULL,NULL,0,&s); n = mbsrtowcs(wbuf, buf, sizeof(buf), &s); if ((wbuf2 = malloc(n * sizeof(wbuf2))) != NULL) { wcscpy(wbuf2,wbuf); /* frame_add_string(f, wbuf2, n, 1);*/ /* bfi->obj->prev->type = HTMLOBJ_TEXT_MEM;*/ } } default: break; } /* move indent */ bfi->off_x += bfi->cur_x; bfi->cur_x = 0; }