RadaeePDF.com :: Topic: How to add font file to radaee library (1/2)
Welcome, Guest
Username: Password: Remember me

Signin/Signup with:

Questions about Android development and PDF
  • Page:
  • 1
  • 2

TOPIC: How to add font file to radaee library

How to add font file to radaee library 2 years 6 months ago #8315

  • asliyanage
  • asliyanage's Avatar
  • OFFLINE
  • Expert Boarder
  • Posts: 105
  • Karma: 0
I need to add new font file.How to add this with radaee library ?
The topic has been locked.

How to add font file to radaee library 2 years 6 months ago #8318

  • nermeen
  • nermeen's Avatar
  • OFFLINE
  • Moderator
  • Posts: 659
  • Thank you received: 38
  • Karma: 17
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:
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) {
	}
}
3. Add your font to the font list between fontfileListStart() and fontfileListEnd() as follows:
fontfileListStart();
…
fontfileListAdd(fontPath);
…
fontfileListEnd();
4. Add font mapping (if-necessary).
fontfileMapping("Times”, “Times New Roman");

You can check font name list after fontfileListEnd() like:
String face_name = null;
int face_first = 0;
int face_count = getFaceCount();
while (face_first < face_count) {
	face_name = getFaceName(face_first);
	face_first++;
}
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.
The topic has been locked.

How to add font file to radaee library 2 years 6 months ago #8321

  • asliyanage
  • asliyanage's Avatar
  • OFFLINE
  • Expert Boarder
  • Posts: 105
  • Karma: 0
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 ?
Last Edit: 2 years 6 months ago by Docrishav.
The topic has been locked.

How to add font file to radaee library 2 years 6 months ago #8324

  • asliyanage
  • asliyanage's Avatar
  • OFFLINE
  • Expert Boarder
  • Posts: 105
  • Karma: 0
HI Radaee,

Could you please look into this issue?

Regards,
Sameera
The topic has been locked.

How to add font file to radaee library 2 years 6 months ago #8329

  • radaee
  • radaee's Avatar
  • OFFLINE
  • Moderator
  • Posts: 825
  • Thank you received: 10
  • Karma: 43
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:
	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)
			{
			}
		}
	}
The topic has been locked.

How to add font file to radaee library 2 years 6 months ago #8330

  • radaee
  • radaee's Avatar
  • OFFLINE
  • Moderator
  • Posts: 825
  • Thank you received: 10
  • Karma: 43
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") );
The topic has been locked.
  • Page:
  • 1
  • 2
Powered by Kunena Forum