Explore logical Unicode PDF encoding with exact ToUnicode
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 5/5
- Tiempo estimado
- Más de una semana
- Aptitud para principiantes
- 25/100
Línea de trabajo
The issue shares external Typst and Krilla implementations, including logical text code and an architecture document, but does not identify an OpenPDF file or define a requested change. Read the linked Krilla architecture and logical text implementation to understand the proposal; a concrete OpenPDF task would need to specify an integration point and acceptance criteria.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
I am sharing an Enhanced Unicode PDF architecture developed for Typsastra. This is not a request for OpenPDF to adopt it, but a working reference that may be useful for future Unicode PDF encoding work, particularly as an alternative to relying on /ActualText.
The implementation was motivated by Khmer support but is script-independent and has been tested with multilingual complex-script content.
Implementations
Typst adapter
Converts already-shaped text into source-ordered logical units:
- Fork: https://github.com/Sovichea/typst
- Tested revision:
https://github.com/Sovichea/typst/tree/75202cf09a26a5ef5dfd0f26ab7a4fe007e1be39 - Logical-unit preparation:
https://github.com/Sovichea/typst/blob/75202cf09a26a5ef5dfd0f26ab7a4fe007e1be39/crates/typst-pdf/src/text/logical.rs
Krilla PDF backend
Implements logical CID allocation, synthetic TrueType glyphs, exact /ToUnicode, font sharding, and logical-order TJ output:
- Fork: https://github.com/Sovichea/krilla
- Tested revision:
https://github.com/Sovichea/krilla/tree/d05158cf3ebead248745f846d0397e84dfb9f2d0 - Architecture document:
https://github.com/Sovichea/krilla/blob/d05158cf3ebead248745f846d0397e84dfb9f2d0/PDF_LOGICAL_UNITS.md - Logical text implementation:
https://github.com/Sovichea/krilla/blob/d05158cf3ebead248745f846d0397e84dfb9f2d0/crates/krilla/src/text/logical.rs - Logical font mapper:
https://github.com/Sovichea/krilla/blob/d05158cf3ebead248745f846d0397e84dfb9f2d0/crates/krilla/src/text/logical_font.rs
Architecture
The boundary between shaping and PDF generation is a source-ordered logical unit:
STRUCT LogicalUnit
text: exact logical Unicode
glyphs: already-shaped positioned glyphs
visual_position: independent x and y position
END STRUCT
The contract is:
- logical text is authoritative for extraction and accessibility;
- glyphs are authoritative for appearance;
- units remain in source order;
- the PDF backend does not reshape the text.
flowchart LR
A[Logical Unicode]
B[Existing shaping engine]
C[Positioned glyphs]
D[Logical units]
E[Semantic and visual key]
F[Unique logical CID]
G[Synthetic glyph]
H[Exact ToUnicode]
I[Logical-order TJ]
J[PDF]
A --> B
B --> C
C --> D
D --> E
E --> F
F --> G
F --> H
G --> I
H --> I
I --> J
A CID is reused only when both the logical text and visual construction are identical:
semantic_key := exact Unicode + positioned glyph construction
IF semantic_key already exists
reuse its CID
ELSE
allocate a new CID
create a synthetic composite glyph
map the CID to exact Unicode through ToUnicode
END IF
Each synthetic glyph contains the unit’s shaped source glyphs as positioned TrueType components. Logical CIDs are then emitted in source order, with TJ adjustments reproducing visual placement.
Unsupported units fall back to ordinary glyph output rather than failing the document.
Possible relevance to OpenPDF
The smallest possible integration boundary would be a low-level API accepting externally shaped logical units:
INPUT
source font
exact Unicode text
positioned glyphs
OUTPUT
logical CID
synthetic visual glyph
exact ToUnicode mapping
This would not require OpenPDF to replace its shaping engine or redesign paragraph layout. OpenPDF’s existing Java2D GlyphVector output could potentially be adapted to the same interface later.
Test binary
A prebuilt Typst-compatible binary is available for testing:
https://github.com/Sovichea/typsastra/releases/tag/enhanced-unicode-v0.3.1
It supports Windows, Linux, and macOS. After downloading the appropriate archive:
typst compile input.typ output.pdf
pdftotext -enc UTF-8 output.pdf output.txt
Relevant fixture:
There is no expectation that OpenPDF adopt this implementation. I am sharing it as a tested architecture that may provide useful ideas for exact Unicode /ToUnicode encoding without depending on /ActualText.
- 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
-
enhancement
Dificultad 5/5 Más de una semana Aptitud para principiantes 38/100
-
Dificultad 4/5 1-2 días Aptitud para principiantes 45/100
Todos los issues de LibrePDF/OpenPDF
Issues similares
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 80/100
OpenAPITools/openapi-generator#25454 ·
Los mantenedores suelen responder en 1 día
-
Component - Build
Dificultad 2/5 1-3 horas Aptitud para principiantes 75/100
Los mantenedores suelen responder en 1 día
-
Update the Russian localizationAbierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 62/100
-
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