- Posts: 100
- Thank you received: 0
Microsoft Windows Phone 8.1 support ends (13 Jul 2017)
Microsoft has ended support for Windows Phone 8.1
Questions about Android development and PDF
How to add font file to radaee library
- asliyanage
- Topic Author
- Offline
- Premium Member
-
Less
More
IP: 192.168.0.71
11 years 2 months ago #8315
by asliyanage
How to add font file to radaee library was created by asliyanage
I need to add new font file.How to add this with radaee library ?
IP: 192.168.0.135
11 years 2 months ago #8318
by nermeen
Replied by nermeen on topic How to add font file to radaee library
The steps (for example to add “Times New Roman”) are:
1. Download the font and add it to the assets folder.
2. In com.radaee.pdf.Global.Init(), copy the font to the internal storage, as follows:
3. Add your font to the font list between fontfileListStart() and fontfileListEnd() as follows:
4. Add font mapping (if-necessary).
You can check font name list after fontfileListEnd() like:
When you don't know which font to use in PDF file, you can invoke Document.SetFontDel() to set font delegate, to map a font name to a font path.
1. Download the font and add it to the assets folder.
2. In com.radaee.pdf.Global.Init(), copy the font to the internal storage, as follows:
Code:
String fontPath = act.getFilesDir().getAbsolutePath() + "/times.ttf";
sub = new File(fontPath);
if (!sub.exists()) {
try {
InputStream src;
FileOutputStream dst = new FileOutputStream(sub);
src = assets.open("fonts/times.ttf");
while ((read = src.read(buf)) > 0) {
dst.write(buf, 0, read);
}
src.close();
src = null;
dst.close();
dst = null;
} catch (Exception e) {
}
}
Code:
fontfileListStart();
…
fontfileListAdd(fontPath);
…
fontfileListEnd();
Code:
fontfileMapping("Times”, “Times New Roman");
You can check font name list after fontfileListEnd() like:
Code:
String face_name = null;
int face_first = 0;
int face_count = getFaceCount();
while (face_first < face_count) {
face_name = getFaceName(face_first);
face_first++;
}
- asliyanage
- Topic Author
- Offline
- Premium Member
-
Less
More
- Posts: 100
- Thank you received: 0
IP: 192.168.0.71
11 years 2 months ago - 11 years 2 months ago #8321
by asliyanage
Replied by asliyanage on topic How to add font file to radaee library
Assets folder mean which Assets folder?
Library Assets or my app Assets folder ?
1)I added below method to Global class
private static void addFont(Activity act,AssetManager assets) {
String fontPath = act.getFilesDir().getAbsolutePath() + "/TimeRoman.ttf";
int read;
File sub = new File(fontPath);
byte buf[] = new byte[4096];
if (!sub.exists()) {
try {
InputStream src;
FileOutputStream dst = new FileOutputStream(sub);
src = assets.open("fonts/times.ttf");
while ((read = src.read(buf)) > 0) {
dst.write(buf, 0, read);
}
src.close();
src = null;
dst.close();
dst = null;
} catch (Exception e) {
}
}
2)Then i calling the method inside Init.
AssetManager assets = act.getAssets();
addFont(act,assets);
3)Then i added below to Init method
fontfileListStart();
String fontPath = act.getFilesDir().getAbsolutePath() + "/TimeRoman.ttf";
fontfileListAdd(fontPath);
fontfileListEnd();
Then i add below to init method
int face_first = 0;
int face_count = getFaceCount();
String face_name = null;
while (face_first < face_count) {
face_name = getFaceName(face_first);
face_first++;
}
But it doesn't show me the TimeRoman font name ?
...............................
Also i checked the /data/data/com.example.wtest/files folder using adb command(in debug mode) ,then i saw the font file is there.But it doesn't show me the list ?
Library Assets or my app Assets folder ?
1)I added below method to Global class
private static void addFont(Activity act,AssetManager assets) {
String fontPath = act.getFilesDir().getAbsolutePath() + "/TimeRoman.ttf";
int read;
File sub = new File(fontPath);
byte buf[] = new byte[4096];
if (!sub.exists()) {
try {
InputStream src;
FileOutputStream dst = new FileOutputStream(sub);
src = assets.open("fonts/times.ttf");
while ((read = src.read(buf)) > 0) {
dst.write(buf, 0, read);
}
src.close();
src = null;
dst.close();
dst = null;
} catch (Exception e) {
}
}
2)Then i calling the method inside Init.
AssetManager assets = act.getAssets();
addFont(act,assets);
3)Then i added below to Init method
fontfileListStart();
String fontPath = act.getFilesDir().getAbsolutePath() + "/TimeRoman.ttf";
fontfileListAdd(fontPath);
fontfileListEnd();
Then i add below to init method
int face_first = 0;
int face_count = getFaceCount();
String face_name = null;
while (face_first < face_count) {
face_name = getFaceName(face_first);
face_first++;
}
But it doesn't show me the TimeRoman font name ?
...............................
Also i checked the /data/data/com.example.wtest/files folder using adb command(in debug mode) ,then i saw the font file is there.But it doesn't show me the list ?
Last edit: 11 years 2 months ago by Docrishav.
- asliyanage
- Topic Author
- Offline
- Premium Member
-
Less
More
- Posts: 100
- Thank you received: 0
IP: 192.168.0.71
11 years 2 months ago #8324
by asliyanage
Replied by asliyanage on topic How to add font file to radaee library
HI Radaee,
Could you please look into this issue?
Regards,
Sameera
Could you please look into this issue?
Regards,
Sameera
IP: 192.168.0.71
11 years 2 months ago #8329
by radaee
Replied by radaee on topic How to add font file to radaee library
assets in ViewLib shall not linked to package.
so, it is better place font in res/raw in ViewLib.
and load font in res/raw("res" subdir in ViewLib and "raw" subdir in "res") by these codes:
so, it is better place font in res/raw in ViewLib.
and load font in res/raw("res" subdir in ViewLib and "raw" subdir in "res") by these codes:
Code:
static private void load_file(Resources res, int res_id, File save_file)
{
if( !save_file.exists() )
{
try
{
int read;
byte buf[] = new byte[4096];
InputStream src = res.openRawResource(res_id );
FileOutputStream dst = new FileOutputStream( save_file );
while( (read = src.read( buf )) > 0 )
dst.write( buf, 0, read );
dst.close();
src.close();
dst = null;
src = null;
}
catch(Exception e)
{
}
}
}
IP: 192.168.0.71
11 years 2 months ago #8330
by radaee
Replied by radaee on topic How to add font file to radaee library
fot times.ttf in "res/raw" may renamed ID as R.raw.times.
like this:
load_cmyk_icc( res, R.raw.cmyk_rgb, new File(files, "cmyk_rgb") );
like this:
load_cmyk_icc( res, R.raw.cmyk_rgb, new File(files, "cmyk_rgb") );
Time to create page: 0.619 seconds