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 "Link Metrics..." custom parameters #641

Merged
merged 11 commits into from
Apr 1, 2021
Merged

Implement "Link Metrics..." custom parameters #641

merged 11 commits into from
Apr 1, 2021

Conversation

jenskutilek
Copy link
Contributor

If the custom parameters "Link Metrics To Master" or "Link Metrics To First Master" are present, this will apply glyph layer widths and kerning from the referenced source master.

Fixes #256.

Base automatically changed from master to main February 17, 2021 12:38
Copy link
Collaborator

@simoncozens simoncozens left a comment

Choose a reason for hiding this comment

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

Thanks so much for this! I spoke to someone today who needed this functionality.

What you have here works fine, but it's a bit clumsy - a lot of repetition of the source-finding code. Instead, we could have a metrics_source method on a GSFontMaster object which returns the right master - either the master itself if no custom parameters are set, or the correct master/first master based on custom parameter.

Then you only need to do that search in the one place, and you can get the width information from self.font.glyphs[glyph.name].layers[master.metrics_source.id].width and the kerning information from self.font.masters[master_id].metrics_source.kerning.

Let me know if you want any help implementing that, or if you don't have time to make the changes, let me know and I'll do it.

Lib/glyphsLib/builder/glyph.py Outdated Show resolved Hide resolved
Lib/glyphsLib/builder/glyph.py Outdated Show resolved Hide resolved
Lib/glyphsLib/builder/glyph.py Outdated Show resolved Hide resolved
Lib/glyphsLib/builder/kerning.py Outdated Show resolved Hide resolved
@simoncozens simoncozens requested review from anthrotype and madig April 1, 2021 10:44
@simoncozens
Copy link
Collaborator

I've finished off Jens' PR. Would be good for another pair of eyes to OK my changes.

@google-cla
Copy link

google-cla bot commented Apr 1, 2021

All (the pull request submitter and all commit authors) CLAs are signed, but one or more commits were authored or co-authored by someone other than the pull request submitter.

We need to confirm that all authors are ok with their commits being contributed to this project. Please have them confirm that by leaving a comment that contains only @googlebot I consent. in this pull request.

Note to project maintainer: There may be cases where the author cannot leave a comment, or the comment is not properly detected as consent. In those cases, you can manually confirm consent of the commit author(s), and set the cla label to yes (if enabled on your project).

ℹ️ Googlers: Go here for more info.

@simoncozens
Copy link
Collaborator

@googlebot I consent.

@simoncozens simoncozens requested review from simoncozens and removed request for simoncozens April 1, 2021 11:20
width = metric_layer.width
else:
width = None
if layer.width != width:
Copy link
Member

Choose a reason for hiding this comment

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

you're only applying it if width is not None (or if metric_layer is true); the != may catch the case when width is None and layer.width is not None and trigger the logging debug message, when in fact you haven't applied anything because width was None. I think the logger.debug() call should be moved in the if metric_layer: branch after you override width = metric_layer.width


from .glyph import BRACKET_GLYPH_RE

logger = logging.getLogger(__name__)
Copy link
Member

Choose a reason for hiding this comment

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

where is this logger being used?

return os.path.join(os.path.dirname(__file__), "data", "LinkMetrics.glyphs")


class UtilTest(unittest.TestCase):
Copy link
Member

Choose a reason for hiding this comment

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

you are using plain assert .. == ... like in pytest-style tests but then you're sublcassing from unittest.TestCase.. Either you subclass TestCase and then use unittest-style self.assertEqual(etc.) or you simply use pytest-style testing and remove the subclassing from unittest.TestCase. You can still group pytest tests as instance methods by creating the test class and naming it such that it starts with the string "Test" (see https://docs.pytest.org/en/reorganize-docs/new-docs/user/naming_conventions.html). We can configure pytest so that it also recognizes class names that ends with "Test" but it's simpler if you rename it TestUtil.
I prefer that you use pytest-style for newly added tests.
The test runner in pytest anyway and it understand both. But mixing ways the two like you do here is incorrect.

@anthrotype
Copy link
Member

@jenskutilek the googlebot wants you to also reply "I consent" before it's happy

@simoncozens
Copy link
Collaborator

Thanks, good catches.

@simoncozens
Copy link
Collaborator

@jenskutilek the googlebot wants you to also reply "I consent" before it's happy

No, it's happy enough now, because @jenskutilek was the PR originator.

@anthrotype
Copy link
Member

No, it's happy enough now

yeah you're right

Copy link
Member

@anthrotype anthrotype left a comment

Choose a reason for hiding this comment

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

LGTM

@simoncozens simoncozens merged commit 19b26b6 into googlefonts:main Apr 1, 2021
@jenskutilek
Copy link
Contributor Author

Thank you @simoncozens for picking this up!

@jenskutilek jenskutilek deleted the link-metrics-custom-param branch April 3, 2021 15:04
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.

Custom parameter "Link Metrics With Master" support is not complete
3 participants