A bespoke SVG to PDF/PNG renderer for the GlycoDraw platform
Project description
glycorender
A bespoke SVG to PDF/PNG renderer for the GlycoDraw platform, specialized in accurately rendering glycan structures with support for chemical notations and path-based text positioning.
Features
- Accurate SVG to PDF and PNG conversion for glycan structures
- Support for text on paths with proper positioning and orientation
- Special handling for monosaccharide properties like "Df" with proper styling
- Gradient fills for circles and shapes
- Precise connection path rendering between glycan elements
- Support for various SVG path commands
Installation
pip install glycorender
Quick Start
from glycorender import convert_svg_to_pdf, convert_svg_to_png
# Convert SVG file to PDF
with open('glycan_structure.svg', 'r') as f:
svg_data = f.read()
convert_svg_to_pdf(svg_data, 'output.pdf')
# Convert SVG file to PNG
convert_svg_to_png(svg_data, 'output.png')
# Or directly from SVG data
svg_data = """..."""
convert_svg_to_pdf(svg_data, 'output.pdf')
convert_svg_to_png(svg_data, 'output.png')
Use Cases
GlycoRender is specifically designed for:
- Converting glycan structure diagrams from GlycoDraw to publication-quality PDFs or PNGs
- Preserving the exact layout and styling of complex carbohydrate representations
- Ensuring chemical notations are properly formatted in the output
- Maintaining the correct connections between monosaccharide units
API Reference
convert_svg_to_pdf(svg_data, pdf_file_path)
Converts SVG data to a PDF file.
Parameters:
svg_data(str or bytes): SVG content either as a string or bytespdf_file_path(str): Path where the output PDF should be saved
convert_svg_to_png(svg_data, png_file_path)
Converts SVG data to a PNG file.
Parameters:
svg_data(str or bytes): SVG content either as a string or bytespng_file_path(str): Path where the output PNG should be saved
Supported SVG Elements
<path>: Full support for path commands (M, L, H, V, Z, etc.)<circle>: Support for basic circles and gradient-filled circles<rect>: Support for rectangles with stroke and fill<text>and<textPath>: Support for text placement along paths with proper orientation<defs>: Support for path and gradient definitions<radialGradient>: Support for radial gradients with stops
Dependencies
- ReportLab: For PDF generation
- PyMuPDF: For PNG conversion
- Pillow: For PNG metadata injection
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file glycorender-0.2.5.tar.gz.
File metadata
- Download URL: glycorender-0.2.5.tar.gz
- Upload date:
- Size: 123.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.19
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9af84c22e8a39f3f9fe4b15ccad20123b584e5d75cf82f3b089fc0ccaaa29333
|
|
| MD5 |
427698fff62fd0d6f1c32725a09cb214
|
|
| BLAKE2b-256 |
48e5ecae0b9cc7aec89899064e4aa55b9ba3c14434896bb6a3afbefa140e3fad
|
File details
Details for the file glycorender-0.2.5-py3-none-any.whl.
File metadata
- Download URL: glycorender-0.2.5-py3-none-any.whl
- Upload date:
- Size: 121.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.19
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f84106cca2a42052981b1a1fe8baa2c7655cdcb44de40a75b30af16750899ec5
|
|
| MD5 |
f662269f89cd6fad6dc6a1ddc623073e
|
|
| BLAKE2b-256 |
492dcd7ae6e2655760eec8612ed39981f4a74d977e635358045e204c5c13b387
|