Пример #1
0
int __stdcall picture(char *text, char *buffer, char *screen1, int width, int height)
{

 //unsigned char *screen;
 //screen=zmalloc(20*78); 
	//kol_board_puts(screen);
	//kol_board_puts("It was text\n");
	
stbtt_fontinfo font;
   int i,j,ascent,baseline,descent,ch=0;
   float scale, xpos=0;
   
   //baseline=10;
   kol_board_puts("Font address:\n");
   //kol_board_puti(buffer);
 if (buffer==-1) {stbtt_InitFont(&font, pdf_font_DroidSans,stbtt_GetFontOffsetForIndex(pdf_font_DroidSans,0) );kol_board_puts("default font\n");} else {stbtt_InitFont(&font, buffer,stbtt_GetFontOffsetForIndex(buffer,0) );kol_board_puts("Font loaded..\n");}

//kol_board_puti(&screen);
   scale = stbtt_ScaleForPixelHeight(&font, height*3/4);
   //stbtt_GetFontVMetrics(&font, &ascent,0,0);
   stbtt_GetFontVMetrics(&font, &ascent,&descent,0); //lev
   //baseline = (int) (ascent*scale);
   baseline = (int) ((ascent-descent)*scale); //lev


//kol_board_puts("Text render:\n");

   while (dos2utf(text[ch])) {
	   //kol_board_puts("new symbol...\n");
      int advance,lsb,x0,y0,x1,y1;
      //float x_shift = xpos - (float) i_floor(xpos);
      
     // kol_board_puts("floor called!\n");
      stbtt_GetCodepointHMetrics(&font, dos2utf(text[ch]), &advance, &lsb);
      stbtt_GetCodepointBitmapBoxSubpixel(&font, dos2utf(text[ch]), scale,scale,0,0, &x0,&y0,&x1,&y1);


     //10= y0, 20=y1-y0 or so
      stbtt_MakeCodepointBitmapSubpixel(&font, &screen1[(baseline + y0)*width+ (int)xpos + x0], x1-x0,y1-y0, width, scale,scale,0,0, dos2utf(text[ch]));
       
      // note that this stomps the old data, so where character boxes overlap (e.g. 'lj') it's wrong
      // because this API is really for baking character bitmaps into textures. if you want to do this,
      // you need to render the bitmap to a temp buffer, then\n\t"alpha blend" that into the working buffer
      xpos += (advance * scale);
      if (text[ch+1])
         xpos += scale*stbtt_GetCodepointKernAdvance(&font, dos2utf(text[ch]),dos2utf(text[ch+1]));
      ++ch;
   }
   
  //zmemcpy(screen1,bitmap,20*20);

//kol_board_puts("finished...\n");
return 0;
}
Пример #2
0
bool TruetypeFont::renderGlyph(char32_t c)
{
    bool result = false;
    GlyphPtr glyph = char2glyph[c];
    if(!glyph)
    {
        result = true;
        glyph.reset(new Glyph);
//    glyph->render(face, size, c);

        int advance, lsb;
        stbtt_GetCodepointHMetrics(_fontinfo, c, &advance, &lsb);

        int ix0, iy0, ix1, iy1;
        stbtt_GetCodepointBitmapBox(_fontinfo, c, _vscale, _vscale, &ix0, &iy0, &ix1, &iy1);
        int width = ix1-ix0;
        int height = iy1-iy0;
        unsigned char* bmpmem = (unsigned char*)malloc(width*height);
        stbtt_MakeCodepointBitmapSubpixel(_fontinfo, bmpmem, width, height, width, _vscale, _vscale, .0, .0, c);

        BitmapPtr result(new Bitmap(width,
                                    height,
                                    GL_RGBA,
                                    GL_ALPHA,
                                    bmpmem));
        result->flip();
        free(bmpmem);
        glyph->bitmap = result;
        glyph->advance = floorf(advance*_vscale);
        glyph->xoffset = floorf(lsb*_vscale);
        glyph->yoffset = -iy1;

        char2glyph[c] = glyph;
        glyphs.push_back(glyph);
    }
    return result;
}