Imported Upstream version 8.2.2
[platform/upstream/harfbuzz.git] / src / hb-ot-cff2-table.hh
index 6e1b01c..af24bb9 100644 (file)
@@ -28,8 +28,9 @@
 #define HB_OT_CFF2_TABLE_HH
 
 #include "hb-ot-cff-common.hh"
-#include "hb-subset-cff2.hh"
+#include "hb-subset-cff-common.hh"
 #include "hb-draw.hh"
+#include "hb-paint.hh"
 
 namespace CFF {
 
@@ -37,10 +38,9 @@ namespace CFF {
  * CFF2 -- Compact Font Format (CFF) Version 2
  * https://docs.microsoft.com/en-us/typography/opentype/spec/cff2
  */
-#define HB_OT_TAG_cff2 HB_TAG('C','F','F','2')
+#define HB_OT_TAG_CFF2 HB_TAG('C','F','F','2')
 
 typedef CFFIndex<HBUINT32>  CFF2Index;
-template <typename Type> struct CFF2IndexOf : CFFIndexOf<HBUINT32, Type> {};
 
 typedef CFF2Index         CFF2CharStrings;
 typedef Subrs<HBUINT32>   CFF2Subrs;
@@ -56,7 +56,7 @@ struct CFF2FDSelect
     unsigned int size = src.get_size (num_glyphs);
     CFF2FDSelect *dest = c->allocate_size<CFF2FDSelect> (size);
     if (unlikely (!dest)) return_trace (false);
-    memcpy (dest, &src, size);
+    hb_memcpy (dest, &src, size);
     return_trace (true);
   }
 
@@ -124,7 +124,7 @@ struct CFF2VariationStore
     unsigned int size_ = varStore->get_size ();
     CFF2VariationStore *dest = c->allocate_size<CFF2VariationStore> (size_);
     if (unlikely (!dest)) return_trace (false);
-    memcpy (dest, varStore, size_);
+    hb_memcpy (dest, varStore, size_);
     return_trace (true);
   }
 
@@ -247,12 +247,8 @@ typedef cff2_private_dict_values_base_t<num_dict_val_t> cff2_private_dict_values
 
 struct cff2_priv_dict_interp_env_t : num_interp_env_t
 {
-  void init (const byte_str_t &str)
-  {
-    num_interp_env_t::init (str);
-    ivs = 0;
-    seen_vsindex = false;
-  }
+  cff2_priv_dict_interp_env_t (const hb_ubytes_t &str) :
+    num_interp_env_t (str) {}
 
   void process_vsindex ()
   {
@@ -267,8 +263,8 @@ struct cff2_priv_dict_interp_env_t : num_interp_env_t
   void  set_ivs (unsigned int ivs_) { ivs = ivs_; }
 
   protected:
-  unsigned int  ivs;
-  bool   seen_vsindex;
+  unsigned int  ivs = 0;
+  bool   seen_vsindex = false;
 };
 
 struct cff2_private_dict_opset_t : dict_opset_t
@@ -286,9 +282,6 @@ struct cff2_private_dict_opset_t : dict_opset_t
       case OpCode_BlueFuzz:
       case OpCode_ExpansionFactor:
       case OpCode_LanguageGroup:
-       val.single_val = env.argStack.pop_num ();
-       env.clear_args ();
-       break;
       case OpCode_BlueValues:
       case OpCode_OtherBlues:
       case OpCode_FamilyBlues:
@@ -385,7 +378,7 @@ using namespace CFF;
 
 struct cff2
 {
-  static constexpr hb_tag_t tableTag = HB_OT_TAG_cff2;
+  static constexpr hb_tag_t tableTag = HB_OT_TAG_CFF2;
 
   bool sanitize (hb_sanitize_context_t *c) const
   {
@@ -397,8 +390,12 @@ struct cff2
   template <typename PRIVOPSET, typename PRIVDICTVAL>
   struct accelerator_templ_t
   {
+    static constexpr hb_tag_t tableTag = cff2::tableTag;
+
     accelerator_templ_t (hb_face_t *face)
     {
+      if (!face) return;
+
       topDict.init ();
       fontDicts.init ();
       privateDicts.init ();
@@ -415,10 +412,10 @@ struct cff2
         goto fail;
 
       { /* parse top dict */
-       byte_str_t topDictStr (cff2 + cff2->topDict, cff2->topDictSize);
+       hb_ubytes_t topDictStr = (cff2 + cff2->topDict).as_ubytes (cff2->topDictSize);
        if (unlikely (!topDictStr.sanitize (&sc))) goto fail;
-       cff2_top_dict_interpreter_t top_interp;
-       top_interp.env.init (topDictStr);
+       num_interp_env_t env (topDictStr);
+       cff2_top_dict_interpreter_t top_interp (env);
        topDict.init ();
        if (unlikely (!top_interp.interpret (topDict))) goto fail;
       }
@@ -447,20 +444,20 @@ struct cff2
       /* parse font dicts and gather private dicts */
       for (unsigned int i = 0; i < fdCount; i++)
       {
-       const byte_str_t fontDictStr = (*fdArray)[i];
+       const hb_ubytes_t fontDictStr = (*fdArray)[i];
        if (unlikely (!fontDictStr.sanitize (&sc))) goto fail;
        cff2_font_dict_values_t  *font;
-       cff2_font_dict_interpreter_t font_interp;
-       font_interp.env.init (fontDictStr);
+       num_interp_env_t env (fontDictStr);
+       cff2_font_dict_interpreter_t font_interp (env);
        font = fontDicts.push ();
        if (unlikely (font == &Crap (cff2_font_dict_values_t))) goto fail;
        font->init ();
        if (unlikely (!font_interp.interpret (*font))) goto fail;
 
-       const byte_str_t privDictStr (StructAtOffsetOrNull<UnsizedByteStr> (cff2, font->privateDictInfo.offset), font->privateDictInfo.size);
+       const hb_ubytes_t privDictStr = StructAtOffsetOrNull<UnsizedByteStr> (cff2, font->privateDictInfo.offset).as_ubytes (font->privateDictInfo.size);
        if (unlikely (!privDictStr.sanitize (&sc))) goto fail;
-       dict_interpreter_t<PRIVOPSET, PRIVDICTVAL, cff2_priv_dict_interp_env_t>  priv_interp;
-       priv_interp.env.init(privDictStr);
+       cff2_priv_dict_interp_env_t env2 (privDictStr);
+       dict_interpreter_t<PRIVOPSET, PRIVDICTVAL, cff2_priv_dict_interp_env_t> priv_interp (env2);
        privateDicts[i].init ();
        if (unlikely (!priv_interp.interpret (privateDicts[i]))) goto fail;
 
@@ -470,7 +467,6 @@ struct cff2
          goto fail;
       }
 
-
       return;
 
       fail:
@@ -487,13 +483,20 @@ struct cff2
       blob = nullptr;
     }
 
+    hb_vector_t<uint16_t> *create_glyph_to_sid_map () const
+    {
+      return nullptr;
+    }
+
+    hb_blob_t *get_blob () const { return blob; }
+
     bool is_valid () const { return blob; }
 
     protected:
-    hb_blob_t                  *blob = nullptr;
     hb_sanitize_context_t      sc;
 
     public:
+    hb_blob_t                  *blob = nullptr;
     cff2_top_dict_values_t     topDict;
     const CFF2Subrs            *globalSubrs = nullptr;
     const CFF2VariationStore   *varStore = nullptr;
@@ -515,14 +518,28 @@ struct cff2
     HB_INTERNAL bool get_extents (hb_font_t *font,
                                  hb_codepoint_t glyph,
                                  hb_glyph_extents_t *extents) const;
-#ifdef HB_EXPERIMENTAL_API
-    HB_INTERNAL bool get_path (hb_font_t *font, hb_codepoint_t glyph, draw_helper_t &draw_helper) const;
-#endif
+    HB_INTERNAL bool paint_glyph (hb_font_t *font, hb_codepoint_t glyph, hb_paint_funcs_t *funcs, void *data, hb_color_t foreground) const;
+    HB_INTERNAL bool get_path (hb_font_t *font, hb_codepoint_t glyph, hb_draw_session_t &draw_session) const;
   };
 
-  typedef accelerator_templ_t<cff2_private_dict_opset_subset_t, cff2_private_dict_values_subset_t> accelerator_subset_t;
+  struct accelerator_subset_t : accelerator_templ_t<cff2_private_dict_opset_subset_t, cff2_private_dict_values_subset_t>
+  {
+    accelerator_subset_t (hb_face_t *face) : SUPER (face) {}
+    ~accelerator_subset_t ()
+    {
+      if (cff_accelerator)
+       cff_subset_accelerator_t::destroy (cff_accelerator);
+    }
 
-  bool subset (hb_subset_context_t *c) const { return hb_subset_cff2 (c); }
+    HB_INTERNAL bool subset (hb_subset_context_t *c) const;
+    HB_INTERNAL bool serialize (hb_serialize_context_t *c,
+                               struct cff2_subset_plan &plan,
+                               hb_array_t<int> normalized_coords) const;
+
+    mutable CFF::cff_subset_accelerator_t* cff_accelerator = nullptr;
+
+    typedef accelerator_templ_t<cff2_private_dict_opset_subset_t, cff2_private_dict_values_subset_t> SUPER;
+  };
 
   public:
   FixedVersion<HBUINT8>                version;        /* Version of CFF2 table. set to 0x0200u */
@@ -537,6 +554,10 @@ struct cff2_accelerator_t : cff2::accelerator_t {
   cff2_accelerator_t (hb_face_t *face) : cff2::accelerator_t (face) {}
 };
 
+struct cff2_subset_accelerator_t : cff2::accelerator_subset_t {
+  cff2_subset_accelerator_t (hb_face_t *face) : cff2::accelerator_subset_t (face) {}
+};
+
 } /* namespace OT */
 
 #endif /* HB_OT_CFF2_TABLE_HH */