diff --git a/src/ios/ios.pyx b/src/ios/ios.pyx index 0e00cf5..4583320 100644 --- a/src/ios/ios.pyx +++ b/src/ios/ios.pyx @@ -14,6 +14,8 @@ cdef extern from "ios_wrapper.h": int ios_send_email(char *subject, char *text, char *mimetype, char *filename, char *filename_alias, ios_send_email_cb cb, void *userdata) void ios_open_url(char *url) + float ios_uiscreen_get_scale() + int ios_uiscreen_get_dpi() cdef void _send_email_done(char *status, void *data): cdef object callback = data @@ -159,3 +161,13 @@ def send_email(subject, text, mimetype=None, filename=None, filename_alias=None, return 0 return 1 + +def get_scale(): + '''Return the UIScreen scale (1 on iPad, 2 on iPad 3) + ''' + return ios_uiscreen_get_scale() + +def get_dpi(): + '''Return the approximate DPI of the screen + ''' + return ios_uiscreen_get_dpi() diff --git a/src/ios/ios_mail.m b/src/ios/ios_mail.m index 395b8f6..719ecdc 100644 --- a/src/ios/ios_mail.m +++ b/src/ios/ios_mail.m @@ -109,3 +109,22 @@ int ios_send_email(char *subject, char *text, char *mimetype, char *filename, return 1; } + +float ios_uiscreen_get_scale() { + float scale = 1.0; + if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)]) { + scale = [[UIScreen mainScreen] scale]; + }; + return scale; +} + +int ios_uiscreen_get_dpi() { + float scale = ios_uiscreen_get_scale(); + float dpi = 160 * scale; + if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { + dpi = 132 * scale; + } else if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) { + dpi = 163 * scale; + } + return dpi; +} diff --git a/src/ios/ios_wrapper.h b/src/ios/ios_wrapper.h index fe2b0e6..2ad63b4 100644 --- a/src/ios/ios_wrapper.h +++ b/src/ios/ios_wrapper.h @@ -1,6 +1,8 @@ #ifndef __IOS_WRAPPER #define __IOS_WRAPPER +float ios_uiscreen_get_scale(void); +int ios_uiscreen_get_dpi(void); void ios_open_url(char *url); typedef void (*ios_send_email_cb)(char *, void *);