Jump to content
New account registrations are disabed. This website is now an archive. Read more here.
Sign in to follow this  
Guest Wachunga

Auto Font Install

Recommended Posts

Guest Wachunga

Introduction

Automatically installs one or more fonts so the player doesn't have to. It only does this the first time the game is run and the process is quite transparent (notification to the player is optional).

 

Features

  • handles installation of fonts so players don't have to
  • supports multiple fonts
  • transparent installation

Screenshots

post-1-0-91892900-1331858893_thumb.jpg post-1-0-16975300-1331858895_thumb.jpg

 

The Script

auto_font_install.txt

 

 

#==============================================================================
# ** Auto Font Install
#------------------------------------------------------------------------------
# Wachunga
# Version 1.1
# 2006-05-26
#------------------------------------------------------------------------------
=begin

 Automatically installs one or more fonts so the player doesn't have to. It
 only does this the first time the game is run and the process is quite
 transparent (notification to the player is optional).

 Thanks to MagicMagor for the pointer to one of the Win32 functions.

 FEATURES
 - handles installation of fonts so players don't have to
 - supports multiple fonts
 - process is quite transparent

 SETUP
 Create a Fonts folder in the game directory and place all fonts to be
 installed within. Then update the Filenames and Names constants below,
 adding an element to both arrays for each font.

 This script only installs the fonts on the player's computer. You'll
 still have to refer to them as necessary within the game,
 e.g. by setting a new default as follows (in main):
 Font.default_name = [Fonts::Names[0], 'MS PGothic']

 This script uses the SDK, available from:
 http://www.hbgames.org/forums/showthread.php?t=1802

 (To remove this dependency, just delete the three SDK-labeled lines,
 including the 'end' at the bottom of the script.)

 This script also requires the free FileUtils module by Minero Aoki, which
 is included in the standard Ruby distribution but for some reason not
 available in RMXP. Download and place it in your scripts subdirectory:
 http://s88387243.onlinehome.us/rmxp/auto_font_install/fileutils.rb

 Note: if player does not have the rights to install fonts on their machine,
 this probably won't work -- but then they wouldn't be able to do it manually
 either. :)

=end

#------------------------------------------------------------------------------
# * SDK Log Script
#------------------------------------------------------------------------------
SDK.log('Auto Font Install', 'Wachunga', 1.1, '2006-05-26')

#------------------------------------------------------------------------------
# * Begin SDK Enabled Check
#------------------------------------------------------------------------------
if SDK.state('Auto Font Install') == true

 module Fonts
   # filenames of fonts to be in stalled
   Filenames = ['FUTRFW.TTF']

   # names (not filenames) of fonts to be installed
   Names = ['Futurist Fixed-width']

   # whether to notify player (via pop-up message) that fonts were installed
   Notify = true

   # location of fonts (relative to game folder)
   Source = 'Fonts/'

   # location of fonts after installation
   Dest = ENV['SystemRoot'] + '\Fonts\\'
 end

 class Scene_Title

   AFR = Win32API.new('gdi32', 'AddFontResource', ['P'], 'L')
   WPS = Win32API.new('kernel32', 'WriteProfileString', ['P'] * 3, 'L')
   SM = Win32API.new('user32', 'SendMessage', ['L'] * 4, 'L')
   WM_FONTCHANGE = 0x001D
   HWND_BROADCAST = 0xffff

   alias wachunga_autofontinstall_st_main main
   def main
  success = []
  for i in 0...Fonts::Filenames.size
    f = Fonts::Filenames[i]
    # check if already installed...
    if not FileTest.exists?(Fonts::Dest + f)
	  # check to ensure font is in specified location...
	  if FileTest.exists?(Fonts::Source + f)
	    require Dir.getwd + '/Data/fileutils.rb'
	    # copy file to fonts folder
	    FileUtils.cp(Fonts::Source + f, Fonts::Dest + f)
	    # add font resource
	    AFR.call(Fonts::Dest + f)
	    # add entry to win.ini/registry
	    WPS.call('Fonts', Fonts::Names[i] + ' (TrueType)', f)
	    SM.call(HWND_BROADCAST,WM_FONTCHANGE,0,0)
	    if FileTest.exists?(Fonts::Dest + f)
		  success.push(Fonts::Names[i])
	    else
		  print "Auto Font Install:\n\nFailed to install " +
		    Fonts::Names[i] + '.'
	    end
	  else
	    print "Auto Font Install:\n\nFont " + f + " not found."
	  end
    end
  end
  if success != [] # one or more fonts successfully installed
    if Fonts::Notify
	  fonts = ''
	  success.each do |f|
	    fonts << f << ', '
	  end
	  print "Auto Font Install:\n\nSucessfully installed " + fonts[0..-3] +
	    '.'
    end
    # new fonts aren't recognized in RMXP until the program is
    # restarted, so this is (unfortunately) necessary
    a = Thread.new { system('Game') }
    exit
  end
  wachunga_autofontinstall_st_main
   end

 end

#------------------------------------------------------------------------------
# * End SDK Enable Test
#------------------------------------------------------------------------------
end

 

Instructions

 

Copy all of this script, and open the Script Editor within RMXP. At the bottom of the list of classes on the left side of the new window, you'll see one called "Main". Right click on it and select "Insert". In the newly created entry in the list, paste this script.

 

Note that this script uses the SDK, which must be above this script. Remove or comment out the "SDK Log Script" and "SDK Enabled Check" (also at the end of the script) to remove this dependency.

 

This script also requires the free FileUtils module by Minero Aoki, which is included in the standard Ruby distribution but for some reason not available in RMXP. Download fileutils.rb and place it in your scripts subdirectory.

 

Full instructions are provided at the top of the script itself.

 

Compatibility

SDK 1.5 compliant, but can also work without using the SDK.

 

Updates & History<p>

New in version 1.1:

  • now copies the font when installing it instead of moving it permanently
  • slightly improved notification message

Credits & Thanks

Thanks to MagicMagor for the pointer to one of the Win32 functions.

 

Authors Notes

Full instructions are provided at the top of the script itself.

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...