forked from tsdgeos/poppler_mirror
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAnnotStampImageHelper.cc
79 lines (66 loc) · 2.57 KB
/
AnnotStampImageHelper.cc
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
//========================================================================
//
// AnnotStampImageHelper.cc
//
// Copyright (C) 2021 Mahmoud Ahmed Khalil <[email protected]>
// Copyright (C) 2021 Albert Astals Cid <[email protected]>
//
// Licensed under GPLv2 or later
//
//========================================================================
#include "AnnotStampImageHelper.h"
#include "goo/gmem.h"
#include "goo/gstrtod.h"
#include "PDFDoc.h"
#include "Stream.h"
#include "Dict.h"
#include <iostream>
AnnotStampImageHelper::AnnotStampImageHelper(PDFDoc *docA, int widthA, int heightA, ColorSpace colorSpace, int bitsPerComponent, char *data, int dataLength)
{
initialize(docA, widthA, heightA, colorSpace, bitsPerComponent, data, dataLength);
}
AnnotStampImageHelper::AnnotStampImageHelper(PDFDoc *docA, int widthA, int heightA, ColorSpace colorSpace, int bitsPerComponent, char *data, int dataLength, Ref softMaskRef)
{
initialize(docA, widthA, heightA, colorSpace, bitsPerComponent, data, dataLength);
sMaskRef = softMaskRef;
Dict *dict = imgObj.streamGetDict();
dict->add("SMask", Object(sMaskRef));
}
void AnnotStampImageHelper::initialize(PDFDoc *docA, int widthA, int heightA, ColorSpace colorSpace, int bitsPerComponent, char *data, int dataLength)
{
doc = docA;
width = widthA;
height = heightA;
sMaskRef = Ref::INVALID();
Dict *dict = new Dict(docA->getXRef());
dict->add("Type", Object(objName, "XObject"));
dict->add("Subtype", Object(objName, "Image"));
dict->add("Width", Object(width));
dict->add("Height", Object(height));
dict->add("ImageMask", Object(false));
dict->add("BitsPerComponent", Object(bitsPerComponent));
dict->add("Length", Object(dataLength));
switch (colorSpace) {
case ColorSpace::DeviceGray:
dict->add("ColorSpace", Object(objName, "DeviceGray"));
break;
case ColorSpace::DeviceRGB:
dict->add("ColorSpace", Object(objName, "DeviceRGB"));
break;
case ColorSpace::DeviceCMYK:
dict->add("ColorSpace", Object(objName, "DeviceCMYK"));
break;
}
char *dataCopied = (char *)gmalloc(sizeof(char) * (dataLength));
std::memcpy(dataCopied, data, dataLength);
Stream *dataStream = new AutoFreeMemStream(dataCopied, 0, dataLength, Object(dict));
imgObj = Object(dataStream);
ref = doc->getXRef()->addIndirectObject(imgObj);
}
void AnnotStampImageHelper::removeAnnotStampImageObject()
{
if (sMaskRef != Ref::INVALID()) {
doc->getXRef()->removeIndirectObject(sMaskRef);
}
doc->getXRef()->removeIndirectObject(ref);
}