Recent

Author Topic: Chinese Fonts in fpPDF  (Read 3524 times)

dbannon

  • Hero Member
  • *****
  • Posts: 3156
    • tomboy-ng, a rewrite of the classic Tomboy
Re: Chinese Fonts in fpPDF
« Reply #30 on: September 30, 2024, 11:02:38 am »
OK jianwt, I see the problem.  Down in the function TPDFTestApp.SetupFonts() you have this code starting at line number 226 -

Code: Pascal  [Select][+][-]
  1.     {$ifdef windows}
  2.     gTTFontCache.SearchPath.Add('./');
  3.     // Put 'extra' fonts right next to binary ??
  4.     gTTFontCache.ReadStandardFonts;
  5.     // Scans usual places but apparently also ./fonts/ ? Nice ...
  6.     {$endif}        

That means the "gTTFontCache.ReadStandardFonts;" command is only used in Windows, not linux.  Having the fonts next to binary is a good idea in Windows, a very bad idea in Linux. But both MUST call gTTFontCache.ReadStandardFonts;. So, this is better -

Code: Pascal  [Select][+][-]
  1.     {$ifdef windows}
  2.     gTTFontCache.SearchPath.Add('./');
  3.     // Put 'extra' fonts right next to binary ??
  4.     {$endif}
  5.     gTTFontCache.ReadStandardFonts;
  6.     // Scans usual places but apparently also ./fonts/ ? Nice ...
  7.        

Why ?  Generally, a Windows install will have the application in its own folder so, searching there is quick. But installed binaries will probably go into /usr/bin/ and I have 2649 files there and many in lower levels so, you don't want gTTFFontCache scanning that !

I tried it with that change, all good.

I have my user supplied fonts in $HOME/.fonts - thats a great place on Linux. At least for now, I note in the libfontconfig source, a note that they will stop looking some time ??  But will still work well with gTTFFontCache

Good luck

Davo

Lazarus 3, Linux (and reluctantly Win10/11, OSX Monterey)
My Project - https://github.com/tomboy-notes/tomboy-ng and my github - https://github.com/davidbannon

jianwt

  • Full Member
  • ***
  • Posts: 125
Re: Chinese Fonts in fpPDF
« Reply #31 on: October 01, 2024, 05:58:08 am »
@ dbannon

Because I just want to generate PDF files under linux system. I put the Chinese font "SIMFANG.TTF" I used under './', '/fonts' and' /home/username/.fonts' and couldn't find them. Please help me have a look again, I will upload the fonts, and please help me correct where I need to modify my code.

Due to the use of Chinese font cannot upload with package, I give a download address  https://github.com/21wmd/ttf-simfang/blob/master/usr/share/fonts/truetype/sim/simfang.ttf
Excuse me.
Playing with code for half a day, the program is running when the overflow. Can you help me see where my code is wrong and how to fix it?
Thank you very much。

« Last Edit: October 01, 2024, 06:05:25 am by jianwt »

dbannon

  • Hero Member
  • *****
  • Posts: 3156
    • tomboy-ng, a rewrite of the classic Tomboy
Re: Chinese Fonts in fpPDF
« Reply #32 on: October 01, 2024, 06:42:53 am »
jianwt, I just compiled and run you recent example code, it worked, for me, as expected.

I believe your problem must relate to finding the font. In my case, I have simfang.ttf in my ~/.fonts directory and the FontCache does look there, does find it. We need to understand why it does not find it i your case.

When you run the compiled app, you should see a report of what it did. If running from Lazarus, you need to view that report form Consol I/O but I suggest it would be much, much easier if you ran it from the command line. So, please do the following -
Compile the code (from withing Lazarus if you like)
Then, open a terminal, and change to the directory where the source code is.
Then give the following command, one by one -
Code: Bash  [Select][+][-]
  1. $> ls
  2. $> ./testfppdf

Then copy that output from those commands by highlighting them with the mouse and pressing Ctrl-Shift-C.  Now, go back to your browser and paste that content into a response to this thread.

Post that message.

Then, back to your terminal and give this command -

Code: Bash  [Select][+][-]
  1. $>  ls  -la  ~/.fonts

And copy the output from that into another new message and post it too. That should be all we need to do to work out what is happening. I am sure we will work it out !

Davo
 

Lazarus 3, Linux (and reluctantly Win10/11, OSX Monterey)
My Project - https://github.com/tomboy-notes/tomboy-ng and my github - https://github.com/davidbannon

dsiders

  • Hero Member
  • *****
  • Posts: 1280
Re: Chinese Fonts in fpPDF
« Reply #33 on: October 01, 2024, 06:58:33 am »
To my knowledge, you need make sure the new font(s) are in the font cache.

Code: Bash  [Select][+][-]
  1. fc-cache -f -v
  2. fc-list
  3.  
Preview the next Lazarus documentation release at: https://dsiders.gitlab.io/lazdocsnext

jianwt

  • Full Member
  • ***
  • Posts: 125
Re: Chinese Fonts in fpPDF
« Reply #34 on: October 01, 2024, 08:32:40 am »
When the operation goes to "Then copy that output from those commands by highlighting them with the mouse and pressing Ctrl-Shift-C. Now, go back to your browser and paste that content into a response to this thread. "During this step, Exception at 0000000000431BF9 is displayed: EListError: List index (0) out of bounds. ". I'm a novice, I don't know how to operate, just copy the error message. Still don't know what's causing the problem; I looked at it in detail, and the Chinese font of the letter I placed should have been found, but it still said "Exception at 0000000000431BF9: EListError: List index (0) out of bounds." I don't know what to do. Beginners are terrible. Thank you very much. I'm really sorry for taking up so much of your time.

It may also have something to do with the deepin64 system I use.

jianwt@jianwt-PC:~/Desktop/testFPpdf_linux$ ls  -la  ~/.fonts
总用量 32112
drwxr-xr-x  2 jianwt jianwt     4096 10月  1 10:04 .
drwxr-x--- 25 jianwt jianwt     4096 10月  1 14:18 ..
-rw-r--r--  1 jianwt jianwt  3996872 6月  14 11:26 仿宋_GB2312.ttf
-rw-r--r--  1 jianwt jianwt 12128500 6月  14 11:26 华文中宋.ttf
-rw-r--r--  1 jianwt jianwt  4135804 6月  14 11:26 楷体_GB2312.ttf
-rwxrw-rw-  1 jianwt jianwt   980756 12月  7  2019 ARIALBD.TTF
-rwxrw-rw-  1 jianwt jianwt  1036584 12月  7  2019 ARIAL.TTF
-rwxrw-rw-  1 jianwt jianwt 10578152 10月 15  2019 SIMFANG.TTF
-rw-r--r--  1 jianwt jianwt       36 6月  14 11:26 .uuid
« Last Edit: October 01, 2024, 08:46:31 am by jianwt »

dbannon

  • Hero Member
  • *****
  • Posts: 3156
    • tomboy-ng, a rewrite of the classic Tomboy
Re: Chinese Fonts in fpPDF
« Reply #35 on: October 01, 2024, 09:24:46 am »
To my knowledge, you need make sure the new font(s) are in the font cache.

Don, you certainly do if you use libfontconfig directly but when running the Cache from fpttf it seems to read from ~/.fonts as long as you call .ReadSdFonts.  Or so I have found.

Davo
Lazarus 3, Linux (and reluctantly Win10/11, OSX Monterey)
My Project - https://github.com/tomboy-notes/tomboy-ng and my github - https://github.com/davidbannon

jianwt

  • Full Member
  • ***
  • Posts: 125
Re: Chinese Fonts in fpPDF
« Reply #36 on: October 01, 2024, 09:58:38 am »
I also put the fonts under "/usr/share/fonts/" and updated the font cache. But still reported "During this step, Exception at 0000000000431BF9 is displayed: EListError: List index (0) out of bounds.", very helpless! .

dbannon

  • Hero Member
  • *****
  • Posts: 3156
    • tomboy-ng, a rewrite of the classic Tomboy
Re: Chinese Fonts in fpPDF
« Reply #37 on: October 01, 2024, 11:47:25 am »
jianwt, I believe that you are getting this exception because you are trying to use a font that does not exist. But I am sure that the code you are using checks for such a situation !

Attached is the code for a much simpler test, it tests only the cache, you can run it to prove, or otherwise, that you have the fonts available that your expect.

Please compile it in Lazarus and then, from the command line in the directly it was compiled in, run, for example -

$> ./project1  --file=simfang.ttf

That should show us, conclusively, that the font is being found in ~/.fonts or NOT !

I note you have changed the file, simfang.ttf to SIMFANG.TTF, strange thing to do but my tests indicate that fpttf is case insensitive.

Please run my little test, I am pretty sure it cannot do anything that will raise an exception.

(except, if you get the parameter wrong, don't think I checked for that ...)

Davo

Lazarus 3, Linux (and reluctantly Win10/11, OSX Monterey)
My Project - https://github.com/tomboy-notes/tomboy-ng and my github - https://github.com/davidbannon

jianwt

  • Full Member
  • ***
  • Posts: 125
Re: Chinese Fonts in fpPDF
« Reply #38 on: October 02, 2024, 09:47:58 am »
The forum can not log in for a day, just can log in.
Sometimes the forums don't go up.

After compiling, the system displays
 
【jianwt@jianwt-PC:~/Desktop/TestCache$./project1 --file=simfang.ttf

Found 245 fonts.】

I think I found the font. Does' 245 'represent a single font, or the sum total of fonts in my system? Don't understand??

I fill in SIMFANG.TTF because when I paste the font into the linux system, it becomes uppercase.

I want to start from simple, you can help me write a Chinese font DEMO, simple point, see what the problem is.
« Last Edit: October 02, 2024, 10:11:50 am by jianwt »

paweld

  • Hero Member
  • *****
  • Posts: 1268
Re: Chinese Fonts in fpPDF
« Reply #39 on: October 02, 2024, 01:28:00 pm »
Attached an example requires “pdftoppm” installed
Best regards / Pozdrawiam
paweld

dbannon

  • Hero Member
  • *****
  • Posts: 3156
    • tomboy-ng, a rewrite of the classic Tomboy
Re: Chinese Fonts in fpPDF
« Reply #40 on: October 02, 2024, 01:56:03 pm »
OK, jianwt, I am sorry, I made a mistake with that code.  Sorry, I was in a hurry and I did not test it properly !!!

You could repeat that test with a different command, please try -

Code: Bash  [Select][+][-]
  1. $> ./project1 --part=fang

Attached is a second version that works as it should. You can recompile with is code and try again. But the above test should work.  The test command takes three options -

  • --file=<filename>    broken in your version
  • --part=<part of font name>   Works for me.
  • --name=<font name>   works for me.


Please either try again, with the existing copy and the new command I mention above.  OR, recompile and try the original command.

Again, sorry for my mistake.

The 245 fonts is how many fonts were found on your system by the cache.  You have less than I would expect, my standard Debian install has something like 2900. So, that says to me, maybe you don't have the default fonts we are assuming are present ?

> I fill in SIMFANG.TTF because when I paste the font into the linux system, it becomes uppercase.

Wow, I have no idea why that would happen. But my tests seemed to indicate the FontCache is case insensitive. If the above tests don't show us anything interesting, just as another thing to try, please do this -

Code: Pascal  [Select][+][-]
  1. $>  cp  ~/.fonts/SIMFANG.TTF  ~/.fonts/simfang.ttf

And then run the above experiments.  I don't think this will make any difference but please try, just in case.

And another experiment, if you are still not getting an answer from projet1, try this -

Code: Pascal  [Select][+][-]
  1. $> sudo  cp ~/.fonts/simfang.ttf /usr/local/share/fonts/truetype/.

You will have to enter the root password when prompted.  Please don't do this if you have had a positive response to the experiments above here.

Davo

ps, when I run that command, it looks like this -

Code: Bash  [Select][+][-]
  1. dbannon@dell:~/Pascal/fcl-pdf/TestCache$ ./project1 --part=fang
  2. Found 2948 fonts.
  3.         Name - [FangSong]
  4.         File - [/home/dbannon/.fonts/simfang.ttf]
  5.         Regular

EDIT: forgot the attachment !
« Last Edit: October 02, 2024, 02:00:56 pm by dbannon »
Lazarus 3, Linux (and reluctantly Win10/11, OSX Monterey)
My Project - https://github.com/tomboy-notes/tomboy-ng and my github - https://github.com/davidbannon

dbannon

  • Hero Member
  • *****
  • Posts: 3156
    • tomboy-ng, a rewrite of the classic Tomboy
Re: Chinese Fonts in fpPDF
« Reply #41 on: October 02, 2024, 02:30:25 pm »
jianwt, in case my theory is right, that you don't have any of what we consider "standard fonts", here is a stripped down version of the earlier PDF demo, it uses ONLY simfang (or, failing that, one of the other Chinese fonts we know work).  It does NOT use things like liberation sans ....

If it does not find a suitable chinese font, it will give an error message, it "should" not crash. If it does, then we need to work out why !

Only prints one block of text using a chinese font.

Davo

Lazarus 3, Linux (and reluctantly Win10/11, OSX Monterey)
My Project - https://github.com/tomboy-notes/tomboy-ng and my github - https://github.com/davidbannon

jianwt

  • Full Member
  • ***
  • Posts: 125
Re: Chinese Fonts in fpPDF
« Reply #42 on: October 02, 2024, 04:22:37 pm »
@paweld

@dbannon

Thank you. I'll take a good look at your routine in the morning.

jianwt

  • Full Member
  • ***
  • Posts: 125
Re: Chinese Fonts in fpPDF
« Reply #43 on: October 03, 2024, 03:46:49 am »
@paweld

Thank you for your help, I have run your DEMO and it runs perfectly in my linux system. Thanks again for your help! Wish you a happy work!
Where can I get the file "pdftoppm"? Can you give me a download website? thank you.
The operation effect is shown in the following figure:
« Last Edit: October 03, 2024, 03:58:42 am by jianwt »

jianwt

  • Full Member
  • ***
  • Posts: 125
Re: Chinese Fonts in fpPDF
« Reply #44 on: October 03, 2024, 03:54:05 am »
@dbannon

Your last TestPDF runs very well in my linux system, and Chinese can be displayed. The previous ones all reported overflow errors, I don't know why. Finally, thank you very much for your warm help to the novice in these two days. Wish you a happy work!

Code: Pascal  [Select][+][-]
  1. 1.//$>./project1 --part=fang
  2. Output:   jianwt@jianwt-PC:~/Desktop/TestCachewt/TestCache$ ./project1 --part=fang
  3.               Found 245 fonts.
  4.               Name - [FangSong]
  5.               File - [/usr/share/fonts/SIMFANG.TTF]
  6.               Regular
  7.  
  8.               Name - [FangSong]
  9.               File - [/home/jianwt/.fonts/SIMFANG.TTF]
  10.               Regular
  11.  
  12.               Name - [FangSong_GB2312]
  13.               File - [/home/jianwt/.fonts/仿宋_GB2312.ttf]
  14.              Regular
  15.  
  16.            jianwt@jianwt-PC:~/Desktop/TestCachewt/TestCache$
  17.  
  18.  
  19. 2.//$>   cp  ~/.fonts/SIMFANG.TTF  ~/.fonts/simfang.ttf
  20. Output:jianwt@jianwt-PC:~/Desktop/TestCachewt/TestCache$ cp  ~/.fonts/SIMFANG.TTF  ~/.fonts/simfang.ttf
  21.             jianwt@jianwt-PC:~/Desktop/TestCachewt/TestCache$
  22.  
  23. 3.//$> sudo  cp ~/.fonts/simfang.ttf /usr/local/share/fonts/truetype/.
  24. Output: jianwt @ jianwt - PC: ~ / Desktop/TestCachewt TestCache $sudo cp ~ /. / fonts/simfang the vera.ttf/usr/local/share/fonts/truetype /.
  25.             Please enter your password:
  26.             Successful verification
  27.             Cp: unable to create the common file '/ usr/local/share/fonts/truetype /.' : the file or directory
  28.            jianwt@jianwt-PC:~/Desktop/TestCachewt/TestCache$
  29.  
  30.  
  31.  
« Last Edit: October 03, 2024, 03:55:42 am by jianwt »

 

TinyPortal © 2005-2018