Пример #1
0
/**
 * takes a utf16 string and runs Harfbuzz to create a list of glyphs
 *
 * @param aContext     void context
 * @param aUtf16String the utf16 string
 * @param aHarfBuzz    structure containing Harfbuzz stuff
 * @return             error
 */
static int Utf16_To_Harfbuzz( void       *aContext,
                              uint16_t   *aUtf16String,
                              int         nChars,
                              HarfBuzz_t *aHarfBuzz ) {
   ft_Context_t *ftContext = FT_CONTEXT( aContext );
   HB_FontRec    hbFont;
   HB_Face       hbFace = NULL;
   HB_ShaperItem hbShaperItem;

   memset( aHarfBuzz->str,             0, sizeof( aHarfBuzz->str ) );
   memset( aHarfBuzz->out_glyphs,      0, sizeof( aHarfBuzz->out_glyphs ) );
   memset( aHarfBuzz->out_attrs,       0, sizeof( aHarfBuzz->out_attrs ) );
   memset( aHarfBuzz->out_advs,        0, sizeof( aHarfBuzz->out_advs ) );
   memset( aHarfBuzz->out_offsets,     0, sizeof( aHarfBuzz->out_offsets ) );
   memset( aHarfBuzz->out_logClusters, 0, sizeof( aHarfBuzz->out_logClusters ) );

   memset( &hbFont,                    0, sizeof( HB_FontRec ) );
   memset( &hbFace,                    0, sizeof( HB_Face ) );

   hbFace = HB_NewFace( ftContext->m_face, hb_freetype_table_sfnt_get );

   memcpy( aHarfBuzz->str, aUtf16String, nChars * sizeof( uint16_t ) );

   aHarfBuzz->n_Chars = nChars;

   assert( ftContext->m_face != NULL );

   hbFont.klass    = &hb_freetype_class;
   hbFont.userData = ftContext->m_face;
   hbFont.x_ppem   = ftContext->m_face->size->metrics.x_ppem;
   hbFont.y_ppem   = ftContext->m_face->size->metrics.y_ppem;
   hbFont.x_scale  = ftContext->m_face->size->metrics.x_scale;
   hbFont.y_scale  = ftContext->m_face->size->metrics.y_scale;

   memset( &hbShaperItem, 0, sizeof( HB_ShaperItem ) );

   hbShaperItem.kerning_applied     = FALSE;
   hbShaperItem.string              = ( HB_UChar16 * )aHarfBuzz->str;
   hbShaperItem.stringLength        = nChars;
   hbShaperItem.item.bidiLevel      = 0;
   hbShaperItem.item.script         = HB_Script_Arabic;
   hbShaperItem.item.pos            = 0;
   hbShaperItem.item.length         = hbShaperItem.stringLength;
   hbShaperItem.shaperFlags         = 0;
   hbShaperItem.font                = &hbFont;
   hbShaperItem.face                = hbFace;
   hbShaperItem.glyphIndicesPresent = FALSE;
   hbShaperItem.initialGlyphCount   = 0;
   hbShaperItem.glyphs              = aHarfBuzz->out_glyphs;
   hbShaperItem.attributes          = aHarfBuzz->out_attrs;
   hbShaperItem.advances            = aHarfBuzz->out_advs;
   hbShaperItem.offsets             = aHarfBuzz->out_offsets;
   hbShaperItem.log_clusters        = aHarfBuzz->out_logClusters;
   hbShaperItem.num_glyphs          = MAX_CHARS;

   HB_ShapeItem( &hbShaperItem );
   HB_FreeFace( hbFace );

   return 0;
}
HB_FaceRec_* FontPlatformData::harfbuzzFace() const
{
    if (!m_harfbuzzFace)
        m_harfbuzzFace = RefCountedHarfbuzzFace::create(HB_NewFace(const_cast<FontPlatformData*>(this), harfbuzzSkiaGetTable));

    return m_harfbuzzFace->face();
}
Пример #3
0
/**
    The FT_Face should be initialized already in scribus, but I can't access it!!!

    based on tests/fuzzing/fuzz.cc
 */
ShaperFontInfo::ShaperFontInfo(ScFace scface, qreal size)
{
    face = 0;
    FT_Library library = 0;
    // XXX: deal with error
    bool error = FT_Init_FreeType(&library);
    if(error)
    {
        qDebug() << "error initing FT library";
    }
    // qDebug() << "font file:" << scface.fontFilePath();
    error = FT_New_Face(library, 
            scface.fontFilePath().toUtf8().data(), 
            scface.faceIndex(), &face);
    if(error)
    {
        qDebug() << "error loading FT font?";
    }
    error = FT_Set_Char_Size(face, 0, 10, 72, 72); // XXX: not sure what should I put here!! fonts/ftface puts 10 for the size, why?
    if(error)
    {
        qDebug() << "error setting font size";
    }
    hbFace = HB_NewFace(face, hb_freetype_table_sfnt_get);
    hbFont.klass = &hb_freetype_class;
    hbFont.userData = face;
    hbFont.x_ppem  = face->size->metrics.x_ppem;
    hbFont.y_ppem  = face->size->metrics.y_ppem;
    hbFont.x_scale = face->size->metrics.x_scale;
    hbFont.y_scale = face->size->metrics.y_scale;
}
Пример #4
0
HB_FaceRec_* FontPlatformData::harfbuzzFace() const
{
#ifdef SUPPORT_COMPLEX_SCRIPTS
    if (!m_harfbuzzFace)
        m_harfbuzzFace = RefCountedHarfbuzzFace::create(
            HB_NewFace(const_cast<FontPlatformData*>(this), harfbuzzSkiaGetTable));

    return m_harfbuzzFace->face();
#else
    return NULL;
#endif
}
Пример #5
0
 void setupFontForScriptRun()
 {
     const FontData* fontData = m_font->fontDataAt(0);
     if (!fontData->containsCharacters(m_item.string + m_item.item.pos, m_item.item.length))
         fontData = m_font->fontDataForCharacters(m_item.string + m_item.item.pos, m_item.item.length);
     const FontPlatformData& platformData = fontData->fontDataForCharacter(' ')->platformData();
     void* opaquePlatformData = const_cast<FontPlatformData*>(&platformData);
     m_item.font->userData = opaquePlatformData;
     if (m_item.face)
         HB_FreeFace(m_item.face);
     m_item.face = HB_NewFace(opaquePlatformData, harfbuzzSkiaGetTable);
 }
Пример #6
0
Shaper::Shaper(FT_Face face, HB_Script script, const QString &str)
{
    HB_Face hbFace = HB_NewFace(face, hb_getSFntTable);

    hbFont.klass = &hb_fontClass;
    hbFont.userData = face;
    hbFont.x_ppem  = face->size->metrics.x_ppem;
    hbFont.y_ppem  = face->size->metrics.y_ppem;
    hbFont.x_scale = face->size->metrics.x_scale;
    hbFont.y_scale = face->size->metrics.y_scale;

    shaper_item.kerning_applied = false;
    shaper_item.string = reinterpret_cast<const HB_UChar16 *>(str.constData());
    shaper_item.stringLength = str.length();
    shaper_item.item.script = script;
    shaper_item.item.pos = 0;
    shaper_item.item.length = shaper_item.stringLength;
    shaper_item.item.bidiLevel = 0; // ###
    shaper_item.shaperFlags = 0;
    shaper_item.font = &hbFont;
    shaper_item.face = hbFace;
    shaper_item.num_glyphs = shaper_item.item.length;
    shaper_item.glyphIndicesPresent = false;
    shaper_item.initialGlyphCount = 0;


    while (1) {
        hb_glyphs.resize(shaper_item.num_glyphs);
        hb_attributes.resize(shaper_item.num_glyphs);
        hb_advances.resize(shaper_item.num_glyphs);
        hb_offsets.resize(shaper_item.num_glyphs);
        hb_logClusters.resize(shaper_item.num_glyphs);

        memset(hb_glyphs.data(), 0, hb_glyphs.size() * sizeof(HB_Glyph));
        memset(hb_attributes.data(), 0, hb_attributes.size() * sizeof(HB_GlyphAttributes));
        memset(hb_advances.data(), 0, hb_advances.size() * sizeof(HB_Fixed));
        memset(hb_offsets.data(), 0, hb_offsets.size() * sizeof(HB_FixedPoint));

        shaper_item.glyphs = hb_glyphs.data();
        shaper_item.attributes = hb_attributes.data();
        shaper_item.advances = hb_advances.data();
        shaper_item.offsets = hb_offsets.data();
        shaper_item.log_clusters = hb_logClusters.data();

        if (HB_ShapeItem(&shaper_item))
            break;
    }

    HB_FreeFace(hbFace);
}
Пример #7
0
bool FMShaper::setFont (/*FT_Face face, HB_Font font  */)
{
	HB_Face hbFace = HB_NewFace(anchorOTF->_face, hb_getSFntTable);
	HB_Font hbFont = new HB_FontRec;
	
	
	hbFont->klass = anchorOTF->hbFont.klass ;
	hbFont->userData = anchorOTF->hbFont.userData;
	hbFont->x_ppem  = anchorOTF->hbFont.x_ppem;
	hbFont->y_ppem  = anchorOTF->hbFont.y_ppem;
	hbFont->x_scale = anchorOTF->hbFont.x_scale;
	hbFont->y_scale = anchorOTF->hbFont.y_scale;
	m.font = hbFont;
	m.face = hbFace;
	
	anchorFace = anchorOTF->_face;
	faceisset = true;
	return faceisset;
}
Пример #8
0
HB_Face qHBNewFace(void *font, HB_GetFontTableFunc tableFunc)
{
    return HB_NewFace(font, tableFunc);
}