Revision: 3857
          http://skim-app.svn.sourceforge.net/skim-app/?rev=3857&view=rev
Author:   hofman
Date:     2008-05-06 15:08:52 -0700 (Tue, 06 May 2008)

Log Message:
-----------
Support for foreground color of text notes. Leopard only.

Modified Paths:
--------------
    trunk/SKMainWindowController.h
    trunk/SKMainWindowController.m
    trunk/SKPDFAnnotationFreeText.h
    trunk/SKPDFAnnotationFreeText.m
    trunk/SKPDFView.m

Modified: trunk/SKMainWindowController.h
===================================================================
--- trunk/SKMainWindowController.h      2008-05-06 21:57:20 UTC (rev 3856)
+++ trunk/SKMainWindowController.h      2008-05-06 22:08:52 UTC (rev 3857)
@@ -222,6 +222,7 @@
     NSButton                    *colorAccessoryView;
     BOOL                        updatingColor;
     BOOL                        updatingFont;
+    BOOL                        updatingFontAttributes;
     BOOL                        updatingLine;
     
     BOOL                        settingUpWindow;

Modified: trunk/SKMainWindowController.m
===================================================================
--- trunk/SKMainWindowController.m      2008-05-06 21:57:20 UTC (rev 3856)
+++ trunk/SKMainWindowController.m      2008-05-06 22:08:52 UTC (rev 3857)
@@ -571,10 +571,17 @@
     PDFAnnotation *annotation = [pdfView activeAnnotation];
     
     if ([[self window] isMainWindow]) {
-        if ([annotation isNote] && [annotation 
respondsToSelector:@selector(font)]) {
-            updatingFont = YES;
-            [[NSFontManager sharedFontManager] 
setSelectedFont:[(PDFAnnotationFreeText *)annotation font] isMultiple:NO];
-            updatingFont = NO;
+        if ([annotation isNote]) {
+            if ([annotation respondsToSelector:@selector(font)]) {
+                updatingFont = YES;
+                [[NSFontManager sharedFontManager] 
setSelectedFont:[(PDFAnnotationFreeText *)annotation font] isMultiple:NO];
+                updatingFont = NO;
+            }
+            if ([annotation respondsToSelector:@selector(fontColor)]) {
+                updatingFontAttributes = YES;
+                [[NSFontManager sharedFontManager] 
setSelectedAttributes:[NSDictionary 
dictionaryWithObjectsAndKeys:[(PDFAnnotationFreeText *)annotation fontColor], 
NSForegroundColorAttributeName, nil] isMultiple:NO];
+                updatingFontAttributes = NO;
+            }
         }
     }
 }
@@ -1231,6 +1238,19 @@
     }
 }
 
+- (IBAction)changeAttributes:(id)sender{
+    PDFAnnotation *annotation = [pdfView activeAnnotation];
+    if (updatingFontAttributes == NO && [annotation isNote] && [annotation 
respondsToSelector:@selector(setFontColor:)] && [annotation 
respondsToSelector:@selector(fontColor)]) {
+        NSColor *color = [(PDFAnnotationFreeText *)annotation fontColor];
+        NSColor *newColor = [[sender convertAttributes:[NSDictionary 
dictionaryWithObjectsAndKeys:color, NSForegroundColorAttributeName, nil]] 
valueForKey:NSForegroundColorAttributeName];
+        if ([newColor isEqual:color] == NO) {
+            updatingFontAttributes = YES;
+            [(PDFAnnotationFreeText *)annotation setFontColor:newColor];
+            updatingFontAttributes = NO;
+        }
+    }
+}
+
 - (void)changeLineWidth:(id)sender {
     PDFAnnotation *annotation = [pdfView activeAnnotation];
     NSString *type = [annotation type];
@@ -3451,6 +3471,11 @@
                     [[NSFontManager sharedFontManager] 
setSelectedFont:[(PDFAnnotationFreeText *)note font] isMultiple:NO];
                     updatingFont = NO;
                 }
+                if (updatingFontAttributes == NO && ([keyPath 
isEqualToString:SKPDFAnnotationFontColorKey])) {
+                    updatingFontAttributes = YES;
+                    [[NSFontManager sharedFontManager] 
setSelectedAttributes:[NSDictionary 
dictionaryWithObjectsAndKeys:[(PDFAnnotationFreeText *)note fontColor], 
NSForegroundColorAttributeName, nil] isMultiple:NO];
+                    updatingFontAttributes = NO;
+                }
                 if (updatingLine == NO && ([keyPath 
isEqualToString:SKPDFAnnotationBorderKey] || [keyPath 
isEqualToString:SKPDFAnnotationStartLineStyleKey] || [keyPath 
isEqualToString:SKPDFAnnotationEndLineStyleKey])) {
                     updatingLine = YES;
                     [[SKLineInspector sharedLineInspector] 
setAnnotationStyle:note];

Modified: trunk/SKPDFAnnotationFreeText.h
===================================================================
--- trunk/SKPDFAnnotationFreeText.h     2008-05-06 21:57:20 UTC (rev 3856)
+++ trunk/SKPDFAnnotationFreeText.h     2008-05-06 22:08:52 UTC (rev 3857)
@@ -40,6 +40,7 @@
 #import <Quartz/Quartz.h>
 
 extern NSString *SKPDFAnnotationFontKey;
+extern NSString *SKPDFAnnotationFontColorKey;
 extern NSString *SKPDFAnnotationFontNameKey;
 extern NSString *SKPDFAnnotationFontSizeKey;
 extern NSString *SKPDFAnnotationRotationKey;

Modified: trunk/SKPDFAnnotationFreeText.m
===================================================================
--- trunk/SKPDFAnnotationFreeText.m     2008-05-06 21:57:20 UTC (rev 3856)
+++ trunk/SKPDFAnnotationFreeText.m     2008-05-06 22:08:52 UTC (rev 3857)
@@ -44,6 +44,7 @@
 #import "NSUserDefaultsController_SKExtensions.h"
 
 NSString *SKPDFAnnotationFontKey = @"font";
+NSString *SKPDFAnnotationFontColorKey = @"fontColor";
 NSString *SKPDFAnnotationFontNameKey = @"fontName";
 NSString *SKPDFAnnotationFontSizeKey = @"fontSize";
 NSString *SKPDFAnnotationRotationKey = @"rotation";
@@ -78,10 +79,14 @@
 - (id)initWithProperties:(NSDictionary *)dict{
     if (self = [super initWithProperties:dict]) {
         Class fontClass = [NSFont class];
+        Class colorClass = [NSColor class];
         NSFont *font = [dict objectForKey:SKPDFAnnotationFontKey];
+        NSColor *fontColor = [dict objectForKey:SKPDFAnnotationFontColorKey];
         NSNumber *rotation = [dict objectForKey:SKPDFAnnotationRotationKey];
         if ([font isKindOfClass:fontClass])
             [self setFont:font];
+        if ([fontColor isKindOfClass:colorClass] && [self 
respondsToSelector:@selector(setFontColor:)])
+            [self setFontColor:fontColor];
         if ([rotation respondsToSelector:@selector(intValue)] && [self 
respondsToSelector:@selector(setRotation:)])
             [self setRotation:[rotation intValue]];
     }
@@ -91,6 +96,8 @@
 - (NSDictionary *)properties{
     NSMutableDictionary *dict = [[[super properties] mutableCopy] autorelease];
     [dict setValue:[self font] forKey:SKPDFAnnotationFontKey];
+    if ([self respondsToSelector:@selector(fontColor)])
+        [dict setValue:[self fontColor] forKey:SKPDFAnnotationFontColorKey];
     if ([self respondsToSelector:@selector(rotation)])
         [dict setValue:[NSNumber numberWithInt:[self rotation]] 
forKey:SKPDFAnnotationRotationKey];
     return dict;
@@ -118,6 +125,7 @@
     if (freeTextKeys == nil) {
         NSMutableSet *mutableKeys = [[super keysForValuesToObserveForUndo] 
mutableCopy];
         [mutableKeys addObject:SKPDFAnnotationFontKey];
+        [mutableKeys addObject:SKPDFAnnotationFontColorKey];
         freeTextKeys = [mutableKeys copy];
         [mutableKeys release];
     }

Modified: trunk/SKPDFView.m
===================================================================
--- trunk/SKPDFView.m   2008-05-06 21:57:20 UTC (rev 3856)
+++ trunk/SKPDFView.m   2008-05-06 22:08:52 UTC (rev 3857)
@@ -1975,12 +1975,14 @@
         NSRect editBounds = [activeAnnotation bounds];
         NSFont *font = [(PDFAnnotationFreeText *)activeAnnotation font];
         NSColor *color = [activeAnnotation color];
+        NSColor *fontColor = [(PDFAnnotationFreeText *)activeAnnotation 
fontColor];
         float alpha = [color alphaComponent];
         if (alpha < 1.0)
             color = [[NSColor controlBackgroundColor] 
blendedColorWithFraction:alpha ofColor:[color colorWithAlphaComponent:1.0]];
         editBounds = [self convertRect:[self convertRect:editBounds 
fromPage:[activeAnnotation page]] toView:[self documentView]];
         editField = [[NSTextField alloc] initWithFrame:editBounds];
         [editField setBackgroundColor:color];
+        [editField setTextColor:fontColor];
         [editField setFont:[[NSFontManager sharedFontManager] convertFont:font 
toSize:[font pointSize] * [self scaleFactor]]];
         [editField setStringValue:[activeAnnotation string]];
         [editField setDelegate:self];


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference 
Don't miss this year's exciting event. There's still time to save $100. 
Use priority code J8TL2D2. 
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
_______________________________________________
Skim-app-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/skim-app-commit

Reply via email to