2013-06-15 20:51:38 +01:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
|
|
|
/*
|
|
|
|
* This file is part of the LibreOffice project.
|
|
|
|
*
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
*/
|
|
|
|
|
2017-03-06 16:43:57 +02:00
|
|
|
#include <ostream>
|
|
|
|
#include <vector>
|
|
|
|
std::ostream& operator<<(std::ostream& rStream, const std::vector<long>& rVec);
|
|
|
|
|
2013-06-15 20:51:38 +01:00
|
|
|
#include <unotest/filters-test.hxx>
|
|
|
|
#include <test/bootstrapfixture.hxx>
|
|
|
|
|
|
|
|
#include <vcl/wrkwin.hxx>
|
|
|
|
|
|
|
|
#include <osl/file.hxx>
|
|
|
|
#include <osl/process.h>
|
|
|
|
|
2017-03-06 16:43:57 +02:00
|
|
|
std::ostream& operator<<(std::ostream& rStream, const std::vector<long>& rVec)
|
|
|
|
{
|
|
|
|
rStream << "{ ";
|
|
|
|
for (size_t i = 0; i < rVec.size() - 1; i++)
|
|
|
|
rStream << rVec[i] << ", ";
|
|
|
|
rStream << rVec.back();
|
|
|
|
rStream << " }";
|
|
|
|
return rStream;
|
|
|
|
}
|
|
|
|
|
2013-06-15 20:51:38 +01:00
|
|
|
class VclComplexTextTest : public test::BootstrapFixture
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
VclComplexTextTest() : BootstrapFixture(true, false) {}
|
|
|
|
|
|
|
|
/// Play with font measuring etc.
|
|
|
|
void testArabic();
|
2016-02-16 14:14:43 +02:00
|
|
|
#if defined(_WIN32)
|
2015-11-07 18:45:31 +10:00
|
|
|
void testTdf95650(); // Windows-only issue
|
|
|
|
#endif
|
2013-06-15 20:51:38 +01:00
|
|
|
|
|
|
|
CPPUNIT_TEST_SUITE(VclComplexTextTest);
|
|
|
|
CPPUNIT_TEST(testArabic);
|
2016-02-16 14:14:43 +02:00
|
|
|
#if defined(_WIN32)
|
2015-11-07 18:45:31 +10:00
|
|
|
CPPUNIT_TEST(testTdf95650);
|
|
|
|
#endif
|
2013-06-15 20:51:38 +01:00
|
|
|
CPPUNIT_TEST_SUITE_END();
|
|
|
|
};
|
|
|
|
|
|
|
|
void VclComplexTextTest::testArabic()
|
|
|
|
{
|
2013-06-17 14:27:03 +01:00
|
|
|
const unsigned char pOneTwoThreeUTF8[] = {
|
|
|
|
0xd9, 0x88, 0xd8, 0xa7, 0xd8, 0xad, 0xd9, 0x90,
|
|
|
|
0xd8, 0xaf, 0xd9, 0x92, 0x20, 0xd8, 0xa5, 0xd8,
|
|
|
|
0xab, 0xd9, 0x8d, 0xd9, 0x86, 0xd9, 0x8a, 0xd9,
|
|
|
|
0x86, 0x20, 0xd8, 0xab, 0xd9, 0x84, 0xd8, 0xa7,
|
|
|
|
0xd8, 0xab, 0xd8, 0xa9, 0xd9, 0x8c, 0x00
|
|
|
|
};
|
2015-01-19 15:10:10 +01:00
|
|
|
OUString aOneTwoThree( reinterpret_cast<char const *>(pOneTwoThreeUTF8),
|
2013-06-17 14:27:03 +01:00
|
|
|
SAL_N_ELEMENTS( pOneTwoThreeUTF8 ) - 1,
|
|
|
|
RTL_TEXTENCODING_UTF8 );
|
2016-12-21 19:01:27 +01:00
|
|
|
ScopedVclPtrInstance<WorkWindow> pWin(static_cast<vcl::Window *>(nullptr));
|
2015-04-23 21:24:37 +01:00
|
|
|
CPPUNIT_ASSERT( pWin );
|
2013-06-15 20:51:38 +01:00
|
|
|
|
2017-02-26 21:52:28 +02:00
|
|
|
vcl::Font aFont("DejaVu Sans", "Book", Size(0, 12));
|
2013-06-15 20:51:38 +01:00
|
|
|
|
2017-02-26 21:52:28 +02:00
|
|
|
OutputDevice *pOutDev = pWin.get();
|
2013-06-15 20:51:38 +01:00
|
|
|
pOutDev->SetFont( aFont );
|
|
|
|
|
2017-03-01 01:38:58 +02:00
|
|
|
// absolute character widths AKA text array.
|
2017-03-06 16:43:57 +02:00
|
|
|
std::vector<long> aRefCharWidths {6, 9, 16, 16, 22, 22, 26, 29, 32, 32,
|
|
|
|
36, 40, 49, 53, 56, 63, 63, 66, 72, 72};
|
2017-03-01 01:38:58 +02:00
|
|
|
std::vector<long> aCharWidths(aOneTwoThree.getLength(), 0);
|
|
|
|
long nTextWidth = pOutDev->GetTextArray(aOneTwoThree, aCharWidths.data());
|
2017-03-06 16:43:57 +02:00
|
|
|
|
|
|
|
CPPUNIT_ASSERT_EQUAL(aRefCharWidths, aCharWidths);
|
2017-03-01 01:38:58 +02:00
|
|
|
CPPUNIT_ASSERT_EQUAL(72L, nTextWidth);
|
|
|
|
CPPUNIT_ASSERT_EQUAL(nTextWidth, aCharWidths.back());
|
|
|
|
|
2017-02-26 21:52:28 +02:00
|
|
|
// text advance width and line height
|
|
|
|
CPPUNIT_ASSERT_EQUAL(72L, pOutDev->GetTextWidth(aOneTwoThree));
|
|
|
|
CPPUNIT_ASSERT_EQUAL(13L, pOutDev->GetTextHeight());
|
|
|
|
|
|
|
|
// exact bounding rectangle, not essentially the same as text width/height
|
2017-02-27 13:07:31 +02:00
|
|
|
#if defined(MACOSX) || defined(_WIN32)
|
|
|
|
// FIXME: fails on some Linux tinderboxes, might be a FreeType issue.
|
2017-02-26 21:52:28 +02:00
|
|
|
Rectangle aBoundRect;
|
|
|
|
pOutDev->GetTextBoundRect(aBoundRect, aOneTwoThree);
|
|
|
|
CPPUNIT_ASSERT_EQUAL(Rectangle(0, 1, 71, 15), aBoundRect);
|
2017-02-27 13:07:31 +02:00
|
|
|
#endif
|
2017-02-26 21:52:28 +02:00
|
|
|
|
2013-06-15 20:51:38 +01:00
|
|
|
// normal orientation
|
|
|
|
Rectangle aInput;
|
|
|
|
Rectangle aRect = pOutDev->GetTextRect( aInput, aOneTwoThree );
|
|
|
|
|
|
|
|
// now rotate 270 degress
|
2014-09-16 10:09:58 +02:00
|
|
|
vcl::Font aRotated( aFont );
|
2013-06-15 20:51:38 +01:00
|
|
|
aRotated.SetOrientation( 2700 );
|
|
|
|
pOutDev->SetFont( aRotated );
|
|
|
|
Rectangle aRectRot = pOutDev->GetTextRect( aInput, aOneTwoThree );
|
|
|
|
|
|
|
|
// Check that we did do the rotation ...
|
|
|
|
#if 0
|
2017-02-27 13:07:31 +02:00
|
|
|
// FIXME: This seems to be wishful thinking, GetTextRect() does not take
|
2017-02-26 21:52:28 +02:00
|
|
|
// rotation into account.
|
2013-06-15 20:51:38 +01:00
|
|
|
fprintf( stderr, "%ld %ld %ld %ld\n",
|
|
|
|
aRect.GetWidth(), aRect.GetHeight(),
|
|
|
|
aRectRot.GetWidth(), aRectRot.GetHeight() );
|
|
|
|
CPPUNIT_ASSERT( aRectRot.GetWidth() == aRect.GetHeight() );
|
|
|
|
CPPUNIT_ASSERT( aRectRot.GetHeight() == aRect.GetWidth() );
|
|
|
|
#else
|
|
|
|
(void)aRect; (void)aRectRot;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2016-02-16 14:14:43 +02:00
|
|
|
#if defined(_WIN32)
|
2015-11-07 18:45:31 +10:00
|
|
|
void VclComplexTextTest::testTdf95650()
|
|
|
|
{
|
|
|
|
const sal_Unicode pTxt[] = {
|
|
|
|
0x0131, 0x0302, 0x0504, 0x4E44, 0x3031, 0x3030, 0x3531, 0x2D30,
|
|
|
|
0x3037, 0x0706, 0x0908, 0x0B0A, 0x0D0C, 0x0F0E, 0x072E, 0x100A,
|
|
|
|
0x0D11, 0x1312, 0x0105, 0x020A, 0x0512, 0x1403, 0x030C, 0x1528,
|
|
|
|
0x2931, 0x632E, 0x7074, 0x0D20, 0x0E0A, 0x100A, 0xF00D, 0x0D20,
|
|
|
|
0x030A, 0x0C0B, 0x20E0, 0x0A0D
|
|
|
|
};
|
|
|
|
OUString aTxt(pTxt, SAL_N_ELEMENTS(pTxt) - 1);
|
2016-12-21 19:01:27 +01:00
|
|
|
ScopedVclPtrInstance<WorkWindow> pWin(static_cast<vcl::Window *>(nullptr));
|
2015-11-07 18:45:31 +10:00
|
|
|
CPPUNIT_ASSERT(pWin);
|
|
|
|
|
2016-12-25 14:27:02 +01:00
|
|
|
OutputDevice *pOutDev = pWin.get();
|
2015-11-07 18:45:31 +10:00
|
|
|
// Check that the following executes without failing assertion
|
2016-10-14 16:44:22 +02:00
|
|
|
pOutDev->ImplLayout(aTxt, 9, 1, Point(), 0, nullptr, SalLayoutFlags::BiDiRtl);
|
2015-11-07 18:45:31 +10:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-06-15 20:51:38 +01:00
|
|
|
CPPUNIT_TEST_SUITE_REGISTRATION(VclComplexTextTest);
|
|
|
|
|
|
|
|
CPPUNIT_PLUGIN_IMPLEMENT();
|
|
|
|
|
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|