[Libreoffice-commits] core.git: include/vcl vcl/source
Tomaž Vajngerl
tomaz.vajngerl at collabora.co.uk
Sat Oct 29 21:48:09 UTC 2016
include/vcl/outdev.hxx | 12 ++++++++++--
vcl/source/gdi/virdev.cxx | 4 ++--
vcl/source/image/ImplImageTree.cxx | 16 +++++++++-------
vcl/source/outdev/outdev.cxx | 2 +-
vcl/source/outdev/textline.cxx | 16 ++++++++--------
vcl/source/window/window.cxx | 16 ++++++++++------
6 files changed, 40 insertions(+), 26 deletions(-)
New commits:
commit 69b6ab1f8de08b3418fd42d56076a73d40a29229
Author: Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
Date: Fri Oct 28 23:24:30 2016 +0200
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 at gmail.com>
Tested-by: Tomaž Vajngerl <quikee at gmail.com>
diff --git a/include/vcl/outdev.hxx b/include/vcl/outdev.hxx
index e21f0cb..6b396fa 100644
--- a/include/vcl/outdev.hxx
+++ b/include/vcl/outdev.hxx
@@ -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; }
diff --git a/vcl/source/gdi/virdev.cxx b/vcl/source/gdi/virdev.cxx
index 4d5c197..2e80762 100644
--- a/vcl/source/gdi/virdev.cxx
+++ b/vcl/source/gdi/virdev.cxx
@@ -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;
diff --git a/vcl/source/image/ImplImageTree.cxx b/vcl/source/image/ImplImageTree.cxx
index a112ddb..c101e5b 100644
--- a/vcl/source/image/ImplImageTree.cxx
+++ b/vcl/source/image/ImplImageTree.cxx
@@ -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";
diff --git a/vcl/source/outdev/outdev.cxx b/vcl/source/outdev/outdev.cxx
index 8555f5c..5cb45be 100644
--- a/vcl/source/outdev/outdev.cxx
+++ b/vcl/source/outdev/outdev.cxx
@@ -68,7 +68,7 @@ OutputDevice::OutputDevice() :
mnOutHeight = 0;
mnDPIX = 0;
mnDPIY = 0;
- mnDPIScaleFactor = 1;
+ mnDPIScalePercentage = 100;
mnTextOffX = 0;
mnTextOffY = 0;
mnOutOffOrigX = 0;
diff --git a/vcl/source/outdev/textline.cxx b/vcl/source/outdev/textline.cxx
index cdf40b3..d742e8f 100644
--- a/vcl/source/outdev/textline.cxx
+++ b/vcl/source/outdev/textline.cxx
@@ -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)
+ float fScaleFactor = GetDPIScaleFactor();
+
+ if (fScaleFactor > 1.0f)
{
- nWaveHeight *= mnDPIScaleFactor;
+ nWaveHeight *= fScaleFactor;
- nStartY += mnDPIScaleFactor - 1; // Shift down additional pixel(s) to create more visual separation.
+ 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 );
diff --git a/vcl/source/window/window.cxx b/vcl/source/window/window.cxx
index 2c97ee5..9170c6b 100644
--- a/vcl/source/window/window.cxx
+++ b/vcl/source/window/window.cxx
@@ -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
More information about the Libreoffice-commits
mailing list