hb-cff2-interp-cs.hh 3.2 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
/*
 * 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

29 30
#include "hb.hh"
#include "hb-cff-interp-cs-common.hh"
M
Michiharu Ariza 已提交
31 32 33 34 35

namespace CFF {

using namespace OT;

36
struct CFF2CSInterpEnv : CSInterpEnv<BlendArg, CFF2Subrs>
M
Michiharu Ariza 已提交
37 38 39
{
  inline void init (const ByteStr &str, const CFF2Subrs &globalSubrs_, const CFF2Subrs &localSubrs_)
  {
40
    SUPER::init (str, globalSubrs_, localSubrs_);
M
Michiharu Ariza 已提交
41 42 43 44 45
    ivs = 0;
  }

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

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

57
  inline void process_vsindex (void)
M
Michiharu Ariza 已提交
58 59
  {
    unsigned int  index;
60 61
    if (likely (argStack.check_pop_uint (index)))
      set_ivs (argStack.check_pop_uint (index));
M
Michiharu Ariza 已提交
62 63
  }

M
Michiharu Ariza 已提交
64 65 66 67 68
  inline unsigned int get_ivs (void) const { return ivs; }
  inline void         set_ivs (unsigned int ivs_) { ivs = ivs_; }

  protected:
  unsigned int  ivs;
69 70

  typedef CSInterpEnv<BlendArg, CFF2Subrs> SUPER;
M
Michiharu Ariza 已提交
71 72
};

M
Michiharu Ariza 已提交
73
template <typename OPSET, typename PARAM>
74
struct CFF2CSOpSet : CSOpSet<BlendArg, OPSET, CFF2CSInterpEnv, PARAM>
M
Michiharu Ariza 已提交
75 76 77 78 79 80
{
  static inline bool process_op (OpCode op, CFF2CSInterpEnv &env, PARAM& param)
  {
    switch (op) {

      case OpCode_blendcs:
M
Michiharu Ariza 已提交
81 82
        return OPSET::process_blend (env, param);

M
Michiharu Ariza 已提交
83
      case OpCode_vsindexcs:
84 85
        OPSET::process_vsindex (env, param);
        break;
M
Michiharu Ariza 已提交
86

M
Michiharu Ariza 已提交
87 88 89 90 91 92 93
      default:
        if (unlikely (!SUPER::process_op (op, env, param)))
          return false;
        break;
    }
    return true;
  }
M
Michiharu Ariza 已提交
94 95 96 97

  static inline bool process_blend (CFF2CSInterpEnv &env, PARAM& param)
  {
    // XXX: TODO leave default values?
98
    OPSET::flush_args (env, param);
M
Michiharu Ariza 已提交
99 100 101
    return true;
  }

102
  static inline void process_vsindex (CFF2CSInterpEnv &env, PARAM& param)
M
Michiharu Ariza 已提交
103
  {
104 105
    env.process_vsindex ();
    OPSET::flush_n_args_and_op (OpCode_vsindexcs, 1, env, param);
M
Michiharu Ariza 已提交
106
  }
107 108 109

  private:
  typedef CSOpSet<BlendArg, OPSET, CFF2CSInterpEnv, PARAM>  SUPER;
M
Michiharu Ariza 已提交
110 111 112 113 114 115 116 117
};

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

} /* namespace CFF */

#endif /* HB_CFF2_INTERP_CS_HH */