Non-styled versions of TTF fonts are chosen and artificially styled over available styled versions
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Idoneità per principianti
- 35/100
Direzione di ricerca
Start by tracing how FontFactory.register and FontFactory.getFont handle the registered Roboto style names and the supplied style flags. The report provides a Java reproduction using regular, italic, bold, and bold-italic TTF files, but names no source file or test. Done means the italic and bold-italic requests use their matching font files and render with the expected weight and angle.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Describe the bug
I'm observing something similiar to what #244 described: I'm registering a bunch of TTF files (Roboto) in different styles from the class path and trying to use these. However, OpenPDF seems to choose the regular (non-styled) font file and apply all necessary styles to it instead of using the styled version in the first place.
To Reproduce
Put the Roboto files (regular, italic, bold, bold-italic; downloadable from Google Fonts) onto the classpath (e.g., the resources folder when using maven) and register them like so:
// In a class file
private static final Font ROBOTO_BOLD_ITALIC;
private static final Font ROBOTO_BOLD;
private static final Font ROBOTO_ITALIC;
private static final Font ROBOTO_REGULAR;
static {
URL robotoRegularUrl = Thread.currentThread ().getContextClassLoader ().getResource ("fonts/Roboto-Regular.ttf");
URL robotoBoldUrl = Thread.currentThread ().getContextClassLoader ().getResource ("fonts/Roboto-Bold.ttf");
URL robotoItalicUrl = Thread.currentThread ().getContextClassLoader ().getResource ("fonts/Roboto-Italic.ttf");
URL robotoBoldItalicUrl = Thread.currentThread ().getContextClassLoader ().getResource ("fonts/Roboto-BoldItalic.ttf");
// Obviously check if any of those URLs is null
try {
FontFactory.register (robotoBoldItalicUrl.toExternalForm (), "Roboto-BoldItalic");
FontFactory.register (robotoItalicUrl.toExternalForm (), "Roboto-Italic");
FontFactory.register (robotoBoldUrl.toExternalForm (), "Roboto-Bold");
FontFactory.register (robotoRegularUrl.toExternalForm (), "Roboto");
ROBOTO_BOLD_ITALIC = FontFactory.getFont ("Roboto-BoldItalic", BaseFont.IDENTITY_H, true, 10, Font.BOLDITALIC);
ROBOTO_BOLD = FontFactory.getFont ("Roboto-Bold", BaseFont.IDENTITY_H, true, 10);
ROBOTO_ITALIC = FontFactory.getFont ("Roboto-Italic", BaseFont.IDENTITY_H, true, 10);
ROBOTO_REGULAR = FontFactory.getFont ("Roboto", BaseFont.IDENTITY_H, true, 10);
} catch (Exception e) {
e.printStackTrace ();
throw new IllegalStateException (e);
}
}
This will lead to all files being read. Using them like new Paragraph ("text", ROBOTO_BOLD_ITALIC); will (apparently) not use the file previously read, but rather the regular one and OpenPDF will apply all given styles to that one. This is judging by the looks of the outcome, it looks just like the PDF displayed in #244.
Curiously, if I don't specify styles at all in FontFactory.getFont, then OpenPDF will only use ROBOTO_REGULAR whenever ROBOTO_ITALIC or ROBOTO_BOLD_ITALIC should have been used. ROBOTO_BOLD works as expected though.
Expected behavior
Italic and Bold-Italic should work as expected, using the correct file supplied for them.
Screenshots
This is produced by OpenPDF:
This is as displayed in-browser on Google Fonts:
This is as displayed in LibreOffice:
Obviously, OpenPDF's output looks just wrong: Notice the stroke weight and inclination angle.
System
- OS: Linux (OpenSuSE Tumbleweed)
- Used font: Roboto
- OpenPDF version: 2.0.1 (cannot upgrade due to this issue)
- Lingua principale
- Java
- Stelle
- 4.4k
- Fork
- 714
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di LibrePDF/OpenPDF
-
bug
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 88/100
-
IndexOutOfBoundsException in PdfReaderForse già presa @andreasrosdalw l’ha presa 93 giorni fa. Apertabug
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
-
`PdfSmartCopy` can take effectively unbounded time on nested shared Form XObjectsForse già presa Una pull request collegata a questa issue è aperta o già unita. Apertabug
Difficoltà 4/5 3-5 giorni Idoneità per principianti 48/100
-
Difficoltà 5/5 Più di una settimana Idoneità per principianti 25/100
-
enhancement
Difficoltà 5/5 Più di una settimana Idoneità per principianti 38/100
Tutte le issue di LibrePDF/OpenPDF
Issue simili
-
priority: medium Review effort [1-5]: 3 status: needs-triage type: bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
carlos-emr/carlos#5431 ·
I maintainer di solito rispondono entro 1 giorno
-
Integration tests: jetty:run fails with WELD-001408 for CountryJpaServiceForse già presa @viniciusmachak l’ha presa oggi. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 66/100
primefaces/primefaces#15431 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 80/100
OpenAPITools/openapi-generator#25454 ·
I maintainer di solito rispondono entro 1 giorno
-
Component - Build
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100