tesseract  4.0.0-1-g2a2b
callcpp.cpp
Go to the documentation of this file.
1 /**********************************************************************
2  * File: callcpp.cpp
3  * Description: extern C interface calling C++ from C.
4  * Author: Ray Smith
5  * Created: Sun Feb 04 20:39:23 MST 1996
6  *
7  * (C) Copyright 1996, Hewlett-Packard Co.
8  ** Licensed under the Apache License, Version 2.0 (the "License");
9  ** you may not use this file except in compliance with the License.
10  ** You may obtain a copy of the License at
11  ** http://www.apache.org/licenses/LICENSE-2.0
12  ** Unless required by applicable law or agreed to in writing, software
13  ** distributed under the License is distributed on an "AS IS" BASIS,
14  ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  ** See the License for the specific language governing permissions and
16  ** limitations under the License.
17  *
18  **********************************************************************/
19 
20 // Include automatically generated configuration file if running autoconf.
21 #ifdef HAVE_CONFIG_H
22 #include "config_auto.h"
23 #endif
24 
25 #include "callcpp.h"
26 #include <cstdarg> // for va_end, va_list, va_start
27 #include <cstdio> // for vsprintf
28 #include <memory> // for unique_ptr
29 #include "scrollview.h" // for ScrollView, SVEvent, SVET_ANY, SVET_INPUT
30 #include "tprintf.h" // for tprintf
31 
32 void
33 cprintf ( //Trace printf
34 const char *format, ... //special message
35 ) {
36  va_list args; //variable args
37  char msg[1000];
38 
39  va_start(args, format); //variable list
40  vsprintf(msg, format, args); //Format into msg
41  va_end(args);
42 
43  tprintf ("%s", msg);
44 }
45 
46 
47 #ifndef GRAPHICS_DISABLED
48 ScrollView *c_create_window( /*create a window */
49  const char *name, /*name/title of window */
50  int16_t xpos, /*coords of window */
51  int16_t ypos, /*coords of window */
52  int16_t xsize, /*size of window */
53  int16_t ysize, /*size of window */
54  double xmin, /*scrolling limits */
55  double xmax, /*to stop users */
56  double ymin, /*getting lost in */
57  double ymax /*empty space */
58  ) {
59  return new ScrollView(name, xpos, ypos, xsize, ysize, xmax - xmin, ymax - ymin, true);
60 }
61 
62 
63 void c_line_color_index( /*set color */
64  void *win,
65  C_COL index) {
66  // The colors are the same as the SV ones except that SV has COLOR:NONE --> offset of 1
67  ScrollView* window = (ScrollView*) win;
68  window->Pen((ScrollView::Color) (index + 1));
69 }
70 
71 
72 void c_move( /*move pen */
73  void *win,
74  double x,
75  double y) {
76  ScrollView* window = (ScrollView*) win;
77  window->SetCursor((int) x, (int) y);
78 }
79 
80 
81 void c_draw( /*move pen */
82  void *win,
83  double x,
84  double y) {
85  ScrollView* window = (ScrollView*) win;
86  window->DrawTo((int) x, (int) y);
87 }
88 
89 
90 void c_make_current( /*move pen */
91  void *win) {
92  ScrollView* window = (ScrollView*) win;
93  window->Update();
94 }
95 
96 
97 void c_clear_window( /*move pen */
98  void *win) {
99  ScrollView* window = (ScrollView*) win;
100  window->Clear();
101 }
102 
103 
105  // Wait till an input or click event (all others are thrown away)
106  char ret = '\0';
107  SVEventType ev_type = SVET_ANY;
108  do {
109  std::unique_ptr<SVEvent> ev(win->AwaitEvent(SVET_ANY));
110  ev_type = ev->type;
111  if (ev_type == SVET_INPUT)
112  ret = ev->parameter[0];
113  } while (ev_type != SVET_INPUT && ev_type != SVET_CLICK);
114  return ret;
115 }
116 #endif
117 
118 void reverse32(void *ptr) {
119  char tmp;
120  char *cptr = (char *) ptr;
121 
122  tmp = *cptr;
123  *cptr = *(cptr + 3);
124  *(cptr + 3) = tmp;
125  tmp = *(cptr + 1);
126  *(cptr + 1) = *(cptr + 2);
127  *(cptr + 2) = tmp;
128 }
129 
130 
131 void reverse16(void *ptr) {
132  char tmp;
133  char *cptr = (char *) ptr;
134 
135  tmp = *cptr;
136  *cptr = *(cptr + 1);
137  *(cptr + 1) = tmp;
138 }
void DrawTo(int x, int y)
Definition: scrollview.cpp:527
void cprintf(const char *format,...)
Definition: callcpp.cpp:33
void c_draw(void *win, double x, double y)
Definition: callcpp.cpp:81
C_COL
Definition: callcpp.h:29
SVEventType
Definition: scrollview.h:45
void SetCursor(int x, int y)
Definition: scrollview.cpp:521
void c_clear_window(void *win)
Definition: callcpp.cpp:97
static void Update()
Definition: scrollview.cpp:711
SVEvent * AwaitEvent(SVEventType type)
Definition: scrollview.cpp:445
void reverse32(void *ptr)
Definition: callcpp.cpp:118
void c_move(void *win, double x, double y)
Definition: callcpp.cpp:72
DLLSYM void tprintf(const char *format,...)
Definition: tprintf.cpp:37
void Clear()
Definition: scrollview.cpp:591
char window_wait(ScrollView *win)
Definition: callcpp.cpp:104
void c_make_current(void *win)
Definition: callcpp.cpp:90
void Pen(Color color)
Definition: scrollview.cpp:722
ScrollView * c_create_window(const char *name, int16_t xpos, int16_t ypos, int16_t xsize, int16_t ysize, double xmin, double xmax, double ymin, double ymax)
Definition: callcpp.cpp:48
void c_line_color_index(void *win, C_COL index)
Definition: callcpp.cpp:63
void reverse16(void *ptr)
Definition: callcpp.cpp:131