CAnnotationManage.m 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. //
  2. // CAnnotationManage.m
  3. // ComPDFKit_Tools
  4. //
  5. // Copyright © 2014-2024 PDF Technologies, Inc. All Rights Reserved.
  6. //
  7. // THIS SOURCE CODE AND ANY ACCOMPANYING DOCUMENTATION ARE PROTECTED BY INTERNATIONAL COPYRIGHT LAW
  8. // AND MAY NOT BE RESOLD OR REDISTRIBUTED. USAGE IS BOUND TO THE ComPDFKit LICENSE AGREEMENT.
  9. // UNAUTHORIZED REPRODUCTION OR DISTRIBUTION IS SUBJECT TO CIVIL AND CRIMINAL PENALTIES.
  10. // This notice may not be removed from this file.
  11. //
  12. #import "CAnnotationManage.h"
  13. #import "CPDFListView.h"
  14. #import "CAnnotStyle.h"
  15. #import <ComPDFKit/ComPDFKit.h>
  16. @interface CAnnotationManage ()
  17. @property (nonatomic, strong) CPDFListView *pdfListView;
  18. @property (nonatomic, strong) CPDFAnnotation *annotation;
  19. @property (nonatomic, strong) CAnnotStyle *annotStyle;
  20. @end
  21. @implementation CAnnotationManage
  22. - (instancetype)initWithPDFView:(CPDFListView *)pdfListView {
  23. if (self = [super init]) {
  24. self.pdfListView = pdfListView;
  25. }
  26. return self;
  27. }
  28. #pragma mark - Publice Methods
  29. - (void)setAnnotStyleFromAnnotations:(NSArray<CPDFAnnotation *> *)annotations {
  30. self.annotStyle = [[CAnnotStyle alloc] initWithAnnotionMode:CPDFViewAnnotationModeNone annotations:annotations];
  31. }
  32. - (void)refreshPageWithAnnotations:(NSArray *)annotations {
  33. NSMutableArray *pages = [NSMutableArray array];
  34. for (CPDFAnnotation * annotation in annotations) {
  35. CPDFPage *page = annotation.page;
  36. if(![pages containsObject:page]) {
  37. [pages addObject:page];
  38. }
  39. }
  40. for (CPDFPage *page in pages) {
  41. [self.pdfListView setNeedsDisplayForPage:page];
  42. }
  43. }
  44. - (void)setAnnotStyleFromMode:(CPDFViewAnnotationMode)annotationMode {
  45. self.annotStyle = [[CAnnotStyle alloc] initWithAnnotionMode:annotationMode annotations:@[]];
  46. }
  47. + (CPDFKitPlatformColor *)highlightAnnotationColor {
  48. CPDFKitPlatformColor *highlightAnnotationColor = nil;
  49. CAnnotStyle *annotStyle = [[CAnnotStyle alloc] initWithAnnotionMode:CPDFViewAnnotationModeHighlight annotations:@[]];
  50. CGFloat red, green, blue, alpha;
  51. [annotStyle.color getRed:&red green:&green blue:&blue alpha:&alpha];
  52. highlightAnnotationColor = [CPDFKitPlatformColor colorWithRed:red green:green blue:blue alpha:annotStyle.opacity];
  53. return highlightAnnotationColor;
  54. }
  55. + (CPDFKitPlatformColor *)underlineAnnotationColor {
  56. CPDFKitPlatformColor *underlineAnnotationColor = nil;
  57. CAnnotStyle *annotStyle = [[CAnnotStyle alloc] initWithAnnotionMode:CPDFViewAnnotationModeUnderline annotations:@[]];
  58. CGFloat red, green, blue, alpha;
  59. [annotStyle.color getRed:&red green:&green blue:&blue alpha:&alpha];
  60. underlineAnnotationColor = [CPDFKitPlatformColor colorWithRed:red green:green blue:blue alpha:annotStyle.opacity];
  61. return underlineAnnotationColor;
  62. }
  63. + (CPDFKitPlatformColor *)strikeoutAnnotationColor {
  64. CPDFKitPlatformColor *strikeoutAnnotationColor = nil;
  65. CAnnotStyle *annotStyle = [[CAnnotStyle alloc] initWithAnnotionMode:CPDFViewAnnotationModeStrikeout annotations:@[]];
  66. CGFloat red, green, blue, alpha;
  67. [annotStyle.color getRed:&red green:&green blue:&blue alpha:&alpha];
  68. strikeoutAnnotationColor = [CPDFKitPlatformColor colorWithRed:red green:green blue:blue alpha:annotStyle.opacity];
  69. return strikeoutAnnotationColor;
  70. }
  71. + (CPDFKitPlatformColor *)squigglyAnnotationColor {
  72. CPDFKitPlatformColor *squigglyAnnotationColor = nil;
  73. CAnnotStyle *annotStyle = [[CAnnotStyle alloc] initWithAnnotionMode:CPDFViewAnnotationModeSquiggly annotations:@[]];
  74. CGFloat red, green, blue, alpha;
  75. [annotStyle.color getRed:&red green:&green blue:&blue alpha:&alpha];
  76. squigglyAnnotationColor = [CPDFKitPlatformColor colorWithRed:red green:green blue:blue alpha:annotStyle.opacity];
  77. return squigglyAnnotationColor;
  78. }
  79. + (CPDFKitPlatformColor *)freehandAnnotationColor {
  80. CPDFKitPlatformColor *freehandAnnotationColor = nil;
  81. CAnnotStyle *annotStyle = [[CAnnotStyle alloc] initWithAnnotionMode:CPDFViewAnnotationModeInk annotations:@[]];
  82. CGFloat red, green, blue, alpha;
  83. [annotStyle.color getRed:&red green:&green blue:&blue alpha:&alpha];
  84. freehandAnnotationColor = [CPDFKitPlatformColor colorWithRed:red green:green blue:blue alpha:annotStyle.opacity];
  85. return freehandAnnotationColor;
  86. }
  87. @end