Skip to content

Commit c0ca4e4

Browse files
committed
Don't use skrifa interjector if provided variation coordinates map to default
1 parent ab3dc07 commit c0ca4e4

3 files changed

Lines changed: 35 additions & 276 deletions

File tree

src/interjector.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ impl Interjector<'_> {
2020
pub(crate) mod skrifa {
2121
use crate::{MaxpData, Tag};
2222
use kurbo::{BezPath, CubicBez};
23-
use skrifa::instance::Location;
23+
use skrifa::instance::{Location, LocationRef};
2424
use skrifa::outline::{DrawSettings, OutlinePen};
2525
use skrifa::prelude::Size;
2626
use skrifa::{FontRef, GlyphId, MetadataProvider};
@@ -45,6 +45,10 @@ pub(crate) mod skrifa {
4545

4646
Some(Self { font_ref, location })
4747
}
48+
49+
pub(crate) fn is_default_location(&self) -> bool {
50+
LocationRef::from(&self.location).is_default()
51+
}
4852
}
4953

5054
impl<'a> SkrifaInterjector<'a> {

src/lib.rs

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -173,26 +173,25 @@ fn prepare_context<'a>(
173173
#[cfg(not(feature = "variable-fonts"))]
174174
let interjector = Interjector::Dummy(PhantomData);
175175
// For CFF, we _always_ want to do normal subsetting, since CFF cannot have variations.
176-
// For TrueType, we prefer normal subsetting in case no variation was requested. If we do have
177-
// variations, we use `skrifa` to instance.
176+
// For TrueType, we prefer normal subsetting in case the requested variation coordinates
177+
// resolve to the default location. If we do have variations, we use `skrifa` to instance.
178178
// For CFF2, we _always_ use `skrifa` to instance.
179179
#[cfg(feature = "variable-fonts")]
180-
let interjector = if (variation_coordinates.is_empty()
181-
&& flavor == FontFlavor::TrueType)
182-
|| flavor == FontFlavor::Cff
183-
{
184-
// For TrueType and CFF, we are still best off using the normal subsetting logic in case no variation coordinates
185-
// have been passed.
180+
let interjector = if flavor == FontFlavor::Cff {
186181
Interjector::Dummy(PhantomData)
187182
} else {
188-
Interjector::Skrifa(
189-
interjector::skrifa::SkrifaInterjector::new(
190-
data,
191-
index,
192-
variation_coordinates,
193-
)
194-
.ok_or(MalformedFont)?,
183+
let interjector = interjector::skrifa::SkrifaInterjector::new(
184+
data,
185+
index,
186+
variation_coordinates,
195187
)
188+
.ok_or(MalformedFont)?;
189+
190+
if flavor == FontFlavor::TrueType && interjector.is_default_location() {
191+
Interjector::Dummy(PhantomData)
192+
} else {
193+
Interjector::Skrifa(interjector)
194+
}
196195
};
197196

198197
Ok(Context {

tests/ttx/NotoSans-Regular_var_1.ttx

Lines changed: 16 additions & 260 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
<!-- Most of this table will be recalculated by the compiler -->
2424
<tableVersion value="1.0"/>
2525
<fontRevision value="2.013"/>
26-
<checkSumAdjustment value="0xf902a8a3"/>
26+
<checkSumAdjustment value="0x99fde9d7"/>
2727
<magicNumber value="0x5f0f3cf5"/>
2828
<flags value="00000000 00000011"/>
2929
<unitsPerEm value="1000"/>
@@ -64,18 +64,18 @@
6464
<!-- Most of this table will be recalculated by the compiler -->
6565
<tableVersion value="0x10000"/>
6666
<numGlyphs value="14"/>
67-
<maxPoints value="51"/>
68-
<maxContours value="2"/>
69-
<maxCompositePoints value="0"/>
70-
<maxCompositeContours value="0"/>
67+
<maxPoints value="273"/>
68+
<maxContours value="24"/>
69+
<maxCompositePoints value="143"/>
70+
<maxCompositeContours value="8"/>
7171
<maxZones value="1"/>
7272
<maxTwilightPoints value="0"/>
7373
<maxStorage value="0"/>
7474
<maxFunctionDefs value="0"/>
7575
<maxInstructionDefs value="0"/>
7676
<maxStackElements value="0"/>
7777
<maxSizeOfInstructions value="0"/>
78-
<maxComponentElements value="0"/>
78+
<maxComponentElements value="4"/>
7979
<maxComponentDepth value="1"/>
8080
</maxp>
8181

@@ -160,114 +160,13 @@
160160
</TTGlyph>
161161

162162
<TTGlyph name="Ccircumflex" xMin="61" yMin="-10" xMax="601" yMax="944">
163-
<contour>
164-
<pt x="403" y="645" on="1"/>
165-
<pt x="346" y="645" on="0"/>
166-
<pt x="254" y="606" on="0"/>
167-
<pt x="190" y="531" on="0"/>
168-
<pt x="156" y="424" on="0"/>
169-
<pt x="156" y="357" on="1"/>
170-
<pt x="156" y="269" on="0"/>
171-
<pt x="211" y="139" on="0"/>
172-
<pt x="320" y="69" on="0"/>
173-
<pt x="402" y="69" on="1"/>
174-
<pt x="449" y="69" on="0"/>
175-
<pt x="533" y="85" on="0"/>
176-
<pt x="573" y="97" on="1"/>
177-
<pt x="573" y="19" on="1"/>
178-
<pt x="533" y="4" on="0"/>
179-
<pt x="448" y="-10" on="0"/>
180-
<pt x="389" y="-10" on="1"/>
181-
<pt x="280" y="-10" on="0"/>
182-
<pt x="134" y="80" on="0"/>
183-
<pt x="61" y="246" on="0"/>
184-
<pt x="61" y="358" on="1"/>
185-
<pt x="61" y="439" on="0"/>
186-
<pt x="106" y="573" on="0"/>
187-
<pt x="193" y="671" on="0"/>
188-
<pt x="321" y="724" on="0"/>
189-
<pt x="404" y="724" on="1"/>
190-
<pt x="459" y="724" on="0"/>
191-
<pt x="561" y="702" on="0"/>
192-
<pt x="601" y="682" on="1"/>
193-
<pt x="565" y="606" on="1"/>
194-
<pt x="532" y="621" on="0"/>
195-
<pt x="451" y="645" on="0"/>
196-
</contour>
197-
<contour>
198-
<pt x="424" y="944" on="1"/>
199-
<pt x="436" y="922" on="0"/>
200-
<pt x="481" y="867" on="0"/>
201-
<pt x="530" y="814" on="0"/>
202-
<pt x="549" y="795" on="1"/>
203-
<pt x="549" y="784" on="1"/>
204-
<pt x="487" y="784" on="1"/>
205-
<pt x="461" y="800" on="0"/>
206-
<pt x="405" y="847" on="0"/>
207-
<pt x="378" y="874" on="1"/>
208-
<pt x="351" y="847" on="0"/>
209-
<pt x="297" y="801" on="0"/>
210-
<pt x="271" y="784" on="1"/>
211-
<pt x="211" y="784" on="1"/>
212-
<pt x="211" y="795" on="1"/>
213-
<pt x="230" y="815" on="0"/>
214-
<pt x="277" y="867" on="0"/>
215-
<pt x="321" y="922" on="0"/>
216-
<pt x="334" y="944" on="1"/>
217-
</contour>
218-
<instructions/>
163+
<component glyphName="C" x="0" y="0" flags="0x204"/>
164+
<component glyphName="circumflex" x="171" y="178" flags="0x4"/>
219165
</TTGlyph>
220166

221167
<TTGlyph name="Cdotaccent" xMin="61" yMin="-10" xMax="601" yMax="915">
222-
<contour>
223-
<pt x="403" y="645" on="1"/>
224-
<pt x="346" y="645" on="0"/>
225-
<pt x="254" y="606" on="0"/>
226-
<pt x="190" y="531" on="0"/>
227-
<pt x="156" y="424" on="0"/>
228-
<pt x="156" y="357" on="1"/>
229-
<pt x="156" y="269" on="0"/>
230-
<pt x="211" y="139" on="0"/>
231-
<pt x="320" y="69" on="0"/>
232-
<pt x="402" y="69" on="1"/>
233-
<pt x="449" y="69" on="0"/>
234-
<pt x="533" y="85" on="0"/>
235-
<pt x="573" y="97" on="1"/>
236-
<pt x="573" y="19" on="1"/>
237-
<pt x="533" y="4" on="0"/>
238-
<pt x="448" y="-10" on="0"/>
239-
<pt x="389" y="-10" on="1"/>
240-
<pt x="280" y="-10" on="0"/>
241-
<pt x="134" y="80" on="0"/>
242-
<pt x="61" y="246" on="0"/>
243-
<pt x="61" y="358" on="1"/>
244-
<pt x="61" y="439" on="0"/>
245-
<pt x="106" y="573" on="0"/>
246-
<pt x="193" y="671" on="0"/>
247-
<pt x="321" y="724" on="0"/>
248-
<pt x="404" y="724" on="1"/>
249-
<pt x="459" y="724" on="0"/>
250-
<pt x="561" y="702" on="0"/>
251-
<pt x="601" y="682" on="1"/>
252-
<pt x="565" y="606" on="1"/>
253-
<pt x="532" y="621" on="0"/>
254-
<pt x="451" y="645" on="0"/>
255-
</contour>
256-
<contour>
257-
<pt x="381" y="915" on="1"/>
258-
<pt x="401" y="915" on="0"/>
259-
<pt x="432" y="888" on="0"/>
260-
<pt x="432" y="859" on="1"/>
261-
<pt x="432" y="831" on="0"/>
262-
<pt x="401" y="803" on="0"/>
263-
<pt x="381" y="803" on="1"/>
264-
<pt x="359" y="803" on="0"/>
265-
<pt x="329" y="831" on="0"/>
266-
<pt x="329" y="859" on="1"/>
267-
<pt x="329" y="888" on="0"/>
268-
<pt x="359" y="915" on="0"/>
269-
</contour>
270-
<instructions/>
168+
<component glyphName="C" x="0" y="0" flags="0x204"/>
169+
<component glyphName="dotaccent" x="289" y="178" flags="0x4"/>
271170
</TTGlyph>
272171

273172
<TTGlyph name="E" xMin="97" yMin="0" xMax="496" yMax="714">
@@ -392,161 +291,18 @@
392291
</TTGlyph>
393292

394293
<TTGlyph name="cacute" xMin="55" yMin="-10" xMax="447" yMax="766">
395-
<contour>
396-
<pt x="300" y="-10" on="1"/>
397-
<pt x="229" y="-10" on="0"/>
398-
<pt x="118" y="48" on="0"/>
399-
<pt x="55" y="170" on="0"/>
400-
<pt x="55" y="265" on="1"/>
401-
<pt x="55" y="364" on="0"/>
402-
<pt x="121" y="488" on="0"/>
403-
<pt x="234" y="546" on="0"/>
404-
<pt x="306" y="546" on="1"/>
405-
<pt x="347" y="546" on="0"/>
406-
<pt x="423" y="529" on="0"/>
407-
<pt x="447" y="517" on="1"/>
408-
<pt x="420" y="444" on="1"/>
409-
<pt x="396" y="453" on="0"/>
410-
<pt x="332" y="469" on="0"/>
411-
<pt x="304" y="469" on="1"/>
412-
<pt x="250" y="469" on="0"/>
413-
<pt x="180" y="423" on="0"/>
414-
<pt x="146" y="333" on="0"/>
415-
<pt x="146" y="266" on="1"/>
416-
<pt x="146" y="202" on="0"/>
417-
<pt x="180" y="112" on="0"/>
418-
<pt x="248" y="66" on="0"/>
419-
<pt x="299" y="66" on="1"/>
420-
<pt x="343" y="66" on="0"/>
421-
<pt x="410" y="84" on="0"/>
422-
<pt x="438" y="97" on="1"/>
423-
<pt x="438" y="19" on="1"/>
424-
<pt x="411" y="5" on="0"/>
425-
<pt x="346" y="-10" on="0"/>
426-
</contour>
427-
<contour>
428-
<pt x="432" y="756" on="1"/>
429-
<pt x="423" y="742" on="0"/>
430-
<pt x="389" y="702" on="0"/>
431-
<pt x="348" y="659" on="0"/>
432-
<pt x="307" y="620" on="0"/>
433-
<pt x="289" y="606" on="1"/>
434-
<pt x="231" y="606" on="1"/>
435-
<pt x="231" y="618" on="1"/>
436-
<pt x="246" y="637" on="0"/>
437-
<pt x="281" y="689" on="0"/>
438-
<pt x="315" y="744" on="0"/>
439-
<pt x="326" y="766" on="1"/>
440-
<pt x="432" y="766" on="1"/>
441-
</contour>
442-
<instructions/>
294+
<component glyphName="c" x="0" y="0" flags="0x204"/>
295+
<component glyphName="acute" x="191" y="0" flags="0x4"/>
443296
</TTGlyph>
444297

445298
<TTGlyph name="ccircumflex" xMin="55" yMin="-10" xMax="453" yMax="766">
446-
<contour>
447-
<pt x="300" y="-10" on="1"/>
448-
<pt x="229" y="-10" on="0"/>
449-
<pt x="118" y="48" on="0"/>
450-
<pt x="55" y="170" on="0"/>
451-
<pt x="55" y="265" on="1"/>
452-
<pt x="55" y="364" on="0"/>
453-
<pt x="121" y="488" on="0"/>
454-
<pt x="234" y="546" on="0"/>
455-
<pt x="306" y="546" on="1"/>
456-
<pt x="347" y="546" on="0"/>
457-
<pt x="423" y="529" on="0"/>
458-
<pt x="447" y="517" on="1"/>
459-
<pt x="420" y="444" on="1"/>
460-
<pt x="396" y="453" on="0"/>
461-
<pt x="332" y="469" on="0"/>
462-
<pt x="304" y="469" on="1"/>
463-
<pt x="250" y="469" on="0"/>
464-
<pt x="180" y="423" on="0"/>
465-
<pt x="146" y="333" on="0"/>
466-
<pt x="146" y="266" on="1"/>
467-
<pt x="146" y="202" on="0"/>
468-
<pt x="180" y="112" on="0"/>
469-
<pt x="248" y="66" on="0"/>
470-
<pt x="299" y="66" on="1"/>
471-
<pt x="343" y="66" on="0"/>
472-
<pt x="410" y="84" on="0"/>
473-
<pt x="438" y="97" on="1"/>
474-
<pt x="438" y="19" on="1"/>
475-
<pt x="411" y="5" on="0"/>
476-
<pt x="346" y="-10" on="0"/>
477-
</contour>
478-
<contour>
479-
<pt x="328" y="766" on="1"/>
480-
<pt x="340" y="744" on="0"/>
481-
<pt x="385" y="689" on="0"/>
482-
<pt x="434" y="636" on="0"/>
483-
<pt x="453" y="617" on="1"/>
484-
<pt x="453" y="606" on="1"/>
485-
<pt x="391" y="606" on="1"/>
486-
<pt x="365" y="622" on="0"/>
487-
<pt x="309" y="669" on="0"/>
488-
<pt x="282" y="696" on="1"/>
489-
<pt x="255" y="669" on="0"/>
490-
<pt x="201" y="623" on="0"/>
491-
<pt x="175" y="606" on="1"/>
492-
<pt x="115" y="606" on="1"/>
493-
<pt x="115" y="617" on="1"/>
494-
<pt x="134" y="637" on="0"/>
495-
<pt x="181" y="689" on="0"/>
496-
<pt x="225" y="744" on="0"/>
497-
<pt x="238" y="766" on="1"/>
498-
</contour>
499-
<instructions/>
299+
<component glyphName="c" x="0" y="0" flags="0x204"/>
300+
<component glyphName="circumflex" x="75" y="0" flags="0x4"/>
500301
</TTGlyph>
501302

502303
<TTGlyph name="cdotaccent" xMin="55" yMin="-10" xMax="447" yMax="737">
503-
<contour>
504-
<pt x="300" y="-10" on="1"/>
505-
<pt x="229" y="-10" on="0"/>
506-
<pt x="118" y="48" on="0"/>
507-
<pt x="55" y="170" on="0"/>
508-
<pt x="55" y="265" on="1"/>
509-
<pt x="55" y="364" on="0"/>
510-
<pt x="121" y="488" on="0"/>
511-
<pt x="234" y="546" on="0"/>
512-
<pt x="306" y="546" on="1"/>
513-
<pt x="347" y="546" on="0"/>
514-
<pt x="423" y="529" on="0"/>
515-
<pt x="447" y="517" on="1"/>
516-
<pt x="420" y="444" on="1"/>
517-
<pt x="396" y="453" on="0"/>
518-
<pt x="332" y="469" on="0"/>
519-
<pt x="304" y="469" on="1"/>
520-
<pt x="250" y="469" on="0"/>
521-
<pt x="180" y="423" on="0"/>
522-
<pt x="146" y="333" on="0"/>
523-
<pt x="146" y="266" on="1"/>
524-
<pt x="146" y="202" on="0"/>
525-
<pt x="180" y="112" on="0"/>
526-
<pt x="248" y="66" on="0"/>
527-
<pt x="299" y="66" on="1"/>
528-
<pt x="343" y="66" on="0"/>
529-
<pt x="410" y="84" on="0"/>
530-
<pt x="438" y="97" on="1"/>
531-
<pt x="438" y="19" on="1"/>
532-
<pt x="411" y="5" on="0"/>
533-
<pt x="346" y="-10" on="0"/>
534-
</contour>
535-
<contour>
536-
<pt x="285" y="737" on="1"/>
537-
<pt x="305" y="737" on="0"/>
538-
<pt x="336" y="710" on="0"/>
539-
<pt x="336" y="681" on="1"/>
540-
<pt x="336" y="653" on="0"/>
541-
<pt x="305" y="625" on="0"/>
542-
<pt x="285" y="625" on="1"/>
543-
<pt x="263" y="625" on="0"/>
544-
<pt x="233" y="653" on="0"/>
545-
<pt x="233" y="681" on="1"/>
546-
<pt x="233" y="710" on="0"/>
547-
<pt x="263" y="737" on="0"/>
548-
</contour>
549-
<instructions/>
304+
<component glyphName="c" x="0" y="0" flags="0x204"/>
305+
<component glyphName="dotaccent" x="193" y="0" flags="0x4"/>
550306
</TTGlyph>
551307

552308
<TTGlyph name="circumflex" xMin="40" yMin="606" xMax="378" yMax="766">

0 commit comments

Comments
 (0)