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?

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?