Signed-off-by: Dmitry Timoshkov dmitry@baikal.ru --- dlls/prntvpt/main.c | 15 ++---- dlls/prntvpt/prntvpt_private.h | 29 ++++++++++ dlls/prntvpt/ticket.c | 99 +++++++++++++++++++--------------- 3 files changed, 88 insertions(+), 55 deletions(-) create mode 100644 dlls/prntvpt/prntvpt_private.h
diff --git a/dlls/prntvpt/main.c b/dlls/prntvpt/main.c index ac44cdc1ee..2c27dc6689 100644 --- a/dlls/prntvpt/main.c +++ b/dlls/prntvpt/main.c @@ -29,13 +29,9 @@ #include "wine/heap.h" #include "wine/debug.h"
-WINE_DEFAULT_DEBUG_CHANNEL(prntvpt); +#include "prntvpt_private.h"
-struct prn_provider -{ - DWORD owner; - HANDLE hprn; -}; +WINE_DEFAULT_DEBUG_CHANNEL(prntvpt);
BOOL WINAPI DllMain(HINSTANCE hinst, DWORD reason, LPVOID reserved) { @@ -64,18 +60,13 @@ HRESULT WINAPI PTQuerySchemaVersionSupport(PCWSTR printer, DWORD *version) return E_NOTIMPL; }
-static BOOL is_valid_provider(struct prn_provider *prov) -{ - return prov && prov->owner == GetCurrentThreadId(); -} - HRESULT WINAPI PTCloseProvider(HPTPROVIDER provider) { struct prn_provider *prov = (struct prn_provider *)provider;
TRACE("%p\n", provider);
- if (!is_valid_provider(prov)) + if (!is_valid_provider(provider)) return E_HANDLE;
prov->owner = 0; diff --git a/dlls/prntvpt/prntvpt_private.h b/dlls/prntvpt/prntvpt_private.h new file mode 100644 index 0000000000..c8d1c5ef34 --- /dev/null +++ b/dlls/prntvpt/prntvpt_private.h @@ -0,0 +1,29 @@ +/* + * Copyright 2019 Dmitry Timoshkov + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA + */ + +struct prn_provider +{ + DWORD owner; + HANDLE hprn; +}; + +static inline BOOL is_valid_provider(HPTPROVIDER provider) +{ + struct prn_provider *prov = (struct prn_provider *)provider; + return prov && prov->owner == GetCurrentThreadId(); +} diff --git a/dlls/prntvpt/ticket.c b/dlls/prntvpt/ticket.c index 8f1da24af8..e9745233c9 100644 --- a/dlls/prntvpt/ticket.c +++ b/dlls/prntvpt/ticket.c @@ -33,6 +33,8 @@ #include "wine/heap.h" #include "wine/debug.h"
+#include "prntvpt_private.h" + WINE_DEFAULT_DEBUG_CHANNEL(prntvpt);
struct size @@ -665,47 +667,6 @@ static void ticket_to_devmode(const struct ticket *ticket, DEVMODEW *dm) dm->dmCollate = ticket->document.collate; }
-static void initialize_ticket(struct ticket *ticket) -{ - ticket->job.nup = 0; - ticket->job.copies = 1; - ticket->job.input_bin = DMBIN_AUTO; - ticket->document.collate = DMCOLLATE_FALSE; - ticket->page.media.paper = DMPAPER_A4; - ticket->page.media.size.width = 210000; - ticket->page.media.size.height = 297000; - ticket->page.resolution.x = 600; - ticket->page.resolution.y = 600; - ticket->page.orientation = DMORIENT_PORTRAIT; - ticket->page.scaling = 100; - ticket->page.color = DMCOLOR_MONOCHROME; -} - -HRESULT WINAPI PTConvertPrintTicketToDevMode(HPTPROVIDER provider, IStream *stream, EDefaultDevmodeType type, - EPrintTicketScope scope, ULONG *size, PDEVMODEW *dm, BSTR *error) -{ - HRESULT hr; - struct ticket ticket; - - TRACE("%p,%p,%d,%d,%p,%p,%p\n", provider, stream, type, scope, size, dm, error); - - if (!provider || !stream || !size || !dm) - return E_INVALIDARG; - - initialize_ticket(&ticket); - - hr = parse_ticket(stream, scope, &ticket); - if (hr != S_OK) return hr; - - *dm = heap_alloc(sizeof(**dm)); - if (!dm) return E_OUTOFMEMORY; - - ticket_to_devmode(&ticket, *dm); - *size = sizeof(**dm); - - return S_OK; -} - static void devmode_to_ticket(const DEVMODEW *dm, struct ticket *ticket) { if (dm->dmFields & DM_ORIENTATION) @@ -738,6 +699,55 @@ static void devmode_to_ticket(const DEVMODEW *dm, struct ticket *ticket) ticket->document.collate = dm->dmCollate; }
+static HRESULT initialize_ticket(struct prn_provider *prov, struct ticket *ticket) +{ + PRINTER_INFO_2W *pi2; + DWORD size; + HRESULT hr = S_OK; + + GetPrinterW(prov->hprn, 2, NULL, 0, &size); + if (GetLastError() != ERROR_INSUFFICIENT_BUFFER) + return HRESULT_FROM_WIN32(GetLastError()); + + pi2 = heap_alloc(size); + if (!pi2) return E_OUTOFMEMORY; + + if (!GetPrinterW(prov->hprn, 2, (LPBYTE)pi2, size, NULL)) + hr = HRESULT_FROM_WIN32(GetLastError()); + else + devmode_to_ticket(pi2->pDevMode, ticket); + + heap_free(pi2); + return hr; +} + +HRESULT WINAPI PTConvertPrintTicketToDevMode(HPTPROVIDER provider, IStream *stream, EDefaultDevmodeType type, + EPrintTicketScope scope, ULONG *size, PDEVMODEW *dm, BSTR *error) +{ + struct prn_provider *prov = (struct prn_provider *)provider; + HRESULT hr; + struct ticket ticket; + + TRACE("%p,%p,%d,%d,%p,%p,%p\n", provider, stream, type, scope, size, dm, error); + + if (!is_valid_provider(provider) || !stream || !size || !dm) + return E_INVALIDARG; + + hr = initialize_ticket(prov, &ticket); + if (hr != S_OK) return hr; + + hr = parse_ticket(stream, scope, &ticket); + if (hr != S_OK) return hr; + + *dm = heap_alloc(sizeof(**dm)); + if (!dm) return E_OUTOFMEMORY; + + ticket_to_devmode(&ticket, *dm); + *size = sizeof(**dm); + + return S_OK; +} + static HRESULT add_attribute(IXMLDOMElement *element, const WCHAR *attr, const WCHAR *value) { VARIANT var; @@ -1197,11 +1207,13 @@ static void dump_devmode(const DEVMODEW *dm) HRESULT WINAPI PTConvertDevModeToPrintTicket(HPTPROVIDER provider, ULONG size, PDEVMODEW dm, EPrintTicketScope scope, IStream *stream) { + struct prn_provider *prov = (struct prn_provider *)provider; struct ticket ticket; + HRESULT hr;
TRACE("%p,%u,%p,%d,%p\n", provider, size, dm, scope, stream);
- if (!provider || !dm || !stream) + if (!is_valid_provider(provider) || !dm || !stream) return E_INVALIDARG;
dump_devmode(dm); @@ -1209,7 +1221,8 @@ HRESULT WINAPI PTConvertDevModeToPrintTicket(HPTPROVIDER provider, ULONG size, P if (!IsValidDevmodeW(dm, size)) return E_INVALIDARG;
- initialize_ticket(&ticket); + hr = initialize_ticket(prov, &ticket); + if (hr != S_OK) return hr; devmode_to_ticket(dm, &ticket);
return write_ticket(stream, &ticket, scope);
Hi,
While running your changed tests, I think I found new failures. Being a bot and all I'm not very good at pattern recognition, so I might be wrong, but could you please double-check?
Full results can be found at: https://testbot.winehq.org/JobDetails.pl?Key=73419
Your paranoid android.
=== debiant (build log) ===
Task: WineTest did not produce the wow32 report