half-width character display bug! #1248
-
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 7 replies
-
Sorry i add one thing, the character 'タ' above is Janpanese, And this bug is not with fonttype, i tried all fonttype. |
Beta Was this translation helpful? Give feedback.
-
This is not a bug:
Look at this snippet to see this work: import fitz
doc = fitz.open()
page = doc.new_page()
r1 = fitz.Rect(100, 100, 300, 120)
r2 = fitz.Rect(100, 120, 300, 140)
t1 = "9999タ" # all chars are supported by font "Mincho" (Japanese)
t2 = "x9999タ" # starts with a char unsupported by Mincho
page.add_freetext_annot(r1, t1, fontname="helv")
page.add_freetext_annot(r2, t2, fontname="helv")
doc.ez_save(__file__.replace(".py", ".pdf"), pretty=True) This will produce the following: When looking at the PDF "source" of the annotations, we will see this: >>> a1 = page.first_annot
>>> a2 = a1.next
>>> print(a1._getAP().decode())
0 w
0 0 200 20 re
W
n
BT
0 0 0 rg
0 24.8 Td
0 -14.400001 Td
/Mincho 12 Tf
<0039003900390039ff80> Tj % ==> all text in Mincho!
ET
>>> print(a2._getAP().decode())
0 w
0 0 200 20 re
W
n
BT
0 0 0 rg
0 24.8 Td
0 -14.400001 Td
/Helv 12 Tf
(x9999) Tj % ==> start text in Helv
/Mincho 12 Tf
<ff80> Tj % ==> switch to Mincho when we must
ET
>>> |
Beta Was this translation helpful? Give feedback.
-
Got it, Thanks for your anwser! |
Beta Was this translation helpful? Give feedback.
This is not a bug:
For FreeText annots, MuPDF supports non-embedded fonts only: Base-14 and CJK. As explained here, surprising behaviour can occur if you access / update annotations with a different tool than the one you used for creating them.
As you wrote, you "double clicked" the annot. This will have happened in a PDF viewer different from MuPDF (maybe Adobe Acrobat or something else), so this effect is inevitable.
MuPDF's internal logic for creating the annotation works roughly like this: