openhtmltopdf icon indicating copy to clipboard operation
openhtmltopdf copied to clipboard

Font weight and style resolving inconsistencies

Open HerbertsVaadin opened this issue 1 year ago • 0 comments

In com.openhtmltopdf.svgsupport.PDFTranscoder.OpenHtmlFontResolver two getWeight methods resolve the font-weight:400 to different weight values.

private Float getWeight(Integer weight) {
    if (weight == null) {
        return null;
    }

    switch (weight.intValue()) {
    ...
    case 400:
        return TextAttribute.WEIGHT_REGULAR;
    ...
    }
}
Float getWeight(IdentValue weight) {
    if (weight == IdentValue.NORMAL) {
        return TextAttribute.WEIGHT_REGULAR;
    ...
    } else if (weight == IdentValue.FONT_WEIGHT_400) {
        return TextAttribute.WEIGHT_MEDIUM;
    } ...

}

WEIGHT_REGULAR=Float.valueOf(1.0f); WEIGHT_MEDIUM=Float.valueOf(1.5f);

Similar problem for resolving styles. Normal resolves to null here:

private Float getStyle(IdentValue fontStyle) {
	if (fontStyle == IdentValue.ITALIC ||
		fontStyle == IdentValue.OBLIQUE)
		return TextAttribute.POSTURE_OBLIQUE;
	
	return null;
}

Normal resolves to 0f here (which is the preffered value).

private Float getStyle(FontStyle style) {
    switch (style) {
    case ITALIC:
    case OBLIQUE:
        return TextAttribute.POSTURE_OBLIQUE;
    case NORMAL:
    default:
        return 0f;
    }
}

This causes the font not being interpreted correctly for drawing SVGs.

HerbertsVaadin avatar Sep 08 '22 15:09 HerbertsVaadin