1*2d1272b8SAndroid Build Coastguard Worker /* 2*2d1272b8SAndroid Build Coastguard Worker * Copyright © 2009 Red Hat, Inc. 3*2d1272b8SAndroid Build Coastguard Worker * Copyright © 2018 Google, Inc. 4*2d1272b8SAndroid Build Coastguard Worker * 5*2d1272b8SAndroid Build Coastguard Worker * This is part of HarfBuzz, a text shaping library. 6*2d1272b8SAndroid Build Coastguard Worker * 7*2d1272b8SAndroid Build Coastguard Worker * Permission is hereby granted, without written agreement and without 8*2d1272b8SAndroid Build Coastguard Worker * license or royalty fees, to use, copy, modify, and distribute this 9*2d1272b8SAndroid Build Coastguard Worker * software and its documentation for any purpose, provided that the 10*2d1272b8SAndroid Build Coastguard Worker * above copyright notice and the following two paragraphs appear in 11*2d1272b8SAndroid Build Coastguard Worker * all copies of this software. 12*2d1272b8SAndroid Build Coastguard Worker * 13*2d1272b8SAndroid Build Coastguard Worker * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR 14*2d1272b8SAndroid Build Coastguard Worker * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES 15*2d1272b8SAndroid Build Coastguard Worker * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN 16*2d1272b8SAndroid Build Coastguard Worker * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH 17*2d1272b8SAndroid Build Coastguard Worker * DAMAGE. 18*2d1272b8SAndroid Build Coastguard Worker * 19*2d1272b8SAndroid Build Coastguard Worker * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, 20*2d1272b8SAndroid Build Coastguard Worker * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 21*2d1272b8SAndroid Build Coastguard Worker * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS 22*2d1272b8SAndroid Build Coastguard Worker * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO 23*2d1272b8SAndroid Build Coastguard Worker * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. 24*2d1272b8SAndroid Build Coastguard Worker * 25*2d1272b8SAndroid Build Coastguard Worker * Red Hat Author(s): Behdad Esfahbod 26*2d1272b8SAndroid Build Coastguard Worker * Google Author(s): Behdad Esfahbod 27*2d1272b8SAndroid Build Coastguard Worker */ 28*2d1272b8SAndroid Build Coastguard Worker 29*2d1272b8SAndroid Build Coastguard Worker #ifndef HB_BLOB_HH 30*2d1272b8SAndroid Build Coastguard Worker #define HB_BLOB_HH 31*2d1272b8SAndroid Build Coastguard Worker 32*2d1272b8SAndroid Build Coastguard Worker #include "hb.hh" 33*2d1272b8SAndroid Build Coastguard Worker 34*2d1272b8SAndroid Build Coastguard Worker 35*2d1272b8SAndroid Build Coastguard Worker /* 36*2d1272b8SAndroid Build Coastguard Worker * hb_blob_t 37*2d1272b8SAndroid Build Coastguard Worker */ 38*2d1272b8SAndroid Build Coastguard Worker 39*2d1272b8SAndroid Build Coastguard Worker struct hb_blob_t 40*2d1272b8SAndroid Build Coastguard Worker { ~hb_blob_thb_blob_t41*2d1272b8SAndroid Build Coastguard Worker ~hb_blob_t () { destroy_user_data (); } 42*2d1272b8SAndroid Build Coastguard Worker destroy_user_datahb_blob_t43*2d1272b8SAndroid Build Coastguard Worker void destroy_user_data () 44*2d1272b8SAndroid Build Coastguard Worker { 45*2d1272b8SAndroid Build Coastguard Worker if (destroy) 46*2d1272b8SAndroid Build Coastguard Worker { 47*2d1272b8SAndroid Build Coastguard Worker destroy (user_data); 48*2d1272b8SAndroid Build Coastguard Worker user_data = nullptr; 49*2d1272b8SAndroid Build Coastguard Worker destroy = nullptr; 50*2d1272b8SAndroid Build Coastguard Worker } 51*2d1272b8SAndroid Build Coastguard Worker } 52*2d1272b8SAndroid Build Coastguard Worker 53*2d1272b8SAndroid Build Coastguard Worker HB_INTERNAL bool try_make_writable (); 54*2d1272b8SAndroid Build Coastguard Worker HB_INTERNAL bool try_make_writable_inplace (); 55*2d1272b8SAndroid Build Coastguard Worker HB_INTERNAL bool try_make_writable_inplace_unix (); 56*2d1272b8SAndroid Build Coastguard Worker as_byteshb_blob_t57*2d1272b8SAndroid Build Coastguard Worker hb_bytes_t as_bytes () const { return hb_bytes_t (data, length); } 58*2d1272b8SAndroid Build Coastguard Worker template <typename Type> ashb_blob_t59*2d1272b8SAndroid Build Coastguard Worker const Type* as () const { return as_bytes ().as<Type> (); } 60*2d1272b8SAndroid Build Coastguard Worker 61*2d1272b8SAndroid Build Coastguard Worker public: 62*2d1272b8SAndroid Build Coastguard Worker hb_object_header_t header; 63*2d1272b8SAndroid Build Coastguard Worker 64*2d1272b8SAndroid Build Coastguard Worker const char *data = nullptr; 65*2d1272b8SAndroid Build Coastguard Worker unsigned int length = 0; 66*2d1272b8SAndroid Build Coastguard Worker hb_memory_mode_t mode = (hb_memory_mode_t) 0; 67*2d1272b8SAndroid Build Coastguard Worker 68*2d1272b8SAndroid Build Coastguard Worker void *user_data = nullptr; 69*2d1272b8SAndroid Build Coastguard Worker hb_destroy_func_t destroy = nullptr; 70*2d1272b8SAndroid Build Coastguard Worker }; 71*2d1272b8SAndroid Build Coastguard Worker 72*2d1272b8SAndroid Build Coastguard Worker 73*2d1272b8SAndroid Build Coastguard Worker /* 74*2d1272b8SAndroid Build Coastguard Worker * hb_blob_ptr_t 75*2d1272b8SAndroid Build Coastguard Worker */ 76*2d1272b8SAndroid Build Coastguard Worker 77*2d1272b8SAndroid Build Coastguard Worker template <typename P> 78*2d1272b8SAndroid Build Coastguard Worker struct hb_blob_ptr_t 79*2d1272b8SAndroid Build Coastguard Worker { 80*2d1272b8SAndroid Build Coastguard Worker typedef hb_remove_pointer<P> T; 81*2d1272b8SAndroid Build Coastguard Worker hb_blob_ptr_thb_blob_ptr_t82*2d1272b8SAndroid Build Coastguard Worker hb_blob_ptr_t (hb_blob_t *b_ = nullptr) : b (b_) {} operator =hb_blob_ptr_t83*2d1272b8SAndroid Build Coastguard Worker hb_blob_t * operator = (hb_blob_t *b_) { return b = b_; } operator ->hb_blob_ptr_t84*2d1272b8SAndroid Build Coastguard Worker const T * operator -> () const { return get (); } operator *hb_blob_ptr_t85*2d1272b8SAndroid Build Coastguard Worker const T & operator * () const { return *get (); } operator const C*hb_blob_ptr_t86*2d1272b8SAndroid Build Coastguard Worker template <typename C> operator const C * () const { return get (); } operator const char*hb_blob_ptr_t87*2d1272b8SAndroid Build Coastguard Worker operator const char * () const { return (const char *) get (); } gethb_blob_ptr_t88*2d1272b8SAndroid Build Coastguard Worker const T * get () const { return b->as<T> (); } get_blobhb_blob_ptr_t89*2d1272b8SAndroid Build Coastguard Worker hb_blob_t * get_blob () const { return b.get_raw (); } get_lengthhb_blob_ptr_t90*2d1272b8SAndroid Build Coastguard Worker unsigned int get_length () const { return b.get ()->length; } destroyhb_blob_ptr_t91*2d1272b8SAndroid Build Coastguard Worker void destroy () { hb_blob_destroy (b.get_raw ()); b = nullptr; } 92*2d1272b8SAndroid Build Coastguard Worker 93*2d1272b8SAndroid Build Coastguard Worker private: 94*2d1272b8SAndroid Build Coastguard Worker hb_nonnull_ptr_t<hb_blob_t> b; 95*2d1272b8SAndroid Build Coastguard Worker }; 96*2d1272b8SAndroid Build Coastguard Worker 97*2d1272b8SAndroid Build Coastguard Worker 98*2d1272b8SAndroid Build Coastguard Worker #endif /* HB_BLOB_HH */ 99