mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-09 23:34:20 +00:00
Direct2D: Fix text drawing using gradients
This commit is contained in:
parent
7f4176e259
commit
5aab60f4e5
2 changed files with 23 additions and 9 deletions
|
|
@ -1681,17 +1681,18 @@ void Direct2DGraphicsContext::drawGlyphs (Span<const uint16_t> glyphNumbers,
|
|||
return;
|
||||
|
||||
const auto fontScale = font.getHorizontalScale();
|
||||
const auto scaledTransform = AffineTransform::scale (fontScale, 1.0f).followedBy (transform);
|
||||
const auto glyphRunTransform = scaledTransform.followedBy (currentState->currentTransform.getTransform());
|
||||
const auto onlyTranslated = glyphRunTransform.isOnlyTranslation();
|
||||
const auto textTransform = AffineTransform::scale (fontScale, 1.0f).followedBy (transform);
|
||||
const auto worldTransform = currentState->currentTransform.getTransform();
|
||||
const auto textAndWorldTransform = textTransform.followedBy (worldTransform);
|
||||
const auto onlyTranslated = textAndWorldTransform.isOnlyTranslation();
|
||||
|
||||
const auto fillTransform = onlyTranslated
|
||||
? SavedState::BrushTransformFlags::applyWorldAndFillTypeTransforms
|
||||
: SavedState::BrushTransformFlags::applyFillTypeTransform;
|
||||
|
||||
const auto brush = currentState->getBrush (fillTransform);
|
||||
auto brush = currentState->getBrush (fillTransform);
|
||||
|
||||
if (! brush)
|
||||
if (brush == nullptr)
|
||||
return;
|
||||
|
||||
applyPendingClipList();
|
||||
|
|
@ -1699,9 +1700,17 @@ void Direct2DGraphicsContext::drawGlyphs (Span<const uint16_t> glyphNumbers,
|
|||
D2D1_POINT_2F baselineOrigin { 0.0f, 0.0f };
|
||||
|
||||
if (onlyTranslated)
|
||||
baselineOrigin = { glyphRunTransform.getTranslationX(), glyphRunTransform.getTranslationY() };
|
||||
{
|
||||
baselineOrigin = { textAndWorldTransform.getTranslationX(), textAndWorldTransform.getTranslationY() };
|
||||
}
|
||||
else
|
||||
getPimpl()->setDeviceContextTransform (glyphRunTransform);
|
||||
{
|
||||
D2D1::Matrix3x2F matrix{};
|
||||
brush->GetTransform (&matrix);
|
||||
const auto brushTransform = D2DUtilities::matrixToTransform (matrix);
|
||||
brush->SetTransform (D2DUtilities::transformToMatrix (brushTransform.followedBy (textTransform.inverted())));
|
||||
getPimpl()->setDeviceContextTransform (textAndWorldTransform);
|
||||
}
|
||||
|
||||
auto& run = getPimpl()->glyphRun;
|
||||
run.replace (positions, fontScale);
|
||||
|
|
|
|||
|
|
@ -324,9 +324,14 @@ struct D2DUtilities
|
|||
return { c.getFloatRed(), c.getFloatGreen(), c.getFloatBlue(), c.getFloatAlpha() };
|
||||
}
|
||||
|
||||
static D2D1::Matrix3x2F transformToMatrix (const AffineTransform& transform)
|
||||
static D2D1::Matrix3x2F transformToMatrix (const AffineTransform& t)
|
||||
{
|
||||
return { transform.mat00, transform.mat10, transform.mat01, transform.mat11, transform.mat02, transform.mat12 };
|
||||
return { t.mat00, t.mat10, t.mat01, t.mat11, t.mat02, t.mat12 };
|
||||
}
|
||||
|
||||
static AffineTransform matrixToTransform (const D2D1_MATRIX_3X2_F& m)
|
||||
{
|
||||
return { m._11, m._21, m._31, m._12, m._22, m._32 };
|
||||
}
|
||||
|
||||
static Rectangle<int> rectFromSize (D2D1_SIZE_U s)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue