You are not logged in.

#1 2020-09-12 03:25:56

zw963
Member
Registered: 2018-06-18
Posts: 200

[Solved] Emacs print non-ASCII characters(use linux lpr) as a square.

Hi, i set up my printer(1005w) connect with WiFi.

printer is working, and i can print same text correctly
with WPS-office package, but when i send emacs buffer content
directly with `(print-buffer)`, all Chinese character replace
with a Square.

Thank you.

Last edited by zw963 (2020-09-14 07:49:49)

Offline

#2 2020-09-12 05:48:31

seth
Member
Registered: 2012-09-03
Posts: 51,213

Re: [Solved] Emacs print non-ASCII characters(use linux lpr) as a square.

Offline

#3 2020-09-12 09:54:02

zw963
Member
Registered: 2018-06-18
Posts: 200

Re: [Solved] Emacs print non-ASCII characters(use linux lpr) as a square.


Sorry, i checked, but not found any useful info from above link.

Following is some supplement, do you consider if another one issue?

1. I use Wayland, not Xorg.
2. I guess emacs use lpr command for print, because when i run code like
   
   $: cat 'text_file' |lpr

   get same print result.

3. all content show correct when open with emacs, it just not correct if print with
   lpr. (my emacs use a font which load from ~/.fonts, not system location), maybe this
   cause that?



Following is a screenshot for print result  (print to a pdf file)

https://i.imgur.com/R9j0Fpl.png

Thank you.

Offline

#4 2020-09-12 11:30:26

solskog
Member
Registered: 2020-09-05
Posts: 416

Re: [Solved] Emacs print non-ASCII characters(use linux lpr) as a square.

What is your test_file encoding? CJK txt files often use different encoding then ASCII/UTF-8. Try first transcode your file:

$ file text_file
$text_file: ISO-8859 text
$ iconv -sc -f GB2312 -t UTF-8 text_file -o result.txt

Last edited by solskog (2020-09-12 11:31:24)

Offline

#5 2020-09-12 13:22:54

seth
Member
Registered: 2012-09-03
Posts: 51,213

Re: [Solved] Emacs print non-ASCII characters(use linux lpr) as a square.

(my emacs use a font which load from ~/.fonts, not system location), maybe this  cause that?

Yes. Cups doesn't run as your user.

Try installing eg. https://www.archlinux.org/packages/extr … fonts-cjk/

The "normal" problem would have been that you're using a pcf bitmap font to resolve cjk from - which is no longer supported by pango.

@solskog, 湯 interpreted as iso-8859 would be "湯", not a single empty glyph.

Last edited by seth (2020-09-12 13:23:04)

Offline

#6 2020-09-12 19:24:38

solskog
Member
Registered: 2020-09-05
Posts: 416

Re: [Solved] Emacs print non-ASCII characters(use linux lpr) as a square.

湯 interpreted as iso-8859 would be "湯", not a single empty glyph.

Yes, but it depends on your editors font settings. I set encoding=utf8 and fileencodings=utf8,gb2312 in Vim to get correct encoding. but in another editor eg: Vis Editor with default settings I get empty glyph.

And I am suspect that even if OP had correct fonts installed in system and correct encoding/settings for Emacs but the CUPS lpr encoding/settings were not justified for CJK.

Last edited by solskog (2020-09-12 19:38:13)

Offline

#7 2020-09-12 19:39:56

seth
Member
Registered: 2012-09-03
Posts: 51,213

Re: [Solved] Emacs print non-ASCII characters(use linux lpr) as a square.

If you have utf-8 codepoints in a file interpreted as gb2312 you'll (likely) get (some) errors, what could lead to the glyph being skipped or displayed as some error or whatnot (though an accurate™ error should reflect more boxes per glyph to account for the byte count, I guess)
This should™ only happen for external files, though, since your primary encoding is still utf-8

Offline

#8 2020-09-14 04:35:09

zw963
Member
Registered: 2018-06-18
Posts: 200

Re: [Solved] Emacs print non-ASCII characters(use linux lpr) as a square.

solskog wrote:

What is your test_file encoding? CJK txt files often use different encoding then ASCII/UTF-8. Try first transcode your file:

Acutally, i only use UTF-8 coding.

 ╰─ $ file 2.txt 
2.txt: UTF-8 Unicode text
 ╰─ $ \cat 2.txt 
0x03000003  0 lggram 只要看这一篇,车险全搞懂(值得收藏) - 知乎 - Nightly
0x03000097  0 lggram Frequently Asked Questions · Sorbet - Nightly

Try installing eg. https://www.archlinux.org/packages/extr … fonts-cjk/

The "normal" problem would have been that you're using a pcf bitmap font to resolve cjk from - which is no longer supported by pango.

Yes, i try install noto-fonts-cjk, but no luck, it still not working.

In fact, i want to clarify this, because i guess it maybe a lpr issue.(not a emacs issue?)

because i can reproduce this issue with following command

 ╰─ $ cat 2.txt |lpr

Because i set pdf as default printer, With above command, i can get a pdf content like this

pZubB4U.png

But i find out a solution use paps package. (though, i even don't know what this package stand for,
and, if this just a workaround, not really fix my issue)

 ╰─ $ 127  pacman -S paps
resolving dependencies...
looking for conflicting packages...

Packages (1) paps-0.7.1-2
...

 ╰─ $ cat 2.txt |paps|lpr

Now i get a new pdf, with Chinese character get print correctly.

LNVL9pK.png


So, is this really a setup fonts into ~/.fonts issue? i don't know, but,
i can confirm, this is not a gb2312 encoding issue anyway.

Thank you.

----------------------------------------------------

UPDATED:

I fixed my question with a bash wrapper script.


 ╰─ $ \cat new_lpr 
#!/bin/bash

paps|lpr

And, set emacs to use this new lpr command

(setq lpr-command "new_lpr")

Emacs "printer-buffer" command is working now, i guess it print out a new paper
which use same fonts as emacs itself used.

Last edited by zw963 (2020-09-14 04:53:18)

Offline

#9 2020-09-14 05:41:51

solskog
Member
Registered: 2020-09-05
Posts: 416

Re: [Solved] Emacs print non-ASCII characters(use linux lpr) as a square.

seth wrote
The "normal" problem would have been that you're using a pcf bitmap font to resolve cjk from - which is no longer supported by pango.

community/paps 0.7.1-2
    Converts Unicode text to postscript and pdf using pango

Great that you solved it!

Last edited by solskog (2020-09-14 05:42:14)

Offline

#10 2020-09-14 07:01:32

seth
Member
Registered: 2012-09-03
Posts: 51,213

Re: [Solved] Emacs print non-ASCII characters(use linux lpr) as a square.

The issue is actually that emacs just shells out the text to lpr instead of generating postscript or pdf internally and the texttopdf filter, while linking fontconfig, can apparently not deal w/ it.

Please always remember to mark resolved threads by editing your initial posts subject - so others will know that there's no task left, but maybe a solution to find.
Thanks.

Offline

Board footer

Powered by FluxBB