Revert "Imported Upstream version 1.2.7"
[platform/upstream/harfbuzz.git] / util / ansi-print.cc
index e0ce7b3..0fc3719 100644 (file)
@@ -41,7 +41,7 @@
 #include <unistd.h> /* for isatty() */
 #endif
 
-#if defined (_MSC_VER) && (_MSC_VER < 1800)
+#ifdef _MSC_VER
 static inline long int
 lround (double x)
 {
@@ -52,8 +52,6 @@ lround (double x)
 }
 #endif
 
-#define ESC_E (char)27
-
 #define MIN(a,b) ((a) < (b) ? (a) : (b))
 
 #define CELL_W 8
@@ -224,12 +222,11 @@ struct biimage_t
 };
 
 const char *
-block_best (const biimage_t &bi, bool *inverse)
+block_best (const biimage_t &bi, unsigned int *score, bool *inverse)
 {
   assert (bi.width  <= CELL_W);
   assert (bi.height <= CELL_H);
 
-  unsigned int score = (unsigned int) -1;
   unsigned int row_sum[CELL_H] = {0};
   unsigned int col_sum[CELL_W] = {0};
   unsigned int row_sum_i[CELL_H] = {0};
@@ -265,14 +262,14 @@ block_best (const biimage_t &bi, bool *inverse)
   const char *best_c = " ";
 
   /* Maybe empty is better! */
-  if (total < score) {
-    score = total;
+  if (total < *score) {
+    *score = total;
     *inverse = false;
     best_c = " ";
   }
   /* Maybe full is better! */
-  if (total_i < score) {
-    score = total_i;
+  if (total_i < *score) {
+    *score = total_i;
     *inverse = true;
     best_c = " ";
   }
@@ -298,11 +295,11 @@ block_best (const biimage_t &bi, bool *inverse)
        best_inv = true;
       }
     }
-    if (best_s < score) {
+    if (best_s < *score) {
       static const char *lower[7] = {"▁", "▂", "▃", "▄", "▅", "▆", "▇"};
-      unsigned int which = lround ((double) ((best_i + 1) * 8) / bi.height);
+      unsigned int which = lround (((best_i + 1) * 8) / bi.height);
       if (1 <= which && which <= 7) {
-       score = best_s;
+       *score = best_s;
        *inverse = best_inv;
        best_c = lower[7 - which];
       }
@@ -330,11 +327,11 @@ block_best (const biimage_t &bi, bool *inverse)
        best_inv = false;
       }
     }
-    if (best_s < score) {
+    if (best_s < *score) {
       static const char *left [7] = {"▏", "▎", "▍", "▌", "▋", "▊", "▉"};
-      unsigned int which = lround ((double) ((best_i + 1) * 8) / bi.width);
+      unsigned int which = lround (((best_i + 1) * 8) / bi.width);
       if (1 <= which && which <= 7) {
-       score = best_s;
+       *score = best_s;
        *inverse = best_inv;
        best_c = left[which - 1];
       }
@@ -352,7 +349,7 @@ block_best (const biimage_t &bi, bool *inverse)
          qs += quad_i[i][j];
        } else
          qs += quad[i][j];
-    if (qs < score) {
+    if (qs < *score) {
       const char *c = NULL;
       bool inv = false;
       switch (q) {
@@ -368,7 +365,7 @@ block_best (const biimage_t &bi, bool *inverse)
        case 14: c = "▟"; inv = true;  break;
       }
       if (c) {
-       score = qs;
+       *score = qs;
        *inverse = inv;
        best_c = c;
       }
@@ -397,23 +394,24 @@ ansi_print_image_rgb24 (const uint32_t *data,
       bi.set (cell);
       if (bi.unicolor) {
         if (last_bg != bi.bg) {
-         printf ("%c[%dm", ESC_E, 40 + bi.bg);
+         printf ("\e[%dm", 40 + bi.bg);
          last_bg = bi.bg;
        }
        printf (" ");
       } else {
         /* Figure out the closest character to the biimage */
+        unsigned int score = (unsigned int) -1;
        bool inverse = false;
-        const char *c = block_best (bi, &inverse);
+        const char *c = block_best (bi, &score, &inverse);
        if (inverse) {
          if (last_bg != bi.fg || last_fg != bi.bg) {
-           printf ("%c[%d;%dm", ESC_E, 30 + bi.bg, 40 + bi.fg);
+           printf ("\e[%d;%dm", 30 + bi.bg, 40 + bi.fg);
            last_bg = bi.fg;
            last_fg = bi.bg;
          }
        } else {
          if (last_bg != bi.bg || last_fg != bi.fg) {
-           printf ("%c[%d;%dm", ESC_E, 40 + bi.bg, 30 + bi.fg);
+           printf ("\e[%d;%dm", 40 + bi.bg, 30 + bi.fg);
            last_bg = bi.bg;
            last_fg = bi.fg;
          }
@@ -421,7 +419,7 @@ ansi_print_image_rgb24 (const uint32_t *data,
        printf ("%s", c);
       }
     }
-    printf ("%c[0m\n", ESC_E); /* Reset */
+    printf ("\e[0m\n"); /* Reset */
     last_bg = last_fg = -1;
   }
 }