Commit f42a3bad authored by Aleix Pol Gonzalez's avatar Aleix Pol Gonzalez 🐧
Browse files

Drop libkscreen dependency

Drops the x11 fallback. We were falling back to QX11Extras that were in
fact using QScreen internally.
Also remove the QDesktopWidget fallbacks for the same reason.
Drops some API for fetching the dpi and unifies it with ::realDpi(QWidget).

Based on Sebas's patch.
Reviewed by Albert.

REVIEW: 126913
parent 1b2de0d1
......@@ -65,13 +65,6 @@ find_package(ZLIB REQUIRED)
# TYPE RECOMMENDED
# PURPOSE "Required to build Okular.")
find_package(KF5Screen)
set_package_properties("LibKScreen" PROPERTIES
DESCRIPTION "KDE screen management library"
URL "https://projects.kde.org/projects/kdereview/libkscreen"
TYPE RECOMMENDED
PURPOSE "DPI detection support")
add_definitions(-DQT_USE_FAST_CONCATENATION -DQT_USE_FAST_OPERATOR_PLUS)
add_definitions(-DTRANSLATION_DOMAIN="okular")
......@@ -223,11 +216,6 @@ PUBLIC # these are included from the installed headers
Qt5::Widgets
)
if(LibKScreen_FOUND)
message("KF5: port code to KScreen")
#target_link_libraries(okularcore KF5::LibKScreen)
endif(LibKScreen_FOUND)
set_target_properties(okularcore PROPERTIES VERSION 6.0.0 SOVERSION 6 OUTPUT_NAME Okular5Core EXPORT_NAME Core)
install(TARGETS okularcore EXPORT Okular5Targets ${KDE_INSTALL_TARGETS_DEFAULT_ARGS})
......
/* Defines if force the use DRM in okular */
#define OKULAR_FORCE_DRM ${_OKULAR_FORCE_DRM}
/* Defines if LibKScreen is present */
#define HAVE_LIBKSCREEN ${LibKScreen_FOUND}
......@@ -11,6 +11,7 @@
#include "utils.h"
#include "utils_p.h"
#include "debug_p.h"
#include "settings_core.h"
#include <QtCore/QRect>
......@@ -18,15 +19,8 @@
#include <QDesktopWidget>
#include <QImage>
#include <QIODevice>
#ifdef Q_WS_X11
#include "config-okular.h"
#if HAVE_LIBKSCREEN
#include <kscreen/config.h>
#include <kscreen/edid.h>
#endif
#include <QX11Info>
#endif
#include <QWindow>
#include <QScreen>
#ifdef Q_OS_MAC
#include <ApplicationServices/ApplicationServices.h>
......@@ -64,133 +58,29 @@ QRect Utils::rotateRect( const QRect & source, int width, int height, int orient
return ret;
}
#if defined(Q_WS_X11)
double Utils::dpiX()
{
return QX11Info::appDpiX();
}
double Utils::dpiY()
{
return QX11Info::appDpiY();
}
double Utils::realDpiX()
{
const QDesktopWidget* w = QApplication::desktop();
if (w->width() > 0 && w->widthMM() > 0) {
qCDebug(OkularCoreDebug) << "Pix:" << w->width() << "MM:" << w->widthMM();
return (double(w->width()) * 25.4) / double(w->widthMM());
} else {
return dpiX();
}
}
double Utils::realDpiY()
{
const QDesktopWidget* w = QApplication::desktop();
if (w->height() > 0 && w->heightMM() > 0) {
qCDebug(OkularCoreDebug) << "Pix:" << w->height() << "MM:" << w->heightMM();
return (double(w->height()) * 25.4) / double(w->heightMM());
} else {
return dpiY();
}
}
#if !defined(Q_OS_MAC)
QSizeF Utils::realDpi(QWidget* widgetOnScreen)
{
if (widgetOnScreen)
{
// Firstly try to retrieve DPI via LibKScreen
#if HAVE_LIBKSCREEN
KScreen::Config* config = KScreen::Config::current();
if (config) {
KScreen::OutputList outputs = config->outputs();
QPoint globalPos = widgetOnScreen->parentWidget() ?
widgetOnScreen->mapToGlobal(widgetOnScreen->pos()):
widgetOnScreen->pos();
QRect widgetRect(globalPos, widgetOnScreen->size());
KScreen::Output* selectedOutput = 0;
int maxArea = 0;
Q_FOREACH(KScreen::Output *output, outputs)
{
if (output->currentMode())
{
QRect outputRect(output->pos(),output->currentMode()->size());
QRect intersection = outputRect.intersected(widgetRect);
int area = intersection.width()*intersection.height();
if (area > maxArea)
{
maxArea = area;
selectedOutput = output;
}
}
}
const QScreen* screen = widgetOnScreen && widgetOnScreen->window() && widgetOnScreen->window()->windowHandle()
? widgetOnScreen->window()->windowHandle()->screen()
: qGuiApp->primaryScreen();
if (selectedOutput)
{
qCDebug(OkularCoreDebug) << "Found widget at output #" << selectedOutput->id();
QRect outputRect(selectedOutput->pos(),selectedOutput->currentMode()->size());
QSize szMM = selectedOutput->sizeMm();
qCDebug(OkularCoreDebug) << "Output size is (mm) " << szMM;
qCDebug(OkularCoreDebug) << "Output rect is " << outputRect;
if (selectedOutput->edid()) {
qCDebug(OkularCoreDebug) << "EDID WxH (cm): " << selectedOutput->edid()->width() << 'x' << selectedOutput->edid()->height();
}
if (szMM.width() > 0 && szMM.height() > 0 && outputRect.width() > 0 && outputRect.height() > 0
&& selectedOutput->edid()
&& qAbs(static_cast<int>(selectedOutput->edid()->width()*10) - szMM.width()) < 10
&& qAbs(static_cast<int>(selectedOutput->edid()->height()*10) - szMM.height()) < 10)
{
// sizes in EDID seem to be consistent
QSizeF res(static_cast<qreal>(outputRect.width())*25.4/szMM.width(),
static_cast<qreal>(outputRect.height())*25.4/szMM.height());
if (!selectedOutput->isHorizontal())
{
qCDebug(OkularCoreDebug) << "Output is vertical, transposing DPI rect";
res.transpose();
}
if (qAbs(res.width() - res.height()) / qMin(res.height(), res.width()) < 0.05) {
return res;
} else {
qCDebug(OkularCoreDebug) << "KScreen calculation returned a non square dpi." << res << ". Falling back";
}
}
}
else
{
qCDebug(OkularCoreDebug) << "Didn't find a KScreen selectedOutput to calculate DPI. Falling back";
if (screen)
{
const QSizeF res(screen->physicalDotsPerInchX(), screen->physicalDotsPerInchY());
if (res.width() > 0 && res.height() > 0) {
if (qAbs(res.width() - res.height()) / qMin(res.height(), res.width()) < 0.05) {
return res;
} else {
qCDebug(OkularCoreDebug) << "QScreen calculation returned a non square dpi." << res << ". Falling back";
}
}
else
{
qCDebug(OkularCoreDebug) << "Didn't find a KScreen config to calculate DPI. Falling back";
}
#endif
}
// this is also fallback for LibKScreen branch if KScreen::Output
// for particular widget was not found
QSizeF res = QSizeF(realDpiX(), realDpiY());
if (qAbs(res.width() - res.height()) / qMin(res.height(), res.width()) < 0.05) {
return res;
} else {
qCDebug(OkularCoreDebug) << "QDesktopWidget calculation returned a non square dpi." << res << ". Falling back";
}
res = QSizeF(dpiX(), dpiY());
if (qAbs(res.width() - res.height()) / qMin(res.height(), res.width()) < 0.05) {
return res;
} else {
qCDebug(OkularCoreDebug) << "QX11Info returned a non square dpi." << res << ". Falling back";
}
res = QSizeF(72, 72);
return res;
return QSizeF(72, 72);
}
#elif defined(Q_OS_MAC)
#else
/*
* Code copied from http://developer.apple.com/qa/qa2001/qa1217.html
*/
......@@ -244,7 +134,7 @@ QSizeF Utils::realDpi(QWidget* widgetOnScreen)
return err;
}
double Utils::dpiX()
double Utils::realDpiX()
{
double x,y;
CGDisplayErr err = GetDisplayDPI( CGDisplayCurrentMode(kCGDirectMainDisplay),
......@@ -254,7 +144,7 @@ double Utils::dpiX()
return err == CGDisplayNoErr ? x : 72.0;
}
double Utils::dpiY()
double Utils::realDpiY()
{
double x,y;
CGDisplayErr err = GetDisplayDPI( CGDisplayCurrentMode(kCGDirectMainDisplay),
......@@ -264,42 +154,6 @@ double Utils::dpiY()
return err == CGDisplayNoErr ? y : 72.0;
}
double Utils::realDpiX()
{
return dpiX();
}
double Utils::realDpiY()
{
return dpiY();
}
QSizeF Utils::realDpi(QWidget*)
{
return QSizeF(realDpiX(), realDpiY());
}
#else
double Utils::dpiX()
{
return QDesktopWidget().physicalDpiX();
}
double Utils::dpiY()
{
return QDesktopWidget().physicalDpiY();
}
double Utils::realDpiX()
{
return dpiX();
}
double Utils::realDpiY()
{
return dpiY();
}
QSizeF Utils::realDpi(QWidget*)
{
return QSizeF(realDpiX(), realDpiY());
......
......@@ -34,38 +34,6 @@ class OKULARCORE_EXPORT Utils
*/
static QRect rotateRect( const QRect & source, int width, int height, int orientation );
/**
* Return the horizontal DPI of the main display
*/
static double dpiX();
/**
* Return the vertical DPI of the main display
*/
static double dpiY();
/**
* Return the real horizontal DPI of the main display.
*
* On X11, it can indicate the real horizontal DPI value without any Xrdb
* setting. Otherwise, returns the same as dpiX(),
*
* @since 0.9 (KDE 4.3)
* @deprecated Can not work with multi-monitor configurations
*/
static double realDpiX();
/**
* Return the real vertical DPI of the main display
*
* On X11, it can indicate the real horizontal DPI value without any Xrdb
* setting. Otherwise, returns the same as dpiX(),
*
* @since 0.9 (KDE 4.3)
* @deprecated Can not work with multi-monitor configurations
*/
static double realDpiY();
/**
* Return the real DPI of the display containing given widget
*
......
......@@ -132,8 +132,9 @@ Okular::Document::OpenResult Converter::convertWithPassword( const QString &file
const QString masterLayout = mStyleInformation->masterPageName();
const PageFormatProperty property = mStyleInformation->pageProperty( masterLayout );
int pageWidth = qRound(property.width() / 72.0 * Okular::Utils::dpiX());
int pageHeight = qRound(property.height() / 72.0 * Okular::Utils::dpiY());
const QSizeF dpi = Okular::Utils::realDpi(nullptr);
int pageWidth = qRound(property.width() / 72.0 * dpi.width());
int pageHeight = qRound(property.height() / 72.0 * dpi.height());
if ( pageWidth == 0 )
pageWidth = 600;
......
......@@ -344,9 +344,7 @@ void TIFFGenerator::loadPages( QVector<Okular::Page*> & pagesVector )
uint32 width = 0;
uint32 height = 0;
const double dpiX = Okular::Utils::dpiX();
const double dpiY = Okular::Utils::dpiY();
const QSizeF dpi = Okular::Utils::realDpi(nullptr);
for ( tdir_t i = 0; i < dirs; ++i )
{
if ( !TIFFSetDirectory( d->tiff, i ) )
......@@ -356,8 +354,8 @@ void TIFFGenerator::loadPages( QVector<Okular::Page*> & pagesVector )
TIFFGetField( d->tiff, TIFFTAG_IMAGELENGTH, &height ) != 1 )
continue;
adaptSizeToResolution( d->tiff, TIFFTAG_XRESOLUTION, dpiX, &width );
adaptSizeToResolution( d->tiff, TIFFTAG_YRESOLUTION, dpiY, &height );
adaptSizeToResolution( d->tiff, TIFFTAG_XRESOLUTION, dpi.width(), &width );
adaptSizeToResolution( d->tiff, TIFFTAG_YRESOLUTION, dpi.height(), &height );
Okular::Page * page = new Okular::Page( realdirs, width, height, readTiffRotation( d->tiff ) );
pagesVector[ realdirs ] = page;
......
......@@ -345,7 +345,7 @@ void AnnotWindow::renderLatex( bool render )
QColor fontColor = textEdit->textColor();
int fontSize = textEdit->fontPointSize();
QString latexOutput;
GuiUtils::LatexRenderer::Error errorCode = m_latexRenderer->renderLatexInHtml( contents, fontColor, fontSize, Okular::Utils::dpiX(), latexOutput );
GuiUtils::LatexRenderer::Error errorCode = m_latexRenderer->renderLatexInHtml( contents, fontColor, fontSize, Okular::Utils::realDpi(nullptr).width(), latexOutput );
switch ( errorCode )
{
case GuiUtils::LatexRenderer::LatexNotFound:
......
......@@ -766,7 +766,7 @@ void PagePainter::paintCroppedPageOnPainter( QPainter * destPainter, const Okula
if ( geom->style().width() || geom->geometricalInnerColor().isValid() )
{
mixedPainter->save();
const double width = geom->style().width() * Okular::Utils::dpiX() / ( 72.0 * 2.0 ) * scaledWidth / page->width();
const double width = geom->style().width() * Okular::Utils::realDpi(nullptr).width() / ( 72.0 * 2.0 ) * scaledWidth / page->width();
QRectF r( .0, .0, annotBoundary.width(), annotBoundary.height() );
r.adjust( width, width, -width, -width );
r.translate( annotBoundary.topLeft() );
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment