@geastack/apple 0.2.15 → 0.2.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +6 -6
- package/targets/ios/generate-xcode-project.mjs +5 -0
- package/targets/macos/app-compiler-plugins.mjs +22 -0
- package/targets/macos/build-macos.sh +40 -2
- package/targets/macos/main/font_registry.h +2 -0
- package/targets/macos/main/font_registry.mm +72 -51
- package/targets/macos/main/macos_background_test.h +54 -0
- package/targets/macos/main/macos_control_admission.h +13 -0
- package/targets/macos/main/macos_key_event.h +73 -0
- package/targets/macos/main/macos_main.mm +100 -19
- package/targets/macos/main/macos_renderer.h +2 -0
- package/targets/macos/main/macos_renderer.mm +349 -46
- package/targets/macos/main/press_bridge.h +21 -3
- package/targets/macos/main/press_bridge.mm +126 -26
- package/targets/macos/sync-resources.mjs +24 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@geastack/apple",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.16",
|
|
4
4
|
"description": "Generated Apple SDK bindings plus the macOS and iOS native build targets for Gea apps.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -111,14 +111,14 @@
|
|
|
111
111
|
"access": "public"
|
|
112
112
|
},
|
|
113
113
|
"dependencies": {
|
|
114
|
-
"@geastack/compiler": "^1.0.
|
|
115
|
-
"@geastack/core": "^0.1.
|
|
114
|
+
"@geastack/compiler": "^1.0.34",
|
|
115
|
+
"@geastack/core": "^0.1.44",
|
|
116
116
|
"@geastack/elements": "^0.1.6",
|
|
117
|
-
"@geastack/engine": "^0.1.
|
|
117
|
+
"@geastack/engine": "^0.1.18",
|
|
118
118
|
"@geastack/geaos": "^0.1.3",
|
|
119
119
|
"@geastack/geatsc-plugin-apple-native": "^0.1.4",
|
|
120
|
-
"@geastack/geatsc-plugin-gea": "^0.1.
|
|
121
|
-
"@geastack/host": "^0.1.
|
|
120
|
+
"@geastack/geatsc-plugin-gea": "^0.1.24",
|
|
121
|
+
"@geastack/host": "^0.1.18"
|
|
122
122
|
},
|
|
123
123
|
"scripts": {
|
|
124
124
|
"prepublishOnly": "npm run build",
|
|
@@ -299,6 +299,10 @@ const includePaths = [
|
|
|
299
299
|
...(process.env.GEA_FW_INCLUDE_DIRS || '').split('\n').filter(Boolean),
|
|
300
300
|
]
|
|
301
301
|
|
|
302
|
+
// OTHER_LDFLAGS -no_deduplicate: ld64 folds functions with identical code by
|
|
303
|
+
// default, address-taken ones included, and the runtime tells callables apart
|
|
304
|
+
// by entry address (CallableObject::callWithReceiver finds a method's receiver
|
|
305
|
+
// check by it), so a folded method template ran its twin's check.
|
|
302
306
|
function buildSettings(configuration) {
|
|
303
307
|
const preprocessorDefinitions = [
|
|
304
308
|
'GEA_EMBEDDED_GIF_C_API=1',
|
|
@@ -331,6 +335,7 @@ function buildSettings(configuration) {
|
|
|
331
335
|
IPHONEOS_DEPLOYMENT_TARGET = 16.0;
|
|
332
336
|
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
|
|
333
337
|
ONLY_ACTIVE_ARCH = ${configuration === 'Debug' ? 'YES' : 'NO'};
|
|
338
|
+
OTHER_LDFLAGS = ("$(inherited)", "-Wl,-no_deduplicate");
|
|
334
339
|
PRODUCT_BUNDLE_IDENTIFIER = ${q(bundleId)};
|
|
335
340
|
PRODUCT_NAME = ${q(appName)};
|
|
336
341
|
SDKROOT = iphoneos;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import fs from 'node:fs'
|
|
2
|
+
import path from 'node:path'
|
|
3
|
+
import {createHash} from 'node:crypto'
|
|
4
|
+
import {fileURLToPath} from 'node:url'
|
|
5
|
+
|
|
6
|
+
// Consume the actual CLI apps-inspect record, not a second app registry.
|
|
7
|
+
export function appCompilerPlugins(app) {
|
|
8
|
+
if(!app||typeof app.root!=='string'||!path.isAbsolute(app.root))throw Error('Missing absolute app root for compiler plugins')
|
|
9
|
+
const entries=app.compilerPlugins??[]
|
|
10
|
+
if(!Array.isArray(entries))throw Error('Invalid app compilerPlugins')
|
|
11
|
+
const paths=[]
|
|
12
|
+
for(const entry of entries){
|
|
13
|
+
if(typeof entry!=='string'||!entry||/[\x00-\x1f\x7f]/.test(entry)||path.isAbsolute(entry)||entry.split(/[\\/]/).includes('..'))throw Error('Invalid declared app compiler plugin')
|
|
14
|
+
const file=fs.realpathSync(path.resolve(app.root,entry))
|
|
15
|
+
if(!fs.statSync(file).isFile())throw Error('Declared app compiler plugin is not a file: '+file)
|
|
16
|
+
if(!paths.includes(file))paths.push(file)
|
|
17
|
+
}
|
|
18
|
+
const hash=createHash('sha256').update('gea-app-compiler-plugins-v1\0')
|
|
19
|
+
for(const file of paths)hash.update(file).update('\0').update(fs.readFileSync(file)).update('\0')
|
|
20
|
+
return {paths,fingerprint:hash.digest('hex')}
|
|
21
|
+
}
|
|
22
|
+
if(process.argv[1]&&path.resolve(process.argv[1])===fileURLToPath(import.meta.url))process.stdout.write(JSON.stringify(appCompilerPlugins(JSON.parse(process.argv[2]))))
|
|
@@ -571,6 +571,19 @@ generate_app() {
|
|
|
571
571
|
elif [[ -f "$appDir/geatsc-plugin.mjs" ]]; then
|
|
572
572
|
extraArgs+=(--extra-geatsc-plugin "$appDir/geatsc-plugin.mjs")
|
|
573
573
|
fi
|
|
574
|
+
# Explicit app-owned host mappings are separate from dependency plugins.
|
|
575
|
+
# Resolve the same validated CLI record used by nativeSources below.
|
|
576
|
+
local declaredAppMetadata declaredAppPlugins declaredPluginPath
|
|
577
|
+
declaredAppMetadata="$(node "$GEA_CLI" apps inspect "$id" --json)" || return 1
|
|
578
|
+
declaredAppPlugins="$(node "$ROOT_DIR/targets/macos/app-compiler-plugins.mjs" "$declaredAppMetadata")" || return 1
|
|
579
|
+
while IFS= read -r declaredPluginPath; do
|
|
580
|
+
[[ -n "$declaredPluginPath" ]] || continue
|
|
581
|
+
local alreadySelected=0 selectedArgument
|
|
582
|
+
for selectedArgument in ${extraArgs[@]+"${extraArgs[@]}"}; do
|
|
583
|
+
if [[ "$selectedArgument" == "$declaredPluginPath" ]] || { [[ -f "$selectedArgument" ]] && [[ "$selectedArgument" -ef "$declaredPluginPath" ]]; }; then alreadySelected=1; fi
|
|
584
|
+
done
|
|
585
|
+
(( alreadySelected != 0 )) || extraArgs+=(--extra-geatsc-plugin "$declaredPluginPath")
|
|
586
|
+
done < <(node -e 'for(const p of JSON.parse(process.argv[1]).paths)console.log(p)' "$declaredAppPlugins")
|
|
574
587
|
if [[ "$appRuntime" == "apple-native" ]]; then
|
|
575
588
|
extraArgs+=(--apple-native)
|
|
576
589
|
fi
|
|
@@ -580,7 +593,8 @@ generate_app() {
|
|
|
580
593
|
local envSignature="GEA_BUILD_CONFIG=$(cat "$buildConfig")
|
|
581
594
|
GEA_WEBGL_AUTO_INSTANCE=${GEA_WEBGL_AUTO_INSTANCE:-}
|
|
582
595
|
GEA_WEBGL_AUTO_INSTANCE_TEST=${GEA_WEBGL_AUTO_INSTANCE_TEST:-}
|
|
583
|
-
GEA_COMPILER_FINGERPRINT=${compilerFingerprint}
|
|
596
|
+
GEA_COMPILER_FINGERPRINT=${compilerFingerprint}
|
|
597
|
+
GEA_APP_PLUGIN_FINGERPRINT=$(node -e 'process.stdout.write(JSON.parse(process.argv[1]).fingerprint)' "$declaredAppPlugins")"
|
|
584
598
|
|
|
585
599
|
# Only when an alternate compiler was named, so the default signature -- and
|
|
586
600
|
# therefore every existing generated directory's freshness -- is unchanged.
|
|
@@ -961,7 +975,7 @@ case "${GEA_MACOS_THERMALRIGHT_PRODUCT_ID:-}" in
|
|
|
961
975
|
;;
|
|
962
976
|
esac
|
|
963
977
|
if [[ "$THERMALRIGHT_DISPLAY_TARGET" == "0" ]]; then
|
|
964
|
-
CXX_DEFINES+=(-DGEA_EMBEDDED_PIXEL_FORMAT=1) # RGBA8888 for AppKit
|
|
978
|
+
CXX_DEFINES+=(-DGEA_EMBEDDED_PIXEL_FORMAT=1 -DGEA_CSS_FONT_STRETCH=1) # RGBA8888 and native variable-font style for AppKit
|
|
965
979
|
fi
|
|
966
980
|
if [[ "$THERMALRIGHT_DISPLAY_TARGET" == "1" ]]; then
|
|
967
981
|
THERMALRIGHT_WIDTH="${GEA_MACOS_THERMALRIGHT_WIDTH:-$THERMALRIGHT_DEFAULT_WIDTH}"
|
|
@@ -1069,6 +1083,12 @@ MM_SOURCES=(
|
|
|
1069
1083
|
"$ROOT_DIR/targets/macos/main/macos_host_device_control.mm"
|
|
1070
1084
|
"$ROOT_DIR/targets/macos/main/macos_network.mm"
|
|
1071
1085
|
)
|
|
1086
|
+
# Fail rather than silently linking weak transport fallbacks from an older core.
|
|
1087
|
+
FRAMEWORK_OBJCXX_SOURCES="$(gea_fw_objcxx_sources)" || exit 1
|
|
1088
|
+
[[ -n "$FRAMEWORK_OBJCXX_SOURCES" ]] || { echo "Missing framework Apple transport sources" >&2; exit 1; }
|
|
1089
|
+
while IFS= read -r framework_mm; do
|
|
1090
|
+
[[ -n "$framework_mm" ]] && MM_SOURCES+=("$framework_mm")
|
|
1091
|
+
done <<< "$FRAMEWORK_OBJCXX_SOURCES"
|
|
1072
1092
|
|
|
1073
1093
|
if [[ "${GEA_NATIVE_DEBUGGER:-0}" == "1" ]]; then
|
|
1074
1094
|
MM_SOURCES+=("$GEA_DEBUGGER_NATIVE_SOURCE")
|
|
@@ -1945,6 +1965,16 @@ if [[ "$APPLE_NATIVE" == "1" ]]; then
|
|
|
1945
1965
|
)
|
|
1946
1966
|
fi
|
|
1947
1967
|
|
|
1968
|
+
# App-owned archive/framework inputs come only from the validated CLI record.
|
|
1969
|
+
APP_LINK_JSON="$(node "$GEA_CLI" apps inspect "$APP_ID" --json)"
|
|
1970
|
+
APP_LINK_RECORD="$(node -e 'const a=JSON.parse(process.argv[1]);const c=a.nativeLink?.macos;if(!c)throw Error("CLI lacks validated macos nativeLink");process.stdout.write(JSON.stringify(c))' "$APP_LINK_JSON")"
|
|
1971
|
+
APP_NATIVE_LIBRARIES=()
|
|
1972
|
+
while IFS= read -r library; do [[ -z "$library" ]] || APP_NATIVE_LIBRARIES+=("$library"); done < <(node -e 'for(const p of JSON.parse(process.argv[1]).nativeLibraries)console.log(p)' "$APP_LINK_RECORD")
|
|
1973
|
+
while IFS= read -r framework; do [[ -z "$framework" ]] || LINK_FRAMEWORKS+=(-framework "$framework"); done < <(node -e 'for(const p of JSON.parse(process.argv[1]).frameworks)console.log(p)' "$APP_LINK_RECORD")
|
|
1974
|
+
|
|
1975
|
+
node "$GEA_CLI" apps sync-native-resources "$APP_ID" --target macos --output "$RES_DIR" > "$BUILD_DIR/native-resources.json"
|
|
1976
|
+
if [[ "$(node -e 'process.stdout.write(String(JSON.parse(require("fs").readFileSync(process.argv[1],"utf8")).changed))' "$BUILD_DIR/native-resources.json")" == "true" ]]; then BUNDLE_CONTENT_CHANGED=1; fi
|
|
1977
|
+
|
|
1948
1978
|
LINK_OUTPUT="$MACOS_DIR/$APP_EXEC"
|
|
1949
1979
|
LINK_OUTPUT_TMP="$LINK_OUTPUT.tmp.$$"
|
|
1950
1980
|
LINK_SIGNATURE_FILE="$BUILD_DIR/link.sig"
|
|
@@ -1953,8 +1983,10 @@ LINK_SIGNATURE_TMP="$LINK_SIGNATURE_FILE.tmp.$$"
|
|
|
1953
1983
|
printf 'compiler=%s\n' "$MACOS_COMPILER_VERSION"
|
|
1954
1984
|
printf 'opt=%s\n' "$GEA_MACOS_OPT_LEVEL"
|
|
1955
1985
|
printf 'debug=%s\n' "${GEA_MACOS_DEBUG_INFO:-}"
|
|
1986
|
+
printf 'link=%s\n' -Wl,-no_deduplicate
|
|
1956
1987
|
printf 'framework=%s\n' "${LINK_FRAMEWORKS[@]}"
|
|
1957
1988
|
printf 'object=%s\n' "${OBJ_FILES[@]}"
|
|
1989
|
+
for library in ${APP_NATIVE_LIBRARIES[@]+"${APP_NATIVE_LIBRARIES[@]}"}; do shasum -a 256 "$library"; done
|
|
1958
1990
|
} > "$LINK_SIGNATURE_TMP"
|
|
1959
1991
|
|
|
1960
1992
|
LINK_NEEDED=0
|
|
@@ -1973,9 +2005,15 @@ if (( LINK_NEEDED != 0 )); then
|
|
|
1973
2005
|
# Preserve the last complete executable until the linker succeeds. Clear both
|
|
1974
2006
|
# completion markers first so a killed link is retried and re-signed.
|
|
1975
2007
|
rm -f "$LINK_SIGNATURE_FILE" "$BUILD_DIR/codesign.complete" "$LINK_OUTPUT_TMP"
|
|
2008
|
+
# -no_deduplicate: ld64 folds functions with identical code by default,
|
|
2009
|
+
# address-taken ones included, and the runtime tells callables apart by
|
|
2010
|
+
# entry address (CallableObject::callWithReceiver finds a method's receiver
|
|
2011
|
+
# check by it), so a folded method template ran its twin's check.
|
|
1976
2012
|
macos_run_tracked_child clang++ -std=c++20 -ObjC++ -fobjc-arc "$GEA_MACOS_OPT_LEVEL" ${GEA_MACOS_DEBUG_INFO} \
|
|
2013
|
+
-Wl,-no_deduplicate \
|
|
1977
2014
|
"${LINK_FRAMEWORKS[@]}" \
|
|
1978
2015
|
"${OBJ_FILES[@]}" \
|
|
2016
|
+
${APP_NATIVE_LIBRARIES[@]+"${APP_NATIVE_LIBRARIES[@]}"} \
|
|
1979
2017
|
-o "$LINK_OUTPUT_TMP"
|
|
1980
2018
|
mv "$LINK_OUTPUT_TMP" "$LINK_OUTPUT"
|
|
1981
2019
|
mv "$LINK_SIGNATURE_TMP" "$LINK_SIGNATURE_FILE"
|
|
@@ -16,6 +16,8 @@ namespace gea::macos {
|
|
|
16
16
|
// to assign stable ids the first time each family is seen. Unknown ids fall
|
|
17
17
|
// back to the system font.
|
|
18
18
|
NSFont *fontForId(int fontId, int sizePx);
|
|
19
|
+
// Stretch uses percentage tenths (1000 = 100%). The tuple is part of font identity.
|
|
20
|
+
NSFont *fontForId(int fontId, int sizePx, int weight, int stretch);
|
|
19
21
|
|
|
20
22
|
// Walks `directoryPath` for .ttf / .otf files and registers each with
|
|
21
23
|
// CTFontManager in the process scope. Returns the count of newly registered
|
|
@@ -128,66 +128,64 @@ const std::uint8_t *runtimeTtfBytesForFamilyId(int familyId, unsigned long *leng
|
|
|
128
128
|
return it->second.data();
|
|
129
129
|
}
|
|
130
130
|
|
|
131
|
-
static NSFont *self_resolveFont(int fontId,
|
|
132
|
-
|
|
133
|
-
NSFont *fontForId(int fontId, int sizePx)
|
|
134
|
-
{
|
|
135
|
-
CGFloat size = sizePx > 0 ? static_cast<CGFloat>(sizePx) : [NSFont systemFontSize];
|
|
136
|
-
|
|
137
|
-
// Cache resolved fonts by (fontId, size). `+[NSFont fontWithName:size:]` and
|
|
138
|
-
// the CTFontDescriptor fallback below both do a CoreText font-descriptor
|
|
139
|
-
// match, which is expensive — and this is called for EVERY text node on
|
|
140
|
-
// EVERY frame (renderer sync + layout measurement). Without this cache,
|
|
141
|
-
// CoreText font matching dominated the profile and pegged a CPU core. The
|
|
142
|
-
// set of (family, size) pairs an app uses is tiny, so the cache stays small.
|
|
143
|
-
static NSMutableDictionary<NSNumber *, NSFont *> *cache;
|
|
144
|
-
static dispatch_once_t once;
|
|
145
|
-
dispatch_once(&once, ^{ cache = [NSMutableDictionary dictionary]; });
|
|
146
|
-
NSNumber *key = @(static_cast<long long>(fontId) * 100000LL + llround(size));
|
|
147
|
-
@synchronized(cache) {
|
|
148
|
-
NSFont *hit = cache[key];
|
|
149
|
-
if (hit) return hit;
|
|
150
|
-
}
|
|
151
|
-
NSFont *resolved = self_resolveFont(fontId, size);
|
|
152
|
-
if (resolved) {
|
|
153
|
-
@synchronized(cache) { cache[key] = resolved; }
|
|
154
|
-
}
|
|
155
|
-
return resolved;
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
static NSFont *self_resolveFont(int fontId, CGFloat size)
|
|
131
|
+
static NSFont *self_resolveFont(int fontId, int sizePx, int weight, int stretch)
|
|
159
132
|
{
|
|
160
133
|
NSString *family = familyForId(fontId);
|
|
134
|
+
const CGFloat size = std::clamp(sizePx > 0 ? sizePx : 13, 1, 4096);
|
|
161
135
|
if (!family || family.length == 0) return [NSFont systemFontOfSize:size];
|
|
162
|
-
// CSS system-font keywords map to the actual system UI font — San Francisco
|
|
163
|
-
// on macOS. There is no PostScript face literally named "-apple-system", so
|
|
164
|
-
// `+[NSFont fontWithName:@"-apple-system"]` returns nil and we'd otherwise
|
|
165
|
-
// fall through to a wrong family. systemFontOfSize: IS San Francisco.
|
|
166
136
|
NSString *lower = family.lowercaseString;
|
|
167
137
|
if ([lower isEqualToString:@"-apple-system"] || [lower isEqualToString:@"system-ui"] ||
|
|
168
138
|
[lower isEqualToString:@"blinkmacsystemfont"] || [lower hasPrefix:@".applesystemuifont"] ||
|
|
169
139
|
[lower hasPrefix:@".sf"] || [lower isEqualToString:@"san francisco"] ||
|
|
170
140
|
[lower isEqualToString:@"sf pro"] || [lower isEqualToString:@"sf pro text"]) {
|
|
171
|
-
|
|
141
|
+
const CGFloat nativeWeight = weight <= 400 ? (weight - 400) / 1000.0 : (weight - 400) / 800.0;
|
|
142
|
+
return [NSFont systemFontOfSize:size weight:nativeWeight];
|
|
172
143
|
}
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
144
|
+
NSDictionary *baseAttributes = @{ (__bridge NSString *)kCTFontFamilyNameAttribute: family };
|
|
145
|
+
CTFontDescriptorRef descriptor = CTFontDescriptorCreateWithAttributes((__bridge CFDictionaryRef)baseAttributes);
|
|
146
|
+
CTFontRef base = CTFontCreateWithFontDescriptor(descriptor, size, nullptr);
|
|
147
|
+
CFRelease(descriptor);
|
|
148
|
+
if (!base) return [NSFont systemFontOfSize:size];
|
|
149
|
+
NSMutableDictionary *variation = [NSMutableDictionary dictionary];
|
|
150
|
+
CFArrayRef axes = CTFontCopyVariationAxes(base);
|
|
151
|
+
if (axes) {
|
|
152
|
+
for (NSDictionary *axis in (__bridge NSArray *)axes) {
|
|
153
|
+
NSNumber *identifier = axis[(__bridge NSString *)kCTFontVariationAxisIdentifierKey];
|
|
154
|
+
const uint32_t tag = identifier.unsignedIntValue;
|
|
155
|
+
if (tag != 0x77676874 && tag != 0x77647468) continue; // wght / wdth
|
|
156
|
+
const double requested = tag == 0x77676874 ? weight : stretch / 10.0;
|
|
157
|
+
const double minimum = [axis[(__bridge NSString *)kCTFontVariationAxisMinimumValueKey] doubleValue];
|
|
158
|
+
const double maximum = [axis[(__bridge NSString *)kCTFontVariationAxisMaximumValueKey] doubleValue];
|
|
159
|
+
variation[identifier] = @(std::clamp(requested, minimum, maximum));
|
|
160
|
+
}
|
|
161
|
+
CFRelease(axes);
|
|
187
162
|
}
|
|
188
|
-
|
|
163
|
+
NSMutableDictionary *attributes = [NSMutableDictionary dictionary];
|
|
164
|
+
if (variation.count) attributes[(__bridge NSString *)kCTFontVariationAttribute] = variation;
|
|
165
|
+
else attributes[(__bridge NSString *)kCTFontTraitsAttribute] = @{
|
|
166
|
+
(__bridge NSString *)kCTFontWeightTrait: @((weight - 400) / 800.0)
|
|
167
|
+
};
|
|
168
|
+
CTFontDescriptorRef adjustment = CTFontDescriptorCreateWithAttributes((__bridge CFDictionaryRef)attributes);
|
|
169
|
+
CTFontRef selected = CTFontCreateCopyWithAttributes(base, size, nullptr, adjustment);
|
|
170
|
+
CFRelease(adjustment); CFRelease(base);
|
|
171
|
+
return selected ? (__bridge_transfer NSFont *)selected : [NSFont systemFontOfSize:size];
|
|
189
172
|
}
|
|
190
173
|
|
|
174
|
+
NSFont *fontForId(int fontId, int sizePx, int weight, int stretch)
|
|
175
|
+
{
|
|
176
|
+
weight = std::clamp(weight, 1, 1000);
|
|
177
|
+
stretch = std::clamp(stretch, 1, 32767);
|
|
178
|
+
sizePx = std::clamp(sizePx > 0 ? sizePx : 13, 1, 4096);
|
|
179
|
+
static NSMutableDictionary<NSString *, NSFont *> *cache = [NSMutableDictionary dictionary];
|
|
180
|
+
NSString *key = [NSString stringWithFormat:@"%d:%d:%d:%d", fontId, sizePx, weight, stretch];
|
|
181
|
+
@synchronized(cache) { NSFont *hit = cache[key]; if (hit) return hit; }
|
|
182
|
+
NSFont *selected = self_resolveFont(fontId, sizePx, weight, stretch);
|
|
183
|
+
if (selected) { @synchronized(cache) { if (cache.count >= 1024) [cache removeAllObjects]; cache[key] = selected; } }
|
|
184
|
+
return selected;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
NSFont *fontForId(int fontId, int sizePx) { return fontForId(fontId, sizePx, 400, 1000); }
|
|
188
|
+
|
|
191
189
|
int registerCustomTtfDirectory(NSString *directoryPath)
|
|
192
190
|
{
|
|
193
191
|
NSFileManager *fm = [NSFileManager defaultManager];
|
|
@@ -274,10 +272,10 @@ NSLineBreakMode lineBreakModeForText(NSString *text, NSFont *font, CGFloat maxWi
|
|
|
274
272
|
// Host text-measurement hook for the AppKit renderer. The Thermalright target
|
|
275
273
|
// has no AppKit text renderer; it wants the framework's generated-font metrics.
|
|
276
274
|
#if !GEA_MACOS_THERMALRIGHT_DISPLAY_TARGET
|
|
277
|
-
|
|
275
|
+
static bool measureNativeText(const char *text,
|
|
278
276
|
int maxWidth,
|
|
279
277
|
int fontId,
|
|
280
|
-
int fontSize,
|
|
278
|
+
int fontSize, int fontWeight, int fontStretch, int lineHeight,
|
|
281
279
|
int *outWidth,
|
|
282
280
|
int *outHeight)
|
|
283
281
|
{
|
|
@@ -304,6 +302,9 @@ extern "C" bool gea_host_measure_text(const char *text,
|
|
|
304
302
|
key.append(std::to_string(fontId));
|
|
305
303
|
key.push_back('\x1f');
|
|
306
304
|
key.append(std::to_string(fontSize));
|
|
305
|
+
key.push_back('\x1f'); key.append(std::to_string(fontWeight));
|
|
306
|
+
key.push_back('\x1f'); key.append(std::to_string(fontStretch));
|
|
307
|
+
key.push_back('\x1f'); key.append(std::to_string(lineHeight));
|
|
307
308
|
{
|
|
308
309
|
std::scoped_lock guard(measureLock);
|
|
309
310
|
auto it = measureCache.find(key);
|
|
@@ -314,12 +315,13 @@ extern "C" bool gea_host_measure_text(const char *text,
|
|
|
314
315
|
}
|
|
315
316
|
}
|
|
316
317
|
|
|
317
|
-
NSFont *font = gea::macos::fontForId(fontId, fontSize);
|
|
318
|
+
NSFont *font = gea::macos::fontForId(fontId, fontSize, fontWeight, fontStretch);
|
|
318
319
|
if (!font) return false;
|
|
319
320
|
NSString *str = [NSString stringWithUTF8String:text] ?: @"";
|
|
320
321
|
const CGFloat boundedMax = maxWidth > 0 ? maxWidth : CGFLOAT_MAX;
|
|
321
322
|
NSMutableParagraphStyle *paragraph = [[NSMutableParagraphStyle alloc] init];
|
|
322
323
|
paragraph.lineBreakMode = gea::macos::lineBreakModeForText(str, font, boundedMax);
|
|
324
|
+
if (lineHeight > 0) { paragraph.minimumLineHeight = lineHeight; paragraph.maximumLineHeight = lineHeight; }
|
|
323
325
|
NSDictionary *attrs = @{
|
|
324
326
|
NSFontAttributeName: font,
|
|
325
327
|
NSParagraphStyleAttributeName: paragraph,
|
|
@@ -347,4 +349,23 @@ extern "C" bool gea_host_measure_text(const char *text,
|
|
|
347
349
|
}
|
|
348
350
|
return true;
|
|
349
351
|
}
|
|
352
|
+
// Readiness must reject CoreText's successful system fallback for a missing face.
|
|
353
|
+
extern "C" bool gea_host_packaged_font_available(int familyId)
|
|
354
|
+
{
|
|
355
|
+
unsigned long length = 0;
|
|
356
|
+
if (!gea::macos::runtimeTtfBytesForFamilyId(familyId, &length) || !length) return false;
|
|
357
|
+
NSString *requested = gea::macos::familyForId(familyId);
|
|
358
|
+
NSFont *selected = gea::macos::fontForId(familyId, 14, 400, 1000);
|
|
359
|
+
if (!requested || !selected || ![selected.familyName isEqualToString:requested]) return false;
|
|
360
|
+
const UniChar characters[] = {'A', 0x00b5};
|
|
361
|
+
CGGlyph glyphs[2] = {};
|
|
362
|
+
return CTFontGetGlyphsForCharacters((__bridge CTFontRef)selected, characters, glyphs, 2)
|
|
363
|
+
&& glyphs[0] != 0 && glyphs[1] != 0;
|
|
364
|
+
}
|
|
365
|
+
extern "C" bool gea_host_measure_text(const char *text, int maxWidth, int fontId, int fontSize, int *width, int *height)
|
|
366
|
+
{ return measureNativeText(text, maxWidth, fontId, fontSize, 400, 1000, 0, width, height); }
|
|
367
|
+
extern "C" bool gea_host_measure_text_with_style(const char *text, int maxWidth, int fontId, int fontSize, int weight, int lineHeight, int *width, int *height)
|
|
368
|
+
{ return measureNativeText(text, maxWidth, fontId, fontSize, weight, 1000, lineHeight, width, height); }
|
|
369
|
+
extern "C" bool gea_host_measure_text_with_variations(const char *text, int maxWidth, int fontId, int fontSize, int weight, int stretch, int lineHeight, int *width, int *height)
|
|
370
|
+
{ return measureNativeText(text, maxWidth, fontId, fontSize, weight, stretch, lineHeight, width, height); }
|
|
350
371
|
#endif
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#import <AppKit/AppKit.h>
|
|
4
|
+
#include <cstdio>
|
|
5
|
+
#include <cstdlib>
|
|
6
|
+
#include <cstring>
|
|
7
|
+
|
|
8
|
+
// Hidden-window test mode. Ordinary user launches keep normal AppKit
|
|
9
|
+
// presentation. Tests can instantiate the real application without ordering a
|
|
10
|
+
// window, becoming active, or opening Gea audio. This is not a WebView path.
|
|
11
|
+
namespace gea::macos::background_test {
|
|
12
|
+
[[noreturn]] inline void refuse(const char* reason) {
|
|
13
|
+
std::fprintf(stderr, "Gea background UI test refused: %s\n", reason);
|
|
14
|
+
std::fflush(stderr);
|
|
15
|
+
std::_Exit(78);
|
|
16
|
+
}
|
|
17
|
+
inline bool enabled() {
|
|
18
|
+
static const bool value = [] {
|
|
19
|
+
const char* flag = std::getenv("GEA_MACOS_BACKGROUND_TEST");
|
|
20
|
+
if (!flag) return false;
|
|
21
|
+
if (std::strcmp(flag, "1") != 0)
|
|
22
|
+
refuse("GEA_MACOS_BACKGROUND_TEST must be absent or exactly 1");
|
|
23
|
+
return true;
|
|
24
|
+
}();
|
|
25
|
+
return value;
|
|
26
|
+
}
|
|
27
|
+
inline void checkApplication(NSApplication* app) {
|
|
28
|
+
if (!enabled()) return;
|
|
29
|
+
if (!app || app.activationPolicy != NSApplicationActivationPolicyProhibited || app.active)
|
|
30
|
+
refuse("application must stay prohibited and inactive");
|
|
31
|
+
for (NSWindow* window in app.windows) {
|
|
32
|
+
if (window.visible || window.keyWindow || window.mainWindow)
|
|
33
|
+
refuse("all owned windows must stay hidden, nonkey and nonmain");
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
inline void configure(NSApplication* app) {
|
|
37
|
+
if (!enabled()) return;
|
|
38
|
+
const char* audio = std::getenv("GEA_AUDIO_DISABLED");
|
|
39
|
+
if (!audio || std::strcmp(audio, "1") != 0)
|
|
40
|
+
refuse("GEA_AUDIO_DISABLED=1 is required before application startup");
|
|
41
|
+
[app setActivationPolicy:NSApplicationActivationPolicyProhibited];
|
|
42
|
+
checkApplication(app);
|
|
43
|
+
}
|
|
44
|
+
inline void present(NSWindow* window) {
|
|
45
|
+
if (enabled()) {
|
|
46
|
+
checkApplication(NSApp);
|
|
47
|
+
if (!window || window.visible || window.keyWindow || window.mainWindow)
|
|
48
|
+
refuse("window presentation is forbidden");
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
[window makeKeyAndOrderFront:nil];
|
|
52
|
+
[NSApp activateIgnoringOtherApps:YES];
|
|
53
|
+
}
|
|
54
|
+
} // namespace gea::macos::background_test
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
#include "native_identity.h"
|
|
3
|
+
#include "ui/selector.h"
|
|
4
|
+
#include "ui/tree_internal.h"
|
|
5
|
+
namespace gea::macos {
|
|
6
|
+
// Native callbacks keep their original allocation lease. Disabled state is
|
|
7
|
+
// resolved from the live Tree at the mutation boundary, not cached NSControl
|
|
8
|
+
// appearance; cancellation still uses allocation-only admission.
|
|
9
|
+
inline bool controlAdmitted(int node, const gea::framework::identity::Owner &owner) {
|
|
10
|
+
return gea::framework::identity::current(node, owner) &&
|
|
11
|
+
!gea::embedded::ui::selector::disabled(gea::embedded::ui::Tree::instance(), node);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
#import <AppKit/AppKit.h>
|
|
3
|
+
#include "events.h"
|
|
4
|
+
|
|
5
|
+
// NSEvent.keyCode is a physical AppKit scan code, not a legacy keyCode.
|
|
6
|
+
// `key` follows the current layout; `code` names the physical position.
|
|
7
|
+
static const char *geaPhysicalKeyCode(unsigned short code) {
|
|
8
|
+
switch(code) {
|
|
9
|
+
case 0:return "KeyA";case 1:return "KeyS";case 2:return "KeyD";case 3:return "KeyF";
|
|
10
|
+
case 4:return "KeyH";case 5:return "KeyG";case 6:return "KeyZ";case 7:return "KeyX";
|
|
11
|
+
case 8:return "KeyC";case 9:return "KeyV";case 11:return "KeyB";case 12:return "KeyQ";
|
|
12
|
+
case 13:return "KeyW";case 14:return "KeyE";case 15:return "KeyR";case 16:return "KeyY";
|
|
13
|
+
case 17:return "KeyT";case 18:return "Digit1";case 19:return "Digit2";case 20:return "Digit3";
|
|
14
|
+
case 21:return "Digit4";case 22:return "Digit6";case 23:return "Digit5";case 24:return "Equal";
|
|
15
|
+
case 25:return "Digit9";case 26:return "Digit7";case 27:return "Minus";case 28:return "Digit8";
|
|
16
|
+
case 29:return "Digit0";case 30:return "BracketRight";case 31:return "KeyO";case 32:return "KeyU";
|
|
17
|
+
case 33:return "BracketLeft";case 34:return "KeyI";case 35:return "KeyP";case 36:return "Enter";
|
|
18
|
+
case 37:return "KeyL";case 38:return "KeyJ";case 39:return "Quote";case 40:return "KeyK";
|
|
19
|
+
case 41:return "Semicolon";case 42:return "Backslash";case 43:return "Comma";case 44:return "Slash";
|
|
20
|
+
case 45:return "KeyN";case 46:return "KeyM";case 47:return "Period";case 48:return "Tab";
|
|
21
|
+
case 49:return "Space";case 50:return "Backquote";case 51:return "Backspace";case 53:return "Escape";
|
|
22
|
+
case 54:return "MetaRight";case 55:return "MetaLeft";case 56:return "ShiftLeft";case 57:return "CapsLock";
|
|
23
|
+
case 58:return "AltLeft";case 59:return "ControlLeft";case 60:return "ShiftRight";
|
|
24
|
+
case 61:return "AltRight";case 62:return "ControlRight";case 63:return "Fn";
|
|
25
|
+
case 65:return "NumpadDecimal";case 67:return "NumpadMultiply";case 69:return "NumpadAdd";
|
|
26
|
+
case 71:return "NumLock";case 75:return "NumpadDivide";case 76:return "NumpadEnter";
|
|
27
|
+
case 78:return "NumpadSubtract";case 81:return "NumpadEqual";case 82:return "Numpad0";
|
|
28
|
+
case 83:return "Numpad1";case 84:return "Numpad2";case 85:return "Numpad3";case 86:return "Numpad4";
|
|
29
|
+
case 87:return "Numpad5";case 88:return "Numpad6";case 89:return "Numpad7";case 91:return "Numpad8";
|
|
30
|
+
case 92:return "Numpad9";case 96:return "F5";case 97:return "F6";case 98:return "F7";
|
|
31
|
+
case 99:return "F3";case 100:return "F8";case 101:return "F9";case 103:return "F11";
|
|
32
|
+
case 109:return "F10";case 111:return "F12";case 115:return "Home";case 116:return "PageUp";
|
|
33
|
+
case 117:return "Delete";case 118:return "F4";case 119:return "End";case 120:return "F2";
|
|
34
|
+
case 121:return "PageDown";case 122:return "F1";case 123:return "ArrowLeft";
|
|
35
|
+
case 124:return "ArrowRight";case 125:return "ArrowDown";case 126:return "ArrowUp";
|
|
36
|
+
default:return "Unidentified";
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
static gea::framework::events::PointerEvent geaNativeKey(NSEvent *native, bool composing, bool up) {
|
|
40
|
+
gea::framework::events::PointerEvent event;
|
|
41
|
+
event.type=up?gea::framework::events::PointerEventType::KeyUp:gea::framework::events::PointerEventType::KeyDown;
|
|
42
|
+
event.code=geaPhysicalKeyCode(native.keyCode);
|
|
43
|
+
NSString *characters=(native.modifierFlags & (NSEventModifierFlagCommand|NSEventModifierFlagControl))?
|
|
44
|
+
native.charactersIgnoringModifiers:native.characters;
|
|
45
|
+
event.key=characters.UTF8String?:"";
|
|
46
|
+
switch(native.keyCode) {
|
|
47
|
+
case 36:case 76:event.key="Enter";event.keyCode=13;break;
|
|
48
|
+
case 48:event.key="Tab";event.keyCode=9;break;
|
|
49
|
+
case 49:event.key=" ";event.keyCode=32;break;
|
|
50
|
+
case 51:event.key="Backspace";event.keyCode=8;break;
|
|
51
|
+
case 53:event.key="Escape";event.keyCode=27;break;
|
|
52
|
+
case 115:event.key="Home";event.keyCode=36;break;
|
|
53
|
+
case 116:event.key="PageUp";event.keyCode=33;break;
|
|
54
|
+
case 117:event.key="Delete";event.keyCode=46;break;
|
|
55
|
+
case 119:event.key="End";event.keyCode=35;break;
|
|
56
|
+
case 121:event.key="PageDown";event.keyCode=34;break;
|
|
57
|
+
case 123:event.key="ArrowLeft";event.keyCode=37;break;
|
|
58
|
+
case 124:event.key="ArrowRight";event.keyCode=39;break;
|
|
59
|
+
case 125:event.key="ArrowDown";event.keyCode=40;break;
|
|
60
|
+
case 126:event.key="ArrowUp";event.keyCode=38;break;
|
|
61
|
+
default: {
|
|
62
|
+
NSString *upper=[native.charactersIgnoringModifiers uppercaseString];
|
|
63
|
+
if(upper.length==1)event.keyCode=[upper characterAtIndex:0];
|
|
64
|
+
break;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
event.altKey=(native.modifierFlags & NSEventModifierFlagOption)!=0;
|
|
68
|
+
event.ctrlKey=(native.modifierFlags & NSEventModifierFlagControl)!=0;
|
|
69
|
+
event.metaKey=(native.modifierFlags & NSEventModifierFlagCommand)!=0;
|
|
70
|
+
event.shiftKey=(native.modifierFlags & NSEventModifierFlagShift)!=0;
|
|
71
|
+
event.repeat=native.isARepeat;event.isComposing=composing;
|
|
72
|
+
return event;
|
|
73
|
+
}
|