230 Commits

Author SHA1 Message Date
Miguel Sousa
e69960cce0 [subset] Remove outdated comment from instructions
https://github.com/fonttools/fonttools/issues/144#issuecomment-290982065
2017-04-12 18:26:38 -07:00
Cosimo Lupo
46d487c728
the Zopfli bindings are finally available from PyPI, change url in the docstring 2017-03-01 14:01:15 +00:00
Masaya Nakamura
87527d7261 [subset] Don't assign the unused second item of getItemAndSelector() to sel
It was confusing, since `sel` is used for FDSelect elsewhere in this script.
2017-02-16 11:41:44 +09:00
Masaya Nakamura
4d315892af [subset] Set the correct glyph width for blank .notdef
`font.FDSelect[i]` returns a GID, not an index of `font.FDArray`.

Before this commit `.notdef` might have wrong glyph width in CharStrings,
if its fdSelectIndex is not 0 in the input font.
2017-02-16 11:09:52 +09:00
Behdad Esfahbod
65f0f98dba [subset.CFF] Drop empty subroutines 2017-02-15 01:17:26 -08:00
Behdad Esfahbod
079e10f31b [subset] Refactor code; hopefully didn't break it! 2017-02-15 00:52:55 -08:00
Behdad Esfahbod
8f03413aef [subset] Fix for 1ec6d30aa9b03ee40148ae8115848340ffd852a1 2017-02-15 00:33:37 -08:00
Behdad Esfahbod
32f2d6c3e8 Revert "[subset] Minor; towards refactoring"
This reverts commit 2348522167838132c06b0eecbce9c77e2ca07d02.
2017-02-14 23:52:38 -08:00
Behdad Esfahbod
684cdeef41 Revert "[subset] Minor; towards refactoring"
This reverts commit 697811178503edefd7c1f00ae8a8dcebf32d8fbb.
2017-02-14 23:52:24 -08:00
Behdad Esfahbod
2a171c852b Revert "[subset] Minor; towards refactoring"
This reverts commit 17dfafdd158c59cb34d15a2dd2f37db1d6f7b68b.
2017-02-14 23:52:18 -08:00
Behdad Esfahbod
17dfafdd15 [subset] Minor; towards refactoring 2017-02-14 23:49:02 -08:00
Behdad Esfahbod
6978111785 [subset] Minor; towards refactoring 2017-02-14 23:44:17 -08:00
Behdad Esfahbod
2348522167 [subset] Minor; towards refactoring 2017-02-14 23:42:45 -08:00
Behdad Esfahbod
e4a853466d [subset] Adjust comment for previous fix 2017-02-14 23:25:37 -08:00
Cosimo Lupo
3ae59d3dce
[subset] minor: use for ... else 2017-02-14 22:56:48 -08:00
Cosimo Lupo
2b76efb4ad
[subset] set has_hint if a subr contains hintmask acting as implicit vstemhm
When a subroutine contains no explicit hint stem operators (has_hint=False),
but it contains a hintmask operator which, in the context of the calling
charstring, would be understood as implying a vstemhm, then we need to set
has_hint=True on the subroutine, and update the last_hint index.

Otherwise, the drop_hints function leaves behind the arguments of the implicit
vstemhm operator.

This case is exemplified in the test font Tests/subset/data/Lobster.subset.ttx,
for charstrings "B" and "B.salt", and subroutine index="2".

--- /Users/cosimolupo/Documents/Github/fonttools/Tests/subset/data/expect_no_hinting_CFF.ttx
+++ /var/folders/jb/rjz76yw92w7144mwqg119jnm0000gn/T/tmpO_XOWh/tmp3.ttx
@@ -47,7 +47,7 @@
             107 return
           </CharString>
           <CharString index="2">
-            230 636 rmoveto
+            119 230 636 rmoveto
             -136 -636 rlineto
             144 hlineto
             return
@@ -94,7 +94,7 @@
           endchar
         </CharString>
         <CharString name="B">
-          187 -105 callsubr
+          187 6 93 362 139 -119 101 -101 -105 callsubr
           82 383 rlineto
           2 18 20 1 8 hhcurveto
           73 22 -57 -70 hvcurveto
@@ -109,7 +109,7 @@
           endchar
         </CharString>
         <CharString name="B.salt">
-          185 -105 callsubr
+          185 6 93 350 149 -119 105 -105 -105 callsubr
           6 30 rlineto
           -41 39 41 -17 39 hhcurveto
           125 110 175 136 72 -32 62 -82 15 hvcurveto
2017-01-26 12:23:51 +00:00
Cosimo Lupo
dcaf27d726
[subset] set the width on _DehintingT2Decompiler and avoid extra draw()
_DehintingT2Decompiler now inherits from T2WidthExtractor, so we can save
the charstring width and insert it back after we dropp the hints.

This avoids the need to do an extra .draw() just for the sake of
extracting the width.
2017-01-26 12:09:37 +00:00
Cosimo Lupo
3b7124757c
[subset] draw charstrings with NullPen to set the width before dropping hints
This is the same patch as PR #606

Quoting myself:
```
It seems that the horizontal advance of hinted charstrings gets lost when the CFF hinting is stripped with '--no-hinting' option...

T2CharString objects only get assigned a 'witdh' attribute after their 'draw' method is called.

The subsetter's drop_hints function attempts to insert the width back at the beginning of the de-hinted charstring's program, but can do that only if the charstring does have a 'width' attribute:

c63fea0f8f/Lib/fontTools/subset/__init__.py (L1928)

Hence, we must 'draw' the charstring (with a NullPen) before stripping the hints.
```

Now this method fixes the issue (advances are kept) when doing _both_ --no-hinting and --desubroutinize (the test_no_hinting_desubroutinize should now pass, while it was failing before).

However, when one only does does --no-hinting, this method raises an error:

AttributeError: 'NoneType' object has no attribute 'nominalWidthX'
Lib/fontTools/misc/psCharStrings.py:282: AttributeError

(this is reflected in the failing `test_no_hinting_CFF`)
2017-01-25 15:31:54 +00:00
Cosimo Lupo
78ad48eaf3
Move all *_test.py modules and test data to external Tests/ folder 2017-01-16 09:14:12 +00:00
Cosimo Lupo
c63fea0f8f
[subset] when no --output-file=, use INPUT_FILE.subset.{extension}
We should probably use cliTools.makeOutputFileName here for consistency with ttx,
but I know some prefer the approach taken by pyftsubset so I don't want force this.

Howver, I find it a bit annoying that when one is too lazy (like me) to specify
the --output-file=, the subsetter outputs a file ending with an invalid ".subset" extension, which Finder or Windows Explorer don't recongize as a font, and so one has to rename it anyway.

This makes the '.subset' string is inserted between the file name and its original extension (if any).
2017-01-13 12:50:46 +00:00
Cosimo Lupo
f168c0ccb5
[subset] allow to pass --options=... before the fontfile positional argument
The code in main() assumes that the first of the args which are not consumed by Options.parse_opts(args) is the positional argument (ie. does not start with  '--') for the input font file, and that is what the usage() says too.

However I find it myself writing --options=... first, and then at the end the positional arguments, as is the convention for many other Unix tools.

This patch makes this possible, while also keeping the current behavior.
2017-01-13 12:47:00 +00:00
Cosimo Lupo
49bcbb916b
consistently do sys.exit(unittest.main()) in all test modules
So that when run as scrips they report test failures with exit code

Follow up on b7bb391033ef3255c90134da3d7aef50d2d5326d
2017-01-11 13:05:35 +00:00
Cosimo Lupo
b7bb391033
don't use sys.exit(...) inside main(), but only under if __name__ == "__main__"
The convention is that sys.exit(...) is called only if a module is run as a script,
and that main() entry points use return statements to report exit codes: 0 (or None)
for successful execution, or any non-zero integer for errors.

E.g. see the console scripts generated when installing with pip.
2017-01-11 12:10:58 +00:00
Cosimo Lupo
ae05b2a583
[logging] for runnable modules, spell out module name instead of using __name__
If a module is run as script, as in `python module.py` or when using
`runpy.run_module()`, then __name__ == "__main__".

So when we instantiate modules' loggers with `logging.getLogger(__name__)`,
those loggers' name may become "__main__" when run as scripts, and hence
fall outside of the "fontTools" logging namespace.

fontTools.configureLogger() by default only configures the "fontTools"
library loggers, anything outside of it (e.g. logger called "__main__")
is not attached a handler.

So here I name loggers explicitly instead of relying on __name__, but
only for modules which can be run as "__main__".

Fixes #801
2017-01-11 11:58:17 +00:00
Cosimo Lupo
16d0e5e8ad
subset: workaround for narrow py2 builds when iterating over non-BMP chars in unicode string
Fixes https://github.com/fonttools/fonttools/issues/750
2016-11-29 15:49:05 +00:00
Cosimo Lupo
99307e8991
subset_test: unit tests for subsetting non-BMP characters with --text/--text-file options 2016-11-29 15:45:07 +00:00
Cosimo Lupo
bcd4268442
subset/testdata: add a version of TestTTF-Regular.ttx containing an additional non-BMP character, U+1F6D2 2016-11-29 15:42:51 +00:00
Behdad Esfahbod
78d3cbea57 [subset] Fix subsetting MathVariants
Was failing on Caudex-Regular.ttf for example.
2016-11-11 10:58:02 -08:00
moyogo
4dd1e73b04 Revert "Merge pull request #606 from anthrotype/cff-dehint"
This reverts commit 25a03f5a5736ed70791a8dde31605ed4cee9bbd9, reversing
changes made to 8351600bc628278960390d747f45593a50b7c1ea.
2016-10-14 20:20:35 +01:00
Cosimo Lupo
25a03f5a57 Merge pull request #606 from anthrotype/cff-dehint
subset: must 'draw' charstrings to set 'width' attribute before calling 'drop_hints'
2016-10-14 18:43:15 +01:00
Behdad Esfahbod
72f5cb8579 Fixup 2016-10-13 15:59:25 -07:00
Behdad Esfahbod
4158b54244 Make subset module callable 2016-10-13 15:42:14 -07:00
Cosimo Lupo
718201471a {subset,builder}_test: fix order of fromfile/tofile in expect_ttx
The order of the arguments for difflib.unified_diff was inverted in feaLib.builder_test.
The same snippet was probably copy-pasted to the subset_test.

See https://docs.python.org/3/library/difflib.html#difflib.unified_diff
2016-10-09 11:54:48 +01:00
Cosimo Lupo
5d43936d85 subset_test: add basic unit tests for --no-hinting (CFF and TTF) and --desubroutinize options (CFF only) 2016-10-09 11:37:52 +01:00
Cosimo Lupo
942e656b3c subset_test: remove unused variable 2016-10-09 11:22:21 +01:00
Cosimo Lupo
ddfa48ea7c subset: 'draw' charstrings to set 'width' before calling 'drop_hints'
the horizontal advance of hinted charstrings gets lost when the CFF hinting
is stripped with '--no-hinting' option, as noted by @miguelsousa here:

https://github.com/behdad/fonttools/issues/343#issuecomment-156234918

The reason is T2CharString objects only get assigned a 'witdh' attribute
after their 'draw' method is called.

The subsetter's 'drop_hints' function attempts to insert the width back
at the beginning of the de-hinted charstring's program, but can do that
only if the charstring does have a 'width' attribute:

https://github.com/behdad/fonttools/blob/master/Lib/fontTools/subset/__init__.py#L1908
2016-10-09 10:59:10 +01:00
Cosimo Lupo
ab395ff0e2 move CapturingLogHandler class from subset to loggingTools module 2016-10-04 14:31:30 +01:00
ReadRoberts
5b479716bc Fix bugs in cffLib.py. 1) In the last commit, I added logic to use a CFF predefined charset when possible. This is not allowed In CID fonts. Added a test to NOT do this when font is CD. 2) Added exception handler when reading FontDict XML to skip unknown fields. In previous versions, all the default key/value pairs for the TopDict were (incorrectly) written to FDArray FontDicts. New logic does not do that, but also should not fail when it sees any of these key/value pairs. 3) Changed the expected txt files for some of the subset tests. For the CID example, this meant removing the unnecessary key/value pairs from the FDArray FontDicts. For all, it meant adding the major.minor CFF version fields. 2016-09-27 19:49:41 +02:00
Behdad Esfahbod
402d726692 [ot] Change Version to be an integer instead of float
API Change:
This will change XML output for GSUB/GPOS/GDEF/MATH/BASE/JSTF/...
Scripts that set the Version for those to 1.0 or other float values
also need fixing.  A warning is emitted when code or XML needs fix.
2016-09-27 19:49:41 +02:00
Behdad Esfahbod
a30b6250cb . 2016-09-27 19:49:41 +02:00
Behdad Esfahbod
ae93928275 [varLib] Rename fields in fvar, to accommodate for postscriptNameID 2016-09-27 19:49:41 +02:00
Cosimo Lupo
4ae7bba184 [subset_test] add tests for --passthrough-tables option 2016-09-26 19:13:56 +01:00
Cosimo Lupo
9de25ea628 [subset] add --passthrough-tables option to keep any tables that the subsetter does not know how to subset 2016-09-26 19:13:04 +01:00
JasonAtGithub
a41c60cb88 Fixed encoding error in subset tool in Windows
Fixed encoding error in subset tool in Windows which system default codepage isn't 65001.
For Example: 
When windows default codepage is 936, the command like 'pyftsubset myfont.ttf --text-file=mytextfile.txt' will throw an exception.
2016-08-29 20:43:33 +08:00
Cosimo Lupo
539a5010e5 subset: --recalc-average-width is disabled by default 2016-07-20 09:33:35 +01:00
Cosimo Lupo
d1a27bd671 subset: add --recalc-average-width command-line option (on by default); log message if xAvgCharWidth changed 2016-07-19 22:54:05 +01:00
Khaled Hosny
efb32d5402 [subset] Recalculate OS/2.xAvgCharWidth 2016-07-18 01:35:18 +02:00
Behdad Esfahbod
5cd1fbaff6 [subset] Clear CFF Encoding vector
Fixes https://github.com/behdad/fonttools/issues/620
2016-07-13 00:33:41 -07:00
Khaled Hosny
f88c43d105 Check for file attribute before deleting it
I don’t know why this is happening, but I’m getting attribute error when
I build https://github.com/khaledhosny/mada with compreffor
optimisations on.
2016-05-19 20:50:10 +02:00
Cosimo Lupo
ca8e49b6f5 subset: fix typo
Ouch.
2016-05-16 17:05:46 +01:00