updates
This commit is contained in:
1 parent
5c9f70268a
commit
422307e0bc
11 files changed
+5506
-10
No files matched your search
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -20,11 +20,13 @@ namespace ams
|
||||
namespace font4
|
||||
{
|
||||
|
||||
static const int fontconverter4_success = 1;
|
||||
static const int fontconverter4_failure = -1;
|
||||
|
||||
//Class intended to open and load a single freetype font-face (single file)
|
||||
//Loads glyphs and glyph metrics from .ttf and .otf files using the Freetype library.
|
||||
class freetype_fontfaceloader
|
||||
{
|
||||
//Class intended to open and load a single freetype font-face (single file)
|
||||
//Loads glyphs and glyph metrics from .ttf and .otf files using the Freetype library.
|
||||
class freetype_fontfaceloader
|
||||
{
|
||||
public:
|
||||
freetype_fontfaceloader();
|
||||
~freetype_fontfaceloader();
|
||||
@@ -42,11 +44,16 @@ class freetype_fontfaceloader
|
||||
bool hasglyph(uint32_t charind);
|
||||
int getglyph(uint32_t charind, int charheight, amsbitplane *glyph, amsglyphmetrics *glyphmetrics);
|
||||
|
||||
facemetrics getfacemetrics(int charheight);
|
||||
|
||||
//loads the set of glyphs into memory for the font-face
|
||||
//performs no other calculations
|
||||
//void load_amsface(uint32_t charindmin, uint32_t charindmax, int targetcharheight, amsfontface *fface);
|
||||
};
|
||||
int load_glyphrange(
|
||||
int charheight,
|
||||
uint32_t charindmin,
|
||||
uint32_t charindmax,
|
||||
amsglyphrange *glyphrange_out
|
||||
);
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -56,6 +63,9 @@ class freetype_fontfaceloader
|
||||
|
||||
void test_printglyph(amsbitplane *glyph);
|
||||
void test_getglyph1();
|
||||
void test_getglyph2();
|
||||
void test_facemetrics();
|
||||
void test_glyphrange_load();
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
@@ -88,6 +88,8 @@ int freetype_fontfaceloader::getglyph(uint32_t charind, int charheight, amsbitpl
|
||||
|
||||
int I,J;
|
||||
|
||||
*metrics = amsglyphmetrics();
|
||||
|
||||
if(bopen)
|
||||
{
|
||||
|
||||
@@ -112,6 +114,14 @@ int freetype_fontfaceloader::getglyph(uint32_t charind, int charheight, amsbitpl
|
||||
metrics->height = slot->bitmap.rows;
|
||||
metrics->xbearing = face->glyph->metrics.horiBearingX/64;
|
||||
metrics->ybearing = face->glyph->metrics.horiBearingY/64;
|
||||
metrics->hadvance = face->glyph->metrics.horiAdvance/64;
|
||||
if(FT_HAS_VERTICAL(face))
|
||||
{
|
||||
metrics->hasvertical = 1;
|
||||
metrics->vxbearing = face->glyph->metrics.vertBearingX/64;
|
||||
metrics->vybearing = face->glyph->metrics.vertBearingY/64;
|
||||
metrics->vadvance = face->glyph->metrics.vertAdvance/64;
|
||||
}
|
||||
metrics->haschar = 1;
|
||||
|
||||
glyph->resize(metrics->width, metrics->height);
|
||||
@@ -156,5 +166,88 @@ int freetype_fontfaceloader::getglyph(uint32_t charind, int charheight, amsbitpl
|
||||
return ret;
|
||||
}
|
||||
|
||||
facemetrics freetype_fontfaceloader::getfacemetrics(int charheight)
|
||||
{
|
||||
facemetrics ret = facemetrics();
|
||||
|
||||
FT_Matrix matrix;
|
||||
FT_Vector pen;
|
||||
FT_Error error;
|
||||
|
||||
|
||||
|
||||
if(bopen)
|
||||
{
|
||||
matrix.xx = (FT_Fixed)( cos( 0.0 ) * 0x10000L );
|
||||
matrix.xy = (FT_Fixed)(-sin( 0.0 ) * 0x10000L );
|
||||
matrix.yx = (FT_Fixed)( sin( 0.0 ) * 0x10000L );
|
||||
matrix.yy = (FT_Fixed)( cos( 0.0 ) * 0x10000L );
|
||||
|
||||
pen.x = 0;
|
||||
pen.y = 0;
|
||||
FT_Set_Char_Size(face,charheight*64,0,100,0);
|
||||
FT_Set_Transform(face,&matrix,&pen);
|
||||
|
||||
ret.ascender = face->size->metrics.ascender/64;
|
||||
ret.descender = face->size->metrics.descender/64;
|
||||
ret.max_advance = face->size->metrics.max_advance/64;
|
||||
ret.height = face->size->metrics.height/64;
|
||||
}
|
||||
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int freetype_fontfaceloader::load_glyphrange(
|
||||
int charheight,
|
||||
uint32_t charindmin,
|
||||
uint32_t charindmax,
|
||||
amsglyphrange *glyphrange_out
|
||||
)
|
||||
{
|
||||
int ret = fontconverter4_success;
|
||||
int64_t I;
|
||||
|
||||
if(glyphrange_out==NULL)
|
||||
{
|
||||
ret = fontconverter4_failure;
|
||||
return ret;
|
||||
}
|
||||
|
||||
*glyphrange_out = amsglyphrange();
|
||||
|
||||
if(bopen)
|
||||
{
|
||||
charindmax = (charindmax<charindmin) ? charindmin : charindmax;
|
||||
|
||||
glyphrange_out->charheight = charheight;
|
||||
glyphrange_out->charindmin = charindmin;
|
||||
glyphrange_out->charindmax = charindmax;
|
||||
glyphrange_out->fontfacemetrics = getfacemetrics(charheight);
|
||||
|
||||
glyphrange_out->metrics.resize(charindmax-charindmin);
|
||||
glyphrange_out->glyphs.resize(charindmax-charindmin);
|
||||
|
||||
for(I=charindmin;I<charindmax;I++)
|
||||
{
|
||||
getglyph(
|
||||
(uint32_t) I,
|
||||
charheight,
|
||||
&(glyphrange_out->glyphs[I]),
|
||||
&(glyphrange_out->metrics[I])
|
||||
);
|
||||
}
|
||||
|
||||
glyphrange_out->docalculations();
|
||||
}
|
||||
else
|
||||
{
|
||||
ret = fontconverter4_failure;
|
||||
return ret;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
};
|
||||
};
|
||||
@@ -37,7 +37,7 @@ void test_getglyph1()
|
||||
}
|
||||
|
||||
I = 70;
|
||||
I = 511;
|
||||
//I = 511;
|
||||
ftload.getglyph((uint32_t) I,(uint32_t) charheight,&ggg,&gm);
|
||||
gm.print();
|
||||
test_printglyph(&ggg);
|
||||
@@ -45,5 +45,80 @@ void test_getglyph1()
|
||||
ftload.close();
|
||||
}
|
||||
|
||||
void test_getglyph2()
|
||||
{
|
||||
int res;
|
||||
int I;
|
||||
const char *fname = "../inputfonts/LiberationSerif-BoldItalic.ttf";
|
||||
freetype_fontfaceloader ftload;
|
||||
amsbitplane glyph;
|
||||
amsglyphmetrics gm;
|
||||
int charheight = 30;
|
||||
|
||||
ftload.open(fname);
|
||||
|
||||
printf("Font metrics for %s\n",fname);
|
||||
for(I=0;I<256;I++)
|
||||
{
|
||||
res = ftload.getglyph(I,charheight,&glyph, &gm);
|
||||
printf("char: %d, res: %d\n",I,res);
|
||||
if(I>=32 && I<127)
|
||||
{
|
||||
printf("ascii: %c\n",(char)(unsigned char)I);
|
||||
}
|
||||
printf("glyphmetrics: \n");
|
||||
gm.print();
|
||||
|
||||
}
|
||||
|
||||
ftload.close();
|
||||
return;
|
||||
}
|
||||
|
||||
void test_facemetrics()
|
||||
{
|
||||
int res;
|
||||
int I;
|
||||
const char *fname = "../inputfonts/LiberationSerif-BoldItalic.ttf";
|
||||
freetype_fontfaceloader ftload;
|
||||
facemetrics fm;
|
||||
int charheight = 128;
|
||||
|
||||
ftload.open(fname);
|
||||
|
||||
printf("Face metrics for %s\n",fname);
|
||||
fm = ftload.getfacemetrics(charheight);
|
||||
fm.print();
|
||||
|
||||
ftload.close();
|
||||
return;
|
||||
}
|
||||
|
||||
void test_glyphrange_load()
|
||||
{
|
||||
int res;
|
||||
int I;
|
||||
const char *fname = "../inputfonts/LiberationSerif-BoldItalic.ttf";
|
||||
uint32_t charindmin = 0;
|
||||
uint32_t charindmax = 512;
|
||||
|
||||
freetype_fontfaceloader ftload;
|
||||
amsglyphrange font;
|
||||
|
||||
int charheight = 128;
|
||||
|
||||
ftload.open(fname);
|
||||
|
||||
ftload.load_glyphrange(
|
||||
charheight,charindmin,charindmax,&font
|
||||
);
|
||||
|
||||
font.print();
|
||||
|
||||
ftload.close();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
};
|
||||
};
|
||||
+5
-1
@@ -4,6 +4,10 @@ int main(int argc, char* argv[])
|
||||
{
|
||||
int ret = 0;
|
||||
printf("ams fontconverter4 tests.\n");
|
||||
ams::font4::test_getglyph1();
|
||||
//ams::font4::test_getglyph1();
|
||||
//ams::font4::test_getglyph2();
|
||||
//ams::font4::test_facemetrics();
|
||||
ams::font4::test_glyphrange_load();
|
||||
|
||||
return ret;
|
||||
}
|
||||
Reference in new issue
Block a user