Skip to content

Commit 3e90b28

Browse files
committed
Inspector orientation label and PGOrientation improvements.
1 parent 56055fe commit 3e90b28

11 files changed

+46
-23
lines changed

PGAppKitAdditions.m

+1-1
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ @implementation NSImageRep(PGAppKitAdditions)
158158
- (id)PG_thumbnailWithMaxSize:(NSSize)size orientation:(PGOrientation)orientation opaque:(BOOL)opaque
159159
{
160160
if(!self) return nil;
161-
NSSize const originalSize = PGRotated90CC & orientation ? NSMakeSize([self pixelsHigh], [self pixelsWide]) : NSMakeSize([self pixelsWide], [self pixelsHigh]);
161+
NSSize const originalSize = PGRotated90CCW & orientation ? NSMakeSize([self pixelsHigh], [self pixelsWide]) : NSMakeSize([self pixelsWide], [self pixelsHigh]);
162162
NSSize const s = PGIntegralSize(PGScaleSizeByFloat(originalSize, MIN(1.0f, MIN(size.width / originalSize.width, size.height / originalSize.height))));
163163
NSBitmapImageRep *const thumbRep = [[[NSBitmapImageRep alloc] initWithBitmapDataPlanes:NULL pixelsWide:s.width pixelsHigh:s.height bitsPerSample:8 samplesPerPixel:4 hasAlpha:YES isPlanar:NO colorSpaceName:NSDeviceRGBColorSpace bytesPerRow:0 bitsPerPixel:0] autorelease];
164164
if(!thumbRep) return nil;

PGDisplayController.m

+3-3
Original file line numberDiff line numberDiff line change
@@ -882,7 +882,7 @@ - (NSSize)_sizeForImageRep:(NSImageRep *)rep orientation:(PGOrientation)orientat
882882
{
883883
if(!rep) return NSZeroSize;
884884
NSSize originalSize = PGActualSizeWithDPI == scaleMode ? [rep size] : NSMakeSize([rep pixelsWide], [rep pixelsHigh]);
885-
if(orientation & PGRotated90CC) {
885+
if(orientation & PGRotated90CCW) {
886886
CGFloat const w = originalSize.width;
887887
originalSize.width = originalSize.height;
888888
originalSize.height = w;
@@ -1349,9 +1349,9 @@ - (void)clipViewGestureDidEnd:(PGClipView *)sender
13491349
PGOrientation o;
13501350
switch((NSInteger)round((deg + 360.0f) / 90.0f) % 4) {
13511351
case 0: o = PGUpright; break;
1352-
case 1: o = PGRotated90CC; break;
1352+
case 1: o = PGRotated90CCW; break;
13531353
case 2: o = PGUpsideDown; break;
1354-
case 3: o = PGRotated270CC; break;
1354+
case 3: o = PGRotated90CW; break;
13551355
default: PGAssertNotReached(@"Rotation wasn't simplified into an orientation.");
13561356
}
13571357
[[self activeDocument] setBaseOrientation:PGAddOrientation([[self activeDocument] baseOrientation], o)];

PGFoundationAdditions.m

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ + (id)PG_transformWithRect:(inout NSRectPointer)rectPtr orientation:(PGOrientati
5252
NSAffineTransform *const transform = [self transform];
5353
if(PGUpright == orientation) return transform;
5454
[transform translateXBy:NSMidX(*rectPtr) yBy:NSMidY(*rectPtr)];
55-
if(orientation & PGRotated90CC) {
55+
if(orientation & PGRotated90CCW) {
5656
[transform rotateByDegrees:90.0f];
5757
rectPtr->size = NSMakeSize(NSHeight(*rectPtr), NSWidth(*rectPtr)); // Swap.
5858
}

PGGenericImageAdapter.m

+1-10
Original file line numberDiff line numberDiff line change
@@ -80,16 +80,7 @@ - (NSDictionary *)_imageSourceOptions
8080
- (void)_setImageProperties:(NSDictionary *)properties
8181
{
8282
PGOrientation const oldOrientation = _orientation;
83-
switch([[properties objectForKey:(NSString *)kCGImagePropertyOrientation] unsignedIntegerValue]) {
84-
case 2: _orientation = PGFlippedHorz; break;
85-
case 3: _orientation = PGUpsideDown; break;
86-
case 4: _orientation = PGFlippedVert; break;
87-
case 5: _orientation = PGRotated90CC | PGFlippedHorz; break;
88-
case 6: _orientation = PGRotated270CC; break;
89-
case 7: _orientation = PGRotated90CC | PGFlippedVert; break;
90-
case 8: _orientation = PGRotated90CC; break;
91-
default: _orientation = PGUpright; break;
92-
}
83+
_orientation = PGOrientationWithTIFFOrientation([[properties objectForKey:(NSString *)kCGImagePropertyOrientation] unsignedIntegerValue]);
9384
if(oldOrientation != _orientation) [self invalidateThumbnail];
9485
[_imageProperties release];
9586
_imageProperties = [properties copy];

PGGeometry.h

+2
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,9 @@ extern PGRectEdgeMask PGReadingDirectionAndLocationToRectEdgeMask(PGPageLocation
6060

6161
#pragma mark PGOrientation
6262

63+
extern PGOrientation PGOrientationWithTIFFOrientation(NSUInteger orientation);
6364
extern PGOrientation PGAddOrientation(PGOrientation o1, PGOrientation o2);
65+
extern NSString *PGLocalizedStringWithOrientation(PGOrientation orientation);
6466

6567
#pragma mark PGInset
6668

PGGeometry.m

+29-2
Original file line numberDiff line numberDiff line change
@@ -172,14 +172,41 @@ PGRectEdgeMask PGReadingDirectionAndLocationToRectEdgeMask(PGPageLocation loc, P
172172

173173
#pragma mark PGOrientation
174174

175+
PGOrientation PGOrientationWithTIFFOrientation(NSUInteger orientation)
176+
{
177+
switch(orientation) {
178+
case 2: return PGFlippedHorz;
179+
case 3: return PGUpsideDown;
180+
case 4: return PGFlippedVert;
181+
case 5: return PGRotated90CCW | PGFlippedHorz;
182+
case 6: return PGRotated90CW;
183+
case 7: return PGRotated90CCW | PGFlippedVert;
184+
case 8: return PGRotated90CCW;
185+
default: return PGUpright;
186+
}
187+
}
175188
PGOrientation PGAddOrientation(PGOrientation o1, PGOrientation o2)
176189
{
177190
PGOrientation n1 = o1, n2 = o2;
178-
if(o1 & PGRotated90CC && !(o2 & PGRotated90CC)) n2 = ((o2 & PGFlippedHorz) >> 1) | ((o2 & PGFlippedVert) << 1);
191+
if(o1 & PGRotated90CCW && !(o2 & PGRotated90CCW)) n2 = ((o2 & PGFlippedHorz) >> 1) | ((o2 & PGFlippedVert) << 1);
179192
PGOrientation r = n1 ^ n2;
180-
if(o1 & PGRotated90CC && o2 & PGRotated90CC) r ^= PGUpsideDown;
193+
if(o1 & PGRotated90CCW && o2 & PGRotated90CCW) r ^= PGUpsideDown;
181194
return r;
182195
}
196+
NSString *PGLocalizedStringWithOrientation(PGOrientation orientation)
197+
{
198+
// TODO: Add these to the Localizable.strings files.
199+
switch(orientation) {
200+
case PGFlippedHorz: return NSLocalizedString(@"Flipped Horizontally", nil);
201+
case PGUpsideDown: return NSLocalizedString(@"Upside Down", nil);
202+
case PGFlippedVert: return NSLocalizedString(@"Flipped Vertically", nil);
203+
case PGRotated90CCW | PGFlippedHorz: return NSLocalizedString(@"Rotated CCW & Flipped Horizontally", nil);
204+
case PGRotated90CW: return NSLocalizedString(@"Rotated CW", nil);
205+
case PGRotated90CCW | PGFlippedVert: return NSLocalizedString(@"Rotated CCW & Flipped Vertically", nil);
206+
case PGRotated90CCW: return NSLocalizedString(@"Rotated CCW", nil);
207+
default: return NSLocalizedString(@"Upright", nil);
208+
}
209+
}
183210

184211
#pragma mark PGInset
185212

PGGeometryTypes.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,9 @@ enum {
5353
PGUpright = 0,
5454
PGFlippedVert = 1 << 0,
5555
PGFlippedHorz = 1 << 1,
56-
PGRotated90CC = 1 << 2, // Counter-Clockwise.
56+
PGRotated90CCW = 1 << 2, // Counter-Clockwise.
5757
PGUpsideDown = PGFlippedVert | PGFlippedHorz,
58-
PGRotated270CC = PGFlippedVert | PGFlippedHorz | PGRotated90CC
58+
PGRotated90CW = PGFlippedVert | PGFlippedHorz | PGRotated90CCW
5959
};
6060
typedef NSUInteger PGOrientation;
6161

PGImageView.m

+1-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ - (NSSize)size
9797
}
9898
- (NSSize)originalSize
9999
{
100-
return PGRotated90CC & _orientation ? NSMakeSize([_rep pixelsHigh], [_rep pixelsWide]) : NSMakeSize([_rep pixelsWide], [_rep pixelsHigh]);
100+
return PGRotated90CCW & _orientation ? NSMakeSize([_rep pixelsHigh], [_rep pixelsWide]) : NSMakeSize([_rep pixelsWide], [_rep pixelsHigh]);
101101
}
102102
- (CGFloat)averageScaleFactor
103103
{

PGInspectorPanelController.m

+4-1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434

3535
// Other Sources
3636
#import "PGFoundationAdditions.h"
37+
#import "PGGeometry.h"
3738

3839
@interface NSObject(PGAdditions)
3940

@@ -191,7 +192,6 @@ - (NSDictionary *)_humanReadablePropertiesWithDictionary:(NSDictionary *)dict
191192
// TODO: Create special formatters for certain properties.
192193
// TODO: Automatically resize the first column to fit.
193194
/*
194-
kCGImagePropertyOrientation
195195
kCGImagePropertyExifFNumber (?)
196196
kCGImagePropertyExifExposureProgram (?)
197197
kCGImagePropertyExifISOSpeedRatings (?)
@@ -212,6 +212,9 @@ - (NSDictionary *)_humanReadablePropertiesWithDictionary:(NSDictionary *)dict
212212

213213
if([[dict objectForKey:(NSString *)kCGImagePropertyHasAlpha] boolValue]) [properties setObject:@"Yes" forKey:@"Alpha"];
214214

215+
PGOrientation const orientation = PGOrientationWithTIFFOrientation([[dict objectForKey:(NSString *)kCGImagePropertyOrientation] unsignedIntegerValue]);
216+
if(PGUpright != orientation) [properties setObject:PGLocalizedStringWithOrientation(orientation) forKey:@"Orientation"];
217+
215218
NSDictionary *const TIFFDict = [dict objectForKey:(NSString *)kCGImagePropertyTIFFDictionary];
216219
NSDictionary *const exifDict = [dict objectForKey:(NSString *)kCGImagePropertyExifDictionary];
217220

PGOrientationMenuItemCell.m

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ - (NSImage *)iconForOrientation:(inout PGOrientation *)orientation highlighted:(
5252
*orientation = PGUpright;
5353
return [NSImage imageNamed:flag ? @"Mirror-White" : @"Mirror-Black"];
5454
case PGFlippedVert:
55-
*orientation = PGRotated90CC;
55+
*orientation = PGRotated90CCW;
5656
return [NSImage imageNamed:flag ? @"Mirror-White" : @"Mirror-Black"];
5757
default: return [NSImage imageNamed:flag ? @"Silhouette-White" : @"Silhouette-Black"];
5858
}

PGThumbnailView.m

+1-1
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ - (void)drawRect:(NSRect)aRect
322322
continue;
323323
}
324324
NSSize originalSize = [thumb size];
325-
if(PGRotated90CC & _thumbnailOrientation) originalSize = NSMakeSize(originalSize.height, originalSize.width);
325+
if(PGRotated90CCW & _thumbnailOrientation) originalSize = NSMakeSize(originalSize.height, originalSize.width);
326326
NSRect const frame = [self frameOfItemAtIndex:i withMargin:NO];
327327
NSRect const thumbnailRect = PGIntegralRect(PGCenteredSizeInRect(PGScaleSizeByFloat(originalSize, MIN(1, MIN(NSWidth(frame) / originalSize.width, NSHeight(frame) / originalSize.height))), frame));
328328
BOOL const enabled = [[self dataSource] thumbnailView:self canSelectItem:item];

0 commit comments

Comments
 (0)