예제 #1
0
Bool32 CTB_GetRecRaster(const char *fname, int32_t id_rast, RecRaster *r)
{
    uchar raster[REC_MAX_RASTER_SIZE], w, h, data[CTB_DATA_SIZE];
    int32_t wb, ww, hh;
    Bool32 ret;
    CTB_handle hnd;

    if (!CTB_open(fname, &hnd, "w"))
        return FALSE;

    ret = CTB_read(&hnd, id_rast, raster, data);
    CTB_close(&hnd);

    if (ret) {
        w = data[1];
        h = data[2];
        ww = w;
        hh = h;
        r->lnRasterBufSize = REC_MAX_RASTER_SIZE;
        r->lnPixWidth = ww;
        r->lnPixHeight = hh;

        if (hnd.signums == (CTB_GRAY_SCALE | CTB_PLANE)) {
            memcpy(r->Raster, raster, ww * hh);
        }

        else {
            wb = (w + 7) / 8;
            memcpy(r->Raster, raster, wb * hh);
            CTB_align8_lines(r->Raster, r->lnPixWidth, r->lnPixHeight);
        }
    }

    return ret;
}
예제 #2
0
static int LoadCTB(char *name) {
	CTB_handle ctbhan;
	uchar CTBdata[CTB_DATA_SIZE];
	welet *wel, *twel;
	int num;
	int i;
	int16_t *pint16;
	uint32_t *pword32;

	// process CTB-file
	if (CTB_open(name, &ctbhan, "r") == FALSE) { // MessageBox(GetActiveWindow(),name,"Error open CTB-base",MB_OK);
		return -41;
	}

	// grey file ?
	if ((ctbhan.signums & CTB_GRAY) == 0) {
		CTB_close(&ctbhan);
		//	 MessageBox(GetActiveWindow(),name,"Not grey base",MB_OK);
		return -42;
	}

	if (CTB_read_global_data(&ctbhan, CTBdata) == 0 || memcmp(&CTBdata[1],
			ParolBase, 5) != 0) {
		CTB_close(&ctbhan);
		//	 MessageBox(GetActiveWindow(),name,"Not cluster CTB-base",MB_OK);
		return -43;
	}

	num = CTB_volume(&ctbhan);

	if ((wel = (welet *) malloc(num * sizeof(welet))) == NULL) {
		CTB_close(&ctbhan);
		return -1;
	}

	for (i = 0, twel = wel; i < num; i++, twel++) {
		if (GetCTBasWelet(&ctbhan, i, twel) == 0) {
			CTB_close(&ctbhan);
			return -2;
		}
	}
	CTB_close(&ctbhan);

	// now to static
	memset(&fonbase, 0, sizeof(FONBASE));
	pint16 = (int16_t *) (CTBdata + 6);
	pword32 = (uint32_t *) (CTBdata + 8);
	fonbase.start = wel;
	fonbase.inBase = num;
	fonbase.ace = NULL;
	fonbase.countFont = *pint16;
	// Информация о шрифтах в полях
	SetFields(fonbase.fontFields[0],pword32);
	SetFields(fonbase.fontFields[1],(pword32+2));
	SetFields(fonbase.fontFields[2],(pword32+4));
	SetFields(fonbase.fontFields[3],(pword32+6));

	return num;
}
예제 #3
0
int32_t CTB_copy(char *new_name, char *old_name)
{
    char *p;
    CTB_handle hi, ho;
    int16_t i, n;
    uchar dst[CTB_DATA_SIZE], buffer[256* 128 + 2 + CTB_DATA_SIZE ];
    ctb_err_code = CTB_ERR_NONE;
    p = ctb_last_punct(old_name);

    if (p)
        *p = '\0';

    p = ctb_last_punct(new_name);

    if (p)
        *p = '\0';

    if (!CTB_open(old_name, &hi, "w"))
        return 0;

    CTB_read_global_data(&hi, dst);
    CTB_files_init(new_name, dst, hi.width, hi.height, hi.dpb, hi.signums,
                   hi.attr_size);
    n = (int16_t) CTB_volume(&hi);

    if (!CTB_open(new_name, &ho, "w"))
        return 0;

    for (i = 0; i < n; i++) {
        switch (CTB_read(&hi, i, buffer, dst)) {
            case 1:
                CTB_write_mark(&ho, -1, buffer, dst, FALSE);
                break;
            case 2:
                CTB_write_mark(&ho, -1, buffer, dst, TRUE);
                break;
            default:
                break;
        }
    }

    CTB_close(&ho);
    CTB_close(&hi);
    return n;
}
예제 #4
0
Bool32 rstr_open_cont(void)
{
#ifdef _USE_CTB_
    uchar   data[CTB_DATA_SIZE]= {0};
    rstr_close_cont();
    data[0]=38;
    if( !CTB_create(local_ctb_name,data) || !CTB_open(local_ctb_name,&this_ctb,"w") )
    {
        mkdir("TMP", S_IRWXU);
        if( !CTB_create(local_ctb_name,data) || !CTB_open(local_ctb_name,&this_ctb,"w") )
            return FALSE;
    }

    CTB_read_global_data(&this_ctb,data);

    datalen = data[0];
    return TRUE;
#else
    return FALSE;
#endif
}
예제 #5
0
int32_t CTB_AddRecRaster(const char *fname, RecRaster *r, uchar let)
{
    CTB_handle hnd;
    int32_t num;
    uchar raster[REC_MAX_RASTER_SIZE], data[CTB_DATA_SIZE] = { 0 };
    int32_t wb;
    Bool32 ret;

    if (!CTB_open(fname, &hnd, "w")) {
        if (1)
            CTB_create(fname, NULL);

        else
            CTB_create_gray(fname, NULL);

        if (!CTB_open(fname, &hnd, "w")) {
            return FALSE;
        }
    }

    data[1] = (uchar) r->lnPixWidth;
    data[2] = (uchar) r->lnPixHeight;
    data[3] = let;

    if (hnd.signums & (CTB_GRAY_SCALE | CTB_PLANE)) {
        wb = r->lnPixWidth;
        memcpy(raster, r->Raster, wb * r->lnPixHeight);
    }

    else {
        wb = ((r->lnPixWidth + 63) / 64) * 8;
        memcpy(raster, r->Raster, wb * r->lnPixHeight);
        CTB_align1_lines(raster, r->lnPixWidth, r->lnPixHeight);
    }

    ret = CTB_write(&hnd, -1, raster, data);
    num = hnd.num;
    CTB_close(&hnd);
    return ret ? num : -1;
}
예제 #6
0
// save base for spell learning
Bool32 rstr_open_cont1(void)
{
#ifdef _USE_CTB_
    uchar   data[CTB_DATA_SIZE]= {0};
    static  int init=1;
    if( init )
    {
        init=0;
        data[0]=38+12*3+1;
        if( !CTB_create("d:\\vers",data) || !CTB_open("d:\\vers",&this_ctb1,"w") )
            return FALSE;
        CTB_read_global_data(&this_ctb1,data);
        datalen1 = data[0];
    }
    return TRUE;
#else
    return FALSE;
#endif
}
예제 #7
0
int32_t CTB_compress(const char *filename)
{
    char *p, tmp_file[MAXPATH], file_name[MAXPATH];
    CTB_handle hi, ho;
    int32_t i, n, compress;
    uchar dst[CTB_DATA_SIZE], buffer[256* 128 + 2 + CTB_DATA_SIZE ];
    p = ctb_last_punct(file_name);
    strcpy(file_name, filename);
    ctb_err_code = CTB_ERR_NONE;

    if (p)
        *p = '\0';

    STRCPY(tmp_file, file_name);
    p = STRRCHR(tmp_file, '\\');

    if (p) {
        *(p + 1) = '\0';
        STRCAT(tmp_file, "$$$$$$$$");
    }

    else
        STRCPY(tmp_file, "$$$$$$$$");

    if (!CTB_open(file_name, &hi, "w"))
        return FALSE;

    CTB_read_global_data(&hi, dst);
    CTB_files_init(tmp_file, dst, hi.width, hi.height, hi.dpb, hi.signums,
                   hi.attr_size);
    n = CTB_volume(&hi);
    compress = hi.need_compress;

    if (compress) {
        if (!CTB_open(tmp_file, &ho, "w"))
            return 0;

        for (i = 0; i < n; i++) {
            switch (CTB_read(&hi, i, buffer, dst)) {
                case 1:
                    CTB_write_mark(&ho, -1, buffer, dst, FALSE);
                    break;
                case 2:
                    CTB_write_mark(&ho, -1, buffer, dst, TRUE);
                    break;
                default:
                    break;
            }
        }

        ho.need_compress = 0;
        CTB_close(&ho);
    }

    hi.need_compress = 0;
    CTB_close(&hi);

    if (!compress) { // delete tmp file //
        STRCAT(tmp_file, ".CTB");
        UNLINK(tmp_file);
        *ctb_last_punct(tmp_file) = 0;
        STRCAT(tmp_file, ".IND");
        UNLINK(tmp_file);
        return 0;
    }

    STRCAT(file_name, ".CTB");
    STRCAT(tmp_file, ".CTB");
    UNLINK(file_name);
    RENAME(tmp_file, file_name);
    *ctb_last_punct(tmp_file) = 0;
    *ctb_last_punct(file_name) = 0;
    STRCAT(file_name, ".IND");
    STRCAT(tmp_file, ".IND");
    UNLINK(file_name);
    RENAME(tmp_file, file_name);
    return n;
}