indexing description: "[ Factory to create 3d representations of normal fonts. Ensures that only one 3d representation of a given font is created by caching the results. Inherit from EM3D_SHARED_FONT_FACTORY to use this functionality. ]" author: "" date: "$Date$" revision: "$Revision$" class EM3D_FONT_FACTORY create {EM3D_SHARED_FONT_FACTORY} -- Initialization make feature {NONE} -- Initialization make is -- Create new factory do create font_cache.make end feature -- Access last_font: EM3D_FONT -- Last font created feature -- Font creation create_from_ttf (a_ttf_font: EM_TTF_FONT) is -- Create new 3d font from `a_ttf_font' in `last_font' require font_exists: a_ttf_font /= Void do fetch_font (a_ttf_font) if last_font = Void then create {EM3D_TTF_FONT}last_font.make_from_ttf (a_ttf_font) cache_font (a_ttf_font) end ensure result_exists: last_font /= Void end -- create_from_bmp (a_bmp_font: EM_BMP_FONT) is -- -- Create new 3d font from `a_bmp_font' in `last_font' -- require -- font_exists: a_bmp_font /= Void -- local -- em3d_font: EM3 -- do -- fetch_font (a_bmp_font) -- if last_font = Void then -- create {EM3D_BMP_FONT}last_font.make_from_bmp (a_bmp_font) -- cache_font (a_bmp_font) -- end -- ensure -- result_exists: last_font /= Void -- end feature {NONE} -- Implementation fetch_font (a_font: EM_FONT) is -- Search `font_cache' for entry containing `a_font' and -- set `last_font' to either 3d font if found or Void otherwise do last_font := Void from font_cache.start until font_cache.off or last_font /= Void loop if font_cache.item_for_iteration.first = a_font then last_font := font_cache.item_for_iteration.second end font_cache.forth end ensure void_if_not_found: font_cache.off implies last_font = Void end cache_font (a_font: EM_FONT) is -- Add new entry consisting of `a_font' and `last_font' -- to `font_cache' local entry: DS_PAIR [EM_FONT, EM3D_FONT] do create entry.make (a_font, last_font) font_cache.put_first (entry) end font_cache: DS_LINKED_LIST [DS_PAIR [EM_FONT, EM3D_FONT]] -- Cache that stores pairs of normal and 3d fonts -- Unfortunately, EM_FONT is not hashable, and therefore -- DS_HASHTABLE cannot be used end