danfickle / danfickle/openhtmltopdf
Font weight and style resolving inconsistencies
- Dominant language
- Java
- Stars
- 2.2k
- Forks
- 423
- PR merge metrics
- No merged PRs in 30d
Description
In `com.openhtmltopdf.svgsupport.PDFTranscoder.OpenHtmlFontResolver`
two getWeight methods resolve the `font-weight:400` to different weight values.
```java
private Float getWeight(Integer weight) {
if (weight == null) {
return null;
}
switch (weight.intValue()) {
...
case 400:
return TextAttribute.WEIGHT_REGULAR;
...
}
}
```
```java
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:
```java
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).
```java
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.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.