-
Notifications
You must be signed in to change notification settings - Fork 806
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
Implement CTFontCopyLocalizedName and CTFontCopyAvailableTables #2058
Conversation
Frameworks/CoreGraphics/CGFont.mm
Outdated
@@ -151,7 +151,7 @@ CGFontRef CGFontCreateCopyWithVariations(CGFontRef font, CFDictionaryRef variati | |||
*/ | |||
CFStringRef CGFontCopyPostScriptName(CGFontRef font) { | |||
RETURN_NULL_IF(!font); | |||
return _DWriteFontCopyInformationalString(font->_dwriteFontFace, DWRITE_INFORMATIONAL_STRING_POSTSCRIPT_NAME); | |||
return _DWriteFontCopyInformationalString(font->_dwriteFontFace, DWRITE_INFORMATIONAL_STRING_POSTSCRIPT_NAME, nullptr); |
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 don't use just use default parameter?
You can leave these as is. #Resolved
@@ -35,7 +35,7 @@ static inline CFStringRef _CFStringCreateUppercaseCopy(CFStringRef string) { | |||
return ret; | |||
} | |||
|
|||
COREGRAPHICS_EXPORT CFStringRef _CFStringFromLocalizedString(IDWriteLocalizedStrings* localizedString); | |||
COREGRAPHICS_EXPORT CFStringRef _CFStringFromLocalizedString(IDWriteLocalizedStrings* localizedString, CFStringRef* language); |
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.
CFStringRef* language = nullptr
This saves you from all the extra null addition changes. #Resolved
@@ -65,7 +65,8 @@ COREGRAPHICS_EXPORT HRESULT _DWriteCreateTextFormatWithFontNameAndSize(CFStringR | |||
|
|||
// DWriteFont getters that convert to a CF/CG object or struct | |||
COREGRAPHICS_EXPORT CFStringRef _DWriteFontCopyInformationalString(const Microsoft::WRL::ComPtr<IDWriteFontFace>& fontFace, |
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.
_DWriteFontCopyInformationalString [](start = 32, length = 34)
same here
CFStringRef* language = nullptr #Resolved
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.
given these are private methods, this should make life easier.
In reply to: 102774998 [](ancestors = 102774998)
} | ||
|
||
const NSString* c_localeName = @"en-us"; |
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.
c_localeName [](start = 16, length = 12)
static #Resolved
TEST(CTFont, CopyLocalizedName) { | ||
auto fontName = woc::MakeAutoCF<CFStringRef>(CFSTR("Metadata Test")); | ||
StrongId<NSURL> testFileURL = __GetURLFromPathRelativeToModuleDirectory(@"/data/MetadataTest-Regular.ttf"); |
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.
MetadataTest [](start = 84, length = 12)
nit: make it a const? #WontFix
// Don't want to make test too precise so that it may fail should fonts change, but 'cmap' is a required font table | ||
// So it should be safe to always test that this value is available | ||
EXPECT_TRUE(CFArrayContainsValue(availableTables, { 0, count }, (const void*)kCTFontTableCmap)); |
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.
(const void*) [](start = 68, length = 13)
nit: c++ cast #WontFix
super nit: I feel the note here could be better. Refers to: Frameworks/CoreGraphics/CGFont.mm:225 in 031bf91. [](commit_id = 031bf91, deletion_comment = False) |
Frameworks/CoreText/CTFont.mm
Outdated
@Status Stub | ||
@Notes | ||
@Status Interoperable | ||
@Notes options is not supported, and is deprecated anyway |
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.
anyway [](start = 52, length = 6)
super nit: 'anyway' is not needed #WontFix
@@ -62,10 +62,12 @@ CTFontSymbolicTraits _CTFontSymbolicTraitsFromCFNumber(CFNumberRef num); | |||
HRESULT _DWriteCreateFontFaceWithFontDescriptor(CTFontDescriptorRef fontDescriptor, IDWriteFontFace** fontFace); | |||
|
|||
CFDictionaryRef _DWriteFontCreateTraitsDict(const Microsoft::WRL::ComPtr<IDWriteFontFace>& fontFace); | |||
CFStringRef _DWriteFontCopyName(const Microsoft::WRL::ComPtr<IDWriteFontFace>& fontFace, CFStringRef nameKey); | |||
CFStringRef _DWriteFontCopyName(const Microsoft::WRL::ComPtr<IDWriteFontFace>& fontFace, CFStringRef nameKey, CFStringRef* actualLanguage); |
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.
actualLanguage [](start = 123, length = 14)
same here with the default argument #Resolved
void* tableContext; | ||
BOOL exists; | ||
|
||
RETURN_NULL_IF_FAILED(fontFace->TryGetFontTable(_CTToDWriteFontTableTag(tag), &tableData, &tableSize, &tableContext, &exists)); |
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.
tableContext [](start = 111, length = 12)
nit: c++ cast #WontFix
auto copyrightName = woc::MakeAutoCF<CFStringRef>(CTFontCopyLocalizedName(font, kCTFontCopyrightNameKey, &actualLanguage)); | ||
EXPECT_OBJCEQ(c_copyrightName, (__bridge NSString*)copyrightName.get()); | ||
ASSERT_NE(nil, actualLanguage); |
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.
actualLanguage [](start = 19, length = 14)
nit: if actualLanguage was nil, this would never run.
Given they are not dependent, They should be able to be evaluated regardless. #Resolved
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.
:
@@ -284,7 +284,7 @@ static CFDictionaryRef _DWriteFontCreateTraitsDict(const ComPtr<IDWriteFontFace> | |||
/** | |||
* Gets a name/informational string from a DWrite font face corresponding to a CTFont constant | |||
*/ | |||
CFStringRef _DWriteFontCopyName(const ComPtr<IDWriteFontFace>& fontFace, CFStringRef nameKey) { | |||
CFStringRef _DWriteFontCopyName(const ComPtr<IDWriteFontFace>& fontFace, CFStringRef nameKey, CFStringRef* actualLanuguage) { |
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.
actualLanuguage [](start = 107, length = 15)
nit: typo
RETURN_NULL_IF_FAILED(fontFace->TryGetFontTable(_CTToDWriteFontTableTag(tag), &tableData, &tableSize, &tableContext, &exists)); | ||
if (exists) { | ||
// Returned array is expected to have unboxed CTFontTableTag values | ||
CFArrayAppendValue(ret, (const void*)tag); |
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.
surprised this doesn't screw with the memory management on the CFArray... can you run your tests under appverifier and make sure there are no issues?
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 array isn't using any memory management callbacks so it shouldn't be leaking anything, but it's worth checking.
Update: no leaks!
@@ -97,8 +97,9 @@ HRESULT UpdateCollection(const ComPtr<IDWriteFactory>& dwriteFactory, const ComP | |||
} | |||
|
|||
// Private helper, wraps around GetUserDefaultLocaleName() and returns a default of "en-us" if it fails | |||
static inline const wchar_t* __GetUserDefaultLocaleName(wchar_t* buf, size_t bufferSize) { | |||
int defaultLocaleSuccess = GetUserDefaultLocaleName(buf, bufferSize); | |||
template <size_t size> |
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 result in an instance of this method for every size. could we just use _countof() where size is needed in the previous version of this?
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 only being used with buffers of size LOCALE_NAME_MAX_LENGTH, so there will only be one instance, but I didn't think it made sense to do any calculation or pass in a parameter when the size is known at compile-time. Would _countof work w/ function arg?
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.
I don't see any issue with that. It is standard practice to pass a buffer and a length. Now you are constrained to passing an array instead.
Frameworks/CoreText/CTFont.mm
Outdated
@@ -493,17 +493,16 @@ CFStringRef CTFontCopyDisplayName(CTFontRef font) { | |||
@Status Interoperable | |||
*/ | |||
CFStringRef CTFontCopyName(CTFontRef font, CFStringRef nameKey) { | |||
RETURN_NULL_IF(!font); | |||
return _DWriteFontCopyName(font->_dwriteFontFace, nameKey); | |||
return CTFontCopyLocalizedName(font, nameKey, nullptr); | |||
} | |||
|
|||
/** | |||
@Status Stub | |||
@Notes | |||
*/ | |||
CFStringRef CTFontCopyLocalizedName(CTFontRef font, CFStringRef nameKey, CFStringRef _Nullable* actualLanguage) { |
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.
Not a stub anymore.
Frameworks/CoreText/CTFont.mm
Outdated
@Status Stub | ||
@Notes | ||
@Status Interoperable | ||
@Notes options is not supported, and is deprecated anyway |
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.
Caveat instead.
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.
I was going off of the decision w/ CTFontCopyTable where we're still marking it Interoperable despite not supporting kCTFontTableOptionExcludeSynthetic
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.
I think they should all be caveats :)
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.
Leave a comment
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.
:clock1024:
@Notes | ||
*/ | ||
CFStringRef CTFontCopyLocalizedName(CTFontRef font, CFStringRef nameKey, CFStringRef _Nullable* actualLanguage) { | ||
UNIMPLEMENTED(); | ||
return StubReturn(); | ||
RETURN_NULL_IF(!font); |
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 is this a RETURN_NULL_IF
but the other functions in this file are return x ? : nullptr
?
kCTFontTableProp, kCTFontTableSbit, kCTFontTableSbix, kCTFontTableTrak, kCTFontTableVhea, | ||
kCTFontTableVmtx }; | ||
|
||
CFArrayRef _DWriteCopyAvailableFontTables(const ComPtr<IDWriteFontFace>& fontFace) { |
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.
nit: prefer taking ComPtr values by unboxed ptr
I know there's precedent for doing the wrong thing in this code, so it may not be worth fixing. #WontFix
|
||
inline uint32_t _CTToDWriteFontTableTag(uint32_t tag) { | ||
// CT has the opposite byte order of DWrite, so we need 'BASE' -> 'ESAB' |
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.
l o l
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 like we've done with some CG constants, we can simply force these to have the values we want them to.
That'll reduce stuff like this down to, say, not existing at all.
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.
A dev can pass in a specific tag for CTFontCopyTable though. We'd at least need to keep the function around (though I guess we could reverse the internal constants)
EDIT: Forget I said anything, for some reason I thought the tags were strings (plausible to pass in raw) rather than ints (pretty unlikely)
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.
I can see that case where someone would just use 'BASE' or something. The values are public and the conversion is cheap so I think it's worth it to just do the conversion "Just in case"
Ah, I see. I didn’t see that it allowed freeform input.
|
ping @rajsesh-msft @msft-Jeyaram |
Fixes #2023