Skip to content

Commit 51a2c2e

Browse files
committed
Format code with clang-format
Signed-off-by: Stefan Weil <[email protected]>
1 parent 95ea778 commit 51a2c2e

File tree

2 files changed

+166
-157
lines changed

2 files changed

+166
-157
lines changed

src/api/renderer.h

+123-114
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
// To avoid collision with other typenames include the ABSOLUTE MINIMUM
2222
// complexity of includes here. Use forward declarations wherever possible
2323
// and hide includes of complex types in baseapi.cpp.
24-
#include <string> // for std::string
24+
#include <string> // for std::string
2525
#include "genericvector.h"
2626
#include "platform.h"
2727

@@ -45,107 +45,116 @@ class TessBaseAPI;
4545
* in addition to the heuristics for producing it.
4646
*/
4747
class TESS_API TessResultRenderer {
48-
public:
49-
virtual ~TessResultRenderer();
50-
51-
// Takes ownership of pointer so must be new'd instance.
52-
// Renderers aren't ordered, but appends the sequences of next parameter
53-
// and existing next(). The renderers should be unique across both lists.
54-
void insert(TessResultRenderer* next);
55-
56-
// Returns the next renderer or nullptr.
57-
TessResultRenderer* next() { return next_; }
58-
59-
/**
60-
* Starts a new document with the given title.
61-
* This clears the contents of the output data.
62-
* Title should use UTF-8 encoding.
63-
*/
64-
bool BeginDocument(const char* title);
65-
66-
/**
67-
* Adds the recognized text from the source image to the current document.
68-
* Invalid if BeginDocument not yet called.
69-
*
70-
* Note that this API is a bit weird but is designed to fit into the
71-
* current TessBaseAPI implementation where the api has lots of state
72-
* information that we might want to add in.
73-
*/
74-
bool AddImage(TessBaseAPI* api);
75-
76-
/**
77-
* Finishes the document and finalizes the output data
78-
* Invalid if BeginDocument not yet called.
79-
*/
80-
bool EndDocument();
81-
82-
const char* file_extension() const { return file_extension_; }
83-
const char* title() const { return title_.c_str(); }
84-
85-
// Is everything fine? Otherwise something went wrong.
86-
bool happy() { return happy_; }
87-
88-
/**
89-
* Returns the index of the last image given to AddImage
90-
* (i.e. images are incremented whether the image succeeded or not)
91-
*
92-
* This is always defined. It means either the number of the
93-
* current image, the last image ended, or in the completed document
94-
* depending on when in the document lifecycle you are looking at it.
95-
* Will return -1 if a document was never started.
96-
*/
97-
int imagenum() const { return imagenum_; }
98-
99-
protected:
100-
/**
101-
* Called by concrete classes.
102-
*
103-
* outputbase is the name of the output file excluding
104-
* extension. For example, "/path/to/chocolate-chip-cookie-recipe"
105-
*
106-
* extension indicates the file extension to be used for output
107-
* files. For example "pdf" will produce a .pdf file, and "hocr"
108-
* will produce .hocr files.
109-
*/
110-
TessResultRenderer(const char *outputbase,
111-
const char* extension);
112-
113-
// Hook for specialized handling in BeginDocument()
114-
virtual bool BeginDocumentHandler();
115-
116-
// This must be overridden to render the OCR'd results
117-
virtual bool AddImageHandler(TessBaseAPI* api) = 0;
118-
119-
// Hook for specialized handling in EndDocument()
120-
virtual bool EndDocumentHandler();
121-
122-
// Renderers can call this to append '\0' terminated strings into
123-
// the output string returned by GetOutput.
124-
// This method will grow the output buffer if needed.
125-
void AppendString(const char* s);
126-
127-
// Renderers can call this to append binary byte sequences into
128-
// the output string returned by GetOutput. Note that s is not necessarily
129-
// '\0' terminated (and can contain '\0' within it).
130-
// This method will grow the output buffer if needed.
131-
void AppendData(const char* s, int len);
132-
133-
private:
134-
const char* file_extension_; // standard extension for generated output
135-
STRING title_; // title of document being renderered
136-
int imagenum_; // index of last image added
137-
138-
FILE* fout_; // output file pointer
139-
TessResultRenderer* next_; // Can link multiple renderers together
140-
bool happy_; // I get grumpy when the disk fills up, etc.
48+
public:
49+
virtual ~TessResultRenderer();
50+
51+
// Takes ownership of pointer so must be new'd instance.
52+
// Renderers aren't ordered, but appends the sequences of next parameter
53+
// and existing next(). The renderers should be unique across both lists.
54+
void insert(TessResultRenderer* next);
55+
56+
// Returns the next renderer or nullptr.
57+
TessResultRenderer* next() {
58+
return next_;
59+
}
60+
61+
/**
62+
* Starts a new document with the given title.
63+
* This clears the contents of the output data.
64+
* Title should use UTF-8 encoding.
65+
*/
66+
bool BeginDocument(const char* title);
67+
68+
/**
69+
* Adds the recognized text from the source image to the current document.
70+
* Invalid if BeginDocument not yet called.
71+
*
72+
* Note that this API is a bit weird but is designed to fit into the
73+
* current TessBaseAPI implementation where the api has lots of state
74+
* information that we might want to add in.
75+
*/
76+
bool AddImage(TessBaseAPI* api);
77+
78+
/**
79+
* Finishes the document and finalizes the output data
80+
* Invalid if BeginDocument not yet called.
81+
*/
82+
bool EndDocument();
83+
84+
const char* file_extension() const {
85+
return file_extension_;
86+
}
87+
const char* title() const {
88+
return title_.c_str();
89+
}
90+
91+
// Is everything fine? Otherwise something went wrong.
92+
bool happy() {
93+
return happy_;
94+
}
95+
96+
/**
97+
* Returns the index of the last image given to AddImage
98+
* (i.e. images are incremented whether the image succeeded or not)
99+
*
100+
* This is always defined. It means either the number of the
101+
* current image, the last image ended, or in the completed document
102+
* depending on when in the document lifecycle you are looking at it.
103+
* Will return -1 if a document was never started.
104+
*/
105+
int imagenum() const {
106+
return imagenum_;
107+
}
108+
109+
protected:
110+
/**
111+
* Called by concrete classes.
112+
*
113+
* outputbase is the name of the output file excluding
114+
* extension. For example, "/path/to/chocolate-chip-cookie-recipe"
115+
*
116+
* extension indicates the file extension to be used for output
117+
* files. For example "pdf" will produce a .pdf file, and "hocr"
118+
* will produce .hocr files.
119+
*/
120+
TessResultRenderer(const char* outputbase, const char* extension);
121+
122+
// Hook for specialized handling in BeginDocument()
123+
virtual bool BeginDocumentHandler();
124+
125+
// This must be overridden to render the OCR'd results
126+
virtual bool AddImageHandler(TessBaseAPI* api) = 0;
127+
128+
// Hook for specialized handling in EndDocument()
129+
virtual bool EndDocumentHandler();
130+
131+
// Renderers can call this to append '\0' terminated strings into
132+
// the output string returned by GetOutput.
133+
// This method will grow the output buffer if needed.
134+
void AppendString(const char* s);
135+
136+
// Renderers can call this to append binary byte sequences into
137+
// the output string returned by GetOutput. Note that s is not necessarily
138+
// '\0' terminated (and can contain '\0' within it).
139+
// This method will grow the output buffer if needed.
140+
void AppendData(const char* s, int len);
141+
142+
private:
143+
const char* file_extension_; // standard extension for generated output
144+
STRING title_; // title of document being renderered
145+
int imagenum_; // index of last image added
146+
147+
FILE* fout_; // output file pointer
148+
TessResultRenderer* next_; // Can link multiple renderers together
149+
bool happy_; // I get grumpy when the disk fills up, etc.
141150
};
142151

143152
/**
144153
* Renders tesseract output into a plain UTF-8 text string
145154
*/
146155
class TESS_API TessTextRenderer : public TessResultRenderer {
147156
public:
148-
explicit TessTextRenderer(const char *outputbase);
157+
explicit TessTextRenderer(const char* outputbase);
149158

150159
protected:
151160
bool AddImageHandler(TessBaseAPI* api) override;
@@ -156,8 +165,8 @@ class TESS_API TessTextRenderer : public TessResultRenderer {
156165
*/
157166
class TESS_API TessHOcrRenderer : public TessResultRenderer {
158167
public:
159-
explicit TessHOcrRenderer(const char *outputbase, bool font_info);
160-
explicit TessHOcrRenderer(const char *outputbase);
168+
explicit TessHOcrRenderer(const char* outputbase, bool font_info);
169+
explicit TessHOcrRenderer(const char* outputbase);
161170

162171
protected:
163172
bool BeginDocumentHandler() override;
@@ -171,16 +180,15 @@ class TESS_API TessHOcrRenderer : public TessResultRenderer {
171180
/**
172181
* Renders tesseract output into an alto text string
173182
*/
174-
class TESS_API TessAltoRenderer : public TessResultRenderer {
175-
public:
176-
explicit TessAltoRenderer(const char *outputbase);
177-
178-
protected:
179-
bool BeginDocumentHandler() override;
180-
bool AddImageHandler(TessBaseAPI* api) override;
181-
bool EndDocumentHandler() override;
183+
class TESS_API TessAltoRenderer : public TessResultRenderer {
184+
public:
185+
explicit TessAltoRenderer(const char* outputbase);
182186

183-
};
187+
protected:
188+
bool BeginDocumentHandler() override;
189+
bool AddImageHandler(TessBaseAPI* api) override;
190+
bool EndDocumentHandler() override;
191+
};
184192

185193
/**
186194
* Renders Tesseract output into a TSV string
@@ -196,7 +204,7 @@ class TESS_API TessTsvRenderer : public TessResultRenderer {
196204
bool EndDocumentHandler() override;
197205

198206
private:
199-
bool font_info_; // whether to print font information
207+
bool font_info_; // whether to print font information
200208
};
201209

202210
/**
@@ -206,7 +214,8 @@ class TESS_API TessPDFRenderer : public TessResultRenderer {
206214
public:
207215
// datadir is the location of the TESSDATA. We need it because
208216
// we load a custom PDF font from this location.
209-
TessPDFRenderer(const char* outputbase, const char* datadir, bool textonly = false);
217+
TessPDFRenderer(const char* outputbase, const char* datadir,
218+
bool textonly = false);
210219

211220
protected:
212221
bool BeginDocumentHandler() override;
@@ -227,21 +236,21 @@ class TESS_API TessPDFRenderer : public TessResultRenderer {
227236
// Bookkeeping only. DIY = Do It Yourself.
228237
void AppendPDFObjectDIY(size_t objectsize);
229238
// Bookkeeping + emit data.
230-
void AppendPDFObject(const char *data);
239+
void AppendPDFObject(const char* data);
231240
// Create the /Contents object for an entire page.
232241
char* GetPDFTextObjects(TessBaseAPI* api, double width, double height);
233242
// Turn an image into a PDF object. Only transcode if we have to.
234243
static bool imageToPDFObj(Pix* pix, const char* filename, long int objnum,
235-
char** pdf_object, long int* pdf_object_size, const int jpg_quality);
244+
char** pdf_object, long int* pdf_object_size,
245+
int jpg_quality);
236246
};
237247

238-
239248
/**
240249
* Renders tesseract output into a plain UTF-8 text string
241250
*/
242251
class TESS_API TessUnlvRenderer : public TessResultRenderer {
243252
public:
244-
explicit TessUnlvRenderer(const char *outputbase);
253+
explicit TessUnlvRenderer(const char* outputbase);
245254

246255
protected:
247256
bool AddImageHandler(TessBaseAPI* api) override;
@@ -263,7 +272,7 @@ class TESS_API TessLSTMBoxRenderer : public TessResultRenderer {
263272
*/
264273
class TESS_API TessBoxTextRenderer : public TessResultRenderer {
265274
public:
266-
explicit TessBoxTextRenderer(const char *outputbase);
275+
explicit TessBoxTextRenderer(const char* outputbase);
267276

268277
protected:
269278
bool AddImageHandler(TessBaseAPI* api) override;
@@ -293,7 +302,7 @@ class TESS_API TessOsdRenderer : public TessResultRenderer {
293302
bool AddImageHandler(TessBaseAPI* api) override;
294303
};
295304

296-
#endif // ndef DISABLED_LEGACY_ENGINE
305+
#endif // ndef DISABLED_LEGACY_ENGINE
297306

298307
} // namespace tesseract.
299308

0 commit comments

Comments
 (0)