Skip to content

Latest commit

 

History

History
372 lines (361 loc) · 52.3 KB

CoreGraphics.md

File metadata and controls

372 lines (361 loc) · 52.3 KB

CoreGraphics

Symbols: 61.4% of Apple's iOS API (664 of 1082, exact) · Rows: 43: 36 ✅ 3 🟡 4 ❌ · iOS: 2.0+

Area: Graphics & text · Apple: CoreGraphics · Issues: area:graphics

How isim implements it

  • Adapted: isim's own C implementation (isim/frameworks/CoreGraphics) over the host's cairo. isim parses PDFs itself (CGPDFParser.c: the object model, cross-reference tables and streams, filters, the standard security handler) and renders their pages with poppler-glib.

API

API / feature Status iOS Notes
Geometry (CGRect/CGPoint/CGSize functions, Swift helpers) ✅ ≤17 CGFloat is a typealias of Double
CGAffineTransform ✅ ≤17
CGContext paths: rects, ellipses, arcs, lines, curves; fill, EO fill, stroke ✅ ≤17 via host cairo; even-odd fill tested (HelloDrawing)
Graphics state, CTM (translate/scale/rotate/concat), alpha, line width/cap/join/miter limit ✅ ≤17 caps/joins/miter limit unverified
Clipping (clip, clip(using: .evenOdd), clip(to: rect)) ✅ ≤17 even-odd clip unverified
CGPath / CGMutablePath (build, bounding box, contains, apply) ✅ ≤17 adapted; tested (HelloQuartz, CGPathTest)
CGMutablePath.addArc(tangent1End:tangent2End:radius:transform:), CGPathAddArcToPoint ✅ ≤17 adapted: a line to the first tangent point and a circular arc built from Bézier quarters; tested (CGPathTest)
CGPath.copy(strokingWithWidth:lineCap:lineJoin:miterLimit:transform:), CGPathCreateCopyByStrokingPath ✅ ≤17 adapted: isim's own outliner (bands per segment, miter / round / bevel joins with the miter limit, butt / round / square caps, then a winding union), so the outline is one non-overlapping filled shape; curves are flattened first and the transform maps the outline; tested (CGPathTest, HelloQuartz)
CGPath.copy(dashingWithPhase:lengths:transform:), CGPathCreateCopyByDashingPath ✅ ≤17 adapted: dashes along the flattened path (lengths before the transform), closed subpaths include their closing segment; tested (CGPathTest, HelloQuartz)
CGPath.copy(using:), mutableCopy(using:), CGPathCreateCopyByTransformingPath, CGPathCreateMutableCopyByTransformingPath ✅ ≤17 adapted; tested (CGPathTest, HelloQuartz)
CGPath.isRect(_:), CGPathIsRect ✅ ≤17 adapted: an axis-aligned rectangle (from CGPath(rect:) or four lines and a close); tested (CGPathTest)
CGPath.union, intersection, subtracting, symmetricDifference, normalized(using:), lineIntersection, lineSubtracting, componentsSeparated(using:), flattened(threshold:), intersects(_:using:) and their C functions ✅ 16 adapted: isim's own polygon clipper over flattened outlines (edges split at crossings, kept by the winding or even-odd rule), so results are made of lines; tested (CGPathTest, HelloQuartz)
CGColor (RGB, gray, copy with alpha, components in their space, converted(to:)) ✅ ≤17 gray colors keep 2 components; tested (HelloQuartz)
CGColorSpace (sRGB, Display P3, linear, gray, CMYK, pattern) ✅ ≤17 adapted: named spaces preserve their name/model/base/extended-range properties; colors convert to sRGB for drawing (exact Display P3 matrix, linear transfer, gray and CMYK; out-of-gamut clamped, no wide-color output); tested (HelloQuartz)
CGColorSpaceCreateWithICCData, CGColorSpaceCopyICCData (CGColorSpace(iccData:), copyICCData()) 🟡 ≤17 adapted: isim reads the profile itself (no lcms2): its header and tag table; RGB matrix / TRC profiles (rXYZ / gXYZ / bXYZ, curv gamma or table, para functions 0–4) and gray kTRC profiles convert exactly to sRGB (Bradford D50 → D65); CGImages in the space are converted pixel by pixel; tested (CGExtrasTest, profiles it builds). Missing: LUT-based profiles (A2B0) draw as their device space, rendering intents are ignored
CGColorSpaceCreateLab, kCGColorSpaceGenericLab ✅ ≤17 adapted: Lab → XYZ at the white point → D65 (von Kries) → sRGB, a and b clamped to the range; 8-bit images map L to 0…100 and a / b over the range; tested (CGExtrasTest, HelloQuartz)
CGColorSpaceCreateIndexed, CGColorSpaceGetColorTableCount, CGColorSpaceGetColorTable (colorTable), CGColorSpaceCopyBaseColorSpace ✅ ≤17 adapted: colors and 8-bit images through the table and the base space (indices past the end take the last color); tested (CGExtrasTest, HelloQuartz)
CGColorSpaceCreateExtended, CreateLinearized, CreateExtendedLinearized, CreateCopyWithStandardRange; kCGColorSpaceLinearDisplayP3, kCGColorSpaceExtendedDisplayP3, kCGColorSpaceExtendedRange ✅ ≤17 adapted: named spaces map to their named variants (sRGB, gray, Display P3); ICC and Lab spaces get extended-range copies and have no linear form; tested (CGExtrasTest, HelloQuartz)
CGDataProviderCreateDirect, CGDataProviderCreateSequential (CGDataProviderDirectCallbacks, CGDataProviderSequentialCallbacks) ✅ ≤17 adapted: the bytes are read through the callbacks when the provider is created (byte pointer, bytes at positions, or sequentially after a rewind) and kept in memory; releaseInfo runs when the provider is freed; tested (CGExtrasTest)
CGLayer (CGLayerCreateWithContext, size, context, CGContextDrawLayerInRect / AtPoint) ✅ ≤17 adapted: a premultiplied RGBA bitmap at the context's device scale, drawn back as an image; tested (CGExtrasTest, HelloQuartz)
CGContextDrawConicGradient (drawConicGradient(_:center:angle:)) ✅ 17.0 adapted: 720 wedges around the center, counterclockwise from the angle, filling the clip; tested (CGExtrasTest, HelloQuartz)
Pattern colors (CGPattern, setFillPattern) ✅ ≤17 adapted: colored and uncolored fill/stroke patterns; uncolored components use the pattern space's RGB/gray/CMYK base; cell drawn once at 2x and tiled relative to the current CTM, with phase and alpha; tested (HelloQuartz)
CGImage (from UIImage, crop, draw into context) ✅ ≤17 decoded by the host
CGImage from raw bytes (CGDataProvider, CGImageCreate, CGImageMaskCreate, masking, dataProvider) ✅ ≤17 8 bits per component (RGB(A/X) in any order, gray, gray+alpha, alpha only, masks, decode arrays); 16-bit/float layouts are refused with a log; decoded images report premultiplied RGBA bytes; tested (HelloQuartz)
CGBitmapContext (CGContext(data:...), pixel read/write, makeImage) ✅ ≤17 draws into app memory (zero-copy for BGRA/A8, converted in/out for RGBA and gray), y-up like iOS; UIGraphicsPushContext makes UIKit draw into it; drawable from any thread (each thread has its own drawing target, as on iOS); tested (HelloQuartz, including drawing on a background thread while frames render)
CGGradient, CGShading (CGFunction) ✅ ≤17 linear/radial with before/after extension; shadings sampled at 64 steps; tested (HelloQuartz). One-sided radial extension approximated
Line dashes (setLineDash) ✅ ≤17 tested (HelloDrawing)
Shadows (setShadow) ✅ ≤17 adapted: operations draw as a group; alpha is blurred with a 3-pass box blur and offset in base space. Vector/PDF groups rasterize only the shadow mask, keeping the source operation vector; tested on bitmap/UIKit and PDF contexts (HelloQuartz)
Blend modes, transparency layers ✅ ≤17 blend modes map to cairo operators (plusDarker approximated); layers composite with the outer alpha/shadow; multiply and layer tested (HelloQuartz)
Clip to mask (clip(to:mask:)) ✅ ≤17 alpha of masks with alpha, luminance of opaque masks; tested (HelloQuartz)
Text drawing in CG (Core Text lines/frames, text matrix/position) ✅ ≤17 glyphs drawn y-up through the text matrix (upside down in UIKit's flipped space, as on iOS); CGContextShowTextAtPoint (deprecated) unverified; text drawing modes other than fill/invisible draw as fill
CGContext queries (ctm, boundingBoxOfClipPath, path, isPathEmpty, conversions) ✅ ≤17 adapted through cairo; replacePathWithStrokedPath makes a flattened outline (exact segment width/caps, conservative round approximation for bevel/miter joins); tested (HelloQuartz)
PDF contexts (CGContext(consumer:mediaBox:), beginPDFPage, closePDF) ✅ ≤17 cairo PDF surface, y-up pages; tested (HelloQuartz)
CGPDFDocument / CGPDFPage (read, drawPDFPage) ✅ ≤17 adapted: isim's parser reads the objects (classic and cross-reference-stream files, object streams, incremental updates, a damaged xref rebuilt by scanning) and poppler-glib renders. Like Apple's, drawPDFPage draws the page without its
annotations (PDFKit draws them; poppler's print path still draws form fields). Version, catalog, info, file identifier, page dictionaries, the five boxes with inheritance and defaults, rotation, getDrawingTransform, outline (CGPDFDocumentGetOutline: titles, page destinations, DestinationRect, named destinations); tested (CGPDFTest, HelloQuartz)
Encrypted PDFs (isEncrypted, isUnlocked, unlockWithPassword, allowsPrinting, allowsCopying, accessPermissions) ✅ ≤17 adapted: the standard security handler, RC4 40–128 bit (R2–R3), AES-128 (R4, crypt filters) and AES-256 (R5/R6), user and owner passwords; an empty user password unlocks by itself; the owner password allows everything; poppler renders with the password that unlocked it; tested (CGPDFTest)
CGPDFObject, CGPDFDictionary, CGPDFArray, CGPDFString, CGPDFStream ✅ ≤17 adapted: values resolved through references; ApplyFunction / ApplyBlock; text strings in PDFDocEncoding, UTF-16BE and UTF-8; CopyDate with time zones; CGPDFStreamCopyData decodes Flate, LZW, ASCIIHex, ASCII85 and RunLength (with PNG/TIFF predictors) and hands JPEG / JPEG 2000 back encoded with their format; tested (CGPDFTest)
CGPDFScanner, CGPDFContentStream, CGPDFOperatorTable ✅ ≤17 adapted: content streams of a page (one or an array, inherited resources) or of a form stream with a parent; operators call their callbacks with the operands on the stack; inline images reach BI as a stream; CGPDFScannerStop; tested (CGPDFTest, HelloQuartz)
PDF context links, destinations, outline, info (setURL(_:for:), addDestination(_:at:), setDestination(_:for:), CGPDFContextSetOutline, kCGPDFContextTitle… keys) 🟡 ≤17 adapted through cairo's PDF tags and outline; title, author, subject, keywords and creator written; tested (CGPDFTest, HelloQuartz). Missing: addDocumentMetadata is a stub (no XMP), and the encryption, PDF/A, PDF/X and output-intent keys are accepted but not written
CGFont 🟡 ≤17 adapted subset: creation by name or an OpenType data provider; PostScript/full names and units/em (provider metadata parsed with HarfBuzz); CGFontCopyTableTags / CGFontCopyTableForTag (tableTags, table(for:)): a font by name through the host's HarfBuzz face, a font from data from its sfnt table directory (the first font of a collection); tested (HelloQuartz, CGExtrasTest). Missing: glyph advances / bounds and PostScript subsets
Types not yet in isim (iOS 17 and earlier) ❌ ≤17 not implemented, found by the 2026-10 sweep: CGBitmapLayout, CGColorBufferFormat, CGColorConversionInfo, CGColorConversionInfoTransformType, CGColorDataFormat, CGColorModel, CGComponent, CGContentInfo, CGError, CGGlyphDeprecatedEnum, CGImageComponentInfo, CGPDFStructureElement, CGPDFTagProperty, CGPDFTagType, CGRenderingBufferProvider, ColorSyncProfile, IOSurfaceRef (17 types; with their members under "Not yet in isim")
Types not yet in isim (iOS 18) ❌ 18.0 not implemented, found by the 2026-10 sweep: CGToneMapping (1 type; with its members under "Not yet in isim")
Types not yet in isim (iOS 26) ❌ 26.0 not implemented, found by the 2026-10 sweep: CGBitmapParameters, CGContentToneMappingInfo (2 types; with their members under "Not yet in isim")
Types not yet in isim (iOS 27) ❌ 27.0 not implemented, found by the 2026-10 sweep: CGPDFMarkedContentItem (1 type; with its members under "Not yet in isim")

Not yet in isim

418 symbols Apple documents for iOS that isim does not have (exact; Apple snapshot 2026-10-14). Each links to Apple's documentation.

List