How to use the restructure.int16 function in restructure

To help you get started, we’ve selected a few restructure examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github foliojs / fontkit / src / tables / GDEF.js View on Github external
coverage:       new r.Pointer(r.uint16, Coverage),
  glyphCount:     r.uint16,
  attachPoints:   new r.Array(new r.Pointer(r.uint16, AttachPoint), 'glyphCount')
});

let CaretValue = new r.VersionedStruct(r.uint16, {
  1: { // Design units only
    coordinate: r.int16
  },

  2: { // Contour point
    caretValuePoint: r.uint16
  },

  3: { // Design units plus Device table
    coordinate:     r.int16,
    deviceTable:    new r.Pointer(r.uint16, Device)
  }
});

let LigGlyph = new r.Array(new r.Pointer(r.uint16, CaretValue), r.uint16);

let LigCaretList = new r.Struct({
  coverage:       new r.Pointer(r.uint16, Coverage),
  ligGlyphCount:  r.uint16,
  ligGlyphs:      new r.Array(new r.Pointer(r.uint16, LigGlyph), 'ligGlyphCount')
});

let MarkGlyphSetsDef = new r.Struct({
  markSetTableFormat: r.uint16,
  markSetCount:       r.uint16,
  coverage:           new r.Array(new r.Pointer(r.uint32, Coverage), 'markSetCount')
github foliojs / fontkit / src / tables / OS2.js View on Github external
xAvgCharWidth:          r.int16,   // average weighted advance width of lower case letters and space
    usWeightClass:          r.uint16,  // visual weight of stroke in glyphs
    usWidthClass:           r.uint16,  // relative change from the normal aspect ratio (width to height ratio)
    fsType:                 new r.Bitfield(r.uint16, [ // Indicates font embedding licensing rights
      null, 'noEmbedding', 'viewOnly', 'editable', null,
      null, null, null, 'noSubsetting', 'bitmapOnly'
    ]),
    ySubscriptXSize:        r.int16,   // recommended horizontal size in pixels for subscripts
    ySubscriptYSize:        r.int16,   // recommended vertical size in pixels for subscripts
    ySubscriptXOffset:      r.int16,   // recommended horizontal offset for subscripts
    ySubscriptYOffset:      r.int16,   // recommended vertical offset form the baseline for subscripts
    ySuperscriptXSize:      r.int16,   // recommended horizontal size in pixels for superscripts
    ySuperscriptYSize:      r.int16,   // recommended vertical size in pixels for superscripts
    ySuperscriptXOffset:    r.int16,   // recommended horizontal offset for superscripts
    ySuperscriptYOffset:    r.int16,   // recommended vertical offset from the baseline for superscripts
    yStrikeoutSize:         r.int16,   // width of the strikeout stroke
    yStrikeoutPosition:     r.int16,   // position of the strikeout stroke relative to the baseline
    sFamilyClass:           r.int16,   // classification of font-family design
    panose:                 new r.Array(r.uint8, 10),   // describe the visual characteristics of a given typeface
    ulCharRange:            new r.Array(r.uint32, 4),
    vendorID:               new r.String(4),          // four character identifier for the font vendor
    fsSelection:            new r.Bitfield(r.uint16, [  // bit field containing information about the font
      'italic', 'underscore', 'negative', 'outlined', 'strikeout',
      'bold', 'regular', 'useTypoMetrics', 'wws', 'oblique'
    ]),
    usFirstCharIndex:       r.uint16,  // The minimum Unicode index in this font
    usLastCharIndex:        r.uint16   // The maximum Unicode index in this font
  },

  // The Apple version of this table ends here, but the Microsoft one continues on...
  0: {},
github foliojs / fontkit / src / tables / head.js View on Github external
flags:              r.uint16,
  unitsPerEm:         r.uint16,                  // range from 64 to 16384
  created:            new r.Array(r.int32, 2),
  modified:           new r.Array(r.int32, 2),
  xMin:               r.int16,                   // for all glyph bounding boxes
  yMin:               r.int16,                   // for all glyph bounding boxes
  xMax:               r.int16,                   // for all glyph bounding boxes
  yMax:               r.int16,                   // for all glyph bounding boxes
  macStyle:           new r.Bitfield(r.uint16, [
    'bold', 'italic', 'underline', 'outline',
    'shadow', 'condensed', 'extended'
  ]),
  lowestRecPPEM:      r.uint16,                  // smallest readable size in pixels
  fontDirectionHint:  r.int16,
  indexToLocFormat:   r.int16,                   // 0 for short offsets, 1 for long
  glyphDataFormat:    r.int16                    // 0 for current format
});
github foliojs / fontkit / src / glyph / TTFGlyph.js View on Github external
import Glyph from './Glyph';
import Path from './Path';
import BBox from './BBox';
import r from 'restructure';

// The header for both simple and composite glyphs
let GlyfHeader = new r.Struct({
  numberOfContours: r.int16, // if negative, this is a composite glyph
  xMin:             r.int16,
  yMin:             r.int16,
  xMax:             r.int16,
  yMax:             r.int16
});

// Flags for simple glyphs
const ON_CURVE        = 1 << 0;
const X_SHORT_VECTOR  = 1 << 1;
const Y_SHORT_VECTOR  = 1 << 2;
const REPEAT          = 1 << 3;
const SAME_X          = 1 << 4;
const SAME_Y          = 1 << 5;

// Flags for composite glyphs
const ARG_1_AND_2_ARE_WORDS     = 1 << 0;
const ARGS_ARE_XY_VALUES        = 1 << 1;
const ROUND_XY_TO_GRID          = 1 << 2;
const WE_HAVE_A_SCALE           = 1 << 3;
github foliojs / fontkit / src / tables / OS2.js View on Github external
import r from 'restructure';

var OS2 = new r.VersionedStruct(r.uint16, {
  header: {
    xAvgCharWidth:          r.int16,   // average weighted advance width of lower case letters and space
    usWeightClass:          r.uint16,  // visual weight of stroke in glyphs
    usWidthClass:           r.uint16,  // relative change from the normal aspect ratio (width to height ratio)
    fsType:                 new r.Bitfield(r.uint16, [ // Indicates font embedding licensing rights
      null, 'noEmbedding', 'viewOnly', 'editable', null,
      null, null, null, 'noSubsetting', 'bitmapOnly'
    ]),
    ySubscriptXSize:        r.int16,   // recommended horizontal size in pixels for subscripts
    ySubscriptYSize:        r.int16,   // recommended vertical size in pixels for subscripts
    ySubscriptXOffset:      r.int16,   // recommended horizontal offset for subscripts
    ySubscriptYOffset:      r.int16,   // recommended vertical offset form the baseline for subscripts
    ySuperscriptXSize:      r.int16,   // recommended horizontal size in pixels for superscripts
    ySuperscriptYSize:      r.int16,   // recommended vertical size in pixels for superscripts
    ySuperscriptXOffset:    r.int16,   // recommended horizontal offset for superscripts
    ySuperscriptYOffset:    r.int16,   // recommended vertical offset from the baseline for superscripts
    yStrikeoutSize:         r.int16,   // width of the strikeout stroke
    yStrikeoutPosition:     r.int16,   // position of the strikeout stroke relative to the baseline
    sFamilyClass:           r.int16,   // classification of font-family design
    panose:                 new r.Array(r.uint8, 10),   // describe the visual characteristics of a given typeface
    ulCharRange:            new r.Array(r.uint32, 4),
    vendorID:               new r.String(4),          // four character identifier for the font vendor
    fsSelection:            new r.Bitfield(r.uint16, [  // bit field containing information about the font
      'italic', 'underscore', 'negative', 'outlined', 'strikeout',
      'bold', 'regular', 'useTypoMetrics', 'wws', 'oblique'
    ]),
    usFirstCharIndex:       r.uint16,  // The minimum Unicode index in this font
    usLastCharIndex:        r.uint16   // The maximum Unicode index in this font
github foliojs / fontkit / src / tables / OS2.js View on Github external
panose:                 new r.Array(r.uint8, 10),   // describe the visual characteristics of a given typeface
    ulCharRange:            new r.Array(r.uint32, 4),
    vendorID:               new r.String(4),          // four character identifier for the font vendor
    fsSelection:            new r.Bitfield(r.uint16, [  // bit field containing information about the font
      'italic', 'underscore', 'negative', 'outlined', 'strikeout',
      'bold', 'regular', 'useTypoMetrics', 'wws', 'oblique'
    ]),
    usFirstCharIndex:       r.uint16,  // The minimum Unicode index in this font
    usLastCharIndex:        r.uint16   // The maximum Unicode index in this font
  },

  // The Apple version of this table ends here, but the Microsoft one continues on...
  0: {},

  1: {
    typoAscender:       r.int16,
    typoDescender:      r.int16,
    typoLineGap:        r.int16,
    winAscent:          r.uint16,
    winDescent:         r.uint16,
    codePageRange:      new r.Array(r.uint32, 2)
  },

  2: {
    // these should be common with version 1 somehow
    typoAscender:       r.int16,
    typoDescender:      r.int16,
    typoLineGap:        r.int16,
    winAscent:          r.uint16,
    winDescent:         r.uint16,
    codePageRange:      new r.Array(r.uint32, 2),
github foliojs / fontkit / src / tables / OS2.js View on Github external
usWidthClass:           r.uint16,  // relative change from the normal aspect ratio (width to height ratio)
    fsType:                 new r.Bitfield(r.uint16, [ // Indicates font embedding licensing rights
      null, 'noEmbedding', 'viewOnly', 'editable', null,
      null, null, null, 'noSubsetting', 'bitmapOnly'
    ]),
    ySubscriptXSize:        r.int16,   // recommended horizontal size in pixels for subscripts
    ySubscriptYSize:        r.int16,   // recommended vertical size in pixels for subscripts
    ySubscriptXOffset:      r.int16,   // recommended horizontal offset for subscripts
    ySubscriptYOffset:      r.int16,   // recommended vertical offset form the baseline for subscripts
    ySuperscriptXSize:      r.int16,   // recommended horizontal size in pixels for superscripts
    ySuperscriptYSize:      r.int16,   // recommended vertical size in pixels for superscripts
    ySuperscriptXOffset:    r.int16,   // recommended horizontal offset for superscripts
    ySuperscriptYOffset:    r.int16,   // recommended vertical offset from the baseline for superscripts
    yStrikeoutSize:         r.int16,   // width of the strikeout stroke
    yStrikeoutPosition:     r.int16,   // position of the strikeout stroke relative to the baseline
    sFamilyClass:           r.int16,   // classification of font-family design
    panose:                 new r.Array(r.uint8, 10),   // describe the visual characteristics of a given typeface
    ulCharRange:            new r.Array(r.uint32, 4),
    vendorID:               new r.String(4),          // four character identifier for the font vendor
    fsSelection:            new r.Bitfield(r.uint16, [  // bit field containing information about the font
      'italic', 'underscore', 'negative', 'outlined', 'strikeout',
      'bold', 'regular', 'useTypoMetrics', 'wws', 'oblique'
    ]),
    usFirstCharIndex:       r.uint16,  // The minimum Unicode index in this font
    usLastCharIndex:        r.uint16   // The maximum Unicode index in this font
  },

  // The Apple version of this table ends here, but the Microsoft one continues on...
  0: {},

  1: {
    typoAscender:       r.int16,
github foliojs / fontkit / src / DFont.js View on Github external
import r from 'restructure';
import TTFFont from './TTFFont';

let DFontName = new r.String(r.uint8);
let DFontData = new r.Struct({
  len: r.uint32,
  buf: new r.Buffer('len')
});

let Ref = new r.Struct({
  id: r.uint16,
  nameOffset: r.int16,
  attr: r.uint8,
  dataOffset: r.uint24,
  handle: r.uint32
});

let Type = new r.Struct({
  name: new r.String(4),
  maxTypeIndex: r.uint16,
  refList: new r.Pointer(r.uint16, new r.Array(Ref, t => t.maxTypeIndex + 1), { type: 'parent' })
});

let TypeList = new r.Struct({
  length: r.uint16,
  types: new r.Array(Type, t => t.length + 1)
});
github foliojs / fontkit / src / tables / OS2.js View on Github external
typoDescender:      r.int16,
    typoLineGap:        r.int16,
    winAscent:          r.uint16,
    winDescent:         r.uint16,
    codePageRange:      new r.Array(r.uint32, 2),

    xHeight:            r.int16,
    capHeight:          r.int16,
    defaultChar:        r.uint16,
    breakChar:          r.uint16,
    maxContent:         r.uint16
  },

  5: {
    typoAscender:       r.int16,
    typoDescender:      r.int16,
    typoLineGap:        r.int16,
    winAscent:          r.uint16,
    winDescent:         r.uint16,
    codePageRange:      new r.Array(r.uint32, 2),

    xHeight:            r.int16,
    capHeight:          r.int16,
    defaultChar:        r.uint16,
    breakChar:          r.uint16,
    maxContent:         r.uint16,

    usLowerOpticalPointSize: r.uint16,
    usUpperOpticalPointSize: r.uint16
  }
});
github foliojs / fontkit / src / tables / kern.js View on Github external
left:   r.uint16,
  right:  r.uint16,
  value:  r.int16
});

let ClassTable = new r.Struct({
  firstGlyph: r.uint16,
  nGlyphs: r.uint16,
  offsets: new r.Array(r.uint16, 'nGlyphs'),
  max: t => t.offsets.length && Math.max.apply(Math, t.offsets)
});

let Kern2Array = new r.Struct({
  off: t => t._startOffset - t.parent.parent._startOffset,
  len: t => (((t.parent.leftTable.max - t.off) / t.parent.rowWidth) + 1) * (t.parent.rowWidth / 2),
  values: new r.LazyArray(r.int16, 'len')
});

let KernSubtable = new r.VersionedStruct('format', {
  0: {
    nPairs:         r.uint16,
    searchRange:    r.uint16,
    entrySelector:  r.uint16,
    rangeShift:     r.uint16,
    pairs:          new r.Array(KernPair, 'nPairs')
  },

  2: {
    rowWidth:   r.uint16,
    leftTable:  new r.Pointer(r.uint16, ClassTable, {type: 'parent'}),
    rightTable: new r.Pointer(r.uint16, ClassTable, {type: 'parent'}),
    array:      new r.Pointer(r.uint16, Kern2Array, {type: 'parent'})