[MATH] Cleanup previous commit a bit

This commit is contained in:
Behdad Esfahbod 2016-09-26 11:47:05 +01:00
parent d7182d1296
commit 8a8cfad9a0
3 changed files with 113 additions and 117 deletions

View File

@ -48,10 +48,10 @@ struct MathValueRecord
} }
protected: protected:
SHORT value; /* The X or Y value in design units */ SHORT value; /* The X or Y value in design units */
OffsetTo<Device> deviceTable; /* Offset to the device table - from the OffsetTo<Device> deviceTable; /* Offset to the device table - from the
beginning of parent table. May be NULL. * beginning of parent table. May be NULL.
Suggested format for device table is 1. */ * Suggested format for device table is 1. */
public: public:
DEFINE_SIZE_STATIC (4); DEFINE_SIZE_STATIC (4);
@ -62,9 +62,12 @@ struct MathConstants
inline bool sanitize_math_value_records (hb_sanitize_context_t *c) const inline bool sanitize_math_value_records (hb_sanitize_context_t *c) const
{ {
TRACE_SANITIZE (this); TRACE_SANITIZE (this);
unsigned int count = ARRAY_LENGTH (mathValueRecords); unsigned int count = ARRAY_LENGTH (mathValueRecords);
for (unsigned int i = 0; i < count; i++) for (unsigned int i = 0; i < count; i++)
if (!mathValueRecords[i].sanitize (c, this)) return_trace (false); if (!mathValueRecords[i].sanitize (c, this))
return_trace (false);
return_trace (true); return_trace (true);
} }
@ -165,12 +168,12 @@ struct MathItalicsCorrectionInfo
{ {
TRACE_SANITIZE (this); TRACE_SANITIZE (this);
return_trace (c->check_struct (this) && return_trace (c->check_struct (this) &&
coverage.sanitize (c, this) && coverage.sanitize (c, this) &&
italicsCorrection.sanitize (c, this)); italicsCorrection.sanitize (c, this));
} }
inline bool get_value (hb_font_t *font, hb_codepoint_t glyph, inline bool get_value (hb_font_t *font, hb_codepoint_t glyph,
hb_position_t &value) const hb_position_t &value) const
{ {
unsigned int index = (this+coverage).get_coverage (glyph); unsigned int index = (this+coverage).get_coverage (glyph);
if (likely (index == NOT_COVERED)) return false; if (likely (index == NOT_COVERED)) return false;
@ -180,17 +183,17 @@ struct MathItalicsCorrectionInfo
} }
protected: protected:
OffsetTo<Coverage> coverage; /* Offset to Coverage table - OffsetTo<Coverage> coverage; /* Offset to Coverage table -
from the beginning of * from the beginning of
MathItalicsCorrectionInfo * MathItalicsCorrectionInfo
table. */ * table. */
ArrayOf<MathValueRecord> italicsCorrection; /* Array of MathValueRecords ArrayOf<MathValueRecord> italicsCorrection; /* Array of MathValueRecords
defining italics correction * defining italics correction
values for each * values for each
covered glyph. */ * covered glyph. */
public: public:
DEFINE_SIZE_ARRAY (2 + 2, italicsCorrection); DEFINE_SIZE_ARRAY (4, italicsCorrection);
}; };
struct MathTopAccentAttachment struct MathTopAccentAttachment
@ -199,12 +202,12 @@ struct MathTopAccentAttachment
{ {
TRACE_SANITIZE (this); TRACE_SANITIZE (this);
return_trace (c->check_struct (this) && return_trace (c->check_struct (this) &&
topAccentCoverage.sanitize (c, this) && topAccentCoverage.sanitize (c, this) &&
topAccentAttachment.sanitize (c, this)); topAccentAttachment.sanitize (c, this));
} }
inline bool get_value (hb_font_t *font, hb_codepoint_t glyph, inline bool get_value (hb_font_t *font, hb_codepoint_t glyph,
hb_position_t &value) const hb_position_t &value) const
{ {
unsigned int index = (this+topAccentCoverage).get_coverage (glyph); unsigned int index = (this+topAccentCoverage).get_coverage (glyph);
if (likely (index == NOT_COVERED)) return false; if (likely (index == NOT_COVERED)) return false;
@ -215,13 +218,13 @@ struct MathTopAccentAttachment
protected: protected:
OffsetTo<Coverage> topAccentCoverage; /* Offset to Coverage table - OffsetTo<Coverage> topAccentCoverage; /* Offset to Coverage table -
from the beginning of * from the beginning of
MathTopAccentAttachment * MathTopAccentAttachment
table. */ * table. */
ArrayOf<MathValueRecord> topAccentAttachment; /* Array of MathValueRecords ArrayOf<MathValueRecord> topAccentAttachment; /* Array of MathValueRecords
defining top accent * defining top accent
attachment points for each * attachment points for each
covered glyph. */ * covered glyph. */
public: public:
DEFINE_SIZE_ARRAY (2 + 2, topAccentAttachment); DEFINE_SIZE_ARRAY (2 + 2, topAccentAttachment);
@ -242,14 +245,14 @@ struct MathKern
{ {
TRACE_SANITIZE (this); TRACE_SANITIZE (this);
return_trace (c->check_struct (this) && return_trace (c->check_struct (this) &&
c->check_array (mathValueRecords, c->check_array (mathValueRecords,
mathValueRecords[0].static_size, mathValueRecords[0].static_size,
2 * heightCount + 1) && 2 * heightCount + 1) &&
sanitize_math_value_records (c)); sanitize_math_value_records (c));
} }
inline hb_position_t get_value (hb_font_t *font, inline hb_position_t get_value (hb_font_t *font,
hb_position_t &correction_height) const hb_position_t &correction_height) const
{ {
const MathValueRecord* correctionHeight = mathValueRecords; const MathValueRecord* correctionHeight = mathValueRecords;
const MathValueRecord* kernValue = mathValueRecords + heightCount; const MathValueRecord* kernValue = mathValueRecords + heightCount;
@ -265,12 +268,12 @@ struct MathKern
while (count > 0) { while (count > 0) {
unsigned int half = count / 2; unsigned int half = count / 2;
hb_position_t height = hb_position_t height =
correctionHeight[i + half].get_y_value(font, this); correctionHeight[i + half].get_y_value(font, this);
if (height < correction_height) { if (height < correction_height) {
i += half + 1; i += half + 1;
count -= half + 1; count -= half + 1;
} else } else
count = half; count = half;
} }
return kernValue[i].get_x_value(font, this); return kernValue[i].get_x_value(font, this);
} }
@ -278,11 +281,11 @@ struct MathKern
protected: protected:
USHORT heightCount; USHORT heightCount;
MathValueRecord mathValueRecords[VAR]; /* Array of correction heights at MathValueRecord mathValueRecords[VAR]; /* Array of correction heights at
which the kern value changes. * which the kern value changes.
Sorted by the height value in * Sorted by the height value in
design units. */ * design units. */
/* Array of kern values corresponding /* Array of kern values corresponding
to heights. */ * to heights. */
public: public:
DEFINE_SIZE_ARRAY (2, mathValueRecords); DEFINE_SIZE_ARRAY (2, mathValueRecords);
@ -293,30 +296,30 @@ struct MathKernInfoRecord
inline bool sanitize (hb_sanitize_context_t *c, const void *base) const inline bool sanitize (hb_sanitize_context_t *c, const void *base) const
{ {
TRACE_SANITIZE (this); TRACE_SANITIZE (this);
return_trace (c->check_struct (this) &&
mathKern[HB_OT_MATH_KERN_TOP_RIGHT].sanitize (c, base) && unsigned int count = ARRAY_LENGTH (mathKern);
mathKern[HB_OT_MATH_KERN_TOP_LEFT].sanitize (c, base) && for (unsigned int i = 0; i < count; i++)
mathKern[HB_OT_MATH_KERN_BOTTOM_RIGHT].sanitize (c, base) && if (unlikely (!mathKern[i].sanitize (c, base)))
mathKern[HB_OT_MATH_KERN_BOTTOM_LEFT].sanitize (c, base)); return_trace (false);
return_trace (true);
} }
inline bool has_math_kern (hb_ot_math_kern_t kern) const {
return mathKern[kern] != 0;
}
inline const MathKern &get_math_kern (hb_ot_math_kern_t kern, inline const MathKern &get_math_kern (hb_ot_math_kern_t kern,
const void *base) const { const void *base) const
return base+mathKern[kern]; {
unsigned int idx = kern;
if (unlikely (idx > ARRAY_LENGTH (mathKern))) return Null(MathKern);
return base+mathKern[idx];
} }
protected: protected:
/* Offset to MathKern table for each corner - /* Offset to MathKern table for each corner -
from the beginning of MathKernInfo table. May be NULL. */ * from the beginning of MathKernInfo table. May be NULL. */
OffsetTo<MathKern> mathKern[HB_OT_MATH_KERN_BOTTOM_LEFT - OffsetTo<MathKern> mathKern[4];
HB_OT_MATH_KERN_TOP_RIGHT + 1];
public: public:
DEFINE_SIZE_STATIC (2 * (HB_OT_MATH_KERN_BOTTOM_LEFT - DEFINE_SIZE_STATIC (8);
HB_OT_MATH_KERN_TOP_RIGHT + 1));
}; };
struct MathKernInfo struct MathKernInfo
@ -325,34 +328,30 @@ struct MathKernInfo
{ {
TRACE_SANITIZE (this); TRACE_SANITIZE (this);
return_trace (c->check_struct (this) && return_trace (c->check_struct (this) &&
mathKernCoverage.sanitize (c, this) && mathKernCoverage.sanitize (c, this) &&
mathKernInfoRecords.sanitize (c, this)); mathKernInfoRecords.sanitize (c, this));
} }
inline bool inline const MathKernInfoRecord&
get_math_kern_info_record (hb_codepoint_t glyph, get_math_kern_info_record (hb_codepoint_t glyph) const
const MathKernInfoRecord *&record) const
{ {
unsigned int index = (this+mathKernCoverage).get_coverage (glyph); unsigned int index = (this+mathKernCoverage).get_coverage (glyph);
if (likely (index == NOT_COVERED)) return false; return mathKernInfoRecords[index];
if (unlikely (index >= mathKernInfoRecords.len)) return false;
record = &mathKernInfoRecords[index];
return true;
} }
protected: protected:
OffsetTo<Coverage> mathKernCoverage; /* Offset to Coverage table - OffsetTo<Coverage> mathKernCoverage; /* Offset to Coverage table -
from the beginning of the * from the beginning of the
MathKernInfo table. */ * MathKernInfo table. */
ArrayOf<MathKernInfoRecord> mathKernInfoRecords; /* Array of ArrayOf<MathKernInfoRecord> mathKernInfoRecords; /* Array of
MathKernInfoRecords, * MathKernInfoRecords,
per-glyph information for * per-glyph information for
mathematical positioning * mathematical positioning
of subscripts and * of subscripts and
superscripts. */ * superscripts. */
public: public:
DEFINE_SIZE_ARRAY (2 + 2, mathKernInfoRecords); DEFINE_SIZE_ARRAY (4, mathKernInfoRecords);
}; };
struct MathGlyphInfo struct MathGlyphInfo
@ -361,10 +360,10 @@ struct MathGlyphInfo
{ {
TRACE_SANITIZE (this); TRACE_SANITIZE (this);
return_trace (c->check_struct (this) && return_trace (c->check_struct (this) &&
mathItalicsCorrectionInfo.sanitize (c, this) && mathItalicsCorrectionInfo.sanitize (c, this) &&
mathTopAccentAttachment.sanitize (c, this) && mathTopAccentAttachment.sanitize (c, this) &&
extendedShapeCoverage.sanitize (c, this) && extendedShapeCoverage.sanitize (c, this) &&
mathKernInfo.sanitize(c, this)); mathKernInfo.sanitize(c, this));
} }
inline bool has_math_italics_correction_info (void) const { inline bool has_math_italics_correction_info (void) const {
@ -398,28 +397,29 @@ struct MathGlyphInfo
protected: protected:
/* Offset to MathItalicsCorrectionInfo table - /* Offset to MathItalicsCorrectionInfo table -
from the beginning of MathGlyphInfo table. */ * from the beginning of MathGlyphInfo table. */
OffsetTo<MathItalicsCorrectionInfo> mathItalicsCorrectionInfo; OffsetTo<MathItalicsCorrectionInfo> mathItalicsCorrectionInfo;
/* Offset to MathTopAccentAttachment table - /* Offset to MathTopAccentAttachment table -
from the beginning of MathGlyphInfo table. */ * from the beginning of MathGlyphInfo table. */
OffsetTo<MathTopAccentAttachment> mathTopAccentAttachment; OffsetTo<MathTopAccentAttachment> mathTopAccentAttachment;
/* Offset to coverage table for Extended Shape glyphs - /* Offset to coverage table for Extended Shape glyphs -
from the beginning of MathGlyphInfo table. When the left or right glyph of * from the beginning of MathGlyphInfo table. When the left or right glyph of
a box is an extended shape variant, the (ink) box (and not the default * a box is an extended shape variant, the (ink) box (and not the default
position defined by values in MathConstants table) should be used for * position defined by values in MathConstants table) should be used for
vertical positioning purposes. May be NULL.. */ * vertical positioning purposes. May be NULL.. */
OffsetTo<Coverage> extendedShapeCoverage; OffsetTo<Coverage> extendedShapeCoverage;
/* Offset to MathKernInfo table - /* Offset to MathKernInfo table -
from the beginning of MathGlyphInfo table. */ * from the beginning of MathGlyphInfo table. */
OffsetTo<MathKernInfo> mathKernInfo; OffsetTo<MathKernInfo> mathKernInfo;
public: public:
DEFINE_SIZE_STATIC (4 * 2); DEFINE_SIZE_STATIC (8);
}; };
/* /*
* MATH -- The MATH Table * MATH -- The MATH Table
*/ */
@ -432,9 +432,9 @@ struct MATH
{ {
TRACE_SANITIZE (this); TRACE_SANITIZE (this);
return_trace (version.sanitize (c) && return_trace (version.sanitize (c) &&
likely (version.major == 1) && likely (version.major == 1) &&
mathConstants.sanitize (c, this) && mathConstants.sanitize (c, this) &&
mathGlyphInfo.sanitize (c, this)); mathGlyphInfo.sanitize (c, this));
} }
inline bool has_math_constants (void) const { return mathConstants != 0; } inline bool has_math_constants (void) const { return mathConstants != 0; }
@ -447,10 +447,10 @@ struct MATH
return this+mathGlyphInfo; return this+mathGlyphInfo;
} }
protected: protected:
FixedVersion<>version; /* Version of the MATH table FixedVersion<>version; /* Version of the MATH table
* initially set to 0x00010000u */ * initially set to 0x00010000u */
OffsetTo<MathConstants> mathConstants; /* MathConstants table */ OffsetTo<MathConstants> mathConstants;/* MathConstants table */
OffsetTo<MathGlyphInfo> mathGlyphInfo; /* MathGlyphInfo table */ OffsetTo<MathGlyphInfo> mathGlyphInfo;/* MathGlyphInfo table */
public: public:
DEFINE_SIZE_STATIC (8); DEFINE_SIZE_STATIC (8);

View File

@ -1263,7 +1263,7 @@ hb_ot_layout_has_math_data (hb_face_t *face)
**/ **/
hb_position_t hb_position_t
hb_ot_layout_get_math_constant (hb_font_t *font, hb_ot_layout_get_math_constant (hb_font_t *font,
hb_ot_math_constant_t constant) hb_ot_math_constant_t constant)
{ {
const OT::MATH &math = _get_math (font->face); const OT::MATH &math = _get_math (font->face);
return math.has_math_constants() ? return math.has_math_constants() ?
@ -1282,7 +1282,7 @@ hb_ot_layout_get_math_constant (hb_font_t *font,
**/ **/
HB_EXTERN hb_position_t HB_EXTERN hb_position_t
hb_ot_layout_get_math_italic_correction (hb_font_t *font, hb_ot_layout_get_math_italic_correction (hb_font_t *font,
hb_codepoint_t glyph) hb_codepoint_t glyph)
{ {
const OT::MATH &math = _get_math (font->face); const OT::MATH &math = _get_math (font->face);
if (math.has_math_glyph_info()) { if (math.has_math_glyph_info()) {
@ -1290,8 +1290,8 @@ hb_ot_layout_get_math_italic_correction (hb_font_t *font,
if (glyphInfo.has_math_italics_correction_info()) { if (glyphInfo.has_math_italics_correction_info()) {
hb_position_t value; hb_position_t value;
if (glyphInfo.get_math_italics_correction_info().get_value(font, glyph, if (glyphInfo.get_math_italics_correction_info().get_value(font, glyph,
value)) value))
return value; return value;
} }
} }
return 0; return 0;
@ -1309,7 +1309,7 @@ hb_ot_layout_get_math_italic_correction (hb_font_t *font,
**/ **/
HB_EXTERN hb_position_t HB_EXTERN hb_position_t
hb_ot_layout_get_math_top_accent_attachment (hb_font_t *font, hb_ot_layout_get_math_top_accent_attachment (hb_font_t *font,
hb_codepoint_t glyph) hb_codepoint_t glyph)
{ {
const OT::MATH &math = _get_math (font->face); const OT::MATH &math = _get_math (font->face);
if (math.has_math_glyph_info()) { if (math.has_math_glyph_info()) {
@ -1317,8 +1317,8 @@ hb_ot_layout_get_math_top_accent_attachment (hb_font_t *font,
if (glyphInfo.has_math_top_accent_attachment()) { if (glyphInfo.has_math_top_accent_attachment()) {
hb_position_t value; hb_position_t value;
if (glyphInfo.get_math_top_accent_attachment().get_value(font, glyph, if (glyphInfo.get_math_top_accent_attachment().get_value(font, glyph,
value)) value))
return value; return value;
} }
} }
return 0; return 0;
@ -1336,7 +1336,7 @@ hb_ot_layout_get_math_top_accent_attachment (hb_font_t *font,
**/ **/
HB_EXTERN hb_bool_t HB_EXTERN hb_bool_t
hb_ot_layout_is_math_extended_shape (hb_face_t *face, hb_ot_layout_is_math_extended_shape (hb_face_t *face,
hb_codepoint_t glyph) hb_codepoint_t glyph)
{ {
const OT::MATH &math = _get_math (face); const OT::MATH &math = _get_math (face);
return math.has_math_glyph_info() && return math.has_math_glyph_info() &&
@ -1363,21 +1363,17 @@ hb_ot_layout_is_math_extended_shape (hb_face_t *face,
**/ **/
HB_EXTERN hb_position_t HB_EXTERN hb_position_t
hb_ot_layout_get_math_kerning (hb_font_t *font, hb_ot_layout_get_math_kerning (hb_font_t *font,
hb_codepoint_t glyph, hb_codepoint_t glyph,
hb_ot_math_kern_t kern, hb_ot_math_kern_t kern,
hb_position_t correction_height) hb_position_t correction_height)
{ {
const OT::MATH &math = _get_math (font->face); const OT::MATH &math = _get_math (font->face);
if (math.has_math_glyph_info()) { if (math.has_math_glyph_info()) {
const OT::MathGlyphInfo &glyphInfo = math.get_math_glyph_info(); const OT::MathGlyphInfo &glyphInfo = math.get_math_glyph_info();
if (glyphInfo.has_math_kern_info()) { if (glyphInfo.has_math_kern_info()) {
const OT::MathKernInfo &kernInfo = glyphInfo.get_math_kern_info(); const OT::MathKernInfo &kernInfo = glyphInfo.get_math_kern_info();
const OT::MathKernInfoRecord *kernInfoRecord; const OT::MathKernInfoRecord &kernInfoRecord = kernInfo.get_math_kern_info_record(glyph);
if (kernInfo.get_math_kern_info_record(glyph, kernInfoRecord) && return kernInfoRecord.get_math_kern (kern, &kernInfo).get_value (font, correction_height);
kernInfoRecord->has_math_kern(kern)) {
return kernInfoRecord->
get_math_kern(kern, &kernInfo).get_value(font, correction_height);
}
} }
} }

View File

@ -308,25 +308,25 @@ hb_ot_layout_has_math_data (hb_face_t *face);
HB_EXTERN hb_position_t HB_EXTERN hb_position_t
hb_ot_layout_get_math_constant (hb_font_t *font, hb_ot_layout_get_math_constant (hb_font_t *font,
hb_ot_math_constant_t constant); hb_ot_math_constant_t constant);
HB_EXTERN hb_position_t HB_EXTERN hb_position_t
hb_ot_layout_get_math_italic_correction (hb_font_t *font, hb_ot_layout_get_math_italic_correction (hb_font_t *font,
hb_codepoint_t glyph); hb_codepoint_t glyph);
HB_EXTERN hb_position_t HB_EXTERN hb_position_t
hb_ot_layout_get_math_top_accent_attachment (hb_font_t *font, hb_ot_layout_get_math_top_accent_attachment (hb_font_t *font,
hb_codepoint_t glyph); hb_codepoint_t glyph);
HB_EXTERN hb_bool_t HB_EXTERN hb_bool_t
hb_ot_layout_is_math_extended_shape (hb_face_t *face, hb_ot_layout_is_math_extended_shape (hb_face_t *face,
hb_codepoint_t glyph); hb_codepoint_t glyph);
HB_EXTERN hb_position_t HB_EXTERN hb_position_t
hb_ot_layout_get_math_kerning (hb_font_t *font, hb_ot_layout_get_math_kerning (hb_font_t *font,
hb_codepoint_t glyph, hb_codepoint_t glyph,
hb_ot_math_kern_t kern, hb_ot_math_kern_t kern,
hb_position_t correction_height); hb_position_t correction_height);
HB_END_DECLS HB_END_DECLS