14 #include <QtCore/QRect>
15 #include <QApplication>
16 #include <QDesktopWidget>
21 #include "config-okular.h"
23 #include <kscreen/config.h>
24 #include <kscreen/edid.h>
30 #include <ApplicationServices/ApplicationServices.h>
31 #include <IOKit/graphics/IOGraphicsLib.h>
36 using namespace Okular;
43 switch ( orientation )
46 ret =
QRect( width - source.
y() - source.
height(), source.
x(),
50 ret =
QRect( width - source.
x() - source.
width(), height - source.
y() - source.
height(),
54 ret =
QRect( source.
y(), height - source.
x() - source.
width(),
81 kDebug() <<
"Pix:" << w->
width() <<
"MM:" << w->
widthMM();
82 return (
double(w->
width()) * 25.4) / double(w->
widthMM());
105 KScreen::Config* config = KScreen::Config::current();
107 KScreen::OutputList outputs = config->outputs();
110 widgetOnScreen->
pos();
111 QRect widgetRect(globalPos, widgetOnScreen->
size());
113 KScreen::Output* selectedOutput = 0;
115 Q_FOREACH(KScreen::Output *output, outputs)
117 if (output->currentMode())
119 QRect outputRect(output->pos(),output->currentMode()->size());
121 int area = intersection.
width()*intersection.height();
125 selectedOutput = output;
132 kDebug() <<
"Found widget at output #" << selectedOutput->id();
133 QRect outputRect(selectedOutput->pos(),selectedOutput->currentMode()->size());
134 QSize szMM = selectedOutput->sizeMm();
135 kDebug() <<
"Output size is (mm) " << szMM;
136 kDebug() <<
"Output rect is " << outputRect;
137 if (selectedOutput->edid()) {
138 kDebug() <<
"EDID WxH (cm): " << selectedOutput->edid()->
width() <<
'x' << selectedOutput->edid()->height();
140 if (szMM.width() > 0 && szMM.height() > 0 && outputRect.width() > 0 && outputRect.height() > 0
141 && selectedOutput->edid()
142 && qAbs(static_cast<int>(selectedOutput->edid()->width()*10) - szMM.width()) < 10
143 && qAbs(static_cast<int>(selectedOutput->edid()->height()*10) - szMM.height()) < 10)
146 QSizeF res(static_cast<qreal>(outputRect.width())*25.4/szMM.width(),
147 static_cast<qreal
>(outputRect.height())*25.4/szMM.height());
148 if (!selectedOutput->isHorizontal())
150 kDebug() <<
"Output is vertical, transposing DPI rect";
153 if (qAbs(res.width() - res.height()) / qMin(res.height(), res.width()) < 0.05) {
156 kDebug() <<
"KScreen calculation returned a non square dpi." << res <<
". Falling back";
162 kDebug() <<
"Didn't find a KScreen selectedOutput to calculate DPI. Falling back";
167 kDebug() <<
"Didn't find a KScreen config to calculate DPI. Falling back";
177 kDebug() <<
"QDesktopWidget calculation returned a non square dpi." << res <<
". Falling back";
184 kDebug() <<
"QX11Info returned a non square dpi." << res <<
". Falling back";
191 #elif defined(Q_WS_MAC)
196 static int GetIntFromDictionaryForKey( CFDictionaryRef desc, CFStringRef key )
200 if ( (value = (CFNumberRef)CFDictionaryGetValue(desc, key)) == NULL || CFGetTypeID(value) != CFNumberGetTypeID())
202 CFNumberGetValue(value, kCFNumberIntType, &num);
206 static CGDisplayErr GetDisplayDPI( CFDictionaryRef displayModeDict, CGDirectDisplayID displayID,
207 double *horizontalDPI,
double *verticalDPI )
209 CGDisplayErr err = kCGErrorFailure;
210 io_connect_t displayPort;
211 CFDictionaryRef displayDict;
214 displayPort = CGDisplayIOServicePort( displayID );
215 if ( displayPort != MACH_PORT_NULL )
218 displayDict = IODisplayCreateInfoDictionary(displayPort, 0);
219 if ( displayDict != NULL )
221 const double mmPerInch = 25.4;
222 double horizontalSizeInInches =
223 (double)GetIntFromDictionaryForKey(displayDict,
224 CFSTR(kDisplayHorizontalImageSize)) / mmPerInch;
225 double verticalSizeInInches =
226 (double)GetIntFromDictionaryForKey(displayDict,
227 CFSTR(kDisplayVerticalImageSize)) / mmPerInch;
230 CFRelease(displayDict);
235 (double)GetIntFromDictionaryForKey( displayModeDict, kCGDisplayWidth )
236 / horizontalSizeInInches;
237 *verticalDPI = (double)GetIntFromDictionaryForKey( displayModeDict,
238 kCGDisplayHeight ) / verticalSizeInInches;
239 err = CGDisplayNoErr;
248 CGDisplayErr err = GetDisplayDPI( CGDisplayCurrentMode(kCGDirectMainDisplay),
249 kCGDirectMainDisplay,
252 return err == CGDisplayNoErr ? x : 72.0;
258 CGDisplayErr err = GetDisplayDPI( CGDisplayCurrentMode(kCGDirectMainDisplay),
259 kCGDirectMainDisplay,
262 return err == CGDisplayNoErr ? y : 72.0;
308 return ( argb & 0xFFFFFF ) == 0xFFFFFF;
316 int width = image->
width();
317 int height = image->
height();
318 int left, top, bottom, right, x, y;
326 for ( top = 0; top < height; ++top )
327 for ( x = 0; x < width; ++x )
335 for ( bottom = height-1; bottom >= top; --bottom )
336 for ( x = width-1; x >= 0; --x )
347 for ( y = top; y <= bottom && ( left > 0 || right < width-1 ); ++y )
349 for ( x = 0; x < left; ++x )
352 for ( x = width-1; x > right+1; --x )
361 kDebug() <<
"Computed bounding box" << bbox <<
"in" << time.
elapsed() <<
"ms";
372 while ( ( read = from->
read( buffer.
data(), buffer.
size() ) ) > 0 )
375 if ( read != written )
383 matrix.
rotate( (
int)rotation * 90 );
static double dpiY()
Return the vertical DPI of the main display.
static double realDpiX()
Return the real horizontal DPI of the main display.
NormalizedRect is a helper class which stores the coordinates of a normalized rect, which is a rectangle of.
Rotated 180 degrees clockwise.
static QRect rotateRect(const QRect &source, int width, int height, int orientation)
Rotate the rect source in the area width x height with the specified orientation .
static double dpiX()
Return the horizontal DPI of the main display.
QRgb pixel(int x, int y) const
static NormalizedRect imageBoundingBox(const QImage *image)
Compute the smallest rectangle that contains all non-white pixels in image), in normalized [0...
const char * constData() const
qint64 read(char *data, qint64 maxSize)
Rotated 2700 degrees clockwise.
QRect intersected(const QRect &rectangle) const
void copyQIODevice(QIODevice *from, QIODevice *to)
Rotated 90 degrees clockwise.
QTransform buildRotationMatrix(Rotation rotation)
Return a rotation matrix corresponding to the rotation enumeration.
QDesktopWidget * desktop()
qint64 write(const char *data, qint64 maxSize)
static QSizeF realDpi(QWidget *widgetOnScreen)
Return the real DPI of the display containing given widget.
static bool isWhite(QRgb argb)
static double realDpiY()
Return the real vertical DPI of the main display.