111 Commits

Author SHA1 Message Date
Cosimo Lupo
afd73dd2b1
NameRecordVisitor: remove unnecessary check for out of bounds nameIDs 2024-08-30 18:20:13 +01:00
Cosimo Lupo
8f01590353
FeatureParamsSize.SubfamilyID is *not* actually a NameID 2024-08-30 18:20:12 +01:00
Cosimo Lupo
821f37329e
NameRecordVisitor: include whole sequence of UI labels for character variants, not just first
Fixes #3616
2024-08-30 18:20:12 +01:00
Khaled Hosny
ae31d05605 [ttLib] Fix warning when calling addMultilingualName() with "ar" name
I get warning from _makeMacName() because it does not have a TTFont, but
the font is there, just not passed from addMultilingualName() ->
findMultilingualName() -> _makeMacName().
2023-08-13 14:21:32 +03:00
Behdad Esfahbod
530e409416 [name] Speed up NameRecordVisitor
Don't visit large tables without any name records.
2023-07-20 10:16:04 -06:00
Behdad Esfahbod
d27cc3abf8 Revert "Merge pull request #3214 from fonttools/subset-speed-regression"
This reverts commit f7965ba0086ebad9e3fa103935dc2edf41ffe780, reversing
changes made to 31319a7ef218237eea7cd6713ec29032a5cdd752.
2023-07-20 10:16:04 -06:00
Cosimo Lupo
687e23cf3f
[NameVisitor] remove logging, caller can log if they wish 2023-07-20 10:27:30 +01:00
Marc Foley
cfede76fd9 Implement Cosimo feedback 2023-07-10 15:01:40 +01:00
Marc Foley
edf8891fba Use NameRecordVisitor in subsetter 2023-06-27 15:23:56 +01:00
Marc Foley
a792851131 add removeUnusedNames staticmethod to name table 2023-06-27 12:06:18 +01:00
Johannes Neumeier
29f980135a Clean up and NotImplemented as proper return value 2023-02-27 09:31:13 +02:00
Johannes Neumeier
f52b3da721 Make NameRecord comparison not fail on encoding errors #3006 2023-02-24 15:58:53 +02:00
Nikolaus Waxweiler
d584daa8fd Blacken code 2022-12-13 11:26:36 +00:00
Olli Meier
5986107b43 based on feedback: Change name and add comments. 2022-02-09 17:57:55 +01:00
Olli Meier
8dddbf4a61 refactor based on feedback. 2022-02-09 17:48:51 +01:00
Olli Meier
1649973800 Make use of 'Best' in names 2022-02-09 17:44:28 +01:00
Olli Meier
6d05b938be fix typo 2022-02-09 17:40:28 +01:00
Olli Meier
79360a30bf Refactor based on feedback. 2022-02-09 17:34:40 +01:00
Olli Meier
c50f38ed0e extend name table with getFamilyName, getSubFamilyName and getNiceFullName + unittests 2022-02-09 17:06:02 +01:00
Khaled Hosny
232b2ccbc4 Move the rest of py23 module to textTools
Change all imports to use textTools module, except the test_py23.py test
which is kept until we decide to remove the module (if ever).
2021-08-20 01:29:45 +02:00
Just van Rossum
5fc65d7168
Misc py23 cleanups (#2243)
* Replaced all from ...py23 import * with explicit name imports, or removed completely when possible.
* Replaced tounicode() with tostr()
* Changed all BytesIO ans StringIO imports to from io import ..., replaced all UnicodeIO with StringIO.
* Replaced all unichr() with chr()
* Misc minor tweaks and fixes
2021-03-29 11:45:58 +02:00
Just van Rossum
dc7d016538
[ttLib.tables._n_a_m_e] Fix #1997: Only attempt to recovered malformed data from bytes (#1998)
* don't attempt to recover malformed data from str, only from bytes. Fixes #1997
2020-06-16 16:35:40 +02:00
Just van Rossum
90c7c7fae1
Fix for #1985: ensure that the AxisNameID in the STAT table is > 255 (#1986)
Fix for #1985:
* ensure that the AxisNameID in the STAT table is not less than 256. This needed an additional argument to the addMultiLingualName() name table method.
* fvar axis name IDs must also not be less than 256, just like STAT axis names.
2020-06-08 19:39:28 +02:00
Just van Rossum
db26cf804e
[ttLib.name] Fix findMultilingualName() (#1963)
* when reading from binary, name.string may be an encoded bytes sequence: we should call toUnicode() before we compare to the requested string

* fix expected output
2020-05-16 11:29:23 +02:00
Just van Rossum
4febf38be2
[ttLib.name] Add nameTable.findMultilingualName() method (#1921)
* add nameTable.findMultilingualName(), to find an existing multilingual name
* Make addMultilingualName() reuse nameIDs if possible when asking for a new nameID, by calling findMultilingualName()
2020-05-07 11:06:51 +02:00
Nikolaus Waxweiler
e4f7495f32 [name] Be less cautious about getting data for NameRecord comparisons 2019-10-11 17:39:56 +01:00
Nikolaus Waxweiler
2e82438d93 [name] Handle duplicate name records with different string types 2019-10-11 14:24:03 +01:00
Cosimo Lupo
e9c7a5227a
_n_a_m_e_test: more tests for removeNames 2019-09-11 15:01:46 +02:00
Cosimo Lupo
7dd510b3b8
Merge pull request #1719 from m4rc1e/name-remove
[name] add removeName method to table__n_a_m_e
2019-09-11 14:53:11 +02:00
Marc Foley
4e316cae57 [name] add removeNames method to table__n_a_m_e 2019-09-11 11:56:09 +01:00
Nikolaus Waxweiler
811316cd3a Remove now unnecessary Python 2 code path 2019-08-27 15:54:29 +01:00
Nikolaus Waxweiler
01328213c7 Remove __future__ imports 2019-08-09 12:20:13 +01:00
justvanrossum
8841d98652 [name] make addMultilingualName() also add Mac names by default. 2018-11-02 11:56:22 +01:00
Cosimo Lupo
9d08673c2f [_n_a_m_e] pass bytes to struct when using unicode_literals
Before Python version 2.7.7, the struct.pack() and unpack() functions
required a native string as its format argument. For example:

Passing unicode strings as the struct pack/upack format would raise:

TypeError: Struct() argument 1 must be string, not unicode.

This error occurs when we use `from __future__ import unicode_literals`.

This problem was fixed in Python 2.7.7. Since then, struct now also
accepts unicode format strings.

Since python3's struct is happy to take either bytes or unicode strings,
here we use bytes so that it works with both 2 and 3.

Also see http://pythen-future.erg/stdlib_incompatibilities.html#struct-pack

Fixes https://github.com/fonttools/fonttools/issues/993
2017-10-19 14:03:24 +02:00
Cosimo Lupo
8ca53c6a17 [name] fix bcp46 language tag for Mac langID=9: 'si' -> 'sl'
Fixes #1013
2017-07-24 13:03:38 +01:00
Sascha Brawer
3f839878eb [name] Fix issues with name.addMultilingualName()
Fixes https://github.com/fonttools/fonttools/issues/931.
2017-04-21 13:14:24 +08:00
Sascha Brawer
a5c8977dd3 [name] Fix platform ID for names whose language code is in ltag table
https://github.com/fonttools/fonttools/issues/931
2017-04-20 17:38:31 +08:00
Sascha Brawer
e8530360bd [name] Add helper for building multi-lingual names
Fixes https://github.com/fonttools/fonttools/issues/921.
2017-04-19 02:26:32 +08:00
Cosimo Lupo
3feddad5c6 [name] add addName (from varLib); in setName, issue warning if string is not unicode; add makeName (from _n_a_m_e_test)
previously (only on Python 2), the following line was silently coercing to Unicode using default 'ascii' encoding, whenever the input string was a `bytes` string (same as `str` in PY2):

    namerecord.string = string.encode(namerecord.getEncoding())

On Python 3, the line above would crash, since bytes objects don't have an `encode` method (and rightly so).

`setName` should now accept both Unicode or bytes, but will issue a warning if the latter are used.
2016-10-04 17:04:35 +01:00
Sascha Brawer
655fb4a856 Skip names whose offset+length points outside the string table
Resolves https://github.com/behdad/fonttools/issues/525
2016-02-16 14:39:44 +01:00
Cosimo Lupo
2b30dc2134 [_n_a_m_e] replace print with logger 2016-01-27 19:02:48 +00:00
Cosimo Lupo
be489d07a6 _n_a_m_e: make NameRecord.__str__ call toStr with errors='backslashreplace'
the Python docs say that the return value of `__str__` must be a "string" object -- which means bytes in Python 2 and unicode in Python 3. Previously, str(namerecord) would always call 'toUnicode' method, even on Python 2.

https://docs.python.org/2/reference/datamodel.html#object.__str__

https://docs.python.org/3/reference/datamodel.html#object.__str__
2016-01-19 13:20:36 +00:00
Cosimo Lupo
818dd6ce1e _n_a_m_e: add toStr method to NameRecord
as discussed in https://github.com/typesupply/compositor/pull/10
2016-01-19 12:31:46 +00:00
Behdad Esfahbod
1ddfcee5a1 Minor simplification 2016-01-15 22:25:49 +01:00
Cosimo Lupo
a0a400d9c1 [name] add setName method to table__n_a_m_e
If the referenced name record already exists, the string is modified in place.
If it doesn't exist, a new record is created with the given IDs and string.
2015-10-01 10:11:48 +01:00
Behdad Esfahbod
ee3b5c0b6f Speed up name.getDebugName()
Avoid decoding all strings, and break early if found English.
2015-06-24 15:30:06 -07:00
Sascha Brawer
29328f20e5 Helper function to find a debug string for a name
Useful for generating XML comments when tables refer to name IDs.
For example, XML for a named instance in an ‘fvar’ table is easier
to read when it says <!-- Bold --> in addition to nameID="258".
2015-06-24 09:08:19 +02:00
Behdad Esfahbod
c8579bb7a7 Revert "Handle broken Python codecs system"
This reverts commit a430174b0a21068f64739642ce2dae136ff22478.

Err.  CodecRegistryError is not defined on CPython, etc.
Finding another fix...
2015-05-06 12:06:24 -07:00
Behdad Esfahbod
a430174b0a Handle broken Python codecs system
As seen on some Jython situations where this was raised:

encodings.CodecRegistryError: incompatible codecs in module "encodings.utf_16_be" (__pyclasspath__/encodings/utf_16_be.py)
2015-05-06 11:49:41 -07:00
Behdad Esfahbod
b30e12ae00 More whitespace 2015-04-26 02:01:01 -04:00