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

[CGD2D] Migrate the text drawing code from CGContextCairo. #1729

Merged

Conversation

DHowett-MSFT
Copy link

@DHowett-MSFT DHowett-MSFT commented Jan 18, 2017

Fixes #1634.


This change is Reviewable

@DHowett-MSFT
Copy link
Author

With #1727, all of the enabled drawing tests pass!

@DHowett-MSFT
Copy link
Author

Therefore, this branch will merge into the merge branch.

// Text Drawing
CGTextDrawingMode textDrawingMode = kCGTextFill;
woc::StrongCF<CGFontRef> font;
CGFloat fontSize;
Copy link
Author

Choose a reason for hiding this comment

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

perhaps this needs zero initialization.

Copy link
Contributor

Choose a reason for hiding this comment

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

or the default font size value

// Text Drawing
CGTextDrawingMode textDrawingMode = kCGTextFill;
woc::StrongCF<CGFontRef> font;
CGFloat fontSize;
Copy link
Contributor

Choose a reason for hiding this comment

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

or the default font size value

*/
void CGContextSetTextDrawingMode(CGContextRef context, CGTextDrawingMode mode) {
NOISY_RETURN_IF_NULL(context);
UNIMPLEMENTED();
auto& state = context->CurrentGState();
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: oneline these? (context->CurrentGState().textDrawingMode = mode)

// * Stroke: fully opaque black
// If a context does not support alpha, the default fill looks like fully opaque black.
CGContextSetRGBFillColor(context, 0, 0, 0, 0);
// * All colors are fully opaque black.
Copy link
Contributor

Choose a reason for hiding this comment

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

why did this change?

Copy link
Author

Choose a reason for hiding this comment

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

It was wrong.

Copy link
Author

Choose a reason for hiding this comment

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

The commit it is in is titled "Fix the default ... from the reference platform."

UNIMPLEMENTED();
NOISY_RETURN_IF_NULL(font);
auto& state = context->CurrentGState();
state.font = font;
Copy link
Contributor

Choose a reason for hiding this comment

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

context->CurrentGState().font= font;

Copy link
Author

Choose a reason for hiding this comment

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

nit*.

*/
void CGContextSetTextDrawingMode(CGContextRef context, CGTextDrawingMode mode) {
NOISY_RETURN_IF_NULL(context);
UNIMPLEMENTED();
auto& state = context->CurrentGState();
state.textDrawingMode = mode;
Copy link
Contributor

Choose a reason for hiding this comment

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

context->CurrentGState().mode= mode;

*/
void CGContextSelectFont(CGContextRef context, const char* name, CGFloat size, CGTextEncoding encoding) {
NOISY_RETURN_IF_NULL(context);
UNIMPLEMENTED();

auto fontName = woc::MakeStrongCF<CFStringRef>(CFStringCreateWithCString(nullptr, name, kCFStringEncodingUTF8));
Copy link
Contributor

Choose a reason for hiding this comment

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

auto [](start = 4, length = 4)

we should just give it the correct type, maybe we are over abusing auto here?

Copy link
Author

Choose a reason for hiding this comment

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

CC explicitly allows the use of auto when the type is unwieldy and immediately expressly identified by the right side

Copy link
Contributor

Choose a reason for hiding this comment

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

sure, I feel like this could lead to every single instance of woc:MakeStrong/ woc:* end up being auto.
your call.


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

}

/**
@Status Interoperable
*/
void CGContextSetFontSize(CGContextRef context, CGFloat ptSize) {
NOISY_RETURN_IF_NULL(context);
UNIMPLEMENTED();
auto& state = context->CurrentGState();
state.fontSize = ptSize;
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: context->CurrentGState().fontSize = ptSize;

}

// Internal: used by CoreText.
void CGContextDrawGlyphRun(CGContextRef context, const DWRITE_GLYPH_RUN* glyphRun) {
Copy link
Contributor

Choose a reason for hiding this comment

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

i would be happy if we also check the validity of glyphRun here. It doesn't look like DrawGlyphRunis takes care of this and can crash

Copy link
Author

Choose a reason for hiding this comment

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

This is only called by proper consumers who are aware of the contract.

Copy link
Contributor

Choose a reason for hiding this comment

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

i would suggest to add it at least in the actual function (makes sense to validate it, rather than expecting the user to give it in)
In the future someone decide to be less cautious and call it, we would end up with a crash.

@@ -1878,7 +2035,6 @@ void CGContextShowGlyphs(CGContextRef context, const CGGlyph* glyphs, unsigned c
*/
void CGContextShowGlyphsAtPositions(CGContextRef context, const CGGlyph* glyphs, const CGPoint* Lpositions, size_t count) {
NOISY_RETURN_IF_NULL(context);
// TODO(DH) GH#1070 Merge in CGContextCairo.mm's Glyph Run code.
Copy link
Contributor

Choose a reason for hiding this comment

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

// TODO(DH) GH#1070 Merge in CGContextCairo.mm's Gl [](start = 3, length = 52)

is this being missed? or it's will/not arrive?

Copy link
Author

Choose a reason for hiding this comment

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

This doesn't exist. The dream isn't real.

// Give array of advances of zero so it will use positions correctly
std::vector<FLOAT> dwriteAdvances(count, 0);
DWRITE_GLYPH_RUN run = { fontFace.Get(), state.fontSize, count, glyphs, dwriteAdvances.data(), positions.data(), FALSE, 0 };
THROW_IF_FAILED(context->DrawGlyphRun(&run, false));
Copy link
Contributor

Choose a reason for hiding this comment

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

THROW_IF_FAILED [](start = 4, length = 15)

i thought we settled on fast fail?

Copy link
Author

Choose a reason for hiding this comment

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

Good catch.

//******************************************************************************

#import <CoreGraphics/CGGeometry.h>
#import <Starboard.h>
Copy link
Contributor

Choose a reason for hiding this comment

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

:D

Copy link
Contributor

@msft-Jeyaram msft-Jeyaram left a comment

Choose a reason for hiding this comment

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

🍰

@DHowett-MSFT DHowett-MSFT dismissed msft-Jeyaram’s stale review January 18, 2017 22:24

I fixed the legitimate complaints you had before you submitted this status.

@MSFTFox
Copy link
Member

MSFTFox commented Jan 18, 2017

:shipit:

@DHowett-MSFT DHowett-MSFT merged commit 92ed07c into microsoft:20170118-merge-develop Jan 19, 2017
@DHowett-MSFT DHowett-MSFT deleted the 201701-cgtextbro branch January 19, 2017 00:43
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.

8 participants