-
Notifications
You must be signed in to change notification settings - Fork 813
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
Conversation
There was a problem hiding this 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.
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) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
CFMutableArrayRef outErrors = nil; | ||
HRESULT ret = S_OK; |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
🕐 |
EXPECT_FALSE(CTFontManagerUnregisterFontsForURL((__bridge CFURLRef)testFileURL, kCTFontManagerScopeSession, &error)); | ||
EXPECT_NE(nullptr, error); | ||
EXPECT_EQ(kCTFontManagerErrorInvalidFontData, CFErrorGetCode(error)); | ||
} |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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)); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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)); | ||
} |
There was a problem hiding this comment.
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.
: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); |
There was a problem hiding this comment.
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
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) |
There was a problem hiding this 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); |
There was a problem hiding this comment.
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()); |
There was a problem hiding this comment.
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??
Missing font files or otherwise incorrect font file data would cause a crash without producing a CFError or returning false.
This change is![Reviewable](https://camo.githubusercontent.com/23b05f5fb48215c989e92cc44cf6512512d083132bd3daf689867c8d9d386888/68747470733a2f2f72657669657761626c652e696f2f7265766965775f627574746f6e2e737667)