tdf#149439 set initial customoption values from lpoptions when present

I presume there's a better way to do all this.

Change-Id: Id7e6cd3be5b82e419f17bba31834fef7cfe8299b
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/137237
Tested-by: Jenkins
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
diff --git a/vcl/unx/generic/printer/cupsmgr.cxx b/vcl/unx/generic/printer/cupsmgr.cxx
index 6acfe1d..5cb91e0 100644
--- a/vcl/unx/generic/printer/cupsmgr.cxx
+++ b/vcl/unx/generic/printer/cupsmgr.cxx
@@ -494,6 +494,32 @@ const PPDParser* CUPSManager::createCUPSParser( const OUString& rPrinter )
                        for( int i = 0; i < pPPD->num_groups; i++ )
                            updatePrinterContextInfo( pPPD->groups + i, rContext );

                        // tdf#149439 Set Custom values.
                        for (int k = 0; k < pDest->num_options; ++k)
                        {
                            if (strncmp(pDest->options[k].value, RTL_CONSTASCII_STRINGPARAM("Custom.")) == 0)
                            {
                                const PPDKey* pKey = rContext.getParser()->getKey(OStringToOUString(pDest->options[k].name, aEncoding));
                                if (!pKey)
                                {
                                    SAL_WARN("vcl.unx.print", "Custom key " << pDest->options[k].name << " not found");
                                    continue;
                                }
                                const PPDValue* pCustomValue = rContext.getValue(pKey);
                                if (!pCustomValue)
                                {
                                    SAL_WARN("vcl.unx.print", "Value for " << pDest->options[k].name << " not found");
                                    continue;
                                }
                                if (!pCustomValue->m_bCustomOption)
                                {
                                    SAL_WARN("vcl.unx.print", "Value for " << pDest->options[k].name << " not set to custom option");
                                    continue;
                                }
                                pCustomValue->m_aCustomOption = OStringToOUString(pDest->options[k].value, aEncoding);
                            }
                        }

                        rInfo.m_pParser = pNewParser;
                        rInfo.m_aContext = rContext;