summaryrefslogtreecommitdiff
path: root/svx
diff options
context:
space:
mode:
authorTomaž Vajngerl <tomaz.vajngerl@collabora.co.uk>2024-03-28 12:30:34 +0900
committerTomaž Vajngerl <quikee@gmail.com>2024-04-03 04:06:50 +0200
commitf61ea135430d7b4a1fac7de1e57a1314fbb1b49e (patch)
treeb90ac8f11051ff25dd7204e2bfebff6dc31d79f3 /svx
parentdb64748f1ee771da9da857f95601b9e08b577166 (diff)
editeng: use text scaling that better mimics MSO text scaling
Implement text scaling algorithm that is similar to MSO text scaling for text boxes for the compatibility purpuse, so that the Impress slides better match how the PP slides are layed out. This also moves the implementation into EditEng, where it is possible to better control how searching for the best scaling factor is performed without doing additional irrelevant work or trigger invalidations that should not be triggered. An additional change is that the paragraph with no content at the end are ignored, and are not taken into account when determining the height of the content. This is done for compatibility reasons. Fix horizontal spacing of tabs - the spacing shouldn't be scaled and the tab shouldn't include the space at the beginning of the line. Change-Id: Ie37fa67f1cf300e915a4ebaef2a7f968bf6c5744 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/165441 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
Diffstat (limited to 'svx')
-rw-r--r--svx/source/svdraw/svdotext.cxx133
-rw-r--r--svx/source/svdraw/svdotextdecomposition.cxx4
-rw-r--r--svx/source/svdraw/svdotxed.cxx2
3 files changed, 25 insertions, 114 deletions
diff --git a/svx/source/svdraw/svdotext.cxx b/svx/source/svdraw/svdotext.cxx
index 8e5e1f835542..526b4d8b0b8e 100644
--- a/svx/source/svdraw/svdotext.cxx
+++ b/svx/source/svdraw/svdotext.cxx
@@ -1233,14 +1233,14 @@ void SdrTextObj::ImpSetupDrawOutlinerForPaint( bool bContourFrame,
}
else if (IsAutoFit())
{
- ImpAutoFitText(rOutliner);
+ setupAutoFitText(rOutliner);
}
}
double SdrTextObj::GetFontScale() const
{
SdrOutliner& rOutliner = ImpGetDrawOutliner();
- // This eventually calls ImpAutoFitText
+ // This eventually calls setupAutoFitText
UpdateOutlinerFormatting(rOutliner, o3tl::temporary(tools::Rectangle()));
return rOutliner.getScalingParameters().fFontY;
@@ -1249,133 +1249,41 @@ double SdrTextObj::GetFontScale() const
double SdrTextObj::GetSpacingScale() const
{
SdrOutliner& rOutliner = ImpGetDrawOutliner();
- // This eventually calls ImpAutoFitText
+ // This eventually calls setupAutoFitText
UpdateOutlinerFormatting(rOutliner, o3tl::temporary(tools::Rectangle()));
return rOutliner.getScalingParameters().fSpacingY;
}
-void SdrTextObj::ImpAutoFitText( SdrOutliner& rOutliner ) const
+void SdrTextObj::setupAutoFitText(SdrOutliner& rOutliner) const
{
- const Size aShapeSize=GetSnapRect().GetSize();
- ImpAutoFitText( rOutliner,
- Size(aShapeSize.Width()-GetTextLeftDistance()-GetTextRightDistance(),
- aShapeSize.Height()-GetTextUpperDistance()-GetTextLowerDistance()),
- IsVerticalWriting() );
-}
+ const Size aShapeSize = GetSnapRect().GetSize();
+ Size aSize(aShapeSize.Width() - GetTextLeftDistance() - GetTextRightDistance(),
+ aShapeSize.Height() - GetTextUpperDistance() - GetTextLowerDistance());
-void SdrTextObj::ImpAutoFitText(SdrOutliner& rOutliner, const Size& rTextSize,
- bool bIsVerticalWriting) const
-{
- autoFitTextForCompatibility(rOutliner, rTextSize, bIsVerticalWriting);
+ setupAutoFitText(rOutliner, aSize);
}
-
-void SdrTextObj::autoFitTextForCompatibility(SdrOutliner& rOutliner, const Size& rTextBoxSize, bool bIsVerticalWriting) const
+void SdrTextObj::setupAutoFitText(SdrOutliner& rOutliner, const Size& rTextBoxSize) const
{
- rOutliner.setRoundFontSizeToPt(true);
+ rOutliner.setRoundFontSizeToPt(true); // We need to round the font size nearest integer pt size
+ rOutliner.SetMaxAutoPaperSize(rTextBoxSize);
+ rOutliner.SetPaperSize(rTextBoxSize);
const SdrTextFitToSizeTypeItem& rItem = GetObjectItem(SDRATTR_TEXT_FITTOSIZE);
- double fMaxScale = rItem.getFontScale();
- if (fMaxScale > 0.0)
- {
- rOutliner.setScalingParameters({ fMaxScale, fMaxScale, 100.0, 100.0 });
- }
- else
- {
- fMaxScale = 100.0;
- }
-
- Size aCurrentTextBoxSize = rOutliner.CalcTextSizeNTP();
- if (aCurrentTextBoxSize.Height() == 0)
- return;
- tools::Long nExtendTextBoxBy = -50;
- aCurrentTextBoxSize.extendBy(0, nExtendTextBoxBy);
- double fCurrentFitFactor = 1.0;
+ double fFontScale = rItem.getFontScale();
+ double fSpacingScale = rItem.getSpacingScale();
- if (bIsVerticalWriting)
- fCurrentFitFactor = double(rTextBoxSize.Width()) / aCurrentTextBoxSize.Width();
- else
- fCurrentFitFactor = double(rTextBoxSize.Height()) / aCurrentTextBoxSize.Height();
-
- auto aParameters = rOutliner.getScalingParameters();
- double fInitialFontScaleY = aParameters.fFontY;
- double fInitialSpacing = aParameters.fSpacingY;
-
- if (fCurrentFitFactor >= 1.0 && fInitialFontScaleY >= 100.0 && fInitialSpacing >= 100.0)
- return;
-
- sal_Int32 nFontHeight = GetObjectItemSet().Get(EE_CHAR_FONTHEIGHT).GetHeight();
-
- double fFontHeightPt = o3tl::convert(double(nFontHeight), o3tl::Length::mm100, o3tl::Length::pt);
- double fMinY = 0.0;
- double fMaxY = fMaxScale;
-
- double fBestFontScale = 0.0;
- double fBestSpacing = 100.0;
- double fBestFitFactor = fCurrentFitFactor;
-
- if (fCurrentFitFactor >= 1.0)
+ if (fFontScale > 0.0 && fSpacingScale > 0.0 && !mbInEditMode)
{
- fMinY = fInitialFontScaleY;
- fBestFontScale = fInitialFontScaleY;
- fBestSpacing = fInitialSpacing;
- fBestFitFactor = fCurrentFitFactor;
+ rOutliner.setScalingParameters({ fFontScale, fFontScale, 100.0, fSpacingScale });
}
else
{
- fMaxY = std::min(fInitialFontScaleY, fMaxScale);
+ rOutliner.resetScalingParameters();
}
- double fInTheMidle = 0.5;
-
- int iteration = 0;
- double fFitFactorTarget = 1.00;
-
- while (iteration < 10)
- {
- iteration++;
- double fScaleY = fMinY + (fMaxY - fMinY) * fInTheMidle;
-
- double fScaledFontHeight = fFontHeightPt * (fScaleY / 100.0);
- double fRoundedScaledFontHeight = std::floor(fScaledFontHeight * 10.0) / 10.0;
- double fCurrentFontScale = (fRoundedScaledFontHeight / fFontHeightPt) * 100.0;
-
- fCurrentFitFactor = 0.0; // reset fit factor;
-
- for (double fCurrentSpacing : {100.0, 90.0, 80.0})
- {
- if (fCurrentFitFactor >= fFitFactorTarget)
- continue;
-
- rOutliner.setScalingParameters({ fCurrentFontScale, fCurrentFontScale, 100.0, fCurrentSpacing });
-
- aCurrentTextBoxSize = rOutliner.CalcTextSizeNTP();
- aCurrentTextBoxSize.extendBy(0, nExtendTextBoxBy);
- if (bIsVerticalWriting)
- fCurrentFitFactor = double(rTextBoxSize.Width()) / aCurrentTextBoxSize.Width();
- else
- fCurrentFitFactor = double(rTextBoxSize.Height()) / aCurrentTextBoxSize.Height();
-
-
- if (fCurrentSpacing == 100.0)
- {
- if (fCurrentFitFactor > fFitFactorTarget)
- fMinY = fCurrentFontScale;
- else
- fMaxY = fCurrentFontScale;
- }
-
- if ((fBestFitFactor < fFitFactorTarget && fCurrentFitFactor > fBestFitFactor)
- || (fCurrentFitFactor >= fFitFactorTarget && fCurrentFitFactor < fBestFitFactor))
- {
- fBestFontScale = fCurrentFontScale;
- fBestSpacing = fCurrentSpacing;
- fBestFitFactor = fCurrentFitFactor;
- }
- }
- }
- rOutliner.setScalingParameters({ fBestFontScale, fBestFontScale, 100.0, fBestSpacing });
+ rOutliner.QuickFormatDoc();
}
void SdrTextObj::SetupOutlinerFormatting( SdrOutliner& rOutl, tools::Rectangle& rPaintRect ) const
@@ -1966,10 +1874,13 @@ void SdrTextObj::onEditOutlinerStatusEvent( EditStatus* pEditStatus )
assert(mpEditingOutliner);
mbInDownScale = true;
+ // Need to reset scaling so it searches for the fitting size again
+ mpEditingOutliner->resetScalingParameters();
+
// sucks that we cannot disable paints via
// mpEditingOutliner->SetUpdateMode(FALSE) - but EditEngine skips
// formatting as well, then.
- ImpAutoFitText(*mpEditingOutliner);
+ setupAutoFitText(*mpEditingOutliner);
mbInDownScale = false;
}
}
diff --git a/svx/source/svdraw/svdotextdecomposition.cxx b/svx/source/svdraw/svdotextdecomposition.cxx
index e54fdfd76cd7..7b94bfbc1093 100644
--- a/svx/source/svdraw/svdotextdecomposition.cxx
+++ b/svx/source/svdraw/svdotextdecomposition.cxx
@@ -935,11 +935,11 @@ void SdrTextObj::impDecomposeAutoFitTextPrimitive(
rOutliner.SetMinColumnWrapHeight(nAnchorTextWidth);
}
- rOutliner.SetPaperSize(aNullSize);
+ rOutliner.SetPaperSize(aAnchorTextSize);
rOutliner.SetUpdateLayout(true);
rOutliner.SetText(*pOutlinerParaObject);
- ImpAutoFitText(rOutliner,aAnchorTextSize,bVerticalWriting);
+ setupAutoFitText(rOutliner, aAnchorTextSize);
// set visualizing page at Outliner; needed e.g. for PageNumberField decomposition
rOutliner.setVisualizedPage(GetSdrPageFromXDrawPage(aViewInformation.getVisualizedPage()));
diff --git a/svx/source/svdraw/svdotxed.cxx b/svx/source/svdraw/svdotxed.cxx
index 120bf26b1751..8666f262be92 100644
--- a/svx/source/svdraw/svdotxed.cxx
+++ b/svx/source/svdraw/svdotxed.cxx
@@ -110,7 +110,7 @@ bool SdrTextObj::BegTextEdit(SdrOutliner& rOutl)
}
else if (IsAutoFit())
{
- ImpAutoFitText(rOutl);
+ setupAutoFitText(rOutl);
}
if(pOutlinerParaObject)