Coverage Report

Created: 2025-06-10 07:19

/src/ghostpdl/base/gdevkrnlsclass.c
Line
Count
Source (jump to first uncovered line)
1
/* Copyright (C) 2001-2025 Artifex Software, Inc.
2
   All Rights Reserved.
3
4
   This software is provided AS-IS with no warranty, either express or
5
   implied.
6
7
   This software is distributed under license and may not be copied,
8
   modified or distributed except as expressly authorized under the terms
9
   of the license contained in the file LICENSE in this distribution.
10
11
   Refer to licensing information at http://www.artifex.com or contact
12
   Artifex Software, Inc.,  39 Mesa Street, Suite 108A, San Francisco,
13
   CA 94129, USA, for further information.
14
*/
15
16
#include "gx.h"
17
#include "gxdcolor.h"
18
#include "gdevkrnlsclass.h" /* 'standard' built in subclasses, currently Page, Object, and Nup filter */
19
20
/* If set to '1' ths forces all devices to be loaded, even if they won't do anything.
21
 * This is useful for cluster testing that the very presence of a device doesn't
22
 * break anything. This requires that all of these devices pass through if the params
23
 * they use are 0/NULL.
24
 */
25
#define FORCE_TESTING_SUBCLASSING 0
26
27
/* This installs the 'kernel' device classes. If you add any devices here you should
28
 * almost certainly edit gdevp14.c, gs_pdf14_device_push() and add the new device to the list
29
 * of devices which the push of the compositor claims are already installed (to prevent
30
 * a second copy being installed by gdev_prn_open).
31
 */
32
int install_internal_subclass_devices(gx_device **ppdev, bool *devices_loaded)
33
9.57k
{
34
9.57k
    int code = 0;
35
9.57k
    gx_device *dev = (gx_device *)*ppdev, *saved;
36
37
    /*
38
     * NOTE: the Nup device should precede the PageHandler so the FirstPage, LastPage
39
     *       and PageList will filter pages out BEFORE they are seen by the nesting.
40
     */
41
42
#if FORCE_TESTING_SUBCLASSING
43
    if (!dev->NupHandlerPushed) {
44
#else
45
9.57k
    if (!dev->NupHandlerPushed && dev->NupControl != 0) {
46
0
#endif
47
0
        code = gx_device_nup_device_install(dev);
48
0
        if (code < 0)
49
0
            return code;
50
51
0
        saved = dev = dev->child;
52
53
        /* Open all devices *after* the new current device */
54
0
        do {
55
0
            dev->is_open = true;
56
0
            dev = dev->child;
57
0
        }while(dev);
58
59
0
        dev = saved;
60
61
        /* Rewind to top device in chain */
62
0
        while(dev->parent)
63
0
            dev = dev->parent;
64
65
        /* Note in all devices in chain that we have loaded the NupHandler */
66
0
        do {
67
0
            dev->NupHandlerPushed = true;
68
0
            dev = dev->child;
69
0
        }while(dev);
70
71
0
        dev = saved;
72
0
        if (devices_loaded)
73
0
            *devices_loaded = true;
74
0
    }
75
#if FORCE_TESTING_SUBCLASSING
76
    if (!dev->PageHandlerPushed) {
77
#else
78
9.57k
    if (!dev->PageHandlerPushed && (dev->FirstPage != 0 || dev->LastPage != 0 || dev->PageList != 0)) {
79
0
#endif
80
0
        code = gx_device_subclass(dev, (gx_device *)&gs_flp_device, sizeof(first_last_subclass_data));
81
0
        if (code < 0)
82
0
            return code;
83
84
0
        saved = dev = dev->child;
85
86
        /* Open all devices *after* the new current device */
87
0
        do {
88
0
            dev->is_open = true;
89
0
            dev = dev->child;
90
0
        }while(dev);
91
92
0
        dev = saved;
93
94
        /* Rewind to top device in chain */
95
0
        while(dev->parent)
96
0
            dev = dev->parent;
97
98
        /* Note in all devices in chain that we have loaded the PageHandler */
99
0
        do {
100
0
            dev->PageHandlerPushed = true;
101
0
            dev = dev->child;
102
0
        }while(dev);
103
104
0
        dev = saved;
105
0
        if (devices_loaded)
106
0
            *devices_loaded = true;
107
0
    }
108
#if FORCE_TESTING_SUBCLASSING
109
    if (!dev->ObjectHandlerPushed) {
110
#else
111
9.57k
    if (!dev->ObjectHandlerPushed && dev->ObjectFilter != 0) {
112
0
#endif
113
0
        code = gx_device_subclass(dev, (gx_device *)&gs_obj_filter_device, sizeof(obj_filter_subclass_data));
114
0
        if (code < 0)
115
0
            return code;
116
117
0
        saved = dev = dev->child;
118
119
        /* Open all devices *after* the new current device */
120
0
        do {
121
0
            dev->is_open = true;
122
0
            dev = dev->child;
123
0
        }while(dev);
124
125
0
        dev = saved;
126
127
        /* Rewind to top device in chain */
128
0
        while(dev->parent)
129
0
            dev = dev->parent;
130
131
        /* Note in all devices in chain that we have loaded the ObjectHandler */
132
0
        do {
133
0
            dev->ObjectHandlerPushed = true;
134
0
            dev = dev->child;
135
0
        }while(dev);
136
137
0
        dev = saved;
138
0
        if (devices_loaded)
139
0
            *devices_loaded = true;
140
0
    }
141
9.57k
    *ppdev = dev;
142
9.57k
    return code;
143
9.57k
}