Recent

Author Topic: FPImage Font problem with Persian characters  (Read 27073 times)

Sanem

  • Full Member
  • ***
  • Posts: 173
Re: FPImage Font problem with Persian characters
« Reply #15 on: May 28, 2016, 04:30:08 pm »
thank you so much for the sample code
i tested the code in my lazarus and i got this error in screenshot, actually i dont know any thing about this libraries, so if you could give me some resources to read about them and see if they fit my project needs.
thanks a lot

engkin

  • Hero Member
  • *****
  • Posts: 3112
Re: FPImage Font problem with Persian characters
« Reply #16 on: May 28, 2016, 05:51:00 pm »
HarfBuzz does not provide all the needed libraries for that example. It is Pango/PangoCairo one. Plus different versions might not work. I ran it inside GTK 2.0 bin folder. The result is the attached pdf file.

Graeme

  • Hero Member
  • *****
  • Posts: 1428
    • Graeme on the web
Re: FPImage Font problem with Persian characters
« Reply #17 on: May 28, 2016, 08:29:32 pm »
FreeType is able of rendering individual glyphs and a few languages, but it does not support Arabic. It is stated in their website:
Quote
but not other complex scripts like Arabic.

And that quote is from 2014.

Here is another quote from their website (homepage) mentioning Arabic support.
Quote
FreeType 2.6
2015-06-08

FreeType 2.6 has been released. This is a new major release that provides a better (and simpler) thread-safety model. Among other new features we now have auto-hinting support for Arabic and Thai, together with much improved handling of Apple's GX TrueType variation font format.

;-)
« Last Edit: May 29, 2016, 01:32:12 pm by Graeme »
--
fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal
http://fpgui.sourceforge.net/

engkin

  • Hero Member
  • *****
  • Posts: 3112
Re: FPImage Font problem with Persian characters
« Reply #18 on: May 28, 2016, 09:35:27 pm »
You are RIGHT!!

Sanem

  • Full Member
  • ***
  • Posts: 173
Re: FPImage Font problem with Persian characters
« Reply #19 on: May 29, 2016, 01:28:20 pm »
So?!
if freetype does support arabic why it doesnt work in my code??
is it something about lazarus packages? because i tested it in LCL and it worked!

Code: Pascal  [Select][+][-]
  1. program project1;
  2.  
  3. uses
  4.   Classes,
  5.   SysUtils,
  6.   FPimage,
  7.   FPImgCanv,
  8.   ftfont,
  9.   FPWritePNG,
  10.   FPCanvas,
  11.   lconvencoding,
  12.   LazUTF8;
  13.  
  14.   procedure TestFPImgFont;
  15.   var
  16.     Img: TFPMemoryImage;
  17.     ImgCanvas: TFPImageCanvas;
  18.     AFont: TFreeTypeFont;
  19.     s: string;
  20.   begin
  21.     Img := nil;
  22.     ImgCanvas := nil;
  23.     AFont := nil;
  24.     try
  25.       // initialize free type font manager
  26.       ftfont.InitEngine;
  27.       FontMgr.SearchPath := ExtractFilePath(ParamStr(0));
  28.       AFont := TFreeTypeFont.Create;
  29.       // create an image of width 200, height 100
  30.       Img := TFPMemoryImage.Create(200, 100);
  31.       Img.UsePalette := False;
  32.       // create the canvas with the drawing operations
  33.       ImgCanvas := TFPImageCanvas.Create(Img);
  34.       // paint white background
  35.       ImgCanvas.Brush.FPColor := colWhite;
  36.       ImgCanvas.Brush.Style := bsSolid;
  37.       ImgCanvas.Rectangle(0, 0, Img.Width, Img.Height);
  38.       // paint text
  39.       ImgCanvas.Font := AFont;
  40.       ImgCanvas.Font.Name := 'B Titr';
  41.       ImgCanvas.Font.Size := 20;
  42.       s := 'فارسی';
  43.  
  44.       ImgCanvas.TextOut(10, 30, UTF8ToCP1256(s));
  45.       ImgCanvas.Image.SaveToFile('Pics/1.png');
  46.     finally
  47.       AFont.Free;
  48.       ImgCanvas.Free;
  49.       Img.Free;
  50.     end;
  51.   end;
  52.  
  53. begin
  54.   TestFPImgFont;
  55. end.
  56.  

Graeme

  • Hero Member
  • *****
  • Posts: 1428
    • Graeme on the web
Re: FPImage Font problem with Persian characters
« Reply #20 on: May 29, 2016, 01:37:12 pm »
When using LCL, you are offloading most of the work to the backend toolkits (Win32, GTK2 or Qt), and they obviously know how to handle Right-to-Left languages. So when using FPImage and FreeType directly, it seems there is an extra step required - note my post about data order (eg: text string) versus display order. The LCL backend toolkits obviously do the display order work for you.

What I do find weird in your output of FPImage+FreeText is that you only see rectangles. With AggPas output I at least see the correct font glyphs, just not in the right order.

[edit]
I did some more google searching. FreeType is about extracting glyph information from a font file and applying hinting, kerning etc. Text layouting is done by another library or your application. Here is some FreeType information about various text layouting methods and what steps are required. This link takes you directly to the Right-to-Left text layouting information.
  http://freetype.sourceforge.net/freetype2/docs/glyphs/glyphs-5.html#section-4
« Last Edit: May 29, 2016, 01:46:07 pm by Graeme »
--
fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal
http://fpgui.sourceforge.net/

Sanem

  • Full Member
  • ***
  • Posts: 173
Re: FPImage Font problem with Persian characters
« Reply #21 on: May 29, 2016, 02:09:17 pm »
Can i see the code you mean from your aggpas output?
because when i used BGRAbitmap i got same Result, as you can see in screenshot.

Regards
« Last Edit: May 29, 2016, 02:11:43 pm by simin_sh »

benohb

  • Full Member
  • ***
  • Posts: 213
Re: FPImage Font problem with Persian characters
« Reply #22 on: May 30, 2016, 09:51:30 am »
Hello simin_sh  ..  :D lock at attachments  (minibidi)
Add the file in your project folder + (uses ....minibidi;)

vae:WideString;
...
 vae:=UTF8Decode('السلام عليكم');
  BidiString(vae,[bdoApplyShape],bdnArabic,bdpDefault,bdlNone);
 vae:=UTF8Encode(vae);
  writeln(vae);
« Last Edit: May 30, 2016, 09:53:24 am by benohb »

Graeme

  • Hero Member
  • *****
  • Posts: 1428
    • Graeme on the web
Re: FPImage Font problem with Persian characters
« Reply #23 on: May 30, 2016, 11:45:08 am »
... look at attachments  (minibidi)
Many thanks. That seems to do the trick - mostly. Some combining characters (where the baseline changes) is not yet supported (see attachment), but it is much better already.

Where is the minibidi code being maintained (URL), so I can link to it, or get occasional updates?
« Last Edit: May 30, 2016, 11:48:47 am by Graeme »
--
fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal
http://fpgui.sourceforge.net/

Sanem

  • Full Member
  • ***
  • Posts: 173
Re: FPImage Font problem with Persian characters
« Reply #24 on: May 31, 2016, 09:11:47 am »
Thank you benohb for your replay, but as you can see my code and screenshot below, still showing ?????? instead of perian charachters!

Code: Pascal  [Select][+][-]
  1. program project1;
  2.  
  3. uses minibidi;
  4.  
  5. var
  6.   vae: WideString;
  7. begin
  8.   vae := UTF8Decode('السلام عليكم');
  9.   BidiString(vae, [bdoApplyShape], bdnArabic, bdpDefault, bdlNone);
  10.   vae := UTF8Encode(vae);
  11.   writeln(vae);
  12.   ReadLn;
  13. end.
  14.  
  15.  

Graeme

  • Hero Member
  • *****
  • Posts: 1428
    • Graeme on the web
Re: FPImage Font problem with Persian characters
« Reply #25 on: May 31, 2016, 10:33:39 am »
but as you can see my code and screenshot below, still showing ?????? instead of perian charachters!
You are doing a lot of things "wrong" in that code.

  • You are not specifying the compiler mode. Some compiler modes do string handling different to others. eg: {$mode objfpc} or {$mode delphi} etc. I believe Free Pascal still defaults to the TP mode which is the old DOS Turbo Pascal mode.
  • You are not specifying how the compiler should interpret the generic String type. eg: {$H+}. FPC 3.0 also supports some DelphiString mode I believe
  • You are using writeln() to test your results. The console window can have a different encoding to your application, so you or need to change the encoding of the console window, or re-encode the string to match that of the console window. Search the help, I can't remember the function to call for this.
  • You are outputing to the console window, but what font does the console window use? Thus does that font include the Persian glyphs you are trying to display?
  • You are using a WideString type without enabling the widestring manager. eg: cwstring in the uses clause.
« Last Edit: May 31, 2016, 10:38:13 am by Graeme »
--
fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal
http://fpgui.sourceforge.net/

engkin

  • Hero Member
  • *****
  • Posts: 3112
Re: FPImage Font problem with Persian characters
« Reply #26 on: May 31, 2016, 08:48:49 pm »
... look at attachments  (minibidi)
Many thanks. That seems to do the trick - mostly. Some combining characters (where the baseline changes) is not yet supported (see attachment), but it is much better already.

Two trivial changes are needed to add support for the rest of the characters:
1-Constant SHAPE_LAST needs a new value #$06D2
2-Extend ShapeTypes array range to 0..177 and remove the comment at its end.

engkin

  • Hero Member
  • *****
  • Posts: 3112
Re: FPImage Font problem with Persian characters
« Reply #27 on: May 31, 2016, 08:55:53 pm »
You are using a WideString type without enabling the widestring manager. eg: cwstring in the uses clause.

Isn't cwstring for *nix only? simin_sh is using Windows.

benohb

  • Full Member
  • ***
  • Posts: 213
Re: FPImage Font problem with Persian characters
« Reply #28 on: June 02, 2016, 07:09:50 am »
simin_sh .Graeme
Quote
Where is the minibidi code being maintained (URL), so I can link to it, or get occasional updates?
No link (dead). I've downloaded it over 3 years ago  :(   .
Person
https://github.com/zaher?tab=repositories


We will improve it.(TASHKIL+missing)
Quote
Thank you benohb for your replay, but as you can see my code and screenshot below, still showing ?????? instead of perian charachters!
My system debian linux 64 bit
I think the problem in code page .

Sanem

  • Full Member
  • ***
  • Posts: 173
Re: FPImage Font problem with Persian characters
« Reply #29 on: June 02, 2016, 10:47:32 am »
Thank you all, still not working.
i tested what you said Graeme and tried to display the text on a fpimage canvas, as you can see in my project which is in this link:
https://www.dropbox.com/s/5fampciz2909u16/MinibidiTest.zip?dl=0

and as engkin said im using windows 10, and as i understood cwstrig is not for windows.

benohb, so you think it wont work on windows??

 

TinyPortal © 2005-2018