mirror of
https://github.com/JakubMelka/PDF4QT.git
synced 2025-06-05 21:59:17 +02:00
Issue #24: Text selection and table selection bug
This commit is contained in:
@ -1567,46 +1567,15 @@ void PDFSelectTableTool::keyPressEvent(QWidget* widget, QKeyEvent* event)
|
||||
cell.row = rowIndex;
|
||||
cell.column = columnIndex;
|
||||
cell.rectangle = QRectF(left, top, width, height);
|
||||
|
||||
PDFTextSelection textSelection = m_textLayout.createTextSelection(m_pageIndex, cell.rectangle.topLeft(), cell.rectangle.bottomRight(), Qt::yellow, true);
|
||||
cell.text = m_textLayout.getTextFromSelection(textSelection, m_pageIndex).trimmed();
|
||||
cell.text = cell.text.remove(QChar('\n'));
|
||||
|
||||
tableCells.push_back(cell);
|
||||
}
|
||||
}
|
||||
|
||||
const PDFTextBlocks& textBlocks = m_textLayout.getTextBlocks();
|
||||
for (size_t i = 0; i < textBlocks.size(); ++i)
|
||||
{
|
||||
// Detect, if whole block can be in some text cell
|
||||
const PDFTextBlock& textBlock = textBlocks[i];
|
||||
QRectF textRect = textBlock.getBoundingBox().boundingRect();
|
||||
auto itBlockCell = std::find_if(tableCells.begin(), tableCells.end(), [textRect](const auto& cell) { return cell.rectangle.contains(textRect); });
|
||||
if (itBlockCell != tableCells.end())
|
||||
{
|
||||
// Jakub Melka: whole block is contained in the cell
|
||||
PDFTextSelection blockSelection = m_textLayout.selectBlock(i, m_pageIndex, QColor());
|
||||
QString text = m_textLayout.getTextFromSelection(blockSelection, m_pageIndex);
|
||||
TableCell& cell = *itBlockCell;
|
||||
cell.text = QString("%1 %2").arg(cell.text, text).trimmed();
|
||||
continue;
|
||||
}
|
||||
|
||||
const PDFTextLines& textLines = textBlock.getLines();
|
||||
for (size_t j = 0; j < textLines.size(); ++j)
|
||||
{
|
||||
const PDFTextLine& textLine = textLines[j];
|
||||
QRectF boundingRect = textLine.getBoundingBox().boundingRect();
|
||||
|
||||
auto itLineCell = std::find_if(tableCells.begin(), tableCells.end(), [boundingRect](const auto& cell) { return cell.rectangle.contains(boundingRect); });
|
||||
if (itLineCell != tableCells.end())
|
||||
{
|
||||
// Jakub Melka: whole block is contained in the cell
|
||||
PDFTextSelection blockSelection = m_textLayout.selectLineInBlock(i, j, m_pageIndex, QColor());
|
||||
QString text = m_textLayout.getTextFromSelection(blockSelection, m_pageIndex);
|
||||
TableCell& cell = *itLineCell;
|
||||
cell.text = QString("%1 %2").arg(cell.text, text).trimmed();
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (m_isTransposed)
|
||||
{
|
||||
auto comparator = [](const TableCell& left, const TableCell right)
|
||||
|
Reference in New Issue
Block a user