Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 100 lines (88 sloc) 2.942 kb
d6a2787 Oliver Drobnik Added new files
authored
1 //
2 // CGUtils.m
3 // CoreTextExtensions
4 //
5 // Created by Oliver Drobnik on 1/16/11.
6 // Copyright 2011 Drobnik.com. All rights reserved.
7 //
8
9 #import "CGUtils.h"
10
11
1bf64de Oliver Drobnik replaced own rounded rect with UIBezierPath
authored
12 // deprecated: use bezierPathWithRoundedRect instead
d6a2787 Oliver Drobnik Added new files
authored
13
1bf64de Oliver Drobnik replaced own rounded rect with UIBezierPath
authored
14 //CGPathRef newPathForRoundedRect(CGRect rect, CGFloat cornerRadius, BOOL roundTopCorners, BOOL roundBottomCorners)
15 //
16 //{
17 // CGMutablePathRef retPath = CGPathCreateMutable();
18 //
19 // CGRect innerRect = CGRectInset(rect, cornerRadius, cornerRadius);
20 //
21 // CGFloat inside_right = innerRect.origin.x + innerRect.size.width;
22 // CGFloat outside_right = rect.origin.x + rect.size.width;
23 // CGFloat inside_bottom = innerRect.origin.y + innerRect.size.height;
24 // CGFloat outside_bottom = rect.origin.y + rect.size.height;
25 //
26 // CGFloat inside_top = innerRect.origin.y;
27 // CGFloat outside_top = rect.origin.y;
28 // CGFloat outside_left = rect.origin.x;
29 //
30 //
31 // if (roundTopCorners)
32 // {
33 // CGPathMoveToPoint(retPath, NULL, innerRect.origin.x, outside_top);
34 // CGPathAddLineToPoint(retPath, NULL, inside_right, outside_top);
35 //
36 // CGPathAddArcToPoint(retPath, NULL, outside_right, outside_top, outside_right, inside_top, cornerRadius);
37 // }
38 // else
39 // {
40 // CGPathMoveToPoint(retPath, NULL, outside_left, outside_top);
41 // CGPathAddLineToPoint(retPath, NULL, outside_right, outside_top);
42 //
43 // }
44 //
45 // if (roundBottomCorners)
46 // {
47 // CGPathAddLineToPoint(retPath, NULL, outside_right, inside_bottom);
48 // CGPathAddArcToPoint(retPath, NULL, outside_right, outside_bottom, inside_right, outside_bottom, cornerRadius);
49 //
50 // CGPathAddLineToPoint(retPath, NULL, innerRect.origin.x, outside_bottom);
51 // CGPathAddArcToPoint(retPath, NULL, outside_left, outside_bottom, outside_left, inside_bottom, cornerRadius);
52 // }
53 // else
54 // {
55 // CGPathAddLineToPoint(retPath, NULL, outside_right, outside_bottom);
56 // CGPathAddLineToPoint(retPath, NULL, outside_left, outside_bottom);
57 // }
58 //
59 //
60 //
61 // if (roundTopCorners)
62 // {
63 // CGPathAddLineToPoint(retPath, NULL, outside_left, inside_top);
64 // CGPathAddArcToPoint(retPath, NULL, outside_left, outside_top, innerRect.origin.x, outside_top, cornerRadius);
65 // }
66 // else
67 // {
68 // CGPathAddLineToPoint(retPath, NULL, rect.origin.x, outside_top);
69 //
70 // }
71 //
72 //
73 // CGPathCloseSubpath(retPath);
74 //
75 // return retPath;
76 //}
d6a2787 Oliver Drobnik Added new files
authored
77
c54be85 Oliver Drobnik Modifications to avoid conflict with DTFoundation
authored
78 CGSize sizeThatFitsKeepingAspectRatio2(CGSize originalSize, CGSize sizeToFit)
67693c7 Oliver Drobnik Added support for VIDEO Tag.
authored
79 {
d090710 Oliver Drobnik Don't adjust size if already fitting.
authored
80 if (originalSize.width <= sizeToFit.width && originalSize.height <= sizeToFit.height)
81 {
82 return originalSize;
83 }
84
67693c7 Oliver Drobnik Added support for VIDEO Tag.
authored
85 CGFloat necessaryZoomWidth = sizeToFit.width / originalSize.width;
86 CGFloat necessaryZoomHeight = sizeToFit.height / originalSize.height;
87
88 CGFloat smallerZoom = MIN(necessaryZoomWidth, necessaryZoomHeight);
89
90 CGSize scaledSize = CGSizeMake(roundf(originalSize.width*smallerZoom), roundf(originalSize.height*smallerZoom));
d090710 Oliver Drobnik Don't adjust size if already fitting.
authored
91
67693c7 Oliver Drobnik Added support for VIDEO Tag.
authored
92 return scaledSize;
93 }
3021ccc Oliver Drobnik faster way to find glyph next to point
authored
94
95
96 CGPoint CGRectCenter(CGRect rect)
97 {
7528d11 Jonathan Sterling Normalized indentation (tabs)
jonsterling authored
98 return (CGPoint){ CGRectGetMidX(rect), CGRectGetMidY(rect) };
3021ccc Oliver Drobnik faster way to find glyph next to point
authored
99 }
Something went wrong with that request. Please try again.