vcl/inc/ppdparser.hxx | 1 vcl/unx/generic/printer/ppdparser.cxx | 92 ++++++++++++++++++++++++++++++++++ 2 files changed, 93 insertions(+)
New commits: commit ef92722b3cd92e5e96a9c8cf1bc9ee8a72eb7241 Author: Michael Weghorn <m.wegh...@posteo.de> AuthorDate: Thu Oct 17 07:44:49 2024 +0200 Commit: Michael Weghorn <m.wegh...@posteo.de> CommitDate: Thu Oct 17 09:23:00 2024 +0200 Partially revert "loplugin:unusedmethods" to fix --enable-cpdb build This PPDParser ctor is used by CPDManager::createCPDParser, which gets built with the `--enable-cpdb` autogen option. This partially reverts commit 5c4fac1e9f50832852e87452f3152f01b905f9e6. Change-Id: Ic22fc4e776c0b0ef2013b9296c7dbe9345c4e51c Reviewed-on: https://gerrit.libreoffice.org/c/core/+/175040 Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk> Tested-by: Jenkins Reviewed-by: Michael Weghorn <m.wegh...@posteo.de> diff --git a/vcl/inc/ppdparser.hxx b/vcl/inc/ppdparser.hxx index c6cac395f820..ef62c8778e2f 100644 --- a/vcl/inc/ppdparser.hxx +++ b/vcl/inc/ppdparser.hxx @@ -157,6 +157,7 @@ private: std::unique_ptr<PPDTranslator> m_pTranslator; PPDParser( OUString aFile ); + PPDParser(OUString aFile, const std::vector<PPDKey*>& keys); void parseOrderDependency(const OString& rLine); void parseOpenUI(const OString& rLine, std::string_view rPPDGroup); diff --git a/vcl/unx/generic/printer/ppdparser.cxx b/vcl/unx/generic/printer/ppdparser.cxx index 107fdb4b0d17..7f1df3848537 100644 --- a/vcl/unx/generic/printer/ppdparser.cxx +++ b/vcl/unx/generic/printer/ppdparser.cxx @@ -600,6 +600,98 @@ const PPDParser* PPDParser::getParser( const OUString& rFile ) return pNewParser; } +PPDParser::PPDParser(OUString aFile, const std::vector<PPDKey*>& keys) + : m_aFile(std::move(aFile)) + , m_aFileEncoding(RTL_TEXTENCODING_MS_1252) + , m_pImageableAreas(nullptr) + , m_pDefaultPaperDimension(nullptr) + , m_pPaperDimensions(nullptr) + , m_pDefaultInputSlot(nullptr) + , m_pDefaultResolution(nullptr) + , m_pTranslator(new PPDTranslator()) +{ + for (auto & key: keys) + { + insertKey( std::unique_ptr<PPDKey>(key) ); + } + + // fill in shortcuts + const PPDKey* pKey; + + pKey = getKey( u"PageSize"_ustr ); + + if ( pKey ) { + std::unique_ptr<PPDKey> pImageableAreas(new PPDKey(u"ImageableArea"_ustr)); + std::unique_ptr<PPDKey> pPaperDimensions(new PPDKey(u"PaperDimension"_ustr)); +#if ENABLE_CUPS + for (int i = 0; i < pKey->countValues(); i++) { + const PPDValue* pValue = pKey -> getValue(i); + OUString aValueName = pValue -> m_aOption; + PPDValue* pImageableAreaValue = pImageableAreas -> insertValue( aValueName, eQuoted ); + PPDValue* pPaperDimensionValue = pPaperDimensions -> insertValue( aValueName, eQuoted ); + rtl_TextEncoding aEncoding = osl_getThreadTextEncoding(); + OString o = OUStringToOString( aValueName, aEncoding ); + pwg_media_t *pPWGMedia = pwgMediaForPWG(o.pData->buffer); + if (pPWGMedia != nullptr) { + OUStringBuffer aBuf( 256 ); + aBuf = "0 0 " + + OUString::number(PWG_TO_POINTS(pPWGMedia -> width)) + + " " + + OUString::number(PWG_TO_POINTS(pPWGMedia -> length)); + if ( pImageableAreaValue ) + pImageableAreaValue->m_aValue = aBuf.makeStringAndClear(); + aBuf.append( OUString::number(PWG_TO_POINTS(pPWGMedia -> width)) + + " " + + OUString::number(PWG_TO_POINTS(pPWGMedia -> length) )); + if ( pPaperDimensionValue ) + pPaperDimensionValue->m_aValue = aBuf.makeStringAndClear(); + if (aValueName.equals(pKey -> getDefaultValue() -> m_aOption)) { + pImageableAreas -> m_pDefaultValue = pImageableAreaValue; + pPaperDimensions -> m_pDefaultValue = pPaperDimensionValue; + } + } + } +#endif + insertKey(std::move(pImageableAreas)); + insertKey(std::move(pPaperDimensions)); + } + + m_pImageableAreas = getKey( u"ImageableArea"_ustr ); + const PPDValue* pDefaultImageableArea = nullptr; + if( m_pImageableAreas ) + pDefaultImageableArea = m_pImageableAreas->getDefaultValue(); + if (m_pImageableAreas == nullptr) { + SAL_WARN( "vcl.unx.print", "no ImageableArea in " << m_aFile); + } + if (pDefaultImageableArea == nullptr) { + SAL_WARN( "vcl.unx.print", "no DefaultImageableArea in " << m_aFile); + } + + m_pPaperDimensions = getKey( u"PaperDimension"_ustr ); + if( m_pPaperDimensions ) + m_pDefaultPaperDimension = m_pPaperDimensions->getDefaultValue(); + if (m_pPaperDimensions == nullptr) { + SAL_WARN( "vcl.unx.print", "no PaperDimensions in " << m_aFile); + } + if (m_pDefaultPaperDimension == nullptr) { + SAL_WARN( "vcl.unx.print", "no DefaultPaperDimensions in " << m_aFile); + } + + auto pResolutions = getKey( u"Resolution"_ustr ); + if( pResolutions ) + m_pDefaultResolution = pResolutions->getDefaultValue(); + if (pResolutions == nullptr) { + SAL_INFO( "vcl.unx.print", "no Resolution in " << m_aFile); + } + SAL_INFO_IF(!m_pDefaultResolution, "vcl.unx.print", "no DefaultResolution in " + m_aFile); + + auto pInputSlots = getKey( u"InputSlot"_ustr ); + if( pInputSlots ) + m_pDefaultInputSlot = pInputSlots->getDefaultValue(); + SAL_INFO_IF(!pInputSlots, "vcl.unx.print", "no InputSlot in " << m_aFile); + SAL_INFO_IF(!m_pDefaultInputSlot, "vcl.unx.print", "no DefaultInputSlot in " << m_aFile); +} + PPDParser::PPDParser( OUString aFile ) : m_aFile(std::move( aFile )), m_aFileEncoding( RTL_TEXTENCODING_MS_1252 ),