scantools
1.0.4
Graphics manipulation with a view towards scanned documents
|
Text box, as defined in an HOCR file. More...
#include <HOCRTextBox.h>
Public Member Functions | |
HOCRTextBox () | |
Constructs an empty text box. | |
bool | hasText () const |
Decide if the text box contains non-trivial text. More... | |
qreal | angle () const |
Text angle. More... | |
QXmlStreamAttributes | attributes () const |
Returns the attributes of the textBox. More... | |
QVector< qreal > | baselinePolynomial () const |
Base line as a polynomial. More... | |
QPoint | baselineReferencePoint () const |
Base line reference point. More... | |
QRect | boundingBox () const |
Bounding box. More... | |
QString | classType () const |
Class of this textBox. More... | |
int | confidence () const |
Confidence level. More... | |
QString | direction () const |
Text flow direction. More... | |
qreal | fontSize () const |
Font size. More... | |
QString | imageName () const |
Image associated with content of this text box. More... | |
QString | language () const |
Language of the content of this text box. More... | |
void | render (QPainter &painter) const |
Paint the contents of the text box to a painter. More... | |
QImage | toImage (const QFont &overrideFont, QImage::Format format=QImage::Format_Grayscale8) const |
Export this text box as an image. More... | |
QByteArray | toRawPDFContentStream (const QFont &font, resolution xRes, resolution yRes, length deltaX=length(), length deltaY=length()) const |
Return raw PDF text rendering commands. More... | |
QString | toText () const |
Export this text box as text. More... | |
qint64 | estimateFit (const QFont &font) const |
Estimate how well a given font fits the textbox. More... | |
QFont | suggestFont () const |
Suggest font. More... | |
QString | text () const |
Text content of the text box. More... | |
Text box, as defined in an HOCR file.
This class represents a box that may contain text and also other text boxes. Every text box has a bounding rectagle, text, a type, and a list of attributes. There are several helper functions to interpret the attribules.
Texboxes can be rendered on a QPainter. For users who wish to implement their own rendering routines, there are several helper functions that give suggestions for optimal rendering.
The methods of this class are reentrant, but not thread safe.
Definition at line 44 of file HOCRTextBox.h.
|
inline |
Text angle.
Definition at line 62 of file HOCRTextBox.h.
|
inline |
Returns the attributes of the textBox.
Definition at line 69 of file HOCRTextBox.h.
|
inline |
Base line as a polynomial.
Definition at line 77 of file HOCRTextBox.h.
|
inline |
Base line reference point.
Definition at line 85 of file HOCRTextBox.h.
|
inline |
Bounding box.
Definition at line 92 of file HOCRTextBox.h.
QString HOCRTextBox::classType | ( | ) | const |
Class of this textBox.
|
inline |
Confidence level.
Definition at line 108 of file HOCRTextBox.h.
|
inline |
Text flow direction.
Definition at line 116 of file HOCRTextBox.h.
qint64 HOCRTextBox::estimateFit | ( | const QFont & | font | ) | const |
Estimate how well a given font fits the textbox.
For this box, and for each subbox, this method computes the width of the text when rendered with the given font, and compares it to the width of the bounding box. The square of the difference is then computed, and the results are added up.
font | Font with which the text is to be rendered. The font's pixelSize will be changed in the process. |
|
inline |
Font size.
Definition at line 123 of file HOCRTextBox.h.
bool HOCRTextBox::hasText | ( | ) | const |
Decide if the text box contains non-trivial text.
|
inline |
Image associated with content of this text box.
Definition at line 131 of file HOCRTextBox.h.
|
inline |
Language of the content of this text box.
Definition at line 138 of file HOCRTextBox.h.
void HOCRTextBox::render | ( | QPainter & | painter | ) | const |
Paint the contents of the text box to a painter.
Paint the contents of the text box to a painter. Coordinates are in pixels. This is convenient if the contents of an HOCR file is drawn onto a bitmap that is meant to resemble the original scanned image as closely as possible. When writing to a PDF, for instance, resolution needs to be taken into account.
painter | QPainter to be used in the paint job |
QFont HOCRTextBox::suggestFont | ( | ) | const |
Suggest font.
Suggests a font for rendering this document. Three standard fonts ("Helvetica", "Times", "Courier") are tried, and the one is chose that fits the text box best.
|
inline |
Text content of the text box.
Definition at line 232 of file HOCRTextBox.h.
QImage HOCRTextBox::toImage | ( | const QFont & | overrideFont, |
QImage::Format | format = QImage::Format_Grayscale8 |
||
) | const |
Export this text box as an image.
Paint the contents of the text box to an image and returns the image. In case of an error, an empty image is returned.
overrideFont | If null, a standard font will be taken. If not null, then the specified font will be taken. |
format | Format of the returned QImage |
QByteArray HOCRTextBox::toRawPDFContentStream | ( | const QFont & | font, |
resolution | xRes, | ||
resolution | yRes, | ||
length | deltaX = length() , |
||
length | deltaY = length() |
||
) | const |
Return raw PDF text rendering commands.
This method converts the text box into a sequence of raw PDF text rendering command that are suitable for inclusion in a PDF file. The commands refer to the font /F1 and assume that this font exists. The text is encoded using the Windows-1252 encoding. Characters that cannot be represented in this encoding are discarded.
font | A reference to a QFont that should match the font "/F1" as closely as possible. The font is used to optimise placement of the text. |
xRes | Horizontal resolution. Used to transform the bitmap coordinates found in the HOCR file to physical sizes. Needs to be valid, or else the result is undefined. |
yRes | Vertical resolution. Used to transform the bitmap coordinates found in the HOCR file to physical sizes. Needs to be valid, or else the result is undefined. |
deltaX | Horizontal offest for text placement |
deltaY | Vertical offest for text placement |
QString HOCRTextBox::toText | ( | ) | const |
Export this text box as text.