1. sayfa (Toplam 1 sayfa)

DPI Scale-Text Scale Ve Font Yönetimi

Gönderilme zamanı: 06 May 2026, 15:21
gönderen TRWE_2012
Merhabalar

Az sonra tarafımdan oluşturulmuş/düzenmiş konu anlatımına geçmeden önce, bu konu aşağıda linkleri verilen sordumNET makalelerinin tamamını kapsayan bir anlatım olduğunu vurgulamak isterim.Yani ben, "Büyük Resmi" ele aldım.

https://www.sordum.net/46552/dpi-olcekl ... istirelim/
https://www.sordum.net/39309/windows-10 ... egistirme/
https://www.sordum.net/22319/windows-10 ... nt-sorunu/
https://www.sordum.net/70717/windows-ta ... istirilir/
https://www.sordum.net/6820/windowsta-m ... istirilir/
https://www.sordum.net/47058/windows-10 ... k-yapalim/
https://www.sordum.net/45592/windows-10 ... istirelim/

İyi okumalar....


TRWE_2012
Alaydan Yetişme PC Kullanıcısı



Resim
BETİK İÇERİKLERİ

Betik-1 : Systems Fonts Manager v2.0.ps1

Kod: Tümünü seç

# =============================================================================
# Manage-SystemFonts.ps1  (v2)
# Displays and edits all active Windows UI fonts, sizes and styles.
# Covers: CaptionFont, SmCaptionFont, IconFont, MenuFont, MessageFont,
#         StatusFont (WindowMetrics LOGFONT) and FontSubstitutes (name-only).
# Based on WinPaletter categories: Titlebar / Icons / Menus /
#         Miscellaneous / Fonts substitutes
#
# Bug fixes vs v1:
#   - Weight=0 (unset LOGFONT) now shows "--" instead of "0"
#   - Empty font name (unset LOGFONT) now shows "(not set)" instead of blank
#   - Header now shows real active DPI via GDI + Accessibility Text Scale
#   - Italic field added: read, display, edit
#   - Edit-Entry shows numbered font list with search filter
# =============================================================================

Add-Type -AssemblyName System.Drawing

Add-Type @"
using System;
using System.Runtime.InteropServices;
public class GDIHelper {
    [DllImport("gdi32.dll")]  public static extern int    GetDeviceCaps(IntPtr hdc, int nIndex);
    [DllImport("user32.dll")] public static extern IntPtr GetDC(IntPtr hWnd);
    [DllImport("user32.dll")] public static extern int    ReleaseDC(IntPtr hWnd, IntPtr hDC);
}
"@

# --- CONSTANTS ---------------------------------------------------------------
$WM_PATH   = "HKCU:\Control Panel\Desktop\WindowMetrics"
$FS_PATH   = "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\FontSubstitutes"
$DPI_PATH  = "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\FontDPI"
$ACC_PATH  = "HKCU:\SOFTWARE\Microsoft\Accessibility"
$LOGPIXELSX = 88

# --- LOGFONT HELPERS ---------------------------------------------------------
function Read-LogFont {
    param([byte[]]$Bytes, [int]$DPI = 96)
    if ($null -eq $Bytes -or $Bytes.Length -lt 92) {
        return @{ Name="(not set)"; PointSize=0; Weight=0; Italic=0; Height=0 }
    }
    $h   = [BitConverter]::ToInt32($Bytes, 0)
    $w   = [BitConverter]::ToInt32($Bytes, 16)
    $it  = $Bytes[20]
    $nm  = [System.Text.Encoding]::Unicode.GetString($Bytes, 28, 64).TrimEnd([char]0)
    if ([string]::IsNullOrWhiteSpace($nm)) { $nm = "(not set)" }
    $pt  = if ($h -lt 0) { [Math]::Round([Math]::Abs($h) * 72 / $DPI) } else { $h }
    return @{ Name=$nm; PointSize=[int]$pt; Weight=$w; Italic=$it; Height=$h }
}

function Build-LogFont {
    param(
        [string]$FaceName,
        [int]   $PointSize,
        [int]   $DPI     = 96,
        [int]   $Weight  = 400,
        [byte]  $Italic  = 0,
        [byte]  $CharSet = 1,
        [byte]  $Quality = 5
    )
    $bytes = New-Object byte[] 92
    $lfH   = [int32](-[Math]::Round($PointSize * $DPI / 72))
    [Array]::Copy([BitConverter]::GetBytes($lfH),            0, $bytes,  0, 4)
    [Array]::Copy([BitConverter]::GetBytes([int32]$Weight),  0, $bytes, 16, 4)
    $bytes[20] = $Italic
    $bytes[23] = $CharSet
    $bytes[26] = $Quality
    $nb = [System.Text.Encoding]::Unicode.GetBytes($FaceName)
    [Array]::Copy($nb, 0, $bytes, 28, [Math]::Min($nb.Length, 62))
    return $bytes
}

# --- FONT VALIDATION ---------------------------------------------------------
function Test-FontInstalled {
    param([string]$Name)
    if ([string]::IsNullOrWhiteSpace($Name) -or $Name -eq "(not set)") { return $false }
    return ([System.Drawing.FontFamily]::Families |
        Where-Object { $_.Name -eq $Name }).Count -gt 0
}

# --- GET ACTIVE DPI (via GDI, not registry) ----------------------------------
function Get-ActiveDPI {
    $hdc = [GDIHelper]::GetDC([IntPtr]::Zero)
    $dpi = [GDIHelper]::GetDeviceCaps($hdc, $LOGPIXELSX)
    [GDIHelper]::ReleaseDC([IntPtr]::Zero, $hdc) | Out-Null
    if ($dpi -lt 72) { return 96 }
    return [int]$dpi
}

# --- GET ACCESSIBILITY TEXT SCALE --------------------------------------------
function Get-TextScale {
    try {
        $v = (Get-ItemProperty $ACC_PATH -ErrorAction SilentlyContinue).TextScaleFactor
        if ($v -and [int]$v -gt 0) { return [int]$v }
    } catch {}
    return 100
}

# --- WEIGHT / ITALIC DISPLAY -------------------------------------------------
function Format-Weight {
    param([int]$W)
    if ($W -eq 0)   { return "  --  " }
    if ($W -eq 400) { return "Normal" }
    if ($W -eq 700) { return "Bold" }
    return "$W"
}

function Format-Style {
    param([int]$W, [byte]$I)
    if ($W -eq 0) { return "  --  " }
    $s = if ($W -ge 700) { "Bold" } else { "Normal" }
    if ($I) { $s += " Italic" }
    return $s
}

# --- ENTRY DEFINITIONS -------------------------------------------------------
$ENTRIES = @(
    [ordered]@{ ID=1; Category="Titlebar";        Label="Title Bar";             Type="logfont";    Key="CaptionFont"    }
    [ordered]@{ ID=2; Category="Titlebar";        Label="Tool Window Title Bar"; Type="logfont";    Key="SmCaptionFont"  }
    [ordered]@{ ID=3; Category="Icons";           Label="Icon Labels";           Type="logfont";    Key="IconFont"       }
    [ordered]@{ ID=4; Category="Menus";           Label="Menu";                  Type="logfont";    Key="MenuFont"       }
    [ordered]@{ ID=5; Category="Miscellaneous";   Label="Message / Dialogs";     Type="logfont";    Key="MessageFont"    }
    [ordered]@{ ID=6; Category="Miscellaneous";   Label="Status / Tooltips";     Type="logfont";    Key="StatusFont"     }
    [ordered]@{ ID=7; Category="Fnt.Substitutes"; Label="MS Shell Dlg";          Type="substitute"; Key="MS Shell Dlg"   }
    [ordered]@{ ID=8; Category="Fnt.Substitutes"; Label="MS Shell Dlg 2";        Type="substitute"; Key="MS Shell Dlg 2" }
    [ordered]@{ ID=9; Category="Fnt.Substitutes"; Label="Segoe UI (sub)";        Type="substitute"; Key="Segoe UI"       }
)

# --- READ ALL CURRENT VALUES -------------------------------------------------
function Read-AllEntries {
    param([int]$DPI)
    $wmProps = Get-ItemProperty $WM_PATH -ErrorAction SilentlyContinue
    $fsProps = Get-ItemProperty $FS_PATH -ErrorAction SilentlyContinue

    foreach ($e in $ENTRIES) {
        if ($e.Type -eq "logfont") {
            $raw = if ($wmProps) { $wmProps.($e.Key) } else { $null }
            $lf  = Read-LogFont -Bytes $raw -DPI $DPI
            $e.CurrentName   = $lf.Name
            $e.CurrentSize   = $lf.PointSize
            $e.CurrentWeight = $lf.Weight
            $e.CurrentItalic = $lf.Italic
        } else {
            $val = if ($fsProps) { $fsProps.($e.Key) } else { $null }
            $e.CurrentName   = if ($val) { $val } else { "(not set)" }
            $e.CurrentSize   = $null
            $e.CurrentWeight = $null
            $e.CurrentItalic = $null
        }
    }
}

# --- DISPLAY TABLE -----------------------------------------------------------
function Show-Table {
    param([int]$DPI)

    Read-AllEntries -DPI $DPI

    $dispScale = [Math]::Round($DPI / 96 * 100)
    $textScale = Get-TextScale

    Clear-Host
    Write-Host ""
    Write-Host "  =================================================================" -ForegroundColor Cyan
    Write-Host "    Windows System Font Manager  (v2)" -ForegroundColor Cyan
    Write-Host "  =================================================================" -ForegroundColor Cyan
    Write-Host ("    Active DPI: {0}  |  Display Scale: {1}%  |  Text Scale: {2}%" -f $DPI, $dispScale, $textScale) -ForegroundColor DarkCyan
    Write-Host ""
    Write-Host ("  {0,-3}  {1,-16}  {2,-26}  {3,-22}  {4,-6}  {5}" -f `
        "ID","Category","Label","Font Name","Size","Style") -ForegroundColor DarkGray
    Write-Host ("  {0,-3}  {1,-16}  {2,-26}  {3,-22}  {4,-6}  {5}" -f `
        "---","----------------","--------------------------","----------------------","------","-------------") -ForegroundColor DarkGray

    foreach ($e in $ENTRIES) {
        $sizeStr  = if ($null -ne $e.CurrentSize -and $e.CurrentSize -gt 0) {
                        "$($e.CurrentSize) pt"
                    } else { "  --  " }
        $styleStr = if ($null -ne $e.CurrentWeight) {
                        Format-Style -W $e.CurrentWeight -I ([byte]$e.CurrentItalic)
                    } else { "  --  " }

        $dispName  = if ($e.CurrentName -eq "(not set)") { "(not set)" } else { $e.CurrentName }
        $nameColor = if ($e.CurrentName -eq "(not set)") { "DarkGray" }
                     elseif (Test-FontInstalled $e.CurrentName) { "White" }
                     else { "Yellow" }

        Write-Host -NoNewline ("  {0,-3}  {1,-16}  {2,-26}  " -f $e.ID, $e.Category, $e.Label)
        Write-Host -NoNewline ("{0,-22}" -f $dispName) -ForegroundColor $nameColor
        Write-Host ("  {0,-6}  {1}" -f $sizeStr, $styleStr)
    }

    Write-Host ""
    Write-Host "  [White=installed]  [Yellow=not found]  [Gray=(not set)]" -ForegroundColor DarkGray
    Write-Host ""
    Write-Host "  ----------------------------------------------------------------" -ForegroundColor DarkGray
    Write-Host "  [1-9] Edit entry    [L] List installed fonts    [Q] Quit" -ForegroundColor DarkCyan
    Write-Host "  ----------------------------------------------------------------" -ForegroundColor DarkGray
    Write-Host ""
}

# --- LIST INSTALLED FONTS (numbered, 2-column) --------------------------------
function Show-InstalledFonts {
    param([string]$Filter = "")
    Clear-Host
    Write-Host ""
    $all = [System.Drawing.FontFamily]::Families | Sort-Object Name | Select-Object -ExpandProperty Name
    if ($Filter -ne "") { $all = $all | Where-Object { $_ -like "*$Filter*" } }

    if ($all.Count -eq 0) {
        Write-Host "  No fonts match: $Filter" -ForegroundColor Yellow
        Write-Host ""
        return $null
    }

    Write-Host ("  Installed fonts$(if($Filter -ne ''){" (filter: '$Filter')"})" ) -ForegroundColor Cyan
    Write-Host ""
    $i = 0
    foreach ($f in $all) {
        $str = ("{0,4}. {1}" -f ($i+1), $f)
        if (($i % 2) -eq 1) { Write-Host ("{0,-38}" -f $str) }
        else                 { Write-Host -NoNewline ("{0,-38}" -f $str) }
        $i++
    }
    if (($i % 2) -ne 0) { Write-Host "" }
    Write-Host ""
    return $all
}

function Select-Font {
    param([string]$CurrentName)
    while ($true) {
        $filter = (Read-Host "  Search font (ENTER = show all)").Trim()
        $fonts  = Show-InstalledFonts -Filter $filter

        if ($null -eq $fonts) {
            $r = (Read-Host "  Try again? [Y/N]").Trim().ToUpper()
            if ($r -ne "Y") { return $null }
            continue
        }

        Write-Host "  Enter font ID  (0 = search again   ENTER = keep current)" -ForegroundColor DarkCyan
        $raw = (Read-Host "  Font ID").Trim()
        if ($raw -eq "") { return $CurrentName }
        $id = 0
        if ([int]::TryParse($raw, [ref]$id)) {
            if ($id -eq 0) { continue }
            if ($id -ge 1 -and $id -le $fonts.Count) { return $fonts[$id - 1] }
        }
        Write-Host "  Invalid ID." -ForegroundColor Yellow
    }
}

# --- EDIT ENTRY --------------------------------------------------------------
function Edit-Entry {
    param($Entry, [int]$DPI)

    Write-Host ""
    Write-Host ("  Editing: [{0}] {1}" -f $Entry.ID, $Entry.Label) -ForegroundColor Cyan
    Write-Host ("  Current font  : {0}" -f $Entry.CurrentName)
    if ($null -ne $Entry.CurrentSize) {
        $italicNote = if ($Entry.CurrentItalic) { "  Italic" } else { "" }
        Write-Host ("  Current size  : {0} pt" -f $Entry.CurrentSize)
        Write-Host ("  Current style : {0}{1}" -f (Format-Weight -W $Entry.CurrentWeight), $italicNote)
    }
    Write-Host ""

    # --- Font selection
    Write-Host "  Select new font:" -ForegroundColor DarkCyan
    $newName = Select-Font -CurrentName $Entry.CurrentName
    if ($null -eq $newName) {
        Write-Host "  Cancelled." -ForegroundColor DarkGray
        return
    }

    if (-not (Test-FontInstalled $newName)) {
        Write-Host ("  WARNING: '{0}' is not installed. Entry will still be written." -f $newName) -ForegroundColor Yellow
    }

    $newSize   = $Entry.CurrentSize
    $newWeight = $Entry.CurrentWeight
    $newItalic = if ($null -ne $Entry.CurrentItalic) { [byte]$Entry.CurrentItalic } else { [byte]0 }

    if ($Entry.Type -eq "logfont") {
        # --- Size
        $rawSize = (Read-Host "  New size in pt (ENTER to keep '$($Entry.CurrentSize) pt')").Trim()
        if ($rawSize -ne "") {
            $parsed = 0
            if ([int]::TryParse($rawSize, [ref]$parsed) -and $parsed -ge 6 -and $parsed -le 72) {
                $newSize = $parsed
            } else {
                Write-Host "  Invalid size. Keeping current." -ForegroundColor Yellow
            }
        }

        # --- Weight
        Write-Host "  Weight: [N] Normal   [B] Bold   [ENTER] Keep current" -ForegroundColor DarkCyan
        $wIn = (Read-Host "  Weight").Trim().ToUpper()
        switch ($wIn) {
            "N" { $newWeight = 400 }
            "B" { $newWeight = 700 }
        }

        # --- Italic
        Write-Host "  Italic: [Y] Yes   [N] No   [ENTER] Keep current" -ForegroundColor DarkCyan
        $iIn = (Read-Host "  Italic").Trim().ToUpper()
        switch ($iIn) {
            "Y" { $newItalic = [byte]1 }
            "N" { $newItalic = [byte]0 }
        }
    }

    # --- Confirm
    Write-Host ""
    if ($Entry.Type -eq "logfont") {
        $styleLabel = Format-Style -W $newWeight -I $newItalic
        Write-Host ("  Apply: {0}  |  {1} pt  |  {2}" -f $newName, $newSize, $styleLabel) -ForegroundColor Green
    } else {
        Write-Host ("  Apply substitute: {0} -> {1}" -f $Entry.Key, $newName) -ForegroundColor Green
    }

    $confirm = (Read-Host "  Confirm? [Y/N]").Trim().ToUpper()
    if ($confirm -ne "Y") {
        Write-Host "  Cancelled." -ForegroundColor DarkGray
        return
    }

    # --- Write
    try {
        if ($Entry.Type -eq "logfont") {
            $bytes = Build-LogFont -FaceName $newName -PointSize $newSize -DPI $DPI `
                                   -Weight $newWeight -Italic $newItalic
            Set-ItemProperty -Path $WM_PATH -Name $Entry.Key -Value $bytes -Type Binary -ErrorAction Stop
        } else {
            if (-not (Test-Path $FS_PATH)) { New-Item -Path $FS_PATH -Force | Out-Null }
            Set-ItemProperty -Path $FS_PATH -Name $Entry.Key -Value $newName -Type String -ErrorAction Stop
        }
        Write-Host ("  [{0}] written successfully." -f $Entry.Key) -ForegroundColor Green
        $script:pendingRestart = $true
    } catch {
        Write-Host ("  FAILED to write [{0}]: {1}" -f $Entry.Key, $_) -ForegroundColor Red
    }

    Start-Sleep -Milliseconds 800
}

# --- MAIN LOOP ---------------------------------------------------------------
$script:pendingRestart = $false
$dpi = Get-ActiveDPI

while ($true) {
    Show-Table -DPI $dpi

    if ($script:pendingRestart) {
        Write-Host "  *** Pending changes detected. Restart Windows to apply. ***" -ForegroundColor Yellow
        Write-Host ""
    }

    $input = (Read-Host "  Command").Trim().ToUpper()

    if ($input -eq "Q") { break }

    if ($input -eq "L") {
        Show-InstalledFonts
        Read-Host "  Press ENTER to return"
        continue
    }

    $id = 0
    if ([int]::TryParse($input, [ref]$id) -and $id -ge 1 -and $id -le 9) {
        $entry = $ENTRIES | Where-Object { $_.ID -eq $id }
        if ($entry) { Edit-Entry -Entry $entry -DPI $dpi }
        continue
    }

    Write-Host "  Unknown command." -ForegroundColor DarkGray
    Start-Sleep -Milliseconds 500
}

# --- EXIT --------------------------------------------------------------------
Write-Host ""
if ($script:pendingRestart) {
    Write-Host "  ========================================================" -ForegroundColor Yellow
    Write-Host "  Changes written. Restart Windows to apply all settings." -ForegroundColor Yellow
    Write-Host "  ========================================================" -ForegroundColor Yellow
} else {
    Write-Host "  No changes made." -ForegroundColor DarkGray
}
Write-Host ""

Read-Host "`nPress ENTER to exit."
Resim
Betik-2 : Set Display DPI Manager v5.1.ps1 [Asıl Amiral Gemisi Budur]

Kod: Tümünü seç

# =============================================================================
# Set-DisplayDPI.ps1  (v5.1)
# Windows 10/11 unified DPI / Font / Style manager.
#
# Modes:
#   [A] Display Scale only  (all UI elements)
#   [B] Text Scale only     (text size, Accessibility)
#   [C] Display Scale + Text Scale together
#
# For each mode the user:
#   1. Enters DPI or Scale%
#   2. Picks a font from a numbered installed-font list
#   3. Picks style: Normal / Bold / Italic / Bold-Italic
#   Script auto-calculates and writes all WindowMetrics LOGFONT entries.
# =============================================================================

Add-Type @"
using System;
using System.Runtime.InteropServices;
public class DPIHelper {
    [DllImport("gdi32.dll")]  public static extern int    GetDeviceCaps(IntPtr hdc, int nIndex);
    [DllImport("user32.dll")] public static extern IntPtr GetDC(IntPtr hWnd);
    [DllImport("user32.dll")] public static extern int    ReleaseDC(IntPtr hWnd, IntPtr hDC);
    [DllImport("user32.dll", CharSet=CharSet.Auto)]
    public static extern IntPtr SendMessageTimeout(
        IntPtr hWnd, uint Msg, UIntPtr wParam,
        string lParam, uint fuFlags, uint uTimeout, out UIntPtr lpdwResult);
}
"@
Add-Type -AssemblyName System.Drawing

# --- CONSTANTS ---------------------------------------------------------------
$LOGPIXELSX       = 88
$WM_SETTINGCHANGE = 0x001A
$HWND_BROADCAST   = [IntPtr]0xFFFF

$WM_PATH  = "HKCU:\Control Panel\Desktop\WindowMetrics"
$FS_PATH  = "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\FontSubstitutes"
$ACC_PATH = "HKCU:\SOFTWARE\Microsoft\Accessibility"

$DISPLAY_SCALE_KEYS = @(
    @{ Path="HKCU:\Control Panel\Desktop";                                                     Name="LogPixels";      Type="DWord"; Fixed=$null }
    @{ Path="HKCU:\Control Panel\Desktop";                                                     Name="Win8DpiScaling"; Type="DWord"; Fixed=1    }
    @{ Path="HKCU:\Control Panel\Desktop\WindowMetrics";                                       Name="AppliedDPI";     Type="DWord"; Fixed=$null }
    @{ Path="HKLM:\System\CurrentControlSet\Hardware Profiles\Current\Software\Fonts";         Name="LogPixels";      Type="DWord"; Fixed=$null }
    @{ Path="HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\FontDPI";                      Name="LogPixels";      Type="DWord"; Fixed=$null }
)

# Auto point sizes per UI element (Windows recommended defaults)
$WM_ENTRIES = @(
    @{ Key="CaptionFont";   Label="Title Bar";          AutoPt=9 }
    @{ Key="SmCaptionFont"; Label="Tool Window Title";  AutoPt=8 }
    @{ Key="IconFont";      Label="Icon Labels";        AutoPt=9 }
    @{ Key="MenuFont";      Label="Menu";               AutoPt=9 }
    @{ Key="MessageFont";   Label="Message / Dialogs";  AutoPt=9 }
    @{ Key="StatusFont";    Label="Status / Tooltips";  AutoPt=8 }
)

$FS_ENTRIES = @("MS Shell Dlg", "MS Shell Dlg 2", "Segoe UI")

$PRESETS = [ordered]@{
    100=96; 125=120; 150=144; 175=168; 200=192; 225=216; 250=240; 300=288; 350=336
}

# --- LOGFONT -----------------------------------------------------------------
function Build-LogFont {
    param([string]$Face,[int]$Pt,[int]$DPI=96,[int]$Weight=400,[byte]$Italic=0)
    $b=[byte[]]::new(92)
    $h=[int32](-[Math]::Round($Pt*$DPI/72))
    [Array]::Copy([BitConverter]::GetBytes($h),             0,$b, 0,4)
    [Array]::Copy([BitConverter]::GetBytes([int32]$Weight), 0,$b,16,4)
    $b[20]=$Italic; $b[23]=1; $b[26]=5
    $nb=[System.Text.Encoding]::Unicode.GetBytes($Face)
    [Array]::Copy($nb,0,$b,28,[Math]::Min($nb.Length,62))
    return $b
}
function Read-LogFont {
    param([byte[]]$B,[int]$DPI=96)
    if($null -eq $B -or $B.Length -lt 92){return @{Name="(none)";Pt=0;Weight=0;Italic=0}}
    $h=[BitConverter]::ToInt32($B,0); $w=[BitConverter]::ToInt32($B,16); $it=$B[20]
    $nm=[System.Text.Encoding]::Unicode.GetString($B,28,64).TrimEnd([char]0)
    $pt=if($h-lt 0){[Math]::Round([Math]::Abs($h)*72/$DPI)}else{$h}
    return @{Name=$nm;Pt=[int]$pt;Weight=$w;Italic=$it}
}

# --- HELPERS -----------------------------------------------------------------
function Get-CurrentDPI {
    $hdc=[DPIHelper]::GetDC([IntPtr]::Zero)
    $v=[DPIHelper]::GetDeviceCaps($hdc,$LOGPIXELSX)
    [DPIHelper]::ReleaseDC([IntPtr]::Zero,$hdc)|Out-Null
    return [int]$v
}
function Get-CurrentTextScale {
    try{$v=(Get-ItemProperty $ACC_PATH -EA SilentlyContinue).TextScaleFactor;if($v){return [int]$v}}catch{}
    return 100
}
function ConvertTo-Scale{param([int]$D) return [Math]::Round($D/96*100)}
function ConvertTo-DPI  {param([int]$S) return [Math]::Round($S*96/100)}
function Read-Choice {
    param([string]$P,[string[]]$V)
    while($true){
        $i=(Read-Host $P).Trim().ToUpper()
        if($V -contains $i){return $i}
        Write-Host "  Please enter one of: $($V -join ', ')" -ForegroundColor Yellow
    }
}
function Read-Int {
    param([string]$P,[int]$Min,[int]$Max)
    while($true){
        $r=Read-Host $P;$v=0
        if([int]::TryParse($r.Trim(),[ref]$v)-and $v-ge $Min-and $v-le $Max){return $v}
        Write-Host "  Enter an integer between $Min and $Max." -ForegroundColor Yellow
    }
}
function Send-Broadcast {
    $r=[UIntPtr]::Zero
    [DPIHelper]::SendMessageTimeout($HWND_BROADCAST,$WM_SETTINGCHANGE,[UIntPtr]::Zero,"Environment",2,1000,[ref]$r)|Out-Null
}

# --- FONT LIST ---------------------------------------------------------------
function Get-InstalledFonts {
    return [System.Drawing.FontFamily]::Families|Sort-Object Name|Select-Object -ExpandProperty Name
}

function Show-FontList {
    param([string]$Filter="")
    $fonts=Get-InstalledFonts
    if($Filter-ne""){$fonts=$fonts|Where-Object{$_ -like "*$Filter*"}}
    if($fonts.Count-eq 0){Write-Host "  No fonts match '$Filter'." -ForegroundColor Yellow;return $null}
    Clear-Host
    Write-Host ""
    Write-Host "  Installed fonts$(if($Filter-ne''){"  (filter: '$Filter')"})" -ForegroundColor Cyan
    Write-Host ""
    $i=0
    foreach($f in $fonts){
        $id=$i+1
        $str=("{0,4}. {1}" -f $id,$f)
        if(($i%2)-eq 1){Write-Host("{0,-38}"-f $str)}
        else{Write-Host -NoNewline("{0,-38}"-f $str)}
        $i++
    }
    if(($i%2)-ne 0){Write-Host ""}
    Write-Host ""
    return $fonts
}

function Select-Font {
    while($true){
        $filter=(Read-Host "  Search font name (ENTER = show all)").Trim()
        $fonts=Show-FontList -Filter $filter
        if($null -eq $fonts){
            $r=Read-Choice "  Try again? [Y/N]" @("Y","N")
            if($r-eq"N"){return $null}
            continue
        }
        Write-Host "  Enter font ID  (0 = search again)" -ForegroundColor DarkCyan
        $id=Read-Int "  Font ID" 0 $fonts.Count
        if($id-eq 0){continue}
        return $fonts[$id-1]
    }
}

function Select-Style {
    Write-Host ""
    Write-Host "  Font style:" -ForegroundColor DarkCyan
    Write-Host "  [1] Normal   [2] Bold   [3] Italic   [4] Bold Italic" -ForegroundColor Gray
    Write-Host ""
    $s=Read-Choice "  Style" @("1","2","3","4")
    switch($s){
        "1"{return @{Weight=400;Italic=[byte]0;Label="Normal"}}
        "2"{return @{Weight=700;Italic=[byte]0;Label="Bold"}}
        "3"{return @{Weight=400;Italic=[byte]1;Label="Italic"}}
        "4"{return @{Weight=700;Italic=[byte]1;Label="Bold Italic"}}
    }
}

# --- STATUS ------------------------------------------------------------------
function Show-Status {
    $dpi=Get-CurrentDPI; $scale=ConvertTo-Scale $dpi; $text=Get-CurrentTextScale
    $wmP=Get-ItemProperty $WM_PATH -EA SilentlyContinue
    $fsP=Get-ItemProperty $FS_PATH -EA SilentlyContinue
    Clear-Host
    Write-Host ""
    Write-Host "  =================================================================" -ForegroundColor Cyan
    Write-Host "    Set-DisplayDPI  v5.1  --  Windows 10/11 Scale + Font Manager" -ForegroundColor Cyan
    Write-Host "  =================================================================" -ForegroundColor Cyan
    Write-Host ""
    Write-Host ("  Display Scale : {0}%  (DPI: {1})" -f $scale,$dpi) -ForegroundColor White
    Write-Host ("  Text Scale    : {0}%  (Accessibility)" -f $text) -ForegroundColor White
    Write-Host ""
    Write-Host "  Active font settings:" -ForegroundColor DarkCyan
    Write-Host ("  {0,-22}  {1,-22}  {2,-6}  {3}" -f "UI Element","Font","Size","Style") -ForegroundColor DarkGray
    Write-Host ("  {0,-22}  {1,-22}  {2,-6}  {3}" -f "----------------------","----------------------","------","----------") -ForegroundColor DarkGray
    foreach($e in $WM_ENTRIES){
        $lf=Read-LogFont -B $wmP.($e.Key) -DPI $dpi
        $sty=if($lf.Weight-ge 700-and $lf.Italic){"Bold Italic"}
             elseif($lf.Weight-ge 700){"Bold"}
             elseif($lf.Italic){"Italic"}
             else{"Normal"}
        $ptS=if($lf.Pt-gt 0){"$($lf.Pt) pt"}else{"  --  "}
        Write-Host("  {0,-22}  {1,-22}  {2,-6}  {3}"-f $e.Label,$lf.Name,$ptS,$sty)
    }
    Write-Host ""
    Write-Host "  FontSubstitutes:" -ForegroundColor DarkCyan
    foreach($k in $FS_ENTRIES){
        $v=$fsP.$k
        Write-Host("    {0,-20} -> {1}"-f $k,$(if($v){$v}else{"(not set)"}))
    }
    Write-Host ""
    Write-Host "  Presets:" -ForegroundColor DarkGray
    # Use explicit key list to avoid ordered-hashtable int-key lookup issues
    $presetKeys = @(100,125,150,175,200,225,250,300,350)
    $presetVals = @( 96,120,144,168,192,216,240,288,336)
    for($pi=0;$pi -lt $presetKeys.Length;$pi++){
        $pKey=$presetKeys[$pi]; $pVal=$presetVals[$pi]
        $mk=if($pKey-eq $scale){" <-- current"}else{""}
        $cl=if($mk){"Green"}else{"DarkGray"}
        Write-Host("  {0,-8} = DPI {1,-5}{2}"-f "$pKey%",$pVal,$mk) -ForegroundColor $cl
    }
    Write-Host ""
    Write-Host "  [A] Display Scale   [B] Text Scale   [C] Both   [Q] Quit" -ForegroundColor DarkCyan
    Write-Host ""
}

# --- READ DPI INPUT ----------------------------------------------------------
function Read-DPIInput {
    $mode=Read-Choice "  Input mode: [D] = DPI value   [S] = Scale %" @("D","S")
    if($mode-eq"D"){
        $newDPI=Read-Int "  Enter DPI (96 - 480)" 96 480
        $newScale=ConvertTo-Scale $newDPI
    }else{
        $newScale=Read-Int "  Enter Scale % (100 - 500)" 100 500
        $newDPI=ConvertTo-DPI $newScale
    }
    Write-Host("  ->  DPI={0}  Scale={1}%"-f $newDPI,$newScale) -ForegroundColor Cyan
    if(-not($PRESETS.Values -contains $newDPI)){
        Write-Host("  WARNING: {0} DPI is not a standard preset."-f $newDPI) -ForegroundColor Yellow
    }
    return @{DPI=$newDPI;Scale=$newScale}
}

# --- PREVIEW -----------------------------------------------------------------
function Show-Preview {
    param($Font,$DPIInfo,$TextScale,[string]$Mode)
    $applyD=($Mode-eq"A"-or $Mode-eq"C")
    $applyT=($Mode-eq"B"-or $Mode-eq"C")
    $dpi=if($applyD){$DPIInfo.DPI}else{Get-CurrentDPI}
    Write-Host ""
    Write-Host "  --- Preview of changes to apply ---" -ForegroundColor Cyan
    if($applyD){Write-Host("  Display Scale : {0}%  (DPI: {1})"-f $DPIInfo.Scale,$DPIInfo.DPI) -ForegroundColor White}
    Write-Host("  Font          : {0}  |  Style: {1}"-f $Font.Name,$Font.StyleLabel) -ForegroundColor White
    Write-Host ""
    # Use TextScale for ALL modes: Mode A passes existing TextScale, B/C pass new value
    $tsPct=if($TextScale-gt 0){$TextScale}else{100}
    # Header: show TextScale line with [new] or [existing] tag
    if($applyT){
        Write-Host("  Text Scale    : {0}%  [new value]"-f $TextScale) -ForegroundColor White
    } elseif($tsPct-ne 100){
        Write-Host("  Text Scale    : {0}%  [existing - kept]"-f $tsPct) -ForegroundColor DarkGray
    }
    Write-Host("  {0,-22}  {1,-10}  {2,-10}  {3}"-f "UI Element","base pt","final pt","px at DPI $dpi") -ForegroundColor DarkGray
    Write-Host("  {0,-22}  {1,-10}  {2,-10}  {3}"-f "----------------------","----------","----------","----------") -ForegroundColor DarkGray
    foreach($e in $WM_ENTRIES){
        $finalPt=[Math]::Max(6,[Math]::Round($e.AutoPt*$tsPct/100))
        $px=[Math]::Round($finalPt*$dpi/72)
        $baseStr="$($e.AutoPt) pt"
        $finalStr=if($tsPct-ne 100){"$finalPt pt"}else{"(same)"}
        Write-Host("  {0,-22}  {1,-10}  {2,-10}  {3} px"-f $e.Label,$baseStr,$finalStr,$px)
    }
    Write-Host ""
    Write-Host("  FontSubstitutes: {0}"-f ($FS_ENTRIES -join ", ")) -ForegroundColor DarkGray
    Write-Host("    -> {0}"-f $Font.Name)
}

# --- WRITE HELPERS -----------------------------------------------------------
function Write-DisplayScale {
    param([int]$DPI)
    foreach($k in $DISPLAY_SCALE_KEYS){
        try{
            $val=if($null -ne $k.Fixed){$k.Fixed}else{$DPI}
            if(-not(Test-Path $k.Path)){New-Item -Path $k.Path -Force|Out-Null}
            Set-ItemProperty -Path $k.Path -Name $k.Name -Value $val -Type $k.Type -EA Stop
            Write-Host("  [SET] {0} \ {1} = {2}"-f ($k.Path -split'\\')[-1],$k.Name,$val) -ForegroundColor Green
        }catch{Write-Host("  [FAIL] {0}\{1}: {2}"-f $k.Path,$k.Name,$_) -ForegroundColor Red}
    }
}
function Write-WMFonts {
    param([string]$Face,[int]$Weight,[byte]$Italic,[int]$DPI,[int]$TextScalePct=100)
    if(-not(Test-Path $WM_PATH)){New-Item -Path $WM_PATH -Force|Out-Null}
    foreach($e in $WM_ENTRIES){
        try{
            $scaledPt=[Math]::Max(6,[Math]::Round($e.AutoPt*$TextScalePct/100))
            $b=Build-LogFont -Face $Face -Pt $scaledPt -DPI $DPI -Weight $Weight -Italic $Italic
            Set-ItemProperty -Path $WM_PATH -Name $e.Key -Value $b -Type Binary -EA Stop
            $scaleNote=if($TextScalePct-ne 100){"  (base $($e.AutoPt) pt x $TextScalePct%)"}else{""}
            Write-Host("  [SET] {0,-22} -> {1}  {2} pt{3}"-f $e.Label,$Face,$scaledPt,$scaleNote) -ForegroundColor Green
        }catch{Write-Host("  [FAIL] {0}: {1}"-f $e.Key,$_) -ForegroundColor Red}
    }
}
function Write-FontSubstitutes {
    param([string]$Face)
    if(-not(Test-Path $FS_PATH)){New-Item -Path $FS_PATH -Force|Out-Null}
    foreach($k in $FS_ENTRIES){
        try{
            Set-ItemProperty -Path $FS_PATH -Name $k -Value $Face -Type String -EA Stop
            Write-Host("  [SET] Substitute {0,-20} -> {1}"-f $k,$Face) -ForegroundColor Green
        }catch{Write-Host("  [FAIL] Substitute {0}: {1}"-f $k,$_) -ForegroundColor Red}
    }
}
function Write-TextScale {
    param([int]$Scale)
    try{
        if(-not(Test-Path $ACC_PATH)){New-Item -Path $ACC_PATH -Force|Out-Null}
        Set-ItemProperty -Path $ACC_PATH -Name "TextScaleFactor" -Value $Scale -Type DWord -EA Stop
        Write-Host("  [SET] TextScaleFactor = {0}%"-f $Scale) -ForegroundColor Green
        Send-Broadcast
        Write-Host "  WM_SETTINGCHANGE broadcast sent." -ForegroundColor DarkGray
    }catch{Write-Host("  [FAIL] TextScaleFactor: {0}"-f $_) -ForegroundColor Red}
}

# --- FONT + STYLE SELECTION --------------------------------------------------
function Read-FontAndStyle {
    Write-Host ""
    Write-Host "  Select font for all UI entries:" -ForegroundColor Cyan
    $name=Select-Font
    if($null -eq $name){Write-Host "  Font selection cancelled." -ForegroundColor DarkGray;return $null}
    $style=Select-Style
    return @{Name=$name;Weight=$style.Weight;Italic=$style.Italic;StyleLabel=$style.Label}
}

# --- MODES -------------------------------------------------------------------
function Run-ModeA {
    Write-Host ""; Write-Host "  [A] Display Scale + Font" -ForegroundColor Cyan
    $dpiInfo=Read-DPIInput
    $font=Read-FontAndStyle
    if($null -eq $font){return}
    # Carry over existing TextScale so LOGFONT punto is not silently reset to 9pt
    $existingTS=Get-CurrentTextScale
    Show-Preview -Font $font -DPIInfo $dpiInfo -TextScale $existingTS -Mode "A"
    Write-Host ""
    if((Read-Choice "  Apply? [Y/N]" @("Y","N")) -eq "N"){Write-Host "  Cancelled." -ForegroundColor DarkGray;return}
    Write-Host ""; Write-Host "  Writing Display Scale..." -ForegroundColor DarkCyan
    Write-DisplayScale -DPI $dpiInfo.DPI
    Write-Host ""; Write-Host "  Writing WindowMetrics fonts..." -ForegroundColor DarkCyan
    # Pass existing TextScale: preview and write now use the same value
    Write-WMFonts -Face $font.Name -Weight $font.Weight -Italic $font.Italic -DPI $dpiInfo.DPI -TextScalePct $existingTS
    Write-Host ""; Write-Host "  Writing FontSubstitutes..." -ForegroundColor DarkCyan
    Write-FontSubstitutes -Face $font.Name
    Write-Host ""; Write-Host "  *** FULL RESTART REQUIRED. ***" -ForegroundColor Yellow
}

function Run-ModeB {
    Write-Host ""; Write-Host "  [B] Text Scale + Font" -ForegroundColor Cyan
    $textScale=Read-Int "  Enter Text Scale % (100 - 225)" 100 225
    $font=Read-FontAndStyle
    if($null -eq $font){return}
    $dpi=Get-CurrentDPI
    Show-Preview -Font $font -DPIInfo @{DPI=$dpi;Scale=(ConvertTo-Scale $dpi)} -TextScale $textScale -Mode "B"
    Write-Host ""
    if((Read-Choice "  Apply? [Y/N]" @("Y","N")) -eq "N"){Write-Host "  Cancelled." -ForegroundColor DarkGray;return}
    Write-Host ""; Write-Host "  Writing Text Scale..." -ForegroundColor DarkCyan
    Write-TextScale -Scale $textScale
    Write-Host ""; Write-Host "  Writing WindowMetrics fonts..." -ForegroundColor DarkCyan
    Write-WMFonts -Face $font.Name -Weight $font.Weight -Italic $font.Italic -DPI $dpi -TextScalePct $textScale
    Write-Host ""; Write-Host "  Writing FontSubstitutes..." -ForegroundColor DarkCyan
    Write-FontSubstitutes -Face $font.Name
    Write-Host ""; Write-Host "  *** FULL RESTART REQUIRED. ***" -ForegroundColor Yellow
}

function Run-ModeC {
    Write-Host ""; Write-Host "  [C] Display Scale + Text Scale + Font" -ForegroundColor Cyan
    Write-Host ""; Write-Host "  -- Display Scale --" -ForegroundColor DarkCyan
    $dpiInfo=Read-DPIInput
    Write-Host ""; Write-Host "  -- Text Scale --" -ForegroundColor DarkCyan
    $textScale=Read-Int "  Enter Text Scale % (100 - 225)" 100 225
    $font=Read-FontAndStyle
    if($null -eq $font){return}
    Show-Preview -Font $font -DPIInfo $dpiInfo -TextScale $textScale -Mode "C"
    Write-Host ""
    if((Read-Choice "  Apply all? [Y/N]" @("Y","N")) -eq "N"){Write-Host "  Cancelled." -ForegroundColor DarkGray;return}
    Write-Host ""; Write-Host "  Writing Display Scale..." -ForegroundColor DarkCyan
    Write-DisplayScale -DPI $dpiInfo.DPI
    Write-Host ""; Write-Host "  Writing Text Scale..." -ForegroundColor DarkCyan
    Write-TextScale -Scale $textScale
    Write-Host ""; Write-Host "  Writing WindowMetrics fonts..." -ForegroundColor DarkCyan
    Write-WMFonts -Face $font.Name -Weight $font.Weight -Italic $font.Italic -DPI $dpiInfo.DPI -TextScalePct $textScale
    Write-Host ""; Write-Host "  Writing FontSubstitutes..." -ForegroundColor DarkCyan
    Write-FontSubstitutes -Face $font.Name
    Write-Host ""; Write-Host "  *** FULL RESTART REQUIRED. ***" -ForegroundColor Yellow
}

# --- MAIN LOOP ---------------------------------------------------------------
while($true){
    Show-Status
    $cmd=Read-Choice "  Command" @("A","B","C","Q")
    if($cmd-eq"Q"){break}
    switch($cmd){"A"{Run-ModeA}"B"{Run-ModeB}"C"{Run-ModeC}}
    Write-Host ""
    Read-Host "  Press ENTER to return to menu"
}

Write-Host ""
Read-Host "`nPress ENTER to exit."
Resim
50 GÜNLÜK İNDİRME LİNK :

https://www.upload.ee/files/19318929/WindowsDPI.7z.html

SONUÇLARI (Betiklerin Sistem Üzerindeki Görsel Etkileri) :

Sistem : Windows11.24H2.R7019 Home x64-Kullanılan Yazı Fontu : Play
Resim
Resim