textutilities
This commit is contained in:
1 parent
da272f5b49
commit
7ab7dad283
18 files changed
+260
-2
No files matched your search
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,34 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
charheight=25
|
||||||
|
normal=../inputfonts/FreeMono.ttf
|
||||||
|
bold=../inputfonts/FreeMonoBold.ttf
|
||||||
|
italic=../inputfonts/FreeMonoOblique.ttf
|
||||||
|
bolditalic=../inputfonts/FreeMonoBoldOblique.ttf
|
||||||
|
output=../outputfonts/amsmono25.amsfontatlas
|
||||||
|
outputimg=../outputfonts/amsmono25.png
|
||||||
|
|
||||||
|
./amsmakefontatlasv1 $normal $bold $italic $bolditalic $charheight $output
|
||||||
|
./amsdumpfontatlastexture $output $outputimg
|
||||||
|
|
||||||
|
charheight=25
|
||||||
|
normal=../inputfonts/LiberationSans-Regular.ttf
|
||||||
|
bold=../inputfonts/LiberationSans-Bold.ttf
|
||||||
|
italic=../inputfonts/LiberationSans-Italic.ttf
|
||||||
|
bolditalic=../inputfonts/LiberationSans-BoldItalic.ttf
|
||||||
|
output=../outputfonts/amssans25.amsfontatlas
|
||||||
|
outputimg=../outputfonts/amssans25.png
|
||||||
|
|
||||||
|
./amsmakefontatlasv1 $normal $bold $italic $bolditalic $charheight $output
|
||||||
|
./amsdumpfontatlastexture $output $outputimg
|
||||||
|
|
||||||
|
charheight=25
|
||||||
|
normal=../inputfonts/LiberationSerif-Regular.ttf
|
||||||
|
bold=../inputfonts/LiberationSerif-Bold.ttf
|
||||||
|
italic=../inputfonts/LiberationSerif-Italic.ttf
|
||||||
|
bolditalic=../inputfonts/LiberationSerif-BoldItalic.ttf
|
||||||
|
output=../outputfonts/amsserif25.amsfontatlas
|
||||||
|
outputimg=../outputfonts/amsserif25.png
|
||||||
|
|
||||||
|
./amsmakefontatlasv1 $normal $bold $italic $bolditalic $charheight $output
|
||||||
|
./amsdumpfontatlastexture $output $outputimg
|
||||||
Binary file not shown.
@@ -0,0 +1,7 @@
|
|||||||
|
#!/usr/bin/bash
|
||||||
|
|
||||||
|
textfile=./makefont1.sh
|
||||||
|
fontfile=../outputfonts/amsserif25.amsfontatlas
|
||||||
|
outimg=../notes/testrender.png
|
||||||
|
|
||||||
|
./ams_testrendertextfile $textfile $fontfile $outimg
|
||||||
Binary file not shown.
@@ -64,6 +64,15 @@ namespace font4
|
|||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
|
//converts truetype font files to a textureatlas page file
|
||||||
|
void convertfontatlas_v1(int argc, char* argv[]);
|
||||||
|
|
||||||
|
//dumps fontatlas image
|
||||||
|
void dumpfontatlastexture(int argc, char* argv[]);
|
||||||
|
|
||||||
|
//renders a text file as an image
|
||||||
|
void testrendertextfile(int argc, char* argv[]);
|
||||||
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Binary file not shown.
|
After Width: | Height: | Size: 43 KiB |
Binary file not shown.
Binary file not shown.
|
After Width: | Height: | Size: 182 KiB |
Binary file not shown.
Binary file not shown.
|
After Width: | Height: | Size: 238 KiB |
Binary file not shown.
Binary file not shown.
|
After Width: | Height: | Size: 236 KiB |
@@ -0,0 +1,202 @@
|
|||||||
|
#include <amsfontconverter4/amsfontconverter4.hpp>
|
||||||
|
|
||||||
|
namespace ams
|
||||||
|
{
|
||||||
|
namespace font4
|
||||||
|
{
|
||||||
|
|
||||||
|
void convertfontatlas_v1(int argc, char* argv[])
|
||||||
|
{
|
||||||
|
if(argc<7)
|
||||||
|
{
|
||||||
|
printf("amsmakefontatlas v1 use:\n");
|
||||||
|
printf("amsmakefontatlas v1 [normalfont] [boldfont] [italicfont] [bolditalicfont] [charheight (integer)] [outputfile]\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
amsstring fnormal,fbold,fitalic,fbolditalic,fnum,foutput;
|
||||||
|
int charheight;
|
||||||
|
int res;
|
||||||
|
int tft;
|
||||||
|
|
||||||
|
amsfontfamily ff;
|
||||||
|
amsfontatlas fa;
|
||||||
|
amsglyphrange gr;
|
||||||
|
|
||||||
|
fnormal = argv[1];
|
||||||
|
fbold = argv[2];
|
||||||
|
fitalic = argv[3];
|
||||||
|
fbolditalic = argv[4];
|
||||||
|
fnum = argv[5];
|
||||||
|
foutput = argv[6];
|
||||||
|
|
||||||
|
charheight = (int)fnum.strtonum();
|
||||||
|
if(charheight<0)
|
||||||
|
{
|
||||||
|
charheight = 15;
|
||||||
|
}
|
||||||
|
|
||||||
|
//debug
|
||||||
|
// printf("fnormal: %s\nfbold: %s\nfitalic %s\nfbolditalic: %s\ncharheight: %d\nfoutput %s\n",
|
||||||
|
// fnormal.cstring,fbold.cstring,fitalic.cstring,fbolditalic.cstring,charheight,foutput.cstring);
|
||||||
|
|
||||||
|
//Unicode Ranges
|
||||||
|
//https://jrgraphix.net/research/unicode_blocks.php
|
||||||
|
// 0 - 0x07f - basic latin
|
||||||
|
// 0x00a0 - 0x0ff - extended latin
|
||||||
|
// 0x0370 - 0x03ff - greek and coptic
|
||||||
|
// 0x0400 - 0x04ff - cyrillic
|
||||||
|
// 0x0590 - 0x05ff - hebrew
|
||||||
|
|
||||||
|
//Load normal fonts
|
||||||
|
tft = typefacetype_normal;
|
||||||
|
ff.charheight = charheight;
|
||||||
|
res = ft_load_glyphrange(fnormal.cstring,charheight,0,256,&gr);
|
||||||
|
gr.typefacetype = tft; ff.addrange(gr);
|
||||||
|
res = ft_load_glyphrange(fnormal.cstring,charheight,256,512,&gr);
|
||||||
|
gr.typefacetype = tft; ff.addrange(gr);
|
||||||
|
res = ft_load_glyphrange(fnormal.cstring,charheight,0x0370,0x03ff,&gr);
|
||||||
|
gr.typefacetype = tft; ff.addrange(gr);
|
||||||
|
res = ft_load_glyphrange(fnormal.cstring,charheight,0x0470,0x04ff,&gr);
|
||||||
|
gr.typefacetype = tft; ff.addrange(gr);
|
||||||
|
res = ft_load_glyphrange(fnormal.cstring,charheight,0x0590,0x059f,&gr);
|
||||||
|
gr.typefacetype = tft; ff.addrange(gr);
|
||||||
|
|
||||||
|
//Load bold fonts
|
||||||
|
tft = typefacetype_bold;
|
||||||
|
res = ft_load_glyphrange(fbold.cstring,charheight,0,256,&gr);
|
||||||
|
gr.typefacetype = tft; ff.addrange(gr);
|
||||||
|
res = ft_load_glyphrange(fbold.cstring,charheight,256,512,&gr);
|
||||||
|
gr.typefacetype = tft; ff.addrange(gr);
|
||||||
|
res = ft_load_glyphrange(fbold.cstring,charheight,0x0370,0x03ff,&gr);
|
||||||
|
gr.typefacetype = tft; ff.addrange(gr);
|
||||||
|
res = ft_load_glyphrange(fbold.cstring,charheight,0x0470,0x04ff,&gr);
|
||||||
|
gr.typefacetype = tft; ff.addrange(gr);
|
||||||
|
res = ft_load_glyphrange(fbold.cstring,charheight,0x0590,0x059f,&gr);
|
||||||
|
gr.typefacetype = tft; ff.addrange(gr);
|
||||||
|
|
||||||
|
//Load italic fonts
|
||||||
|
tft = typefacetype_italic;
|
||||||
|
res = ft_load_glyphrange(fitalic.cstring,charheight,0,256,&gr);
|
||||||
|
gr.typefacetype = tft; ff.addrange(gr);
|
||||||
|
res = ft_load_glyphrange(fitalic.cstring,charheight,256,512,&gr);
|
||||||
|
gr.typefacetype = tft; ff.addrange(gr);
|
||||||
|
res = ft_load_glyphrange(fitalic.cstring,charheight,0x0370,0x03ff,&gr);
|
||||||
|
gr.typefacetype = tft; ff.addrange(gr);
|
||||||
|
res = ft_load_glyphrange(fitalic.cstring,charheight,0x0470,0x04ff,&gr);
|
||||||
|
gr.typefacetype = tft; ff.addrange(gr);
|
||||||
|
res = ft_load_glyphrange(fitalic.cstring,charheight,0x0590,0x059f,&gr);
|
||||||
|
gr.typefacetype = tft; ff.addrange(gr);
|
||||||
|
|
||||||
|
//Load bolditalic fonts
|
||||||
|
tft = typefacetype_bolditalic;
|
||||||
|
res = ft_load_glyphrange(fbolditalic.cstring,charheight,0,256,&gr);
|
||||||
|
gr.typefacetype = tft; ff.addrange(gr);
|
||||||
|
res = ft_load_glyphrange(fbolditalic.cstring,charheight,256,512,&gr);
|
||||||
|
gr.typefacetype = tft; ff.addrange(gr);
|
||||||
|
res = ft_load_glyphrange(fbolditalic.cstring,charheight,0x0370,0x03ff,&gr);
|
||||||
|
gr.typefacetype = tft; ff.addrange(gr);
|
||||||
|
res = ft_load_glyphrange(fbolditalic.cstring,charheight,0x0470,0x04ff,&gr);
|
||||||
|
gr.typefacetype = tft; ff.addrange(gr);
|
||||||
|
res = ft_load_glyphrange(fbolditalic.cstring,charheight,0x0590,0x059f,&gr);
|
||||||
|
gr.typefacetype = tft; ff.addrange(gr);
|
||||||
|
|
||||||
|
ff.docalculations();
|
||||||
|
ff.build_fontatlas(&fa);
|
||||||
|
fa.rendercontrol.spacewidth = (int)(0.5*(float)charheight);
|
||||||
|
fa.rendercontrol.tabwidth = 3*fa.rendercontrol.spacewidth;
|
||||||
|
|
||||||
|
fa.save(foutput.cstring);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
void dumpfontatlastexture(int argc, char* argv[])
|
||||||
|
{
|
||||||
|
int res;
|
||||||
|
amsstring finput, foutput;
|
||||||
|
amsfontatlas fa;
|
||||||
|
|
||||||
|
if(argc<3)
|
||||||
|
{
|
||||||
|
printf("amsdumpfontatlastexture use:\n");
|
||||||
|
printf("amsdumpfontatlastexture [fontatlasfile in] [imagefile out]\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
finput = argv[1];
|
||||||
|
foutput = argv[2];
|
||||||
|
|
||||||
|
res = fa.load(finput.cstring);
|
||||||
|
if(res!=amsfont4_success)
|
||||||
|
{
|
||||||
|
printf("File %s failed to load.\n",finput.cstring);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
write_image(foutput.cstring,&(fa.texture));
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
void testrendertextfile(int argc, char* argv[])
|
||||||
|
{
|
||||||
|
amsstring ftext, ffont, foutput;
|
||||||
|
amsstring textfiletext;
|
||||||
|
amsfontatlas fa;
|
||||||
|
rendertext_simple_pars pars;
|
||||||
|
|
||||||
|
if(argc<4)
|
||||||
|
{
|
||||||
|
printf("ams_testrendertextfile [textfilename] [fontatlasname] [outputimgname]");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ftext = argv[1];
|
||||||
|
ffont = argv[2];
|
||||||
|
foutput = argv[3];
|
||||||
|
|
||||||
|
FILE *fp = NULL;
|
||||||
|
fp = fopen(ftext.cstring,"r");
|
||||||
|
if(fp==NULL)
|
||||||
|
{
|
||||||
|
printf("error: could not open %s as a textfile.\n",ftext.cstring);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
freadtxtfile(fp,&textfiletext);
|
||||||
|
fclose(fp); fp = NULL;
|
||||||
|
|
||||||
|
|
||||||
|
int res;
|
||||||
|
res = fa.load(ffont.cstring);
|
||||||
|
if(res!=amsfont4_success)
|
||||||
|
{
|
||||||
|
printf("error: could not open %s as a font file.\n",ffont.cstring);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//pars.charheight = fa.charheight;
|
||||||
|
pars.charheight = fa.rendercontrol.lineheight;
|
||||||
|
rendertext_simple_mesh mesh;
|
||||||
|
rendertext_simple(
|
||||||
|
textfiletext,
|
||||||
|
fa,
|
||||||
|
pars,
|
||||||
|
&mesh
|
||||||
|
);
|
||||||
|
|
||||||
|
amsimage img;
|
||||||
|
rendertext_rendertoimg(
|
||||||
|
&mesh, &fa, &img
|
||||||
|
);
|
||||||
|
|
||||||
|
write_image(foutput.cstring,&img);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
};
|
||||||
+8
-2
@@ -5,14 +5,20 @@ using namespace ams::font4;
|
|||||||
int main(int argc, char* argv[])
|
int main(int argc, char* argv[])
|
||||||
{
|
{
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
printf("ams fontconverter4 tests.\n");
|
//printf("ams fontconverter4 tests.\n");
|
||||||
//ams::font4::test_getglyph1();
|
//ams::font4::test_getglyph1();
|
||||||
//ams::font4::test_getglyph2();
|
//ams::font4::test_getglyph2();
|
||||||
//ams::font4::test_facemetrics();
|
//ams::font4::test_facemetrics();
|
||||||
//ams::font4::test_glyphrange_load();
|
//ams::font4::test_glyphrange_load();
|
||||||
|
|
||||||
//test_load_fontfamily1();
|
//test_load_fontfamily1();
|
||||||
test_rendertext_simple1();
|
//test_rendertext_simple1();
|
||||||
|
|
||||||
|
//convertfontatlas_v1(argc,argv);
|
||||||
|
//dumpfontatlastexture(argc,argv);
|
||||||
|
testrendertextfile(argc,argv);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user