mIRC Home    About    Download    Register    News    Help

Print Thread
#255230 01/10/15 11:19 AM
Joined: Feb 2015
Posts: 138
kap Offline OP
Vogon poet
OP Offline
Vogon poet
Joined: Feb 2015
Posts: 138
Hello,

I've been spending some time in pai's MTS engine on Peace and Protection(PnP) and created a dark theme. I like using the font Consolas and before applying a new theme PnP checks whether a font exists with this function:


Code:
alias -l font.exists {
  var %chr = 32
  while (%chr < 127) {
    if (($width($chr(%chr),$1-,100) != $width($chr(%chr),$1- bold,100)) || ($height($chr(%chr),$1-,100) != $height($chr(%chr),$1- bold,100))) return 1
    inc %chr
  }
  return 0
}


This code returns 1 for Courier New, Times New Roman, Verdana, FixedSys etc. However it returns 0 for Consolas or - my new favorite - Hack (https://github.com/chrissimpkins/Hack)

Without going into com objects to query for installed fonts, I wanted to float the feature suggestion of $font(Consolas).exists identifier and property that returns True if a Font exists on a machine and False if it doesn't.

Thanks for reading!

kind regards,


GNU Terry Pratchett - Looking for a mIRC help channel -> Check #mircscripting @ irc.swiftirc.net
Joined: Apr 2003
Posts: 342
M
Fjord artisan
Offline
Fjord artisan
M
Joined: Apr 2003
Posts: 342
People have been asking for a way to check if a font exists or not for years now. Don't think it's ever been added. Not to fear though. Perhaps we can fix that little alias you have there...

This seems to work for me...
Code:
alias -l font.exists {
  var %chr = 32
  while (%chr < 127) {
    if (($width($chr(%chr),$1-,100) != $width($chr(%chr),$1- bold,100)) || ($height($chr(%chr),$1-,100) != $height($chr(%chr),$1- bold,100)) $&
      || ($width($chr(32),$1- bold,100) != $width($chr(32),*,100)) || ($height($chr(32),$1- bold,100) != $height($chr(32),*,100))) return 1   
    inc %chr
  }
  return 0
}


Link Copied to Clipboard