Recent

Author Topic: windows mobile and wince fonts  (Read 19916 times)

zariq

  • Full Member
  • ***
  • Posts: 109
windows mobile and wince fonts
« on: November 26, 2010, 02:37:11 am »
Hi.

I would like to know if anyone has been able to to get lazarus programs to use fonts other than Tahoma and Courier in wince(windows mobile). This question has been asked a few times before but hasn't been answered.

I would like to use a complex right to left script but just the two default fonts seem to be availabe. It can't be a wince problem because office mobile and visual studio programs can use any font in the the windows\font folder.

If not many people are using lazarus for wince then it might not be worth while putting a lot of effort into it but text display is arguably one of the most important aspects of a program and this problem could do with a solution.

Thanks.

felipemdc

  • Administrator
  • Hero Member
  • *
  • Posts: 3538
Re: windows mobile and wince fonts
« Reply #1 on: November 29, 2010, 10:35:05 pm »
You should try using Windows APIs to interact with TCanvas.Handle to load the desired font and then paint it to the canvas. It should be rather easy. Then we can compare to see which options you used and why the LCL is using wrong options to load fonts.

Zaher

  • Hero Member
  • *****
  • Posts: 683
    • parmaja.org
Re: windows mobile and wince fonts
« Reply #2 on: November 29, 2010, 10:54:02 pm »
Hi, Felipe, did you tried SynEdit in WinCE?
I also have problem with it, i tried to look inside the synedit but i failed.

felipemdc

  • Administrator
  • Hero Member
  • *
  • Posts: 3538
Re: windows mobile and wince fonts
« Reply #3 on: November 29, 2010, 11:10:30 pm »
No, I've never tryed it. Which problem do you have exactly?

Zaher

  • Hero Member
  • *****
  • Posts: 683
    • parmaja.org
Re: windows mobile and wince fonts
« Reply #4 on: November 29, 2010, 11:32:53 pm »
https://sourceforge.net/project/screenshots.php?group_id=191784&ssid=109452
Fixed font width not calculated correct, i can not catch the real problem, i think you can try it.

zariq

  • Full Member
  • ***
  • Posts: 109
Re: windows mobile and wince fonts
« Reply #5 on: November 30, 2010, 11:22:55 pm »
I found the following code in the forum which works with different fonts. I changed the code to work with a stringgrid and removed some unwanted stuff.

http://www.lazarus.freepascal.org/index.php/topic,8855.msg42853.html#msg42853


Code: [Select]
procedure TForm1.Button1Click(Sender: TObject);
var I, TextLen: Longint;
     lf: LOGFONT;
     f: HFONT;
begin
    FillChar(lf,SizeOf(lf),0);
    lf.lfFaceName:= 'font name';
    lf.lfHeight := stringgrid1.Font.Height;
    lf.lfWeight := FW_NORMAL;
    f := CreateFontIndirect(lf);
    if (f <> 0) then
    begin
      try
        stringgrid1.Canvas.Handle := GetDC(stringgrid1.Handle);
        SelectObject(stringgrid1.Canvas.Handle,f);
        stringgrid1.Canvas.TextOut(10,10,'}Æ');
      finally
        ReleaseDC(stringgrid1.Handle, stringgrid1.Canvas.Handle);
        DeleteObject(f);
      end;
    end;
end;

It only works with the textout procedure. Using the cells property doen't work.

felipemdc

  • Administrator
  • Hero Member
  • *
  • Posts: 3538
Re: windows mobile and wince fonts
« Reply #6 on: December 01, 2010, 01:56:45 pm »
You should select the original font back.

OldFontHandle := SelectObject(stringgrid1.Canvas.Handle,f);
....
SelectObject(stringgrid1.Canvas.Handle, OldFontHandle);

Also, I would paint in the OnPaint event, if it is possible.

zariq

  • Full Member
  • ***
  • Posts: 109
Re: windows mobile and wince fonts
« Reply #7 on: December 08, 2010, 10:22:40 pm »
The following procedure is showing the font I wanted to use. I haven't tested with other fonts, actually hasn't been tested much at all. Attachment show it running on windows mobile 6 phone.

Code: [Select]
procedure TForm1.StringGrid1DrawCell(Sender: TObject; aCol, aRow: Integer;
  aRect: TRect; aState: TGridDrawState);
var  lf: LOGFONT;
     f: HFONT;
     oldfonthandle: HFONT;
begin
    StringGrid1.Canvas.Brush.Style:=bsSolid;
    stringgrid1.canvas.Brush.Color := stringgrid1.Color;
    stringgrid1.canvas.FillRect(aRect);

    if (arow < 3) then
    begin
        FillChar(lf,SizeOf(lf),0);
        lf.lfFaceName:= 'Urdu Web';
        lf.lfHeight := stringgrid1.Font.Height;
        f := CreateFontIndirect(lf);
        if (f <> 0) then
        begin
           try
              stringgrid1.canvas.Font.Color:= clred;
              OldFontHandle := SelectObject(stringgrid1.Canvas.Handle,f);
              stringgrid1.Canvas.textrect(arect,aRect.Left+2,aRect.Top+2,stringgrid1.cells[acol,arow]);
           finally
              SelectObject(stringgrid1.Canvas.Handle, OldFontHandle);
              DeleteObject(f);
           end;
        end;
    end
    else
    begin
       stringgrid1.canvas.Font.Color:= clblue;
       stringgrid1.Canvas.textrect(arect,aRect.Left+2,aRect.Top+2,stringgrid1.cells[acol,arow]);
    end;
end;


felipemdc

  • Administrator
  • Hero Member
  • *
  • Posts: 3538
Re: windows mobile and wince fonts
« Reply #8 on: December 10, 2010, 11:05:06 am »
https://sourceforge.net/project/screenshots.php?group_id=191784&ssid=109452
Fixed font width not calculated correct, i can not catch the real problem, i think you can try it.

Could you add this to the bug tracker?

Aha, this is just the old issue with the selection of fonts. Simply the used font is not monospaced, if you use @ it won't be over spaced.

Something needs to be fixed to improve the font selection, but I'm not sure what...
« Last Edit: December 10, 2010, 12:51:35 pm by felipemdc »

zariq

  • Full Member
  • ***
  • Posts: 109
Re: windows mobile and wince fonts
« Reply #9 on: December 10, 2010, 02:15:19 pm »
I'm gettting some strange behaviour when trying to fill the the grid from a file and displaying it.

I have an editor which uses the urdu font but it only saves in rich text. So to test the procedure I copy and pasted some text into notepad and saved it as a text file. I read that file into the stringgrid when the program starts, but it only shows a couple of the letters correctly, the rest get replaced by question marks. If I copy and paste the actual text from the editor into a variable and display that variable in the ondrawcell event then it displays correctly. It needs to be copy pasted because that seems to copy extra characters which are needed. These extra characters are not visible in the lazarus editor, but the variable seems to have them when the program is running. The contents of the file and the stringgrid are the same, but that doesn't seem to be enough to display the font. This behaviour is the same is windows xp and windows mobile.

Funny thing is if I run the program in delphi the letters get displayed properly. Notepad and wordpad load and display the file properly. I suppose I could add the extra charcters when reading the file but the pattern of the added character/s doesn't seem to be regular.

felipemdc

  • Administrator
  • Hero Member
  • *
  • Posts: 3538
Re: windows mobile and wince fonts
« Reply #10 on: December 10, 2010, 03:12:37 pm »
Could you provide a file with the problematic text?

PS: And an example application which loads it and shows the issue too.
« Last Edit: December 11, 2010, 11:59:44 am by felipemdc »

felipemdc

  • Administrator
  • Hero Member
  • *
  • Posts: 3538
Re: windows mobile and wince fonts
« Reply #11 on: December 11, 2010, 12:00:45 pm »
Aha, this is just the old issue with the selection of fonts. Simply the used font is not monospaced, if you use @ it won't be over spaced.

Something needs to be fixed to improve the font selection, but I'm not sure what...

In the mean time you can solve this by figuring out a TFont set of properties which will select Courier. Set SynEdit.Font. I'm not sure which set of properties will work at the moment...

zariq

  • Full Member
  • ***
  • Posts: 109
Re: windows mobile and wince fonts
« Reply #12 on: December 11, 2010, 10:17:58 pm »
Hi.

I have posted the project and two pictures.  The first shows the output from lazarus and the other is from the same program compiled in delphi with the letters showing correctly.

the first, third,seventh, ninth, eleventh and twelfth letters are displayed correctly, the others are backwards question marks(right to left font). When displaying characters from the file, the stringgrid obviously contains just the letters which were read, but when the characters are copy pasted to a variable then when the program is running the variable has ascii 195 character between some of the letters. I have also icluded the link to where the font can be downloaded. I didn't post the font because the creators ask that the font not be distributed but downloaded from their website.

http://www.isc.com.au/webfonts/urduweb.htm

Zaher

  • Hero Member
  • *****
  • Posts: 683
    • parmaja.org
Re: windows mobile and wince fonts
« Reply #13 on: December 11, 2010, 10:39:41 pm »
zariq: urduwords.txt is Ansi not UTF-8 change it and try again.

zariq

  • Full Member
  • ***
  • Posts: 109
Re: windows mobile and wince fonts
« Reply #14 on: December 12, 2010, 01:12:37 am »

Thanks Zaher that did the trick. It show correctly on the pc and windows mobile. I assumed that, since the font is not unicode and that i'm using shortstrings, the encoding wouldn't matter.

Is there any way to deal with the file as it is or do I have to learn utf8 or use a converter instead?


 

TinyPortal © 2005-2018