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

[dvipdfmx] 特定の条件で誤ったグリフが出力される #165

Closed
h20y6m opened this issue Dec 21, 2023 · 7 comments
Closed

[dvipdfmx] 特定の条件で誤ったグリフが出力される #165

h20y6m opened this issue Dec 21, 2023 · 7 comments
Labels

Comments

@h20y6m
Copy link
Collaborator

h20y6m commented Dec 21, 2023

dvipdfmxで以下のような条件のときに誤ったグリフが出力されます。

  • CID経由でTrueTypeフォントを使っている
  • Adobe-Japan1-UCS2でU+10000以上のコードにマップされる
  • 該当の文字がフォントに存在しない
  • 文字コードの下位16ビットに一致する文字がフォントに存在している
%#!ptex2pdf -u
\special{pdf:mapfile uptex-ipaex.map}
𠂰% U+200b0
𠃵% U+200f5
𠅘% U+20158
𤿲% U+24ff2
𧦴% U+279b4
𧵳% U+27d73
姬% U+2f862
諭% U+2f9d0
\bye
dvipdfmx:warning: Unicode char U+2f862 replaced with U+f862.
dvipdfmx:warning: Unicode char U+2f9d0 replaced with U+f9d0.
dvipdfmx:warning: Unicode char U+200b0 replaced with U+00b0.
dvipdfmx:warning: Unicode char U+200f5 replaced with U+00f5.
dvipdfmx:warning: Unicode char U+24ff2 replaced with U+4ff2.
dvipdfmx:warning: Unicode char U+27d73 replaced with U+7d73.
dvipdfmx:warning: Unicode char U+20158 replaced with U+0158.
dvipdfmx:warning: Unicode char U+279b4 replaced with U+79b4.

以下の部分でunsigned shortにキャストしているためだと思います。

#ifdef FIX_CJK_UNIOCDE_SYMBOLS
if (gid == 0 && unicode_cmap) {
int alt_code;
alt_code = fix_CJK_symbols((unsigned short)code);
if (alt_code != code) {
gid = tt_cmap_lookup(ttcmap, alt_code);
if (gid != 0) {
WARN("Unicode char U+%04x replaced with U+%04x.", code, alt_code);
}
}
}
#endif /* FIX_CJK_UNIOCDE_SYMBOLS */

@aminophen aminophen added the bug label Jan 6, 2024
@t-tk
Copy link
Collaborator

t-tk commented Feb 1, 2024

fix_CJK_symbols() はレガシーエンコーディングとUnicodeの間の変換表の揺らぎ問題(波ダッシュ問題)で見つからないグリフを見つけられるようにする意図のようです。
なので、以下で充分だという気がします。
全然テストしていませんが…

diff --git a/source/texk/dvipdfm-x/cidtype2.c b/source/texk/dvipdfm-x/cidtype2.c
index 2c6caf908..a3d5a63c8 100644
--- a/source/texk/dvipdfm-x/cidtype2.c
+++ b/source/texk/dvipdfm-x/cidtype2.c
@@ -827,7 +827,7 @@ CIDFont_type2_dofont (pdf_font *font)
         } else {
           gid  = tt_cmap_lookup(ttcmap, code);
 #ifdef FIX_CJK_UNIOCDE_SYMBOLS
-          if (gid == 0 && unicode_cmap) {
+          if (gid == 0 && unicode_cmap && code <= 0xFFFF) {
             int alt_code;

             alt_code = fix_CJK_symbols((unsigned short)code);

@t-tk
Copy link
Collaborator

t-tk commented Feb 1, 2024

なぜか、この変換表に
FULLWIDTH YEN SIGN (U+FFE5) “¥” と YEN SIGN (U+00A5) “¥” の相互変換が含まれていません。
変換表のラインナップからすると、入れた方がいいような気がします。

    {0x2014, 0x2015}, /* EM DASH <-> HORIZONTAL BAR */
    {0x2016, 0x2225}, /* DOUBLE VERTICAL LINE <-> PARALLEL TO */
    {0x203E, 0xFFE3}, /* OVERLINE <-> FULLWIDTH MACRON */
    {0x2026, 0x22EF}, /* HORIZONTAL ELLIPSIS <-> MIDLINE HORIZONTAL ELLIPSIS */
    {0x2212, 0xFF0D}, /* MINUS SIGN <-> FULLWIDTH HYPHEN-MINUS */
    {0x301C, 0xFF5E}, /* WAVE DASH <-> FULLWIDTH TILDE */
    {0xFFE0, 0x00A2}, /* FULLWIDTH CENT SIGN <-> CENT SIGN */
    {0xFFE1, 0x00A3}, /* FULLWIDTH POUND SIGN <-> POUND SIGN */
    {0xFFE2, 0x00AC}, /* FULLWIDTH NOT SIGN <-> NOT SIGN */
    {0xFFFF, 0xFFFF}, /* EOD */

@t-tk
Copy link
Collaborator

t-tk commented Feb 2, 2024

テストしました。
予定通り、提示していただいたサンプルで下記のようなエラーになり、該当の文字は□に×のグリフになりました。

dvipdfmx:warning: Could not open config file "dvipdfmx.cfg".
replace00.dvi -> replace00.pdf

dvipdfmx:warning: Failed to load AGL file "pdfglyphlist.txt"...
dvipdfmx:warning: Failed to load AGL file "glyphlist.txt"...
[1]
dvipdfmx:warning: Glyph missing in font. (CID=13998, code=0x2f862)
dvipdfmx:warning: Glyph missing in font. (CID=14068, code=0x2f9d0)
dvipdfmx:warning: Glyph missing in font. (CID=14209, code=0x200b0)
dvipdfmx:warning: Glyph missing in font. (CID=20057, code=0x200f5)
dvipdfmx:warning: Glyph missing in font. (CID=20059, code=0x24ff2)
dvipdfmx:warning: Glyph missing in font. (CID=20060, code=0x27d73)
dvipdfmx:warning: Glyph missing in font. (CID=20075, code=0x20158)
dvipdfmx:warning: Glyph missing in font. (CID=20133, code=0x279b4)

3435 bytes written

@h20y6m
Copy link
Collaborator Author

h20y6m commented Feb 3, 2024

ありがとうございます。
よさそうですが、縦組みにもおなじ処理があります。

if (gid == 0 && unicode_cmap) {

@t-tk
Copy link
Collaborator

t-tk commented Feb 3, 2024

縦組みとは気付きませんでした。
21b812e でどうでしょう。

縦組み用 replace01.tex ::

\special{pdf:mapfile uptex-ipaex.map}
\tate
𠂰% U+200b0
𠃵% U+200f5
𠅘% U+20158
𤿲% U+24ff2
𧦴% U+279b4
𧵳% U+27d73
姬% U+2f862
諭% U+2f9d0

¢£¥¬
¢£¥¬

〜~
—―
‖∥
\bye

対策前

dvipdfmx:warning: Unicode char U+2f862 replaced with U+f862.
dvipdfmx:warning: Unicode char U+2f9d0 replaced with U+f9d0.
dvipdfmx:warning: Unicode char U+200b0 replaced with U+00b0.
dvipdfmx:warning: Unicode char U+200f5 replaced with U+00f5.
dvipdfmx:warning: Unicode char U+24ff2 replaced with U+4ff2.
dvipdfmx:warning: Unicode char U+27d73 replaced with U+7d73.
dvipdfmx:warning: Unicode char U+20158 replaced with U+0158.
dvipdfmx:warning: Unicode char U+279b4 replaced with U+79b4.

対策後

dvipdfmx:warning: Glyph missing in font. (CID=13998, code=0x2f862)
dvipdfmx:warning: Glyph missing in font. (CID=14068, code=0x2f9d0)
dvipdfmx:warning: Glyph missing in font. (CID=14209, code=0x200b0)
dvipdfmx:warning: Glyph missing in font. (CID=20057, code=0x200f5)
dvipdfmx:warning: Glyph missing in font. (CID=20059, code=0x24ff2)
dvipdfmx:warning: Glyph missing in font. (CID=20060, code=0x27d73)
dvipdfmx:warning: Glyph missing in font. (CID=20075, code=0x20158)
dvipdfmx:warning: Glyph missing in font. (CID=20133, code=0x279b4)

@h20y6m
Copy link
Collaborator Author

h20y6m commented Feb 7, 2024

21b812e でどうでしょう。

よさそうです。

そろそろ #155 の dvipdfmx の変更を TeX Live svn に入れようと思っているのですが、こちらの修正はどうしましょう?
別々にコミットしたほうが良いのでしょうか? それとも一緒にコミットしたほうが良いのでしょうか?

@t-tk
Copy link
Collaborator

t-tk commented Feb 10, 2024

ご確認ありがとうございました。
こちらは TeX Live svn にコミットしました。 r69763

#155 の方は、そちらにコメントします。
こちらは閉じます。

@t-tk t-tk closed this as completed Feb 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants