fix glyph rotation for Skia text rendering on Windows
The makes the chart descriptions in tdf#114209 and e.g. Japanese
from the document from tdf#126169 be rotated correctly,
Change-Id: I09a739fea7629000f3f49e417531bc47ba99c68f
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/90610
Tested-by: Jenkins
Reviewed-by: Luboš Luňák <l.lunak@collabora.com>
diff --git a/vcl/inc/skia/gdiimpl.hxx b/vcl/inc/skia/gdiimpl.hxx
index a7de1cf..630b7a1 100644
--- a/vcl/inc/skia/gdiimpl.hxx
+++ b/vcl/inc/skia/gdiimpl.hxx
@@ -203,14 +203,20 @@ public:
void drawBitmap(const SalTwoRect& rPosAry, const SkBitmap& aBitmap,
SkBlendMode eBlendMode = SkBlendMode::kSrcOver);
void drawGenericLayout(const GenericSalLayout& layout, Color textColor, const SkFont& font);
enum class GlyphOrientation
{
Apply,
Ignore
};
void drawGenericLayout(const GenericSalLayout& layout, Color textColor, const SkFont& font,
GlyphOrientation glyphOrientation);
protected:
// To be called before any drawing.
void preDraw();
// To be called after any drawing.
void postDraw();
// The canvas to drawn to. Will be diverted to a temporary for Xor mode.
// The canvas to draw to. Will be diverted to a temporary for Xor mode.
SkCanvas* getDrawCanvas() { return mXorMode ? getXorCanvas() : mSurface->getCanvas(); }
virtual void createSurface();
diff --git a/vcl/skia/gdiimpl.cxx b/vcl/skia/gdiimpl.cxx
index 3bf0724..8ce3bf8 100644
--- a/vcl/skia/gdiimpl.cxx
+++ b/vcl/skia/gdiimpl.cxx
@@ -1265,7 +1265,7 @@ static double toCos(int degree10th) { return SkScalarCos(toRadian(degree10th));
static double toSin(int degree10th) { return SkScalarSin(toRadian(degree10th)); }
void SkiaSalGraphicsImpl::drawGenericLayout(const GenericSalLayout& layout, Color textColor,
const SkFont& font)
const SkFont& font, GlyphOrientation glyphOrientation)
{
std::vector<SkGlyphID> glyphIds;
std::vector<SkRSXform> glyphForms;
@@ -1274,13 +1274,16 @@ void SkiaSalGraphicsImpl::drawGenericLayout(const GenericSalLayout& layout, Colo
Point aPos;
const GlyphItem* pGlyph;
int nStart = 0;
double orientationAngle = layout.GetOrientation(); // 10th of degree
while (layout.GetNextGlyph(&pGlyph, aPos, nStart))
{
glyphIds.push_back(pGlyph->glyphId());
double angle = orientationAngle;
if (pGlyph->IsVertical())
angle += 900; // 90 degree
int angle = 0; // 10th of degree
if (glyphOrientation == GlyphOrientation::Apply)
{
angle = layout.GetOrientation();
if (pGlyph->IsVertical())
angle += 900; // 90 degree
}
SkRSXform form = SkRSXform::Make(toCos(angle), toSin(angle), aPos.X(), aPos.Y());
glyphForms.emplace_back(std::move(form));
}
diff --git a/vcl/skia/win/gdiimpl.cxx b/vcl/skia/win/gdiimpl.cxx
index b7014ed..0708c8e 100644
--- a/vcl/skia/win/gdiimpl.cxx
+++ b/vcl/skia/win/gdiimpl.cxx
@@ -155,7 +155,8 @@ bool WinSkiaSalGraphicsImpl::DrawTextLayout(const GenericSalLayout& rLayout)
SkiaSalGraphicsImpl* impl = static_cast<SkiaSalGraphicsImpl*>(mWinParent.GetImpl());
COLORREF color = ::GetTextColor(mWinParent.getHDC());
Color salColor(GetRValue(color), GetGValue(color), GetBValue(color));
impl->drawGenericLayout(rLayout, salColor, font);
// The font already is set up to have glyphs rotated as needed.
impl->drawGenericLayout(rLayout, salColor, font, SkiaSalGraphicsImpl::GlyphOrientation::Ignore);
return true;
}
diff --git a/vcl/skia/x11/textrender.cxx b/vcl/skia/x11/textrender.cxx
index 02911fc..a980523 100644
--- a/vcl/skia/x11/textrender.cxx
+++ b/vcl/skia/x11/textrender.cxx
@@ -59,7 +59,8 @@ void SkiaTextRender::DrawTextLayout(const GenericSalLayout& rLayout, const SalGr
assert(dynamic_cast<SkiaSalGraphicsImpl*>(rGraphics.GetImpl()));
SkiaSalGraphicsImpl* impl = static_cast<SkiaSalGraphicsImpl*>(rGraphics.GetImpl());
impl->drawGenericLayout(rLayout, mnTextColor, font);
impl->drawGenericLayout(rLayout, mnTextColor, font,
SkiaSalGraphicsImpl::GlyphOrientation::Apply);
}
void SkiaTextRender::ClearDevFontCache() { fontManager.reset(); }