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

Implement CTFontCreatePathForGlyph#1330

Merged
ms-jihua merged 4 commits into
microsoft:developfrom
ms-jihua:ctfont_createpathforglyph_1107
Nov 9, 2016
Merged

Implement CTFontCreatePathForGlyph#1330
ms-jihua merged 4 commits into
microsoft:developfrom
ms-jihua:ctfont_createpathforglyph_1107

Conversation

@ms-jihua

@ms-jihua ms-jihua commented Nov 7, 2016

Copy link
Copy Markdown
Contributor
  • Minor style changes to CTFont.mm

Fixes #922


This change is Reviewable

 - Minor style changes to CTFont.mm

Fixes microsoft#922
fontTransformWithoutTranslate.ty = 0;
CGAffineTransform totalTransform = CGAffineTransformConcat(fontTransformWithoutTranslate, scaleByFontSize);

// Compare against a transformed version of expectedElements

@ms-jihua ms-jihua Nov 7, 2016

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.

a transformed version of expectedElements [](start = 23, length = 41)

i wanted to use CGPathCreateCopyByTransformingPath, but we don't have that yet :( #Resolved

}

HRESULT CGPathGeometrySink::RuntimeClassInitialize() {
return S_OK;

@DHowett-MSFT DHowett-MSFT Nov 7, 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.

nit: These two could be in the body of the class, right? #Resolved

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.

yeah, I copied the template from mnithish's code above


In reply to: 86887974 [](ancestors = 86887974)

Comment thread tests/unittests/CoreText/CTFontTests.mm Outdated
break;

default:
EXPECT_TRUE_MSG(false, @"An invalid CGPathElementType was returned from CTFontCreatePathForGlyph");

@DHowett-MSFT DHowett-MSFT Nov 7, 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.

EXPECT_TRUE_MSG [](start = 16, length = 15)

you could FAIL() << "message" for this to escape the weird EXPECT_TRUE(false) #Resolved

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Or, ADD_FAILURE_AT() << "msg" to make it a non-fatal failure.


In reply to: 86888788 [](ancestors = 86888788)

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.

huh, TIL


In reply to: 86888869 [](ancestors = 86888869,86888788)

CGPathAddCurveToPoint(_cgPath.get(),
_transform,
beziers[i].point1.x,
-beziers[i].point1.y,

@aballway aballway Nov 7, 2016

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.

-beziers[i].point1.y [](start = 34, length = 20)

nit: maybe add parens around this so the unary - sticks out more, right now it's super sneaky #WontFix

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.

Mm, tried it, it looks funky to me, and I called these out in the class comment anyway. Going to leave as-is.


In reply to: 86891299 [](ancestors = 86891299)

}

void STDMETHODCALLTYPE AddLines(_In_ const D2D1_POINT_2F* points, unsigned int pointsCount) {
// Could have used CGPathAddLines instead,

@aballway aballway Nov 7, 2016

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.

// Could have used CGPathAddLines instead, [](start = 8, length = 42)

nit: feels more like a commit comment than in-code #Resolved

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.

Hmmm...


In reply to: 86891501 [](ancestors = 86891501)


/**
* Custom IDWriteGeometrySink class that captures the glyph runs generated by
* DWrite for the given TextLayout and TextRenderer constraints.

@ms-jihua ms-jihua Nov 7, 2016

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.

oops #Resolved

* IDWriteFontFace::GetGlyphRunOutline uses this class in a single-threaded manner (dumping the draw instructions from the font linearly)
* As such, this class is deliberately left thread-unsafe.
*/
class CGPathGeometrySink : public RuntimeClass<RuntimeClassFlags<WinRtClassicComMix>, IDWriteGeometrySink> {

@aballway aballway Nov 7, 2016

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.

CGPathGeometrySink [](start = 6, length = 18)

nit: class name should follow framework naming convention #Resolved

@ms-jihua ms-jihua Nov 7, 2016

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.

? what did you have in mind?


In reply to: 86892134 [](ancestors = 86892134)

@aballway aballway Nov 8, 2016

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.

__CTPathGeometrySink if it's only going to be used here #Resolved


CGPathGeometrySink::CGPathGeometrySink(const CGAffineTransform* transform) {
_cgPath.reset(CGPathCreateMutable());
_transform = transform;

@aballway aballway Nov 7, 2016

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.

_transform [](start = 4, length = 10)

leaking? #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.

? CGAffineTransforms are not ref-counted o.o


In reply to: 86892348 [](ancestors = 86892348)

Comment thread tests/unittests/CoreText/CTFontTests.mm Outdated
EXPECT_TRUE_MSG(false, @"An invalid CGPathElementType was returned from CTFontCreatePathForGlyph");
break;
}
++comparePathContext->count;

@aballway aballway Nov 7, 2016

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.

comparePathContext [](start = 10, length = 18)

nit: parens for clear operator precedence #Resolved

@aballway

aballway commented Nov 7, 2016

Copy link
Copy Markdown
Contributor

:shipit:

Comment thread tests/unittests/CoreText/CTFontTests.mm Outdated
switch (element->type) {
case kCGPathElementMoveToPoint:
case kCGPathElementAddLineToPoint:
EXPECT_NEAR(comparePathContext->expectedElements[comparePathContext->count].point.x, element->points[0].x, 0.002f);

@aballway aballway Nov 7, 2016

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.

0.002f [](start = 123, length = 6)

nit: make this a constant #Resolved


CGPathGeometrySink::CGPathGeometrySink(const CGAffineTransform* transform) {
_cgPath.reset(CGPathCreateMutable());
_transform = transform;

@rajsesh rajsesh Nov 7, 2016

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.

Transform is stored by pointer, thereby requiring the caller manages its lifetime. could you make a copy here instead, so this class can be free-standing? #Resolved

static const CFStringRef c_courierNewBoldName = CFSTR("Courier New Bold");
static const CFStringRef c_courierNewBoldItalicName = CFSTR("Courier New Bold Italic");
static const CFStringRef c_trebuchetMSItalicName = CFSTR("Trebuchet MS Italic");
static const CFStringRef c_timesNewRomanName = CFSTR("Times New Roman");

@rajsesh rajsesh Nov 7, 2016

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.

Are we sure these fonts exist on the build server/phone? #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.

yup!


In reply to: 86892725 [](ancestors = 86892725)


// CGPath has support for both orders of Bezier curve,
// but DWrite's GeometrySink only supports cubic Bezier curves, and approximates any quadratic curves in terms of a cubic curve
// Eg: Reference platform quadratic curve: (previous endpoint), (512, 632), (480, 632)

@rajsesh rajsesh Nov 7, 2016

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.

The comments until this point are immensely useful in the context of the implementation code as well, would help to duplicate it there. #Resolved

_invalidState = true;
}

return _invalidState ? E_INVALIDARG : S_OK;

@rajsesh rajsesh Nov 7, 2016

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.

E_UNEXPECTED is probably more appropriate given there are no args to this method. #Resolved

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.

isn't E_UNEXPECTED generally kind of scary? I was trying to go for something a bit lighter.


In reply to: 86893574 [](ancestors = 86893574)

@rajsesh rajsesh Nov 7, 2016

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.

It is essentially saying that the object wasn't expecting the call at this point. E_FAIL is scarier. #Resolved

@rajsesh rajsesh left a comment

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.

Per offline discussion, lets add a visual verification test as well, just to be complete. I am changing my status back to request changes so we get the sample work as well.

* IDWriteFontFace::GetGlyphRunOutline uses this class in a single-threaded manner (dumping the draw instructions from the font linearly)
* As such, this class is deliberately left thread-unsafe.
*/
class CGPathGeometrySink : public RuntimeClass<RuntimeClassFlags<WinRtClassicComMix>, IDWriteGeometrySink> {

@aballway aballway Nov 8, 2016

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.

__CTPathGeometrySink if it's only going to be used here #Resolved

private:
woc::unique_cf<CGMutablePathRef> _cgPath;
const CGAffineTransform* _transform;
bool _figureInProgress = false; // Keeps track of whether this class is currently between a BeginFigure and EndFigure call

@aballway aballway Nov 8, 2016

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: maybe just an enum to hold the state rather than two bools #WontFix

isa = PBXGroup;
children = (
1ED8201D1DD28D4D00DF2DD7 /* CTCPathForGlyphTestViewController.h */,
1ED8201A1DD28D2700DF2DD7 /* CTCPathForGlyphTestViewController.h */,

@ms-jihua ms-jihua Nov 8, 2016

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.

oops I might've added it twice apparently? let me check #Resolved

// - (void)drawRect:(CGRect)rect {
// }

// @end

@ms-jihua ms-jihua Nov 8, 2016

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.

oops #Resolved

@ms-jihua

ms-jihua commented Nov 9, 2016

Copy link
Copy Markdown
Contributor Author

ping!

@ms-jihua ms-jihua merged commit b52a219 into microsoft:develop Nov 9, 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.

5 participants