summaryrefslogtreecommitdiff
path: root/vcl
diff options
context:
space:
mode:
authorChris Sherlock <chris.sherlock79@gmail.com>2021-09-05 13:35:13 +1000
committerMike Kaganski <mike.kaganski@collabora.com>2021-09-18 07:52:10 +0200
commitd596eb99c887b52ab99c38665cf1cacbcd24b029 (patch)
tree2dcd68a1b338362c1eeeba5ad7b663c75eebfe16 /vcl
parent1f9a792a391f0811bbb5f570ad5c84d13312c539 (diff)
vcl: rename ImplDeviceFontList to PhysicalFontFaceCollection and test
- renamed ImplDeviceFontList to PhysicalFontFaceCollection and moved to own header file - wrote unit test for PhysicalFontFaceCollection Note that this is part of a series of patches where I also move font files into the relevant font directories, and into the vcl::font namespace. Change-Id: I43669137bcd9a9b2a9417b2369a5cb1b93b93733 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/121663 Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com> Tested-by: Jenkins
Diffstat (limited to 'vcl')
-rw-r--r--vcl/CppunitTest_vcl_font.mk8
-rw-r--r--vcl/inc/PhysicalFontCollection.hxx2
-rw-r--r--vcl/inc/PhysicalFontFamily.hxx7
-rw-r--r--vcl/inc/font/PhysicalFontFaceCollection.hxx50
-rw-r--r--vcl/inc/outdev.h14
-rw-r--r--vcl/qa/cppunit/physicalfontfacecollection.cxx101
-rw-r--r--vcl/source/font/PhysicalFontCollection.cxx5
-rw-r--r--vcl/source/font/PhysicalFontFamily.cxx3
-rw-r--r--vcl/source/gdi/embeddedfontshelper.cxx3
-rw-r--r--vcl/source/gdi/print.cxx9
-rw-r--r--vcl/source/gdi/virdev.cxx3
-rw-r--r--vcl/source/outdev/font.cxx17
-rw-r--r--vcl/source/outdev/outdev.cxx5
-rw-r--r--vcl/win/gdi/salfont.cxx3
14 files changed, 192 insertions, 38 deletions
diff --git a/vcl/CppunitTest_vcl_font.mk b/vcl/CppunitTest_vcl_font.mk
index 8b66a989fa50..55a850e044a6 100644
--- a/vcl/CppunitTest_vcl_font.mk
+++ b/vcl/CppunitTest_vcl_font.mk
@@ -16,15 +16,21 @@ $(eval $(call gb_CppunitTest_set_include,vcl_font,\
$(eval $(call gb_CppunitTest_add_exception_objects,vcl_font, \
vcl/qa/cppunit/font \
+ vcl/qa/cppunit/physicalfontfacecollection \
))
-$(eval $(call gb_CppunitTest_use_externals,vcl_font,boost_headers))
+$(eval $(call gb_CppunitTest_use_externals,vcl_font,\
+ boost_headers \
+ harfbuzz \
+ graphite \
+))
$(eval $(call gb_CppunitTest_use_libraries,vcl_font, \
comphelper \
cppu \
cppuhelper \
sal \
+ salhelper \
svt \
test \
tl \
diff --git a/vcl/inc/PhysicalFontCollection.hxx b/vcl/inc/PhysicalFontCollection.hxx
index 38e591600467..c3ccdb69d438 100644
--- a/vcl/inc/PhysicalFontCollection.hxx
+++ b/vcl/inc/PhysicalFontCollection.hxx
@@ -67,7 +67,7 @@ public:
// misc utilities
std::shared_ptr<PhysicalFontCollection> Clone() const;
- std::unique_ptr<ImplDeviceFontList> GetDeviceFontList() const;
+ std::unique_ptr<vcl::font::PhysicalFontFaceCollection> GetFontFaceCollection() const;
std::unique_ptr<ImplDeviceFontSizeList> GetDeviceFontSizeList( const OUString& rFontName ) const;
private:
diff --git a/vcl/inc/PhysicalFontFamily.hxx b/vcl/inc/PhysicalFontFamily.hxx
index 0137aca3b7c4..77f0938ebead 100644
--- a/vcl/inc/PhysicalFontFamily.hxx
+++ b/vcl/inc/PhysicalFontFamily.hxx
@@ -30,7 +30,10 @@
#include "PhysicalFontFace.hxx"
-class ImplDeviceFontList;
+namespace vcl::font
+{
+class PhysicalFontFaceCollection;
+}
class PhysicalFontFace;
class PhysicalFontCollection;
@@ -74,7 +77,7 @@ public:
PhysicalFontFace* FindBestFontFace( const FontSelectPattern& rFSD ) const;
- void UpdateDevFontList( ImplDeviceFontList& ) const;
+ void UpdateDevFontList(vcl::font::PhysicalFontFaceCollection&) const;
void UpdateCloneFontList(PhysicalFontCollection&) const;
static void CalcType( ImplFontAttrs& rType, FontWeight& rWeight, FontWidth& rWidth,
diff --git a/vcl/inc/font/PhysicalFontFaceCollection.hxx b/vcl/inc/font/PhysicalFontFaceCollection.hxx
new file mode 100644
index 000000000000..9b4622690bfb
--- /dev/null
+++ b/vcl/inc/font/PhysicalFontFaceCollection.hxx
@@ -0,0 +1,50 @@
+/* -*- 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/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#pragma once
+
+#include <sal/config.h>
+
+#include <vcl/dllapi.h>
+
+#include <PhysicalFontFace.hxx>
+
+#include <vector>
+
+/**
+ A PhysicalFontFaceCollection is created by a PhysicalFontCollection and
+ becomes invalid when original PhysicalFontCollection is modified.
+ */
+
+namespace vcl::font
+{
+class PhysicalFontFaceCollection
+{
+private:
+ std::vector<rtl::Reference<PhysicalFontFace>> maDevFontVector;
+
+public:
+ PhysicalFontFaceCollection() { maDevFontVector.reserve(1024); }
+ void Add(PhysicalFontFace* pFace) { maDevFontVector.push_back(pFace); }
+ PhysicalFontFace* Get(int nIndex) const { return maDevFontVector[nIndex].get(); }
+ int Count() const { return maDevFontVector.size(); }
+};
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
diff --git a/vcl/inc/outdev.h b/vcl/inc/outdev.h
index 16871789bb22..4e050cf52665 100644
--- a/vcl/inc/outdev.h
+++ b/vcl/inc/outdev.h
@@ -35,20 +35,6 @@ class VirtualDevice;
class PhysicalFontCollection;
enum class AddFontSubstituteFlags;
-// an ImplDeviceFontList is created by a PhysicalFontCollection
-// it becomes invalid when original PhysicalFontCollection is modified
-class ImplDeviceFontList
-{
-private:
- std::vector<rtl::Reference<PhysicalFontFace>> maDevFontVector;
-
-public:
- ImplDeviceFontList() { maDevFontVector.reserve(1024); }
- void Add( PhysicalFontFace* pFace ) { maDevFontVector.push_back( pFace ); }
- PhysicalFontFace* Get( int nIndex ) const { return maDevFontVector[ nIndex ].get(); }
- int Count() const { return maDevFontVector.size(); }
-};
-
class ImplDeviceFontSizeList
{
private:
diff --git a/vcl/qa/cppunit/physicalfontfacecollection.cxx b/vcl/qa/cppunit/physicalfontfacecollection.cxx
new file mode 100644
index 000000000000..829729c3a185
--- /dev/null
+++ b/vcl/qa/cppunit/physicalfontfacecollection.cxx
@@ -0,0 +1,101 @@
+/* -*- 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/.
+ */
+
+#include <sal/config.h>
+
+#include <test/bootstrapfixture.hxx>
+#include <cppunit/TestAssert.h>
+
+#include <rtl/ref.hxx>
+#include <basegfx/polygon/b2dpolypolygon.hxx>
+
+#include <vcl/fontcapabilities.hxx>
+#include <vcl/fontcharmap.hxx>
+#include <vcl/glyphitem.hxx>
+#include <vcl/virdev.hxx>
+
+#include <PhysicalFontFace.hxx>
+#include <font/PhysicalFontFaceCollection.hxx>
+#include <fontattributes.hxx>
+#include <fontinstance.hxx>
+#include <fontselect.hxx>
+
+class VclPhysicalFontFaceCollectionTest : public test::BootstrapFixture
+{
+public:
+ VclPhysicalFontFaceCollectionTest()
+ : BootstrapFixture(true, false)
+ {
+ }
+
+ void testShouldGetFontId();
+
+ CPPUNIT_TEST_SUITE(VclPhysicalFontFaceCollectionTest);
+ CPPUNIT_TEST(testShouldGetFontId);
+ CPPUNIT_TEST_SUITE_END();
+};
+
+namespace
+{
+class TestFontInstance : public LogicalFontInstance
+{
+public:
+ TestFontInstance(PhysicalFontFace const& rFontFace, FontSelectPattern const& rFontSelectPattern)
+ : LogicalFontInstance(rFontFace, rFontSelectPattern)
+ {
+ }
+
+ bool GetGlyphOutline(sal_GlyphId, basegfx::B2DPolyPolygon&, bool) const override
+ {
+ return true;
+ }
+
+protected:
+ bool ImplGetGlyphBoundRect(sal_GlyphId, tools::Rectangle&, bool) const override { return true; }
+};
+
+class TestFontFace : public PhysicalFontFace
+{
+public:
+ TestFontFace(sal_uIntPtr nId)
+ : PhysicalFontFace(FontAttributes())
+ , mnFontId(nId)
+ {
+ }
+
+ rtl::Reference<LogicalFontInstance>
+ CreateFontInstance(FontSelectPattern const& rFontSelectPattern) const override
+ {
+ return new TestFontInstance(*this, rFontSelectPattern);
+ }
+
+ sal_IntPtr GetFontId() const override { return mnFontId; }
+ FontCharMapRef GetFontCharMap() const override { return FontCharMap::GetDefaultMap(false); }
+ bool GetFontCapabilities(vcl::FontCapabilities&) const override { return true; }
+
+private:
+ sal_IntPtr mnFontId;
+};
+}
+
+void VclPhysicalFontFaceCollectionTest::testShouldGetFontId()
+{
+ vcl::font::PhysicalFontFaceCollection aCollection;
+ aCollection.Add(new TestFontFace(1988756));
+
+ rtl::Reference<PhysicalFontFace> pActual(new TestFontFace(1988756));
+ rtl::Reference<PhysicalFontFace> pExpected = aCollection.Get(0);
+
+ CPPUNIT_ASSERT_EQUAL(pExpected->GetFontId(), pActual->GetFontId());
+ CPPUNIT_ASSERT_EQUAL(1, aCollection.Count());
+}
+
+CPPUNIT_TEST_SUITE_REGISTRATION(VclPhysicalFontFaceCollectionTest);
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/source/font/PhysicalFontCollection.cxx b/vcl/source/font/PhysicalFontCollection.cxx
index 7161e5b35c49..698e3a91c48e 100644
--- a/vcl/source/font/PhysicalFontCollection.cxx
+++ b/vcl/source/font/PhysicalFontCollection.cxx
@@ -27,6 +27,7 @@
#include <unotools/fontdefs.hxx>
#include <o3tl/sorted_vector.hxx>
#include <outdev.h>
+#include <font/PhysicalFontFaceCollection.hxx>
#include <PhysicalFontCollection.hxx>
static ImplFontAttrs lcl_IsCJKFont( const OUString& rFontName )
@@ -887,9 +888,9 @@ std::shared_ptr<PhysicalFontCollection> PhysicalFontCollection::Clone() const
return xClonedCollection;
}
-std::unique_ptr<ImplDeviceFontList> PhysicalFontCollection::GetDeviceFontList() const
+std::unique_ptr<vcl::font::PhysicalFontFaceCollection> PhysicalFontCollection::GetFontFaceCollection() const
{
- std::unique_ptr<ImplDeviceFontList> pDeviceFontList(new ImplDeviceFontList);
+ std::unique_ptr<vcl::font::PhysicalFontFaceCollection> pDeviceFontList(new vcl::font::PhysicalFontFaceCollection);
for (auto const& family : maPhysicalFontFamilies)
{
diff --git a/vcl/source/font/PhysicalFontFamily.cxx b/vcl/source/font/PhysicalFontFamily.cxx
index cd8634aeb0ed..31caca8dcd31 100644
--- a/vcl/source/font/PhysicalFontFamily.cxx
+++ b/vcl/source/font/PhysicalFontFamily.cxx
@@ -23,6 +23,7 @@
#include <unotools/fontdefs.hxx>
#include <outdev.h>
+#include <font/PhysicalFontFaceCollection.hxx>
#include <PhysicalFontCollection.hxx>
void PhysicalFontFamily::CalcType( ImplFontAttrs& rType, FontWeight& rWeight, FontWidth& rWidth,
@@ -232,7 +233,7 @@ PhysicalFontFace* PhysicalFontFamily::FindBestFontFace( const FontSelectPattern&
// update device font list with unique font faces, with uniqueness
// meaning different font attributes, but not different fonts sizes
-void PhysicalFontFamily::UpdateDevFontList( ImplDeviceFontList& rDevFontList ) const
+void PhysicalFontFamily::UpdateDevFontList( vcl::font::PhysicalFontFaceCollection& rDevFontList ) const
{
PhysicalFontFace* pPrevFace = nullptr;
for (auto const& font : maFontFaces)
diff --git a/vcl/source/gdi/embeddedfontshelper.cxx b/vcl/source/gdi/embeddedfontshelper.cxx
index cbe4ceed3454..ebcedb45b6a4 100644
--- a/vcl/source/gdi/embeddedfontshelper.cxx
+++ b/vcl/source/gdi/embeddedfontshelper.cxx
@@ -21,6 +21,7 @@
#include <com/sun/star/io/XInputStream.hpp>
#include <outdev.h>
+#include <font/PhysicalFontFaceCollection.hxx>
#include <PhysicalFontCollection.hxx>
#include <salgdi.hxx>
#include <sft.hxx>
@@ -258,7 +259,7 @@ OUString EmbeddedFontsHelper::fontFileUrl( std::u16string_view familyName, FontF
SalGraphics* graphics = Application::GetDefaultDevice()->GetGraphics();
PhysicalFontCollection fonts;
graphics->GetDevFontList( &fonts );
- std::unique_ptr< ImplDeviceFontList > fontInfo( fonts.GetDeviceFontList());
+ std::unique_ptr< vcl::font::PhysicalFontFaceCollection > fontInfo( fonts.GetFontFaceCollection());
PhysicalFontFace* selected = nullptr;
for( int i = 0;
i < fontInfo->Count();
diff --git a/vcl/source/gdi/print.cxx b/vcl/source/gdi/print.cxx
index f46d6ed03ec5..36aa93f6ec37 100644
--- a/vcl/source/gdi/print.cxx
+++ b/vcl/source/gdi/print.cxx
@@ -35,6 +35,7 @@
#include <outdev.h>
#include <print.h>
#include <PhysicalFontCollection.hxx>
+#include <font/PhysicalFontFaceCollection.hxx>
#include <print.hrc>
#include <salgdi.hxx>
#include <salinst.hxx>
@@ -560,7 +561,7 @@ void Printer::ImplReleaseFonts()
mbInitFont = true;
mpFontInstance.clear();
- mpDeviceFontList.reset();
+ mpFontFaceCollection.reset();
mpDeviceFontSizeList.reset();
}
@@ -922,7 +923,7 @@ void Printer::dispose()
// the FontEntry to NULL here
// TODO: consolidate duplicate cleanup by Printer and OutputDevice
mpFontInstance.clear();
- mpDeviceFontList.reset();
+ mpFontFaceCollection.reset();
mpDeviceFontSizeList.reset();
mxFontCache.reset();
// font list deleted by OutputDevice dtor
@@ -1069,7 +1070,7 @@ bool Printer::SetPrinterProps( const Printer* pPrinter )
ReleaseGraphics();
pSVData->mpDefInst->DestroyInfoPrinter( mpInfoPrinter );
mpFontInstance.clear();
- mpDeviceFontList.reset();
+ mpFontFaceCollection.reset();
mpDeviceFontSizeList.reset();
// clean up font list
mxFontCache.reset();
@@ -1098,7 +1099,7 @@ bool Printer::SetPrinterProps( const Printer* pPrinter )
pSVData->mpDefInst->DestroyInfoPrinter( mpInfoPrinter );
mpFontInstance.clear();
- mpDeviceFontList.reset();
+ mpFontFaceCollection.reset();
mpDeviceFontSizeList.reset();
mxFontCache.reset();
mxFontCollection.reset();
diff --git a/vcl/source/gdi/virdev.cxx b/vcl/source/gdi/virdev.cxx
index 8f5a1d96f329..77f364aded4d 100644
--- a/vcl/source/gdi/virdev.cxx
+++ b/vcl/source/gdi/virdev.cxx
@@ -26,6 +26,7 @@
#include <vcl/virdev.hxx>
#include <outdev.h>
+#include <font/PhysicalFontFaceCollection.hxx>
#include <PhysicalFontCollection.hxx>
#include <salinst.hxx>
#include <salgdi.hxx>
@@ -470,7 +471,7 @@ void VirtualDevice::ImplSetReferenceDevice( RefDevMode i_eRefDevMode, sal_Int32
// the reference device should have only scalable fonts
// => clean up the original font lists before getting new ones
mpFontInstance.clear();
- mpDeviceFontList.reset();
+ mpFontFaceCollection.reset();
mpDeviceFontSizeList.reset();
// preserve global font lists
diff --git a/vcl/source/outdev/font.cxx b/vcl/source/outdev/font.cxx
index 4161ea8ce236..ed6f5be095b8 100644
--- a/vcl/source/outdev/font.cxx
+++ b/vcl/source/outdev/font.cxx
@@ -38,6 +38,7 @@
#include <window.h>
#include <ImplLayoutArgs.hxx>
+#include <font/PhysicalFontFaceCollection.hxx>
#include <PhysicalFontCollection.hxx>
#include <drawmode.hxx>
#include <font/FeatureCollector.hxx>
@@ -103,7 +104,7 @@ FontMetric OutputDevice::GetDevFont( int nDevFontIndex ) const
int nCount = GetDevFontCount();
if( nDevFontIndex < nCount )
{
- const PhysicalFontFace& rData = *mpDeviceFontList->Get( nDevFontIndex );
+ const PhysicalFontFace& rData = *mpFontFaceCollection->Get( nDevFontIndex );
aFontMetric.SetFamilyName( rData.GetFamilyName() );
aFontMetric.SetStyleName( rData.GetStyleName() );
aFontMetric.SetCharSet( rData.GetCharSet() );
@@ -121,22 +122,22 @@ FontMetric OutputDevice::GetDevFont( int nDevFontIndex ) const
int OutputDevice::GetDevFontCount() const
{
- if( !mpDeviceFontList )
+ if( !mpFontFaceCollection )
{
if (!mxFontCollection)
{
return 0;
}
- mpDeviceFontList = mxFontCollection->GetDeviceFontList();
+ mpFontFaceCollection = mxFontCollection->GetFontFaceCollection();
- if (!mpDeviceFontList->Count())
+ if (!mpFontFaceCollection->Count())
{
- mpDeviceFontList.reset();
+ mpFontFaceCollection.reset();
return 0;
}
}
- return mpDeviceFontList->Count();
+ return mpFontFaceCollection->Count();
}
bool OutputDevice::IsFontAvailable( const OUString& rFontName ) const
@@ -512,7 +513,7 @@ void OutputDevice::ImplClearFontData( const bool bNewFontLists )
if ( bNewFontLists )
{
- mpDeviceFontList.reset();
+ mpFontFaceCollection.reset();
mpDeviceFontSizeList.reset();
// release all physically selected fonts on this device
@@ -1487,7 +1488,7 @@ void OutputDevice::ImplReleaseFonts()
mbInitFont = true;
mpFontInstance.clear();
- mpDeviceFontList.reset();
+ mpFontFaceCollection.reset();
mpDeviceFontSizeList.reset();
}
diff --git a/vcl/source/outdev/outdev.cxx b/vcl/source/outdev/outdev.cxx
index 574fd89b91c2..85a82fac0d03 100644
--- a/vcl/source/outdev/outdev.cxx
+++ b/vcl/source/outdev/outdev.cxx
@@ -32,6 +32,7 @@
#include <vcl/lazydelete.hxx>
#include <comphelper/processfactory.hxx>
+#include <font/PhysicalFontFaceCollection.hxx>
#include <salgdi.hxx>
#include <window.h>
#include <outdev.h>
@@ -68,7 +69,7 @@ OutputDevice::OutputDevice(OutDevType eOutDevType) :
mpNextGraphics = nullptr;
mpMetaFile = nullptr;
mpFontInstance = nullptr;
- mpDeviceFontList = nullptr;
+ mpFontFaceCollection = nullptr;
mpDeviceFontSizeList = nullptr;
mpAlphaVDev = nullptr;
mpExtOutDevData = nullptr;
@@ -169,7 +170,7 @@ void OutputDevice::dispose()
mpFontInstance.clear();
// remove cached results of GetDevFontList/GetDevSizeList
- mpDeviceFontList.reset();
+ mpFontFaceCollection.reset();
mpDeviceFontSizeList.reset();
// release ImplFontCache specific to this OutputDevice
diff --git a/vcl/win/gdi/salfont.cxx b/vcl/win/gdi/salfont.cxx
index e07680c87dec..6c199de9c18f 100644
--- a/vcl/win/gdi/salfont.cxx
+++ b/vcl/win/gdi/salfont.cxx
@@ -53,6 +53,7 @@
#include <fontsubset.hxx>
#include <outdev.h>
+#include <font/PhysicalFontFaceCollection.hxx>
#include <PhysicalFontCollection.hxx>
#include <PhysicalFontFace.hxx>
#include <sft.hxx>
@@ -329,7 +330,7 @@ bool WinGlyphFallbackSubstititution::FindFontSubstitute(FontSelectPattern& rFont
}
// last level fallback, check each font type face one by one
- std::unique_ptr<ImplDeviceFontList> pTestFontList = pFontCollection->GetDeviceFontList();
+ std::unique_ptr<vcl::font::PhysicalFontFaceCollection> pTestFontList = pFontCollection->GetFontFaceCollection();
// limit the count of fonts to be checked to prevent hangs
static const int MAX_GFBFONT_COUNT = 600;
int nTestFontCount = pTestFontList->Count();