Codejock Forums Homepage
Forum Home Forum Home > Codejock Products > Visual C++ MFC > Toolkit Pro
  New Posts New Posts RSS Feed - Make XAML markup DPI-aware?
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Make XAML markup DPI-aware?

 Post Reply Post Reply
Author
Message
MacW View Drop Down
Senior Member
Senior Member


Joined: 26 June 2007
Status: Offline
Points: 253
Post Options Post Options   Thanks (0) Thanks(0)   Quote MacW Quote  Post ReplyReply Direct Link To This Post Topic: Make XAML markup DPI-aware?
    Posted: 21 January 2015 at 10:27am
I use the latest version of XTP.

I tried to render XAML markup into a device context that has 300 DPI.

XTPMarkupParseText(...)
XTPMarkupRenderElement(...,*pDC,Rect);
XTPMarkupReleaseElement(...);

But all measures used in the markup, e.g. FontSize='24pt' do not scale to the DPI settings of the output device context. Looking at the markup source code in XTP reveals that measurements like 24pt are transformed assuming a DPI setting of 96 DPI.

For example, look at CXTPMarkupBuilder::ConvertLength in Source\Markup\XTPMarkupBuilder.cpp.

Thís makes it impossible to render markup device-independently. All font-measurements (and others) have to be parametrized and calculated and inserted at runtime, before calling the XTP MarkupParseText and MarkupRenderElement methods.

There are now monitors with more than 96 DPI, font-scaling may be used in Windows or a programmer may want to render Codejock XAML markup into a printer or PDF device context.

Is there hope that this will be corrected in the foreseeable future or do I need to come up with my own solution to this hard-coded DPI dependency?
Back to Top
astoyan View Drop Down
Admin Group
Admin Group
Avatar

Joined: 24 August 2013
Status: Offline
Points: 284
Post Options Post Options   Thanks (0) Thanks(0)   Quote astoyan Quote  Post ReplyReply Direct Link To This Post Posted: 14 April 2015 at 11:39pm
Hello MacW,

All previous version of ToolkitPro, including the most recent 16.4.0, mostly do not support DPI scalling. But the next version which should be released in a few weeks will support DPI scalling for most of the components, it's already implemented and is currently in the testing stage. Note, for Markup DPI scalling will be disabled by default in order to provide backward compatibility, but it'll be easy to enable it by setting to TRUE an new bDpiAware argument of XTPMarkupParseText or calling CXTPMarkupContext::SetDpiAware. Once an update is out please re-test all your markup related functionality with the DpiAware option enabled to make sure nothing is broken and let me know if you find any issues.

Thank you.
Regards,
  Alexander Stoyan
Back to Top
MacW View Drop Down
Senior Member
Senior Member


Joined: 26 June 2007
Status: Offline
Points: 253
Post Options Post Options   Thanks (0) Thanks(0)   Quote MacW Quote  Post ReplyReply Direct Link To This Post Posted: 15 April 2015 at 11:01am
That's good news, Alexander Smile

Lets hope that it all works (because you write 'will support DPI scalling for most of the components').

I don't need much, I just use the XAML engine to render text, no graphics, no UI elements etc. So far I have been able to work around this by supplying the absolute font sizes to the markup at runtime.
Back to Top
MacW View Drop Down
Senior Member
Senior Member


Joined: 26 June 2007
Status: Offline
Points: 253
Post Options Post Options   Thanks (0) Thanks(0)   Quote MacW Quote  Post ReplyReply Direct Link To This Post Posted: 19 May 2015 at 9:13am
Will this feature be configurable?

Because my code has a lot of places where I manually scale the font-size I need to match the screen's DPI setting, and then hand over something like 14pt to the Codejock XAML parser. 14pt may be the result of scaling the desired 11pt size to a 140 DPI screen.

Codejock should not scale the 14pt again. Otherwise I would have to change al my code when I install the promised update.

There should be a switch for the markup context which allows me to tell if it should scale font sizes or not.

Back to Top
cpede View Drop Down
Senior Member
Senior Member


Joined: 13 August 2004
Location: Denmark
Status: Offline
Points: 645
Post Options Post Options   Thanks (0) Thanks(0)   Quote cpede Quote  Post ReplyReply Direct Link To This Post Posted: 15 March 2016 at 4:02am
I was also surprised to find the following code in CXTPMarkupImage two times:
szRet = XTP_DPI(m_pDeviceImage->GetSize());
This breaks my Markup images because I use them together with some markup drawing elements.

I thought that Markup DPI awareness should be default off, but the line above does not look at this flag.

For v1700 I did the following fast fix:
//szRet = XTP_DPI(m_pDeviceImage->GetSize());
if (NULL != m_pMarkupContext && m_pMarkupContext->IsDpiAware())
szRet = XTP_DPI(m_pDeviceImage->GetSize());
else
szRet = m_pDeviceImage->GetSize();
In v1710 the correct solution would be to add a ScaleSize member to the CXTPDpi class, and a similar ScaleSize method in CXTPMarkupContext calling this method if m_pDpi existed, and then finally change the line
szRet = XTP_DPI(m_pDeviceImage->GetSize());
to something like 
szRet = m_pMarkupContext->ScaleSize(m_pDeviceImage->GetSize());
Please fix this.

-cpede


Product: Xtreme ToolkitPro (20.3.0)
Platform: Windows 10 (x64)
Language: Visual Studio 2017 (C++)
Back to Top
astoyan View Drop Down
Admin Group
Admin Group
Avatar

Joined: 24 August 2013
Status: Offline
Points: 284
Post Options Post Options   Thanks (0) Thanks(0)   Quote astoyan Quote  Post ReplyReply Direct Link To This Post Posted: 17 March 2016 at 10:06pm
Hello cpede,

XTP_DPI should not appear in CXTPMarkupImage, it was a bug which we've just fixed. Please try the following below DIFF patch and let me know if it works fine for you:

Index: Source/Markup/Controls/XTPMarkupImage.cpp
===================================================================
--- Source/Markup/Controls/XTPMarkupImage.cpp   (revision 17587)
+++ Source/Markup/Controls/XTPMarkupImage.cpp   (working copy)
@@ -102,7 +102,11 @@
 
        if (NULL != m_pDeviceImage)
        {
-               szRet = XTP_DPI(m_pDeviceImage->GetSize());
+               szRet = m_pDeviceImage->GetSize();
+               if (NULL != m_pMarkupContext)
+               {
+                       szRet = m_pMarkupContext->Scale(szRet);
+               }
        }
 
        return szRet;
@@ -135,7 +139,12 @@
        CSize size(0, 0);
        if (NULL != m_pDeviceImage)
        {
-               size = XTP_DPI(m_pDeviceImage->GetSize());
+               size = m_pDeviceImage->GetSize();
+               if (NULL != m_pMarkupContext)
+               {
+                       size = m_pMarkupContext->Scale(size);
+               }
+
                if (!(size.cx == 0 || size.cy == 0))
                {
                        XTPMarkupStretch stretch = GetStretch();
Index: Source/Markup/XTPMarkupContext.cpp
===================================================================
--- Source/Markup/XTPMarkupContext.cpp  (revision 17587)
+++ Source/Markup/XTPMarkupContext.cpp  (working copy)
@@ -483,6 +483,13 @@
        return NULL != m_pDpi ? m_pDpi->ScaleY(y) : y;
 }
 
+CSize CXTPMarkupContext::Scale(const SIZE& size) const
+{
+       return NULL != m_pDpi 
+               ? CSize(ScaleX(size.cx), ScaleY(size.cy))
+               : size;
+}
+
 CXTPMarkupObject* CXTPMarkupContext::CreateMarkupObject(CXTPMarkupType* pType)
 {
        CXTPMarkupObject* pObject = pType->CreateObject(this);
Index: Source/Markup/XTPMarkupContext.h
===================================================================
--- Source/Markup/XTPMarkupContext.h    (revision 17587)
+++ Source/Markup/XTPMarkupContext.h    (working copy)
@@ -263,6 +263,7 @@
        float ScaleY(float y) const; // <combine CXTPMarkupContext::ScaleX@int>
        double ScaleX(double x) const; // <combine CXTPMarkupContext::ScaleX@int>
        double ScaleY(double y) const; // <combine CXTPMarkupContext::ScaleX@int>
+       CSize Scale(const SIZE& size) const; // <combine CXTPMarkupContext::ScaleX@int>
 
        //-----------------------------------------------------------------------
        // Summary: Loads a chunk of script code in a specified language.

Thanks,
  Alexander
Back to Top
astoyan View Drop Down
Admin Group
Admin Group
Avatar

Joined: 24 August 2013
Status: Offline
Points: 284
Post Options Post Options   Thanks (0) Thanks(0)   Quote astoyan Quote  Post ReplyReply Direct Link To This Post Posted: 17 March 2016 at 10:10pm
Originally posted by MacW MacW wrote:

Will this feature be configurable?

Because my code has a lot of places where I manually scale the font-size I need to match the screen's DPI setting, and then hand over something like 14pt to the Codejock XAML parser. 14pt may be the result of scaling the desired 11pt size to a 140 DPI screen.

Codejock should not scale the 14pt again. Otherwise I would have to change al my code when I install the promised update.

There should be a switch for the markup context which allows me to tell if it should scale font sizes or not.


Hello MacW,

Please provide a test XAML and try attach 2 screenshots, one of Codejock Markup rendered in 140DPI, another one from WPF application rendering the same markup in 140DPI.

Thank you.
Alexander
Back to Top
 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.04
Copyright ©2001-2021 Web Wiz Ltd.

This page was generated in 0.156 seconds.