-
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 CTFontGetVerticalTranslationsForGlyphs #2104
Conversation
Out of curiosity, what is unit of measurement is "1em"? #Closed |
I mistyped, it should be "design units" but em is arbitrary I think? I still don't 100% grok the differences between the units, |
Frameworks/CoreText/CTFont.mm
Outdated
@@ -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; |
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: camelCase instead of PascalCase?
scripts/git/common.ps1
Outdated
@@ -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" |
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.
?
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 branch changed the location of the scripts without updating the scripts, needed to fix this ro get my pre-commit to run
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.
oh, i didn't see that this wasn't going into develop. how come that's the case?
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.
Testing the packaging branch basically
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's the plan for getting this into develop then? are we cherry-picking it, or will develop not have it until packaging merges?
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.
¯\(ツ)/¯
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. 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' }; |
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.
can you also test the translations for ' ' and '_'?
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). |
https://en.wikipedia.org/wiki/Em_(typography In reply to: 282806234 [](ancestors = 282806234) |
🕐 |
Frameworks/CoreText/CTFont.mm
Outdated
return CGSizeZero; | ||
} | ||
|
||
return CGSize{ -__CTFontScaleMetric(font, metrics.advanceWidth >> 1), |
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.
mm, I understand that this >> 1 is probably safe, but the gains here don't seem worth overriding principle of least surprise.
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.
any compiler worth its salt will optimize /2
to >>1
; we can likely rely on that behaviour and prefer /2 where it's clearer.
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.
parentheses will probably make this clearer too?
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 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.
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'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.
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.
/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', ' ', '_' }; |
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.
vaguely interested in '-' and '|' also, but we probably won't find anything surprising, so i'll leave it up to you
Thanks for the info. In reply to: 282799721 [](ancestors = 282799721) |
Pending other approvals of course. |
TEST(CTFont, GetVerticalTranslationsForGLyphs) { | ||
auto font = woc::MakeAutoCF<CTFontRef>(CTFontCreateWithName(CFSTR("Arial"), 20, nullptr)); | ||
UniChar chars[6] = { 'T', 'e', 's', 't', ' ', '_' }; |
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.
UniChar [](start = 4, length = 7)
UniChar? no shouty
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.
UniChar is from CF?
@msft-Jeyaram |
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.
Please make sure this is in two different commits (one for the packaging change, one for the implementation) before merging.
Frameworks/CoreText/CTFont.mm
Outdated
return CGSizeZero; | ||
} | ||
|
||
return CGSize{ -__CTFontScaleMetric(font, metrics.advanceWidth >> 1), |
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.
/me assists with the doubling down
:p I figured after i made the comment LOL In reply to: 282899498 [](ancestors = 282899498) |
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.
do the commit thing tho
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 to do the commit thing
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.