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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
|
/*++
Copyright (c) 2005 Microsoft Corporation
All rights reserved.
THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
PARTICULAR PURPOSE.
File Name:
wmpthndlr.cpp
Abstract:
PageWatermark PrintTicket handler implementation. Derived from CPTHandler,
this provides PageWatermark specific Get and Set methods acting on the
PrintTicket passed (as a DOM document).
--*/
#include "precomp.h"
#include "debug.h"
#include "globals.h"
#include "xdstring.h"
#include "xdexcept.h"
#include "wmpthndlr.h"
using XDPrintSchema::PRINTTICKET_NAME;
using XDPrintSchema::NAME_ATTRIBUTE_NAME;
using XDPrintSchema::SCHEMA_DECIMAL;
using XDPrintSchema::SCHEMA_INTEGER;
using XDPrintSchema::SCHEMA_STRING;
using XDPrintSchema::PageWatermark::WatermarkData;
using XDPrintSchema::PageWatermark::EWatermarkOption;
using XDPrintSchema::PageWatermark::EWatermarkOptionMin;
using XDPrintSchema::PageWatermark::NoWatermark;
using XDPrintSchema::PageWatermark::TextWatermark;
using XDPrintSchema::PageWatermark::BitmapWatermark;
using XDPrintSchema::PageWatermark::VectorWatermark;
using XDPrintSchema::PageWatermark::EWatermarkOptionMax;
using XDPrintSchema::PageWatermark::ECommonWatermarkProps;
using XDPrintSchema::PageWatermark::ECommonWatermarkPropsMin;
using XDPrintSchema::PageWatermark::WidthOrigin;
using XDPrintSchema::PageWatermark::HeightOrigin;
using XDPrintSchema::PageWatermark::Transparency;
using XDPrintSchema::PageWatermark::Angle;
using XDPrintSchema::PageWatermark::ECommonWatermarkPropsMax;
using XDPrintSchema::PageWatermark::ETextWatermarkProps;
using XDPrintSchema::PageWatermark::ETextWatermarkPropsMin;
using XDPrintSchema::PageWatermark::FontColor;
using XDPrintSchema::PageWatermark::FontSize;
using XDPrintSchema::PageWatermark::Text;
using XDPrintSchema::PageWatermark::ETextWatermarkPropsMax;
using XDPrintSchema::PageWatermark::EVectBmpWatermarkProps;
using XDPrintSchema::PageWatermark::EVectBmpWatermarkPropsMin;
using XDPrintSchema::PageWatermark::WidthExtent;
using XDPrintSchema::PageWatermark::HeightExtent;
using XDPrintSchema::PageWatermark::EVectBmpWatermarkPropsMax;
using XDPrintSchema::PageWatermark::WATERMARK_FEATURE;
using XDPrintSchema::PageWatermark::WATERMARK_OPTIONS;
using XDPrintSchema::PageWatermark::CMN_WATERMARK_PROPS;
using XDPrintSchema::PageWatermark::TXT_WATERMARK_PROPS;
using XDPrintSchema::PageWatermark::VECTBMP_WATERMARK_PROPS;
using XDPrintSchema::PageWatermark::Layering::ELayeringOption;
using XDPrintSchema::PageWatermark::Layering::ELayeringOptionMin;
using XDPrintSchema::PageWatermark::Layering::Overlay;
using XDPrintSchema::PageWatermark::Layering::Underlay;
using XDPrintSchema::PageWatermark::Layering::ELayeringOptionMax;
using XDPrintSchema::PageWatermark::Layering::LAYERING_FEATURE;
using XDPrintSchema::PageWatermark::Layering::LAYERING_OPTIONS;
/*++
Routine Name:
CWMPTHandler::CWMPTHandler
Routine Description:
CWMPTHandler class constructor
Arguments:
pPrintTicket - Pointer to the DOM document representation of the PrintTicket
Return Value:
None
--*/
CWMPTHandler::CWMPTHandler(
_In_ IXMLDOMDocument2* pPrintTicket
) :
CPTHandler(pPrintTicket)
{
}
/*++
Routine Name:
CWMPTHandler::~CWMPTHandler
Routine Description:
CWMPTHandler class destructor
Arguments:
None
Return Value:
None
--*/
CWMPTHandler::~CWMPTHandler()
{
}
/*++
Routine Name:
CWMPTHandler::GetData
Routine Description:
The routine fills the data structure passed in with watermark data retrieved from
the PrintTicket passed to the class constructor.
Arguments:
pWmData - Pointer to the watermark data structure to be filled in
Return Value:
HRESULT
S_OK - On success
E_ELEMENT_NOT_FOUND - Feature not present in PrintTicket
E_* - On error
--*/
HRESULT
CWMPTHandler::GetData(
_Out_ WatermarkData* pWmData
)
{
HRESULT hr = S_OK;
if (SUCCEEDED(hr = CHECK_POINTER(pWmData, E_POINTER)))
{
CComBSTR bstrWMOption;
CComBSTR bstrLayerOption;
if (SUCCEEDED(hr = GetFeatureOption(CComBSTR(WATERMARK_FEATURE), &bstrWMOption)) &&
SUCCEEDED(hr = GetSubFeatureOption(CComBSTR(WATERMARK_FEATURE),
CComBSTR(LAYERING_FEATURE),
&bstrLayerOption)) &&
SUCCEEDED(hr = GetScoredPropertyValue(CComBSTR(WATERMARK_FEATURE),
CComBSTR(CMN_WATERMARK_PROPS[WidthOrigin]),
&pWmData->widthOrigin)) &&
SUCCEEDED(hr = GetScoredPropertyValue(CComBSTR(WATERMARK_FEATURE),
CComBSTR(CMN_WATERMARK_PROPS[HeightOrigin]),
&pWmData->heightOrigin)) &&
SUCCEEDED(hr = GetScoredPropertyValue(CComBSTR(WATERMARK_FEATURE),
CComBSTR(CMN_WATERMARK_PROPS[Transparency]),
&pWmData->transparency)) &&
SUCCEEDED(hr = GetScoredPropertyValue(CComBSTR(WATERMARK_FEATURE),
CComBSTR(CMN_WATERMARK_PROPS[Angle]),
&pWmData->angle)))
{
if (bstrWMOption == WATERMARK_OPTIONS[BitmapWatermark])
{
pWmData->type = BitmapWatermark;
if (SUCCEEDED(hr = GetScoredPropertyValue(CComBSTR(WATERMARK_FEATURE),
CComBSTR(VECTBMP_WATERMARK_PROPS[WidthExtent]),
&pWmData->widthExtent)))
{
hr = GetScoredPropertyValue(CComBSTR(WATERMARK_FEATURE),
CComBSTR(VECTBMP_WATERMARK_PROPS[HeightExtent]),
&pWmData->heightExtent);
}
}
else if (bstrWMOption == WATERMARK_OPTIONS[TextWatermark])
{
pWmData->type = TextWatermark;
if (SUCCEEDED(hr = GetScoredPropertyValue(CComBSTR(WATERMARK_FEATURE),
CComBSTR(TXT_WATERMARK_PROPS[FontColor]),
&pWmData->txtData.bstrFontColor)) &&
SUCCEEDED(hr = GetScoredPropertyValue(CComBSTR(WATERMARK_FEATURE),
CComBSTR(TXT_WATERMARK_PROPS[FontSize]),
&pWmData->txtData.fontSize)))
{
hr = GetScoredPropertyValue(CComBSTR(WATERMARK_FEATURE),
CComBSTR(TXT_WATERMARK_PROPS[Text]),
&pWmData->txtData.bstrText);
}
}
else if (bstrWMOption == WATERMARK_OPTIONS[VectorWatermark])
{
pWmData->type = VectorWatermark;
if (SUCCEEDED(hr = GetScoredPropertyValue(CComBSTR(WATERMARK_FEATURE),
CComBSTR(VECTBMP_WATERMARK_PROPS[WidthExtent]),
&pWmData->widthExtent)))
{
hr = GetScoredPropertyValue(CComBSTR(WATERMARK_FEATURE),
CComBSTR(VECTBMP_WATERMARK_PROPS[HeightExtent]),
&pWmData->heightExtent);
}
}
else
{
hr = E_FAIL;
}
if (SUCCEEDED(hr))
{
if (bstrLayerOption == LAYERING_OPTIONS[Underlay])
{
pWmData->layering = Underlay;
}
else if (bstrLayerOption == LAYERING_OPTIONS[Overlay])
{
pWmData->layering = Overlay;
}
else
{
hr = E_FAIL;
}
}
}
if (hr == E_ELEMENT_NOT_FOUND)
{
pWmData->type = NoWatermark;
}
}
//
// Validate the data
//
if (SUCCEEDED(hr))
{
if (pWmData->type < EWatermarkOptionMin ||
pWmData->type >= EWatermarkOptionMax ||
pWmData->layering < ELayeringOptionMin ||
pWmData->layering >= ELayeringOptionMax)
{
hr = E_FAIL;
}
}
ERR_ON_HR_EXC(hr, E_ELEMENT_NOT_FOUND);
return hr;
}
/*++
Routine Name:
CWMPTHandler::SetData
Routine Description:
This routine sets the watermark data in the PrintTicket passed to the
class constructor.
Arguments:
pWmData - Pointer to the watermark data to be set in the PrintTicket
Return Value:
HRESULT
S_OK - On success
E_* - On error
--*/
HRESULT
CWMPTHandler::SetData(
_In_ CONST WatermarkData* pWmData
)
{
HRESULT hr = S_OK;
if (SUCCEEDED(hr = CHECK_POINTER(pWmData, E_POINTER)))
{
try
{
//
// Remove any existing watermark feature node
//
if (SUCCEEDED(hr = Delete()) &&
pWmData->type != NoWatermark)
{
//
// Construct the appropriate watermark element
//
CComPtr<IXMLDOMElement> pWMDataElem(NULL);
PTDOMElementVector paramInitList;
switch (pWmData->type)
{
case TextWatermark:
{
hr = CreateTextWMElements(pWmData, &pWMDataElem, ¶mInitList);
}
break;
case BitmapWatermark:
{
hr = CreateBitmapWMElements(pWmData, &pWMDataElem, ¶mInitList);
}
break;
case VectorWatermark:
{
hr = CreateVectorWMElements(pWmData, &pWMDataElem, ¶mInitList);
}
break;
default:
{
hr = E_FAIL;
}
break;
}
//
// Insert the watermark and paramater init nodes
//
CComPtr<IXMLDOMNode> pPTRoot(NULL);
CComBSTR bstrPTQuery(m_bstrFrameworkPrefix);
bstrPTQuery += PRINTTICKET_NAME;
if (SUCCEEDED(hr) &&
SUCCEEDED(hr = GetNode(bstrPTQuery, &pPTRoot)))
{
hr = pPTRoot->appendChild(pWMDataElem, NULL);
PTDOMElementVector::iterator iterParamInit = paramInitList.begin();
for (;iterParamInit != paramInitList.end() && SUCCEEDED(hr); iterParamInit++)
{
hr = pPTRoot->appendChild(*iterParamInit, NULL);
}
}
}
}
catch (exception& DBG_ONLY(e))
{
ERR(e.what());
hr = E_FAIL;
}
}
ERR_ON_HR(hr);
return hr;
}
/*++
Routine Name:
CWMPTHandler::Delete
Routine Description:
This routine deletes the watermark feature from the PrintTicket passed to the
class constructor
Arguments:
None
Return Value:
HRESULT
S_OK - On success
E_* - On error
--*/
HRESULT
CWMPTHandler::Delete(
VOID
)
{
//
// Remove any existing watermark feature node
//
HRESULT hr = DeleteFeature(CComBSTR(WATERMARK_FEATURE));
ERR_ON_HR(hr);
return hr;
}
/*++
Routine Name:
CWMPTHandler::CreateCommonWMElements
Routine Description:
This routine creates all the DOM elements common to all Watermark types. Note that
this routine also returns the option element seperately (so the caller can specify the
watermark type) and a list of the ParameterInit elements (so the caller can append them
to the root PrintTicket element)
Arguments:
pWmData - Pointer to the watermark data structure
ppWMDataElem - Pointer to an IXMLDOMElement pointer that recieves feature element
ppOptionElem - Pointer to an IXMLDOMElement pointer that recieves option element
pParamInitList - Pointer to a vector of DOM element pointers that recieves the parameter init elements
Return Value:
HRESULT
S_OK - On success
E_* - On error
--*/
HRESULT
CWMPTHandler::CreateCommonWMElements(
_In_ CONST WatermarkData* pWmData,
_Outptr_ IXMLDOMElement** ppWMDataElem,
_Outptr_ IXMLDOMElement** ppOptionElem,
_Out_ PTDOMElementVector* pParamInitList
)
{
HRESULT hr = S_OK;
if (SUCCEEDED(hr = CHECK_POINTER(pWmData, E_POINTER)) &&
SUCCEEDED(hr = CHECK_POINTER(ppWMDataElem, E_POINTER)) &&
SUCCEEDED(hr = CHECK_POINTER(ppOptionElem, E_POINTER)) &&
SUCCEEDED(hr = CHECK_POINTER(pParamInitList, E_POINTER)))
{
*ppWMDataElem = NULL;
if (pWmData->layering < ELayeringOptionMin ||
pWmData->layering >= ELayeringOptionMax)
{
hr = E_INVALIDARG;
}
}
if (SUCCEEDED(hr))
{
//
// Create the feature option pair - CreateFeatureOptionPair does not
// set the option name, this is done in the calling function
//
if (SUCCEEDED(hr = CreateFeatureOptionPair(CComBSTR(WATERMARK_FEATURE), ppWMDataElem, ppOptionElem)))
{
//
// Over all common properties, create and insert the element
//
for (ECommonWatermarkProps cmnProps = ECommonWatermarkPropsMin;
cmnProps < ECommonWatermarkPropsMax && SUCCEEDED(hr);
cmnProps = static_cast<ECommonWatermarkProps>(cmnProps + 1))
{
//
// Create the scored property element
//
CComPtr<IXMLDOMElement> pScoredProperty(NULL);
if (SUCCEEDED(hr = CreateScoredProperty(CComBSTR(CMN_WATERMARK_PROPS[cmnProps]), &pScoredProperty)))
{
//
// Construct the param ref and param init elements
//
CComBSTR bstrPRefName(WATERMARK_FEATURE);
if (wcscmp(CMN_WATERMARK_PROPS[cmnProps], L"Angle") == 0)
{
bstrPRefName += L"Text";
}
bstrPRefName += CMN_WATERMARK_PROPS[cmnProps];
CComPtr<IXMLDOMElement> pParamRef(NULL);
CComPtr<IXMLDOMElement> pParamInit(NULL);
CComBSTR bstrType;
CComBSTR bstrValue;
if (SUCCEEDED(hr = GetCmnPropTypeAndValue(pWmData, cmnProps, &bstrType, &bstrValue)) &&
SUCCEEDED(hr = CreateParamRefInitPair(bstrPRefName, bstrType, bstrValue, &pParamRef, &pParamInit)))
{
//
// Append the parameter ref element to the scored property, append the
// scored property to the option element and add the parameter init
// element to the vector
//
CComPtr<IXMLDOMNode> pPRInserted(NULL);
CComPtr<IXMLDOMNode> pSPInserted(NULL);
if (SUCCEEDED(hr = pScoredProperty->appendChild(pParamRef, &pPRInserted)) &&
SUCCEEDED(hr = (*ppOptionElem)->appendChild(pScoredProperty, &pSPInserted)))
{
try
{
pParamInitList->push_back(pParamInit);
}
catch (exception& DBG_ONLY(e))
{
ERR(e.what());
hr = E_FAIL;
}
}
}
}
}
}
//
// Create the layering feature
//
CComPtr<IXMLDOMElement> pLayeringElement(NULL);
CComPtr<IXMLDOMElement> pLayeringOptionElement(NULL);
CComBSTR bstrAttribName(m_bstrKeywordsPrefix);
bstrAttribName += LAYERING_OPTIONS[pWmData->layering];
if (SUCCEEDED(hr) &&
SUCCEEDED(hr = CreateFeatureOptionPair(CComBSTR(LAYERING_FEATURE),
CComBSTR(LAYERING_OPTIONS[pWmData->layering]),
&pLayeringElement,
&pLayeringOptionElement)))
{
//
// Append the layering feature to the watermark feature node
//
hr = (*ppWMDataElem)->appendChild(pLayeringElement, NULL);
}
}
ERR_ON_HR(hr);
return hr;
}
/*++
Routine Name:
CWMPTHandler::CreateCommonVectBmpWMElements
Routine Description:
This routine creates all the DOM elements common to all the vector and bitmap Watermark types.
Arguments:
pWmData - Pointer to the watermark data structure
pOptionElem - Pointer to an IXMLDOMElement to append the elements to
pParamInitList - Pointer to a vector of DOM element pointers that recieves the parameter init elements
Return Value:
HRESULT
S_OK - On success
E_* - On error
--*/
HRESULT
CWMPTHandler::CreateCommonVectBmpWMElements(
_In_ CONST WatermarkData* pWmData,
_In_ IXMLDOMElement* pOptionElem,
_Out_ PTDOMElementVector* pParamInitList
)
{
HRESULT hr = S_OK;
if (SUCCEEDED(hr = CHECK_POINTER(pWmData, E_POINTER)) &&
SUCCEEDED(hr = CHECK_POINTER(pOptionElem, E_POINTER)) &&
SUCCEEDED(hr = CHECK_POINTER(pParamInitList, E_POINTER)))
{
//
// Over all common properties, create and insert the element
//
for (EVectBmpWatermarkProps vectBmpProps = EVectBmpWatermarkPropsMin;
vectBmpProps < EVectBmpWatermarkPropsMax && SUCCEEDED(hr);
vectBmpProps = static_cast<EVectBmpWatermarkProps>(vectBmpProps + 1))
{
//
// Create the scored property element
//
CComPtr<IXMLDOMElement> pScoredProperty(NULL);
if (SUCCEEDED(hr = CreateScoredProperty(CComBSTR(VECTBMP_WATERMARK_PROPS[vectBmpProps]), &pScoredProperty)))
{
//
// Construct the param ref and param init elements
//
CComBSTR bstrPRefName(WATERMARK_FEATURE);
bstrPRefName += VECTBMP_WATERMARK_PROPS[vectBmpProps];
CComPtr<IXMLDOMElement> pParamRef(NULL);
CComPtr<IXMLDOMElement> pParamInit(NULL);
CComBSTR bstrType;
CComBSTR bstrValue;
if (SUCCEEDED(hr = GetCmnVectBmpPropTypeAndValue(pWmData, vectBmpProps, &bstrType, &bstrValue)) &&
SUCCEEDED(hr = CreateParamRefInitPair(bstrPRefName, bstrType, bstrValue, &pParamRef, &pParamInit)))
{
//
// Append the parameter ref element to the scored property, append the
// scored property to the option element and add the parameter init
// element to the vector
//
CComPtr<IXMLDOMNode> pPRInserted(NULL);
CComPtr<IXMLDOMNode> pSPInserted(NULL);
if (SUCCEEDED(hr = pScoredProperty->appendChild(pParamRef, &pPRInserted)) &&
SUCCEEDED(hr = pOptionElem->appendChild(pScoredProperty, &pSPInserted)))
{
try
{
pParamInitList->push_back(pParamInit);
}
catch (exception& DBG_ONLY(e))
{
ERR(e.what());
hr = E_FAIL;
}
}
}
}
}
}
ERR_ON_HR(hr);
return hr;
}
/*++
Routine Name:
CWMPTHandler::CreateTextWMElements
Routine Description:
This routine creates a text watermark feature in the PrintTicket
Arguments:
pWmData - Pointer to the watermark data structure
ppWMDataElem - Pointer to an IXMLDOMElement pointer that recieves feature element
pParamInitList - P:ointer to a vector of DOM element pointers that recieves the parameter init elements
Return Value:
HRESULT
S_OK - On success
E_* - On error
--*/
HRESULT
CWMPTHandler::CreateTextWMElements(
_In_ CONST WatermarkData* pWmData,
_Outptr_ IXMLDOMElement** ppWMDataElem,
_Out_ PTDOMElementVector* pParamInitList
)
{
HRESULT hr = S_OK;
CComPtr<IXMLDOMElement> pOptionElem(NULL);
if (SUCCEEDED(hr = CHECK_POINTER(pWmData, E_POINTER)) &&
SUCCEEDED(hr = CHECK_POINTER(ppWMDataElem, E_POINTER)) &&
SUCCEEDED(hr = CHECK_POINTER(pParamInitList, E_POINTER)) &&
SUCCEEDED(hr = CreateCommonWMElements(pWmData, ppWMDataElem, &pOptionElem, pParamInitList)))
{
//
// Set the option node name attribute
//
CComBSTR bstrAttribName(m_bstrKeywordsPrefix);
bstrAttribName += WATERMARK_OPTIONS[TextWatermark];
hr = CreateXMLAttribute(pOptionElem, NAME_ATTRIBUTE_NAME, NULL, bstrAttribName );
}
//
// Write out the text specific options
//
if (SUCCEEDED(hr))
{
for (ETextWatermarkProps txtProps = ETextWatermarkPropsMin;
txtProps < ETextWatermarkPropsMax && SUCCEEDED(hr);
txtProps = static_cast<ETextWatermarkProps>(txtProps + 1))
{
//
// Create the scored property element
//
CComPtr<IXMLDOMElement> pScoredProperty(NULL);
if (SUCCEEDED(hr = CreateScoredProperty(CComBSTR(TXT_WATERMARK_PROPS[txtProps]), &pScoredProperty)))
{
//
// Construct the param ref and param init elements
//
CComBSTR bstrPRefName(WATERMARK_FEATURE);
bstrPRefName += TXT_WATERMARK_PROPS[txtProps];
CComPtr<IXMLDOMElement> pParamRef(NULL);
CComPtr<IXMLDOMElement> pParamInit(NULL);
CComBSTR bstrType;
CComBSTR bstrValue;
if (SUCCEEDED(hr = GetTxtPropTypeAndValue(pWmData, txtProps, &bstrType, &bstrValue)) &&
SUCCEEDED(hr = CreateParamRefInitPair(bstrPRefName, bstrType, bstrValue, &pParamRef, &pParamInit)))
{
//
// Append the parameter ref element to the scored property, append the
// scored property to the option element and add the parameter init
// element to the param init list
//
CComPtr<IXMLDOMNode> pPRInserted(NULL);
CComPtr<IXMLDOMNode> pSPInserted(NULL);
if (SUCCEEDED(hr = pScoredProperty->appendChild(pParamRef, &pPRInserted)) &&
SUCCEEDED(hr = pOptionElem->appendChild(pScoredProperty, &pSPInserted)))
{
try
{
pParamInitList->push_back(pParamInit);
}
catch (exception& DBG_ONLY(e))
{
ERR(e.what());
hr = E_FAIL;
}
}
}
}
}
}
ERR_ON_HR(hr);
return hr;
}
/*++
Routine Name:
CWMPTHandler::CreateBitmapWMElements
Routine Description:
This routine creates a bitmap watermark feature in the PrintTicket
Arguments:
pWmData - Pointer to the watermark data structure
ppWMDataElem - Pointer to an IXMLDOMElement pointer that recieves feature element
pParamInitList - P:ointer to a vector of DOM element pointers that recieves the parameter init elements
Return Value:
HRESULT
S_OK - On success
E_* - On error
--*/
HRESULT
CWMPTHandler::CreateBitmapWMElements(
_In_ CONST WatermarkData* pWmData,
_Outptr_ IXMLDOMElement** ppWMDataElem,
_Out_ PTDOMElementVector* pParamInitList
)
{
HRESULT hr = S_OK;
CComPtr<IXMLDOMElement> pOptionElem(NULL);
if (SUCCEEDED(hr = CHECK_POINTER(pWmData, E_POINTER)) &&
SUCCEEDED(hr = CHECK_POINTER(ppWMDataElem, E_POINTER)) &&
SUCCEEDED(hr = CHECK_POINTER(pParamInitList, E_POINTER)) &&
SUCCEEDED(hr = CreateCommonWMElements(pWmData, ppWMDataElem, &pOptionElem, pParamInitList)) &&
SUCCEEDED(hr = CreateCommonVectBmpWMElements(pWmData, pOptionElem, pParamInitList)))
{
//
// Set the option node name attribute
//
CComBSTR bstrAttribName(m_bstrKeywordsPrefix);
bstrAttribName += WATERMARK_OPTIONS[BitmapWatermark];
hr = CreateXMLAttribute(pOptionElem, NAME_ATTRIBUTE_NAME, NULL, bstrAttribName );
}
ERR_ON_HR(hr);
return hr;
}
/*++
Routine Name:
CWMPTHandler::CreateVectorWMElements
Routine Description:
This routine creates a vector watermark feature in the PrintTicket
Arguments:
pWmData - Pointer to the watermark data structure
ppWMDataElem - Pointer to an IXMLDOMElement pointer that recieves feature element
pParamInitList - P:ointer to a vector of DOM element pointers that recieves the parameter init elements
Return Value:
HRESULT
S_OK - On success
E_* - On error
--*/
HRESULT
CWMPTHandler::CreateVectorWMElements(
_In_ CONST WatermarkData* pWmData,
_Outptr_ IXMLDOMElement** ppWMDataElem,
_Out_ PTDOMElementVector* pParamInitList
)
{
HRESULT hr = S_OK;
CComPtr<IXMLDOMElement> pOptionElem(NULL);
if (SUCCEEDED(hr = CHECK_POINTER(pWmData, E_POINTER)) &&
SUCCEEDED(hr = CHECK_POINTER(ppWMDataElem, E_POINTER)) &&
SUCCEEDED(hr = CHECK_POINTER(pParamInitList, E_POINTER)) &&
SUCCEEDED(hr = CreateCommonWMElements(pWmData, ppWMDataElem, &pOptionElem, pParamInitList)) &&
SUCCEEDED(hr = CreateCommonVectBmpWMElements(pWmData, pOptionElem, pParamInitList)))
{
//
// Set the option node name attribute
//
CComBSTR bstrAttribName(m_bstrKeywordsPrefix);
bstrAttribName += WATERMARK_OPTIONS[VectorWatermark];
hr = CreateXMLAttribute(pOptionElem, NAME_ATTRIBUTE_NAME, NULL, bstrAttribName );
}
ERR_ON_HR(hr);
return hr;
}
/*++
Routine Name:
CWMPTHandler::GetCmnPropTypeAndValue
Routine Description:
This routine initalises the type and value strings for a given common watermark property
Arguments:
pWmData - Pointer to a watermark data structure with the watermark settings
cmnProps - The watermark setting to retrieve the type and value for
pbstrType - Pointer to a BSTR that recieves the type of the value
pbstrValue - Pointer to a BSTR that recieves the value as a string
Return Value:
HRESULT
S_OK - On success
E_* - On error
--*/
HRESULT
CWMPTHandler::GetCmnPropTypeAndValue(
_In_ CONST WatermarkData* pWmData,
_In_ CONST ECommonWatermarkProps cmnProps,
_Outptr_ BSTR* pbstrType,
_Outptr_ BSTR* pbstrValue
)
{
HRESULT hr = S_OK;
if (SUCCEEDED(hr = CHECK_POINTER(pWmData, E_POINTER)) &&
SUCCEEDED(hr = CHECK_POINTER(pbstrType, E_POINTER)) &&
SUCCEEDED(hr = CHECK_POINTER(pbstrValue, E_POINTER)))
{
if (cmnProps < ECommonWatermarkPropsMin ||
cmnProps >= ECommonWatermarkPropsMax)
{
hr = E_INVALIDARG;
}
}
if (SUCCEEDED(hr))
{
try
{
CStringXDW cstrType;
CStringXDW cstrValue;
switch (cmnProps)
{
case WidthOrigin:
{
cstrType = SCHEMA_INTEGER;
cstrValue.Format(L"%i", pWmData->widthOrigin);
}
break;
case HeightOrigin:
{
cstrType = SCHEMA_INTEGER;
cstrValue.Format(L"%i", pWmData->heightOrigin);
}
break;
case Transparency:
{
cstrType = SCHEMA_INTEGER;
cstrValue.Format(L"%i", pWmData->transparency);
}
break;
case Angle:
{
cstrType = SCHEMA_INTEGER;
cstrValue.Format(L"%i", pWmData->angle);
}
break;
default:
{
hr = E_FAIL;
ERR("Unknown common watermark property\n");
}
break;
}
if (SUCCEEDED(hr))
{
*pbstrType = cstrType.AllocSysString();
*pbstrValue = cstrValue.AllocSysString();
}
}
catch (CXDException& e)
{
hr = e;
}
}
ERR_ON_HR(hr);
return hr;
}
/*++
Routine Name:
CWMPTHandler::GetCmnVectBmpPropTypeAndValue
Routine Description:
This routine initalises the type and value strings for a common vector and bitmap
watermark properties
Arguments:
pWmData - Pointer to a watermark data structure with the watermark settings
cmnProps - The setting to retrieve the type and value for
pbstrType - Pointer to a BSTR that recieves the type of the value
pbstrValue - Pointer to a BSTR that recieves the value as a string
Return Value:
HRESULT
S_OK - On success
E_* - On error
--*/
HRESULT
CWMPTHandler::GetCmnVectBmpPropTypeAndValue(
_In_ CONST WatermarkData* pWmData,
_In_ CONST EVectBmpWatermarkProps cmnProps,
_Outptr_ BSTR* pbstrType,
_Outptr_ BSTR* pbstrValue
)
{
HRESULT hr = S_OK;
if (SUCCEEDED(hr = CHECK_POINTER(pWmData, E_POINTER)) &&
SUCCEEDED(hr = CHECK_POINTER(pbstrType, E_POINTER)) &&
SUCCEEDED(hr = CHECK_POINTER(pbstrValue, E_POINTER)))
{
if (cmnProps < EVectBmpWatermarkPropsMin ||
cmnProps >= EVectBmpWatermarkPropsMax)
{
hr = E_INVALIDARG;
}
}
if (SUCCEEDED(hr))
{
try
{
CStringXDW cstrType;
CStringXDW cstrValue;
switch (cmnProps)
{
case WidthExtent:
{
cstrType = SCHEMA_INTEGER;
cstrValue.Format(L"%i", pWmData->widthExtent);
}
break;
case HeightExtent:
{
cstrType = SCHEMA_INTEGER;
cstrValue.Format(L"%i", pWmData->heightExtent);
}
break;
default:
{
hr = E_FAIL;
ERR("Unknown common watermark property\n");
}
break;
}
if (SUCCEEDED(hr))
{
*pbstrType = cstrType.AllocSysString();
*pbstrValue = cstrValue.AllocSysString();
}
}
catch (CXDException& e)
{
hr = e;
}
}
ERR_ON_HR(hr);
return hr;
}
/*++
Routine Name:
CWMPTHandler::GetTxtPropTypeAndValue
Routine Description:
This routine initalises the type and value strings for a given text watermark property
Arguments:
pWmData - Pointer to a watermark data structure with the watermark settings
txtProps - The text watermark setting to retrieve the type and value for
pbstrType - Pointer to a BSTR that recieves the type of the value
pbstrValue - Pointer to a BSTR that recieves the value as a string
Return Value:
HRESULT
S_OK - On success
E_* - On error
--*/
HRESULT
CWMPTHandler::GetTxtPropTypeAndValue(
_In_ CONST WatermarkData* pWmData,
_In_ CONST ETextWatermarkProps txtProps,
_Outptr_ BSTR* pbstrType,
_Outptr_ BSTR* pbstrValue
)
{
HRESULT hr = S_OK;
if (SUCCEEDED(hr = CHECK_POINTER(pWmData, E_POINTER)) &&
SUCCEEDED(hr = CHECK_POINTER(pbstrType, E_POINTER)) &&
SUCCEEDED(hr = CHECK_POINTER(pbstrValue, E_POINTER)))
{
if (txtProps < ETextWatermarkPropsMin ||
txtProps >= ETextWatermarkPropsMax)
{
hr = E_INVALIDARG;
}
}
if (SUCCEEDED(hr))
{
try
{
CStringXDW cstrType;
CStringXDW cstrValue;
switch (txtProps)
{
case FontColor:
{
cstrType = SCHEMA_STRING;
cstrValue.Format(L"%s", static_cast<LPCWSTR>(pWmData->txtData.bstrFontColor));
}
break;
case FontSize:
{
cstrType = SCHEMA_INTEGER;
cstrValue.Format(L"%i", pWmData->txtData.fontSize);
}
break;
case Text:
{
cstrType = SCHEMA_STRING;
cstrValue.Format(L"%s", static_cast<LPCWSTR>(pWmData->txtData.bstrText));
}
break;
default:
{
hr = E_FAIL;
ERR("Unknown text watermark property\n");
}
break;
}
if (SUCCEEDED(hr))
{
*pbstrType = cstrType.AllocSysString();
*pbstrValue = cstrValue.AllocSysString();
}
}
catch (CXDException& e)
{
hr = e;
}
}
ERR_ON_HR(hr);
return hr;
}
|