Beispiel #1
0
static void
resize_columns (Sheet *sheet)
{
	GnmRange r;

	if (gnm_debug_flag ("stf"))
		g_printerr ("Auto-fitting columns...\n");

	/* If we have lots of rows, auto-fitting will take a very long
	   time.  It is probably better to look at only, say, 1000 rows
	   of data.  */
	range_init_full_sheet (&r, sheet);
	r.end.row = MIN (r.end.row, 1000);

	colrow_autofit (sheet, &r, TRUE,
			TRUE, /* Ignore strings */
			TRUE, /* Don't shrink */
			TRUE, /* Don't shrink */
			NULL, NULL);
	if (gnm_debug_flag ("stf"))
		g_printerr ("Auto-fitting columns...  done\n");

	sheet_queue_respan (sheet, 0, gnm_sheet_get_last_row (sheet));
}
Beispiel #2
0
static gboolean
sylk_rtd_f_parse (SylkReader *state, char *str)
{
	GnmStyle *style = NULL;
	char *next;
	int   tmp, size = -1;
	gboolean is_default_style = FALSE;
	int full_col = -1, full_row = -1;

	for (; *str != '\0' ; str = next) {
		next = sylk_next_token (str);
		switch (*str) {
		case 'D': /* Default sheet style
			     ;D<fmt-id><digits><alignment><num_cols??> default Format. */
			is_default_style = TRUE;

		case 'F': { /* Cell Format
			     ;F<fmt-id><digits><alignment>: Single cell format. */

			 /* Format:
				D - default
				C - currency (extended)
				E - exponent
				F - fixed
				G - general,
				$ - dollar
				* - graph
				% - percent

			   Alignment: DCGLR-X
				*/
			char ch1, alignment;
			if (3 == sscanf (str+1, "%c%d%c", &ch1, &tmp, &alignment)) {
				int a = -1;
				switch (alignment) {
				case 'S' : /* standard ? how does this differ from default */
				case 'D' : a = GNM_HALIGN_GENERAL; break;
				case 'L' : a = GNM_HALIGN_LEFT; break;
				case 'R' : a = GNM_HALIGN_RIGHT; break;
				case 'C' : a = GNM_HALIGN_CENTER; break;
				case 'X' : a = GNM_HALIGN_FILL; break;
				default :
					   break;
				}
				if (a >= 0) {
					if (style == NULL) style = gnm_style_new ();
					gnm_style_set_align_h (style, a);
				}
			}
			break;
		}

		/**************************************************/
		/* Globals */
		case 'E':
			state->pp.sheet->display_formulas = TRUE;
			break;
		case 'G':
			state->pp.sheet->hide_grid = TRUE;
			break;
		case 'H':
			state->pp.sheet->hide_col_header = TRUE;
			state->pp.sheet->hide_row_header = TRUE;
			break;
		case 'K': /* show commas ?? */
			break;
		case 'Z': /* hide zeros */
			state->pp.sheet->hide_zero = TRUE;
			break;
		/**************************************************/

		case 'M' : /* row or col size * 20 or num cols for global */
			sylk_parse_int (str+1, &size);
			break;

		case 'N' : { /* global font */
			int size;
			if (2 == sscanf (str+1, "%d %d", &tmp, &size) &&
			    1 <= tmp && tmp <= (int)state->fonts->len) {
				GnmStyle const *font =
					g_ptr_array_index (state->fonts, tmp-1);
				if (style == NULL) style = gnm_style_new ();
				is_default_style = TRUE;
				gnm_style_merge_element (style, font,
					MSTYLE_FONT_NAME);
				gnm_style_merge_element (style, font,
					MSTYLE_FONT_SIZE);
				/* It looks like the size from the id dominates
				 * this size */
			}
			break;
		}

		case 'P':
			if (sylk_parse_int (str+1, &tmp) &&
			    0 <= tmp && tmp < (int)state->formats->len) {
				if (style == NULL) style = gnm_style_new ();
				gnm_style_set_format (style,
					g_ptr_array_index (state->formats, tmp));
			}
			break;

		case 'S':
			for (str++ ; *str && *str != ';' ; str++) {
				switch (*str) {
				case 'I':
					if (style == NULL) style = gnm_style_new ();
					gnm_style_set_font_italic (style, TRUE);
					break;

				case 'D':
					if (style == NULL) style = gnm_style_new ();
					gnm_style_set_font_bold (style, TRUE);
					break;

				case 'M':
					if (sylk_parse_int (str+1, &tmp) &&
					    1 <= tmp && tmp <= (int)state->fonts->len) {
						GnmStyle const *font =
							g_ptr_array_index (state->fonts, tmp-1);
						if (style == NULL) style = gnm_style_new ();
						gnm_style_merge_element (style, font,
									 MSTYLE_FONT_NAME);
						gnm_style_merge_element (style, font,
									 MSTYLE_FONT_SIZE);
					}
					str = (char *)" ";
					break;

				case 'S': /* seems to stipple things */
					if (style == NULL) style = gnm_style_new ();
					gnm_style_set_pattern (style, 5);
					break;

				case 'T': style = sylk_set_border (style, MSTYLE_BORDER_TOP); break;
				case 'B': style = sylk_set_border (style, MSTYLE_BORDER_BOTTOM); break;
				case 'L': style = sylk_set_border (style, MSTYLE_BORDER_LEFT); break;
				case 'R': style = sylk_set_border (style, MSTYLE_BORDER_RIGHT); break;

				default:
					sylk_read_warning (state, "unhandled style S%c.", *str);
				}
			}
			break;

		case 'W': {
			int first, last, width;
			if (3 == sscanf (str+1, "%d %d %d", &first, &last, &width)) {
				/* width seems to be in characters */
				if (first <= last &&
				    first < gnm_sheet_get_max_cols (state->pp.sheet) &&
				    last < gnm_sheet_get_max_cols (state->pp.sheet))
					while (first <= last)
						sheet_col_set_size_pts (state->pp.sheet,
							first++ - 1, width*7.45, TRUE);
			}
			break;
		}

		case 'C': if (sylk_parse_int (str+1, &tmp)) full_col = tmp - 1; break;
		case 'R': if (sylk_parse_int (str+1, &tmp)) full_row = tmp - 1; break;
		case 'X': if (sylk_parse_int (str+1, &tmp)) state->pp.eval.col = tmp - 1; break;
		case 'Y': if (sylk_parse_int (str+1, &tmp)) state->pp.eval.row = tmp - 1; break;
		default:
			sylk_read_warning (state, "unhandled F option %c.", *str);
		}
	}

	if (full_col >= 0) {
		if (NULL != style)
			sheet_style_apply_col (state->pp.sheet, full_col, style);
		if (size > 0)
			sheet_col_set_size_pts (state->pp.sheet,
						full_col, size / 20.0, FALSE);
	} else if (full_row >= 0) {
		if (NULL != style)
			sheet_style_apply_row (state->pp.sheet, full_row, style);
		if (size > 0)
			sheet_row_set_size_pts (state->pp.sheet,
						full_row, size / 20.0, FALSE);
	} else if (NULL != style) {
		if (is_default_style) {
			GnmRange r;
			range_init_full_sheet (&r, state->pp.sheet);
			sheet_style_apply_range (state->pp.sheet, &r, style);
		} else
			sheet_style_apply_pos (state->pp.sheet,
				state->pp.eval.col, state->pp.eval.row, style);
	}

	return TRUE;
}