Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Properly support RTL text drawing in CoreText #2022

Merged
merged 2 commits into from
Mar 2, 2017

Conversation

aballway
Copy link
Contributor

Now properly draws RTL text with support for text matrix manipulation.
Change CTLineGetOffsetForStringIndex and CTFramesetterCreateFrame to remove assumption of LTR text.

Fixes #1932

@@ -2089,6 +2089,12 @@ void CGContextSetPatternPhase(CGContextRef context, CGSize phase) {
// First glyph's origin is at the given relative position for the glyph run
CGPoint runningPosition{ glyphRuns[i].relativePosition.x, std::round(glyphRuns[i].relativePosition.y) };
for (size_t j = 0; j < run->glyphCount; ++j) {
if (run->bidiLevel & 1) {

Choose a reason for hiding this comment

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

nit: Since we use this in two different places, but with flipped senses, it might be reasonable to abstract it out into a helper macro or inlinable function. if(!RUN_IS_BIDI(...)) seems clearer than that we currently have.

}

// Even if text is RTL set bidiLevel to 0 to draw in correct orientation for proper transformation by glyph

Choose a reason for hiding this comment

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

nit: comment "we have compensated for the RTL glyph positions, so we don't need DWrite to do it for us."

ret += std::accumulate(run->_dwriteGlyphRun.glyphAdvances,
run->_dwriteGlyphRun.glyphAdvances + index,
run->_relativeXOffset,
std::minus<CGFloat>());

Choose a reason for hiding this comment

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

lol accumulate

@@ -505,7 +509,10 @@ HRESULT STDMETHODCALLTYPE GetPixelsPerDip(_In_opt_ void* clientDrawingContext, _
line->_strRange.length = stringRange;
line->_glyphCount = glyphCount;
line->_relativeXOffset = static_cast<_CTRun*>(line->_runs[0])->_relativeXOffset;
line->_relativeYOffset = static_cast<_CTRun*>(line->_runs[0])->_relativeYOffset;
if (static_cast<_CTRun*>([line->_runs objectAtIndex:0])->_dwriteGlyphRun.bidiLevel & 1) {

Choose a reason for hiding this comment

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

nit: cache line->_runs[0] to avoid double (or triple!) dynamic dispatch

@@ -78,7 +78,6 @@ inline void _SafeRelease(T** p) {
@public
CFRange _strRange;
CGFloat _relativeXOffset;
CGFloat _relativeYOffset;

Choose a reason for hiding this comment

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

no more relative y offset!
how uh
how do we handle top-to-bottom scripts?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We don't currently support TtB scripts.

ret += std::accumulate(run->_dwriteGlyphRun.glyphAdvances,
run->_dwriteGlyphRun.glyphAdvances + index,
run->_relativeXOffset);
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: this is probably an awful idea, but you could use a ternary for the last parameter instead of having the if/else

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I tried that some other place but it really didn't like it, can't remember why though.

DHowett-MSFT
DHowett-MSFT previously approved these changes Feb 23, 2017
@rajsesh
Copy link
Contributor

rajsesh commented Feb 23, 2017

Given #2027, are we sure nothing really regressed here?

@DHowett-MSFT
Copy link

right: it would behoove us to avoid merging anything until 2027 is merged with test fixes.

@DHowett-MSFT DHowett-MSFT dismissed their stale review February 23, 2017 01:35

Dismissing until 2027.

@rajsesh
Copy link
Contributor

rajsesh commented Feb 23, 2017

The recommendation in the issue #1932 is to use ComputeGlyphOrigins but we decided to roll out our own implementation instead?

@rajsesh
Copy link
Contributor

rajsesh commented Feb 23, 2017

ComputeGlyphOrigins is not available on windows < anniversary update, so we can't use it here. Will wait for #2027

@aballway
Copy link
Contributor Author

aballway commented Mar 1, 2017

Tests passed post #2027, please take another look 🍏

@aballway
Copy link
Contributor Author

aballway commented Mar 2, 2017

Rebased on top of develop to resolve merge conflict, tests passed again.

@aballway aballway merged commit 7eac832 into microsoft:develop Mar 2, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants