Skip to content

Instantly share code, notes, and snippets.

@AWtnb
Created April 21, 2024 05:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AWtnb/183f76b10bf2f159a328a999afd43ba7 to your computer and use it in GitHub Desktop.
Save AWtnb/183f76b10bf2f159a328a999afd43ba7 to your computer and use it in GitHub Desktop.
Check RTF font information inside clipboard with Windows Powreshell
function Get-ClipboardFontInfo {
Add-Type -AssemblyName System.Windows.Forms
$cb = [System.Windows.Forms.Clipboard]::GetData([System.Windows.Forms.DataFormats]::Rtf)
if (-not $cb) {
"フォント情報がコピーされていません……" | Write-Host
return
}
$rtb = [System.Windows.Forms.RichTextBox]::new()
$rtb.Rtf = $cb
$font = $null
for ($i = 0; $i -lt $rtb.Text.length; $i++) {
$rtb.Select($i, 1)
$t = $rtb.SelectedText
$u = [Convert]::ToInt32($t -as [char]).ToString("X4")
$font = $rtb.SelectionFont
[PSCustomObject]@{
"Text" = $t;
"Codepoint" = $u;
"OriginalFontName" = $font.OriginalFontName;
"Size" = $font.SizeInPoints;
"Style" = $font.Style;
} | Write-Output
$font | Clear-Variable -ErrorAction SilentlyContinue
}
$rtb | Clear-Variable -ErrorAction SilentlyContinue
}
Get-ClipboardFontInfo | Format-Table
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment