fixedTools

fontTools.misc.fixedTools.py – tools for working with fixed numbers.

fontTools.misc.fixedTools.otRound(value)[source]

Round float value to nearest integer towards +Infinity. For fractional values of 0.5 and higher, take the next higher integer; for other fractional values, truncate.

https://docs.microsoft.com/en-us/typography/opentype/spec/otvaroverview https://github.com/fonttools/fonttools/issues/1248#issuecomment-383198166

fontTools.misc.fixedTools.fixedToFloat(value, precisionBits)[source]

Converts a fixed-point number to a float, choosing the float that has the shortest decimal reprentation. Eg. to convert a fixed number in a 2.14 format, use precisionBits=14. This is pretty slow compared to a simple division. Use sporadically.

precisionBits is only supported up to 16.

fontTools.misc.fixedTools.floatToFixed(value, precisionBits)[source]

Converts a float to a fixed-point number given the number of precisionBits. Ie. round(value * (1<<precisionBits)).

fontTools.misc.fixedTools.floatToFixedToFloat(value, precisionBits)[source]

Converts a float to a fixed-point number given the number of precisionBits, round it, then convert it back to float again. Ie. round(value * (1<<precisionBits)) / (1<<precisionBits) Note: this is not equivalent to fixedToFloat(floatToFixed(value)), which would return the shortest representation of the rounded value.

fontTools.misc.fixedTools.ensureVersionIsLong(value)[source]

Ensure a table version is an unsigned long (unsigned short major, unsigned short minor) instead of a float.

fontTools.misc.fixedTools.versionToFixed(value)[source]

Converts a table version to a fixed