MS明朝のRTFデータをHTMLにコンバートすると、異なるfont-familyが適用されている

RTFデータをHTMLにコンバートしていますが、MS明朝が正しくコンバートされない場合があります。
Windows環境で実行してみると正しく動作しますが、Linux環境では正しく動作しません。
失敗するRTFファイルをアップロードします。
body1.rtfが、"MS ゴシック"となり、body2.rtfが、"Times New Roman"になります。body.zip (794 Bytes)

何か正しく変換する方法はありませんか。変換時のプログラムは以下のとおりです。
RtfLoadOptions loadOptions = new RtfLoadOptions();
loadOptions.setLoadFormat(LoadFormat.RTF);

Document doc = new Document(rtf, loadOptions);

HtmlSaveOptions saveOptions = new HtmlSaveOptions();
saveOptions.setSaveFormat(SaveFormat.HTML);
saveOptions.setEncoding(StandardCharsets.UTF_8);
saveOptions.setHtmlVersion(HtmlVersion.HTML_5);
saveOptions.setExportImagesAsBase64(true);

doc.save(html, saveOptions);

@yasufumi_hayashi

ドキュメントをHTMLに変換するマシンに、ドキュメントで使用されているフォントをインストールする必要があります。 それでも問題が発生する場合は、テスト用にドキュメントで使用されているフォントをここに圧縮して添付してください。

追加でご教示ください。

RTFデータが大量にあるため、全てのRTFで利用されているフォントを調査し、変換マシンに全フォントをインストールすることができません。
ですので、フォントがインストールされていない状態で変換したときの影響を調査しています。

・変換マシンにインストールされていなければ、
HTML変換時にRTF時とは異なるfont-familyが適用されるフォントを教えてください
・上記フォントの場合、どのようなfont-familyが適用されるか教えてください

よろしくお願いします。

@chikashihayashi, 次のコードを使用して、変換中に置換されたフォントを確認できます:

    public static void main(String[] args) throws Exception {
        Document doc = new Document("in.rtf");

        FontSubstitutionWarningCollector callback = new FontSubstitutionWarningCollector();
        doc.setWarningCallback(callback);

        doc.save("out.html");

        // Print the font substitution warnings.
        for (WarningInfo info : callback.FontSubstitutionWarnings) {
            System.out.println(info.getDescription());
        }

        // Iterate all substituted fonts.
        for (String substitutedFont : callback.SubstitutedFonts.keySet()) {
            String message = String.format("Missing font %s has been substituted with %s.",
                    substitutedFont, callback.SubstitutedFonts.get(substitutedFont));
            System.out.println(message);
        }
    }

    private static class FontSubstitutionWarningCollector implements IWarningCallback {
        /// <summary>
        /// Called every time a warning occurs during loading/saving.
        /// </summary>
        public void warning(WarningInfo info) {
            if (info.getWarningType() == WarningType.FONT_SUBSTITUTION)
            {
                FontSubstitutionWarnings.warning(info);

                // Extract font names from the warning.
                Pattern pattern = Pattern.compile("'(.*?)'");
                Matcher matcher = pattern.matcher(info.getDescription());
                if (matcher.find())
                {
                    String substitutedFont = matcher.group(1);
                    if (matcher.find()) {
                        String substitutionFont = matcher.group(1);

                        SubstitutedFonts.put(substitutedFont, substitutionFont);
                    }
                }
            }
        }

        public WarningInfoCollection FontSubstitutionWarnings = new WarningInfoCollection();
        public Hashtable<String, String> SubstitutedFonts = new Hashtable<String, String>();
    }

FontSubstitutionSettingsを使用して、フォント置換のルールを指定できます。 ドキュメントの例を確認してください。

教えていただいたコードでWarningを出力しましたが、MS明朝に対する記載はありませんでした。
以下が出力結果です。

Font ‘Calibri’ has not been found. Using ‘Liberation Sans’ font instead. Reason: table substitution.
Font ‘MS ゴシック’ has not been found. Using ‘VL Gothic’ font instead. Reason: table substitution.
Font ‘Times New Roman’ has not been found. Using ‘FreeSerif’ font instead. Reason: table substitution.
Font ‘Arial’ has not been found. Using ‘Liberation Sans’ font instead. Reason: table substitution.
Missing font Calibri has been substituted with Liberation Sans.
Missing font Times New Roman has been substituted with FreeSerif.
Missing font MS ゴシック has been substituted with VL Gothic.
Missing font Arial has been substituted with Liberation Sans.

また、FontSubstitutionSettingsを使い異なるフォントに変更しようと試しましたが、結果は変わりませんでした。どこかおかしなところがあるのでしょうか。

RtfLoadOptions loadOptions = new RtfLoadOptions();
loadOptions.setLoadFormat(LoadFormat.RTF);
com.aspose.words.Document doc = new com.aspose.words.Document(fileRtf, loadOptions);

doc.setFontSettings(new FontSettings());
FontSubstitutionSettings settings = doc.getFontSettings().getSubstitutionSettings();
settings.getFontInfoSubstitution().setEnabled(true);
settings.getTableSubstitution().addSubstitutes("MS 明朝", "VL Gothic");

HtmlSaveOptions saveOptions = new HtmlSaveOptions();
saveOptions.setSaveFormat(SaveFormat.HTML);
saveOptions.setHtmlVersion(HtmlVersion.HTML_5);
saveOptions.setEncoding(StandardCharsets.UTF_8);
saveOptions.setExportImagesAsBase64(true);

doc.save(fileRtf.replaceAll("rtf", "html"), saveOptions);

@yasufumi_hayashi, コードをテストしたドキュメントは何ですか? サンプルドキュメントを添付していただけますか?

Aspose.Wordsのどのバージョンを使用していますか?

使用したドキュメントは、最初に添付した body.zip になります。
Aspose.Wordsのバージョンは 21.10.0 になります。

@yasufumi_hayashi, 問題を再現できません。 WSL on Windows 10にインストールされている Arch Linuxで以下のコードを実行してみました。

コードを実行する前に、「VLゴシック」フォントを〜 /.local/share/fonts にコピーしてインストールしました。 Iosevkaフォントは、/usr/share/fontsにインストールされているArchLinuxの標準フォントです。

public class Main {
    public static void main(String[] args) throws Exception {
        License lic = new License();
        lic.setLicense("Aspose.Words.Java.lic");

        String docPath = "body1.rtf";
        System.out.println(docPath);
        Document doc = new Document(docPath);

        FontSubstitutionWarningCollector callback = new FontSubstitutionWarningCollector();
        doc.setWarningCallback(callback);

        HtmlSaveOptions saveOptions = new HtmlSaveOptions();
        saveOptions.setSaveFormat(SaveFormat.HTML);
        saveOptions.setHtmlVersion(HtmlVersion.HTML_5);
        saveOptions.setEncoding(StandardCharsets.UTF_8);
        saveOptions.setExportImagesAsBase64(true);

        doc.save("body1.aspose.words.21.10.html", saveOptions);
    }

    private static class FontSubstitutionWarningCollector implements IWarningCallback {
        /// <summary>
        /// Called every time a warning occurs during loading/saving.
        /// </summary>
        public void warning(WarningInfo info) {
            if (info.getWarningType() == WarningType.FONT_SUBSTITUTION)
            {
                System.out.println(info.getDescription());
            }
        }
    }
}

コードを実行するためのコマンド:
/usr/lib/jvm/java-18-jdk/bin/java -Dfile.encoding=UTF-8 -classpath /<path_to_project>:/<path_to>/aspose-words-21.10.0-jdk17.jar Main

出力は次のとおりです:
/<path_to>/body1.rtf

Font 'MS ゴシック' has not been found. Using 'VL Gothic' font instead. Reason: font info substitution.
Font 'MS 明朝' has not been found. Using 'VL Gothic' font instead. Reason: font info substitution.
Font 'Arial' has not been found. Using 'Iosevka Nerd Font Mono' font instead. Reason: font info substitution.

ご覧のとおり、置換されたフォントの中にMS 明朝が表示されています。

先に進む前に、問題を再現する必要があります。

オペレーティングシステムとJDKのバージョンは何ですか?
問題を示すDockerイメージを作成できれば素晴らしいと思います。

@dshvydkiy, ご確認いただきありがとうございます。
OSは、CentOS 7.4です。
JDKは、zulu-8-8.62.0.19-1.x86_64(openjdk version “1.8.0_332”) を利用しています。
フォントを local にコピーしないといけないのでしょうか。
dockerを作るのにはチャレンジしてみようと思いますが、一旦、お伝えしておきます。

@yasufumi_hayashi, はい、フォントをDockerイメージにコピーしてください。