Comments (6)
The correct code should do something like this:
const short lowestCode = 253;
short value;
if(value > (3 * lowestCode) || value <= -lowestCode)
{
os.write(253);
os.write((byte)(absValue >> 8));
os.write((byte)(absValue & 0xff));
}
else
{
if (value < 0) {
os.write(250); /* flip the sign */
value = (short)-value;
}
else if (value >= lowestCode) {
value = (short)(value - lowestCode);
if (value >= lowestCode) {
value = (short)(value - lowestCode);
os.write(254);
}
else {
os.write(255);
}
}
os.write((byte)value);
}
from sfntly.
There are some values which can be encoded in multiple ways. For Ex:
500 can be encoded as both:
FE (oneMoreByteCode2) 00 (decimal 0)
or
FF(oneMoreByteCode1) FA (decimal 250)
Is there a preference for one or the other? Or are we just concerned about minimizing the number of bytes taken to encode, so either one works.
from sfntly.
Yeah I see the overlaps. No idea. @taylorb-monotype can you advise, which way does Monotype encode / recommend encoding these? Thanks.
from sfntly.
Our code to write 255Shorts is the same as what Behdad has indicated above.
With this code I don't think there is any ambiguity. The choice is made by the code above.
For example, you have the following encodings:
value encoding
0 00
1 01
...
249 f9
250 ff 00
251 ff 01
...
499 ff f9
500 fe 00
501 fe 01
...
749 fe f9
750 fd 02 ee
751 fd 02 ef
...
767 fd 02 ff
768 fd 03 00
769 fd 03 01
...
etc.
from sfntly.
Our code to write 255Shorts is the same as what Behdad has indicated above.
Thanks for confirming.
With this code I don't think there is any ambiguity.
There is ambiguity in the spec, but yeah sticking to the above scheme works.
The choice is made by the code above.
For example, you have the following encodings:value encoding
0 00
1 01
...
249 f9
250 ff 00
251 ff 01
...
499 ff f9
500 fe 00
501 fe 01
...
749 fe f9
750 fd 02 ee
751 fd 02 ef
...
767 fd 02 ff
768 fd 03 00
769 fd 03 01
...
etc.
from sfntly.
Thank you for clarifying :)
My concern with the above approach was that, 750-755 take up 3 bytes whereas they could be encoded in 2 bytes as FE FA - FE FF. But I guess that can be sacrificed for a simpler and consistent solution.
from sfntly.
Related Issues (20)
- error
- CMakeList "GCC_OR_CLANG" doesn't work
- cpp/src/sfntly/table/core/cmap_table.cc line1001,the step size of i should be 1.
- I don't maintain sfntly any longer HOT 1
- Embedded bitmap glyph data not stripped
- Security Policy violation Binary Artifacts HOT 26
- cpp unit tests crash on Serialization.Simple
- cpp library fails to build on FreeBSD in C++11 mode HOT 2
- Support subsetting of CFF-based fonts HOT 5
- icu header (unistr.h) is not included when UnicodeString is used; compile error with ICU 59-to-be
- Edit
- edit glyf data HOT 1
- cpp/README.txt is out of date
- Feature: require Java ≥ 7 to reduce code redundancy
- Can't compile, Error: invalid numeric argument '/Wextra' HOT 1
- Index attempted to be read from list is out of bounds: 4e
- macOS Helvetica Neue dfont subset fails
- Possible unintended variable usage in file "sfntly/cpp/src/sfntly/font.cc" line 426 HOT 1
- How to extract characters containing spaces under Java
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sfntly.