CPDFAnnotationBarButton.m 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. //
  2. // CPDFAnnotationBarButton.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 "CPDFAnnotationBarButton.h"
  13. #import "CPDFListView.h"
  14. @implementation CPDFAnnotationBarButton
  15. - (void)drawRect:(CGRect)rect {
  16. [super drawRect:rect];
  17. CGRect imageFrame = self.imageView.frame;
  18. CGContextRef ctx = UIGraphicsGetCurrentContext();
  19. CGContextSetStrokeColorWithColor(ctx, self.lineColor.CGColor);
  20. if (self.tag == CPDFViewAnnotationModeHighlight) {
  21. CGContextMoveToPoint(ctx, CGRectGetMinX(imageFrame)-2, CGRectGetMidY(imageFrame));
  22. CGContextSetLineWidth(ctx, CGRectGetHeight(imageFrame));
  23. CGContextAddLineToPoint(ctx, CGRectGetMaxX(imageFrame)+2, CGRectGetMidY(imageFrame));
  24. }else if (self.tag == CPDFViewAnnotationModeUnderline) {
  25. CGContextMoveToPoint(ctx, CGRectGetMinX(imageFrame), CGRectGetMaxY(imageFrame));
  26. CGContextSetLineWidth(ctx, 2.0);
  27. CGContextAddLineToPoint(ctx, CGRectGetMaxX(imageFrame), CGRectGetMaxY(imageFrame));
  28. } else if (self.tag == CPDFViewAnnotationModeStrikeout) {
  29. CGContextMoveToPoint(ctx, CGRectGetMinX(imageFrame), CGRectGetMidY(imageFrame));
  30. CGContextSetLineWidth(ctx, 2.0);
  31. CGContextAddLineToPoint(ctx, CGRectGetMaxX(imageFrame), CGRectGetMidY(imageFrame));
  32. } else if (self.tag == CPDFViewAnnotationModeSquiggly) {
  33. float tWidth = imageFrame.size.width / 6.0;
  34. CGContextMoveToPoint(ctx, CGRectGetMinX(imageFrame), CGRectGetMaxY(imageFrame));
  35. CGContextSetLineWidth(ctx, 2.0);
  36. CGContextAddCurveToPoint(ctx,
  37. CGRectGetMinX(imageFrame)+tWidth,CGRectGetMaxY(imageFrame)+4,
  38. CGRectGetMinX(imageFrame)+tWidth*2.0,CGRectGetMaxY(imageFrame)-4,
  39. CGRectGetMinX(imageFrame)+tWidth*3.0,CGRectGetMaxY(imageFrame));
  40. CGContextAddCurveToPoint(ctx,
  41. CGRectGetMinX(imageFrame)+tWidth*4.0,CGRectGetMaxY(imageFrame)+4,
  42. CGRectGetMinX(imageFrame)+tWidth*5.0,CGRectGetMaxY(imageFrame)-4,
  43. CGRectGetMinX(imageFrame)+tWidth*6.0,CGRectGetMaxY(imageFrame));
  44. } else if (self.tag == CPDFViewAnnotationModeInk) {
  45. float tWidth = imageFrame.size.width / 6.0;
  46. CGContextMoveToPoint(ctx, CGRectGetMinX(imageFrame), CGRectGetMaxY(imageFrame));
  47. CGContextSetLineWidth(ctx, 2.0);
  48. CGContextAddCurveToPoint(ctx,
  49. CGRectGetMinX(imageFrame)+tWidth,CGRectGetMaxY(imageFrame)+4,
  50. CGRectGetMinX(imageFrame)+tWidth*2.0,CGRectGetMaxY(imageFrame)-4,
  51. CGRectGetMinX(imageFrame)+tWidth*3.0,CGRectGetMaxY(imageFrame));
  52. CGContextAddCurveToPoint(ctx,
  53. CGRectGetMinX(imageFrame)+tWidth*4.0,CGRectGetMaxY(imageFrame)+4,
  54. CGRectGetMinX(imageFrame)+tWidth*5.0,CGRectGetMaxY(imageFrame)-4,
  55. CGRectGetMinX(imageFrame)+tWidth*6.0,CGRectGetMaxY(imageFrame));
  56. }
  57. CGContextStrokePath(ctx);
  58. }
  59. @end