Skip to content

Commit

Permalink
Change image2c output for Flutter 3.10 deprecations
Browse files Browse the repository at this point in the history
  • Loading branch information
Electric Bolt committed May 11, 2023
1 parent 2a14eaa commit 485975e
Show file tree
Hide file tree
Showing 8 changed files with 220 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@
developmentRegion = English;
hasScannedForEncodings = 0;
knownRegions = (
English,
en,
);
mainGroup = 745C046B1DBA04CA0035C216;
Expand All @@ -205,7 +206,7 @@
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "SRC_DIR=\"$SRCROOT/BinUtilsTestLibrary\"\n\nif [ -e \"$SRC_DIR/CustomViewBin.h\" ]; then\n echo Checking xib and h timestamps\n\n XIB_TIMESTAMP=`stat -f \"%m\" $SRC_DIR/CustomView.xib`\n H_TIMESTAMP=`stat -f \"%m\" $SRC_DIR/CustomViewBin.h`\n\n if [ $XIB_TIMESTAMP -le $H_TIMESTAMP ]; then\n echo \"xib file unchanged\";\n exit 0;\n fi\nfi\n\necho \"Compiling $SRC_DIR xib to nib\"\n\nibtool --errors --warnings --notices --module BinUtilsTestLibrary --auto-activate-custom-fonts --target-device iphone --minimum-deployment-target 7.0 --output-format human-readable-text --compile $SRC_DIR/CustomView.nib $SRC_DIR/CustomView.xib\n\necho \"Generating source file\"\n$SRCROOT/../bin/bin2c -h $SRC_DIR/CustomView.nib >$SRC_DIR/CustomViewBin.h\n$SRCROOT/../bin/bin2c $SRC_DIR/CustomView.nib >$SRC_DIR/CustomViewBin.m\n\nrm $SRC_DIR/CustomView.nib";
shellScript = "SRC_DIR=\"$SRCROOT/BinUtilsTestLibrary\"\n\nif [ -e \"$SRC_DIR/CustomViewBin.h\" ]; then\n echo Checking xib and h timestamps\n\n XIB_TIMESTAMP=`stat -f \"%m\" $SRC_DIR/CustomView.xib`\n H_TIMESTAMP=`stat -f \"%m\" $SRC_DIR/CustomViewBin.h`\n\n if [ $XIB_TIMESTAMP -le $H_TIMESTAMP ]; then\n echo \"xib file unchanged\";\n exit 0;\n fi\nfi\n\necho \"Compiling $SRC_DIR xib to nib\"\n\nibtool --errors --warnings --notices --module BinUtilsTestLibrary --auto-activate-custom-fonts --target-device iphone --minimum-deployment-target 7.0 --output-format human-readable-text --compile $SRC_DIR/CustomView.nib $SRC_DIR/CustomView.xib\n\necho \"Generating source file\"\n$SRCROOT/../bin/bin2c -h $SRC_DIR/CustomView.nib >$SRC_DIR/CustomViewBin.h\n$SRCROOT/../bin/bin2c $SRC_DIR/CustomView.nib >$SRC_DIR/CustomViewBin.m\n\nrm $SRC_DIR/CustomView.nib\n";
};
745C04C11DBA141A0035C216 /* ShellScript */ = {
isa = PBXShellScriptBuildPhase;
Expand Down
Binary file modified bin/bin2c
Binary file not shown.
Binary file modified bin/image2c
Binary file not shown.
78 changes: 78 additions & 0 deletions bin2c/bin2c.xcodeproj/xcshareddata/xcschemes/bin2c.xcscheme
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1300"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "745A06D51D73A56500DAA6FC"
BuildableName = "bin2c"
BlueprintName = "bin2c"
ReferencedContainer = "container:bin2c.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
</Testables>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "745A06D51D73A56500DAA6FC"
BuildableName = "bin2c"
BlueprintName = "bin2c"
ReferencedContainer = "container:bin2c.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "745A06D51D73A56500DAA6FC"
BuildableName = "bin2c"
BlueprintName = "bin2c"
ReferencedContainer = "container:bin2c.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>
4 changes: 2 additions & 2 deletions bin2c/bin2c/main.m
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// binutils. Copyright © 2016-2022 Electric Bolt Limited. See LICENSE file
// binutils. Copyright © 2016-2023 Electric Bolt Limited. See LICENSE file

@import Foundation;

static void haltSyntax() {
fprintf(stderr, "bin2c Version 1.1.2; Copyright © 2016-2022 Electric Bolt Limited\n");
fprintf(stderr, "bin2c Version 1.2.0; Copyright © 2016-2023 Electric Bolt Limited\n");
fprintf(stderr, "Syntax: bin2c [-h|-dart] input-file-1 [input-file-2] ... [input-file-n]\n");
fprintf(stderr, " -h = output .h file\n");
fprintf(stderr, " -dart = output .dart file\n");
Expand Down
8 changes: 8 additions & 0 deletions binutils.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>
112 changes: 112 additions & 0 deletions image2c/image2c.xcodeproj/xcshareddata/xcschemes/image2c.xcscheme
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1300"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "741C3BF81D7CDCB80017C153"
BuildableName = "image2c"
BlueprintName = "image2c"
ReferencedContainer = "container:image2c.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
</Testables>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "741C3BF81D7CDCB80017C153"
BuildableName = "image2c"
BlueprintName = "image2c"
ReferencedContainer = "container:image2c.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
<CommandLineArguments>
<CommandLineArgument
argument = "-dart "
isEnabled = "YES">
</CommandLineArgument>
<CommandLineArgument
argument = "-h"
isEnabled = "NO">
</CommandLineArgument>
<CommandLineArgument
argument = "Images"
isEnabled = "YES">
</CommandLineArgument>
<CommandLineArgument
argument = "dartfigurate/ui/images/rawimages.dart"
isEnabled = "YES">
</CommandLineArgument>
<CommandLineArgument
argument = "/Users/shared/build/appfigurate/dartfigurate/lib/ui/images/source/noappicon.png"
isEnabled = "NO">
</CommandLineArgument>
<CommandLineArgument
argument = "/Users/shared/build/appfigurate/dartfigurate/lib/ui/images/source/[email protected]"
isEnabled = "YES">
</CommandLineArgument>
<CommandLineArgument
argument = "/Users/shared/build/appfigurate/dartfigurate/lib/ui/images/source/[email protected]"
isEnabled = "YES">
</CommandLineArgument>
<CommandLineArgument
argument = "/Users/shared/build/appfigurate/dartfigurate/lib/ui/images/source/[email protected]"
isEnabled = "YES">
</CommandLineArgument>
</CommandLineArguments>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "741C3BF81D7CDCB80017C153"
BuildableName = "image2c"
BlueprintName = "image2c"
ReferencedContainer = "container:image2c.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>
22 changes: 18 additions & 4 deletions image2c/image2c/main.m
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// binutils. Copyright © 2016-2022 Electric Bolt Limited. See LICENSE file
// binutils. Copyright © 2016-2023 Electric Bolt Limited. See LICENSE file

@import Foundation;

static void haltSyntax() {
fprintf(stderr, "image2c Version 1.1.2; Copyright © 2016-2022 Electric Bolt Limited\n");
fprintf(stderr, "image2c Version 1.2.0; Copyright © 2016-2023 Electric Bolt Limited\n");
fprintf(stderr, "Syntax: image2c [-h|-dart] category-name header-file input-file-1 [input-file-2] ... [input-file-n]\n");
fprintf(stderr, " -h = output .h file\n");
fprintf(stderr, " -dart = output .dart file\n");
Expand Down Expand Up @@ -45,6 +45,8 @@ int main(int argc, const char * argv[]) {

// Combine all scales (@1x,@2x,@3x) of identically named images together.
NSMutableDictionary* distinctImageNames = [NSMutableDictionary new];
BOOL _1x = NO;
BOOL _2x = NO;
for (int i = inputFileIndex; i < argc; i++) {
NSString* inputFile = [NSString stringWithCString: argv[i] encoding: NSUTF8StringEncoding];
NSString* f = inputFile.lastPathComponent;
Expand All @@ -70,6 +72,11 @@ int main(int argc, const char * argv[]) {
[distinctImageNames setObject: scales forKey: f];
}
[scales addObject: [NSNumber numberWithInt: scale]];
if (scale == 1) {
_1x = YES;
} else if (scale == 2) {
_2x = YES;
}
}

printf("// Auto-generated with image2c. Do not change.\n\n");
Expand All @@ -89,6 +96,9 @@ int main(int argc, const char * argv[]) {
[sb appendFormat: @"import 'package:%@';\n", headerFile];
[sb appendString: @"import 'package:flutter/cupertino.dart';\n\n"];
[sb appendFormat: @"class %@ {\n", categoryName];
[sb appendString: @"\tstatic double _devicePixelRatio = WidgetsBinding.instance.platformDispatcher.implicitView!.devicePixelRatio;\n"];
[sb appendString: @"\tstatic bool _1x = (_devicePixelRatio - 1.0).abs() < 0.01;\n"];
[sb appendString: @"\tstatic bool _2x = (_devicePixelRatio - 2.0).abs() < 0.01;\n"];
printf("%s", [sb UTF8String]);
} else {
NSMutableString* sb = [NSMutableString new];
Expand Down Expand Up @@ -120,15 +130,19 @@ int main(int argc, const char * argv[]) {
NSMutableString* sb = [NSMutableString new];
[sb appendFormat: @"\tstatic Image %@({double? width, double? height}) {\n", f];
if ([scales count] > 1)
[sb appendString: @"\t\tvar data = MediaQueryData.fromWindow(WidgetsBinding.instance.window);\n\t\t"];
[sb appendString: @"\t\t"];
for (int i = 0; i < [scales count]; i++) {
NSString* s = [f uppercaseString];
int scale = [[scales objectAtIndex: i] intValue];
if (scale != 1)
s = [s stringByAppendingFormat: @"_%ldX", (long) scale];
s = [s stringByAppendingString: @"_PNG"];
if (i < [scales count] - 1) {
[sb appendFormat: @"if ((data.devicePixelRatio - %ld.0).abs() < 0.01) {\n", (long) scale];
if (scale == 1) {
[sb appendString: @"if (_1x) {\n"];
} else if (scale == 2) {
[sb appendString: @"if (_2x) {\n"];
}
[sb appendFormat: @"\t\t\treturn Image.memory(%@, scale: %ld.0, width: width, height: height);\n", s, (long) scale];
[sb appendString: @"\t\t} else "];
} else {
Expand Down

0 comments on commit 485975e

Please sign in to comment.