patch 9.1.0871: getcellpixels() can be further improved

Problem:  getcellpixels() can be further improved
Solution: Fix floating point exception, implement getcellpixels() in the
          UI (mikoto2000)

closes: #16059

Signed-off-by: mikoto2000 <mikoto2000@gmail.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
diff --git a/src/evalfunc.c b/src/evalfunc.c
index 12f7a88..b2905da 100644
--- a/src/evalfunc.c
+++ b/src/evalfunc.c
@@ -61,6 +61,7 @@
 static void f_function(typval_T *argvars, typval_T *rettv);
 static void f_garbagecollect(typval_T *argvars, typval_T *rettv);
 static void f_get(typval_T *argvars, typval_T *rettv);
+static void f_getcellpixels(typval_T *argvars, typval_T *rettv);
 static void f_getchangelist(typval_T *argvars, typval_T *rettv);
 static void f_getcharpos(typval_T *argvars, typval_T *rettv);
 static void f_getcharsearch(typval_T *argvars, typval_T *rettv);
@@ -2078,13 +2079,7 @@
     {"getbufvar",	2, 3, FEARG_1,	    arg3_buffer_string_any,
 			ret_any,	    f_getbufvar},
     {"getcellpixels",	0, 0, 0,	    NULL,
-			ret_list_any,
-#if (defined(UNIX) || defined(VMS)) && (defined(FEAT_EVAL) || defined(PROTO))
-	    f_getcellpixels
-#else
-	    NULL
-#endif
-			},
+			ret_list_any,	    f_getcellpixels},
     {"getcellwidths",	0, 0, 0,	    NULL,
 			ret_list_any,	    f_getcellwidths},
     {"getchangelist",	0, 1, FEARG_1,	    arg1_buffer,
@@ -5217,6 +5212,45 @@
 }
 
 /*
+ * "getcellpixels()" function
+ */
+    static void
+f_getcellpixels(typval_T *argvars UNUSED, typval_T *rettv)
+{
+    if (rettv_list_alloc(rettv) == FAIL)
+        return;
+
+#if defined(FEAT_GUI)
+    if (gui.in_use)
+    {
+        // success pixel size and no gui.
+        list_append_number(rettv->vval.v_list, (varnumber_T)gui.char_width);
+        list_append_number(rettv->vval.v_list, (varnumber_T)gui.char_height);
+    }
+    else
+#endif
+    {
+        struct cellsize cs;
+#if defined(UNIX)
+        mch_calc_cell_size(&cs);
+#else
+        // Non-Unix CUIs are not supported, so set this to -1x-1.
+        cs.cs_xpixel = -1;
+        cs.cs_ypixel = -1;
+#endif
+
+        // failed get pixel size.
+        if (cs.cs_xpixel == -1)
+            return;
+
+        // success pixel size and no gui.
+        list_append_number(rettv->vval.v_list, (varnumber_T)cs.cs_xpixel);
+        list_append_number(rettv->vval.v_list, (varnumber_T)cs.cs_ypixel);
+    }
+
+}
+
+/*
  * "getchangelist()" function
  */
     static void