tesseract
3.03
|
00001 /********************************************************************** 00002 * File: callcpp.cpp 00003 * Description: extern C interface calling C++ from C. 00004 * Author: Ray Smith 00005 * Created: Sun Feb 04 20:39:23 MST 1996 00006 * 00007 * (C) Copyright 1996, Hewlett-Packard Co. 00008 ** Licensed under the Apache License, Version 2.0 (the "License"); 00009 ** you may not use this file except in compliance with the License. 00010 ** You may obtain a copy of the License at 00011 ** http://www.apache.org/licenses/LICENSE-2.0 00012 ** Unless required by applicable law or agreed to in writing, software 00013 ** distributed under the License is distributed on an "AS IS" BASIS, 00014 ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00015 ** See the License for the specific language governing permissions and 00016 ** limitations under the License. 00017 * 00018 **********************************************************************/ 00019 00020 // Include automatically generated configuration file if running autoconf. 00021 #ifdef HAVE_CONFIG_H 00022 #include "config_auto.h" 00023 #endif 00024 00025 #include "errcode.h" 00026 #ifdef __UNIX__ 00027 #include <assert.h> 00028 #include <stdarg.h> 00029 #endif 00030 #include <time.h> 00031 #include "memry.h" 00032 #include "scrollview.h" 00033 #include "params.h" 00034 #include "callcpp.h" 00035 #include "tprintf.h" 00036 #include "host.h" 00037 #include "unichar.h" 00038 00039 void 00040 cprintf ( //Trace printf 00041 const char *format, ... //special message 00042 ) { 00043 va_list args; //variable args 00044 char msg[1000]; 00045 00046 va_start(args, format); //variable list 00047 vsprintf(msg, format, args); //Format into msg 00048 va_end(args); 00049 00050 tprintf ("%s", msg); 00051 } 00052 00053 00054 #ifndef GRAPHICS_DISABLED 00055 ScrollView *c_create_window( /*create a window */ 00056 const char *name, /*name/title of window */ 00057 inT16 xpos, /*coords of window */ 00058 inT16 ypos, /*coords of window */ 00059 inT16 xsize, /*size of window */ 00060 inT16 ysize, /*size of window */ 00061 double xmin, /*scrolling limits */ 00062 double xmax, /*to stop users */ 00063 double ymin, /*getting lost in */ 00064 double ymax /*empty space */ 00065 ) { 00066 return new ScrollView(name, xpos, ypos, xsize, ysize, xmax - xmin, ymax - ymin, true); 00067 } 00068 00069 00070 void c_line_color_index( /*set color */ 00071 void *win, 00072 C_COL index) { 00073 // The colors are the same as the SV ones except that SV has COLOR:NONE --> offset of 1 00074 ScrollView* window = (ScrollView*) win; 00075 window->Pen((ScrollView::Color) (index + 1)); 00076 } 00077 00078 00079 void c_move( /*move pen */ 00080 void *win, 00081 double x, 00082 double y) { 00083 ScrollView* window = (ScrollView*) win; 00084 window->SetCursor((int) x, (int) y); 00085 } 00086 00087 00088 void c_draw( /*move pen */ 00089 void *win, 00090 double x, 00091 double y) { 00092 ScrollView* window = (ScrollView*) win; 00093 window->DrawTo((int) x, (int) y); 00094 } 00095 00096 00097 void c_make_current( /*move pen */ 00098 void *win) { 00099 ScrollView* window = (ScrollView*) win; 00100 window->Update(); 00101 } 00102 00103 00104 void c_clear_window( /*move pen */ 00105 void *win) { 00106 ScrollView* window = (ScrollView*) win; 00107 window->Clear(); 00108 } 00109 00110 00111 char window_wait(ScrollView* win) { 00112 SVEvent* ev; 00113 // Wait till an input or click event (all others are thrown away) 00114 char ret = '\0'; 00115 SVEventType ev_type = SVET_ANY; 00116 do { 00117 ev = win->AwaitEvent(SVET_ANY); 00118 ev_type = ev->type; 00119 if (ev_type == SVET_INPUT) 00120 ret = ev->parameter[0]; 00121 delete ev; 00122 } while (ev_type != SVET_INPUT && ev_type != SVET_CLICK); 00123 return ret; 00124 } 00125 #endif 00126 00127 void reverse32(void *ptr) { 00128 char tmp; 00129 char *cptr = (char *) ptr; 00130 00131 tmp = *cptr; 00132 *cptr = *(cptr + 3); 00133 *(cptr + 3) = tmp; 00134 tmp = *(cptr + 1); 00135 *(cptr + 1) = *(cptr + 2); 00136 *(cptr + 2) = tmp; 00137 } 00138 00139 00140 void reverse16(void *ptr) { 00141 char tmp; 00142 char *cptr = (char *) ptr; 00143 00144 tmp = *cptr; 00145 *cptr = *(cptr + 1); 00146 *(cptr + 1) = tmp; 00147 }