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 CTFontGetVerticalTranslationsForGlyphs #2104

Merged
merged 1 commit into from
Mar 1, 2017

Conversation

aballway
Copy link
Contributor

@aballway aballway commented Feb 27, 2017

Fixes #2025

There is a magic number that the reference platform adds to every vertical glyph translation independent of font. With this constant added to all vertical translations we are within 1 design unit of reference platform values.

@pradipd
Copy link
Contributor

pradipd commented Feb 27, 2017

Out of curiosity, what is unit of measurement is "1em"? #Closed

@aballway
Copy link
Contributor Author

I mistyped, it should be "design units" but em is arbitrary I think? I still don't 100% grok the differences between the units,

@@ -96,6 +96,9 @@
const CFStringRef kCTFontDefaultItalicFontName = CFSTR("Arial Italic");
const CFStringRef kCTFontDefaultMonospacedFontName = CFSTR("Courier New");

// Reference platform adds a constant amount of space (scaled by font size) to each glyph's vertical translation
static const unsigned int sc_VerticalTranslationSpace = 102;
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: camelCase instead of PascalCase?

@@ -55,9 +55,9 @@ function Get-StagedFiles {

# Formats the given file using ClangFormat
function ClangFormatFile([string]$repoRoot, [string]$filename, [bool]$isDryRun){
$clangCommand = "$repoRoot/tools/scripts/clang-format.ps1"
$clangCommand = "$repoRoot/scripts/git/clang-format.ps1"
Copy link
Contributor

Choose a reason for hiding this comment

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

?

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 branch changed the location of the scripts without updating the scripts, needed to fix this ro get my pre-commit to run

Copy link
Contributor

Choose a reason for hiding this comment

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

oh, i didn't see that this wasn't going into develop. how come that's the case?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Testing the packaging branch basically

Copy link
Contributor

Choose a reason for hiding this comment

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

what's the plan for getting this into develop then? are we cherry-picking it, or will develop not have it until packaging merges?

Copy link
Contributor Author

@aballway aballway Feb 27, 2017

Choose a reason for hiding this comment

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

¯\(ツ)

Copy link
Contributor

Choose a reason for hiding this comment

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

a. We should update the script in a separate change.
b. This will merge to develop when packaging branch merges (or we cherry-pick this to develop if needed).

b ==> a is critical.


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

TEST(CTFont, GetVerticalTranslationsForGLyphs) {
auto font = woc::MakeAutoCF<CTFontRef>(CTFontCreateWithName(CFSTR("Arial"), 20, nullptr));
UniChar chars[4] = { 'T', 'e', 's', 't' };
Copy link
Contributor

Choose a reason for hiding this comment

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

can you also test the translations for ' ' and '_'?

@aballway aballway requested a review from bbowman February 27, 2017 18:22
@ms-jihua
Copy link
Contributor

1em is approximately 1 'character height', and varies depending on font size and designer preference, but is generally = ~the height in px of a capital H at the current font size.

A design unit is a constant fraction, usually 1/1024, of an em. The actual fraction (designUnitsPerEm) is up to the designer, but it's usually something like that. Coordinates for fonts (ie: height of an 'r') are usually specified in whole design units (font coordinates usually don't look like 254.876 of an em).

@rajsesh
Copy link
Contributor

rajsesh commented Feb 27, 2017

https://en.wikipedia.org/wiki/Em_(typography


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

@rajsesh
Copy link
Contributor

rajsesh commented Feb 27, 2017

🕐

return CGSizeZero;
}

return CGSize{ -__CTFontScaleMetric(font, metrics.advanceWidth >> 1),
Copy link
Contributor

Choose a reason for hiding this comment

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

mm, I understand that this >> 1 is probably safe, but the gains here don't seem worth overriding principle of least surprise.

Choose a reason for hiding this comment

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

any compiler worth its salt will optimize /2 to >>1; we can likely rely on that behaviour and prefer /2 where it's clearer.

Choose a reason for hiding this comment

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

parentheses will probably make this clearer too?

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 think that using bitshifts as multiply/divide by powers of two is common enough, and should be a simple enough piece to parse in the future.

Copy link
Contributor

Choose a reason for hiding this comment

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

it's common, but i also had to do a double-take and make sure that advanceWidth wasn't 1) a bit flag somehow 2) a signed int. imma double down and say you should just write what you mean here and let the compiler optimize.

Choose a reason for hiding this comment

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

/me assists with the doubling down

CTFontGetVerticalTranslationsForGlyphs(font, glyphs, translations, 4);
EXPECT_NEAR(-6.108, translations[0].width, c_errorMargin);
EXPECT_NEAR(-5.562, translations[1].width, c_errorMargin);
UniChar chars[6] = { 'T', 'e', 's', 't', ' ', '_' };
Copy link
Contributor

Choose a reason for hiding this comment

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

vaguely interested in '-' and '|' also, but we probably won't find anything surprising, so i'll leave it up to you

@pradipd
Copy link
Contributor

pradipd commented Feb 27, 2017

Thanks for the info.


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

@rajsesh
Copy link
Contributor

rajsesh commented Feb 27, 2017

Pending other approvals of course.

@msft-Jeyaram
Copy link
Contributor

msft-Jeyaram commented Feb 27, 2017

static const wchar_t* g_logTag = L"CTFont";

nit: what does the g means? #Closed


Refers to: Frameworks/CoreText/CTFont.mm:41 in a2dac20. [](commit_id = a2dac20, deletion_comment = False)

TEST(CTFont, GetVerticalTranslationsForGLyphs) {
auto font = woc::MakeAutoCF<CTFontRef>(CTFontCreateWithName(CFSTR("Arial"), 20, nullptr));
UniChar chars[6] = { 'T', 'e', 's', 't', ' ', '_' };
Copy link
Contributor

Choose a reason for hiding this comment

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

UniChar [](start = 4, length = 7)

UniChar? no shouty

Copy link
Contributor Author

Choose a reason for hiding this comment

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

UniChar is from CF?

@aballway
Copy link
Contributor Author

static const wchar_t* g_logTag = L"CTFont";

global, presumably. Not related to this PR though


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


Refers to: Frameworks/CoreText/CTFont.mm:41 in a2dac20. [](commit_id = a2dac20, deletion_comment = False)

@DHowett-MSFT
Copy link

@msft-Jeyaram UniChar isn't shouty; UNICHAR would be!

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.

Please make sure this is in two different commits (one for the packaging change, one for the implementation) before merging.

return CGSizeZero;
}

return CGSize{ -__CTFontScaleMetric(font, metrics.advanceWidth >> 1),

Choose a reason for hiding this comment

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

/me assists with the doubling down

@msft-Jeyaram
Copy link
Contributor

:p I figured after i made the comment LOL


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

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.

do the commit thing tho

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.

+1 to do the commit thing

@aballway aballway merged commit 3740a7e into microsoft:packaging Mar 1, 2017
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.

7 participants