Coverage Report

Created: 2026-06-30 11:14

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/vcl/headless/svpprn.cxx
Line
Count
Source
1
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
/*
3
 * This file is part of the LibreOffice project.
4
 *
5
 * This Source Code Form is subject to the terms of the Mozilla Public
6
 * License, v. 2.0. If a copy of the MPL was not distributed with this
7
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8
 *
9
 * This file incorporates work covered by the following license notice:
10
 *
11
 *   Licensed to the Apache Software Foundation (ASF) under one or more
12
 *   contributor license agreements. See the NOTICE file distributed
13
 *   with this work for additional information regarding copyright
14
 *   ownership. The ASF licenses this file to you under the Apache
15
 *   License, Version 2.0 (the "License"); you may not use this file
16
 *   except in compliance with the License. You may obtain a copy of
17
 *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
18
 */
19
20
#include <sal/config.h>
21
22
#include <string_view>
23
24
#include <vcl/svapp.hxx>
25
#include <printerinfomanager.hxx>
26
27
#include <jobset.h>
28
#include <print.h>
29
30
#include <unx/genpspgraphics.h>
31
32
#include <headless/svpprn.hxx>
33
#include <headless/svpinst.hxx>
34
35
using namespace psp;
36
37
static void copyJobDataToJobSetup( ImplJobSetup* pJobSetup, JobData& rData )
38
0
{
39
0
    pJobSetup->SetOrientation( rData.m_eOrientation == orientation::Landscape ? Orientation::Landscape : Orientation::Portrait );
40
41
    // copy page size
42
0
    OUString aPaper;
43
0
    int width, height;
44
45
0
    rData.m_aContext.getPageSize( aPaper, width, height );
46
0
    pJobSetup->SetPaperFormat( PaperInfo::fromPSName(OUStringToOString( aPaper, RTL_TEXTENCODING_ISO_8859_1 )) );
47
0
    pJobSetup->SetPaperWidth( 0 );
48
0
    pJobSetup->SetPaperHeight( 0 );
49
0
    if( pJobSetup->GetPaperFormat() == PAPER_USER )
50
0
    {
51
        // convert from points to 1/100 mm
52
0
        width = o3tl::convert(width, o3tl::Length::pt, o3tl::Length::mm100);
53
0
        height = o3tl::convert(height, o3tl::Length::pt, o3tl::Length::mm100);
54
55
0
        if( rData.m_eOrientation == psp::orientation::Portrait )
56
0
        {
57
0
            pJobSetup->SetPaperWidth( width );
58
0
            pJobSetup->SetPaperHeight( height );
59
0
        }
60
0
        else
61
0
        {
62
0
            pJobSetup->SetPaperWidth( height );
63
0
            pJobSetup->SetPaperHeight( width );
64
0
        }
65
0
    }
66
67
    // copy input slot
68
0
    const PPDKey* pKey = nullptr;
69
0
    const PPDValue* pValue = nullptr;
70
71
0
    pJobSetup->SetPaperBin( 0xffff );
72
0
    if( rData.m_pParser )
73
0
        pKey                    = rData.m_pParser->getKey( u"InputSlot"_ustr );
74
0
    if( pKey )
75
0
        pValue                  = rData.m_aContext.getValue( pKey );
76
0
    if( pKey && pValue )
77
0
    {
78
0
        int nPaperBin;
79
0
        for( nPaperBin = 0;
80
0
             pValue != pKey->getValue( nPaperBin ) &&
81
0
                 nPaperBin < pKey->countValues();
82
0
             nPaperBin++ );
83
0
        pJobSetup->SetPaperBin(
84
0
            (nPaperBin == pKey->countValues()
85
0
             || pValue == pKey->getDefaultValue())
86
0
            ? 0xffff : nPaperBin);
87
0
    }
88
89
    // copy duplex
90
0
    pKey = nullptr;
91
0
    pValue = nullptr;
92
93
0
    pJobSetup->SetDuplexMode( DuplexMode::Unknown );
94
0
    if( rData.m_pParser )
95
0
        pKey = rData.m_pParser->getKey( u"Duplex"_ustr );
96
0
    if( pKey )
97
0
        pValue = rData.m_aContext.getValue( pKey );
98
0
    if( pKey && pValue )
99
0
    {
100
0
        if( pValue->m_aOption.equalsIgnoreAsciiCase( "None" ) ||
101
0
            pValue->m_aOption.startsWithIgnoreAsciiCase( "Simplex" )
102
0
           )
103
0
        {
104
0
            pJobSetup->SetDuplexMode( DuplexMode::Off );
105
0
        }
106
0
        else if( pValue->m_aOption.equalsIgnoreAsciiCase( "DuplexNoTumble" ) )
107
0
        {
108
0
            pJobSetup->SetDuplexMode( DuplexMode::LongEdge );
109
0
        }
110
0
        else if( pValue->m_aOption.equalsIgnoreAsciiCase( "DuplexTumble" ) )
111
0
        {
112
0
            pJobSetup->SetDuplexMode( DuplexMode::ShortEdge );
113
0
        }
114
0
    }
115
116
    // copy the whole context
117
118
0
    sal_uInt32 nBytes;
119
0
    std::unique_ptr<sal_uInt8[]> pBuffer;
120
0
    if( rData.getStreamBuffer( pBuffer, nBytes ) )
121
0
        pJobSetup->SetDriverData( std::move(pBuffer), nBytes );
122
0
    else
123
0
        pJobSetup->SetDriverData( nullptr, 0 );
124
0
}
125
126
// SalInstance
127
128
SalInfoPrinter* SvpSalInstance::CreateInfoPrinter(SalPrinterQueueInfo& rQueueInfo,
129
                                                  ImplJobSetup& rJobSetup)
130
0
{
131
    // create and initialize SalInfoPrinter
132
0
    SvpSalInfoPrinter* pPrinter = new SvpSalInfoPrinter;
133
134
0
    PrinterInfoManager& rManager(PrinterInfoManager::get());
135
0
    PrinterInfo aInfo(rManager.getPrinterInfo(rQueueInfo.maPrinterName));
136
0
    pPrinter->m_aJobData = aInfo;
137
138
0
    if (rJobSetup.GetDriverData())
139
0
        JobData::constructFromStreamBuffer(rJobSetup.GetDriverData(), rJobSetup.GetDriverDataLen(),
140
0
                                           aInfo);
141
142
0
    rJobSetup.SetSystem(JOBSETUP_SYSTEM_UNIX);
143
0
    rJobSetup.SetPrinterName(rQueueInfo.maPrinterName);
144
0
    rJobSetup.SetDriver(aInfo.m_aDriverName);
145
0
    copyJobDataToJobSetup(&rJobSetup, aInfo);
146
147
0
    return pPrinter;
148
0
}
149
150
std::unique_ptr<SalPrinter> SvpSalInstance::CreatePrinter( SalInfoPrinter* pInfoPrinter )
151
0
{
152
    // create and initialize SalPrinter
153
0
    SvpSalPrinter* pPrinter = new SvpSalPrinter( pInfoPrinter );
154
0
    pPrinter->m_aJobData = static_cast<SvpSalInfoPrinter*>(pInfoPrinter)->m_aJobData;
155
156
0
    return std::unique_ptr<SalPrinter>(pPrinter);
157
0
}
158
159
void SvpSalInstance::GetPrinterQueueInfo(ImplPrnQueueList& rList)
160
0
{
161
0
    PrinterInfoManager& rManager( PrinterInfoManager::get() );
162
0
    static const char* pNoSyncDetection = getenv( "SAL_DISABLE_SYNCHRONOUS_PRINTER_DETECTION" );
163
0
    if( ! pNoSyncDetection || ! *pNoSyncDetection )
164
0
    {
165
        // #i62663# synchronize possible asynchronouse printer detection now
166
0
        rManager.checkPrintersChanged( true );
167
0
    }
168
169
0
    for (const auto& [rPrinterName, rInfo] : rManager.getPrinters())
170
0
    {
171
        // create new entry
172
0
        std::unique_ptr<SalPrinterQueueInfo> pInfo(new SalPrinterQueueInfo);
173
0
        pInfo->maPrinterName = rPrinterName;
174
0
        pInfo->maDriver         = rInfo.m_aDriverName;
175
0
        pInfo->maLocation       = rInfo.m_aLocation;
176
0
        pInfo->maComment        = rInfo.m_aComment;
177
178
0
        OUString sPdfDir;
179
0
        if (getPdfDir(rInfo, sPdfDir))
180
0
            pInfo->maLocation = sPdfDir;
181
182
0
        rList.Add(std::move(pInfo));
183
0
    }
184
0
}
185
186
OUString SvpSalInstance::GetDefaultPrinter()
187
0
{
188
0
    PrinterInfoManager& rManager( PrinterInfoManager::get() );
189
0
    return rManager.getDefaultPrinter();
190
0
}
191
192
void SvpSalInstance::PostPrintersChanged()
193
0
{
194
0
    SvpSalInstance *pInst = SvpSalInstance::s_pDefaultInstance;
195
0
    for (auto pSalFrame : pInst->getFrames() )
196
0
        pInst->PostEvent( pSalFrame, nullptr, SalEvent::PrinterChanged );
197
0
}
198
199
bool SvpSalInfoPrinter::Setup( weld::Window&, ImplJobSetup&)
200
0
{
201
0
    return false;
202
0
}
203
204
SvpSalPrinter::SvpSalPrinter( SalInfoPrinter* pInfoPrinter )
205
0
    : PspSalPrinter( pInfoPrinter )
206
0
{
207
0
}
208
209
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */