mirror of https://github.com/JakubMelka/PDF4QT.git
Bugfixing
This commit is contained in:
parent
4cfd05995e
commit
7f55d11916
|
@ -651,10 +651,14 @@ QDataStream& operator>>(QDataStream& stream, PDFTextLayoutSettings& settings)
|
|||
return stream;
|
||||
}
|
||||
|
||||
PDFTextSelection::PDFTextSelection(PDFTextSelectionItems&& items) :
|
||||
m_items(qMove(items))
|
||||
void PDFTextSelection::addItems(const PDFTextSelectionItems& items, QColor color)
|
||||
{
|
||||
std::transform(items.cbegin(), items.cend(), std::back_inserter(m_items), [color] (const auto& item) { return PDFTextSelectionColoredItem(item.first, item.second, color); });
|
||||
}
|
||||
|
||||
void PDFTextSelection::build()
|
||||
{
|
||||
std::sort(m_items.begin(), m_items.end());
|
||||
}
|
||||
|
||||
PDFFindResults PDFTextFlow::find(const QString& text, Qt::CaseSensitivity caseSensitivity) const
|
||||
|
@ -752,7 +756,7 @@ PDFTextFlows PDFTextFlow::createTextFlows(const PDFTextLayout& layout, FlowFlags
|
|||
{
|
||||
// Jakub Melka: try to guess space between letters
|
||||
const TextCharacter& previousCharacter = characters[i - 1];
|
||||
if (!previousCharacter.character.isSpace() && QLineF(previousCharacter.position, currentCharacter.position).length() > previousCharacter.advance * 1.1)
|
||||
if (!previousCharacter.character.isSpace() && QLineF(previousCharacter.position, currentCharacter.position).length() > previousCharacter.advance * 1.2)
|
||||
{
|
||||
currentFlow.m_text += QChar(' ');
|
||||
currentFlow.m_characterPointers.emplace_back();
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
|
||||
#include "pdfglobal.h"
|
||||
|
||||
#include <QColor>
|
||||
#include <QDataStream>
|
||||
#include <QPainterPath>
|
||||
|
||||
|
@ -178,14 +179,43 @@ struct PDFCharacterPointer
|
|||
using PDFTextSelectionItem = std::pair<PDFCharacterPointer, PDFCharacterPointer>;
|
||||
using PDFTextSelectionItems = std::vector<PDFTextSelectionItem>;
|
||||
|
||||
/// Text selection, can be used across multiple pages.
|
||||
struct PDFTextSelectionColoredItem
|
||||
{
|
||||
explicit inline PDFTextSelectionColoredItem() = default;
|
||||
explicit inline PDFTextSelectionColoredItem(PDFCharacterPointer start, PDFCharacterPointer end, QColor color) :
|
||||
start(start),
|
||||
end(end),
|
||||
color(color)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
inline bool operator<(const PDFTextSelectionColoredItem& other) const { return std::tie(start, end) < std::tie(other.start, other.end); }
|
||||
|
||||
PDFCharacterPointer start;
|
||||
PDFCharacterPointer end;
|
||||
QColor color;
|
||||
};
|
||||
using PDFTextSelectionColoredItems = std::vector<PDFTextSelectionColoredItem>;
|
||||
|
||||
/// Text selection, can be used across multiple pages. Also defines color
|
||||
/// for each text selection.
|
||||
class PDFTextSelection
|
||||
{
|
||||
public:
|
||||
explicit PDFTextSelection(PDFTextSelectionItems&& items);
|
||||
explicit PDFTextSelection() = default;
|
||||
|
||||
/// Adds text selection items to selection
|
||||
/// \param items Items
|
||||
/// \param color Color for items (must include alpha channel)
|
||||
void addItems(const PDFTextSelectionItems& items, QColor color);
|
||||
|
||||
/// Builds text selection, so it is prepared for rendering. Text selection,
|
||||
/// which is not build, can't be used for rendering.
|
||||
void build();
|
||||
|
||||
private:
|
||||
PDFTextSelectionItems m_items;
|
||||
PDFTextSelectionColoredItems m_items;
|
||||
};
|
||||
|
||||
struct PDFFindResult
|
||||
|
|
|
@ -39,6 +39,7 @@ PDFAdvancedFindWidget::PDFAdvancedFindWidget(pdf::PDFDrawWidgetProxy* proxy, QWi
|
|||
|
||||
connect(ui->regularExpressionsCheckbox, &QCheckBox::clicked, this, &PDFAdvancedFindWidget::updateUI);
|
||||
connect(m_proxy, &pdf::PDFDrawWidgetProxy::textLayoutChanged, this, &PDFAdvancedFindWidget::performSearch);
|
||||
connect(ui->resultsTableWidget, &QTableWidget::cellDoubleClicked, this, &PDFAdvancedFindWidget::onResultItemDoubleClicked);
|
||||
updateUI();
|
||||
}
|
||||
|
||||
|
@ -52,7 +53,9 @@ void PDFAdvancedFindWidget::setDocument(const pdf::PDFDocument* document)
|
|||
if (m_document != document)
|
||||
{
|
||||
m_document = document;
|
||||
m_findResults.clear();
|
||||
updateUI();
|
||||
updateResultsUI();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -102,6 +105,18 @@ void PDFAdvancedFindWidget::on_searchButton_clicked()
|
|||
}
|
||||
}
|
||||
|
||||
void PDFAdvancedFindWidget::onResultItemDoubleClicked(int row, int column)
|
||||
{
|
||||
Q_UNUSED(column);
|
||||
|
||||
if (row >= 0 && row < m_findResults.size())
|
||||
{
|
||||
const pdf::PDFFindResult& findResult = m_findResults[row];
|
||||
const pdf::PDFInteger pageIndex = findResult.textSelectionItems.front().first.pageIndex;
|
||||
m_proxy->goToPage(pageIndex);
|
||||
}
|
||||
}
|
||||
|
||||
void PDFAdvancedFindWidget::updateUI()
|
||||
{
|
||||
const bool enableUI = m_document && m_document->getCatalog()->getPageCount() > 0;
|
||||
|
|
|
@ -49,6 +49,7 @@ public:
|
|||
|
||||
private slots:
|
||||
void on_searchButton_clicked();
|
||||
void onResultItemDoubleClicked(int row, int column);
|
||||
|
||||
private:
|
||||
void updateUI();
|
||||
|
|
Loading…
Reference in New Issue