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

Add metrics to transformations filter #238

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

moyogo
Copy link
Collaborator

@moyogo moyogo commented Mar 26, 2018

Add LSB, RSB arguments but also TSB, BSB and VerticalOrigin.

if self.options.BSB:
ctx.metrics["bottomMargin"] = self.options.BSB
if self.options.VerticalOrigin:
ctx.metrics["verticalOrigin"] = self.options.VerticalOrigin
Copy link
Member

@anthrotype anthrotype Mar 26, 2018

Choose a reason for hiding this comment

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

why don't you just use the metrics values defined in self.options? The context is only for stuff that may vary from glyph to another, but this options should be global for all the glyphs processed by this filter instance.

Copy link
Member

Choose a reason for hiding this comment

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

stuff that may vary from glyph to another

sorry, I meant stuff that may vary from one font to another.

I see, you're mapping the Glyphs.app-specific option names (e.g. LSB, RSB) to defcon Glyph-specific attribute names (e.g. "leftMargin", "rightMargin").
I think this should be moved to start method, which is run only once at filter initialization, since it is not dependent on the font you're currenty running the filter onto.

@moyogo moyogo force-pushed the transformations-metrics branch from 5bc1c7d to 9bbdebb Compare March 26, 2018 16:06
else:
logger.warning(
"Cannot add %i to undefined %s in %s",
value, attr, glyph.name
Copy link
Member

Choose a reason for hiding this comment

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

minor suggestion: you don’t need to increment value +=current_value, just setattr(glyph, attr, current_value+value)

["c", "d"])
def test_verticalOrigin_undefined(self, font, name):
value = +14
with CapturingLogHandler(logger, level="WARNING") as captor:
Copy link
Member

Choose a reason for hiding this comment

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

Since we are doing pytest-style tests you could use the caplog fixture

@anthrotype
Copy link
Member

@moyogo @madig what's the status of this?

@moyogo
Copy link
Collaborator Author

moyogo commented May 24, 2018

We need to change the way filter strings are parsed in glyphLib. Width:+30, which should add 30 to the width, doesn’t mean the same asWidth:30 or Width:=30 or Width:=+30, which should set the width to 30.

@anthrotype
Copy link
Member

@moyogo so, about https://github.com/googlei18n/ufo2ft/pull/238/files#diff-866da416f2f593dfda48548e538d877aR86

I see you are using leftMargin, righMargin, etc. Now, I think this is a bit problematic, for two reasons,
which are interrelated in a way.

The glyphs we are operating on are parent-less, they are copies of the original without a reference to their parent font. For components, that means they cannot get their own "bounds" by themselves without requiring the glyph set they are within. Besides, in ufoLib2 the glyph objects don't have a parent (they never have, not just when they are duplicated out of a font).

If you look at the outlineCompiler, you'll see we don't use leftMargin and rightMargin attributes to build the htmx; but we make the bounding boxes ourselves at the beginning for the whole glyphSet and compute the margins accordingly

Maybe in set_context method of Transformations filter, we should compute the bounding boxes the same way that the outlineCompiler does (we could turn that method in a function and move it to the ufo2ft.util module so both outlineCompiler and the Transformations filter can use it)
Since it may be expensive operation, you'd do that only if there are any metrics specific options set in the Transformation filter

Setting the leftMargin basically means redrawing the glyph's outline but shifted horizontally, plus modifying the advance at the same time (see how defcon implements that).

You see, I'm reluctant to add a parent attribute to the ufoLib2 objects. I don't like these recursive cross-references between containers and contained objects. I'd like to keep them as pure data classes without too much built-in intelligence

@anthrotype
Copy link
Member

this PR is stale. Is there still interest in this?

@anthrotype
Copy link
Member

hm, I guess this depends on googlefonts/glyphsLib#366 being fixed first, right @moyogo?

@moyogo
Copy link
Collaborator Author

moyogo commented Sep 26, 2018

Yes #366 should be fixed first.

Base automatically changed from master to main March 1, 2021 09:01
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.

2 participants