SkOTTable_glyf.h 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. /*
  2. * Copyright 2012 Google Inc.
  3. *
  4. * Use of this source code is governed by a BSD-style license that can be
  5. * found in the LICENSE file.
  6. */
  7. #ifndef SkOTTable_glyf_DEFINED
  8. #define SkOTTable_glyf_DEFINED
  9. #include "src/core/SkEndian.h"
  10. #include "src/sfnt/SkOTTableTypes.h"
  11. #include "src/sfnt/SkOTTable_head.h"
  12. #include "src/sfnt/SkOTTable_loca.h"
  13. #pragma pack(push, 1)
  14. struct SkOTTableGlyphData;
  15. extern uint8_t const * const SK_OT_GlyphData_NoOutline;
  16. struct SkOTTableGlyph {
  17. static const SK_OT_CHAR TAG0 = 'g';
  18. static const SK_OT_CHAR TAG1 = 'l';
  19. static const SK_OT_CHAR TAG2 = 'y';
  20. static const SK_OT_CHAR TAG3 = 'f';
  21. static const SK_OT_ULONG TAG = SkOTTableTAG<SkOTTableGlyph>::value;
  22. class Iterator {
  23. public:
  24. Iterator(const SkOTTableGlyph& glyf,
  25. const SkOTTableIndexToLocation& loca,
  26. SkOTTableHead::IndexToLocFormat locaFormat)
  27. : fGlyf(glyf)
  28. , fLocaFormat(SkOTTableHead::IndexToLocFormat::ShortOffsets == locaFormat.value ? 0 : 1)
  29. , fCurrentGlyphOffset(0)
  30. { fLocaPtr.shortOffset = reinterpret_cast<const SK_OT_USHORT*>(&loca); }
  31. void advance(uint16_t num) {
  32. fLocaPtr.shortOffset += num << fLocaFormat;
  33. fCurrentGlyphOffset = fLocaFormat ? SkEndian_SwapBE32(*fLocaPtr.longOffset)
  34. : uint32_t(SkEndian_SwapBE16(*fLocaPtr.shortOffset) << 1);
  35. }
  36. const SkOTTableGlyphData* next() {
  37. uint32_t previousGlyphOffset = fCurrentGlyphOffset;
  38. advance(1);
  39. if (previousGlyphOffset == fCurrentGlyphOffset) {
  40. return reinterpret_cast<const SkOTTableGlyphData*>(&SK_OT_GlyphData_NoOutline);
  41. } else {
  42. return reinterpret_cast<const SkOTTableGlyphData*>(
  43. reinterpret_cast<const SK_OT_BYTE*>(&fGlyf) + previousGlyphOffset
  44. );
  45. }
  46. }
  47. private:
  48. const SkOTTableGlyph& fGlyf;
  49. uint16_t fLocaFormat; //0 or 1
  50. uint32_t fCurrentGlyphOffset;
  51. union LocaPtr {
  52. const SK_OT_USHORT* shortOffset;
  53. const SK_OT_ULONG* longOffset;
  54. } fLocaPtr;
  55. };
  56. };
  57. struct SkOTTableGlyphData {
  58. SK_OT_SHORT numberOfContours; //== -1 Composite, > 0 Simple
  59. SK_OT_FWORD xMin;
  60. SK_OT_FWORD yMin;
  61. SK_OT_FWORD xMax;
  62. SK_OT_FWORD yMax;
  63. struct Simple {
  64. SK_OT_USHORT endPtsOfContours[1/*numberOfContours*/];
  65. struct Instructions {
  66. SK_OT_USHORT length;
  67. SK_OT_BYTE data[1/*length*/];
  68. };
  69. union Flags {
  70. struct Field {
  71. SK_OT_BYTE_BITFIELD(
  72. OnCurve,
  73. xShortVector,
  74. yShortVector,
  75. Repeat,
  76. xIsSame_xShortVectorPositive,
  77. yIsSame_yShortVectorPositive,
  78. Reserved6,
  79. Reserved7)
  80. } field;
  81. struct Raw {
  82. static const SK_OT_USHORT OnCurveMask = SkTEndian_SwapBE16(1 << 0);
  83. static const SK_OT_USHORT xShortVectorMask = SkTEndian_SwapBE16(1 << 1);
  84. static const SK_OT_USHORT yShortVectorMask = SkTEndian_SwapBE16(1 << 2);
  85. static const SK_OT_USHORT RepeatMask = SkTEndian_SwapBE16(1 << 3);
  86. static const SK_OT_USHORT xIsSame_xShortVectorPositiveMask = SkTEndian_SwapBE16(1 << 4);
  87. static const SK_OT_USHORT yIsSame_yShortVectorPositiveMask = SkTEndian_SwapBE16(1 << 5);
  88. SK_OT_BYTE value;
  89. } raw;
  90. };
  91. //xCoordinates
  92. //yCoordinates
  93. };
  94. struct Composite {
  95. struct Component {
  96. union Flags {
  97. struct Field {
  98. //8-15
  99. SK_OT_BYTE_BITFIELD(
  100. WE_HAVE_INSTRUCTIONS,
  101. USE_MY_METRICS,
  102. OVERLAP_COMPOUND,
  103. SCALED_COMPONENT_OFFSET,
  104. UNSCALED_COMPONENT_OFFSET,
  105. Reserved13,
  106. Reserved14,
  107. Reserved15)
  108. //0-7
  109. SK_OT_BYTE_BITFIELD(
  110. ARG_1_AND_2_ARE_WORDS,
  111. ARGS_ARE_XY_VALUES,
  112. ROUND_XY_TO_GRID,
  113. WE_HAVE_A_SCALE,
  114. RESERVED,
  115. MORE_COMPONENTS,
  116. WE_HAVE_AN_X_AND_Y_SCALE,
  117. WE_HAVE_A_TWO_BY_TWO)
  118. } field;
  119. struct Raw {
  120. static const SK_OT_USHORT ARG_1_AND_2_ARE_WORDS_Mask = SkTEndian_SwapBE16(1 << 0);
  121. static const SK_OT_USHORT ARGS_ARE_XY_VALUES_Mask = SkTEndian_SwapBE16(1 << 1);
  122. static const SK_OT_USHORT ROUND_XY_TO_GRID_Mask = SkTEndian_SwapBE16(1 << 2);
  123. static const SK_OT_USHORT WE_HAVE_A_SCALE_Mask = SkTEndian_SwapBE16(1 << 3);
  124. static const SK_OT_USHORT RESERVED_Mask = SkTEndian_SwapBE16(1 << 4);
  125. static const SK_OT_USHORT MORE_COMPONENTS_Mask = SkTEndian_SwapBE16(1 << 5);
  126. static const SK_OT_USHORT WE_HAVE_AN_X_AND_Y_SCALE_Mask = SkTEndian_SwapBE16(1 << 6);
  127. static const SK_OT_USHORT WE_HAVE_A_TWO_BY_TWO_Mask = SkTEndian_SwapBE16(1 << 7);
  128. static const SK_OT_USHORT WE_HAVE_INSTRUCTIONS_Mask = SkTEndian_SwapBE16(1 << 8);
  129. static const SK_OT_USHORT USE_MY_METRICS_Mask = SkTEndian_SwapBE16(1 << 9);
  130. static const SK_OT_USHORT OVERLAP_COMPOUND_Mask = SkTEndian_SwapBE16(1 << 10);
  131. static const SK_OT_USHORT SCALED_COMPONENT_OFFSET_Mask = SkTEndian_SwapBE16(1 << 11);
  132. static const SK_OT_USHORT UNSCALED_COMPONENT_OFFSET_mask = SkTEndian_SwapBE16(1 << 12);
  133. //Reserved
  134. //Reserved
  135. //Reserved
  136. SK_OT_USHORT value;
  137. } raw;
  138. } flags;
  139. SK_OT_USHORT glyphIndex;
  140. union Transform {
  141. union Matrix {
  142. /** !WE_HAVE_A_SCALE & !WE_HAVE_AN_X_AND_Y_SCALE & !WE_HAVE_A_TWO_BY_TWO */
  143. struct None { } none;
  144. /** WE_HAVE_A_SCALE */
  145. struct Scale {
  146. SK_OT_F2DOT14 a_d;
  147. } scale;
  148. /** WE_HAVE_AN_X_AND_Y_SCALE */
  149. struct ScaleXY {
  150. SK_OT_F2DOT14 a;
  151. SK_OT_F2DOT14 d;
  152. } scaleXY;
  153. /** WE_HAVE_A_TWO_BY_TWO */
  154. struct TwoByTwo {
  155. SK_OT_F2DOT14 a;
  156. SK_OT_F2DOT14 b;
  157. SK_OT_F2DOT14 c;
  158. SK_OT_F2DOT14 d;
  159. } twoByTwo;
  160. };
  161. /** ARG_1_AND_2_ARE_WORDS & ARGS_ARE_XY_VALUES */
  162. struct WordValue {
  163. SK_OT_FWORD e;
  164. SK_OT_FWORD f;
  165. SkOTTableGlyphData::Composite::Component::Transform::Matrix matrix;
  166. } wordValue;
  167. /** !ARG_1_AND_2_ARE_WORDS & ARGS_ARE_XY_VALUES */
  168. struct ByteValue {
  169. SK_OT_CHAR e;
  170. SK_OT_CHAR f;
  171. SkOTTableGlyphData::Composite::Component::Transform::Matrix matrix;
  172. } byteValue;
  173. /** ARG_1_AND_2_ARE_WORDS & !ARGS_ARE_XY_VALUES */
  174. struct WordIndex {
  175. SK_OT_USHORT compoundPointIndex;
  176. SK_OT_USHORT componentPointIndex;
  177. SkOTTableGlyphData::Composite::Component::Transform::Matrix matrix;
  178. } wordIndex;
  179. /** !ARG_1_AND_2_ARE_WORDS & !ARGS_ARE_XY_VALUES */
  180. struct ByteIndex {
  181. SK_OT_BYTE compoundPointIndex;
  182. SK_OT_BYTE componentPointIndex;
  183. SkOTTableGlyphData::Composite::Component::Transform::Matrix matrix;
  184. } byteIndex;
  185. } transform;
  186. } component;//[] last element does not set MORE_COMPONENTS
  187. /** Comes after the last Component if the last component has WE_HAVE_INSTR. */
  188. struct Instructions {
  189. SK_OT_USHORT length;
  190. SK_OT_BYTE data[1/*length*/];
  191. };
  192. };
  193. };
  194. #pragma pack(pop)
  195. #endif