const char *text : string or unistring #80
Replies: 18 comments 7 replies
-
@nico-robert Glad you are plugging away :-) Regarding the encoding with haru, see this. Basically you need to tell haru what text encoding to use by calling Let me know if that works, or doesn't. /Ashok |
Beta Was this translation helpful? Give feedback.
-
I wasn't aware of the tclhpdf either. That's always a danger with open source. The release at that link seems quite old though, so there may still be value to a newer implementation. I suspect your unicode worked with encoding_list.c because it seems to write only one char at a time in draw_text and only letters between 0x20 and 0xff in which both unicode and almost any other encoding will look the same (the single byte followed by a zero byte). Regarding your current problem, can you make your code available? I can try taking a look at the problem but I don't have time to write all the cffi interface myself to test it out. /Ashok |
Beta Was this translation helpful? Give feedback.
-
Hello @apnadkarni , |
Beta Was this translation helpful? Give feedback.
-
You could just attach it to your reply by clicking at the bottom of the github discussions entry widget (see where it says "Attach files..." unless you do not want to make it public. |
Beta Was this translation helpful? Give feedback.
-
Thanks, I'll take a look in the next couple of days. Just need to finish up some enhancements to cffi first. /Ashok |
Beta Was this translation helpful? Give feedback.
-
I had a quick look. Attached is a patch which works for this demo (only looked at encoding_list). Although only three lines have changed, the ramifications are wide and deep in terms of how the interface should look. I had misunderstood the hpdf api so need to think about it a bit more. BTW, I was impressed with how far along you are with the interface and demos. /Ashok |
Beta Was this translation helpful? Give feedback.
-
Yes, that change is necessary. The short answer is that the In the case of Also, I assume you understood the reason for the following change:
The first line sets buffer to a Unicode character corresponding to a specific byte value, say 0xA3 (for example). However, the intent is not to interpret the 0xA3 as a Unicode char but rather 0xA3 as an encoding using the encoding being displayed e.g. iso8859-2. That is what the second line does, it stores the byte value 0xa3 followed by the terminating \0 character. Now the above works for when you want to write a single character corresponding to an specific ordinal position in the encoding. For outputting a general Unicode string, the application would need to do something like
Hope that clarifies but I'll elaborate later when I've more time. /Ashok |
Beta Was this translation helpful? Give feedback.
-
Thanks for the clarification... |
Beta Was this translation helpful? Give feedback.
-
To conclude my previous post, mu suggestion is that all parameters that are expected to be encoded strings be changed to
Then an example call would look like
|
Beta Was this translation helpful? Give feedback.
-
Also, to reply to your question, there is no way for cffi to distinguish between bytes vs strings vs any other types thanks to Tcl's everything is a string semantics. |
Beta Was this translation helpful? Give feedback.
-
Thanks , I don’t know if I’m able to find the encoding applied to my font. I'm gonna keep looking... |
Beta Was this translation helpful? Give feedback.
-
When you say encoding for your font, do you mean the font you are using for testing? My understanding is that the application has to enable the appropriate fonts when calling haru so from the interface point of view, it does not have to detect the font. May be I misunderstand the issue. /Ashok |
Beta Was this translation helpful? Give feedback.
-
Yes my encoding for my font I use... If I understand your procedure
In Tcl I have this result with your procedure
Without your procedure I have this result :
In any case, this I think does not come from your library (I think you already knew 😉), it is probably me who does not understand Thanks anyway |
Beta Was this translation helpful? Give feedback.
-
Hello @apnadkarni , |
Beta Was this translation helpful? Give feedback.
-
The following worked for me (patch against your original code).
Line numbers likely off as I had some "experimental" code in there as well. The key I think is that the third argument to HPDF_GetFont should be the same as the encoding used when outputting text via HPDF_Page_TextOut (CP1252 here but likely any would do as long as it is the same in both calls) The (c) then displays correctly, and you might notice the single quotes around Ctrl-L are also fixed. /Ashok |
Beta Was this translation helpful? Give feedback.
-
By the way, you need to also add [hpdf_encode...] when outputting the caption or any other text. |
Beta Was this translation helpful? Give feedback.
-
It works... I will continue in this way. Nicolas |
Beta Was this translation helpful? Give feedback.
-
Thanks. Pls let me know if you open source your work. |
Beta Was this translation helpful? Give feedback.
-
Hello @apnadkarni ,
Always working on my library (libharu).
C function HPDF_Page_TextOut :
cffi function :
text define to
string
works in most cases but when I have symbol in my string the display of characters is strange.If I set the text to
unistring
it works with different encodings and different symbols, but it only displays the first character, by example :HPDF_Page_TextOut $page 10 10 "Text_example ©"
display :
T
If I set the text to string , Text_example works but for copyright symbol my display is like this :
Text_example ́'
I'm a little confused... What type I should put as argument according to my text ?
I hope I was clear in my request
Thanks
Nicolas
Beta Was this translation helpful? Give feedback.
All reactions