gnumeric r17297 - trunk/src



Author: mortenw
Date: Sat Apr  4 14:43:40 2009
New Revision: 17297
URL: http://svn.gnome.org/viewvc/gnumeric?rev=17297&view=rev

Log:
Check for too large sheets areawise too.



Modified:
   trunk/src/gnumeric.h
   trunk/src/sheet.c
   trunk/src/sheet.h
   trunk/src/xml-sax-read.c

Modified: trunk/src/gnumeric.h
==============================================================================
--- trunk/src/gnumeric.h	(original)
+++ trunk/src/gnumeric.h	Sat Apr  4 14:43:40 2009
@@ -8,12 +8,18 @@
 
 G_BEGIN_DECLS
 
-/* really used rows and columns should not exceed these values (TILE_TOP_LEVEL
- can't exceed 5 currently) */
-#define GNM_DEFAULT_ROWS 0x10000
+/* Individual maxima for the dimensions.  See also gnm_sheet_valid_size.  */
 #define GNM_MAX_ROWS 0x1000000
-#define GNM_DEFAULT_COLS 0x100
 #define GNM_MAX_COLS 0x1000
+
+/* Standard size */
+#define GNM_DEFAULT_COLS 0x100
+#define GNM_DEFAULT_ROWS 0x10000
+
+/* Minimum size.  dependent.c sets row constraint.  */
+#define GNM_MIN_ROWS 0x80
+#define GNM_MIN_COLS 0x80
+
 /*
  * Note: more than 364238 columns will introduce a column named TRUE.
  */

Modified: trunk/src/sheet.c
==============================================================================
--- trunk/src/sheet.c	(original)
+++ trunk/src/sheet.c	Sat Apr  4 14:43:40 2009
@@ -1039,22 +1039,50 @@
 
 /* ------------------------------------------------------------------------- */
 
+static gboolean
+powerof2 (int i)
+{
+	return i > 0 && (i & (i - 1)) == 0;
+}
+
 gboolean
+gnm_sheet_valid_size (int cols, int rows)
+{
+	return (cols >= GNM_MIN_COLS &&
+		cols <= GNM_MAX_COLS &&
+		powerof2 (cols) &&
+		rows >= GNM_MIN_ROWS &&
+		rows <= GNM_MAX_ROWS &&
+		powerof2 (rows) &&
+		0x80000000u / (unsigned)(cols / 2) >= (unsigned)rows);
+}
+
+void
 gnm_sheet_suggest_size (int *cols, int *rows)
 {
-	gboolean bad = (*cols > GNM_MAX_COLS || *rows > GNM_MAX_ROWS);
 	int c = GNM_DEFAULT_COLS;
 	int r = GNM_DEFAULT_ROWS;
 
 	while (c < *cols && c < GNM_MAX_COLS)
 		c *= 2;
-	*cols = c;
 
 	while (r < *rows && r < GNM_MAX_ROWS)
 		r *= 2;
-	*rows = r;
 
-	return bad;
+	while (!gnm_sheet_valid_size (c, r)) {
+		/* Darn!  Too large.  */
+		if (*cols >= GNM_MIN_COLS && c > GNM_MIN_COLS)
+			c /= 2;
+		else if (*rows >= GNM_MIN_ROWS && r > GNM_MIN_ROWS)
+			r /= 2;
+		else if (c > GNM_MIN_COLS)
+			c /= 2;
+		else
+			r /= 2;
+	}
+
+	*cols = c;
+	*rows = r;
 }
 
 /**
@@ -1076,8 +1104,7 @@
 
 	g_return_val_if_fail (wb != NULL, NULL);
 	g_return_val_if_fail (name != NULL, NULL);
-	g_return_val_if_fail (columns <= GNM_MAX_COLS, NULL);
-	g_return_val_if_fail (rows <= GNM_MAX_ROWS, NULL);
+	g_return_val_if_fail (gnm_sheet_valid_size (columns, rows), NULL);
 
 	sheet = g_object_new (GNM_SHEET_TYPE,
 			      "workbook", wb,

Modified: trunk/src/sheet.h
==============================================================================
--- trunk/src/sheet.h	(original)
+++ trunk/src/sheet.h	Sat Apr  4 14:43:40 2009
@@ -125,7 +125,8 @@
 Sheet    *sheet_dup		 (Sheet const *source_sheet);
 void      sheet_destroy_contents (Sheet *sheet);
 
-gboolean  gnm_sheet_suggest_size (int *cols, int *rows);
+gboolean  gnm_sheet_valid_size   (int cols, int rows);
+void      gnm_sheet_suggest_size (int *cols, int *rows);
 
 int gnm_sheet_get_max_rows (Sheet const *sheet);
 int gnm_sheet_get_max_cols (Sheet const *sheet);

Modified: trunk/src/xml-sax-read.c
==============================================================================
--- trunk/src/xml-sax-read.c	(original)
+++ trunk/src/xml-sax-read.c	Sat Apr  4 14:43:40 2009
@@ -496,9 +496,17 @@
 	g_return_if_fail (name != NULL);
 
 	if (NULL == workbook_sheet_by_name (wb, name)) {
-		Sheet *sheet = sheet_new (wb, name,
-					  state->sheet_cols,
-					  state->sheet_rows);
+		Sheet *sheet;
+
+		if (!gnm_sheet_valid_size (state->sheet_cols,
+					   state->sheet_rows)) {
+			gnm_sheet_suggest_size (&state->sheet_cols,
+						&state->sheet_rows);
+		}
+
+		sheet = sheet_new (wb, name,
+				   state->sheet_cols,
+				   state->sheet_rows);
 		workbook_sheet_attach (wb, sheet);
 	}
 }



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]