how can I change the font for CEikRichTextEditor
| Tue, 2008-04-29 12:01 | |
|
I am developing application on A1000 UIQ2.1. However the phone I use only has English. The code i use is as follows: _LIT(chineseFont, "C:\\system\\fonts\\chinese.gdr"); In the ConstructL the code is: TFontSpec fontSpec(chineseFont,16); TCharFormatMask iCharFormatMask; iCharFormat.iFontSpec.iTypeface=fontSpec.iTypeface; richTextEditor ->ApplyCharFormatL(iCharFormat,iCharFormatMask); The code pass the compile but when debug, it fail to run TFontSpec fontSpec(chineseFont,16); can someone help to solve the problem? Thanks in advance. |
|






Forum posts: 1058
There are several problems with your code:
The TFontSpec constructor does not want a file name, it wants a font facename. You have to find out the facename of your font and pass that to TFontSpec.
TFontSpec wants the font size in 1/20 points, i.e. in twips. Don't pass it 16, pass it 16*20 for a 16 point font.
In iCharFormatMask you set only the EAttFontHeight attribute, but you want not only to set font height, but also the typeface. You need the corresponding flag as well.
By the way, it would be better to work with a CCharFormatLayer that you construct yourself. If you use CGlobalText::SetGlobalCharFormat, after you got the CGlobalText that is the base of the RichTextEditor, by using something like
CGlobalText* iGlobalText=(CGlobalText*)(iRichTextEditor->Text());the new font becomes something like the default font for that particular control, automatically used for any new text that you type.
René Brunner
Forum posts: 13
Thanks for your quick reply.
I see the mistake I made, by searching the internet, I do not find the facename of the chinese.gdr. I am now trying to find another font along with its facename. Besides, I will take your advice and try to use the CGlobalText::SetGlobalCharFormat.
I will let you know how it goes. Thanks again : )
Forum posts: 1058
Maybe good to know: There are freeware utilities that are able to show you all installed fonts, with their facename. This is not only useful in cases like your case now where you don't know yet the facename, it's also useful to verify that UIQ really did accept the font that you tried to install. If UIQ does not like a font file, it does not give you an error message, but just silently ignores the font, and later you scratch your head why on earth your program is not able to select the font - it simply is not there, as far as UIQ is concerned.
One such utility you can find here:
http://www.dishneau.com/symbian/UIQFont.htm
René Brunner
Forum posts: 13
Oh, that's wonderful.
Actually, as I am using a phone bought in EU, so there is no chinese font installed for sure. The chinese font inside the phone are installed by installing an sis application, which allows the pen to write chinese characters. By using the Fontviewer, it shows me:
Chinese Calendar
FixedHeight - FixedWidth
and I am wondering whether it is the facename of the chinese.gdr. As I am not in the company, I am not able to test it today. I will let you know tomorrow.
Besides, I found the code to print the facename in NewLC, as follows.
http://www.newlc.com/topic-16251
I will try that as well. Now I am a little more confident that things are going to work. Thanks
Forum posts: 1058
Uh, "Chinese Calendar" does not sound too good.
If you get problems with that font: I myself am using a font called SimSun (I am sure that this is the facename), contained in a font file simsun.ttf, that is more or less in the public domain. You can download the font e.g. here:
http://www.vietnamtourism.com/c_pages/font/simsum.htm
Looks ok for Hanzi. However as a TrueType font, it needs the FreeType font renderer, as I explained in some other thread about fonts.
René Brunner
Forum posts: 13
Hi René,
Now i back to work from the holiday. And I replace the code
_LIT(chineseFont, "Chinese Calendar");
and it works now. So the Chinese Calendar is the facename of the font.
Now I encounter another problem about the descriptor. The code is as follows:
void CSMS4CCR2AppUi:: ShowTextL(CEikEdwin& aTextControl)
{
aTextControl.Text()->Reset();
RFileBuf fileBuf;
fullPath.Copy(KFilename); //give the file name
GetFullPathName(fullPath); //combine the filename and path
if(fileBuf.Open(iEikonEnv->FsSession(),fullPath,EFileRead) == EFileRead)
{
CleanupClosePushL(fileBuf);
RReadStream input(&fileBuf);
CleanupClosePushL(input);
CPlainText::TImportExportParam params;
params.iGuessForeignEncoding = ETrue;
CPlainText::TImportExportResult result;
TRAPD(error, aTextControl.Text()->ImportTextL(0,input,params,result));
if(error != KErrNone)
{
UpdateInstruction(_L("Importtext fails!"));
}
//aTextControl.Text()->Extract(fullPath,12);
CleanupStack::PopAndDestroy(2); // input, fileBuf
//aTextControl.SetTextL(&*fullPath);
HBufC *text = NULL;
text=aTextControl.GetTextInHBufL();
//text=aTextControl.Text();
aTextControl.SetTextL(text);
aTextControl.NotifyNewDocumentL(); // Formats and draws a new document, updates scrollbars if necessary
aTextControl.UpdateAllFieldsL(); // Updates all the fields in the document
delete text;
}
else
{
UpdateInstruction(_L("cannot find file"));
}
}
As I have some chinese characters in the txt file(in utf8 format), I tried ConverToUnicode and it's not working. It works with me now by using ImportTextL which convert the characters internally.
What i want now is to get the aTextControl.Text() into an descriptor and pass some of them to the function aTextControl.SetTextL(const TDesC* aDes).
For example, there are 5 chars in the descriptor and I only want the 3rd char.
Can you help me with that? I am not good at descriptor at all.
Forum posts: 1058
Hard to say why ConvertToUnicode() did not work for you; as far as I remember it should be the right method to call for UTF-8 to UTF-16 conversion. Anyway, if your ImportTextL trick works, so far so good.
For extracting parts of a descriptor have a look at TDesC::Mid().
René Brunner
Forum posts: 13
Hi René,
Thanks for your quick reply.
I have get all the converted chars by the code
aTextControl.Text()->Extract(fullPath,0);
Then I show one char by using the method you suggest and it works.
aTextControl.SetTextL(&fullPath.Mid(12,1));
Now the question is to show the 2nd and 5th character at one line.
For example, I need to show fullPath.Mid(2,1) and fullPath.Mid(5,1) at one line. So the combine of the characters shall be done.
Do you have better solution to use?
So far, I solve it by declare another TBuf <50> testString;
testString.Append(fullPath[2]);
testString.Append(fullPath[5]);
aTextControl.SetTextL(&testString);