Switch old and uniscribe backends to shape_plan

This commit is contained in:
Behdad Esfahbod 2012-07-27 01:26:11 -04:00
parent c32c096a42
commit b6b7ba1313
5 changed files with 48 additions and 174 deletions

View File

@ -248,61 +248,6 @@ _hb_old_shaper_shape_plan_data_destroy (hb_old_shaper_shape_plan_data_t *data)
* shaper
*/
static hb_user_data_key_t hb_old_data_key;
static HB_Face
_hb_old_face_get (hb_face_t *face)
{
HB_Face data = (HB_Face) hb_face_get_user_data (face, &hb_old_data_key);
if (likely (data)) return data;
data = _hb_old_shaper_face_data_create (face);
if (unlikely (!data)) {
DEBUG_MSG (OLD, face, "HB_NewFace failed");
return NULL;
}
if (unlikely (!hb_face_set_user_data (face, &hb_old_data_key, data,
(hb_destroy_func_t) _hb_old_shaper_face_data_destroy,
false)))
{
_hb_old_shaper_face_data_destroy (data);
data = (HB_Face) hb_face_get_user_data (face, &hb_old_data_key);
if (data)
return data;
else
return NULL;
}
return data;
}
static HB_Font
_hb_old_font_get (hb_font_t *font)
{
/* Ouch, check user_data! */
HB_Font data = _hb_old_shaper_font_data_create (font);
if (!data)
return NULL;
if (unlikely (!hb_font_set_user_data (font, &hb_old_data_key, data,
(hb_destroy_func_t) _hb_old_shaper_font_data_destroy,
false)))
{
_hb_old_shaper_font_data_destroy (data);
data = (HB_Font) hb_font_get_user_data (font, &hb_old_data_key);
if (data)
return data;
else
return NULL;
}
return data;
}
hb_bool_t
_hb_old_shape (hb_shape_plan_t *shape_plan,
hb_font_t *font,
@ -310,27 +255,12 @@ _hb_old_shape (hb_shape_plan_t *shape_plan,
const hb_feature_t *features,
unsigned int num_features)
{
if (unlikely (!buffer->len))
return true;
buffer->guess_properties ();
hb_face_t *face = font->face;
HB_Face old_face = HB_SHAPER_DATA_GET (face);
HB_Font old_font = HB_SHAPER_DATA_GET (font);
bool backward = HB_DIRECTION_IS_BACKWARD (buffer->props.direction);
#define FAIL(...) \
HB_STMT_START { \
DEBUG_MSG (OLD, NULL, __VA_ARGS__); \
return false; \
} HB_STMT_END;
HB_Face old_face = _hb_old_face_get (font->face);
if (unlikely (!old_face))
FAIL ("Couldn't get old face");
HB_Font old_font = _hb_old_font_get (font);
if (unlikely (!old_font))
FAIL ("Couldn't get old font");
retry:
unsigned int scratch_size;
@ -398,7 +328,7 @@ retry:
{
buffer->ensure (buffer->allocated * 2);
if (buffer->in_error)
FAIL ("Buffer resize failed");
return false;
goto retry;
}
return false;
@ -429,7 +359,7 @@ retry:
buffer->ensure (num_glyphs);
if (buffer->in_error)
FAIL ("Buffer in error");
return false;
buffer->len = num_glyphs;

View File

@ -82,6 +82,11 @@ hb_shape_full (hb_font_t *font,
unsigned int num_features,
const char * const *shaper_list)
{
if (unlikely (!buffer->len))
return true;
buffer->guess_properties ();
hb_shape_plan_t *shape_plan = hb_shape_plan_create (font->face, &buffer->props, features, num_features, shaper_list);
hb_bool_t res = hb_shape_plan_execute (shape_plan, font, buffer, features, num_features);
hb_shape_plan_destroy (shape_plan);

View File

@ -36,8 +36,7 @@
#ifdef HB_SHAPER
/* For use in things like font->shaper_data() in the shaper implementations. */
#define shaper_data() shaper_data.HB_SHAPER
#define HB_SHAPER_DATA_GET(object) HB_SHAPER_DATA (HB_SHAPER, object)
#endif

View File

@ -69,15 +69,11 @@ struct hb_shaper_data_t {
#define HB_SHAPER_DATA_TYPE(shaper, object) struct hb_##shaper##_shaper_##object##_data_t
#define HB_SHAPER_DATA(shaper, object) (* (HB_SHAPER_DATA_TYPE(shaper, object) **) &(object)->shaper_data.shaper)
#define HB_SHAPER_DATA_GET_FUNC(shaper, object) _hb_##shaper##_shaper_get_##object##_data
#define HB_SHAPER_DATA_CREATE_FUNC(shaper, object) _hb_##shaper##_shaper_##object##_data_create
#define HB_SHAPER_DATA_DESTROY_FUNC(shaper, object) _hb_##shaper##_shaper_##object##_data_destroy
#define HB_SHAPER_DATA_PROTOTYPE(shaper, object) \
HB_SHAPER_DATA_TYPE (shaper, object); /* Type forward declaration. */ \
static inline HB_SHAPER_DATA_TYPE (shaper, object) * \
HB_SHAPER_DATA_GET_FUNC (shaper, object) (hb_##object##_t *object) \
{ return HB_SHAPER_DATA (shaper, object); } \
extern "C" HB_INTERNAL HB_SHAPER_DATA_TYPE (shaper, object) * \
HB_SHAPER_DATA_CREATE_FUNC (shaper, object) (hb_##object##_t *object HB_SHAPER_DATA_CREATE_FUNC_EXTRA_ARGS); \
extern "C" HB_INTERNAL void \

View File

@ -55,38 +55,6 @@ DWORD GetFontData(
);
*/
static bool
populate_log_font (LOGFONTW *lf,
hb_font_t *font)
{
memset (lf, 0, sizeof (*lf));
lf->lfHeight = -font->y_scale;
lf->lfCharSet = DEFAULT_CHARSET;
hb_blob_t *blob = Sanitizer<name>::sanitize (hb_face_reference_table (font->face, HB_TAG ('n','a','m','e')));
const name *name_table = Sanitizer<name>::lock_instance (blob);
unsigned int len = name_table->get_name (3, 1, 0x409, 4,
lf->lfFaceName,
sizeof (lf->lfFaceName[0]) * LF_FACESIZE)
/ sizeof (lf->lfFaceName[0]);
hb_blob_destroy (blob);
if (unlikely (!len)) {
DEBUG_MSG (UNISCRIBE, NULL, "Didn't find English name table entry");
return false;
}
if (unlikely (len >= LF_FACESIZE)) {
DEBUG_MSG (UNISCRIBE, NULL, "Font name too long");
return false;
}
for (unsigned int i = 0; i < len; i++)
lf->lfFaceName[i] = hb_be_uint16 (lf->lfFaceName[i]);
lf->lfFaceName[len] = 0;
return true;
}
/*
* shaper face data
@ -141,6 +109,38 @@ struct hb_uniscribe_shaper_font_data_t {
SCRIPT_CACHE script_cache;
};
static bool
populate_log_font (LOGFONTW *lf,
hb_font_t *font)
{
memset (lf, 0, sizeof (*lf));
lf->lfHeight = -font->y_scale;
lf->lfCharSet = DEFAULT_CHARSET;
hb_blob_t *blob = Sanitizer<name>::sanitize (hb_face_reference_table (font->face, HB_TAG ('n','a','m','e')));
const name *name_table = Sanitizer<name>::lock_instance (blob);
unsigned int len = name_table->get_name (3, 1, 0x409, 4,
lf->lfFaceName,
sizeof (lf->lfFaceName[0]) * LF_FACESIZE)
/ sizeof (lf->lfFaceName[0]);
hb_blob_destroy (blob);
if (unlikely (!len)) {
DEBUG_MSG (UNISCRIBE, NULL, "Didn't find English name table entry");
return false;
}
if (unlikely (len >= LF_FACESIZE)) {
DEBUG_MSG (UNISCRIBE, NULL, "Font name too long");
return false;
}
for (unsigned int i = 0; i < len; i++)
lf->lfFaceName[i] = hb_be_uint16 (lf->lfFaceName[i]);
lf->lfFaceName[len] = 0;
return true;
}
hb_uniscribe_shaper_font_data_t *
_hb_uniscribe_shaper_font_data_create (hb_font_t *font)
{
@ -208,65 +208,18 @@ _hb_uniscribe_shaper_shape_plan_data_destroy (hb_uniscribe_shaper_shape_plan_dat
/*
* shaper
*/
static hb_user_data_key_t hb_uniscribe_data_key;
static hb_uniscribe_shaper_face_data_t *
_hb_uniscribe_face_get_data (hb_face_t *face)
{
hb_uniscribe_shaper_face_data_t *data = (hb_uniscribe_shaper_face_data_t *) hb_face_get_user_data (face, &hb_uniscribe_data_key);
if (likely (data)) return data;
data = _hb_uniscribe_shaper_face_data_create (face);
if (!data) return NULL;
if (unlikely (!hb_face_set_user_data (face, &hb_uniscribe_data_key, data,
(hb_destroy_func_t) _hb_uniscribe_shaper_face_data_destroy,
false)))
{
_hb_uniscribe_shaper_face_data_destroy (data);
data = (hb_uniscribe_shaper_face_data_t *) hb_face_get_user_data (face, &hb_uniscribe_data_key);
}
return data;
}
static hb_uniscribe_shaper_font_data_t *
_hb_uniscribe_font_get_data (hb_font_t *font)
{
hb_uniscribe_shaper_font_data_t *data = (hb_uniscribe_shaper_font_data_t *) hb_font_get_user_data (font, &hb_uniscribe_data_key);
if (likely (data)) return data;
data = _hb_uniscribe_shaper_font_data_create (font);
if (unlikely (!data))
return NULL;
if (unlikely (!hb_font_set_user_data (font, &hb_uniscribe_data_key, data,
(hb_destroy_func_t) _hb_uniscribe_shaper_font_data_destroy,
false)))
{
_hb_uniscribe_shaper_font_data_destroy (data);
data = (hb_uniscribe_shaper_font_data_t *) hb_font_get_user_data (font, &hb_uniscribe_data_key);
}
return data;
}
LOGFONTW *
hb_uniscribe_font_get_logfontw (hb_font_t *font)
{
hb_uniscribe_shaper_font_data_t *font_data = _hb_uniscribe_font_get_data (font);
if (unlikely (!font_data))
return NULL;
hb_uniscribe_shaper_font_data_t *font_data = HB_SHAPER_DATA_GET (font);
return &font_data->log_font;
}
HFONT
hb_uniscribe_font_get_hfont (hb_font_t *font)
{
hb_uniscribe_shaper_font_data_t *font_data = _hb_uniscribe_font_get_data (font);
if (unlikely (!font_data))
return 0;
hb_uniscribe_shaper_font_data_t *font_data = HB_SHAPER_DATA_GET (font);
return font_data->hfont;
}
@ -278,7 +231,9 @@ _hb_uniscribe_shape (hb_shape_plan_t *shape_plan,
const hb_feature_t *features,
unsigned int num_features)
{
buffer->guess_properties ();
hb_face_t *face = font->face;
hb_uniscribe_shaper_face_data_t *face_data = HB_SHAPER_DATA_GET (face);
hb_uniscribe_shaper_font_data_t *font_data = HB_SHAPER_DATA_GET (font);
#define FAIL(...) \
HB_STMT_START { \
@ -286,17 +241,6 @@ _hb_uniscribe_shape (hb_shape_plan_t *shape_plan,
return false; \
} HB_STMT_END;
hb_uniscribe_shaper_face_data_t *face_data = _hb_uniscribe_face_get_data (font->face);
if (unlikely (!face_data->fh))
FAIL ("Couldn't get face data");
hb_uniscribe_shaper_font_data_t *font_data = _hb_uniscribe_font_get_data (font);
if (unlikely (!font_data->hfont))
FAIL ("Couldn't get font font");
if (unlikely (!buffer->len))
return true;
HRESULT hr;
retry: