[gobject] Flesh out hb-gobject

Move it to new harfbuzz-gobject library.  Implement enums and
boxed types for object-types.  Still have to do boxed types for
value types.
This commit is contained in:
Behdad Esfahbod 2013-08-26 20:56:58 -04:00
parent 23027f7611
commit 71439a8c7a
11 changed files with 333 additions and 77 deletions

View File

@ -144,9 +144,16 @@ if $have_glib; then
fi
AM_CONDITIONAL(HAVE_GLIB, $have_glib)
AC_ARG_WITH(gobject,
[AS_HELP_STRING([--with-gobject=@<:@yes/no/auto@:>@],
[Use gobject @<:@default=auto@:>@])],,
[with_gobject=auto])
have_gobject=false
if $have_glib; then
PKG_CHECK_MODULES(GOBJECT, gobject-2.0 glib-2.0 >= 2.16, have_gobject=true, :)
if test "x$with_gobject" = "xyes" -o "x$with_gobject" = "xauto"; then
PKG_CHECK_MODULES(GOBJECT, gobject-2.0 glib-2.0, have_gobject=true, :)
fi
if test "x$with_gobject" = "xyes" -a "x$have_gobject" != "xtrue"; then
AC_MSG_ERROR([gobject support requested but gobject-2.0 / glib-2.0 not found])
fi
if $have_gobject; then
AC_DEFINE(HAVE_GOBJECT, 1, [Have gobject2 library])
@ -411,5 +418,6 @@ Test / platform shapers (not normally needed):
Other features:
Documentation: ${enable_gtk_doc}
GObject bindings: ${have_gobject}
Introspection: ${found_introspection}
])

View File

@ -21,7 +21,7 @@ DOC_MAIN_SGML_FILE=$(DOC_MODULE)-docs.xml
# gtk-doc will search all .c and .h files beneath these paths
# for inline comments documenting functions and macros.
# e.g. DOC_SOURCE_DIR=$(top_srcdir)/gtk $(top_srcdir)/gdk
DOC_SOURCE_DIR=$(top_srcdir)/src
DOC_SOURCE_DIR=$(top_srcdir)/src $(top_builddir)/src
# Extra options to pass to gtkdoc-scangobj. Not normally needed.
SCANGOBJ_OPTIONS=
@ -58,6 +58,11 @@ EXTRA_HFILES=$(top_builddir)/src/hb-version.h
# Header files or dirs to ignore when scanning. Use base file/dir names
# e.g. IGNORE_HFILES=gtkdebug.h gtkintl.h private_code
IGNORE_HFILES=`cd $(top_srcdir)/src; find . -path './hb-*/*.h' | sed 's@^.*/@@'`
if HAVE_GOBJECT
else
# XXX Prevent "make dist"
IGNORE_HFILES+=hb-gobject.h
endif
# Images to copy into HTML directory.
# e.g. HTML_IMAGES=$(top_srcdir)/gtk/stock-icons/stock_about_24.png
@ -83,7 +88,10 @@ expand_content_files=
# e.g. GTKDOC_CFLAGS=-I$(top_srcdir) -I$(top_builddir) $(GTK_DEBUG_FLAGS)
# e.g. GTKDOC_LIBS=$(top_builddir)/gtk/$(gtktargetlib)
GTKDOC_CFLAGS=
GTKDOC_LIBS=
GTKDOC_LIBS=$(top_builddir)/src/libharfbuzz.la
if HAVE_GOBJECT
GTKDOC_LIBS+=$(top_builddir)/src/libharfbuzz-gobject.la
endif
# This includes the standard gtk-doc make rules, copied by gtkdocize.
include $(top_srcdir)/gtk-doc.make

View File

@ -26,6 +26,7 @@
<xi:include href="xml/hb-shape.xml"/>
<xi:include href="xml/hb-version.xml"/>
<xi:include href="xml/hb-deprecated.xml"/>
<xi:include href="xml/hb-set.xml"/>
@ -44,6 +45,8 @@
<xi:include href="xml/hb-uniscribe.xml"/>
<xi:include href="xml/hb-coretext.xml"/>
<xi:include href="xml/hb-gobject.xml"/>
</chapter>
<chapter id="object-tree">
<title>Object Hierarchy</title>

View File

@ -102,7 +102,6 @@ hb_script_from_string
hb_script_get_horizontal_direction
hb_script_t
hb_script_to_iso15924_tag
HB_SCRIPT_CANADIAN_ABORIGINAL
hb_tag_from_string
hb_tag_t
hb_tag_to_string
@ -126,6 +125,13 @@ uint64_t
uint8_t
</SECTION>
<SECTION>
<FILE>hb-deprecated</FILE>
HB_BUFFER_FLAGS_DEFAULT
HB_BUFFER_SERIALIZE_FLAGS_DEFAULT
HB_SCRIPT_CANADIAN_ABORIGINAL
</SECTION>
<SECTION>
<FILE>hb-coretext</FILE>
hb_coretext_face_get_cg_font
@ -247,6 +253,46 @@ hb_glib_script_from_script
hb_glib_script_to_script
</SECTION>
<SECTION>
<FILE>hb-gobject</FILE>
HB_GOBJECT_TYPE_BLOB
HB_GOBJECT_TYPE_BUFFER
HB_GOBJECT_TYPE_BUFFER_CONTENT_TYPE
HB_GOBJECT_TYPE_BUFFER_FLAGS
HB_GOBJECT_TYPE_BUFFER_SERIALIZE_FLAGS
HB_GOBJECT_TYPE_BUFFER_SERIALIZE_FORMAT
HB_GOBJECT_TYPE_DIRECTION
HB_GOBJECT_TYPE_FACE
HB_GOBJECT_TYPE_FONT
HB_GOBJECT_TYPE_FONT_FUNCS
HB_GOBJECT_TYPE_MEMORY_MODE
HB_GOBJECT_TYPE_OT_LAYOUT_GLYPH_CLASS
HB_GOBJECT_TYPE_SCRIPT
HB_GOBJECT_TYPE_SHAPE_PLAN
HB_GOBJECT_TYPE_UNICODE_COMBINING_CLASS
HB_GOBJECT_TYPE_UNICODE_FUNCS
HB_GOBJECT_TYPE_UNICODE_GENERAL_CATEGORY
hb_gobject_blob_get_type
hb_gobject_buffer_content_type_get_type
hb_gobject_buffer_flags_get_type
hb_gobject_buffer_get_type
hb_gobject_buffer_serialize_flags_get_type
hb_gobject_buffer_serialize_format_get_type
hb_gobject_direction_get_type
hb_gobject_face_get_type
hb_gobject_font_funcs_get_type
hb_gobject_font_get_type
hb_gobject_memory_mode_get_type
hb_gobject_ot_layout_glyph_class_get_type
hb_gobject_script_get_type
hb_gobject_shape_plan_get_type
hb_gobject_unicode_combining_class_get_type
hb_gobject_unicode_funcs_get_type
hb_gobject_unicode_general_category_get_type
<SUBSECTION Private>
HB_GOBJECT_H_IN
</SECTION>
<SECTION>
<FILE>hb-gobject</FILE>

View File

@ -126,21 +126,6 @@ HBSOURCES += hb-glib.cc
HBHEADERS += hb-glib.h
endif
if HAVE_GOBJECT
HBCFLAGS += $(GOBJECT_CFLAGS)
HBLIBS += $(GOBJECT_LIBS)
HBSOURCES += hb-gobject-structs.cc
nodist_HBSOURCES = hb-gobject-enums.cc
HBHEADERS += hb-gobject.h
BUILT_SOURCES += hb-gobject-enums.cc
EXTRA_DIST += hb-gobject-enums.cc.tmpl
DISTCLEANFILES += hb-gobject-enums.cc
hb-gobject-enums.cc: hb-gobject-enums.cc.tmpl $(HBHEADERS)
$(AM_V_GEN) $(GLIB_MKENUMS) --template $^ > "$@.tmp" && \
mv "$@.tmp" "$@" || ( $(RM) "@.tmp" && false )
endif
if HAVE_FREETYPE
HBCFLAGS += $(FREETYPE_CFLAGS)
HBLIBS += $(FREETYPE_LIBS)
@ -236,6 +221,39 @@ pkgconfig_DATA += harfbuzz-icu.pc
EXTRA_DIST += harfbuzz-icu.pc.in
endif
if HAVE_GOBJECT
lib_LTLIBRARIES += libharfbuzz-gobject.la
libharfbuzz_gobject_la_SOURCES = hb-gobject-structs.cc
nodist_libharfbuzz_gobject_la_SOURCES = hb-gobject-enums.cc
libharfbuzz_gobject_la_CPPFLAGS = $(GOBJECT_CFLAGS)
libharfbuzz_gobject_la_LDFLAGS = $(AM_LDFLAGS) -version-info $(HB_LIBTOOL_VERSION_INFO) -no-undefined
libharfbuzz_gobject_la_LIBADD = $(GOBJECT_LIBS) libharfbuzz.la
pkginclude_HEADERS += hb-gobject.h hb-gobject-structs.h
nodist_pkginclude_HEADERS += hb-gobject-enums.h
pkgconfig_DATA += harfbuzz-gobject.pc
EXTRA_DIST += harfbuzz-gobject.pc.in
BUILT_SOURCES += \
hb-gobject-enums.cc \
hb-gobject-enums.h \
$(NULL)
EXTRA_DIST += \
hb-gobject-enums.cc.tmpl \
hb-gobject-enums.h.tmpl \
$(NULL)
DISTCLEANFILES += \
hb-gobject-enums.cc \
hb-gobject-enums.h \
$(NULL)
hb-gobject-enums.%: hb-gobject-enums.%.tmpl $(HBHEADERS)
$(AM_V_GEN) $(GLIB_MKENUMS) \
--identifier-prefix hb_ --symbol-prefix hb_gobject \
--template $^ | \
sed 's/_t_get_type/_get_type/g; s/_T (/ (/g' > "$@.tmp" && \
mv "$@.tmp" "$@" || ( $(RM) "@.tmp" && false )
endif
%.pc: %.pc.in $(top_builddir)/config.status
$(AM_V_GEN) \
$(SED) -e 's@%prefix%@$(prefix)@g' \

View File

@ -0,0 +1,12 @@
prefix=%prefix%
exec_prefix=%exec_prefix%
libdir=%libdir%
includedir=%includedir%
Name: harfbuzz
Description: HarfBuzz text shaping library GObject integration
Version: %VERSION%
Requires: harfbuzz gobject-2.0 glib-2.0
Libs: -L${libdir} -lharfbuzz-gobject
Cflags: -I${includedir}/harfbuzz

View File

@ -45,13 +45,12 @@
/*** END file-production ***/
/*** BEGIN value-header ***/
inline static /* TODO(behdad) disable these for now until we fix them... */
GType
@enum_name@_get_type (void)
{
static volatile gsize g_define_type_id__volatile = 0;
static gsize type_id = 0;
if (g_once_init_enter (&g_define_type_id__volatile))
if (g_once_init_enter (&type_id))
{
static const G@Type@Value values[] = {
/*** END value-header ***/
@ -63,12 +62,12 @@ GType
/*** BEGIN value-tail ***/
{ 0, NULL, NULL }
};
GType g_define_type_id =
GType id =
g_@type@_register_static (g_intern_static_string ("@EnumName@"), values);
g_once_init_leave (&g_define_type_id__volatile, g_define_type_id);
g_once_init_leave (&type_id, id);
}
return g_define_type_id__volatile;
return type_id;
}
/*** END value-tail ***/

View File

@ -0,0 +1,55 @@
/*** BEGIN file-header ***/
/*
* Copyright © 2013 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_GOBJECT_H_IN
#error "Include <hb-gobject.h> instead."
#endif
#ifndef HB_GOBJECT_ENUMS_H
#define HB_GOBJECT_ENUMS_H
#include "hb.h"
#include <glib-object.h>
HB_BEGIN_DECLS
/*** END file-header ***/
/*** BEGIN value-header ***/
GType @enum_name@_get_type (void) G_GNUC_CONST;
#define @ENUMPREFIX@_TYPE_@ENUMSHORT@ (@enum_name@_get_type ())
/*** END value-header ***/
/*** BEGIN file-tail ***/
HB_END_DECLS
#endif /* HB_GOBJECT_ENUMS_H */
/*** END file-tail ***/

View File

@ -37,27 +37,77 @@
#include "hb-gobject.h"
#define _HB_DEFINE_BOXED_TYPE(Name,underscore_name,copy_func,free_func) \
#define HB_DEFINE_BOXED_TYPE(name,copy_func,free_func) \
GType \
underscore_name##_get_type (void) \
hb_gobject_##name##_get_type (void) \
{ \
static volatile gsize type = 0; \
if (g_once_init_enter (&type)) { \
GType t = g_boxed_type_register_static (g_intern_static_string (#Name), \
static gsize type_id = 0; \
if (g_once_init_enter (&type_id)) { \
GType id = g_boxed_type_register_static (g_intern_static_string ("hb_" #name "_t"), \
(GBoxedCopyFunc) copy_func, \
(GBoxedFreeFunc) free_func); \
g_once_init_leave (&type, t); \
g_once_init_leave (&type_id, id); \
} \
return type; \
return type_id; \
}
#define HB_DEFINE_BOXED_TYPE(name) \
_HB_DEFINE_BOXED_TYPE (hb_##name, hb_gobject_##name, hb_##name##_reference, hb_##name##_destroy);
#define HB_DEFINE_OBJECT_TYPE(name) \
HB_DEFINE_BOXED_TYPE (name, hb_##name##_reference, hb_##name##_destroy);
HB_DEFINE_BOXED_TYPE (buffer)
HB_DEFINE_BOXED_TYPE (blob)
HB_DEFINE_BOXED_TYPE (face)
HB_DEFINE_BOXED_TYPE (font)
HB_DEFINE_BOXED_TYPE (font_funcs)
HB_DEFINE_BOXED_TYPE (unicode_funcs)
HB_DEFINE_OBJECT_TYPE (buffer)
HB_DEFINE_OBJECT_TYPE (blob)
HB_DEFINE_OBJECT_TYPE (face)
HB_DEFINE_OBJECT_TYPE (font)
HB_DEFINE_OBJECT_TYPE (font_funcs)
HB_DEFINE_OBJECT_TYPE (set)
HB_DEFINE_OBJECT_TYPE (shape_plan)
HB_DEFINE_OBJECT_TYPE (unicode_funcs)
static hb_feature_t *feature_reference (hb_feature_t *g)
{
hb_feature_t *c = (hb_feature_t *) calloc (1, sizeof (hb_feature_t));
if (unlikely (!c)) return NULL;
*c = *g;
return c;
}
static void feature_destroy (hb_feature_t *g) { free (g); }
HB_DEFINE_BOXED_TYPE (feature, feature_reference, feature_destroy)
static hb_glyph_info_t *glyph_info_reference (hb_glyph_info_t *g)
{
hb_glyph_info_t *c = (hb_glyph_info_t *) calloc (1, sizeof (hb_glyph_info_t));
if (unlikely (!c)) return NULL;
*c = *g;
return c;
}
static void glyph_info_destroy (hb_glyph_info_t *g) { free (g); }
HB_DEFINE_BOXED_TYPE (glyph_info, glyph_info_reference, glyph_info_destroy)
static hb_glyph_position_t *glyph_position_reference (hb_glyph_position_t *g)
{
hb_glyph_position_t *c = (hb_glyph_position_t *) calloc (1, sizeof (hb_glyph_position_t));
if (unlikely (!c)) return NULL;
*c = *g;
return c;
}
static void glyph_position_destroy (hb_glyph_position_t *g) { free (g); }
HB_DEFINE_BOXED_TYPE (glyph_position, glyph_position_reference, glyph_position_destroy)
static hb_language_t language_reference (hb_language_t l) { return l; }
static void language_destroy (hb_language_t l) { }
HB_DEFINE_BOXED_TYPE (language, language_reference, language_destroy)
static hb_segment_properties_t *segment_properties_reference (hb_segment_properties_t *g)
{
hb_segment_properties_t *c = (hb_segment_properties_t *) calloc (1, sizeof (hb_segment_properties_t));
if (unlikely (!c)) return NULL;
*c = *g;
return c;
}
static void segment_properties_destroy (hb_segment_properties_t *g) { free (g); }
HB_DEFINE_BOXED_TYPE (segment_properties, segment_properties_reference, segment_properties_destroy)
static hb_user_data_key_t user_data_key_reference (hb_user_data_key_t l) { return l; }
static void user_data_key_destroy (hb_user_data_key_t l) { }
HB_DEFINE_BOXED_TYPE (user_data_key, user_data_key_reference, user_data_key_destroy)

87
src/hb-gobject-structs.h Normal file
View File

@ -0,0 +1,87 @@
/*
* Copyright © 2011 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_GOBJECT_H_IN
#error "Include <hb-gobject.h> instead."
#endif
#ifndef HB_GOBJECT_STRUCTS_H
#define HB_GOBJECT_STRUCTS_H
#include "hb.h"
#include <glib-object.h>
HB_BEGIN_DECLS
/* Object types */
GType hb_gobject_blob_get_type (void);
#define HB_GOBJECT_TYPE_BLOB (hb_gobject_blob_get_type ())
GType hb_gobject_buffer_get_type (void);
#define HB_GOBJECT_TYPE_BUFFER (hb_gobject_buffer_get_type ())
GType hb_gobject_face_get_type (void);
#define HB_GOBJECT_TYPE_FACE (hb_gobject_face_get_type ())
GType hb_gobject_font_get_type (void);
#define HB_GOBJECT_TYPE_FONT (hb_gobject_font_get_type ())
GType hb_gobject_font_funcs_get_type (void);
#define HB_GOBJECT_TYPE_FONT_FUNCS (hb_gobject_font_funcs_get_type ())
GType hb_gobject_set_get_type (void);
#define HB_GOBJECT_TYPE_SET (hb_gobject_set_get_type ())
GType hb_gobject_shape_plan_get_type (void);
#define HB_GOBJECT_TYPE_SHAPE_PLAN (hb_gobject_shape_plan_get_type ())
GType hb_gobject_unicode_funcs_get_type (void);
#define HB_GOBJECT_TYPE_UNICODE_FUNCS (hb_gobject_unicode_funcs_get_type ())
/* Value types */
GType hb_gobject_feature_get_type (void);
#define HB_GOBJECT_TYPE_FEATURE (hb_gobject_feature_get_type ())
GType hb_gobject_glyph_info_get_type (void);
#define HB_GOBJECT_TYPE_GLYPH_INFO (hb_gobject_glyph_info_get_type ())
GType hb_gobject_glyph_position_get_type (void);
#define HB_GOBJECT_TYPE_GLYPH_POSITION (hb_gobject_glyph_position_get_type ())
GType hb_gobject_segment_properties_get_type (void);
#define HB_GOBJECT_TYPE_SEGMENT_PROPERTIES (hb_gobject_segment_properties_get_type ())
GType hb_gobject_user_data_key_get_type (void);
#define HB_GOBJECT_TYPE_USER_DATA_KEY (hb_gobject_user_data_key_get_type ())
HB_END_DECLS
#endif /* HB_GOBJECT_H */

View File

@ -26,45 +26,15 @@
#ifndef HB_GOBJECT_H
#define HB_GOBJECT_H
#define HB_GOBJECT_H_IN
#include "hb.h"
#include <glib-object.h>
#include "hb-gobject-enums.h"
#include "hb-gobject-structs.h"
HB_BEGIN_DECLS
#ifndef __GTK_DOC_IGNORE__
/* Objects */
#define HB_GOBJECT_TYPE_BLOB hb_gobject_blob_get_type ()
GType
hb_gobject_blob_get_type (void);
#define HB_GOBJECT_TYPE_BUFFER hb_gobject_buffer_get_type ()
GType
hb_gobject_buffer_get_type (void);
#define HB_GOBJECT_TYPE_FACE hb_gobject_face_get_type ()
GType
hb_gobject_face_get_type (void);
#define HB_GOBJECT_TYPE_FONT hb_gobject_font_get_type ()
GType
hb_gobject_font_get_type (void);
#define HB_GOBJECT_TYPE_FONT_FUNCS hb_gobject_font_funcs_get_type ()
GType
hb_gobject_font_funcs_get_type (void);
#define HB_GOBJECT_TYPE_UNICODE_FUNCS hb_gobject_unicode_funcs_get_type ()
GType
hb_gobject_unicode_funcs_get_type (void);
#endif /* __GTK_DOC_IGNORE__ */
/* Enums */
HB_END_DECLS
#undef HB_GOBJECT_H_IN
#endif /* HB_GOBJECT_H */