-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgnustep-libs-opal-webkit-gaps.html
More file actions
1405 lines (1278 loc) · 67.6 KB
/
Copy pathgnustep-libs-opal-webkit-gaps.html
File metadata and controls
1405 lines (1278 loc) · 67.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>libs-opal — CoreGraphics, CoreText & ImageIO gaps for WebKit</title>
<style>
:root {
--bg: #fbfbf8;
--fg: #1a1a1a;
--muted: #555;
--accent: #b03000;
--accent2: #0a4d68;
--ok: #1f7a1f;
--warn: #b06800;
--bad: #b00020;
--code-bg: #f0ece4;
--rule: #d6cfc0;
--card: #fff;
}
html { -webkit-text-size-adjust: 100%; }
body { margin: 0 auto; max-width: 1080px; padding: 2.5rem 1.5rem 6rem;
font: 16px/1.55 -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, sans-serif;
color: var(--fg); background: var(--bg); }
h1 { font-size: 2rem; line-height: 1.2; margin: 0 0 .25rem; }
h2 { font-size: 1.4rem; margin: 2.5rem 0 .75rem; padding-bottom: .25rem; border-bottom: 2px solid var(--rule); }
h3 { font-size: 1.15rem; margin: 1.75rem 0 .5rem; color: var(--accent2); }
h4 { margin: 1.25rem 0 .35rem; }
.subtitle { color: var(--muted); font-size: 1.05rem; margin: 0 0 2rem; }
code, pre, kbd { font-family: "SF Mono", Menlo, Consolas, monospace; }
code { background: var(--code-bg); padding: 1px 5px; border-radius: 3px; font-size: .9em; }
pre { background: var(--code-bg); padding: .85rem 1rem; border-radius: 6px;
overflow-x: auto; font-size: .82rem; line-height: 1.45;
border-left: 3px solid var(--accent2); }
pre code { background: none; padding: 0; }
pre.shell { border-left-color: var(--ok); }
pre.objc { border-left-color: var(--accent); }
pre.c { border-left-color: #555; }
a { color: var(--accent2); }
a:hover { color: var(--accent); }
.tldr { background: var(--card); border: 1px solid var(--rule); border-left: 4px solid var(--accent2);
padding: 1rem 1.25rem; border-radius: 6px; margin-bottom: 2rem; }
.tldr h3 { margin-top: 0; color: var(--accent2); }
.pill { display: inline-block; font-size: .72rem; padding: 1px 8px; border-radius: 999px;
background: #eee; color: #333; margin-left: .35rem; vertical-align: middle;
font-weight: 600; letter-spacing: .02em; }
.pill.ok { background: #d8efd8; color: var(--ok); }
.pill.warn { background: #f6e4cb; color: var(--warn); }
.pill.bad { background: #f5d0d6; color: var(--bad); }
.pill.info { background: #d6e6f3; color: var(--accent2); }
table { border-collapse: collapse; width: 100%; margin: 1rem 0; font-size: .92rem; }
th, td { text-align: left; padding: .5rem .65rem; border-bottom: 1px solid var(--rule); vertical-align: top; }
th { background: #eee5d6; }
tr:nth-child(even) td { background: #faf6ed; }
table.compact td, table.compact th { padding: .35rem .55rem; font-size: .88rem; }
.nav { position: sticky; top: 0; background: var(--bg); margin: -2.5rem -1.5rem 2rem;
padding: .75rem 1.5rem; border-bottom: 1px solid var(--rule);
font-size: .88rem; z-index: 10; }
.nav a { margin-right: .9rem; text-decoration: none; }
.gap { background: #fff5f5; border-left: 4px solid var(--bad); padding: .8rem 1rem; margin: 1rem 0; border-radius: 0 6px 6px 0; }
.gap strong { color: var(--bad); }
.resolved { background: #ecf7ec; border-left: 4px solid var(--ok); padding: .8rem 1rem; margin: 1rem 0; border-radius: 0 6px 6px 0; }
.resolved strong { color: var(--ok); }
.open-q { background: #fff8d6; border: 1px solid #e5d76b; padding: .8rem 1rem; margin: 1rem 0; border-radius: 6px; font-size: .92rem; }
.open-q strong { color: #7a5e00; }
.yesno { font-weight: 600; }
.yesno.yes { color: var(--ok); }
.yesno.no { color: var(--bad); }
.yesno.partial { color: var(--warn); }
.src { color: var(--muted); font-size: .85em; }
.phase-badge { display: inline-block; font-size: .78rem; font-weight: 600; padding: 1px 7px;
border-radius: 4px; background: #e8e0d4; color: #555; margin-left: .3rem; }
.phase-badge.p2 { background: #d6e6f3; color: var(--accent2); }
.phase-badge.p4 { background: #f6e4cb; color: var(--warn); }
.phase-badge.p5 { background: #fde0d0; color: var(--accent); }
.phase-badge.p6 { background: #f5d0d6; color: var(--bad); }
.phase-badge.stub { background: #e8e0d4; color: #555; }
footer { margin-top: 4rem; padding-top: 1rem; border-top: 1px solid var(--rule);
color: var(--muted); font-size: .9rem; }
</style>
</head>
<body>
<nav class="nav">
<a href="#tldr">TL;DR</a>
<a href="#post-merge">Post-merge audit</a>
<a href="#cg-coverage">CG coverage</a>
<a href="#cg-gaps">CG gaps</a>
<a href="#ct-coverage">CT coverage</a>
<a href="#ct-gaps">CT gaps</a>
<a href="#imageio">ImageIO</a>
<a href="#harfbuzz">HarfBuzz</a>
<a href="#build-notes">Build notes</a>
</nav>
<h1>libs-opal — CoreGraphics, CoreText & ImageIO gaps for WebKit
<span class="pill warn">Sub-plan</span>
</h1>
<p class="subtitle">
What must be added to <code>gnustep/libs-opal</code> to reach full CoreGraphics and CoreText coverage
for the minimal WebKit v5 build. libs-opal provides CoreGraphics (<code>OpalGraphics</code>),
CoreText (<code>OpalText</code>), and ImageIO in a single library with Cairo and
FreeType/Fontconfig backends. Parent plan:
<a href="gnustep-webkit-v5-porting-plan.html">WebKit v5 Cocoa-native porting plan</a>.
</p>
<!-- ═══════════════════════════════════════════════════ TL;DR -->
<section id="tldr">
<h2>TL;DR</h2>
<div class="tldr">
<h3>Executive summary</h3>
<ul>
<li><strong>CoreGraphics (OpalGraphics) is ~90% covered.</strong> The core drawing API — contexts, paths, images, gradients, patterns, PDF, transforms — all exists with a Cairo backend. The gaps are a handful of missing functions, mostly CSS-specific geometry (conic gradients, continuous rounded rects) and Apple SPI stubs.</li>
<li><strong>CoreText (OpalText) is ~80% covered.</strong> Font creation, glyph metrics, line layout, and run access are implemented via FreeType/Fontconfig. The gaps are font fallback cascade APIs for international text and several SPI entry points WebKit calls by name.</li>
<li><strong>ImageIO is sufficient</strong> for the minimal build. PNG, JPEG, TIFF, and GIF are handled. HEIC is not needed for web. <code>CGImageMetadata</code> can be stubbed.</li>
<li><strong>Text shaping model:</strong> On macOS, WebKit uses CoreText exclusively via <code>ComplexTextControllerCoreText.mm</code> and the <code>platform/graphics/coretext/</code> files. It does <em>not</em> call HarfBuzz directly. We mirror that model: WebKit calls CT* APIs; libs-opal's OpalText may use HarfBuzz internally behind the API, but that is an implementation detail WebKit never sees.</li>
<li><strong>~5–8 functions need real implementations.</strong> The rest can be stubbed initially and filled in per phase. The highest-priority real implementations are: <code>CTFontDrawGlyphs</code> (any text at all), <code>CTFontCopyDefaultCascadeListForLanguages</code> (international content), and <code>CGPathAddUnevenCornersRoundedRect</code> (CSS border-radius).</li>
</ul>
</div>
<h3>Scope of libs-opal</h3>
<p>libs-opal ships three distinct framework personalities from one build tree:</p>
<table class="compact">
<thead><tr><th>Subproject</th><th>Framework</th><th>Backend</th><th>Headers</th><th>WebKit entry point</th></tr></thead>
<tbody>
<tr><td><code>OpalGraphics</code></td><td>CoreGraphics</td><td>Cairo 1.x + LCMS2</td><td>~35 public headers</td><td><code>platform/graphics/cg/</code>, <code>platform/cocoa/</code></td></tr>
<tr><td><code>OpalText</code></td><td>CoreText</td><td>FreeType 2 + Fontconfig + (optionally HarfBuzz)</td><td>~15 public headers</td><td><code>platform/graphics/coretext/</code>, <code>ComplexTextControllerCoreText.mm</code></td></tr>
<tr><td>(inline)</td><td>ImageIO</td><td>libpng, libjpeg, libtiff, giflib</td><td>2 public headers</td><td><code>platform/image-decoders/</code> indirectly via <code>CGImageSource</code></td></tr>
</tbody>
</table>
</section>
<!-- ═══════════════════════════════════════════════════ POST-MERGE AUDIT -->
<section id="post-merge">
<h2>Post-merge audit — 31 DTW-Thalion PRs merged <span class="pill ok">Done</span></h2>
<p>31 PRs from DTW-Thalion were merged into pkgdemon/libs-opal (including PR #48 CGPattern which required manual conflict resolution). These added 5 major new feature implementations and fixed 12+ bugs with direct WebKit impact.</p>
<h3>New features implemented by DTW PRs</h3>
<table>
<thead>
<tr>
<th>PR</th>
<th>Feature</th>
<th>WebKit Impact</th>
</tr>
</thead>
<tbody>
<tr>
<td>#52</td>
<td>CGContextSetBlendMode — all 27 Apple blend modes mapped to Cairo operators</td>
<td>Direct — CSS mix-blend-mode, compositing</td>
</tr>
<tr>
<td>#57 + #51</td>
<td>CGContextClipToMask — A8 mask pattern for fills, strokes, images, gradients, text</td>
<td>Direct — CSS masking, image masking</td>
</tr>
<tr>
<td>#56</td>
<td>CGContextDrawTiledImage — tile loop with correct anchoring</td>
<td>Direct — CSS background-repeat</td>
</tr>
<tr>
<td>#37</td>
<td>CGShading / CGFunction — axial and radial shading with 64-sample function approximation</td>
<td>Direct — gradient rendering</td>
</tr>
<tr>
<td>#48</td>
<td>CGPattern fills (colored and uncolored) — was returning nil, now implemented</td>
<td>Direct — CSS repeating patterns, SVG pattern fills</td>
</tr>
<tr>
<td>#53</td>
<td>CGGeometry dictionary representations (CGPoint/CGSize/CGRect to/from NSDictionary)</td>
<td>Property serialization</td>
</tr>
</tbody>
</table>
<h3>Critical bug fixes</h3>
<table>
<thead>
<tr>
<th>PR</th>
<th>Fix</th>
<th>WebKit Impact</th>
</tr>
</thead>
<tbody>
<tr>
<td>#39</td>
<td>Font ascent/descent — was using bbox.yMax (too large), now uses ft_face->ascender</td>
<td><strong>Critical</strong> — all text line heights and baselines were wrong</td>
</tr>
<tr>
<td>#47</td>
<td>CGBitmapContext bytesPerRow=0 — was storing 0 causing zero-length buffer</td>
<td><strong>Critical</strong> — WebKit creates contexts with bytesPerRow=0</td>
</tr>
<tr>
<td>#31</td>
<td>CGImageCreateWithImageInRect crop size — was reporting original dimensions</td>
<td>Direct — sprite sheets, CSS object-fit, canvas drawImage</td>
</tr>
<tr>
<td>#45</td>
<td>CGDataProvider releaseData callback never called — memory leak</td>
<td>Direct — every buffer passed through CGDataProviderCreateWithData leaked</td>
</tr>
<tr>
<td>#28</td>
<td>CGPathGetCurrentPoint after close — was returning close point, not move point</td>
<td>Path construction correctness</td>
</tr>
<tr>
<td>#36</td>
<td>JPEG encoder was embedding garbage alpha channel</td>
<td>Image output correctness</td>
</tr>
<tr>
<td>#50</td>
<td>Fill/stroke color reset on color space change</td>
<td>Color correctness</td>
</tr>
<tr>
<td>#19</td>
<td>Dash array allocated as bytes not doubles — stack corruption</td>
<td>Crash fix</td>
</tr>
<tr>
<td>#22</td>
<td>CGAffineTransformIsIdentity was treating any diagonal as identity</td>
<td>Transform correctness</td>
</tr>
<tr>
<td>#26</td>
<td>CGColor component count didn't include alpha; equality broken</td>
<td>Color correctness</td>
</tr>
</tbody>
</table>
<h3>Coverage update</h3>
<div class="resolved">
CoreGraphics coverage: <strong>~75%</strong> (up from ~62% pre-merge). The 5 new feature implementations (blend modes, clip-to-mask, tiled image, shading/function, pattern) close major rendering gaps.
<br><br>
CoreText coverage: <strong>~45%</strong> (up from ~40%). The ascent/descent fix is the main gain — no new CT functions were added.
</div>
<h3>Remaining gaps</h3>
<div class="gap">
<strong>CoreGraphics remaining:</strong>
<ul>
<li>CGContextDrawConicGradient — not present (CSS conic-gradient)</li>
<li>CGPathAddContinuousRoundedRect / CGPathAddUnevenCornersRoundedRect — not present</li>
<li>CGContextSetBaseCTM — Apple SPI, not present</li>
<li>CGColorSpaceUsesExtendedRange — not present (stub returning false is sufficient)</li>
</ul>
<strong>CoreText remaining (these are the biggest blockers):</strong>
<ul>
<li>CTTypesetter shaping — EMPTY FIXME, returns empty runs. <strong>#1 blocker — no text renders without this</strong></li>
<li>CTFontDrawGlyphs — stub that returns immediately (fallback via CGContextShowGlyphsAtPositions works)</li>
<li>CTFontCopyDefaultCascadeListForLanguages — not present (font fallback)</li>
<li>CTFontDescriptorCreateForCSSFamily — not present (CSS font families)</li>
<li>CTFontCreateForCharactersWithLanguageAndOption — not present (per-character font selection)</li>
</ul>
</div>
</section>
<!-- ═══════════════════════════════════════════════════ CG COVERAGE -->
<section id="cg-coverage">
<h2>CoreGraphics coverage</h2>
<p>Coverage is assessed against what WebKit's Cocoa port actually calls. Files audited:
<code>Source/WebCore/platform/graphics/cg/</code>,
<code>Source/WebCore/platform/cocoa/</code>,
<code>Source/WebKit/WebProcess/WebPage/Cocoa/</code>,
<code>Source/WebCore/rendering/</code> (for geometry helpers).</p>
<table>
<thead>
<tr>
<th>API group</th>
<th>Key types / functions</th>
<th>libs-opal has it?</th>
<th>Notes</th>
</tr>
</thead>
<tbody>
<tr>
<td><strong>CGContext — drawing</strong></td>
<td><code>CGContextDrawImage</code>, <code>CGContextFillRect</code>, <code>CGContextStrokePath</code>, <code>CGContextSaveGState</code> / <code>RestoreGState</code>, <code>CGContextClip*</code>, blend modes, shadow, transparency layers</td>
<td><span class="yesno yes">Yes</span></td>
<td>Full Cairo mapping in <code>CGContext.m</code></td>
</tr>
<tr>
<td><strong>CGContext — transforms</strong></td>
<td><code>CGContextConcatCTM</code>, <code>CGContextGetCTM</code>, <code>CGContextTranslateCTM</code>, <code>CGContextScaleCTM</code>, <code>CGContextRotateCTM</code></td>
<td><span class="yesno yes">Yes</span></td>
<td></td>
</tr>
<tr>
<td><strong>CGBitmapContext</strong></td>
<td><code>CGBitmapContextCreate</code>, <code>CGBitmapContextCreateImage</code>, <code>CGBitmapContextGetData</code>, bitmap info flags</td>
<td><span class="yesno yes">Yes</span></td>
<td>Critical for off-screen compositing</td>
</tr>
<tr>
<td><strong>CGPath</strong></td>
<td><code>CGPathCreateMutable</code>, <code>CGPathAddArc</code>, <code>CGPathAddCurveToPoint</code>, <code>CGPathAddEllipseInRect</code>, <code>CGPathAddRect</code>, <code>CGPathAddRoundedRect</code>, <code>CGPathApply</code></td>
<td><span class="yesno yes">Yes</span></td>
<td>Missing: continuous rounded rect variants (see gaps)</td>
</tr>
<tr>
<td><strong>CGImage</strong></td>
<td><code>CGImageCreate</code>, <code>CGImageCreateCopy</code>, <code>CGImageCreateWithImageInRect</code>, <code>CGImageGetWidth/Height/BitsPerComponent</code>, <code>CGImageRelease</code></td>
<td><span class="yesno yes">Yes</span></td>
<td></td>
</tr>
<tr>
<td><strong>CGImageSource / Destination</strong></td>
<td><code>CGImageSourceCreateWithData</code>, <code>CGImageSourceCreateImageAtIndex</code>, <code>CGImageSourceGetCount</code>, <code>CGImageDestinationCreate*</code>, <code>CGImageDestinationFinalize</code></td>
<td><span class="yesno yes">Yes</span></td>
<td>In the ImageIO layer</td>
</tr>
<tr>
<td><strong>CGColor</strong></td>
<td><code>CGColorCreate</code>, <code>CGColorCreateGenericRGB</code>, <code>CGColorGetComponents</code>, <code>CGColorGetColorSpace</code>, named system colors</td>
<td><span class="yesno yes">Yes</span></td>
<td></td>
</tr>
<tr>
<td><strong>CGColorSpace</strong></td>
<td><code>CGColorSpaceCreateDeviceRGB</code>, <code>CGColorSpaceCreateWithName</code> (<code>kCGColorSpaceSRGB</code>, <code>kCGColorSpaceDisplayP3</code>), ICC profile creation, LCMS2 backend</td>
<td><span class="yesno yes">Yes</span></td>
<td>Wide-gamut names may need adding</td>
</tr>
<tr>
<td><strong>CGFont</strong></td>
<td><code>CGFontCreateWithFontName</code>, <code>CGFontCreateWithDataProvider</code>, <code>CGFontGetGlyphBoundingBoxes</code>, <code>CGFontGetAscent/Descent/CapHeight/XHeight</code>, <code>CGFontCopyTableForTag</code></td>
<td><span class="yesno yes">Yes</span></td>
<td>Backed by FreeType via OpalText</td>
</tr>
<tr>
<td><strong>CGGradient — linear & radial</strong></td>
<td><code>CGGradientCreateWithColors</code>, <code>CGContextDrawLinearGradient</code>, <code>CGContextDrawRadialGradient</code>, extend options</td>
<td><span class="yesno yes">Yes</span></td>
<td>Cairo <code>cairo_pattern_t</code> mapping</td>
</tr>
<tr>
<td><strong>CGGradient — conic</strong></td>
<td><code>CGContextDrawConicGradient</code></td>
<td><span class="yesno no">No</span></td>
<td>See gap 3a</td>
</tr>
<tr>
<td><strong>CGShading</strong></td>
<td><code>CGShadingCreateAxial</code>, <code>CGShadingCreateRadial</code>, <code>CGContextDrawShading</code></td>
<td><span class="yesno yes">Yes</span></td>
<td></td>
</tr>
<tr>
<td><strong>CGPattern</strong></td>
<td><code>CGPatternCreate</code>, <code>CGColorSpaceCreatePattern</code>, <code>CGContextSetFillPattern</code></td>
<td><span class="yesno yes">Yes</span></td>
<td></td>
</tr>
<tr>
<td><strong>CGLayer</strong></td>
<td><code>CGLayerCreateWithContext</code>, <code>CGContextDrawLayerAtPoint</code>, <code>CGLayerGetContext</code></td>
<td><span class="yesno yes">Yes</span></td>
<td></td>
</tr>
<tr>
<td><strong>CGPDFDocument / Page / Context</strong></td>
<td><code>CGPDFDocumentCreateWithURL</code>, <code>CGPDFPageGetDrawingTransform</code>, <code>CGContextBeginPage</code>, <code>CGPDFContextCreate</code></td>
<td><span class="yesno yes">Yes</span></td>
<td>PDF disabled in minimal build anyway</td>
</tr>
<tr>
<td><strong>CGAffineTransform</strong></td>
<td><code>CGAffineTransformMake</code>, <code>CGAffineTransformConcat</code>, <code>CGAffineTransformInvert</code>, <code>CGAffineTransformIsIdentity</code>, point/rect application</td>
<td><span class="yesno yes">Yes</span></td>
<td></td>
</tr>
<tr>
<td><strong>CGDataProvider / Consumer</strong></td>
<td><code>CGDataProviderCreateWithData</code>, <code>CGDataProviderCreateWithURL</code>, sequential callbacks, direct-access callbacks</td>
<td><span class="yesno yes">Yes</span></td>
<td></td>
</tr>
<tr>
<td><strong>CGFunction</strong></td>
<td><code>CGFunctionCreate</code> with callbacks (used by <code>CGShading</code>)</td>
<td><span class="yesno yes">Yes</span></td>
<td></td>
</tr>
<tr>
<td><strong>CGGeometry helpers</strong></td>
<td><code>CGRectUnion</code>, <code>CGRectIntersection</code>, <code>CGRectContainsRect</code>, <code>CGPointApplyAffineTransform</code>, <code>CGSizeApplyAffineTransform</code></td>
<td><span class="yesno yes">Yes</span></td>
<td></td>
</tr>
<tr>
<td><strong>CGContextSetBaseCTM</strong></td>
<td>Apple SPI for base CTM</td>
<td><span class="yesno no">No</span></td>
<td>See gap 3c</td>
</tr>
<tr>
<td><strong>CGColorSpaceUsesExtendedRange</strong></td>
<td>HDR range query</td>
<td><span class="yesno no">No</span></td>
<td>See gap 3d</td>
</tr>
<tr>
<td><strong>CG SPI family</strong></td>
<td><code>CGStyleRef</code>, <code>CGGStateRef</code>, <code>CGContextDelegateRef</code>, etc.</td>
<td><span class="yesno no">No</span></td>
<td>Stub header needed; see gap 3e</td>
</tr>
</tbody>
</table>
</section>
<!-- ═══════════════════════════════════════════════════ CG GAPS -->
<section id="cg-gaps">
<h2>CoreGraphics gaps — must add</h2>
<!-- 3a -->
<h3>3a. <code>CGContextDrawConicGradient</code> <span class="phase-badge p6">Phase 6</span></h3>
<div class="gap">
<strong>Missing from libs-opal.</strong> WebKit uses this for CSS <code>conic-gradient()</code> and <code>@property</code> painted decorations.
</div>
<p>Function signature (Apple private extension of CGGradient):</p>
<pre class="c">void CGContextDrawConicGradient(
CGContextRef context,
CGGradientRef gradient,
CGPoint center,
CGFloat angle /* rotation in radians */
);</pre>
<p>Cairo has no native conic gradient primitive. Three implementation strategies:</p>
<ol>
<li><strong>Manual angular rasterization (recommended for correctness).</strong> Create a <code>cairo_surface_t</code> of the bounding box, fill each pixel by computing its angle from <code>center</code>, look up the gradient stop, write the ARGB value. Then paint that surface onto the context. ~150–200 LOC. This is exact and independent of Cairo version.</li>
<li><strong>Mesh gradient approximation.</strong> Cairo 1.12+ has <code>cairo_pattern_create_mesh()</code>. Divide the circle into N wedge-shaped mesh patches. Each patch is a Coon's patch approximating a pie slice. N=72 (5° steps) gives smooth output. ~250 LOC.</li>
<li><strong>Stub (return immediately).</strong> Conic gradients are absent from basic web content. The minimal build can stub this entirely — pages will simply paint the first gradient stop's solid color instead.</li>
</ol>
<p><strong>Plan:</strong> Stub in Phase 2–5. Implement via manual rasterization in Phase 6.</p>
<pre class="c">/* Source/OpalGraphics/CGGradient.m — stub */
void CGContextDrawConicGradient(CGContextRef ctx,
CGGradientRef gradient,
CGPoint center,
CGFloat angle)
{
/* TODO Phase 6: angular rasterization via cairo_image_surface */
(void)ctx; (void)gradient; (void)center; (void)angle;
}</pre>
<!-- 3b -->
<h3>3b. <code>CGPathAddContinuousRoundedRect</code> / <code>CGPathAddUnevenCornersRoundedRect</code> <span class="phase-badge p4">Phase 4–5</span></h3>
<div class="gap">
<strong>Missing from libs-opal.</strong> WebKit calls these for CSS <code>border-radius</code>. Without them, rounded boxes fall back to rectangular clips or incorrect geometry.
</div>
<p>Function signatures:</p>
<pre class="c">/* Continuous ("squircle") rounded rect — equal corner radii, iOS-style superellipse */
void CGPathAddContinuousRoundedRect(
CGMutablePathRef path,
const CGAffineTransform *transform,
CGRect rect,
CGFloat cornerWidth,
CGFloat cornerHeight);
/* Per-corner radii — used for arbitrary border-radius values */
void CGPathAddUnevenCornersRoundedRect(
CGMutablePathRef path,
const CGAffineTransform *transform,
CGRect rect,
const CGSize topLeft,
const CGSize topRight,
const CGSize bottomRight,
const CGSize bottomLeft);</pre>
<p><strong>Implementation approach for <code>CGPathAddUnevenCornersRoundedRect</code>:</strong> Each corner is a quarter-ellipse arc. Use <code>CGPathAddArc</code> (already implemented) for each of the four corners with its respective <code>CGSize</code> radii, connected by straight line segments. This is straightforward and ~100 LOC:</p>
<pre class="c">void CGPathAddUnevenCornersRoundedRect(
CGMutablePathRef path,
const CGAffineTransform *t,
CGRect r,
const CGSize tl, const CGSize tr,
const CGSize br, const CGSize bl)
{
CGFloat minX = CGRectGetMinX(r), minY = CGRectGetMinY(r);
CGFloat maxX = CGRectGetMaxX(r), maxY = CGRectGetMaxY(r);
/* Top edge, start after top-left corner */
CGPathMoveToPoint(path, t, minX + tl.width, minY);
/* Top-right */
CGPathAddLineToPoint(path, t, maxX - tr.width, minY);
CGPathAddCurveToPoint(path, t,
maxX - tr.width * 0.4477f, minY,
maxX, minY + tr.height * 0.4477f,
maxX, minY + tr.height);
/* Bottom-right */
CGPathAddLineToPoint(path, t, maxX, maxY - br.height);
CGPathAddCurveToPoint(path, t,
maxX, maxY - br.height * 0.4477f,
maxX - br.width * 0.4477f, maxY,
maxX - br.width, maxY);
/* Bottom-left */
CGPathAddLineToPoint(path, t, minX + bl.width, maxY);
CGPathAddCurveToPoint(path, t,
minX + bl.width * 0.4477f, maxY,
minX, maxY - bl.height * 0.4477f,
minX, maxY - bl.height);
/* Top-left */
CGPathAddLineToPoint(path, t, minX, minY + tl.height);
CGPathAddCurveToPoint(path, t,
minX, minY + tl.height * 0.4477f,
minX + tl.width * 0.4477f, minY,
minX + tl.width, minY);
CGPathCloseSubpath(path);
}</pre>
<p>The constant <code>0.4477</code> is the standard cubic Bezier circle approximation factor (4*(sqrt(2)-1)/3). For <code>CGPathAddContinuousRoundedRect</code>, implement first as a simple <code>CGPathAddRoundedRect</code> alias using equal radii — the "squircle" superellipse shape can be refined later with a proper 5th-order superellipse approximation in Phase 6.</p>
<p><strong>Estimated LOC:</strong> ~120 for both functions. File: <code>Source/OpalGraphics/CGPath.m</code>.</p>
<!-- 3c -->
<h3>3c. <code>CGContextSetBaseCTM</code> <span class="phase-badge p2">Phase 2</span></h3>
<div class="gap">
<strong>Apple SPI. Missing from libs-opal.</strong> WebKit calls this early in the drawing pipeline to set the device-pixel-aligned base coordinate transform, below the user CTM. Without it, sub-pixel rendering alignment is off.
</div>
<pre class="c">/* Apple SPI — sets the base (device) CTM separate from the user CTM */
void CGContextSetBaseCTM(CGContextRef ctx, CGAffineTransform transform);</pre>
<p>The base CTM concept separates the "device to surface" transform from the "user space to device" transform. In Cairo terms, this maps to <code>cairo_surface_set_device_transform()</code> applied to the underlying surface, while the context CTM (<code>cairo_transform()</code>) handles the user space. The simplest approach for Phase 2 is to <em>fold</em> the base CTM into the context CTM — i.e., concatenate it with <code>CGContextConcatCTM</code>. This loses the semantic separation but is sufficient for correct pixel output:</p>
<pre class="c">void CGContextSetBaseCTM(CGContextRef ctx, CGAffineTransform transform)
{
/* Phase 2 approximation: fold base CTM into context CTM.
* Proper implementation: apply via cairo_surface_set_device_transform
* on the underlying cairo_surface_t and track separately in OpalContext. */
CGContextConcatCTM(ctx, transform);
}</pre>
<p>This function should be declared in <code>Headers/CoreGraphics/CoreGraphicsSPI.h</code> (see gap 3e) and implemented in <code>Source/OpalGraphics/CGContext.m</code>.</p>
<!-- 3d -->
<h3>3d. <code>CGColorSpaceUsesExtendedRange</code> <span class="phase-badge stub">Stub immediately</span></h3>
<div class="gap">
<strong>Missing from libs-opal.</strong> WebKit queries this to determine if a color space can represent HDR values (outside [0,1]). Used in compositing decisions for EDR/HDR content.
</div>
<pre class="c">bool CGColorSpaceUsesExtendedRange(CGColorSpaceRef space);</pre>
<p>All Cairo-backed color spaces in libs-opal operate in [0,1] SDR range. Return <code>false</code> unconditionally. This is correct for all color spaces OpalGraphics currently creates:</p>
<pre class="c">/* Source/OpalGraphics/CGColorSpace.m */
bool CGColorSpaceUsesExtendedRange(CGColorSpaceRef space)
{
(void)space;
return false; /* OpalGraphics has no HDR/EDR color spaces */
}</pre>
<p>Add to <code>Headers/CoreGraphics/CGColorSpace.h</code> as a public API (it is technically public on macOS 10.12+).</p>
<!-- 3e -->
<h3>3e. Apple SPI stub header — <code>CoreGraphicsSPI.h</code> <span class="phase-badge p2">Phase 2</span></h3>
<div class="gap">
<strong>Missing from libs-opal.</strong> WebKit includes <code><CoreGraphics/CoreGraphicsSPI.h></code> from numerous files in <code>platform/graphics/cg/</code> and <code>platform/cocoa/</code>. Without this header, WebKit will not compile.
</div>
<p>This header must live at <code>Headers/CoreGraphics/CoreGraphicsSPI.h</code> and declare (with stub implementations in <code>Source/OpalGraphics/CGContextSPI.m</code>) the following Apple-private entry points that WebKit references:</p>
<h4>CGStyleRef family (focus ring, shadows, color matrices)</h4>
<pre class="c">typedef struct CGStyle *CGStyleRef;
typedef struct CGGState *CGGStateRef;
/* Focus ring drawing */
CGStyleRef CGStyleCreateFocusRingWithColor(CGColorRef color);
void CGContextSetStyle(CGContextRef ctx, CGStyleRef style);
void CGStyleRelease(CGStyleRef style);
/* Color matrix / image effects */
typedef struct CGColorTransform *CGColorTransformRef;
CGColorTransformRef CGColorTransformCreate(CGColorSpaceRef space,
CFDictionaryRef attributes);
void CGColorTransformRelease(CGColorTransformRef xform);
CGImageRef CGImageApplyColorTransform(CGImageRef image,
CGColorTransformRef xform);</pre>
<h4>CGFont rendering style SPI</h4>
<pre class="c">/* Font antialiasing / rendering style queries */
typedef uint32_t CGFontRenderingStyle;
typedef uint32_t CGFontAntialiasingStyle;
#define kCGFontRenderingStyleAntialiasing (1 << 0)
#define kCGFontRenderingStyleSubpixelPositioning (1 << 1)
#define kCGFontRenderingStyleSubpixelQuantization (1 << 2)
CGFontRenderingStyle CGFontGetRenderingStyle(CGFontRef font);
CGFontAntialiasingStyle CGFontGetAntialiasingStyle(CGFontRef font);</pre>
<h4>CGContext delegate (compositor hooks)</h4>
<pre class="c">typedef struct CGContextDelegate *CGContextDelegateRef;
/* Stub — WebKit checks for this on macOS only; always NULL on GNUstep */
CGContextDelegateRef CGContextGetDelegate(CGContextRef ctx);
void CGContextSetDelegate(CGContextRef ctx, CGContextDelegateRef delegate);</pre>
<h4>IOSurface context (disabled)</h4>
<pre class="c">/* Stub — IOSurface is not available on GNUstep; WebKit guards with HAVE(IOSURFACE) */
typedef void *CGIOSurfaceContextRef; /* opaque, never non-NULL on GNUstep */
CGContextRef CGIOSurfaceContextCreate(CGIOSurfaceContextRef surface,
size_t width, size_t height,
size_t bitsPerComponent, size_t bytesPerRow,
CGColorSpaceRef colorSpace, CGBitmapInfo bitmapInfo);
/* Returns NULL */</pre>
<h4>CGS Window Server functions (not applicable)</h4>
<pre class="c">/* CGS* are Quartz Window Server SPI — not applicable to GNUstep.
* WebKit guards these with PLATFORM(MAC). Define as dead stubs for
* source compatibility; should never be called at runtime. */
typedef int CGSConnectionID;
typedef uint32_t CGSWindowID;
CGSConnectionID CGSMainConnectionID(void); /* returns 0 */
CGError CGSSetWindowOpacity(CGSConnectionID cid,
CGSWindowID wid, bool isOpaque); /* returns kCGErrorFailure */</pre>
<h4>Image cache flags</h4>
<pre class="c">typedef uint32_t CGImageCachingFlags;
#define kCGImageCachingTransient 0
#define kCGImageCachingTemporary 1
#define kCGImageCachingAlwaysCache 2
void CGImageSetCachingFlags(CGImageRef image, CGImageCachingFlags flags);
/* Stub: OpalGraphics has no image cache; this is a no-op */</pre>
<h4>CGContextSetBaseCTM (also declared here)</h4>
<pre class="c">void CGContextSetBaseCTM(CGContextRef ctx, CGAffineTransform transform);</pre>
<p>All stub implementations belong in a new file <code>Source/OpalGraphics/CGContextSPI.m</code>. Each function body is a no-op or returns a safe zero/NULL value. The goal is source-level compilation; none of these are called on the GNUstep code path at runtime.</p>
</section>
<!-- ═══════════════════════════════════════════════════ CT COVERAGE -->
<section id="ct-coverage">
<h2>CoreText coverage</h2>
<p>Coverage assessed against <code>Source/WebCore/platform/graphics/coretext/</code>,
<code>Source/WebCore/platform/cocoa/FontCocoa.mm</code>,
<code>Source/WebCore/platform/graphics/ComplexTextController.cpp</code>,
<code>Source/WebCore/platform/graphics/ComplexTextControllerCoreText.mm</code>,
and font-loading code in <code>Source/WebCore/platform/graphics/cocoa/FontPlatformDataCocoa.mm</code>.</p>
<div class="resolved">
<strong>Architecture note:</strong> WebKit on macOS does <em>not</em> call HarfBuzz or FreeType directly. All text shaping goes through CT* APIs. OpalText implements those CT* APIs and may use HarfBuzz internally (behind the API surface), but WebKit is unaware of this. This matches exactly what macOS does — WebKit is unmodified.
</div>
<table>
<thead>
<tr>
<th>API group</th>
<th>Key types / functions</th>
<th>libs-opal has it?</th>
<th>Notes</th>
</tr>
</thead>
<tbody>
<tr>
<td><strong>CTFont — creation</strong></td>
<td><code>CTFontCreateWithName</code>, <code>CTFontCreateWithFontDescriptor</code>, <code>CTFontCreateCopyWithAttributes</code>, <code>CTFontCreateCopyWithSymbolicTraits</code>, <code>CTFontCreateWithGraphicsFont</code></td>
<td><span class="yesno yes">Yes</span></td>
<td>FreeType backend</td>
</tr>
<tr>
<td><strong>CTFont — metrics</strong></td>
<td><code>CTFontGetSize</code>, <code>CTFontGetAscent</code>, <code>CTFontGetDescent</code>, <code>CTFontGetLeading</code>, <code>CTFontGetCapHeight</code>, <code>CTFontGetXHeight</code>, <code>CTFontGetUnitsPerEm</code>, <code>CTFontGetBoundingBox</code></td>
<td><span class="yesno yes">Yes</span></td>
<td></td>
</tr>
<tr>
<td><strong>CTFont — glyph access</strong></td>
<td><code>CTFontGetGlyphsForCharacters</code>, <code>CTFontGetAdvancesForGlyphs</code>, <code>CTFontGetBoundingRectsForGlyphs</code>, <code>CTFontGetVerticalTranslationsForGlyphs</code></td>
<td><span class="yesno yes">Yes</span></td>
<td></td>
</tr>
<tr>
<td><strong>CTFont — table access</strong></td>
<td><code>CTFontCopyTable</code> (<code>kCTFontTableCmap</code>, <code>kCTFontTableGlyf</code>, <code>kCTFontTableOS2</code>, etc.)</td>
<td><span class="yesno yes">Yes</span></td>
<td>FreeType raw table access</td>
</tr>
<tr>
<td><strong>CTFont — name attributes</strong></td>
<td><code>CTFontCopyPostScriptName</code>, <code>CTFontCopyFamilyName</code>, <code>CTFontCopyFullName</code>, <code>CTFontCopyDisplayName</code></td>
<td><span class="yesno yes">Yes</span></td>
<td></td>
</tr>
<tr>
<td><strong>CTFontDescriptor</strong></td>
<td><code>CTFontDescriptorCreateWithAttributes</code>, <code>CTFontDescriptorCopyAttribute</code>, <code>CTFontDescriptorCreateMatchingFontDescriptors</code>, <code>CTFontDescriptorCreateWithNameAndSize</code></td>
<td><span class="yesno yes">Yes</span></td>
<td>Fontconfig backend</td>
</tr>
<tr>
<td><strong>CTFontCollection</strong></td>
<td><code>CTFontCollectionCreateFromAvailableFonts</code>, <code>CTFontCollectionCreateMatchingFontDescriptors</code></td>
<td><span class="yesno yes">Yes</span></td>
<td></td>
</tr>
<tr>
<td><strong>CTFontManager</strong></td>
<td><code>CTFontManagerRegisterFontsForURL</code>, <code>CTFontManagerCopyAvailableFontFamilyNames</code></td>
<td><span class="yesno yes">Yes</span></td>
<td></td>
</tr>
<tr>
<td><strong>CTLine — creation & drawing</strong></td>
<td><code>CTLineCreateWithAttributedString</code>, <code>CTLineDraw</code>, <code>CTLineGetOffsetForStringIndex</code>, <code>CTLineGetStringIndexForPosition</code></td>
<td><span class="yesno yes">Yes</span></td>
<td></td>
</tr>
<tr>
<td><strong>CTLine — metrics</strong></td>
<td><code>CTLineGetTypographicBounds</code>, <code>CTLineGetImageBounds</code>, <code>CTLineGetTrailingWhitespaceWidth</code>, <code>CTLineGetGlyphRuns</code></td>
<td><span class="yesno yes">Yes</span></td>
<td></td>
</tr>
<tr>
<td><strong>CTRun</strong></td>
<td><code>CTRunGetGlyphs</code>, <code>CTRunGetAdvances</code>, <code>CTRunGetPositions</code>, <code>CTRunGetAttributes</code>, <code>CTRunGetStatus</code>, <code>CTRunGetGlyphCount</code>, <code>CTRunGetStringRange</code>, <code>CTRunGetTypographicBounds</code></td>
<td><span class="yesno yes">Yes</span></td>
<td>Core of complex text shaping output</td>
</tr>
<tr>
<td><strong>CTFrame / CTFramesetter</strong></td>
<td><code>CTFramesetterCreateWithAttributedString</code>, <code>CTFramesetterCreateFrame</code>, <code>CTFrameGetLines</code>, <code>CTFrameDraw</code>, <code>CTFramesetterSuggestFrameSizeWithConstraints</code></td>
<td><span class="yesno yes">Yes</span></td>
<td></td>
</tr>
<tr>
<td><strong>CTTypesetter</strong></td>
<td><code>CTTypesetterCreateWithAttributedString</code>, <code>CTTypesetterSuggestLineBreak</code>, <code>CTTypesetterCreateLine</code></td>
<td><span class="yesno yes">Yes</span></td>
<td></td>
</tr>
<tr>
<td><strong>CTParagraphStyle</strong></td>
<td><code>CTParagraphStyleCreate</code>, <code>CTParagraphStyleGetValueForSpecifier</code>, writing direction, alignment, line break mode</td>
<td><span class="yesno yes">Yes</span></td>
<td></td>
</tr>
<tr>
<td><strong>CTTextTab</strong></td>
<td><code>CTTextTabCreate</code>, <code>CTTextTabGetLocation</code>, <code>CTTextTabGetAlignment</code></td>
<td><span class="yesno yes">Yes</span></td>
<td></td>
</tr>
<tr>
<td><strong>CTGlyphInfo</strong></td>
<td><code>CTGlyphInfoCreateWithGlyph</code>, <code>CTGlyphInfoGetGlyph</code></td>
<td><span class="yesno yes">Yes</span></td>
<td></td>
</tr>
<tr>
<td><strong>CTStringAttributes</strong></td>
<td><code>kCTFontAttributeName</code>, <code>kCTForegroundColorAttributeName</code>, <code>kCTKernAttributeName</code>, <code>kCTLigatureAttributeName</code>, <code>kCTUnderlineStyleAttributeName</code>, <code>kCTParagraphStyleAttributeName</code></td>
<td><span class="yesno yes">Yes</span></td>
<td></td>
</tr>
<tr>
<td><strong>CTFont cascade list</strong></td>
<td><code>CTFontCopyDefaultCascadeListForLanguages</code></td>
<td><span class="yesno no">No</span></td>
<td>See gap 5a — CRITICAL</td>
</tr>
<tr>
<td><strong>CTFontDrawGlyphs</strong></td>
<td>Public API to draw glyphs at positions</td>
<td><span class="yesno partial">Partial</span></td>
<td>See gap 5c — verify & fix</td>
</tr>
<tr>
<td><strong>CT SPI family</strong></td>
<td><code>CTFontDescriptorCreateForCSSFamily</code>, <code>CTFontCreateForCharactersWithLanguageAndOption</code>, <code>CTLineCreateWithUniCharProvider</code>, etc.</td>
<td><span class="yesno no">No</span></td>
<td>See gaps 5b, 5d, 5f</td>
</tr>
</tbody>
</table>
</section>
<!-- ═══════════════════════════════════════════════════ CT GAPS -->
<section id="ct-gaps">
<h2>CoreText gaps — must add</h2>
<!-- 5a -->
<h3>5a. <code>CTFontCopyDefaultCascadeListForLanguages</code> <span class="phase-badge p5">Phase 5–6</span></h3>
<div class="gap">
<strong>CRITICAL for web content. Missing from libs-opal.</strong> This is the primary font fallback mechanism. WebKit calls it to obtain the ordered list of fallback fonts for a given primary font and an array of BCP-47 language tags. Without it, characters not present in the primary font render as missing-glyph boxes for <em>all</em> non-Latin scripts (CJK, Arabic, Hebrew, Devanagari, etc.).
</div>
<pre class="c">/* Returns CFArray of CTFontDescriptorRef, ordered by priority */
CFArrayRef CTFontCopyDefaultCascadeListForLanguages(
CTFontRef font,
CFArrayRef languagePrefList /* CFArray of CFStringRef BCP-47 tags */
);</pre>
<p><strong>Implementation plan using Fontconfig:</strong></p>
<ol>
<li>Extract the primary font's family name from <code>font</code>.</li>
<li>For each language tag in <code>languagePrefList</code>, create an <code>FcPattern</code> with <code>FC_LANG</code> set to that language (converting BCP-47 <code>zh-Hans</code> to fontconfig <code>zh-cn</code> etc.).</li>
<li>Call <code>FcFontSort(config, pattern, FcTrue, &charset, &result)</code> to get all fonts covering that language, sorted by match quality.</li>
<li>Deduplicate across languages (fonts appearing for multiple languages appear once, at the highest-priority position).</li>
<li>Exclude the primary font itself from the result (the cascade list is fallbacks only).</li>
<li>Wrap each <code>FcPattern</code> result as a <code>CTFontDescriptorRef</code> via <code>CTFontDescriptorCreateWithAttributes</code> (already implemented in OpalText).</li>
<li>Return as a <code>CFArrayRef</code>.</li>
</ol>
<pre class="c">/* Source/OpalText/CTFont.m — sketch */
CFArrayRef CTFontCopyDefaultCascadeListForLanguages(
CTFontRef font,
CFArrayRef languagePrefList)
{
FcConfig *config = FcConfigGetCurrent();
CFMutableArrayRef result = CFArrayCreateMutable(
kCFAllocatorDefault, 0, &kCFTypeArrayCallBacks);
CFIndex langCount = CFArrayGetCount(languagePrefList);
for (CFIndex i = 0; i < langCount; i++) {
CFStringRef lang = CFArrayGetValueAtIndex(languagePrefList, i);
char langBuf[64] = {0};
CFStringGetCString(lang, langBuf, sizeof(langBuf),
kCFStringEncodingUTF8);
FcPattern *pat = FcPatternCreate();
FcPatternAddString(pat, FC_LANG,
(const FcChar8 *)opal_bcp47_to_fc_lang(langBuf));
FcResult fcr;
FcFontSet *fs = FcFontSort(config, pat, FcTrue, NULL, &fcr);
if (fs) {
for (int j = 0; j < fs->nfont; j++) {
FcChar8 *family = NULL;
FcPatternGetString(fs->fonts[j], FC_FAMILY, 0, &family);
if (family && !opal_cascade_list_contains(result, family)) {
CTFontDescriptorRef desc =
opal_fd_from_fc_pattern(fs->fonts[j]);
CFArrayAppendValue(result, desc);
CFRelease(desc);
}
}
FcFontSetDestroy(fs);
}
FcPatternDestroy(pat);
}
return result;
}</pre>
<p><strong>Estimated LOC:</strong> ~180 including the BCP-47 to fontconfig language tag conversion table and the deduplication helpers. File: <code>Source/OpalText/CTFont.m</code>.</p>
<!-- 5b -->
<h3>5b. <code>CTFontDescriptorCreateForCSSFamily</code> <span class="phase-badge p5">Phase 5</span></h3>
<div class="gap">
<strong>Apple SPI. Missing from libs-opal.</strong> WebKit calls this to resolve CSS generic font families to system font descriptors. Without it, all CSS generic families silently fail and WebKit may assert or crash.
</div>
<pre class="c">/* kCTFontCSSFamilySerif, kCTFontCSSFamilySansSerif, etc. */
typedef uint32_t CTFontCSSFamilyClass;
#define kCTFontCSSFamilySerif 0
#define kCTFontCSSFamilySansSerif 1
#define kCTFontCSSFamilyCursive 2
#define kCTFontCSSFamilyFantasy 3
#define kCTFontCSSFamilyMonospace 4
#define kCTFontCSSFamilySystemUI 5
CTFontDescriptorRef CTFontDescriptorCreateForCSSFamily(
CTFontCSSFamilyClass cssFamily,
CFStringRef *outFamilyName /* optional; receives resolved family name */
);</pre>
<p><strong>Implementation:</strong> Map CSS family constants to fontconfig generic aliases (<code>serif</code>, <code>sans-serif</code>, <code>monospace</code>) and call <code>CTFontDescriptorCreateWithNameAndSize</code>:</p>
<pre class="c">static const char *opal_css_family_fc_name(CTFontCSSFamilyClass cls) {
switch (cls) {
case kCTFontCSSFamilySerif: return "serif";
case kCTFontCSSFamilySansSerif: return "sans-serif";
case kCTFontCSSFamilyCursive: return "cursive";
case kCTFontCSSFamilyFantasy: return "fantasy";
case kCTFontCSSFamilyMonospace: return "monospace";
case kCTFontCSSFamilySystemUI: return "sans-serif"; /* best effort */
default: return "sans-serif";
}
}
CTFontDescriptorRef CTFontDescriptorCreateForCSSFamily(
CTFontCSSFamilyClass cssFamily,
CFStringRef *outFamilyName)
{
const char *fcName = opal_css_family_fc_name(cssFamily);
CFStringRef name = CFStringCreateWithCString(
kCFAllocatorDefault, fcName, kCFStringEncodingUTF8);
if (outFamilyName) *outFamilyName = CFRetain(name);
CTFontDescriptorRef desc = CTFontDescriptorCreateWithNameAndSize(name, 0);
CFRelease(name);
return desc;
}</pre>
<p><strong>Estimated LOC:</strong> ~90. File: <code>Source/OpalText/CTFontDescriptor.m</code>. Declare in <code>Headers/CoreText/CoreTextSPI.h</code>.</p>
<!-- 5c -->
<h3>5c. <code>CTFontDrawGlyphs</code> <span class="phase-badge p2">Phase 2</span></h3>
<div class="gap">
<strong>Partially present — verify and fix.</strong> <code>CTFontDrawGlyphs</code> is the public API that WebKit's <code>DrawGlyphsRecorder</code> and <code>ComplexTextControllerCoreText.mm</code> use to paint glyph arrays into a CGContext. If it has bugs or is missing, <em>no text renders at all</em>.
</div>
<pre class="c">void CTFontDrawGlyphs(
CTFontRef font,
const CGGlyph glyphs[],
const CGPoint positions[],
size_t count,
CGContextRef context);</pre>
<p><strong>Required behavior:</strong></p>
<ul>
<li>Respect the current CGContext fill color (text color).</li>
<li>Respect the current CTM — positions are in user space, not device space.</li>
<li>Use FreeType to render each glyph into a temporary Cairo surface, then composite at the given position.</li>
<li>Respect <code>CGContextGetTextMatrix</code> (text matrix) for glyph orientation.</li>
<li>Handle sub-pixel antialiasing flags from the context's <code>CGContextSetShouldAntialias</code> / <code>CGContextSetShouldSmoothFonts</code>.</li>
</ul>
<p><strong>Action:</strong> Write a test program that calls <code>CTFontDrawGlyphs</code> via OpalText and inspects the output bitmap. If glyphs do not appear or appear mispositioned, audit <code>Source/OpalText/CTFont.m</code> for coordinate system errors (Cairo's Y axis is top-down; CoreGraphics is bottom-up — this flip is a common source of glyph inversion bugs).</p>
<!-- 5d -->
<h3>5d. <code>CTFontCreateForCharactersWithLanguageAndOption</code> <span class="phase-badge p5">Phase 5–6</span></h3>
<div class="gap">
<strong>Apple SPI. Missing from libs-opal.</strong> WebKit uses this to find a font that can render specific Unicode characters, with a language preference and fallback options. Used in <code>FontCascade::fontForCombiningCharacterSequence</code>.
</div>
<pre class="c">typedef uint32_t CTFontFallbackOption;
#define kCTFontFallbackOptionNone 0
#define kCTFontFallbackOptionSystem (1 << 0)
#define kCTFontFallbackOptionPreferCJK (1 << 1)
CTFontRef CTFontCreateForCharactersWithLanguageAndOption(
CTFontRef currentFont,
const UTF16Char *characters,
CFIndex length,
CFStringRef language, /* BCP-47 language tag, may be NULL */
CTFontFallbackOption option,
CFIndex *coveredLength /* out: how many chars the returned font covers */
);</pre>
<p><strong>Implementation:</strong> Build an <code>FcCharSet</code> from the Unicode code points in <code>characters[0..length-1]</code>. Call <code>FcFontSort</code> with <code>FC_CHARSET</code> matching. For each candidate from fontconfig, check if it covers all requested characters using <code>FcCharSetHasChar</code>. Return the first match as a <code>CTFontRef</code> with the same point size as <code>currentFont</code>. Set <code>*coveredLength</code> to the number of UTF-16 code units covered.</p>
<pre class="c">CTFontRef CTFontCreateForCharactersWithLanguageAndOption(
CTFontRef currentFont,
const UTF16Char *characters,
CFIndex length,
CFStringRef language,
CTFontFallbackOption option,
CFIndex *coveredLength)
{
FcConfig *config = FcConfigGetCurrent();
FcCharSet *cs = FcCharSetCreate();
/* Convert UTF-16 to codepoints and add to charset */
for (CFIndex i = 0; i < length; ) {
UTF32Char cp = opal_utf16_codepoint(characters, length, &i);
FcCharSetAddChar(cs, cp);
}
FcPattern *pat = FcPatternCreate();
FcPatternAddCharSet(pat, FC_CHARSET, cs);
if (language) {
char langBuf[64] = {0};
CFStringGetCString(language, langBuf, sizeof(langBuf),
kCFStringEncodingUTF8);
FcPatternAddString(pat, FC_LANG,
(const FcChar8 *)opal_bcp47_to_fc_lang(langBuf));
}
FcConfigSubstitute(config, pat, FcMatchPattern);
FcDefaultSubstitute(pat);
FcResult result;
FcPattern *match = FcFontMatch(config, pat, &result);
CTFontRef fallback = NULL;
if (match) {
fallback = opal_ct_font_from_fc_pattern(match,
CTFontGetSize(currentFont));
if (coveredLength) *coveredLength = length; /* optimistic */