mirror of
https://github.com/JakubMelka/PDF4QT.git
synced 2025-06-05 21:59:17 +02:00
Signature plugin: Layout horizontally/vertically
This commit is contained in:
@ -1674,10 +1674,50 @@ void PDFPageContentElementManipulator::performOperation(Operation operation)
|
|||||||
}
|
}
|
||||||
|
|
||||||
case Operation::LayoutVertically:
|
case Operation::LayoutVertically:
|
||||||
|
{
|
||||||
|
auto comparator = [](PDFPageContentElement* left, PDFPageContentElement* right)
|
||||||
|
{
|
||||||
|
QRectF r1 = left->getBoundingBox();
|
||||||
|
QRectF r2 = right->getBoundingBox();
|
||||||
|
|
||||||
|
return r1.y() > r2.y();
|
||||||
|
};
|
||||||
|
std::stable_sort(manipulatedElements.begin(), manipulatedElements.end(), comparator);
|
||||||
|
|
||||||
|
qreal yTop = representativeRect.bottom();
|
||||||
|
for (PDFPageContentElement* element : manipulatedElements)
|
||||||
|
{
|
||||||
|
QRectF boundingBox = element->getBoundingBox();
|
||||||
|
QPointF offset(0.0, yTop - boundingBox.bottom());
|
||||||
|
element->performManipulation(PDFPageContentElement::Translate, offset);
|
||||||
|
yTop -= boundingBox.height();
|
||||||
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
case Operation::LayoutHorizontally:
|
case Operation::LayoutHorizontally:
|
||||||
|
{
|
||||||
|
auto comparator = [](PDFPageContentElement* left, PDFPageContentElement* right)
|
||||||
|
{
|
||||||
|
QRectF r1 = left->getBoundingBox();
|
||||||
|
QRectF r2 = right->getBoundingBox();
|
||||||
|
|
||||||
|
return r1.x() < r2.x();
|
||||||
|
};
|
||||||
|
std::stable_sort(manipulatedElements.begin(), manipulatedElements.end(), comparator);
|
||||||
|
|
||||||
|
qreal x = representativeRect.left();
|
||||||
|
for (PDFPageContentElement* element : manipulatedElements)
|
||||||
|
{
|
||||||
|
QRectF boundingBox = element->getBoundingBox();
|
||||||
|
QPointF offset(x - boundingBox.left(), 0.0);
|
||||||
|
element->performManipulation(PDFPageContentElement::Translate, offset);
|
||||||
|
x += boundingBox.width();
|
||||||
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
case Operation::LayoutForm:
|
case Operation::LayoutForm:
|
||||||
break;
|
break;
|
||||||
|
Reference in New Issue
Block a user