mIRC Homepage
Posted By: pouncer previewing a font in a textbox - 28/05/07 02:30 PM
can someone show me how to make a preview font thing, where i can select a font on my system, and it will show the font in a preview?
Posted By: Riamus2 Re: previewing a font in a textbox - 28/05/07 03:00 PM
The best method of doing that would be to use the DCX DLL. Set up a richedit window and display the text there with the specified font.

Of course, you could just make it display in a custom window and clear the window each time you preview so you only see the specific preview. But I would personally use DCX for that.
Posted By: pouncer Re: previewing a font in a textbox - 28/05/07 06:43 PM
Thanks, yeah i use dcx and will try that!

also, is there an alias anywhere that will get all the fonts on my machine? i want to grab all these fonts, basically click the font name in the listbox, and the preview shoud come up in the richedit as you say.
Posted By: chiram Re: previewing a font in a textbox - 29/05/07 01:31 AM
been a while since i made a dialog so..
Code:
dialog fontlist {
  ...
  list 25 1 1 1 1
}

alias grabfonts { $findfile(c:\,*.ttf,0,did -a fontlist 25 $1-) }


i believe that should print the full path to each .ttf font file in the listbox.
Posted By: Riamus2 Re: previewing a font in a textbox - 29/05/07 02:24 AM
*** Don't use that alias! As it is written, it will search your entire computer for fonts and if you have a lot of files and large hard drive(s), this can take a very long time.

Use this instead:
Code:
alias grabfonts { $findfile(c:\windows\fonts\,*.ttf,0,0,did -a fontlist 25 $1-) }



If you happen to be on a Windows version that uses a different path for fonts (not sure what Vista uses), you can adjust the path. If necessary, you can check $os and have the path change automatically based on the user's OS.
Posted By: hixxy Re: previewing a font in a textbox - 29/05/07 08:21 AM
That won't list all fonts, only truetype ones. This should get all of them:

Code:
alias grabfonts { noop $findfile(c:\windows\fonts\,*.fon;*.ttf,0,did -a fontlist 25 $1-) }


You should also not start a line with an $identifier, as mIRC will try to execute the return value as a command. In the case of $findfile, it will try to execute /<number_of_files_found>
Posted By: pouncer Re: previewing a font in a textbox - 29/05/07 09:19 AM
Thanks guys. also, isn't there somehow i can save these fonts first time round, and then when the user loads the dialog up, it should put the fonts in the listview

is that a better approach?
Posted By: hixxy Re: previewing a font in a textbox - 29/05/07 11:00 AM
Yeah, you could make a font cache of some sorts..

Code:
alias listfonts { 
  if (!$hget(fontcache)) { noop $findfile(c:\windows\fonts\,*.fon;*.ttf,0,hadd -m fontcache $calc($hget(fontcache,0).item + 1) $1-) }
  var %i = 1
  while ($hget(fontcache,%i)) {
    did -a <dialog> <id> $v1
    inc %i
  }
}


Are you ever going to start having a go at these scripts yourself?
Posted By: Riamus2 Re: previewing a font in a textbox - 29/05/07 11:33 AM
Oh, yeah. I forgot about the .fon fonts. I've used true type for so long that I just forgot there was another format for them. smile

As for using noop, I should have thought of that. I've had few cases where I've needed it, so I didn't think of it.
Posted By: pouncer Re: previewing a font in a textbox - 29/05/07 11:52 AM
well hixxy i'm only asking because someone told me to use filter as its faster loaidng stuff to dialogs like this

Code:
alias listfonts {
  did -r dialog 15
  .filter -k $shortfn(Font.dat) load_font
}

alias load_font {
  if ($1 == [FONTS]) return
  tokenize 61 $1-
  did -a dialog 15 $2
}


where font.dat contains all my system fonts, i'm not sure though
Posted By: deegee Re: previewing a font in a textbox - 29/05/07 04:13 PM
This alias
  • Loads the fonts to the dialog
  • Calls '/listfonts' if needed

To renew the fontlist from "%SystemRoot%\Fonts", delete or empty font.dat.
Code:
alias load_fonts {
  did -r dialog 15
  if !$lines(font.dat) { listfonts }
  loadbuf -o dialog 15 font.dat
}

This alias
  • Finds the path to the "%SystemRoot%\Fonts" directory
  • Then lists the fontfiles in font.dat
  • Sorts the filenames

It lists filenames though, not fontnames.
Code:
alias listfonts {
  var %a = f. $+ $ticks
  .comopen %a WScript.Shell
  if $comerr { return }
  if $com(%a,ExpandEnvironmentStrings,3,bstr*,% $+ SystemRoot%) && $com(%a).result { noop }
  .comclose %a
  if *% iswm $v1 { return }
  %a = $v2 $+ \Fonts
  .fopen -no fontlist font.dat
  noop $findfile(%a,*.fon;*.ttf,0,.fwrite -n fontlist $nopath($1-))
  .fclose fontlist
  filter -ffctn 1 1 font.dat font.dat
}

© mIRC Discussion Forums