note description: "[ A font contained inside a custom package file that can be use to draw text with a {TEXT_IMAGE}. ]" author: "Louis Marchand" date: "Mon, 30 Mar 2015 01:06:37 +0000" revision: "2.0" class TEXT_FONT_CPF inherit CPF_RESSOURCE_MANAGER rename make as make_cpf_ressource undefine default_create end TEXT_FONT rename make as make_from_file, make_with_index as make_with_index_from_file redefine open, disable_style_modifier, is_underline, enable_underline, disable_underline, is_bold, enable_bold, disable_bold, is_italic, enable_italic, disable_italic, is_strike_through, enable_strike_through, disable_strike_through, has_outline, outline_size, set_outline_size, disable_outline, has_hinting, disable_hinting, has_normal_hinting, enable_normal_hinting, has_light_hinting, has_monochrome_hinting, enable_light_hinting, enable_monochrome_hinting, is_kerning_enabled, enable_kerning, disable_kerning, maximum_height, ascent, descent, line_skip_height, is_monospace, face_family_name, face_style_name, is_glyph_provided, glyph_metrics, text_dimension, item end create make, make_with_index feature -- Initialisation make (a_cpf: CPF_PACKAGE_FILE; a_cpf_index: INTEGER_32; a_size: INTEGER_32) -- Initialization for Current contained in a_cpf at index -- a_cpf_index and using a_size as Currents size. require font_text_enabled: Text_library.is_text_enable cpf_index_valid: a_cpf.is_readable and then a_cpf_index > 0 and then a_cpf_index <= a_cpf.sub_files_count do make_with_index (a_cpf, a_cpf_index, a_size, 0) end make_with_index (a_cpf: CPF_PACKAGE_FILE; a_cpf_index: INTEGER_32; a_size: INTEGER_32; a_index: INTEGER_32) -- Initialization for Current contained in a_cpf at index -- a_cpf_index and using a_size as Currents size. -- The a_index is use if there is more than one font in a ttf file. require font_text_enabled: Text_library.is_text_enable cpf_index_valid: a_cpf.is_readable and then a_cpf_index > 0 and then a_cpf_index <= a_cpf.sub_files_count do default_create make_cpf_ressource (a_cpf, a_cpf_index) rwop := {GAME_SDL_EXTERNAL}.sdl_allocrw; cpf.lock_mutex; cpf.select_sub_file (cpf_index) {GAME_SDL_EXTERNAL}.setsdlrwops (rwop, cpf.internal_pointer) last_position := cpf.position; cpf.unlock_mutex end feature -- Access open -- Open Current do cpf.lock_mutex; cpf.go (last_position) Precursor {TEXT_FONT} last_position := cpf.position; cpf.unlock_mutex end disable_style_modifier -- Disable all style modifier (underline, bold, italic and strike through) do cpf.lock_mutex; cpf.go (last_position) Precursor {TEXT_FONT} last_position := cpf.position; cpf.unlock_mutex end is_underline: BOOLEAN -- Is Current has an underline style modifier do cpf.lock_mutex; cpf.go (last_position) Result := Precursor {TEXT_FONT} last_position := cpf.position; cpf.unlock_mutex end enable_underline -- Add an underline style modifier to Current do cpf.lock_mutex; cpf.go (last_position) Precursor {TEXT_FONT} last_position := cpf.position; cpf.unlock_mutex end disable_underline -- remove an underline style modifier to Current do cpf.lock_mutex; cpf.go (last_position) Precursor {TEXT_FONT} last_position := cpf.position; cpf.unlock_mutex end is_bold: BOOLEAN -- Is Current has a bold style modifier do cpf.lock_mutex; cpf.go (last_position) Result := Precursor {TEXT_FONT} last_position := cpf.position; cpf.unlock_mutex end enable_bold -- Add a bold style modifier to Current do cpf.lock_mutex; cpf.go (last_position) Precursor {TEXT_FONT} last_position := cpf.position; cpf.unlock_mutex end disable_bold -- remove a bold style modifier to Current do cpf.lock_mutex; cpf.go (last_position) Precursor {TEXT_FONT} last_position := cpf.position; cpf.unlock_mutex end is_italic: BOOLEAN -- Is Current has an italic style modifier do cpf.lock_mutex; cpf.go (last_position) Result := Precursor {TEXT_FONT} last_position := cpf.position; cpf.unlock_mutex end enable_italic -- Add an italic style modifier to Current do cpf.lock_mutex; cpf.go (last_position) Precursor {TEXT_FONT} last_position := cpf.position; cpf.unlock_mutex end disable_italic -- remove an italic style modifier to Current do cpf.lock_mutex; cpf.go (last_position) Precursor {TEXT_FONT} last_position := cpf.position; cpf.unlock_mutex end is_strike_through: BOOLEAN -- Is Current has a strike through style modifier do cpf.lock_mutex; cpf.go (last_position) Result := Precursor {TEXT_FONT} last_position := cpf.position; cpf.unlock_mutex end enable_strike_through -- Add a strike through style modifier to Current do cpf.lock_mutex; cpf.go (last_position) Precursor {TEXT_FONT} last_position := cpf.position; cpf.unlock_mutex end disable_strike_through -- remove a strike through style modifier to Current do cpf.lock_mutex; cpf.go (last_position) Precursor {TEXT_FONT} last_position := cpf.position; cpf.unlock_mutex end has_outline: BOOLEAN -- Is Current has an outline size. do cpf.lock_mutex; cpf.go (last_position) Result := Precursor {TEXT_FONT} last_position := cpf.position; cpf.unlock_mutex end outline_size: INTEGER_32 assign set_outline_size -- The ouline width of Current (0 for disabled) do cpf.lock_mutex; cpf.go (last_position) Result := Precursor {TEXT_FONT} last_position := cpf.position; cpf.unlock_mutex end set_outline_size (a_outline_size: INTEGER_32) -- Assign outline_size with the value of outline_size do cpf.lock_mutex; cpf.go (last_position) Precursor {TEXT_FONT} (a_outline_size) last_position := cpf.position; cpf.unlock_mutex end disable_outline -- Disable the outline size in Current do cpf.lock_mutex; cpf.go (last_position) Precursor {TEXT_FONT} last_position := cpf.position; cpf.unlock_mutex end has_hinting: BOOLEAN -- Has the library a hint about how to draw Current do cpf.lock_mutex; cpf.go (last_position) Result := Precursor {TEXT_FONT} last_position := cpf.position; cpf.unlock_mutex end disable_hinting -- Disable the draw hinting of Current do cpf.lock_mutex; cpf.go (last_position) Precursor {TEXT_FONT} last_position := cpf.position; cpf.unlock_mutex end has_normal_hinting: BOOLEAN -- The library has the normal hinting to draw `Current do cpf.lock_mutex; cpf.go (last_position) Result := Precursor {TEXT_FONT} last_position := cpf.position; cpf.unlock_mutex end enable_normal_hinting -- Use the normal hinting to draw Current do cpf.lock_mutex; cpf.go (last_position) Precursor {TEXT_FONT} last_position := cpf.position; cpf.unlock_mutex end has_light_hinting: BOOLEAN -- The library has the light hinting to draw Current do cpf.lock_mutex; cpf.go (last_position) Result := Precursor {TEXT_FONT} last_position := cpf.position; cpf.unlock_mutex end enable_light_hinting -- Use the light hinting to draw Current do cpf.lock_mutex; cpf.go (last_position) Precursor {TEXT_FONT} last_position := cpf.position; cpf.unlock_mutex end has_monochrome_hinting: BOOLEAN -- The library has the monochrome hinting to draw Current. do cpf.lock_mutex; cpf.go (last_position) Result := Precursor {TEXT_FONT} last_position := cpf.position; cpf.unlock_mutex end enable_monochrome_hinting -- Use the monochrome hinting to draw Current. -- Must only be use with monochrome display do cpf.lock_mutex; cpf.go (last_position) Precursor {TEXT_FONT} last_position := cpf.position; cpf.unlock_mutex end is_kerning_enabled: BOOLEAN -- If True, the library can use kerning when drawing a text with Current do cpf.lock_mutex; cpf.go (last_position) Result := Precursor {TEXT_FONT} last_position := cpf.position; cpf.unlock_mutex end enable_kerning -- Allow the library to use kerning when drawing a text with Current do cpf.lock_mutex; cpf.go (last_position) Precursor {TEXT_FONT} last_position := cpf.position; cpf.unlock_mutex end disable_kerning -- Does not allow the library to use kerning when drawing a text with Current do cpf.lock_mutex; cpf.go (last_position) Precursor {TEXT_FONT} last_position := cpf.position; cpf.unlock_mutex end maximum_height: INTEGER_32 -- The maximum height that a gliph can take in pixel using Current do cpf.lock_mutex; cpf.go (last_position) Result := Precursor {TEXT_FONT} last_position := cpf.position; cpf.unlock_mutex end ascent: INTEGER_32 -- distance from the top of the drawing area to the baseline in pixel. do cpf.lock_mutex; cpf.go (last_position) Result := Precursor {TEXT_FONT} last_position := cpf.position; cpf.unlock_mutex end descent: INTEGER_32 -- distance from the baseline to the bottom of the drawing area in pixel. do cpf.lock_mutex; cpf.go (last_position) Result := Precursor {TEXT_FONT} last_position := cpf.position; cpf.unlock_mutex end line_skip_height: INTEGER_32 -- the recommended pixel height of a rendered line of text using Current do cpf.lock_mutex; cpf.go (last_position) Result := Precursor {TEXT_FONT} last_position := cpf.position; cpf.unlock_mutex end is_monospace: BOOLEAN -- True if every character that exists in Current is the same width do cpf.lock_mutex; cpf.go (last_position) Result := Precursor {TEXT_FONT} last_position := cpf.position; cpf.unlock_mutex end face_family_name: READABLE_STRING_GENERAL -- The name of the face family of Curent do cpf.lock_mutex; cpf.go (last_position) Result := Precursor {TEXT_FONT} last_position := cpf.position; cpf.unlock_mutex end face_style_name: READABLE_STRING_GENERAL -- The name of the face style of Curent do cpf.lock_mutex; cpf.go (last_position) Result := Precursor {TEXT_FONT} last_position := cpf.position; cpf.unlock_mutex end is_glyph_provided (a_character: CHARACTER_32): BOOLEAN -- Is Current can draw a glyph representing a_character do cpf.lock_mutex; cpf.go (last_position) Result := Precursor {TEXT_FONT} (a_character) last_position := cpf.position; cpf.unlock_mutex end glyph_metrics (a_character: CHARACTER_32): TUPLE [minimal_x: INTEGER_32; maximal_x: INTEGER_32; minimal_y: INTEGER_32; maximal_y: INTEGER_32; advance: INTEGER_32] -- The informations about the glyph representing a_character generated with Current. -- Set has_error on error. do cpf.lock_mutex; cpf.go (last_position) Result := Precursor {TEXT_FONT} (a_character) last_position := cpf.position; cpf.unlock_mutex end text_dimension (a_text: READABLE_STRING_GENERAL): TUPLE [width: INTEGER_32; height: INTEGER_32] -- The dimension of the a_text drawed with Current do cpf.lock_mutex; cpf.go (last_position) Result := Precursor {TEXT_FONT} (a_text) last_position := cpf.position; cpf.unlock_mutex end feature {GAME_SDL_ANY} -- Implementation lock_cpf_mutex -- Lock the mutex of the CPF so that no object -- can modify the CPF. Must used unlock_cpf_mutex -- After the operation is done. If not, the -- application may deadlock do cpf.lock_mutex end unlock_cpf_mutex -- Unlock the mutex of the CPF. Must be used after -- a lock_cpf_mutex. If not, the application may -- deadlock do cpf.unlock_mutex end item: POINTER -- Access to memory area. -- Note that you must call lock_cpf_mutex before using -- this routine and using unlock_cpf_mutex after do cpf.select_sub_file (cpf_index); cpf.go (last_position) Result := Precursor {TEXT_FONT} last_position := cpf.position end feature {NONE} -- Implementation - Variables last_position: INTEGER_32 -- The last known position inside the CPF used in that object. end -- class TEXT_FONT_CPF
Generated by ISE EiffelStudio