working render of unicode characters

everything is to document and I left a lot of
garbage comments :p
master
Alessandro Mauri 4 years ago
parent 74fa0c7582
commit fac8e0d96a
  1. BIN
      .sconsign.dblite
  2. 1
      src/config.h
  3. 31
      src/fbuffer.c
  4. 4
      src/fbuffer.h
  5. BIN
      src/fbuffer.o
  6. 27
      src/ste.c
  7. BIN
      src/ste.o

Binary file not shown.

@ -2,5 +2,6 @@
#define _CONFIG_H_
#define TABSIZE 4 // Tab size as used in render
#define MAX_LINE 1024 // maximum line length on screen
#endif

@ -3,6 +3,7 @@
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <wchar.h>
void bufInit (FileBuffer *b)
{
@ -172,11 +173,27 @@ void updateRender (Row *rw)
{
/* count the special characters
* spaces, utf-8 continuation chars */
static int tabs, i, off, cc, ut;
for (i = 0, tabs = 0, cc = 0, ut = 0; i < rw->size; i++) {
static int tabs, i, off/*, utf_width, utf_chars*/;
//static wchar_t wc_tmp;
//static char *mb_p;
tabs = 0;
//utf_width = 0;
//utf_chars = 0;
for (i = 0; i < rw->size; i++) {
if (rw->chars[i] == '\t') tabs++;
else if (isCont(rw->chars[i])) cc++;
else if (isUtf(rw->chars[i])) ut++;
/*else if (isStart(rw->chars[i])) {
utf_chars++;
wc_tmp = 0;
mb_p = &rw->chars[i];
//int utf_len = mblen(mb_p, rw->size - i);
mbtowc(&wc_tmp, mb_p, rw->size - i);
utf_width += wcwidth(wc_tmp);
//utf_len += utf_chars;
} */
}
rw->render = NULL;
free(rw->render);
@ -200,6 +217,6 @@ void updateRender (Row *rw)
}
}
rw->render[off] = '\0';
rw->r_size = off - cc;
rw->utf = cc + ut;
}
rw->r_size = off;
//rw->utf = utf_width - utf_chars;
}

@ -1,6 +1,8 @@
#ifndef _FBUFFER_H_
#define _FBUFFER_H_
#ifndef _XOPEN_SOURCE
#define _XOPEN_SOURCE /* See feature_test_macros(7) */
#endif
/* Row structure, defines actual and
* render chars, actual and render size
* and difference between render and

Binary file not shown.

@ -6,6 +6,7 @@
#include <string.h>
#include <ctype.h>
#include <locale.h>
#include <wchar.h>
#include "fbuffer.h"
#include "config.h"
@ -14,6 +15,7 @@
#define CTRL(k) ((k) & 0x1f) // Control mask modifier
#define STAT_SIZE 128
#define CBUF_SIZE 2048
#define MAX_LINE 1024
#define MODE_MASK 0x1
#define COMMAND_MASK 0x06
@ -103,6 +105,10 @@ static void sbMove (CharBuffer *buf, int x);
/* --------------------------------- main ------------------------------------ */
int main (int argc, char *argv[])
{
/* Init locales */
setlocale(LC_ALL, "");
setlocale(LC_CTYPE, "");
/* Initialize the first row */
bufInit(&rows);
@ -210,9 +216,6 @@ int main (int argc, char *argv[])
void termInit (void)
{
/* Init locales */
setlocale(LC_ALL, "");
/* Init the screen and refresh */
initscr();
refresh();
@ -324,9 +327,17 @@ void drawLines (void)
/* Draw the line matcing render memory */
if (&rows.rw[ln] == NULL) termDie("drawlines NULL");
if (rows.rw[ln].r_size > t.cur.off_x) {
start = t.cur.off_x;
while (isCont(rows.rw[ln].render[start])) start++;
addnstr(&rows.rw[ln].render[start], (t.dim.x + 1) + (rows.rw[ln].utf >> 2));
while (isCont(rows.rw[ln].render[start])) start++;
static wchar_t converted_line[MAX_LINE];
static int x = 0;
for (x = 0; x < MAX_LINE; x++) converted_line[x] = 0;
mbstowcs(converted_line, &rows.rw[ln].render[start], MAX_LINE);
addnwstr(converted_line, t.dim.x + 1);
//addnstr(&rows.rw[ln].render[start], (t.dim.x + 1) + rows.rw[ln].utf);
}
}
lnMove(i + 1, 0);
@ -354,9 +365,9 @@ void drawBar (char *s)
for (i = len; i <= t.dim.x + t.pad; i++)
mvaddch(t.dim.y, i, ' ');
static char m[40];
sprintf(m, "x: %d y: %d Zoom: %c", t.cur.x, t.cur.y, whatsThat());
mvaddstr(t.dim.y, t.dim.x + t.pad - strlen(m), m);
static char right_message[40];
sprintf(right_message, "x: %d y: %d Zoom: %c", t.cur.x, t.cur.y, whatsThat());
mvaddstr(t.dim.y, t.dim.x + t.pad - strlen(right_message), right_message);
/* Return to normal contrast mode */
attroff(COLOR_PAIR(2));

Binary file not shown.
Loading…
Cancel
Save