src/Makefile.am | 5 src/check-c-linkage-decls.sh | 18 ++ src/check-header-guards.sh | 2 src/hb-blob-private.h | 2 src/hb-blob.c | 18 +- src/hb-blob.h | 2 src/hb-buffer-private.hh | 1 src/hb-buffer.cc | 7 src/hb-buffer.h | 1 src/hb-common.c | 6 src/hb-common.h | 21 +- src/hb-font-private.h | 96 ++++++++++++ src/hb-font-private.hh | 97 ------------- src/hb-font.cc | 6 src/hb-font.h | 1 src/hb-ft.c | 246 ++++++++++++++++++++++++++++++++ src/hb-ft.cc | 240 -------------------------------- src/hb-ft.h | 2 src/hb-glib.c | 6 src/hb-glib.h | 2 src/hb-graphite.cc | 8 - src/hb-graphite.h | 3 src/hb-icu.c | 6 src/hb-icu.h | 2 src/hb-language.c | 5 src/hb-language.h | 2 src/hb-object-private.h | 2 src/hb-open-file-private.hh | 4 src/hb-open-type-private.hh | 5 src/hb-ot-head-private.hh | 261 +++++++++++++++++------------------ src/hb-ot-layout-common-private.hh | 6 src/hb-ot-layout-gdef-private.hh | 6 src/hb-ot-layout-gpos-private.hh | 6 src/hb-ot-layout-gsub-private.hh | 7 src/hb-ot-layout-gsubgpos-private.hh | 13 + src/hb-ot-layout-private.hh | 6 src/hb-ot-layout.cc | 5 src/hb-ot-layout.h | 1 src/hb-ot-shape.cc | 6 src/hb-ot-shape.h | 2 src/hb-ot-tag.c | 5 src/hb-ot-tag.h | 2 src/hb-ot.h | 3 src/hb-private.h | 5 src/hb-shape.cc | 5 src/hb-shape.h | 1 src/hb-unicode-private.h | 1 src/hb-unicode.c | 6 src/hb-unicode.h | 1 src/hb.h | 3 src/main.cc | 6 51 files changed, 683 insertions(+), 490 deletions(-)
New commits: commit acdba3f90b232fc12fcb200dca2584481b339118 Author: Behdad Esfahbod <[email protected]> Date: Fri Jul 23 15:11:18 2010 -0400 Prefer C linkage diff --git a/src/Makefile.am b/src/Makefile.am index a8ba69c..409c939 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -113,6 +113,7 @@ main_CPPFLAGS = $(HBCFLAGS) main_LDADD = libharfbuzz.la $(HBLIBS) TESTS = \ + check-c-linkage-decls.sh \ check-header-guards.sh \ check-internal-symbols.sh \ $(NULL) diff --git a/src/check-c-linkage-decls.sh b/src/check-c-linkage-decls.sh new file mode 100755 index 0000000..c262516 --- /dev/null +++ b/src/check-c-linkage-decls.sh @@ -0,0 +1,18 @@ +#!/bin/sh + +LC_ALL=C +export LC_ALL + +test -z "$srcdir" && srcdir=. +stat=0 + +cd "$srcdir" + +for x in *.c *.cc *.h *.hh ; do + if ! grep -q HB_BEGIN_DECLS "$x" || ! grep -q HB_END_DECLS "$x"; then + echo "Ouch, file $x does not HB_BEGIN_DECLS / HB_END_DECLS" + stat=1 + fi +done + +exit $stat diff --git a/src/hb-blob-private.h b/src/hb-blob-private.h index c91af65..92109ed 100644 --- a/src/hb-blob-private.h +++ b/src/hb-blob-private.h @@ -33,6 +33,7 @@ HB_BEGIN_DECLS + struct _hb_blob_t { hb_reference_count_t ref_count; @@ -52,6 +53,7 @@ struct _hb_blob_t { extern HB_INTERNAL hb_blob_t _hb_blob_nil; + HB_END_DECLS #endif /* HB_BLOB_PRIVATE_H */ diff --git a/src/hb-blob.c b/src/hb-blob.c index 0357fb4..926481d 100644 --- a/src/hb-blob.c +++ b/src/hb-blob.c @@ -35,13 +35,16 @@ #include <sys/mman.h> #endif /* HAVE_SYS_MMAN_H */ +#include <stdio.h> +#include <errno.h> + +HB_BEGIN_DECLS + + #ifndef HB_DEBUG_BLOB #define HB_DEBUG_BLOB HB_DEBUG+0 #endif -#include <stdio.h> -#include <errno.h> - hb_blob_t _hb_blob_nil = { HB_REFERENCE_COUNT_INVALID, /* ref_count */ @@ -273,7 +276,7 @@ _try_make_writable_inplace_unix_locked (hb_blob_t *blob) } static void -_try_writable_inplace_locked (hb_blob_t *blob) +try_writable_inplace_locked (hb_blob_t *blob) { if (HB_DEBUG_BLOB) fprintf (stderr, "%p %s: making writable\n", blob, __FUNCTION__); @@ -301,7 +304,7 @@ hb_blob_try_writable_inplace (hb_blob_t *blob) hb_mutex_lock (blob->lock); if (blob->mode == HB_MEMORY_MODE_READONLY_MAY_MAKE_WRITABLE) - _try_writable_inplace_locked (blob); + try_writable_inplace_locked (blob); mode = blob->mode; @@ -321,7 +324,7 @@ hb_blob_try_writable (hb_blob_t *blob) hb_mutex_lock (blob->lock); if (blob->mode == HB_MEMORY_MODE_READONLY_MAY_MAKE_WRITABLE) - _try_writable_inplace_locked (blob); + try_writable_inplace_locked (blob); if (blob->mode == HB_MEMORY_MODE_READONLY) { @@ -354,3 +357,6 @@ done: return mode == HB_MEMORY_MODE_WRITABLE; } + + +HB_END_DECLS diff --git a/src/hb-blob.h b/src/hb-blob.h index d13bb0d..dbbfc90 100644 --- a/src/hb-blob.h +++ b/src/hb-blob.h @@ -31,6 +31,7 @@ HB_BEGIN_DECLS + typedef enum { HB_MEMORY_MODE_DUPLICATE, HB_MEMORY_MODE_READONLY, @@ -82,6 +83,7 @@ hb_blob_try_writable_inplace (hb_blob_t *blob); hb_bool_t hb_blob_try_writable (hb_blob_t *blob); + HB_END_DECLS #endif /* HB_BLOB_H */ diff --git a/src/hb-buffer-private.hh b/src/hb-buffer-private.hh index cfc781c..b48ef1d 100644 --- a/src/hb-buffer-private.hh +++ b/src/hb-buffer-private.hh @@ -34,6 +34,7 @@ HB_BEGIN_DECLS + #define HB_BUFFER_GLYPH_PROPERTIES_UNKNOWN 0xFFFF diff --git a/src/hb-buffer.cc b/src/hb-buffer.cc index b04466a..ff39330 100644 --- a/src/hb-buffer.cc +++ b/src/hb-buffer.cc @@ -29,6 +29,8 @@ #include <string.h> +HB_BEGIN_DECLS + static hb_buffer_t _hb_buffer_nil = { HB_REFERENCE_COUNT_INVALID, /* ref_count */ @@ -96,7 +98,7 @@ _hb_buffer_ensure (hb_buffer_t *buffer, unsigned int size) return likely (size <= buffer->allocated) ? TRUE : _hb_buffer_enlarge (buffer, size); } -static hb_bool_t +static inline hb_bool_t _hb_buffer_ensure_separate (hb_buffer_t *buffer, unsigned int size) { if (unlikely (!_hb_buffer_ensure (buffer, size))) return FALSE; @@ -692,3 +694,6 @@ hb_buffer_add_utf32 (hb_buffer_t *buffer, ADD_UTF (uint32_t); #undef UTF_NEXT } + + +HB_END_DECLS diff --git a/src/hb-buffer.h b/src/hb-buffer.h index 7b8b7ea..e6d477d 100644 --- a/src/hb-buffer.h +++ b/src/hb-buffer.h @@ -34,6 +34,7 @@ HB_BEGIN_DECLS + typedef struct _hb_buffer_t hb_buffer_t; typedef struct _hb_glyph_info_t { diff --git a/src/hb-common.c b/src/hb-common.c index d205fc8..74f8933 100644 --- a/src/hb-common.c +++ b/src/hb-common.c @@ -26,6 +26,9 @@ #include "hb-private.h" +HB_BEGIN_DECLS + + hb_tag_t hb_tag_from_string (const char *s) { @@ -39,3 +42,6 @@ hb_tag_from_string (const char *s) return HB_TAG_STR (tag); } + + +HB_END_DECLS diff --git a/src/hb-common.h b/src/hb-common.h index 74d8512..85906c5 100644 --- a/src/hb-common.h +++ b/src/hb-common.h @@ -27,6 +27,17 @@ #ifndef HB_COMMON_H #define HB_COMMON_H +# ifdef __cplusplus +# define HB_BEGIN_DECLS extern "C" { +# define HB_END_DECLS } +# else /* !__cplusplus */ +# define HB_BEGIN_DECLS +# define HB_END_DECLS +# endif /* !__cplusplus */ + +HB_BEGIN_DECLS + + #ifdef _MSC_VER #define _HB__STR2__(x) #x #define _HB__STR1__(x) _HB__STR2__(x) @@ -47,14 +58,6 @@ typedef unsigned long long uint64_t; #include <stdint.h> #endif -# ifdef __cplusplus -# define HB_BEGIN_DECLS extern "C" { -# define HB_END_DECLS } -# else /* !__cplusplus */ -# define HB_BEGIN_DECLS -# define HB_END_DECLS -# endif /* !__cplusplus */ - typedef int hb_bool_t; typedef uint32_t hb_tag_t; @@ -88,4 +91,6 @@ typedef enum _hb_direction_t { #define HB_DIRECTION_REVERSE(dir) ((hb_direction_t) (((unsigned int) (dir)) ^ 1)) +HB_END_DECLS + #endif /* HB_COMMON_H */ diff --git a/src/hb-font-private.h b/src/hb-font-private.h index 7f54cbd..f91da83 100644 --- a/src/hb-font-private.h +++ b/src/hb-font-private.h @@ -33,6 +33,7 @@ HB_BEGIN_DECLS + /* * hb_font_funcs_t */ diff --git a/src/hb-font.cc b/src/hb-font.cc index 8c4a608..a1535f1 100644 --- a/src/hb-font.cc +++ b/src/hb-font.cc @@ -34,6 +34,8 @@ #include <string.h> +HB_BEGIN_DECLS + /* * hb_font_funcs_t @@ -467,3 +469,5 @@ hb_font_set_ppem (hb_font_t *font, font->y_ppem = y_ppem; } + +HB_END_DECLS diff --git a/src/hb-font.h b/src/hb-font.h index 89324fa..19247ef 100644 --- a/src/hb-font.h +++ b/src/hb-font.h @@ -32,6 +32,7 @@ HB_BEGIN_DECLS + typedef struct _hb_face_t hb_face_t; typedef struct _hb_font_t hb_font_t; diff --git a/src/hb-ft.c b/src/hb-ft.c index bdf2936..8619456 100644 --- a/src/hb-ft.c +++ b/src/hb-ft.c @@ -33,6 +33,9 @@ #include FT_TRUETYPE_TABLES_H +HB_BEGIN_DECLS + + static hb_codepoint_t hb_ft_get_glyph (hb_font_t *font HB_UNUSED, hb_face_t *face HB_UNUSED, @@ -145,7 +148,7 @@ hb_ft_get_font_funcs (void) static hb_blob_t * -_get_table (hb_tag_t tag, void *user_data) +get_table (hb_tag_t tag, void *user_data) { FT_Face ft_face = (FT_Face) user_data; FT_Byte *buffer; @@ -191,7 +194,7 @@ hb_ft_face_create (FT_Face ft_face, face = hb_face_create_for_data (blob, ft_face->face_index); hb_blob_destroy (blob); } else { - face = hb_face_create_for_tables (_get_table, destroy, ft_face); + face = hb_face_create_for_tables (get_table, destroy, ft_face); } return face; @@ -238,3 +241,6 @@ hb_ft_font_create (FT_Face ft_face, return font; } + + +HB_END_DECLS diff --git a/src/hb-ft.h b/src/hb-ft.h index d7dc97e..be5c854 100644 --- a/src/hb-ft.h +++ b/src/hb-ft.h @@ -36,6 +36,7 @@ HB_BEGIN_DECLS + hb_font_funcs_t * hb_ft_get_font_funcs (void); @@ -51,6 +52,7 @@ hb_font_t * hb_ft_font_create (FT_Face ft_face, hb_destroy_func_t destroy); + HB_END_DECLS #endif /* HB_FT_H */ diff --git a/src/hb-glib.c b/src/hb-glib.c index d336c46..c548fa6 100644 --- a/src/hb-glib.c +++ b/src/hb-glib.c @@ -32,6 +32,9 @@ #include <glib.h> +HB_BEGIN_DECLS + + static hb_codepoint_t hb_glib_get_mirroring (hb_codepoint_t unicode) { g_unichar_get_mirror_char (unicode, &unicode); return unicode; } static hb_category_t hb_glib_get_general_category (hb_codepoint_t unicode) { return g_unichar_type (unicode); } static hb_script_t hb_glib_get_script (hb_codepoint_t unicode) { return g_unichar_get_script (unicode); } @@ -56,3 +59,6 @@ hb_glib_get_unicode_funcs (void) { return &glib_ufuncs; } + + +HB_END_DECLS diff --git a/src/hb-glib.h b/src/hb-glib.h index 76f7676..81ab15d 100644 --- a/src/hb-glib.h +++ b/src/hb-glib.h @@ -31,9 +31,11 @@ HB_BEGIN_DECLS + hb_unicode_funcs_t * hb_glib_get_unicode_funcs (void); + HB_END_DECLS #endif /* HB_GLIB_H */ diff --git a/src/hb-graphite.cc b/src/hb-graphite.cc index 8794db7..5d777ef 100644 --- a/src/hb-graphite.cc +++ b/src/hb-graphite.cc @@ -33,6 +33,9 @@ #include "hb-graphite.h" #include <map> +HB_BEGIN_DECLS + + namespace TtfUtil { extern int FontAscent(const void *pOS2); @@ -302,3 +305,6 @@ hb_graphite_shape (hb_font_t *font, delete[] firsts; delete[] flags; } + + +HB_END_DECLS diff --git a/src/hb-graphite.h b/src/hb-graphite.h index ac9ca27..b5d1176 100644 --- a/src/hb-graphite.h +++ b/src/hb-graphite.h @@ -30,9 +30,9 @@ #include "hb-shape.h" - HB_BEGIN_DECLS + #define HB_GRAPHITE_TAG_Silf HB_TAG('S','i','l','f') void hb_graphite_shape (hb_font_t *font, @@ -41,6 +41,7 @@ void hb_graphite_shape (hb_font_t *font, hb_feature_t *features, unsigned int num_features); + HB_END_DECLS #endif /* HB_GRAPHITE_H */ diff --git a/src/hb-icu.c b/src/hb-icu.c index dc97a54..44b92af 100644 --- a/src/hb-icu.c +++ b/src/hb-icu.c @@ -35,6 +35,9 @@ #include <unicode/uchar.h> #include <unicode/uscript.h> +HB_BEGIN_DECLS + + static hb_codepoint_t hb_icu_get_mirroring (hb_codepoint_t unicode) { return u_charMirror(unicode); } static unsigned int hb_icu_get_combining_class (hb_codepoint_t unicode) { return u_getCombiningClass (unicode); } @@ -246,3 +249,6 @@ hb_icu_get_unicode_funcs (void) { return &icu_ufuncs; } + + +HB_END_DECLS diff --git a/src/hb-icu.h b/src/hb-icu.h index cdb55b4..cc17af8 100644 --- a/src/hb-icu.h +++ b/src/hb-icu.h @@ -31,9 +31,11 @@ HB_BEGIN_DECLS + hb_unicode_funcs_t * hb_icu_get_unicode_funcs (void); + HB_END_DECLS #endif /* HB_ICU_H */ diff --git a/src/hb-language.c b/src/hb-language.c index d57cbdf..2aabada 100644 --- a/src/hb-language.c +++ b/src/hb-language.c @@ -28,6 +28,9 @@ #include "hb-language.h" +HB_BEGIN_DECLS + + static const char canon_map[256] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, @@ -113,3 +116,5 @@ hb_language_to_string (hb_language_t language) return (const char *) language; } + +HB_END_DECLS diff --git a/src/hb-language.h b/src/hb-language.h index d366cad..d3c91fb 100644 --- a/src/hb-language.h +++ b/src/hb-language.h @@ -31,6 +31,7 @@ HB_BEGIN_DECLS + typedef const void *hb_language_t; hb_language_t @@ -39,6 +40,7 @@ hb_language_from_string (const char *str); const char * hb_language_to_string (hb_language_t language); + HB_END_DECLS #endif /* HB_LANGUAGE_H */ diff --git a/src/hb-object-private.h b/src/hb-object-private.h index 9fdd564..57f5f94 100644 --- a/src/hb-object-private.h +++ b/src/hb-object-private.h @@ -32,6 +32,7 @@ #include "hb-private.h" +HB_BEGIN_DECLS /* Encapsulate operations on the object's reference count */ @@ -135,5 +136,6 @@ _hb_trace_object (const void *obj, } HB_STMT_END +HB_END_DECLS #endif /* HB_OBJECT_PRIVATE_H */ diff --git a/src/hb-open-file-private.hh b/src/hb-open-file-private.hh index 9570b0f..0782f65 100644 --- a/src/hb-open-file-private.hh +++ b/src/hb-open-file-private.hh @@ -29,6 +29,8 @@ #include "hb-open-type-private.hh" +HB_BEGIN_DECLS + /* * @@ -251,4 +253,6 @@ struct OpenTypeFontFile }; +HB_END_DECLS + #endif /* HB_OPEN_FILE_PRIVATE_HH */ diff --git a/src/hb-open-type-private.hh b/src/hb-open-type-private.hh index a0ecc2e..ae01ef9 100644 --- a/src/hb-open-type-private.hh +++ b/src/hb-open-type-private.hh @@ -31,6 +31,8 @@ #include "hb-blob.h" +HB_BEGIN_DECLS +HB_END_DECLS /* @@ -728,4 +730,7 @@ struct SortedArrayOf : ArrayOf<Type> { }; +HB_BEGIN_DECLS +HB_END_DECLS + #endif /* HB_OPEN_TYPE_PRIVATE_HH */ diff --git a/src/hb-ot-head-private.hh b/src/hb-ot-head-private.hh index faf0282..a3e87a9 100644 --- a/src/hb-ot-head-private.hh +++ b/src/hb-ot-head-private.hh @@ -29,6 +29,9 @@ #include "hb-open-type-private.hh" +HB_BEGIN_DECLS + + /* * head */ @@ -125,4 +128,6 @@ struct head }; +HB_END_DECLS + #endif /* HB_OT_HEAD_PRIVATE_HH */ diff --git a/src/hb-ot-layout-common-private.hh b/src/hb-ot-layout-common-private.hh index 5c90c27..c4a4055 100644 --- a/src/hb-ot-layout-common-private.hh +++ b/src/hb-ot-layout-common-private.hh @@ -36,6 +36,9 @@ #define NOT_COVERED ((unsigned int) 0x110000) #define MAX_NESTING_LEVEL 8 +HB_BEGIN_DECLS +HB_END_DECLS + /* * @@ -574,4 +577,7 @@ struct Device }; +HB_BEGIN_DECLS +HB_END_DECLS + #endif /* HB_OT_LAYOUT_COMMON_PRIVATE_HH */ diff --git a/src/hb-ot-layout-gdef-private.hh b/src/hb-ot-layout-gdef-private.hh index 2f77ef4..549e4b7 100644 --- a/src/hb-ot-layout-gdef-private.hh +++ b/src/hb-ot-layout-gdef-private.hh @@ -31,6 +31,8 @@ #include "hb-font-private.h" +HB_BEGIN_DECLS + /* * Attachment List Table @@ -397,4 +399,6 @@ struct GDEF }; +HB_END_DECLS + #endif /* HB_OT_LAYOUT_GDEF_PRIVATE_HH */ diff --git a/src/hb-ot-layout-gpos-private.hh b/src/hb-ot-layout-gpos-private.hh index 77cbbeb..00fa7ef 100644 --- a/src/hb-ot-layout-gpos-private.hh +++ b/src/hb-ot-layout-gpos-private.hh @@ -29,6 +29,8 @@ #include "hb-ot-layout-gsubgpos-private.hh" +HB_BEGIN_DECLS + #define HB_OT_LAYOUT_GPOS_NO_LAST ((unsigned int) -1) @@ -1373,7 +1375,9 @@ struct MarkMarkPos }; +HB_BEGIN_DECLS static inline bool position_lookup (hb_apply_context_t *c, unsigned int lookup_index); +HB_END_DECLS struct ContextPos : Context { @@ -1627,4 +1631,6 @@ static inline bool position_lookup (hb_apply_context_t *c, unsigned int lookup_i } +HB_END_DECLS + #endif /* HB_OT_LAYOUT_GPOS_PRIVATE_HH */ diff --git a/src/hb-ot-layout-gsub-private.hh b/src/hb-ot-layout-gsub-private.hh index 9af5b63..f09b4d2 100644 --- a/src/hb-ot-layout-gsub-private.hh +++ b/src/hb-ot-layout-gsub-private.hh @@ -29,6 +29,8 @@ #include "hb-ot-layout-gsubgpos-private.hh" +HB_BEGIN_DECLS + struct SingleSubstFormat1 { @@ -541,8 +543,9 @@ struct LigatureSubst }; - +HB_BEGIN_DECLS static inline bool substitute_lookup (hb_apply_context_t *c, unsigned int lookup_index); +HB_END_DECLS struct ContextSubst : Context { @@ -936,4 +939,6 @@ static inline bool substitute_lookup (hb_apply_context_t *c, unsigned int lookup } +HB_END_DECLS + #endif /* HB_OT_LAYOUT_GSUB_PRIVATE_HH */ diff --git a/src/hb-ot-layout-gsubgpos-private.hh b/src/hb-ot-layout-gsubgpos-private.hh index a3274b0..c13cddf 100644 --- a/src/hb-ot-layout-gsubgpos-private.hh +++ b/src/hb-ot-layout-gsubgpos-private.hh @@ -30,6 +30,8 @@ #include "hb-buffer-private.hh" #include "hb-ot-layout-gdef-private.hh" +HB_BEGIN_DECLS + #ifndef HB_DEBUG_APPLY #define HB_DEBUG_APPLY HB_DEBUG+0 @@ -39,6 +41,8 @@ hb_trace_t<HB_DEBUG_APPLY> trace (&c->debug_depth, "APPLY", HB_FUNC, this); \ +HB_BEGIN_DECLS + struct hb_apply_context_t { unsigned int debug_depth; @@ -164,6 +168,8 @@ static inline bool match_lookahead (hb_apply_context_t *c, return true; } +HB_END_DECLS + struct LookupRecord { @@ -180,6 +186,9 @@ struct LookupRecord DEFINE_SIZE_STATIC (4); }; + +HB_BEGIN_DECLS + static inline bool apply_lookup (hb_apply_context_t *c, unsigned int count, /* Including the first glyph */ unsigned int lookupCount, @@ -236,6 +245,8 @@ static inline bool apply_lookup (hb_apply_context_t *c, return true; } +HB_END_DECLS + /* Contextual lookups */ @@ -939,4 +950,6 @@ struct GSUBGPOS }; +HB_END_DECLS + #endif /* HB_OT_LAYOUT_GSUBGPOS_PRIVATE_HH */ diff --git a/src/hb-ot-layout-private.hh b/src/hb-ot-layout-private.hh index 8d0d469..8e041ba 100644 --- a/src/hb-ot-layout-private.hh +++ b/src/hb-ot-layout-private.hh @@ -35,9 +35,9 @@ #include "hb-font-private.h" #include "hb-buffer-private.hh" - HB_BEGIN_DECLS + typedef unsigned int hb_ot_layout_class_t; /* @@ -119,6 +119,7 @@ _hb_ot_layout_skip_mark (hb_face_t *face, unsigned int lookup_flags, unsigned int *property); + HB_END_DECLS #endif /* HB_OT_LAYOUT_PRIVATE_HH */ diff --git a/src/hb-ot-layout.cc b/src/hb-ot-layout.cc index 82b56c8..c39b63e 100644 --- a/src/hb-ot-layout.cc +++ b/src/hb-ot-layout.cc @@ -38,6 +38,8 @@ #include <stdlib.h> #include <string.h> +HB_BEGIN_DECLS + hb_ot_layout_t * _hb_ot_layout_new (hb_face_t *face) @@ -644,3 +646,6 @@ hb_ot_layout_position_finish (hb_font_t *font HB_UNUSED, } } } + + +HB_END_DECLS diff --git a/src/hb-ot-layout.h b/src/hb-ot-layout.h index d8c862b..e1b6381 100644 --- a/src/hb-ot-layout.h +++ b/src/hb-ot-layout.h @@ -35,6 +35,7 @@ HB_BEGIN_DECLS + #define HB_OT_TAG_GDEF HB_TAG('G','D','E','F') #define HB_OT_TAG_GSUB HB_TAG('G','S','U','B') #define HB_OT_TAG_GPOS HB_TAG('G','P','O','S') diff --git a/src/hb-ot-shape.cc b/src/hb-ot-shape.cc index 027f725..3c21953 100644 --- a/src/hb-ot-shape.cc +++ b/src/hb-ot-shape.cc @@ -32,6 +32,9 @@ #include "hb-ot-layout.h" +HB_BEGIN_DECLS + + /* XXX vertical */ hb_tag_t default_features[] = { HB_TAG('c','a','l','t'), @@ -625,3 +628,6 @@ hb_ot_shape (hb_font_t *font, buffer->direction = original_direction; } + + +HB_END_DECLS diff --git a/src/hb-ot-shape.h b/src/hb-ot-shape.h index 1fafb8e..182d951 100644 --- a/src/hb-ot-shape.h +++ b/src/hb-ot-shape.h @@ -32,6 +32,7 @@ HB_BEGIN_DECLS + void hb_ot_shape (hb_font_t *font, hb_face_t *face, @@ -39,6 +40,7 @@ hb_ot_shape (hb_font_t *font, hb_feature_t *features, unsigned int num_features); + HB_END_DECLS #endif /* HB_OT_SHAPE_H */ diff --git a/src/hb-ot-tag.c b/src/hb-ot-tag.c index 2d9db66..448f795 100644 --- a/src/hb-ot-tag.c +++ b/src/hb-ot-tag.c @@ -29,6 +29,8 @@ #include <string.h> +HB_BEGIN_DECLS + /* * Complete list at: @@ -694,3 +696,6 @@ hb_ot_tag_to_language (hb_tag_t tag) buf[10] = '\0'; return hb_language_from_string ((char *) buf); } + + +HB_END_DECLS diff --git a/src/hb-ot-tag.h b/src/hb-ot-tag.h index 6d15d4e..1eec69f 100644 --- a/src/hb-ot-tag.h +++ b/src/hb-ot-tag.h @@ -32,6 +32,7 @@ HB_BEGIN_DECLS + #define HB_OT_TAG_DEFAULT_SCRIPT HB_TAG ('D', 'F', 'L', 'T') #define HB_OT_TAG_DEFAULT_LANGUAGE HB_TAG ('d', 'f', 'l', 't') @@ -47,6 +48,7 @@ hb_ot_tag_from_language (hb_language_t language); hb_language_t hb_ot_tag_to_language (hb_tag_t tag); + HB_END_DECLS #endif /* HB_OT_TAG_H */ diff --git a/src/hb-ot.h b/src/hb-ot.h index 91992b8..268711d 100644 --- a/src/hb-ot.h +++ b/src/hb-ot.h @@ -33,4 +33,7 @@ #include "hb-ot-shape.h" #include "hb-ot-tag.h" +HB_BEGIN_DECLS +HB_END_DECLS + #endif /* HB_OT_H */ diff --git a/src/hb-private.h b/src/hb-private.h index 6b0a957..ad7c362 100644 --- a/src/hb-private.h +++ b/src/hb-private.h @@ -44,6 +44,8 @@ #include <stdio.h> #include <errno.h> +HB_BEGIN_DECLS + /* Essentials */ @@ -259,4 +261,7 @@ _hb_trace (const char *what, #include "hb-object-private.h" + +HB_END_DECLS + #endif /* HB_PRIVATE_H */ diff --git a/src/hb-shape.cc b/src/hb-shape.cc index 45bdc91..a73977b 100644 --- a/src/hb-shape.cc +++ b/src/hb-shape.cc @@ -36,6 +36,8 @@ #include "hb-graphite.h" #endif +HB_BEGIN_DECLS + void hb_shape (hb_font_t *font, @@ -58,3 +60,6 @@ hb_shape (hb_font_t *font, hb_ot_shape (font, face, buffer, features, num_features); } + + +HB_END_DECLS diff --git a/src/hb-shape.h b/src/hb-shape.h index d5210f3..48f1a55 100644 --- a/src/hb-shape.h +++ b/src/hb-shape.h @@ -33,6 +33,7 @@ HB_BEGIN_DECLS + typedef struct _hb_feature_t { hb_tag_t tag; uint32_t value; diff --git a/src/hb-unicode-private.h b/src/hb-unicode-private.h index 9bb566e..419404b 100644 --- a/src/hb-unicode-private.h +++ b/src/hb-unicode-private.h @@ -33,6 +33,7 @@ HB_BEGIN_DECLS + /* * hb_unicode_funcs_t */ diff --git a/src/hb-unicode.c b/src/hb-unicode.c index b237fbb..2de963e 100644 --- a/src/hb-unicode.c +++ b/src/hb-unicode.c @@ -28,6 +28,9 @@ #include "hb-unicode-private.h" +HB_BEGIN_DECLS + + /* * hb_unicode_funcs_t */ @@ -313,3 +316,6 @@ _hb_script_get_horizontal_direction (hb_script_t script) return horiz_dir[script]; } + + +HB_END_DECLS diff --git a/src/hb-unicode.h b/src/hb-unicode.h index 2f4f69b..8aeba33 100644 --- a/src/hb-unicode.h +++ b/src/hb-unicode.h @@ -31,6 +31,7 @@ HB_BEGIN_DECLS + /* Unicode General Category property */ typedef enum { diff --git a/src/hb.h b/src/hb.h index 905fd7b..691adee 100644 --- a/src/hb.h +++ b/src/hb.h @@ -35,4 +35,7 @@ #include "hb-shape.h" #include "hb-unicode.h" +HB_BEGIN_DECLS +HB_END_DECLS + #endif /* HB_H */ diff --git a/src/main.cc b/src/main.cc index 5d68862..083908e 100644 --- a/src/main.cc +++ b/src/main.cc @@ -35,6 +35,9 @@ #include <stdlib.h> #include <stdio.h> +HB_BEGIN_DECLS + + int main (int argc, char **argv) { @@ -188,3 +191,6 @@ main (int argc, char **argv) return 0; } + + +HB_END_DECLS commit cc6d52279d10a2edcf0d86c3a18a79ff4f6d3858 Author: Behdad Esfahbod <[email protected]> Date: Fri Jul 23 15:00:13 2010 -0400 De-C++ where possible Helps with avoiding many "extern C" declarations in source files. diff --git a/src/Makefile.am b/src/Makefile.am index ace7686..a8ba69c 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -16,7 +16,7 @@ HBSOURCES = \ hb-buffer-private.hh \ hb-common.c \ hb-font.cc \ - hb-font-private.hh \ + hb-font-private.h \ hb-object-private.h \ hb-open-file-private.hh \ hb-open-type-private.hh \ @@ -82,7 +82,7 @@ if HAVE_FREETYPE HBCFLAGS += $(FREETYPE_CFLAGS) HBLIBS += $(FREETYPE_LIBS) HBSOURCES += \ - hb-ft.cc \ + hb-ft.c \ $(NULL) HBHEADERS += \ hb-ft.h \ diff --git a/src/check-header-guards.sh b/src/check-header-guards.sh index b84fd68..59c399a 100755 --- a/src/check-header-guards.sh +++ b/src/check-header-guards.sh @@ -10,7 +10,7 @@ cd "$srcdir" for x in *.h *.hh ; do tag=`echo "$x" | tr 'a-z.-' 'A-Z_'` - lines=`grep "$tag" "$x" | wc -l` + lines=`grep "\<$tag\>" "$x" | wc -l` if test "x$lines" != x3; then echo "Ouch, header file $x does not have correct preprocessor guards" stat=1 diff --git a/src/hb-font-private.h b/src/hb-font-private.h new file mode 100644 index 0000000..7f54cbd --- /dev/null +++ b/src/hb-font-private.h @@ -0,0 +1,95 @@ +/* + * Copyright (C) 2009 Red Hat, 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. + * + * Red Hat Author(s): Behdad Esfahbod + */ + +#ifndef HB_FONT_PRIVATE_H +#define HB_FONT_PRIVATE_H + +#include "hb-private.h" + +#include "hb-font.h" + +HB_BEGIN_DECLS + +/* + * hb_font_funcs_t + */ + +struct _hb_font_funcs_t { + hb_reference_count_t ref_count; + + hb_bool_t immutable; + + struct { + hb_font_get_glyph_func_t get_glyph; + hb_font_get_contour_point_func_t get_contour_point; + hb_font_get_glyph_metrics_func_t get_glyph_metrics; + hb_font_get_kerning_func_t get_kerning; + } v; +}; + +extern HB_INTERNAL hb_font_funcs_t _hb_font_funcs_nil; + + +/* + * hb_face_t + */ + +struct _hb_face_t { + hb_reference_count_t ref_count; + + hb_get_table_func_t get_table; + hb_destroy_func_t destroy; + void *user_data; + + hb_blob_t *head_blob; + const struct head *head_table; + + struct hb_ot_layout_t *ot_layout; +}; + + +/* + * hb_font_t + */ + +struct _hb_font_t { + hb_reference_count_t ref_count; + + unsigned int x_scale; + unsigned int y_scale; + + unsigned int x_ppem; + unsigned int y_ppem; + + hb_font_funcs_t *klass; + hb_destroy_func_t destroy; + void *user_data; +}; + + +HB_END_DECLS + +#endif /* HB_FONT_PRIVATE_H */ diff --git a/src/hb-font-private.hh b/src/hb-font-private.hh deleted file mode 100644 index 35aa4d5..0000000 --- a/src/hb-font-private.hh +++ /dev/null @@ -1,95 +0,0 @@ -/* - * Copyright (C) 2009 Red Hat, 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. - * - * Red Hat Author(s): Behdad Esfahbod - */ - -#ifndef HB_FONT_PRIVATE_HH -#define HB_FONT_PRIVATE_HH - -#include "hb-private.h" - -#include "hb-font.h" - -HB_BEGIN_DECLS - -/* - * hb_font_funcs_t - */ - -struct _hb_font_funcs_t { - hb_reference_count_t ref_count; - - hb_bool_t immutable; - - struct { - hb_font_get_glyph_func_t get_glyph; - hb_font_get_contour_point_func_t get_contour_point; - hb_font_get_glyph_metrics_func_t get_glyph_metrics; - hb_font_get_kerning_func_t get_kerning; - } v; -}; - -extern HB_INTERNAL hb_font_funcs_t _hb_font_funcs_nil; - - -/* - * hb_face_t - */ - -struct _hb_face_t { - hb_reference_count_t ref_count; - - hb_get_table_func_t get_table; - hb_destroy_func_t destroy; - void *user_data; - - hb_blob_t *head_blob; - const struct head *head_table; - - struct hb_ot_layout_t *ot_layout; -}; - - -/* - * hb_font_t - */ - -struct _hb_font_t { - hb_reference_count_t ref_count; - - unsigned int x_scale; - unsigned int y_scale; - - unsigned int x_ppem; - unsigned int y_ppem; - - hb_font_funcs_t *klass; - hb_destroy_func_t destroy; - void *user_data; -}; - - -HB_END_DECLS - -#endif /* HB_FONT_PRIVATE_HH */ diff --git a/src/hb-font.cc b/src/hb-font.cc index 34c2345..8c4a608 100644 --- a/src/hb-font.cc +++ b/src/hb-font.cc @@ -26,7 +26,7 @@ #include "hb-private.h" -#include "hb-font-private.hh" +#include "hb-font-private.h" #include "hb-blob-private.h" #include "hb-open-file-private.hh" diff --git a/src/hb-ft.c b/src/hb-ft.c new file mode 100644 index 0000000..bdf2936 --- /dev/null +++ b/src/hb-ft.c @@ -0,0 +1,240 @@ +/* + * Copyright (C) 2009 Red Hat, Inc. + * Copyright (C) 2009 Keith Stribley <[email protected]> + * + * 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. + * + * Red Hat Author(s): Behdad Esfahbod + */ + +#include "hb-private.h" + +#include "hb-ft.h" + +#include "hb-font-private.h" + +#include FT_TRUETYPE_TABLES_H + +static hb_codepoint_t +hb_ft_get_glyph (hb_font_t *font HB_UNUSED, + hb_face_t *face HB_UNUSED, + const void *user_data, + hb_codepoint_t unicode, + hb_codepoint_t variation_selector) +{ + FT_Face ft_face = (FT_Face) user_data; + +#ifdef HAVE_FT_FACE_GETCHARVARIANTINDEX + if (unlikely (variation_selector)) { + hb_codepoint_t glyph = FT_Face_GetCharVariantIndex (ft_face, unicode, variation_selector); + if (glyph) + return glyph; + } +#endif + + return FT_Get_Char_Index (ft_face, unicode); +} + +static hb_bool_t +hb_ft_get_contour_point (hb_font_t *font HB_UNUSED, + hb_face_t *face HB_UNUSED, + const void *user_data, + unsigned int point_index, + hb_codepoint_t glyph, + hb_position_t *x, + hb_position_t *y) +{ + FT_Face ft_face = (FT_Face) user_data; + int load_flags = FT_LOAD_DEFAULT; + + /* TODO: load_flags, embolden, etc */ + + if (unlikely (FT_Load_Glyph (ft_face, glyph, load_flags))) + return FALSE; + + if (unlikely (ft_face->glyph->format != FT_GLYPH_FORMAT_OUTLINE)) + return FALSE; + + if (unlikely (point_index >= (unsigned int) ft_face->glyph->outline.n_points)) + return FALSE; + + *x = ft_face->glyph->outline.points[point_index].x; + *y = ft_face->glyph->outline.points[point_index].y; + + return TRUE; +} + +static void +hb_ft_get_glyph_metrics (hb_font_t *font HB_UNUSED, + hb_face_t *face HB_UNUSED, + const void *user_data, + hb_codepoint_t glyph, + hb_glyph_metrics_t *metrics) +{ + FT_Face ft_face = (FT_Face) user_data; + int load_flags = FT_LOAD_DEFAULT; + + /* TODO: load_flags, embolden, etc */ + + metrics->x_advance = metrics->y_advance = 0; + metrics->x_offset = metrics->y_offset = 0; + metrics->width = metrics->height = 0; + if (likely (!FT_Load_Glyph (ft_face, glyph, load_flags))) + { + /* TODO: A few negations should be in order here, not sure. */ + metrics->x_advance = ft_face->glyph->advance.x; + metrics->y_advance = ft_face->glyph->advance.y; + metrics->x_offset = ft_face->glyph->metrics.horiBearingX; + metrics->y_offset = ft_face->glyph->metrics.horiBearingY; + metrics->width = ft_face->glyph->metrics.width; + metrics->height = ft_face->glyph->metrics.height; + } +} + +static hb_position_t +hb_ft_get_kerning (hb_font_t *font HB_UNUSED, + hb_face_t *face HB_UNUSED, + const void *user_data, + hb_codepoint_t first_glyph, + hb_codepoint_t second_glyph) +{ + FT_Face ft_face = (FT_Face) user_data; + FT_Vector kerning; + + /* TODO: Kern type? */ + if (FT_Get_Kerning (ft_face, first_glyph, second_glyph, FT_KERNING_DEFAULT, &kerning)) + return 0; + + return kerning.x; +} + +static hb_font_funcs_t ft_ffuncs = { + HB_REFERENCE_COUNT_INVALID, /* ref_count */ + TRUE, /* immutable */ + { + hb_ft_get_glyph, + hb_ft_get_contour_point, + hb_ft_get_glyph_metrics, + hb_ft_get_kerning + } +}; + +hb_font_funcs_t * +hb_ft_get_font_funcs (void) +{ + return &ft_ffuncs; +} + + +static hb_blob_t * +_get_table (hb_tag_t tag, void *user_data) +{ + FT_Face ft_face = (FT_Face) user_data; + FT_Byte *buffer; + FT_ULong length = 0; + FT_Error error; + + if (unlikely (tag == HB_TAG_NONE)) + return NULL; + + error = FT_Load_Sfnt_Table (ft_face, tag, 0, NULL, &length); + if (error) + return NULL; + + /* TODO Use FT_Memory? */ + buffer = (FT_Byte *) malloc (length); + if (buffer == NULL) + return NULL; + + error = FT_Load_Sfnt_Table (ft_face, tag, 0, buffer, &length); + if (error) + return NULL; + + return hb_blob_create ((const char *) buffer, length, + HB_MEMORY_MODE_WRITABLE, + free, buffer); +} + + +hb_face_t * +hb_ft_face_create (FT_Face ft_face, + hb_destroy_func_t destroy) +{ + hb_face_t *face; + + if (ft_face->stream->read == NULL) { + hb_blob_t *blob; + + blob = hb_blob_create ((const char *) ft_face->stream->base, + (unsigned int) ft_face->stream->size, + /* TODO: Check FT_FACE_FLAG_EXTERNAL_STREAM? */ + HB_MEMORY_MODE_READONLY_MAY_MAKE_WRITABLE, + destroy, ft_face); + face = hb_face_create_for_data (blob, ft_face->face_index); + hb_blob_destroy (blob); + } else { + face = hb_face_create_for_tables (_get_table, destroy, ft_face); + } + + return face; +} + +static void +hb_ft_face_finalize (FT_Face ft_face) +{ + hb_face_destroy ((hb_face_t *) ft_face->generic.data); +} + +hb_face_t * +hb_ft_face_create_cached (FT_Face ft_face) +{ + if (unlikely (!ft_face->generic.data || ft_face->generic.finalizer != (FT_Generic_Finalizer) hb_ft_face_finalize)) + { + if (ft_face->generic.finalizer) + ft_face->generic.finalizer (ft_face); + + ft_face->generic.data = hb_ft_face_create (ft_face, NULL); + ft_face->generic.finalizer = (FT_Generic_Finalizer) hb_ft_face_finalize; + } + + return hb_face_reference ((hb_face_t *) ft_face->generic.data); +} + + +hb_font_t * +hb_ft_font_create (FT_Face ft_face, + hb_destroy_func_t destroy) +{ + hb_font_t *font; + + font = hb_font_create (); + hb_font_set_funcs (font, + hb_ft_get_font_funcs (), + destroy, ft_face); + hb_font_set_scale (font, + ((uint64_t) ft_face->size->metrics.x_scale * (uint64_t) ft_face->units_per_EM) >> 16, + ((uint64_t) ft_face->size->metrics.y_scale * (uint64_t) ft_face->units_per_EM) >> 16); + hb_font_set_ppem (font, + ft_face->size->metrics.x_ppem, + ft_face->size->metrics.y_ppem); + + return font; +} diff --git a/src/hb-ft.cc b/src/hb-ft.cc deleted file mode 100644 index aee64f6..0000000 --- a/src/hb-ft.cc +++ /dev/null @@ -1,240 +0,0 @@ -/* - * Copyright (C) 2009 Red Hat, Inc. - * Copyright (C) 2009 Keith Stribley <[email protected]> - * - * 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. - * - * Red Hat Author(s): Behdad Esfahbod - */ - -#include "hb-private.h" - -#include "hb-ft.h" - -#include "hb-font-private.hh" - -#include FT_TRUETYPE_TABLES_H - -static hb_codepoint_t -hb_ft_get_glyph (hb_font_t *font HB_UNUSED, - hb_face_t *face HB_UNUSED, - const void *user_data, - hb_codepoint_t unicode, - hb_codepoint_t variation_selector) -{ - FT_Face ft_face = (FT_Face) user_data; - -#ifdef HAVE_FT_FACE_GETCHARVARIANTINDEX - if (unlikely (variation_selector)) { - hb_codepoint_t glyph = FT_Face_GetCharVariantIndex (ft_face, unicode, variation_selector); - if (glyph) - return glyph; - } -#endif - - return FT_Get_Char_Index (ft_face, unicode); -} - -static hb_bool_t -hb_ft_get_contour_point (hb_font_t *font HB_UNUSED, - hb_face_t *face HB_UNUSED, - const void *user_data, - unsigned int point_index, - hb_codepoint_t glyph, - hb_position_t *x, - hb_position_t *y) -{ - FT_Face ft_face = (FT_Face) user_data; - int load_flags = FT_LOAD_DEFAULT; - - /* TODO: load_flags, embolden, etc */ - - if (unlikely (FT_Load_Glyph (ft_face, glyph, load_flags))) - return FALSE; - - if (unlikely (ft_face->glyph->format != FT_GLYPH_FORMAT_OUTLINE)) - return FALSE; - - if (unlikely (point_index >= (unsigned int) ft_face->glyph->outline.n_points)) - return FALSE; - - *x = ft_face->glyph->outline.points[point_index].x; - *y = ft_face->glyph->outline.points[point_index].y; - - return TRUE; -} - -static void -hb_ft_get_glyph_metrics (hb_font_t *font HB_UNUSED, - hb_face_t *face HB_UNUSED, - const void *user_data, - hb_codepoint_t glyph, - hb_glyph_metrics_t *metrics) -{ - FT_Face ft_face = (FT_Face) user_data; - int load_flags = FT_LOAD_DEFAULT; - - /* TODO: load_flags, embolden, etc */ - - metrics->x_advance = metrics->y_advance = 0; - metrics->x_offset = metrics->y_offset = 0; - metrics->width = metrics->height = 0; - if (likely (!FT_Load_Glyph (ft_face, glyph, load_flags))) - { - /* TODO: A few negations should be in order here, not sure. */ - metrics->x_advance = ft_face->glyph->advance.x; - metrics->y_advance = ft_face->glyph->advance.y; - metrics->x_offset = ft_face->glyph->metrics.horiBearingX; - metrics->y_offset = ft_face->glyph->metrics.horiBearingY; - metrics->width = ft_face->glyph->metrics.width; - metrics->height = ft_face->glyph->metrics.height; - } -} - -static hb_position_t -hb_ft_get_kerning (hb_font_t *font HB_UNUSED, - hb_face_t *face HB_UNUSED, - const void *user_data, - hb_codepoint_t first_glyph, - hb_codepoint_t second_glyph) -{ - FT_Face ft_face = (FT_Face) user_data; - FT_Vector kerning; - - /* TODO: Kern type? */ - if (FT_Get_Kerning (ft_face, first_glyph, second_glyph, FT_KERNING_DEFAULT, &kerning)) - return 0; - - return kerning.x; -} - -static hb_font_funcs_t ft_ffuncs = { - HB_REFERENCE_COUNT_INVALID, /* ref_count */ - TRUE, /* immutable */ - { - hb_ft_get_glyph, - hb_ft_get_contour_point, - hb_ft_get_glyph_metrics, - hb_ft_get_kerning - } -}; - -hb_font_funcs_t * -hb_ft_get_font_funcs (void) -{ - return &ft_ffuncs; -} - - -static hb_blob_t * -_get_table (hb_tag_t tag, void *user_data) -{ - FT_Face ft_face = (FT_Face) user_data; - FT_Byte *buffer; - FT_ULong length = 0; - FT_Error error; - - if (unlikely (tag == HB_TAG_NONE)) - return NULL; - - error = FT_Load_Sfnt_Table (ft_face, tag, 0, NULL, &length); - if (error) - return NULL; - - /* TODO Use FT_Memory? */ - buffer = (FT_Byte *) malloc (length); - if (buffer == NULL) - return NULL; - - error = FT_Load_Sfnt_Table (ft_face, tag, 0, buffer, &length); - if (error) - return NULL; - - return hb_blob_create ((const char *) buffer, length, - HB_MEMORY_MODE_WRITABLE, - free, buffer); -} - - -hb_face_t * -hb_ft_face_create (FT_Face ft_face, - hb_destroy_func_t destroy) -{ - hb_face_t *face; - - if (ft_face->stream->read == NULL) { - hb_blob_t *blob; - - blob = hb_blob_create ((const char *) ft_face->stream->base, - (unsigned int) ft_face->stream->size, - /* TODO: Check FT_FACE_FLAG_EXTERNAL_STREAM? */ - HB_MEMORY_MODE_READONLY_MAY_MAKE_WRITABLE, - destroy, ft_face); - face = hb_face_create_for_data (blob, ft_face->face_index); - hb_blob_destroy (blob); - } else { - face = hb_face_create_for_tables (_get_table, destroy, ft_face); - } - - return face; -} - -static void -hb_ft_face_finalize (FT_Face ft_face) -{ - hb_face_destroy ((hb_face_t *) ft_face->generic.data); -} - -hb_face_t * -hb_ft_face_create_cached (FT_Face ft_face) -{ - if (unlikely (!ft_face->generic.data || ft_face->generic.finalizer != (FT_Generic_Finalizer) hb_ft_face_finalize)) - { - if (ft_face->generic.finalizer) - ft_face->generic.finalizer (ft_face); - - ft_face->generic.data = hb_ft_face_create (ft_face, NULL); - ft_face->generic.finalizer = (FT_Generic_Finalizer) hb_ft_face_finalize; - } - - return hb_face_reference ((hb_face_t *) ft_face->generic.data); -} - - -hb_font_t * -hb_ft_font_create (FT_Face ft_face, - hb_destroy_func_t destroy) -{ - hb_font_t *font; - - font = hb_font_create (); - hb_font_set_funcs (font, - hb_ft_get_font_funcs (), - destroy, ft_face); - hb_font_set_scale (font, - ((uint64_t) ft_face->size->metrics.x_scale * (uint64_t) ft_face->units_per_EM) >> 16, - ((uint64_t) ft_face->size->metrics.y_scale * (uint64_t) ft_face->units_per_EM) >> 16); - hb_font_set_ppem (font, - ft_face->size->metrics.x_ppem, - ft_face->size->metrics.y_ppem); - - return font; -} diff --git a/src/hb-graphite.cc b/src/hb-graphite.cc index 54a01fc..8794db7 100644 --- a/src/hb-graphite.cc +++ b/src/hb-graphite.cc @@ -29,7 +29,7 @@ #include <graphite/GrConstants.h> #include <graphite/Segment.h> #include "hb-buffer-private.hh" -#include "hb-font-private.hh" +#include "hb-font-private.h" #include "hb-graphite.h" #include <map> diff --git a/src/hb-ot-layout-gdef-private.hh b/src/hb-ot-layout-gdef-private.hh index 1adff6e..2f77ef4 100644 --- a/src/hb-ot-layout-gdef-private.hh +++ b/src/hb-ot-layout-gdef-private.hh @@ -29,7 +29,7 @@ #include "hb-ot-layout-common-private.hh" -#include "hb-font-private.hh" +#include "hb-font-private.h" /* diff --git a/src/hb-ot-layout-private.hh b/src/hb-ot-layout-private.hh index decc8f7..8d0d469 100644 --- a/src/hb-ot-layout-private.hh +++ b/src/hb-ot-layout-private.hh @@ -32,7 +32,7 @@ #include "hb-ot-layout.h" #include "hb-ot-head-private.hh" -#include "hb-font-private.hh" +#include "hb-font-private.h" #include "hb-buffer-private.hh" commit 0dd200d28f51bf4062d8a377432c8977c80cb210 Author: Behdad Esfahbod <[email protected]> Date: Fri Jul 23 14:56:29 2010 -0400 Header dep cleanup diff --git a/src/hb-font-private.hh b/src/hb-font-private.hh index d24ea5f..35aa4d5 100644 --- a/src/hb-font-private.hh +++ b/src/hb-font-private.hh @@ -31,8 +31,6 @@ #include "hb-font.h" -#include "hb-ot-head-private.hh" - HB_BEGIN_DECLS /* diff --git a/src/hb-ot-layout-private.hh b/src/hb-ot-layout-private.hh index 55b609d..decc8f7 100644 --- a/src/hb-ot-layout-private.hh +++ b/src/hb-ot-layout-private.hh @@ -30,6 +30,7 @@ #include "hb-private.h" #include "hb-ot-layout.h" +#include "hb-ot-head-private.hh" #include "hb-font-private.hh" #include "hb-buffer-private.hh" commit fb0d25246267851a1fc200ead28c56359a40047e Author: Behdad Esfahbod <[email protected]> Date: Fri Jul 23 14:54:22 2010 -0400 dos2unix diff --git a/src/hb-ot-head-private.hh b/src/hb-ot-head-private.hh index cdc981f..faf0282 100644 --- a/src/hb-ot-head-private.hh +++ b/src/hb-ot-head-private.hh @@ -1,128 +1,128 @@ -/* - * Copyright (C) 2010 Red Hat, 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. - * - * Red Hat Author(s): Behdad Esfahbod - */ - -#ifndef HB_OT_HEAD_PRIVATE_HH -#define HB_OT_HEAD_PRIVATE_HH - -#include "hb-open-type-private.hh" - -/* - * head - */ - -#define HB_OT_TAG_head HB_TAG('h','e','a','d') - -struct head -{ - static const hb_tag_t Tag = HB_OT_TAG_head; - - inline bool sanitize (hb_sanitize_context_t *c) { - TRACE_SANITIZE (); - /* Shall we check for magicNumber here? Who cares? */ - return c->check_struct (this) && likely (version.major == 1); - } - - FixedVersion version; /* Version of the head table--currently - * 0x00010000 for version 1.0. */ - FixedVersion fontRevision; /* Set by font manufacturer. */ - ULONG checkSumAdjustment; /* To compute: set it to 0, sum the - * entire font as ULONG, then store - * 0xB1B0AFBA - sum. */ - ULONG magicNumber; /* Set to 0x5F0F3CF5. */ - USHORT flags; /* Bit 0: Baseline for font at y=0; - * Bit 1: Left sidebearing point at x=0; - * Bit 2: Instructions may depend on point size; - * Bit 3: Force ppem to integer values for all - * internal scaler math; may use fractional - * ppem sizes if this bit is clear; - * Bit 4: Instructions may alter advance width - * (the advance widths might not scale linearly); - - * Bits 5-10: These should be set according to - * Apple's specification. However, they are not - * implemented in OpenType. - * Bit 5: This bit should be set in fonts that are - * intended to e laid out vertically, and in - * which the glyphs have been drawn such that an - * x-coordinate of 0 corresponds to the desired - * vertical baseline. - * Bit 6: This bit must be set to zero. - * Bit 7: This bit should be set if the font - * requires layout for correct linguistic - * rendering (e.g. Arabic fonts). - * Bit 8: This bit should be set for a GX font - * which has one or more metamorphosis effects - * designated as happening by default. - * Bit 9: This bit should be set if the font - * contains any strong right-to-left glyphs. - * Bit 10: This bit should be set if the font - * contains Indic-style rearrangement effects. - - * Bit 11: Font data is 'lossless,' as a result - * of having been compressed and decompressed - * with the Agfa MicroType Express engine. - * Bit 12: Font converted (produce compatible metrics) - * Bit 13: Font optimized for ClearTypeâ¢. - * Note, fonts that rely on embedded bitmaps (EBDT) - * for rendering should not be considered optimized - * for ClearType, and therefore should keep this bit - * cleared. - * Bit 14: Reserved, set to 0 - * Bit 15: Reserved, set to 0. */ - USHORT unitsPerEm; /* Valid range is from 16 to 16384. This value - * should be a power of 2 for fonts that have - * TrueType outlines. */ - LONGDATETIME created; /* Number of seconds since 12:00 midnight, - January 1, 1904. 64-bit integer */ - LONGDATETIME modified; /* Number of seconds since 12:00 midnight, - January 1, 1904. 64-bit integer */ - SHORT xMin; /* For all glyph bounding boxes. */ - SHORT yMin; /* For all glyph bounding boxes. */ - SHORT xMax; /* For all glyph bounding boxes. */ - SHORT yMax; /* For all glyph bounding boxes. */ - USHORT macStyle; /* Bit 0: Bold (if set to 1); - * Bit 1: Italic (if set to 1) - * Bit 2: Underline (if set to 1) - * Bit 3: Outline (if set to 1) - * Bit 4: Shadow (if set to 1) - * Bit 5: Condensed (if set to 1) - * Bit 6: Extended (if set to 1) - * Bits 7-15: Reserved (set to 0). */ - USHORT lowestRecPPEM; /* Smallest readable size in pixels. */ - SHORT fontDirectionHint; /* Deprecated (Set to 2). - * 0: Fully mixed directional glyphs; - * 1: Only strongly left to right; - * 2: Like 1 but also contains neutrals; - * -1: Only strongly right to left; - * -2: Like -1 but also contains neutrals. */ - SHORT indexToLocFormat; /* 0 for short offsets, 1 for long. */ - SHORT glyphDataFormat; /* 0 for current format. */ - public: - DEFINE_SIZE_STATIC (54); -}; - - -#endif /* HB_OT_HEAD_PRIVATE_HH */ +/* + * Copyright (C) 2010 Red Hat, 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. + * + * Red Hat Author(s): Behdad Esfahbod + */ + +#ifndef HB_OT_HEAD_PRIVATE_HH +#define HB_OT_HEAD_PRIVATE_HH + +#include "hb-open-type-private.hh" + +/* + * head + */ + +#define HB_OT_TAG_head HB_TAG('h','e','a','d') + +struct head +{ + static const hb_tag_t Tag = HB_OT_TAG_head; + + inline bool sanitize (hb_sanitize_context_t *c) { + TRACE_SANITIZE (); + /* Shall we check for magicNumber here? Who cares? */ + return c->check_struct (this) && likely (version.major == 1); + } + + FixedVersion version; /* Version of the head table--currently + * 0x00010000 for version 1.0. */ + FixedVersion fontRevision; /* Set by font manufacturer. */ + ULONG checkSumAdjustment; /* To compute: set it to 0, sum the + * entire font as ULONG, then store + * 0xB1B0AFBA - sum. */ + ULONG magicNumber; /* Set to 0x5F0F3CF5. */ + USHORT flags; /* Bit 0: Baseline for font at y=0; + * Bit 1: Left sidebearing point at x=0; + * Bit 2: Instructions may depend on point size; + * Bit 3: Force ppem to integer values for all + * internal scaler math; may use fractional + * ppem sizes if this bit is clear; + * Bit 4: Instructions may alter advance width + * (the advance widths might not scale linearly); + + * Bits 5-10: These should be set according to + * Apple's specification. However, they are not + * implemented in OpenType. + * Bit 5: This bit should be set in fonts that are + * intended to e laid out vertically, and in + * which the glyphs have been drawn such that an + * x-coordinate of 0 corresponds to the desired + * vertical baseline. + * Bit 6: This bit must be set to zero. + * Bit 7: This bit should be set if the font + * requires layout for correct linguistic + * rendering (e.g. Arabic fonts). + * Bit 8: This bit should be set for a GX font + * which has one or more metamorphosis effects + * designated as happening by default. + * Bit 9: This bit should be set if the font + * contains any strong right-to-left glyphs. + * Bit 10: This bit should be set if the font + * contains Indic-style rearrangement effects. + + * Bit 11: Font data is 'lossless,' as a result + * of having been compressed and decompressed + * with the Agfa MicroType Express engine. + * Bit 12: Font converted (produce compatible metrics) + * Bit 13: Font optimized for ClearTypeâ¢. + * Note, fonts that rely on embedded bitmaps (EBDT) + * for rendering should not be considered optimized + * for ClearType, and therefore should keep this bit + * cleared. + * Bit 14: Reserved, set to 0 + * Bit 15: Reserved, set to 0. */ + USHORT unitsPerEm; /* Valid range is from 16 to 16384. This value + * should be a power of 2 for fonts that have + * TrueType outlines. */ + LONGDATETIME created; /* Number of seconds since 12:00 midnight, + January 1, 1904. 64-bit integer */ + LONGDATETIME modified; /* Number of seconds since 12:00 midnight, + January 1, 1904. 64-bit integer */ + SHORT xMin; /* For all glyph bounding boxes. */ + SHORT yMin; /* For all glyph bounding boxes. */ + SHORT xMax; /* For all glyph bounding boxes. */ + SHORT yMax; /* For all glyph bounding boxes. */ + USHORT macStyle; /* Bit 0: Bold (if set to 1); + * Bit 1: Italic (if set to 1) + * Bit 2: Underline (if set to 1) + * Bit 3: Outline (if set to 1) + * Bit 4: Shadow (if set to 1) + * Bit 5: Condensed (if set to 1) + * Bit 6: Extended (if set to 1) + * Bits 7-15: Reserved (set to 0). */ + USHORT lowestRecPPEM; /* Smallest readable size in pixels. */ + SHORT fontDirectionHint; /* Deprecated (Set to 2). + * 0: Fully mixed directional glyphs; + * 1: Only strongly left to right; + * 2: Like 1 but also contains neutrals; + * -1: Only strongly right to left; + * -2: Like -1 but also contains neutrals. */ + SHORT indexToLocFormat; /* 0 for short offsets, 1 for long. */ + SHORT glyphDataFormat; /* 0 for current format. */ + public: + DEFINE_SIZE_STATIC (54); +}; + + +#endif /* HB_OT_HEAD_PRIVATE_HH */
_______________________________________________ HarfBuzz mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/harfbuzz
