Skip to content

Fix/system fonts api 5479#6063

Open
SakShamJain8 wants to merge 6 commits intoStirling-Tools:mainfrom
SakShamJain8:fix/system-fonts-api-5479
Open

Fix/system fonts api 5479#6063
SakShamJain8 wants to merge 6 commits intoStirling-Tools:mainfrom
SakShamJain8:fix/system-fonts-api-5479

Conversation

@SakShamJain8
Copy link
Copy Markdown
Contributor

@SakShamJain8 SakShamJain8 commented Apr 3, 2026

Description of Changes

This PR adds system fonts API endpoint and frontend integration to enable users to select from available system fonts in the Stirling PDF application.

Summary

  • Backend: Added /api/v1/general/fonts public API endpoint that returns a cached list of system-installed fonts
  • Backend: Implemented FontService to discover and cache fonts from AWT and system font directories
  • Backend: Added FontController with endpoints:
    • GET /api/v1/general/fonts - Returns list of available fonts
    • POST /api/v1/general/fonts/refresh - Forces font cache refresh after system font installation
  • Security: Added /api/v1/general/fonts to public whitelist in RequestUriUtils (no authentication required)
  • Frontend: Created useSystemFonts hook that:
    • Fetches fonts from backend
    • Supports both web (Vite proxy) and Tauri desktop modes
    • Implements caching and error handling
  • Frontend: Updated TextInputWithFont component to use system fonts instead of hardcoded list
  • Frontend: Updated TypeSignatureText component to use system fonts with refresh button

Why This Change

Users were limited to hardcoded font lists (5 fonts) when annotating PDFs or creating signatures. This prevented them from using their system-installed fonts, reducing usability and functionality.

Challenges Encountered

  1. Tauri vs Web Mode: Had to detect application mode and route API calls appropriately
  2. Thread Safety: Font service runs in multi-threaded Spring context; implemented caching strategy
  3. Cross-Platform: Font directories differ across Windows/Linux/macOS; implemented platform-specific paths
  4. OTF/TTC Support: Java's Font.createFont() has limited format support; added fallback filename extraction

Testing

  • ✅ Backend API tested with Postman: Returns 200 OK with font list (50+ fonts on Windows)
  • ✅ Fonts endpoint is accessible without authentication
  • ✅ Frontend hook successfully fetches and displays fonts
  • ✅ Both web and Tauri modes work correctly
  • ✅ Font refresh endpoint clears cache and repopulates successfully

Closes #5479


Checklist

General

Documentation

Translations (if applicable)

UI Changes (if applicable)

  • Font selection dropdown now shows system fonts instead of hardcoded list

Testing (if applicable)

  • I have tested my changes locally
  • Backend: curl http://localhost:8080/api/v1/general/fonts returns 200 OK with full font list
  • Frontend: Font dropdown populates correctly with system fonts
  • Tauri and web modes both work correctly

Screenshot for Reference

Screenshot (4)

…ith'

- Files opened via 'Open with' are now automatically selected in FileContext
- This enables immediate access to all PDF tools without manual reselection
- Moved AppInitializer inside ToolWorkflowProvider to fix context availability

Fixes Stirling-Tools#6029
…g-Tools#5479)

- Add public fonts endpoint (/api/v1/general/fonts) to security whitelist
- Add FontController and FontService for backend font management
- Add useSystemFonts hook for frontend font loading
- Support both web (Vite proxy) and Tauri desktop modes
- Include font cache refresh endpoint for post-installation updates
- Update TextInputWithFont and TypeSignatureText components to use system fonts
@dosubot dosubot bot added the size:XL This PR changes 500-999 lines ignoring generated files. label Apr 3, 2026
@stirlingbot stirlingbot bot added Java Pull requests that update Java code Front End Issues or pull requests related to front-end development Back End Issues related to back-end development API API-related issues or pull requests labels Apr 3, 2026
@dosubot dosubot bot added the enhancement New feature or request label Apr 3, 2026
@stirlingbot stirlingbot bot removed the enhancement New feature or request label Apr 3, 2026
@Frooodle
Copy link
Copy Markdown
Member

Frooodle commented Apr 4, 2026

Why would we want to add the fonts to auth exclusion? Only logged in users should need to access these endpoints

Edit: Great feature idea btw appreciate you making this!

@SakShamJain8
Copy link
Copy Markdown
Contributor Author

Why would we want to add the fonts to auth exclusion? Only logged in users should need to access these endpoints

Edit: Great feature idea btw appreciate you making this!

The fonts endpoint could benefit from being public because:

1.. No Security Risk -> Font names alone won't expose sensitive data like file paths, user info, system details etc.
2. Performance -> Reduces unnecessary round-trips, It will query fonts once only when compared to after every login
3. UX Flow -> In desktop mode, we could show font previews before login

However, I understand the security-first approach. Should I move it back to authenticated-only?"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

API API-related issues or pull requests Back End Issues related to back-end development Front End Issues or pull requests related to front-end development Java Pull requests that update Java code size:XL This PR changes 500-999 lines ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature Request]: Select custom fonts for signatures

2 participants