2007-03-08 04:03:40 +08:00
|
|
|
/**********************************************************************
|
|
|
|
* File: callcpp.cpp
|
|
|
|
* Description: extern C interface calling C++ from C.
|
|
|
|
* Author: Ray Smith
|
|
|
|
* Created: Sun Feb 04 20:39:23 MST 1996
|
|
|
|
*
|
|
|
|
* (C) Copyright 1996, Hewlett-Packard Co.
|
|
|
|
** Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
** you may not use this file except in compliance with the License.
|
|
|
|
** You may obtain a copy of the License at
|
|
|
|
** http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
** Unless required by applicable law or agreed to in writing, software
|
|
|
|
** distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
** See the License for the specific language governing permissions and
|
|
|
|
** limitations under the License.
|
|
|
|
*
|
|
|
|
**********************************************************************/
|
|
|
|
|
2012-09-22 08:59:31 +08:00
|
|
|
// Include automatically generated configuration file if running autoconf.
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config_auto.h"
|
|
|
|
#endif
|
|
|
|
|
2010-11-24 02:34:14 +08:00
|
|
|
#include "errcode.h"
|
2007-03-08 04:03:40 +08:00
|
|
|
#ifdef __UNIX__
|
2010-11-24 02:34:14 +08:00
|
|
|
#include <assert.h>
|
2007-03-08 04:03:40 +08:00
|
|
|
#include <stdarg.h>
|
|
|
|
#endif
|
2010-11-24 02:34:14 +08:00
|
|
|
#include <time.h>
|
|
|
|
#include "memry.h"
|
|
|
|
#include "scrollview.h"
|
|
|
|
#include "params.h"
|
|
|
|
#include "callcpp.h"
|
|
|
|
#include "tprintf.h"
|
|
|
|
#include "host.h"
|
2007-07-18 09:15:07 +08:00
|
|
|
#include "unichar.h"
|
2007-03-08 04:03:40 +08:00
|
|
|
|
|
|
|
void
|
|
|
|
cprintf ( //Trace printf
|
|
|
|
const char *format, ... //special message
|
|
|
|
) {
|
|
|
|
va_list args; //variable args
|
|
|
|
char msg[1000];
|
|
|
|
|
|
|
|
va_start(args, format); //variable list
|
|
|
|
vsprintf(msg, format, args); //Format into msg
|
2007-07-18 09:15:07 +08:00
|
|
|
va_end(args);
|
2007-03-08 04:03:40 +08:00
|
|
|
|
|
|
|
tprintf ("%s", msg);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef GRAPHICS_DISABLED
|
2008-04-22 08:41:37 +08:00
|
|
|
ScrollView *c_create_window( /*create a window */
|
2007-03-08 04:03:40 +08:00
|
|
|
const char *name, /*name/title of window */
|
Use POSIX data types and macros (#878)
* api: Replace Tesseract data types by POSIX data types
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* ccmain: Replace Tesseract data types by POSIX data types
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* ccstruct: Replace Tesseract data types by POSIX data types
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* classify: Replace Tesseract data types by POSIX data types
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* cutil: Replace Tesseract data types by POSIX data types
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* dict: Replace Tesseract data types by POSIX data types
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* textord: Replace Tesseract data types by POSIX data types
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* training: Replace Tesseract data types by POSIX data types
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* wordrec: Replace Tesseract data types by POSIX data types
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* ccutil: Replace Tesseract data types by POSIX data types
Now all Tesseract data types which are no longer needed can be removed
from ccutil/host.h.
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* ccmain: Replace Tesseract's MIN_*INT, MAX_*INT* by POSIX *INT*_MIN, *INT*_MAX
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* ccstruct: Replace Tesseract's MIN_*INT, MAX_*INT* by POSIX *INT*_MIN, *INT*_MAX
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* classify: Replace Tesseract's MIN_*INT, MAX_*INT* by POSIX *INT*_MIN, *INT*_MAX
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* dict: Replace Tesseract's MIN_*INT, MAX_*INT* by POSIX *INT*_MIN, *INT*_MAX
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* lstm: Replace Tesseract's MIN_*INT, MAX_*INT* by POSIX *INT*_MIN, *INT*_MAX
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* textord: Replace Tesseract's MIN_*INT, MAX_*INT* by POSIX *INT*_MIN, *INT*_MAX
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* wordrec: Replace Tesseract's MIN_*INT, MAX_*INT* by POSIX *INT*_MIN, *INT*_MAX
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* ccutil: Replace Tesseract's MIN_*INT, MAX_*INT* by POSIX *INT*_MIN, *INT*_MAX
Remove the macros which are now unused from ccutil/host.h.
Remove also the obsolete history comments.
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* Fix build error caused by ambiguous ClipToRange
Error message vom Appveyor CI:
C:\projects\tesseract\ccstruct\coutln.cpp(818): error C2672: 'ClipToRange': no matching overloaded function found [C:\projects\tesseract\build\libtesseract.vcxproj]
C:\projects\tesseract\ccstruct\coutln.cpp(818): error C2782: 'T ClipToRange(const T &,const T &,const T &)': template parameter 'T' is ambiguous [C:\projects\tesseract\build\libtesseract.vcxproj]
c:\projects\tesseract\ccutil\helpers.h(122): note: see declaration of 'ClipToRange'
C:\projects\tesseract\ccstruct\coutln.cpp(818): note: could be 'char'
C:\projects\tesseract\ccstruct\coutln.cpp(818): note: or 'int'
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* unittest: Replace Tesseract's MAX_INT8 by POSIX INT8_MAX
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* arch: Replace Tesseract's MAX_INT8 by POSIX INT8_MAX
Signed-off-by: Stefan Weil <sw@weilnetz.de>
2018-03-14 04:36:30 +08:00
|
|
|
int16_t xpos, /*coords of window */
|
|
|
|
int16_t ypos, /*coords of window */
|
|
|
|
int16_t xsize, /*size of window */
|
|
|
|
int16_t ysize, /*size of window */
|
2007-03-08 04:03:40 +08:00
|
|
|
double xmin, /*scrolling limits */
|
|
|
|
double xmax, /*to stop users */
|
|
|
|
double ymin, /*getting lost in */
|
|
|
|
double ymax /*empty space */
|
|
|
|
) {
|
2008-02-01 08:36:18 +08:00
|
|
|
return new ScrollView(name, xpos, ypos, xsize, ysize, xmax - xmin, ymax - ymin, true);
|
2007-03-08 04:03:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void c_line_color_index( /*set color */
|
|
|
|
void *win,
|
|
|
|
C_COL index) {
|
2008-02-01 08:36:18 +08:00
|
|
|
// The colors are the same as the SV ones except that SV has COLOR:NONE --> offset of 1
|
|
|
|
ScrollView* window = (ScrollView*) win;
|
|
|
|
window->Pen((ScrollView::Color) (index + 1));
|
2007-03-08 04:03:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void c_move( /*move pen */
|
|
|
|
void *win,
|
|
|
|
double x,
|
|
|
|
double y) {
|
2008-02-01 08:36:18 +08:00
|
|
|
ScrollView* window = (ScrollView*) win;
|
|
|
|
window->SetCursor((int) x, (int) y);
|
2007-03-08 04:03:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void c_draw( /*move pen */
|
|
|
|
void *win,
|
|
|
|
double x,
|
|
|
|
double y) {
|
2008-02-01 08:36:18 +08:00
|
|
|
ScrollView* window = (ScrollView*) win;
|
|
|
|
window->DrawTo((int) x, (int) y);
|
2007-03-08 04:03:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void c_make_current( /*move pen */
|
|
|
|
void *win) {
|
2008-02-01 08:36:18 +08:00
|
|
|
ScrollView* window = (ScrollView*) win;
|
|
|
|
window->Update();
|
2007-03-08 04:03:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void c_clear_window( /*move pen */
|
|
|
|
void *win) {
|
2008-02-01 08:36:18 +08:00
|
|
|
ScrollView* window = (ScrollView*) win;
|
|
|
|
window->Clear();
|
2007-03-08 04:03:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-04-22 08:41:37 +08:00
|
|
|
char window_wait(ScrollView* win) {
|
2008-02-01 08:36:18 +08:00
|
|
|
SVEvent* ev;
|
2008-04-22 08:41:37 +08:00
|
|
|
// Wait till an input or click event (all others are thrown away)
|
2008-02-01 08:36:18 +08:00
|
|
|
char ret = '\0';
|
|
|
|
SVEventType ev_type = SVET_ANY;
|
|
|
|
do {
|
2008-04-22 08:41:37 +08:00
|
|
|
ev = win->AwaitEvent(SVET_ANY);
|
2008-02-01 08:36:18 +08:00
|
|
|
ev_type = ev->type;
|
2008-04-22 08:41:37 +08:00
|
|
|
if (ev_type == SVET_INPUT)
|
2008-02-01 08:36:18 +08:00
|
|
|
ret = ev->parameter[0];
|
|
|
|
delete ev;
|
|
|
|
} while (ev_type != SVET_INPUT && ev_type != SVET_CLICK);
|
|
|
|
return ret;
|
2007-03-08 04:03:40 +08:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2007-07-18 09:15:07 +08:00
|
|
|
void reverse32(void *ptr) {
|
2007-03-08 04:03:40 +08:00
|
|
|
char tmp;
|
|
|
|
char *cptr = (char *) ptr;
|
|
|
|
|
|
|
|
tmp = *cptr;
|
|
|
|
*cptr = *(cptr + 3);
|
|
|
|
*(cptr + 3) = tmp;
|
|
|
|
tmp = *(cptr + 1);
|
|
|
|
*(cptr + 1) = *(cptr + 2);
|
|
|
|
*(cptr + 2) = tmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-07-18 09:15:07 +08:00
|
|
|
void reverse16(void *ptr) {
|
2007-03-08 04:03:40 +08:00
|
|
|
char tmp;
|
|
|
|
char *cptr = (char *) ptr;
|
|
|
|
|
|
|
|
tmp = *cptr;
|
|
|
|
*cptr = *(cptr + 1);
|
|
|
|
*(cptr + 1) = tmp;
|
|
|
|
}
|