Skip to content

Commit

Permalink
Include text alignment in line layout
Browse files Browse the repository at this point in the history
  • Loading branch information
XiaoMigros committed Apr 27, 2024
1 parent 744c38e commit f46190e
Showing 1 changed file with 33 additions and 14 deletions.
47 changes: 33 additions & 14 deletions src/engraving/rendering/dev/tlayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5906,12 +5906,29 @@ void TLayout::layoutTextLineBaseSegment(TextLineBaseSegment* item, LayoutContext
double y1 = std::min(0.0, pp2.y()) + y0;
double y2 = std::max(0.0, pp2.y()) - y0;

double l = 0.0;
double l1 = 0.0;
double l2 = 0.0;
double gapBetweenTextAndLine = _spatium * tl->gapBetweenTextAndLine().val();

bool alignBeginText = tl->beginTextPlace() == TextPlace::LEFT || tl->beginTextPlace() == TextPlace::AUTO;
bool alignContinueText = tl->continueTextPlace() == TextPlace::LEFT || tl->continueTextPlace() == TextPlace::AUTO;
bool alignEndText = tl->endTextPlace() == TextPlace::LEFT || tl->endTextPlace() == TextPlace::AUTO;
bool isSingleOrBegin = item->isSingleBeginType();
bool hasBeginText = !item->text()->empty() && isSingleOrBegin;
bool hasContinueText = !item->text()->empty() && !isSingleOrBegin;
bool hasEndText = !item->endText()->empty() && item->isSingleEndType();

if (!item->text()->empty()) {
double gapBetweenTextAndLine = _spatium * tl->gapBetweenTextAndLine().val();
if ((item->isSingleBeginType() && (tl->beginTextPlace() == TextPlace::LEFT || tl->beginTextPlace() == TextPlace::AUTO))
|| (!item->isSingleBeginType() && (tl->continueTextPlace() == TextPlace::LEFT || tl->continueTextPlace() == TextPlace::AUTO))) {
l = item->text()->pos().x() + item->text()->ldata()->bbox().width() + gapBetweenTextAndLine;
if ((isSingleOrBegin && alignBeginText) || (!isSingleOrBegin && alignContinueText)) {
l1 = item->text()->pos().x() + gapBetweenTextAndLine;
switch (item->text()->align().horizontal) {
case AlignH::LEFT:
l1 += item->text()->ldata()->bbox().width();
break;
case AlignH::HCENTER:
l1 += item->text()->ldata()->bbox().width() / 2;
break;
}
}

double h = item->text()->height();
Expand Down Expand Up @@ -5949,21 +5966,23 @@ void TLayout::layoutTextLineBaseSegment(TextLineBaseSegment* item, LayoutContext
}
// set end text position and extend bbox
if (!item->endText()->empty()) {
l2 = gapBetweenTextAndLine;
switch (item->endText()->align().horizontal) {
case AlignH::RIGHT:
l2 += item->endText()->ldata()->bbox().width();
break;
case AlignH::HCENTER:
l2 += item->endText()->ldata()->bbox().width() / 2;
break;
}
item->endText()->mutldata()->moveX(ldata->bbox().right());
ldata->addBbox(item->endText()->ldata()->bbox().translated(item->endText()->pos()));
}

if (tl->lineVisible() || !ctx.conf().isPrintingMode()) {
pp1 = PointF(l, 0.0);

pp1 = PointF(l1, 0.0);
pp2.rx() -= l2;
// Make sure baseline of text and line are properly aligned (accounting for line thickness)
bool alignBeginText = tl->beginTextPlace() == TextPlace::LEFT || tl->beginTextPlace() == TextPlace::AUTO;
bool alignContinueText = tl->continueTextPlace() == TextPlace::LEFT || tl->continueTextPlace() == TextPlace::AUTO;
bool alignEndText = tl->endTextPlace() == TextPlace::LEFT || tl->endTextPlace() == TextPlace::AUTO;
bool isSingleOrBegin = item->isSingleBeginType();
bool hasBeginText = !item->text()->empty() && isSingleOrBegin;
bool hasContinueText = !item->text()->empty() && !isSingleOrBegin;
bool hasEndText = !item->endText()->empty() && item->isSingleEndType();
if ((hasBeginText && alignBeginText) || (hasContinueText && alignContinueText)) {
alignBaseLine(item->text(), pp1, pp2);
} else if (hasEndText && alignEndText) {
Expand Down

0 comments on commit f46190e

Please sign in to comment.