Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Support kCTParagraphStyleSpecifierLineHeightMultiple#1298

Merged
aballway merged 4 commits into
microsoft:developfrom
aballway:develop
Nov 4, 2016
Merged

Support kCTParagraphStyleSpecifierLineHeightMultiple#1298
aballway merged 4 commits into
microsoft:developfrom
aballway:develop

Conversation

@aballway

@aballway aballway commented Nov 2, 2016

Copy link
Copy Markdown
Contributor

Adds support for kCTParagraphStyleSpecifierLineHeightMultiple. DWrite only allows line height multiples if the line height is kept constant through the frame, which is not guaranteed, so we need to manually manipulate the line origins. Also removes the redundant line origin variable in _CTLine.

Fixes #1090


This change is Reviewable

Comment thread Frameworks/CoreText/CTFrame.mm Outdated
for (_CTLine* line in static_cast<id<NSFastEnumeration>>(framePtr->_lines)) {
if (line->_lineOrigin.y < framePtr->_frameRect.size.height && line->_lineOrigin.y > 0) {
for (size_t i = 0; i < framePtr->_lineOrigins.size(); ++i) {
if (framePtr->_lineOrigins[i].y < framePtr->_frameRect.size.height && framePtr->_lineOrigins[i].y > 0) {

@msft-Jeyaram msft-Jeyaram Nov 2, 2016

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

framePtr->_lineOrigins[i].y > 0 [](start = 81, length = 32)

switch around and have this check first.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

whoops this check isn't actually needed any longer

ret->_frameRect.size.height += totalShifted;
}
}
}

@msft-Jeyaram msft-Jeyaram Nov 2, 2016

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Although you don't "prefer" early returns. This code would be much simpler and so much simpler to read if you used early returns.
We have if layers that aren't the greatest looking for code readability.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I hate to admit it but you're right in this case, too many layers

Comment thread Frameworks/CoreText/CTFramesetter.mm Outdated
sizeof(lineHeightMultiple),
&lineHeightMultiple) &&
lineHeightMultiple > 0) {
// The actual ratio we need to change the line height by is multiple - 1

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

multiple [](start = 76, length = 8)

lineHeightMultiple

CGPathRef path = CGPathCreateWithRect(CGRectMake(0, 0, FLT_MAX, FLT_MAX), nullptr);

NSMutableAttributedString* normalString = [[[NSMutableAttributedString alloc] initWithString:@"TEST\nTEST\nTEST"] autorelease];
CTFramesetterRef normalFramesetter = CTFramesetterCreateWithAttributedString((CFAttributedStringRef)normalString);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CFAttributedStringRef [](start = 82, length = 21)

proper casting?

static_cast<NSString*>(kCTParagraphStyleAttributeName) : (id)CTParagraphStyleCreate(settings, 1)
}
range:NSMakeRange(0, 14)];

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bad formatting?

CGPoint halfOrigins[3];
CTFrameGetLineOrigins(halfFrame, {}, halfOrigins);
EXPECT_NEAR(half * normalLineSpaceFirst, halfOrigins[1].y - halfOrigins[0].y, c_errorDelta);
EXPECT_NEAR(half * normalLineSpaceSecond, halfOrigins[2].y - halfOrigins[0].y, c_errorDelta);

@msft-Jeyaram msft-Jeyaram Nov 2, 2016

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a duplicate of the above with slightly different configuration. Refactor the code so you can use it generically and can add more tests easily.

@msft-Jeyaram

Copy link
Copy Markdown

🕐

Comment thread Frameworks/CoreText/CTFramesetter.mm Outdated
return [_DWriteGetFrame(static_cast<CFAttributedStringRef>(typesetter->_attributedString.get()), range, frameSize) retain];
_CTFrame* ret = _DWriteGetFrame(static_cast<CFAttributedStringRef>(typesetter->_attributedString.get()), range, frameSize);

// Trying to access attributes without any text with throw an error

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: typo: // Trying to access attributes without any text with will throw an error


TEST_P(CoreTextLineSpaceMultipleTest, OriginsShouldBeMovedByRatio) {
NSMutableAttributedString* multipleString = [[[NSMutableAttributedString alloc] initWithString:@"TEST\nTEST\nTEST"] autorelease];
CGFloat param = GetParam();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

param [](start = 12, length = 5)

please give this a more meaningful name

CTParagraphStyleRef settings = static_cast<CTParagraphStyleRef>(
[typesetter->_attributedString attribute:static_cast<NSString*>(kCTParagraphStyleAttributeName) atIndex:0 effectiveRange:nullptr]);

if (settings == nil) {

@DHowett-MSFT DHowett-MSFT Nov 3, 2016

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nil [](start = 20, length = 3)

nit: nullptr, since it's not objc #ByDesign

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It actually is an objc

Comment thread Frameworks/CoreText/CTFramesetter.mm Outdated
}

return [_DWriteGetFrame(static_cast<CFAttributedStringRef>(typesetter->_attributedString.get()), range, frameSize) retain];
_CTFrame* ret = _DWriteGetFrame(static_cast<CFAttributedStringRef>(typesetter->_attributedString.get()), range, frameSize);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_CTFrame [](start = 4, length = 8)

If you do a StrongId<_CTFrame> and then .detach() when you return, this will memory manage sanely.

@DHowett-MSFT

Copy link
Copy Markdown

:shipit:

@ms-jihua

ms-jihua commented Nov 4, 2016

Copy link
Copy Markdown
Contributor

:shipit:

@aballway aballway merged commit b73f8ce into microsoft:develop Nov 4, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants