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

Right to Left does not work properly on multicell, Works correctly on Text #291

Open
jayeshkarandemyglamm opened this issue Apr 4, 2024 · 3 comments

Comments

@jayeshkarandemyglamm
Copy link

i want to print arabic text in a multicell, i was able to get the rtl with goarabic glyph function which work correctly on pdf.Text but does not work on pdf.Multicell
Screenshot 2024-04-04 at 12 59 52 PM

`
package main

import (
"log"

"github.com/01walid/goarabic"
"github.com/signintech/gopdf"

)
func main() {
pdf := gopdf.GoPdf{}
pdf.Start(gopdf.Config{ PageSize: gopdf.Rect{W: 595.28, H: 841.89}}) //595.28, 841.89 = A4
pdf.AddPage()
err := pdf.AddTTFFont("HDZB_5", "./DejaVuSansCondensed.ttf")
if err != nil {
log.Print(err.Error())
return
}

err = pdf.SetFont("HDZB_5", "", 14)
if err != nil {
log.Print(err.Error())
return
}
pdf.Cell(nil, "هذا يوم جيد لبدء شيء جديد وإظهار ذلك للجميع")
pdf.Br(20.0)
pdf.Text(reverseString(goarabic.ToGlyph("احمد")))
pdf.Br(20.0)
pdf.Text(reverseString(goarabic.ToGlyph("الايام السبعة")))
rect := &gopdf.Rect{W: 100, H: 100}
pdf.Br(20.0)
pdf.MultiCell(rect,reverseString(goarabic.ToGlyph("هذا يوم جيد لبدء شيء جديد وإظهار ذلك للجميع")))

pdf.Br(20.0)
pdf.Text(reverseString(goarabic.ToGlyph("هذا يوم جيد لبدء شيء جديد وإظهار ذلك للجميع")))

pdf.WritePdf("test1.pdf")
}

func reverseString(s string) string {
runes := []rune(s)
for i, j := 0, len(runes)-1; i < j; i, j = i+1, j-1 {
runes[i], runes[j] = runes[j], runes[i]
}
return string(runes)
}
`

@oneplus1000
Copy link
Collaborator

I would like you to explain more for people who have zero knowledge of Arabic language, where the points are wrong and where the points are correct.

@jayeshkarandemyglamm
Copy link
Author

i dont have much knowlege for arabic either but i could see discrepency when the multiline text was showing differently in browser and in the pdf
below is how a browser renders the multiline
Screenshot 2024-04-06 at 10 17 11 AM

and this is how it renders in go pdf
Screenshot 2024-04-06 at 10 16 29 AM

code snippet
pdf.Br(20.0) pdf.Text("example 1 with 2 with 3 with 4 and 5 and 6 and 7") pdf.Br(20.0) pdf.Text(reverseString(goarabic.ToGlyph("مثال 1 مع 2 مع 3 مع 4 و5 و6 و7"))) pdf.Br(20.0) rect := &gopdf.Rect{W: 100, H: 100} pdf.MultiCell(rect,"example 1 with 2 with 3 with 4 and 5 and 6 and 7") pdf.Br(20.0) pdf.MultiCell(rect,reverseString(goarabic.ToGlyph("مثال 1 مع 2 مع 3 مع 4 و5 و6 و7")))

@oneplus1000
Copy link
Collaborator

https://github.com/oneplus1000/gopdf/tree/issue_291

I've tried modifying the function MultiCellWithOption. To be able to add new lines RTL style.
(new code in the branch in link above.)

pdf.Br(20.0)
pdf.Text("example 1 with 2 with 3 with 4 and 5 and 6 and 7")
pdf.Br(20.0)
pdf.Text(reverseString(goarabic.ToGlyph("مثال 1 مع 2 مع 3 مع 4 و5 و6 و7")))
pdf.Br(20.0)
rect := &gopdf.Rect{W: 100, H: 100}
pdf.MultiCell(rect, "example 1 with 2 with 3 with 4 and 5 and 6 and 7")
pdf.Br(20.0)
pdf.MultiCellWithOption(rect, reverseString(goarabic.ToGlyph("مثال 1 مع 2 مع 3 مع 4 و5 و6 و7")), gopdf.CellOption{
  Align:      gopdf.Right,
  RtlLineBrk: true, // <-- Make a new line RTL style.
})
pdf.WritePdf("test.pdf")

I would like you to help me. Check if I did it right or wrong.

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