1 | //======================================================================== |
2 | // |
3 | // OutputDev.cc |
4 | // |
5 | // Copyright 1996-2003 Glyph & Cog, LLC |
6 | // |
7 | //======================================================================== |
8 | |
9 | //======================================================================== |
10 | // |
11 | // Modified under the Poppler project - http://poppler.freedesktop.org |
12 | // |
13 | // All changes made under the Poppler project to this file are licensed |
14 | // under GPL version 2 or later |
15 | // |
16 | // Copyright (C) 2005 Jonathan Blandford <jrb@redhat.com> |
17 | // Copyright (C) 2006 Thorkild Stray <thorkild@ifi.uio.no> |
18 | // Copyright (C) 2007, 2017 Adrian Johnson <ajohnson@redneon.com> |
19 | // Copyright (C) 2009 Carlos Garcia Campos <carlosgc@gnome.org> |
20 | // Copyright (C) 2009, 2012, 2013, 2018, 2019 Albert Astals Cid <aacid@kde.org> |
21 | // Copyright (C) 2012 Thomas Freitag <Thomas.Freitag@alfa.de> |
22 | // Copyright (C) 2018 Adam Reichold <adam.reichold@t-online.de> |
23 | // |
24 | // To see a description of the changes please see the Changelog file that |
25 | // came with your tarball or type make ChangeLog if you are building from git |
26 | // |
27 | //======================================================================== |
28 | |
29 | #include <config.h> |
30 | |
31 | #include <cstddef> |
32 | #include "Object.h" |
33 | #include "Stream.h" |
34 | #include "GfxState.h" |
35 | #include "OutputDev.h" |
36 | |
37 | //------------------------------------------------------------------------ |
38 | // OutputDev |
39 | //------------------------------------------------------------------------ |
40 | |
41 | OutputDev::OutputDev() |
42 | #ifdef USE_CMS |
43 | : iccColorSpaceCache(5) |
44 | #endif |
45 | { |
46 | } |
47 | |
48 | OutputDev::~OutputDev() = default; |
49 | |
50 | void OutputDev::setDefaultCTM(const double *ctm) |
51 | { |
52 | int i; |
53 | double det; |
54 | |
55 | for (i = 0; i < 6; ++i) { |
56 | defCTM[i] = ctm[i]; |
57 | } |
58 | det = 1 / (defCTM[0] * defCTM[3] - defCTM[1] * defCTM[2]); |
59 | defICTM[0] = defCTM[3] * det; |
60 | defICTM[1] = -defCTM[1] * det; |
61 | defICTM[2] = -defCTM[2] * det; |
62 | defICTM[3] = defCTM[0] * det; |
63 | defICTM[4] = (defCTM[2] * defCTM[5] - defCTM[3] * defCTM[4]) * det; |
64 | defICTM[5] = (defCTM[1] * defCTM[4] - defCTM[0] * defCTM[5]) * det; |
65 | } |
66 | |
67 | void OutputDev::cvtDevToUser(double dx, double dy, double *ux, double *uy) |
68 | { |
69 | *ux = defICTM[0] * dx + defICTM[2] * dy + defICTM[4]; |
70 | *uy = defICTM[1] * dx + defICTM[3] * dy + defICTM[5]; |
71 | } |
72 | |
73 | void OutputDev::cvtUserToDev(double ux, double uy, int *dx, int *dy) |
74 | { |
75 | *dx = (int)(defCTM[0] * ux + defCTM[2] * uy + defCTM[4] + 0.5); |
76 | *dy = (int)(defCTM[1] * ux + defCTM[3] * uy + defCTM[5] + 0.5); |
77 | } |
78 | |
79 | void OutputDev::updateAll(GfxState *state) |
80 | { |
81 | updateLineDash(state); |
82 | updateFlatness(state); |
83 | updateLineJoin(state); |
84 | updateLineCap(state); |
85 | updateMiterLimit(state); |
86 | updateLineWidth(state); |
87 | updateStrokeAdjust(state); |
88 | updateFillColorSpace(state); |
89 | updateFillColor(state); |
90 | updateStrokeColorSpace(state); |
91 | updateStrokeColor(state); |
92 | updateBlendMode(state); |
93 | updateFillOpacity(state); |
94 | updateStrokeOpacity(state); |
95 | updateFillOverprint(state); |
96 | updateStrokeOverprint(state); |
97 | updateTransfer(state); |
98 | updateFont(state); |
99 | } |
100 | |
101 | bool OutputDev::beginType3Char(GfxState *state, double x, double y, double dx, double dy, CharCode code, const Unicode *u, int uLen) |
102 | { |
103 | return false; |
104 | } |
105 | |
106 | void OutputDev::drawImageMask(GfxState *state, Object *ref, Stream *str, int width, int height, bool invert, bool interpolate, bool inlineImg) |
107 | { |
108 | int i, j; |
109 | |
110 | if (inlineImg) { |
111 | str->reset(); |
112 | j = height * ((width + 7) / 8); |
113 | for (i = 0; i < j; ++i) { |
114 | str->getChar(); |
115 | } |
116 | str->close(); |
117 | } |
118 | } |
119 | |
120 | void OutputDev::setSoftMaskFromImageMask(GfxState *state, Object *ref, Stream *str, int width, int height, bool invert, bool inlineImg, double *baseMatrix) |
121 | { |
122 | drawImageMask(state, ref, str, width, height, invert, interpolate: false, inlineImg); |
123 | } |
124 | |
125 | void OutputDev::unsetSoftMaskFromImageMask(GfxState *state, double *baseMatrix) |
126 | { |
127 | return; |
128 | } |
129 | |
130 | void OutputDev::drawImage(GfxState *state, Object *ref, Stream *str, int width, int height, GfxImageColorMap *colorMap, bool interpolate, const int *maskColors, bool inlineImg) |
131 | { |
132 | int i, j; |
133 | |
134 | if (inlineImg) { |
135 | str->reset(); |
136 | j = height * ((width * colorMap->getNumPixelComps() * colorMap->getBits() + 7) / 8); |
137 | for (i = 0; i < j; ++i) { |
138 | str->getChar(); |
139 | } |
140 | str->close(); |
141 | } |
142 | } |
143 | |
144 | void OutputDev::drawMaskedImage(GfxState *state, Object *ref, Stream *str, int width, int height, GfxImageColorMap *colorMap, bool interpolate, Stream *maskStr, int maskWidth, int maskHeight, bool maskInvert, bool maskInterpolate) |
145 | { |
146 | drawImage(state, ref, str, width, height, colorMap, interpolate, maskColors: nullptr, inlineImg: false); |
147 | } |
148 | |
149 | void OutputDev::drawSoftMaskedImage(GfxState *state, Object *ref, Stream *str, int width, int height, GfxImageColorMap *colorMap, bool interpolate, Stream *maskStr, int maskWidth, int maskHeight, GfxImageColorMap *maskColorMap, |
150 | bool maskInterpolate) |
151 | { |
152 | drawImage(state, ref, str, width, height, colorMap, interpolate, maskColors: nullptr, inlineImg: false); |
153 | } |
154 | |
155 | void OutputDev::endMarkedContent(GfxState *state) { } |
156 | |
157 | void OutputDev::beginMarkedContent(const char *name, Dict *properties) { } |
158 | |
159 | void OutputDev::markPoint(const char *name) { } |
160 | |
161 | void OutputDev::markPoint(const char *name, Dict *properties) { } |
162 | |
163 | #ifdef OPI_SUPPORT |
164 | void OutputDev::opiBegin(GfxState *state, Dict *opiDict) { } |
165 | |
166 | void OutputDev::opiEnd(GfxState *state, Dict *opiDict) { } |
167 | #endif |
168 | |
169 | void OutputDev::startProfile() |
170 | { |
171 | profileHash = std::make_unique<std::unordered_map<std::string, ProfileData>>(); |
172 | } |
173 | |
174 | std::unique_ptr<std::unordered_map<std::string, ProfileData>> OutputDev::endProfile() |
175 | { |
176 | return std::move(profileHash); |
177 | } |
178 | |