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

Arabic characters are not getting rendered properly when tried with FOP #960

Open
nucleussoftwareopen opened this issue Oct 10, 2023 · 3 comments
Labels

Comments

@nucleussoftwareopen
Copy link

Describe the bug
The arabic characters not being rendered properly in the PDF when using below font with FOP. If I do not use the FOP, the characters appears properly.

  1. majalla

Same issue is coming with Arial and Noto as well.

To Reproduce
Code to reproduce the issue

  1. Refer below Sample Code for Unit test

public class MultipleDirTest2 {

@Test
public void multiDirTest(){
    Document document = new Document(PageSize.A4, 50, 50, 50, 50);
    PdfWriter writer = null;
    FontFactory.register("D:/workspace/windows/fonts/majalla.ttf");
   try {
        writer = PdfWriter.getInstance(document, new FileOutputStream("NotWorking_UT_arab__majalla_with_FOP.pdf"));
        try {
            Class.forName("org.apache.fop.complexscripts.util.GlyphSequence");
        } catch (ClassNotFoundException e) {
            System.out.println("DO");
        }
        document.open();
        PdfContentByte cb = writer.getDirectContent();
       BaseFont bf = BaseFont.createFont("D:\\workspace\\windows\\fonts\\majalla.ttf", BaseFont.IDENTITY_H, true);
       Font font1 = new Font(bf, 24, Font.NORMAL, Color.BLUE);
        float llx = 100;
        float lly = 100;
        float urx = 500;
        float ury = 800;
        Paragraph element1 = new Paragraph();
        Paragraph element2 = new Paragraph();

        String ar9 = "مبلغ الإيصال المستلم";     //the input arabic string(word)

        element1.add(new Chunk(ar9 ,font1));

        element1.setRunDirection(PdfWriter.RUN_DIRECTION_RTL);

        element2.setRunDirection(PdfWriter.RUN_DIRECTION_RTL);
        ColumnText ct = new ColumnText(cb);
        ct.setSimpleColumn(llx,lly,urx,ury);
        ct.addElement(element1);
        ct.go();
        document.close();
    }
    catch (Exception e) {
        e.printStackTrace();
    }
}

For getting the correct output I have updated the else block of method "convertToBytes" in class com.lowagie.text.pdf.FontDetails.java . New method else block will look like below. Once I use below updated FontDetails class, the above test case results in correct output.

else { /*String fileName = ((TrueTypeFontUnicode)getBaseFont()).fileName; if (FopGlyphProcessor.isFopSupported() && (fileName!=null && fileName.length()>0 &&( fileName.contains(".ttf") || fileName.contains(".TTF")))){ return FopGlyphProcessor.convertToBytesWithGlyphs(ttu,text,fileName,longTag); }else { return convertToBytesWithGlyphs(text); }*/ return convertToBytesWithGlyphs(text); }

Actual Output
Not-working-output

Expected behavior
Expected-output

Screenshots
screenshots added above.

System (please complete the following information):

  • OS: Windows 10 Enterprise
  • Used Font: sakkal majalla

Additional context
Add any other context about the problem here.

@andreasrosdal
Copy link
Contributor

Hello, can you please submit a pull request to solve this bug? It seems like you have described the solution here.

@nucleussoftwareopen

@asturio
Copy link
Member

asturio commented Feb 23, 2024

Yes, please submit a pull request. Also because it is probably easier to solve this, if you can understand the given alphabet (I can't, sorry)

@rzaq-alshoshan
Copy link

I had the same issue before, the issue is with the used font.
Some fonts for some reason will pick a wrong glyph.
Although the issue was not there in itext older versions, but changing the font to this one fixed the issue for me.
https://github.com/LibrePDF/OpenPDF/blob/master/pdf-toolbox/src/test/resources/com/lowagie/examples/fonts/noto/NotoSansArabic-Regular.ttf

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

No branches or pull requests

4 participants