Add hb_set_t
This commit is contained in:
parent
5b93e8d94f
commit
0b08adb353
2
TODO
2
TODO
|
@ -85,6 +85,8 @@ Tests to write:
|
||||||
|
|
||||||
- GObject, FreeType, etc
|
- GObject, FreeType, etc
|
||||||
|
|
||||||
|
- hb_set_t
|
||||||
|
|
||||||
|
|
||||||
Optimizations:
|
Optimizations:
|
||||||
=============
|
=============
|
||||||
|
|
|
@ -34,6 +34,8 @@ HBSOURCES = \
|
||||||
hb-ot-name-table.hh \
|
hb-ot-name-table.hh \
|
||||||
hb-ot-tag.cc \
|
hb-ot-tag.cc \
|
||||||
hb-private.hh \
|
hb-private.hh \
|
||||||
|
hb-set-private.hh \
|
||||||
|
hb-set.cc \
|
||||||
hb-shape.cc \
|
hb-shape.cc \
|
||||||
hb-tt-font.cc \
|
hb-tt-font.cc \
|
||||||
hb-unicode-private.hh \
|
hb-unicode-private.hh \
|
||||||
|
@ -46,6 +48,7 @@ HBHEADERS = \
|
||||||
hb-buffer.h \
|
hb-buffer.h \
|
||||||
hb-common.h \
|
hb-common.h \
|
||||||
hb-font.h \
|
hb-font.h \
|
||||||
|
hb-set.h \
|
||||||
hb-shape.h \
|
hb-shape.h \
|
||||||
hb-unicode.h \
|
hb-unicode.h \
|
||||||
hb-version.h \
|
hb-version.h \
|
||||||
|
|
|
@ -31,6 +31,7 @@
|
||||||
|
|
||||||
#include "hb-ot-layout-private.hh"
|
#include "hb-ot-layout-private.hh"
|
||||||
#include "hb-open-type-private.hh"
|
#include "hb-open-type-private.hh"
|
||||||
|
#include "hb-set-private.hh"
|
||||||
|
|
||||||
|
|
||||||
#define NO_CONTEXT ((unsigned int) 0x110000)
|
#define NO_CONTEXT ((unsigned int) 0x110000)
|
||||||
|
|
|
@ -95,51 +95,4 @@ _hb_ot_layout_destroy (hb_ot_layout_t *layout);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
struct _hb_set_t
|
|
||||||
{
|
|
||||||
void clear (void) {
|
|
||||||
memset (elts, 0, sizeof elts);
|
|
||||||
}
|
|
||||||
bool add (hb_codepoint_t g)
|
|
||||||
{
|
|
||||||
if (unlikely (g > MAX_G)) return false;
|
|
||||||
elt_t &e = elt (g);
|
|
||||||
elt_t m = mask (g);
|
|
||||||
bool ret = !!(e & m);
|
|
||||||
e |= m;
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
bool has (hb_codepoint_t g) const
|
|
||||||
{
|
|
||||||
if (unlikely (g > MAX_G)) return false;
|
|
||||||
return !!(elt (g) & mask (g));
|
|
||||||
}
|
|
||||||
bool intersects (hb_codepoint_t first,
|
|
||||||
hb_codepoint_t last) const
|
|
||||||
{
|
|
||||||
if (unlikely (first > MAX_G)) return false;
|
|
||||||
if (unlikely (last > MAX_G)) last = MAX_G;
|
|
||||||
unsigned int end = last + 1;
|
|
||||||
for (hb_codepoint_t i = first; i < end; i++)
|
|
||||||
if (has (i))
|
|
||||||
return true;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
typedef uint32_t elt_t;
|
|
||||||
static const unsigned int MAX_G = 65536 - 1;
|
|
||||||
static const unsigned int SHIFT = 5;
|
|
||||||
static const unsigned int BITS = (1 << SHIFT);
|
|
||||||
static const unsigned int MASK = BITS - 1;
|
|
||||||
|
|
||||||
elt_t &elt (hb_codepoint_t g) { return elts[g >> SHIFT]; }
|
|
||||||
elt_t elt (hb_codepoint_t g) const { return elts[g >> SHIFT]; }
|
|
||||||
elt_t mask (hb_codepoint_t g) const { return elt_t (1) << (g & MASK); }
|
|
||||||
|
|
||||||
elt_t elts[(MAX_G + 1 + (BITS - 1)) / BITS]; /* 8kb */
|
|
||||||
ASSERT_STATIC (sizeof (elt_t) * 8 == BITS);
|
|
||||||
ASSERT_STATIC (sizeof (elts) * 8 > MAX_G);
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif /* HB_OT_LAYOUT_PRIVATE_HH */
|
#endif /* HB_OT_LAYOUT_PRIVATE_HH */
|
||||||
|
|
|
@ -183,8 +183,6 @@ void
|
||||||
hb_ot_layout_substitute_finish (hb_buffer_t *buffer);
|
hb_ot_layout_substitute_finish (hb_buffer_t *buffer);
|
||||||
|
|
||||||
|
|
||||||
typedef struct _hb_set_t hb_set_t;
|
|
||||||
|
|
||||||
hb_bool_t
|
hb_bool_t
|
||||||
hb_ot_layout_substitute_closure_lookup (hb_face_t *face,
|
hb_ot_layout_substitute_closure_lookup (hb_face_t *face,
|
||||||
hb_set_t *glyphs,
|
hb_set_t *glyphs,
|
||||||
|
|
|
@ -0,0 +1,95 @@
|
||||||
|
/*
|
||||||
|
* Copyright © 2012 Google, Inc.
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*
|
||||||
|
* Google Author(s): Behdad Esfahbod
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef HB_SET_PRIVATE_HH
|
||||||
|
#define HB_SET_PRIVATE_HH
|
||||||
|
|
||||||
|
#include "hb-private.hh"
|
||||||
|
#include "hb-set.h"
|
||||||
|
#include "hb-object-private.hh"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
struct _hb_set_t
|
||||||
|
{
|
||||||
|
inline void clear (void) {
|
||||||
|
memset (elts, 0, sizeof elts);
|
||||||
|
}
|
||||||
|
inline bool add (hb_codepoint_t g)
|
||||||
|
{
|
||||||
|
if (unlikely (g > MAX_G)) return false;
|
||||||
|
elt_t &e = elt (g);
|
||||||
|
elt_t m = mask (g);
|
||||||
|
bool ret = !(e & m);
|
||||||
|
e |= m;
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
inline bool del (hb_codepoint_t g)
|
||||||
|
{
|
||||||
|
if (unlikely (g > MAX_G)) return false;
|
||||||
|
elt_t &e = elt (g);
|
||||||
|
elt_t m = mask (g);
|
||||||
|
bool ret = !!(e & m);
|
||||||
|
e &= ~m;
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
inline bool has (hb_codepoint_t g) const
|
||||||
|
{
|
||||||
|
if (unlikely (g > MAX_G)) return false;
|
||||||
|
return !!(elt (g) & mask (g));
|
||||||
|
}
|
||||||
|
inline bool intersects (hb_codepoint_t first,
|
||||||
|
hb_codepoint_t last) const
|
||||||
|
{
|
||||||
|
if (unlikely (first > MAX_G)) return false;
|
||||||
|
if (unlikely (last > MAX_G)) last = MAX_G;
|
||||||
|
unsigned int end = last + 1;
|
||||||
|
for (hb_codepoint_t i = first; i < end; i++)
|
||||||
|
if (has (i))
|
||||||
|
return true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
typedef uint32_t elt_t;
|
||||||
|
static const unsigned int MAX_G = 65536 - 1;
|
||||||
|
static const unsigned int SHIFT = 5;
|
||||||
|
static const unsigned int BITS = (1 << SHIFT);
|
||||||
|
static const unsigned int MASK = BITS - 1;
|
||||||
|
|
||||||
|
elt_t &elt (hb_codepoint_t g) { return elts[g >> SHIFT]; }
|
||||||
|
elt_t elt (hb_codepoint_t g) const { return elts[g >> SHIFT]; }
|
||||||
|
elt_t mask (hb_codepoint_t g) const { return elt_t (1) << (g & MASK); }
|
||||||
|
|
||||||
|
hb_object_header_t header;
|
||||||
|
elt_t elts[(MAX_G + 1 + (BITS - 1)) / BITS]; /* 8kb */
|
||||||
|
|
||||||
|
ASSERT_STATIC (sizeof (elt_t) * 8 == BITS);
|
||||||
|
ASSERT_STATIC (sizeof (elts) * 8 > MAX_G);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* HB_SET_PRIVATE_HH */
|
|
@ -0,0 +1,120 @@
|
||||||
|
/*
|
||||||
|
* Copyright © 2012 Google, Inc.
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*
|
||||||
|
* Google Author(s): Behdad Esfahbod
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "hb-set-private.hh"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
static hb_set_t _hb_set_nil = {
|
||||||
|
HB_OBJECT_HEADER_STATIC,
|
||||||
|
|
||||||
|
{0} /* elts */
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
hb_set_t *
|
||||||
|
hb_set_create ()
|
||||||
|
{
|
||||||
|
hb_set_t *set;
|
||||||
|
|
||||||
|
if (!(set = hb_object_create<hb_set_t> ()))
|
||||||
|
return &_hb_set_nil;
|
||||||
|
|
||||||
|
set->clear ();
|
||||||
|
|
||||||
|
return set;
|
||||||
|
}
|
||||||
|
|
||||||
|
hb_set_t *
|
||||||
|
hb_set_get_empty (void)
|
||||||
|
{
|
||||||
|
return &_hb_set_nil;
|
||||||
|
}
|
||||||
|
|
||||||
|
hb_set_t *
|
||||||
|
hb_set_reference (hb_set_t *set)
|
||||||
|
{
|
||||||
|
return hb_object_reference (set);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
hb_set_destroy (hb_set_t *set)
|
||||||
|
{
|
||||||
|
if (!hb_object_destroy (set)) return;
|
||||||
|
|
||||||
|
free (set);
|
||||||
|
}
|
||||||
|
|
||||||
|
hb_bool_t
|
||||||
|
hb_set_set_user_data (hb_set_t *set,
|
||||||
|
hb_user_data_key_t *key,
|
||||||
|
void * data,
|
||||||
|
hb_destroy_func_t destroy,
|
||||||
|
hb_bool_t replace)
|
||||||
|
{
|
||||||
|
return hb_object_set_user_data (set, key, data, destroy, replace);
|
||||||
|
}
|
||||||
|
|
||||||
|
void *
|
||||||
|
hb_set_get_user_data (hb_set_t *set,
|
||||||
|
hb_user_data_key_t *key)
|
||||||
|
{
|
||||||
|
return hb_object_get_user_data (set, key);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
hb_bool_t
|
||||||
|
hb_set_allocation_successful (hb_set_t *set)
|
||||||
|
{
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
hb_set_clear (hb_set_t *set)
|
||||||
|
{
|
||||||
|
set->clear ();
|
||||||
|
}
|
||||||
|
|
||||||
|
hb_bool_t
|
||||||
|
hb_set_has (hb_set_t *set,
|
||||||
|
hb_codepoint_t codepoint)
|
||||||
|
{
|
||||||
|
return set->has (codepoint);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
hb_set_add (hb_set_t *set,
|
||||||
|
hb_codepoint_t codepoint)
|
||||||
|
{
|
||||||
|
set->add (codepoint);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
hb_set_del (hb_set_t *set,
|
||||||
|
hb_codepoint_t codepoint)
|
||||||
|
{
|
||||||
|
set->del (codepoint);
|
||||||
|
}
|
|
@ -0,0 +1,91 @@
|
||||||
|
/*
|
||||||
|
* Copyright © 2012 Google, Inc.
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*
|
||||||
|
* Google Author(s): Behdad Esfahbod
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef HB_H_IN
|
||||||
|
#error "Include <hb.h> instead."
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef HB_SET_H
|
||||||
|
#define HB_SET_H
|
||||||
|
|
||||||
|
#include "hb-common.h"
|
||||||
|
|
||||||
|
HB_BEGIN_DECLS
|
||||||
|
|
||||||
|
|
||||||
|
typedef struct _hb_set_t hb_set_t;
|
||||||
|
|
||||||
|
|
||||||
|
hb_set_t *
|
||||||
|
hb_set_create (void);
|
||||||
|
|
||||||
|
hb_set_t *
|
||||||
|
hb_set_get_empty (void);
|
||||||
|
|
||||||
|
hb_set_t *
|
||||||
|
hb_set_reference (hb_set_t *set);
|
||||||
|
|
||||||
|
void
|
||||||
|
hb_set_destroy (hb_set_t *set);
|
||||||
|
|
||||||
|
hb_bool_t
|
||||||
|
hb_set_set_user_data (hb_set_t *set,
|
||||||
|
hb_user_data_key_t *key,
|
||||||
|
void * data,
|
||||||
|
hb_destroy_func_t destroy,
|
||||||
|
hb_bool_t replace);
|
||||||
|
|
||||||
|
void *
|
||||||
|
hb_set_get_user_data (hb_set_t *set,
|
||||||
|
hb_user_data_key_t *key);
|
||||||
|
|
||||||
|
|
||||||
|
/* Returns FALSE if allocation has failed before */
|
||||||
|
hb_bool_t
|
||||||
|
hb_set_allocation_successful (hb_set_t *set);
|
||||||
|
|
||||||
|
void
|
||||||
|
hb_set_clear (hb_set_t *set);
|
||||||
|
|
||||||
|
hb_bool_t
|
||||||
|
hb_set_has (hb_set_t *set,
|
||||||
|
hb_codepoint_t codepoint);
|
||||||
|
|
||||||
|
void
|
||||||
|
hb_set_add (hb_set_t *set,
|
||||||
|
hb_codepoint_t codepoint);
|
||||||
|
|
||||||
|
void
|
||||||
|
hb_set_del (hb_set_t *set,
|
||||||
|
hb_codepoint_t codepoint);
|
||||||
|
|
||||||
|
/* TODO: add union, intersect, subtract, equal, empty, min, max, iter, etc */
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
HB_END_DECLS
|
||||||
|
|
||||||
|
#endif /* HB_SET_H */
|
1
src/hb.h
1
src/hb.h
|
@ -32,6 +32,7 @@
|
||||||
#include "hb-buffer.h"
|
#include "hb-buffer.h"
|
||||||
#include "hb-common.h"
|
#include "hb-common.h"
|
||||||
#include "hb-font.h"
|
#include "hb-font.h"
|
||||||
|
#include "hb-set.h"
|
||||||
#include "hb-shape.h"
|
#include "hb-shape.h"
|
||||||
#include "hb-unicode.h"
|
#include "hb-unicode.h"
|
||||||
#include "hb-version.h"
|
#include "hb-version.h"
|
||||||
|
|
Loading…
Reference in New Issue