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

Fixed metadata that enables fonts to be recognised as a family (tested!) #630

Merged
merged 18 commits into from
Nov 9, 2023
Merged

Conversation

mattlag
Copy link
Contributor

@mattlag mattlag commented Oct 26, 2023

This is an updated version of #606 with a few additions that allow the code to pass npm run test. @Connum, If this gets merged, we can also close #606 .

From @Lmpessoa
I've found out that a few fields that might be passed to opentype.js were not being used while producing the font. I have been able to pinpoint those fields and where they should be applied to produce fonts that are recognised as a family. Tested only with a couple of fonts but changes were regonised by Windows and other apps.

An issue regarding the fields hhea.caretSlopeRise and hhea.caretSlopeRun for italic and oblique fonts is still pending review but does not prevent font usage or recognition as a family (caret slope had a weird inclination while testing on Word but not on Affinity Designer).

These same changes were applied to the copy of the library used by Glyphr Studio (v2) where the tests were conducted.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • I did npm run test and all tests passed green (including code styling checks).
  • I have added tests to cover my changes.
  • My change requires a change to the documentation.
  • I have updated the README accordingly.
  • I have read the CONTRIBUTING document.

Lmpessoa and others added 7 commits July 21, 2023 11:43
I've found out that a few fields that might be passed to opentype.js were not being used while producing the font. I have been able to pinpoint those fields and where they should be applied to produce fonts that are recognised as a family. Tested only with a couple of fonts but changes were regonised by Windows and other apps.

An issue regarding the fields hhea.caretSlopeRise and hhea.caretSlopeRun for italic and oblique fonts is still pending review but does not prevent font usage or recognition as a family (caret slope had a weird inclination while testing on Word but not on Affinity Designer).

These same changes were applied to the copy of the library used by Glyphr Studio (v2) where the tests were conducted.
Copy link
Contributor

@Connum Connum left a comment

Choose a reason for hiding this comment

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

See my one comment, otherwise it looks good.
However, while the current tests are now passing, there are no tests to test the new functionality itself. We should test for

  • the values being calculated/set correctly
  • the panose fallback working and its values and the resulting os2 properties taking on the corresponding values
  • the macStyle value being written correctly

src/font.js Show resolved Hide resolved
Lmpessoa and others added 10 commits November 5, 2023 16:51
I've found out that a few fields that might be passed to opentype.js were not being used while producing the font. I have been able to pinpoint those fields and where they should be applied to produce fonts that are recognised as a family. Tested only with a couple of fonts but changes were regonised by Windows and other apps.

An issue regarding the fields hhea.caretSlopeRise and hhea.caretSlopeRun for italic and oblique fonts is still pending review but does not prevent font usage or recognition as a family (caret slope had a weird inclination while testing on Word but not on Affinity Designer).

These same changes were applied to the copy of the library used by Glyphr Studio (v2) where the tests were conducted.
src/font.js Show resolved Hide resolved
src/tables/head.js Outdated Show resolved Hide resolved
@Connum
Copy link
Contributor

Connum commented Nov 7, 2023

I added two more comments for some minor things. If that and the macStyle bit are resolved, we should be good to go!

@mattlag
Copy link
Contributor Author

mattlag commented Nov 7, 2023

@Connum I marked our conversations as resolved, but please let me know if you have any further comments!

@Connum
Copy link
Contributor

Connum commented Nov 9, 2023

Could you please merge the master branch back in and resolve the conflicts? Then this would be ready to be merged back in!

@mattlag
Copy link
Contributor Author

mattlag commented Nov 9, 2023

Sorry, my inexperience showing again. I'm not sure exactly how to merge the master branch back in.

I see this at the base of the pull request:
image

And in GitHub desktop I see this:
image

@Connum Connum merged commit 3ce8902 into opentypejs:master Nov 9, 2023
1 check passed
@Connum
Copy link
Contributor

Connum commented Nov 9, 2023

It's all good! I wanted to do a rebase first, but squash and merge worked fine. Thanks for your contribution, really appreciated!

@mattlag
Copy link
Contributor Author

mattlag commented Nov 9, 2023

Hey, @Connum, I want to give you a huge thank-you for helping me out. I'm essentially a UX Designer pretending to be a JavaScript developer 😅 so the extra time you put in reviewing my code and helping me out - I really appreciate it!

@mattlag
Copy link
Contributor Author

mattlag commented Nov 9, 2023

@Connum, one last question you may know the answer two - when does opentype.js ship a 'release'? v1.3.1 was released in 2020, what is the criteria for releasing 1.3.2? I want to use this new feature that just got merged. Should I just use a random build, or is 1.3.2 a thing that will happen soon?

@Connum
Copy link
Contributor

Connum commented Nov 9, 2023

That's a good question, and unfortunately this is still to be discussed. Only about a year ago was this project revitalised thanks to @ILOVEPIE 's initiative (see #464), but as it often happens, life and paid work got in the way and active work on the project was dormant for several months again.

Only recently have I found some time to review PRs and issues again and fix bugs myself. There are already some bigger features and refactorings in the master since the last version was released, and several in line in the form of outstanding PRs. Some internally used methods have changed that might have been exposed and used externally, therefore the next release will most probably be 2.0.0.

Meanwhile, I would use the current master as a github dependency (npm install "https://github.com/opentypejs/opentype.js.git#master"), keeping in mind that even though the master branch is protected by required code reviews for each PR and disallowing direct code changes, there might still be the case that something gets messed up or even broken when there is no test catching it. Although I'd say that risk is only marginally higher than with any proper release...

Would be lovely to see more contributions in the future, I'm always happy to help if my time allows!

@mattlag
Copy link
Contributor Author

mattlag commented Nov 9, 2023

This is great, thank you for all the context!

bFamilyType: options.panose[0] || 0,
bSerifStyle: options.panose[1] || 0,
bWeight: options.panose[2] || 0,
bProportion: options.panose[3] || 0,
Copy link

@Finii Finii Sep 10, 2024

Choose a reason for hiding this comment

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

This PR introduces names for the individual Panose values.
I think this is problematic.

When one sees a property bProportion one might assume it has something to do with the font proportion. But the Panose values are ... a mess. The meaning of a certain value depends on the 1st Panose value.

For example with the 4th Panose value panose[3] contains

  • Proportion for Latin Text
  • Spacing for Latin Script and Latin Picture
  • Aspect for Latin Decorative

So I would not call it bProportion as that is an oversimplification. I believe it is best to keep just the array and let interested uses decode it by for example this excellent compilation (by Alan Bernard Hughes) that I usually use for reference:

image
https://forum.high-logic.com/postedfiles/Panose.pdf

Edit: Fix wrong name


Addendum:

The names chosen above are from Panose-1 which was rather simple. But when it has been expanded to be Panose-2 the values became multiple meaning depending on Family Kind.

Just looked it up again in Haralambous: Fonts & Encodings, O'Reilly (2007)

panose

@Connum
Copy link
Contributor

Connum commented Sep 10, 2024

pinging @yne @ILOVEPIE

@yne
Copy link
Contributor

yne commented Sep 10, 2024

not sure if I can be of any help here

@Finii
Copy link

Finii commented Sep 10, 2024

Sorry, "I think this is problematic." is kind of an exaggeration.
I just stumbled about this when I tried to fix Panose.

The real "problem" is described in the new PR #761, which fixes the Panose write operation.

Finii added a commit to Finii/opentype.js that referenced this pull request Sep 10, 2024
[why]
When an existing font file is read from a buffer and then written back
into a buffer all Panose values will be zero.

The problem has been most likly been introduced with PR opentypejs#630 (but I did
not check that).

There are two disjunct data structures in the font.tables.os2 object
that describe the panose values:
* An array with the Panose values `.panose = [ 1, 2, ...]`
* Dedicated properties for each Panose value e.g. `.bFamilyType`

The aforementioned PR seems to address only fonts created from scratch
and not parsed from a buffer.

Writing out the font into a buffer will always use the dedicated Panose
properties and ignore the .panose array.

Parsing a font does set the array but not the dedicated properties. They
are not even existing then.

[how]
When an existing font is parsed the `.panose` array is filled (as
before). But now the dedicated properties are also created and filled
with the individual values.

[note]
The written font is always using the dedicated values. If a user changes
the panose array that will have no effect. There are no checks if the
data is consistent. Having the same data in two disjunct structures is
not so nice to handle.

Signed-off-by: Fini Jastrow <[email protected]>
@Finii Finii mentioned this pull request Sep 10, 2024
8 tasks
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.

5 participants