123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882 |
- //
- // CAnnotStyle.m
- // ComPDFKit_Tools
- //
- // Copyright © 2014-2024 PDF Technologies, Inc. All Rights Reserved.
- //
- // THIS SOURCE CODE AND ANY ACCOMPANYING DOCUMENTATION ARE PROTECTED BY INTERNATIONAL COPYRIGHT LAW
- // AND MAY NOT BE RESOLD OR REDISTRIBUTED. USAGE IS BOUND TO THE ComPDFKit LICENSE AGREEMENT.
- // UNAUTHORIZED REPRODUCTION OR DISTRIBUTION IS SUBJECT TO CIVIL AND CRIMINAL PENALTIES.
- // This notice may not be removed from this file.
- //
- #import "CAnnotStyle.h"
- #import "CPDFListView.h"
- #import "CStringConstants.h"
- #import "CPDFAnnotation+PDFListView.h"
- #import "NSUserDefaults+Utils.h"
- #pragma mark - CAnnotStyle
- @interface CAnnotStyle ()
- @property (nonatomic, strong) NSArray *headKeys;
- @property (nonatomic, strong) NSArray *trialKeys;
- @property (nonatomic, strong) NSArray *annotations;
- @property (nonatomic, assign) CPDFViewAnnotationMode annotMode;
- @property (nonatomic, assign) BOOL isSelectAnnot;
- @end
- @implementation CAnnotStyle
- - (instancetype)initWithAnnotionMode:(CPDFViewAnnotationMode)annotionMode annotations:(NSArray *)annotations {
- if (self = [super init]) {
- if(annotations.count > 0) {
- self.isSelectAnnot = YES;
- self.annotations = annotations;
- self.annotMode = [self convertAnnotationType];
- } else {
- self.isSelectAnnot = NO;
- self.annotMode = annotionMode;
- }
- }
- return self;
- }
- - (CPDFAnnotation *)annotation {
- return self.annotations.firstObject;
- }
- - (CPDFViewAnnotationMode)convertAnnotationType {
- CPDFViewAnnotationMode annotationType = CPDFViewAnnotationModeNone;
- if ([self.annotation isKindOfClass:[CPDFFreeTextAnnotation class]]) {
- annotationType = CPDFViewAnnotationModeFreeText;
- } else if ([self.annotation isKindOfClass:[CPDFTextAnnotation class]]) {
- annotationType = CPDFViewAnnotationModeNote;
- } else if ([self.annotation isKindOfClass:[CPDFCircleAnnotation class]]) {
- annotationType = CPDFViewAnnotationModeCircle;
- } else if ([self.annotation isKindOfClass:[CPDFSquareAnnotation class]]) {
- annotationType = CPDFViewAnnotationModeSquare;
- } else if ([self.annotation isKindOfClass:[CPDFMarkupAnnotation class]]) {
- CPDFMarkupAnnotation *markup = (CPDFMarkupAnnotation *)self.annotation;
- if (CPDFMarkupTypeHighlight == markup.markupType) {
- annotationType = CPDFViewAnnotationModeHighlight;
- } else if (CPDFMarkupTypeStrikeOut == markup.markupType) {
- annotationType = CPDFViewAnnotationModeStrikeout;
- } else if (CPDFMarkupTypeUnderline == markup.markupType) {
- annotationType = CPDFViewAnnotationModeUnderline;
- } else if (CPDFMarkupTypeSquiggly == markup.markupType) {
- annotationType = CPDFViewAnnotationModeSquiggly;
- }
- } else if ([self.annotation isKindOfClass:[CPDFLineAnnotation class]]) {
- CPDFLineAnnotation *line = (CPDFLineAnnotation *)self.annotation;
- if (CPDFLineStyleNone == line.endLineStyle && CPDFLineStyleNone == line.startLineStyle) {
- annotationType = CPDFViewAnnotationModeLine;
- } else {
- annotationType = CPDFViewAnnotationModeArrow;
- }
- } else if ([self.annotation isKindOfClass:[CPDFInkAnnotation class]]) {
- annotationType = CPDFViewAnnotationModeInk;
- } else if ([self.annotation isKindOfClass:[CPDFLinkAnnotation class]]) {
- annotationType = CPDFViewAnnotationModeLink;
- } else if ([self.annotation isKindOfClass:[CPDFSignatureAnnotation class]]) {
- annotationType = CPDFViewAnnotationModeSignature;
- } else if ([self.annotation isKindOfClass:[CPDFStampAnnotation class]]) {
- annotationType = CPDFViewAnnotationModeStamp;
- } else if ([self.annotation isKindOfClass:[CPDFSoundAnnotation class]]) {
- annotationType = CPDFViewAnnotationModeSound;
- }else if([self.annotation isKindOfClass:[CPDFTextWidgetAnnotation class]]){
- annotationType = CPDFViewFormModeText;
- }else if([self.annotation isKindOfClass:[CPDFButtonWidgetAnnotation class]]) {
- CPDFButtonWidgetAnnotation * annotation = (CPDFButtonWidgetAnnotation*)self.annotation;
- if(annotation.controlType == CPDFWidgetCheckBoxControl) {
- annotationType = CPDFViewFormModeCheckBox;
- }else if(annotation.controlType == CPDFWidgetRadioButtonControl) {
- annotationType = CPDFViewFormModeRadioButton;
- }else if(annotation.controlType == CPDFWidgetPushButtonControl) {
- annotationType = CPDFViewFormModeButton;
- }
- }else if([self.annotation isKindOfClass:[CPDFChoiceWidgetAnnotation class]]){
- CPDFChoiceWidgetAnnotation * annotation = (CPDFChoiceWidgetAnnotation*)self.annotation;
- if(annotation.isListChoice){
- annotationType = CPDFViewFormModeList;
- }else {
- annotationType = CPDFViewFormModeCombox;
- }
- }
- return annotationType;
- }
- #pragma mark - Common
- - (UIColor *)color {
- UIColor *color = nil;
- if (self.isSelectAnnot) {
- color = [self annotation].color;
- } else {
- NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
- switch (_annotMode) {
- case CPDFViewAnnotationModeNote:
- color = [userDefaults PDFListViewColorForKey:CAnchoredNoteColorKey];
- break;
- case CPDFViewAnnotationModeCircle:
- color = [userDefaults PDFListViewColorForKey:CCircleNoteColorKey];
- break;
- case CPDFViewAnnotationModeSquare:
- color = [userDefaults PDFListViewColorForKey:CSquareNoteColorKey];
- break;
- case CPDFViewAnnotationModeHighlight:
- color = [userDefaults PDFListViewColorForKey:CHighlightNoteColorKey];
- break;
- case CPDFViewAnnotationModeUnderline:
- color = [userDefaults PDFListViewColorForKey:CUnderlineNoteColorKey];
- break;
- case CPDFViewAnnotationModeStrikeout:
- color = [userDefaults PDFListViewColorForKey:CStrikeOutNoteColorKey];
- break;
- case CPDFViewAnnotationModeSquiggly:
- color = [userDefaults PDFListViewColorForKey:CSquigglyNoteColorKey];
- break;
- case CPDFViewAnnotationModeLine:
- color = [userDefaults PDFListViewColorForKey:CLineNoteColorKey];
- break;
- case CPDFViewAnnotationModeArrow:
- color = [userDefaults PDFListViewColorForKey:CArrowNoteColorKey];
- break;
- case CPDFViewAnnotationModeInk:
- color = [CPDFKitConfig sharedInstance].freehandAnnotationColor;
- break;
- default:
- break;
- }
- }
- return color;
- }
- - (void)setColor:(UIColor *)color {
- if (self.isSelectAnnot) {
- for (CPDFAnnotation *annotation in self.annotations) {
- annotation.color = color;
- }
- } else {
- NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
- switch (self.annotMode) {
- case CPDFViewAnnotationModeNote:
- [userDefaults setPDFListViewColor:color forKey:CAnchoredNoteColorKey];
- break;
- case CPDFViewAnnotationModeCircle:
- [userDefaults setPDFListViewColor:color forKey:CCircleNoteColorKey];
- break;
- case CPDFViewAnnotationModeSquare:
- [userDefaults setPDFListViewColor:color forKey:CSquareNoteColorKey];
- break;
- case CPDFViewAnnotationModeHighlight:
- [userDefaults setPDFListViewColor:color forKey:CHighlightNoteColorKey];
- break;
- case CPDFViewAnnotationModeUnderline:
- [userDefaults setPDFListViewColor:color forKey:CUnderlineNoteColorKey];
- break;
- case CPDFViewAnnotationModeStrikeout:
- [userDefaults setPDFListViewColor:color forKey:CStrikeOutNoteColorKey];
- break;
- case CPDFViewAnnotationModeSquiggly:
- [userDefaults setPDFListViewColor:color forKey:CSquigglyNoteColorKey];
- break;
- case CPDFViewAnnotationModeLine:
- [userDefaults setPDFListViewColor:color forKey:CLineNoteColorKey];
- break;
- case CPDFViewAnnotationModeArrow:
- [userDefaults setPDFListViewColor:color forKey:CArrowNoteColorKey];
- break;
- case CPDFViewAnnotationModeInk:
- [[CPDFKitConfig sharedInstance] setFreehandAnnotationColor:color];
- [userDefaults setPDFListViewColor:color forKey:CInkNoteColorKey];
- break;
- default:
- break;
- }
- [userDefaults synchronize];
- }
- }
- - (CGFloat)opacity {
- CGFloat opacity = 0;
- if (self.isSelectAnnot) {
- opacity = self.annotation.opacity;
- } else {
- NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
- switch (self.annotMode) {
- case CPDFViewAnnotationModeFreeText:
- opacity = [userDefaults floatForKey:CFreeTextNoteOpacityKey];
- break;
- case CPDFViewAnnotationModeNote:
- opacity = [userDefaults floatForKey:CAnchoredNoteOpacityKey];
- break;
- case CPDFViewAnnotationModeCircle:
- opacity = [userDefaults floatForKey:CCircleNoteOpacityKey];
- break;
- case CPDFViewAnnotationModeSquare:
- opacity = [userDefaults floatForKey:CSquareNoteOpacityKey];
- break;
- case CPDFViewAnnotationModeHighlight:
- opacity = [userDefaults floatForKey:CHighlightNoteOpacityKey];
- break;
- case CPDFViewAnnotationModeUnderline:
- opacity = [userDefaults floatForKey:CUnderlineNoteOpacityKey];
- break;
- case CPDFViewAnnotationModeStrikeout:
- opacity = [userDefaults floatForKey:CStrikeOutNoteOpacityKey];
- break;
- case CPDFViewAnnotationModeSquiggly:
- opacity = [userDefaults floatForKey:CSquigglyNoteOpacityKey];
- break;
- case CPDFViewAnnotationModeLine:
- opacity = [userDefaults floatForKey:CLineNoteOpacityKey];
- break;
- case CPDFViewAnnotationModeArrow:
- opacity = [userDefaults floatForKey:CArrowNoteOpacityKey];
- break;
- case CPDFViewAnnotationModeInk:
- opacity = [CPDFKitConfig sharedInstance].freehandAnnotationOpacity;
- opacity/=100;
- break;
- default:
- break;
- }
- }
- return opacity;
- }
- - (void)setOpacity:(CGFloat)opacity {
- if (self.isSelectAnnot) {
- for (CPDFAnnotation *annotation in self.annotations) {
- [annotation setOpacity:opacity];
- }
- } else {
- NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
- switch (self.annotMode) {
- case CPDFViewAnnotationModeFreeText:
- [userDefaults setFloat:opacity forKey:CFreeTextNoteOpacityKey];
- break;
- case CPDFViewAnnotationModeNote:
- [userDefaults setFloat:opacity forKey:CAnchoredNoteOpacityKey];
- break;
- case CPDFViewAnnotationModeCircle:
- [userDefaults setFloat:opacity forKey:CCircleNoteOpacityKey];
- break;
- case CPDFViewAnnotationModeSquare:
- [userDefaults setFloat:opacity forKey:CSquareNoteOpacityKey];
- break;
- case CPDFViewAnnotationModeHighlight:
- [userDefaults setFloat:opacity forKey:CHighlightNoteOpacityKey];
- break;
- case CPDFViewAnnotationModeUnderline:
- [userDefaults setFloat:opacity forKey:CUnderlineNoteOpacityKey];
- break;
- case CPDFViewAnnotationModeStrikeout:
- [userDefaults setFloat:opacity forKey:CStrikeOutNoteOpacityKey];
- break;
- case CPDFViewAnnotationModeSquiggly:
- [userDefaults setFloat:opacity forKey:CSquigglyNoteOpacityKey];
- break;
- case CPDFViewAnnotationModeLine:
- [userDefaults setFloat:opacity forKey:CLineNoteOpacityKey];
- break;
- case CPDFViewAnnotationModeArrow:
- [userDefaults setFloat:opacity forKey:CArrowNoteOpacityKey];
- break;
- case CPDFViewAnnotationModeInk:
- [[CPDFKitConfig sharedInstance] setFreehandAnnotationOpacity:opacity * 100];
- [userDefaults setFloat:opacity forKey:CInkNoteOpacityKey];
- break;
- default:
- break;
- }
- [userDefaults synchronize];
- }
- }
- - (CPDFBorderStyle)style {
- CPDFBorderStyle style = CPDFBorderStyleSolid;
- if (self.isSelectAnnot) {
- style = self.annotation.borderStyle;
- } else {
- NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
- switch (self.annotMode) {
- case CPDFViewAnnotationModeFreeText:
- style = [userDefaults integerForKey:CFreeTextNoteLineStyleKey];
- break;
- case CPDFViewAnnotationModeCircle:
- style = [userDefaults integerForKey:CCircleNoteLineStyleKey];
- break;
- case CPDFViewAnnotationModeSquare:
- style = [userDefaults integerForKey:CSquareNoteLineStyleKey];
- break;
- case CPDFViewAnnotationModeLine:
- style = [userDefaults integerForKey:CLineNoteLineStyleKey];
- break;
- case CPDFViewAnnotationModeArrow:
- style = [userDefaults integerForKey:CArrowNoteLineStyleKey];
- break;
- case CPDFViewAnnotationModeInk:
- style = [userDefaults integerForKey:CInkNoteLineStyleyKey];
- break;
- default:
- break;
- }
- }
- return style;
- }
- - (void)setStyle:(CPDFBorderStyle)style {
- if (self.isSelectAnnot) {
- for (CPDFAnnotation *annotation in self.annotations) {
- [annotation setBorderStyle:style];
- }
- } else {
- NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
- switch (self.annotMode) {
- case CPDFViewAnnotationModeFreeText:
- [userDefaults setInteger:style forKey:CFreeTextNoteLineStyleKey];
- break;
- case CPDFViewAnnotationModeCircle:
- [userDefaults setInteger:style forKey:CCircleNoteLineStyleKey];
- break;
- case CPDFViewAnnotationModeSquare:
- [userDefaults setInteger:style forKey:CSquareNoteLineStyleKey];
- break;
- case CPDFViewAnnotationModeLine:
- [userDefaults setInteger:style forKey:CLineNoteLineStyleKey];
- break;
- case CPDFViewAnnotationModeArrow:
- [userDefaults setInteger:style forKey:CArrowNoteLineStyleKey];
- break;
- case CPDFViewAnnotationModeInk:
- [userDefaults setInteger:style forKey:CInkNoteLineStyleyKey];
- break;
- default:
- break;
- }
- [userDefaults synchronize];
- }
- }
- - (NSArray *)dashPattern {
- if (self.isSelectAnnot) {
- if(CPDFBorderStyleDashed == self.annotation.border.style) {
- return self.annotation.dashPattern;
- } else {
- return 0;
- }
- } else {
- NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
- NSInteger dashPattern = 0;
- switch (self.annotMode) {
- case CPDFViewAnnotationModeFreeText:
- dashPattern = [userDefaults integerForKey:CFreeTextNoteDashPatternKey];
- break;
- case CPDFViewAnnotationModeCircle:
- dashPattern = [userDefaults integerForKey:CCircleNoteDashPatternKey];
- break;
- case CPDFViewAnnotationModeSquare:
- dashPattern = [userDefaults integerForKey:CSquareNoteDashPatternKey];
- break;
- case CPDFViewAnnotationModeLine:
- dashPattern = [userDefaults integerForKey:CLineNoteDashPatternKey];
- break;
- case CPDFViewAnnotationModeArrow:
- dashPattern = [userDefaults integerForKey:CArrowNoteDashPatternKey];
- break;
- case CPDFViewAnnotationModeInk:
- dashPattern = [userDefaults integerForKey:CInkNoteDashPatternKey];
- break;
- default:
- break;
- }
- if(CPDFBorderStyleDashed != self.style) {
- dashPattern= 0;
- }
- return @[@(dashPattern)];
- }
- }
- - (void)setDashPattern:(NSArray *)dashPatterns {
- if (self.isSelectAnnot) {
- for (CPDFAnnotation *annotation in self.annotations) {
- [annotation setDashPattern:dashPatterns];
- }
- } else {
- NSInteger dashPattern = [dashPatterns.firstObject integerValue];
- NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
- switch (self.annotMode) {
- case CPDFViewAnnotationModeFreeText:
- [userDefaults setInteger:dashPattern forKey:CFreeTextNoteDashPatternKey];
- break;
- case CPDFViewAnnotationModeCircle:
- [userDefaults setInteger:dashPattern forKey:CCircleNoteDashPatternKey];
- break;
- case CPDFViewAnnotationModeSquare:
- [userDefaults setInteger:dashPattern forKey:CSquareNoteDashPatternKey];
- break;
- case CPDFViewAnnotationModeLine:
- [userDefaults setInteger:dashPattern forKey:CLineNoteDashPatternKey];
- break;
- case CPDFViewAnnotationModeArrow:
- [userDefaults setInteger:dashPattern forKey:CArrowNoteDashPatternKey];
- break;
- case CPDFViewAnnotationModeInk:
- [userDefaults setInteger:dashPattern forKey:CInkNoteDashPatternKey];
- break;
- default:
- break;
- }
- [userDefaults synchronize];
- }
- }
- - (CGFloat)lineWidth {
- CGFloat lineWidth = 0;
- if (self.isSelectAnnot) {
- lineWidth = self.annotation.lineWidth;
- } else {
- NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
- switch (self.annotMode) {
- case CPDFViewAnnotationModeCircle:
- lineWidth = [userDefaults floatForKey:CCircleNoteLineWidthKey];
- break;
- case CPDFViewAnnotationModeSquare:
- lineWidth = [userDefaults floatForKey:CSquareNoteLineWidthKey];
- break;
- case CPDFViewAnnotationModeLine:
- lineWidth = [userDefaults floatForKey:CLineNoteLineWidthKey];
- break;
- case CPDFViewAnnotationModeArrow:
- lineWidth = [userDefaults floatForKey:CArrowNoteLineWidthKey];
- break;
- case CPDFViewAnnotationModeInk:
- lineWidth = [CPDFKitConfig sharedInstance].freehandAnnotationBorderWidth;
- break;
- default:
- break;
- }
- }
- return lineWidth;
- }
- - (void)setLineWidth:(CGFloat)lineWidth {
- if (self.isSelectAnnot) {
- for (CPDFAnnotation *annotation in self.annotations) {
- [annotation setBorderWidth:lineWidth];
- }
- } else {
- NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
- switch (self.annotMode) {
- case CPDFViewAnnotationModeCircle:
- [userDefaults setFloat:lineWidth forKey:CCircleNoteLineWidthKey];
- break;
- case CPDFViewAnnotationModeSquare:
- [userDefaults setFloat:lineWidth forKey:CSquareNoteLineWidthKey];
- break;
- case CPDFViewAnnotationModeLine:
- [userDefaults setFloat:lineWidth forKey:CLineNoteLineWidthKey];
- break;
- case CPDFViewAnnotationModeArrow:
- [userDefaults setFloat:lineWidth forKey:CArrowNoteLineWidthKey];
- break;
- case CPDFViewAnnotationModeInk:
- [[CPDFKitConfig sharedInstance] setFreehandAnnotationBorderWidth:lineWidth];
- [userDefaults setFloat:lineWidth forKey:CInkNoteLineWidthKey];
- break;
- default:
- break;
- }
- [userDefaults synchronize];
- }
- }
- - (CPDFLineStyle)startLineStyle {
- CPDFLineStyle startLineStyle = CPDFLineStyleNone;
- if (self.isSelectAnnot) {
- if ([self.annotation isKindOfClass:[CPDFLineAnnotation class]]) {
- startLineStyle = [(CPDFLineAnnotation *)self.annotation startLineStyle];
- }
- } else {
- NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
- switch (self.annotMode) {
- case CPDFViewAnnotationModeArrow:
- startLineStyle = [userDefaults integerForKey:CArrowNoteStartStyleKey];
- break;
- case CPDFViewAnnotationModeLine:
- startLineStyle = [userDefaults integerForKey:CLineNoteStartStyleKey];
- break;
- default:
- break;
- }
- }
- return startLineStyle;
- }
- - (void)setStartLineStyle:(CPDFLineStyle)startLineStyle {
- if(self.isSelectAnnot) {
- for (CPDFAnnotation *annotation in self.annotations) {
- if([annotation isKindOfClass:[CPDFLineAnnotation class]]){
- [(CPDFLineAnnotation*)annotation setStartLineStyle:startLineStyle];
- }
- }
- } else {
- NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
- switch (self.annotMode) {
- case CPDFViewAnnotationModeArrow:
- [userDefaults setInteger:startLineStyle forKey:CArrowNoteStartStyleKey];
- break;
- case CPDFViewAnnotationModeLine:
- [userDefaults setInteger:startLineStyle forKey:CLineNoteStartStyleKey];
- break;
- default:
- break;
- }
- [userDefaults synchronize];
- }
- }
- - (CPDFLineStyle)endLineStyle {
- CPDFLineStyle endLineStyle = CPDFLineStyleNone;
- if(self.isSelectAnnot) {
- if ([self.annotation isKindOfClass:[CPDFLineAnnotation class]]) {
- endLineStyle = [(CPDFLineAnnotation *)self.annotation endLineStyle];
- }
- } else {
- NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
- switch (self.annotMode) {
- case CPDFViewAnnotationModeArrow:
- endLineStyle = [userDefaults integerForKey:CArrowNoteEndStyleKey];
- break;
- case CPDFViewAnnotationModeLine:
- endLineStyle = [userDefaults integerForKey:CLineNoteEndStyleKey];
- break;
- default:
- break;
- }
- }
- return endLineStyle;
- }
- -(void)setEndLineStyle:(CPDFLineStyle)endLineStyle {
- if(self.isSelectAnnot) {
- for (CPDFAnnotation *annotation in self.annotations) {
- if([annotation isKindOfClass:[CPDFLineAnnotation class]]){
- [(CPDFLineAnnotation*)annotation setEndLineStyle:endLineStyle];
- }
- }
- } else {
- NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
- switch (self.annotMode) {
- case CPDFViewAnnotationModeArrow:
- [userDefaults setInteger:endLineStyle forKey:CArrowNoteEndStyleKey];
- break;
- case CPDFViewAnnotationModeLine:
- [userDefaults setInteger:endLineStyle forKey:CLineNoteEndStyleKey];
- break;
- default:
- break;
- }
- [userDefaults synchronize];
- }
- }
- #pragma mark - FreeText
- - (UIColor *)fontColor {
- UIColor *color = nil;
- if (self.isSelectAnnot) {
- if([self.annotation isKindOfClass:[CPDFFreeTextAnnotation class]]) {
- color = [(CPDFFreeTextAnnotation *)self.annotation fontColor];
- }
- } else {
- NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
- switch (self.annotMode) {
- case CPDFViewAnnotationModeFreeText:
- color = [userDefaults PDFListViewColorForKey:CFreeTextNoteFontColorKey];
- break;
- default:
- break;
- }
- }
- return color;
- }
- - (void)setFontColor:(UIColor *)fontColor {
- if (self.isSelectAnnot) {
- for (CPDFAnnotation *annotation in self.annotations) {
- if ([annotation isKindOfClass:[CPDFFreeTextAnnotation class]]) {
- CGFloat red,green,blue,alpha;
- [fontColor getRed:&red green:&green blue:&blue alpha:&alpha];
- [(CPDFFreeTextAnnotation *)annotation setFontColor:[UIColor colorWithRed:red green:green blue:blue alpha:self.opacity]];
- }
- }
- } else {
- NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
- switch (self.annotMode) {
- case CPDFViewAnnotationModeFreeText:
- [userDefaults setPDFListViewColor:fontColor forKey:CFreeTextNoteFontColorKey];
- break;
- default:
- break;
- }
- [userDefaults synchronize];
- }
- }
- - (CGFloat)fontSize {
- CGFloat fontSize = 11;
- if (self.isSelectAnnot) {
- if ([self.annotation isKindOfClass:[CPDFFreeTextAnnotation class]]) {
- fontSize = [(CPDFFreeTextAnnotation *)self.annotation font].pointSize;
- }
- } else {
- NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
- switch (self.annotMode) {
- case CPDFViewAnnotationModeFreeText:
- fontSize = [userDefaults floatForKey:CFreeTextNoteFontSizeKey];
- break;
- default:
- break;
- }
- }
- return fontSize;
- }
- - (void)setFontSize:(CGFloat)fontSize {
- if (self.isSelectAnnot) {
- for (CPDFAnnotation *annotation in self.annotations) {
- if ([annotation isKindOfClass:[CPDFFreeTextAnnotation class]]) {
- CPDFFreeTextAnnotation *freeText = (CPDFFreeTextAnnotation *)annotation;
- UIFont *font = [(CPDFFreeTextAnnotation *)annotation font];
- [(CPDFFreeTextAnnotation *)annotation setFont:[UIFont fontWithName:font.fontName size:fontSize]];
-
- NSDictionary *attributes = @{NSFontAttributeName : freeText.font};
- CGRect bounds = annotation.bounds;
- CGRect rect = [freeText.contents boundingRectWithSize:CGSizeMake(bounds.size.width, CGFLOAT_MAX)
- options:NSStringDrawingUsesLineFragmentOrigin
- attributes:attributes
- context:nil];
- rect.size.height += 6;
- bounds.origin.y = CGRectGetMaxY(bounds) - rect.size.height;
- bounds.size.height = rect.size.height;
- //
- annotation.bounds = bounds;
- }
- }
- } else {
- NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
- switch (self.annotMode) {
- case CPDFViewAnnotationModeFreeText:
- [userDefaults setFloat:fontSize forKey:CFreeTextNoteFontSizeKey];
- break;
- default:
- break;
- }
- [userDefaults synchronize];
- }
- }
- - (NSString *)fontName {
- NSString *fontName = nil;
- if (self.isSelectAnnot) {
- if ([self.annotation isKindOfClass:[CPDFFreeTextAnnotation class]]) {
- fontName = [(CPDFFreeTextAnnotation *)self.annotation font].fontName;
- }
- } else {
- NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
- switch (self.annotMode) {
- case CPDFViewAnnotationModeFreeText:
- fontName = [userDefaults objectForKey:CFreeTextNoteFontNameKey];
- break;
- default:
- break;
- }
- }
- return fontName;
- }
- - (void)setFontName:(NSString *)fontName {
- if (self.isSelectAnnot) {
- for (CPDFAnnotation *annotation in self.annotations) {
- if ([annotation isKindOfClass:[CPDFFreeTextAnnotation class]]) {
- UIFont *font = [(CPDFFreeTextAnnotation *)annotation font];
- [(CPDFFreeTextAnnotation *)annotation setFont:[UIFont fontWithName:fontName size:font.pointSize]];
- }
- }
- } else {
- NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
- switch (self.annotMode) {
- case CPDFViewAnnotationModeFreeText:
- [userDefaults setObject:fontName forKey:CFreeTextNoteFontNameKey];
- break;
- default:
- break;
- }
- [userDefaults synchronize];
- }
- }
- - (NSTextAlignment)alignment {
- NSTextAlignment alignment = NSTextAlignmentLeft;
- if (self.isSelectAnnot) {
- if ([self.annotation isKindOfClass:[CPDFFreeTextAnnotation class]]) {
- alignment = [(CPDFFreeTextAnnotation *)self.annotation alignment];
- }
- } else {
- NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
- switch (self.annotMode) {
- case CPDFViewAnnotationModeFreeText:
- alignment = [userDefaults integerForKey:CFreeTextNoteAlignmentKey];
- break;
- default:
- break;
- }
- }
- return alignment;
- }
- - (void)setAlignment:(NSTextAlignment)alignment {
- if (self.isSelectAnnot){
- for (CPDFAnnotation *annotation in self.annotations) {
- if ([annotation isKindOfClass:[CPDFFreeTextAnnotation class]]) {
- [(CPDFFreeTextAnnotation *)annotation setAlignment:alignment];
- }
- }
- } else {
- NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
- switch (self.annotMode) {
- case CPDFViewAnnotationModeFreeText:
- [userDefaults setInteger:alignment forKey:CFreeTextNoteAlignmentKey];
- break;
- default:
- break;
- }
- [userDefaults synchronize];
- }
- }
- #pragma mark - Circle&Square
- - (UIColor *)interiorColor {
- UIColor *interiorColor = nil;
- if (self.isSelectAnnot) {
- if([self.annotation isKindOfClass:[CPDFCircleAnnotation class]] ||
- [self.annotation isKindOfClass:[CPDFSquareAnnotation class]]) {
- interiorColor = [(CPDFCircleAnnotation *)self.annotation interiorColor];
- } else if ([self.annotation isKindOfClass:[CPDFFreeTextAnnotation class]]) {
- interiorColor = [(CPDFFreeTextAnnotation *)self.annotation color];
- }
- } else {
- NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
- switch (self.annotMode) {
- case CPDFViewAnnotationModeCircle:
- interiorColor = [userDefaults PDFListViewColorForKey:CCircleNoteInteriorColorKey];
- break;
- case CPDFViewAnnotationModeSquare:
- interiorColor = [userDefaults PDFListViewColorForKey:CSquareNoteInteriorColorKey];
- break;
- default:
- break;
- }
- }
- return interiorColor;
- }
- - (void)setInteriorColor:(UIColor *)interiorColor {
- if (self.isSelectAnnot){
- for (CPDFAnnotation *annotation in self.annotations) {
- if ([annotation isKindOfClass:[CPDFCircleAnnotation class]] ||
- [annotation isKindOfClass:[CPDFSquareAnnotation class]]) {
- [(CPDFCircleAnnotation *)annotation setInteriorColor:interiorColor];
- } else if ([annotation isKindOfClass:[CPDFFreeTextAnnotation class]]) {
- [(CPDFFreeTextAnnotation *)annotation setColor:interiorColor];
- }
- }
- } else {
- NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
- switch (self.annotMode) {
- case CPDFViewAnnotationModeCircle:
- [userDefaults setPDFListViewColor:interiorColor forKey:CCircleNoteInteriorColorKey];
- break;
- case CPDFViewAnnotationModeSquare:
- [userDefaults setPDFListViewColor:interiorColor forKey:CSquareNoteInteriorColorKey];
- break;
- default:
- break;
- }
- }
- }
- - (CGFloat)interiorOpacity {
- CGFloat opacity = 0;
- if (self.isSelectAnnot) {
- if([self.annotation isKindOfClass:[CPDFCircleAnnotation class]] ||
- [self.annotation isKindOfClass:[CPDFSquareAnnotation class]]) {
- opacity = [(CPDFCircleAnnotation *)self.annotation interiorOpacity];
- } else {
- opacity = [self.annotation opacity];
- }
- } else {
- NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
- switch (self.annotMode) {
- case CPDFViewAnnotationModeCircle:
- opacity = [userDefaults floatForKey:CCircleNoteInteriorOpacityKey];
- break;
- case CPDFViewAnnotationModeSquare:
- opacity = [userDefaults floatForKey:CSquareNoteInteriorOpacityKey];
- break;
- default:
- break;
- }
- }
- return opacity;
- }
- - (void)setInteriorOpacity:(CGFloat)interiorOpacity {
- if (self.isSelectAnnot) {
- for (CPDFAnnotation *annotation in self.annotations) {
- if ([annotation isKindOfClass:[CPDFCircleAnnotation class]] ||
- [annotation isKindOfClass:[CPDFSquareAnnotation class]]) {
- [(CPDFCircleAnnotation *)annotation setInteriorOpacity:interiorOpacity];
- } else {
- [(CPDFCircleAnnotation *)annotation setOpacity:interiorOpacity];
- }
- }
- } else {
- NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
- switch (self.annotMode) {
- case CPDFViewAnnotationModeCircle:
- [userDefaults setFloat:interiorOpacity forKey:CCircleNoteInteriorOpacityKey];
- break;
- case CPDFViewAnnotationModeSquare:
- [userDefaults setFloat:interiorOpacity forKey:CSquareNoteInteriorOpacityKey];
- break;
- default:
- break;
- }
- [userDefaults synchronize];
- }
- }
- @end
|