-
Notifications
You must be signed in to change notification settings - Fork 11
/
cbmpdata.cpp
1550 lines (1208 loc) · 45.2 KB
/
cbmpdata.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// $Id$
/* @@tag:xara-cn@@ DO NOT MODIFY THIS LINE
================================XARAHEADERSTART===========================
Xara LX, a vector drawing and manipulation program.
Copyright (C) 1993-2006 Xara Group Ltd.
Copyright on certain contributions may be held in joint with their
respective authors. See AUTHORS file for details.
LICENSE TO USE AND MODIFY SOFTWARE
----------------------------------
This file is part of Xara LX.
Xara LX is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License version 2 as published
by the Free Software Foundation.
Xara LX and its component source files are distributed in the hope
that it will be useful, but WITHOUT ANY WARRANTY; without even the
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with Xara LX (see the file GPL in the root directory of the
distribution); if not, write to the Free Software Foundation, Inc., 51
Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
ADDITIONAL RIGHTS
-----------------
Conditional upon your continuing compliance with the GNU General Public
License described above, Xara Group Ltd grants to you certain additional
rights.
The additional rights are to use, modify, and distribute the software
together with the wxWidgets library, the wxXtra library, and the "CDraw"
library and any other such library that any version of Xara LX relased
by Xara Group Ltd requires in order to compile and execute, including
the static linking of that library to XaraLX. In the case of the
"CDraw" library, you may satisfy obligation under the GNU General Public
License to provide source code by providing a binary copy of the library
concerned and a copy of the license accompanying it.
Nothing in this section restricts any of the rights you have under
the GNU General Public License.
SCOPE OF LICENSE
----------------
This license applies to this program (XaraLX) and its constituent source
files only, and does not necessarily apply to other Xara products which may
in part share the same code base, and are subject to their own licensing
terms.
This license does not apply to files in the wxXtra directory, which
are built into a separate library, and are subject to the wxWindows
license contained within that directory in the file "WXXTRA-LICENSE".
This license does not apply to the binary libraries (if any) within
the "libs" directory, which are subject to a separate license contained
within that directory in the file "LIBS-LICENSE".
ARRANGEMENTS FOR CONTRIBUTION OF MODIFICATIONS
----------------------------------------------
Subject to the terms of the GNU Public License (see above), you are
free to do whatever you like with your modifications. However, you may
(at your option) wish contribute them to Xara's source tree. You can
find details of how to do this at:
https://www.xaraxtreme.org/developers/
Prior to contributing your modifications, you will need to complete our
contributor agreement. This can be found at:
https://www.xaraxtreme.org/developers/contribute/
Please note that Xara will not accept modifications which modify any of
the text between the start and end of this header (marked
XARAHEADERSTART and XARAHEADEREND).
MARKS
-----
Xara, Xara LX, Xara X, Xara X/Xtreme, Xara Xtreme, the Xtreme and Xara
designs are registered or unregistered trademarks, design-marks, and/or
service marks of Xara Group Ltd. All rights in these marks are reserved.
Xara Group Ltd, Gaddesden Place, Hemel Hempstead, HP2 6EX, UK.
https://www.xara.com/
=================================XARAHEADEREND============================
*/
// A simple Dialog That does some Gavin Rendering into itself
#include "camtypes.h"
#include "bmpexprw.h"
#include "prvwmenu.h" // the context menu for the dialog
//#include "exprwres.h"
#include "giffiltr.h" // for TI_GIFFilter
//#include "selop.h" - in camtypes.h [AUTOMATICALLY REMOVED]
//#include "app.h" // for Document - in camtypes.h [AUTOMATICALLY REMOVED]
//#include "webprvw.h" // the resource strings for the web preview
#include "product.h" // the product name
#include "backgrnd.h"
#include "bmpexdoc.h"
#include "prvwflt.h"
#include "fileutil.h"
#include "bitmpinf.h"
#include "sgliboil.h"
#include "makebmp.h"
#include "filtimag.h" //The imagemap filter class
#include "filtimop.h" //The ImagemapFilterOptions class
#include "filtrmgr.h" //The Filter Manager - used to find the imagemap filter
//#include "resimmap.h" //Imagemap resources
#include "menucmds.h" // InvokeWeblink
//#include "bmpsdlgr.h" // _R(IDS_JPEG)
// This is not compulsory, but you may as well put it in so that the correct version
// of your file can be registered in the .exe
DECLARE_SOURCE("$Revision$");
// An implement to match the Declare in the .h file.
// If you have many classes, it is recommended to place them all together,
// here at the start of the file
CC_IMPLEMENT_MEMDUMP(BrowserPreviewOptions, CCObject)
CC_IMPLEMENT_DYNAMIC(BitmapPreviewData, CCObject)
// This will get Camelot to display the filename and linenumber of any memory allocations
// that are not released at program exit
#define new CAM_DEBUG_NEW
// this is a pointer to the path where the bitmap page background was exported
// to be displayed in the web stub
PathName * BitmapPreviewData::pPagePath = NULL;
////////////////////////////////////////////////////////////////////////////////////////////
// BrowserPreviewOptions section
/*******************************************************************************************
> BrowserPreviewOptions::BrowserPreviewOptions()
Author: Stefan_Stoykov (Xara Group Ltd) <[email protected]>
Created: 1/7/97
Purpose: Default Constructor
*******************************************************************************************/
BrowserPreviewOptions::BrowserPreviewOptions()
{
m_Background = BROWSER_BGR_NONE;
m_bInfo = TRUE;
m_bImagemap = TRUE;
m_pSpread = NULL;
}
/*******************************************************************************************
> BrowserPreviewOptions::BrowserPreviewOptions(BrowserBackground Bgr, BOOL bInfo,
BOOL bImagemap, ImagemapFilterOptions ifoToUse)
Author: Stefan_Stoykov (Xara Group Ltd) <[email protected]>
Created: 1/7/97
Purpose: Constructor - set the default values
*******************************************************************************************/
BrowserPreviewOptions::BrowserPreviewOptions(BrowserBackground Bgr, BOOL bInfo, BOOL bImagemap
, ImagemapFilterOptions ifoOptions)
{
m_Background = Bgr;
m_bInfo = bInfo;
m_bImagemap = bImagemap;
m_pSpread = NULL;
m_ifoImagemapOptions = ifoOptions;
}
/*******************************************************************************************
> void BrowserPreviewOptions::Get(BrowserBackground *pBgr, BOOL *pbInfo, BOOL *pbImagemap)
Author: Stefan_Stoykov (Xara Group Ltd) <[email protected]>
Created: 1/7/97
Purpose: Gets the values of the member variables
*******************************************************************************************/
void BrowserPreviewOptions::Get(BrowserBackground *pBgr, BOOL *pbInfo, BOOL *pbImagemap,
ImagemapFilterOptions* pifoOptions)
{
*pBgr = m_Background;
*pbInfo = m_bInfo;
*pbImagemap = m_bImagemap;
if (pifoOptions)
*pifoOptions=m_ifoImagemapOptions;
}
/*******************************************************************************************
> void BrowserPreviewOptions::Set(BrowserBackground Bgr, BOOL bInfo, BOOL bImagemap,
ImagemapFilterOPtions ifoToSet)
Author: Stefan_Stoykov (Xara Group Ltd) <[email protected]>
Created: 1/7/97
Purpose: Sets values for the member variables
*******************************************************************************************/
void BrowserPreviewOptions::Set(BrowserBackground Bgr, BOOL bInfo, BOOL bImagemap,
ImagemapFilterOptions ifoToSet)
{
m_Background = Bgr;
m_bInfo = bInfo;
m_bImagemap = bImagemap;
m_ifoImagemapOptions=ifoToSet;
}
/********************************************************************************************
> BrowserPreviewOptions::BrowserPreviewOptions(const BrowserPreviewOptions& obj)
Author: Ranbir_Rana (Xara Group Ltd) <[email protected]>
Created: 29/07/97
Scope: public
********************************************************************************************/
BrowserPreviewOptions::BrowserPreviewOptions(const BrowserPreviewOptions& obj)
{
m_Background = obj.m_Background;
m_bInfo = obj.m_bInfo;
m_bImagemap = obj.m_bImagemap;
m_pSpread = obj.m_pSpread;
m_ifoImagemapOptions = obj.m_ifoImagemapOptions;
}
////////////////////////////////////////////////////////////////////////////////////////////
// BitmapPreviewData section
/*******************************************************************************************
> BitmapPreviewData::BitmapPreviewData()
Author: Stefan_Stoykov (Xara Group Ltd) <[email protected]>
Created: 11/4/97
Purpose: Constructor
*******************************************************************************************/
BitmapPreviewData::BitmapPreviewData()
{
m_pBitmap = NULL;
m_FileSize = 0;
m_pOptions = NULL;
m_pTempHTMLPath = NULL;
m_bIsSameBitmap = TRUE;
}
/*******************************************************************************************
> BitmapPreviewData::~BitmapPreviewData()
Author: Stefan_Stoykov (Xara Group Ltd) <[email protected]>
Created: 11/4/97
Purpose: Destructor
*******************************************************************************************/
BitmapPreviewData::~BitmapPreviewData()
{
DeleteBitmapData();
}
/*******************************************************************************************
> void BitmapPreviewData::DeleteBitmapData()
Author: Stefan_Stoykov (Xara Group Ltd) <[email protected]>
Created: 11/4/97
Purpose: Removes all the data of the object, but only if its not shared with other
objects of the same type
*******************************************************************************************/
void BitmapPreviewData::DeleteBitmapData()
{
if (!m_bIsSameBitmap)
{
// delete the bitmap
if (m_pBitmap != NULL)
delete m_pBitmap;
m_pBitmap = NULL;
// delete the options
// SMFIX - Please dont delete my options these are only place holders, this class is NOT responsible for these objects
//if (m_pOptions != NULL)
// delete m_pOptions;
//m_pOptions = NULL;
}
// delete the html stub file
if (m_pTempHTMLPath != NULL)
{
// delete the temp file
FileUtil::DeleteFile(m_pTempHTMLPath);
// delete the path name
delete m_pTempHTMLPath;
}
m_pTempHTMLPath = NULL;
}
/*******************************************************************************************
> static BOOL BitmapPreviewData::ComposeHTMLColour(DocColour *pColour, String_32 &OutColour)
Author: Stefan_Stoykov (Xara Group Ltd) <[email protected]>
Created: 11/4/97
Inputs: pColour - pointer to a DocColour
Outputs: OutColour - string, where the converted colour is stored.
Purpose: Converts from a DocColour to a colour string in html format:
"#rrggbb", where rr - the red component, gg - the green, and rr - the blue.
All the components specify a hexadecimal value in the 00 - ff range.
*******************************************************************************************/
BOOL BitmapPreviewData::ComposeHTMLColour(DocColour *pColour, String_32 &OutColour)
{
if (pColour == NULL)
return FALSE;
// get the RGB values from the colour
INT32 R, G, B;
pColour->GetRGBValue(&R, &G, &B);
// convert this into a html colour string
OutColour = String_32( _T("#") );
String_32 c;
// add the red component
if (R < 16) // is a leading 0 required
OutColour += _T("0");
c._MakeMsg( _T("#1%X"), R % 256);
OutColour += c;
// the green component
if (G < 16)
OutColour += _T("0");
c._MakeMsg( _T("#1%X"), G % 256);
OutColour += c;
// the blue component
if (B < 16)
OutColour += _T("0");
c._MakeMsg( _T("#1%X"), B % 256);
OutColour += c;
return TRUE;
}
/*******************************************************************************************
> static BOOL BitmapPreviewData::ExportBrowserTypeBitmap(KernelBitmap *pBmp,PathName *pOutFile)
Author: Stefan_Stoykov (Xara Group Ltd) <[email protected]>
Created: 11/4/97
Inputs: pKernelBitmap - pointer to a Bitmap to be exported
pOutPath - the path to export the bitmap to
Purpose: Exports a kernel bitmap to a gif file, the gif preview filter is used, so
that no export options dialog box is displayed.
*******************************************************************************************/
BOOL BitmapPreviewData::ExportBrowserTypeBitmap(KernelBitmap *pBmp,PathName *pOutFile)
{
ERROR3IF(pBmp == NULL, "NULL param passed in ExportPreviewBitmap");
ERROR3IF(pOutFile == NULL, "NULL param passed in ExportPreviewBitmap");
if ((pBmp == NULL) || (pOutFile == NULL))
return FALSE;
// create a disk file
CCDiskFile TempDiskFile(1024, FALSE, TRUE);
// Find the gif preview filter for export (so we don't get an options dialog box)
Filter *pFilter = Filter::GetFirst();
while (pFilter != NULL)
{
if (IS_A(pFilter,PreviewFilterGIF))
// This is the filter!
break;
// Try the next filter
pFilter = Filter::GetNext(pFilter);
}
if (pFilter == NULL)
return FALSE; // filter not found
// get the preview bitmap filter, so no dialog box is displayed
PreviewFilterGIF *pGIFFilter = (PreviewFilterGIF *)pFilter;
BOOL ok = TRUE;
// create an operation for the export
SelOperation *pOp = new SelOperation;
if (pOp != NULL)
{
ok = pGIFFilter->DoExportBitmap(pOp, &TempDiskFile, pOutFile, pBmp);
// delete the created operation
delete pOp;
}
else
return FALSE;
// close the file
if (TempDiskFile.isOpen())
TempDiskFile.close();
return ok;
}
/*******************************************************************************************
> static BOOL BitmapPreviewData::SetBackgroundFromPage(CCDiskFile &DiskFile, Spread * pSpread = NULL)
Author: Stefan_Stoykov (Xara Group Ltd) <[email protected]>
Created: 11/4/97
Inputs: DiskFile - the file to write to
pSpread - the spread to pull the page background from
Purpose: Gets the current page background from the current document and generates an
HTML string which displays the same background on the HTML page. If a spread
has been specified then use that instead of the current document.
See Also: BitmapPreviewData::ComposeHTMLColour, BitmapPreviewData::ExportBrowserTypeBitmap
*******************************************************************************************/
BOOL BitmapPreviewData::SetBackgroundFromPage(CCDiskFile &DiskFile, Spread * pSpread)
{
String_256 s; // to contain the generated html strings
// If the user has not specified a spead then assume the selected spread in the current doc
if (pSpread == NULL)
{
// get the current doc
Document *pDoc = Document::GetCurrent();
ERROR3IF(pDoc == NULL, "No Current Document");
if (pDoc == NULL)
return FALSE;
pSpread = pDoc->GetSelectedSpread();
}
// get the page colour, or bitmap fill
KernelBitmap *pPageBmp = NULL;
DocColour *pPageColour = NULL;
OpBackground::GetPageColour(pSpread, &pPageBmp, &pPageColour);
BOOL Ok = TRUE;
// check for a bitmap page background first
if (pPageBmp != NULL) // the page background was a bitmap
{
// check if we haven't exported that bitmap before
if (pPagePath == NULL)
{
// alocate the path name
pPagePath = new PathName;
if (pPagePath)
{
// create a new temporary file
Ok = FileUtil::GetTemporaryPathName( _T("gif"), pPagePath);
}
else
Ok = FALSE;
}
// check if we have a valid path
if (Ok) Ok = pPagePath->IsValid();
// export the background bitmap into the a file
if (Ok && ExportBrowserTypeBitmap(pPageBmp, pPagePath))
{
// everything went ok, so add the link in the html file
s.MakeMsg(_R(IDS_HTML_BGIMAGE), (const TCHAR *)pPagePath->GetFileName());
DiskFile.write(s);
}
return Ok;
}
// If we recovered a page background colour then use that
// otherwise Page is by default white so set this as a background
BOOL AllocatedColour = FALSE;
if (pPageColour == NULL)
{
// Neither colour nor bitmap.
AllocatedColour = TRUE;
pPageColour = new DocColour(COLOUR_WHITE); // default colour of a page (white)
}
// convert to a browser colour
String_32 col;
if (ComposeHTMLColour(pPageColour,col))
{
// output the background colour
s.MakeMsg(_R(IDS_HTML_BGCOLOUR), (TCHAR *)col);
DiskFile.write(s);
}
else
Ok = FALSE;
if (AllocatedColour && pPageColour != NULL)
delete pPageColour;
return Ok;
}
/*******************************************************************************************
> static BOOL BitmapPreviewData::ExportImagemap(CCDiskFile &DiskFile, PathName *pPath,
ImagemapFilterOptions ifoOptionsToUse)
Author: Stefan_Stoykov (Xara Group Ltd) <[email protected]>
Created: 24/6/97
Inputs: -
Purpose: Generate a imagemap for our bitmap, and writes it out to our html page
*******************************************************************************************/
BOOL BitmapPreviewData::ExportImagemap(CCDiskFile &DiskFile, PathName *pPath, SelectionType Sel, DPI dpi,
ImagemapFilterOptions ifoOptionsToUse)
{
// sanity checks
ERROR3IF(pPath == NULL, "BitmapPreviewData::ExportImagemap - no file path to use");
if (dpi <= 0.0)
return FALSE;
//Rewritten by Graham 23/7/97
//First find the imagemap filter
ImagemapFilter* pImagemapFilter = (ImagemapFilter*) Filter::FindFilterFromID(FILTERID_IMAGEMAP);
if (pImagemapFilter == NULL) // no imagemap filter found
return FALSE;
//Now, we're going to set some imagemap filter options into the filter
//But before we do so, let's remember the old set of imagemap filter options
//so that the user doesn't get her defaults overridden
ImagemapFilterOptions ifoOld=pImagemapFilter->GetFilterOptions();
//Now, base our new set of options on the set we have been given
ImagemapFilterOptions ifoToSet=ifoOptionsToUse;
//But make the following changes
ifoToSet.m_strName="PreviewBitmapImagemap";
ifoToSet.m_stExportArea=Sel;
ifoToSet.m_dDPI=dpi;
ifoToSet.m_fClipboard=FALSE;
ifoToSet.m_fFile=TRUE;
ifoToSet.m_pthFile=*pPath;
ifoToSet.m_fInsert=TRUE;
ifoToSet.m_pfileFile=&DiskFile;
ifoToSet.m_fReportErrors=FALSE;
//Then set our new options back into the imagemap filter
pImagemapFilter->SetFilterOptions(ifoToSet);
//And tell the filter to export the file
BOOL ok= pImagemapFilter->PrepareAndWriteData(Document::GetCurrent());
//Finally, set the previous set of options back into the filter
pImagemapFilter->SetFilterOptions(ifoOld);
return ok; // return the result of the export
}
/*******************************************************************************************
> BOOL BitmapPreviewData::GenerateHTMLStub(BrowserPreviewOptions BrowserOptions)
Author: Stefan_Stoykov (Xara Group Ltd) <[email protected]>
Created: 24/6/97
Inputs: BrowserOptions - the options for generating the html page
Purpose: Generate a html file which includes our bitmap, together with some other optional
stuff. Used for browser preview.
*******************************************************************************************/
BOOL BitmapPreviewData::GenerateHTMLStub(BrowserPreviewOptions BrowserOptions)
{
PORTNOTE("other","Removed _R(IDD_TIMAPOPTIONS) - isn't wanted yet")
#ifndef EXCLUDE_FROM_XARALX
// sanity checks
// check for export options
ERROR3IF(m_pOptions == NULL, "BitmapPreviewData::GenerateHTMLStub - need export options");
if (m_pOptions == NULL) // we need export options
return FALSE;
// get the path for the exported bitmap from the options
PathName TempPath = m_pOptions->GetPathName();
// check for exported bitmap
ERROR3IF((m_pOptions->HasTempFile() == FALSE) || (TempPath.IsValid() == FALSE),
"BitmapPreviewData::GenerateHTMLStub - need exported bitmap");
if ((m_pOptions->HasTempFile() == FALSE) || (TempPath.IsValid() == FALSE))
return FALSE;
// delete the previous temp file, if any
if (m_pTempHTMLPath != NULL)
FileUtil::DeleteFile(m_pTempHTMLPath);
else
m_pTempHTMLPath = new PathName;
// safety check
if (m_pTempHTMLPath == NULL)
return FALSE;
// create a new temp file
if (FileUtil::GetTemporaryPathName( _T("htm"),m_pTempHTMLPath) == FALSE)
{
delete m_pTempHTMLPath;
m_pTempHTMLPath = NULL;
return FALSE;
}
// start creating the html page
// create a disk file
CCDiskFile TempDiskFile(1024, FALSE, TRUE);
// get path name to server, so we can find the logo bitmaps
CString str;
AfxGetModuleShortFileName(AfxGetInstanceHandle(), str);
String_256 strPathName(str.GetBuffer(0));
// create a path name object from the program name
PathName ProgramPath(strPathName);
try
{
// open it for reading
if (!TempDiskFile.open(*m_pTempHTMLPath, ios::out))
return FALSE;
// output header
String_256 s(_R(IDS_HTML_HEAD));
TempDiskFile.write(s);
// set the background attributes
switch (BrowserOptions.m_Background)
{
case BROWSER_BGR_DOC:
{
// set the background from the document page
if (!SetBackgroundFromPage(TempDiskFile, BrowserOptions.m_pSpread))
ERROR3("Setting the html background from the document page failed\n");
}
break;
case BROWSER_BGR_CHECKER:
{
// display the checkered bitmap as background
// get the checkered bitmap name
String_256 Checker(_R(IDS_HTML_CHECKER));
// set it in the path
ProgramPath.SetFileNameAndType(Checker);
// set the checkered bitmap as background image
s.MakeMsg(_R(IDS_CHECK_BACK), (TCHAR *)ProgramPath.GetWebAddress());
TempDiskFile.write(s);
}
break;
case BROWSER_BGR_BITMAP:
{
// set our bitmap as background image
s.MakeMsg(_R(IDS_BITMAPED_BACKGROUND), (TCHAR *)TempPath.GetWebAddress());
TempDiskFile.write(s);
}
break;
case BROWSER_BGR_NONE:
{
String_256 background(_R(IDS_PLAIN_BACKGROUND));
TempDiskFile.write(background);
}
break;
default:
ERROR3("Unknown type of BrowserOptions.m_Background");
break;
} // end of switch(BrowserOptions.m_Background) block
// Get a pointer to the actual bitmap so that we can get some details from it.
// OILBitmap *pOilBitmap = m_pBitmap->ActualBitmap;
// ERROR3IF(pOilBitmap == NULL,"BitmapPreviewData::GenerateBitmapInfoStrings NULL oil bitmap pointer");
// Get the details from the specified bitmap
// BitmapInfo BmInfo;
// pOilBitmap->GetInfo(&BmInfo);
// output our bitmap, but only if it wasn't already set as background
String_256 s2(_R(IDS_PAGE_TITLE));
TempDiskFile.write(s2);
if (BrowserOptions.m_Background != BROWSER_BGR_BITMAP)
{
// output the bitmap
if (m_pOptions->GetFilterType() == MAKE_BITMAP_FILTER)
{
// GIF animation
s.MakeMsg(_R(IDS_DISPLAY_PIC), (const TCHAR *)TempPath.GetFileName());
}
else
{
if( m_pOptions->GetFilterNameStrID() == _R(IDN_FILTERNAME_GIF) ||
m_pOptions->GetFilterNameStrID() == _R(IDS_JPG_EXP_FILTERNAME) ||
m_pOptions->GetFilterNameStrID() == _R(IDT_FILTERNAME_BMP) )
{
s.MakeMsg(_R(IDS_DISPLAY_BMP), (const TCHAR *)TempPath.GetFileName());
}
else
if( m_pOptions->GetFilterNameStrID() == _R(IDS_FILTERNAME_PNG) )
s.MakeMsg(_R(IDS_DISPLAY_PNG), (const TCHAR *)TempPath.GetFileName());
}
TempDiskFile.write(s);
}
else
{
s.MakeMsg(_R(IDS_EMPTY_BOX));
TempDiskFile.write(s);
}
switch (m_pOptions->GetFilterNameStrID())
{
case _R(IDT_FILTERNAME_BMP):
s2.MakeMsg(_R(IDS_BMP_MESSAGE));
s.MakeMsg(_R(IDS_WARNING_BOX), (TCHAR *)s2);
TempDiskFile.write(s);
break;
case _R(IDS_FILTERNAME_PNG):
s2.MakeMsg(_R(IDS_PNG_MESSAGE));
s.MakeMsg(_R(IDS_WARNING_BOX), (TCHAR *)s2);
TempDiskFile.write(s);
break;
} // end of switch(m_pOptions->GetFilterNameStrID())
s.MakeMsg(_R(IDS_DETAILS_BUILD));
TempDiskFile.write(s);
// output the bitmap info, if requested
if (BrowserOptions.m_bInfo != FALSE)
{
String_64 ImageSize;
String_64 FileSize;
BOOL m_bTransparent = FALSE;
INT32 count;
count=0;
// generate the info strings
if (m_pOptions->GetFilterType() == MAKE_BITMAP_FILTER)
{
// This is actually the export animated GIF using the frame gallery system
MakeBitmapExportOptions* pMkBOptions = (MakeBitmapExportOptions*)m_pOptions;
ERROR3IF(!pMkBOptions->IS_KIND_OF(MakeBitmapExportOptions), "pMkBOptions isn't");
PALETTE Palette = PAL_OPTIMISED;
DITHER DitherType;
UINT32 colDepth;
String_64 sPalette;
String_64 Dither;
UINT32 NoOfColours;
NoOfColours=m_pOptions->GetNumColsInPalette();
// Palette = pMkBOptions->GetPalette();
DitherType = pMkBOptions->GetDither();
colDepth = pMkBOptions->GetDepth();
s2.MakeMsg(_R(IDS_ANIMATED_GIF));
if (pMkBOptions->WantTransparent())
{
s2.MakeMsg(_R(IDS_TRANSPARENT),"animated GIF");
}
s.MakeMsg(_R(IDS_TEXTLINE_BR),(const TCHAR*)s2);
TempDiskFile.write(s);
switch (Palette)
{
case PAL_OPTIMISED:
sPalette.MakeMsg(_R(IDS_OPTIMISED_PAL));
break;
case PAL_BROWSER:
case PAL_STANDARD:
sPalette.MakeMsg(_R(IDS_BROWSER_PAL));
break;
case PAL_GLOBALOPTIMISED:
sPalette.MakeMsg(_R(IDS_GLOBAL_OPT));
break;
}
if (colDepth == 8 && (Palette == PAL_STANDARD || Palette == PAL_BROWSER) )
{
NoOfColours = 216;
}
switch (colDepth)
{
case 32:
case 24:
s2.MakeMsg(_R(IDS_TRUECOLOUR),colDepth);
break;
case 8:
{
// Include the transparent colour in the colour depth check
UINT32 RealNumberOfColours = NoOfColours;
if (colDepth <= 8 && pMkBOptions->WantTransparent())
{
UINT32 MaxColours = UINT32(pow(2,colDepth));
RealNumberOfColours++;
if (RealNumberOfColours > MaxColours)
RealNumberOfColours = MaxColours;
}
// We say 8 but we really mean the number of colours deep
// We cannot say 2 colours = 2bpp as we save it as 10 colours due
// to having 1 transparent colour and the usual lets pick 10 as the
// transparent colour. Cannot allow the user to choose 1 as the code
// then outputs 8bpp as GRenderOptPalette::GetOptimisedPalette has the
// test if (ReservedColours < NumColours), which fails.
/* if (RealNumberOfColours <= 2)
s2.MakeMsg(_R(IDS_PALETTEINFO),2,NoOfColours,(const TCHAR*)sPalette);
else */
if (RealNumberOfColours <= 16)
s2.MakeMsg(_R(IDS_PALETTEINFO),4,NoOfColours,(const TCHAR*)sPalette);
else
s2.MakeMsg(_R(IDS_AN_PALINFO),colDepth,NoOfColours,(const TCHAR*)sPalette);
break;
}
case 1:
s2.MakeMsg(_R(IDS_MONO),colDepth);
break;
case 4:
default:
s2.MakeMsg(_R(IDS_PALETTEINFO),colDepth,NoOfColours,(const TCHAR*)sPalette);
break;
}
TempDiskFile.write(s2);
s.MakeMsg(_R(IDS_NODITHER));
switch (DitherType)
{
case XARADITHER_ORDERED:
case XARADITHER_ORDERED_GREY:
Dither.MakeMsg(_R(IDS_DITH_ORDER));
s.MakeMsg(_R(IDS_DITHERING),(const TCHAR*) Dither);
break;
case XARADITHER_ERROR_DIFFUSION:
case XARADITHER_SIMPLE:
Dither.MakeMsg(_R(IDS_DITH_ERROR));
s.MakeMsg(_R(IDS_DITHERING),(const TCHAR*) Dither);
break;
case XARADITHER_NONE:
s.MakeMsg(_R(IDS_NODITHER));
break;
}
TempDiskFile.write(s);
} // if (m_pOptions->GetFilterType() == MAKE_BITMAP_FILTER) block ends
else
{
switch (m_pOptions->GetFilterNameStrID())
{
case _R(IDN_FILTERNAME_GIF):
{
GIFExportOptions* pGIFOptions = (GIFExportOptions*)m_pOptions;
ERROR3IF(!pGIFOptions->IS_KIND_OF(GIFExportOptions), "pGIFOptions isn't");
PALETTE Palette = PAL_OPTIMISED;
DITHER DitherType;
UINT32 colDepth;
String_64 sPalette;
String_64 Dither;
UINT32 NoOfColours;
NoOfColours=m_pOptions->GetNumColsInPalette();
// Palette = pGIFOptions->GetPalette();
DitherType = pGIFOptions->GetDither();
colDepth = pGIFOptions->GetDepth();
if (pGIFOptions->WantTransparent())
count=count+1;
if (pGIFOptions->WantInterlaced())
count=count+2;
s.MakeMsg(_R(IDS_GIF));
s2.MakeMsg(_R(IDS_A), (const TCHAR*)s);
switch (count)
{
case 1:
s2.MakeMsg(_R(IDS_TRANSPARENT),"GIF");
break;
case 2:
s2.MakeMsg(_R(IDS_INTERLACED),"GIF");
break;
case 3:
s2.MakeMsg(_R(IDS_INTER_TRANS),"GIF");
break;
case 0:
break;
}
s.MakeMsg(_R(IDS_TEXTLINE_BR),(const TCHAR*)s2);
TempDiskFile.write(s);
switch (Palette)
{
case PAL_OPTIMISED:
sPalette.MakeMsg(_R(IDS_OPTIMISED_PAL));
break;
case PAL_BROWSER:
case PAL_STANDARD:
sPalette.MakeMsg(_R(IDS_BROWSER_PAL));
break;
case PAL_GLOBALOPTIMISED:
sPalette.MakeMsg(_R(IDS_GLOBAL_OPT));
break;
}
if (colDepth == 8 && (Palette == PAL_STANDARD || Palette == PAL_BROWSER) )
{
NoOfColours = 216;
}
s2.MakeMsg(_R(IDS_PALETTEINFO),colDepth,NoOfColours,(const TCHAR*)sPalette);
if (colDepth == 8)
s2.MakeMsg(_R(IDS_AN_PALINFO),colDepth,NoOfColours,(const TCHAR*)sPalette);
if (colDepth == 1)
s2.MakeMsg(_R(IDS_MONO),colDepth);
if (colDepth > 8)
s2.MakeMsg(_R(IDS_TRUECOLOUR),colDepth);
TempDiskFile.write(s2);
s.MakeMsg(_R(IDS_NODITHER));
switch (DitherType)
{
case XARADITHER_ORDERED:
case XARADITHER_ORDERED_GREY:
Dither.MakeMsg(_R(IDS_DITH_ORDER));
s.MakeMsg(_R(IDS_DITHERING),(const TCHAR*) Dither);
break;
case XARADITHER_ERROR_DIFFUSION:
case XARADITHER_SIMPLE:
Dither.MakeMsg(_R(IDS_DITH_ERROR));
s.MakeMsg(_R(IDS_DITHERING),(const TCHAR*) Dither);
break;
case XARADITHER_NONE:
s.MakeMsg(_R(IDS_NODITHER));
break;
}
TempDiskFile.write(s);