diff --git a/lib/Slic3r.pm b/lib/Slic3r.pm index 30d516217..e55e24a7a 100644 --- a/lib/Slic3r.pm +++ b/lib/Slic3r.pm @@ -43,6 +43,7 @@ use FindBin; # Let the XS module know where the GUI resources reside. set_resources_dir(decode_path($FindBin::Bin) . (($^O eq 'darwin') ? '/../Resources' : '/resources')); set_var_dir(resources_dir() . "/icons"); +set_local_dir(resources_dir() . "/localization/"); use Moo 1.003001; diff --git a/lib/Slic3r/GUI.pm b/lib/Slic3r/GUI.pm index 5d6d8e4a6..0b4f9743a 100644 --- a/lib/Slic3r/GUI.pm +++ b/lib/Slic3r/GUI.pm @@ -8,7 +8,6 @@ use FindBin; use List::Util qw(first); use Slic3r::GUI::2DBed; use Slic3r::GUI::AboutDialog; -use Slic3r::GUI::BedShapeDialog; use Slic3r::GUI::BonjourBrowser; use Slic3r::GUI::ConfigWizard; use Slic3r::GUI::Controller; @@ -31,7 +30,6 @@ use Slic3r::GUI::ProgressStatusBar; use Slic3r::GUI::OptionsGroup; use Slic3r::GUI::OptionsGroup::Field; use Slic3r::GUI::SystemInfo; -use Slic3r::GUI::Tab; our $have_OpenGL = eval "use Slic3r::GUI::3DScene; 1"; our $have_LWP = eval "use LWP::UserAgent; 1"; @@ -41,16 +39,17 @@ use Wx::Event qw(EVT_IDLE EVT_COMMAND EVT_MENU); use base 'Wx::App'; use constant FILE_WILDCARDS => { - known => 'Known files (*.stl, *.obj, *.amf, *.xml, *.prusa)|*.stl;*.STL;*.obj;*.OBJ;*.amf;*.AMF;*.xml;*.XML;*.prusa;*.PRUSA', + known => 'Known files (*.stl, *.obj, *.amf, *.xml, *.3mf, *.prusa)|*.stl;*.STL;*.obj;*.OBJ;*.amf;*.AMF;*.xml;*.XML;*.3mf;*.3MF;*.prusa;*.PRUSA', stl => 'STL files (*.stl)|*.stl;*.STL', obj => 'OBJ files (*.obj)|*.obj;*.OBJ', amf => 'AMF files (*.amf)|*.amf;*.AMF;*.xml;*.XML', + threemf => '3MF files (*.3mf)|*.3mf;*.3MF', prusa => 'Prusa Control files (*.prusa)|*.prusa;*.PRUSA', ini => 'INI files *.ini|*.ini;*.INI', gcode => 'G-code files (*.gcode, *.gco, *.g, *.ngc)|*.gcode;*.GCODE;*.gco;*.GCO;*.g;*.G;*.ngc;*.NGC', svg => 'SVG files *.svg|*.svg;*.SVG', }; -use constant MODEL_WILDCARD => join '|', @{&FILE_WILDCARDS}{qw(known stl obj amf prusa)}; +use constant MODEL_WILDCARD => join '|', @{&FILE_WILDCARDS}{qw(known stl obj amf threemf prusa)}; # Datadir provided on the command line. our $datadir; @@ -67,6 +66,10 @@ our $medium_font = Wx::SystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT); $medium_font->SetPointSize(12); our $grey = Wx::Colour->new(200,200,200); +# Events to be sent from a C++ menu implementation: +# 1) To inform about a change of the application language. +our $LANGUAGE_CHANGE_EVENT = Wx::NewEventType; + sub OnInit { my ($self) = @_; @@ -80,6 +83,7 @@ sub OnInit { # Mac: "~/Library/Application Support/Slic3r" Slic3r::set_data_dir($datadir || Wx::StandardPaths::Get->GetUserDataDir); Slic3r::GUI::set_wxapp($self); + Slic3r::GUI::load_language(); $self->{notifier} = Slic3r::GUI::Notifier->new; $self->{app_config} = Slic3r::GUI::AppConfig->new; @@ -114,10 +118,12 @@ sub OnInit { # If set, the "Controller" tab for the control of the printer over serial line and the serial port settings are hidden. no_controller => $self->{app_config}->get('no_controller'), no_plater => $no_plater, + lang_ch_event => $LANGUAGE_CHANGE_EVENT, ); $self->SetTopWindow($frame); - EVT_IDLE($frame, sub { + #EVT_IDLE($frame, sub { + EVT_IDLE($self->{mainframe}, sub { while (my $cb = shift @cb) { $cb->(); } @@ -132,10 +138,42 @@ sub OnInit { $self->{mainframe}->config_wizard(1); }); } + + # The following event is emited by the C++ menu implementation of application language change. + EVT_COMMAND($self, -1, $LANGUAGE_CHANGE_EVENT, sub{ + $self->recreate_GUI; + }); return 1; } +sub recreate_GUI{ + my ($self) = @_; + my $topwindow = $self->GetTopWindow(); + $self->{mainframe} = my $frame = Slic3r::GUI::MainFrame->new( + # If set, the "Controller" tab for the control of the printer over serial line and the serial port settings are hidden. + no_controller => $self->{app_config}->get('no_controller'), + no_plater => $no_plater, + lang_ch_event => $LANGUAGE_CHANGE_EVENT, + ); + + if($topwindow) + { + $self->SetTopWindow($frame); + $topwindow->Destroy; + } + + my $run_wizard = 1 if $self->{preset_bundle}->has_defauls_only; + if ($run_wizard) { + # On OSX the UI was not initialized correctly if the wizard was called + # before the UI was up and running. + $self->CallAfter(sub { + # Run the config wizard, don't offer the "reset user profile" checkbox. + $self->{mainframe}->config_wizard(1); + }); + } +} + sub about { my ($self) = @_; my $about = Slic3r::GUI::AboutDialog->new(undef); diff --git a/lib/Slic3r/GUI/3DScene.pm b/lib/Slic3r/GUI/3DScene.pm index 03055a582..4ca5b4188 100644 --- a/lib/Slic3r/GUI/3DScene.pm +++ b/lib/Slic3r/GUI/3DScene.pm @@ -1602,7 +1602,8 @@ sub draw_legend { if ($self->_legend_enabled) { - my $tex_id = Slic3r::GUI::_3DScene::get_legend_texture_id; + # If the legend texture has not been loaded into the GPU, do it now. + my $tex_id = Slic3r::GUI::_3DScene::finalize_legend_texture; if ($tex_id > 0) { my $tex_w = Slic3r::GUI::_3DScene::get_legend_texture_width; diff --git a/lib/Slic3r/GUI/BedShapeDialog.pm b/lib/Slic3r/GUI/BedShapeDialog.pm deleted file mode 100644 index 70c8e0256..000000000 --- a/lib/Slic3r/GUI/BedShapeDialog.pm +++ /dev/null @@ -1,316 +0,0 @@ -# The bed shape dialog. -# The dialog opens from Print Settins tab -> Bed Shape: Set... - -package Slic3r::GUI::BedShapeDialog; -use strict; -use warnings; -use utf8; - -use List::Util qw(min max); -use Slic3r::Geometry qw(X Y unscale); -use Wx qw(:dialog :id :misc :sizer :choicebook wxTAB_TRAVERSAL); -use Wx::Event qw(EVT_CLOSE); -use base 'Wx::Dialog'; - -sub new { - my $class = shift; - my ($parent, $default) = @_; - my $self = $class->SUPER::new($parent, -1, "Bed Shape", wxDefaultPosition, [350,700], wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER); - - $self->{panel} = my $panel = Slic3r::GUI::BedShapePanel->new($self, $default); - - my $main_sizer = Wx::BoxSizer->new(wxVERTICAL); - $main_sizer->Add($panel, 1, wxEXPAND); - $main_sizer->Add($self->CreateButtonSizer(wxOK | wxCANCEL), 0, wxEXPAND); - - $self->SetSizer($main_sizer); - $self->SetMinSize($self->GetSize); - $main_sizer->SetSizeHints($self); - - # needed to actually free memory - EVT_CLOSE($self, sub { - $self->EndModal(wxID_OK); - $self->Destroy; - }); - - return $self; -} - -sub GetValue { - my ($self) = @_; - return $self->{panel}->GetValue; -} - -package Slic3r::GUI::BedShapePanel; - -use List::Util qw(min max sum first); -use Scalar::Util qw(looks_like_number); -use Slic3r::Geometry qw(PI X Y unscale scaled_epsilon); -use Wx qw(:font :id :misc :sizer :choicebook :filedialog :pen :brush wxTAB_TRAVERSAL); -use Wx::Event qw(EVT_CLOSE EVT_CHOICEBOOK_PAGE_CHANGED EVT_BUTTON); -use base 'Wx::Panel'; - -use constant SHAPE_RECTANGULAR => 0; -use constant SHAPE_CIRCULAR => 1; -use constant SHAPE_CUSTOM => 2; - -sub new { - my $class = shift; - my ($parent, $default) = @_; - my $self = $class->SUPER::new($parent, -1); - - $self->on_change(undef); - - my $box = Wx::StaticBox->new($self, -1, "Shape"); - my $sbsizer = Wx::StaticBoxSizer->new($box, wxVERTICAL); - - # shape options - $self->{shape_options_book} = Wx::Choicebook->new($self, -1, wxDefaultPosition, [300,-1], wxCHB_TOP); - $sbsizer->Add($self->{shape_options_book}); - - $self->{optgroups} = []; - { - my $optgroup = $self->_init_shape_options_page('Rectangular'); - $optgroup->append_single_option_line(Slic3r::GUI::OptionsGroup::Option->new( - opt_id => 'rect_size', - type => 'point', - label => 'Size', - tooltip => 'Size in X and Y of the rectangular plate.', - default => [200,200], - )); - $optgroup->append_single_option_line(Slic3r::GUI::OptionsGroup::Option->new( - opt_id => 'rect_origin', - type => 'point', - label => 'Origin', - tooltip => 'Distance of the 0,0 G-code coordinate from the front left corner of the rectangle.', - default => [0,0], - )); - } - { - my $optgroup = $self->_init_shape_options_page('Circular'); - $optgroup->append_single_option_line(Slic3r::GUI::OptionsGroup::Option->new( - opt_id => 'diameter', - type => 'f', - label => 'Diameter', - tooltip => 'Diameter of the print bed. It is assumed that origin (0,0) is located in the center.', - sidetext => 'mm', - default => 200, - )); - } - { - my $optgroup = $self->_init_shape_options_page('Custom'); - $optgroup->append_line(Slic3r::GUI::OptionsGroup::Line->new( - full_width => 1, - widget => sub { - my ($parent) = @_; - - my $btn = Wx::Button->new($parent, -1, "Load shape from STL...", wxDefaultPosition, wxDefaultSize); - EVT_BUTTON($self, $btn, sub { $self->_load_stl }); - return $btn; - } - )); - } - - EVT_CHOICEBOOK_PAGE_CHANGED($self, -1, sub { - $self->_update_shape; - }); - - # right pane with preview canvas - my $canvas = $self->{canvas} = Slic3r::GUI::2DBed->new($self); - - # main sizer - my $top_sizer = Wx::BoxSizer->new(wxHORIZONTAL); - $top_sizer->Add($sbsizer, 0, wxEXPAND | wxTOP | wxBOTTOM, 10); - $top_sizer->Add($canvas, 1, wxEXPAND | wxALL, 10) if $canvas; - - $self->SetSizerAndFit($top_sizer); - - $self->_set_shape($default); - $self->_update_preview; - - return $self; -} - -sub on_change { - my ($self, $cb) = @_; - $self->{on_change} = $cb // sub {}; -} - -# Called from the constructor. -# Set the initial bed shape from a list of points. -# Deduce the bed shape type (rect, circle, custom) -# This routine shall be smart enough if the user messes up -# with the list of points in the ini file directly. -sub _set_shape { - my ($self, $points) = @_; - - # is this a rectangle? - if (@$points == 4) { - my $polygon = Slic3r::Polygon->new_scale(@$points); - my $lines = $polygon->lines; - if ($lines->[0]->parallel_to_line($lines->[2]) && $lines->[1]->parallel_to_line($lines->[3])) { - # okay, it's a rectangle - - # find origin - # the || 0 hack prevents "-0" which might confuse the user - my $x_min = min(map $_->[X], @$points) || 0; - my $x_max = max(map $_->[X], @$points) || 0; - my $y_min = min(map $_->[Y], @$points) || 0; - my $y_max = max(map $_->[Y], @$points) || 0; - my $origin = [-$x_min, -$y_min]; - - $self->{shape_options_book}->SetSelection(SHAPE_RECTANGULAR); - my $optgroup = $self->{optgroups}[SHAPE_RECTANGULAR]; - $optgroup->set_value('rect_size', [ $x_max-$x_min, $y_max-$y_min ]); - $optgroup->set_value('rect_origin', $origin); - $self->_update_shape; - return; - } - } - - # is this a circle? - { - # Analyze the array of points. Do they reside on a circle? - my $polygon = Slic3r::Polygon->new_scale(@$points); - my $center = $polygon->bounding_box->center; - my @vertex_distances = map $center->distance_to($_), @$polygon; - my $avg_dist = sum(@vertex_distances)/@vertex_distances; - if (!defined first { abs($_ - $avg_dist) > 10*scaled_epsilon } @vertex_distances) { - # all vertices are equidistant to center - $self->{shape_options_book}->SetSelection(SHAPE_CIRCULAR); - my $optgroup = $self->{optgroups}[SHAPE_CIRCULAR]; - $optgroup->set_value('diameter', sprintf("%.0f", unscale($avg_dist*2))); - $self->_update_shape; - return; - } - } - - if (@$points < 3) { - # Invalid polygon. Revert to default bed dimensions. - $self->{shape_options_book}->SetSelection(SHAPE_RECTANGULAR); - my $optgroup = $self->{optgroups}[SHAPE_RECTANGULAR]; - $optgroup->set_value('rect_size', [200, 200]); - $optgroup->set_value('rect_origin', [0, 0]); - $self->_update_shape; - return; - } - - # This is a custom bed shape, use the polygon provided. - $self->{shape_options_book}->SetSelection(SHAPE_CUSTOM); - # Copy the polygon to the canvas, make a copy of the array. - $self->{canvas}->bed_shape([@$points]); - $self->_update_shape; -} - -# Update the bed shape from the dialog fields. -sub _update_shape { - my ($self) = @_; - - my $page_idx = $self->{shape_options_book}->GetSelection; - if ($page_idx == SHAPE_RECTANGULAR) { - my $rect_size = $self->{optgroups}[SHAPE_RECTANGULAR]->get_value('rect_size'); - my $rect_origin = $self->{optgroups}[SHAPE_RECTANGULAR]->get_value('rect_origin'); - my ($x, $y) = @$rect_size; - return if !looks_like_number($x) || !looks_like_number($y); # empty strings or '-' or other things - return if !$x || !$y or $x == 0 or $y == 0; - my ($x0, $y0) = (0,0); - my ($x1, $y1) = ($x ,$y); - { - my ($dx, $dy) = @$rect_origin; - return if !looks_like_number($dx) || !looks_like_number($dy); # empty strings or '-' or other things - $x0 -= $dx; - $x1 -= $dx; - $y0 -= $dy; - $y1 -= $dy; - } - $self->{canvas}->bed_shape([ - [$x0,$y0], - [$x1,$y0], - [$x1,$y1], - [$x0,$y1], - ]); - } elsif ($page_idx == SHAPE_CIRCULAR) { - my $diameter = $self->{optgroups}[SHAPE_CIRCULAR]->get_value('diameter'); - return if !$diameter or $diameter == 0; - my $r = $diameter/2; - my $twopi = 2*PI; - my $edges = 60; - my $polygon = Slic3r::Polygon->new_scale( - map [ $r * cos $_, $r * sin $_ ], - map { $twopi/$edges*$_ } 1..$edges - ); - $self->{canvas}->bed_shape([ - map [ unscale($_->x), unscale($_->y) ], @$polygon #)) - ]); - } - - $self->{on_change}->(); - $self->_update_preview; -} - -sub _update_preview { - my ($self) = @_; - $self->{canvas}->Refresh if $self->{canvas}; - $self->Refresh; -} - -# Called from the constructor. -# Create a panel for a rectangular / circular / custom bed shape. -sub _init_shape_options_page { - my ($self, $title) = @_; - - my $panel = Wx::Panel->new($self->{shape_options_book}); - my $optgroup; - push @{$self->{optgroups}}, $optgroup = Slic3r::GUI::OptionsGroup->new( - parent => $panel, - title => 'Settings', - label_width => 100, - on_change => sub { - my ($opt_id) = @_; - #$self->{"_$opt_id"} = $optgroup->get_value($opt_id); - $self->_update_shape; - }, - ); - $panel->SetSizerAndFit($optgroup->sizer); - $self->{shape_options_book}->AddPage($panel, $title); - - return $optgroup; -} - -# Loads an stl file, projects it to the XY plane and calculates a polygon. -sub _load_stl { - my ($self) = @_; - - my $dialog = Wx::FileDialog->new($self, 'Choose a file to import bed shape from (STL/OBJ/AMF/PRUSA):', "", "", &Slic3r::GUI::MODEL_WILDCARD, wxFD_OPEN | wxFD_FILE_MUST_EXIST); - if ($dialog->ShowModal != wxID_OK) { - $dialog->Destroy; - return; - } - my $input_file = $dialog->GetPaths; - $dialog->Destroy; - - my $model = Slic3r::Model->read_from_file($input_file); - my $mesh = $model->mesh; - my $expolygons = $mesh->horizontal_projection; - - if (@$expolygons == 0) { - Slic3r::GUI::show_error($self, "The selected file contains no geometry."); - return; - } - if (@$expolygons > 1) { - Slic3r::GUI::show_error($self, "The selected file contains several disjoint areas. This is not supported."); - return; - } - - my $polygon = $expolygons->[0]->contour; - $self->{canvas}->bed_shape([ map [ unscale($_->x), unscale($_->y) ], @$polygon ]); - $self->_update_preview(); -} - -# Returns the resulting bed shape polygon. This value will be stored to the ini file. -sub GetValue { - my ($self) = @_; - return $self->{canvas}->bed_shape; -} - -1; diff --git a/lib/Slic3r/GUI/MainFrame.pm b/lib/Slic3r/GUI/MainFrame.pm index c91c59ea7..a3ebea0b8 100644 --- a/lib/Slic3r/GUI/MainFrame.pm +++ b/lib/Slic3r/GUI/MainFrame.pm @@ -11,13 +11,23 @@ use List::Util qw(min first); use Slic3r::Geometry qw(X Y); use Wx qw(:frame :bitmap :id :misc :notebook :panel :sizer :menu :dialog :filedialog :font :icon wxTheApp); -use Wx::Event qw(EVT_CLOSE EVT_MENU EVT_NOTEBOOK_PAGE_CHANGED); +use Wx::Event qw(EVT_CLOSE EVT_COMMAND EVT_MENU EVT_NOTEBOOK_PAGE_CHANGED); use base 'Wx::Frame'; our $qs_last_input_file; our $qs_last_output_file; our $last_config; +# Events to be sent from a C++ Tab implementation: +# 1) To inform about a change of a configuration value. +our $VALUE_CHANGE_EVENT = Wx::NewEventType; +# 2) To inform about a preset selection change or a "modified" status change. +our $PRESETS_CHANGED_EVENT = Wx::NewEventType; +# 3) To inform about a click on Browse button +our $BUTTON_BROWSE_EVENT = Wx::NewEventType; +# 4) To inform about a click on Test button +our $BUTTON_TEST_EVENT = Wx::NewEventType; + sub new { my ($class, %params) = @_; @@ -37,6 +47,7 @@ sub new { $self->{no_controller} = $params{no_controller}; $self->{no_plater} = $params{no_plater}; $self->{loaded} = 0; + $self->{lang_ch_event} = $params{lang_ch_event}; # initialize tabpanel and menubar $self->_init_tabpanel; @@ -106,33 +117,41 @@ sub _init_tabpanel { $panel->AddPage($self->{controller} = Slic3r::GUI::Controller->new($panel), "Controller"); } } - $self->{options_tabs} = {}; - for my $tab_name (qw(print filament printer)) { - my $tab; - $tab = $self->{options_tabs}{$tab_name} = ("Slic3r::GUI::Tab::" . ucfirst $tab_name)->new( - $panel, - no_controller => $self->{no_controller}); - # Callback to be executed after any of the configuration fields (Perl class Slic3r::GUI::OptionsGroup::Field) change their value. - $tab->on_value_change(sub { - my ($opt_key, $value) = @_; - my $config = $tab->{presets}->get_current_preset->config; - if ($self->{plater}) { - $self->{plater}->on_config_change($config); # propagate config change events to the plater - $self->{plater}->on_extruders_change($value) if $opt_key eq 'extruders_count'; + #TODO this is an example of a Slic3r XS interface call to add a new preset editor page to the main view. + # The following event is emited by the C++ Tab implementation on config value change. + EVT_COMMAND($self, -1, $VALUE_CHANGE_EVENT, sub { + my ($self, $event) = @_; + my $str = $event->GetString; + my ($opt_key, $name) = ($str =~ /(.*) (.*)/); + #print "VALUE_CHANGE_EVENT: ", $opt_key, "\n"; + my $tab = Slic3r::GUI::get_preset_tab($name); + my $config = $tab->get_config; + if ($self->{plater}) { + $self->{plater}->on_config_change($config); # propagate config change events to the plater + if ($opt_key eq 'extruders_count'){ + my $value = $event->GetInt(); + $self->{plater}->on_extruders_change($value); } - # don't save while loading for the first time - $self->config->save($Slic3r::GUI::autosave) if $Slic3r::GUI::autosave && $self->{loaded}; - }); - # Install a callback for the tab to update the platter and print controller presets, when - # a preset changes at Slic3r::GUI::Tab. - $tab->on_presets_changed(sub { - if ($self->{plater}) { - # Update preset combo boxes (Print settings, Filament, Printer) from their respective tabs. - $self->{plater}->update_presets($tab_name, @_); + } + # don't save while loading for the first time + $self->config->save($Slic3r::GUI::autosave) if $Slic3r::GUI::autosave && $self->{loaded}; + }); + # The following event is emited by the C++ Tab implementation on preset selection, + # or when the preset's "modified" status changes. + EVT_COMMAND($self, -1, $PRESETS_CHANGED_EVENT, sub { + my ($self, $event) = @_; + my $tab_name = $event->GetString; + + my $tab = Slic3r::GUI::get_preset_tab($tab_name); + if ($self->{plater}) { + # Update preset combo boxes (Print settings, Filament, Printer) from their respective tabs. + my $presets = $tab->get_presets; + if (defined $presets){ + my $reload_dependent_tabs = $tab->get_dependent_tabs; + $self->{plater}->update_presets($tab_name, $reload_dependent_tabs, $presets); if ($tab_name eq 'printer') { # Printer selected at the Printer tab, update "compatible" marks at the print and filament selectors. - my ($presets, $reload_dependent_tabs) = @_; for my $tab_name_other (qw(print filament)) { # If the printer tells us that the print or filament preset has been switched or invalidated, # refresh the print or filament tab page. Otherwise just refresh the combo box. @@ -141,23 +160,76 @@ sub _init_tabpanel { $self->{options_tabs}{$tab_name_other}->$update_action; } # Update the controller printers. - $self->{controller}->update_presets(@_) if $self->{controller}; + $self->{controller}->update_presets($presets) if $self->{controller}; } - $self->{plater}->on_config_change($tab->{presets}->get_current_preset->config); + $self->{plater}->on_config_change($tab->get_config); } - }); - # Load the currently selected preset into the GUI, update the preset selection box. - $tab->load_current_preset; - $panel->AddPage($tab, $tab->title); - } + } + }); + # The following event is emited by the C++ Tab implementation , + # when the Browse button was clicked + EVT_COMMAND($self, -1, $BUTTON_BROWSE_EVENT, sub { + my ($self, $event) = @_; + my $msg = $event->GetString; + print "BUTTON_BROWSE_EVENT: ", $msg, "\n"; -#TODO this is an example of a Slic3r XS interface call to add a new preset editor page to the main view. -# Slic3r::GUI::create_preset_tab("print"); + # look for devices + my $entries; + { + my $res = Net::Bonjour->new('http'); + $res->discover; + $entries = [ $res->entries ]; + } + if (@{$entries}) { + my $dlg = Slic3r::GUI::BonjourBrowser->new($self, $entries); + my $tab = Slic3r::GUI::get_preset_tab("printer"); + $tab->load_key_value('octoprint_host', $dlg->GetValue . ":" . $dlg->GetPort) + if $dlg->ShowModal == wxID_OK; + } else { + Wx::MessageDialog->new($self, 'No Bonjour device found', 'Device Browser', wxOK | wxICON_INFORMATION)->ShowModal; + } + }); + # The following event is emited by the C++ Tab implementation , + # when the Test button was clicked + EVT_COMMAND($self, -1, $BUTTON_TEST_EVENT, sub { + my ($self, $event) = @_; + my $msg = $event->GetString; + print "BUTTON_TEST_EVENT: ", $msg, "\n"; + + my $ua = LWP::UserAgent->new; + $ua->timeout(10); + + my $config = Slic3r::GUI::get_preset_tab("printer")->get_config; + my $res = $ua->get( + "http://" . $config->octoprint_host . "/api/version", + 'X-Api-Key' => $config->octoprint_apikey, + ); + if ($res->is_success) { + Slic3r::GUI::show_info($self, "Connection to OctoPrint works correctly.", "Success!"); + } else { + Slic3r::GUI::show_error($self, + "I wasn't able to connect to OctoPrint (" . $res->status_line . "). " + . "Check hostname and OctoPrint version (at least 1.1.0 is required)."); + } + }); + # A variable to inform C++ Tab implementation about disabling of Browse button + $self->{is_disabled_button_browse} = (!eval "use Net::Bonjour; 1") ? 1 : 0 ; + # A variable to inform C++ Tab implementation about user_agent + $self->{is_user_agent} = (eval "use LWP::UserAgent; 1") ? 1 : 0 ; + Slic3r::GUI::create_preset_tabs(wxTheApp->{preset_bundle}, wxTheApp->{app_config}, + $self->{no_controller}, $self->{is_disabled_button_browse}, + $self->{is_user_agent}, + $VALUE_CHANGE_EVENT, $PRESETS_CHANGED_EVENT, + $BUTTON_BROWSE_EVENT, $BUTTON_TEST_EVENT); + $self->{options_tabs} = {}; + for my $tab_name (qw(print filament printer)) { + $self->{options_tabs}{$tab_name} = Slic3r::GUI::get_preset_tab("$tab_name"); + } if ($self->{plater}) { $self->{plater}->on_select_preset(sub { my ($group, $name) = @_; - $self->{options_tabs}{$group}->select_preset($name); + $self->{options_tabs}{$group}->select_preset($name); }); # load initial config my $full_config = wxTheApp->{preset_bundle}->full_config; @@ -244,6 +316,9 @@ sub _init_menubar { $self->_append_menu_item($self->{plater_menu}, "Export plate as AMF...", 'Export current plate as AMF', sub { $plater->export_amf; }, undef, 'brick_go.png'); + $self->_append_menu_item($self->{plater_menu}, "Export plate as 3MF...", 'Export current plate as 3MF', sub { + $plater->export_3mf; + }, undef, 'brick_go.png'); $self->{object_menu} = $self->{plater}->object_menu; $self->on_plater_selection_changed(0); @@ -341,9 +416,11 @@ sub _init_menubar { $menubar->Append($self->{object_menu}, "&Object") if $self->{object_menu}; $menubar->Append($windowMenu, "&Window"); $menubar->Append($self->{viewMenu}, "&View") if $self->{viewMenu}; + # Add an optional debug menu + # (Select application language from the list of installed languages) + # In production code, the add_debug_menu() call should do nothing. + Slic3r::GUI::add_debug_menu($menubar, $self->{lang_ch_event}); $menubar->Append($helpMenu, "&Help"); - # Add an optional debug menu. In production code, the add_debug_menu() call should do nothing. - Slic3r::GUI::add_debug_menu($menubar); $self->SetMenuBar($menubar); } } @@ -374,7 +451,7 @@ sub quick_slice { # select input file my $input_file; if (!$params{reslice}) { - my $dialog = Wx::FileDialog->new($self, 'Choose a file to slice (STL/OBJ/AMF/PRUSA):', + my $dialog = Wx::FileDialog->new($self, 'Choose a file to slice (STL/OBJ/AMF/3MF/PRUSA):', wxTheApp->{app_config}->get_last_dir, "", &Slic3r::GUI::MODEL_WILDCARD, wxFD_OPEN | wxFD_FILE_MUST_EXIST); if ($dialog->ShowModal != wxID_OK) { @@ -611,7 +688,7 @@ sub load_configbundle { # Load a provied DynamicConfig into the Print / Filament / Printer tabs, thus modifying the active preset. # Also update the platter with the new presets. sub load_config { - my ($self, $config) = @_; + my ($self, $config) = @_; $_->load_config($config) foreach values %{$self->{options_tabs}}; $self->{plater}->on_config_change($config) if $self->{plater}; } @@ -661,7 +738,7 @@ sub check_unsaved_changes { my @dirty = (); foreach my $tab (values %{$self->{options_tabs}}) { - push @dirty, $tab->title if $tab->{presets}->current_is_dirty; + push @dirty, $tab->title if $tab->current_preset_is_dirty; } if (@dirty) { diff --git a/lib/Slic3r/GUI/OptionsGroup.pm b/lib/Slic3r/GUI/OptionsGroup.pm index 7ffb2067b..962e6ffc0 100644 --- a/lib/Slic3r/GUI/OptionsGroup.pm +++ b/lib/Slic3r/GUI/OptionsGroup.pm @@ -158,7 +158,9 @@ sub _build_field { my $opt_id = $opt->opt_id; my $on_change = sub { + #! This function will be called from Field. my ($opt_id, $value) = @_; + #! Call OptionGroup._on_change(...) $self->_on_change($opt_id, $value) unless $self->_disabled; }; @@ -213,6 +215,8 @@ sub _build_field { } return undef if !$field; + #! setting up a function that will be triggered when the field changes + #! think of it as $field->on_change = ($on_change) $field->on_change($on_change); $field->on_kill_focus($on_kill_focus); $self->_fields->{$opt_id} = $field; diff --git a/lib/Slic3r/GUI/Plater.pm b/lib/Slic3r/GUI/Plater.pm index 17a39184d..833b1a2a7 100644 --- a/lib/Slic3r/GUI/Plater.pm +++ b/lib/Slic3r/GUI/Plater.pm @@ -375,7 +375,9 @@ sub new { my $text = Wx::StaticText->new($self, -1, "$group_labels{$group}:", wxDefaultPosition, wxDefaultSize, wxALIGN_RIGHT); $text->SetFont($Slic3r::GUI::small_font); my $choice = Wx::BitmapComboBox->new($self, -1, "", wxDefaultPosition, wxDefaultSize, [], wxCB_READONLY); - EVT_LEFT_DOWN($choice, sub { $self->filament_color_box_lmouse_down(0, @_); } ); + if ($group eq 'filament') { + EVT_LEFT_DOWN($choice, sub { $self->filament_color_box_lmouse_down(0, @_); } ); + } $self->{preset_choosers}{$group} = [$choice]; # setup the listener EVT_COMBOBOX($choice, $choice, sub { @@ -441,7 +443,7 @@ sub new { $print_info_sizer->Add($grid_sizer, 0, wxEXPAND); my @info = ( fil_m => "Used Filament (m)", - fil_mm3 => "Used Filament (mm^3)", + fil_mm3 => "Used Filament (mm\u00B3)", fil_g => "Used Filament (g)", cost => "Cost", time => "Estimated printing time", @@ -620,7 +622,7 @@ sub load_files { # One of the files is potentionally a bundle of files. Don't bundle them, but load them one by one. # Only bundle .stls or .objs if the printer has multiple extruders. my $one_by_one = (@$nozzle_dmrs <= 1) || (@$input_files == 1) || - defined(first { $_ =~ /.[aA][mM][fF]$/ || $_ =~ /.3[mM][fF]$/ || $_ =~ /.[pP][rR][uI][sS][aA]$/ } @$input_files); + defined(first { $_ =~ /.[aA][mM][fF]$/ || $_ =~ /.[aA][mM][fF].[xX][mM][lL]$/ || $_ =~ /.[zZ][iI][pP].[aA][mM][fF]$/ || $_ =~ /.3[mM][fF]$/ || $_ =~ /.[pP][rR][uI][sS][aA]$/ } @$input_files); my $process_dialog = Wx::ProgressDialog->new('Loading…', "Processing input file\n" . basename($input_files->[0]), 100, $self, 0); $process_dialog->Pulse; @@ -638,8 +640,19 @@ sub load_files { my $input_file = $input_files->[$i]; $process_dialog->Update(100. * $i / @$input_files, "Processing input file\n" . basename($input_file)); - my $model = eval { Slic3r::Model->read_from_file($input_file, 0) }; - Slic3r::GUI::show_error($self, $@) if $@; + my $model; + if (($input_file =~ /.3[mM][fF]$/) || ($input_file =~ /.[zZ][iI][pP].[aA][mM][fF]$/)) + { + $model = eval { Slic3r::Model->read_from_archive($input_file, wxTheApp->{preset_bundle}, 0) }; + Slic3r::GUI::show_error($self, $@) if $@; + $_->load_current_preset for (values %{$self->GetFrame->{options_tabs}}); + wxTheApp->{app_config}->update_config_dir(dirname($input_file)); + } + else + { + $model = eval { Slic3r::Model->read_from_file($input_file, 0) }; + Slic3r::GUI::show_error($self, $@) if $@; + } next if ! defined $model; @@ -786,7 +799,6 @@ sub remove { splice @{$self->{objects}}, $obj_idx, 1; $self->{model}->delete_object($obj_idx); $self->{print}->delete_object($obj_idx); - $self->{gcode_preview_data}->reset; $self->{list}->DeleteItem($obj_idx); $self->object_list_changed; @@ -807,7 +819,6 @@ sub reset { @{$self->{objects}} = (); $self->{model}->clear_objects; $self->{print}->clear_objects; - $self->{gcode_preview_data}->reset; $self->{list}->DeleteAllItems; $self->object_list_changed; @@ -1161,6 +1172,7 @@ sub async_apply_config { # Reset preview canvases. If the print has been invalidated, the preview canvases will be cleared. # Otherwise they will be just refreshed. if ($invalidated) { + $self->{gcode_preview_data}->reset; $self->{toolpaths2D}->reload_print if $self->{toolpaths2D}; $self->{preview3D}->reload_print if $self->{preview3D}; } @@ -1267,8 +1279,6 @@ sub reslice { $self->stop_background_process; # Rather perform one additional unnecessary update of the print object instead of skipping a pending async update. $self->async_apply_config; - # Reset gcode data - $self->{gcode_preview_data}->reset; $self->statusbar->SetCancelCallback(sub { $self->stop_background_process; $self->statusbar->SetStatusText("Slicing cancelled"); @@ -1574,15 +1584,50 @@ sub export_amf { return if !@{$self->{objects}}; # Ask user for a file name to write into. my $output_file = $self->_get_export_file('AMF') or return; - $self->{model}->store_amf($output_file); - $self->statusbar->SetStatusText("AMF file exported to $output_file"); + my $res = $self->{model}->store_amf($output_file, $self->{print}); + if ($res) + { + $self->statusbar->SetStatusText("AMF file exported to $output_file"); + } + else + { + $self->statusbar->SetStatusText("Error exporting AMF file $output_file"); + } +} + +sub export_3mf { + my ($self) = @_; + return if !@{$self->{objects}}; + # Ask user for a file name to write into. + my $output_file = $self->_get_export_file('3MF') or return; + my $res = $self->{model}->store_3mf($output_file, $self->{print}); + if ($res) + { + $self->statusbar->SetStatusText("3MF file exported to $output_file"); + } + else + { + $self->statusbar->SetStatusText("Error exporting 3MF file $output_file"); + } } # Ask user to select an output file for a given file format (STl, AMF, 3MF). # Propose a default file name based on the 'output_filename_format' configuration value. sub _get_export_file { my ($self, $format) = @_; - my $suffix = $format eq 'STL' ? '.stl' : '.amf.xml'; + my $suffix = ''; + if ($format eq 'STL') + { + $suffix = '.stl'; + } + elsif ($format eq 'AMF') + { + $suffix = '.zip.amf'; + } + elsif ($format eq '3MF') + { + $suffix = '.3mf'; + } my $output_file = eval { $self->{print}->output_filepath($main::opt{output} // '') }; Slic3r::GUI::catch_error($self) and return undef; $output_file =~ s/\.[gG][cC][oO][dD][eE]$/$suffix/; @@ -2091,8 +2136,8 @@ sub OnDropFiles { # stop scalars leaking on older perl # https://rt.perl.org/rt3/Public/Bug/Display.html?id=70602 @_ = (); - # only accept STL, OBJ and AMF files - return 0 if grep !/\.(?:[sS][tT][lL]|[oO][bB][jJ]|[aA][mM][fF](?:\.[xX][mM][lL])?|[pP][rR][uU][sS][aA])$/, @$filenames; + # only accept STL, OBJ, AMF, 3MF and PRUSA files + return 0 if grep !/\.(?:[sS][tT][lL]|[oO][bB][jJ]|[aA][mM][fF]|[3][mM][fF]|[aA][mM][fF].[xX][mM][lL]|[zZ][iI][pP].[aA][mM][lL]|[pP][rR][uU][sS][aA])$/, @$filenames; $self->{window}->load_files($filenames); } diff --git a/lib/Slic3r/GUI/Plater/3DPreview.pm b/lib/Slic3r/GUI/Plater/3DPreview.pm index 01321ccc5..554b9e35a 100644 --- a/lib/Slic3r/GUI/Plater/3DPreview.pm +++ b/lib/Slic3r/GUI/Plater/3DPreview.pm @@ -18,7 +18,7 @@ sub new { $self->{config} = $config; $self->{number_extruders} = 1; # Show by feature type by default. - $self->{preferred_color_mode} = 0; + $self->{preferred_color_mode} = 'feature'; $self->auto_zoom(1); # init GUI elements @@ -72,7 +72,7 @@ sub new { my $label_show_features = $self->{label_show_features} = Wx::StaticText->new($self, -1, "Show"); - my $combochecklist_features = Wx::ComboCtrl->new(); + my $combochecklist_features = $self->{combochecklist_features} = Wx::ComboCtrl->new(); $combochecklist_features->Create($self, -1, "Feature types", wxDefaultPosition, [200, -1], wxCB_READONLY); #FIXME If the following line is removed, the combo box popup list will not react to mouse clicks. # On the other side, with this line the combo box popup cannot be closed by clicking on the combo button on Windows 10. @@ -82,10 +82,10 @@ sub new { my $feature_items = "Perimeter|External perimeter|Overhang perimeter|Internal infill|Solid infill|Top solid infill|Bridge infill|Gap fill|Skirt|Support material|Support material interface|Wipe tower"; Slic3r::GUI::create_combochecklist($combochecklist_features, $feature_text, $feature_items, 1); - my $checkbox_travel = Wx::CheckBox->new($self, -1, "Travel"); - my $checkbox_retractions = Wx::CheckBox->new($self, -1, "Retractions"); - my $checkbox_unretractions = Wx::CheckBox->new($self, -1, "Unretractions"); - my $checkbox_shells = Wx::CheckBox->new($self, -1, "Shells"); + my $checkbox_travel = $self->{checkbox_travel} = Wx::CheckBox->new($self, -1, "Travel"); + my $checkbox_retractions = $self->{checkbox_retractions} = Wx::CheckBox->new($self, -1, "Retractions"); + my $checkbox_unretractions = $self->{checkbox_unretractions} = Wx::CheckBox->new($self, -1, "Unretractions"); + my $checkbox_shells = $self->{checkbox_shells} = Wx::CheckBox->new($self, -1, "Shells"); my $hsizer = Wx::BoxSizer->new(wxHORIZONTAL); my $vsizer = Wx::BoxSizer->new(wxVERTICAL); @@ -194,7 +194,7 @@ sub new { }); EVT_CHOICE($self, $choice_view_type, sub { my $selection = $choice_view_type->GetCurrentSelection(); - $self->{preferred_color_mode} = $selection; + $self->{preferred_color_mode} = ($selection == 4) ? 'tool' : 'feature'; $self->gcode_preview_data->set_type($selection); $self->auto_zoom(0); $self->reload_print; @@ -258,6 +258,7 @@ sub new { ); $self->gcode_preview_data->set_extrusion_paths_colors(\@extrusion_roles_colors); + $self->show_hide_ui_elements('none'); $self->reload_print; return $self; @@ -346,6 +347,17 @@ sub load_print { $self->slider_high->Show; $self->Layout; + if ($self->{preferred_color_mode} eq 'tool_or_feature') { + # It is left to Slic3r to decide whether the print shall be colored by the tool or by the feature. + # Color by feature if it is a single extruder print. + my $extruders = $self->{print}->extruders; + my $type = (scalar(@{$extruders}) > 1) ? 4 : 0; + $self->gcode_preview_data->set_type($type); + $self->{choice_view_type}->SetSelection($type); + # If the ->SetSelection changed the following line, revert it to "decide yourself". + $self->{preferred_color_mode} = 'tool_or_feature'; + } + # Collect colors per extruder. my @colors = (); if (! $self->gcode_preview_data->empty() || $self->gcode_preview_data->type == 4) { @@ -370,8 +382,10 @@ sub load_print { #my @volume_ids = $self->canvas->load_object($object->model_object); #$self->canvas->volumes->[$_]->color->[3] = 0.2 for @volume_ids; } + $self->show_hide_ui_elements('simple'); } else { $self->canvas->load_gcode_preview($self->print, $self->gcode_preview_data, \@colors); + $self->show_hide_ui_elements('full'); } if ($self->auto_zoom) { $self->canvas->zoom_to_volumes; @@ -428,14 +442,23 @@ sub set_number_extruders { my ($self, $number_extruders) = @_; if ($self->{number_extruders} != $number_extruders) { $self->{number_extruders} = $number_extruders; - $self->{preferred_color_mode} = ($number_extruders > 1) ? + my $type = ($number_extruders > 1) ? 4 # color by a tool number : 0; # color by a feature type - $self->{choice_view_type}->SetSelection($self->{preferred_color_mode}); - $self->gcode_preview_data->set_type($self->{preferred_color_mode}); + $self->{choice_view_type}->SetSelection($type); + $self->gcode_preview_data->set_type($type); + $self->{preferred_color_mode} = ($type == 4) ? 'tool_or_feature' : 'feature'; } } +sub show_hide_ui_elements { + my ($self, $what) = @_; + my $method = ($what eq 'full') ? 'Enable' : 'Disable'; + $self->{$_}->$method for qw(label_show_features combochecklist_features checkbox_travel checkbox_retractions checkbox_unretractions checkbox_shells); + $method = ($what eq 'none') ? 'Disable' : 'Enable'; + $self->{$_}->$method for qw(label_view_type choice_view_type); +} + # Called by the Platter wxNotebook when this page is activated. sub OnActivate { # my ($self) = @_; diff --git a/lib/Slic3r/GUI/Tab.pm b/lib/Slic3r/GUI/Tab.pm deleted file mode 100644 index 4bd18366b..000000000 --- a/lib/Slic3r/GUI/Tab.pm +++ /dev/null @@ -1,1837 +0,0 @@ -# The "Expert" tab at the right of the main tabbed window. - -# This file implements following packages: -# Slic3r::GUI::Tab; -# Slic3r::GUI::Tab::Print; -# Slic3r::GUI::Tab::Filament; -# Slic3r::GUI::Tab::Printer; -# Slic3r::GUI::Tab::Page -# - Option page: For example, the Slic3r::GUI::Tab::Print has option pages "Layers and perimeters", "Infill", "Skirt and brim" ... -# Slic3r::GUI::SavePresetWindow -# - Dialog to select a new preset name to store the configuration. -# Slic3r::GUI::Tab::Preset; -# - Single preset item: name, file is default or external. - -package Slic3r::GUI::Tab; -use strict; -use warnings; -use utf8; - -use File::Basename qw(basename); -use List::Util qw(first); -use Wx qw(:bookctrl :dialog :keycode :icon :id :misc :panel :sizer :treectrl :window - :button wxTheApp wxCB_READONLY); -use Wx::Event qw(EVT_BUTTON EVT_COMBOBOX EVT_KEY_DOWN EVT_CHECKBOX EVT_TREE_SEL_CHANGED); -use base qw(Wx::Panel Class::Accessor); - -sub new { - my ($class, $parent, %params) = @_; - my $self = $class->SUPER::new($parent, -1, wxDefaultPosition, wxDefaultSize, wxBK_LEFT | wxTAB_TRAVERSAL); - - # Vertical sizer to hold the choice menu and the rest of the page. - $self->{sizer} = Wx::BoxSizer->new(wxVERTICAL); - $self->{sizer}->SetSizeHints($self); - $self->SetSizer($self->{sizer}); - - # preset chooser - { - - # choice menu - $self->{presets_choice} = Wx::BitmapComboBox->new($self, -1, "", wxDefaultPosition, [270, -1], [], wxCB_READONLY); - $self->{presets_choice}->SetFont($Slic3r::GUI::small_font); - - # buttons - $self->{btn_save_preset} = Wx::BitmapButton->new($self, -1, Wx::Bitmap->new(Slic3r::var("disk.png"), wxBITMAP_TYPE_PNG), - wxDefaultPosition, wxDefaultSize, wxBORDER_NONE); - $self->{btn_delete_preset} = Wx::BitmapButton->new($self, -1, Wx::Bitmap->new(Slic3r::var("delete.png"), wxBITMAP_TYPE_PNG), - wxDefaultPosition, wxDefaultSize, wxBORDER_NONE); - $self->{show_incompatible_presets} = 0; - $self->{bmp_show_incompatible_presets} = Wx::Bitmap->new(Slic3r::var("flag-red-icon.png"), wxBITMAP_TYPE_PNG); - $self->{bmp_hide_incompatible_presets} = Wx::Bitmap->new(Slic3r::var("flag-green-icon.png"), wxBITMAP_TYPE_PNG); - $self->{btn_hide_incompatible_presets} = Wx::BitmapButton->new($self, -1, - $self->{bmp_hide_incompatible_presets}, - wxDefaultPosition, wxDefaultSize, wxBORDER_NONE); - $self->{btn_save_preset}->SetToolTipString("Save current " . lc($self->title)); - $self->{btn_delete_preset}->SetToolTipString("Delete this preset"); - $self->{btn_delete_preset}->Disable; - - my $hsizer = Wx::BoxSizer->new(wxHORIZONTAL); - $self->{sizer}->Add($hsizer, 0, wxBOTTOM, 3); - $hsizer->Add($self->{presets_choice}, 1, wxLEFT | wxRIGHT | wxTOP | wxALIGN_CENTER_VERTICAL, 3); - $hsizer->AddSpacer(4); - $hsizer->Add($self->{btn_save_preset}, 0, wxALIGN_CENTER_VERTICAL); - $hsizer->AddSpacer(4); - $hsizer->Add($self->{btn_delete_preset}, 0, wxALIGN_CENTER_VERTICAL); - $hsizer->AddSpacer(16); - $hsizer->Add($self->{btn_hide_incompatible_presets}, 0, wxALIGN_CENTER_VERTICAL); - } - - # Horizontal sizer to hold the tree and the selected page. - $self->{hsizer} = Wx::BoxSizer->new(wxHORIZONTAL); - $self->{sizer}->Add($self->{hsizer}, 1, wxEXPAND, 0); - - # left vertical sizer - my $left_sizer = Wx::BoxSizer->new(wxVERTICAL); - $self->{hsizer}->Add($left_sizer, 0, wxEXPAND | wxLEFT | wxTOP | wxBOTTOM, 3); - - # tree - $self->{treectrl} = Wx::TreeCtrl->new($self, -1, wxDefaultPosition, [185, -1], wxTR_NO_BUTTONS | wxTR_HIDE_ROOT | wxTR_SINGLE | wxTR_NO_LINES | wxBORDER_SUNKEN | wxWANTS_CHARS); - $left_sizer->Add($self->{treectrl}, 1, wxEXPAND); - $self->{icons} = Wx::ImageList->new(16, 16, 1); - # Map from an icon file name to its index in $self->{icons}. - $self->{icon_index} = {}; - # Index of the last icon inserted into $self->{icons}. - $self->{icon_count} = -1; - $self->{treectrl}->AssignImageList($self->{icons}); - $self->{treectrl}->AddRoot("root"); - $self->{pages} = []; - $self->{treectrl}->SetIndent(0); - $self->{disable_tree_sel_changed_event} = 0; - EVT_TREE_SEL_CHANGED($parent, $self->{treectrl}, sub { - return if $self->{disable_tree_sel_changed_event}; - my $page = first { $_->{title} eq $self->{treectrl}->GetItemText($self->{treectrl}->GetSelection) } @{$self->{pages}} - or return; - $_->Hide for @{$self->{pages}}; - $page->Show; - $self->{hsizer}->Layout; - $self->Refresh; - }); - EVT_KEY_DOWN($self->{treectrl}, sub { - my ($treectrl, $event) = @_; - if ($event->GetKeyCode == WXK_TAB) { - $treectrl->Navigate($event->ShiftDown ? &Wx::wxNavigateBackward : &Wx::wxNavigateForward); - } else { - $event->Skip; - } - }); - - EVT_COMBOBOX($parent, $self->{presets_choice}, sub { - $self->select_preset($self->{presets_choice}->GetStringSelection); - }); - - EVT_BUTTON($self, $self->{btn_save_preset}, sub { $self->save_preset }); - EVT_BUTTON($self, $self->{btn_delete_preset}, sub { $self->delete_preset }); - EVT_BUTTON($self, $self->{btn_hide_incompatible_presets}, sub { $self->_toggle_show_hide_incompatible }); - - # Initialize the DynamicPrintConfig by default keys/values. - # Possible %params keys: no_controller - $self->build(%params); - $self->rebuild_page_tree; - $self->_update; - - return $self; -} - -# Save the current preset into file. -# This removes the "dirty" flag of the preset, possibly creates a new preset under a new name, -# and activates the new preset. -# Wizard calls save_preset with a name "My Settings", otherwise no name is provided and this method -# opens a Slic3r::GUI::SavePresetWindow dialog. -sub save_preset { - my ($self, $name) = @_; - - # since buttons (and choices too) don't get focus on Mac, we set focus manually - # to the treectrl so that the EVT_* events are fired for the input field having - # focus currently. is there anything better than this? - $self->{treectrl}->SetFocus; - - if (!defined $name) { - my $preset = $self->{presets}->get_selected_preset; - my $default_name = $preset->default ? 'Untitled' : $preset->name; - $default_name =~ s/\.[iI][nN][iI]$//; - my $dlg = Slic3r::GUI::SavePresetWindow->new($self, - title => lc($self->title), - default => $default_name, - values => [ map $_->name, grep !$_->default && !$_->external, @{$self->{presets}} ], - ); - return unless $dlg->ShowModal == wxID_OK; - $name = $dlg->get_name; - } - # Save the preset into Slic3r::data_dir/presets/section_name/preset_name.ini - eval { $self->{presets}->save_current_preset($name); }; - Slic3r::GUI::catch_error($self) and return; - # Mark the print & filament enabled if they are compatible with the currently selected preset. - wxTheApp->{preset_bundle}->update_compatible_with_printer(0); - # Add the new item into the UI component, remove dirty flags and activate the saved item. - $self->update_tab_ui; - # Update the selection boxes at the platter. - $self->_on_presets_changed; -} - -# Called for a currently selected preset. -sub delete_preset { - my ($self) = @_; - my $current_preset = $self->{presets}->get_selected_preset; - # Don't let the user delete the '- default -' configuration. - my $msg = 'Are you sure you want to ' . ($current_preset->external ? 'remove' : 'delete') . ' the selected preset?'; - my $title = ($current_preset->external ? 'Remove' : 'Delete') . ' Preset'; - return if $current_preset->default || - wxID_YES != Wx::MessageDialog->new($self, $msg, $title, wxYES_NO | wxNO_DEFAULT | wxICON_QUESTION)->ShowModal; - # Delete the file and select some other reasonable preset. - # The 'external' presets will only be removed from the preset list, their files will not be deleted. - eval { $self->{presets}->delete_current_preset; }; - Slic3r::GUI::catch_error($self) and return; - # Load the newly selected preset into the UI, update selection combo boxes with their dirty flags. - $self->load_current_preset; -} - -sub _toggle_show_hide_incompatible { - my ($self) = @_; - $self->{show_incompatible_presets} = ! $self->{show_incompatible_presets}; - $self->_update_show_hide_incompatible_button; - $self->update_tab_ui; -} - -sub _update_show_hide_incompatible_button { - my ($self) = @_; - $self->{btn_hide_incompatible_presets}->SetBitmap($self->{show_incompatible_presets} ? - $self->{bmp_show_incompatible_presets} : $self->{bmp_hide_incompatible_presets}); - $self->{btn_hide_incompatible_presets}->SetToolTipString($self->{show_incompatible_presets} ? - "Both compatible an incompatible presets are shown. Click to hide presets not compatible with the current printer." : - "Only compatible presets are shown. Click to show both the presets compatible and not compatible with the current printer."); -} - -# Register the on_value_change callback. -sub on_value_change { - my ($self, $cb) = @_; - $self->{on_value_change} = $cb; -} - -# Register the on_presets_changed callback. -sub on_presets_changed { - my ($self, $cb) = @_; - $self->{on_presets_changed} = $cb; -} - -# This method is called whenever an option field is changed by the user. -# Propagate event to the parent through the 'on_value_change' callback -# and call _update. -# The on_value_change callback triggers Platter::on_config_change() to configure the 3D preview -# (colors, wipe tower positon etc) and to restart the background slicing process. -sub _on_value_change { - my ($self, $key, $value) = @_; - $self->{on_value_change}->($key, $value) if $self->{on_value_change}; - $self->_update; -} - -# Override this to capture changes of configuration caused either by loading or switching a preset, -# or by a user changing an option field. -# This callback is useful for cross-validating configuration values of a single preset. -sub _update {} - -# Call a callback to update the selection of presets on the platter: -# To update the content of the selection boxes, -# to update the filament colors of the selection boxes, -# to update the "dirty" flags of the selection boxes, -# to uddate number of "filament" selection boxes when the number of extruders change. -sub _on_presets_changed { - my ($self, $reload_dependent_tabs) = @_; - $self->{on_presets_changed}->($self->{presets}, $reload_dependent_tabs) - if $self->{on_presets_changed}; -} - -# For the printer profile, generate the extruder pages after a preset is loaded. -sub on_preset_loaded {} - -# If the current preset is dirty, the user is asked whether the changes may be discarded. -# if the current preset was not dirty, or the user agreed to discard the changes, 1 is returned. -sub may_discard_current_dirty_preset -{ - my ($self, $presets, $new_printer_name) = @_; - $presets //= $self->{presets}; - # Display a dialog showing the dirty options in a human readable form. - my $old_preset = $presets->get_current_preset; - my $type_name = $presets->name; - my $tab = ' '; - my $name = $old_preset->default ? - ('Default ' . $type_name . ' preset') : - ($type_name . " preset\n$tab" . $old_preset->name); - # Collect descriptions of the dirty options. - my @option_names = (); - foreach my $opt_key (@{$presets->current_dirty_options}) { - my $opt = $Slic3r::Config::Options->{$opt_key}; - my $name = $opt->{full_label} // $opt->{label}; - $name = $opt->{category} . " > $name" if $opt->{category}; - push @option_names, $name; - } - # Show a confirmation dialog with the list of dirty options. - my $changes = join "\n", map "$tab$_", @option_names; - my $message = (defined $new_printer_name) ? - "$name\n\nis not compatible with printer\n$tab$new_printer_name\n\nand it has the following unsaved changes:" : - "$name\n\nhas the following unsaved changes:"; - my $confirm = Wx::MessageDialog->new($self, - $message . "\n$changes\n\nDiscard changes and continue anyway?", - 'Unsaved Changes', wxYES_NO | wxNO_DEFAULT | wxICON_QUESTION); - return $confirm->ShowModal == wxID_YES; -} - -# Called by the UI combo box when the user switches profiles. -# Select a preset by a name. If ! defined(name), then the default preset is selected. -# If the current profile is modified, user is asked to save the changes. -sub select_preset { - my ($self, $name, $force) = @_; - $force //= 0; - my $presets = $self->{presets}; - # If no name is provided, select the "-- default --" preset. - $name //= $presets->default_preset->name; - my $current_dirty = $presets->current_is_dirty; - my $canceled = 0; - my $printer_tab = $presets->name eq 'printer'; - my @reload_dependent_tabs = (); - if (! $force && $current_dirty && ! $self->may_discard_current_dirty_preset) { - $canceled = 1; - } elsif ($printer_tab) { - # Before switching the printer to a new one, verify, whether the currently active print and filament - # are compatible with the new printer. - # If they are not compatible and the the current print or filament are dirty, let user decide - # whether to discard the changes or keep the current printer selection. - my $new_printer_preset = $presets->find_preset($name, 1); - my $print_presets = wxTheApp->{preset_bundle}->print; - my $print_preset_dirty = $print_presets->current_is_dirty; - my $print_preset_compatible = $print_presets->get_edited_preset->is_compatible_with_printer($new_printer_preset); - $canceled = ! $force && $print_preset_dirty && ! $print_preset_compatible && - ! $self->may_discard_current_dirty_preset($print_presets, $name); - my $filament_presets = wxTheApp->{preset_bundle}->filament; - my $filament_preset_dirty = $filament_presets->current_is_dirty; - my $filament_preset_compatible = $filament_presets->get_edited_preset->is_compatible_with_printer($new_printer_preset); - if (! $canceled && ! $force) { - $canceled = $filament_preset_dirty && ! $filament_preset_compatible && - ! $self->may_discard_current_dirty_preset($filament_presets, $name); - } - if (! $canceled) { - if (! $print_preset_compatible) { - # The preset will be switched to a different, compatible preset, or the '-- default --'. - push @reload_dependent_tabs, 'print'; - $print_presets->discard_current_changes if $print_preset_dirty; - } - if (! $filament_preset_compatible) { - # The preset will be switched to a different, compatible preset, or the '-- default --'. - push @reload_dependent_tabs, 'filament'; - $filament_presets->discard_current_changes if $filament_preset_dirty; - } - } - } - if ($canceled) { - $self->update_tab_ui; - # Trigger the on_presets_changed event so that we also restore the previous value in the plater selector, - # if this action was initiated from the platter. - $self->_on_presets_changed; - } else { - $presets->discard_current_changes if $current_dirty; - $presets->select_preset_by_name($name); - # Mark the print & filament enabled if they are compatible with the currently selected preset. - # The following method should not discard changes of current print or filament presets on change of a printer profile, - # if they are compatible with the current printer. - wxTheApp->{preset_bundle}->update_compatible_with_printer(1) - if $current_dirty || $printer_tab; - # Initialize the UI from the current preset. - $self->load_current_preset(\@reload_dependent_tabs); - } -} - -# Initialize the UI from the current preset. -sub load_current_preset { - my ($self, $dependent_tab_names) = @_; - my $preset = $self->{presets}->get_current_preset; - eval { - local $SIG{__WARN__} = Slic3r::GUI::warning_catcher($self); - my $method = $preset->default ? 'Disable' : 'Enable'; - $self->{btn_delete_preset}->$method; - $self->_update; - # For the printer profile, generate the extruder pages. - $self->on_preset_loaded; - # Reload preset pages with the new configuration values. - $self->_reload_config; - }; - # use CallAfter because some field triggers schedule on_change calls using CallAfter, - # and we don't want them to be called after this update_dirty() as they would mark the - # preset dirty again - # (not sure this is true anymore now that update_dirty is idempotent) - wxTheApp->CallAfter(sub { - $self->update_tab_ui; - $self->_on_presets_changed($dependent_tab_names); - }); -} - -sub add_options_page { - my ($self, $title, $icon, %params) = @_; - # Index of $icon in an icon list $self->{icons}. - my $icon_idx = 0; - if ($icon) { - $icon_idx = $self->{icon_index}->{$icon}; - if (! defined $icon_idx) { - # Add a new icon to the icon list. - my $bitmap = Wx::Bitmap->new(Slic3r::var($icon), wxBITMAP_TYPE_PNG); - $self->{icons}->Add($bitmap); - $icon_idx = $self->{icon_count} + 1; - $self->{icon_count} = $icon_idx; - $self->{icon_index}->{$icon} = $icon_idx; - } - } - # Initialize the page. - my $page = Slic3r::GUI::Tab::Page->new($self, $title, $icon_idx); - $page->Hide; - $self->{hsizer}->Add($page, 1, wxEXPAND | wxLEFT, 5); - push @{$self->{pages}}, $page; - return $page; -} - -# Reload current $self->{config} (aka $self->{presets}->edited_preset->config) into the UI fields. -sub _reload_config { - my ($self) = @_; - $self->Freeze; - $_->reload_config for @{$self->{pages}}; - $self->Thaw; -} - -# Regerenerate content of the page tree. -sub rebuild_page_tree { - my ($self) = @_; - $self->Freeze; - # get label of the currently selected item - my $selected = $self->{treectrl}->GetItemText($self->{treectrl}->GetSelection); - my $rootItem = $self->{treectrl}->GetRootItem; - $self->{treectrl}->DeleteChildren($rootItem); - my $have_selection = 0; - foreach my $page (@{$self->{pages}}) { - my $itemId = $self->{treectrl}->AppendItem($rootItem, $page->{title}, $page->{iconID}); - if ($page->{title} eq $selected) { - $self->{disable_tree_sel_changed_event} = 1; - $self->{treectrl}->SelectItem($itemId); - $self->{disable_tree_sel_changed_event} = 0; - $have_selection = 1; - } - } - if (!$have_selection) { - # this is triggered on first load, so we don't disable the sel change event - $self->{treectrl}->SelectItem($self->{treectrl}->GetFirstChild($rootItem)); - } - $self->Thaw; -} - -# Update the combo box label of the selected preset based on its "dirty" state, -# comparing the selected preset config with $self->{config}. -sub update_dirty { - my ($self) = @_; - $self->{presets}->update_dirty_ui($self->{presets_choice}); - $self->_on_presets_changed; -} - -# Load a provied DynamicConfig into the tab, modifying the active preset. -# This could be used for example by setting a Wipe Tower position by interactive manipulation in the 3D view. -sub load_config { - my ($self, $config) = @_; - my $modified = 0; - foreach my $opt_key (@{$self->{config}->diff($config)}) { - $self->{config}->set($opt_key, $config->get($opt_key)); - $modified = 1; - } - if ($modified) { - $self->update_dirty; - # Initialize UI components with the config values. - $self->_reload_config; - $self->_update; - } -} - -# To be called by custom widgets, load a value into a config, -# update the preset selection boxes (the dirty flags) -sub _load_key_value { - my ($self, $opt_key, $value) = @_; - $self->{config}->set($opt_key, $value); - # Mark the print & filament enabled if they are compatible with the currently selected preset. - if ($opt_key eq 'compatible_printers') { -# $opt_key eq 'compatible_printers_condition') { - wxTheApp->{preset_bundle}->update_compatible_with_printer(0); - } - $self->{presets}->update_dirty_ui($self->{presets_choice}); - $self->_on_presets_changed; - $self->_update; -} - -# Find a field with an index over all pages of this tab. -# This method is used often and everywhere, therefore it shall be quick. -sub get_field { - my ($self, $opt_key, $opt_index) = @_; - foreach my $page (@{$self->{pages}}) { - my $field = $page->get_field($opt_key, $opt_index); - return $field if defined $field; - } - return undef; -} - -# Set a key/value pair on this page. Return true if the value has been modified. -# Currently used for distributing extruders_count over preset pages of Slic3r::GUI::Tab::Printer -# after a preset is loaded. -sub set_value { - my ($self, $opt_key, $value) = @_; - my $changed = 0; - foreach my $page (@{$self->{pages}}) { - $changed = 1 if $page->set_value($opt_key, $value); - } - return $changed; -} - -# Return a callback to create a Tab widget to mark the preferences as compatible / incompatible to the current printer. -sub _compatible_printers_widget { - my ($self) = @_; - - return sub { - my ($parent) = @_; - - my $checkbox = $self->{compatible_printers_checkbox} = Wx::CheckBox->new($parent, -1, "All"); - - my $btn = $self->{compatible_printers_btn} = Wx::Button->new($parent, -1, "Set…", wxDefaultPosition, wxDefaultSize, - wxBU_LEFT | wxBU_EXACTFIT); - $btn->SetFont($Slic3r::GUI::small_font); - $btn->SetBitmap(Wx::Bitmap->new(Slic3r::var("printer_empty.png"), wxBITMAP_TYPE_PNG)); - - my $sizer = Wx::BoxSizer->new(wxHORIZONTAL); - $sizer->Add($checkbox, 0, wxALIGN_CENTER_VERTICAL); - $sizer->Add($btn, 0, wxALIGN_CENTER_VERTICAL); - - EVT_CHECKBOX($self, $checkbox, sub { - my $method = $checkbox->GetValue ? 'Disable' : 'Enable'; - $btn->$method; - # All printers have been made compatible with this preset. - $self->_load_key_value('compatible_printers', []) if $checkbox->GetValue; - $self->get_field('compatible_printers_condition')->toggle($checkbox->GetValue); - }); - - EVT_BUTTON($self, $btn, sub { - # Collect names of non-default non-external printer profiles. - my @presets = map $_->name, grep !$_->default && !$_->external, - @{wxTheApp->{preset_bundle}->printer}; - my $dlg = Wx::MultiChoiceDialog->new($self, - "Select the printers this profile is compatible with.", - "Compatible printers", \@presets); - # Collect and set indices of printers marked as compatible. - my @selections = (); - foreach my $preset_name (@{ $self->{config}->get('compatible_printers') }) { - my $idx = first { $presets[$_] eq $preset_name } 0..$#presets; - push @selections, $idx if defined $idx; - } - $dlg->SetSelections(@selections); - # Show the dialog. - if ($dlg->ShowModal == wxID_OK) { - my $value = [ @presets[$dlg->GetSelections] ]; - if (!@$value) { - $checkbox->SetValue(1); - $self->get_field('compatible_printers_condition')->toggle(1); - $btn->Disable; - } - # All printers have been made compatible with this preset. - $self->_load_key_value('compatible_printers', $value); - } - }); - - return $sizer; - }; -} - -sub _reload_compatible_printers_widget { - my ($self) = @_; - my $has_any = int(@{$self->{config}->get('compatible_printers')}) > 0; - my $method = $has_any ? 'Enable' : 'Disable'; - $self->{compatible_printers_checkbox}->SetValue(! $has_any); - $self->{compatible_printers_btn}->$method; - $self->get_field('compatible_printers_condition')->toggle(! $has_any); -} - -sub update_ui_from_settings { - my ($self) = @_; - # Show the 'show / hide presets' button only for the print and filament tabs, and only if enabled - # in application preferences. - my $show = wxTheApp->{app_config}->get("show_incompatible_presets") && $self->{presets}->name ne 'printer'; - my $method = $show ? 'Show' : 'Hide'; - $self->{btn_hide_incompatible_presets}->$method; - # If the 'show / hide presets' button is hidden, hide the incompatible presets. - if ($show) { - $self->_update_show_hide_incompatible_button; - } else { - if ($self->{show_incompatible_presets}) { - $self->{show_incompatible_presets} = 0; - $self->update_tab_ui; - } - } -} -sub update_tab_ui { - my ($self) = @_; - $self->{presets}->update_tab_ui($self->{presets_choice}, $self->{show_incompatible_presets}) -} - -package Slic3r::GUI::Tab::Print; -use base 'Slic3r::GUI::Tab'; - -use List::Util qw(first); -use Wx qw(:icon :dialog :id wxTheApp); - -sub name { 'print' } -sub title { 'Print Settings' } - -sub build { - my $self = shift; - - $self->{presets} = wxTheApp->{preset_bundle}->print; - $self->{config} = $self->{presets}->get_edited_preset->config; - - { - my $page = $self->add_options_page('Layers and perimeters', 'layers.png'); - { - my $optgroup = $page->new_optgroup('Layer height'); - $optgroup->append_single_option_line('layer_height'); - $optgroup->append_single_option_line('first_layer_height'); - } - { - my $optgroup = $page->new_optgroup('Vertical shells'); - $optgroup->append_single_option_line('perimeters'); - $optgroup->append_single_option_line('spiral_vase'); - my $line = Slic3r::GUI::OptionsGroup::Line->new( - label => '', - full_width => 1, - widget => sub { - my ($parent) = @_; - return $self->{recommended_thin_wall_thickness_description_line} = Slic3r::GUI::OptionsGroup::StaticText->new($parent); - }, - ); - $optgroup->append_line($line); - } - { - my $optgroup = $page->new_optgroup('Horizontal shells'); - my $line = Slic3r::GUI::OptionsGroup::Line->new( - label => 'Solid layers', - ); - $line->append_option($optgroup->get_option('top_solid_layers')); - $line->append_option($optgroup->get_option('bottom_solid_layers')); - $optgroup->append_line($line); - } - { - my $optgroup = $page->new_optgroup('Quality (slower slicing)'); - $optgroup->append_single_option_line('extra_perimeters'); - $optgroup->append_single_option_line('ensure_vertical_shell_thickness'); - $optgroup->append_single_option_line('avoid_crossing_perimeters'); - $optgroup->append_single_option_line('thin_walls'); - $optgroup->append_single_option_line('overhangs'); - } - { - my $optgroup = $page->new_optgroup('Advanced'); - $optgroup->append_single_option_line('seam_position'); - $optgroup->append_single_option_line('external_perimeters_first'); - } - } - - { - my $page = $self->add_options_page('Infill', 'infill.png'); - { - my $optgroup = $page->new_optgroup('Infill'); - $optgroup->append_single_option_line('fill_density'); - $optgroup->append_single_option_line('fill_pattern'); - $optgroup->append_single_option_line('external_fill_pattern'); - } - { - my $optgroup = $page->new_optgroup('Reducing printing time'); - $optgroup->append_single_option_line('infill_every_layers'); - $optgroup->append_single_option_line('infill_only_where_needed'); - } - { - my $optgroup = $page->new_optgroup('Advanced'); - $optgroup->append_single_option_line('solid_infill_every_layers'); - $optgroup->append_single_option_line('fill_angle'); - $optgroup->append_single_option_line('solid_infill_below_area'); - $optgroup->append_single_option_line('bridge_angle'); - $optgroup->append_single_option_line('only_retract_when_crossing_perimeters'); - $optgroup->append_single_option_line('infill_first'); - } - } - - { - my $page = $self->add_options_page('Skirt and brim', 'box.png'); - { - my $optgroup = $page->new_optgroup('Skirt'); - $optgroup->append_single_option_line('skirts'); - $optgroup->append_single_option_line('skirt_distance'); - $optgroup->append_single_option_line('skirt_height'); - $optgroup->append_single_option_line('min_skirt_length'); - } - { - my $optgroup = $page->new_optgroup('Brim'); - $optgroup->append_single_option_line('brim_width'); - } - } - - { - my $page = $self->add_options_page('Support material', 'building.png'); - { - my $optgroup = $page->new_optgroup('Support material'); - $optgroup->append_single_option_line('support_material'); - $optgroup->append_single_option_line('support_material_threshold'); - $optgroup->append_single_option_line('support_material_enforce_layers'); - } - { - my $optgroup = $page->new_optgroup('Raft'); - $optgroup->append_single_option_line('raft_layers'); -# $optgroup->append_single_option_line('raft_contact_distance'); - } - { - my $optgroup = $page->new_optgroup('Options for support material and raft'); - $optgroup->append_single_option_line('support_material_contact_distance'); - $optgroup->append_single_option_line('support_material_pattern'); - $optgroup->append_single_option_line('support_material_with_sheath'); - $optgroup->append_single_option_line('support_material_spacing'); - $optgroup->append_single_option_line('support_material_angle'); - $optgroup->append_single_option_line('support_material_interface_layers'); - $optgroup->append_single_option_line('support_material_interface_spacing'); - $optgroup->append_single_option_line('support_material_interface_contact_loops'); - $optgroup->append_single_option_line('support_material_buildplate_only'); - $optgroup->append_single_option_line('support_material_xy_spacing'); - $optgroup->append_single_option_line('dont_support_bridges'); - $optgroup->append_single_option_line('support_material_synchronize_layers'); - } - } - - { - my $page = $self->add_options_page('Speed', 'time.png'); - { - my $optgroup = $page->new_optgroup('Speed for print moves'); - $optgroup->append_single_option_line('perimeter_speed'); - $optgroup->append_single_option_line('small_perimeter_speed'); - $optgroup->append_single_option_line('external_perimeter_speed'); - $optgroup->append_single_option_line('infill_speed'); - $optgroup->append_single_option_line('solid_infill_speed'); - $optgroup->append_single_option_line('top_solid_infill_speed'); - $optgroup->append_single_option_line('support_material_speed'); - $optgroup->append_single_option_line('support_material_interface_speed'); - $optgroup->append_single_option_line('bridge_speed'); - $optgroup->append_single_option_line('gap_fill_speed'); - } - { - my $optgroup = $page->new_optgroup('Speed for non-print moves'); - $optgroup->append_single_option_line('travel_speed'); - } - { - my $optgroup = $page->new_optgroup('Modifiers'); - $optgroup->append_single_option_line('first_layer_speed'); - } - { - my $optgroup = $page->new_optgroup('Acceleration control (advanced)'); - $optgroup->append_single_option_line('perimeter_acceleration'); - $optgroup->append_single_option_line('infill_acceleration'); - $optgroup->append_single_option_line('bridge_acceleration'); - $optgroup->append_single_option_line('first_layer_acceleration'); - $optgroup->append_single_option_line('default_acceleration'); - } - { - my $optgroup = $page->new_optgroup('Autospeed (advanced)'); - $optgroup->append_single_option_line('max_print_speed'); - $optgroup->append_single_option_line('max_volumetric_speed'); - $optgroup->append_single_option_line('max_volumetric_extrusion_rate_slope_positive'); - $optgroup->append_single_option_line('max_volumetric_extrusion_rate_slope_negative'); - } - } - - { - my $page = $self->add_options_page('Multiple Extruders', 'funnel.png'); - { - my $optgroup = $page->new_optgroup('Extruders'); - $optgroup->append_single_option_line('perimeter_extruder'); - $optgroup->append_single_option_line('infill_extruder'); - $optgroup->append_single_option_line('solid_infill_extruder'); - $optgroup->append_single_option_line('support_material_extruder'); - $optgroup->append_single_option_line('support_material_interface_extruder'); - } - { - my $optgroup = $page->new_optgroup('Ooze prevention'); - $optgroup->append_single_option_line('ooze_prevention'); - $optgroup->append_single_option_line('standby_temperature_delta'); - } - { - my $optgroup = $page->new_optgroup('Wipe tower'); - $optgroup->append_single_option_line('wipe_tower'); - $optgroup->append_single_option_line('wipe_tower_x'); - $optgroup->append_single_option_line('wipe_tower_y'); - $optgroup->append_single_option_line('wipe_tower_width'); - $optgroup->append_single_option_line('wipe_tower_per_color_wipe'); - } - { - my $optgroup = $page->new_optgroup('Advanced'); - $optgroup->append_single_option_line('interface_shells'); - } - } - - { - my $page = $self->add_options_page('Advanced', 'wrench.png'); - { - my $optgroup = $page->new_optgroup('Extrusion width', - label_width => 180, - ); - $optgroup->append_single_option_line('extrusion_width'); - $optgroup->append_single_option_line('first_layer_extrusion_width'); - $optgroup->append_single_option_line('perimeter_extrusion_width'); - $optgroup->append_single_option_line('external_perimeter_extrusion_width'); - $optgroup->append_single_option_line('infill_extrusion_width'); - $optgroup->append_single_option_line('solid_infill_extrusion_width'); - $optgroup->append_single_option_line('top_infill_extrusion_width'); - $optgroup->append_single_option_line('support_material_extrusion_width'); - } - { - my $optgroup = $page->new_optgroup('Overlap'); - $optgroup->append_single_option_line('infill_overlap'); - } - { - my $optgroup = $page->new_optgroup('Flow'); - $optgroup->append_single_option_line('bridge_flow_ratio'); - } - { - my $optgroup = $page->new_optgroup('Other'); - $optgroup->append_single_option_line('clip_multipart_objects'); - $optgroup->append_single_option_line('elefant_foot_compensation'); - $optgroup->append_single_option_line('xy_size_compensation'); -# $optgroup->append_single_option_line('threads'); - $optgroup->append_single_option_line('resolution'); - } - } - - { - my $page = $self->add_options_page('Output options', 'page_white_go.png'); - { - my $optgroup = $page->new_optgroup('Sequential printing'); - $optgroup->append_single_option_line('complete_objects'); - my $line = Slic3r::GUI::OptionsGroup::Line->new( - label => 'Extruder clearance (mm)', - ); - foreach my $opt_key (qw(extruder_clearance_radius extruder_clearance_height)) { - my $option = $optgroup->get_option($opt_key); - $option->width(60); - $line->append_option($option); - } - $optgroup->append_line($line); - } - { - my $optgroup = $page->new_optgroup('Output file'); - $optgroup->append_single_option_line('gcode_comments'); - - { - my $option = $optgroup->get_option('output_filename_format'); - $option->full_width(1); - $optgroup->append_single_option_line($option); - } - } - { - my $optgroup = $page->new_optgroup('Post-processing scripts', - label_width => 0, - ); - my $option = $optgroup->get_option('post_process'); - $option->full_width(1); - $option->height(50); - $optgroup->append_single_option_line($option); - } - } - - { - my $page = $self->add_options_page('Notes', 'note.png'); - { - my $optgroup = $page->new_optgroup('Notes', - label_width => 0, - ); - my $option = $optgroup->get_option('notes'); - $option->full_width(1); - $option->height(250); - $optgroup->append_single_option_line($option); - } - } - - { - my $page = $self->add_options_page('Dependencies', 'wrench.png'); - { - my $optgroup = $page->new_optgroup('Profile dependencies'); - { - my $line = Slic3r::GUI::OptionsGroup::Line->new( - label => 'Compatible printers', - widget => $self->_compatible_printers_widget, - ); - $optgroup->append_line($line); - - my $option = $optgroup->get_option('compatible_printers_condition'); - $option->full_width(1); - $optgroup->append_single_option_line($option); - } - } - } -} - -# Reload current $self->{config} (aka $self->{presets}->edited_preset->config) into the UI fields. -sub _reload_config { - my ($self) = @_; - $self->_reload_compatible_printers_widget; - $self->SUPER::_reload_config; -} - -# Slic3r::GUI::Tab::Print::_update is called after a configuration preset is loaded or switched, or when a single option is modifed by the user. -sub _update { - my ($self) = @_; - $self->Freeze; - - my $config = $self->{config}; - - if ($config->spiral_vase && !($config->perimeters == 1 && $config->top_solid_layers == 0 && $config->fill_density == 0)) { - my $dialog = Wx::MessageDialog->new($self, - "The Spiral Vase mode requires:\n" - . "- one perimeter\n" - . "- no top solid layers\n" - . "- 0% fill density\n" - . "- no support material\n" - . "- no ensure_vertical_shell_thickness\n" - . "\nShall I adjust those settings in order to enable Spiral Vase?", - 'Spiral Vase', wxICON_WARNING | wxYES | wxNO); - my $new_conf = Slic3r::Config->new; - if ($dialog->ShowModal() == wxID_YES) { - $new_conf->set("perimeters", 1); - $new_conf->set("top_solid_layers", 0); - $new_conf->set("fill_density", 0); - $new_conf->set("support_material", 0); - $new_conf->set("ensure_vertical_shell_thickness", 0); - } else { - $new_conf->set("spiral_vase", 0); - } - $self->load_config($new_conf); - } - - if ($config->wipe_tower && - ($config->first_layer_height != 0.2 || $config->layer_height < 0.15 || $config->layer_height > 0.35)) { - my $dialog = Wx::MessageDialog->new($self, - "The Wipe Tower currently supports only:\n" - . "- first layer height 0.2mm\n" - . "- layer height from 0.15mm to 0.35mm\n" - . "\nShall I adjust those settings in order to enable the Wipe Tower?", - 'Wipe Tower', wxICON_WARNING | wxYES | wxNO); - my $new_conf = Slic3r::Config->new; - if ($dialog->ShowModal() == wxID_YES) { - $new_conf->set("first_layer_height", 0.2); - $new_conf->set("layer_height", 0.15) if $config->layer_height < 0.15; - $new_conf->set("layer_height", 0.35) if $config->layer_height > 0.35; - } else { - $new_conf->set("wipe_tower", 0); - } - $self->load_config($new_conf); - } - - if ($config->wipe_tower && $config->support_material && $config->support_material_contact_distance > 0. && - ($config->support_material_extruder != 0 || $config->support_material_interface_extruder != 0)) { - my $dialog = Wx::MessageDialog->new($self, - "The Wipe Tower currently supports the non-soluble supports only\n" - . "if they are printed with the current extruder without triggering a tool change.\n" - . "(both support_material_extruder and support_material_interface_extruder need to be set to 0).\n" - . "\nShall I adjust those settings in order to enable the Wipe Tower?", - 'Wipe Tower', wxICON_WARNING | wxYES | wxNO); - my $new_conf = Slic3r::Config->new; - if ($dialog->ShowModal() == wxID_YES) { - $new_conf->set("support_material_extruder", 0); - $new_conf->set("support_material_interface_extruder", 0); - } else { - $new_conf->set("wipe_tower", 0); - } - $self->load_config($new_conf); - } - - if ($config->wipe_tower && $config->support_material && $config->support_material_contact_distance == 0 && - ! $config->support_material_synchronize_layers) { - my $dialog = Wx::MessageDialog->new($self, - "For the Wipe Tower to work with the soluble supports, the support layers\n" - . "need to be synchronized with the object layers.\n" - . "\nShall I synchronize support layers in order to enable the Wipe Tower?", - 'Wipe Tower', wxICON_WARNING | wxYES | wxNO); - my $new_conf = Slic3r::Config->new; - if ($dialog->ShowModal() == wxID_YES) { - $new_conf->set("support_material_synchronize_layers", 1); - } else { - $new_conf->set("wipe_tower", 0); - } - $self->load_config($new_conf); - } - - if ($config->support_material) { - # Ask only once. - if (! $self->{support_material_overhangs_queried}) { - $self->{support_material_overhangs_queried} = 1; - if ($config->overhangs != 1) { - my $dialog = Wx::MessageDialog->new($self, - "Supports work better, if the following feature is enabled:\n" - . "- Detect bridging perimeters\n" - . "\nShall I adjust those settings for supports?", - 'Support Generator', wxICON_WARNING | wxYES | wxNO | wxCANCEL); - my $answer = $dialog->ShowModal(); - my $new_conf = Slic3r::Config->new; - if ($answer == wxID_YES) { - # Enable "detect bridging perimeters". - $new_conf->set("overhangs", 1); - } elsif ($answer == wxID_NO) { - # Do nothing, leave supports on and "detect bridging perimeters" off. - } elsif ($answer == wxID_CANCEL) { - # Disable supports. - $new_conf->set("support_material", 0); - $self->{support_material_overhangs_queried} = 0; - } - $self->load_config($new_conf); - } - } - } else { - $self->{support_material_overhangs_queried} = 0; - } - - if ($config->fill_density == 100 - && !first { $_ eq $config->fill_pattern } @{$Slic3r::Config::Options->{external_fill_pattern}{values}}) { - my $dialog = Wx::MessageDialog->new($self, - "The " . $config->fill_pattern . " infill pattern is not supposed to work at 100% density.\n" - . "\nShall I switch to rectilinear fill pattern?", - 'Infill', wxICON_WARNING | wxYES | wxNO); - - my $new_conf = Slic3r::Config->new; - if ($dialog->ShowModal() == wxID_YES) { - $new_conf->set("fill_pattern", 'rectilinear'); - $new_conf->set("fill_density", 100); - } else { - $new_conf->set("fill_density", 40); - } - $self->load_config($new_conf); - } - - my $have_perimeters = $config->perimeters > 0; - $self->get_field($_)->toggle($have_perimeters) - for qw(extra_perimeters ensure_vertical_shell_thickness thin_walls overhangs seam_position external_perimeters_first - external_perimeter_extrusion_width - perimeter_speed small_perimeter_speed external_perimeter_speed); - - my $have_infill = $config->fill_density > 0; - # infill_extruder uses the same logic as in Print::extruders() - $self->get_field($_)->toggle($have_infill) - for qw(fill_pattern infill_every_layers infill_only_where_needed solid_infill_every_layers - solid_infill_below_area infill_extruder); - - my $have_solid_infill = ($config->top_solid_layers > 0) || ($config->bottom_solid_layers > 0); - # solid_infill_extruder uses the same logic as in Print::extruders() - $self->get_field($_)->toggle($have_solid_infill) - for qw(external_fill_pattern infill_first solid_infill_extruder solid_infill_extrusion_width - solid_infill_speed); - - $self->get_field($_)->toggle($have_infill || $have_solid_infill) - for qw(fill_angle bridge_angle infill_extrusion_width infill_speed bridge_speed); - - $self->get_field('gap_fill_speed')->toggle($have_perimeters && $have_infill); - - my $have_top_solid_infill = $config->top_solid_layers > 0; - $self->get_field($_)->toggle($have_top_solid_infill) - for qw(top_infill_extrusion_width top_solid_infill_speed); - - my $have_default_acceleration = $config->default_acceleration > 0; - $self->get_field($_)->toggle($have_default_acceleration) - for qw(perimeter_acceleration infill_acceleration bridge_acceleration first_layer_acceleration); - - my $have_skirt = $config->skirts > 0 || $config->min_skirt_length > 0; - $self->get_field($_)->toggle($have_skirt) - for qw(skirt_distance skirt_height); - - my $have_brim = $config->brim_width > 0; - # perimeter_extruder uses the same logic as in Print::extruders() - $self->get_field('perimeter_extruder')->toggle($have_perimeters || $have_brim); - - my $have_raft = $config->raft_layers > 0; - my $have_support_material = $config->support_material || $have_raft; - my $have_support_interface = $config->support_material_interface_layers > 0; - my $have_support_soluble = $have_support_material && $config->support_material_contact_distance == 0; - $self->get_field($_)->toggle($have_support_material) - for qw(support_material_threshold support_material_pattern support_material_with_sheath - support_material_spacing support_material_angle - support_material_interface_layers dont_support_bridges - support_material_extrusion_width support_material_contact_distance support_material_xy_spacing); - $self->get_field($_)->toggle($have_support_material && $have_support_interface) - for qw(support_material_interface_spacing support_material_interface_extruder - support_material_interface_speed support_material_interface_contact_loops); - $self->get_field('support_material_synchronize_layers')->toggle($have_support_soluble); - - $self->get_field('perimeter_extrusion_width')->toggle($have_perimeters || $have_skirt || $have_brim); - $self->get_field('support_material_extruder')->toggle($have_support_material || $have_skirt); - $self->get_field('support_material_speed')->toggle($have_support_material || $have_brim || $have_skirt); - - my $have_sequential_printing = $config->complete_objects; - $self->get_field($_)->toggle($have_sequential_printing) - for qw(extruder_clearance_radius extruder_clearance_height); - - my $have_ooze_prevention = $config->ooze_prevention; - $self->get_field($_)->toggle($have_ooze_prevention) - for qw(standby_temperature_delta); - - my $have_wipe_tower = $config->wipe_tower; - $self->get_field($_)->toggle($have_wipe_tower) - for qw(wipe_tower_x wipe_tower_y wipe_tower_width wipe_tower_per_color_wipe); - - $self->{recommended_thin_wall_thickness_description_line}->SetText( - Slic3r::GUI::PresetHints::recommended_thin_wall_thickness(wxTheApp->{preset_bundle})); - - $self->Thaw; -} - -# Update on activation to recalculate the estimates if the nozzle diameter changed -# and the extrusion width values were left to zero (automatic, nozzle dependent). -sub OnActivate { - my ($self) = @_; - $self->{recommended_thin_wall_thickness_description_line}->SetText( - Slic3r::GUI::PresetHints::recommended_thin_wall_thickness(wxTheApp->{preset_bundle})); -} - -package Slic3r::GUI::Tab::Filament; -use base 'Slic3r::GUI::Tab'; -use Wx qw(wxTheApp); - -sub name { 'filament' } -sub title { 'Filament Settings' } - -sub build { - my $self = shift; - - $self->{presets} = wxTheApp->{preset_bundle}->filament; - $self->{config} = $self->{presets}->get_edited_preset->config; - - { - my $page = $self->add_options_page('Filament', 'spool.png'); - { - my $optgroup = $page->new_optgroup('Filament'); - $optgroup->append_single_option_line('filament_colour', 0); - $optgroup->append_single_option_line('filament_diameter', 0); - $optgroup->append_single_option_line('extrusion_multiplier', 0); - $optgroup->append_single_option_line('filament_density', 0); - $optgroup->append_single_option_line('filament_cost', 0); - } - - { - my $optgroup = $page->new_optgroup('Temperature (°C)'); - - { - my $line = Slic3r::GUI::OptionsGroup::Line->new( - label => 'Extruder', - ); - $line->append_option($optgroup->get_option('first_layer_temperature', 0)); - $line->append_option($optgroup->get_option('temperature', 0)); - $optgroup->append_line($line); - } - - { - my $line = Slic3r::GUI::OptionsGroup::Line->new( - label => 'Bed', - ); - $line->append_option($optgroup->get_option('first_layer_bed_temperature', 0)); - $line->append_option($optgroup->get_option('bed_temperature', 0)); - $optgroup->append_line($line); - } - } - } - - { - my $page = $self->add_options_page('Cooling', 'hourglass.png'); - { - my $optgroup = $page->new_optgroup('Enable'); - $optgroup->append_single_option_line('fan_always_on', 0); - $optgroup->append_single_option_line('cooling', 0); - - my $line = Slic3r::GUI::OptionsGroup::Line->new( - label => '', - full_width => 1, - widget => sub { - my ($parent) = @_; - return $self->{cooling_description_line} = Slic3r::GUI::OptionsGroup::StaticText->new($parent); - }, - ); - $optgroup->append_line($line); - } - { - my $optgroup = $page->new_optgroup('Fan settings'); - - { - my $line = Slic3r::GUI::OptionsGroup::Line->new( - label => 'Fan speed', - ); - $line->append_option($optgroup->get_option('min_fan_speed', 0)); - $line->append_option($optgroup->get_option('max_fan_speed', 0)); - $optgroup->append_line($line); - } - - $optgroup->append_single_option_line('bridge_fan_speed', 0); - $optgroup->append_single_option_line('disable_fan_first_layers', 0); - } - { - my $optgroup = $page->new_optgroup('Cooling thresholds', - label_width => 250, - ); - $optgroup->append_single_option_line('fan_below_layer_time', 0); - $optgroup->append_single_option_line('slowdown_below_layer_time', 0); - $optgroup->append_single_option_line('min_print_speed', 0); - } - } - - { - my $page = $self->add_options_page('Advanced', 'wrench.png'); - { - my $optgroup = $page->new_optgroup('Filament properties'); - $optgroup->append_single_option_line('filament_type', 0); - $optgroup->append_single_option_line('filament_soluble', 0); - - $optgroup = $page->new_optgroup('Print speed override'); - $optgroup->append_single_option_line('filament_max_volumetric_speed', 0); - - my $line = Slic3r::GUI::OptionsGroup::Line->new( - label => '', - full_width => 1, - widget => sub { - my ($parent) = @_; - return $self->{volumetric_speed_description_line} = Slic3r::GUI::OptionsGroup::StaticText->new($parent); - }, - ); - $optgroup->append_line($line); - } - } - - { - my $page = $self->add_options_page('Custom G-code', 'cog.png'); - { - my $optgroup = $page->new_optgroup('Start G-code', - label_width => 0, - ); - my $option = $optgroup->get_option('start_filament_gcode', 0); - $option->full_width(1); - $option->height(150); - $optgroup->append_single_option_line($option); - } - { - my $optgroup = $page->new_optgroup('End G-code', - label_width => 0, - ); - my $option = $optgroup->get_option('end_filament_gcode', 0); - $option->full_width(1); - $option->height(150); - $optgroup->append_single_option_line($option); - } - } - - { - my $page = $self->add_options_page('Notes', 'note.png'); - { - my $optgroup = $page->new_optgroup('Notes', - label_width => 0, - ); - my $option = $optgroup->get_option('filament_notes', 0); - $option->full_width(1); - $option->height(250); - $optgroup->append_single_option_line($option); - } - } - - { - my $page = $self->add_options_page('Dependencies', 'wrench.png'); - { - my $optgroup = $page->new_optgroup('Profile dependencies'); - { - my $line = Slic3r::GUI::OptionsGroup::Line->new( - label => 'Compatible printers', - widget => $self->_compatible_printers_widget, - ); - $optgroup->append_line($line); - - my $option = $optgroup->get_option('compatible_printers_condition'); - $option->full_width(1); - $optgroup->append_single_option_line($option); - } - } - } -} - -# Reload current $self->{config} (aka $self->{presets}->edited_preset->config) into the UI fields. -sub _reload_config { - my ($self) = @_; - $self->_reload_compatible_printers_widget; - $self->SUPER::_reload_config; -} - -# Slic3r::GUI::Tab::Filament::_update is called after a configuration preset is loaded or switched, or when a single option is modifed by the user. -sub _update { - my ($self) = @_; - - $self->{cooling_description_line}->SetText( - Slic3r::GUI::PresetHints::cooling_description($self->{presets}->get_edited_preset)); - $self->{volumetric_speed_description_line}->SetText( - Slic3r::GUI::PresetHints::maximum_volumetric_flow_description(wxTheApp->{preset_bundle})); - - my $cooling = $self->{config}->cooling->[0]; - my $fan_always_on = $cooling || $self->{config}->fan_always_on->[0]; - $self->get_field($_, 0)->toggle($cooling) - for qw(max_fan_speed fan_below_layer_time slowdown_below_layer_time min_print_speed); - $self->get_field($_, 0)->toggle($fan_always_on) - for qw(min_fan_speed disable_fan_first_layers); -} - -sub OnActivate { - my ($self) = @_; - $self->{volumetric_speed_description_line}->SetText( - Slic3r::GUI::PresetHints::maximum_volumetric_flow_description(wxTheApp->{preset_bundle})); -} - -package Slic3r::GUI::Tab::Printer; -use base 'Slic3r::GUI::Tab'; -use Wx qw(wxTheApp :sizer :button :bitmap :misc :id :icon :dialog); -use Wx::Event qw(EVT_BUTTON); - -sub name { 'printer' } -sub title { 'Printer Settings' } - -sub build { - my ($self, %params) = @_; - - $self->{presets} = wxTheApp->{preset_bundle}->printer; - $self->{config} = $self->{presets}->get_edited_preset->config; - $self->{extruders_count} = scalar @{$self->{config}->nozzle_diameter}; - - my $bed_shape_widget = sub { - my ($parent) = @_; - - my $btn = Wx::Button->new($parent, -1, "Set…", wxDefaultPosition, wxDefaultSize, - wxBU_LEFT | wxBU_EXACTFIT); - $btn->SetFont($Slic3r::GUI::small_font); - $btn->SetBitmap(Wx::Bitmap->new(Slic3r::var("printer_empty.png"), wxBITMAP_TYPE_PNG)); - - my $sizer = Wx::BoxSizer->new(wxHORIZONTAL); - $sizer->Add($btn); - - EVT_BUTTON($self, $btn, sub { - my $dlg = Slic3r::GUI::BedShapeDialog->new($self, $self->{config}->bed_shape); - $self->_load_key_value('bed_shape', $dlg->GetValue) if $dlg->ShowModal == wxID_OK; - }); - - return $sizer; - }; - - { - my $page = $self->add_options_page('General', 'printer_empty.png'); - { - my $optgroup = $page->new_optgroup('Size and coordinates'); - - my $line = Slic3r::GUI::OptionsGroup::Line->new( - label => 'Bed shape', - widget => $bed_shape_widget, - ); - $optgroup->append_line($line); - - $optgroup->append_single_option_line('z_offset'); - } - { - my $optgroup = $page->new_optgroup('Capabilities'); - { - my $option = Slic3r::GUI::OptionsGroup::Option->new( - opt_id => 'extruders_count', - type => 'i', - default => 1, - label => 'Extruders', - tooltip => 'Number of extruders of the printer.', - min => 1, - ); - $optgroup->append_single_option_line($option); - $optgroup->append_single_option_line('single_extruder_multi_material'); - } - $optgroup->on_change(sub { - my ($opt_key, $value) = @_; - wxTheApp->CallAfter(sub { - if ($opt_key eq 'extruders_count') { - $self->_extruders_count_changed($optgroup->get_value('extruders_count')); - $self->update_dirty; - } else { - $self->update_dirty; - $self->_on_value_change($opt_key, $value); - } - }); - }); - } - if (!$params{no_controller}) - { - my $optgroup = $page->new_optgroup('USB/Serial connection'); - my $line = Slic3r::GUI::OptionsGroup::Line->new( - label => 'Serial port', - ); - my $serial_port = $optgroup->get_option('serial_port'); - $serial_port->side_widget(sub { - my ($parent) = @_; - - my $btn = Wx::BitmapButton->new($parent, -1, Wx::Bitmap->new(Slic3r::var("arrow_rotate_clockwise.png"), wxBITMAP_TYPE_PNG), - wxDefaultPosition, wxDefaultSize, &Wx::wxBORDER_NONE); - $btn->SetToolTipString("Rescan serial ports") - if $btn->can('SetToolTipString'); - EVT_BUTTON($self, $btn, \&_update_serial_ports); - - return $btn; - }); - my $serial_test = sub { - my ($parent) = @_; - - my $btn = $self->{serial_test_btn} = Wx::Button->new($parent, -1, - "Test", wxDefaultPosition, wxDefaultSize, wxBU_LEFT | wxBU_EXACTFIT); - $btn->SetFont($Slic3r::GUI::small_font); - $btn->SetBitmap(Wx::Bitmap->new(Slic3r::var("wrench.png"), wxBITMAP_TYPE_PNG)); - - EVT_BUTTON($self, $btn, sub { - my $sender = Slic3r::GCode::Sender->new; - my $res = $sender->connect( - $self->{config}->serial_port, - $self->{config}->serial_speed, - ); - if ($res && $sender->wait_connected) { - Slic3r::GUI::show_info($self, "Connection to printer works correctly.", "Success!"); - } else { - Slic3r::GUI::show_error($self, "Connection failed."); - } - }); - return $btn; - }; - $line->append_option($serial_port); - $line->append_option($optgroup->get_option('serial_speed')); - $line->append_widget($serial_test); - $optgroup->append_line($line); - } - { - my $optgroup = $page->new_optgroup('OctoPrint upload'); - - # append two buttons to the Host line - my $octoprint_host_browse = sub { - my ($parent) = @_; - - my $btn = Wx::Button->new($parent, -1, "Browse…", wxDefaultPosition, wxDefaultSize, wxBU_LEFT); - $btn->SetFont($Slic3r::GUI::small_font); - $btn->SetBitmap(Wx::Bitmap->new(Slic3r::var("zoom.png"), wxBITMAP_TYPE_PNG)); - - if (!eval "use Net::Bonjour; 1") { - $btn->Disable; - } - - EVT_BUTTON($self, $btn, sub { - # look for devices - my $entries; - { - my $res = Net::Bonjour->new('http'); - $res->discover; - $entries = [ $res->entries ]; - } - if (@{$entries}) { - my $dlg = Slic3r::GUI::BonjourBrowser->new($self, $entries); - $self->_load_key_value('octoprint_host', $dlg->GetValue . ":" . $dlg->GetPort) - if $dlg->ShowModal == wxID_OK; - } else { - Wx::MessageDialog->new($self, 'No Bonjour device found', 'Device Browser', wxOK | wxICON_INFORMATION)->ShowModal; - } - }); - - return $btn; - }; - my $octoprint_host_test = sub { - my ($parent) = @_; - - my $btn = $self->{octoprint_host_test_btn} = Wx::Button->new($parent, -1, - "Test", wxDefaultPosition, wxDefaultSize, wxBU_LEFT | wxBU_EXACTFIT); - $btn->SetFont($Slic3r::GUI::small_font); - $btn->SetBitmap(Wx::Bitmap->new(Slic3r::var("wrench.png"), wxBITMAP_TYPE_PNG)); - - EVT_BUTTON($self, $btn, sub { - my $ua = LWP::UserAgent->new; - $ua->timeout(10); - - my $res = $ua->get( - "http://" . $self->{config}->octoprint_host . "/api/version", - 'X-Api-Key' => $self->{config}->octoprint_apikey, - ); - if ($res->is_success) { - Slic3r::GUI::show_info($self, "Connection to OctoPrint works correctly.", "Success!"); - } else { - Slic3r::GUI::show_error($self, - "I wasn't able to connect to OctoPrint (" . $res->status_line . "). " - . "Check hostname and OctoPrint version (at least 1.1.0 is required)."); - } - }); - return $btn; - }; - - my $host_line = $optgroup->create_single_option_line('octoprint_host'); - $host_line->append_widget($octoprint_host_browse); - $host_line->append_widget($octoprint_host_test); - $optgroup->append_line($host_line); - $optgroup->append_single_option_line('octoprint_apikey'); - } - { - my $optgroup = $page->new_optgroup('Firmware'); - $optgroup->append_single_option_line('gcode_flavor'); - } - { - my $optgroup = $page->new_optgroup('Advanced'); - $optgroup->append_single_option_line('use_relative_e_distances'); - $optgroup->append_single_option_line('use_firmware_retraction'); - $optgroup->append_single_option_line('use_volumetric_e'); - $optgroup->append_single_option_line('variable_layer_height'); - } - } - { - my $page = $self->add_options_page('Custom G-code', 'cog.png'); - { - my $optgroup = $page->new_optgroup('Start G-code', - label_width => 0, - ); - my $option = $optgroup->get_option('start_gcode'); - $option->full_width(1); - $option->height(150); - $optgroup->append_single_option_line($option); - } - { - my $optgroup = $page->new_optgroup('End G-code', - label_width => 0, - ); - my $option = $optgroup->get_option('end_gcode'); - $option->full_width(1); - $option->height(150); - $optgroup->append_single_option_line($option); - } - { - my $optgroup = $page->new_optgroup('Before layer change G-code', - label_width => 0, - ); - my $option = $optgroup->get_option('before_layer_gcode'); - $option->full_width(1); - $option->height(150); - $optgroup->append_single_option_line($option); - } - { - my $optgroup = $page->new_optgroup('After layer change G-code', - label_width => 0, - ); - my $option = $optgroup->get_option('layer_gcode'); - $option->full_width(1); - $option->height(150); - $optgroup->append_single_option_line($option); - } - { - my $optgroup = $page->new_optgroup('Tool change G-code', - label_width => 0, - ); - my $option = $optgroup->get_option('toolchange_gcode'); - $option->full_width(1); - $option->height(150); - $optgroup->append_single_option_line($option); - } - { - my $optgroup = $page->new_optgroup('Between objects G-code (for sequential printing)', - label_width => 0, - ); - my $option = $optgroup->get_option('between_objects_gcode'); - $option->full_width(1); - $option->height(150); - $optgroup->append_single_option_line($option); - } - } - - { - my $page = $self->add_options_page('Notes', 'note.png'); - { - my $optgroup = $page->new_optgroup('Notes', - label_width => 0, - ); - my $option = $optgroup->get_option('printer_notes'); - $option->full_width(1); - $option->height(250); - $optgroup->append_single_option_line($option); - } - } - - $self->{extruder_pages} = []; - $self->_build_extruder_pages; - - $self->_update_serial_ports if (!$params{no_controller}); -} - -sub _update_serial_ports { - my ($self) = @_; - - $self->get_field('serial_port')->set_values([ Slic3r::GUI::scan_serial_ports ]); -} - -sub _extruders_count_changed { - my ($self, $extruders_count) = @_; - $self->{extruders_count} = $extruders_count; - wxTheApp->{preset_bundle}->printer->get_edited_preset->set_num_extruders($extruders_count); - wxTheApp->{preset_bundle}->update_multi_material_filament_presets; - $self->_build_extruder_pages; - $self->_on_value_change('extruders_count', $extruders_count); -} - -sub _build_extruder_pages { - my ($self) = @_; - my $default_config = Slic3r::Config::Full->new; - - foreach my $extruder_idx (@{$self->{extruder_pages}} .. $self->{extruders_count}-1) { - # build page - my $page = $self->{extruder_pages}[$extruder_idx] = $self->add_options_page("Extruder " . ($extruder_idx + 1), 'funnel.png'); - { - my $optgroup = $page->new_optgroup('Size'); - $optgroup->append_single_option_line('nozzle_diameter', $extruder_idx); - } - { - my $optgroup = $page->new_optgroup('Layer height limits'); - $optgroup->append_single_option_line($_, $extruder_idx) - for qw(min_layer_height max_layer_height); - } - { - my $optgroup = $page->new_optgroup('Position (for multi-extruder printers)'); - $optgroup->append_single_option_line('extruder_offset', $extruder_idx); - } - { - my $optgroup = $page->new_optgroup('Retraction'); - $optgroup->append_single_option_line($_, $extruder_idx) - for qw(retract_length retract_lift); - - { - my $line = Slic3r::GUI::OptionsGroup::Line->new( - label => 'Only lift Z', - ); - $line->append_option($optgroup->get_option('retract_lift_above', $extruder_idx)); - $line->append_option($optgroup->get_option('retract_lift_below', $extruder_idx)); - $optgroup->append_line($line); - } - - $optgroup->append_single_option_line($_, $extruder_idx) - for qw(retract_speed deretract_speed retract_restart_extra retract_before_travel retract_layer_change wipe retract_before_wipe); - } - { - my $optgroup = $page->new_optgroup('Retraction when tool is disabled (advanced settings for multi-extruder setups)'); - $optgroup->append_single_option_line($_, $extruder_idx) - for qw(retract_length_toolchange retract_restart_extra_toolchange); - } - { - my $optgroup = $page->new_optgroup('Preview'); - $optgroup->append_single_option_line('extruder_colour', $extruder_idx); - } - } - - # remove extra pages - if ($self->{extruders_count} <= $#{$self->{extruder_pages}}) { - $_->Destroy for @{$self->{extruder_pages}}[$self->{extruders_count}..$#{$self->{extruder_pages}}]; - splice @{$self->{extruder_pages}}, $self->{extruders_count}; - } - - # rebuild page list - my @pages_without_extruders = (grep $_->{title} !~ /^Extruder \d+/, @{$self->{pages}}); - my $page_notes = pop @pages_without_extruders; - @{$self->{pages}} = ( - @pages_without_extruders, - @{$self->{extruder_pages}}[ 0 .. $self->{extruders_count}-1 ], - $page_notes - ); - $self->rebuild_page_tree; -} - -# Slic3r::GUI::Tab::Printer::_update is called after a configuration preset is loaded or switched, or when a single option is modifed by the user. -sub _update { - my ($self) = @_; - $self->Freeze; - - my $config = $self->{config}; - - my $serial_speed = $self->get_field('serial_speed'); - if ($serial_speed) { - $self->get_field('serial_speed')->toggle($config->get('serial_port')); - if ($config->get('serial_speed') && $config->get('serial_port')) { - $self->{serial_test_btn}->Enable; - } else { - $self->{serial_test_btn}->Disable; - } - } - if ($config->get('octoprint_host') && eval "use LWP::UserAgent; 1") { - $self->{octoprint_host_test_btn}->Enable; - } else { - $self->{octoprint_host_test_btn}->Disable; - } - $self->get_field('octoprint_apikey')->toggle($config->get('octoprint_host')); - - my $have_multiple_extruders = $self->{extruders_count} > 1; - $self->get_field('toolchange_gcode')->toggle($have_multiple_extruders); - $self->get_field('single_extruder_multi_material')->toggle($have_multiple_extruders); - - for my $i (0 .. ($self->{extruders_count}-1)) { - my $have_retract_length = $config->get_at('retract_length', $i) > 0; - - # when using firmware retraction, firmware decides retraction length - $self->get_field('retract_length', $i)->toggle(!$config->use_firmware_retraction); - - # user can customize travel length if we have retraction length or we're using - # firmware retraction - $self->get_field('retract_before_travel', $i)->toggle($have_retract_length || $config->use_firmware_retraction); - - # user can customize other retraction options if retraction is enabled - my $retraction = ($have_retract_length || $config->use_firmware_retraction); - $self->get_field($_, $i)->toggle($retraction) - for qw(retract_lift retract_layer_change); - - # retract lift above/below only applies if using retract lift - $self->get_field($_, $i)->toggle($retraction && $config->get_at('retract_lift', $i) > 0) - for qw(retract_lift_above retract_lift_below); - - # some options only apply when not using firmware retraction - $self->get_field($_, $i)->toggle($retraction && !$config->use_firmware_retraction) - for qw(retract_speed deretract_speed retract_before_wipe retract_restart_extra wipe); - - my $wipe = $config->get_at('wipe', $i); - $self->get_field('retract_before_wipe', $i)->toggle($wipe); - - if ($config->use_firmware_retraction && $wipe) { - my $dialog = Wx::MessageDialog->new($self, - "The Wipe option is not available when using the Firmware Retraction mode.\n" - . "\nShall I disable it in order to enable Firmware Retraction?", - 'Firmware Retraction', wxICON_WARNING | wxYES | wxNO); - - my $new_conf = Slic3r::Config->new; - if ($dialog->ShowModal() == wxID_YES) { - my $wipe = $config->wipe; - $wipe->[$i] = 0; - $new_conf->set("wipe", $wipe); - } else { - $new_conf->set("use_firmware_retraction", 0); - } - $self->load_config($new_conf); - } - - $self->get_field('retract_length_toolchange', $i)->toggle($have_multiple_extruders); - - my $toolchange_retraction = $config->get_at('retract_length_toolchange', $i) > 0; - $self->get_field('retract_restart_extra_toolchange', $i)->toggle - ($have_multiple_extruders && $toolchange_retraction); - } - - $self->Thaw; -} - -# this gets executed after preset is loaded and before GUI fields are updated -sub on_preset_loaded { - my ($self) = @_; - # update the extruders count field - my $extruders_count = scalar @{ $self->{config}->nozzle_diameter }; - $self->set_value('extruders_count', $extruders_count); - # update the GUI field according to the number of nozzle diameters supplied - $self->_extruders_count_changed($extruders_count); -} - -# Single Tab page containing a {vsizer} of {optgroups} -package Slic3r::GUI::Tab::Page; -use Wx qw(wxTheApp :misc :panel :sizer); -use base 'Wx::ScrolledWindow'; - -sub new { - my ($class, $parent, $title, $iconID) = @_; - my $self = $class->SUPER::new($parent, -1, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL); - $self->{optgroups} = []; - $self->{title} = $title; - $self->{iconID} = $iconID; - - $self->SetScrollbars(1, 1, 1, 1); - - $self->{vsizer} = Wx::BoxSizer->new(wxVERTICAL); - $self->SetSizer($self->{vsizer}); - - return $self; -} - -sub new_optgroup { - my ($self, $title, %params) = @_; - - my $optgroup = Slic3r::GUI::ConfigOptionsGroup->new( - parent => $self, - title => $title, - config => $self->GetParent->{config}, - label_width => $params{label_width} // 200, - on_change => sub { - my ($opt_key, $value) = @_; - wxTheApp->CallAfter(sub { - $self->GetParent->update_dirty; - $self->GetParent->_on_value_change($opt_key, $value); - }); - }, - ); - - push @{$self->{optgroups}}, $optgroup; - $self->{vsizer}->Add($optgroup->sizer, 0, wxEXPAND | wxALL, 10); - - return $optgroup; -} - -sub reload_config { - my ($self) = @_; - $_->reload_config for @{$self->{optgroups}}; -} - -sub get_field { - my ($self, $opt_key, $opt_index) = @_; - foreach my $optgroup (@{ $self->{optgroups} }) { - my $field = $optgroup->get_fieldc($opt_key, $opt_index); - return $field if defined $field; - } - return undef; -} - -sub set_value { - my ($self, $opt_key, $value) = @_; - my $changed = 0; - foreach my $optgroup (@{$self->{optgroups}}) { - $changed = 1 if $optgroup->set_value($opt_key, $value); - } - return $changed; -} - -# Dialog to select a new file name for a modified preset to be saved. -# Called from Tab::save_preset(). -package Slic3r::GUI::SavePresetWindow; -use Wx qw(:combobox :dialog :id :misc :sizer); -use Wx::Event qw(EVT_BUTTON EVT_TEXT_ENTER); -use base 'Wx::Dialog'; - -sub new { - my ($class, $parent, %params) = @_; - my $self = $class->SUPER::new($parent, -1, "Save preset", wxDefaultPosition, wxDefaultSize); - - my @values = @{$params{values}}; - - my $text = Wx::StaticText->new($self, -1, "Save " . lc($params{title}) . " as:", wxDefaultPosition, wxDefaultSize); - $self->{combo} = Wx::ComboBox->new($self, -1, $params{default}, wxDefaultPosition, wxDefaultSize, \@values, - wxTE_PROCESS_ENTER); - my $buttons = $self->CreateStdDialogButtonSizer(wxOK | wxCANCEL); - - my $sizer = Wx::BoxSizer->new(wxVERTICAL); - $sizer->Add($text, 0, wxEXPAND | wxTOP | wxLEFT | wxRIGHT, 10); - $sizer->Add($self->{combo}, 0, wxEXPAND | wxLEFT | wxRIGHT, 10); - $sizer->Add($buttons, 0, wxEXPAND | wxBOTTOM | wxLEFT | wxRIGHT, 10); - - EVT_BUTTON($self, wxID_OK, \&accept); - EVT_TEXT_ENTER($self, $self->{combo}, \&accept); - - $self->SetSizer($sizer); - $sizer->SetSizeHints($self); - - return $self; -} - -sub accept { - my ($self, $event) = @_; - if (($self->{chosen_name} = Slic3r::normalize_utf8_nfc($self->{combo}->GetValue))) { - if ($self->{chosen_name} !~ /^[^<>:\/\\|?*\"]+$/) { - Slic3r::GUI::show_error($self, "The supplied name is not valid; the following characters are not allowed: <>:/\|?*\""); - } elsif ($self->{chosen_name} eq '- default -') { - Slic3r::GUI::show_error($self, "The supplied name is not available."); - } else { - $self->EndModal(wxID_OK); - } - } -} - -sub get_name { - my ($self) = @_; - return $self->{chosen_name}; -} - -1; diff --git a/lib/Slic3r/Print.pm b/lib/Slic3r/Print.pm index fa3d4a101..8300fdbed 100644 --- a/lib/Slic3r/Print.pm +++ b/lib/Slic3r/Print.pm @@ -93,6 +93,8 @@ sub export_gcode { $self->status_cb->(95, "Running post-processing scripts"); $self->config->setenv; for my $script (@{$self->config->post_process}) { + # Ignore empty post processing script lines. + next if $script =~ /^\s*$/; Slic3r::debugf " '%s' '%s'\n", $script, $output_file; # -x doesn't return true on Windows except for .exe files if (($^O eq 'MSWin32') ? !(-e $script) : !(-x $script)) { diff --git a/resources/localization/cs_CZ/Slic3rPE.mo b/resources/localization/cs_CZ/Slic3rPE.mo new file mode 100644 index 000000000..9ddd8e3b1 Binary files /dev/null and b/resources/localization/cs_CZ/Slic3rPE.mo differ diff --git a/resources/localization/cs_CZ/Slic3rPE_cs.po b/resources/localization/cs_CZ/Slic3rPE_cs.po new file mode 100644 index 000000000..b6af76f35 --- /dev/null +++ b/resources/localization/cs_CZ/Slic3rPE_cs.po @@ -0,0 +1,2704 @@ +# Oleksandra Iushchenko , 2018. +# +msgid "" +msgstr "" +"Project-Id-Version: SLIC3R PE VERSION\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2018-02-13 17:18+0100\n" +"PO-Revision-Date: 2018-02-15 18:26+0100\n" +"Last-Translator: Oleksandra Iushchenko \n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"X-Generator: Poedit 2.0.6\n" +"Plural-Forms: nplurals=3; plural=(n==1) ? 0 : (n>=2 && n<=4) ? 1 : 2;\n" +"Language: cs_CZ\n" +"X-Poedit-KeywordsList: _L\n" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\BedShapeDialog.cpp:50 +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:1188 +msgid "Size" +msgstr "Rozměr" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\BedShapeDialog.cpp:51 +msgid "Size in X and Y of the rectangular plate." +msgstr "Rozměr tiskové podložky v ose X a Y." + +#: c:\src\Slic3r\xs\src\slic3r\GUI\BedShapeDialog.cpp:57 +msgid "Origin" +msgstr "Origin" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\BedShapeDialog.cpp:58 +msgid "" +"Distance of the 0,0 G-code coordinate from the front left corner of the " +"rectangle." +msgstr "Vzdálenost souřadnice 0,0 G-kódu od předního levého rohu obdélníku." + +#: c:\src\Slic3r\xs\src\slic3r\GUI\BedShapeDialog.cpp:65 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:133 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:204 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:215 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:329 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:340 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:359 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:438 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:783 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:803 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:862 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:880 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:898 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1046 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1054 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1096 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1105 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1115 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1123 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1131 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1217 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1423 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1493 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1529 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1706 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1713 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1720 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1729 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1739 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1749 +msgid "mm" +msgstr "mm" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\BedShapeDialog.cpp:66 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:435 +msgid "Diameter" +msgstr "Průměr" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\BedShapeDialog.cpp:67 +msgid "" +"Diameter of the print bed. It is assumed that origin (0,0) is located in the " +"center." +msgstr "" +"Průměr tiskové podložky.Přepokládaná souřadnice 0,0 je umístěna uprostřed." + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:965 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:312 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:704 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:960 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1274 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1447 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1473 +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:432 +msgid "Extruders" +msgstr "Extrudér" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:966 +msgid "Number of extruders of the printer." +msgstr "Počet extrudérů tiskárny." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:30 +msgid "Avoid crossing perimeters" +msgstr "Vyhnout se přejíždění perimetrů" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:31 +msgid "" +"Optimize travel moves in order to minimize the crossing of perimeters. This " +"is mostly useful with Bowden extruders which suffer from oozing. This " +"feature slows down both the print and the G-code generation." +msgstr "" +"Optimalizovat přesuny do pořadí aby se minimalizovalo přejíždění perimetrů. " +"Nejvíce užitečné u Bowdenových extruderů které trpí na vytékáné filamentu. " +"Toto nastavení zpomaluje tisk i generování G-kódu." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:38 +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:939 +msgid "Bed shape" +msgstr "Tvar tiskové podložky" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:42 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1574 +msgid "Other layers" +msgstr "Ostatní vrstvy" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:43 +msgid "" +"Bed temperature for layers after the first one. Set this to zero to disable " +"bed temperature control commands in the output." +msgstr "" +"Teplota tiskové podložky pro další vrstvy po první vrstvě. Nastavením na " +"hodnotu nula vypnete ovládací příkazy teploty tiskové podložky ve výstupu." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:46 +msgid "Bed temperature" +msgstr "Teplota tiskové podložky" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:52 +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:1131 +msgid "Before layer change G-code" +msgstr "Before layer change G-code" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:53 +msgid "" +"This custom code is inserted at every layer change, right before the Z move. " +"Note that you can use placeholder variables for all Slic3r settings as well " +"as [layer_num] and [layer_z]." +msgstr "" +"Tento upravený kód je vložen pro každou změnu vrstvy, předtím než se pohne " +"Z. Můžete přidávat zástupné proměnné pro veškeré nastavení Slic3ru stejně " +"tak jako [layer_num] a [layer_z]." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:63 +msgid "Between objects G-code" +msgstr "G-kód mezi objekty" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:64 +msgid "" +"This code is inserted between objects when using sequential printing. By " +"default extruder and bed temperature are reset using non-wait command; " +"however if M104, M109, M140 or M190 are detected in this custom code, Slic3r " +"will not add temperature commands. Note that you can use placeholder " +"variables for all Slic3r settings, so you can put a \"M109 " +"S[first_layer_temperature]\" command wherever you want." +msgstr "" +"Tento kód je vložen mezi objekty, pokud je použit sekvenční tisk. Ve " +"výchozím nastavení je resetován extrudér a tisková podložka pomocí non-wait " +"(nečekacím) příkazem; nicméně pokud jsou příkazy M104, M109, 140 nebo M190 " +"detekovány v tomto upraveném kódu, Slic3r nebude přidávat teplotní příkazy. " +"Můžete přidávat zástupné proměnné pro veškeré nastavení Slic3ru, takže " +"můžete vložit příkaz “M109 S[first_layer_temperature]” kamkoliv chcete." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:72 +msgid "Bottom" +msgstr "Spodek" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:73 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:243 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:294 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:302 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:606 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:764 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:780 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:943 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:991 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1154 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1585 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1641 +msgid "Layers and Perimeters" +msgstr "Vrstvy a perimetry" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:74 +msgid "Number of solid layers to generate on bottom surfaces." +msgstr "Počet plných vrstev." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:76 +msgid "Bottom solid layers" +msgstr "Plné spodní vrstvy" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:81 +msgid "Bridge" +msgstr "Most" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:82 +msgid "" +"This is the acceleration your printer will use for bridges. Set zero to " +"disable acceleration control for bridges." +msgstr "" +"Nastavení akcelerace tiskárny při vytváření mostů. Nastavením na nulu " +"vypnete ovládání akcelerace pro mosty." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:84 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:178 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:578 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:686 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:954 +msgid "mm/s\\u00B2" +msgstr "mm/s\\u00B2" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:90 +msgid "Bridging angle" +msgstr "Úhel vytváření mostů" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:91 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:251 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:492 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:506 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:544 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:683 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:693 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:711 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:729 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:748 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1265 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1282 +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:347 +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:348 +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:664 +msgid "Infill" +msgstr "Výplň" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:92 +msgid "" +"Bridging angle override. If left to zero, the bridging angle will be " +"calculated automatically. Otherwise the provided angle will be used for all " +"bridges. Use 180\\u00B0 for zero angle." +msgstr "" +"Přepsání úhlu vytváření mostů. Nastavením hodnoty na nulu se bude úhel " +"vytváření mostů vypočítávat automaticky. Při zadání jiného úhlu, bude pro " +"všechny mosty použitý zadaný úhel. Pro nulový úhel zadejte 180\\u00B0." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:95 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:496 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1172 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1183 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1403 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1559 +msgid "\\u00B0" +msgstr "\\u00B0" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:101 +msgid "Bridges fan speed" +msgstr "Rychlost ventilátoru při vytváření mostů" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:102 +msgid "This fan speed is enforced during all bridges and overhangs." +msgstr "" +"Nastavená rychlost ventilátoru je využita vždy při vytváření mostů a přesahů." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:103 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:508 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:791 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:852 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1062 +msgid "%" +msgstr "%" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:110 +msgid "Bridge flow ratio" +msgstr "Poměr průtoku při vytváření mostů" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:111 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:212 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:738 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1735 +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:343 +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:357 +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:450 +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:453 +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:830 +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:1112 +msgid "Advanced" +msgstr "Pokročilé" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:112 +msgid "" +"This factor affects the amount of plastic for bridging. You can decrease it " +"slightly to pull the extrudates and prevent sagging, although default " +"settings are usually good and you should experiment with cooling (use a fan) " +"before tweaking this." +msgstr "" +"Tato hodnota určuje množství vytlačeného plastu při vytváření mostů. Mírným " +"šnížením této hodnoty můžete předejít pronášení ikdyž, přednastavené hodnoty " +"jsou většinou dobré a je lepší experimentovat s chlazením (využitím " +"ventilátoru), než s touto hodnotou." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:121 +msgid "Bridges" +msgstr "Mosty" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:122 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:282 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:637 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:749 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:981 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1203 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1253 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1304 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1627 +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:399 +msgid "Speed" +msgstr "Rychlost" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:123 +msgid "Speed for printing bridges." +msgstr "Rychlost pro vytváření mostů." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:124 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:640 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:751 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:813 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:870 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:983 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1139 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1148 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1538 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1651 +msgid "mm/s" +msgstr "mm/s" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:131 +msgid "Brim width" +msgstr "Okraj první vrstvy" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:132 +msgid "" +"Horizontal width of the brim that will be printed around each object on the " +"first layer." +msgstr "Šírka okraje první vrsty která bude vytištěna okolo každého objektu." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:139 +msgid "Clip multi-part objects" +msgstr "Připnutí objektů z více částí k sobě" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:140 +msgid "" +"When printing multi-material objects, this settings will make slic3r to clip " +"the overlapping object parts one by the other (2nd part will be clipped by " +"the 1st, 3rd part will be clipped by the 1st and 2nd etc)." +msgstr "" +"Připnutí překrývajících se objektů jednek druhému při multi-materiálovém " +"tisku. (Druhá část se připne k první, třetí část k první a druhé, atd)." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:147 +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:510 +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:868 +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:1673 +msgid "Compatible printers" +msgstr "Kompatibilní tiskárny" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:151 +msgid "Compatible printers condition" +msgstr "Stav kompatibilních tiskáren" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:152 +msgid "" +"A boolean expression using the configuration values of an active printer " +"profile. If this expression evaluates to true, this profile is considered " +"compatible with the active printer profile." +msgstr "" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:158 +msgid "Complete individual objects" +msgstr "Dokončení individuálních objektů" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:159 +msgid "" +"When printing multiple objects or copies, this feature will complete each " +"object before moving onto next one (and starting it from its bottom layer). " +"This feature is useful to avoid the risk of ruined prints. Slic3r should " +"warn and prevent you from extruder collisions, but beware." +msgstr "" +"Při tisku více objektů nebo kopií tiskárna kompletně dokončí jeden objekt, " +"předtím než začne tisknout druhý (začíná od spodní vstvy). Tato vlastnost je " +"výhodná z důvodů snížení rizika zničených výtisků. Slic3r by měl varovat při " +"možné kolizi extrudéru s objektem a zabránit mu, přesto doporučujeme " +"obezřetnost." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:167 +msgid "Enable auto cooling" +msgstr "Zapnutí automatického chlazení" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:168 +msgid "" +"This flag enables the automatic cooling logic that adjusts print speed and " +"fan speed according to layer printing time." +msgstr "" +"Zapíná výpočet automatického chlazení který upravuje rychlost tisku a " +"ventilátoru v závislosti na délce tisku jedné vstvy." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:174 +#: c:\src\Slic3r\xs\src\slic3r\GUI\GUI.cpp:293 +msgid "Default" +msgstr "Výchozí" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:175 +msgid "" +"This is the acceleration your printer will be reset to after the role-" +"specific acceleration values are used (perimeter/infill). Set zero to " +"prevent resetting acceleration at all." +msgstr "" +"Toto je hodnota akcelerace na kterou se tiskárna vrátí po specifických " +"úpravách akcelerace například při tisku (perimetru/výplně). Nastavením na " +"nulu zabráníte návratu rychlostí zcela." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:184 +msgid "Disable fan for the first" +msgstr "Vypnutí chlazení pro prvních" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:185 +msgid "" +"You can set this to a positive value to disable fan at all during the first " +"layers, so that it does not make adhesion worse." +msgstr "" +"Nastavením počtu prvních vstev s vypnutým chlazením pro nezhoršování " +"přilnavosti." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:187 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:696 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1035 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1226 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1287 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1439 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1484 +msgid "layers" +msgstr "vrstev" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:194 +msgid "Don't support bridges" +msgstr "Nevytvářet podpory pod mosty" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:195 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1032 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1382 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1389 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1401 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1411 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1419 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1434 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1455 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1466 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1482 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1491 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1500 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1511 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1527 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1535 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1536 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1545 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1553 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1567 +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:375 +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:376 +msgid "Support material" +msgstr "Podpory" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:196 +msgid "" +"Experimental option for preventing support material from being generated " +"under bridged areas." +msgstr "" +"Experimentální nastavení pro zabránění tvorbě podpěr v oblastech po mosty." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:202 +msgid "Distance between copies" +msgstr "Vzdálenost mezi kopiemi" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:203 +msgid "Distance used for the auto-arrange feature of the plater." +msgstr "" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:211 +msgid "Elefant foot compensation" +msgstr "" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:213 +msgid "" +"The first layer will be shrunk in the XY plane by the configured value to " +"compensate for the 1st layer squish aka an Elefant Foot effect." +msgstr "" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:221 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:231 +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:852 +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:1125 +msgid "End G-code" +msgstr "Konec G-code" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:222 +msgid "" +"This end procedure is inserted at the end of the output file. Note that you " +"can use placeholder variables for all Slic3r settings." +msgstr "" +"Tato ukončovací procedůra je vložena na konec výstupního souboru. Můžete " +"přidávat zástupné proměnné pro veškeré nastavení Slic3ru." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:232 +msgid "" +"This end procedure is inserted at the end of the output file, before the " +"printer end gcode. Note that you can use placeholder variables for all " +"Slic3r settings. If you have multiple extruders, the gcode is processed in " +"extruder order." +msgstr "" +"Tato ukončovací procedůra je vložena na konec výstupního souboru, před " +"konečným g-kódem tiskárny. Můžete přidávat zástupné proměnné pro veškeré " +"nastavení Slic3ru. Pokud máte tiskárnu s více extrudéry, g-kód je zpracován " +"v pořadí extrudérů." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:242 +msgid "Ensure vertical shell thickness" +msgstr "Zajistit vertikální tloušťku obalu" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:244 +msgid "" +"Add solid infill near sloping surfaces to guarantee the vertical shell " +"thickness (top+bottom solid layers)." +msgstr "" +"Přidá plnou výplň u šikmých ploch pro garanci vertikální tloušťku obalu " +"(vrchní a podní plné vrstvy)." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:250 +msgid "Top/bottom fill pattern" +msgstr "Vzor výplně vrchních/spodních vrstev" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:252 +msgid "" +"Fill pattern for top/bottom infill. This only affects the external visible " +"layer, and not its adjacent solid shells." +msgstr "" +"Vzor výplně pro vrchní/spodní vrstvy. Ovlivňuje pouze vnější viditelné " +"vrstvy. Neovlivňuje přilehlé plné obaly." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:271 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:281 +msgid "External perimeters" +msgstr "Vnější perimetry" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:272 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:381 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:594 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:712 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:969 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1294 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1456 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1616 +msgid "Extrusion Width" +msgstr "Šíře extruze" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:273 +msgid "" +"Set this to a non-zero value to set a manual extrusion width for external " +"perimeters. If left zero, default extrusion width will be used if set, " +"otherwise 1.125 x nozzle diameter will be used. If expressed as percentage " +"(for example 200%), it will be computed over layer height." +msgstr "" +"Nastavení na kladnou hodnotu, definuje šířku manuální extruze pro vnější " +"obvod. Pokud je ponechána nula, použije se výchozí šířka extruze, pokud je " +"nastavena, jinak se použije průměr trysky 1,125 x. Pokud je hodnota " +"vyjádřena jako procento (například 200%), vypočítá se podle výšky vrstvy." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:276 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:599 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:717 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:974 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1298 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1460 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1621 +msgid "mm or % (leave 0 for default)" +msgstr "mm nebo % (ponechte 0 jako výchozí)" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:283 +msgid "" +"This separate setting will affect the speed of external perimeters (the " +"visible ones). If expressed as percentage (for example: 80%) it will be " +"calculated on the perimeters speed setting above. Set to zero for auto." +msgstr "" +"Toto oddělené nastavení ovlivní rychlost tisku vnějších perimetrů (těch " +"viditelných). Pokud je hodnota vyjádřena procenty (například: 80%), bude " +"rychlost vypočítána z hodnoty rychlosti tisku perimetrů, nastavené výše. " +"Nastavte nulu pro automatický výpočet." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:286 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:621 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1257 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1308 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1503 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1633 +msgid "mm/s or %" +msgstr "mm nebo %" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:293 +msgid "External perimeters first" +msgstr "Nejprve tisknout vnější perimetry" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:295 +msgid "" +"Print contour perimeters from the outermost one to the innermost one instead " +"of the default inverse order." +msgstr "" +"Tisk obrysových perimetrů od vnějších po vnitřní namísto opačného výchozího " +"pořadí." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:301 +msgid "Extra perimeters if needed" +msgstr "Extra perimetry pokud jsou potřeba" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:303 +#, no-c-format +msgid "" +"Add more perimeters when needed for avoiding gaps in sloping walls. Slic3r " +"keeps adding perimeters, until more than 70% of the loop immediately above " +"is supported." +msgstr "" +"Přidání více perimetrů, pokud je potřeba, pro vyvarování se tvorbě mezer v " +"šikmých plochách. Slic3r pokračuje v přidávání perimetrů, dokud není " +"podepřeno více než 70% perimetrů v následující vrstvě." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:311 +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:794 +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:1231 +msgid "Extruder" +msgstr "Extrudér" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:313 +msgid "" +"The extruder to use (unless more specific extruder settings are specified). " +"This value overrides perimeter and infill extruders, but not the support " +"extruders." +msgstr "" +"Extrudér, který chcete použít (pokud nejsou zvoleny specifičtější nastavení " +"extruderu). Tato hodnota přepíše nastavení perimetrového a výplňového " +"exrtuderu, ale ne nastavení extrudéru pro podpory." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:324 +msgid "Height" +msgstr "Výška" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:325 +msgid "" +"Set this to the vertical distance between your nozzle tip and (usually) the " +"X carriage rods. In other words, this is the height of the clearance " +"cylinder around your extruder, and it represents the maximum depth the " +"extruder can peek before colliding with other printed objects." +msgstr "" +"Zadejte vertikální vzdálenost mezi tryskou a (obvykle) tyčemi osy X. Jinými " +"slovy, je to výška kolizního prostoru okolo extrudéru a představuje " +"maximální hloubku, které může extrudér dosáhnout před kolizí s jinými, již " +"vytištěnými, objekty." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:335 +msgid "Radius" +msgstr "Rádius" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:336 +msgid "" +"Set this to the clearance radius around your extruder. If the extruder is " +"not centered, choose the largest value for safety. This setting is used to " +"check for collisions and to display the graphical preview in the plater." +msgstr "" +"Zadejte horizontální rádius kolizního prostoru okolo extrudéru. Pokud tryska " +"není v centru tohoto rádiusu, zvolte nejdelší vzdálenost. Toto nastavení " +"slouží ke kontrole kolizí a zobrazení grafického náhledu v Plater." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:346 +msgid "Extruder Color" +msgstr "Barva extrudéru" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:347 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:410 +msgid "This is only used in the Slic3r interface as a visual help." +msgstr "Toto je ve Slic3ru jako názorná pomoc." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:354 +msgid "Extruder offset" +msgstr "Odsazení extrudéru" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:355 +msgid "" +"If your firmware doesn't handle the extruder displacement you need the G-" +"code to take it into account. This option lets you specify the displacement " +"of each extruder with respect to the first one. It expects positive " +"coordinates (they will be subtracted from the XY coordinate)." +msgstr "" +"Pokud firmware nezpracovává umístění extrudéru správně, potřebujete aby to " +"vzal G-kód v úvahu. Toto nastavení umožňuje určit odsazení každého extruderu " +"vzhledem k prvnímu. Očekávají se pozitivní souřadnice (budou odečteny od " +"souřadnice XY)." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:364 +msgid "Extrusion axis" +msgstr "Osa extrudéru" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:365 +msgid "" +"Use this option to set the axis letter associated to your printer's extruder " +"(usually E but some printers use A)." +msgstr "" +"Touto volbou nastavíte písmeno osy přidružené k extruderu tiskárny (obvykle " +"E, ale některé tiskárny používají A)." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:371 +msgid "Extrusion multiplier" +msgstr "Násobič extruze" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:372 +msgid "" +"This factor changes the amount of flow proportionally. You may need to tweak " +"this setting to get nice surface finish and correct single wall widths. " +"Usual values are between 0.9 and 1.1. If you think you need to change this " +"more, check filament diameter and your firmware E steps." +msgstr "" +"Tento faktor mění poměrné množství toku. Možná bude třeba toto nastavení " +"vyladit, pro dosažení hezkého povrchu a správné šířky jednotlivých stěn. " +"Obvyklé hodnoty jsou mezi 0,9 a 1,1. Pokud si myslíte, že hodnotu " +"potřebujete změnit více, zkontrolujte průměr vlákna a E kroky ve firmwaru." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:380 +msgid "Default extrusion width" +msgstr "Výchozí šířka extruze" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:382 +msgid "" +"Set this to a non-zero value to allow a manual extrusion width. If left to " +"zero, Slic3r derives extrusion widths from the nozzle diameter (see the " +"tooltips for perimeter extrusion width, infill extrusion width etc). If " +"expressed as percentage (for example: 230%), it will be computed over layer " +"height." +msgstr "" +"Nastavením kladné hodnoty povolíte manuální šířku extruze. Pokud je hodnota " +"ponechána na nule, Slic3r odvozuje šířku extruze z průměru trysky (viz " +"nápovědy pro šířku extruze perimetru, šířku extruze výplně apod.). Pokud je " +"hodnota vyjádřena procenty (například: 230%), vypočítá se z výšky vrstvy." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:386 +msgid "mm or % (leave 0 for auto)" +msgstr "mm or % (pro automatické ponechte 0)" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:391 +msgid "Keep fan always on" +msgstr "Ventilátor vždy zapnutý" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:392 +msgid "" +"If this is enabled, fan will never be disabled and will be kept running at " +"least at its minimum speed. Useful for PLA, harmful for ABS." +msgstr "" +"Pokud je tato funkce zapnutá, ventilátor nebude nikdy vypnut a bude udržován " +"v chodu alespoň rychlostí která je nastavena jako minimální rychlost. " +"Užitečné pro PLA, škodlivé pro ABS." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:398 +msgid "Enable fan if layer print time is below" +msgstr "Zapnout ventilátor pokud je doba tisku vrstvy kratší než" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:399 +msgid "" +"If layer print time is estimated below this number of seconds, fan will be " +"enabled and its speed will be calculated by interpolating the minimum and " +"maximum speeds." +msgstr "" +"Pokud je doba tisku vrstvy odhadnuta jako kratší než tato nastavená hodnota " +"ve vteřinách, ventilátor bude aktivován a jeho rychlost bude vypočtena " +"interpolací minimální a maximální rychlosti." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:401 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1244 +msgid "approximate seconds" +msgstr "vteřin přibližně" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:409 +msgid "Color" +msgstr "Barva" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:416 +msgid "Filament notes" +msgstr "Poznámky k filamentu" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:417 +msgid "You can put your notes regarding the filament here." +msgstr "Zde můžete vložit poznámky týkající se filamentu." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:425 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:819 +msgid "Max volumetric speed" +msgstr "Maximální objemová rychlost" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:426 +msgid "" +"Maximum volumetric speed allowed for this filament. Limits the maximum " +"volumetric speed of a print to the minimum of print and filament volumetric " +"speed. Set to zero for no limit." +msgstr "" +"Maximální povolený objem průtoku pro tento filament. Omezuje maximální " +"rychlost průtoku pro tisk až na minimální rychlost průtoku pro tisk a " +"filament. Zadejte nulu pro nastavení bez omezení." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:429 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:822 +msgid "mm\\u00B3/s" +msgstr "mm\\u00B3/s" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:436 +msgid "" +"Enter your filament diameter here. Good precision is required, so use a " +"caliper and do multiple measurements along the filament, then compute the " +"average." +msgstr "" +"Zde zadejte průměr filamentu. Je zapotřebí správné přesnosti, proto použijte " +"šupleru a proveďte několik měření podél vlákna, poté vypočtete průměr." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:444 +msgid "Density" +msgstr "Hustota" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:445 +msgid "" +"Enter your filament density here. This is only for statistical information. " +"A decent way is to weigh a known length of filament and compute the ratio of " +"the length to volume. Better is to calculate the volume directly through " +"displacement." +msgstr "" +"Zde zadejte hustotu filamentu. Toto je pouze pro statistické informace. " +"Přípustný způsob je zvážit známou délku vlákna a vypočítat poměr délky k " +"objemu. Je lepší vypočítat objem přímo přes posun." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:448 +msgid "g/cm\\u00B3" +msgstr "g/cm\\u00B3" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:454 +msgid "Filament type" +msgstr "Typ filamentu" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:455 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1004 +msgid "" +"If you want to process the output G-code through custom scripts, just list " +"their absolute paths here. Separate multiple scripts with a semicolon. " +"Scripts will be passed the absolute path to the G-code file as the first " +"argument, and they can access the Slic3r config settings by reading " +"environment variables." +msgstr "" +"Pokud chcete zpracovat výstupní G-kód pomocí vlastních skriptů, stačí zde " +"uvést jejich absolutní cesty. Oddělte více skriptů středníkem. Skripty " +"předají absolutní cestu k souboru G-kódu jako první argument a mohou " +"přistupovat k nastavení konfigurace Slic3ru čtením proměnných prostředí." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:474 +msgid "Soluble material" +msgstr "Rozpustný materiál" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:475 +msgid "Soluble material is most likely used for a soluble support." +msgstr "Rozpustný materiál je převážně používán pro tisk rozpustných podpor." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:480 +msgid "Cost" +msgstr "Náklady" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:481 +msgid "" +"Enter your filament cost per kg here. This is only for statistical " +"information." +msgstr "" +"Zde zadejte cenu filamentu za kg. Slouží pouze pro statistické informace." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:482 +msgid "money/kg" +msgstr "korun/kg" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:491 +msgid "Fill angle" +msgstr "Úhel výplně" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:493 +msgid "" +"Default base angle for infill orientation. Cross-hatching will be applied to " +"this. Bridges will be infilled using the best direction Slic3r can detect, " +"so this setting does not affect them." +msgstr "" +"Výchozí základní úhel pro orientaci výplně. Na toto bude použito křížové " +"šrafování. Mosty budou vyplněny nejlepším směrem, který Slic3r dokáže " +"rozpoznat, takže toto nastavení je neovlivní." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:505 +msgid "Fill density" +msgstr "Hustota výplně" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:507 +#, no-c-format +msgid "Density of internal infill, expressed in the range 0% - 100%." +msgstr "Hustota vnitřní výplně, vyjádřená v rozmezí 0% až 100%." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:543 +msgid "Fill pattern" +msgstr "Vzor výplně" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:545 +msgid "Fill pattern for general low-density infill." +msgstr "Vzor výplně pro obecnou výplň s nízkou hustotou." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:575 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:584 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:593 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:627 +msgid "First layer" +msgstr "První vrstva" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:576 +msgid "" +"This is the acceleration your printer will use for first layer. Set zero to " +"disable acceleration control for first layer." +msgstr "" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:585 +msgid "" +"Heated build plate temperature for the first layer. Set this to zero to " +"disable bed temperature control commands in the output." +msgstr "" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:595 +msgid "" +"Set this to a non-zero value to set a manual extrusion width for first " +"layer. You can use this to force fatter extrudates for better adhesion. If " +"expressed as percentage (for example 120%) it will be computed over first " +"layer height. If set to zero, it will use the default extrusion width." +msgstr "" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:605 +msgid "First layer height" +msgstr "Výška první vrstvy" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:607 +msgid "" +"When printing with very low layer heights, you might still want to print a " +"thicker bottom layer to improve adhesion and tolerance for non perfect build " +"plates. This can be expressed as an absolute value or as a percentage (for " +"example: 150%) over the default layer height." +msgstr "" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:611 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:742 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1392 +msgid "mm or %" +msgstr "mm nebo %" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:617 +msgid "First layer speed" +msgstr "Rychlost první vrstvy" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:618 +msgid "" +"If expressed as absolute value in mm/s, this speed will be applied to all " +"the print moves of the first layer, regardless of their type. If expressed " +"as a percentage (for example: 40%) it will scale the default speeds." +msgstr "" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:628 +msgid "" +"Extruder temperature for first layer. If you want to control temperature " +"manually during print, set this to zero to disable temperature control " +"commands in the output file." +msgstr "" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:636 +msgid "Gap fill" +msgstr "Výplň mezer" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:638 +msgid "" +"Speed for filling small gaps using short zigzag moves. Keep this reasonably " +"low to avoid too much shaking and resonance issues. Set zero to disable gaps " +"filling." +msgstr "" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:646 +msgid "Verbose G-code" +msgstr "Verbose G-code" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:647 +msgid "" +"Enable this to get a commented G-code file, with each line explained by a " +"descriptive text. If you print from SD card, the additional weight of the " +"file could make your firmware slow down." +msgstr "" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:654 +msgid "G-code flavor" +msgstr "Druh G-kódu" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:655 +msgid "" +"Some G/M-code commands, including temperature control and others, are not " +"universal. Set this option to your printer's firmware to get a compatible " +"output. The \"No extrusion\" flavor prevents Slic3r from exporting any " +"extrusion value at all." +msgstr "" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:684 +msgid "" +"This is the acceleration your printer will use for infill. Set zero to " +"disable acceleration control for infill." +msgstr "" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:692 +msgid "Combine infill every" +msgstr "Kombinovat výplň každou" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:694 +msgid "" +"This feature allows to combine infill and speed up your print by extruding " +"thicker infill layers while preserving thin perimeters, thus accuracy." +msgstr "" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:698 +msgid "Combine infill every n layers" +msgstr "" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:703 +msgid "Infill extruder" +msgstr "Extruder pro výplň" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:705 +msgid "The extruder to use when printing infill." +msgstr "Extruder který se použije pro tisk výplní." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:713 +msgid "" +"Set this to a non-zero value to set a manual extrusion width for infill. If " +"left zero, default extrusion width will be used if set, otherwise 1.125 x " +"nozzle diameter will be used. You may want to use fatter extrudates to speed " +"up the infill and make your parts stronger. If expressed as percentage (for " +"example 90%) it will be computed over layer height." +msgstr "" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:722 +msgid "Infill before perimeters" +msgstr "Tisknout výplň před tiskem perimetrů" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:723 +msgid "" +"This option will switch the print order of perimeters and infill, making the " +"latter first." +msgstr "" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:728 +msgid "Only infill where needed" +msgstr "Výplň pouze kde je potřeba" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:730 +msgid "" +"This option will limit infill to the areas actually needed for supporting " +"ceilings (it will act as internal support material). If enabled, slows down " +"the G-code generation due to the multiple checks involved." +msgstr "" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:737 +msgid "Infill/perimeters overlap" +msgstr "Přesah pro výplň/perimetry" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:739 +msgid "" +"This setting applies an additional overlap between infill and perimeters for " +"better bonding. Theoretically this shouldn't be needed, but backlash might " +"cause gaps. If expressed as percentage (example: 15%) it is calculated over " +"perimeter extrusion width." +msgstr "" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:750 +msgid "Speed for printing the internal fill. Set to zero for auto." +msgstr "" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:759 +msgid "Interface shells" +msgstr "" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:760 +msgid "" +"Force the generation of solid shells between adjacent materials/volumes. " +"Useful for multi-extruder prints with translucent materials or manual " +"soluble support material." +msgstr "" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:768 +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:1137 +msgid "After layer change G-code" +msgstr "After layer change G-code" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:769 +msgid "" +"This custom code is inserted at every layer change, right after the Z move " +"and before the extruder moves to the first layer point. Note that you can " +"use placeholder variables for all Slic3r settings as well as [layer_num] and " +"[layer_z]." +msgstr "" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:779 +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:315 +msgid "Layer height" +msgstr "Výška vrstvy" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:781 +msgid "" +"This setting controls the height (and thus the total number) of the slices/" +"layers. Thinner layers give better accuracy but take more time to print." +msgstr "" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:789 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:798 +msgid "Max" +msgstr "Maximálně" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:790 +msgid "This setting represents the maximum speed of your fan." +msgstr "" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:799 +#, no-c-format +msgid "" +"This is the highest printable layer height for this extruder, used to cap " +"the variable layer height and support layer height. Maximum recommended " +"layer height is 75% of the extrusion width to achieve reasonable inter-layer " +"adhesion. If set to 0, layer height is limited to 75% of the nozzle diameter." +msgstr "" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:809 +msgid "Max print speed" +msgstr "Maximální rychlost tisku" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:810 +msgid "" +"When setting other speed settings to 0 Slic3r will autocalculate the optimal " +"speed in order to keep constant extruder pressure. This experimental setting " +"is used to set the highest print speed you want to allow." +msgstr "" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:820 +msgid "" +"This experimental setting is used to set the maximum volumetric speed your " +"extruder supports." +msgstr "" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:828 +msgid "Max volumetric slope positive" +msgstr "" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:829 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:840 +msgid "" +"This experimental setting is used to limit the speed of change in extrusion " +"rate. A value of 1.8 mm\\u00B3/s\\u00B2 ensures, that a change from the " +"extrusion rate of 1.8 mm\\u00B3/s (0.45mm extrusion width, 0.2mm extrusion " +"height, feedrate 20 mm/s) to 5.4 mm\\u00B3/s (feedrate 60 mm/s) will take at " +"least 2 seconds." +msgstr "" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:833 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:844 +msgid "mm\\u00B3/s\\u00B2" +msgstr "mm\\u00B3/s\\u00B2" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:839 +msgid "Max volumetric slope negative" +msgstr "" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:850 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:859 +msgid "Min" +msgstr "Minimálně" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:851 +msgid "This setting represents the minimum PWM your fan needs to work." +msgstr "" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:860 +msgid "" +"This is the lowest printable layer height for this extruder and limits the " +"resolution for variable layer height. Typical values are between 0.05 mm and " +"0.1 mm." +msgstr "" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:868 +msgid "Min print speed" +msgstr "Minimální rychlost tisku" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:869 +msgid "Slic3r will not scale speed down below this speed." +msgstr "" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:876 +msgid "Minimum extrusion length" +msgstr "Minimální délka extruze" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:877 +msgid "" +"Generate no less than the number of skirt loops required to consume the " +"specified amount of filament on the bottom layer. For multi-extruder " +"machines, this minimum applies to each extruder." +msgstr "" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:886 +msgid "Configuration notes" +msgstr "Configurační poznámky" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:887 +msgid "" +"You can put here your personal notes. This text will be added to the G-code " +"header comments." +msgstr "" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:896 +msgid "Nozzle diameter" +msgstr "Průměr trysky" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:897 +msgid "" +"This is the diameter of your extruder nozzle (for example: 0.5, 0.35 etc.)" +msgstr "" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:903 +msgid "API Key" +msgstr "Klíč API" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:904 +msgid "" +"Slic3r can upload G-code files to OctoPrint. This field should contain the " +"API Key required for authentication." +msgstr "" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:910 +msgid "Host or IP" +msgstr "Host nebo IP" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:911 +msgid "" +"Slic3r can upload G-code files to OctoPrint. This field should contain the " +"hostname or IP address of the OctoPrint instance." +msgstr "" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:917 +msgid "Only retract when crossing perimeters" +msgstr "" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:918 +msgid "" +"Disables retraction when the travel path does not exceed the upper layer's " +"perimeters (and thus any ooze will be probably invisible)." +msgstr "" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:924 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1697 +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:805 +msgid "Enable" +msgstr "Zapnout" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:925 +msgid "" +"This option will drop the temperature of the inactive extruders to prevent " +"oozing. It will enable a tall skirt automatically and move extruders outside " +"such skirt when changing temperatures." +msgstr "" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:932 +msgid "Output filename format" +msgstr "Formát výstupního názvu" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:933 +msgid "" +"You can use all configuration options as variables inside this template. For " +"example: [layer_height], [fill_density] etc. You can also use [timestamp], " +"[year], [month], [day], [hour], [minute], [second], [version], " +"[input_filename], [input_filename_base]." +msgstr "" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:942 +msgid "Detect bridging perimeters" +msgstr "" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:944 +msgid "" +"Experimental option to adjust flow for overhangs (bridge flow will be used), " +"to apply bridge speed to them and enable fan." +msgstr "" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:950 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:968 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:980 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:990 +msgid "Perimeters" +msgstr "Perimetry" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:951 +msgid "" +"This is the acceleration your printer will use for perimeters. A high value " +"like 9000 usually gives good results if your hardware is up to the job. Set " +"zero to disable acceleration control for perimeters." +msgstr "" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:959 +msgid "Perimeter extruder" +msgstr "Extruder pro perimetry" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:961 +msgid "" +"The extruder to use when printing perimeters and brim. First extruder is 1." +msgstr "" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:970 +msgid "" +"Set this to a non-zero value to set a manual extrusion width for perimeters. " +"You may want to use thinner extrudates to get more accurate surfaces. If " +"left zero, default extrusion width will be used if set, otherwise 1.125 x " +"nozzle diameter will be used. If expressed as percentage (for example 200%) " +"it will be computed over layer height." +msgstr "" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:982 +msgid "" +"Speed for perimeters (contours, aka vertical shells). Set to zero for auto." +msgstr "" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:992 +msgid "" +"This option sets the number of perimeters to generate for each layer. Note " +"that Slic3r may increase this number automatically when it detects sloping " +"surfaces which benefit from a higher number of perimeters if the Extra " +"Perimeters option is enabled." +msgstr "" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:996 +msgid "(minimum)" +msgstr "(minimálně)" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1003 +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:495 +msgid "Post-processing scripts" +msgstr "Post-processing scripts" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1016 +msgid "Printer notes" +msgstr "Poznámky o tiskárně" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1017 +msgid "You can put your notes regarding the printer here." +msgstr "" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1031 +msgid "Raft layers" +msgstr "Vrstev raftu" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1033 +msgid "" +"The object will be raised by this number of layers, and support material " +"will be generated under it." +msgstr "" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1041 +msgid "Resolution" +msgstr "Rozlišení" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1042 +msgid "" +"Minimum detail resolution, used to simplify the input file for speeding up " +"the slicing job and reducing memory usage. High-resolution models often " +"carry more detail than printers can render. Set to zero to disable any " +"simplification and use full resolution from input." +msgstr "" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1052 +msgid "Minimum travel after retraction" +msgstr "" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1053 +msgid "" +"Retraction is not triggered when travel moves are shorter than this length." +msgstr "" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1059 +msgid "Retract amount before wipe" +msgstr "" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1060 +msgid "" +"With bowden extruders, it may be wise to do some amount of quick retract " +"before doing the wipe movement." +msgstr "" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1067 +msgid "Retract on layer change" +msgstr "" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1068 +msgid "This flag enforces a retraction whenever a Z move is done." +msgstr "" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1073 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1082 +msgid "Length" +msgstr "Vzdálenost" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1074 +msgid "Retraction Length" +msgstr "Vzdálenost retrakce" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1075 +msgid "" +"When retraction is triggered, filament is pulled back by the specified " +"amount (the length is measured on raw filament, before it enters the " +"extruder)." +msgstr "" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1077 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1087 +msgid "mm (zero to disable)" +msgstr "mm (nula pro vypnutí)" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1083 +msgid "Retraction Length (Toolchange)" +msgstr "Vzdálenost retrakce (při změně nástroje)" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1084 +msgid "" +"When retraction is triggered before changing tool, filament is pulled back " +"by the specified amount (the length is measured on raw filament, before it " +"enters the extruder)." +msgstr "" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1092 +msgid "Lift Z" +msgstr "Zvednout Z" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1093 +msgid "" +"If you set this to a positive value, Z is quickly raised every time a " +"retraction is triggered. When using multiple extruders, only the setting for " +"the first extruder will be considered." +msgstr "" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1101 +msgid "Above Z" +msgstr "Nad Z" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1102 +msgid "Only lift Z above" +msgstr "Zvednout Z pouze nad" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1103 +msgid "" +"If you set this to a positive value, Z lift will only take place above the " +"specified absolute Z. You can tune this setting for skipping lift on the " +"first layers." +msgstr "" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1110 +msgid "Below Z" +msgstr "Pod Z" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1111 +msgid "Only lift Z below" +msgstr "Zvednout Z pouze pod" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1112 +msgid "" +"If you set this to a positive value, Z lift will only take place below the " +"specified absolute Z. You can tune this setting for limiting lift to the " +"first layers." +msgstr "" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1120 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1128 +msgid "Extra length on restart" +msgstr "Extra vzdálenost při restartu" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1121 +msgid "" +"When the retraction is compensated after the travel move, the extruder will " +"push this additional amount of filament. This setting is rarely needed." +msgstr "" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1129 +msgid "" +"When the retraction is compensated after changing tool, the extruder will " +"push this additional amount of filament." +msgstr "" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1136 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1137 +msgid "Retraction Speed" +msgstr "Rychlost retrakce" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1138 +msgid "The speed for retractions (it only applies to the extruder motor)." +msgstr "" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1144 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1145 +msgid "Deretraction Speed" +msgstr "" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1146 +msgid "" +"The speed for loading of a filament into extruder after retraction (it only " +"applies to the extruder motor). If left to zero, the retraction speed is " +"used." +msgstr "" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1153 +msgid "Seam position" +msgstr "Pozice švu" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1155 +msgid "Position of perimeters starting points." +msgstr "" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1171 +msgid "Direction" +msgstr "Směr" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1173 +msgid "Preferred direction of the seam" +msgstr "Preferovaný směr švu" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1174 +msgid "Seam preferred direction" +msgstr "Preferovaný směr švu" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1182 +msgid "Jitter" +msgstr "" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1184 +msgid "Seam preferred direction jitter" +msgstr "" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1185 +msgid "Preferred direction of the seam - jitter" +msgstr "" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1195 +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:989 +msgid "Serial port" +msgstr "Sériový port" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1196 +msgid "USB/serial port for printer connection." +msgstr "USB/sériový port pro připojení tiskárny." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1204 +msgid "Serial port speed" +msgstr "Rychlost sériového portu" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1205 +msgid "Speed (baud) of USB/serial port for printer connection." +msgstr "Rychlost (baud) USB/sériového portu pro připojení tiskárny." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1214 +msgid "Distance from object" +msgstr "Vzdálenost od objektu" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1215 +msgid "" +"Distance between skirt and object(s). Set this to zero to attach the skirt " +"to the object(s) and get a brim for better adhesion." +msgstr "" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1223 +msgid "Skirt height" +msgstr "Výška skirtu" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1224 +msgid "" +"Height of skirt expressed in layers. Set this to a tall value to use skirt " +"as a shield against drafts." +msgstr "" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1231 +msgid "Loops (minimum)" +msgstr "Smyček (minimálně)" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1232 +msgid "Skirt Loops" +msgstr "Smyček skirtu" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1233 +msgid "" +"Number of loops for the skirt. If the Minimum Extrusion Length option is " +"set, the number of loops might be greater than the one configured here. Set " +"this to zero to disable skirt completely." +msgstr "" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1241 +msgid "Slow down if layer print time is below" +msgstr "Zpomalit tisk pokud je doba tisku kratší než" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1242 +msgid "" +"If layer print time is estimated below this number of seconds, print moves " +"speed will be scaled down to extend duration to this value." +msgstr "" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1252 +msgid "Small perimeters" +msgstr "Malé perimetry" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1254 +msgid "" +"This separate setting will affect the speed of perimeters having radius <= " +"6.5mm (usually holes). If expressed as percentage (for example: 80%) it will " +"be calculated on the perimeters speed setting above. Set to zero for auto." +msgstr "" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1264 +msgid "Solid infill threshold area" +msgstr "Prahová hodnota plochy pro plnou výplň" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1266 +msgid "" +"Force solid infill for regions having a smaller area than the specified " +"threshold." +msgstr "" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1267 +msgid "mm\\u00B2" +msgstr "mm\\u00B2" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1273 +msgid "Solid infill extruder" +msgstr "Extrudér pro plnou výplň" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1275 +msgid "The extruder to use when printing solid infill." +msgstr "" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1281 +msgid "Solid infill every" +msgstr "Plná výplň každou" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1283 +msgid "" +"This feature allows to force a solid layer every given number of layers. " +"Zero to disable. You can set this to any value (for example 9999); Slic3r " +"will automatically choose the maximum possible number of layers to combine " +"according to nozzle diameter and layer height." +msgstr "" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1293 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1303 +msgid "Solid infill" +msgstr "Plná výplň" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1295 +msgid "" +"Set this to a non-zero value to set a manual extrusion width for infill for " +"solid surfaces. If left zero, default extrusion width will be used if set, " +"otherwise 1.125 x nozzle diameter will be used. If expressed as percentage " +"(for example 90%) it will be computed over layer height." +msgstr "" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1305 +msgid "" +"Speed for printing solid regions (top/bottom/internal horizontal shells). " +"This can be expressed as a percentage (for example: 80%) over the default " +"infill speed above. Set to zero for auto." +msgstr "" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1316 +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:331 +msgid "Solid layers" +msgstr "Plných vrstev" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1317 +msgid "Number of solid layers to generate on top and bottom surfaces." +msgstr "Počet plných vstev generovaných vrchních a spodních površích." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1324 +msgid "Spiral vase" +msgstr "Spirálová váza" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1325 +msgid "" +"This feature will raise Z gradually while printing a single-walled object in " +"order to remove any visible seam. This option requires a single perimeter, " +"no infill, no top solid layers and no support material. You can still set " +"any number of bottom solid layers as well as skirt/brim loops. It won't work " +"when printing more than an object." +msgstr "" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1334 +msgid "Temperature variation" +msgstr "Temperature variation" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1335 +msgid "" +"Temperature difference to be applied when an extruder is not active. Enables " +"a full-height \"sacrificial\" skirt on which the nozzles are periodically " +"wiped." +msgstr "" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1344 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1359 +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:846 +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:1119 +msgid "Start G-code" +msgstr "Začátek G-kódu" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1345 +msgid "" +"This start procedure is inserted at the beginning, after bed has reached the " +"target temperature and extruder just started heating, and before extruder " +"has finished heating. If Slic3r detects M104 or M190 in your custom codes, " +"such commands will not be prepended automatically so you're free to " +"customize the order of heating commands and other custom actions. Note that " +"you can use placeholder variables for all Slic3r settings, so you can put a " +"\"M109 S[first_layer_temperature]\" command wherever you want." +msgstr "" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1360 +msgid "" +"This start procedure is inserted at the beginning, after any printer start " +"gcode. This is used to override settings for a specific filament. If Slic3r " +"detects M104, M109, M140 or M190 in your custom codes, such commands will " +"not be prepended automatically so you're free to customize the order of " +"heating commands and other custom actions. Note that you can use placeholder " +"variables for all Slic3r settings, so you can put a \"M109 " +"S[first_layer_temperature]\" command wherever you want. If you have multiple " +"extruders, the gcode is processed in extruder order." +msgstr "" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1375 +msgid "Single Extruder Multi Material" +msgstr "Multi Materiálový tisk s jedním extrudérem" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1376 +msgid "The printer multiplexes filaments into a single hot end." +msgstr "" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1381 +msgid "Generate support material" +msgstr "Generovat podpory" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1383 +msgid "Enable support material generation." +msgstr "" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1388 +msgid "XY separation between an object and its support" +msgstr "XY vzdálenost mezi objektem a podporami" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1390 +msgid "" +"XY separation between an object and its support. If expressed as percentage " +"(for example 50%), it will be calculated over external perimeter width." +msgstr "" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1400 +msgid "Pattern angle" +msgstr "Úhel vzoru" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1402 +msgid "" +"Use this setting to rotate the support material pattern on the horizontal " +"plane." +msgstr "" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1410 +msgid "Support on build plate only" +msgstr "Podpory pouze na tiskové ploše" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1412 +msgid "" +"Only create support if it lies on a build plate. Don't create support on a " +"print." +msgstr "" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1418 +msgid "Contact Z distance" +msgstr "Kontaktní vzdálenost Z" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1420 +msgid "" +"The vertical distance between object and support material interface. Setting " +"this to 0 will also prevent Slic3r from using bridge flow and speed for the " +"first object layer." +msgstr "" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1433 +msgid "Enforce support for the first" +msgstr "Zesílit podpory pro prvních" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1435 +msgid "" +"Generate support material for the specified number of layers counting from " +"bottom, regardless of whether normal support material is enabled or not and " +"regardless of any angle threshold. This is useful for getting more adhesion " +"of objects having a very thin or poor footprint on the build plate." +msgstr "" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1441 +msgid "Enforce support for the first n layers" +msgstr "" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1446 +msgid "Support material/raft/skirt extruder" +msgstr "Support material/raft/skirt extruder" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1448 +msgid "" +"The extruder to use when printing support material, raft and skirt (1+, 0 to " +"use the current extruder to minimize tool changes)." +msgstr "" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1457 +msgid "" +"Set this to a non-zero value to set a manual extrusion width for support " +"material. If left zero, default extrusion width will be used if set, " +"otherwise nozzle diameter will be used. If expressed as percentage (for " +"example 90%) it will be computed over layer height." +msgstr "" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1465 +msgid "Interface loops" +msgstr "" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1467 +msgid "" +"Cover the top contact layer of the supports with loops. Disabled by default." +msgstr "" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1472 +msgid "Support material/raft interface extruder" +msgstr "" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1474 +msgid "" +"The extruder to use when printing support material interface (1+, 0 to use " +"the current extruder to minimize tool changes). This affects raft too." +msgstr "" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1481 +msgid "Interface layers" +msgstr "" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1483 +msgid "" +"Number of interface layers to insert between the object(s) and support " +"material." +msgstr "" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1490 +msgid "Interface pattern spacing" +msgstr "" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1492 +msgid "Spacing between interface lines. Set zero to get a solid interface." +msgstr "" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1499 +msgid "Support material interface" +msgstr "Support material interface" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1501 +msgid "" +"Speed for printing support material interface layers. If expressed as " +"percentage (for example 50%) it will be calculated over support material " +"speed." +msgstr "" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1510 +msgid "Pattern" +msgstr "Vzor" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1512 +msgid "Pattern used to generate support material." +msgstr "" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1526 +msgid "Pattern spacing" +msgstr "Vzdálenost vzoru" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1528 +msgid "Spacing between support material lines." +msgstr "" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1537 +msgid "Speed for printing support material." +msgstr "" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1544 +msgid "Synchronize with object layers" +msgstr "Synchronizovat s vrstvami objektu" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1546 +msgid "" +"Synchronize support layers with the object print layers. This is useful with " +"multi-material printers, where the extruder switch is expensive." +msgstr "" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1552 +msgid "Overhang threshold" +msgstr "Práh přesahu" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1554 +msgid "" +"Support material will not be generated for overhangs whose slope angle " +"(90\\u00B0 = vertical) is above the given threshold. In other words, this " +"value represent the most horizontal slope (measured from the horizontal " +"plane) that you can print without support material. Set to zero for " +"automatic detection (recommended)." +msgstr "" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1566 +msgid "With sheath around the support" +msgstr "S pouzdrem okolo podpor" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1568 +msgid "" +"Add a sheath (a single perimeter line) around the base support. This makes " +"the support more reliable, but also more difficult to remove." +msgstr "" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1575 +msgid "" +"Extruder temperature for layers after the first one. Set this to zero to " +"disable temperature control commands in the output." +msgstr "" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1578 +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:793 +msgid "Temperature" +msgstr "Teplota" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1584 +msgid "Detect thin walls" +msgstr "Detekovat tenké zdi" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1586 +msgid "" +"Detect single-width walls (parts where two extrusions don't fit and we need " +"to collapse them into a single trace)." +msgstr "" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1592 +msgid "Threads" +msgstr "" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1593 +msgid "" +"Threads are used to parallelize long-running tasks. Optimal threads number " +"is slightly above the number of available cores/processors." +msgstr "" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1604 +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:1143 +msgid "Tool change G-code" +msgstr "Tool change G-code" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1605 +msgid "" +"This custom code is inserted right before every extruder change. Note that " +"you can use placeholder variables for all Slic3r settings as well as " +"[previous_extruder] and [next_extruder]." +msgstr "" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1615 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1626 +msgid "Top solid infill" +msgstr "Vrchní plná výplň" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1617 +msgid "" +"Set this to a non-zero value to set a manual extrusion width for infill for " +"top surfaces. You may want to use thinner extrudates to fill all narrow " +"regions and get a smoother finish. If left zero, default extrusion width " +"will be used if set, otherwise nozzle diameter will be used. If expressed as " +"percentage (for example 90%) it will be computed over layer height." +msgstr "" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1628 +msgid "" +"Speed for printing top solid layers (it only applies to the uppermost " +"external layers and not to their internal solid layers). You may want to " +"slow down this to get a nicer surface finish. This can be expressed as a " +"percentage (for example: 80%) over the solid infill speed above. Set to zero " +"for auto." +msgstr "" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1640 +msgid "Top" +msgstr "Vrchní" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1642 +msgid "Number of solid layers to generate on top surfaces." +msgstr "" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1644 +msgid "Top solid layers" +msgstr "Vrchních plných vrstev" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1649 +msgid "Travel" +msgstr "Přesun" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1650 +msgid "Speed for travel moves (jumps between distant extrusion points)." +msgstr "" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1658 +msgid "Use firmware retraction" +msgstr "Použít retrakce z firmware" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1659 +msgid "" +"This experimental setting uses G10 and G11 commands to have the firmware " +"handle the retraction. This is only supported in recent Marlin." +msgstr "" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1665 +msgid "Use relative E distances" +msgstr "Použít relativní E vzdálenosti" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1666 +msgid "" +"If your firmware requires relative E values, check this, otherwise leave it " +"unchecked. Most firmwares use absolute values." +msgstr "" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1672 +msgid "Use volumetric E" +msgstr "" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1673 +msgid "" +"This experimental setting uses outputs the E values in cubic millimeters " +"instead of linear millimeters. If your firmware doesn't already know " +"filament diameter(s), you can put commands like 'M200 D[filament_diameter_0] " +"T0' in your start G-code in order to turn volumetric mode on and use the " +"filament diameter associated to the filament selected in Slic3r. This is " +"only supported in recent Marlin." +msgstr "" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1683 +msgid "Enable variable layer height feature" +msgstr "Zapnout variabilní výšku vrstev" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1684 +msgid "" +"Some printers or printer setups may have difficulties printing with a " +"variable layer height. Enabled by default." +msgstr "" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1690 +msgid "Wipe while retracting" +msgstr "Očistit při retrakci" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1691 +msgid "" +"This flag will move the nozzle while retracting to minimize the possible " +"blob on leaky extruders." +msgstr "" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1698 +msgid "" +"Multi material printers may need to prime or purge extruders on tool " +"changes. Extrude the excess material into the wipe tower." +msgstr "" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1704 +msgid "Position X" +msgstr "Pozice X" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1705 +msgid "X coordinate of the left front corner of a wipe tower" +msgstr "" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1711 +msgid "Position Y" +msgstr "Pozice Y" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1712 +msgid "Y coordinate of the left front corner of a wipe tower" +msgstr "" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1718 +msgid "Width" +msgstr "Šířka" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1719 +msgid "Width of a wipe tower" +msgstr "Šířka čistící věže" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1725 +msgid "Per color change depth" +msgstr "Hloubka výměny pro barvu" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1726 +msgid "" +"Depth of a wipe color per color change. For N colors, there will be maximum " +"(N-1) tool switches performed, therefore the total depth of the wipe tower " +"will be (N-1) times this value." +msgstr "" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1734 +msgid "XY Size Compensation" +msgstr "Kompenzace XY rozměrů" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1736 +msgid "" +"The object will be grown/shrunk in the XY plane by the configured value " +"(negative = inwards, positive = outwards). This might be useful for fine-" +"tuning hole sizes." +msgstr "" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1744 +msgid "Z offset" +msgstr "Odsazení Z" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1745 +msgid "" +"This value will be added (or subtracted) from all the Z coordinates in the " +"output G-code. It is used to compensate for bad Z endstop position: for " +"example, if your endstop zero actually leaves the nozzle 0.3mm far from the " +"print bed, set this to -0.3 (or fix your endstop)." +msgstr "" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\BedShapeDialog.cpp:39 +msgid "Shape" +msgstr "Tvar" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\BedShapeDialog.cpp:46 +msgid "Rectangular" +msgstr "Obdélníkový" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\BedShapeDialog.cpp:62 +msgid "Circular" +msgstr "Kruhový" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\BedShapeDialog.cpp:75 +msgid "Load shape from STL..." +msgstr "Načíst tvar ze souboru STL…" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\BedShapeDialog.cpp:120 +msgid "Settings" +msgstr "Nastavení" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\BedShapeDialog.cpp:298 +msgid "Choose a file to import bed shape from (STL/OBJ/AMF/PRUSA):" +msgstr "Výběr souboru pro import tvaru tiskové podložky (STL/OBJ/AMF/PRUSA):" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\BedShapeDialog.cpp:315 +msgid "Error! " +msgstr "Chyba! " + +#: c:\src\Slic3r\xs\src\slic3r\GUI\BedShapeDialog.cpp:324 +msgid "The selected file contains no geometry." +msgstr "Vybraný soubor neobsahuje geometrii." + +#: c:\src\Slic3r\xs\src\slic3r\GUI\BedShapeDialog.cpp:328 +msgid "" +"The selected file contains several disjoint areas. This is not supported." +msgstr "" +"Vybraný soubor obsahuje několik nespojených ploch. Tato možnost není " +"podporována." + +#: c:\src\Slic3r\xs\src\slic3r\GUI\BedShapeDialog.hpp:42 +msgid "Bed Shape" +msgstr "Tvar tiskové podložky" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\GUI.cpp:468 +msgid "Error" +msgstr "Chyba" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\GUI.cpp:473 +msgid "Notice" +msgstr "Oznámení" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:50 +msgid "Save current " +msgstr "Uložit stávající " + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:51 +msgid "Delete this preset" +msgstr "Smazat přednastavení" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:330 +msgid "Horizontal shells" +msgstr "Horizontal shells" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:336 +msgid "Quality (slower slicing)" +msgstr "Kvalita (pomalejší slicing)" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:353 +msgid "Reducing printing time" +msgstr "Zkracování tiskového času" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:365 +msgid "Skirt and brim" +msgstr "Skirt and brim" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:381 +msgid "Raft" +msgstr "Raft" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:412 +msgid "Speed for non-print moves" +msgstr "Speed for non-print moves" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:415 +msgid "Modifiers" +msgstr "Modifikátory" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:418 +msgid "Acceleration control (advanced)" +msgstr "Kontrola akcelerací (pokročilé)" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:425 +msgid "Autospeed (advanced)" +msgstr "Automatická rychlost (pokročilé)" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:431 +msgid "Multiple Extruders" +msgstr "Multiple Extruders" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:439 +msgid "Ooze prevention" +msgstr "Ooze prevention" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:464 +msgid "Overlap" +msgstr "Překrytí" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:467 +msgid "Flow" +msgstr "Průtok" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:470 +msgid "Other" +msgstr "Ostatní" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:477 +msgid "Output options" +msgstr "Možnosti výstupu" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:478 +msgid "Sequential printing" +msgstr "Sekvenční tisk" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:501 +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:502 +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:858 +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:859 +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:1155 +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:1156 +msgid "Notes" +msgstr "Poznámky" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:508 +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:866 +msgid "Dependencies" +msgstr "Závislosti" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:509 +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:867 +msgid "Profile dependencies" +msgstr "Profilové závislosti" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:799 +msgid "Bed" +msgstr "Tisková podložka" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:804 +msgid "Cooling" +msgstr "Chlazení" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:816 +msgid "Fan settings" +msgstr "Nastavení ventilátoru" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:835 +msgid "Print speed override" +msgstr "Přepsání rychlosti tisku" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:845 +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:1118 +msgid "Custom G-code" +msgstr "Upravený G-kód" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:936 +msgid "General" +msgstr "Obecné" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:937 +msgid "Size and coordinates" +msgstr "Rozměr a souřadnice" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:941 +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:1642 +msgid "Set" +msgstr "Nastavit" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:961 +msgid "Capabilities" +msgstr "Možnosti" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:1003 +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:1071 +msgid "Test" +msgstr "Test" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:1016 +msgid "Connection to printer works correctly." +msgstr "Připojení k tiskárně pracuje správně." + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:1016 +msgid "Success!" +msgstr "Úspěch!" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:1019 +msgid "Connection failed." +msgstr "Připojení selhalo." + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:1031 +msgid "OctoPrint upload" +msgstr "OctoPrint nahrávání" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:1034 +msgid "Browse" +msgstr "Procházet" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:1046 +msgid "Button BROWSE was clicked!" +msgstr "Tlačítko PROCHÁZET bylo stisknuto!" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:1081 +msgid "Button TEST was clicked!" +msgstr "Tlačítko TEST bylo stisknuto!" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:1109 +msgid "Firmware" +msgstr "Firmware" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:1191 +msgid "Layer height limits" +msgstr "Výskové limity vrstvy" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:1196 +msgid "Position (for multi-extruder printers)" +msgstr "Position (for multi-extruder printers)" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:1215 +msgid "" +"Retraction when tool is disabled (advanced settings for multi-extruder " +"setups)" +msgstr "" +"Retraction when tool is disabled (advanced settings for multi-extruder " +"setups)" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:1219 +msgid "Preview" +msgstr "Náhled" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:1310 +msgid "" +"The Wipe option is not available when using the Firmware Retraction mode.\n" +"\n" +"Shall I disable it in order to enable Firmware Retraction?" +msgstr "" +"The Wipe option is not available when using the Firmware Retraction mode.\n" +"\n" +"Shall I disable it in order to enable Firmware Retraction?" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:1558 +msgid "The supplied name is empty. It can't be saved." +msgstr "The supplied name is empty. It can't be saved." + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:1569 +msgid "Something is wrong. It can't be saved." +msgstr "Něco se pokazilo. Nemůže být uloženo." + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:1586 +msgid "remove" +msgstr "odebrat" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:1586 +msgid "delete" +msgstr "smazat" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:1587 +msgid "Are you sure you want to " +msgstr "Jste si jistý že chcete " + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:1587 +msgid " the selected preset?" +msgstr " zvolené přednastavení?" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:1588 +msgid "Remove" +msgstr "Odebrat" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:1588 +msgid "Delete" +msgstr "Smazat" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:1589 +msgid " Preset" +msgstr " Přednastavení" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:1641 +msgid "All" +msgstr "Vše" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:1672 +msgid "Select the printers this profile is compatible with." +msgstr "Select the printers this profile is compatible with." + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:1756 +msgid "Save " +msgstr "Uložit " + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:1756 +msgid " as:" +msgstr " jako:" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:1790 +msgid "" +"The supplied name is not valid; the following characters are not allowed:" +msgstr "" +"The supplied name is not valid; the following characters are not allowed:" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:1793 +msgid "The supplied name is not available." +msgstr "The supplied name is not available." + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.hpp:182 +msgid "Print Settings" +msgstr "Nastavení tisku" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.hpp:202 +msgid "Filament Settings" +msgstr "Nastavení Filamentu" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.hpp:248 +msgid "Save preset" +msgstr "Uložit přednastavení" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Field.cpp:35 +msgid "default" +msgstr "výchozí" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\BedShapeDialog.cpp:71 +msgid "Custom" +msgstr "Upravený" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\GUI.cpp:212 +msgid "Array of language names and identifiers should have the same size." +msgstr "" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\GUI.cpp:223 +msgid "Select the language" +msgstr "Výběr jazyka" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\GUI.cpp:223 +msgid "Language" +msgstr "Jazyk" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\GUI.cpp:321 +msgid "Change Application Language" +msgstr "Změnit Jazyk Aplikace" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:314 +msgid "Layers and perimeters" +msgstr "Vrstvy a perimetry" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:319 +msgid "Vertical shells" +msgstr "Vertical shells" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:366 +msgid "Skirt" +msgstr "Skirt" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:372 +msgid "Brim" +msgstr "Brim" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:385 +msgid "Options for support material and raft" +msgstr "Options for support material and raft" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:400 +msgid "Speed for print moves" +msgstr "Speed for print moves" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:443 +msgid "Wipe tower" +msgstr "Čistící věž" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:454 +msgid "Extrusion width" +msgstr "Šířka extruze" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:480 +msgid "Extruder clearance (mm)" +msgstr "" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:489 +msgid "Output file" +msgstr "Výstupní soubor" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:534 +#, no-c-format +msgid "" +"The Spiral Vase mode requires:\n" +"- one perimeter\n" +"- no top solid layers\n" +"- 0% fill density\n" +"- no support material\n" +"- no ensure_vertical_shell_thickness\n" +"\n" +"Shall I adjust those settings in order to enable Spiral Vase?" +msgstr "" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:541 +msgid "Spiral Vase" +msgstr "Spirálová váza" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:560 +msgid "" +"The Wipe Tower currently supports only:\n" +"- first layer height 0.2mm\n" +"- layer height from 0.15mm to 0.35mm\n" +"\n" +"Shall I adjust those settings in order to enable the Wipe Tower?" +msgstr "" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:564 +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:585 +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:602 +msgid "Wipe Tower" +msgstr "Čistící věž" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:581 +msgid "" +"The Wipe Tower currently supports the non-soluble supports only\n" +"if they are printed with the current extruder without triggering a tool " +"change.\n" +"(both support_material_extruder and support_material_interface_extruder need " +"to be set to 0).\n" +"\n" +"Shall I adjust those settings in order to enable the Wipe Tower?" +msgstr "" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:599 +msgid "" +"For the Wipe Tower to work with the soluble supports, the support layers\n" +"need to be synchronized with the object layers.\n" +"\n" +"Shall I synchronize support layers in order to enable the Wipe Tower?" +msgstr "" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:617 +msgid "" +"Supports work better, if the following feature is enabled:\n" +"- Detect bridging perimeters\n" +"\n" +"Shall I adjust those settings for supports?" +msgstr "" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:620 +msgid "Support Generator" +msgstr "Generátor Podpor" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:662 +msgid "The " +msgstr "" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:662 +#, no-c-format +msgid "" +" infill pattern is not supposed to work at 100% density.\n" +"\n" +"Shall I switch to rectilinear fill pattern?" +msgstr "" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:785 +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:786 +msgid "Filament" +msgstr "Filament" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:817 +msgid "Fan speed" +msgstr "Rychlost ventilátoru" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:825 +msgid "Cooling thresholds" +msgstr "Práh chlazení" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:831 +msgid "Filament properties" +msgstr "Vlastnosti filamentu" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:988 +msgid "USB/Serial connection" +msgstr "USB/Sériové připojení" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:994 +msgid "Rescan serial ports" +msgstr "Znovu prohledat sériové porty" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:1149 +msgid "Between objects G-code (for sequential printing)" +msgstr "Between objects G-code (for sequential printing)" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:1185 +msgid "Extruder " +msgstr "Extrudér " + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:1199 +msgid "Retraction" +msgstr "Retrakce" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:1202 +msgid "Only lift Z" +msgstr "Pouze zvednout Z" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:1312 +msgid "Firmware Retraction" +msgstr "Firmware Retrakce" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:1467 +msgid "Default " +msgstr "Výchozí " + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:1467 +msgid " preset" +msgstr " přednastavení" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:1468 +msgid " preset\n" +msgstr " přednastavení\n" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:1486 +msgid "" +"\n" +"\n" +"is not compatible with printer\n" +msgstr "" +"\n" +"\n" +"není kompatibilní s tiskárnou\n" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:1486 +msgid "" +"\n" +"\n" +"and it has the following unsaved changes:" +msgstr "" +"\n" +"\n" +"a má neuložené následující změny:" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:1487 +msgid "" +"\n" +"\n" +"has the following unsaved changes:" +msgstr "" +"\n" +"\n" +"má neuložené následující změny:" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:1489 +msgid "" +"\n" +"\n" +"Discard changes and continue anyway?" +msgstr "" +"\n" +"\n" +"Zahodit změny a přesto pokračovat?" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:1490 +msgid "Unsaved Changes" +msgstr "Neuložené Změny" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.hpp:228 +msgid "Printer Settings" +msgstr "Nastavení tiskárny" diff --git a/resources/localization/en_US/Slic3rPE.mo b/resources/localization/en_US/Slic3rPE.mo new file mode 100644 index 000000000..f967df550 Binary files /dev/null and b/resources/localization/en_US/Slic3rPE.mo differ diff --git a/resources/localization/en_US/Slic3rPE_en.po b/resources/localization/en_US/Slic3rPE_en.po new file mode 100644 index 000000000..b0ee7f2e5 --- /dev/null +++ b/resources/localization/en_US/Slic3rPE_en.po @@ -0,0 +1,3016 @@ +# Copyright (C) 2018 THE Slic3rPE'S COPYRIGHT HOLDER +# This file is distributed under the same license as the Slic3rPE package. +# Oleksandra Iushchenko , 2018. +# +msgid "" +msgstr "" +"Project-Id-Version: SLIC3R PE VERSION\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2018-02-13 17:18+0100\n" +"PO-Revision-Date: 2018-02-15 18:17+0100\n" +"Last-Translator: Oleksandra Iushchenko \n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"X-Generator: Poedit 2.0.6\n" +"Plural-Forms: nplurals=2; plural=(n != 1);\n" +"Language: en_US\n" +"X-Poedit-KeywordsList: _L\n" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\BedShapeDialog.cpp:50 +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:1188 +msgid "Size" +msgstr "Size" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\BedShapeDialog.cpp:51 +msgid "Size in X and Y of the rectangular plate." +msgstr "Size in X and Y of the rectangular plate." + +#: c:\src\Slic3r\xs\src\slic3r\GUI\BedShapeDialog.cpp:57 +msgid "Origin" +msgstr "Origin" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\BedShapeDialog.cpp:58 +msgid "" +"Distance of the 0,0 G-code coordinate from the front left corner of the " +"rectangle." +msgstr "" +"Distance of the 0,0 G-code coordinate from the front left corner of the " +"rectangle." + +#: c:\src\Slic3r\xs\src\slic3r\GUI\BedShapeDialog.cpp:65 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:133 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:204 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:215 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:329 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:340 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:359 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:438 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:783 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:803 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:862 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:880 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:898 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1046 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1054 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1096 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1105 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1115 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1123 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1131 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1217 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1423 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1493 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1529 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1706 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1713 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1720 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1729 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1739 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1749 +msgid "mm" +msgstr "mm" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\BedShapeDialog.cpp:66 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:435 +msgid "Diameter" +msgstr "Diameter" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\BedShapeDialog.cpp:67 +msgid "" +"Diameter of the print bed. It is assumed that origin (0,0) is located in the " +"center." +msgstr "" +"Diameter of the print bed. It is assumed that origin (0,0) is located in the " +"center." + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:965 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:312 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:704 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:960 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1274 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1447 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1473 +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:432 +msgid "Extruders" +msgstr "Extruders" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:966 +msgid "Number of extruders of the printer." +msgstr "Number of extruders of the printer." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:30 +msgid "Avoid crossing perimeters" +msgstr "Avoid crossing perimeters" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:31 +msgid "" +"Optimize travel moves in order to minimize the crossing of perimeters. This " +"is mostly useful with Bowden extruders which suffer from oozing. This " +"feature slows down both the print and the G-code generation." +msgstr "" +"Optimize travel moves in order to minimize the crossing of perimeters. This " +"is mostly useful with Bowden extruders which suffer from oozing. This " +"feature slows down both the print and the G-code generation." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:38 +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:939 +msgid "Bed shape" +msgstr "Bed shape" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:42 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1574 +msgid "Other layers" +msgstr "Other layers" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:43 +msgid "" +"Bed temperature for layers after the first one. Set this to zero to disable " +"bed temperature control commands in the output." +msgstr "" +"Bed temperature for layers after the first one. Set this to zero to disable " +"bed temperature control commands in the output." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:46 +msgid "Bed temperature" +msgstr "Bed temperature" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:52 +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:1131 +msgid "Before layer change G-code" +msgstr "Before layer change G-code" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:53 +msgid "" +"This custom code is inserted at every layer change, right before the Z move. " +"Note that you can use placeholder variables for all Slic3r settings as well " +"as [layer_num] and [layer_z]." +msgstr "" +"This custom code is inserted at every layer change, right before the Z move. " +"Note that you can use placeholder variables for all Slic3r settings as well " +"as [layer_num] and [layer_z]." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:63 +msgid "Between objects G-code" +msgstr "Between objects G-code" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:64 +msgid "" +"This code is inserted between objects when using sequential printing. By " +"default extruder and bed temperature are reset using non-wait command; " +"however if M104, M109, M140 or M190 are detected in this custom code, Slic3r " +"will not add temperature commands. Note that you can use placeholder " +"variables for all Slic3r settings, so you can put a \"M109 " +"S[first_layer_temperature]\" command wherever you want." +msgstr "" +"This code is inserted between objects when using sequential printing. By " +"default extruder and bed temperature are reset using non-wait command; " +"however if M104, M109, M140 or M190 are detected in this custom code, Slic3r " +"will not add temperature commands. Note that you can use placeholder " +"variables for all Slic3r settings, so you can put a \"M109 " +"S[first_layer_temperature]\" command wherever you want." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:72 +msgid "Bottom" +msgstr "Bottom" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:73 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:243 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:294 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:302 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:606 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:764 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:780 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:943 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:991 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1154 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1585 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1641 +msgid "Layers and Perimeters" +msgstr "Layers and perimeters" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:74 +msgid "Number of solid layers to generate on bottom surfaces." +msgstr "Number of solid layers to generate on bottom surfaces." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:76 +msgid "Bottom solid layers" +msgstr "Bottom solid layers" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:81 +msgid "Bridge" +msgstr "Bridge" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:82 +msgid "" +"This is the acceleration your printer will use for bridges. Set zero to " +"disable acceleration control for bridges." +msgstr "" +"This is the acceleration your printer will use for bridges. Set zero to " +"disable acceleration control for bridges." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:84 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:178 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:578 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:686 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:954 +msgid "mm/s\\u00B2" +msgstr "mm/s\\u00B2" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:90 +msgid "Bridging angle" +msgstr "Bridging angle" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:91 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:251 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:492 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:506 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:544 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:683 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:693 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:711 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:729 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:748 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1265 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1282 +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:347 +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:348 +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:664 +msgid "Infill" +msgstr "Infill" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:92 +msgid "" +"Bridging angle override. If left to zero, the bridging angle will be " +"calculated automatically. Otherwise the provided angle will be used for all " +"bridges. Use 180\\u00B0 for zero angle." +msgstr "" +"Bridging angle override. If left to zero, the bridging angle will be " +"calculated automatically. Otherwise the provided angle will be used for all " +"bridges. Use 180\\u00B0 for zero angle." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:95 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:496 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1172 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1183 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1403 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1559 +msgid "\\u00B0" +msgstr "\\u00B0" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:101 +msgid "Bridges fan speed" +msgstr "Bridges fan speed" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:102 +msgid "This fan speed is enforced during all bridges and overhangs." +msgstr "This fan speed is enforced during all bridges and overhangs." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:103 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:508 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:791 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:852 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1062 +msgid "%" +msgstr "%" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:110 +msgid "Bridge flow ratio" +msgstr "Bridge flow ratio" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:111 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:212 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:738 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1735 +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:343 +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:357 +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:450 +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:453 +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:830 +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:1112 +msgid "Advanced" +msgstr "Advanced" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:112 +msgid "" +"This factor affects the amount of plastic for bridging. You can decrease it " +"slightly to pull the extrudates and prevent sagging, although default " +"settings are usually good and you should experiment with cooling (use a fan) " +"before tweaking this." +msgstr "" +"This factor affects the amount of plastic for bridging. You can decrease it " +"slightly to pull the extrudates and prevent sagging, although default " +"settings are usually good and you should experiment with cooling (use a fan) " +"before tweaking this." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:121 +msgid "Bridges" +msgstr "Bridges" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:122 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:282 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:637 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:749 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:981 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1203 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1253 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1304 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1627 +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:399 +msgid "Speed" +msgstr "Speed" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:123 +msgid "Speed for printing bridges." +msgstr "Speed for printing bridges." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:124 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:640 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:751 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:813 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:870 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:983 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1139 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1148 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1538 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1651 +msgid "mm/s" +msgstr "mm/s" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:131 +msgid "Brim width" +msgstr "Brim width" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:132 +msgid "" +"Horizontal width of the brim that will be printed around each object on the " +"first layer." +msgstr "" +"Horizontal width of the brim that will be printed around each object on the " +"first layer." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:139 +msgid "Clip multi-part objects" +msgstr "Clip multi-part objects" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:140 +msgid "" +"When printing multi-material objects, this settings will make slic3r to clip " +"the overlapping object parts one by the other (2nd part will be clipped by " +"the 1st, 3rd part will be clipped by the 1st and 2nd etc)." +msgstr "" +"When printing multi-material objects, this settings will make slic3r to clip " +"the overlapping object parts one by the other (2nd part will be clipped by " +"the 1st, 3rd part will be clipped by the 1st and 2nd etc)." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:147 +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:510 +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:868 +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:1673 +msgid "Compatible printers" +msgstr "Compatible printers" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:151 +msgid "Compatible printers condition" +msgstr "Compatible printers condition" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:152 +msgid "" +"A boolean expression using the configuration values of an active printer " +"profile. If this expression evaluates to true, this profile is considered " +"compatible with the active printer profile." +msgstr "" +"A boolean expression using the configuration values of an active printer " +"profile. If this expression evaluates to true, this profile is considered " +"compatible with the active printer profile." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:158 +msgid "Complete individual objects" +msgstr "Complete individual objects" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:159 +msgid "" +"When printing multiple objects or copies, this feature will complete each " +"object before moving onto next one (and starting it from its bottom layer). " +"This feature is useful to avoid the risk of ruined prints. Slic3r should " +"warn and prevent you from extruder collisions, but beware." +msgstr "" +"When printing multiple objects or copies, this feature will complete each " +"object before moving onto next one (and starting it from its bottom layer). " +"This feature is useful to avoid the risk of ruined prints. Slic3r should " +"warn and prevent you from extruder collisions, but beware." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:167 +msgid "Enable auto cooling" +msgstr "Enable auto cooling" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:168 +msgid "" +"This flag enables the automatic cooling logic that adjusts print speed and " +"fan speed according to layer printing time." +msgstr "" +"This flag enables the automatic cooling logic that adjusts print speed and " +"fan speed according to layer printing time." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:174 +#: c:\src\Slic3r\xs\src\slic3r\GUI\GUI.cpp:293 +msgid "Default" +msgstr "Default" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:175 +msgid "" +"This is the acceleration your printer will be reset to after the role-" +"specific acceleration values are used (perimeter/infill). Set zero to " +"prevent resetting acceleration at all." +msgstr "" +"This is the acceleration your printer will be reset to after the role-" +"specific acceleration values are used (perimeter/infill). Set zero to " +"prevent resetting acceleration at all." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:184 +msgid "Disable fan for the first" +msgstr "Disable fan for the first" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:185 +msgid "" +"You can set this to a positive value to disable fan at all during the first " +"layers, so that it does not make adhesion worse." +msgstr "" +"You can set this to a positive value to disable fan at all during the first " +"layers, so that it does not make adhesion worse." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:187 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:696 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1035 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1226 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1287 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1439 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1484 +msgid "layers" +msgstr "layers" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:194 +msgid "Don't support bridges" +msgstr "Don't support bridges" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:195 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1032 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1382 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1389 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1401 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1411 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1419 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1434 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1455 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1466 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1482 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1491 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1500 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1511 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1527 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1535 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1536 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1545 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1553 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1567 +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:375 +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:376 +msgid "Support material" +msgstr "Support material" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:196 +msgid "" +"Experimental option for preventing support material from being generated " +"under bridged areas." +msgstr "" +"Experimental option for preventing support material from being generated " +"under bridged areas." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:202 +msgid "Distance between copies" +msgstr "Distance between copies" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:203 +msgid "Distance used for the auto-arrange feature of the plater." +msgstr "Distance used for the auto-arrange feature of the plater." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:211 +msgid "Elefant foot compensation" +msgstr "Elefant foot compensation" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:213 +msgid "" +"The first layer will be shrunk in the XY plane by the configured value to " +"compensate for the 1st layer squish aka an Elefant Foot effect." +msgstr "" +"The first layer will be shrunk in the XY plane by the configured value to " +"compensate for the 1st layer squish aka an Elefant Foot effect." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:221 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:231 +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:852 +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:1125 +msgid "End G-code" +msgstr "End G-code" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:222 +msgid "" +"This end procedure is inserted at the end of the output file. Note that you " +"can use placeholder variables for all Slic3r settings." +msgstr "" +"This end procedure is inserted at the end of the output file. Note that you " +"can use placeholder variables for all Slic3r settings." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:232 +msgid "" +"This end procedure is inserted at the end of the output file, before the " +"printer end gcode. Note that you can use placeholder variables for all " +"Slic3r settings. If you have multiple extruders, the gcode is processed in " +"extruder order." +msgstr "" +"This end procedure is inserted at the end of the output file, before the " +"printer end gcode. Note that you can use placeholder variables for all " +"Slic3r settings. If you have multiple extruders, the gcode is processed in " +"extruder order." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:242 +msgid "Ensure vertical shell thickness" +msgstr "Ensure vertical shell thickness" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:244 +msgid "" +"Add solid infill near sloping surfaces to guarantee the vertical shell " +"thickness (top+bottom solid layers)." +msgstr "" +"Add solid infill near sloping surfaces to guarantee the vertical shell " +"thickness (top+bottom solid layers)." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:250 +msgid "Top/bottom fill pattern" +msgstr "Top/bottom fill pattern" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:252 +msgid "" +"Fill pattern for top/bottom infill. This only affects the external visible " +"layer, and not its adjacent solid shells." +msgstr "" +"Fill pattern for top/bottom infill. This only affects the external visible " +"layer, and not its adjacent solid shells." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:271 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:281 +msgid "External perimeters" +msgstr "External perimeters" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:272 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:381 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:594 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:712 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:969 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1294 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1456 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1616 +msgid "Extrusion Width" +msgstr "Extrusion width" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:273 +msgid "" +"Set this to a non-zero value to set a manual extrusion width for external " +"perimeters. If left zero, default extrusion width will be used if set, " +"otherwise 1.125 x nozzle diameter will be used. If expressed as percentage " +"(for example 200%), it will be computed over layer height." +msgstr "" +"Set this to a non-zero value to set a manual extrusion width for external " +"perimeters. If left zero, default extrusion width will be used if set, " +"otherwise 1.125 x nozzle diameter will be used. If expressed as percentage " +"(for example 200%), it will be computed over layer height." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:276 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:599 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:717 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:974 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1298 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1460 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1621 +msgid "mm or % (leave 0 for default)" +msgstr "mm or % (leave 0 for default)" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:283 +msgid "" +"This separate setting will affect the speed of external perimeters (the " +"visible ones). If expressed as percentage (for example: 80%) it will be " +"calculated on the perimeters speed setting above. Set to zero for auto." +msgstr "" +"This separate setting will affect the speed of external perimeters (the " +"visible ones). If expressed as percentage (for example: 80%) it will be " +"calculated on the perimeters speed setting above. Set to zero for auto." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:286 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:621 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1257 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1308 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1503 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1633 +msgid "mm/s or %" +msgstr "mm/s or %" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:293 +msgid "External perimeters first" +msgstr "External perimeters first" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:295 +msgid "" +"Print contour perimeters from the outermost one to the innermost one instead " +"of the default inverse order." +msgstr "" +"Print contour perimeters from the outermost one to the innermost one instead " +"of the default inverse order." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:301 +msgid "Extra perimeters if needed" +msgstr "Extra perimeters if needed" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:303 +#, c-format +msgid "" +"Add more perimeters when needed for avoiding gaps in sloping walls. Slic3r " +"keeps adding perimeters, until more than 70% of the loop immediately above " +"is supported." +msgstr "" +"Add more perimeters when needed for avoiding gaps in sloping walls. Slic3r " +"keeps adding perimeters, until more than 70% of the loop immediately above " +"is supported." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:311 +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:794 +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:1231 +msgid "Extruder" +msgstr "Extruder" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:313 +msgid "" +"The extruder to use (unless more specific extruder settings are specified). " +"This value overrides perimeter and infill extruders, but not the support " +"extruders." +msgstr "" +"The extruder to use (unless more specific extruder settings are specified). " +"This value overrides perimeter and infill extruders, but not the support " +"extruders." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:324 +msgid "Height" +msgstr "Height" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:325 +msgid "" +"Set this to the vertical distance between your nozzle tip and (usually) the " +"X carriage rods. In other words, this is the height of the clearance " +"cylinder around your extruder, and it represents the maximum depth the " +"extruder can peek before colliding with other printed objects." +msgstr "" +"Set this to the vertical distance between your nozzle tip and (usually) the " +"X carriage rods. In other words, this is the height of the clearance " +"cylinder around your extruder, and it represents the maximum depth the " +"extruder can peek before colliding with other printed objects." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:335 +msgid "Radius" +msgstr "Radius" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:336 +msgid "" +"Set this to the clearance radius around your extruder. If the extruder is " +"not centered, choose the largest value for safety. This setting is used to " +"check for collisions and to display the graphical preview in the plater." +msgstr "" +"Set this to the clearance radius around your extruder. If the extruder is " +"not centered, choose the largest value for safety. This setting is used to " +"check for collisions and to display the graphical preview in the plater." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:346 +msgid "Extruder Color" +msgstr "Extruder Color" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:347 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:410 +msgid "This is only used in the Slic3r interface as a visual help." +msgstr "This is only used in the Slic3r interface as a visual help." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:354 +msgid "Extruder offset" +msgstr "Extruders offset" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:355 +msgid "" +"If your firmware doesn't handle the extruder displacement you need the G-" +"code to take it into account. This option lets you specify the displacement " +"of each extruder with respect to the first one. It expects positive " +"coordinates (they will be subtracted from the XY coordinate)." +msgstr "" +"If your firmware doesn't handle the extruder displacement you need the G-" +"code to take it into account. This option lets you specify the displacement " +"of each extruder with respect to the first one. It expects positive " +"coordinates (they will be subtracted from the XY coordinate)." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:364 +msgid "Extrusion axis" +msgstr "Extrusion axis" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:365 +msgid "" +"Use this option to set the axis letter associated to your printer's extruder " +"(usually E but some printers use A)." +msgstr "" +"Use this option to set the axis letter associated to your printer's extruder " +"(usually E but some printers use A)." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:371 +msgid "Extrusion multiplier" +msgstr "Extrusion multiplier" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:372 +msgid "" +"This factor changes the amount of flow proportionally. You may need to tweak " +"this setting to get nice surface finish and correct single wall widths. " +"Usual values are between 0.9 and 1.1. If you think you need to change this " +"more, check filament diameter and your firmware E steps." +msgstr "" +"This factor changes the amount of flow proportionally. You may need to tweak " +"this setting to get nice surface finish and correct single wall widths. " +"Usual values are between 0.9 and 1.1. If you think you need to change this " +"more, check filament diameter and your firmware E steps." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:380 +msgid "Default extrusion width" +msgstr "Default extrusion width" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:382 +msgid "" +"Set this to a non-zero value to allow a manual extrusion width. If left to " +"zero, Slic3r derives extrusion widths from the nozzle diameter (see the " +"tooltips for perimeter extrusion width, infill extrusion width etc). If " +"expressed as percentage (for example: 230%), it will be computed over layer " +"height." +msgstr "" +"Set this to a non-zero value to allow a manual extrusion width. If left to " +"zero, Slic3r derives extrusion widths from the nozzle diameter (see the " +"tooltips for perimeter extrusion width, infill extrusion width etc). If " +"expressed as percentage (for example: 230%), it will be computed over layer " +"height." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:386 +msgid "mm or % (leave 0 for auto)" +msgstr "mm or % (leave 0 for auto)" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:391 +msgid "Keep fan always on" +msgstr "Keep fan always on" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:392 +msgid "" +"If this is enabled, fan will never be disabled and will be kept running at " +"least at its minimum speed. Useful for PLA, harmful for ABS." +msgstr "" +"If this is enabled, fan will never be disabled and will be kept running at " +"least at its minimum speed. Useful for PLA, harmful for ABS." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:398 +msgid "Enable fan if layer print time is below" +msgstr "Enable fan if layer print time is below" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:399 +msgid "" +"If layer print time is estimated below this number of seconds, fan will be " +"enabled and its speed will be calculated by interpolating the minimum and " +"maximum speeds." +msgstr "" +"If layer print time is estimated below this number of seconds, fan will be " +"enabled and its speed will be calculated by interpolating the minimum and " +"maximum speeds." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:401 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1244 +msgid "approximate seconds" +msgstr "approximate seconds" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:409 +msgid "Color" +msgstr "Color" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:416 +msgid "Filament notes" +msgstr "Filament notes" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:417 +msgid "You can put your notes regarding the filament here." +msgstr "You can put your notes regarding the filament here." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:425 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:819 +msgid "Max volumetric speed" +msgstr "Max volumetric speed" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:426 +msgid "" +"Maximum volumetric speed allowed for this filament. Limits the maximum " +"volumetric speed of a print to the minimum of print and filament volumetric " +"speed. Set to zero for no limit." +msgstr "" +"Maximum volumetric speed allowed for this filament. Limits the maximum " +"volumetric speed of a print to the minimum of print and filament volumetric " +"speed. Set to zero for no limit." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:429 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:822 +msgid "mm\\u00B3/s" +msgstr "mm\\u00B3/s" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:436 +msgid "" +"Enter your filament diameter here. Good precision is required, so use a " +"caliper and do multiple measurements along the filament, then compute the " +"average." +msgstr "" +"Enter your filament diameter here. Good precision is required, so use a " +"caliper and do multiple measurements along the filament, then compute the " +"average." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:444 +msgid "Density" +msgstr "Density" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:445 +msgid "" +"Enter your filament density here. This is only for statistical information. " +"A decent way is to weigh a known length of filament and compute the ratio of " +"the length to volume. Better is to calculate the volume directly through " +"displacement." +msgstr "" +"Enter your filament density here. This is only for statistical information. " +"A decent way is to weigh a known length of filament and compute the ratio of " +"the length to volume. Better is to calculate the volume directly through " +"displacement." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:448 +msgid "g/cm\\u00B3" +msgstr "g/cm\\u00B3" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:454 +msgid "Filament type" +msgstr "Filament type" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:455 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1004 +msgid "" +"If you want to process the output G-code through custom scripts, just list " +"their absolute paths here. Separate multiple scripts with a semicolon. " +"Scripts will be passed the absolute path to the G-code file as the first " +"argument, and they can access the Slic3r config settings by reading " +"environment variables." +msgstr "" +"If you want to process the output G-code through custom scripts, just list " +"their absolute paths here. Separate multiple scripts with a semicolon. " +"Scripts will be passed the absolute path to the G-code file as the first " +"argument, and they can access the Slic3r config settings by reading " +"environment variables." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:474 +msgid "Soluble material" +msgstr "Soluble material" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:475 +msgid "Soluble material is most likely used for a soluble support." +msgstr "Soluble material is most likely used for a soluble support." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:480 +msgid "Cost" +msgstr "Cost" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:481 +msgid "" +"Enter your filament cost per kg here. This is only for statistical " +"information." +msgstr "" +"Enter your filament cost per kg here. This is only for statistical " +"information." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:482 +msgid "money/kg" +msgstr "money/kg" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:491 +msgid "Fill angle" +msgstr "Fill angle" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:493 +msgid "" +"Default base angle for infill orientation. Cross-hatching will be applied to " +"this. Bridges will be infilled using the best direction Slic3r can detect, " +"so this setting does not affect them." +msgstr "" +"Default base angle for infill orientation. Cross-hatching will be applied to " +"this. Bridges will be infilled using the best direction Slic3r can detect, " +"so this setting does not affect them." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:505 +msgid "Fill density" +msgstr "Fill density" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:507 +#, c-format +msgid "Density of internal infill, expressed in the range 0% - 100%." +msgstr "Density of internal infill, expressed in the range 0% - 100%." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:543 +msgid "Fill pattern" +msgstr "Fill pattern" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:545 +msgid "Fill pattern for general low-density infill." +msgstr "Fill pattern for general low-density infill." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:575 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:584 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:593 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:627 +msgid "First layer" +msgstr "First layers" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:576 +msgid "" +"This is the acceleration your printer will use for first layer. Set zero to " +"disable acceleration control for first layer." +msgstr "" +"This is the acceleration your printer will use for first layer. Set zero to " +"disable acceleration control for first layer." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:585 +msgid "" +"Heated build plate temperature for the first layer. Set this to zero to " +"disable bed temperature control commands in the output." +msgstr "" +"Heated build plate temperature for the first layer. Set this to zero to " +"disable bed temperature control commands in the output." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:595 +msgid "" +"Set this to a non-zero value to set a manual extrusion width for first " +"layer. You can use this to force fatter extrudates for better adhesion. If " +"expressed as percentage (for example 120%) it will be computed over first " +"layer height. If set to zero, it will use the default extrusion width." +msgstr "" +"Set this to a non-zero value to set a manual extrusion width for first " +"layer. You can use this to force fatter extrudates for better adhesion. If " +"expressed as percentage (for example 120%) it will be computed over first " +"layer height. If set to zero, it will use the default extrusion width." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:605 +msgid "First layer height" +msgstr "First layer height" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:607 +msgid "" +"When printing with very low layer heights, you might still want to print a " +"thicker bottom layer to improve adhesion and tolerance for non perfect build " +"plates. This can be expressed as an absolute value or as a percentage (for " +"example: 150%) over the default layer height." +msgstr "" +"When printing with very low layer heights, you might still want to print a " +"thicker bottom layer to improve adhesion and tolerance for non perfect build " +"plates. This can be expressed as an absolute value or as a percentage (for " +"example: 150%) over the default layer height." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:611 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:742 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1392 +msgid "mm or %" +msgstr "mm or %" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:617 +msgid "First layer speed" +msgstr "First layer speed" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:618 +msgid "" +"If expressed as absolute value in mm/s, this speed will be applied to all " +"the print moves of the first layer, regardless of their type. If expressed " +"as a percentage (for example: 40%) it will scale the default speeds." +msgstr "" +"If expressed as absolute value in mm/s, this speed will be applied to all " +"the print moves of the first layer, regardless of their type. If expressed " +"as a percentage (for example: 40%) it will scale the default speeds." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:628 +msgid "" +"Extruder temperature for first layer. If you want to control temperature " +"manually during print, set this to zero to disable temperature control " +"commands in the output file." +msgstr "" +"Extruder temperature for first layer. If you want to control temperature " +"manually during print, set this to zero to disable temperature control " +"commands in the output file." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:636 +msgid "Gap fill" +msgstr "Gap fill" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:638 +msgid "" +"Speed for filling small gaps using short zigzag moves. Keep this reasonably " +"low to avoid too much shaking and resonance issues. Set zero to disable gaps " +"filling." +msgstr "" +"Speed for filling small gaps using short zigzag moves. Keep this reasonably " +"low to avoid too much shaking and resonance issues. Set zero to disable gaps " +"filling." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:646 +msgid "Verbose G-code" +msgstr "Verbose G-code" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:647 +msgid "" +"Enable this to get a commented G-code file, with each line explained by a " +"descriptive text. If you print from SD card, the additional weight of the " +"file could make your firmware slow down." +msgstr "" +"Enable this to get a commented G-code file, with each line explained by a " +"descriptive text. If you print from SD card, the additional weight of the " +"file could make your firmware slow down." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:654 +msgid "G-code flavor" +msgstr "G-code flavor" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:655 +msgid "" +"Some G/M-code commands, including temperature control and others, are not " +"universal. Set this option to your printer's firmware to get a compatible " +"output. The \"No extrusion\" flavor prevents Slic3r from exporting any " +"extrusion value at all." +msgstr "" +"Some G/M-code commands, including temperature control and others, are not " +"universal. Set this option to your printer's firmware to get a compatible " +"output. The \"No extrusion\" flavor prevents Slic3r from exporting any " +"extrusion value at all." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:684 +msgid "" +"This is the acceleration your printer will use for infill. Set zero to " +"disable acceleration control for infill." +msgstr "" +"This is the acceleration your printer will use for infill. Set zero to " +"disable acceleration control for infill." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:692 +msgid "Combine infill every" +msgstr "Combine infill every" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:694 +msgid "" +"This feature allows to combine infill and speed up your print by extruding " +"thicker infill layers while preserving thin perimeters, thus accuracy." +msgstr "" +"This feature allows to combine infill and speed up your print by extruding " +"thicker infill layers while preserving thin perimeters, thus accuracy." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:698 +msgid "Combine infill every n layers" +msgstr "Combine infill every n layers" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:703 +msgid "Infill extruder" +msgstr "Infill extruder" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:705 +msgid "The extruder to use when printing infill." +msgstr "The extruder to use when printing infill." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:713 +msgid "" +"Set this to a non-zero value to set a manual extrusion width for infill. If " +"left zero, default extrusion width will be used if set, otherwise 1.125 x " +"nozzle diameter will be used. You may want to use fatter extrudates to speed " +"up the infill and make your parts stronger. If expressed as percentage (for " +"example 90%) it will be computed over layer height." +msgstr "" +"Set this to a non-zero value to set a manual extrusion width for infill. If " +"left zero, default extrusion width will be used if set, otherwise 1.125 x " +"nozzle diameter will be used. You may want to use fatter extrudates to speed " +"up the infill and make your parts stronger. If expressed as percentage (for " +"example 90%) it will be computed over layer height." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:722 +msgid "Infill before perimeters" +msgstr "Infill before perimeters" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:723 +msgid "" +"This option will switch the print order of perimeters and infill, making the " +"latter first." +msgstr "" +"This option will switch the print order of perimeters and infill, making the " +"latter first." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:728 +msgid "Only infill where needed" +msgstr "Only infill where needed" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:730 +msgid "" +"This option will limit infill to the areas actually needed for supporting " +"ceilings (it will act as internal support material). If enabled, slows down " +"the G-code generation due to the multiple checks involved." +msgstr "" +"This option will limit infill to the areas actually needed for supporting " +"ceilings (it will act as internal support material). If enabled, slows down " +"the G-code generation due to the multiple checks involved." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:737 +msgid "Infill/perimeters overlap" +msgstr "Infill/perimeters overlap" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:739 +msgid "" +"This setting applies an additional overlap between infill and perimeters for " +"better bonding. Theoretically this shouldn't be needed, but backlash might " +"cause gaps. If expressed as percentage (example: 15%) it is calculated over " +"perimeter extrusion width." +msgstr "" +"This setting applies an additional overlap between infill and perimeters for " +"better bonding. Theoretically this shouldn't be needed, but backlash might " +"cause gaps. If expressed as percentage (example: 15%) it is calculated over " +"perimeter extrusion width." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:750 +msgid "Speed for printing the internal fill. Set to zero for auto." +msgstr "Speed for printing the internal fill. Set to zero for auto." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:759 +msgid "Interface shells" +msgstr "Interface shells" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:760 +msgid "" +"Force the generation of solid shells between adjacent materials/volumes. " +"Useful for multi-extruder prints with translucent materials or manual " +"soluble support material." +msgstr "" +"Force the generation of solid shells between adjacent materials/volumes. " +"Useful for multi-extruder prints with translucent materials or manual " +"soluble support material." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:768 +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:1137 +msgid "After layer change G-code" +msgstr "After layer change G-code" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:769 +msgid "" +"This custom code is inserted at every layer change, right after the Z move " +"and before the extruder moves to the first layer point. Note that you can " +"use placeholder variables for all Slic3r settings as well as [layer_num] and " +"[layer_z]." +msgstr "" +"This custom code is inserted at every layer change, right after the Z move " +"and before the extruder moves to the first layer point. Note that you can " +"use placeholder variables for all Slic3r settings as well as [layer_num] and " +"[layer_z]." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:779 +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:315 +msgid "Layer height" +msgstr "Layer height" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:781 +msgid "" +"This setting controls the height (and thus the total number) of the slices/" +"layers. Thinner layers give better accuracy but take more time to print." +msgstr "" +"This setting controls the height (and thus the total number) of the slices/" +"layers. Thinner layers give better accuracy but take more time to print." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:789 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:798 +msgid "Max" +msgstr "Max" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:790 +msgid "This setting represents the maximum speed of your fan." +msgstr "This setting represents the maximum speed of your fan." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:799 +#, c-format +msgid "" +"This is the highest printable layer height for this extruder, used to cap " +"the variable layer height and support layer height. Maximum recommended " +"layer height is 75% of the extrusion width to achieve reasonable inter-layer " +"adhesion. If set to 0, layer height is limited to 75% of the nozzle diameter." +msgstr "" +"This is the highest printable layer height for this extruder, used to cap " +"the variable layer height and support layer height. Maximum recommended " +"layer height is 75% of the extrusion width to achieve reasonable inter-layer " +"adhesion. If set to 0, layer height is limited to 75% of the nozzle diameter." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:809 +msgid "Max print speed" +msgstr "Max print speed" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:810 +msgid "" +"When setting other speed settings to 0 Slic3r will autocalculate the optimal " +"speed in order to keep constant extruder pressure. This experimental setting " +"is used to set the highest print speed you want to allow." +msgstr "" +"When setting other speed settings to 0 Slic3r will autocalculate the optimal " +"speed in order to keep constant extruder pressure. This experimental setting " +"is used to set the highest print speed you want to allow." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:820 +msgid "" +"This experimental setting is used to set the maximum volumetric speed your " +"extruder supports." +msgstr "" +"This experimental setting is used to set the maximum volumetric speed your " +"extruder supports." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:828 +msgid "Max volumetric slope positive" +msgstr "Max volumetric slope positive" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:829 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:840 +msgid "" +"This experimental setting is used to limit the speed of change in extrusion " +"rate. A value of 1.8 mm\\u00B3/s\\u00B2 ensures, that a change from the " +"extrusion rate of 1.8 mm\\u00B3/s (0.45mm extrusion width, 0.2mm extrusion " +"height, feedrate 20 mm/s) to 5.4 mm\\u00B3/s (feedrate 60 mm/s) will take at " +"least 2 seconds." +msgstr "" +"This experimental setting is used to limit the speed of change in extrusion " +"rate. A value of 1.8 mm\\u00B3/s\\u00B2 ensures, that a change from the " +"extrusion rate of 1.8 mm\\u00B3/s (0.45mm extrusion width, 0.2mm extrusion " +"height, feedrate 20 mm/s) to 5.4 mm\\u00B3/s (feedrate 60 mm/s) will take at " +"least 2 seconds." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:833 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:844 +msgid "mm\\u00B3/s\\u00B2" +msgstr "mm\\u00B3/s\\u00B2" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:839 +msgid "Max volumetric slope negative" +msgstr "Max volumetric slope negative" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:850 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:859 +msgid "Min" +msgstr "Min" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:851 +msgid "This setting represents the minimum PWM your fan needs to work." +msgstr "This setting represents the minimum PWM your fan needs to work." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:860 +msgid "" +"This is the lowest printable layer height for this extruder and limits the " +"resolution for variable layer height. Typical values are between 0.05 mm and " +"0.1 mm." +msgstr "" +"This is the lowest printable layer height for this extruder and limits the " +"resolution for variable layer height. Typical values are between 0.05 mm and " +"0.1 mm." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:868 +msgid "Min print speed" +msgstr "Min print speed" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:869 +msgid "Slic3r will not scale speed down below this speed." +msgstr "Slic3r will not scale speed down below this speed." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:876 +msgid "Minimum extrusion length" +msgstr "Minimum extrusion length" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:877 +msgid "" +"Generate no less than the number of skirt loops required to consume the " +"specified amount of filament on the bottom layer. For multi-extruder " +"machines, this minimum applies to each extruder." +msgstr "" +"Generate no less than the number of skirt loops required to consume the " +"specified amount of filament on the bottom layer. For multi-extruder " +"machines, this minimum applies to each extruder." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:886 +msgid "Configuration notes" +msgstr "Configuration notes" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:887 +msgid "" +"You can put here your personal notes. This text will be added to the G-code " +"header comments." +msgstr "" +"You can put here your personal notes. This text will be added to the G-code " +"header comments." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:896 +msgid "Nozzle diameter" +msgstr "Nozzle diameter" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:897 +msgid "" +"This is the diameter of your extruder nozzle (for example: 0.5, 0.35 etc.)" +msgstr "" +"This is the diameter of your extruder nozzle (for example: 0.5, 0.35 etc.)" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:903 +msgid "API Key" +msgstr "API Key" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:904 +msgid "" +"Slic3r can upload G-code files to OctoPrint. This field should contain the " +"API Key required for authentication." +msgstr "" +"Slic3r can upload G-code files to OctoPrint. This field should contain the " +"API Key required for authentication." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:910 +msgid "Host or IP" +msgstr "Host or IP" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:911 +msgid "" +"Slic3r can upload G-code files to OctoPrint. This field should contain the " +"hostname or IP address of the OctoPrint instance." +msgstr "" +"Slic3r can upload G-code files to OctoPrint. This field should contain the " +"hostname or IP address of the OctoPrint instance." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:917 +msgid "Only retract when crossing perimeters" +msgstr "Only retract when crossing perimeters" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:918 +msgid "" +"Disables retraction when the travel path does not exceed the upper layer's " +"perimeters (and thus any ooze will be probably invisible)." +msgstr "" +"Disables retraction when the travel path does not exceed the upper layer's " +"perimeters (and thus any ooze will be probably invisible)." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:924 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1697 +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:805 +msgid "Enable" +msgstr "Enable" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:925 +msgid "" +"This option will drop the temperature of the inactive extruders to prevent " +"oozing. It will enable a tall skirt automatically and move extruders outside " +"such skirt when changing temperatures." +msgstr "" +"This option will drop the temperature of the inactive extruders to prevent " +"oozing. It will enable a tall skirt automatically and move extruders outside " +"such skirt when changing temperatures." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:932 +msgid "Output filename format" +msgstr "Output filename format" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:933 +msgid "" +"You can use all configuration options as variables inside this template. For " +"example: [layer_height], [fill_density] etc. You can also use [timestamp], " +"[year], [month], [day], [hour], [minute], [second], [version], " +"[input_filename], [input_filename_base]." +msgstr "" +"You can use all configuration options as variables inside this template. For " +"example: [layer_height], [fill_density] etc. You can also use [timestamp], " +"[year], [month], [day], [hour], [minute], [second], [version], " +"[input_filename], [input_filename_base]." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:942 +msgid "Detect bridging perimeters" +msgstr "Detect bridging perimeters" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:944 +msgid "" +"Experimental option to adjust flow for overhangs (bridge flow will be used), " +"to apply bridge speed to them and enable fan." +msgstr "" +"Experimental option to adjust flow for overhangs (bridge flow will be used), " +"to apply bridge speed to them and enable fan." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:950 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:968 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:980 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:990 +msgid "Perimeters" +msgstr "Perimeters" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:951 +msgid "" +"This is the acceleration your printer will use for perimeters. A high value " +"like 9000 usually gives good results if your hardware is up to the job. Set " +"zero to disable acceleration control for perimeters." +msgstr "" +"This is the acceleration your printer will use for perimeters. A high value " +"like 9000 usually gives good results if your hardware is up to the job. Set " +"zero to disable acceleration control for perimeters." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:959 +msgid "Perimeter extruder" +msgstr "Perimeter extruder" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:961 +msgid "" +"The extruder to use when printing perimeters and brim. First extruder is 1." +msgstr "" +"The extruder to use when printing perimeters and brim. First extruder is 1." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:970 +msgid "" +"Set this to a non-zero value to set a manual extrusion width for perimeters. " +"You may want to use thinner extrudates to get more accurate surfaces. If " +"left zero, default extrusion width will be used if set, otherwise 1.125 x " +"nozzle diameter will be used. If expressed as percentage (for example 200%) " +"it will be computed over layer height." +msgstr "" +"Set this to a non-zero value to set a manual extrusion width for perimeters. " +"You may want to use thinner extrudates to get more accurate surfaces. If " +"left zero, default extrusion width will be used if set, otherwise 1.125 x " +"nozzle diameter will be used. If expressed as percentage (for example 200%) " +"it will be computed over layer height." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:982 +msgid "" +"Speed for perimeters (contours, aka vertical shells). Set to zero for auto." +msgstr "" +"Speed for perimeters (contours, aka vertical shells). Set to zero for auto." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:992 +msgid "" +"This option sets the number of perimeters to generate for each layer. Note " +"that Slic3r may increase this number automatically when it detects sloping " +"surfaces which benefit from a higher number of perimeters if the Extra " +"Perimeters option is enabled." +msgstr "" +"This option sets the number of perimeters to generate for each layer. Note " +"that Slic3r may increase this number automatically when it detects sloping " +"surfaces which benefit from a higher number of perimeters if the Extra " +"Perimeters option is enabled." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:996 +msgid "(minimum)" +msgstr "(minimum)" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1003 +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:495 +msgid "Post-processing scripts" +msgstr "Post-processing scripts" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1016 +msgid "Printer notes" +msgstr "Printer notes" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1017 +msgid "You can put your notes regarding the printer here." +msgstr "You can put your notes regarding the printer here." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1031 +msgid "Raft layers" +msgstr "Raft layers" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1033 +msgid "" +"The object will be raised by this number of layers, and support material " +"will be generated under it." +msgstr "" +"The object will be raised by this number of layers, and support material " +"will be generated under it." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1041 +msgid "Resolution" +msgstr "Resolution" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1042 +msgid "" +"Minimum detail resolution, used to simplify the input file for speeding up " +"the slicing job and reducing memory usage. High-resolution models often " +"carry more detail than printers can render. Set to zero to disable any " +"simplification and use full resolution from input." +msgstr "" +"Minimum detail resolution, used to simplify the input file for speeding up " +"the slicing job and reducing memory usage. High-resolution models often " +"carry more detail than printers can render. Set to zero to disable any " +"simplification and use full resolution from input." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1052 +msgid "Minimum travel after retraction" +msgstr "Minimum travel after retraction" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1053 +msgid "" +"Retraction is not triggered when travel moves are shorter than this length." +msgstr "" +"Retraction is not triggered when travel moves are shorter than this length." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1059 +msgid "Retract amount before wipe" +msgstr "Retract amount before wipe" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1060 +msgid "" +"With bowden extruders, it may be wise to do some amount of quick retract " +"before doing the wipe movement." +msgstr "" +"With bowden extruders, it may be wise to do some amount of quick retract " +"before doing the wipe movement." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1067 +msgid "Retract on layer change" +msgstr "Retract on layer change" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1068 +msgid "This flag enforces a retraction whenever a Z move is done." +msgstr "This flag enforces a retraction whenever a Z move is done." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1073 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1082 +msgid "Length" +msgstr "Length" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1074 +msgid "Retraction Length" +msgstr "Retraction Length" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1075 +msgid "" +"When retraction is triggered, filament is pulled back by the specified " +"amount (the length is measured on raw filament, before it enters the " +"extruder)." +msgstr "" +"When retraction is triggered, filament is pulled back by the specified " +"amount (the length is measured on raw filament, before it enters the " +"extruder)." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1077 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1087 +msgid "mm (zero to disable)" +msgstr "mm (zero to disable)" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1083 +msgid "Retraction Length (Toolchange)" +msgstr "Retraction Length (Toolchange)" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1084 +msgid "" +"When retraction is triggered before changing tool, filament is pulled back " +"by the specified amount (the length is measured on raw filament, before it " +"enters the extruder)." +msgstr "" +"When retraction is triggered before changing tool, filament is pulled back " +"by the specified amount (the length is measured on raw filament, before it " +"enters the extruder)." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1092 +msgid "Lift Z" +msgstr "Lift Z" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1093 +msgid "" +"If you set this to a positive value, Z is quickly raised every time a " +"retraction is triggered. When using multiple extruders, only the setting for " +"the first extruder will be considered." +msgstr "" +"If you set this to a positive value, Z is quickly raised every time a " +"retraction is triggered. When using multiple extruders, only the setting for " +"the first extruder will be considered." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1101 +msgid "Above Z" +msgstr "Above Z" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1102 +msgid "Only lift Z above" +msgstr "Only lift Z above" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1103 +msgid "" +"If you set this to a positive value, Z lift will only take place above the " +"specified absolute Z. You can tune this setting for skipping lift on the " +"first layers." +msgstr "" +"If you set this to a positive value, Z lift will only take place above the " +"specified absolute Z. You can tune this setting for skipping lift on the " +"first layers." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1110 +msgid "Below Z" +msgstr "Below Z" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1111 +msgid "Only lift Z below" +msgstr "Only lift Z below" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1112 +msgid "" +"If you set this to a positive value, Z lift will only take place below the " +"specified absolute Z. You can tune this setting for limiting lift to the " +"first layers." +msgstr "" +"If you set this to a positive value, Z lift will only take place below the " +"specified absolute Z. You can tune this setting for limiting lift to the " +"first layers." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1120 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1128 +msgid "Extra length on restart" +msgstr "Extra length on restart" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1121 +msgid "" +"When the retraction is compensated after the travel move, the extruder will " +"push this additional amount of filament. This setting is rarely needed." +msgstr "" +"When the retraction is compensated after the travel move, the extruder will " +"push this additional amount of filament. This setting is rarely needed." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1129 +msgid "" +"When the retraction is compensated after changing tool, the extruder will " +"push this additional amount of filament." +msgstr "" +"When the retraction is compensated after changing tool, the extruder will " +"push this additional amount of filament." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1136 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1137 +msgid "Retraction Speed" +msgstr "Retraction Speed" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1138 +msgid "The speed for retractions (it only applies to the extruder motor)." +msgstr "The speed for retractions (it only applies to the extruder motor)." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1144 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1145 +msgid "Deretraction Speed" +msgstr "Deretraction Speed" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1146 +msgid "" +"The speed for loading of a filament into extruder after retraction (it only " +"applies to the extruder motor). If left to zero, the retraction speed is " +"used." +msgstr "" +"The speed for loading of a filament into extruder after retraction (it only " +"applies to the extruder motor). If left to zero, the retraction speed is " +"used." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1153 +msgid "Seam position" +msgstr "Seam position" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1155 +msgid "Position of perimeters starting points." +msgstr "Position of perimeters starting points." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1171 +msgid "Direction" +msgstr "Direction" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1173 +msgid "Preferred direction of the seam" +msgstr "Preferred direction of the seam" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1174 +msgid "Seam preferred direction" +msgstr "Seam preferred direction" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1182 +msgid "Jitter" +msgstr "Jitter" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1184 +msgid "Seam preferred direction jitter" +msgstr "Seam preferred direction jitter" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1185 +msgid "Preferred direction of the seam - jitter" +msgstr "Preferred direction of the seam - jitter" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1195 +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:989 +msgid "Serial port" +msgstr "Serial port" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1196 +msgid "USB/serial port for printer connection." +msgstr "USB/serial port for printer connection." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1204 +msgid "Serial port speed" +msgstr "Serial port speed" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1205 +msgid "Speed (baud) of USB/serial port for printer connection." +msgstr "Speed (baud) of USB/serial port for printer connection." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1214 +msgid "Distance from object" +msgstr "Distance from object" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1215 +msgid "" +"Distance between skirt and object(s). Set this to zero to attach the skirt " +"to the object(s) and get a brim for better adhesion." +msgstr "" +"Distance between skirt and object(s). Set this to zero to attach the skirt " +"to the object(s) and get a brim for better adhesion." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1223 +msgid "Skirt height" +msgstr "Skirt height" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1224 +msgid "" +"Height of skirt expressed in layers. Set this to a tall value to use skirt " +"as a shield against drafts." +msgstr "" +"Height of skirt expressed in layers. Set this to a tall value to use skirt " +"as a shield against drafts." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1231 +msgid "Loops (minimum)" +msgstr "Loops (minimum)" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1232 +msgid "Skirt Loops" +msgstr "Skirt Loops" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1233 +msgid "" +"Number of loops for the skirt. If the Minimum Extrusion Length option is " +"set, the number of loops might be greater than the one configured here. Set " +"this to zero to disable skirt completely." +msgstr "" +"Number of loops for the skirt. If the Minimum Extrusion Length option is " +"set, the number of loops might be greater than the one configured here. Set " +"this to zero to disable skirt completely." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1241 +msgid "Slow down if layer print time is below" +msgstr "Slow down if layer print time is below" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1242 +msgid "" +"If layer print time is estimated below this number of seconds, print moves " +"speed will be scaled down to extend duration to this value." +msgstr "" +"If layer print time is estimated below this number of seconds, print moves " +"speed will be scaled down to extend duration to this value." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1252 +msgid "Small perimeters" +msgstr "Small perimeters" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1254 +msgid "" +"This separate setting will affect the speed of perimeters having radius <= " +"6.5mm (usually holes). If expressed as percentage (for example: 80%) it will " +"be calculated on the perimeters speed setting above. Set to zero for auto." +msgstr "" +"This separate setting will affect the speed of perimeters having radius <= " +"6.5mm (usually holes). If expressed as percentage (for example: 80%) it will " +"be calculated on the perimeters speed setting above. Set to zero for auto." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1264 +msgid "Solid infill threshold area" +msgstr "Solid infill threshold area" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1266 +msgid "" +"Force solid infill for regions having a smaller area than the specified " +"threshold." +msgstr "" +"Force solid infill for regions having a smaller area than the specified " +"threshold." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1267 +msgid "mm\\u00B2" +msgstr "mm\\u00B2" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1273 +msgid "Solid infill extruder" +msgstr "Solid infill extruder" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1275 +msgid "The extruder to use when printing solid infill." +msgstr "The extruder to use when printing solid infill." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1281 +msgid "Solid infill every" +msgstr "Solid infill every" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1283 +msgid "" +"This feature allows to force a solid layer every given number of layers. " +"Zero to disable. You can set this to any value (for example 9999); Slic3r " +"will automatically choose the maximum possible number of layers to combine " +"according to nozzle diameter and layer height." +msgstr "" +"This feature allows to force a solid layer every given number of layers. " +"Zero to disable. You can set this to any value (for example 9999); Slic3r " +"will automatically choose the maximum possible number of layers to combine " +"according to nozzle diameter and layer height." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1293 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1303 +msgid "Solid infill" +msgstr "Solid infill" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1295 +msgid "" +"Set this to a non-zero value to set a manual extrusion width for infill for " +"solid surfaces. If left zero, default extrusion width will be used if set, " +"otherwise 1.125 x nozzle diameter will be used. If expressed as percentage " +"(for example 90%) it will be computed over layer height." +msgstr "" +"Set this to a non-zero value to set a manual extrusion width for infill for " +"solid surfaces. If left zero, default extrusion width will be used if set, " +"otherwise 1.125 x nozzle diameter will be used. If expressed as percentage " +"(for example 90%) it will be computed over layer height." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1305 +msgid "" +"Speed for printing solid regions (top/bottom/internal horizontal shells). " +"This can be expressed as a percentage (for example: 80%) over the default " +"infill speed above. Set to zero for auto." +msgstr "" +"Speed for printing solid regions (top/bottom/internal horizontal shells). " +"This can be expressed as a percentage (for example: 80%) over the default " +"infill speed above. Set to zero for auto." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1316 +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:331 +msgid "Solid layers" +msgstr "Solid layers" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1317 +msgid "Number of solid layers to generate on top and bottom surfaces." +msgstr "Number of solid layers to generate on top and bottom surfaces." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1324 +msgid "Spiral vase" +msgstr "Spiral vase" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1325 +msgid "" +"This feature will raise Z gradually while printing a single-walled object in " +"order to remove any visible seam. This option requires a single perimeter, " +"no infill, no top solid layers and no support material. You can still set " +"any number of bottom solid layers as well as skirt/brim loops. It won't work " +"when printing more than an object." +msgstr "" +"This feature will raise Z gradually while printing a single-walled object in " +"order to remove any visible seam. This option requires a single perimeter, " +"no infill, no top solid layers and no support material. You can still set " +"any number of bottom solid layers as well as skirt/brim loops. It won't work " +"when printing more than an object." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1334 +msgid "Temperature variation" +msgstr "Temperature variation" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1335 +msgid "" +"Temperature difference to be applied when an extruder is not active. Enables " +"a full-height \"sacrificial\" skirt on which the nozzles are periodically " +"wiped." +msgstr "" +"Temperature difference to be applied when an extruder is not active. Enables " +"a full-height \"sacrificial\" skirt on which the nozzles are periodically " +"wiped." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1344 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1359 +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:846 +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:1119 +msgid "Start G-code" +msgstr "Start G-code" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1345 +msgid "" +"This start procedure is inserted at the beginning, after bed has reached the " +"target temperature and extruder just started heating, and before extruder " +"has finished heating. If Slic3r detects M104 or M190 in your custom codes, " +"such commands will not be prepended automatically so you're free to " +"customize the order of heating commands and other custom actions. Note that " +"you can use placeholder variables for all Slic3r settings, so you can put a " +"\"M109 S[first_layer_temperature]\" command wherever you want." +msgstr "" +"This start procedure is inserted at the beginning, after bed has reached the " +"target temperature and extruder just started heating, and before extruder " +"has finished heating. If Slic3r detects M104 or M190 in your custom codes, " +"such commands will not be prepended automatically so you're free to " +"customize the order of heating commands and other custom actions. Note that " +"you can use placeholder variables for all Slic3r settings, so you can put a " +"\"M109 S[first_layer_temperature]\" command wherever you want." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1360 +msgid "" +"This start procedure is inserted at the beginning, after any printer start " +"gcode. This is used to override settings for a specific filament. If Slic3r " +"detects M104, M109, M140 or M190 in your custom codes, such commands will " +"not be prepended automatically so you're free to customize the order of " +"heating commands and other custom actions. Note that you can use placeholder " +"variables for all Slic3r settings, so you can put a \"M109 " +"S[first_layer_temperature]\" command wherever you want. If you have multiple " +"extruders, the gcode is processed in extruder order." +msgstr "" +"This start procedure is inserted at the beginning, after any printer start " +"gcode. This is used to override settings for a specific filament. If Slic3r " +"detects M104, M109, M140 or M190 in your custom codes, such commands will " +"not be prepended automatically so you're free to customize the order of " +"heating commands and other custom actions. Note that you can use placeholder " +"variables for all Slic3r settings, so you can put a \"M109 " +"S[first_layer_temperature]\" command wherever you want. If you have multiple " +"extruders, the gcode is processed in extruder order." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1375 +msgid "Single Extruder Multi Material" +msgstr "Single Extruder Multi Material" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1376 +msgid "The printer multiplexes filaments into a single hot end." +msgstr "The printer multiplexes filaments into a single hot end." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1381 +msgid "Generate support material" +msgstr "Generate support material" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1383 +msgid "Enable support material generation." +msgstr "Enable support material generation." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1388 +msgid "XY separation between an object and its support" +msgstr "XY separation between an object and its support" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1390 +msgid "" +"XY separation between an object and its support. If expressed as percentage " +"(for example 50%), it will be calculated over external perimeter width." +msgstr "" +"XY separation between an object and its support. If expressed as percentage " +"(for example 50%), it will be calculated over external perimeter width." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1400 +msgid "Pattern angle" +msgstr "Pattern angle" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1402 +msgid "" +"Use this setting to rotate the support material pattern on the horizontal " +"plane." +msgstr "" +"Use this setting to rotate the support material pattern on the horizontal " +"plane." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1410 +msgid "Support on build plate only" +msgstr "Support on build plate only" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1412 +msgid "" +"Only create support if it lies on a build plate. Don't create support on a " +"print." +msgstr "" +"Only create support if it lies on a build plate. Don't create support on a " +"print." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1418 +msgid "Contact Z distance" +msgstr "Contact Z distance" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1420 +msgid "" +"The vertical distance between object and support material interface. Setting " +"this to 0 will also prevent Slic3r from using bridge flow and speed for the " +"first object layer." +msgstr "" +"The vertical distance between object and support material interface. Setting " +"this to 0 will also prevent Slic3r from using bridge flow and speed for the " +"first object layer." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1433 +msgid "Enforce support for the first" +msgstr "Enforce support for the first" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1435 +msgid "" +"Generate support material for the specified number of layers counting from " +"bottom, regardless of whether normal support material is enabled or not and " +"regardless of any angle threshold. This is useful for getting more adhesion " +"of objects having a very thin or poor footprint on the build plate." +msgstr "" +"Generate support material for the specified number of layers counting from " +"bottom, regardless of whether normal support material is enabled or not and " +"regardless of any angle threshold. This is useful for getting more adhesion " +"of objects having a very thin or poor footprint on the build plate." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1441 +msgid "Enforce support for the first n layers" +msgstr "Enforce support for the first n layers" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1446 +msgid "Support material/raft/skirt extruder" +msgstr "Support material/raft/skirt extruder" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1448 +msgid "" +"The extruder to use when printing support material, raft and skirt (1+, 0 to " +"use the current extruder to minimize tool changes)." +msgstr "" +"The extruder to use when printing support material, raft and skirt (1+, 0 to " +"use the current extruder to minimize tool changes)." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1457 +msgid "" +"Set this to a non-zero value to set a manual extrusion width for support " +"material. If left zero, default extrusion width will be used if set, " +"otherwise nozzle diameter will be used. If expressed as percentage (for " +"example 90%) it will be computed over layer height." +msgstr "" +"Set this to a non-zero value to set a manual extrusion width for support " +"material. If left zero, default extrusion width will be used if set, " +"otherwise nozzle diameter will be used. If expressed as percentage (for " +"example 90%) it will be computed over layer height." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1465 +msgid "Interface loops" +msgstr "Interface loops" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1467 +msgid "" +"Cover the top contact layer of the supports with loops. Disabled by default." +msgstr "" +"Cover the top contact layer of the supports with loops. Disabled by default." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1472 +msgid "Support material/raft interface extruder" +msgstr "Support material/raft interface extruder" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1474 +msgid "" +"The extruder to use when printing support material interface (1+, 0 to use " +"the current extruder to minimize tool changes). This affects raft too." +msgstr "" +"The extruder to use when printing support material interface (1+, 0 to use " +"the current extruder to minimize tool changes). This affects raft too." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1481 +msgid "Interface layers" +msgstr "Interface layers" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1483 +msgid "" +"Number of interface layers to insert between the object(s) and support " +"material." +msgstr "" +"Number of interface layers to insert between the object(s) and support " +"material." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1490 +msgid "Interface pattern spacing" +msgstr "Interface pattern spacing" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1492 +msgid "Spacing between interface lines. Set zero to get a solid interface." +msgstr "Spacing between interface lines. Set zero to get a solid interface." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1499 +msgid "Support material interface" +msgstr "Support material interface" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1501 +msgid "" +"Speed for printing support material interface layers. If expressed as " +"percentage (for example 50%) it will be calculated over support material " +"speed." +msgstr "" +"Speed for printing support material interface layers. If expressed as " +"percentage (for example 50%) it will be calculated over support material " +"speed." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1510 +msgid "Pattern" +msgstr "Pattern" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1512 +msgid "Pattern used to generate support material." +msgstr "Pattern used to generate support material." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1526 +msgid "Pattern spacing" +msgstr "Pattern spacing" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1528 +msgid "Spacing between support material lines." +msgstr "Spacing between support material lines." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1537 +msgid "Speed for printing support material." +msgstr "Speed for printing support material." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1544 +msgid "Synchronize with object layers" +msgstr "Synchronize with object layers" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1546 +msgid "" +"Synchronize support layers with the object print layers. This is useful with " +"multi-material printers, where the extruder switch is expensive." +msgstr "" +"Synchronize support layers with the object print layers. This is useful with " +"multi-material printers, where the extruder switch is expensive." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1552 +msgid "Overhang threshold" +msgstr "Overhang threshold" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1554 +msgid "" +"Support material will not be generated for overhangs whose slope angle " +"(90\\u00B0 = vertical) is above the given threshold. In other words, this " +"value represent the most horizontal slope (measured from the horizontal " +"plane) that you can print without support material. Set to zero for " +"automatic detection (recommended)." +msgstr "" +"Support material will not be generated for overhangs whose slope angle " +"(90\\u00B0 = vertical) is above the given threshold. In other words, this " +"value represent the most horizontal slope (measured from the horizontal " +"plane) that you can print without support material. Set to zero for " +"automatic detection (recommended)." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1566 +msgid "With sheath around the support" +msgstr "With sheath around the support" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1568 +msgid "" +"Add a sheath (a single perimeter line) around the base support. This makes " +"the support more reliable, but also more difficult to remove." +msgstr "" +"Add a sheath (a single perimeter line) around the base support. This makes " +"the support more reliable, but also more difficult to remove." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1575 +msgid "" +"Extruder temperature for layers after the first one. Set this to zero to " +"disable temperature control commands in the output." +msgstr "" +"Extruder temperature for layers after the first one. Set this to zero to " +"disable temperature control commands in the output." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1578 +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:793 +msgid "Temperature" +msgstr "Temperature" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1584 +msgid "Detect thin walls" +msgstr "Detect thin walls" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1586 +msgid "" +"Detect single-width walls (parts where two extrusions don't fit and we need " +"to collapse them into a single trace)." +msgstr "" +"Detect single-width walls (parts where two extrusions don't fit and we need " +"to collapse them into a single trace)." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1592 +msgid "Threads" +msgstr "Threads" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1593 +msgid "" +"Threads are used to parallelize long-running tasks. Optimal threads number " +"is slightly above the number of available cores/processors." +msgstr "" +"Threads are used to parallelize long-running tasks. Optimal threads number " +"is slightly above the number of available cores/processors." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1604 +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:1143 +msgid "Tool change G-code" +msgstr "Tool change G-code" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1605 +msgid "" +"This custom code is inserted right before every extruder change. Note that " +"you can use placeholder variables for all Slic3r settings as well as " +"[previous_extruder] and [next_extruder]." +msgstr "" +"This custom code is inserted right before every extruder change. Note that " +"you can use placeholder variables for all Slic3r settings as well as " +"[previous_extruder] and [next_extruder]." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1615 +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1626 +msgid "Top solid infill" +msgstr "Top solid infill" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1617 +msgid "" +"Set this to a non-zero value to set a manual extrusion width for infill for " +"top surfaces. You may want to use thinner extrudates to fill all narrow " +"regions and get a smoother finish. If left zero, default extrusion width " +"will be used if set, otherwise nozzle diameter will be used. If expressed as " +"percentage (for example 90%) it will be computed over layer height." +msgstr "" +"Set this to a non-zero value to set a manual extrusion width for infill for " +"top surfaces. You may want to use thinner extrudates to fill all narrow " +"regions and get a smoother finish. If left zero, default extrusion width " +"will be used if set, otherwise nozzle diameter will be used. If expressed as " +"percentage (for example 90%) it will be computed over layer height." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1628 +msgid "" +"Speed for printing top solid layers (it only applies to the uppermost " +"external layers and not to their internal solid layers). You may want to " +"slow down this to get a nicer surface finish. This can be expressed as a " +"percentage (for example: 80%) over the solid infill speed above. Set to zero " +"for auto." +msgstr "" +"Speed for printing top solid layers (it only applies to the uppermost " +"external layers and not to their internal solid layers). You may want to " +"slow down this to get a nicer surface finish. This can be expressed as a " +"percentage (for example: 80%) over the solid infill speed above. Set to zero " +"for auto." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1640 +msgid "Top" +msgstr "Top" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1642 +msgid "Number of solid layers to generate on top surfaces." +msgstr "Number of solid layers to generate on top surfaces." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1644 +msgid "Top solid layers" +msgstr "Top solid layers" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1649 +msgid "Travel" +msgstr "Travel" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1650 +msgid "Speed for travel moves (jumps between distant extrusion points)." +msgstr "Speed for travel moves (jumps between distant extrusion points)." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1658 +msgid "Use firmware retraction" +msgstr "Use firmware retraction" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1659 +msgid "" +"This experimental setting uses G10 and G11 commands to have the firmware " +"handle the retraction. This is only supported in recent Marlin." +msgstr "" +"This experimental setting uses G10 and G11 commands to have the firmware " +"handle the retraction. This is only supported in recent Marlin." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1665 +msgid "Use relative E distances" +msgstr "Use relative E distances" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1666 +msgid "" +"If your firmware requires relative E values, check this, otherwise leave it " +"unchecked. Most firmwares use absolute values." +msgstr "" +"If your firmware requires relative E values, check this, otherwise leave it " +"unchecked. Most firmwares use absolute values." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1672 +msgid "Use volumetric E" +msgstr "Use volumetric E" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1673 +msgid "" +"This experimental setting uses outputs the E values in cubic millimeters " +"instead of linear millimeters. If your firmware doesn't already know " +"filament diameter(s), you can put commands like 'M200 D[filament_diameter_0] " +"T0' in your start G-code in order to turn volumetric mode on and use the " +"filament diameter associated to the filament selected in Slic3r. This is " +"only supported in recent Marlin." +msgstr "" +"This experimental setting uses outputs the E values in cubic millimeters " +"instead of linear millimeters. If your firmware doesn't already know " +"filament diameter(s), you can put commands like 'M200 D[filament_diameter_0] " +"T0' in your start G-code in order to turn volumetric mode on and use the " +"filament diameter associated to the filament selected in Slic3r. This is " +"only supported in recent Marlin." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1683 +msgid "Enable variable layer height feature" +msgstr "Enable variable layer height feature" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1684 +msgid "" +"Some printers or printer setups may have difficulties printing with a " +"variable layer height. Enabled by default." +msgstr "" +"Some printers or printer setups may have difficulties printing with a " +"variable layer height. Enabled by default." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1690 +msgid "Wipe while retracting" +msgstr "Wipe while retracting" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1691 +msgid "" +"This flag will move the nozzle while retracting to minimize the possible " +"blob on leaky extruders." +msgstr "" +"This flag will move the nozzle while retracting to minimize the possible " +"blob on leaky extruders." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1698 +msgid "" +"Multi material printers may need to prime or purge extruders on tool " +"changes. Extrude the excess material into the wipe tower." +msgstr "" +"Multi material printers may need to prime or purge extruders on tool " +"changes. Extrude the excess material into the wipe tower." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1704 +msgid "Position X" +msgstr "Position X" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1705 +msgid "X coordinate of the left front corner of a wipe tower" +msgstr "X coordinate of the left front corner of a wipe tower" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1711 +msgid "Position Y" +msgstr "Position Y" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1712 +msgid "Y coordinate of the left front corner of a wipe tower" +msgstr "Y coordinate of the left front corner of a wipe tower" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1718 +msgid "Width" +msgstr "Width" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1719 +msgid "Width of a wipe tower" +msgstr "Width of a wipe tower" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1725 +msgid "Per color change depth" +msgstr "Per color change depth" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1726 +msgid "" +"Depth of a wipe color per color change. For N colors, there will be maximum " +"(N-1) tool switches performed, therefore the total depth of the wipe tower " +"will be (N-1) times this value." +msgstr "" +"Depth of a wipe color per color change. For N colors, there will be maximum " +"(N-1) tool switches performed, therefore the total depth of the wipe tower " +"will be (N-1) times this value." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1734 +msgid "XY Size Compensation" +msgstr "XY Size Compensation" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1736 +msgid "" +"The object will be grown/shrunk in the XY plane by the configured value " +"(negative = inwards, positive = outwards). This might be useful for fine-" +"tuning hole sizes." +msgstr "" +"The object will be grown/shrunk in the XY plane by the configured value " +"(negative = inwards, positive = outwards). This might be useful for fine-" +"tuning hole sizes." + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1744 +msgid "Z offset" +msgstr "Z offset" + +#: C:\src\Slic3r\xs\src\libslic3r\PrintConfig.cpp:1745 +msgid "" +"This value will be added (or subtracted) from all the Z coordinates in the " +"output G-code. It is used to compensate for bad Z endstop position: for " +"example, if your endstop zero actually leaves the nozzle 0.3mm far from the " +"print bed, set this to -0.3 (or fix your endstop)." +msgstr "" +"This value will be added (or subtracted) from all the Z coordinates in the " +"output G-code. It is used to compensate for bad Z endstop position: for " +"example, if your endstop zero actually leaves the nozzle 0.3mm far from the " +"print bed, set this to -0.3 (or fix your endstop)." + +#: c:\src\Slic3r\xs\src\slic3r\GUI\BedShapeDialog.cpp:39 +msgid "Shape" +msgstr "Shape" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\BedShapeDialog.cpp:46 +msgid "Rectangular" +msgstr "Rectangular" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\BedShapeDialog.cpp:62 +msgid "Circular" +msgstr "Circular" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\BedShapeDialog.cpp:75 +msgid "Load shape from STL..." +msgstr "Load shape from STL..." + +#: c:\src\Slic3r\xs\src\slic3r\GUI\BedShapeDialog.cpp:120 +msgid "Settings" +msgstr "Settings" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\BedShapeDialog.cpp:298 +msgid "Choose a file to import bed shape from (STL/OBJ/AMF/PRUSA):" +msgstr "Choose a file to import bed shape from (STL/OBJ/AMF/PRUSA):" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\BedShapeDialog.cpp:315 +msgid "Error! " +msgstr "Error! " + +#: c:\src\Slic3r\xs\src\slic3r\GUI\BedShapeDialog.cpp:324 +msgid "The selected file contains no geometry." +msgstr "The selected file contains no geometry." + +#: c:\src\Slic3r\xs\src\slic3r\GUI\BedShapeDialog.cpp:328 +msgid "" +"The selected file contains several disjoint areas. This is not supported." +msgstr "" +"The selected file contains several disjoint areas. This is not supported." + +#: c:\src\Slic3r\xs\src\slic3r\GUI\BedShapeDialog.hpp:42 +msgid "Bed Shape" +msgstr "Bed Shape" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\GUI.cpp:468 +msgid "Error" +msgstr "Error" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\GUI.cpp:473 +msgid "Notice" +msgstr "Notice" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:50 +msgid "Save current " +msgstr "Save current " + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:51 +msgid "Delete this preset" +msgstr "Delete this preset" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:330 +msgid "Horizontal shells" +msgstr "Horizontal shells" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:336 +msgid "Quality (slower slicing)" +msgstr "Quality (slower slicing)" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:353 +msgid "Reducing printing time" +msgstr "Reducing printing time" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:365 +msgid "Skirt and brim" +msgstr "Skirt and brim" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:381 +msgid "Raft" +msgstr "Raft" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:412 +msgid "Speed for non-print moves" +msgstr "Speed for non-print moves" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:415 +msgid "Modifiers" +msgstr "Modifiers" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:418 +msgid "Acceleration control (advanced)" +msgstr "Acceleration control (advanced)" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:425 +msgid "Autospeed (advanced)" +msgstr "Autospeed (advanced)" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:431 +msgid "Multiple Extruders" +msgstr "Multiple Extruders" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:439 +msgid "Ooze prevention" +msgstr "Ooze prevention" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:464 +msgid "Overlap" +msgstr "Overlap" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:467 +msgid "Flow" +msgstr "Flow" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:470 +msgid "Other" +msgstr "Other" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:477 +msgid "Output options" +msgstr "Output options" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:478 +msgid "Sequential printing" +msgstr "Sequential printing" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:501 +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:502 +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:858 +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:859 +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:1155 +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:1156 +msgid "Notes" +msgstr "Notes" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:508 +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:866 +msgid "Dependencies" +msgstr "Dependencies" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:509 +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:867 +msgid "Profile dependencies" +msgstr "Profile dependencies" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:799 +msgid "Bed" +msgstr "Bed" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:804 +msgid "Cooling" +msgstr "Cooling" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:816 +msgid "Fan settings" +msgstr "Fan settings" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:835 +msgid "Print speed override" +msgstr "Print speed override" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:845 +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:1118 +msgid "Custom G-code" +msgstr "Custom G-code" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:936 +msgid "General" +msgstr "General" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:937 +msgid "Size and coordinates" +msgstr "Size and coordinates" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:941 +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:1642 +msgid "Set" +msgstr "Set" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:961 +msgid "Capabilities" +msgstr "Capabilities" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:1003 +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:1071 +msgid "Test" +msgstr "Test" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:1016 +msgid "Connection to printer works correctly." +msgstr "Connection to printer works correctly." + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:1016 +msgid "Success!" +msgstr "Success!" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:1019 +msgid "Connection failed." +msgstr "Connection failed." + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:1031 +msgid "OctoPrint upload" +msgstr "OctoPrint upload" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:1034 +msgid "Browse" +msgstr "Browse" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:1046 +msgid "Button BROWSE was clicked!" +msgstr "Button BROWSE was clicked!" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:1081 +msgid "Button TEST was clicked!" +msgstr "Button TEST was clicked!" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:1109 +msgid "Firmware" +msgstr "Firmware" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:1191 +msgid "Layer height limits" +msgstr "Layer height limits" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:1196 +msgid "Position (for multi-extruder printers)" +msgstr "Position (for multi-extruder printers)" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:1215 +msgid "" +"Retraction when tool is disabled (advanced settings for multi-extruder " +"setups)" +msgstr "" +"Retraction when tool is disabled (advanced settings for multi-extruder " +"setups)" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:1219 +msgid "Preview" +msgstr "Preview" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:1310 +msgid "" +"The Wipe option is not available when using the Firmware Retraction mode.\n" +"\n" +"Shall I disable it in order to enable Firmware Retraction?" +msgstr "" +"The Wipe option is not available when using the Firmware Retraction mode.\n" +"\n" +"Shall I disable it in order to enable Firmware Retraction?" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:1558 +msgid "The supplied name is empty. It can't be saved." +msgstr "The supplied name is empty. It can't be saved." + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:1569 +msgid "Something is wrong. It can't be saved." +msgstr "Something is wrong. It can't be saved." + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:1586 +msgid "remove" +msgstr "remove" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:1586 +msgid "delete" +msgstr "delete" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:1587 +msgid "Are you sure you want to " +msgstr "Are you sure you want to " + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:1587 +msgid " the selected preset?" +msgstr " the selected preset?" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:1588 +msgid "Remove" +msgstr "Remove" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:1588 +msgid "Delete" +msgstr "Delete" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:1589 +msgid " Preset" +msgstr " Preset" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:1641 +msgid "All" +msgstr "All" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:1672 +msgid "Select the printers this profile is compatible with." +msgstr "Select the printers this profile is compatible with." + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:1756 +msgid "Save " +msgstr "Save " + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:1756 +msgid " as:" +msgstr " as:" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:1790 +msgid "" +"The supplied name is not valid; the following characters are not allowed:" +msgstr "" +"The supplied name is not valid; the following characters are not allowed:" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:1793 +msgid "The supplied name is not available." +msgstr "The supplied name is not available." + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.hpp:182 +msgid "Print Settings" +msgstr "Print Settings" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.hpp:202 +msgid "Filament Settings" +msgstr "Filament Settings" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.hpp:248 +msgid "Save preset" +msgstr "Save preset" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Field.cpp:35 +msgid "default" +msgstr "default" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\BedShapeDialog.cpp:71 +msgid "Custom" +msgstr "Custom" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\GUI.cpp:212 +msgid "Array of language names and identifiers should have the same size." +msgstr "Array of language names and identifiers should have the same size." + +#: c:\src\Slic3r\xs\src\slic3r\GUI\GUI.cpp:223 +msgid "Select the language" +msgstr "Select the language" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\GUI.cpp:223 +msgid "Language" +msgstr "Language" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\GUI.cpp:321 +msgid "Change Application Language" +msgstr "Change Application Language" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:314 +msgid "Layers and perimeters" +msgstr "Layers and perimeters" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:319 +msgid "Vertical shells" +msgstr "Vertical shells" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:366 +msgid "Skirt" +msgstr "Skirt" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:372 +msgid "Brim" +msgstr "Brim" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:385 +msgid "Options for support material and raft" +msgstr "Options for support material and raft" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:400 +msgid "Speed for print moves" +msgstr "Speed for print moves" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:443 +msgid "Wipe tower" +msgstr "Wipe tower" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:454 +msgid "Extrusion width" +msgstr "Extrusion width" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:480 +msgid "Extruder clearance (mm)" +msgstr "Extruder clearance (mm)" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:489 +msgid "Output file" +msgstr "Output file" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:534 +#, c-format +msgid "" +"The Spiral Vase mode requires:\n" +"- one perimeter\n" +"- no top solid layers\n" +"- 0% fill density\n" +"- no support material\n" +"- no ensure_vertical_shell_thickness\n" +"\n" +"Shall I adjust those settings in order to enable Spiral Vase?" +msgstr "" +"The Spiral Vase mode requires:\n" +"- one perimeter\n" +"- no top solid layers\n" +"- 0% fill density\n" +"- no support material\n" +"- no ensure_vertical_shell_thickness\n" +"\n" +"Shall I adjust those settings in order to enable Spiral Vase?" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:541 +msgid "Spiral Vase" +msgstr "Spiral Vase" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:560 +msgid "" +"The Wipe Tower currently supports only:\n" +"- first layer height 0.2mm\n" +"- layer height from 0.15mm to 0.35mm\n" +"\n" +"Shall I adjust those settings in order to enable the Wipe Tower?" +msgstr "" +"The Wipe Tower currently supports only:\n" +"- first layer height 0.2mm\n" +"- layer height from 0.15mm to 0.35mm\n" +"\n" +"Shall I adjust those settings in order to enable the Wipe Tower?" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:564 +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:585 +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:602 +msgid "Wipe Tower" +msgstr "Wipe tower" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:581 +msgid "" +"The Wipe Tower currently supports the non-soluble supports only\n" +"if they are printed with the current extruder without triggering a tool " +"change.\n" +"(both support_material_extruder and support_material_interface_extruder need " +"to be set to 0).\n" +"\n" +"Shall I adjust those settings in order to enable the Wipe Tower?" +msgstr "" +"The Wipe Tower currently supports the non-soluble supports only\n" +"if they are printed with the current extruder without triggering a tool " +"change.\n" +"(both support_material_extruder and support_material_interface_extruder need " +"to be set to 0).\n" +"\n" +"Shall I adjust those settings in order to enable the Wipe Tower?" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:599 +msgid "" +"For the Wipe Tower to work with the soluble supports, the support layers\n" +"need to be synchronized with the object layers.\n" +"\n" +"Shall I synchronize support layers in order to enable the Wipe Tower?" +msgstr "" +"For the Wipe Tower to work with the soluble supports, the support layers\n" +"need to be synchronized with the object layers.\n" +"\n" +"Shall I synchronize support layers in order to enable the Wipe Tower?" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:617 +msgid "" +"Supports work better, if the following feature is enabled:\n" +"- Detect bridging perimeters\n" +"\n" +"Shall I adjust those settings for supports?" +msgstr "" +"Supports work better, if the following feature is enabled:\n" +"- Detect bridging perimeters\n" +"\n" +"Shall I adjust those settings for supports?" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:620 +msgid "Support Generator" +msgstr "Support Generator" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:662 +msgid "The " +msgstr "The " + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:662 +#, c-format +msgid "" +" infill pattern is not supposed to work at 100% density.\n" +"\n" +"Shall I switch to rectilinear fill pattern?" +msgstr "" +" infill pattern is not supposed to work at 100% density.\n" +"\n" +"Shall I switch to rectilinear fill pattern?" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:785 +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:786 +msgid "Filament" +msgstr "Filament" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:817 +msgid "Fan speed" +msgstr "Fan speed" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:825 +msgid "Cooling thresholds" +msgstr "Cooling thresholds" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:831 +msgid "Filament properties" +msgstr "Filament properties" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:988 +msgid "USB/Serial connection" +msgstr "USB/Serial connection" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:994 +msgid "Rescan serial ports" +msgstr "Rescan serial ports" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:1149 +msgid "Between objects G-code (for sequential printing)" +msgstr "Between objects G-code (for sequential printing)" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:1185 +msgid "Extruder " +msgstr "Extruder " + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:1199 +msgid "Retraction" +msgstr "Retraction" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:1202 +msgid "Only lift Z" +msgstr "Only lift Z" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:1312 +msgid "Firmware Retraction" +msgstr "Firmware Retraction" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:1467 +msgid "Default " +msgstr "Default " + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:1467 +msgid " preset" +msgstr " preset" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:1468 +msgid " preset\n" +msgstr " preset\n" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:1486 +msgid "" +"\n" +"\n" +"is not compatible with printer\n" +msgstr "" +"\n" +"\n" +"is not compatible with printer\n" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:1486 +msgid "" +"\n" +"\n" +"and it has the following unsaved changes:" +msgstr "" +"\n" +"\n" +"and it has the following unsaved changes:" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:1487 +msgid "" +"\n" +"\n" +"has the following unsaved changes:" +msgstr "" +"\n" +"\n" +"has the following unsaved changes:" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:1489 +msgid "" +"\n" +"\n" +"Discard changes and continue anyway?" +msgstr "" +"\n" +"\n" +"Discard changes and continue anyway?" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:1490 +msgid "Unsaved Changes" +msgstr "Unsaved Changes" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.hpp:228 +msgid "Printer Settings" +msgstr "Printer Settings" diff --git a/resources/localization/uk/Slic3rPE.mo b/resources/localization/uk/Slic3rPE.mo new file mode 100644 index 000000000..40e32c81e Binary files /dev/null and b/resources/localization/uk/Slic3rPE.mo differ diff --git a/resources/localization/uk/Slic3rPE_uk.po b/resources/localization/uk/Slic3rPE_uk.po new file mode 100644 index 000000000..6166632e2 --- /dev/null +++ b/resources/localization/uk/Slic3rPE_uk.po @@ -0,0 +1,538 @@ +# This file is distributed under the same license as the Slic3rPE package. +# Oleksandra Iushchenko , 2018. +# +msgid "" +msgstr "" +"Project-Id-Version: \n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2018-02-07 20:20+0100\n" +"PO-Revision-Date: 2018-02-08 01:41+0100\n" +"Last-Translator: Oleksandra Iushchenko \n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"X-Generator: Poedit 2.0.6\n" +"Plural-Forms: nplurals=3; plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n" +"%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2);\n" +"Language: uk\n" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\BedShapeDialog.cpp:81 +msgid "Default" +msgstr "За замовчуванням" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\BedShapeDialog.cpp:109 +msgid "Shape" +msgstr "Вигляд (Форма)" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\BedShapeDialog.cpp:116 +msgid "Rectangular" +msgstr "Прямокутний" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\BedShapeDialog.cpp:132 +msgid "Circular" +msgstr "Круговий" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\BedShapeDialog.cpp:141 +msgid "Custom" +msgstr "Користувацький" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\BedShapeDialog.cpp:145 +msgid "Load shape from STL..." +msgstr "Завантажте форму з STL ..." + +#: c:\src\Slic3r\xs\src\slic3r\GUI\BedShapeDialog.cpp:190 +msgid "Settings" +msgstr "Налаштування" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\BedShapeDialog.cpp:368 +msgid "Choose a file to import bed shape from (STL/OBJ/AMF/PRUSA):" +msgstr "Виберіть файл, щоб імпортувати форму подложки з (STL/OBJ/AMF/PRUSA):" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\BedShapeDialog.cpp:385 +msgid "Error! " +msgstr "Помилка! " + +#: c:\src\Slic3r\xs\src\slic3r\GUI\BedShapeDialog.cpp:394 +msgid "The selected file contains no geometry." +msgstr "Обратний файл не містить геометрії." + +#: c:\src\Slic3r\xs\src\slic3r\GUI\BedShapeDialog.cpp:398 +msgid "" +"The selected file contains several disjoint areas. This is not supported." +msgstr "Обраний файл містить декілька непересічних областей. Не підтримується." + +#: c:\src\Slic3r\xs\src\slic3r\GUI\BedShapeDialog.hpp:45 +msgid "Bed Shape" +msgstr "Форма полотна" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\GUI.cpp:318 +msgid "Error" +msgstr "Помилка" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\GUI.cpp:323 +msgid "Notice" +msgstr "Зауваження" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:51 +msgid "Save current " +msgstr "Зберегти поточний " + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:52 +msgid "Delete this preset" +msgstr "Видалити це налаштування" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:324 +msgid "Layers and perimeters" +msgstr "Шари та периметри" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:325 +msgid "Layer height" +msgstr "Висота шару" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:329 +msgid "Vertical shells" +msgstr "Вертикальні оболонки" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:340 +msgid "Horizontal shells" +msgstr "Горизонтальні оболонки" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:341 +msgid "Solid layers" +msgstr "Тверді шари" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:346 +msgid "Quality (slower slicing)" +msgstr "Якість (повільне нарізання)" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:353 +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:367 +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:460 +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:463 +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:839 +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:1122 +msgid "Advanced" +msgstr "Розширений" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:357 +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:358 +msgid "Infill" +msgstr "Заповнення" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:363 +msgid "Reducing printing time" +msgstr "Зниження часу друку" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:375 +msgid "Skirt and brim" +msgstr "Плінтус та край" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:376 +msgid "Skirt" +msgstr "Плінтус" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:382 +msgid "Brim" +msgstr "Край" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:385 +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:386 +msgid "Support material" +msgstr "Опорний матеріал" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:391 +msgid "Raft" +msgstr "Пліт" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:395 +msgid "Options for support material and raft" +msgstr "Варіанти для опорного матеріалу та плоту" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:409 +msgid "Speed" +msgstr "Швидкість" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:410 +msgid "Speed for print moves" +msgstr "Швидкість друкарських рухів" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:422 +msgid "Speed for non-print moves" +msgstr "Швидкість недрукарських рухів" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:425 +msgid "Modifiers" +msgstr "Модифікатори" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:428 +msgid "Acceleration control (advanced)" +msgstr "Контроль прискорення (розширений)" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:435 +msgid "Autospeed (advanced)" +msgstr "Автоматична швидкість (розширена)" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:441 +msgid "Multiple Extruders" +msgstr "Кілька екструдерів" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:442 +msgid "Extruders" +msgstr "Екструдери" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:449 +msgid "Ooze prevention" +msgstr "Профілактика ?Ooze?" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:453 +msgid "Wipe tower" +msgstr "Вежа очищення" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:464 +msgid "Extrusion width" +msgstr "Ширина екструзії" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:474 +msgid "Overlap" +msgstr "Перекриття" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:477 +msgid "Flow" +msgstr "Потік" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:480 +msgid "Other" +msgstr "Інше" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:487 +msgid "Output options" +msgstr "Параметри виводу" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:488 +msgid "Sequential printing" +msgstr "Послідовне друкування" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:499 +msgid "Output file" +msgstr "Вихідний файл" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:505 +msgid "Post-processing scripts" +msgstr "Скрипти пост-обробки" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:511 +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:512 +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:867 +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:868 +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:1165 +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:1166 +msgid "Notes" +msgstr "Примітки" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:518 +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:875 +msgid "Dependencies" +msgstr "Залежності" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:519 +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:876 +msgid "Profile dependencies" +msgstr "Залежності профілю" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:794 +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:795 +msgid "Filament" +msgstr "Філаметн" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:802 +msgid "Temperature" +msgstr "Температура" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:803 +msgid "Extruder" +msgstr "Екструдер" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:808 +msgid "Bed" +msgstr "Полотно" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:813 +msgid "Cooling" +msgstr "Охолодження" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:814 +msgid "Enable" +msgstr "Увімкнути" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:825 +msgid "Fan settings" +msgstr "Налаштування вентилятора" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:834 +msgid "Cooling thresholds" +msgstr "Пороги охолодження" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:840 +msgid "Filament properties" +msgstr "Властивості філаменту" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:844 +msgid "Print speed override" +msgstr "Перевизначення швидкості друку" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:854 +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:1128 +msgid "Custom G-code" +msgstr "Користувацький G-код" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:855 +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:1129 +msgid "Start G-code" +msgstr "Початок G-коду" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:861 +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:1135 +msgid "End G-code" +msgstr "Закінчення G-коду" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:945 +msgid "General" +msgstr "Загальне" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:946 +msgid "Size and coordinates" +msgstr "Розмір і координати" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:948 +msgid "Bed shape" +msgstr "Форма полотна" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:950 +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:1649 +msgid "Set" +msgstr "Встановити" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:971 +msgid "Capabilities" +msgstr "Можливості" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:998 +msgid "USB/Serial connection" +msgstr "USB/послідовне з'єднання" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:1004 +msgid "Rescan serial ports" +msgstr "Сканувати ще раз послідовні порти" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:1013 +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:1081 +msgid "Test" +msgstr "Перевірити" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:1026 +msgid "Connection to printer works correctly." +msgstr "Підключення до принтера працює коректно." + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:1026 +msgid "Success!" +msgstr "Успіх!" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:1029 +msgid "Connection failed." +msgstr "Підключення не вдалося." + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:1041 +msgid "OctoPrint upload" +msgstr "Завантаження OctoPrint" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:1044 +msgid "Browse" +msgstr "Переглянути" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:1119 +msgid "Firmware" +msgstr "Прошивка" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:1141 +msgid "Before layer change G-code" +msgstr "G-код перед зміною шару " + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:1147 +msgid "After layer change G-code" +msgstr "G-код після зміни шару" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:1153 +msgid "Tool change G-code" +msgstr "G-код зміни інструменту " + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:1159 +msgid "Between objects G-code (for sequential printing)" +msgstr "G-код між об'єктами (для послідовного друку)" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:1195 +msgid "Extruder " +msgstr "Екструдер " + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:1198 +#: c:\src\Slic3r\xs\src\slic3r\GUI\BedShapeDialog.cpp:120 +msgid "Size" +msgstr "Розмір" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:1201 +msgid "Layer height limits" +msgstr "Межі висоти шару" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:1206 +msgid "Position (for multi-extruder printers)" +msgstr "Позиція (для мульти-екструдерних принтерів)" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:1209 +msgid "Retraction" +msgstr "Утягування/відкликання" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:1212 +msgid "Only lift Z" +msgstr "Межі підняття Z" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:1225 +msgid "" +"Retraction when tool is disabled (advanced settings for multi-extruder " +"setups)" +msgstr "" +"Утягування/відкликання при відключенні інструмента (додаткові налаштування " +"для налагодження мульти-екструдерів)" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:1229 +msgid "Preview" +msgstr "Попередній перегляд" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:1320 +msgid "" +"The Wipe option is not available when using the Firmware Retraction mode.\n" +"\n" +"Shall I disable it in order to enable Firmware Retraction?" +msgstr "" +"Параметр «Очистити» недоступний при використанні режиму програмного " +"утягування/відкликання.\n" +"\n" +"Відключити його для увімкнення програмного утягування/відкликання?" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:1322 +msgid "Firmware Retraction" +msgstr "Програмне утягування/відкликання" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:1565 +msgid "The supplied name is empty. It can't be saved." +msgstr "Надане ім'я порожнє. Не вдається зберегти." + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:1576 +msgid "Something is wrong. It can't be saved." +msgstr "Щось не так. Не вдається зберегти." + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:1593 +msgid "remove" +msgstr "перемістити" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:1593 +msgid "delete" +msgstr "видалити" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:1594 +msgid "Are you sure you want to " +msgstr "Ви впевнені, що хочете " + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:1594 +msgid " the selected preset?" +msgstr "вибране налаштування?" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:1595 +msgid "Remove" +msgstr "Перемістити" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:1595 +msgid "Delete" +msgstr "Видалити" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:1596 +msgid " Preset" +msgstr " Налаштування" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:1648 +msgid "All" +msgstr "Всі" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:1679 +msgid "Select the printers this profile is compatible with." +msgstr "Оберіть принтери, сумісні з цим профілем." + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:1680 +msgid "Compatible printers" +msgstr "Сумісні принтери" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:1763 +msgid "Save " +msgstr "Зберегти " + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:1763 +msgid " as:" +msgstr " як:" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:1797 +msgid "" +"The supplied name is not valid; the following characters are not allowed:" +msgstr "Надане ім'я недійсне; такі символи не допускаються:" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.cpp:1800 +msgid "The supplied name is not available." +msgstr "Надане ім'я недійсне." + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.hpp:178 +msgid "Print Settings" +msgstr "Налаштування друку" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.hpp:198 +msgid "Filament Settings" +msgstr "Налаштування філаменту" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.hpp:224 +msgid "Printer Settings" +msgstr "Налаштування принтеру" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Tab.hpp:244 +msgid "Save preset" +msgstr "Зберегти налаштування" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\Field.cpp:35 +msgid "default" +msgstr "за замовчуванням" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\BedShapeDialog.cpp:121 +msgid "Size in X and Y of the rectangular plate." +msgstr "Розмір прямокутної подложки за X та Y." + +#: c:\src\Slic3r\xs\src\slic3r\GUI\BedShapeDialog.cpp:127 +msgid "Origin" +msgstr "Початок координат" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\BedShapeDialog.cpp:128 +msgid "" +"Distance of the 0,0 G-code coordinate from the front left corner of the " +"rectangle." +msgstr "Відстань координат 0,0 G-коду від нижнього лівого кута прямокутника." + +#: c:\src\Slic3r\xs\src\slic3r\GUI\BedShapeDialog.cpp:135 +msgid "mm" +msgstr "мм" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\BedShapeDialog.cpp:136 +msgid "Diameter" +msgstr "Діаметр" + +#: c:\src\Slic3r\xs\src\slic3r\GUI\BedShapeDialog.cpp:137 +msgid "" +"Diameter of the print bed. It is assumed that origin (0,0) is located in the " +"center." +msgstr "" +"Діаметр подложки. Передбачається, що початок координат (0,0) знаходиться в " +"центрі." diff --git a/utils/post-processing/flowrate.pl b/utils/post-processing/flowrate.pl index 7aeef24dc..4d742631e 100755 --- a/utils/post-processing/flowrate.pl +++ b/utils/post-processing/flowrate.pl @@ -25,7 +25,7 @@ while (<>) { my $mm_per_mm = $e_length / $dist; # dE/dXY my $mm3_per_mm = ($filament_diameter[$T] ** 2) * PI/4 * $mm_per_mm; my $vol_speed = $F/60 * $mm3_per_mm; - my $comment = sprintf ' ; dXY = %.3fmm ; dE = %.5fmm ; dE/XY = %.5fmm/mm; volspeed = %.5fmm^3/sec', + my $comment = sprintf ' ; dXY = %.3fmm ; dE = %.5fmm ; dE/XY = %.5fmm/mm; volspeed = %.5fmm\u00B3/sec', $dist, $e_length, $mm_per_mm, $vol_speed; s/(\R+)/$comment$1/; } diff --git a/xs/CMakeLists.txt b/xs/CMakeLists.txt index a1848a67a..41bf9de26 100644 --- a/xs/CMakeLists.txt +++ b/xs/CMakeLists.txt @@ -74,6 +74,8 @@ add_library(libslic3r STATIC ${LIBDIR}/libslic3r/Fill/FillRectilinear3.hpp ${LIBDIR}/libslic3r/Flow.cpp ${LIBDIR}/libslic3r/Flow.hpp + ${LIBDIR}/libslic3r/Format/3mf.cpp + ${LIBDIR}/libslic3r/Format/3mf.hpp ${LIBDIR}/libslic3r/Format/AMF.cpp ${LIBDIR}/libslic3r/Format/AMF.hpp ${LIBDIR}/libslic3r/Format/OBJ.cpp @@ -179,6 +181,18 @@ add_library(libslic3r_gui STATIC ${LIBDIR}/slic3r/GUI/PresetHints.hpp ${LIBDIR}/slic3r/GUI/GUI.cpp ${LIBDIR}/slic3r/GUI/GUI.hpp + ${LIBDIR}/slic3r/GUI/Tab.cpp + ${LIBDIR}/slic3r/GUI/Tab.hpp + ${LIBDIR}/slic3r/GUI/TabIface.cpp + ${LIBDIR}/slic3r/GUI/TabIface.hpp + ${LIBDIR}/slic3r/GUI/Field.cpp + ${LIBDIR}/slic3r/GUI/Field.hpp + ${LIBDIR}/slic3r/GUI/OptionsGroup.cpp + ${LIBDIR}/slic3r/GUI/OptionsGroup.hpp + ${LIBDIR}/slic3r/GUI/BedShapeDialog.cpp + ${LIBDIR}/slic3r/GUI/BedShapeDialog.hpp + ${LIBDIR}/slic3r/GUI/2DBed.cpp + ${LIBDIR}/slic3r/GUI/2DBed.hpp ${LIBDIR}/slic3r/GUI/wxExtensions.cpp ${LIBDIR}/slic3r/GUI/wxExtensions.hpp ) @@ -193,6 +207,18 @@ add_library(admesh STATIC ${LIBDIR}/admesh/util.cpp ) +add_library(miniz STATIC + ${LIBDIR}/miniz/miniz.h + ${LIBDIR}/miniz/miniz_common.h + ${LIBDIR}/miniz/miniz_tdef.h + ${LIBDIR}/miniz/miniz_tinfl.h + ${LIBDIR}/miniz/miniz_zip.h + ${LIBDIR}/miniz/miniz.cpp + ${LIBDIR}/miniz/miniz_tdef.cpp + ${LIBDIR}/miniz/miniz_tinfl.cpp + ${LIBDIR}/miniz/miniz_zip.cpp +) + add_library(clipper STATIC ${LIBDIR}/clipper.cpp ${LIBDIR}/clipper.hpp @@ -293,6 +319,7 @@ set(XS_XSP_FILES ${XSP_DIR}/GUI_AppConfig.xsp ${XSP_DIR}/GUI_3DScene.xsp ${XSP_DIR}/GUI_Preset.xsp + ${XSP_DIR}/GUI_Tab.xsp ${XSP_DIR}/Layer.xsp ${XSP_DIR}/Line.xsp ${XSP_DIR}/Model.xsp @@ -352,7 +379,7 @@ if(APPLE) # Ignore undefined symbols of the perl interpreter, they will be found in the caller image. target_link_libraries(XS "-undefined dynamic_lookup") endif() -target_link_libraries(XS libslic3r libslic3r_gui admesh clipper nowide polypartition poly2tri) +target_link_libraries(XS libslic3r libslic3r_gui admesh miniz clipper nowide polypartition poly2tri) if(SLIC3R_PROFILE) target_link_libraries(XS Shiny) endif() @@ -555,7 +582,7 @@ endif() # Create a slic3r executable add_executable(slic3r ${PROJECT_SOURCE_DIR}/src/slic3r.cpp) target_include_directories(XS PRIVATE src src/libslic3r) -target_link_libraries(slic3r libslic3r libslic3r_gui admesh ${Boost_LIBRARIES} clipper ${EXPAT_LIBRARIES} ${GLEW_LIBRARIES} polypartition poly2tri ${TBB_LIBRARIES} ${wxWidgets_LIBRARIES}) +target_link_libraries(slic3r libslic3r libslic3r_gui admesh miniz ${Boost_LIBRARIES} clipper ${EXPAT_LIBRARIES} ${GLEW_LIBRARIES} polypartition poly2tri ${TBB_LIBRARIES} ${wxWidgets_LIBRARIES}) if(SLIC3R_PROFILE) target_link_libraries(Shiny) endif() diff --git a/xs/lib/Slic3r/XS.pm b/xs/lib/Slic3r/XS.pm index 26c8befe2..47a584343 100644 --- a/xs/lib/Slic3r/XS.pm +++ b/xs/lib/Slic3r/XS.pm @@ -283,6 +283,7 @@ for my $class (qw( Slic3r::GUI::_3DScene::GLVolume Slic3r::GUI::Preset Slic3r::GUI::PresetCollection + Slic3r::GUI::Tab Slic3r::Layer Slic3r::Layer::Region Slic3r::Layer::Support diff --git a/xs/src/libslic3r/Config.cpp b/xs/src/libslic3r/Config.cpp index 474be7237..1a0b8fb4a 100644 --- a/xs/src/libslic3r/Config.cpp +++ b/xs/src/libslic3r/Config.cpp @@ -324,7 +324,7 @@ void ConfigBase::setenv_() void ConfigBase::load(const std::string &file) { if (boost::iends_with(file, ".gcode") || boost::iends_with(file, ".g")) - this->load_from_gcode(file); + this->load_from_gcode_file(file); else this->load_from_ini(file); } @@ -349,10 +349,10 @@ void ConfigBase::load(const boost::property_tree::ptree &tree) } } -// Load the config keys from the tail of a G-code. -void ConfigBase::load_from_gcode(const std::string &file) +// Load the config keys from the tail of a G-code file. +void ConfigBase::load_from_gcode_file(const std::string &file) { - // 1) Read a 64k block from the end of the G-code. + // Read a 64k block from the end of the G-code. boost::nowide::ifstream ifs(file); { const char slic3r_gcode_header[] = "; generated by Slic3r "; @@ -365,30 +365,39 @@ void ConfigBase::load_from_gcode(const std::string &file) auto file_length = ifs.tellg(); auto data_length = std::min(65535, file_length); ifs.seekg(file_length - data_length, ifs.beg); - std::vector data(size_t(data_length) + 1, 0); - ifs.read(data.data(), data_length); + std::vector data(size_t(data_length) + 1, 0); + ifs.read(data.data(), data_length); ifs.close(); - // 2) Walk line by line in reverse until a non-configuration key appears. - char *data_start = data.data(); + load_from_gcode_string(data.data()); +} + +// Load the config keys from the given string. +void ConfigBase::load_from_gcode_string(const char* str) +{ + if (str == nullptr) + return; + + // Walk line by line in reverse until a non-configuration key appears. + char *data_start = const_cast(str); // boost::nowide::ifstream seems to cook the text data somehow, so less then the 64k of characters may be retrieved. - char *end = data_start + strlen(data.data()); + char *end = data_start + strlen(str); size_t num_key_value_pairs = 0; for (;;) { // Extract next line. - for (-- end; end > data_start && (*end == '\r' || *end == '\n'); -- end); + for (--end; end > data_start && (*end == '\r' || *end == '\n'); --end); if (end == data_start) break; char *start = end; - *(++ end) = 0; - for (; start > data_start && *start != '\r' && *start != '\n'; -- start); + *(++end) = 0; + for (; start > data_start && *start != '\r' && *start != '\n'; --start); if (start == data_start) break; // Extracted a line from start to end. Extract the key = value pair. - if (end - (++ start) < 10 || start[0] != ';' || start[1] != ' ') + if (end - (++start) < 10 || start[0] != ';' || start[1] != ' ') break; char *key = start + 2; - if (! (*key >= 'a' && *key <= 'z') || (*key >= 'A' && *key <= 'Z')) + if (!(*key >= 'a' && *key <= 'z') || (*key >= 'A' && *key <= 'Z')) // A key must start with a letter. break; char *sep = strchr(key, '='); @@ -402,8 +411,8 @@ void ConfigBase::load_from_gcode(const std::string &file) break; *key_end = 0; // The key may contain letters, digits and underscores. - for (char *c = key; c != key_end; ++ c) - if (! ((*c >= 'a' && *c <= 'z') || (*c >= 'A' && *c <= 'Z') || (*c >= '0' && *c <= '9') || *c == '_')) { + for (char *c = key; c != key_end; ++c) + if (!((*c >= 'a' && *c <= 'z') || (*c >= 'A' && *c <= 'Z') || (*c >= '0' && *c <= '9') || *c == '_')) { key = nullptr; break; } @@ -411,8 +420,9 @@ void ConfigBase::load_from_gcode(const std::string &file) break; try { this->set_deserialize(key, value); - ++ num_key_value_pairs; - } catch (UnknownOptionException & /* e */) { + ++num_key_value_pairs; + } + catch (UnknownOptionException & /* e */) { // ignore } end = start; diff --git a/xs/src/libslic3r/Config.hpp b/xs/src/libslic3r/Config.hpp index a58bb613a..3dccedbf0 100644 --- a/xs/src/libslic3r/Config.hpp +++ b/xs/src/libslic3r/Config.hpp @@ -1056,7 +1056,8 @@ public: void setenv_(); void load(const std::string &file); void load_from_ini(const std::string &file); - void load_from_gcode(const std::string &file); + void load_from_gcode_file(const std::string &file); + void load_from_gcode_string(const char* str); void load(const boost::property_tree::ptree &tree); void save(const std::string &file) const; diff --git a/xs/src/libslic3r/Format/3mf.cpp b/xs/src/libslic3r/Format/3mf.cpp new file mode 100644 index 000000000..029debf72 --- /dev/null +++ b/xs/src/libslic3r/Format/3mf.cpp @@ -0,0 +1,1396 @@ +#include "../libslic3r.h" +#include "../Model.hpp" +#include "../Utils.hpp" +#include "../GCode.hpp" +#include "../slic3r/GUI/PresetBundle.hpp" + +#include "3mf.hpp" + +#include +#include +#include +#include +#include + +#include +#include +#include + +const std::string MODEL_FOLDER = "3D/"; +const std::string MODEL_EXTENSION = ".model"; +const std::string MODEL_FILE = "3D/3dmodel.model"; // << this is the only format of the string which works with CURA +const std::string CONTENT_TYPES_FILE = "[Content_Types].xml"; +const std::string RELATIONSHIPS_FILE = "_rels/.rels"; +const std::string CONFIG_FILE = "Metadata/Slic3r_PE.config"; + +const char* MODEL_TAG = "model"; +const char* RESOURCES_TAG = "resources"; +const char* OBJECT_TAG = "object"; +const char* MESH_TAG = "mesh"; +const char* VERTICES_TAG = "vertices"; +const char* VERTEX_TAG = "vertex"; +const char* TRIANGLES_TAG = "triangles"; +const char* TRIANGLE_TAG = "triangle"; +const char* COMPONENTS_TAG = "components"; +const char* COMPONENT_TAG = "component"; +const char* BUILD_TAG = "build"; +const char* ITEM_TAG = "item"; + +const char* UNIT_ATTR = "unit"; +const char* NAME_ATTR = "name"; +const char* TYPE_ATTR = "type"; +const char* ID_ATTR = "id"; +const char* X_ATTR = "x"; +const char* Y_ATTR = "y"; +const char* Z_ATTR = "z"; +const char* V1_ATTR = "v1"; +const char* V2_ATTR = "v2"; +const char* V3_ATTR = "v3"; +const char* OBJECTID_ATTR = "objectid"; +const char* TRANSFORM_ATTR = "transform"; + +const unsigned int VALID_OBJECT_TYPES_COUNT = 1; +const char* VALID_OBJECT_TYPES[] = +{ + "model" +}; + +const unsigned int INVALID_OBJECT_TYPES_COUNT = 4; +const char* INVALID_OBJECT_TYPES[] = +{ + "solidsupport", + "support", + "surface", + "other" +}; + +typedef Eigen::Matrix Matrix4x4; + +const char* get_attribute_value_charptr(const char** attributes, unsigned int attributes_size, const char* attribute_key) +{ + if ((attributes == nullptr) || (attributes_size == 0) || (attributes_size % 2 != 0) || (attribute_key == nullptr)) + return nullptr; + + for (unsigned int a = 0; a < attributes_size; a += 2) + { + if (::strcmp(attributes[a], attribute_key) == 0) + return attributes[a + 1]; + } + + return nullptr; +} + +std::string get_attribute_value_string(const char** attributes, unsigned int attributes_size, const char* attribute_key) +{ + const char* text = get_attribute_value_charptr(attributes, attributes_size, attribute_key); + return (text != nullptr) ? text : ""; +} + +float get_attribute_value_float(const char** attributes, unsigned int attributes_size, const char* attribute_key) +{ + const char* text = get_attribute_value_charptr(attributes, attributes_size, attribute_key); + return (text != nullptr) ? (float)::atof(text) : 0.0f; +} + +int get_attribute_value_int(const char** attributes, unsigned int attributes_size, const char* attribute_key) +{ + const char* text = get_attribute_value_charptr(attributes, attributes_size, attribute_key); + return (text != nullptr) ? ::atoi(text) : 0; +} + +Matrix4x4 get_matrix_from_string(const std::string& mat_str) +{ + if (mat_str.empty()) + // empty string means default identity matrix + return Matrix4x4::Identity(); + + std::vector mat_elements_str; + boost::split(mat_elements_str, mat_str, boost::is_any_of(" "), boost::token_compress_on); + + unsigned int size = (unsigned int)mat_elements_str.size(); + if (size != 12) + // invalid data, return identity matrix + return Matrix4x4::Identity(); + + Matrix4x4 ret = Matrix4x4::Identity(); + unsigned int i = 0; + // matrices are stored into 3mf files as 4x3 + // we need to transpose them + for (unsigned int c = 0; c < 4; ++c) + { + for (unsigned int r = 0; r < 3; ++r) + { + ret(r, c) = (float)::atof(mat_elements_str[i++].c_str()); + } + } + return ret; +} + +float get_unit_factor(const std::string& unit) +{ + const char* text = unit.c_str(); + + if (::strcmp(text, "micron") == 0) + return 0.001f; + else if (::strcmp(text, "centimeter") == 0) + return 10.0f; + else if (::strcmp(text, "inch") == 0) + return 25.4f; + else if (::strcmp(text, "foot") == 0) + return 304.8f; + else if (::strcmp(text, "meter") == 0) + return 1000.0f; + else + // default "millimeters" (see specification) + return 1.0f; +} + +bool is_valid_object_type(const std::string& type) +{ + // if the type is empty defaults to "model" (see specification) + if (type.empty()) + return true; + + for (unsigned int i = 0; i < VALID_OBJECT_TYPES_COUNT; ++i) + { + if (::strcmp(type.c_str(), VALID_OBJECT_TYPES[i]) == 0) + return true; + } + + return false; +} + +namespace Slic3r { + + // Base class with error messages management + class _3MF_Base + { + std::vector m_errors; + + protected: + void add_error(const std::string& error) { m_errors.push_back(error); } + void clear_errors() { m_errors.clear(); } + + public: + void log_errors() + { + for (const std::string& error : m_errors) + { + printf("%s\n", error.c_str()); + } + } + }; + + class _3MF_Importer : public _3MF_Base + { + struct Component + { + int object_id; + Matrix4x4 matrix; + + explicit Component(int object_id); + Component(int object_id, const Matrix4x4& matrix); + }; + + typedef std::vector ComponentsList; + + struct CurrentObject + { + struct Geometry + { + std::vector vertices; + std::vector triangles; + + bool empty(); + void reset(); + }; + + int id; + Geometry geometry; + ModelObject* object; + TriangleMesh mesh; + ComponentsList components; + + CurrentObject(); + + void reset(); + }; + + struct Instance + { + ModelInstance* instance; + Matrix4x4 matrix; + + Instance(ModelInstance* instance, const Matrix4x4& matrix); + }; + + typedef std::map IdToModelObjectMap; + typedef std::map IdToAliasesMap; + typedef std::vector InstancesList; + + XML_Parser m_xml_parser; + Model* m_model; + float m_unit_factor; + CurrentObject m_curr_object; + IdToModelObjectMap m_objects; + IdToAliasesMap m_objects_aliases; + InstancesList m_instances; + + public: + _3MF_Importer(); + ~_3MF_Importer(); + + bool load_model_from_file(const std::string& filename, Model& model, PresetBundle& bundle); + + private: + void _destroy_xml_parser(); + void _stop_xml_parser(); + + bool _load_model_from_file(const std::string& filename, Model& model, PresetBundle& bundle); + bool _extract_model_from_archive(mz_zip_archive& archive, const mz_zip_archive_file_stat& stat); + bool _extract_config_from_archive(mz_zip_archive& archive, const mz_zip_archive_file_stat& stat, PresetBundle& bundle, const std::string& archive_filename); + + void _handle_start_xml_element(const char* name, const char** attributes); + void _handle_end_xml_element(const char* name); + + bool _handle_start_model(const char** attributes, unsigned int num_attributes); + bool _handle_end_model(); + + bool _handle_start_resources(const char** attributes, unsigned int num_attributes); + bool _handle_end_resources(); + + bool _handle_start_object(const char** attributes, unsigned int num_attributes); + bool _handle_end_object(); + + bool _handle_start_mesh(const char** attributes, unsigned int num_attributes); + bool _handle_end_mesh(); + + bool _handle_start_vertices(const char** attributes, unsigned int num_attributes); + bool _handle_end_vertices(); + + bool _handle_start_vertex(const char** attributes, unsigned int num_attributes); + bool _handle_end_vertex(); + + bool _handle_start_triangles(const char** attributes, unsigned int num_attributes); + bool _handle_end_triangles(); + + bool _handle_start_triangle(const char** attributes, unsigned int num_attributes); + bool _handle_end_triangle(); + + bool _handle_start_components(const char** attributes, unsigned int num_attributes); + bool _handle_end_components(); + + bool _handle_start_component(const char** attributes, unsigned int num_attributes); + bool _handle_end_component(); + + bool _handle_start_build(const char** attributes, unsigned int num_attributes); + bool _handle_end_build(); + + bool _handle_start_item(const char** attributes, unsigned int num_attributes); + bool _handle_end_item(); + + bool _create_object_instance(int object_id, const Matrix4x4& matrix, unsigned int recur_counter); + + void _apply_transform(ModelObject& object, const Matrix4x4& matrix); + void _apply_transform(ModelInstance& instance, const Matrix4x4& matrix); + + static void XMLCALL _handle_start_xml_element(void* userData, const char* name, const char** attributes); + static void XMLCALL _handle_end_xml_element(void* userData, const char* name); + }; + + _3MF_Importer::Component::Component(int object_id) + : object_id(object_id) + , matrix(Matrix4x4::Identity()) + { + } + + _3MF_Importer::Component::Component(int object_id, const Matrix4x4& matrix) + : object_id(object_id) + , matrix(matrix) + { + } + + bool _3MF_Importer::CurrentObject::Geometry::empty() + { + return vertices.empty() || triangles.empty(); + } + + void _3MF_Importer::CurrentObject::Geometry::reset() + { + vertices.clear(); + triangles.clear(); + } + + _3MF_Importer::CurrentObject::CurrentObject() + { + reset(); + } + + void _3MF_Importer::CurrentObject::reset() + { + id = -1; + geometry.reset(); + object = nullptr; + mesh = TriangleMesh(); + components.clear(); + } + + _3MF_Importer::Instance::Instance(ModelInstance* instance, const Matrix4x4& matrix) + : instance(instance) + , matrix(matrix) + { + } + + _3MF_Importer::_3MF_Importer() + : m_xml_parser(nullptr) + , m_model(nullptr) + , m_unit_factor(1.0f) + { + } + + _3MF_Importer::~_3MF_Importer() + { + _destroy_xml_parser(); + } + + bool _3MF_Importer::load_model_from_file(const std::string& filename, Model& model, PresetBundle& bundle) + { + m_model = &model; + m_unit_factor = 1.0f; + m_curr_object.reset(); + m_objects.clear(); + m_objects_aliases.clear(); + m_instances.clear(); + clear_errors(); + + return _load_model_from_file(filename, model, bundle); + } + + void _3MF_Importer::_destroy_xml_parser() + { + if (m_xml_parser != nullptr) + { + XML_ParserFree(m_xml_parser); + m_xml_parser = nullptr; + } + } + + void _3MF_Importer::_stop_xml_parser() + { + if (m_xml_parser != nullptr) + XML_StopParser(m_xml_parser, false); + } + + bool _3MF_Importer::_load_model_from_file(const std::string& filename, Model& model, PresetBundle& bundle) + { + mz_zip_archive archive; + mz_zip_zero_struct(&archive); + + mz_bool res = mz_zip_reader_init_file(&archive, filename.c_str(), 0); + if (res == 0) + { + add_error("Unable to open the file"); + return false; + } + + mz_uint num_entries = mz_zip_reader_get_num_files(&archive); + + mz_zip_archive_file_stat stat; + for (mz_uint i = 0; i < num_entries; ++i) + { + if (mz_zip_reader_file_stat(&archive, i, &stat)) + { + std::string name(stat.m_filename); + std::replace(name.begin(), name.end(), '\\', '/'); + + if (boost::algorithm::istarts_with(name, MODEL_FOLDER) && boost::algorithm::iends_with(name, MODEL_EXTENSION)) + { + // valid model name -> extract model + if (!_extract_model_from_archive(archive, stat)) + { + mz_zip_reader_end(&archive); + add_error("Archive does not contain a valid model"); + return false; + } + } + else if (boost::algorithm::iequals(name, CONFIG_FILE)) + { + // extract slic3r config file + if (!_extract_config_from_archive(archive, stat, bundle, filename)) + { + mz_zip_reader_end(&archive); + add_error("Archive does not contain a valid config"); + return false; + } + } + } + } + + mz_zip_reader_end(&archive); + return true; + } + + bool _3MF_Importer::_extract_model_from_archive(mz_zip_archive& archive, const mz_zip_archive_file_stat& stat) + { + if (stat.m_uncomp_size == 0) + { + add_error("Found invalid size"); + return false; + } + + _destroy_xml_parser(); + + m_xml_parser = XML_ParserCreate(nullptr); + if (m_xml_parser == nullptr) + { + add_error("Unable to create parser"); + return false; + } + + XML_SetUserData(m_xml_parser, (void*)this); + XML_SetElementHandler(m_xml_parser, _3MF_Importer::_handle_start_xml_element, _3MF_Importer::_handle_end_xml_element); + + void* parser_buffer = XML_GetBuffer(m_xml_parser, (int)stat.m_uncomp_size); + if (parser_buffer == nullptr) + { + add_error("Unable to create buffer"); + return false; + } + + mz_bool res = mz_zip_reader_extract_file_to_mem(&archive, stat.m_filename, parser_buffer, (size_t)stat.m_uncomp_size, 0); + if (res == 0) + { + add_error("Error while reading model data to buffer"); + return false; + } + + if (!XML_ParseBuffer(m_xml_parser, (int)stat.m_uncomp_size, 1)) + { + char error_buf[1024]; + ::sprintf(error_buf, "Error (%s) while parsing xml file at line %d", XML_ErrorString(XML_GetErrorCode(m_xml_parser)), XML_GetCurrentLineNumber(m_xml_parser)); + add_error(error_buf); + return false; + } + + return true; + } + + bool _3MF_Importer::_extract_config_from_archive(mz_zip_archive& archive, const mz_zip_archive_file_stat& stat, PresetBundle& bundle, const std::string& archive_filename) + { + if (stat.m_uncomp_size > 0) + { + std::vector buffer((size_t)stat.m_uncomp_size + 1, 0); + mz_bool res = mz_zip_reader_extract_file_to_mem(&archive, stat.m_filename, (void*)buffer.data(), (size_t)stat.m_uncomp_size, 0); + if (res == 0) + { + add_error("Error while reading config data to buffer"); + return false; + } + + buffer.back() = '\0'; + bundle.load_config_string(buffer.data(), archive_filename.c_str()); + } + + return true; + } + + void _3MF_Importer::_handle_start_xml_element(const char* name, const char** attributes) + { + if (m_xml_parser == nullptr) + return; + + bool res = true; + unsigned int num_attributes = (unsigned int)XML_GetSpecifiedAttributeCount(m_xml_parser); + + if (::strcmp(MODEL_TAG, name) == 0) + res = _handle_start_model(attributes, num_attributes); + else if (::strcmp(RESOURCES_TAG, name) == 0) + res = _handle_start_resources(attributes, num_attributes); + else if (::strcmp(OBJECT_TAG, name) == 0) + res = _handle_start_object(attributes, num_attributes); + else if (::strcmp(MESH_TAG, name) == 0) + res = _handle_start_mesh(attributes, num_attributes); + else if (::strcmp(VERTICES_TAG, name) == 0) + res = _handle_start_vertices(attributes, num_attributes); + else if (::strcmp(VERTEX_TAG, name) == 0) + res = _handle_start_vertex(attributes, num_attributes); + else if (::strcmp(TRIANGLES_TAG, name) == 0) + res = _handle_start_triangles(attributes, num_attributes); + else if (::strcmp(TRIANGLE_TAG, name) == 0) + res = _handle_start_triangle(attributes, num_attributes); + else if (::strcmp(COMPONENTS_TAG, name) == 0) + res = _handle_start_components(attributes, num_attributes); + else if (::strcmp(COMPONENT_TAG, name) == 0) + res = _handle_start_component(attributes, num_attributes); + else if (::strcmp(BUILD_TAG, name) == 0) + res = _handle_start_build(attributes, num_attributes); + else if (::strcmp(ITEM_TAG, name) == 0) + res = _handle_start_item(attributes, num_attributes); + + if (!res) + _stop_xml_parser(); + } + + void _3MF_Importer::_handle_end_xml_element(const char* name) + { + if (m_xml_parser == nullptr) + return; + + bool res = true; + + if (::strcmp(MODEL_TAG, name) == 0) + res = _handle_end_model(); + else if (::strcmp(RESOURCES_TAG, name) == 0) + res = _handle_end_resources(); + else if (::strcmp(OBJECT_TAG, name) == 0) + res = _handle_end_object(); + else if (::strcmp(MESH_TAG, name) == 0) + res = _handle_end_mesh(); + else if (::strcmp(VERTICES_TAG, name) == 0) + res = _handle_end_vertices(); + else if (::strcmp(VERTEX_TAG, name) == 0) + res = _handle_end_vertex(); + else if (::strcmp(TRIANGLES_TAG, name) == 0) + res = _handle_end_triangles(); + else if (::strcmp(TRIANGLE_TAG, name) == 0) + res = _handle_end_triangle(); + else if (::strcmp(COMPONENTS_TAG, name) == 0) + res = _handle_end_components(); + else if (::strcmp(COMPONENT_TAG, name) == 0) + res = _handle_end_component(); + else if (::strcmp(BUILD_TAG, name) == 0) + res = _handle_end_build(); + else if (::strcmp(ITEM_TAG, name) == 0) + res = _handle_end_item(); + + if (!res) + _stop_xml_parser(); + } + + bool _3MF_Importer::_handle_start_model(const char** attributes, unsigned int num_attributes) + { + m_unit_factor = get_unit_factor(get_attribute_value_string(attributes, num_attributes, UNIT_ATTR)); + return true; + } + + bool _3MF_Importer::_handle_end_model() + { + // deletes all non-built or non-instanced objects + for (const IdToModelObjectMap::value_type& object : m_objects) + { + if ((object.second != nullptr) && (object.second->instances.size() == 0)) + m_model->delete_object(object.second); + } + + // applies instances' matrices + for (Instance& instance : m_instances) + { + if (instance.instance != nullptr) + { + ModelObject* object = instance.instance->get_object(); + if (object != nullptr) + { + if (object->instances.size() == 1) + { + // single instance -> apply the matrix to object geometry + _apply_transform(*object, instance.matrix); + } + else + { + // multiple instances -> apply the matrix to the instance + _apply_transform(*instance.instance, instance.matrix); + } + } + } + } + + return true; + } + + bool _3MF_Importer::_handle_start_resources(const char** attributes, unsigned int num_attributes) + { + // do nothing + return true; + } + + bool _3MF_Importer::_handle_end_resources() + { + // do nothing + return true; + } + + bool _3MF_Importer::_handle_start_object(const char** attributes, unsigned int num_attributes) + { + // reset current data + m_curr_object.reset(); + + if (is_valid_object_type(get_attribute_value_string(attributes, num_attributes, TYPE_ATTR))) + { + // create new object (it may be removed later if no instances are generated from it) + m_curr_object.object = m_model->add_object(); + if (m_curr_object.object == nullptr) + { + add_error("Unable to create object"); + return false; + } + + // set object data + m_curr_object.object->name = get_attribute_value_string(attributes, num_attributes, NAME_ATTR); + m_curr_object.id = get_attribute_value_int(attributes, num_attributes, ID_ATTR); + } + + return true; + } + + bool _3MF_Importer::_handle_end_object() + { + if (m_curr_object.object != nullptr) + { + if (m_curr_object.geometry.empty()) + { + // no geometry defined + // remove the object from the model + m_model->delete_object(m_curr_object.object); + + if (m_curr_object.components.empty()) + { + // no components defined -> invalid object, delete it + IdToModelObjectMap::iterator object_item = m_objects.find(m_curr_object.id); + if (object_item != m_objects.end()) + m_objects.erase(object_item); + + IdToAliasesMap::iterator alias_item = m_objects_aliases.find(m_curr_object.id); + if (alias_item != m_objects_aliases.end()) + m_objects_aliases.erase(alias_item); + } + else + // adds components to aliases + m_objects_aliases.insert(IdToAliasesMap::value_type(m_curr_object.id, m_curr_object.components)); + } + else + { + // geometry defined, add it to the object + + ModelVolume* volume = m_curr_object.object->add_volume(m_curr_object.mesh); + if (volume == nullptr) + { + add_error("Unable to add volume"); + return false; + } + + stl_file& stl = volume->mesh.stl; + stl.stats.type = inmemory; + stl.stats.number_of_facets = (uint32_t)m_curr_object.geometry.triangles.size() / 3; + stl.stats.original_num_facets = (int)stl.stats.number_of_facets; + stl_allocate(&stl); + for (size_t i = 0; i < m_curr_object.geometry.triangles.size(); /*nothing*/) + { + stl_facet& facet = stl.facet_start[i / 3]; + for (unsigned int v = 0; v < 3; ++v) + { + ::memcpy((void*)&facet.vertex[v].x, (const void*)&m_curr_object.geometry.vertices[m_curr_object.geometry.triangles[i++] * 3], 3 * sizeof(float)); + } + } + stl_get_size(&stl); + volume->mesh.repair(); + + // stores the object for later use + if (m_objects.find(m_curr_object.id) == m_objects.end()) + { + m_objects.insert(IdToModelObjectMap::value_type(m_curr_object.id, m_curr_object.object)); + m_objects_aliases.insert(IdToAliasesMap::value_type(m_curr_object.id, ComponentsList(1, Component(m_curr_object.id)))); // aliases itself + } + else + { + add_error("Found object with duplicate id"); + return false; + } + } + } + + return true; + } + + bool _3MF_Importer::_handle_start_mesh(const char** attributes, unsigned int num_attributes) + { + // reset current geometry + m_curr_object.geometry.reset(); + return true; + } + + bool _3MF_Importer::_handle_end_mesh() + { + // do nothing + return true; + } + + bool _3MF_Importer::_handle_start_vertices(const char** attributes, unsigned int num_attributes) + { + // reset current vertices + m_curr_object.geometry.vertices.clear(); + return true; + } + + bool _3MF_Importer::_handle_end_vertices() + { + // do nothing + return true; + } + + bool _3MF_Importer::_handle_start_vertex(const char** attributes, unsigned int num_attributes) + { + // appends the vertex coordinates + // missing values are set equal to ZERO + m_curr_object.geometry.vertices.push_back(m_unit_factor * get_attribute_value_float(attributes, num_attributes, X_ATTR)); + m_curr_object.geometry.vertices.push_back(m_unit_factor * get_attribute_value_float(attributes, num_attributes, Y_ATTR)); + m_curr_object.geometry.vertices.push_back(m_unit_factor * get_attribute_value_float(attributes, num_attributes, Z_ATTR)); + return true; + } + + bool _3MF_Importer::_handle_end_vertex() + { + // do nothing + return true; + } + + bool _3MF_Importer::_handle_start_triangles(const char** attributes, unsigned int num_attributes) + { + // reset current triangles + m_curr_object.geometry.triangles.clear(); + return true; + } + + bool _3MF_Importer::_handle_end_triangles() + { + // do nothing + return true; + } + + bool _3MF_Importer::_handle_start_triangle(const char** attributes, unsigned int num_attributes) + { + // we are ignoring the following attributes: + // p1 + // p2 + // p3 + // pid + // see specifications + + // appends the triangle's vertices indices + // missing values are set equal to ZERO + m_curr_object.geometry.triangles.push_back((unsigned int)get_attribute_value_int(attributes, num_attributes, V1_ATTR)); + m_curr_object.geometry.triangles.push_back((unsigned int)get_attribute_value_int(attributes, num_attributes, V2_ATTR)); + m_curr_object.geometry.triangles.push_back((unsigned int)get_attribute_value_int(attributes, num_attributes, V3_ATTR)); + return true; + } + + bool _3MF_Importer::_handle_end_triangle() + { + // do nothing + return true; + } + + bool _3MF_Importer::_handle_start_components(const char** attributes, unsigned int num_attributes) + { + // reset current components + m_curr_object.components.clear(); + return true; + } + + bool _3MF_Importer::_handle_end_components() + { + // do nothing + return true; + } + + bool _3MF_Importer::_handle_start_component(const char** attributes, unsigned int num_attributes) + { + int object_id = get_attribute_value_int(attributes, num_attributes, OBJECTID_ATTR); + Matrix4x4 matrix = get_matrix_from_string(get_attribute_value_string(attributes, num_attributes, TRANSFORM_ATTR)); + + IdToModelObjectMap::iterator object_item = m_objects.find(object_id); + if (object_item == m_objects.end()) + { + IdToAliasesMap::iterator alias_item = m_objects_aliases.find(object_id); + if (alias_item == m_objects_aliases.end()) + { + add_error("Found component with invalid object id"); + return false; + } + } + + m_curr_object.components.emplace_back(object_id, matrix); + + return true; + } + + bool _3MF_Importer::_handle_end_component() + { + // do nothing + return true; + } + + bool _3MF_Importer::_handle_start_build(const char** attributes, unsigned int num_attributes) + { + // do nothing + return true; + } + + bool _3MF_Importer::_handle_end_build() + { + // do nothing + return true; + } + + bool _3MF_Importer::_handle_start_item(const char** attributes, unsigned int num_attributes) + { + // we are ignoring the following attributes + // thumbnail + // partnumber + // pid + // pindex + // see specifications + + int object_id = get_attribute_value_int(attributes, num_attributes, OBJECTID_ATTR); + Matrix4x4 matrix = get_matrix_from_string(get_attribute_value_string(attributes, num_attributes, TRANSFORM_ATTR)); + + return _create_object_instance(object_id, matrix, 1); + } + + bool _3MF_Importer::_handle_end_item() + { + // do nothing + return true; + } + + bool _3MF_Importer::_create_object_instance(int object_id, const Matrix4x4& matrix, unsigned int recur_counter) + { + static const unsigned int MAX_RECURSIONS = 10; + + // escape from circular aliasing + if (recur_counter > MAX_RECURSIONS) + { + add_error("Too many recursions"); + return false; + } + + IdToAliasesMap::iterator it = m_objects_aliases.find(object_id); + if (it == m_objects_aliases.end()) + { + add_error("Found item with invalid object id"); + return false; + } + + if ((it->second.size() == 1) && (it->second[0].object_id == object_id)) + { + // aliasing to itself + + IdToModelObjectMap::iterator object_item = m_objects.find(object_id); + if ((object_item == m_objects.end()) || (object_item->second == nullptr)) + { + add_error("Found invalid object"); + return false; + } + else + { + ModelInstance* instance = object_item->second->add_instance(); + if (instance == nullptr) + { + add_error("Unable to add object instance"); + return false; + } + + m_instances.emplace_back(instance, matrix); + } + } + else + { + // recursively process nested components + for (const Component& component : it->second) + { + if (!_create_object_instance(component.object_id, matrix * component.matrix, recur_counter + 1)) + return false; + } + } + + return true; + } + + void _3MF_Importer::_apply_transform(ModelObject& object, const Matrix4x4& matrix) + { + float matrix3x4[12] = { matrix(0, 0), matrix(0, 1), matrix(0, 2), matrix(0, 3), + matrix(1, 0), matrix(1, 1), matrix(1, 2), matrix(1, 3), + matrix(2, 0), matrix(2, 1), matrix(2, 2), matrix(2, 3) }; + + object.transform(matrix3x4); + } + + void _3MF_Importer::_apply_transform(ModelInstance& instance, const Matrix4x4& matrix) + { + // slic3r ModelInstance cannot be transformed using a matrix + // we extract from the given matrix only the values currently used + + // translation + double offset_x = (double)matrix(0, 3); + double offset_y = (double)matrix(1, 3); + double offset_z = (double)matrix(2, 3); + + // scale + double sx = ::sqrt(sqr((double)matrix(0, 0)) + sqr((double)matrix(1, 0)) + sqr((double)matrix(2, 0))); + double sy = ::sqrt(sqr((double)matrix(0, 1)) + sqr((double)matrix(1, 1)) + sqr((double)matrix(2, 1))); + double sz = ::sqrt(sqr((double)matrix(0, 2)) + sqr((double)matrix(1, 2)) + sqr((double)matrix(2, 2))); + + // invalid scale value, return + if ((sx == 0.0) || (sy == 0.0) || (sz == 0.0)) + return; + + // non-uniform scale value, return + if ((std::abs(sx - sy) > 0.00001) || (std::abs(sx - sz) > 0.00001)) + return; + + // rotations (extracted using quaternion) + double inv_sx = 1.0 / sx; + double inv_sy = 1.0 / sy; + double inv_sz = 1.0 / sz; + + Eigen::Matrix m3x3; + m3x3 << (double)matrix(0, 0) * inv_sx, (double)matrix(0, 1) * inv_sy, (double)matrix(0, 2) * inv_sz, + (double)matrix(1, 0) * inv_sx, (double)matrix(1, 1) * inv_sy, (double)matrix(1, 2) * inv_sz, + (double)matrix(2, 0) * inv_sx, (double)matrix(2, 1) * inv_sy, (double)matrix(2, 2) * inv_sz; + + double qw = 0.5 * ::sqrt(std::max(0.0, 1.0 + m3x3(0, 0) + m3x3(1, 1) + m3x3(2, 2))); + double qx = 0.5 * ::sqrt(std::max(0.0, 1.0 + m3x3(0, 0) - m3x3(1, 1) - m3x3(2, 2))); + double qy = 0.5 * ::sqrt(std::max(0.0, 1.0 - m3x3(0, 0) + m3x3(1, 1) - m3x3(2, 2))); + double qz = 0.5 * ::sqrt(std::max(0.0, 1.0 - m3x3(0, 0) - m3x3(1, 1) + m3x3(2, 2))); + + double q_magnitude = ::sqrt(sqr(qw) + sqr(qx) + sqr(qy) + sqr(qz)); + + // invalid length, return + if (q_magnitude == 0.0) + return; + + double inv_q_magnitude = 1.0 / q_magnitude; + + qw *= inv_q_magnitude; + qx *= inv_q_magnitude; + qy *= inv_q_magnitude; + qz *= inv_q_magnitude; + + double test = qx * qy + qz * qw; + double angle_x, angle_y, angle_z; + + if (test > 0.499) + { + // singularity at north pole + angle_x = 0.0; + angle_y = 2.0 * ::atan2(qx, qw); + angle_z = 0.5 * PI; + } + else if (test < -0.499) + { + // singularity at south pole + angle_x = 0.0; + angle_y = -2.0 * ::atan2(qx, qw); + angle_z = -0.5 * PI; + } + else + { + angle_x = ::atan2(2.0 * qx * qw - 2.0 * qy * qz, 1.0 - 2.0 * sqr(qx) - 2.0 * sqr(qz)); + angle_y = ::atan2(2.0 * qy * qw - 2.0 * qx * qz, 1.0 - 2.0 * sqr(qy) - 2.0 * sqr(qz)); + angle_z = ::asin(2.0 * qx * qy + 2.0 * qz * qw); + + if (angle_x < 0.0) + angle_x += 2.0 * PI; + + if (angle_y < 0.0) + angle_y += 2.0 * PI; + + if (angle_z < 0.0) + angle_z += 2.0 * PI; + } + + instance.offset.x = offset_x; + instance.offset.y = offset_y; + instance.scaling_factor = sx; + instance.rotation = angle_z; + } + + void XMLCALL _3MF_Importer::_handle_start_xml_element(void* userData, const char* name, const char** attributes) + { + _3MF_Importer* importer = (_3MF_Importer*)userData; + if (importer != nullptr) + importer->_handle_start_xml_element(name, attributes); + } + + void XMLCALL _3MF_Importer::_handle_end_xml_element(void* userData, const char* name) + { + _3MF_Importer* importer = (_3MF_Importer*)userData; + if (importer != nullptr) + importer->_handle_end_xml_element(name); + } + + class _3MF_Exporter : public _3MF_Base + { + struct BuildItem + { + unsigned int id; + Matrix4x4 matrix; + + BuildItem(unsigned int id, const Matrix4x4& matrix); + }; + + typedef std::vector BuildItemsList; + + public: + bool save_model_to_file(const std::string& filename, Model& model, const Print& print); + + private: + bool _save_model_to_file(const std::string& filename, Model& model, const Print& print); + bool _add_content_types_file_to_archive(mz_zip_archive& archive); + bool _add_relationships_file_to_archive(mz_zip_archive& archive); + bool _add_model_file_to_archive(mz_zip_archive& archive, Model& model); + bool _add_object_to_model_stream(std::stringstream& stream, unsigned int& object_id, ModelObject& object, BuildItemsList& build_items); + bool _add_mesh_to_object_stream(std::stringstream& stream, ModelObject& object); + bool _add_build_to_model_stream(std::stringstream& stream, const BuildItemsList& build_items); + bool _add_config_file_to_archive(mz_zip_archive& archive, const Print& print); + }; + + _3MF_Exporter::BuildItem::BuildItem(unsigned int id, const Matrix4x4& matrix) + : id(id) + , matrix(matrix) + { + } + + bool _3MF_Exporter::save_model_to_file(const std::string& filename, Model& model, const Print& print) + { + clear_errors(); + return _save_model_to_file(filename, model, print); + } + + bool _3MF_Exporter::_save_model_to_file(const std::string& filename, Model& model, const Print& print) + { + mz_zip_archive archive; + mz_zip_zero_struct(&archive); + + mz_bool res = mz_zip_writer_init_file(&archive, filename.c_str(), 0); + if (res == 0) + { + add_error("Unable to open the file"); + return false; + } + + // adds content types file + if (!_add_content_types_file_to_archive(archive)) + { + mz_zip_writer_end(&archive); + boost::filesystem::remove(filename); + return false; + } + + // adds relationships file + if (!_add_relationships_file_to_archive(archive)) + { + mz_zip_writer_end(&archive); + boost::filesystem::remove(filename); + return false; + } + + // adds model file + if (!_add_model_file_to_archive(archive, model)) + { + mz_zip_writer_end(&archive); + boost::filesystem::remove(filename); + return false; + } + + // adds slic3r config file + if (!_add_config_file_to_archive(archive, print)) + { + mz_zip_writer_end(&archive); + boost::filesystem::remove(filename); + return false; + } + + if (!mz_zip_writer_finalize_archive(&archive)) + { + mz_zip_writer_end(&archive); + boost::filesystem::remove(filename); + add_error("Unable to finalize the archive"); + return false; + } + + mz_zip_writer_end(&archive); + + return true; + } + + bool _3MF_Exporter::_add_content_types_file_to_archive(mz_zip_archive& archive) + { + std::stringstream stream; + stream << "\n"; + stream << "\n"; + stream << " \n"; + stream << " \n"; + stream << ""; + + std::string out = stream.str(); + + if (!mz_zip_writer_add_mem(&archive, CONTENT_TYPES_FILE.c_str(), (const void*)out.data(), out.length(), MZ_DEFAULT_COMPRESSION)) + { + add_error("Unable to add content types file to archive"); + return false; + } + + return true; + } + + bool _3MF_Exporter::_add_relationships_file_to_archive(mz_zip_archive& archive) + { + std::stringstream stream; + stream << "\n"; + stream << "\n"; + stream << " \n"; + stream << ""; + + std::string out = stream.str(); + + if (!mz_zip_writer_add_mem(&archive, RELATIONSHIPS_FILE.c_str(), (const void*)out.data(), out.length(), MZ_DEFAULT_COMPRESSION)) + { + add_error("Unable to add relationships file to archive"); + return false; + } + + return true; + } + + bool _3MF_Exporter::_add_model_file_to_archive(mz_zip_archive& archive, Model& model) + { + std::stringstream stream; + stream << "\n"; + stream << "\n"; + stream << " \n"; + + BuildItemsList build_items; + + unsigned int object_id = 1; + for (ModelObject* obj : model.objects) + { + if (obj == nullptr) + continue; + + if (!_add_object_to_model_stream(stream, object_id, *obj, build_items)) + { + add_error("Unable to add object to archive"); + return false; + } + } + + + stream << " \n"; + + if (!_add_build_to_model_stream(stream, build_items)) + { + add_error("Unable to add build to archive"); + return false; + } + + stream << "\n"; + + std::string out = stream.str(); + + if (!mz_zip_writer_add_mem(&archive, MODEL_FILE.c_str(), (const void*)out.data(), out.length(), MZ_DEFAULT_COMPRESSION)) + { + add_error("Unable to add model file to archive"); + return false; + } + + return true; + } + + bool _3MF_Exporter::_add_object_to_model_stream(std::stringstream& stream, unsigned int& object_id, ModelObject& object, BuildItemsList& build_items) + { + unsigned int id = 0; + for (const ModelInstance* instance : object.instances) + { + if (instance == nullptr) + continue; + + unsigned int instance_id = object_id + id; + stream << " \n"; + + if (id == 0) + { + if (!_add_mesh_to_object_stream(stream, object)) + { + add_error("Unable to add mesh to archive"); + return false; + } + } + else + { + stream << " \n"; + stream << " \n"; + stream << " \n"; + } + + Eigen::Affine3f transform; + transform = Eigen::Translation3f((float)(instance->offset.x + object.origin_translation.x), (float)(instance->offset.y + object.origin_translation.y), (float)object.origin_translation.z) + * Eigen::AngleAxisf((float)instance->rotation, Eigen::Vector3f::UnitZ()) + * Eigen::Scaling((float)instance->scaling_factor); + build_items.emplace_back(instance_id, transform.matrix()); + + stream << " \n"; + + ++id; + } + + object_id += id; + return true; + } + + bool _3MF_Exporter::_add_mesh_to_object_stream(std::stringstream& stream, ModelObject& object) + { + stream << " \n"; + stream << " \n"; + + typedef std::map VolumeToOffsetMap; + VolumeToOffsetMap volumes_offset; + unsigned int vertices_count = 0; + for (ModelVolume* volume : object.volumes) + { + if (volume == nullptr) + continue; + + volumes_offset.insert(VolumeToOffsetMap::value_type(volume, vertices_count)); + + if (!volume->mesh.repaired) + volume->mesh.repair(); + + stl_file& stl = volume->mesh.stl; + if (stl.v_shared == nullptr) + stl_generate_shared_vertices(&stl); + + if (stl.stats.shared_vertices == 0) + { + add_error("Found invalid mesh"); + return false; + } + + vertices_count += stl.stats.shared_vertices; + + for (int i = 0; i < stl.stats.shared_vertices; ++i) + { + stream << " \n"; + } + } + + stream << " \n"; + stream << " \n"; + + for (ModelVolume* volume : object.volumes) + { + if (volume == nullptr) + continue; + + VolumeToOffsetMap::const_iterator offset_it = volumes_offset.find(volume); + assert(offset_it != volumes_offset.end()); + + stl_file& stl = volume->mesh.stl; + + for (uint32_t i = 0; i < stl.stats.number_of_facets; ++i) + { + stream << " second << "\" "; + } + stream << "/>\n"; + } + + } + + stream << " \n"; + stream << " \n"; + + return true; + } + + bool _3MF_Exporter::_add_build_to_model_stream(std::stringstream& stream, const BuildItemsList& build_items) + { + if (build_items.size() == 0) + { + add_error("No build item found"); + return false; + } + + stream << " \n"; + + for (const BuildItem& item : build_items) + { + stream << " \n"; + } + + stream << " \n"; + + return true; + } + + bool _3MF_Exporter::_add_config_file_to_archive(mz_zip_archive& archive, const Print& print) + { + char buffer[1024]; + sprintf(buffer, "; %s\n\n", header_slic3r_generated().c_str()); + std::string out = buffer; + + GCode::append_full_config(print, out); + + if (!mz_zip_writer_add_mem(&archive, CONFIG_FILE.c_str(), (const void*)out.data(), out.length(), MZ_DEFAULT_COMPRESSION)) + { + add_error("Unable to add config file to archive"); + return false; + } + + return true; + } + + bool load_3mf(const char* path, PresetBundle* bundle, Model* model) + { + if ((path == nullptr) || (bundle == nullptr) || (model == nullptr)) + return false; + + _3MF_Importer importer; + bool res = importer.load_model_from_file(path, *model, *bundle); + + if (!res) + importer.log_errors(); + + return res; + } + + bool store_3mf(const char* path, Model* model, Print* print) + { + if ((path == nullptr) || (model == nullptr) || (print == nullptr)) + return false; + + _3MF_Exporter exporter; + bool res = exporter.save_model_to_file(path, *model, *print); + + if (!res) + exporter.log_errors(); + + return res; + } + +} // namespace Slic3r diff --git a/xs/src/libslic3r/Format/3mf.hpp b/xs/src/libslic3r/Format/3mf.hpp new file mode 100644 index 000000000..9b48c860b --- /dev/null +++ b/xs/src/libslic3r/Format/3mf.hpp @@ -0,0 +1,19 @@ +#ifndef slic3r_Format_3mf_hpp_ +#define slic3r_Format_3mf_hpp_ + +namespace Slic3r { + + class Model; + class Print; + class PresetBundle; + + // Load the content of a 3mf file into the given model and preset bundle. + extern bool load_3mf(const char* path, PresetBundle* bundle, Model* model); + + // Save the given model and the config data contained in the given Print into a 3mf file. + // The model could be modified during the export process if meshes are not repaired or have no shared vertices + extern bool store_3mf(const char* path, Model* model, Print* print); + +}; // namespace Slic3r + +#endif /* slic3r_Format_3mf_hpp_ */ diff --git a/xs/src/libslic3r/Format/AMF.cpp b/xs/src/libslic3r/Format/AMF.cpp index b8abf038b..a52dd532a 100644 --- a/xs/src/libslic3r/Format/AMF.cpp +++ b/xs/src/libslic3r/Format/AMF.cpp @@ -7,8 +7,14 @@ #include "../libslic3r.h" #include "../Model.hpp" +#include "../GCode.hpp" +#include "../slic3r/GUI/PresetBundle.hpp" #include "AMF.hpp" +#include +#include +#include + #if 0 // Enable debugging and assert in this file. #define DEBUG @@ -18,18 +24,22 @@ #include +const char* SLIC3R_CONFIG_TYPE = "slic3rpe_config"; + namespace Slic3r { struct AMFParserContext { - AMFParserContext(XML_Parser parser, Model *model) : + AMFParserContext(XML_Parser parser, const std::string& archive_filename, PresetBundle* preset_bundle, Model *model) : m_parser(parser), m_model(*model), m_object(nullptr), m_volume(nullptr), m_material(nullptr), - m_instance(nullptr) + m_instance(nullptr), + m_preset_bundle(preset_bundle), + m_archive_filename(archive_filename) { m_path.reserve(12); } @@ -149,6 +159,10 @@ struct AMFParserContext Instance *m_instance; // Generic string buffer for vertices, face indices, metadata etc. std::string m_value[3]; + // Pointer to preset bundle to update if config data are stored inside the amf file + PresetBundle* m_preset_bundle; + // Fullpath name of the amf file + std::string m_archive_filename; private: AMFParserContext& operator=(AMFParserContext&); @@ -403,7 +417,10 @@ void AMFParserContext::endElement(const char * /* name */) break; case NODE_TYPE_METADATA: - if (strncmp(m_value[0].c_str(), "slic3r.", 7) == 0) { + if ((m_preset_bundle != nullptr) && strncmp(m_value[0].c_str(), SLIC3R_CONFIG_TYPE, strlen(SLIC3R_CONFIG_TYPE)) == 0) { + m_preset_bundle->load_config_string(m_value[1].c_str(), m_archive_filename.c_str()); + } + else if (strncmp(m_value[0].c_str(), "slic3r.", 7) == 0) { const char *opt_key = m_value[0].c_str() + 7; if (print_config_def.options.find(opt_key) != print_config_def.options.end()) { DynamicPrintConfig *config = nullptr; @@ -474,10 +491,13 @@ void AMFParserContext::endDocument() } // Load an AMF file into a provided model. -bool load_amf(const char *path, Model *model) +bool load_amf_file(const char *path, PresetBundle* bundle, Model *model) { + if ((path == nullptr) || (model == nullptr)) + return false; + XML_Parser parser = XML_ParserCreate(nullptr); // encoding - if (! parser) { + if (!parser) { printf("Couldn't allocate memory for parser\n"); return false; } @@ -488,7 +508,7 @@ bool load_amf(const char *path, Model *model) return false; } - AMFParserContext ctx(parser, model); + AMFParserContext ctx(parser, path, bundle, model); XML_SetUserData(parser, (void*)&ctx); XML_SetElementHandler(parser, AMFParserContext::startElement, AMFParserContext::endElement); XML_SetCharacterDataHandler(parser, AMFParserContext::characters); @@ -519,49 +539,163 @@ bool load_amf(const char *path, Model *model) if (result) ctx.endDocument(); + return result; } -bool store_amf(const char *path, Model *model) +// Load an AMF archive into a provided model. +bool load_amf_archive(const char *path, PresetBundle* bundle, Model *model) { - FILE *file = boost::nowide::fopen(path, "wb"); - if (file == nullptr) + if ((path == nullptr) || (model == nullptr)) return false; - fprintf(file, "\n"); - fprintf(file, "\n"); - fprintf(file, "Slic3r %s\n", SLIC3R_VERSION); + mz_zip_archive archive; + mz_zip_zero_struct(&archive); + + mz_bool res = mz_zip_reader_init_file(&archive, path, 0); + if (res == 0) + { + printf("Unable to init zip reader\n"); + return false; + } + + mz_uint num_entries = mz_zip_reader_get_num_files(&archive); + if (num_entries != 1) + { + printf("Found invalid number of entries\n"); + mz_zip_reader_end(&archive); + return false; + } + + mz_zip_archive_file_stat stat; + res = mz_zip_reader_file_stat(&archive, 0, &stat); + if (res == 0) + { + printf("Unable to extract entry statistics\n"); + mz_zip_reader_end(&archive); + return false; + } + + std::string internal_amf_filename = boost::ireplace_last_copy(boost::filesystem::path(path).filename().string(), ".zip.amf", ".amf"); + if (internal_amf_filename != stat.m_filename) + { + printf("Found invalid internal filename\n"); + mz_zip_reader_end(&archive); + return false; + } + + if (stat.m_uncomp_size == 0) + { + printf("Found invalid size\n"); + mz_zip_reader_end(&archive); + return false; + } + + XML_Parser parser = XML_ParserCreate(nullptr); // encoding + if (!parser) { + printf("Couldn't allocate memory for parser\n"); + mz_zip_reader_end(&archive); + return false; + } + + AMFParserContext ctx(parser, path, bundle, model); + XML_SetUserData(parser, (void*)&ctx); + XML_SetElementHandler(parser, AMFParserContext::startElement, AMFParserContext::endElement); + XML_SetCharacterDataHandler(parser, AMFParserContext::characters); + + void* parser_buffer = XML_GetBuffer(parser, (int)stat.m_uncomp_size); + if (parser_buffer == nullptr) + { + printf("Unable to create buffer\n"); + mz_zip_reader_end(&archive); + return false; + } + + res = mz_zip_reader_extract_file_to_mem(&archive, stat.m_filename, parser_buffer, (size_t)stat.m_uncomp_size, 0); + if (res == 0) + { + printf("Error while reading model data to buffer\n"); + mz_zip_reader_end(&archive); + return false; + } + + if (!XML_ParseBuffer(parser, (int)stat.m_uncomp_size, 1)) + { + printf("Error (%s) while parsing xml file at line %d\n", XML_ErrorString(XML_GetErrorCode(parser)), XML_GetCurrentLineNumber(parser)); + mz_zip_reader_end(&archive); + return false; + } + + ctx.endDocument(); + + mz_zip_reader_end(&archive); + return true; +} + +// Load an AMF file into a provided model. +// If bundle is not a null pointer, updates it if the amf file/archive contains config data +bool load_amf(const char *path, PresetBundle* bundle, Model *model) +{ + if (boost::iends_with(path, ".zip.amf")) + return load_amf_archive(path, bundle, model); + else if (boost::iends_with(path, ".amf") || boost::iends_with(path, ".amf.xml")) + return load_amf_file(path, bundle, model); + else + return false; +} + +bool store_amf(const char *path, Model *model, Print* print) +{ + if ((path == nullptr) || (model == nullptr) || (print == nullptr)) + return false; + + mz_zip_archive archive; + mz_zip_zero_struct(&archive); + + mz_bool res = mz_zip_writer_init_file(&archive, path, 0); + if (res == 0) + return false; + + std::stringstream stream; + stream << "\n"; + stream << "\n"; + stream << "Slic3r " << SLIC3R_VERSION << "\n"; + + std::string config = "\n"; + GCode::append_full_config(*print, config); + stream << "" << config << "\n"; + for (const auto &material : model->materials) { if (material.first.empty()) continue; // note that material-id must never be 0 since it's reserved by the AMF spec - fprintf(file, " \n", material.first.c_str()); + stream << " \n"; for (const auto &attr : material.second->attributes) - fprintf(file, " %s\n", attr.first.c_str(), attr.second.c_str()); + stream << " " << attr.second << "\n"; for (const std::string &key : material.second->config.keys()) - fprintf(file, " %s\n", key.c_str(), material.second->config.serialize(key).c_str()); - fprintf(file, " \n"); + stream << " " << material.second->config.serialize(key) << "\n"; + stream << " \n"; } std::string instances; for (size_t object_id = 0; object_id < model->objects.size(); ++ object_id) { ModelObject *object = model->objects[object_id]; - fprintf(file, " \n", object_id); + stream << " \n"; for (const std::string &key : object->config.keys()) - fprintf(file, " %s\n", key.c_str(), object->config.serialize(key).c_str()); - if (! object->name.empty()) - fprintf(file, " %s\n", object->name.c_str()); + stream << " " << object->config.serialize(key) << "\n"; + if (!object->name.empty()) + stream << " " << object->name << "\n"; std::vector layer_height_profile = object->layer_height_profile_valid ? object->layer_height_profile : std::vector(); if (layer_height_profile.size() >= 4 && (layer_height_profile.size() % 2) == 0) { // Store the layer height profile as a single semicolon separated list. - fprintf(file, " "); - fprintf(file, "%f", layer_height_profile.front()); - for (size_t i = 1; i < layer_height_profile.size(); ++ i) - fprintf(file, ";%f", layer_height_profile[i]); - fprintf(file, "\n \n"); + stream << " "; + stream << layer_height_profile.front(); + for (size_t i = 1; i < layer_height_profile.size(); ++i) + stream << ";" << layer_height_profile[i]; + stream << "\n \n"; } //FIXME Store the layer height ranges (ModelObject::layer_height_ranges) - fprintf(file, " \n"); - fprintf(file, " \n"); + stream << " \n"; + stream << " \n"; std::vector vertices_offsets; int num_vertices = 0; for (ModelVolume *volume : object->volumes) { @@ -572,41 +706,41 @@ bool store_amf(const char *path, Model *model) if (stl.v_shared == nullptr) stl_generate_shared_vertices(&stl); for (size_t i = 0; i < stl.stats.shared_vertices; ++ i) { - fprintf(file, " \n"); - fprintf(file, " \n"); - fprintf(file, " %f\n", stl.v_shared[i].x); - fprintf(file, " %f\n", stl.v_shared[i].y); - fprintf(file, " %f\n", stl.v_shared[i].z); - fprintf(file, " \n"); - fprintf(file, " \n"); + stream << " \n"; + stream << " \n"; + stream << " " << stl.v_shared[i].x << "\n"; + stream << " " << stl.v_shared[i].y << "\n"; + stream << " " << stl.v_shared[i].z << "\n"; + stream << " \n"; + stream << " \n"; } num_vertices += stl.stats.shared_vertices; } - fprintf(file, " \n"); - for (size_t i_volume = 0; i_volume < object->volumes.size(); ++ i_volume) { + stream << " \n"; + for (size_t i_volume = 0; i_volume < object->volumes.size(); ++i_volume) { ModelVolume *volume = object->volumes[i_volume]; int vertices_offset = vertices_offsets[i_volume]; if (volume->material_id().empty()) - fprintf(file, " \n"); + stream << " \n"; else - fprintf(file, " \n", volume->material_id().c_str()); + stream << " material_id() << "\">\n"; for (const std::string &key : volume->config.keys()) - fprintf(file, " %s\n", key.c_str(), volume->config.serialize(key).c_str()); - if (! volume->name.empty()) - fprintf(file, " %s\n", volume->name.c_str()); + stream << " " << volume->config.serialize(key) << "\n"; + if (!volume->name.empty()) + stream << " " << volume->name << "\n"; if (volume->modifier) - fprintf(file, " 1\n"); - for (int i = 0; i < volume->mesh.stl.stats.number_of_facets; ++ i) { - fprintf(file, " \n"); - for (int j = 0; j < 3; ++ j) - fprintf(file, " %d\n", j+1, volume->mesh.stl.v_indices[i].vertex[j] + vertices_offset, j+1); - fprintf(file, " \n"); + stream << " 1\n"; + for (int i = 0; i < volume->mesh.stl.stats.number_of_facets; ++i) { + stream << " \n"; + for (int j = 0; j < 3; ++j) + stream << " " << volume->mesh.stl.v_indices[i].vertex[j] + vertices_offset << "\n"; + stream << " \n"; } - fprintf(file, " \n"); + stream << " \n"; } - fprintf(file, " \n"); - fprintf(file, " \n"); - if (! object->instances.empty()) { + stream << " \n"; + stream << " \n"; + if (!object->instances.empty()) { for (ModelInstance *instance : object->instances) { char buf[512]; sprintf(buf, @@ -627,12 +761,31 @@ bool store_amf(const char *path, Model *model) } } if (! instances.empty()) { - fprintf(file, " \n"); - fwrite(instances.data(), instances.size(), 1, file); - fprintf(file, " \n"); + stream << " \n"; + stream << instances; + stream << " \n"; } - fprintf(file, "\n"); - fclose(file); + stream << "\n"; + + std::string internal_amf_filename = boost::ireplace_last_copy(boost::filesystem::path(path).filename().string(), ".zip.amf", ".amf"); + std::string out = stream.str(); + + if (!mz_zip_writer_add_mem(&archive, internal_amf_filename.c_str(), (const void*)out.data(), out.length(), MZ_DEFAULT_COMPRESSION)) + { + mz_zip_writer_end(&archive); + boost::filesystem::remove(path); + return false; + } + + if (!mz_zip_writer_finalize_archive(&archive)) + { + mz_zip_writer_end(&archive); + boost::filesystem::remove(path); + return false; + } + + mz_zip_writer_end(&archive); + return true; } diff --git a/xs/src/libslic3r/Format/AMF.hpp b/xs/src/libslic3r/Format/AMF.hpp index e58ce2f0f..027ebdab3 100644 --- a/xs/src/libslic3r/Format/AMF.hpp +++ b/xs/src/libslic3r/Format/AMF.hpp @@ -4,11 +4,15 @@ namespace Slic3r { class Model; +class Print; +class PresetBundle; -// Load an AMF file into a provided model. -extern bool load_amf(const char *path, Model *model); +// Load the content of an amf file into the given model and preset bundle. +extern bool load_amf(const char *path, PresetBundle* bundle, Model *model); -extern bool store_amf(const char *path, Model *model); +// Save the given model and the config data contained in the given Print into an amf file. +// The model could be modified during the export process if meshes are not repaired or have no shared vertices +extern bool store_amf(const char *path, Model *model, Print* print); }; // namespace Slic3r diff --git a/xs/src/libslic3r/GCode.cpp b/xs/src/libslic3r/GCode.cpp index 39f1a4102..080b4769d 100644 --- a/xs/src/libslic3r/GCode.cpp +++ b/xs/src/libslic3r/GCode.cpp @@ -776,7 +776,7 @@ void GCode::_do_export(Print &print, FILE *file, GCodePreviewData *preview_data) _writeln(file, this->placeholder_parser_process("end_filament_gcode", print.config.end_filament_gcode.get_at(m_writer.extruder()->id()), m_writer.extruder()->id())); } else { for (const std::string &end_gcode : print.config.end_filament_gcode.values) - _writeln(file, this->placeholder_parser_process("end_gcode", end_gcode, (unsigned int)(&end_gcode - &print.config.end_filament_gcode.values.front()))); + _writeln(file, this->placeholder_parser_process("end_filament_gcode", end_gcode, (unsigned int)(&end_gcode - &print.config.end_filament_gcode.values.front()))); } _writeln(file, this->placeholder_parser_process("end_gcode", print.config.end_gcode, m_writer.extruder()->id())); _write(file, m_writer.update_progress(m_layer_count, m_layer_count, true)); // 100% @@ -816,13 +816,10 @@ void GCode::_do_export(Print &print, FILE *file, GCodePreviewData *preview_data) // Append full config. _write(file, "\n"); { - StaticPrintConfig *configs[] = { &print.config, &print.default_object_config, &print.default_region_config }; - for (size_t i = 0; i < sizeof(configs) / sizeof(configs[0]); ++ i) { - StaticPrintConfig *cfg = configs[i]; - for (const std::string &key : cfg->keys()) - if (key != "compatible_printers") - _write_format(file, "; %s = %s\n", key.c_str(), cfg->serialize(key).c_str()); - } + std::string full_config = ""; + append_full_config(print, full_config); + if (!full_config.empty()) + _write(file, full_config); } // starts analizer calculations @@ -1385,6 +1382,24 @@ void GCode::apply_print_config(const PrintConfig &print_config) m_config.apply(print_config); } +void GCode::append_full_config(const Print& print, std::string& str) +{ + char buff[1024]; + + const StaticPrintConfig *configs[] = { &print.config, &print.default_object_config, &print.default_region_config }; + for (size_t i = 0; i < sizeof(configs) / sizeof(configs[0]); ++i) { + const StaticPrintConfig *cfg = configs[i]; + for (const std::string &key : cfg->keys()) + { + if (key != "compatible_printers") + { + sprintf(buff, "; %s = %s\n", key.c_str(), cfg->serialize(key).c_str()); + str += buff; + } + } + } +} + void GCode::set_extruders(const std::vector &extruder_ids) { m_writer.set_extruders(extruder_ids); diff --git a/xs/src/libslic3r/GCode.hpp b/xs/src/libslic3r/GCode.hpp index f35f2d5e9..968cd14de 100644 --- a/xs/src/libslic3r/GCode.hpp +++ b/xs/src/libslic3r/GCode.hpp @@ -160,6 +160,9 @@ public: void set_layer_count(unsigned int value) { m_layer_count = value; } void apply_print_config(const PrintConfig &print_config); + // append full config to the given string + static void append_full_config(const Print& print, std::string& str); + protected: void _do_export(Print &print, FILE *file, GCodePreviewData *preview_data); diff --git a/xs/src/libslic3r/Model.cpp b/xs/src/libslic3r/Model.cpp index 88a0b8279..f65707ccb 100644 --- a/xs/src/libslic3r/Model.cpp +++ b/xs/src/libslic3r/Model.cpp @@ -5,6 +5,7 @@ #include "Format/OBJ.hpp" #include "Format/PRUS.hpp" #include "Format/STL.hpp" +#include "Format/3mf.hpp" #include @@ -46,16 +47,16 @@ Model Model::read_from_file(const std::string &input_file, bool add_default_inst result = load_stl(input_file.c_str(), &model); else if (boost::algorithm::iends_with(input_file, ".obj")) result = load_obj(input_file.c_str(), &model); - else if (boost::algorithm::iends_with(input_file, ".amf") || - boost::algorithm::iends_with(input_file, ".amf.xml")) - result = load_amf(input_file.c_str(), &model); + else if (!boost::algorithm::iends_with(input_file, ".zip.amf") && (boost::algorithm::iends_with(input_file, ".amf") || + boost::algorithm::iends_with(input_file, ".amf.xml"))) + result = load_amf(input_file.c_str(), nullptr, &model); #ifdef SLIC3R_PRUS else if (boost::algorithm::iends_with(input_file, ".prusa")) result = load_prus(input_file.c_str(), &model); #endif /* SLIC3R_PRUS */ else throw std::runtime_error("Unknown file format. Input file must have .stl, .obj, .amf(.xml) or .prusa extension."); - + if (! result) throw std::runtime_error("Loading of a model file failed."); @@ -71,6 +72,33 @@ Model Model::read_from_file(const std::string &input_file, bool add_default_inst return model; } +Model Model::read_from_archive(const std::string &input_file, PresetBundle* bundle, bool add_default_instances) +{ + Model model; + + bool result = false; + if (boost::algorithm::iends_with(input_file, ".3mf")) + result = load_3mf(input_file.c_str(), bundle, &model); + else if (boost::algorithm::iends_with(input_file, ".zip.amf")) + result = load_amf(input_file.c_str(), bundle, &model); + else + throw std::runtime_error("Unknown file format. Input file must have .3mf or .zip.amf extension."); + + if (!result) + throw std::runtime_error("Loading of a model file failed."); + + if (model.objects.empty()) + throw std::runtime_error("The supplied file couldn't be read because it's empty"); + + for (ModelObject *o : model.objects) + o->input_file = input_file; + + if (add_default_instances) + model.add_default_instances(); + + return model; +} + ModelObject* Model::add_object() { this->objects.emplace_back(new ModelObject(this)); @@ -115,6 +143,23 @@ void Model::delete_object(size_t idx) this->objects.erase(i); } +void Model::delete_object(ModelObject* object) +{ + if (object == nullptr) + return; + + for (ModelObjectPtrs::iterator it = objects.begin(); it != objects.end(); ++it) + { + ModelObject* obj = *it; + if (obj == object) + { + delete obj; + objects.erase(it); + return; + } + } +} + void Model::clear_objects() { for (ModelObject *o : this->objects) @@ -607,6 +652,20 @@ void ModelObject::rotate(float angle, const Axis &axis) this->invalidate_bounding_box(); } +void ModelObject::transform(const float* matrix3x4) +{ + if (matrix3x4 == nullptr) + return; + + for (ModelVolume* v : volumes) + { + v->mesh.transform(matrix3x4); + } + + origin_translation = Pointf3(0.0f, 0.0f, 0.0f); + invalidate_bounding_box(); +} + void ModelObject::mirror(const Axis &axis) { for (ModelVolume *v : this->volumes) diff --git a/xs/src/libslic3r/Model.hpp b/xs/src/libslic3r/Model.hpp index 636dfa1f4..cf9bfd85a 100644 --- a/xs/src/libslic3r/Model.hpp +++ b/xs/src/libslic3r/Model.hpp @@ -19,6 +19,7 @@ class ModelInstance; class ModelMaterial; class ModelObject; class ModelVolume; +class PresetBundle; typedef std::string t_model_material_id; typedef std::string t_model_material_attribute; @@ -119,6 +120,7 @@ public: void translate(coordf_t x, coordf_t y, coordf_t z); void scale(const Pointf3 &versor); void rotate(float angle, const Axis &axis); + void transform(const float* matrix3x4); void mirror(const Axis &axis); size_t materials_count() const; size_t facets_count() const; @@ -238,12 +240,14 @@ public: ~Model() { this->clear_objects(); this->clear_materials(); } static Model read_from_file(const std::string &input_file, bool add_default_instances = true); + static Model read_from_archive(const std::string &input_file, PresetBundle* bundle, bool add_default_instances = true); ModelObject* add_object(); ModelObject* add_object(const char *name, const char *path, const TriangleMesh &mesh); ModelObject* add_object(const char *name, const char *path, TriangleMesh &&mesh); ModelObject* add_object(const ModelObject &other, bool copy_volumes = true); void delete_object(size_t idx); + void delete_object(ModelObject* object); void clear_objects(); ModelMaterial* add_material(t_model_material_id material_id); diff --git a/xs/src/libslic3r/Polygon.hpp b/xs/src/libslic3r/Polygon.hpp index f36abc185..1a02d78b7 100644 --- a/xs/src/libslic3r/Polygon.hpp +++ b/xs/src/libslic3r/Polygon.hpp @@ -24,6 +24,12 @@ public: explicit Polygon(const Points &points): MultiPoint(points) {} Polygon(const Polygon &other) : MultiPoint(other.points) {} Polygon(Polygon &&other) : MultiPoint(std::move(other.points)) {} + static Polygon new_scale(std::vector points) { + Points int_points; + for (auto pt : points) + int_points.push_back(Point::new_scale(pt.x, pt.y)); + return Polygon(int_points); + } Polygon& operator=(const Polygon &other) { points = other.points; return *this; } Polygon& operator=(Polygon &&other) { points = std::move(other.points); return *this; } diff --git a/xs/src/libslic3r/Polyline.hpp b/xs/src/libslic3r/Polyline.hpp index a1d777692..b64743d84 100644 --- a/xs/src/libslic3r/Polyline.hpp +++ b/xs/src/libslic3r/Polyline.hpp @@ -21,6 +21,14 @@ public: Polyline(Polyline &&other) : MultiPoint(std::move(other.points)) {} Polyline& operator=(const Polyline &other) { points = other.points; return *this; } Polyline& operator=(Polyline &&other) { points = std::move(other.points); return *this; } + static Polyline new_scale(std::vector points) { + Polyline pl; + Points int_points; + for (auto pt : points) + int_points.push_back(Point::new_scale(pt.x, pt.y)); + pl.append(int_points); + return pl; + } void append(const Point &point) { this->points.push_back(point); } void append(const Points &src) { this->append(src.begin(), src.end()); } diff --git a/xs/src/libslic3r/PrintConfig.cpp b/xs/src/libslic3r/PrintConfig.cpp index 5bbf20c4c..d88bb2162 100644 --- a/xs/src/libslic3r/PrintConfig.cpp +++ b/xs/src/libslic3r/PrintConfig.cpp @@ -9,6 +9,10 @@ namespace Slic3r { +//! macro used to mark string used at localization, +//! return same string +#define _L(s) s + PrintConfigDef::PrintConfigDef() { t_optiondef_map &Options = this->options; @@ -17,34 +21,39 @@ PrintConfigDef::PrintConfigDef() // Maximum extruder temperature, bumped to 1500 to support printing of glass. const int max_temp = 1500; + + //! On purpose of localization there is that changes at text of tooltip and sidetext: + //! - ° -> \u00B0 + //! - ² -> \u00B2 + //! - ³ -> \u00B3 def = this->add("avoid_crossing_perimeters", coBool); - def->label = "Avoid crossing perimeters"; - def->tooltip = "Optimize travel moves in order to minimize the crossing of perimeters. " + def->label = _L("Avoid crossing perimeters"); + def->tooltip = _L("Optimize travel moves in order to minimize the crossing of perimeters. " "This is mostly useful with Bowden extruders which suffer from oozing. " - "This feature slows down both the print and the G-code generation."; + "This feature slows down both the print and the G-code generation."); def->cli = "avoid-crossing-perimeters!"; def->default_value = new ConfigOptionBool(false); def = this->add("bed_shape", coPoints); - def->label = "Bed shape"; + def->label = _L("Bed shape"); def->default_value = new ConfigOptionPoints { Pointf(0,0), Pointf(200,0), Pointf(200,200), Pointf(0,200) }; def = this->add("bed_temperature", coInts); - def->label = "Other layers"; - def->tooltip = "Bed temperature for layers after the first one. " - "Set this to zero to disable bed temperature control commands in the output."; + def->label = _L("Other layers"); + def->tooltip = _L("Bed temperature for layers after the first one. " + "Set this to zero to disable bed temperature control commands in the output."); def->cli = "bed-temperature=i@"; - def->full_label = "Bed temperature"; + def->full_label = _L("Bed temperature"); def->min = 0; def->max = 300; def->default_value = new ConfigOptionInts { 0 }; def = this->add("before_layer_gcode", coString); - def->label = "Before layer change G-code"; - def->tooltip = "This custom code is inserted at every layer change, right before the Z move. " + def->label = _L("Before layer change G-code"); + def->tooltip = _L("This custom code is inserted at every layer change, right before the Z move. " "Note that you can use placeholder variables for all Slic3r settings as well " - "as [layer_num] and [layer_z]."; + "as [layer_num] and [layer_z]."); def->cli = "before-layer-gcode=s"; def->multiline = true; def->full_width = true; @@ -52,8 +61,8 @@ PrintConfigDef::PrintConfigDef() def->default_value = new ConfigOptionString(""); def = this->add("between_objects_gcode", coString); - def->label = "Between objects G-code"; - def->tooltip = "This code is inserted between objects when using sequential printing. By default extruder and bed temperature are reset using non-wait command; however if M104, M109, M140 or M190 are detected in this custom code, Slic3r will not add temperature commands. Note that you can use placeholder variables for all Slic3r settings, so you can put a \"M109 S[first_layer_temperature]\" command wherever you want."; + def->label = _L("Between objects G-code"); + def->tooltip = _L("This code is inserted between objects when using sequential printing. By default extruder and bed temperature are reset using non-wait command; however if M104, M109, M140 or M190 are detected in this custom code, Slic3r will not add temperature commands. Note that you can use placeholder variables for all Slic3r settings, so you can put a \"M109 S[first_layer_temperature]\" command wherever you want."); def->cli = "between-objects-gcode=s"; def->multiline = true; def->full_width = true; @@ -61,158 +70,158 @@ PrintConfigDef::PrintConfigDef() def->default_value = new ConfigOptionString(""); def = this->add("bottom_solid_layers", coInt); - def->label = "Bottom"; - def->category = "Layers and Perimeters"; - def->tooltip = "Number of solid layers to generate on bottom surfaces."; + def->label = _L("Bottom"); + def->category = _L("Layers and Perimeters"); + def->tooltip = _L("Number of solid layers to generate on bottom surfaces."); def->cli = "bottom-solid-layers=i"; - def->full_label = "Bottom solid layers"; + def->full_label = _L("Bottom solid layers"); def->min = 0; def->default_value = new ConfigOptionInt(3); def = this->add("bridge_acceleration", coFloat); - def->label = "Bridge"; - def->tooltip = "This is the acceleration your printer will use for bridges. " - "Set zero to disable acceleration control for bridges."; - def->sidetext = "mm/s²"; + def->label = _L("Bridge"); + def->tooltip = _L("This is the acceleration your printer will use for bridges. " + "Set zero to disable acceleration control for bridges."); + def->sidetext = _L("mm/s\u00B2"); def->cli = "bridge-acceleration=f"; def->min = 0; def->default_value = new ConfigOptionFloat(0); def = this->add("bridge_angle", coFloat); - def->label = "Bridging angle"; - def->category = "Infill"; - def->tooltip = "Bridging angle override. If left to zero, the bridging angle will be calculated " + def->label = _L("Bridging angle"); + def->category = _L("Infill"); + def->tooltip = _L("Bridging angle override. If left to zero, the bridging angle will be calculated " "automatically. Otherwise the provided angle will be used for all bridges. " - "Use 180° for zero angle."; - def->sidetext = "°"; + "Use 180\u00B0 for zero angle."); + def->sidetext = _L("\u00B0"); def->cli = "bridge-angle=f"; def->min = 0; def->default_value = new ConfigOptionFloat(0.); def = this->add("bridge_fan_speed", coInts); - def->label = "Bridges fan speed"; - def->tooltip = "This fan speed is enforced during all bridges and overhangs."; - def->sidetext = "%"; + def->label = _L("Bridges fan speed"); + def->tooltip = _L("This fan speed is enforced during all bridges and overhangs."); + def->sidetext = _L("%"); def->cli = "bridge-fan-speed=i@"; def->min = 0; def->max = 100; def->default_value = new ConfigOptionInts { 100 }; def = this->add("bridge_flow_ratio", coFloat); - def->label = "Bridge flow ratio"; - def->category = "Advanced"; - def->tooltip = "This factor affects the amount of plastic for bridging. " + def->label = _L("Bridge flow ratio"); + def->category = _L("Advanced"); + def->tooltip = _L("This factor affects the amount of plastic for bridging. " "You can decrease it slightly to pull the extrudates and prevent sagging, " "although default settings are usually good and you should experiment " - "with cooling (use a fan) before tweaking this."; + "with cooling (use a fan) before tweaking this."); def->cli = "bridge-flow-ratio=f"; def->min = 0; def->default_value = new ConfigOptionFloat(1); def = this->add("bridge_speed", coFloat); - def->label = "Bridges"; - def->category = "Speed"; - def->tooltip = "Speed for printing bridges."; - def->sidetext = "mm/s"; + def->label = _L("Bridges"); + def->category = _L("Speed"); + def->tooltip = _L("Speed for printing bridges."); + def->sidetext = _L("mm/s"); def->cli = "bridge-speed=f"; def->aliases.push_back("bridge_feed_rate"); def->min = 0; def->default_value = new ConfigOptionFloat(60); def = this->add("brim_width", coFloat); - def->label = "Brim width"; - def->tooltip = "Horizontal width of the brim that will be printed around each object on the first layer."; - def->sidetext = "mm"; + def->label = _L("Brim width"); + def->tooltip = _L("Horizontal width of the brim that will be printed around each object on the first layer."); + def->sidetext = _L("mm"); def->cli = "brim-width=f"; def->min = 0; def->default_value = new ConfigOptionFloat(0); def = this->add("clip_multipart_objects", coBool); - def->label = "Clip multi-part objects"; - def->tooltip = "When printing multi-material objects, this settings will make slic3r " + def->label = _L("Clip multi-part objects"); + def->tooltip = _L("When printing multi-material objects, this settings will make slic3r " "to clip the overlapping object parts one by the other " - "(2nd part will be clipped by the 1st, 3rd part will be clipped by the 1st and 2nd etc)."; + "(2nd part will be clipped by the 1st, 3rd part will be clipped by the 1st and 2nd etc)."); def->cli = "clip-multipart-objects!"; def->default_value = new ConfigOptionBool(false); def = this->add("compatible_printers", coStrings); - def->label = "Compatible printers"; + def->label = _L("Compatible printers"); def->default_value = new ConfigOptionStrings(); def = this->add("compatible_printers_condition", coString); - def->label = "Compatible printers condition"; - def->tooltip = "A boolean expression using the configuration values of an active printer profile. " + def->label = _L("Compatible printers condition"); + def->tooltip = _L("A boolean expression using the configuration values of an active printer profile. " "If this expression evaluates to true, this profile is considered compatible " - "with the active printer profile."; + "with the active printer profile."); def->default_value = new ConfigOptionString(); def = this->add("complete_objects", coBool); - def->label = "Complete individual objects"; - def->tooltip = "When printing multiple objects or copies, this feature will complete " + def->label = _L("Complete individual objects"); + def->tooltip = _L("When printing multiple objects or copies, this feature will complete " "each object before moving onto next one (and starting it from its bottom layer). " "This feature is useful to avoid the risk of ruined prints. " - "Slic3r should warn and prevent you from extruder collisions, but beware."; + "Slic3r should warn and prevent you from extruder collisions, but beware."); def->cli = "complete-objects!"; def->default_value = new ConfigOptionBool(false); def = this->add("cooling", coBools); - def->label = "Enable auto cooling"; - def->tooltip = "This flag enables the automatic cooling logic that adjusts print speed " - "and fan speed according to layer printing time."; + def->label = _L("Enable auto cooling"); + def->tooltip = _L("This flag enables the automatic cooling logic that adjusts print speed " + "and fan speed according to layer printing time."); def->cli = "cooling!"; def->default_value = new ConfigOptionBools { true }; def = this->add("default_acceleration", coFloat); - def->label = "Default"; - def->tooltip = "This is the acceleration your printer will be reset to after " + def->label = _L("Default"); + def->tooltip = _L("This is the acceleration your printer will be reset to after " "the role-specific acceleration values are used (perimeter/infill). " - "Set zero to prevent resetting acceleration at all."; - def->sidetext = "mm/s²"; + "Set zero to prevent resetting acceleration at all."); + def->sidetext = _L("mm/s\u00B2"); def->cli = "default-acceleration=f"; def->min = 0; def->default_value = new ConfigOptionFloat(0); def = this->add("disable_fan_first_layers", coInts); - def->label = "Disable fan for the first"; - def->tooltip = "You can set this to a positive value to disable fan at all " - "during the first layers, so that it does not make adhesion worse."; - def->sidetext = "layers"; + def->label = _L("Disable fan for the first"); + def->tooltip = _L("You can set this to a positive value to disable fan at all " + "during the first layers, so that it does not make adhesion worse."); + def->sidetext = _L("layers"); def->cli = "disable-fan-first-layers=i@"; def->min = 0; def->max = 1000; def->default_value = new ConfigOptionInts { 3 }; def = this->add("dont_support_bridges", coBool); - def->label = "Don't support bridges"; - def->category = "Support material"; - def->tooltip = "Experimental option for preventing support material from being generated " - "under bridged areas."; + def->label = _L("Don't support bridges"); + def->category = _L("Support material"); + def->tooltip = _L("Experimental option for preventing support material from being generated " + "under bridged areas."); def->cli = "dont-support-bridges!"; def->default_value = new ConfigOptionBool(true); def = this->add("duplicate_distance", coFloat); - def->label = "Distance between copies"; - def->tooltip = "Distance used for the auto-arrange feature of the plater."; - def->sidetext = "mm"; + def->label = _L("Distance between copies"); + def->tooltip = _L("Distance used for the auto-arrange feature of the plater."); + def->sidetext = _L("mm"); def->cli = "duplicate-distance=f"; def->aliases.push_back("multiply_distance"); def->min = 0; def->default_value = new ConfigOptionFloat(6); def = this->add("elefant_foot_compensation", coFloat); - def->label = "Elephant foot compensation"; - def->category = "Advanced"; - def->tooltip = "The first layer will be shrunk in the XY plane by the configured value " - "to compensate for the 1st layer squish aka an Elephant Foot effect."; - def->sidetext = "mm"; + def->label = _L("Elephant foot compensation"); + def->category = _L("Advanced"); + def->tooltip = _L("The first layer will be shrunk in the XY plane by the configured value " + "to compensate for the 1st layer squish aka an Elephant Foot effect."); + def->sidetext = _L("mm"); def->cli = "elefant-foot-compensation=f"; def->min = 0; def->default_value = new ConfigOptionFloat(0); def = this->add("end_gcode", coString); - def->label = "End G-code"; - def->tooltip = "This end procedure is inserted at the end of the output file. " - "Note that you can use placeholder variables for all Slic3r settings."; + def->label = _L("End G-code"); + def->tooltip = _L("This end procedure is inserted at the end of the output file. " + "Note that you can use placeholder variables for all Slic3r settings."); def->cli = "end-gcode=s"; def->multiline = true; def->full_width = true; @@ -220,10 +229,10 @@ PrintConfigDef::PrintConfigDef() def->default_value = new ConfigOptionString("M104 S0 ; turn off temperature\nG28 X0 ; home X axis\nM84 ; disable motors\n"); def = this->add("end_filament_gcode", coStrings); - def->label = "End G-code"; - def->tooltip = "This end procedure is inserted at the end of the output file, before the printer end gcode. " + def->label = _L("End G-code"); + def->tooltip = _L("This end procedure is inserted at the end of the output file, before the printer end gcode. " "Note that you can use placeholder variables for all Slic3r settings. " - "If you have multiple extruders, the gcode is processed in extruder order."; + "If you have multiple extruders, the gcode is processed in extruder order."); def->cli = "end-filament-gcode=s@"; def->multiline = true; def->full_width = true; @@ -231,18 +240,18 @@ PrintConfigDef::PrintConfigDef() def->default_value = new ConfigOptionStrings { "; Filament-specific end gcode \n;END gcode for filament\n" }; def = this->add("ensure_vertical_shell_thickness", coBool); - def->label = "Ensure vertical shell thickness"; - def->category = "Layers and Perimeters"; - def->tooltip = "Add solid infill near sloping surfaces to guarantee the vertical shell thickness " - "(top+bottom solid layers)."; + def->label = _L("Ensure vertical shell thickness"); + def->category = _L("Layers and Perimeters"); + def->tooltip = _L("Add solid infill near sloping surfaces to guarantee the vertical shell thickness " + "(top+bottom solid layers)."); def->cli = "ensure-vertical-shell-thickness!"; def->default_value = new ConfigOptionBool(false); def = this->add("external_fill_pattern", coEnum); - def->label = "Top/bottom fill pattern"; - def->category = "Infill"; - def->tooltip = "Fill pattern for top/bottom infill. This only affects the external visible layer, " - "and not its adjacent solid shells."; + def->label = _L("Top/bottom fill pattern"); + def->category = _L("Infill"); + def->tooltip = _L("Fill pattern for top/bottom infill. This only affects the external visible layer, " + "and not its adjacent solid shells."); def->cli = "external-fill-pattern|solid-fill-pattern=s"; def->enum_keys_map = &ConfigOptionEnum::get_enum_values(); def->enum_values.push_back("rectilinear"); @@ -260,50 +269,50 @@ PrintConfigDef::PrintConfigDef() def->default_value = new ConfigOptionEnum(ipRectilinear); def = this->add("external_perimeter_extrusion_width", coFloatOrPercent); - def->label = "External perimeters"; - def->category = "Extrusion Width"; - def->tooltip = "Set this to a non-zero value to set a manual extrusion width for external perimeters. " + def->label = _L("External perimeters"); + def->category = _L("Extrusion Width"); + def->tooltip = _L("Set this to a non-zero value to set a manual extrusion width for external perimeters. " "If left zero, default extrusion width will be used if set, otherwise 1.125 x nozzle diameter will be used. " - "If expressed as percentage (for example 200%), it will be computed over layer height."; - def->sidetext = "mm or % (leave 0 for default)"; + "If expressed as percentage (for example 200%), it will be computed over layer height."); + def->sidetext = _L("mm or % (leave 0 for default)"); def->cli = "external-perimeter-extrusion-width=s"; def->default_value = new ConfigOptionFloatOrPercent(0, false); def = this->add("external_perimeter_speed", coFloatOrPercent); - def->label = "External perimeters"; - def->category = "Speed"; - def->tooltip = "This separate setting will affect the speed of external perimeters (the visible ones). " + def->label = _L("External perimeters"); + def->category = _L("Speed"); + def->tooltip = _L("This separate setting will affect the speed of external perimeters (the visible ones). " "If expressed as percentage (for example: 80%) it will be calculated " - "on the perimeters speed setting above. Set to zero for auto."; - def->sidetext = "mm/s or %"; + "on the perimeters speed setting above. Set to zero for auto."); + def->sidetext = _L("mm/s or %"); def->cli = "external-perimeter-speed=s"; def->ratio_over = "perimeter_speed"; def->min = 0; def->default_value = new ConfigOptionFloatOrPercent(50, true); def = this->add("external_perimeters_first", coBool); - def->label = "External perimeters first"; - def->category = "Layers and Perimeters"; - def->tooltip = "Print contour perimeters from the outermost one to the innermost one " - "instead of the default inverse order."; + def->label = _L("External perimeters first"); + def->category = _L("Layers and Perimeters"); + def->tooltip = _L("Print contour perimeters from the outermost one to the innermost one " + "instead of the default inverse order."); def->cli = "external-perimeters-first!"; def->default_value = new ConfigOptionBool(false); def = this->add("extra_perimeters", coBool); - def->label = "Extra perimeters if needed"; - def->category = "Layers and Perimeters"; - def->tooltip = "Add more perimeters when needed for avoiding gaps in sloping walls. " + def->label = _L("Extra perimeters if needed"); + def->category = _L("Layers and Perimeters"); + def->tooltip = _L("Add more perimeters when needed for avoiding gaps in sloping walls. " "Slic3r keeps adding perimeters, until more than 70% of the loop immediately above " - "is supported."; + "is supported."); def->cli = "extra-perimeters!"; def->default_value = new ConfigOptionBool(true); def = this->add("extruder", coInt); def->gui_type = "i_enum_open"; - def->label = "Extruder"; - def->category = "Extruders"; - def->tooltip = "The extruder to use (unless more specific extruder settings are specified). " - "This value overrides perimeter and infill extruders, but not the support extruders."; + def->label = _L("Extruder"); + def->category = _L("Extruders"); + def->tooltip = _L("The extruder to use (unless more specific extruder settings are specified). " + "This value overrides perimeter and infill extruders, but not the support extruders."); def->cli = "extruder=i"; def->min = 0; // 0 = inherit defaults def->enum_labels.push_back("default"); // override label for item 0 @@ -313,84 +322,84 @@ PrintConfigDef::PrintConfigDef() def->enum_labels.push_back("4"); def = this->add("extruder_clearance_height", coFloat); - def->label = "Height"; - def->tooltip = "Set this to the vertical distance between your nozzle tip and (usually) the X carriage rods. " + def->label = _L("Height"); + def->tooltip = _L("Set this to the vertical distance between your nozzle tip and (usually) the X carriage rods. " "In other words, this is the height of the clearance cylinder around your extruder, " "and it represents the maximum depth the extruder can peek before colliding with " - "other printed objects."; - def->sidetext = "mm"; + "other printed objects."); + def->sidetext = _L("mm"); def->cli = "extruder-clearance-height=f"; def->min = 0; def->default_value = new ConfigOptionFloat(20); def = this->add("extruder_clearance_radius", coFloat); - def->label = "Radius"; - def->tooltip = "Set this to the clearance radius around your extruder. " + def->label = _L("Radius"); + def->tooltip = _L("Set this to the clearance radius around your extruder. " "If the extruder is not centered, choose the largest value for safety. " "This setting is used to check for collisions and to display the graphical preview " - "in the plater."; - def->sidetext = "mm"; + "in the plater."); + def->sidetext = _L("mm"); def->cli = "extruder-clearance-radius=f"; def->min = 0; def->default_value = new ConfigOptionFloat(20); def = this->add("extruder_colour", coStrings); - def->label = "Extruder Color"; - def->tooltip = "This is only used in the Slic3r interface as a visual help."; + def->label = _L("Extruder Color"); + def->tooltip = _L("This is only used in the Slic3r interface as a visual help."); def->cli = "extruder-color=s@"; def->gui_type = "color"; // Empty string means no color assigned yet. def->default_value = new ConfigOptionStrings { "" }; def = this->add("extruder_offset", coPoints); - def->label = "Extruder offset"; - def->tooltip = "If your firmware doesn't handle the extruder displacement you need the G-code " + def->label = _L("Extruder offset"); + def->tooltip = _L("If your firmware doesn't handle the extruder displacement you need the G-code " "to take it into account. This option lets you specify the displacement of each extruder " "with respect to the first one. It expects positive coordinates (they will be subtracted " - "from the XY coordinate)."; - def->sidetext = "mm"; + "from the XY coordinate)."); + def->sidetext = _L("mm"); def->cli = "extruder-offset=s@"; def->default_value = new ConfigOptionPoints { Pointf(0,0) }; def = this->add("extrusion_axis", coString); - def->label = "Extrusion axis"; - def->tooltip = "Use this option to set the axis letter associated to your printer's extruder " - "(usually E but some printers use A)."; + def->label = _L("Extrusion axis"); + def->tooltip = _L("Use this option to set the axis letter associated to your printer's extruder " + "(usually E but some printers use A)."); def->cli = "extrusion-axis=s"; def->default_value = new ConfigOptionString("E"); def = this->add("extrusion_multiplier", coFloats); - def->label = "Extrusion multiplier"; - def->tooltip = "This factor changes the amount of flow proportionally. You may need to tweak " + def->label = _L("Extrusion multiplier"); + def->tooltip = _L("This factor changes the amount of flow proportionally. You may need to tweak " "this setting to get nice surface finish and correct single wall widths. " "Usual values are between 0.9 and 1.1. If you think you need to change this more, " - "check filament diameter and your firmware E steps."; + "check filament diameter and your firmware E steps."); def->cli = "extrusion-multiplier=f@"; def->default_value = new ConfigOptionFloats { 1. }; def = this->add("extrusion_width", coFloatOrPercent); - def->label = "Default extrusion width"; - def->category = "Extrusion Width"; - def->tooltip = "Set this to a non-zero value to allow a manual extrusion width. " + def->label = _L("Default extrusion width"); + def->category = _L("Extrusion Width"); + def->tooltip = _L("Set this to a non-zero value to allow a manual extrusion width. " "If left to zero, Slic3r derives extrusion widths from the nozzle diameter " "(see the tooltips for perimeter extrusion width, infill extrusion width etc). " - "If expressed as percentage (for example: 230%), it will be computed over layer height."; - def->sidetext = "mm or % (leave 0 for auto)"; + "If expressed as percentage (for example: 230%), it will be computed over layer height."); + def->sidetext = _L("mm or % (leave 0 for auto)"); def->cli = "extrusion-width=s"; def->default_value = new ConfigOptionFloatOrPercent(0, false); def = this->add("fan_always_on", coBools); - def->label = "Keep fan always on"; - def->tooltip = "If this is enabled, fan will never be disabled and will be kept running at least " - "at its minimum speed. Useful for PLA, harmful for ABS."; + def->label = _L("Keep fan always on"); + def->tooltip = _L("If this is enabled, fan will never be disabled and will be kept running at least " + "at its minimum speed. Useful for PLA, harmful for ABS."); def->cli = "fan-always-on!"; def->default_value = new ConfigOptionBools { false }; def = this->add("fan_below_layer_time", coInts); - def->label = "Enable fan if layer print time is below"; - def->tooltip = "If layer print time is estimated below this number of seconds, fan will be enabled " - "and its speed will be calculated by interpolating the minimum and maximum speeds."; - def->sidetext = "approximate seconds"; + def->label = _L("Enable fan if layer print time is below"); + def->tooltip = _L("If layer print time is estimated below this number of seconds, fan will be enabled " + "and its speed will be calculated by interpolating the minimum and maximum speeds."); + def->sidetext = _L("approximate seconds"); def->cli = "fan-below-layer-time=i@"; def->width = 60; def->min = 0; @@ -398,15 +407,15 @@ PrintConfigDef::PrintConfigDef() def->default_value = new ConfigOptionInts { 60 }; def = this->add("filament_colour", coStrings); - def->label = "Color"; - def->tooltip = "This is only used in the Slic3r interface as a visual help."; + def->label = _L("Color"); + def->tooltip = _L("This is only used in the Slic3r interface as a visual help."); def->cli = "filament-color=s@"; def->gui_type = "color"; def->default_value = new ConfigOptionStrings { "#29b2b2" }; def = this->add("filament_notes", coStrings); - def->label = "Filament notes"; - def->tooltip = "You can put your notes regarding the filament here."; + def->label = _L("Filament notes"); + def->tooltip = _L("You can put your notes regarding the filament here."); def->cli = "filament-notes=s@"; def->multiline = true; def->full_width = true; @@ -414,40 +423,40 @@ PrintConfigDef::PrintConfigDef() def->default_value = new ConfigOptionStrings { "" }; def = this->add("filament_max_volumetric_speed", coFloats); - def->label = "Max volumetric speed"; - def->tooltip = "Maximum volumetric speed allowed for this filament. Limits the maximum volumetric " + def->label = _L("Max volumetric speed"); + def->tooltip = _L("Maximum volumetric speed allowed for this filament. Limits the maximum volumetric " "speed of a print to the minimum of print and filament volumetric speed. " - "Set to zero for no limit."; - def->sidetext = "mm³/s"; + "Set to zero for no limit."); + def->sidetext = _L("mm\u00B3/s"); def->cli = "filament-max-volumetric-speed=f@"; def->min = 0; def->default_value = new ConfigOptionFloats { 0. }; def = this->add("filament_diameter", coFloats); - def->label = "Diameter"; - def->tooltip = "Enter your filament diameter here. Good precision is required, so use a caliper " - "and do multiple measurements along the filament, then compute the average."; - def->sidetext = "mm"; + def->label = _L("Diameter"); + def->tooltip = _L("Enter your filament diameter here. Good precision is required, so use a caliper " + "and do multiple measurements along the filament, then compute the average."); + def->sidetext = _L("mm"); def->cli = "filament-diameter=f@"; def->min = 0; def->default_value = new ConfigOptionFloats { 3. }; def = this->add("filament_density", coFloats); - def->label = "Density"; - def->tooltip = "Enter your filament density here. This is only for statistical information. " + def->label = _L("Density"); + def->tooltip = _L("Enter your filament density here. This is only for statistical information. " "A decent way is to weigh a known length of filament and compute the ratio " - "of the length to volume. Better is to calculate the volume directly through displacement."; - def->sidetext = "g/cm^3"; + "of the length to volume. Better is to calculate the volume directly through displacement."); + def->sidetext = _L("g/cm\u00B3"); def->cli = "filament-density=f@"; def->min = 0; def->default_value = new ConfigOptionFloats { 0. }; def = this->add("filament_type", coStrings); - def->label = "Filament type"; - def->tooltip = "If you want to process the output G-code through custom scripts, just list their " + def->label = _L("Filament type"); + def->tooltip = _L("If you want to process the output G-code through custom scripts, just list their " "absolute paths here. Separate multiple scripts with a semicolon. Scripts will be passed " "the absolute path to the G-code file as the first argument, and they can access " - "the Slic3r config settings by reading environment variables."; + "the Slic3r config settings by reading environment variables."); def->cli = "filament_type=s@"; def->gui_type = "f_enum_open"; def->gui_flags = "show_value"; @@ -463,15 +472,15 @@ PrintConfigDef::PrintConfigDef() def->default_value = new ConfigOptionStrings { "PLA" }; def = this->add("filament_soluble", coBools); - def->label = "Soluble material"; - def->tooltip = "Soluble material is most likely used for a soluble support."; + def->label = _L("Soluble material"); + def->tooltip = _L("Soluble material is most likely used for a soluble support."); def->cli = "filament-soluble!"; def->default_value = new ConfigOptionBools { false }; def = this->add("filament_cost", coFloats); - def->label = "Cost"; - def->tooltip = "Enter your filament cost per kg here. This is only for statistical information."; - def->sidetext = "money/kg"; + def->label = _L("Cost"); + def->tooltip = _L("Enter your filament cost per kg here. This is only for statistical information."); + def->sidetext = _L("money/kg"); def->cli = "filament-cost=f@"; def->min = 0; def->default_value = new ConfigOptionFloats { 0. }; @@ -480,12 +489,12 @@ PrintConfigDef::PrintConfigDef() def->default_value = new ConfigOptionStrings { "" }; def = this->add("fill_angle", coFloat); - def->label = "Fill angle"; - def->category = "Infill"; - def->tooltip = "Default base angle for infill orientation. Cross-hatching will be applied to this. " + def->label = _L("Fill angle"); + def->category = _L("Infill"); + def->tooltip = _L("Default base angle for infill orientation. Cross-hatching will be applied to this. " "Bridges will be infilled using the best direction Slic3r can detect, so this setting " - "does not affect them."; - def->sidetext = "°"; + "does not affect them."); + def->sidetext = _L("\u00B0"); def->cli = "fill-angle=f"; def->min = 0; def->max = 360; @@ -494,10 +503,10 @@ PrintConfigDef::PrintConfigDef() def = this->add("fill_density", coPercent); def->gui_type = "f_enum_open"; def->gui_flags = "show_value"; - def->label = "Fill density"; - def->category = "Infill"; - def->tooltip = "Density of internal infill, expressed in the range 0% - 100%."; - def->sidetext = "%"; + def->label = _L("Fill density"); + def->category = _L("Infill"); + def->tooltip = _L("Density of internal infill, expressed in the range 0% - 100%."); + def->sidetext = _L("%"); def->cli = "fill-density=s"; def->min = 0; def->max = 100; @@ -532,9 +541,9 @@ PrintConfigDef::PrintConfigDef() def->default_value = new ConfigOptionPercent(20); def = this->add("fill_pattern", coEnum); - def->label = "Fill pattern"; - def->category = "Infill"; - def->tooltip = "Fill pattern for general low-density infill."; + def->label = _L("Fill pattern"); + def->category = _L("Infill"); + def->tooltip = _L("Fill pattern for general low-density infill."); def->cli = "fill-pattern=s"; def->enum_keys_map = &ConfigOptionEnum::get_enum_values(); def->enum_values.push_back("rectilinear"); @@ -564,89 +573,89 @@ PrintConfigDef::PrintConfigDef() def->default_value = new ConfigOptionEnum(ipStars); def = this->add("first_layer_acceleration", coFloat); - def->label = "First layer"; - def->tooltip = "This is the acceleration your printer will use for first layer. Set zero " - "to disable acceleration control for first layer."; - def->sidetext = "mm/s²"; + def->label = _L("First layer"); + def->tooltip = _L("This is the acceleration your printer will use for first layer. Set zero " + "to disable acceleration control for first layer."); + def->sidetext = _L("mm/s\u00B2"); def->cli = "first-layer-acceleration=f"; def->min = 0; def->default_value = new ConfigOptionFloat(0); def = this->add("first_layer_bed_temperature", coInts); - def->label = "First layer"; - def->tooltip = "Heated build plate temperature for the first layer. Set this to zero to disable " - "bed temperature control commands in the output."; + def->label = _L("First layer"); + def->tooltip = _L("Heated build plate temperature for the first layer. Set this to zero to disable " + "bed temperature control commands in the output."); def->cli = "first-layer-bed-temperature=i@"; def->max = 0; def->max = 300; def->default_value = new ConfigOptionInts { 0 }; def = this->add("first_layer_extrusion_width", coFloatOrPercent); - def->label = "First layer"; - def->category = "Extrusion Width"; - def->tooltip = "Set this to a non-zero value to set a manual extrusion width for first layer. " + def->label = _L("First layer"); + def->category = _L("Extrusion Width"); + def->tooltip = _L("Set this to a non-zero value to set a manual extrusion width for first layer. " "You can use this to force fatter extrudates for better adhesion. If expressed " "as percentage (for example 120%) it will be computed over first layer height. " - "If set to zero, it will use the default extrusion width."; - def->sidetext = "mm or % (leave 0 for default)"; + "If set to zero, it will use the default extrusion width."); + def->sidetext = _L("mm or % (leave 0 for default)"); def->cli = "first-layer-extrusion-width=s"; def->ratio_over = "first_layer_height"; def->default_value = new ConfigOptionFloatOrPercent(200, true); def = this->add("first_layer_height", coFloatOrPercent); - def->label = "First layer height"; - def->category = "Layers and Perimeters"; - def->tooltip = "When printing with very low layer heights, you might still want to print a thicker " + def->label = _L("First layer height"); + def->category = _L("Layers and Perimeters"); + def->tooltip = _L("When printing with very low layer heights, you might still want to print a thicker " "bottom layer to improve adhesion and tolerance for non perfect build plates. " "This can be expressed as an absolute value or as a percentage (for example: 150%) " - "over the default layer height."; - def->sidetext = "mm or %"; + "over the default layer height."); + def->sidetext = _L("mm or %"); def->cli = "first-layer-height=s"; def->ratio_over = "layer_height"; def->default_value = new ConfigOptionFloatOrPercent(0.35, false); def = this->add("first_layer_speed", coFloatOrPercent); - def->label = "First layer speed"; - def->tooltip = "If expressed as absolute value in mm/s, this speed will be applied to all the print moves " + def->label = _L("First layer speed"); + def->tooltip = _L("If expressed as absolute value in mm/s, this speed will be applied to all the print moves " "of the first layer, regardless of their type. If expressed as a percentage " - "(for example: 40%) it will scale the default speeds."; - def->sidetext = "mm/s or %"; + "(for example: 40%) it will scale the default speeds."); + def->sidetext = _L("mm/s or %"); def->cli = "first-layer-speed=s"; def->min = 0; def->default_value = new ConfigOptionFloatOrPercent(30, false); def = this->add("first_layer_temperature", coInts); - def->label = "First layer"; - def->tooltip = "Extruder temperature for first layer. If you want to control temperature manually " - "during print, set this to zero to disable temperature control commands in the output file."; + def->label = _L("First layer"); + def->tooltip = _L("Extruder temperature for first layer. If you want to control temperature manually " + "during print, set this to zero to disable temperature control commands in the output file."); def->cli = "first-layer-temperature=i@"; def->min = 0; def->max = max_temp; def->default_value = new ConfigOptionInts { 200 }; def = this->add("gap_fill_speed", coFloat); - def->label = "Gap fill"; - def->category = "Speed"; - def->tooltip = "Speed for filling small gaps using short zigzag moves. Keep this reasonably low " - "to avoid too much shaking and resonance issues. Set zero to disable gaps filling."; - def->sidetext = "mm/s"; + def->label = _L("Gap fill"); + def->category = _L("Speed"); + def->tooltip = _L("Speed for filling small gaps using short zigzag moves. Keep this reasonably low " + "to avoid too much shaking and resonance issues. Set zero to disable gaps filling."); + def->sidetext = _L("mm/s"); def->cli = "gap-fill-speed=f"; def->min = 0; def->default_value = new ConfigOptionFloat(20); def = this->add("gcode_comments", coBool); - def->label = "Verbose G-code"; - def->tooltip = "Enable this to get a commented G-code file, with each line explained by a descriptive text. " + def->label = _L("Verbose G-code"); + def->tooltip = _L("Enable this to get a commented G-code file, with each line explained by a descriptive text. " "If you print from SD card, the additional weight of the file could make your firmware " - "slow down."; + "slow down."); def->cli = "gcode-comments!"; def->default_value = new ConfigOptionBool(0); def = this->add("gcode_flavor", coEnum); - def->label = "G-code flavor"; - def->tooltip = "Some G/M-code commands, including temperature control and others, are not universal. " + def->label = _L("G-code flavor"); + def->tooltip = _L("Some G/M-code commands, including temperature control and others, are not universal. " "Set this option to your printer's firmware to get a compatible output. " - "The \"No extrusion\" flavor prevents Slic3r from exporting any extrusion value at all."; + "The \"No extrusion\" flavor prevents Slic3r from exporting any extrusion value at all."); def->cli = "gcode-flavor=s"; def->enum_keys_map = &ConfigOptionEnum::get_enum_values(); def->enum_values.push_back("reprap"); @@ -672,75 +681,75 @@ PrintConfigDef::PrintConfigDef() def->default_value = new ConfigOptionEnum(gcfMarlin); def = this->add("infill_acceleration", coFloat); - def->label = "Infill"; - def->tooltip = "This is the acceleration your printer will use for infill. Set zero to disable " - "acceleration control for infill."; - def->sidetext = "mm/s²"; + def->label = _L("Infill"); + def->tooltip = _L("This is the acceleration your printer will use for infill. Set zero to disable " + "acceleration control for infill."); + def->sidetext = _L("mm/s\u00B2"); def->cli = "infill-acceleration=f"; def->min = 0; def->default_value = new ConfigOptionFloat(0); def = this->add("infill_every_layers", coInt); - def->label = "Combine infill every"; - def->category = "Infill"; - def->tooltip = "This feature allows to combine infill and speed up your print by extruding thicker " - "infill layers while preserving thin perimeters, thus accuracy."; - def->sidetext = "layers"; + def->label = _L("Combine infill every"); + def->category = _L("Infill"); + def->tooltip = _L("This feature allows to combine infill and speed up your print by extruding thicker " + "infill layers while preserving thin perimeters, thus accuracy."); + def->sidetext = _L("layers"); def->cli = "infill-every-layers=i"; - def->full_label = "Combine infill every n layers"; + def->full_label = _L("Combine infill every n layers"); def->min = 1; def->default_value = new ConfigOptionInt(1); def = this->add("infill_extruder", coInt); - def->label = "Infill extruder"; - def->category = "Extruders"; - def->tooltip = "The extruder to use when printing infill."; + def->label = _L("Infill extruder"); + def->category = _L("Extruders"); + def->tooltip = _L("The extruder to use when printing infill."); def->cli = "infill-extruder=i"; def->min = 1; def->default_value = new ConfigOptionInt(1); def = this->add("infill_extrusion_width", coFloatOrPercent); - def->label = "Infill"; - def->category = "Extrusion Width"; - def->tooltip = "Set this to a non-zero value to set a manual extrusion width for infill. " + def->label = _L("Infill"); + def->category = _L("Extrusion Width"); + def->tooltip = _L("Set this to a non-zero value to set a manual extrusion width for infill. " "If left zero, default extrusion width will be used if set, otherwise 1.125 x nozzle diameter will be used. " "You may want to use fatter extrudates to speed up the infill and make your parts stronger. " - "If expressed as percentage (for example 90%) it will be computed over layer height."; - def->sidetext = "mm or % (leave 0 for default)"; + "If expressed as percentage (for example 90%) it will be computed over layer height."); + def->sidetext = _L("mm or % (leave 0 for default)"); def->cli = "infill-extrusion-width=s"; def->default_value = new ConfigOptionFloatOrPercent(0, false); def = this->add("infill_first", coBool); - def->label = "Infill before perimeters"; - def->tooltip = "This option will switch the print order of perimeters and infill, making the latter first."; + def->label = _L("Infill before perimeters"); + def->tooltip = _L("This option will switch the print order of perimeters and infill, making the latter first."); def->cli = "infill-first!"; def->default_value = new ConfigOptionBool(false); def = this->add("infill_only_where_needed", coBool); - def->label = "Only infill where needed"; - def->category = "Infill"; - def->tooltip = "This option will limit infill to the areas actually needed for supporting ceilings " + def->label = _L("Only infill where needed"); + def->category = _L("Infill"); + def->tooltip = _L("This option will limit infill to the areas actually needed for supporting ceilings " "(it will act as internal support material). If enabled, slows down the G-code generation " - "due to the multiple checks involved."; + "due to the multiple checks involved."); def->cli = "infill-only-where-needed!"; def->default_value = new ConfigOptionBool(false); def = this->add("infill_overlap", coFloatOrPercent); - def->label = "Infill/perimeters overlap"; - def->category = "Advanced"; - def->tooltip = "This setting applies an additional overlap between infill and perimeters for better bonding. " + def->label = _L("Infill/perimeters overlap"); + def->category = _L("Advanced"); + def->tooltip = _L("This setting applies an additional overlap between infill and perimeters for better bonding. " "Theoretically this shouldn't be needed, but backlash might cause gaps. If expressed " - "as percentage (example: 15%) it is calculated over perimeter extrusion width."; - def->sidetext = "mm or %"; + "as percentage (example: 15%) it is calculated over perimeter extrusion width."); + def->sidetext = _L("mm or %"); def->cli = "infill-overlap=s"; def->ratio_over = "perimeter_extrusion_width"; def->default_value = new ConfigOptionFloatOrPercent(25, true); def = this->add("infill_speed", coFloat); - def->label = "Infill"; - def->category = "Speed"; - def->tooltip = "Speed for printing the internal fill. Set to zero for auto."; - def->sidetext = "mm/s"; + def->label = _L("Infill"); + def->category = _L("Speed"); + def->tooltip = _L("Speed for printing the internal fill. Set to zero for auto."); + def->sidetext = _L("mm/s"); def->cli = "infill-speed=f"; def->aliases.push_back("print_feed_rate"); def->aliases.push_back("infill_feed_rate"); @@ -748,19 +757,19 @@ PrintConfigDef::PrintConfigDef() def->default_value = new ConfigOptionFloat(80); def = this->add("interface_shells", coBool); - def->label = "Interface shells"; - def->tooltip = "Force the generation of solid shells between adjacent materials/volumes. " + def->label = _L("Interface shells"); + def->tooltip = _L("Force the generation of solid shells between adjacent materials/volumes. " "Useful for multi-extruder prints with translucent materials or manual soluble " - "support material."; + "support material."); def->cli = "interface-shells!"; - def->category = "Layers and Perimeters"; + def->category = _L("Layers and Perimeters"); def->default_value = new ConfigOptionBool(false); def = this->add("layer_gcode", coString); - def->label = "After layer change G-code"; - def->tooltip = "This custom code is inserted at every layer change, right after the Z move " + def->label = _L("After layer change G-code"); + def->tooltip = _L("This custom code is inserted at every layer change, right after the Z move " "and before the extruder moves to the first layer point. Note that you can use " - "placeholder variables for all Slic3r settings as well as [layer_num] and [layer_z]."; + "placeholder variables for all Slic3r settings as well as [layer_num] and [layer_z]."); def->cli = "after-layer-gcode|layer-gcode=s"; def->multiline = true; def->full_width = true; @@ -768,116 +777,116 @@ PrintConfigDef::PrintConfigDef() def->default_value = new ConfigOptionString(""); def = this->add("layer_height", coFloat); - def->label = "Layer height"; - def->category = "Layers and Perimeters"; - def->tooltip = "This setting controls the height (and thus the total number) of the slices/layers. " - "Thinner layers give better accuracy but take more time to print."; - def->sidetext = "mm"; + def->label = _L("Layer height"); + def->category = _L("Layers and Perimeters"); + def->tooltip = _L("This setting controls the height (and thus the total number) of the slices/layers. " + "Thinner layers give better accuracy but take more time to print."); + def->sidetext = _L("mm"); def->cli = "layer-height=f"; def->min = 0; def->default_value = new ConfigOptionFloat(0.3); def = this->add("max_fan_speed", coInts); - def->label = "Max"; - def->tooltip = "This setting represents the maximum speed of your fan."; - def->sidetext = "%"; + def->label = _L("Max"); + def->tooltip = _L("This setting represents the maximum speed of your fan."); + def->sidetext = _L("%"); def->cli = "max-fan-speed=i@"; def->min = 0; def->max = 100; def->default_value = new ConfigOptionInts { 100 }; def = this->add("max_layer_height", coFloats); - def->label = "Max"; - def->tooltip = "This is the highest printable layer height for this extruder, used to cap " + def->label = _L("Max"); + def->tooltip = _L("This is the highest printable layer height for this extruder, used to cap " "the variable layer height and support layer height. Maximum recommended layer height " "is 75% of the extrusion width to achieve reasonable inter-layer adhesion. " - "If set to 0, layer height is limited to 75% of the nozzle diameter."; - def->sidetext = "mm"; + "If set to 0, layer height is limited to 75% of the nozzle diameter."); + def->sidetext = _L("mm"); def->cli = "max-layer-height=f@"; def->min = 0; def->default_value = new ConfigOptionFloats { 0. }; def = this->add("max_print_speed", coFloat); - def->label = "Max print speed"; - def->tooltip = "When setting other speed settings to 0 Slic3r will autocalculate the optimal speed " + def->label = _L("Max print speed"); + def->tooltip = _L("When setting other speed settings to 0 Slic3r will autocalculate the optimal speed " "in order to keep constant extruder pressure. This experimental setting is used " - "to set the highest print speed you want to allow."; - def->sidetext = "mm/s"; + "to set the highest print speed you want to allow."); + def->sidetext = _L("mm/s"); def->cli = "max-print-speed=f"; def->min = 1; def->default_value = new ConfigOptionFloat(80); def = this->add("max_volumetric_speed", coFloat); - def->label = "Max volumetric speed"; - def->tooltip = "This experimental setting is used to set the maximum volumetric speed your " - "extruder supports."; - def->sidetext = "mm³/s"; + def->label = _L("Max volumetric speed"); + def->tooltip = _L("This experimental setting is used to set the maximum volumetric speed your " + "extruder supports."); + def->sidetext = _L("mm\u00B3/s"); def->cli = "max-volumetric-speed=f"; def->min = 0; def->default_value = new ConfigOptionFloat(0); def = this->add("max_volumetric_extrusion_rate_slope_positive", coFloat); - def->label = "Max volumetric slope positive"; - def->tooltip = "This experimental setting is used to limit the speed of change in extrusion rate. " - "A value of 1.8 mm³/s² ensures, that a change from the extrusion rate " - "of 1.8 mm³/s (0.45mm extrusion width, 0.2mm extrusion height, feedrate 20 mm/s) " - "to 5.4 mm³/s (feedrate 60 mm/s) will take at least 2 seconds."; - def->sidetext = "mm³/s²"; + def->label = _L("Max volumetric slope positive"); + def->tooltip = _L("This experimental setting is used to limit the speed of change in extrusion rate. " + "A value of 1.8 mm\u00B3/s\u00B2 ensures, that a change from the extrusion rate " + "of 1.8 mm\u00B3/s (0.45mm extrusion width, 0.2mm extrusion height, feedrate 20 mm/s) " + "to 5.4 mm\u00B3/s (feedrate 60 mm/s) will take at least 2 seconds."); + def->sidetext = _L("mm\u00B3/s\u00B2"); def->cli = "max-volumetric-extrusion-rate-slope-positive=f"; def->min = 0; def->default_value = new ConfigOptionFloat(0); def = this->add("max_volumetric_extrusion_rate_slope_negative", coFloat); - def->label = "Max volumetric slope negative"; - def->tooltip = "This experimental setting is used to limit the speed of change in extrusion rate. " - "A value of 1.8 mm³/s² ensures, that a change from the extrusion rate " - "of 1.8 mm³/s (0.45mm extrusion width, 0.2mm extrusion height, feedrate 20 mm/s) " - "to 5.4 mm³/s (feedrate 60 mm/s) will take at least 2 seconds."; - def->sidetext = "mm³/s²"; + def->label = _L("Max volumetric slope negative"); + def->tooltip = _L("This experimental setting is used to limit the speed of change in extrusion rate. " + "A value of 1.8 mm\u00B3/s\u00B2 ensures, that a change from the extrusion rate " + "of 1.8 mm\u00B3/s (0.45mm extrusion width, 0.2mm extrusion height, feedrate 20 mm/s) " + "to 5.4 mm\u00B3/s (feedrate 60 mm/s) will take at least 2 seconds."); + def->sidetext = _L("mm\u00B3/s\u00B2"); def->cli = "max-volumetric-extrusion-rate-slope-negative=f"; def->min = 0; def->default_value = new ConfigOptionFloat(0); def = this->add("min_fan_speed", coInts); - def->label = "Min"; - def->tooltip = "This setting represents the minimum PWM your fan needs to work."; - def->sidetext = "%"; + def->label = _L("Min"); + def->tooltip = _L("This setting represents the minimum PWM your fan needs to work."); + def->sidetext = _L("%"); def->cli = "min-fan-speed=i@"; def->min = 0; def->max = 100; def->default_value = new ConfigOptionInts { 35 }; def = this->add("min_layer_height", coFloats); - def->label = "Min"; - def->tooltip = "This is the lowest printable layer height for this extruder and limits " - "the resolution for variable layer height. Typical values are between 0.05 mm and 0.1 mm."; - def->sidetext = "mm"; + def->label = _L("Min"); + def->tooltip = _L("This is the lowest printable layer height for this extruder and limits " + "the resolution for variable layer height. Typical values are between 0.05 mm and 0.1 mm."); + def->sidetext = _L("mm"); def->cli = "min-layer-height=f@"; def->min = 0; def->default_value = new ConfigOptionFloats { 0.07 }; def = this->add("min_print_speed", coFloats); - def->label = "Min print speed"; - def->tooltip = "Slic3r will not scale speed down below this speed."; - def->sidetext = "mm/s"; + def->label = _L("Min print speed"); + def->tooltip = _L("Slic3r will not scale speed down below this speed."); + def->sidetext = _L("mm/s"); def->cli = "min-print-speed=f@"; def->min = 0; def->default_value = new ConfigOptionFloats { 10. }; def = this->add("min_skirt_length", coFloat); - def->label = "Minimum extrusion length"; - def->tooltip = "Generate no less than the number of skirt loops required to consume " + def->label = _L("Minimum extrusion length"); + def->tooltip = _L("Generate no less than the number of skirt loops required to consume " "the specified amount of filament on the bottom layer. For multi-extruder machines, " - "this minimum applies to each extruder."; - def->sidetext = "mm"; + "this minimum applies to each extruder."); + def->sidetext = _L("mm"); def->cli = "min-skirt-length=f"; def->min = 0; def->default_value = new ConfigOptionFloat(0); def = this->add("notes", coString); - def->label = "Configuration notes"; - def->tooltip = "You can put here your personal notes. This text will be added to the G-code " - "header comments."; + def->label = _L("Configuration notes"); + def->tooltip = _L("You can put here your personal notes. This text will be added to the G-code " + "header comments."); def->cli = "notes=s"; def->multiline = true; def->full_width = true; @@ -885,127 +894,128 @@ PrintConfigDef::PrintConfigDef() def->default_value = new ConfigOptionString(""); def = this->add("nozzle_diameter", coFloats); - def->label = "Nozzle diameter"; - def->tooltip = "This is the diameter of your extruder nozzle (for example: 0.5, 0.35 etc.)"; - def->sidetext = "mm"; + def->label = _L("Nozzle diameter"); + def->tooltip = _L("This is the diameter of your extruder nozzle (for example: 0.5, 0.35 etc.)"); + def->sidetext = _L("mm"); def->cli = "nozzle-diameter=f@"; def->default_value = new ConfigOptionFloats { 0.5 }; def = this->add("octoprint_apikey", coString); - def->label = "API Key"; - def->tooltip = "Slic3r can upload G-code files to OctoPrint. This field should contain " - "the API Key required for authentication."; + def->label = _L("API Key"); + def->tooltip = _L("Slic3r can upload G-code files to OctoPrint. This field should contain " + "the API Key required for authentication."); def->cli = "octoprint-apikey=s"; def->default_value = new ConfigOptionString(""); def = this->add("octoprint_host", coString); - def->label = "Host or IP"; - def->tooltip = "Slic3r can upload G-code files to OctoPrint. This field should contain " - "the hostname or IP address of the OctoPrint instance."; + def->label = _L("Host or IP"); + def->tooltip = _L("Slic3r can upload G-code files to OctoPrint. This field should contain " + "the hostname or IP address of the OctoPrint instance."); def->cli = "octoprint-host=s"; def->default_value = new ConfigOptionString(""); def = this->add("only_retract_when_crossing_perimeters", coBool); - def->label = "Only retract when crossing perimeters"; - def->tooltip = "Disables retraction when the travel path does not exceed the upper layer's perimeters " - "(and thus any ooze will be probably invisible)."; + def->label = _L("Only retract when crossing perimeters"); + def->tooltip = _L("Disables retraction when the travel path does not exceed the upper layer's perimeters " + "(and thus any ooze will be probably invisible)."); def->cli = "only-retract-when-crossing-perimeters!"; def->default_value = new ConfigOptionBool(true); def = this->add("ooze_prevention", coBool); - def->label = "Enable"; - def->tooltip = "This option will drop the temperature of the inactive extruders to prevent oozing. " + def->label = _L("Enable"); + def->tooltip = _L("This option will drop the temperature of the inactive extruders to prevent oozing. " "It will enable a tall skirt automatically and move extruders outside such " - "skirt when changing temperatures."; + "skirt when changing temperatures."); def->cli = "ooze-prevention!"; def->default_value = new ConfigOptionBool(false); def = this->add("output_filename_format", coString); - def->label = "Output filename format"; - def->tooltip = "You can use all configuration options as variables inside this template. " + def->label = _L("Output filename format"); + def->tooltip = _L("You can use all configuration options as variables inside this template. " "For example: [layer_height], [fill_density] etc. You can also use [timestamp], " "[year], [month], [day], [hour], [minute], [second], [version], [input_filename], " - "[input_filename_base]."; + "[input_filename_base]."); def->cli = "output-filename-format=s"; def->full_width = true; def->default_value = new ConfigOptionString("[input_filename_base].gcode"); def = this->add("overhangs", coBool); - def->label = "Detect bridging perimeters"; - def->category = "Layers and Perimeters"; - def->tooltip = "Experimental option to adjust flow for overhangs (bridge flow will be used), " - "to apply bridge speed to them and enable fan."; + def->label = _L("Detect bridging perimeters"); + def->category = _L("Layers and Perimeters"); + def->tooltip = _L("Experimental option to adjust flow for overhangs (bridge flow will be used), " + "to apply bridge speed to them and enable fan."); def->cli = "overhangs!"; def->default_value = new ConfigOptionBool(true); def = this->add("perimeter_acceleration", coFloat); - def->label = "Perimeters"; - def->tooltip = "This is the acceleration your printer will use for perimeters. " + def->label = _L("Perimeters"); + def->tooltip = _L("This is the acceleration your printer will use for perimeters. " "A high value like 9000 usually gives good results if your hardware is up to the job. " - "Set zero to disable acceleration control for perimeters."; - def->sidetext = "mm/s²"; + "Set zero to disable acceleration control for perimeters."); + def->sidetext = _L("mm/s\u00B2"); def->cli = "perimeter-acceleration=f"; def->default_value = new ConfigOptionFloat(0); def = this->add("perimeter_extruder", coInt); - def->label = "Perimeter extruder"; - def->category = "Extruders"; - def->tooltip = "The extruder to use when printing perimeters and brim. First extruder is 1."; + def->label = _L("Perimeter extruder"); + def->category = _L("Extruders"); + def->tooltip = _L("The extruder to use when printing perimeters and brim. First extruder is 1."); def->cli = "perimeter-extruder=i"; def->aliases.push_back("perimeters_extruder"); def->min = 1; def->default_value = new ConfigOptionInt(1); def = this->add("perimeter_extrusion_width", coFloatOrPercent); - def->label = "Perimeters"; - def->category = "Extrusion Width"; - def->tooltip = "Set this to a non-zero value to set a manual extrusion width for perimeters. " + def->label = _L("Perimeters"); + def->category = _L("Extrusion Width"); + def->tooltip = _L("Set this to a non-zero value to set a manual extrusion width for perimeters. " "You may want to use thinner extrudates to get more accurate surfaces. " "If left zero, default extrusion width will be used if set, otherwise 1.125 x nozzle diameter will be used. " - "If expressed as percentage (for example 200%) it will be computed over layer height."; - def->sidetext = "mm or % (leave 0 for default)"; + "If expressed as percentage (for example 200%) it will be computed over layer height."); + def->sidetext = _L("mm or % (leave 0 for default)"); def->cli = "perimeter-extrusion-width=s"; def->aliases.push_back("perimeters_extrusion_width"); def->default_value = new ConfigOptionFloatOrPercent(0, false); def = this->add("perimeter_speed", coFloat); - def->label = "Perimeters"; - def->category = "Speed"; - def->tooltip = "Speed for perimeters (contours, aka vertical shells). Set to zero for auto."; - def->sidetext = "mm/s"; + def->label = _L("Perimeters"); + def->category = _L("Speed"); + def->tooltip = _L("Speed for perimeters (contours, aka vertical shells). Set to zero for auto."); + def->sidetext = _L("mm/s"); def->cli = "perimeter-speed=f"; def->aliases.push_back("perimeter_feed_rate"); def->min = 0; def->default_value = new ConfigOptionFloat(60); def = this->add("perimeters", coInt); - def->label = "Perimeters"; - def->category = "Layers and Perimeters"; - def->tooltip = "This option sets the number of perimeters to generate for each layer. " + def->label = _L("Perimeters"); + def->category = _L("Layers and Perimeters"); + def->tooltip = _L("This option sets the number of perimeters to generate for each layer. " "Note that Slic3r may increase this number automatically when it detects " "sloping surfaces which benefit from a higher number of perimeters " - "if the Extra Perimeters option is enabled."; - def->sidetext = "(minimum)"; + "if the Extra Perimeters option is enabled."); + def->sidetext = _L("(minimum)"); def->cli = "perimeters=i"; def->aliases.push_back("perimeter_offsets"); def->min = 0; def->default_value = new ConfigOptionInt(3); def = this->add("post_process", coStrings); - def->label = "Post-processing scripts"; - def->tooltip = "If you want to process the output G-code through custom scripts, " + def->label = _L("Post-processing scripts"); + def->tooltip = _L("If you want to process the output G-code through custom scripts, " "just list their absolute paths here. Separate multiple scripts with a semicolon. " "Scripts will be passed the absolute path to the G-code file as the first argument, " - "and they can access the Slic3r config settings by reading environment variables."; + "and they can access the Slic3r config settings by reading environment variables."); def->cli = "post-process=s@"; def->gui_flags = "serialized"; def->multiline = true; def->full_width = true; - def->height = 60; + def->height = 60; + def->default_value = new ConfigOptionStrings{ "" }; def = this->add("printer_notes", coString); - def->label = "Printer notes"; - def->tooltip = "You can put your notes regarding the printer here."; + def->label = _L("Printer notes"); + def->tooltip = _L("You can put your notes regarding the printer here."); def->cli = "printer-notes=s"; def->multiline = true; def->full_width = true; @@ -1019,131 +1029,131 @@ PrintConfigDef::PrintConfigDef() def->default_value = new ConfigOptionString(""); def = this->add("raft_layers", coInt); - def->label = "Raft layers"; - def->category = "Support material"; - def->tooltip = "The object will be raised by this number of layers, and support material " - "will be generated under it."; - def->sidetext = "layers"; + def->label = _L("Raft layers"); + def->category = _L("Support material"); + def->tooltip = _L("The object will be raised by this number of layers, and support material " + "will be generated under it."); + def->sidetext = _L("layers"); def->cli = "raft-layers=i"; def->min = 0; def->default_value = new ConfigOptionInt(0); def = this->add("resolution", coFloat); - def->label = "Resolution"; - def->tooltip = "Minimum detail resolution, used to simplify the input file for speeding up " + def->label = _L("Resolution"); + def->tooltip = _L("Minimum detail resolution, used to simplify the input file for speeding up " "the slicing job and reducing memory usage. High-resolution models often carry " "more detail than printers can render. Set to zero to disable any simplification " - "and use full resolution from input."; - def->sidetext = "mm"; + "and use full resolution from input."); + def->sidetext = _L("mm"); def->cli = "resolution=f"; def->min = 0; def->default_value = new ConfigOptionFloat(0); def = this->add("retract_before_travel", coFloats); - def->label = "Minimum travel after retraction"; - def->tooltip = "Retraction is not triggered when travel moves are shorter than this length."; - def->sidetext = "mm"; + def->label = _L("Minimum travel after retraction"); + def->tooltip = _L("Retraction is not triggered when travel moves are shorter than this length."); + def->sidetext = _L("mm"); def->cli = "retract-before-travel=f@"; def->default_value = new ConfigOptionFloats { 2. }; def = this->add("retract_before_wipe", coPercents); - def->label = "Retract amount before wipe"; - def->tooltip = "With bowden extruders, it may be wise to do some amount of quick retract " - "before doing the wipe movement."; - def->sidetext = "%"; + def->label = _L("Retract amount before wipe"); + def->tooltip = _L("With bowden extruders, it may be wise to do some amount of quick retract " + "before doing the wipe movement."); + def->sidetext = _L("%"); def->cli = "retract-before-wipe=s@"; def->default_value = new ConfigOptionPercents { 0. }; def = this->add("retract_layer_change", coBools); - def->label = "Retract on layer change"; - def->tooltip = "This flag enforces a retraction whenever a Z move is done."; + def->label = _L("Retract on layer change"); + def->tooltip = _L("This flag enforces a retraction whenever a Z move is done."); def->cli = "retract-layer-change!"; def->default_value = new ConfigOptionBools { false }; def = this->add("retract_length", coFloats); - def->label = "Length"; - def->full_label = "Retraction Length"; - def->tooltip = "When retraction is triggered, filament is pulled back by the specified amount " - "(the length is measured on raw filament, before it enters the extruder)."; - def->sidetext = "mm (zero to disable)"; + def->label = _L("Length"); + def->full_label = _L("Retraction Length"); + def->tooltip = _L("When retraction is triggered, filament is pulled back by the specified amount " + "(the length is measured on raw filament, before it enters the extruder)."); + def->sidetext = _L("mm (zero to disable)"); def->cli = "retract-length=f@"; def->default_value = new ConfigOptionFloats { 2. }; def = this->add("retract_length_toolchange", coFloats); - def->label = "Length"; - def->full_label = "Retraction Length (Toolchange)"; - def->tooltip = "When retraction is triggered before changing tool, filament is pulled back " + def->label = _L("Length"); + def->full_label = _L("Retraction Length (Toolchange)"); + def->tooltip = _L("When retraction is triggered before changing tool, filament is pulled back " "by the specified amount (the length is measured on raw filament, before it enters " - "the extruder)."; - def->sidetext = "mm (zero to disable)"; + "the extruder)."); + def->sidetext = _L("mm (zero to disable)"); def->cli = "retract-length-toolchange=f@"; def->default_value = new ConfigOptionFloats { 10. }; def = this->add("retract_lift", coFloats); - def->label = "Lift Z"; - def->tooltip = "If you set this to a positive value, Z is quickly raised every time a retraction " + def->label = _L("Lift Z"); + def->tooltip = _L("If you set this to a positive value, Z is quickly raised every time a retraction " "is triggered. When using multiple extruders, only the setting for the first extruder " - "will be considered."; - def->sidetext = "mm"; + "will be considered."); + def->sidetext = _L("mm"); def->cli = "retract-lift=f@"; def->default_value = new ConfigOptionFloats { 0. }; def = this->add("retract_lift_above", coFloats); - def->label = "Above Z"; - def->full_label = "Only lift Z above"; - def->tooltip = "If you set this to a positive value, Z lift will only take place above the specified " - "absolute Z. You can tune this setting for skipping lift on the first layers."; - def->sidetext = "mm"; + def->label = _L("Above Z"); + def->full_label = _L("Only lift Z above"); + def->tooltip = _L("If you set this to a positive value, Z lift will only take place above the specified " + "absolute Z. You can tune this setting for skipping lift on the first layers."); + def->sidetext = _L("mm"); def->cli = "retract-lift-above=f@"; def->default_value = new ConfigOptionFloats { 0. }; def = this->add("retract_lift_below", coFloats); - def->label = "Below Z"; - def->full_label = "Only lift Z below"; - def->tooltip = "If you set this to a positive value, Z lift will only take place below " + def->label = _L("Below Z"); + def->full_label = _L("Only lift Z below"); + def->tooltip = _L("If you set this to a positive value, Z lift will only take place below " "the specified absolute Z. You can tune this setting for limiting lift " - "to the first layers."; - def->sidetext = "mm"; + "to the first layers."); + def->sidetext = _L("mm"); def->cli = "retract-lift-below=f@"; def->default_value = new ConfigOptionFloats { 0. }; def = this->add("retract_restart_extra", coFloats); - def->label = "Extra length on restart"; - def->tooltip = "When the retraction is compensated after the travel move, the extruder will push " - "this additional amount of filament. This setting is rarely needed."; - def->sidetext = "mm"; + def->label = _L("Extra length on restart"); + def->tooltip = _L("When the retraction is compensated after the travel move, the extruder will push " + "this additional amount of filament. This setting is rarely needed."); + def->sidetext = _L("mm"); def->cli = "retract-restart-extra=f@"; def->default_value = new ConfigOptionFloats { 0. }; def = this->add("retract_restart_extra_toolchange", coFloats); - def->label = "Extra length on restart"; - def->tooltip = "When the retraction is compensated after changing tool, the extruder will push " - "this additional amount of filament."; - def->sidetext = "mm"; + def->label = _L("Extra length on restart"); + def->tooltip = _L("When the retraction is compensated after changing tool, the extruder will push " + "this additional amount of filament."); + def->sidetext = _L("mm"); def->cli = "retract-restart-extra-toolchange=f@"; def->default_value = new ConfigOptionFloats { 0. }; def = this->add("retract_speed", coFloats); - def->label = "Retraction Speed"; - def->full_label = "Retraction Speed"; - def->tooltip = "The speed for retractions (it only applies to the extruder motor)."; - def->sidetext = "mm/s"; + def->label = _L("Retraction Speed"); + def->full_label = _L("Retraction Speed"); + def->tooltip = _L("The speed for retractions (it only applies to the extruder motor)."); + def->sidetext = _L("mm/s"); def->cli = "retract-speed=f@"; def->default_value = new ConfigOptionFloats { 40. }; def = this->add("deretract_speed", coFloats); - def->label = "Deretraction Speed"; - def->full_label = "Deretraction Speed"; - def->tooltip = "The speed for loading of a filament into extruder after retraction " - "(it only applies to the extruder motor). If left to zero, the retraction speed is used."; - def->sidetext = "mm/s"; + def->label = _L("Deretraction Speed"); + def->full_label = _L("Deretraction Speed"); + def->tooltip = _L("The speed for loading of a filament into extruder after retraction " + "(it only applies to the extruder motor). If left to zero, the retraction speed is used."); + def->sidetext = _L("mm/s"); def->cli = "retract-speed=f@"; def->default_value = new ConfigOptionFloats { 0. }; def = this->add("seam_position", coEnum); - def->label = "Seam position"; - def->category = "Layers and Perimeters"; - def->tooltip = "Position of perimeters starting points."; + def->label = _L("Seam position"); + def->category = _L("Layers and Perimeters"); + def->tooltip = _L("Position of perimeters starting points."); def->cli = "seam-position=s"; def->enum_keys_map = &ConfigOptionEnum::get_enum_values(); def->enum_values.push_back("random"); @@ -1159,10 +1169,10 @@ PrintConfigDef::PrintConfigDef() #if 0 def = this->add("seam_preferred_direction", coFloat); // def->gui_type = "slider"; - def->label = "Direction"; - def->sidetext = "°"; - def->full_label = "Preferred direction of the seam"; - def->tooltip = "Seam preferred direction"; + def->label = _L("Direction"); + def->sidetext = _L("\u00B0"); + def->full_label = _L("Preferred direction of the seam"); + def->tooltip = _L("Seam preferred direction"); def->cli = "seam-preferred-direction=f"; def->min = 0; def->max = 360; @@ -1170,10 +1180,10 @@ PrintConfigDef::PrintConfigDef() def = this->add("seam_preferred_direction_jitter", coFloat); // def->gui_type = "slider"; - def->label = "Jitter"; - def->sidetext = "°"; - def->full_label = "Seam preferred direction jitter"; - def->tooltip = "Preferred direction of the seam - jitter"; + def->label = _L("Jitter"); + def->sidetext = _L("\u00B0"); + def->full_label = _L("Seam preferred direction jitter"); + def->tooltip = _L("Preferred direction of the seam - jitter"); def->cli = "seam-preferred-direction-jitter=f"; def->min = 0; def->max = 360; @@ -1183,17 +1193,17 @@ PrintConfigDef::PrintConfigDef() def = this->add("serial_port", coString); def->gui_type = "select_open"; def->label = ""; - def->full_label = "Serial port"; - def->tooltip = "USB/serial port for printer connection."; + def->full_label = _L("Serial port"); + def->tooltip = _L("USB/serial port for printer connection."); def->cli = "serial-port=s"; def->width = 200; def->default_value = new ConfigOptionString(""); def = this->add("serial_speed", coInt); def->gui_type = "i_enum_open"; - def->label = "Speed"; - def->full_label = "Serial port speed"; - def->tooltip = "Speed (baud) of USB/serial port for printer connection."; + def->label = _L("Speed"); + def->full_label = _L("Serial port speed"); + def->tooltip = _L("Speed (baud) of USB/serial port for printer connection."); def->cli = "serial-speed=i"; def->min = 1; def->max = 300000; @@ -1202,37 +1212,37 @@ PrintConfigDef::PrintConfigDef() def->default_value = new ConfigOptionInt(250000); def = this->add("skirt_distance", coFloat); - def->label = "Distance from object"; - def->tooltip = "Distance between skirt and object(s). Set this to zero to attach the skirt " - "to the object(s) and get a brim for better adhesion."; - def->sidetext = "mm"; + def->label = _L("Distance from object"); + def->tooltip = _L("Distance between skirt and object(s). Set this to zero to attach the skirt " + "to the object(s) and get a brim for better adhesion."); + def->sidetext = _L("mm"); def->cli = "skirt-distance=f"; def->min = 0; def->default_value = new ConfigOptionFloat(6); def = this->add("skirt_height", coInt); - def->label = "Skirt height"; - def->tooltip = "Height of skirt expressed in layers. Set this to a tall value to use skirt " - "as a shield against drafts."; - def->sidetext = "layers"; + def->label = _L("Skirt height"); + def->tooltip = _L("Height of skirt expressed in layers. Set this to a tall value to use skirt " + "as a shield against drafts."); + def->sidetext = _L("layers"); def->cli = "skirt-height=i"; def->default_value = new ConfigOptionInt(1); def = this->add("skirts", coInt); - def->label = "Loops (minimum)"; - def->full_label = "Skirt Loops"; - def->tooltip = "Number of loops for the skirt. If the Minimum Extrusion Length option is set, " + def->label = _L("Loops (minimum)"); + def->full_label = _L("Skirt Loops"); + def->tooltip = _L("Number of loops for the skirt. If the Minimum Extrusion Length option is set, " "the number of loops might be greater than the one configured here. Set this to zero " - "to disable skirt completely."; + "to disable skirt completely."); def->cli = "skirts=i"; def->min = 0; def->default_value = new ConfigOptionInt(1); def = this->add("slowdown_below_layer_time", coInts); - def->label = "Slow down if layer print time is below"; - def->tooltip = "If layer print time is estimated below this number of seconds, print moves " - "speed will be scaled down to extend duration to this value."; - def->sidetext = "approximate seconds"; + def->label = _L("Slow down if layer print time is below"); + def->tooltip = _L("If layer print time is estimated below this number of seconds, print moves " + "speed will be scaled down to extend duration to this value."); + def->sidetext = _L("approximate seconds"); def->cli = "slowdown-below-layer-time=i@"; def->width = 60; def->min = 0; @@ -1240,63 +1250,63 @@ PrintConfigDef::PrintConfigDef() def->default_value = new ConfigOptionInts { 5 }; def = this->add("small_perimeter_speed", coFloatOrPercent); - def->label = "Small perimeters"; - def->category = "Speed"; - def->tooltip = "This separate setting will affect the speed of perimeters having radius <= 6.5mm " + def->label = _L("Small perimeters"); + def->category = _L("Speed"); + def->tooltip = _L("This separate setting will affect the speed of perimeters having radius <= 6.5mm " "(usually holes). If expressed as percentage (for example: 80%) it will be calculated " - "on the perimeters speed setting above. Set to zero for auto."; - def->sidetext = "mm/s or %"; + "on the perimeters speed setting above. Set to zero for auto."); + def->sidetext = _L("mm/s or %"); def->cli = "small-perimeter-speed=s"; def->ratio_over = "perimeter_speed"; def->min = 0; def->default_value = new ConfigOptionFloatOrPercent(15, false); def = this->add("solid_infill_below_area", coFloat); - def->label = "Solid infill threshold area"; - def->category = "Infill"; - def->tooltip = "Force solid infill for regions having a smaller area than the specified threshold."; - def->sidetext = "mm²"; + def->label = _L("Solid infill threshold area"); + def->category = _L("Infill"); + def->tooltip = _L("Force solid infill for regions having a smaller area than the specified threshold."); + def->sidetext = _L("mm\u00B2"); def->cli = "solid-infill-below-area=f"; def->min = 0; def->default_value = new ConfigOptionFloat(70); def = this->add("solid_infill_extruder", coInt); - def->label = "Solid infill extruder"; - def->category = "Extruders"; - def->tooltip = "The extruder to use when printing solid infill."; + def->label = _L("Solid infill extruder"); + def->category = _L("Extruders"); + def->tooltip = _L("The extruder to use when printing solid infill."); def->cli = "solid-infill-extruder=i"; def->min = 1; def->default_value = new ConfigOptionInt(1); def = this->add("solid_infill_every_layers", coInt); - def->label = "Solid infill every"; - def->category = "Infill"; - def->tooltip = "This feature allows to force a solid layer every given number of layers. " + def->label = _L("Solid infill every"); + def->category = _L("Infill"); + def->tooltip = _L("This feature allows to force a solid layer every given number of layers. " "Zero to disable. You can set this to any value (for example 9999); " "Slic3r will automatically choose the maximum possible number of layers " - "to combine according to nozzle diameter and layer height."; - def->sidetext = "layers"; + "to combine according to nozzle diameter and layer height."); + def->sidetext = _L("layers"); def->cli = "solid-infill-every-layers=i"; def->min = 0; def->default_value = new ConfigOptionInt(0); def = this->add("solid_infill_extrusion_width", coFloatOrPercent); - def->label = "Solid infill"; - def->category = "Extrusion Width"; - def->tooltip = "Set this to a non-zero value to set a manual extrusion width for infill for solid surfaces. " + def->label = _L("Solid infill"); + def->category = _L("Extrusion Width"); + def->tooltip = _L("Set this to a non-zero value to set a manual extrusion width for infill for solid surfaces. " "If left zero, default extrusion width will be used if set, otherwise 1.125 x nozzle diameter will be used. " - "If expressed as percentage (for example 90%) it will be computed over layer height."; - def->sidetext = "mm or % (leave 0 for default)"; + "If expressed as percentage (for example 90%) it will be computed over layer height."); + def->sidetext = _L("mm or % (leave 0 for default)"); def->cli = "solid-infill-extrusion-width=s"; def->default_value = new ConfigOptionFloatOrPercent(0, false); def = this->add("solid_infill_speed", coFloatOrPercent); - def->label = "Solid infill"; - def->category = "Speed"; - def->tooltip = "Speed for printing solid regions (top/bottom/internal horizontal shells). " + def->label = _L("Solid infill"); + def->category = _L("Speed"); + def->tooltip = _L("Speed for printing solid regions (top/bottom/internal horizontal shells). " "This can be expressed as a percentage (for example: 80%) over the default " - "infill speed above. Set to zero for auto."; - def->sidetext = "mm/s or %"; + "infill speed above. Set to zero for auto."); + def->sidetext = _L("mm/s or %"); def->cli = "solid-infill-speed=s"; def->ratio_over = "infill_speed"; def->aliases.push_back("solid_infill_feed_rate"); @@ -1304,42 +1314,42 @@ PrintConfigDef::PrintConfigDef() def->default_value = new ConfigOptionFloatOrPercent(20, false); def = this->add("solid_layers", coInt); - def->label = "Solid layers"; - def->tooltip = "Number of solid layers to generate on top and bottom surfaces."; + def->label = _L("Solid layers"); + def->tooltip = _L("Number of solid layers to generate on top and bottom surfaces."); def->cli = "solid-layers=i"; def->shortcut.push_back("top_solid_layers"); def->shortcut.push_back("bottom_solid_layers"); def->min = 0; def = this->add("spiral_vase", coBool); - def->label = "Spiral vase"; - def->tooltip = "This feature will raise Z gradually while printing a single-walled object " + def->label = _L("Spiral vase"); + def->tooltip = _L("This feature will raise Z gradually while printing a single-walled object " "in order to remove any visible seam. This option requires a single perimeter, " "no infill, no top solid layers and no support material. You can still set " "any number of bottom solid layers as well as skirt/brim loops. " - "It won't work when printing more than an object."; + "It won't work when printing more than an object."); def->cli = "spiral-vase!"; def->default_value = new ConfigOptionBool(false); def = this->add("standby_temperature_delta", coInt); - def->label = "Temperature variation"; - def->tooltip = "Temperature difference to be applied when an extruder is not active. " - "Enables a full-height \"sacrificial\" skirt on which the nozzles are periodically wiped."; - def->sidetext = "∆°C"; + def->label = _L("Temperature variation"); + def->tooltip = _L("Temperature difference to be applied when an extruder is not active. " + "Enables a full-height \"sacrificial\" skirt on which the nozzles are periodically wiped."); + def->sidetext = "∆°C"; def->cli = "standby-temperature-delta=i"; def->min = -max_temp; def->max = max_temp; def->default_value = new ConfigOptionInt(-5); def = this->add("start_gcode", coString); - def->label = "Start G-code"; - def->tooltip = "This start procedure is inserted at the beginning, after bed has reached " + def->label = _L("Start G-code"); + def->tooltip = _L("This start procedure is inserted at the beginning, after bed has reached " "the target temperature and extruder just started heating, and before extruder " "has finished heating. If Slic3r detects M104 or M190 in your custom codes, " "such commands will not be prepended automatically so you're free to customize " "the order of heating commands and other custom actions. Note that you can use " "placeholder variables for all Slic3r settings, so you can put " - "a \"M109 S[first_layer_temperature]\" command wherever you want."; + "a \"M109 S[first_layer_temperature]\" command wherever you want."); def->cli = "start-gcode=s"; def->multiline = true; def->full_width = true; @@ -1347,15 +1357,15 @@ PrintConfigDef::PrintConfigDef() def->default_value = new ConfigOptionString("G28 ; home all axes\nG1 Z5 F5000 ; lift nozzle\n"); def = this->add("start_filament_gcode", coStrings); - def->label = "Start G-code"; - def->tooltip = "This start procedure is inserted at the beginning, after any printer start gcode. " + def->label = _L("Start G-code"); + def->tooltip = _L("This start procedure is inserted at the beginning, after any printer start gcode. " "This is used to override settings for a specific filament. If Slic3r detects " "M104, M109, M140 or M190 in your custom codes, such commands will " "not be prepended automatically so you're free to customize the order " "of heating commands and other custom actions. Note that you can use placeholder variables " "for all Slic3r settings, so you can put a \"M109 S[first_layer_temperature]\" command " "wherever you want. If you have multiple extruders, the gcode is processed " - "in extruder order."; + "in extruder order."); def->cli = "start-filament-gcode=s@"; def->multiline = true; def->full_width = true; @@ -1363,24 +1373,24 @@ PrintConfigDef::PrintConfigDef() def->default_value = new ConfigOptionStrings { "; Filament gcode\n" }; def = this->add("single_extruder_multi_material", coBool); - def->label = "Single Extruder Multi Material"; - def->tooltip = "The printer multiplexes filaments into a single hot end."; + def->label = _L("Single Extruder Multi Material"); + def->tooltip = _L("The printer multiplexes filaments into a single hot end."); def->cli = "single-extruder-multi-material!"; def->default_value = new ConfigOptionBool(false); def = this->add("support_material", coBool); - def->label = "Generate support material"; - def->category = "Support material"; - def->tooltip = "Enable support material generation."; + def->label = _L("Generate support material"); + def->category = _L("Support material"); + def->tooltip = _L("Enable support material generation."); def->cli = "support-material!"; def->default_value = new ConfigOptionBool(false); def = this->add("support_material_xy_spacing", coFloatOrPercent); - def->label = "XY separation between an object and its support"; - def->category = "Support material"; - def->tooltip = "XY separation between an object and its support. If expressed as percentage " - "(for example 50%), it will be calculated over external perimeter width."; - def->sidetext = "mm or %"; + def->label = _L("XY separation between an object and its support"); + def->category = _L("Support material"); + def->tooltip = _L("XY separation between an object and its support. If expressed as percentage " + "(for example 50%), it will be calculated over external perimeter width."); + def->sidetext = _L("mm or %"); def->cli = "support-material-xy-spacing=s"; def->ratio_over = "external_perimeter_extrusion_width"; def->min = 0; @@ -1388,30 +1398,30 @@ PrintConfigDef::PrintConfigDef() def->default_value = new ConfigOptionFloatOrPercent(50, true); def = this->add("support_material_angle", coFloat); - def->label = "Pattern angle"; - def->category = "Support material"; - def->tooltip = "Use this setting to rotate the support material pattern on the horizontal plane."; - def->sidetext = "°"; + def->label = _L("Pattern angle"); + def->category = _L("Support material"); + def->tooltip = _L("Use this setting to rotate the support material pattern on the horizontal plane."); + def->sidetext = _L("\u00B0"); def->cli = "support-material-angle=f"; def->min = 0; def->max = 359; def->default_value = new ConfigOptionFloat(0); def = this->add("support_material_buildplate_only", coBool); - def->label = "Support on build plate only"; - def->category = "Support material"; - def->tooltip = "Only create support if it lies on a build plate. Don't create support on a print."; + def->label = _L("Support on build plate only"); + def->category = _L("Support material"); + def->tooltip = _L("Only create support if it lies on a build plate. Don't create support on a print."); def->cli = "support-material-buildplate-only!"; def->default_value = new ConfigOptionBool(false); def = this->add("support_material_contact_distance", coFloat); def->gui_type = "f_enum_open"; - def->label = "Contact Z distance"; - def->category = "Support material"; - def->tooltip = "The vertical distance between object and support material interface. " + def->label = _L("Contact Z distance"); + def->category = _L("Support material"); + def->tooltip = _L("The vertical distance between object and support material interface. " "Setting this to 0 will also prevent Slic3r from using bridge flow and speed " - "for the first object layer."; - def->sidetext = "mm"; + "for the first object layer."); + def->sidetext = _L("mm"); def->cli = "support-material-contact-distance=f"; def->min = 0; def->enum_values.push_back("0"); @@ -1421,86 +1431,86 @@ PrintConfigDef::PrintConfigDef() def->default_value = new ConfigOptionFloat(0.2); def = this->add("support_material_enforce_layers", coInt); - def->label = "Enforce support for the first"; - def->category = "Support material"; - def->tooltip = "Generate support material for the specified number of layers counting from bottom, " + def->label = _L("Enforce support for the first"); + def->category = _L("Support material"); + def->tooltip = _L("Generate support material for the specified number of layers counting from bottom, " "regardless of whether normal support material is enabled or not and regardless " "of any angle threshold. This is useful for getting more adhesion of objects " - "having a very thin or poor footprint on the build plate."; - def->sidetext = "layers"; + "having a very thin or poor footprint on the build plate."); + def->sidetext = _L("layers"); def->cli = "support-material-enforce-layers=f"; - def->full_label = "Enforce support for the first n layers"; + def->full_label = _L("Enforce support for the first n layers"); def->min = 0; def->default_value = new ConfigOptionInt(0); def = this->add("support_material_extruder", coInt); - def->label = "Support material/raft/skirt extruder"; - def->category = "Extruders"; - def->tooltip = "The extruder to use when printing support material, raft and skirt " - "(1+, 0 to use the current extruder to minimize tool changes)."; + def->label = _L("Support material/raft/skirt extruder"); + def->category = _L("Extruders"); + def->tooltip = _L("The extruder to use when printing support material, raft and skirt " + "(1+, 0 to use the current extruder to minimize tool changes)."); def->cli = "support-material-extruder=i"; def->min = 0; def->default_value = new ConfigOptionInt(1); def = this->add("support_material_extrusion_width", coFloatOrPercent); - def->label = "Support material"; - def->category = "Extrusion Width"; - def->tooltip = "Set this to a non-zero value to set a manual extrusion width for support material. " + def->label = _L("Support material"); + def->category = _L("Extrusion Width"); + def->tooltip = _L("Set this to a non-zero value to set a manual extrusion width for support material. " "If left zero, default extrusion width will be used if set, otherwise nozzle diameter will be used. " - "If expressed as percentage (for example 90%) it will be computed over layer height."; - def->sidetext = "mm or % (leave 0 for default)"; + "If expressed as percentage (for example 90%) it will be computed over layer height."); + def->sidetext = _L("mm or % (leave 0 for default)"); def->cli = "support-material-extrusion-width=s"; def->default_value = new ConfigOptionFloatOrPercent(0, false); def = this->add("support_material_interface_contact_loops", coBool); - def->label = "Interface loops"; - def->category = "Support material"; - def->tooltip = "Cover the top contact layer of the supports with loops. Disabled by default."; + def->label = _L("Interface loops"); + def->category = _L("Support material"); + def->tooltip = _L("Cover the top contact layer of the supports with loops. Disabled by default."); def->cli = "support-material-interface-contact-loops!"; def->default_value = new ConfigOptionBool(false); def = this->add("support_material_interface_extruder", coInt); - def->label = "Support material/raft interface extruder"; - def->category = "Extruders"; - def->tooltip = "The extruder to use when printing support material interface " - "(1+, 0 to use the current extruder to minimize tool changes). This affects raft too."; + def->label = _L("Support material/raft interface extruder"); + def->category = _L("Extruders"); + def->tooltip = _L("The extruder to use when printing support material interface " + "(1+, 0 to use the current extruder to minimize tool changes). This affects raft too."); def->cli = "support-material-interface-extruder=i"; def->min = 0; def->default_value = new ConfigOptionInt(1); def = this->add("support_material_interface_layers", coInt); - def->label = "Interface layers"; - def->category = "Support material"; - def->tooltip = "Number of interface layers to insert between the object(s) and support material."; - def->sidetext = "layers"; + def->label = _L("Interface layers"); + def->category = _L("Support material"); + def->tooltip = _L("Number of interface layers to insert between the object(s) and support material."); + def->sidetext = _L("layers"); def->cli = "support-material-interface-layers=i"; def->min = 0; def->default_value = new ConfigOptionInt(3); def = this->add("support_material_interface_spacing", coFloat); - def->label = "Interface pattern spacing"; - def->category = "Support material"; - def->tooltip = "Spacing between interface lines. Set zero to get a solid interface."; - def->sidetext = "mm"; + def->label = _L("Interface pattern spacing"); + def->category = _L("Support material"); + def->tooltip = _L("Spacing between interface lines. Set zero to get a solid interface."); + def->sidetext = _L("mm"); def->cli = "support-material-interface-spacing=f"; def->min = 0; def->default_value = new ConfigOptionFloat(0); def = this->add("support_material_interface_speed", coFloatOrPercent); - def->label = "Support material interface"; - def->category = "Support material"; - def->tooltip = "Speed for printing support material interface layers. If expressed as percentage " - "(for example 50%) it will be calculated over support material speed."; - def->sidetext = "mm/s or %"; + def->label = _L("Support material interface"); + def->category = _L("Support material"); + def->tooltip = _L("Speed for printing support material interface layers. If expressed as percentage " + "(for example 50%) it will be calculated over support material speed."); + def->sidetext = _L("mm/s or %"); def->cli = "support-material-interface-speed=s"; def->ratio_over = "support_material_speed"; def->min = 0; def->default_value = new ConfigOptionFloatOrPercent(100, true); def = this->add("support_material_pattern", coEnum); - def->label = "Pattern"; - def->category = "Support material"; - def->tooltip = "Pattern used to generate support material."; + def->label = _L("Pattern"); + def->category = _L("Support material"); + def->tooltip = _L("Pattern used to generate support material."); def->cli = "support-material-pattern=s"; def->enum_keys_map = &ConfigOptionEnum::get_enum_values(); def->enum_values.push_back("rectilinear"); @@ -1514,75 +1524,75 @@ PrintConfigDef::PrintConfigDef() def->default_value = new ConfigOptionEnum(smpPillars); def = this->add("support_material_spacing", coFloat); - def->label = "Pattern spacing"; - def->category = "Support material"; - def->tooltip = "Spacing between support material lines."; - def->sidetext = "mm"; + def->label = _L("Pattern spacing"); + def->category = _L("Support material"); + def->tooltip = _L("Spacing between support material lines."); + def->sidetext = _L("mm"); def->cli = "support-material-spacing=f"; def->min = 0; def->default_value = new ConfigOptionFloat(2.5); def = this->add("support_material_speed", coFloat); - def->label = "Support material"; - def->category = "Support material"; - def->tooltip = "Speed for printing support material."; - def->sidetext = "mm/s"; + def->label = _L("Support material"); + def->category = _L("Support material"); + def->tooltip = _L("Speed for printing support material."); + def->sidetext = _L("mm/s"); def->cli = "support-material-speed=f"; def->min = 0; def->default_value = new ConfigOptionFloat(60); def = this->add("support_material_synchronize_layers", coBool); - def->label = "Synchronize with object layers"; - def->category = "Support material"; - def->tooltip = "Synchronize support layers with the object print layers. This is useful " - "with multi-material printers, where the extruder switch is expensive."; + def->label = _L("Synchronize with object layers"); + def->category = _L("Support material"); + def->tooltip = _L("Synchronize support layers with the object print layers. This is useful " + "with multi-material printers, where the extruder switch is expensive."); def->cli = "support-material-synchronize-layers!"; def->default_value = new ConfigOptionBool(false); def = this->add("support_material_threshold", coInt); - def->label = "Overhang threshold"; - def->category = "Support material"; - def->tooltip = "Support material will not be generated for overhangs whose slope angle " - "(90° = vertical) is above the given threshold. In other words, this value " + def->label = _L("Overhang threshold"); + def->category = _L("Support material"); + def->tooltip = _L("Support material will not be generated for overhangs whose slope angle " + "(90\u00B0 = vertical) is above the given threshold. In other words, this value " "represent the most horizontal slope (measured from the horizontal plane) " "that you can print without support material. Set to zero for automatic detection " - "(recommended)."; - def->sidetext = "°"; + "(recommended)."); + def->sidetext = _L("\u00B0"); def->cli = "support-material-threshold=i"; def->min = 0; def->max = 90; def->default_value = new ConfigOptionInt(0); def = this->add("support_material_with_sheath", coBool); - def->label = "With sheath around the support"; - def->category = "Support material"; - def->tooltip = "Add a sheath (a single perimeter line) around the base support. This makes " - "the support more reliable, but also more difficult to remove."; + def->label = _L("With sheath around the support"); + def->category = _L("Support material"); + def->tooltip = _L("Add a sheath (a single perimeter line) around the base support. This makes " + "the support more reliable, but also more difficult to remove."); def->cli = "support-material-with-sheath!"; def->default_value = new ConfigOptionBool(true); def = this->add("temperature", coInts); - def->label = "Other layers"; - def->tooltip = "Extruder temperature for layers after the first one. Set this to zero to disable " - "temperature control commands in the output."; + def->label = _L("Other layers"); + def->tooltip = _L("Extruder temperature for layers after the first one. Set this to zero to disable " + "temperature control commands in the output."); def->cli = "temperature=i@"; - def->full_label = "Temperature"; + def->full_label = _L("Temperature"); def->max = 0; def->max = max_temp; def->default_value = new ConfigOptionInts { 200 }; def = this->add("thin_walls", coBool); - def->label = "Detect thin walls"; - def->category = "Layers and Perimeters"; - def->tooltip = "Detect single-width walls (parts where two extrusions don't fit and we need " - "to collapse them into a single trace)."; + def->label = _L("Detect thin walls"); + def->category = _L("Layers and Perimeters"); + def->tooltip = _L("Detect single-width walls (parts where two extrusions don't fit and we need " + "to collapse them into a single trace)."); def->cli = "thin-walls!"; def->default_value = new ConfigOptionBool(true); def = this->add("threads", coInt); - def->label = "Threads"; - def->tooltip = "Threads are used to parallelize long-running tasks. Optimal threads number " - "is slightly above the number of available cores/processors."; + def->label = _L("Threads"); + def->tooltip = _L("Threads are used to parallelize long-running tasks. Optimal threads number " + "is slightly above the number of available cores/processors."); def->cli = "threads|j=i"; def->readonly = true; def->min = 1; @@ -1592,10 +1602,10 @@ PrintConfigDef::PrintConfigDef() } def = this->add("toolchange_gcode", coString); - def->label = "Tool change G-code"; - def->tooltip = "This custom code is inserted right before every extruder change. " + def->label = _L("Tool change G-code"); + def->tooltip = _L("This custom code is inserted right before every extruder change. " "Note that you can use placeholder variables for all Slic3r settings as well " - "as [previous_extruder] and [next_extruder]."; + "as [previous_extruder] and [next_extruder]."); def->cli = "toolchange-gcode=s"; def->multiline = true; def->full_width = true; @@ -1603,141 +1613,141 @@ PrintConfigDef::PrintConfigDef() def->default_value = new ConfigOptionString(""); def = this->add("top_infill_extrusion_width", coFloatOrPercent); - def->label = "Top solid infill"; - def->category = "Extrusion Width"; - def->tooltip = "Set this to a non-zero value to set a manual extrusion width for infill for top surfaces. " + def->label = _L("Top solid infill"); + def->category = _L("Extrusion Width"); + def->tooltip = _L("Set this to a non-zero value to set a manual extrusion width for infill for top surfaces. " "You may want to use thinner extrudates to fill all narrow regions and get a smoother finish. " "If left zero, default extrusion width will be used if set, otherwise nozzle diameter will be used. " - "If expressed as percentage (for example 90%) it will be computed over layer height."; - def->sidetext = "mm or % (leave 0 for default)"; + "If expressed as percentage (for example 90%) it will be computed over layer height."); + def->sidetext = _L("mm or % (leave 0 for default)"); def->cli = "top-infill-extrusion-width=s"; def->default_value = new ConfigOptionFloatOrPercent(0, false); def = this->add("top_solid_infill_speed", coFloatOrPercent); - def->label = "Top solid infill"; - def->category = "Speed"; - def->tooltip = "Speed for printing top solid layers (it only applies to the uppermost " + def->label = _L("Top solid infill"); + def->category = _L("Speed"); + def->tooltip = _L("Speed for printing top solid layers (it only applies to the uppermost " "external layers and not to their internal solid layers). You may want " "to slow down this to get a nicer surface finish. This can be expressed " "as a percentage (for example: 80%) over the solid infill speed above. " - "Set to zero for auto."; - def->sidetext = "mm/s or %"; + "Set to zero for auto."); + def->sidetext = _L("mm/s or %"); def->cli = "top-solid-infill-speed=s"; def->ratio_over = "solid_infill_speed"; def->min = 0; def->default_value = new ConfigOptionFloatOrPercent(15, false); def = this->add("top_solid_layers", coInt); - def->label = "Top"; - def->category = "Layers and Perimeters"; - def->tooltip = "Number of solid layers to generate on top surfaces."; + def->label = _L("Top"); + def->category = _L("Layers and Perimeters"); + def->tooltip = _L("Number of solid layers to generate on top surfaces."); def->cli = "top-solid-layers=i"; - def->full_label = "Top solid layers"; + def->full_label = _L("Top solid layers"); def->min = 0; def->default_value = new ConfigOptionInt(3); def = this->add("travel_speed", coFloat); - def->label = "Travel"; - def->tooltip = "Speed for travel moves (jumps between distant extrusion points)."; - def->sidetext = "mm/s"; + def->label = _L("Travel"); + def->tooltip = _L("Speed for travel moves (jumps between distant extrusion points)."); + def->sidetext = _L("mm/s"); def->cli = "travel-speed=f"; def->aliases.push_back("travel_feed_rate"); def->min = 1; def->default_value = new ConfigOptionFloat(130); def = this->add("use_firmware_retraction", coBool); - def->label = "Use firmware retraction"; - def->tooltip = "This experimental setting uses G10 and G11 commands to have the firmware " - "handle the retraction. This is only supported in recent Marlin."; + def->label = _L("Use firmware retraction"); + def->tooltip = _L("This experimental setting uses G10 and G11 commands to have the firmware " + "handle the retraction. This is only supported in recent Marlin."); def->cli = "use-firmware-retraction!"; def->default_value = new ConfigOptionBool(false); def = this->add("use_relative_e_distances", coBool); - def->label = "Use relative E distances"; - def->tooltip = "If your firmware requires relative E values, check this, " - "otherwise leave it unchecked. Most firmwares use absolute values."; + def->label = _L("Use relative E distances"); + def->tooltip = _L("If your firmware requires relative E values, check this, " + "otherwise leave it unchecked. Most firmwares use absolute values."); def->cli = "use-relative-e-distances!"; def->default_value = new ConfigOptionBool(false); def = this->add("use_volumetric_e", coBool); - def->label = "Use volumetric E"; - def->tooltip = "This experimental setting uses outputs the E values in cubic millimeters " + def->label = _L("Use volumetric E"); + def->tooltip = _L("This experimental setting uses outputs the E values in cubic millimeters " "instead of linear millimeters. If your firmware doesn't already know " "filament diameter(s), you can put commands like 'M200 D[filament_diameter_0] T0' " "in your start G-code in order to turn volumetric mode on and use the filament " "diameter associated to the filament selected in Slic3r. This is only supported " - "in recent Marlin."; + "in recent Marlin."); def->cli = "use-volumetric-e!"; def->default_value = new ConfigOptionBool(false); def = this->add("variable_layer_height", coBool); - def->label = "Enable variable layer height feature"; - def->tooltip = "Some printers or printer setups may have difficulties printing " - "with a variable layer height. Enabled by default."; + def->label = _L("Enable variable layer height feature"); + def->tooltip = _L("Some printers or printer setups may have difficulties printing " + "with a variable layer height. Enabled by default."); def->cli = "variable-layer-height!"; def->default_value = new ConfigOptionBool(true); def = this->add("wipe", coBools); - def->label = "Wipe while retracting"; - def->tooltip = "This flag will move the nozzle while retracting to minimize the possible blob " - "on leaky extruders."; + def->label = _L("Wipe while retracting"); + def->tooltip = _L("This flag will move the nozzle while retracting to minimize the possible blob " + "on leaky extruders."); def->cli = "wipe!"; def->default_value = new ConfigOptionBools { false }; def = this->add("wipe_tower", coBool); - def->label = "Enable"; - def->tooltip = "Multi material printers may need to prime or purge extruders on tool changes. " - "Extrude the excess material into the wipe tower."; + def->label = _L("Enable"); + def->tooltip = _L("Multi material printers may need to prime or purge extruders on tool changes. " + "Extrude the excess material into the wipe tower."); def->cli = "wipe-tower!"; def->default_value = new ConfigOptionBool(false); def = this->add("wipe_tower_x", coFloat); - def->label = "Position X"; - def->tooltip = "X coordinate of the left front corner of a wipe tower"; - def->sidetext = "mm"; + def->label = _L("Position X"); + def->tooltip = _L("X coordinate of the left front corner of a wipe tower"); + def->sidetext = _L("mm"); def->cli = "wipe-tower-x=f"; def->default_value = new ConfigOptionFloat(180.); def = this->add("wipe_tower_y", coFloat); - def->label = "Position Y"; - def->tooltip = "Y coordinate of the left front corner of a wipe tower"; - def->sidetext = "mm"; + def->label = _L("Position Y"); + def->tooltip = _L("Y coordinate of the left front corner of a wipe tower"); + def->sidetext = _L("mm"); def->cli = "wipe-tower-y=f"; def->default_value = new ConfigOptionFloat(140.); def = this->add("wipe_tower_width", coFloat); - def->label = "Width"; - def->tooltip = "Width of a wipe tower"; - def->sidetext = "mm"; + def->label = _L("Width"); + def->tooltip = _L("Width of a wipe tower"); + def->sidetext = _L("mm"); def->cli = "wipe-tower-width=f"; def->default_value = new ConfigOptionFloat(60.); def = this->add("wipe_tower_per_color_wipe", coFloat); - def->label = "Per color change depth"; - def->tooltip = "Depth of a wipe color per color change. For N colors, there will be " + def->label = _L("Per color change depth"); + def->tooltip = _L("Depth of a wipe color per color change. For N colors, there will be " "maximum (N-1) tool switches performed, therefore the total depth " - "of the wipe tower will be (N-1) times this value."; - def->sidetext = "mm"; + "of the wipe tower will be (N-1) times this value."); + def->sidetext = _L("mm"); def->cli = "wipe-tower-per-color-wipe=f"; def->default_value = new ConfigOptionFloat(15.); def = this->add("xy_size_compensation", coFloat); - def->label = "XY Size Compensation"; - def->category = "Advanced"; - def->tooltip = "The object will be grown/shrunk in the XY plane by the configured value " + def->label = _L("XY Size Compensation"); + def->category = _L("Advanced"); + def->tooltip = _L("The object will be grown/shrunk in the XY plane by the configured value " "(negative = inwards, positive = outwards). This might be useful " - "for fine-tuning hole sizes."; - def->sidetext = "mm"; + "for fine-tuning hole sizes."); + def->sidetext = _L("mm"); def->cli = "xy-size-compensation=f"; def->default_value = new ConfigOptionFloat(0); def = this->add("z_offset", coFloat); - def->label = "Z offset"; - def->tooltip = "This value will be added (or subtracted) from all the Z coordinates " + def->label = _L("Z offset"); + def->tooltip = _L("This value will be added (or subtracted) from all the Z coordinates " "in the output G-code. It is used to compensate for bad Z endstop position: " "for example, if your endstop zero actually leaves the nozzle 0.3mm far " - "from the print bed, set this to -0.3 (or fix your endstop)."; - def->sidetext = "mm"; + "from the print bed, set this to -0.3 (or fix your endstop)."); + def->sidetext = _L("mm"); def->cli = "z-offset=f"; def->default_value = new ConfigOptionFloat(0); } diff --git a/xs/src/libslic3r/TriangleMesh.cpp b/xs/src/libslic3r/TriangleMesh.cpp index f5894d5e9..1cdfb091d 100644 --- a/xs/src/libslic3r/TriangleMesh.cpp +++ b/xs/src/libslic3r/TriangleMesh.cpp @@ -374,6 +374,15 @@ void TriangleMesh::mirror_z() this->mirror(Z); } +void TriangleMesh::transform(const float* matrix3x4) +{ + if (matrix3x4 == nullptr) + return; + + stl_transform(&stl, const_cast(matrix3x4)); + stl_invalidate_shared_vertices(&stl); +} + void TriangleMesh::align_to_origin() { this->translate( diff --git a/xs/src/libslic3r/TriangleMesh.hpp b/xs/src/libslic3r/TriangleMesh.hpp index b28f3a310..3192c90b6 100644 --- a/xs/src/libslic3r/TriangleMesh.hpp +++ b/xs/src/libslic3r/TriangleMesh.hpp @@ -47,6 +47,7 @@ public: void mirror_x(); void mirror_y(); void mirror_z(); + void transform(const float* matrix3x4); void align_to_origin(); void rotate(double angle, Point* center); TriangleMeshPtrs split() const; diff --git a/xs/src/libslic3r/Utils.hpp b/xs/src/libslic3r/Utils.hpp index fd60cf91a..27e7fad6b 100644 --- a/xs/src/libslic3r/Utils.hpp +++ b/xs/src/libslic3r/Utils.hpp @@ -20,6 +20,11 @@ void set_resources_dir(const std::string &path); // Return a full path to the resources directory. const std::string& resources_dir(); +// Set a path with GUI localization files. +void set_local_dir(const std::string &path); +// Return a full path to the localization directory. +const std::string& localization_dir(); + // Set a path with preset files. void set_data_dir(const std::string &path); // Return a full path to the GUI resource files. diff --git a/xs/src/libslic3r/utils.cpp b/xs/src/libslic3r/utils.cpp index 1a7e16f11..34b9eaa9f 100644 --- a/xs/src/libslic3r/utils.cpp +++ b/xs/src/libslic3r/utils.cpp @@ -103,6 +103,18 @@ const std::string& resources_dir() return g_resources_dir; } +static std::string g_local_dir; + +void set_local_dir(const std::string &dir) +{ + g_local_dir = dir; +} + +const std::string& localization_dir() +{ + return g_local_dir; +} + static std::string g_data_dir; void set_data_dir(const std::string &dir) diff --git a/xs/src/miniz/miniz.cpp b/xs/src/miniz/miniz.cpp new file mode 100644 index 000000000..318a86da9 --- /dev/null +++ b/xs/src/miniz/miniz.cpp @@ -0,0 +1,594 @@ +/************************************************************************** + * + * Copyright 2013-2014 RAD Game Tools and Valve Software + * Copyright 2010-2014 Rich Geldreich and Tenacious Software LLC + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + **************************************************************************/ + +#include "miniz.h" + +typedef unsigned char mz_validate_uint16[sizeof(mz_uint16) == 2 ? 1 : -1]; +typedef unsigned char mz_validate_uint32[sizeof(mz_uint32) == 4 ? 1 : -1]; +typedef unsigned char mz_validate_uint64[sizeof(mz_uint64) == 8 ? 1 : -1]; + +/* ------------------- zlib-style API's */ + +mz_ulong mz_adler32(mz_ulong adler, const unsigned char *ptr, size_t buf_len) +{ + mz_uint32 i, s1 = (mz_uint32)(adler & 0xffff), s2 = (mz_uint32)(adler >> 16); + size_t block_len = buf_len % 5552; + if (!ptr) + return MZ_ADLER32_INIT; + while (buf_len) + { + for (i = 0; i + 7 < block_len; i += 8, ptr += 8) + { + s1 += ptr[0], s2 += s1; + s1 += ptr[1], s2 += s1; + s1 += ptr[2], s2 += s1; + s1 += ptr[3], s2 += s1; + s1 += ptr[4], s2 += s1; + s1 += ptr[5], s2 += s1; + s1 += ptr[6], s2 += s1; + s1 += ptr[7], s2 += s1; + } + for (; i < block_len; ++i) + s1 += *ptr++, s2 += s1; + s1 %= 65521U, s2 %= 65521U; + buf_len -= block_len; + block_len = 5552; + } + return (s2 << 16) + s1; +} + +/* Karl Malbrain's compact CRC-32. See "A compact CCITT crc16 and crc32 C implementation that balances processor cache usage against speed": http://www.geocities.com/malbrain/ */ +#if 0 + mz_ulong mz_crc32(mz_ulong crc, const mz_uint8 *ptr, size_t buf_len) + { + static const mz_uint32 s_crc32[16] = { 0, 0x1db71064, 0x3b6e20c8, 0x26d930ac, 0x76dc4190, 0x6b6b51f4, 0x4db26158, 0x5005713c, + 0xedb88320, 0xf00f9344, 0xd6d6a3e8, 0xcb61b38c, 0x9b64c2b0, 0x86d3d2d4, 0xa00ae278, 0xbdbdf21c }; + mz_uint32 crcu32 = (mz_uint32)crc; + if (!ptr) + return MZ_CRC32_INIT; + crcu32 = ~crcu32; + while (buf_len--) + { + mz_uint8 b = *ptr++; + crcu32 = (crcu32 >> 4) ^ s_crc32[(crcu32 & 0xF) ^ (b & 0xF)]; + crcu32 = (crcu32 >> 4) ^ s_crc32[(crcu32 & 0xF) ^ (b >> 4)]; + } + return ~crcu32; + } +#else +/* Faster, but larger CPU cache footprint. + */ +mz_ulong mz_crc32(mz_ulong crc, const mz_uint8 *ptr, size_t buf_len) +{ + static const mz_uint32 s_crc_table[256] = + { + 0x00000000, 0x77073096, 0xEE0E612C, 0x990951BA, 0x076DC419, 0x706AF48F, 0xE963A535, + 0x9E6495A3, 0x0EDB8832, 0x79DCB8A4, 0xE0D5E91E, 0x97D2D988, 0x09B64C2B, 0x7EB17CBD, + 0xE7B82D07, 0x90BF1D91, 0x1DB71064, 0x6AB020F2, 0xF3B97148, 0x84BE41DE, 0x1ADAD47D, + 0x6DDDE4EB, 0xF4D4B551, 0x83D385C7, 0x136C9856, 0x646BA8C0, 0xFD62F97A, 0x8A65C9EC, + 0x14015C4F, 0x63066CD9, 0xFA0F3D63, 0x8D080DF5, 0x3B6E20C8, 0x4C69105E, 0xD56041E4, + 0xA2677172, 0x3C03E4D1, 0x4B04D447, 0xD20D85FD, 0xA50AB56B, 0x35B5A8FA, 0x42B2986C, + 0xDBBBC9D6, 0xACBCF940, 0x32D86CE3, 0x45DF5C75, 0xDCD60DCF, 0xABD13D59, 0x26D930AC, + 0x51DE003A, 0xC8D75180, 0xBFD06116, 0x21B4F4B5, 0x56B3C423, 0xCFBA9599, 0xB8BDA50F, + 0x2802B89E, 0x5F058808, 0xC60CD9B2, 0xB10BE924, 0x2F6F7C87, 0x58684C11, 0xC1611DAB, + 0xB6662D3D, 0x76DC4190, 0x01DB7106, 0x98D220BC, 0xEFD5102A, 0x71B18589, 0x06B6B51F, + 0x9FBFE4A5, 0xE8B8D433, 0x7807C9A2, 0x0F00F934, 0x9609A88E, 0xE10E9818, 0x7F6A0DBB, + 0x086D3D2D, 0x91646C97, 0xE6635C01, 0x6B6B51F4, 0x1C6C6162, 0x856530D8, 0xF262004E, + 0x6C0695ED, 0x1B01A57B, 0x8208F4C1, 0xF50FC457, 0x65B0D9C6, 0x12B7E950, 0x8BBEB8EA, + 0xFCB9887C, 0x62DD1DDF, 0x15DA2D49, 0x8CD37CF3, 0xFBD44C65, 0x4DB26158, 0x3AB551CE, + 0xA3BC0074, 0xD4BB30E2, 0x4ADFA541, 0x3DD895D7, 0xA4D1C46D, 0xD3D6F4FB, 0x4369E96A, + 0x346ED9FC, 0xAD678846, 0xDA60B8D0, 0x44042D73, 0x33031DE5, 0xAA0A4C5F, 0xDD0D7CC9, + 0x5005713C, 0x270241AA, 0xBE0B1010, 0xC90C2086, 0x5768B525, 0x206F85B3, 0xB966D409, + 0xCE61E49F, 0x5EDEF90E, 0x29D9C998, 0xB0D09822, 0xC7D7A8B4, 0x59B33D17, 0x2EB40D81, + 0xB7BD5C3B, 0xC0BA6CAD, 0xEDB88320, 0x9ABFB3B6, 0x03B6E20C, 0x74B1D29A, 0xEAD54739, + 0x9DD277AF, 0x04DB2615, 0x73DC1683, 0xE3630B12, 0x94643B84, 0x0D6D6A3E, 0x7A6A5AA8, + 0xE40ECF0B, 0x9309FF9D, 0x0A00AE27, 0x7D079EB1, 0xF00F9344, 0x8708A3D2, 0x1E01F268, + 0x6906C2FE, 0xF762575D, 0x806567CB, 0x196C3671, 0x6E6B06E7, 0xFED41B76, 0x89D32BE0, + 0x10DA7A5A, 0x67DD4ACC, 0xF9B9DF6F, 0x8EBEEFF9, 0x17B7BE43, 0x60B08ED5, 0xD6D6A3E8, + 0xA1D1937E, 0x38D8C2C4, 0x4FDFF252, 0xD1BB67F1, 0xA6BC5767, 0x3FB506DD, 0x48B2364B, + 0xD80D2BDA, 0xAF0A1B4C, 0x36034AF6, 0x41047A60, 0xDF60EFC3, 0xA867DF55, 0x316E8EEF, + 0x4669BE79, 0xCB61B38C, 0xBC66831A, 0x256FD2A0, 0x5268E236, 0xCC0C7795, 0xBB0B4703, + 0x220216B9, 0x5505262F, 0xC5BA3BBE, 0xB2BD0B28, 0x2BB45A92, 0x5CB36A04, 0xC2D7FFA7, + 0xB5D0CF31, 0x2CD99E8B, 0x5BDEAE1D, 0x9B64C2B0, 0xEC63F226, 0x756AA39C, 0x026D930A, + 0x9C0906A9, 0xEB0E363F, 0x72076785, 0x05005713, 0x95BF4A82, 0xE2B87A14, 0x7BB12BAE, + 0x0CB61B38, 0x92D28E9B, 0xE5D5BE0D, 0x7CDCEFB7, 0x0BDBDF21, 0x86D3D2D4, 0xF1D4E242, + 0x68DDB3F8, 0x1FDA836E, 0x81BE16CD, 0xF6B9265B, 0x6FB077E1, 0x18B74777, 0x88085AE6, + 0xFF0F6A70, 0x66063BCA, 0x11010B5C, 0x8F659EFF, 0xF862AE69, 0x616BFFD3, 0x166CCF45, + 0xA00AE278, 0xD70DD2EE, 0x4E048354, 0x3903B3C2, 0xA7672661, 0xD06016F7, 0x4969474D, + 0x3E6E77DB, 0xAED16A4A, 0xD9D65ADC, 0x40DF0B66, 0x37D83BF0, 0xA9BCAE53, 0xDEBB9EC5, + 0x47B2CF7F, 0x30B5FFE9, 0xBDBDF21C, 0xCABAC28A, 0x53B39330, 0x24B4A3A6, 0xBAD03605, + 0xCDD70693, 0x54DE5729, 0x23D967BF, 0xB3667A2E, 0xC4614AB8, 0x5D681B02, 0x2A6F2B94, + 0xB40BBE37, 0xC30C8EA1, 0x5A05DF1B, 0x2D02EF8D + }; + + mz_uint32 crc32 = (mz_uint32)crc ^ 0xFFFFFFFF; + const mz_uint8 *pByte_buf = (const mz_uint8 *)ptr; + + while (buf_len >= 4) + { + crc32 = (crc32 >> 8) ^ s_crc_table[(crc32 ^ pByte_buf[0]) & 0xFF]; + crc32 = (crc32 >> 8) ^ s_crc_table[(crc32 ^ pByte_buf[1]) & 0xFF]; + crc32 = (crc32 >> 8) ^ s_crc_table[(crc32 ^ pByte_buf[2]) & 0xFF]; + crc32 = (crc32 >> 8) ^ s_crc_table[(crc32 ^ pByte_buf[3]) & 0xFF]; + pByte_buf += 4; + buf_len -= 4; + } + + while (buf_len) + { + crc32 = (crc32 >> 8) ^ s_crc_table[(crc32 ^ pByte_buf[0]) & 0xFF]; + ++pByte_buf; + --buf_len; + } + + return ~crc32; +} +#endif + +void mz_free(void *p) +{ + MZ_FREE(p); +} + +void *miniz_def_alloc_func(void *opaque, size_t items, size_t size) +{ + (void)opaque, (void)items, (void)size; + return MZ_MALLOC(items * size); +} +void miniz_def_free_func(void *opaque, void *address) +{ + (void)opaque, (void)address; + MZ_FREE(address); +} +void *miniz_def_realloc_func(void *opaque, void *address, size_t items, size_t size) +{ + (void)opaque, (void)address, (void)items, (void)size; + return MZ_REALLOC(address, items * size); +} + +const char *mz_version(void) +{ + return MZ_VERSION; +} + +#ifndef MINIZ_NO_ZLIB_APIS + +int mz_deflateInit(mz_streamp pStream, int level) +{ + return mz_deflateInit2(pStream, level, MZ_DEFLATED, MZ_DEFAULT_WINDOW_BITS, 9, MZ_DEFAULT_STRATEGY); +} + +int mz_deflateInit2(mz_streamp pStream, int level, int method, int window_bits, int mem_level, int strategy) +{ + tdefl_compressor *pComp; + mz_uint comp_flags = TDEFL_COMPUTE_ADLER32 | tdefl_create_comp_flags_from_zip_params(level, window_bits, strategy); + + if (!pStream) + return MZ_STREAM_ERROR; + if ((method != MZ_DEFLATED) || ((mem_level < 1) || (mem_level > 9)) || ((window_bits != MZ_DEFAULT_WINDOW_BITS) && (-window_bits != MZ_DEFAULT_WINDOW_BITS))) + return MZ_PARAM_ERROR; + + pStream->data_type = 0; + pStream->adler = MZ_ADLER32_INIT; + pStream->msg = NULL; + pStream->reserved = 0; + pStream->total_in = 0; + pStream->total_out = 0; + if (!pStream->zalloc) + pStream->zalloc = miniz_def_alloc_func; + if (!pStream->zfree) + pStream->zfree = miniz_def_free_func; + + pComp = (tdefl_compressor *)pStream->zalloc(pStream->opaque, 1, sizeof(tdefl_compressor)); + if (!pComp) + return MZ_MEM_ERROR; + + pStream->state = (struct mz_internal_state *)pComp; + + if (tdefl_init(pComp, NULL, NULL, comp_flags) != TDEFL_STATUS_OKAY) + { + mz_deflateEnd(pStream); + return MZ_PARAM_ERROR; + } + + return MZ_OK; +} + +int mz_deflateReset(mz_streamp pStream) +{ + if ((!pStream) || (!pStream->state) || (!pStream->zalloc) || (!pStream->zfree)) + return MZ_STREAM_ERROR; + pStream->total_in = pStream->total_out = 0; + tdefl_init((tdefl_compressor *)pStream->state, NULL, NULL, ((tdefl_compressor *)pStream->state)->m_flags); + return MZ_OK; +} + +int mz_deflate(mz_streamp pStream, int flush) +{ + size_t in_bytes, out_bytes; + mz_ulong orig_total_in, orig_total_out; + int mz_status = MZ_OK; + + if ((!pStream) || (!pStream->state) || (flush < 0) || (flush > MZ_FINISH) || (!pStream->next_out)) + return MZ_STREAM_ERROR; + if (!pStream->avail_out) + return MZ_BUF_ERROR; + + if (flush == MZ_PARTIAL_FLUSH) + flush = MZ_SYNC_FLUSH; + + if (((tdefl_compressor *)pStream->state)->m_prev_return_status == TDEFL_STATUS_DONE) + return (flush == MZ_FINISH) ? MZ_STREAM_END : MZ_BUF_ERROR; + + orig_total_in = pStream->total_in; + orig_total_out = pStream->total_out; + for (;;) + { + tdefl_status defl_status; + in_bytes = pStream->avail_in; + out_bytes = pStream->avail_out; + + defl_status = tdefl_compress((tdefl_compressor *)pStream->state, pStream->next_in, &in_bytes, pStream->next_out, &out_bytes, (tdefl_flush)flush); + pStream->next_in += (mz_uint)in_bytes; + pStream->avail_in -= (mz_uint)in_bytes; + pStream->total_in += (mz_uint)in_bytes; + pStream->adler = tdefl_get_adler32((tdefl_compressor *)pStream->state); + + pStream->next_out += (mz_uint)out_bytes; + pStream->avail_out -= (mz_uint)out_bytes; + pStream->total_out += (mz_uint)out_bytes; + + if (defl_status < 0) + { + mz_status = MZ_STREAM_ERROR; + break; + } + else if (defl_status == TDEFL_STATUS_DONE) + { + mz_status = MZ_STREAM_END; + break; + } + else if (!pStream->avail_out) + break; + else if ((!pStream->avail_in) && (flush != MZ_FINISH)) + { + if ((flush) || (pStream->total_in != orig_total_in) || (pStream->total_out != orig_total_out)) + break; + return MZ_BUF_ERROR; /* Can't make forward progress without some input. + */ + } + } + return mz_status; +} + +int mz_deflateEnd(mz_streamp pStream) +{ + if (!pStream) + return MZ_STREAM_ERROR; + if (pStream->state) + { + pStream->zfree(pStream->opaque, pStream->state); + pStream->state = NULL; + } + return MZ_OK; +} + +mz_ulong mz_deflateBound(mz_streamp pStream, mz_ulong source_len) +{ + (void)pStream; + /* This is really over conservative. (And lame, but it's actually pretty tricky to compute a true upper bound given the way tdefl's blocking works.) */ + return MZ_MAX(128 + (source_len * 110) / 100, 128 + source_len + ((source_len / (31 * 1024)) + 1) * 5); +} + +int mz_compress2(unsigned char *pDest, mz_ulong *pDest_len, const unsigned char *pSource, mz_ulong source_len, int level) +{ + int status; + mz_stream stream; + memset(&stream, 0, sizeof(stream)); + + /* In case mz_ulong is 64-bits (argh I hate longs). */ + if ((source_len | *pDest_len) > 0xFFFFFFFFU) + return MZ_PARAM_ERROR; + + stream.next_in = pSource; + stream.avail_in = (mz_uint32)source_len; + stream.next_out = pDest; + stream.avail_out = (mz_uint32)*pDest_len; + + status = mz_deflateInit(&stream, level); + if (status != MZ_OK) + return status; + + status = mz_deflate(&stream, MZ_FINISH); + if (status != MZ_STREAM_END) + { + mz_deflateEnd(&stream); + return (status == MZ_OK) ? MZ_BUF_ERROR : status; + } + + *pDest_len = stream.total_out; + return mz_deflateEnd(&stream); +} + +int mz_compress(unsigned char *pDest, mz_ulong *pDest_len, const unsigned char *pSource, mz_ulong source_len) +{ + return mz_compress2(pDest, pDest_len, pSource, source_len, MZ_DEFAULT_COMPRESSION); +} + +mz_ulong mz_compressBound(mz_ulong source_len) +{ + return mz_deflateBound(NULL, source_len); +} + +typedef struct +{ + tinfl_decompressor m_decomp; + mz_uint m_dict_ofs, m_dict_avail, m_first_call, m_has_flushed; + int m_window_bits; + mz_uint8 m_dict[TINFL_LZ_DICT_SIZE]; + tinfl_status m_last_status; +} inflate_state; + +int mz_inflateInit2(mz_streamp pStream, int window_bits) +{ + inflate_state *pDecomp; + if (!pStream) + return MZ_STREAM_ERROR; + if ((window_bits != MZ_DEFAULT_WINDOW_BITS) && (-window_bits != MZ_DEFAULT_WINDOW_BITS)) + return MZ_PARAM_ERROR; + + pStream->data_type = 0; + pStream->adler = 0; + pStream->msg = NULL; + pStream->total_in = 0; + pStream->total_out = 0; + pStream->reserved = 0; + if (!pStream->zalloc) + pStream->zalloc = miniz_def_alloc_func; + if (!pStream->zfree) + pStream->zfree = miniz_def_free_func; + + pDecomp = (inflate_state *)pStream->zalloc(pStream->opaque, 1, sizeof(inflate_state)); + if (!pDecomp) + return MZ_MEM_ERROR; + + pStream->state = (struct mz_internal_state *)pDecomp; + + tinfl_init(&pDecomp->m_decomp); + pDecomp->m_dict_ofs = 0; + pDecomp->m_dict_avail = 0; + pDecomp->m_last_status = TINFL_STATUS_NEEDS_MORE_INPUT; + pDecomp->m_first_call = 1; + pDecomp->m_has_flushed = 0; + pDecomp->m_window_bits = window_bits; + + return MZ_OK; +} + +int mz_inflateInit(mz_streamp pStream) +{ + return mz_inflateInit2(pStream, MZ_DEFAULT_WINDOW_BITS); +} + +int mz_inflate(mz_streamp pStream, int flush) +{ + inflate_state *pState; + mz_uint n, first_call, decomp_flags = TINFL_FLAG_COMPUTE_ADLER32; + size_t in_bytes, out_bytes, orig_avail_in; + tinfl_status status; + + if ((!pStream) || (!pStream->state)) + return MZ_STREAM_ERROR; + if (flush == MZ_PARTIAL_FLUSH) + flush = MZ_SYNC_FLUSH; + if ((flush) && (flush != MZ_SYNC_FLUSH) && (flush != MZ_FINISH)) + return MZ_STREAM_ERROR; + + pState = (inflate_state *)pStream->state; + if (pState->m_window_bits > 0) + decomp_flags |= TINFL_FLAG_PARSE_ZLIB_HEADER; + orig_avail_in = pStream->avail_in; + + first_call = pState->m_first_call; + pState->m_first_call = 0; + if (pState->m_last_status < 0) + return MZ_DATA_ERROR; + + if (pState->m_has_flushed && (flush != MZ_FINISH)) + return MZ_STREAM_ERROR; + pState->m_has_flushed |= (flush == MZ_FINISH); + + if ((flush == MZ_FINISH) && (first_call)) + { + /* MZ_FINISH on the first call implies that the input and output buffers are large enough to hold the entire compressed/decompressed file. */ + decomp_flags |= TINFL_FLAG_USING_NON_WRAPPING_OUTPUT_BUF; + in_bytes = pStream->avail_in; + out_bytes = pStream->avail_out; + status = tinfl_decompress(&pState->m_decomp, pStream->next_in, &in_bytes, pStream->next_out, pStream->next_out, &out_bytes, decomp_flags); + pState->m_last_status = status; + pStream->next_in += (mz_uint)in_bytes; + pStream->avail_in -= (mz_uint)in_bytes; + pStream->total_in += (mz_uint)in_bytes; + pStream->adler = tinfl_get_adler32(&pState->m_decomp); + pStream->next_out += (mz_uint)out_bytes; + pStream->avail_out -= (mz_uint)out_bytes; + pStream->total_out += (mz_uint)out_bytes; + + if (status < 0) + return MZ_DATA_ERROR; + else if (status != TINFL_STATUS_DONE) + { + pState->m_last_status = TINFL_STATUS_FAILED; + return MZ_BUF_ERROR; + } + return MZ_STREAM_END; + } + /* flush != MZ_FINISH then we must assume there's more input. */ + if (flush != MZ_FINISH) + decomp_flags |= TINFL_FLAG_HAS_MORE_INPUT; + + if (pState->m_dict_avail) + { + n = MZ_MIN(pState->m_dict_avail, pStream->avail_out); + memcpy(pStream->next_out, pState->m_dict + pState->m_dict_ofs, n); + pStream->next_out += n; + pStream->avail_out -= n; + pStream->total_out += n; + pState->m_dict_avail -= n; + pState->m_dict_ofs = (pState->m_dict_ofs + n) & (TINFL_LZ_DICT_SIZE - 1); + return ((pState->m_last_status == TINFL_STATUS_DONE) && (!pState->m_dict_avail)) ? MZ_STREAM_END : MZ_OK; + } + + for (;;) + { + in_bytes = pStream->avail_in; + out_bytes = TINFL_LZ_DICT_SIZE - pState->m_dict_ofs; + + status = tinfl_decompress(&pState->m_decomp, pStream->next_in, &in_bytes, pState->m_dict, pState->m_dict + pState->m_dict_ofs, &out_bytes, decomp_flags); + pState->m_last_status = status; + + pStream->next_in += (mz_uint)in_bytes; + pStream->avail_in -= (mz_uint)in_bytes; + pStream->total_in += (mz_uint)in_bytes; + pStream->adler = tinfl_get_adler32(&pState->m_decomp); + + pState->m_dict_avail = (mz_uint)out_bytes; + + n = MZ_MIN(pState->m_dict_avail, pStream->avail_out); + memcpy(pStream->next_out, pState->m_dict + pState->m_dict_ofs, n); + pStream->next_out += n; + pStream->avail_out -= n; + pStream->total_out += n; + pState->m_dict_avail -= n; + pState->m_dict_ofs = (pState->m_dict_ofs + n) & (TINFL_LZ_DICT_SIZE - 1); + + if (status < 0) + return MZ_DATA_ERROR; /* Stream is corrupted (there could be some uncompressed data left in the output dictionary - oh well). */ + else if ((status == TINFL_STATUS_NEEDS_MORE_INPUT) && (!orig_avail_in)) + return MZ_BUF_ERROR; /* Signal caller that we can't make forward progress without supplying more input or by setting flush to MZ_FINISH. */ + else if (flush == MZ_FINISH) + { + /* The output buffer MUST be large to hold the remaining uncompressed data when flush==MZ_FINISH. */ + if (status == TINFL_STATUS_DONE) + return pState->m_dict_avail ? MZ_BUF_ERROR : MZ_STREAM_END; + /* status here must be TINFL_STATUS_HAS_MORE_OUTPUT, which means there's at least 1 more byte on the way. If there's no more room left in the output buffer then something is wrong. */ + else if (!pStream->avail_out) + return MZ_BUF_ERROR; + } + else if ((status == TINFL_STATUS_DONE) || (!pStream->avail_in) || (!pStream->avail_out) || (pState->m_dict_avail)) + break; + } + + return ((status == TINFL_STATUS_DONE) && (!pState->m_dict_avail)) ? MZ_STREAM_END : MZ_OK; +} + +int mz_inflateEnd(mz_streamp pStream) +{ + if (!pStream) + return MZ_STREAM_ERROR; + if (pStream->state) + { + pStream->zfree(pStream->opaque, pStream->state); + pStream->state = NULL; + } + return MZ_OK; +} + +int mz_uncompress(unsigned char *pDest, mz_ulong *pDest_len, const unsigned char *pSource, mz_ulong source_len) +{ + mz_stream stream; + int status; + memset(&stream, 0, sizeof(stream)); + + /* In case mz_ulong is 64-bits (argh I hate longs). */ + if ((source_len | *pDest_len) > 0xFFFFFFFFU) + return MZ_PARAM_ERROR; + + stream.next_in = pSource; + stream.avail_in = (mz_uint32)source_len; + stream.next_out = pDest; + stream.avail_out = (mz_uint32)*pDest_len; + + status = mz_inflateInit(&stream); + if (status != MZ_OK) + return status; + + status = mz_inflate(&stream, MZ_FINISH); + if (status != MZ_STREAM_END) + { + mz_inflateEnd(&stream); + return ((status == MZ_BUF_ERROR) && (!stream.avail_in)) ? MZ_DATA_ERROR : status; + } + *pDest_len = stream.total_out; + + return mz_inflateEnd(&stream); +} + +const char *mz_error(int err) +{ + static struct + { + int m_err; + const char *m_pDesc; + } s_error_descs[] = + { + { MZ_OK, "" }, { MZ_STREAM_END, "stream end" }, { MZ_NEED_DICT, "need dictionary" }, { MZ_ERRNO, "file error" }, { MZ_STREAM_ERROR, "stream error" }, { MZ_DATA_ERROR, "data error" }, { MZ_MEM_ERROR, "out of memory" }, { MZ_BUF_ERROR, "buf error" }, { MZ_VERSION_ERROR, "version error" }, { MZ_PARAM_ERROR, "parameter error" } + }; + mz_uint i; + for (i = 0; i < sizeof(s_error_descs) / sizeof(s_error_descs[0]); ++i) + if (s_error_descs[i].m_err == err) + return s_error_descs[i].m_pDesc; + return NULL; +} + +#endif /*MINIZ_NO_ZLIB_APIS */ + +/* + This is free and unencumbered software released into the public domain. + + Anyone is free to copy, modify, publish, use, compile, sell, or + distribute this software, either in source code form or as a compiled + binary, for any purpose, commercial or non-commercial, and by any + means. + + In jurisdictions that recognize copyright laws, the author or authors + of this software dedicate any and all copyright interest in the + software to the public domain. We make this dedication for the benefit + of the public at large and to the detriment of our heirs and + successors. We intend this dedication to be an overt act of + relinquishment in perpetuity of all present and future rights to this + software under copyright law. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR + OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + OTHER DEALINGS IN THE SOFTWARE. + + For more information, please refer to +*/ diff --git a/xs/src/miniz/miniz.h b/xs/src/miniz/miniz.h new file mode 100644 index 000000000..6e7d5fde0 --- /dev/null +++ b/xs/src/miniz/miniz.h @@ -0,0 +1,462 @@ +/* miniz.c 2.0.6 beta - public domain deflate/inflate, zlib-subset, ZIP reading/writing/appending, PNG writing + See "unlicense" statement at the end of this file. + Rich Geldreich , last updated Oct. 13, 2013 + Implements RFC 1950: http://www.ietf.org/rfc/rfc1950.txt and RFC 1951: http://www.ietf.org/rfc/rfc1951.txt + + Most API's defined in miniz.c are optional. For example, to disable the archive related functions just define + MINIZ_NO_ARCHIVE_APIS, or to get rid of all stdio usage define MINIZ_NO_STDIO (see the list below for more macros). + + * Low-level Deflate/Inflate implementation notes: + + Compression: Use the "tdefl" API's. The compressor supports raw, static, and dynamic blocks, lazy or + greedy parsing, match length filtering, RLE-only, and Huffman-only streams. It performs and compresses + approximately as well as zlib. + + Decompression: Use the "tinfl" API's. The entire decompressor is implemented as a single function + coroutine: see tinfl_decompress(). It supports decompression into a 32KB (or larger power of 2) wrapping buffer, or into a memory + block large enough to hold the entire file. + + The low-level tdefl/tinfl API's do not make any use of dynamic memory allocation. + + * zlib-style API notes: + + miniz.c implements a fairly large subset of zlib. There's enough functionality present for it to be a drop-in + zlib replacement in many apps: + The z_stream struct, optional memory allocation callbacks + deflateInit/deflateInit2/deflate/deflateReset/deflateEnd/deflateBound + inflateInit/inflateInit2/inflate/inflateEnd + compress, compress2, compressBound, uncompress + CRC-32, Adler-32 - Using modern, minimal code size, CPU cache friendly routines. + Supports raw deflate streams or standard zlib streams with adler-32 checking. + + Limitations: + The callback API's are not implemented yet. No support for gzip headers or zlib static dictionaries. + I've tried to closely emulate zlib's various flavors of stream flushing and return status codes, but + there are no guarantees that miniz.c pulls this off perfectly. + + * PNG writing: See the tdefl_write_image_to_png_file_in_memory() function, originally written by + Alex Evans. Supports 1-4 bytes/pixel images. + + * ZIP archive API notes: + + The ZIP archive API's where designed with simplicity and efficiency in mind, with just enough abstraction to + get the job done with minimal fuss. There are simple API's to retrieve file information, read files from + existing archives, create new archives, append new files to existing archives, or clone archive data from + one archive to another. It supports archives located in memory or the heap, on disk (using stdio.h), + or you can specify custom file read/write callbacks. + + - Archive reading: Just call this function to read a single file from a disk archive: + + void *mz_zip_extract_archive_file_to_heap(const char *pZip_filename, const char *pArchive_name, + size_t *pSize, mz_uint zip_flags); + + For more complex cases, use the "mz_zip_reader" functions. Upon opening an archive, the entire central + directory is located and read as-is into memory, and subsequent file access only occurs when reading individual files. + + - Archives file scanning: The simple way is to use this function to scan a loaded archive for a specific file: + + int mz_zip_reader_locate_file(mz_zip_archive *pZip, const char *pName, const char *pComment, mz_uint flags); + + The locate operation can optionally check file comments too, which (as one example) can be used to identify + multiple versions of the same file in an archive. This function uses a simple linear search through the central + directory, so it's not very fast. + + Alternately, you can iterate through all the files in an archive (using mz_zip_reader_get_num_files()) and + retrieve detailed info on each file by calling mz_zip_reader_file_stat(). + + - Archive creation: Use the "mz_zip_writer" functions. The ZIP writer immediately writes compressed file data + to disk and builds an exact image of the central directory in memory. The central directory image is written + all at once at the end of the archive file when the archive is finalized. + + The archive writer can optionally align each file's local header and file data to any power of 2 alignment, + which can be useful when the archive will be read from optical media. Also, the writer supports placing + arbitrary data blobs at the very beginning of ZIP archives. Archives written using either feature are still + readable by any ZIP tool. + + - Archive appending: The simple way to add a single file to an archive is to call this function: + + mz_bool mz_zip_add_mem_to_archive_file_in_place(const char *pZip_filename, const char *pArchive_name, + const void *pBuf, size_t buf_size, const void *pComment, mz_uint16 comment_size, mz_uint level_and_flags); + + The archive will be created if it doesn't already exist, otherwise it'll be appended to. + Note the appending is done in-place and is not an atomic operation, so if something goes wrong + during the operation it's possible the archive could be left without a central directory (although the local + file headers and file data will be fine, so the archive will be recoverable). + + For more complex archive modification scenarios: + 1. The safest way is to use a mz_zip_reader to read the existing archive, cloning only those bits you want to + preserve into a new archive using using the mz_zip_writer_add_from_zip_reader() function (which compiles the + compressed file data as-is). When you're done, delete the old archive and rename the newly written archive, and + you're done. This is safe but requires a bunch of temporary disk space or heap memory. + + 2. Or, you can convert an mz_zip_reader in-place to an mz_zip_writer using mz_zip_writer_init_from_reader(), + append new files as needed, then finalize the archive which will write an updated central directory to the + original archive. (This is basically what mz_zip_add_mem_to_archive_file_in_place() does.) There's a + possibility that the archive's central directory could be lost with this method if anything goes wrong, though. + + - ZIP archive support limitations: + No zip64 or spanning support. Extraction functions can only handle unencrypted, stored or deflated files. + Requires streams capable of seeking. + + * This is a header file library, like stb_image.c. To get only a header file, either cut and paste the + below header, or create miniz.h, #define MINIZ_HEADER_FILE_ONLY, and then include miniz.c from it. + + * Important: For best perf. be sure to customize the below macros for your target platform: + #define MINIZ_USE_UNALIGNED_LOADS_AND_STORES 1 + #define MINIZ_LITTLE_ENDIAN 1 + #define MINIZ_HAS_64BIT_REGISTERS 1 + + * On platforms using glibc, Be sure to "#define _LARGEFILE64_SOURCE 1" before including miniz.c to ensure miniz + uses the 64-bit variants: fopen64(), stat64(), etc. Otherwise you won't be able to process large files + (i.e. 32-bit stat() fails for me on files > 0x7FFFFFFF bytes). +*/ +#pragma once + +#include "miniz_common.h" +#include "miniz_tdef.h" +#include "miniz_tinfl.h" + +/* Defines to completely disable specific portions of miniz.c: + If all macros here are defined the only functionality remaining will be CRC-32, adler-32, tinfl, and tdefl. */ + +/* Define MINIZ_NO_STDIO to disable all usage and any functions which rely on stdio for file I/O. */ +/*#define MINIZ_NO_STDIO */ + +/* If MINIZ_NO_TIME is specified then the ZIP archive functions will not be able to get the current time, or */ +/* get/set file times, and the C run-time funcs that get/set times won't be called. */ +/* The current downside is the times written to your archives will be from 1979. */ +/*#define MINIZ_NO_TIME */ + +/* Define MINIZ_NO_ARCHIVE_APIS to disable all ZIP archive API's. */ +/*#define MINIZ_NO_ARCHIVE_APIS */ + +/* Define MINIZ_NO_ARCHIVE_WRITING_APIS to disable all writing related ZIP archive API's. */ +/*#define MINIZ_NO_ARCHIVE_WRITING_APIS */ + +/* Define MINIZ_NO_ZLIB_APIS to remove all ZLIB-style compression/decompression API's. */ +/*#define MINIZ_NO_ZLIB_APIS */ + +/* Define MINIZ_NO_ZLIB_COMPATIBLE_NAME to disable zlib names, to prevent conflicts against stock zlib. */ +/*#define MINIZ_NO_ZLIB_COMPATIBLE_NAMES */ + +/* Define MINIZ_NO_MALLOC to disable all calls to malloc, free, and realloc. + Note if MINIZ_NO_MALLOC is defined then the user must always provide custom user alloc/free/realloc + callbacks to the zlib and archive API's, and a few stand-alone helper API's which don't provide custom user + functions (such as tdefl_compress_mem_to_heap() and tinfl_decompress_mem_to_heap()) won't work. */ +/*#define MINIZ_NO_MALLOC */ + +#if defined(__TINYC__) && (defined(__linux) || defined(__linux__)) +/* TODO: Work around "error: include file 'sys\utime.h' when compiling with tcc on Linux */ +#define MINIZ_NO_TIME +#endif + +#include + +#if !defined(MINIZ_NO_TIME) && !defined(MINIZ_NO_ARCHIVE_APIS) +#include +#endif + +#if defined(_M_IX86) || defined(_M_X64) || defined(__i386__) || defined(__i386) || defined(__i486__) || defined(__i486) || defined(i386) || defined(__ia64__) || defined(__x86_64__) +/* MINIZ_X86_OR_X64_CPU is only used to help set the below macros. */ +#define MINIZ_X86_OR_X64_CPU 1 +#else +#define MINIZ_X86_OR_X64_CPU 0 +#endif + +#if (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__) || MINIZ_X86_OR_X64_CPU +/* Set MINIZ_LITTLE_ENDIAN to 1 if the processor is little endian. */ +#define MINIZ_LITTLE_ENDIAN 1 +#else +#define MINIZ_LITTLE_ENDIAN 0 +#endif + +#if MINIZ_X86_OR_X64_CPU +/* Set MINIZ_USE_UNALIGNED_LOADS_AND_STORES to 1 on CPU's that permit efficient integer loads and stores from unaligned addresses. */ +#define MINIZ_USE_UNALIGNED_LOADS_AND_STORES 1 +#else +#define MINIZ_USE_UNALIGNED_LOADS_AND_STORES 0 +#endif + +#if defined(_M_X64) || defined(_WIN64) || defined(__MINGW64__) || defined(_LP64) || defined(__LP64__) || defined(__ia64__) || defined(__x86_64__) +/* Set MINIZ_HAS_64BIT_REGISTERS to 1 if operations on 64-bit integers are reasonably fast (and don't involve compiler generated calls to helper functions). */ +#define MINIZ_HAS_64BIT_REGISTERS 1 +#else +#define MINIZ_HAS_64BIT_REGISTERS 0 +#endif + +/* ------------------- zlib-style API Definitions. */ + +/* For more compatibility with zlib, miniz.c uses unsigned long for some parameters/struct members. Beware: mz_ulong can be either 32 or 64-bits! */ +typedef unsigned long mz_ulong; + +/* mz_free() internally uses the MZ_FREE() macro (which by default calls free() unless you've modified the MZ_MALLOC macro) to release a block allocated from the heap. */ +void mz_free(void *p); + +#define MZ_ADLER32_INIT (1) +/* mz_adler32() returns the initial adler-32 value to use when called with ptr==NULL. */ +mz_ulong mz_adler32(mz_ulong adler, const unsigned char *ptr, size_t buf_len); + +#define MZ_CRC32_INIT (0) +/* mz_crc32() returns the initial CRC-32 value to use when called with ptr==NULL. */ +mz_ulong mz_crc32(mz_ulong crc, const unsigned char *ptr, size_t buf_len); + +/* Compression strategies. */ +enum +{ + MZ_DEFAULT_STRATEGY = 0, + MZ_FILTERED = 1, + MZ_HUFFMAN_ONLY = 2, + MZ_RLE = 3, + MZ_FIXED = 4 +}; + +/* Method */ +#define MZ_DEFLATED 8 + +/* Heap allocation callbacks. +Note that mz_alloc_func parameter types purpsosely differ from zlib's: items/size is size_t, not unsigned long. */ +typedef void *(*mz_alloc_func)(void *opaque, size_t items, size_t size); +typedef void (*mz_free_func)(void *opaque, void *address); +typedef void *(*mz_realloc_func)(void *opaque, void *address, size_t items, size_t size); + +/* Compression levels: 0-9 are the standard zlib-style levels, 10 is best possible compression (not zlib compatible, and may be very slow), MZ_DEFAULT_COMPRESSION=MZ_DEFAULT_LEVEL. */ +enum +{ + MZ_NO_COMPRESSION = 0, + MZ_BEST_SPEED = 1, + MZ_BEST_COMPRESSION = 9, + MZ_UBER_COMPRESSION = 10, + MZ_DEFAULT_LEVEL = 6, + MZ_DEFAULT_COMPRESSION = -1 +}; + +#define MZ_VERSION "10.0.1" +#define MZ_VERNUM 0xA010 +#define MZ_VER_MAJOR 10 +#define MZ_VER_MINOR 0 +#define MZ_VER_REVISION 1 +#define MZ_VER_SUBREVISION 0 + +#ifndef MINIZ_NO_ZLIB_APIS + +/* Flush values. For typical usage you only need MZ_NO_FLUSH and MZ_FINISH. The other values are for advanced use (refer to the zlib docs). */ +enum +{ + MZ_NO_FLUSH = 0, + MZ_PARTIAL_FLUSH = 1, + MZ_SYNC_FLUSH = 2, + MZ_FULL_FLUSH = 3, + MZ_FINISH = 4, + MZ_BLOCK = 5 +}; + +/* Return status codes. MZ_PARAM_ERROR is non-standard. */ +enum +{ + MZ_OK = 0, + MZ_STREAM_END = 1, + MZ_NEED_DICT = 2, + MZ_ERRNO = -1, + MZ_STREAM_ERROR = -2, + MZ_DATA_ERROR = -3, + MZ_MEM_ERROR = -4, + MZ_BUF_ERROR = -5, + MZ_VERSION_ERROR = -6, + MZ_PARAM_ERROR = -10000 +}; + +/* Window bits */ +#define MZ_DEFAULT_WINDOW_BITS 15 + +struct mz_internal_state; + +/* Compression/decompression stream struct. */ +typedef struct mz_stream_s +{ + const unsigned char *next_in; /* pointer to next byte to read */ + unsigned int avail_in; /* number of bytes available at next_in */ + mz_ulong total_in; /* total number of bytes consumed so far */ + + unsigned char *next_out; /* pointer to next byte to write */ + unsigned int avail_out; /* number of bytes that can be written to next_out */ + mz_ulong total_out; /* total number of bytes produced so far */ + + char *msg; /* error msg (unused) */ + struct mz_internal_state *state; /* internal state, allocated by zalloc/zfree */ + + mz_alloc_func zalloc; /* optional heap allocation function (defaults to malloc) */ + mz_free_func zfree; /* optional heap free function (defaults to free) */ + void *opaque; /* heap alloc function user pointer */ + + int data_type; /* data_type (unused) */ + mz_ulong adler; /* adler32 of the source or uncompressed data */ + mz_ulong reserved; /* not used */ +} mz_stream; + +typedef mz_stream *mz_streamp; + +/* Returns the version string of miniz.c. */ +const char *mz_version(void); + +/* mz_deflateInit() initializes a compressor with default options: */ +/* Parameters: */ +/* pStream must point to an initialized mz_stream struct. */ +/* level must be between [MZ_NO_COMPRESSION, MZ_BEST_COMPRESSION]. */ +/* level 1 enables a specially optimized compression function that's been optimized purely for performance, not ratio. */ +/* (This special func. is currently only enabled when MINIZ_USE_UNALIGNED_LOADS_AND_STORES and MINIZ_LITTLE_ENDIAN are defined.) */ +/* Return values: */ +/* MZ_OK on success. */ +/* MZ_STREAM_ERROR if the stream is bogus. */ +/* MZ_PARAM_ERROR if the input parameters are bogus. */ +/* MZ_MEM_ERROR on out of memory. */ +int mz_deflateInit(mz_streamp pStream, int level); + +/* mz_deflateInit2() is like mz_deflate(), except with more control: */ +/* Additional parameters: */ +/* method must be MZ_DEFLATED */ +/* window_bits must be MZ_DEFAULT_WINDOW_BITS (to wrap the deflate stream with zlib header/adler-32 footer) or -MZ_DEFAULT_WINDOW_BITS (raw deflate/no header or footer) */ +/* mem_level must be between [1, 9] (it's checked but ignored by miniz.c) */ +int mz_deflateInit2(mz_streamp pStream, int level, int method, int window_bits, int mem_level, int strategy); + +/* Quickly resets a compressor without having to reallocate anything. Same as calling mz_deflateEnd() followed by mz_deflateInit()/mz_deflateInit2(). */ +int mz_deflateReset(mz_streamp pStream); + +/* mz_deflate() compresses the input to output, consuming as much of the input and producing as much output as possible. */ +/* Parameters: */ +/* pStream is the stream to read from and write to. You must initialize/update the next_in, avail_in, next_out, and avail_out members. */ +/* flush may be MZ_NO_FLUSH, MZ_PARTIAL_FLUSH/MZ_SYNC_FLUSH, MZ_FULL_FLUSH, or MZ_FINISH. */ +/* Return values: */ +/* MZ_OK on success (when flushing, or if more input is needed but not available, and/or there's more output to be written but the output buffer is full). */ +/* MZ_STREAM_END if all input has been consumed and all output bytes have been written. Don't call mz_deflate() on the stream anymore. */ +/* MZ_STREAM_ERROR if the stream is bogus. */ +/* MZ_PARAM_ERROR if one of the parameters is invalid. */ +/* MZ_BUF_ERROR if no forward progress is possible because the input and/or output buffers are empty. (Fill up the input buffer or free up some output space and try again.) */ +int mz_deflate(mz_streamp pStream, int flush); + +/* mz_deflateEnd() deinitializes a compressor: */ +/* Return values: */ +/* MZ_OK on success. */ +/* MZ_STREAM_ERROR if the stream is bogus. */ +int mz_deflateEnd(mz_streamp pStream); + +/* mz_deflateBound() returns a (very) conservative upper bound on the amount of data that could be generated by deflate(), assuming flush is set to only MZ_NO_FLUSH or MZ_FINISH. */ +mz_ulong mz_deflateBound(mz_streamp pStream, mz_ulong source_len); + +/* Single-call compression functions mz_compress() and mz_compress2(): */ +/* Returns MZ_OK on success, or one of the error codes from mz_deflate() on failure. */ +int mz_compress(unsigned char *pDest, mz_ulong *pDest_len, const unsigned char *pSource, mz_ulong source_len); +int mz_compress2(unsigned char *pDest, mz_ulong *pDest_len, const unsigned char *pSource, mz_ulong source_len, int level); + +/* mz_compressBound() returns a (very) conservative upper bound on the amount of data that could be generated by calling mz_compress(). */ +mz_ulong mz_compressBound(mz_ulong source_len); + +/* Initializes a decompressor. */ +int mz_inflateInit(mz_streamp pStream); + +/* mz_inflateInit2() is like mz_inflateInit() with an additional option that controls the window size and whether or not the stream has been wrapped with a zlib header/footer: */ +/* window_bits must be MZ_DEFAULT_WINDOW_BITS (to parse zlib header/footer) or -MZ_DEFAULT_WINDOW_BITS (raw deflate). */ +int mz_inflateInit2(mz_streamp pStream, int window_bits); + +/* Decompresses the input stream to the output, consuming only as much of the input as needed, and writing as much to the output as possible. */ +/* Parameters: */ +/* pStream is the stream to read from and write to. You must initialize/update the next_in, avail_in, next_out, and avail_out members. */ +/* flush may be MZ_NO_FLUSH, MZ_SYNC_FLUSH, or MZ_FINISH. */ +/* On the first call, if flush is MZ_FINISH it's assumed the input and output buffers are both sized large enough to decompress the entire stream in a single call (this is slightly faster). */ +/* MZ_FINISH implies that there are no more source bytes available beside what's already in the input buffer, and that the output buffer is large enough to hold the rest of the decompressed data. */ +/* Return values: */ +/* MZ_OK on success. Either more input is needed but not available, and/or there's more output to be written but the output buffer is full. */ +/* MZ_STREAM_END if all needed input has been consumed and all output bytes have been written. For zlib streams, the adler-32 of the decompressed data has also been verified. */ +/* MZ_STREAM_ERROR if the stream is bogus. */ +/* MZ_DATA_ERROR if the deflate stream is invalid. */ +/* MZ_PARAM_ERROR if one of the parameters is invalid. */ +/* MZ_BUF_ERROR if no forward progress is possible because the input buffer is empty but the inflater needs more input to continue, or if the output buffer is not large enough. Call mz_inflate() again */ +/* with more input data, or with more room in the output buffer (except when using single call decompression, described above). */ +int mz_inflate(mz_streamp pStream, int flush); + +/* Deinitializes a decompressor. */ +int mz_inflateEnd(mz_streamp pStream); + +/* Single-call decompression. */ +/* Returns MZ_OK on success, or one of the error codes from mz_inflate() on failure. */ +int mz_uncompress(unsigned char *pDest, mz_ulong *pDest_len, const unsigned char *pSource, mz_ulong source_len); + +/* Returns a string description of the specified error code, or NULL if the error code is invalid. */ +const char *mz_error(int err); + +/* Redefine zlib-compatible names to miniz equivalents, so miniz.c can be used as a drop-in replacement for the subset of zlib that miniz.c supports. */ +/* Define MINIZ_NO_ZLIB_COMPATIBLE_NAMES to disable zlib-compatibility if you use zlib in the same project. */ +#ifndef MINIZ_NO_ZLIB_COMPATIBLE_NAMES +typedef unsigned char Byte; +typedef unsigned int uInt; +typedef mz_ulong uLong; +typedef Byte Bytef; +typedef uInt uIntf; +typedef char charf; +typedef int intf; +typedef void *voidpf; +typedef uLong uLongf; +typedef void *voidp; +typedef void *const voidpc; +#define Z_NULL 0 +#define Z_NO_FLUSH MZ_NO_FLUSH +#define Z_PARTIAL_FLUSH MZ_PARTIAL_FLUSH +#define Z_SYNC_FLUSH MZ_SYNC_FLUSH +#define Z_FULL_FLUSH MZ_FULL_FLUSH +#define Z_FINISH MZ_FINISH +#define Z_BLOCK MZ_BLOCK +#define Z_OK MZ_OK +#define Z_STREAM_END MZ_STREAM_END +#define Z_NEED_DICT MZ_NEED_DICT +#define Z_ERRNO MZ_ERRNO +#define Z_STREAM_ERROR MZ_STREAM_ERROR +#define Z_DATA_ERROR MZ_DATA_ERROR +#define Z_MEM_ERROR MZ_MEM_ERROR +#define Z_BUF_ERROR MZ_BUF_ERROR +#define Z_VERSION_ERROR MZ_VERSION_ERROR +#define Z_PARAM_ERROR MZ_PARAM_ERROR +#define Z_NO_COMPRESSION MZ_NO_COMPRESSION +#define Z_BEST_SPEED MZ_BEST_SPEED +#define Z_BEST_COMPRESSION MZ_BEST_COMPRESSION +#define Z_DEFAULT_COMPRESSION MZ_DEFAULT_COMPRESSION +#define Z_DEFAULT_STRATEGY MZ_DEFAULT_STRATEGY +#define Z_FILTERED MZ_FILTERED +#define Z_HUFFMAN_ONLY MZ_HUFFMAN_ONLY +#define Z_RLE MZ_RLE +#define Z_FIXED MZ_FIXED +#define Z_DEFLATED MZ_DEFLATED +#define Z_DEFAULT_WINDOW_BITS MZ_DEFAULT_WINDOW_BITS +#define alloc_func mz_alloc_func +#define free_func mz_free_func +#define internal_state mz_internal_state +#define z_stream mz_stream +#define deflateInit mz_deflateInit +#define deflateInit2 mz_deflateInit2 +#define deflateReset mz_deflateReset +#define deflate mz_deflate +#define deflateEnd mz_deflateEnd +#define deflateBound mz_deflateBound +#define compress mz_compress +#define compress2 mz_compress2 +#define compressBound mz_compressBound +#define inflateInit mz_inflateInit +#define inflateInit2 mz_inflateInit2 +#define inflate mz_inflate +#define inflateEnd mz_inflateEnd +#define uncompress mz_uncompress +#define crc32 mz_crc32 +#define adler32 mz_adler32 +#define MAX_WBITS 15 +#define MAX_MEM_LEVEL 9 +#define zError mz_error +#define ZLIB_VERSION MZ_VERSION +#define ZLIB_VERNUM MZ_VERNUM +#define ZLIB_VER_MAJOR MZ_VER_MAJOR +#define ZLIB_VER_MINOR MZ_VER_MINOR +#define ZLIB_VER_REVISION MZ_VER_REVISION +#define ZLIB_VER_SUBREVISION MZ_VER_SUBREVISION +#define zlibVersion mz_version +#define zlib_version mz_version() +#endif /* #ifndef MINIZ_NO_ZLIB_COMPATIBLE_NAMES */ + +#endif /* MINIZ_NO_ZLIB_APIS */ + diff --git a/xs/src/miniz/miniz_common.h b/xs/src/miniz/miniz_common.h new file mode 100644 index 000000000..d45bdfcb4 --- /dev/null +++ b/xs/src/miniz/miniz_common.h @@ -0,0 +1,83 @@ +#pragma once +#include +#include +#include +#include + +/* ------------------- Types and macros */ +typedef unsigned char mz_uint8; +typedef signed short mz_int16; +typedef unsigned short mz_uint16; +typedef unsigned int mz_uint32; +typedef unsigned int mz_uint; +typedef int64_t mz_int64; +typedef uint64_t mz_uint64; +typedef int mz_bool; + +#define MZ_FALSE (0) +#define MZ_TRUE (1) + +/* Works around MSVC's spammy "warning C4127: conditional expression is constant" message. */ +#ifdef _MSC_VER +#define MZ_MACRO_END while (0, 0) +#else +#define MZ_MACRO_END while (0) +#endif + +#ifdef MINIZ_NO_STDIO +#define MZ_FILE void * +#else +#include +#define MZ_FILE FILE +#endif /* #ifdef MINIZ_NO_STDIO */ + +#ifdef MINIZ_NO_TIME +typedef struct mz_dummy_time_t_tag +{ + int m_dummy; +} mz_dummy_time_t; +#define MZ_TIME_T mz_dummy_time_t +#else +#define MZ_TIME_T time_t +#endif + +#define MZ_ASSERT(x) assert(x) + +#ifdef MINIZ_NO_MALLOC +#define MZ_MALLOC(x) NULL +#define MZ_FREE(x) (void)x, ((void)0) +#define MZ_REALLOC(p, x) NULL +#else +#define MZ_MALLOC(x) malloc(x) +#define MZ_FREE(x) free(x) +#define MZ_REALLOC(p, x) realloc(p, x) +#endif + +#define MZ_MAX(a, b) (((a) > (b)) ? (a) : (b)) +#define MZ_MIN(a, b) (((a) < (b)) ? (a) : (b)) +#define MZ_CLEAR_OBJ(obj) memset(&(obj), 0, sizeof(obj)) + +#if MINIZ_USE_UNALIGNED_LOADS_AND_STORES && MINIZ_LITTLE_ENDIAN +#define MZ_READ_LE16(p) *((const mz_uint16 *)(p)) +#define MZ_READ_LE32(p) *((const mz_uint32 *)(p)) +#else +#define MZ_READ_LE16(p) ((mz_uint32)(((const mz_uint8 *)(p))[0]) | ((mz_uint32)(((const mz_uint8 *)(p))[1]) << 8U)) +#define MZ_READ_LE32(p) ((mz_uint32)(((const mz_uint8 *)(p))[0]) | ((mz_uint32)(((const mz_uint8 *)(p))[1]) << 8U) | ((mz_uint32)(((const mz_uint8 *)(p))[2]) << 16U) | ((mz_uint32)(((const mz_uint8 *)(p))[3]) << 24U)) +#endif + +#define MZ_READ_LE64(p) (((mz_uint64)MZ_READ_LE32(p)) | (((mz_uint64)MZ_READ_LE32((const mz_uint8 *)(p) + sizeof(mz_uint32))) << 32U)) + +#ifdef _MSC_VER +#define MZ_FORCEINLINE __forceinline +#elif defined(__GNUC__) +#define MZ_FORCEINLINE __inline__ __attribute__((__always_inline__)) +#else +#define MZ_FORCEINLINE inline +#endif + +extern void *miniz_def_alloc_func(void *opaque, size_t items, size_t size); +extern void miniz_def_free_func(void *opaque, void *address); +extern void *miniz_def_realloc_func(void *opaque, void *address, size_t items, size_t size); + +#define MZ_UINT16_MAX (0xFFFFU) +#define MZ_UINT32_MAX (0xFFFFFFFFU) diff --git a/xs/src/miniz/miniz_tdef.cpp b/xs/src/miniz/miniz_tdef.cpp new file mode 100644 index 000000000..36207e64a --- /dev/null +++ b/xs/src/miniz/miniz_tdef.cpp @@ -0,0 +1,1555 @@ +/************************************************************************** + * + * Copyright 2013-2014 RAD Game Tools and Valve Software + * Copyright 2010-2014 Rich Geldreich and Tenacious Software LLC + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + **************************************************************************/ + +#include "miniz_tdef.h" +#include "miniz.h" + +/* ------------------- Low-level Compression (independent from all decompression API's) */ + +/* Purposely making these tables static for faster init and thread safety. */ +static const mz_uint16 s_tdefl_len_sym[256] = + { + 257, 258, 259, 260, 261, 262, 263, 264, 265, 265, 266, 266, 267, 267, 268, 268, 269, 269, 269, 269, 270, 270, 270, 270, 271, 271, 271, 271, 272, 272, 272, 272, + 273, 273, 273, 273, 273, 273, 273, 273, 274, 274, 274, 274, 274, 274, 274, 274, 275, 275, 275, 275, 275, 275, 275, 275, 276, 276, 276, 276, 276, 276, 276, 276, + 277, 277, 277, 277, 277, 277, 277, 277, 277, 277, 277, 277, 277, 277, 277, 277, 278, 278, 278, 278, 278, 278, 278, 278, 278, 278, 278, 278, 278, 278, 278, 278, + 279, 279, 279, 279, 279, 279, 279, 279, 279, 279, 279, 279, 279, 279, 279, 279, 280, 280, 280, 280, 280, 280, 280, 280, 280, 280, 280, 280, 280, 280, 280, 280, + 281, 281, 281, 281, 281, 281, 281, 281, 281, 281, 281, 281, 281, 281, 281, 281, 281, 281, 281, 281, 281, 281, 281, 281, 281, 281, 281, 281, 281, 281, 281, 281, + 282, 282, 282, 282, 282, 282, 282, 282, 282, 282, 282, 282, 282, 282, 282, 282, 282, 282, 282, 282, 282, 282, 282, 282, 282, 282, 282, 282, 282, 282, 282, 282, + 283, 283, 283, 283, 283, 283, 283, 283, 283, 283, 283, 283, 283, 283, 283, 283, 283, 283, 283, 283, 283, 283, 283, 283, 283, 283, 283, 283, 283, 283, 283, 283, + 284, 284, 284, 284, 284, 284, 284, 284, 284, 284, 284, 284, 284, 284, 284, 284, 284, 284, 284, 284, 284, 284, 284, 284, 284, 284, 284, 284, 284, 284, 284, 285 + }; + +static const mz_uint8 s_tdefl_len_extra[256] = + { + 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, + 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, + 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, + 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 0 + }; + +static const mz_uint8 s_tdefl_small_dist_sym[512] = + { + 0, 1, 2, 3, 4, 4, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 11, + 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 13, + 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, + 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, + 14, 14, 14, 14, 14, 14, 14, 14, 14, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, + 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, + 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, + 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, + 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17 + }; + +static const mz_uint8 s_tdefl_small_dist_extra[512] = + { + 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, + 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, + 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, + 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, + 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, + 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, + 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, + 7, 7, 7, 7, 7, 7, 7, 7 + }; + +static const mz_uint8 s_tdefl_large_dist_sym[128] = + { + 0, 0, 18, 19, 20, 20, 21, 21, 22, 22, 22, 22, 23, 23, 23, 23, 24, 24, 24, 24, 24, 24, 24, 24, 25, 25, 25, 25, 25, 25, 25, 25, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, + 26, 26, 26, 26, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, + 28, 28, 28, 28, 28, 28, 28, 28, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29 + }; + +static const mz_uint8 s_tdefl_large_dist_extra[128] = + { + 0, 0, 8, 8, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, + 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, + 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13 + }; + +/* Radix sorts tdefl_sym_freq[] array by 16-bit key m_key. Returns ptr to sorted values. */ +typedef struct +{ + mz_uint16 m_key, m_sym_index; +} tdefl_sym_freq; +static tdefl_sym_freq *tdefl_radix_sort_syms(mz_uint num_syms, tdefl_sym_freq *pSyms0, tdefl_sym_freq *pSyms1) +{ + mz_uint32 total_passes = 2, pass_shift, pass, i, hist[256 * 2]; + tdefl_sym_freq *pCur_syms = pSyms0, *pNew_syms = pSyms1; + MZ_CLEAR_OBJ(hist); + for (i = 0; i < num_syms; i++) + { + mz_uint freq = pSyms0[i].m_key; + hist[freq & 0xFF]++; + hist[256 + ((freq >> 8) & 0xFF)]++; + } + while ((total_passes > 1) && (num_syms == hist[(total_passes - 1) * 256])) + total_passes--; + for (pass_shift = 0, pass = 0; pass < total_passes; pass++, pass_shift += 8) + { + const mz_uint32 *pHist = &hist[pass << 8]; + mz_uint offsets[256], cur_ofs = 0; + for (i = 0; i < 256; i++) + { + offsets[i] = cur_ofs; + cur_ofs += pHist[i]; + } + for (i = 0; i < num_syms; i++) + pNew_syms[offsets[(pCur_syms[i].m_key >> pass_shift) & 0xFF]++] = pCur_syms[i]; + { + tdefl_sym_freq *t = pCur_syms; + pCur_syms = pNew_syms; + pNew_syms = t; + } + } + return pCur_syms; +} + +/* tdefl_calculate_minimum_redundancy() originally written by: Alistair Moffat, alistair@cs.mu.oz.au, Jyrki Katajainen, jyrki@diku.dk, November 1996. */ +static void tdefl_calculate_minimum_redundancy(tdefl_sym_freq *A, int n) +{ + int root, leaf, next, avbl, used, dpth; + if (n == 0) + return; + else if (n == 1) + { + A[0].m_key = 1; + return; + } + A[0].m_key += A[1].m_key; + root = 0; + leaf = 2; + for (next = 1; next < n - 1; next++) + { + if (leaf >= n || A[root].m_key < A[leaf].m_key) + { + A[next].m_key = A[root].m_key; + A[root++].m_key = (mz_uint16)next; + } + else + A[next].m_key = A[leaf++].m_key; + if (leaf >= n || (root < next && A[root].m_key < A[leaf].m_key)) + { + A[next].m_key = (mz_uint16)(A[next].m_key + A[root].m_key); + A[root++].m_key = (mz_uint16)next; + } + else + A[next].m_key = (mz_uint16)(A[next].m_key + A[leaf++].m_key); + } + A[n - 2].m_key = 0; + for (next = n - 3; next >= 0; next--) + A[next].m_key = A[A[next].m_key].m_key + 1; + avbl = 1; + used = dpth = 0; + root = n - 2; + next = n - 1; + while (avbl > 0) + { + while (root >= 0 && (int)A[root].m_key == dpth) + { + used++; + root--; + } + while (avbl > used) + { + A[next--].m_key = (mz_uint16)(dpth); + avbl--; + } + avbl = 2 * used; + dpth++; + used = 0; + } +} + +/* Limits canonical Huffman code table's max code size. */ +enum +{ + TDEFL_MAX_SUPPORTED_HUFF_CODESIZE = 32 +}; +static void tdefl_huffman_enforce_max_code_size(int *pNum_codes, int code_list_len, int max_code_size) +{ + int i; + mz_uint32 total = 0; + if (code_list_len <= 1) + return; + for (i = max_code_size + 1; i <= TDEFL_MAX_SUPPORTED_HUFF_CODESIZE; i++) + pNum_codes[max_code_size] += pNum_codes[i]; + for (i = max_code_size; i > 0; i--) + total += (((mz_uint32)pNum_codes[i]) << (max_code_size - i)); + while (total != (1UL << max_code_size)) + { + pNum_codes[max_code_size]--; + for (i = max_code_size - 1; i > 0; i--) + if (pNum_codes[i]) + { + pNum_codes[i]--; + pNum_codes[i + 1] += 2; + break; + } + total--; + } +} + +static void tdefl_optimize_huffman_table(tdefl_compressor *d, int table_num, int table_len, int code_size_limit, int static_table) +{ + int i, j, l, num_codes[1 + TDEFL_MAX_SUPPORTED_HUFF_CODESIZE]; + mz_uint next_code[TDEFL_MAX_SUPPORTED_HUFF_CODESIZE + 1]; + MZ_CLEAR_OBJ(num_codes); + if (static_table) + { + for (i = 0; i < table_len; i++) + num_codes[d->m_huff_code_sizes[table_num][i]]++; + } + else + { + tdefl_sym_freq syms0[TDEFL_MAX_HUFF_SYMBOLS], syms1[TDEFL_MAX_HUFF_SYMBOLS], *pSyms; + int num_used_syms = 0; + const mz_uint16 *pSym_count = &d->m_huff_count[table_num][0]; + for (i = 0; i < table_len; i++) + if (pSym_count[i]) + { + syms0[num_used_syms].m_key = (mz_uint16)pSym_count[i]; + syms0[num_used_syms++].m_sym_index = (mz_uint16)i; + } + + pSyms = tdefl_radix_sort_syms(num_used_syms, syms0, syms1); + tdefl_calculate_minimum_redundancy(pSyms, num_used_syms); + + for (i = 0; i < num_used_syms; i++) + num_codes[pSyms[i].m_key]++; + + tdefl_huffman_enforce_max_code_size(num_codes, num_used_syms, code_size_limit); + + MZ_CLEAR_OBJ(d->m_huff_code_sizes[table_num]); + MZ_CLEAR_OBJ(d->m_huff_codes[table_num]); + for (i = 1, j = num_used_syms; i <= code_size_limit; i++) + for (l = num_codes[i]; l > 0; l--) + d->m_huff_code_sizes[table_num][pSyms[--j].m_sym_index] = (mz_uint8)(i); + } + + next_code[1] = 0; + for (j = 0, i = 2; i <= code_size_limit; i++) + next_code[i] = j = ((j + num_codes[i - 1]) << 1); + + for (i = 0; i < table_len; i++) + { + mz_uint rev_code = 0, code, code_size; + if ((code_size = d->m_huff_code_sizes[table_num][i]) == 0) + continue; + code = next_code[code_size]++; + for (l = code_size; l > 0; l--, code >>= 1) + rev_code = (rev_code << 1) | (code & 1); + d->m_huff_codes[table_num][i] = (mz_uint16)rev_code; + } +} + +#define TDEFL_PUT_BITS(b, l) \ + do \ + { \ + mz_uint bits = b; \ + mz_uint len = l; \ + MZ_ASSERT(bits <= ((1U << len) - 1U)); \ + d->m_bit_buffer |= (bits << d->m_bits_in); \ + d->m_bits_in += len; \ + while (d->m_bits_in >= 8) \ + { \ + if (d->m_pOutput_buf < d->m_pOutput_buf_end) \ + *d->m_pOutput_buf++ = (mz_uint8)(d->m_bit_buffer); \ + d->m_bit_buffer >>= 8; \ + d->m_bits_in -= 8; \ + } \ + } \ + MZ_MACRO_END + +#define TDEFL_RLE_PREV_CODE_SIZE() \ + { \ + if (rle_repeat_count) \ + { \ + if (rle_repeat_count < 3) \ + { \ + d->m_huff_count[2][prev_code_size] = (mz_uint16)(d->m_huff_count[2][prev_code_size] + rle_repeat_count); \ + while (rle_repeat_count--) \ + packed_code_sizes[num_packed_code_sizes++] = prev_code_size; \ + } \ + else \ + { \ + d->m_huff_count[2][16] = (mz_uint16)(d->m_huff_count[2][16] + 1); \ + packed_code_sizes[num_packed_code_sizes++] = 16; \ + packed_code_sizes[num_packed_code_sizes++] = (mz_uint8)(rle_repeat_count - 3); \ + } \ + rle_repeat_count = 0; \ + } \ + } + +#define TDEFL_RLE_ZERO_CODE_SIZE() \ + { \ + if (rle_z_count) \ + { \ + if (rle_z_count < 3) \ + { \ + d->m_huff_count[2][0] = (mz_uint16)(d->m_huff_count[2][0] + rle_z_count); \ + while (rle_z_count--) \ + packed_code_sizes[num_packed_code_sizes++] = 0; \ + } \ + else if (rle_z_count <= 10) \ + { \ + d->m_huff_count[2][17] = (mz_uint16)(d->m_huff_count[2][17] + 1); \ + packed_code_sizes[num_packed_code_sizes++] = 17; \ + packed_code_sizes[num_packed_code_sizes++] = (mz_uint8)(rle_z_count - 3); \ + } \ + else \ + { \ + d->m_huff_count[2][18] = (mz_uint16)(d->m_huff_count[2][18] + 1); \ + packed_code_sizes[num_packed_code_sizes++] = 18; \ + packed_code_sizes[num_packed_code_sizes++] = (mz_uint8)(rle_z_count - 11); \ + } \ + rle_z_count = 0; \ + } \ + } + +static mz_uint8 s_tdefl_packed_code_size_syms_swizzle[] = { 16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15 }; + +static void tdefl_start_dynamic_block(tdefl_compressor *d) +{ + int num_lit_codes, num_dist_codes, num_bit_lengths; + mz_uint i, total_code_sizes_to_pack, num_packed_code_sizes, rle_z_count, rle_repeat_count, packed_code_sizes_index; + mz_uint8 code_sizes_to_pack[TDEFL_MAX_HUFF_SYMBOLS_0 + TDEFL_MAX_HUFF_SYMBOLS_1], packed_code_sizes[TDEFL_MAX_HUFF_SYMBOLS_0 + TDEFL_MAX_HUFF_SYMBOLS_1], prev_code_size = 0xFF; + + d->m_huff_count[0][256] = 1; + + tdefl_optimize_huffman_table(d, 0, TDEFL_MAX_HUFF_SYMBOLS_0, 15, MZ_FALSE); + tdefl_optimize_huffman_table(d, 1, TDEFL_MAX_HUFF_SYMBOLS_1, 15, MZ_FALSE); + + for (num_lit_codes = 286; num_lit_codes > 257; num_lit_codes--) + if (d->m_huff_code_sizes[0][num_lit_codes - 1]) + break; + for (num_dist_codes = 30; num_dist_codes > 1; num_dist_codes--) + if (d->m_huff_code_sizes[1][num_dist_codes - 1]) + break; + + memcpy(code_sizes_to_pack, &d->m_huff_code_sizes[0][0], num_lit_codes); + memcpy(code_sizes_to_pack + num_lit_codes, &d->m_huff_code_sizes[1][0], num_dist_codes); + total_code_sizes_to_pack = num_lit_codes + num_dist_codes; + num_packed_code_sizes = 0; + rle_z_count = 0; + rle_repeat_count = 0; + + memset(&d->m_huff_count[2][0], 0, sizeof(d->m_huff_count[2][0]) * TDEFL_MAX_HUFF_SYMBOLS_2); + for (i = 0; i < total_code_sizes_to_pack; i++) + { + mz_uint8 code_size = code_sizes_to_pack[i]; + if (!code_size) + { + TDEFL_RLE_PREV_CODE_SIZE(); + if (++rle_z_count == 138) + { + TDEFL_RLE_ZERO_CODE_SIZE(); + } + } + else + { + TDEFL_RLE_ZERO_CODE_SIZE(); + if (code_size != prev_code_size) + { + TDEFL_RLE_PREV_CODE_SIZE(); + d->m_huff_count[2][code_size] = (mz_uint16)(d->m_huff_count[2][code_size] + 1); + packed_code_sizes[num_packed_code_sizes++] = code_size; + } + else if (++rle_repeat_count == 6) + { + TDEFL_RLE_PREV_CODE_SIZE(); + } + } + prev_code_size = code_size; + } + if (rle_repeat_count) + { + TDEFL_RLE_PREV_CODE_SIZE(); + } + else + { + TDEFL_RLE_ZERO_CODE_SIZE(); + } + + tdefl_optimize_huffman_table(d, 2, TDEFL_MAX_HUFF_SYMBOLS_2, 7, MZ_FALSE); + + TDEFL_PUT_BITS(2, 2); + + TDEFL_PUT_BITS(num_lit_codes - 257, 5); + TDEFL_PUT_BITS(num_dist_codes - 1, 5); + + for (num_bit_lengths = 18; num_bit_lengths >= 0; num_bit_lengths--) + if (d->m_huff_code_sizes[2][s_tdefl_packed_code_size_syms_swizzle[num_bit_lengths]]) + break; + num_bit_lengths = MZ_MAX(4, (num_bit_lengths + 1)); + TDEFL_PUT_BITS(num_bit_lengths - 4, 4); + for (i = 0; (int)i < num_bit_lengths; i++) + TDEFL_PUT_BITS(d->m_huff_code_sizes[2][s_tdefl_packed_code_size_syms_swizzle[i]], 3); + + for (packed_code_sizes_index = 0; packed_code_sizes_index < num_packed_code_sizes;) + { + mz_uint code = packed_code_sizes[packed_code_sizes_index++]; + MZ_ASSERT(code < TDEFL_MAX_HUFF_SYMBOLS_2); + TDEFL_PUT_BITS(d->m_huff_codes[2][code], d->m_huff_code_sizes[2][code]); + if (code >= 16) + TDEFL_PUT_BITS(packed_code_sizes[packed_code_sizes_index++], "\02\03\07"[code - 16]); + } +} + +static void tdefl_start_static_block(tdefl_compressor *d) +{ + mz_uint i; + mz_uint8 *p = &d->m_huff_code_sizes[0][0]; + + for (i = 0; i <= 143; ++i) + *p++ = 8; + for (; i <= 255; ++i) + *p++ = 9; + for (; i <= 279; ++i) + *p++ = 7; + for (; i <= 287; ++i) + *p++ = 8; + + memset(d->m_huff_code_sizes[1], 5, 32); + + tdefl_optimize_huffman_table(d, 0, 288, 15, MZ_TRUE); + tdefl_optimize_huffman_table(d, 1, 32, 15, MZ_TRUE); + + TDEFL_PUT_BITS(1, 2); +} + +static const mz_uint mz_bitmasks[17] = { 0x0000, 0x0001, 0x0003, 0x0007, 0x000F, 0x001F, 0x003F, 0x007F, 0x00FF, 0x01FF, 0x03FF, 0x07FF, 0x0FFF, 0x1FFF, 0x3FFF, 0x7FFF, 0xFFFF }; + +#if MINIZ_USE_UNALIGNED_LOADS_AND_STORES && MINIZ_LITTLE_ENDIAN && MINIZ_HAS_64BIT_REGISTERS +static mz_bool tdefl_compress_lz_codes(tdefl_compressor *d) +{ + mz_uint flags; + mz_uint8 *pLZ_codes; + mz_uint8 *pOutput_buf = d->m_pOutput_buf; + mz_uint8 *pLZ_code_buf_end = d->m_pLZ_code_buf; + mz_uint64 bit_buffer = d->m_bit_buffer; + mz_uint bits_in = d->m_bits_in; + +#define TDEFL_PUT_BITS_FAST(b, l) \ + { \ + bit_buffer |= (((mz_uint64)(b)) << bits_in); \ + bits_in += (l); \ + } + + flags = 1; + for (pLZ_codes = d->m_lz_code_buf; pLZ_codes < pLZ_code_buf_end; flags >>= 1) + { + if (flags == 1) + flags = *pLZ_codes++ | 0x100; + + if (flags & 1) + { + mz_uint s0, s1, n0, n1, sym, num_extra_bits; + mz_uint match_len = pLZ_codes[0], match_dist = *(const mz_uint16 *)(pLZ_codes + 1); + pLZ_codes += 3; + + MZ_ASSERT(d->m_huff_code_sizes[0][s_tdefl_len_sym[match_len]]); + TDEFL_PUT_BITS_FAST(d->m_huff_codes[0][s_tdefl_len_sym[match_len]], d->m_huff_code_sizes[0][s_tdefl_len_sym[match_len]]); + TDEFL_PUT_BITS_FAST(match_len & mz_bitmasks[s_tdefl_len_extra[match_len]], s_tdefl_len_extra[match_len]); + + /* This sequence coaxes MSVC into using cmov's vs. jmp's. */ + s0 = s_tdefl_small_dist_sym[match_dist & 511]; + n0 = s_tdefl_small_dist_extra[match_dist & 511]; + s1 = s_tdefl_large_dist_sym[match_dist >> 8]; + n1 = s_tdefl_large_dist_extra[match_dist >> 8]; + sym = (match_dist < 512) ? s0 : s1; + num_extra_bits = (match_dist < 512) ? n0 : n1; + + MZ_ASSERT(d->m_huff_code_sizes[1][sym]); + TDEFL_PUT_BITS_FAST(d->m_huff_codes[1][sym], d->m_huff_code_sizes[1][sym]); + TDEFL_PUT_BITS_FAST(match_dist & mz_bitmasks[num_extra_bits], num_extra_bits); + } + else + { + mz_uint lit = *pLZ_codes++; + MZ_ASSERT(d->m_huff_code_sizes[0][lit]); + TDEFL_PUT_BITS_FAST(d->m_huff_codes[0][lit], d->m_huff_code_sizes[0][lit]); + + if (((flags & 2) == 0) && (pLZ_codes < pLZ_code_buf_end)) + { + flags >>= 1; + lit = *pLZ_codes++; + MZ_ASSERT(d->m_huff_code_sizes[0][lit]); + TDEFL_PUT_BITS_FAST(d->m_huff_codes[0][lit], d->m_huff_code_sizes[0][lit]); + + if (((flags & 2) == 0) && (pLZ_codes < pLZ_code_buf_end)) + { + flags >>= 1; + lit = *pLZ_codes++; + MZ_ASSERT(d->m_huff_code_sizes[0][lit]); + TDEFL_PUT_BITS_FAST(d->m_huff_codes[0][lit], d->m_huff_code_sizes[0][lit]); + } + } + } + + if (pOutput_buf >= d->m_pOutput_buf_end) + return MZ_FALSE; + + *(mz_uint64 *)pOutput_buf = bit_buffer; + pOutput_buf += (bits_in >> 3); + bit_buffer >>= (bits_in & ~7); + bits_in &= 7; + } + +#undef TDEFL_PUT_BITS_FAST + + d->m_pOutput_buf = pOutput_buf; + d->m_bits_in = 0; + d->m_bit_buffer = 0; + + while (bits_in) + { + mz_uint32 n = MZ_MIN(bits_in, 16); + TDEFL_PUT_BITS((mz_uint)bit_buffer & mz_bitmasks[n], n); + bit_buffer >>= n; + bits_in -= n; + } + + TDEFL_PUT_BITS(d->m_huff_codes[0][256], d->m_huff_code_sizes[0][256]); + + return (d->m_pOutput_buf < d->m_pOutput_buf_end); +} +#else +static mz_bool tdefl_compress_lz_codes(tdefl_compressor *d) +{ + mz_uint flags; + mz_uint8 *pLZ_codes; + + flags = 1; + for (pLZ_codes = d->m_lz_code_buf; pLZ_codes < d->m_pLZ_code_buf; flags >>= 1) + { + if (flags == 1) + flags = *pLZ_codes++ | 0x100; + if (flags & 1) + { + mz_uint sym, num_extra_bits; + mz_uint match_len = pLZ_codes[0], match_dist = (pLZ_codes[1] | (pLZ_codes[2] << 8)); + pLZ_codes += 3; + + MZ_ASSERT(d->m_huff_code_sizes[0][s_tdefl_len_sym[match_len]]); + TDEFL_PUT_BITS(d->m_huff_codes[0][s_tdefl_len_sym[match_len]], d->m_huff_code_sizes[0][s_tdefl_len_sym[match_len]]); + TDEFL_PUT_BITS(match_len & mz_bitmasks[s_tdefl_len_extra[match_len]], s_tdefl_len_extra[match_len]); + + if (match_dist < 512) + { + sym = s_tdefl_small_dist_sym[match_dist]; + num_extra_bits = s_tdefl_small_dist_extra[match_dist]; + } + else + { + sym = s_tdefl_large_dist_sym[match_dist >> 8]; + num_extra_bits = s_tdefl_large_dist_extra[match_dist >> 8]; + } + MZ_ASSERT(d->m_huff_code_sizes[1][sym]); + TDEFL_PUT_BITS(d->m_huff_codes[1][sym], d->m_huff_code_sizes[1][sym]); + TDEFL_PUT_BITS(match_dist & mz_bitmasks[num_extra_bits], num_extra_bits); + } + else + { + mz_uint lit = *pLZ_codes++; + MZ_ASSERT(d->m_huff_code_sizes[0][lit]); + TDEFL_PUT_BITS(d->m_huff_codes[0][lit], d->m_huff_code_sizes[0][lit]); + } + } + + TDEFL_PUT_BITS(d->m_huff_codes[0][256], d->m_huff_code_sizes[0][256]); + + return (d->m_pOutput_buf < d->m_pOutput_buf_end); +} +#endif /* MINIZ_USE_UNALIGNED_LOADS_AND_STORES && MINIZ_LITTLE_ENDIAN && MINIZ_HAS_64BIT_REGISTERS */ + +static mz_bool tdefl_compress_block(tdefl_compressor *d, mz_bool static_block) +{ + if (static_block) + tdefl_start_static_block(d); + else + tdefl_start_dynamic_block(d); + return tdefl_compress_lz_codes(d); +} + +static int tdefl_flush_block(tdefl_compressor *d, int flush) +{ + mz_uint saved_bit_buf, saved_bits_in; + mz_uint8 *pSaved_output_buf; + mz_bool comp_block_succeeded = MZ_FALSE; + int n, use_raw_block = ((d->m_flags & TDEFL_FORCE_ALL_RAW_BLOCKS) != 0) && (d->m_lookahead_pos - d->m_lz_code_buf_dict_pos) <= d->m_dict_size; + mz_uint8 *pOutput_buf_start = ((d->m_pPut_buf_func == NULL) && ((*d->m_pOut_buf_size - d->m_out_buf_ofs) >= TDEFL_OUT_BUF_SIZE)) ? ((mz_uint8 *)d->m_pOut_buf + d->m_out_buf_ofs) : d->m_output_buf; + + d->m_pOutput_buf = pOutput_buf_start; + d->m_pOutput_buf_end = d->m_pOutput_buf + TDEFL_OUT_BUF_SIZE - 16; + + MZ_ASSERT(!d->m_output_flush_remaining); + d->m_output_flush_ofs = 0; + d->m_output_flush_remaining = 0; + + *d->m_pLZ_flags = (mz_uint8)(*d->m_pLZ_flags >> d->m_num_flags_left); + d->m_pLZ_code_buf -= (d->m_num_flags_left == 8); + + if ((d->m_flags & TDEFL_WRITE_ZLIB_HEADER) && (!d->m_block_index)) + { + TDEFL_PUT_BITS(0x78, 8); + TDEFL_PUT_BITS(0x01, 8); + } + + TDEFL_PUT_BITS(flush == TDEFL_FINISH, 1); + + pSaved_output_buf = d->m_pOutput_buf; + saved_bit_buf = d->m_bit_buffer; + saved_bits_in = d->m_bits_in; + + if (!use_raw_block) + comp_block_succeeded = tdefl_compress_block(d, (d->m_flags & TDEFL_FORCE_ALL_STATIC_BLOCKS) || (d->m_total_lz_bytes < 48)); + + /* If the block gets expanded, forget the current contents of the output buffer and send a raw block instead. */ + if (((use_raw_block) || ((d->m_total_lz_bytes) && ((d->m_pOutput_buf - pSaved_output_buf + 1U) >= d->m_total_lz_bytes))) && + ((d->m_lookahead_pos - d->m_lz_code_buf_dict_pos) <= d->m_dict_size)) + { + mz_uint i; + d->m_pOutput_buf = pSaved_output_buf; + d->m_bit_buffer = saved_bit_buf, d->m_bits_in = saved_bits_in; + TDEFL_PUT_BITS(0, 2); + if (d->m_bits_in) + { + TDEFL_PUT_BITS(0, 8 - d->m_bits_in); + } + for (i = 2; i; --i, d->m_total_lz_bytes ^= 0xFFFF) + { + TDEFL_PUT_BITS(d->m_total_lz_bytes & 0xFFFF, 16); + } + for (i = 0; i < d->m_total_lz_bytes; ++i) + { + TDEFL_PUT_BITS(d->m_dict[(d->m_lz_code_buf_dict_pos + i) & TDEFL_LZ_DICT_SIZE_MASK], 8); + } + } + /* Check for the extremely unlikely (if not impossible) case of the compressed block not fitting into the output buffer when using dynamic codes. */ + else if (!comp_block_succeeded) + { + d->m_pOutput_buf = pSaved_output_buf; + d->m_bit_buffer = saved_bit_buf, d->m_bits_in = saved_bits_in; + tdefl_compress_block(d, MZ_TRUE); + } + + if (flush) + { + if (flush == TDEFL_FINISH) + { + if (d->m_bits_in) + { + TDEFL_PUT_BITS(0, 8 - d->m_bits_in); + } + if (d->m_flags & TDEFL_WRITE_ZLIB_HEADER) + { + mz_uint i, a = d->m_adler32; + for (i = 0; i < 4; i++) + { + TDEFL_PUT_BITS((a >> 24) & 0xFF, 8); + a <<= 8; + } + } + } + else + { + mz_uint i, z = 0; + TDEFL_PUT_BITS(0, 3); + if (d->m_bits_in) + { + TDEFL_PUT_BITS(0, 8 - d->m_bits_in); + } + for (i = 2; i; --i, z ^= 0xFFFF) + { + TDEFL_PUT_BITS(z & 0xFFFF, 16); + } + } + } + + MZ_ASSERT(d->m_pOutput_buf < d->m_pOutput_buf_end); + + memset(&d->m_huff_count[0][0], 0, sizeof(d->m_huff_count[0][0]) * TDEFL_MAX_HUFF_SYMBOLS_0); + memset(&d->m_huff_count[1][0], 0, sizeof(d->m_huff_count[1][0]) * TDEFL_MAX_HUFF_SYMBOLS_1); + + d->m_pLZ_code_buf = d->m_lz_code_buf + 1; + d->m_pLZ_flags = d->m_lz_code_buf; + d->m_num_flags_left = 8; + d->m_lz_code_buf_dict_pos += d->m_total_lz_bytes; + d->m_total_lz_bytes = 0; + d->m_block_index++; + + if ((n = (int)(d->m_pOutput_buf - pOutput_buf_start)) != 0) + { + if (d->m_pPut_buf_func) + { + *d->m_pIn_buf_size = d->m_pSrc - (const mz_uint8 *)d->m_pIn_buf; + if (!(*d->m_pPut_buf_func)(d->m_output_buf, n, d->m_pPut_buf_user)) + return (d->m_prev_return_status = TDEFL_STATUS_PUT_BUF_FAILED); + } + else if (pOutput_buf_start == d->m_output_buf) + { + int bytes_to_copy = (int)MZ_MIN((size_t)n, (size_t)(*d->m_pOut_buf_size - d->m_out_buf_ofs)); + memcpy((mz_uint8 *)d->m_pOut_buf + d->m_out_buf_ofs, d->m_output_buf, bytes_to_copy); + d->m_out_buf_ofs += bytes_to_copy; + if ((n -= bytes_to_copy) != 0) + { + d->m_output_flush_ofs = bytes_to_copy; + d->m_output_flush_remaining = n; + } + } + else + { + d->m_out_buf_ofs += n; + } + } + + return d->m_output_flush_remaining; +} + +#if MINIZ_USE_UNALIGNED_LOADS_AND_STORES +#ifdef MINIZ_UNALIGNED_USE_MEMCPY +static inline mz_uint16 TDEFL_READ_UNALIGNED_WORD(const mz_uint8* p) +{ + mz_uint16 ret; + memcpy(&ret, p, sizeof(mz_uint16)); + return ret; +} +static inline mz_uint16 TDEFL_READ_UNALIGNED_WORD2(const mz_uint16* p) +{ + mz_uint16 ret; + memcpy(&ret, p, sizeof(mz_uint16)); + return ret; +} +#else +#define TDEFL_READ_UNALIGNED_WORD(p) *(const mz_uint16 *)(p) +#define TDEFL_READ_UNALIGNED_WORD2(p) *(const mz_uint16 *)(p) +#endif +static MZ_FORCEINLINE void tdefl_find_match(tdefl_compressor *d, mz_uint lookahead_pos, mz_uint max_dist, mz_uint max_match_len, mz_uint *pMatch_dist, mz_uint *pMatch_len) +{ + mz_uint dist, pos = lookahead_pos & TDEFL_LZ_DICT_SIZE_MASK, match_len = *pMatch_len, probe_pos = pos, next_probe_pos, probe_len; + mz_uint num_probes_left = d->m_max_probes[match_len >= 32]; + const mz_uint16 *s = (const mz_uint16 *)(d->m_dict + pos), *p, *q; + mz_uint16 c01 = TDEFL_READ_UNALIGNED_WORD(&d->m_dict[pos + match_len - 1]), s01 = TDEFL_READ_UNALIGNED_WORD2(s); + MZ_ASSERT(max_match_len <= TDEFL_MAX_MATCH_LEN); + if (max_match_len <= match_len) + return; + for (;;) + { + for (;;) + { + if (--num_probes_left == 0) + return; +#define TDEFL_PROBE \ + next_probe_pos = d->m_next[probe_pos]; \ + if ((!next_probe_pos) || ((dist = (mz_uint16)(lookahead_pos - next_probe_pos)) > max_dist)) \ + return; \ + probe_pos = next_probe_pos & TDEFL_LZ_DICT_SIZE_MASK; \ + if (TDEFL_READ_UNALIGNED_WORD(&d->m_dict[probe_pos + match_len - 1]) == c01) \ + break; + TDEFL_PROBE; + TDEFL_PROBE; + TDEFL_PROBE; + } + if (!dist) + break; + q = (const mz_uint16 *)(d->m_dict + probe_pos); + if (TDEFL_READ_UNALIGNED_WORD2(q) != s01) + continue; + p = s; + probe_len = 32; + do + { + } while ((TDEFL_READ_UNALIGNED_WORD2(++p) == TDEFL_READ_UNALIGNED_WORD2(++q)) && (TDEFL_READ_UNALIGNED_WORD2(++p) == TDEFL_READ_UNALIGNED_WORD2(++q)) && + (TDEFL_READ_UNALIGNED_WORD2(++p) == TDEFL_READ_UNALIGNED_WORD2(++q)) && (TDEFL_READ_UNALIGNED_WORD2(++p) == TDEFL_READ_UNALIGNED_WORD2(++q)) && (--probe_len > 0)); + if (!probe_len) + { + *pMatch_dist = dist; + *pMatch_len = MZ_MIN(max_match_len, (mz_uint)TDEFL_MAX_MATCH_LEN); + break; + } + else if ((probe_len = ((mz_uint)(p - s) * 2) + (mz_uint)(*(const mz_uint8 *)p == *(const mz_uint8 *)q)) > match_len) + { + *pMatch_dist = dist; + if ((*pMatch_len = match_len = MZ_MIN(max_match_len, probe_len)) == max_match_len) + break; + c01 = TDEFL_READ_UNALIGNED_WORD(&d->m_dict[pos + match_len - 1]); + } + } +} +#else +static MZ_FORCEINLINE void tdefl_find_match(tdefl_compressor *d, mz_uint lookahead_pos, mz_uint max_dist, mz_uint max_match_len, mz_uint *pMatch_dist, mz_uint *pMatch_len) +{ + mz_uint dist, pos = lookahead_pos & TDEFL_LZ_DICT_SIZE_MASK, match_len = *pMatch_len, probe_pos = pos, next_probe_pos, probe_len; + mz_uint num_probes_left = d->m_max_probes[match_len >= 32]; + const mz_uint8 *s = d->m_dict + pos, *p, *q; + mz_uint8 c0 = d->m_dict[pos + match_len], c1 = d->m_dict[pos + match_len - 1]; + MZ_ASSERT(max_match_len <= TDEFL_MAX_MATCH_LEN); + if (max_match_len <= match_len) + return; + for (;;) + { + for (;;) + { + if (--num_probes_left == 0) + return; +#define TDEFL_PROBE \ + next_probe_pos = d->m_next[probe_pos]; \ + if ((!next_probe_pos) || ((dist = (mz_uint16)(lookahead_pos - next_probe_pos)) > max_dist)) \ + return; \ + probe_pos = next_probe_pos & TDEFL_LZ_DICT_SIZE_MASK; \ + if ((d->m_dict[probe_pos + match_len] == c0) && (d->m_dict[probe_pos + match_len - 1] == c1)) \ + break; + TDEFL_PROBE; + TDEFL_PROBE; + TDEFL_PROBE; + } + if (!dist) + break; + p = s; + q = d->m_dict + probe_pos; + for (probe_len = 0; probe_len < max_match_len; probe_len++) + if (*p++ != *q++) + break; + if (probe_len > match_len) + { + *pMatch_dist = dist; + if ((*pMatch_len = match_len = probe_len) == max_match_len) + return; + c0 = d->m_dict[pos + match_len]; + c1 = d->m_dict[pos + match_len - 1]; + } + } +} +#endif /* #if MINIZ_USE_UNALIGNED_LOADS_AND_STORES */ + +#if MINIZ_USE_UNALIGNED_LOADS_AND_STORES && MINIZ_LITTLE_ENDIAN +static mz_bool tdefl_compress_fast(tdefl_compressor *d) +{ + /* Faster, minimally featured LZRW1-style match+parse loop with better register utilization. Intended for applications where raw throughput is valued more highly than ratio. */ + mz_uint lookahead_pos = d->m_lookahead_pos, lookahead_size = d->m_lookahead_size, dict_size = d->m_dict_size, total_lz_bytes = d->m_total_lz_bytes, num_flags_left = d->m_num_flags_left; + mz_uint8 *pLZ_code_buf = d->m_pLZ_code_buf, *pLZ_flags = d->m_pLZ_flags; + mz_uint cur_pos = lookahead_pos & TDEFL_LZ_DICT_SIZE_MASK; + + while ((d->m_src_buf_left) || ((d->m_flush) && (lookahead_size))) + { + const mz_uint TDEFL_COMP_FAST_LOOKAHEAD_SIZE = 4096; + mz_uint dst_pos = (lookahead_pos + lookahead_size) & TDEFL_LZ_DICT_SIZE_MASK; + mz_uint num_bytes_to_process = (mz_uint)MZ_MIN(d->m_src_buf_left, TDEFL_COMP_FAST_LOOKAHEAD_SIZE - lookahead_size); + d->m_src_buf_left -= num_bytes_to_process; + lookahead_size += num_bytes_to_process; + + while (num_bytes_to_process) + { + mz_uint32 n = MZ_MIN(TDEFL_LZ_DICT_SIZE - dst_pos, num_bytes_to_process); + memcpy(d->m_dict + dst_pos, d->m_pSrc, n); + if (dst_pos < (TDEFL_MAX_MATCH_LEN - 1)) + memcpy(d->m_dict + TDEFL_LZ_DICT_SIZE + dst_pos, d->m_pSrc, MZ_MIN(n, (TDEFL_MAX_MATCH_LEN - 1) - dst_pos)); + d->m_pSrc += n; + dst_pos = (dst_pos + n) & TDEFL_LZ_DICT_SIZE_MASK; + num_bytes_to_process -= n; + } + + dict_size = MZ_MIN(TDEFL_LZ_DICT_SIZE - lookahead_size, dict_size); + if ((!d->m_flush) && (lookahead_size < TDEFL_COMP_FAST_LOOKAHEAD_SIZE)) + break; + + while (lookahead_size >= 4) + { + mz_uint cur_match_dist, cur_match_len = 1; + mz_uint8 *pCur_dict = d->m_dict + cur_pos; + mz_uint first_trigram = (*(const mz_uint32 *)pCur_dict) & 0xFFFFFF; + mz_uint hash = (first_trigram ^ (first_trigram >> (24 - (TDEFL_LZ_HASH_BITS - 8)))) & TDEFL_LEVEL1_HASH_SIZE_MASK; + mz_uint probe_pos = d->m_hash[hash]; + d->m_hash[hash] = (mz_uint16)lookahead_pos; + + if (((cur_match_dist = (mz_uint16)(lookahead_pos - probe_pos)) <= dict_size) && ((*(const mz_uint32 *)(d->m_dict + (probe_pos &= TDEFL_LZ_DICT_SIZE_MASK)) & 0xFFFFFF) == first_trigram)) + { + const mz_uint16 *p = (const mz_uint16 *)pCur_dict; + const mz_uint16 *q = (const mz_uint16 *)(d->m_dict + probe_pos); + mz_uint32 probe_len = 32; + do + { + } while ((TDEFL_READ_UNALIGNED_WORD2(++p) == TDEFL_READ_UNALIGNED_WORD2(++q)) && (TDEFL_READ_UNALIGNED_WORD2(++p) == TDEFL_READ_UNALIGNED_WORD2(++q)) && + (TDEFL_READ_UNALIGNED_WORD2(++p) == TDEFL_READ_UNALIGNED_WORD2(++q)) && (TDEFL_READ_UNALIGNED_WORD2(++p) == TDEFL_READ_UNALIGNED_WORD2(++q)) && (--probe_len > 0)); + cur_match_len = ((mz_uint)(p - (const mz_uint16 *)pCur_dict) * 2) + (mz_uint)(*(const mz_uint8 *)p == *(const mz_uint8 *)q); + if (!probe_len) + cur_match_len = cur_match_dist ? TDEFL_MAX_MATCH_LEN : 0; + + if ((cur_match_len < TDEFL_MIN_MATCH_LEN) || ((cur_match_len == TDEFL_MIN_MATCH_LEN) && (cur_match_dist >= 8U * 1024U))) + { + cur_match_len = 1; + *pLZ_code_buf++ = (mz_uint8)first_trigram; + *pLZ_flags = (mz_uint8)(*pLZ_flags >> 1); + d->m_huff_count[0][(mz_uint8)first_trigram]++; + } + else + { + mz_uint32 s0, s1; + cur_match_len = MZ_MIN(cur_match_len, lookahead_size); + + MZ_ASSERT((cur_match_len >= TDEFL_MIN_MATCH_LEN) && (cur_match_dist >= 1) && (cur_match_dist <= TDEFL_LZ_DICT_SIZE)); + + cur_match_dist--; + + pLZ_code_buf[0] = (mz_uint8)(cur_match_len - TDEFL_MIN_MATCH_LEN); + *(mz_uint16 *)(&pLZ_code_buf[1]) = (mz_uint16)cur_match_dist; + pLZ_code_buf += 3; + *pLZ_flags = (mz_uint8)((*pLZ_flags >> 1) | 0x80); + + s0 = s_tdefl_small_dist_sym[cur_match_dist & 511]; + s1 = s_tdefl_large_dist_sym[cur_match_dist >> 8]; + d->m_huff_count[1][(cur_match_dist < 512) ? s0 : s1]++; + + d->m_huff_count[0][s_tdefl_len_sym[cur_match_len - TDEFL_MIN_MATCH_LEN]]++; + } + } + else + { + *pLZ_code_buf++ = (mz_uint8)first_trigram; + *pLZ_flags = (mz_uint8)(*pLZ_flags >> 1); + d->m_huff_count[0][(mz_uint8)first_trigram]++; + } + + if (--num_flags_left == 0) + { + num_flags_left = 8; + pLZ_flags = pLZ_code_buf++; + } + + total_lz_bytes += cur_match_len; + lookahead_pos += cur_match_len; + dict_size = MZ_MIN(dict_size + cur_match_len, (mz_uint)TDEFL_LZ_DICT_SIZE); + cur_pos = (cur_pos + cur_match_len) & TDEFL_LZ_DICT_SIZE_MASK; + MZ_ASSERT(lookahead_size >= cur_match_len); + lookahead_size -= cur_match_len; + + if (pLZ_code_buf > &d->m_lz_code_buf[TDEFL_LZ_CODE_BUF_SIZE - 8]) + { + int n; + d->m_lookahead_pos = lookahead_pos; + d->m_lookahead_size = lookahead_size; + d->m_dict_size = dict_size; + d->m_total_lz_bytes = total_lz_bytes; + d->m_pLZ_code_buf = pLZ_code_buf; + d->m_pLZ_flags = pLZ_flags; + d->m_num_flags_left = num_flags_left; + if ((n = tdefl_flush_block(d, 0)) != 0) + return (n < 0) ? MZ_FALSE : MZ_TRUE; + total_lz_bytes = d->m_total_lz_bytes; + pLZ_code_buf = d->m_pLZ_code_buf; + pLZ_flags = d->m_pLZ_flags; + num_flags_left = d->m_num_flags_left; + } + } + + while (lookahead_size) + { + mz_uint8 lit = d->m_dict[cur_pos]; + + total_lz_bytes++; + *pLZ_code_buf++ = lit; + *pLZ_flags = (mz_uint8)(*pLZ_flags >> 1); + if (--num_flags_left == 0) + { + num_flags_left = 8; + pLZ_flags = pLZ_code_buf++; + } + + d->m_huff_count[0][lit]++; + + lookahead_pos++; + dict_size = MZ_MIN(dict_size + 1, (mz_uint)TDEFL_LZ_DICT_SIZE); + cur_pos = (cur_pos + 1) & TDEFL_LZ_DICT_SIZE_MASK; + lookahead_size--; + + if (pLZ_code_buf > &d->m_lz_code_buf[TDEFL_LZ_CODE_BUF_SIZE - 8]) + { + int n; + d->m_lookahead_pos = lookahead_pos; + d->m_lookahead_size = lookahead_size; + d->m_dict_size = dict_size; + d->m_total_lz_bytes = total_lz_bytes; + d->m_pLZ_code_buf = pLZ_code_buf; + d->m_pLZ_flags = pLZ_flags; + d->m_num_flags_left = num_flags_left; + if ((n = tdefl_flush_block(d, 0)) != 0) + return (n < 0) ? MZ_FALSE : MZ_TRUE; + total_lz_bytes = d->m_total_lz_bytes; + pLZ_code_buf = d->m_pLZ_code_buf; + pLZ_flags = d->m_pLZ_flags; + num_flags_left = d->m_num_flags_left; + } + } + } + + d->m_lookahead_pos = lookahead_pos; + d->m_lookahead_size = lookahead_size; + d->m_dict_size = dict_size; + d->m_total_lz_bytes = total_lz_bytes; + d->m_pLZ_code_buf = pLZ_code_buf; + d->m_pLZ_flags = pLZ_flags; + d->m_num_flags_left = num_flags_left; + return MZ_TRUE; +} +#endif /* MINIZ_USE_UNALIGNED_LOADS_AND_STORES && MINIZ_LITTLE_ENDIAN */ + +static MZ_FORCEINLINE void tdefl_record_literal(tdefl_compressor *d, mz_uint8 lit) +{ + d->m_total_lz_bytes++; + *d->m_pLZ_code_buf++ = lit; + *d->m_pLZ_flags = (mz_uint8)(*d->m_pLZ_flags >> 1); + if (--d->m_num_flags_left == 0) + { + d->m_num_flags_left = 8; + d->m_pLZ_flags = d->m_pLZ_code_buf++; + } + d->m_huff_count[0][lit]++; +} + +static MZ_FORCEINLINE void tdefl_record_match(tdefl_compressor *d, mz_uint match_len, mz_uint match_dist) +{ + mz_uint32 s0, s1; + + MZ_ASSERT((match_len >= TDEFL_MIN_MATCH_LEN) && (match_dist >= 1) && (match_dist <= TDEFL_LZ_DICT_SIZE)); + + d->m_total_lz_bytes += match_len; + + d->m_pLZ_code_buf[0] = (mz_uint8)(match_len - TDEFL_MIN_MATCH_LEN); + + match_dist -= 1; + d->m_pLZ_code_buf[1] = (mz_uint8)(match_dist & 0xFF); + d->m_pLZ_code_buf[2] = (mz_uint8)(match_dist >> 8); + d->m_pLZ_code_buf += 3; + + *d->m_pLZ_flags = (mz_uint8)((*d->m_pLZ_flags >> 1) | 0x80); + if (--d->m_num_flags_left == 0) + { + d->m_num_flags_left = 8; + d->m_pLZ_flags = d->m_pLZ_code_buf++; + } + + s0 = s_tdefl_small_dist_sym[match_dist & 511]; + s1 = s_tdefl_large_dist_sym[(match_dist >> 8) & 127]; + d->m_huff_count[1][(match_dist < 512) ? s0 : s1]++; + + if (match_len >= TDEFL_MIN_MATCH_LEN) + d->m_huff_count[0][s_tdefl_len_sym[match_len - TDEFL_MIN_MATCH_LEN]]++; +} + +static mz_bool tdefl_compress_normal(tdefl_compressor *d) +{ + const mz_uint8 *pSrc = d->m_pSrc; + size_t src_buf_left = d->m_src_buf_left; + tdefl_flush flush = d->m_flush; + + while ((src_buf_left) || ((flush) && (d->m_lookahead_size))) + { + mz_uint len_to_move, cur_match_dist, cur_match_len, cur_pos; + /* Update dictionary and hash chains. Keeps the lookahead size equal to TDEFL_MAX_MATCH_LEN. */ + if ((d->m_lookahead_size + d->m_dict_size) >= (TDEFL_MIN_MATCH_LEN - 1)) + { + mz_uint dst_pos = (d->m_lookahead_pos + d->m_lookahead_size) & TDEFL_LZ_DICT_SIZE_MASK, ins_pos = d->m_lookahead_pos + d->m_lookahead_size - 2; + mz_uint hash = (d->m_dict[ins_pos & TDEFL_LZ_DICT_SIZE_MASK] << TDEFL_LZ_HASH_SHIFT) ^ d->m_dict[(ins_pos + 1) & TDEFL_LZ_DICT_SIZE_MASK]; + mz_uint num_bytes_to_process = (mz_uint)MZ_MIN(src_buf_left, TDEFL_MAX_MATCH_LEN - d->m_lookahead_size); + const mz_uint8 *pSrc_end = pSrc + num_bytes_to_process; + src_buf_left -= num_bytes_to_process; + d->m_lookahead_size += num_bytes_to_process; + while (pSrc != pSrc_end) + { + mz_uint8 c = *pSrc++; + d->m_dict[dst_pos] = c; + if (dst_pos < (TDEFL_MAX_MATCH_LEN - 1)) + d->m_dict[TDEFL_LZ_DICT_SIZE + dst_pos] = c; + hash = ((hash << TDEFL_LZ_HASH_SHIFT) ^ c) & (TDEFL_LZ_HASH_SIZE - 1); + d->m_next[ins_pos & TDEFL_LZ_DICT_SIZE_MASK] = d->m_hash[hash]; + d->m_hash[hash] = (mz_uint16)(ins_pos); + dst_pos = (dst_pos + 1) & TDEFL_LZ_DICT_SIZE_MASK; + ins_pos++; + } + } + else + { + while ((src_buf_left) && (d->m_lookahead_size < TDEFL_MAX_MATCH_LEN)) + { + mz_uint8 c = *pSrc++; + mz_uint dst_pos = (d->m_lookahead_pos + d->m_lookahead_size) & TDEFL_LZ_DICT_SIZE_MASK; + src_buf_left--; + d->m_dict[dst_pos] = c; + if (dst_pos < (TDEFL_MAX_MATCH_LEN - 1)) + d->m_dict[TDEFL_LZ_DICT_SIZE + dst_pos] = c; + if ((++d->m_lookahead_size + d->m_dict_size) >= TDEFL_MIN_MATCH_LEN) + { + mz_uint ins_pos = d->m_lookahead_pos + (d->m_lookahead_size - 1) - 2; + mz_uint hash = ((d->m_dict[ins_pos & TDEFL_LZ_DICT_SIZE_MASK] << (TDEFL_LZ_HASH_SHIFT * 2)) ^ (d->m_dict[(ins_pos + 1) & TDEFL_LZ_DICT_SIZE_MASK] << TDEFL_LZ_HASH_SHIFT) ^ c) & (TDEFL_LZ_HASH_SIZE - 1); + d->m_next[ins_pos & TDEFL_LZ_DICT_SIZE_MASK] = d->m_hash[hash]; + d->m_hash[hash] = (mz_uint16)(ins_pos); + } + } + } + d->m_dict_size = MZ_MIN(TDEFL_LZ_DICT_SIZE - d->m_lookahead_size, d->m_dict_size); + if ((!flush) && (d->m_lookahead_size < TDEFL_MAX_MATCH_LEN)) + break; + + /* Simple lazy/greedy parsing state machine. */ + len_to_move = 1; + cur_match_dist = 0; + cur_match_len = d->m_saved_match_len ? d->m_saved_match_len : (TDEFL_MIN_MATCH_LEN - 1); + cur_pos = d->m_lookahead_pos & TDEFL_LZ_DICT_SIZE_MASK; + if (d->m_flags & (TDEFL_RLE_MATCHES | TDEFL_FORCE_ALL_RAW_BLOCKS)) + { + if ((d->m_dict_size) && (!(d->m_flags & TDEFL_FORCE_ALL_RAW_BLOCKS))) + { + mz_uint8 c = d->m_dict[(cur_pos - 1) & TDEFL_LZ_DICT_SIZE_MASK]; + cur_match_len = 0; + while (cur_match_len < d->m_lookahead_size) + { + if (d->m_dict[cur_pos + cur_match_len] != c) + break; + cur_match_len++; + } + if (cur_match_len < TDEFL_MIN_MATCH_LEN) + cur_match_len = 0; + else + cur_match_dist = 1; + } + } + else + { + tdefl_find_match(d, d->m_lookahead_pos, d->m_dict_size, d->m_lookahead_size, &cur_match_dist, &cur_match_len); + } + if (((cur_match_len == TDEFL_MIN_MATCH_LEN) && (cur_match_dist >= 8U * 1024U)) || (cur_pos == cur_match_dist) || ((d->m_flags & TDEFL_FILTER_MATCHES) && (cur_match_len <= 5))) + { + cur_match_dist = cur_match_len = 0; + } + if (d->m_saved_match_len) + { + if (cur_match_len > d->m_saved_match_len) + { + tdefl_record_literal(d, (mz_uint8)d->m_saved_lit); + if (cur_match_len >= 128) + { + tdefl_record_match(d, cur_match_len, cur_match_dist); + d->m_saved_match_len = 0; + len_to_move = cur_match_len; + } + else + { + d->m_saved_lit = d->m_dict[cur_pos]; + d->m_saved_match_dist = cur_match_dist; + d->m_saved_match_len = cur_match_len; + } + } + else + { + tdefl_record_match(d, d->m_saved_match_len, d->m_saved_match_dist); + len_to_move = d->m_saved_match_len - 1; + d->m_saved_match_len = 0; + } + } + else if (!cur_match_dist) + tdefl_record_literal(d, d->m_dict[MZ_MIN(cur_pos, sizeof(d->m_dict) - 1)]); + else if ((d->m_greedy_parsing) || (d->m_flags & TDEFL_RLE_MATCHES) || (cur_match_len >= 128)) + { + tdefl_record_match(d, cur_match_len, cur_match_dist); + len_to_move = cur_match_len; + } + else + { + d->m_saved_lit = d->m_dict[MZ_MIN(cur_pos, sizeof(d->m_dict) - 1)]; + d->m_saved_match_dist = cur_match_dist; + d->m_saved_match_len = cur_match_len; + } + /* Move the lookahead forward by len_to_move bytes. */ + d->m_lookahead_pos += len_to_move; + MZ_ASSERT(d->m_lookahead_size >= len_to_move); + d->m_lookahead_size -= len_to_move; + d->m_dict_size = MZ_MIN(d->m_dict_size + len_to_move, (mz_uint)TDEFL_LZ_DICT_SIZE); + /* Check if it's time to flush the current LZ codes to the internal output buffer. */ + if ((d->m_pLZ_code_buf > &d->m_lz_code_buf[TDEFL_LZ_CODE_BUF_SIZE - 8]) || + ((d->m_total_lz_bytes > 31 * 1024) && (((((mz_uint)(d->m_pLZ_code_buf - d->m_lz_code_buf) * 115) >> 7) >= d->m_total_lz_bytes) || (d->m_flags & TDEFL_FORCE_ALL_RAW_BLOCKS)))) + { + int n; + d->m_pSrc = pSrc; + d->m_src_buf_left = src_buf_left; + if ((n = tdefl_flush_block(d, 0)) != 0) + return (n < 0) ? MZ_FALSE : MZ_TRUE; + } + } + + d->m_pSrc = pSrc; + d->m_src_buf_left = src_buf_left; + return MZ_TRUE; +} + +static tdefl_status tdefl_flush_output_buffer(tdefl_compressor *d) +{ + if (d->m_pIn_buf_size) + { + *d->m_pIn_buf_size = d->m_pSrc - (const mz_uint8 *)d->m_pIn_buf; + } + + if (d->m_pOut_buf_size) + { + size_t n = MZ_MIN(*d->m_pOut_buf_size - d->m_out_buf_ofs, d->m_output_flush_remaining); + memcpy((mz_uint8 *)d->m_pOut_buf + d->m_out_buf_ofs, d->m_output_buf + d->m_output_flush_ofs, n); + d->m_output_flush_ofs += (mz_uint)n; + d->m_output_flush_remaining -= (mz_uint)n; + d->m_out_buf_ofs += n; + + *d->m_pOut_buf_size = d->m_out_buf_ofs; + } + + return (d->m_finished && !d->m_output_flush_remaining) ? TDEFL_STATUS_DONE : TDEFL_STATUS_OKAY; +} + +tdefl_status tdefl_compress(tdefl_compressor *d, const void *pIn_buf, size_t *pIn_buf_size, void *pOut_buf, size_t *pOut_buf_size, tdefl_flush flush) +{ + if (!d) + { + if (pIn_buf_size) + *pIn_buf_size = 0; + if (pOut_buf_size) + *pOut_buf_size = 0; + return TDEFL_STATUS_BAD_PARAM; + } + + d->m_pIn_buf = pIn_buf; + d->m_pIn_buf_size = pIn_buf_size; + d->m_pOut_buf = pOut_buf; + d->m_pOut_buf_size = pOut_buf_size; + d->m_pSrc = (const mz_uint8 *)(pIn_buf); + d->m_src_buf_left = pIn_buf_size ? *pIn_buf_size : 0; + d->m_out_buf_ofs = 0; + d->m_flush = flush; + + if (((d->m_pPut_buf_func != NULL) == ((pOut_buf != NULL) || (pOut_buf_size != NULL))) || (d->m_prev_return_status != TDEFL_STATUS_OKAY) || + (d->m_wants_to_finish && (flush != TDEFL_FINISH)) || (pIn_buf_size && *pIn_buf_size && !pIn_buf) || (pOut_buf_size && *pOut_buf_size && !pOut_buf)) + { + if (pIn_buf_size) + *pIn_buf_size = 0; + if (pOut_buf_size) + *pOut_buf_size = 0; + return (d->m_prev_return_status = TDEFL_STATUS_BAD_PARAM); + } + d->m_wants_to_finish |= (flush == TDEFL_FINISH); + + if ((d->m_output_flush_remaining) || (d->m_finished)) + return (d->m_prev_return_status = tdefl_flush_output_buffer(d)); + +#if MINIZ_USE_UNALIGNED_LOADS_AND_STORES && MINIZ_LITTLE_ENDIAN + if (((d->m_flags & TDEFL_MAX_PROBES_MASK) == 1) && + ((d->m_flags & TDEFL_GREEDY_PARSING_FLAG) != 0) && + ((d->m_flags & (TDEFL_FILTER_MATCHES | TDEFL_FORCE_ALL_RAW_BLOCKS | TDEFL_RLE_MATCHES)) == 0)) + { + if (!tdefl_compress_fast(d)) + return d->m_prev_return_status; + } + else +#endif /* #if MINIZ_USE_UNALIGNED_LOADS_AND_STORES && MINIZ_LITTLE_ENDIAN */ + { + if (!tdefl_compress_normal(d)) + return d->m_prev_return_status; + } + + if ((d->m_flags & (TDEFL_WRITE_ZLIB_HEADER | TDEFL_COMPUTE_ADLER32)) && (pIn_buf)) + d->m_adler32 = (mz_uint32)mz_adler32(d->m_adler32, (const mz_uint8 *)pIn_buf, d->m_pSrc - (const mz_uint8 *)pIn_buf); + + if ((flush) && (!d->m_lookahead_size) && (!d->m_src_buf_left) && (!d->m_output_flush_remaining)) + { + if (tdefl_flush_block(d, flush) < 0) + return d->m_prev_return_status; + d->m_finished = (flush == TDEFL_FINISH); + if (flush == TDEFL_FULL_FLUSH) + { + MZ_CLEAR_OBJ(d->m_hash); + MZ_CLEAR_OBJ(d->m_next); + d->m_dict_size = 0; + } + } + + return (d->m_prev_return_status = tdefl_flush_output_buffer(d)); +} + +tdefl_status tdefl_compress_buffer(tdefl_compressor *d, const void *pIn_buf, size_t in_buf_size, tdefl_flush flush) +{ + MZ_ASSERT(d->m_pPut_buf_func); + return tdefl_compress(d, pIn_buf, &in_buf_size, NULL, NULL, flush); +} + +tdefl_status tdefl_init(tdefl_compressor *d, tdefl_put_buf_func_ptr pPut_buf_func, void *pPut_buf_user, int flags) +{ + d->m_pPut_buf_func = pPut_buf_func; + d->m_pPut_buf_user = pPut_buf_user; + d->m_flags = (mz_uint)(flags); + d->m_max_probes[0] = 1 + ((flags & 0xFFF) + 2) / 3; + d->m_greedy_parsing = (flags & TDEFL_GREEDY_PARSING_FLAG) != 0; + d->m_max_probes[1] = 1 + (((flags & 0xFFF) >> 2) + 2) / 3; + if (!(flags & TDEFL_NONDETERMINISTIC_PARSING_FLAG)) + MZ_CLEAR_OBJ(d->m_hash); + d->m_lookahead_pos = d->m_lookahead_size = d->m_dict_size = d->m_total_lz_bytes = d->m_lz_code_buf_dict_pos = d->m_bits_in = 0; + d->m_output_flush_ofs = d->m_output_flush_remaining = d->m_finished = d->m_block_index = d->m_bit_buffer = d->m_wants_to_finish = 0; + d->m_pLZ_code_buf = d->m_lz_code_buf + 1; + d->m_pLZ_flags = d->m_lz_code_buf; + d->m_num_flags_left = 8; + d->m_pOutput_buf = d->m_output_buf; + d->m_pOutput_buf_end = d->m_output_buf; + d->m_prev_return_status = TDEFL_STATUS_OKAY; + d->m_saved_match_dist = d->m_saved_match_len = d->m_saved_lit = 0; + d->m_adler32 = 1; + d->m_pIn_buf = NULL; + d->m_pOut_buf = NULL; + d->m_pIn_buf_size = NULL; + d->m_pOut_buf_size = NULL; + d->m_flush = TDEFL_NO_FLUSH; + d->m_pSrc = NULL; + d->m_src_buf_left = 0; + d->m_out_buf_ofs = 0; + if (!(flags & TDEFL_NONDETERMINISTIC_PARSING_FLAG)) + MZ_CLEAR_OBJ(d->m_dict); + memset(&d->m_huff_count[0][0], 0, sizeof(d->m_huff_count[0][0]) * TDEFL_MAX_HUFF_SYMBOLS_0); + memset(&d->m_huff_count[1][0], 0, sizeof(d->m_huff_count[1][0]) * TDEFL_MAX_HUFF_SYMBOLS_1); + return TDEFL_STATUS_OKAY; +} + +tdefl_status tdefl_get_prev_return_status(tdefl_compressor *d) +{ + return d->m_prev_return_status; +} + +mz_uint32 tdefl_get_adler32(tdefl_compressor *d) +{ + return d->m_adler32; +} + +mz_bool tdefl_compress_mem_to_output(const void *pBuf, size_t buf_len, tdefl_put_buf_func_ptr pPut_buf_func, void *pPut_buf_user, int flags) +{ + tdefl_compressor *pComp; + mz_bool succeeded; + if (((buf_len) && (!pBuf)) || (!pPut_buf_func)) + return MZ_FALSE; + pComp = (tdefl_compressor *)MZ_MALLOC(sizeof(tdefl_compressor)); + if (!pComp) + return MZ_FALSE; + succeeded = (tdefl_init(pComp, pPut_buf_func, pPut_buf_user, flags) == TDEFL_STATUS_OKAY); + succeeded = succeeded && (tdefl_compress_buffer(pComp, pBuf, buf_len, TDEFL_FINISH) == TDEFL_STATUS_DONE); + MZ_FREE(pComp); + return succeeded; +} + +typedef struct +{ + size_t m_size, m_capacity; + mz_uint8 *m_pBuf; + mz_bool m_expandable; +} tdefl_output_buffer; + +static mz_bool tdefl_output_buffer_putter(const void *pBuf, int len, void *pUser) +{ + tdefl_output_buffer *p = (tdefl_output_buffer *)pUser; + size_t new_size = p->m_size + len; + if (new_size > p->m_capacity) + { + size_t new_capacity = p->m_capacity; + mz_uint8 *pNew_buf; + if (!p->m_expandable) + return MZ_FALSE; + do + { + new_capacity = MZ_MAX(128U, new_capacity << 1U); + } while (new_size > new_capacity); + pNew_buf = (mz_uint8 *)MZ_REALLOC(p->m_pBuf, new_capacity); + if (!pNew_buf) + return MZ_FALSE; + p->m_pBuf = pNew_buf; + p->m_capacity = new_capacity; + } + memcpy((mz_uint8 *)p->m_pBuf + p->m_size, pBuf, len); + p->m_size = new_size; + return MZ_TRUE; +} + +void *tdefl_compress_mem_to_heap(const void *pSrc_buf, size_t src_buf_len, size_t *pOut_len, int flags) +{ + tdefl_output_buffer out_buf; + MZ_CLEAR_OBJ(out_buf); + if (!pOut_len) + return MZ_FALSE; + else + *pOut_len = 0; + out_buf.m_expandable = MZ_TRUE; + if (!tdefl_compress_mem_to_output(pSrc_buf, src_buf_len, tdefl_output_buffer_putter, &out_buf, flags)) + return NULL; + *pOut_len = out_buf.m_size; + return out_buf.m_pBuf; +} + +size_t tdefl_compress_mem_to_mem(void *pOut_buf, size_t out_buf_len, const void *pSrc_buf, size_t src_buf_len, int flags) +{ + tdefl_output_buffer out_buf; + MZ_CLEAR_OBJ(out_buf); + if (!pOut_buf) + return 0; + out_buf.m_pBuf = (mz_uint8 *)pOut_buf; + out_buf.m_capacity = out_buf_len; + if (!tdefl_compress_mem_to_output(pSrc_buf, src_buf_len, tdefl_output_buffer_putter, &out_buf, flags)) + return 0; + return out_buf.m_size; +} + +static const mz_uint s_tdefl_num_probes[11] = { 0, 1, 6, 32, 16, 32, 128, 256, 512, 768, 1500 }; + +/* level may actually range from [0,10] (10 is a "hidden" max level, where we want a bit more compression and it's fine if throughput to fall off a cliff on some files). */ +mz_uint tdefl_create_comp_flags_from_zip_params(int level, int window_bits, int strategy) +{ + mz_uint comp_flags = s_tdefl_num_probes[(level >= 0) ? MZ_MIN(10, level) : MZ_DEFAULT_LEVEL] | ((level <= 3) ? TDEFL_GREEDY_PARSING_FLAG : 0); + if (window_bits > 0) + comp_flags |= TDEFL_WRITE_ZLIB_HEADER; + + if (!level) + comp_flags |= TDEFL_FORCE_ALL_RAW_BLOCKS; + else if (strategy == MZ_FILTERED) + comp_flags |= TDEFL_FILTER_MATCHES; + else if (strategy == MZ_HUFFMAN_ONLY) + comp_flags &= ~TDEFL_MAX_PROBES_MASK; + else if (strategy == MZ_FIXED) + comp_flags |= TDEFL_FORCE_ALL_STATIC_BLOCKS; + else if (strategy == MZ_RLE) + comp_flags |= TDEFL_RLE_MATCHES; + + return comp_flags; +} + +#ifdef _MSC_VER +#pragma warning(push) +#pragma warning(disable : 4204) /* nonstandard extension used : non-constant aggregate initializer (also supported by GNU C and C99, so no big deal) */ +#endif + +/* Simple PNG writer function by Alex Evans, 2011. Released into the public domain: https://gist.github.com/908299, more context at + http://altdevblogaday.org/2011/04/06/a-smaller-jpg-encoder/. + This is actually a modification of Alex's original code so PNG files generated by this function pass pngcheck. */ +void *tdefl_write_image_to_png_file_in_memory_ex(const void *pImage, int w, int h, int num_chans, size_t *pLen_out, mz_uint level, mz_bool flip) +{ + /* Using a local copy of this array here in case MINIZ_NO_ZLIB_APIS was defined. */ + static const mz_uint s_tdefl_png_num_probes[11] = { 0, 1, 6, 32, 16, 32, 128, 256, 512, 768, 1500 }; + tdefl_compressor *pComp = (tdefl_compressor *)MZ_MALLOC(sizeof(tdefl_compressor)); + tdefl_output_buffer out_buf; + int i, bpl = w * num_chans, y, z; + mz_uint32 c; + *pLen_out = 0; + if (!pComp) + return NULL; + MZ_CLEAR_OBJ(out_buf); + out_buf.m_expandable = MZ_TRUE; + out_buf.m_capacity = 57 + MZ_MAX(64, (1 + bpl) * h); + if (NULL == (out_buf.m_pBuf = (mz_uint8 *)MZ_MALLOC(out_buf.m_capacity))) + { + MZ_FREE(pComp); + return NULL; + } + /* write dummy header */ + for (z = 41; z; --z) + tdefl_output_buffer_putter(&z, 1, &out_buf); + /* compress image data */ + tdefl_init(pComp, tdefl_output_buffer_putter, &out_buf, s_tdefl_png_num_probes[MZ_MIN(10, level)] | TDEFL_WRITE_ZLIB_HEADER); + for (y = 0; y < h; ++y) + { + tdefl_compress_buffer(pComp, &z, 1, TDEFL_NO_FLUSH); + tdefl_compress_buffer(pComp, (mz_uint8 *)pImage + (flip ? (h - 1 - y) : y) * bpl, bpl, TDEFL_NO_FLUSH); + } + if (tdefl_compress_buffer(pComp, NULL, 0, TDEFL_FINISH) != TDEFL_STATUS_DONE) + { + MZ_FREE(pComp); + MZ_FREE(out_buf.m_pBuf); + return NULL; + } + /* write real header */ + *pLen_out = out_buf.m_size - 41; + { + static const mz_uint8 chans[] = { 0x00, 0x00, 0x04, 0x02, 0x06 }; + mz_uint8 pnghdr[41] = { 0x89, 0x50, 0x4e, 0x47, 0x0d, + 0x0a, 0x1a, 0x0a, 0x00, 0x00, + 0x00, 0x0d, 0x49, 0x48, 0x44, + 0x52, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x08, + 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x49, 0x44, 0x41, + 0x54 }; + pnghdr[18] = (mz_uint8)(w >> 8); + pnghdr[19] = (mz_uint8)w; + pnghdr[22] = (mz_uint8)(h >> 8); + pnghdr[23] = (mz_uint8)h; + pnghdr[25] = chans[num_chans]; + pnghdr[33] = (mz_uint8)(*pLen_out >> 24); + pnghdr[34] = (mz_uint8)(*pLen_out >> 16); + pnghdr[35] = (mz_uint8)(*pLen_out >> 8); + pnghdr[36] = (mz_uint8)*pLen_out; + c = (mz_uint32)mz_crc32(MZ_CRC32_INIT, pnghdr + 12, 17); + for (i = 0; i < 4; ++i, c <<= 8) + ((mz_uint8 *)(pnghdr + 29))[i] = (mz_uint8)(c >> 24); + memcpy(out_buf.m_pBuf, pnghdr, 41); + } + /* write footer (IDAT CRC-32, followed by IEND chunk) */ + if (!tdefl_output_buffer_putter("\0\0\0\0\0\0\0\0\x49\x45\x4e\x44\xae\x42\x60\x82", 16, &out_buf)) + { + *pLen_out = 0; + MZ_FREE(pComp); + MZ_FREE(out_buf.m_pBuf); + return NULL; + } + c = (mz_uint32)mz_crc32(MZ_CRC32_INIT, out_buf.m_pBuf + 41 - 4, *pLen_out + 4); + for (i = 0; i < 4; ++i, c <<= 8) + (out_buf.m_pBuf + out_buf.m_size - 16)[i] = (mz_uint8)(c >> 24); + /* compute final size of file, grab compressed data buffer and return */ + *pLen_out += 57; + MZ_FREE(pComp); + return out_buf.m_pBuf; +} +void *tdefl_write_image_to_png_file_in_memory(const void *pImage, int w, int h, int num_chans, size_t *pLen_out) +{ + /* Level 6 corresponds to TDEFL_DEFAULT_MAX_PROBES or MZ_DEFAULT_LEVEL (but we can't depend on MZ_DEFAULT_LEVEL being available in case the zlib API's where #defined out) */ + return tdefl_write_image_to_png_file_in_memory_ex(pImage, w, h, num_chans, pLen_out, 6, MZ_FALSE); +} + +/* Allocate the tdefl_compressor and tinfl_decompressor structures in C so that */ +/* non-C language bindings to tdefL_ and tinfl_ API don't need to worry about */ +/* structure size and allocation mechanism. */ +tdefl_compressor *tdefl_compressor_alloc() +{ + return (tdefl_compressor *)MZ_MALLOC(sizeof(tdefl_compressor)); +} + +void tdefl_compressor_free(tdefl_compressor *pComp) +{ + MZ_FREE(pComp); +} + +#ifdef _MSC_VER +#pragma warning(pop) +#endif diff --git a/xs/src/miniz/miniz_tdef.h b/xs/src/miniz/miniz_tdef.h new file mode 100644 index 000000000..ca63cfd42 --- /dev/null +++ b/xs/src/miniz/miniz_tdef.h @@ -0,0 +1,181 @@ +#pragma once +#include "miniz_common.h" + +/* ------------------- Low-level Compression API Definitions */ + +/* Set TDEFL_LESS_MEMORY to 1 to use less memory (compression will be slightly slower, and raw/dynamic blocks will be output more frequently). */ +#define TDEFL_LESS_MEMORY 0 + +/* tdefl_init() compression flags logically OR'd together (low 12 bits contain the max. number of probes per dictionary search): */ +/* TDEFL_DEFAULT_MAX_PROBES: The compressor defaults to 128 dictionary probes per dictionary search. 0=Huffman only, 1=Huffman+LZ (fastest/crap compression), 4095=Huffman+LZ (slowest/best compression). */ +enum +{ + TDEFL_HUFFMAN_ONLY = 0, + TDEFL_DEFAULT_MAX_PROBES = 128, + TDEFL_MAX_PROBES_MASK = 0xFFF +}; + +/* TDEFL_WRITE_ZLIB_HEADER: If set, the compressor outputs a zlib header before the deflate data, and the Adler-32 of the source data at the end. Otherwise, you'll get raw deflate data. */ +/* TDEFL_COMPUTE_ADLER32: Always compute the adler-32 of the input data (even when not writing zlib headers). */ +/* TDEFL_GREEDY_PARSING_FLAG: Set to use faster greedy parsing, instead of more efficient lazy parsing. */ +/* TDEFL_NONDETERMINISTIC_PARSING_FLAG: Enable to decrease the compressor's initialization time to the minimum, but the output may vary from run to run given the same input (depending on the contents of memory). */ +/* TDEFL_RLE_MATCHES: Only look for RLE matches (matches with a distance of 1) */ +/* TDEFL_FILTER_MATCHES: Discards matches <= 5 chars if enabled. */ +/* TDEFL_FORCE_ALL_STATIC_BLOCKS: Disable usage of optimized Huffman tables. */ +/* TDEFL_FORCE_ALL_RAW_BLOCKS: Only use raw (uncompressed) deflate blocks. */ +/* The low 12 bits are reserved to control the max # of hash probes per dictionary lookup (see TDEFL_MAX_PROBES_MASK). */ +enum +{ + TDEFL_WRITE_ZLIB_HEADER = 0x01000, + TDEFL_COMPUTE_ADLER32 = 0x02000, + TDEFL_GREEDY_PARSING_FLAG = 0x04000, + TDEFL_NONDETERMINISTIC_PARSING_FLAG = 0x08000, + TDEFL_RLE_MATCHES = 0x10000, + TDEFL_FILTER_MATCHES = 0x20000, + TDEFL_FORCE_ALL_STATIC_BLOCKS = 0x40000, + TDEFL_FORCE_ALL_RAW_BLOCKS = 0x80000 +}; + +/* High level compression functions: */ +/* tdefl_compress_mem_to_heap() compresses a block in memory to a heap block allocated via malloc(). */ +/* On entry: */ +/* pSrc_buf, src_buf_len: Pointer and size of source block to compress. */ +/* flags: The max match finder probes (default is 128) logically OR'd against the above flags. Higher probes are slower but improve compression. */ +/* On return: */ +/* Function returns a pointer to the compressed data, or NULL on failure. */ +/* *pOut_len will be set to the compressed data's size, which could be larger than src_buf_len on uncompressible data. */ +/* The caller must free() the returned block when it's no longer needed. */ +void *tdefl_compress_mem_to_heap(const void *pSrc_buf, size_t src_buf_len, size_t *pOut_len, int flags); + +/* tdefl_compress_mem_to_mem() compresses a block in memory to another block in memory. */ +/* Returns 0 on failure. */ +size_t tdefl_compress_mem_to_mem(void *pOut_buf, size_t out_buf_len, const void *pSrc_buf, size_t src_buf_len, int flags); + +/* Compresses an image to a compressed PNG file in memory. */ +/* On entry: */ +/* pImage, w, h, and num_chans describe the image to compress. num_chans may be 1, 2, 3, or 4. */ +/* The image pitch in bytes per scanline will be w*num_chans. The leftmost pixel on the top scanline is stored first in memory. */ +/* level may range from [0,10], use MZ_NO_COMPRESSION, MZ_BEST_SPEED, MZ_BEST_COMPRESSION, etc. or a decent default is MZ_DEFAULT_LEVEL */ +/* If flip is true, the image will be flipped on the Y axis (useful for OpenGL apps). */ +/* On return: */ +/* Function returns a pointer to the compressed data, or NULL on failure. */ +/* *pLen_out will be set to the size of the PNG image file. */ +/* The caller must mz_free() the returned heap block (which will typically be larger than *pLen_out) when it's no longer needed. */ +void *tdefl_write_image_to_png_file_in_memory_ex(const void *pImage, int w, int h, int num_chans, size_t *pLen_out, mz_uint level, mz_bool flip); +void *tdefl_write_image_to_png_file_in_memory(const void *pImage, int w, int h, int num_chans, size_t *pLen_out); + +/* Output stream interface. The compressor uses this interface to write compressed data. It'll typically be called TDEFL_OUT_BUF_SIZE at a time. */ +typedef mz_bool (*tdefl_put_buf_func_ptr)(const void *pBuf, int len, void *pUser); + +/* tdefl_compress_mem_to_output() compresses a block to an output stream. The above helpers use this function internally. */ +mz_bool tdefl_compress_mem_to_output(const void *pBuf, size_t buf_len, tdefl_put_buf_func_ptr pPut_buf_func, void *pPut_buf_user, int flags); + +enum +{ + TDEFL_MAX_HUFF_TABLES = 3, + TDEFL_MAX_HUFF_SYMBOLS_0 = 288, + TDEFL_MAX_HUFF_SYMBOLS_1 = 32, + TDEFL_MAX_HUFF_SYMBOLS_2 = 19, + TDEFL_LZ_DICT_SIZE = 32768, + TDEFL_LZ_DICT_SIZE_MASK = TDEFL_LZ_DICT_SIZE - 1, + TDEFL_MIN_MATCH_LEN = 3, + TDEFL_MAX_MATCH_LEN = 258 +}; + +/* TDEFL_OUT_BUF_SIZE MUST be large enough to hold a single entire compressed output block (using static/fixed Huffman codes). */ +#if TDEFL_LESS_MEMORY +enum +{ + TDEFL_LZ_CODE_BUF_SIZE = 24 * 1024, + TDEFL_OUT_BUF_SIZE = (TDEFL_LZ_CODE_BUF_SIZE * 13) / 10, + TDEFL_MAX_HUFF_SYMBOLS = 288, + TDEFL_LZ_HASH_BITS = 12, + TDEFL_LEVEL1_HASH_SIZE_MASK = 4095, + TDEFL_LZ_HASH_SHIFT = (TDEFL_LZ_HASH_BITS + 2) / 3, + TDEFL_LZ_HASH_SIZE = 1 << TDEFL_LZ_HASH_BITS +}; +#else +enum +{ + TDEFL_LZ_CODE_BUF_SIZE = 64 * 1024, + TDEFL_OUT_BUF_SIZE = (TDEFL_LZ_CODE_BUF_SIZE * 13) / 10, + TDEFL_MAX_HUFF_SYMBOLS = 288, + TDEFL_LZ_HASH_BITS = 15, + TDEFL_LEVEL1_HASH_SIZE_MASK = 4095, + TDEFL_LZ_HASH_SHIFT = (TDEFL_LZ_HASH_BITS + 2) / 3, + TDEFL_LZ_HASH_SIZE = 1 << TDEFL_LZ_HASH_BITS +}; +#endif + +/* The low-level tdefl functions below may be used directly if the above helper functions aren't flexible enough. The low-level functions don't make any heap allocations, unlike the above helper functions. */ +typedef enum { + TDEFL_STATUS_BAD_PARAM = -2, + TDEFL_STATUS_PUT_BUF_FAILED = -1, + TDEFL_STATUS_OKAY = 0, + TDEFL_STATUS_DONE = 1 +} tdefl_status; + +/* Must map to MZ_NO_FLUSH, MZ_SYNC_FLUSH, etc. enums */ +typedef enum { + TDEFL_NO_FLUSH = 0, + TDEFL_SYNC_FLUSH = 2, + TDEFL_FULL_FLUSH = 3, + TDEFL_FINISH = 4 +} tdefl_flush; + +/* tdefl's compression state structure. */ +typedef struct +{ + tdefl_put_buf_func_ptr m_pPut_buf_func; + void *m_pPut_buf_user; + mz_uint m_flags, m_max_probes[2]; + int m_greedy_parsing; + mz_uint m_adler32, m_lookahead_pos, m_lookahead_size, m_dict_size; + mz_uint8 *m_pLZ_code_buf, *m_pLZ_flags, *m_pOutput_buf, *m_pOutput_buf_end; + mz_uint m_num_flags_left, m_total_lz_bytes, m_lz_code_buf_dict_pos, m_bits_in, m_bit_buffer; + mz_uint m_saved_match_dist, m_saved_match_len, m_saved_lit, m_output_flush_ofs, m_output_flush_remaining, m_finished, m_block_index, m_wants_to_finish; + tdefl_status m_prev_return_status; + const void *m_pIn_buf; + void *m_pOut_buf; + size_t *m_pIn_buf_size, *m_pOut_buf_size; + tdefl_flush m_flush; + const mz_uint8 *m_pSrc; + size_t m_src_buf_left, m_out_buf_ofs; + mz_uint8 m_dict[TDEFL_LZ_DICT_SIZE + TDEFL_MAX_MATCH_LEN - 1]; + mz_uint16 m_huff_count[TDEFL_MAX_HUFF_TABLES][TDEFL_MAX_HUFF_SYMBOLS]; + mz_uint16 m_huff_codes[TDEFL_MAX_HUFF_TABLES][TDEFL_MAX_HUFF_SYMBOLS]; + mz_uint8 m_huff_code_sizes[TDEFL_MAX_HUFF_TABLES][TDEFL_MAX_HUFF_SYMBOLS]; + mz_uint8 m_lz_code_buf[TDEFL_LZ_CODE_BUF_SIZE]; + mz_uint16 m_next[TDEFL_LZ_DICT_SIZE]; + mz_uint16 m_hash[TDEFL_LZ_HASH_SIZE]; + mz_uint8 m_output_buf[TDEFL_OUT_BUF_SIZE]; +} tdefl_compressor; + +/* Initializes the compressor. */ +/* There is no corresponding deinit() function because the tdefl API's do not dynamically allocate memory. */ +/* pBut_buf_func: If NULL, output data will be supplied to the specified callback. In this case, the user should call the tdefl_compress_buffer() API for compression. */ +/* If pBut_buf_func is NULL the user should always call the tdefl_compress() API. */ +/* flags: See the above enums (TDEFL_HUFFMAN_ONLY, TDEFL_WRITE_ZLIB_HEADER, etc.) */ +tdefl_status tdefl_init(tdefl_compressor *d, tdefl_put_buf_func_ptr pPut_buf_func, void *pPut_buf_user, int flags); + +/* Compresses a block of data, consuming as much of the specified input buffer as possible, and writing as much compressed data to the specified output buffer as possible. */ +tdefl_status tdefl_compress(tdefl_compressor *d, const void *pIn_buf, size_t *pIn_buf_size, void *pOut_buf, size_t *pOut_buf_size, tdefl_flush flush); + +/* tdefl_compress_buffer() is only usable when the tdefl_init() is called with a non-NULL tdefl_put_buf_func_ptr. */ +/* tdefl_compress_buffer() always consumes the entire input buffer. */ +tdefl_status tdefl_compress_buffer(tdefl_compressor *d, const void *pIn_buf, size_t in_buf_size, tdefl_flush flush); + +tdefl_status tdefl_get_prev_return_status(tdefl_compressor *d); +mz_uint32 tdefl_get_adler32(tdefl_compressor *d); + +/* Create tdefl_compress() flags given zlib-style compression parameters. */ +/* level may range from [0,10] (where 10 is absolute max compression, but may be much slower on some files) */ +/* window_bits may be -15 (raw deflate) or 15 (zlib) */ +/* strategy may be either MZ_DEFAULT_STRATEGY, MZ_FILTERED, MZ_HUFFMAN_ONLY, MZ_RLE, or MZ_FIXED */ +mz_uint tdefl_create_comp_flags_from_zip_params(int level, int window_bits, int strategy); + +/* Allocate the tdefl_compressor structure in C so that */ +/* non-C language bindings to tdefl_ API don't need to worry about */ +/* structure size and allocation mechanism. */ +tdefl_compressor *tdefl_compressor_alloc(); +void tdefl_compressor_free(tdefl_compressor *pComp); diff --git a/xs/src/miniz/miniz_tinfl.cpp b/xs/src/miniz/miniz_tinfl.cpp new file mode 100644 index 000000000..59b24d73f --- /dev/null +++ b/xs/src/miniz/miniz_tinfl.cpp @@ -0,0 +1,725 @@ +/************************************************************************** + * + * Copyright 2013-2014 RAD Game Tools and Valve Software + * Copyright 2010-2014 Rich Geldreich and Tenacious Software LLC + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + **************************************************************************/ + +#include "miniz_tinfl.h" + +/* ------------------- Low-level Decompression (completely independent from all compression API's) */ + +#define TINFL_MEMCPY(d, s, l) memcpy(d, s, l) +#define TINFL_MEMSET(p, c, l) memset(p, c, l) + +#define TINFL_CR_BEGIN \ + switch (r->m_state) \ + { \ + case 0: +#define TINFL_CR_RETURN(state_index, result) \ + do \ + { \ + status = result; \ + r->m_state = state_index; \ + goto common_exit; \ + case state_index:; \ + } \ + MZ_MACRO_END +#define TINFL_CR_RETURN_FOREVER(state_index, result) \ + do \ + { \ + for (;;) \ + { \ + TINFL_CR_RETURN(state_index, result); \ + } \ + } \ + MZ_MACRO_END +#define TINFL_CR_FINISH } + +#define TINFL_GET_BYTE(state_index, c) \ + do \ + { \ + while (pIn_buf_cur >= pIn_buf_end) \ + { \ + TINFL_CR_RETURN(state_index, (decomp_flags & TINFL_FLAG_HAS_MORE_INPUT) ? TINFL_STATUS_NEEDS_MORE_INPUT : TINFL_STATUS_FAILED_CANNOT_MAKE_PROGRESS); \ + } \ + c = *pIn_buf_cur++; \ + } \ + MZ_MACRO_END + +#define TINFL_NEED_BITS(state_index, n) \ + do \ + { \ + mz_uint c; \ + TINFL_GET_BYTE(state_index, c); \ + bit_buf |= (((tinfl_bit_buf_t)c) << num_bits); \ + num_bits += 8; \ + } while (num_bits < (mz_uint)(n)) +#define TINFL_SKIP_BITS(state_index, n) \ + do \ + { \ + if (num_bits < (mz_uint)(n)) \ + { \ + TINFL_NEED_BITS(state_index, n); \ + } \ + bit_buf >>= (n); \ + num_bits -= (n); \ + } \ + MZ_MACRO_END +#define TINFL_GET_BITS(state_index, b, n) \ + do \ + { \ + if (num_bits < (mz_uint)(n)) \ + { \ + TINFL_NEED_BITS(state_index, n); \ + } \ + b = bit_buf & ((1 << (n)) - 1); \ + bit_buf >>= (n); \ + num_bits -= (n); \ + } \ + MZ_MACRO_END + +/* TINFL_HUFF_BITBUF_FILL() is only used rarely, when the number of bytes remaining in the input buffer falls below 2. */ +/* It reads just enough bytes from the input stream that are needed to decode the next Huffman code (and absolutely no more). It works by trying to fully decode a */ +/* Huffman code by using whatever bits are currently present in the bit buffer. If this fails, it reads another byte, and tries again until it succeeds or until the */ +/* bit buffer contains >=15 bits (deflate's max. Huffman code size). */ +#define TINFL_HUFF_BITBUF_FILL(state_index, pHuff) \ + do \ + { \ + temp = (pHuff)->m_look_up[bit_buf & (TINFL_FAST_LOOKUP_SIZE - 1)]; \ + if (temp >= 0) \ + { \ + code_len = temp >> 9; \ + if ((code_len) && (num_bits >= code_len)) \ + break; \ + } \ + else if (num_bits > TINFL_FAST_LOOKUP_BITS) \ + { \ + code_len = TINFL_FAST_LOOKUP_BITS; \ + do \ + { \ + temp = (pHuff)->m_tree[~temp + ((bit_buf >> code_len++) & 1)]; \ + } while ((temp < 0) && (num_bits >= (code_len + 1))); \ + if (temp >= 0) \ + break; \ + } \ + TINFL_GET_BYTE(state_index, c); \ + bit_buf |= (((tinfl_bit_buf_t)c) << num_bits); \ + num_bits += 8; \ + } while (num_bits < 15); + +/* TINFL_HUFF_DECODE() decodes the next Huffman coded symbol. It's more complex than you would initially expect because the zlib API expects the decompressor to never read */ +/* beyond the final byte of the deflate stream. (In other words, when this macro wants to read another byte from the input, it REALLY needs another byte in order to fully */ +/* decode the next Huffman code.) Handling this properly is particularly important on raw deflate (non-zlib) streams, which aren't followed by a byte aligned adler-32. */ +/* The slow path is only executed at the very end of the input buffer. */ +/* v1.16: The original macro handled the case at the very end of the passed-in input buffer, but we also need to handle the case where the user passes in 1+zillion bytes */ +/* following the deflate data and our non-conservative read-ahead path won't kick in here on this code. This is much trickier. */ +#define TINFL_HUFF_DECODE(state_index, sym, pHuff) \ + do \ + { \ + int temp; \ + mz_uint code_len, c; \ + if (num_bits < 15) \ + { \ + if ((pIn_buf_end - pIn_buf_cur) < 2) \ + { \ + TINFL_HUFF_BITBUF_FILL(state_index, pHuff); \ + } \ + else \ + { \ + bit_buf |= (((tinfl_bit_buf_t)pIn_buf_cur[0]) << num_bits) | (((tinfl_bit_buf_t)pIn_buf_cur[1]) << (num_bits + 8)); \ + pIn_buf_cur += 2; \ + num_bits += 16; \ + } \ + } \ + if ((temp = (pHuff)->m_look_up[bit_buf & (TINFL_FAST_LOOKUP_SIZE - 1)]) >= 0) \ + code_len = temp >> 9, temp &= 511; \ + else \ + { \ + code_len = TINFL_FAST_LOOKUP_BITS; \ + do \ + { \ + temp = (pHuff)->m_tree[~temp + ((bit_buf >> code_len++) & 1)]; \ + } while (temp < 0); \ + } \ + sym = temp; \ + bit_buf >>= code_len; \ + num_bits -= code_len; \ + } \ + MZ_MACRO_END + +tinfl_status tinfl_decompress(tinfl_decompressor *r, const mz_uint8 *pIn_buf_next, size_t *pIn_buf_size, mz_uint8 *pOut_buf_start, mz_uint8 *pOut_buf_next, size_t *pOut_buf_size, const mz_uint32 decomp_flags) +{ + static const int s_length_base[31] = { 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31, 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0 }; + static const int s_length_extra[31] = { 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0, 0, 0 }; + static const int s_dist_base[32] = { 1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193, 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145, 8193, 12289, 16385, 24577, 0, 0 }; + static const int s_dist_extra[32] = { 0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13 }; + static const mz_uint8 s_length_dezigzag[19] = { 16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15 }; + static const int s_min_table_sizes[3] = { 257, 1, 4 }; + + tinfl_status status = TINFL_STATUS_FAILED; + mz_uint32 num_bits, dist, counter, num_extra; + tinfl_bit_buf_t bit_buf; + const mz_uint8 *pIn_buf_cur = pIn_buf_next, *const pIn_buf_end = pIn_buf_next + *pIn_buf_size; + mz_uint8 *pOut_buf_cur = pOut_buf_next, *const pOut_buf_end = pOut_buf_next + *pOut_buf_size; + size_t out_buf_size_mask = (decomp_flags & TINFL_FLAG_USING_NON_WRAPPING_OUTPUT_BUF) ? (size_t)-1 : ((pOut_buf_next - pOut_buf_start) + *pOut_buf_size) - 1, dist_from_out_buf_start; + + /* Ensure the output buffer's size is a power of 2, unless the output buffer is large enough to hold the entire output file (in which case it doesn't matter). */ + if (((out_buf_size_mask + 1) & out_buf_size_mask) || (pOut_buf_next < pOut_buf_start)) + { + *pIn_buf_size = *pOut_buf_size = 0; + return TINFL_STATUS_BAD_PARAM; + } + + num_bits = r->m_num_bits; + bit_buf = r->m_bit_buf; + dist = r->m_dist; + counter = r->m_counter; + num_extra = r->m_num_extra; + dist_from_out_buf_start = r->m_dist_from_out_buf_start; + TINFL_CR_BEGIN + + bit_buf = num_bits = dist = counter = num_extra = r->m_zhdr0 = r->m_zhdr1 = 0; + r->m_z_adler32 = r->m_check_adler32 = 1; + if (decomp_flags & TINFL_FLAG_PARSE_ZLIB_HEADER) + { + TINFL_GET_BYTE(1, r->m_zhdr0); + TINFL_GET_BYTE(2, r->m_zhdr1); + counter = (((r->m_zhdr0 * 256 + r->m_zhdr1) % 31 != 0) || (r->m_zhdr1 & 32) || ((r->m_zhdr0 & 15) != 8)); + if (!(decomp_flags & TINFL_FLAG_USING_NON_WRAPPING_OUTPUT_BUF)) + counter |= (((1U << (8U + (r->m_zhdr0 >> 4))) > 32768U) || ((out_buf_size_mask + 1) < (size_t)(1U << (8U + (r->m_zhdr0 >> 4))))); + if (counter) + { + TINFL_CR_RETURN_FOREVER(36, TINFL_STATUS_FAILED); + } + } + + do + { + TINFL_GET_BITS(3, r->m_final, 3); + r->m_type = r->m_final >> 1; + if (r->m_type == 0) + { + TINFL_SKIP_BITS(5, num_bits & 7); + for (counter = 0; counter < 4; ++counter) + { + if (num_bits) + TINFL_GET_BITS(6, r->m_raw_header[counter], 8); + else + TINFL_GET_BYTE(7, r->m_raw_header[counter]); + } + if ((counter = (r->m_raw_header[0] | (r->m_raw_header[1] << 8))) != (mz_uint)(0xFFFF ^ (r->m_raw_header[2] | (r->m_raw_header[3] << 8)))) + { + TINFL_CR_RETURN_FOREVER(39, TINFL_STATUS_FAILED); + } + while ((counter) && (num_bits)) + { + TINFL_GET_BITS(51, dist, 8); + while (pOut_buf_cur >= pOut_buf_end) + { + TINFL_CR_RETURN(52, TINFL_STATUS_HAS_MORE_OUTPUT); + } + *pOut_buf_cur++ = (mz_uint8)dist; + counter--; + } + while (counter) + { + size_t n; + while (pOut_buf_cur >= pOut_buf_end) + { + TINFL_CR_RETURN(9, TINFL_STATUS_HAS_MORE_OUTPUT); + } + while (pIn_buf_cur >= pIn_buf_end) + { + TINFL_CR_RETURN(38, (decomp_flags & TINFL_FLAG_HAS_MORE_INPUT) ? TINFL_STATUS_NEEDS_MORE_INPUT : TINFL_STATUS_FAILED_CANNOT_MAKE_PROGRESS); + } + n = MZ_MIN(MZ_MIN((size_t)(pOut_buf_end - pOut_buf_cur), (size_t)(pIn_buf_end - pIn_buf_cur)), counter); + TINFL_MEMCPY(pOut_buf_cur, pIn_buf_cur, n); + pIn_buf_cur += n; + pOut_buf_cur += n; + counter -= (mz_uint)n; + } + } + else if (r->m_type == 3) + { + TINFL_CR_RETURN_FOREVER(10, TINFL_STATUS_FAILED); + } + else + { + if (r->m_type == 1) + { + mz_uint8 *p = r->m_tables[0].m_code_size; + mz_uint i; + r->m_table_sizes[0] = 288; + r->m_table_sizes[1] = 32; + TINFL_MEMSET(r->m_tables[1].m_code_size, 5, 32); + for (i = 0; i <= 143; ++i) + *p++ = 8; + for (; i <= 255; ++i) + *p++ = 9; + for (; i <= 279; ++i) + *p++ = 7; + for (; i <= 287; ++i) + *p++ = 8; + } + else + { + for (counter = 0; counter < 3; counter++) + { + TINFL_GET_BITS(11, r->m_table_sizes[counter], "\05\05\04"[counter]); + r->m_table_sizes[counter] += s_min_table_sizes[counter]; + } + MZ_CLEAR_OBJ(r->m_tables[2].m_code_size); + for (counter = 0; counter < r->m_table_sizes[2]; counter++) + { + mz_uint s; + TINFL_GET_BITS(14, s, 3); + r->m_tables[2].m_code_size[s_length_dezigzag[counter]] = (mz_uint8)s; + } + r->m_table_sizes[2] = 19; + } + for (; (int)r->m_type >= 0; r->m_type--) + { + int tree_next, tree_cur; + tinfl_huff_table *pTable; + mz_uint i, j, used_syms, total, sym_index, next_code[17], total_syms[16]; + pTable = &r->m_tables[r->m_type]; + MZ_CLEAR_OBJ(total_syms); + MZ_CLEAR_OBJ(pTable->m_look_up); + MZ_CLEAR_OBJ(pTable->m_tree); + for (i = 0; i < r->m_table_sizes[r->m_type]; ++i) + total_syms[pTable->m_code_size[i]]++; + used_syms = 0, total = 0; + next_code[0] = next_code[1] = 0; + for (i = 1; i <= 15; ++i) + { + used_syms += total_syms[i]; + next_code[i + 1] = (total = ((total + total_syms[i]) << 1)); + } + if ((65536 != total) && (used_syms > 1)) + { + TINFL_CR_RETURN_FOREVER(35, TINFL_STATUS_FAILED); + } + for (tree_next = -1, sym_index = 0; sym_index < r->m_table_sizes[r->m_type]; ++sym_index) + { + mz_uint rev_code = 0, l, cur_code, code_size = pTable->m_code_size[sym_index]; + if (!code_size) + continue; + cur_code = next_code[code_size]++; + for (l = code_size; l > 0; l--, cur_code >>= 1) + rev_code = (rev_code << 1) | (cur_code & 1); + if (code_size <= TINFL_FAST_LOOKUP_BITS) + { + mz_int16 k = (mz_int16)((code_size << 9) | sym_index); + while (rev_code < TINFL_FAST_LOOKUP_SIZE) + { + pTable->m_look_up[rev_code] = k; + rev_code += (1 << code_size); + } + continue; + } + if (0 == (tree_cur = pTable->m_look_up[rev_code & (TINFL_FAST_LOOKUP_SIZE - 1)])) + { + pTable->m_look_up[rev_code & (TINFL_FAST_LOOKUP_SIZE - 1)] = (mz_int16)tree_next; + tree_cur = tree_next; + tree_next -= 2; + } + rev_code >>= (TINFL_FAST_LOOKUP_BITS - 1); + for (j = code_size; j > (TINFL_FAST_LOOKUP_BITS + 1); j--) + { + tree_cur -= ((rev_code >>= 1) & 1); + if (!pTable->m_tree[-tree_cur - 1]) + { + pTable->m_tree[-tree_cur - 1] = (mz_int16)tree_next; + tree_cur = tree_next; + tree_next -= 2; + } + else + tree_cur = pTable->m_tree[-tree_cur - 1]; + } + tree_cur -= ((rev_code >>= 1) & 1); + pTable->m_tree[-tree_cur - 1] = (mz_int16)sym_index; + } + if (r->m_type == 2) + { + for (counter = 0; counter < (r->m_table_sizes[0] + r->m_table_sizes[1]);) + { + mz_uint s; + TINFL_HUFF_DECODE(16, dist, &r->m_tables[2]); + if (dist < 16) + { + r->m_len_codes[counter++] = (mz_uint8)dist; + continue; + } + if ((dist == 16) && (!counter)) + { + TINFL_CR_RETURN_FOREVER(17, TINFL_STATUS_FAILED); + } + num_extra = "\02\03\07"[dist - 16]; + TINFL_GET_BITS(18, s, num_extra); + s += "\03\03\013"[dist - 16]; + TINFL_MEMSET(r->m_len_codes + counter, (dist == 16) ? r->m_len_codes[counter - 1] : 0, s); + counter += s; + } + if ((r->m_table_sizes[0] + r->m_table_sizes[1]) != counter) + { + TINFL_CR_RETURN_FOREVER(21, TINFL_STATUS_FAILED); + } + TINFL_MEMCPY(r->m_tables[0].m_code_size, r->m_len_codes, r->m_table_sizes[0]); + TINFL_MEMCPY(r->m_tables[1].m_code_size, r->m_len_codes + r->m_table_sizes[0], r->m_table_sizes[1]); + } + } + for (;;) + { + mz_uint8 *pSrc; + for (;;) + { + if (((pIn_buf_end - pIn_buf_cur) < 4) || ((pOut_buf_end - pOut_buf_cur) < 2)) + { + TINFL_HUFF_DECODE(23, counter, &r->m_tables[0]); + if (counter >= 256) + break; + while (pOut_buf_cur >= pOut_buf_end) + { + TINFL_CR_RETURN(24, TINFL_STATUS_HAS_MORE_OUTPUT); + } + *pOut_buf_cur++ = (mz_uint8)counter; + } + else + { + int sym2; + mz_uint code_len; +#if TINFL_USE_64BIT_BITBUF + if (num_bits < 30) + { + bit_buf |= (((tinfl_bit_buf_t)MZ_READ_LE32(pIn_buf_cur)) << num_bits); + pIn_buf_cur += 4; + num_bits += 32; + } +#else + if (num_bits < 15) + { + bit_buf |= (((tinfl_bit_buf_t)MZ_READ_LE16(pIn_buf_cur)) << num_bits); + pIn_buf_cur += 2; + num_bits += 16; + } +#endif + if ((sym2 = r->m_tables[0].m_look_up[bit_buf & (TINFL_FAST_LOOKUP_SIZE - 1)]) >= 0) + code_len = sym2 >> 9; + else + { + code_len = TINFL_FAST_LOOKUP_BITS; + do + { + sym2 = r->m_tables[0].m_tree[~sym2 + ((bit_buf >> code_len++) & 1)]; + } while (sym2 < 0); + } + counter = sym2; + bit_buf >>= code_len; + num_bits -= code_len; + if (counter & 256) + break; + +#if !TINFL_USE_64BIT_BITBUF + if (num_bits < 15) + { + bit_buf |= (((tinfl_bit_buf_t)MZ_READ_LE16(pIn_buf_cur)) << num_bits); + pIn_buf_cur += 2; + num_bits += 16; + } +#endif + if ((sym2 = r->m_tables[0].m_look_up[bit_buf & (TINFL_FAST_LOOKUP_SIZE - 1)]) >= 0) + code_len = sym2 >> 9; + else + { + code_len = TINFL_FAST_LOOKUP_BITS; + do + { + sym2 = r->m_tables[0].m_tree[~sym2 + ((bit_buf >> code_len++) & 1)]; + } while (sym2 < 0); + } + bit_buf >>= code_len; + num_bits -= code_len; + + pOut_buf_cur[0] = (mz_uint8)counter; + if (sym2 & 256) + { + pOut_buf_cur++; + counter = sym2; + break; + } + pOut_buf_cur[1] = (mz_uint8)sym2; + pOut_buf_cur += 2; + } + } + if ((counter &= 511) == 256) + break; + + num_extra = s_length_extra[counter - 257]; + counter = s_length_base[counter - 257]; + if (num_extra) + { + mz_uint extra_bits; + TINFL_GET_BITS(25, extra_bits, num_extra); + counter += extra_bits; + } + + TINFL_HUFF_DECODE(26, dist, &r->m_tables[1]); + num_extra = s_dist_extra[dist]; + dist = s_dist_base[dist]; + if (num_extra) + { + mz_uint extra_bits; + TINFL_GET_BITS(27, extra_bits, num_extra); + dist += extra_bits; + } + + dist_from_out_buf_start = pOut_buf_cur - pOut_buf_start; + if ((dist > dist_from_out_buf_start) && (decomp_flags & TINFL_FLAG_USING_NON_WRAPPING_OUTPUT_BUF)) + { + TINFL_CR_RETURN_FOREVER(37, TINFL_STATUS_FAILED); + } + + pSrc = pOut_buf_start + ((dist_from_out_buf_start - dist) & out_buf_size_mask); + + if ((MZ_MAX(pOut_buf_cur, pSrc) + counter) > pOut_buf_end) + { + while (counter--) + { + while (pOut_buf_cur >= pOut_buf_end) + { + TINFL_CR_RETURN(53, TINFL_STATUS_HAS_MORE_OUTPUT); + } + *pOut_buf_cur++ = pOut_buf_start[(dist_from_out_buf_start++ - dist) & out_buf_size_mask]; + } + continue; + } +#if MINIZ_USE_UNALIGNED_LOADS_AND_STORES + else if ((counter >= 9) && (counter <= dist)) + { + const mz_uint8 *pSrc_end = pSrc + (counter & ~7); + do + { + ((mz_uint32 *)pOut_buf_cur)[0] = ((const mz_uint32 *)pSrc)[0]; + ((mz_uint32 *)pOut_buf_cur)[1] = ((const mz_uint32 *)pSrc)[1]; + pOut_buf_cur += 8; + } while ((pSrc += 8) < pSrc_end); + if ((counter &= 7) < 3) + { + if (counter) + { + pOut_buf_cur[0] = pSrc[0]; + if (counter > 1) + pOut_buf_cur[1] = pSrc[1]; + pOut_buf_cur += counter; + } + continue; + } + } +#endif + do + { + pOut_buf_cur[0] = pSrc[0]; + pOut_buf_cur[1] = pSrc[1]; + pOut_buf_cur[2] = pSrc[2]; + pOut_buf_cur += 3; + pSrc += 3; + } while ((int)(counter -= 3) > 2); + if ((int)counter > 0) + { + pOut_buf_cur[0] = pSrc[0]; + if ((int)counter > 1) + pOut_buf_cur[1] = pSrc[1]; + pOut_buf_cur += counter; + } + } + } + } while (!(r->m_final & 1)); + + /* Ensure byte alignment and put back any bytes from the bitbuf if we've looked ahead too far on gzip, or other Deflate streams followed by arbitrary data. */ + /* I'm being super conservative here. A number of simplifications can be made to the byte alignment part, and the Adler32 check shouldn't ever need to worry about reading from the bitbuf now. */ + TINFL_SKIP_BITS(32, num_bits & 7); + while ((pIn_buf_cur > pIn_buf_next) && (num_bits >= 8)) + { + --pIn_buf_cur; + num_bits -= 8; + } + bit_buf &= (tinfl_bit_buf_t)((((mz_uint64)1) << num_bits) - (mz_uint64)1); + MZ_ASSERT(!num_bits); /* if this assert fires then we've read beyond the end of non-deflate/zlib streams with following data (such as gzip streams). */ + + if (decomp_flags & TINFL_FLAG_PARSE_ZLIB_HEADER) + { + for (counter = 0; counter < 4; ++counter) + { + mz_uint s; + if (num_bits) + TINFL_GET_BITS(41, s, 8); + else + TINFL_GET_BYTE(42, s); + r->m_z_adler32 = (r->m_z_adler32 << 8) | s; + } + } + TINFL_CR_RETURN_FOREVER(34, TINFL_STATUS_DONE); + + TINFL_CR_FINISH + +common_exit: + /* As long as we aren't telling the caller that we NEED more input to make forward progress: */ + /* Put back any bytes from the bitbuf in case we've looked ahead too far on gzip, or other Deflate streams followed by arbitrary data. */ + /* We need to be very careful here to NOT push back any bytes we definitely know we need to make forward progress, though, or we'll lock the caller up into an inf loop. */ + if ((status != TINFL_STATUS_NEEDS_MORE_INPUT) && (status != TINFL_STATUS_FAILED_CANNOT_MAKE_PROGRESS)) + { + while ((pIn_buf_cur > pIn_buf_next) && (num_bits >= 8)) + { + --pIn_buf_cur; + num_bits -= 8; + } + } + r->m_num_bits = num_bits; + r->m_bit_buf = bit_buf & (tinfl_bit_buf_t)((((mz_uint64)1) << num_bits) - (mz_uint64)1); + r->m_dist = dist; + r->m_counter = counter; + r->m_num_extra = num_extra; + r->m_dist_from_out_buf_start = dist_from_out_buf_start; + *pIn_buf_size = pIn_buf_cur - pIn_buf_next; + *pOut_buf_size = pOut_buf_cur - pOut_buf_next; + if ((decomp_flags & (TINFL_FLAG_PARSE_ZLIB_HEADER | TINFL_FLAG_COMPUTE_ADLER32)) && (status >= 0)) + { + const mz_uint8 *ptr = pOut_buf_next; + size_t buf_len = *pOut_buf_size; + mz_uint32 i, s1 = r->m_check_adler32 & 0xffff, s2 = r->m_check_adler32 >> 16; + size_t block_len = buf_len % 5552; + while (buf_len) + { + for (i = 0; i + 7 < block_len; i += 8, ptr += 8) + { + s1 += ptr[0], s2 += s1; + s1 += ptr[1], s2 += s1; + s1 += ptr[2], s2 += s1; + s1 += ptr[3], s2 += s1; + s1 += ptr[4], s2 += s1; + s1 += ptr[5], s2 += s1; + s1 += ptr[6], s2 += s1; + s1 += ptr[7], s2 += s1; + } + for (; i < block_len; ++i) + s1 += *ptr++, s2 += s1; + s1 %= 65521U, s2 %= 65521U; + buf_len -= block_len; + block_len = 5552; + } + r->m_check_adler32 = (s2 << 16) + s1; + if ((status == TINFL_STATUS_DONE) && (decomp_flags & TINFL_FLAG_PARSE_ZLIB_HEADER) && (r->m_check_adler32 != r->m_z_adler32)) + status = TINFL_STATUS_ADLER32_MISMATCH; + } + return status; +} + +/* Higher level helper functions. */ +void *tinfl_decompress_mem_to_heap(const void *pSrc_buf, size_t src_buf_len, size_t *pOut_len, int flags) +{ + tinfl_decompressor decomp; + void *pBuf = NULL, *pNew_buf; + size_t src_buf_ofs = 0, out_buf_capacity = 0; + *pOut_len = 0; + tinfl_init(&decomp); + for (;;) + { + size_t src_buf_size = src_buf_len - src_buf_ofs, dst_buf_size = out_buf_capacity - *pOut_len, new_out_buf_capacity; + tinfl_status status = tinfl_decompress(&decomp, (const mz_uint8 *)pSrc_buf + src_buf_ofs, &src_buf_size, (mz_uint8 *)pBuf, pBuf ? (mz_uint8 *)pBuf + *pOut_len : NULL, &dst_buf_size, + (flags & ~TINFL_FLAG_HAS_MORE_INPUT) | TINFL_FLAG_USING_NON_WRAPPING_OUTPUT_BUF); + if ((status < 0) || (status == TINFL_STATUS_NEEDS_MORE_INPUT)) + { + MZ_FREE(pBuf); + *pOut_len = 0; + return NULL; + } + src_buf_ofs += src_buf_size; + *pOut_len += dst_buf_size; + if (status == TINFL_STATUS_DONE) + break; + new_out_buf_capacity = out_buf_capacity * 2; + if (new_out_buf_capacity < 128) + new_out_buf_capacity = 128; + pNew_buf = MZ_REALLOC(pBuf, new_out_buf_capacity); + if (!pNew_buf) + { + MZ_FREE(pBuf); + *pOut_len = 0; + return NULL; + } + pBuf = pNew_buf; + out_buf_capacity = new_out_buf_capacity; + } + return pBuf; +} + +size_t tinfl_decompress_mem_to_mem(void *pOut_buf, size_t out_buf_len, const void *pSrc_buf, size_t src_buf_len, int flags) +{ + tinfl_decompressor decomp; + tinfl_status status; + tinfl_init(&decomp); + status = tinfl_decompress(&decomp, (const mz_uint8 *)pSrc_buf, &src_buf_len, (mz_uint8 *)pOut_buf, (mz_uint8 *)pOut_buf, &out_buf_len, (flags & ~TINFL_FLAG_HAS_MORE_INPUT) | TINFL_FLAG_USING_NON_WRAPPING_OUTPUT_BUF); + return (status != TINFL_STATUS_DONE) ? TINFL_DECOMPRESS_MEM_TO_MEM_FAILED : out_buf_len; +} + +int tinfl_decompress_mem_to_callback(const void *pIn_buf, size_t *pIn_buf_size, tinfl_put_buf_func_ptr pPut_buf_func, void *pPut_buf_user, int flags) +{ + int result = 0; + tinfl_decompressor decomp; + mz_uint8 *pDict = (mz_uint8 *)MZ_MALLOC(TINFL_LZ_DICT_SIZE); + size_t in_buf_ofs = 0, dict_ofs = 0; + if (!pDict) + return TINFL_STATUS_FAILED; + tinfl_init(&decomp); + for (;;) + { + size_t in_buf_size = *pIn_buf_size - in_buf_ofs, dst_buf_size = TINFL_LZ_DICT_SIZE - dict_ofs; + tinfl_status status = tinfl_decompress(&decomp, (const mz_uint8 *)pIn_buf + in_buf_ofs, &in_buf_size, pDict, pDict + dict_ofs, &dst_buf_size, + (flags & ~(TINFL_FLAG_HAS_MORE_INPUT | TINFL_FLAG_USING_NON_WRAPPING_OUTPUT_BUF))); + in_buf_ofs += in_buf_size; + if ((dst_buf_size) && (!(*pPut_buf_func)(pDict + dict_ofs, (int)dst_buf_size, pPut_buf_user))) + break; + if (status != TINFL_STATUS_HAS_MORE_OUTPUT) + { + result = (status == TINFL_STATUS_DONE); + break; + } + dict_ofs = (dict_ofs + dst_buf_size) & (TINFL_LZ_DICT_SIZE - 1); + } + MZ_FREE(pDict); + *pIn_buf_size = in_buf_ofs; + return result; +} + +tinfl_decompressor *tinfl_decompressor_alloc() +{ + tinfl_decompressor *pDecomp = (tinfl_decompressor *)MZ_MALLOC(sizeof(tinfl_decompressor)); + if (pDecomp) + tinfl_init(pDecomp); + return pDecomp; +} + +void tinfl_decompressor_free(tinfl_decompressor *pDecomp) +{ + MZ_FREE(pDecomp); +} diff --git a/xs/src/miniz/miniz_tinfl.h b/xs/src/miniz/miniz_tinfl.h new file mode 100644 index 000000000..b90f22749 --- /dev/null +++ b/xs/src/miniz/miniz_tinfl.h @@ -0,0 +1,137 @@ +#pragma once +#include "miniz_common.h" +/* ------------------- Low-level Decompression API Definitions */ + +/* Decompression flags used by tinfl_decompress(). */ +/* TINFL_FLAG_PARSE_ZLIB_HEADER: If set, the input has a valid zlib header and ends with an adler32 checksum (it's a valid zlib stream). Otherwise, the input is a raw deflate stream. */ +/* TINFL_FLAG_HAS_MORE_INPUT: If set, there are more input bytes available beyond the end of the supplied input buffer. If clear, the input buffer contains all remaining input. */ +/* TINFL_FLAG_USING_NON_WRAPPING_OUTPUT_BUF: If set, the output buffer is large enough to hold the entire decompressed stream. If clear, the output buffer is at least the size of the dictionary (typically 32KB). */ +/* TINFL_FLAG_COMPUTE_ADLER32: Force adler-32 checksum computation of the decompressed bytes. */ +enum +{ + TINFL_FLAG_PARSE_ZLIB_HEADER = 1, + TINFL_FLAG_HAS_MORE_INPUT = 2, + TINFL_FLAG_USING_NON_WRAPPING_OUTPUT_BUF = 4, + TINFL_FLAG_COMPUTE_ADLER32 = 8 +}; + +/* High level decompression functions: */ +/* tinfl_decompress_mem_to_heap() decompresses a block in memory to a heap block allocated via malloc(). */ +/* On entry: */ +/* pSrc_buf, src_buf_len: Pointer and size of the Deflate or zlib source data to decompress. */ +/* On return: */ +/* Function returns a pointer to the decompressed data, or NULL on failure. */ +/* *pOut_len will be set to the decompressed data's size, which could be larger than src_buf_len on uncompressible data. */ +/* The caller must call mz_free() on the returned block when it's no longer needed. */ +void *tinfl_decompress_mem_to_heap(const void *pSrc_buf, size_t src_buf_len, size_t *pOut_len, int flags); + +/* tinfl_decompress_mem_to_mem() decompresses a block in memory to another block in memory. */ +/* Returns TINFL_DECOMPRESS_MEM_TO_MEM_FAILED on failure, or the number of bytes written on success. */ +#define TINFL_DECOMPRESS_MEM_TO_MEM_FAILED ((size_t)(-1)) +size_t tinfl_decompress_mem_to_mem(void *pOut_buf, size_t out_buf_len, const void *pSrc_buf, size_t src_buf_len, int flags); + +/* tinfl_decompress_mem_to_callback() decompresses a block in memory to an internal 32KB buffer, and a user provided callback function will be called to flush the buffer. */ +/* Returns 1 on success or 0 on failure. */ +typedef int (*tinfl_put_buf_func_ptr)(const void *pBuf, int len, void *pUser); +int tinfl_decompress_mem_to_callback(const void *pIn_buf, size_t *pIn_buf_size, tinfl_put_buf_func_ptr pPut_buf_func, void *pPut_buf_user, int flags); + +struct tinfl_decompressor_tag; +typedef struct tinfl_decompressor_tag tinfl_decompressor; + +/* Allocate the tinfl_decompressor structure in C so that */ +/* non-C language bindings to tinfl_ API don't need to worry about */ +/* structure size and allocation mechanism. */ + +tinfl_decompressor *tinfl_decompressor_alloc(); +void tinfl_decompressor_free(tinfl_decompressor *pDecomp); + +/* Max size of LZ dictionary. */ +#define TINFL_LZ_DICT_SIZE 32768 + +/* Return status. */ +typedef enum { + /* This flags indicates the inflator needs 1 or more input bytes to make forward progress, but the caller is indicating that no more are available. The compressed data */ + /* is probably corrupted. If you call the inflator again with more bytes it'll try to continue processing the input but this is a BAD sign (either the data is corrupted or you called it incorrectly). */ + /* If you call it again with no input you'll just get TINFL_STATUS_FAILED_CANNOT_MAKE_PROGRESS again. */ + TINFL_STATUS_FAILED_CANNOT_MAKE_PROGRESS = -4, + + /* This flag indicates that one or more of the input parameters was obviously bogus. (You can try calling it again, but if you get this error the calling code is wrong.) */ + TINFL_STATUS_BAD_PARAM = -3, + + /* This flags indicate the inflator is finished but the adler32 check of the uncompressed data didn't match. If you call it again it'll return TINFL_STATUS_DONE. */ + TINFL_STATUS_ADLER32_MISMATCH = -2, + + /* This flags indicate the inflator has somehow failed (bad code, corrupted input, etc.). If you call it again without resetting via tinfl_init() it it'll just keep on returning the same status failure code. */ + TINFL_STATUS_FAILED = -1, + + /* Any status code less than TINFL_STATUS_DONE must indicate a failure. */ + + /* This flag indicates the inflator has returned every byte of uncompressed data that it can, has consumed every byte that it needed, has successfully reached the end of the deflate stream, and */ + /* if zlib headers and adler32 checking enabled that it has successfully checked the uncompressed data's adler32. If you call it again you'll just get TINFL_STATUS_DONE over and over again. */ + TINFL_STATUS_DONE = 0, + + /* This flag indicates the inflator MUST have more input data (even 1 byte) before it can make any more forward progress, or you need to clear the TINFL_FLAG_HAS_MORE_INPUT */ + /* flag on the next call if you don't have any more source data. If the source data was somehow corrupted it's also possible (but unlikely) for the inflator to keep on demanding input to */ + /* proceed, so be sure to properly set the TINFL_FLAG_HAS_MORE_INPUT flag. */ + TINFL_STATUS_NEEDS_MORE_INPUT = 1, + + /* This flag indicates the inflator definitely has 1 or more bytes of uncompressed data available, but it cannot write this data into the output buffer. */ + /* Note if the source compressed data was corrupted it's possible for the inflator to return a lot of uncompressed data to the caller. I've been assuming you know how much uncompressed data to expect */ + /* (either exact or worst case) and will stop calling the inflator and fail after receiving too much. In pure streaming scenarios where you have no idea how many bytes to expect this may not be possible */ + /* so I may need to add some code to address this. */ + TINFL_STATUS_HAS_MORE_OUTPUT = 2 +} tinfl_status; + +/* Initializes the decompressor to its initial state. */ +#define tinfl_init(r) \ + do \ + { \ + (r)->m_state = 0; \ + } \ + MZ_MACRO_END +#define tinfl_get_adler32(r) (r)->m_check_adler32 + +/* Main low-level decompressor coroutine function. This is the only function actually needed for decompression. All the other functions are just high-level helpers for improved usability. */ +/* This is a universal API, i.e. it can be used as a building block to build any desired higher level decompression API. In the limit case, it can be called once per every byte input or output. */ +tinfl_status tinfl_decompress(tinfl_decompressor *r, const mz_uint8 *pIn_buf_next, size_t *pIn_buf_size, mz_uint8 *pOut_buf_start, mz_uint8 *pOut_buf_next, size_t *pOut_buf_size, const mz_uint32 decomp_flags); + +/* Internal/private bits follow. */ +enum +{ + TINFL_MAX_HUFF_TABLES = 3, + TINFL_MAX_HUFF_SYMBOLS_0 = 288, + TINFL_MAX_HUFF_SYMBOLS_1 = 32, + TINFL_MAX_HUFF_SYMBOLS_2 = 19, + TINFL_FAST_LOOKUP_BITS = 10, + TINFL_FAST_LOOKUP_SIZE = 1 << TINFL_FAST_LOOKUP_BITS +}; + +typedef struct +{ + mz_uint8 m_code_size[TINFL_MAX_HUFF_SYMBOLS_0]; + mz_int16 m_look_up[TINFL_FAST_LOOKUP_SIZE], m_tree[TINFL_MAX_HUFF_SYMBOLS_0 * 2]; +} tinfl_huff_table; + +#if MINIZ_HAS_64BIT_REGISTERS +#define TINFL_USE_64BIT_BITBUF 1 +#else +#define TINFL_USE_64BIT_BITBUF 0 +#endif + +#if TINFL_USE_64BIT_BITBUF +typedef mz_uint64 tinfl_bit_buf_t; +#define TINFL_BITBUF_SIZE (64) +#else +typedef mz_uint32 tinfl_bit_buf_t; +#define TINFL_BITBUF_SIZE (32) +#endif + +struct tinfl_decompressor_tag +{ + mz_uint32 m_state, m_num_bits, m_zhdr0, m_zhdr1, m_z_adler32, m_final, m_type, m_check_adler32, m_dist, m_counter, m_num_extra, m_table_sizes[TINFL_MAX_HUFF_TABLES]; + tinfl_bit_buf_t m_bit_buf; + size_t m_dist_from_out_buf_start; + tinfl_huff_table m_tables[TINFL_MAX_HUFF_TABLES]; + mz_uint8 m_raw_header[4], m_len_codes[TINFL_MAX_HUFF_SYMBOLS_0 + TINFL_MAX_HUFF_SYMBOLS_1 + 137]; +}; + diff --git a/xs/src/miniz/miniz_zip.cpp b/xs/src/miniz/miniz_zip.cpp new file mode 100644 index 000000000..463660c1c --- /dev/null +++ b/xs/src/miniz/miniz_zip.cpp @@ -0,0 +1,4659 @@ +/************************************************************************** + * + * Copyright 2013-2014 RAD Game Tools and Valve Software + * Copyright 2010-2014 Rich Geldreich and Tenacious Software LLC + * Copyright 2016 Martin Raiber + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + **************************************************************************/ +#include "miniz_zip.h" + +#include + +#ifndef MINIZ_NO_ARCHIVE_APIS + +/* ------------------- .ZIP archive reading */ + +#ifdef MINIZ_NO_STDIO +#define MZ_FILE void * +#else +#include + +#if defined(_MSC_VER) || defined(__MINGW64__) + +static FILE *mz_fopen(const char *pFilename, const char *pMode) +{ + FILE *pFile = NULL; + pFile = boost::nowide::fopen(pFilename, pMode); + return pFile; +} +static FILE *mz_freopen(const char *pPath, const char *pMode, FILE *pStream) +{ + FILE *pFile = NULL; + pFile = boost::nowide::freopen(pPath, pMode, pStream); + return pFile; +} +#ifndef MINIZ_NO_TIME +#include +#endif +#define MZ_FOPEN mz_fopen +#define MZ_FCLOSE fclose +#define MZ_FREAD fread +#define MZ_FWRITE fwrite +#define MZ_FTELL64 _ftelli64 +#define MZ_FSEEK64 _fseeki64 +#define MZ_FILE_STAT_STRUCT _stat +#define MZ_FILE_STAT _stat +#define MZ_FFLUSH fflush +#define MZ_FREOPEN mz_freopen +#define MZ_DELETE_FILE remove +#elif defined(__MINGW32__) +#ifndef MINIZ_NO_TIME +#include +#endif +#define MZ_FOPEN(f, m) fopen(f, m) +#define MZ_FCLOSE fclose +#define MZ_FREAD fread +#define MZ_FWRITE fwrite +#define MZ_FTELL64 ftello64 +#define MZ_FSEEK64 fseeko64 +#define MZ_FILE_STAT_STRUCT _stat +#define MZ_FILE_STAT _stat +#define MZ_FFLUSH fflush +#define MZ_FREOPEN(f, m, s) freopen(f, m, s) +#define MZ_DELETE_FILE remove +#elif defined(__TINYC__) +#ifndef MINIZ_NO_TIME +#include +#endif +#define MZ_FOPEN(f, m) fopen(f, m) +#define MZ_FCLOSE fclose +#define MZ_FREAD fread +#define MZ_FWRITE fwrite +#define MZ_FTELL64 ftell +#define MZ_FSEEK64 fseek +#define MZ_FILE_STAT_STRUCT stat +#define MZ_FILE_STAT stat +#define MZ_FFLUSH fflush +#define MZ_FREOPEN(f, m, s) freopen(f, m, s) +#define MZ_DELETE_FILE remove +#elif defined(__GNUC__) && _LARGEFILE64_SOURCE +#ifndef MINIZ_NO_TIME +#include +#endif +#define MZ_FOPEN(f, m) fopen64(f, m) +#define MZ_FCLOSE fclose +#define MZ_FREAD fread +#define MZ_FWRITE fwrite +#define MZ_FTELL64 ftello64 +#define MZ_FSEEK64 fseeko64 +#define MZ_FILE_STAT_STRUCT stat64 +#define MZ_FILE_STAT stat64 +#define MZ_FFLUSH fflush +#define MZ_FREOPEN(p, m, s) freopen64(p, m, s) +#define MZ_DELETE_FILE remove +#elif defined(__APPLE__) && _LARGEFILE64_SOURCE +#ifndef MINIZ_NO_TIME +#include +#endif +#define MZ_FOPEN(f, m) fopen(f, m) +#define MZ_FCLOSE fclose +#define MZ_FREAD fread +#define MZ_FWRITE fwrite +#define MZ_FTELL64 ftello +#define MZ_FSEEK64 fseeko +#define MZ_FILE_STAT_STRUCT stat +#define MZ_FILE_STAT stat +#define MZ_FFLUSH fflush +#define MZ_FREOPEN(p, m, s) freopen(p, m, s) +#define MZ_DELETE_FILE remove + +#else +#pragma message("Using fopen, ftello, fseeko, stat() etc. path for file I/O - this path may not support large files.") +#ifndef MINIZ_NO_TIME +#include +#endif +#define MZ_FOPEN(f, m) fopen(f, m) +#define MZ_FCLOSE fclose +#define MZ_FREAD fread +#define MZ_FWRITE fwrite +#ifdef __STRICT_ANSI__ +#define MZ_FTELL64 ftell +#define MZ_FSEEK64 fseek +#else +#define MZ_FTELL64 ftello +#define MZ_FSEEK64 fseeko +#endif +#define MZ_FILE_STAT_STRUCT stat +#define MZ_FILE_STAT stat +#define MZ_FFLUSH fflush +#define MZ_FREOPEN(f, m, s) freopen(f, m, s) +#define MZ_DELETE_FILE remove +#endif /* #ifdef _MSC_VER */ +#endif /* #ifdef MINIZ_NO_STDIO */ + +#define MZ_TOLOWER(c) ((((c) >= 'A') && ((c) <= 'Z')) ? ((c) - 'A' + 'a') : (c)) + +/* Various ZIP archive enums. To completely avoid cross platform compiler alignment and platform endian issues, miniz.c doesn't use structs for any of this stuff. */ +enum +{ + /* ZIP archive identifiers and record sizes */ + MZ_ZIP_END_OF_CENTRAL_DIR_HEADER_SIG = 0x06054b50, + MZ_ZIP_CENTRAL_DIR_HEADER_SIG = 0x02014b50, + MZ_ZIP_LOCAL_DIR_HEADER_SIG = 0x04034b50, + MZ_ZIP_LOCAL_DIR_HEADER_SIZE = 30, + MZ_ZIP_CENTRAL_DIR_HEADER_SIZE = 46, + MZ_ZIP_END_OF_CENTRAL_DIR_HEADER_SIZE = 22, + + /* ZIP64 archive identifier and record sizes */ + MZ_ZIP64_END_OF_CENTRAL_DIR_HEADER_SIG = 0x06064b50, + MZ_ZIP64_END_OF_CENTRAL_DIR_LOCATOR_SIG = 0x07064b50, + MZ_ZIP64_END_OF_CENTRAL_DIR_HEADER_SIZE = 56, + MZ_ZIP64_END_OF_CENTRAL_DIR_LOCATOR_SIZE = 20, + MZ_ZIP64_EXTENDED_INFORMATION_FIELD_HEADER_ID = 0x0001, + MZ_ZIP_DATA_DESCRIPTOR_ID = 0x08074b50, + MZ_ZIP_DATA_DESCRIPTER_SIZE64 = 24, + MZ_ZIP_DATA_DESCRIPTER_SIZE32 = 16, + + /* Central directory header record offsets */ + MZ_ZIP_CDH_SIG_OFS = 0, + MZ_ZIP_CDH_VERSION_MADE_BY_OFS = 4, + MZ_ZIP_CDH_VERSION_NEEDED_OFS = 6, + MZ_ZIP_CDH_BIT_FLAG_OFS = 8, + MZ_ZIP_CDH_METHOD_OFS = 10, + MZ_ZIP_CDH_FILE_TIME_OFS = 12, + MZ_ZIP_CDH_FILE_DATE_OFS = 14, + MZ_ZIP_CDH_CRC32_OFS = 16, + MZ_ZIP_CDH_COMPRESSED_SIZE_OFS = 20, + MZ_ZIP_CDH_DECOMPRESSED_SIZE_OFS = 24, + MZ_ZIP_CDH_FILENAME_LEN_OFS = 28, + MZ_ZIP_CDH_EXTRA_LEN_OFS = 30, + MZ_ZIP_CDH_COMMENT_LEN_OFS = 32, + MZ_ZIP_CDH_DISK_START_OFS = 34, + MZ_ZIP_CDH_INTERNAL_ATTR_OFS = 36, + MZ_ZIP_CDH_EXTERNAL_ATTR_OFS = 38, + MZ_ZIP_CDH_LOCAL_HEADER_OFS = 42, + + /* Local directory header offsets */ + MZ_ZIP_LDH_SIG_OFS = 0, + MZ_ZIP_LDH_VERSION_NEEDED_OFS = 4, + MZ_ZIP_LDH_BIT_FLAG_OFS = 6, + MZ_ZIP_LDH_METHOD_OFS = 8, + MZ_ZIP_LDH_FILE_TIME_OFS = 10, + MZ_ZIP_LDH_FILE_DATE_OFS = 12, + MZ_ZIP_LDH_CRC32_OFS = 14, + MZ_ZIP_LDH_COMPRESSED_SIZE_OFS = 18, + MZ_ZIP_LDH_DECOMPRESSED_SIZE_OFS = 22, + MZ_ZIP_LDH_FILENAME_LEN_OFS = 26, + MZ_ZIP_LDH_EXTRA_LEN_OFS = 28, + MZ_ZIP_LDH_BIT_FLAG_HAS_LOCATOR = 1 << 3, + + /* End of central directory offsets */ + MZ_ZIP_ECDH_SIG_OFS = 0, + MZ_ZIP_ECDH_NUM_THIS_DISK_OFS = 4, + MZ_ZIP_ECDH_NUM_DISK_CDIR_OFS = 6, + MZ_ZIP_ECDH_CDIR_NUM_ENTRIES_ON_DISK_OFS = 8, + MZ_ZIP_ECDH_CDIR_TOTAL_ENTRIES_OFS = 10, + MZ_ZIP_ECDH_CDIR_SIZE_OFS = 12, + MZ_ZIP_ECDH_CDIR_OFS_OFS = 16, + MZ_ZIP_ECDH_COMMENT_SIZE_OFS = 20, + + /* ZIP64 End of central directory locator offsets */ + MZ_ZIP64_ECDL_SIG_OFS = 0, /* 4 bytes */ + MZ_ZIP64_ECDL_NUM_DISK_CDIR_OFS = 4, /* 4 bytes */ + MZ_ZIP64_ECDL_REL_OFS_TO_ZIP64_ECDR_OFS = 8, /* 8 bytes */ + MZ_ZIP64_ECDL_TOTAL_NUMBER_OF_DISKS_OFS = 16, /* 4 bytes */ + + /* ZIP64 End of central directory header offsets */ + MZ_ZIP64_ECDH_SIG_OFS = 0, /* 4 bytes */ + MZ_ZIP64_ECDH_SIZE_OF_RECORD_OFS = 4, /* 8 bytes */ + MZ_ZIP64_ECDH_VERSION_MADE_BY_OFS = 12, /* 2 bytes */ + MZ_ZIP64_ECDH_VERSION_NEEDED_OFS = 14, /* 2 bytes */ + MZ_ZIP64_ECDH_NUM_THIS_DISK_OFS = 16, /* 4 bytes */ + MZ_ZIP64_ECDH_NUM_DISK_CDIR_OFS = 20, /* 4 bytes */ + MZ_ZIP64_ECDH_CDIR_NUM_ENTRIES_ON_DISK_OFS = 24, /* 8 bytes */ + MZ_ZIP64_ECDH_CDIR_TOTAL_ENTRIES_OFS = 32, /* 8 bytes */ + MZ_ZIP64_ECDH_CDIR_SIZE_OFS = 40, /* 8 bytes */ + MZ_ZIP64_ECDH_CDIR_OFS_OFS = 48, /* 8 bytes */ + MZ_ZIP_VERSION_MADE_BY_DOS_FILESYSTEM_ID = 0, + MZ_ZIP_DOS_DIR_ATTRIBUTE_BITFLAG = 0x10, + MZ_ZIP_GENERAL_PURPOSE_BIT_FLAG_IS_ENCRYPTED = 1, + MZ_ZIP_GENERAL_PURPOSE_BIT_FLAG_COMPRESSED_PATCH_FLAG = 32, + MZ_ZIP_GENERAL_PURPOSE_BIT_FLAG_USES_STRONG_ENCRYPTION = 64, + MZ_ZIP_GENERAL_PURPOSE_BIT_FLAG_LOCAL_DIR_IS_MASKED = 8192, + MZ_ZIP_GENERAL_PURPOSE_BIT_FLAG_UTF8 = 1 << 11 +}; + +typedef struct +{ + void *m_p; + size_t m_size, m_capacity; + mz_uint m_element_size; +} mz_zip_array; + +struct mz_zip_internal_state_tag +{ + mz_zip_array m_central_dir; + mz_zip_array m_central_dir_offsets; + mz_zip_array m_sorted_central_dir_offsets; + + /* The flags passed in when the archive is initially opened. */ + uint32_t m_init_flags; + + /* MZ_TRUE if the archive has a zip64 end of central directory headers, etc. */ + mz_bool m_zip64; + + /* MZ_TRUE if we found zip64 extended info in the central directory (m_zip64 will also be slammed to true too, even if we didn't find a zip64 end of central dir header, etc.) */ + mz_bool m_zip64_has_extended_info_fields; + + /* These fields are used by the file, FILE, memory, and memory/heap read/write helpers. */ + MZ_FILE *m_pFile; + mz_uint64 m_file_archive_start_ofs; + + void *m_pMem; + size_t m_mem_size; + size_t m_mem_capacity; +}; + +#define MZ_ZIP_ARRAY_SET_ELEMENT_SIZE(array_ptr, element_size) (array_ptr)->m_element_size = element_size + +#if defined(DEBUG) || defined(_DEBUG) || defined(NDEBUG) +static MZ_FORCEINLINE mz_uint mz_zip_array_range_check(const mz_zip_array *pArray, mz_uint index) +{ + MZ_ASSERT(index < pArray->m_size); + return index; +} +#define MZ_ZIP_ARRAY_ELEMENT(array_ptr, element_type, index) ((element_type *)((array_ptr)->m_p))[mz_zip_array_range_check(array_ptr, index)] +#else +#define MZ_ZIP_ARRAY_ELEMENT(array_ptr, element_type, index) ((element_type *)((array_ptr)->m_p))[index] +#endif + +static MZ_FORCEINLINE void mz_zip_array_init(mz_zip_array *pArray, mz_uint32 element_size) +{ + memset(pArray, 0, sizeof(mz_zip_array)); + pArray->m_element_size = element_size; +} + +static MZ_FORCEINLINE void mz_zip_array_clear(mz_zip_archive *pZip, mz_zip_array *pArray) +{ + pZip->m_pFree(pZip->m_pAlloc_opaque, pArray->m_p); + memset(pArray, 0, sizeof(mz_zip_array)); +} + +static mz_bool mz_zip_array_ensure_capacity(mz_zip_archive *pZip, mz_zip_array *pArray, size_t min_new_capacity, mz_uint growing) +{ + void *pNew_p; + size_t new_capacity = min_new_capacity; + MZ_ASSERT(pArray->m_element_size); + if (pArray->m_capacity >= min_new_capacity) + return MZ_TRUE; + if (growing) + { + new_capacity = MZ_MAX(1, pArray->m_capacity); + while (new_capacity < min_new_capacity) + new_capacity *= 2; + } + if (NULL == (pNew_p = pZip->m_pRealloc(pZip->m_pAlloc_opaque, pArray->m_p, pArray->m_element_size, new_capacity))) + return MZ_FALSE; + pArray->m_p = pNew_p; + pArray->m_capacity = new_capacity; + return MZ_TRUE; +} + +static MZ_FORCEINLINE mz_bool mz_zip_array_reserve(mz_zip_archive *pZip, mz_zip_array *pArray, size_t new_capacity, mz_uint growing) +{ + if (new_capacity > pArray->m_capacity) + { + if (!mz_zip_array_ensure_capacity(pZip, pArray, new_capacity, growing)) + return MZ_FALSE; + } + return MZ_TRUE; +} + +static MZ_FORCEINLINE mz_bool mz_zip_array_resize(mz_zip_archive *pZip, mz_zip_array *pArray, size_t new_size, mz_uint growing) +{ + if (new_size > pArray->m_capacity) + { + if (!mz_zip_array_ensure_capacity(pZip, pArray, new_size, growing)) + return MZ_FALSE; + } + pArray->m_size = new_size; + return MZ_TRUE; +} + +static MZ_FORCEINLINE mz_bool mz_zip_array_ensure_room(mz_zip_archive *pZip, mz_zip_array *pArray, size_t n) +{ + return mz_zip_array_reserve(pZip, pArray, pArray->m_size + n, MZ_TRUE); +} + +static MZ_FORCEINLINE mz_bool mz_zip_array_push_back(mz_zip_archive *pZip, mz_zip_array *pArray, const void *pElements, size_t n) +{ + size_t orig_size = pArray->m_size; + if (!mz_zip_array_resize(pZip, pArray, orig_size + n, MZ_TRUE)) + return MZ_FALSE; + memcpy((mz_uint8 *)pArray->m_p + orig_size * pArray->m_element_size, pElements, n * pArray->m_element_size); + return MZ_TRUE; +} + +#ifndef MINIZ_NO_TIME +static MZ_TIME_T mz_zip_dos_to_time_t(int dos_time, int dos_date) +{ + struct tm tm; + memset(&tm, 0, sizeof(tm)); + tm.tm_isdst = -1; + tm.tm_year = ((dos_date >> 9) & 127) + 1980 - 1900; + tm.tm_mon = ((dos_date >> 5) & 15) - 1; + tm.tm_mday = dos_date & 31; + tm.tm_hour = (dos_time >> 11) & 31; + tm.tm_min = (dos_time >> 5) & 63; + tm.tm_sec = (dos_time << 1) & 62; + return mktime(&tm); +} + +#ifndef MINIZ_NO_ARCHIVE_WRITING_APIS +static void mz_zip_time_t_to_dos_time(MZ_TIME_T time, mz_uint16 *pDOS_time, mz_uint16 *pDOS_date) +{ +#ifdef _MSC_VER + struct tm tm_struct; + struct tm *tm = &tm_struct; + errno_t err = localtime_s(tm, &time); + if (err) + { + *pDOS_date = 0; + *pDOS_time = 0; + return; + } +#else + struct tm *tm = localtime(&time); +#endif /* #ifdef _MSC_VER */ + + *pDOS_time = (mz_uint16)(((tm->tm_hour) << 11) + ((tm->tm_min) << 5) + ((tm->tm_sec) >> 1)); + *pDOS_date = (mz_uint16)(((tm->tm_year + 1900 - 1980) << 9) + ((tm->tm_mon + 1) << 5) + tm->tm_mday); +} +#endif /* MINIZ_NO_ARCHIVE_WRITING_APIS */ + +#ifndef MINIZ_NO_STDIO +#ifndef MINIZ_NO_ARCHIVE_WRITING_APIS +static mz_bool mz_zip_get_file_modified_time(const char *pFilename, MZ_TIME_T *pTime) +{ + struct MZ_FILE_STAT_STRUCT file_stat; + + /* On Linux with x86 glibc, this call will fail on large files (I think >= 0x80000000 bytes) unless you compiled with _LARGEFILE64_SOURCE. Argh. */ + if (MZ_FILE_STAT(pFilename, &file_stat) != 0) + return MZ_FALSE; + + *pTime = file_stat.st_mtime; + + return MZ_TRUE; +} +#endif /* #ifndef MINIZ_NO_ARCHIVE_WRITING_APIS*/ + +static mz_bool mz_zip_set_file_times(const char *pFilename, MZ_TIME_T access_time, MZ_TIME_T modified_time) +{ + struct utimbuf t; + + memset(&t, 0, sizeof(t)); + t.actime = access_time; + t.modtime = modified_time; + + return !utime(pFilename, &t); +} +#endif /* #ifndef MINIZ_NO_STDIO */ +#endif /* #ifndef MINIZ_NO_TIME */ + +static MZ_FORCEINLINE mz_bool mz_zip_set_error(mz_zip_archive *pZip, mz_zip_error err_num) +{ + if (pZip) + pZip->m_last_error = err_num; + return MZ_FALSE; +} + +static mz_bool mz_zip_reader_init_internal(mz_zip_archive *pZip, mz_uint flags) +{ + (void)flags; + if ((!pZip) || (pZip->m_pState) || (pZip->m_zip_mode != MZ_ZIP_MODE_INVALID)) + return mz_zip_set_error(pZip, MZ_ZIP_INVALID_PARAMETER); + + if (!pZip->m_pAlloc) + pZip->m_pAlloc = miniz_def_alloc_func; + if (!pZip->m_pFree) + pZip->m_pFree = miniz_def_free_func; + if (!pZip->m_pRealloc) + pZip->m_pRealloc = miniz_def_realloc_func; + + pZip->m_archive_size = 0; + pZip->m_central_directory_file_ofs = 0; + pZip->m_total_files = 0; + pZip->m_last_error = MZ_ZIP_NO_ERROR; + + if (NULL == (pZip->m_pState = (mz_zip_internal_state *)pZip->m_pAlloc(pZip->m_pAlloc_opaque, 1, sizeof(mz_zip_internal_state)))) + return mz_zip_set_error(pZip, MZ_ZIP_ALLOC_FAILED); + + memset(pZip->m_pState, 0, sizeof(mz_zip_internal_state)); + MZ_ZIP_ARRAY_SET_ELEMENT_SIZE(&pZip->m_pState->m_central_dir, sizeof(mz_uint8)); + MZ_ZIP_ARRAY_SET_ELEMENT_SIZE(&pZip->m_pState->m_central_dir_offsets, sizeof(mz_uint32)); + MZ_ZIP_ARRAY_SET_ELEMENT_SIZE(&pZip->m_pState->m_sorted_central_dir_offsets, sizeof(mz_uint32)); + pZip->m_pState->m_init_flags = flags; + pZip->m_pState->m_zip64 = MZ_FALSE; + pZip->m_pState->m_zip64_has_extended_info_fields = MZ_FALSE; + + pZip->m_zip_mode = MZ_ZIP_MODE_READING; + + return MZ_TRUE; +} + +static MZ_FORCEINLINE mz_bool mz_zip_reader_filename_less(const mz_zip_array *pCentral_dir_array, const mz_zip_array *pCentral_dir_offsets, mz_uint l_index, mz_uint r_index) +{ + const mz_uint8 *pL = &MZ_ZIP_ARRAY_ELEMENT(pCentral_dir_array, mz_uint8, MZ_ZIP_ARRAY_ELEMENT(pCentral_dir_offsets, mz_uint32, l_index)), *pE; + const mz_uint8 *pR = &MZ_ZIP_ARRAY_ELEMENT(pCentral_dir_array, mz_uint8, MZ_ZIP_ARRAY_ELEMENT(pCentral_dir_offsets, mz_uint32, r_index)); + mz_uint l_len = MZ_READ_LE16(pL + MZ_ZIP_CDH_FILENAME_LEN_OFS), r_len = MZ_READ_LE16(pR + MZ_ZIP_CDH_FILENAME_LEN_OFS); + mz_uint8 l = 0, r = 0; + pL += MZ_ZIP_CENTRAL_DIR_HEADER_SIZE; + pR += MZ_ZIP_CENTRAL_DIR_HEADER_SIZE; + pE = pL + MZ_MIN(l_len, r_len); + while (pL < pE) + { + if ((l = MZ_TOLOWER(*pL)) != (r = MZ_TOLOWER(*pR))) + break; + pL++; + pR++; + } + return (pL == pE) ? (l_len < r_len) : (l < r); +} + +#define MZ_SWAP_UINT32(a, b) \ + do \ + { \ + mz_uint32 t = a; \ + a = b; \ + b = t; \ + } \ + MZ_MACRO_END + +/* Heap sort of lowercased filenames, used to help accelerate plain central directory searches by mz_zip_reader_locate_file(). (Could also use qsort(), but it could allocate memory.) */ +static void mz_zip_reader_sort_central_dir_offsets_by_filename(mz_zip_archive *pZip) +{ + mz_zip_internal_state *pState = pZip->m_pState; + const mz_zip_array *pCentral_dir_offsets = &pState->m_central_dir_offsets; + const mz_zip_array *pCentral_dir = &pState->m_central_dir; + mz_uint32 *pIndices; + mz_uint32 start, end; + const mz_uint32 size = pZip->m_total_files; + + if (size <= 1U) + return; + + pIndices = &MZ_ZIP_ARRAY_ELEMENT(&pState->m_sorted_central_dir_offsets, mz_uint32, 0); + + start = (size - 2U) >> 1U; + for (;;) + { + mz_uint64 child, root = start; + for (;;) + { + if ((child = (root << 1U) + 1U) >= size) + break; + child += (((child + 1U) < size) && (mz_zip_reader_filename_less(pCentral_dir, pCentral_dir_offsets, pIndices[child], pIndices[child + 1U]))); + if (!mz_zip_reader_filename_less(pCentral_dir, pCentral_dir_offsets, pIndices[root], pIndices[child])) + break; + MZ_SWAP_UINT32(pIndices[root], pIndices[child]); + root = child; + } + if (!start) + break; + start--; + } + + end = size - 1; + while (end > 0) + { + mz_uint64 child, root = 0; + MZ_SWAP_UINT32(pIndices[end], pIndices[0]); + for (;;) + { + if ((child = (root << 1U) + 1U) >= end) + break; + child += (((child + 1U) < end) && mz_zip_reader_filename_less(pCentral_dir, pCentral_dir_offsets, pIndices[child], pIndices[child + 1U])); + if (!mz_zip_reader_filename_less(pCentral_dir, pCentral_dir_offsets, pIndices[root], pIndices[child])) + break; + MZ_SWAP_UINT32(pIndices[root], pIndices[child]); + root = child; + } + end--; + } +} + +static mz_bool mz_zip_reader_locate_header_sig(mz_zip_archive *pZip, mz_uint32 record_sig, mz_uint32 record_size, mz_int64 *pOfs) +{ + mz_int64 cur_file_ofs; + mz_uint32 buf_u32[4096 / sizeof(mz_uint32)]; + mz_uint8 *pBuf = (mz_uint8 *)buf_u32; + + /* Basic sanity checks - reject files which are too small */ + if (pZip->m_archive_size < record_size) + return MZ_FALSE; + + /* Find the record by scanning the file from the end towards the beginning. */ + cur_file_ofs = MZ_MAX((mz_int64)pZip->m_archive_size - (mz_int64)sizeof(buf_u32), 0); + for (;;) + { + int i, n = (int)MZ_MIN(sizeof(buf_u32), pZip->m_archive_size - cur_file_ofs); + + if (pZip->m_pRead(pZip->m_pIO_opaque, cur_file_ofs, pBuf, n) != (mz_uint)n) + return MZ_FALSE; + + for (i = n - 4; i >= 0; --i) + { + mz_uint s = MZ_READ_LE32(pBuf + i); + if (s == record_sig) + { + if ((pZip->m_archive_size - (cur_file_ofs + i)) >= record_size) + break; + } + } + + if (i >= 0) + { + cur_file_ofs += i; + break; + } + + /* Give up if we've searched the entire file, or we've gone back "too far" (~64kb) */ + if ((!cur_file_ofs) || ((pZip->m_archive_size - cur_file_ofs) >= (MZ_UINT16_MAX + record_size))) + return MZ_FALSE; + + cur_file_ofs = MZ_MAX(cur_file_ofs - (sizeof(buf_u32) - 3), 0); + } + + *pOfs = cur_file_ofs; + return MZ_TRUE; +} + +static mz_bool mz_zip_reader_read_central_dir(mz_zip_archive *pZip, mz_uint flags) +{ + mz_uint cdir_size = 0, cdir_entries_on_this_disk = 0, num_this_disk = 0, cdir_disk_index = 0; + mz_uint64 cdir_ofs = 0; + mz_int64 cur_file_ofs = 0; + const mz_uint8 *p; + + mz_uint32 buf_u32[4096 / sizeof(mz_uint32)]; + mz_uint8 *pBuf = (mz_uint8 *)buf_u32; + mz_bool sort_central_dir = ((flags & MZ_ZIP_FLAG_DO_NOT_SORT_CENTRAL_DIRECTORY) == 0); + mz_uint32 zip64_end_of_central_dir_locator_u32[(MZ_ZIP64_END_OF_CENTRAL_DIR_LOCATOR_SIZE + sizeof(mz_uint32) - 1) / sizeof(mz_uint32)]; + mz_uint8 *pZip64_locator = (mz_uint8 *)zip64_end_of_central_dir_locator_u32; + + mz_uint32 zip64_end_of_central_dir_header_u32[(MZ_ZIP64_END_OF_CENTRAL_DIR_HEADER_SIZE + sizeof(mz_uint32) - 1) / sizeof(mz_uint32)]; + mz_uint8 *pZip64_end_of_central_dir = (mz_uint8 *)zip64_end_of_central_dir_header_u32; + + mz_uint64 zip64_end_of_central_dir_ofs = 0; + + /* Basic sanity checks - reject files which are too small, and check the first 4 bytes of the file to make sure a local header is there. */ + if (pZip->m_archive_size < MZ_ZIP_END_OF_CENTRAL_DIR_HEADER_SIZE) + return mz_zip_set_error(pZip, MZ_ZIP_NOT_AN_ARCHIVE); + + if (!mz_zip_reader_locate_header_sig(pZip, MZ_ZIP_END_OF_CENTRAL_DIR_HEADER_SIG, MZ_ZIP_END_OF_CENTRAL_DIR_HEADER_SIZE, &cur_file_ofs)) + return mz_zip_set_error(pZip, MZ_ZIP_FAILED_FINDING_CENTRAL_DIR); + + /* Read and verify the end of central directory record. */ + if (pZip->m_pRead(pZip->m_pIO_opaque, cur_file_ofs, pBuf, MZ_ZIP_END_OF_CENTRAL_DIR_HEADER_SIZE) != MZ_ZIP_END_OF_CENTRAL_DIR_HEADER_SIZE) + return mz_zip_set_error(pZip, MZ_ZIP_FILE_READ_FAILED); + + if (MZ_READ_LE32(pBuf + MZ_ZIP_ECDH_SIG_OFS) != MZ_ZIP_END_OF_CENTRAL_DIR_HEADER_SIG) + return mz_zip_set_error(pZip, MZ_ZIP_NOT_AN_ARCHIVE); + + if (cur_file_ofs >= (MZ_ZIP64_END_OF_CENTRAL_DIR_LOCATOR_SIZE + MZ_ZIP64_END_OF_CENTRAL_DIR_HEADER_SIZE)) + { + if (pZip->m_pRead(pZip->m_pIO_opaque, cur_file_ofs - MZ_ZIP64_END_OF_CENTRAL_DIR_LOCATOR_SIZE, pZip64_locator, MZ_ZIP64_END_OF_CENTRAL_DIR_LOCATOR_SIZE) == MZ_ZIP64_END_OF_CENTRAL_DIR_LOCATOR_SIZE) + { + if (MZ_READ_LE32(pZip64_locator + MZ_ZIP64_ECDL_SIG_OFS) == MZ_ZIP64_END_OF_CENTRAL_DIR_LOCATOR_SIG) + { + zip64_end_of_central_dir_ofs = MZ_READ_LE64(pZip64_locator + MZ_ZIP64_ECDL_REL_OFS_TO_ZIP64_ECDR_OFS); + if (zip64_end_of_central_dir_ofs > (pZip->m_archive_size - MZ_ZIP64_END_OF_CENTRAL_DIR_HEADER_SIZE)) + return mz_zip_set_error(pZip, MZ_ZIP_NOT_AN_ARCHIVE); + + if (pZip->m_pRead(pZip->m_pIO_opaque, zip64_end_of_central_dir_ofs, pZip64_end_of_central_dir, MZ_ZIP64_END_OF_CENTRAL_DIR_HEADER_SIZE) == MZ_ZIP64_END_OF_CENTRAL_DIR_HEADER_SIZE) + { + if (MZ_READ_LE32(pZip64_end_of_central_dir + MZ_ZIP64_ECDH_SIG_OFS) == MZ_ZIP64_END_OF_CENTRAL_DIR_HEADER_SIG) + { + pZip->m_pState->m_zip64 = MZ_TRUE; + } + } + } + } + } + + pZip->m_total_files = MZ_READ_LE16(pBuf + MZ_ZIP_ECDH_CDIR_TOTAL_ENTRIES_OFS); + cdir_entries_on_this_disk = MZ_READ_LE16(pBuf + MZ_ZIP_ECDH_CDIR_NUM_ENTRIES_ON_DISK_OFS); + num_this_disk = MZ_READ_LE16(pBuf + MZ_ZIP_ECDH_NUM_THIS_DISK_OFS); + cdir_disk_index = MZ_READ_LE16(pBuf + MZ_ZIP_ECDH_NUM_DISK_CDIR_OFS); + cdir_size = MZ_READ_LE32(pBuf + MZ_ZIP_ECDH_CDIR_SIZE_OFS); + cdir_ofs = MZ_READ_LE32(pBuf + MZ_ZIP_ECDH_CDIR_OFS_OFS); + + if (pZip->m_pState->m_zip64) + { + mz_uint32 zip64_total_num_of_disks = MZ_READ_LE32(pZip64_locator + MZ_ZIP64_ECDL_TOTAL_NUMBER_OF_DISKS_OFS); + mz_uint64 zip64_cdir_total_entries = MZ_READ_LE64(pZip64_end_of_central_dir + MZ_ZIP64_ECDH_CDIR_TOTAL_ENTRIES_OFS); + mz_uint64 zip64_cdir_total_entries_on_this_disk = MZ_READ_LE64(pZip64_end_of_central_dir + MZ_ZIP64_ECDH_CDIR_NUM_ENTRIES_ON_DISK_OFS); + mz_uint64 zip64_size_of_end_of_central_dir_record = MZ_READ_LE64(pZip64_end_of_central_dir + MZ_ZIP64_ECDH_SIZE_OF_RECORD_OFS); + mz_uint64 zip64_size_of_central_directory = MZ_READ_LE64(pZip64_end_of_central_dir + MZ_ZIP64_ECDH_CDIR_SIZE_OFS); + + if (zip64_size_of_end_of_central_dir_record < (MZ_ZIP64_END_OF_CENTRAL_DIR_HEADER_SIZE - 12)) + return mz_zip_set_error(pZip, MZ_ZIP_INVALID_HEADER_OR_CORRUPTED); + + if (zip64_total_num_of_disks != 1U) + return mz_zip_set_error(pZip, MZ_ZIP_UNSUPPORTED_MULTIDISK); + + /* Check for miniz's practical limits */ + if (zip64_cdir_total_entries > MZ_UINT32_MAX) + return mz_zip_set_error(pZip, MZ_ZIP_TOO_MANY_FILES); + + pZip->m_total_files = (mz_uint32)zip64_cdir_total_entries; + + if (zip64_cdir_total_entries_on_this_disk > MZ_UINT32_MAX) + return mz_zip_set_error(pZip, MZ_ZIP_TOO_MANY_FILES); + + cdir_entries_on_this_disk = (mz_uint32)zip64_cdir_total_entries_on_this_disk; + + /* Check for miniz's current practical limits (sorry, this should be enough for millions of files) */ + if (zip64_size_of_central_directory > MZ_UINT32_MAX) + return mz_zip_set_error(pZip, MZ_ZIP_UNSUPPORTED_CDIR_SIZE); + + cdir_size = (mz_uint32)zip64_size_of_central_directory; + + num_this_disk = MZ_READ_LE32(pZip64_end_of_central_dir + MZ_ZIP64_ECDH_NUM_THIS_DISK_OFS); + + cdir_disk_index = MZ_READ_LE32(pZip64_end_of_central_dir + MZ_ZIP64_ECDH_NUM_DISK_CDIR_OFS); + + cdir_ofs = MZ_READ_LE64(pZip64_end_of_central_dir + MZ_ZIP64_ECDH_CDIR_OFS_OFS); + } + + if (pZip->m_total_files != cdir_entries_on_this_disk) + return mz_zip_set_error(pZip, MZ_ZIP_UNSUPPORTED_MULTIDISK); + + if (((num_this_disk | cdir_disk_index) != 0) && ((num_this_disk != 1) || (cdir_disk_index != 1))) + return mz_zip_set_error(pZip, MZ_ZIP_UNSUPPORTED_MULTIDISK); + + if (cdir_size < pZip->m_total_files * MZ_ZIP_CENTRAL_DIR_HEADER_SIZE) + return mz_zip_set_error(pZip, MZ_ZIP_INVALID_HEADER_OR_CORRUPTED); + + if ((cdir_ofs + (mz_uint64)cdir_size) > pZip->m_archive_size) + return mz_zip_set_error(pZip, MZ_ZIP_INVALID_HEADER_OR_CORRUPTED); + + pZip->m_central_directory_file_ofs = cdir_ofs; + + if (pZip->m_total_files) + { + mz_uint i, n; + /* Read the entire central directory into a heap block, and allocate another heap block to hold the unsorted central dir file record offsets, and possibly another to hold the sorted indices. */ + if ((!mz_zip_array_resize(pZip, &pZip->m_pState->m_central_dir, cdir_size, MZ_FALSE)) || + (!mz_zip_array_resize(pZip, &pZip->m_pState->m_central_dir_offsets, pZip->m_total_files, MZ_FALSE))) + return mz_zip_set_error(pZip, MZ_ZIP_ALLOC_FAILED); + + if (sort_central_dir) + { + if (!mz_zip_array_resize(pZip, &pZip->m_pState->m_sorted_central_dir_offsets, pZip->m_total_files, MZ_FALSE)) + return mz_zip_set_error(pZip, MZ_ZIP_ALLOC_FAILED); + } + + if (pZip->m_pRead(pZip->m_pIO_opaque, cdir_ofs, pZip->m_pState->m_central_dir.m_p, cdir_size) != cdir_size) + return mz_zip_set_error(pZip, MZ_ZIP_FILE_READ_FAILED); + + /* Now create an index into the central directory file records, do some basic sanity checking on each record */ + p = (const mz_uint8 *)pZip->m_pState->m_central_dir.m_p; + for (n = cdir_size, i = 0; i < pZip->m_total_files; ++i) + { + mz_uint total_header_size, disk_index, bit_flags, filename_size, ext_data_size; + mz_uint64 comp_size, decomp_size, local_header_ofs; + + if ((n < MZ_ZIP_CENTRAL_DIR_HEADER_SIZE) || (MZ_READ_LE32(p) != MZ_ZIP_CENTRAL_DIR_HEADER_SIG)) + return mz_zip_set_error(pZip, MZ_ZIP_INVALID_HEADER_OR_CORRUPTED); + + MZ_ZIP_ARRAY_ELEMENT(&pZip->m_pState->m_central_dir_offsets, mz_uint32, i) = (mz_uint32)(p - (const mz_uint8 *)pZip->m_pState->m_central_dir.m_p); + + if (sort_central_dir) + MZ_ZIP_ARRAY_ELEMENT(&pZip->m_pState->m_sorted_central_dir_offsets, mz_uint32, i) = i; + + comp_size = MZ_READ_LE32(p + MZ_ZIP_CDH_COMPRESSED_SIZE_OFS); + decomp_size = MZ_READ_LE32(p + MZ_ZIP_CDH_DECOMPRESSED_SIZE_OFS); + local_header_ofs = MZ_READ_LE32(p + MZ_ZIP_CDH_LOCAL_HEADER_OFS); + filename_size = MZ_READ_LE16(p + MZ_ZIP_CDH_FILENAME_LEN_OFS); + ext_data_size = MZ_READ_LE16(p + MZ_ZIP_CDH_EXTRA_LEN_OFS); + + if ((!pZip->m_pState->m_zip64_has_extended_info_fields) && + (ext_data_size) && + (MZ_MAX(MZ_MAX(comp_size, decomp_size), local_header_ofs) == MZ_UINT32_MAX)) + { + /* Attempt to find zip64 extended information field in the entry's extra data */ + mz_uint32 extra_size_remaining = ext_data_size; + + if (extra_size_remaining) + { + const mz_uint8 *pExtra_data = p + MZ_ZIP_CENTRAL_DIR_HEADER_SIZE + filename_size; + + do + { + mz_uint32 field_id; + mz_uint32 field_data_size; + + if (extra_size_remaining < (sizeof(mz_uint16) * 2)) + return mz_zip_set_error(pZip, MZ_ZIP_INVALID_HEADER_OR_CORRUPTED); + + field_id = MZ_READ_LE16(pExtra_data); + field_data_size = MZ_READ_LE16(pExtra_data + sizeof(mz_uint16)); + + if ((field_data_size + sizeof(mz_uint16) * 2) > extra_size_remaining) + return mz_zip_set_error(pZip, MZ_ZIP_INVALID_HEADER_OR_CORRUPTED); + + if (field_id == MZ_ZIP64_EXTENDED_INFORMATION_FIELD_HEADER_ID) + { + /* Ok, the archive didn't have any zip64 headers but it uses a zip64 extended information field so mark it as zip64 anyway (this can occur with infozip's zip util when it reads compresses files from stdin). */ + pZip->m_pState->m_zip64 = MZ_TRUE; + pZip->m_pState->m_zip64_has_extended_info_fields = MZ_TRUE; + break; + } + + pExtra_data += sizeof(mz_uint16) * 2 + field_data_size; + extra_size_remaining = extra_size_remaining - sizeof(mz_uint16) * 2 - field_data_size; + } while (extra_size_remaining); + } + } + + /* I've seen archives that aren't marked as zip64 that uses zip64 ext data, argh */ + if ((comp_size != MZ_UINT32_MAX) && (decomp_size != MZ_UINT32_MAX)) + { + if (((!MZ_READ_LE32(p + MZ_ZIP_CDH_METHOD_OFS)) && (decomp_size != comp_size)) || (decomp_size && !comp_size)) + return mz_zip_set_error(pZip, MZ_ZIP_INVALID_HEADER_OR_CORRUPTED); + } + + disk_index = MZ_READ_LE16(p + MZ_ZIP_CDH_DISK_START_OFS); + if ((disk_index == MZ_UINT16_MAX) || ((disk_index != num_this_disk) && (disk_index != 1))) + return mz_zip_set_error(pZip, MZ_ZIP_UNSUPPORTED_MULTIDISK); + + if (comp_size != MZ_UINT32_MAX) + { + if (((mz_uint64)MZ_READ_LE32(p + MZ_ZIP_CDH_LOCAL_HEADER_OFS) + MZ_ZIP_LOCAL_DIR_HEADER_SIZE + comp_size) > pZip->m_archive_size) + return mz_zip_set_error(pZip, MZ_ZIP_INVALID_HEADER_OR_CORRUPTED); + } + + bit_flags = MZ_READ_LE16(p + MZ_ZIP_CDH_BIT_FLAG_OFS); + if (bit_flags & MZ_ZIP_GENERAL_PURPOSE_BIT_FLAG_LOCAL_DIR_IS_MASKED) + return mz_zip_set_error(pZip, MZ_ZIP_UNSUPPORTED_ENCRYPTION); + + if ((total_header_size = MZ_ZIP_CENTRAL_DIR_HEADER_SIZE + MZ_READ_LE16(p + MZ_ZIP_CDH_FILENAME_LEN_OFS) + MZ_READ_LE16(p + MZ_ZIP_CDH_EXTRA_LEN_OFS) + MZ_READ_LE16(p + MZ_ZIP_CDH_COMMENT_LEN_OFS)) > n) + return mz_zip_set_error(pZip, MZ_ZIP_INVALID_HEADER_OR_CORRUPTED); + + n -= total_header_size; + p += total_header_size; + } + } + + if (sort_central_dir) + mz_zip_reader_sort_central_dir_offsets_by_filename(pZip); + + return MZ_TRUE; +} + +void mz_zip_zero_struct(mz_zip_archive *pZip) +{ + if (pZip) + MZ_CLEAR_OBJ(*pZip); +} + +static mz_bool mz_zip_reader_end_internal(mz_zip_archive *pZip, mz_bool set_last_error) +{ + mz_bool status = MZ_TRUE; + + if (!pZip) + return MZ_FALSE; + + if ((!pZip->m_pState) || (!pZip->m_pAlloc) || (!pZip->m_pFree) || (pZip->m_zip_mode != MZ_ZIP_MODE_READING)) + { + if (set_last_error) + pZip->m_last_error = MZ_ZIP_INVALID_PARAMETER; + + return MZ_FALSE; + } + + if (pZip->m_pState) + { + mz_zip_internal_state *pState = pZip->m_pState; + pZip->m_pState = NULL; + + mz_zip_array_clear(pZip, &pState->m_central_dir); + mz_zip_array_clear(pZip, &pState->m_central_dir_offsets); + mz_zip_array_clear(pZip, &pState->m_sorted_central_dir_offsets); + +#ifndef MINIZ_NO_STDIO + if (pState->m_pFile) + { + if (pZip->m_zip_type == MZ_ZIP_TYPE_FILE) + { + if (MZ_FCLOSE(pState->m_pFile) == EOF) + { + if (set_last_error) + pZip->m_last_error = MZ_ZIP_FILE_CLOSE_FAILED; + status = MZ_FALSE; + } + } + pState->m_pFile = NULL; + } +#endif /* #ifndef MINIZ_NO_STDIO */ + + pZip->m_pFree(pZip->m_pAlloc_opaque, pState); + } + pZip->m_zip_mode = MZ_ZIP_MODE_INVALID; + + return status; +} + +mz_bool mz_zip_reader_end(mz_zip_archive *pZip) +{ + return mz_zip_reader_end_internal(pZip, MZ_TRUE); +} +mz_bool mz_zip_reader_init(mz_zip_archive *pZip, mz_uint64 size, mz_uint flags) +{ + if ((!pZip) || (!pZip->m_pRead)) + return mz_zip_set_error(pZip, MZ_ZIP_INVALID_PARAMETER); + + if (!mz_zip_reader_init_internal(pZip, flags)) + return MZ_FALSE; + + pZip->m_zip_type = MZ_ZIP_TYPE_USER; + pZip->m_archive_size = size; + + if (!mz_zip_reader_read_central_dir(pZip, flags)) + { + mz_zip_reader_end_internal(pZip, MZ_FALSE); + return MZ_FALSE; + } + + return MZ_TRUE; +} + +static size_t mz_zip_mem_read_func(void *pOpaque, mz_uint64 file_ofs, void *pBuf, size_t n) +{ + mz_zip_archive *pZip = (mz_zip_archive *)pOpaque; + size_t s = (file_ofs >= pZip->m_archive_size) ? 0 : (size_t)MZ_MIN(pZip->m_archive_size - file_ofs, n); + memcpy(pBuf, (const mz_uint8 *)pZip->m_pState->m_pMem + file_ofs, s); + return s; +} + +mz_bool mz_zip_reader_init_mem(mz_zip_archive *pZip, const void *pMem, size_t size, mz_uint flags) +{ + if (!pMem) + return mz_zip_set_error(pZip, MZ_ZIP_INVALID_PARAMETER); + + if (size < MZ_ZIP_END_OF_CENTRAL_DIR_HEADER_SIZE) + return mz_zip_set_error(pZip, MZ_ZIP_NOT_AN_ARCHIVE); + + if (!mz_zip_reader_init_internal(pZip, flags)) + return MZ_FALSE; + + pZip->m_zip_type = MZ_ZIP_TYPE_MEMORY; + pZip->m_archive_size = size; + pZip->m_pRead = mz_zip_mem_read_func; + pZip->m_pIO_opaque = pZip; + pZip->m_pNeeds_keepalive = NULL; + +#ifdef __cplusplus + pZip->m_pState->m_pMem = const_cast(pMem); +#else + pZip->m_pState->m_pMem = (void *)pMem; +#endif + + pZip->m_pState->m_mem_size = size; + + if (!mz_zip_reader_read_central_dir(pZip, flags)) + { + mz_zip_reader_end_internal(pZip, MZ_FALSE); + return MZ_FALSE; + } + + return MZ_TRUE; +} + +#ifndef MINIZ_NO_STDIO +static size_t mz_zip_file_read_func(void *pOpaque, mz_uint64 file_ofs, void *pBuf, size_t n) +{ + mz_zip_archive *pZip = (mz_zip_archive *)pOpaque; + mz_int64 cur_ofs = MZ_FTELL64(pZip->m_pState->m_pFile); + + file_ofs += pZip->m_pState->m_file_archive_start_ofs; + + if (((mz_int64)file_ofs < 0) || (((cur_ofs != (mz_int64)file_ofs)) && (MZ_FSEEK64(pZip->m_pState->m_pFile, (mz_int64)file_ofs, SEEK_SET)))) + return 0; + + return MZ_FREAD(pBuf, 1, n, pZip->m_pState->m_pFile); +} + +mz_bool mz_zip_reader_init_file(mz_zip_archive *pZip, const char *pFilename, mz_uint32 flags) +{ + return mz_zip_reader_init_file_v2(pZip, pFilename, flags, 0, 0); +} + +mz_bool mz_zip_reader_init_file_v2(mz_zip_archive *pZip, const char *pFilename, mz_uint flags, mz_uint64 file_start_ofs, mz_uint64 archive_size) +{ + mz_uint64 file_size; + MZ_FILE *pFile; + + if ((!pZip) || (!pFilename) || ((archive_size) && (archive_size < MZ_ZIP_END_OF_CENTRAL_DIR_HEADER_SIZE))) + return mz_zip_set_error(pZip, MZ_ZIP_INVALID_PARAMETER); + + pFile = MZ_FOPEN(pFilename, "rb"); + if (!pFile) + return mz_zip_set_error(pZip, MZ_ZIP_FILE_OPEN_FAILED); + + file_size = archive_size; + if (!file_size) + { + if (MZ_FSEEK64(pFile, 0, SEEK_END)) + { + MZ_FCLOSE(pFile); + return mz_zip_set_error(pZip, MZ_ZIP_FILE_SEEK_FAILED); + } + + file_size = MZ_FTELL64(pFile); + } + + /* TODO: Better sanity check archive_size and the # of actual remaining bytes */ + + if (file_size < MZ_ZIP_END_OF_CENTRAL_DIR_HEADER_SIZE) + { + MZ_FCLOSE(pFile); + return mz_zip_set_error(pZip, MZ_ZIP_NOT_AN_ARCHIVE); + } + + if (!mz_zip_reader_init_internal(pZip, flags)) + { + MZ_FCLOSE(pFile); + return MZ_FALSE; + } + + pZip->m_zip_type = MZ_ZIP_TYPE_FILE; + pZip->m_pRead = mz_zip_file_read_func; + pZip->m_pIO_opaque = pZip; + pZip->m_pState->m_pFile = pFile; + pZip->m_archive_size = file_size; + pZip->m_pState->m_file_archive_start_ofs = file_start_ofs; + + if (!mz_zip_reader_read_central_dir(pZip, flags)) + { + mz_zip_reader_end_internal(pZip, MZ_FALSE); + return MZ_FALSE; + } + + return MZ_TRUE; +} + +mz_bool mz_zip_reader_init_cfile(mz_zip_archive *pZip, MZ_FILE *pFile, mz_uint64 archive_size, mz_uint flags) +{ + mz_uint64 cur_file_ofs; + + if ((!pZip) || (!pFile)) + return mz_zip_set_error(pZip, MZ_ZIP_FILE_OPEN_FAILED); + + cur_file_ofs = MZ_FTELL64(pFile); + + if (!archive_size) + { + if (MZ_FSEEK64(pFile, 0, SEEK_END)) + return mz_zip_set_error(pZip, MZ_ZIP_FILE_SEEK_FAILED); + + archive_size = MZ_FTELL64(pFile) - cur_file_ofs; + + if (archive_size < MZ_ZIP_END_OF_CENTRAL_DIR_HEADER_SIZE) + return mz_zip_set_error(pZip, MZ_ZIP_NOT_AN_ARCHIVE); + } + + if (!mz_zip_reader_init_internal(pZip, flags)) + return MZ_FALSE; + + pZip->m_zip_type = MZ_ZIP_TYPE_CFILE; + pZip->m_pRead = mz_zip_file_read_func; + + pZip->m_pIO_opaque = pZip; + pZip->m_pState->m_pFile = pFile; + pZip->m_archive_size = archive_size; + pZip->m_pState->m_file_archive_start_ofs = cur_file_ofs; + + if (!mz_zip_reader_read_central_dir(pZip, flags)) + { + mz_zip_reader_end_internal(pZip, MZ_FALSE); + return MZ_FALSE; + } + + return MZ_TRUE; +} + +#endif /* #ifndef MINIZ_NO_STDIO */ + +static MZ_FORCEINLINE const mz_uint8 *mz_zip_get_cdh(mz_zip_archive *pZip, mz_uint file_index) +{ + if ((!pZip) || (!pZip->m_pState) || (file_index >= pZip->m_total_files)) + return NULL; + return &MZ_ZIP_ARRAY_ELEMENT(&pZip->m_pState->m_central_dir, mz_uint8, MZ_ZIP_ARRAY_ELEMENT(&pZip->m_pState->m_central_dir_offsets, mz_uint32, file_index)); +} + +mz_bool mz_zip_reader_is_file_encrypted(mz_zip_archive *pZip, mz_uint file_index) +{ + mz_uint m_bit_flag; + const mz_uint8 *p = mz_zip_get_cdh(pZip, file_index); + if (!p) + { + mz_zip_set_error(pZip, MZ_ZIP_INVALID_PARAMETER); + return MZ_FALSE; + } + + m_bit_flag = MZ_READ_LE16(p + MZ_ZIP_CDH_BIT_FLAG_OFS); + return (m_bit_flag & (MZ_ZIP_GENERAL_PURPOSE_BIT_FLAG_IS_ENCRYPTED | MZ_ZIP_GENERAL_PURPOSE_BIT_FLAG_USES_STRONG_ENCRYPTION)) != 0; +} + +mz_bool mz_zip_reader_is_file_supported(mz_zip_archive *pZip, mz_uint file_index) +{ + mz_uint bit_flag; + mz_uint method; + + const mz_uint8 *p = mz_zip_get_cdh(pZip, file_index); + if (!p) + { + mz_zip_set_error(pZip, MZ_ZIP_INVALID_PARAMETER); + return MZ_FALSE; + } + + method = MZ_READ_LE16(p + MZ_ZIP_CDH_METHOD_OFS); + bit_flag = MZ_READ_LE16(p + MZ_ZIP_CDH_BIT_FLAG_OFS); + + if ((method != 0) && (method != MZ_DEFLATED)) + { + mz_zip_set_error(pZip, MZ_ZIP_UNSUPPORTED_METHOD); + return MZ_FALSE; + } + + if (bit_flag & (MZ_ZIP_GENERAL_PURPOSE_BIT_FLAG_IS_ENCRYPTED | MZ_ZIP_GENERAL_PURPOSE_BIT_FLAG_USES_STRONG_ENCRYPTION)) + { + mz_zip_set_error(pZip, MZ_ZIP_UNSUPPORTED_ENCRYPTION); + return MZ_FALSE; + } + + if (bit_flag & MZ_ZIP_GENERAL_PURPOSE_BIT_FLAG_COMPRESSED_PATCH_FLAG) + { + mz_zip_set_error(pZip, MZ_ZIP_UNSUPPORTED_FEATURE); + return MZ_FALSE; + } + + return MZ_TRUE; +} + +mz_bool mz_zip_reader_is_file_a_directory(mz_zip_archive *pZip, mz_uint file_index) +{ + mz_uint filename_len, attribute_mapping_id, external_attr; + const mz_uint8 *p = mz_zip_get_cdh(pZip, file_index); + if (!p) + { + mz_zip_set_error(pZip, MZ_ZIP_INVALID_PARAMETER); + return MZ_FALSE; + } + + filename_len = MZ_READ_LE16(p + MZ_ZIP_CDH_FILENAME_LEN_OFS); + if (filename_len) + { + if (*(p + MZ_ZIP_CENTRAL_DIR_HEADER_SIZE + filename_len - 1) == '/') + return MZ_TRUE; + } + + /* Bugfix: This code was also checking if the internal attribute was non-zero, which wasn't correct. */ + /* Most/all zip writers (hopefully) set DOS file/directory attributes in the low 16-bits, so check for the DOS directory flag and ignore the source OS ID in the created by field. */ + /* FIXME: Remove this check? Is it necessary - we already check the filename. */ + attribute_mapping_id = MZ_READ_LE16(p + MZ_ZIP_CDH_VERSION_MADE_BY_OFS) >> 8; + (void)attribute_mapping_id; + + external_attr = MZ_READ_LE32(p + MZ_ZIP_CDH_EXTERNAL_ATTR_OFS); + if ((external_attr & MZ_ZIP_DOS_DIR_ATTRIBUTE_BITFLAG) != 0) + { + return MZ_TRUE; + } + + return MZ_FALSE; +} + +static mz_bool mz_zip_file_stat_internal(mz_zip_archive *pZip, mz_uint file_index, const mz_uint8 *pCentral_dir_header, mz_zip_archive_file_stat *pStat, mz_bool *pFound_zip64_extra_data) +{ + mz_uint n; + const mz_uint8 *p = pCentral_dir_header; + + if (pFound_zip64_extra_data) + *pFound_zip64_extra_data = MZ_FALSE; + + if ((!p) || (!pStat)) + return mz_zip_set_error(pZip, MZ_ZIP_INVALID_PARAMETER); + + /* Extract fields from the central directory record. */ + pStat->m_file_index = file_index; + pStat->m_central_dir_ofs = MZ_ZIP_ARRAY_ELEMENT(&pZip->m_pState->m_central_dir_offsets, mz_uint32, file_index); + pStat->m_version_made_by = MZ_READ_LE16(p + MZ_ZIP_CDH_VERSION_MADE_BY_OFS); + pStat->m_version_needed = MZ_READ_LE16(p + MZ_ZIP_CDH_VERSION_NEEDED_OFS); + pStat->m_bit_flag = MZ_READ_LE16(p + MZ_ZIP_CDH_BIT_FLAG_OFS); + pStat->m_method = MZ_READ_LE16(p + MZ_ZIP_CDH_METHOD_OFS); +#ifndef MINIZ_NO_TIME + pStat->m_time = mz_zip_dos_to_time_t(MZ_READ_LE16(p + MZ_ZIP_CDH_FILE_TIME_OFS), MZ_READ_LE16(p + MZ_ZIP_CDH_FILE_DATE_OFS)); +#endif + pStat->m_crc32 = MZ_READ_LE32(p + MZ_ZIP_CDH_CRC32_OFS); + pStat->m_comp_size = MZ_READ_LE32(p + MZ_ZIP_CDH_COMPRESSED_SIZE_OFS); + pStat->m_uncomp_size = MZ_READ_LE32(p + MZ_ZIP_CDH_DECOMPRESSED_SIZE_OFS); + pStat->m_internal_attr = MZ_READ_LE16(p + MZ_ZIP_CDH_INTERNAL_ATTR_OFS); + pStat->m_external_attr = MZ_READ_LE32(p + MZ_ZIP_CDH_EXTERNAL_ATTR_OFS); + pStat->m_local_header_ofs = MZ_READ_LE32(p + MZ_ZIP_CDH_LOCAL_HEADER_OFS); + + /* Copy as much of the filename and comment as possible. */ + n = MZ_READ_LE16(p + MZ_ZIP_CDH_FILENAME_LEN_OFS); + n = MZ_MIN(n, MZ_ZIP_MAX_ARCHIVE_FILENAME_SIZE - 1); + memcpy(pStat->m_filename, p + MZ_ZIP_CENTRAL_DIR_HEADER_SIZE, n); + pStat->m_filename[n] = '\0'; + + n = MZ_READ_LE16(p + MZ_ZIP_CDH_COMMENT_LEN_OFS); + n = MZ_MIN(n, MZ_ZIP_MAX_ARCHIVE_FILE_COMMENT_SIZE - 1); + pStat->m_comment_size = n; + memcpy(pStat->m_comment, p + MZ_ZIP_CENTRAL_DIR_HEADER_SIZE + MZ_READ_LE16(p + MZ_ZIP_CDH_FILENAME_LEN_OFS) + MZ_READ_LE16(p + MZ_ZIP_CDH_EXTRA_LEN_OFS), n); + pStat->m_comment[n] = '\0'; + + /* Set some flags for convienance */ + pStat->m_is_directory = mz_zip_reader_is_file_a_directory(pZip, file_index); + pStat->m_is_encrypted = mz_zip_reader_is_file_encrypted(pZip, file_index); + pStat->m_is_supported = mz_zip_reader_is_file_supported(pZip, file_index); + + /* See if we need to read any zip64 extended information fields. */ + /* Confusingly, these zip64 fields can be present even on non-zip64 archives (Debian zip on a huge files from stdin piped to stdout creates them). */ + if (MZ_MAX(MZ_MAX(pStat->m_comp_size, pStat->m_uncomp_size), pStat->m_local_header_ofs) == MZ_UINT32_MAX) + { + /* Attempt to find zip64 extended information field in the entry's extra data */ + mz_uint32 extra_size_remaining = MZ_READ_LE16(p + MZ_ZIP_CDH_EXTRA_LEN_OFS); + + if (extra_size_remaining) + { + const mz_uint8 *pExtra_data = p + MZ_ZIP_CENTRAL_DIR_HEADER_SIZE + MZ_READ_LE16(p + MZ_ZIP_CDH_FILENAME_LEN_OFS); + + do + { + mz_uint32 field_id; + mz_uint32 field_data_size; + + if (extra_size_remaining < (sizeof(mz_uint16) * 2)) + return mz_zip_set_error(pZip, MZ_ZIP_INVALID_HEADER_OR_CORRUPTED); + + field_id = MZ_READ_LE16(pExtra_data); + field_data_size = MZ_READ_LE16(pExtra_data + sizeof(mz_uint16)); + + if ((field_data_size + sizeof(mz_uint16) * 2) > extra_size_remaining) + return mz_zip_set_error(pZip, MZ_ZIP_INVALID_HEADER_OR_CORRUPTED); + + if (field_id == MZ_ZIP64_EXTENDED_INFORMATION_FIELD_HEADER_ID) + { + const mz_uint8 *pField_data = pExtra_data + sizeof(mz_uint16) * 2; + mz_uint32 field_data_remaining = field_data_size; + + if (pFound_zip64_extra_data) + *pFound_zip64_extra_data = MZ_TRUE; + + if (pStat->m_uncomp_size == MZ_UINT32_MAX) + { + if (field_data_remaining < sizeof(mz_uint64)) + return mz_zip_set_error(pZip, MZ_ZIP_INVALID_HEADER_OR_CORRUPTED); + + pStat->m_uncomp_size = MZ_READ_LE64(pField_data); + pField_data += sizeof(mz_uint64); + field_data_remaining -= sizeof(mz_uint64); + } + + if (pStat->m_comp_size == MZ_UINT32_MAX) + { + if (field_data_remaining < sizeof(mz_uint64)) + return mz_zip_set_error(pZip, MZ_ZIP_INVALID_HEADER_OR_CORRUPTED); + + pStat->m_comp_size = MZ_READ_LE64(pField_data); + pField_data += sizeof(mz_uint64); + field_data_remaining -= sizeof(mz_uint64); + } + + if (pStat->m_local_header_ofs == MZ_UINT32_MAX) + { + if (field_data_remaining < sizeof(mz_uint64)) + return mz_zip_set_error(pZip, MZ_ZIP_INVALID_HEADER_OR_CORRUPTED); + + pStat->m_local_header_ofs = MZ_READ_LE64(pField_data); + pField_data += sizeof(mz_uint64); + field_data_remaining -= sizeof(mz_uint64); + } + + break; + } + + pExtra_data += sizeof(mz_uint16) * 2 + field_data_size; + extra_size_remaining = extra_size_remaining - sizeof(mz_uint16) * 2 - field_data_size; + } while (extra_size_remaining); + } + } + + return MZ_TRUE; +} + +static MZ_FORCEINLINE mz_bool mz_zip_string_equal(const char *pA, const char *pB, mz_uint len, mz_uint flags) +{ + mz_uint i; + if (flags & MZ_ZIP_FLAG_CASE_SENSITIVE) + return 0 == memcmp(pA, pB, len); + for (i = 0; i < len; ++i) + if (MZ_TOLOWER(pA[i]) != MZ_TOLOWER(pB[i])) + return MZ_FALSE; + return MZ_TRUE; +} + +static MZ_FORCEINLINE int mz_zip_filename_compare(const mz_zip_array *pCentral_dir_array, const mz_zip_array *pCentral_dir_offsets, mz_uint l_index, const char *pR, mz_uint r_len) +{ + const mz_uint8 *pL = &MZ_ZIP_ARRAY_ELEMENT(pCentral_dir_array, mz_uint8, MZ_ZIP_ARRAY_ELEMENT(pCentral_dir_offsets, mz_uint32, l_index)), *pE; + mz_uint l_len = MZ_READ_LE16(pL + MZ_ZIP_CDH_FILENAME_LEN_OFS); + mz_uint8 l = 0, r = 0; + pL += MZ_ZIP_CENTRAL_DIR_HEADER_SIZE; + pE = pL + MZ_MIN(l_len, r_len); + while (pL < pE) + { + if ((l = MZ_TOLOWER(*pL)) != (r = MZ_TOLOWER(*pR))) + break; + pL++; + pR++; + } + return (pL == pE) ? (int)(l_len - r_len) : (l - r); +} + +static mz_bool mz_zip_locate_file_binary_search(mz_zip_archive *pZip, const char *pFilename, mz_uint32 *pIndex) +{ + mz_zip_internal_state *pState = pZip->m_pState; + const mz_zip_array *pCentral_dir_offsets = &pState->m_central_dir_offsets; + const mz_zip_array *pCentral_dir = &pState->m_central_dir; + mz_uint32 *pIndices = &MZ_ZIP_ARRAY_ELEMENT(&pState->m_sorted_central_dir_offsets, mz_uint32, 0); + const uint32_t size = pZip->m_total_files; + const mz_uint filename_len = (mz_uint)strlen(pFilename); + + if (pIndex) + *pIndex = 0; + + if (size) + { + /* yes I could use uint32_t's, but then we would have to add some special case checks in the loop, argh, and */ + /* honestly the major expense here on 32-bit CPU's will still be the filename compare */ + mz_int64 l = 0, h = (mz_int64)size - 1; + + while (l <= h) + { + mz_int64 m = l + ((h - l) >> 1); + uint32_t file_index = pIndices[(uint32_t)m]; + + int comp = mz_zip_filename_compare(pCentral_dir, pCentral_dir_offsets, file_index, pFilename, filename_len); + if (!comp) + { + if (pIndex) + *pIndex = file_index; + return MZ_TRUE; + } + else if (comp < 0) + l = m + 1; + else + h = m - 1; + } + } + + return mz_zip_set_error(pZip, MZ_ZIP_FILE_NOT_FOUND); +} + +int mz_zip_reader_locate_file(mz_zip_archive *pZip, const char *pName, const char *pComment, mz_uint flags) +{ + mz_uint32 index; + if (!mz_zip_reader_locate_file_v2(pZip, pName, pComment, flags, &index)) + return -1; + else + return (int)index; +} + +mz_bool mz_zip_reader_locate_file_v2(mz_zip_archive *pZip, const char *pName, const char *pComment, mz_uint flags, mz_uint32 *pIndex) +{ + mz_uint file_index; + size_t name_len, comment_len; + + if (pIndex) + *pIndex = 0; + + if ((!pZip) || (!pZip->m_pState) || (!pName)) + return mz_zip_set_error(pZip, MZ_ZIP_INVALID_PARAMETER); + + /* See if we can use a binary search */ + if (((pZip->m_pState->m_init_flags & MZ_ZIP_FLAG_DO_NOT_SORT_CENTRAL_DIRECTORY) == 0) && + (pZip->m_zip_mode == MZ_ZIP_MODE_READING) && + ((flags & (MZ_ZIP_FLAG_IGNORE_PATH | MZ_ZIP_FLAG_CASE_SENSITIVE)) == 0) && (!pComment) && (pZip->m_pState->m_sorted_central_dir_offsets.m_size)) + { + return mz_zip_locate_file_binary_search(pZip, pName, pIndex); + } + + /* Locate the entry by scanning the entire central directory */ + name_len = strlen(pName); + if (name_len > MZ_UINT16_MAX) + return mz_zip_set_error(pZip, MZ_ZIP_INVALID_PARAMETER); + + comment_len = pComment ? strlen(pComment) : 0; + if (comment_len > MZ_UINT16_MAX) + return mz_zip_set_error(pZip, MZ_ZIP_INVALID_PARAMETER); + + for (file_index = 0; file_index < pZip->m_total_files; file_index++) + { + const mz_uint8 *pHeader = &MZ_ZIP_ARRAY_ELEMENT(&pZip->m_pState->m_central_dir, mz_uint8, MZ_ZIP_ARRAY_ELEMENT(&pZip->m_pState->m_central_dir_offsets, mz_uint32, file_index)); + mz_uint filename_len = MZ_READ_LE16(pHeader + MZ_ZIP_CDH_FILENAME_LEN_OFS); + const char *pFilename = (const char *)pHeader + MZ_ZIP_CENTRAL_DIR_HEADER_SIZE; + if (filename_len < name_len) + continue; + if (comment_len) + { + mz_uint file_extra_len = MZ_READ_LE16(pHeader + MZ_ZIP_CDH_EXTRA_LEN_OFS), file_comment_len = MZ_READ_LE16(pHeader + MZ_ZIP_CDH_COMMENT_LEN_OFS); + const char *pFile_comment = pFilename + filename_len + file_extra_len; + if ((file_comment_len != comment_len) || (!mz_zip_string_equal(pComment, pFile_comment, file_comment_len, flags))) + continue; + } + if ((flags & MZ_ZIP_FLAG_IGNORE_PATH) && (filename_len)) + { + int ofs = filename_len - 1; + do + { + if ((pFilename[ofs] == '/') || (pFilename[ofs] == '\\') || (pFilename[ofs] == ':')) + break; + } while (--ofs >= 0); + ofs++; + pFilename += ofs; + filename_len -= ofs; + } + if ((filename_len == name_len) && (mz_zip_string_equal(pName, pFilename, filename_len, flags))) + { + if (pIndex) + *pIndex = file_index; + return MZ_TRUE; + } + } + + return mz_zip_set_error(pZip, MZ_ZIP_FILE_NOT_FOUND); +} + +mz_bool mz_zip_reader_extract_to_mem_no_alloc(mz_zip_archive *pZip, mz_uint file_index, void *pBuf, size_t buf_size, mz_uint flags, void *pUser_read_buf, size_t user_read_buf_size) +{ + int status = TINFL_STATUS_DONE; + mz_uint64 needed_size, cur_file_ofs, comp_remaining, out_buf_ofs = 0, read_buf_size, read_buf_ofs = 0, read_buf_avail; + mz_zip_archive_file_stat file_stat; + void *pRead_buf; + mz_uint32 local_header_u32[(MZ_ZIP_LOCAL_DIR_HEADER_SIZE + sizeof(mz_uint32) - 1) / sizeof(mz_uint32)]; + mz_uint8 *pLocal_header = (mz_uint8 *)local_header_u32; + tinfl_decompressor inflator; + + if ((!pZip) || (!pZip->m_pState) || ((buf_size) && (!pBuf)) || ((user_read_buf_size) && (!pUser_read_buf)) || (!pZip->m_pRead)) + return mz_zip_set_error(pZip, MZ_ZIP_INVALID_PARAMETER); + + if (!mz_zip_reader_file_stat(pZip, file_index, &file_stat)) + return MZ_FALSE; + + /* A directory or zero length file */ + if ((file_stat.m_is_directory) || (!file_stat.m_comp_size)) + return MZ_TRUE; + + /* Encryption and patch files are not supported. */ + if (file_stat.m_bit_flag & (MZ_ZIP_GENERAL_PURPOSE_BIT_FLAG_IS_ENCRYPTED | MZ_ZIP_GENERAL_PURPOSE_BIT_FLAG_USES_STRONG_ENCRYPTION | MZ_ZIP_GENERAL_PURPOSE_BIT_FLAG_COMPRESSED_PATCH_FLAG)) + return mz_zip_set_error(pZip, MZ_ZIP_UNSUPPORTED_ENCRYPTION); + + /* This function only supports decompressing stored and deflate. */ + if ((!(flags & MZ_ZIP_FLAG_COMPRESSED_DATA)) && (file_stat.m_method != 0) && (file_stat.m_method != MZ_DEFLATED)) + return mz_zip_set_error(pZip, MZ_ZIP_UNSUPPORTED_METHOD); + + /* Ensure supplied output buffer is large enough. */ + needed_size = (flags & MZ_ZIP_FLAG_COMPRESSED_DATA) ? file_stat.m_comp_size : file_stat.m_uncomp_size; + if (buf_size < needed_size) + return mz_zip_set_error(pZip, MZ_ZIP_BUF_TOO_SMALL); + + /* Read and parse the local directory entry. */ + cur_file_ofs = file_stat.m_local_header_ofs; + if (pZip->m_pRead(pZip->m_pIO_opaque, cur_file_ofs, pLocal_header, MZ_ZIP_LOCAL_DIR_HEADER_SIZE) != MZ_ZIP_LOCAL_DIR_HEADER_SIZE) + return mz_zip_set_error(pZip, MZ_ZIP_FILE_READ_FAILED); + + if (MZ_READ_LE32(pLocal_header) != MZ_ZIP_LOCAL_DIR_HEADER_SIG) + return mz_zip_set_error(pZip, MZ_ZIP_INVALID_HEADER_OR_CORRUPTED); + + cur_file_ofs += MZ_ZIP_LOCAL_DIR_HEADER_SIZE + MZ_READ_LE16(pLocal_header + MZ_ZIP_LDH_FILENAME_LEN_OFS) + MZ_READ_LE16(pLocal_header + MZ_ZIP_LDH_EXTRA_LEN_OFS); + if ((cur_file_ofs + file_stat.m_comp_size) > pZip->m_archive_size) + return mz_zip_set_error(pZip, MZ_ZIP_INVALID_HEADER_OR_CORRUPTED); + + if ((flags & MZ_ZIP_FLAG_COMPRESSED_DATA) || (!file_stat.m_method)) + { + /* The file is stored or the caller has requested the compressed data. */ + if (pZip->m_pRead(pZip->m_pIO_opaque, cur_file_ofs, pBuf, (size_t)needed_size) != needed_size) + return mz_zip_set_error(pZip, MZ_ZIP_FILE_READ_FAILED); + +#ifndef MINIZ_DISABLE_ZIP_READER_CRC32_CHECKS + if ((flags & MZ_ZIP_FLAG_COMPRESSED_DATA) == 0) + { + if (mz_crc32(MZ_CRC32_INIT, (const mz_uint8 *)pBuf, (size_t)file_stat.m_uncomp_size) != file_stat.m_crc32) + return mz_zip_set_error(pZip, MZ_ZIP_CRC_CHECK_FAILED); + } +#endif + + return MZ_TRUE; + } + + /* Decompress the file either directly from memory or from a file input buffer. */ + tinfl_init(&inflator); + + if (pZip->m_pState->m_pMem) + { + /* Read directly from the archive in memory. */ + pRead_buf = (mz_uint8 *)pZip->m_pState->m_pMem + cur_file_ofs; + read_buf_size = read_buf_avail = file_stat.m_comp_size; + comp_remaining = 0; + } + else if (pUser_read_buf) + { + /* Use a user provided read buffer. */ + if (!user_read_buf_size) + return MZ_FALSE; + pRead_buf = (mz_uint8 *)pUser_read_buf; + read_buf_size = user_read_buf_size; + read_buf_avail = 0; + comp_remaining = file_stat.m_comp_size; + } + else + { + /* Temporarily allocate a read buffer. */ + read_buf_size = MZ_MIN(file_stat.m_comp_size, (mz_uint64)MZ_ZIP_MAX_IO_BUF_SIZE); + if (((sizeof(size_t) == sizeof(mz_uint32))) && (read_buf_size > 0x7FFFFFFF)) + return mz_zip_set_error(pZip, MZ_ZIP_INTERNAL_ERROR); + + if (NULL == (pRead_buf = pZip->m_pAlloc(pZip->m_pAlloc_opaque, 1, (size_t)read_buf_size))) + return mz_zip_set_error(pZip, MZ_ZIP_ALLOC_FAILED); + + read_buf_avail = 0; + comp_remaining = file_stat.m_comp_size; + } + + do + { + /* The size_t cast here should be OK because we've verified that the output buffer is >= file_stat.m_uncomp_size above */ + size_t in_buf_size, out_buf_size = (size_t)(file_stat.m_uncomp_size - out_buf_ofs); + if ((!read_buf_avail) && (!pZip->m_pState->m_pMem)) + { + read_buf_avail = MZ_MIN(read_buf_size, comp_remaining); + if (pZip->m_pRead(pZip->m_pIO_opaque, cur_file_ofs, pRead_buf, (size_t)read_buf_avail) != read_buf_avail) + { + status = TINFL_STATUS_FAILED; + mz_zip_set_error(pZip, MZ_ZIP_DECOMPRESSION_FAILED); + break; + } + cur_file_ofs += read_buf_avail; + comp_remaining -= read_buf_avail; + read_buf_ofs = 0; + } + in_buf_size = (size_t)read_buf_avail; + status = tinfl_decompress(&inflator, (mz_uint8 *)pRead_buf + read_buf_ofs, &in_buf_size, (mz_uint8 *)pBuf, (mz_uint8 *)pBuf + out_buf_ofs, &out_buf_size, TINFL_FLAG_USING_NON_WRAPPING_OUTPUT_BUF | (comp_remaining ? TINFL_FLAG_HAS_MORE_INPUT : 0)); + read_buf_avail -= in_buf_size; + read_buf_ofs += in_buf_size; + out_buf_ofs += out_buf_size; + } while (status == TINFL_STATUS_NEEDS_MORE_INPUT); + + if (status == TINFL_STATUS_DONE) + { + /* Make sure the entire file was decompressed, and check its CRC. */ + if (out_buf_ofs != file_stat.m_uncomp_size) + { + mz_zip_set_error(pZip, MZ_ZIP_UNEXPECTED_DECOMPRESSED_SIZE); + status = TINFL_STATUS_FAILED; + } +#ifndef MINIZ_DISABLE_ZIP_READER_CRC32_CHECKS + else if (mz_crc32(MZ_CRC32_INIT, (const mz_uint8 *)pBuf, (size_t)file_stat.m_uncomp_size) != file_stat.m_crc32) + { + mz_zip_set_error(pZip, MZ_ZIP_CRC_CHECK_FAILED); + status = TINFL_STATUS_FAILED; + } +#endif + } + + if ((!pZip->m_pState->m_pMem) && (!pUser_read_buf)) + pZip->m_pFree(pZip->m_pAlloc_opaque, pRead_buf); + + return status == TINFL_STATUS_DONE; +} + +mz_bool mz_zip_reader_extract_file_to_mem_no_alloc(mz_zip_archive *pZip, const char *pFilename, void *pBuf, size_t buf_size, mz_uint flags, void *pUser_read_buf, size_t user_read_buf_size) +{ + mz_uint32 file_index; + if (!mz_zip_reader_locate_file_v2(pZip, pFilename, NULL, flags, &file_index)) + return MZ_FALSE; + return mz_zip_reader_extract_to_mem_no_alloc(pZip, file_index, pBuf, buf_size, flags, pUser_read_buf, user_read_buf_size); +} + +mz_bool mz_zip_reader_extract_to_mem(mz_zip_archive *pZip, mz_uint file_index, void *pBuf, size_t buf_size, mz_uint flags) +{ + return mz_zip_reader_extract_to_mem_no_alloc(pZip, file_index, pBuf, buf_size, flags, NULL, 0); +} + +mz_bool mz_zip_reader_extract_file_to_mem(mz_zip_archive *pZip, const char *pFilename, void *pBuf, size_t buf_size, mz_uint flags) +{ + return mz_zip_reader_extract_file_to_mem_no_alloc(pZip, pFilename, pBuf, buf_size, flags, NULL, 0); +} + +void *mz_zip_reader_extract_to_heap(mz_zip_archive *pZip, mz_uint file_index, size_t *pSize, mz_uint flags) +{ + mz_uint64 comp_size, uncomp_size, alloc_size; + const mz_uint8 *p = mz_zip_get_cdh(pZip, file_index); + void *pBuf; + + if (pSize) + *pSize = 0; + + if (!p) + { + mz_zip_set_error(pZip, MZ_ZIP_INVALID_PARAMETER); + return NULL; + } + + comp_size = MZ_READ_LE32(p + MZ_ZIP_CDH_COMPRESSED_SIZE_OFS); + uncomp_size = MZ_READ_LE32(p + MZ_ZIP_CDH_DECOMPRESSED_SIZE_OFS); + + alloc_size = (flags & MZ_ZIP_FLAG_COMPRESSED_DATA) ? comp_size : uncomp_size; + if (((sizeof(size_t) == sizeof(mz_uint32))) && (alloc_size > 0x7FFFFFFF)) + { + mz_zip_set_error(pZip, MZ_ZIP_INTERNAL_ERROR); + return NULL; + } + + if (NULL == (pBuf = pZip->m_pAlloc(pZip->m_pAlloc_opaque, 1, (size_t)alloc_size))) + { + mz_zip_set_error(pZip, MZ_ZIP_ALLOC_FAILED); + return NULL; + } + + if (!mz_zip_reader_extract_to_mem(pZip, file_index, pBuf, (size_t)alloc_size, flags)) + { + pZip->m_pFree(pZip->m_pAlloc_opaque, pBuf); + return NULL; + } + + if (pSize) + *pSize = (size_t)alloc_size; + return pBuf; +} + +void *mz_zip_reader_extract_file_to_heap(mz_zip_archive *pZip, const char *pFilename, size_t *pSize, mz_uint flags) +{ + mz_uint32 file_index; + if (!mz_zip_reader_locate_file_v2(pZip, pFilename, NULL, flags, &file_index)) + { + if (pSize) + *pSize = 0; + return MZ_FALSE; + } + return mz_zip_reader_extract_to_heap(pZip, file_index, pSize, flags); +} + +mz_bool mz_zip_reader_extract_to_callback(mz_zip_archive *pZip, mz_uint file_index, mz_file_write_func pCallback, void *pOpaque, mz_uint flags) +{ + int status = TINFL_STATUS_DONE; + mz_uint file_crc32 = MZ_CRC32_INIT; + mz_uint64 read_buf_size, read_buf_ofs = 0, read_buf_avail, comp_remaining, out_buf_ofs = 0, cur_file_ofs; + mz_zip_archive_file_stat file_stat; + void *pRead_buf = NULL; + void *pWrite_buf = NULL; + mz_uint32 local_header_u32[(MZ_ZIP_LOCAL_DIR_HEADER_SIZE + sizeof(mz_uint32) - 1) / sizeof(mz_uint32)]; + mz_uint8 *pLocal_header = (mz_uint8 *)local_header_u32; + + if ((!pZip) || (!pZip->m_pState) || (!pCallback) || (!pZip->m_pRead)) + return mz_zip_set_error(pZip, MZ_ZIP_INVALID_PARAMETER); + + if (!mz_zip_reader_file_stat(pZip, file_index, &file_stat)) + return MZ_FALSE; + + /* A directory or zero length file */ + if ((file_stat.m_is_directory) || (!file_stat.m_comp_size)) + return MZ_TRUE; + + /* Encryption and patch files are not supported. */ + if (file_stat.m_bit_flag & (MZ_ZIP_GENERAL_PURPOSE_BIT_FLAG_IS_ENCRYPTED | MZ_ZIP_GENERAL_PURPOSE_BIT_FLAG_USES_STRONG_ENCRYPTION | MZ_ZIP_GENERAL_PURPOSE_BIT_FLAG_COMPRESSED_PATCH_FLAG)) + return mz_zip_set_error(pZip, MZ_ZIP_UNSUPPORTED_ENCRYPTION); + + /* This function only supports decompressing stored and deflate. */ + if ((!(flags & MZ_ZIP_FLAG_COMPRESSED_DATA)) && (file_stat.m_method != 0) && (file_stat.m_method != MZ_DEFLATED)) + return mz_zip_set_error(pZip, MZ_ZIP_UNSUPPORTED_METHOD); + + /* Read and do some minimal validation of the local directory entry (this doesn't crack the zip64 stuff, which we already have from the central dir) */ + cur_file_ofs = file_stat.m_local_header_ofs; + if (pZip->m_pRead(pZip->m_pIO_opaque, cur_file_ofs, pLocal_header, MZ_ZIP_LOCAL_DIR_HEADER_SIZE) != MZ_ZIP_LOCAL_DIR_HEADER_SIZE) + return mz_zip_set_error(pZip, MZ_ZIP_FILE_READ_FAILED); + + if (MZ_READ_LE32(pLocal_header) != MZ_ZIP_LOCAL_DIR_HEADER_SIG) + return mz_zip_set_error(pZip, MZ_ZIP_INVALID_HEADER_OR_CORRUPTED); + + cur_file_ofs += MZ_ZIP_LOCAL_DIR_HEADER_SIZE + MZ_READ_LE16(pLocal_header + MZ_ZIP_LDH_FILENAME_LEN_OFS) + MZ_READ_LE16(pLocal_header + MZ_ZIP_LDH_EXTRA_LEN_OFS); + if ((cur_file_ofs + file_stat.m_comp_size) > pZip->m_archive_size) + return mz_zip_set_error(pZip, MZ_ZIP_INVALID_HEADER_OR_CORRUPTED); + + /* Decompress the file either directly from memory or from a file input buffer. */ + if (pZip->m_pState->m_pMem) + { + pRead_buf = (mz_uint8 *)pZip->m_pState->m_pMem + cur_file_ofs; + read_buf_size = read_buf_avail = file_stat.m_comp_size; + comp_remaining = 0; + } + else + { + read_buf_size = MZ_MIN(file_stat.m_comp_size, (mz_uint64)MZ_ZIP_MAX_IO_BUF_SIZE); + if (NULL == (pRead_buf = pZip->m_pAlloc(pZip->m_pAlloc_opaque, 1, (size_t)read_buf_size))) + return mz_zip_set_error(pZip, MZ_ZIP_ALLOC_FAILED); + + read_buf_avail = 0; + comp_remaining = file_stat.m_comp_size; + } + + if ((flags & MZ_ZIP_FLAG_COMPRESSED_DATA) || (!file_stat.m_method)) + { + /* The file is stored or the caller has requested the compressed data. */ + if (pZip->m_pState->m_pMem) + { + if (((sizeof(size_t) == sizeof(mz_uint32))) && (file_stat.m_comp_size > MZ_UINT32_MAX)) + return mz_zip_set_error(pZip, MZ_ZIP_INTERNAL_ERROR); + + if (pCallback(pOpaque, out_buf_ofs, pRead_buf, (size_t)file_stat.m_comp_size) != file_stat.m_comp_size) + { + mz_zip_set_error(pZip, MZ_ZIP_WRITE_CALLBACK_FAILED); + status = TINFL_STATUS_FAILED; + } + else if (!(flags & MZ_ZIP_FLAG_COMPRESSED_DATA)) + { +#ifndef MINIZ_DISABLE_ZIP_READER_CRC32_CHECKS + file_crc32 = (mz_uint32)mz_crc32(file_crc32, (const mz_uint8 *)pRead_buf, (size_t)file_stat.m_comp_size); +#endif + } + + cur_file_ofs += file_stat.m_comp_size; + out_buf_ofs += file_stat.m_comp_size; + comp_remaining = 0; + } + else + { + while (comp_remaining) + { + read_buf_avail = MZ_MIN(read_buf_size, comp_remaining); + if (pZip->m_pRead(pZip->m_pIO_opaque, cur_file_ofs, pRead_buf, (size_t)read_buf_avail) != read_buf_avail) + { + mz_zip_set_error(pZip, MZ_ZIP_FILE_READ_FAILED); + status = TINFL_STATUS_FAILED; + break; + } + +#ifndef MINIZ_DISABLE_ZIP_READER_CRC32_CHECKS + if (!(flags & MZ_ZIP_FLAG_COMPRESSED_DATA)) + { + file_crc32 = (mz_uint32)mz_crc32(file_crc32, (const mz_uint8 *)pRead_buf, (size_t)read_buf_avail); + } +#endif + + if (pCallback(pOpaque, out_buf_ofs, pRead_buf, (size_t)read_buf_avail) != read_buf_avail) + { + mz_zip_set_error(pZip, MZ_ZIP_WRITE_CALLBACK_FAILED); + status = TINFL_STATUS_FAILED; + break; + } + + cur_file_ofs += read_buf_avail; + out_buf_ofs += read_buf_avail; + comp_remaining -= read_buf_avail; + } + } + } + else + { + tinfl_decompressor inflator; + tinfl_init(&inflator); + + if (NULL == (pWrite_buf = pZip->m_pAlloc(pZip->m_pAlloc_opaque, 1, TINFL_LZ_DICT_SIZE))) + { + mz_zip_set_error(pZip, MZ_ZIP_ALLOC_FAILED); + status = TINFL_STATUS_FAILED; + } + else + { + do + { + mz_uint8 *pWrite_buf_cur = (mz_uint8 *)pWrite_buf + (out_buf_ofs & (TINFL_LZ_DICT_SIZE - 1)); + size_t in_buf_size, out_buf_size = TINFL_LZ_DICT_SIZE - (out_buf_ofs & (TINFL_LZ_DICT_SIZE - 1)); + if ((!read_buf_avail) && (!pZip->m_pState->m_pMem)) + { + read_buf_avail = MZ_MIN(read_buf_size, comp_remaining); + if (pZip->m_pRead(pZip->m_pIO_opaque, cur_file_ofs, pRead_buf, (size_t)read_buf_avail) != read_buf_avail) + { + mz_zip_set_error(pZip, MZ_ZIP_FILE_READ_FAILED); + status = TINFL_STATUS_FAILED; + break; + } + cur_file_ofs += read_buf_avail; + comp_remaining -= read_buf_avail; + read_buf_ofs = 0; + } + + in_buf_size = (size_t)read_buf_avail; + status = tinfl_decompress(&inflator, (const mz_uint8 *)pRead_buf + read_buf_ofs, &in_buf_size, (mz_uint8 *)pWrite_buf, pWrite_buf_cur, &out_buf_size, comp_remaining ? TINFL_FLAG_HAS_MORE_INPUT : 0); + read_buf_avail -= in_buf_size; + read_buf_ofs += in_buf_size; + + if (out_buf_size) + { + if (pCallback(pOpaque, out_buf_ofs, pWrite_buf_cur, out_buf_size) != out_buf_size) + { + mz_zip_set_error(pZip, MZ_ZIP_WRITE_CALLBACK_FAILED); + status = TINFL_STATUS_FAILED; + break; + } + +#ifndef MINIZ_DISABLE_ZIP_READER_CRC32_CHECKS + file_crc32 = (mz_uint32)mz_crc32(file_crc32, pWrite_buf_cur, out_buf_size); +#endif + if ((out_buf_ofs += out_buf_size) > file_stat.m_uncomp_size) + { + mz_zip_set_error(pZip, MZ_ZIP_DECOMPRESSION_FAILED); + status = TINFL_STATUS_FAILED; + break; + } + } + } while ((status == TINFL_STATUS_NEEDS_MORE_INPUT) || (status == TINFL_STATUS_HAS_MORE_OUTPUT)); + } + } + + if ((status == TINFL_STATUS_DONE) && (!(flags & MZ_ZIP_FLAG_COMPRESSED_DATA))) + { + /* Make sure the entire file was decompressed, and check its CRC. */ + if (out_buf_ofs != file_stat.m_uncomp_size) + { + mz_zip_set_error(pZip, MZ_ZIP_UNEXPECTED_DECOMPRESSED_SIZE); + status = TINFL_STATUS_FAILED; + } +#ifndef MINIZ_DISABLE_ZIP_READER_CRC32_CHECKS + else if (file_crc32 != file_stat.m_crc32) + { + mz_zip_set_error(pZip, MZ_ZIP_DECOMPRESSION_FAILED); + status = TINFL_STATUS_FAILED; + } +#endif + } + + if (!pZip->m_pState->m_pMem) + pZip->m_pFree(pZip->m_pAlloc_opaque, pRead_buf); + + if (pWrite_buf) + pZip->m_pFree(pZip->m_pAlloc_opaque, pWrite_buf); + + return status == TINFL_STATUS_DONE; +} + +mz_bool mz_zip_reader_extract_file_to_callback(mz_zip_archive *pZip, const char *pFilename, mz_file_write_func pCallback, void *pOpaque, mz_uint flags) +{ + mz_uint32 file_index; + if (!mz_zip_reader_locate_file_v2(pZip, pFilename, NULL, flags, &file_index)) + return MZ_FALSE; + + return mz_zip_reader_extract_to_callback(pZip, file_index, pCallback, pOpaque, flags); +} + +mz_zip_reader_extract_iter_state* mz_zip_reader_extract_iter_new(mz_zip_archive *pZip, mz_uint file_index, mz_uint flags) +{ + mz_zip_reader_extract_iter_state *pState; + mz_uint32 local_header_u32[(MZ_ZIP_LOCAL_DIR_HEADER_SIZE + sizeof(mz_uint32) - 1) / sizeof(mz_uint32)]; + mz_uint8 *pLocal_header = (mz_uint8 *)local_header_u32; + + /* Argument sanity check */ + if ((!pZip) || (!pZip->m_pState)) + return NULL; + + /* Allocate an iterator status structure */ + pState = (mz_zip_reader_extract_iter_state*)pZip->m_pAlloc(pZip->m_pAlloc_opaque, 1, sizeof(mz_zip_reader_extract_iter_state)); + if (!pState) + { + mz_zip_set_error(pZip, MZ_ZIP_ALLOC_FAILED); + return NULL; + } + + /* Fetch file details */ + if (!mz_zip_reader_file_stat(pZip, file_index, &pState->file_stat)) + { + pZip->m_pFree(pZip->m_pAlloc_opaque, pState); + return NULL; + } + + /* Encryption and patch files are not supported. */ + if (pState->file_stat.m_bit_flag & (MZ_ZIP_GENERAL_PURPOSE_BIT_FLAG_IS_ENCRYPTED | MZ_ZIP_GENERAL_PURPOSE_BIT_FLAG_USES_STRONG_ENCRYPTION | MZ_ZIP_GENERAL_PURPOSE_BIT_FLAG_COMPRESSED_PATCH_FLAG)) + { + mz_zip_set_error(pZip, MZ_ZIP_UNSUPPORTED_ENCRYPTION); + pZip->m_pFree(pZip->m_pAlloc_opaque, pState); + return NULL; + } + + /* This function only supports decompressing stored and deflate. */ + if ((!(flags & MZ_ZIP_FLAG_COMPRESSED_DATA)) && (pState->file_stat.m_method != 0) && (pState->file_stat.m_method != MZ_DEFLATED)) + { + mz_zip_set_error(pZip, MZ_ZIP_UNSUPPORTED_METHOD); + pZip->m_pFree(pZip->m_pAlloc_opaque, pState); + return NULL; + } + + /* Init state - save args */ + pState->pZip = pZip; + pState->flags = flags; + + /* Init state - reset variables to defaults */ + pState->status = TINFL_STATUS_DONE; +#ifndef MINIZ_DISABLE_ZIP_READER_CRC32_CHECKS + pState->file_crc32 = MZ_CRC32_INIT; +#endif + pState->read_buf_ofs = 0; + pState->out_buf_ofs = 0; + pState->pRead_buf = NULL; + pState->pWrite_buf = NULL; + pState->out_blk_remain = 0; + + /* Read and parse the local directory entry. */ + pState->cur_file_ofs = pState->file_stat.m_local_header_ofs; + if (pZip->m_pRead(pZip->m_pIO_opaque, pState->cur_file_ofs, pLocal_header, MZ_ZIP_LOCAL_DIR_HEADER_SIZE) != MZ_ZIP_LOCAL_DIR_HEADER_SIZE) + { + mz_zip_set_error(pZip, MZ_ZIP_FILE_READ_FAILED); + pZip->m_pFree(pZip->m_pAlloc_opaque, pState); + return NULL; + } + + if (MZ_READ_LE32(pLocal_header) != MZ_ZIP_LOCAL_DIR_HEADER_SIG) + { + mz_zip_set_error(pZip, MZ_ZIP_INVALID_HEADER_OR_CORRUPTED); + pZip->m_pFree(pZip->m_pAlloc_opaque, pState); + return NULL; + } + + pState->cur_file_ofs += MZ_ZIP_LOCAL_DIR_HEADER_SIZE + MZ_READ_LE16(pLocal_header + MZ_ZIP_LDH_FILENAME_LEN_OFS) + MZ_READ_LE16(pLocal_header + MZ_ZIP_LDH_EXTRA_LEN_OFS); + if ((pState->cur_file_ofs + pState->file_stat.m_comp_size) > pZip->m_archive_size) + { + mz_zip_set_error(pZip, MZ_ZIP_INVALID_HEADER_OR_CORRUPTED); + pZip->m_pFree(pZip->m_pAlloc_opaque, pState); + return NULL; + } + + /* Decompress the file either directly from memory or from a file input buffer. */ + if (pZip->m_pState->m_pMem) + { + pState->pRead_buf = (mz_uint8 *)pZip->m_pState->m_pMem + pState->cur_file_ofs; + pState->read_buf_size = pState->read_buf_avail = pState->file_stat.m_comp_size; + pState->comp_remaining = pState->file_stat.m_comp_size; + } + else + { + if (!((flags & MZ_ZIP_FLAG_COMPRESSED_DATA) || (!pState->file_stat.m_method))) + { + /* Decompression required, therefore intermediate read buffer required */ + pState->read_buf_size = MZ_MIN(pState->file_stat.m_comp_size, MZ_ZIP_MAX_IO_BUF_SIZE); + if (NULL == (pState->pRead_buf = pZip->m_pAlloc(pZip->m_pAlloc_opaque, 1, (size_t)pState->read_buf_size))) + { + mz_zip_set_error(pZip, MZ_ZIP_ALLOC_FAILED); + pZip->m_pFree(pZip->m_pAlloc_opaque, pState); + return NULL; + } + } + else + { + /* Decompression not required - we will be reading directly into user buffer, no temp buf required */ + pState->read_buf_size = 0; + } + pState->read_buf_avail = 0; + pState->comp_remaining = pState->file_stat.m_comp_size; + } + + if (!((flags & MZ_ZIP_FLAG_COMPRESSED_DATA) || (!pState->file_stat.m_method))) + { + /* Decompression required, init decompressor */ + tinfl_init( &pState->inflator ); + + /* Allocate write buffer */ + if (NULL == (pState->pWrite_buf = pZip->m_pAlloc(pZip->m_pAlloc_opaque, 1, TINFL_LZ_DICT_SIZE))) + { + mz_zip_set_error(pZip, MZ_ZIP_ALLOC_FAILED); + if (pState->pRead_buf) + pZip->m_pFree(pZip->m_pAlloc_opaque, pState->pRead_buf); + pZip->m_pFree(pZip->m_pAlloc_opaque, pState); + return NULL; + } + } + + return pState; +} + +mz_zip_reader_extract_iter_state* mz_zip_reader_extract_file_iter_new(mz_zip_archive *pZip, const char *pFilename, mz_uint flags) +{ + mz_uint32 file_index; + + /* Locate file index by name */ + if (!mz_zip_reader_locate_file_v2(pZip, pFilename, NULL, flags, &file_index)) + return NULL; + + /* Construct iterator */ + return mz_zip_reader_extract_iter_new(pZip, file_index, flags); +} + +size_t mz_zip_reader_extract_iter_read(mz_zip_reader_extract_iter_state* pState, void* pvBuf, size_t buf_size) +{ + size_t copied_to_caller = 0; + + /* Argument sanity check */ + if ((!pState) || (!pState->pZip) || (!pState->pZip->m_pState) || (!pvBuf)) + return 0; + + if ((pState->flags & MZ_ZIP_FLAG_COMPRESSED_DATA) || (!pState->file_stat.m_method)) + { + /* The file is stored or the caller has requested the compressed data, calc amount to return. */ + copied_to_caller = MZ_MIN( buf_size, pState->comp_remaining ); + + /* Zip is in memory....or requires reading from a file? */ + if (pState->pZip->m_pState->m_pMem) + { + /* Copy data to caller's buffer */ + memcpy( pvBuf, pState->pRead_buf, copied_to_caller ); + pState->pRead_buf = ((mz_uint8*)pState->pRead_buf) + copied_to_caller; + } + else + { + /* Read directly into caller's buffer */ + if (pState->pZip->m_pRead(pState->pZip->m_pIO_opaque, pState->cur_file_ofs, pvBuf, copied_to_caller) != copied_to_caller) + { + /* Failed to read all that was asked for, flag failure and alert user */ + mz_zip_set_error(pState->pZip, MZ_ZIP_FILE_READ_FAILED); + pState->status = TINFL_STATUS_FAILED; + copied_to_caller = 0; + } + } + +#ifndef MINIZ_DISABLE_ZIP_READER_CRC32_CHECKS + /* Compute CRC if not returning compressed data only */ + if (!(pState->flags & MZ_ZIP_FLAG_COMPRESSED_DATA)) + pState->file_crc32 = (mz_uint32)mz_crc32(pState->file_crc32, (const mz_uint8 *)pvBuf, copied_to_caller); +#endif + + /* Advance offsets, dec counters */ + pState->cur_file_ofs += copied_to_caller; + pState->out_buf_ofs += copied_to_caller; + pState->comp_remaining -= copied_to_caller; + } + else + { + do + { + /* Calc ptr to write buffer - given current output pos and block size */ + mz_uint8 *pWrite_buf_cur = (mz_uint8 *)pState->pWrite_buf + (pState->out_buf_ofs & (TINFL_LZ_DICT_SIZE - 1)); + + /* Calc max output size - given current output pos and block size */ + size_t in_buf_size, out_buf_size = TINFL_LZ_DICT_SIZE - (pState->out_buf_ofs & (TINFL_LZ_DICT_SIZE - 1)); + + if (!pState->out_blk_remain) + { + /* Read more data from file if none available (and reading from file) */ + if ((!pState->read_buf_avail) && (!pState->pZip->m_pState->m_pMem)) + { + /* Calc read size */ + pState->read_buf_avail = MZ_MIN(pState->read_buf_size, pState->comp_remaining); + if (pState->pZip->m_pRead(pState->pZip->m_pIO_opaque, pState->cur_file_ofs, pState->pRead_buf, (size_t)pState->read_buf_avail) != pState->read_buf_avail) + { + mz_zip_set_error(pState->pZip, MZ_ZIP_FILE_READ_FAILED); + pState->status = TINFL_STATUS_FAILED; + break; + } + + /* Advance offsets, dec counters */ + pState->cur_file_ofs += pState->read_buf_avail; + pState->comp_remaining -= pState->read_buf_avail; + pState->read_buf_ofs = 0; + } + + /* Perform decompression */ + in_buf_size = (size_t)pState->read_buf_avail; + pState->status = tinfl_decompress(&pState->inflator, (const mz_uint8 *)pState->pRead_buf + pState->read_buf_ofs, &in_buf_size, (mz_uint8 *)pState->pWrite_buf, pWrite_buf_cur, &out_buf_size, pState->comp_remaining ? TINFL_FLAG_HAS_MORE_INPUT : 0); + pState->read_buf_avail -= in_buf_size; + pState->read_buf_ofs += in_buf_size; + + /* Update current output block size remaining */ + pState->out_blk_remain = out_buf_size; + } + + if (pState->out_blk_remain) + { + /* Calc amount to return. */ + size_t to_copy = MZ_MIN( (buf_size - copied_to_caller), pState->out_blk_remain ); + + /* Copy data to caller's buffer */ + memcpy( (uint8_t*)pvBuf + copied_to_caller, pWrite_buf_cur, to_copy ); + +#ifndef MINIZ_DISABLE_ZIP_READER_CRC32_CHECKS + /* Perform CRC */ + pState->file_crc32 = (mz_uint32)mz_crc32(pState->file_crc32, pWrite_buf_cur, to_copy); +#endif + + /* Decrement data consumed from block */ + pState->out_blk_remain -= to_copy; + + /* Inc output offset, while performing sanity check */ + if ((pState->out_buf_ofs += to_copy) > pState->file_stat.m_uncomp_size) + { + mz_zip_set_error(pState->pZip, MZ_ZIP_DECOMPRESSION_FAILED); + pState->status = TINFL_STATUS_FAILED; + break; + } + + /* Increment counter of data copied to caller */ + copied_to_caller += to_copy; + } + } while ( (copied_to_caller < buf_size) && ((pState->status == TINFL_STATUS_NEEDS_MORE_INPUT) || (pState->status == TINFL_STATUS_HAS_MORE_OUTPUT)) ); + } + + /* Return how many bytes were copied into user buffer */ + return copied_to_caller; +} + +mz_bool mz_zip_reader_extract_iter_free(mz_zip_reader_extract_iter_state* pState) +{ + int status; + + /* Argument sanity check */ + if ((!pState) || (!pState->pZip) || (!pState->pZip->m_pState)) + return MZ_FALSE; + + /* Was decompression completed and requested? */ + if ((pState->status == TINFL_STATUS_DONE) && (!(pState->flags & MZ_ZIP_FLAG_COMPRESSED_DATA))) + { + /* Make sure the entire file was decompressed, and check its CRC. */ + if (pState->out_buf_ofs != pState->file_stat.m_uncomp_size) + { + mz_zip_set_error(pState->pZip, MZ_ZIP_UNEXPECTED_DECOMPRESSED_SIZE); + pState->status = TINFL_STATUS_FAILED; + } +#ifndef MINIZ_DISABLE_ZIP_READER_CRC32_CHECKS + else if (pState->file_crc32 != pState->file_stat.m_crc32) + { + mz_zip_set_error(pState->pZip, MZ_ZIP_DECOMPRESSION_FAILED); + pState->status = TINFL_STATUS_FAILED; + } +#endif + } + + /* Free buffers */ + if (!pState->pZip->m_pState->m_pMem) + pState->pZip->m_pFree(pState->pZip->m_pAlloc_opaque, pState->pRead_buf); + if (pState->pWrite_buf) + pState->pZip->m_pFree(pState->pZip->m_pAlloc_opaque, pState->pWrite_buf); + + /* Save status */ + status = pState->status; + + /* Free context */ + pState->pZip->m_pFree(pState->pZip->m_pAlloc_opaque, pState); + + return status == TINFL_STATUS_DONE; +} + +#ifndef MINIZ_NO_STDIO +static size_t mz_zip_file_write_callback(void *pOpaque, mz_uint64 ofs, const void *pBuf, size_t n) +{ + (void)ofs; + + return MZ_FWRITE(pBuf, 1, n, (MZ_FILE *)pOpaque); +} + +mz_bool mz_zip_reader_extract_to_file(mz_zip_archive *pZip, mz_uint file_index, const char *pDst_filename, mz_uint flags) +{ + mz_bool status; + mz_zip_archive_file_stat file_stat; + MZ_FILE *pFile; + + if (!mz_zip_reader_file_stat(pZip, file_index, &file_stat)) + return MZ_FALSE; + + if ((file_stat.m_is_directory) || (!file_stat.m_is_supported)) + return mz_zip_set_error(pZip, MZ_ZIP_UNSUPPORTED_FEATURE); + + pFile = MZ_FOPEN(pDst_filename, "wb"); + if (!pFile) + return mz_zip_set_error(pZip, MZ_ZIP_FILE_OPEN_FAILED); + + status = mz_zip_reader_extract_to_callback(pZip, file_index, mz_zip_file_write_callback, pFile, flags); + + if (MZ_FCLOSE(pFile) == EOF) + { + if (status) + mz_zip_set_error(pZip, MZ_ZIP_FILE_CLOSE_FAILED); + + status = MZ_FALSE; + } + +#if !defined(MINIZ_NO_TIME) && !defined(MINIZ_NO_STDIO) + if (status) + mz_zip_set_file_times(pDst_filename, file_stat.m_time, file_stat.m_time); +#endif + + return status; +} + +mz_bool mz_zip_reader_extract_file_to_file(mz_zip_archive *pZip, const char *pArchive_filename, const char *pDst_filename, mz_uint flags) +{ + mz_uint32 file_index; + if (!mz_zip_reader_locate_file_v2(pZip, pArchive_filename, NULL, flags, &file_index)) + return MZ_FALSE; + + return mz_zip_reader_extract_to_file(pZip, file_index, pDst_filename, flags); +} + +mz_bool mz_zip_reader_extract_to_cfile(mz_zip_archive *pZip, mz_uint file_index, MZ_FILE *pFile, mz_uint flags) +{ + mz_zip_archive_file_stat file_stat; + + if (!mz_zip_reader_file_stat(pZip, file_index, &file_stat)) + return MZ_FALSE; + + if ((file_stat.m_is_directory) || (!file_stat.m_is_supported)) + return mz_zip_set_error(pZip, MZ_ZIP_UNSUPPORTED_FEATURE); + + return mz_zip_reader_extract_to_callback(pZip, file_index, mz_zip_file_write_callback, pFile, flags); +} + +mz_bool mz_zip_reader_extract_file_to_cfile(mz_zip_archive *pZip, const char *pArchive_filename, MZ_FILE *pFile, mz_uint flags) +{ + mz_uint32 file_index; + if (!mz_zip_reader_locate_file_v2(pZip, pArchive_filename, NULL, flags, &file_index)) + return MZ_FALSE; + + return mz_zip_reader_extract_to_cfile(pZip, file_index, pFile, flags); +} +#endif /* #ifndef MINIZ_NO_STDIO */ + +static size_t mz_zip_compute_crc32_callback(void *pOpaque, mz_uint64 file_ofs, const void *pBuf, size_t n) +{ + mz_uint32 *p = (mz_uint32 *)pOpaque; + (void)file_ofs; + *p = (mz_uint32)mz_crc32(*p, (const mz_uint8 *)pBuf, n); + return n; +} + +mz_bool mz_zip_validate_file(mz_zip_archive *pZip, mz_uint file_index, mz_uint flags) +{ + mz_zip_archive_file_stat file_stat; + mz_zip_internal_state *pState; + const mz_uint8 *pCentral_dir_header; + mz_bool found_zip64_ext_data_in_cdir = MZ_FALSE; + mz_bool found_zip64_ext_data_in_ldir = MZ_FALSE; + mz_uint32 local_header_u32[(MZ_ZIP_LOCAL_DIR_HEADER_SIZE + sizeof(mz_uint32) - 1) / sizeof(mz_uint32)]; + mz_uint8 *pLocal_header = (mz_uint8 *)local_header_u32; + mz_uint64 local_header_ofs = 0; + mz_uint32 local_header_filename_len, local_header_extra_len, local_header_crc32; + mz_uint64 local_header_comp_size, local_header_uncomp_size; + mz_uint32 uncomp_crc32 = MZ_CRC32_INIT; + mz_bool has_data_descriptor; + mz_uint32 local_header_bit_flags; + + mz_zip_array file_data_array; + mz_zip_array_init(&file_data_array, 1); + + if ((!pZip) || (!pZip->m_pState) || (!pZip->m_pAlloc) || (!pZip->m_pFree) || (!pZip->m_pRead)) + return mz_zip_set_error(pZip, MZ_ZIP_INVALID_PARAMETER); + + if (file_index > pZip->m_total_files) + return mz_zip_set_error(pZip, MZ_ZIP_INVALID_PARAMETER); + + pState = pZip->m_pState; + + pCentral_dir_header = mz_zip_get_cdh(pZip, file_index); + + if (!mz_zip_file_stat_internal(pZip, file_index, pCentral_dir_header, &file_stat, &found_zip64_ext_data_in_cdir)) + return MZ_FALSE; + + /* A directory or zero length file */ + if ((file_stat.m_is_directory) || (!file_stat.m_uncomp_size)) + return MZ_TRUE; + + /* Encryption and patch files are not supported. */ + if (file_stat.m_is_encrypted) + return mz_zip_set_error(pZip, MZ_ZIP_UNSUPPORTED_ENCRYPTION); + + /* This function only supports stored and deflate. */ + if ((file_stat.m_method != 0) && (file_stat.m_method != MZ_DEFLATED)) + return mz_zip_set_error(pZip, MZ_ZIP_UNSUPPORTED_METHOD); + + if (!file_stat.m_is_supported) + return mz_zip_set_error(pZip, MZ_ZIP_UNSUPPORTED_FEATURE); + + /* Read and parse the local directory entry. */ + local_header_ofs = file_stat.m_local_header_ofs; + if (pZip->m_pRead(pZip->m_pIO_opaque, local_header_ofs, pLocal_header, MZ_ZIP_LOCAL_DIR_HEADER_SIZE) != MZ_ZIP_LOCAL_DIR_HEADER_SIZE) + return mz_zip_set_error(pZip, MZ_ZIP_FILE_READ_FAILED); + + if (MZ_READ_LE32(pLocal_header) != MZ_ZIP_LOCAL_DIR_HEADER_SIG) + return mz_zip_set_error(pZip, MZ_ZIP_INVALID_HEADER_OR_CORRUPTED); + + local_header_filename_len = MZ_READ_LE16(pLocal_header + MZ_ZIP_LDH_FILENAME_LEN_OFS); + local_header_extra_len = MZ_READ_LE16(pLocal_header + MZ_ZIP_LDH_EXTRA_LEN_OFS); + local_header_comp_size = MZ_READ_LE32(pLocal_header + MZ_ZIP_LDH_COMPRESSED_SIZE_OFS); + local_header_uncomp_size = MZ_READ_LE32(pLocal_header + MZ_ZIP_LDH_DECOMPRESSED_SIZE_OFS); + local_header_crc32 = MZ_READ_LE32(pLocal_header + MZ_ZIP_LDH_CRC32_OFS); + local_header_bit_flags = MZ_READ_LE16(pLocal_header + MZ_ZIP_LDH_BIT_FLAG_OFS); + has_data_descriptor = (local_header_bit_flags & 8) != 0; + + if (local_header_filename_len != strlen(file_stat.m_filename)) + return mz_zip_set_error(pZip, MZ_ZIP_INVALID_HEADER_OR_CORRUPTED); + + if ((local_header_ofs + MZ_ZIP_LOCAL_DIR_HEADER_SIZE + local_header_filename_len + local_header_extra_len + file_stat.m_comp_size) > pZip->m_archive_size) + return mz_zip_set_error(pZip, MZ_ZIP_INVALID_HEADER_OR_CORRUPTED); + + if (!mz_zip_array_resize(pZip, &file_data_array, MZ_MAX(local_header_filename_len, local_header_extra_len), MZ_FALSE)) + return mz_zip_set_error(pZip, MZ_ZIP_ALLOC_FAILED); + + if (local_header_filename_len) + { + if (pZip->m_pRead(pZip->m_pIO_opaque, local_header_ofs + MZ_ZIP_LOCAL_DIR_HEADER_SIZE, file_data_array.m_p, local_header_filename_len) != local_header_filename_len) + { + mz_zip_set_error(pZip, MZ_ZIP_FILE_READ_FAILED); + goto handle_failure; + } + + /* I've seen 1 archive that had the same pathname, but used backslashes in the local dir and forward slashes in the central dir. Do we care about this? For now, this case will fail validation. */ + if (memcmp(file_stat.m_filename, file_data_array.m_p, local_header_filename_len) != 0) + { + mz_zip_set_error(pZip, MZ_ZIP_VALIDATION_FAILED); + goto handle_failure; + } + } + + if ((local_header_extra_len) && ((local_header_comp_size == MZ_UINT32_MAX) || (local_header_uncomp_size == MZ_UINT32_MAX))) + { + mz_uint32 extra_size_remaining = local_header_extra_len; + const mz_uint8 *pExtra_data = (const mz_uint8 *)file_data_array.m_p; + + if (pZip->m_pRead(pZip->m_pIO_opaque, local_header_ofs + MZ_ZIP_LOCAL_DIR_HEADER_SIZE + local_header_filename_len, file_data_array.m_p, local_header_extra_len) != local_header_extra_len) + { + mz_zip_set_error(pZip, MZ_ZIP_FILE_READ_FAILED); + goto handle_failure; + } + + do + { + mz_uint32 field_id, field_data_size, field_total_size; + + if (extra_size_remaining < (sizeof(mz_uint16) * 2)) + return mz_zip_set_error(pZip, MZ_ZIP_INVALID_HEADER_OR_CORRUPTED); + + field_id = MZ_READ_LE16(pExtra_data); + field_data_size = MZ_READ_LE16(pExtra_data + sizeof(mz_uint16)); + field_total_size = field_data_size + sizeof(mz_uint16) * 2; + + if (field_total_size > extra_size_remaining) + return mz_zip_set_error(pZip, MZ_ZIP_INVALID_HEADER_OR_CORRUPTED); + + if (field_id == MZ_ZIP64_EXTENDED_INFORMATION_FIELD_HEADER_ID) + { + const mz_uint8 *pSrc_field_data = pExtra_data + sizeof(mz_uint32); + + if (field_data_size < sizeof(mz_uint64) * 2) + { + mz_zip_set_error(pZip, MZ_ZIP_INVALID_HEADER_OR_CORRUPTED); + goto handle_failure; + } + + local_header_uncomp_size = MZ_READ_LE64(pSrc_field_data); + local_header_comp_size = MZ_READ_LE64(pSrc_field_data + sizeof(mz_uint64)); + + found_zip64_ext_data_in_ldir = MZ_TRUE; + break; + } + + pExtra_data += field_total_size; + extra_size_remaining -= field_total_size; + } while (extra_size_remaining); + } + + /* TODO: parse local header extra data when local_header_comp_size is 0xFFFFFFFF! (big_descriptor.zip) */ + /* I've seen zips in the wild with the data descriptor bit set, but proper local header values and bogus data descriptors */ + if ((has_data_descriptor) && (!local_header_comp_size) && (!local_header_crc32)) + { + mz_uint8 descriptor_buf[32]; + mz_bool has_id; + const mz_uint8 *pSrc; + mz_uint32 file_crc32; + mz_uint64 comp_size = 0, uncomp_size = 0; + + mz_uint32 num_descriptor_uint32s = ((pState->m_zip64) || (found_zip64_ext_data_in_ldir)) ? 6 : 4; + + if (pZip->m_pRead(pZip->m_pIO_opaque, local_header_ofs + MZ_ZIP_LOCAL_DIR_HEADER_SIZE + local_header_filename_len + local_header_extra_len + file_stat.m_comp_size, descriptor_buf, sizeof(mz_uint32) * num_descriptor_uint32s) != (sizeof(mz_uint32) * num_descriptor_uint32s)) + { + mz_zip_set_error(pZip, MZ_ZIP_FILE_READ_FAILED); + goto handle_failure; + } + + has_id = (MZ_READ_LE32(descriptor_buf) == MZ_ZIP_DATA_DESCRIPTOR_ID); + pSrc = has_id ? (descriptor_buf + sizeof(mz_uint32)) : descriptor_buf; + + file_crc32 = MZ_READ_LE32(pSrc); + + if ((pState->m_zip64) || (found_zip64_ext_data_in_ldir)) + { + comp_size = MZ_READ_LE64(pSrc + sizeof(mz_uint32)); + uncomp_size = MZ_READ_LE64(pSrc + sizeof(mz_uint32) + sizeof(mz_uint64)); + } + else + { + comp_size = MZ_READ_LE32(pSrc + sizeof(mz_uint32)); + uncomp_size = MZ_READ_LE32(pSrc + sizeof(mz_uint32) + sizeof(mz_uint32)); + } + + if ((file_crc32 != file_stat.m_crc32) || (comp_size != file_stat.m_comp_size) || (uncomp_size != file_stat.m_uncomp_size)) + { + mz_zip_set_error(pZip, MZ_ZIP_VALIDATION_FAILED); + goto handle_failure; + } + } + else + { + if ((local_header_crc32 != file_stat.m_crc32) || (local_header_comp_size != file_stat.m_comp_size) || (local_header_uncomp_size != file_stat.m_uncomp_size)) + { + mz_zip_set_error(pZip, MZ_ZIP_VALIDATION_FAILED); + goto handle_failure; + } + } + + mz_zip_array_clear(pZip, &file_data_array); + + if ((flags & MZ_ZIP_FLAG_VALIDATE_HEADERS_ONLY) == 0) + { + if (!mz_zip_reader_extract_to_callback(pZip, file_index, mz_zip_compute_crc32_callback, &uncomp_crc32, 0)) + return MZ_FALSE; + + /* 1 more check to be sure, although the extract checks too. */ + if (uncomp_crc32 != file_stat.m_crc32) + { + mz_zip_set_error(pZip, MZ_ZIP_VALIDATION_FAILED); + return MZ_FALSE; + } + } + + return MZ_TRUE; + +handle_failure: + mz_zip_array_clear(pZip, &file_data_array); + return MZ_FALSE; +} + +mz_bool mz_zip_validate_archive(mz_zip_archive *pZip, mz_uint flags) +{ + mz_zip_internal_state *pState; + uint32_t i; + + if ((!pZip) || (!pZip->m_pState) || (!pZip->m_pAlloc) || (!pZip->m_pFree) || (!pZip->m_pRead)) + return mz_zip_set_error(pZip, MZ_ZIP_INVALID_PARAMETER); + + pState = pZip->m_pState; + + /* Basic sanity checks */ + if (!pState->m_zip64) + { + if (pZip->m_total_files > MZ_UINT16_MAX) + return mz_zip_set_error(pZip, MZ_ZIP_ARCHIVE_TOO_LARGE); + + if (pZip->m_archive_size > MZ_UINT32_MAX) + return mz_zip_set_error(pZip, MZ_ZIP_ARCHIVE_TOO_LARGE); + } + else + { + if (pZip->m_total_files >= MZ_UINT32_MAX) + return mz_zip_set_error(pZip, MZ_ZIP_ARCHIVE_TOO_LARGE); + + if (pState->m_central_dir.m_size >= MZ_UINT32_MAX) + return mz_zip_set_error(pZip, MZ_ZIP_ARCHIVE_TOO_LARGE); + } + + for (i = 0; i < pZip->m_total_files; i++) + { + if (MZ_ZIP_FLAG_VALIDATE_LOCATE_FILE_FLAG & flags) + { + mz_uint32 found_index; + mz_zip_archive_file_stat stat; + + if (!mz_zip_reader_file_stat(pZip, i, &stat)) + return MZ_FALSE; + + if (!mz_zip_reader_locate_file_v2(pZip, stat.m_filename, NULL, 0, &found_index)) + return MZ_FALSE; + + /* This check can fail if there are duplicate filenames in the archive (which we don't check for when writing - that's up to the user) */ + if (found_index != i) + return mz_zip_set_error(pZip, MZ_ZIP_VALIDATION_FAILED); + } + + if (!mz_zip_validate_file(pZip, i, flags)) + return MZ_FALSE; + } + + return MZ_TRUE; +} + +mz_bool mz_zip_validate_mem_archive(const void *pMem, size_t size, mz_uint flags, mz_zip_error *pErr) +{ + mz_bool success = MZ_TRUE; + mz_zip_archive zip; + mz_zip_error actual_err = MZ_ZIP_NO_ERROR; + + if ((!pMem) || (!size)) + { + if (pErr) + *pErr = MZ_ZIP_INVALID_PARAMETER; + return MZ_FALSE; + } + + mz_zip_zero_struct(&zip); + + if (!mz_zip_reader_init_mem(&zip, pMem, size, flags)) + { + if (pErr) + *pErr = zip.m_last_error; + return MZ_FALSE; + } + + if (!mz_zip_validate_archive(&zip, flags)) + { + actual_err = zip.m_last_error; + success = MZ_FALSE; + } + + if (!mz_zip_reader_end_internal(&zip, success)) + { + if (!actual_err) + actual_err = zip.m_last_error; + success = MZ_FALSE; + } + + if (pErr) + *pErr = actual_err; + + return success; +} + +#ifndef MINIZ_NO_STDIO +mz_bool mz_zip_validate_file_archive(const char *pFilename, mz_uint flags, mz_zip_error *pErr) +{ + mz_bool success = MZ_TRUE; + mz_zip_archive zip; + mz_zip_error actual_err = MZ_ZIP_NO_ERROR; + + if (!pFilename) + { + if (pErr) + *pErr = MZ_ZIP_INVALID_PARAMETER; + return MZ_FALSE; + } + + mz_zip_zero_struct(&zip); + + if (!mz_zip_reader_init_file_v2(&zip, pFilename, flags, 0, 0)) + { + if (pErr) + *pErr = zip.m_last_error; + return MZ_FALSE; + } + + if (!mz_zip_validate_archive(&zip, flags)) + { + actual_err = zip.m_last_error; + success = MZ_FALSE; + } + + if (!mz_zip_reader_end_internal(&zip, success)) + { + if (!actual_err) + actual_err = zip.m_last_error; + success = MZ_FALSE; + } + + if (pErr) + *pErr = actual_err; + + return success; +} +#endif /* #ifndef MINIZ_NO_STDIO */ + +/* ------------------- .ZIP archive writing */ + +#ifndef MINIZ_NO_ARCHIVE_WRITING_APIS + +static MZ_FORCEINLINE void mz_write_le16(mz_uint8 *p, mz_uint16 v) +{ + p[0] = (mz_uint8)v; + p[1] = (mz_uint8)(v >> 8); +} +static MZ_FORCEINLINE void mz_write_le32(mz_uint8 *p, mz_uint32 v) +{ + p[0] = (mz_uint8)v; + p[1] = (mz_uint8)(v >> 8); + p[2] = (mz_uint8)(v >> 16); + p[3] = (mz_uint8)(v >> 24); +} +static MZ_FORCEINLINE void mz_write_le64(mz_uint8 *p, mz_uint64 v) +{ + mz_write_le32(p, (mz_uint32)v); + mz_write_le32(p + sizeof(mz_uint32), (mz_uint32)(v >> 32)); +} + +#define MZ_WRITE_LE16(p, v) mz_write_le16((mz_uint8 *)(p), (mz_uint16)(v)) +#define MZ_WRITE_LE32(p, v) mz_write_le32((mz_uint8 *)(p), (mz_uint32)(v)) +#define MZ_WRITE_LE64(p, v) mz_write_le64((mz_uint8 *)(p), (mz_uint64)(v)) + +static size_t mz_zip_heap_write_func(void *pOpaque, mz_uint64 file_ofs, const void *pBuf, size_t n) +{ + mz_zip_archive *pZip = (mz_zip_archive *)pOpaque; + mz_zip_internal_state *pState = pZip->m_pState; + mz_uint64 new_size = MZ_MAX(file_ofs + n, pState->m_mem_size); + + if (!n) + return 0; + + /* An allocation this big is likely to just fail on 32-bit systems, so don't even go there. */ + if ((sizeof(size_t) == sizeof(mz_uint32)) && (new_size > 0x7FFFFFFF)) + { + mz_zip_set_error(pZip, MZ_ZIP_FILE_TOO_LARGE); + return 0; + } + + if (new_size > pState->m_mem_capacity) + { + void *pNew_block; + size_t new_capacity = MZ_MAX(64, pState->m_mem_capacity); + + while (new_capacity < new_size) + new_capacity *= 2; + + if (NULL == (pNew_block = pZip->m_pRealloc(pZip->m_pAlloc_opaque, pState->m_pMem, 1, new_capacity))) + { + mz_zip_set_error(pZip, MZ_ZIP_ALLOC_FAILED); + return 0; + } + + pState->m_pMem = pNew_block; + pState->m_mem_capacity = new_capacity; + } + memcpy((mz_uint8 *)pState->m_pMem + file_ofs, pBuf, n); + pState->m_mem_size = (size_t)new_size; + return n; +} + +static mz_bool mz_zip_writer_end_internal(mz_zip_archive *pZip, mz_bool set_last_error) +{ + mz_zip_internal_state *pState; + mz_bool status = MZ_TRUE; + + if ((!pZip) || (!pZip->m_pState) || (!pZip->m_pAlloc) || (!pZip->m_pFree) || ((pZip->m_zip_mode != MZ_ZIP_MODE_WRITING) && (pZip->m_zip_mode != MZ_ZIP_MODE_WRITING_HAS_BEEN_FINALIZED))) + { + if (set_last_error) + mz_zip_set_error(pZip, MZ_ZIP_INVALID_PARAMETER); + return MZ_FALSE; + } + + pState = pZip->m_pState; + pZip->m_pState = NULL; + mz_zip_array_clear(pZip, &pState->m_central_dir); + mz_zip_array_clear(pZip, &pState->m_central_dir_offsets); + mz_zip_array_clear(pZip, &pState->m_sorted_central_dir_offsets); + +#ifndef MINIZ_NO_STDIO + if (pState->m_pFile) + { + if (pZip->m_zip_type == MZ_ZIP_TYPE_FILE) + { + if (MZ_FCLOSE(pState->m_pFile) == EOF) + { + if (set_last_error) + mz_zip_set_error(pZip, MZ_ZIP_FILE_CLOSE_FAILED); + status = MZ_FALSE; + } + } + + pState->m_pFile = NULL; + } +#endif /* #ifndef MINIZ_NO_STDIO */ + + if ((pZip->m_pWrite == mz_zip_heap_write_func) && (pState->m_pMem)) + { + pZip->m_pFree(pZip->m_pAlloc_opaque, pState->m_pMem); + pState->m_pMem = NULL; + } + + pZip->m_pFree(pZip->m_pAlloc_opaque, pState); + pZip->m_zip_mode = MZ_ZIP_MODE_INVALID; + return status; +} + +mz_bool mz_zip_writer_init_v2(mz_zip_archive *pZip, mz_uint64 existing_size, mz_uint flags) +{ + mz_bool zip64 = (flags & MZ_ZIP_FLAG_WRITE_ZIP64) != 0; + + if ((!pZip) || (pZip->m_pState) || (!pZip->m_pWrite) || (pZip->m_zip_mode != MZ_ZIP_MODE_INVALID)) + return mz_zip_set_error(pZip, MZ_ZIP_INVALID_PARAMETER); + + if (flags & MZ_ZIP_FLAG_WRITE_ALLOW_READING) + { + if (!pZip->m_pRead) + return mz_zip_set_error(pZip, MZ_ZIP_INVALID_PARAMETER); + } + + if (pZip->m_file_offset_alignment) + { + /* Ensure user specified file offset alignment is a power of 2. */ + if (pZip->m_file_offset_alignment & (pZip->m_file_offset_alignment - 1)) + return mz_zip_set_error(pZip, MZ_ZIP_INVALID_PARAMETER); + } + + if (!pZip->m_pAlloc) + pZip->m_pAlloc = miniz_def_alloc_func; + if (!pZip->m_pFree) + pZip->m_pFree = miniz_def_free_func; + if (!pZip->m_pRealloc) + pZip->m_pRealloc = miniz_def_realloc_func; + + pZip->m_archive_size = existing_size; + pZip->m_central_directory_file_ofs = 0; + pZip->m_total_files = 0; + + if (NULL == (pZip->m_pState = (mz_zip_internal_state *)pZip->m_pAlloc(pZip->m_pAlloc_opaque, 1, sizeof(mz_zip_internal_state)))) + return mz_zip_set_error(pZip, MZ_ZIP_ALLOC_FAILED); + + memset(pZip->m_pState, 0, sizeof(mz_zip_internal_state)); + + MZ_ZIP_ARRAY_SET_ELEMENT_SIZE(&pZip->m_pState->m_central_dir, sizeof(mz_uint8)); + MZ_ZIP_ARRAY_SET_ELEMENT_SIZE(&pZip->m_pState->m_central_dir_offsets, sizeof(mz_uint32)); + MZ_ZIP_ARRAY_SET_ELEMENT_SIZE(&pZip->m_pState->m_sorted_central_dir_offsets, sizeof(mz_uint32)); + + pZip->m_pState->m_zip64 = zip64; + pZip->m_pState->m_zip64_has_extended_info_fields = zip64; + + pZip->m_zip_type = MZ_ZIP_TYPE_USER; + pZip->m_zip_mode = MZ_ZIP_MODE_WRITING; + + return MZ_TRUE; +} + +mz_bool mz_zip_writer_init(mz_zip_archive *pZip, mz_uint64 existing_size) +{ + return mz_zip_writer_init_v2(pZip, existing_size, 0); +} + +mz_bool mz_zip_writer_init_heap_v2(mz_zip_archive *pZip, size_t size_to_reserve_at_beginning, size_t initial_allocation_size, mz_uint flags) +{ + pZip->m_pWrite = mz_zip_heap_write_func; + pZip->m_pNeeds_keepalive = NULL; + + if (flags & MZ_ZIP_FLAG_WRITE_ALLOW_READING) + pZip->m_pRead = mz_zip_mem_read_func; + + pZip->m_pIO_opaque = pZip; + + if (!mz_zip_writer_init_v2(pZip, size_to_reserve_at_beginning, flags)) + return MZ_FALSE; + + pZip->m_zip_type = MZ_ZIP_TYPE_HEAP; + + if (0 != (initial_allocation_size = MZ_MAX(initial_allocation_size, size_to_reserve_at_beginning))) + { + if (NULL == (pZip->m_pState->m_pMem = pZip->m_pAlloc(pZip->m_pAlloc_opaque, 1, initial_allocation_size))) + { + mz_zip_writer_end_internal(pZip, MZ_FALSE); + return mz_zip_set_error(pZip, MZ_ZIP_ALLOC_FAILED); + } + pZip->m_pState->m_mem_capacity = initial_allocation_size; + } + + return MZ_TRUE; +} + +mz_bool mz_zip_writer_init_heap(mz_zip_archive *pZip, size_t size_to_reserve_at_beginning, size_t initial_allocation_size) +{ + return mz_zip_writer_init_heap_v2(pZip, size_to_reserve_at_beginning, initial_allocation_size, 0); +} + +#ifndef MINIZ_NO_STDIO +static size_t mz_zip_file_write_func(void *pOpaque, mz_uint64 file_ofs, const void *pBuf, size_t n) +{ + mz_zip_archive *pZip = (mz_zip_archive *)pOpaque; + mz_int64 cur_ofs = MZ_FTELL64(pZip->m_pState->m_pFile); + + file_ofs += pZip->m_pState->m_file_archive_start_ofs; + + if (((mz_int64)file_ofs < 0) || (((cur_ofs != (mz_int64)file_ofs)) && (MZ_FSEEK64(pZip->m_pState->m_pFile, (mz_int64)file_ofs, SEEK_SET)))) + { + mz_zip_set_error(pZip, MZ_ZIP_FILE_SEEK_FAILED); + return 0; + } + + return MZ_FWRITE(pBuf, 1, n, pZip->m_pState->m_pFile); +} + +mz_bool mz_zip_writer_init_file(mz_zip_archive *pZip, const char *pFilename, mz_uint64 size_to_reserve_at_beginning) +{ + return mz_zip_writer_init_file_v2(pZip, pFilename, size_to_reserve_at_beginning, 0); +} + +mz_bool mz_zip_writer_init_file_v2(mz_zip_archive *pZip, const char *pFilename, mz_uint64 size_to_reserve_at_beginning, mz_uint flags) +{ + MZ_FILE *pFile; + + pZip->m_pWrite = mz_zip_file_write_func; + pZip->m_pNeeds_keepalive = NULL; + + if (flags & MZ_ZIP_FLAG_WRITE_ALLOW_READING) + pZip->m_pRead = mz_zip_file_read_func; + + pZip->m_pIO_opaque = pZip; + + if (!mz_zip_writer_init_v2(pZip, size_to_reserve_at_beginning, flags)) + return MZ_FALSE; + + if (NULL == (pFile = MZ_FOPEN(pFilename, (flags & MZ_ZIP_FLAG_WRITE_ALLOW_READING) ? "w+b" : "wb"))) + { + mz_zip_writer_end(pZip); + return mz_zip_set_error(pZip, MZ_ZIP_FILE_OPEN_FAILED); + } + + pZip->m_pState->m_pFile = pFile; + pZip->m_zip_type = MZ_ZIP_TYPE_FILE; + + if (size_to_reserve_at_beginning) + { + mz_uint64 cur_ofs = 0; + char buf[4096]; + + MZ_CLEAR_OBJ(buf); + + do + { + size_t n = (size_t)MZ_MIN(sizeof(buf), size_to_reserve_at_beginning); + if (pZip->m_pWrite(pZip->m_pIO_opaque, cur_ofs, buf, n) != n) + { + mz_zip_writer_end(pZip); + return mz_zip_set_error(pZip, MZ_ZIP_FILE_WRITE_FAILED); + } + cur_ofs += n; + size_to_reserve_at_beginning -= n; + } while (size_to_reserve_at_beginning); + } + + return MZ_TRUE; +} + +mz_bool mz_zip_writer_init_cfile(mz_zip_archive *pZip, MZ_FILE *pFile, mz_uint flags) +{ + pZip->m_pWrite = mz_zip_file_write_func; + pZip->m_pNeeds_keepalive = NULL; + + if (flags & MZ_ZIP_FLAG_WRITE_ALLOW_READING) + pZip->m_pRead = mz_zip_file_read_func; + + pZip->m_pIO_opaque = pZip; + + if (!mz_zip_writer_init_v2(pZip, 0, flags)) + return MZ_FALSE; + + pZip->m_pState->m_pFile = pFile; + pZip->m_pState->m_file_archive_start_ofs = MZ_FTELL64(pZip->m_pState->m_pFile); + pZip->m_zip_type = MZ_ZIP_TYPE_CFILE; + + return MZ_TRUE; +} +#endif /* #ifndef MINIZ_NO_STDIO */ + +mz_bool mz_zip_writer_init_from_reader_v2(mz_zip_archive *pZip, const char *pFilename, mz_uint flags) +{ + mz_zip_internal_state *pState; + + if ((!pZip) || (!pZip->m_pState) || (pZip->m_zip_mode != MZ_ZIP_MODE_READING)) + return mz_zip_set_error(pZip, MZ_ZIP_INVALID_PARAMETER); + + if (flags & MZ_ZIP_FLAG_WRITE_ZIP64) + { + /* We don't support converting a non-zip64 file to zip64 - this seems like more trouble than it's worth. (What about the existing 32-bit data descriptors that could follow the compressed data?) */ + if (!pZip->m_pState->m_zip64) + return mz_zip_set_error(pZip, MZ_ZIP_INVALID_PARAMETER); + } + + /* No sense in trying to write to an archive that's already at the support max size */ + if (pZip->m_pState->m_zip64) + { + if (pZip->m_total_files == MZ_UINT32_MAX) + return mz_zip_set_error(pZip, MZ_ZIP_TOO_MANY_FILES); + } + else + { + if (pZip->m_total_files == MZ_UINT16_MAX) + return mz_zip_set_error(pZip, MZ_ZIP_TOO_MANY_FILES); + + if ((pZip->m_archive_size + MZ_ZIP_CENTRAL_DIR_HEADER_SIZE + MZ_ZIP_LOCAL_DIR_HEADER_SIZE) > MZ_UINT32_MAX) + return mz_zip_set_error(pZip, MZ_ZIP_FILE_TOO_LARGE); + } + + pState = pZip->m_pState; + + if (pState->m_pFile) + { +#ifdef MINIZ_NO_STDIO + (void)pFilename; + return mz_zip_set_error(pZip, MZ_ZIP_INVALID_PARAMETER); +#else + if (pZip->m_pIO_opaque != pZip) + return mz_zip_set_error(pZip, MZ_ZIP_INVALID_PARAMETER); + + if (pZip->m_zip_type == MZ_ZIP_TYPE_FILE) + { + if (!pFilename) + return mz_zip_set_error(pZip, MZ_ZIP_INVALID_PARAMETER); + + /* Archive is being read from stdio and was originally opened only for reading. Try to reopen as writable. */ + if (NULL == (pState->m_pFile = MZ_FREOPEN(pFilename, "r+b", pState->m_pFile))) + { + /* The mz_zip_archive is now in a bogus state because pState->m_pFile is NULL, so just close it. */ + mz_zip_reader_end_internal(pZip, MZ_FALSE); + return mz_zip_set_error(pZip, MZ_ZIP_FILE_OPEN_FAILED); + } + } + + pZip->m_pWrite = mz_zip_file_write_func; + pZip->m_pNeeds_keepalive = NULL; +#endif /* #ifdef MINIZ_NO_STDIO */ + } + else if (pState->m_pMem) + { + /* Archive lives in a memory block. Assume it's from the heap that we can resize using the realloc callback. */ + if (pZip->m_pIO_opaque != pZip) + return mz_zip_set_error(pZip, MZ_ZIP_INVALID_PARAMETER); + + pState->m_mem_capacity = pState->m_mem_size; + pZip->m_pWrite = mz_zip_heap_write_func; + pZip->m_pNeeds_keepalive = NULL; + } + /* Archive is being read via a user provided read function - make sure the user has specified a write function too. */ + else if (!pZip->m_pWrite) + return mz_zip_set_error(pZip, MZ_ZIP_INVALID_PARAMETER); + + /* Start writing new files at the archive's current central directory location. */ + /* TODO: We could add a flag that lets the user start writing immediately AFTER the existing central dir - this would be safer. */ + pZip->m_archive_size = pZip->m_central_directory_file_ofs; + pZip->m_central_directory_file_ofs = 0; + + /* Clear the sorted central dir offsets, they aren't useful or maintained now. */ + /* Even though we're now in write mode, files can still be extracted and verified, but file locates will be slow. */ + /* TODO: We could easily maintain the sorted central directory offsets. */ + mz_zip_array_clear(pZip, &pZip->m_pState->m_sorted_central_dir_offsets); + + pZip->m_zip_mode = MZ_ZIP_MODE_WRITING; + + return MZ_TRUE; +} + +mz_bool mz_zip_writer_init_from_reader(mz_zip_archive *pZip, const char *pFilename) +{ + return mz_zip_writer_init_from_reader_v2(pZip, pFilename, 0); +} + +/* TODO: pArchive_name is a terrible name here! */ +mz_bool mz_zip_writer_add_mem(mz_zip_archive *pZip, const char *pArchive_name, const void *pBuf, size_t buf_size, mz_uint level_and_flags) +{ + return mz_zip_writer_add_mem_ex(pZip, pArchive_name, pBuf, buf_size, NULL, 0, level_and_flags, 0, 0); +} + +typedef struct +{ + mz_zip_archive *m_pZip; + mz_uint64 m_cur_archive_file_ofs; + mz_uint64 m_comp_size; +} mz_zip_writer_add_state; + +static mz_bool mz_zip_writer_add_put_buf_callback(const void *pBuf, int len, void *pUser) +{ + mz_zip_writer_add_state *pState = (mz_zip_writer_add_state *)pUser; + if ((int)pState->m_pZip->m_pWrite(pState->m_pZip->m_pIO_opaque, pState->m_cur_archive_file_ofs, pBuf, len) != len) + return MZ_FALSE; + + pState->m_cur_archive_file_ofs += len; + pState->m_comp_size += len; + return MZ_TRUE; +} + +#define MZ_ZIP64_MAX_LOCAL_EXTRA_FIELD_SIZE (sizeof(mz_uint16) * 2 + sizeof(mz_uint64) * 2) +#define MZ_ZIP64_MAX_CENTRAL_EXTRA_FIELD_SIZE (sizeof(mz_uint16) * 2 + sizeof(mz_uint64) * 3) +static mz_uint32 mz_zip_writer_create_zip64_extra_data(mz_uint8 *pBuf, mz_uint64 *pUncomp_size, mz_uint64 *pComp_size, mz_uint64 *pLocal_header_ofs) +{ + mz_uint8 *pDst = pBuf; + mz_uint32 field_size = 0; + + MZ_WRITE_LE16(pDst + 0, MZ_ZIP64_EXTENDED_INFORMATION_FIELD_HEADER_ID); + MZ_WRITE_LE16(pDst + 2, 0); + pDst += sizeof(mz_uint16) * 2; + + if (pUncomp_size) + { + MZ_WRITE_LE64(pDst, *pUncomp_size); + pDst += sizeof(mz_uint64); + field_size += sizeof(mz_uint64); + } + + if (pComp_size) + { + MZ_WRITE_LE64(pDst, *pComp_size); + pDst += sizeof(mz_uint64); + field_size += sizeof(mz_uint64); + } + + if (pLocal_header_ofs) + { + MZ_WRITE_LE64(pDst, *pLocal_header_ofs); + pDst += sizeof(mz_uint64); + field_size += sizeof(mz_uint64); + } + + MZ_WRITE_LE16(pBuf + 2, field_size); + + return (mz_uint32)(pDst - pBuf); +} + +static mz_bool mz_zip_writer_create_local_dir_header(mz_zip_archive *pZip, mz_uint8 *pDst, mz_uint16 filename_size, mz_uint16 extra_size, mz_uint64 uncomp_size, mz_uint64 comp_size, mz_uint32 uncomp_crc32, mz_uint16 method, mz_uint16 bit_flags, mz_uint16 dos_time, mz_uint16 dos_date) +{ + (void)pZip; + memset(pDst, 0, MZ_ZIP_LOCAL_DIR_HEADER_SIZE); + MZ_WRITE_LE32(pDst + MZ_ZIP_LDH_SIG_OFS, MZ_ZIP_LOCAL_DIR_HEADER_SIG); + MZ_WRITE_LE16(pDst + MZ_ZIP_LDH_VERSION_NEEDED_OFS, method ? 20 : 0); + MZ_WRITE_LE16(pDst + MZ_ZIP_LDH_BIT_FLAG_OFS, bit_flags); + MZ_WRITE_LE16(pDst + MZ_ZIP_LDH_METHOD_OFS, method); + MZ_WRITE_LE16(pDst + MZ_ZIP_LDH_FILE_TIME_OFS, dos_time); + MZ_WRITE_LE16(pDst + MZ_ZIP_LDH_FILE_DATE_OFS, dos_date); + MZ_WRITE_LE32(pDst + MZ_ZIP_LDH_CRC32_OFS, uncomp_crc32); + MZ_WRITE_LE32(pDst + MZ_ZIP_LDH_COMPRESSED_SIZE_OFS, MZ_MIN(comp_size, MZ_UINT32_MAX)); + MZ_WRITE_LE32(pDst + MZ_ZIP_LDH_DECOMPRESSED_SIZE_OFS, MZ_MIN(uncomp_size, MZ_UINT32_MAX)); + MZ_WRITE_LE16(pDst + MZ_ZIP_LDH_FILENAME_LEN_OFS, filename_size); + MZ_WRITE_LE16(pDst + MZ_ZIP_LDH_EXTRA_LEN_OFS, extra_size); + return MZ_TRUE; +} + +static mz_bool mz_zip_writer_create_central_dir_header(mz_zip_archive *pZip, mz_uint8 *pDst, + mz_uint16 filename_size, mz_uint16 extra_size, mz_uint16 comment_size, + mz_uint64 uncomp_size, mz_uint64 comp_size, mz_uint32 uncomp_crc32, + mz_uint16 method, mz_uint16 bit_flags, mz_uint16 dos_time, mz_uint16 dos_date, + mz_uint64 local_header_ofs, mz_uint32 ext_attributes) +{ + (void)pZip; + memset(pDst, 0, MZ_ZIP_CENTRAL_DIR_HEADER_SIZE); + MZ_WRITE_LE32(pDst + MZ_ZIP_CDH_SIG_OFS, MZ_ZIP_CENTRAL_DIR_HEADER_SIG); + MZ_WRITE_LE16(pDst + MZ_ZIP_CDH_VERSION_NEEDED_OFS, method ? 20 : 0); + MZ_WRITE_LE16(pDst + MZ_ZIP_CDH_BIT_FLAG_OFS, bit_flags); + MZ_WRITE_LE16(pDst + MZ_ZIP_CDH_METHOD_OFS, method); + MZ_WRITE_LE16(pDst + MZ_ZIP_CDH_FILE_TIME_OFS, dos_time); + MZ_WRITE_LE16(pDst + MZ_ZIP_CDH_FILE_DATE_OFS, dos_date); + MZ_WRITE_LE32(pDst + MZ_ZIP_CDH_CRC32_OFS, uncomp_crc32); + MZ_WRITE_LE32(pDst + MZ_ZIP_CDH_COMPRESSED_SIZE_OFS, MZ_MIN(comp_size, MZ_UINT32_MAX)); + MZ_WRITE_LE32(pDst + MZ_ZIP_CDH_DECOMPRESSED_SIZE_OFS, MZ_MIN(uncomp_size, MZ_UINT32_MAX)); + MZ_WRITE_LE16(pDst + MZ_ZIP_CDH_FILENAME_LEN_OFS, filename_size); + MZ_WRITE_LE16(pDst + MZ_ZIP_CDH_EXTRA_LEN_OFS, extra_size); + MZ_WRITE_LE16(pDst + MZ_ZIP_CDH_COMMENT_LEN_OFS, comment_size); + MZ_WRITE_LE32(pDst + MZ_ZIP_CDH_EXTERNAL_ATTR_OFS, ext_attributes); + MZ_WRITE_LE32(pDst + MZ_ZIP_CDH_LOCAL_HEADER_OFS, MZ_MIN(local_header_ofs, MZ_UINT32_MAX)); + return MZ_TRUE; +} + +static mz_bool mz_zip_writer_add_to_central_dir(mz_zip_archive *pZip, const char *pFilename, mz_uint16 filename_size, + const void *pExtra, mz_uint16 extra_size, const void *pComment, mz_uint16 comment_size, + mz_uint64 uncomp_size, mz_uint64 comp_size, mz_uint32 uncomp_crc32, + mz_uint16 method, mz_uint16 bit_flags, mz_uint16 dos_time, mz_uint16 dos_date, + mz_uint64 local_header_ofs, mz_uint32 ext_attributes, + const char *user_extra_data, mz_uint user_extra_data_len) +{ + mz_zip_internal_state *pState = pZip->m_pState; + mz_uint32 central_dir_ofs = (mz_uint32)pState->m_central_dir.m_size; + size_t orig_central_dir_size = pState->m_central_dir.m_size; + mz_uint8 central_dir_header[MZ_ZIP_CENTRAL_DIR_HEADER_SIZE]; + + if (!pZip->m_pState->m_zip64) + { + if (local_header_ofs > 0xFFFFFFFF) + return mz_zip_set_error(pZip, MZ_ZIP_FILE_TOO_LARGE); + } + + /* miniz doesn't support central dirs >= MZ_UINT32_MAX bytes yet */ + if (((mz_uint64)pState->m_central_dir.m_size + MZ_ZIP_CENTRAL_DIR_HEADER_SIZE + filename_size + extra_size + user_extra_data_len + comment_size) >= MZ_UINT32_MAX) + return mz_zip_set_error(pZip, MZ_ZIP_UNSUPPORTED_CDIR_SIZE); + + if (!mz_zip_writer_create_central_dir_header(pZip, central_dir_header, filename_size, extra_size + user_extra_data_len, comment_size, uncomp_size, comp_size, uncomp_crc32, method, bit_flags, dos_time, dos_date, local_header_ofs, ext_attributes)) + return mz_zip_set_error(pZip, MZ_ZIP_INTERNAL_ERROR); + + if ((!mz_zip_array_push_back(pZip, &pState->m_central_dir, central_dir_header, MZ_ZIP_CENTRAL_DIR_HEADER_SIZE)) || + (!mz_zip_array_push_back(pZip, &pState->m_central_dir, pFilename, filename_size)) || + (!mz_zip_array_push_back(pZip, &pState->m_central_dir, pExtra, extra_size)) || + (!mz_zip_array_push_back(pZip, &pState->m_central_dir, user_extra_data, user_extra_data_len)) || + (!mz_zip_array_push_back(pZip, &pState->m_central_dir, pComment, comment_size)) || + (!mz_zip_array_push_back(pZip, &pState->m_central_dir_offsets, ¢ral_dir_ofs, 1))) + { + /* Try to resize the central directory array back into its original state. */ + mz_zip_array_resize(pZip, &pState->m_central_dir, orig_central_dir_size, MZ_FALSE); + return mz_zip_set_error(pZip, MZ_ZIP_ALLOC_FAILED); + } + + return MZ_TRUE; +} + +static mz_bool mz_zip_writer_validate_archive_name(const char *pArchive_name) +{ + /* Basic ZIP archive filename validity checks: Valid filenames cannot start with a forward slash, cannot contain a drive letter, and cannot use DOS-style backward slashes. */ + if (*pArchive_name == '/') + return MZ_FALSE; + + while (*pArchive_name) + { + if ((*pArchive_name == '\\') || (*pArchive_name == ':')) + return MZ_FALSE; + + pArchive_name++; + } + + return MZ_TRUE; +} + +static mz_uint mz_zip_writer_compute_padding_needed_for_file_alignment(mz_zip_archive *pZip) +{ + mz_uint32 n; + if (!pZip->m_file_offset_alignment) + return 0; + n = (mz_uint32)(pZip->m_archive_size & (pZip->m_file_offset_alignment - 1)); + return (mz_uint)((pZip->m_file_offset_alignment - n) & (pZip->m_file_offset_alignment - 1)); +} + +static mz_bool mz_zip_writer_write_zeros(mz_zip_archive *pZip, mz_uint64 cur_file_ofs, mz_uint32 n) +{ + char buf[4096]; + memset(buf, 0, MZ_MIN(sizeof(buf), n)); + while (n) + { + mz_uint32 s = MZ_MIN(sizeof(buf), n); + if (pZip->m_pWrite(pZip->m_pIO_opaque, cur_file_ofs, buf, s) != s) + return mz_zip_set_error(pZip, MZ_ZIP_FILE_WRITE_FAILED); + + cur_file_ofs += s; + n -= s; + } + return MZ_TRUE; +} + +mz_bool mz_zip_writer_add_mem_ex(mz_zip_archive *pZip, const char *pArchive_name, const void *pBuf, size_t buf_size, const void *pComment, mz_uint16 comment_size, mz_uint level_and_flags, + mz_uint64 uncomp_size, mz_uint32 uncomp_crc32) +{ + return mz_zip_writer_add_mem_ex_v2(pZip, pArchive_name, pBuf, buf_size, pComment, comment_size, level_and_flags, uncomp_size, uncomp_crc32, NULL, NULL, 0, NULL, 0); +} + +mz_bool mz_zip_writer_add_mem_ex_v2(mz_zip_archive *pZip, const char *pArchive_name, const void *pBuf, size_t buf_size, const void *pComment, mz_uint16 comment_size, + mz_uint level_and_flags, mz_uint64 uncomp_size, mz_uint32 uncomp_crc32, MZ_TIME_T *last_modified, + const char *user_extra_data, mz_uint user_extra_data_len, const char *user_extra_data_central, mz_uint user_extra_data_central_len) +{ + mz_uint16 method = 0, dos_time = 0, dos_date = 0; + mz_uint level, ext_attributes = 0, num_alignment_padding_bytes; + mz_uint64 local_dir_header_ofs = pZip->m_archive_size, cur_archive_file_ofs = pZip->m_archive_size, comp_size = 0; + size_t archive_name_size; + mz_uint8 local_dir_header[MZ_ZIP_LOCAL_DIR_HEADER_SIZE]; + tdefl_compressor *pComp = NULL; + mz_bool store_data_uncompressed; + mz_zip_internal_state *pState; + mz_uint8 *pExtra_data = NULL; + mz_uint32 extra_size = 0; + mz_uint8 extra_data[MZ_ZIP64_MAX_CENTRAL_EXTRA_FIELD_SIZE]; + mz_uint16 bit_flags = 0; + + if ((int)level_and_flags < 0) + level_and_flags = MZ_DEFAULT_LEVEL; + + if (uncomp_size || (buf_size && !(level_and_flags & MZ_ZIP_FLAG_COMPRESSED_DATA))) + bit_flags |= MZ_ZIP_LDH_BIT_FLAG_HAS_LOCATOR; + + if (!(level_and_flags & MZ_ZIP_FLAG_ASCII_FILENAME)) + bit_flags |= MZ_ZIP_GENERAL_PURPOSE_BIT_FLAG_UTF8; + + level = level_and_flags & 0xF; + store_data_uncompressed = ((!level) || (level_and_flags & MZ_ZIP_FLAG_COMPRESSED_DATA)); + + if ((!pZip) || (!pZip->m_pState) || (pZip->m_zip_mode != MZ_ZIP_MODE_WRITING) || ((buf_size) && (!pBuf)) || (!pArchive_name) || ((comment_size) && (!pComment)) || (level > MZ_UBER_COMPRESSION)) + return mz_zip_set_error(pZip, MZ_ZIP_INVALID_PARAMETER); + + pState = pZip->m_pState; + + if (pState->m_zip64) + { + if (pZip->m_total_files == MZ_UINT32_MAX) + return mz_zip_set_error(pZip, MZ_ZIP_TOO_MANY_FILES); + } + else + { + if (pZip->m_total_files == MZ_UINT16_MAX) + { + pState->m_zip64 = MZ_TRUE; + /*return mz_zip_set_error(pZip, MZ_ZIP_TOO_MANY_FILES); */ + } + if ((buf_size > 0xFFFFFFFF) || (uncomp_size > 0xFFFFFFFF)) + { + pState->m_zip64 = MZ_TRUE; + /*return mz_zip_set_error(pZip, MZ_ZIP_ARCHIVE_TOO_LARGE); */ + } + } + + if ((!(level_and_flags & MZ_ZIP_FLAG_COMPRESSED_DATA)) && (uncomp_size)) + return mz_zip_set_error(pZip, MZ_ZIP_INVALID_PARAMETER); + + if (!mz_zip_writer_validate_archive_name(pArchive_name)) + return mz_zip_set_error(pZip, MZ_ZIP_INVALID_FILENAME); + +#ifndef MINIZ_NO_TIME + if (last_modified != NULL) + { + mz_zip_time_t_to_dos_time(*last_modified, &dos_time, &dos_date); + } + else + { + MZ_TIME_T cur_time; + time(&cur_time); + mz_zip_time_t_to_dos_time(cur_time, &dos_time, &dos_date); + } +#endif /* #ifndef MINIZ_NO_TIME */ + + archive_name_size = strlen(pArchive_name); + if (archive_name_size > MZ_UINT16_MAX) + return mz_zip_set_error(pZip, MZ_ZIP_INVALID_FILENAME); + + num_alignment_padding_bytes = mz_zip_writer_compute_padding_needed_for_file_alignment(pZip); + + /* miniz doesn't support central dirs >= MZ_UINT32_MAX bytes yet */ + if (((mz_uint64)pState->m_central_dir.m_size + MZ_ZIP_CENTRAL_DIR_HEADER_SIZE + archive_name_size + MZ_ZIP64_MAX_CENTRAL_EXTRA_FIELD_SIZE + comment_size) >= MZ_UINT32_MAX) + return mz_zip_set_error(pZip, MZ_ZIP_UNSUPPORTED_CDIR_SIZE); + + if (!pState->m_zip64) + { + /* Bail early if the archive would obviously become too large */ + if ((pZip->m_archive_size + num_alignment_padding_bytes + MZ_ZIP_LOCAL_DIR_HEADER_SIZE + archive_name_size + + MZ_ZIP_CENTRAL_DIR_HEADER_SIZE + archive_name_size + comment_size + user_extra_data_len + + pState->m_central_dir.m_size + MZ_ZIP_END_OF_CENTRAL_DIR_HEADER_SIZE + user_extra_data_central_len + + MZ_ZIP_DATA_DESCRIPTER_SIZE32) > 0xFFFFFFFF) + { + pState->m_zip64 = MZ_TRUE; + /*return mz_zip_set_error(pZip, MZ_ZIP_ARCHIVE_TOO_LARGE); */ + } + } + + if ((archive_name_size) && (pArchive_name[archive_name_size - 1] == '/')) + { + /* Set DOS Subdirectory attribute bit. */ + ext_attributes |= MZ_ZIP_DOS_DIR_ATTRIBUTE_BITFLAG; + + /* Subdirectories cannot contain data. */ + if ((buf_size) || (uncomp_size)) + return mz_zip_set_error(pZip, MZ_ZIP_INVALID_PARAMETER); + } + + /* Try to do any allocations before writing to the archive, so if an allocation fails the file remains unmodified. (A good idea if we're doing an in-place modification.) */ + if ((!mz_zip_array_ensure_room(pZip, &pState->m_central_dir, MZ_ZIP_CENTRAL_DIR_HEADER_SIZE + archive_name_size + comment_size + (pState->m_zip64 ? MZ_ZIP64_MAX_CENTRAL_EXTRA_FIELD_SIZE : 0))) || (!mz_zip_array_ensure_room(pZip, &pState->m_central_dir_offsets, 1))) + return mz_zip_set_error(pZip, MZ_ZIP_ALLOC_FAILED); + + if ((!store_data_uncompressed) && (buf_size)) + { + if (NULL == (pComp = (tdefl_compressor *)pZip->m_pAlloc(pZip->m_pAlloc_opaque, 1, sizeof(tdefl_compressor)))) + return mz_zip_set_error(pZip, MZ_ZIP_ALLOC_FAILED); + } + + if (!mz_zip_writer_write_zeros(pZip, cur_archive_file_ofs, num_alignment_padding_bytes)) + { + pZip->m_pFree(pZip->m_pAlloc_opaque, pComp); + return MZ_FALSE; + } + + local_dir_header_ofs += num_alignment_padding_bytes; + if (pZip->m_file_offset_alignment) + { + MZ_ASSERT((local_dir_header_ofs & (pZip->m_file_offset_alignment - 1)) == 0); + } + cur_archive_file_ofs += num_alignment_padding_bytes; + + MZ_CLEAR_OBJ(local_dir_header); + + if (!store_data_uncompressed || (level_and_flags & MZ_ZIP_FLAG_COMPRESSED_DATA)) + { + method = MZ_DEFLATED; + } + + if (pState->m_zip64) + { + if (uncomp_size >= MZ_UINT32_MAX || local_dir_header_ofs >= MZ_UINT32_MAX) + { + pExtra_data = extra_data; + extra_size = mz_zip_writer_create_zip64_extra_data(extra_data, (uncomp_size >= MZ_UINT32_MAX) ? &uncomp_size : NULL, + (uncomp_size >= MZ_UINT32_MAX) ? &comp_size : NULL, (local_dir_header_ofs >= MZ_UINT32_MAX) ? &local_dir_header_ofs : NULL); + } + + if (!mz_zip_writer_create_local_dir_header(pZip, local_dir_header, (mz_uint16)archive_name_size, extra_size + user_extra_data_len, 0, 0, 0, method, bit_flags, dos_time, dos_date)) + return mz_zip_set_error(pZip, MZ_ZIP_INTERNAL_ERROR); + + if (pZip->m_pWrite(pZip->m_pIO_opaque, local_dir_header_ofs, local_dir_header, sizeof(local_dir_header)) != sizeof(local_dir_header)) + return mz_zip_set_error(pZip, MZ_ZIP_FILE_WRITE_FAILED); + + cur_archive_file_ofs += sizeof(local_dir_header); + + if (pZip->m_pWrite(pZip->m_pIO_opaque, cur_archive_file_ofs, pArchive_name, archive_name_size) != archive_name_size) + { + pZip->m_pFree(pZip->m_pAlloc_opaque, pComp); + return mz_zip_set_error(pZip, MZ_ZIP_FILE_WRITE_FAILED); + } + cur_archive_file_ofs += archive_name_size; + + if (pExtra_data != NULL) + { + if (pZip->m_pWrite(pZip->m_pIO_opaque, cur_archive_file_ofs, extra_data, extra_size) != extra_size) + return mz_zip_set_error(pZip, MZ_ZIP_FILE_WRITE_FAILED); + + cur_archive_file_ofs += extra_size; + } + } + else + { + if ((comp_size > MZ_UINT32_MAX) || (cur_archive_file_ofs > MZ_UINT32_MAX)) + return mz_zip_set_error(pZip, MZ_ZIP_ARCHIVE_TOO_LARGE); + if (!mz_zip_writer_create_local_dir_header(pZip, local_dir_header, (mz_uint16)archive_name_size, user_extra_data_len, 0, 0, 0, method, bit_flags, dos_time, dos_date)) + return mz_zip_set_error(pZip, MZ_ZIP_INTERNAL_ERROR); + + if (pZip->m_pWrite(pZip->m_pIO_opaque, local_dir_header_ofs, local_dir_header, sizeof(local_dir_header)) != sizeof(local_dir_header)) + return mz_zip_set_error(pZip, MZ_ZIP_FILE_WRITE_FAILED); + + cur_archive_file_ofs += sizeof(local_dir_header); + + if (pZip->m_pWrite(pZip->m_pIO_opaque, cur_archive_file_ofs, pArchive_name, archive_name_size) != archive_name_size) + { + pZip->m_pFree(pZip->m_pAlloc_opaque, pComp); + return mz_zip_set_error(pZip, MZ_ZIP_FILE_WRITE_FAILED); + } + cur_archive_file_ofs += archive_name_size; + } + + if (user_extra_data_len > 0) + { + if (pZip->m_pWrite(pZip->m_pIO_opaque, cur_archive_file_ofs, user_extra_data, user_extra_data_len) != user_extra_data_len) + return mz_zip_set_error(pZip, MZ_ZIP_FILE_WRITE_FAILED); + + cur_archive_file_ofs += user_extra_data_len; + } + + if (!(level_and_flags & MZ_ZIP_FLAG_COMPRESSED_DATA)) + { + uncomp_crc32 = (mz_uint32)mz_crc32(MZ_CRC32_INIT, (const mz_uint8 *)pBuf, buf_size); + uncomp_size = buf_size; + if (uncomp_size <= 3) + { + level = 0; + store_data_uncompressed = MZ_TRUE; + } + } + + if (store_data_uncompressed) + { + if (pZip->m_pWrite(pZip->m_pIO_opaque, cur_archive_file_ofs, pBuf, buf_size) != buf_size) + { + pZip->m_pFree(pZip->m_pAlloc_opaque, pComp); + return mz_zip_set_error(pZip, MZ_ZIP_FILE_WRITE_FAILED); + } + + cur_archive_file_ofs += buf_size; + comp_size = buf_size; + } + else if (buf_size) + { + mz_zip_writer_add_state state; + + state.m_pZip = pZip; + state.m_cur_archive_file_ofs = cur_archive_file_ofs; + state.m_comp_size = 0; + + if ((tdefl_init(pComp, mz_zip_writer_add_put_buf_callback, &state, tdefl_create_comp_flags_from_zip_params(level, -15, MZ_DEFAULT_STRATEGY)) != TDEFL_STATUS_OKAY) || + (tdefl_compress_buffer(pComp, pBuf, buf_size, TDEFL_FINISH) != TDEFL_STATUS_DONE)) + { + pZip->m_pFree(pZip->m_pAlloc_opaque, pComp); + return mz_zip_set_error(pZip, MZ_ZIP_COMPRESSION_FAILED); + } + + comp_size = state.m_comp_size; + cur_archive_file_ofs = state.m_cur_archive_file_ofs; + } + + pZip->m_pFree(pZip->m_pAlloc_opaque, pComp); + pComp = NULL; + + if (uncomp_size) + { + mz_uint8 local_dir_footer[MZ_ZIP_DATA_DESCRIPTER_SIZE64]; + mz_uint32 local_dir_footer_size = MZ_ZIP_DATA_DESCRIPTER_SIZE32; + + MZ_ASSERT(bit_flags & MZ_ZIP_LDH_BIT_FLAG_HAS_LOCATOR); + + MZ_WRITE_LE32(local_dir_footer + 0, MZ_ZIP_DATA_DESCRIPTOR_ID); + MZ_WRITE_LE32(local_dir_footer + 4, uncomp_crc32); + if (pExtra_data == NULL) + { + if (comp_size > MZ_UINT32_MAX) + return mz_zip_set_error(pZip, MZ_ZIP_ARCHIVE_TOO_LARGE); + + MZ_WRITE_LE32(local_dir_footer + 8, comp_size); + MZ_WRITE_LE32(local_dir_footer + 12, uncomp_size); + } + else + { + MZ_WRITE_LE64(local_dir_footer + 8, comp_size); + MZ_WRITE_LE64(local_dir_footer + 16, uncomp_size); + local_dir_footer_size = MZ_ZIP_DATA_DESCRIPTER_SIZE64; + } + + if (pZip->m_pWrite(pZip->m_pIO_opaque, cur_archive_file_ofs, local_dir_footer, local_dir_footer_size) != local_dir_footer_size) + return MZ_FALSE; + + cur_archive_file_ofs += local_dir_footer_size; + } + + if (pExtra_data != NULL) + { + extra_size = mz_zip_writer_create_zip64_extra_data(extra_data, (uncomp_size >= MZ_UINT32_MAX) ? &uncomp_size : NULL, + (uncomp_size >= MZ_UINT32_MAX) ? &comp_size : NULL, (local_dir_header_ofs >= MZ_UINT32_MAX) ? &local_dir_header_ofs : NULL); + } + + if (!mz_zip_writer_add_to_central_dir(pZip, pArchive_name, (mz_uint16)archive_name_size, pExtra_data, extra_size, pComment, + comment_size, uncomp_size, comp_size, uncomp_crc32, method, bit_flags, dos_time, dos_date, local_dir_header_ofs, ext_attributes, + user_extra_data_central, user_extra_data_central_len)) + return MZ_FALSE; + + pZip->m_total_files++; + pZip->m_archive_size = cur_archive_file_ofs; + + return MZ_TRUE; +} + +#ifndef MINIZ_NO_STDIO +mz_bool mz_zip_writer_add_cfile(mz_zip_archive *pZip, const char *pArchive_name, MZ_FILE *pSrc_file, mz_uint64 size_to_add, const MZ_TIME_T *pFile_time, const void *pComment, mz_uint16 comment_size, mz_uint level_and_flags, + const char *user_extra_data, mz_uint user_extra_data_len, const char *user_extra_data_central, mz_uint user_extra_data_central_len) +{ + mz_uint16 gen_flags = MZ_ZIP_LDH_BIT_FLAG_HAS_LOCATOR; + mz_uint uncomp_crc32 = MZ_CRC32_INIT, level, num_alignment_padding_bytes; + mz_uint16 method = 0, dos_time = 0, dos_date = 0, ext_attributes = 0; + mz_uint64 local_dir_header_ofs, cur_archive_file_ofs = pZip->m_archive_size, uncomp_size = size_to_add, comp_size = 0; + size_t archive_name_size; + mz_uint8 local_dir_header[MZ_ZIP_LOCAL_DIR_HEADER_SIZE]; + mz_uint8 *pExtra_data = NULL; + mz_uint32 extra_size = 0; + mz_uint8 extra_data[MZ_ZIP64_MAX_CENTRAL_EXTRA_FIELD_SIZE]; + mz_zip_internal_state *pState; + + if (!(level_and_flags & MZ_ZIP_FLAG_ASCII_FILENAME)) + gen_flags |= MZ_ZIP_GENERAL_PURPOSE_BIT_FLAG_UTF8; + + if ((int)level_and_flags < 0) + level_and_flags = MZ_DEFAULT_LEVEL; + level = level_and_flags & 0xF; + + /* Sanity checks */ + if ((!pZip) || (!pZip->m_pState) || (pZip->m_zip_mode != MZ_ZIP_MODE_WRITING) || (!pArchive_name) || ((comment_size) && (!pComment)) || (level > MZ_UBER_COMPRESSION)) + return mz_zip_set_error(pZip, MZ_ZIP_INVALID_PARAMETER); + + pState = pZip->m_pState; + + if ((!pState->m_zip64) && (uncomp_size > MZ_UINT32_MAX)) + { + /* Source file is too large for non-zip64 */ + /*return mz_zip_set_error(pZip, MZ_ZIP_ARCHIVE_TOO_LARGE); */ + pState->m_zip64 = MZ_TRUE; + } + + /* We could support this, but why? */ + if (level_and_flags & MZ_ZIP_FLAG_COMPRESSED_DATA) + return mz_zip_set_error(pZip, MZ_ZIP_INVALID_PARAMETER); + + if (!mz_zip_writer_validate_archive_name(pArchive_name)) + return mz_zip_set_error(pZip, MZ_ZIP_INVALID_FILENAME); + + if (pState->m_zip64) + { + if (pZip->m_total_files == MZ_UINT32_MAX) + return mz_zip_set_error(pZip, MZ_ZIP_TOO_MANY_FILES); + } + else + { + if (pZip->m_total_files == MZ_UINT16_MAX) + { + pState->m_zip64 = MZ_TRUE; + /*return mz_zip_set_error(pZip, MZ_ZIP_TOO_MANY_FILES); */ + } + } + + archive_name_size = strlen(pArchive_name); + if (archive_name_size > MZ_UINT16_MAX) + return mz_zip_set_error(pZip, MZ_ZIP_INVALID_FILENAME); + + num_alignment_padding_bytes = mz_zip_writer_compute_padding_needed_for_file_alignment(pZip); + + /* miniz doesn't support central dirs >= MZ_UINT32_MAX bytes yet */ + if (((mz_uint64)pState->m_central_dir.m_size + MZ_ZIP_CENTRAL_DIR_HEADER_SIZE + archive_name_size + MZ_ZIP64_MAX_CENTRAL_EXTRA_FIELD_SIZE + comment_size) >= MZ_UINT32_MAX) + return mz_zip_set_error(pZip, MZ_ZIP_UNSUPPORTED_CDIR_SIZE); + + if (!pState->m_zip64) + { + /* Bail early if the archive would obviously become too large */ + if ((pZip->m_archive_size + num_alignment_padding_bytes + MZ_ZIP_LOCAL_DIR_HEADER_SIZE + archive_name_size + MZ_ZIP_CENTRAL_DIR_HEADER_SIZE + + archive_name_size + comment_size + user_extra_data_len + pState->m_central_dir.m_size + MZ_ZIP_END_OF_CENTRAL_DIR_HEADER_SIZE + 1024 + + MZ_ZIP_DATA_DESCRIPTER_SIZE32 + user_extra_data_central_len) > 0xFFFFFFFF) + { + pState->m_zip64 = MZ_TRUE; + /*return mz_zip_set_error(pZip, MZ_ZIP_ARCHIVE_TOO_LARGE); */ + } + } + +#ifndef MINIZ_NO_TIME + if (pFile_time) + { + mz_zip_time_t_to_dos_time(*pFile_time, &dos_time, &dos_date); + } +#endif + + if (uncomp_size <= 3) + level = 0; + + if (!mz_zip_writer_write_zeros(pZip, cur_archive_file_ofs, num_alignment_padding_bytes)) + { + return mz_zip_set_error(pZip, MZ_ZIP_FILE_WRITE_FAILED); + } + + cur_archive_file_ofs += num_alignment_padding_bytes; + local_dir_header_ofs = cur_archive_file_ofs; + + if (pZip->m_file_offset_alignment) + { + MZ_ASSERT((cur_archive_file_ofs & (pZip->m_file_offset_alignment - 1)) == 0); + } + + if (uncomp_size && level) + { + method = MZ_DEFLATED; + } + + MZ_CLEAR_OBJ(local_dir_header); + if (pState->m_zip64) + { + if (uncomp_size >= MZ_UINT32_MAX || local_dir_header_ofs >= MZ_UINT32_MAX) + { + pExtra_data = extra_data; + extra_size = mz_zip_writer_create_zip64_extra_data(extra_data, (uncomp_size >= MZ_UINT32_MAX) ? &uncomp_size : NULL, + (uncomp_size >= MZ_UINT32_MAX) ? &comp_size : NULL, (local_dir_header_ofs >= MZ_UINT32_MAX) ? &local_dir_header_ofs : NULL); + } + + if (!mz_zip_writer_create_local_dir_header(pZip, local_dir_header, (mz_uint16)archive_name_size, extra_size + user_extra_data_len, 0, 0, 0, method, gen_flags, dos_time, dos_date)) + return mz_zip_set_error(pZip, MZ_ZIP_INTERNAL_ERROR); + + if (pZip->m_pWrite(pZip->m_pIO_opaque, cur_archive_file_ofs, local_dir_header, sizeof(local_dir_header)) != sizeof(local_dir_header)) + return mz_zip_set_error(pZip, MZ_ZIP_FILE_WRITE_FAILED); + + cur_archive_file_ofs += sizeof(local_dir_header); + + if (pZip->m_pWrite(pZip->m_pIO_opaque, cur_archive_file_ofs, pArchive_name, archive_name_size) != archive_name_size) + { + return mz_zip_set_error(pZip, MZ_ZIP_FILE_WRITE_FAILED); + } + + cur_archive_file_ofs += archive_name_size; + + if (pZip->m_pWrite(pZip->m_pIO_opaque, cur_archive_file_ofs, extra_data, extra_size) != extra_size) + return mz_zip_set_error(pZip, MZ_ZIP_FILE_WRITE_FAILED); + + cur_archive_file_ofs += extra_size; + } + else + { + if ((comp_size > MZ_UINT32_MAX) || (cur_archive_file_ofs > MZ_UINT32_MAX)) + return mz_zip_set_error(pZip, MZ_ZIP_ARCHIVE_TOO_LARGE); + if (!mz_zip_writer_create_local_dir_header(pZip, local_dir_header, (mz_uint16)archive_name_size, user_extra_data_len, 0, 0, 0, method, gen_flags, dos_time, dos_date)) + return mz_zip_set_error(pZip, MZ_ZIP_INTERNAL_ERROR); + + if (pZip->m_pWrite(pZip->m_pIO_opaque, cur_archive_file_ofs, local_dir_header, sizeof(local_dir_header)) != sizeof(local_dir_header)) + return mz_zip_set_error(pZip, MZ_ZIP_FILE_WRITE_FAILED); + + cur_archive_file_ofs += sizeof(local_dir_header); + + if (pZip->m_pWrite(pZip->m_pIO_opaque, cur_archive_file_ofs, pArchive_name, archive_name_size) != archive_name_size) + { + return mz_zip_set_error(pZip, MZ_ZIP_FILE_WRITE_FAILED); + } + + cur_archive_file_ofs += archive_name_size; + } + + if (user_extra_data_len > 0) + { + if (pZip->m_pWrite(pZip->m_pIO_opaque, cur_archive_file_ofs, user_extra_data, user_extra_data_len) != user_extra_data_len) + return mz_zip_set_error(pZip, MZ_ZIP_FILE_WRITE_FAILED); + + cur_archive_file_ofs += user_extra_data_len; + } + + if (uncomp_size) + { + mz_uint64 uncomp_remaining = uncomp_size; + void *pRead_buf = pZip->m_pAlloc(pZip->m_pAlloc_opaque, 1, MZ_ZIP_MAX_IO_BUF_SIZE); + if (!pRead_buf) + { + return mz_zip_set_error(pZip, MZ_ZIP_ALLOC_FAILED); + } + + if (!level) + { + while (uncomp_remaining) + { + mz_uint n = (mz_uint)MZ_MIN((mz_uint64)MZ_ZIP_MAX_IO_BUF_SIZE, uncomp_remaining); + if ((MZ_FREAD(pRead_buf, 1, n, pSrc_file) != n) || (pZip->m_pWrite(pZip->m_pIO_opaque, cur_archive_file_ofs, pRead_buf, n) != n)) + { + pZip->m_pFree(pZip->m_pAlloc_opaque, pRead_buf); + return mz_zip_set_error(pZip, MZ_ZIP_FILE_READ_FAILED); + } + uncomp_crc32 = (mz_uint32)mz_crc32(uncomp_crc32, (const mz_uint8 *)pRead_buf, n); + uncomp_remaining -= n; + cur_archive_file_ofs += n; + } + comp_size = uncomp_size; + } + else + { + mz_bool result = MZ_FALSE; + mz_zip_writer_add_state state; + tdefl_compressor *pComp = (tdefl_compressor *)pZip->m_pAlloc(pZip->m_pAlloc_opaque, 1, sizeof(tdefl_compressor)); + if (!pComp) + { + pZip->m_pFree(pZip->m_pAlloc_opaque, pRead_buf); + return mz_zip_set_error(pZip, MZ_ZIP_ALLOC_FAILED); + } + + state.m_pZip = pZip; + state.m_cur_archive_file_ofs = cur_archive_file_ofs; + state.m_comp_size = 0; + + if (tdefl_init(pComp, mz_zip_writer_add_put_buf_callback, &state, tdefl_create_comp_flags_from_zip_params(level, -15, MZ_DEFAULT_STRATEGY)) != TDEFL_STATUS_OKAY) + { + pZip->m_pFree(pZip->m_pAlloc_opaque, pComp); + pZip->m_pFree(pZip->m_pAlloc_opaque, pRead_buf); + return mz_zip_set_error(pZip, MZ_ZIP_INTERNAL_ERROR); + } + + for (;;) + { + size_t in_buf_size = (mz_uint32)MZ_MIN(uncomp_remaining, (mz_uint64)MZ_ZIP_MAX_IO_BUF_SIZE); + tdefl_status status; + tdefl_flush flush = TDEFL_NO_FLUSH; + + if (MZ_FREAD(pRead_buf, 1, in_buf_size, pSrc_file) != in_buf_size) + { + mz_zip_set_error(pZip, MZ_ZIP_FILE_READ_FAILED); + break; + } + + uncomp_crc32 = (mz_uint32)mz_crc32(uncomp_crc32, (const mz_uint8 *)pRead_buf, in_buf_size); + uncomp_remaining -= in_buf_size; + + if (pZip->m_pNeeds_keepalive != NULL && pZip->m_pNeeds_keepalive(pZip->m_pIO_opaque)) + flush = TDEFL_FULL_FLUSH; + + status = tdefl_compress_buffer(pComp, pRead_buf, in_buf_size, uncomp_remaining ? flush : TDEFL_FINISH); + if (status == TDEFL_STATUS_DONE) + { + result = MZ_TRUE; + break; + } + else if (status != TDEFL_STATUS_OKAY) + { + mz_zip_set_error(pZip, MZ_ZIP_COMPRESSION_FAILED); + break; + } + } + + pZip->m_pFree(pZip->m_pAlloc_opaque, pComp); + + if (!result) + { + pZip->m_pFree(pZip->m_pAlloc_opaque, pRead_buf); + return MZ_FALSE; + } + + comp_size = state.m_comp_size; + cur_archive_file_ofs = state.m_cur_archive_file_ofs; + } + + pZip->m_pFree(pZip->m_pAlloc_opaque, pRead_buf); + } + + { + mz_uint8 local_dir_footer[MZ_ZIP_DATA_DESCRIPTER_SIZE64]; + mz_uint32 local_dir_footer_size = MZ_ZIP_DATA_DESCRIPTER_SIZE32; + + MZ_WRITE_LE32(local_dir_footer + 0, MZ_ZIP_DATA_DESCRIPTOR_ID); + MZ_WRITE_LE32(local_dir_footer + 4, uncomp_crc32); + if (pExtra_data == NULL) + { + if (comp_size > MZ_UINT32_MAX) + return mz_zip_set_error(pZip, MZ_ZIP_ARCHIVE_TOO_LARGE); + + MZ_WRITE_LE32(local_dir_footer + 8, comp_size); + MZ_WRITE_LE32(local_dir_footer + 12, uncomp_size); + } + else + { + MZ_WRITE_LE64(local_dir_footer + 8, comp_size); + MZ_WRITE_LE64(local_dir_footer + 16, uncomp_size); + local_dir_footer_size = MZ_ZIP_DATA_DESCRIPTER_SIZE64; + } + + if (pZip->m_pWrite(pZip->m_pIO_opaque, cur_archive_file_ofs, local_dir_footer, local_dir_footer_size) != local_dir_footer_size) + return MZ_FALSE; + + cur_archive_file_ofs += local_dir_footer_size; + } + + if (pExtra_data != NULL) + { + extra_size = mz_zip_writer_create_zip64_extra_data(extra_data, (uncomp_size >= MZ_UINT32_MAX) ? &uncomp_size : NULL, + (uncomp_size >= MZ_UINT32_MAX) ? &comp_size : NULL, (local_dir_header_ofs >= MZ_UINT32_MAX) ? &local_dir_header_ofs : NULL); + } + + if (!mz_zip_writer_add_to_central_dir(pZip, pArchive_name, (mz_uint16)archive_name_size, pExtra_data, extra_size, pComment, comment_size, + uncomp_size, comp_size, uncomp_crc32, method, gen_flags, dos_time, dos_date, local_dir_header_ofs, ext_attributes, + user_extra_data_central, user_extra_data_central_len)) + return MZ_FALSE; + + pZip->m_total_files++; + pZip->m_archive_size = cur_archive_file_ofs; + + return MZ_TRUE; +} + +mz_bool mz_zip_writer_add_file(mz_zip_archive *pZip, const char *pArchive_name, const char *pSrc_filename, const void *pComment, mz_uint16 comment_size, mz_uint level_and_flags) +{ + MZ_FILE *pSrc_file = NULL; + mz_uint64 uncomp_size = 0; + MZ_TIME_T file_modified_time; + MZ_TIME_T *pFile_time = NULL; + mz_bool status; + + memset(&file_modified_time, 0, sizeof(file_modified_time)); + +#if !defined(MINIZ_NO_TIME) && !defined(MINIZ_NO_STDIO) + pFile_time = &file_modified_time; + if (!mz_zip_get_file_modified_time(pSrc_filename, &file_modified_time)) + return mz_zip_set_error(pZip, MZ_ZIP_FILE_STAT_FAILED); +#endif + + pSrc_file = MZ_FOPEN(pSrc_filename, "rb"); + if (!pSrc_file) + return mz_zip_set_error(pZip, MZ_ZIP_FILE_OPEN_FAILED); + + MZ_FSEEK64(pSrc_file, 0, SEEK_END); + uncomp_size = MZ_FTELL64(pSrc_file); + MZ_FSEEK64(pSrc_file, 0, SEEK_SET); + + status = mz_zip_writer_add_cfile(pZip, pArchive_name, pSrc_file, uncomp_size, pFile_time, pComment, comment_size, level_and_flags, NULL, 0, NULL, 0); + + MZ_FCLOSE(pSrc_file); + + return status; +} +#endif /* #ifndef MINIZ_NO_STDIO */ + +static mz_bool mz_zip_writer_update_zip64_extension_block(mz_zip_array *pNew_ext, mz_zip_archive *pZip, const mz_uint8 *pExt, uint32_t ext_len, mz_uint64 *pComp_size, mz_uint64 *pUncomp_size, mz_uint64 *pLocal_header_ofs, mz_uint32 *pDisk_start) +{ + /* + 64 should be enough for any new zip64 data */ + if (!mz_zip_array_reserve(pZip, pNew_ext, ext_len + 64, MZ_FALSE)) + return mz_zip_set_error(pZip, MZ_ZIP_ALLOC_FAILED); + + mz_zip_array_resize(pZip, pNew_ext, 0, MZ_FALSE); + + if ((pUncomp_size) || (pComp_size) || (pLocal_header_ofs) || (pDisk_start)) + { + mz_uint8 new_ext_block[64]; + mz_uint8 *pDst = new_ext_block; + mz_write_le16(pDst, MZ_ZIP64_EXTENDED_INFORMATION_FIELD_HEADER_ID); + mz_write_le16(pDst + sizeof(mz_uint16), 0); + pDst += sizeof(mz_uint16) * 2; + + if (pUncomp_size) + { + mz_write_le64(pDst, *pUncomp_size); + pDst += sizeof(mz_uint64); + } + + if (pComp_size) + { + mz_write_le64(pDst, *pComp_size); + pDst += sizeof(mz_uint64); + } + + if (pLocal_header_ofs) + { + mz_write_le64(pDst, *pLocal_header_ofs); + pDst += sizeof(mz_uint64); + } + + if (pDisk_start) + { + mz_write_le32(pDst, *pDisk_start); + pDst += sizeof(mz_uint32); + } + + mz_write_le16(new_ext_block + sizeof(mz_uint16), (mz_uint16)((pDst - new_ext_block) - sizeof(mz_uint16) * 2)); + + if (!mz_zip_array_push_back(pZip, pNew_ext, new_ext_block, pDst - new_ext_block)) + return mz_zip_set_error(pZip, MZ_ZIP_ALLOC_FAILED); + } + + if ((pExt) && (ext_len)) + { + mz_uint32 extra_size_remaining = ext_len; + const mz_uint8 *pExtra_data = pExt; + + do + { + mz_uint32 field_id, field_data_size, field_total_size; + + if (extra_size_remaining < (sizeof(mz_uint16) * 2)) + return mz_zip_set_error(pZip, MZ_ZIP_INVALID_HEADER_OR_CORRUPTED); + + field_id = MZ_READ_LE16(pExtra_data); + field_data_size = MZ_READ_LE16(pExtra_data + sizeof(mz_uint16)); + field_total_size = field_data_size + sizeof(mz_uint16) * 2; + + if (field_total_size > extra_size_remaining) + return mz_zip_set_error(pZip, MZ_ZIP_INVALID_HEADER_OR_CORRUPTED); + + if (field_id != MZ_ZIP64_EXTENDED_INFORMATION_FIELD_HEADER_ID) + { + if (!mz_zip_array_push_back(pZip, pNew_ext, pExtra_data, field_total_size)) + return mz_zip_set_error(pZip, MZ_ZIP_ALLOC_FAILED); + } + + pExtra_data += field_total_size; + extra_size_remaining -= field_total_size; + } while (extra_size_remaining); + } + + return MZ_TRUE; +} + +/* TODO: This func is now pretty freakin complex due to zip64, split it up? */ +mz_bool mz_zip_writer_add_from_zip_reader(mz_zip_archive *pZip, mz_zip_archive *pSource_zip, mz_uint src_file_index) +{ + mz_uint n, bit_flags, num_alignment_padding_bytes, src_central_dir_following_data_size; + mz_uint64 src_archive_bytes_remaining, local_dir_header_ofs; + mz_uint64 cur_src_file_ofs, cur_dst_file_ofs; + mz_uint32 local_header_u32[(MZ_ZIP_LOCAL_DIR_HEADER_SIZE + sizeof(mz_uint32) - 1) / sizeof(mz_uint32)]; + mz_uint8 *pLocal_header = (mz_uint8 *)local_header_u32; + mz_uint8 new_central_header[MZ_ZIP_CENTRAL_DIR_HEADER_SIZE]; + size_t orig_central_dir_size; + mz_zip_internal_state *pState; + void *pBuf; + const mz_uint8 *pSrc_central_header; + mz_zip_archive_file_stat src_file_stat; + mz_uint32 src_filename_len, src_comment_len, src_ext_len; + mz_uint32 local_header_filename_size, local_header_extra_len; + mz_uint64 local_header_comp_size, local_header_uncomp_size; + mz_bool found_zip64_ext_data_in_ldir = MZ_FALSE; + + /* Sanity checks */ + if ((!pZip) || (!pZip->m_pState) || (pZip->m_zip_mode != MZ_ZIP_MODE_WRITING) || (!pSource_zip->m_pRead)) + return mz_zip_set_error(pZip, MZ_ZIP_INVALID_PARAMETER); + + pState = pZip->m_pState; + + /* Don't support copying files from zip64 archives to non-zip64, even though in some cases this is possible */ + if ((pSource_zip->m_pState->m_zip64) && (!pZip->m_pState->m_zip64)) + return mz_zip_set_error(pZip, MZ_ZIP_INVALID_PARAMETER); + + /* Get pointer to the source central dir header and crack it */ + if (NULL == (pSrc_central_header = mz_zip_get_cdh(pSource_zip, src_file_index))) + return mz_zip_set_error(pZip, MZ_ZIP_INVALID_PARAMETER); + + if (MZ_READ_LE32(pSrc_central_header + MZ_ZIP_CDH_SIG_OFS) != MZ_ZIP_CENTRAL_DIR_HEADER_SIG) + return mz_zip_set_error(pZip, MZ_ZIP_INVALID_HEADER_OR_CORRUPTED); + + src_filename_len = MZ_READ_LE16(pSrc_central_header + MZ_ZIP_CDH_FILENAME_LEN_OFS); + src_comment_len = MZ_READ_LE16(pSrc_central_header + MZ_ZIP_CDH_COMMENT_LEN_OFS); + src_ext_len = MZ_READ_LE16(pSrc_central_header + MZ_ZIP_CDH_EXTRA_LEN_OFS); + src_central_dir_following_data_size = src_filename_len + src_ext_len + src_comment_len; + + /* TODO: We don't support central dir's >= MZ_UINT32_MAX bytes right now (+32 fudge factor in case we need to add more extra data) */ + if ((pState->m_central_dir.m_size + MZ_ZIP_CENTRAL_DIR_HEADER_SIZE + src_central_dir_following_data_size + 32) >= MZ_UINT32_MAX) + return mz_zip_set_error(pZip, MZ_ZIP_UNSUPPORTED_CDIR_SIZE); + + num_alignment_padding_bytes = mz_zip_writer_compute_padding_needed_for_file_alignment(pZip); + + if (!pState->m_zip64) + { + if (pZip->m_total_files == MZ_UINT16_MAX) + return mz_zip_set_error(pZip, MZ_ZIP_TOO_MANY_FILES); + } + else + { + /* TODO: Our zip64 support still has some 32-bit limits that may not be worth fixing. */ + if (pZip->m_total_files == MZ_UINT32_MAX) + return mz_zip_set_error(pZip, MZ_ZIP_TOO_MANY_FILES); + } + + if (!mz_zip_file_stat_internal(pSource_zip, src_file_index, pSrc_central_header, &src_file_stat, NULL)) + return MZ_FALSE; + + cur_src_file_ofs = src_file_stat.m_local_header_ofs; + cur_dst_file_ofs = pZip->m_archive_size; + + /* Read the source archive's local dir header */ + if (pSource_zip->m_pRead(pSource_zip->m_pIO_opaque, cur_src_file_ofs, pLocal_header, MZ_ZIP_LOCAL_DIR_HEADER_SIZE) != MZ_ZIP_LOCAL_DIR_HEADER_SIZE) + return mz_zip_set_error(pZip, MZ_ZIP_FILE_READ_FAILED); + + if (MZ_READ_LE32(pLocal_header) != MZ_ZIP_LOCAL_DIR_HEADER_SIG) + return mz_zip_set_error(pZip, MZ_ZIP_INVALID_HEADER_OR_CORRUPTED); + + cur_src_file_ofs += MZ_ZIP_LOCAL_DIR_HEADER_SIZE; + + /* Compute the total size we need to copy (filename+extra data+compressed data) */ + local_header_filename_size = MZ_READ_LE16(pLocal_header + MZ_ZIP_LDH_FILENAME_LEN_OFS); + local_header_extra_len = MZ_READ_LE16(pLocal_header + MZ_ZIP_LDH_EXTRA_LEN_OFS); + local_header_comp_size = MZ_READ_LE32(pLocal_header + MZ_ZIP_LDH_COMPRESSED_SIZE_OFS); + local_header_uncomp_size = MZ_READ_LE32(pLocal_header + MZ_ZIP_LDH_DECOMPRESSED_SIZE_OFS); + src_archive_bytes_remaining = local_header_filename_size + local_header_extra_len + src_file_stat.m_comp_size; + + /* Try to find a zip64 extended information field */ + if ((local_header_extra_len) && ((local_header_comp_size == MZ_UINT32_MAX) || (local_header_uncomp_size == MZ_UINT32_MAX))) + { + mz_zip_array file_data_array; + const mz_uint8 *pExtra_data; + mz_uint32 extra_size_remaining = local_header_extra_len; + + mz_zip_array_init(&file_data_array, 1); + if (!mz_zip_array_resize(pZip, &file_data_array, local_header_extra_len, MZ_FALSE)) + { + return mz_zip_set_error(pZip, MZ_ZIP_ALLOC_FAILED); + } + + if (pSource_zip->m_pRead(pSource_zip->m_pIO_opaque, src_file_stat.m_local_header_ofs + MZ_ZIP_LOCAL_DIR_HEADER_SIZE + local_header_filename_size, file_data_array.m_p, local_header_extra_len) != local_header_extra_len) + { + mz_zip_array_clear(pZip, &file_data_array); + return mz_zip_set_error(pZip, MZ_ZIP_FILE_READ_FAILED); + } + + pExtra_data = (const mz_uint8 *)file_data_array.m_p; + + do + { + mz_uint32 field_id, field_data_size, field_total_size; + + if (extra_size_remaining < (sizeof(mz_uint16) * 2)) + { + mz_zip_array_clear(pZip, &file_data_array); + return mz_zip_set_error(pZip, MZ_ZIP_INVALID_HEADER_OR_CORRUPTED); + } + + field_id = MZ_READ_LE16(pExtra_data); + field_data_size = MZ_READ_LE16(pExtra_data + sizeof(mz_uint16)); + field_total_size = field_data_size + sizeof(mz_uint16) * 2; + + if (field_total_size > extra_size_remaining) + { + mz_zip_array_clear(pZip, &file_data_array); + return mz_zip_set_error(pZip, MZ_ZIP_INVALID_HEADER_OR_CORRUPTED); + } + + if (field_id == MZ_ZIP64_EXTENDED_INFORMATION_FIELD_HEADER_ID) + { + const mz_uint8 *pSrc_field_data = pExtra_data + sizeof(mz_uint32); + + if (field_data_size < sizeof(mz_uint64) * 2) + { + mz_zip_array_clear(pZip, &file_data_array); + return mz_zip_set_error(pZip, MZ_ZIP_INVALID_HEADER_OR_CORRUPTED); + } + + local_header_uncomp_size = MZ_READ_LE64(pSrc_field_data); + local_header_comp_size = MZ_READ_LE64(pSrc_field_data + sizeof(mz_uint64)); /* may be 0 if there's a descriptor */ + + found_zip64_ext_data_in_ldir = MZ_TRUE; + break; + } + + pExtra_data += field_total_size; + extra_size_remaining -= field_total_size; + } while (extra_size_remaining); + + mz_zip_array_clear(pZip, &file_data_array); + } + + if (!pState->m_zip64) + { + /* Try to detect if the new archive will most likely wind up too big and bail early (+(sizeof(mz_uint32) * 4) is for the optional descriptor which could be present, +64 is a fudge factor). */ + /* We also check when the archive is finalized so this doesn't need to be perfect. */ + mz_uint64 approx_new_archive_size = cur_dst_file_ofs + num_alignment_padding_bytes + MZ_ZIP_LOCAL_DIR_HEADER_SIZE + src_archive_bytes_remaining + (sizeof(mz_uint32) * 4) + + pState->m_central_dir.m_size + MZ_ZIP_CENTRAL_DIR_HEADER_SIZE + src_central_dir_following_data_size + MZ_ZIP_END_OF_CENTRAL_DIR_HEADER_SIZE + 64; + + if (approx_new_archive_size >= MZ_UINT32_MAX) + return mz_zip_set_error(pZip, MZ_ZIP_ARCHIVE_TOO_LARGE); + } + + /* Write dest archive padding */ + if (!mz_zip_writer_write_zeros(pZip, cur_dst_file_ofs, num_alignment_padding_bytes)) + return MZ_FALSE; + + cur_dst_file_ofs += num_alignment_padding_bytes; + + local_dir_header_ofs = cur_dst_file_ofs; + if (pZip->m_file_offset_alignment) + { + MZ_ASSERT((local_dir_header_ofs & (pZip->m_file_offset_alignment - 1)) == 0); + } + + /* The original zip's local header+ext block doesn't change, even with zip64, so we can just copy it over to the dest zip */ + if (pZip->m_pWrite(pZip->m_pIO_opaque, cur_dst_file_ofs, pLocal_header, MZ_ZIP_LOCAL_DIR_HEADER_SIZE) != MZ_ZIP_LOCAL_DIR_HEADER_SIZE) + return mz_zip_set_error(pZip, MZ_ZIP_FILE_WRITE_FAILED); + + cur_dst_file_ofs += MZ_ZIP_LOCAL_DIR_HEADER_SIZE; + + /* Copy over the source archive bytes to the dest archive, also ensure we have enough buf space to handle optional data descriptor */ + if (NULL == (pBuf = pZip->m_pAlloc(pZip->m_pAlloc_opaque, 1, (size_t)MZ_MAX(32U, MZ_MIN((mz_uint64)MZ_ZIP_MAX_IO_BUF_SIZE, src_archive_bytes_remaining))))) + return mz_zip_set_error(pZip, MZ_ZIP_ALLOC_FAILED); + + while (src_archive_bytes_remaining) + { + n = (mz_uint)MZ_MIN((mz_uint64)MZ_ZIP_MAX_IO_BUF_SIZE, src_archive_bytes_remaining); + if (pSource_zip->m_pRead(pSource_zip->m_pIO_opaque, cur_src_file_ofs, pBuf, n) != n) + { + pZip->m_pFree(pZip->m_pAlloc_opaque, pBuf); + return mz_zip_set_error(pZip, MZ_ZIP_FILE_READ_FAILED); + } + cur_src_file_ofs += n; + + if (pZip->m_pWrite(pZip->m_pIO_opaque, cur_dst_file_ofs, pBuf, n) != n) + { + pZip->m_pFree(pZip->m_pAlloc_opaque, pBuf); + return mz_zip_set_error(pZip, MZ_ZIP_FILE_WRITE_FAILED); + } + cur_dst_file_ofs += n; + + src_archive_bytes_remaining -= n; + } + + /* Now deal with the optional data descriptor */ + bit_flags = MZ_READ_LE16(pLocal_header + MZ_ZIP_LDH_BIT_FLAG_OFS); + if (bit_flags & 8) + { + /* Copy data descriptor */ + if ((pSource_zip->m_pState->m_zip64) || (found_zip64_ext_data_in_ldir)) + { + /* src is zip64, dest must be zip64 */ + + /* name uint32_t's */ + /* id 1 (optional in zip64?) */ + /* crc 1 */ + /* comp_size 2 */ + /* uncomp_size 2 */ + if (pSource_zip->m_pRead(pSource_zip->m_pIO_opaque, cur_src_file_ofs, pBuf, (sizeof(mz_uint32) * 6)) != (sizeof(mz_uint32) * 6)) + { + pZip->m_pFree(pZip->m_pAlloc_opaque, pBuf); + return mz_zip_set_error(pZip, MZ_ZIP_FILE_READ_FAILED); + } + + n = sizeof(mz_uint32) * ((MZ_READ_LE32(pBuf) == MZ_ZIP_DATA_DESCRIPTOR_ID) ? 6 : 5); + } + else + { + /* src is NOT zip64 */ + mz_bool has_id; + + if (pSource_zip->m_pRead(pSource_zip->m_pIO_opaque, cur_src_file_ofs, pBuf, sizeof(mz_uint32) * 4) != sizeof(mz_uint32) * 4) + { + pZip->m_pFree(pZip->m_pAlloc_opaque, pBuf); + return mz_zip_set_error(pZip, MZ_ZIP_FILE_READ_FAILED); + } + + has_id = (MZ_READ_LE32(pBuf) == MZ_ZIP_DATA_DESCRIPTOR_ID); + + if (pZip->m_pState->m_zip64) + { + /* dest is zip64, so upgrade the data descriptor */ + const mz_uint32 *pSrc_descriptor = (const mz_uint32 *)((const mz_uint8 *)pBuf + (has_id ? sizeof(mz_uint32) : 0)); + const mz_uint32 src_crc32 = pSrc_descriptor[0]; + const mz_uint64 src_comp_size = pSrc_descriptor[1]; + const mz_uint64 src_uncomp_size = pSrc_descriptor[2]; + + mz_write_le32((mz_uint8 *)pBuf, MZ_ZIP_DATA_DESCRIPTOR_ID); + mz_write_le32((mz_uint8 *)pBuf + sizeof(mz_uint32) * 1, src_crc32); + mz_write_le64((mz_uint8 *)pBuf + sizeof(mz_uint32) * 2, src_comp_size); + mz_write_le64((mz_uint8 *)pBuf + sizeof(mz_uint32) * 4, src_uncomp_size); + + n = sizeof(mz_uint32) * 6; + } + else + { + /* dest is NOT zip64, just copy it as-is */ + n = sizeof(mz_uint32) * (has_id ? 4 : 3); + } + } + + if (pZip->m_pWrite(pZip->m_pIO_opaque, cur_dst_file_ofs, pBuf, n) != n) + { + pZip->m_pFree(pZip->m_pAlloc_opaque, pBuf); + return mz_zip_set_error(pZip, MZ_ZIP_FILE_WRITE_FAILED); + } + + cur_src_file_ofs += n; + cur_dst_file_ofs += n; + } + pZip->m_pFree(pZip->m_pAlloc_opaque, pBuf); + + /* Finally, add the new central dir header */ + orig_central_dir_size = pState->m_central_dir.m_size; + + memcpy(new_central_header, pSrc_central_header, MZ_ZIP_CENTRAL_DIR_HEADER_SIZE); + + if (pState->m_zip64) + { + /* This is the painful part: We need to write a new central dir header + ext block with updated zip64 fields, and ensure the old fields (if any) are not included. */ + const mz_uint8 *pSrc_ext = pSrc_central_header + MZ_ZIP_CENTRAL_DIR_HEADER_SIZE + src_filename_len; + mz_zip_array new_ext_block; + + mz_zip_array_init(&new_ext_block, sizeof(mz_uint8)); + + MZ_WRITE_LE32(new_central_header + MZ_ZIP_CDH_COMPRESSED_SIZE_OFS, MZ_UINT32_MAX); + MZ_WRITE_LE32(new_central_header + MZ_ZIP_CDH_DECOMPRESSED_SIZE_OFS, MZ_UINT32_MAX); + MZ_WRITE_LE32(new_central_header + MZ_ZIP_CDH_LOCAL_HEADER_OFS, MZ_UINT32_MAX); + + if (!mz_zip_writer_update_zip64_extension_block(&new_ext_block, pZip, pSrc_ext, src_ext_len, &src_file_stat.m_comp_size, &src_file_stat.m_uncomp_size, &local_dir_header_ofs, NULL)) + { + mz_zip_array_clear(pZip, &new_ext_block); + return MZ_FALSE; + } + + MZ_WRITE_LE16(new_central_header + MZ_ZIP_CDH_EXTRA_LEN_OFS, new_ext_block.m_size); + + if (!mz_zip_array_push_back(pZip, &pState->m_central_dir, new_central_header, MZ_ZIP_CENTRAL_DIR_HEADER_SIZE)) + { + mz_zip_array_clear(pZip, &new_ext_block); + return mz_zip_set_error(pZip, MZ_ZIP_ALLOC_FAILED); + } + + if (!mz_zip_array_push_back(pZip, &pState->m_central_dir, pSrc_central_header + MZ_ZIP_CENTRAL_DIR_HEADER_SIZE, src_filename_len)) + { + mz_zip_array_clear(pZip, &new_ext_block); + mz_zip_array_resize(pZip, &pState->m_central_dir, orig_central_dir_size, MZ_FALSE); + return mz_zip_set_error(pZip, MZ_ZIP_ALLOC_FAILED); + } + + if (!mz_zip_array_push_back(pZip, &pState->m_central_dir, new_ext_block.m_p, new_ext_block.m_size)) + { + mz_zip_array_clear(pZip, &new_ext_block); + mz_zip_array_resize(pZip, &pState->m_central_dir, orig_central_dir_size, MZ_FALSE); + return mz_zip_set_error(pZip, MZ_ZIP_ALLOC_FAILED); + } + + if (!mz_zip_array_push_back(pZip, &pState->m_central_dir, pSrc_central_header + MZ_ZIP_CENTRAL_DIR_HEADER_SIZE + src_filename_len + src_ext_len, src_comment_len)) + { + mz_zip_array_clear(pZip, &new_ext_block); + mz_zip_array_resize(pZip, &pState->m_central_dir, orig_central_dir_size, MZ_FALSE); + return mz_zip_set_error(pZip, MZ_ZIP_ALLOC_FAILED); + } + + mz_zip_array_clear(pZip, &new_ext_block); + } + else + { + /* sanity checks */ + if (cur_dst_file_ofs > MZ_UINT32_MAX) + return mz_zip_set_error(pZip, MZ_ZIP_ARCHIVE_TOO_LARGE); + + if (local_dir_header_ofs >= MZ_UINT32_MAX) + return mz_zip_set_error(pZip, MZ_ZIP_ARCHIVE_TOO_LARGE); + + MZ_WRITE_LE32(new_central_header + MZ_ZIP_CDH_LOCAL_HEADER_OFS, local_dir_header_ofs); + + if (!mz_zip_array_push_back(pZip, &pState->m_central_dir, new_central_header, MZ_ZIP_CENTRAL_DIR_HEADER_SIZE)) + return mz_zip_set_error(pZip, MZ_ZIP_ALLOC_FAILED); + + if (!mz_zip_array_push_back(pZip, &pState->m_central_dir, pSrc_central_header + MZ_ZIP_CENTRAL_DIR_HEADER_SIZE, src_central_dir_following_data_size)) + { + mz_zip_array_resize(pZip, &pState->m_central_dir, orig_central_dir_size, MZ_FALSE); + return mz_zip_set_error(pZip, MZ_ZIP_ALLOC_FAILED); + } + } + + /* This shouldn't trigger unless we screwed up during the initial sanity checks */ + if (pState->m_central_dir.m_size >= MZ_UINT32_MAX) + { + /* TODO: Support central dirs >= 32-bits in size */ + mz_zip_array_resize(pZip, &pState->m_central_dir, orig_central_dir_size, MZ_FALSE); + return mz_zip_set_error(pZip, MZ_ZIP_UNSUPPORTED_CDIR_SIZE); + } + + n = (mz_uint32)orig_central_dir_size; + if (!mz_zip_array_push_back(pZip, &pState->m_central_dir_offsets, &n, 1)) + { + mz_zip_array_resize(pZip, &pState->m_central_dir, orig_central_dir_size, MZ_FALSE); + return mz_zip_set_error(pZip, MZ_ZIP_ALLOC_FAILED); + } + + pZip->m_total_files++; + pZip->m_archive_size = cur_dst_file_ofs; + + return MZ_TRUE; +} + +mz_bool mz_zip_writer_finalize_archive(mz_zip_archive *pZip) +{ + mz_zip_internal_state *pState; + mz_uint64 central_dir_ofs, central_dir_size; + mz_uint8 hdr[256]; + + if ((!pZip) || (!pZip->m_pState) || (pZip->m_zip_mode != MZ_ZIP_MODE_WRITING)) + return mz_zip_set_error(pZip, MZ_ZIP_INVALID_PARAMETER); + + pState = pZip->m_pState; + + if (pState->m_zip64) + { + if ((pZip->m_total_files > MZ_UINT32_MAX) || (pState->m_central_dir.m_size >= MZ_UINT32_MAX)) + return mz_zip_set_error(pZip, MZ_ZIP_TOO_MANY_FILES); + } + else + { + if ((pZip->m_total_files > MZ_UINT16_MAX) || ((pZip->m_archive_size + pState->m_central_dir.m_size + MZ_ZIP_END_OF_CENTRAL_DIR_HEADER_SIZE) > MZ_UINT32_MAX)) + return mz_zip_set_error(pZip, MZ_ZIP_TOO_MANY_FILES); + } + + central_dir_ofs = 0; + central_dir_size = 0; + if (pZip->m_total_files) + { + /* Write central directory */ + central_dir_ofs = pZip->m_archive_size; + central_dir_size = pState->m_central_dir.m_size; + pZip->m_central_directory_file_ofs = central_dir_ofs; + if (pZip->m_pWrite(pZip->m_pIO_opaque, central_dir_ofs, pState->m_central_dir.m_p, (size_t)central_dir_size) != central_dir_size) + return mz_zip_set_error(pZip, MZ_ZIP_FILE_WRITE_FAILED); + + pZip->m_archive_size += central_dir_size; + } + + if (pState->m_zip64) + { + /* Write zip64 end of central directory header */ + mz_uint64 rel_ofs_to_zip64_ecdr = pZip->m_archive_size; + + MZ_CLEAR_OBJ(hdr); + MZ_WRITE_LE32(hdr + MZ_ZIP64_ECDH_SIG_OFS, MZ_ZIP64_END_OF_CENTRAL_DIR_HEADER_SIG); + MZ_WRITE_LE64(hdr + MZ_ZIP64_ECDH_SIZE_OF_RECORD_OFS, MZ_ZIP64_END_OF_CENTRAL_DIR_HEADER_SIZE - sizeof(mz_uint32) - sizeof(mz_uint64)); + MZ_WRITE_LE16(hdr + MZ_ZIP64_ECDH_VERSION_MADE_BY_OFS, 0x031E); /* TODO: always Unix */ + MZ_WRITE_LE16(hdr + MZ_ZIP64_ECDH_VERSION_NEEDED_OFS, 0x002D); + MZ_WRITE_LE64(hdr + MZ_ZIP64_ECDH_CDIR_NUM_ENTRIES_ON_DISK_OFS, pZip->m_total_files); + MZ_WRITE_LE64(hdr + MZ_ZIP64_ECDH_CDIR_TOTAL_ENTRIES_OFS, pZip->m_total_files); + MZ_WRITE_LE64(hdr + MZ_ZIP64_ECDH_CDIR_SIZE_OFS, central_dir_size); + MZ_WRITE_LE64(hdr + MZ_ZIP64_ECDH_CDIR_OFS_OFS, central_dir_ofs); + if (pZip->m_pWrite(pZip->m_pIO_opaque, pZip->m_archive_size, hdr, MZ_ZIP64_END_OF_CENTRAL_DIR_HEADER_SIZE) != MZ_ZIP64_END_OF_CENTRAL_DIR_HEADER_SIZE) + return mz_zip_set_error(pZip, MZ_ZIP_FILE_WRITE_FAILED); + + pZip->m_archive_size += MZ_ZIP64_END_OF_CENTRAL_DIR_HEADER_SIZE; + + /* Write zip64 end of central directory locator */ + MZ_CLEAR_OBJ(hdr); + MZ_WRITE_LE32(hdr + MZ_ZIP64_ECDL_SIG_OFS, MZ_ZIP64_END_OF_CENTRAL_DIR_LOCATOR_SIG); + MZ_WRITE_LE64(hdr + MZ_ZIP64_ECDL_REL_OFS_TO_ZIP64_ECDR_OFS, rel_ofs_to_zip64_ecdr); + MZ_WRITE_LE32(hdr + MZ_ZIP64_ECDL_TOTAL_NUMBER_OF_DISKS_OFS, 1); + if (pZip->m_pWrite(pZip->m_pIO_opaque, pZip->m_archive_size, hdr, MZ_ZIP64_END_OF_CENTRAL_DIR_LOCATOR_SIZE) != MZ_ZIP64_END_OF_CENTRAL_DIR_LOCATOR_SIZE) + return mz_zip_set_error(pZip, MZ_ZIP_FILE_WRITE_FAILED); + + pZip->m_archive_size += MZ_ZIP64_END_OF_CENTRAL_DIR_LOCATOR_SIZE; + } + + /* Write end of central directory record */ + MZ_CLEAR_OBJ(hdr); + MZ_WRITE_LE32(hdr + MZ_ZIP_ECDH_SIG_OFS, MZ_ZIP_END_OF_CENTRAL_DIR_HEADER_SIG); + MZ_WRITE_LE16(hdr + MZ_ZIP_ECDH_CDIR_NUM_ENTRIES_ON_DISK_OFS, MZ_MIN(MZ_UINT16_MAX, pZip->m_total_files)); + MZ_WRITE_LE16(hdr + MZ_ZIP_ECDH_CDIR_TOTAL_ENTRIES_OFS, MZ_MIN(MZ_UINT16_MAX, pZip->m_total_files)); + MZ_WRITE_LE32(hdr + MZ_ZIP_ECDH_CDIR_SIZE_OFS, MZ_MIN(MZ_UINT32_MAX, central_dir_size)); + MZ_WRITE_LE32(hdr + MZ_ZIP_ECDH_CDIR_OFS_OFS, MZ_MIN(MZ_UINT32_MAX, central_dir_ofs)); + + if (pZip->m_pWrite(pZip->m_pIO_opaque, pZip->m_archive_size, hdr, MZ_ZIP_END_OF_CENTRAL_DIR_HEADER_SIZE) != MZ_ZIP_END_OF_CENTRAL_DIR_HEADER_SIZE) + return mz_zip_set_error(pZip, MZ_ZIP_FILE_WRITE_FAILED); + +#ifndef MINIZ_NO_STDIO + if ((pState->m_pFile) && (MZ_FFLUSH(pState->m_pFile) == EOF)) + return mz_zip_set_error(pZip, MZ_ZIP_FILE_CLOSE_FAILED); +#endif /* #ifndef MINIZ_NO_STDIO */ + + pZip->m_archive_size += MZ_ZIP_END_OF_CENTRAL_DIR_HEADER_SIZE; + + pZip->m_zip_mode = MZ_ZIP_MODE_WRITING_HAS_BEEN_FINALIZED; + return MZ_TRUE; +} + +mz_bool mz_zip_writer_finalize_heap_archive(mz_zip_archive *pZip, void **ppBuf, size_t *pSize) +{ + if ((!ppBuf) || (!pSize)) + return mz_zip_set_error(pZip, MZ_ZIP_INVALID_PARAMETER); + + *ppBuf = NULL; + *pSize = 0; + + if ((!pZip) || (!pZip->m_pState)) + return mz_zip_set_error(pZip, MZ_ZIP_INVALID_PARAMETER); + + if (pZip->m_pWrite != mz_zip_heap_write_func) + return mz_zip_set_error(pZip, MZ_ZIP_INVALID_PARAMETER); + + if (!mz_zip_writer_finalize_archive(pZip)) + return MZ_FALSE; + + *ppBuf = pZip->m_pState->m_pMem; + *pSize = pZip->m_pState->m_mem_size; + pZip->m_pState->m_pMem = NULL; + pZip->m_pState->m_mem_size = pZip->m_pState->m_mem_capacity = 0; + + return MZ_TRUE; +} + +mz_bool mz_zip_writer_end(mz_zip_archive *pZip) +{ + return mz_zip_writer_end_internal(pZip, MZ_TRUE); +} + +#ifndef MINIZ_NO_STDIO +mz_bool mz_zip_add_mem_to_archive_file_in_place(const char *pZip_filename, const char *pArchive_name, const void *pBuf, size_t buf_size, const void *pComment, mz_uint16 comment_size, mz_uint level_and_flags) +{ + return mz_zip_add_mem_to_archive_file_in_place_v2(pZip_filename, pArchive_name, pBuf, buf_size, pComment, comment_size, level_and_flags, NULL); +} + +mz_bool mz_zip_add_mem_to_archive_file_in_place_v2(const char *pZip_filename, const char *pArchive_name, const void *pBuf, size_t buf_size, const void *pComment, mz_uint16 comment_size, mz_uint level_and_flags, mz_zip_error *pErr) +{ + mz_bool status, created_new_archive = MZ_FALSE; + mz_zip_archive zip_archive; + struct MZ_FILE_STAT_STRUCT file_stat; + mz_zip_error actual_err = MZ_ZIP_NO_ERROR; + + mz_zip_zero_struct(&zip_archive); + if ((int)level_and_flags < 0) + level_and_flags = MZ_DEFAULT_LEVEL; + + if ((!pZip_filename) || (!pArchive_name) || ((buf_size) && (!pBuf)) || ((comment_size) && (!pComment)) || ((level_and_flags & 0xF) > MZ_UBER_COMPRESSION)) + { + if (pErr) + *pErr = MZ_ZIP_INVALID_PARAMETER; + return MZ_FALSE; + } + + if (!mz_zip_writer_validate_archive_name(pArchive_name)) + { + if (pErr) + *pErr = MZ_ZIP_INVALID_FILENAME; + return MZ_FALSE; + } + + /* Important: The regular non-64 bit version of stat() can fail here if the file is very large, which could cause the archive to be overwritten. */ + /* So be sure to compile with _LARGEFILE64_SOURCE 1 */ + if (MZ_FILE_STAT(pZip_filename, &file_stat) != 0) + { + /* Create a new archive. */ + if (!mz_zip_writer_init_file_v2(&zip_archive, pZip_filename, 0, level_and_flags)) + { + if (pErr) + *pErr = zip_archive.m_last_error; + return MZ_FALSE; + } + + created_new_archive = MZ_TRUE; + } + else + { + /* Append to an existing archive. */ + if (!mz_zip_reader_init_file_v2(&zip_archive, pZip_filename, level_and_flags | MZ_ZIP_FLAG_DO_NOT_SORT_CENTRAL_DIRECTORY, 0, 0)) + { + if (pErr) + *pErr = zip_archive.m_last_error; + return MZ_FALSE; + } + + if (!mz_zip_writer_init_from_reader_v2(&zip_archive, pZip_filename, level_and_flags)) + { + if (pErr) + *pErr = zip_archive.m_last_error; + + mz_zip_reader_end_internal(&zip_archive, MZ_FALSE); + + return MZ_FALSE; + } + } + + status = mz_zip_writer_add_mem_ex(&zip_archive, pArchive_name, pBuf, buf_size, pComment, comment_size, level_and_flags, 0, 0); + actual_err = zip_archive.m_last_error; + + /* Always finalize, even if adding failed for some reason, so we have a valid central directory. (This may not always succeed, but we can try.) */ + if (!mz_zip_writer_finalize_archive(&zip_archive)) + { + if (!actual_err) + actual_err = zip_archive.m_last_error; + + status = MZ_FALSE; + } + + if (!mz_zip_writer_end_internal(&zip_archive, status)) + { + if (!actual_err) + actual_err = zip_archive.m_last_error; + + status = MZ_FALSE; + } + + if ((!status) && (created_new_archive)) + { + /* It's a new archive and something went wrong, so just delete it. */ + int ignoredStatus = MZ_DELETE_FILE(pZip_filename); + (void)ignoredStatus; + } + + if (pErr) + *pErr = actual_err; + + return status; +} + +void *mz_zip_extract_archive_file_to_heap_v2(const char *pZip_filename, const char *pArchive_name, const char *pComment, size_t *pSize, mz_uint flags, mz_zip_error *pErr) +{ + mz_uint32 file_index; + mz_zip_archive zip_archive; + void *p = NULL; + + if (pSize) + *pSize = 0; + + if ((!pZip_filename) || (!pArchive_name)) + { + if (pErr) + *pErr = MZ_ZIP_INVALID_PARAMETER; + + return NULL; + } + + mz_zip_zero_struct(&zip_archive); + if (!mz_zip_reader_init_file_v2(&zip_archive, pZip_filename, flags | MZ_ZIP_FLAG_DO_NOT_SORT_CENTRAL_DIRECTORY, 0, 0)) + { + if (pErr) + *pErr = zip_archive.m_last_error; + + return NULL; + } + + if (mz_zip_reader_locate_file_v2(&zip_archive, pArchive_name, pComment, flags, &file_index)) + { + p = mz_zip_reader_extract_to_heap(&zip_archive, file_index, pSize, flags); + } + + mz_zip_reader_end_internal(&zip_archive, p != NULL); + + if (pErr) + *pErr = zip_archive.m_last_error; + + return p; +} + +void *mz_zip_extract_archive_file_to_heap(const char *pZip_filename, const char *pArchive_name, size_t *pSize, mz_uint flags) +{ + return mz_zip_extract_archive_file_to_heap_v2(pZip_filename, pArchive_name, NULL, pSize, flags, NULL); +} + +#endif /* #ifndef MINIZ_NO_STDIO */ + +#endif /* #ifndef MINIZ_NO_ARCHIVE_WRITING_APIS */ + +/* ------------------- Misc utils */ + +mz_zip_mode mz_zip_get_mode(mz_zip_archive *pZip) +{ + return pZip ? pZip->m_zip_mode : MZ_ZIP_MODE_INVALID; +} + +mz_zip_type mz_zip_get_type(mz_zip_archive *pZip) +{ + return pZip ? pZip->m_zip_type : MZ_ZIP_TYPE_INVALID; +} + +mz_zip_error mz_zip_set_last_error(mz_zip_archive *pZip, mz_zip_error err_num) +{ + mz_zip_error prev_err; + + if (!pZip) + return MZ_ZIP_INVALID_PARAMETER; + + prev_err = pZip->m_last_error; + + pZip->m_last_error = err_num; + return prev_err; +} + +mz_zip_error mz_zip_peek_last_error(mz_zip_archive *pZip) +{ + if (!pZip) + return MZ_ZIP_INVALID_PARAMETER; + + return pZip->m_last_error; +} + +mz_zip_error mz_zip_clear_last_error(mz_zip_archive *pZip) +{ + return mz_zip_set_last_error(pZip, MZ_ZIP_NO_ERROR); +} + +mz_zip_error mz_zip_get_last_error(mz_zip_archive *pZip) +{ + mz_zip_error prev_err; + + if (!pZip) + return MZ_ZIP_INVALID_PARAMETER; + + prev_err = pZip->m_last_error; + + pZip->m_last_error = MZ_ZIP_NO_ERROR; + return prev_err; +} + +const char *mz_zip_get_error_string(mz_zip_error mz_err) +{ + switch (mz_err) + { + case MZ_ZIP_NO_ERROR: + return "no error"; + case MZ_ZIP_UNDEFINED_ERROR: + return "undefined error"; + case MZ_ZIP_TOO_MANY_FILES: + return "too many files"; + case MZ_ZIP_FILE_TOO_LARGE: + return "file too large"; + case MZ_ZIP_UNSUPPORTED_METHOD: + return "unsupported method"; + case MZ_ZIP_UNSUPPORTED_ENCRYPTION: + return "unsupported encryption"; + case MZ_ZIP_UNSUPPORTED_FEATURE: + return "unsupported feature"; + case MZ_ZIP_FAILED_FINDING_CENTRAL_DIR: + return "failed finding central directory"; + case MZ_ZIP_NOT_AN_ARCHIVE: + return "not a ZIP archive"; + case MZ_ZIP_INVALID_HEADER_OR_CORRUPTED: + return "invalid header or archive is corrupted"; + case MZ_ZIP_UNSUPPORTED_MULTIDISK: + return "unsupported multidisk archive"; + case MZ_ZIP_DECOMPRESSION_FAILED: + return "decompression failed or archive is corrupted"; + case MZ_ZIP_COMPRESSION_FAILED: + return "compression failed"; + case MZ_ZIP_UNEXPECTED_DECOMPRESSED_SIZE: + return "unexpected decompressed size"; + case MZ_ZIP_CRC_CHECK_FAILED: + return "CRC-32 check failed"; + case MZ_ZIP_UNSUPPORTED_CDIR_SIZE: + return "unsupported central directory size"; + case MZ_ZIP_ALLOC_FAILED: + return "allocation failed"; + case MZ_ZIP_FILE_OPEN_FAILED: + return "file open failed"; + case MZ_ZIP_FILE_CREATE_FAILED: + return "file create failed"; + case MZ_ZIP_FILE_WRITE_FAILED: + return "file write failed"; + case MZ_ZIP_FILE_READ_FAILED: + return "file read failed"; + case MZ_ZIP_FILE_CLOSE_FAILED: + return "file close failed"; + case MZ_ZIP_FILE_SEEK_FAILED: + return "file seek failed"; + case MZ_ZIP_FILE_STAT_FAILED: + return "file stat failed"; + case MZ_ZIP_INVALID_PARAMETER: + return "invalid parameter"; + case MZ_ZIP_INVALID_FILENAME: + return "invalid filename"; + case MZ_ZIP_BUF_TOO_SMALL: + return "buffer too small"; + case MZ_ZIP_INTERNAL_ERROR: + return "internal error"; + case MZ_ZIP_FILE_NOT_FOUND: + return "file not found"; + case MZ_ZIP_ARCHIVE_TOO_LARGE: + return "archive is too large"; + case MZ_ZIP_VALIDATION_FAILED: + return "validation failed"; + case MZ_ZIP_WRITE_CALLBACK_FAILED: + return "write calledback failed"; + default: + break; + } + + return "unknown error"; +} + +/* Note: Just because the archive is not zip64 doesn't necessarily mean it doesn't have Zip64 extended information extra field, argh. */ +mz_bool mz_zip_is_zip64(mz_zip_archive *pZip) +{ + if ((!pZip) || (!pZip->m_pState)) + return MZ_FALSE; + + return pZip->m_pState->m_zip64; +} + +size_t mz_zip_get_central_dir_size(mz_zip_archive *pZip) +{ + if ((!pZip) || (!pZip->m_pState)) + return 0; + + return pZip->m_pState->m_central_dir.m_size; +} + +mz_uint mz_zip_reader_get_num_files(mz_zip_archive *pZip) +{ + return pZip ? pZip->m_total_files : 0; +} + +mz_uint64 mz_zip_get_archive_size(mz_zip_archive *pZip) +{ + if (!pZip) + return 0; + return pZip->m_archive_size; +} + +mz_uint64 mz_zip_get_archive_file_start_offset(mz_zip_archive *pZip) +{ + if ((!pZip) || (!pZip->m_pState)) + return 0; + return pZip->m_pState->m_file_archive_start_ofs; +} + +MZ_FILE *mz_zip_get_cfile(mz_zip_archive *pZip) +{ + if ((!pZip) || (!pZip->m_pState)) + return 0; + return pZip->m_pState->m_pFile; +} + +size_t mz_zip_read_archive_data(mz_zip_archive *pZip, mz_uint64 file_ofs, void *pBuf, size_t n) +{ + if ((!pZip) || (!pZip->m_pState) || (!pBuf) || (!pZip->m_pRead)) + return mz_zip_set_error(pZip, MZ_ZIP_INVALID_PARAMETER); + + return pZip->m_pRead(pZip->m_pIO_opaque, file_ofs, pBuf, n); +} + +mz_uint mz_zip_reader_get_filename(mz_zip_archive *pZip, mz_uint file_index, char *pFilename, mz_uint filename_buf_size) +{ + mz_uint n; + const mz_uint8 *p = mz_zip_get_cdh(pZip, file_index); + if (!p) + { + if (filename_buf_size) + pFilename[0] = '\0'; + mz_zip_set_error(pZip, MZ_ZIP_INVALID_PARAMETER); + return 0; + } + n = MZ_READ_LE16(p + MZ_ZIP_CDH_FILENAME_LEN_OFS); + if (filename_buf_size) + { + n = MZ_MIN(n, filename_buf_size - 1); + memcpy(pFilename, p + MZ_ZIP_CENTRAL_DIR_HEADER_SIZE, n); + pFilename[n] = '\0'; + } + return n + 1; +} + +mz_bool mz_zip_reader_file_stat(mz_zip_archive *pZip, mz_uint file_index, mz_zip_archive_file_stat *pStat) +{ + return mz_zip_file_stat_internal(pZip, file_index, mz_zip_get_cdh(pZip, file_index), pStat, NULL); +} + +mz_bool mz_zip_end(mz_zip_archive *pZip) +{ + if (!pZip) + return MZ_FALSE; + + if (pZip->m_zip_mode == MZ_ZIP_MODE_READING) + return mz_zip_reader_end(pZip); +#ifndef MINIZ_NO_ARCHIVE_WRITING_APIS + else if ((pZip->m_zip_mode == MZ_ZIP_MODE_WRITING) || (pZip->m_zip_mode == MZ_ZIP_MODE_WRITING_HAS_BEEN_FINALIZED)) + return mz_zip_writer_end(pZip); +#endif + + return MZ_FALSE; +} + +#endif /*#ifndef MINIZ_NO_ARCHIVE_APIS*/ diff --git a/xs/src/miniz/miniz_zip.h b/xs/src/miniz/miniz_zip.h new file mode 100644 index 000000000..71ecb4ae2 --- /dev/null +++ b/xs/src/miniz/miniz_zip.h @@ -0,0 +1,429 @@ + +#pragma once +#include "miniz.h" + +/* ------------------- ZIP archive reading/writing */ + +#ifndef MINIZ_NO_ARCHIVE_APIS + +enum +{ + /* Note: These enums can be reduced as needed to save memory or stack space - they are pretty conservative. */ + MZ_ZIP_MAX_IO_BUF_SIZE = 64 * 1024, + MZ_ZIP_MAX_ARCHIVE_FILENAME_SIZE = 512, + MZ_ZIP_MAX_ARCHIVE_FILE_COMMENT_SIZE = 512 +}; + +typedef struct +{ + /* Central directory file index. */ + mz_uint32 m_file_index; + + /* Byte offset of this entry in the archive's central directory. Note we currently only support up to UINT_MAX or less bytes in the central dir. */ + mz_uint64 m_central_dir_ofs; + + /* These fields are copied directly from the zip's central dir. */ + mz_uint16 m_version_made_by; + mz_uint16 m_version_needed; + mz_uint16 m_bit_flag; + mz_uint16 m_method; + +#ifndef MINIZ_NO_TIME + MZ_TIME_T m_time; +#endif + + /* CRC-32 of uncompressed data. */ + mz_uint32 m_crc32; + + /* File's compressed size. */ + mz_uint64 m_comp_size; + + /* File's uncompressed size. Note, I've seen some old archives where directory entries had 512 bytes for their uncompressed sizes, but when you try to unpack them you actually get 0 bytes. */ + mz_uint64 m_uncomp_size; + + /* Zip internal and external file attributes. */ + mz_uint16 m_internal_attr; + mz_uint32 m_external_attr; + + /* Entry's local header file offset in bytes. */ + mz_uint64 m_local_header_ofs; + + /* Size of comment in bytes. */ + mz_uint32 m_comment_size; + + /* MZ_TRUE if the entry appears to be a directory. */ + mz_bool m_is_directory; + + /* MZ_TRUE if the entry uses encryption/strong encryption (which miniz_zip doesn't support) */ + mz_bool m_is_encrypted; + + /* MZ_TRUE if the file is not encrypted, a patch file, and if it uses a compression method we support. */ + mz_bool m_is_supported; + + /* Filename. If string ends in '/' it's a subdirectory entry. */ + /* Guaranteed to be zero terminated, may be truncated to fit. */ + char m_filename[MZ_ZIP_MAX_ARCHIVE_FILENAME_SIZE]; + + /* Comment field. */ + /* Guaranteed to be zero terminated, may be truncated to fit. */ + char m_comment[MZ_ZIP_MAX_ARCHIVE_FILE_COMMENT_SIZE]; + +} mz_zip_archive_file_stat; + +typedef size_t (*mz_file_read_func)(void *pOpaque, mz_uint64 file_ofs, void *pBuf, size_t n); +typedef size_t (*mz_file_write_func)(void *pOpaque, mz_uint64 file_ofs, const void *pBuf, size_t n); +typedef mz_bool (*mz_file_needs_keepalive)(void *pOpaque); + +struct mz_zip_internal_state_tag; +typedef struct mz_zip_internal_state_tag mz_zip_internal_state; + +typedef enum { + MZ_ZIP_MODE_INVALID = 0, + MZ_ZIP_MODE_READING = 1, + MZ_ZIP_MODE_WRITING = 2, + MZ_ZIP_MODE_WRITING_HAS_BEEN_FINALIZED = 3 +} mz_zip_mode; + +typedef enum { + MZ_ZIP_FLAG_CASE_SENSITIVE = 0x0100, + MZ_ZIP_FLAG_IGNORE_PATH = 0x0200, + MZ_ZIP_FLAG_COMPRESSED_DATA = 0x0400, + MZ_ZIP_FLAG_DO_NOT_SORT_CENTRAL_DIRECTORY = 0x0800, + MZ_ZIP_FLAG_VALIDATE_LOCATE_FILE_FLAG = 0x1000, /* if enabled, mz_zip_reader_locate_file() will be called on each file as its validated to ensure the func finds the file in the central dir (intended for testing) */ + MZ_ZIP_FLAG_VALIDATE_HEADERS_ONLY = 0x2000, /* validate the local headers, but don't decompress the entire file and check the crc32 */ + MZ_ZIP_FLAG_WRITE_ZIP64 = 0x4000, /* always use the zip64 file format, instead of the original zip file format with automatic switch to zip64. Use as flags parameter with mz_zip_writer_init*_v2 */ + MZ_ZIP_FLAG_WRITE_ALLOW_READING = 0x8000, + MZ_ZIP_FLAG_ASCII_FILENAME = 0x10000 +} mz_zip_flags; + +typedef enum { + MZ_ZIP_TYPE_INVALID = 0, + MZ_ZIP_TYPE_USER, + MZ_ZIP_TYPE_MEMORY, + MZ_ZIP_TYPE_HEAP, + MZ_ZIP_TYPE_FILE, + MZ_ZIP_TYPE_CFILE, + MZ_ZIP_TOTAL_TYPES +} mz_zip_type; + +/* miniz error codes. Be sure to update mz_zip_get_error_string() if you add or modify this enum. */ +typedef enum { + MZ_ZIP_NO_ERROR = 0, + MZ_ZIP_UNDEFINED_ERROR, + MZ_ZIP_TOO_MANY_FILES, + MZ_ZIP_FILE_TOO_LARGE, + MZ_ZIP_UNSUPPORTED_METHOD, + MZ_ZIP_UNSUPPORTED_ENCRYPTION, + MZ_ZIP_UNSUPPORTED_FEATURE, + MZ_ZIP_FAILED_FINDING_CENTRAL_DIR, + MZ_ZIP_NOT_AN_ARCHIVE, + MZ_ZIP_INVALID_HEADER_OR_CORRUPTED, + MZ_ZIP_UNSUPPORTED_MULTIDISK, + MZ_ZIP_DECOMPRESSION_FAILED, + MZ_ZIP_COMPRESSION_FAILED, + MZ_ZIP_UNEXPECTED_DECOMPRESSED_SIZE, + MZ_ZIP_CRC_CHECK_FAILED, + MZ_ZIP_UNSUPPORTED_CDIR_SIZE, + MZ_ZIP_ALLOC_FAILED, + MZ_ZIP_FILE_OPEN_FAILED, + MZ_ZIP_FILE_CREATE_FAILED, + MZ_ZIP_FILE_WRITE_FAILED, + MZ_ZIP_FILE_READ_FAILED, + MZ_ZIP_FILE_CLOSE_FAILED, + MZ_ZIP_FILE_SEEK_FAILED, + MZ_ZIP_FILE_STAT_FAILED, + MZ_ZIP_INVALID_PARAMETER, + MZ_ZIP_INVALID_FILENAME, + MZ_ZIP_BUF_TOO_SMALL, + MZ_ZIP_INTERNAL_ERROR, + MZ_ZIP_FILE_NOT_FOUND, + MZ_ZIP_ARCHIVE_TOO_LARGE, + MZ_ZIP_VALIDATION_FAILED, + MZ_ZIP_WRITE_CALLBACK_FAILED, + MZ_ZIP_TOTAL_ERRORS +} mz_zip_error; + +typedef struct +{ + mz_uint64 m_archive_size; + mz_uint64 m_central_directory_file_ofs; + + /* We only support up to UINT32_MAX files in zip64 mode. */ + mz_uint32 m_total_files; + mz_zip_mode m_zip_mode; + mz_zip_type m_zip_type; + mz_zip_error m_last_error; + + mz_uint64 m_file_offset_alignment; + + mz_alloc_func m_pAlloc; + mz_free_func m_pFree; + mz_realloc_func m_pRealloc; + void *m_pAlloc_opaque; + + mz_file_read_func m_pRead; + mz_file_write_func m_pWrite; + mz_file_needs_keepalive m_pNeeds_keepalive; + void *m_pIO_opaque; + + mz_zip_internal_state *m_pState; + +} mz_zip_archive; + +typedef struct +{ + mz_zip_archive *pZip; + mz_uint flags; + + int status; +#ifndef MINIZ_DISABLE_ZIP_READER_CRC32_CHECKS + mz_uint file_crc32; +#endif + mz_uint64 read_buf_size, read_buf_ofs, read_buf_avail, comp_remaining, out_buf_ofs, cur_file_ofs; + mz_zip_archive_file_stat file_stat; + void *pRead_buf; + void *pWrite_buf; + + size_t out_blk_remain; + + tinfl_decompressor inflator; + +} mz_zip_reader_extract_iter_state; + +/* -------- ZIP reading */ + +/* Inits a ZIP archive reader. */ +/* These functions read and validate the archive's central directory. */ +mz_bool mz_zip_reader_init(mz_zip_archive *pZip, mz_uint64 size, mz_uint flags); + +mz_bool mz_zip_reader_init_mem(mz_zip_archive *pZip, const void *pMem, size_t size, mz_uint flags); + +#ifndef MINIZ_NO_STDIO +/* Read a archive from a disk file. */ +/* file_start_ofs is the file offset where the archive actually begins, or 0. */ +/* actual_archive_size is the true total size of the archive, which may be smaller than the file's actual size on disk. If zero the entire file is treated as the archive. */ +mz_bool mz_zip_reader_init_file(mz_zip_archive *pZip, const char *pFilename, mz_uint32 flags); +mz_bool mz_zip_reader_init_file_v2(mz_zip_archive *pZip, const char *pFilename, mz_uint flags, mz_uint64 file_start_ofs, mz_uint64 archive_size); + +/* Read an archive from an already opened FILE, beginning at the current file position. */ +/* The archive is assumed to be archive_size bytes long. If archive_size is < 0, then the entire rest of the file is assumed to contain the archive. */ +/* The FILE will NOT be closed when mz_zip_reader_end() is called. */ +mz_bool mz_zip_reader_init_cfile(mz_zip_archive *pZip, MZ_FILE *pFile, mz_uint64 archive_size, mz_uint flags); +#endif + +/* Ends archive reading, freeing all allocations, and closing the input archive file if mz_zip_reader_init_file() was used. */ +mz_bool mz_zip_reader_end(mz_zip_archive *pZip); + +/* -------- ZIP reading or writing */ + +/* Clears a mz_zip_archive struct to all zeros. */ +/* Important: This must be done before passing the struct to any mz_zip functions. */ +void mz_zip_zero_struct(mz_zip_archive *pZip); + +mz_zip_mode mz_zip_get_mode(mz_zip_archive *pZip); +mz_zip_type mz_zip_get_type(mz_zip_archive *pZip); + +/* Returns the total number of files in the archive. */ +mz_uint mz_zip_reader_get_num_files(mz_zip_archive *pZip); + +mz_uint64 mz_zip_get_archive_size(mz_zip_archive *pZip); +mz_uint64 mz_zip_get_archive_file_start_offset(mz_zip_archive *pZip); +MZ_FILE *mz_zip_get_cfile(mz_zip_archive *pZip); + +/* Reads n bytes of raw archive data, starting at file offset file_ofs, to pBuf. */ +size_t mz_zip_read_archive_data(mz_zip_archive *pZip, mz_uint64 file_ofs, void *pBuf, size_t n); + +/* Attempts to locates a file in the archive's central directory. */ +/* Valid flags: MZ_ZIP_FLAG_CASE_SENSITIVE, MZ_ZIP_FLAG_IGNORE_PATH */ +/* Returns -1 if the file cannot be found. */ +int mz_zip_locate_file(mz_zip_archive *pZip, const char *pName, const char *pComment, mz_uint flags); +/* Returns MZ_FALSE if the file cannot be found. */ +mz_bool mz_zip_locate_file_v2(mz_zip_archive *pZip, const char *pName, const char *pComment, mz_uint flags, mz_uint32 *pIndex); + +/* All mz_zip funcs set the m_last_error field in the mz_zip_archive struct. These functions retrieve/manipulate this field. */ +/* Note that the m_last_error functionality is not thread safe. */ +mz_zip_error mz_zip_set_last_error(mz_zip_archive *pZip, mz_zip_error err_num); +mz_zip_error mz_zip_peek_last_error(mz_zip_archive *pZip); +mz_zip_error mz_zip_clear_last_error(mz_zip_archive *pZip); +mz_zip_error mz_zip_get_last_error(mz_zip_archive *pZip); +const char *mz_zip_get_error_string(mz_zip_error mz_err); + +/* MZ_TRUE if the archive file entry is a directory entry. */ +mz_bool mz_zip_reader_is_file_a_directory(mz_zip_archive *pZip, mz_uint file_index); + +/* MZ_TRUE if the file is encrypted/strong encrypted. */ +mz_bool mz_zip_reader_is_file_encrypted(mz_zip_archive *pZip, mz_uint file_index); + +/* MZ_TRUE if the compression method is supported, and the file is not encrypted, and the file is not a compressed patch file. */ +mz_bool mz_zip_reader_is_file_supported(mz_zip_archive *pZip, mz_uint file_index); + +/* Retrieves the filename of an archive file entry. */ +/* Returns the number of bytes written to pFilename, or if filename_buf_size is 0 this function returns the number of bytes needed to fully store the filename. */ +mz_uint mz_zip_reader_get_filename(mz_zip_archive *pZip, mz_uint file_index, char *pFilename, mz_uint filename_buf_size); + +/* Attempts to locates a file in the archive's central directory. */ +/* Valid flags: MZ_ZIP_FLAG_CASE_SENSITIVE, MZ_ZIP_FLAG_IGNORE_PATH */ +/* Returns -1 if the file cannot be found. */ +int mz_zip_reader_locate_file(mz_zip_archive *pZip, const char *pName, const char *pComment, mz_uint flags); +int mz_zip_reader_locate_file_v2(mz_zip_archive *pZip, const char *pName, const char *pComment, mz_uint flags, mz_uint32 *file_index); + +/* Returns detailed information about an archive file entry. */ +mz_bool mz_zip_reader_file_stat(mz_zip_archive *pZip, mz_uint file_index, mz_zip_archive_file_stat *pStat); + +/* MZ_TRUE if the file is in zip64 format. */ +/* A file is considered zip64 if it contained a zip64 end of central directory marker, or if it contained any zip64 extended file information fields in the central directory. */ +mz_bool mz_zip_is_zip64(mz_zip_archive *pZip); + +/* Returns the total central directory size in bytes. */ +/* The current max supported size is <= MZ_UINT32_MAX. */ +size_t mz_zip_get_central_dir_size(mz_zip_archive *pZip); + +/* Extracts a archive file to a memory buffer using no memory allocation. */ +/* There must be at least enough room on the stack to store the inflator's state (~34KB or so). */ +mz_bool mz_zip_reader_extract_to_mem_no_alloc(mz_zip_archive *pZip, mz_uint file_index, void *pBuf, size_t buf_size, mz_uint flags, void *pUser_read_buf, size_t user_read_buf_size); +mz_bool mz_zip_reader_extract_file_to_mem_no_alloc(mz_zip_archive *pZip, const char *pFilename, void *pBuf, size_t buf_size, mz_uint flags, void *pUser_read_buf, size_t user_read_buf_size); + +/* Extracts a archive file to a memory buffer. */ +mz_bool mz_zip_reader_extract_to_mem(mz_zip_archive *pZip, mz_uint file_index, void *pBuf, size_t buf_size, mz_uint flags); +mz_bool mz_zip_reader_extract_file_to_mem(mz_zip_archive *pZip, const char *pFilename, void *pBuf, size_t buf_size, mz_uint flags); + +/* Extracts a archive file to a dynamically allocated heap buffer. */ +/* The memory will be allocated via the mz_zip_archive's alloc/realloc functions. */ +/* Returns NULL and sets the last error on failure. */ +void *mz_zip_reader_extract_to_heap(mz_zip_archive *pZip, mz_uint file_index, size_t *pSize, mz_uint flags); +void *mz_zip_reader_extract_file_to_heap(mz_zip_archive *pZip, const char *pFilename, size_t *pSize, mz_uint flags); + +/* Extracts a archive file using a callback function to output the file's data. */ +mz_bool mz_zip_reader_extract_to_callback(mz_zip_archive *pZip, mz_uint file_index, mz_file_write_func pCallback, void *pOpaque, mz_uint flags); +mz_bool mz_zip_reader_extract_file_to_callback(mz_zip_archive *pZip, const char *pFilename, mz_file_write_func pCallback, void *pOpaque, mz_uint flags); + +/* Extract a file iteratively */ +mz_zip_reader_extract_iter_state* mz_zip_reader_extract_iter_new(mz_zip_archive *pZip, mz_uint file_index, mz_uint flags); +mz_zip_reader_extract_iter_state* mz_zip_reader_extract_file_iter_new(mz_zip_archive *pZip, const char *pFilename, mz_uint flags); +size_t mz_zip_reader_extract_iter_read(mz_zip_reader_extract_iter_state* pState, void* pvBuf, size_t buf_size); +mz_bool mz_zip_reader_extract_iter_free(mz_zip_reader_extract_iter_state* pState); + +#ifndef MINIZ_NO_STDIO +/* Extracts a archive file to a disk file and sets its last accessed and modified times. */ +/* This function only extracts files, not archive directory records. */ +mz_bool mz_zip_reader_extract_to_file(mz_zip_archive *pZip, mz_uint file_index, const char *pDst_filename, mz_uint flags); +mz_bool mz_zip_reader_extract_file_to_file(mz_zip_archive *pZip, const char *pArchive_filename, const char *pDst_filename, mz_uint flags); + +/* Extracts a archive file starting at the current position in the destination FILE stream. */ +mz_bool mz_zip_reader_extract_to_cfile(mz_zip_archive *pZip, mz_uint file_index, MZ_FILE *File, mz_uint flags); +mz_bool mz_zip_reader_extract_file_to_cfile(mz_zip_archive *pZip, const char *pArchive_filename, MZ_FILE *pFile, mz_uint flags); +#endif + +#if 0 +/* TODO */ + typedef void *mz_zip_streaming_extract_state_ptr; + mz_zip_streaming_extract_state_ptr mz_zip_streaming_extract_begin(mz_zip_archive *pZip, mz_uint file_index, mz_uint flags); + uint64_t mz_zip_streaming_extract_get_size(mz_zip_archive *pZip, mz_zip_streaming_extract_state_ptr pState); + uint64_t mz_zip_streaming_extract_get_cur_ofs(mz_zip_archive *pZip, mz_zip_streaming_extract_state_ptr pState); + mz_bool mz_zip_streaming_extract_seek(mz_zip_archive *pZip, mz_zip_streaming_extract_state_ptr pState, uint64_t new_ofs); + size_t mz_zip_streaming_extract_read(mz_zip_archive *pZip, mz_zip_streaming_extract_state_ptr pState, void *pBuf, size_t buf_size); + mz_bool mz_zip_streaming_extract_end(mz_zip_archive *pZip, mz_zip_streaming_extract_state_ptr pState); +#endif + +/* This function compares the archive's local headers, the optional local zip64 extended information block, and the optional descriptor following the compressed data vs. the data in the central directory. */ +/* It also validates that each file can be successfully uncompressed unless the MZ_ZIP_FLAG_VALIDATE_HEADERS_ONLY is specified. */ +mz_bool mz_zip_validate_file(mz_zip_archive *pZip, mz_uint file_index, mz_uint flags); + +/* Validates an entire archive by calling mz_zip_validate_file() on each file. */ +mz_bool mz_zip_validate_archive(mz_zip_archive *pZip, mz_uint flags); + +/* Misc utils/helpers, valid for ZIP reading or writing */ +mz_bool mz_zip_validate_mem_archive(const void *pMem, size_t size, mz_uint flags, mz_zip_error *pErr); +mz_bool mz_zip_validate_file_archive(const char *pFilename, mz_uint flags, mz_zip_error *pErr); + +/* Universal end function - calls either mz_zip_reader_end() or mz_zip_writer_end(). */ +mz_bool mz_zip_end(mz_zip_archive *pZip); + +/* -------- ZIP writing */ + +#ifndef MINIZ_NO_ARCHIVE_WRITING_APIS + +/* Inits a ZIP archive writer. */ +/*Set pZip->m_pWrite (and pZip->m_pIO_opaque) before calling mz_zip_writer_init or mz_zip_writer_init_v2*/ +/*The output is streamable, i.e. file_ofs in mz_file_write_func always increases only by n*/ +mz_bool mz_zip_writer_init(mz_zip_archive *pZip, mz_uint64 existing_size); +mz_bool mz_zip_writer_init_v2(mz_zip_archive *pZip, mz_uint64 existing_size, mz_uint flags); + +mz_bool mz_zip_writer_init_heap(mz_zip_archive *pZip, size_t size_to_reserve_at_beginning, size_t initial_allocation_size); +mz_bool mz_zip_writer_init_heap_v2(mz_zip_archive *pZip, size_t size_to_reserve_at_beginning, size_t initial_allocation_size, mz_uint flags); + +#ifndef MINIZ_NO_STDIO +mz_bool mz_zip_writer_init_file(mz_zip_archive *pZip, const char *pFilename, mz_uint64 size_to_reserve_at_beginning); +mz_bool mz_zip_writer_init_file_v2(mz_zip_archive *pZip, const char *pFilename, mz_uint64 size_to_reserve_at_beginning, mz_uint flags); +mz_bool mz_zip_writer_init_cfile(mz_zip_archive *pZip, MZ_FILE *pFile, mz_uint flags); +#endif + +/* Converts a ZIP archive reader object into a writer object, to allow efficient in-place file appends to occur on an existing archive. */ +/* For archives opened using mz_zip_reader_init_file, pFilename must be the archive's filename so it can be reopened for writing. If the file can't be reopened, mz_zip_reader_end() will be called. */ +/* For archives opened using mz_zip_reader_init_mem, the memory block must be growable using the realloc callback (which defaults to realloc unless you've overridden it). */ +/* Finally, for archives opened using mz_zip_reader_init, the mz_zip_archive's user provided m_pWrite function cannot be NULL. */ +/* Note: In-place archive modification is not recommended unless you know what you're doing, because if execution stops or something goes wrong before */ +/* the archive is finalized the file's central directory will be hosed. */ +mz_bool mz_zip_writer_init_from_reader(mz_zip_archive *pZip, const char *pFilename); +mz_bool mz_zip_writer_init_from_reader_v2(mz_zip_archive *pZip, const char *pFilename, mz_uint flags); + +/* Adds the contents of a memory buffer to an archive. These functions record the current local time into the archive. */ +/* To add a directory entry, call this method with an archive name ending in a forwardslash with an empty buffer. */ +/* level_and_flags - compression level (0-10, see MZ_BEST_SPEED, MZ_BEST_COMPRESSION, etc.) logically OR'd with zero or more mz_zip_flags, or just set to MZ_DEFAULT_COMPRESSION. */ +mz_bool mz_zip_writer_add_mem(mz_zip_archive *pZip, const char *pArchive_name, const void *pBuf, size_t buf_size, mz_uint level_and_flags); + +/* Like mz_zip_writer_add_mem(), except you can specify a file comment field, and optionally supply the function with already compressed data. */ +/* uncomp_size/uncomp_crc32 are only used if the MZ_ZIP_FLAG_COMPRESSED_DATA flag is specified. */ +mz_bool mz_zip_writer_add_mem_ex(mz_zip_archive *pZip, const char *pArchive_name, const void *pBuf, size_t buf_size, const void *pComment, mz_uint16 comment_size, mz_uint level_and_flags, + mz_uint64 uncomp_size, mz_uint32 uncomp_crc32); + +mz_bool mz_zip_writer_add_mem_ex_v2(mz_zip_archive *pZip, const char *pArchive_name, const void *pBuf, size_t buf_size, const void *pComment, mz_uint16 comment_size, mz_uint level_and_flags, + mz_uint64 uncomp_size, mz_uint32 uncomp_crc32, MZ_TIME_T *last_modified, const char *user_extra_data_local, mz_uint user_extra_data_local_len, + const char *user_extra_data_central, mz_uint user_extra_data_central_len); + +#ifndef MINIZ_NO_STDIO +/* Adds the contents of a disk file to an archive. This function also records the disk file's modified time into the archive. */ +/* level_and_flags - compression level (0-10, see MZ_BEST_SPEED, MZ_BEST_COMPRESSION, etc.) logically OR'd with zero or more mz_zip_flags, or just set to MZ_DEFAULT_COMPRESSION. */ +mz_bool mz_zip_writer_add_file(mz_zip_archive *pZip, const char *pArchive_name, const char *pSrc_filename, const void *pComment, mz_uint16 comment_size, mz_uint level_and_flags); + +/* Like mz_zip_writer_add_file(), except the file data is read from the specified FILE stream. */ +mz_bool mz_zip_writer_add_cfile(mz_zip_archive *pZip, const char *pArchive_name, MZ_FILE *pSrc_file, mz_uint64 size_to_add, + const MZ_TIME_T *pFile_time, const void *pComment, mz_uint16 comment_size, mz_uint level_and_flags, const char *user_extra_data_local, mz_uint user_extra_data_local_len, + const char *user_extra_data_central, mz_uint user_extra_data_central_len); +#endif + +/* Adds a file to an archive by fully cloning the data from another archive. */ +/* This function fully clones the source file's compressed data (no recompression), along with its full filename, extra data (it may add or modify the zip64 local header extra data field), and the optional descriptor following the compressed data. */ +mz_bool mz_zip_writer_add_from_zip_reader(mz_zip_archive *pZip, mz_zip_archive *pSource_zip, mz_uint src_file_index); + +/* Finalizes the archive by writing the central directory records followed by the end of central directory record. */ +/* After an archive is finalized, the only valid call on the mz_zip_archive struct is mz_zip_writer_end(). */ +/* An archive must be manually finalized by calling this function for it to be valid. */ +mz_bool mz_zip_writer_finalize_archive(mz_zip_archive *pZip); + +/* Finalizes a heap archive, returning a poiner to the heap block and its size. */ +/* The heap block will be allocated using the mz_zip_archive's alloc/realloc callbacks. */ +mz_bool mz_zip_writer_finalize_heap_archive(mz_zip_archive *pZip, void **ppBuf, size_t *pSize); + +/* Ends archive writing, freeing all allocations, and closing the output file if mz_zip_writer_init_file() was used. */ +/* Note for the archive to be valid, it *must* have been finalized before ending (this function will not do it for you). */ +mz_bool mz_zip_writer_end(mz_zip_archive *pZip); + +/* -------- Misc. high-level helper functions: */ + +/* mz_zip_add_mem_to_archive_file_in_place() efficiently (but not atomically) appends a memory blob to a ZIP archive. */ +/* Note this is NOT a fully safe operation. If it crashes or dies in some way your archive can be left in a screwed up state (without a central directory). */ +/* level_and_flags - compression level (0-10, see MZ_BEST_SPEED, MZ_BEST_COMPRESSION, etc.) logically OR'd with zero or more mz_zip_flags, or just set to MZ_DEFAULT_COMPRESSION. */ +/* TODO: Perhaps add an option to leave the existing central dir in place in case the add dies? We could then truncate the file (so the old central dir would be at the end) if something goes wrong. */ +mz_bool mz_zip_add_mem_to_archive_file_in_place(const char *pZip_filename, const char *pArchive_name, const void *pBuf, size_t buf_size, const void *pComment, mz_uint16 comment_size, mz_uint level_and_flags); +mz_bool mz_zip_add_mem_to_archive_file_in_place_v2(const char *pZip_filename, const char *pArchive_name, const void *pBuf, size_t buf_size, const void *pComment, mz_uint16 comment_size, mz_uint level_and_flags, mz_zip_error *pErr); + +/* Reads a single file from an archive into a heap block. */ +/* If pComment is not NULL, only the file with the specified comment will be extracted. */ +/* Returns NULL on failure. */ +void *mz_zip_extract_archive_file_to_heap(const char *pZip_filename, const char *pArchive_name, size_t *pSize, mz_uint flags); +void *mz_zip_extract_archive_file_to_heap_v2(const char *pZip_filename, const char *pArchive_name, const char *pComment, size_t *pSize, mz_uint flags, mz_zip_error *pErr); + +#endif /* #ifndef MINIZ_NO_ARCHIVE_WRITING_APIS */ + +#endif /* MINIZ_NO_ARCHIVE_APIS */ diff --git a/xs/src/perlglue.cpp b/xs/src/perlglue.cpp index 5f3b5f691..cb2ef7368 100644 --- a/xs/src/perlglue.cpp +++ b/xs/src/perlglue.cpp @@ -63,6 +63,7 @@ REGISTER_CLASS(Preset, "GUI::Preset"); REGISTER_CLASS(PresetCollection, "GUI::PresetCollection"); REGISTER_CLASS(PresetBundle, "GUI::PresetBundle"); REGISTER_CLASS(PresetHints, "GUI::PresetHints"); +REGISTER_CLASS(TabIface, "GUI::Tab"); SV* ConfigBase__as_hash(ConfigBase* THIS) { diff --git a/xs/src/slic3r/GUI/2DBed.cpp b/xs/src/slic3r/GUI/2DBed.cpp new file mode 100644 index 000000000..c5d68400d --- /dev/null +++ b/xs/src/slic3r/GUI/2DBed.cpp @@ -0,0 +1,189 @@ +#include "2DBed.hpp"; + +#include +#include "BoundingBox.hpp" +#include "Geometry.hpp" +#include "ClipperUtils.hpp" + +namespace Slic3r { +namespace GUI { + +void Bed_2D::repaint() +{ + wxAutoBufferedPaintDC dc(this); + auto cw = GetSize().GetWidth(); + auto ch = GetSize().GetHeight(); + // when canvas is not rendered yet, size is 0, 0 + if (cw == 0) return ; + + if (m_user_drawn_background) { + // On all systems the AutoBufferedPaintDC() achieves double buffering. + // On MacOS the background is erased, on Windows the background is not erased + // and on Linux / GTK the background is erased to gray color. + // Fill DC with the background on Windows & Linux / GTK. + auto color = wxSystemSettings::GetColour(wxSYS_COLOUR_3DLIGHT); //GetSystemColour + dc.SetPen(*new wxPen(color, 1, wxPENSTYLE_SOLID)); + dc.SetBrush(*new wxBrush(color, wxBRUSHSTYLE_SOLID)); + auto rect = GetUpdateRegion().GetBox(); + dc.DrawRectangle(rect.GetLeft(), rect.GetTop(), rect.GetWidth(), rect.GetHeight()); + } + + // turn cw and ch from sizes to max coordinates + cw--; + ch--; + + auto cbb = BoundingBoxf(Pointf(0, 0),Pointf(cw, ch)); + // leave space for origin point + cbb.min.translate(4, 0); + cbb.max.translate(-4, -4); + + // leave space for origin label + cbb.max.translate(0, -13); + + // read new size + cw = cbb.size().x; + ch = cbb.size().y; + + auto ccenter = cbb.center(); + + // get bounding box of bed shape in G - code coordinates + auto bed_shape = m_bed_shape; + auto bed_polygon = Polygon::new_scale(m_bed_shape); + auto bb = BoundingBoxf(m_bed_shape); + bb.merge(Pointf(0, 0)); // origin needs to be in the visible area + auto bw = bb.size().x; + auto bh = bb.size().y; + auto bcenter = bb.center(); + + // calculate the scaling factor for fitting bed shape in canvas area + auto sfactor = std::min(cw/bw, ch/bh); + auto shift = Pointf( + ccenter.x - bcenter.x * sfactor, + ccenter.y - bcenter.y * sfactor + ); + m_scale_factor = sfactor; + m_shift = Pointf(shift.x + cbb.min.x, + shift.y - (cbb.max.y - GetSize().GetHeight())); + + // draw bed fill + dc.SetBrush(*new wxBrush(*new wxColour(255, 255, 255), wxSOLID)); + wxPointList pt_list; + for (auto pt: m_bed_shape) + { + Point pt_pix = to_pixels(pt); + pt_list.push_back(new wxPoint(pt_pix.x, pt_pix.y)); + } + dc.DrawPolygon(&pt_list, 0, 0); + + // draw grid + auto step = 10; // 1cm grid + Polylines polylines; + for (auto x = bb.min.x - fmod(bb.min.x, step) + step; x < bb.max.x; x += step) { + Polyline pl = Polyline::new_scale({ Pointf(x, bb.min.y), Pointf(x, bb.max.y) }); + polylines.push_back(pl); + } + for (auto y = bb.min.y - fmod(bb.min.y, step) + step; y < bb.max.y; y += step) { + polylines.push_back(Polyline::new_scale({ Pointf(bb.min.x, y), Pointf(bb.max.x, y) })); + } + polylines = intersection_pl(polylines, bed_polygon); + + dc.SetPen(*new wxPen(*new wxColour(230, 230, 230), 1, wxSOLID)); + for (auto pl : polylines) + { + for (size_t i = 0; i < pl.points.size()-1; i++){ + Point pt1 = to_pixels(Pointf::new_unscale(pl.points[i])); + Point pt2 = to_pixels(Pointf::new_unscale(pl.points[i+1])); + dc.DrawLine(pt1.x, pt1.y, pt2.x, pt2.y); + } + } + + // draw bed contour + dc.SetPen(*new wxPen(*new wxColour(0, 0, 0), 1, wxSOLID)); + dc.SetBrush(*new wxBrush(*new wxColour(0, 0, 0), wxTRANSPARENT)); + dc.DrawPolygon(&pt_list, 0, 0); + + auto origin_px = to_pixels(Pointf(0, 0)); + + // draw axes + auto axes_len = 50; + auto arrow_len = 6; + auto arrow_angle = Geometry::deg2rad(45.0); + dc.SetPen(*new wxPen(*new wxColour(255, 0, 0), 2, wxSOLID)); // red + auto x_end = Pointf(origin_px.x + axes_len, origin_px.y); + dc.DrawLine(wxPoint(origin_px.x, origin_px.y), wxPoint(x_end.x, x_end.y)); + for (auto angle : { -arrow_angle, arrow_angle }){ + auto end = x_end; + end.translate(-arrow_len, 0); + end.rotate(angle, x_end); + dc.DrawLine(wxPoint(x_end.x, x_end.y), wxPoint(end.x, end.y)); + } + + dc.SetPen(*new wxPen(*new wxColour(0, 255, 0), 2, wxSOLID)); // green + auto y_end = Pointf(origin_px.x, origin_px.y - axes_len); + dc.DrawLine(wxPoint(origin_px.x, origin_px.y), wxPoint(y_end.x, y_end.y)); + for (auto angle : { -arrow_angle, arrow_angle }) { + auto end = y_end; + end.translate(0, +arrow_len); + end.rotate(angle, y_end); + dc.DrawLine(wxPoint(y_end.x, y_end.y), wxPoint(end.x, end.y)); + } + + // draw origin + dc.SetPen(*new wxPen(*new wxColour(0, 0, 0), 1, wxSOLID)); + dc.SetBrush(*new wxBrush(*new wxColour(0, 0, 0), wxSOLID)); + dc.DrawCircle(origin_px.x, origin_px.y, 3); + + dc.SetTextForeground(*new wxColour(0, 0, 0)); + dc.SetFont(*new wxFont(10, wxDEFAULT, wxNORMAL, wxNORMAL)); + dc.DrawText("(0,0)", origin_px.x + 1, origin_px.y + 2); + + // draw current position + if (m_pos!= Pointf(0, 0)) { + auto pos_px = to_pixels(m_pos); + dc.SetPen(*new wxPen(*new wxColour(200, 0, 0), 2, wxSOLID)); + dc.SetBrush(*new wxBrush(*new wxColour(200, 0, 0), wxTRANSPARENT)); + dc.DrawCircle(pos_px.x, pos_px.y, 5); + + dc.DrawLine(pos_px.x - 15, pos_px.y, pos_px.x + 15, pos_px.y); + dc.DrawLine(pos_px.x, pos_px.y - 15, pos_px.x, pos_px.y + 15); + } + + m_painted = true; +} + +// convert G - code coordinates into pixels +Point Bed_2D::to_pixels(Pointf point){ + auto p = Pointf(point); + p.scale(m_scale_factor); + p.translate(m_shift); + return Point(p.x, GetSize().GetHeight() - p.y); +} + +void Bed_2D::mouse_event(wxMouseEvent event){ + if (!m_interactive) return; + if (!m_painted) return; + + auto pos = event.GetPosition(); + auto point = to_units(Point(pos.x, pos.y)); + if (event.LeftDown() || event.Dragging()) { + if (m_on_move) + m_on_move(point) ; + Refresh(); + } +} + +// convert pixels into G - code coordinates +Pointf Bed_2D::to_units(Point point){ + auto p = Pointf(point.x, GetSize().GetHeight() - point.y); + p.translate(m_shift.negative()); + p.scale(1 / m_scale_factor); + return p; +} + +void Bed_2D::set_pos(Pointf pos){ + m_pos = pos; + Refresh(); +} + +} // GUI +} // Slic3r \ No newline at end of file diff --git a/xs/src/slic3r/GUI/2DBed.hpp b/xs/src/slic3r/GUI/2DBed.hpp new file mode 100644 index 000000000..859417efb --- /dev/null +++ b/xs/src/slic3r/GUI/2DBed.hpp @@ -0,0 +1,45 @@ +#include +#include "Config.hpp" + +namespace Slic3r { +namespace GUI { + +class Bed_2D : public wxPanel +{ + bool m_user_drawn_background = false; + + bool m_painted = false; + bool m_interactive = false; + double m_scale_factor; + Pointf m_shift; + Pointf m_pos; + std::function m_on_move = nullptr; + + Point to_pixels(Pointf point); + Pointf to_units(Point point); + void repaint(); + void mouse_event(wxMouseEvent event); + void set_pos(Pointf pos); + +public: + Bed_2D(wxWindow* parent) + { + Create(parent, wxID_ANY, wxDefaultPosition, wxSize(250, -1), wxTAB_TRAVERSAL); +// m_user_drawn_background = $^O ne 'darwin'; + m_user_drawn_background = true; + Bind(wxEVT_PAINT, ([this](wxPaintEvent e) { repaint(); })); +// EVT_ERASE_BACKGROUND($self, sub{}) if $self->{user_drawn_background}; +// Bind(EVT_MOUSE_EVENTS, ([this](wxMouseEvent event){/*mouse_event()*/; })); + Bind(wxEVT_LEFT_DOWN, ([this](wxMouseEvent event){ mouse_event(event); })); + Bind(wxEVT_MOTION, ([this](wxMouseEvent event){ mouse_event(event); })); + Bind(wxEVT_SIZE, ([this](wxSizeEvent e) { Refresh(); })); + } + ~Bed_2D(){} + + std::vector m_bed_shape; + +}; + + +} // GUI +} // Slic3r diff --git a/xs/src/slic3r/GUI/3DScene.cpp b/xs/src/slic3r/GUI/3DScene.cpp index 616d43496..3deadd105 100644 --- a/xs/src/slic3r/GUI/3DScene.cpp +++ b/xs/src/slic3r/GUI/3DScene.cpp @@ -1117,21 +1117,12 @@ const unsigned char _3DScene::LegendTexture::Squares_Border_Color[3] = { 64, 64, const unsigned char _3DScene::LegendTexture::Background_Color[3] = { 9, 91, 134 }; const unsigned char _3DScene::LegendTexture::Opacity = 255; -_3DScene::LegendTexture::LegendTexture() - : m_tex_id(0) - , m_tex_width(0) - , m_tex_height(0) +// Generate a texture data, but don't load it into the GPU yet, as the GPU context may not yet be valid. +bool _3DScene::LegendTexture::generate(const GCodePreviewData& preview_data, const std::vector& tool_colors) { -} - -_3DScene::LegendTexture::~LegendTexture() -{ - _destroy_texture(); -} - -bool _3DScene::LegendTexture::generate_texture(const GCodePreviewData& preview_data, const std::vector& tool_colors) -{ - _destroy_texture(); + // Mark the texture as released, but don't release the texture from the GPU yet. + m_tex_width = m_tex_height = 0; + m_data.clear(); // collects items to render const std::string& title = preview_data.get_legend_title(); @@ -1241,64 +1232,45 @@ bool _3DScene::LegendTexture::generate_texture(const GCodePreviewData& preview_d memDC.SelectObject(wxNullBitmap); - return _create_texture(preview_data, bitmap); -} - -unsigned int _3DScene::LegendTexture::get_texture_id() const -{ - return m_tex_id; -} - -unsigned int _3DScene::LegendTexture::get_texture_width() const -{ - return m_tex_width; -} - -unsigned int _3DScene::LegendTexture::get_texture_height() const -{ - return m_tex_height; -} - -void _3DScene::LegendTexture::reset_texture() -{ - _destroy_texture(); -} - -bool _3DScene::LegendTexture::_create_texture(const GCodePreviewData& preview_data, const wxBitmap& bitmap) -{ - if ((m_tex_width == 0) || (m_tex_height == 0)) - return false; - - wxImage image = bitmap.ConvertToImage(); - image.SetMaskColour(Background_Color[0], Background_Color[1], Background_Color[2]); - - // prepare buffer - std::vector buffer(4 * m_tex_width * m_tex_height, 0); - for (unsigned int h = 0; h < m_tex_height; ++h) + // Convert the bitmap into a linear data ready to be loaded into the GPU. { - unsigned int hh = h * m_tex_width; - for (unsigned int w = 0; w < m_tex_width; ++w) + wxImage image = bitmap.ConvertToImage(); + image.SetMaskColour(Background_Color[0], Background_Color[1], Background_Color[2]); + + // prepare buffer + m_data.assign(4 * m_tex_width * m_tex_height, 0); + for (unsigned int h = 0; h < m_tex_height; ++h) { - unsigned char* px_ptr = buffer.data() + 4 * (hh + w); - *px_ptr++ = image.GetRed(w, h); - *px_ptr++ = image.GetGreen(w, h); - *px_ptr++ = image.GetBlue(w, h); - *px_ptr++ = image.IsTransparent(w, h) ? 0 : Opacity; + unsigned int hh = h * m_tex_width; + unsigned char* px_ptr = m_data.data() + 4 * hh; + for (unsigned int w = 0; w < m_tex_width; ++w) + { + *px_ptr++ = image.GetRed(w, h); + *px_ptr++ = image.GetGreen(w, h); + *px_ptr++ = image.GetBlue(w, h); + *px_ptr++ = image.IsTransparent(w, h) ? 0 : Opacity; + } } } - - // sends buffer to gpu - ::glGenTextures(1, &m_tex_id); - ::glBindTexture(GL_TEXTURE_2D, m_tex_id); - ::glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, (GLsizei)m_tex_width, (GLsizei)m_tex_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, (const GLvoid*)buffer.data()); - ::glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - ::glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - ::glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 1); - ::glBindTexture(GL_TEXTURE_2D, 0); - return true; } +unsigned int _3DScene::LegendTexture::finalize() +{ + if (! m_data.empty()) { + // sends buffer to gpu + ::glGenTextures(1, &m_tex_id); + ::glBindTexture(GL_TEXTURE_2D, m_tex_id); + ::glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, (GLsizei)m_tex_width, (GLsizei)m_tex_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, (const GLvoid*)m_data.data()); + ::glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + ::glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + ::glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 1); + ::glBindTexture(GL_TEXTURE_2D, 0); + m_data.clear(); + } + return (m_tex_width > 0 && m_tex_height > 0) ? m_tex_id : 0; +} + void _3DScene::LegendTexture::_destroy_texture() { if (m_tex_id > 0) @@ -1308,6 +1280,7 @@ void _3DScene::LegendTexture::_destroy_texture() m_tex_height = 0; m_tex_width = 0; } + m_data.clear(); } void _3DScene::_glew_init() @@ -2267,7 +2240,12 @@ void _3DScene::_update_gcode_volumes_visibility(const GCodePreviewData& preview_ void _3DScene::_generate_legend_texture(const GCodePreviewData& preview_data, const std::vector& tool_colors) { - s_legend_texture.generate_texture(preview_data, tool_colors); + s_legend_texture.generate(preview_data, tool_colors); +} + +unsigned int _3DScene::finalize_legend_texture() +{ + return s_legend_texture.finalize(); } void _3DScene::_load_shells(const Print& print, GLVolumeCollection& volumes, bool use_VBOs) diff --git a/xs/src/slic3r/GUI/3DScene.hpp b/xs/src/slic3r/GUI/3DScene.hpp index bf3515ac5..9cbcb6ebc 100644 --- a/xs/src/slic3r/GUI/3DScene.hpp +++ b/xs/src/slic3r/GUI/3DScene.hpp @@ -421,20 +421,25 @@ class _3DScene unsigned int m_tex_height; public: - LegendTexture(); - ~LegendTexture(); + LegendTexture() : m_tex_id(0), m_tex_width(0), m_tex_height(0) {} + ~LegendTexture() { _destroy_texture(); } - bool generate_texture(const GCodePreviewData& preview_data, const std::vector& tool_colors); + // Generate a texture data, but don't load it into the GPU yet, as the glcontext may not be valid yet. + bool generate(const GCodePreviewData& preview_data, const std::vector& tool_colors); + // If not loaded, load the texture data into the GPU. Return a texture ID or 0 if the texture has zero size. + unsigned int finalize(); - unsigned int get_texture_id() const; - unsigned int get_texture_width() const; - unsigned int get_texture_height() const; + unsigned int get_texture_id() const { return m_tex_id; } + unsigned int get_texture_width() const { return m_tex_width; } + unsigned int get_texture_height() const { return m_tex_height; } - void reset_texture(); + void reset_texture() { _destroy_texture(); } private: bool _create_texture(const GCodePreviewData& preview_data, const wxBitmap& bitmap); void _destroy_texture(); + // generate() fills in m_data with the pixels, while finalize() moves the data to the GPU before rendering. + std::vector m_data; }; static LegendTexture s_legend_texture; @@ -449,6 +454,7 @@ public: static unsigned int get_legend_texture_height(); static void reset_legend_texture(); + static unsigned int finalize_legend_texture(); static void _load_print_toolpaths( const Print *print, diff --git a/xs/src/slic3r/GUI/BedShapeDialog.cpp b/xs/src/slic3r/GUI/BedShapeDialog.cpp new file mode 100644 index 000000000..5ee0c1f8b --- /dev/null +++ b/xs/src/slic3r/GUI/BedShapeDialog.cpp @@ -0,0 +1,341 @@ +#include "BedShapeDialog.hpp" + +#include +#include +#include +#include "Polygon.hpp" +#include "BoundingBox.hpp" +#include +#include "Model.hpp" +#include "boost/nowide/iostream.hpp" + +namespace Slic3r { +namespace GUI { + +void BedShapeDialog::build_dialog(ConfigOptionPoints* default_pt) +{ + m_panel = new BedShapePanel(this); + m_panel->build_panel(default_pt); + + auto main_sizer = new wxBoxSizer(wxVERTICAL); + main_sizer->Add(m_panel, 1, wxEXPAND); + main_sizer->Add(CreateButtonSizer(wxOK | wxCANCEL), 0, wxALIGN_CENTER_HORIZONTAL | wxBOTTOM, 10); + + SetSizer(main_sizer); + SetMinSize(GetSize()); + main_sizer->SetSizeHints(this); + + // needed to actually free memory + this->Bind(wxEVT_CLOSE_WINDOW, ([this](wxCloseEvent e){ + EndModal(wxID_OK); + Destroy(); + })); +} + +void BedShapePanel::build_panel(ConfigOptionPoints* default_pt) +{ +// on_change(nullptr); + + auto box = new wxStaticBox(this, wxID_ANY, _L("Shape")); + auto sbsizer = new wxStaticBoxSizer(box, wxVERTICAL); + + // shape options + m_shape_options_book = new wxChoicebook(this, wxID_ANY, wxDefaultPosition, wxSize(300, -1), wxCHB_TOP); + sbsizer->Add(m_shape_options_book); + + auto optgroup = init_shape_options_page(_L("Rectangular")); + ConfigOptionDef def; + def.type = coPoints; + def.default_value = new ConfigOptionPoints{ Pointf(200, 200) }; + def.label = _LU8("Size"); + def.tooltip = _LU8("Size in X and Y of the rectangular plate."); + Option option(def, "rect_size"); + optgroup->append_single_option_line(option); + + def.type = coPoints; + def.default_value = new ConfigOptionPoints{ Pointf(0, 0) }; + def.label = _LU8("Origin"); + def.tooltip = _LU8("Distance of the 0,0 G-code coordinate from the front left corner of the rectangle."); + option = Option(def, "rect_origin"); + optgroup->append_single_option_line(option); + + optgroup = init_shape_options_page(_L("Circular")); + def.type = coFloat; + def.default_value = new ConfigOptionFloat(200); + def.sidetext = _LU8("mm"); + def.label = _LU8("Diameter"); + def.tooltip = _LU8("Diameter of the print bed. It is assumed that origin (0,0) is located in the center."); + option = Option(def, "diameter"); + optgroup->append_single_option_line(option); + + optgroup = init_shape_options_page(_L("Custom")); + Line line{ "", "" }; + line.full_width = 1; + line.widget = [this](wxWindow* parent) { + auto btn = new wxButton(parent, wxID_ANY, _L("Load shape from STL..."), wxDefaultPosition, wxDefaultSize); + + auto sizer = new wxBoxSizer(wxHORIZONTAL); + sizer->Add(btn); + + btn->Bind(wxEVT_BUTTON, ([this](wxCommandEvent e) + { + load_stl(); + })); + + return sizer; + }; + optgroup->append_line(line); + + Bind(wxEVT_CHOICEBOOK_PAGE_CHANGED, ([this](wxCommandEvent e) + { + update_shape(); + })); + + // right pane with preview canvas + m_canvas = new Bed_2D(this); + m_canvas->m_bed_shape = default_pt->values; + + // main sizer + auto top_sizer = new wxBoxSizer(wxHORIZONTAL); + top_sizer->Add(sbsizer, 0, wxEXPAND | wxLeft | wxTOP | wxBOTTOM, 10); + if (m_canvas) + top_sizer->Add(m_canvas, 1, wxEXPAND | wxALL, 10) ; + + SetSizerAndFit(top_sizer); + + set_shape(default_pt); + update_preview(); +} + +#define SHAPE_RECTANGULAR 0 +#define SHAPE_CIRCULAR 1 +#define SHAPE_CUSTOM 2 + +// Called from the constructor. +// Create a panel for a rectangular / circular / custom bed shape. +ConfigOptionsGroupShp BedShapePanel::init_shape_options_page(wxString title){ + + auto panel = new wxPanel(m_shape_options_book); + ConfigOptionsGroupShp optgroup; + optgroup = std::make_shared(panel, _L("Settings")); + + optgroup->label_width = 100; + optgroup->m_on_change = [this](t_config_option_key opt_key, boost::any value){ + update_shape(); + }; + + m_optgroups.push_back(optgroup); + panel->SetSizerAndFit(optgroup->sizer); + m_shape_options_book->AddPage(panel, title); + + return optgroup; +} + +// Called from the constructor. +// Set the initial bed shape from a list of points. +// Deduce the bed shape type(rect, circle, custom) +// This routine shall be smart enough if the user messes up +// with the list of points in the ini file directly. +void BedShapePanel::set_shape(ConfigOptionPoints* points) +{ + auto polygon = Polygon::new_scale(points->values); + + // is this a rectangle ? + if (points->size() == 4) { + auto lines = polygon.lines(); + if (lines[0].parallel_to(lines[2]) && lines[1].parallel_to(lines[3])) { + // okay, it's a rectangle + // find origin + // the || 0 hack prevents "-0" which might confuse the user + int x_min, x_max, y_min, y_max; + x_max = x_min = points->values[0].x; + y_max = y_min = points->values[0].y; + for (auto pt : points->values){ + if (x_min > pt.x) x_min = pt.x; + if (x_max < pt.x) x_max = pt.x; + if (y_min > pt.y) y_min = pt.y; + if (y_max < pt.y) y_max = pt.y; + } + if (x_min < 0) x_min = 0; + if (x_max < 0) x_max = 0; + if (y_min < 0) y_min = 0; + if (y_max < 0) y_max = 0; + auto origin = new ConfigOptionPoints{ Pointf(-x_min, -y_min) }; + + m_shape_options_book->SetSelection(SHAPE_RECTANGULAR); + auto optgroup = m_optgroups[SHAPE_RECTANGULAR]; + optgroup->set_value("rect_size", new ConfigOptionPoints{ Pointf(x_max - x_min, y_max - y_min) });//[x_max - x_min, y_max - y_min]); + optgroup->set_value("rect_origin", origin); + update_shape(); + return; + } + } + + // is this a circle ? + { + // Analyze the array of points.Do they reside on a circle ? + auto center = polygon.bounding_box().center(); + std::vector vertex_distances; + double avg_dist = 0; + for (auto pt: polygon.points) + { + double distance = center.distance_to(pt); + vertex_distances.push_back(distance); + avg_dist += distance; + } + + bool defined_value = true; + for (auto el: vertex_distances) + { + if (abs(el - avg_dist) > 10 * SCALED_EPSILON) + defined_value = false; + break; + } + if (defined_value) { + // all vertices are equidistant to center + m_shape_options_book->SetSelection(SHAPE_CIRCULAR); + auto optgroup = m_optgroups[SHAPE_CIRCULAR]; + boost::any ret = wxNumberFormatter::ToString(unscale(avg_dist * 2), 0); + optgroup->set_value("diameter", ret); + update_shape(); + return; + } + } + + if (points->size() < 3) { + // Invalid polygon.Revert to default bed dimensions. + m_shape_options_book->SetSelection(SHAPE_RECTANGULAR); + auto optgroup = m_optgroups[SHAPE_RECTANGULAR]; + optgroup->set_value("rect_size", new ConfigOptionPoints{ Pointf(200, 200) }); + optgroup->set_value("rect_origin", new ConfigOptionPoints{ Pointf(0, 0) }); + update_shape(); + return; + } + + // This is a custom bed shape, use the polygon provided. + m_shape_options_book->SetSelection(SHAPE_CUSTOM); + // Copy the polygon to the canvas, make a copy of the array. + m_canvas->m_bed_shape = points->values; + update_shape(); +} + +void BedShapePanel::update_preview() +{ + if (m_canvas) m_canvas->Refresh(); + Refresh(); +} + +// Update the bed shape from the dialog fields. +void BedShapePanel::update_shape() +{ + auto page_idx = m_shape_options_book->GetSelection(); + if (page_idx == SHAPE_RECTANGULAR) { + Pointf rect_size, rect_origin; + try{ + rect_size = boost::any_cast(m_optgroups[SHAPE_RECTANGULAR]->get_value("rect_size")); } + catch (const std::exception &e){ + return;} + try{ + rect_origin = boost::any_cast(m_optgroups[SHAPE_RECTANGULAR]->get_value("rect_origin")); + } + catch (const std::exception &e){ + return;} + + auto x = rect_size.x; + auto y = rect_size.y; + // empty strings or '-' or other things + if (x == 0 || y == 0) return; + double x0 = 0.0; + double y0 = 0.0; + double x1 = x; + double y1 = y; + + auto dx = rect_origin.x; + auto dy = rect_origin.y; + + x0 -= dx; + x1 -= dx; + y0 -= dy; + y1 -= dy; + m_canvas->m_bed_shape = { Pointf(x0, y0), + Pointf(x1, y0), + Pointf(x1, y1), + Pointf(x0, y1)}; + } + else if(page_idx == SHAPE_CIRCULAR) { + double diameter; + try{ + diameter = boost::any_cast(m_optgroups[SHAPE_CIRCULAR]->get_value("diameter")); + } + catch (const std::exception &e){ + return; + } + if (diameter == 0.0) return ; + auto r = diameter / 2; + auto twopi = 2 * PI; + auto edges = 60; + std::vector points; + for (size_t i = 1; i <= 60; ++i){ + auto angle = i * twopi / edges; + points.push_back(Pointf(r*cos(angle), r*sin(angle))); + } + m_canvas->m_bed_shape = points; + } + +// $self->{on_change}->(); + update_preview(); +} + +// Loads an stl file, projects it to the XY plane and calculates a polygon. +void BedShapePanel::load_stl() +{ + t_file_wild_card vec_FILE_WILDCARDS = get_file_wild_card(); + std::vector file_types = { "known", "stl", "obj", "amf", "prusa"}; + wxString MODEL_WILDCARD; + for (auto file_type: file_types) + MODEL_WILDCARD += vec_FILE_WILDCARDS.at(file_type) + "|"; + + auto dialog = new wxFileDialog(this, _L("Choose a file to import bed shape from (STL/OBJ/AMF/PRUSA):"), "", "", + MODEL_WILDCARD, wxFD_OPEN | wxFD_FILE_MUST_EXIST); + if (dialog->ShowModal() != wxID_OK) { + dialog->Destroy(); + return; + } + wxArrayString input_file; + dialog->GetPaths(input_file); + dialog->Destroy(); + + std::string file_name = input_file[0].ToStdString(); + + Model model; + try { + model = Model::read_from_file(file_name); + } + catch (std::exception &e) { + auto msg = _L("Error! ") + file_name + " : " + e.what() + "."; + show_error(this, msg); + exit(1); + } + + auto mesh = model.mesh(); + auto expolygons = mesh.horizontal_projection(); + + if (expolygons.size() == 0) { + show_error(this, _L("The selected file contains no geometry.")); + return; + } + if (expolygons.size() > 1) { + show_error(this, _L("The selected file contains several disjoint areas. This is not supported.")); + return; + } + + auto polygon = expolygons[0].contour; + std::vector points; + for (auto pt : polygon.points) + points.push_back(Pointf::new_unscale(pt)); + m_canvas->m_bed_shape = points; + update_preview(); +} + +} // GUI +} // Slic3r diff --git a/xs/src/slic3r/GUI/BedShapeDialog.hpp b/xs/src/slic3r/GUI/BedShapeDialog.hpp new file mode 100644 index 000000000..81b0a41e3 --- /dev/null +++ b/xs/src/slic3r/GUI/BedShapeDialog.hpp @@ -0,0 +1,51 @@ +// The bed shape dialog. +// The dialog opens from Print Settins tab->Bed Shape : Set... + +#include "OptionsGroup.hpp" +#include "2DBed.hpp" + + +#include +#include + +namespace Slic3r { +namespace GUI { + +using ConfigOptionsGroupShp = std::shared_ptr; +class BedShapePanel : public wxPanel +{ + wxChoicebook* m_shape_options_book; + Bed_2D* m_canvas; + + std::vector m_optgroups; + +public: + BedShapePanel(wxWindow* parent) : wxPanel(parent, wxID_ANY){} + ~BedShapePanel(){} + + void build_panel(ConfigOptionPoints* default_pt); + + ConfigOptionsGroupShp init_shape_options_page(wxString title); + void set_shape(ConfigOptionPoints* points); + void update_preview(); + void update_shape(); + void load_stl(); + + // Returns the resulting bed shape polygon. This value will be stored to the ini file. + std::vector GetValue() { return m_canvas->m_bed_shape; } +}; + +class BedShapeDialog : public wxDialog +{ + BedShapePanel* m_panel; +public: + BedShapeDialog(wxWindow* parent) : wxDialog(parent, wxID_ANY, _L("Bed Shape"), + wxDefaultPosition, wxSize(350, 700), wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER){} + ~BedShapeDialog(){ } + + void build_dialog(ConfigOptionPoints* default_pt); + std::vector GetValue() { return m_panel->GetValue(); } +}; + +} // GUI +} // Slic3r diff --git a/xs/src/slic3r/GUI/ConfigExceptions.hpp b/xs/src/slic3r/GUI/ConfigExceptions.hpp new file mode 100644 index 000000000..9038d3445 --- /dev/null +++ b/xs/src/slic3r/GUI/ConfigExceptions.hpp @@ -0,0 +1,15 @@ +#include +namespace Slic3r { + +class ConfigError : public std::runtime_error { +using std::runtime_error::runtime_error; +}; + +namespace GUI { + +class ConfigGUITypeError : public ConfigError { +using ConfigError::ConfigError; +}; +} + +} diff --git a/xs/src/slic3r/GUI/Field.cpp b/xs/src/slic3r/GUI/Field.cpp new file mode 100644 index 000000000..330af6d0a --- /dev/null +++ b/xs/src/slic3r/GUI/Field.cpp @@ -0,0 +1,570 @@ +#include "GUI.hpp"//"slic3r_gui.hpp" +#include "Field.hpp" + +//#include +#include +#include +#include +#include "PrintConfig.hpp" +#include + +namespace Slic3r { namespace GUI { + + void Field::on_kill_focus(wxEvent& event) { + // Without this, there will be nasty focus bugs on Windows. + // Also, docs for wxEvent::Skip() say "In general, it is recommended to skip all + // non-command events to allow the default handling to take place." + event.Skip(); + std::cerr << "calling Field::on_kill_focus from " << m_opt_id<< "\n"; + // call the registered function if it is available + if (m_on_kill_focus!=nullptr) + m_on_kill_focus(); + } + void Field::on_change_field() + { +// std::cerr << "calling Field::_on_change \n"; + if (m_on_change != nullptr && !m_disable_change_event) + m_on_change(m_opt_id, get_value()); + } + + wxString Field::get_tooltip_text(const wxString& default_string) + { + wxString tooltip_text(""); + wxString tooltip = wxString::FromUTF8(m_opt.tooltip.c_str()); + if (tooltip.length() > 0) + tooltip_text = tooltip + "(" + _L("default") + ": " + + (boost::iends_with(m_opt_id, "_gcode") ? "\n" : "") + + default_string + ")"; + + return tooltip_text; + } + + bool Field::is_matched(std::string string, std::string pattern) + { + std::regex regex_pattern(pattern, std::regex_constants::icase); // use ::icase to make the matching case insensitive like /i in perl + return std::regex_match(string, regex_pattern); + } + + boost::any Field::get_value_by_opt_type(wxString str, ConfigOptionType type) + { + boost::any ret_val; + switch (m_opt.type){ + case coInt: + ret_val = wxAtoi(str); + break; + case coPercent: + case coPercents: + case coFloats: + case coFloat:{ + if (m_opt.type == coPercent) str.RemoveLast(); + double val; + str.ToCDouble(&val); + ret_val = val; + break; } + case coString: + case coStrings: + ret_val = str.ToStdString(); + break; + case coFloatOrPercent:{ + if (str.Last() == '%') + str.RemoveLast(); + double val; + str.ToCDouble(&val); + ret_val = val; + break; + } + default: + break; + } + + return ret_val; + } + + void TextCtrl::BUILD() { + auto size = wxSize(wxDefaultSize); + if (m_opt.height >= 0) size.SetHeight(m_opt.height); + if (m_opt.width >= 0) size.SetWidth(m_opt.width); + + wxString text_value = wxString(""); + + switch (m_opt.type) { + case coFloatOrPercent: + { + if (static_cast(m_opt.default_value)->percent) + { + text_value = wxString::Format(_T("%i"), int(m_opt.default_value->getFloat())); + text_value += "%"; + } + else + text_value = wxNumberFormatter::ToString(m_opt.default_value->getFloat(), 2); + break; + } + case coPercent: + { + text_value = wxString::Format(_T("%i"), int(m_opt.default_value->getFloat())); + text_value += "%"; + break; + } + case coPercents: + { + const ConfigOptionPercents *vec = static_cast(m_opt.default_value); + if (vec == nullptr || vec->empty()) break; + if (vec->size() > 1) + break; + double val = vec->get_at(0); + text_value = val - int(val) == 0 ? wxString::Format(_T("%i"), int(val)) : wxNumberFormatter::ToString(val, 2, wxNumberFormatter::Style_None); + break; + } + case coFloat: + { + double val = m_opt.default_value->getFloat(); + text_value = (val - int(val)) == 0 ? wxString::Format(_T("%i"), int(val)) : wxNumberFormatter::ToString(val, 2, wxNumberFormatter::Style_None); + break; + } + case coFloats: + { + const ConfigOptionFloats *vec = static_cast(m_opt.default_value); + if (vec == nullptr || vec->empty()) break; + if (vec->size() > 1) + break; + double val = vec->get_at(0); + text_value = val - int(val) == 0 ? wxString::Format(_T("%i"), int(val)) : wxNumberFormatter::ToString(val, 2, wxNumberFormatter::Style_None); + break; + } + case coString: + text_value = static_cast(m_opt.default_value)->value; + break; + case coStrings: + { + const ConfigOptionStrings *vec = static_cast(m_opt.default_value); + if (vec == nullptr || vec->empty()) break; + if (vec->size() > 1) + break; + text_value = vec->values.at(0); + break; + } + default: + break; + } + + auto temp = new wxTextCtrl(m_parent, wxID_ANY, text_value, wxDefaultPosition, size, (m_opt.multiline ? wxTE_MULTILINE : 0)); + + temp->SetToolTip(get_tooltip_text(text_value)); + + temp->Bind(wxEVT_LEFT_DOWN, ([temp](wxEvent& event) + { + //! to allow the default handling + event.Skip(); + //! eliminating the g-code pop up text description + temp->GetToolTip()->Enable(false); + }), temp->GetId()); + + temp->Bind(wxEVT_KILL_FOCUS, ([this, temp](wxEvent& e) + { + on_kill_focus(e); + temp->GetToolTip()->Enable(true); + }), temp->GetId()); + + temp->Bind(wxEVT_TEXT, ([this](wxCommandEvent) { on_change_field(); }), temp->GetId()); + + // recast as a wxWindow to fit the calling convention + window = dynamic_cast(temp); + } + + boost::any TextCtrl::get_value() + { + wxString ret_str = static_cast(window)->GetValue(); + boost::any ret_val = get_value_by_opt_type(ret_str, m_opt.type); + + return ret_val; + } + + void TextCtrl::enable() { dynamic_cast(window)->Enable(); dynamic_cast(window)->SetEditable(true); } + void TextCtrl::disable() { dynamic_cast(window)->Disable(); dynamic_cast(window)->SetEditable(false); } + +void CheckBox::BUILD() { + auto size = wxSize(wxDefaultSize); + if (m_opt.height >= 0) size.SetHeight(m_opt.height); + if (m_opt.width >= 0) size.SetWidth(m_opt.width); + + bool check_value = m_opt.type == coBool ? + m_opt.default_value->getBool() : m_opt.type == coBools ? + static_cast(m_opt.default_value)->values.at(0) : + false; + + auto temp = new wxCheckBox(m_parent, wxID_ANY, wxString(""), wxDefaultPosition, size); + temp->SetValue(check_value); + if (m_opt.readonly) temp->Disable(); + + temp->Bind(wxEVT_CHECKBOX, ([this](wxCommandEvent e) { on_change_field(); }), temp->GetId()); + + temp->SetToolTip(get_tooltip_text(check_value ? "true" : "false")); + + // recast as a wxWindow to fit the calling convention + window = dynamic_cast(temp); +} + +int undef_spin_val = -9999; //! Probably, It's not necessary + +void SpinCtrl::BUILD() { + auto size = wxSize(wxDefaultSize); + if (m_opt.height >= 0) size.SetHeight(m_opt.height); + if (m_opt.width >= 0) size.SetWidth(m_opt.width); + + wxString text_value = wxString(""); + int default_value = 0; + + switch (m_opt.type) { + case coInt: + default_value = m_opt.default_value->getInt(); + text_value = wxString::Format(_T("%i"), default_value); + break; + case coInts: + { + const ConfigOptionInts *vec = static_cast(m_opt.default_value); + if (vec == nullptr || vec->empty()) break; + for (size_t id = 0; id < vec->size(); ++id) + { + default_value = vec->get_at(id); + text_value += wxString::Format(_T("%i"), default_value); + } + break; + } + default: + break; + } + + auto temp = new wxSpinCtrl(m_parent, wxID_ANY, text_value, wxDefaultPosition, size, + 0, m_opt.min >0 ? m_opt.min : 0, m_opt.max < 2147483647 ? m_opt.max : 2147483647, default_value); + + temp->Bind(wxEVT_SPINCTRL, ([this](wxCommandEvent e) { tmp_value = undef_spin_val; on_change_field(); }), temp->GetId()); + temp->Bind(wxEVT_KILL_FOCUS, ([this](wxEvent& e) { tmp_value = undef_spin_val; on_kill_focus(e); }), temp->GetId()); + temp->Bind(wxEVT_TEXT, ([this](wxCommandEvent e) + { +// # On OSX / Cocoa, wxSpinCtrl::GetValue() doesn't return the new value +// # when it was changed from the text control, so the on_change callback +// # gets the old one, and on_kill_focus resets the control to the old value. +// # As a workaround, we get the new value from $event->GetString and store +// #here temporarily so that we can return it from $self->get_value + std::string value = e.GetString().utf8_str().data(); + if (is_matched(value, "^\\d+$")) + tmp_value = std::stoi(value); + on_change_field(); +// # We don't reset tmp_value here because _on_change might put callbacks +// # in the CallAfter queue, and we want the tmp value to be available from +// # them as well. + }), temp->GetId()); + + temp->SetToolTip(get_tooltip_text(text_value)); + + // recast as a wxWindow to fit the calling convention + window = dynamic_cast(temp); +} + +void Choice::BUILD() { + auto size = wxSize(wxDefaultSize); + if (m_opt.height >= 0) size.SetHeight(m_opt.height); + if (m_opt.width >= 0) size.SetWidth(m_opt.width); + + wxComboBox* temp; + if (!m_opt.gui_type.empty() && m_opt.gui_type.compare("select_open") != 0) + temp = new wxComboBox(m_parent, wxID_ANY, wxString(""), wxDefaultPosition, size); + else + temp = new wxComboBox(m_parent, wxID_ANY, wxString(""), wxDefaultPosition, size, 0, NULL, wxCB_READONLY); + + // recast as a wxWindow to fit the calling convention + window = dynamic_cast(temp); + + if (m_opt.enum_labels.empty() && m_opt.enum_values.empty()){ + } + else{ + for (auto el : m_opt.enum_labels.empty() ? m_opt.enum_values : m_opt.enum_labels) + temp->Append(wxString(el)); + set_selection(); + } + temp->Bind(wxEVT_TEXT, ([this](wxCommandEvent e) { on_change_field(); }), temp->GetId()); + temp->Bind(wxEVT_COMBOBOX, ([this](wxCommandEvent e) { on_change_field(); }), temp->GetId()); + + temp->SetToolTip(get_tooltip_text(temp->GetValue())); +} + +void Choice::set_selection() +{ + wxString text_value = wxString(""); + switch (m_opt.type){ + case coFloat: + case coPercent: { + double val = m_opt.default_value->getFloat(); + text_value = val - int(val) == 0 ? wxString::Format(_T("%i"), int(val)) : wxNumberFormatter::ToString(val, 1); + size_t idx = 0; + for (auto el : m_opt.enum_values) + { + if (el.compare(text_value) == 0) + break; + ++idx; + } + if (m_opt.type == coPercent) text_value += "%"; + idx == m_opt.enum_values.size() ? + dynamic_cast(window)->SetValue(text_value) : + dynamic_cast(window)->SetSelection(idx); + break; + } + case coEnum:{ + int id_value = static_cast*>(m_opt.default_value)->value; //!! + dynamic_cast(window)->SetSelection(id_value); + break; + } + case coInt:{ + int val = m_opt.default_value->getInt(); //!! + text_value = wxString::Format(_T("%i"), int(val)); + size_t idx = 0; + for (auto el : m_opt.enum_values) + { + if (el.compare(text_value) == 0) + break; + ++idx; + } + idx == m_opt.enum_values.size() ? + dynamic_cast(window)->SetValue(text_value) : + dynamic_cast(window)->SetSelection(idx); + break; + } + case coStrings:{ + text_value = static_cast(m_opt.default_value)->values.at(0); + + size_t idx = 0; + for (auto el : m_opt.enum_values) + { + if (el.compare(text_value) == 0) + break; + ++idx; + } + idx == m_opt.enum_values.size() ? + dynamic_cast(window)->SetValue(text_value) : + dynamic_cast(window)->SetSelection(idx); + break; + } + } +} + +void Choice::set_value(const std::string value) //! Redundant? +{ + m_disable_change_event = true; + + size_t idx=0; + for (auto el : m_opt.enum_values) + { + if (el.compare(value) == 0) + break; + ++idx; + } + + idx == m_opt.enum_values.size() ? + dynamic_cast(window)->SetValue(value) : + dynamic_cast(window)->SetSelection(idx); + + m_disable_change_event = false; +} + +void Choice::set_value(boost::any value) +{ + m_disable_change_event = true; + + switch (m_opt.type){ + case coInt: + case coFloat: + case coPercent: + case coStrings:{ + wxString text_value; + if (m_opt.type == coInt) + text_value = wxString::Format(_T("%i"), int(boost::any_cast(value))); + else + text_value = boost::any_cast(value); + auto idx = 0; + for (auto el : m_opt.enum_values) + { + if (el.compare(text_value) == 0) + break; + ++idx; + } + if (m_opt.type == coPercent) text_value += "%"; + idx == m_opt.enum_values.size() ? + dynamic_cast(window)->SetValue(text_value) : + dynamic_cast(window)->SetSelection(idx); + break; + } + case coEnum:{ + dynamic_cast(window)->SetSelection(boost::any_cast(value)); + break; + } + default: + break; + } + + m_disable_change_event = false; +} + +//! it's needed for _update_serial_ports() +void Choice::set_values(const std::vector values) +{ + if (values.empty()) + return; + m_disable_change_event = true; + +// #it looks that Clear() also clears the text field in recent wxWidgets versions, +// # but we want to preserve it + auto ww = dynamic_cast(window); + auto value = ww->GetValue(); + ww->Clear(); + for (auto el : values) + ww->Append(wxString(el)); + ww->SetValue(value); + + m_disable_change_event = false; +} + +boost::any Choice::get_value() +{ + boost::any ret_val; + wxString ret_str = static_cast(window)->GetValue(); + + if (m_opt.type != coEnum) + ret_val = get_value_by_opt_type(ret_str, m_opt.type); + else + { + int ret_enum = static_cast(window)->GetSelection(); + if (m_opt_id.compare("external_fill_pattern") == 0) + { + if (!m_opt.enum_values.empty()){ + std::string key = m_opt.enum_values[ret_enum]; + t_config_enum_values map_names = ConfigOptionEnum::get_enum_values(); + int value = map_names.at(key); + + ret_val = static_cast(value); + } + else + ret_val = static_cast(0); + } + if (m_opt_id.compare("fill_pattern") == 0) + ret_val = static_cast(ret_enum); + else if (m_opt_id.compare("gcode_flavor") == 0) + ret_val = static_cast(ret_enum); + else if (m_opt_id.compare("support_material_pattern") == 0) + ret_val = static_cast(ret_enum); + else if (m_opt_id.compare("seam_position") == 0) + ret_val = static_cast(ret_enum); + } + + return ret_val; +} + +void ColourPicker::BUILD() +{ + auto size = wxSize(wxDefaultSize); + if (m_opt.height >= 0) size.SetHeight(m_opt.height); + if (m_opt.width >= 0) size.SetWidth(m_opt.width); + + wxString clr(static_cast(m_opt.default_value)->values.at(0)); + auto temp = new wxColourPickerCtrl(m_parent, wxID_ANY, clr, wxDefaultPosition, size); + + // // recast as a wxWindow to fit the calling convention + window = dynamic_cast(temp); + + temp->Bind(wxEVT_COLOURPICKER_CHANGED, ([this](wxCommandEvent e) { on_change_field(); }), temp->GetId()); + + temp->SetToolTip(get_tooltip_text(clr)); +} + +boost::any ColourPicker::get_value(){ + boost::any ret_val; + + auto colour = static_cast(window)->GetColour(); + auto clr_str = wxString::Format(wxT("#%02X%02X%02X"), colour.Red(), colour.Green(), colour.Blue()); + ret_val = clr_str.ToStdString(); + + return ret_val; +} + +void PointCtrl::BUILD() +{ + auto size = wxSize(wxDefaultSize); + if (m_opt.height >= 0) size.SetHeight(m_opt.height); + if (m_opt.width >= 0) size.SetWidth(m_opt.width); + + auto temp = new wxBoxSizer(wxHORIZONTAL); + // $self->wxSizer($sizer); + // + wxSize field_size(40, -1); + + auto default_pt = static_cast(m_opt.default_value)->values.at(0); + double val = default_pt.x; + wxString X = val - int(val) == 0 ? wxString::Format(_T("%i"), int(val)) : wxNumberFormatter::ToString(val, 2, wxNumberFormatter::Style_None); + val = default_pt.y; + wxString Y = val - int(val) == 0 ? wxString::Format(_T("%i"), int(val)) : wxNumberFormatter::ToString(val, 2, wxNumberFormatter::Style_None); + + x_textctrl = new wxTextCtrl(m_parent, wxID_ANY, X, wxDefaultPosition, field_size); + y_textctrl = new wxTextCtrl(m_parent, wxID_ANY, Y, wxDefaultPosition, field_size); + + temp->Add(new wxStaticText(m_parent, wxID_ANY, "x : "), 0, wxALIGN_CENTER_VERTICAL, 0); + temp->Add(x_textctrl); + temp->Add(new wxStaticText(m_parent, wxID_ANY, " y : "), 0, wxALIGN_CENTER_VERTICAL, 0); + temp->Add(y_textctrl); + + x_textctrl->Bind(wxEVT_TEXT, ([this](wxCommandEvent e) { on_change_field(); }), x_textctrl->GetId()); + y_textctrl->Bind(wxEVT_TEXT, ([this](wxCommandEvent e) { on_change_field(); }), y_textctrl->GetId()); + + // // recast as a wxWindow to fit the calling convention + sizer = dynamic_cast(temp); + + x_textctrl->SetToolTip(get_tooltip_text(X+", "+Y)); + y_textctrl->SetToolTip(get_tooltip_text(X+", "+Y)); +} + +void PointCtrl::set_value(const Pointf value) +{ + m_disable_change_event = true; + + double val = value.x; + x_textctrl->SetValue(val - int(val) == 0 ? wxString::Format(_T("%i"), int(val)) : wxNumberFormatter::ToString(val, 2, wxNumberFormatter::Style_None)); + val = value.y; + y_textctrl->SetValue(val - int(val) == 0 ? wxString::Format(_T("%i"), int(val)) : wxNumberFormatter::ToString(val, 2, wxNumberFormatter::Style_None)); + + m_disable_change_event = false; +} + +void PointCtrl::set_value(boost::any value) +{ + Pointf pt; + try + { + pt = boost::any_cast(value)->values.at(0); + } + catch (const std::exception &e) + { + try{ + pt = boost::any_cast(value); + } + catch (const std::exception &e) + { + std::cerr << "Error! Can't cast PointCtrl value" << m_opt_id << "\n"; + return; + } + } + set_value(pt); +} + +boost::any PointCtrl::get_value() +{ + Pointf ret_point; + double val; + x_textctrl->GetValue().ToDouble(&val); + ret_point.x = val; + y_textctrl->GetValue().ToDouble(&val); + ret_point.y = val; + return ret_point; +} + +} // GUI +} // Slic3r + + diff --git a/xs/src/slic3r/GUI/Field.hpp b/xs/src/slic3r/GUI/Field.hpp new file mode 100644 index 000000000..93ba32efd --- /dev/null +++ b/xs/src/slic3r/GUI/Field.hpp @@ -0,0 +1,270 @@ +#ifndef SLIC3R_GUI_FIELD_HPP +#define SLIC3R_GUI_FIELD_HPP + +#include +#ifndef WX_PRECOMP + #include +#endif + +#include +#include +#include + +#include +#include + +#include "../../libslic3r/libslic3r.h" +#include "../../libslic3r/Config.hpp" + +//#include "slic3r_gui.hpp" +#include "GUI.hpp" + +namespace Slic3r { namespace GUI { + +class Field; +using t_field = std::unique_ptr; +using t_kill_focus = std::function; +using t_change = std::function; + +class Field { +protected: + // factory function to defer and enforce creation of derived type. + virtual void PostInitialize() { BUILD(); } + + /// Finish constructing the Field's wxWidget-related properties, including setting its own sizer, etc. + virtual void BUILD() = 0; + + /// Call the attached on_kill_focus method. + //! It's important to use wxEvent instead of wxFocusEvent, + //! in another case we can't unfocused control at all + void on_kill_focus(wxEvent& event); + /// Call the attached on_change method. + void on_change_field(); + +public: + /// parent wx item, opportunity to refactor (probably not necessary - data duplication) + wxWindow* m_parent {nullptr}; + + /// Function object to store callback passed in from owning object. + t_kill_focus m_on_kill_focus {nullptr}; + + /// Function object to store callback passed in from owning object. + t_change m_on_change {nullptr}; + + // This is used to avoid recursive invocation of the field change/update by wxWidgets. + bool m_disable_change_event {false}; + + /// Copy of ConfigOption for deduction purposes + const ConfigOptionDef m_opt {ConfigOptionDef()}; + const t_config_option_key m_opt_id;//! {""}; + + /// Sets a value for this control. + /// subclasses should overload with a specific version + /// Postcondition: Method does not fire the on_change event. + virtual void set_value(boost::any value) = 0; + + /// Gets a boost::any representing this control. + /// subclasses should overload with a specific version + virtual boost::any get_value() = 0; + + virtual void enable() = 0; + virtual void disable() = 0; + + /// Fires the enable or disable function, based on the input. + inline void toggle(bool en) { en ? enable() : disable(); } + + virtual wxString get_tooltip_text(const wxString& default_string); + + Field(const ConfigOptionDef& opt, const t_config_option_key& id) : m_opt(opt), m_opt_id(id) {}; + Field(wxWindow* parent, const ConfigOptionDef& opt, const t_config_option_key& id) : m_parent(parent), m_opt(opt), m_opt_id(id) {}; + + /// If you don't know what you are getting back, check both methods for nullptr. + virtual wxSizer* getSizer() { return nullptr; } + virtual wxWindow* getWindow() { return nullptr; } + + bool is_matched(std::string string, std::string pattern); + boost::any get_value_by_opt_type(wxString str, ConfigOptionType type); + + /// Factory method for generating new derived classes. + template + static t_field Create(wxWindow* parent, const ConfigOptionDef& opt, const t_config_option_key& id) // interface for creating shared objects + { + auto p = Slic3r::make_unique(parent, opt, id); + p->PostInitialize(); + return std::move(p); //!p; + } +}; + +/// Convenience function, accepts a const reference to t_field and checks to see whether +/// or not both wx pointers are null. +inline bool is_bad_field(const t_field& obj) { return obj->getSizer() == nullptr && obj->getWindow() == nullptr; } + +/// Covenience function to determine whether this field is a valid window field. +inline bool is_window_field(const t_field& obj) { return !is_bad_field(obj) && obj->getWindow() != nullptr; } + +/// Covenience function to determine whether this field is a valid sizer field. +inline bool is_sizer_field(const t_field& obj) { return !is_bad_field(obj) && obj->getSizer() != nullptr; } + +class TextCtrl : public Field { + using Field::Field; +public: + TextCtrl(const ConfigOptionDef& opt, const t_config_option_key& id) : Field(opt, id) {} + TextCtrl(wxWindow* parent, const ConfigOptionDef& opt, const t_config_option_key& id) : Field(parent, opt, id) {} + + void BUILD(); + wxWindow* window {nullptr}; + + virtual void set_value(std::string value) { + m_disable_change_event = true; + dynamic_cast(window)->SetValue(wxString(value)); + m_disable_change_event = false; + } + virtual void set_value(boost::any value) { + m_disable_change_event = true; + dynamic_cast(window)->SetValue(boost::any_cast(value)); + m_disable_change_event = false; + } + + boost::any get_value() override; + + virtual void enable(); + virtual void disable(); + virtual wxWindow* getWindow() { return window; } +}; + +class CheckBox : public Field { + using Field::Field; +public: + CheckBox(const ConfigOptionDef& opt, const t_config_option_key& id) : Field(opt, id) {} + CheckBox(wxWindow* parent, const ConfigOptionDef& opt, const t_config_option_key& id) : Field(parent, opt, id) {} + + wxWindow* window{ nullptr }; + void BUILD() override; + + void set_value(const bool value) { + m_disable_change_event = true; + dynamic_cast(window)->SetValue(value); + m_disable_change_event = false; + } + void set_value(boost::any value) { + m_disable_change_event = true; + dynamic_cast(window)->SetValue(boost::any_cast(value)); + m_disable_change_event = false; + } + boost::any get_value() override { + return boost::any(dynamic_cast(window)->GetValue()); + } + + void enable() override { dynamic_cast(window)->Enable(); } + void disable() override { dynamic_cast(window)->Disable(); } + wxWindow* getWindow() override { return window; } +}; + +class SpinCtrl : public Field { + using Field::Field; +public: + SpinCtrl(const ConfigOptionDef& opt, const t_config_option_key& id) : Field(opt, id), tmp_value(-9999) {} + SpinCtrl(wxWindow* parent, const ConfigOptionDef& opt, const t_config_option_key& id) : Field(parent, opt, id), tmp_value(-9999) {} + + int tmp_value; + + wxWindow* window{ nullptr }; + void BUILD() override; + + void set_value(const std::string value) { + m_disable_change_event = true; + dynamic_cast(window)->SetValue(value); + m_disable_change_event = false; + } + void set_value(boost::any value) { + m_disable_change_event = true; + dynamic_cast(window)->SetValue(boost::any_cast(value)); + m_disable_change_event = false; + } + boost::any get_value() override { + return boost::any(dynamic_cast(window)->GetValue()); + } + + void enable() override { dynamic_cast(window)->Enable(); } + void disable() override { dynamic_cast(window)->Disable(); } + wxWindow* getWindow() override { return window; } +}; + +class Choice : public Field { + using Field::Field; +public: + Choice(const ConfigOptionDef& opt, const t_config_option_key& id) : Field(opt, id) {} + Choice(wxWindow* parent, const ConfigOptionDef& opt, const t_config_option_key& id) : Field(parent, opt, id) {} + + wxWindow* window{ nullptr }; + void BUILD() override; + + void set_selection(); + void set_value(const std::string value); + void set_value(boost::any value); + void set_values(const std::vector values); + boost::any get_value() override; + + void enable() override { dynamic_cast(window)->Enable(); }; + void disable() override{ dynamic_cast(window)->Disable(); }; + wxWindow* getWindow() override { return window; } +}; + +class ColourPicker : public Field { + using Field::Field; +public: + ColourPicker(const ConfigOptionDef& opt, const t_config_option_key& id) : Field(opt, id) {} + ColourPicker(wxWindow* parent, const ConfigOptionDef& opt, const t_config_option_key& id) : Field(parent, opt, id) {} + + wxWindow* window{ nullptr }; + void BUILD() override; + + void set_value(const std::string value) { + m_disable_change_event = true; + dynamic_cast(window)->SetColour(value); + m_disable_change_event = false; + } + void set_value(boost::any value) { + m_disable_change_event = true; + dynamic_cast(window)->SetColour(boost::any_cast(value)); + m_disable_change_event = false; + } + + boost::any get_value() override; + + void enable() override { dynamic_cast(window)->Enable(); }; + void disable() override{ dynamic_cast(window)->Disable(); }; + wxWindow* getWindow() override { return window; } +}; + +class PointCtrl : public Field { + using Field::Field; +public: + PointCtrl(const ConfigOptionDef& opt, const t_config_option_key& id) : Field(opt, id) {} + PointCtrl(wxWindow* parent, const ConfigOptionDef& opt, const t_config_option_key& id) : Field(parent, opt, id) {} + + wxSizer* sizer{ nullptr }; + wxTextCtrl* x_textctrl; + wxTextCtrl* y_textctrl; + + void BUILD() override; + + void set_value(const Pointf value); + void set_value(boost::any value); + boost::any get_value() override; + + void enable() override { + x_textctrl->Enable(); + y_textctrl->Enable(); }; + void disable() override{ + x_textctrl->Disable(); + y_textctrl->Disable(); }; + wxSizer* getSizer() override { return sizer; } +}; + + +#endif +} // GUI +} // Slic3r + + diff --git a/xs/src/slic3r/GUI/GUI.cpp b/xs/src/slic3r/GUI/GUI.cpp index 809ee8508..0d7d58e0f 100644 --- a/xs/src/slic3r/GUI/GUI.cpp +++ b/xs/src/slic3r/GUI/GUI.cpp @@ -4,6 +4,7 @@ #include #include +#include #include #include @@ -12,21 +13,39 @@ #import #elif _WIN32 #include +// Undefine min/max macros incompatible with the standard library +// For example, std::numeric_limits::max() +// produces some weird errors +#ifdef min +#undef min +#endif +#ifdef max +#undef max +#endif #include "boost/nowide/convert.hpp" #pragma comment(lib, "user32.lib") #endif #include #include +#include +#include +#include #include #include #include #include #include #include +#include #include "wxExtensions.hpp" +#include "Tab.hpp" +#include "TabIface.hpp" +#include "AppConfig.hpp" +#include "Utils.hpp" + namespace Slic3r { namespace GUI { #if __APPLE__ @@ -153,6 +172,10 @@ wxApp *g_wxApp = nullptr; wxFrame *g_wxMainFrame = nullptr; wxNotebook *g_wxTabPanel = nullptr; +std::vector g_tabs_list; + +wxLocale* g_wxLocale; + void set_wxapp(wxApp *app) { g_wxApp = app; @@ -168,25 +191,292 @@ void set_tab_panel(wxNotebook *tab_panel) g_wxTabPanel = tab_panel; } -void add_debug_menu(wxMenuBar *menu) +std::vector& get_tabs_list() { -#if 0 - auto debug_menu = new wxMenu(); - debug_menu->Append(wxWindow::NewControlId(1), "Some debug"); - menu->Append(debug_menu, _T("&Debug")); -#endif + return g_tabs_list; } -void create_preset_tab(const char *name) +bool checked_tab(Tab* tab) { - auto *panel = new wxPanel(g_wxTabPanel, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxBK_LEFT | wxTAB_TRAVERSAL); - // Vertical sizer to hold the choice menu and the rest of the page. - auto *sizer = new wxBoxSizer(wxVERTICAL); - sizer->SetSizeHints(panel); - panel->SetSizer(sizer); - auto *button = new wxButton(panel, wxID_ANY, "Hello World", wxDefaultPosition, wxDefaultSize, 0); - sizer->Add(button, 0, 0, 0); - g_wxTabPanel->AddPage(panel, name); + bool ret = true; + if (find(g_tabs_list.begin(), g_tabs_list.end(), tab) == g_tabs_list.end()) + ret = false; + return ret; +} + +void delete_tab_from_list(Tab* tab) +{ + std::vector::iterator itr = find(g_tabs_list.begin(), g_tabs_list.end(), tab); + if (itr != g_tabs_list.end()) + g_tabs_list.erase(itr); +} + +bool select_language(wxArrayString & names, + wxArrayLong & identifiers) +{ + wxCHECK_MSG(names.Count() == identifiers.Count(), false, + _L("Array of language names and identifiers should have the same size.")); + int init_selection = 0; + long current_language = g_wxLocale ? g_wxLocale->GetLanguage() : wxLANGUAGE_UNKNOWN; + for (auto lang : identifiers){ + if (lang == current_language) + break; + else + ++init_selection; + } + if (init_selection == identifiers.size()) + init_selection = 0; + long index = wxGetSingleChoiceIndex(_L("Select the language"), _L("Language"), + names, init_selection); + if (index != -1) + { + g_wxLocale = new wxLocale; + g_wxLocale->Init(identifiers[index]); + g_wxLocale->AddCatalogLookupPathPrefix(wxPathOnly(localization_dir())); + g_wxLocale->AddCatalog(g_wxApp->GetAppName()); + return true; + } + return false; +} + +bool load_language() +{ + wxConfig config(g_wxApp->GetAppName()); + long language; + if (!config.Read(wxT("wxTranslation_Language"), + &language, wxLANGUAGE_UNKNOWN)) + { + language = wxLANGUAGE_UNKNOWN; + } + if (language == wxLANGUAGE_UNKNOWN) + return false; + wxArrayString names; + wxArrayLong identifiers; + get_installed_languages(names, identifiers); + for (size_t i = 0; i < identifiers.Count(); i++) + { + if (identifiers[i] == language) + { + g_wxLocale = new wxLocale; + g_wxLocale->Init(identifiers[i]); + g_wxLocale->AddCatalogLookupPathPrefix(wxPathOnly(localization_dir())); + g_wxLocale->AddCatalog(g_wxApp->GetAppName()); + return true; + } + } + return false; +} + +void save_language() +{ + wxConfig config(g_wxApp->GetAppName()); + long language = wxLANGUAGE_UNKNOWN; + if (g_wxLocale) { + language = g_wxLocale->GetLanguage(); + } + config.Write(wxT("wxTranslation_Language"), language); + config.Flush(); +} + +void get_installed_languages(wxArrayString & names, + wxArrayLong & identifiers) +{ + names.Clear(); + identifiers.Clear(); + + wxDir dir(wxPathOnly(localization_dir())); + wxString filename; + const wxLanguageInfo * langinfo; + wxString name = wxLocale::GetLanguageName(wxLANGUAGE_DEFAULT); + if (!name.IsEmpty()) + { + names.Add(_L("Default")); + identifiers.Add(wxLANGUAGE_DEFAULT); + } + for (bool cont = dir.GetFirst(&filename, wxEmptyString, wxDIR_DIRS); + cont; cont = dir.GetNext(&filename)) + { + wxLogTrace(wxTraceMask(), + "L10n: Directory found = \"%s\"", + filename.GetData()); + langinfo = wxLocale::FindLanguageInfo(filename); + if (langinfo != NULL) + { + auto full_file_name = dir.GetName() + wxFileName::GetPathSeparator() + + filename + wxFileName::GetPathSeparator() + + g_wxApp->GetAppName() + wxT(".mo"); + if (wxFileExists(full_file_name)) + { + names.Add(langinfo->Description); + identifiers.Add(langinfo->Language); + } + } + } +} + +void add_debug_menu(wxMenuBar *menu, int event_language_change) +{ +//#if 0 + auto local_menu = new wxMenu(); + local_menu->Append(wxWindow::NewControlId(1), _L("Change Application Language")); + local_menu->Bind(wxEVT_MENU, [event_language_change](wxEvent&){ + wxArrayString names; + wxArrayLong identifiers; + get_installed_languages(names, identifiers); + if (select_language(names, identifiers)){ + save_language(); + show_info(g_wxTabPanel, "Application will be restarted", "Attention!"); + if (event_language_change > 0) { + wxCommandEvent event(event_language_change); + g_wxApp->ProcessEvent(event); + } + } + }); + menu->Append(local_menu, _T("&Localization")); +//#endif +} + +void create_preset_tabs(PresetBundle *preset_bundle, AppConfig *app_config, + bool no_controller, bool is_disabled_button_browse, bool is_user_agent, + int event_value_change, int event_presets_changed, + int event_button_browse, int event_button_test) +{ + add_created_tab(new TabPrint (g_wxTabPanel, no_controller), preset_bundle, app_config); + add_created_tab(new TabFilament (g_wxTabPanel, no_controller), preset_bundle, app_config); + add_created_tab(new TabPrinter (g_wxTabPanel, no_controller, is_disabled_button_browse, is_user_agent), + preset_bundle, app_config); + for (size_t i = 0; i < g_wxTabPanel->GetPageCount(); ++ i) { + Tab *tab = dynamic_cast(g_wxTabPanel->GetPage(i)); + if (! tab) + continue; + tab->set_event_value_change(wxEventType(event_value_change)); + tab->set_event_presets_changed(wxEventType(event_presets_changed)); + if (tab->name() == "printer"){ + TabPrinter* tab_printer = static_cast(tab); + tab_printer->set_event_button_browse(wxEventType(event_button_browse)); + tab_printer->set_event_button_test(wxEventType(event_button_test)); + } + } +} + +TabIface* get_preset_tab_iface(char *name) +{ + for (size_t i = 0; i < g_wxTabPanel->GetPageCount(); ++ i) { + Tab *tab = dynamic_cast(g_wxTabPanel->GetPage(i)); + if (! tab) + continue; + if (tab->name() == name) { + return new TabIface(tab); + } + } + return new TabIface(nullptr); +} + +// opt_index = 0, by the reason of zero-index in ConfigOptionVector by default (in case only one element) +void change_opt_value(DynamicPrintConfig& config, t_config_option_key opt_key, boost::any value, int opt_index /*= 0*/) +{ + try{ + switch (config.def()->get(opt_key)->type){ + case coFloatOrPercent:{ + const auto &val = *config.option(opt_key); + config.set_key_value(opt_key, new ConfigOptionFloatOrPercent(boost::any_cast(value), val.percent)); + break;} + case coPercent: + config.set_key_value(opt_key, new ConfigOptionPercent(boost::any_cast(value))); + break; + case coFloat:{ + double& val = config.opt_float(opt_key); + val = boost::any_cast(value); + break; + } + case coPercents: + case coFloats:{ + double& val = config.opt_float(opt_key, 0); + val = boost::any_cast(value); + break; + } + case coString: + config.set_key_value(opt_key, new ConfigOptionString(boost::any_cast(value))); + break; + case coStrings:{ + if (opt_key.compare("compatible_printers") == 0){ + config.option(opt_key)->values.resize(0); + for (auto el : boost::any_cast>(value)) + config.option(opt_key)->values.push_back(el); + } + else{ + ConfigOptionStrings* vec_new = new ConfigOptionStrings{ boost::any_cast(value) }; + config.option(opt_key)->set_at(vec_new, opt_index, opt_index); + } + } + break; + case coBool: + config.set_key_value(opt_key, new ConfigOptionBool(boost::any_cast(value))); + break; + case coBools:{ + ConfigOptionBools* vec_new = new ConfigOptionBools{ boost::any_cast(value) }; + config.option(opt_key)->set_at(vec_new, opt_index, opt_index); + break;} + case coInt: + config.set_key_value(opt_key, new ConfigOptionInt(boost::any_cast(value))); + break; + case coInts:{ + ConfigOptionInts* vec_new = new ConfigOptionInts{ boost::any_cast(value) }; + config.option(opt_key)->set_at(vec_new, opt_index, opt_index); + } + break; + case coEnum:{ + if (opt_key.compare("external_fill_pattern") == 0 || + opt_key.compare("fill_pattern") == 0) + config.set_key_value(opt_key, new ConfigOptionEnum(boost::any_cast(value))); + else if (opt_key.compare("gcode_flavor") == 0) + config.set_key_value(opt_key, new ConfigOptionEnum(boost::any_cast(value))); + else if (opt_key.compare("support_material_pattern") == 0) + config.set_key_value(opt_key, new ConfigOptionEnum(boost::any_cast(value))); + else if (opt_key.compare("seam_position") == 0) + config.set_key_value(opt_key, new ConfigOptionEnum(boost::any_cast(value))); + } + break; + case coPoints:{ + ConfigOptionPoints points; + points.values = boost::any_cast>(value); + config.set_key_value(opt_key, new ConfigOptionPoints(points)); + } + break; + case coNone: + break; + default: + break; + } + } + catch (const std::exception &e) + { + int i = 0;//no reason, just experiment + } +} + +void add_created_tab(Tab* panel, PresetBundle *preset_bundle, AppConfig *app_config) +{ + panel->m_show_btn_incompatible_presets = app_config->get("show_incompatible_presets").empty(); + panel->create_preset_tab(preset_bundle); + + // Load the currently selected preset into the GUI, update the preset selection box. + panel->load_current_preset(); + g_wxTabPanel->AddPage(panel, panel->title()); +} + +void show_error(wxWindow* parent, wxString message){ + auto msg_wingow = new wxMessageDialog(parent, message, _L("Error"), wxOK | wxICON_ERROR); + msg_wingow->ShowModal(); +} + +void show_info(wxWindow* parent, wxString message, wxString title){ + auto msg_wingow = new wxMessageDialog(parent, message, title.empty() ? _L("Notice") : title, wxOK | wxICON_INFORMATION); + msg_wingow->ShowModal(); +} + +wxApp* get_app(){ + return g_wxApp; } void create_combochecklist(wxComboCtrl* comboCtrl, std::string text, std::string items, bool initial_value) diff --git a/xs/src/slic3r/GUI/GUI.hpp b/xs/src/slic3r/GUI/GUI.hpp index f15ba15d6..14f429713 100644 --- a/xs/src/slic3r/GUI/GUI.hpp +++ b/xs/src/slic3r/GUI/GUI.hpp @@ -3,14 +3,50 @@ #include #include +#include "Config.hpp" class wxApp; class wxFrame; +class wxWindow; class wxMenuBar; class wxNotebook; class wxComboCtrl; +class wxString; +class wxArrayString; +class wxArrayLong; -namespace Slic3r { namespace GUI { +namespace Slic3r { + +class PresetBundle; +class PresetCollection; +class AppConfig; +class DynamicPrintConfig; +class TabIface; + +//! macro used to localization, return wxString +#define _L(s) wxGetTranslation(s) +//! macro used to localization, return const CharType * +#define _LU8(s) wxGetTranslation(s).ToUTF8().data() + +namespace GUI { + +class Tab; +// Map from an file_type name to full file wildcard name. +typedef std::map t_file_wild_card; +inline t_file_wild_card& get_file_wild_card() { + static t_file_wild_card FILE_WILDCARDS; + if (FILE_WILDCARDS.empty()){ + FILE_WILDCARDS["known"] = "Known files (*.stl, *.obj, *.amf, *.xml, *.prusa)|*.stl;*.STL;*.obj;*.OBJ;*.amf;*.AMF;*.xml;*.XML;*.prusa;*.PRUSA"; + FILE_WILDCARDS["stl"] = "STL files (*.stl)|*.stl;*.STL"; + FILE_WILDCARDS["obj"] = "OBJ files (*.obj)|*.obj;*.OBJ"; + FILE_WILDCARDS["amf"] = "AMF files (*.amf)|*.amf;*.AMF;*.xml;*.XML"; + FILE_WILDCARDS["prusa"] = "Prusa Control files (*.prusa)|*.prusa;*.PRUSA"; + FILE_WILDCARDS["ini"] = "INI files *.ini|*.ini;*.INI"; + FILE_WILDCARDS["gcode"] = "G-code files (*.gcode, *.gco, *.g, *.ngc)|*.gcode;*.GCODE;*.gco;*.GCO;*.g;*.G;*.ngc;*.NGC"; + FILE_WILDCARDS["svg"] = "SVG files *.svg|*.svg;*.SVG"; + } + return FILE_WILDCARDS; +} void disable_screensaver(); void enable_screensaver(); @@ -23,10 +59,34 @@ void set_wxapp(wxApp *app); void set_main_frame(wxFrame *main_frame); void set_tab_panel(wxNotebook *tab_panel); -void add_debug_menu(wxMenuBar *menu); -// Create a new preset tab (print, filament or printer), +void add_debug_menu(wxMenuBar *menu, int event_language_change); +// Create a new preset tab (print, filament and printer), +void create_preset_tabs(PresetBundle *preset_bundle, AppConfig *app_config, + bool no_controller, bool is_disabled_button_browse, bool is_user_agent, + int event_value_change, int event_presets_changed, + int event_button_browse, int event_button_test); +TabIface* get_preset_tab_iface(char *name); + // add it at the end of the tab panel. -void create_preset_tab(const char *name); +void add_created_tab(Tab* panel, PresetBundle *preset_bundle, AppConfig *app_config); +// Change option value in config +void change_opt_value(DynamicPrintConfig& config, t_config_option_key opt_key, boost::any value, int opt_index = 0); + +void show_error(wxWindow* parent, wxString message); +void show_info(wxWindow* parent, wxString message, wxString title); + +// load language saved at application config +bool load_language(); +// save language at application config +void save_language(); +// get list of installed languages +void get_installed_languages(wxArrayString & names, wxArrayLong & identifiers); +// select language from the list of installed languages +bool select_language(wxArrayString & names, wxArrayLong & identifiers); + +std::vector& get_tabs_list(); +bool checked_tab(Tab* tab); +void delete_tab_from_list(Tab* tab); // Creates a wxCheckListBoxComboPopup inside the given wxComboCtrl, filled with the given text and items. // Items are all initialized to the given value. diff --git a/xs/src/slic3r/GUI/OptionsGroup.cpp b/xs/src/slic3r/GUI/OptionsGroup.cpp new file mode 100644 index 000000000..a6d91cfc1 --- /dev/null +++ b/xs/src/slic3r/GUI/OptionsGroup.cpp @@ -0,0 +1,410 @@ +#include "OptionsGroup.hpp" +#include "ConfigExceptions.hpp" + +#include +#include +#include + +namespace Slic3r { namespace GUI { + +const t_field& OptionsGroup::build_field(const Option& opt) { + return build_field(opt.opt_id, opt.opt); +} +const t_field& OptionsGroup::build_field(const t_config_option_key& id) { + const ConfigOptionDef& opt = m_options.at(id).opt; + return build_field(id, opt); +} + +const t_field& OptionsGroup::build_field(const t_config_option_key& id, const ConfigOptionDef& opt) { + // Check the gui_type field first, fall through + // is the normal type. + if (opt.gui_type.compare("select") == 0) { + } else if (opt.gui_type.compare("select_open") == 0) { + m_fields.emplace(id, STDMOVE(Choice::Create(m_parent, opt, id))); + } else if (opt.gui_type.compare("color") == 0) { + m_fields.emplace(id, STDMOVE(ColourPicker::Create(m_parent, opt, id))); + } else if (opt.gui_type.compare("f_enum_open") == 0 || + opt.gui_type.compare("i_enum_open") == 0 || + opt.gui_type.compare("i_enum_closed") == 0) { + m_fields.emplace(id, STDMOVE(Choice::Create(m_parent, opt, id))); + } else if (opt.gui_type.compare("slider") == 0) { + } else if (opt.gui_type.compare("i_spin") == 0) { // Spinctrl + } else { + switch (opt.type) { + case coFloatOrPercent: + case coFloat: + case coFloats: + case coPercent: + case coPercents: + case coString: + case coStrings: + m_fields.emplace(id, STDMOVE(TextCtrl::Create(m_parent, opt, id))); + break; + case coBool: + case coBools: + m_fields.emplace(id, STDMOVE(CheckBox::Create(m_parent, opt, id))); + break; + case coInt: + case coInts: + m_fields.emplace(id, STDMOVE(SpinCtrl::Create(m_parent, opt, id))); + break; + case coEnum: + m_fields.emplace(id, STDMOVE(Choice::Create(m_parent, opt, id))); + break; + case coPoints: + m_fields.emplace(id, STDMOVE(PointCtrl::Create(m_parent, opt, id))); + break; + case coNone: break; + default: + throw /*//!ConfigGUITypeError("")*/std::logic_error("This control doesn't exist till now"); break; + } + } + // Grab a reference to fields for convenience + const t_field& field = m_fields[id]; + field->m_on_change = [this](std::string opt_id, boost::any value){ + //! This function will be called from Field. + //! Call OptionGroup._on_change(...) + if (!this->m_disabled) + this->on_change_OG(opt_id, value); + }; + field->m_on_kill_focus = [this](){ + //! This function will be called from Field. + if (!this->m_disabled) + this->on_kill_focus(); + }; + field->m_parent = parent(); + // assign function objects for callbacks, etc. + return field; +} + +void OptionsGroup::append_line(const Line& line) { +//! if (line.sizer != nullptr || (line.widget != nullptr && line.full_width > 0)){ + if ( (line.sizer != nullptr || line.widget != nullptr) && line.full_width){ + if (line.sizer != nullptr) { + sizer->Add(line.sizer, 0, wxEXPAND | wxALL, wxOSX ? 0 : 15); + return; + } + if (line.widget != nullptr) { + sizer->Add(line.widget(m_parent), 0, wxEXPAND | wxALL, wxOSX ? 0 : 15); + return; + } + } + + auto option_set = line.get_options(); + for (auto opt : option_set) + m_options.emplace(opt.opt_id, opt); + + // if we have a single option with no label, no sidetext just add it directly to sizer + if (option_set.size() == 1 && label_width == 0 && option_set.front().opt.full_width && + option_set.front().opt.sidetext.size() == 0 && option_set.front().side_widget == nullptr && + line.get_extra_widgets().size() == 0) { + const auto& option = option_set.front(); + const auto& field = build_field(option); + + if (is_window_field(field)) + sizer->Add(field->getWindow(), 0, wxEXPAND | wxALL, wxOSX ? 0 : 5); + if (is_sizer_field(field)) + sizer->Add(field->getSizer(), 0, wxEXPAND | wxALL, wxOSX ? 0 : 5); + return; + } + + auto grid_sizer = m_grid_sizer; + + // Build a label if we have it + if (label_width != 0) { + auto label = new wxStaticText(parent(), wxID_ANY, line.label + (line.label.IsEmpty() ? "" : ":"), + wxDefaultPosition, wxSize(label_width, -1)); + label->SetFont(label_font); + label->Wrap(label_width); // avoid a Linux/GTK bug + grid_sizer->Add(label, 0, wxALIGN_CENTER_VERTICAL,0); + if (line.label_tooltip.compare("") != 0) + label->SetToolTip(line.label_tooltip); + } + + // If there's a widget, build it and add the result to the sizer. + if (line.widget != nullptr) { + auto wgt = line.widget(parent()); + grid_sizer->Add(wgt, 0, wxEXPAND | wxBOTTOM | wxTOP, wxOSX ? 0 : 5); + return; + } + + // if we have a single option with no sidetext just add it directly to the grid sizer + if (option_set.size() == 1 && option_set.front().opt.sidetext.size() == 0 && + option_set.front().side_widget == nullptr && line.get_extra_widgets().size() == 0) { + const auto& option = option_set.front(); + const auto& field = build_field(option); +//! std::cerr << "single option, no sidetext.\n"; +//! std::cerr << "field parent is not null?: " << (field->parent != nullptr) << "\n"; + + if (is_window_field(field)) + grid_sizer->Add(field->getWindow(), 0, (option.opt.full_width ? wxEXPAND : 0) | + wxBOTTOM | wxTOP | wxALIGN_CENTER_VERTICAL, wxOSX ? 0 : 2); + if (is_sizer_field(field)) + grid_sizer->Add(field->getSizer(), 0, (option.opt.full_width ? wxEXPAND : 0) | wxALIGN_CENTER_VERTICAL, 0); + return; + } + + // if we're here, we have more than one option or a single option with sidetext + // so we need a horizontal sizer to arrange these things + auto sizer = new wxBoxSizer(wxHORIZONTAL); + grid_sizer->Add(sizer, 0, wxEXPAND | wxALL, 0); + for (auto opt : option_set) { + ConfigOptionDef option = opt.opt; + // add label if any + if (option.label != "") { + auto field_label = new wxStaticText(parent(), wxID_ANY, wxString::FromUTF8(option.label.c_str()) + ":", wxDefaultPosition, wxDefaultSize); + field_label->SetFont(label_font); + sizer->Add(field_label, 0, wxALIGN_CENTER_VERTICAL, 0); + } + + // add field + const Option& opt_ref = opt; + auto& field = build_field(opt_ref); + is_sizer_field(field) ? + sizer->Add(field->getSizer(), 0, wxALIGN_CENTER_VERTICAL, 0) : + sizer->Add(field->getWindow(), 0, wxALIGN_CENTER_VERTICAL, 0); + + // add sidetext if any + if (option.sidetext != "") { + auto sidetext = new wxStaticText(parent(), wxID_ANY, wxString::FromUTF8(option.sidetext.c_str()), wxDefaultPosition, wxDefaultSize); + sidetext->SetFont(sidetext_font); + sizer->Add(sidetext, 0, wxLEFT | wxALIGN_CENTER_VERTICAL, 4); + } + + // add side widget if any + if (opt.side_widget != nullptr) { + sizer->Add(opt.side_widget(parent())/*!.target()*/, 0, wxLEFT | wxALIGN_CENTER_VERTICAL, 1); //! requires verification + } + + if (opt.opt_id != option_set.back().opt_id) //! istead of (opt != option_set.back()) + { + sizer->AddSpacer(6); + } + } + // add extra sizers if any + for (auto extra_widget : line.get_extra_widgets()) { + sizer->Add(extra_widget(parent())/*!.target()*/, 0, wxLEFT | wxALIGN_CENTER_VERTICAL, 4); //! requires verification + } +} + +Line OptionsGroup::create_single_option_line(const Option& option) const { + Line retval{ wxString::FromUTF8(option.opt.label.c_str()), wxString::FromUTF8(option.opt.tooltip.c_str()) }; + Option tmp(option); + tmp.opt.label = std::string(""); + retval.append_option(tmp); + return retval; +} + +void OptionsGroup::on_change_OG(t_config_option_key id, /*config_value*/boost::any value) { + if (m_on_change != nullptr) + m_on_change(id, value); +} + +Option ConfigOptionsGroup::get_option(const std::string opt_key, int opt_index /*= -1*/) +{ + if (!m_config->has(opt_key)) { + //! exception ("No $opt_key in ConfigOptionsGroup config"); + } + + std::string opt_id = opt_index == -1 ? opt_key : opt_key + "#" + std::to_string(opt_index); + std::pair pair(opt_key, opt_index); + m_opt_map.emplace(opt_id, pair); + + return Option(*m_config->def()->get(opt_key), opt_id); +} + +void ConfigOptionsGroup::on_change_OG(t_config_option_key opt_id, boost::any value) +{ + if (!m_opt_map.empty()) + { + auto it = m_opt_map.find(opt_id); + if (it == m_opt_map.end()) + { + OptionsGroup::on_change_OG(opt_id, value); + return; + } + + auto itOption = it->second; + std::string opt_key = itOption.first; + int opt_index = itOption.second; + + auto option = m_options.at(opt_id).opt; + + // get value +//! auto field_value = get_value(opt_id); + if (option.gui_flags.compare("serialized")==0) { + if (opt_index != -1){ + // die "Can't set serialized option indexed value" ; + } + // # Split a string to multiple strings by a semi - colon.This is the old way of storing multi - string values. + // # Currently used for the post_process config value only. + // my @values = split / ; / , $field_value; + // $self->config->set($opt_key, \@values); + } + else { + if (opt_index == -1) { + // change_opt_value(*m_config, opt_key, field_value); + //!? why field_value?? in this case changed value will be lose! No? + change_opt_value(*m_config, opt_key, value); + } + else { + change_opt_value(*m_config, opt_key, value, opt_index); +// auto value = m_config->get($opt_key); +// $value->[$opt_index] = $field_value; +// $self->config->set($opt_key, $value); + } + } + } + + OptionsGroup::on_change_OG(opt_id, value); //!? Why doing this +} + +void ConfigOptionsGroup::reload_config(){ + for (std::map< std::string, std::pair >::iterator it = m_opt_map.begin(); it != m_opt_map.end(); ++it) { + auto opt_id = it->first; + std::string opt_key = m_opt_map.at(opt_id).first; + int opt_index = m_opt_map.at(opt_id).second; + auto option = m_options.at(opt_id).opt; + set_value(opt_id, config_value(opt_key, opt_index, option.gui_flags.compare("serialized") == 0 )); + } + +} + +boost::any ConfigOptionsGroup::config_value(std::string opt_key, int opt_index, bool deserialize){ + + if (deserialize) { + // Want to edit a vector value(currently only multi - strings) in a single edit box. + // Aggregate the strings the old way. + // Currently used for the post_process config value only. + if (opt_index != -1) + throw std::out_of_range("Can't deserialize option indexed value"); +// return join(';', m_config->get(opt_key)}); + return get_config_value(*m_config, opt_key); + } + else { +// return opt_index == -1 ? m_config->get(opt_key) : m_config->get_at(opt_key, opt_index); + return get_config_value(*m_config, opt_key, opt_index); + } +} + +wxString double_to_string(double const value) +{ + int precision = 10 * value - int(10 * value) == 0 ? 1 : 2; + return value - int(value) == 0 ? + wxString::Format(_T("%i"), int(value)) : + wxNumberFormatter::ToString(value, precision, wxNumberFormatter::Style_None); +} + +boost::any ConfigOptionsGroup::get_config_value(DynamicPrintConfig& config, std::string opt_key, int opt_index/* = -1*/) +{ + size_t idx = opt_index == -1 ? 0 : opt_index; + + boost::any ret; + wxString text_value = wxString(""); + const ConfigOptionDef* opt = config.def()->get(opt_key); + switch (opt->type){ + case coFloatOrPercent:{ + const auto &value = *config.option(opt_key); + if (value.percent) + { + text_value = wxString::Format(_T("%i"), int(value.value)); + text_value += "%"; + } + else + text_value = double_to_string(value.value); + ret = text_value; + break; + } + case coPercent:{ + double val = config.option(opt_key)->value; + text_value = wxString::Format(_T("%i"), int(val)); + ret = text_value;// += "%"; + } + break; + case coPercents: + case coFloats: + case coFloat:{ + double val = opt->type == coFloats ? + config.opt_float(opt_key, idx/*0opt_index*/) : + opt->type == coFloat ? config.opt_float(opt_key) : + config.option(opt_key)->values.at(idx/*0*/); + ret = double_to_string(val); + } + break; + case coString: + ret = static_cast(config.opt_string(opt_key)); + break; + case coStrings: + if (config.option(opt_key)->values.empty()) + ret = text_value; + else + ret = static_cast(config.opt_string(opt_key, static_cast(idx/*0*/)/*opt_index*/)); + break; + case coBool: + ret = config.opt_bool(opt_key); + break; + case coBools: + ret = config.opt_bool(opt_key, idx/*0opt_index*/); + break; + case coInt: + ret = config.opt_int(opt_key); + break; + case coInts: + ret = config.opt_int(opt_key, idx/*0/*opt_index*/); + break; + case coEnum:{ + if (opt_key.compare("external_fill_pattern") == 0 || + opt_key.compare("fill_pattern") == 0 ){ + ret = static_cast(config.option>(opt_key)->value); + } + else if (opt_key.compare("gcode_flavor") == 0 ){ + ret = static_cast(config.option>(opt_key)->value); + } + else if (opt_key.compare("support_material_pattern") == 0){ + ret = static_cast(config.option>(opt_key)->value); + } + else if (opt_key.compare("seam_position") == 0) + ret = static_cast(config.option>(opt_key)->value); + } + break; + case coPoints:{ + const auto &value = *config.option(opt_key); + ret = value.values.at(idx/*0*/); + } + break; + case coNone: + default: + break; + } + return ret; +} + +Field* ConfigOptionsGroup::get_fieldc(t_config_option_key opt_key, int opt_index){ + std::string opt_id = ""; + for (std::map< std::string, std::pair >::iterator it = m_opt_map.begin(); it != m_opt_map.end(); ++it) { + if (opt_key == m_opt_map.at(it->first).first && opt_index == m_opt_map.at(it->first).second){ + opt_id = it->first; + break; + } + } + return opt_id.empty() ? nullptr : get_field(opt_id); +} + +void ogStaticText::SetText(wxString value) +{ + SetLabel(value); + Wrap(400); + GetParent()->Layout(); +} + +void Option::translate() +{ + opt.label = _LU8(opt.label); + opt.tooltip = _LU8(opt.tooltip); + opt.sidetext = _LU8(opt.sidetext); + opt.full_label = _LU8(opt.full_label); + opt.category = _LU8(opt.category); +} + +} // GUI +} // Slic3r diff --git a/xs/src/slic3r/GUI/OptionsGroup.hpp b/xs/src/slic3r/GUI/OptionsGroup.hpp new file mode 100644 index 000000000..becc62d71 --- /dev/null +++ b/xs/src/slic3r/GUI/OptionsGroup.hpp @@ -0,0 +1,181 @@ +#include +#include +#include +//#include + +#include +#include + +#include "libslic3r/Config.hpp" +#include "libslic3r/PrintConfig.hpp" +#include "libslic3r/libslic3r.h" + +#include "Field.hpp" + +// Translate the ifdef +#ifdef __WXOSX__ + #define wxOSX true +#else + #define wxOSX false +#endif + +#define BORDER(a, b) ((wxOSX ? a : b)) + +namespace Slic3r { namespace GUI { + +/// Widget type describes a function object that returns a wxWindow (our widget) and accepts a wxWidget (parent window). +using widget_t = std::function;//!std::function; +using column_t = std::function; + +/// Wraps a ConfigOptionDef and adds function object for creating a side_widget. +struct Option { + ConfigOptionDef opt { ConfigOptionDef() }; + t_config_option_key opt_id;//! {""}; + widget_t side_widget {nullptr}; + bool readonly {false}; + + Option(const ConfigOptionDef& _opt, t_config_option_key id) : + opt(_opt), opt_id(id) { translate(); } + void translate(); +}; +using t_option = std::unique_ptr