indexing

	description: "[

		Frequently used bitmap fonts.
		Use EM_SHARED_STANDARD_FONTS to access this class.

	]"
	date: "$Date$"
	revision: "$Revision$"

class EM_STANDARD_BMP_FONTS

inherit

	EM_SHARED_BITMAP_FACTORY
		export {NONE} all end

	EM_SHARED_ERROR_HANDLER
		export {NONE} all end

	KL_SHARED_EXECUTION_ENVIRONMENT
		export {NONE} all end

	KL_SHARED_FILE_SYSTEM
		export {NONE} all end

create {EM_SHARED_STANDARD_FONTS}

	make

feature {NONE} -- Initialization

	make is
			-- Create standard bmp font object.
		do
		end

feature -- Access

	big_font: EM_FONT is
			-- Standard font, biggest size
		do
			Result := big_vera_font
		end

	medium_font: EM_FONT is
			-- Standard font, medium size
		do
			Result := medium_vera_font
		end

	small_font: EM_FONT is
			-- Standard font, small size
		do
			Result := small_vera_font
		end

	smallest_font: EM_FONT is
			-- Standard font, smallest size
		do
			Result := smallest_vera_font
		end

	big_vera_font: EM_FONT
			-- Vera font, big size

	medium_vera_font: EM_FONT
			-- Vera font, medium size

	small_vera_font: EM_FONT
			-- Vera font, small size

	smallest_vera_font: EM_FONT
			-- Vera font, smallest size

feature -- Status report

	are_fonts_loaded: BOOLEAN
			-- Are fonts loaded?

	font_dirname: STRING is
			-- Name of font directory; If not specified via `set_font_dirname' defaults to:
			-- "${EM}/resource/font/bmp" if the environment variable ${EM} is set
			-- "." (current working directory) otherwise.
		do
			if custom_font_dirname /= Void then
				Result := custom_font_dirname
			else
				Result := default_font_dirname
			end
		end

feature -- Status setting

	set_font_dirname (a_dirname: STRING) is
			-- Set `font_dirname' to `a_dirname'.
		require
			a_dirname_not_void: a_dirname /= Void
		do
			custom_font_dirname := a_dirname
		ensure
			font_dirname_set: font_dirname = a_dirname
		end

feature -- Loading

	load_fonts is
			-- Load available fonts into memory.
			-- Makes them available via `*_font'.
		do
			load_bitmapfont (big_vera_font_filename)
			big_vera_font := last_font
			load_bitmapfont (medium_vera_font_filename)
			medium_vera_font := last_font
			load_bitmapfont (small_vera_font_filename)
			small_vera_font := last_font
			load_bitmapfont (smallest_vera_font_filename)
			smallest_vera_font := last_font
			are_fonts_loaded := True
		end

feature {NONE} -- Implementation

	custom_font_dirname: STRING
			-- Name of custom font directory name; `Void' if not set.

	default_font_dirname: STRING is
			-- Full name of default font directory
		local
			em_value: STRING
		do
			em_value := execution_environment.variable_value ("EM")
			if em_value /= Void then
				Result := file_system.nested_pathname (em_value, <<"resource", "font", "bmp">>)
			else
				Result := (".").twin
			end
		ensure
			filename_not_void: Result /= Void
		end

	load_bitmapfont (a_filename: STRING) is
			-- Load font from the directory `font_dirname' with the filename
			-- `a_filename' and make it available in `last_font'. If file does not exist
			-- or loading fails, set `last_font' to `Void'.
		require
			a_filename_not_void: a_filename /= Void
		local
			full_filename: STRING
			bitmap: EM_BITMAP
		do
			last_font := Void
			full_filename := file_system.pathname (font_dirname, a_filename)
			Bitmap_factory.create_bitmap_from_image (full_filename)
			bitmap := Bitmap_factory.last_bitmap
			bitmap.set_transparent_color (0, 0, 0)
			create {EM_BMP_FONT} last_font.make (bitmap)
		rescue
			Error_handler.raise_error (Error_handler.Em_error_load_bitmapfont, [a_filename])
		end

	last_font: EM_FONT
			-- Last font loaded via `load_font'

feature {NONE} -- Constants

	big_vera_font_filename: STRING is "vera1024.gif"
		-- Relative filename of big vera bitmap font

	medium_vera_font_filename: STRING is "vera512.gif"
		-- Relative filename of medium vera bitmap font

	small_vera_font_filename: STRING is "vera256.gif"
		-- Relative filename of small vera bitmap font

	smallest_vera_font_filename: STRING is "vera128.gif"
		-- Relative filename of smallest vera bitmap font

invariant

	fonts_loaded: are_fonts_loaded implies smallest_font /= Void
	fonts_loaded: are_fonts_loaded implies smallest_vera_font /= Void
	fonts_loaded: are_fonts_loaded implies small_font /= Void
	fonts_loaded: are_fonts_loaded implies small_vera_font /= Void
	fonts_loaded: are_fonts_loaded implies medium_font /= Void
	fonts_loaded: are_fonts_loaded implies medium_vera_font /= Void
	fonts_loaded: are_fonts_loaded implies big_font /= Void
	fonts_loaded: are_fonts_loaded implies big_vera_font /= Void

end