hb-cff2-interp-cs.hh 2.8 KB
Newer Older
M
Michiharu Ariza 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
/*
 * Copyright © 2018 Adobe Systems Incorporated.
 *
 *  This is part of HarfBuzz, a text shaping library.
 *
 * Permission is hereby granted, without written agreement and without
 * license or royalty fees, to use, copy, modify, and distribute this
 * software and its documentation for any purpose, provided that the
 * above copyright notice and the following two paragraphs appear in
 * all copies of this software.
 *
 * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
 * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
 * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
 * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
 * DAMAGE.
 *
 * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
 * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
 * FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
 * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
 * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
 *
 * Adobe Author(s): Michiharu Ariza
 */
#ifndef HB_CFF2_INTERP_CS_HH
#define HB_CFF2_INTERP_CS_HH

#include "hb-private.hh"
#include "hb-cff-interp-cs-common-private.hh"

namespace CFF {

using namespace OT;

struct CFF2CSInterpEnv : CSInterpEnv<CFF2Subrs>
{
  inline void init (const ByteStr &str, const CFF2Subrs &globalSubrs_, const CFF2Subrs &localSubrs_)
  {
    CSInterpEnv<CFF2Subrs>::init (str, globalSubrs_, localSubrs_);
    ivs = 0;
  }

  inline bool fetch_op (OpCode &op)
  {
M
Michiharu Ariza 已提交
46
    if (unlikely (this->substr.avail ()))
M
Michiharu Ariza 已提交
47 48 49
      return CSInterpEnv<CFF2Subrs>::fetch_op (op);

    /* make up return or endchar op */
M
Michiharu Ariza 已提交
50
    if (this->callStack.check_underflow ())
M
Michiharu Ariza 已提交
51 52 53 54 55 56 57 58 59 60 61 62 63
      op = OpCode_return;
    else
      op = OpCode_endchar;
    return true;
  }

  inline unsigned int get_ivs (void) const { return ivs; }
  inline void         set_ivs (unsigned int ivs_) { ivs = ivs_; }

  protected:
  unsigned int  ivs;
};

M
Michiharu Ariza 已提交
64 65
template <typename OPSET, typename PARAM>
struct CFF2CSOpSet : CSOpSet<OPSET, CFF2CSInterpEnv, PARAM>
M
Michiharu Ariza 已提交
66 67 68 69 70 71
{
  static inline bool process_op (OpCode op, CFF2CSInterpEnv &env, PARAM& param)
  {
    switch (op) {

      case OpCode_blendcs:
M
Michiharu Ariza 已提交
72
        //env.flush_stack (); // XXX: TODO
M
Michiharu Ariza 已提交
73 74 75 76 77 78
        break;
      case OpCode_vsindexcs:
        {
          unsigned int ivs;
          if (unlikely (!env.argStack.check_pop_uint (ivs))) return false;
          env.set_ivs (ivs);
M
Michiharu Ariza 已提交
79
          //env.flush_stack ();
M
Michiharu Ariza 已提交
80 81 82
        }
        break;
      default:
M
Michiharu Ariza 已提交
83
        typedef CSOpSet<OPSET, CFF2CSInterpEnv, PARAM>  SUPER;
M
Michiharu Ariza 已提交
84 85 86 87 88 89 90 91 92 93 94 95 96 97
        if (unlikely (!SUPER::process_op (op, env, param)))
          return false;
        break;
    }
    return true;
  }
};

template <typename OPSET, typename PARAM>
struct CFF2CSInterpreter : CSInterpreter<CFF2CSInterpEnv, OPSET, PARAM> {};

} /* namespace CFF */

#endif /* HB_CFF2_INTERP_CS_HH */