CRichText and Custom Font

Login to reply to this topic.
Fri, 2006-10-06 19:22
Joined: 2003-12-20
Forum posts: 85
Hi,,

i have my custom (gdr) font, i want to set it with CRichText Editor. my font is unicode. I found 2 - 3 links but they r not much informative....
can any budy share his/her idea  or code  sample.

Code:

TInt aFileId;
TFileName fileName=_L("c:\\MBSindhiWeb.gdr");
iCoeEnv->ScreenDevice()->AddFile(fileName,aFileId);
CFont *iFont;
CGraphicsDevice* ScreenDevice=iCoeEnv->ScreenDevice();
TFontSpec aFontSpec(fileName,100);
ScreenDevice->GetNearestFontInTwips(iFont,aFontSpec);
TCharFormat charFormat(aFontSpec.iTypeface.iName, aFontSpec.iHeight);

now i want to use  *iFont with CRichText control.

regards
kmsoomro


Sat, 2006-10-07 08:05
Joined: 2005-11-20
Forum posts: 1156
Re: CRichText and Custom Font
CEikRichTextEditor::ApplyCharFormatL is probably what you need.

If you use Forum Search, e.g. for "TCharFormat", you will find a lot of older threads with all kinds of useful information about fonts, characters formats and RichText.

René Brunner

Sat, 2006-10-07 19:03
Joined: 2003-12-20
Forum posts: 85
Re: CRichText and Custom Font


Hi

My font is like Arabic font, but has some additional character set. Editor only displays Unicode value in Arabic format which is by default supported by the emulator and it skips (not display) additional characters of my language: the conclusion that I got is: editor may not load my custom .GDR font.

Code example:

Font path:
Code:
Epoc32\release\wins\urel\z\system\fonts

z\system\fonts\MBSania.gdr

Code:

_LIT(KFontFileName,"MBSania.gdr");


CRichText* text = RichText();
TInt textSize = text->DocumentLength();

TCharFormatMask charFormatMask; // the attribute mask
charFormatMask.SetAttrib(EAttFontTypeface );

TFontSpec aFontSpec(KFontFileName,2);
TCharFormat charFormat(aFontSpec.iTypeface.iName, aFontSpec.iHeight);

text->ApplyCharFormatL(charFormat, charFormatMask,textSize,aText.Length());


Is there any code mistake plz guide me?


Sat, 2006-10-07 20:18
Joined: 2005-11-20
Forum posts: 1156
Re: CRichText and Custom Font
I would first try to check whether the system accepts the font at all before trying to use it in a program.

One way to do this: Copy the font to the device and check whether the FontViewer tool shows the font as installed:
http://newlc.com/FontViewer.html

If not then there is probably something wrong with the font itself.

Btw, I don't think your font will be a "custom" font. As far as I know Symbian treats all the .gdr font files that it finds in the font directories on the available drives in the same way. So if the font file is valid there should be no problem to use it.

I once tried to build a .gdr font file myself and found Symbian to be less than helpful: It just silently ignored the file without giving the smallest hint about what it did not like about it.

Did you consider working with TrueType fonts and a font that supports your script?

René Brunner

Sun, 2006-10-08 09:29
Joined: 2003-12-20
Forum posts: 85
Re: CRichText and Custom Font
i welcome if any one guide/ give me example in True Type Font.

Sun, 2006-10-08 09:50
Joined: 2003-12-20
Forum posts: 85
Re: CRichText and Custom Font
i tested that my font is installed,,

Code:

TTypefaceSupport *typeface;
TInt iFontCount = iCoeEnv->ScreenDevice()->NumTypefaces();
for( TInt i=0;i<iFontCount;i++)
{
typeface = new TTypefaceSupport;
//User::LeaveIfNull(typeface);
iCoeEnv->ScreenDevice()->TypefaceSupport(*typeface,i);
//TBuf<100> a(typeface->iTypeface.iName.Des());
RDebug::Print(_L("type face name(): %S"), &typeface->iTypeface.iName.Des());
//User::LeaveIfError(iFont.Append(typeface));
}



and i got out like this

Code:
type face name(): LatinBold13
type face name(): LatinBold17
type face name(): LatinBold19
type face name(): LatinPlain12
type face name(): Acb14
type face name(): Acb30
type face name(): Acp5
type face name(): MBSania



it shows that my MBSania font is insalled, but to display it.......
Sun, 2006-10-08 13:25
Joined: 2005-11-20
Forum posts: 1156
Re: CRichText and Custom Font
Symbian supports TrueType fonts with the help of a port of Freetype:
http://www.symbian.com/developer/downloads/syslibs.html

However, there seem to be some limits. The UIQ 2.1 emulator that I use has Freetype installed, but a version that does not work with font collections (.ttc files), only fonts (.ttf files), and it does not accept Code2000, a font with a phantastic number of scripts, as I said without telling what's the problem.

René Brunner

Sun, 2006-10-08 13:32
Joined: 2005-11-20
Forum posts: 1156
Re: CRichText and Custom Font
Maybe a good idea to reduce the complexity of the problem, take the RichText stuff out of the loop just for now and try to draw one of the codepoints in question directly by CGraphicsContext::DrawText somewhere, after selecting the font into the context.

René Brunner

  • Login to reply to this topic.