Fix: Correct print scaling for Win2D PDF printing
Issue:
When you're printing pages using Win2D, especially when dealing with PDF documents that are rendered to CanvasBitmaps, you might run into some problems if your Windows display scaling isn't set to 100%. You might find that the edges of your printed PDF page are cut off, or the content might look like it's spilling out of the paper boundaries.
Cause:
The problem was happening because a part of the code, `PdfDocument.GetPage().RenderToStreamAsync()`, was being used without specifying certain rendering options (`PdfPageRenderOptions`). This meant the PDF page was being turned into an image stream using a default resolution (probably assuming 96 DPI for the PDF's original size) and wasn't taking into account the printer's actual DPI or your system's display scaling factor (`RawPixelsPerViewPixel`). Because of this, the `CanvasBitmap` created from this stream had pixel dimensions that didn't accurately match the intended physical size on paper when display scaling was active. This led to an incorrect layout by `CanvasPrintDocument`.
Solution:
I've made changes to the `LoadPDFPageBitmapsAsync` method in `Wino.Core.UWP/Services/PrintService.cs` to address this. Here's what I did:
1. I now get the printer's DPI from the `CanvasPrintDocument` (`sender.Dpi`).
2. I also get your current system display scaling factor (`DisplayInformation.GetForCurrentView().RawPixelsPerViewPixel`).
3. For each page in your PDF, I calculate the target pixel dimensions needed to print the page at its correct physical size, using the printer's DPI.
4. Then, I figure out the necessary `DestinationWidth` and `DestinationHeight` (in DIPs) for `PdfPageRenderOptions` by dividing those target pixel dimensions by the `rawPixelsPerViewPixel`.
5. Finally, I call `PdfPage.RenderToStreamAsync()` using these calculated options.
This makes sure that the `CanvasBitmap` objects are created with pixel dimensions that are right for the printer's resolution and are correctly scaled according to your system's display settings. I ran some checks by simulating how this would work with display scaling at 100%, 125%, and 150%, and it confirmed that the calculations are now correct.
* Remove account rename dialog. Implement edit account details page.
* Remove unused folder definition.
* Adressing theming issues and adding reset button. Changing the UI a bit.
* Enable auto indent in initializer. Use service from the application.
* Adding color picker to acc setup dialog. Changing UI of edit acc details page.
* Very basic online search for gmail.
* Server side of handling offline search and listing part in listing page.
* Default search mode implementation and search UI improvements.
* Online search for Outlook.
* Very basic online search for gmail.
* Server side of handling offline search and listing part in listing page.
* Default search mode implementation and search UI improvements.
* Online search for Outlook.
* Online search for imap without downloading the messages yet. TODO
* Completing imap search.
* Remove AppCenter usage and libraries.
* Remove redundant pacakges and add the app insights sink.
* Diagnostic id support and manipulating telemetries.
* Handling of appdomain unhandled exceptions.
* Remove unused package identity package from mail project.
* Fixing printing.
* Fixing an issue where scrollviewer overrides a part of template in mail list. Adjusted zoomed out header grid's corner radius.
* IDLE implementation, imap synchronization strategies basics and condstore synchronization.
* Adding iCloud and Yahoo as special IMAP handling scenario.
* iCloud special imap handling.
* Support for killing synchronizers.
* Update privacy policy url.
* Batching condstore downloads into 50, using SORT extension for searches if supported.
* Bumping some nugets. More on the imap synchronizers.
* Delegating idle synchronizations to server to post-sync operations.
* Update mailkit to resolve qresync bug with iCloud.
* Fixing remote highest mode seq checks for qresync and condstore synchronizers.
* Yahoo custom settings.
* Bump google sdk package.
* Fixing the build issue....
* NRE on canceled token accounts during setup.
* Server crash handlers.
* Remove ARM32. Upgrade server to .NET 9.
* Fix icons for yahoo and apple.
* Fixed an issue where disabled folders causing an exception on forced sync.
* Remove smtp encoding constraint.
* Remove commented code.
* Fixing merge conflict
* Addressing double registrations for mailkit remote folder events in synchronizers.
* Making sure idle canceled result is not reported.
* Fixing custom imap server dialog opening.
* Fixing the issue with account creation making the previously selected account as selected as well.
* Fixing app close behavior and logging app close.
* Ground work for NET9 UWP switch.
* Add launch settings for Wino.Mail
* Added new test WAP project
* fix platforms in slnx solution
* ManagePackageVersionsCentrally set default
* Fixing assets and couple issues with the new packaging project.
* Add back markdown
* Fix nuget warnings
* FIx error in WAP about build tools
* Add build.props with default language preview
* Some AOT compilation progress.
* More AOT stuff.
* Remove deprecated protocol auth activation handler.
* Fix remaining protocol handler for google auth.
* Even more AOT
* More more AOT fixes
* Fix a few more AOT warnings
* Fix signature editor AOT
* Fix composer and renderer AOT JSON
* Outlook Sync AOT
* Fixing bundle generation and package signing.
---------
Co-authored-by: Burak Kaan Köse <bkaankose@outlook.com>
* Plaintext links are now clickable and fixes dark mode.
- Change `AppxPackageDir` path from `C:\Users\bkaan\Desktop\Packages\` to `$(USERPROFILE)\Desktop\Packages\`, fixes error when building release.
- Plaintext links are now clickable, and match the same subtle style as Windows Mail.
- Remove `!important` from inline styles to allow Dark Reader to properly recolor the element.
* Implement setting for clickable plaintext link
* Fix an incorrect namespace for copy auth url request.
* Implemented SSL handshake process for testing imap configuration.
* Implemented SSL handshake process for testing imap configuration.
* Replace certificate PathIcon with WinoFontIcon in XAML.
* Implemented copying auth URL for Gmail authentication.
* Update Button icon and add row spacing in Flyout grid
The icon used in the Button.Content has been updated to a new
design and is now wrapped inside a Viewbox with a width of 20
to ensure proper scaling. Additionally, the Grid inside the
Flyout now includes RowSpacing="12" to improve visual separation
between rows.
* Cancellation support for getting responses from the server.
* Adding cancel button for account creation dialog initialization.
* Prevent invalid outlook message types like contact, calendar event or todo item.
* Remove debug launcher options.
* Added logic to replace embedded images with linked resources
* Added alt text for images and replaced NewtonSoft with Text.Json
* Fix draft mime preparation
* Fix crashes for signatures without images.
---------
Co-authored-by: Burak Kaan Köse <bkaankose@outlook.com>
* Separation of messages. Introducing Wino.Messages library.
* Wino.Server and Wino.Packaging projects. Enabling full trust for UWP and app service connection manager basics.
* Remove debug code.
* Enable generating assembly info to deal with unsupported os platform warnings.
* Fix server-client connection.
* UIMessage communication. Single instancing for server and re-connection mechanism on suspension.
* Removed IWinoSynchronizerFactory from UWP project.
* Removal of background task service from core.
* Delegating changes to UI and triggering new background synchronization.
* Fix build error.
* Moved core lib messages to Messaging project.
* Better client-server communication. Handling of requests in the server. New synchronizer factory in the server.
* WAM broker and MSAL token caching for OutlookAuthenticator. Handling account creation for Outlook.
* WinoServerResponse basics.
* Delegating protocol activation for Gmail authenticator.
* Adding margin to searchbox to match action bar width.
* Move libraries into lib folder.
* Storing base64 encoded mime on draft creation instead of MimeMessage object. Fixes serialization/deserialization issue with S.T.Json
* Scrollbar adjustments
* WınoExpander for thread expander layout ıssue.
* Handling synchronizer state changes.
* Double init on background activation.
* FIxing packaging issues and new Wino Mail launcher protocol for activation from full thrust process.
* Remove debug deserialization.
* Remove debug code.
* Making sure the server connection is established when the app is launched.
* Thrust -> Trust string replacement...
* Rename package to Wino Mail
* Enable translated values in the server.
* Fixed an issue where toast activation can't find the clicked mail after the folder is initialized.
* Revert debug code.
* Change server background sync to every 3 minute and Inbox only synchronization.
* Revert google auth changes.
* App preferences page.
* Changing tray icon visibility on preference change.
* Start the server with invisible tray icon if set to invisible.
* Reconnect button on the title bar.
* Handling of toast actions.
* Enable x86 build for server during packaging.
* Get rid of old background tasks and v180 migration.
* Terminate client when Exit clicked in server.
* Introducing SynchronizationSource to prevent notifying UI after server tick synchronization.
* Remove confirmAppClose restricted capability and unused debug code in manifest.
* Closing the reconnect info popup when reconnect is clicked.
* Custom RetryHandler for OutlookSynchronizer and separating client/server logs.
* Running server on Windows startup.
* Fix startup exe.
* Fix for expander list view item paddings.
* Force full sync on app launch instead of Inbox.
* Fix draft creation.
* Fix an issue with custom folder sync logic.
* Reporting back account sync progress from server.
* Fix sending drafts and missing notifications for imap.
* Changing imap folder sync requirements.
* Retain file count is set to 3.
* Disabled swipe gestures temporarily due to native crash
with SwipeControl
* Save all attachments implementation.
* Localization for save all attachments button.
* Fix logging dates for logs.
* Fixing ARM64 build.
* Add ARM64 build config to packaging project.
* Comment out OutOfProcPDB for ARM64.
* Hnadling GONE response for Outlook folder synchronization.