Support configurable inter-word spacing limits during justified line breaking
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 5/5
- Tiempo estimado
- Más de una semana
- Aptitud para principiantes
- 38/100
Línea de trabajo
Start with BidiLine.processLine() and PdfDocument.writeLineToContent(), the two entry points named in the issue. Trace how candidate breakpoints and remaining width determine word spacing, then check the existing line breaking tests. Done means an opt-in policy selects legal breaks within the configured spacing limits while preserving default behavior and natural spacing on the last paragraph line.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Is your feature request related to a problem? Please describe.
When rendering justified, hyphenated paragraphs, OpenPDF chooses line breaks using text at its natural width. Once the line has been broken, the remaining width is distributed during justification.
This allows inter-word spacing to be increased, but the line-breaking algorithm does not consider placing an additional word on the line by reducing inter-word spacing.
For example, suppose two possible breaks produce:
- A hyphenated line requiring 130% inter-word spacing
- A line containing the complete next word requiring 90% inter-word spacing
The second result is typographically closer to the natural 100% spacing, but OpenPDF currently selects the first because the complete word does not fit at its natural width.
PDF supports negative word-spacing adjustments through the Tw operator, so the output format can represent the desired result. The limitation appears to be in line breaking, particularly BidiLine.processLine().
Describe the solution you'd like
Provide an optional justified line-breaking policy with configurable inter-word spacing limits, for example:
columnText.setMinimumWordSpacingRatio(0.70f);
columnText.setMaximumWordSpacingRatio(1.35f);
columnText.setPreferredWordSpacingRatio(1.00f);
For each line, the line breaker would evaluate legal breakpoints at:
- Word boundaries
- Available hyphenation points
For each candidate, it would calculate the inter-word spacing required to fill the line:
required spacing ratio = (available line width - glyph width) / natural space width
Candidates outside the configured minimum and maximum would be rejected. Among the remaining candidates, OpenPDF would select the one closest to the preferred ratio. A hyphenation penalty could optionally be applied so that otherwise similar candidates prefer an unhyphenated break. The last line of a paragraph would continue to use natural spacing, as it does currently. This should be opt-in, preserving the existing line-breaking behavior by default.
Describe alternatives you've considered
The alternatives appear to be:
- Forking OpenPDF and modifying BidiLine.
- Performing paragraph layout externally and drawing every line directly through PdfContentByte.
External layout would duplicate much of OpenPDF's handling of mixed fonts, inline formatting, bidirectional text, links, superscripts, hyphenation, and page/column transitions. A configurable implementation within OpenPDF's line breaker seems more reusable.
Your real name
Ioannis Rigopoulos
Additional context
The relevant behavior can be seen in:
- BidiLine.processLine(), which stops scanning when the next character exceeds the available natural width
- PdfDocument.writeLineToContent(), which calculates the final word and character spacing
The rendering stage already appears capable of emitting negative word spacing if a PdfLine has negative remaining width. The main change may therefore be to retain and score candidate breakpoints beyond the natural line width.
One possible initial implementation would compare:
- The existing word/hyphen break before overflow
- Hyphenation candidates
- The next complete-word boundary, if it fits within the configured minimum spacing
A paragraph-wide optimization could be considered later, but even a line-by-line candidate comparison would improve the current result considerably.
Example requirement:
- Minimum inter-word spacing: 70%
- Maximum inter-word spacing: 135%
- Preferred inter-word spacing: 100%
- Hyphenation enabled
- Lenguaje dominante
- Java
- Estrellas
- 4.4k
- Forks
- 714
- Métricas de merge de PR
- Sin PR fusionados en 30 d
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de LibrePDF/OpenPDF
-
bug
Dificultad 1/5 Menos de una hora Aptitud para principiantes 88/100
-
IndexOutOfBoundsException in PdfReaderPosiblemente ocupada @andreasrosdalw la tomó hace 93 días. Abiertobug
Dificultad 2/5 1-3 horas Aptitud para principiantes 70/100
-
`PdfSmartCopy` can take effectively unbounded time on nested shared Form XObjectsPosiblemente ocupada Un pull request vinculado a esta issue está abierto o ya se fusionó. Abiertobug
Dificultad 4/5 3-5 días Aptitud para principiantes 48/100
-
Dificultad 5/5 Más de una semana Aptitud para principiantes 25/100
-
Dificultad 4/5 1-2 días Aptitud para principiantes 45/100
Todos los issues de LibrePDF/OpenPDF
Issues similares
-
Component - Build
Dificultad 2/5 1-3 horas Aptitud para principiantes 75/100
Los mantenedores suelen responder en 1 día
-
bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 77/100
navikt/mock-oauth2-server#1149 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
oracle/graalvm-reachability-metadata#11318 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
Stirling-Tools/Stirling-PDF#8709 · 1 reacción ·
Los mantenedores suelen responder en 1 día
-
Javadoc config rendering issueAbiertoarea/config
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
quarkusio/quarkus#57910 · 1 comentario ·
Los mantenedores suelen responder en 1 día