indexing description: "[ Collection of True Type Fonts ]" date: "$Date$" revision: "$Revision$" class EM_STANDARD_TTF_FONTS inherit 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 ttf font object. do end feature -- Access bitstream_vera_sans_fonts: HASH_TABLE [EM_TTF_FONT, INTEGER] is -- Bitstream font table once create Result.make (10) ensure bitstream_vera_sans_fonts_not_void: Result /= Void end bitstream_vera_sans_font (point_size: INTEGER; style: INTEGER): EM_TTF_FONT is -- Bistream font with `point_size' size require point_size_positive: point_size > 0 style_valid: style = Normal or style = Bold or style = Italic or style = Bold | Italic do if bitstream_vera_sans_fonts.has (point_size | style) then Result := bitstream_vera_sans_fonts.item (point_size | style) else if style = Normal then create Result.make_from_ttf_file (file_system.pathname (font_dirname, "Vera.ttf"), point_size) elseif style = Bold then create Result.make_from_ttf_file (file_system.pathname (font_dirname, "VeraBd.ttf"), point_size) elseif style = Italic then create Result.make_from_ttf_file (file_system.pathname (font_dirname, "VeraIt.ttf"), point_size) else create Result.make_from_ttf_file (file_system.pathname (font_dirname, "VeraBI.ttf"), point_size) end bitstream_vera_sans_fonts.put (Result, point_size | style) end ensure bitstream_vera_sans_font_not_void: Result /= Void end bitstream_vera_sans_mono_fonts: HASH_TABLE [EM_TTF_FONT, INTEGER] is -- bitstream font table once create Result.make (10) ensure bitstream_vera_sans_mono_fonts_not_void: Result /= Void end bitstream_vera_sans_mono_font (point_size: INTEGER; style: INTEGER): EM_TTF_FONT is -- bistream font with `point_size' size require point_size_positive: point_size > 0 style_valid: style = Normal or style = Bold or style = Italic or style = Bold | Italic do if bitstream_vera_sans_mono_fonts.has (point_size | style) then Result := bitstream_vera_sans_mono_fonts.item (point_size | style) else if style = Normal then create Result.make_from_ttf_file (file_system.pathname (font_dirname, "VeraMono.ttf"), point_size) elseif style = Bold then create Result.make_from_ttf_file (file_system.pathname (font_dirname, "VeraMoBd.ttf"), point_size) elseif style = Italic then create Result.make_from_ttf_file (file_system.pathname (font_dirname, "VeraMoIt.ttf"), point_size) else create Result.make_from_ttf_file (file_system.pathname (font_dirname, "VeraMoBI.ttf"), point_size) end bitstream_vera_sans_mono_fonts.put (Result, point_size | style) end ensure bitstream_vera_sans_mono_font_not_void: Result /= Void end custom_fonts: HASH_TABLE [EM_TTF_FONT, STRING] is -- store custom fonts once create Result.make (10) ensure custom_fonts_not_void: Result /= Void end feature -- Style for Bitstream Normal: INTEGER is 0x0 Bold: INTEGER is 0x80000 Italic: INTEGER is 0x40000 feature -- Standard Fonts bitstream_vera_sans (point_size: INTEGER): EM_TTF_FONT is -- 'bistream vera sans' font require point_size_positive: point_size > 0 do Result := bitstream_vera_sans_font (point_size, Normal) ensure bitstream_vera_sans_not_void: Result /= Void end bitstream_vera_sans_bold (point_size: INTEGER): EM_TTF_FONT is -- 'bitstream vera sans bold' font require point_size_positive: point_size > 0 do Result := bitstream_vera_sans_font (point_size, Bold) ensure bitstream_vera_sans_bold_not_void: Result /= Void end bitstream_vera_sans_italic (point_size: INTEGER): EM_TTF_FONT is -- 'bitstream vera sans italic' font require point_size_positive: point_size > 0 do Result := bitstream_vera_sans_font (point_size, Italic) ensure bitstream_vera_sans_italic_not_void: Result /= Void end bitstream_vera_sans_bold_italic (point_size: INTEGER): EM_TTF_FONT is -- 'bitstream vera sans bold italic' font require point_size_positive: point_size > 0 do Result := bitstream_vera_sans_font (point_size, Bold | Italic) ensure bitstream_vera_sans_bold_italic_not_void: Result /= Void end bitstream_vera_sans_mono (point_size: INTEGER): EM_TTF_FONT is -- 'bitstream vera sans mono' font require point_size_positive: point_size > 0 do Result := bitstream_vera_sans_mono_font (point_size, Normal) ensure bitstream_vera_sans_mono_not_void: Result /= Void end bitstream_vera_sans_mono_bold (point_size: INTEGER): EM_TTF_FONT is -- 'bitstream vera sans mono bold' font require point_size_positive: point_size > 0 do Result := bitstream_vera_sans_mono_font (point_size, Bold) ensure bitstream_vera_sans_mono_bold_not_void: Result /= Void end bitstream_vera_sans_mono_italic (point_size: INTEGER): EM_TTF_FONT is -- 'bitstream vera sans mono italic' font require point_size_positive: point_size > 0 do Result := bitstream_vera_sans_mono_font (point_size, Italic) ensure bitstream_vera_sans_mono_italic_not_void: Result /= Void end bitstream_vera_sans_mono_bold_italic (point_size: INTEGER): EM_TTF_FONT is -- 'bitstream vera sans mono bold italic' font require point_size_positive: point_size > 0 do Result := bitstream_vera_sans_mono_font (point_size, Bold | Italic) ensure bitstream_vera_sans_mono_bold_italic_not_void: Result /= Void end feature -- Custom fonts load_custom_font (ttf_file: STRING; point_size: INTEGER; id: STRING) is -- Load a font from `ttf_file' with `point_size' size and store it as `id' require ttf_file_not_void: ttf_file /= Void point_size_positive: point_size > 0 id_not_void: id /= Void id_not_taken: not has_custom_font (id) local font: EM_TTF_FONT do create font.make_from_ttf_file (file_system.pathname (font_dirname, ttf_file), point_size) custom_fonts.put (font, id) ensure font_loaded: has_custom_font (id) end custom_font (id: STRING): EM_TTF_FONT is -- Custom font identified by `id' -- The result always exists! If `id' is unknown this feature returns 'bitstream_vera_sans (12)'. require id_not_void: id /= Void do if custom_fonts.has (id) then Result := custom_fonts.item (id) else Result := bitstream_vera_sans (12) end ensure custom_font_not_void: Result /= Void end feature -- Status report font_dirname: STRING is -- Name of font directory; If not specified via `set_font_dirname' defaults to: -- "${EM}/resource/font/ttf/bitstream" 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 has_custom_font (id: STRING): BOOLEAN is -- Does the font identified by `id' exist? require id_not_void: id /= Void do Result := custom_fonts.has (id) 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 {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", "ttf", "bitstream">>) else Result := (".").twin end ensure filename_not_void: Result /= Void end end