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

Not all font characters will display when painted with :graphics #222

Open
JanSuran03 opened this issue Jun 22, 2022 · 10 comments
Open

Not all font characters will display when painted with :graphics #222

JanSuran03 opened this issue Jun 22, 2022 · 10 comments

Comments

@JanSuran03
Copy link

JanSuran03 commented Jun 22, 2022

Not all font characters of my native (Czech) language will display when painted with :graphics. But if I create a blank JFrame with Canvas it all works fine. I don't know what I have to set up to make it work...

(let [a4-width (.getWidth PageSize/A4)
      name-label-height 150]
  (pdf [{:font {:encoding :unicode
                :ttf-name "fonts/arialuni.ttf"
                :size     50}}
        [:graphics
         (fn [^Graphics2D g2d]
           (doto g2d
             (.setColor (Color. 0 255 255)
             (.fillRect 0 0 a4-width name-label-height)
             (.setFont (Font. "Calibri" Font/BOLD 50))
             (.setColor Color/BLACK)
             (.drawString "ěščůéúť" 20 60)))]
        [:paragraph (apply str (repeat 8 "ěščřžýáíéóťďůú\n"))]]))

(let [canvas (proxy [Canvas] []
               (paint [^Graphics g]
                (doto g
                   (.setColor Color/RED)
                   (.fillRect 100 100 400 250)
                   (.setFont (Font. "Calibri" Font/BOLD 40))
                   (.drawString "ěščůúť" 450 80))))]
  (doto (proxy [JFrame] [])
    (.add canvas)
    (.setVisible true)
    (.setBounds 500 500 1000 600)))

image

@yogthos
Copy link
Collaborator

yogthos commented Jun 22, 2022

Not sure what the solution would be here. Have you tried using a different TTF font?

@JanSuran03
Copy link
Author

Well, the thing is, it works for paragprahs, but it doesn't work for Graphics2D. On the other hand, it works for Graphics2D for the second example.

@JanSuran03
Copy link
Author

And by the way, I don't even know if the font exists... (without :ttf-name some of the characters don't display but with an invalid :ttf-name they do? :D
image

@yogthos
Copy link
Collaborator

yogthos commented Jun 23, 2022

Setting the encoding might help, here's the function that attempts to resolve the font.

@JanSuran03
Copy link
Author

The encoding is there, but it still doesn't affect anything.

@yogthos
Copy link
Collaborator

yogthos commented Jun 23, 2022

Unfortunately, not sure what to do here. I'm open to a PR if you do figure it out though. :)

@JanSuran03
Copy link
Author

Oh, the same bug appears in the Quil (https://github.com/quil/quil) library.
I can set the text mode to :shape which works fine, it just doesn't act like text at all (as an image instead - cannot be selected etc.) or :model which allows me to interact with it, however, it doesn't display all the characters. Hmm 🤔

@yogthos
Copy link
Collaborator

yogthos commented Jun 26, 2022

Might be an underlying issue in Java graphics implementation. Wonder if using SVG might be a workaround here.

@yannis218
Copy link

I am experiencing the same issue: The non-ASCII characters appear when drawn into the Graphics2D of my JPanel, but not in the Graphics2D of the PDF :graphics element. If it were a problem with Graphics2D itself, would it not fail in both instances?

@yogthos
Copy link
Collaborator

yogthos commented Dec 16, 2023

Not really sure what the difference between rendering to a JPanel vs the graphics element is unfortunately.

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

3 participants