summaryrefslogtreecommitdiff
path: root/vcl/qt5
diff options
context:
space:
mode:
authorJan-Marek Glogowski <glogow@fbihome.de>2018-07-05 18:38:07 +0200
committerJan-Marek Glogowski <glogow@fbihome.de>2018-07-06 10:47:32 +0200
commitebd1d973eac7ef6f330634a2d2a8ca1bf3c6720e (patch)
tree791aabcd7874e6598084d775371df322d5a15820 /vcl/qt5
parentd4125bd04bd58972594510bf6ab5614693e25833 (diff)
Qt5 flesh out font handling
Fills some more FontAttributes based on the QFont. Also implements initial font rotation support. Something is still strage with the vertical font in Writers vertical ruler. Text looks correct in vertical text boxes FWIW. The toRectangle bug is embarrassing; I was wondering for quite some time, which glyphs had strange size rects :-) While at it, move the Qt5Font header to vcl/inc/qt5. Change-Id: I67fa400486981035be6f98c5ab56e82d69c42065
Diffstat (limited to 'vcl/qt5')
-rw-r--r--vcl/qt5/Qt5Font.cxx53
-rw-r--r--vcl/qt5/Qt5Font.hxx41
-rw-r--r--vcl/qt5/Qt5FontFace.cxx64
-rw-r--r--vcl/qt5/Qt5Graphics_Text.cxx43
4 files changed, 152 insertions, 49 deletions
diff --git a/vcl/qt5/Qt5Font.cxx b/vcl/qt5/Qt5Font.cxx
index 0164c3b13cd4..dc393dd1cae8 100644
--- a/vcl/qt5/Qt5Font.cxx
+++ b/vcl/qt5/Qt5Font.cxx
@@ -17,14 +17,65 @@
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
-#include "Qt5Font.hxx"
+#include <Qt5Font.hxx>
+#include <Qt5Tools.hxx>
#include <QtGui/QFont>
#include <QtGui/QRawFont>
+static QFont::Weight GetQFontWeight(FontWeight eWeight)
+{
+ switch (eWeight)
+ {
+ case WEIGHT_THIN:
+ return QFont::Thin;
+ case WEIGHT_ULTRALIGHT:
+ return QFont::ExtraLight;
+ case WEIGHT_LIGHT:
+ return QFont::Light;
+ case FontWeight_FORCE_EQUAL_SIZE:
+ assert(false && "FontWeight_FORCE_EQUAL_SIZE not implementable for QFont");
+ case WEIGHT_SEMILIGHT:
+ case WEIGHT_DONTKNOW:
+ case WEIGHT_NORMAL:
+ return QFont::Normal;
+ case WEIGHT_MEDIUM:
+ return QFont::Medium;
+ case WEIGHT_SEMIBOLD:
+ return QFont::DemiBold;
+ case WEIGHT_BOLD:
+ return QFont::Bold;
+ case WEIGHT_ULTRABOLD:
+ return QFont::ExtraBold;
+ case WEIGHT_BLACK:
+ return QFont::Black;
+ }
+
+ // so we would get enum not handled warning
+ return QFont::Normal;
+}
+
Qt5Font::Qt5Font(const PhysicalFontFace& rPFF, const FontSelectPattern& rFSP)
: LogicalFontInstance(rPFF, rFSP)
{
+ setFamily(toQString(rPFF.GetFamilyName()));
+ setWeight(GetQFontWeight(rPFF.GetWeight()));
+ setPixelSize(rFSP.mnHeight);
+ switch (rFSP.GetItalic())
+ {
+ case ITALIC_DONTKNOW:
+ case FontItalic_FORCE_EQUAL_SIZE:
+ break;
+ case ITALIC_NONE:
+ setStyle(Style::StyleNormal);
+ break;
+ case ITALIC_OBLIQUE:
+ setStyle(Style::StyleOblique);
+ break;
+ case ITALIC_NORMAL:
+ setStyle(Style::StyleItalic);
+ break;
+ }
}
Qt5Font::~Qt5Font() {}
diff --git a/vcl/qt5/Qt5Font.hxx b/vcl/qt5/Qt5Font.hxx
deleted file mode 100644
index 81bd723c1ab6..000000000000
--- a/vcl/qt5/Qt5Font.hxx
+++ /dev/null
@@ -1,41 +0,0 @@
-/* -*- 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 <fontinstance.hxx>
-
-#include <QtGui/QFont>
-
-#include <Qt5FontFace.hxx>
-
-class Qt5Font final : public QFont, public LogicalFontInstance
-{
- friend rtl::Reference<LogicalFontInstance>
- Qt5FontFace::CreateFontInstance(const FontSelectPattern&) const;
-
- virtual hb_font_t* ImplInitHbFont() override;
-
- explicit Qt5Font(const PhysicalFontFace&, const FontSelectPattern&);
-
-public:
- virtual ~Qt5Font() override;
-};
-
-/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/qt5/Qt5FontFace.cxx b/vcl/qt5/Qt5FontFace.cxx
index 043a9b6e798b..10f79aa559bd 100644
--- a/vcl/qt5/Qt5FontFace.cxx
+++ b/vcl/qt5/Qt5FontFace.cxx
@@ -18,7 +18,7 @@
*/
#include <Qt5FontFace.hxx>
-#include "Qt5Font.hxx"
+#include <Qt5Font.hxx>
#include <Qt5Tools.hxx>
#include <sft.hxx>
@@ -41,13 +41,67 @@ Qt5FontFace::Qt5FontFace(const Qt5FontFace& rSrc)
m_xCharMap = rSrc.m_xCharMap;
}
+void Qt5FontFace::fillAttributesFromQFont(const QFont& rFont, FontAttributes& rFA)
+{
+ QFontInfo aFontInfo(rFont);
+
+ rFA.SetFamilyName(toOUString(aFontInfo.family()));
+ if (IsStarSymbol(toOUString(aFontInfo.family())))
+ rFA.SetSymbolFlag(true);
+ rFA.SetStyleName(toOUString(aFontInfo.styleName()));
+ rFA.SetPitch(aFontInfo.fixedPitch() ? PITCH_FIXED : PITCH_VARIABLE);
+
+ FontWeight eWeight = WEIGHT_DONTKNOW;
+ switch (aFontInfo.weight())
+ {
+ case QFont::Thin:
+ eWeight = WEIGHT_THIN;
+ break;
+ case QFont::ExtraLight:
+ eWeight = WEIGHT_ULTRALIGHT;
+ break;
+ case QFont::Light:
+ eWeight = WEIGHT_LIGHT;
+ break;
+ case QFont::Normal:
+ eWeight = WEIGHT_NORMAL;
+ break;
+ case QFont::Medium:
+ eWeight = WEIGHT_MEDIUM;
+ break;
+ case QFont::DemiBold:
+ eWeight = WEIGHT_SEMIBOLD;
+ break;
+ case QFont::Bold:
+ eWeight = WEIGHT_BOLD;
+ break;
+ case QFont::ExtraBold:
+ eWeight = WEIGHT_ULTRABOLD;
+ break;
+ case QFont::Black:
+ eWeight = WEIGHT_BLACK;
+ break;
+ }
+ rFA.SetWeight(eWeight);
+
+ switch (aFontInfo.style())
+ {
+ case QFont::StyleNormal:
+ rFA.SetItalic(ITALIC_NONE);
+ break;
+ case QFont::StyleItalic:
+ rFA.SetItalic(ITALIC_NORMAL);
+ break;
+ case QFont::StyleOblique:
+ rFA.SetItalic(ITALIC_OBLIQUE);
+ break;
+ }
+}
+
Qt5FontFace* Qt5FontFace::fromQFont(const QFont& rFont)
{
FontAttributes aFA;
- aFA.SetFamilyName(toOUString(rFont.family()));
- aFA.SetStyleName(toOUString(rFont.styleName()));
- aFA.SetItalic(rFont.italic() ? ITALIC_NORMAL : ITALIC_NONE);
-
+ fillAttributesFromQFont(rFont, aFA);
return new Qt5FontFace(aFA, rFont.toString());
}
diff --git a/vcl/qt5/Qt5Graphics_Text.cxx b/vcl/qt5/Qt5Graphics_Text.cxx
index cb7bef853ba8..282432214589 100644
--- a/vcl/qt5/Qt5Graphics_Text.cxx
+++ b/vcl/qt5/Qt5Graphics_Text.cxx
@@ -19,7 +19,7 @@
#include <Qt5Graphics.hxx>
#include <Qt5FontFace.hxx>
-#include "Qt5Font.hxx"
+#include <Qt5Font.hxx>
#include <Qt5Painter.hxx>
#include <vcl/fontcharmap.hxx>
@@ -56,6 +56,7 @@ void Qt5Graphics::SetFont(const FontSelectPattern* pReqFont, int nFallbackLevel)
void Qt5Graphics::GetFontMetric(ImplFontMetricDataRef& rFMD, int nFallbackLevel)
{
QRawFont aRawFont(QRawFont::fromFont(*m_pTextStyle[nFallbackLevel]));
+ Qt5FontFace::fillAttributesFromQFont(*m_pTextStyle[nFallbackLevel], *rFMD);
QByteArray aHheaTable = aRawFont.fontTable("hhea");
std::vector<uint8_t> rHhea(aHheaTable.data(), aHheaTable.data() + aHheaTable.size());
@@ -65,6 +66,7 @@ void Qt5Graphics::GetFontMetric(ImplFontMetricDataRef& rFMD, int nFallbackLevel)
rFMD->ImplCalcLineSpacing(rHhea, rOS2, aRawFont.unitsPerEm());
+ rFMD->SetSlant(0);
rFMD->SetWidth(aRawFont.averageCharWidth());
rFMD->SetMinKashida(m_pTextStyle[nFallbackLevel]->GetKashidaWidth());
@@ -146,10 +148,21 @@ bool Qt5Graphics::GetGlyphBoundRect(const GlyphItem& rGlyph, tools::Rectangle& r
bool Qt5Graphics::GetGlyphOutline(const GlyphItem&, basegfx::B2DPolyPolygon&) { return false; }
+class Qt5CommonSalLayout : public GenericSalLayout
+{
+public:
+ Qt5CommonSalLayout(LogicalFontInstance& rLFI)
+ : GenericSalLayout(rLFI)
+ {
+ }
+
+ void SetOrientation(int nOrientation) { mnOrientation = nOrientation; }
+};
+
std::unique_ptr<SalLayout> Qt5Graphics::GetTextLayout(ImplLayoutArgs&, int nFallbackLevel)
{
if (m_pTextStyle[nFallbackLevel])
- return std::unique_ptr<SalLayout>(new GenericSalLayout(*m_pTextStyle[nFallbackLevel]));
+ return std::unique_ptr<SalLayout>(new Qt5CommonSalLayout(*m_pTextStyle[nFallbackLevel]));
return std::unique_ptr<SalLayout>();
}
@@ -162,6 +175,14 @@ void Qt5Graphics::DrawTextLayout(const GenericSalLayout& rLayout)
QVector<quint32> glyphIndexes;
QVector<QPointF> positions;
+ // prevent glyph rotation inside the SalLayout
+ // probably better to add a parameter to GetNextGlyphs?
+ Qt5CommonSalLayout* pQt5Layout
+ = static_cast<Qt5CommonSalLayout*>(const_cast<GenericSalLayout*>(&rLayout));
+ int nOrientation = rLayout.GetOrientation();
+ if (nOrientation)
+ pQt5Layout->SetOrientation(0);
+
Point aPos;
const GlyphItem* pGlyph;
int nStart = 0;
@@ -171,6 +192,9 @@ void Qt5Graphics::DrawTextLayout(const GenericSalLayout& rLayout)
positions.push_back(QPointF(aPos.X(), aPos.Y()));
}
+ if (nOrientation)
+ pQt5Layout->SetOrientation(nOrientation);
+
QGlyphRun aGlyphRun;
aGlyphRun.setPositions(positions);
aGlyphRun.setGlyphIndexes(glyphIndexes);
@@ -179,6 +203,21 @@ void Qt5Graphics::DrawTextLayout(const GenericSalLayout& rLayout)
Qt5Painter aPainter(*this);
QColor aColor = toQColor(m_aTextColor);
aPainter.setPen(aColor);
+
+ if (nOrientation)
+ {
+ // make text position the center of the rotation
+ // then rotate and move back
+ QRect window = aPainter.window();
+ window.moveTo(-positions[0].x(), -positions[0].y());
+ aPainter.setWindow(window);
+
+ QTransform p;
+ p.rotate(-static_cast<qreal>(nOrientation) / 10.0);
+ p.translate(-positions[0].x(), -positions[0].y());
+ aPainter.setTransform(p);
+ }
+
aPainter.drawGlyphRun(QPointF(), aGlyphRun);
}