__
This commit is contained in:
@@ -2,6 +2,9 @@
|
||||
#define STB_TRUETYPE_IMPLEMENTATION // force following include to generate implementation
|
||||
#include <renderd7/external/stb_truetype.h>
|
||||
|
||||
#define STB_IMAGE_WRITE_IMPLEMENTATION
|
||||
#include <renderd7/external/stb_image_write.h>
|
||||
|
||||
RenderD7::NFontApi::NFontApi()
|
||||
{
|
||||
|
||||
@@ -32,39 +35,42 @@ void RenderD7::NFontApi::LoadTTF(std::string path)
|
||||
return;
|
||||
}
|
||||
status+="success!\n";
|
||||
b_h = 128;
|
||||
b_w = 512;
|
||||
l_h = 24; /* line height */
|
||||
scale = stbtt_ScaleForPixelHeight(&font, l_h);
|
||||
|
||||
stbtt_GetFontVMetrics(&font, &ascent,&decent,0);
|
||||
stbtt_GetFontVMetrics(&font, &ascent,&decent,&linegap);
|
||||
linespace = scale * (ascent - decent + linegap);
|
||||
|
||||
baseline = (int) (ascent*scale);
|
||||
height = (int) ((ascent - decent)*scale);
|
||||
|
||||
}
|
||||
|
||||
std::vector<unsigned char> RenderD7::NFontApi::GetGlyphBitmap(int glyph)
|
||||
unsigned char* RenderD7::NFontApi::GetGlyphBitmap(char glyph)
|
||||
{
|
||||
stbtt_GetGlyphBitmapBox(&font, glyph, scale, scale, &x0, &y0, &x1, &y1);
|
||||
//stbtt_GetGlyphBitmapBox(&font, glyph, scale, scale, &x0, &y0, &x1, &y1);
|
||||
stbtt_GetCodepointBitmapBox(&font, glyph, scale, scale, &x0, &y0, &x1, &y1);
|
||||
w = x1-x0;
|
||||
h = y1-y0;
|
||||
|
||||
std::vector<unsigned char> bitmap;
|
||||
bitmap.resize(h*w);
|
||||
stbtt_MakeGlyphBitmap(&font, bitmap.data(), w, h, w, scale, scale, glyph);
|
||||
unsigned char* bitmap;
|
||||
bitmap = stbtt_GetCodepointBitmap(&font, scale, scale, glyph, &w, &h, 0, 0);
|
||||
return bitmap;
|
||||
}
|
||||
|
||||
int RenderD7::NFontApi::GetGlyphHeight(int glyph)
|
||||
int RenderD7::NFontApi::GetGlyphHeight(char glyph)
|
||||
{
|
||||
stbtt_GetGlyphBitmapBox(&font, glyph, scale, scale, &x0, &y0, &x1, &y1);
|
||||
stbtt_GetCodepointBitmapBox(&font, glyph, scale, scale, &x0, &y0, &x1, &y1);
|
||||
w = x1-x0;
|
||||
h = y1-y0;
|
||||
return h;
|
||||
}
|
||||
|
||||
int RenderD7::NFontApi::GetGlyphWidth(int glyph)
|
||||
int RenderD7::NFontApi::GetGlyphWidth(char glyph)
|
||||
{
|
||||
stbtt_GetGlyphBitmapBox(&font, glyph, scale, scale, &x0, &y0, &x1, &y1);
|
||||
stbtt_GetCodepointBitmapBox(&font, glyph, scale, scale, &x0, &y0, &x1, &y1);
|
||||
w = x1-x0;
|
||||
h = y1-y0;
|
||||
return w;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user