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

Implement CTFontCopyLocalizedName and CTFontCopyAvailableTables #2058

Merged
merged 7 commits into from
Mar 2, 2017

Conversation

aballway
Copy link
Contributor

Fixes #2023

@@ -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);
Copy link
Contributor

@msft-Jeyaram msft-Jeyaram Feb 23, 2017

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);
Copy link
Contributor

@msft-Jeyaram msft-Jeyaram Feb 23, 2017

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,
Copy link
Contributor

@msft-Jeyaram msft-Jeyaram Feb 23, 2017

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

Copy link
Contributor

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";
Copy link
Contributor

@msft-Jeyaram msft-Jeyaram Feb 23, 2017

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");
Copy link
Contributor

@msft-Jeyaram msft-Jeyaram Feb 23, 2017

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));
Copy link
Contributor

@msft-Jeyaram msft-Jeyaram Feb 23, 2017

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

@msft-Jeyaram
Copy link
Contributor

msft-Jeyaram commented Feb 23, 2017

@notes Returns family name

super nit: I feel the note here could be better.
Just saying returns family name doesn't help.
So It doesn't return the full name and 'only' returns family name? #WontFix


Refers to: Frameworks/CoreGraphics/CGFont.mm:225 in 031bf91. [](commit_id = 031bf91, deletion_comment = False)

@Status Stub
@Notes
@Status Interoperable
@Notes options is not supported, and is deprecated anyway
Copy link
Contributor

@msft-Jeyaram msft-Jeyaram Feb 23, 2017

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);
Copy link
Contributor

@msft-Jeyaram msft-Jeyaram Feb 23, 2017

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));
Copy link
Contributor

@msft-Jeyaram msft-Jeyaram Feb 23, 2017

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);
Copy link
Contributor

@msft-Jeyaram msft-Jeyaram Feb 23, 2017

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

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.

:

@@ -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) {
Copy link
Contributor

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);
Copy link
Contributor

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?

Copy link
Contributor Author

@aballway aballway Feb 23, 2017

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>
Copy link
Contributor

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?

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 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?

Copy link
Contributor

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.

@@ -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) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Not a stub anymore.

@Status Stub
@Notes
@Status Interoperable
@Notes options is not supported, and is deprecated anyway
Copy link
Contributor

Choose a reason for hiding this comment

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

Caveat instead.

Copy link
Contributor Author

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

Copy link
Contributor

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 :)

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.

Leave a comment

Copy link

@DHowett-MSFT DHowett-MSFT left a 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);

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) {
Copy link

@DHowett-MSFT DHowett-MSFT Feb 24, 2017

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'

Choose a reason for hiding this comment

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

l o l

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.

Copy link
Contributor

@ms-jihua ms-jihua Feb 24, 2017

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)

Copy link
Contributor Author

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"

@DHowett-MSFT
Copy link

DHowett-MSFT commented Feb 24, 2017 via email

@aballway
Copy link
Contributor Author

aballway commented Mar 1, 2017

ping @rajsesh-msft @msft-Jeyaram

@aballway aballway merged commit 5c54820 into microsoft:develop Mar 2, 2017
@aballway aballway deleted the ct branch April 25, 2017 16:25
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.

6 participants