Repository navigation
feat: ctxDrawSymbol and symbolSize, SF Symbols drawn in a surface in the fill colour - #71
Merged
Merged
Conversation
…the fill colour The system's icons by name, which createStatusItem's image and a menu item's iconName already take, can now be drawn into a surface for a renderer's own content, sidorares/react-x11#591. ctxDrawSymbol draws the symbol fitted into a rect, centred, in the current fill colour. The template's shape goes into a transparency layer and the colour through it, so a symbol follows the CTM, the clip, the global alpha and the blend mode as a glyph run does, over what is already drawn. It answers false, drawing nothing, for a name the catalogue does not know. symbolSize answers the symbol's size in points, or null. Both take pointSize, weight, scale and variableValue, and run on the calling thread in threaded mode, where they draw the same pixels. The CSS weight mapping matchFont used is shared as FontWeightFromCss. CI now runs test/text-features.js, which #70 added to the test script only, and the new test/symbols.js.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
For sidorares/react-x11#591: the system's icons by name, drawn into a surface for a renderer's own content.
createStatusItem'simageand a menu item'siconNamealready take an SF Symbol name; nothing that draws inside a window did, so an app whose tray icon iswaveformcould not showwaveformin its own UI.Rendered by this branch: the eight symbols the Hush port uses, at weights 300, 500 and 800 in three fill colours, and
speaker.wave.3.fillatvariableValue0, 0.34, 0.67 and 1.The verbs
native.ctxDrawSymbol(surface, name, x, y, width, height, options?)draws the symbol fitted into the rect, centred and keeping its proportions, in the current fill colour, and answerstrue; for a name the catalogue does not know it answersfalseand draws nothing. A symbol is a template, its shape in whatever colour it is drawn with, so it is drawn the wayctxDrawGlyphsdraws a run: the template goes into a transparency layer and the fill colour through it withSourceIn, and the layer composites once through the surface's CTM and clip, at its global alpha and blend mode, over what is already drawn.native.symbolSize(name, options?)answers{ width, height }in points, the symbol's designed padding included, ornullfor an unknown name.Both take
pointSize, default 13;weight, 100 to 900, mapped to AppKit's weights the waymatchFontmaps them, a mapping now shared asFontWeightFromCss;scale,'small','medium'or'large'; andvariableValue, 0 to 1, on macOS 13 and later. A name that is not a string is aTypeError.In threaded mode both run on the calling thread, like every other
ctx*verb and the font verbs: anNSImagedrawn into a bitmap context is not a view, so it does not need the UI thread that bezels do. The test checks that a worker draws the same pixels as the main thread.Tests
test/symbols.js, added to the test script and to CI:symbolSize: a size that grows with the point size and the weight;nullfor an unknown name; the options optionalctxDrawSymbol: opaque ink in the fill colour, inside its rect and centred in it; over a white background, the rest of the rect left white;falseand no ink for an unknown name; the colour following the fill colour; the global alpha applied once; the clip; more ink at a heavier weight; less of a variable symbol at a lower value; aTypeErrorfor a name that is not a stringMutation check, each change rebuilt and run alone, all 7 caught:
SourceInfill, so the template's blackvariableValueignoredTypeErrorfor a non-string nameTypeErrorchecktruefor an unknown nameCI also gains a step for
test/text-features.js, which #70 added to the test script but not to the workflow.npm teston this Mac: every test file passes.