gfx/harfbuzz/src/hb-face.cc

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/gfx/harfbuzz/src/hb-face.cc	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,481 @@
     1.4 +/*
     1.5 + * Copyright © 2009  Red Hat, Inc.
     1.6 + * Copyright © 2012  Google, Inc.
     1.7 + *
     1.8 + *  This is part of HarfBuzz, a text shaping library.
     1.9 + *
    1.10 + * Permission is hereby granted, without written agreement and without
    1.11 + * license or royalty fees, to use, copy, modify, and distribute this
    1.12 + * software and its documentation for any purpose, provided that the
    1.13 + * above copyright notice and the following two paragraphs appear in
    1.14 + * all copies of this software.
    1.15 + *
    1.16 + * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
    1.17 + * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
    1.18 + * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
    1.19 + * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
    1.20 + * DAMAGE.
    1.21 + *
    1.22 + * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
    1.23 + * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
    1.24 + * FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
    1.25 + * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
    1.26 + * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
    1.27 + *
    1.28 + * Red Hat Author(s): Behdad Esfahbod
    1.29 + * Google Author(s): Behdad Esfahbod
    1.30 + */
    1.31 +
    1.32 +#include "hb-private.hh"
    1.33 +
    1.34 +#include "hb-ot-layout-private.hh"
    1.35 +
    1.36 +#include "hb-font-private.hh"
    1.37 +#include "hb-open-file-private.hh"
    1.38 +#include "hb-ot-head-table.hh"
    1.39 +#include "hb-ot-maxp-table.hh"
    1.40 +
    1.41 +#include "hb-cache-private.hh"
    1.42 +
    1.43 +#include <string.h>
    1.44 +
    1.45 +
    1.46 +/*
    1.47 + * hb_face_t
    1.48 + */
    1.49 +
    1.50 +const hb_face_t _hb_face_nil = {
    1.51 +  HB_OBJECT_HEADER_STATIC,
    1.52 +
    1.53 +  true, /* immutable */
    1.54 +
    1.55 +  NULL, /* reference_table_func */
    1.56 +  NULL, /* user_data */
    1.57 +  NULL, /* destroy */
    1.58 +
    1.59 +  0,    /* index */
    1.60 +  1000, /* upem */
    1.61 +  0,    /* num_glyphs */
    1.62 +
    1.63 +  {
    1.64 +#define HB_SHAPER_IMPLEMENT(shaper) HB_SHAPER_DATA_INVALID,
    1.65 +#include "hb-shaper-list.hh"
    1.66 +#undef HB_SHAPER_IMPLEMENT
    1.67 +  },
    1.68 +
    1.69 +  NULL, /* shape_plans */
    1.70 +};
    1.71 +
    1.72 +
    1.73 +/**
    1.74 + * hb_face_create_for_tables:
    1.75 + * @reference_table_func: (closure user_data) (destroy destroy) (scope notified):
    1.76 + * @user_data: 
    1.77 + * @destroy: 
    1.78 + *
    1.79 + * 
    1.80 + *
    1.81 + * Return value: (transfer full)
    1.82 + *
    1.83 + * Since: 1.0
    1.84 + **/
    1.85 +hb_face_t *
    1.86 +hb_face_create_for_tables (hb_reference_table_func_t  reference_table_func,
    1.87 +			   void                      *user_data,
    1.88 +			   hb_destroy_func_t          destroy)
    1.89 +{
    1.90 +  hb_face_t *face;
    1.91 +
    1.92 +  if (!reference_table_func || !(face = hb_object_create<hb_face_t> ())) {
    1.93 +    if (destroy)
    1.94 +      destroy (user_data);
    1.95 +    return hb_face_get_empty ();
    1.96 +  }
    1.97 +
    1.98 +  face->reference_table_func = reference_table_func;
    1.99 +  face->user_data = user_data;
   1.100 +  face->destroy = destroy;
   1.101 +
   1.102 +  face->upem = 0;
   1.103 +  face->num_glyphs = (unsigned int) -1;
   1.104 +
   1.105 +  return face;
   1.106 +}
   1.107 +
   1.108 +
   1.109 +typedef struct hb_face_for_data_closure_t {
   1.110 +  hb_blob_t *blob;
   1.111 +  unsigned int  index;
   1.112 +} hb_face_for_data_closure_t;
   1.113 +
   1.114 +static hb_face_for_data_closure_t *
   1.115 +_hb_face_for_data_closure_create (hb_blob_t *blob, unsigned int index)
   1.116 +{
   1.117 +  hb_face_for_data_closure_t *closure;
   1.118 +
   1.119 +  closure = (hb_face_for_data_closure_t *) malloc (sizeof (hb_face_for_data_closure_t));
   1.120 +  if (unlikely (!closure))
   1.121 +    return NULL;
   1.122 +
   1.123 +  closure->blob = blob;
   1.124 +  closure->index = index;
   1.125 +
   1.126 +  return closure;
   1.127 +}
   1.128 +
   1.129 +static void
   1.130 +_hb_face_for_data_closure_destroy (hb_face_for_data_closure_t *closure)
   1.131 +{
   1.132 +  hb_blob_destroy (closure->blob);
   1.133 +  free (closure);
   1.134 +}
   1.135 +
   1.136 +static hb_blob_t *
   1.137 +_hb_face_for_data_reference_table (hb_face_t *face HB_UNUSED, hb_tag_t tag, void *user_data)
   1.138 +{
   1.139 +  hb_face_for_data_closure_t *data = (hb_face_for_data_closure_t *) user_data;
   1.140 +
   1.141 +  if (tag == HB_TAG_NONE)
   1.142 +    return hb_blob_reference (data->blob);
   1.143 +
   1.144 +  const OT::OpenTypeFontFile &ot_file = *OT::Sanitizer<OT::OpenTypeFontFile>::lock_instance (data->blob);
   1.145 +  const OT::OpenTypeFontFace &ot_face = ot_file.get_face (data->index);
   1.146 +
   1.147 +  const OT::OpenTypeTable &table = ot_face.get_table_by_tag (tag);
   1.148 +
   1.149 +  hb_blob_t *blob = hb_blob_create_sub_blob (data->blob, table.offset, table.length);
   1.150 +
   1.151 +  return blob;
   1.152 +}
   1.153 +
   1.154 +/**
   1.155 + * hb_face_create: (Xconstructor)
   1.156 + * @blob: 
   1.157 + * @index: 
   1.158 + *
   1.159 + * 
   1.160 + *
   1.161 + * Return value: (transfer full):
   1.162 + *
   1.163 + * Since: 1.0
   1.164 + **/
   1.165 +hb_face_t *
   1.166 +hb_face_create (hb_blob_t    *blob,
   1.167 +		unsigned int  index)
   1.168 +{
   1.169 +  hb_face_t *face;
   1.170 +
   1.171 +  if (unlikely (!blob || !hb_blob_get_length (blob)))
   1.172 +    return hb_face_get_empty ();
   1.173 +
   1.174 +  hb_face_for_data_closure_t *closure = _hb_face_for_data_closure_create (OT::Sanitizer<OT::OpenTypeFontFile>::sanitize (hb_blob_reference (blob)), index);
   1.175 +
   1.176 +  if (unlikely (!closure))
   1.177 +    return hb_face_get_empty ();
   1.178 +
   1.179 +  face = hb_face_create_for_tables (_hb_face_for_data_reference_table,
   1.180 +				    closure,
   1.181 +				    (hb_destroy_func_t) _hb_face_for_data_closure_destroy);
   1.182 +
   1.183 +  hb_face_set_index (face, index);
   1.184 +
   1.185 +  return face;
   1.186 +}
   1.187 +
   1.188 +/**
   1.189 + * hb_face_get_empty:
   1.190 + *
   1.191 + * 
   1.192 + *
   1.193 + * Return value: (transfer full)
   1.194 + *
   1.195 + * Since: 1.0
   1.196 + **/
   1.197 +hb_face_t *
   1.198 +hb_face_get_empty (void)
   1.199 +{
   1.200 +  return const_cast<hb_face_t *> (&_hb_face_nil);
   1.201 +}
   1.202 +
   1.203 +
   1.204 +/**
   1.205 + * hb_face_reference: (skip)
   1.206 + * @face: a face.
   1.207 + *
   1.208 + * 
   1.209 + *
   1.210 + * Return value: 
   1.211 + *
   1.212 + * Since: 1.0
   1.213 + **/
   1.214 +hb_face_t *
   1.215 +hb_face_reference (hb_face_t *face)
   1.216 +{
   1.217 +  return hb_object_reference (face);
   1.218 +}
   1.219 +
   1.220 +/**
   1.221 + * hb_face_destroy: (skip)
   1.222 + * @face: a face.
   1.223 + *
   1.224 + * 
   1.225 + *
   1.226 + * Since: 1.0
   1.227 + **/
   1.228 +void
   1.229 +hb_face_destroy (hb_face_t *face)
   1.230 +{
   1.231 +  if (!hb_object_destroy (face)) return;
   1.232 +
   1.233 +  for (hb_face_t::plan_node_t *node = face->shape_plans; node; )
   1.234 +  {
   1.235 +    hb_face_t::plan_node_t *next = node->next;
   1.236 +    hb_shape_plan_destroy (node->shape_plan);
   1.237 +    free (node);
   1.238 +    node = next;
   1.239 +  }
   1.240 +
   1.241 +#define HB_SHAPER_IMPLEMENT(shaper) HB_SHAPER_DATA_DESTROY(shaper, face);
   1.242 +#include "hb-shaper-list.hh"
   1.243 +#undef HB_SHAPER_IMPLEMENT
   1.244 +
   1.245 +  if (face->destroy)
   1.246 +    face->destroy (face->user_data);
   1.247 +
   1.248 +  free (face);
   1.249 +}
   1.250 +
   1.251 +/**
   1.252 + * hb_face_set_user_data: (skip)
   1.253 + * @face: a face.
   1.254 + * @key: 
   1.255 + * @data: 
   1.256 + * @destroy: 
   1.257 + * @replace: 
   1.258 + *
   1.259 + * 
   1.260 + *
   1.261 + * Return value: 
   1.262 + *
   1.263 + * Since: 1.0
   1.264 + **/
   1.265 +hb_bool_t
   1.266 +hb_face_set_user_data (hb_face_t          *face,
   1.267 +		       hb_user_data_key_t *key,
   1.268 +		       void *              data,
   1.269 +		       hb_destroy_func_t   destroy,
   1.270 +		       hb_bool_t           replace)
   1.271 +{
   1.272 +  return hb_object_set_user_data (face, key, data, destroy, replace);
   1.273 +}
   1.274 +
   1.275 +/**
   1.276 + * hb_face_get_user_data: (skip)
   1.277 + * @face: a face.
   1.278 + * @key: 
   1.279 + *
   1.280 + * 
   1.281 + *
   1.282 + * Return value: (transfer none):
   1.283 + *
   1.284 + * Since: 1.0
   1.285 + **/
   1.286 +void *
   1.287 +hb_face_get_user_data (hb_face_t          *face,
   1.288 +		       hb_user_data_key_t *key)
   1.289 +{
   1.290 +  return hb_object_get_user_data (face, key);
   1.291 +}
   1.292 +
   1.293 +/**
   1.294 + * hb_face_make_immutable:
   1.295 + * @face: a face.
   1.296 + *
   1.297 + * 
   1.298 + *
   1.299 + * Since: 1.0
   1.300 + **/
   1.301 +void
   1.302 +hb_face_make_immutable (hb_face_t *face)
   1.303 +{
   1.304 +  if (hb_object_is_inert (face))
   1.305 +    return;
   1.306 +
   1.307 +  face->immutable = true;
   1.308 +}
   1.309 +
   1.310 +/**
   1.311 + * hb_face_is_immutable:
   1.312 + * @face: a face.
   1.313 + *
   1.314 + * 
   1.315 + *
   1.316 + * Return value: 
   1.317 + *
   1.318 + * Since: 1.0
   1.319 + **/
   1.320 +hb_bool_t
   1.321 +hb_face_is_immutable (hb_face_t *face)
   1.322 +{
   1.323 +  return face->immutable;
   1.324 +}
   1.325 +
   1.326 +
   1.327 +/**
   1.328 + * hb_face_reference_table:
   1.329 + * @face: a face.
   1.330 + * @tag: 
   1.331 + *
   1.332 + * 
   1.333 + *
   1.334 + * Return value: (transfer full):
   1.335 + *
   1.336 + * Since: 1.0
   1.337 + **/
   1.338 +hb_blob_t *
   1.339 +hb_face_reference_table (hb_face_t *face,
   1.340 +			 hb_tag_t   tag)
   1.341 +{
   1.342 +  return face->reference_table (tag);
   1.343 +}
   1.344 +
   1.345 +/**
   1.346 + * hb_face_reference_blob:
   1.347 + * @face: a face.
   1.348 + *
   1.349 + * 
   1.350 + *
   1.351 + * Return value: (transfer full):
   1.352 + *
   1.353 + * Since: 1.0
   1.354 + **/
   1.355 +hb_blob_t *
   1.356 +hb_face_reference_blob (hb_face_t *face)
   1.357 +{
   1.358 +  return face->reference_table (HB_TAG_NONE);
   1.359 +}
   1.360 +
   1.361 +/**
   1.362 + * hb_face_set_index:
   1.363 + * @face: a face.
   1.364 + * @index: 
   1.365 + *
   1.366 + * 
   1.367 + *
   1.368 + * Since: 1.0
   1.369 + **/
   1.370 +void
   1.371 +hb_face_set_index (hb_face_t    *face,
   1.372 +		   unsigned int  index)
   1.373 +{
   1.374 +  if (hb_object_is_inert (face))
   1.375 +    return;
   1.376 +
   1.377 +  face->index = index;
   1.378 +}
   1.379 +
   1.380 +/**
   1.381 + * hb_face_get_index:
   1.382 + * @face: a face.
   1.383 + *
   1.384 + * 
   1.385 + *
   1.386 + * Return value: 
   1.387 + *
   1.388 + * Since: 1.0
   1.389 + **/
   1.390 +unsigned int
   1.391 +hb_face_get_index (hb_face_t    *face)
   1.392 +{
   1.393 +  return face->index;
   1.394 +}
   1.395 +
   1.396 +/**
   1.397 + * hb_face_set_upem:
   1.398 + * @face: a face.
   1.399 + * @upem: 
   1.400 + *
   1.401 + * 
   1.402 + *
   1.403 + * Since: 1.0
   1.404 + **/
   1.405 +void
   1.406 +hb_face_set_upem (hb_face_t    *face,
   1.407 +		  unsigned int  upem)
   1.408 +{
   1.409 +  if (hb_object_is_inert (face))
   1.410 +    return;
   1.411 +
   1.412 +  face->upem = upem;
   1.413 +}
   1.414 +
   1.415 +/**
   1.416 + * hb_face_get_upem:
   1.417 + * @face: a face.
   1.418 + *
   1.419 + * 
   1.420 + *
   1.421 + * Return value: 
   1.422 + *
   1.423 + * Since: 1.0
   1.424 + **/
   1.425 +unsigned int
   1.426 +hb_face_get_upem (hb_face_t *face)
   1.427 +{
   1.428 +  return face->get_upem ();
   1.429 +}
   1.430 +
   1.431 +void
   1.432 +hb_face_t::load_upem (void) const
   1.433 +{
   1.434 +  hb_blob_t *head_blob = OT::Sanitizer<OT::head>::sanitize (reference_table (HB_OT_TAG_head));
   1.435 +  const OT::head *head_table = OT::Sanitizer<OT::head>::lock_instance (head_blob);
   1.436 +  upem = head_table->get_upem ();
   1.437 +  hb_blob_destroy (head_blob);
   1.438 +}
   1.439 +
   1.440 +/**
   1.441 + * hb_face_set_glyph_count:
   1.442 + * @face: a face.
   1.443 + * @glyph_count: 
   1.444 + *
   1.445 + * 
   1.446 + *
   1.447 + * Since: 1.0
   1.448 + **/
   1.449 +void
   1.450 +hb_face_set_glyph_count (hb_face_t    *face,
   1.451 +			 unsigned int  glyph_count)
   1.452 +{
   1.453 +  if (hb_object_is_inert (face))
   1.454 +    return;
   1.455 +
   1.456 +  face->num_glyphs = glyph_count;
   1.457 +}
   1.458 +
   1.459 +/**
   1.460 + * hb_face_get_glyph_count:
   1.461 + * @face: a face.
   1.462 + *
   1.463 + * 
   1.464 + *
   1.465 + * Return value: 
   1.466 + *
   1.467 + * Since: 1.0
   1.468 + **/
   1.469 +unsigned int
   1.470 +hb_face_get_glyph_count (hb_face_t *face)
   1.471 +{
   1.472 +  return face->get_num_glyphs ();
   1.473 +}
   1.474 +
   1.475 +void
   1.476 +hb_face_t::load_num_glyphs (void) const
   1.477 +{
   1.478 +  hb_blob_t *maxp_blob = OT::Sanitizer<OT::maxp>::sanitize (reference_table (HB_OT_TAG_maxp));
   1.479 +  const OT::maxp *maxp_table = OT::Sanitizer<OT::maxp>::lock_instance (maxp_blob);
   1.480 +  num_glyphs = maxp_table->get_num_glyphs ();
   1.481 +  hb_blob_destroy (maxp_blob);
   1.482 +}
   1.483 +
   1.484 +

mercurial