2
* layout.cpp - A superclass for layouts.
4
* Copyright (c) 2004 by Alastair M. Robinson
5
* Distributed under the terms of the GNU General Public License -
6
* see the file named "COPYING" for more details.
14
#include "support/generaldialogs.h"
15
#include "pixbufthumbnail/egg-pixbuf-thumbnail.h"
16
#include "imagesource/pixbuf_from_imagesource.h"
17
#include "support/rotatepixbuf.h"
18
#include "support/maskpixbuf.h"
2
* layout.cpp - A superclass for layouts.
4
* Copyright (c) 2004 by Alastair M. Robinson
5
* Distributed under the terms of the GNU General Public License -
6
* see the file named "COPYING" for more details.
14
#include "support/generaldialogs.h"
15
#include "pixbufthumbnail/egg-pixbuf-thumbnail.h"
16
#include "imagesource/pixbuf_from_imagesource.h"
17
#include "support/rotatepixbuf.h"
18
#include "support/maskpixbuf.h"
20
20
#include "imagesource/imagesource.h"
21
#include "imagesource/imagesource_gdkpixbuf.h"
22
#include "imagesource/imagesource_cms.h"
23
#include "imagesource/imagesource_util.h"
24
#include "imagesource/imagesource_mask.h"
25
#include "imagesource/imagesource_rotate.h"
26
#include "imagesource/imagesource_promote.h"
28
#include "photoprint_state.h"
29
#include "support/progress.h"
31
#include "support/layoutrectangle.h"
38
ConfigTemplate LayoutDB::Template[]=
40
ConfigTemplate("LayoutType","NUp"),
45
Layout_ImageInfo::Layout_ImageInfo(Layout &layout, const char *filename, int page, bool allowcropping, PP_ROTATION rotation)
46
: page(page), allowcropping(allowcropping), crop_hpan(CENTRE), crop_vpan(CENTRE),
47
rotation(rotation), layout(layout), maskfilename(NULL), thumbnail(NULL), mask(NULL), transformed(NULL), selected(false),
48
customprofile(NULL), customintent(INTENT_DEFAULT)
52
if(filename[0]=='/' || filename[1]==':')
55
if(filename[0]=='\\' && filename[1]=='\\')
59
this->filename=BuildAbsoluteFilename(filename);
61
this->filename=strdup(filename);
67
Layout_ImageInfo::Layout_ImageInfo(Layout &layout, Layout_ImageInfo *ii, int page, bool allowcropping, PP_ROTATION rotation)
68
: page(page), allowcropping(allowcropping), crop_hpan(CENTRE), crop_vpan(CENTRE),
69
rotation(rotation), layout(layout), maskfilename(NULL), thumbnail(NULL), mask(NULL), transformed(NULL), selected(false),
70
customprofile(NULL), customintent(INTENT_DEFAULT)
72
cerr << "Stealing existing image!" << endl;
76
thumbnail=ii->thumbnail;
77
ii->thumbnail=NULL; // We steal the thumbnail from the old image!
79
ii->mask=NULL; // And the mask too!
21
#include "imagesource/imagesource_gdkpixbuf.h"
22
#include "imagesource/imagesource_cms.h"
23
#include "imagesource/imagesource_util.h"
24
#include "imagesource/imagesource_mask.h"
25
#include "imagesource/imagesource_rotate.h"
26
#include "imagesource/imagesource_promote.h"
28
#include "photoprint_state.h"
29
#include "support/progress.h"
31
#include "support/layoutrectangle.h"
38
ConfigTemplate LayoutDB::Template[]=
40
ConfigTemplate("LayoutType","NUp"),
45
Layout_ImageInfo::Layout_ImageInfo(Layout &layout, const char *filename, int page, bool allowcropping, PP_ROTATION rotation)
46
: PPEffectHeader(), page(page), allowcropping(allowcropping), crop_hpan(CENTRE), crop_vpan(CENTRE),
47
rotation(rotation), layout(layout), maskfilename(NULL), thumbnail(NULL), mask(NULL), transformed(NULL), selected(false),
48
customprofile(NULL), customintent(LCMSWRAPPER_INTENT_DEFAULT)
52
if(filename[0]=='/' || filename[1]==':')
55
if(filename[0]=='\\' && filename[1]=='\\')
59
this->filename=BuildAbsoluteFilename(filename);
61
this->filename=strdup(filename);
67
Layout_ImageInfo::Layout_ImageInfo(Layout &layout, Layout_ImageInfo *ii, int page, bool allowcropping, PP_ROTATION rotation)
68
: PPEffectHeader(), page(page), allowcropping(allowcropping), crop_hpan(CENTRE), crop_vpan(CENTRE),
69
rotation(rotation), layout(layout), maskfilename(NULL), thumbnail(NULL), mask(NULL), transformed(NULL), selected(false),
70
customprofile(NULL), customintent(LCMSWRAPPER_INTENT_DEFAULT)
72
cerr << "Stealing existing image!" << endl;
76
thumbnail=ii->thumbnail;
77
ii->thumbnail=NULL; // We steal the thumbnail from the old image!
79
ii->mask=NULL; // And the mask too!
81
81
customprofile=ii->customprofile;
82
82
ii->customprofile=NULL; // And the custom profile!
84
84
customintent=ii->customintent;
87
this->filename=strdup(ii->filename);
89
this->maskfilename=strdup(ii->maskfilename);
91
allowcropping=ii->allowcropping;
92
crop_hpan=ii->crop_hpan;
93
crop_vpan=ii->crop_vpan;
94
rotation=ii->rotation;
99
Layout_ImageInfo::~Layout_ImageInfo()
102
g_object_unref(thumbnail);
104
g_object_unref(mask);
106
g_object_unref(transformed);
107
layout.imagelist=g_list_remove(layout.imagelist,this);
87
this->filename=strdup(ii->filename);
89
this->maskfilename=strdup(ii->maskfilename);
91
allowcropping=ii->allowcropping;
92
crop_hpan=ii->crop_hpan;
93
crop_vpan=ii->crop_vpan;
94
rotation=ii->rotation;
99
Layout_ImageInfo::~Layout_ImageInfo()
102
g_object_unref(thumbnail);
104
g_object_unref(mask);
106
g_object_unref(transformed);
107
layout.imagelist=g_list_remove(layout.imagelist,this);
108
108
if(customprofile)
109
109
free(customprofile);
114
void Layout_ImageInfo::DrawThumbnail(GtkWidget *widget,int xpos,int ypos,int width,int height)
116
GdkPixbuf *thumbnail=GetThumbnail();
119
g_object_unref(transformed);
122
LayoutRectangle r(gdk_pixbuf_get_width(thumbnail),gdk_pixbuf_get_height(thumbnail));
123
LayoutRectangle target(xpos,ypos,width,height);
125
RectFit *fit=r.Fit(target,allowcropping,rotation,crop_hpan,crop_vpan);
127
cerr << "Scaling thumbnail" << endl;
130
switch(fit->rotation)
133
transformed=gdk_pixbuf_scale_simple(thumbnail,fit->width,fit->height,GDK_INTERP_NEAREST);
136
tmp=gdk_pixbuf_rotate_simple(thumbnail,GDK_PIXBUF_ROTATE_CLOCKWISE);
137
transformed=gdk_pixbuf_scale_simple(tmp,fit->width,fit->height,GDK_INTERP_NEAREST);
138
g_object_unref(G_OBJECT(tmp));
141
tmp=gdk_pixbuf_rotate_simple(thumbnail,GDK_PIXBUF_ROTATE_UPSIDEDOWN);
142
transformed=gdk_pixbuf_scale_simple(tmp,fit->width,fit->height,GDK_INTERP_NEAREST);
143
g_object_unref(G_OBJECT(tmp));
146
tmp=gdk_pixbuf_rotate_simple(thumbnail,GDK_PIXBUF_ROTATE_COUNTERCLOCKWISE);
147
transformed=gdk_pixbuf_scale_simple(tmp,fit->width,fit->height,GDK_INTERP_NEAREST);
148
g_object_unref(G_OBJECT(tmp));
161
if(dw>gdk_pixbuf_get_width(transformed))
163
cerr << "DW too high" << endl;
164
dw=gdk_pixbuf_get_width(transformed);
167
if(dh>gdk_pixbuf_get_height(transformed))
169
cerr << "DH too high" << endl;
170
dh=gdk_pixbuf_get_height(transformed);
173
cerr << "Done - drawing..." << endl;
176
maskpixbuf(transformed,fit->xoffset,fit->yoffset,dw,dh,mask);
178
gdk_draw_pixbuf(widget->window,NULL,transformed,
179
fit->xoffset,fit->yoffset,
182
GDK_RGB_DITHER_NONE,0,0);
184
cerr << "Done" << endl;
190
void Layout_ImageInfo::SetMask(const char *filename)
194
g_object_unref(mask);
203
maskfilename=strdup(filename);
207
GdkPixbuf *Layout_ImageInfo::GetThumbnail()
211
if(layout.state.batchmode)
214
if(maskfilename && !mask)
216
mask=egg_pixbuf_get_thumbnail_for_file (maskfilename, EGG_PIXBUF_THUMBNAIL_LARGE, &err);
217
cerr << "Attempting to load mask from: " << maskfilename << endl;
220
cerr << "Failed." << endl;
223
ImageSource *src=ISLoadImage(maskfilename);
227
w=(src->width*256)/src->height;
232
h=(src->height*256)/src->width;
234
src=ISScaleImageBySize(src,w,h,IS_SCALING_NEARESTNEIGHBOUR);
235
mask=pixbuf_from_imagesource(src);
239
catch(const char *err)
241
cerr << "Error: " << err << endl;
245
if(err && err->message)
246
cerr << "Error: " << err->message << endl;
248
cerr << "Can't get mask thumbnail" << endl;
114
void Layout_ImageInfo::DrawThumbnail(GtkWidget *widget,int xpos,int ypos,int width,int height)
116
GdkPixbuf *thumbnail=GetThumbnail();
119
g_object_unref(transformed);
122
LayoutRectangle r(gdk_pixbuf_get_width(thumbnail),gdk_pixbuf_get_height(thumbnail));
123
LayoutRectangle target(xpos,ypos,width,height);
125
RectFit *fit=r.Fit(target,allowcropping,rotation,crop_hpan,crop_vpan);
128
switch(fit->rotation)
131
transformed=gdk_pixbuf_scale_simple(thumbnail,fit->width,fit->height,GDK_INTERP_NEAREST);
134
tmp=gdk_pixbuf_rotate_simple(thumbnail,GDK_PIXBUF_ROTATE_CLOCKWISE);
135
transformed=gdk_pixbuf_scale_simple(tmp,fit->width,fit->height,GDK_INTERP_NEAREST);
136
g_object_unref(G_OBJECT(tmp));
139
tmp=gdk_pixbuf_rotate_simple(thumbnail,GDK_PIXBUF_ROTATE_UPSIDEDOWN);
140
transformed=gdk_pixbuf_scale_simple(tmp,fit->width,fit->height,GDK_INTERP_NEAREST);
141
g_object_unref(G_OBJECT(tmp));
144
tmp=gdk_pixbuf_rotate_simple(thumbnail,GDK_PIXBUF_ROTATE_COUNTERCLOCKWISE);
145
transformed=gdk_pixbuf_scale_simple(tmp,fit->width,fit->height,GDK_INTERP_NEAREST);
146
g_object_unref(G_OBJECT(tmp));
159
if(dw>gdk_pixbuf_get_width(transformed))
161
cerr << "DW too high" << endl;
162
dw=gdk_pixbuf_get_width(transformed);
165
if(dh>gdk_pixbuf_get_height(transformed))
167
cerr << "DH too high" << endl;
168
dh=gdk_pixbuf_get_height(transformed);
172
maskpixbuf(transformed,fit->xoffset,fit->yoffset,dw,dh,mask);
174
gdk_draw_pixbuf(widget->window,NULL,transformed,
175
fit->xoffset,fit->yoffset,
178
GDK_RGB_DITHER_NONE,0,0);
184
void Layout_ImageInfo::SetMask(const char *filename)
188
g_object_unref(mask);
197
maskfilename=strdup(filename);
202
GdkPixbuf *Layout_ImageInfo::GetThumbnailNoEffects()
206
if(layout.state.batchmode)
209
if(maskfilename && !mask)
211
mask=egg_pixbuf_get_thumbnail_for_file (maskfilename, EGG_PIXBUF_THUMBNAIL_LARGE, &err);
212
cerr << "Attempting to load mask from: " << maskfilename << endl;
215
cerr << "Failed." << endl;
218
ImageSource *src=ISLoadImage(maskfilename);
222
w=(src->width*256)/src->height;
227
h=(src->height*256)/src->width;
229
src=ISScaleImageBySize(src,w,h,IS_SCALING_NEARESTNEIGHBOUR);
230
mask=pixbuf_from_imagesource(src);
234
catch(const char *err)
236
cerr << "Error: " << err << endl;
240
if(err && err->message)
241
cerr << "Error: " << err->message << endl;
243
cerr << "Can't get mask thumbnail" << endl;
251
// return(thumbnail);
258
253
cerr << "Thumbnail not cached - loading..." << endl;
260
255
ImageSource *src=NULL;
262
thumbnail=egg_pixbuf_get_thumbnail_for_file (filename, EGG_PIXBUF_THUMBNAIL_LARGE, &err);
257
thumbnail=egg_pixbuf_get_thumbnail_for_file (filename, EGG_PIXBUF_THUMBNAIL_LARGE, &err);
266
261
cerr << "Can't get pixbuf - loading thumbnail via ImageSource..." << endl;
267
src=ISLoadImage(filename);
271
w=(src->width*256)/src->height;
276
h=(src->height*256)/src->width;
278
src=ISScaleImageBySize(src,w,h,IS_SCALING_NEARESTNEIGHBOUR);
279
thumbnail=pixbuf_from_imagesource(src);
284
if(err && err->message)
287
throw "Can't get thumbnail";
262
src=ISLoadImage(filename);
266
w=(src->width*256)/src->height;
271
h=(src->height*256)/src->width;
273
src=ISScaleImageBySize(src,w,h,IS_SCALING_NEARESTNEIGHBOUR);
274
thumbnail=pixbuf_from_imagesource(src);
279
if(err && err->message)
282
throw "Can't get thumbnail";
291
286
// If there's no display profile, then we can use the Default RGB profile instead...
292
287
cerr << "Checking for Display Profile..." << endl;
293
288
CMSProfile *targetprof;
294
289
CMColourDevice target=CM_COLOURDEVICE_NONE;
295
if((targetprof=layout.state.profilemanager.GetProfile(CM_COLOURDEVICE_DISPLAY)))
296
target=CM_COLOURDEVICE_DISPLAY;
290
if((targetprof=layout.state.profilemanager.GetProfile(CM_COLOURDEVICE_PRINTERPROOF)))
291
// target=CM_COLOURDEVICE_DISPLAY;
292
target=CM_COLOURDEVICE_PRINTERPROOF;
297
293
else if((targetprof=layout.state.profilemanager.GetProfile(CM_COLOURDEVICE_DEFAULTRGB)))
298
294
target=CM_COLOURDEVICE_DEFAULTRGB;
371
LayoutRectangle *Layout_ImageInfo::GetBounds()
373
// Dummy function - override in subclasses!
374
LayoutRectangle *result=new LayoutRectangle(0,0,100,100);
379
ImageSource *Layout_ImageInfo::GetImageSource(CMColourDevice target,CMTransformFactory *factory)
367
GdkPixbuf *Layout_ImageInfo::GetThumbnail()
372
GdkPixbuf *tn=GetThumbnailNoEffects();
375
ImageSource *src2=new ImageSource_GdkPixbuf(thumbnail);
376
src2=ApplyEffects(src2,PPEFFECT_PRESCALE);
377
GdkPixbuf *tn2=pixbuf_from_imagesource(src2);
379
g_object_unref(G_OBJECT(tn));
386
LayoutRectangle *Layout_ImageInfo::GetBounds()
388
// Dummy function - override in subclasses!
389
LayoutRectangle *result=new LayoutRectangle(0,0,100,100);
394
ImageSource *Layout_ImageInfo::GetImageSource(CMColourDevice target,CMTransformFactory *factory)
381
396
ImageSource *result=NULL;
384
cerr << "Loading image " << endl;
385
ImageSource *is=ISLoadImage(filename);
387
IS_TYPE colourspace=layout.GetColourSpace(target);
389
if(STRIP_ALPHA(is->type)==IS_TYPE_GREY)
390
is=new ImageSource_Promote(is,colourspace);
392
if(STRIP_ALPHA(is->type)==IS_TYPE_BW)
393
is=new ImageSource_Promote(is,colourspace);
395
CMSTransform *transform=NULL;
399
cerr << "Loading image " << endl;
400
ImageSource *is=ISLoadImage(filename);
402
is=ApplyEffects(is,PPEFFECT_PRESCALE);
404
IS_TYPE colourspace=layout.GetColourSpace(target);
406
if(STRIP_ALPHA(is->type)==IS_TYPE_GREY)
407
is=new ImageSource_Promote(is,colourspace);
409
if(STRIP_ALPHA(is->type)==IS_TYPE_BW)
410
is=new ImageSource_Promote(is,colourspace);
412
CMSTransform *transform=NULL;
400
417
if(customprofile)
401
418
emb=new CMSProfile(customprofile); // FIXME: Lifespan!
403
420
emb=is->GetEmbeddedProfile();
407
cerr << "Has embedded / assigned profile..." << endl;
408
transform=factory->GetTransform(target,emb,customintent); // FIXME: intent!
412
cerr << "No embedded profile - using default" << endl;
413
transform=factory->GetTransform(target,IS_TYPE(STRIP_ALPHA(is->type)),customintent);
417
is=new ImageSource_CMS(is,transform);
421
catch(const char *err)
423
ErrorMessage_Dialog(err);
429
ImageSource *Layout_ImageInfo::ApplyMask(ImageSource *is)
433
ImageSource *mask=ISLoadImage(maskfilename);
434
if((is->width>is->height)^(mask->width>mask->height))
436
mask=new ImageSource_Rotate(mask,90);
437
cerr << "Rotating mask" << endl;
439
mask=ISScaleImageBySize(mask,is->width,is->height,IS_SCALING_AUTOMATIC);
440
is=new ImageSource_Mask(is,mask);
446
bool Layout_ImageInfo::GetSelected()
452
void Layout_ImageInfo::SetSelected(bool sel)
458
void Layout_ImageInfo::ToggleSelected()
464
const char *Layout_ImageInfo::GetFilename()
424
cerr << "Has embedded / assigned profile..." << endl;
425
transform=factory->GetTransform(target,emb,customintent); // FIXME: intent!
429
cerr << "No embedded profile - using default" << endl;
430
transform=factory->GetTransform(target,IS_TYPE(STRIP_ALPHA(is->type)),customintent);
434
is=new ImageSource_CMS(is,transform);
438
catch(const char *err)
440
ErrorMessage_Dialog(err);
446
ImageSource *Layout_ImageInfo::ApplyMask(ImageSource *is)
450
ImageSource *mask=ISLoadImage(maskfilename);
451
if((is->width>is->height)^(mask->width>mask->height))
453
mask=new ImageSource_Rotate(mask,90);
454
cerr << "Rotating mask" << endl;
456
mask=ISScaleImageBySize(mask,is->width,is->height,IS_SCALING_AUTOMATIC);
457
is=new ImageSource_Mask(is,mask);
463
bool Layout_ImageInfo::GetSelected()
469
void Layout_ImageInfo::SetSelected(bool sel)
475
void Layout_ImageInfo::ToggleSelected()
481
const char *Layout_ImageInfo::GetFilename()
470
487
void Layout_ImageInfo::FlushThumbnail()
498
void Layout_ImageInfo::SetRenderingIntent(int intent)
515
void Layout_ImageInfo::SetRenderingIntent(LCMSWrapper_Intent intent)
500
517
FlushThumbnail();
501
518
customintent=intent;
505
int Layout_ImageInfo::GetRenderingIntent()
522
LCMSWrapper_Intent Layout_ImageInfo::GetRenderingIntent()
507
524
return(customintent);
511
Layout::Layout(PhotoPrint_State &state,Layout *oldlayout)
512
: xoffset(0), yoffset(0), pages(1), currentpage(0), backgroundfilename(NULL), background(NULL),
513
backgroundtransformed(NULL), state(state), imagelist(NULL), iterator(NULL), factory(NULL)
528
Layout::Layout(PhotoPrint_State &state,Layout *oldlayout)
529
: PageExtent(), xoffset(0), yoffset(0), pages(1), currentpage(0), backgroundfilename(NULL), background(NULL),
530
backgroundtransformed(NULL), state(state), imagelist(NULL), iterator(NULL), factory(NULL), gc(NULL)
515
532
factory=state.profilemanager.GetTransformFactory();
539
g_object_unref(G_OBJECT(gc));
523
if(backgroundtransformed)
524
g_object_unref(G_OBJECT(backgroundtransformed));
525
backgroundtransformed=NULL;
528
g_object_unref(G_OBJECT(background));
531
if(backgroundfilename)
532
free(backgroundfilename);
533
backgroundfilename=NULL;
537
for(unsigned int i=0;i<g_list_length(imagelist);++i)
539
GList *element=g_list_nth(imagelist,i);
540
Layout_ImageInfo *ii=(Layout_ImageInfo *)element->data;
544
g_list_free(imagelist);
553
for(unsigned int i=0;i<g_list_length(imagelist);++i)
555
GList *element=g_list_nth(imagelist,i);
556
Layout_ImageInfo *ii=(Layout_ImageInfo *)element->data;
560
g_list_free(imagelist);
566
// DUMMY FUNCTION - should be overridden by subclasses
567
int Layout::AddImage(const char *filename,bool allowcropping,PP_ROTATION rotation)
569
cerr << "AddImage: Dummy function - should be overridden" << endl;
574
// DUMMY FUNCTION - should be overridden by subclasses
575
void Layout::CopyImage(Layout_ImageInfo *ii)
577
cerr << "CopyImage: Dummy function - should be overridden" << endl;
581
ImageSource *Layout::GetImageSource(int page,CMColourDevice target,CMTransformFactory *factory,int res)
583
cerr << "GetImageSource: Dummy function - should be overridden" << endl;
588
IS_TYPE Layout::GetColourSpace(CMColourDevice target)
590
enum IS_TYPE colourspace=IS_TYPE_RGB;
591
CMSProfile *profile=state.profilemanager.GetProfile(target);
594
colourspace=profile->GetColourSpace();
598
const char *cs=state.FindString("PrintColourSpace");
599
if(strcmp(cs,"RGB")==0)
600
colourspace=IS_TYPE_RGB;
601
else if(strcmp(cs,"CMYK")==0)
602
colourspace=IS_TYPE_CMYK;
604
cerr << "PrintColourSpace is set to an unknown colour space!" << endl;
610
void Layout::TransferImages(Layout *oldlayout,Progress *p)
612
if(currentpage>=pages);
616
Layout_ImageInfo *ii=oldlayout->FirstImage();
620
ii=oldlayout->NextImage();
622
ii=oldlayout->FirstImage();
627
ii=oldlayout->NextImage();
630
if(!(p->DoProgress(img,count)))
635
if(currentpage>=pages)
640
void Layout::DBToLayout(LayoutDB &db)
642
state.printer.SetDriver(state.printoutput.FindString("Driver"));
646
void Layout::LayoutToDB(LayoutDB &db)
651
void Layout::Reflow()
656
GtkWidget *Layout::CreateWidget()
662
void Layout::RefreshWidget(GtkWidget *widget)
667
int Layout::GetCurrentPage()
673
void Layout::SetCurrentPage(int page)
679
void Layout::Print(Progress *p)
681
state.printer.SetProgress(p);
682
CMTransformFactory *factory=state.profilemanager.GetTransformFactory();
683
for(int p=0;p<GetPages();++p)
685
ImageSource *is=GetImageSource(p,CM_COLOURDEVICE_PRINTER,factory);
688
state.printer.Print(is,xoffset,yoffset);
693
state.printer.SetProgress(NULL);
696
void (*Layout::SetUnitFunc())(GtkWidget *wid,enum Units unit)
698
cerr << "This function should be overridden" << endl;
703
void Layout::DrawPreview(GtkWidget *widget,int xpos,int ypos,int width,int height)
705
Layout_ImageInfo *ii=FirstImage();
709
if(currentpage==ii->page)
710
ii->DrawThumbnail(widget,xpos,ypos,width,height);
716
Layout_ImageInfo *Layout::FirstImage()
720
return((Layout_ImageInfo *)iterator->data);
726
Layout_ImageInfo *Layout::NextImage()
729
iterator=g_list_next(iterator);
731
return((Layout_ImageInfo *)iterator->data);
737
int Layout::GetPages()
743
Layout_ImageInfo *Layout::FirstSelected()
745
Layout_ImageInfo *ii=FirstImage();
748
if(ii->GetSelected())
756
Layout_ImageInfo *Layout::NextSelected()
758
Layout_ImageInfo *ii=NextImage();
761
if(ii->GetSelected())
769
void Layout::SelectAll()
771
Layout_ImageInfo *ii=FirstImage();
774
ii->SetSelected(true);
780
void Layout::SelectNone()
782
Layout_ImageInfo *ii=FirstSelected();
785
ii->SetSelected(false);
791
Layout_ImageInfo *Layout::ImageAtCoord(int x,int y)
797
int Layout::GetCapabilities()
803
void Layout::SetBackground(const char *filename)
805
if(backgroundtransformed)
806
g_object_unref(G_OBJECT(backgroundtransformed));
807
backgroundtransformed=NULL;
810
g_object_unref(G_OBJECT(background));
813
if(backgroundfilename)
814
free(backgroundfilename);
815
backgroundfilename=NULL;
817
cerr << "Setting background..." << endl;
818
if(filename && strlen(filename)>0)
822
backgroundfilename=strdup(filename);
824
cerr << "Attempting to load background from: " << backgroundfilename << endl;
825
background=egg_pixbuf_get_thumbnail_for_file (backgroundfilename, EGG_PIXBUF_THUMBNAIL_LARGE, &err);
828
cerr << "Failed." << endl;
831
ImageSource *src=ISLoadImage(backgroundfilename);
835
w=(src->width*256)/src->height;
840
h=(src->height*256)/src->width;
842
src=ISScaleImageBySize(src,w,h,IS_SCALING_NEARESTNEIGHBOUR);
843
background=pixbuf_from_imagesource(src);
847
catch(const char *err)
849
cerr << "Error: " << err << endl;
853
if(err && err->message)
854
cerr << "Error: " << err->message << endl;
856
cerr << "Can't get mask thumbnail" << endl;
857
free(backgroundfilename);
858
backgroundfilename=NULL;
542
if(backgroundtransformed)
543
g_object_unref(G_OBJECT(backgroundtransformed));
544
backgroundtransformed=NULL;
547
g_object_unref(G_OBJECT(background));
550
if(backgroundfilename)
551
free(backgroundfilename);
552
backgroundfilename=NULL;
556
for(unsigned int i=0;i<g_list_length(imagelist);++i)
558
GList *element=g_list_nth(imagelist,i);
559
Layout_ImageInfo *ii=(Layout_ImageInfo *)element->data;
563
g_list_free(imagelist);
572
for(unsigned int i=0;i<g_list_length(imagelist);++i)
574
GList *element=g_list_nth(imagelist,i);
575
Layout_ImageInfo *ii=(Layout_ImageInfo *)element->data;
579
g_list_free(imagelist);
585
// DUMMY FUNCTION - should be overridden by subclasses
586
int Layout::AddImage(const char *filename,bool allowcropping,PP_ROTATION rotation)
588
cerr << "AddImage: Dummy function - should be overridden" << endl;
593
// DUMMY FUNCTION - should be overridden by subclasses
594
void Layout::CopyImage(Layout_ImageInfo *ii)
596
cerr << "CopyImage: Dummy function - should be overridden" << endl;
600
ImageSource *Layout::GetImageSource(int page,CMColourDevice target,CMTransformFactory *factory,int res)
602
cerr << "GetImageSource: Dummy function - should be overridden" << endl;
607
IS_TYPE Layout::GetColourSpace(CMColourDevice target)
609
enum IS_TYPE colourspace=IS_TYPE_RGB;
610
CMSProfile *profile=state.profilemanager.GetProfile(target);
613
colourspace=profile->GetColourSpace();
617
const char *cs=state.FindString("PrintColourSpace");
618
if(strcmp(cs,"RGB")==0)
619
colourspace=IS_TYPE_RGB;
620
else if(strcmp(cs,"CMYK")==0)
621
colourspace=IS_TYPE_CMYK;
623
cerr << "PrintColourSpace is set to an unknown colour space!" << endl;
629
void Layout::TransferImages(Layout *oldlayout,Progress *p)
631
if(currentpage>=pages);
635
Layout_ImageInfo *ii=oldlayout->FirstImage();
639
ii=oldlayout->NextImage();
641
ii=oldlayout->FirstImage();
646
ii=oldlayout->NextImage();
649
if(!(p->DoProgress(img,count)))
654
if(currentpage>=pages)
659
void Layout::DBToLayout(LayoutDB &db)
661
state.printer.SetDriver(state.printoutput.FindString("Driver"));
665
void Layout::LayoutToDB(LayoutDB &db)
670
void Layout::Reflow()
675
GtkWidget *Layout::CreateWidget()
681
void Layout::RefreshWidget(GtkWidget *widget)
686
int Layout::GetCurrentPage()
692
void Layout::SetCurrentPage(int page)
698
void Layout::Print(Progress *p)
700
state.printer.SetProgress(p);
701
CMTransformFactory *factory=state.profilemanager.GetTransformFactory();
702
for(int p=0;p<GetPages();++p)
704
ImageSource *is=GetImageSource(p,CM_COLOURDEVICE_PRINTER,factory);
707
state.printer.Print(is,xoffset,yoffset);
712
state.printer.SetProgress(NULL);
715
void (*Layout::SetUnitFunc())(GtkWidget *wid,enum Units unit)
717
cerr << "This function should be overridden" << endl;
722
void Layout::DrawPreviewBG(GtkWidget *widget,int xpos,int ypos,int width,int height)
731
// Use printer and monitor profiles to calculate "paper white".
732
// If there's no display profile, then we can use the Default RGB profile instead...
733
cerr << "Checking for Display Profile..." << endl;
734
CMSProfile *targetprof;
735
CMColourDevice target=CM_COLOURDEVICE_NONE;
736
if((targetprof=state.profilemanager.GetProfile(CM_COLOURDEVICE_PRINTERPROOF)))
737
target=CM_COLOURDEVICE_PRINTERPROOF;
738
else if((targetprof=state.profilemanager.GetProfile(CM_COLOURDEVICE_DEFAULTRGB)))
739
target=CM_COLOURDEVICE_DEFAULTRGB;
744
if(target!=CM_COLOURDEVICE_NONE)
746
CMSTransform *transform=NULL;
747
cerr << "Creating default->monitor transform..." << endl;
748
transform = factory->GetTransform(target,IS_TYPE_RGB,LCMSWRAPPER_INTENT_DEFAULT);
751
cerr << "Applying transform..." << endl;
753
ISDataType rgbtriple[3];
754
rgbtriple[0]=bgcol.red;
755
rgbtriple[1]=bgcol.green;
756
rgbtriple[2]=bgcol.blue;
757
transform->Transform(rgbtriple,rgbtriple,1);
758
bgcol.red=rgbtriple[0];
759
bgcol.green=rgbtriple[1];
760
bgcol.blue=rgbtriple[2];
764
gc=gdk_gc_new(widget->window);
765
gdk_gc_set_rgb_fg_color(gc,&bgcol);
767
gdk_draw_rectangle (widget->window,
773
LayoutRectangle sr(leftmargin,topmargin,
774
imageablewidth,imageableheight);
780
gdk_draw_rectangle (widget->window,
781
widget->style->mid_gc[widget->state],FALSE,
782
xpos+sr.x,ypos+sr.y,sr.w,sr.h);
786
void Layout::DrawPreview(GtkWidget *widget,int xpos,int ypos,int width,int height)
788
DrawPreviewBG(widget,xpos,ypos,width,height);
790
Layout_ImageInfo *ii=FirstImage();
794
if(currentpage==ii->page)
795
ii->DrawThumbnail(widget,xpos,ypos,width,height);
801
Layout_ImageInfo *Layout::FirstImage()
805
return((Layout_ImageInfo *)iterator->data);
811
Layout_ImageInfo *Layout::NextImage()
814
iterator=g_list_next(iterator);
816
return((Layout_ImageInfo *)iterator->data);
822
int Layout::GetPages()
828
Layout_ImageInfo *Layout::FirstSelected()
830
Layout_ImageInfo *ii=FirstImage();
833
if(ii->GetSelected())
841
Layout_ImageInfo *Layout::NextSelected()
843
Layout_ImageInfo *ii=NextImage();
846
if(ii->GetSelected())
854
void Layout::SelectAll()
856
Layout_ImageInfo *ii=FirstImage();
859
ii->SetSelected(true);
865
void Layout::SelectNone()
867
Layout_ImageInfo *ii=FirstSelected();
870
ii->SetSelected(false);
876
Layout_ImageInfo *Layout::ImageAtCoord(int x,int y)
882
int Layout::GetCapabilities()
888
void Layout::SetBackground(const char *filename)
890
if(backgroundtransformed)
891
g_object_unref(G_OBJECT(backgroundtransformed));
892
backgroundtransformed=NULL;
895
g_object_unref(G_OBJECT(background));
898
if(backgroundfilename)
899
free(backgroundfilename);
900
backgroundfilename=NULL;
902
cerr << "Setting background..." << endl;
903
if(filename && strlen(filename)>0)
907
backgroundfilename=strdup(filename);
909
cerr << "Attempting to load background from: " << backgroundfilename << endl;
910
background=egg_pixbuf_get_thumbnail_for_file (backgroundfilename, EGG_PIXBUF_THUMBNAIL_LARGE, &err);
913
cerr << "Failed." << endl;
916
ImageSource *src=ISLoadImage(backgroundfilename);
920
w=(src->width*256)/src->height;
925
h=(src->height*256)/src->width;
927
src=ISScaleImageBySize(src,w,h,IS_SCALING_NEARESTNEIGHBOUR);
928
background=pixbuf_from_imagesource(src);
932
catch(const char *err)
934
cerr << "Error: " << err << endl;
938
if(err && err->message)
939
cerr << "Error: " << err->message << endl;
941
cerr << "Can't get mask thumbnail" << endl;
942
free(backgroundfilename);
943
backgroundfilename=NULL;
865
950
void Layout::FlushThumbnails()