clean up harfbuzz->icu interface

This commit is contained in:
Dane Springmeyer 2014-08-29 17:41:29 -07:00
parent a2927c123b
commit c7f58ee64c

View file

@ -29,11 +29,11 @@
#include <mapnik/text/face.hpp>
// stl
#include <list>
#include <type_traits>
// harfbuzz
#include <harfbuzz/hb.h>
#include <harfbuzz/hb-ft.h>
//#include <harfbuzz/hb-icu.h>
namespace mapnik
{
@ -41,7 +41,17 @@ namespace mapnik
static inline hb_script_t _icu_script_to_script(UScriptCode script)
{
if (script == USCRIPT_INVALID_CODE) return HB_SCRIPT_INVALID;
return hb_script_from_string(uscript_getShortName(script), -1);
return hb_script_from_string(uscript_getShortName(script), -1);
}
static inline const uint16_t * uchar_to_utf16(const UChar* src)
{
static_assert(sizeof(UChar) == sizeof(uint16_t),"UChar is eq size to uint16_t");
#if defined(_MSC_VER)
return reinterpret_cast<const uint16_t *>(src);
#else
return src;
#endif
}
struct harfbuzz_shaper
@ -61,7 +71,6 @@ static void shape_text(text_line & line,
auto hb_buffer_deleter = [](hb_buffer_t * buffer) { hb_buffer_destroy(buffer);};
const std::unique_ptr<hb_buffer_t, decltype(hb_buffer_deleter)> buffer(hb_buffer_create(),hb_buffer_deleter);
//hb_buffer_set_unicode_funcs(buffer.get(), hb_icu_get_unicode_funcs());
hb_buffer_pre_allocate(buffer.get(), length);
mapnik::value_unicode_string const& text = itemizer.text();
@ -76,7 +85,7 @@ static void shape_text(text_line & line,
{
++pos;
hb_buffer_clear_contents(buffer.get());
hb_buffer_add_utf16(buffer.get(), reinterpret_cast<const uint16_t *>(text.getBuffer()), text.length(), text_item.start, text_item.end - text_item.start);
hb_buffer_add_utf16(buffer.get(), uchar_to_utf16(text.getBuffer()), text.length(), text_item.start, text_item.end - text_item.start);
hb_buffer_set_direction(buffer.get(), (text_item.rtl == UBIDI_RTL)?HB_DIRECTION_RTL:HB_DIRECTION_LTR);
hb_buffer_set_script(buffer.get(), _icu_script_to_script(text_item.script));
hb_font_t *font(hb_ft_font_create(face->get_face(), nullptr));