summaryrefslogtreecommitdiff
path: root/vcl/qt5
diff options
context:
space:
mode:
authorJan-Marek Glogowski <glogow@fbihome.de>2017-10-30 19:05:41 +0100
committerThorsten Behrens <Thorsten.Behrens@CIB.de>2017-11-06 12:05:32 +0100
commitb66a7cbd8491fe436126e11975c360f47ae346ed (patch)
treea8dce4ec9526d69a5c4c8640e3728dc3723c9065 /vcl/qt5
parent185c9724fd8445695f9233f8120c71e80392767d (diff)
QT5 first stab on implementing CommonSalLayout
CommonSalLayout doesn't rally have an interface. It's cluttered with #ifdefs. Currently we have to move the Qt5Font into the VCL library. Someone should refactor this... Doen't render any text yet, but reports some sizes. Eventually that would cut down the public interface again. Change-Id: I12f32affb05b37e070c6cbc80db01779f84590b6
Diffstat (limited to 'vcl/qt5')
-rw-r--r--vcl/qt5/Qt5Font.cxx26
-rw-r--r--vcl/qt5/Qt5FontFace.cxx4
-rw-r--r--vcl/qt5/Qt5FontFace.hxx12
-rw-r--r--vcl/qt5/Qt5Graphics.cxx9
-rw-r--r--vcl/qt5/Qt5Graphics.hxx8
-rw-r--r--vcl/qt5/Qt5Graphics_Text.cxx54
6 files changed, 99 insertions, 14 deletions
diff --git a/vcl/qt5/Qt5Font.cxx b/vcl/qt5/Qt5Font.cxx
new file mode 100644
index 000000000000..8ad5e2b0c040
--- /dev/null
+++ b/vcl/qt5/Qt5Font.cxx
@@ -0,0 +1,26 @@
+/* -*- 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 .
+ */
+
+#include <qt5/Qt5Font.hxx>
+
+Qt5Font::~Qt5Font()
+{
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/qt5/Qt5FontFace.cxx b/vcl/qt5/Qt5FontFace.cxx
index 701509b06108..347f6bb58ba5 100644
--- a/vcl/qt5/Qt5FontFace.cxx
+++ b/vcl/qt5/Qt5FontFace.cxx
@@ -65,7 +65,7 @@ sal_IntPtr Qt5FontFace::GetFontId() const
return reinterpret_cast<sal_IntPtr>( &m_aFontId );
}
-const FontCharMapRef Qt5FontFace::GetFontCharMap()
+const FontCharMapRef Qt5FontFace::GetFontCharMap() const
{
if( m_xCharMap.is() )
return m_xCharMap;
@@ -88,7 +88,7 @@ const FontCharMapRef Qt5FontFace::GetFontCharMap()
return m_xCharMap;
}
-bool Qt5FontFace::GetFontCapabilities(vcl::FontCapabilities &rFontCapabilities)
+bool Qt5FontFace::GetFontCapabilities(vcl::FontCapabilities &rFontCapabilities) const
{
// read this only once per font
if( m_bFontCapabilitiesRead )
diff --git a/vcl/qt5/Qt5FontFace.hxx b/vcl/qt5/Qt5FontFace.hxx
index 76b8fdee99f1..7cfbdf8be702 100644
--- a/vcl/qt5/Qt5FontFace.hxx
+++ b/vcl/qt5/Qt5FontFace.hxx
@@ -44,8 +44,8 @@ public:
int GetFontTable( const char pTagName[5], unsigned char* ) const;
- const FontCharMapRef GetFontCharMap();
- bool GetFontCapabilities( vcl::FontCapabilities &rFontCapabilities );
+ const FontCharMapRef GetFontCharMap() const;
+ bool GetFontCapabilities( vcl::FontCapabilities &rFontCapabilities ) const;
bool HasChar( sal_uInt32 cChar ) const;
protected:
@@ -53,10 +53,10 @@ protected:
Qt5FontFace( const FontAttributes& rFA, const QString &rFontID );
private:
- const QString m_aFontId;
- FontCharMapRef m_xCharMap;
- vcl::FontCapabilities m_aFontCapabilities;
- bool m_bFontCapabilitiesRead;
+ const QString m_aFontId;
+ mutable FontCharMapRef m_xCharMap;
+ mutable vcl::FontCapabilities m_aFontCapabilities;
+ mutable bool m_bFontCapabilitiesRead;
};
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/qt5/Qt5Graphics.cxx b/vcl/qt5/Qt5Graphics.cxx
index 1d0d15677eb4..aebb486c2453 100644
--- a/vcl/qt5/Qt5Graphics.cxx
+++ b/vcl/qt5/Qt5Graphics.cxx
@@ -30,6 +30,9 @@ Qt5Graphics::Qt5Graphics( Qt5Frame *pFrame )
: m_pFrame( pFrame )
, m_pQImage( nullptr )
, m_pFontCollection( nullptr )
+ , m_pFontData{ nullptr, }
+ , m_pTextStyle{ nullptr, }
+ , m_aTextColor( MAKE_SALCOLOR(0x00, 0x00, 0x00) )
{
}
@@ -37,11 +40,17 @@ Qt5Graphics::Qt5Graphics( QImage *pQImage )
: m_pFrame( nullptr )
, m_pQImage( pQImage )
, m_pFontCollection( nullptr )
+ , m_pFontData{ nullptr, }
+ , m_pTextStyle{ nullptr, }
+ , m_aTextColor( MAKE_SALCOLOR(0x00, 0x00, 0x00) )
{
}
Qt5Graphics::~Qt5Graphics()
{
+ // release the text styles
+ for (int i = 0; i < MAX_FALLBACK; ++i)
+ delete m_pTextStyle[ i ];
}
void Qt5Graphics::PreparePainter()
diff --git a/vcl/qt5/Qt5Graphics.hxx b/vcl/qt5/Qt5Graphics.hxx
index b021134e54b7..d9f74a05b919 100644
--- a/vcl/qt5/Qt5Graphics.hxx
+++ b/vcl/qt5/Qt5Graphics.hxx
@@ -25,9 +25,10 @@
#include <QtGui/QRegion>
+class Qt5Font;
+class Qt5FontFace;
class Qt5Frame;
class PhysicalFontCollection;
-class PhysicalFontFace;
class QImage;
class QPainter;
@@ -39,8 +40,11 @@ class Qt5Graphics : public SalGraphics
QImage *m_pQImage;
QRegion m_aClipRegion;
std::unique_ptr< QPainter > m_pPainter;
+
PhysicalFontCollection *m_pFontCollection;
- PhysicalFontFace *m_pFont;
+ const Qt5FontFace *m_pFontData[ MAX_FALLBACK ];
+ Qt5Font *m_pTextStyle[ MAX_FALLBACK ];
+ SalColor m_aTextColor;
void PreparePainter();
diff --git a/vcl/qt5/Qt5Graphics_Text.cxx b/vcl/qt5/Qt5Graphics_Text.cxx
index fe6931c84458..0053a56c412d 100644
--- a/vcl/qt5/Qt5Graphics_Text.cxx
+++ b/vcl/qt5/Qt5Graphics_Text.cxx
@@ -19,34 +19,78 @@
#include "Qt5Graphics.hxx"
#include "Qt5FontFace.hxx"
+#include <qt5/Qt5Font.hxx>
#include <vcl/fontcharmap.hxx>
+#include <CommonSalLayout.hxx>
#include <PhysicalFontCollection.hxx>
#include <QtGui/QFontDatabase>
+#include <QtGui/QRawFont>
#include <QtCore/QStringList>
void Qt5Graphics::SetTextColor( SalColor nSalColor )
{
+ m_aTextColor = nSalColor;
}
-void Qt5Graphics::SetFont( const FontSelectPattern*, int nFallbackLevel )
+void Qt5Graphics::SetFont( const FontSelectPattern* pReqFont, int nFallbackLevel )
{
+ // release the text styles
+ for (int i = nFallbackLevel; i < MAX_FALLBACK; ++i)
+ {
+ if ( !m_pTextStyle[ i ] )
+ break;
+ delete m_pTextStyle[ i ];
+ m_pTextStyle[ i ] = nullptr;
+ }
+
+ if( !pReqFont )
+ // handle release-font-resources request
+ m_pFontData[ nFallbackLevel ] = nullptr;
+ else
+ {
+ m_pFontData[ nFallbackLevel ] = static_cast<const Qt5FontFace*>( pReqFont->mpFontData );
+ m_pTextStyle[ nFallbackLevel ] = new Qt5Font( *pReqFont );
+ }
}
void Qt5Graphics::GetFontMetric( ImplFontMetricDataRef &rFMD, int nFallbackLevel )
{
+ QRawFont aRawFont( QRawFont::fromFont( *m_pTextStyle[ nFallbackLevel ] ) );
+
+ QByteArray aHheaTable = aRawFont.fontTable( "hhea" );
+ std::vector<uint8_t> rHhea(aHheaTable.data(), aHheaTable.data() + aHheaTable.size() );
+
+ QByteArray aOs2Table = aRawFont.fontTable( "OS/2" );
+ std::vector<uint8_t> rOS2(aHheaTable.data(), aHheaTable.data() + aHheaTable.size() );
+
+ rFMD->ImplCalcLineSpacing( rHhea, rOS2, aRawFont.unitsPerEm() );
+
+ rFMD->SetWidth( aRawFont.averageCharWidth() );
+
+ const QChar nKashidaCh[ 2 ] = { 0x06, 0x40 };
+ quint32 nKashidaGid = 0;
+ QPointF aPoint;
+ int nNumGlyphs;
+ if( aRawFont.glyphIndexesForChars( nKashidaCh, 1, &nKashidaGid, &nNumGlyphs )
+ && aRawFont.advancesForGlyphIndexes( &nKashidaGid, &aPoint, 1 ) )
+ rFMD->SetMinKashida( lrint(aPoint.rx()) );
}
const FontCharMapRef Qt5Graphics::GetFontCharMap() const
{
- return nullptr;
+ if( !m_pFontData[ 0 ] )
+ return FontCharMapRef( new FontCharMap() );
+ return m_pFontData[ 0 ]->GetFontCharMap();
}
bool Qt5Graphics::GetFontCapabilities(vcl::FontCapabilities &rFontCapabilities) const
{
- return false;
+ if( !m_pFontData[ 0 ] )
+ return false;
+ return m_pFontData[ 0 ]->GetFontCapabilities( rFontCapabilities );
}
void Qt5Graphics::GetDevFontList( PhysicalFontCollection* pPFC )
@@ -90,7 +134,7 @@ void Qt5Graphics::FreeEmbedFontData( const void* pData, long nDataLen )
{
}
-void Qt5Graphics::GetGlyphWidths( const PhysicalFontFace*, bool bVertical,
+void Qt5Graphics::GetGlyphWidths( const PhysicalFontFace* pPFF, bool bVertical,
std::vector< sal_Int32 >& rWidths,
Ucs2UIntMap& rUnicodeEnc )
{
@@ -108,6 +152,8 @@ bool Qt5Graphics::GetGlyphOutline( const GlyphItem&, basegfx::B2DPolyPolygon& )
SalLayout* Qt5Graphics::GetTextLayout( ImplLayoutArgs&, int nFallbackLevel )
{
+ if( m_pTextStyle[ nFallbackLevel ] )
+ return new CommonSalLayout( *m_pTextStyle[ nFallbackLevel ] );
return nullptr;
}