Kaydet (Commit) ebd1d973 authored tarafından Jan-Marek Glogowski's avatar Jan-Marek Glogowski

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
üst d4125bd0
......@@ -37,6 +37,7 @@ public:
virtual ~Qt5FontFace() override;
static Qt5FontFace* fromQFont(const QFont& rFont);
static void fillAttributesFromQFont(const QFont& rFont, FontAttributes& rFA);
sal_IntPtr GetFontId() const override;
......
......@@ -49,7 +49,7 @@ inline QRect toQRect(const tools::Rectangle& rRect)
inline tools::Rectangle toRectangle(const QRect& rRect)
{
return tools::Rectangle(rRect.left(), rRect.top(), rRect.width(), rRect.height());
return tools::Rectangle(rRect.left(), rRect.top(), rRect.right(), rRect.bottom());
}
inline QSize toQSize(const Size& rSize) { return QSize(rSize.Width(), rSize.Height()); }
......
......@@ -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() {}
......
......@@ -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());
}
......
......@@ -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);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment