Skip to content

Fix bug in font.appendSFNTName#5469

Closed
siroccal wants to merge 1 commit intofontforge:masterfrom
siroccal:patch-3
Closed

Fix bug in font.appendSFNTName#5469
siroccal wants to merge 1 commit intofontforge:masterfrom
siroccal:patch-3

Conversation

@siroccal
Copy link
Copy Markdown

This unneeded if-statement made it impossible to change e.g. the 'Family' SFNT data from 'Sans Bold' to 'Sans'. Fixes #2635.

Type of change

  • Bug fix

This unneeded if-statement made it impossible to change e.g. the 'Family' SFNT data from 'Sans Bold' to 'Sans'. Fixes fontforge#2635.
Copy link
Copy Markdown
Contributor

@skef skef left a comment

Choose a reason for hiding this comment

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

I'm confused by this -- strcmp shouldn't return 0 when comparing "Sans" to "Sans Bold". Are you sure you have the analysis of your problem right?

@siroccal
Copy link
Copy Markdown
Author

siroccal commented Oct 7, 2024

I'm confused by this -- strcmp shouldn't return 0 when comparing "Sans" to "Sans Bold". Are you sure you have the analysis of your problem right?

You can try it out yourself and see it doesn't work properly.
E.g. download Source Sans Pro, extract 'SourceSansPro-Semibold.otf' and try to use appendSFNTName to change the name from 'Source Sans Pro Semibold' to 'Source Sans Pro'. And you'll see it doesn't work:

$ python Code/font-name-fix.py -f 'Source Sans Pro' .local/share/fonts/adobe-source-sans/SourceSansPro-Semibold.otf
The following table(s) in the font have been ignored by FontForge
  Ignoring 'DSIG' digital signature table
$ fc-list | grep -i 'Source Sans Pro'
/home/user/.local/share/fonts/adobe-source-sans/SourceSansPro-Semibold.otf: Source Sans Pro,Source Sans Pro Semibold:style=Semibold,Regular

The font name stays 'Source Sans Pro,Source Sans Pro Semibold'.

But after applying this patch it works properly:

$ python Code/font-name-fix.py -f 'Source Sans Pro' .local/share/fonts/adobe-source-sans/SourceSansPro-Semibold.otf
The following table(s) in the font have been ignored by FontForge
  Ignoring 'DSIG' digital signature table
$ fc-list | grep -i 'Source Sans Pro'
/home/user/.local/share/fonts/adobe-source-sans/SourceSansPro-Semibold.otf: Source Sans Pro:style=Semibold,Regular

Now the font name is just 'Source Sans Pro', as intended.

Here's the python script I used: font-name-fix.txt (just change extension to .py)

@iorsh
Copy link
Copy Markdown
Contributor

iorsh commented Oct 7, 2024

It looks like the solution is slightly different. SetSFNTName() is not called with the real English name values, but rather with default values produced earlier by DefaultTTFEnglishNames(). So when the current value differs from default, but the target value is the default, strcmp() does receive two identical strings and produces 0.

So for the English names the logic should be as follows:

  1. The new name is empty ==> delete entry
  2. The new name equals to default ==> delete entry
  3. The new name differs from default ==> add or overwrite entry

Instead of deleting the if clause entirely we should do

	if ( names!=NULL ) {
	    free( names->names[strid] );
	    names->names[strid] = NULL;
	}
	Py_DECREF(val);

@siroccal
Copy link
Copy Markdown
Author

siroccal commented Oct 8, 2024

It looks like the solution is slightly different. SetSFNTName() is not called with the real English name values, but rather with default values produced earlier by DefaultTTFEnglishNames(). So when the current value differs from default, but the target value is the default, strcmp() does receive two identical strings and produces 0.

So for the English names the logic should be as follows:

1. The new name is empty ==> delete entry

2. **The new name equals to default ==> delete entry**

3. The new name differs from default ==> add or overwrite entry

Instead of deleting the if clause entirely we should do

	if ( names!=NULL ) {
	    free( names->names[strid] );
	    names->names[strid] = NULL;
	}
	Py_DECREF(val);

Yeah, that does also seem to work for me.

Removing the if-statement entirely or doing it your way both seem to work for fixing #2635, so either approach is fine with me. If your way is implemented, then this pull request can be closed.

@skef
Copy link
Copy Markdown
Contributor

skef commented Nov 10, 2024

@iorsh Looks like the author would rather we implement the suggested fix rather than changing this PR. What do you think?

@iorsh
Copy link
Copy Markdown
Contributor

iorsh commented Nov 10, 2024

@iorsh Looks like the author would rather we implement the suggested fix rather than changing this PR. What do you think?

I'm ok with that. Superseding this PR with #5494

@skef skef closed this Nov 11, 2024
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.

appendSFNTName doesn't always replace existing 'Family' value

3 participants