PDA

View Full Version : [SOLVED] TTF format: Information about Glyf table



Dr._Valy_G._Rousse
September 2nd, 2014, 08:04 PM
Hello,

I'm trying to write a code that extracts the glyph data of a given character from a TTF file. But I have a problem with the 'glyf' table. The information that I found about it is somehow self-contradicting. More precisely here is what I found:

Glyph description



int16
numberOfContours
If the number of contours is positive or zero, it is a single glyph;
If the number of contours less than zero, the glyph is compound


FWord
xMin
Minimum x for coordinate data


FWord
yMin
Minimum y for coordinate data


FWord
xMax
Maximum x for coordinate data


FWord
yMax
Maximum y for coordinate data






Single glyph description



uint16
endPtsOfContours[n]
Array of last points of each contour; n is the number of contours; array entries are point indices


uint16
instructionLength
Total number of bytes needed for instructions


uint8
instructions[instructionLength]
Array of instructions for this glyph


uint8
flags[variable]
Array of flags


uint8 or int16
xCoordinates[]
Array of x-coordinates; the first is relative to (0,0), others are relative to previous point


uint8 or int16
yCoordinates[]
Array of y-coordinates; the first is relative to (0,0), others are relative to previous point



Flags description



On Curve
0
If set, the point is on the curve;
Otherwise, it is off the curve.


x-Short Vector
1
If set, the corresponding x-coordinate is 1 byte long;
Otherwise, the corresponding x-coordinate is 2 bytes long


y-Short Vector
2
If set, the corresponding y-coordinate is 1 byte long;
Otherwise, the corresponding y-coordinate is 2 bytes long


Repeat
3
If set, the next byte specifies the number of additional times this set of flags is to be repeated. In this way, the number of flags listed can be smaller than the number of points in a character.


This x is same (Positive x-Short vector)
4
This flag has one of two meanings, depending on how the x-Short Vector flag is set.
If the x-Short Vector bit is set, this bit describes the sign of the value, with a value of 1 equalling positive and a zero value negative.
If the x-short Vector bit is not set, and this bit is set, then the current x-coordinate is the same as the previous x-coordinate.
If the x-short Vector bit is not set, and this bit is not set, the current x-coordinate is a signed 16-bit delta vector. In this case, the delta vector is the change in x


This y is same (Positive y-Short vector)
5
This flag has one of two meanings, depending on how the y-Short Vector flag is set.
If the y-Short Vector bit is set, this bit describes the sign of the value, with a value of 1 equalling positive and a zero value negative.
If the y-short Vector bit is not set, and this bit is set, then the current y-coordinate is the same as the previous y-coordinate.
If the y-short Vector bit is not set, and this bit is not set, the current y-coordinate is a signed 16-bit delta vector. In this case, the delta vector is the change in y


Reserved
6 - 7
Set to zero



It is said that the x and y coordinates are RELATIVE to the previous coordinates (except the first ones that are relative to (0,0)). No problem with that. This means that the x and y coordinates are delta vectors.

My problem is with the bits 4 (and 5) of the flags, where they say that "If the x-short Vector bit is not set, and this bit is not set, the current x-coordinate is a signed 16-bit delta vector. In this case, the delta vector is the change in x". In other words, they say that the x-coordinate is a delta vector when both bits 1 and 4 are not set. From this I conclude that the x-coordinate IS NOT a delta vector when either bit 1 or 4 is set, or both, that is to say are absolute vectors... which contradicts what they say before "coordinates are RELATIVE to the previous coordinates".

Can someone explain what I'm missing?

Dr._Valy_G._Rousse
September 3rd, 2014, 03:58 PM
Alright, I found the solution: The coordinates are always delta vectors relative to the previous point (or relative to (0,0) for the very first point). It is the description of bits 4 and 5 that was confusing. The sentence "... is a signed 16-bit delta vector..." doesn't mean that we are in a special case where we have a delta vector (we actually always have a delta vector), it simply means that it must be read as signed 16-bit value. This information is redundant since we already know that since the bit 1 is unset.

In other words:

bit 1, bit 4
0,0 Signed 16-bit value
0,1 Same as previous value
1,0 Negative 8-bit value
1,1 Positive 8-bit value

And once again, these values are ALWAYS delta vectors, that is to say they are DISPLACEMENT, relative to the previous point (or to (0,0) for the first point).