Skip to content

Commit

Permalink
Merge branch 'github/develop' into github/master
Browse files Browse the repository at this point in the history
  • Loading branch information
Raj Seshasankaran committed Jul 21, 2016
2 parents a82beab + acf58a9 commit 7af8620
Show file tree
Hide file tree
Showing 80 changed files with 5,071 additions and 2,307 deletions.
8 changes: 6 additions & 2 deletions Frameworks/CoreFoundation/Base.subproj/SymbolAliases
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,12 @@ _kCFCalendarIdentifierIslamicCivil _kCFIslamicCivilCalendar
_kCFCalendarIdentifierJapanese _kCFJapaneseCalendar
_kCFCalendarIdentifierPersian _kCFPersianCalendar
_kCFCalendarIdentifierRepublicOfChina _kCFRepublicOfChinaCalendar
_kCFCalendarIdentifierIslamicTabular _kCFIslamicTabularCalendar
_kCFCalendarIdentifierIslamicUmmAlQura _kCFIslamicUmmAlQuraCalendar
_kCFCalendarIdentifierIslamicTabular _kCFIslamicTabularCalendar
_kCFCalendarIdentifierIslamicUmmAlQura _kCFIslamicUmmAlQuraCalendar
// WINOBJC: Expose additional calendar identifiers for foundation to use
_kCFCalendarIdentifierCoptic _kCFCopticCalendar
_kCFCalendarIdentifierEthiopicAmeteAlem _kCFEthiopicAmeteAlemCalendar
_kCFCalendarIdentifierEthiopicAmeteMihret _kCFEthiopicAmeteMihretCalendar


_kCFLocaleCalendarIdentifierKey _kCFLocaleCalendarIdentifier
Expand Down
74 changes: 50 additions & 24 deletions Frameworks/CoreFoundation/Locale.subproj/CFCalendar.c
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,8 @@ static void __CFCalendarSetupCal(CFCalendarRef calendar) {
calendar->_cal = __CFCalendarCreateUCalendar(calendar->_identifier, calendar->_localeID, calendar->_tz);
}

#if DEPLOYMENT_RUNTIME_SWIFT
// WINOBJC: CFCalendarIsWeekend and getNextWeekend are useful. Add win32 as a target as well to properly export it for Foundation to access
#if DEPLOYMENT_RUNTIME_SWIFT || TARGET_OS_WIN32
Boolean _CFCalendarIsWeekend(CFCalendarRef calendar, CFAbsoluteTime at) {
if (calendar->_cal == NULL) {
__CFCalendarSetupCal(calendar);
Expand Down Expand Up @@ -652,6 +653,9 @@ static CFRange __CFCalendarGetRangeOfUnit2(CFCalendarRef calendar, CFCalendarUni
case kCFCalendarUnitHour:
case kCFCalendarUnitDay:
case kCFCalendarUnitWeekday:
// WINOBJC: WeekOfYear and WeekOfMonth are also valid "biggerUnit"s.
case kCFCalendarUnitWeekOfYear:
case kCFCalendarUnitWeekOfMonth:
case kCFCalendarUnitWeek:
case kCFCalendarUnitMonth:
case kCFCalendarUnitYear:
Expand All @@ -667,6 +671,9 @@ static CFRange __CFCalendarGetRangeOfUnit2(CFCalendarRef calendar, CFCalendarUni
case kCFCalendarUnitHour:
case kCFCalendarUnitDay:
case kCFCalendarUnitWeekday:
// WINOBJC: WeekOfYear and WeekOfMonth are also valid "biggerUnit"s.
case kCFCalendarUnitWeekOfYear:
case kCFCalendarUnitWeekOfMonth:
case kCFCalendarUnitWeek:
case kCFCalendarUnitMonth:
case kCFCalendarUnitYear:
Expand All @@ -681,6 +688,9 @@ static CFRange __CFCalendarGetRangeOfUnit2(CFCalendarRef calendar, CFCalendarUni
switch (biggerUnit) {
case kCFCalendarUnitDay:
case kCFCalendarUnitWeekday:
// WINOBJC: WeekOfYear and WeekOfMonth are also valid "biggerUnit"s.
case kCFCalendarUnitWeekOfYear:
case kCFCalendarUnitWeekOfMonth:
case kCFCalendarUnitWeek:
case kCFCalendarUnitMonth:
case kCFCalendarUnitYear:
Expand All @@ -693,6 +703,9 @@ static CFRange __CFCalendarGetRangeOfUnit2(CFCalendarRef calendar, CFCalendarUni
break;
case kCFCalendarUnitDay:
switch (biggerUnit) {
// WINOBJC: WeekOfYear and WeekOfMonth are also valid "biggerUnit"s.
case kCFCalendarUnitWeekOfYear:
case kCFCalendarUnitWeekOfMonth:
case kCFCalendarUnitWeek:
case kCFCalendarUnitMonth:
case kCFCalendarUnitYear:
Expand All @@ -703,6 +716,9 @@ static CFRange __CFCalendarGetRangeOfUnit2(CFCalendarRef calendar, CFCalendarUni
break;
case kCFCalendarUnitWeekday:
switch (biggerUnit) {
// WINOBJC: WeekOfYear and WeekOfMonth are also valid "biggerUnit"s.
case kCFCalendarUnitWeekOfYear:
case kCFCalendarUnitWeekOfMonth:
case kCFCalendarUnitWeek:
case kCFCalendarUnitMonth:
case kCFCalendarUnitYear:
Expand All @@ -720,6 +736,9 @@ static CFRange __CFCalendarGetRangeOfUnit2(CFCalendarRef calendar, CFCalendarUni
break;
}
break;
// WINOBJC: Add cases for weekOf units. ICU will handle them below.
case kCFCalendarUnitWeekOfYear:
case kCFCalendarUnitWeekOfMonth:
case kCFCalendarUnitWeek:
switch (biggerUnit) {
case kCFCalendarUnitMonth:
Expand Down Expand Up @@ -964,36 +983,43 @@ Boolean _CFCalendarGetComponentDifferenceV(CFCalendarRef calendar, CFAbsoluteTim
int direction = (startingAT <= resultAT) ? 1 : -1;
char ch = *componentDesc;
while (ch) {
// WINOBJC: ICU function ucal_add does not accept UCAL_LEAP_MONTH. Skip this component as it causes failure. TODO: 7682424 ICU update may fix this
if (ch == 'l') {
vector++;
componentDesc++;
ch = *componentDesc;
continue;
}
UCalendarDateFields field = __CFCalendarGetICUFieldCodeFromChar(ch);
const int multiple_table[] = {0, 0, 16, 19, 24, 26, 24, 28, 14, 14, 14};
int multiple = direction * (1 << multiple_table[flsl(__CFCalendarGetCalendarUnitFromChar(ch)) - 1]);
Boolean divide = false, alwaysDivide = false;
int result = 0;
while ((direction > 0 && curr < goal) || (direction < 0 && goal < curr)) {
ucal_add(calendar->_cal, field, multiple, &status);
UDate newcurr = ucal_getMillis(calendar->_cal, &status);
if ((direction > 0 && curr < newcurr && newcurr <= goal) || (direction < 0 && newcurr < curr && goal <= newcurr)) {
result += multiple;
curr = newcurr;
} else {
// Either newcurr is going backwards, or not making
// progress, or has overshot the goal; reset date
// and try smaller multiples.
ucal_setMillis(calendar->_cal, curr, &status);
divide = true;
// once we start overshooting the goal, the add at
// smaller multiples will succeed at most once for
// each multiple, so we reduce it every time through
// the loop.
if ((direction > 0 && goal < newcurr) || (direction < 0 && newcurr < goal)) alwaysDivide = true;
}
if (divide) {
multiple = multiple / 2;
if (0 == multiple) break;
divide = alwaysDivide;
}
ucal_add(calendar->_cal, field, multiple, &status);
UDate newcurr = ucal_getMillis(calendar->_cal, &status);
if ((direction > 0 && curr < newcurr && newcurr <= goal) || (direction < 0 && newcurr < curr && goal <= newcurr)) {
result += multiple;
curr = newcurr;
} else {
// Either newcurr is going backwards, or not making
// progress, or has overshot the goal; reset date
// and try smaller multiples.
ucal_setMillis(calendar->_cal, curr, &status);
divide = true;
// once we start overshooting the goal, the add at
// smaller multiples will succeed at most once for
// each multiple, so we reduce it every time through
// the loop.
if ((direction > 0 && goal < newcurr) || (direction < 0 && newcurr < goal)) alwaysDivide = true;
}
if (divide) {
multiple = multiple / 2;
if (0 == multiple) break;
divide = alwaysDivide;
}
}
*(*vector) = result;
*(*vector) = result;
vector++;
componentDesc++;
ch = *componentDesc;
Expand Down
4 changes: 4 additions & 0 deletions Frameworks/CoreFoundation/Locale.subproj/CFLocale.h
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,10 @@ CF_EXPORT const CFStringRef kCFIndianCalendar CF_AVAILABLE(10_6, 4_0);
CF_EXPORT const CFStringRef kCFISO8601Calendar CF_AVAILABLE(10_6, 4_0);
CF_EXPORT const CFStringRef kCFIslamicTabularCalendar CF_AVAILABLE(10_10, 8_0);
CF_EXPORT const CFStringRef kCFIslamicUmmAlQuraCalendar CF_AVAILABLE(10_10, 8_0);
//WINOBJC: Expose additional calendar identifiers for foundation to use
CF_EXPORT const CFStringRef kCFCopticCalendar CF_AVAILABLE(10_10, 8_0);
CF_EXPORT const CFStringRef kCFEthiopicAmeteMihretCalendar CF_AVAILABLE(10_10, 8_0);
CF_EXPORT const CFStringRef kCFEthiopicAmeteAlemCalendar CF_AVAILABLE(10_10, 8_0);

CF_EXTERN_C_END
CF_IMPLICIT_BRIDGING_DISABLED
Expand Down
2 changes: 1 addition & 1 deletion Frameworks/CoreFoundation/NumberDate.subproj/CFDate.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ CFAbsoluteTime CFAbsoluteTimeGetCurrent(void) {

// WINOBJC: ensure that extra precision is maintained in the conversion to seconds.
auto timeSinceEpochSec = std::chrono::duration_cast<std::chrono::duration<double, std::ratio<1>>>(timeSinceEpoch).count();
ret = timeSinceEpochSec;
ret = timeSinceEpochSec - kCFAbsoluteTimeIntervalSince1970;
return ret;
}

Expand Down
46 changes: 23 additions & 23 deletions Frameworks/CoreGraphics/CGColor.mm
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,13 @@ CGColorRef CGColorCreateCopy(CGColorRef color) {
@Status Interoperable
*/
CGColorRef CGColorCreateCopyWithAlpha(CGColorRef color, float alpha) {
ColorQuad curColor;

[(UIColor*)color getColors:&curColor];
static __CGColorQuad defaultColor{ 0.0f, 0.0f, 0.0f, 0.0f };
const __CGColorQuad* curColor = [(UIColor*)color _getColors];
if (!curColor) {
curColor = &defaultColor;
}

return static_cast<CGColorRef>([[_LazyUIColor colorWithRed:curColor.r green:curColor.g blue:curColor.b alpha:alpha] retain]);
return static_cast<CGColorRef>([[_LazyUIColor colorWithRed:curColor->r green:curColor->g blue:curColor->b alpha:alpha] retain]);
}

/**
Expand All @@ -82,25 +84,29 @@ CGColorRef CGColorCreateWithPattern(CGColorSpaceRef colorSpace, CGPatternRef pat
@Status Interoperable
*/
bool CGColorEqualToColor(CGColorRef color1, CGColorRef color2) {
ColorQuad components1{};
ColorQuad components2{};

[(UIColor*)color1 getColors:&components1];
[(UIColor*)color2 getColors:&components2];
if (color1 == color2) {
return true;
}
if (!color1 || !color2) {
return false;
}
const __CGColorQuad* components1 = [(UIColor*)color1 _getColors];
const __CGColorQuad* components2 = [(UIColor*)color2 _getColors];

return ((components1.r == components1.r) && (components1.g == components1.g) && (components1.b == components1.b) &&
(components1.a == components1.a));
return ((components1->r == components2->r) && (components1->g == components2->g) && (components1->b == components2->b) &&
(components1->a == components2->a));
}

/**
@Status Interoperable
*/
CGFloat CGColorGetAlpha(CGColorRef color) {
ColorQuad components;
const __CGColorQuad* curColor = [(UIColor*)color _getColors];

[(UIColor*)color getColors:&components];

return (CGFloat)components.a;
if (curColor) {
return curColor->a;
}
return 0.0f;
}

/**
Expand All @@ -114,16 +120,10 @@ CGColorSpaceRef CGColorGetColorSpace(CGColorRef color) {

/**
@Status Caveat
@Notes Works as expected for RGBA only, but returns a client-freed buffer.
@Notes Works as expected for RGBA only.
*/
const CGFloat* CGColorGetComponents(CGColorRef color) {
float* ret = (float*)IwMalloc(sizeof(float) * 4);
ColorQuad colorComponents;
[(UIColor*)color getColors:&colorComponents];

ColorQuadToFloatArray(colorComponents, ret);

return ret;
return (const CGFloat*)[(UIColor*)color _getColors];
}

/**
Expand Down
15 changes: 11 additions & 4 deletions Frameworks/CoreGraphics/CGContextCairo.mm
Original file line number Diff line number Diff line change
Expand Up @@ -212,13 +212,12 @@
cairo_append_path(ctx, path);

NSUInteger componentsNum = CGColorGetNumberOfComponents(curState->shadowColor);
CGFloat* components = (CGFloat*)CGColorGetComponents(curState->shadowColor);
const CGFloat* components = CGColorGetComponents(curState->shadowColor);
if (componentsNum == 2) {
cairo_set_source_rgba(ctx, components[0], components[0], components[0], components[1]);
} else if (componentsNum == 4) {
cairo_set_source_rgba(ctx, components[0], components[1], components[2], components[3]);
}
IwFree(components);

// Make the stroke style same as _drawContext
cairo_set_line_width(ctx, cairo_get_line_width(_drawContext));
Expand Down Expand Up @@ -700,12 +699,20 @@
}

void CGContextCairo::CGContextSetStrokeColorWithColor(id color) {
[(UIColor*)color getColors:&curState->curStrokeColor];
if (color) {
curState->curStrokeColor = *[(UIColor*)color _getColors];
} else {
_ClearColorQuad(curState->curStrokeColor);
}
}

void CGContextCairo::CGContextSetFillColorWithColor(id color) {
if ((int)[(UIColor*)color _type] == solidBrush) {
[(UIColor*)color getColors:&curState->curFillColor];
if (color) {
curState->curFillColor = *[(UIColor*)color _getColors];
} else {
_ClearColorQuad(curState->curFillColor);
}
curState->curFillColorObject = nil;
} else {
curState->curFillColorObject = [color retain];
Expand Down
12 changes: 10 additions & 2 deletions Frameworks/CoreGraphics/CGContextImpl.mm
Original file line number Diff line number Diff line change
Expand Up @@ -353,12 +353,20 @@
}

void CGContextImpl::CGContextSetStrokeColorWithColor(id color) {
[(UIColor*)color getColors:&curState->curStrokeColor];
if (color) {
curState->curStrokeColor = *[(UIColor*)color _getColors];
} else {
_ClearColorQuad(curState->curStrokeColor);
}
}

void CGContextImpl::CGContextSetFillColorWithColor(id color) {
if ((int)[(UIColor*)color _type] == solidBrush) {
[(UIColor*)color getColors:&curState->curFillColor];
if (color) {
curState->curFillColor = *[(UIColor*)color _getColors];
} else {
_ClearColorQuad(curState->curFillColor);
}
curState->curFillColorObject = nil;
} else {
curState->curFillColorObject = [color retain];
Expand Down
15 changes: 7 additions & 8 deletions Frameworks/CoreGraphics/CGGradient.mm
Original file line number Diff line number Diff line change
Expand Up @@ -115,18 +115,17 @@ - (void)dealloc {

int count = [components count];

_components = new float[count * componentCount];
_components = new CGFloat[count * componentCount];

for (int i = 0; i < count; i++) {
UIColor* curColor = [components objectAtIndex:i];

float colorArray[4];
ColorQuad color;
[curColor getColors:&color];

ColorQuadToFloatArray(color, colorArray);

memcpy(&_components[i * componentCount], colorArray, sizeof(float) * componentCount);
if (curColor) {
const __CGColorQuad* color = [curColor _getColors];
memcpy(&_components[i * componentCount], color, sizeof(CGFloat) * componentCount);
} else {
memset(&_components[i * componentCount], 0, sizeof(CGFloat) * componentCount);
}
}

_locations = new float[count];
Expand Down
Loading

0 comments on commit 7af8620

Please sign in to comment.