googlefonts / noto-emoji

Noto Emoji fonts
SIL Open Font License 1.1
3.74k stars 451 forks source link

Create installer on Windows #392

Open Mistreaper opened 2 years ago

Mistreaper commented 2 years ago

It would be nice if there's a batch script to make Windows installation easier. I found a batch script in twemoji where it uses ttx and python to install its font.

https://github.com/eosrei/twemoji-color-font/blob/master/windows/install.cmd

SleepyCatten commented 1 year ago

I literally came here to ask for the same thing 🥺💟

The Twemoji color font project is likely to be stalled permanently at version 14 now, due to Elon Musk running Twitter into the ground.

Noto may be the only font that's continuing to be updated. If we could make it so that it can be installed as the primary emoji font in Windows 10/11, it will make a lot of people very happy.

https://github.com/13rac1/twemoji-color-font#install-on-windows https://github.com/13rac1/twemoji-color-font/releases/download/v14.0.2/TwitterColorEmoji-SVGinOT-Win-14.0.2.zip

mindplay-dk commented 1 year ago

The new Windows 11 emoji made me very sad - having this available on Windows would definitely make my day!

mindplay-dk commented 1 year ago

I spent half a day trying to write a powershell script to install the font.

Powershell is an absolute nightmare.

I've tried four or five different ways to (1) get the font family name, and (2) register the font.

Dumping the code here if anyone else wants to muck about with this. I left a couple of different approaches commented-out so you can see what didn't work.

Nothing I can find still works today on Windows 11.

Life is too short for this nonsense.

# Launch cmd.exe with right-click and "Run as Administrator"
#
# Then type in the following command to run this script:
#
#   PowerShell.exe -ExecutionPolicy Bypass -File install.ps1

### Remove Segoe UI Emoji font:

$fontsRegPath = "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts\"
$segoeFontName = "Segoe UI Emoji (TrueType)"

if (Get-ItemProperty -Path $fontsRegPath -Name $segoeFontName -ErrorAction SilentlyContinue) {
    Remove-ItemProperty -Path $fontsRegPath -Name $segoeFontName
    Write-Host "Registry value '$segoeFontName' has been deleted from '$fontsRegPath'."
} else {
    Write-Host "Registry value '$segoeFontName' does not exist in '$fontsRegPath'."
}

### Download the NotoColorEmoji font:

$notoFileName = "NotoColorEmoji_WindowsCompatible.ttf"

$url = "https://github.com/googlefonts/noto-emoji/raw/main/fonts/$notoFileName"

$tempPath = [System.IO.Path]::GetTempPath()

$fontFile = Join-Path -Path $tempPath -ChildPath $notoFileName

if (Test-Path -Path $fontFile) {
    Write-Host "File '$fontFile' already exists. Skipping download."
} else {
    try {
        Invoke-WebRequest -Uri $url -OutFile $fontFile

        Write-Host "File downloaded to system Temp Path: $fontFile."
    } catch {
        Write-Host "Error downloading the file: $_.Exception.Message"
        exit
    }
}

### Install the NotoColorEmoji font:

try {
    $typeFace = [Windows.Media.GlyphTypeface]::new($fontFile)

    $family = $typeFace.Win32FamilyNames['en-us']

    if ($null -eq $family) {
        $family = $typeFace.Win32FamilyNames.Values.Item(0)
    }

    $face = $typeFace.Win32FaceNames['en-us']

    if ($null -eq $face) {
        $face = $typeFace.Win32FaceNames.Values.Item(0)
    }

    $fontName = ("$family $face").Trim()

    $fontName = "$fontName (TrueType)"

    write-host "Installing font: $fontFile with font name '$fontName'"

    # If (!(Test-Path ("$($env:windir)\Fonts\" + $fontFile.Name))) {
    #     Write-Host "Copying font: $fontFile"
    #     Copy-Item -Path $fontFile.FullName -Destination ("$($env:windir)\Fonts\" + $fontFile.Name) -Force
    # } else {
    #     Write-Host "Font already exists: $fontFile"
    # }

    # If (!(Get-ItemProperty -Name $fontName -Path "HKLM:\Software\Microsoft\Windows NT\CurrentVersion\Fonts" -ErrorAction SilentlyContinue)) {
    #     Write-Host "Registering font: $fontFile"
    #     New-ItemProperty -Name $fontName -Path "HKLM:\Software\Microsoft\Windows NT\CurrentVersion\Fonts" -PropertyType string -Value $fontFile.Name -Force -ErrorAction SilentlyContinue | Out-Null
    # } else {
    #     Write-Host "Font already registered: $fontFile"
    # }
} catch {
    write-host "Error installing font: $fontFile. " $_.exception.message
}

# try {
#     # load the font:

    # $fontBytes = [System.IO.File]::ReadAllBytes($fontFile)

    # $fontCollection = New-Object System.Drawing.Text.InstalledFontCollection

    # $notoFamily = New-Object -TypeName System.Drawing.FontFamily -ArgumentList $fontBytes

    # $notoFamilyName = $notoFamily.Name

#     # check if aleady installed:

#     foreach ($fontFamily in $fontCollection.Families) {
#         if ($fontFamily.Name -eq $notoFamilyName) {
#             Write-Host "Font '$fontFamily' is already installed."
#             exit
#         }
#     }

#     # install:

#     [System.Drawing.Text.PrivateFontCollection]::AddMemoryFont([System.IO.MemoryStream]::new($fontBytes), $null)

#     Write-Host "Font installed successfully."
# } catch {
#     Write-Host "Error installing the font: $_.Exception.Message"
# }
mindplay-dk commented 1 year ago

For the record, I've been away from this for long enough to forget what the problem was.

Of course, just removing Segoe UI Emoji and installing this font doesn't solve anything - we need something like the script mentioned by OP to actually create a "fake" replacement Segoe UI Emoji font.

I would suggest this shouldn't run on the individual user's machine though - it has a ton of dependencies, and just getting it to run is probably more trouble than most people are willing to go through.

What we probably should do, is automate it as part of the build - so that the replacement font is generated and ready to download after each release. (then perhaps my installation script would be worth finishing, to help people install it.)

mindplay-dk commented 1 year ago

I'm too tired to fight this battle anymore for now, but here's an explanation of how to create a replacement font using Python:

https://github.com/perguto/Country-Flag-Emojis-for-Windows#how-i-did-it

Since this project already uses Python, I guess that would seem okay? Maybe we're not far off from at least having a font we can manually install...