1 /*
   2  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   3  *
   4  * This code is free software; you can redistribute it and/or modify it
   5  * under the terms of the GNU General Public License version 2 only, as
   6  * published by the Free Software Foundation.  Oracle designates this
   7  * particular file as subject to the "Classpath" exception as provided
   8  * by Oracle in the LICENSE file that accompanied this code.
   9  *
  10  * This code is distributed in the hope that it will be useful, but WITHOUT
  11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  13  * version 2 for more details (a copy is included in the LICENSE file that
  14  * accompanied this code).
  15  *
  16  * You should have received a copy of the GNU General Public License version
  17  * 2 along with this work; if not, write to the Free Software Foundation,
  18  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  19  *
  20  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  21  * or visit www.oracle.com if you need additional information or have any
  22  * questions.
  23  */
  24 
  25 // This file is available under and governed by the GNU General Public
  26 // License version 2 only, as published by the Free Software Foundation.
  27 // However, the following notice accompanied the original version of this
  28 // file:
  29 //
  30 /*
  31  * Copyright © 2009  Red Hat, Inc.
  32  *
  33  *  This is part of HarfBuzz, a text shaping library.
  34  *
  35  * Permission is hereby granted, without written agreement and without
  36  * license or royalty fees, to use, copy, modify, and distribute this
  37  * software and its documentation for any purpose, provided that the
  38  * above copyright notice and the following two paragraphs appear in
  39  * all copies of this software.
  40  *
  41  * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
  42  * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
  43  * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
  44  * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
  45  * DAMAGE.
  46  *
  47  * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
  48  * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  49  * FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
  50  * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
  51  * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
  52  *
  53  * Red Hat Author(s): Behdad Esfahbod
  54  */
  55 
  56 #ifndef HB_H_IN
  57 #error "Include <hb.h> instead."
  58 #endif
  59 
  60 #ifndef HB_BLOB_H
  61 #define HB_BLOB_H
  62 
  63 #include "hb-common.h"
  64 
  65 HB_BEGIN_DECLS
  66 
  67 
  68 /*
  69  * Note re various memory-modes:
  70  *
  71  * - In no case shall the HarfBuzz client modify memory
  72  *   that is passed to HarfBuzz in a blob.  If there is
  73  *   any such possibility, MODE_DUPLICATE should be used
  74  *   such that HarfBuzz makes a copy immediately,
  75  *
  76  * - Use MODE_READONLY otherse, unless you really really
  77  *   really know what you are doing,
  78  *
  79  * - MODE_WRITABLE is appropriate if you really made a
  80  *   copy of data solely for the purpose of passing to
  81  *   HarfBuzz and doing that just once (no reuse!),
  82  *
  83  * - If the font is mmap()ed, it's ok to use
  84  *   READONLY_MAY_MAKE_WRITABLE, however, using that mode
  85  *   correctly is very tricky.  Use MODE_READONLY instead.
  86  */
  87 typedef enum {
  88   HB_MEMORY_MODE_DUPLICATE,
  89   HB_MEMORY_MODE_READONLY,
  90   HB_MEMORY_MODE_WRITABLE,
  91   HB_MEMORY_MODE_READONLY_MAY_MAKE_WRITABLE
  92 } hb_memory_mode_t;
  93 
  94 typedef struct hb_blob_t hb_blob_t;
  95 
  96 hb_blob_t *
  97 hb_blob_create (const char        *data,
  98                 unsigned int       length,
  99                 hb_memory_mode_t   mode,
 100                 void              *user_data,
 101                 hb_destroy_func_t  destroy);
 102 
 103 /* Always creates with MEMORY_MODE_READONLY.
 104  * Even if the parent blob is writable, we don't
 105  * want the user of the sub-blob to be able to
 106  * modify the parent data as that data may be
 107  * shared among multiple sub-blobs.
 108  */
 109 hb_blob_t *
 110 hb_blob_create_sub_blob (hb_blob_t    *parent,
 111                          unsigned int  offset,
 112                          unsigned int  length);
 113 
 114 hb_blob_t *
 115 hb_blob_get_empty (void);
 116 
 117 hb_blob_t *
 118 hb_blob_reference (hb_blob_t *blob);
 119 
 120 void
 121 hb_blob_destroy (hb_blob_t *blob);
 122 
 123 hb_bool_t
 124 hb_blob_set_user_data (hb_blob_t          *blob,
 125                        hb_user_data_key_t *key,
 126                        void *              data,
 127                        hb_destroy_func_t   destroy,
 128                        hb_bool_t           replace);
 129 
 130 
 131 void *
 132 hb_blob_get_user_data (hb_blob_t          *blob,
 133                        hb_user_data_key_t *key);
 134 
 135 
 136 void
 137 hb_blob_make_immutable (hb_blob_t *blob);
 138 
 139 hb_bool_t
 140 hb_blob_is_immutable (hb_blob_t *blob);
 141 
 142 
 143 unsigned int
 144 hb_blob_get_length (hb_blob_t *blob);
 145 
 146 const char *
 147 hb_blob_get_data (hb_blob_t *blob, unsigned int *length);
 148 
 149 char *
 150 hb_blob_get_data_writable (hb_blob_t *blob, unsigned int *length);
 151 
 152 
 153 HB_END_DECLS
 154 
 155 #endif /* HB_BLOB_H */