indexing description: "Objects that project EV_FIGURE_WORLDs to an SVG file or string" keywords: SVG, Vision2, projector, "vector graphics" author: "Colin Adams" copyright: "Copyright (c) Barr Rosenberg Reasearch Center LLC 2008" license: "GNU General Public License version 3 (see gpl-3.0.txt)" class SV_PROJECTOR inherit EV_MODEL_PROJECTOR EV_MODEL_DRAWER redefine drawable, offset_x, offset_y end EV_MODEL_PROJECTION_ROUTINES create make, make_with_filename feature {NONE} -- Initialization make (a_world: EV_MODEL_WORLD; a_serializer: SV_XML_SERIALIZER) is -- Initialize for projecting to a string. require a_world_not_void: a_world /= Void a_serializer_not_void: a_serializer /= Void do initialize (a_world, a_serializer) ensure file_name_void: file_name = Void serializer_set: serializer = a_serializer end make_with_filename (a_world: EV_MODEL_WORLD; a_file_name: FILE_NAME; a_serializer: SV_XML_SERIALIZER) is -- Initialize for projecting to `a_file_name'. require a_world_not_void: a_world /= Void a_file_name_not_void: a_file_name /= Void a_serializer_not_void: a_serializer /= Void do initialize (a_world, a_serializer) create file_name.make file_name.set_file_name (a_file_name) ensure file_name_not_void: file_name /= Void serializer_set: serializer = a_serializer end initialize (a_world: EV_MODEL_WORLD; a_serializer: SV_XML_SERIALIZER) is -- Perform common initialization. require a_world_not_void: a_world /= Void a_serializer_not_void: a_serializer /= Void do serializer := a_serializer create draw_routines.make (0, 20) make_with_world (a_world) register_basic_figures create drawable ensure serializer_set: serializer = a_serializer end feature -- Access offset_x: INTEGER -- Offset to right in pixels (in user coordinates in generated SVG) for drawing area offset_y: INTEGER -- Offset to bottom in pixels (to top in user coordinates in generated SVG) for drawing area serializer: SV_XML_SERIALIZER -- XML serializer used by SV_DRAWABLE_IMP string: STRING is -- Projected SVG do Result := drawable.svg_text (serializer) ensure string_not_void: Result /= Void end svg_prefix: STRING is -- Optional prefix for elements in SVG namespace do Result := drawable.svg_prefix end document: XM_DOCUMENT is -- Projected SVG do Result := drawable.document ensure document_not_void: Result /= Void end feature -- Status report indenting: BOOLEAN is -- Will the serializer indent the XML? do Result := drawable.indenting end omitting_xml_declaration: BOOLEAN is -- Will the serializer omit the XML declaration? do Result := drawable.omitting_xml_declaration end wants_doctype: BOOLEAN is -- Does the user want a DOCTYPE to be emitted? do Result := drawable.wants_doctype end uses_default_aspect_ratio: BOOLEAN is -- Does the user want the "preserveAspectRatio" attribute to be omitted? do Result := drawable.uses_default_aspect_ratio end aspect_ratio: STRING is -- Value of "preserveAspectRatio" attribute to be generated; -- Only applicable if `uses_default_aspect_ratio' is `False'. -- If `Void', then a value of "none" is used. do Result := drawable.aspect_ratio end feature -- Setting set_svg_prefix (a_prefix: STRING) is -- Set prefix to use for SVG namespace. -- WARNING: call zero or one times, and do not call after `set_size' or any drawing operation. require a_prefix_not_void: a_prefix /= Void a_prefix_not_empty: not a_prefix.is_empty do drawable.set_svg_prefix (a_prefix) ensure svg_prefix_set: svg_prefix = a_prefix end set_indenting (a_indenting: BOOLEAN) is -- Set `indenting' to `a_indenting'. do drawable.set_indenting (a_indenting) ensure indenting_set: indenting = a_indenting end set_omitting_xml_declaration (a_omitting: BOOLEAN) is -- Set `omitting_xml_declaration' to `a_omitting'. do drawable.set_omitting_xml_declaration (a_omitting) ensure omitting_xml_declaration_set: omitting_xml_declaration = a_omitting end set_wants_doctype (a_status: BOOLEAN) is -- Set `wants_doctype' to `a_status'. do drawable.set_wants_doctype (a_status) ensure wants_doctype_set: wants_doctype = a_status end use_default_aspect_ratio (a_status: BOOLEAN) is -- Do not generate a "preserveAspectRatio" attribute if `a_status' = `True'. -- By default, a preserveAspectRatio="none" attribute is generated. do drawable.use_default_aspect_ratio (a_status) ensure default_aspect_ratio_used: uses_default_aspect_ratio = a_status end set_aspect_ratio (a_aspect_ratio: STRING) is -- Generate a preserveAspectRatio="`a_aspect_ratio'" attribute. require a_aspect_ratio_not_void: a_aspect_ratio /= Void do drawable.set_aspect_ratio (a_aspect_ratio) ensure aspect_ratio_set: aspect_ratio = a_aspect_ratio end feature -- Basic operations project is -- Make standard projection of world on device. local l_bbox: EV_RECTANGLE l_wx, l_wy: INTEGER do if not is_projecting then is_projecting := True world.invalidate l_bbox := world.bounding_box l_wx := l_bbox.left l_wy := l_bbox.top offset_x := -l_wx offset_y := -l_wy drawable.set_size (l_bbox.right - l_wx, l_bbox.bottom - l_wy) drawable.clear -- Full projection. if world.grid_visible then draw_grid end if world.is_show_requested then project_figure_group_full (world) end if file_name /= Void then drawable.save_to_named_file (file_name, serializer, True) else drawable.optimize_svg_file_size end end is_projecting := False end feature {NONE} -- Implementation file_name: FILE_NAME -- Name of optional target file drawable: SV_DRAWABLE -- Drawable used to draw the figures. invariant draw_routines_not_void: draw_routines /= Void drawable_not_void: drawable /= Void serializer_not_void: serializer /= Void end