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

Handle missing font files more gracefully #1486

Merged
merged 5 commits into from
Dec 2, 2016

Conversation

aballway
Copy link
Contributor

@aballway aballway commented Dec 1, 2016

Missing font files or otherwise incorrect font file data would cause a crash without producing a CFError or returning false.


This change is Reviewable

rajsesh
rajsesh previously requested changes Dec 1, 2016
Copy link
Contributor

@rajsesh rajsesh left a comment

Choose a reason for hiding this comment

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

In this case, these are tests and the failures in the build machine is because of missing test data. We need to understand why the test data files are not in the right place and fix that rather than trying to ignore them in the tests.

@aballway
Copy link
Contributor Author

aballway commented Dec 1, 2016

This isn't to fix the error in the build machine, rather the build machine error showed that my changes did not handle the error well and I lacked tests to check that, which is what this fixes.

@@ -66,7 +66,9 @@ - (NSUInteger)length {
CGDataProviderRef CGDataProviderCreateWithURL(CFURLRef url) {
NSString* path = [static_cast<NSURL*>(url) path];
CGDataProvider* ret = [[CGDataProvider alloc] initWithContentsOfFile:path];
ret->filename = path;
if (ret) {
Copy link
Contributor

Choose a reason for hiding this comment

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

this and CGDataProviderCreateWithFilename are pretty much the same logic.
re-use/refactor. rather than introducing the same code path.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This will all be changed for #1450 #WontFix

@msft-Jeyaram
Copy link
Contributor

filename = nil;

nit: remove


Refers to: Frameworks/CoreGraphics/CGDataProvider.mm:33 in 04cd65c. [](commit_id = 04cd65c, deletion_comment = False)

CFMutableArrayRef outErrors = nil;
HRESULT ret = S_OK;
Copy link
Contributor

Choose a reason for hiding this comment

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

ret [](start = 16, length = 3)

nit: result

}

return SUCCEEDED(func(fontDatas.get(), errors));
// S_FALSE represents partial failure so cannot use SUCCEEDED macro
Copy link
Contributor

Choose a reason for hiding this comment

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

why use S_FALSE?
Are you expecting partial failure?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It made more sense to use S_FALSE than E_* that might mean a more fatal failure than what we're experiencing

@@ -729,19 +730,24 @@ void AddDatas(CFArrayRef fontDatas, CFArrayRef* errors) {
if (data) {
if (CFSetContainsValue(m_fontDatasSet.get(), data)) {
__AppendErrorIfExists(outErrors, kCTFontManagerErrorAlreadyRegistered);
ret = S_FALSE;
Copy link
Contributor

Choose a reason for hiding this comment

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

why does this have to be S_FALSE?
Are you expecting this to succeed, where you have failures?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is created with a list of font files, so should one fail we need to return that it failed but still un(register) whatever fonts were valid

@msft-Jeyaram
Copy link
Contributor

🕐

EXPECT_FALSE(CTFontManagerUnregisterFontsForURL((__bridge CFURLRef)testFileURL, kCTFontManagerScopeSession, &error));
EXPECT_NE(nullptr, error);
EXPECT_EQ(kCTFontManagerErrorInvalidFontData, CFErrorGetCode(error));
}
Copy link
Contributor

Choose a reason for hiding this comment

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

addition of registering/unregistering multiple fonts test would be useful.

Copy link
Contributor

Choose a reason for hiding this comment

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

+1, this is a good point that I missed in the previous PR


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

@@ -85,7 +85,19 @@
TEST(CTFontManager, ShouldFailToUnregisterNonregisteredFonts) {
NSURL* testFileURL = __GetURLFromPathRelativeToModuleDirectory(@"/data/WinObjC.ttf");
CFErrorRef error = nullptr;
EXPECT_TRUE(CTFontManagerUnregisterFontsForURL((__bridge CFURLRef)testFileURL, kCTFontManagerScopeSession, &error));
Copy link
Contributor

Choose a reason for hiding this comment

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

what happened here?
How does this behave on the ref platform?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It should return false, this was an error

EXPECT_FALSE(CTFontManagerUnregisterFontsForURL((__bridge CFURLRef)testFileURL, kCTFontManagerScopeSession, &error));
EXPECT_NE(nullptr, error);
EXPECT_EQ(kCTFontManagerErrorInvalidFontData, CFErrorGetCode(error));
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Add a test to attempt to register the same font.

@rajsesh
Copy link
Contributor

rajsesh commented Dec 1, 2016

:face_palm: apologies for the confusion.


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

@@ -667,7 +664,7 @@ HRESULT STDMETHODCALLTYPE GetCurrentFontFile(_Out_ IDWriteFontFile** fontFile) {
RETURN_HR_IF(E_ILLEGAL_METHOD_CALL, m_location < 0 || m_location > CFArrayGetCount(m_fontDatas.get()));

if (0 <= m_location && m_location < m_previouslyCreatedFiles->size()) {
*fontFile = m_previouslyCreatedFiles->at(m_location).Get();
m_previouslyCreatedFiles->at(m_location).CopyTo(fontFile);
Copy link
Contributor

Choose a reason for hiding this comment

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

opyTo(fontFile); [](start = 54, length = 16)

:D

@ms-jihua
Copy link
Contributor

ms-jihua commented Dec 1, 2016

// TODO: #1250: Need to be able to load fonts from the app's bundle

iirc iOS behavior is to return nil for an unfound font, but OSX returns a default font. as such i'd like to keep this?


Refers to: Frameworks/CoreGraphics/DWriteWrapper.mm:411 in 04cd65c. [](commit_id = 04cd65c, deletion_comment = True)

Copy link
Contributor

@ms-jihua ms-jihua left a comment

Choose a reason for hiding this comment

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

Just need to keep that comment

woc::unique_cf<CTFontRef> secondFont{ CTFontCreateWithName(secondFontName.get(), 20, nullptr) };
EXPECT_NE(nullptr, secondFont);
StrongId<NSString> secondName = (NSString*)CTFontCopyFullName(secondFont.get());
EXPECT_OBJCEQ(@"WinObjC Italic", secondName);
Copy link
Contributor

Choose a reason for hiding this comment

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

you have repeated code here and in few other tests that do the same thing.
Consider using a general function. This can help add more tests in the future.


woc::unique_cf<CTFontRef> firstFont{ CTFontCreateWithName(firstFontName.get(), 20, nullptr) };
EXPECT_NE(nullptr, firstFont);
StrongId<NSString> firstName = (NSString*)CTFontCopyFullName(firstFont.get());
Copy link
Contributor

Choose a reason for hiding this comment

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

tring> firstName = (NSString*)CTFontCopyFullName(firstFont.get()); [](start = 16, length = 66)

this feels wrong. The general = causes a retain??

@aballway aballway dismissed rajsesh’s stale review December 2, 2016 20:06

It was a misunderstanding

@aballway aballway merged commit 56fe72e into microsoft:develop Dec 2, 2016
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.

None yet

6 participants