Skip to content

Commit

Permalink
RAII: *::GetHOCRText()
Browse files Browse the repository at this point in the history
  • Loading branch information
rfschtkt committed May 11, 2017
1 parent 986970d commit a1fff87
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
2 changes: 2 additions & 0 deletions api/baseapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1393,6 +1393,7 @@ static void AddBoxToTSV(const PageIterator* it, PageIteratorLevel level,
* Image name/input_file_ can be set by SetInputName before calling
* GetHOCRText
* STL removed from original patch submission and refactored by rays.
* Returned string must be freed with the delete [] operator.
*/
char* TessBaseAPI::GetHOCRText(int page_number) {
return GetHOCRText(NULL, page_number);
Expand All @@ -1405,6 +1406,7 @@ char* TessBaseAPI::GetHOCRText(int page_number) {
* Image name/input_file_ can be set by SetInputName before calling
* GetHOCRText
* STL removed from original patch submission and refactored by rays.
* Returned string must be freed with the delete [] operator.
*/
char* TessBaseAPI::GetHOCRText(ETEXT_DESC* monitor, int page_number) {
if (tesseract_ == NULL || (page_res_ == NULL && Recognize(monitor) < 0))
Expand Down
2 changes: 2 additions & 0 deletions api/baseapi.h
Original file line number Diff line number Diff line change
Expand Up @@ -591,13 +591,15 @@ class TESS_API TessBaseAPI {
* monitor can be used to
* cancel the recognition
* receive progress callbacks
* Returned string must be freed with the delete [] operator.
*/
char* GetHOCRText(ETEXT_DESC* monitor, int page_number);

/**
* Make a HTML-formatted string with hOCR markup from the internal
* data structures.
* page_number is 0-based but will appear in the output as 1-based.
* Returned string must be freed with the delete [] operator.
*/
char* GetHOCRText(int page_number);

Expand Down
5 changes: 2 additions & 3 deletions api/renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,11 +186,10 @@ bool TessHOcrRenderer::EndDocumentHandler() {
}

bool TessHOcrRenderer::AddImageHandler(TessBaseAPI* api) {
char* hocr = api->GetHOCRText(imagenum());
const std::unique_ptr<const char[]> hocr(api->GetHOCRText(imagenum()));
if (hocr == NULL) return false;

AppendString(hocr);
delete[] hocr;
AppendString(hocr.get());

return true;
}
Expand Down

0 comments on commit a1fff87

Please sign in to comment.