Bugfixing

This commit is contained in:
Jakub Melka
2020-01-05 18:13:43 +01:00
parent 4cfd05995e
commit 7f55d11916
4 changed files with 56 additions and 6 deletions

View File

@@ -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();

View File

@@ -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