Skip to content

Conversation

@JimBobSquarePants
Copy link
Member

Prerequisites

  • I have written a descriptive pull-request title
  • I have verified that there are no overlapping pull-requests open
  • I have verified that I am following matches the existing coding patterns and practice as demonstrated in the repository. These follow strict Stylecop rules 👮.
  • I have provided test coverage for my change (where applicable)

Description

Fixes #475
This pull request introduces several improvements and bug fixes to the advanced typographic shaping logic and font test infrastructure. The main focus is on more robust script detection and fallback handling in the OpenType GPOS/GSUB tables, as well as enhancements to test coverage and test font management.

Advanced Typographic Shaping Improvements:

  • Added a new ScriptClass.Default value to represent a fallback/default script, and updated the UnicodeScriptTagMap to include appropriate tags for this default. This allows the shaping engine to gracefully fall back to a default shaper if a script is not present in the font. [1] [2]
  • Introduced a GetScriptClass method in both GSubTable and GPosTable to determine whether the current script is supported by the font, and to return Default if not. Updated relevant shaping logic to use this method, improving script fallback handling and preventing incorrect shaping when text contains unsupported scripts. [1] [2] [3] [4] Fb617cd5L319R319, [5]
  • Updated the initialization of various collections and variables for better type clarity and to use modern C# syntax (e.g., array initializers with []). [1] [2] [3] [4] [5] [6]

Bug Fixes and Logic Corrections:

  • Fixed a logic bug in GlyphPositioningCollection.TryUpdate where the check for removing fallback glyphs now correctly uses replacementCount == 0 instead of j == 0.
  • Made LookupType2Format1SubTable a sealed class and improved variable declarations for clarity and consistency. [1] [2] [3]

Test Infrastructure and Coverage:

  • Added a new test (Issues_475) to verify correct glyph counting and fallback handling for scripts not supported by the provided fonts, ensuring no exceptions are thrown and the correct glyph count is returned.
  • Updated test font references to clarify the difference between a "bad" (malformed) font and a valid one, and added a new test font property for clarity. [1] [2]
  • Updated existing tests to use the new NotoSansSCThinBad test font where appropriate, and fixed a reference in an issue test to use the correct font. [1] [2] [3]

These changes collectively improve the robustness of script detection and fallback in font shaping, clarify test font usage, and expand test coverage for edge cases.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request fixes issue #475 by improving script detection and fallback handling in OpenType GPOS/GSUB tables to prevent infinite loops and exceptions when rendering text in scripts not supported by the font. The main changes introduce a ScriptClass.Default fallback mechanism that gracefully handles unsupported scripts.

Key Changes:

  • Introduced ScriptClass.Default as a fallback when fonts don't support a script, preventing exceptions and infinite loops
  • Added GetScriptClass method in GSubTable and GPosTable to determine script support and return Default when not present
  • Fixed a bug in GlyphPositioningCollection.TryUpdate where fallback glyph removal logic was using the wrong variable

Reviewed changes

Copilot reviewed 10 out of 14 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/SixLabors.Fonts/Unicode/ScriptClass.cs Added ScriptClass.Default enum value (999) to represent fallback script
src/SixLabors.Fonts/Tables/AdvancedTypographic/UnicodeScriptTagMap.cs Added mappings for Default script to DFLT/dflt/latn tags; simplified Lazy initialization
src/SixLabors.Fonts/Tables/AdvancedTypographic/GSubTable.cs Added GetScriptClass method for script fallback; updated to use modern collection initializers
src/SixLabors.Fonts/Tables/AdvancedTypographic/GPosTable.cs Added GetScriptClass method for script fallback; updated to use modern collection initializers
src/SixLabors.Fonts/Tables/AdvancedTypographic/GSub/LookupType2SubTable.cs Made class sealed; updated variable declarations to use explicit types
src/SixLabors.Fonts/GlyphPositioningCollection.cs Fixed bug: replaced j == 0 with replacementCount == 0 for correct fallback glyph removal
tests/SixLabors.Fonts.Tests/TestFonts.cs Renamed NotoSansSCThinFile to NotoSansSCThinBad and added new NotoSansSCThin property for clarity
tests/SixLabors.Fonts.Tests/Issues/Issues_475.cs Added regression test verifying no exceptions with unsupported scripts and correct glyph count
tests/SixLabors.Fonts.Tests/Issues/Issues_469.cs Updated to use correct NotoSansSCThin font reference
tests/SixLabors.Fonts.Tests/FontMetricsTests.cs Updated to use renamed NotoSansSCThinBad font
tests/SixLabors.Fonts.Tests/Fonts/NotoSansSC-Thin-Bad.ttf Font file renamed from NotoSansSC-Thin.ttf for clarity

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review for a chance to win a $100 gift card. Take the survey.

@JimBobSquarePants JimBobSquarePants merged commit aefb967 into main Nov 26, 2025
23 checks passed
@JimBobSquarePants JimBobSquarePants deleted the js/fix-475 branch November 26, 2025 04:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Text rendering never end with some specific characters with fallback font

2 participants