Skip to content

Guess font name and attribute from file nam is not correct, especially for CJK fonts. #6

Description

@chunlinyao

CSSBoxPdf guess font file url by matching file name and font family name. It's not correct especially for CJK font. I suggest using FontMapper to get font.

Change PDFRender#setFont like this. It is still a POC.

    /**
     * Creates object describing font
     * 
     * @return the font object
     */
    private PDFont setFont(String fontFamily, boolean isItalic, boolean isBold)
    {
        COSDictionary dictionary = new COSDictionary();
        dictionary.setItem( COSName.TYPE, COSName.FONT_DESC );
        PDFontDescriptor desc = new PDFontDescriptor(dictionary);
        desc.setItalic(isItalic);
        desc.setFontWeight(isBold? 700: 400);
        desc.setFontFamily(fontFamily);
        FontMapping<TrueTypeFont> trueTypeFont = FontMappers.instance().getTrueTypeFont(fontFamily, desc);

        PDFont font = null;
        if (trueTypeFont != null) {
            try {
                font = PDType0Font.load(doc, trueTypeFont.getFont(), true);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return font;
    }

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions