2013-01-28 08:06:26 -08:00
|
|
|
#include <Eina.h>
|
|
|
|
#include <Ecore.h>
|
|
|
|
#include <Evas.h>
|
|
|
|
#include <Ecore_Evas.h>
|
2013-01-28 08:43:45 -08:00
|
|
|
#include <Ecore_File.h>
|
2013-01-28 15:53:06 -08:00
|
|
|
#include <Edje.h>
|
2013-01-28 08:06:26 -08:00
|
|
|
#include <termios.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
enum {
|
|
|
|
CENTER,
|
|
|
|
FILL,
|
|
|
|
STRETCH
|
|
|
|
};
|
|
|
|
|
|
|
|
Ecore_Evas *ee = NULL;
|
|
|
|
Evas *evas = NULL;
|
|
|
|
Evas_Object *o = NULL;
|
|
|
|
struct termios told, tnew;
|
|
|
|
int tw = 0, th = 0, cw = 0, ch = 0;
|
|
|
|
int w = 0, h = 0;
|
|
|
|
int iw = 0, ih = 0;
|
|
|
|
|
|
|
|
static int
|
|
|
|
echo_off(void)
|
|
|
|
{
|
|
|
|
if (tcgetattr(0, &told) != 0) return -1;
|
|
|
|
tnew = told;
|
|
|
|
tnew.c_lflag &= ~ECHO;
|
|
|
|
if (tcsetattr(0, TCSAFLUSH, &tnew) != 0) return -1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
echo_on(void)
|
|
|
|
{
|
|
|
|
return tcsetattr(0, TCSAFLUSH, &told);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
main(int argc, char **argv)
|
|
|
|
{
|
|
|
|
char buf[8192];
|
|
|
|
|
|
|
|
if (!getenv("TERMINOLOGY")) return 0;
|
|
|
|
if (argc <= 1)
|
|
|
|
{
|
|
|
|
printf("Usage: %s [-s|-f|-c] FILE1 [FILE2 ...]\n"
|
|
|
|
"\n"
|
|
|
|
" -s Stretch file to fill nearest character cell size\n"
|
|
|
|
" -f Fill file to totally cover character cells with no gaps\n"
|
|
|
|
" -c Center file in nearest character cells but only scale down (default)\n",
|
|
|
|
argv[0]);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
eina_init();
|
|
|
|
ecore_init();
|
2013-01-28 08:43:45 -08:00
|
|
|
ecore_file_init();
|
2013-01-28 08:06:26 -08:00
|
|
|
evas_init();
|
|
|
|
ecore_evas_init();
|
2013-01-28 15:53:06 -08:00
|
|
|
edje_init();
|
2013-01-28 08:06:26 -08:00
|
|
|
ee = ecore_evas_buffer_new(1, 1);
|
|
|
|
if (ee)
|
|
|
|
{
|
|
|
|
int i, mode = CENTER;
|
|
|
|
|
|
|
|
evas = ecore_evas_get(ee);
|
|
|
|
o = evas_object_image_add(evas);
|
2013-01-28 08:43:45 -08:00
|
|
|
echo_off();
|
|
|
|
snprintf(buf, sizeof(buf), "%c}qs", 0x1b);
|
2013-01-28 16:43:13 -08:00
|
|
|
if (write(0, buf, strlen(buf) + 1) < 0) perror("write");
|
2013-01-28 08:43:45 -08:00
|
|
|
if (scanf("%i;%i;%i;%i", &tw, &th, &cw, &ch) != 4)
|
|
|
|
{
|
|
|
|
echo_on();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
echo_on();
|
2013-01-28 08:06:26 -08:00
|
|
|
for (i = 1; i < argc; i++)
|
|
|
|
{
|
2013-01-28 08:43:45 -08:00
|
|
|
char *path, *rp;
|
2013-01-28 08:06:26 -08:00
|
|
|
|
|
|
|
if (!strcmp(argv[i], "-c"))
|
|
|
|
{
|
|
|
|
mode = CENTER;
|
|
|
|
i++;
|
|
|
|
if (i >= argc) return 0;
|
|
|
|
}
|
|
|
|
else if (!strcmp(argv[i], "-s"))
|
|
|
|
{
|
|
|
|
mode = STRETCH;
|
|
|
|
i++;
|
|
|
|
if (i >= argc) return 0;
|
|
|
|
}
|
|
|
|
else if (!strcmp(argv[i], "-f"))
|
|
|
|
{
|
|
|
|
mode = FILL;
|
|
|
|
i++;
|
|
|
|
if (i >= argc) return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
path = argv[i];
|
2013-01-28 08:43:45 -08:00
|
|
|
rp = ecore_file_realpath(path);
|
|
|
|
if (rp)
|
2013-01-28 08:06:26 -08:00
|
|
|
{
|
2013-01-28 08:43:45 -08:00
|
|
|
evas_object_image_file_set(o, rp, NULL);
|
|
|
|
evas_object_image_size_get(o, &w, &h);
|
|
|
|
if ((w >= 0) && (h > 0))
|
2013-01-28 08:06:26 -08:00
|
|
|
{
|
2013-01-28 19:34:50 -08:00
|
|
|
int x, y, i;
|
2013-01-28 16:43:13 -08:00
|
|
|
char *line;
|
2013-01-28 08:43:45 -08:00
|
|
|
|
2013-01-28 16:43:13 -08:00
|
|
|
if ((tw <= 0) || (th <= 0) || (cw <= 1) || (ch <= 1))
|
2013-01-28 08:43:45 -08:00
|
|
|
{
|
|
|
|
free(rp);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (w > (tw * cw))
|
|
|
|
{
|
|
|
|
iw = tw;
|
|
|
|
ih = ((h * (tw * cw) / w) + (ch - 1)) / ch;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
iw = (w + (cw - 1)) / cw;
|
|
|
|
ih = (h + (ch - 1)) / ch;
|
|
|
|
}
|
2013-01-28 19:34:50 -08:00
|
|
|
line = malloc(iw + 100);
|
2013-01-28 16:43:13 -08:00
|
|
|
if (!line)
|
|
|
|
{
|
|
|
|
free(rp);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (mode == CENTER)
|
|
|
|
snprintf(buf, sizeof(buf), "%c}ic#%i;%i;%s",
|
2013-01-28 08:43:45 -08:00
|
|
|
0x1b, iw, ih, rp);
|
|
|
|
else if (mode == FILL)
|
2013-01-28 16:43:13 -08:00
|
|
|
snprintf(buf, sizeof(buf), "%c}if#%i;%i;%s",
|
2013-01-28 08:43:45 -08:00
|
|
|
0x1b, iw, ih, rp);
|
|
|
|
else
|
2013-01-28 16:43:13 -08:00
|
|
|
snprintf(buf, sizeof(buf), "%c}is#%i;%i;%s",
|
2013-01-28 08:43:45 -08:00
|
|
|
0x1b, iw, ih, rp);
|
2013-01-28 16:43:13 -08:00
|
|
|
if (write(0, buf, strlen(buf) + 1) < 0) perror("write");
|
2013-01-28 19:34:50 -08:00
|
|
|
i = 0;
|
|
|
|
line[i++] = 0x1b;
|
|
|
|
line[i++] = '}';
|
|
|
|
line[i++] = 'i';
|
|
|
|
line[i++] = 'b';
|
|
|
|
line[i++] = 0;
|
|
|
|
for (x = 0; x < iw; x++) line[i++] = '#';
|
|
|
|
line[i++] = 0x1b;
|
|
|
|
line[i++] = '}';
|
|
|
|
line[i++] = 'i';
|
|
|
|
line[i++] = 'e';
|
|
|
|
line[i++] = 0;
|
|
|
|
line[i++] = '\n';
|
|
|
|
line[i++] = 0;
|
2013-01-28 08:43:45 -08:00
|
|
|
for (y = 0; y < ih; y++)
|
2013-01-28 08:06:26 -08:00
|
|
|
{
|
2013-01-28 19:34:50 -08:00
|
|
|
if (write(0, line, i) < 0) perror("write");
|
2013-01-28 08:06:26 -08:00
|
|
|
}
|
2013-01-28 16:43:13 -08:00
|
|
|
free(line);
|
2013-01-28 08:06:26 -08:00
|
|
|
}
|
2013-01-28 08:43:45 -08:00
|
|
|
free(rp);
|
2013-01-28 08:06:26 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// ecore_main_loop_begin();
|
|
|
|
ecore_evas_free(ee);
|
|
|
|
}
|
2013-01-28 15:53:06 -08:00
|
|
|
edje_shutdown();
|
2013-01-28 08:06:26 -08:00
|
|
|
ecore_evas_shutdown();
|
|
|
|
evas_shutdown();
|
2013-01-28 08:43:45 -08:00
|
|
|
ecore_file_shutdown();
|
2013-01-28 08:06:26 -08:00
|
|
|
ecore_shutdown();
|
|
|
|
eina_shutdown();
|
|
|
|
return 0;
|
|
|
|
}
|