1 #ifndef TEXTITEM_HPP 2 #define TEXTITEM_HPP 3 /* 4 Copyright © 2008-13 Qtrac Ltd. All rights reserved. 5 This program or module is free software: you can redistribute it 6 and/or modify it under the terms of the GNU General Public License 7 as published by the Free Software Foundation, either version 2 of 8 the License, or (at your option) any later version. This program is 9 distributed in the hope that it will be useful, but WITHOUT ANY 10 WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 for more details. 13 */ 14 15 #include "generic.hpp" 16 17 #include <QList> 18 #include <QPainterPath> 19 #include <QRectF> 20 #include <QString> 21 22 23 struct TextItem 24 { TextItemTextItem25 TextItem(const QString &text, const QRectF &rect) 26 : text(text), rect(rect) {} 27 toRectTextItem28 QRect toRect() const { return rect.toRect(); } 29 30 QString text; 31 QRectF rect; 32 }; 33 34 35 class TextItems 36 { 37 public: at(const int index) const38 TextItem at(const int index) const { return items.at(index); } append(const TextItem & item)39 void append(const TextItem &item) { items << item; } count() const40 int count() const { return items.count(); } 41 QStringList texts() const; 42 QList<QRectF> rects() const; 43 void columnZoneYxOrder(const int Width, const int ToleranceR, 44 const int ToleranceY, const int Columns); 45 void columnYxOrder(const int Width, const int ToleranceY, 46 const int Columns); 47 const QList<QPainterPath> generateZones(const int Width, 48 const int ToleranceR, const int ToleranceY, 49 const int Columns) const; 50 51 void debug(const int page, const int ToleranceY, 52 const bool ComparingWords=true, const bool Yx=false); 53 54 private: 55 QList<TextItem> items; 56 }; 57 58 59 inline int normalizedY(const int y, const int ToleranceY); 60 61 const TextItems getWords(const TextBoxList &list); 62 const TextItems getCharacters(const TextBoxList &list); 63 64 #endif // TEXTITEM_HPP 65