Revision: 12860 http://sourceforge.net/p/skim-app/code/12860 Author: hofman Date: 2022-04-24 15:04:17 +0000 (Sun, 24 Apr 2022) Log Message: ----------- Get and keep angles for language directions rather than the enum values
Modified Paths: -------------- trunk/PDFDocument_SKExtensions.h trunk/PDFDocument_SKExtensions.m trunk/PDFPage_SKExtensions.m trunk/SKPDFDocument.h trunk/SKPDFDocument.m Modified: trunk/PDFDocument_SKExtensions.h =================================================================== --- trunk/PDFDocument_SKExtensions.h 2022-04-24 14:35:33 UTC (rev 12859) +++ trunk/PDFDocument_SKExtensions.h 2022-04-24 15:04:17 UTC (rev 12860) @@ -39,16 +39,16 @@ #import <Cocoa/Cocoa.h> #import <Quartz/Quartz.h> -typedef struct _SKLanguageDirections { - NSLocaleLanguageDirection characterDirection; - NSLocaleLanguageDirection lineDirection; -} SKLanguageDirections; +typedef struct _SKLanguageDirectionAngles { + NSInteger characterDirection; + NSInteger lineDirection; +} SKLanguageDirectionAngles; @interface PDFDocument (SKExtensions) - (NSArray *)pageLabels; - (NSArray *)fileIDStrings; - (NSDictionary *)initialSettings; -- (SKLanguageDirections)languageDirections; +- (SKLanguageDirectionAngles)languageDirectionAngles; - (BOOL)allowsNotes; - (BOOL)realAllowsCommenting; - (NSDocument *)containingDocument; Modified: trunk/PDFDocument_SKExtensions.m =================================================================== --- trunk/PDFDocument_SKExtensions.m 2022-04-24 14:35:33 UTC (rev 12859) +++ trunk/PDFDocument_SKExtensions.m 2022-04-24 15:04:17 UTC (rev 12860) @@ -203,10 +203,21 @@ return [settings count] > 0 ? settings : nil; } -- (SKLanguageDirections)languageDirections { +static inline NSInteger angleForDirection(NSLocaleLanguageDirection direction, BOOL isLine) { + switch (direction) { + case NSLocaleLanguageDirectionLeftToRight: return 0; + case NSLocaleLanguageDirectionRightToLeft: return 180; + case NSLocaleLanguageDirectionTopToBottom: return 270; + case NSLocaleLanguageDirectionBottomToTop: return 90; + case NSLocaleLanguageDirectionUnknown: + default: return isLine ? 270 : 0; + } +} + +- (SKLanguageDirectionAngles)languageDirectionAngles { CGPDFDocumentRef doc = [self documentRef]; CGPDFDictionaryRef catalog = CGPDFDocumentGetCatalog(doc); - SKLanguageDirections directions = (SKLanguageDirections){NSLocaleLanguageDirectionLeftToRight, NSLocaleLanguageDirectionTopToBottom}; + SKLanguageDirectionAngles angles = (SKLanguageDirectionAngles){0, 270}; if (catalog) { CGPDFStringRef lang = NULL; CGPDFDictionaryRef viewerPrefs = NULL; @@ -213,29 +224,31 @@ const char *direction = NULL; if (CGPDFDictionaryGetString(catalog, "Lang", &lang)) { NSString *language = (NSString *)CGPDFStringCopyTextString(lang); - directions.characterDirection = [NSLocale characterDirectionForLanguage:language]; - directions.lineDirection = [NSLocale lineDirectionForLanguage:language]; - if (directions.lineDirection == NSLocaleLanguageDirectionUnknown) { - if (directions.characterDirection < NSLocaleLanguageDirectionTopToBottom) - directions.lineDirection = NSLocaleLanguageDirectionTopToBottom; + NSLocaleLanguageDirection characterDirection = [NSLocale characterDirectionForLanguage:language]; + NSLocaleLanguageDirection lineDirection = [NSLocale lineDirectionForLanguage:language]; + [language release]; + if (lineDirection == NSLocaleLanguageDirectionUnknown) { + if (characterDirection < NSLocaleLanguageDirectionTopToBottom) + lineDirection = NSLocaleLanguageDirectionTopToBottom; else - directions.lineDirection = NSLocaleLanguageDirectionLeftToRight; + lineDirection = NSLocaleLanguageDirectionLeftToRight; } - if (directions.characterDirection == NSLocaleLanguageDirectionUnknown) { - if (directions.lineDirection > NSLocaleLanguageDirectionRightToLeft) - directions.characterDirection = NSLocaleLanguageDirectionLeftToRight; + if (characterDirection == NSLocaleLanguageDirectionUnknown) { + if (lineDirection > NSLocaleLanguageDirectionRightToLeft) + characterDirection = NSLocaleLanguageDirectionLeftToRight; else - directions.characterDirection = NSLocaleLanguageDirectionTopToBottom; + characterDirection = NSLocaleLanguageDirectionTopToBottom; } - [language release]; + angles.characterDirection = angleForDirection(characterDirection, NO); + angles.lineDirection = angleForDirection(lineDirection, YES); } else if (CGPDFDictionaryGetDictionary(catalog, "ViewerPreferences", &viewerPrefs) && CGPDFDictionaryGetName(viewerPrefs, "Direction", &direction)) { if (0 == strcmp(direction, "L2R")) - directions.characterDirection = kCFLocaleLanguageDirectionLeftToRight; + angles.characterDirection = 0; else if (0 == strcmp(direction, "R2L")) - directions.characterDirection = kCFLocaleLanguageDirectionRightToLeft; + angles.characterDirection = 180; } } - return directions; + return angles; } #pragma clang diagnostic push Modified: trunk/PDFPage_SKExtensions.m =================================================================== --- trunk/PDFPage_SKExtensions.m 2022-04-24 14:35:33 UTC (rev 12859) +++ trunk/PDFPage_SKExtensions.m 2022-04-24 15:04:17 UTC (rev 12860) @@ -462,17 +462,6 @@ return CGPDFPageGetRotationAngle([self pageRef]); } -static inline NSInteger angleForDirection(NSLocaleLanguageDirection direction, BOOL isLine) { - switch (direction) { - case NSLocaleLanguageDirectionLeftToRight: return 0; - case NSLocaleLanguageDirectionRightToLeft: return 180; - case NSLocaleLanguageDirectionTopToBottom: return 270; - case NSLocaleLanguageDirectionBottomToTop: return 90; - case NSLocaleLanguageDirectionUnknown: - default: return isLine ? 270 : 0; - } -} - static inline NSInteger distanceForAngle(NSInteger angle, NSRect bounds, NSRect pageBounds) { switch (angle) { case 0: return NSMinX(bounds); @@ -484,13 +473,11 @@ } - (NSInteger)characterDirectionAngle { - SKLanguageDirections directions = [[self document] languageDirections]; - return ([self intrinsicRotation] + angleForDirection(directions.characterDirection, NO)) % 360; + return ([self intrinsicRotation] + [[self document] languageDirectionAngles].characterDirection) % 360; } - (NSInteger)lineDirectionAngle { - SKLanguageDirections directions = [[self document] languageDirections]; - return ([self intrinsicRotation] + angleForDirection(directions.lineDirection, YES)) % 360; + return ([self intrinsicRotation] + [[self document] languageDirectionAngles].lineDirection) % 360; } - (CGFloat)sortOrderForBounds:(NSRect)bounds { Modified: trunk/SKPDFDocument.h =================================================================== --- trunk/SKPDFDocument.h 2022-04-24 14:35:33 UTC (rev 12859) +++ trunk/SKPDFDocument.h 2022-04-24 15:04:17 UTC (rev 12860) @@ -43,7 +43,7 @@ @protocol SKPDFDocumentDelegate; @interface SKPDFDocument : PDFDocument { - SKLanguageDirections *languageDirections; + SKLanguageDirectionAngles *languageDirectionAngles; NSDocument *containingDocument; } @property (nonatomic, assign) NSDocument *containingDocument; Modified: trunk/SKPDFDocument.m =================================================================== --- trunk/SKPDFDocument.m 2022-04-24 14:35:33 UTC (rev 12859) +++ trunk/SKPDFDocument.m 2022-04-24 15:04:17 UTC (rev 12860) @@ -55,7 +55,7 @@ - (void)dealloc { containingDocument = nil; - SKZONEDESTROY(languageDirections); + SKZONEDESTROY(languageDirectionAngles); [super dealloc]; } @@ -63,12 +63,12 @@ return [SKPDFPage class]; } -- (SKLanguageDirections)languageDirections { - if (languageDirections == NULL) { - languageDirections = (SKLanguageDirections *)NSZoneMalloc(NULL, sizeof(SKLanguageDirections)); - *languageDirections = [super languageDirections]; +- (SKLanguageDirectionAngles)languageDirectionAngles { + if (languageDirectionAngles == NULL) { + languageDirectionAngles = (SKLanguageDirectionAngles *)NSZoneMalloc(NULL, sizeof(SKLanguageDirectionAngles)); + *languageDirectionAngles = [super languageDirectionAngles]; } - return *languageDirections; + return *languageDirectionAngles; } - (BOOL)unlockWithPassword:(NSString *)password { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. _______________________________________________ Skim-app-commit mailing list Skim-app-commit@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/skim-app-commit