Tesseract  3.02
tesseract-ocr/cutil/callcpp.cpp
Go to the documentation of this file.
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 "mfcpch.h"
00021 #include          "errcode.h"
00022 #ifdef __UNIX__
00023 #include          <assert.h>
00024 #include <stdarg.h>
00025 #endif
00026 #include          <time.h>
00027 #include          "memry.h"
00028 #include          "scrollview.h"
00029 #include          "params.h"
00030 #include          "callcpp.h"
00031 #include          "tprintf.h"
00032 #include          "host.h"
00033 #include "unichar.h"
00034 
00035 // Include automatically generated configuration file if running autoconf.
00036 #ifdef HAVE_CONFIG_H
00037 #include "config_auto.h"
00038 #endif
00039 
00040 void
00041 cprintf (                        //Trace printf
00042 const char *format, ...          //special message
00043 ) {
00044   va_list args;                  //variable args
00045   char msg[1000];
00046 
00047   va_start(args, format);  //variable list
00048   vsprintf(msg, format, args);  //Format into msg
00049   va_end(args);
00050 
00051   tprintf ("%s", msg);
00052 }
00053 
00054 
00055 #ifndef GRAPHICS_DISABLED
00056 ScrollView *c_create_window(                   /*create a window */
00057                       const char *name,  /*name/title of window */
00058                       inT16 xpos,        /*coords of window */
00059                       inT16 ypos,        /*coords of window */
00060                       inT16 xsize,       /*size of window */
00061                       inT16 ysize,       /*size of window */
00062                       double xmin,       /*scrolling limits */
00063                       double xmax,       /*to stop users */
00064                       double ymin,       /*getting lost in */
00065                       double ymax        /*empty space */
00066                      ) {
00067    return new ScrollView(name, xpos, ypos, xsize, ysize, xmax - xmin, ymax - ymin, true);
00068 }
00069 
00070 
00071 void c_line_color_index(  /*set color */
00072                         void *win,
00073                         C_COL index) {
00074  // The colors are the same as the SV ones except that SV has COLOR:NONE --> offset of 1
00075  ScrollView* window = (ScrollView*) win;
00076  window->Pen((ScrollView::Color) (index + 1));
00077 }
00078 
00079 
00080 void c_move(  /*move pen */
00081             void *win,
00082             double x,
00083             double y) {
00084   ScrollView* window = (ScrollView*) win;
00085   window->SetCursor((int) x, (int) y);
00086 }
00087 
00088 
00089 void c_draw(  /*move pen */
00090             void *win,
00091             double x,
00092             double y) {
00093   ScrollView* window = (ScrollView*) win;
00094   window->DrawTo((int) x, (int) y);
00095 }
00096 
00097 
00098 void c_make_current(  /*move pen */
00099                     void *win) {
00100   ScrollView* window = (ScrollView*) win;
00101   window->Update();
00102 }
00103 
00104 
00105 void c_clear_window(  /*move pen */
00106                     void *win) {
00107   ScrollView* window = (ScrollView*) win;
00108   window->Clear();
00109 }
00110 
00111 
00112 char window_wait(ScrollView* win) {
00113   SVEvent* ev;
00114   // Wait till an input or click event (all others are thrown away)
00115   char ret = '\0';
00116   SVEventType ev_type = SVET_ANY;
00117   do {
00118     ev = win->AwaitEvent(SVET_ANY);
00119     ev_type = ev->type;
00120     if (ev_type == SVET_INPUT)
00121       ret = ev->parameter[0];
00122     delete ev;
00123   } while (ev_type != SVET_INPUT && ev_type != SVET_CLICK);
00124   return ret;
00125 }
00126 #endif
00127 
00128 void reverse32(void *ptr) {
00129   char tmp;
00130   char *cptr = (char *) ptr;
00131 
00132   tmp = *cptr;
00133   *cptr = *(cptr + 3);
00134   *(cptr + 3) = tmp;
00135   tmp = *(cptr + 1);
00136   *(cptr + 1) = *(cptr + 2);
00137   *(cptr + 2) = tmp;
00138 }
00139 
00140 
00141 void reverse16(void *ptr) {
00142   char tmp;
00143   char *cptr = (char *) ptr;
00144 
00145   tmp = *cptr;
00146   *cptr = *(cptr + 1);
00147   *(cptr + 1) = tmp;
00148 }