⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 html_tbl.c

📁 ELinks is an advanced and well-established feature-rich text mode web (HTTP/FTP/..) browser. ELinks
💻 C
📖 第 1 页 / 共 4 页
字号:
	while (d) {		int mss, mii;		int p = 0;		int wq;		int dd;		memset(w, 0, t->x * sizeof(int));		memset(mx, 0, t->x * sizeof(int));		for (i = 0; i < t->x; i++) {			switch (om) {				case 0:					if (t->w_c[i] < t->xcols[i]) {						w[i] = 1, mx[i] = (t->xcols[i] > t->max_c[i] ? t->max_c[i] : t->xcols[i]) - t->w_c[i];						if (mx[i] <= 0) w[i] = 0;					}					break;				case 1:					if (t->xcols[i] < -1 && t->xcols[i] != -2) {						w[i] = t->xcols[i] <= -2 ? -2 - t->xcols[i] : 1;						mx[i] = t->max_c[i] - t->w_c[i];						if (mx[i] <= 0) w[i] = 0;					}					break;				case 2:				case 3:					if (t->w_c[i] < t->max_c[i] && (om == 3 || t->xcols[i] == W_AUTO)) {						mx[i] = t->max_c[i] - t->w_c[i];						if (mmax_c) w[i] = gf_val(5, 5 * HTML_CHAR_WIDTH) + t->max_c[i] * 10 / mmax_c;						else w[i] = 1;					}					break;				case 4:					if (t->xcols[i] >= 0) {						w[i] = 1, mx[i] = t->xcols[i] - t->w_c[i];						if (mx[i] <= 0) w[i] = 0;					}					break;				case 5:					if (t->xcols[i] < 0) w[i] = t->xcols[i] <= -2 ? -2 - t->xcols[i] : 1, mx[i] = MAXINT;					break;				case 6:					w[i] = 1, mx[i] = MAXINT;					break;				default:					/*internal("could not expand table");*/					goto end2;			}			p += w[i];		}		if (!p) {			om++;			continue;		}		wq = 0;		if (u) memset(u, 0, t->x);		dd = d;		a:		mss = 0; mii = -1;		for (i = 0; i < t->x; i++) if (w[i]) {			int ss;			if (u && u[i]) continue;			if (!(ss = dd * w[i] / p)) ss = 1;			if (ss > mx[i]) ss = mx[i];			if (ss > mss) mss = ss, mii = i;		}		if (mii != -1) {			int q = t->w_c[mii];			if (u) u[mii] = 1;			t->w_c[mii] += mss;			d -= t->w_c[mii] - q;			while (d < 0) t->w_c[mii]--, d++;			if (t->w_c[mii] < q) {				/*internal("shrinking cell");*/				t->w_c[mii] = q;			}			wq = 1;			if (d) goto a;		} else if (!wq) om++;	}	end2:	mem_free(mx);	mem_free(w);	if (u) mem_free(u);}#ifdef HTML_TABLE_2ND_PASSvoid check_table_widths(struct table *t){	int *w;	int i, j;	int s, ns;	int m, mi = 0; /* go away, warning! */	if ((unsigned)t->x > MAXINT / sizeof(int)) overalloc();	w = mem_calloc(t->x * sizeof(int));	for (j = 0; j < t->y; j++) for (i = 0; i < t->x; i++) {		struct table_cell *c = CELL(t, i, j);		int k, p = 0;		if (!c->start) continue;		for (k = 1; k < c->colspan; k++) p += get_vline_width(t, i + k) >= 0;		for (k = 0; k < c->colspan; k++) p += t->w_c[i + k];		get_cell_width(c->start, c->end, t->cellpd, p, 1, &c->x_width, NULL, c->link_num, NULL, NULL);		if (c->x_width > p) {			/*int min, max;			get_cell_width(c->start, c->end, t->cellpd, 0, 0, &min, &max, c->link_num, NULL, NULL);			internal("cell is now wider (%d > %d) min = %d, max = %d, now_min = %d, now_max = %d", c->x_width, p, t->min_c[i], t->max_c[i], min, max);*/			/* sbohem, internale. chytl jsi mi spoustu chyb v tabulkovaci, ale ted je proste cas jit ... ;-( */			c->x_width = p;		}	}	s = 1;	do {		ns = MAXINT;		for (i = 0; i < t->x; i++) for (j = 0; j < t->y; j++) {			struct table_cell *c = CELL(t, i, j);			if (!c->start) continue;			if (c->colspan + i > t->x) {				/*internal("colspan out of table");*/				mem_free(w);				return;			}			if (c->colspan == s) {				int k, p = 0;				for (k = 1; k < s; k++) p += get_vline_width(t, i + k) >= 0;				dst_width(w + i, s, c->x_width - p, t->max_c + i);				/*for (k = i; k < i + s; k++) if (w[k] > t->w_c[k]) {					int l;					int c;					ag:					c = 0;					for (l = i; l < i + s; l++) if (w[l] < t->w_c[k]) w[l]++, w[k]--, c = 1;					if (w[k] > t->w_c[k]) {						if (!c) internal("can't shrink cell");						else goto ag;					}				}*/			} else if (c->colspan > s && c->colspan < ns) ns = c->colspan;		}	} while ((s = ns) != MAXINT);	s = 0; ns = 0;	for (i = 0; i < t->x; i++) {		s += t->w_c[i], ns += w[i];		/*if (w[i] > t->w_c[i]) {			int k;			for (k = 0; k < t->x; k++) debug("%d, %d", t->w_c[k], w[k]);			debug("column %d: new width(%d) is larger than previous(%d)", i, w[i], t->w_c[i]);		}*/	}	if (ns > s) {		/*internal("new width(%d) is larger than previous(%d)", ns, s);*/		mem_free(w);		return;	}	m = -1;	for (i = 0; i < t->x; i++) {		/*if (table_level == 1) debug("%d: %d %d %d %d", i, t->max_c[i], t->min_c[i], t->w_c[i], w[i]);*/		if (t->max_c[i] > m) m = t->max_c[i], mi = i;	}	/*if (table_level == 1) debug("%d %d", mi, s - ns);*/	if (m != -1) {		w[mi] += s - ns;		if (w[mi] <= t->max_c[mi]) {			mem_free(t->w_c);			t->w_c = w;			return;		}	}	mem_free(w);}#endifvoid get_table_heights(struct table *t){	int s, ns;	int i, j;	for (j = 0; j < t->y; j++) {		for (i = 0; i < t->x; i++) {			struct table_cell *cell = CELL(t, i, j);			struct part *p;#ifdef G			struct g_part *gp;#endif			int xw = 0, sp;			if (!cell->used || cell->spanned) continue;			/*			fprintf(stderr, "i==%d, w_c[i]==%d, min_c[i]==%d, max_c[i]==%d\n", i, t->w_c[i], t->min_c[i], t->max_c[i]);			*/			for (sp = 0; sp < cell->colspan; sp++) {				xw += t->w_c[i + sp];				if (sp < cell->colspan - 1) {					if (!F) xw += get_vline_width(t, i + sp + 1) >= 0;#ifdef G					else xw += g_get_vline_pad(t, i + sp + 1, NULL, NULL);#endif				}			}			if (!F) {				if (!(p = format_html_part(cell->start, cell->end, cell->align, t->cellpd, xw, NULL, 2, 2, NULL, cell->link_num))) return;				cell->height = p->y;				mem_free(p);#ifdef G			} else {				if (!(gp = g_format_html_part(cell->start, cell->end, cell->align, 0, xw, NULL, cell->link_num, NULL /* FIX: background image */, cell->bgcolor_str, t->gp->data))) return;				/*if (gp->root->xw > xw) internal("vono to neumi formatovat... buuuu (%d > %d)", gp->root->xw, xw);*/				cell->root = gp->root;				gp->root = NULL;				cell->height = gp->y;				cell->g_width = xw;				g_release_part(gp);				mem_free(gp);#endif			}				/*debug("%d, %d.",xw, cell->height);*/		}	}	s = 1;	do {		ns = MAXINT;		for (j = 0; j < t->y; j++) {			for (i = 0; i < t->x; i++) {				struct table_cell *cell = CELL(t, i, j);				if (!cell->used || cell->spanned) continue;				if (cell->rowspan == s) {					int k, p = 0;					for (k = 1; k < s; k++) {						if (!F) p += get_hline_width(t, j + k) >= 0;#ifdef G						else p += g_get_hline_pad(t, j + k, NULL, NULL);#endif					}					dst_width(t->r_heights + j, s, cell->height - p, NULL);				} else if (cell->rowspan > s && cell->rowspan < ns) ns = cell->rowspan;			}		}	} while ((s = ns) != MAXINT);	if (!F) {		t->rh = (!!(t->frame & F_ABOVE) + !!(t->frame & F_BELOW)) * !!t->border;		for (j = 0; j < t->y; j++) {			t->rh += t->r_heights[j];			if (j) t->rh += get_hline_width(t, j) >= 0;		}#ifdef G	} else {		t->rh = 0;		for (j = 0; j <= t->y; j++) {			t->rh += g_get_hline_pad(t, j, NULL, NULL);			if (j < t->y) t->rh += t->r_heights[j];		}#endif	}}void display_complicated_table(struct table *t, int x, int y, int *yy){	int i, j;	struct f_data *f = t->p->data;	int yp, xp = x + ((t->frame & F_LHS) && t->border);	for (i = 0; i < t->x; i++) {		yp = y + ((t->frame & F_ABOVE) && t->border);		for (j = 0; j < t->y; j++) {			struct table_cell *cell = CELL(t, i, j);			if (cell->start) {				int yt;				struct part *p = NULL;				int xw = 0, yw = 0, s;				for (s = 0; s < cell->colspan; s++) {					xw += t->w_c[i + s];					if (s < cell->colspan - 1) xw += get_vline_width(t, i + s + 1) >= 0;				}				for (s = 0; s < cell->rowspan; s++) {					yw += t->r_heights[j + s];					if (s < cell->rowspan - 1) yw += get_hline_width(t, j + s + 1) >= 0;				}				html_stack_dup();				html_top.dontkill = 1;				if (cell->b) format.attr |= AT_BOLD;				memcpy(&format.bg, &cell->bgcolor, sizeof(struct rgb));				memcpy(&par_format.bgcolor, &cell->bgcolor, sizeof(struct rgb));				p = format_html_part(cell->start, cell->end, cell->align, t->cellpd, xw, f, t->p->xp + xp, t->p->yp + yp + (cell->valign != VAL_MIDDLE && cell->valign != VAL_BOTTOM ? 0 : (yw - cell->height) / (cell->valign == VAL_MIDDLE ? 2 : 1)), NULL, cell->link_num);				cell->xpos = xp;				cell->ypos = yp;				cell->xw = xw;				cell->yw = yw;				for (yt = 0; yt < p->y; yt++) {					xxpand_lines(t->p, yp + yt);					xxpand_line(t->p, yp + yt, xp + t->w_c[i]);				}				kill_html_stack_item(&html_top);				mem_free(p);			}			cell->xpos = xp;			cell->ypos = yp;			cell->xw = t->w_c[i];			yp += t->r_heights[j];			if (j < t->y - 1) yp += (get_hline_width(t, j + 1) >= 0);		}		if (i < t->x - 1) xp += t->w_c[i] + (get_vline_width(t, i + 1) >= 0);	}	yp = y;	for (j = 0; j < t->y; j++) {		yp += t->r_heights[j];		if (j < t->y - 1) yp += (get_hline_width(t, j + 1) >= 0);	}	*yy = yp + (!!(t->frame & F_ABOVE) + !!(t->frame & F_BELOW)) * !!t->border;}/* !!! FIXME: background */#define draw_frame_point(xx, yy, ii, jj)	\if (H_LINE_X((ii-1), (jj)) >= 0 || H_LINE_X((ii), (jj)) >= 0 || V_LINE_X((ii), (jj-1)) >= 0 || V_LINE_X((ii), (jj)) >= 0) xset_hchar(t->p, (xx), (yy), frame_table[V_LINE((ii),(jj)-1)+3*H_LINE((ii),(jj))+9*H_LINE((ii)-1,(jj))+27*V_LINE((ii),(jj))] | ATTR_FRAME)#define draw_frame_hline(xx, yy, ll, ii, jj)	\if (H_LINE_X((ii), (jj)) >= 0) xset_hchars(t->p, (xx), (yy), (ll), hline_table[H_LINE((ii), (jj))] | ATTR_FRAME)#define draw_frame_vline(xx, yy, ll, ii, jj)	\{						\	int qq;					\	if (V_LINE_X((ii), (jj)) >= 0) for (qq = 0; qq < (ll); qq++) xset_hchar(t->p, (xx), (yy) + qq, vline_table[V_LINE((ii), (jj))] | ATTR_FRAME); }#ifndef DEBUG#define H_LINE_X(xx, yy) fh[(xx) + 1 + (t->x + 2) * (yy)]#define V_LINE_X(xx, yy) fv[(yy) + 1 + (t->y + 2) * (xx)]#else#define H_LINE_X(xx, yy) (*(xx < -1 || xx > t->x + 1 || yy < 0 || yy > t->y ? (signed char *)NULL : &fh[(xx) + 1 + (t->x + 2) * (yy)]))#define V_LINE_X(xx, yy) (*(xx < 0 || xx > t->x || yy < -1 || yy > t->y + 1 ? (signed char *)NULL : &fv[(yy) + 1 + (t->y + 2) * (xx)]))#endif#define H_LINE(xx, yy) (H_LINE_X((xx), (yy)) < 0 ? 0 : H_LINE_X((xx), (yy)))#define V_LINE(xx, yy) (V_LINE_X((xx), (yy)) < 0 ? 0 : V_LINE_X((xx), (yy)))void get_table_frame(struct table *t, signed char *fv, signed char *fh){	int i, j;	memset(fh, -1, (t->x + 2) * (t->y + 1));	memset(fv, -1, (t->x + 1) * (t->y + 2));	for (j = 0; j < t->y; j++) for (i = 0; i < t->x; i++) {		int x, y;		int xsp, ysp;		struct table_cell *cell = CELL(t, i, j);		if (!cell->used || cell->spanned) continue;		if ((xsp = cell->colspan) == 0) xsp = t->x - i;		if ((ysp = cell->rowspan) == 0) ysp = t->y - j;		if (t->rules != R_NONE && t->rules != R_COLS) for (x = 0; x < xsp; x++) {H_LINE_X(i + x, j) = t->cellsp; H_LINE_X(i + x, j + ysp) = t->cellsp;}		if (t->rules != R_NONE && t->rules != R_ROWS) for (y = 0; y < ysp; y++) {V_LINE_X(i, j + y) = t->cellsp; V_LINE_X(i + xsp, j + y) = t->cellsp;}		if (F) {			for (x = 0; x < xsp; x++) for (y = 1; y < ysp; y++)				H_LINE_X(i + x, j + y) = -2;			for (x = 1; x < xsp; x++) for (y = 0; y < ysp; y++)				V_LINE_X(i + x, j + y) = -2;		}	}	if (t->rules == R_GROUPS) {		for (i = 1; i < t->x; i++) {			if (/*i < t->xc &&*/ t->xcols[i]) continue;			for (j = 0; j < t->y; j++) V_LINE_X(i, j) = 0;		}		for (j = 1; j < t->y; j++) {			for (i = 0; i < t->x; i++) if (CELL(t, i, j)->group) goto c;			for (i = 0; i < t->x; i++) H_LINE_X(i, j) = 0;			c:;		}	}	for (i = 0; i < t->x; i++) {		H_LINE_X(i, 0) = t->border * !!(t->frame & F_ABOVE);		H_LINE_X(i, t->y) = t->border * !!(t->frame & F_BELOW);	}	for (j = 0; j < t->y; j++) {		V_LINE_X(0, j) = t->border * !!(t->frame & F_LHS);		V_LINE_X(t->x, j) = t->border * !!(t->frame & F_RHS);	}}void display_table_frames(struct table *t, int x, int y){	signed char *fh, *fv;	int i, j;	int cx, cy;	if ((unsigned)t->x > MAXINT) overalloc();	if ((unsigned)t->y > MAXINT) overalloc();	if (((unsigned)t->x + 2) * ((unsigned)t->y + 2) / ((unsigned)t->x + 2) != ((unsigned)t->y + 2)) overalloc();	if (((unsigned)t->x + 2) * ((unsigned)t->y + 2) > MAXINT) overalloc();	fh = mem_alloc((t->x + 2) * (t->y + 1));	fv = mem_alloc((t->x + 1) * (t->y + 2));	get_table_frame(t, fv, fh);	cy = y;	for (j = 0; j <= t->y; j++) {		cx = x;		if ((j > 0 && j < t->y && get_hline_width(t, j) >= 0) || (j == 0 && t->border && (t->frame & F_ABOVE)) || (j == t->y && t->border && (t->frame & F_BELOW))) {			for (i = 0; i < t->x; i++) {				int w;				if (i > 0) w = get_vline_width(t, i);				else w = t->border && (t->frame & F_LHS) ? t->border : -1;				if (w >= 0) {					draw_frame_point(cx, cy, i, j);					if (j < t->y) draw_frame_vline(cx, cy + 1, t->r_heights[j], i, j);					cx++;				}				w = t->w_c[i];				draw_frame_hline(cx, cy, w, i, j);				cx += w;			}			if (t->border && (t->frame & F_RHS)) {				draw_frame_point(cx, cy, i, j);				if (j < t->y) draw_frame_vline(cx, cy + 1, t->r_heights[j], i, j);				cx++;			}			cy++;		} else if (j < t->y) {			for (i = 0; i <= t->x; i++) {				if ((i > 0 && i < t->x && get_vline_width(t, i) >= 0) || (i == 0 && t->border && (t->frame & F_LHS)) || (i == t->x && t->border && (t->frame & F_RHS))) {					draw_frame_vline(cx, cy, t->r_heights[j], i, j);					cx++;				}				if (i < t->x) cx += t->w_c[i];			}		}		if (j < t->y) cy += t->r_heights[j];		/*for (cyy = cy1; cyy < cy; cyy++) xxpand_line(t->p, cyy, cx - 1);*/	}	mem_free(fh);	mem_free(fv);}#ifdef Gvoid process_g_table(struct g_part *gp, struct table *t);#endifvoid format_table(unsigned char *attr, unsigned char *html, unsigned char *eof, unsigned char **end, void *f){	struct part *p = !F ? f : NULL;#ifdef G	struct g_part *gp = F ? f : NULL;#endif	int border, cellsp, vcellpd, cellpd, align;	int frame, rules, width, wf;	struct rgb bgcolor;	struct table *t;	char *al;	int cye;	int x;	int i;	/*int llm = last_link_to_move;*/	struct s_e *bad_html = NULL;	int bad_html_n;	struct node *n, *nn;	int cpd_pass, cpd_width, cpd_last;	table_level++;	memcpy(&bgcolor, &par_format.bgcolor, sizeof(struct rgb));	get_bgcolor(attr, &bgcolor);	if ((border = get_num(attr, "border")) == -1) border = has_attr(attr, "border") || has_attr(attr, "rules") || has_attr(attr, "frame");	/*if (!border) border = 1;*/	if ((cellsp = get_num(attr, "cellspacing")) == -1) cellsp = gf_val(1, 2);	if ((cellpd = get_num(attr, "cellpadding")) == -1) {		vcellpd = gf_val(0, 1);		cellpd = gf_val(!!border, 1);	} else {		if (!F) {			vcellpd = cellpd >= HTML_CHAR_HEIGHT / 2 + 1;			cellpd = cellpd >= HTML_CHAR_WIDTH / 2 + 1;		} else vcellpd = cellpd;	}	if (!F && !border) cellsp = 0;	else if (!F && !cellsp) cellsp = 1;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -