Skip to content

Commit

Permalink
Add High Contrast image assets (#6915)
Browse files Browse the repository at this point in the history
This commit adds image assets for High Contrast mode

Tagging this issue so it contains a nice list of all the recent HC
fixes: #5360

I made several changes to DHowett's script and added it to the repo:
* Add support for generating high contrast icons
* Add the ability to easily edit the "intermediate" (previously "zbase")
  files for manual hinting
* Appease the spellchecker

I created new SVGs for HC mode. There's one SVG for both Black and White
modes -- I just invert the colors. Then I manually hinted the generated
bitmaps for the production icons. I didn't bother hinting the Dev/Pre
ones, so the text does get unreadable at small sizes.

View the original images in #6915.

Co-authored-by: Jeffrey Tippet <[email protected]>
Co-authored-by: Dustin L. Howett <[email protected]>
Closes #6822

(cherry picked from commit bd93cb5)
  • Loading branch information
jtippet authored and DHowett committed Jul 20, 2020
1 parent 91cfeb0 commit 20a6062
Show file tree
Hide file tree
Showing 414 changed files with 239 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .github/actions/spell-check/dictionary/microsoft.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
ACLs
altform
backplating
DACL
DACLs
LKG
Expand All @@ -8,7 +10,9 @@ microsoftonline
osgvsowi
powerrename
powershell
pscustomobject
SACLs
tdbuildteamid
vcruntime
visualstudio
wslpath
3 changes: 3 additions & 0 deletions .github/actions/spell-check/expect/expect.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1075,6 +1075,8 @@ INITCOMMONCONTROLSEX
INITDIALOG
initguid
INITMENU
imagemagick
inkscape
inl
INLINEPREFIX
Inlines
Expand Down Expand Up @@ -2252,6 +2254,7 @@ targetentrypoint
TARGETLIBS
TARGETNAME
targetnametoken
targetsize
targetver
taskbar
tbar
Expand Down
181 changes: 181 additions & 0 deletions res/terminal/Generate-TerminalAssets.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
#
# Generate-TerminalAssets.ps1
#
# Typical usage:
# .\Generate-TerminalAssets.ps1 -Path .\Terminal.svg -HighContrastPath .\Terminal_HC.svg -Destination .\images
# .\Generate-TerminalAssets.ps1 -Path .\Terminal_Pre.svg -HighContrastPath .\Terminal_Pre_HC.svg -Destination .\images-Pre
# .\Generate-TerminalAssets.ps1 -Path .\Terminal_Dev.svg -HighContrastPath .\Terminal_Dev_HC.svg -Destination .\images-Dev
#
# Some icons benefit from manual hints. The most efficient way to do that is to run the script twice:
#
# 1. Run .\Generate-TerminalAssets.ps1 ...args... -Destination .\images -KeepIntermediates
# 2. Manually hint the intermediate images under .\images\_intermediate*.png
# 3. Run .\Generate-TerminalAssets.ps1 ...args... -Destination .\images -UseExistingIntermediates
#
# Hinting the intermediate files minimizes the number of times you'll have to
# hint the same image. You may want to hint just the _intermediate.*.png and
# _intermediate.black.*.png files, and delete _intermediate.white.*.png. The
# script will then automatically derive _intermediate.white.*.png from
# _intermediate.black.*.png.
#

Param(
[Parameter(Mandatory=$true,ValueFromPipeline=$true)]
[string]$Path,
[string]$Destination,
[int[]]$Altforms = (16, 20, 24, 30, 32, 36, 40, 48, 60, 64, 72, 80, 96, 256),
[switch]$Unplated = $true,
[float[]]$Scales = (1.0, 1.25, 1.5, 2.0, 4.0),
[string]$HighContrastPath = "",
[switch]$UseExistingIntermediates = $false,
[switch]$KeepIntermediates = $false
)

$assetTypes = @(
[pscustomobject]@{Name="LargeTile"; W=310; H=310; IconSize=96}
[pscustomobject]@{Name="LockScreenLogo"; W=24; H=24; IconSize=24}
[pscustomobject]@{Name="SmallTile"; W=71; H=71; IconSize=36}
[pscustomobject]@{Name="SplashScreen"; W=620; H=300; IconSize=96}
[pscustomobject]@{Name="Square44x44Logo"; W=44; H=44; IconSize=32}
[pscustomobject]@{Name="Square150x150Logo"; W=150; H=150; IconSize=48}
[pscustomobject]@{Name="StoreLogo"; W=50; H=50; IconSize=36}
[pscustomobject]@{Name="Wide310x150Logo"; W=310; H=150; IconSize=48}
)

function CeilToEven ([int]$i) { if ($i % 2 -eq 0) { [int]($i) } else { [int]($i + 1) } }

$inflatedAssetSizes = $assetTypes | ForEach-Object {
$as = $_;
$scales | ForEach-Object {
[pscustomobject]@{
Name = $as.Name + ".scale-$($_*100)"
W = [math]::Round($as.W * $_, [System.MidpointRounding]::ToPositiveInfinity)
H = [math]::Round($as.H * $_, [System.MidpointRounding]::ToPositiveInfinity)
IconSize = CeilToEven ($as.IconSize * $_)
}
}
}

$allAssetSizes = $inflatedAssetSizes + ($Altforms | ForEach-Object {
[pscustomobject]@{
Name = "Square44x44Logo.targetsize-${_}"
W = [int]$_
H = [int]$_
IconSize = [int]$_
}
If ($Unplated) {
[pscustomobject]@{
Name = "Square44x44Logo.targetsize-${_}_altform-unplated"
W = [int]$_
H = [int]$_
IconSize = [int]$_
}
}
})

# Cross product with the 3 high contrast modes
$allAssetSizes = $allAssetSizes | ForEach-Object {
$asset = $_
("standard", "black", "white") | ForEach-Object {
$contrast = $_
$name = $asset.Name
If ($contrast -Ne "standard") {
If ($HighContrastPath -Eq "") {
# "standard" is the default, so we can omit it in filenames
return
}
$name += "_contrast-" + $contrast
}
[pscustomobject]@{
Name = $name
W = $asset.W
H = $asset.H
IconSize = $asset.IconSize
Contrast = $_
}
}
}

$allSizes = $allAssetSizes.IconSize | Group-Object | Select-Object -Expand Name

$TranslatedSVGPath = & wsl wslpath -u ((Get-Item $Path -ErrorAction:Stop).FullName -Replace "\\","/")
$TranslatedSVGContrastPath = $null
If ($HighContrastPath -Ne "") {
$TranslatedSVGContrastPath = & wsl wslpath -u ((Get-Item $HighContrastPath -ErrorAction:Stop).FullName -Replace "\\","/")
}
& wsl which inkscape | Out-Null
If ($LASTEXITCODE -Ne 0) { throw "Inkscape is not installed in WSL" }
& wsl which convert | Out-Null
If ($LASTEXITCODE -Ne 0) { throw "imagemagick is not installed in WSL" }

If (-Not [string]::IsNullOrEmpty($Destination)) {
New-Item -Type Directory $Destination -EA:Ignore
$TranslatedOutDir = & wsl wslpath -u ((Get-Item $Destination -EA:Stop).FullName -Replace "\\","/")
} Else {
$TranslatedOutDir = "."
}

$intermediateFiles = [System.Collections.Concurrent.ConcurrentBag[string]]::new()

# Generate the base icons
$allSizes | ForEach-Object -Parallel {
$sz = $_;

$destinationNt = $using:Destination
$destinationWsl = $using:TranslatedOutDir
$svgStandardWsl = $using:TranslatedSVGPath
$svgContrastWsl = $using:TranslatedSVGContrastPath

$intermediateStandardNt = "$destinationNt\_intermediate.standard.$($sz).png"
$intermediateStandardWsl = "$destinationWsl/_intermediate.standard.$($sz).png"

If (($using:UseExistingIntermediates -Eq $false) -Or (-Not (Test-Path $intermediateStandardNt))) {
wsl inkscape -z -e "$intermediateStandardWsl" -w $sz -h $sz $svgStandardWsl
} Else {
Write-Host "Using existing $intermediateStandardNt"
}

($using:intermediateFiles).Add($intermediateStandardNt)

If ($svgContrastWsl -Ne $null) {
$intermediateBlackNt = "$destinationNt\_intermediate.black.$($sz).png"
$intermediateWhiteNt = "$destinationNt\_intermediate.white.$($sz).png"
$intermediateBlackWsl = "$destinationWsl/_intermediate.black.$($sz).png"
$intermediateWhiteWsl = "$destinationWsl/_intermediate.white.$($sz).png"

If (($using:UseExistingIntermediates -Eq $false) -Or (-Not (Test-Path $intermediateBlackNt))) {
wsl inkscape -z -e "$intermediateBlackWsl" -w $sz -h $sz $svgContrastWsl
} Else {
Write-Host "Using existing $intermediateBlackNt"
}

If (($using:UseExistingIntermediates -Eq $false) -Or (-Not (Test-Path $intermediateWhiteNt))) {
# The HC white icon is just a negative image of the HC black one
wsl convert "$intermediateBlackWsl" -channel RGB -negate "$intermediateWhiteWsl"
} Else {
Write-Host "Using existing $intermediateWhiteNt"
}

($using:intermediateFiles).Add($intermediateBlackNt)
($using:intermediateFiles).Add($intermediateWhiteNt)
}
}

# Once the base icons are done, splat them into the middles of larger canvases.
$allAssetSizes | ForEach-Object -Parallel {
$asset = $_
If ($asset.W -Eq $asset.H -And $asset.IconSize -eq $asset.W) {
Write-Host "Copying base icon for size=$($asset.IconSize), contrast=$($asset.Contrast) to $($asset.Name)"
Copy-Item "${using:Destination}\_intermediate.$($asset.Contrast).$($asset.IconSize).png" "${using:Destination}\$($asset.Name).png" -Force
} Else {
wsl convert "$($using:TranslatedOutDir)/_intermediate.$($asset.Contrast).$($asset.IconSize).png" -gravity center -background transparent -extent "$($asset.W)x$($asset.H)" "$($using:TranslatedOutDir)/$($asset.Name).png"
}
}

If ($KeepIntermediates -Eq $false) {
$intermediateFiles | ForEach-Object {
Write-Host "Cleaning up intermediate file $_"
Remove-Item $_
}
}

17 changes: 17 additions & 0 deletions res/terminal/Terminal_Dev_HC.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 17 additions & 0 deletions res/terminal/Terminal_HC.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 17 additions & 0 deletions res/terminal/Terminal_Pre_HC.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 20a6062

Please sign in to comment.