tdf#100164 change scaling unit to precentage for *.5x factors
Currently we support DPI scaling by a integer factor. This commit changes that to percentage so we can have scaling factors like 1.5x or 1.25x. This is useful with 2.7k monitors that are in between standard DPI and HiDPI. Thresholding was adjusted to scale to 1.5x when DPI is between 120 and 168 DPI. The old method GetDPIScaleFactor has been changed to return a float value insted of int. Sometimes it is however more accurate to use GetDPIScalePercentage which was added in this commit. Change-Id: Iaecee793ff3d5084d00adeebbcf5d7368c580882 Reviewed-on: https://gerrit.libreoffice.org/30379 Reviewed-by: Tomaž Vajngerl <quikee@gmail.com> Tested-by: Tomaž Vajngerl <quikee@gmail.com>
This commit is contained in:
committed by
Tomaž Vajngerl
parent
a86144696d
commit
69b6ab1f8d
@@ -365,7 +365,7 @@ private:
|
||||
long mnOutHeight;
|
||||
sal_Int32 mnDPIX;
|
||||
sal_Int32 mnDPIY;
|
||||
sal_Int32 mnDPIScaleFactor; ///< For Hi-DPI displays, we want to draw everything mnDPIScaleFactor-times larger
|
||||
sal_Int32 mnDPIScalePercentage; ///< For Hi-DPI displays, we want to draw elements for a percentage larger
|
||||
/// font specific text alignment offsets in pixel units
|
||||
mutable long mnTextOffX;
|
||||
mutable long mnTextOffY;
|
||||
@@ -533,7 +533,15 @@ public:
|
||||
SAL_DLLPRIVATE void SetDPIX( sal_Int32 nDPIX ) { mnDPIX = nDPIX; }
|
||||
SAL_DLLPRIVATE void SetDPIY( sal_Int32 nDPIY ) { mnDPIY = nDPIY; }
|
||||
|
||||
sal_Int32 GetDPIScaleFactor() const { return mnDPIScaleFactor; }
|
||||
float GetDPIScaleFactor() const
|
||||
{
|
||||
return mnDPIScalePercentage / 100.0f;
|
||||
}
|
||||
|
||||
sal_Int32 GetDPIScalePercentage() const
|
||||
{
|
||||
return mnDPIScalePercentage;
|
||||
}
|
||||
|
||||
OutDevType GetOutDevType() const { return meOutDevType; }
|
||||
|
||||
|
@@ -181,7 +181,7 @@ void VirtualDevice::ImplInitVirDev( const OutputDevice* pOutDev,
|
||||
mpFontCache = pSVData->maGDIData.mpScreenFontCache;
|
||||
mnDPIX = pOutDev->mnDPIX;
|
||||
mnDPIY = pOutDev->mnDPIY;
|
||||
mnDPIScaleFactor = pOutDev->mnDPIScaleFactor;
|
||||
mnDPIScalePercentage = pOutDev->mnDPIScalePercentage;
|
||||
maFont = pOutDev->maFont;
|
||||
|
||||
if( maTextColor != pOutDev->maTextColor )
|
||||
@@ -486,7 +486,7 @@ void VirtualDevice::ImplSetReferenceDevice( RefDevMode i_eRefDevMode, sal_Int32
|
||||
{
|
||||
mnDPIX = i_nDPIX;
|
||||
mnDPIY = i_nDPIY;
|
||||
mnDPIScaleFactor = 1;
|
||||
mnDPIScalePercentage = 100;
|
||||
|
||||
EnableOutput( false ); // prevent output on reference device
|
||||
mbScreenComp = false;
|
||||
|
@@ -124,9 +124,9 @@ void loadImageFromStream(std::shared_ptr<SvStream> const & xStream, OUString con
|
||||
if (eFlags & ImageLoadFlags::IgnoreDarkTheme)
|
||||
bConvertToDarkTheme = false;
|
||||
|
||||
sal_Int32 aScaleFactor = Application::GetDefaultDevice()->GetDPIScaleFactor();
|
||||
float aScaleFactor = Application::GetDefaultDevice()->GetDPIScaleFactor();
|
||||
if (eFlags & ImageLoadFlags::IgnoreScalingFactor)
|
||||
aScaleFactor = 1;
|
||||
aScaleFactor = 1.0f;
|
||||
|
||||
if (rPath.endsWith(".png"))
|
||||
{
|
||||
@@ -149,7 +149,7 @@ void loadImageFromStream(std::shared_ptr<SvStream> const & xStream, OUString con
|
||||
if (bConvertToDarkTheme)
|
||||
rBitmap = BitmapProcessor::createLightImage(rBitmap);
|
||||
|
||||
if (aScaleFactor > 1)
|
||||
if (aScaleFactor > 1.0f)
|
||||
rBitmap.Scale(double(aScaleFactor), double(aScaleFactor), BmpScaleFlag::Fast);
|
||||
}
|
||||
|
||||
@@ -284,13 +284,15 @@ OUString createVariant(const ImageLoadFlags eFlags)
|
||||
if (eFlags & ImageLoadFlags::IgnoreDarkTheme)
|
||||
bConvertToDarkTheme = false;
|
||||
|
||||
sal_Int32 aScaleFactor = Application::GetDefaultDevice()->GetDPIScaleFactor();
|
||||
sal_Int32 aScalePercentage = Application::GetDefaultDevice()->GetDPIScalePercentage();
|
||||
if (eFlags & ImageLoadFlags::IgnoreScalingFactor)
|
||||
aScaleFactor = 1;
|
||||
aScalePercentage = 100;
|
||||
|
||||
OUString aVariant;
|
||||
if (aScaleFactor == 2)
|
||||
aVariant = "2x";
|
||||
if (aScalePercentage == 100 && !bConvertToDarkTheme)
|
||||
return aVariant;
|
||||
|
||||
aVariant = OUString::number(aScalePercentage);
|
||||
|
||||
if (bConvertToDarkTheme)
|
||||
aVariant += "-dark";
|
||||
|
@@ -68,7 +68,7 @@ OutputDevice::OutputDevice() :
|
||||
mnOutHeight = 0;
|
||||
mnDPIX = 0;
|
||||
mnDPIY = 0;
|
||||
mnDPIScaleFactor = 1;
|
||||
mnDPIScalePercentage = 100;
|
||||
mnTextOffX = 0;
|
||||
mnTextOffY = 0;
|
||||
mnOutOffOrigX = 0;
|
||||
|
@@ -1017,20 +1017,20 @@ void OutputDevice::DrawWaveLine( const Point& rStartPos, const Point& rEndPos )
|
||||
aStartPt.RotateAround( nEndX, nEndY, -nOrientation );
|
||||
}
|
||||
|
||||
long nWaveHeight;
|
||||
|
||||
nWaveHeight = 3;
|
||||
long nWaveHeight = 3;
|
||||
nStartY++;
|
||||
nEndY++;
|
||||
|
||||
if (mnDPIScaleFactor > 1)
|
||||
{
|
||||
nWaveHeight *= mnDPIScaleFactor;
|
||||
float fScaleFactor = GetDPIScaleFactor();
|
||||
|
||||
nStartY += mnDPIScaleFactor - 1; // Shift down additional pixel(s) to create more visual separation.
|
||||
if (fScaleFactor > 1.0f)
|
||||
{
|
||||
nWaveHeight *= fScaleFactor;
|
||||
|
||||
nStartY += fScaleFactor - 1; // Shift down additional pixel(s) to create more visual separation.
|
||||
|
||||
// odd heights look better than even
|
||||
if (mnDPIScaleFactor % 2 == 0)
|
||||
if (nWaveHeight % 2 == 0)
|
||||
{
|
||||
nWaveHeight--;
|
||||
}
|
||||
@@ -1044,7 +1044,7 @@ void OutputDevice::DrawWaveLine( const Point& rStartPos, const Point& rEndPos )
|
||||
}
|
||||
ImplDrawWaveLine(nStartX, nStartY, 0, 0,
|
||||
nEndX-nStartX, nWaveHeight,
|
||||
mnDPIScaleFactor, nOrientation, GetLineColor());
|
||||
fScaleFactor, nOrientation, GetLineColor());
|
||||
|
||||
if( mpAlphaVDev )
|
||||
mpAlphaVDev->DrawWaveLine( rStartPos, rEndPos );
|
||||
|
@@ -869,7 +869,7 @@ void Window::ReleaseGraphics( bool bRelease )
|
||||
|
||||
static sal_Int32 CountDPIScaleFactor(sal_Int32 nDPI)
|
||||
{
|
||||
sal_Int32 nResult = 1;
|
||||
sal_Int32 nResult = 100;
|
||||
|
||||
#ifndef MACOSX
|
||||
// Setting of HiDPI is unfortunately all only a heuristic; and to add
|
||||
@@ -877,8 +877,12 @@ static sal_Int32 CountDPIScaleFactor(sal_Int32 nDPI)
|
||||
// the DPI and whatnot
|
||||
// eg. fdo#77059 - set the value from which we do consider the
|
||||
// screen hi-dpi to greater than 168
|
||||
if (nDPI > 168)
|
||||
nResult = std::max(sal_Int32(1), (nDPI + 48) / 96);
|
||||
if (nDPI > 216) // 96 * 2 + 96 / 4
|
||||
nResult = 250;
|
||||
else if (nDPI > 168) // 96 * 2 - 96 / 4
|
||||
nResult = 200;
|
||||
else if (nDPI > 120) // 96 * 1.5 - 96 / 4
|
||||
nResult = 150;
|
||||
#else
|
||||
(void)nDPI;
|
||||
#endif
|
||||
@@ -1130,7 +1134,7 @@ void Window::ImplInit( vcl::Window* pParent, WinBits nStyle, SystemParentData* p
|
||||
}
|
||||
|
||||
// setup the scale factor for Hi-DPI displays
|
||||
mnDPIScaleFactor = CountDPIScaleFactor(mpWindowImpl->mpFrameData->mnDPIY);
|
||||
mnDPIScalePercentage = CountDPIScaleFactor(mpWindowImpl->mpFrameData->mnDPIY);
|
||||
mnDPIX = mpWindowImpl->mpFrameData->mnDPIX;
|
||||
mnDPIY = mpWindowImpl->mpFrameData->mnDPIY;
|
||||
|
||||
@@ -1316,7 +1320,7 @@ void Window::ImplInitResolutionSettings()
|
||||
mnDPIY = mpWindowImpl->mpFrameData->mnDPIY;
|
||||
|
||||
// setup the scale factor for Hi-DPI displays
|
||||
mnDPIScaleFactor = CountDPIScaleFactor(mpWindowImpl->mpFrameData->mnDPIY);
|
||||
mnDPIScalePercentage = CountDPIScaleFactor(mpWindowImpl->mpFrameData->mnDPIY);
|
||||
const StyleSettings& rStyleSettings = mxSettings->GetStyleSettings();
|
||||
SetPointFont(*this, rStyleSettings.GetAppFont());
|
||||
}
|
||||
@@ -1324,7 +1328,7 @@ void Window::ImplInitResolutionSettings()
|
||||
{
|
||||
mnDPIX = mpWindowImpl->mpParent->mnDPIX;
|
||||
mnDPIY = mpWindowImpl->mpParent->mnDPIY;
|
||||
mnDPIScaleFactor = mpWindowImpl->mpParent->mnDPIScaleFactor;
|
||||
mnDPIScalePercentage = mpWindowImpl->mpParent->mnDPIScalePercentage;
|
||||
}
|
||||
|
||||
// update the recalculated values for logical units
|
||||
|
Reference in New Issue
Block a user