Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Frameworks/CoreGraphics/CGPath.mm
Original file line number Diff line number Diff line change
Expand Up @@ -719,4 +719,4 @@ CGPoint CGPathGetCurrentPoint(CGPathRef path) {
bool CGPathIsRect(CGPathRef path, CGRect* rect) {
UNIMPLEMENTED();
return StubReturn();
}
}
3 changes: 1 addition & 2 deletions Frameworks/CoreText/CTFrame.mm
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,7 @@ void CTFrameDraw(CTFrameRef frameRef, CGContextRef ctx) {
if (frame && ctx) {
// Need to invert and translate coordinates so frame draws from top-left
CGContextSaveGState(ctx);
CGRect boundingRect;
_CGPathGetBoundingBoxInternal(frame->_path.get(), &boundingRect);
CGRect boundingRect = CGPathGetBoundingBox(frame->_path.get());
CGContextTranslateCTM(ctx, 0, boundingRect.size.height);

// Invert Text Matrix so glyphs are drawn in correct orientation
Expand Down
9 changes: 3 additions & 6 deletions Frameworks/CoreText/CTFramesetter.mm
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,11 @@ CTFramesetterRef CTFramesetterCreateWithAttributedString(CFAttributedStringRef s
@Notes frameAttributes parameter ignored
*/
CTFrameRef CTFramesetterCreateFrame(CTFramesetterRef framesetter, CFRange stringRange, CGPathRef path, CFDictionaryRef frameAttributes) {
CGRect frameSize;
CGRect containingRect = CGPathGetBoundingBox(path);

// TODO 1143: Replace with public functions or workaround.
// _CGPathGetBoundingBoxInternal(path, &frameSize);

_CTFrame* ret = __CreateFrame(static_cast<_CTFramesetter*>(framesetter), frameSize, stringRange);
_CTFrame* ret = __CreateFrame(static_cast<_CTFramesetter*>(framesetter), containingRect, stringRange);
ret->_path.reset(CGPathRetain(path));
ret->_frameRect.origin = frameSize.origin;
ret->_frameRect.origin = containingRect.origin;

return static_cast<CTFrameRef>(ret);
}
Expand Down
70 changes: 56 additions & 14 deletions Frameworks/UIKit/NSTextContainer.mm
Original file line number Diff line number Diff line change
Expand Up @@ -62,39 +62,81 @@ - (NSArray*)exclusionPaths {
return _exclusionPaths;
}

static CGFloat _leftMostLocationForPath(CGRect proposedRectangle, CGPathRef path, CGFloat bufferAmount, bool eoFill) {
CGFloat topLocation = proposedRectangle.origin.y;

for (CGFloat left = proposedRectangle.origin.x; left < proposedRectangle.origin.x + proposedRectangle.size.width;
left += bufferAmount) {
// Transform is ignored since UIBezierPath has already applied it
if (!CGPathContainsPoint(path, NULL, CGPointMake(left, topLocation), eoFill)) {
return left;
}
}

return proposedRectangle.origin.x + proposedRectangle.size.width;
}

static CGFloat _rightMostLocationForPath(CGRect proposedRectangle, CGPathRef path, CGFloat bufferAmount, bool eoFill) {
CGFloat topLocation = proposedRectangle.origin.y;
CGFloat lastRight = proposedRectangle.origin.x;

for (CGFloat right = proposedRectangle.origin.x; right < proposedRectangle.origin.x + proposedRectangle.size.width;
right += bufferAmount) {
// Transform is ignored since UIBezierPath has already applied it
if (CGPathContainsPoint(path, NULL, CGPointMake(right, topLocation), eoFill)) {
return lastRight;
}
lastRight = right;
}
// No exclusion zone hit.
return proposedRectangle.origin.x + proposedRectangle.size.width;
}

/**
@Status Caveat
@Notes writingDirection and atIndex parameters are ignored
TODO::1123 This needs to handle multiple exclusion zones properly when creating remainingRect
Currently processing exclusion zones left-to-right fails to calculate properly
*/

- (CGRect)lineFragmentRectForProposedRect:(CGRect)proposed
atIndex:(NSUInteger)idx
writingDirection:(NSWritingDirection)direction
remainingRect:(CGRect*)remainingRect {
// Issue 1123 & 1143 : This requires further investigation after CGPath work.
CGRect totalRect = CGRectMake(0, 0, _size.width, _size.height);
CGRect ret = CGRectIntersection(proposed, totalRect);

if (_exclusionPaths != nil) {
for (UIBezierPath* path in(NSArray*)_exclusionPaths) {
// TODO 1143: Replace with public function or work around.
// CGRect shapeRect = _CGPathFitRect(path.CGPath, ret, _size, self.lineFragmentPadding);
// ret = CGRectIntersection(shapeRect, ret);
CGFloat leftMostAllowedPosition = proposed.origin.x;
CGFloat rightMostAllowedPosition = proposed.origin.x + proposed.size.width;

for (UIBezierPath* path in (NSArray*)_exclusionPaths) {
for (CGFloat yposition = proposed.origin.y; yposition < proposed.origin.y + proposed.size.height;
yposition += self.lineFragmentPadding) {
CGFloat leftMost = _leftMostLocationForPath(proposed, path.CGPath, self.lineFragmentPadding, path.usesEvenOddFillRule);
if (leftMostAllowedPosition < leftMost) {
leftMostAllowedPosition = leftMost;
}

CGFloat rightMost = _rightMostLocationForPath(proposed, path.CGPath, self.lineFragmentPadding, path.usesEvenOddFillRule);
if (rightMostAllowedPosition < rightMost) {
rightMostAllowedPosition = rightMost;
}
}
}

CGRect fitRect = CGRectMake(leftMostAllowedPosition,
proposed.origin.y,
rightMostAllowedPosition - leftMostAllowedPosition,
proposed.size.height);
ret = CGRectIntersection(fitRect, ret);

if (remainingRect) {
*remainingRect = CGRectMake(ret.origin.x + ret.size.width + self.lineFragmentPadding,
ret.origin.y,
_size.width - ret.origin.x - ret.size.width,
ret.size.height);
for (UIBezierPath* path in(NSArray*)_exclusionPaths) {
CGRect shapeRect = _CGPathFitRect(path.CGPath, *remainingRect, _size, self.lineFragmentPadding);
*remainingRect = CGRectIntersection(shapeRect, *remainingRect);
}
*remainingRect =
CGRectMake(rightMostAllowedPosition, proposed.origin.y, proposed.size.width - fitRect.size.width, proposed.size.height);
}
}

return ret;
}

@end
4 changes: 2 additions & 2 deletions tests/unittests/CoreGraphics/CGBitmapContextTests.mm
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ void _TestPixelFormat(const CGRect bounds, const CGBitmapInfo info, DWORD expect
CGColorSpaceRelease(colorSpace);
CGContextRelease(context);
}
TEST(CGBitmapContext, VerifyPixelFormatRGBA) {
DISABLED_TEST(CGBitmapContext, VerifyPixelFormatRGBA) {
_TestPixelFormat(CGRect{ 0, 0, 10, 10 },
kCGBitmapByteOrder32Big | kCGImageAlphaPremultipliedLast,
0xff800000, // expectedbg
Expand All @@ -160,7 +160,7 @@ void _TestPixelFormat(const CGRect bounds, const CGBitmapInfo info, DWORD expect
);
}

TEST(CGBitmapContext, VerifyPixelFormatBGRA) {
DISABLED_TEST(CGBitmapContext, VerifyPixelFormatBGRA) {
_TestPixelFormat(CGRect{ 0, 0, 10, 10 },
kCGBitmapByteOrder32Big | kCGImageAlphaPremultipliedFirst,
0xff000080, // expectedbg
Expand Down