Skip to content

Commit

Permalink
Mac screen DPI fix
Browse files Browse the repository at this point in the history
  • Loading branch information
codeservice committed Jan 27, 2013
1 parent 647a259 commit 09dab5e
Showing 1 changed file with 22 additions and 15 deletions.
37 changes: 22 additions & 15 deletions project/mac/System.mm
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,28 @@ bool LaunchBrowser(const char *inUtf8URL)

double CapabilitiesGetScreenDPI()
{
#ifndef OBJC_ARC
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
#endif

NSScreen *screen = [NSScreen mainScreen];
NSDictionary *description = [screen deviceDescription];
NSSize displayPixelSize = [[description objectForKey:NSDeviceSize] sizeValue];
CGSize displayPhysicalSize = CGDisplayScreenSize(
[[description objectForKey:@"NSScreenNumber"] unsignedIntValue]);
double result = ((displayPixelSize.width / displayPhysicalSize.width) + (displayPixelSize.height / displayPhysicalSize.height)) * 0.5 * 25.4;

#ifndef OBJC_ARC
[pool drain];
#endif
return result;
#ifndef OBJC_ARC
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
#endif

double result = 72.0f;

NSScreen *screen = [NSScreen mainScreen];

if (screen)
{
CGFloat scaleFactor = [screen userSpaceScaleFactor];
NSDictionary* deviceDescription = [screen deviceDescription];
NSSize resolution = [[deviceDescription objectForKey:NSDeviceResolution] sizeValue];
//printf("size.width: %f size.height: %f sf: %f\n", resolution.width, resolution.height, scaleFactor);

result = scaleFactor * (resolution.width + resolution.height)/2.0;
}

#ifndef OBJC_ARC
[pool drain];
#endif
return result;
}

double CapabilitiesGetPixelAspectRatio() {
Expand Down

0 comments on commit 09dab5e

Please sign in to comment.