Skip to content

Commit 6f4adfe

Browse files
committed
Removing Annotator export without images.
* Adding image compression option to Annotator export.
1 parent 8b4211c commit 6f4adfe

File tree

4 files changed

+23
-42
lines changed

4 files changed

+23
-42
lines changed

src/Canvas.vala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -501,11 +501,11 @@ public class Canvas : DrawingArea {
501501

502502
//-------------------------------------------------------------
503503
// Saves this canvas and all canvas items in XML format.
504-
public Xml.Node* save( string? image_dir = null ) {
504+
public Xml.Node* save( string image_dir, int compression ) {
505505

506506
Xml.Node* node = new Xml.Node( null, "canvas" );
507507

508-
node->add_child( image.save( editor.filename, image_dir ) );
508+
node->add_child( image.save( image_dir, compression ) );
509509
node->add_child( items.save( image_dir ) );
510510

511511
return( node );

src/CanvasImage.vala

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -580,23 +580,18 @@ public class CanvasImage {
580580

581581
//-------------------------------------------------------------
582582
// Saves the contents of this canvas image to XML format.
583-
public Xml.Node* save( string fname, string? image_dir ) {
584-
585-
Xml.Node* node = new Xml.Node( null, "image" );
586-
587-
if( image_dir != null ) {
588-
string[] options = { "compression" };
589-
string[] values = { "9" };
590-
var name = GLib.Path.build_filename( image_dir, "background.png" );
591-
stdout.printf( "Attempting to save canvas image as %s\n", name );
592-
try {
593-
_buf.savev( name, "png", options, values );
594-
node->set_prop( "filename", name );
595-
} catch( GLib.Error e ) {
596-
critical( e.message );
597-
}
598-
} else {
583+
public Xml.Node* save( string image_dir, int compression ) {
584+
585+
Xml.Node* node = new Xml.Node( null, "image" );
586+
string[] options = { "compression" };
587+
string[] values = { compression.to_string() };
588+
var fname = GLib.Path.build_filename( image_dir, "background.png" );
589+
590+
try {
591+
_buf.savev( fname, "png", options, values );
599592
node->set_prop( "filename", fname );
593+
} catch( GLib.Error e ) {
594+
critical( e.message );
600595
}
601596

602597
node->set_prop( "angle", _angle.to_string() );

src/Exporter.vala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,6 @@ public class Exporter : Box {
170170
FileFilter filter = new FileFilter();
171171
filter.set_filter_name( export.label );
172172
foreach( string extension in export.extensions ) {
173-
stdout.printf( "Setting export to %s\n", extension );
174173
filter.add_pattern( "*" + extension );
175174
}
176175
dialog.set_filter( filter );

src/exports/ExportEditable.vala

Lines changed: 10 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,7 @@ public class ExportEditable : Export {
3939
var fname = repair_filename( filename );
4040

4141
/* Figure out if the user wants to include the images or not */
42-
if( get_bool( "include-images" ) ) {
43-
save_with_images( fname );
44-
} else {
45-
save_without_images( fname );
46-
}
42+
save( fname );
4743

4844
return( true );
4945

@@ -54,7 +50,7 @@ public class ExportEditable : Export {
5450
// images used within the annotation are saved into the directory
5551
// and the directory is zipped and archived as the final *.annotator
5652
// file.
57-
private void save_with_images( string fname ) {
53+
private void save( string fname ) {
5854

5955
string temp_dir;
6056

@@ -142,25 +138,16 @@ public class ExportEditable : Export {
142138

143139
}
144140

145-
//-------------------------------------------------------------
146-
// Saves the *.annotator file as an XML file, leaving the image
147-
// paths to point to the local filesystem.
148-
private void save_without_images( string fname ) {
149-
150-
save_xml( fname, null );
151-
152-
}
153-
154141
//-------------------------------------------------------------
155142
// Saves the XML information from the annotation. Copies the stored
156143
// images in the given image directory, if specified.
157-
private void save_xml( string fname, string? image_dir ) {
144+
private void save_xml( string fname, string image_dir ) {
158145

159146
Xml.Doc* doc = new Xml.Doc( "1.0" );
160147
Xml.Node* root = new Xml.Node( null, "exports" );
161148

162149
root->set_prop( "version", Annotator.version );
163-
root->add_child( canvas.save( image_dir ) );
150+
root->add_child( canvas.save( image_dir, get_scale( "image-compression" ) ) );
164151

165152
doc->set_root_element( root );
166153
doc->save_format_file( fname, 1 );
@@ -218,7 +205,7 @@ public class ExportEditable : Export {
218205

219206
/* Open the portable Minder file for reading */
220207
if( archive.open_filename( filename, 16384 ) != Archive.Result.OK ) {
221-
return( load_xml( filename ) );
208+
return( false );
222209
}
223210

224211
unowned Archive.Entry entry;
@@ -265,21 +252,21 @@ public class ExportEditable : Export {
265252
// Add the setting to enable/disable including the images included
266253
// in the annotation.
267254
public override void add_settings( Grid grid ) {
268-
add_setting_bool( "include-images", grid, _( "Include images" ), _( "Including images will allow the saved file to be used on a different machine, but will make the file size much larger" ), false );
255+
add_setting_scale( "image-compression", grid, _( "Image Compression" ), null, 0, 9, 1, 0 );
269256
}
270257

271258
//-------------------------------------------------------------
272259
// Save the settings.
273260
public override void save_settings( Xml.Node* node ) {
274-
node->set_prop( "include-images", get_bool( "include-images" ).to_string() );
261+
node->set_prop( "compression", get_scale( "image-compression" ).to_string() );
275262
}
276263

277264
//-------------------------------------------------------------
278265
// Load the settings.
279266
public override void load_settings( Xml.Node* node ) {
280-
var ii = node->get_prop( "include-images" );
281-
if( ii != null ) {
282-
set_bool( "include-images", bool.parse( ii ) );
267+
var c = node->get_prop( "compression" );
268+
if( c != null ) {
269+
set_scale( "image-compression", int.parse( c ) );
283270
}
284271
}
285272

0 commit comments

Comments
 (0)