Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Got Issue with Font Khmer Unicode. #206

Open
kuth-chi opened this issue Feb 19, 2023 · 3 comments
Open

Got Issue with Font Khmer Unicode. #206

kuth-chi opened this issue Feb 19, 2023 · 3 comments

Comments

@kuth-chi
Copy link

I have add_font with the code below:
` def chapter_body(self, name):
with open(name, 'rb') as fh:
txt = fh.read().decode('utf-8')
# set font
self.add_font('KhmerOS_content', fname='font/KhmerOS_content.ttf')
# self.add_font('content', 'B', fname='font/static/NotoSansKhmer/NotoSansKhmer-Bold.ttf')
self.set_font('KhmerOS_content','', size=12)

    self.multi_cell(0, 10, txt)
    self.ln()
    # end each chapter
    # self.add_font(fname='font/Norasi-Italic.ttf')
    self.set_font('helvetica', 'I', size=14)
    self.cell(0, 5, 'End of Chapter')`

But it is working not properly (Not support Khmer characters)
You can find result with attachment for detail.
Screenshot 2023-02-18 201948

@Lucas-C
Copy link

Lucas-C commented Feb 19, 2023

Hi @ezzhop

Note that PyFPDF is not maintained anymore.
fpdf2 is its successor: https://pypi.org/project/fpdf2/
We have work ongoing to support more font types, and supporting ligatures:
https://github.com/PyFPDF/fpdf2/issues?q=is%3Aissue+is%3Aopen+label%3Afont

@kuth-chi
Copy link
Author

Hi @Lucas-C
Thank you the information.
I have installed FPDF2 to my project.
But still problem with Khmer OS font is an Unicode UTF-8
def chapter_body(self, name): # Reading text file: with open(name, "rb") as fh: txt = fh.read().decode("utf-8") # Setting font: Times 12 self.add_font('KhmerOS Moul', fname='font/KhmerOSMuol.ttf') self.set_font("KhmerOS Moul", size=12) # Printing text in a 6cm width column: self.multi_cell(60, 5, txt) self.ln() # Final mention in italics: self.set_font(style="") self.cell(0, 5, "(end of excerpt)") # Start back at first column: self.set_col(0)
image

and also got an error message.
UserWarning: Core font or font already added 'khmeros moul': doing nothing warnings.warn(f"Core font or font already added '{fontkey}': doing nothing")

I hope got a solution about this, Thank in advance.

@Lucas-C
Copy link

Lucas-C commented Feb 20, 2023

Hi @ezzhop! 😊

If you have an issue with fpdf2, please report it by opening a dedicated issue on the fpdf2 project GitHub page: https://github.com/PyFPDF/fpdf2/issues

Please take care to provide a minimal reproducing example, including mention of where to find the TTF font files used: https://stackoverflow.com/help/minimal-reproducible-example
Something along the lines of this snippet:

from fpdf import FPDF

pdf = FPDF()
txt = """..."""
self.add_font(fname='font/KhmerOSMuol.ttf')
self.set_font("KhmerOSMuol", size=12)
self.multi_cell(60, 5, txt)
pdf.output("khmer-rendering-issue.pdf")

Also, please understand that neither me nor other fpdf2 contributors know khmer language.
Hence, could you try to be very specific on the issue you are facing please?
I understand that some characters are not rendered correctly, but could you please answer those questions:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants