/** *Therealtestfunction *2.trytocreateanemptywindow *3.trytoconverttheWindowPeertoanXWindow *4.trytoresizeandmovethewindowtoanotherposition,sowegetawellknowingpositionandsize. *5.runsomemoretests
*/ void ToolkitTest::testXUnitConversion()
{ #ifdef _WIN32
HKEY hkey;
DWORD type;
DWORD data;
DWORD size(sizeof(data)); LONG ret = ::RegOpenKeyW(HKEY_CURRENT_USER, L"Control Panel\\Desktop", &hkey); if (ret == ERROR_SUCCESS)
{
ret = ::RegQueryValueExW(hkey, L"LogPixels", nullptr, &type, reinterpret_cast<LPBYTE>(&data), &size); if (ret == ERROR_SUCCESS && type == REG_DWORD && data != 96)
{
std::cerr << "non-default resolution, skipping textXUnitConversion\n"; return;
}
} #endif
// create a window
sal_Int32 x = 100;
sal_Int32 y = 100;
sal_Int32 width = 640;
sal_Int32 height = 480;
uno::Reference<awt::XWindowPeer> const xWindowPeer
= createFloatingWindow(getMultiServiceFactory(), x, y, width, height);
CPPUNIT_ASSERT(xWindowPeer.is());
// resize and move the window to a well known position and size
uno::Reference<awt::XWindow> const xWindow(xWindowPeer, uno::UNO_QUERY);
CPPUNIT_ASSERT(xWindow.is());
// try to get the position of the window in 1/100mm with the XUnitConversion method
awt::Point const aPointInMM_100TH
= xConv->convertPointToLogic(aPoint, util::MeasureUnit::MM_100TH);
std::cerr << "Window position:\n";
std::cerr << "X: " << aPointInMM_100TH.X << " 1/100mm\n";
std::cerr << "Y: " << aPointInMM_100TH.Y << " 1/100mm\n";
// try to get the size of the window in 1/100mm with the XUnitConversion method
awt::Size const aSizeInMM_100TH = xConv->convertSizeToLogic(aSize, util::MeasureUnit::MM_100TH);
std::cerr << "Window size:\n";
std::cerr << "Width: " << aSizeInMM_100TH.Width << " 1/100mm\n";
std::cerr << "Height: " << aSizeInMM_100TH.Height << " 1/100mm\n";
// try to get the size of the window in 1/10mm with the XUnitConversion method
awt::Size const aSizeInMM_10TH = xConv->convertSizeToLogic(aSize, util::MeasureUnit::MM_10TH);
std::cerr << "Window size:\n";
std::cerr << "Width: " << aSizeInMM_10TH.Width << " 1/10mm\n";
std::cerr << "Height: " << aSizeInMM_10TH.Height << " 1/10mm\n";
// check the size with a delta which must be smaller a given difference
CPPUNIT_ASSERT_MESSAGE("Size.Width not correct",
std::abs(aSizeInMM_100TH.Width - aSizeInMM_10TH.Width * 10) < 10);
CPPUNIT_ASSERT_MESSAGE("Size.Height not correct",
std::abs(aSizeInMM_100TH.Height - aSizeInMM_10TH.Height * 10) < 10);
// assure the pixels are the same as we already know
CPPUNIT_ASSERT_EQUAL_MESSAGE("failed: Size from pixel to 1/100mm to pixel", aNewSize.Width,
aSize.Width);
CPPUNIT_ASSERT_EQUAL_MESSAGE("failed: Size from pixel to 1/100mm to pixel", aNewSize.Height,
aSize.Height);
¤ Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.0.14Bemerkung:
(vorverarbeitet am 2026-10-03)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.