Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bidi + Font Shaping Support #198

Merged
merged 340 commits into from
Nov 10, 2021
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
340 commits
Select commit Hold shift + click to select a range
2dd9cd0
Update AppliedFontStyle.cs
JimBobSquarePants Sep 14, 2021
6d9521c
Add tests for substitutions (not all are covered yet)
brianpopow Sep 14, 2021
0752255
Fix typo in method name
brianpopow Sep 14, 2021
ce5407a
Fix typo's in method names
brianpopow Sep 14, 2021
08f1d5c
Implement loading GPOS LookupType1Format2SubTable
brianpopow Sep 14, 2021
073246b
Fix xml comment
brianpopow Sep 14, 2021
76b5fbd
Add ligature substitution test
brianpopow Sep 14, 2021
6096aa6
Implement LookupType1Format2SubTable
JimBobSquarePants Sep 14, 2021
7c8e047
Add layout mode.
JimBobSquarePants Sep 14, 2021
3513c67
Add GPos unit test
brianpopow Sep 14, 2021
39a9de5
Fix text direction overrides
JimBobSquarePants Sep 14, 2021
ef00a82
Update AppliedFontStyle.cs
JimBobSquarePants Sep 14, 2021
8c70cad
Implement loading Pair Adjustment Positioning Subtable
brianpopow Sep 14, 2021
44010ad
Add *.received.txt to ignore
brianpopow Sep 14, 2021
bc88894
Started implementing Pair Adjustment Positioning Format 2 (still inco…
brianpopow Sep 14, 2021
d1b447a
Fix GPos table loading and implement apply
JimBobSquarePants Sep 15, 2021
05cd063
Use kerning as fallback only.
JimBobSquarePants Sep 15, 2021
9d9a0bd
Update Program.cs
JimBobSquarePants Sep 15, 2021
893fa51
Normalize glyph APIs
JimBobSquarePants Sep 15, 2021
80a8289
Add test case for farßi text
brianpopow Sep 15, 2021
0223eb4
Add test to verify arabic numbers are rendered from left to right
brianpopow Sep 15, 2021
d0d7d27
Implement reading Cursive Attachment Positioning Format1
brianpopow Sep 15, 2021
dfb0d7a
Implement loading Mark-to-Base Attachment Positioning Subtable
brianpopow Sep 15, 2021
8b6c6be
Fix Bidi mirroring for brackets etc.
JimBobSquarePants Sep 15, 2021
e7d3502
Merge branch 'js/ligatures' of https://github.com/SixLabors/Fonts int…
JimBobSquarePants Sep 15, 2021
c59ad2a
Merge branch 'master' into js/ligatures
JimBobSquarePants Sep 15, 2021
84e2708
Fix nullable stuff.
JimBobSquarePants Sep 15, 2021
5dd2e37
Add tests for kurdish text including punctuation
brianpopow Sep 15, 2021
655bbd9
Rework gpos table test: compare now against expected control points
brianpopow Sep 15, 2021
01e5561
Disable gpos lookup table 3 and 4, enable once TryUpdatePosition is i…
brianpopow Sep 15, 2021
ff00a56
Fix issue reading LookupType6Format2SubTable when chainedClassSeqRule…
brianpopow Sep 15, 2021
2398554
Add Chained Contexts Substitution format 3 test
brianpopow Sep 15, 2021
d586723
Fix gsub test font
brianpopow Sep 15, 2021
f44ab62
Refactor lookup type 6: extract some classes in separate files
brianpopow Sep 16, 2021
c85d59f
Extract MatchInputSequence method
brianpopow Sep 16, 2021
2e7479f
Refactor: extract classes into separate files
brianpopow Sep 16, 2021
ca34e25
Refactor: invert if statements to reduce nesting
brianpopow Sep 16, 2021
5f4d172
Begin layout rewrite.
JimBobSquarePants Sep 16, 2021
fb13a4d
Merge branch 'js/ligatures' of https://github.com/SixLabors/Fonts int…
JimBobSquarePants Sep 16, 2021
631c940
First attempt implementing Chained Contexts Substitution for Format 2
brianpopow Sep 16, 2021
3dc3656
Add test case for Chained Contexts Substitution Format2
brianpopow Sep 16, 2021
0f1cc56
Better test case for Chained Contexts Substitution, format 3
brianpopow Sep 16, 2021
0987c06
Remove code duplication for match class sequence
brianpopow Sep 17, 2021
ed8faac
Implement Chained Contexts Substitution, Format 1 (still untested)
brianpopow Sep 17, 2021
7172123
Implement loading Mark-to-Ligature Attachment Positioning Subtable
brianpopow Sep 17, 2021
b993dd2
Implement loading Mark-to-Mark Attachment Positioning Subtable
brianpopow Sep 17, 2021
456cd52
Implement loading Contextual Positioning Subtables
brianpopow Sep 17, 2021
3781bca
Implement loading Chained Contexts Positioning Subtable
brianpopow Sep 17, 2021
3496615
New TextLayout now works with basic LTR
JimBobSquarePants Sep 18, 2021
dbcd37d
Implement Reverse Chaining Contextual Single Substitution
brianpopow Sep 18, 2021
acceeb0
Add test case for LookupType8SubTable
brianpopow Sep 18, 2021
40d1fa9
Move classes which are common to gsub and gpos one directory up
brianpopow Sep 18, 2021
e262dd1
Final TextLayout fixes for LTR basic
JimBobSquarePants Sep 18, 2021
08b7788
Merge branch 'js/ligatures' of https://github.com/SixLabors/Fonts int…
JimBobSquarePants Sep 18, 2021
09c967d
Allow tabs following newline
JimBobSquarePants Sep 18, 2021
69c28bc
Handle tabs and non breaking spaces. Capture new lines as glyphs.
JimBobSquarePants Sep 19, 2021
5e83491
Trim trailing whitespace
JimBobSquarePants Sep 19, 2021
22db034
Implement Bidi reordering
JimBobSquarePants Sep 19, 2021
e9f186d
Nearly works. Just need to fix reversal count.
JimBobSquarePants Sep 19, 2021
2f212a3
Fix recursive reversal of bidi runs
brianpopow Sep 19, 2021
c40518c
Fix max/min assignment
JimBobSquarePants Sep 20, 2021
bafd398
Fix whitespace trimming
JimBobSquarePants Sep 20, 2021
16b7963
Fix offsetting
JimBobSquarePants Sep 20, 2021
eb7d244
Fix Bidi even run level > 0
JimBobSquarePants Sep 20, 2021
c05497d
Fix tabulation width
JimBobSquarePants Sep 20, 2021
6442885
Add unit test for bidi text mixing arabic texts with numbers
brianpopow Sep 20, 2021
d90f0e6
Handle mid point between line breaks.
JimBobSquarePants Sep 20, 2021
5a826e4
Update TextLayoutTests.cs
JimBobSquarePants Sep 20, 2021
995c8b3
Merge branch 'js/ligatures' of https://github.com/SixLabors/Fonts int…
JimBobSquarePants Sep 20, 2021
1f79273
Fix LINQ issue, when run only contains one level
brianpopow Sep 20, 2021
1454f9d
Update TextLayoutTests.cs
JimBobSquarePants Sep 20, 2021
08d1203
Merge branch 'js/ligatures' of https://github.com/SixLabors/Fonts int…
JimBobSquarePants Sep 20, 2021
fcfbbaf
Attempt to implement gpos chained contexts positioning, format 3 (sti…
brianpopow Sep 20, 2021
20a4a79
Fix offset index
brianpopow Sep 20, 2021
1d52d72
Implement gpos chained contexts positioning, format 2
brianpopow Sep 20, 2021
4188ab7
Move table loading methods and sequence matching methods in separate …
brianpopow Sep 20, 2021
e1de3f8
Implement gpos chained contexts positioning, format 1
brianpopow Sep 20, 2021
62f3384
Add IGlyphCollection Interface
brianpopow Sep 20, 2021
8888b61
Fix text measurements and add text alignment
JimBobSquarePants Sep 20, 2021
1792b35
Merge branch 'js/ligatures' of https://github.com/SixLabors/Fonts int…
JimBobSquarePants Sep 20, 2021
a186688
Update RendererOptions.cs
JimBobSquarePants Sep 20, 2021
bca863c
Implement gpos contextual positioning subtables TryUpdatePosition
brianpopow Sep 20, 2021
4494a6d
Add GetGlyphIds and Count to the GlyphCollection interface
brianpopow Sep 20, 2021
87457cf
Start implementing cursive attachment positioning subtable (still WIP)
brianpopow Sep 20, 2021
1a3bf7b
Fix loading entry exit anchors
brianpopow Sep 20, 2021
0b78801
Update Program.cs
JimBobSquarePants Sep 20, 2021
6386d74
Continue with LookupType3SubTable TryUpdatePosition
brianpopow Sep 21, 2021
68b9634
Change lookup subtables to static classes
brianpopow Sep 21, 2021
037bd02
Fixes for LookupType3SubTable TryUpdatePosition (still needs testing)
brianpopow Sep 21, 2021
9ed0a96
Layout fixes and perf tweaks
JimBobSquarePants Sep 21, 2021
a90c3c8
Fix for orphaned glyphs
JimBobSquarePants Sep 21, 2021
953f388
Base record and mark record will now load the anchor table
brianpopow Sep 21, 2021
89b9dd3
Fix issue setting the offset of the reader stream
brianpopow Sep 21, 2021
8528f48
Add test for gsub ContextualSubstitution Format1
brianpopow Sep 22, 2021
3a626b7
Add test for gsub ContextualSubstitution Format3
brianpopow Sep 22, 2021
d3e101d
Pass direction to glyph collections.
JimBobSquarePants Sep 22, 2021
4d13bff
Update Issues_180.cs
JimBobSquarePants Sep 22, 2021
3011e7c
Fix vertical alignment
JimBobSquarePants Sep 22, 2021
94661c5
Add test for rendering mathematical equation with arabic text
brianpopow Sep 22, 2021
e063c4d
Remove unrequired check
JimBobSquarePants Sep 22, 2021
c25989e
Make LayoutMode internal for now
JimBobSquarePants Sep 22, 2021
aec84f8
Update TextLayout.cs
JimBobSquarePants Sep 22, 2021
6c2667e
Add method to retrieve first glyph id at a given position
brianpopow Sep 22, 2021
8152d00
Add test for gsub LookupType5SubTable, Format 2.
brianpopow Sep 22, 2021
bf8ddc8
Remove ugly casting
JimBobSquarePants Sep 22, 2021
bbf8570
Merge branch 'js/ligatures' of https://github.com/SixLabors/Fonts int…
JimBobSquarePants Sep 22, 2021
39ab42b
Update GlyphSubstitutionCollection.cs
JimBobSquarePants Sep 22, 2021
355cfb9
Implement Shaping filter for GPOS
JimBobSquarePants Sep 22, 2021
5301be8
Try fix LookupType6SubTable format 1: still wrong glyph gets substituted
brianpopow Sep 22, 2021
e19aa3c
Add test case for gsub LookupType 6, format 1
brianpopow Sep 22, 2021
5e54d56
Fix issue in substitution of LookupType6SubTable, format1
brianpopow Sep 22, 2021
5d05e7b
Fix issues with gsub LookupType5 and and type6 format2, add better tests
brianpopow Sep 22, 2021
b8261cf
Add test fonts for GposLookupType1 Format1 and Format2
brianpopow Sep 23, 2021
da9173c
Faster feature check
JimBobSquarePants Sep 23, 2021
7ffba56
Merge branch 'js/ligatures' of https://github.com/SixLabors/Fonts int…
JimBobSquarePants Sep 23, 2021
dfd7b91
Vector should not be readonly
JimBobSquarePants Sep 23, 2021
d66fcb2
Add ability to check for mark category
JimBobSquarePants Sep 23, 2021
ff157d0
Don't fallback for control points.
JimBobSquarePants Sep 23, 2021
eb9830f
Add test font for GposLookupType2 format 1
brianpopow Sep 23, 2021
2d380c1
Update SingleAdjustmentPositioning Format1 test
brianpopow Sep 23, 2021
a92907d
Update LookupType3SubTable.cs
JimBobSquarePants Sep 23, 2021
7efb39f
Merge branch 'js/ligatures' of https://github.com/SixLabors/Fonts int…
JimBobSquarePants Sep 23, 2021
ed665e1
Add test for SingleAdjustmentPositioning format 2
brianpopow Sep 23, 2021
e05aae7
Move Class1Record to a separate file
brianpopow Sep 23, 2021
9c5d8be
Add test for PairAdjustmentPositioning format 1
brianpopow Sep 23, 2021
428aa53
Add test for Cursive Attachment Positioning
brianpopow Sep 23, 2021
433fd79
Compare rectangles with tolerance
brianpopow Sep 23, 2021
0f78db0
Add test for LookupType7SubTable, Format 1
brianpopow Sep 23, 2021
c333255
Fix loading context format 2: classSeqRuleSetOffsets can be 0
brianpopow Sep 23, 2021
908c60f
Fix TryUpdatePosition, format 2: Compare class sequence
brianpopow Sep 23, 2021
44a8140
Add test for LookupType7SubTable, Format 2
brianpopow Sep 23, 2021
e36de8c
Refactor to pass current feature to shaping tables.
JimBobSquarePants Sep 24, 2021
6478fed
Make layout mode public (vertical unsupported)
JimBobSquarePants Sep 24, 2021
db2f3e2
Fix LayoutMode flags
JimBobSquarePants Sep 24, 2021
4815827
Add test for LookupType7SubTable, Format 3
brianpopow Sep 24, 2021
b26c258
Fix bug in LookupType8SubTable, format 1
brianpopow Sep 24, 2021
014ebd1
Add test for LookupType8SubTable, Format 1
brianpopow Sep 24, 2021
68726ae
Fix issue with LookupType8, Format 2
brianpopow Sep 24, 2021
3345546
Add test for LookupType8SubTable, Format 2
brianpopow Sep 24, 2021
5b6ac13
Refactor check coverage
brianpopow Sep 24, 2021
65facdb
Add test for LookupType8SubTable, Format 3
brianpopow Sep 25, 2021
9f6bb9e
Refactor LookupType6 and LookupType8 to avoid code duplication
brianpopow Sep 25, 2021
92092f6
Merge branch 'master' into js/ligatures
JimBobSquarePants Sep 26, 2021
ee85092
Merge branch 'master' into js/ligatures
JimBobSquarePants Sep 27, 2021
08d64ed
Update Offset method
JimBobSquarePants Sep 27, 2021
a588199
Remove unused method
JimBobSquarePants Sep 27, 2021
027dca6
Use CreateTranslation
JimBobSquarePants Sep 27, 2021
93c65d1
Replace OpenSans-Regular with v26 version, update tests
brianpopow Sep 27, 2021
d81331e
Fix vertical alignment orientation modes
JimBobSquarePants Sep 27, 2021
eccbd60
Merge branch 'js/ligatures' of https://github.com/SixLabors/Fonts int…
JimBobSquarePants Sep 27, 2021
196232e
Fix Bidi override and make text-align variable
JimBobSquarePants Sep 27, 2021
ed98ef0
Add test fonts for gpos LookupType 4, 5 and 6
brianpopow Sep 27, 2021
84a66ca
Rename open sans test fonts
brianpopow Sep 27, 2021
2323d4b
Start implementing Mark-to-Base Attachment Positioning (still WIP)
brianpopow Sep 27, 2021
dbb7048
Expose vertical layout mode
JimBobSquarePants Sep 28, 2021
6473bb3
Remove TODO
JimBobSquarePants Sep 28, 2021
edcc32b
Update issues in LookupType4 TryUpdatePosition, still not correct
brianpopow Sep 29, 2021
0e415c8
Inline local
JimBobSquarePants Sep 30, 2021
437f835
Update TextLayoutTests.cs
JimBobSquarePants Sep 30, 2021
4759352
Update LookupType4SubTable.cs
JimBobSquarePants Sep 30, 2021
cae2b8b
Fix GPOS LookupType4Subtable
JimBobSquarePants Oct 1, 2021
15500a9
Fix BaseRecord load
JimBobSquarePants Oct 1, 2021
0f3b53a
Fix issue reading BaseRecords
brianpopow Oct 1, 2021
870fd01
Add test for gpos LookupType4SubTable
brianpopow Oct 1, 2021
a291d75
Revert vertical layout mode tweaks.
JimBobSquarePants Oct 1, 2021
60485a6
Fix topside bearing based on FreeType value
JimBobSquarePants Oct 1, 2021
24e1a9d
Start implementing gpos LookupType5SubTable
brianpopow Oct 1, 2021
7c25f8e
Fix issue loading LigatureArrayTable
brianpopow Oct 1, 2021
cee59ef
Add test for gpos LookupType5SubTable
brianpopow Oct 1, 2021
4b03ec1
Fix issue loading ligature attach table
brianpopow Oct 2, 2021
b84c145
Start implementing gpos LookupType6SubTable
brianpopow Oct 2, 2021
e89e9a2
Add test for gpos LookupType6SubTable
brianpopow Oct 2, 2021
b85db82
Merge branch 'js/ligatures' of https://github.com/SixLabors/Fonts int…
JimBobSquarePants Oct 3, 2021
1c9a515
Implement reading GlyphDefinitionTable
brianpopow Oct 4, 2021
e8ef367
Fix issue reading mark2 record
brianpopow Oct 4, 2021
cd14e64
Use TryGetReaderAtTablePosition in GlyphDefTable constructor
brianpopow Oct 4, 2021
07caa5a
Move GlyphDefinitionTable to AdvancedTypographic
brianpopow Oct 5, 2021
29907c0
Add TryGetGlyphClass method to retrieve the glyph class from GDEF table
brianpopow Oct 5, 2021
2bb9621
Use also TryGetGlyphClass with LookupType5
brianpopow Oct 5, 2021
4fc2687
Begin tracking the ligature Id.
JimBobSquarePants Oct 7, 2021
017eeee
Make shaping internal so we can break things.
JimBobSquarePants Oct 8, 2021
54bde4a
Add ability to get set data to we can set ligature trackers
JimBobSquarePants Oct 8, 2021
e5d9b5d
Implement Scott's awesome refactoring
JimBobSquarePants Oct 8, 2021
eaee1f3
Use compIndex as fontkit does in gpos LookupType5
brianpopow Oct 8, 2021
5303311
Add comment for compIndex
brianpopow Oct 9, 2021
2dfc709
Gpos LookupType6: check if Marks belonging base or ligature component
brianpopow Oct 9, 2021
00a6402
Refactor is mark glyph
brianpopow Oct 9, 2021
532f0df
Copy GUSB 4 ligature handling from HarfBuzz
JimBobSquarePants Oct 10, 2021
426a3be
Rename Script
JimBobSquarePants Oct 10, 2021
8bb7531
Use > 0 to make sure ligature id is set
brianpopow Oct 10, 2021
beb7bfc
Add font from bugzilla issue
JimBobSquarePants Oct 11, 2021
20e3a77
Don't skip zero-advance glyphs
JimBobSquarePants Oct 11, 2021
ccba919
Implement contextual fractions
brianpopow Oct 12, 2021
adb157d
Fix loop condition in AddFeature
brianpopow Oct 12, 2021
81d9117
Add ContextualFractions tests
brianpopow Oct 12, 2021
03ff44f
Use AdvancedTypographicUtils.IsMarkGlyph()
brianpopow Oct 12, 2021
a357dab
Invert if (allMatched) to reduce nesting
brianpopow Oct 12, 2021
a583c1a
Check also if LigatureComponentCount <= 0
brianpopow Oct 12, 2021
5293b01
Revert "Check also if LigatureComponentCount <= 0"
brianpopow Oct 13, 2021
1fdb88d
Move CoverageRangeRecord to separate file, add DebuggerDisplay
brianpopow Oct 13, 2021
49a3391
Implement loading gpos LookupType9
brianpopow Oct 13, 2021
03cee7a
Add check if coverage index is valid
brianpopow Oct 13, 2021
3febfe3
Update AdvancedTypographicUtils.cs
JimBobSquarePants Oct 14, 2021
f7c0133
Refactor feature application to match references
JimBobSquarePants Oct 14, 2021
be973f2
Apply features in order
brianpopow Oct 16, 2021
b2efe12
Merge pull request #211 from SixLabors/bp/applyfeaturesordered
brianpopow Oct 16, 2021
57b6000
Split lookups into strict stages.
JimBobSquarePants Oct 18, 2021
f30f07a
Begin implementing SkippingGlyphIterator
JimBobSquarePants Oct 19, 2021
7ca4820
Create generic matching function
JimBobSquarePants Oct 19, 2021
dbb0a99
Use generic match function for coverage checks
JimBobSquarePants Oct 19, 2021
6c8f554
Fix coverage condition
JimBobSquarePants Oct 19, 2021
c4e24aa
Use Skipping iterator for sequence matches
JimBobSquarePants Oct 20, 2021
8d2b160
Merge GSUB lookup list code
JimBobSquarePants Oct 20, 2021
01252dd
Fix count increment
JimBobSquarePants Oct 21, 2021
0ef09d6
Fix default shaper assignment
JimBobSquarePants Oct 21, 2021
a6bf0e0
Use iterator for feature application
JimBobSquarePants Oct 21, 2021
83b5204
Lookup4 should remove at match indices
JimBobSquarePants Oct 22, 2021
bbfae58
Update LookupType5SubTable.cs
JimBobSquarePants Oct 24, 2021
9f77e36
Fix GPOS 5 & 6
JimBobSquarePants Oct 24, 2021
b4003d3
Fix up GSUB ligature ids/components
JimBobSquarePants Oct 24, 2021
4f4e1ff
Fix mark anchoring
JimBobSquarePants Oct 25, 2021
1023e23
Fix build/update tests
JimBobSquarePants Oct 25, 2021
d9d76f1
Add MarkAnchoring test
brianpopow Oct 25, 2021
5b9e739
Move glyph offsetting to the end.
JimBobSquarePants Oct 25, 2021
6de3e2b
Add MarkToMarkAttachment test
brianpopow Oct 25, 2021
a6d1bac
Add me_quran test font file
brianpopow Oct 25, 2021
c97ddf1
Fix SingleAdjustmentPositioning test
brianpopow Oct 25, 2021
15b964e
Use upem for font size in gpos tests
brianpopow Oct 25, 2021
1648062
Update LookupType4SubTable.cs
JimBobSquarePants Oct 26, 2021
2822f61
Fix GPOS lookups
JimBobSquarePants Oct 26, 2021
4987d44
Fix final tests
JimBobSquarePants Oct 26, 2021
77b68db
Use compare glyph rectangles exact where appropriate
brianpopow Oct 26, 2021
74527a3
Fix GSub namespace casing
JimBobSquarePants Oct 26, 2021
fcfe260
Fix GSub folder casing
JimBobSquarePants Oct 26, 2021
1673946
Update LookupType4SubTable.cs
JimBobSquarePants Oct 27, 2021
c836c1a
Ensure no clipping of marks
JimBobSquarePants Oct 27, 2021
fc877c5
Use buffer pooling for loading tables when possible
JimBobSquarePants Oct 27, 2021
90dbc64
Update RendererOptions.cs
JimBobSquarePants Oct 27, 2021
231a4a8
Remove Expression.Compile cast
JimBobSquarePants Oct 27, 2021
7c5379d
Update Buffer{T}.cs
JimBobSquarePants Oct 27, 2021
05cb42b
Update features
brianpopow Oct 30, 2021
df041b6
Make Buffer<T> a ref struct
JimBobSquarePants Nov 7, 2021
6cd2633
Merge branch 'js/ligatures' of https://github.com/SixLabors/Fonts int…
JimBobSquarePants Nov 7, 2021
99459c5
Fix kerning options to match CSS spec
JimBobSquarePants Nov 8, 2021
f2a44bf
Remove unused enumerator
JimBobSquarePants Nov 8, 2021
1a534e4
Use switch
JimBobSquarePants Nov 9, 2021
dd518f8
StyleCop cleanup
JimBobSquarePants Nov 9, 2021
79d917b
Update TextMeasurer.cs
JimBobSquarePants Nov 9, 2021
6285e1b
No need to carry index through
JimBobSquarePants Nov 10, 2021
3069f57
Prevent runtime error re kerning.
JimBobSquarePants Nov 10, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/SixLabors.Fonts/AppliedFontStyle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ internal struct AppliedFontStyle
public int End;
public bool ApplyKerning;

// TODO: This should accept all the glyphs in the range to
// allow complex substitutions.
public GlyphMetrics[] GetGlyphLayers(CodePoint codePoint, ColorFontSupport colorFontOptions)
JimBobSquarePants marked this conversation as resolved.
Show resolved Hide resolved
{
GlyphMetrics glyph = this.MainFont.GetGlyphMetrics(codePoint);
Expand Down
31 changes: 27 additions & 4 deletions src/SixLabors.Fonts/BigEndianBinaryReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -167,10 +167,17 @@ public ushort ReadUInt16()
return BinaryPrimitives.ReadUInt16BigEndian(this.buffer);
}

/// <summary>
/// Reads a 16-bit unsigned integer from the stream representing an offset position.
/// 2 bytes are read.
/// </summary>
/// <returns>The 16-bit unsigned integer read</returns>
public ushort ReadOffset16() => this.ReadUInt16();

public TEnum ReadUInt16<TEnum>() => CastTo<TEnum>.From(this.ReadUInt16());

/// <summary>
/// Reads array or 16-bit unsigned integers from the stream.
/// Reads array of 16-bit unsigned integers from the stream.
/// 2 bytes are read.
/// </summary>
/// <param name="length">The length.</param>
Expand All @@ -189,12 +196,12 @@ public ushort[] ReadUInt16Array(int length)
}

/// <summary>
/// Reads array or 16-bit unsigned integers from the stream.
/// 2 bytes are read.
/// Reads array or 32-bit unsigned integers from the stream.
/// 4 bytes are read.
/// </summary>
/// <param name="length">The length.</param>
/// <returns>
/// The 16-bit unsigned integer read
/// The 32-bit unsigned integer read
/// </returns>
public uint[] ReadUInt32Array(int length)
{
Expand Down Expand Up @@ -278,6 +285,17 @@ public byte ReadUInt8()
return this.buffer[0];
}

/// <summary>
/// Reads a 24-bit unsigned integer from the stream, using the bit converter
/// for this reader. 3 bytes are read.
/// </summary>
/// <returns>The 24-bit unsigned integer read.</returns>
public int ReadUInt24()
{
byte highByte = this.ReadByte();
return (highByte << 16) | this.ReadUInt16();
}

/// <summary>
/// Reads a 32-bit unsigned integer from the stream, using the bit converter
/// for this reader. 4 bytes are read.
Expand All @@ -290,6 +308,11 @@ public uint ReadUInt32()
return BinaryPrimitives.ReadUInt32BigEndian(this.buffer);
}

/// <summary>
/// Reads a 32-bit unsigned integer from the stream representing an offset position.
/// 4 bytes are read.
/// </summary>
/// <returns>The 32-bit unsigned integer read</returns>
public uint ReadOffset32() => this.ReadUInt32();

/// <summary>
Expand Down
5 changes: 3 additions & 2 deletions src/SixLabors.Fonts/FontMetrics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,6 @@ internal FontMetrics(
/// <inheritdoc/>
public GlyphMetrics GetGlyphMetrics(CodePoint codePoint)
{
// TODO: Check this. It looks like we could potentially return the metrics
// for the glyph at position zero when a matching codepoint cannot be found.
bool foundGlyph = this.TryGetGlyphIndex(codePoint, out ushort idx);
if (!foundGlyph)
{
Expand Down Expand Up @@ -320,6 +318,9 @@ public static FontMetrics[] LoadFontCollection(Stream stream)
internal bool TryGetGlyphIndex(CodePoint codePoint, out ushort glyphId)
=> this.cmap.TryGetGlyphId(codePoint, out glyphId);

internal bool TryGetGlyphIndex(CodePoint codePoint, CodePoint nextCodePoint, out ushort glyphId, out bool skipNextCodePoint)
=> this.cmap.TryGetGlyphId(codePoint, nextCodePoint, out glyphId, out skipNextCodePoint);

internal bool TryGetColoredVectors(CodePoint codePoint, ushort idx, [NotNullWhen(true)] out GlyphMetrics[]? vectors)
{
if (this.colrTable == null || this.colorGlyphCache == null)
Expand Down
142 changes: 142 additions & 0 deletions src/SixLabors.Fonts/GlyphSubstitutionCollection.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
// Copyright (c) Six Labors.
// Licensed under the Apache License, Version 2.0.

using System.Collections.Generic;

namespace SixLabors.Fonts
{
/// <summary>
/// Represents a collection of glyph indices that are mapped to input codepoints.
/// </summary>
internal class GlyphSubstitutionCollection
{
private readonly List<ushort> glyphIndices = new List<ushort>();
private readonly List<int> inputCodePointIndices = new List<int>();
private ushort originalCodePointOffset;
private readonly List<GlyphIndexToCodePoint> glyphIndexToCodePointMap = new List<GlyphIndexToCodePoint>();

/// <summary>
/// Gets the glyph count.
/// This may be more or less than original user codepoint count (from substitution process).
/// </summary>
public int Count => this.glyphIndices.Count;

/// <summary>
/// Gets the glyph index at the given index.
/// </summary>
/// <param name="index">The index.</param>
/// <returns>The <see cref="ushort"/>.</returns>
public ushort this[int index] => this.glyphIndices[index];

/// <summary>
/// Clears the collection.
/// </summary>
public void Clear()
{
this.glyphIndices.Clear();
this.originalCodePointOffset = 0;
this.inputCodePointIndices.Clear();
this.glyphIndexToCodePointMap.Clear();
}

/// <summary>
/// Add a codepoint index and its glyph index.
/// </summary>
/// <param name="codePointIndex">Index to codepoint element in code point collection.</param>
/// <param name="glyphIndex">Map to glyphindex</param>
public void AddGlyph(int codePointIndex, ushort glyphIndex)
{
// So we can monitor what substituion process
this.inputCodePointIndices.Add(codePointIndex);
this.glyphIndices.Add(glyphIndex);

var glyphIndexToCodePointMap = new GlyphIndexToCodePoint(this.originalCodePointOffset, 1);
this.glyphIndexToCodePointMap.Add(glyphIndexToCodePointMap);
this.originalCodePointOffset++;
}

public void GetGlyphIndexAndMap(int index, out ushort glyphIndex, out ushort codepointOffset, out ushort mapLength)
{
glyphIndex = this.glyphIndices[index];
GlyphIndexToCodePoint glyphIndexToUserCodePoint = this.glyphIndexToCodePointMap[index];
codepointOffset = glyphIndexToUserCodePoint.CodePointOffset;
mapLength = glyphIndexToUserCodePoint.Length;
}

/// <summary>
/// Performs a 1:1 replacement of a glyph index at the given position.
/// </summary>
/// <param name="index">The zero-based index of the element to replace.</param>
/// <param name="newGlyphIndex">The replacement glyph index.</param>
public void Replace(int index, ushort newGlyphIndex)
=> this.glyphIndices[index] = newGlyphIndex;

/// <summary>
/// Replaces a series of glyph indices starting at the given position with a new index.
/// </summary>
/// <param name="index">The zero-based starting index of the range of elements to replace.</param>
/// <param name="count">The number of elements to replace.</param>
/// <param name="newGlyphIndex">The replacement glyph index.</param>
public void Replace(int index, int count, ushort newGlyphIndex)
{
// e.g. f-i ligation
// original 'f' glyph and 'i' glyph are removed
// and then replace with a single glyph.
this.glyphIndices.RemoveRange(index, count);
this.glyphIndices.Insert(index, newGlyphIndex);
GlyphIndexToCodePoint firstRemove = this.glyphIndexToCodePointMap[index];

var newMap = new GlyphIndexToCodePoint(firstRemove.CodePointOffset, (ushort)count);
this.glyphIndexToCodePointMap.RemoveRange(index, count);
this.glyphIndexToCodePointMap.Insert(index, newMap);
}

/// <summary>
/// Replaces a single glyph index with a collection of glyph indices.
/// </summary>
/// <param name="index">The zero-based index of the element to replace.</param>
/// <param name="newGlyphIndices">The collection of replacement glyph indices.</param>
public void Replace(int index, ushort[] newGlyphIndices)
{
this.glyphIndices.RemoveAt(index);
this.glyphIndices.InsertRange(index, newGlyphIndices);
GlyphIndexToCodePoint current = this.glyphIndexToCodePointMap[index];
this.glyphIndexToCodePointMap.RemoveAt(index);

// Insert
int j = newGlyphIndices.Length;
for (int i = 0; i < j; ++i)
{
var newGlyph = new GlyphIndexToCodePoint(current.CodePointOffset, 1);

// May point to the same user codepoint.
this.glyphIndexToCodePointMap.Insert(index, newGlyph);
}
}

/// <summary>
/// Maps from glyph index to original user code point.
/// </summary>
private readonly struct GlyphIndexToCodePoint
{
public GlyphIndexToCodePoint(ushort codePointOffset, ushort length)
{
this.CodePointOffset = codePointOffset;
this.Length = length;
}

/// <summary>
/// Gets the offset from start layout codepoint
/// </summary>
public ushort CodePointOffset { get; }

/// <summary>
/// Gets the number of codepoints represented by the glyph.
/// </summary>
public readonly ushort Length { get; }

public override string ToString()
=> $"CodePointOffset: {this.CodePointOffset} - Length: {this.Length}";
}
}
}
2 changes: 1 addition & 1 deletion src/SixLabors.Fonts/RendererOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ internal AppliedFontStyle GetStyle(int index, int length)

return new AppliedFontStyle
{
Start = 0,
Start = index,
JimBobSquarePants marked this conversation as resolved.
Show resolved Hide resolved
End = length - 1,
PointSize = this.Font.Size,
MainFont = this.Font.FontMetrics,
Expand Down
10 changes: 2 additions & 8 deletions src/SixLabors.Fonts/SixLabors.Fonts.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,11 @@
</PropertyGroup>

<ItemGroup>
<None Remove="Unicode\Resources\Bidi.trie" />
<None Remove="Unicode\Resources\Grapheme.trie" />
<None Remove="Unicode\Resources\LineBreak.trie" />
<None Remove="Unicode\Resources\UnicodeCategory.trie" />
<None Remove="Unicode\Resources\**" />
</ItemGroup>

<ItemGroup>
<EmbeddedResource Include="Unicode\Resources\Bidi.trie" />
<EmbeddedResource Include="Unicode\Resources\Grapheme.trie" />
<EmbeddedResource Include="Unicode\Resources\LineBreak.trie" />
<EmbeddedResource Include="Unicode\Resources\UnicodeCategory.trie" />
<EmbeddedResource Include="Unicode\Resources\**" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public override bool TryGetGlyphId(CodePoint codePoint, out ushort glyphId)

if (charAsInt >= seg.StartCodePoint && charAsInt <= seg.EndCodePoint)
{
glyphId = (ushort)((charAsInt - seg.StartCodePoint) + seg.StartGlyphId);
glyphId = (ushort)(charAsInt - seg.StartCodePoint + seg.StartGlyphId);
return true;
}
}
Expand Down
Loading