-/* xscreensaver, Copyright (c) 2006-2016 Jamie Zawinski <jwz@jwz.org>
+/* xscreensaver, Copyright (c) 2006-2017 Jamie Zawinski <jwz@jwz.org>
*
* Permission to use, copy, modify, distribute, and sell this software and its
* documentation for any purpose is hereby granted without fee, provided that
NSString *text = [self stripTags: html];
CGSize s = r.size;
s.height = 999999;
- s = [text sizeWithFont: font
- constrainedToSize: s
- lineBreakMode:NSLineBreakByWordWrapping];
+ s = [text boundingRectWithSize:s
+ options:NSStringDrawingUsesLineFragmentOrigin
+ attributes:@{NSFontAttributeName: font}
+ context:nil].size;
r.size.height = s.height;
# endif
eolp = YES;
} else if ([s characterAtIndex:0] == ' ' ||
[s hasPrefix:@"Copyright "] ||
+ [s hasPrefix:@"https://"] ||
[s hasPrefix:@"http://"]) {
// don't unwrap if the following line begins with whitespace,
// or with the word "Copyright", or if it begins with a URL.
static char *
anchorize (const char *url)
{
- const char *wiki = "http://en.wikipedia.org/wiki/";
- const char *math = "http://mathworld.wolfram.com/";
- if (!strncmp (wiki, url, strlen(wiki))) {
+ const char *wiki1 = "http://en.wikipedia.org/wiki/";
+ const char *wiki2 = "https://en.wikipedia.org/wiki/";
+ const char *math1 = "http://mathworld.wolfram.com/";
+ const char *math2 = "https://mathworld.wolfram.com/";
+ if (!strncmp (wiki1, url, strlen(wiki1)) ||
+ !strncmp (wiki2, url, strlen(wiki2))) {
char *anchor = (char *) malloc (strlen(url) * 3 + 10);
strcpy (anchor, "Wikipedia: \"");
- const char *in = url + strlen(wiki);
+ const char *in = url + strlen(!strncmp (wiki1, url, strlen(wiki1))
+ ? wiki1 : wiki2);
char *out = anchor + strlen(anchor);
while (*in) {
if (*in == '_') {
*out = 0;
return anchor;
- } else if (!strncmp (math, url, strlen(math))) {
+ } else if (!strncmp (math1, url, strlen(math1)) ||
+ !strncmp (math2, url, strlen(math2))) {
char *anchor = (char *) malloc (strlen(url) * 3 + 10);
strcpy (anchor, "MathWorld: \"");
- const char *start = url + strlen(wiki);
+ const char *start = url + strlen(!strncmp (math1, url, strlen(math1))
+ ? math1 : math2);
const char *in = start;
char *out = anchor + strlen(anchor);
while (*in) {
NSString *text = [nstext text];
# endif
- int L = [text length];
+ NSUInteger L = [text length];
NSRange start; // range is start-of-search to end-of-string
start.location = 0;
start.length = L;
// Find the beginning of a URL...
//
- NSRange r2 = [text rangeOfString:@"http://" options:0 range:start];
+ NSRange r2 = [text rangeOfString: @"http://" options:0 range:start];
+ NSRange r3 = [text rangeOfString:@"https://" options:0 range:start];
+ if ((r2.location == NSNotFound &&
+ r3.location != NSNotFound) ||
+ (r2.location != NSNotFound &&
+ r3.location != NSNotFound &&
+ r3.location < r2.location))
+ r2 = r3;
if (r2.location == NSNotFound)
break;
// Find the end of a URL (whitespace or EOF)...
//
- NSRange r3 = [text rangeOfCharacterFromSet:
- [NSCharacterSet whitespaceAndNewlineCharacterSet]
- options:0 range:start];
+ r3 = [text rangeOfCharacterFromSet:
+ [NSCharacterSet whitespaceAndNewlineCharacterSet]
+ options:0 range:start];
if (r3.location == NSNotFound) // EOF
r3.location = L, r3.length = 0;
free (anchor);
- int L2 = [text length]; // might have changed
+ NSUInteger L2 = [text length]; // might have changed
start.location -= (L - L2);
L = L2;
}
[panel setCanChooseFiles:!dirs_p];
[panel setCanChooseDirectories:dirs_p];
- int result = [panel runModal];
+ NSInteger result = [panel runModal];
if (result == NSOKButton) {
NSArray *files = [panel URLs];
NSString *file = ([files count] > 0 ? [[files objectAtIndex:0] path] : @"");
{
NSView *parent = [button superview];
NSArray *kids = [parent subviews];
- int nkids = [kids count];
+ NSUInteger nkids = [kids count];
int i;
NSTextField *f = 0;
for (i = 0; i < nkids; i++) {
last_child (NSView *parent)
{
NSArray *kids = [parent subviews];
- int nkids = [kids count];
+ NSUInteger nkids = [kids count];
if (nkids == 0)
return 0;
else
layout_group (NSView *group, BOOL horiz_p)
{
NSArray *kids = [group subviews];
- int nkids = [kids count];
- int i;
+ NSUInteger nkids = [kids count];
+ NSUInteger i;
double maxx = 0, miny = 0;
for (i = 0; i < nkids; i++) {
NSView *kid = [kids objectAtIndex:i];
{
NSRect f;
NSArray *kids = [parent subviews];
- int nkids = [kids count];
+ NSUInteger nkids = [kids count];
NSView *text = 0; // the NSText at the bottom of the window
double maxx = 0, miny = 0;
- int i;
+ NSUInteger i;
/* Find the size of the rectangle taken up by each of the children
except the final "NSText" child.
CGFloat max = 0;
for (NSArray *a2 in a) {
NSString *s = [a2 objectAtIndex:0];
+ // #### sizeWithFont deprecated as of iOS 7; use boundingRectWithSize.
CGSize r = [s sizeWithFont:f];
if (r.width > max) max = r.width;
}
[[self navigationItem]
setRightBarButtonItem: [[UIBarButtonItem alloc]
initWithTitle: @"Reset to Defaults"
- style: UIBarButtonItemStyleBordered
+ style: UIBarButtonItemStylePlain
target:self
action:@selector(resetAction:)]];
NSString *s = saver_name;
[mid setFrame:r];
if (top) {
- r.size = [[top text] sizeWithFont:[top font]
- constrainedToSize:
- CGSizeMake (ww - LEFT_MARGIN*2, 100000)
- lineBreakMode:[top lineBreakMode]];
# ifdef LABEL_ABOVE_SLIDER
// Top label goes above, flush center/top.
r.origin.x = (ww - r.size.width) / 2;
r.origin.y = 4;
+ // #### sizeWithFont deprecated as of iOS 7; use boundingRectWithSize.
+ r.size = [[top text] sizeWithFont:[top font]
+ constrainedToSize:
+ CGSizeMake (ww - LEFT_MARGIN*2, 100000)
+ lineBreakMode:[top lineBreakMode]];
# else // !LABEL_ABOVE_SLIDER
// Label goes on the left.
r.origin.x = LEFT_MARGIN;
}
// Left label goes under control, flush left/bottom.
- r.size = [[left text] sizeWithFont:[left font]
- constrainedToSize:
- CGSizeMake(ww - LEFT_MARGIN*2, 100000)
- lineBreakMode:[left lineBreakMode]];
- r.origin.x = [mid frame].origin.x;
- r.origin.y = hh - r.size.height - 4;
- [left setFrame:r];
+ left.frame = CGRectMake([mid frame].origin.x, hh - 4,
+ ww - LEFT_MARGIN*2, 100000);
+ [left sizeToFit];
+ r = left.frame;
+ r.origin.y -= r.size.height;
+ left.frame = r;
// Right label goes under control, flush right/bottom.
- r = [right frame];
- r.size = [[right text] sizeWithFont:[right font]
- constrainedToSize:
- CGSizeMake(ww - LEFT_MARGIN*2, 1000000)
- lineBreakMode:[right lineBreakMode]];
- r.origin.x = ([mid frame].origin.x + [mid frame].size.width -
- r.size.width);
- r.origin.y = [left frame].origin.y;
- [right setFrame:r];
+ right.frame =
+ CGRectMake([mid frame].origin.x + [mid frame].size.width,
+ [left frame].origin.y, ww - LEFT_MARGIN*2, 1000000);
+ [right sizeToFit];
+ r = right.frame;
+ r.origin.x -= r.size.width;
+ right.frame = r;
// Make a box and put the labels and slider into it.
r.origin.x = 0;