tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

hb-aat-layout-bsln-table.hh (4636B)


      1 /*
      2 * Copyright © 2018  Ebrahim Byagowi
      3 *
      4 *  This is part of HarfBuzz, a text shaping library.
      5 *
      6 * Permission is hereby granted, without written agreement and without
      7 * license or royalty fees, to use, copy, modify, and distribute this
      8 * software and its documentation for any purpose, provided that the
      9 * above copyright notice and the following two paragraphs appear in
     10 * all copies of this software.
     11 *
     12 * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
     13 * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
     14 * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
     15 * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
     16 * DAMAGE.
     17 *
     18 * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
     19 * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
     20 * FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
     21 * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
     22 * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
     23 */
     24 
     25 #ifndef HB_AAT_LAYOUT_BSLN_TABLE_HH
     26 #define HB_AAT_LAYOUT_BSLN_TABLE_HH
     27 
     28 #include "hb-aat-layout-common.hh"
     29 
     30 /*
     31 * bsln -- Baseline
     32 * https://developer.apple.com/fonts/TrueType-Reference-Manual/RM06/Chap6bsln.html
     33 */
     34 #define HB_AAT_TAG_bsln HB_TAG('b','s','l','n')
     35 
     36 
     37 namespace AAT {
     38 
     39 
     40 struct BaselineTableFormat0Part
     41 {
     42  bool sanitize (hb_sanitize_context_t *c) const
     43  {
     44    TRACE_SANITIZE (this);
     45    return_trace (c->check_struct (this));
     46  }
     47 
     48  protected:
     49  // Roman, Ideographic centered, Ideographic low, Hanging and Math
     50  // are the default defined ones, but any other maybe accessed also.
     51  HBINT16	deltas[32];	/* These are the FUnit distance deltas from
     52 			 * the font's natural baseline to the other
     53 			 * baselines used in the font. */
     54  public:
     55  DEFINE_SIZE_STATIC (64);
     56 };
     57 
     58 struct BaselineTableFormat1Part
     59 {
     60  bool sanitize (hb_sanitize_context_t *c) const
     61  {
     62    TRACE_SANITIZE (this);
     63    return_trace (likely (c->check_struct (this) &&
     64 		  lookupTable.sanitize (c)));
     65  }
     66 
     67  protected:
     68  HBINT16	deltas[32];	/* ditto */
     69  Lookup<HBUINT16>
     70 	lookupTable;	/* Lookup table that maps glyphs to their
     71 			 * baseline values. */
     72  public:
     73  DEFINE_SIZE_MIN (66);
     74 };
     75 
     76 struct BaselineTableFormat2Part
     77 {
     78  bool sanitize (hb_sanitize_context_t *c) const
     79  {
     80    TRACE_SANITIZE (this);
     81    return_trace (c->check_struct (this));
     82  }
     83 
     84  protected:
     85  HBGlyphID16	stdGlyph;	/* The specific glyph index number in this
     86 			 * font that is used to set the baseline values.
     87 			 * This is the standard glyph.
     88 			 * This glyph must contain a set of control points
     89 			 * (whose numbers are contained in the ctlPoints field)
     90 			 * that are used to determine baseline distances. */
     91  HBUINT16	ctlPoints[32];	/* Set of control point numbers,
     92 			 * associated with the standard glyph.
     93 			 * A value of 0xFFFF means there is no corresponding
     94 			 * control point in the standard glyph. */
     95  public:
     96  DEFINE_SIZE_STATIC (66);
     97 };
     98 
     99 struct BaselineTableFormat3Part
    100 {
    101  bool sanitize (hb_sanitize_context_t *c) const
    102  {
    103    TRACE_SANITIZE (this);
    104    return_trace (likely (c->check_struct (this) && lookupTable.sanitize (c)));
    105  }
    106 
    107  protected:
    108  HBGlyphID16	stdGlyph;	/* ditto */
    109  HBUINT16	ctlPoints[32];	/* ditto */
    110  Lookup<HBUINT16>
    111 	lookupTable;	/* Lookup table that maps glyphs to their
    112 			 * baseline values. */
    113  public:
    114  DEFINE_SIZE_MIN (68);
    115 };
    116 
    117 struct bsln
    118 {
    119  static constexpr hb_tag_t tableTag = HB_AAT_TAG_bsln;
    120 
    121  bool sanitize (hb_sanitize_context_t *c) const
    122  {
    123    TRACE_SANITIZE (this);
    124    if (unlikely (!(c->check_struct (this) && defaultBaseline < 32)))
    125      return_trace (false);
    126    hb_barrier ();
    127 
    128    switch (format)
    129    {
    130    case 0: return_trace (parts.format0.sanitize (c));
    131    case 1: return_trace (parts.format1.sanitize (c));
    132    case 2: return_trace (parts.format2.sanitize (c));
    133    case 3: return_trace (parts.format3.sanitize (c));
    134    default:return_trace (true);
    135    }
    136  }
    137 
    138  protected:
    139  FixedVersion<>version;	/* Version number of the Baseline table. */
    140  HBUINT16	format;		/* Format of the baseline table. Only one baseline
    141 			 * format may be selected for the font. */
    142  HBUINT16	defaultBaseline;/* Default baseline value for all glyphs.
    143 			 * This value can be from 0 through 31. */
    144  union {
    145  // Distance-Based Formats
    146  BaselineTableFormat0Part	format0;
    147  BaselineTableFormat1Part	format1;
    148  // Control Point-based Formats
    149  BaselineTableFormat2Part	format2;
    150  BaselineTableFormat3Part	format3;
    151  } parts;
    152  public:
    153  DEFINE_SIZE_MIN (8);
    154 };
    155 
    156 } /* namespace AAT */
    157 
    158 
    159 #endif /* HB_AAT_LAYOUT_BSLN_TABLE_HH */