Add support for custom fonts in SVG and PNG
- Dominant language
- C++
- Stars
- 406
- Forks
- 134
- Avg merge
- 2d 11h
- Merged PRs (30d)
- 24
Description
Currently Indigo uses single default font for text objects while saving chemical drawing to SVG or PNG.
Enhance font rendering functionality as follows:
1. Extend Indigo SVG/PNG rendering API with optional parameter -- **font object in TTF format**. If the font is provided, it should be used for rendering texts.
2. For SVG rendering the font characters should be converted to **glyph** objects to ensure rendering and scaling quality.
If bounding box for a text object is specified, apply the following wrapping rules:
1. Wrap the text to the next line if it doesn't fit the width of the bounding box.
2. If specified bounding box width is less than the width of the first symbol in the rendered text line, the symbol should be rendered ignoring bonding box width.
3. If a new line of text doesn't fit the height of the bounding box and it is not the first line, the rest of text including this line should not be rendered. The top line of text should be rendered even if doesn't fit the height of the bounding box.
**Agreed approach:**
Ketcher sends custom TTF fonts directly in **POST /v2/indigo/render** via **options.fonts** with bundled JSON string.
```
{
"options": {
"fonts": "[
{
"name": "Arial Bold",
"data": ""
},
{
"name": "Arial Italic",
"data": ""
}
]"
}
}
```
**data** contains the Base64-encoded TTF file.
**name** is used only for logging/debugging and does not affect font selection.
Indigo parses the supplied fonts with FreeType and detects their style.
For each KET text part, Indigo selects the first matching font face based on existing **bold / italic** flags.
{
"text": "test",
"bold": true,
"italic": true
}
This should use the first supplied **bold italic** font face.
If no matching custom font is available, Indigo falls back to the existing default rendering.
**Acceptance criteria:**
* Update render() REST API to
`utils/indigo-service/backend/service/v2/indigo_api.py`
* Update render() WASM
`api/wasm/indigo-ketcher/indigo-ketcher.cpp`
* Python integration tests updated, indigo-service and wasm tests
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.