Exemple #1
0
/**
 * Converts one single glyph (character, sign) into LFF.
 */
FT_Error convertGlyph(FT_ULong charcode) {
    FT_Error error;
    FT_Glyph glyph;

    // load glyph
    error = FT_Load_Glyph(face,
                          FT_Get_Char_Index(face, charcode),
                          FT_LOAD_NO_BITMAP | FT_LOAD_NO_SCALE);
    if (error) {
        std::cerr << "FT_Load_Glyph: " << FT_StrError(error) << std::endl;
        return error;
    }

    FT_Get_Glyph(face->glyph, &glyph);
    FT_OutlineGlyph og = (FT_OutlineGlyph)glyph;
    if (face->glyph->format != ft_glyph_format_outline) {
        std::cerr << "Not an outline font\n";
    }

    // write glyph header
    if (fpLff) {
        fprintf(fpLff, "\n[#%04X]\n", (unsigned)charcode);
    }

    // trace outline of the glyph
    xMin = 1000.0;
    firstpass = true;
    error = FT_Outline_Decompose(&(og->outline), &funcs, fpLff);
    firstpass = false;
    startcontour = true;
    error = FT_Outline_Decompose(&(og->outline), &funcs, fpLff);
    if (fpLff) {
        fprintf(fpLff, "\n");
    }

    if (error) {
        std::cerr << "FT_Outline_Decompose: " << FT_StrError(error) << std::endl;
    }

    return error;
}
Exemple #2
0
void 
font_size(const char *str, int unicode, struct font_context *ctx) {
    FT_Face face = ctx->font;
    FT_UInt glyph_index = FT_Get_Char_Index(face, unicode);
	if (!glyph_index) {
		pf_log("cannot find glyph %d\n", unicode);
        // in android \n can not found, just skip render it
		//exit(1);
        ctx->w = 0;
        return;
	}
    FT_Load_Glyph(face, glyph_index, FT_LOAD_NO_BITMAP);
    
    int err = FT_Render_Glyph(face->glyph, FT_RENDER_MODE_NORMAL);
	if (err)
        _fault(err, "render failed");

    FT_GlyphSlot slot = face->glyph;

    ctx->w = slot->advance.x >> 6;
}
Exemple #3
0
int blf_font_count_missing_chars(FontBLF *font, const char *str, const size_t len, int *r_tot_chars)
{
	int missing = 0;
	size_t i = 0;

	*r_tot_chars = 0;
	while (i < len) {
		unsigned int c;

		if ((c = str[i]) < 0x80) {
			i++;
		}
		else if ((c = BLI_str_utf8_as_unicode_step(str, &i)) != BLI_UTF8_ERR) {
			if (FT_Get_Char_Index((font)->face, c) == 0) {
				missing++;
			}
		}
		(*r_tot_chars)++;
	}
	return missing;
}
Exemple #4
0
int
test_get_char_index( btimer_t*  timer,
                     FT_Face    face,
                     void*      user_data )
{
  bcharset_t*  charset = (bcharset_t*)user_data;
  int          i, done = 0;


  TIMER_START( timer );

  for ( i = 0; i < charset->size; i++ )
  {
    if ( FT_Get_Char_Index(face, charset->code[i]) )
      done++;
  }

  TIMER_STOP( timer );

  return done;
}
	void Glyph::Load(FT_Library& library, FT_Face face, FT_ULong charcode, bool hinting)
	{
		int flags = FT_LOAD_DEFAULT;

		if (hinting)
			flags |= FT_LOAD_FORCE_AUTOHINT;
		else
			flags |= FT_LOAD_NO_HINTING | FT_LOAD_NO_AUTOHINT;

		_error = FT_Load_Char(face, charcode, flags);
		if (_error)
			return;

		_error = FT_Load_Glyph(face, FT_Get_Char_Index(face, charcode), flags);
		if (_error)
			return;

		_error = FT_Get_Glyph(face->glyph, &_glyph);
		if (_error)
			return;
	}
Exemple #6
0
ImageHandle FreeTypeFont::createGlyphImage(int codepoint, int fontSize) const
{
    int glyph_index = FT_Get_Char_Index( fontInfo->face, codepoint );

    int error = FT_Set_Pixel_Sizes(
            fontInfo->face,     /* handle to face object */
            0,                  /* pixel_width           */
            fontSize );         /* pixel_height          */

    if ( error )
      LogError("Error setting font size");

    error = FT_Load_Glyph( fontInfo->face, glyph_index, FT_LOAD_RENDER | FT_LOAD_TARGET_LCD);
    if ( error ) 
        LogError("Error loading glyph");

    FT_Glyph  glyph; /* a handle to the glyph image */    

    error = FT_Get_Glyph( fontInfo->face->glyph, &glyph );
    if ( error ) 
        LogError("Error getting glyph");

    FT_Vector  origin;
    origin.x = origin.y = 0;

    error = FT_Glyph_To_Bitmap(
            &glyph,
            FT_RENDER_MODE_LCD,
            &origin,
            1 );

    FT_Bitmap bitmap = ((FT_BitmapGlyph) glyph)->bitmap;

    if (bitmap.width == 0 || bitmap.rows == 0)
        return HandleInvalid;

    auto image = ImageCreate(AllocatorGetHeap(), bitmap.width/3, bitmap.rows, PixelFormat::R8G8B8);
    image.Resolve()->setBuffer(bitmap.buffer, bitmap.pitch);
    return image;
}
Exemple #7
0
int renderFont(void)
{
	FT_Library library; 
	FT_Face face; /* handle to face object */  
	int fontSize = 8;

	//load library:
	int error = FT_Init_FreeType( &library );
	if ( error ) 
		return -1;

	error = FT_Init_FreeType( &library ); 
	if ( error ) 
		return -2;
	
	error = FT_New_Face( library, "FreeSans.ttf", 0, &face ); 
	if ( error == FT_Err_Unknown_File_Format )
		return -3;
	else if ( error )
		return -4;

	error = FT_Set_Pixel_Sizes( face,	/* handle to face object */  
								0,		/* pixel_width */  
								fontSize ); /* pixel_height */ 
	if(error)
		return -5;

	for(char charcode = 'a'; charcode < 'f'; charcode++)
	{
		FT_UInt glyph_index = FT_Get_Char_Index( face, charcode ); 
		error = FT_Load_Glyph( face, glyph_index, 
								0 ); /* load flags */ 
		
		error = FT_Render_Glyph( face->glyph, FT_RENDER_MODE_MONO);
		printSlot(stdout, face->glyph, fontSize);
	}

	slot2bmp("dump.bmp", face->glyph, fontSize);
	return 0;
}
Exemple #8
0
// Freetype - RenderChar
int RenderChar(FT_ULong currentchar, int sx, int sy, int ex, unsigned char *color)
{
	if (currentchar == 32) return;

#ifdef FB8BIT
		int bpp=1;
#else
		int bpp=4;
#endif		
		
	int row, pitch, bit, x = 0, y = 0;
	FT_UInt glyphindex;
	FT_Vector kerning;
	FT_Error error;
	int tmpcolor;

	if(!(glyphindex = FT_Get_Char_Index(face, currentchar)))
	{
		printf("Freetype <FT_Get_Char_Index> fuer Zeichen %x \"%c\" fehlgeschlagen\n", (int)currentchar,(int)currentchar);
		return 0;
	}

#if ((defined(FREETYPE_MAJOR)) && (((FREETYPE_MAJOR == 2) && (((FREETYPE_MINOR == 1) && (FREETYPE_PATCH >= 9)) || (FREETYPE_MINOR > 1))) || (FREETYPE_MAJOR > 2)))
	FTC_Node anode;
	if((error = FTC_SBitCache_Lookup(cache, &desc, glyphindex, &sbit, &anode)))
#else
	if((error = FTC_SBit_Cache_Lookup(cache, &desc, glyphindex, &sbit)))
#endif
	{
		printf("Freetype <FTC_SBitCache_Lookup> fuer Zeichen %x \"%c\" fehlgeschlagen. Fehler: 0x%.2X>\n", (int)currentchar,(int)currentchar, error);
		return 0;
	}
	if(use_kerning)
	{
		FT_Get_Kerning(face, prev_glyphindex, glyphindex, ft_kerning_default, &kerning);

		prev_glyphindex = glyphindex;
		kerning.x >>= 6;
	}
	else
Exemple #9
0
const Glyph& Font::getGlyph(Uint32 codePoint, unsigned int characterSize, bool bold, float outlineThickness) const
{
    // Get the page corresponding to the character size
    GlyphTable& glyphs = m_pages[characterSize].glyphs;

    // Build the key by combining the glyph index (based on code point), bold flag, and outline thickness
    Uint64 key = combine(outlineThickness, bold, FT_Get_Char_Index(static_cast<FT_Face>(m_face), codePoint));

    // Search the glyph into the cache
    GlyphTable::const_iterator it = glyphs.find(key);
    if (it != glyphs.end())
    {
        // Found: just return it
        return it->second;
    }
    else
    {
        // Not found: we have to load it
        Glyph glyph = loadGlyph(codePoint, characterSize, bold, outlineThickness);
        return glyphs.emplace(key, glyph).first->second;
    }
}
Exemple #10
0
void Font::LoadFont(const char * filename, Float size)
{
	baseSize = size;
	//baseSize /= 16.0;

	FT_Face face;

	FT_New_Face(FreeType, filename, 0, &face);
	FT_Set_Char_Size(face, 16 * baseSize, 16 * baseSize, 300, 300); 

	FT_GlyphSlot slot = face->glyph;

	for (uint8 i = 0; i < 128; i++)
	{
		FT_Load_Glyph(face, FT_Get_Char_Index(face, i), FT_LOAD_DEFAULT);
		FT_Render_Glyph(slot, FT_RENDER_MODE_NORMAL);

		width[i] = slot->advance.x >> 6;

		LoadCharacter(face, i);
	}
}
Exemple #11
0
void FontRenderer::print(const wchar_t* _str, euint32 _num_chars, vptr _target, euint32 _x, euint32 _y, euint32 _w)
{
    FT_GlyphSlot slot = m_ft_face->glyph;
    FT_UInt glyph_index;
    FT_UInt error;

    euint32 n;
    m_char_ptr = 0;
    for ( n = 0; n < _num_chars; n++ )
    {
        glyph_index = FT_Get_Char_Index( m_ft_face, _str[n] );

        error = FT_Load_Glyph( m_ft_face, glyph_index, FT_LOAD_DEFAULT );

        if ( error )
        {
            continue;
        }

        /// 加粗函数 FT_Outline_Embolden( &m_ft_face->glyph->outline, 100 );

        error = FT_Render_Glyph( m_ft_face->glyph, FT_RENDER_MODE_NORMAL );

        if ( error )
        {
            continue;
        }

        draw_text( &slot->bitmap, _target, _x, _y, _w);
        if (0xff00 & _str[n])
        {
            m_char_ptr += m_pixel_size;
        }
        else
        {
            m_char_ptr += m_pixel_size/2;
        }
    }
}
Size FontEngine_Freetype::get_size(const std::string &text, int pos)
{
	FT_UInt glyph_index;

	// Get glyph index
	glyph_index = FT_Get_Char_Index(face, text[pos]);

	// Load glyph image
	FT_Error error = FT_Load_Glyph(face, glyph_index, FT_LOAD_DEFAULT );
	if (error) return Size(0,0);

	FT_Glyph glyph;
	FT_BBox bbox;
	FT_Get_Glyph(face->glyph, &glyph);
	FT_Glyph_Get_CBox( glyph, FT_GLYPH_BBOX_PIXELS, &bbox );

	int y = bbox.yMax + bbox.yMin;	// Include the whitespace, to match the windows GetTextExtentPoint32()

	int x = int(face->glyph->advance.x / 64.0f);

	return (Size(x,y));
}
//// begin font_metric private member methods
void xlui::font_metric::calculate() {
	uint32_t *rt = _text.toUCS4(_text);
	FT_GlyphSlot slot = _font_face->glyph;


	int32_t result = FT_Set_Pixel_Sizes(_font_face, 0, _font.get_size());
	if (result == 0) {
		for(uint32_t i = 0; i < _text.get_character_count(); ++i) {
			FT_UInt glyph_index = FT_Get_Char_Index(_font_face, rt[i]);
			FT_Load_Glyph(_font_face, glyph_index, FT_LOAD_DEFAULT);
			uint32_t h = _font_face->glyph->metrics.horiBearingY >> 6;

			if(h > _max_height) {
				_max_height = h;
			}
			_width += _font_face->glyph->metrics.horiAdvance;
		}
	}

	_width >>= 6;
	delete[] rt;
}
Exemple #14
0
void freetype_render_glyph(unsigned charcode)
{
    FT_Error error;
    unsigned glyph_index;

    glyph_index = FT_Get_Char_Index(face, charcode);
    assert(glyph_index != 0);

    error = FT_Load_Glyph(face, glyph_index, FT_LOAD_NO_BITMAP);
    abort_on_error("FreeType", error);

    #ifdef FT_CONFIG_OPTION_SUBPIXEL_RENDERING
    printf("Subpixel rendering is enabled.\n");
    #endif

    if(face->glyph->format != FT_GLYPH_FORMAT_BITMAP)
    {
        printf("Glyph is not bitmap. Rendering...\n");
        error = FT_Render_Glyph(face->glyph, FT_RENDER_MODE_NORMAL);
        abort_on_error("FreeType", error);
    }
}
uint32_t get_ft2_text_width(wchar_t *text, struct ft2_source *srcdata)
{
    FT_GlyphSlot slot = srcdata->font_face->glyph;
    FT_UInt glyph_index = 0;
    uint32_t w = 0, max_w = 0;

    if (!text)
        return 0;

    for (uint32_t i = 0; i < (uint32_t)wcslen(text); i++) {
        glyph_index = FT_Get_Char_Index(srcdata->font_face, text[i]);
        FT_Load_Glyph(srcdata->font_face, glyph_index, FT_LOAD_DEFAULT);

        if (text[i] == L'\n') w = 0;
        else {
            w += slot->advance.x >> 6;
            if (w > max_w) max_w = w;
        }
    }

    return max_w;
}
Exemple #16
0
void kGUIFace::CalcHeight(unsigned int size)
{
	unsigned int c;
	static char largechars[]={"QWpqjy"};
	int glyph_index,above,below,maxabove,maxbelow;

	assert(size<=MAXFONTSIZE,"Size to large!");

	/* -1,-1 = not calculated yet */
	if(m_pixabove[size]!=-1 || m_pixbelow[size]!=-1)
		return;

	maxabove=0;
	maxbelow=0;
	kGUI::SelectFont(this,size);

	for(c=0;c<sizeof(largechars);++c)
	{
		glyph_index = FT_Get_Char_Index( m_ftface, largechars[c] );
		if(glyph_index>0)
		{
			if(FT_Load_Glyph(m_ftface, glyph_index, FT_LOAD_DEFAULT)==0)
			{
				if(FT_Render_Glyph( m_ftface->glyph, ft_render_mode_normal )==0)
				{
					above=m_ftface->glyph->bitmap_top;
					below=m_ftface->glyph->bitmap.rows-above;

					if(above>maxabove)
						maxabove=above;
					if(below>maxbelow)
						maxbelow=below;
				}
			}
		}
	}
	m_pixabove[size]=maxabove;
	m_pixbelow[size]=maxbelow;
}
Exemple #17
0
/**
 * \brief Get maximal font ascender and descender.
 * \param ch character code
 * The values are extracted from the font face that provides glyphs for the given character
 **/
void ass_font_get_asc_desc(ASS_Font *font, uint32_t ch, int *asc,
                           int *desc)
{
    int i;
    for (i = 0; i < font->n_faces; ++i) {
        FT_Face face = font->faces[i];
        TT_OS2 *os2 = FT_Get_Sfnt_Table(face, ft_sfnt_os2);
        if (FT_Get_Char_Index(face, ass_font_index_magic(face, ch))) {
            int y_scale = face->size->metrics.y_scale;
            if (os2) {
                *asc = FT_MulFix((short)os2->usWinAscent, y_scale);
                *desc = FT_MulFix((short)os2->usWinDescent, y_scale);
            } else {
                *asc = FT_MulFix(face->ascender, y_scale);
                *desc = FT_MulFix(-face->descender, y_scale);
            }
            return;
        }
    }

    *asc = *desc = 0;
}
Exemple #18
0
void Font::cacheString(const std::wstring& str) {

    std::vector<uint32> uncached_idx;
    for(wchar_t chr: str) {
        uint32 idx = FT_Get_Char_Index(mFace->face, chr);
        if(idx == 0) {
            continue;
        }
        if(!mGlyphs[idx-1].cached)
            uncached_idx.push_back(idx);
    }

    if(!uncached_idx.empty()) {
        TexturePlacement* placement = this->getTexturePlacement(this->getLastTexturePlacement());
        uint32* texdata = (uint32*)placement->texture->map();

        if(texdata) {
            for(uint32& idx: uncached_idx) {
                FTGlyph& glyph = mGlyphs[idx-1];
                glyph.size = mFontSize;
                if(!glyph.cache(idx, *this, texdata, *placement)) {
                    // texture full, add a new texture
                    placement->texture->unmap();
                    placement = this->appendTexturePlacement();
                    texdata = (uint32*)placement->texture->map();
                    if(!texdata) {
                        log_error(L"Font::cacheString: unable to map texture");
                        break;
                    }
                }
            }

            placement->texture->unmap();
        } else {
            log_error(L"Font::cacheString: unable to map texture");
        }
    }
}
Exemple #19
0
static int font_makeChar( glFontStash *stsh, font_char_t *c, uint32_t ch )
{
   FT_Bitmap bitmap;
   FT_GlyphSlot slot;
   FT_UInt glyph_index;
   int w,h;

   slot = stsh->face->glyph; /* Small shortcut. */

   /* Get glyph index. */
   glyph_index = FT_Get_Char_Index( stsh->face, ch );

   /* Load the glyph. */
   if (FT_Load_Glyph( stsh->face, glyph_index, FT_LOAD_RENDER | FT_LOAD_NO_BITMAP | FT_LOAD_TARGET_NORMAL)) {
      WARN(_("FT_Load_Glyph failed."));
      return -1;
   }

   bitmap = slot->bitmap; /* to simplify */
   if (bitmap.pixel_mode != FT_PIXEL_MODE_GRAY)
      WARN(_("Font '%s' not using FT_PIXEL_MODE_GRAY!"), stsh->fontname);

   /* need the POT wrapping for opengl */
   w = bitmap.width;
   h = bitmap.rows;

   /* Store data. */
   c->data = malloc( sizeof(GLubyte) * w*h );
   memcpy( c->data, bitmap.buffer, sizeof(GLubyte) * w*h );
   c->w     = w;
   c->h     = h;
   c->off_x = slot->bitmap_left;
   c->off_y = slot->bitmap_top;
   c->adv_x = (GLfloat)slot->advance.x / 64.;
   c->adv_y = (GLfloat)slot->advance.y / 64.;

   return 0;
}
Exemple #20
0
bool Selene::CFont::FillCharData(SCharData& data, FT_Face face)
{
	unsigned int glyphIndex = FT_Get_Char_Index(face, data.m_CharCode);
	FT_Error error = FT_Load_Glyph(face, glyphIndex, FT_LOAD_DEFAULT);
	if (error != 0)
	{
		//...
		return false;
	}

	FT_GlyphSlot glyph = face->glyph;
	error = FT_Render_Glyph(glyph, FT_RENDER_MODE_NORMAL);
	if (error != 0)
	{
		//...
		return false;
	}

	// do something with bitmap
	const FT_Bitmap& bitmap = glyph->bitmap;
	int width = bitmap.width; // NextP2(bitmap.width);
	int height = bitmap.rows; // NextP2(bitmap.rows);
	data.m_pData = new unsigned char[width * height * 2];
	for (int j = 0; j < height; j++)
	{
		for (int i = 0; i < width; i++)
		{
			bool inBitmap = i < bitmap.width && j < bitmap.rows;
			data.m_pData[j * width * 2 + i * 2 + 0] = inBitmap ? 255 : 0;
			data.m_pData[j * width * 2 + i * 2 + 1] = inBitmap ? bitmap.buffer[j * bitmap.width + i] : 0;
		}
	}
	data.m_Width = width;
	data.m_Height = height;
	data.m_AdvanceX = glyph->advance.x >> 6;
	data.m_AdvanceY = glyph->advance.y >> 6;
	return true;
}
bool GlyphString::loadGlyphImages(bool useGlyphIndices, bool keepXAdvance)
{

    for (int i = 0; i < mSize; ++i) {
        int glyphIndex;
        if (useGlyphIndices)
            glyphIndex = mGlyphIndices[i];
        else
            glyphIndex = FT_Get_Char_Index(mFace, mCodePoints[i]);

        if (FT_Load_Glyph(mFace, glyphIndex, 0))
            continue;
        if (FT_Render_Glyph(mFace->glyph, FT_RENDER_MODE_NORMAL))
            continue;

        FT_Bitmap bmp = mFace->glyph->bitmap;

        mGlyphIndices[i] = glyphIndex;
        mGeometries[i].top = mFace->glyph->bitmap_top;
        mGeometries[i].left = mFace->glyph->bitmap_left;
        if (!keepXAdvance)
            mGeometries[i].xAdvance = mFace->glyph->advance.x / 64;

        mImages[i] = QImage(bmp.width, bmp.rows, QImage::Format_ARGB32);

        for (int ii = 0; ii < bmp.width; ++ii)
        {
            for (int jj = 0; jj < bmp.rows; ++jj)
                mImages[i].setPixel(ii, jj, qRgba(mFaceColor.red(),
                                                  mFaceColor.green(),
                                                  mFaceColor.blue(),
                                                  bmp.buffer[jj * bmp.pitch + ii]));
        }

    }

    return true;
}
Exemple #22
0
// https://github.com/mapnik/mapnik/issues/2578
double font_face::get_ascender()
{
    set_unscaled_character_sizes();
    unsigned glyph_index = FT_Get_Char_Index(face_, 'X');

    FT_Vector pen;
    pen.x = 0;
    pen.y = 0;
    FT_Set_Transform(face_, 0, &pen);
    int e = 0;
    if (!(e = FT_Load_Glyph(face_, glyph_index, FT_LOAD_NO_HINTING)))
    {
        FT_Glyph image;
        if (!FT_Get_Glyph(face_->glyph, &image))
        {
            FT_BBox glyph_bbox;
            FT_Glyph_Get_CBox(image, FT_GLYPH_BBOX_TRUNCATE, &glyph_bbox);
            FT_Done_Glyph(image);
            return 64.0 * (glyph_bbox.yMax - glyph_bbox.yMin);
        }
    }
    return face_->ascender;
}
Exemple #23
0
void renderGlyph(SDL_Surface *screen, char glyph)
{
	SDL_FillRect(screen, NULL, 0x00000000);
	int error;
   int glyph_index = FT_Get_Char_Index( face, glyph);
   error = FT_Load_Glyph( face, glyph_index, 0 ); // Load 'A' glyph with default parameters (0)
   if(error)
   {
      exit(0);
   }

   error = FT_Render_Glyph( face->glyph, FT_RENDER_MODE_NORMAL ); // Can haz bitmap?

   if(error)
   {
      exit(0); // no can haz bitmap :|
   }

	int i, j;
	for(i = 0; i<face->glyph->bitmap.rows;i++)
		for(j = 0;j<face->glyph->bitmap.width;j++)
			put_pixel(screen,face->glyph->bitmap.buffer[i*face->glyph->bitmap.pitch+j],j,i);
}
/*
 * Class:     sun_font_FreetypeFontScaler
 * Method:    getGlyphCodeNative
 * Signature: (C)I
 */
JNIEXPORT jint JNICALL
Java_sun_font_FreetypeFontScaler_getGlyphCodeNative(
        JNIEnv *env, jobject scaler,
        jobject font2D, jlong pScaler, jchar charCode) {

    FTScalerInfo* scalerInfo = (FTScalerInfo *) jlong_to_ptr(pScaler);
    int errCode;

    if (scaler == NULL || scalerInfo->face == NULL) { /* bad/null scaler */
        invalidateJavaScaler(env, scaler, scalerInfo);
        return 0;
    }

    /* Freetype functions *may* cause callback to java
       that can use cached values. Make sure our cache is up to date.
       Scaler context is not important here, can use NULL. */
    errCode = setupFTContext(env, font2D, scalerInfo, NULL);
    if (errCode) {
        return 0;
    }

    return FT_Get_Char_Index(scalerInfo->face, charCode);
}
Exemple #25
0
char*
ftloadglyph(FTface f, int ix, FTglyph *g)
{
	FT_Face ft_face = f.ft_face;
	FT_GlyphSlot ft_glyph;
	char *err;

	ix = FT_Get_Char_Index(ft_face, ix);
	err = fterrstr(FT_Load_Glyph(ft_face, ix, FT_LOAD_NO_BITMAP|FT_LOAD_RENDER|FT_LOAD_CROP_BITMAP));
	if (err != nil)
		return err;

	ft_glyph = ft_face->glyph;
	g->top = ft_glyph->bitmap_top;
	g->left = ft_glyph->bitmap_left;
	g->height = ft_glyph->bitmap.rows;
	g->width = ft_glyph->bitmap.width;
	g->advx = ft_glyph->advance.x;
	g->advy = ft_glyph->advance.y;
	g->bpr = ft_glyph->bitmap.pitch;
	g->bitmap = ft_glyph->bitmap.buffer;
	return nil;
}
bool FontFreeType::getBBOXFotChar(unsigned short theChar, Rect &outRect)
{
    if (!_fontRef)
        return false;
    
    // get the ID to the char we need
    int glyph_index = FT_Get_Char_Index(_fontRef, theChar);
    
    if (!glyph_index)
        return false;
    
    // load glyph infos
    if (FT_Load_Glyph(_fontRef, glyph_index, FT_LOAD_DEFAULT))
        return false;
    
    // store result in the passed rectangle
    outRect.origin.x    = 0;
    outRect.origin.y    = - (_fontRef->glyph->metrics.horiBearingY >> 6);
    outRect.size.width  =   (_fontRef->glyph->metrics.width  >> 6);
    outRect.size.height =   (_fontRef->glyph->metrics.height >> 6);
    
    return true;
}
void CWin32Font::GetCharABCWidths(int ch, int &a, int &b, int &c)
{
	Assert(IsValid());

	abc_cache_t finder = { (wchar_t)ch };
	unsigned short i = m_ExtendedABCWidthsCache.Find(finder);
	if (m_ExtendedABCWidthsCache.IsValidIndex(i))
	{
		abc_cache_t &cache = m_ExtendedABCWidthsCache[i];
		a = cache.abc.a;
		b = cache.abc.b;
		c = cache.abc.c;
		return;
	}

	unsigned int glyphIndex = FT_Get_Char_Index(m_FTFace, ch);
	if (glyphIndex && !FT_Load_Glyph(m_FTFace, glyphIndex, FT_LOAD_NO_HINTING))
	{
		FT_Glyph_Metrics &metrics = m_FTFace->glyph->metrics;
		a = metrics.horiBearingX >> 6;
		b = (metrics.width + 127) >> 6; // +127 to ceil and to add 1 pixel for anti-aliasing.
		c = (metrics.horiAdvance - metrics.horiBearingX - metrics.width) >> 6;
	}
bool GlyphPage::fill(unsigned offset, unsigned length, UChar* buffer, unsigned bufferLength, const SimpleFontData* fontData)
{
    if (bufferLength > GlyphPage::size)
        return false;

    FT_Face face = fontData->m_font.m_face;

    if (!face)
        return false;

    bool haveGlyphs = false;
    for (unsigned i = 0; i < bufferLength; i++) {
        Glyph glyph = FT_Get_Char_Index(face, buffer[i]);
        if (!glyph)
            setGlyphDataForIndex(i, 0, 0);
        else {
            setGlyphDataForIndex(i, glyph, fontData);
            haveGlyphs = true;
        }
    }

    return haveGlyphs;
}
PRUint32
gfxFT2LockedFace::GetGlyph(PRUint32 aCharCode)
{
    if (NS_UNLIKELY(!mFace))
        return 0;

#ifdef HAVE_FONTCONFIG_FCFREETYPE_H
    // FcFreeTypeCharIndex will search starting from the most recently
    // selected charmap.  This can cause non-determistic behavior when more
    // than one charmap supports a character but with different glyphs, as
    // with older versions of MS Gothic, for example.  Always prefer a Unicode
    // charmap, if there is one.  (FcFreeTypeCharIndex usually does the
    // appropriate Unicode conversion, but some fonts have non-Roman glyphs
    // for FT_ENCODING_APPLE_ROMAN characters.)
    if (!mFace->charmap || mFace->charmap->encoding != FT_ENCODING_UNICODE) {
        FT_Select_Charmap(mFace, FT_ENCODING_UNICODE);
    }

    return FcFreeTypeCharIndex(mFace, aCharCode);
#else
    return FT_Get_Char_Index(mFace, aCharCode);
#endif
}
Exemple #30
0
static PyObject*
supports_text(Face *self, PyObject *args) {
    PyObject *chars, *fast, *ret = Py_True;
    Py_ssize_t sz, i;
    FT_ULong code;

    if (!PyArg_ParseTuple(args, "O", &chars)) return NULL;
    fast = PySequence_Fast(chars, "List of chars is not a sequence");
    if (fast == NULL) return NULL;
    sz = PySequence_Fast_GET_SIZE(fast);

    for (i = 0; i < sz; i++) {
        code = (FT_ULong)PyNumber_AsSsize_t(PySequence_Fast_GET_ITEM(fast, i), NULL);
        if (FT_Get_Char_Index(self->face, code) == 0) {
            ret = Py_False;
            break;
        }
    }

    Py_DECREF(fast);
    Py_XINCREF(ret);
    return ret;
}