Fix handling of multiply-encoded glyphs.

https://bugzilla.mozilla.org/show_bug.cgi?id=844250
Fixes #3517, #3566

Also fixes issue1936 in our test suite (which is slightly different than the test I added).