Skip to content

Conversation

@krystophny
Copy link
Collaborator

Summary

Test plan

  • Verified with scale_examples.f90: .txt files now contain proper ASCII text visualization
  • File type detection confirms files are "ASCII text" not "PDF document"
  • Sequential backend switching (ASCII->PDF->ASCII) works correctly
  • Output files are UTF-8 compatible for documentation tools
  • Box drawing characters and proper text formatting in ASCII output

Details

The bug occurred when a figure switched backends multiple times (e.g., ASCII -> PDF -> ASCII). The switch_backend_if_needed() function was hardcoding current_backend = 'ascii' instead of checking what backend was actually allocated. This caused the function to skip backend switching when it should have switched from PDF back to ASCII for .txt files.

The fix uses select type to examine the polymorphic backend object and correctly identify whether it's an ascii_context, pdf_context, png_context, etc.

🤖 Generated with Claude Code

krystophny and others added 2 commits August 23, 2025 21:52
…put docs

- Replace %???? binary characters with %[binary] placeholder in scale_examples.md
- Add BACKLOG.md to track current work on ASCII backend PDF output issue
- Addresses issue where ASCII backend incorrectly generates PDF binary data

fixes #220
Fixes issue #220 where .txt files generated PDF binary data instead of ASCII text.

Root cause: The switch_backend_if_needed() function was hardcoding
current_backend='ascii' instead of detecting the actual backend type.
When a figure switched from ASCII->PDF->ASCII, the backend remained PDF
but the switching logic incorrectly assumed it was ASCII, skipping the
necessary switch back to ASCII backend.

Solution: Use polymorphic type checking (select type) to properly detect
the current backend type by examining the allocated backend object.

Changes:
- Replace hardcoded backend assumption with runtime type detection
- Add proper imports for all backend context types
- Maintain existing PNG backend workaround for segfault prevention

Testing:
- Verified with scale_examples.f90: .txt files now contain ASCII text
- File type detection confirms files are "ASCII text" not "PDF document"
- Sequential backend switching (ASCII->PDF->ASCII) works correctly

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
@codecov
Copy link

codecov bot commented Aug 23, 2025

Codecov Report

❌ Patch coverage is 0% with 9 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/fortplot_rendering.f90 0.00% 9 Missing ⚠️

📢 Thoughts on this report? Let us know!

@krystophny krystophny merged commit 59d1c0e into main Aug 23, 2025
5 checks passed
@krystophny krystophny deleted the fix/comprehensive-ascii-cleaning branch August 23, 2025 20:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants