// // CPDFSampleView.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 "CPDFSampleView.h" #if __has_include() #import #else #import "ComPDFKit_Tools.h" #endif #define PI 3.14159265358979323846 @interface CPDFSampleView () @property (nonatomic, assign) CGRect centerRect; @property (nonatomic, assign) CGRect arrowRect; @property (nonatomic, assign) CGRect textRect; @property (nonatomic, assign) CGRect inkRect; @end @implementation CPDFSampleView #pragma mark - Initializers - (instancetype)initWithFrame:(CGRect)frame { if (self = [super initWithFrame:frame]) { } return self; } - (void)layoutSubviews { [super layoutSubviews]; [self setNeedsDisplay]; } - (void)drawRect:(CGRect)rect { [super drawRect:rect]; CGContextRef context = UIGraphicsGetCurrentContext(); self.centerRect = CGRectInset(rect, (self.bounds.size.width/20)*9, (self.bounds.size.height/8)*3); CGPoint centerPoint = CGPointMake(CGRectGetMidX(rect), CGRectGetMidY(rect)); self.arrowRect = CGRectMake(centerPoint.x-self.bounds.size.height/4, centerPoint.y-self.bounds.size.height/4, self.bounds.size.height/2, self.bounds.size.height/2); self.textRect = CGRectInset(rect, self.bounds.size.width/3+3, self.bounds.size.height/3); self.inkRect = CGRectInset(rect, self.bounds.size.width/4, self.bounds.size.height/3); CGContextSetFillColorWithColor(context, [CPDFColorUtils CAnnotationSampleDrawBackgoundColor].CGColor); CGContextFillRect(context, self.bounds); [self drawSamples:context rect:self.centerRect]; } #pragma mark - Private Methods - (void)drawSamples:(CGContextRef)context rect:(CGRect)rect { switch (self.selecIndex) { case CPDFSamplesNote: { CGContextSetRGBStrokeColor(context, 0, 0, 0, 1.0); if(self.color) { CGFloat red, green, blue, alpha; [self.color getRed:&red green:&green blue:&blue alpha:&alpha]; UIColor *color = [UIColor colorWithRed:red green:green blue:blue alpha:self.opcity]; CGContextSetFillColorWithColor(context, color.CGColor); } else { CGContextSetRGBStrokeColor(context, 0.0, 0.0, 0.0, 1.0); CGContextSetFillColorWithColor(context, [UIColor clearColor].CGColor); } // Draw outer boxes. CGFloat width = 1.0; CGFloat size = rect.size.height / 5; CGRect outerRect1 = CGRectInset(rect, 0, 0); outerRect1.size.height -= size; CGRect outerRect2 = outerRect1; outerRect2.origin.x += size; outerRect2.origin.y += size*4; outerRect2.size.width = size; outerRect2.size.height = size; CGContextSetLineWidth(context, width); CGContextMoveToPoint(context, CGRectGetMinX(outerRect1), CGRectGetMinY(outerRect1)); CGContextAddLineToPoint(context, CGRectGetMinX(outerRect1), CGRectGetMaxY(outerRect1)); CGContextAddLineToPoint(context, CGRectGetMinX(outerRect2), CGRectGetMinY(outerRect2)); CGContextAddLineToPoint(context, CGRectGetMidX(outerRect2), CGRectGetMaxY(outerRect2)); CGContextAddLineToPoint(context, CGRectGetMidX(outerRect2), CGRectGetMinY(outerRect2)); CGContextAddLineToPoint(context, CGRectGetMaxX(outerRect1), CGRectGetMaxY(outerRect1)); CGContextAddLineToPoint(context, CGRectGetMaxX(outerRect1), CGRectGetMinY(outerRect1)); CGContextClosePath(context); CGContextDrawPath(context, kCGPathFillStroke); // Draw inner lines. int count = 3; CGFloat xDelta = rect.size.width / 10; CGFloat yDelta = outerRect1.size.height / (count + 1); CGRect lineRect = outerRect1; lineRect.origin.x += xDelta; lineRect.size.width -= 2*xDelta; for (int i=0; i